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;
 }
 public static function setStatus($user_id, $text)
 {
     $status = new PersonalStatus();
     $status->owner = $user_id;
     $status->text = $text;
     $status->time_saved = sql_datetime(time());
     return $status->store();
 }
Beispiel #3
0
 /**
  * Creates a new visit entry
  * @param $type
  * @param $owner_id
  * @param $ref_id
  */
 public static function create($type, $owner_id, $ref_id)
 {
     $o = new Visit();
     $o->type = $type;
     $o->owner = $owner_id;
     $o->ref = $ref_id;
     $o->time = sql_datetime(time());
     $o->store();
 }
Beispiel #4
0
 /**
  * Mark feedback item as handled
  * @param $message_id optionally refer to a response message
  */
 public static function markHandled($id, $message_id = 0)
 {
     $session = SessionHandler::getInstance();
     $i = self::get($id);
     $i->time_answered = sql_datetime(time());
     $i->answered_by = $session->id;
     $i->message = $message_id;
     $i->store();
 }
Beispiel #5
0
 public static function set($owner, $type, $user_id)
 {
     $l = new Like();
     $l->owner = $owner;
     $l->type = $type;
     $l->user = $user_id;
     $l->time = sql_datetime(time());
     $l->store();
 }
Beispiel #6
0
 /**
  * Creates a new poke
  * @param $to
  */
 public static function send($to)
 {
     $session = SessionHandler::getInstance();
     $o = new Poke();
     $o->from = $session->id;
     $o->to = $to;
     $o->time = sql_datetime(time());
     $o->store();
 }
Beispiel #7
0
 function editHandler($p)
 {
     $session = SessionHandler::getInstance();
     $o = FaqItem::get($p['id']);
     $o->question = $p['q'];
     $o->answer = $p['a'];
     $o->creator = $session->id;
     $o->time_created = sql_datetime(time());
     $o->store();
     js_redirect('a/faq');
 }
Beispiel #8
0
 /**
  * @return message id
  */
 public static function send($to, $msg, $type = PRIV_MSG)
 {
     $session = SessionHandler::getInstance();
     $m = new Message();
     $m->to = $to;
     $m->from = $session->id;
     $m->body = $msg;
     $m->type = $type;
     $m->time_sent = sql_datetime(time());
     return $m->store();
 }
 public static function add($type, $reference = 0, $data = '')
 {
     $session = SessionHandler::getInstance();
     $c = new ModerationObject();
     $c->type = $type;
     $c->owner = $session->id;
     $c->time_created = sql_datetime(time());
     $c->data = $data;
     $c->reference = $reference;
     $c->id = $c->store();
     return $c->id;
 }
Beispiel #10
0
/**
 * Converts a SQL timestamp to a text string representing how long ago this timestamp occured
 *
 * @param $sql_time SQL timestamp
 * @return text string representing how long ago this timestamp occured
 */
function ago($sql_time, $past = 'ago', $future = 'in', $just_now = 'just now')
{
    $old_time = ts(sql_datetime($sql_time));
    $curr_time = time();
    if ($curr_time == $old_time) {
        return $just_now;
    }
    if ($curr_time >= $old_time) {
        return elapsed_seconds($curr_time - $old_time, 0) . ' ' . $past;
    }
    return $future . ' ' . elapsed_seconds($old_time - $curr_time, 0);
}
 public function update()
 {
     $db = Database::get_instance();
     $time_updated = sql_datetime();
     $query = $db->prepare("UPDATE aspect_groups SET group_name=?, update_date=? WHERE id=?");
     $data = array($this->group_name, $time_updated, $this->id);
     if ($query->execute($data)) {
         return true;
     } else {
         return false;
     }
 }
Beispiel #12
0
 function createHandler($p)
 {
     $session = SessionHandler::getInstance();
     $o = new BlogEntry();
     $o->owner = $session->id;
     $o->subject = trim($p['subject']);
     $o->body = trim($p['body']);
     $o->time_created = sql_datetime(time());
     $o->time_published = sql_datetime(time());
     $o->id = $o->store();
     js_redirect('a/blogs/overview');
 }
