public function execute()
 {
     mb_internal_encoding("UTF-8");
     $query = waRequest::post('query');
     $query = strtolower($query);
     $collection_by_email = new waContactsCollection('/search/email*=' . $query . '/');
     $contacts_by_email = $collection_by_email->getContacts('*');
     $collection_by_name = new waContactsCollection('/search/name*=' . $query . '/');
     $contacts_by_name = $collection_by_name->getContacts('*');
     if (is_array($contacts_by_email) && is_array($contacts_by_name)) {
         $contacts = array_merge($contacts_by_email, $contacts_by_name);
     } else {
         if (is_array($contacts_by_email) || is_array($contacts_by_name)) {
             $contacts = is_array($contacts_by_email) ? $contacts_by_email : $contacts_by_name;
         } else {
             $contacts = array();
         }
     }
     $modelContactCategory = new waContactCategoryModel();
     $result = $modelContactCategory->getByField('name', $query);
     //        query("SELECT * FROM wa_contact_category WHERE name LIKE '%".mysql_escape_string($query)."%'")->fetchAll();
     if ($result) {
         $search['group'] = $result;
         $search['contacts'] = $contacts;
     } else {
         $search['group'] = array();
         $search['contacts'] = $contacts;
     }
     $this->response['search'] = $search;
 }
 function getOptions($id = null)
 {
     if (!$this->model) {
         $this->model = new waContactCategoryModel();
     }
     if (!$this->categories) {
         $this->categories = $this->model->getALl('id');
     }
     // Checklist options, category_id => name
     $options = array();
     foreach ($this->categories as $id => $row) {
         $options[$id] = $row['name'];
     }
     // Admins are allowed to see everything, and person outside of contacts app can see a list of categories too
     if (wa()->getApp() != 'contacts' || wa()->getUser()->getRights('contacts', 'category.all')) {
         return $options;
     }
     // Only load categories available for current user
     $crm = new contactsRightsModel();
     $allowed = $crm->getAllowedCategories();
     foreach ($options as $id => $row) {
         if (!isset($allowed[$id])) {
             unset($options[$id]);
         }
     }
     return $options;
 }
 public function execute()
 {
     // Only show categories available to current user
     $crm = new contactsRightsModel();
     $cm = new waContactCategoryModel();
     // List of categories user is allowed to add contacts to
     $categories = $cm->getAll('id');
     //        $allowed = $crm->getAllowedCategories();
     //        if ($allowed === true) {
     //            $allowed = $categories;
     //        }
     //        foreach($categories as $id => &$cat) {
     //            if (!isset($allowed[$id]) || $cat['system_id']) {
     //                unset($categories[$id]);
     //            }
     //            $cat = $cat['name'];
     //        }
     //        unset($cat);
     // Set of catorories that are always checked and disabled in list
     $d = waRequest::get('disabled');
     if (!is_array($d)) {
         $d = array($d);
     }
     $this->view->assign('categories', $categories);
     $this->view->assign('disabled', array_fill_keys($d, true));
 }
 public function execute()
 {
     $id = waRequest::post('id');
     if (is_numeric($id)) {
         $modelNotifierRule = new shopNotifierRuleModel();
         $result = $modelNotifierRule->getById($id);
         $result['data_contact'] = json_decode($result['data_contact'], true);
         if (count((array) $result['data_contact']['contact']) > 1) {
             $ids_contact = implode(',', (array) $result['data_contact']['contact']);
         } else {
             if (count((array) $result['data_contact']['contact']) == 1) {
                 foreach ($result['data_contact']['contact'] as $c) {
                     $ids_contact = $c;
                 }
             }
         }
         if (isset($ids_contact)) {
             $result['contacts'] = array();
             $collection = new waContactsCollection('/id/' . $ids_contact . '/');
             $result['contacts'] = $collection->getContacts('*');
         }
         if (array_key_exists("group", $result['data_contact']) && count($result['data_contact']['group'])) {
             $result['groups'] = array();
             $modelContactCategory = new waContactCategoryModel();
             foreach ($result['data_contact']['group'] as $group_id) {
                 $result['groups'][$group_id] = $modelContactCategory->getById($group_id);
             }
         }
         $result['state_name'] = (array) json_decode($result['state_name']);
         $this->response['result'] = $result;
         $this->response['message'] = 'ok';
     } else {
         $this->response['message'] = 'fail';
     }
 }
Ejemplo n.º 5
0
 public function execute()
 {
     $app_settings_model = new waAppSettingsModel();
     $settings = $app_settings_model->get(shopPricePlugin::$plugin_id);
     $ccm = new waContactCategoryModel();
     $categories = array(array('id' => 0, 'name' => 'Все покупатели'));
     foreach ($ccm->getAll() as $c) {
         if ($c['app_id'] == 'shop') {
             $categories[$c['id']] = $c;
         }
     }
     $price_model = new shopPricePluginModel();
     $prices = $price_model->getAll();
     $_prices = array();
     foreach ($prices as $price) {
         $_prices[$price['domain_hash']][] = $price;
     }
     $domain_routes = wa()->getRouting()->getByApp('shop');
     $domains_settings = shopPrice::getDomainsSettings();
     $this->view->assign('prices', $_prices);
     $this->view->assign('domain_routes', $domain_routes);
     $this->view->assign('categories', $categories);
     $this->view->assign('settings', $settings);
     $this->view->assign('domain_settings', $domains_settings);
 }
