Exemple #1
0
 function findById($id)
 {
     $sql = "SELECT * FROM " . $this->tableName() . ' WHERE id= :id';
     $res = $this->db->query($sql, array('id' => $id));
     $data = $this->db->fetchAll($res, Database::FETCH_CLASS, $this->entityName());
     return $data;
 }
Exemple #2
0
 public function index()
 {
     $this->document->setTitle(Language::getVar('SUMO_ADMIN_THEMES_SETTINGS'));
     $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_SETTINGS_DASHBOARD'), 'href' => $this->url->link('settings/dashboard', '', 'SSL')));
     $this->document->addBreadcrumbs(array('text' => Language::getVar('SUMO_ADMIN_THEMES_SETTINGS')));
     $templates = glob(DIR_HOME . 'catalog/view/theme/*');
     foreach ($templates as $dir) {
         $tmp = explode('/', $dir);
         $name = end($tmp);
         if (file_exists($dir . '/information.php')) {
             include $dir . '/information.php';
             $template[$name]['edit'] = $this->url->link('settings/themes/builder', 'token=' . $this->session->data['token'] . '&theme=' . $name, 'SSL');
         } else {
             Logger::warning('Template ' . $name . ' does not have information.php');
             $template[$name] = array('error' => true);
         }
         $template[$name]['active'] = array();
         $stores = Database::fetchAll("SELECT store_id FROM PREFIX_settings_stores WHERE setting_name = 'template' AND setting_value = :tmpl", array('tmpl' => $name));
         foreach ($stores as $check) {
             $store = Database::query("SELECT setting_value AS name FROM PREFIX_settings_stores WHERE store_id = :id AND setting_name = 'title'", array('id' => $check['store_id']))->fetch();
             if (is_array($store)) {
                 $template[$name]['active'][] = $store['name'];
             }
         }
         $this->data['themes'][$name] = $template[$name];
     }
     $this->template = 'settings/themes/list.tpl';
     $this->children = array('common/header', 'common/footer');
     $this->response->setOutput($this->render());
 }
 public function getTranslationsByTranslation($letter = '', $language_id = 0)
 {
     if (!$language_id) {
         return false;
     }
     if (strlen($letter) == 1) {
         return Database::fetchAll("\n                SELECT t.id, t.key_id, t.value, tk.name\n                FROM PREFIX_translations AS t\n                LEFT JOIN PREFIX_translations_keys AS tk\n                ON tk.id = t.key_id\n                WHERE t.language_id = :lid\n                AND LOWER(t.value) LIKE :search\n                ORDER BY t.value ASC", array('lid' => $language_id, 'search' => '' . $letter . '%'));
     } else {
         if ($letter == 'empty') {
             $ignore = '';
             $ignoreList = Database::fetchAll("\n                SELECT key_id AS id\n                FROM PREFIX_translations\n                WHERE language_id = :lang\n                ", array('lang' => $language_id));
             foreach ($ignoreList as $list) {
                 if (empty($ignore)) {
                     $ignore = $list['id'];
                 } else {
                     $ignore .= ',' . $list['id'];
                 }
             }
             if (!empty($ignore)) {
                 $ignore = 'WHERE tk.id NOT IN(' . $ignore . ')';
             }
             return Database::fetchAll("\n                SELECT id, name, (SELECT value FROM PREFIX_translations WHERE key_id = tk.id AND language_id = :default) AS default_value\n                FROM PREFIX_translations_keys AS tk\n                " . $ignore . "\n                ORDER BY default_value ASC", array('default' => $this->config->get('config_language_id')));
         } else {
             return Database::fetchAll("\n                SELECT t.id, t.key_id, t.value, tk.name\n                FROM PREFIX_translations AS t\n                LEFT JOIN PREFIX_translations_keys AS tk\n                ON tk.id = t.key_id\n                WHERE t.language_id = :lid\n                AND (\n                    t.value LIKE '<%'\n                    OR t.value LIKE '\\%%'\n                    OR t.value LIKE '(%'\n                    OR t.value LIKE '^%'\n                    OR t.value LIKE '!%'\n                    OR t.value LIKE '\$%'\n                    OR t.value LIKE '*%'\n                    OR t.value LIKE ''\n                )\n                ORDER BY t.value ASC", array('lid' => $language_id));
         }
     }
 }
 public function getStockStatuses($data = array())
 {
     if ($data) {
         $sql = "SELECT * FROM " . DB_PREFIX . "stock_status WHERE language_id = '" . (int) $this->config->get('config_language_id') . "'";
         $sql .= " ORDER BY name";
         if (isset($data['order']) && $data['order'] == 'DESC') {
             $sql .= " DESC";
         } else {
             $sql .= " ASC";
         }
         if (isset($data['start']) || isset($data['limit'])) {
             if ($data['start'] < 0) {
                 $data['start'] = 0;
             }
             if ($data['limit'] < 1) {
                 $data['limit'] = 20;
             }
             $sql .= " LIMIT " . (int) $data['start'] . "," . (int) $data['limit'];
         }
         $query = $this->db->query($sql);
         return $query->rows;
     } else {
         return Database::fetchAll("SELECT stock_status_id, name\n                FROM PREFIX_stock_status\n                WHERE language_id = :lang\n                ORDER BY name", array('lang' => $this->config->get('language_id')));
     }
 }
