/** * Translates the given string. * @param string translation string * @param int count (positive number) * @return string */ public function translate($message, $count = 1) { $message = (string) $message; // if (!empty($message) && isset($this->dictionary[$message])) { // $word = $this->dictionary[$message]; // if ($count === NULL) $count = 1; // // $s = preg_replace('/([a-z]+)/', '$$1', "n=$count;" . $this->meta['Plural-Forms']); // eval($s); // $message = $word->translate($plural); // } if (!isset($this->translate[$message]) or $this->translate[$message] == '') { $message = $message; // echo $message;exit; if (!dibi::fetchSingle("SELECT 1 FROM [lang_translate] WHERE [key] LIKE %s", $message, "AND [id_lang] = %i", $this->id_lang)) { // echo dibi::$sql; Lang::insertTranslateKey($message, $this->id_lang); } $this->translate[$message] = $message; Lang::invalidateCache(); } else { $message = $this->translate[$message]; } // // $args = func_get_args(); // if (count($args) > 1) { // array_shift($args); // $message = vsprintf($message, $args); // } // // return $message; }
function search_list($get) { $out .= '<h1>Search query history</h1>'; if (empty($get['page'])) { $get['page'] = 1; } $lmt = 10; //number of rows per page $ofs = $lmt * ($get['page'] - 1); $count = dibi::fetchSingle('SELECT count(*) FROM search_history'); $pagecount = ceil($count / $lmt); $searches = dibi::query('SELECT * FROM search_history WHERE f_deleted=0 ORDER BY time DESC %lmt %ofs', $lmt, $ofs); for ($i = 1; $i <= $pagecount; $i++) { $out .= '<a href="index.php?action=searchlist&page=' . $i . '">' . $i . '</a> '; } $out .= '<table>'; foreach ($searches as $search) { $out .= '<tr>'; $out .= '<td>' . $search['time'] . '</td>'; $out .= '<td>' . $search['ip'] . '</td>'; $out .= '<td>' . $search['query'] . '</td>'; $out .= '</tr>'; } $out .= '</table>'; return $out; }
/** * Maps HTTP request to a PresenterRequest object. * @param Nette\Web\IHttpRequest * @return PresenterRequest|NULL */ public function match(IHttpRequest $context) { if (!preg_match('#^/([a-z0-9]{1,3})/(.*?)/?$#', $context->getUri()->path, $matches)) { return NULL; } $lang = $matches[1]; $categories = $matches[2]; $pom = explode("/", $categories); $last = end($pom); if (dibi::fetchSingle("\n\t\t\tSELECT\n\t\t\t COUNT(*)\n\t\t\tFROM\n\t\t\t category\n\t\t\t JOIN category_lang USING(id_category)\n\t\t\t JOIN [lang] USING(id_lang)\n\t\t\tWHERE iso=%s", $lang, "AND link_rewrite = %s", $last)) { $presenter = 'Front:Eshop'; } elseif (dibi::fetchSingle("SELECT COUNT(*) FROM menu_item WHERE lang = %s", $lang, "AND url_identifier=%s", $last)) { $presenter = 'Front:List'; } else { return NULL; } // alternativa: použít jednu tabulku s páry URL -> jméno Presenteru // výhoda: jeden lookup místo (až) tří, neměřitelně vyšší rychlost ;) // nevýhoda: nutnost ji udržovat :-( // alternativa č.2: místo COUNT(*) načíst z DB celý záznam a předat v parametru presenteru // výhoda: stejně jej bude potřebovat // nevýhoda: nadstandardní závislost mezi routerem a presenterem $params = $context->getQuery(); // $params['link_rewrite'] = $last; $params['lang'] = $lang; return new NPresenterRequest($presenter, $context->getMethod(), $params, $context->getPost(), $context->getFiles(), array('secured' => $context->isSecured())); }
function saveArticle($values, $id_node) { $tmp = dibi::fetch("SELECT * FROM article WHERE id_node=%i", $id_node); unset($values['id_node']); //odstranenie premennych ktore niesu v databaze $values = Tools::getValuesForTable('article', $values); $name = NStrings::webalize($values['url_identifier']); $newname = ""; $i = 0; while ($i < 50) { if ($i == 0) { $newname = $name; } else { $newname = NStrings::webalize($name . $i); } $s = dibi::fetchSingle("SELECT COUNT(id_node) FROM article WHERE url_identifier=%s", $newname, " AND id_node!=%i", $id_node); if ($s == 0) { break; } else { $i++; } } $values['url_identifier'] = $newname; dibi::query("UPDATE article SET ", $values, " WHERE id_node=%i", $id_node); NEnvironment::getService('Article')->invalidateCache(); }
public static function addAnswer($values) { $id_poll = $values['id_poll']; $sequence = dibi::fetchSingle("SELECT MAX(sequence)+1 FROM poll_answer WHERE id_poll=%i", $id_poll); $values['sequence'] = $sequence; dibi::query("INSERT INTO poll_answer ", $values); }
function saveProduct($values, $id_node) { $collums = Tools::getCollum('module_product'); foreach ($values as $k => $v) { if (!in_array($k, $collums)) { unset($values[$k]); } } $newname = ""; $name = $values['title']; $i = 0; while ($i < 50) { if ($i == 0) { $newname = $name; } else { $newname = NStrings::webalize($name . $i); } $s = dibi::fetchSingle("SELECT COUNT(id_node) FROM [module_product] WHERE url_identifier=%s", $newname, " AND id_node!=%i", $id_node); if ($s == 0) { break; } else { $i++; } } $values['url_identifier'] = $newname; dibi::query("UPDATE [module_product] SET ", $values, " WHERE id_node=%i", $id_node); Log::addLog($this, "Uprava produktu", "Menil:" . NEnvironment::getSession('Authentication')->login_form, $values['title'], $id_node); }
/** * Maps HTTP request to a PresenterRequest object. * @param Nette\Web\IHttpRequest * @return PresenterRequest|NULL */ public function match(IHttpRequest $context) { \Nette\Diagnostics\FireLogger::log('-------------'); \Nette\Diagnostics\FireLogger::log($context); return NULL; if (!preg_match('#^/([a-zA-Z0-9-]+)/?$#', $context->getUri()->path, $matches)) { return NULL; } $id = $matches[1]; if (dibi::fetchSingle("SELECT COUNT(*) FROM tabulka_produktu WHERE nameid=%s", $id)) { $presenter = 'Front:Product'; } elseif (dibi::fetchSingle("SELECT COUNT(*) FROM tabulka_kategorie WHERE nameid=%s", $id)) { $presenter = 'Front:Category'; } elseif (dibi::fetchSingle("SELECT COUNT(*) FROM tabulka_s_clanky WHERE nameid=%s", $id)) { $presenter = 'Front:Article'; } else { return NULL; } // alternativa: použít jednu tabulku s páry URL -> jméno Presenteru // výhoda: jeden lookup místo (až) tří, neměřitelně vyšší rychlost ;) // nevýhoda: nutnost ji udržovat :-( // alternativa č.2: místo COUNT(*) načíst z DB celý záznam a předat v parametru presenteru // výhoda: stejně jej bude potřebovat // nevýhoda: nadstandardní závislost mezi routerem a presenterem $params = $context->getQuery(); $params['id'] = $id; return new PresenterRequest($presenter, $context->getMethod(), $params, $context->getPost(), $context->getFiles(), array('secured' => $context->isSecured())); }
function actionGenerateExcel($id_order) { $order = OrderModel::get($id_order); //print_r($order);exit; $order['country_name'] = dibi::fetchSingle("SELECT country_name FROM [gui_user_country] WHERE iso = %s", $order['iso']); $date = new DateTime($order['add_date']); $order['create_date'] = $date->format('d/m/Y'); require_once LIBS_DIR . '/PHPExcel/PHPExcel.php'; //cesta k sablone $dir = WWW_DIR . "/uploaded/order_excel_template/invoice_template.xlsx"; $objPHPExcel = PHPExcel_IOFactory::load($dir); // Set active sheet $objPHPExcel->setActiveSheetIndex(0); // Assign data $invoice_number = str_pad($order['id_order'], 5, "0", STR_PAD_LEFT); // var_dump($invoice_number);exit; $objPHPExcel->getActiveSheet()->setCellValue('INVOICE_NUMBER', $invoice_number); $objPHPExcel->getActiveSheet()->setCellValue('VARIABLE_SYMBOL', $invoice_number); $objPHPExcel->getActiveSheet()->setCellValue('B_NAME', $order['name'] . ' ' . $order['surname'] . ' ' . $order['company_name']); $objPHPExcel->getActiveSheet()->setCellValue('B_STREET', $order['address']); $objPHPExcel->getActiveSheet()->setCellValue('B_CITY', $order['city']); $objPHPExcel->getActiveSheet()->setCellValue('B_COUNTRY', $order['country_name']); if ($order['ico'] != '') { $objPHPExcel->getActiveSheet()->setCellValue('B_ICO', $order['ico']); $objPHPExcel->getActiveSheet()->setCellValue('B_TITLE_ICO', 'IČO:'); } if ($order['dic'] != '') { $objPHPExcel->getActiveSheet()->setCellValue('B_IC_DPH', $order['dic']); $objPHPExcel->getActiveSheet()->setCellValue('B_TITLE_IC_DPH', 'IČO:'); } $objPHPExcel->getActiveSheet()->setCellValue('B_IC_DPH', $order['dic']); $objPHPExcel->getActiveSheet()->setCellValue('CREATE_DATE', $order['create_date']); $objPHPExcel->getActiveSheet()->setCellValue('PAYMENTS_METHOD', 'PP'); $objPHPExcel->getActiveSheet()->setCellValue('DPH_TITLE', 'DPH ' . NEnvironment::getVariable('vat') . "%"); $objPHPExcel->getActiveSheet()->setCellValue('DPH', NEnvironment::getVariable('vat')); // Add data $collum = 18; $vat_coef = 1 + NEnvironment::getVariable('vat') / 100; foreach ($order['products'] as $p) { $objPHPExcel->getActiveSheet()->setCellValue('B' . $collum, $p['ean13']); $objPHPExcel->getActiveSheet()->setCellValue('C' . $collum, $p['name']); $objPHPExcel->getActiveSheet()->setCellValue('D' . $collum, $p['count']); //mnozstvo $objPHPExcel->getActiveSheet()->setCellValue('E' . $collum, "ks"); //jed $objPHPExcel->getActiveSheet()->setCellValue('F' . $collum, $p['price'] / $vat_coef); //bez dph $objPHPExcel->getActiveSheet()->setCellValue('G' . $collum, $p['count'] * $p['price'] / $vat_coef); ++$collum; } $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); // Redirect output to a client’s web browser (Excel2007) header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="faktura_' . $invoice_number . '.xlsx"'); header('Cache-Control: max-age=0'); $objWriter->save('php://output'); exit; }
function beforeRender() { parent::beforeRender(); $this->template->id_category = $this->id; $this->template->category_parents = CategoryModel::getParents($this->template->id_category, $this->id_lang); //ak je iba jeden parent zobraz kategorie, inak zobraz produkty if (count($this->template->category_parents) == 1) { $id_parent = current($this->template->category_parents); $category_list = CategoryModel::getFluent('id_category')->where('id_parent = %i', $id_parent)->fetchAll(); $this->template->categories = array(); foreach ($category_list as $l) { $_tmp = CategoryModel::get($l->id_category, $this->id_lang); $_tmp['product_count'] = dibi::fetchSingle("SELECT COUNT(id_product) FROM [product] JOIN [category_product] USING(id_product) WHERE id_category = %i", $l->id_category); $this->template->categories[] = $_tmp; } $this->template->product_count = dibi::fetchSingle("SELECT COUNT(id_product) FROM [product] JOIN [category_product] USING(id_product) WHERE id_category = %i", $this->id); } else { $list = dibi::select('id_product')->from('product')->join('category_product')->using('(id_product)')->join('product_param')->using('(id_product)')->where('id_category = ', $this->id, 'AND product.active = 1'); /* * Filter */ $orderSession = $this['quickFilter']->getSession(); // dde($orderSession['order']); // $orderSession['order'] = 'price'; if ($orderSession['order']) { $list->orderBy($orderSession['order']); } else { $order_array = $this['quickFilter']->getOrderFilterArray(); $list->orderBy(key($order_array)); } $list->groupBy('id_product'); // dump($order); // print_r($list); $count_list = clone $list; // $count = $count_list->removeClause('select')->select('COUNT(id_product)')->fetchSingle(); $count = count($count_list); $vp = new VisualPaginator($this, 'paginator'); $paginator = $vp->getPaginator(); $numOnPageSession = $this['quickFilter']->getSession(); if ($numOnPageSession['num']) { $paginator->itemsPerPage = $numOnPageSession['num']; } else { $num_on_page_array = $this['quickFilter']->getNumOnPageFilterArray(); $paginator->itemsPerPage = key($num_on_page_array); } $paginator->itemCount = (int) $count; $this->template->product_count = $count; $this->template->products = $list->limit($paginator->offset . ',' . $paginator->itemsPerPage)->fetchAll(); //dump($this->template->products); $this->template->paginator = $paginator; foreach ($this->template->products as $k => $p) { $this->template->products[$k] = ProductModel::getProductWithParams($p['id_product'], $this->id_lang, $this->user); } // }; } // print_r($this->template->products);exit; }
function handleSaveSetting(NForm $form) { $values = $form->getValues(); //ak je to "obchodne podmienky" zisti id_page a zapis do konfigu $values['CONDITIONS_CMS_PAGE_ID'] = dibi::fetchSingle("SELECT id_menu_item FROM [menu_item] JOIN [node] \n\t\t\t\tUSING(id_menu_item) WHERE node.id_node = %i", $values['CONDITIONS_CMS_ID']); $setting = $this->getService('Setting'); foreach ($values as $name => $value) { $setting->insert_update($name, array('name' => $name, 'value' => $value)); } $this->flashMessage('Nastavenia boli upravené'); $this->redirect('this'); }
public function idToSlug($id) { $key = 'idToSlug' . $id; if (!isset($this->cache[$key])) { $name = dibi::fetchSingle("SELECT url_identifier FROM [menu_item] WHERE id_menu_item = %i", $id); if (!$name) { $name = NULL; } $this->cache[$key] = $name; } return $this->cache[$key]; }
public function idToSlug($id) { $key = 'idToSlug(' . $id . ')'; // echo $key; // return $name = dibi::fetchSingle("SELECT url_identifier FROM [article] WHERE id_node = %i",$id); $slug = $this->loadCache($key); if ($slug) { return $slug; } else { $name = dibi::fetchSingle("SELECT url_identifier FROM [article] WHERE id_node = %i", $id); if (!$name) { $name = NULL; } } return $this->saveCache($key, $name); }
public function match(IHttpRequest $httpRequest) { // print_r($httpRequest); $request = parent::match($httpRequest); if ($request === NULL) { return NULL; } $params = $request->getParams(); //print_r($params); if (dibi::fetchSingle('SELECT COUNT(*) FROM %n', $this->table, ' WHERE %n = %s', $this->column, $params['categories']) == 0) { return NULL; } return $request; }
/** * Saves extracted data into gettext file * @param string $outputFile * @param array $data * @return GettextExtractor */ public function save() { $e = new MyExtractor(); $data = $e->getData(); $id_lang = dibi::fetchSingle("SELECT id_lang FROM [lang] WHERE iso = %s", $this->lang); if (!$id_lang) { throw new Exception('ISO lang neexistuje'); } foreach ($data as $k => $d) { $arr = array('id_lang' => $id_lang, 'key' => $k, 'files' => implode(", ", $d)); try { dibi::query("INSERT INTO lang_translate", $arr); } catch (Exception $e) { echo $e->getMessage(); } } self::invalidateCache(); return $this; }
function action() { parent::action(); if (isset($_GET['ajax_save_promo']) and $_GET['ajax_save_promo'] == 1) { $arr = Tools::getValuesForTable('promo_text', $_POST); //zisti ci existuje $id_file = dibi::fetchSingle("SELECT id_file FROM [promo_text] WHERE id_file = %i", $_POST['id_file']); // // $arr = array( // 'title'=>$_POST['title'], // 'alt'=>$_POST['alt'], // 'link'=>$_POST['link'], // 'link_name'=>$_POST['link_name'], // ); if ($id_file) { dibi::query("UPDATE promo_text SET ", $arr, "WHERE id_file = %i", $id_file); } else { $arr['id_file'] = $_POST['id_file']; dibi::query("INSERT INTO promo_text ", $arr); } exit; } }
static function save($key, $values) { $langs = self::getAll(); foreach ($langs as $l) { if (isset($values[$l['iso']]) and $values[$l['iso']] != '') { //ak zaznam neexistuje vytvor ho if (!dibi::fetchSingle("SELECT 1 FROM [lang_translate] WHERE id_lang = %i", $l['id_lang'], "AND [key] = %s", $key)) { self::insertTranslateKey($key, $l['id_lang']); } dibi::query("\n\t\t\t\t\tUPDATE\n\t\t\t\t\t\t[lang_translate]\n\t\t\t\t\tSET ", array('translate' => $values[$l['iso']]), "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\tid_lang = %i", $l['id_lang'], "\n\t\t\t\t\t\tAND [key] = %s", $key); } } return true; }
function setParameters($name, $source, $type, $handlers, $period, $filter, $active, $overwrite = true) { if (!$name) { return array('status' => 'fail', 'error' => 'ID is missing.'); } $exists = false; $result = true; $interval = $this->parseDuration($period); $arr = array('name' => $name, 'source' => $source, 'type' => $type, 'handlers' => $handlers, 'h_interval' => $interval, 'period' => $period, 'filter' => $filter, 'active' => $active); //mazani if ($interval < 0) { $sql = "DELETE FROM harvest WHERE name=%s"; $arr['action'] = 'delete'; try { $rs = dibi::query($sql, $name); $arr['status'] = 'OK'; return $arr; } catch (DibiException $e) { $arr['status'] = 'fail'; $arr['error'] = $e; return $arr; } } // vložení $sql = "SELECT COUNT(*) FROM harvest WHERE name=%s"; $rs = dibi::fetchSingle($sql, $name); if ($rs > 0) { if (!$overwrite) { $arr['status'] = 'fail'; $arr['error'] = 'duplicate key'; return $arr; } $exists = true; } try { if ($exists) { dibi::query('UPDATE harvest SET ', $arr, 'WHERE name=%s', $name); //$sql = "UPDATE harvest SET name='$name', source='$source', $type='$type', interval='$interval'"; } else { $arr['create_user'] = MICKA_USER; dibi::query('INSERT INTO harvest', $arr); } $arr['status'] = 'OK'; } catch (DibiException $e) { $this->log(); $this->log($e); $arr['status'] = 'fail'; $arr['error'] = $e; } return $arr; }
function __construct() { $this->id_type_modul = dibi::fetchSingle("SELECT id_type_modul FROM type_modul WHERE dir='gmap'"); }
public function actionUsers($id) { $nodes = new RolesModel(); $this->template->nodes = $nodes; $this->template->parents = $nodes->getChildNodes(NULL); $this->template->role = dibi::fetchSingle('SELECT name FROM [' . TABLE_ROLES . '] WHERE id=%i;', $id); $sql = dibi::query('SELECT u.id, u.username AS name FROM [' . TABLE_USERS . '] AS u LEFT JOIN [' . TABLE_USERS_ROLES . '] AS r ON u.id=r.user_id WHERE r.role_id=%i ORDER BY u.username;', $id); $users = $sql->fetchAll(); $this->template->users = $users; }
function nodeAction() { $node = NodeModel::init(); //-------------------------------// //--------AJAX REQUEST-----------// //------------------------------// if (@$_GET['ajax_change_modul_position']) { if (is_numeric(@$_GET['id_node_ajax']) and is_numeric($_GET['position'])) { dibi::query("UPDATE node SET position=%i", $_GET['position'], " WHERE id_node=%i", $_GET['id_node_ajax']); $node->invalidateCache(); } exit; } if (@$_GET['ajax_change_modul_visible']) { if (is_numeric(@$_GET['id_node_ajax']) and is_numeric($_GET['modul_visible'])) { dibi::query("UPDATE node SET visible=%s", $_GET['modul_visible'], " WHERE id_node=%i", $_GET['id_node_ajax']); } $node->invalidateCache(); // echo dibi::$sql; exit; } //------SITE MAP pre premiestnenie modulu if (isset($_GET['ajax_show_site_map_for_modul'])) { $m = new MenuItem(); $m->doTreeSelectMoveModul(0, 0, $_GET['id_menu_item'], $_GET['id_type_modul']); echo '<form action="" method="post"> <select name="id_menu_item_for_change">'; echo $m->doTreeSelectMoveModulText; echo '<input type="hidden" name="id_type_modul" value="' . htmlspecialchars($_GET['id_type_modul']) . '" /> <input type="hidden" name="id_node" value="' . htmlspecialchars($_GET['id_node']) . '" /> <input type="submit" name="changeModulParent" value="Ulož" /> </form>'; exit; } if (isset($_POST['changeModulParent'])) { $this->changeModulParent(); $node->invalidateCache(); header("Location: ?id_menu_item=" . $_POST['id_menu_item_for_change'] . "&showModulsOnPage=1"); exit; } if (isset($_GET['id_menu_item']) and isset($_GET['id_type_modul']) and isset($_GET['id_modul'])) { if (!dibi::fetchSingle("SELECT COUNT(*) FROM node WHERE id_menu_item=%i", $_GET['id_menu_item'], " AND id_type_modul=%i", $_GET['id_type_modul'], " AND id_node=%i", $_GET['id_modul'])) { header("Location:admin.php"); exit; } } if (isset($_GET['addnode']) and isset($_GET['id_type_modul']) or isset($_POST['addModulToMenu'])) { if (isset($_POST['addModulToMenu'])) { $id_type_modul = $_POST['id_type_modul']; } else { $id_type_modul = $_GET['id_type_modul']; } $sequence = dibi::fetchSingle("SELECT MAX(sequence) FROM node WHERE id_menu_item=%i", $_GET['id_menu_item']) + 1; $session = NEnvironment::getSession('Authentication'); $config = NEnvironment::getConfig(); $arr = array('id_user' => NEnvironment::getUser()->getIdentity()->id, 'id_menu_item' => $_GET['id_menu_item'], 'sequence' => $sequence, 'id_type_modul' => $id_type_modul, 'visible' => $config['NODE_VISIBLE']); dibi::query("INSERT INTO node ", $arr); $this->addModul(dibi::insertId(), $id_type_modul); $node->invalidateCache(); } //zmenenie poradia if (isset($_GET['modul_id_up']) or isset($_GET['modul_id_down'])) { $this->changeOrderNode(); $node->invalidateCache(); header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item'] . "&showModulsOnPage=1"); exit; } //ak je iba jeden modul, hned sa zobrazi ale iba ak nieje setnuta section a showModulsOnPage if (isset($_GET['id_menu_item']) and !isset($_GET['id_type_modul']) and !isset($_GET['section']) and !isset($_GET['showModulsOnPage']) and !isset($_GET['changeMenuItem'])) { $l = dibi::fetch("SELECT *, COUNT(*) as node_count FROM node WHERE id_menu_item=%i", $_GET['id_menu_item'], " ORDER BY sequence"); if ($l['node_count'] == 1) { header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item'] . "&id_type_modul=" . $l['id_type_modul'] . "&id_modul=" . $l['id_node']); exit; } } //pridanie do premenej activeModul instanciu objektu if (isset($_GET['id_type_modul']) and isset($_GET['id_modul'])) { $this->activeModul = $this->nodeFactory($_GET['id_type_modul']); $this->activeModul->action(); } if (isset($_GET['id_modul_del']) and is_numeric($_GET['id_modul_del'])) { $this->deleteNode(NULL, $_GET['id_modul_del']); $node->invalidateCache(); header("Location: admin.php?id_menu_item=" . $_GET['id_menu_item']); exit; } }
function add($values) { //ak produkt nie je, pridaj if ($values['Name_sk'] == '') { return false; } //ak je pridany aby ho system nemusel prepisovat $is_added = false; if (!isset($this->all_product_param_db[$values['Code']]) and $values['Name_sk'] != '') { /* [Code] => 21420011 [Name_sk] => Ladies polo shirt, S, white/ blue (01) [Name_cz] => Dámska poloko?e?a, S, white/ blue (01) [Name_en] => Ladies polo shirt, S, white/ blue (01) [Name_de] => [Name_hu] => [Package] => 1 [Price_CZK] => 124.000000 [Price_EUR] => 4.770000 [Price_SK] => 143.700000 [Image] => p990.02.jpg [Mark] => Best in Town [Stock] => 2 [Category1_sk] => Textil [Category1_cz] => Textil [Category1_en] => Textile [Category1_de] => [Category1_hu] => [Category2_sk] => Výpredaj [Category2_cz] => Výprodej [Category2_en] => Discount [Category2_de] => [Category2_hu] => [Category3_sk] => [Category3_cz] => [Category3_en] => [Category3_de] => [Category3_hu] => */ //zisti ci je v product_temp_parse aby sme zistili group $product_temp_parse = dibi::fetch("SELECT * FROM product_temp_parse WHERE code = %s", $values['Code']); if (!$product_temp_parse) { throw new Exception('Polozka nie je v product_temp_parse. Nemame ako zistit skupinu resp. group_code'); } //zisti ci group_code je v nasej db ak nie je pridaj if (!isset($this->all_product_db[$product_temp_parse['group_code']])) { $arr = array('mark' => $values['Mark'], 'group_code' => $product_temp_parse['group_code']); $id_product = ProductModel::add($arr); if (!$id_product) { throw new Exception('Nastala chyba. Nexistuje id_product'); } $arr_lang = array('id_product' => $id_product, 'id_lang' => 1, 'name' => $product_temp_parse['groupnameSK'], 'link_rewrite' => NStrings::webalize($product_temp_parse['groupnameSK'])); ProductModel::addProductLang($arr_lang); $this->all_product_db[$product_temp_parse['group_code']] = $id_product; $this->all_product_param_db[$values['Code']] = $id_product; } else { $id_product = $this->all_product_db[$product_temp_parse['group_code']]; $this->all_product_param_db[$values['Code']] = $id_product; } //pridanie parametru produktu $arr = array('id_product' => $id_product, 'code' => trim($values['Code']), 'capacity' => $values['Package'], 'color' => trim($product_temp_parse['color']), 'size' => trim($product_temp_parse['dimension'] != '' ? $product_temp_parse['dimension'] : $product_temp_parse['size']), 'material' => trim($product_temp_parse['material']), 'price' => $values['Price_EUR'], 'stock' => $values['Stock'], 'image' => $values['Image']); ProductModel::addProductParamValue($arr); $is_added = true; } $id_product = $this->all_product_param_db[$values['Code']]; /* * Uprava produktu */ if (!$is_added and $values['Name_sk'] != '') { //upravi len co je v xml - nie co je parsovane z CSV $arr = array('price' => $values['Price_EUR'], 'stock' => $values['Stock']); $id_product_param = $this->all_product_param_db[$values['Code']]; ProductModel::setProductParamValue($arr, $id_product_param, 1); } $id_categories = array(); //echo $values['Category1_sk']; if ($id_category = array_search($values['Category1_sk'], $this->category_1)) { $id_categories[] = $id_category; } if ($id_category = array_search($values['Category2_sk'], $this->category_2)) { $id_categories[] = $id_category; } if ($id_category = array_search($values['Category3_sk'], $this->category_3)) { $id_categories[] = $id_category; } ProductModel::removeAllCategory($id_product); // print_r($id_categories); ProductModel::addProductToCategory($id_categories, $id_product); $pom = 0; //ak nie je kategoria pridaj if (!in_array($values['Category1_sk'], $this->category_1) and $values['Category1_sk'] != '') { $id_category = CategoryModel::add(array('id_parent' => NULL, 'active' => 1)); $arr = array('id_category' => $id_category, 'id_lang' => 1, 'name' => $values['Category1_sk']); CategoryModel::addCategoryLang($arr); $this->category_1[] = $values['Category1_sk']; ++$pom; } if (!in_array($values['Category2_sk'], $this->category_2) and $values['Category2_sk'] != '') { $cat1 = dibi::fetchSingle("SELECT category.id_category FROM [category] JOIN [category_lang] USING(id_category) WHERE name = %s", $values['Category1_sk'], " AND id_lang = 1 AND id_parent IS NULL"); if (!$cat1) { throw new Exception('Rodic pre kategoriu neexistuje : ' . $values['Category1_sk']); } $id_category = CategoryModel::add(array('id_parent' => $cat1, 'active' => 1)); $arr = array('id_category' => $id_category, 'id_lang' => 1, 'name' => $values['Category2_sk']); // print_r(array('id_parent'=>$cat1,'active'=>1,'name'=>$values['Category2_sk'] )); CategoryModel::addCategoryLang($arr); $this->category_2[] = $values['Category2_sk']; ++$pom; } // if (!in_array($values['Category3_sk'], $this->category_3) and $values['Category3_sk'] != '') { $cat2 = dibi::fetchSingle("SELECT category.id_category FROM [category] JOIN [category_lang] USING(id_category) WHERE name = %s", $values['Category2_sk'], " AND id_lang = 1 AND id_parent IS NOT NULL"); if (!$cat2) { throw new Exception('Rodic pre kategoriu neexistuje : ' . $values['Category2_sk']); } if ($values['Category3_sk'] == 'Pullovers') { var_dump($cat2); } $id_category = CategoryModel::add(array('id_parent' => $cat2, 'active' => 1)); if ($values['Category3_sk'] == 'Pullovers') { var_dump($id_category); } $arr = array('id_category' => $id_category, 'id_lang' => 1, 'name' => $values['Category3_sk']); if ($values['Category3_sk'] == 'Pullovers') { var_dump($arr); } CategoryModel::addCategoryLang($arr); $this->category_3[] = $values['Category3_sk']; ++$pom; } if ($pom > 0) { // echo "cat1: ". $values['Category1_sk']." - cat2: ". $values['Category2_sk']." - cat3:". $values['Category3_sk']." // "; } }
public static function idToSlug($id) { $cache = self::getCache(); $key = 'idToSlug(' . $id . ')'; if (isset($cache[$key])) { return $cache[$key]; } else { $name = dibi::fetchSingle("SELECT link_rewrite FROM [category_lang] WHERE id_category = %i", $id); if (!$name) { $name = null; } // $cache->save( $key, $name); self::setCache($key, $name); return $name; } }
/* TABLE products product_id | title -----------+---------- 1 | Chair 2 | Table 3 | Computer */ // fetch a single row echo "<h2>fetch()</h2>\n"; $row = dibi::fetch('SELECT title FROM products'); dump($row); // Chair // fetch a single value echo "<h2>fetchSingle()</h2>\n"; $value = dibi::fetchSingle('SELECT title FROM products'); dump($value); // Chair // fetch complete result set echo "<h2>fetchAll()</h2>\n"; $all = dibi::fetchAll('SELECT * FROM products'); dump($all); // fetch complete result set like association array echo "<h2>fetchAssoc('title')</h2>\n"; $res = dibi::query('SELECT * FROM products'); $assoc = $res->fetchAssoc('title'); // key dump($assoc); // fetch complete result set like pairs key => value echo "<h2>fetchPairs('product_id', 'title')</h2>\n"; $pairs = $res->fetchPairs('product_id', 'title');
public function render($id_product = NULL, $show = true, $sale = false) { $params = NEnvironment::getApplication()->getPresenter()->getParam(); //NDebug::bardump($params); if (isset($params['material'])) { $this->material = $params['material']; } if (isset($params['size'])) { $this->size = $params['size']; } if (isset($params['color'])) { $this->color = $params['color']; } if (isset($params['id_product'])) { $this->id_product = $params['id_product']; } if (isset($params['count'])) { $this->count = (int) $params['count']; } if ($id_product != NULL) { $this->id_product = $id_product; } $id_lang = $this->getPresenter()->id_lang; $template = $this->template; $template->setFile(dirname(__FILE__) . '/Product.phtml'); $template->l = ProductModel::get($this->id_product, $id_lang); $lowest_price_product_param = dibi::fetchSingle("SELECT id_product_param FROM [product_param] WHERE id_product = %i", $this->id_product, "ORDER BY price LIMIT 1"); $template->l['price_array'] = ProductModel::getPrice($lowest_price_product_param); if ($show) { $template->images = ProductModel::getImages($this->id_product); $template->files = ProductModel::getFiles($this->id_product); $template->product_alternative = ProductModel::getProductAlternative($this->id_product); // prepocitavanie $this->template->id_product = $this->id_product; $product_params = ProductModel::getProductParamFluent($this->id_product)->orderBy('price')->fetchAll(); // print_r($this->template->product_params);exit; //zisti ktore sltpce su vyplnene $this->template->param = array(); //zisti pre moznosti pre material ak neni zisti pre velkost ak neni zisti pre farbu foreach ($product_params as $k => $p) { if ($p['material'] != '') { $this->template->param['material'][$p['material']] = $p['material']; } if ($p['size'] != '') { $this->template->param['size'][$p['size']] = $p['size']; } if ($p['color'] != '') { $this->template->param['color'][$p['color']] = $p['color']; } } if (isset($this->template->param['material'])) { reset($this->template->param['material']); if ($this->material == NULL or !isset($this->template->param['material'][$this->material])) { $this->material = key($this->template->param['material']); } } if (isset($this->template->param['size'])) { reset($this->template->param['size']); $this->template->param['size'] = dibi::query("SELECT size FROM [product_param] WHERE %if", $this->material != NULL, "material = %s", $this->material, "AND %end id_product = %i", $this->id_product, "AND size != ''")->fetchPairs('size', 'size'); if ($this->size == NULL or !isset($this->template->param['size'][$this->size])) { $this->size = key($this->template->param['size']); } usort($this->template->param['size'], 'EshopProductControl::cmp'); // print_r($this->template->param['size']); } if (isset($this->template->param['color'])) { reset($this->template->param['color']); $this->template->param['color'] = dibi::query("SELECT color FROM [product_param] WHERE %if", $this->material != NULL, "material = %s", $this->material, "AND %end %if", $this->size != NULL, "size = %s", $this->size, "AND %end id_product = %i", $this->id_product, "AND color!=''")->fetchPairs('color', 'color'); if ($this->color == NULL or !isset($this->template->param['color'][$this->color])) { $this->color = key($this->template->param['color']); } } // zisti id_product_param $product = dibi::fetch("\n\t\t\t\tSELECT\n\t\t\t\t\t*, COUNT(*) as c\n\t\t\t\tFROM\n\t\t\t\t\t[product_param]\n\t\t\t\tWHERE 1=1 %if", $this->material != NULL, "AND material = %s", $this->material, "%end\n\t\t\t\t\t%if", $this->size != NULL, "AND size = %s", $this->size, "%end\n\t\t\t\t\t%if", $this->color != NULL, "AND color = %s", $this->color, "%end\n\t\t\t\t\tAND id_product = %i", $this->id_product, "LIMIT 1"); $this->template->id_product_param = $product['id_product_param']; $this->template->price = ProductModel::getPrice($product['id_product_param']); $this->template->sql = dibi::$sql; $this->template->pictograms = PictogramModel::get($this->id_product); //FEATURES - zobrazenie pre sekciu MATRACE link na potahove latky $categories = ProductModel::getProductCategories($this->id_product); $pom = array(); foreach ($categories as $c) { $pom[] = $c['id_category']; } if (in_array('2', $pom) or in_array('3', $pom)) { $this->template->show_link_potahove_latky = 1; } //FEATURES - zobrazenie pre sekciu POSTELE $pom = array(); foreach ($categories as $c) { $pom[] = $c['id_category']; } if (in_array('45', $pom)) { $this->template->show_different_name_for_postele = 1; } } else { $template->setFile(dirname(__FILE__) . '/ProductAnnotation.phtml'); $template->image = self::getImage($this->id_product); // $categories = $this->getPresenter()->getParam('categories'); // // if($categories=='' OR $categories=='novinky'){ // // $pom = ProductModel::getProductCategories($id_product); // $pom = current($pom); // $categories = CategoryModel::getUrl($pom['id_category']); // } $pom = ProductModel::getProductCategories($id_product); // print_r($pom); $pom = end($pom); $categories = CategoryModel::getUrl($pom['id_category']); $template->l['url'] = $this->getPresenter()->link('Eshop:current', array('categories' => $categories, 'url_identifier' => $template->l['link_rewrite'])); } // var_dump(); if ($sale) { $params = dibi::fetch("SELECT * FROM [product_param] WHERE id_product = %i", $this->id_product); $template->l['size'] = $params->size; $template->l['material'] = $params->material; $template->l['color'] = $params->color; $template->l['stock'] = $params->stock; } $template->render(); }
function save(NFORM $form) { $values = $form->getValues(); $langs = Setting::getLangs(); $id_product = $values['id_product']; $table_product_cols = Tools::getCollum('product'); $table_product_lang_cols = Tools::getCollum('product_lang'); //ulozenie jazuka foreach ($langs as $l) { $save_val = array(); foreach ($table_product_lang_cols as $k => $c) { if (isset($values[$c . CategoryFormControl::$_separator . $l['iso']])) { $save_val[$c] = $values[$c . CategoryFormControl::$_separator . $l['iso']]; } } //pridanie linky rewrite if ($save_val['link_rewrite'] == '') { $save_val['link_rewrite'] = NStrings::webalize($values['name' . CategoryFormControl::$_separator . $l['iso']]); } else { $save_val['link_rewrite'] = NStrings::webalize($save_val['link_rewrite']); } ProductModel::save($save_val, $id_product, $l['id_lang']); } //ulozenie zakladnych hodnot $save_val = array(); foreach ($table_product_cols as $p) { if (isset($values[$p])) { $save_val[$p] = $values[$p]; } } ProductModel::save($save_val, $id_product, $l['id_lang']); //ulozit param /* * Iba ak je product bez parametrov */ $val_product_param = Tools::getValuesForTable('product_param', $values); //prvy parameter $id_product_param = dibi::fetchSingle("SELECT id_product_param FROM [product_param] WHERE id_product = %i", $id_product, "ORDER BY sequence"); ProductModel::setProductParamValue($val_product_param, $id_product_param); ProductModel::saveProductAlternative($id_product, $values['product_alternative']); dibi::begin(); ProductModel::deleteProductFromCategories($id_product); ProductModel::addProductToCategory($values['id_categories'], $id_product); dibi::commit(); ProductModel::invalidateCache(); $this->flashMessage(_('Produkt bol uložený')); if ($form['btn_save']->isSubmittedBy()) { $s = NEnvironment::getSession("Admin_Eshop"); $back_url = $s['back_url']; if ($back_url != '') { $this->redirectUrl($back_url); } else { $this->redirect('Eshop:default'); } } else { $this->redirect('this'); } }
public function addMeta($key, $val) { if (empty($key)) { return; } $data = array('id_page' => $this->id, 'key' => $key, 'value' => $val, 'ord' => 1 + dibi::fetchSingle("SELECT max(ord) FROM pages_meta")); dibi::query('REPLACE INTO pages_meta', $data); $this->meta[$key] = $val; }
public function changeUser($form) { if ($form->isValid()) { $values = $form->getValues(); if (dibi::fetchSingle("SELECT 1 FROM auth_user WHERE login=%s", $values['login'], "AND login!=%s", $this->session['form_login']) == 1) { throw new Exception("Dané prihlasovacie meno už existuje. Zadajte iné prosím."); } $arr = array('login' => $values['login'], 'name' => $values['name'], 'surname' => $values['surname'], 'email' => $values['email']); if ($values['password'] != '') { $arr['password'] = UserModel::getHash($values['password']); } dibi::query("UPDATE auth_user SET", $arr, "WHERE id_auth_user=%i", $_GET['id_auth_user']); dibi::query("UPDATE auth_user_role SET ", array('id_auth_role' => $values['id_auth_role']), "WHERE id_auth_user = %i", $_GET['id_auth_user']); Log::addLog($this, 'Pridanie noveho uzivatela'); } else { throw new Exception('Nespavne vyplneny formular'); } Log::addLog($this, "Zmena uzivatelskych udajov.", "Menil:" . $this->session["login_form"]); return true; }
public function renderDefault($id, $id_menu_item) { $this->template->id_menu_item = dibi::fetchSingle("SELECT id_menu_item FROM [node] WHERE id_node = %i", $id); }
function duplicate($form) { $values = $form->getValues(); try { dibi::begin(); if ($values['sourceLang'] == $values['destLang']) { throw new DuplicateException('Nemôžete kopírovať do toho istého jazyku.'); } if (dibi::fetchSingle("SELECT 1 FROM [menu_item] WHERE lang = %s", $values['destLang']) == 1) { throw new DuplicateException('V jazyku "' . $values['destLang'] . '" sa už nachádzajú položky.'); } self::recursionAddMenuItem(0, $values, 0); dibi::commit(); } catch (DuplicateException $e) { $form->addError($e->getMessage()); } }
static function getPrice($weight) { return dibi::fetchSingle("SELECT weight_price FROM [product_weight] WHERE weight_to <= %s", $weight, "ORDER BY weight_to DESC LIMIT 1"); }