Ejemplo n.º 6
0
 public static function listGroups()
 {
     $ContactCategory = new waContactCategoryModel();
     $categories = $ContactCategory->select('*')->where("app_id='shop'")->order('name')->fetchAll();
     $cats = array(array('value' => '', 'title' => ''));
     foreach ($categories as $category) {
         $cats[] = array('value' => $category['id'], 'title' => htmlentities($category['name'], null, 'UTF-8'));
     }
     return $cats;
 }
 public function init()
 {
     $model = new waContactCategoryModel();
     $items = $model->getNames();
     $this->addItem('create', _w('Can add contacts'), 'checkbox');
     $this->addItem('category', _w('Available categories'), 'list', array('items' => $items, 'hint1' => 'all_checkbox'));
     wa()->event('rights.config', $this);
     if (!self::$model) {
         self::$model = new contactsRightsModel();
     }
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException('Access denied.');
     }
     $category = null;
     if ($id = waRequest::get('id')) {
         $cm = new waContactCategoryModel();
         $category = $cm->getById($id);
     }
     $this->view->assign('category', $category);
 }
 public function execute()
 {
     $cm = new waContactCategoryModel();
     // List of categories user is allowed to add contacts to
     $categories = $cm->select('*')->where('system_id IS NULL')->fetchAll('id');
     // Set of catorories that are always checked and disabled in list
     $d = waRequest::get('disabled');
     if (!is_array($d)) {
         $d = array($d);
     }
     $this->view->assign('categories', $categories);
     $this->view->assign('disabled', array_fill_keys($d, true));
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     if (!($id = waRequest::post('id'))) {
         throw new waException('no id');
     }
     $cm = new waContactCategoryModel();
     $cm->delete($id);
     $this->response['message'] = _w('Category has been deleted');
 }
 function getOptions($id = null)
 {
     if (!$this->model) {
         $this->model = new waContactCategoryModel();
     }
     if (!$this->categories) {
         $this->categories = $this->model->getAll('id');
     }
     // Checklist options, category_id => name
     $options = array();
     foreach ($this->categories as $id => $row) {
         $options[$id] = $row['name'];
     }
     return $options;
 }
 public function execute()
 {
     // Only show categories available to current user
     $crm = new contactsRightsModel();
     $cm = new waContactCategoryModel();
     // List of categories user is allowed to add contacts to
     $categories = $cm->getAll('id');
     // Set of catorories that are always checked and disabled in list
     $d = waRequest::get('disabled');
     if (!is_array($d)) {
         $d = array($d);
     }
     $this->view->assign('categories', $categories);
     $this->view->assign('disabled', array_fill_keys($d, true));
 }
 public function execute()
 {
     $this->view->assign('views', null);
     $this->view->assign('settings', $this->getUser()->getSettings('contacts'));
     $historyModel = new contactsHistoryModel();
     $this->view->assign('history', $historyModel->get());
     $cc = new contactsCollection();
     $this->view->assign('totalContacts', $cc->count());
     // only show categories available to current user
     //        $crm = new contactsRightsModel();
     $wcrm = new waContactRightsModel();
     $ccm = new waContactCategoryModel();
     //        $allowed = $crm->getAllowedCategories();
     //        $categories = array();
     //        if($allowed === true) {
     //            $categories = $ccm->getAll();
     //        } else if ($allowed) {
     //            foreach($ccm->getAll() as $cat) {
     //                if (isset($allowed[$cat['id']])) {
     //                    $categories[] = $cat;
     //                }
     //            }
     //        }
     $categories = $ccm->getAll();
     $this->view->assign('categories', $categories);
     // User views are only available to global admin
     $r = new waContactRightsModel();
     $this->view->assign('superadmin', FALSE);
     $this->view->assign('admin', FALSE);
     if (wa()->getUser()->getRights('webasyst', 'backend')) {
         $this->view->assign('superadmin', TRUE);
         $this->view->assign('admin', TRUE);
         //            $group_model = new waGroupModel();
         //            $this->view->assign('groups', $group_model->getAll());
         $cc = new contactsCollection('/users/all/');
         $this->view->assign('totalUsers', $cc->count());
     } else {
         if (wa()->getUser()->getRights('contacts', 'backend') >= 2) {
             $this->view->assign('admin', TRUE);
         }
     }
     // is user allowed to add contacts?
     $this->view->assign('show_create', $wcrm->get(null, null, 'create'));
     $event_params = array();
     $this->view->assign('backend_sidebar', wa()->event('backend_sidebar', $event_params, array('top_li')));
 }