Exemple #5
0
 static function get($params = array())
 {
     $query = 'SELECT * FROM bad_player';
     if (isset($params['order_by'])) {
         $query .= ' ORDER BY ' . $params['order_by'];
     }
     return Database::fetchAll($query);
 }
 public function getExtensions($type)
 {
     $cache = Cache::find('extensions.' . $this->config->get('config_store_id'), $type);
     if (!is_array($cache)) {
         $cache = Database::fetchAll("SELECT * FROM PREFIX_extension WHERE `type` = :type", array('type' => $type));
         Cache::set('extensions.' . $this->config->get('config_store_id'), $type, $cache);
     }
     return $cache;
 }
Exemple #7
0
 public function getStores($data = array())
 {
     $store_data = Cache::find('store');
     if (!$store_data || !is_array($store_data) || empty($store_data)) {
         $store_data = Database::fetchAll("SELECT * FROM PREFIX_store ORDER BY url");
         Cache::set('store', $store_data);
     }
     return $store_data;
 }
Exemple #8
0
 public function getSettings($refresh = false)
 {
     if (is_array($this->settings) && count($this->settings) && !$refresh) {
         return $this->settings;
     }
     foreach (Database::fetchAll("SELECT setting_name, setting_value, is_json FROM PREFIX_settings") as $list) {
         $this->settings[$list['setting_name']] = $list['is_json'] ? json_decode($list['setting_value'], true) : $list['setting_value'];
     }
     return $this->settings;
 }
Exemple #9
0
 public function getSettings($store_id, $refresh = false)
 {
     if (is_array($this->settings) && count($this->settings) && !$refresh) {
         return $this->settings;
     }
     $this->settings[$store_id] = $this->getStore($store_id);
     foreach (Database::fetchAll("SELECT setting_name, setting_value, is_json FROM PREFIX_settings_stores WHERE store_id = :id", array('id' => $store_id)) as $list) {
         $this->settings[$store_id][$list['setting_name']] = $list['is_json'] ? json_decode($list['setting_value'], true) : $list['setting_value'];
     }
     return $this->settings[$store_id];
 }
 /**
  * @covers DataBase::fetchAll
  */
 public function testFetchAll()
 {
     $result = $this->db->fetchAll("SELECT * FROM test");
     $this->assertInternalType('array', $result, LoggerApp::getLastError());
     $this->assertEquals(3, count($result));
     $this->assertEquals(3, $this->db->rowCount());
     for ($i = 1; $i <= 3; $i++) {
         $this->assertEquals('value ' . $i, $result[$i - 1]['name']);
     }
     $r1 = $this->db->fetchAll("SELECT * FROM test WHERE id > ? ORDER BY id", 1);
     $this->assertFalse(LoggerApp::hasError(), LoggerApp::getLastError());
     $this->assertEquals(2, count($r1));
     $this->assertEquals(2, $this->db->rowCount());
     for ($i = 2; $i <= 3; $i++) {
         $this->assertEquals('value ' . $i, $r1[$i - 2]['name']);
     }
     $r2 = $this->db->fetchAll("SELECT * FROM test WHERE id < ?", array(0));
     $this->assertFalse(LoggerApp::hasError(), LoggerApp::getLastError());
     $this->assertEquals(0, $this->db->rowCount());
     $this->assertEmpty($r2, 'Retorno deveria ser vazio');
 }
 public function create_general_list()
 {
     $db = new Database();
     $db->query("SELECT * FROM movie ORDER BY RAND()");
     $values = $db->fetchAll();
     $list = array();
     for ($i = 0; $i < count($values); $i++) {
         array_push($list, $values[$i]['id']);
     }
     $_SESSION["movie_list"] = $list;
     $db = null;
     $this->create_url_from_list();
 }
Exemple #12
0
 public function __construct($registry)
 {
     $this->db = $registry->get('db');
     $this->config = $registry->get('config');
     $weights = Cache::find('weights.' . $this->config->get('config_language_id'));
     if (!is_array($weights)) {
         $weights = Database::fetchAll("SELECT * FROM PREFIX_weight_class AS wc LEFT JOIN PREFIX_weight_class_description AS wcd ON (wc.weight_class_id = wcd.weight_class_id) WHERE wcd.language_id = :lang", array('lang' => $this->config->get('config_language_id')));
         Cache::set('weights.' . $this->config->get('config_language_id'), $weights);
     }
     foreach ($weights as $result) {
         $this->weights[$result['weight_class_id']] = array('weight_class_id' => $result['weight_class_id'], 'title' => $result['title'], 'unit' => $result['unit'], 'value' => $result['value']);
     }
 }
Exemple #13
0
 public function __construct($registry)
 {
     $this->db = $registry->get('db');
     $this->config = $registry->get('config');
     $lengths = Cache::find('lengths.' . $this->config->get('config_language_id'));
     if (!is_array($lengths)) {
         $lengths = Database::fetchAll("SELECT * FROM PREFIX_length_class AS lc LEFT JOIN PREFIX_length_class_description AS lcd ON (lc.length_class_id = lcd.length_class_id) WHERE lcd.language_id = :lang", array('lang' => $this->config->get('config_language_id')));
         Cache::set('lengths.' . $this->config->get('config_language_id'), $lengths);
     }
     foreach ($lengths as $result) {
         $this->lengths[$result['length_class_id']] = array('length_class_id' => $result['length_class_id'], 'title' => $result['title'], 'unit' => $result['unit'], 'value' => $result['value']);
     }
 }
