function userLogin($sql)
 {
     if (sqlQuery($sql, $res, EXT_DEBUG)) {
         $_SESSION['User'] = sqlFetchAssoc($res);
         $_SESSION['User']['data'] = unserialize($_SESSION['User']['data']);
         $_SESSION['User']['is_loggedin'] = true;
         return true;
     }
     return false;
 }
            }
            foreach ($tags as $tag) {
                $str .= '<li><a href="index.html?content=tag&q=' . urlencode($tag) . '">' . htmlspecialchars($tag) . '</a></li>';
            }
            $str .= '</ul>';
        }
        $this->assignLocal('category', 'ROW', array('ndx' => $i, 'title' => $row['category'], 'tags' => $str));
        $this->lightParseTemplate('CATEGORY', 'category');
        $i++;
    }
} else {
    $this->disableTemplate('categories');
}
// Cities
if (!defined('MARKET_CITIES_MENU') || defined('MARKET_CITIES_MENU') && MARKET_CITIES_MENU) {
    $sql = "SELECT city FROM directory_ml WHERE lang='" . MARKET_LANG . "' AND city <> '' GROUP BY city ORDER BY city";
    if (sqlQuery($sql, $res)) {
        $cities = array();
        while ($row = sqlFetchAssoc($res)) {
            $cities[] = $row['city'];
        }
        asort($cities);
        $str = '';
        foreach ($cities as $city) {
            $str .= '<li><a href="index.html?content=city&q=' . urlencode($city) . '">' . htmlspecialchars($city) . '</a></li>';
        }
        $this->assignGlobal('CATEGORIES.Cities', $str);
    }
} else {
    $this->disableTemplate('cities');
}
 function getSQL($lang = '')
 {
     if (!$lang) {
         $lang = MARKET_LANG;
     }
     switch ($this->sql_type) {
         case 'SELECT':
             $tables = $this->extractTables($this->sql['FROM']);
             if (is_array($tables)) {
                 $fields = $this->extractFields($this->sql['SELECT'], $tables);
                 foreach ($tables as $table) {
                     $features = $this->getFeatures($table);
                     if ($features['versioning']) {
                         $this->prepareVsSQL($table, $lang);
                     } else {
                         if ($features['workflow'] && in_array($table . '_ps', $this->should_join)) {
                             $this->prepareWkSQL($table);
                         }
                         if ($features['multilingual'] && in_array($table . '_ml', $this->should_join)) {
                             $this->prepareMlSQL($table, $lang);
                         }
                     }
                 }
             }
             $sql = '';
             foreach ($this->sql as $key => $val) {
                 if ($val) {
                     //if (!($key == 'WHERE' && $val == '1')) {
                     $sql .= $key . ' ' . $val . ' ';
                     //}
                 }
             }
             return $sql;
             break;
         case 'DELETE':
             $sql = "SELECT " . $table . ".id " . $sql;
             if (sqlQuery($sql, $res)) {
                 while ($row = sqlFetchAssoc($res)) {
                     $sqls[] = "DELETE FROM " . $table . " WHERE id='" . $row['id'] . "'";
                     if ($features['workflow']) {
                         $sqls[] = "DELETE FROM " . $table . "_ps WHERE id='" . $row['id'] . "'";
                     }
                 }
                 return $sqls;
             } else {
                 return false;
             }
             break;
     }
 }
 function analyzePage()
 {
     // Get a reference to a template
     $tpl =& $this->getRef('Template');
     if ($tpl->loadTemplate('debug', MARKET_INDIRECT_CALL)) {
         // Elapsed Time
         $tpl->assignLocal('debug', 'ELAPSED_TIME', $this->getElapsedTime());
         // Memory
         $tpl->assignLocal('debug', 'MEMORY_USED', $this->getMemoryUsage());
         // Errors
         $counti = count($this->errors);
         if ($counti) {
             $tpl->assignLocal('debug', 'NUM_OF_ERRORS', $counti . ' ' . ($counti == 1 ? 'error' : 'errors') . ' occured.');
             $vars = '';
             for ($i = 0; $i < $counti; $i++) {
                 $vars .= 'type:`' . $this->errors[$i][0] . '`,value:`' . $this->errors[$i][1] . '`;';
             }
             $tpl->assignSource('error', $vars);
         } else {
             $tpl->assignLocal('debug', 'NUM_OF_ERRORS', 'No error.');
             $tpl->disableTemplate('errors_cnt');
         }
         // Variables
         $counti = count($this->vars);
         if ($counti) {
             $tpl->assignLocal('debug', 'NUM_OF_VARS', $counti . ' ' . ($counti == 1 ? 'variable' : 'variables') . ' watched.');
             $vars = '';
             foreach ($this->vars as $avar => $value) {
                 $vars .= 'variable:`' . $avar . '`,value:`' . $value . "`;";
             }
             $tpl->assignSource('variable', $vars);
         } else {
             $tpl->assignLocal('debug', 'NUM_OF_VARS', 'No variables.');
             $tpl->disableTemplate('variables_cnt');
         }
         // SQLs
         $counti = count($this->sqls);
         if ($counti) {
             $tpl->assignLocal('debug', 'NUM_OF_SQLS', 'This page executed ' . $counti . ' ' . ($counti == 1 ? 'query' : 'queries') . '.');
             $vars = '';
             for ($i = 0; $i < $counti; $i++) {
                 $vars = "sql_query:`" . htmlspecialchars($this->sqls[$i]) . "`;";
                 $tpl->assignSource('sql', $vars);
                 $tpl->assignLocal('sql', 'SQL_INFO', '[' . $this->infos[$i] . ']');
                 if (preg_match('@^SELECT@', $this->sqls[$i])) {
                     if (sqlQuery('EXPLAIN ' . $this->sqls[$i], $res, false)) {
                         $vars = '';
                         while ($row = sqlFetchAssoc($res)) {
                             foreach ($row as $key => $val) {
                                 if (!$val) {
                                     $val = '&nbsp;';
                                 }
                                 $vars .= ucfirst($key) . ':`' . $val . '`,';
                             }
                             $vars = substr($vars, 0, -1) . ';';
                         }
                         if (preg_match('@^comment:`(.*)`@i', $vars, $match)) {
                             $tpl->assignGlobal('SQL_CNT', '<br />[Comment: ' . $match[1] . ']');
                             $tpl->disableTemplate('sql_cnt');
                         } else {
                             $tpl->assignSource('explain', $vars);
                             $tpl->parseTemplate('EXPLAIN', 'explain', MARKET_DO_NOT_APPEND);
                             $tpl->parseTemplate('SQL_CNT', 'sql_cnt', MARKET_DO_NOT_APPEND);
                         }
                     } else {
                         $tpl->clearGlobal('SQL_CNT');
                         $tpl->disableTemplate('sql_cnt');
                     }
                 } else {
                     $tpl->clearGlobal('SQL_CNT');
                     $tpl->disableTemplate('sql_cnt');
                 }
                 $tpl->parseTemplate('SQL', 'sql');
                 $tpl->enableTemplate('sql_cnt');
             }
             $tpl->clearGlobal('SQL_CNT');
         } else {
             $tpl->assignLocal('debug', 'NUM_OF_SQLS', 'This page did not execute any query.');
             $tpl->disableTemplate('sql');
         }
         // Profiling data
         $prf =& $this->getRef('Profiler');
         $counti = count($prf->trace);
         if ($counti) {
             $tpl->assignLocal('debug', 'NUM_OF_TIMERS', $counti . ' ' . ($counti == 1 ? 'timer' : 'timers') . '.');
             $vars = '';
             foreach ($prf->trace as $timer) {
                 $vars .= 'timer:`' . $timer['name'] . '`,description:`' . $timer['description'] . '`,elapsed:`' . $timer['elapsed'] . ' secs`;';
             }
             $tpl->assignSource('profile', $vars);
         } else {
             $tpl->assignLocal('debug', 'NUM_OF_TIMERS', 'No timer set.');
             $tpl->disableTemplate('profiler_cnt');
         }
         // Cache Hits
         if (MARKET_ENABLE_CACHE) {
             $tpl->assignLocal('debug', 'NUM_OF_HITS', $tpl->cache_hits . ' ' . ($tpl->cache_hits == 1 ? 'hit' : 'hits') . '.');
         } else {
             $tpl->assignLocal('debug', 'NUM_OF_HITS', 'Disabled');
         }
         $tpl->parseTemplate('PAGE.Debug', 'debug');
     } else {
         $tpl->assignGlobal('PAGE.Debug', 'Elapsed time: ' . $this->getElapsedTime());
     }
     return $tpl->getVariable('global', 'PAGE.Debug');
 }
 function parseTemplate($var = '', $tname = '', $append = true)
 {
     global $MARKET_mode;
     $tname = $tname ? $tname : $this->last_loaded;
     if ($this->is_loaded[$tname]) {
         if (!$this->is_disabled[$tname]) {
             $parsed = '';
             // Short name
             $template =& $this->templates[$tname];
             if ($template['include'] && preg_match('@\\.php$@', $template['include'])) {
                 $this->includePhpFile($template['include']);
             }
             if ($template['script']) {
                 eval($template['script']);
             }
             // Parse children
             if (is_array($template['children'])) {
                 foreach ($template['children'] as $child) {
                     if (!$this->is_parsed[$child]) {
                         $this->parseTemplate(strtoupper($child), $child);
                     }
                 }
             }
             if ($template['source']) {
                 // Parse the source
                 $source = $this->replaceVars('sglobal', $template['source']);
                 if ($source) {
                     // Source is an SQL query
                     if (preg_match("@^SELECT@", $source)) {
                         $sql = $source;
                         // Navigation
                         if ($template['navigation']) {
                             list($layout, $start, $show, $limit, $javascript) = $this->arrayTrim(explode(',', $template['navigation'], 5));
                             $this->assignNavigationValues($sql, $layout, $start, $show, $limit, $javascript);
                         }
                         if (sqlQuery($sql, $res)) {
                             while ($row = sqlFetchAssoc($res)) {
                                 foreach ($row as $key => $val) {
                                     $this->assignLocal($tname, strtoupper($key), $val);
                                 }
                                 // Template has a radio, checkbox or option input. Try to determine whether it has to be checked.
                                 if ($template['has_input']) {
                                     $parsed .= $this->checkInput($this->replaceVars($tname, $template['has_input']), $this->replaceVars($tname, $template['text']));
                                 } else {
                                     $parsed .= rtrim($this->replaceVars($tname, $template['text'])) . $template['divider'] . "\n";
                                 }
                             }
                             // Remove divider from end of string
                             if ($template['divider']) {
                                 $parsed = substr($parsed, 0, -(strlen($template['divider']) + 1));
                             }
                         } else {
                             // Alternate text
                             $parsed .= $this->replaceVars($tname, $template['alt']);
                         }
                     } else {
                         $arr = $this->parseSource($source);
                         $i = 1;
                         foreach ($arr as $val) {
                             $this->assignLocal($tname, 'MARKET.aa', $i);
                             $this->assignLocal($tname, $val);
                             $parsed .= $this->replaceVars($tname, $template['text']) . $template['divider'];
                             $i++;
                         }
                         // Remove divider from end of string
                         if ($template['divider']) {
                             $parsed = substr($parsed, 0, -(strlen($template['divider']) + 1));
                         }
                     }
                 }
             } else {
                 // Template has a radio, checkbox or option input. Try to determine whether it has to be checked.
                 if ($template['has_input']) {
                     $parsed .= $this->checkInput($this->replaceVars($tname, $template['has_input']), $this->replaceVars($tname, $template['text']));
                 } else {
                     $parsed .= $this->replaceVars($tname, $template['text']);
                 }
             }
             // Global vars
             if ($template['global']) {
                 foreach ($template['global'] as $key => $val) {
                     $this->assignGlobal($key, $this->replaceVars($tname, $val));
                 }
             }
             // Assign the parsed template
             if ($template['assign']) {
                 $this->assignGlobal($template['assign'], $parsed, $append);
                 $this->last_parsed = $template['assign'];
             } else {
                 if ($var) {
                     $this->assignGlobal($var, $parsed, $append);
                     $this->last_parsed = $var;
                 } else {
                     $this->assignGlobal(strtoupper($tname), $parsed, $append);
                     $this->last_parsed = strtoupper($tname);
                 }
             }
             $this->is_parsed[$tname] = true;
             $this->clearLocal($tname);
         } else {
             $this->raiseError(MARKET_ERROR_WARNING, __FUNCTION__ . '(): Template "' . htmlspecialchars($tname) . '" is disabled', __FILE__, __LINE__);
         }
     } else {
         $this->raiseError(MARKET_ERROR_RETURN, __FUNCTION__ . '(): Template "' . htmlspecialchars($tname) . '" is not loaded', __FILE__, __LINE__);
     }
 }