* improved - after adding a page, return to the calling url
[diogenes.git] / include / admin / pages.php
1 <?php
2 require_once 'diogenes.common.inc.php';
3 require_once 'diogenes.admin.inc.php';
4 require_once 'Barrel.php';
5 require_once 'Barrel/Page.php';
6
7 $page = new DiogenesAdmin;
8 $bbarrel =& $page->barrel;
9
10 // rcs handle
11 $rcs = $page->getRcs();
12
13 // translations
14 $page->assign('msg_submit',__("Submit"));
15 $page->assign('msg_reset',__("Reset"));
16 $page->assign('msg_properties',__("Page properties"));
17 $page->assign('msg_parent',__("parent page"));
18 $page->assign('msg_location',__("location"));
19 $page->assign('msg_title',__("title"));
20 $page->assign('msg_page_template',__("page template"));
21 $page->assign('msg_status',__("status"));
22 $page->assign('msg_access',__("access"));
23 $page->assign('msg_read_perms',__("read access"));
24 $page->assign('msg_write_perms',__("write access"));
25 $page->assign('msg_actions',__("actions"));
26 $page->assign('msg_add_page', array(__("Add a page"),"?action=edit") );
27
28 $page->assign('post', $page->script_self());
29 $page->assign('table', $bbarrel->table_page);
30 $page->assign('from', $_REQUEST['from']);
31 $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : "";
32 $target = isset($_REQUEST["target"]) ? $_REQUEST["target"] : "";
33
34 if (isset($_REQUEST["dir"])) {
35 $dir = $_REQUEST["dir"];
36 if (!$action) $action="edit";
37 } else {
38 $dir = 0;
39 }
40
41
42 /* add or update a page */
43 switch ($action) {
44 case "import":
45
46 // if needed, import a file
47 if ($globals->word_import && isset($_FILES['wordfile']) && is_uploaded_file($_FILES['wordfile']['tmp_name'])) {
48 $userfile = strtolower($_FILES['wordfile']['name']);
49 if (!substr($userfile,-4,4) == ".doc") {
50 $page->info(__("Document name does not end in .doc"));
51 } else {
52 $mydir = $bbarrel->spool->spoolPath($dir);
53 $page->info(__("Checking in Word file") . " $userfile");
54 $rcs->commit($dir, $globals->wordfile,
55 file_get_contents($_FILES['wordfile']['tmp_name']),
56 "Word file update $userfile" );
57
58 $page->info(__("Importing Word file") . " $userfile");
59 $rcs->importWordFile($dir, $globals->htmlfile, $_FILES['wordfile']['tmp_name']);
60 }
61 } else if (isset($_FILES['htmlfile']) && is_uploaded_file($_FILES['htmlfile']['tmp_name'])) {
62 $userfile = strtolower($_FILES['htmlfile']['name']);
63 if ( (substr($userfile,-4,4) == ".htm") || (substr($userfile,-5,5) == ".html") ) {
64 $page->info(__("Importing HTML file") . " $userfile");
65 $rcs->commit( $dir, $globals->htmlfile,
66 $rcs->importHtmlString(file_get_contents($_FILES['htmlfile']['tmp_name'])),
67 "html file import of $userfile" );
68 } else {
69 $page->info(__("Raw file import") . " $userfile");
70 $rcs->commit( $dir, $globals->htmlfile,
71 file_get_contents($_FILES['htmlfile']['tmp_name']),
72 "raw file import of $userfile" );
73 }
74 }
75 break;
76
77 case "update":
78 // page ID
79 $props['PID'] = $dir;
80
81 // page location
82 if (isset($_REQUEST['pedit_location'])) {
83 $homepage = 0;
84 $props['location'] = $_REQUEST['pedit_' . 'location'];
85 } else {
86 $homepage = 1;
87 $props['location'] = '';
88 }
89
90 // other properties
91 $kprops = array('parent', 'title', 'perms', 'wperms', 'status', 'template');
92 foreach ($kprops as $key) {
93 $props[$key] = $_REQUEST['pedit_' . $key];
94 }
95
96 $bpage = new Diogenes_Barrel_Page($bbarrel, $props);
97 if ($bpage->toDb($homepage, $page) && $_REQUEST['from'])
98 {
99 header("Location: {$_REQUEST['from']}");
100 exit;
101 }
102 break;
103 }
104
105 // retrieve all the barrel's page
106 $bpages = $bbarrel->getPages();
107
108
109 if ($dir)
110 {
111 $bpage = Diogenes_Barrel_Page::fromDb($bbarrel, $dir);
112 } else {
113 $tparent = empty($_REQUEST['parent']) ? $bbarrel->getPID('') : $_REQUEST['parent'];
114 //$page->info("parent $tparent");
115 $bpage = new Diogenes_Barrel_Page($bbarrel, array('parent' => $tparent));
116 }
117
118 // "Page" toolbar
119 //if (isset($bpage->props['PID'])) {
120 if ($dir != 0) {
121 $page->toolbar(__("Page"), $bpage->make_toolbar($page));
122 $page->toolbar(__("File"), $bpage->make_doc_toolbar($rcs));
123 }
124
125 // retrieve suitable parents for the current page
126 if (!$bpage->props['PID'] || strlen($bpage->props['location']))
127 {
128 $parent_all = array();
129 foreach($bpages as $pkey => $pval)
130 {
131 if (!$dir or (($pval->props['PID'] != $dir) and ($pval->props['parent'] != $dir)))
132 {
133 $parent_all[$pkey] = $pval;
134 }
135 }
136
137 $parent_opts = array();
138 foreach (array_keys($parent_all) as $pkey)
139 {
140 $ppage = $parent_all[$pkey];
141 if (!$ppage->props['parent'] or isset($parent_all[$ppage->props['parent']]))
142 {
143 $pageloc = $bbarrel->getLocation($pkey);
144 $parent_opts[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title'];
145 }
146 }
147 $page->assign('parent_opts', $parent_opts);
148 }
149
150 // messages
151 $gtitle = "";
152 if ($dir)
153 {
154 $gtitle = $bbarrel->getLocation($dir);
155 if (!$gtitle) $gtitle = __("home");
156 }
157 $page->assign('greeting',__("Page manager") . ($gtitle ? " - $gtitle" : "") );
158
159 $page->assign('html',__("Import HTML"));
160 $page->assign('htmlblab',__("You can replace the current page's contents by uploading an HTML file below."));
161 $page->assign('htmlstrip',__("If the file name ends with .htm or .html, anything outside the &lt;body&gt;&lt;/body&gt; pair will be stripped."));
162 $page->assign('send',__("Send"));
163
164 $page->assign('dir',$dir);
165 $page->assign('page_obj', $bpage->props);
166 $page->assign('status_opts',array(0=>__("visible"), 1=>__("under construction"), 2=>__("disabled"), 3=>__("archived")));
167 $page->assign('templates',$page->getTemplates());
168
169 if ($globals->word_import) {
170
171 $page->assign('word',__("Import a Word document"));
172
173 if (file_exists($bbarrel->spool->spoolPath($dir,$globals->wordfile)) )
174 {
175 $page->assign('wordblab', __("This page's master document is currently a Word document."));
176 $page->assign('wordsend', __("You can upload a new version of the Word document below."));
177 $page->assign('wordfile', __("You can get the current version of the file here"));
178 $page->assign('wordlnk', array($globals->wordfile,$page->urlSite((strlen($bpage->props['location']) ? $bpage->props['location'].'/' : '') . $globals->wordfile)) );
179 } else {
180 $page->assign('wordblab', __("If you wish, you can set this page's content from a Word document."));
181 $page->assign('wordsend', __("To do so, simply upload the Word document below."));
182 }
183 }
184
185 $page->display('page-properties.tpl');
186 ?>