Exemple #14
0
 public static function getTemplate($idOrKey, $language_id = null)
 {
     if ($language_id == null || !$language_id) {
         $language_id = self::$config->get('language_id');
     }
     if (is_string($idOrKey) && !is_numeric($idOrKey)) {
         $where = 'event_key';
     } else {
         $where = 'mail_id';
     }
     $content = Database::fetchAll("SELECT language_id, title, content, event_key\n            FROM PREFIX_mails_content AS mc\n            LEFT JOIN PREFIX_mails_to_events AS mte\n                ON mc.mail_id = mte.mail_id\n            WHERE mte." . $where . " = :input", array('input' => $idOrKey));
     if (!$content || !count($content)) {
         Logger::warning('[Mailer] Template not found for ' . $where . ' ' . $idOrKey);
         return false;
     }
     $data = array();
     foreach ($content as $list) {
         $data[$list['language_id']] = $list;
     }
     if (isset($data[$language_id])) {
         $template = $data[$language_id];
     } else {
         $template = reset($data);
     }
     $template['content'] = html_entity_decode($template['content']);
     $status = null;
     $event = explode('_', $template['event_key']);
     if (count($event) == 4) {
         if ($event[2] == 'status' && !empty($event[3])) {
             $table = 'PREFIX_' . $event[1] . '_status';
             $where = $event[1] . '_status_id';
             $id = $event[3];
             try {
                 self::$status = Database::query("SELECT " . $where . " AS id, name FROM " . $table . " WHERE " . $where . " = :id AND language_id = :lang", array('id' => $id, 'lang' => $language_id))->fetch();
                 self::$status['type'] = strtoupper($event[1][0]) . 'ID.';
             } catch (\Exception $e) {
             }
         }
     }
     $toReplace = array();
     preg_match_all('/{+(.*?)}/', $template['content'], $toReplace);
     foreach ($toReplace[1] as $find) {
         $template['content'] = self::shortcodeReplacement($find, $template['content']);
     }
     $toReplace = array();
     preg_match_all('/{+(.*?)}/', $template['title'], $toReplace);
     foreach ($toReplace[1] as $find) {
         $template['title'] = self::shortcodeReplacement($find, $template['title']);
     }
     return $template;
 }
Exemple #15
0
 public function ajaxGetData()
 {
     $type = !empty($this->request->post['type']) ? $this->request->post['type'] : '';
     $id = !empty($this->request->post['id']) ? $this->request->post['id'] : 0;
     if (!empty($type) && in_array($type, $this->types)) {
         $data = array();
         $tmp = Database::fetchAll("SELECT language_id, name FROM PREFIX_" . $type . " WHERE " . $type . "_id = :id", array('id' => $id));
         if (count($tmp)) {
             foreach ($tmp as $list) {
                 $data['names'][$list['language_id']] = $list['name'];
             }
         }
         $this->response->setOutput(json_encode($data));
     }
 }
