function marketQRCode($data, $errorCorrectionLevel = 'L', $matrixPointSize = 4)
 {
     require_once MARKET_ROOT_DIR . '/redist/phpqrcode/qrlib.php';
     $code = md5($data . '|' . $errorCorrectionLevel . '|' . $matrixPointSize);
     $code_dir = substr($code, 0, 2);
     $filename = MARKET_ROOT_DIR . '/cache/qrcode/' . $code_dir . '/' . md5($data . '|' . $errorCorrectionLevel . '|' . $matrixPointSize) . '.png';
     if (!@is_file($filename)) {
         MARKET_Base::makeDir(dirname($filename));
         QRcode::png($data, $filename, $errorCorrectionLevel, $matrixPointSize, 2);
     }
     return MARKET_WEB_DIR . '/cache/qrcode/' . $code_dir . '/' . basename($filename);
 }
 function MARKET()
 {
     // Debugging
     if (defined('DEBUG') && DEBUG) {
         // Error Reporting
         error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
         ini_set('display_errors', '1');
         // Start debugging
         $this->getRef('Debug');
     }
     // Timezone settings
     if (defined('MARKET_TIMEZONE')) {
         date_default_timezone_set(MARKET_TIMEZONE);
     } else {
         date_default_timezone_set('UTC');
     }
     // Internal encoding for multi-byte string manipulation
     if (extension_loaded('mbstring')) {
         mb_internal_encoding('UTF-8');
         mb_regex_encoding('UTF-8');
     } else {
         MARKET_Base::raiseError(MARKET_ERROR_DIE, 'The "mbstring" extension is not loaded. Please see the README file.', __FILE__, __LINE__);
     }
     // Parse the request
     $this->getRef('Request');
 }
/**
 * @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;
}
 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
     }
 }