Beispiel #13
0
 public function save()
 {
     $db = Database::get_instance();
     $time_saved = sql_datetime();
     $query = $db->prepare("INSERT INTO log (message, time) VALUES (?, ?)");
     $data = array($this->message, $time_saved);
     if ($query->execute($data)) {
         return true;
     } else {
         return false;
     }
 }
 public function update()
 {
     $db = Database::get_instance();
     $time_updated = sql_datetime();
     $query = $db->prepare("UPDATE subject_types SET type_name=?, type_description=?, aspect_group=?, update_date=?, parent_id=? WHERE id=?");
     $data = array($this->type_name, $this->type_description, $this->aspect_group, $time_updated, $this->parent_id, $this->id);
     if ($query->execute($data)) {
         return true;
     } else {
         return false;
     }
 }
Beispiel #15
0
 /**
  * Helper function to create new comments
  */
 public static function create($type, $owner, $msg, $private = false)
 {
     $session = SessionHandler::getInstance();
     $c = new Comment();
     $c->type = $type;
     $c->owner = $owner;
     $c->msg = $msg;
     $c->private = $private;
     $c->creator = $session->id;
     $c->creator_ip = client_ip();
     $c->time_created = sql_datetime(time());
     return $c->store();
 }
Beispiel #16
0
function fbHandler($p)
{
    $session = SessionHandler::getInstance();
    $o = new Feedback();
    $o->type = USER;
    $o->subject = $p['subj'];
    $o->body = $p['body'];
    $o->from = $session->id;
    $o->time_created = sql_datetime(time());
    $o->store();
    js_redirect('');
    // jump to start page
}
Beispiel #17
0
 function editHandler($p)
 {
     $o = new ChatRoom();
     $o->id = $p['roomid'];
     $o->name = trim($p['name']);
     if ($p['locked']) {
         $session = SessionHandler::getInstance();
         $o->locked_by = $session->id;
         $o->time_locked = sql_datetime(time());
     }
     $o->store();
     js_redirect('a/chatroom/list');
 }
Beispiel #18
0
function gbHandler($p)
{
    $session = SessionHandler::getInstance();
    if ($session->id == $p['to']) {
        return false;
    }
    $gb = new Guestbook();
    $gb->owner = $p['to'];
    $gb->creator = $session->id;
    $gb->time_created = sql_datetime(time());
    $gb->body = $p['body'];
    $gb->store();
    return true;
}
Beispiel #19
0
 function getShow($id)
 {
     if (!$id || !is_numeric($id)) {
         throw new \Exception('bad id: ' . $id);
     }
     $url = 'http://services.tvrage.com/feeds/full_show_info.php?sid=' . $id;
     $this->setUrl($url);
     if ($this->api_key) {
         $this->Url->setParam('key', $this->api_key);
     }
     $data = $this->getBody();
     $xml = simplexml_load_string($data);
     if (!$xml) {
         echo "ERROR: getShow( " . $id . " ) failed<br/>";
         return false;
     }
     $show = new TvShow();
     $show->id = $id;
     $show->info_url = strval($xml->showlink);
     $show->name = strval($xml->name);
     $show->country = strval($xml->origin_country);
     $show->thumb_url = strval($xml->image);
     $show->started = sql_date(self::parseDate(strval($xml->started)));
     $show->ended = sql_date(self::parseDate(strval($xml->ended)));
     $show->status = self::parseStatus($xml->status, $show->started, $show->ended);
     $show->time_updated = sql_datetime(time());
     $show->store();
     if (!$xml->Episodelist) {
         return $show;
     }
     foreach ($xml->Episodelist->Season as $season) {
         $attrs = $season->attributes();
         foreach ($season as $e) {
             $ep = new TvEpisode();
             $ep->owner = $show->id;
             $ep->title = strval($e->title);
             $ep->link = strval($e->link);
             $ep->setDate(strval($e->airdate));
             $ep->setEpisode($attrs['no'] . 'x' . $e->seasonnum);
             $ep->store();
             //only include episodes in period if it is set
             if (!$this->period_from && !$this->period_to || $ep->getDate() >= $this->period_from && $ep->getDate() <= $this->period_to) {
                 $show->addEpisode($ep);
             }
         }
     }
     return $show;
 }
