fetch() public static method

Executes SQL query and fetch result - Monostate for Dibi\Connection::query() & fetch().
public static fetch ( $args ) : Dibi\Row
return Dibi\Row
 public function renderDefault()
 {
     //uvod
     $home = dibi::fetch("SELECT * FROM [menu_item] WHERE home = 1 AND lang = %s", $this->lang);
     if (!$home) {
         $home = dibi::fetch("SELECT * FROM [menu_item] WHERE lang = %s", $this->lang, "ORDER BY sequence LIMIT 1");
     }
     $this->template->id_menu_item = $home['id_menu_item'];
     /*
      * META INFO
      */
     $this['header']->addTitle($home['meta_title']);
     $this['header']->setDescription($home['meta_description']);
     $node = $this->getService('Node');
     $query = $node->getAll($this->template->id_menu_item);
     $this->template->node_list = $query->fetchAll();
     //produkty na uvode
     $list = dibi::select('id_product')->from('product')->where('home = 1');
     $count_list = clone $list;
     $count = $count_list->removeClause('select')->select('COUNT(id_product)')->fetchSingle();
     $vp = new VisualPaginator($this, 'paginator');
     $paginator = $vp->getPaginator();
     $paginator->itemsPerPage = 12;
     $paginator->itemCount = (int) $count;
     $this->template->products = $list->limit($paginator->offset . ',' . $paginator->itemsPerPage)->fetchAll();
     $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);
     }
     /* widget */
     $this['productNewsSaleAvaiableTable']->setIdLang($this->id_lang);
     $this['productNewsSaleAvaiableTable']->setUser($this->user);
 }
Beispiel #2
0
 public static function duplicate($id_node, $new_id_node)
 {
     // nacitanie, co ma skopirovat
     $values = dibi::fetch("SELECT * FROM [" . self::TABLE . "] WHERE id_node = %i", $id_node);
     //vytvorenie
     self::add($new_id_node);
     self::saveHome($values, $new_id_node);
 }
Beispiel #3
0
 static function get($id_order, $id_user = null)
 {
     $order = dibi::fetch("SELECT * FROM [order] WHERE id_order = %i", $id_order, "%if", $id_user != null, "AND id_user = %i", $id_user, "AND deleted = 0 %end");
     if (!empty($order)) {
         $order['products'] = dibi::fetchAll("SELECT * FROM [order_product] WHERE id_order = %i", $id_order);
     }
     return $order;
 }
