/**
  * Record delete activity
  */
 public function hookDeleteItem($pa_params)
 {
     if ($o_req = $this->getRequest()) {
         if (!is_array($va_activity_list = $o_req->session->getVar($pa_params['table_name'] . '_duplicate_id_list'))) {
             $va_activity_list = array();
         }
         unset($va_activity_list[$pa_params['id']]);
         $o_req->session->setVar($pa_params['table_name'] . '_duplicate_id_list', $va_activity_list);
         AppNavigation::clearMenuBarCache($o_req);
     }
     return $pa_params;
 }
Ejemplo n.º 2
0
 public function Save()
 {
     AssetLoadManager::register('tableList');
     $o_dm = Datamodel::load();
     $t_list = new ca_lists();
     $t_role = $this->getRoleObject();
     $t_role->setMode(ACCESS_WRITE);
     foreach ($t_role->getFormFields() as $vs_f => $va_field_info) {
         $t_role->set($vs_f, $_REQUEST[$vs_f]);
         if ($t_role->numErrors()) {
             $this->request->addActionErrors($t_role->errors(), 'field_' . $vs_f);
         }
     }
     // get vars
     $va_vars = $t_role->get('vars');
     if (!is_array($va_vars)) {
         $va_vars = array();
     }
     // save bundle access settings
     $t_screen = new ca_editor_ui_screens();
     $va_bundle_access_settings = array();
     foreach (ca_users::$s_bundlable_tables as $vs_table) {
         $va_available_bundles = $t_screen->getAvailableBundles($vs_table);
         foreach ($va_available_bundles as $vs_bundle_name => $va_bundle_info) {
             $vs_bundle_name_proc = $vs_table . '_' . str_replace(".", "_", $vs_bundle_name);
             $vn_access = $this->request->getParameter($vs_bundle_name_proc, pInteger);
             $va_bundle_access_settings[$vs_table . '.' . $vs_bundle_name] = $vn_access;
         }
     }
     $va_vars['bundle_access_settings'] = $va_bundle_access_settings;
     if ($t_role->getAppConfig()->get('perform_type_access_checking')) {
         // save type access settings
         $va_type_access_settings = array();
         foreach (ca_users::$s_bundlable_tables as $vs_table) {
             if (!caTableIsActive($vs_table) && $vs_table != 'ca_object_representations') {
                 continue;
             }
             $t_instance = $o_dm->getInstanceByTableName($vs_table, true);
             if (!($vs_list_code = $t_instance->getTypeListCode())) {
                 continue;
             }
             $va_type_ids = $t_list->getItemsForList($vs_list_code, array('idsOnly' => true));
             if (is_array($va_type_ids)) {
                 foreach ($va_type_ids as $vn_i => $vn_item_id) {
                     $vn_access = $this->request->getParameter($vs_table . '_type_' . $vn_item_id, pInteger);
                     $va_type_access_settings[$vs_table . '.' . $vn_item_id] = $vn_access;
                 }
             }
         }
         $va_vars['type_access_settings'] = $va_type_access_settings;
     }
     if ($t_role->getAppConfig()->get('perform_source_access_checking')) {
         // save source access settings
         $va_source_access_settings = array();
         foreach (ca_users::$s_bundlable_tables as $vs_table) {
             if (!caTableIsActive($vs_table) && $vs_table != 'ca_object_representations') {
                 continue;
             }
             $t_instance = $o_dm->getInstanceByTableName($vs_table, true);
             if (!($vs_list_code = $t_instance->getSourceListCode())) {
                 continue;
             }
             $va_source_ids = $t_list->getItemsForList($vs_list_code, array('idsOnly' => true));
             if (is_array($va_source_ids)) {
                 foreach ($va_source_ids as $vn_i => $vn_item_id) {
                     $vn_access = $this->request->getParameter($vs_table . '_source_' . $vn_item_id, pInteger);
                     $va_source_access_settings[$vs_table . '.' . $vn_item_id] = $vn_access;
                 }
             }
             $va_source_access_settings[$vs_table . '_default_id'] = $this->request->getParameter($vs_table . '_default_source', pInteger);
         }
         $va_vars['source_access_settings'] = $va_source_access_settings;
     }
     $va_access_status_settings = array();
     if (is_array($va_access_status_ids = $va_source_ids = $t_list->getItemsForList('access_statuses', array('idsOnly' => true)))) {
         foreach ($va_access_status_ids as $vn_i => $vn_item_id) {
             $vs_access = $this->request->getParameter('access_status_' . $vn_item_id, pString);
             switch ($vs_access) {
                 case 0:
                 case 1:
                     $va_access_status_settings[$vn_item_id] = $vs_access;
                     break;
                 default:
                     $va_access_status_settings[$vn_item_id] = null;
                     break;
             }
         }
     }
     $va_vars['access_status_settings'] = $va_access_status_settings;
     $t_role->set('vars', $va_vars);
     // save actions
     $va_role_action_list = $t_role->getRoleActionList();
     $va_new_role_action_settings = array();
     foreach ($va_role_action_list as $vs_group => $va_group_info) {
         if (caTableIsActive($vs_group) === false && $vs_group != 'ca_object_representations') {
             continue;
         }
         // will return null if group name is not a table name; true if it's an enabled table and false if it's a disabled table
         foreach ($va_group_info['actions'] as $vs_action => $va_action_info) {
             if ($this->request->getParameter($vs_action, pInteger) > 0) {
                 $va_new_role_action_settings[] = $vs_action;
             }
         }
     }
     $t_role->setRoleActions($va_new_role_action_settings);
     AppNavigation::clearMenuBarCache($this->request);
     // clear menu bar cache since role changes may affect content
     if ($this->request->numActionErrors() == 0) {
         if (!$t_role->getPrimaryKey()) {
             $t_role->insert();
             $vs_message = _t("Added role");
         } else {
             $t_role->update();
             $vs_message = _t("Saved changes to role");
         }
         if ($t_role->numErrors()) {
             foreach ($t_role->errors() as $o_e) {
                 $this->request->addActionError($o_e, 'general');
                 $this->notification->addNotification($o_e->getErrorDescription(), __NOTIFICATION_TYPE_ERROR__);
             }
         } else {
             $this->notification->addNotification($vs_message, __NOTIFICATION_TYPE_INFO__);
         }
     } else {
         $this->notification->addNotification(_t("Your entry has errors. See below for details."), __NOTIFICATION_TYPE_ERROR__);
     }
     if ($this->request->numActionErrors()) {
         $this->render('role_edit_html.php');
     } else {
         $this->view->setVar('role_list', $t_role->getRoleList());
         $this->render('role_list_html.php');
     }
 }
