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'))); }
public function getLastViewContext() { if ($this->getRequest()->get('last_hash') === null) { return null; } $params = array('hash' => $this->getRequest()->get('last_hash', ''), 'sort' => $this->getRequest()->get('sort', ''), 'order' => $this->getRequest()->get('order', 1, 'int') ? ' ASC' : ' DESC', 'offset' => $this->getRequest()->get('offset', 0)); $context = null; $plugins_context = wa()->event('backend_last_view_context', $params); foreach ($plugins_context as $cntx) { if (!empty($cntx)) { $context = $cntx; break; } } if (!$context) { $hash = $params['hash']; $sort = $params['sort']; $order = $params['order']; $offset = $params['offset']; $collection = new contactsCollection($hash); if ($sort) { $collection->orderBy($sort, $order); } $total_count = $collection->count(); $ids = array_keys($collection->getContacts('id', max($offset - 1, 0), 3)); $prev = null; $next = null; if ($offset > 0) { $prev = $ids[0]; if ($offset < $total_count - 1) { $next = $ids[2]; } } else { if ($offset < $total_count - 1) { $next = $ids[1]; } } $context = array('total_count' => $total_count, 'offset' => $offset, 'prev' => $prev, 'next' => $next); } return $context; }
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; }