Exemple #16
0
 public function getSetting($group, $store_id = 0)
 {
     $cacheFile = 'settings.' . $store_id . '.' . strtolower($group);
     $data = Cache::find($cacheFile);
     if (is_array($data) || count($data)) {
         return $data;
     }
     $data = array();
     $result = Database::fetchAll("SELECT `key`, `value`, `serialized` FROM PREFIX_setting WHERE store_id = :id AND `group` = :group", array('id' => $store_id, 'group' => $group));
     foreach ($result as $list) {
         $data[$list['key']] = $result['serialized'] ? unserialize($result['value']) : $result['value'];
     }
     Cache::set($cacheFile, $data);
     return $data;
 }
 public function saveTheme($theme_id, $data)
 {
     $dataCheck = Database::fetchAll("SELECT name, create_date FROM PREFIX_builder_themes WHERE theme_id = :id", array('id' => $theme_id));
     if (!is_array($data) || !count($data)) {
         $theme_id = $this->addTheme($data['name']);
     }
     unset($data['name']);
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             $value = json_encode($value);
         }
         Database::query("DELETE FROM PREFIX_builder_themes_settings WHERE setting_name = :key AND theme_id = :id", array('key' => $key, 'id' => $theme_id));
         Database::insert("PREFIX_builder_themes_settings", array('setting_name' => $key, 'setting_value' => $value, 'theme_id' => $theme_id));
     }
     Cache::remove('builder');
 }
 public function ajax()
 {
     $action = isset($this->request->get['action']) ? $this->request->get['action'] : '';
     $lang = isset($this->request->get['lang']) ? $this->request->get['lang'] : $this->config->get('language_id');
     switch ($action) {
         case 'save':
             if (!empty($this->request->post['key_id']) && !empty($this->request->post['value'])) {
                 Language::setVar($this->request->post['key_id'], $lang, html_entity_decode($this->request->post['value'], ENT_QUOTES, 'UTF-8'));
             }
             break;
         case 'fetch':
             if (isset($_POST['keys']) && is_array($_POST['keys']) && !empty($_POST['keys']) && !empty($lang)) {
                 foreach ($_POST['keys'] as $key) {
                     if (!ctype_digit($key)) {
                         return;
                     }
                 }
                 $keys = implode(',', $_POST['keys']);
                 $result = Database::fetchAll("\n                        SELECT t.id, t.key_id, t.value,\n                            (SELECT value FROM PREFIX_translations WHERE key_id = t.key_id AND language_id = " . $this->config->get('language_id') . ") AS default_name,\n                            (SELECT name FROM PREFIX_translations_keys WHERE id = t.id) AS default_key\n                        FROM PREFIX_translations AS t\n                        WHERE language_id = " . $lang . "\n                            AND key_id IN(" . $keys . ")");
                 $this->response->setOutput(json_encode($result));
             }
             break;
         case 'empty':
             $keys = array();
             $keys = Database::fetchAll("\n                    SELECT id, name, (SELECT value FROM PREFIX_translations WHERE key_id = tk.id AND language_id = " . $this->config->get('language_id') . ") AS default_value FROM PREFIX_translations_keys AS tk ORDER BY id\n                ");
             $translated = Database::fetchAll("\n                    SELECT key_id AS id, value FROM PREFIX_translations WHERE language_id = " . $lang);
             foreach ($translated as $list) {
                 $list['value'] = trim($list['value']);
                 if (isset($keys[$list['id']]) && !empty($list['value'])) {
                     unset($keys[$list['id']]);
                 }
             }
             if (!$keys || count($keys) == 0) {
                 $keys['nothing_to_translate'] = 1;
             }
             $this->response->setOutput(json_encode($keys));
             break;
         default:
             $this->response->setOutput(json_encode(array('empty' => 'request')));
             break;
     }
 }
 public function getManufacturers($data = array())
 {
     if ($data) {
         $sql = "SELECT * FROM PREFIX_manufacturer m LEFT JOIN PREFIX_manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id) WHERE m2s.store_id = :store";
         $values = array();
         $values['store'] = $this->config->get('store_id');
         $sort_data = array('name', 'sort_order');
         if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
             $sql .= " ORDER BY :sort";
             $values['sort'] = $data['sort'];
         } else {
             $sql .= " ORDER BY name";
         }
         if (isset($data['order']) && $data['order'] == 'DESC') {
             $sql .= " DESC";
         } else {
             $sql .= " ASC";
         }
         if (isset($data['start']) || isset($data['limit'])) {
             if ($data['start'] < 0) {
                 $data['start'] = 0;
             }
             if ($data['limit'] < 1) {
                 $data['limit'] = 20;
             }
             $values['start'] = $data['start'];
             $values['limit'] = $data['limit'];
             $sql .= " LIMIT :start,:limit";
         }
         $result = Database::fetchAll($sql, $values);
         return $result;
     } else {
         $manufacturer_data = Cache::find('manufacturer.' . (int) $this->config->get('store_id'));
         if (!$manufacturer_data) {
             $manufacturer_data = Database::fetchAll("SELECT * FROM PREFIX_manufacturer m LEFT JOIN PREFIX_manufacturer_to_store m2s ON (m.manufacturer_id = m2s.manufacturer_id) WHERE m2s.store_id = :store ORDER BY name", array('store' => $this->config->get('store_id')));
             Cache::set('manufacturer.' . (int) $this->config->get('store_id'), $manufacturer_data);
         }
         return $manufacturer_data;
     }
 }
Exemple #20
0
 public function __construct($registry)
 {
     $this->config = $registry->get('config');
     $this->language = $registry->get('language');
     $this->request = $registry->get('request');
     $this->session = $registry->get('session');
     $currencies = Cache::find('currencies');
     if (!is_array($currencies)) {
         $currencies = Database::fetchAll("SELECT * FROM PREFIX_currency");
         Cache::set('currencies', $currencies);
     }
     foreach ($currencies as $result) {
         $this->currencies[$result['currency_id']] = $result;
     }
     if (isset($this->request->get['currency']) && array_key_exists($this->request->get['currency'], $this->currencies)) {
         $this->set($this->request->get['currency']);
     } elseif (isset($this->session->data['currency']) && array_key_exists($this->session->data['currency'], $this->currencies)) {
         $this->set($this->session->data['currency']);
     } elseif (isset($this->request->cookie['currency']) && array_key_exists($this->request->cookie['currency'], $this->currencies)) {
         $this->set($this->request->cookie['currency']);
     } else {
         $this->set($this->config->get('currency_id'));
     }
 }
<?php

require 'database.php';
Database::setUsername('root');
Database::setPassword('');
Database::setHostname('localhost');
Database::setDatabase('test');
Database::setDBLink('default');
Database::connect();
$rowSingleAccount1 = Database::fetch("SELECT * FROM account WHERE id = :id", [['id', 1, 'int']]);
$rowSingleAccount2 = Database::fetch("SELECT * FROM account WHERE id = :id", [['id', 1, 'int']]);
echo '<pre>';
print_r($rowSingleAccount1);
print_r($rowSingleAccount2);
echo '</pre>';
$rowMultiAccount = Database::fetchAll("SELECT * FROM account");
echo '<pre>';
print_r($rowMultiAccount);
echo '</pre>';
// $fullname = 'Peter';
// Database::exec("INSERT INTO account(fullname)
// VALUES(:fullname)", [
// 	['fullname', $fullname, 'str']
// ]);
echo '<hr />';
echo '<pre>';
print_r(Database::getStatistics());
echo '</pre>';
 /**
  * @brief nav 反回分页数据
  *
  * @return mix
  */
 public function nav()
 {
     $author = $this->authorID;
     $currentPage = $this->currentPage;
     $currentMeta = $this->currentMeta;
     $searchWord = $this->searchWord;
     $maxPerPage = $this->perPage;
     $where = '';
     if ($author) {
         $where .= " AND P.uid={$author}";
     }
     if ($currentMeta) {
         $where .= " AND R.mid={$currentMeta}";
     }
     if ($searchWord) {
         $where .= " AND P.title LIKE '%{$searchWord}%'";
     }
     $totalPost = Database::fetchAll("SELECT P.pid FROM `{$this->prefix}posts` AS P, `{$this->prefix}posts_relation` AS R WHERE P.type=1 AND P.pid=R.pid{$where} GROUP BY P.pid");
     $totalPost = count($totalPost);
     if ($totalPost <= $maxPerPage) {
         return FALSE;
     }
     if ($totalPost % $maxPerPage == 0) {
         $totalPage = floor($totalPost / $maxPerPage);
     } else {
         $totalPage = floor($totalPost / $maxPerPage) + 1;
     }
     return array('totalPage' => $totalPage, 'currentPage' => $currentPage);
 }
