clarify use of mysql_fetch_array : use mysql_fetch_assoc or mysql_fetch_row
[diogenes.git] / include / admin / files.php
CommitLineData
6855525e
JL
1<?php
2if (empty($_REQUEST['dir']))
3 exit;
4
5require_once 'diogenes.common.inc.php';
6require_once 'diogenes.admin.inc.php';
7require_once 'Barrel/Page.php';
8require_once 'Barrel/File.php';
9
10$page = new DiogenesAdmin($_REQUEST['dir']);
11$bbarrel =& $page->barrel;
12
13// retrieve all the barrel's pages
14$fpages = $bbarrel->getPages();
15
16$page->assign('post',$page->script_self());
17
18// rcs handle
19$rcs = $page->getRcs();
20
21/* 5Mb limit */
22$maxsize=5000000;
23
24$action = (isset($_REQUEST["action"])) ? $_REQUEST["action"] : "";
25$target = isset($_REQUEST["target"]) ? $_REQUEST["target"] : "";
26$newname = isset($_REQUEST["newname"]) ? $_REQUEST["newname"] : "";
27$fileop_sfile = isset($_REQUEST['fileop_sfile']) ? $_REQUEST['fileop_sfile'] : '';
28$fileop_ddir = isset($_REQUEST['fileop_ddir']) ? $_REQUEST['fileop_ddir'] : '';
29
30$fpage = $fpages[$_REQUEST['dir']];
31
32// legacy
33$canedit = $_SESSION['session']->hasPerms($fpage->props['wperms']);
34$page->assign('canedit', $canedit);
35
36// translations
37$page->assign('msg_import',__("Import file"));
38$page->assign('msg_btn_fileop',__("Submit"));
39$page->assign('msg_btn_send',__("Send"));
40$page->assign('msg_create',__("Create an empty file"));
41$page->assign('msg_copy_or_move', __("Copy or move a file"));
42$page->assign('msg_btn_create',__("Create"));
43$page->assign('msg_file',__("file"));
44$page->assign('msg_log',__("log"));
45$page->assign('msg_version',__("version"));
46$page->assign('msg_date',__("date"));
47$page->assign('msg_author',__("author"));
48$page->assign('msg_size',__("size"));
49$page->assign('msg_actions',__("actions"));
50$page->assign('msg_fileop_to', __("to"));
51// for pages
52$page->assign('msg_location',__("location"));
53$page->assign('msg_title',__("title"));
54$page->assign('msg_page_template',__("page template"));
55$page->assign('msg_status',__("status"));
56$page->assign('msg_access',__("access"));
57$page->assign('msg_read_perms',__("read access"));
58$page->assign('msg_write_perms',__("write access"));
59
60// build navigation toolbar
d0b659f7 61$page->toolbar(__("Page"), $fpage->make_toolbar($page));
6855525e
JL
62
63
64switch ($action) {
65case "file_create":
66 if (!$canedit) break;
67 $createfile = isset($_REQUEST['createfile']) ? $_REQUEST['createfile'] : '';
68 if ($createfile) {
69 $page->info(__("Creating empty file") . " $createfile");
70 if ($rcs->checkFile($fpage->props['PID'], $createfile)) {
71 $page->info(__("The specified file already exists!"));
72 } else {
73 $rcs->commit($fpage->props['PID'], $createfile, '', "empty file creation of $createfile");
74 }
75 }
76 break;
77
78case "file_upload":
79 if (!$canedit) break;
80 $userfile = $_FILES['userfile']['name'];
81 if ( is_uploaded_file($_FILES['userfile']['tmp_name'])
82 && (filesize($_FILES['userfile']['tmp_name']) <= $maxsize) )
83 {
84 $rcs->commit($fpage->props['PID'], $userfile,
85 file_get_contents($_FILES['userfile']['tmp_name']),
86 "file manager upload of $userfile" );
87 } else {
88 $page->info(__("Error during file transfer!"));
89 }
90 break;
91
92case "file_delete":
93 if (!$canedit) break;
94 $page->info(__("Deleting file"). " ". $fpage->getLocation($target));
95 $rcs->del($fpage->props['PID'],$target);
96 break;
97
98case "file_rename":
99 if (!$canedit) break;
100 $page->info("Renaming file '$target' to '$newname'");
101 $rcs->move($fpage->props['PID'], $target, $fpage->props['PID'], $newname);
102 break;
103
104case "page_delete":
d0b659f7
JL
105 $target_path = $bbarrel->getLocation($target);
106 $bbarrel->rmPath($target_path, $page);
6855525e
JL
107 $fpages = $bbarrel->getPages();
108 break;
109
110case "restore":
111 if (!$canedit) break;
112 $rev = $_REQUEST["rev"];
113 $page->info("restore : $target,$rev");
114 $path = $rcs->checkout($fpage->props['PID'],$target,$rev,System::mktemp("-d"));
115 $contents = file_get_contents($path);
116 $rcs->commit($fpage->props['PID'],$target,$contents,"restored revision $rev");
117 break;
118
119case "diff":
120 $ffile = new Diogenes_Barrel_File($fpage, $target);
121 $page->assign('greeting', __("Revision differences"). " - ". $fpage->getLocation($target));
122 $page->assign('diff',$rcs->dispDiff($fpage->props['PID'], $target, $_REQUEST["r1"],$_REQUEST["r2"]));
123 $page->toolbar(__("File"), $ffile->make_toolbar(true));
124 $page->display('admin-revs.tpl');
125 exit;
126
127case "revs":
128 $ffile = new Diogenes_Barrel_File($fpage, $target);
129 $page->assign('greeting', __("File revisions"). " - " . $fpage->getLocation($target));
130
131 // build urls
132 $urlPage = $page->urlSite($fpage->props['location']);
133 $urlFile = $page->urlSite($fpage->props['location'], $target);
134
135 // parse log entries
136 $revs = $rcs->logParse($fpage->props['PID'], $target);
137
138 // process log entries
139 $head = $revs[0]['rev'];
140 $rentries = array();
141
142 $sz = count($revs);
143 for ($i = 0; $i < $sz; $i++) {
144 $rev = $revs[$i];
145 $actions = array(array(__("view"), "$urlFile?rev={$rev['rev']}"));
146 if ($target == $globals->htmlfile) {
147 array_push($actions, array(__("view page"),"$urlPage?rev={$rev['rev']}"));
148 }
149 if ($i != ($sz-1)) {
150 array_push($actions, array(__("diff to")." {$revs[$i+1]['rev']}",
151 "?action=diff&amp;dir={$fpage->props['PID']}&amp;target=$target&amp;r1={$revs[$i+1]['rev']}&amp;r2={$rev['rev']}&amp;author={$rev['author']}"));
152 }
153 if (($i != 0) && $canedit) {
154 array_push($actions, array(__("restore"),
155 "javascript:restore('{$rev['rev']}');"));
156 }
157 array_push($rentries, array($rev['rev'],$rev['date'],
158 $rev['author'],$rev['log'], $actions));
159 }
160
161 $page->assign('entries', $rentries);
162 $page->toolbar(__("File"), $ffile->make_toolbar(true));
163 $page->display('admin-revs.tpl');
164 exit;
165
166case "fileop":
167 $fileop_dfile = $fileop_sfile;
168 $file_action = isset($_REQUEST['file_action']) ? $_REQUEST['file_action'] : '';
169 $page->info("$file_action '$fileop_sfile' to '$fileop_ddir'");
170 switch ($file_action)
171 {
172 case "file_copy":
173 $page->info("copying '$fileop_sfile' to '$fileop_ddir'");
174 if ($rcs->checkFile($fileop_ddir, $fileop_dfile))
175 {
176 $dfext = array_pop(explode('.', $fileop_dfile));
177 $dfname = basename($fileop_dfile, '.'.$dfext);
178 $fileop_dfile = $dfname."_copy.$dfext";
179 }
180 $rcs->copy($fpage->props['PID'], $fileop_sfile, $fileop_ddir, $fileop_dfile);
181 break;
182
183 case "file_move":
184 $page->info("moving '$fileop_sfile' to '$fileop_ddir'");
185 $rcs->move($fpage->props['PID'], $fileop_sfile, $fileop_ddir, $fileop_dfile);
186 break;
187 }
188 break;
189
190}
191
192// directory listing
193$page->toolbar(__("Document"), $fpage->make_doc_toolbar($rcs));
194$pageloc = $bbarrel->getLocation($fpage->props['PID']);
195$page->assign('greeting', __("File manager"). " - " .(strlen($pageloc) ? $pageloc : __("home")));
196$page->assign('maxsize',$maxsize);
197
198// retrieve child directories
199foreach($fpages as $pkey => $pval)
200{
201 if ($pval->props['parent'] == $fpage->props['PID'])
202 {
203 $arr = $pval->props;
204 $arr['actions'] = $pval->make_actions();
205 $arr['click'] = "files?dir={$pkey}";
206 $arr['icon'] = $globals->icons->get_icon('barrel', strlen($arr['location']) ? 'directory' : 'home');
207 $arr['iperms'] = $globals->icons->get_icon('perm', $arr['perms']);
208 $arr['iwperms'] = $globals->icons->get_icon('perm', $arr['wperms']);
209 $page->append('childpages', $arr);
210 }
211}
212
213// retrieve files in directory
214$tfentries = $rcs->dispDir($fpage->props['PID'], $pageloc, $canedit);
215$fentries = array();
216foreach ($tfentries as $fentry)
217{
218 $tbfile = new Diogenes_Barrel_File($fpage, $fentry['file']);
219 $fentry['actions'] = $tbfile->make_actions($canedit);
220 array_push($fentries, $fentry);
221}
222$page->assign('childfiles', $fentries);
223
224
225$page->assign('fileops', array("file_copy" => __("Copy"), "file_move" => __("Move")));
226$fileop_ddirs = array();
227foreach($fpages as $pkey => $ppage)
228{
229 $pageloc = $bbarrel->getLocation($pkey);
230 $fileop_ddirs[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title'];
231}
232$page->assign('fileop_ddirs', $fileop_ddirs);
233$page->display('admin-files.tpl');
234?>