function actDefault() { global $ST, $get; $field_name = $this->getURIVal('enum'); if (($field_value = $this->getURIVal($field_name)) && $field_value != 'mode') { $data = array('field_name' => $field_name, 'field_value' => $field_value, 'position' => 0, 'value_desc' => ''); $rs = $ST->select("SELECT * FROM sc_enum WHERE field_name='" . SQL::slashes($field_name) . "' AND field_value='" . SQL::slashes($field_value) . "'"); if ($rs->next()) { $data = $rs->getRow(); } $this->display($data, dirname(__FILE__) . '/enum_item.tpl.php'); } elseif ($field_name) { $rs = $ST->select("SELECT * FROM sc_enum WHERE field_name='{$field_name}' ORDER BY position"); $data = array('rs' => $rs, 'field_name' => $field_name); $data['mode'] = array('add', 'pos', 'value', 'desc', 'name'); if ($mode = $this->getURIVal('mode')) { $data['mode'] = explode(',', $mode); } if ($get->get('title')) { $this->setPageTitle($get->get('title')); $data['hidename'] = true; } if ($get->exists('autoval')) { $data['autoval'] = true; } $this->display($data, dirname(__FILE__) . '/enum.tpl.php'); } else { $rs = $ST->select("SELECT DISTINCT field_name FROM sc_enum ORDER BY field_name")->toArray(); $data = array('rs' => $rs); $this->display($data, dirname(__FILE__) . '/enum_list.tpl.php'); } }
function getQuery($key) { if ($key == 'news') { $cond = " type='news' \n\t\t\t\t\tAND (state='main' OR state='public') "; // $relev=" MATCH nws_title, nws_content,nws_desc AGAINST ('".$this->search."') "; $cond .= " AND (content ILIKE '%" . SQL::slashes($this->search) . "%' OR title ILIKE '%" . SQL::slashes($this->search) . "%' OR description ILIKE '%" . SQL::slashes($this->search) . "%')"; $q = "SELECT id ,title, description FROM sc_news WHERE " . $cond . " "; $countQ = "SELECT COUNT(id) AS c FROM sc_news WHERE " . $cond; $href = "/news/view/"; $title = "Новости"; } if ($key == 'content') { $cond = " mod_content_id=c_id AND (mod_location LIKE 'main' OR mod_location LIKE 'footer' OR mod_location LIKE 'top')\n\t\t\t\t\t\tAND (mod_name ILIKE '%" . SQL::slashes($this->search) . "%' OR mod_title ILIKE '%" . SQL::slashes($this->search) . "%' OR c_text ILIKE '%" . SQL::slashes($this->search) . "%')"; $cond = " c_name ILIKE '%'||mod_alias||'%' AND mod_alias <>'/'"; // $cond=" mod_alias ILIKE '%'||c_name||'%' "; // $cond=" mod_alias =c_name "; // $cond.=" AND (mod_location LIKE '%main%' OR mod_location LIKE '%footer%' OR mod_location LIKE '%top%')"; $cond .= " AND (mod_name ILIKE '%" . SQL::slashes($this->search) . "%' OR mod_title ILIKE '%" . SQL::slashes($this->search) . "%' OR c_text ILIKE '%" . SQL::slashes($this->search) . "%')"; $q = "SELECT mod_alias AS id,mod_title AS title,mod_description AS description FROM sc_content,sc_module WHERE " . $cond . " "; $q = "SELECT c_name AS id,mod_title AS title,mod_description AS description FROM sc_content,sc_module WHERE " . $cond . " "; $countQ = "SELECT COUNT(c_id) AS c FROM sc_content,sc_module WHERE " . $cond; $href = ""; $title = "Разделы сайта"; } if ($key == 'catalog') { $cond = " c.id=g.category AND of.in_stock>0 AND of.itemid=g.id AND of.region='{$this->getRegion()}'"; $cond .= " AND (g.name ILIKE '%" . SQL::slashes($this->search) . "%' OR g.description ILIKE '%" . SQL::slashes($this->search) . "%' OR c.name ILIKE '%" . SQL::slashes($this->search) . "%' )"; $q = "SELECT g.*, g.id AS id, g.name AS title, g.description AS description FROM sc_shop_catalog c,sc_shop_item g, sc_shop_offer of WHERE " . $cond . ""; $countQ = "SELECT COUNT(g.id) AS c FROM sc_shop_catalog c,sc_shop_item g, sc_shop_offer of WHERE " . $cond; $href = "/catalog/goods/"; $title = "Товары и услуги"; } return array($q, $countQ, $href, $title); }
function actDefault() { global $ST; if ($id = $this->getURIIntVal(trim($this->mod_uri, '/'))) { $this->actView($id); return; } $page = new Page($this->cfg('PAGE_SIZE')); // $page=new Page(1); $type = trim($this->mod_uri, '/'); $condition = "g.type='" . SQL::slashes($type) . "' AND g.sort>-1"; $cat_list = $this->enum("gal_{$type}_cat"); $label_list = $this->enum("gal_{$type}_label"); $label_list = array(); $rs = $ST->select("SELECT * FROM sc_enum e WHERE field_name='gal_{$type}_label' AND EXISTS (SELECT gallery_id FROM sc_gallery_label , sc_gallery g WHERE gallery_id=g.id AND label_id=e.field_value AND type='" . SQL::slashes($type) . "' AND sort>-1) ORDER BY position"); while ($rs->next()) { $label_list[$rs->get('field_value')] = $rs->get('value_desc'); } $cat = ''; if (preg_match('|cat-([\\d\\w]+)|', $this->getURIVal($type), $res)) { $cat = $res[1]; $condition .= " AND cat='{$cat}'"; } $label = ''; if (preg_match('|label-([\\d\\w]+)|', $this->getURIVal($type), $res)) { $label = $res[1]; $condition .= " AND EXISTS (SELECT gallery_id FROM sc_gallery_label WHERE gallery_id=g.id AND label_id={$label}) "; } $queryStr = "SELECT COUNT(*) as c FROM sc_gallery g WHERE {$condition}"; $rs = $ST->select($queryStr); if ($rs->next()) { $page->all = $rs->getInt("c"); } $order = "ORDER BY g.sort DESC, g.date DESC, g.id DESC"; if ($type == 'staff') { $order = "ORDER BY ct.position, g.sort DESC, g.date DESC, g.id DESC"; } $queryStr = "SELECT g.*,p.title AS p_title,p.id AS p_id,ct.value_desc AS ct_desc FROM sc_gallery g\r\n\t\t\tLEFT JOIN (SELECT field_value,value_desc,position FROM sc_enum WHERE field_name='gal_{$type}_cat') AS ct ON ct.field_value=g.cat\r\n\t\t\tLEFT JOIN (SELECT n.* FROM sc_news n,(SELECT MAX(id) as id ,gallery FROM sc_news GROUP BY gallery) AS mn WHERE type='public' AND mn.id=n.id) AS p ON p.gallery=g.id \r\n\t\t\r\n\t\tWHERE {$condition} {$order} LIMIT " . $page->getBegin() . "," . $page->per; $rs = $ST->select($queryStr)->toArray(); $data = array('rs' => $rs, 'pg' => $page, 'type' => $type); $data['cat_list'] = $cat_list; $data['cat_list_item'] = array(); // $data['cat']=$cat; $rs = $ST->select("SELECT * FROM sc_gallery WHERE type='{$type}' AND cat<>''"); while ($rs->next()) { $data['cat_list_item'][$rs->get('cat')][] = $rs->getRow(); } // $data['label_list']=$label_list; // $data['label']=$label; $tpl = dirname(__FILE__) . '/' . $type . '.tpl.php'; if (file_exists($tpl)) { $this->display($data, $tpl); return; } $this->display($data, dirname(__FILE__) . '/gallery.tpl.php'); }
function actGetText() { global $ST, $post; $data = array('rule' => '', 'text' => '', 'url' => $post->get('url'), 'exists' => false); $rs = $ST->select("SELECT text,url,rule FROM sc_ceo_text\r\n\t\t\t WHERE\r\n\t\t\t \tplace='{$post->get('place')}' \r\n\t\t\t \tAND ((url='" . SQL::slashes($post->get('url')) . "' AND rule='=') \r\n\t\t\t \tOR ('" . SQL::slashes($post->get('url')) . "' LIKE CONCAT(url,'%') AND rule!='=' ))\r\n\t\t\t ORDER BY LENGTH(url) DESC LIMIT 1"); if ($rs->next()) { $data = $rs->getRow(); $data['exists'] = true; } $data['place'] = $post->get('place'); echo printJSON($data); exit; }
function actRemove() { global $ST, $get, $post; if ($get->get('name')) { $ST->delete('sc_config', "name='" . SQL::slashes($get->get('name')) . "'"); } if ($item = $post->getArray('item')) { foreach ($item as $n) { $ST->delete('sc_config', "name='" . SQL::slashes($n) . "'"); } } echo $this->rndList(); }
function actOrder1c() { global $ST, $get; $login = $get->get('login'); $password = $get->get('password'); $q = "SELECT * FROM sc_users WHERE type='admin' \n\t\t\tAND login='******'\n\t\t\tAND password=PASSWORD('" . SQL::slashes($password) . "')"; $rs = $ST->select($q); if (!$rs->next()) { exit; } $data = array('make_date' => date('Y-m-d'), 'make_time' => date('H:i:s'), 'document' => array()); $date_from = date('Y-m-d'); $date_to = date('Y-m-d', time() + 3600 * 24); if ($get->get('date_from')) { $date_from = $get->get('date_from'); } if ($get->get('date_to')) { $date_to = $get->get('date_to'); } $q = "SELECT * FROM sc_shop_order o,sc_users u WHERE u.u_id=o.userid\n\t\t\tAND o.create_time>='{$date_from}' AND o.create_time<='{$date_to}'\n\t\t"; $rs = $ST->select($q); while ($rs->next()) { $d = array('id' => $rs->get('id'), 'num' => $rs->get('id'), 'date' => dte($rs->get('create_time'), 'Y-m-d'), 'summ' => $rs->get('total_price'), 'contragent' => array('id' => $rs->get('u_id') . '#' . $rs->get('login') . '#' . $rs->get('name'), 'name' => $rs->get('type') == 'user_jur' ? $rs->get('company') : $rs->get('name'), 'address' => $rs->get('address'), 'mail' => $rs->get('mail')), 'time' => dte($rs->get('create_time'), 'H:i:s'), 'additionally' => $rs->get('additionally'), 'goods' => array()); $q = "SELECT *,ec.id AS ext_cat_id, oi.price AS price \t\n\t\t\tFROM sc_shop_order_item AS oi, sc_shop_item AS si\n\t\t\tLEFT JOIN sc_shop_srv_extcat AS ec ON ec.lnk=si.category\n\t\t\tWHERE\n\t\t\t\tsi.id=oi.itemid\n\t\t\t\tAND oi.orderid={$rs->get('id')} \n\t\t\t\t\n\t\t\t"; $q = "SELECT *, oi.price AS price \t\n\t\t\tFROM sc_shop_order_item AS oi, sc_shop_item AS si\n\t\t\t\n\t\t\tWHERE\n\t\t\t\tsi.id=oi.itemid\n\t\t\t\tAND oi.orderid={$rs->get('id')} \n\t\t\t\t\n\t\t\t"; $rs1 = $ST->select($q); while ($rs1->next()) { $g = array('name' => $rs1->get('name'), 'id' => $rs1->get('ext_id'), 'price' => $rs1->get('price') / $rs1->get('count'), 'count' => $rs1->get('count'), 'summ' => $rs1->get('price')); $d['goods'][] = $g; } $data['document'][] = $d; } if ($data['document']) { echo '<?xml version="1.0" encoding="windows-1251"?>'; echo $this->render($data, dirname(__FILE__) . '/order1c.xml.php'); exit; } else { echo 'Нет заказов'; } }
function actSave() { global $ST, $post; $id = $post->getInt('c_id'); if (!trim($post->get('c_name'))) { echo printJSON(array('err' => 'Введите название')); exit; } $rs = $ST->select("SELECT * FROM sc_content WHERE c_name='" . SQL::slashes($post->get('c_name')) . "' AND c_id<>{$id}"); if ($rs->next()) { echo printJSON(array('err' => 'Содержимое с таким названием СУЩЕСТВУЕТ')); exit; } $data = array('c_name' => $post->get('c_name'), 'c_text' => $post->get('c_text')); if ($id) { $ST->update('sc_content', $data, 'c_id=' . $id); } else { $id = $ST->insert('sc_content', $data, 'c_id'); } echo printJSON(array('msg' => 'Сохранено', 'c_id' => $id)); exit; }
function act_recountMan() { global $ST; $rs = $ST->select("SELECT * FROM sc_shop_item WHERE manufacturer <>''"); while ($rs->next()) { $rs1 = $ST->select("SELECT * FROM sc_manufacturer WHERE name='" . SQL::slashes($rs->get('manufacturer')) . "'"); if ($rs1->next()) { $manid = $rs1->get('id'); } else { $manid = $ST->insert('sc_manufacturer', array('name' => $rs->get('manufacturer'))); } $ST->update('sc_shop_item', array('manufacturer_id' => $manid), 'id=' . $rs->get('id')); } }
function actPasschange() { global $ST, $post; $ST->executeUpdate("UPDATE sc_users SET password=PASSWORD('" . SQL::slashes($post->get('password')) . "') WHERE u_id=" . $this->getUserId()); echo printJSON(array('msg' => 'Пароль принят')); exit; }
function getQuery($key) { $search = explode(' ', trim(preg_replace('/\\s+/', ' ', $this->search))); if (in_array($key, array('public', 'news'))) { $cond = " type IN('{$key}') \r\n\t\t\t\t\tAND (state='main' OR state='public') "; // $relev=" MATCH nws_title, nws_content,nws_desc AGAINST ('".$this->search."') "; // $cond.=" AND (content ILIKE '%".SQL::slashes($this->search)."%' OR title ILIKE '%".SQL::slashes($this->search)."%' OR description ILIKE '%".SQL::slashes($this->search)."%')"; $subCond = array(); foreach ($search as $s) { $subCond[] = "(content LIKE '%" . SQL::slashes($s) . "%' OR title LIKE '%" . SQL::slashes($s) . "%' OR description LIKE '%" . SQL::slashes($s) . "%')"; } // $cond.=" AND (".implode(' OR ',$subCond).")"; $cond .= " AND (" . implode(' AND ', $subCond) . ")"; $q = "SELECT id ,title, description FROM sc_news WHERE " . $cond . " "; $countQ = "SELECT COUNT(id) AS c FROM sc_news WHERE " . $cond; $href = "/news/view/"; $title = "Статьи"; } if ($key == 'gallery') { $cond = " type='gallery' \r\n\t\t\t\t\t"; $subCond = array(); foreach ($search as $s) { $subCond[] = "(text LIKE '%" . SQL::slashes($s) . "%' OR name LIKE '%" . SQL::slashes($s) . "%' OR description LIKE '%" . SQL::slashes($s) . "%')"; } // $cond.=" AND (".implode(' OR ',$subCond).")"; $cond .= " AND (" . implode(' AND ', $subCond) . ")"; $q = "SELECT id ,name as title, description FROM sc_gallery WHERE " . $cond . " "; $countQ = "SELECT COUNT(id) AS c FROM sc_gallery WHERE " . $cond; $href = "/gallery/"; $title = "Галлерея"; } if ($key == 'content') { // $cond=" mod_content_id=c_id AND (mod_location LIKE 'main' OR mod_location LIKE 'footer' OR mod_location LIKE 'top') // AND (mod_name ILIKE '%".SQL::slashes($this->search)."%' OR mod_title ILIKE '%".SQL::slashes($this->search)."%' OR c_text ILIKE '%".SQL::slashes($this->search)."%')"; // $cond=" c_name ILIKE '%'||mod_alias||'%' AND mod_alias <>'/'"; $cond = " mod_alias LIKE CONCAT('%',c_name,'%') AND mod_title<>'' AND c_text<>''"; // $cond=" mod_alias =c_name "; // $cond.=" AND (mod_location LIKE '%main%' OR mod_location LIKE '%footer%' OR mod_location LIKE '%top%')"; // $cond.=" AND (mod_name ILIKE '%".SQL::slashes($this->search)."%' OR mod_title ILIKE '%".SQL::slashes($this->search)."%' OR c_text ILIKE '%".SQL::slashes($this->search)."%')"; $subCond = array(); foreach ($search as $s) { $subCond[] = "(mod_name LIKE '%" . SQL::slashes($s) . "%' OR mod_title LIKE '%" . SQL::slashes($s) . "%' OR c_text LIKE '%" . SQL::slashes($s) . "%')"; } // $cond.=" AND (".implode(' OR ',$subCond).")"; $cond .= " AND (" . implode(' AND ', $subCond) . ")"; // $q="SELECT mod_alias AS id,mod_title AS title,mod_description AS description FROM sc_content,sc_module WHERE ".$cond." "; $q = "SELECT c_name AS id,mod_title AS title,mod_description AS description FROM sc_content,sc_module WHERE " . $cond . " "; $countQ = "SELECT COUNT(c_id) AS c FROM sc_content,sc_module WHERE " . $cond; $href = ""; $title = "Разделы сайта"; } if ($key == 'catalog') { $cond = ""; // $cond.=" AND (g.name ILIKE '%".SQL::slashes($this->search)."%' OR g.description ILIKE '%".SQL::slashes($this->search)."%' OR c.name ILIKE '%".SQL::slashes($this->search)."%' )"; $subCond = array(); foreach ($search as $s) { $subCond[] = "(i.name LIKE '%" . SQL::slashes($s) . "%' OR i.description LIKE '%" . SQL::slashes($s) . "%' )"; } // $cond.=" AND (".implode(' OR ',$subCond).")"; $cond .= " AND (" . implode(' AND ', $subCond) . ")"; $cat = LibCatalog::getInstance(); $q = "SELECT g.*, g.id AS id, g.name AS title, g.description AS description FROM sc_shop_item g WHERE " . $cond . ""; $q = "{$cat->select()} " . $cond . ""; $countQ = "{$cat->selectCount()} " . $cond; $href = "/catalog/goods/"; $title = "Товары"; } return array($q, $countQ, $href, $title); }
function actSave() { global $ST, $get, $post; $id = $post->getInt('id'); $data = array('content' => $post->get('content'), 'description' => $post->get('description'), 'title' => $post->get('title'), 'author' => $post->get('author'), 'date' => dte($post->get('date'), 'Y-m-d'), 'state' => $post->get('state'), 'category' => $post->getInt('category'), 'position' => $post->getInt('position'), 'gallery' => $post->getInt('gallery'), 'type' => $this->getType()); $img_out = ""; if (!empty($_FILES['upload']['name']) && isImg($_FILES['upload']['name'])) { $img = $this->cfg('NEWS_IMAGE_PATH') . '/' . md5($_FILES['upload']['tmp_name']) . "." . file_ext($_FILES['upload']['name']); move_uploaded_file($_FILES['upload']['tmp_name'], ROOT . $img); $data['img'] = $img; $img_out = scaleImg($img, 'w200'); } if ($post->getInt('clear')) { $data['img'] = ''; } if ($id) { $ST->update('sc_news', $data, "id=" . $id); } else { $id = $ST->insert('sc_news', $data); } $ST->delete('sc_relation', "parent={$id} AND type='public'"); foreach ($post->getArray('public_rel') as $v) { $ST->insert('sc_relation', array('parent' => $id, 'type' => 'public', 'child' => $v)); } $msg = "Сохранено"; if (true) { $content = ''; $content .= '<small>' . date('d.m.Y') . '</small> '; $content .= '<strong>' . $post->getHtml('title') . '</strong><br />'; $content .= '<span>' . $post->getHtml('description') . '</span><br />'; $content .= '<a href="http://' . $this->cfg('SITE') . '/' . $post->get('type') . '/' . $id . '/">подробнее...</a>'; if ($post->exists('save_and_send')) { $mail = new Mail(); $mail->setFromMail(array($this->cfg('SITE'), $this->cfg('mail'))); $key = 'http://' . $this->cfg('SITE') . '/cabinet/unsubscribe/?key=' . md5($this->getUser('mail') . $this->getType() . 'unsubscribe') . '&type=' . $this->getType() . '&mail=' . $this->getUser('mail'); $key = '<a href="' . $key . '">' . $key . '</a>'; $mail->setTemplate('letter_' . $this->getType(), array('FROM_SITE' => $this->cfg('SITE'), 'CONTENT' => $content, 'BODY' => $post->get('content'), 'TITLE' => $post->get('title'))); $mail->xsend($this->getUser('mail'), array('UNSUBSCRIBE' => $key)); } elseif ($post->exists('save_and_send_all')) { $q = "SELECT distinct mail,id FROM sc_subscribe WHERE type LIKE '%" . $this->getType() . "%' \r\n\t\t\t\tAND NOT EXISTS(SELECT mailid FROM sc_news_sendlog WHERE id=mailid AND newsid={$id}){$this->getMailFilter()}"; if ($post->getInt('pack')) { $q .= " LIMIT {$post->getInt('pack')}"; } $rs = $ST->select($q); $mail = new Mail(); // $mail->setFromMail($this->getConfig('mail')); $mail->setFromMail(array($this->cfg('SITE'), $this->cfg('mail'))); $mail->setTemplate('letter_' . $this->getType(), array('FROM_SITE' => $this->cfg('SITE'), 'CONTENT' => $content, 'BODY' => $post->get('content'), 'TITLE' => $post->get('title'))); $n = 0; while ($rs->next()) { if (check_mail($m = trim($rs->get('mail')))) { $key = 'http://' . $this->cfg('SITE') . '/cabinet/unsubscribe/?key=' . md5($rs->get('mail') . $this->getType() . 'unsubscribe') . '&type=' . $this->getType() . '&mail=' . $rs->get('mail'); $key = '<a href="' . $key . '">' . $key . '</a>'; $mail->xsend($m, array('UNSUBSCRIBE' => $key)); $ST->insert('sc_news_sendlog', array('mailid' => $rs->get('id'), 'newsid' => $id)); $n++; } else { $ST->delete('sc_subscribe', "mail='" . SQL::slashes($rs->get('mail')) . "'"); } } $msg .= " отправлено {$n}"; } } echo printJSONP(array('msg' => $msg, 'id' => $id, 'img' => $img_out)); exit; }
function actUnsubscribe() { DB::delete("sc_subscribe", "mail='" . SQL::slashes($_GET['mail']) . "'"); header("Location: " . $_SERVER['HTTP_REFERER']); exit; }
function actDoRename() { global $ST, $post; $upd = $ST->executeUpdate("UPDATE sc_shop_item SET name=REPLACE(name,'" . SQL::slashes($post->get('name')) . "','" . SQL::slashes($post->get('new_name')) . "')"); echo printJSON(array('msg' => "Затронуто {$upd} записей")); exit; }
function actUnsubscribe() { global $get, $ST; if ($get->get('key') == md5($get->get('mail') . $get->get('type') . 'unsubscribe')) { $rs = $ST->select("SELECT * FROM sc_subscribe WHERE mail='" . SQL::slashes($get->get('mail')) . "'"); if ($rs->next()) { $t = array(); if (trim($rs->get('type'))) { $t = explode(' ', trim($rs->get('type'))); $t = array_diff($t, array($get->get('type'))); } $ST->update('sc_subscribe', array('type' => implode(' ', $t)), "mail='" . SQL::slashes($get->get('mail')) . "'"); } } $this->setPageTitle('Отписаться'); $this->display(array(), dirname(__FILE__) . '/cabinet_unsubscribe.tpl.php'); }
$rs = DB::select($q)->toArray(); if (!$rs) { exit; } ob_start(); include dirname(__FILE__) . "/catalog_subscribe.tpl.php"; $content = ob_get_contents(); ob_end_clean(); $type = 'catalog'; $mail = new Mail(); // $mail->setFromMail($this->getConfig('mail')); $mail->setFromMail(array(Cfg::get('SITE'), Cfg::get('mail'))); $mail->setTemplate('letter_catalog', array('FROM_SITE' => Cfg::get('SITE'), 'CONTENT' => $content)); $q = "SELECT distinct mail,id FROM sc_subscribe WHERE type LIKE '%" . $type . "%' \n\t\t\t\tAND NOT EXISTS(SELECT mailid FROM sc_news_sendlog WHERE id=mailid AND newsid={$id})"; $rs = DB::select($q); $n = 0; while ($rs->next()) { if (check_mail($m = trim($rs->get('mail')))) { $key = 'http://' . Cfg::get('SITE') . '/cabinet/unsubscribe/?key=' . md5($rs->get('mail') . $type . 'unsubscribe') . '&type=' . $type . '&mail=' . $rs->get('mail'); $key = '<a href="' . $key . '">' . $key . '</a>'; $mail->xsend($m, array('UNSUBSCRIBE' => $key)); DB::insert('sc_news_sendlog', array('mailid' => $rs->get('id'), 'newsid' => $id)); $n++; } else { DB::delete('sc_subscribe', "mail='" . SQL::slashes($rs->get('mail')) . "'"); } } $rs = DB::select("SELECT MAX(create_time) AS m FROM sc_shop_proposal"); if ($rs->next()) { file_put_contents($last_time_fname, $rs->get('m')); }
function getGoods($pgSize = 20, $category = 0, $search = '') { global $ST, $get; $pg = new Page($pgSize); $catIds = array(); if ($category) { $rs = $ST->select("SELECT * FROM sc_shop_catalog WHERE id=" . $category); if ($rs->next()) { $catIds = unserialize($rs->get('cache_child_catalog_ids')); } $catIds[] = $category; } $condition = "WHERE 1=1 "; if ($catIds) { $condition .= " AND category IN('" . join("','", $catIds) . "')"; } if ($search = SQL::slashes(strtolower(trim($search)))) { $condition .= " AND (LOWER(name) LIKE '%{$search}%' OR product='{$search}')"; } $query = "SELECT count(*) AS c FROM sc_shop_item i " . $condition; $rs = $ST->select($query); if ($rs->next()) { $pg->all = $rs->getInt('c'); } $order = 'ORDER BY '; $ord = $this->getURIVal('ord') != 'asc' ? 'asc' : 'desc'; if ($this->getURIVal('sort') == 'name') { $order .= 'name ' . $ord; } elseif ($this->getURIVal('sort') == 'price') { $order .= 'price ' . $ord; } elseif ($this->getURIVal('sort') == 'sort') { $order .= 'sort ' . $ord; } elseif ($this->getURIVal('sort') == 'in_stock') { $order .= 'in_stock ' . $ord; } else { if ($search) { $order .= "IF(LOCATE('{$search}',LOWER(i.name)),LOCATE('{$search}',LOWER(i.name)),256),category ,name"; } else { $order .= 'category ,name'; } } $queryStr = "SELECT * FROM sc_shop_item i {$condition} {$order} LIMIT " . $pg->getBegin() . "," . $pg->per; $data['rs'] = $ST->select($queryStr); $data['pg'] = $pg; $data['catalog'] = $this->catRef = $this->getCatalog(); return $data; }
function actSave() { global $post; $id = $post->getInt('u_id'); $data = array('login' => $post->get('login'), 'name' => $post->get('name'), 'company' => $post->get('company'), 'phone' => $post->get('phone'), 'city' => $post->get('city'), 'address' => $post->get('address'), 'img_format' => $post->getInt('img_format'), 'mail' => $post->get('mail'), 'balance' => $post->getFloat('balance'), 'discount' => $post->getFloat('discount'), 'type' => 'vendor'); $msg = 'Сохранено'; $img_out = ""; if (!empty($_FILES['upload']['name']) && isImg($_FILES['upload']['name'])) { $img = $this->cfg('AVATAR_PATH') . '/' . md5($_FILES['upload']['tmp_name']) . "." . file_ext($_FILES['upload']['name']); move_uploaded_file($_FILES['upload']['tmp_name'], ROOT . $img); $data['avat'] = $img; $img_out = scaleImg($img, 'w200'); } if ($post->getInt('clear')) { $data['avat'] = ''; } $err = array(); $rs = DB::select("SELECT * FROM sc_users WHERE login='******'login')) . "' AND u_id<>{$id}"); if ($rs->next()) { $err['login'] = '******'; } if (!$err) { if ($id === 0) { $id = DB::insert('sc_users', $data, 'u_id'); } else { DB::update('sc_users', $data, 'u_id=' . $id); } $rs = DB::select("SELECT * FROM sc_users_vendor WHERE vendor_id={$id}"); $ext_data = array('info' => $post->get('info'), 'html' => $post->get('html'), 'comment' => $post->get('comment'), 'adm_comment' => $post->get('adm_comment')); $ext_data['images'] = $post->getArray('images'); if ($img_pos = $post->getArray('pos')) { //Сортировка картинок asort($img_pos); $temp_img = array(); foreach ($img_pos as $k => $v) { $temp_img[] = $ext_data['images'][$k]; } $ext_data['images'] = $temp_img; } foreach ($_FILES['images_upload']['error'] as $k => $err) { if ($err != 0) { continue; } if (isset($_FILES['images_upload']['tmp_name'][$k]) && isImg($name = $_FILES['images_upload']['name'][$k])) { $path = $this->cfg('AVATAR_PATH') . '/' . md5_file($_FILES['images_upload']['tmp_name'][$k]) . '.' . file_ext($name); if (!file_exists(ROOT . $path)) { rename($_FILES['images_upload']['tmp_name'][$k], ROOT . $path); } if (!in_array($path, $ext_data['images'])) { $ext_data['images'][] = $path; } } } $ext_data['images'] = implode(',', $images = $ext_data['images']); if ($rs->next()) { DB::update('sc_users_vendor', $ext_data, "vendor_id={$id}"); } else { $ext_data['vendor_id'] = $id; DB::insert('sc_users_vendor', $ext_data); } DB::delete("sc_relation", "type='vend_gal' AND parent={$id}"); foreach ($post->getArray('gallery') as $g) { DB::insert('sc_relation', array('type' => 'vend_gal', 'parent' => $id, 'child' => $g)); } echo printJSONP(array('msg' => $msg, 'u_id' => $id, 'img' => $img_out, 'images' => $images)); exit; } else { echo printJSONP(array('err' => $err)); exit; } }
function actRemoveList() { global $ST, $post; $rs = $ST->select("SELECT * FROM sc_shop_note WHERE name='" . SQL::slashes($post->get('name')) . "' AND userid={$this->getUserId()}"); if ($rs->next()) { $ST->delete('sc_shop_note_item', "noteid={$rs->get('id')}"); $ST->delete('sc_shop_note', "id={$rs->get('id')}"); } $data['rs'] = $this->getUserNote(); echo $this->render($data, dirname(__FILE__) . '/list.tpl.php'); }
} return urldecode($url); } if (isset($_GET['q'])) { $q = unicodeUrlDecode($_GET['q'], "cp1251"); $q = trim(strtolower(SQL::slashes($q))); $condition = ''; if ($q) { if ($words = Rumor::getAllForms($q)) { $or = array(); foreach ($words as $w) { $or[] = "i.name LIKE '%" . $w . "%'"; } $condition .= " AND (" . implode(' OR ', $or) . ")"; } else { $condition .= " AND (i.name LIKE '%" . SQL::slashes($q) . "%')"; } } $query = "SELECT i.name,price \r\n\t\tFROM sc_shop_item i\r\n\t\t\t\r\n\t\tWHERE price>0 AND in_stock>0"; if (isset($_GET['m']) && $_GET['m'] == 'all') { } else { // $query.=" AND "; } // $query.=" AND (lower(i.name) LIKE '%$q%' // OR lower(c.name) LIKE '%$q%' // OR (i.product>0 AND i.product='$q') // ) // ORDER BY // IF(LOCATE('$q',LOWER(i.name)),LOCATE('$q',LOWER(i.name)),256), // i.sort DESC // LIMIT 100 ";
function actSave() { global $ST, $post, $get; /*Сохранение*/ if (!trim($post->get('mod_name'))) { echo printJSON(array('msg' => "Введите название! Сохранение невозможно", 'mod_id' => 0, 'mod_content_id' => $post->get('mod_content_id'))); exit; } if ($post->get('mod_type') == 1) { //Текстовка if (!trim($post->get('mod_alias'))) { $post->set('mod_alias', '/' . encodestring($post->get('mod_name')) . "/"); } } elseif ($post->get('mod_type') == 0) { if (!trim($post->get('mod_alias'))) { $post->set('mod_alias', '/' . encodestring($post->get('mod_module_name')) . "/"); } } if (!trim($post->get('mod_alias')) && $post->get('mod_type') != 2) { echo printJSON(array('msg' => "Введите псевдоним! Сохранение невозможно", 'mod_id' => 0, 'mod_content_id' => $post->get('mod_content_id'))); exit; } $content['c_text'] = $post->remove('mod_content'); $post->set('mod_location', implode('|', $post->getArray('mod_location'))); // $post->set('mod_region',implode(',',$post->getArray('mod_region'))); $post->set('mod_access', implode(',', $post->getArray('mod_access'))); if ($post->get('mod_type') == 1) { $content['c_name'] = $post->get('mod_alias'); $name = $content['c_name']; $i = 0; while (true) { //если нашли тектовое содержимое с таким названием но другим ид то переименуем согласно алгоритму $rs = $ST->select("SELECT * FROM sc_content WHERE c_name='" . SQL::slashes($name) . "' AND c_id!=" . $post->getInt('mod_content_id')); if ($rs->next()) { $name = $content['c_name'] . '_' . ++$i; } else { break; } } $content['c_name'] = $name; $post->set('mod_module_name', ''); //стираем название модуля if ($post->get('mod_content_id')) { $rs = $ST->select("SELECT * FROM sc_content WHERE c_id=" . $post->getInt('mod_content_id')); if ($rs->next()) { $ST->update('sc_content', $content, 'c_id=' . $post->getInt('mod_content_id')); } else { $c_id = $ST->insert('sc_content', $content, 'c_id'); $post->set('mod_content_id', $c_id); } } else { $c_id = $ST->insert('sc_content', $content, 'c_id'); $post->set('mod_content_id', $c_id); } } if ($post->get('mod_type') == 2) { $post->set('mod_module_name', ''); } $id = $post->getInt('mod_id'); if (!$post->get('mod_state')) { $post->set('mod_state', 1); } if ($id) { $ST->update('sc_module', $post->get(), "mod_id=" . $id); } else { if ($post->get('mod_type') != 2) { $rs = $ST->select("SELECT * FROM sc_module WHERE mod_alias = '" . SQL::slashes($post->get('mod_alias')) . "' AND mod_type!=2"); if ($rs->next()) { echo printJSON(array('msg' => "Модуль с таким псевдонимом [{$post->get('mod_alias')}] уже существует ! Сохранение невозможно", 'mod_id' => 0, 'mod_content_id' => 0)); exit; } } if ($post->get('mod_id') == '0') { $post->remove('mod_id'); } $id = $ST->insert('sc_module', $post->get(), 'mod_id'); $queryStr = "UPDATE sc_module set mod_position=mod_id where mod_id=" . $id; $ST->executeUpdate($queryStr); } echo printJSON(array('msg' => 'Сохранено', 'mod_id' => $id, 'mod_content_id' => $post->get('mod_content_id'), 'mod_alias' => $post->get('mod_alias'))); exit; }
function update($table_name, $values, $condition = '') { if (!is_array($values)) { return false; } foreach ($values as $key => $val) { if (is_int($key)) { $names_ar[] = $val; } else { $names_ar[] = $key . ' = \'' . SQL::slashes($val) . '\''; } } $names_string = implode(', ', $names_ar); $UpSQL = 'UPDATE ' . $table_name . ' SET ' . $names_string . ($condition ? ' WHERE ' . $condition : ''); return $this->executeUpdate($UpSQL); }
function display($data = array(), $tpl = null, $tplContainer = null, $cache = null) { global $ST; $this->setClientId(); $this->setFirstReferer(); $this->setRefId(); if (!$tpl) { $tpl = $this->tplComponent; } if (!$tplContainer) { $tplContainer = $this->getTplContainer(); } $this->refreshContainer(); /* ceo */ $rs = $ST->select("SELECT * FROM sc_ceo_meta\r\n\t\t\t WHERE \r\n\t\t\t \t(url='" . SQL::slashes($_SERVER['REQUEST_URI']) . "' AND rule='=') \r\n\t\t\t \tOR ('" . SQL::slashes($_SERVER['REQUEST_URI']) . "' LIKE CONCAT(url,'%') AND rule!='=' ) \r\n\t\t\t ORDER BY LENGTH(url) DESC LIMIT 1"); /* ceo */ $this->setCeo(array('url' => $_SERVER['REQUEST_URI'])); if ($rs->next()) { $this->setCeo($rs->getRow()); if ($this->getCeo('title')) { $this->setTitle($this->getCeo('title')); } if ($this->getCeo('header')) { $this->setHeader($this->getCeo('header')); } if ($this->getCeo('description')) { $this->setDescription($this->getCeo('description')); } if ($this->getCeo('keywords')) { $this->setKeywords($this->getCeo('keywords')); } } if (Cfg::get('STAMP')) { Img::$stamp = true; } $rnd = $this->render($data, $tpl); $out = $this->render($data, $tplContainer, $rnd); $t = microtime(true); if (preg_match_all('/\\{%(.+)%\\}/U', $out, $res) && $res) { $vals = array(); foreach ($res[1] as $id => $key) { //07.09.2011 Возможность создавать содержимое по названию $tmp = ''; if ($this->isAdmin()) { $tmp = '<a href="/admin/content/?act=edit&name=' . trim($key) . '" class="coin-text-edit" title="Редактировать"></a>' . $res[0][$id]; } $vals[trim($key)] = $tmp; } foreach ($this->cacheSelect("SELECT * FROM sc_content WHERE c_name IN('" . implode("','", array_keys($vals)) . "')", 0) as $row) { $res = $row['c_text']; if ($this->isAdmin()) { $res = '<a href="/admin/content/?act=edit&name=' . $row['c_name'] . '" class="coin-text-edit" title="Редактировать"></a>' . $res; } $vals[$row['c_name']] = $res; } $out = preg_replace('/\\{%(.+)%\\}/Ue', '$vals[trim("\\1")]', $out); //_replace($keys[$rs->get('c_name')],$res,$out); } $this->visitLog(); //Вывод ob_start(); ob_implicit_flush(0); echo $out; global $begin_time, $query_count, $query_time, $query_report, $cache_time; $t = microtime(true) - $begin_time; ?> <!-- <?php echo $t; ?> --><!-- <?php echo $query_count; ?> <?php echo $query_time; ?> --><!-- <?php echo $t - $query_time; ?> <?php echo $cache_time; ?> --><?php ?> <!-- <?php echo isset($_GET['debug']) && $_GET['debug'] == 'true' ? $query_report : ''; ?> --><?php GzDocOut(3, isset($_GET['debug']) && $_GET['debug'] == 'true'); $this->updateAdvView(); }
if (isset($_GET['act']) && $_GET['act']) { $action = ucfirst($_GET['act']); } $class_name = ucfirst($module); if (in_array($module, $CORE) || $isAdminPath && $module == 'main') { $module_path = CORE_PATH; } elseif ($isAdminPath) { $class_name = 'Admin' . $class_name; } $class_path = $module_path . '/' . $module . '/' . $class_name . '.class.php'; $alias = ($isAdminPath ? ADMIN : '') . '/' . $module . '/'; $explorer = array(); $componentData = array('mod_id' => 0, 'mod_parent_id' => 0, 'mod_name' => '', 'mod_type' => 0, 'mod_module_name' => '', 'mod_alias' => $alias, 'mod_title' => '', 'mod_description' => '', 'mod_keywords' => '', 'mod_content_id' => 0, 'mod_access' => ''); //1 module 2 text 3 link $path = str_replace(ADMIN, '', $URL['path']); $cond = " AND '" . SQL::slashes($path) . "' LIKE CONCAT(mod_alias,'%') AND mod_alias<>'/'"; if ($path == '/') { $cond = " AND mod_alias='/'"; } $q = "SELECT " . implode(',', array_keys($componentData)) . " \r\n\tFROM sc_module \r\n\tWHERE mod_type!=2 {$cond}\r\n\tORDER BY LENGTH(mod_alias) DESC LIMIT 1"; $result = $ST->select($q); if ($result->next()) { $componentData = $result->getRow(); $alias = ($isAdminPath ? ADMIN : '') . $result->get('mod_alias'); if ($result->getInt('mod_type') == 1) { //TEXT MODULE $module_path = CORE_PATH; $class_name = ($isAdminPath ? 'Admin' : '') . 'Component'; $class_path = $module_path . '/' . $class_name . '.class.php'; } elseif ($result->getInt('mod_type') == 0) { //MODULE
static function import($file, $offer) { global $CONFIG, $ST; $log_file = 'import/import_log.txt'; set_time_limit(1000); $start_time = time(); $result = "Не найден контрольный файл"; $goods = array(); if ($offer == 1) { $goods = CatImp::cat1($file); } if ($offer == 2) { $goods = CatImp::cat2($file); } if ($offer == 4) { $goods = CatImp::cat4($file); } if ($offer == 11) { $goods = CatImp::cat1c1('import'); } $only_changes = null; if (isset($goods['only_changes'])) { $only_changes = $goods['only_changes']; } $goods = $goods['goods']; $lnk = array(); $rs = $ST->select("SELECT * FROM sc_shop_srv_extcat WHERE offer={$offer}"); while ($rs->next()) { $lnk[$rs->get('id')] = $rs->getInt('lnk'); } $cnt_imp = 0; $cnt_img = 0; $cnt_upd = 0; $cnt_ins = 0; if ($goods) { if ($only_changes === false) { $gids = array_keys($goods); if (@$CONFIG['SHOP_IMP_FULL_REMOVE'] == 'true') { //удалять товары при полной выгрузке $ST->update("sc_shop_item", array('in_stock' => -1), "offer={$offer} AND ext_id NOT IN(" . implode(',', $gids) . ")"); } else { //просто обнулять $ST->update("sc_shop_item", array('in_stock' => 0), "offer={$offer} AND in_stock>-1 AND ext_id NOT IN(" . implode(',', $gids) . ")"); } } $lnk['00000000-0000-0000-0000-000000000000'] = 0; foreach ($goods as $gid => $g) { $cnt_imp++; $data = array('in_stock' => $g['in_stock']); if ($g['price']) { $data['price'] = $g['price']; } // if(isset($lnk[$g['ext_category']]) && isset($g['price']) ){ if ($g['ext_category'] == '00000000-0000-0000-0000-000000000000') { } elseif (isset($lnk[$g['ext_category']])) { $data['category'] = $lnk[$g['ext_category']]; } if (isset($g['manufacturer'])) { $data['manufacturer'] = @$g['manufacturer']; } if (!empty($g['vendor'])) { $rs = $ST->select("SELECT * FROM sc_manufacturer WHERE name='" . SQL::slashes($g['vendor']) . "'"); if ($rs->next()) { $data['manufacturer_id'] = $rs->getInt('id'); } else { $data['manufacturer_id'] = $ST->insert('sc_manufacturer', array('name' => $g['vendor'])); } } if (!empty($g['name'])) { $data['name'] = $g['name']; } if (!empty($g['description'])) { $data['description'] = $g['description']; } if (!empty($g['html2'])) { $data['html2'] = $g['html2']; } if (!empty($g['weight_flg'])) { $data['weight_flg'] = $g['weight_flg'] == 'true' ? 1 : 0; } $rs = $ST->select("SELECT * FROM sc_shop_item WHERE ext_id='{$gid}' AND offer={$offer}"); if ($rs->next()) { $id = $rs->getInt('id'); $add_data = array(); foreach (array('category', 'manufacturer_id', 'weight_flg', 'name', 'price', 'in_stock', 'description', 'html2') as $k) { if (isset($data[$k]) && $rs->get($k) != $data[$k]) { $add_data[$k] = $data[$k]; } } if ($add_data) { foreach ($add_data as $k => $v) { if (!in_array($k, array('price', 'in_stock'))) { $add_data['sort3'] = 1; break; } } // if(isset($add_data['price']) && $rs->getFloat('price')!=$add_data['price']){ // $add_data['old_price']=$rs->getFloat('price'); // } $add_data['update_time'] = date('Y-m-d H:i:s'); $ST->update('sc_shop_item', $add_data, "id={$id}"); $cnt_upd++; $ST->insert('sc_shop_log', array('type' => 'goodsimport', 'time' => date('Y-m-d H:i:s'), 'data' => serialize(array('id' => $id) + $add_data))); } } else { if (empty($data['category'])) { continue; } $data['ext_id'] = $gid; $data['offer'] = $offer; $data['sort3'] = 1; $data['insert_time'] = date('Y-m-d H:i:s'); $id = $ST->insert('sc_shop_item', $data); $cnt_ins++; } //Свойства if (!empty($g['param'])) { foreach ($g['param'] as $p => $v) { $rs = $ST->select("SELECT id FROM sc_shop_prop WHERE name='" . SQL::slashes($p) . "'"); if ($rs->next()) { $pid = $rs->getInt('id'); } else { $pid = $ST->insert('sc_shop_prop', array('name' => $p)); } $rs = $ST->select("SELECT * FROM sc_shop_prop_val WHERE item_id={$id} AND prop_id={$pid}"); if ($rs->next()) { if ($v != $rs->get('value')) { $ST->update('sc_shop_prop_val', array('value' => $v), "id={$rs->get('id')}"); } } else { $ST->insert('sc_shop_prop_val', array('value' => $v, 'item_id' => $id, 'prop_id' => $pid)); } } } // continue; $filename = $CONFIG['CATALOG_PATH'] . '/goods/' . $id . '.jpg'; if (!empty($g['image_url']) && !file_exists(ROOT . $filename)) { $img_content = @file_get_contents($g['image_url']); if (!$img_content || strpos($img_content, 'rror')) { continue; } file_put_contents(ROOT . $filename, $img_content); $ST->update('sc_shop_item', array('img' => $filename), 'id=' . $id); $cnt_img++; } // } } $stop_time = time(); $t = $stop_time - $start_time; $result = date('Y-m-d H:i:s') . ' - Время загрузки=' . $t . '; Импортировано=' . $cnt_imp . '; Добавлено=' . $cnt_ins . '; Обновлено=' . $cnt_upd . '; Обновлено изображний=' . $cnt_img . "\r\n"; file_put_contents($log_file, $result, FILE_APPEND); return array('t' => $t, 'imp' => $cnt_imp, 'ins' => $cnt_ins, 'upd' => $cnt_upd, 'msg' => $result); } else { $result = date('Y-m-d H:i:s') . " - Список пуст\r\n"; file_put_contents($log_file, $result, FILE_APPEND); return array('msg' => $result); } return $result; }
function actSendOrder() { global $ST, $post; $basket = $this->getBasketInfo($post->get()); if ($error = $this->checkOrder($post, $basket)) { echo printJSON(array('error' => $error)); exit; } else { $address = $post->getString('address'); /* Информация о заказчике */ $data = array('phone' => $post->get('phone')); if ($city = $post->get('city')) { $data['city'] = $city; } if ($address) { $data['address'] = $address; } //Добавим реферала if ($refid = $post->getInt('refid')) { $rs = DB::select("SELECT * FROM sc_users WHERE u_id={$refid}"); if ($rs->next()) { $data['refid'] = $post->getInt('refid'); } else { //Если неправильный refid } } if (!$this->getUserId() && $post->getInt('reg') == 1) { //&& $post->exists('want_reg') if ($post->exists('mail')) { $data['login'] = $post->get('mail'); $data['mail'] = $post->get('mail'); if ($post->exists('auto_pass')) { //Всегда назначать пароль $password = substr(md5(time()), 0, 6); $data[] = "password=MD5('" . $password . "')"; } else { $password = $post->get('password'); $data[] = "password=MD5('" . SQL::slashes($password) . "')"; } if (!session_id()) { session_set_cookie_params(3600 * 24 * 15, '/'); session_start(); } $_SESSION['_USER']['u_id'] = $ST->insert('sc_users', $data, 'u_id'); //уведомление о регистрации $this->sendTemplateMail($data['mail'], 'notice_new_user', array('FROM_SITE' => FROM_SITE, 'LOGIN' => $data['login'], 'PASSWORD' => $password)); //уведомление о регистрации админу $this->sendTemplateMail($this->cfg('MAIL'), 'notice_new_user4admin', array('FROM_SITE' => FROM_SITE, 'LOGIN' => $data['login'], 'name' => $data['name'])); $this->noticeICQ($this->cfg('ICQ'), 'Новый пользователь на сайте'); } } elseif ($this->getUserId()) { //Обновим пользователя if (!empty($basket['bonus'])) { $data['bonus'] = $this->getUser('bonus') - $basket['bonus']; $inc = array('userid' => $this->getUserId(), 'sum' => $basket['bonus'], 'balance' => $data['bonus'], 'type' => 'bonus', 'description' => 'Списание бонуса', 'time' => date('Y-m-d H:i:s')); $ST->insert('sc_income', $inc); } $ST->update('sc_users', $data, 'u_id=' . $this->getUserId()); } $this->setUser($data); $data = array('userid' => $this->getUserId(), 'fullname' => $this->getUser('name'), 'mail' => $post->get('mail') ? $post->get('mail') : $this->getUser('mail'), 'pay_system' => $post->get('pay_system'), 'phone' => $post->get('phone'), 'additionally' => $post->get('additionally'), 'price' => $basket['sum'], 'total_price' => $basket['total_sum'], 'order_status' => 0, 'pay_system' => $post->get('pay_system'), 'delivery' => $basket['delivery'], 'pay_bonus' => $basket['bonus'], 'discount' => $basket['discount'], 'margin' => $basket['margin']); if (Cfg::get("SHOP_DELIVERY_ENABLED")) { $data['date'] = $post->get('date') ? dte($post->get('date'), 'Y-m-d') : date('Y-m-d'); $time = $post->getString('time'); if ($t = $this->enum('sh_delivery_time', $time)) { $time = $t; } $delivery_type = 1; //доставка курьером if ($post->getInt('delivery_type')) { $delivery_type = $post->getInt('delivery_type'); } if ($basket['delivery'] === false) { //доставка не возможна $delivery_type = 2; } $data['city'] = $address; $data['address'] = $post->get('city'); $data['delivery_type'] = $delivery_type; } // $order_data=array( // 'from_name'=>$post->get('from_name'), // 'from_phone'=>$post->get('from_phone'), // 'from_city'=>$post->get('from_city'), // 'remember'=>$post->get('remember'), // 'report'=>$post->get('report'), // 'call'=>$post->get('call'), // 'call_no_report'=>$post->get('call_no_report'), // ); // $data['order_data']=printJSON($order_data); // if(!trim($data['address'])){ // $data['address']=serialize(array( //// 'region'=>$post->get('region'), // 'city'=>$post->get('city'), // 'district'=>$post->get('district'), // 'street'=>$post->get('street'), // 'house'=>$post->get('house'), // 'flat'=>$post->get('flat'), // 'porch'=>$post->get('porch'), // 'floor'=>$post->get('floor'), // )); // // } //Добавим заказ $id = LibShop::addOrder($data, $basket['basket']); if ($refid = $post->getInt('refid')) { ShopBonus::addRefAwards($refid, $basket['basket']); } elseif ($refid = ShopBonus::getPromoRefId($post->get('promo'))) { ShopBonus::addRefAwards($refid, $basket['basket']); } $ps_href = ''; if (isset($data['pay_system']) && $data['pay_system'] == 3 && $data['total_price']) { //Если электронные платежи и есть сумма $rs1 = $ST->select("SELECT * FROM sc_pay_system WHERE name='paymaster'"); if ($rs1->next()) { include_once "core/lib/PSPaymaster.class.php"; $ps = new PSPaymaster(unserialize($rs1->get('config'))); $ps->setDesc('Покупка товара'); $ps->setSumm($data['total_price']); $ps->setEmail($this->getUser('mail')); $ps->setOrderNum($id); $ps_href = $ps->getUrl(); } } // $icq_notice = "Новый заказ на сайте {$_SERVER['HTTP_HOST']}\n"; // // // $icq_notice.="Итого: {$basket['sum']}\n"; // $icq_notice.="Заказчик: {$post->get('from_name')}\n"; // $icq_notice.="Контактный телефон: {$post->get('from_phone')}\n"; // $icq_notice.="Адрес: {$post->get('address')}\n"; //// $icq_notice.="Сообщение: {$post->get('comment')}\n"; // $icq_notice.="Время доставки: {$post->get('date')} {$post->get('time')}\n"; //уведомление о заказе пользователю $notice = $data; //+$order_data; if (!empty($notice['date'])) { $notice['date'] = dte($notice['date']); } // $notice['description']=''; // foreach (array('remember','report','call','call_no_report',) as $v){ // $notice['description'].=$this->enum('field_label',@"{$v}_{$notice[$v]}")."<br>"; // } $notice['ps_href'] = ''; if ($ps_href) { $notice['ps_href'] = "Для того, чтобы оплатить заказа перейдите по ссылке <a href=\"{$ps_href}\">ОПЛАТИТЬ</a>"; } $delivery_list = $this->enum('sh_delivery_type'); $pay_system_list = $this->enum('sh_pay_system'); $notice['ORDER_NUM'] = $order_num = $id; // $notice['ORDER_NUM']=$order_num; $notice['NAME'] = $this->getUser('name'); $notice['FROM_SITE'] = FROM_SITE; $notice['basket'] = $this->render(array_merge($basket, array('is_order' => true, 'is_letter' => true)), dirname(__FILE__) . '/basket_content.tpl.php'); $notice['delivery_type'] = @$delivery_list[$notice['delivery_type']]; $notice['pay_system'] = @$pay_system_list[$notice['pay_system']]; include 'function.tpl.php'; if (!empty($notice['address'])) { $notice['address'] = parsAddr($notice['address']); } // $url="http://{$_SERVER['HTTP_HOST']}/prnt/SHET/?id=$id&PHPSESSID=".session_id(); // $url="http://{$_SERVER['HTTP_HOST']}/prnt/SBER/?id=$id&PHPSESSID=".session_id(); // $content=file_get_contents($url); $att = array(); if (isset($data['pay_system']) && $data['pay_system'] == 1) { $url = "http://{$_SERVER['HTTP_HOST']}/prnt/SBERpdf/?id={$id}"; $notice['ps_href'] = "<a href=\"{$url}\">Распечатать счёт</a>"; // $att[]=array('name'=>'Счёт.xls','file'=>$url."&access=allow"); } /* if($post->getInt('is_jur')){ //Печатать не надо $url="http://{$_SERVER['HTTP_HOST']}/prnt/SchetWord/?id=$id"; $notice['ps_href']="<a href=\"{$url}\">Распечатать счёт</a>"; $att[]=array('name'=>'na_oplatu'.date('Y_m_d').'.doc','file'=>$url."&access=allow"); } */ $mail = $post->exists('mail') ? $post->get('mail') : $this->getUser('mail'); if ($mail) { $this->sendTemplateMail($post->get('mail'), 'notice_new_order', $notice, $att); } //уведомление о заказе админу // $mail_contacts=$this->enum('mail_contacts',$this->getRegion()); $this->sendTemplateMail($this->cfg('MAIL'), 'notice_new_order4admin', $notice); // $this->noticeICQ($this->cfg('ICQ'), $icq_notice); $d = $this->getOrderData(); unset($d['additionally']); $this->saveOrderData($d); $this->saveBasketData(array()); // setcookie('basket',null,0,'/');//Очистим корзину Cookie::set('order_id', $id); $redirect_href = "/catalog/success/?id={$id}"; if ($ps_href) { $redirect_href = $ps_href; } echo printJSON(array('id' => $id, 'order_num' => $order_num, 'error' => '', 'count' => $basket['count'], 'delivery' => $data['delivery'], 'total_price' => $data['total_price'], 'ps_href' => $notice['ps_href'], 'redirect_href' => $redirect_href, 'date' => "{$post->get('date')} {$post->get('time')}")); exit; } }