Ejemplo n.º 14
0
 public function execute()
 {
     // Category counts
     // !!! Probably not the best idea to fetch category counts on the fly...
     $cm = new shopCustomerModel();
     $counts = $cm->getCategoryCounts();
     // Categories
     $ccm = new waContactCategoryModel();
     $categories = array();
     foreach ($ccm->getAll() as $c) {
         if ($c['app_id'] == 'shop') {
             $c['cnt'] = ifset($counts[$c['id']], 0);
             $categories[$c['id']] = $c;
         }
     }
     $this->view->assign('all_customers_count', $cm->countAll());
     $this->view->assign('contacts_url', wa()->getAppUrl('contacts'));
     $this->view->assign('categories', $categories);
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     $cm = new waContactCategoryModel();
     $id = waRequest::post('id');
     $name = waRequest::post('name', 'string');
     if (!$id) {
         if (!$name && $name !== '0') {
             throw new waException('No id and no name given.');
         }
         $id = $cm->add($name);
         $this->logAction('category_add', $id);
     } else {
         if ($name || $name === '0') {
             $cm->updateById($id, array('name' => $name));
         }
     }
     $this->response['id'] = $id;
 }
 public function execute()
 {
     $ccdm = new shopContactCategoryDiscountModel();
     if (waRequest::post()) {
         $categories = waRequest::post('categories', array());
         if (is_array($categories)) {
             $ccdm->save($categories);
         }
     }
     // Categories
     $categories = array();
     $ccm = new waContactCategoryModel();
     $values = $ccdm->getAll('category_id', true);
     foreach ($ccm->getAll('id') as $c) {
         if ($c['app_id'] == 'shop') {
             $c['value'] = (double) ifset($values[$c['id']], 0);
             $categories[$c['id']] = $c;
         }
     }
     $enabled = shopDiscounts::isEnabled('category');
     $this->view->assign('enabled', $enabled);
     $this->view->assign('categories', $categories);
 }
 public function execute()
 {
     $id = waRequest::request('id', 0, 'int');
     $category = null;
     $ccm = new waContactCategoryModel();
     if ($id) {
         $category = $ccm->getById($id);
     }
     if (waRequest::post()) {
         if ($id && waRequest::post('delete')) {
             $ccm->delete($id);
             exit;
         }
         $name = waRequest::request('name');
         $icon = waRequest::request('icon');
         if ($id && $category) {
             $category['name'] = $name;
             $category['icon'] = $icon;
             $ccm->updateById($id, array('name' => $name, 'icon' => $icon));
         } else {
             $category = array('name' => $name, 'icon' => $icon, 'app_id' => 'shop');
             $id = $ccm->insert($category);
             $category['id'] = $id;
         }
         echo "<script>window.location.hash = '#/category/{$id}';\$.customers.reloadSidebar();</script>";
         exit;
     }
     if (!$category) {
         $category = array('id' => '', 'name' => '', 'icon' => '', 'app_id' => '');
     }
     $icons = self::getIcons();
     if (empty($category['icon'])) {
         $category['icon'] = reset($icons);
     }
     $this->view->assign('category', $category);
     $this->view->assign('icons', $icons);
 }
