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;"); }
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); }
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 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; }
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; }
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; }
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; }
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"); }
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"); }