Beispiel #4
0
 function get($id_node)
 {
     $a = dibi::fetch("SELECT *, DATE_FORMAT(add_date, '%d.%m.%Y') AS add_date_formated FROM [article] WHERE id_node=%i", $id_node);
     if (!$a) {
         return false;
     }
     $a['files'] = self::getFiles($id_node);
     $a['first_img'] = isset($a['files'][0]) ? $a['files'][0] : array('src' => 'no-image', 'ext' => 'jpg');
     return $a;
 }
    public static function authenticate($login, $password)
    {
        return \dibi::fetch('
			SELECT *
			FROM [cv2_user]
			WHERE
				login = %s', $login, '
				AND
				password = %s', self::hash($password, $login));
    }
Beispiel #6
0
 public function login($username, $password)
 {
     //echo $this->return_hash($password);
     $user = dibi::fetch("SELECT * FROM user WHERE username=%s AND password=%s", $username, $this->return_hash($password));
     if (!$user) {
         throw new Exception('Neplatné jméno nebo heslo.');
     }
     //$_SESSION['user'] = $user;
     $_SESSION['user'] = serialize($user);
 }
Beispiel #7
0
 public function getFiles($id_node)
 {
     $files = FilesNode::getAllFiles('Home', $id_node);
     foreach ($files as $k => $l) {
         $i = dibi::fetch("SELECT title, link, alt, link_name FROM [promo_text] WHERE id_file = %i", $l['id_file']);
         $files[$k]['title'] = $i['title'];
         $files[$k]['link'] = $i['link'];
         $files[$k]['alt'] = $i['alt'];
         $files[$k]['link_name'] = $i['link_name'];
     }
     return $files;
 }
Beispiel #8
0
 function renderDefault()
 {
     $this->template->blog_box = dibi::fetchAll("SELECT * FROM menu_item WHERE parent = %i", dibi::fetch("SELECT * FROM menu_item WHERE url_identifier = 'blog'")->id_menu_item);
     foreach ($this->template->blog_box as $box) {
         $box['data'] = dibi::fetchAll("\n\t\t\t\tSELECT * FROM node \n\t\t\t\tLEFT JOIN article USING (id_node)\n\t\t\t\tWHERE \n\t\t\t\tid_menu_item = %i", $box->id_menu_item, "\n\t\t\t\tGROUP BY id_node\n\t\t\t\tORDER BY id_node DESC\n\t\t\t\tLIMIT 0, 5\n\t\t\t");
         foreach ($box['data'] as $article) {
             $article['url'] = $this->getPresenter()->link('Blog:current', array('categories' => $box->url_identifier, 'url_identifier' => $article->url_identifier));
             if ($image = FilesNode::getOneFirstFile('article', $article->id_node)) {
                 $article['image_url'] = Files::gURL($image->src, $image->ext, 220, 160, 6);
             }
         }
     }
 }
Beispiel #9
0
 /**
  * Performs an authentication
  * @param  array
  * @return Nette\Security\Identity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $row = dibi::fetch('SELECT * FROM users WHERE login=%s', $username);
     if (!$row) {
         throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     }
     if ($row->password !== $this->calculateHash($password)) {
         throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
     }
     unset($row->password);
     return new Nette\Security\Identity($row->id, $row->role, $row);
 }
Beispiel #10
0
 /**
  * Performs an authentication
  * @param  array
  * @return IIdentity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $username = $credentials[self::USERNAME];
     $password = md5($credentials[self::PASSWORD]);
     $row = dibi::fetch('SELECT * FROM users WHERE login=%s', $username);
     if (!$row) {
         throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     }
     if ($row->password !== $password) {
         throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
     }
     unset($row->password);
     return new Nette\Security\Identity($row->id, $row->role, $row);
 }
Beispiel #11
0
 protected function attached($presenter)
 {
     parent::attached($presenter);
     if (!$this->isSubmitted()) {
         $row = dibi::fetch("SELECT * FROM users WHERE username = %s", $presenter->user->id);
         $row['tags'] = $row['tags'];
         $row['projects'] = array_map(function ($a) {
             return trim($a, '()');
         }, explode(",", $row['projects']));
         if ($row) {
             $this->setValues($row);
         }
     }
 }
Beispiel #12
0
 function render($id_poll = NULL)
 {
     if ($id_poll == NULL) {
         $id_poll = $this->id_poll;
     }
     $template = $this->template;
     $template->setFile(dirname(__FILE__) . '/poll.phtml');
     $template->l = dibi::fetch("SELECT * FROM poll WHERE id_poll=%i", $id_poll, " AND from_date <= CURRENT_DATE() AND to_date >= CURRENT_DATE()");
     $template->answer = dibi::fetchAll("SELECT *, (SELECT COUNT(id_poll_ip_vol) FROM poll_ip_vol WHERE id_poll_answer = poll_answer.id_poll_answer) AS c FROM poll_answer WHERE id_poll=%i", $id_poll, "ORDER BY sequence");
     $template->answer_count = 0;
     //spocita iba tie co uz maju vysledok
     foreach ($template->answer as $a) {
         $template->answer_count += $a['c'];
     }
     $template->render();
 }
Beispiel #13
0
 function add($values)
 {
     $arr = array('name' => $values['name'], 'text' => $values['text'], 'id_node' => $values['id_node'], 'addDate' => new DateTime(), 'status' => 1, 'comment_parent' => (isset($values['comment_parent']) and $values['comment_parent'] != '') ? $values['comment_parent'] : NULL);
     dibi::query("INSERT INTO [comment] ", $arr);
     $l = dibi::fetch("\n\t\t\tSELECT \n\t\t\t\tmenu_item.url_identifier AS menu_url_identifier,\n\t\t\t\tarticle.url_identifier\n\t\t\tFROM \n\t\t\t\t[node]\n\t\t\t\tJOIN [menu_item] USING(id_menu_item)\n\t\t\t\tJOIN article USING(id_node)\n\t\t\tWHERE \n\t\t\t\tnode.id_node = %i", $values['id_node'], "\n\t\t");
     $template = $this->template;
     $template->setFile(dirname(__FILE__) . '/CommentEmailNotification.phtml');
     $template->values = $l;
     $uri = NEnvironment::getHttpRequest()->getUri();
     $template->url = $uri->scheme . '://' . $uri->host . $this->getPresenter()->link(":Homepage:article", $l['menu_url_identifier'], $l['url_identifier']);
     //		$mail = new MyMail();
     //        $mail->addTo( '*****@*****.**' );
     //        $mail->addBcc('*****@*****.**');
     //
     //        $mail->setSubject('Sprievodca ockovanim - Nový komentár.');
     //        if(NEnvironment::isProduction())
     //        	$mail->send($template);
 }
Beispiel #14
0
 public function render()
 {
     $template = new NFileTemplate();
     $template->registerFilter(new NLatteFilter());
     $template->setFile(dirname(__FILE__) . '/promo.phtml');
     $template->id = 'Multiupload_' . $this->type_module;
     //		$template->css = file_get_contents(dirname(__FILE__).'/fileuploader.css');
     //		$template->js = file_get_contents(dirname(__FILE__).'/fileuploader.js');
     if (_NETTE_MODE) {
         $template->action = NEnvironment::getApplication()->getPresenter()->link('Homepage:upload');
     } else {
         $template->action = '/admin.php';
     }
     $template->parsed_url = $this->parsed_url;
     $template->list = self::getAllFiles($this->type_module, $this->id_module, $this->type);
     foreach ($template->list as $k => $l) {
         $i = dibi::fetch("SELECT title, link, alt, link_name FROM [promo_text] WHERE id_file = %i", $l['id_file']);
         $template->list[$k]['title'] = $i['title'];
         $template->list[$k]['link'] = $i['link'];
         $template->list[$k]['alt'] = $i['alt'];
         $template->list[$k]['link_name'] = $i['link_name'];
     }
     return $template;
 }
 function createComponent($name)
 {
     switch ($name) {
         //	    case 'addForm':
         //			$form = $this->baseForm();
         //			$form->addSubmit('btn', 'Pridať');
         ////			$values['product_alternative'] = ProductModel::getFluent($this->id_lang)->where('id_category = 5')->fetchPairs("id_product",'id_product');
         //			//poziadavka klienta - zobrat vsetky produkty z doplnkov
         //
         //
         //			$form->setDefaults( array('id_product_template_group'=>$this->getService('ProductTemplateGroupModel')->getIdDefaultTemplate()) );
         //
         //
         //			$form->onSuccess[] = callback($this, 'add');
         //			return $form;
         //		break;
         case 'editForm':
             $id_product = $this->getPresenter()->getParam('id');
             $form = $this->baseForm();
             $form['id_product']->setValue($id_product);
             $values = array();
             //Titulok 	- doplnit categoria+ nazov produktu
             //Kľúčové slová -
             //Meta popis - doplnit categoria+ nazov produktu  + Výkon + Dĺžka Horenia
             foreach ($this->template->langs as $l) {
                 $val = ProductModel::get($id_product, $l['id_lang']);
                 // ziste ktore komponenty maju jazykovu mutaciu
                 $controls_for_lang = array();
                 foreach ($form->getComponents() as $control) {
                     if (strpos($control->getName(), CategoryFormControl::$_separator)) {
                         if (strpos($control->getName(), CategoryFormControl::$_separator . $l['iso'])) {
                             list($val_key) = explode(CategoryFormControl::$_separator . $l['iso'], $control->getName());
                             $values += array($control->getName() => $val[$val_key]);
                         }
                     } else {
                         if (isset($val[$control->getName()])) {
                             $values += array($control->getName() => $val[$control->getName()]);
                         }
                     }
                 }
             }
             //print_r(ProductModel::getProductAlternative($id_product));exit;
             $values['product_alternative'] = ProductModel::getProductAlternative($id_product);
             // vyriesenie categorii
             //nacitanie prveho parametru - iba pre jednoparametrove produkty
             $param = (array) dibi::fetch("SELECT * FROM [product_param] WHERE id_product = %i", $id_product);
             $form->setDefaults(array_merge($param, $values));
             $form->addSubmit('btn_save_and_stay', 'Upraviť a zostať tu');
             $form->addSubmit('btn_save', 'Upraviť');
             $form->onSuccess[] = callback($this, 'save');
             return $form;
             break;
             /*
              * generator
              */
         /*
          * generator
          */
         case 'generatorForm':
             //ProductModel::repairMinPrice();
             NFormContainer::extensionMethod('NFormContainer::addCheckboxList', array('CheckboxList', 'addCheckboxList'));
             $sizes = dibi::query("SELECT size FROM [product_param] WHERE size !='' GROUP BY size")->fetchPairs('size', 'size');
             $colors = dibi::query("SELECT color FROM [product_param] WHERE color !='' GROUP BY color")->fetchPairs('color', 'color');
             $materials = dibi::query("SELECT material FROM [product_param] WHERE material !='' GROUP BY material")->fetchPairs('material', 'material');
             $f = new MyForm();
             //			$f->getElementPrototype()->addClass('ajax');
             $renderer = $f->getRenderer();
             $renderer->wrappers['controls']['container'] = NHtml::el('div')->addClass('container');
             $renderer->wrappers['pair']['container'] = NHtml::el('div')->addClass('pair-container');
             $renderer->wrappers['label']['container'] = NHtml::el('h3');
             $renderer->wrappers['control']['container'] = NHtml::el('div')->addClass('input-container');
             //			usort($sizes, 'EshopProductControl::cmp');
             $f->addCheckboxList('size', 'Veľkosť', $sizes);
             $f->addCheckboxList('color', 'Farba', $colors);
             $f->addCheckboxList('material', 'Material', $materials);
             //ak je pridavanie a neexistuje id
             $f->addHidden('id_product', $this->getParam('id'));
             //
             //
             //			$renderer = $f->getRenderer();
             //			$renderer->wrappers['label']['container'] = NULL;
             //
             //			//ziskaj vsetky mozne velkosti
             //			$sizes = dibi::fetchAll("SELECT size FROM [product_param] GROUP BY size");
             //			$f->addGroup('Veľkosť');
             //			foreach($sizes as $k=>$size){
             //				$f->addCheckbox('size_'.$k, $size['size']);
             //			}
             //
             //			//ziskaj vsetky mozne farby
             //			$colors = dibi::fetchAll("SELECT color FROM [product_param] GROUP BY color");
             //			$f->addGroup('Farba');
             //			foreach($colors as $k=>$color){
             //				$f->addCheckbox('color_'.$k, $color['color']);
             //			}
             //
             //			//ziskaj vsetky mozne material
             //			$materials = dibi::fetchAll("SELECT material FROM [product_param] GROUP BY material");
             //			$f->addGroup('Material');
             //			foreach($materials as $k=>$material){
             //				$f->addCheckbox('material_'.$k, $material['material']);
             //			}
             $f->addGroup()->setOption('container', 'fieldset class=clear');
             $f->addSubmit('btn_generate', 'Generovať');
             $f->onSuccess[] = array($this, 'handleAddGeneratedParam');
             return $f;
             break;
         case 'productParams':
             //			$d = ProductModel::getProductParamDatasource( $this->getParam('id'))->fetchAll();
             $id_product = $this->getParam('id');
             $grid = new Tabella(ProductModel::getProductParamDatasource($id_product), array('sorting' => 'asc', 'order' => 'sequence', 'id_table' => 'id_product_param', 'limit' => 50, "onSubmit" => function ($post) {
                 //						print_r($post);exit;
                 ProductModel::setProductParamValue($post, $post['id_product_param']);
             }, "onDelete" => function ($id) {
                 ProductModel::deleteProductParamValue($id);
             }));
             $el = NHtml::el("div");
             $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('addEmptyParam!', array('id_product' => $id_product)))->addClass('addIcon ajax'));
             $grid->addColumn($el, 'sequence', array('width' => 20, 'filter' => NULL, "editable" => true));
             //vytiahnutie template_group pre produkt - ake bude mat parametre
             if ($id_product) {
                 $id_product_template_group = ProductModel::getFluent(1, false, false)->removeClause('select')->select('id_product_template_group')->where('id_product = %i', $id_product)->fetchSingle();
             } else {
                 //ak je id_product NULL jedna sa pridavanie produktu
                 if ($id_product == NULL and $this->getParam('id_product_template_group') != NULL) {
                     $id_product_template_group = $this->getParam('id_product_template_group');
                 } else {
                     $id_product_template_group = $this->getService('ProductTemplateGroupModel')->getIdDefaultTemplate();
                 }
             }
             $params = $this->getService('ProductTemplateGroupModel')->fetchAssocAllParam($id_product_template_group);
             foreach ($params as $p) {
                 if ($p['checked']) {
                     $grid->addColumn($this->getService('translator')->translate($p['row_name']), $p['row_name'], array("width" => 50, "editable" => true));
                 }
             }
             $grid->addColumn("Cena", "price", array("width" => 100, "editable" => true));
             //			_repairPriceForView
             //
             //
             //			$grid->addColumn( "Na sklade", "stock", array( "width" => 50, "editable" => true ) );
             ////			$grid->addColumn( "Farba", "color", array( "width" => 100, "editable" => true ) );
             ////			$grid->addColumn( "Veľkosť", "size", array( "width" => 100, "editable" => true ) );
             ////			$grid->addColumn( "Material", "material", array( "width" => 100, "editable" => true ) );
             //			$grid->addColumn( "Napojenie", "connection", array( "width" => 100, "editable" => true ) );
             //			$grid->addColumn( "Cena", "price", array( "width" => 100, "editable" => true ) );
             $grid->addColumn("", "", array("width" => 30, 'filter' => NULL, "options" => '', "renderer" => function ($row) {
                 $el = NHtml::el("td");
                 $el->add(NHtml::el('a')->href(NEnvironment::getApplication()->getPresenter()->link('deleteProductParam!', array('id_product_param' => $row->id_product_param)))->addClass('deleteIcon ajax'));
                 return $el;
             }));
             $this->addComponent($grid, $name);
             break;
         case 'pictogram':
             $p = new PictogramControl($this, $name);
             return $p;
             break;
         case 'keyword':
             return new KeywordControl();
             break;
         case 'ajaxtest':
             return new AjaxTextControl();
             break;
         default:
             return parent::createComponent($name);
             break;
     }
 }
 public function actionAccess($id)
 {
     $nodes = new RolesModel();
     $this->template->nodes = $nodes;
     $this->template->parents = $nodes->getChildNodes(NULL);
     $role = dibi::fetch('SELECT key_name, name FROM [' . TABLE_ROLES . '] WHERE id=%i;', $id);
     $this->template->role = $role->name;
     $access = new AccessModel(array($role));
     $this->template->access = $access->getAccess();
 }