Beispiel #20
0
function handleSubmit($p)
{
    $session = SessionHandler::getInstance();
    $error = ErrorHandler::getInstance();
    if (empty($p['comment'])) {
        return false;
    }
    if (!$session->id) {
        $error->add('Unauthorized submit');
        return false;
    }
    $c = new Comment();
    $c->type = $p['type'];
    $c->msg = $p['comment'];
    $c->private = 0;
    $c->time_created = sql_datetime(time());
    $c->owner = $p['owner'];
    $c->creator = $session->id;
    $c->creator_ip = client_ip();
    $c->store();
    redir($_SERVER['REQUEST_URI']);
}
Beispiel #21
0
 function editWikiSubmit($p)
 {
     if (!isset($p['wiki_name'])) {
         return false;
     }
     $session = SessionHandler::getInstance();
     $text = trim($p['text']);
     $name = normalizeString($p['wiki_name'], array("\t"));
     $wiki = Wiki::getByName($name);
     // abort if we are trying to save a exact copy as the last one
     if ($wiki->text == $text) {
         return false;
     }
     if ($wiki->id) {
         $rev = new Revision();
         $rev->type = WIKI;
         $rev->owner = $wiki->id;
         $rev->value = $wiki->text;
         $rev->time_created = $wiki->time_edited;
         $rev->created_by = $wiki->edited_by;
         $rev->event = EVENT_TEXT_CHANGED;
         $rev->id = $rev->store();
         $wiki->text = $p['text'];
         $wiki->edited_by = $session->id;
         $wiki->time_edited = sql_datetime(time());
         $wiki->revision++;
         $wiki->store();
         redir('u/wiki/show/' . $wiki->name);
     }
     $wiki->name = $name;
     $wiki->text = $p['text'];
     $wiki->edited_by = $session->id;
     $wiki->time_edited = sql_datetime(time());
     $wiki->store();
     redir('u/wiki/show/' . $wiki->name);
 }
Beispiel #22
0
 function handleNew($p)
 {
     $session = SessionHandler::getInstance();
     $o = new PhotoAlbum();
     $o->owner = $session->id;
     $o->name = $p['name'];
     $o->time_created = sql_datetime(time());
     if ($session->isSuperAdmin && $p['system']) {
         $o->owner = 0;
     }
     // create a system wide album
     $o->id = $o->store();
     js_redirect('u/album/show/' . $session->id . '/' . $o->id);
 }
Beispiel #23
0
 public static function create($username, $password, $type = SESSION_REGULAR, $algo = 'sha512')
 {
     $username = trim($username);
     if (User::getByName($username)) {
         return false;
     }
     $o = new User();
     $o->name = $username;
     $o->type = $type;
     $o->time_created = sql_datetime(now());
     $o->id = $o->store();
     if (!$o->id) {
         return false;
     }
     $session = SessionHandler::getInstance();
     $o->password = Password::encrypt($o->id, $session->getEncryptKey(), $password, $algo);
     $o->store();
     // write again with password encoded using the user id
     dp($session->getUsername() . ' created user ' . $username . ' (' . $o->id . ') of type ' . $type);
     return $o->id;
 }
/**
 * Renders html for editing all tblSettings field for current user
 *
 * @return nothing
 */
