示例#1
0
function generate_currency_cache($load = false)
{
    global $mysql, $config;
    $eshop_dir = get_plugcfg_dir('eshop');
    if (!file_exists($eshop_dir . '/cache_currency.php') or $load) {
        $currency_link = checkLinkAvailable('eshop', 'currency') ? generateLink('eshop', 'currency', array()) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'currency'), array());
        $currency_tEntry = array();
        foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_currencies WHERE enabled = 1 ORDER BY position, id") as $row) {
            $row['currency_link'] = $currency_link . "?id=" . $row['id'];
            $currency_tEntry[] = $row;
        }
        file_put_contents($eshop_dir . '/cache_currency.php', serialize($currency_tEntry));
    }
}
示例#2
0
function link_eshop()
{
    $eshopURL = checkLinkAvailable('eshop', '') ? generateLink('eshop', '') : generateLink('core', 'plugin', array('plugin' => 'eshop'));
    return $eshopURL;
}
示例#3
0
function automation()
{
    global $tpl, $mysql, $twig;
    $tpath = locatePluginTemplates(array('config/main', 'config/automation'), 'eshop', 1);
    if (isset($_REQUEST['yml_url']) && !empty($_REQUEST['yml_url']) && isset($_REQUEST['import'])) {
        import_yml($_REQUEST['yml_url']);
        //$import_str = implode('<br/>',$_SESSION['import_yml']);
        //$info = "Импорт YML успешно завершен<br/><br/>".$import_str;
        $info = "Импорт YML успешно завершен";
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['currency'])) {
        $rates_str = update_currency();
        $info = "Валюты обновлены<br/><br/>" . $rates_str;
        msg(array("type" => "info", "info" => $info));
    }
    $xt = $twig->loadTemplate($tpath['config/automation'] . 'config/' . 'automation.tpl');
    $yml_export_link = checkLinkAvailable('eshop', 'yml_export') ? generateLink('eshop', 'yml_export', array()) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'yml_export'), array());
    $tVars = array('yml_export_link' => $yml_export_link, 'info' => '');
    $xg = $twig->loadTemplate($tpath['config/main'] . 'config/' . 'main.tpl');
    $tVars = array('entries' => $xt->render($tVars), 'php_self' => $PHP_SELF, 'plugin_url' => admin_url . '/admin.php?mod=extra-config&plugin=eshop', 'skins_url' => skins_url, 'admin_url' => admin_url, 'home' => home, 'current_title' => 'Автоматизация');
    print $xg->render($tVars);
}
示例#4
0
function plugin_block_eshop($number, $mode, $cat, $overrideTemplateName, $cacheExpire)
{
    global $config, $mysql, $tpl, $template, $twig, $twigLoader, $langMonths, $lang, $TemplateCache;
    // Prepare keys for cacheing
    $cacheKeys = array();
    $cacheDisabled = false;
    $conditions = array();
    if (isset($cat) && !empty($cat)) {
        array_push($conditions, "c.id IN (" . $cat . ") ");
    }
    array_push($conditions, "p.active = 1");
    if ($number < 1 || $number > 100) {
        $number = 5;
    }
    switch ($mode) {
        case 'view':
            $orderby = " ORDER BY p.view DESC ";
            break;
        case 'last':
            $orderby = " ORDER BY p.editdate DESC ";
            break;
        case 'stocked':
            array_push($conditions, "p.stocked = 1");
            $orderby = " ORDER BY p.editdate DESC ";
            break;
        case 'featured':
            array_push($conditions, "p.featured = 1");
            $orderby = " ORDER BY p.editdate DESC ";
            break;
        case 'rnd':
            $cacheDisabled = true;
            $orderby = " ORDER BY RAND() DESC ";
            break;
        default:
            $mode = 'last';
            $orderby = " ORDER BY p.editdate DESC ";
            break;
    }
    $fSort = " GROUP BY p.id " . $orderby . " LIMIT " . $number;
    $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
    $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.url as curl, c.name AS category " . $sqlQPart;
    $tEntries = array();
    foreach ($mysql->select($sqlQ) as $row) {
        $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
        $tEntries[$row['id']] = array('id' => $row['id'], 'code' => $row['code'], 'name' => $row['name'], 'category' => $row['category'], 'active' => $row['active'], 'featured' => $row['featured'], 'stocked' => $row['stocked'], 'position' => $row['position'], 'date' => $row['date'], 'editdate' => $row['editdate'], 'edit_link' => "?mod=extra-config&plugin=eshop&action=edit_product&id=" . $row['id'] . "", 'view_link' => $view_link);
    }
    $entries_array_ids = array_keys($tEntries);
    if (isset($entries_array_ids) && !empty($entries_array_ids)) {
        $entries_string_ids = implode(',', $entries_array_ids);
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $entries_string_ids . ') ORDER BY i.position, i.id') as $irow) {
            $tEntries[$irow['product_id']]['images'][] = $irow;
        }
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $entries_string_ids . ') ORDER BY v.position, v.id') as $vrow) {
            $tEntries[$vrow['product_id']]['variants'][] = $vrow;
        }
    }
    if ($overrideTemplateName) {
        $templateName = 'block/' . $overrideTemplateName;
    } else {
        $templateName = 'block/block_eshop';
    }
    // Determine paths for all template files
    $tpath = locatePluginTemplates(array($templateName), 'eshop', pluginGetVariable('eshop', 'localsource'));
    // Preload template configuration variables
    @templateLoadVariables();
    $cacheKeys[] = '|number=' . $number;
    $cacheKeys[] = '|mode=' . $mode;
    $cacheKeys[] = '|cat=' . $cat;
    $cacheKeys[] = '|templateName=' . $templateName;
    // Generate cache file name [ we should take into account SWITCHER plugin ]
    $cacheFileName = md5('eshop' . $config['theme'] . $templateName . $config['default_lang'] . join('', $cacheKeys)) . '.txt';
    if (!$cacheDisabled && $cacheExpire > 0) {
        $cacheData = cacheRetrieveFile($cacheFileName, $cacheExpire, 'eshop');
        if ($cacheData != false) {
            // We got data from cache. Return it and stop
            return $cacheData;
        }
    }
    $tVars['mode'] = $mode;
    $tVars['number'] = $number;
    $tVars['entries'] = $tEntries;
    $tVars['tpl_url'] = tpl_url;
    $tVars['home'] = home;
    $xt = $twig->loadTemplate($tpath[$templateName] . $templateName . '.tpl');
    $output = $xt->render($tVars);
    if (!$cacheDisabled && $cacheExpire > 0) {
        cacheStoreFile($cacheFileName, $output, 'eshop');
    }
    return $output;
}
示例#5
0
 function onShow(&$output)
 {
     global $userROW, $mysql, $twig;
     if (pluginGetVariable('eshop', 'integrate_gsmg') == "1") {
         $lm = $mysql->record("select date(from_unixtime(max(date))) as pd from " . prefix . "_eshop_products");
         foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_categories ORDER BY position, id") as $rows) {
             $cat_link = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $rows['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $rows['url']));
             $new_output .= "<url>";
             $new_output .= "<loc>" . home . $cat_link . "</loc>";
             $new_output .= "<priority>" . floatval(pluginGetVariable('gsmg', 'catp_pr')) . "</priority>";
             $new_output .= "<lastmod>" . $lm['pd'] . "</lastmod>";
             $new_output .= "<changefreq>daily</changefreq>";
             $new_output .= "</url>";
         }
         $query = "select * from " . prefix . "_eshop_products where active = 1 order by id desc";
         foreach ($mysql->select($query) as $rec) {
             $link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rec['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rec['url']));
             $new_output .= "<url>";
             $new_output .= "<loc>" . home . $link . "</loc>";
             $new_output .= "<priority>" . floatval(pluginGetVariable('gsmg', 'news_pr')) . "</priority>";
             $new_output .= "<lastmod>" . strftime("%Y-%m-%d", max($rec['editdate'], $rec['date'])) . "</lastmod>";
             $new_output .= "<changefreq>daily</changefreq>";
             $new_output .= "</url>";
         }
         $output = $output . $new_output;
     }
 }
示例#6
0
function automation()
{
    global $tpl, $mysql, $twig;
    $tpath = locatePluginTemplates(array('config/main', 'config/automation'), 'eshop', 1);
    if (isset($_REQUEST['yml_url']) && !empty($_REQUEST['yml_url']) && isset($_REQUEST['import'])) {
        import_yml($_REQUEST['yml_url']);
        //$import_str = implode('<br/>',$_SESSION['import_yml']);
        //$info = "Импорт YML успешно завершен<br/><br/>".$import_str;
        $info = "Импорт YML успешно завершен";
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['currency'])) {
        $rates_str = update_currency();
        $info = "Валюты обновлены<br/><br/>" . $rates_str;
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['change_price'])) {
        $change_price_type = intval($_REQUEST['change_price_type']);
        $change_price_qnt = intval($_REQUEST['change_price_qnt']);
        update_prices($change_price_type, $change_price_qnt);
        $info = "Цены обновлены<br/>";
        msg(array("type" => "info", "info" => $info));
    }
    if (isset($_REQUEST['export_csv'])) {
        $SUPRESS_TEMPLATE_SHOW = 1;
        $SUPRESS_MAINBLOCK_SHOW = 1;
        require_once dirname(__FILE__) . '/csv_lib/CsvImportInterface.php';
        require_once dirname(__FILE__) . '/csv_lib/CsvImport.php';
        require_once dirname(__FILE__) . '/csv_lib/CsvExportInterface.php';
        require_once dirname(__FILE__) . '/csv_lib/CsvExport.php';
        $export = new CsvExport();
        $cat_array = array();
        foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_categories ORDER BY position ASC') as $cat_row) {
            $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('cat' => $cat_row['id'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('cat' => $cat_row['id']));
            $cat_array[] = array('id' => $cat_row['id'], 'url' => $cat_row['url'], 'image' => $cat_row['image'], 'name' => $cat_row['name'], 'description' => $cat_row['description'], 'parent_id' => $cat_row['parent_id'], 'position' => $cat_row['position'], 'meta_title' => $cat_row['meta_title'], 'meta_keywords' => $cat_row['meta_keywords'], 'meta_description' => $cat_row['meta_description'], 'link' => $catlink);
        }
        $conditions = array();
        array_push($conditions, "p.active = 1");
        //$limitCount = "10000";
        $fSort = " GROUP BY p.id ORDER BY p.id DESC ";
        $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
        $sqlQ = "SELECT p.id AS id, p.url AS url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.name AS category " . $sqlQPart;
        $entries = array();
        foreach ($mysql->select($sqlQ) as $row) {
            $entriesImg = array();
            foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id = ' . $row['id'] . ' ') as $row2) {
                $entriesImg[] = $row2['filepath'];
            }
            $entriesVariants = array();
            foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id = ' . $row['id'] . ' ') as $vrow) {
                $entriesVariants[] = $vrow;
            }
            $options_array = array();
            foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_options LEFT JOIN " . prefix . "_eshop_features ON " . prefix . "_eshop_features.id=" . prefix . "_eshop_options.feature_id WHERE " . prefix . "_eshop_options.product_id = " . $row['id'] . " ORDER BY position, id") as $orow) {
                $options_array[$orow['id']] = $orow['value'];
            }
            $xf_name_id = array();
            $features_array = array();
            foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_features ORDER BY position, id") as $frow) {
                $frow['value'] = $options_array[$frow['id']];
                $frow['foptions'] = json_decode($frow['foptions'], true);
                foreach ($frow['foptions'] as $key => $value) {
                    $frow['foptions'][$key] = iconv("utf-8", "windows-1251", $value);
                }
                $features_array["xfields_" . $frow['name']] = $frow['value'];
                $xf_name_id[$frow['name']] = $frow['id'];
            }
            $images_comma_separated = implode(",", $entriesImg);
            $entry = array();
            $entry = array('id' => $row['id'], 'code' => $row['code'], 'url' => $row['url'], 'name' => $row['name'], 'variants' => $entriesVariants, 'annotation' => $row['annotation'], 'body' => $row['body'], 'active' => $row['active'], 'featured' => $row['featured'], 'stocked' => $row['stocked'], 'meta_title' => $row['meta_title'], 'meta_keywords' => $row['meta_keywords'], 'meta_description' => $row['meta_description'], 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'cat_name' => $row['category'], 'cid' => $row['cid'], 'images' => $images_comma_separated);
            foreach ($features_array as $fk => $fv) {
                $entry[$fk] = $fv;
            }
            $entries[] = $entry;
        }
        $count = 0;
        foreach ($entries as $entry) {
            foreach ($entry['variants'] as $variant) {
                $entry_row = array();
                $entry_row = $entry;
                unset($entry_row['variants']);
                $entry_row['v_id'] = $variant['id'];
                $entry_row['v_sku'] = $variant['sku'];
                $entry_row['v_name'] = $variant['name'];
                $entry_row['v_price'] = $variant['price'];
                $entry_row['v_compare_price'] = $variant['compare_price'];
                $entry_row['v_stock'] = $variant['stock'];
                $entry_row['v_amount'] = $variant['amount'];
                if ($count == 0) {
                    $export->setHeader(array_keys($entry_row));
                }
                $count += 1;
                $export->append(array($entry_row));
                unset($entry_row);
            }
        }
        $export->export('products.csv', ';');
        die;
    }
    if (isset($_REQUEST['import_csv'])) {
        $SUPRESS_TEMPLATE_SHOW = 1;
        $SUPRESS_MAINBLOCK_SHOW = 1;
        if (is_uploaded_file($_FILES["filename"]["tmp_name"])) {
            require_once dirname(__FILE__) . '/csv_lib/CsvImportInterface.php';
            require_once dirname(__FILE__) . '/csv_lib/CsvImport.php';
            require_once dirname(__FILE__) . '/csv_lib/CsvExportInterface.php';
            require_once dirname(__FILE__) . '/csv_lib/CsvExport.php';
            $import = new CsvImport();
            $filepath = dirname(__FILE__) . "/import/" . $_FILES["filename"]["name"];
            move_uploaded_file($_FILES["filename"]["tmp_name"], $filepath);
            $import->setFile($filepath, 10000, ";");
            $items = $import->getRows();
            $xf_name_id = array();
            foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_features ORDER BY position, id") as $frow) {
                $xf_name_id[$frow['name']] = $frow['id'];
            }
            foreach ($items as $iv) {
                $current_time = time();
                $id = $iv['id'];
                $code = empty($iv['code']) ? "" : $iv['code'];
                $url = empty($iv['url']) ? "" : $iv['url'];
                $name = empty($iv['name']) ? "" : $iv['name'];
                $v_id = empty($iv['v_id']) ? "" : $iv['v_id'];
                $v_sku = empty($iv['v_sku']) ? "" : $iv['v_sku'];
                $v_name = empty($iv['v_name']) ? "" : $iv['v_name'];
                $v_price = empty($iv['v_price']) ? "" : $iv['v_price'];
                $v_compare_price = empty($iv['v_compare_price']) ? "" : $iv['v_compare_price'];
                $v_stock = empty($iv['v_stock']) ? "" : $iv['v_stock'];
                $v_amount = empty($iv['v_amount']) ? "" : $iv['v_amount'];
                if ($v_amount == '') {
                    $v_amount = 'NULL';
                }
                $annotation = empty($iv['annotation']) ? "" : $iv['annotation'];
                $body = empty($iv['body']) ? "" : $iv['body'];
                $active = empty($iv['active']) ? "1" : $iv['active'];
                $featured = empty($iv['featured']) ? "0" : $iv['featured'];
                $stocked = empty($iv['stocked']) ? "0" : $iv['stocked'];
                $meta_title = empty($iv['meta_title']) ? "" : $iv['meta_title'];
                $meta_keywords = empty($iv['meta_keywords']) ? "" : $iv['meta_keywords'];
                $meta_description = empty($iv['meta_description']) ? "" : $iv['meta_description'];
                $date = empty($iv['date']) ? $current_time : $iv['date'];
                $editdate = empty($iv['editdate']) ? $current_time : $iv['editdate'];
                $cat_name = empty($iv['cat_name']) ? "" : $iv['cat_name'];
                $cid = empty($iv['cid']) ? "0" : $iv['cid'];
                //$images = explode(',',$iv['images']);
                $xfields_items = array();
                foreach ($iv as $xfk => $xfv) {
                    preg_match("/xfields_/", $xfk, $find_xf);
                    if (isset($find_xf[0])) {
                        $xf_name = str_replace('xfields_', '', $xfk);
                        $xf_id = $xf_name_id[$xf_name];
                        $xfields_items[$xf_id] = $xfv;
                    }
                }
                if ($iv['id'] != "") {
                    $product_row = $mysql->record("SELECT * FROM " . prefix . "_eshop_products WHERE id=" . db_squote($iv['id']) . " ");
                    if (empty($product_row)) {
                        if ($url != "") {
                            if (!is_array($mysql->record("select id from " . prefix . "_eshop_products where url = " . db_squote($product_row["url"]) . " limit 1"))) {
                                $mysql->query("INSERT INTO " . prefix . "_eshop_products (`id`, `code`, `url`, `name`, `annotation`, `body`, `active`, `featured`, `stocked`, `meta_title`, `meta_keywords`, `meta_description`, `date`, `editdate`) VALUES ('{$id}','{$code}','{$url}','{$name}','{$annotation}','{$body}','{$active}','{$featured}','{$stocked}','{$meta_title}','{$meta_keywords}','{$meta_description}','{$date}','{$editdate}')");
                                $qid = $mysql->lastid('eshop_products');
                                import_upload_images($qid);
                                if (!empty($xfields_items)) {
                                    foreach ($xfields_items as $f_key => $f_value) {
                                        if ($f_value != '') {
                                            $mysql->query("INSERT INTO " . prefix . "_eshop_options (`product_id`, `feature_id`, `value`) VALUES ('{$qid}','{$f_key}','{$f_value}')");
                                        }
                                    }
                                }
                                $category_id = intval($cid);
                                if ($category_id != 0) {
                                    $mysql->query("INSERT INTO " . prefix . "_eshop_products_categories (`product_id`, `category_id`) VALUES ('{$qid}','{$category_id}')");
                                }
                                $mysql->query("INSERT INTO " . prefix . "_eshop_variants (`product_id`, `sku`, `name`, `price`, `compare_price`, `stock`, `amount`) VALUES ('{$qid}', '{$v_sku}', '{$v_name}', '{$v_price}', '{$v_compare_price}', '{$v_stock}', '{$v_amount}')");
                            }
                        }
                    } else {
                        if ($product_row["url"]) {
                            if (is_array($mysql->record("select id from " . prefix . "_eshop_products where url = " . db_squote($url) . " limit 1"))) {
                                $mysql->query("REPLACE INTO " . prefix . "_eshop_products (`id`, `code`, `url`, `name`, `annotation`, `body`, `active`, `featured`, `stocked`, `meta_title`, `meta_keywords`, `meta_description`, `date`, `editdate`) VALUES ('{$id}','{$code}','{$url}','{$name}','{$annotation}','{$body}','{$active}','{$featured}','{$stocked}','{$meta_title}','{$meta_keywords}','{$meta_description}','{$date}','{$editdate}')");
                                $qid = $product_row["id"];
                                import_upload_images($qid);
                                if (!empty($xfields_items)) {
                                    //$mysql->query("DELETE FROM ".prefix."_eshop_options WHERE product_id='$qid'");
                                    foreach ($xfields_items as $f_key => $f_value) {
                                        if ($f_value != '') {
                                            $mysql->query("REPLACE INTO " . prefix . "_eshop_options (`product_id`, `feature_id`, `value`) VALUES ('{$qid}','{$f_key}','{$f_value}')");
                                        }
                                    }
                                }
                                $category_id = intval($cid);
                                if ($category_id != 0) {
                                    //$mysql->query("DELETE FROM ".prefix."_eshop_products_categories WHERE product_id='$qid'");
                                    $mysql->query("REPLACE INTO " . prefix . "_eshop_products_categories (`product_id`, `category_id`) VALUES ('{$qid}','{$category_id}')");
                                } else {
                                    $mysql->query("DELETE FROM " . prefix . "_eshop_products_categories WHERE product_id='{$qid}'");
                                }
                                $SQLv = array();
                                $SQLv['product_id'] = $qid;
                                $SQLv['sku'] = $v_sku;
                                $SQLv['name'] = $v_name;
                                $SQLv['price'] = $v_price;
                                $SQLv['compare_price'] = $v_compare_price;
                                $SQLv['stock'] = $v_stock;
                                $SQLv['amount'] = $v_amount;
                                foreach ($SQLv as $k => $v) {
                                    $vnames[] = $k . ' = ' . db_squote($v);
                                }
                                if ($v_id != "") {
                                    $mysql->query('UPDATE ' . prefix . '_eshop_variants SET ' . implode(', ', $vnames) . ' WHERE id = \'' . intval($v_id) . '\'  ');
                                } else {
                                    $mysql->query("INSERT INTO " . prefix . "_eshop_variants (`product_id`, `sku`, `name`, `price`, `compare_price`, `stock`, `amount`) VALUES ('{$qid}', '{$v_sku}', '{$v_name}', '{$v_price}', '{$v_compare_price}', '{$v_stock}', '{$v_amount}')");
                                }
                                //$mysql->query("DELETE FROM ".prefix."_eshop_variants WHERE product_id='$qid'");
                                //$mysql->query("INSERT INTO ".prefix."_eshop_variants (`product_id`, `price`, `compare_price`, `stock`) VALUES ('$qid', '$price', '$compare_price', '$stock')");
                            }
                        }
                    }
                } else {
                    $mysql->query("INSERT INTO " . prefix . "_eshop_products (`code`, `url`, `name`, `annotation`, `body`, `active`, `featured`, `stocked`, `meta_title`, `meta_keywords`, `meta_description`, `date`, `editdate`) VALUES ('{$code}','{$url}','{$name}','{$annotation}','{$body}','{$active}','{$featured}','{$stocked}','{$meta_title}','{$meta_keywords}','{$meta_description}','{$date}','{$editdate}')");
                    $qid = $mysql->lastid('eshop_products');
                    import_upload_images($qid);
                    if (!empty($xfields_items)) {
                        foreach ($xfields_items as $f_key => $f_value) {
                            if ($f_value != '') {
                                $mysql->query("INSERT INTO " . prefix . "_eshop_options (`product_id`, `feature_id`, `value`) VALUES ('{$qid}','{$f_key}','{$f_value}')");
                            }
                        }
                    }
                    $category_id = intval($cid);
                    if ($category_id != 0) {
                        $mysql->query("INSERT INTO " . prefix . "_eshop_products_categories (`product_id`, `category_id`) VALUES ('{$qid}','{$category_id}')");
                    }
                    $mysql->query("INSERT INTO " . prefix . "_eshop_variants (`product_id`, `sku`, `name`, `price`, `compare_price`, `stock`, `amount`) VALUES ('{$qid}', '{$v_sku}', '{$v_name}', '{$v_price}', '{$v_compare_price}', '{$v_stock}', '{$v_amount}')");
                }
            }
            unlink($filepath);
            $info = "Импорт CSV завершен<br/>";
            msg(array("type" => "info", "info" => $info));
            die;
        } else {
            $info = "Ошибка загрузки файла<br/>";
            msg(array("type" => "info", "info" => $info));
            die;
        }
    }
    if (isset($_REQUEST['multiple_upload_images'])) {
        $images = $_REQUEST['data']['images'];
        if ($images != NULL) {
            foreach ($images as $inx_img => $img) {
                $img_parts = explode(".", $img);
                $img_s = explode("_", $img_parts[0]);
                $qid = $img_s[0];
                if ($qid != "") {
                    $prd_row = $mysql->record("select * from " . prefix . "_eshop_products where id = " . db_squote($qid) . " limit 1");
                    if (!is_array($prd_row)) {
                        break;
                    }
                    $positions_img = array();
                    foreach ($mysql->select("SELECT * FROM " . prefix . "_eshop_images WHERE product_id = '{$qid}' ORDER BY position, id") as $irow) {
                        $positions_img[] = $irow['position'];
                    }
                    if (!empty($positions_img)) {
                        $max_img_pos = max($positions_img) + 1;
                    } else {
                        $max_img_pos = 0;
                    }
                    $inx_img = $max_img_pos;
                    @mkdir($_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/', 0777);
                    @mkdir($_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/thumb', 0777);
                    $timestamp = time();
                    $iname = $timestamp . "-" . $img;
                    $temp_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/temp/' . $img;
                    $current_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/' . $iname;
                    rename($temp_name, $current_name);
                    $temp_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/temp/thumb/' . $img;
                    $current_name = $_SERVER['DOCUMENT_ROOT'] . '/uploads/eshop/products/' . $qid . '/thumb/' . $iname;
                    rename($temp_name, $current_name);
                    $mysql->query("INSERT INTO " . prefix . "_eshop_images (`filepath`, `product_id`, `position`) VALUES ('{$iname}','{$qid}','{$inx_img}')");
                }
            }
        }
        $info = "Изображения загружены<br/>";
        msg(array("type" => "info", "info" => $info));
    }
    $xt = $twig->loadTemplate($tpath['config/automation'] . 'config/' . 'automation.tpl');
    $yml_export_link = checkLinkAvailable('eshop', 'yml_export') ? generateLink('eshop', 'yml_export', array()) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'yml_export'), array());
    $tVars = array('yml_export_link' => $yml_export_link, 'info' => '');
    $xg = $twig->loadTemplate($tpath['config/main'] . 'config/' . 'main.tpl');
    $tVars = array('entries' => $xt->render($tVars), 'php_self' => $PHP_SELF, 'plugin_url' => admin_url . '/admin.php?mod=extra-config&plugin=eshop', 'skins_url' => skins_url, 'admin_url' => admin_url, 'home' => home, 'current_title' => 'Автоматизация');
    print $xg->render($tVars);
}
示例#7
0
function main_prd($params)
{
    global $tpl, $template, $twig, $SYSTEM_FLAGS, $config, $userROW, $mysql, $twigLoader;
    $results = array();
    $params = arrayCharsetConvert(1, $params);
    $number = $params['number'];
    $mode = $params['mode'];
    $cat = $params['cat'];
    $overrideTemplateName = $params['template'];
    $prd_per_page = $number;
    $page = $params['page'];
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO compare ****
        case 'show':
            $conditions = array();
            if (isset($cat) && !empty($cat)) {
                array_push($conditions, "c.id IN (" . $cat . ") ");
            }
            array_push($conditions, "p.active = 1");
            if ($number < 1 || $number > 100) {
                $number = 5;
            }
            switch ($mode) {
                case 'view':
                    $orderby = " ORDER BY p.view DESC ";
                    break;
                case 'last':
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'stocked':
                    array_push($conditions, "p.stocked = 1");
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'featured':
                    array_push($conditions, "p.featured = 1");
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
                case 'rnd':
                    $cacheDisabled = true;
                    $orderby = " ORDER BY RAND() DESC ";
                    break;
                default:
                    $mode = 'last';
                    $orderby = " ORDER BY p.editdate DESC ";
                    break;
            }
            $fSort = " " . $orderby;
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQCount = "SELECT COUNT(p.id) " . $sqlQPart;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.annotation AS annotation, p.body AS body, p.active AS active, p.featured AS featured, p.stocked AS stocked, p.position AS position, p.meta_title AS meta_title, p.meta_keywords AS meta_keywords, p.meta_description AS meta_description, p.date AS date, p.editdate AS editdate, p.views AS views, c.id AS cid, c.url as curl, c.name AS category " . $sqlQPart;
            $entries = array();
            $pageNo = intval($page) ? $page : 0;
            if ($pageNo < 1) {
                $pageNo = 1;
            }
            if (!$start_from) {
                $start_from = ($pageNo - 1) * $prd_per_page;
            }
            $count = $mysql->result($sqlQCount);
            $countPages = ceil($count / $prd_per_page);
            $cmp_array = array();
            foreach ($SYSTEM_FLAGS["eshop"]["compare"]["entries"] as $cmp_row) {
                $cmp_array[] = $cmp_row['linked_fld'];
            }
            foreach ($mysql->select($sqlQ . ' LIMIT ' . $start_from . ', ' . $prd_per_page) as $row) {
                $fulllink = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
                $catlink = checkLinkAvailable('eshop', '') ? generateLink('eshop', '', array('alt' => $row['curl'])) : generateLink('core', 'plugin', array('plugin' => 'eshop'), array('alt' => $row['curl']));
                $cmp_flag = in_array($row['id'], $cmp_array);
                $entries[$row['id']] = array('id' => $row['id'], 'code' => $row['code'], 'name' => $row['name'], 'annotation' => $row['annotation'], 'body' => $row['body'], 'active' => $row['active'], 'featured' => $row['featured'], 'meta_title' => $row['meta_title'], 'meta_keywords' => $row['meta_keywords'], 'meta_description' => $row['meta_description'], 'fulllink' => $fulllink, 'date' => empty($row['date']) ? '' : $row['date'], 'editdate' => empty($row['editdate']) ? '' : $row['editdate'], 'views' => $row['views'], 'cat_name' => $row['category'], 'cid' => $row['cid'], 'catlink' => $catlink, 'compare' => $cmp_flag, 'home' => home, 'tpl_url' => home . '/templates/' . $config['theme']);
            }
            $entries_array_ids = array_keys($entries);
            if (isset($entries_array_ids) && !empty($entries_array_ids)) {
                $entries_string_ids = implode(',', $entries_array_ids);
                foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_images i WHERE i.product_id IN (' . $entries_string_ids . ') ORDER BY i.position, i.id') as $irow) {
                    $entries[$irow['product_id']]['images'][] = $irow;
                }
                foreach ($mysql->select('SELECT * FROM ' . prefix . '_eshop_variants v WHERE v.product_id IN (' . $entries_string_ids . ') ORDER BY v.position, v.id') as $vrow) {
                    $entries[$vrow['product_id']]['variants'][] = $vrow;
                }
            }
            $tVars = array('info' => isset($info) ? $info : '', 'entries' => isset($entries) ? $entries : '', 'tpl_url' => home . '/templates/' . $config['theme'], 'tpl_home' => admin_url);
            if ($overrideTemplateName) {
                $templateName = 'block/' . $overrideTemplateName;
            } else {
                $templateName = 'block/main_block_eshop';
            }
            // Determine paths for all template files
            $tpath = locatePluginTemplates(array($templateName), 'eshop', pluginGetVariable('eshop', 'localsource'));
            // Preload template configuration variables
            @templateLoadVariables();
            $tVars['mode'] = $mode;
            $tVars['number'] = $number;
            $tVars['tpl_url'] = tpl_url;
            $tVars['home'] = home;
            $tVars['pagesss'] = generateLP(array('current' => $pageNo, 'count' => $countPages, 'url' => '#', 'tpl' => $templateName . '_pages'));
            $xt = $twig->loadTemplate($tpath[$templateName] . $templateName . '.tpl');
            if (empty($row)) {
                $results = array('prd_main' => 2, 'prd_main_text' => iconv('Windows-1251', 'UTF-8', 'Нет продукции!'), 'prd_main_pages_text' => iconv('Windows-1251', 'UTF-8', ''));
            } else {
                $results = array('prd_main' => 100, 'prd_main_text' => iconv('Windows-1251', 'UTF-8', $xt->render($tVars)), 'prd_main_pages_text' => iconv('Windows-1251', 'UTF-8', $tVars['pagesss']));
            }
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => $results);
}
示例#8
0
function ebasket_rpc_manage($params)
{
    global $userROW, $DSlist, $mysql, $twig;
    LoadPluginLibrary('xfields', 'common');
    if (!is_array($params) || !isset($params['action'])) {
        return array('status' => 0, 'errorCode' => 1, 'errorText' => 'Activity mode is not set');
    }
    $params = arrayCharsetConvert(1, $params);
    switch ($params['action']) {
        // **** ADD NEW ITEM INTO ebasket ****
        case 'add':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'ebasket can be used only for NEWS');
            }
            // Check available DataSources
            if ($count < 1) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'Count should be positive');
            }
            // Check if linked item is available
            switch ($linked_ds) {
                case $DSlist['news']:
                    $conditions = array();
                    if ($linked_id) {
                        array_push($conditions, "p.id = " . db_squote($linked_id));
                    }
                    $fSort = " GROUP BY p.id ORDER BY p.id DESC";
                    $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
                    $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
                    // Retrieve news record
                    $rec = $mysql->record($sqlQ);
                    if (!is_array($rec)) {
                        return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
                    }
                    $btitle = $rec['name'];
                    $price = $rec['price'];
                    $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $rec['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $rec['url']));
                    $rec['view_link'] = $view_link;
                    // Add data into basked
                    return ebasket_add_item($linked_ds, $linked_id, $btitle, $price, $count, array('item' => $rec));
                    break;
            }
            break;
        case 'update_count':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            $count = intval($params['count']);
            return basket_update_item_count($id, $linked_ds, $linked_id, $count);
            break;
        case 'delete':
            $id = intval($params['id']);
            $linked_ds = intval($params['linked_ds']);
            $linked_id = intval($params['linked_id']);
            return basket_delete_item($id, $linked_ds, $linked_id);
            break;
        case 'add_fast':
            $linked_ds = intval($params['ds']);
            $linked_id = intval($params['id']);
            $count = intval($params['count']);
            $type = intval($params['type']);
            $order['name'] = filter_var($params['name'], FILTER_SANITIZE_STRING);
            if (empty($order['name'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $order['email'] = "";
            $order['phone'] = filter_var($params['phone'], FILTER_SANITIZE_STRING);
            if (empty($order['phone'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $order['address'] = filter_var($params['address'], FILTER_SANITIZE_STRING);
            if (empty($order['address'])) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            // Check available DataSources
            if (!in_array($linked_ds, array($DSlist['news']))) {
                return array('status' => 0, 'errorCode' => 2, 'errorText' => 'ebasket can be used only for NEWS');
            }
            // Check available DataSources
            if ($count < 1) {
                $count = 1;
            }
            $conditions = array();
            if ($linked_id) {
                array_push($conditions, "p.id = " . db_squote($linked_id));
            }
            $fSort = " GROUP BY p.id ORDER BY p.id DESC";
            $sqlQPart = "FROM " . prefix . "_eshop_products p LEFT JOIN " . prefix . "_eshop_products_categories pc ON p.id = pc.product_id LEFT JOIN " . prefix . "_eshop_categories c ON pc.category_id = c.id LEFT JOIN (SELECT * FROM " . prefix . "_eshop_images ORDER BY position, id) i ON i.product_id = p.id LEFT JOIN " . prefix . "_eshop_variants v ON p.id = v.product_id " . (count($conditions) ? "WHERE " . implode(" AND ", $conditions) : '') . $fSort;
            $sqlQ = "SELECT p.id AS id, p.url as url, p.code AS code, p.name AS name, p.active AS active, p.featured AS featured, p.position AS position, c.url as curl, c.name AS category, i.filepath AS image_filepath, v.price AS price, v.compare_price AS compare_price, v.stock AS stock " . $sqlQPart;
            // Retrieve news record
            $rec = $mysql->record($sqlQ);
            if (!is_array($rec)) {
                return array('status' => 0, 'errorCode' => 3, 'errorText' => 'Item [news] with ID (' . $linked_id . ') is not found');
            }
            $btitle = $rec['name'];
            $price = $rec['price'];
            $view_link = checkLinkAvailable('eshop', 'show') ? generateLink('eshop', 'show', array('alt' => $row['url'])) : generateLink('core', 'plugin', array('plugin' => 'eshop', 'handler' => 'show'), array('alt' => $row['url']));
            $rec['view_link'] = $view_link;
            // Add data into basked
            return ebasket_add_fast_order($linked_ds, $linked_id, $btitle, $price, $count, $type, $order, array('item' => $rec));
            break;
    }
    return array('status' => 1, 'errorCode' => 0, 'data' => 'OK, ' . var_export($params, true));
}
示例#9
0
function _guestbook_records($order, $start, $perpage)
{
    global $mysql, $tpl, $userROW, $config, $parse;
    foreach ($mysql->select("SELECT * FROM " . prefix . "_guestbook WHERE status = 1 ORDER BY id {$order} LIMIT {$start}, {$perpage}") as $row) {
        if (pluginGetVariable('guestbook', 'usmilies')) {
            $row['message'] = $parse->smilies($row['message']);
        }
        if (pluginGetVariable('guestbook', 'ubbcodes')) {
            $row['message'] = $parse->bbcodes($row['message']);
        }
        $editlink = checkLinkAvailable('guestbook', 'edit') ? generatePluginLink('guestbook', 'edit', array('id' => $row['id']), array()) : generateLink('core', 'plugin', array('plugin' => 'guestbook', 'handler' => 'edit'), array('id' => $row['id']));
        $dellink = generateLink('core', 'plugin', array('plugin' => 'guestbook'), array('action' => 'delete', 'id' => $row['id']));
        $comnum++;
        // get fields
        $data = $mysql->select("select * from " . prefix . "_guestbook_fields");
        $fields = array();
        foreach ($data as $num => $value) {
            $fields[$value['id']] = $value['name'];
        }
        $comment_fields = array();
        foreach ($fields as $fid => $fname) {
            $comment_fields[$fid] = array('id' => $fid, 'name' => $fname, 'value' => $row[$fid]);
        }
        // set date format
        $date_format = pluginGetVariable('guestbook', 'date');
        if (empty($date_format)) {
            $date_format = 'j Q Y';
        }
        // get social data
        $social = unserialize($row['social']);
        $profiles = array();
        foreach ($social as $name => $id) {
            $img = $mysql->record("SELECT name, description FROM " . prefix . "_images WHERE id = {$id}");
            $profiles[$name] = array('photo' => $config['images_url'] . '/' . $img['name'], 'link' => $img['description']);
        }
        $comments[] = array('id' => $row['id'], 'date' => LangDate($date_format, $row['postdate']), 'message' => $row['message'], 'answer' => $row['answer'], 'author' => $row['author'], 'ip' => $row['ip'], 'comnum' => $comnum, 'edit' => $editlink, 'del' => $dellink, 'fields' => $comment_fields, 'social' => $profiles);
    }
    return $comments;
}