Example #1
0
function do_edit_save($aid, $params)
{
    $pid = cf\api\admin\doAction($aid, $params);
    if (array_key_exists('id', $params)) {
        $pid = $params['id'];
    }
    //update categories
    $pos = cf\query2arrays('SELECT group_id,sort_order FROM cf_products_in_groups WHERE product_id=:id', array('id' => $pid), false, 'group_id');
    cf\execQuery('DELETE FROM cf_products_in_groups WHERE product_id=:id', array('id' => $pid));
    $categories = cf\param::exist('category') ? cf\param::get('category') : array();
    $q = cf\createQuery('INSERT INTO cf_products_in_groups (group_id,product_id,sort_order) VALUES(:groupId,:productId,:sortOrder)', array('productId' => $pid));
    foreach ($categories as $catId) {
        $q->setParam('groupId', $catId);
        $q->setParam('sortOrder', array_key_exists($catId, $pos) ? $pos[$catId]['sort_order'] : 500);
        $q->execute();
    }
    //update attributes
    if (cf\param::exist('attributes')) {
        $attrValues = cf\param::get('attributes');
        $attributes = new cf\ProductAttributes($pid, true);
        foreach ($attributes as $attr) {
            if (array_key_exists($attr->id(), $attrValues)) {
                $attr->setValue($attrValues[$attr->id()]);
            }
        }
        $product = new cf\Product($pid);
        $product->setAttributes($attributes);
    }
}
Example #2
0
function get($id)
{
    $id = getID($id);
    static $q = null;
    \cf\createStaticQuery($q, "SELECT id, code, name, action, method, template FROM cf_form WHERE id=:id");
    $form = \cf\query2array($q, array('id' => $id));
    if ($form['template']) {
        $form['template'] = \cf\query2array("\n\t\t\tSELECT name, subject, recipient, body \n\t\t\tFROM cf_mail_templates \n\t\t\tWHERE id=:id", array('id' => $form['template']));
    } else {
        $form['template'] = false;
    }
    static $qFields = null;
    \cf\createStaticQuery($qFields, "\n\t\tSELECT code,type,name,fmt,descr,mandatory,max_length,min_length,value\n\t\tFROM cf_form_field\n\t\tWHERE form_id=:id\n\t\tORDER BY sort_order\n\t");
    $form['fields'] = \cf\query2arrays($qFields, array('id' => $id), false, 'code');
    foreach ($form['fields'] as &$f) {
        $f['code'] = $form['code'] . '[' . $f['code'] . ']';
        if ($f['type'] == 'radio' || $f['type'] == 'checkbox') {
            $f['options'] = array();
            foreach (explode(';', $f['fmt']) as $option) {
                $f['options'][] = trim($option);
            }
        }
    }
    return $form;
}
Example #3
0
function do_edit_save($aid, $params)
{
    $pid = cf\api\admin\doAction($aid, $params);
    if (array_key_exists('id', $params)) {
        $pid = $params['id'];
    }
    global $fk;
    if (!$fk) {
        //it's not an option
        //update categories
        $pos = cf\query2arrays('SELECT page_id,sort_order FROM cf_products_in_category WHERE product_id=:id', array('id' => $pid), false, 'page_id');
        cf\execQuery('DELETE FROM cf_products_in_category WHERE product_id=:id', array('id' => $pid));
        $categories = cf\param::exist('category') ? cf\param::get('category') : array();
        $q = cf\createQuery('INSERT INTO cf_products_in_category (page_id,product_id,sort_order) VALUES(:categoryId,:productId,:sortOrder)', array('productId' => $pid));
        foreach ($categories as $catId) {
            $q->setParam('categoryId', $catId);
            $q->setParam('sortOrder', array_key_exists($catId, $pos) ? $pos[$catId]['sort_order'] : 500);
            $q->execute();
        }
    }
    //update attributes
    if (cf\param::exist('attributes')) {
        cf\execQuery("DELETE FROM cf_product_attributes WHERE product_id=:id", array('id' => $pid));
        $q = cf\createQuery("INSERT INTO cf_product_attributes (product_id, attribute_id, attribute_value) VALUES (:pid,:aid,:val)");
        $attrValues = cf\param::get('attributes');
        foreach ($attrValues as $id => $val) {
            $q->setParam('pid', $pid);
            $q->setParam('aid', $id);
            $q->setParam('val', $val);
            $q->execute();
        }
    }
}
Example #4
0
function do_edit_save($aid, $params)
{
    global $step, $smarty, $view;
    if (array_key_exists('yml_id', $params)) {
        $step = 3;
        $ymlID = $params['yml_id'];
        $path = $params['file_path'];
        $smarty->assign('ymlID', $ymlID);
        exec('php ' . cf\Config::path . "cron/shop/import/yml.php {$ymlID} {$path} &");
    } else {
        $step = 2;
        $path = sys_get_temp_dir() . uniqid('yml');
        if (array_key_exists('url', $_FILES)) {
            if ($_FILES['url']['type'] == 'url') {
                $params['url'] = $_FILES['url']['name'];
                if (!copy($_FILES['url']['name'], $path)) {
                    die("Can't copy file from URL:" . $_FILES['url']['name']);
                }
            } elseif ($_FILES['url']['type']) {
                if (UPLOAD_ERR_OK != $_FILES['url']['error'] || !is_uploaded_file($_FILES['url']['tmp_name'])) {
                    die("The file could't be uploaded [" . $_FILES['url']['error'] . "], check 'upload_max_filesize' or 'post_max_size' in php.ini");
                }
                if (!move_uploaded_file($_FILES['url']['tmp_name'], $path)) {
                    die("Can't move uploaded file");
                }
            } else {
                if (!copy($params['url'], $path)) {
                    die("Can't copy file from URL:" . $params['url']);
                }
            }
            unset($_FILES['url']);
        }
        $id = cf\api\admin\doAction(cf\param::get('aid'), $params);
        $assigned = array();
        if (array_key_exists('id', $params)) {
            $id = $params['id'];
            $importCat = cf\query2arrays("SELECT from_id,to_id FROM cf_import_yml_categories WHERE yml_id=:id", array('id' => $id));
            foreach ($importCat as $fromTo) {
                $assigned[$fromTo['from_id']] = $fromTo['to_id'];
            }
        }
        $smarty->assign('ymlID', $id);
        $smarty->assign('assigned', json_encode($assigned));
        $smarty->assign('file_path', $path);
        global $categories;
        loadCategoriesFromYML($path);
        $smarty->assign('allCategories', json_encode(createCategoriesTree()));
    }
}
Example #5
0
/**
	@param $parentId  category ID or CODE or PATH OF CODES (e.g. /cars/bmw/x-5)
*/
function getCategoriesTree($parentId = null, $showHidden = false, $maxDepth = 0, $path = '', $depth = 1)
{
    if ($maxDepth && $depth > $maxDepth) {
        return array();
    }
    static $q = null;
    \cf\createStaticQuery($q, "\r\n\t\tSELECT id, parent_id, name, hidden, IFNULL(code,id) AS code, image, page_title, page_keywords, page_descr, short_descr\r\n\t\tFROM cf_groups\r\n\t\tWHERE (parent_id=:parentId OR (:parentId IS NULL AND parent_id IS NULL))\r\n\t\t\t" . ($showHidden ? '' : 'AND (hidden IS NULL OR hidden=0)') . "\r\n\t\tORDER BY sort_order ASC\r\n\t");
    $items = \cf\query2arrays($q, array('parentId' => \cf\Group::toID($parentId)), false, 'code');
    foreach ($items as $id => $item) {
        $items[$id]['depth'] = $depth;
        $items[$id]['path'] = $path . '/' . $items[$id]['code'];
        $items[$id]['children'] = getCategoriesTree($id, $showHidden, $maxDepth, $items[$id]['path'], ++$depth);
    }
    return $items;
}
Example #6
0
function search($search, $showHidden = false)
{
    $search = is_array($search) ? $search : array($search);
    $sql = array();
    $params = array();
    $i = 0;
    foreach ($search as $s) {
        $sql[] = "(\n\t\t\tname LIKE CONCAT('%',:search{$i},'%')\n\t\t\tOR menu_name LIKE CONCAT('%',:search{$i},'%')\n\t\t\tOR short_txt LIKE CONCAT('%',:search{$i},'%')\n\t\t\tOR txt LIKE CONCAT('%',:search{$i},'%')\n\t\t)";
        $params["search{$i}"] = trim($s);
        ++$i;
    }
    $q = null;
    \cf\createStaticQuery($q, "\n\t\tSELECT id, IFNULL(code,id) AS code, parent_id, name, menu_name, image, short_txt, link, hidden, sort_order, title, keywords, descr\n\t\tFROM cf_page\n\t\tWHERE " . implode(' AND ', $sql) . ($showHidden ? '' : 'AND (hidden IS NULL OR hidden=0)') . "\n\t\tORDER BY sort_order ASC\n\t");
    return \cf\query2arrays($q, $params);
}
Example #7
0
File: yml.php Project: sd-studio/or
function getManufacturerID($name)
{
    static $qNew = null;
    cf\createStaticQuery($qNew, "INSERT INTO cf_manufacturers (name) VALUES (:name)");
    static $manufacturers = null;
    if (!$manufacturers) {
        $manufacturers = cf\query2arrays("SELECT name,id FROM cf_manufacturers", array(), false, 'name');
    }
    if (array_key_exists($name, $manufacturers)) {
        return $manufacturers[$name]['id'];
    }
    $qNew->setParam('name', $name)->execute();
    global $db;
    $id = $db->lastInsertId();
    $manufacturers[$name] = array('id' => $id);
    return $id;
}
Example #8
0
function do_edit_save($aid, $params)
{
    $iId = cf\api\admin\doAction($aid, $params);
    if (array_key_exists('id', $params)) {
        $iId = $params['id'];
    }
    //update albums
    $pos = cf\query2arrays('SELECT album_id,sort_order FROM cf_gallery_image_in_album WHERE image_id=:id', array('id' => $iId), false, 'album_id');
    cf\execQuery('DELETE FROM cf_gallery_image_in_album WHERE image_id=:id', array('id' => $iId));
    $albums = cf\param::exist('album') ? cf\param::get('album') : array();
    $q = cf\createQuery('INSERT INTO cf_gallery_image_in_album (album_id,image_id,sort_order) VALUES(:albumId,:imageId,:sortOrder)', array('imageId' => $iId));
    foreach ($albums as $albumId) {
        $q->setParam('albumId', $albumId);
        $q->setParam('sortOrder', array_key_exists($albumId, $pos) ? $pos[$albumId]['sort_order'] : 500);
        $q->execute();
    }
}
Example #9
0
 public static function getHierarchy($parentId = null, $showHidden = false, $maxDepth = 0, $path = false, $depth = 1, &$items = array())
 {
     if ($maxDepth && $depth > $maxDepth) {
         return array();
     }
     $parentId = self::getID($parentId);
     if ($path === false) {
         if ($parentId) {
             $parent = self::get($parentId);
             $path = $parent['path'];
         } else {
             $path = '';
         }
     }
     $q = null;
     \cf\createStaticQuery($q, "\n\t\t\tSELECT id, IFNULL(code,id) AS code, IFNULL(permalink,id) AS permalink, parent_id, name, menu_name, image, short_txt, link, hidden, sort_order, title, keywords, descr\n\t\t\tFROM cf_page\n\t\t\tWHERE (parent_id=:parentId OR (:parentId IS NULL AND parent_id IS NULL))\n\t\t\t\t" . ($showHidden ? '' : 'AND (hidden IS NULL OR hidden=0)') . "\n\t\t\tORDER BY sort_order ASC\n\t\t");
     $pages = \cf\query2arrays($q, array('parentId' => $parentId), false, 'id');
     foreach ($pages as $id => $page) {
         $items[$page['code']] = array_merge($page, array('depth' => $depth, 'path' => $path . '/' . $page['permalink'], 'link' => $page['link'] ? $page['link'] : $path . '/' . $page['permalink'], 'children' => self::getHierarchy($id, $showHidden, $maxDepth, $path . '/' . $page['permalink'], $depth + 1)));
     }
     return $items;
 }