Ejemplo n.º 3
0
 public function Save()
 {
     $vs_view_name = 'preferences_html.php';
     $vs_action = $this->request->getParameter('action', pString);
     switch ($vs_action) {
         case 'EditCataloguingPrefs':
             $vs_group = 'cataloguing';
             $this->request->user->setPreference('cataloguing_locale', $this->request->getParameter('pref_cataloguing_locale', pString));
             $va_ui_prefs = array();
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 foreach ($_REQUEST as $vs_k => $vs_v) {
                     if (preg_match("!pref_{$vs_pref}_([\\d]+)!", $vs_k, $va_matches)) {
                         $va_ui_prefs[$vs_pref][$va_matches[1]] = $vs_v;
                     } elseif (preg_match("!pref_{$vs_pref}__NONE_!", $vs_k)) {
                         $va_ui_prefs[$vs_pref]['_NONE_'] = $vs_v;
                     }
                 }
                 foreach ($va_ui_prefs as $vs_pref => $va_values) {
                     $this->request->user->setPreference($vs_pref, $va_values);
                 }
             }
             $vs_view_name = 'preferences_cataloguing_html.php';
             break;
         case 'EditBatchPrefs':
             $vs_group = 'batch';
             $va_ui_prefs = array();
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 foreach ($_REQUEST as $vs_k => $vs_v) {
                     if (preg_match("!pref_{$vs_pref}!", $vs_k, $va_matches)) {
                         $this->request->user->setPreference($vs_pref, $vs_v);
                     }
                 }
             }
             $vs_view_name = 'preferences_batch_html.php';
             break;
         case 'EditQuickAddPrefs':
             $vs_group = 'quickadd';
             $va_ui_prefs = array();
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 foreach ($_REQUEST as $vs_k => $vs_v) {
                     if (preg_match("!pref_{$vs_pref}_([\\d]+)!", $vs_k, $va_matches)) {
                         $va_ui_prefs[$vs_pref][$va_matches[1]] = $vs_v;
                     }
                 }
                 foreach ($va_ui_prefs as $vs_pref => $va_values) {
                     $this->request->user->setPreference($vs_pref, $va_values);
                 }
             }
             $vs_view_name = 'preferences_quickadd_html.php';
             break;
         case 'EditMediaPrefs':
             $vs_group = 'media';
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 $this->request->user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString));
             }
             break;
         case 'EditUnitsPrefs':
             $vs_group = 'units';
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 $this->request->user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString));
             }
             break;
         case 'EditProfilePrefs':
             $vs_group = 'profile';
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 $this->request->user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString));
             }
             break;
         case 'EditDuplicationPrefs':
             $vs_group = 'duplication';
             foreach (array('ca_objects', 'ca_object_lots', 'ca_entities', 'ca_places', 'ca_occurrences', 'ca_collections', 'ca_storage_locations', 'ca_loans', 'ca_movements', 'ca_lists', 'ca_list_items', 'ca_tours', 'ca_tour_stops', 'ca_sets', 'ca_bundle_displays') as $vs_table) {
                 foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                     if ($vs_pref == 'duplicate_relationships') {
                         $vs_val = $this->request->getParameter("pref_{$vs_table}_{$vs_pref}", pArray);
                     } else {
                         $vs_val = $this->request->getParameter("pref_{$vs_table}_{$vs_pref}", pString);
                     }
                     $this->request->user->setPreference("{$vs_table}_{$vs_pref}", $vs_val);
                 }
             }
             $vs_view_name = 'preferences_duplication_html.php';
             break;
         case 'EditUIPrefs':
         default:
             $vs_group = 'ui';
             $vs_action = 'EditUIPrefs';
             foreach ($this->request->user->getValidPreferences($vs_group) as $vs_pref) {
                 $this->request->user->setPreference($vs_pref, $vs_locale = $this->request->getParameter('pref_' . $vs_pref, pString));
                 if ($vs_pref == 'ui_locale' && $vs_locale) {
                     global $_, $g_ui_locale_id, $g_ui_locale, $_locale;
                     // set UI locale for this request (causes UI language to change immediately - and in time - for this request)
                     // if we didn't do this, you'd have to reload the page to see the locale change
                     $this->request->user->setPreference('ui_locale', $vs_locale);
                     $g_ui_locale_id = $this->request->user->getPreferredUILocaleID();
                     // get current UI locale as locale_id	 			(available as global)
                     $g_ui_locale = $this->request->user->getPreferredUILocale();
                     // get current UI locale as locale string 			(available as global)
                     if (!initializeLocale($g_ui_locale)) {
                         die("Error loading locale " . $g_ui_locale);
                     }
                     MemoryCache::flush('translation');
                     // reload menu bar
                     AppNavigation::clearMenuBarCache($this->request);
                 }
                 if ($vs_pref == 'ui_theme') {
                     // set the view path to use the new theme; if we didn't set this here you'd have to reload the page to
                     // see the theme change.
                     $this->view->setViewPath($this->request->getViewsDirectoryPath() . '/' . $this->request->getModulePath());
                 }
             }
             break;
     }
     $this->request->setAction($vs_action);
     $this->view->setVar('group', $vs_group);
     $this->notification->addNotification(_t("Saved preference settings"), __NOTIFICATION_TYPE_INFO__);
     $this->view->setVar('t_user', $this->request->user);
     $this->render($vs_view_name);
 }
