Пример #1
0
function icon($name, $text)
{
    $db = new CodeKBDatabase();
    $db->dosql("SELECT symbol " . "FROM symbols " . "WHERE name = '{$db->string($name)}'");
    $symbol = $db->column("symbol");
    if (is_null($symbol)) {
        return "";
    }
    global $conf;
    return img("/icons/" . $symbol, $text ? $text : $name, "vertical-align: middle;");
}
Пример #2
0
 public function change($name, $author, $symbol, $description, $documentation)
 {
     if (!$this->_user->entrycan("changeentry", $this)) {
         return false;
     }
     if (!$author && $this->_user->name()) {
         $author = $this->_user->name();
     }
     $db = new CodeKBDatabase();
     $db->dosql("UPDATE entries " . "SET name = '{$db->string($name)}', " . "author = '{$db->string($author)}', " . "symbol = '{$db->string($symbol)}', " . "description = '{$db->string($description)}', " . "documentation = '{$db->string($documentation)}', " . "modified = now()" . "WHERE id = {$db->number($this->_id)}");
     if ($db->success()) {
         $this->_name = $name;
         $this->_author = $author;
         $this->_symbol = $symbol;
         $this->_description = $description;
         return true;
     }
     throw new CodeKBException(__METHOD__, "entry", "failedchange", $name);
 }
Пример #3
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;
}
Пример #4
0
 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;
 }
Пример #5
0
function buildsearchquery($type)
{
    global $lang;
    $query = "SELECT DISTINCT entries.id, " . "entries.name, " . "entries.author, " . "entries.description, " . "entries.symbol, " . "entries.created, " . "entries.modified " . "FROM ";
    $keywords = preg_split("/\\s+/", trim($_POST['query']));
    $count = count($keywords);
    if ($type == "pgsql") {
        for ($i = 0; $i < $count; $i++) {
            $query .= "entries_fti i" . $i . ", ";
        }
    }
    if (is_array($_POST['cats'])) {
        $query .= " entry_cat, ";
    }
    $query .= "entries WHERE ";
    if ($type == "pgsql") {
        $query .= "entries.oid = i0.id AND ";
    }
    if ($_POST['author']) {
        $query .= "lower(entries.author) = lower('" . CodeKBDatabase::string($_POST['author']) . "') AND ";
    }
    $a = 1;
    $b = count($_POST['cats']);
    while (is_array($_POST['cats']) && !is_null($val = array_shift($_POST['cats']))) {
        if ($a == 1) {
            $query .= "entries.id = entry_cat.entry AND ( ";
        }
        $query .= "entry_cat.cat = " . CodeKBDatabase::number($val) . " ";
        if ($a != $b) {
            $query .= "OR ";
        } else {
            $query .= ") AND ";
        }
        $a++;
    }
    if ($_POST['age'] != $lang['search']['all'] && $_POST['whichage']) {
        if ($_POST['whichage'] == $lang['sort']['sortbymodifydate']) {
            $wage = "modified";
        } else {
            $wage = "created";
        }
        switch ($_POST['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();
        }
        $query .= "entries." . CodeKBDatabase::string($wage) . " > '" . CodeKBDatabase::string(date("Y-m-d H:i:s", time() - $age)) . "' AND ";
    }
    $i = 0;
    if ($type == "mysql") {
        $query .= "(";
    }
    while (is_array($keywords) && !is_null($val = array_shift($keywords))) {
        if ($val == "*" || $val == "?") {
            $val = "";
        }
        if ($type == "pgsql") {
            $query .= ($i == 0 ? "" : "AND ") . "i" . $i . ".string ~ lower('^" . CodeKBDatabase::string($val) . "') ";
            if ($i > 0) {
                $query .= "AND i" . ($i - 1) . ".id = i" . $i . ".id ";
            }
            $i++;
        }
        if ($type == "mysql") {
            $query .= ($i == 0 ? "" : "OR ") . " entries.description LIKE '%" . CodeKBDatabase::string($val) . "%' OR entries.documentation LIKE '%" . CodeKBDatabase::string($val) . "%' ";
        }
        $i++;
    }
    if ($type == "mysql") {
        $query .= ") ";
    }
    $sortorder = false;
    switch ($_POST['sort']) {
        case $lang['sort']['sortbycreatedate']:
            $sort = "entries.created";
            break;
        case $lang['sort']['sortbymodifydate']:
            $sort = "entries.modified";
            break;
        case $lang['sort']['sortbyname']:
        default:
            $sort = "entries.name";
    }
    switch ($_POST['order']) {
        case $lang['sort']['descending']:
            $order = "DESC";
            break;
        case $lang['sort']['ascending']:
        default:
            $order = "ASC";
    }
    $query .= "ORDER BY " . $sort . " " . $order;
    echo $query;
    return $query;
}
Пример #6
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;
}
Пример #7
0
 function change($name, $highlight, $symbol, $newupload = null)
 {
     // return values
     // 1 upload failed
     if (!$this->_user->entrycan("changeentry", $this->_entry)) {
         return false;
     }
     // Do we want to exchange our file with a new one?
     if ($newupload) {
         // First upload new one and then delete the old
         global $HTTP_POST_FILES;
         $fs_name = null;
         if (is_uploaded_file($HTTP_POST_FILES[$newupload]['tmp_name'])) {
             $fs_name = $this->upload($newupload);
         }
         if (!$fs_name) {
             throw new CodeKBException(__METHOD__, "file", "failedchange", $name, 1);
         } else {
             $size = $HTTP_POST_FILES[$newupload]['size'];
         }
     } else {
         $fs_name = $this->_fsname;
         $size = $this->_size;
     }
     $db = new CodeKBDatabase();
     $db->dosql("UPDATE files " . "SET name = '{$db->string($name)}', " . "fs_name = '{$db->string($fs_name)}', " . "size = {$db->number($size)}, " . "highlight = '{$db->string($highlight)}', " . "symbol = '{$db->string($symbol)}', " . "modified = now() " . "WHERE id = {$db->number($this->_id)}");
     if (!$db->success()) {
         throw new CodeKBException(__METHOD__, "file", "failedchange", $name);
     }
     // Remove old file
     if ($newupload) {
         $this->delink();
     }
     $this->_name = $name;
     $this->_fs_name = $fs_name;
     $this->_size = $size;
     $this->_highlight = $highlight;
     $this->_symbol = $symbol;
     return true;
 }