Beispiel #17
0
 public function return_page($url)
 {
     return dibi::fetch("SELECT * FROM web WHERE url=%s", $url);
 }
Beispiel #18
0
 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']."
         //			";
     }
 }
Beispiel #19
0
 function changeOrderNode()
 {
     $order = 'DESC';
     if (isset($_GET['modul_id_up'])) {
         $id_node = $_GET['modul_id_up'];
     }
     if (isset($_GET['modul_id_down'])) {
         $id_node = $_GET['modul_id_down'];
     }
     $pom = dibi::fetch("SELECT sequence,id_node,id_menu_item FROM node WHERE id_node=%i", $id_node, " LIMIT 1 ");
     if (isset($_GET['modul_id_up'])) {
         $sequence = $pom['sequence'] + 1.5;
     }
     if (isset($_GET['modul_id_down'])) {
         $sequence = $pom['sequence'] - 1.5;
     }
     //	print_r($pom);
     dibi::query("UPDATE node SET sequence=%s", $sequence, "WHERE id_node=%i", $id_node);
     //	echo dibi::$sql;
     //oprava poradia
     $list = dibi::fetchAll("SELECT * FROM node WHERE id_menu_item='" . $pom['id_menu_item'] . "' ORDER BY sequence");
     $sequence = 0;
     //	echo dibi::$sql;
     //	print_r($list);
     //	exit;
     //	exit;
     foreach ($list as $l) {
         ++$sequence;
         dibi::query("UPDATE node SET sequence=%i", $sequence, " WHERE id_node=%i", $l['id_node']);
     }
     //	exit;
 }
