public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // check rights for this blog at first and unsubscribe user if he hasn't
     $sql = "SELECT c.id FROM blog_emailsubscription s\n        JOIN wa_contact c ON s.contact_id = c.id\n        WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $unsubscribe_contact_ids = array();
     foreach ($model->query($sql) as $row) {
         $rights = 1;
         try {
             $rights = blogHelper::checkRights($blog_id, $row['id'], blogRightConfig::RIGHT_READ);
         } catch (Exception $e) {
             $rights = 0;
         }
         if (!$rights) {
             $unsubscribe_contact_ids[] = $row['id'];
         }
     }
     if ($unsubscribe_contact_ids) {
         $em = new blogEmailsubscriptionModel();
         $em->deleteByField(array('contact_id' => $unsubscribe_contact_ids, 'blog_id' => $blog_id));
     }
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
 public function execute()
 {
     $model_settings = new waAppSettingsModel();
     $settings = $model_settings->get($key = array('shop', 'deliveryshop'));
     $model = new waModel();
     $domains = $model->query("SELECT * FROM site_domain")->fetchAll();
     $prices = $model->query("SELECT * FROM shop_deliveryshop_delivery")->fetchAll('domain');
     foreach ($domains as $d) {
         $tab = explode('.', $d['name']);
         $info[$d['name']]['tab_name'] = $tab[0];
         $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
         $change_tpl[$d['name']] = true;
         if (!file_exists($template_path)) {
             $template_path = wa()->getAppPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka.html', 'shop');
             $change_tpl[$d['name']] = false;
         }
         $template_content[$d['name']] = file_get_contents($template_path);
         unset($template_path);
     }
     $this->view->assign('info', $info);
     $this->view->assign('prices', $prices);
     $this->view->assign('change_tpl', $change_tpl);
     $this->view->assign('template', $template_content);
     $this->view->assign('settings', $settings);
 }
Пример #3
0
 public function execute()
 {
     $model = new waModel();
     $payment_model = new wacabPaymentModel();
     $payments = $payment_model->getAll();
     $apps_model = new wacabAppsModel();
     $apps = $apps_model->getByField('stat', 1, true);
     $total = $model->query('SELECT SUM(pay) FROM wacab_payment WHERE `apps_id` is not null')->fetchAll();
     $plugins_stat = array();
     foreach ($apps as $app) {
         $app_total = $model->query('SELECT SUM(pay) FROM wacab_payment WHERE `apps_id` = ' . $app['id'])->fetch();
         $app_count = $model->query('SELECT COUNT(*) FROM wacab_payment WHERE `pay` >= 0 AND `apps_id` = ' . $app['id'])->fetch();
         $app_return = $model->query('SELECT COUNT(*) FROM wacab_payment WHERE `pay` < 0 AND `apps_id` = ' . $app['id'])->fetch();
         $names = json_decode($app['name'], true);
         if ($app['parent'] == 'no_parent' || $app['parent'] == '') {
             $pname = $names[0];
         } else {
             $pname = $names[0] . " (" . $app['parent'] . ")";
         }
         $plugins_stat[] = array('id' => $app['app_id'], 'total' => $app_total[0], 'name' => $pname, 'count' => $app_count[0], 'return' => $app_return[0]);
     }
     $this->view->assign('total', $total);
     $this->view->assign('apps', $plugins_stat);
     $this->setTemplate(wacabHelper::getAppPath() . '/templates/actions/statistic/stat_page.html');
 }
 protected function getSql()
 {
     $model = new waModel();
     $where = array();
     if ($discountcard = waRequest::get('discountcard')) {
         $where[] = "discountcard LIKE '" . $model->escape($discountcard) . "'";
     }
     $sql = "FROM `shop_discountcards`" . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY `id` DESC";
     return $sql;
 }
