public function write($id, $data)
 {
     $time = time() + $this->expire_time;
     $q = 'REPLACE tblSessionData (session_id,session_data,expires) VALUES(?, ?, ?)';
     Sql::pUpdate($q, 'sss', $id, $data, sql_datetime($time));
     return true;
 }
Example #2
0
 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);
 }
Example #3
0
 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;
 }
Example #4
0
 /** Updates tblFiles entry with current file size & mime type, useful after Image resize / rotate etc */
 public static function sync($id)
 {
     $name = self::getUploadPath($id);
     if (!file_exists($name)) {
         throw new \Exception('cant sync nonexisting file, what do???');
     }
     $size = filesize($name);
     $mime = get_mimetype_of_file($name);
     $q = 'UPDATE tblFiles' . ' SET size = ?, mimetype = ?' . ' WHERE id = ?';
     Sql::pUpdate($q, 'isi', $size, $mime, $id);
 }
Example #5
0
 /** Logs out the user */
 function logout()
 {
     dp($this->username . ' logged out');
     if (!$this->id) {
         throw new \Exception('already logged out');
     }
     Sql::pUpdate('UPDATE tblUsers SET time_last_logout = NOW() WHERE id = ?', 'i', $this->id);
     $params = session_get_cookie_params();
     setcookie(session_name(), '', time() - 604800, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
     $page = XmlDocumentHandler::getInstance();
     $show_page = $this->logged_out_start_page ? $this->logged_out_start_page : $page->getRelativeUrl();
     header('Location: ' . $show_page);
     $this->end();
     die;
 }
Example #6
0
 /**
  * Marks specified user as "deleted"
  */
 public function remove()
 {
     // also removes user from all user groups
     foreach (UserGroupHandler::getGroups($this->id) as $grp) {
         UserGroupHandler::removeFromGroup($this->id, $grp->id);
     }
     $q = 'UPDATE tblUsers SET time_deleted = NOW() WHERE id = ?';
     Sql::pUpdate($q, 'i', $this->id);
 }
Example #7
0
 function save()
 {
     $session = SessionHandler::getInstance();
     if (!$this->id) {
         $q = 'SELECT groupId FROM tblUserGroups WHERE name = ?';
         $this->id = Sql::pSelectItem($q, 's', $this->name);
     }
     if ($this->id) {
         $q = 'UPDATE tblUserGroups SET name = ?, info = ?, level = ? WHERE groupId = ?';
         Sql::pUpdate($q, 'ssii', $this->name, $this->info, $this->level, $this->id);
     } else {
         $q = 'INSERT INTO tblUserGroups SET createdBy = ?, timeCreated = NOW(), name = ?, info = ?, level = ?';
         $this->id = Sql::pInsert($q, 'issi', $session->id, $this->name, $this->info, $this->level);
     }
     return $this->id;
 }
Example #8
0
 public static function updateId($obj, $tblname, $field_name = 'id')
 {
     if (!is_alphanumeric($tblname) || !is_alphanumeric($field_name)) {
         throw new \Exception('very bad');
     }
     if (!$obj->{$field_name}) {
         d($obj);
         throw new \Exception('eehh');
     }
     $reflect = self::reflectQuery($obj, $field_name);
     $q = 'UPDATE ' . $tblname . ' SET ' . implode(', ', $reflect->cols) . ' WHERE ' . $field_name . ' = ?';
     $reflect->str .= is_numeric($obj->{$field_name}) ? 'i' : 's';
     $reflect->vals[] = $obj->{$field_name};
     return Sql::pUpdate($q, $reflect->str, $reflect->vals);
 }
Example #9
0
 public static function deleteByOwner($type, $owner)
 {
     $session = SessionHandler::getInstance();
     $q = 'UPDATE ' . self::$tbl_name . ' SET deleted_by = ?, time_deleted = NOW()' . ' WHERE type = ? AND owner = ?';
     Sql::pUpdate($q, 'iii', $session->id, $type, $owner);
 }
Example #10
0
 static function removePoll($id)
 {
     $session = SessionHandler::getInstance();
     $q = 'UPDATE tblPolls SET deleted_by = ?, time_deleted = NOW() WHERE id = ?';
     Sql::pUpdate($q, 'ii', $session->id, $id);
 }