function notice($message)
{
    $notice = new CodeKBTemplate("notice");
    $notice->push("message", htmlentities($message));
    return $notice;
}
Example #2
0
function showusermod()
{
    global $lang;
    global $conf;
    global $user;
    global $admin;
    global $site;
    global $userid;
    $site->title($lang['admin']['modifyusers']);
    $site->addfooter("help.php?on=admin#user", "help", $lang['menu']['help'], $lang['menu']['helpalt']);
    if ($_POST['cancel']) {
        redirect("admin.php");
    }
    $form1 = new CodeKBForm("admin.php", "modifyuser");
    $form1->addhidden("user", $userid);
    $form1->addtext("name", $admin->username($userid));
    $form1->addlabel("name", $lang['general']['username']);
    $form1->setrequired("name");
    $form1->addpassword("password");
    $form1->addlabel("password", $lang['admin']['password']);
    $form1->addcheckbox("delete", $lang['admin']['deleteuser']);
    $form1->addsubmit("changeuser");
    $form1->addcancel();
    $form2 = new CodeKBForm("admin.php", "modifyuser");
    $form2->addhidden("user", $userid);
    $groups = $admin->listgroups();
    foreach ($groups as $val) {
        if (!is_null($val['name'])) {
            $form2->addcombo("group", $val['id'], $val['name']);
        }
    }
    $form2->addsubmit("joingroup");
    $form2->addcancel();
    $form3 = new CodeKBForm("admin.php", "modifyuser");
    $form3->addhidden("user", $userid);
    $usersgroups = $admin->usersgroups($userid);
    foreach ($usersgroups as $val) {
        if (!is_null($val['name'])) {
            $form3->addcheckbox("group_" . $val['id'], $val['name'] . " (" . url("admin.php?group=" . $val['id'] . "&action=modifygroup", $lang['general']['modify']) . ")");
        }
    }
    $form3->addsubmit("partgroup", $lang['general']['delete']);
    $form3->addcancel();
    if ($_POST['changeuser']) {
        if (!$form1->fill()) {
            $site->addcontent(notice($lang['general']['missing']));
        } else {
            if ($form1->value("delete")) {
                try {
                    $admin->deleteuser($userid);
                    redirect("admin.php?action=users");
                } catch (Exception $e) {
                    if ($e->getCode() == 1) {
                        $site->addcontent(notice($lang['admin']['deleteadmin']));
                    } else {
                        $site->addcontent(notice($lang['admin']['faileddeluser']));
                    }
                }
            } else {
                try {
                    $admin->changeuser($userid, $form1->value("name"), $form1->value("password"));
                    $site->addcontent(notice($lang['admin']['changeusersucc']));
                    $form1->addpassword("password", "");
                } catch (Exception $e) {
                    if ($e->getCode() == 1) {
                        $site->addcontent(notice($lang['admin']['duplicateuser']));
                        $form1->setmissing("name");
                    } else {
                        $site->addcontent(notice($lang['admin']['failesuserchange']));
                    }
                }
            }
        }
    }
    if ($_POST['joingroup'] && $form2->fill() && $form2->value("group")) {
        try {
            $admin->joingroup($userid, $form2->value("group"));
            $site->addcontent(notice($lang['admin']['joinsucc']));
            $form3->addcheckbox("group_" . $form2->value("group"), $admin->groupname($form2->value("group")) . " (" . url("admin.php?group=" . $form2->value("group") . "&action=modifygroup", $lang['general']['modify']) . ")");
        } catch (Exception $e) {
            if ($e->getCode() == 1) {
                $site->addcontent(notice($lang['admin']['alreadyingroup']));
            } else {
                $site->addcontent(notice($lang['admin']['failedjoin']));
            }
        }
    }
    if ($_POST['partgroup'] && $form3->fill()) {
        try {
            foreach ($usersgroups as $val) {
                if ($form3->value("group_" . $val['id'])) {
                    $admin->partgroup($userid, $val['id']);
                    $notice = $lang['admin']['partsucc'];
                    $form3->remove("group_" . $val['id']);
                }
            }
        } catch (Exception $e) {
            $notice = $lang['admin']['failedpart'];
        }
        $site->addcontent(notice($notice));
    }
    $dialog = new CodeKBTemplate("dialog");
    $dialog->push("legend", $lang['admin']['modifyusers']);
    $dialogitem1 = new CodeKBTemplate("dialogitem");
    $content = $form1->head();
    $content .= $lang['admin']['changeuserexplain'] . "<br /><br />\n";
    $dialogitem1->push("head", $content);
    $dialogitem1->push("content1", $form1->get());
    $dialogitem1->push("tail", $form1->tail());
    $dialogitem2 = new CodeKBTemplate("dialogitem");
    $content = $form2->head();
    $content .= $lang['admin']['joinuserexplain'] . "<br /><br />\n";
    $dialogitem2->push("head", $content);
    $dialogitem2->push("content1", $form2->get());
    $dialogitem2->push("tail", $form2->tail());
    $dialogitem3 = new CodeKBTemplate("dialogitem");
    $content = $form3->head();
    $content .= $lang['admin']['partuserexplain'] . "<br /><br />\n";
    $dialogitem3->push("head", $content);
    $content = "<div class = \"forms\">";
    $content .= $form3->get();
    $content .= "</div>";
    $dialogitem3->push("content1", $content);
    $dialogitem3->push("tail", $form3->tail());
    $dialogcode = $dialogitem1->__toString();
    $dialogcode .= $dialogitem2->__toString();
    $dialogcode .= $dialogitem3->__toString();
    $dialog->push("content", $dialogcode);
    $site->addcontent($dialog);
    return true;
}
 public function output()
 {
     global $conf;
     global $lang;
     $header = new CodeKBTemplate("header");
     $header->push("stylesheet", $conf['general']['stylesheet']);
     $header->push("favicon", $conf['general']['imagepath'] . "/codekb.ico");
     $header->push("title", $this->_title);
     $header->push("headline", $conf['general']['title']);
     array_unshift($this->_menu, array("home.php", $lang['menu']['home'], $lang['menu']['homealt']), array("category.php", $lang['menu']['browse'], $lang['menu']['browsealt']));
     if ($this->_user->isadmin()) {
         array_push($this->_menu, array("admin.php", $lang['menu']['admin'], $lang['menu']['adminalt']));
     }
     if ($this->_user->valid()) {
         array_push($this->_menu, array("login.php?action=logout", $lang['menu']['logout'] . " [<em>" . htmlentities($this->_user->name()) . "</em>]", $lang['menu']['logoutalt']));
     } else {
         array_push($this->_menu, array("login.php", $lang['menu']['login'], $lang['menu']['loginalt']));
     }
     $menuitems = "";
     while ($menuentry = array_shift($this->_menu)) {
         $menuitems .= "\t\t" . url($menuentry[0], $menuentry[1], $menuentry[2]);
         if (count($this->_menu) != 0) {
             $menuitems .= " | \n";
         }
     }
     $search = new CodeKBForm("search.php", "search");
     $search->addtext("query");
     $menuitems .= $search->head();
     $searchstring = url("help.php", $lang['menu']['help'], $lang['menu']['helpalt']) . " | \n";
     $searchstring .= url("search.php", $lang['menu']['search'], $lang['menu']['searchalt']) . " \n";
     $searchstring .= $search->get("query");
     $tail = $search->tail();
     $menu = new CodeKBTemplate("menu");
     $menu->push("menu", $menuitems);
     $menu->push("search", $searchstring);
     $menu->push("tail", $tail);
     echo $header;
     echo $menu;
     if ($this->_navigation) {
         echo $this->_navigation;
     }
     echo $this->_content;
     $footeritems = "";
     while ($menuentry = array_shift($this->_footer)) {
         $footeritems .= "\t\t" . url($menuentry[0], icon($menuentry[1], $menuentry[2]), $menuentry[3]) . " \n";
         $footeritems .= "\t\t" . url($menuentry[0], $menuentry[2], $menuentry[3]) . "&nbsp; \n";
     }
     if ($conf['layout']['jumptonavigation']) {
         $footerform = new CodeKBForm("category.php", "list");
         $tmpcat = new CodeKBCategory(0, $this->_user);
         $footerform->addcombo("id", "0", $lang['category']['root'], $this->_catid == 0, "jump");
         $array = $tmpcat->listcategories("name", 1);
         foreach ($array as $val) {
             if ($this->_user->can("see", $val['id'])) {
                 $footerform->addcombo("id", $val['id'], str_repeat("-", $val['reclevel'] * 2) . " " . $val['name'], $this->_catid == $val['id'], "jump");
             }
         }
         unset($tmpcat);
         $footerform->addbutton("jump", $lang['general']['go']);
         $navi = $footerform->head();
         $navi .= $footerform->get("id");
         $navi .= $footerform->tail();
     }
     $query_num = CodeKBDatabase::querycount();
     $endtime = microtime(true);
     $debug = "";
     if ($conf['err']['debug']) {
         CodeKBException::backtrace();
         $debug = "<span style=\"font-size: xx-small;\">(Execution time: " . round($endtime - $this->_starttime, 4) . " / " . $query_num . " Queries)</span>";
     }
     $footer = new CodeKBTemplate("footer");
     $footer->push("footer", $footeritems);
     $footer->push("runtime", $debug);
     $footer->push("navigation", $navi);
     echo $footer;
 }
