1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8$section = 'mytiki';
9require_once('tiki-setup.php');
10include_once('lib/notepad/notepadlib.php');
11include_once('lib/userfiles/userfileslib.php');
12$access->check_feature('feature_notepad');
13$access->check_user($user);
14$access->check_permission('tiki_p_notepad');
15// Process upload here
16if (isset($_FILES['userfile1']) && is_uploaded_file($_FILES['userfile1']['tmp_name'])) {
17	check_ticket('notepad-list');
18	$filegallib = TikiLib::lib('filegal');
19	try {
20		$filegallib->assertUploadedFileIsSafe($_FILES['userfile1']['tmp_name'], $_FILES['userfile1']['name']);
21	} catch (Exception $e) {
22		$smarty->assign('errortype', 403);
23		$smarty->assign('msg', $e->getMessage());
24		$smarty->display("error.tpl");
25		die;
26	}
27	$fp = fopen($_FILES['userfile1']['tmp_name'], "rb");
28	$data = '';
29	while (! feof($fp)) {
30		$data .= fread($fp, 8192 * 16);
31	}
32	fclose($fp);
33	if (strlen($data) > 1000000) {
34		$smarty->assign('msg', tra("The file is too large"));
35		$smarty->display("error.tpl");
36		die;
37	}
38	$size = $_FILES['userfile1']['size'];
39	$name = $_FILES['userfile1']['name'];
40	$type = $_FILES['userfile1']['type'];
41	$notepadlib->replace_note($user, 0, $name, $data);
42}
43if (isset($_REQUEST["merge"])) {
44	check_ticket('notepad-list');
45	$merge = '';
46	$first = true;
47	if (! isset($_REQUEST["note"])) {
48		$smarty->assign('msg', tra("No item indicated"));
49		$smarty->display("error.tpl");
50		die;
51	}
52	foreach (array_keys($_REQUEST["note"]) as $note) {
53		$data_c = $notepadlib->get_note($user, $note);
54		$data = $data_c['data'];
55		if ($first) {
56			$first = false;
57			$merge .= "---------" . tra('merged note:') . $data_c['name'] . "----" . "\n";
58			$merge .= $data;
59		} else {
60			$merge .= "\n---------" . tra('merged note:') . $data_c['name'] . "----" . "\n";
61			$merge .= $data;
62		}
63	}
64	// Now create the merged note
65	$tikilib->replace_note($user, 0, $_REQUEST['merge_name'], $merge);
66}
67if (isset($_REQUEST["delete"]) && isset($_REQUEST["note"])) {
68	foreach (array_keys($_REQUEST["note"]) as $note) {
69		$notepadlib->remove_note($user, $note);
70	}
71}
72$quota = $userfileslib->userfiles_quota($user);
73$limit = $prefs['userfiles_quota'] * 1024 * 1000;
74if ($limit == 0) {
75	$limit = 999999999;
76}
77$percentage = ($quota / $limit) * 100;
78$cellsize = round($percentage / 100 * 200);
79if ($cellsize == 0) {
80	$cellsize = 1;
81}
82$percentage = round($percentage);
83$smarty->assign('cellsize', $cellsize);
84$smarty->assign('percentage', $percentage);
85if (! isset($_REQUEST["sort_mode"])) {
86	$sort_mode = 'lastModif_desc';
87} else {
88	$sort_mode = $_REQUEST["sort_mode"];
89}
90if (! isset($_REQUEST["offset"])) {
91	$offset = 0;
92} else {
93	$offset = $_REQUEST["offset"];
94}
95$smarty->assign_by_ref('offset', $offset);
96if (isset($_REQUEST["find"])) {
97	$find = $_REQUEST["find"];
98} else {
99	$find = '';
100}
101$smarty->assign('find', $find);
102$smarty->assign_by_ref('sort_mode', $sort_mode);
103if (isset($_SESSION['thedate'])) {
104	$pdate = $_SESSION['thedate'];
105} else {
106	$pdate = $tikilib->now;
107}
108$channels = $notepadlib->list_notes($user, $offset, $maxRecords, $sort_mode, $find);
109$smarty->assign_by_ref('cant_pages', $channels["cant"]);
110$smarty->assign_by_ref('channels', $channels["data"]);
111include_once('tiki-section_options.php');
112include_once('tiki-mytiki_shared.php');
113ask_ticket('notepad-list');
114$smarty->assign('mid', 'tiki-notepad_list.tpl');
115$smarty->display("tiki.tpl");
116