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(); $oSubAdmin = SJB_ObjectMother::createSubAdmin($_REQUEST); $registration_form = SJB_ObjectMother::createForm($oSubAdmin); $registration_form->registerTags($tp); $form_submitted = SJB_Request::getVar('action', '') == 'add'; $errors = array(); $acl = SJB_SubAdminAcl::getInstance(); $type = 'subadmin'; $resources = $acl->getResources(); SJB_SubAdminAcl::mergePermissionsWithResources($resources); switch (SJB_Request::getVar('action')) { case 'save': if ($registration_form->isDataValid($errors)) { 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_Request::getVar($name . '_params')); } // get new defined permissions for notification letter $permissions = SJB_SubAdminAcl::getAllPermissions($type, $role); $resources = $acl->getResources(); SJB_SubAdminAcl::mergePermissionsWithResources($resources, $permissions); SJB_Notifications::sendSubAdminRegistrationLetter($oSubAdmin, SJB_Request::get(), $resources); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-subadmins/'); } break; case 'delete': $subadmins = SJB_Request::getVar('subadmin', array()); foreach ($subadmins as $subadmin_sid) { $username = SJB_SubAdminManager::getUserNameBySubAdminSID($subadmin_sid); SJB_SubAdminManager::deleteSubAdminByUserName($username); } SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/manage-subadmins/'); break; default: break; } $tp->assign('errors', $errors); $tp->assign('form_fields', $registration_form->getFormFieldsInfo()); $aPermissionGroups = SJB_SubAdminAcl::getPermissionGroups(); if ('save' == SJB_Request::getVar('action', '')) { SJB_SubAdminAcl::mergePermissionsWithRequest($resources); } SJB_SubAdminAcl::prepareSubPermissions($resources); $tp->assign('groups', $aPermissionGroups); $tp->assign('resources', $resources); $tp->assign('type', $type); $tp->assign('role', 0); $tp->display('add_subadmin.tpl'); }
public function execute() { $type = 'subadmin'; $role = SJB_SubAdmin::getSubAdminSID(); // get new defined permissions for notification letter $acl = SJB_SubAdminAcl::getInstance(); $permissions = SJB_SubAdminAcl::getAllPermissions($type, $role); $resources = $acl->getResources(); SJB_SubAdminAcl::mergePermissionsWithResources($resources, $permissions); $tp = SJB_System::getTemplateProcessor(); $tp->assign('permissions', $resources); $tp->assign('admin_email', SJB_Settings::getSettingByName('notification_email')); $tp->display('../miscellaneous/subadmin-error.tpl'); }
public function execute() { $tp = SJB_System::getTemplateProcessor(); $subAdminSID = SJB_SubAdmin::getSubAdminSID(); if (!empty($subAdminSID) && ($adminInfo = SJB_SubAdmin::getSubAdminInfo())) { // save sub admin notifications via ajax; SJB_SubAdminManager::SaveSubAdminNotifications($subAdminSID, SJB_Request::getVar('name', ''), SJB_Request::getVar('value')); $message = ''; $editedSubAdminInfo = $_REQUEST; $subAdminNewInfo = array_merge($adminInfo, $editedSubAdminInfo); // create subAdmin object $oSubAdmin = SJB_ObjectMother::createSubAdmin($subAdminNewInfo); $oSubAdmin->setSID($adminInfo['sid']); $oSubAdmin->makePropertyNotRequired("username"); $oSubAdmin->makePropertyNotRequired("email"); $oSubAdmin->makePropertyNotRequired("password"); $oSubAdmin->addProperty(array('id' => 'password_cur', 'caption' => 'Current Password', 'type' => 'password', 'length' => '20', 'is_system' => true, 'order' => 1)); $oSubAdmin->setPropertyValue('password_cur', SJB_Request::getVar('password_cur', '')); // permissions $acl = SJB_SubAdminAcl::getInstance(); $type = 'subadmin'; $resources = $acl->getResources(); $perms = SJB_SubAdminAcl::getAllPermissions($type, $oSubAdmin->getSID()); // /permissions SJB_SubAdminAcl::mergePermissionsWithResources($resources, $perms); $errors = array(); $action = SJB_Request::getVar('action', ''); if ('save' == $action) { $registration_form = SJB_ObjectMother::createForm($oSubAdmin); $registration_form->registerTags($tp); if ($adminInfo['email'] == $subAdminNewInfo['email']) { $oSubAdmin->deleteProperty('email'); } $password_value = $oSubAdmin->getPropertyValue('password'); if (!empty($password_value['original'])) { $currentPass = $oSubAdmin->getPropertyValue('password_cur'); if (!empty($currentPass)) { if (!SJB_SubAdmin::checkCurrentPassword($currentPass)) { $oSubAdmin->deleteProperty('password'); $errors['CurrentPassword'] = '******'; } } else { $oSubAdmin->deleteProperty('password'); $errors['CurrentPassword'] = '******'; } } else { $oSubAdmin->deleteProperty('password'); } $oSubAdmin->deleteProperty('password_cur'); if (empty($errors) && $registration_form->isDataValid($errors)) { SJB_SubAdminManager::saveSubAdmin($oSubAdmin); SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/edit-profile/?saved=1'); } } $oSubAdmin->deleteProperty('password'); $oSubAdmin->deleteProperty('password_cur'); $oSubAdmin->addProperty(array('id' => 'password_cur', 'caption' => 'Current Password', 'type' => 'password_cur', 'length' => '20', 'is_system' => true, 'order' => 1)); $oSubAdmin->addProperty(array('id' => 'password', 'caption' => 'New Password', 'type' => 'password', 'length' => '20', 'is_system' => true, 'order' => 1)); $registration_form = SJB_ObjectMother::createForm($oSubAdmin); $registration_form->registerTags($tp); $registration_form->makeDisabled('username'); $tp->assign("saved", SJB_Request::getVar('saved', false)); $tp->assign("errors", $errors); $tp->assign("form_fields", $registration_form->getFormFieldsInfo()); $tp->assign('groups', SJB_SubAdminAcl::getPermissionGroups()); $tp->assign('notifications', SJB_SubAdminAcl::getSubAdminNotifications($resources, $perms)); $tp->assign('resources', $resources); $tp->assign('type', $type); $tp->assign('sid', $subAdminNewInfo['sid']); $tp->assign('message', $message); $tp->display("edit_subadmin_profile.tpl"); } }