public function __construct($id, CodeKBUser &$user)
 {
     $this->_id = $id;
     $this->_user =& $user;
     $db = new CodeKBDatabase();
     $db->dosql("SELECT name, " . "entry, " . "fs_name, " . "size, " . "symbol, " . "highlight, " . "created, " . "modified " . "FROM files " . "WHERE id = {$db->number($this->_id)}");
     if ($db->countrows() == 0) {
         throw new CodeKBException(__METHOD__, "file", "nosuchfile");
     }
     $this->_entry = new CodeKBEntry($db->column("entry"), $this->_user);
     if ($this->_user->entrycan("download", $this->_entry)) {
         $this->_downloadable = true;
     }
     $this->_name = $db->column("name");
     $this->_fsname = $db->column("fs_name");
     $this->_size = $db->column("size");
     $this->_symbol = $db->column("symbol");
     $this->_highlight = $db->column("highlight");
     $this->_created = $db->column("created");
     $this->_modified = $db->column("modified");
     // For mysql...
     if ($this->_modified == "0000-00-00 00:00:00") {
         $this->_modified = null;
     }
 }
 public function documentation()
 {
     $db = new CodeKBDatabase();
     $db->dosql("SELECT documentation " . "FROM entries " . "WHERE id = {$db->number($this->_id)}");
     return $db->column("documentation");
 }
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;");
}
 private function getrights($cat, $cache = true)
 {
     // 1 see
     // 2 download
     // 4 change entries
     // 8 add entries
     // 16 delete entries
     // 32 change categories
     // 64 add categories
     // 128 delete categories
     // First look if we have these rights in the cache already
     if ($cache && !is_null($this->_cache[$cat])) {
         return $this->_cache[$cat];
     }
     $rights = array();
     // Get the maximum rights from given user's groups
     $db = new CodeKBDatabase();
     $db->dosql("SELECT max(rights.rights) AS rightval " . "FROM rights, users, categories, groups, group_user " . "WHERE (" . ($this->_name != null ? "users.name = '{$db->string($this->_name)}' OR" : "") . " users.name is null) AND " . "users.id = group_user.userid AND " . "groups.id = group_user.groupid AND " . "categories.id = {$db->number($cat)} AND " . "categories.id = rights.category AND " . "groups.id = rights.groupid");
     $val = $db->column("rightval");
     if ($val >= 128) {
         $val -= 128;
         $rights[] = "delcat";
     }
     if ($val >= 64) {
         $val -= 64;
         $rights[] = "addcat";
     }
     if ($val >= 32) {
         $val -= 32;
         $rights[] = "changecat";
     }
     if ($val >= 16) {
         $val -= 16;
         $rights[] = "delentry";
     }
     if ($val >= 8) {
         $val -= 8;
         $rights[] = "addentry";
     }
     if ($val >= 4) {
         $val -= 4;
         $rights[] = "changeentry";
     }
     if ($val >= 2) {
         $val -= 2;
         $rights[] = "download";
     }
     if ($val == 1) {
         $val -= 1;
         $rights[] = "see";
     }
     global $conf;
     // In case we want to cache the access rights
     if ($conf['perf']['rightscache'] > 0) {
         $this->_cache[$cat] = $rights;
         if (count($this->_cache) > $conf['perf']['rightscache']) {
             array_shift($this->_cache);
         }
     }
     return $rights;
 }
 public function getrights($group, $cat)
 {
     $db = new CodeKBDatabase();
     $db->dosql("SELECT rights " . "FROM rights " . "WHERE groupid = {$db->number($group)} AND " . "category = {$db->number($cat)}");
     return $db->column("rights");
 }
 public function change($name, $description, $parent = -1)
 {
     // return values
     // 1 child cannot be parent
     // 2 duplicate category
     if (!$this->_user->can("changecat", $this)) {
         return false;
     }
     $db = new CodeKBDatabase();
     $db->start();
     if ($parent == -1) {
         $db->dosql("SELECT parent " . "FROM categories " . "WHERE id = {$db->number($this->_id)}");
         $parent = $db->column("parent");
     } else {
         $i = $parent;
         if ($i == $this->_id) {
             throw new CodeKBException(__METHOD__, "category", "childnoparent", $name, 1);
         }
         while ($i != 0) {
             $db->dosql("SELECT parent " . "FROM categories " . "WHERE id = {$db->number($i)}");
             $i = $db->column("parent");
             if ($i == $this->_id) {
                 $db->abort();
                 throw new CodeKBException(__METHOD__, "category", "childnoparent", $name, 1);
             }
         }
     }
     $db->dosql("SELECT id " . "FROM categories " . "WHERE parent = {$db->number($parent)} AND " . "id <> {$db->number($this->_id)} AND " . "name = '{$db->string($name)}'");
     if ($db->countrows() > 0) {
         $db->abort();
         throw new CodeKBException(__METHOD__, "category", "duplicate", $name, 2);
     }
     $db->dosql("UPDATE categories " . "SET name = '{$db->string($name)}', " . "description = '{$db->string($description)}', " . "parent = {$db->number($parent)} " . "WHERE id = {$db->number($this->_id)}");
     $db->commit();
     if ($db->success()) {
         $this->_name = $name;
         $this->_description = $description;
         if ($parent != -1) {
             $this->_parent = $parent;
         }
         return true;
     }
     $db->abort();
     throw new CodeKBException(__METHOD__, "category", "failedchange", $name);
 }