Esempio n. 1
0
 /**
  * convert a date into a MDB2 timestamp
  *
  * @param integer $hour hour of the date
  * @param integer $minute minute of the date
  * @param integer $second second of the date
  * @param integer $month month of the date
  * @param integer $day day of the date
  * @param integer $year year of the date
  * @return string a valid MDB2 timestamp
  * @access public
  */
 function date2Mdbstamp($hour = null, $minute = null, $second = null, $month = null, $day = null, $year = null)
 {
     return MDB2_Date::unix2Mdbstamp(mktime($hour, $minute, $second, $month, $day, $year, 0));
 }
Esempio n. 2
0
 function isInYear($year, $field)
 {
     // The value of $year is got from get variable, so we must chech that it
     // is really a integer with correct value
     if (!is_int(intval($year)) || $year < 2000) {
         $this->debugger->error("The year value is not correct", "isInYear");
     }
     $yearStarts = mktime(0, 0, 0, 1, 1, $year);
     $yearEnds = mktime(0, 0, 0, 1, 1, $year + 1);
     return " {$field} >= '" . MDB2_Date::unix2Mdbstamp($yearStarts) . "' AND {$field} < '" . MDB2_Date::unix2Mdbstamp($yearEnds) . "' ";
 }
Esempio n. 3
0
 /**
  * LiveUser_Auth_Container_MDB2::updateUserData()
  *
  * Writes current values for user back to the database.
  * This method does nothing in the base class and is supposed to
  * be overridden in subclasses according to the supported backend.
  *
  * @return mixed true or an MDB2 error object
  * @access private
  */
 function updateUserData()
 {
     if (!$this->init_ok) {
         return false;
     }
     if (isset($this->authTableCols['lastlogin'])) {
         $sql = 'UPDATE ' . $this->authTable . '
                  SET ' . $this->authTableCols['lastlogin']['name'] . '=' . $this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->authTableCols['lastlogin']['type']) . '
                  WHERE ' . $this->authTableCols['user_id']['name'] . '=' . $this->dbc->quote($this->authUserId, $this->authTableCols['user_id']['type']);
         $res = $this->dbc->query($sql);
         return $res;
     } else {
         return false;
     }
 }
Esempio n. 4
0
 /**
  * Writes current values for user back to the database.
  * This method does nothing in the base class and is supposed to
  * be overridden in subclasses according to the supported backend.
  *
  * @return boolean true on success or false on failure
  *
  * @access private
  */
 function _updateUserData()
 {
     if (!isset($this->tables['users']['fields']['lastlogin'])) {
         return true;
     }
     $query = 'UPDATE ' . $this->prefix . $this->alias['users'] . '
              SET ' . $this->alias['lastlogin'] . '=' . $this->dbc->quote(MDB2_Date::unix2Mdbstamp($this->currentLogin), $this->fields['lastlogin']) . '
              WHERE ' . $this->alias['auth_user_id'] . '=' . $this->dbc->quote($this->propertyValues['auth_user_id'], $this->fields['auth_user_id']);
     $result = $this->dbc->query($query);
     if (PEAR::isError($result)) {
         $this->_stack->push(LIVEUSER_ERROR, 'exception', array('reason' => $result->getMessage() . '-' . $result->getUserInfo()));
         return false;
     }
     return true;
 }
Esempio n. 5
0
    public function acquireLock($type = '')
    {
        if ($this->haveLock($type)) {
            return TRUE;
        }
        if (!$this->canAcquireLock()) {
            return FALSE;
        }
        $db =& $GLOBALS['db'];
        $sql = 'INSERT INTO db_object_lock (objectid, object_type, lock_type, userid, expires)
				VALUES (
					' . $db->quote($this->id) . ',
					' . $db->quote(strtolower(get_class($this))) . ',
					' . $db->quote($type) . ',
					' . $db->quote($this->getCurrentUser('id')) . ',
					' . $db->quote(MDB2_Date::unix2Mdbstamp(strtotime('+' . LOCK_LENGTH))) . ')';
        $res = $db->query($sql);
        check_db_result($res);
        $this->_held_locks[$type] = TRUE;
        $this->_acquirable_locks[$type] = TRUE;
        if (rand(LOCK_CLEANUP_PROBABLILITY, 100) == 100) {
            $sql = 'DELETE FROM db_object_lock
					WHERE expires < ' . $db->quote(MDB2_Date::unix2Mdbstamp(time()));
            $res = $db->query($sql);
            check_db_result($res);
        }
        return TRUE;
    }
Esempio n. 6
0
<?php

require_once "../DBInterface.php";
require_once "../ErrorReportEnabler.php";
MDB2::loadFile("Date");
$sql = "SELECT (" . MDB2_Date::mdbNow() . " - " . MDB2_Date::unix2Mdbstamp(strtotime('Jan 18, 2007')) . ")";
print "<p>{$sql}</p>";
$result = query($conn, $sql);
print_r($result->fetchRow());
Esempio n. 7
0
 function timeToSql($timestamp)
 {
     return MDB2_Date::unix2Mdbstamp($timestamp);
 }