function showmenu() { global $lang; global $conf; global $user; global $admin; global $site; $site->title($lang['admin']['menu']); $site->addfooter("help.php?on=admin", "help", $lang['menu']['help'], $lang['menu']['helpalt']); $dialog = new CodeKBTemplate("dialog"); $dialog->push("legend", $lang['admin']['menu']); if ($conf['layout']['adminstatistics']) { $stats = $admin->statistics(); $unit = "b"; $size = $stats['size']; if ($size > 1024) { $size /= 1024; $unit = "kb"; } if ($size > 1024) { $size /= 1024; $unit = "mb"; } $size = round($size) . $unit; $dialogitem1 = new CodeKBTemplate("dialogitem"); $dialogitem1->push("head", $lang['admin']['statistics']); $content = "<br /><br />\n"; $content = "<ul>\n"; $content .= "<li>" . phrasereplace($lang['admin']['statusers'], "%1%", $stats['users'] - 1) . "</li>\n"; $content .= "<li>" . phrasereplace($lang['admin']['statgroups'], "%1%", $stats['groups'] - 1) . "</li>\n"; $content .= "<li>" . phrasereplace($lang['admin']['statcats'], "%1%", $stats['cats']) . "</li>\n"; $content .= "<li>" . phrasereplace($lang['admin']['statentries'], "%1%", $stats['entries']) . "</li>\n"; $content .= "<li>" . phrasereplace(phrasereplace($lang['admin']['statfiles'], "%1%", $stats['files']), "%2%", $size) . "</li>\n"; $content .= "</ul>\n"; $dialogitem1->push("content1", $content); } $dialogitem2 = new CodeKBTemplate("dialogitem"); $dialogitem2->push("head", $lang['admin']['menuexplain']); $content = "<br /><br />\n"; $content .= icon("group", $lang['admin']['modifygroups']) . " " . url("admin.php?action=groups", $lang['admin']['modifygroups']) . "<br />\n"; $content .= icon("user", $lang['admin']['modifyusers']) . " " . url("admin.php?action=users", $lang['admin']['modifyusers']) . "<br />\n"; $content .= icon("lock", $lang['admin']['modifynobody']) . " " . url("admin.php?group=0&action=modifygroup", $lang['admin']['modifynobody']) . "<br />\n"; $dialogitem2->push("content1", $content); $content = ""; if ($conf['layout']['adminstatistics']) { $content .= $dialogitem1->__toString(); } $content .= $dialogitem2->__toString(); $dialog->push("content", $content); $site->addcontent($dialog); return true; }
function showlogin() { global $lang; global $site; global $user; $site->title($lang['login']['title']); $site->addfooter("help.php?on=login", "help", $lang['menu']['help'], $lang['menu']['helpalt']); if ($_POST['cancel']) { redirect("home.php"); } $form = new CodeKBForm("login.php", "login"); $form->addtext("user"); $form->addlabel("user", $lang['general']['username']); $form->setrequired("user"); $form->addpassword("password"); $form->addlabel("password", $lang['general']['password']); $form->setrequired("password"); $form->addcheckbox("cookie", $lang['login']['cookie']); $form->addsubmit(); $form->addcancel(); if ($_POST['submit']) { if (!$form->fill()) { $site->addcontent(notice($lang['general']['missing'])); } else { try { $user->login($form->value("user"), $form->value("password")); if ($form->value("cookie")) { $user->cookie(); } redirect("home.php"); } catch (Exception $e) { // A small penalty sleep(3); $site->addcontent(notice($lang['login']['failed'])); $form->setmissing("user"); $form->setmissing("password"); } } } $dialog = new CodeKBTemplate("dialog"); $dialog->push("legend", $lang['login']['title']); $content = $form->head(); $content .= phrasereplace($lang['login']['description'], "%1%", url("login.php?action=register", $lang['login']['register'])) . "<br /><br />\n"; $content .= $form->get(); $content .= $form->tail(); $dialog->push("content", $content); $site->addcontent($dialog); return true; }
function showfile() { global $lang; global $conf; global $user; global $site; global $catid; global $file; $site->title($file->name()); $site->addfooter("help.php?on=file", "help", $lang['menu']['help'], $lang['menu']['helpalt']); if ($file->highlight() == $conf['highlight']['binary']) { redirect("file.php?id=" . $file->id() . "&action=download"); } if ($user->entrycan("changeentry", $file->entry())) { $site->addmenu("file.php?id=" . $file->id() . "&cat=" . $catid . "&action=modify", $lang['menu']['file'], $lang['menu']['filealt']); $site->addfooter("file.php?id=" . $file->id() . "&cat=" . $catid . "&action=modify", "configure", $lang['menu']['file'], $lang['menu']['filealt']); $site->addfooter("entry.php?id=" . $file->entry()->id() . "&cat=" . $catid . "&action=files", "files", $lang['menu']['attach'], $lang['menu']['attachalt']); } $entrytpl = new CodeKBTemplate("entry"); $entrytpl->push("icon", icon($file->symbol(), $file->name())); $entrytpl->push("name", $file->name()); $content = $lang['entry']['createdate'] . ": <em>" . $file->created() . "</em> | "; $content .= $lang['entry']['modifydate'] . ": <em>" . ($file->modified() ? $file->modified() : $lang['general']['never']) . "</em>\n<br />\n"; $content .= $lang['file']['download'] . ": "; $content .= url("file.php?id=" . $file->id() . "&action=download", $file->name()); $content .= " ("; $unit = "b"; $size = $file->size(); if ($size > 1024) { $size /= 1024; $unit = "kb"; } if ($size > 1024) { $size /= 1024; $unit = "mb"; } $content .= round($size) . $unit . ") | "; $content .= url("entry.php?id=" . $file->entry()->id() . "&cat=" . $catid, phrasereplace($lang['general']['backto'], "%1%", htmlentities($file->entry()->name())), $file->entry()->name()); $entrytpl->push("subheader", $content); $code = "[code=" . $file->highlight() . "]"; $code .= $file->content(); $code .= "[/code]"; $entrytpl->push("documentation", parsebbcode($code)); $site->addcontent($entrytpl); return true; }
function showdelete() { global $lang; global $user; global $site; global $conf; global $category; $site->title($lang['category']['delete']); $site->addfooter("help.php?on=category#del", "help", $lang['menu']['help'], $lang['menu']['helpalt']); if (!$user->can("delcat", $category)) { $site->addcontent(notice($lang['category']['nodelallowed'])); return false; } if ($_POST['cancel']) { redirect("category.php?id=" . $category->id()); } $form = new CodeKBForm("category.php", "delete"); $form->addhidden("id", $category->id()); $form->addbutton("submit"); $form->addbutton("cancel"); if ($_POST['submit']) { try { $category->delete(); redirect("category.php?id=" . $category->parent()); } catch (Exception $e) { if ($e->getCode() == 1) { $site->addcontent(notice($lang['category']['faileddelrecursion'])); } else { $site->addcontent(notice($lang['category']['faileddel'])); } } } $dialog = new CodeKBTemplate("dialog"); $dialog->push("legend", $lang['category']['delete']); $dialogitem = new CodeKBTemplate("dialogitem"); $content = $form->head(); $content .= phrasereplace($lang['category']['deleteexplain'], "%1%", htmlentities($category->name())) . "<br />\n"; if (count($category->listcategories()) || count($category->listentries())) { $content .= $lang['category']['deletenotempty'] . "<br />\n"; } $content .= $lang['general']['areyousure'] . "<br />\n"; $dialogitem->push("head", $content); $dialogitem->push("tail", "<br />\n" . $form->tail()); $dialog->push("content", $dialogitem); $site->addcontent($dialog); return true; }
function showsearch() { global $lang; global $conf; global $site; global $user; $site->title($lang['search']['results']); $site->addfooter("search.php", "search", $lang['search']['extended']); if ($_POST['cancel']) { redirect("category.php"); } if (!$_POST['query'] && !$_POST['author'] && !$_POST['cats']) { $site->addcontent(notice($lang['search']['noquery'])); return false; } $start_search = microtime(true); $db = new CodeKBDatabase(); $searchquery = buildsearchquery($db->type()); try { $db->dosql($searchquery); } catch (Exception $e) { $site->addcontent(notice($lang['search']['wrongquery'])); } $end_search = microtime(true); $search = new CodeKBTemplate("search"); $search->push("extended", url("search.php", $lang['search']['extended'])); $text = phrasereplace($lang['search']['xresultsiny'], "%1%", $db->countrows()); $text = phrasereplace($text, "%2%", round($end_search - $start_search, 2)); $search->push("info", $text); $resultcode = ""; while ($val = $db->row()) { try { $tmpentry = new CodeKBEntry($val['id'], $user); unset($tmpentry); } catch (Exception $e) { continue; } $resultitem = new CodeKBTemplate("result"); $content = url("entry.php?id=" . $val['id'], icon($val['symbol'], $val['name'])) . " \n"; $content .= url("entry.php?id=" . $val['id'], htmlentities($val['name']), $val['name']); $resultitem->push("title", $content); $content = $db->datetime($val['created']) . " (" . htmlentities($val['author']) . ")"; $resultitem->push("subtitle", $content); $resultitem->push("description", htmlentities($val['description'])); $resultcode .= $resultitem->__toString(); unset($resultitem); } $search->push("results", $resultcode); $site->addcontent($search); return true; }
function showlinks() { global $lang; global $user; global $site; global $category; global $entry; $site->title($lang['entry']['link']); $site->addfooter("help.php?on=entry#link", "help", $lang['menu']['help'], $lang['menu']['helpalt']); if (!$user->entrycan("delentry", $entry) && !$user->entrycan("addentry", $entry)) { $site->addcontent(notice($lang['entry']['nochangeallowed'])); return false; } if ($category) { $cat = $category->id(); } if ($_POST['cancel']) { redirect("entry.php?id=" . $entry->id() . "&cat=" . $cat); } if ($user->entrycan("addentry", $entry)) { $form1 = new CodeKBForm("entry.php", "link"); $form1->addhidden("id", $entry->id()); $form1->addhidden("cat", $cat); $tmpcat = new CodeKBCategory(0, $user); if ($user->can("addentry", $tmpcat)) { $form1->addcombo("newcat", "0", $lang['category']['root']); } $array = $tmpcat->listcategories("name", 1); foreach ($array as $val) { if ($user->can("addentry", $val['id'])) { $form1->addcombo("newcat", $val['id'], str_repeat("-", $val['reclevel'] * 2) . " " . $val['name']); } } unset($tmpcat); $form1->addlabel("newcat", $lang['entry']['linkadd']); $form1->addsubmit("addlink"); $form1->addcancel(); } if ($user->entrycan("delentry", $entry)) { $form2 = new CodeKBForm("entry.php", "link"); $form2->addhidden("id", $entry->id()); $form2->addhidden("cat", $cat); $catsofentry = $entry->categories(); foreach ($catsofentry as $val) { $thiscat = new CodeKBCategory($val, $user); $form2->addcheckbox("cat_" . $thiscat->id(), $thiscat->name()); unset($thiscat); } $form2->addsubmit("unlink", $lang['general']['delete']); $form2->addcancel(); } if ($_POST['addlink'] && $form1->fill()) { try { $newcat = new CodeKBCategory($form1->value("newcat"), $user); if ($entry->addlink($form1->value("newcat"))) { $site->addcontent(notice(phrasereplace($lang['entry']['linkaddsucc'], "%1%", $newcat->name()))); if ($form2) { $form2->addcheckbox("cat_" . $newcat->id(), $newcat->name()); } } else { $site->addcontent(notice($lang['entry']['failedchange'])); } unset($newcat); } catch (Exception $e) { if ($e->getCode() == 1) { $site->addcontent(notice($lang['entry']['duplicate'])); $form1->setmissing("newcat"); } else { $site->addcontent(notice($lang['entry']['failedchange'])); } } } if ($_POST['unlink'] && is_object($form2) && $form2->fill()) { $id = $entry->id(); foreach ($catsofentry as $val) { if ($form2->value("cat_" . $val) == "1") { try { $entry->delink($val); $notice = $lang['entry']['linkremovesucc']; $form2->remove("cat_" . $val); } catch (Exception $e) { $form2->setmissing("cat_" . $val); $notice = $lang['entry']['failedunlink']; break; } } } if (!$user->entrycan("see", $entry, false)) { redirect("category.php?id=" . $cat); } $site->addcontent(notice($notice)); } $dialog = new CodeKBTemplate("dialog"); $dialog->push("legend", $lang['entry']['link']); $dialogcode = ""; if ($form1) { $dialogitem1 = new CodeKBTemplate("dialogitem"); $content = $form1->head(); $content .= $lang['entry']['linkaddexplain'] . "<br /><br />\n"; $dialogitem1->push("head", $content); $dialogitem1->push("content1", $form1->get()); $dialogitem1->push("tail", $form1->tail()); $dialogcode .= $dialogitem1->__toString(); } if ($form2) { $dialogitem2 = new CodeKBTemplate("dialogitem"); $content = $form2->head(); $content .= $lang['entry']['linkremoveexplain'] . "<br /><br />\n"; $dialogitem2->push("head", $content); $content = "<div class = \"forms\">\n"; $content .= $form2->get(); $content .= "</div>"; $dialogitem2->push("content1", $content); $dialogitem2->push("tail", $form2->tail()); $dialogcode .= $dialogitem2->__toString(); } $dialog->push("content", $dialogcode); $site->addcontent($dialog); return true; }