public function execute() { $tp = SJB_System::getTemplateProcessor(); $subAdminSID = SJB_Request::getVar('subadmin', 0); if (!empty($subAdminSID) && ($adminInfo = SJB_SubAdminManager::getSubAdminInfoBySID($subAdminSID))) { $editedSubAdminInfo = $_REQUEST; $subAdminInfo = array_merge($adminInfo, $editedSubAdminInfo); // create subAdmin object $oSubAdmin = SJB_ObjectMother::createSubAdmin($subAdminInfo); $oSubAdmin->setSID($adminInfo['sid']); $oSubAdmin->makePropertyNotRequired("password"); // permissions $acl = SJB_SubAdminAcl::getInstance(); $type = 'subadmin'; $resources = $acl->getResources(); $perms = SJB_SubAdminAcl::getAllPermissions($type, $oSubAdmin->getSID()); // /permissions SJB_SubAdminAcl::mergePermissionsWithResources($resources, $perms); $registration_form = SJB_ObjectMother::createForm($oSubAdmin); $action = SJB_Request::getVar('action', ''); $registration_form->registerTags($tp); $errors = array(); if ('save' == $action || $action == 'apply') { if ($adminInfo['username'] == $subAdminInfo['username']) { $oSubAdmin->deleteProperty('username'); } if ($adminInfo['email'] == $subAdminInfo['email']) { $oSubAdmin->deleteProperty('email'); } if ($registration_form->isDataValid($errors)) { $password_value = $oSubAdmin->getPropertyValue('password'); if (empty($password_value['original'])) { $oSubAdmin->deleteProperty('password'); } // save subAdmin SJB_SubAdminManager::saveSubAdmin($oSubAdmin); $role = $oSubAdmin->getSID(); SJB_Acl::clearPermissions($type, $role); foreach ($resources as $name => $resource) { SJB_SubAdminAcl::allow($name, $type, $role, SJB_SubAdminAcl::definePermission($name), SJB_Array::get($resource, 'params', '')); } SJB_FlashMessages::getInstance()->addMessage('CHANGES_SAVED'); if ($action == 'save') { SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/manage-subadmins/"); } } SJB_SubAdminAcl::mergePermissionsWithRequest($resources); } SJB_SubAdminAcl::prepareSubPermissions($resources); $tp->assign("errors", $errors); $tp->assign("form_fields", $registration_form->getFormFieldsInfo()); $tp->assign('groups', SJB_SubAdminAcl::getPermissionGroups()); $tp->assign('resources', $resources); $tp->assign('type', $type); $tp->assign('sid', $subAdminInfo['sid']); $tp->display('add_subadmin.tpl'); } }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $restore = SJB_Request::getVar('restore', false); $action = SJB_Request::getVar('action_name', 'view_log'); $action = $action == 'search' ? 'view_log' : $action; $paginator = new SJB_EmailLogPagination(); $display_error = SJB_Request::getVar('display_error', false); $savedErrors = SJB_Session::getValue(self::EMAIL_ERRORS); SJB_Session::unsetValue(self::EMAIL_ERRORS); $this->errors = $savedErrors ? $savedErrors : array(); $message = SJB_Session::getValue(self::EMAIL_LOG_MESSAGE); SJB_Session::unsetValue(self::EMAIL_LOG_MESSAGE); switch ($action) { case 'display_message': $sid = SJB_Request::getVar('sid', false); $email = SJB_EmailLogManager::getEmailInfoBySID($sid); $tp->assign('display_error', $display_error); $tp->assign('email', $email); $tp->display('display_log_message.tpl'); return true; break; case 'resend': try { SJB_Settings::saveSetting(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION, SJB_Request::getVar(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION)); $this->resendEmails(); SJB_Session::setValue(self::EMAIL_LOG_MESSAGE, 'The message(s) were successfully resent.'); } catch (Exception $e) { array_push($this->errors, $e->getMessage()); } SJB_Session::setValue(self::EMAIL_ERRORS, $this->errors); $searchFields = SJB_Request::getVar('searchFields'); SJB_HelperFunctions::redirect(SJB_HelperFunctions::getSiteUrl() . '/email-log/?sorting_field=' . $paginator->sortingField . '&sorting_order=' . $paginator->sortingOrder . '&items_per_page=' . $paginator->itemsPerPage . $searchFields); break; case 'view_log': $userSID = SJB_Request::getVar('user_sid', false); if ($userSID) { $template = 'user_email_log.tpl'; $_REQUEST['username']['equal'] = $userSID; $userInfo = SJB_UserManager::getUserInfoBySID($userSID); $userGroupInfo = SJB_UserGroupManager::getUserGroupInfoBySID($userInfo['user_group_sid']); $tp->assign('userGroupInfo', $userGroupInfo); $tp->assign('display_error', $display_error); $tp->assign('user_info', $userInfo); $tp->assign('user_sid', $userSID); } $email = new SJB_EmailLog($_REQUEST); $search_form_builder = new SJB_SearchFormBuilder($email); $criteria_saver = new SJB_EmailLogCriteriaSaver(); if ($restore) { $_REQUEST = array_merge($_REQUEST, $criteria_saver->getCriteria()); } $criteria = $search_form_builder->extractCriteriaFromRequestData($_REQUEST, $email); if (!$userSID) { $template = 'email_log.tpl'; $search_form_builder->setCriteria($criteria); $search_form_builder->registerTags($tp); $tp->display("email_log_search_form.tpl"); } $order_info = array('sorting_field' => $paginator->sortingField, 'sorting_order' => $paginator->sortingOrder); $criteria_saver->setSessionForOrderInfo($order_info); $criteria_saver->setSessionForCurrentPage($paginator->currentPage); $criteria_saver->setSessionForListingsPerPage($paginator->itemsPerPage); $searcher = new SJB_EmailLogSearcher(array('limit' => ($paginator->currentPage - 1) * $paginator->itemsPerPage, 'num_rows' => $paginator->itemsPerPage), $paginator->sortingField, $paginator->sortingOrder); $found_emails = $searcher->getObjectsSIDsByCriteria($criteria); $criteria_saver->setSession($_REQUEST, $searcher->getFoundObjectSIDs()); foreach ($found_emails as $id => $emailSID) { $emailInfo = SJB_EmailLogManager::getEmailInfoBySID($emailSID); $found_emails[$id] = $emailInfo; $found_emails[$id]['user'] = !empty($emailInfo['username']) ? SJB_UserManager::getUserInfoBySID($emailInfo['username']) : array(); $found_emails[$id]['admin'] = array(); if (!empty($emailInfo['admin'])) { if (is_numeric($emailInfo['admin'])) { $found_emails[$id]['admin'] = SJB_SubAdminManager::getSubAdminInfoBySID($emailInfo['admin']); } else { $found_emails[$id]['admin']['username'] = '******'; } } } $paginator->setItemsCount($searcher->getAffectedRows()); $searchFields = ''; foreach ($_REQUEST as $key => $val) { if (is_array($val)) { foreach ($val as $fieldName => $fieldValue) { $searchFields .= "&{$key}[{$fieldName}]={$fieldValue}"; } } } $tp->assign(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION, SJB_Settings::getSettingByName(self::DO_NOT_SHOW_ATTACHMENT_NOTIFICATION)); $tp->assign('message', $message); $tp->assign('errors', $this->errors); $tp->assign("searchFields", $searchFields); $tp->assign('paginationInfo', $paginator->getPaginationInfo()); $tp->assign("found_emails", $found_emails); $tp->display($template); break; } }