Ejemplo n.º 18
0
 protected function categoryPrepare($id, $auto_title = false)
 {
     $category_model = new waContactCategoryModel();
     $category = $category_model->getById($id);
     if ($category) {
         if ($auto_title) {
             $this->title = $category['name'];
         }
         $this->update_count = array('model' => $category_model, 'id' => $id, 'count' => isset($category['cnt']) ? $category['cnt'] : 0);
     }
     $this->addJoin('wa_contact_categories', null, ':table.category_id = ' . (int) $id);
 }
 public function execute()
 {
     $modelNotifierConfig = new shopNotifierConfigModel();
     $modelNotifierLog = new shopNotifierLogModel();
     $n_date = array('w' => 'week', 'd' => 'days', 'm' => 'hour', 'h' => 'minute');
     $all_notifications = $modelNotifierConfig->getAll();
     foreach ($all_notifications as $notification) {
         $last_event_date = strtotime($modelNotifierLog->getLastDateByConfigId($notification['id']));
         $last_event = strtotime('+' . $notification['repeat_number_time'] . ' ' . $n_date[$notification['repeat_period']], $last_event_date);
         if (date('Y-m-d H:i:s', $last_event) < date('Y-m-d H:i:s')) {
             $states = (array) json_decode($notification['state_name']);
             $last_time = strtotime('-' . $notification['number_time'] . ' ' . $n_date[$notification['period']], $last_event_date);
             $orders = array();
             $orders_new = array();
             foreach ($states as $s) {
                 if ($s == 'new') {
                     $collection = new shopOrdersCollection('search/state_id=new&create_datetime<' . date('Y-m-d H:i:s', $last_time));
                     $orders_new = $collection->getOrders('*,params,items,contact');
                 } else {
                     $states_without_new[] = $s;
                 }
             }
             $state_for_collection = is_array($states_without_new) ? implode('||', $states_without_new) : $states_without_new[0];
             $collection = new shopOrdersCollection('search/state_id=' . $state_for_collection . '&update_datetime<' . date('Y-m-d H:i:s', $last_time));
             $orders = $collection->getOrders('*,params,items,contact');
             if (is_array($orders_new)) {
                 $orders = array_merge($orders, $orders_new);
             }
             $emails = array();
             $notification['data_contact'] = json_decode($notification['data_contact']);
             foreach ($notification['data_contact']->contact as $contact) {
                 $user = new waContact($contact);
                 //                    $email = array();
                 $email = $user->get('email');
                 $emails[$email[0]['value']] = $user->get('name');
             }
             if (!empty($notification['data_contact']->group)) {
                 $modelContactCategory = new waContactCategoryModel();
                 foreach ($notification['data_contact']->group as $group) {
                     $contacts = $modelContactCategory->getByField('category_id', $group);
                     //                      ->query("SELECT * FROM wa_contact_categories WHERE category_id = '".$gr."'")->fetchAll('contact_id');
                     foreach ($contacts as $key => $contact) {
                         $user = new waContact($key);
                         $email = array();
                         $email = $user->get('email');
                         $emails[$email[0]['value']] = $user->get('name');
                     }
                 }
             }
             $view = wa()->getView();
             $shop_config = $general = wa('shop')->getConfig()->getGeneralSettings();
             $from = $shop_config['email'];
             if (!$from) {
                 $from = '*****@*****.**';
             }
             if (!empty($notification['send_email']) && self::isValidEmail($notification['send_email'])) {
                 $from = $notification['send_email'];
             }
             $body = file_get_contents(shopNotifierPlugin::path($notification['template']));
             //TODO: File read error
             if ($notification['group_senders'] == 1) {
                 if ($notification['save_to_order_log'] == 1) {
                     $order_log_model = new shopOrderLogModel();
                     foreach ($orders as $order) {
                         $order_log_model->add(array('order_id' => $order['id'], 'contact_id' => wa()->getUser()->getId(), 'before_state_id' => $order['state_id'], 'after_state_id' => $order['state_id'], 'text' => 'Отправлено уведомление на адреса из оповещания ' . $notification['config_name'], 'action_id' => 'comment'));
                     }
                 }
                 $view->clearAllAssign();
                 $view->assign('orders', $orders);
                 $subject_string = 'Обратите внимание на заказы';
                 $subject = $view->fetch('string:' . $subject_string);
                 $body = $view->fetch('string:' . $body);
                 $message = new waMailMessage($subject, $body);
                 $message->setTo($emails);
                 $message->setFrom($from);
                 $message->send();
             } else {
                 foreach ($orders as $order) {
                     if ($notification['save_to_order_log'] == 1) {
                         $order_log_model = new shopOrderLogModel();
                         $order_log_model->add(array('order_id' => $order['id'], 'contact_id' => wa()->getUser()->getId(), 'before_state_id' => $order['state_id'], 'after_state_id' => $order['state_id'], 'text' => 'Отослано уведомление на емайлы из оповещания ' . $notification['config_name'], 'action_id' => 'comment'));
                     }
                     $view->clearAllAssign();
                     $view->assign('order', $order);
                     $subject_string = 'Заказ ' . shopHelper::encodeOrderId($order['id']);
                     $subject = $view->fetch('string:' . $subject_string);
                     $body = $view->fetch('string:' . $body);
                     $message = new waMailMessage($subject, $body);
                     $message->setTo($emails);
                     $message->setFrom($from);
                     $message->send();
                 }
             }
             $modelNotifierLog->add(array('config_id' => $notification['id']));
         }
     }
 }
 protected function categoryPrepare($id)
 {
     $category_model = new waContactCategoryModel();
     $category = $category_model->getById($id);
     if ($category) {
         $this->title = $category['name'];
         $this->update_count = array('model' => $category_model, 'id' => $id, 'count' => isset($category['cnt']) ? $category['cnt'] : 0);
     }
     $this->joins[] = array('table' => 'wa_contact_categories', 'alias' => 'ct');
     $this->where[] = "ct.category_id = " . (int) $id;
 }
Ejemplo n.º 21
0
<?php

