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 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; }
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 register($name, $pass) { // return values // 1 duplicate user $pass = sha1($pass); global $lang; if ($name == $lang['admin']['nobody']) { throw new CodeKBException(__METHOD__, "admin", "duplicateuser", $name, 1); } $db = new CodeKBDatabase(); $db->start(); $db->dosql("SELECT id " . "FROM users " . "WHERE name = '{$db->string($name)}'"); if ($db->countrows() > 0) { $db->abort(); throw new CodeKBException(__METHOD__, "admin", "duplicateuser", $name, 1); } // We need a random id $succ = false; while ($succ == false) { $id = mt_rand(); $db->dosql("SELECT id " . "FROM users " . "WHERE id = {$db->number($id)}"); if ($db->countrows() == 0) { break; } } $db->dosql("INSERT INTO users (id, name, pass) " . "VALUES ({$db->number($id)}, " . "'{$db->string($name)}', " . "'{$db->string($pass)}')"); $db->commit(); if ($db->success()) { return true; } throw new CodeKBException(__METHOD__, "admin", "failedadduser", $name); }
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); }