Пример #8
0
 function entrycan($what, &$entry, $cache = true)
 {
     // Do something for a bit more performance:
     // Cache the last request because we often query
     // just one entry per page
     static $lastentry;
     static $lastcat;
     if (is_null($entry)) {
         return false;
     }
     if (is_object($entry)) {
         $id = $entry->id();
     } else {
         $id = $entry;
     }
     if ($cache && $id == $lastentry) {
         $array = $lastcat;
     } else {
         $db = new CodeKBDatabase();
         $db->dosql("SELECT cat " . "FROM entry_cat " . "WHERE entry = {$db->number($id)}");
         $lastentry = $id;
         $array = $db->all();
         $lastcat = $array;
     }
     $succ = false;
     while (is_array($array) && ($val = array_pop($array))) {
         if ($this->can($what, $val['cat'], $cache)) {
             $succ = true;
             break;
         }
     }
     if ($succ) {
         return true;
     }
     return false;
 }
Пример #9
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;
}
Пример #10
0
 public function partgroup($user, $group)
 {
     $db = new CodeKBDatabase();
     $db->dosql("DELETE FROM group_user " . "WHERE userid = {$db->number($user)} AND " . "groupid = {$db->number($group)}");
     if ($db->success()) {
         return true;
     }
     throw new CodeKBException(__METHOD__, "admin", "failedpart");
 }
Пример #11
0
 public function delete(&$dbobj = null, $level = 0)
 {
     // return values
     // 1 aborted recursion
     // Are we at the first recursion level?
     if (is_null($dbobj)) {
         $first = true;
         $db = new CodeKBDatabase();
         $db->start();
         $dbobj =& $db;
     } else {
         $first = false;
         $db =& $dbobj;
     }
     if ($this->_id == 0 || !$this->_user->can("delcat", $this)) {
         $db->abort();
         return false;
     }
     $entries = $this->listentries();
     foreach ($entries as $val) {
         $tmpentry = new CodeKBEntry($val['id'], $this->_user);
         $tmpentry->delink($this->_id);
         unset($tmpentry);
     }
     $db->dosql("SELECT id " . "FROM categories " . "WHERE parent = {$db->number($this->_id)}", $level);
     while ($val = $db->row($level)) {
         $subcat = new CodeKBCategory($val['id'], $this->_user);
         if (!$subcat->delete($db, $level + 1)) {
             $db->abort();
             throw new CodeKBException(__METHOD__, "category", "faileddel", null, 1);
         }
         unset($subcat);
     }
     $db->dosql("DELETE FROM rights " . "WHERE category = {$db->number($this->_id)}", $level);
     $db->dosql("DELETE FROM categories " . "WHERE id = {$db->number($this->_id)}", $level);
     if ($first) {
         $db->commit();
     } else {
         return $db->success();
     }
     if ($db->success()) {
         return true;
     }
     $db->abort();
     throw new CodeKBException(__METHOD__, "category", "faileddel");
 }