$ccm = new waContactCategoryModel();
// clean up wa_contact_categories. Delete references to inexisted contacts
$sql = "DELETE ccs.* FROM `wa_contact_categories` ccs JOIN (\n  SELECT ccs.contact_id FROM `wa_contact_categories` ccs\n  LEFT JOIN `wa_contact` c ON c.id = ccs.contact_id\n  WHERE c.id IS NULL\n) t ON ccs.contact_id = t.contact_id";
$ccm->exec($sql);
// recalculate category counters
$ccm->recalcCounters();
Ejemplo n.º 22
0
 public function execute()
 {
     $category_id = waRequest::request('category', 0, 'int');
     $search = waRequest::request('search');
     $start = waRequest::request('start', 0, 'int');
     $limit = 50;
     $order = waRequest::request('order', '!last_order');
     $config = $this->getConfig();
     $use_gravatar = $config->getGeneralSettings('use_gravatar');
     $gravatar_default = $config->getGeneralSettings('gravatar_default');
     // Get customers
     $scm = new shopCustomerModel();
     list($customers, $total) = $scm->getList($category_id, $search, $start, $limit, $order);
     $has_more = $start + count($customers) < $total;
     $countries = array();
     foreach ($customers as &$c) {
         $c['affiliate_bonus'] = (double) $c['affiliate_bonus'];
         if (!$c['photo'] && $use_gravatar) {
             $c['photo'] = shopHelper::getGravatar(!empty($c['email']) ? $c['email'] : '', 50, $gravatar_default);
         } else {
             $c['photo'] = waContact::getPhotoUrl($c['id'], $c['photo'], 50, 50);
         }
         $c['categories'] = array();
         if (!empty($c['address']['region']) && !empty($c['address']['country'])) {
             $countries[$c['address']['country']] = array();
         }
     }
     unset($c);
     // Add region names to addresses
     if ($countries) {
         $rm = new waRegionModel();
         foreach ($rm->where('country_iso3 IN (?)', array_keys($countries))->query() as $row) {
             $countries[$row['country_iso3']][$row['code']] = $row['name'];
         }
         foreach ($customers as &$c) {
             if (!empty($c['address']['region']) && !empty($c['address']['country'])) {
                 $country = $c['address']['country'];
                 $region = $c['address']['region'];
                 if (!empty($countries[$country]) && !empty($countries[$country][$region])) {
                     $c['address']['region_formatted'] = $countries[$country][$region];
                 }
             }
         }
         unset($c);
     }
     // Contact categories
     $ccm = new waContactCategoryModel();
     $categories = $ccm->getAll('id');
     if ($customers) {
         $ccsm = new waContactCategoriesModel();
         foreach ($ccsm->getContactsCategories(array_keys($customers)) as $c_id => $list) {
             foreach ($list as $cat_id) {
                 if (!empty($categories[$cat_id])) {
                     $customers[$c_id]['categories'][$cat_id] = $categories[$cat_id];
                 }
             }
         }
     }
     // Set up lazy loading
     if (!$has_more) {
         // Do not trigger lazy loading, show total count at end of list
         $total_customers_number = $start + count($customers);
     } else {
         $total_customers_number = null;
         // trigger lazy loading
     }
     // List title and other params depending on list type
     if ($search) {
         $title = _w('Search results');
         $hash_start = '#/search/0/' . urlencode($search) . '/';
         $discount = null;
     } else {
         if ($category_id) {
             if (!empty($categories[$category_id])) {
                 $title = $categories[$category_id]['name'];
             } else {
                 $title = _w('Unknown category') . ' ' . $category_id;
             }
             $hash_start = '#/category/' . $category_id . '/';
             if (wa()->getSetting('discount_category')) {
                 $ccdm = new shopContactCategoryDiscountModel();
                 $discount = sprintf_wp('%s%% discount', $ccdm->getDiscount($category_id));
             } else {
                 $discount = null;
             }
         } else {
             $title = _w('All customers');
             $hash_start = '#/all/0/';
             $discount = null;
         }
     }
     $lazy_loading_params = array('limit=' . $limit, 'start=' . ($start + $limit), 'order=' . $order);
     if ($search) {
         $lazy_loading_params[] = 'search=' . $search;
     } else {
         if ($category_id) {
             $lazy_loading_params[] = 'category=' . $category_id;
         }
     }
     $lazy_loading_params = implode('&', $lazy_loading_params);
     $this->view->assign('cols', self::getCols());
     $this->view->assign('title', $title);
     $this->view->assign('order', $order);
     $this->view->assign('total', $total);
     $this->view->assign('discount', $discount);
     $this->view->assign('customers', $customers);
     $this->view->assign('hash_start', $hash_start);
     $this->view->assign('category_id', $category_id);
     $this->view->assign('lazy_loading_params', $lazy_loading_params);
     $this->view->assign('total_customers_number', $total_customers_number);
 }
Ejemplo n.º 23
0
<?php

$category_model = new waContactCategoryModel();
$category = $category_model->getBySystemId('blog');
$contact_model = new waContactModel();
$sql = "SELECT id FROM wa_contact WHERE create_app_id='blog'";
$contact_ids = $contact_model->query($sql)->fetchAll(null, true);
if ($contact_ids) {
    $contact_categories_model = new waContactCategoriesModel();
    $contact_categories_model->add($contact_ids, $category['id']);
}
 protected function getCategories()
 {
     $categories = waRequest::post('categories', array(), 'array_int');
     $cm = new waContactCategoryModel();
     return $cm->select('id')->where("system_id IS NULL AND id IN(" . implode(',', $categories) . ")")->fetchAll(null, true);
 }
