public function execute()
 {
     $ids = waRequest::post('id', array(), 'array_int');
     if (!$ids) {
         $ids = (int) waRequest::get('id');
         if (!$ids) {
             throw new Exception('No ids specified.');
         }
         $ids = array($ids);
     }
     // do not try to delete self
     if (in_array($this->getUser()->getId(), $ids)) {
         die('<p>' . _w('You can not delete yourself.') . '</p><p>' . _w('Please eliminate yourself from deletion list.') . '</p>');
     }
     // Only allow actions with contacts available for current user
     if (!$this->getRights('category.all')) {
         $crm = new contactsRightsModel();
         $ccm = new waContactCategoriesModel();
         $allowed = array_keys($crm->getAllowedCategories());
         foreach ($ccm->getContactsCategories($ids) as $id => $cats) {
             if (!array_intersect($allowed, $cats)) {
                 throw new waRightsException('Access denied');
             }
         }
     }
     $superadmin = wa()->getUser()->getRights('webasyst', 'backend');
     $result = wa()->event('links', $ids);
     $this->view->assign('apps', wa()->getApps());
     $links = array();
     foreach ($result as $app_id => $app_links) {
         foreach ($app_links as $contact_id => $contact_links) {
             if ($contact_links) {
                 $links[$contact_id][$app_id] = $contact_links;
             }
         }
     }
     // Do not allow non-superadmin to remove users
     if (!$superadmin) {
         $um = new waUserModel();
         $users = array_keys($um->getByField(array('id' => $ids, 'is_user' => 1), 'id'));
         foreach ($users as $user_id) {
             if (!isset($links[$user_id]['contacts'])) {
                 $links[$user_id]['contacts'] = array();
             }
             $links[$user_id]['contacts'][] = array('user', 1);
         }
     }
     $contact_model = new waContactModel();
     $this->view->assign('ids', $superadmin ? $ids : array_diff($ids, array_keys($links)));
     $this->view->assign('contacts', $contact_model->getName(array_keys($links)));
     $this->view->assign('superadmin', $superadmin);
     $this->view->assign('all', count($ids));
     $this->view->assign('links', $links);
 }
 public function execute()
 {
     $customer_id = waRequest::request('customer_id', 0, 'int');
     $category_id = waRequest::request('category_id', 0, 'int');
     if (!$customer_id || !$category_id) {
         return;
     }
     $ccm = new waContactCategoriesModel();
     $ccm->add($customer_id, $category_id);
     $cm = new shopCustomerModel();
     $this->response['count'] = $cm->getCategoryCounts($category_id);
 }
 protected function addToCategory()
 {
     $contacts = waRequest::post('contacts', array(), 'array_int');
     $categories = waRequest::post('categories', array(), 'array_int');
     $ccm = new waContactCategoriesModel();
     $ccm->add($contacts, $categories);
     $contacts = count($contacts);
     $categories = count($categories);
     $this->response['message'] = sprintf(_w("%d contact has been added", "%d contacts have been added", $contacts), $contacts);
     $this->response['message'] .= ' ';
     $this->response['message'] .= sprintf(_w("to %d category", "to %d categories", $categories), $categories);
 }
 /**
  * Обработчик хука signup
  *
  * @param waContact $contact
  */
 public function handlerSignup($contact)
 {
     $category_id = $this->getSettings('category_id');
     $ContactCategory = new waContactCategoryModel();
     // проверим на всякий случай есть-ли еще такая категория
     // а то вдруг ее какой-нибудь дурак удалил, а в настройке плагина она осталась
     // ресурсов на проверку нужно мало, а дураков на свете много
     $category_id = $ContactCategory->select('id')->where('id=:id', array('id' => $category_id))->fetchField();
     if ($contact instanceof waContact && $contact->getId() && $category_id) {
         $ContactCategories = new waContactCategoriesModel();
         $ContactCategories->add($contact->getId(), $category_id);
     }
 }
 public function execute()
 {
     $superadmin = $this->getUser()->getRights('webasyst', 'backend');
     $contacts = waRequest::post('id', array(), 'array_int');
     // do not try to delete self
     if (in_array($this->getUser()->getId(), $contacts)) {
         throw new waRightsException('Access denied: attempt to delete own account.');
     }
     // Only allow actions with contacts available for current user
     if (!$this->getRights('category.all')) {
         $crm = new contactsRightsModel();
         $ccm = new waContactCategoriesModel();
         $allowed = array_keys($crm->getAllowedCategories());
         foreach ($ccm->getContactsCategories($contacts) as $id => $cats) {
             if (!array_intersect($allowed, $cats)) {
                 throw new waRightsException('Access denied: no access to contact ' . $id);
             }
         }
     }
     // Deletion of contacts with links to other applications is only allowed to superadmins
     if (!$superadmin && ($links = wa()->event('links', $contacts))) {
         foreach ($links as $app_id => $l) {
             foreach ($l as $contact_id => $contact_links) {
                 if ($contact_links) {
                     throw new waRightsException('Access denied: only superadmin is allowed to delete contacts with links to other applications.');
                 }
             }
         }
     }
     // Are there users among $contacts?
     $um = new waUserModel();
     $users = array_keys($um->getByField(array('id' => $contacts, 'is_user' => 1), 'id'));
     // deletion of users is only allowed to superadmins
     if (!$superadmin && $users) {
         throw new waRightsException('Access denied: only superadmin is allowed to delete users.');
     }
     // Revoke user access before deletion
     foreach ($users as $user_id) {
         waUser::revokeUser($user_id);
     }
     // Bye bye...
     $contact_model = new waContactModel();
     $contact_model->delete($contacts);
     // also throws a contacts.delete event
     $this->response['deleted'] = count($contacts);
     $this->response['message'] = sprintf(_w("%d contact has been deleted", "%d contacts have been deleted", $this->response['deleted']), $this->response['deleted']);
     $this->log('contact_delete', count($contacts));
 }
 protected function addToCategory()
 {
     $contacts = waRequest::post('contacts', array(), 'array_int');
     $categories = $this->getCategories();
     $ccm = new waContactCategoriesModel();
     $ccm->add($contacts, $categories);
     foreach ($categories as $category_id) {
         $c = new waContactsCollection("/category/" . $category_id);
         $this->response['count'][$category_id] = $c->count();
     }
     $contacts = count($contacts);
     $categories = count($categories);
     $this->response['message'] = sprintf(_w("%d contact has been added", "%d contacts have been added", $contacts), $contacts);
     $this->response['message'] .= ' ';
     $this->response['message'] .= sprintf(_w("to %d category", "to %d categories", $categories), $categories);
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException('Access denied.');
     }
     $contacts = waRequest::post('contacts', array(), 'array_int');
     $categories = waRequest::post('categories', array(), 'array_int');
     if (!$contacts || !$categories) {
         return;
     }
     $ccm = new waContactCategoriesModel();
     $ccm->remove($contacts, $categories);
     $contacts = count($contacts);
     $categories = count($categories);
     $this->response['message'] = sprintf(_w("%d contact has been removed", "%d contacts have been removed", $contacts), $contacts);
     $this->response['message'] .= ' ';
     $this->response['message'] .= sprintf(_w("from %d category", "from %d categories", $categories), $categories);
 }
 public function execute()
 {
     // only allowed to global admin
     if (!wa()->getUser()->getRights('webasyst', 'backend')) {
         throw new waRightsException(_w('Access denied'));
     }
     $contacts = waRequest::post('contacts', array(), 'array_int');
     $categories = waRequest::post('categories', array(), 'array_int');
     $ccm = new waContactCategoriesModel();
     $ccm->add($contacts, $categories);
     foreach ($categories as $category_id) {
         $c = new waContactsCollection("/category/" . $category_id);
         $this->response['count'][$category_id] = $c->count();
     }
     $contacts = count($contacts);
     $categories = count($categories);
     $this->response['message'] = sprintf(_w("%d contact has been added", "%d contacts have been added", $contacts), $contacts);
     $this->response['message'] .= ' ';
     $this->response['message'] .= sprintf(_w("to %d category", "to %d categories", $categories), $categories);
 }