function editUserdataSettings($_userid = '')
{
    global $h;
    if (empty($_userid)) {
        $_userid = $h->session->id;
    }
    $list = readAllUserdata($_userid);
    if (!$list) {
        return;
    }
    echo '<div class="settings">';
    echo xhtmlForm('edit_settings_frm', '', 'post', 'multipart/form-data');
    echo xhtmlHidden('edit_settings_check', 1);
    echo '<table>';
    foreach ($list as $row) {
        if (!empty($_POST['edit_settings_check'])) {
            switch ($row['fieldType']) {
                case USERDATA_TYPE_IMAGE:
                    if (!empty($_POST['userdata_' . $row['fieldId'] . '_remove'])) {
                        $h->files->deleteFile($row['settingValue']);
                        $row['settingValue'] = 0;
                    } else {
                        if (isset($_FILES['userdata_' . $row['fieldId']])) {
                            // FIXME: Gör så att handleUpload klarar av att ta userId som parameter
                            $row['settingValue'] = $h->files->handleUpload($_FILES['userdata_' . $row['fieldId']], FILETYPE_USERDATA, $row['fieldId']);
                        }
                    }
                    break;
                case USERDATA_TYPE_EMAIL:
                    if (empty($_POST['userdata_' . $row['fieldId']])) {
                        break;
                    }
                    if (!is_email($_POST['userdata_' . $row['fieldId']])) {
                        echo '<div class="critical">' . t('The email entered is not valid!') . '</div>';
                    } else {
                        $chk = findUserByEmail($_POST['userdata_' . $row['fieldId']]);
                        if ($chk && $chk != $_userid) {
                            echo '<div class="critical">' . t('The email entered already taken!') . '</div>';
                        } else {
                            $row['settingValue'] = $_POST['userdata_' . $row['fieldId']];
                        }
                    }
                    break;
                case USERDATA_TYPE_BIRTHDATE:
                    if (empty($_POST['userdata_' . $row['fieldId'] . '_year'])) {
                        break;
                    }
                    $born = mktime(0, 0, 0, $_POST['userdata_' . $row['fieldId'] . '_month'], $_POST['userdata_' . $row['fieldId'] . '_day'], $_POST['userdata_' . $row['fieldId'] . '_year']);
                    $row['settingValue'] = sql_datetime($born);
                    break;
                case USERDATA_TYPE_BIRTHDATE_SWE:
                    if (empty($_POST['userdata_' . $row['fieldId'] . '_year'])) {
                        break;
                    }
                    $born = mktime(0, 0, 0, $_POST['userdata_' . $row['fieldId'] . '_month'], $_POST['userdata_' . $row['fieldId'] . '_day'], $_POST['userdata_' . $row['fieldId'] . '_year']);
                    if ($check = SsnValidateSwedishNum($_POST['userdata_' . $row['fieldId'] . '_year'], $_POST['userdata_' . $row['fieldId'] . '_month'], $_POST['userdata_' . $row['fieldId'] . '_day'], $_POST['userdata_' . $row['fieldId'] . '_chk']) === true) {
                        $row['settingValue'] = sql_datetime($born);
                    } else {
                        echo '<div class="critical">' . t('The Swedish SSN you entered is not valid!') . '</div>';
                    }
                    break;
                case USERDATA_TYPE_LOCATION_SWE:
                    if (empty($_POST['userdata_' . $row['fieldId']])) {
                        break;
                    }
                    if (!ZipLocation::isValid($_POST['userdata_' . $row['fieldId']])) {
                        echo '<div class="critical">' . t('The Swedish zipcode you entered is not valid!') . '</div>';
                        $h->session->log('User entered invalid swedish zipcode: ' . $_POST['userdata_' . $row['fieldId']], LOGLEVEL_WARNING);
                    } else {
                        saveSetting(SETTING_USERDATA, 0, $_userid, 'city', ZipLocation::cityId($_POST['userdata_' . $row['fieldId']]));
                        saveSetting(SETTING_USERDATA, 0, $_userid, 'region', ZipLocation::regionId($_POST['userdata_' . $row['fieldId']]));
                        $row['settingValue'] = $_POST['userdata_' . $row['fieldId']];
                    }
                    break;
                default:
                    if (!empty($_POST['userdata_' . $row['fieldId']])) {
                        $row['settingValue'] = $_POST['userdata_' . $row['fieldId']];
                    } else {
                        $row['settingValue'] = '';
                    }
                    break;
            }
            //Stores the setting
            saveSetting(SETTING_USERDATA, 0, $_userid, $row['fieldId'], $row['settingValue']);
        }
        echo '<tr>' . getUserdataInput($row) . '</tr>';
    }
    echo '</table>';
    echo xhtmlSubmit('Save');
    echo xhtmlFormClose();
    echo '</div>';
}
Beispiel #25
0
 public function test3()
 {
     $this->assertEquals(sql_datetime(''), '');
 }