Example #10
0
<?php

require_once 'init.php';
require_once cf\Config::path . 'api/shop.php';
$page = cf\api\page\get('products');
$smarty->assign('pageId', $page['id']);
$smarty->assign('pageText', cf\api\page\getText($page['id']));
$categories = cf\api\shop\getCategoriesTree();
$smarty->assign('categories', $categories);
$products = array();
foreach ($categories as $cat) {
    $products[$cat['id']] = cf\api\shop\getProducts($cat['id']);
    foreach ($products[$cat['id']] as &$product) {
        $info = cf\api\shop\getProduct($product[0]);
        $product['attributes'] = $info['attributes'];
    }
}
$smarty->assign('products', $products);
$smarty->assign('reviews', cf\query2arrays("SELECT author, review FROM reviews ORDER BY sort_order LIMIT 4"));
show('products', $page['name'], array(), $page['title'], $page['keywords'], $page['descr']);
Example #11
0
function doAction($id, $params = array())
{
    $user = \cf\User::getLoggedIn();
    //TODO check params by params_id
    foreach ($params as $nm => $v) {
        $params[$nm] = $v ? $v : null;
    }
    $query = \cf\query2var('SELECT query FROM cf_admin_action WHERE id=:id', array('id' => $id));
    $sqlparts = preg_split('/\\s*;\\s*/', $query, -1, PREG_SPLIT_NO_EMPTY);
    foreach ($sqlparts as &$sql) {
        if (preg_match('/^\\s*INSERT\\s+INTO\\s+(\\w+)\\s*$/i', $sql, $match)) {
            //INSERT INTO tname
            $sql = 'INSERT INTO ' . $match[1] . ' (' . implode(',', array_keys($params)) . ') VALUES(:' . implode(',:', array_keys($params)) . ')';
        } else {
            if (preg_match('/^\\s*UPDATE\\s+(\\w+)\\s+(WHERE .+)/i', $sql, $match)) {
                //UPDATE tname WHERE id=:id [AND ... AND ...]
                $names = array();
                foreach ($params as $nm => $v) {
                    $names[] = "{$nm}=:{$nm}";
                }
                $sql = 'UPDATE ' . $match[1] . ' SET ' . implode(',', $names) . ' ' . $match[2];
            }
        }
        eval('$sql="' . $sql . '";');
    }
    $query = implode(';', $sqlparts);
    $fileParams = \cf\query2arrays("\n\t\tSELECT cf_admin_action_param.name AS name, fmt\n\t\tFROM cf_admin_action_param\n\t\tINNER JOIN cf_admin_action_params ON cf_admin_action_param.params_id = cf_admin_action_params.id\n\t\tINNER JOIN cf_admin_action ON cf_admin_action_params.id = cf_admin_action.params_id\n\t\tWHERE cf_admin_action.id=:id AND cf_admin_action_param.type_id='File'", array('id' => $id));
    foreach ($fileParams as $param) {
        $nm = $param['name'];
        if ($params[$nm][0] == "\t") {
            //tab at the beginning: delete file
            @unlink(\cf\Config::root_path . substr($params[$nm], 1));
            $params[$nm] = null;
        }
        if (array_key_exists($nm, $_FILES)) {
            list($uploadDir, $ext) = explode(';', $param['fmt']);
            $fparams = $_FILES[$nm];
            if ($fparams['type'] == 'url') {
                //URL passed
                $url = $fparams['name'];
                $urlInfo = parse_url($url);
                if (in_array($urlInfo['scheme'], stream_get_wrappers())) {
                    //are such URLs supported
                    $fname = pathinfo($urlInfo['path']);
                    if ($ext != '*' && !in_array(strtolower($fname['extension']), explode(',', strtolower($ext)))) {
                        continue;
                        //invalid file type
                    }
                    $path = "{$uploadDir}/" . uniqid($nm) . '.' . $fname['extension'];
                    if (copy($url, \cf\Config::root_path . "{$path}")) {
                        @unlink(\cf\Config::root_path . $params[$nm]);
                        chmod(\cf\Config::root_path . "{$path}", 0644);
                        $params[$nm] = $path;
                    }
                }
            } else {
                //file uploaded
                if (UPLOAD_ERR_OK != $fparams['error'] || !is_uploaded_file($fparams['tmp_name'])) {
                    continue;
                    //if a file is not uploaded check upload_max_filesize or post_max_size in php.ini
                }
                $fname = pathinfo($fparams['name']);
                if ($ext != '*' && !in_array(strtolower($fname['extension']), explode(',', strtolower($ext)))) {
                    continue;
                    //invalid file type
                }
                $path = "{$uploadDir}/" . uniqid($nm) . '.' . $fname['extension'];
                if (move_uploaded_file($fparams['tmp_name'], \cf\Config::root_path . "{$path}")) {
                    @unlink(\cf\Config::root_path . $params[$nm]);
                    chmod(\cf\Config::root_path . "{$path}", 0644);
                    $params[$nm] = $path;
                }
            }
        }
    }
    \cf\execQuery($query, $params);
    global $db;
    return $db->lastInsertId();
}
Example #12
0
<?php

