コード例 #1
0
 function marketNumber($number, $decimal_places = 0)
 {
     $lng =& MARKET_Base::getRef('Lang');
     return number_format($number, $decimal_places, $lng->strs['MATH']['Decimal_Point'], $lng->strs['MATH']['Thousands_Separator']);
 }
コード例 #2
0
function __($str)
{
    $lng = MARKET_Base::getRef('Lang');
    return $lng->translate($str);
}
コード例 #3
0
/**
 * @version     1.0a
 * @package     virtualCityMarket
 * @copyright   Copyright (C) 2012 Logotech S.A.. All rights reserved.
 * @license     GNU Affero General Public License version 3 or later; see LICENSE.txt
 * @author      Dimitrios Mitzias for Logotech S.A.
 */
function sqlQuery($sql, &$res, $log = true)
{
    global $MARKET_db_conn;
    // Connect to database
    if (!is_resource($MARKET_db_conn)) {
        $MARKET_db_conn = @mysqli_connect(MARKET_DB_HOST, MARKET_DB_USER, MARKET_DB_PASS, MARKET_DB_DATABASE) or MARKET_Base::raiseError(MARKET_ERROR_DIE, 'sql_connect(): Cannot connect to "' . MARKET_DB_HOST . '" SQL Server', __FILE__, __LINE__);
        @mysqli_select_db($MARKET_db_conn, MARKET_DB_DATABASE) or MARKET_Base::raiseError(MARKET_ERROR_DIE, 'sql_select_db(): Cannot select database "' . MARKET_DB_DATABASE . '"', __FILE__, __LINE__);
        if (defined('MARKET_DB_COLLATION')) {
            @mysqli_query($MARKET_db_conn, "SET NAMES '" . MARKET_DB_COLLATION . "'");
        } else {
            @mysqli_query($MARKET_db_conn, "SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");
        }
    }
    if (DEBUG && $log) {
        $dbg =& MARKET_Base::getRef('Debug');
        $dbg->add('sql', $sql);
        $prf =& MARKET_Base::getRef('Profiler');
        $prf->startTimer('sqlQuery', $sql);
    }
    $res = @mysqli_query($MARKET_db_conn, $sql);
    if (DEBUG && $log) {
        $prf->stopTimer('sqlQuery');
    }
    if ($res) {
        if (preg_match('@^(SELECT|SHOW)(?! CREATE)@', $sql) && ($found = @mysqli_num_rows($res))) {
            if (DEBUG && $log) {
                $dbg->add('info', 'MySQL Results: ' . $found);
            }
            return $found;
        } else {
            if (preg_match('@^EXPLAIN@', $sql) && ($found = @mysqli_num_rows($res))) {
                return true;
            } else {
                if (preg_match('@^INSERT@', $sql)) {
                    $sql = "SELECT LAST_INSERT_ID()";
                    $res = @mysqli_query($MARKET_db_conn, $sql);
                    $row = @mysqli_fetch_row($res);
                    $insert_id = $row[0];
                    $insert_id = $insert_id ? $insert_id : -1;
                    if (DEBUG && $log) {
                        $dbg->add('info', 'MySQL Insert ID: ' . $insert_id);
                    }
                    return $insert_id;
                } else {
                    if (preg_match('@^(UPDATE|DELETE|REPLACE)@', $sql)) {
                        $affected_rows = @mysqli_affected_rows($MARKET_db_conn);
                        if (DEBUG && $log) {
                            $dbg->add('info', 'MySQL Affected Rows: ' . $affected_rows);
                        }
                        return $affected_rows;
                    } else {
                        if (preg_match('@^CREATE@', $sql)) {
                            if (DEBUG && $log) {
                                $dbg->add('info', 'MySQL Results: Table creation');
                            }
                            return true;
                        } else {
                            if (preg_match('@^SHOW CREATE@', $sql)) {
                                if (DEBUG && $log) {
                                    $dbg->add('info', 'MySQL Results: Table creation SQL');
                                }
                                return true;
                            } else {
                                if (DEBUG && $log) {
                                    $dbg->add('info', 'MySQL Results: Unknown');
                                }
                            }
                        }
                    }
                }
            }
        }
    } else {
        if (DEBUG && $log) {
            $dbg->add('info', 'MySQL Error: ' . sqlError());
        }
    }
    return false;
}
コード例 #4
0
 function raiseError($level, $error, $file, $line)
 {
     global $MARKET_ERROR;
     if (defined('DEBUG') && DEBUG) {
         $dbg =& MARKET_Base::getRef('Debug');
     }
     $MARKET_ERROR = preg_replace('@^(.*):@U', '<b>$1:</b>', sprintf('%s [file %s, line %d]', $error, basename($file), $line));
     // Warning
     if ($level & MARKET_ERROR_WARNING) {
         if (defined('DEBUG') && DEBUG) {
             $dbg->add('warning', $MARKET_ERROR);
         }
     }
     // Just return
     if ($level & MARKET_ERROR_RETURN) {
         if (defined('DEBUG') && DEBUG) {
             $dbg->add('error', $MARKET_ERROR);
         }
     }
     // Print this error
     if ($level & MARKET_ERROR_PRINT) {
         if (defined('DEBUG') && DEBUG) {
             $dbg->add('error', $MARKET_ERROR);
         }
         $this->user_errors[] = '<i>' . $error . '</i>';
     }
     // Fatal Error
     if ($level & MARKET_ERROR_DIE) {
         fatalError($error, $file, $line);
         // This function will exit
     }
 }