Ejemplo n.º 4
0
 public function Logout()
 {
     $this->request->deauthenticate();
     AppNavigation::clearMenuBarCache($this->request);
     // clear menu bar cache on logout just in case
     $this->notification->addNotification(_t("You are now logged out"), __NOTIFICATION_TYPE_INFO__);
     $this->view->setVar('notifications', $this->notification->getNotifications());
     $this->render('logged_out_html.php');
 }
Ejemplo n.º 5
0
 public function Save()
 {
     AssetLoadManager::register('tableList');
     $t_group = $this->getGroupObject();
     $t_group->setMode(ACCESS_WRITE);
     foreach ($t_group->getFormFields() as $vs_f => $va_field_info) {
         $t_group->set($vs_f, $_REQUEST[$vs_f]);
         if ($t_group->numErrors()) {
             $this->request->addActionErrors($t_group->errors(), 'field_' . $vs_f);
         }
     }
     $t_group->set('user_id', null);
     if ($this->request->getParameter('password', pString) != $this->request->getParameter('password_confirm', pString)) {
         $this->request->addActionError(new ApplicationError(1050, _t("Password does not match confirmation. Please try again."), "administrate/GroupsController->Save()", '', false, false), 'field_password');
     }
     AppNavigation::clearMenuBarCache($this->request);
     // clear menu bar cache since changes may affect content
     if ($this->request->numActionErrors() == 0) {
         if (!$t_group->getPrimaryKey()) {
             $t_group->insert();
             $vs_message = _t("Added group");
         } else {
             $t_group->update();
             $vs_message = _t("Saved changes to group");
         }
         if ($t_group->numErrors()) {
             foreach ($t_group->errors() as $o_e) {
                 $this->request->addActionError($o_e, 'general');
                 $this->notification->addNotification($o_e->getErrorDescription(), __NOTIFICATION_TYPE_ERROR__);
             }
         } else {
             // Save roles
             $va_set_group_roles = $this->request->getParameter('roles', pArray);
             if (!is_array($va_set_group_roles)) {
                 $va_set_group_roles = array();
             }
             $va_existing_group_roles = $t_group->getGroupRoles();
             $va_role_list = $t_group->getRoleList();
             foreach ($va_role_list as $vn_role_id => $va_role_info) {
                 if ($va_existing_group_roles[$vn_role_id] && !in_array($vn_role_id, $va_set_group_roles)) {
                     // remove role
                     $t_group->removeRoles($vn_role_id);
                     continue;
                 }
                 if (!$va_existing_group_roles[$vn_role_id] && in_array($vn_role_id, $va_set_group_roles)) {
                     // add role
                     $t_group->addRoles($vn_role_id);
                     continue;
                 }
             }
             $this->notification->addNotification($vs_message, __NOTIFICATION_TYPE_INFO__);
         }
     } else {
         $this->notification->addNotification(_t("Your entry has errors. See below for details."), __NOTIFICATION_TYPE_ERROR__);
     }
     if ($this->request->numActionErrors()) {
         $this->render('group_edit_html.php');
     } else {
         // success
         $this->view->setVar('group_list', $t_group->getGroupList());
         $this->render('group_list_html.php');
     }
 }