Beispiel #20
0
 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();
 }
Beispiel #21
0
<?php 
require dirname(__FILE__) . '/Nette/Debugger.php';
require dirname(__FILE__) . '/../dibi/dibi.php';
ndebug();
dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb'));
/*
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');
Beispiel #22
0
 protected function getUserDetailsAndLoginUser()
 {
     $this->oauth->setToken($this->getSession('oauth')->token, $this->getSession('oauth')->secret);
     //fetch user datail XML
     $this->oauth->fetch(self::API_URL . "user/details");
     $user_details = $this->oauth->getLastResponse();
     $xml = simplexml_load_string($user_details);
     $user = array('id' => $xml->user['id'], 'username' => $xml->user['display_name'], 'account_created' => $xml->user['account_created'], 'img' => $xml->user->img['href'], 'changesets' => $xml->user->changesets['count'], 'traces' => $xml->user->traces['count'], 'description' => $xml->user->description, 'home_lat' => $xml->user->home['lat'], 'home_lon' => $xml->user->home['lon'], 'last_login' => date("Y-m-d H:i:s"));
     // convert xml-nodes to strings
     foreach ($user as &$val) {
         $val = strval($val);
     }
     // update db
     $row = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']);
     if ($row) {
         //better dont change usernames, we use it as primary key
         unset($user['username']);
         dibi::query('UPDATE users SET ', $user, ' WHERE id = %i', $user['id']);
     } else {
         $user['first_login'] = new DateTime();
         dibi::query('INSERT INTO users ', $user);
     }
     // load complete row from db
     $dbuser = dibi::fetch('SELECT * FROM users WHERE id = %i', $user['id']);
     if ($dbuser['webpages'] != 'admin' and $dbuser['webpages'] != 'all') {
         $dbuser['webpages'] = '14' . ($dbuser['webpages'] ? ',' : '') . $dbuser['webpages'];
     }
     $this->user->login(new Identity($dbuser['username'], array($dbuser['webpages'] == 'admin' ? 'admin' : 'user'), $dbuser));
     // remove all tokens - TODO if tokens to be used, save them in DB
     $this->redirectUrl('//' . $_SERVER['HTTP_HOST'] . $this->getSession('oauth')->back_url);
 }
Beispiel #23
0
 function showUsers()
 {
     $user = NEnvironment::getUser();
     if (!$user->isAllowed('manage_user', 'edit')) {
         throw new LogicException('Nemáte dostatočné oprávnenie na túto sekciu');
     }
     try {
         //uprava uzivatela
         if (isset($_GET['id_auth_user']) and $_GET['id_auth_user'] != "") {
             $form = new NForm();
             $form->addText('name', 'Meno');
             $form->addText('surname', 'Priezvisko');
             $form->addText('email', 'Email');
             $form->addText('login', 'Login')->addRule(NFORM::FILLED, 'Login musí byť vyplnený');
             $form->addPassword('password', 'Heslo');
             $role = dibi::query('SELECT id_auth_role, key_name FROM auth_role ORDER BY key_name')->fetchPairs('id_auth_role', 'key_name');
             $form->addPassword('password2', 'Znova heslo')->addConditionOn($form['password'], NForm::FILLED)->addRule(NForm::FILLED, 'Zadejte heslo pro kontrolu')->addRule(NForm::EQUAL, 'Hesla se musi shodovat', $form['password']);
             $form->addSelect('id_auth_role', 'Uživateľská skupina:', $role);
             $form->addSubmit('addUser', 'Upravit');
             $form->onSubmit[] = array($this, 'changeUser');
             if (!$form->isSubmitted()) {
                 // 	první zobrazení, nastavíme výchozí hodnoty
                 $form->setDefaults(dibi::fetch("SELECT *, id_auth_role FROM auth_user LEFT JOIN [auth_user_role] USING(id_auth_user) WHERE auth_user.id_auth_user=%i", $_GET['id_auth_user']));
             }
             $form->fireEvents();
             MT::addTemplate(APP_DIR . '/require_modules/authentication/editUser.phtml', 'editUser');
             MT::addVar('editUser', 'form', (string) $form);
         }
     } catch (Exception $e) {
         ?>
   <div style="border:2px solid red;padding:5px;">
     <?php 
         echo $e->getMessage();
         ?>
   </div><?php 
     }
     if (!isset($_GET['id_auth_user'])) {
         if (isset($_GET['id_delete_user'])) {
             $this->deleteUser();
         }
         $form = new NForm();
         $form->getElementPrototype()->id = 'formAddUser';
         $form->addText('name', 'Meno');
         $form->addText('surname', 'Priezvisko');
         $form->addText('email', 'Email');
         $form->addText('login', 'Login')->addRule(NFORM::FILLED, 'Login musí byť vyplnený');
         $form->addPassword('password', 'Heslo')->addRule(NForm::FILLED, 'Zadejte heslo');
         $role = dibi::query('SELECT id_auth_role, key_name FROM [auth_role] ORDER BY key_name')->fetchPairs('id_auth_role', 'key_name');
         $form->addPassword('password2', 'Znova heslo')->addRule(NForm::FILLED, 'Zadejte heslo pro kontrolu')->addRule(NForm::EQUAL, 'Hesla se musi shodovat', $form['password']);
         $form->addSelect('id_auth_role', 'Uživateľská skupina:', $role);
         $form->addSubmit('addUser', 'Pridať použivateľa');
         $form->onSubmit[] = array($this, 'addUser');
         $form->fireEvents();
         MT::addTemplate(APP_DIR . '/require_modules/authentication/showUsers.phtml', 'showUsers');
         $list = dibi::fetchAll("\n      \tSELECT \n      \t\t*\n      \tFROM \n      \t\tauth_user\n      \tORDER BY login");
         MT::addVar('showUsers', 'list', $list);
         MT::addVar('showUsers', 'form', $form);
     }
 }
Beispiel #24
0
 function createComponent($name)
 {
     switch ($name) {
         /*
          * newsletterTabella
          */
         case 'newsletterTabella':
             $grid = new Tabella(NewsletterModel::getFluent()->toDataSource(), array('sorting' => 'desc', 'order' => 'adddate', 'id_table' => 'id', 'limit' => 100, 'onSuccess' => function ($values) {
                 NewsletterModel::edit($values, $values['id_newsletter_emails']);
             }, 'onDelete' => function ($id_newsletter_emails) {
                 NewsletterModel::delete($id_newsletter_emails);
             }));
             $el = NHtml::el("div");
             $session = NEnvironment::getSession('checked_emails');
             $grid->addColumn($el, "", array("editable" => false, 'filter' => false, "width" => 20, "renderer" => function ($row) use($session) {
                 $el = NHtml::el("td");
                 $checked = isset($session->emails[$row['id_newsletter_emails']]) ? 'checked="checked"' : '';
                 $el->add('<input class="checked_emails" type="checkbox" name="se[]" value="' . $row['id_newsletter_emails'] . '" ' . $checked . '/>');
                 return $el;
             }));
             $grid->addColumn("Id", "id_newsletter_emails", array("width" => 30, 'editable' => false));
             $grid->addColumn("Email", "email", array("width" => 50, 'editable' => false));
             //				$grid->addColumn( "Popis", "description", array( 'editable'=>true ) );
             $grid->addColumn("Dátum registrácie ", "adddate", array("width" => 100));
             /*$grid->addColumn( "Aktívny", "active",
             						array(
             							"width" => 50,
             							'type'=>  Tabella::SELECT,
             							"editable" => true,
             							"filter" => array( 1=>'áno', 0=>'nie'),
             							'renderer' => function($row){
             								$active = ($row['active'] == 1)?'áno':'nie';
             								$el = NHtml::el( "td" )->setHtml($active);
             								return $el;
             							}
             						)
             				);
             
             
             				$grid->addColumn("", "",
             					array(
             						"width" => 30,
             						'filter'=>NULL,
             						"options" => '',
             
             						"renderer" => function( $row ) {
             							$el = NHtml::el( "td" );
             
             							$el->add(
             							NHtml::el( 'a' )->href(
             								NEnvironment::getApplication()->getPresenter()->link( 'deleteEmail!' , array('id'=>$row->id_newsletter_emails))
             							)->addClass( 'deleteIcon' )
             							);
             
             							$span = NHtml::el('span');
             
             
             							$el->add($span);
             
             							return $el;
             						}
             						)
             					);
             */
             $this->addComponent($grid, $name);
             break;
             /*
              * newslette text
              */
         /*
          * newslette text
          */
         case 'newsletterTextForm':
             $last_newsletter = dibi::fetch("SELECT * FROM [newsletter_sended_msg] ORDER BY [date] DESC LIMIT 1");
             $f = new MyForm($this, $name);
             $f->addText('subject', 'Predmet')->addRule(NForm::FILLED, 'Predmet musí byť vyplnený.');
             $f->addTextArea('text', '');
             $f->addText('my_email', 'Testovací email');
             $f->addSubmit('btn_send_emails', 'Odoslať všetkým')->onClick[] = array($this, 'actionSendEmails');
             $f->addSubmit('btn_send_to_me', 'Odoslať testovací email')->onClick[] = array($this, 'actionSendTestingEmail');
             if (!$last_newsletter) {
                 $email_template = new NFileTemplate();
                 $email_template->registerFilter(new NLatteFilter());
                 $email_template->setFile(WWW_DIR . '/newsletter/templates/1/1.phtml');
                 $email_template->text = '';
                 $values['text'] = (string) $email_template;
             } else {
                 $values = $last_newsletter;
             }
             $f->setDefaults($values);
             return $f;
             break;
         case 'addForm':
             $f = new MyForm();
             $f->addText('emails', 'Email');
             $f->addSubmit('btn', 'Pridať');
             $f->onSuccess[] = array($this, 'handleAddEmail');
             return $f;
             break;
         default:
             return parent::createComponent($name);
             break;
     }
 }