require_once cf\Config::path . 'api/gallery.php';
$smarty->assign('hitsCategory', cf\api\page\get('hits'));
$hits = prepareProducts(cf\api\shop\getProducts('hits', array(), 0, 3));
$smarty->assign('hits', $hits);
$smarty->assign('newCategory', cf\api\page\get('new'));
$new = prepareProducts(cf\api\shop\getProducts('new', array(), 0, 3));
$smarty->assign('new', $new);
$smarty->assign('discountCategory', cf\api\page\get('discount'));
$discount = prepareProducts(cf\api\shop\getProducts('discount', array(), 0, 3));
$smarty->assign('discount', $discount);
$smarty->assign('products', array_merge($hits, $new, $discount));
$smarty->assign('banners', cf\api\gallery\getImages($page['id']));
$smarty->assign('blocks', cf\api\page\getHierarchy($page['id'], true, 1));
$smarty->assign('newslist', cf\query2arrays("\n\tSELECT IFNULL(code,cf_news.id) AS code,name,image,short_txt \n\tFROM cf_news \n\tINNER JOIN cf_news_in_category ON cf_news.id=cf_news_in_category.news_id\n\tWHERE cf_news_in_category.category_id = :pid\n\tORDER BY dt DESC\n", array('pid' => $page['id'])));
Example #13
0
function getList()
{
    $user = \cf\User::getLoggedIn();
    $ids = array();
    if ($user) {
        $cid = create();
        $products = \cf\query2arrays('SELECT product_id, amount FROM cf_products_in_cart WHERE cart_id=:cid', array('cid' => $cid), false, 'product_id');
        $productIDs = array();
        foreach ($products as $id => $p) {
            $productIDs[$id] = $p['amount'];
        }
    } else {
        $c = create();
        $productIDs = $c->getParam('ready');
    }
    $cart = array('contents' => array());
    $total_qty = 0;
    $total_price = 0;
    foreach ($productIDs as $id => $qty) {
        $product = new \cf\Product($id);
        $cart['contents'][$product->id()] = array('product' => $product->toArray(), 'qty' => $qty, 'total' => $product->price() * $qty);
        $total_qty += $qty;
        $total_price += $product->price() * $qty;
    }
    $ruProducts = 'товаров';
    if ($total_qty % 100 < 10 || $total_qty % 100 > 20) {
        if ($total_qty % 10 == 1) {
            $ruProducts = 'товар';
        } else {
            if ($total_qty % 10 > 1 && $total_qty % 10 < 5) {
                $ruProducts = 'товара';
            }
        }
    }
    $cart['ru_products'] = $ruProducts;
    $cart['total'] = array('qty' => $total_qty, 'sum' => $total_price);
    return $cart;
}
Example #14
0
function doAction($id, $params = array())
{
    $user = \cf\User::getLoggedIn();
    $sql = \cf\query2var('SELECT query FROM cf_admin_action WHERE id=:id', array('id' => $id));
    eval('$sql="' . $sql . '";');
    foreach ($params as $nm => $v) {
        $params[$nm] = $v ? $v : null;
    }
    $fileParams = \cf\query2arrays("\n\t\tSELECT cf_admin_action_param.name AS name, fmt\n\t\tFROM cf_admin_action_param\n\t\tINNER JOIN cf_admin_action_params ON cf_admin_action_param.params_id = cf_admin_action_params.id\n\t\tINNER JOIN cf_admin_action ON cf_admin_action_params.id = cf_admin_action.params_id\n\t\tWHERE cf_admin_action.id=:id AND cf_admin_action_param.type_id='File'", array('id' => $id));
    foreach ($fileParams as $param) {
        $nm = $param['name'];
        if ($params[$nm][0] == "\t") {
            //tab at the beginning: delete file
            @unlink(\cf\Config::root_path . substr($params[$nm], 1));
            $params[$nm] = null;
        }
        if (array_key_exists($nm, $_FILES)) {
            list($uploadDir, $ext) = explode(';', $param['fmt']);
            $fparams = $_FILES[$nm];
            if ($fparams['type'] == 'url') {
                //URL passed
                $url = $fparams['name'];
                $urlInfo = parse_url($url);
                if (in_array($urlInfo['scheme'], stream_get_wrappers())) {
                    //are such URLs supported
                    $fname = pathinfo($urlInfo['path']);
                    if ($ext != '*' && !in_array(strtolower($fname['extension']), explode(',', strtolower($ext)))) {
                        continue;
                        //invalid file type
                    }
                    $path = "{$uploadDir}/" . uniqid($nm) . '.' . $fname['extension'];
                    if (copy($url, \cf\Config::root_path . "{$path}")) {
                        @unlink(\cf\Config::root_path . $params[$nm]);
                        chmod(\cf\Config::root_path . "{$path}", 0644);
                        $params[$nm] = $path;
                    }
                }
            } else {
                //file uploaded
                if (UPLOAD_ERR_OK != $fparams['error'] || !is_uploaded_file($fparams['tmp_name'])) {
                    continue;
                    //if a file is not uploaded check upload_max_filesize or post_max_size in php.ini
                }
                $fname = pathinfo($fparams['name']);
                if ($ext != '*' && !in_array(strtolower($fname['extension']), explode(',', strtolower($ext)))) {
                    continue;
                    //invalid file type
                }
                $path = "{$uploadDir}/" . uniqid($nm) . '.' . $fname['extension'];
                if (move_uploaded_file($fparams['tmp_name'], \cf\Config::root_path . "{$path}")) {
                    @unlink(\cf\Config::root_path . $params[$nm]);
                    chmod(\cf\Config::root_path . "{$path}", 0644);
                    $params[$nm] = $path;
                }
            }
        }
    }
    \cf\execQuery($sql, $params);
    global $db;
    return $db->lastInsertId();
}
Example #15
0
function getImages($albumId, $showHidden = false)
{
    $albumId = getAlbumID($albumId);
    return \cf\query2arrays("\r\n\t\tSELECT cf_gallery_images.id AS id, IFNULL(code,cf_gallery_images.id) AS code, name, image, short_descr, hidden, url\r\n\t\tFROM cf_gallery_images\r\n\t\tINNER JOIN cf_gallery_image_in_album ON cf_gallery_images.id=cf_gallery_image_in_album.image_id\r\n\t\tWHERE cf_gallery_image_in_album.album_id=:aid\r\n\t\tORDER BY sort_order", array('aid' => $albumId));
}
Example #16
0
function getList()
{
    $user = \cf\User::getLoggedIn();
    $ids = array();
    if ($user) {
        $cid = create();
        $products = \cf\query2arrays('SELECT product_id, amount FROM cf_products_in_cart WHERE cart_id=:cid', array('cid' => $cid), false, 'product_id');
        $productIDs = array();
        foreach ($products as $id => $p) {
            $productIDs[$id] = $p['amount'];
        }
    } else {
        $c = create();
        $productIDs = $c->getParam('ready');
    }
    $cart = array();
    $total_number = 0;
    $total_price = 0;
    foreach ($productIDs as $id => $amount) {
        $product = new \cf\Product($id);
        $cart[] = array('id' => $product->id(), 'name' => $product->fullName(), 'amount' => $amount, 'price' => $product->price(), 'image' => $product->image(), 'manufacturerName' => $product->manufacturerName(), 'total_price' => $product->price() * $amount, 'attributes' => $product->attributes()->values());
        $total_number += $amount;
        $total_price += $product->price() * $amount;
    }
    $ruProducts = 'товаров';
    if ($total_number % 100 < 10 || $total_number % 100 > 20) {
        if ($total_number % 10 == 1) {
            $ruProducts = 'товар';
        } else {
            if ($total_number % 10 > 1 && $total_number % 10 < 5) {
                $ruProducts = 'товара';
            }
        }
    }
    return array_merge(array(array('total_amount' => $total_number, 'number' => $total_number, 'total_price' => $total_price, 'sum' => $total_price, 'ru_products' => $ruProducts)), $cart);
}