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.'); } $this->getRights(); $crm = new contactsRightsModel(); $contacts = $crm->getAllowedContactsIds($contacts); if (!$contacts) { throw new waRightsException('Access denied: no access to contacts '); } // 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); } $contact_model = new waContactModel(); $cnt = count($contacts); if ($cnt > 30) { $log_params = $cnt; } else { // contact names $log_params = $contact_model->getName($contacts); } $history_model = new contactsHistoryModel(); foreach ($contacts as $contact_id) { $history_model->deleteByField(array('type' => 'add', 'hash' => '/contact/' . $contact_id)); } // Bye bye... $contact_model->delete($contacts); // also throws a contacts.delete event $this->response['deleted'] = $cnt; $this->response['message'] = sprintf(_w("%d contact has been deleted", "%d contacts have been deleted", $this->response['deleted']), $this->response['deleted']); $this->logAction('contact_delete', $log_params); }
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>'); } $crm = new contactsRightsModel(); $ids = $crm->getAllowedContactsIds($ids); if (!$ids) { throw new waRightsException(_w('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); }