Example #1
0
 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();
 }
Example #2
0
 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);
 }
Example #3
0
 public function setUrl($url = null)
 {
     if (!$url) {
         $url = $this->nazev;
     }
     $this->url = NStrings::webalize($url);
 }
Example #4
0
    public function renderXml()
    {
        $this->template->items = dibi::query('
SELECT 
product.id_product AS id, 
product_lang.name, 
product_lang.description, 
product_lang.link_rewrite AS product_link,
category_product.id_category AS id_category,
category_lang.name AS category_name,
category_lang.link_rewrite AS category_link
FROM `product`
LEFT JOIN product_lang USING (id_product)
LEFT JOIN category_product USING (id_product)
LEFT JOIN category_lang USING (id_category)
WHERE product_lang.id_lang = 1 AND
 category_lang.id_lang = 1
GROUP BY (id_product)')->fetchAll();
        $this->template->baseUri = 'http://www.matrace-rosty.sk';
        $this->id_lang = 1;
        for ($i = 0; $i < count($this->template->items); $i++) {
            $productWithLowestPrice = dibi::query('SELECT * FROM product_param WHERE id_product = %i', $this->template->items[$i]['id'], ' ORDER BY price LIMIT 0,1')->fetch();
            $this->template->items[$i]['url'] = $this->getPresenter()->link('Eshop:current', array('categories' => $this->template->items[$i]['category_link'], 'url_identifier' => NStrings::webalize($this->template->items[$i]['product_link'])));
            $this->template->items[$i]['image'] = ProductModel::getImage($this->template->items[$i]['id']);
            $this->template->items[$i]['price_vat'] = round($productWithLowestPrice['price'], 2);
            $this->template->items[$i]['price'] = round($this->template->items[$i]['price_vat'] / 1.2, 2);
            $this->template->items[$i]['vat'] = '0.20';
            $this->template->items[$i]['size'] = $productWithLowestPrice['size'];
            $this->template->items[$i]['material'] = $productWithLowestPrice['material'];
        }
    }
Example #5
0
 public function generovatUsername($id)
 {
     $zaznam = $this->findById($id);
     $jmeno = NStrings::webalize($zaznam->jmeno);
     $prijmeni = NStrings::webalize($zaznam->prijmeni);
     $username = NStrings::webalize($prijmeni);
     if (!$this->findByUsername($username)) {
         return $username;
     }
     $username = $prijmeni . NStrings::truncate($jmeno, 1, '');
     if (!$this->findByUsername($username)) {
         return $username;
     }
     $username = $prijmeni . $jmeno;
     if (!$this->findByUsername($username)) {
         return $username;
     }
     for ($i = 1; 1 == 1; $i++) {
         $username = $prijmeni . $jmeno . $i;
         if (!$this->findByUsername($username)) {
             return $username;
         }
     }
 }
Example #6
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']."
         //			";
     }
 }
Example #7
0
	/**
	 * Returns the sanitized file name.
	 * @return string
	 */
	public function getSanitizedName()
	{
		return trim(NStrings::webalize($this->name, '.', FALSE), '.-');
	}
Example #8
0
 /**
  * @access public
  * @param $dir
  * @param $name
  * @param $ext
  * @ParamType $dir 
  * @ParamType $name 
  * @ParamType $ext 
  */
 public function doNameFile($dir, $name, $ext)
 {
     $number = "";
     while (file_exists($dir . '/' . NStrings::webalize($name) . $number . "." . $ext)) {
         ++$number;
     }
     //    echo NStrings::webalize($name).$number.".".$ext;exit;
     return NStrings::webalize($name) . $number;
 }
Example #9
0
 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');
     }
 }
Example #10
0
 function categoryAction(NForm $form)
 {
     $values = $form->getValues();
     $langs = Setting::getLangs();
     switch ($this->mode) {
         case 'edit':
             $id_category = $values['id_category'];
             foreach ($langs as $l) {
                 $lang_val = array();
                 foreach ($values as $k => $v) {
                     if (strpos($k, self::$_separator . $l['iso'])) {
                         list($name) = explode(self::$_separator . $l['iso'], $k);
                         $lang_val[$name] = $v;
                         //pridanie linky rewrite
                         if ($name == 'link_rewrite' and $v == '') {
                             $lang_val[$name] = NStrings::webalize($values['name' . self::$_separator . $l['iso']]);
                         } elseif ($name == 'link_rewrite') {
                             $lang_val[$name] = NStrings::webalize($lang_val[$name]);
                         }
                         //			    unset($values[$k]);
                     }
                 }
                 $lang_val += array('id_parent' => $values['id_parent'], 'active' => $values['active'], 'show_on_bottom' => $values['show_on_bottom']);
                 $c = new CategoryModel($l['id_lang']);
                 $c->save($lang_val, $id_category);
             }
             $c = new CategoryModel(1);
             $c->repairSequence();
             //	print_r($values);
             CategoryModel::repairCategoryRewriteLink();
             CategoryModel::invalidateCache();
             $this->getPresenter()->flashMessage(_('Kategória bola upravená.'));
             $this->getPresenter()->redirect("this");
             break;
         case 'add':
             $id_category = CategoryModel::add(array('id_parent' => $values['id_parent'], 'active' => $values['active']));
             unset($values['id_parent'], $values['active']);
             foreach ($langs as $l) {
                 $lang_val = array();
                 foreach ($values as $k => $v) {
                     if (strpos($k, self::$_separator . $l['iso'])) {
                         list($name) = explode(self::$_separator . $l['iso'], $k);
                         $lang_val[$name] = $v;
                         //pridanie linky rewrite
                         if ($name == 'link_rewrite' and $v == '') {
                             $lang_val[$name] = NStrings::webalize($values['name' . self::$_separator . $l['iso']]);
                         }
                     }
                 }
                 $lang_val += array('id_category' => $id_category, 'id_lang' => $l['id_lang']);
                 CategoryModel::addCategoryLang($lang_val);
             }
             $c = new CategoryModel(1);
             $c->repairSequence();
             // prepisanie file_node na novy id_category
             dibi::query("UPDATE [file_node] SET id_module = %i", $id_category, "WHERE id_module = 999999 AND type_module = 'category'");
             CategoryModel::repairCategoryRewriteLink();
             CategoryModel::invalidateCache();
             //	print_r($values);
             $this->getPresenter()->flashMessage(_('Kategória bola pridaná.'));
             $this->getPresenter()->redirect("Eshop:default");
             break;
     }
 }
Example #11
0
 static function getUrl($id_category, $id_lang = 1)
 {
     $pom = self::getParents($id_category, $id_lang);
     $tree = self::getTree($id_lang);
     $pom = array_reverse($pom);
     //		print_r($pom);
     $return = array();
     foreach ($pom as $k => $i) {
         $return[$k] = NStrings::webalize($tree[$i]['name']);
     }
     return implode('/', $return);
 }
Example #12
0
 public function urlClanku($clanek)
 {
     return NStrings::webalize($clanek->id . '-' . $clanek->nadpis);
 }
Example #13
0
 function url_identifier($name, $id_current = 0)
 {
     $newname = "";
     $i = 0;
     while ($i < 500) {
         if ($i == 0) {
             $newname = NStrings::webalize($name);
         } else {
             $newname = NStrings::webalize($name . $i);
         }
         $s = dibi::fetchSingle("SELECT COUNT(id_menu_item) FROM menu_item WHERE url_identifier=%s", $newname, " AND id_menu_item!=%i", $id_current);
         if ($s == 0) {
             break;
         } else {
             $i++;
         }
     }
     return $newname;
 }