Exemple #23
0
<?php

define('ALLOW_ACCESS', true);
// allow access to this page
require_once "includes/header.php";
$db = new Database();
$db->query('SELECT id, name, role_id, email, phone, date_registered, birthday, lang_id, can_login FROM users WHERE role_id != 2 ORDER BY id DESC');
$users = $db->fetchAll();
$db->query('SELECT id, role FROM user_roles ORDER BY id DESC');
$roles = $db->fetchAll();
$db->query('SELECT id, eng_name FROM languages ORDER BY id DESC');
// $db->bind(':product_id', $product_id);
$languages = $db->fetchAll();
?>

<h1 class="page-header">Employees <small><span class="label label-default"><?php 
echo count($users);
?>
</span></small></h1>

<div class="table-responsive">
	<table class="table table-hover table-condensed">
		<thead>
			<tr>
				<th>NAME</th>
				<th>EMAIL</th>
				<th>PHONE</th>
				<th>REG_DATE</th>
				<th>BIRTHDAY</th>
				<th>LANG</th>
				<th>ROLE</th>
Exemple #24
0
    public function ajax()
    {
        // Contains results
        $bind = array();
        $data = array();
        if (isset($this->request->get['keyword'])) {
            // Parse all keywords to lowercase
            $keywords = strtolower($this->request->get['keyword']);
            // Perform search only if we have some keywords
            if (strlen($keywords) >= 2) {
                $cache = 'products.search.' . $keywords;
                $data = Cache::find($cache);
                if (!is_array($data) || !count($data)) {
                    $this->load->model('catalog/product');
                    $data = array();
                    $parts = explode(' ', $keywords);
                    $add = '';
                    // Generating search
                    $partcount = 1;
                    foreach ($parts as $part) {
                        $part = '%' . strtolower($part) . '%';
                        $add .= ' AND (LOWER(pd.name) LIKE :part_' . $partcount;
                        $bind['part_' . $partcount] = $part;
                        $partcount++;
                        $add .= ' OR LOWER(p.model) LIKE :part_' . $partcount;
                        $bind['part_' . $partcount] = $part;
                        $partcount++;
                        $add .= ' OR LOWER(p.model_2) LIKE :part_' . $partcount;
                        $bind['part_' . $partcount] = $part;
                        $partcount++;
                        $add .= ' OR LOWER(pd.tag) LIKE :part_' . $partcount;
                        $bind['part_' . $partcount] = $part;
                        $partcount++;
                        $add .= ' )';
                    }
                    $sql = 'SELECT pd.product_id
                    FROM PREFIX_product_description AS pd
                    LEFT JOIN PREFIX_product AS p
                        ON p.product_id = pd.product_id
                    LEFT JOIN PREFIX_product_to_store AS p2s
                        ON p2s.product_id = pd.product_id

                    WHERE 1 = 1 ' . $add . '
                        AND p.status = 1
                        AND pd.language_id = ' . (int) $this->config->get('language_id') . '
                        AND p2s.store_id =  ' . (int) $this->config->get('store_id') . '
                    ORDER BY LOWER(tag) ASC, LOWER(pd.name) ASC, LOWER(p.model) ASC
                    LIMIT 15';
                    $data = Database::fetchAll($sql, $bind);
                    if ($data && count($data)) {
                        $basehref = 'product/product&keyword=' . $this->request->get['keyword'] . '&product_id=';
                        foreach ($data as $key => $list) {
                            $product = $this->model_catalog_product->getProduct($list['product_id']);
                            if ((!$product['stock_visible'] || $product['stock_visible'] == 2 && !$this->config->get('display_stock_empty')) && $product['quantity'] <= 0) {
                                unset($data[$key]);
                                continue;
                            }
                            $data[$key] = array('name' => htmlspecialchars_decode($product['name'], ENT_QUOTES), 'href' => $this->url->link('product/product', 'path=unknown&product_id=' . $product['product_id'] . '&keyword=' . $this->request->get['keyword']));
                        }
                    } else {
                        exit('meh, failure');
                    }
                    Cache::set($cache, $data);
                }
            }
        }
        $this->response->setOutput(json_encode($data));
    }
Exemple #25
0
<?php