Ejemplo n.º 25
0
 /**
  * Adds contact to a category.
  *
  * @param int|string $category_id Category's simple numeric or system string key (app_id)
  * @throws waException
  */
 public function addToCategory($category_id)
 {
     if (!$this->id) {
         throw new waException('Contact not saved!');
     }
     if (!is_numeric($category_id)) {
         $category_model = new waContactCategoryModel();
         $category = $category_model->getBySystemId($category_id);
         $category_id = $category['id'];
     }
     $contact_categories_model = new waContactCategoriesModel();
     if (!$contact_categories_model->inCategory($this->id, $category_id)) {
         $contact_categories_model->add($this->id, $category_id);
     }
 }
Ejemplo n.º 26
0
    private function reset()
    {
        /**
         * @event reset
         *
         * Notify plugins about reset all settings
         *
         * @param void
         * @return void
         */
        wa()->event('reset');
        //XXX hardcode
        $tables = array('shop_page', 'shop_page_params', 'shop_category', 'shop_category_params', 'shop_category_products', 'shop_category_routes', 'shop_product', 'shop_product_params', 'shop_product_features', 'shop_product_features_selectable', 'shop_product_images', 'shop_product_pages', 'shop_product_related', 'shop_product_reviews', 'shop_product_services', 'shop_product_skus', 'shop_product_stocks', 'shop_product_stocks_log', 'shop_search_index', 'shop_search_word', 'shop_tag', 'shop_product_tags', 'shop_set', 'shop_set_products', 'shop_stock', 'shop_feature', 'shop_feature_values_dimension', 'shop_feature_values_double', 'shop_feature_values_text', 'shop_feature_values_varchar', 'shop_feature_values_color', 'shop_feature_values_range', 'shop_type', 'shop_type_features', 'shop_type_services', 'shop_type_upselling', 'shop_service', 'shop_service_variants', 'shop_currency', 'shop_customer', 'shop_cart_items', 'shop_order', 'shop_order_items', 'shop_order_log', 'shop_order_log_params', 'shop_order_params', 'shop_affiliate_transaction', 'shop_checkout_flow', 'shop_notification', 'shop_notification_params', 'shop_coupon', 'shop_discount_by_sum', 'shop_tax', 'shop_tax_regions', 'shop_tax_zip_codes', 'shop_affiliate_transaction', 'shop_importexport');
        $model = new waModel();
        foreach ($tables as $table) {
            $exist = false;
            try {
                $model->query(sprintf("SELECT * FROM `%s` WHERE 0", $table));
                $exist = true;
                $model->query(sprintf("TRUNCATE `%s`", $table));
            } catch (waDbException $ex) {
                if ($exist) {
                    throw $ex;
                }
            }
        }
        $sqls = array();
        $sqls[] = 'UPDATE`shop_type` SET`count` = 0';
        $sqls[] = 'UPDATE`shop_set` SET`count` = 0';
        foreach ($sqls as $sql) {
            $model->query($sql);
        }
        $ccm = new waContactCategoryModel();
        $ccm->deleteByField('app_id', 'shop');
        $app_settings_model = new waAppSettingsModel();
        $currency_model = new shopCurrencyModel();
        $currency_model->insert(array('code' => 'USD', 'rate' => 1.0, 'sort' => 1), 2);
        $app_settings_model->set('shop', 'currency', 'USD');
        $app_settings_model->set('shop', 'use_product_currency', true);
        $paths = array();
        $paths[] = wa()->getDataPath('products', false, 'shop');
        $paths[] = wa()->getDataPath('products', true, 'shop');
        $paths[] = wa()->getTempPath();
        $config_path = wa()->getConfigPath('shop');
        foreach (waFiles::listdir($config_path, true) as $path) {
            if (!in_array($path, array('plugins.php', '..', '.'))) {
                $paths[] = $config_path . '/' . $path;
            }
        }
        $paths[] = wa()->getCachePath(null, 'shop');
        foreach ($paths as $path) {
            waFiles::delete($path, true);
        }
        $path = wa()->getDataPath('products', true, 'shop');
        waFiles::write($path . '/thumb.php', '<?php
$file = realpath(dirname(__FILE__)."/../../../../")."/wa-apps/shop/lib/config/data/thumb.php";

if (file_exists($file)) {
    include($file);
} else {
    header("HTTP/1.0 404 Not Found");
}
');
        waFiles::copy($this->getConfig()->getAppPath('lib/config/data/.htaccess'), $path . '/.htaccess');
        echo json_encode(array('result' => 'ok', 'redirect' => '?action=welcome'));
        exit;
    }
 public function execute()
 {
     $this->prepare();
     if ($query = trim(waRequest::post('query'), '/')) {
         if (strpos($query, '/') === false) {
             $h = $hash = 'search/' . $query;
         } else {
             $h = $hash = $query;
             if (substr($hash, 0, 14) == 'import/results') {
                 $h = str_replace('import/results', 'import', $hash);
             }
         }
     } else {
         $h = $hash = '';
     }
     $h_parts = explode('/', $h, 2);
     $add_fields = array();
     if ($h_parts[0] == 'explore') {
         $collection = new contactsCollection();
         $event_params = array('collection' => $collection, 'hash' => $h_parts[1]);
         $result = wa()->event('explore', $event_params);
         if ($result) {
             $result = reset($result);
             $add_fields = ifset($result['fields']);
             $this->response['add_fields'] = $add_fields;
             $this->response['name'] = $result['name'];
         }
     } else {
         $collection = new contactsCollection($h);
     }
     $this->response['fields'] = array();
     $fields = '*,photo_url_32,photo_url_96';
     if ($h_parts[0] === 'users') {
         $fields .= ',_access';
         $this->response['fields']['_access'] = array('id' => '_access', 'name' => _w('Access'), 'type' => 'Access', 'vertical' => true);
     }
     $collection->orderBy($this->sort, $this->order);
     $this->response['count'] = $collection->count();
     $view = waRequest::post('view');
     if ($view == 'list') {
         // Preload info to cache to avoid excess DB access
         $cm = new waCountryModel();
         $cm->preload();
     }
     $this->response['contacts'] = array_values($collection->getContacts($fields, $this->offset, $this->limit));
     $this->workupContacts($this->response['contacts']);
     $this->response['total_count'] = $collection->count();
     foreach ($this->response['contacts'] as $i => &$c) {
         $c['offset'] = $this->offset + $i;
     }
     unset($c);
     if ($view == 'list') {
         // Need to format field values correctly for this view.
         foreach ($this->response['contacts'] as &$cdata) {
             $c = new waContact($cdata['id']);
             $c->setCache($cdata);
             $data = $c->load('list,js') + $cdata;
             contactsHelper::normalzieContactFieldValues($data, waContactFields::getInfo($c['is_company'] ? 'company' : 'person', true));
             if (isset($data['photo'])) {
                 $data['photo'] = $c->getPhoto();
             }
             $c->removeCache(array_keys($cdata));
             $cdata = $data;
         }
         $this->response['fields'] = array_merge($this->response['fields'], contactsHelper::getFieldsDescription(array('title', 'name', 'photo', 'firstname', 'middlename', 'lastname', 'locale', 'timezone', 'jobtitle', 'company', 'sex', 'company_contact_id'), true));
         unset($cdata);
     }
     // for companies set name to company name
     // for contacts with empty name, set it to <no name>
     foreach ($this->response['contacts'] as &$c) {
         if (isset($c['name']) && trim($c['name'])) {
             continue;
         }
         if (isset($c['company']) && trim($c['company'])) {
             $c['name'] = $c['company'];
             unset($c['company']);
             continue;
         }
         $c['name'] = '<' . _w('no name') . '>';
     }
     unset($c);
     $title = $collection->getTitle();
     $hm = new contactsHistoryModel();
     if ($hash) {
         $type = explode('/', $hash);
         $hash = substr($hash, 0, 1) == '/' ? $hash : '/contacts/' . $hash;
         $type = $type[0];
         // if search query looks like a quick search then remove field name from header
         if ($type == 'search' && preg_match('~^/contacts/search/(name\\*=[^/]*|email\\*=[^/]*@[^/]*)/?$~i', $hash)) {
             $title = preg_replace("~^[^=]+=~", '', $title);
         }
         // save history
         if ($type == 'search') {
             $hm->save($hash, $title, $type, $this->response['count']);
             $this->logAction('search');
         }
         // Information about system category in categories view
         if (substr($hash, 0, 19) === '/contacts/category/') {
             $category_id = (int) substr($hash, 19);
             $cm = new waContactCategoryModel();
             $category = $cm->getById($category_id);
             if ($category && $category['system_id']) {
                 $this->response['system_category'] = $category['system_id'];
             }
         }
     }
     // Update history in user's browser
     $this->response['history'] = $hm->get();
     $this->response['title'] = $title;
 }
Ejemplo n.º 28
0
 /**
  * Delete one or more contacts and fire event сontacts.delete
  *
  * @event contacts.delete
  *
  * @param int|array $id - contact id or array of contact ids
  * @return bool
  */
 public function delete($id, $send_event = true)
 {
     if ($send_event) {
         // Fire @event contacts.delete allowing other applications to clean up their data
         if (!is_array($id)) {
             $id = array($id);
         }
         wa()->event(array('contacts', 'delete'), $id);
     }
     if (is_array($id)) {
         $nid = array();
         foreach ($id as $i) {
             $nid[] = -(int) $i;
         }
     } else {
         $nid = -(int) $id;
     }
     // Delete rights
     $right_model = new waContactRightsModel();
     $right_model->deleteByField('group_id', $nid);
     // Delete settings
     $setting_model = new waContactSettingsModel();
     $setting_model->deleteByField('contact_id', $id);
     // Delete emails
     $contact_email_model = new waContactEmailsModel();
     $contact_email_model->deleteByField('contact_id', $id);
     // Delete from groups
     $user_groups_model = new waUserGroupsModel();
     $user_groups_model->deleteByField('contact_id', $id);
     // Delete from contact lists
     if (class_exists('contactsContactListsModel')) {
         // @todo: Use plugin for contacts
         $contact_lists_model = new contactsContactListsModel();
         $contact_lists_model->deleteByField('contact_id', $id);
     }
     // Delete from contact rights
     $contact_rights_model = new contactsRightsModel();
     $contact_rights_model->deleteByField('group_id', $nid);
     // Delete data
     $contact_data_model = new waContactDataModel();
     $contact_data_model->deleteByField('contact_id', $id);
     $contact_data_text_model = new waContactDataTextModel();
     $contact_data_text_model->deleteByField('contact_id', $id);
     // Dalete from categories
     $contact_categories_model = new waContactCategoriesModel();
     $category_ids = array_keys($contact_categories_model->getByField('contact_id', $id, 'category_id'));
     $contact_categories_model->deleteByField('contact_id', $id);
     // update counters in wa_contact_category
     $contact_category_model = new waContactCategoryModel();
     $contact_category_model->recalcCounters($category_ids);
     //        // Delete contact from logs
     //        $login_log_model = new waLoginLogModel();
     //        $login_log_model->deleteByField('contact_id', $id);
     // Clear references
     $this->updateByField(array('company_contact_id' => $id), array('company_contact_id' => 0));
     // Delete contact
     return $this->deleteById($id);
 }
 public function execute()
 {
     $this->prepare();
     if ($query = trim(waRequest::post('query'), '/')) {
         if (strpos($query, '/') === false) {
             $h = $hash = 'search/' . $query;
         } else {
             $h = $hash = $query;
             if (substr($hash, 0, 14) == 'import/results') {
                 $h = str_replace('import/results', 'import', $hash);
             }
         }
     } else {
         $h = $hash = '';
     }
     $collection = $this->getCollection($h);
     $collection->orderBy($this->sort, $this->order);
     $this->response['count'] = $collection->count();
     $view = waRequest::post('view');
     switch ($view) {
         case 'list':
             $fields = '*';
             break;
         case 'thumbs':
             $fields = 'id,name,photo';
             break;
         case 'table':
         default:
             $fields = waRequest::post('fields');
     }
     if ($view == 'list') {
         // Preload info to cache to avoid excess DB access
         $cm = new waCountryModel();
         $cm->preload();
     }
     if ($hash && $fields != '*') {
         if ($wf = $collection->getWhereFields()) {
             $fields = $fields . "," . implode(",", $wf);
         }
         $this->response['fields'] = explode(',', $fields);
     }
     $this->response['contacts'] = array_values($collection->getContacts($fields, $this->offset, $this->limit));
     if ($view == 'list') {
         // Need to format field values correctly for this view.
         foreach ($this->response['contacts'] as &$cdata) {
             $c = new waContact($cdata['id']);
             $c->setCache($cdata);
             $data = $c->load('list,js') + $cdata;
             if (isset($data['photo'])) {
                 $data['photo'] = $c->getPhoto();
             }
             $c->removeCache(array_keys($cdata));
             $cdata = $data;
         }
         unset($cdata);
     }
     // for companies set name to company name
     // for contacts with empty name, set it to <no name>
     foreach ($this->response['contacts'] as &$c) {
         if (isset($c['name']) && trim($c['name'])) {
             continue;
         }
         if (isset($c['company']) && trim($c['company'])) {
             $c['name'] = $c['company'];
             unset($c['company']);
             continue;
         }
         $c['name'] = '<' . _w('no name') . '>';
     }
     unset($c);
     $title = $collection->getTitle();
     if ($hash) {
         $type = explode('/', $hash);
         $hash = substr($hash, 0, 1) == '/' ? $hash : '/contacts/' . $hash;
         $type = $type[0];
         // if search query looks like a quick search then remove field name from header
         if ($type == 'search' && preg_match('~^/contacts/search/(name\\*=[^/]*|email\\*=[^/]*@[^/]*)/?$~i', $hash)) {
             $title = preg_replace("~^[^=]+=~", '', $title);
         }
         // save history
         if ($type == 'search' || $type == 'import') {
             $history = new contactsHistoryModel();
             if ($history->save($hash, $title, $type, $this->response['count'])) {
                 // new search performed, save to statistics log
                 $this->log('search', 1);
             }
         }
         // Information about system category in categories view
         if (substr($hash, 0, 19) === '/contacts/category/') {
             $category_id = (int) substr($hash, 19);
             $cm = new waContactCategoryModel();
             $category = $cm->getById($category_id);
             if ($category && $category['system_id']) {
                 $this->response['system_category'] = $category['system_id'];
             }
         }
     }
     // Update history in user's browser
     $historyModel = new contactsHistoryModel();
     $this->response['history'] = $historyModel->get();
     $this->response['title'] = $title;
 }