Beispiel #25
0
 public static function duplicate($id_node, $new_id_node)
 {
     // nacitanie, co ma skopirovat
     $values = dibi::fetch("SELECT * FROM [module_product] WHERE id_node = %i", $id_node);
     //vytvorenie
     self::add($new_id_node);
     self::saveProduct($values, $new_id_node);
     $id_file_node = FilesNode::getFileNode(self::MODULE_NAME, $id_node);
     if ($id_file_node) {
         FilesNode::copyTo($id_file_node, self::MODULE_NAME, $new_id_node);
     }
 }
Beispiel #26
0
 /**
  * add class to database
  *
  * @param mixed $name
  * @param mixed $path
  * @param mixed $codeLine
  * @return void
  */
 protected function _addClass($name, $path, $codeLine)
 {
     $data = array('name' => $name, 'path' => $path);
     $classData = dibi::fetch('
         SELECT t.id as classId, COALESCE(s.id,0) as signatureId
         FROM [classes] t
             LEFT JOIN [class_signature] ts ON ( t.id = ts.class_id )
             LEFT JOIN [signatures] s ON ( ts.signature_id = s.id AND s.definition = %s)
         WHERE name = %s AND t.path = %s ORDER BY signatureId DESC', $codeLine, $name, $path);
     if (false === $classData || 0 == $classData->signatureId) {
         $signatureId = $this->_createSignature('c', $codeLine, $path);
         if (false === $classData) {
             dibi::query('INSERT INTO [classes] %v', $data);
             $classId = dibi::getInsertId();
         } else {
             $classId = $classData->classId;
         }
         dibi::query('INSERT INTO [class_signature] %v', array('class_id' => $classId, 'signature_id' => $signatureId));
     } else {
         $signatureId = $classData->signatureId;
     }
     $this->_assignSignatureToMagento($signatureId);
 }
Beispiel #27
0
 public function getSQL()
 {
     $row = dibi::fetch("SHOW CREATE DATABASE `{$this->name}`");
     return $row['Create Database'];
 }
Beispiel #28
0
 function addModul()
 {
     if ($_POST['name'] == "") {
         $_POST['name'] = $_POST['dir'];
     }
     if (dibi::fetch("SELECT 1 FROM type_modul WHERE dir=%s", $_POST['dir']) != 1) {
         dibi::query("INSERT INTO type_modul ", array('name' => $_POST['name'], 'dir' => $_POST['dir'], 'visible_for_user' => $_POST['visible_for_user']));
     } else {
         throw new Exception("Dany modul bud neexistuje alebo uz bol pridany");
     }
 }
Beispiel #29
0
 public static function getPageBySeoname($seoname, $lang)
 {
     $page = dibi::fetch("SELECT * FROM pages WHERE lang = %s", $lang, " AND seoname = %s", $seoname, " AND deleted=0");
     if ($page) {
         return self::pagesModelNode($page);
     }
     return false;
 }
Beispiel #30
0
 public function getSQL()
 {
     $row = dibi::fetch("SHOW CREATE TABLE `{$this->db}`.`{$this->name}`");
     return $row['Create Table'];
 }