Exemple #9
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);
     }
 }
 /**
  * Delete category by ID
  * @param int $id
  * @return boolean
  */
 public function delete($id)
 {
     $ccm = new waContactCategoriesModel();
     $ccm->deleteByField('category_id', $id);
     return $this->deleteById($id);
 }
 /** Using $this->id get waContact and save it in $this->contact;
  * Load vars into $this->view specific to waContact. */
 protected function getContactInfo()
 {
     $system = wa();
     if ($this->id == $system->getUser()->getId()) {
         $this->contact = $system->getUser();
         $this->view->assign('own_profile', true);
     } else {
         $this->contact = new waContact($this->id);
         $this->view->assign('own_profile', false);
     }
     $exists = $this->contact->exists();
     if ($exists) {
         $this->view->assign('contact', $this->contact);
         // who created this contact and when
         $this->view->assign('contact_create_time', waDateTime::format('datetime', $this->contact['create_datetime'], $system->getUser()->getTimezone()));
         if ($this->contact['create_contact_id']) {
             try {
                 $author = new waContact($this->contact['create_contact_id']);
                 if ($author['name']) {
                     $this->view->assign('author', $author);
                 }
             } catch (Exception $e) {
                 // Contact not found. Ignore silently.
             }
         }
         $this->view->assign('top', $this->contact->getTopFields());
         // Main contact editor data
         $fieldValues = $this->contact->load('js', true);
         $m = new waContactModel();
         if (isset($fieldValues['company_contact_id'])) {
             if (!$m->getById($fieldValues['company_contact_id'])) {
                 $fieldValues['company_contact_id'] = 0;
                 $this->contact->save(array('company_contact_id' => 0));
             }
         }
         $contactFields = waContactFields::getInfo($this->contact['is_company'] ? 'company' : 'person', true);
         // Only show fields that are allowed in own profile
         if (!empty($this->params['limited_own_profile'])) {
             $allowed = array();
             foreach (waContactFields::getAll('person') as $f) {
                 if ($f->getParameter('allow_self_edit')) {
                     $allowed[$f->getId()] = true;
                 }
             }
             $fieldValues = array_intersect_key($fieldValues, $allowed);
             $contactFields = array_intersect_key($contactFields, $allowed);
         }
         contactsHelper::normalzieContactFieldValues($fieldValues, $contactFields);
         $this->view->assign('contactFields', $contactFields);
         $this->view->assign('contactFieldsOrder', array_keys($contactFields));
         $this->view->assign('fieldValues', $fieldValues);
         // Contact categories
         $cm = new waContactCategoriesModel();
         $this->view->assign('contact_categories', array_values($cm->getContactCategories($this->id)));
     } else {
         $this->view->assign('contact', array('id' => $this->id));
     }
     return $exists;
 }
 /**
  * Merge given contacts into master contact, save, send merge event, then delete slaves.
  *
  * !!! Probably should move it into something like contactsHelper
  *
  * @param array $merge_ids list of contact ids
  * @param int $master_id contact id to merge others into
  * @return array
  */
 public static function merge($merge_ids, $master_id)
 {
     $merge_ids[] = $master_id;
     // List of contacts to merge
     $collection = new contactsCollection('id/' . implode(',', $merge_ids));
     $contacts_data = $collection->getContacts('*');
     // Master contact data
     if (!$master_id || !isset($contacts_data[$master_id])) {
         throw new waException('No contact to merge into.');
     }
     $master_data = $contacts_data[$master_id];
     unset($contacts_data[$master_id]);
     $master = new waContact($master_id);
     $result = array('total_requested' => count($contacts_data) + 1, 'total_merged' => 0, 'error' => '', 'users' => 0);
     if ($master_data['photo']) {
         $filename = wa()->getDataPath(waContact::getPhotoDir($master_data['id']) . "{$master_data['photo']}.original.jpg", true, 'contacts');
         if (!file_exists($filename)) {
             $master_data['photo'] = null;
         }
     }
     $data_fields = waContactFields::getAll('enabled');
     $check_duplicates = array();
     // field_id => true
     $update_photo = null;
     // if need to update photo here it is file paths
     // merge loop
     foreach ($contacts_data as $id => $info) {
         if ($info['is_user'] > 0) {
             $result['users']++;
             unset($contacts_data[$id]);
             continue;
         }
         foreach ($data_fields as $f => $field) {
             if (!empty($info[$f])) {
                 if ($field->isMulti()) {
                     $master->add($f, $info[$f]);
                     $check_duplicates[$f] = true;
                 } else {
                     // Field does not allow multiple values.
                     // Set value if no value yet.
                     if (empty($master_data[$f])) {
                         $master[$f] = $master_data[$f] = $info[$f];
                     }
                 }
             }
         }
         // photo
         if (!$master_data['photo'] && $info['photo'] && !$update_photo) {
             $filename_original = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.original.jpg", true, 'contacts');
             if (file_exists($filename_original)) {
                 $update_photo = array('original' => $filename_original);
                 $filename_crop = wa()->getDataPath(waContact::getPhotoDir($info['id']) . "{$info['photo']}.jpg", true, 'contacts');
                 if (file_exists($filename_crop)) {
                     $update_photo['crop'] = $filename_crop;
                 }
             }
         }
         // birthday parts
         if (!empty($data_fields['birthday'])) {
             foreach (array('birth_day', 'birth_month', 'birth_year') as $f) {
                 if (empty($master_data[$f]) && !empty($info[$f])) {
                     $master[$f] = $master_data[$f] = $info[$f];
                 }
             }
         }
     }
     // Remove duplicates
     foreach (array_keys($check_duplicates) as $f) {
         $values = $master[$f];
         if (!is_array($values) || count($values) <= 1) {
             continue;
         }
         $unique_values = array();
         // md5 => true
         foreach ($values as $k => $v) {
             if (is_array($v)) {
                 if (isset($v['value']) && is_string($v['value'])) {
                     $v = $v['value'];
                 } else {
                     unset($v['ext'], $v['status']);
                     ksort($v);
                     $v = serialize($v);
                 }
             }
             $hash = md5(mb_strtolower($v));
             if (!empty($unique_values[$hash])) {
                 unset($values[$k]);
                 continue;
             }
             $unique_values[$hash] = true;
         }
         $master[$f] = array_values($values);
     }
     // Save master contact
     $errors = $master->save(array(), 42);
     // 42 == do not validate anything at all
     if ($errors) {
         $errormsg = array();
         foreach ($errors as $field => $err) {
             if (!is_array($err)) {
                 $err = array($err);
             }
             foreach ($err as $str) {
                 $errormsg[] = $field . ': ' . $str;
             }
         }
         $result['error'] = implode("\n<br>", $errormsg);
         return $result;
     }
     // Merge categories
     $category_ids = array();
     $ccm = new waContactCategoriesModel();
     foreach ($ccm->getContactsCategories($merge_ids) as $cid => $cats) {
         $category_ids += array_flip($cats);
     }
     $category_ids = array_keys($category_ids);
     $ccm->add($master_id, $category_ids);
     // update photo
     if ($update_photo) {
         $rand = mt_rand();
         $path = wa()->getDataPath(waContact::getPhotoDir($master['id']), true, 'contacts', false);
         // delete old image
         if (file_exists($path)) {
             waFiles::delete($path);
         }
         waFiles::create($path);
         $filename = $path . "/" . $rand . ".original.jpg";
         waFiles::create($filename);
         waImage::factory($update_photo['original'])->save($filename, 90);
         if (!empty($update_photo['crop'])) {
             $filename = $path . "/" . $rand . ".jpg";
             waFiles::create($filename);
             waImage::factory($update_photo['crop'])->save($filename, 90);
         } else {
             waFiles::copy($filename, $path . "/" . $rand . ".jpg");
         }
         $master->save(array('photo' => $rand));
     }
     $result['total_merged'] = count($contacts_data) + 1;
     $contact_ids = array_keys($contacts_data);
     // wa_log
     $log_model = new waLogModel();
     $log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id));
     // wa_login_log
     $login_log_model = new waLoginLogModel();
     $login_log_model->updateByField('contact_id', $contact_ids, array('contact_id' => $master_id));
     // Merge event
     $params = array('contacts' => $contact_ids, 'id' => $master_data['id']);
     wa()->event(array('contacts', 'merge'), $params);
     // Delete all merged contacts
     $contact_model = new waContactModel();
     $contact_model->delete($contact_ids, false);
     // false == do not trigger event
     $history_model = new contactsHistoryModel();
     foreach ($contact_ids as $contact_id) {
         $history_model->deleteByField(array('type' => 'add', 'hash' => '/contact/' . $contact_id));
     }
     return $result;
 }