define('ALLOW_ACCESS', true);
// allow access to this page
require_once "includes/header.php";
$db = new Database();
if (isset($_GET["subCat"])) {
    $db->query("SELECT name FROM categories_sub WHERE id = :subCat LIMIT 1");
    $db->bind(':subCat', $_GET["subCat"]);
    $subCat = $db->single();
    $title = $subCat["name"];
    $db->query("SELECT id as ID, user_id as Owner, title as Title, price as Price, currency as Cur, city_name as City, UPPER(country_code) as Country, top_add as 'Top Ad', date_created as 'Created', date_last_edit as 'Last Edited', date_published as 'Published', status as Status FROM products_view WHERE sub_category_id = :subCat ORDER BY id DESC");
    $db->bind(':subCat', $_GET["subCat"]);
    $ads = $db->fetchAll();
} elseif (isset($_GET["owner"])) {
    $db->query("SELECT name FROM users WHERE id = :owner LIMIT 1");
    $db->bind(':owner', $_GET["owner"]);
    $owner = $db->single();
    $title = $owner["name"] . "'s Advertisments";
    $db->query("SELECT id as ID, user_id as Owner, title as Title, price as Price, currency as Cur, city_name as City, UPPER(country_code) as Country, top_add as 'Top Ad', date_created as 'Created', date_last_edit as 'Last Edited', date_published as 'Published', status as Status FROM products_view WHERE user_id = :owner ORDER BY id DESC");
    $db->bind(':owner', $_GET["owner"]);
    $ads = $db->fetchAll();
} else {
    $db->query("SELECT id, name FROM categories_sub WHERE id IN (SELECT DISTINCT sub_cat_id as id FROM products) ORDER BY name ASC");
    $subCats = $db->fetchAll();
}
?>

