| 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 | |
| 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 | $bpage->toDb($homepage, $page); |
| 98 | break; |
| 99 | |
| 100 | |
| 101 | case "page_delete": |
| 102 | Diogenes_Barrel_Page::delete($bbarrel, $target, $page); |
| 103 | break; |
| 104 | } |
| 105 | |
| 106 | // retrieve all the barrel's page |
| 107 | $bpages = $bbarrel->getPages(); |
| 108 | |
| 109 | |
| 110 | if ($dir) |
| 111 | { |
| 112 | $bpage = Diogenes_Barrel_Page::fromDb($bbarrel, $dir); |
| 113 | } else { |
| 114 | $tparent = empty($_REQUEST['parent']) ? $bbarrel->getPID('') : $_REQUEST['parent']; |
| 115 | //$page->info("parent $tparent"); |
| 116 | $bpage = new Diogenes_Barrel_Page($bbarrel, array('parent' => $tparent)); |
| 117 | } |
| 118 | |
| 119 | // "Page" toolbar |
| 120 | //if (isset($bpage->props['PID'])) { |
| 121 | if ($dir != 0) { |
| 122 | $page->toolbar(__("Page"), $bpage->make_toolbar()); |
| 123 | $page->toolbar(__("File"), $bpage->make_doc_toolbar($rcs)); |
| 124 | } |
| 125 | |
| 126 | // retrieve suitable parents for the current page |
| 127 | if (!$bpage->props['PID'] || strlen($bpage->props['location'])) |
| 128 | { |
| 129 | $parent_all = array(); |
| 130 | foreach($bpages as $pkey => $pval) |
| 131 | { |
| 132 | if (!$dir or (($pval->props['PID'] != $dir) and ($pval->props['parent'] != $dir))) |
| 133 | { |
| 134 | $parent_all[$pkey] = $pval; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | $parent_opts = array(); |
| 139 | foreach (array_keys($parent_all) as $pkey) |
| 140 | { |
| 141 | $ppage = $parent_all[$pkey]; |
| 142 | if (!$ppage->props['parent'] or isset($parent_all[$ppage->props['parent']])) |
| 143 | { |
| 144 | $pageloc = $bbarrel->getLocation($pkey); |
| 145 | $parent_opts[$pkey] = ( strlen($pageloc) ? "<$pageloc> " : "") . $ppage->props['title']; |
| 146 | } |
| 147 | } |
| 148 | $page->assign('parent_opts', $parent_opts); |
| 149 | } |
| 150 | |
| 151 | // messages |
| 152 | $gtitle = ""; |
| 153 | if ($dir) |
| 154 | { |
| 155 | $gtitle = $bbarrel->getLocation($dir); |
| 156 | if (!$gtitle) $gtitle = __("home"); |
| 157 | } |
| 158 | $page->assign('greeting',__("Page manager") . ($gtitle ? " - $gtitle" : "") ); |
| 159 | |
| 160 | $page->assign('html',__("Import HTML")); |
| 161 | $page->assign('htmlblab',__("You can replace the current page's contents by uploading an HTML file below.")); |
| 162 | $page->assign('htmlstrip',__("If the file name ends with .htm or .html, anything outside the <body></body> pair will be stripped.")); |
| 163 | $page->assign('send',__("Send")); |
| 164 | |
| 165 | $page->assign('dir',$dir); |
| 166 | $page->assign('page_obj', $bpage->props); |
| 167 | $page->assign('status_opts',array(0=>__("visible"), 1=>__("under construction"), 2=>__("disabled"), 3=>__("archived"))); |
| 168 | $page->assign('templates',$page->getTemplates()); |
| 169 | |
| 170 | if ($globals->word_import) { |
| 171 | |
| 172 | $page->assign('word',__("Import a Word document")); |
| 173 | |
| 174 | if (file_exists($bbarrel->spool->spoolPath($dir,$globals->wordfile)) ) |
| 175 | { |
| 176 | $page->assign('wordblab', __("This page's master document is currently a Word document.")); |
| 177 | $page->assign('wordsend', __("You can upload a new version of the Word document below.")); |
| 178 | $page->assign('wordfile', __("You can get the current version of the file here")); |
| 179 | $page->assign('wordlnk', array($globals->wordfile,$page->urlSite((strlen($bpage->props['location']) ? $bpage->props['location'].'/' : '') . $globals->wordfile)) ); |
| 180 | } else { |
| 181 | $page->assign('wordblab', __("If you wish, you can set this page's content from a Word document.")); |
| 182 | $page->assign('wordsend', __("To do so, simply upload the Word document below.")); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | $page->display('page-properties.tpl'); |
| 187 | ?> |