Ejemplo n.º 1
0
 /**
  * Query
  *
  * @param mixed $sql
  * @param mixed $inputarr
  * @param mixed $numrows
  * @param mixed $offset
  * @access public
  * @return void
  */
 public function Query($sql, $inputarr = false, $numrows = -1, $offset = -1)
 {
     // auto add $dbprefix where we have {table}
     $sql = $this->_add_prefix($sql);
     // remove conversions for MySQL
     if (strcasecmp($this->dbtype, 'pgsql') != 0) {
         $sql = str_replace('::int', '', $sql);
         $sql = str_replace('::text', '', $sql);
     }
     $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
     if ($numrows >= 0 or $offset >= 0) {
         /* adodb drivers are inconsisent with the casting of $numrows and $offset so WE
          * cast to integer here anyway */
         $result = $this->dblink->SelectLimit($sql, (int) $numrows, (int) $offset, $inputarr);
     } else {
         $result = $this->dblink->Execute($sql, $inputarr);
     }
     if (!$result) {
         if (function_exists("debug_backtrace") && defined('DEBUG_SQL')) {
             echo "<pre style='text-align: left;'>";
             var_dump(debug_backtrace());
             echo "</pre>";
         }
         $query_params = '';
         if (is_array($inputarr) && count($inputarr)) {
             $query_params = implode(',', array_map(array('Filters', 'noXSS'), $inputarr));
         }
         die(sprintf("Query {%s} with params {%s} Failed! (%s)", Filters::noXSS($sql), $query_params, Filters::noXSS($this->dblink->ErrorMsg())));
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Session garbage collection handler
  *
  * @access protected
  * @return boolean
  */
 function _gc()
 {
     if (!$this->_db->Execute('DELETE FROM sessions WHERE expire < ' . $this->_db->DBTimeStamp(time() - $this->sessionLife)) && AK_DEBUG) {
         trigger_error($this->_db->ErrorMsg(), E_USER_NOTICE);
     }
     return (bool) $this->_db->Affected_Rows();
 }
Ejemplo n.º 3
0
 /**
  * Increment the counter
  * @return nothing
  * @access public
  */
 function incrementCounter()
 {
     // increment in the same table
     if ($this->table != '' && count($this->pk) > 0 && $this->counterField != '') {
         $fileHash = $this->downloadHash;
         $this->pk['value'] = $fileHash['pk'];
         $sql = 'UPDATE ' . $this->table . ' SET ' . KT_escapeFieldName($this->counterField) . ' = ' . KT_escapeFieldName($this->counterField) . '+ 1 WHERE ' . KT_escapeFieldName($this->pk['field']) . ' = ' . KT_escapeForSql($this->pk['value'], $this->pk['type'], false);
         $ret = $this->conn->Execute($sql);
         if ($ret === false) {
             $this->setError(new tNG_error('INCREMENTER_ERROR', array(), array($this->conn->ErrorMsg(), $sql)));
             return;
         }
     }
     // increment in the MTM table
     if ($this->counterFieldMtm != '' && $this->tableMtm != '' && count($this->fkMtm) > 0 && count($this->pkMtm) > 0) {
         $fileHash = $this->downloadHash;
         if (!isset($fileHash['fkMtm']) || $fileHash['fkMtm'] == '') {
             $this->setError(new tNG_error('INCREMENTER_ERROR_FK', array(), array($this->fkMtm['field'])));
             return;
         }
         $this->fkMtm['value'] = $fileHash['fkMtm'];
         if (!isset($fileHash['pkMtm']) || $fileHash['pkMtm'] == '') {
             $this->setError(new tNG_error('INCREMENTER_ERROR_FK', array(), array($this->pkMtm['field'])));
             return;
         }
         $this->pkMtm['value'] = $fileHash['pkMtm'];
         $sql = 'UPDATE ' . $this->tableMtm . ' SET ' . KT_escapeFieldName($this->counterFieldMtm) . ' = ' . KT_escapeFieldName($this->counterFieldMtm) . '+ 1 WHERE ' . KT_escapeFieldName($this->pkMtm['field']) . ' = ' . KT_escapeForSql($this->pkMtm['value'], $this->pkMtm['type'], false) . ' AND ' . KT_escapeFieldName($this->fkMtm['field']) . ' = ' . KT_escapeForSql($this->fkMtm['value'], $this->fkMtm['type'], false);
         $ret = $this->conn->Execute($sql);
         if ($ret === false) {
             $this->setError(new tNG_error('INCREMENTER_ERROR', array(), array($this->conn->ErrorMsg(), $sql)));
             return;
         }
     }
     return null;
 }
Ejemplo n.º 4
0
 /**
  * Inserts $message to the currently open database.  Calls open(),
  * if necessary.  Also passes the message along to any Log_observer
  * instances that are observing this Log.
  *
  * @param mixed  $message  String or object containing the message to log.
  * @param string $priority The priority of the message.  Valid
  *                  values are: PEAR_LOG_EMERG, PEAR_LOG_ALERT,
  *                  PEAR_LOG_CRIT, PEAR_LOG_ERR, PEAR_LOG_WARNING,
  *                  PEAR_LOG_NOTICE, PEAR_LOG_INFO, and PEAR_LOG_DEBUG.
  * @return boolean  True on success or false on failure.
  * @access public     
  */
 function log($message, $priority = null)
 {
     /* If a priority hasn't been specified, use the default value. */
     if ($priority === null) {
         $priority = $this->_priority;
     }
     /* Abort early if the priority is above the maximum logging level. */
     if (!$this->_isMasked($priority)) {
         return false;
     }
     /* If the connection isn't open and can't be opened, return failure. */
     if (!$this->_opened && !$this->open()) {
         return false;
     }
     /* Extract the string representation of the message. */
     $message = $this->_extractMessage($message);
     /* Build the SQL query for this log entry insertion. */
     $q = sprintf('insert into %s (logtime, ident, priority, message)' . 'values(%s, %s, %d, %s)', $this->_table, $this->_db->DBTimeStamp(time()), $this->_db->Quote($this->_ident), $priority, $this->_db->Quote($message));
     $result = $this->_db->Execute($q);
     if ($this->_db->ErrorMsg() != '') {
         return false;
     }
     $this->_announce(array('priority' => $priority, 'message' => $message));
     return true;
 }
 /**
  * import component data's from sql
  */
 function importDataFromSql()
 {
     $sqlDump = ASCMS_APP_CACHE_FOLDER . '/DLC_FILES' . SystemComponent::getPathForType($this->componentType) . '/' . $this->componentName . '/Data/Data.sql';
     if (!file_exists($sqlDump)) {
         return;
     }
     $pattern = '/\\s+INTO\\s+`?([a-z\\d_]+)`?/i';
     $moduleId = 0;
     $fp = @fopen($sqlDump, "r");
     if ($fp !== false) {
         while (!feof($fp)) {
             $buffer = fgets($fp);
             if (substr($buffer, 0, 1) != "#" && substr($buffer, 0, 2) != "--") {
                 $sqlQuery .= $buffer;
                 if (preg_match("/;[ \t\r\n]*\$/", $buffer)) {
                     $sqlQuery = preg_replace('#contrexx_#', DBPREFIX, $sqlQuery, 1);
                     $matches = null;
                     preg_match($pattern, $sqlQuery, $matches, 0);
                     $table = isset($matches[1]) ? $matches[1] : '';
                     switch ($table) {
                         case DBPREFIX . 'modules':
                             $data = $this->getColumnsAndDataFromSql($sqlQuery);
                             $newModuleId = $this->db->GetOne('SELECT MAX(`id`)+1 FROM `' . DBPREFIX . 'modules`');
                             $replacements = array('id' => $newModuleId);
                             $sqlQuery = $this->repalceDataInQuery($table, $data, $replacements);
                             break;
                         case DBPREFIX . 'component':
                             $data = $this->getColumnsAndDataFromSql($sqlQuery);
                             $replacements = array('id' => NULL);
                             $sqlQuery = $this->repalceDataInQuery($table, $data, $replacements);
                             break;
                         case DBPREFIX . 'backend_areas':
                             $data = $this->getColumnsAndDataFromSql($sqlQuery);
                             $replacements = array('module_id' => $newModuleId);
                             $sqlQuery = $this->repalceDataInQuery($table, $data, $replacements);
                             break;
                         default:
                             break;
                     }
                     $result = $this->db->Execute($sqlQuery);
                     if ($result === false) {
                         throw new SystemComponentException($sqlQuery . ' (' . $this->db->ErrorMsg() . ')');
                     }
                     $sqlQuery = '';
                 }
             }
         }
     }
 }
Ejemplo n.º 6
0
    public function UpdateTranslit($id_category)
    {
        $this->SetFieldsByID($id_category);
        $cat = $this->fields;
        $translit = G::StrToTrans($cat['name']);
        $sql = 'UPDATE ' . $this->table . '
			SET edit_user = '******'member']['id_user'] . ',
			edit_date = "' . date('Y-m-d H:i:s') . '",
			translit = "' . $translit . '"
			WHERE id_category = ' . $id_category;
        $this->db->StartTrans();
        $res = $this->db->Execute($sql);
        if (false === $res) {
            $this->ERRORS[] = array(2, 'SQL query error.', __FILE__ . '::' . __CLASS__ . '::' . __FUNCTION__ . '::' . __LINE__, 'SQL QUERY: ' . $sql, 'SQL ERROR: ' . $this->db->ErrorMsg());
            $this->ERRORS_MES[] = extension_loaded('gettext') ? _('internal_error') : 'internal_error';
            $this->db->FailTrans();
            return false;
        }
        $this->db->CompleteTrans();
        return $translit;
    }
Ejemplo n.º 7
0
 /**
  * Clean the cache
  *
  * If no group is specified all cache items  will be removed
  * from the database else only cache items of the specified
  * group will be destroyed
  *
  * @access public
  * @param    string    $group    If no group is specified all cache items  will be
  * removed from the database else only cache items
  * of the specified group will be destroyed
  * @param    string    $mode    Flush cache mode. Options are:
  *
  * - old
  * - ingroup
  * - notingroup
  * @return boolean True if no problem
  */
 function clean($group = false, $mode = 'ingroup')
 {
     switch ($mode) {
         case 'ingroup':
             if (!$this->_db->Execute('DELETE FROM cache WHERE cache_group = ' . $this->_db->qstr($group)) && AK_DEBUG) {
                 trigger_error($this->_db->ErrorMsg(), E_USER_NOTICE);
             }
             return (bool) $this->_db->Affected_Rows();
         case 'notingroup':
             if (!$this->_db->Execute('DELETE FROM cache WHERE cache_group NOT LIKE ' . $this->_db->qstr($group)) && AK_DEBUG) {
                 trigger_error($this->_db->ErrorMsg(), E_USER_NOTICE);
             }
             return (bool) $this->_db->Affected_Rows();
         case 'old':
             if (!$this->_db->Execute('DELETE FROM cache WHERE expire < ' . $this->_db->DBTimeStamp(time())) && AK_DEBUG) {
                 trigger_error($this->_db->ErrorMsg(), E_USER_NOTICE);
             }
             return (bool) $this->_db->Affected_Rows();
         default:
             return true;
     }
 }
Ejemplo n.º 8
0
 /**
  *Connect to the database
  *
  *This function connects to the database and stores the connection on {@link $conn}
  *
  */
 function connect()
 {
     if (empty($this->conn)) {
         $this->lasterror = 0;
         $this->lasterrmsg = '';
         $this->conn = ADONewConnection('mysql');
         $this->conn->Connect($this->host, $this->user, $this->password, $this->database);
     }
     if ($this->conn->ErrorNo() != 0) {
         $this->lasterror = 3;
         $this->lasterrmsg = $this->conn->ErrorMsg();
     }
 }