<?php 
if (isset($_GET["owner"]) or isset($_GET["subCat"])) {
    ?>
// allow access to this page
require_once "includes/header.php";
$db = new Database();
// $mainCatID = false;
if (isset($_GET["cat_id"])) {
    $mainCatID = $_GET["cat_id"];
    $subCategories = $db->getSubCategoriesArray($mainCatID, "CASE WHEN name = 'Other' THEN 2 ELSE 1 END,name ASC");
    require_once "../lib/includes/sanitize-all.php";
}
$mainCategories = $db->getMainCategoriesArray("case when name = 'Deleted' then 3 when name = 'Free Stuff' then 2 else 1 end,name desc");
$subCatID = NULL;
if (isset($_GET["sub_cat_id"])) {
    $subCatID = $_GET["sub_cat_id"];
    $db->query('SELECT id, slug, name, name_nor, type, count FROM attributes WHERE sub_cat_id = :subCatID ORDER BY name ASC');
    $db->bind(':subCatID', $subCatID);
    $attributes = $db->fetchAll();
}
if (isset($_GET["attr_id"])) {
    $attrID = $_GET["attr_id"];
    $db->query('SELECT id, name, name_nor, slug, count FROM specs WHERE id IN ( SELECT DISTINCT spec_id FROM product_specs WHERE attribute_id = :attrID ) ORDER BY name DESC ');
    // $db->query('SELECT id, name, slug, count FROM specs WHERE id IN ( SELECT DISTINCT spec_id FROM product_specs WHERE attribute_id = :attrID AND product_id IN (SELECT id FROM products WHERE sub_cat_id = :subCatID ) ) ORDER BY name DESC ');
    // $db->bind(':subCatID', $subCatID);
    $db->bind(':attrID', $attrID);
    $specifications = $db->fetchAll();
}
$change_attribute = false;
if (isset($_GET["change_attribute"])) {
    $change_attribute = $change_attribute;
}
?>
Exemple #27
0
 static function getNbSets($id_player, $id_set_type)
 {
     $id_player = intval($id_player);
     $id_set_type = intval($id_set_type);
     $results = Database::fetchAll('
   SELECT SUM(nb_sets) AS nb_sets FROM (
     (SELECT COUNT(*) AS nb_sets
     FROM bad_set
     WHERE id_player_1_win = ' . $id_player . ' AND id_set_type = ' . $id_set_type . ')
   UNION ALL
     (SELECT COUNT(*) AS nb_sets
     FROM bad_set
     WHERE id_player_2_win = ' . $id_player . ' AND id_set_type = ' . $id_set_type . ')
   UNION ALL
     (SELECT COUNT(*) AS nb_sets
     FROM bad_set
     WHERE id_player_1_lose = ' . $id_player . ' AND id_set_type = ' . $id_set_type . ')
   UNION ALL
     (SELECT COUNT(*) AS nb_sets
     FROM bad_set
     WHERE id_player_2_lose = ' . $id_player . ' AND id_set_type = ' . $id_set_type . ')
   ) AS t
   ');
     if (count($results) == 0) {
         return 1;
     }
     return $results[0]['nb_sets'] + 1;
 }
Exemple #28
0
 public function rewrite($link)
 {
     $link = str_replace('common/home', '', $link);
     $cache = Cache::find('rewrites', $link);
     if ($cache && !empty($cache)) {
         return $cache;
     }
     $url_info = parse_url(str_replace('&amp;', '&', $link));
     if (!empty($url_info['query'])) {
         $url_info['query'] .= '&';
     } else {
         $url_info['query'] = '';
     }
     if (!empty($url_info['path'])) {
         $url_info['query'] .= 'route=' . ltrim(str_replace('.html', '', $url_info['path']), '/');
     }
     $url = '';
     $data = array();
     if (isset($url_info['query'])) {
         parse_str($url_info['query'], $data);
         foreach ($data as $key => $value) {
             if (isset($data['route'])) {
                 if ($data['route'] == 'product/product' && $key == 'product_id' || ($data['route'] == 'product/manufacturer/info' || $data['route'] == 'product/product') && $key == 'manufacturer_id') {
                     $product = Database::query("SELECT *\n                            FROM PREFIX_url_alias\n                            WHERE `query` = :query\n                            AND (\n                                language_id = :lang\n                                OR language_id = ''\n                            )", array('query' => $key . '=' . $value, 'lang' => $this->config->get('language_id')))->fetch();
                     if (is_array($product)) {
                         $url = rtrim($url, '/') . '/' . strtolower($product['keyword']);
                         $url_info['path'] = '';
                         unset($data[$key]);
                     }
                 } elseif ($key == 'path') {
                     if ($value == 'unknown') {
                         if (isset($data['product_id'])) {
                             $check = Database::query("SELECT category_id FROM PREFIX_product_to_category WHERE product_id = :id ORDER BY category_id DESC LIMIT 1", array('id' => $data['product_id']))->fetch();
                             if (isset($check['category_id'])) {
                                 $path = Database::query("SELECT category_id, path_id, level FROM PREFIX_category_path WHERE path_id = :id", array('id' => $check['category_id']))->fetch();
                                 if ($path['category_id'] == $path['path_id'] && $path['level'] == 0) {
                                     //$desc = Database::query("SELECT name FROM PREFIX_category_description WHERE category_id = :id AND language_id = :lang", array('id' => $check['category_id'], 'lang' => $this->config->get('language_id')))->fetch();
                                     //$url = rtrim($url, '/') . '/' . strtolower($desc['name']) . '/';
                                     $check = Database::query("SELECT * FROM PREFIX_url_alias WHERE `query` = 'category_id=" . (int) $check['category_id'] . "' AND language_id = :lang", array('lang' => $this->config->get('language_id')))->fetch();
                                     if (is_array($check)) {
                                         $url = rtrim($url, '/') . '/' . strtolower($check['keyword']) . '/';
                                         $url_info['path'] = '';
                                     }
                                     $url_info['path'] = '';
                                 } else {
                                     $paths = Database::fetchAll("SELECT path_id FROM PREFIX_category_path WHERE category_id = :id ORDER BY level ASC", array('id' => $path['category_id']));
                                     foreach ($paths as $path) {
                                         $check = Database::query("SELECT * FROM PREFIX_url_alias WHERE `query` = 'category_id=" . (int) $path['path_id'] . "' AND language_id = :lang", array('lang' => $this->config->get('language_id')))->fetch();
                                         if (is_array($check)) {
                                             $url = rtrim($url, '/') . '/' . strtolower($check['keyword']) . '/';
                                             $url_info['path'] = '';
                                         }
                                         //$url = rtrim($url, '/') . '/' . strtolower($desc['name']) . '/';
                                     }
                                     //$url = rtrim($url, '/') . '/-iets-/';
                                 }
                             }
                         }
                         $url_info['path'] = '';
                     } else {
                         $categories = explode('_', $value);
                         foreach ($categories as $category) {
                             $check = Database::query("SELECT * FROM PREFIX_url_alias WHERE `query` = 'category_id=" . (int) $category . "' AND language_id = :lang", array('lang' => $this->config->get('language_id')))->fetch();
                             if (is_array($check)) {
                                 $url = rtrim($url, '/') . '/' . strtolower($check['keyword']) . '/';
                                 $url_info['path'] = '';
                             }
                         }
                     }
                     unset($data[$key]);
                 } else {
                     if ($data['route'] == 'information/information' && $key == 'information_id') {
                         $page = Database::query("SELECT *\n                            FROM PREFIX_url_alias\n                            WHERE `query` = :query\n                            AND (\n                                language_id = :lang\n                                OR language_id = ''\n                            )", array('query' => 'information_id=' . $value, 'lang' => $this->config->get('language_id')))->fetch();
                         if (is_array($page)) {
                             // check for subpage
                             $check = Database::query("\n                                SELECT parent_id\n                                FROM PREFIX_information\n                                WHERE information_id = " . (int) $value)->fetch();
                             if ($check['parent_id']) {
                                 $query2 = Database::query("\n                                    SELECT *\n                                    FROM PREFIX_url_alias\n                                    WHERE `query` = :query\n                                    AND (\n                                        language_id = " . (int) $this->config->get('language_id') . "\n                                        OR language_id = ''\n                                    )", array('query' => $key . '=' . (int) $check['parent_id']))->fetch();
                                 if (count($query2)) {
                                     $url = rtrim($url, '/') . '/' . $query2['keyword'];
                                 }
                             }
                             $url = rtrim($url, '/') . '/' . strtolower($page['keyword']);
                             $url_info['path'] = '';
                             unset($data[$key]);
                         }
                     } else {
                         if ($data['route'] == 'information/blog' && $key == 'blog_id') {
                             $query = Database::query("\n                            SELECT *\n                            FROM PREFIX_url_alias\n                            WHERE `query` = :query\n                            AND (\n                                language_id = " . (int) $this->config->get('language_id') . "\n                                OR language_id = ''\n                            )", array('query' => $key . '=' . $value))->fetch();
                             if (count($query)) {
                                 $url = rtrim($url, '/') . '/blog/' . $query['keyword'];
                                 $url_info['path'] = '';
                                 unset($data[$key]);
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($url) {
         unset($data['route']);
         $query = '';
         if ($data) {
             foreach ($data as $key => $value) {
                 if (is_array($value)) {
                     foreach ($value as $k => $v) {
                         $query .= '&' . $key . '[' . $k . ']=' . $v;
                     }
                 } else {
                     $query .= '&' . $key . '=' . $value;
                 }
             }
             if ($query) {
                 $query = '?' . trim($query, '&');
             }
         }
         $return_url = str_replace('/index.php', '', $url_info['path']);
         $return_url = str_replace($url, '', $return_url) . $url . $query;
         Cache::set('rewrites', $link, $return_url);
         return $return_url;
     } else {
         Cache::set('rewrites', $link, $link);
         return $link;
     }
 }
Exemple #29
0
 public function checkCredentials($email, $password, $javascript, $browser, $ip, $session_id)
 {
     try {
         $minutes = rand(15, 45);
         $time_limit = date("Y-m-d H:i:s", strtotime("-" . $minutes . " min"));
         $db = new Database();
         $db->query('SELECT id FROM log_login WHERE email=:email AND date_time > :time_limit AND status != "success" LIMIT 11');
         $db->bind(':email', $email);
         $db->bind(':time_limit', $time_limit);
         $login_attempts = $db->fetchAll();
         // check if user has less then 10 failed attempts to login
         if (count($login_attempts) >= 5) {
             // !!!!!!!!!!!!! sent email with token to user to get direct acces to account but check also if ip addresses are same and insert new column to tokens db_tabel named ip_address
             throw new Exception(Translate::string("user.blocked"), 1);
             return false;
         }
         // check passwords
         $db->query('SELECT id, password, can_login, role_id FROM users WHERE email=:email LIMIT 1');
         $db->bind(':email', $email);
         $user = $db->single();
         if ($user) {
             if (!$user["can_login"]) {
                 $this->insertLog("user tried to login but was blocked by admin", $email, $javascript, $browser, $ip, $session_id);
                 throw new Exception(Translate::string("user.disabled"), 1);
                 return false;
             }
             $db_pass = $user["password"];
             $password_hashed = hash("sha256", $password);
             if ($db_pass === $password_hashed) {
                 // passwords match and login successful
                 if (!isset($_SESSION)) {
                     session_start();
                 }
                 ini_set('session.cookie_httponly', 'On');
                 ini_set('session.cookie_secure', 'On');
                 ini_set('session.use_cookies', 'On');
                 ini_set('session.use_only_cookies', 'On');
                 ini_set("session.cookie_lifetime", "1800");
                 // half hour
                 $_SESSION['timeout'] = time() + 1800;
                 $_SESSION["email"] = $email;
                 $_SESSION['user_id'] = $user["id"];
                 if ($user["role_id"] == 1 || $user["role_id"] == 3) {
                     $_SESSION['employee'] = $user["id"];
                     $employee = true;
                     if ($user["role_id"] == 1) {
                         $admin = true;
                     }
                 }
                 $admin = false;
                 $employee = false;
                 $this->insertLog("success", $email, $javascript, $browser, $ip, $session_id);
                 return true;
             }
         }
         // login failed
         $this->insertLog("failure", $email, $javascript, $browser, $ip, $session_id);
         throw new Exception(Translate::string("login.wrong_credentials"), 1);
         return false;
     } catch (Exception $e) {
         echo '' . $e->getMessage();
     }
 }
Exemple #30
0
<?php

global $ns;
$databases = Database::fetchAll();
$text = "<h2>" . LAN_ADMIN_DATABASES_INDEX_TITLE . "</h2>";
if (count($databases)) {
    $text .= "\n<table>\n<tr><th>" . LAN_ADMIN_DATABASES_INDEX_THDATABASENAME . "</th><th>" . LAN_ADMIN_COMMON_EDIT . "</th><th>" . LAN_ADMIN_COMMON_DELETE . "</th></tr>";
    foreach ($databases as $database) {
        $text .= "<tr><td>" . $database->getName() . "</td><td><a href=\"" . e_SELF . "?action=edit&id=" . $database->getId() . "\"/>" . LAN_ADMIN_COMMON_EDIT . "</a></td><td><a href=\"" . e_SELF . "?action=delete&id=" . $database->getId() . "\" onclick=\"javascript: return confirm('" . LAN_ADMIN_DATABASES_INDEX_CONFIRMDELETE . "');\">" . LAN_ADMIN_COMMON_DELETE . "</a></td></tr>";
    }
    $text .= "</table>";
} else {
    $text .= "<p>" . LAN_ADMIN_DATABASES_INDEX_NODATABASESREGISTERED . "</p>";
}
$text .= "<input type=\"button\" value=\"" . LAN_ADMIN_DATABASES_INDEX_ADDDATABASEBUTTON . "\" onclick=\"javascript: window.location='" . e_SELF . "?action=add'\"/>";
$ns->tableRender("<a href=\"admin_e107dkp.php\">Main Menu</a> -> <img src=\"images/icons/database-16.png\"/> Database Management", "<div style=\"text-align: center\">{$text}</div>");