Beispiel #26
0
 /**
  * @param $key array from a $_FILES entry
  * @param $blind dont verify if is_uploaded_file(), useful when importing files from other means than HTTP uploads
  * @return file id
  */
 public static function import($type, &$key, $category = 0, $blind = false)
 {
     // ignore empty file uploads
     if (!$key['name']) {
         return false;
     }
     if (!$blind && !is_uploaded_file($key['tmp_name'])) {
         throw new \Exception('Upload failed for file ' . $key['name']);
         //$error->add('Upload failed for file '.$key['name'] );
         //return;
     }
     $session = SessionHandler::getInstance();
     $file = new File();
     $file->type = $type;
     $file->uploader = $session->id;
     $file->uploader_ip = client_ip();
     $file->size = $key['size'];
     $file->name = $key['name'];
     $file->mimetype = $key['type'];
     $file->category = $category;
     $file->time_uploaded = sql_datetime(time());
     $file->id = $file->store();
     if (!$file->id) {
         return false;
     }
     $dst_file = self::getUploadPath($file->id);
     if ($blind) {
         // UGLY HACK using "@": currently gives a E_WARNING: "Operation not permitted" error,
         // even though the rename suceeds???
         if (!@rename($key['tmp_name'], $dst_file)) {
             throw new \Exception('rename failed');
         }
     } elseif (!move_uploaded_file($key['tmp_name'], $dst_file)) {
         throw new \Exception('Failed to move file from ' . $key['tmp_name'] . ' to ' . $dst_file);
     }
     chmod($dst_file, 0777);
     $key['name'] = $dst_file;
     $key['file_id'] = $file->id;
     return $file->id;
 }
Beispiel #27
0
 public function parse()
 {
     $this->last_parsed = sql_datetime();
     $this->update();
 }
Beispiel #28
0
{
    $grp = new UserGroup();
    $grp->setName($p['name']);
    $grp->setInfo($p['info']);
    $grp->setLevel($p['level']);
    $grp->save();
    redir('a/usergroups');
}
$header->setTitle('Admin: Manage user groups');
echo '<h1>Manage user groups</h1>';
echo '<h2>Add new group</h2>';
$form = new XhtmlForm('adm_usergroup');
$form->addInput('name', 'Group name');
$form->addTextarea('info', 'Info');
$form->addDropdown('level', 'Level', getUserLevels());
$form->addSubmit('Add');
$form->setHandler('addUserGroupSubmit');
echo $form->render();
echo '<br/>';
echo '<h2>Existing groups</h2>';
echo '<table>';
echo '<tr><th>Name</th><th>Level</th><th>Info</th><th>Created</th></tr>';
foreach (UserGroup::getAll() as $grp) {
    echo '<tr>';
    echo '<td>' . ahref('a/usergroup/' . $grp->getId(), $grp->getName()) . '</td>';
    echo '<td>' . $grp->getLevelDesc() . '</td>';
    echo '<td>' . $grp->getInfo() . '</td>';
    echo '<td>' . sql_datetime($grp->getTimeCreated()) . '</td>';
    echo '</tr>';
}
echo '</table>';
Beispiel #29
0
 public function store()
 {
     $obj->time_saved = sql_datetime(time());
     return SqlObject::store($this, self::$tbl_name, 'id');
 }
Beispiel #30
0
 public static function getAllBetween($time_start, $time_end)
 {
     $q = 'SELECT * FROM ' . self::$tbl_name . ' WHERE timeCreated BETWEEN "' . sql_datetime($time_start) . '" AND "' . sql_datetime($time_end) . '"' . ' ORDER BY timeCreated DESC';
     return Sql::pSelect($q);
 }