Exemple #13
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']);
}
Exemple #14
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);
 }
 /** Using $this->id get waContact and save it in $this->contact;
  * Load vars into $this->view specific to waContact. */
 protected function getContactInfo()
 {
     $system = wa();
     if ($this->id == $system->getUser()->getId()) {
         $this->contact = $system->getUser();
         $this->view->assign('own_profile', TRUE);
     } else {
         $this->contact = new waContact($this->id);
     }
     //
     // Load vars into view
     //
     $this->view->assign('contact', $this->contact);
     // who created this contact and when
     $this->view->assign('contact_create_time', waDateTime::format('datetime', $this->contact['create_datetime'], $system->getUser()->getTimezone()));
     if ($this->contact['create_contact_id']) {
         try {
             $author = new waContact($this->contact['create_contact_id']);
             if ($author['name']) {
                 $this->view->assign('author', $author);
             }
         } catch (Exception $e) {
             // Contact not found. Ignore silently.
         }
     }
     // Info above tabs
     $fields = array('email', 'phone', 'im');
     $top = array();
     foreach ($fields as $f) {
         if ($v = $this->contact->get($f, 'top,html')) {
             $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v);
         }
     }
     $this->view->assign('top', $top);
     // Main contact editor data
     $fieldValues = $this->contact->load('js', TRUE);
     $contactFields = waContactFields::getInfo($this->contact['is_company'] ? 'company' : 'person', TRUE);
     $this->view->assign('contactFields', $contactFields);
     $this->view->assign('fieldValues', $fieldValues);
     // Contact categories
     $cm = new waContactCategoriesModel();
     $this->view->assign('contact_categories', array_values($cm->getContactCategories($this->id)));
 }
 public function execute()
 {
     $id = waRequest::request('id', null, waRequest::TYPE_INT);
     $scm = new shopCustomerModel();
     $customer = $scm->getById($id);
     try {
         $contact = new waContact($id);
         $contact->getName();
     } catch (waException $e) {
         // !!! What to do when shop_customer exists, but no wa_contact found?
         throw $e;
     }
     $ccsm = new waContactCategoriesModel();
     $contact_categories = $ccsm->getContactCategories($id);
     $contacts_url = wa()->getAppUrl('contacts');
     // Info above tabs
     $top = array();
     foreach (array('email', 'phone', 'im') as $f) {
         if ($v = $contact->get($f, 'top,html')) {
             $top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v);
         }
     }
     // Get photo
     $photo = $contact->get('photo');
     $config = $this->getConfig();
     $use_gravatar = $config->getGeneralSettings('use_gravatar');
     $gravatar_default = $config->getGeneralSettings('gravatar_default');
     if (!$photo && $use_gravatar) {
         $photo = shopHelper::getGravatar($contact->get('email', 'default'), 96, $gravatar_default);
     } else {
         $photo = $contact->getPhoto(96);
     }
     $contact['photo'] = $photo;
     // Customer orders
     $im = new shopOrderItemsModel();
     $orders_collection = new shopOrdersCollection('search/contact_id=' . $id);
     $total_count = $orders_collection->count();
     $orders = $orders_collection->getOrders('*,items,params', 0, $total_count);
     shopHelper::workupOrders($orders);
     foreach ($orders as &$o) {
         $o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
         $o['shipping_name'] = ifset($o['params']['shipping_name'], '');
         $o['payment_name'] = ifset($o['params']['payment_name'], '');
         // !!! TODO: shipping and payment icons
     }
     // Customer reviews
     $prm = new shopProductReviewsModel();
     $reviews = $prm->getList('*,is_new,product', array('escape' => false, 'where' => array('contact_id' => $id), 'limit' => false));
     // Customer affiliate transactions history
     $atm = new shopAffiliateTransactionModel();
     $affiliate_history = $atm->getByContact($id);
     $this->view->assign('top', $top);
     $this->view->assign('orders', $orders);
     $this->view->assign('reviews', $reviews);
     $this->view->assign('contact', $contact);
     $this->view->assign('customer', $customer);
     $this->view->assign('contacts_url', $contacts_url);
     $this->view->assign('affiliate_history', $affiliate_history);
     $this->view->assign('contact_categories', $contact_categories);
     $this->view->assign('def_cur_tmpl', str_replace('0', '%s', waCurrency::format('%{s}', 0, wa()->getConfig()->getCurrency())));
     $this->view->assign('point_rate', str_replace(',', '.', (double) str_replace(',', '.', wa()->getSetting('affiliate_usage_rate'))));
     $fields = waContactFields::getAll('person');
     if (isset($fields['name'])) {
         unset($fields['name']);
     }
     $this->view->assign('fields', $fields);
     $this->view->assign('orders_default_view', $config->getOption('orders_default_view'));
     /*
      * @event backend_customer
      * @return array[string]array $return[%plugin_id%] array of html output
      * @return array[string][string]string $return[%plugin_id%]['info_section'] html output
      * @return array[string][string]string $return[%plugin_id%]['name_suffix'] html output
      * @return array[string][string]string $return[%plugin_id%]['header'] html output
      * @return array[string][string]string $return[%plugin_id%]['action_link'] html output
      */
     $this->view->assign('backend_customer', wa()->event('backend_customer', $customer));
 }
 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);
 }