Ejemplo n.º 6
0
 public function Save()
 {
     AssetLoadManager::register('tableList');
     $t_user = $this->getUserObject();
     $this->opo_app_plugin_manager->hookBeforeUserSaveData(array('user_id' => $t_user->getPrimaryKey(), 'instance' => $t_user));
     $vb_send_activation_email = false;
     if ($t_user->get("user_id") && $this->request->config->get("email_user_when_account_activated") && $_REQUEST["active"] != $t_user->get("active")) {
         $vb_send_activation_email = true;
     }
     $t_user->setMode(ACCESS_WRITE);
     foreach ($t_user->getFormFields() as $vs_f => $va_field_info) {
         // dont get/set password if backend doesn't support it
         if ($vs_f == 'password' && !AuthenticationManager::supports(__CA_AUTH_ADAPTER_FEATURE_UPDATE_PASSWORDS__)) {
             continue;
         }
         $t_user->set($vs_f, $_REQUEST[$vs_f]);
         if ($t_user->numErrors()) {
             $this->request->addActionErrors($t_user->errors(), 'field_' . $vs_f);
         }
     }
     if ($this->request->getParameter('entity_id', pInteger) == 0) {
         $t_user->set('entity_id', null);
     }
     if (AuthenticationManager::supports(__CA_AUTH_ADAPTER_FEATURE_UPDATE_PASSWORDS__)) {
         if ($this->request->getParameter('password', pString) != $this->request->getParameter('password_confirm', pString)) {
             $this->request->addActionError(new ApplicationError(1050, _t("Password does not match confirmation. Please try again."), "administrate/UserController->Save()", '', false, false), 'field_password');
         }
     }
     AppNavigation::clearMenuBarCache($this->request);
     // clear menu bar cache since changes may affect content
     if ($this->request->numActionErrors() == 0) {
         if (!$t_user->getPrimaryKey()) {
             $t_user->insert();
             $vs_message = _t("Added user");
         } else {
             $t_user->update();
             $vs_message = _t("Saved changes to user");
         }
         $this->opo_app_plugin_manager->hookAfterUserSaveData(array('user_id' => $t_user->getPrimaryKey(), 'instance' => $t_user));
         if ($t_user->numErrors()) {
             foreach ($t_user->errors() as $o_e) {
                 $this->request->addActionError($o_e, 'general');
                 $this->notification->addNotification($o_e->getErrorDescription(), __NOTIFICATION_TYPE_ERROR__);
             }
         } else {
             // Save roles
             $va_set_user_roles = $this->request->getParameter('roles', pArray);
             if (!is_array($va_set_user_roles)) {
                 $va_set_user_roles = array();
             }
             $va_existing_user_roles = $t_user->getUserRoles();
             $va_role_list = $t_user->getRoleList();
             foreach ($va_role_list as $vn_role_id => $va_role_info) {
                 if ($va_existing_user_roles[$vn_role_id] && !in_array($vn_role_id, $va_set_user_roles)) {
                     // remove role
                     $t_user->removeRoles($vn_role_id);
                     continue;
                 }
                 if (!$va_existing_user_roles[$vn_role_id] && in_array($vn_role_id, $va_set_user_roles)) {
                     // add role
                     $t_user->addRoles($vn_role_id);
                     continue;
                 }
             }
             // Save groups
             $va_set_user_groups = $this->request->getParameter('groups', pArray);
             if (!is_array($va_set_user_groups)) {
                 $va_set_user_groups = array();
             }
             $va_existing_user_groups = $t_user->getUserGroups();
             $va_group_list = $t_user->getGroupList();
             foreach ($va_group_list as $vn_group_id => $va_group_info) {
                 if ($va_existing_user_groups[$vn_group_id] && !in_array($vn_group_id, $va_set_user_groups)) {
                     // remove group
                     $t_user->removeFromGroups($vn_group_id);
                     continue;
                 }
                 if (!$va_existing_user_groups[$vn_group_id] && in_array($vn_group_id, $va_set_user_groups)) {
                     // add group
                     $t_user->addToGroups($vn_group_id);
                     continue;
                 }
             }
             // Save profile prefs
             $va_profile_prefs = $t_user->getValidPreferences('profile');
             if (is_array($va_profile_prefs) && sizeof($va_profile_prefs)) {
                 $this->opo_app_plugin_manager->hookBeforeUserSavePrefs(array('user_id' => $t_user->getPrimaryKey(), 'instance' => $t_user));
                 $va_changed_prefs = array();
                 foreach ($va_profile_prefs as $vs_pref) {
                     if ($this->request->getParameter('pref_' . $vs_pref, pString) != $t_user->getPreference($vs_pref)) {
                         $va_changed_prefs[$vs_pref] = true;
                     }
                     $t_user->setPreference($vs_pref, $this->request->getParameter('pref_' . $vs_pref, pString));
                 }
                 $t_user->update();
                 $this->opo_app_plugin_manager->hookAfterUserSavePrefs(array('user_id' => $t_user->getPrimaryKey(), 'instance' => $t_user, 'modified_prefs' => $va_changed_prefs));
             }
             if ($vb_send_activation_email) {
                 # --- send email confirmation
                 $o_view = new View($this->request, array($this->request->getViewsDirectoryPath()));
                 # -- generate email subject line from template
                 $vs_subject_line = $o_view->render("mailTemplates/account_activation_subject.tpl");
                 # -- generate mail text from template - get both the text and the html versions
                 $vs_mail_message_text = $o_view->render("mailTemplates/account_activation.tpl");
                 $vs_mail_message_html = $o_view->render("mailTemplates/account_activation_html.tpl");
                 caSendmail($t_user->get('email'), $this->request->config->get("ca_admin_email"), $vs_subject_line, $vs_mail_message_text, $vs_mail_message_html);
             }
             $this->notification->addNotification($vs_message, __NOTIFICATION_TYPE_INFO__);
         }
     } else {
         $this->notification->addNotification(_t("Your entry has errors. See below for details."), __NOTIFICATION_TYPE_ERROR__);
     }
     if ($this->request->numActionErrors()) {
         $this->render('user_edit_html.php');
     } else {
         // success
         // If we are editing the user record of the currently logged in user
         // we have a problem: the request object flushes out changes to its own user object
         // for the logged-in user at the end of the request overwriting any changes we've made.
         //
         // To avoid this we check here to see if we're editing the currently logged-in
         // user and reload the request's copy if needed.
         if ($t_user->getPrimaryKey() == $this->request->user->getPrimaryKey()) {
             $this->request->user->load($t_user->getPrimaryKey());
         }
         $this->ListUsers();
     }
 }