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';
     }
 }
 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()
 {
     $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.º 4
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);
 }
 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;
 }
 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;
 }
 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;
 }