Example #4
0
function showinput()
{
    global $lang;
    global $conf;
    global $user;
    global $site;
    global $catid;
    global $file;
    $site->title($lang['file']['modify']);
    $site->addfooter("help.php?on=file#change", "help", $lang['menu']['help'], $lang['menu']['helpalt']);
    if (!$user->entrycan("changeentry", $file->entry())) {
        $site->addcontent(notice($lang['entry']['nochangeallowed']));
        return false;
    }
    if ($_POST['cancel']) {
        redirect("entry.php?id=" . $file->entry()->id());
    }
    $form = new CodeKBForm("file.php", "modify");
    $form->addhidden("id", $file->id());
    $form->addhidden("cat", $catid);
    $form->addtext("name", $file->name());
    $form->addlabel("name", $lang['file']['name']);
    $form->setrequired("name");
    $form->addfile("upload");
    $form->addlabel("upload", $lang['file']['upload']);
    $form->addcombo("highlight", $conf['highlight']['binary'], null, $conf['highlight']['binary'] == $file->highlight());
    foreach ($conf['highlight']['languages'] as $language) {
        $form->addcombo("highlight", $language, null, $language == $file->highlight());
    }
    $form->addlabel("highlight", $lang['file']['language']);
    $db = new CodeKBDatabase();
    $db->dosql("SELECT name, symbol " . "FROM symbols " . "WHERE symbol LIKE 'type_%'");
    while ($val = $db->row()) {
        $form->addradio("symbol", $val['name'], icon($val['name'], $val['name']), $val['name'] == $file->symbol(), false);
    }
    $form->addbutton("submit");
    $form->addbutton("cancel");
    if ($_POST['submit']) {
        if (!$form->fill()) {
            $site->addcontent(notice($lang['general']['missing']));
        } else {
            global $HTTP_POST_FILES;
            if (is_uploaded_file($HTTP_POST_FILES['upload']['tmp_name'])) {
                $upload = "upload";
            } else {
                $upload = false;
            }
            try {
                $file->change($form->value("name"), $form->value("highlight"), $form->value("symbol"), $upload);
                if ($form->value("highlight") == $conf['highlight']['binary']) {
                    redirect("entry.php?id=" . $file->entry()->id() . "&cat=" . $catid);
                } else {
                    redirect("file.php?id=" . $file->id() . "&cat=" . $catid);
                }
            } catch (Exception $e) {
                $site->addcontent(notice($lang['entry']['failedfilechange']));
            }
        }
    }
    $dialog = new CodeKBTemplate("dialog");
    $dialog->push("legend", $lang['file']['modify']);
    $dialogitem = new CodeKBTemplate("dialogitem");
    $content = $form->head();
    $content .= $form->get("name");
    $dialogitem->push("top", $content);
    $dialogitem->push("head", "(" . $lang['file']['newuploadexplain'] . ")<br />\n");
    $dialogitem->push("content1", $form->get());
    $dialogitem->push("tail", $form->tail());
    $dialog->push("content", $dialogitem);
    $site->addcontent($dialog);
    return true;
}
Example #5
0
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;
}
Example #6
0
function showregister()
{
    global $lang;
    global $site;
    global $user;
    $site->title($lang['register']['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", "register");
    $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->addpassword("password2");
    $form->addlabel("password2", $lang['register']['passwordagain']);
    $form->setrequired("password2");
    $form->addsubmit();
    $form->addcancel();
    if ($_POST['submit']) {
        if (!$form->fill()) {
            $site->addcontent(notice($lang['general']['missing']));
        } else {
            if ($form->value("password") != $form->value("password2")) {
                $site->addcontent(notice($lang['register']['wrongpass']));
                $form->setmissing("password");
                $form->setmissing("password2");
            } else {
                try {
                    $user->register($form->value("user"), $form->value("password"));
                    redirect("login.php?action=registered");
                } catch (Exception $e) {
                    if ($e->getCode() == 1) {
                        $site->addcontent(notice($lang['register']['duplicate']));
                        $form->setmissing("user");
                        $form->setmissing("password");
                        $form->setmissing("password2");
                    } else {
                        $site->addcontent(notice($lang['register']['failed']));
                    }
                }
            }
        }
    }
    $dialog = new CodeKBTemplate("dialog");
    $dialog->push("legend", $lang['register']['title']);
    $content = $form->head();
    $content .= $lang['register']['description'] . "<br /><br />\n";
    $content .= $form->get();
    $content .= $form->tail();
    $dialog->push("content", $content);
    $site->addcontent($dialog);
    return true;
}
Example #7
0
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;
}
Example #8
0
function showfiles()
{
    global $lang;
    global $conf;
    global $user;
    global $site;
    global $category;
    global $entry;
    $site->title($lang['entry']['files']);
    $site->addfooter("help.php?on=file", "help", $lang['menu']['help'], $lang['menu']['helpalt']);
    if ($category) {
        $cat = $category->id();
    }
    if (!$user->entrycan("changeentry", $entry)) {
        $site->addcontent(notice($lang['entry']['nochangeallowed']));
        return false;
    }
    if ($_POST['cancel']) {
        redirect("entry.php?id=" . $entry->id() . "&cat=" . $cat);
    }
    $form1 = new CodeKBForm("entry.php", "files");
    $form1->addhidden("id", $entry->id());
    $form1->addhidden("cat", $cat);
    $form1->addfile("upload");
    $form1->addlabel("upload", $lang['file']['upload']);
    $form1->addcombo("highlight", $conf['highlight']['binary']);
    while ($language = next($conf['highlight']['languages'])) {
        $form1->addcombo("highlight", $language, null, $language == "text");
    }
    $form1->addlabel("highlight", $lang['file']['language']);
    $db = new CodeKBDatabase();
    $db->dosql("SELECT name, symbol " . "FROM symbols " . "WHERE symbol LIKE 'type_%'");
    while ($val = $db->row()) {
        $form1->addradio("symbol", $val['name'], icon($val['name'], $val['name']), $val['name'] == "Unkown", false);
    }
    $form1->addsubmit("addfile");
    $form1->addcancel();
    $form2 = new CodeKBForm("entry.php", "files");
    $form2->addhidden("id", $entry->id());
    $form2->addhidden("cat", $cat);
    $filesofentry = $entry->listfiles();
    foreach ($filesofentry as $val) {
        $form2->addcheckbox("file_" . $val['id'], icon($val['symbol'], $val['name']) . " " . $val['name'] . " (" . url("file.php?id=" . $val['id'] . "&cat=" . $cat . "&action=modify", $lang['general']['modify']) . ")");
    }
    $form2->addsubmit("removefile", $lang['general']['delete']);
    $form2->addcancel();
    if ($_POST['addfile'] && $form1->fill()) {
        try {
            $ret = $entry->addfile("upload", $form1->value("highlight"), $form1->value("symbol"));
            $newfile = new CodeKBFile($ret, $user);
            $site->addcontent(notice($lang['file']['addsucc']));
            $form2->addcheckbox("file_" . $newfile->id(), icon($newfile->symbol(), $newfile->name()) . " " . $newfile->name() . " (" . url("file.php?id=" . $newfile->id() . "&cat=" . $cat . "&action=modify", $lang['general']['modify']) . ")");
            unset($newfile);
        } catch (Exception $e) {
            if ($e->getCode() == 1) {
                $site->addcontent(notice($lang['file']['uploadfailed']));
            } else {
                $site->addcontent(notice($lang['file']['failedadd']));
            }
        }
    }
    if ($_POST['removefile'] && $form2->fill()) {
        foreach ($filesofentry as $val) {
            try {
                if ($form2->value("file_" . $val['id']) == "1") {
                    $tmpfile = new CodeKBFile($val['id'], $user);
                    $tmpfile->delete();
                    unset($tmpfile);
                    $notice = $lang['file']['delsucc'];
                    $form2->remove("file_" . $val['id']);
                }
            } catch (Exception1 $e) {
                $notice = $lang['file']['failedremove'];
                break;
            }
        }
        $site->addcontent(notice($notice));
    }
    $dialog = new CodeKBTemplate("dialog");
    $dialog->push("legend", $lang['entry']['files']);
    $dialogcode = "";
    $dialogitem1 = new CodeKBTemplate("dialogitem");
    $content = $form1->head();
    $content .= $lang['file']['addexplain'] . "<br /><br />\n";
    $dialogitem1->push("head", $content);
    $dialogitem1->push("content1", $form1->get());
    $dialogitem1->push("tail", $form1->tail());
    $dialogcode .= $dialogitem1->__toString();
    $content = $form2->head();
    $content .= $lang['file']['removeexplain'] . "<br /><br />\n";
    $dialogitem2 = new CodeKBTemplate("dialogitem");
    $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;
}