/** Adds the user to a user group */ public static function addToGroup($user_id, $grp_id) { $q = 'SELECT COUNT(*) FROM ' . self::$tbl_name . ' WHERE groupId = ? AND userId = ?'; if (Sql::pSelectItem($q, 'ii', $grp_id, $user_id)) { return true; } $q = 'INSERT INTO ' . self::$tbl_name . ' SET groupId = ?, userId = ?'; Sql::pInsert($q, 'ii', $grp_id, $user_id); return true; }
public function store() { $q = 'SELECT id FROM ' . self::$tbl_name . ' WHERE owner = ? AND season = ? AND episode = ?'; $this->id = Sql::pSelectItem($q, 'iii', $this->owner, $this->season, $this->episode); if ($this->id) { $q = 'UPDATE ' . self::$tbl_name . ' SET owner = ?, title = ?, date = ?, info = ?, season = ?, episode = ?, link = ? WHERE id = ?'; Sql::pUpdate($q, 'isssiisi', $this->owner, $this->title, $this->date, $this->info, $this->season, $this->episode, $this->link, $this->id); return $this->id; } $q = 'INSERT INTO ' . self::$tbl_name . ' SET owner = ?, title = ?, date = ?, info = ?, season = ?, episode = ?, link = ?'; return Sql::pInsert($q, 'isssiis', $this->owner, $this->title, $this->date, $this->info, $this->season, $this->episode, $this->link); }
public static function set($type, $owner, $name, $val) { $q = 'SELECT id FROM ' . self::$tbl_name . ' WHERE owner = ? AND type = ? AND name = ?'; if (Sql::pSelectItem($q, 'iis', $owner, $type, $name)) { $q = 'UPDATE ' . self::$tbl_name . ' SET time_saved = NOW(), value = ?' . ' WHERE owner = ? AND type = ? AND name = ?'; Sql::pUpdate($q, 'siis', $val, $owner, $type, $name); } else { $q = 'INSERT INTO ' . self::$tbl_name . ' SET time_saved = NOW(),' . 'owner = ?, type = ?, name = ?, value = ?'; Sql::pInsert($q, 'iiss', $owner, $type, $name, $val); } return true; }
/** Votes for a poll */ static function addVote($type, $id, $value) { $session = SessionHandler::getInstance(); if (!$session->id) { return false; } if (self::hasAnswered($type, $id)) { return false; } $q = 'INSERT INTO ' . self::$tbl_name . ' SET type = ?, owner = ?, userId = ?, value = ?, timestamp = NOW()'; Sql::pInsert($q, 'iiii', $type, $id, $session->id, $value); return true; }
public static function add($user_id, $ip, $user_agent, $type = LOGIN_INTERNAL) { $q = 'INSERT INTO ' . self::$tbl_name . ' SET timeCreated = NOW(), userId = ?, IP = ?, userAgent = ?, type = ?'; return Sql::pInsert($q, 'issi', $user_id, $ip, $user_agent, $type); }
static function create($name, $level) { $session = SessionHandler::getInstance(); $creator_id = $session->id ? $session->id : 0; $q = 'INSERT INTO tblUserGroups SET createdBy = ?, timeCreated = NOW(), name = ?, level = ?'; return Sql::pInsert($q, 'isi', $creator_id, $name, $level); }
/** * Creates a object in a database table * @return insert id */ public static function create($obj, $tblname) { if (!is_alphanumeric($tblname)) { throw new \Exception('very bad'); } $reflect = self::reflectQuery($obj, '', false); if (!$reflect->cols) { throw new \Exception('no columns defined for ' . $tblname); } $q = 'INSERT INTO ' . $tblname . ' SET ' . implode(', ', $reflect->cols); return Sql::pInsert($q, $reflect->str, $reflect->vals); }
static function addPollExactPeriod($type, $owner, $text, $time_start, $time_end) { $session = SessionHandler::getInstance(); $q = 'INSERT INTO tblPolls SET type = ?, owner = ?,' . ' created_by = ?, text = ?, time_start = ?,' . ' time_end = ?, time_created = NOW()'; return Sql::pInsert($q, 'iiisss', $type, $owner, $session->id, trim($text), sql_datetime($time_start), sql_datetime($time_end)); }