Пример #5
0
 public function execute(&$params)
 {
     $master_id = $params['id'];
     $merge_ids = $params['contacts'];
     $m = new waModel();
     foreach (array(array('blog_comment', 'contact_id')) as $pair) {
         list($table, $field) = $pair;
         $sql = "UPDATE {$table} SET {$field} = :master WHERE {$field} in (:ids)";
         $m->exec($sql, array('master' => $master_id, 'ids' => $merge_ids));
     }
     return null;
 }
 public function postPublishAction($params)
 {
     $post_id = (int) $params['id'];
     $blog_id = (int) $params['blog_id'];
     // add subscribers to queue
     $sql = "REPLACE INTO blog_emailsubscription_log (post_id, contact_id, name, email, datetime)\n                SELECT " . $post_id . ", c.id, c.name, e.email, '" . date('Y-m-d H:i:s') . "' FROM blog_emailsubscription s\n                JOIN wa_contact c ON s.contact_id = c.id\n                JOIN wa_contact_emails e ON c.id = e.contact_id AND e.sort = 0\n                WHERE s.blog_id = " . $blog_id;
     $model = new waModel();
     $model->exec($sql);
     // save backend url for cron
     $app_settings_model = new waAppSettingsModel();
     $app_settings_model->set(array($this->app_id, $this->id), 'backend_url', wa()->getRootUrl(true) . wa()->getConfig()->getBackendUrl());
 }
 public function execute()
 {
     $term = waRequest::request('term');
     $limit = waRequest::request('limit', 30, 'int');
     if (mb_strlen($term) < 2) {
         return;
     }
     $type = waRequest::request('type', null, waRequest::TYPE_STRING_TRIM);
     $model = new waModel();
     if (strpos($term, '@') !== FALSE) {
         $contacts = new contactsCollection('/search/email*=' . $term);
     } else {
         $contacts = new contactsCollection();
         $t_a = preg_split("/\\s+/", $term);
         $cond = array();
         foreach ($t_a as $t) {
             $t = trim($t);
             if ($t) {
                 $t = $model->escape($t, 'like');
                 if ($type === 'person') {
                     $cond[] = "(c.firstname LIKE '{$t}%' OR c.middlename LIKE '{$t}%' OR c.lastname LIKE '{$t}%')";
                 } else {
                     if ($type === 'company') {
                         $cond[] = "c.name LIKE '{$t}%'";
                     } else {
                         $cond[] = "(c.firstname LIKE '{$t}%' OR c.middlename LIKE '{$t}%' OR c.lastname LIKE '{$t}%' OR c.name LIKE '{$t}%')";
                     }
                 }
             }
         }
         if ($cond) {
             $contacts->addWhere(implode(" AND ", $cond));
         }
     }
     if ($type) {
         if ($type === 'person') {
             $contacts->addWhere("is_company = 0");
         } else {
             if ($type === 'company') {
                 $contacts->addWhere("is_company = 1");
             }
         }
     }
     $this->response = array();
     $term_safe = htmlspecialchars($term);
     foreach ($contacts->getContacts('id,name,company,email', 0, $limit) as $c) {
         $name = $this->prepare($c['name'], $term_safe);
         $email = $this->prepare(ifset($c['email'][0], ''), $term_safe);
         $company = $this->prepare($c['company'], $term_safe);
         $this->response[] = array('label' => implode(', ', array_filter(array($name, $company, $email))), 'value' => $c['id'], 'name' => $c['name'], 'email' => ifset($c['email'][0], ''), 'company' => $c['company']);
     }
 }
 public function execute()
 {
     switch (waRequest::get('event')) {
         case 'del_trans':
             $model = new waModel();
             $model->query('TRUNCATE TABLE  `wacab_payment`');
             break;
         case 'del_reviews':
             $model = new waModel();
             $model->query('TRUNCATE TABLE  `wacab_review`');
             break;
     }
 }
 public function execute()
 {
     try {
         $data = waRequest::post();
         $model = new waModel();
         foreach ($data['data'] as $k => $v) {
             if ($v['id'] != 'new') {
                 $is = $model->query("SELECT * FROM shop_deliveryshop_pvz WHERE code = '" . $v['id'] . "' AND domain = '" . $k . "'")->fetchAssoc();
                 if (!$is) {
                     $d = $model->query("SELECT * FROM shop_deliveryshop_pvz WHERE code = '" . $v['id'] . "'")->fetchAssoc();
                     if ($d && $d['domain'] == '') {
                         $model->query("UPDATE shop_deliveryshop_pvz SET \n                                           address = '" . $v['address'] . "',\n                                           workTime = '" . $v['workTime'] . "',\n                                           email = '" . $v['email'] . "',\n                                           TK = '" . $v['TK'] . "',\n                                           note = '" . $v['note'] . "',\n                                           phone = '" . $v['phone'] . "',\n                                           domain = '" . $k . "'\n                                           WHERE id = '" . $d['id'] . "'");
                     } else {
                         $model->query("INSERT INTO shop_deliveryshop_pvz \n                                           (code, name, city, cityCode, workTime, address, phone, note, coordX, coordY, \n                                           weightMin, weightMax, TK, domain, status, email)\n                                           VALUES ('" . $v['id'] . "', '" . $d['name'] . "', '" . $d['city'] . "',\n                                           '" . $d['cityCode'] . "', '" . $v['workTime'] . "',\n                                           '" . $v['address'] . "', '" . $v['phone'] . "', '" . $v['note'] . "',\n                                           '" . $d['coordX'] . "', '" . $d['coordY'] . "', '" . $d['weightMin'] . "',\n                                           '" . $d['weightMax'] . "', '" . $v['TK'] . "', '" . $k . "', '" . $d['status'] . "', '" . $v['email'] . "')");
                     }
                 } else {
                     $model->query("UPDATE shop_deliveryshop_pvz SET \n                                       address = '" . $v['address'] . "',\n                                       workTime = '" . $v['workTime'] . "',\n                                       email = '" . $v['email'] . "',\n                                       TK = '" . $v['TK'] . "',\n                                       note = '" . $v['note'] . "',\n                                       phone = '" . $v['phone'] . "'\n                                       WHERE id = '" . $is['id'] . "' AND domain = '" . $k . "'");
                 }
             } else {
                 if ($v['city']) {
                     $city = $model->query("SELECT city FROM shop_deliveryshop_city WHERE cityCode = '" . $v['city'] . "'")->fetchField();
                     $model->query("INSERT INTO shop_deliveryshop_pvz \n                                       (code, name, city, cityCode, workTime, address, phone, note, coordX, coordY, \n                                       weightMin, weightMax, TK, domain, status, email)\n                                       VALUES ('" . $v['code'] . "', '" . $v['name'] . "', '" . $city . "',\n                                       '" . $v['city'] . "', '" . $v['workTime'] . "',\n                                       '" . $v['address'] . "', '" . $v['phone'] . "', '" . $v['note'] . "',\n                                       '" . $v['coordX'] . "', '" . $v['coordY'] . "', '" . $v['weightMin'] . "',\n                                       '" . $v['weightMax'] . "', '" . $v['TK'] . "', '" . $k . "', 'new', '" . $v['email'] . "')");
                 } else {
                     $this->response['stat'] = 'error';
                 }
             }
         }
         $this->response['message'] = 'ok';
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 public function execute()
 {
     $url = waRequest::param('url');
     $domain = waRequest::server('HTTP_HOST');
     $model = new waModel();
     //    $main_domain = $model->query("SELECT value FROM wa_app_settings WHERE app_id = 'webasyst' AND name = 'url'")->fetchField();
     $app_settings_model = new waAppSettingsModel();
     $main_domain = trim(str_replace(array('https', 'http', '://'), '', $app_settings_model->get('webasyst', 'url')), "/");
     $data = $model->query("\nSELECT\n  shop_deliveryshop_city_description.*\n, shop_deliveryshop_city.city\n, shop_deliveryshop_city.region\nFROM\n  shop_deliveryshop_city_description\nLEFT JOIN\n  shop_deliveryshop_city ON shop_deliveryshop_city_description.cityCode = shop_deliveryshop_city.cityCode\nLEFT JOIN\n  wa_region ON wa_region.code = shop_deliveryshop_city.region AND wa_region.country_iso3='rus'\nWHERE\n  (url = '{$url}' OR city = '{$url}')\nAND\n  domain IN ('{$domain}', '{$main_domain}')\nLIMIT 1\n  ")->fetchAssoc();
     // Уменьшаем стоимость доставки на сумму указанную в настройках плагина
     $delivery_compensation = $model->query("SELECT price FROM shop_deliveryshop_delivery WHERE domain = '" . $domain . "'")->fetchField();
     $delivery_compensation = intval($delivery_compensation);
     $delivery_price = intval($data['delivery_price']);
     $courier_price = intval($data['courier_price']);
     if ($delivery_price > $delivery_compensation) {
         $data['delivery_price'] = (int) (($delivery_price - $delivery_compensation) / 50) * 50;
         //Уменьшаем до ближайшего полтинника
     } else {
         $data['delivery_price'] = 0;
     }
     if ($courier_price > $delivery_compensation) {
         $data['courier_price'] = (int) (($courier_price - $delivery_compensation) / 50) * 50;
         //Уменьшаем до ближайшего полтинника
     } else {
         $data['courier_price'] = 0;
     }
     foreach (array('meta_title' => $main_domain, 'meta_description' => '', 'meta_keywords' => '', 'delivery_time' => '', 'courier_time' => '') as $key => $value) {
         $data[$key] = isset($data[$key]) ? $data[$key] : $value;
     }
     wa()->getResponse()->setTitle($data['meta_title']);
     wa()->getResponse()->setMeta('description', $data['meta_description']);
     wa()->getResponse()->setMeta('keywords', $data['meta_keywords']);
     $city_code = isset($data['cityCode']) ? $data['cityCode'] : 0;
     $pvz = $model->query("\nSELECT\n  shop_deliveryshop_pvz.*\nFROM\n  shop_deliveryshop_pvz\nWHERE\n  cityCode = {$city_code}\nAND\n  status = 'completed'\nAND\n  (domain IN ('{$domain}', '{$main_domain}') OR domain IS NULL)\n")->fetchAll();
     //$site_model = new siteDomainModel();
     //$domain_id = $site_model->getByName($domain);
     $domain_id = $model->query("SELECT id FROM site_domain WHERE name = '" . $domain . "'")->fetchField();
     $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $domain_id . '.html', false, 'shop', true);
     if (!file_exists($template_path)) {
         $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka.html', false, 'shop', true);
     }
     if (!file_exists($template_path)) {
         $template_path = wa()->getAppPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka.html', 'shop');
     }
     $this->view->assign('data', $data);
     $this->view->assign('pvz', $pvz);
     $this->view->assign('page', array('id' => null, 'name' => '', 'content' => $this->view->fetch($template_path)));
     $this->setThemeTemplate('page.html');
     waSystem::popActivePlugin();
 }
 protected function getSql()
 {
     $model = new waModel();
     $where = array();
     if ($discountcard = waRequest::get('discountcard')) {
         $where[] = "`discountcard` LIKE '" . $model->escape($discountcard) . "'";
     }
     if ($order_id = waRequest::get('order_id')) {
         $order_id = $this->decodeOrderId($order_id);
         $where[] = "`order_id` = '" . $order_id . "'";
     }
     $sql = "FROM `shop_discountcards_order`" . ($where ? " WHERE " . implode(" AND ", $where) : "") . " ORDER BY `order_id` DESC";
     return $sql;
 }
 public function execute()
 {
     $plugin_id = array('shop', 'deliveryshop');
     try {
         $app_settings_model = new waAppSettingsModel();
         $settings = waRequest::post('settings');
         $app_settings_model->set($plugin_id, 'status', (int) $settings['status']);
         $model = new waModel();
         $domains = $model->query("SELECT * FROM site_domain")->fetchAll();
         $reset_tpls = waRequest::post('reset_tpls');
         $template = waRequest::post('template');
         $prices = waRequest::post('prices');
         $this->response['pri'] = $prices;
         foreach ($domains as $d) {
             $id_price = $model->query("SELECT id FROM shop_deliveryshop_delivery WHERE domain = '" . $d['name'] . "'")->fetchField();
             if ($id_price) {
                 $model->query("UPDATE shop_deliveryshop_delivery SET price = '" . $prices[$d['name']]['price'] . "' WHERE domain = '" . $d['name'] . "'");
             } else {
                 $model->query("INSERT INTO shop_deliveryshop_delivery (domain, price)\n                                   VALUES ('" . $d['name'] . "', '" . $prices[$d['name']]['price'] . "')");
             }
             if (isset($reset_tpls[$d['name']])) {
                 $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
                 @unlink($template_path);
             } else {
                 if (!isset($template[$d['name']])) {
                     throw new waException('Не определён шаблон');
                 }
                 $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
                 if (!file_exists($template_path)) {
                     $template_path = wa()->getAppPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka.html', 'shop');
                 }
                 $template_content = file_get_contents($template_path);
                 if ($template_content != $template[$d['name']]) {
                     $template_path = wa()->getDataPath('plugins/deliveryshop/templates/actions/frontend/FrontendDostavka' . $d['id'] . '.html', false, 'shop', true);
                     $f = fopen($template_path, 'w');
                     if (!$f) {
                         throw new waException('Не удаётся сохранить шаблон. Проверьте права на запись ' . $template_path);
                     }
                     fwrite($f, $template[$d['name']]);
                     fclose($f);
                 }
             }
             $this->response['template'] = $template;
         }
         $this->response['message'] = "Сохранено";
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
Пример #13
0
 public static function getUserCategoryId($contact_id = null)
 {
     if ($contact_id === null) {
         $contact_id = wa()->getUser()->getId();
     }
     $model = new waModel();
     $sql = "SELECT * FROM `wa_contact_categories` WHERE `contact_id` = '" . $model->escape($contact_id) . "'";
     $categories = $model->query($sql)->fetchAll();
     $category_ids = array();
     $category_ids[] = 0;
     foreach ($categories as $category) {
         $category_ids[] = $category['category_id'];
     }
     return $category_ids;
 }
Пример #14
0
 public function deleteByField($field, $value = null)
 {
     if (is_array($field)) {
         $items = $this->getByField($field, $this->id);
     } else {
         $items = $this->getByField($field, $value, $this->id);
     }
     $res = false;
     if ($ids = array_keys($items)) {
         $res = parent::deleteByField($this->id, $ids);
         if ($res) {
             $type_upselling_model = new shopTypeUpsellingModel();
             $type_upselling_model->deleteByField('feature_id', $ids);
             $params_model = new shopProductFeaturesModel();
             $params_model->deleteByField('feature_id', $ids);
             $types = $this->groupByValueType($items);
             foreach ($types as $type => $type_ids) {
                 if ($model = self::getValuesModel($type)) {
                     $model->deleteByField('feature_id', $type_ids);
                 }
             }
             $this->deleteByField('parent_id', $ids);
         }
     }
     return $res;
 }
 public function updateById($id, $data, $options = null, $return_object = false)
 {
     if ($cache = wa()->getCache()) {
         $cache->delete('block_' . $id);
     }
     return parent::updateById($id, $data, $options, $return_object);
 }
 /**
  * Escapes special characters in a string for use in an SQL statement
  *
  * @param string
  * @return string
  */
 public function escape($value)
 {
     if (is_float($value)) {
         return str_replace(',', '.', (double) $value);
     }
     return $this->model->escape($value);
 }
Пример #17
0
 /**
  * Called by $this->load() to populate data into $this->persistent->rec_data
  *
  * Subclasses may override this method to tune load() behavior, e.g.
  * to load data lazily by field name passed in $field_or_db_row.
  * Subclasses overriding this should also call parent::doLoad() since the base class
  * uses it to load data from $this->m model.
  *
  * @param array $field_or_db_row see $this->load()
  * @throws waException
  */
 protected function doLoad($field_or_db_row = null)
 {
     // load from array?
     if (is_array($field_or_db_row)) {
         $fields = $this->m->getMetadata();
         $nulls = array_fill_keys(array_keys($fields), null);
         $this->persistent->setAll(array_intersect_key($field_or_db_row, $fields) + $nulls);
         return;
     }
     // requested field already loaded?
     if ($field_or_db_row) {
         // check if can be loaded from $this->m model
         if (!array_key_exists($field_or_db_row, $this->m->getMetadata())) {
             return;
         }
     } else {
         $loaded = true;
         foreach ($this->m->getMetadata() as $f => $v) {
             if (!$this->persistent->keyExists($f)) {
                 $loaded = false;
                 break;
             }
         }
         if ($loaded) {
             return;
         }
     }
     // load from model
     $row = $this->m->getById($this->id);
     if (!$row) {
         throw new waException('No record found in ' . $this->m->getTableName() . ' for id=' . $this->id, 404);
     }
     $this->persistent->setAll($row);
 }
 protected function query($sql, $one = true)
 {
     $q = $this->source->query($sql);
     if ($one) {
         return $q->fetch();
     } else {
         return $q->fetchAll();
     }
 }
 public function insert($data, $type = 0)
 {
     if (!isset($data['application_id'])) {
         $data['application_id'] = waSystem::getInstance()->getApp();
     }
     if (!isset($data['create_datetime'])) {
         $data['create_datetime'] = date('Y-m-d H:i:s');
     }
     return parent::insert($data);
 }
 public function getById($value)
 {
     $data = parent::getById($value);
     if ($data && $data['system_id'] && wa()->appExists($data['system_id'])) {
         $app = wa()->getAppInfo($data['system_id']);
         $data['name'] = $app['name'];
         $data['icon'] = wa()->getRootUrl(true) . $app['icon'][16];
     }
     return $data;
 }
Пример #21
0
 protected function generateSchema($app_id, $tables = array())
 {
     $plugin_id = false;
     if (strpos($app_id, '/') !== false) {
         list($app_id, $plugin_id) = explode('/', $app_id, 2);
         $path = wa()->getConfig()->getAppsPath($app_id, 'plugins/' . $plugin_id . '/lib/config/db.php');
     } else {
         $path = wa()->getConfig()->getAppsPath($app_id, 'lib/config/db.php');
     }
     if (waRequest::param('update') !== null) {
         $schema = (include $path);
         if (!$tables) {
             $tables = array_keys($schema);
         }
     } elseif ($tables) {
         if (!is_array($tables)) {
             $tables = array($tables);
         }
     } else {
         $prefix = $app_id == 'webasyst' ? 'wa' : $app_id;
         if ($plugin_id) {
             $prefix .= '_' . $plugin_id;
         }
         // @todo: use db adapter to get tables
         $sql = "SHOW TABLES LIKE '" . $prefix . "\\_%'";
         $tables = $this->model->query($sql)->fetchAll(null, true);
         $sql = "SHOW TABLES LIKE '" . $prefix . "'";
         $tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
     }
     $schema = array();
     foreach ($tables as $t) {
         echo $t . "\n";
         try {
             $schema[$t] = $this->model->describe($t, 1);
         } catch (waDbException $ex) {
             print "\tError: " . $ex->getMessage() . "\n";
         }
     }
     if ($schema) {
         // save schema to lib/config/db.php of the app
         waUtils::varExportToFile($this->schemaToString($schema), $path, false);
     }
 }
 public function execute()
 {
     try {
         $id = waRequest::post('id');
         $status = waRequest::post('status');
         $g = waRequest::post('g');
         $model = new waModel();
         if ($g == 'shop') {
             $model->query("UPDATE shop_deliveryshop_city SET status='" . $status . "' WHERE cityCode='" . $id . "'");
         } else {
             if ($g == 'delivery') {
                 $model->query("UPDATE shop_deliveryshop_pvz SET status='" . $status . "' WHERE code='" . $id . "'");
             }
         }
         $this->response['message'] = 'ok';
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 protected function getTables($prefix)
 {
     // @todo: use db adapter to get tables
     $tables = array();
     $prefix = $this->model->escape($prefix, 'l');
     $sql = "SHOW TABLES LIKE '{$prefix}'";
     $tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
     $sql = "SHOW TABLES LIKE '{$prefix}\\_%'";
     $tables = array_merge($tables, $this->model->query($sql)->fetchAll(null, true));
     return $tables;
 }
 public function execute()
 {
     $id = waRequest::post('id');
     $name = waRequest::post('name');
     $content = waRequest::post('content');
     $model = new waModel();
     if (is_numeric($id)) {
         $model->query("UPDATE shop_notifier_template SET name = '" . $name . "' WHERE id = '" . $id . "'");
     } else {
         $result = $model->query("INSERT INTO shop_notifier_template (name) VALUES ('" . $name . "')");
         $id = $result->lastInsertId();
     }
     $template_path = shopNotifierPlugin::path($id);
     $f = fopen($template_path, 'w');
     if (!$f) {
         throw new waException('Не удаётся сохранить шаблон. Проверьте права на запись ' . $template_path);
     }
     fwrite($f, $content);
     fclose($f);
     $this->response['result'] = array('id' => $id, 'name' => $name);
 }
 public function insert($data, $type = 0)
 {
     if (!isset($data['create_contact_id'])) {
         $data['create_contact_id'] = waSystem::getInstance()->getUser()->getId();
     }
     if (!isset($data['create_app_id'])) {
         $data['create_app_id'] = waSystem::getInstance()->getApp();
     }
     if (!isset($data['create_datetime'])) {
         $data['create_datetime'] = date("Y-m-d H:i:s");
     }
     return parent::insert($data, $type = 0);
 }
 public function execute()
 {
     switch (waRequest::get('event')) {
         case 'del_trans':
             $model = new waModel();
             $model->query('TRUNCATE TABLE  `wacab_payment`');
             break;
         case 'del_reviews':
             $model = new waModel();
             $model->query('TRUNCATE TABLE  `wacab_review`');
             break;
         case 'del_areports':
             $model = new waModel();
             $model->query('TRUNCATE TABLE  `wacab_areport`');
             break;
         case 'print_report':
             $model = new wacabAgentModel();
             $report = $model->getByField('rid', waRequest::get('rid'));
             echo $report['html'];
             break;
     }
 }
 public function execute()
 {
     try {
         $PvzList = simplexml_load_file('http://gw.edostavka.ru:11443/pvzlist.php');
         $model = new waModel();
         $update = 0;
         $insert = 0;
         if ($PvzList) {
             foreach ($PvzList->Pvz as $pvz) {
                 if (!($weight = $pvz->WeightLimit)) {
                     $weight['WeightMin'] = '';
                     $weight['WeightMax'] = '';
                 }
                 $id = $model->query("SELECT id FROM shop_deliveryshop_pvz WHERE code='" . (string) $pvz['Code'] . "'")->fetchField();
                 $id_city = $model->query("SELECT cityCode FROM shop_deliveryshop_city WHERE cityCode='" . (string) $pvz['CityCode'] . "'")->fetchField();
                 $youcity = new shopDeliveryshopPluginHelper();
                 $data = $youcity->getCitySearch($pvz[0]['City']);
                 if ($data[2] != 0 && is_numeric($data[2])) {
                     $region = $data[2];
                 } else {
                     if ($data[4] == 'ukr') {
                         $region = 'Украина';
                     } else {
                         if ($data[4] == 'kaz') {
                             $region = 'Казахстан';
                         }
                     }
                 }
                 if ($id_city) {
                     $model->query("UPDATE shop_deliveryshop_city SET \n                                       cityCode='" . mysql_escape_string((string) $pvz[0]['CityCode']) . "',\n                                       city='" . mysql_escape_string((string) $pvz[0]['City']) . "',\n                                       region='" . $region . "'\n                                       WHERE cityCode='" . $id_city . "'");
                 } else {
                     $model->query("INSERT INTO shop_deliveryshop_city\n                                       (cityCode, city, region, status)\n                                        VALUES ('" . mysql_escape_string((string) $pvz[0]['CityCode']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['City']) . "', '" . $region . "', 'new')");
                 }
                 if ($id) {
                     $model->query("UPDATE shop_deliveryshop_pvz SET\n                                       code='" . mysql_escape_string((string) $pvz['Code']) . "',\n                                       name='" . mysql_escape_string((string) $pvz[0]['Name']) . "',\n                                       cityCode='" . mysql_escape_string((string) $pvz[0]['CityCode']) . "',\n                                       city='" . mysql_escape_string((string) $pvz[0]['City']) . "',\n                                       workTime='" . mysql_escape_string((string) $pvz[0]['WorkTime']) . "',\n                                       address='" . mysql_escape_string((string) $pvz[0]['Address']) . "',\n                                       phone='" . mysql_escape_string((string) $pvz[0]['Phone']) . "',\n                                       note='" . mysql_escape_string((string) $pvz[0]['Note']) . "',\n                                       coordX='" . mysql_escape_string((string) $pvz[0]['coordX']) . "',\n                                       coordY='" . mysql_escape_string((string) $pvz[0]['coordY']) . "',\n                                       weightMin='" . mysql_escape_string((string) $weight['WeightMin']) . "',\n                                       weightMax='" . mysql_escape_string((string) $weight['WeightMax']) . "'\n                                       WHERE id='" . $id . "'");
                     $update++;
                 } else {
                     $model->query("INSERT INTO shop_deliveryshop_pvz\n                                       (code, name, cityCode, city, workTime, address, phone, note, coordX, coordY, weightMin, weightMax, status)\n                                        VALUES ('" . mysql_escape_string((string) $pvz['Code']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['Name']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['CityCode']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['City']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['WorkTime']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['Address']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['Phone']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['Note']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['coordX']) . "',\n                                        '" . mysql_escape_string((string) $pvz[0]['coordY']) . "',\n                                        '" . mysql_escape_string((string) $weight['WeightMin']) . "',\n                                        '" . mysql_escape_string((string) $weight['WeightMax']) . "',\n                                        'new')");
                 }
             }
         }
         $this->response['message'] = 'Импортировано';
         $this->response['update'] = $update;
         $this->response['ins'] = $insert;
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }
 /**
  * @return waModel
  * @throws waException
  */
 private function getSourceModel()
 {
     if (!$this->source) {
         $this->source_path = $this->option('path');
         if (substr($this->source_path, -1) != '/') {
             $this->source_path .= '/';
         }
         if (!file_exists($this->source_path)) {
             throw new waException(sprintf(_wp('Invalid PATH %s; %s'), $this->source_path, _wp('directory not exists')));
         }
         if (!file_exists($this->source_path . 'kernel/wbs.xml')) {
             throw new waException(sprintf(_wp('Invalid PATH %s; %s'), $this->source_path, _wp('file kernel/wbs.xml not found')));
         }
         /**
          *
          * @var SimpleXMLElement $wbs
          */
         $wbs = simplexml_load_file($this->source_path . 'kernel/wbs.xml');
         $this->dbkey = (string) $wbs->FRONTEND['dbkey'];
         $dkey_path = $this->source_path . 'dblist/' . $this->dbkey . '.xml';
         if (empty($this->dbkey) || !file_exists($dkey_path)) {
             throw new waException(sprintf(_wp('Invalid PATH %s; %s'), $this->source_path, sprintf(_wp('invalid file %s'), 'dblist/' . $this->dbkey . '.xml')));
         }
         /**
          *
          * @var SimpleXMLElement $dblist
          */
         $dblist = simplexml_load_file($dkey_path);
         $host_name = (string) $dblist->DBSETTINGS['SQLSERVER'];
         $host = $wbs->xPath('/WBS/SQLSERVERS/SQLSERVER[@NAME="' . htmlentities($host_name, ENT_QUOTES, 'utf-8') . '"]');
         if (!count($host)) {
             throw new waException(_wp('Invalid SQL server name'));
         }
         $host = $host[0];
         $port = (string) $host['PORT'];
         $this->sql_options = array('host' => (string) $host['HOST'] . ($port ? ':' . $port : ''), 'user' => (string) $dblist->DBSETTINGS['DB_USER'], 'password' => (string) $dblist->DBSETTINGS['DB_PASSWORD'], 'database' => (string) $dblist->DBSETTINGS['DB_NAME'], 'type' => function_exists('mysqli_connect') ? 'mysqli' : 'mysql');
         $this->source = new waModel($this->sql_options);
     } else {
         $this->source->ping();
     }
     return $this->source;
 }
Пример #29
0
 public function execute(&$params)
 {
     $master_id = $params['id'];
     $merge_ids = $params['contacts'];
     $all_ids = array_merge($merge_ids, array($master_id));
     $m = new waModel();
     //
     // All the simple cases: update contact_id in tables
     //
     foreach (array(array('shop_cart_items', 'contact_id'), array('shop_checkout_flow', 'contact_id'), array('shop_order', 'contact_id'), array('shop_order_log', 'contact_id'), array('shop_product', 'contact_id'), array('shop_product_reviews', 'contact_id'), array('shop_affiliate_transaction', 'contact_id')) as $pair) {
         list($table, $field) = $pair;
         $sql = "UPDATE {$table} SET {$field} = :master WHERE {$field} in (:ids)";
         $m->exec($sql, array('master' => $master_id, 'ids' => $merge_ids));
     }
     //
     // shop_affiliate_transaction
     //
     $balance = 0.0;
     $sql = "SELECT * FROM shop_affiliate_transaction WHERE contact_id=? ORDER BY id";
     foreach ($m->query($sql, $master_id) as $row) {
         $balance += $row['amount'];
         if ($row['balance'] != $balance) {
             $m->exec("UPDATE shop_affiliate_transaction SET balance=? WHERE id=?", $balance, $row['id']);
         }
     }
     $affiliate_bonus = $balance;
     //
     // shop_customer
     //
     // Make sure it exists
     $cm = new shopCustomerModel();
     $cm->createFromContact($master_id);
     $sql = "SELECT SUM(number_of_orders) FROM shop_customer WHERE contact_id IN (:ids)";
     $number_of_orders = $m->query($sql, array('ids' => $all_ids))->fetchField();
     $sql = "SELECT MAX(last_order_id) FROM shop_customer WHERE contact_id IN (:ids)";
     $last_order_id = $m->query($sql, array('ids' => $all_ids))->fetchField();
     $sql = "UPDATE shop_customer SET number_of_orders=?, last_order_id=?, affiliate_bonus=? WHERE contact_id=?";
     $m->exec($sql, ifempty($number_of_orders, 0), ifempty($last_order_id, null), ifempty($affiliate_bonus, 0), $master_id);
     if ($number_of_orders) {
         shopCustomers::recalculateTotalSpent($master_id);
     }
     wa('shop')->event('customers_merge', $params);
     return null;
 }
 public function execute()
 {
     try {
         $data = waRequest::post();
         $model = new waModel();
         foreach ($data['data'] as $k => $v) {
             $delivery_time = '{$delivery_time}';
             $delivery_price = '{$delivery_price}';
             $courier_time = '{$courier_time}';
             $courier_price = '{$courier_price}';
             if ($v['description'] == '<p><br></p>' || $v['description'] == '') {
                 $v['description'] = '';
             }
             if ($v['anons_shop'] == '<p><br></p>' || $v['anons_shop'] == '') {
                 $v['anons_shop'] = '';
             }
             if ($v['anons_delivery'] == '<p><br></p>' || $v['anons_delivery'] == '') {
                 $v['anons_delivery'] = '';
             }
             if ($v['id'] != 'new') {
                 $id = $model->query("SELECT id FROM shop_deliveryshop_city_description \n                                         WHERE cityCode='" . $v['id'] . "' AND domain='" . $k . "'")->fetchField();
                 $model->query("UPDATE shop_deliveryshop_city SET region = '" . $v['region'] . "' WHERE cityCode = '" . $v['id'] . "'");
                 if ($id) {
                     $model->query("UPDATE shop_deliveryshop_city_description SET\n                                       ID_TK = '" . $v['ID_TK'] . "',\n                                       delivery_time = '" . $v['delivery_time'] . "',\n                                       delivery_price = '" . $v['delivery_price'] . "',\n                                       courier_time = '" . $v['courier_time'] . "',\n                                       courier_price = '" . $v['courier_price'] . "',\n                                       description = '" . $v['description'] . "',\n                                       url = '" . $v['url'] . "',\n                                       anons_shop = '" . $v['anons_shop'] . "',\n                                       anons_delivery = '" . $v['anons_delivery'] . "',\n                                       meta_title = '" . $v['meta_title'] . "',\n                                       meta_keywords = '" . $v['meta_keywords'] . "',\n                                       meta_description = '" . $v['meta_description'] . "'\n                                       WHERE cityCode = '" . $v['id'] . "' AND domain = '" . $k . "'");
                 } else {
                     $model->query("INSERT INTO shop_deliveryshop_city_description\n                                       (cityCode, ID_TK, delivery_time, delivery_price, \n                                       courier_time, courier_price, description, meta_title,\n                                       meta_keywords, meta_description, domain, url, anons_shop, anons_delivery) VALUES\n                                       ('" . $v['id'] . "', '" . $v['ID_TK'] . "', '" . $v['delivery_time'] . "',\n                                       '" . $v['delivery_price'] . "', '" . $v['courier_time'] . "',\n                                       '" . $v['courier_price'] . "', '" . $v['description'] . "', '" . $v['meta_title'] . "',\n                                       '" . $v['meta_keywords'] . "', '" . $v['meta_description'] . "', '" . $k . "',\n                                       '" . $v['url'] . "', '" . $v['anons_shop'] . "', '" . $v['anons_delivery'] . "')");
                 }
             } else {
                 if ($v['region']) {
                     $model->query("INSERT INTO shop_deliveryshop_city_description\n                                       (cityCode, ID_TK, delivery_time, delivery_price, \n                                       courier_time, courier_price, description, meta_title,\n                                       meta_keywords, meta_description, domain, url, anons_shop, anons_delivery) VALUES\n                                       ('" . $v['IDcity'] . "', '" . $v['ID_TK'] . "', '" . $v['delivery_time'] . "',\n                                       '" . $v['delivery_price'] . "', '" . $v['courier_time'] . "',\n                                       '" . $v['courier_price'] . "', '" . $v['description'] . "', '" . $v['meta_title'] . "',\n                                       '" . $v['meta_keywords'] . "', '" . $v['meta_description'] . "', '" . $k . "',\n                                       '" . $v['url'] . "', '" . $v['anons_shop'] . "', '" . $v['anons_delivery'] . "')");
                     $model->query("INSERT INTO shop_deliveryshop_city \n                                       (cityCode, city, region, status) VALUES\n                                       ('" . $v['IDcity'] . "', '" . $v['city'] . "', '" . $v['region'] . "', 'new')");
                 } else {
                     $this->response['stat'] = 'error';
                 }
             }
         }
         $this->response['message'] = 'ok';
     } catch (Exception $e) {
         $this->setError($e->getMessage());
     }
 }