示例#1
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;
}
示例#2
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;
}
示例#3
0
function showlisting()
{
    global $lang;
    global $user;
    global $site;
    global $conf;
    global $category;
    $site->title($category->name());
    if ($user->can("addcat", $category)) {
        $site->addmenu("category.php?id=" . $category->id() . "&action=new", $lang['menu']['addcat'], $lang['menu']['addcatalt']);
        $site->addfooter("category.php?id=" . $category->id() . "&action=new", "newcat", $lang['menu']['addcat'], $lang['menu']['addcatalt']);
    }
    if ($user->can("addentry", $category)) {
        $site->addmenu("entry.php?cat=" . $category->id() . "&action=new", $lang['menu']['addentry'], $lang['menu']['addentryalt']);
        $site->addfooter("entry.php?cat=" . $category->id() . "&action=new", "newentry", $lang['menu']['addentry'], $lang['menu']['addentryalt']);
    }
    if ($category->id() != 0 && $user->can("changecat", $category)) {
        $site->addfooter("category.php?id=" . $category->id() . "&action=change", "configure", $lang['menu']['changecat'], $lang['menu']['changecatalt']);
    }
    if ($category->id() != 0 && $user->can("delcat", $category)) {
        $site->addfooter("category.php?id=" . $category->id() . "&action=delete", "delete", $lang['menu']['delcat'], $lang['menu']['delcatalt']);
    }
    $site->addfooter("help.php?on=category", "help", $lang['menu']['help'], $lang['menu']['helpalt']);
    // Sorting stuff
    $sort = $_SESSION['sort'] ? $_SESSION['sort'] : urldecode($_COOKIE['codekb_sort']);
    $order = $_SESSION['order'] != "" ? $_SESSION['order'] : urldecode($_COOKIE['codekb_order']);
    $age = $_SESSION['age'] != "" ? $_SESSION['age'] : urldecode($_COOKIE['codekb_age']);
    $whichage = $_SESSION['wage'] != "" ? $_SESSION['wage'] : urldecode($_COOKIE['codekb_wage']);
    $entriesperpage = $_SESSION['epp'] != "" ? $_SESSION['epp'] : urldecode($_COOKIE['codekb_epp']);
    if (!$entriesperpage) {
        $entriesperpage = $conf['layout']['entriesperpage'];
    }
    switch ($sort) {
        case $lang['sort']['sortbycreatedate']:
            $sort = "created";
            break;
        case $lang['sort']['sortbymodifydate']:
            $sort = "modified";
            break;
        case $lang['sort']['sortbyname']:
        default:
            $sort = "name";
    }
    switch ($order) {
        case $lang['sort']['descending']:
            $order = "DESC";
            break;
        case $lang['sort']['ascending']:
        default:
            $order = "ASC";
    }
    $sortorder = $sort . " " . $order;
    if ($age != $lang['search']['all'] && $whichage) {
        if ($whichage == $lang['sort']['sortbymodifydate']) {
            $wage = "modified";
        } else {
            $wage = "created";
        }
        switch ($age) {
            case $lang['search']['1day']:
                $age = 86400;
                break;
            case $lang['search']['7days']:
                $age = 604800;
                break;
            case $lang['search']['1month']:
                $age = 2592000;
                break;
            case $lang['search']['3months']:
                $age = 7776000;
                break;
            case $lang['search']['6months']:
                $age = 15552000;
                break;
            case $lang['search']['1year']:
                $age = 31536000;
                break;
            default:
                $age = time();
        }
        $filter = "AND entries." . CodeKBDatabase::string($wage) . " > '" . CodeKBDatabase::string(date("Y-m-d H:i:s", time() - $age)) . "' ";
    }
    if ($_GET['offset']) {
        $offset = $_GET['offset'];
    } else {
        $offset = 0;
    }
    $list = new CodeKBTemplate("listing");
    // Categories
    $categories = $category->listcategories();
    $i = 0;
    $count = 4;
    $listcode = "";
    foreach ($categories as $cat) {
        $listitem = new CodeKBTemplate("listitem");
        if ($i % $count == 0) {
            $listitem->push("first", true);
        }
        $listitem->push("icon", url("category.php?id=" . $cat['id'], icon("category", $cat['name']), $cat['name']) . "\n");
        $listitem->push("name", url("category.php?id=" . $cat['id'], htmlentities($cat['name']), $cat['name']));
        // Do we want to show subcategory and entry counts?
        if ($conf['layout']['showcounts']) {
            $listitem->push("catdescr", $lang['category']['subcats']);
            $listitem->push("entdescr", $lang['category']['entries']);
            $catcount = $category->listcategories(null, $conf['layout']['showcountsrecursive'] ? "1" : "0", $cat['id']);
            $listitem->push("count", true);
            $listitem->push("catcount", count($catcount));
            $entrycount = count($category->listentries(null, null, $cat['id']));
            if ($conf['layout']['showcountsrecursive']) {
                foreach ($catcount as $val) {
                    $entrycount += count($category->listentries(null, null, $val['id']));
                }
            }
            $listitem->push("entrycount", $entrycount);
        }
        $listitem->push("description", htmlentities($cat['description']));
        $i++;
        if ($i % $count == 0) {
            $listitem->push("last", true);
        }
        $listcode .= $listitem->__toString();
        unset($listitem);
    }
    $list->push("categories", $listcode);
    // Entries
    $entries = $category->listentries($sortorder, $filter);
    $list->push("changeview", url("category.php?id=" . $category->id() . "&action=sort", $lang['sort']['changeview'], $lang['sort']['changeviewalt']));
    $entriescount = count($entries);
    if ($entriesperpage == $lang['search']['all']) {
        $entriesperpage = $entriescount;
    }
    if ($offset >= $entriescount) {
        $offset = $entriescount - 1;
    }
    if (!is_numeric($offset) || $offset <= 0) {
        $offset = 0;
    }
    if ($entriescount > 0) {
        $pages = ceil($entriescount / $entriesperpage);
        $currentpage = ceil($offset / $entriesperpage) + 1;
        $pagesting = "";
        if ($pages > 1) {
            // Go to the given offset
            for ($i = 0; $i < $offset * $entriesperpage - 1; $i++) {
                if (is_array($entries)) {
                    array_shift($entries);
                }
            }
            $pagestring .= url("category.php?id=" . $category->id() . "&offset=" . ($offset <= 0 ? "0" : $offset - 1), $lang['search']['last'], $lang['search']['lastalt']) . " ";
            for ($i = 1; $i <= $pages; $i++) {
                if ($i == $currentpage) {
                    $pagestring .= $i . " ";
                } else {
                    $pagestring .= url("category.php?id=" . $category->id() . "&offset=" . ($i - 1), $i, phrasereplace($lang['search']['page'], "%1%", $i)) . " ";
                }
            }
            $pagestring .= url("category.php?id=" . $category->id() . "&offset=" . ($offset >= $entriescount - 1 ? $entriescount - 1 : $offset + 1), $lang['search']['next'], $lang['search']['nextalt']);
        }
        $list->push("pages", $pagestring);
    }
    $i = 0;
    $count = 3;
    $listcode = "";
    foreach ($entries as $entry) {
        $listitem = new CodeKBTemplate("listitem");
        if ($i % $count == 0) {
            $listitem->push("first", true);
        }
        $listitem->push("icon", url("entry.php?id=" . $entry['id'] . "&cat=" . $category->id(), icon($entry['symbol'], $entry['name']), $entry['name']) . "\n");
        $listitem->push("name", url("entry.php?id=" . $entry['id'] . "&cat=" . $category->id(), htmlentities($entry['name']), $entry['name']));
        $listitem->push("description", htmlentities($entry['description']));
        $i++;
        if ($entriesperpage != $lang['search']['all'] && $i == $entriesperpage) {
            $listitem->push("last", true);
            break;
        }
        if ($i % $count == 0 || $i == $entriescount) {
            $listitem->push("last", true);
        }
        $listcode .= $listitem->__toString();
        unset($listitem);
    }
    $list->push("entries", $listcode);
    $site->addcontent($list);
    return true;
}
示例#4
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;
}