/** * Set access setting for given bundle * * @param string $ps_table the table the bundle belongs to * @param string $ps_bundle the bundle name, e.g. preferred_labels * @param int $pn_access access level, __CA_BUNDLE_ACCESS_NONE__, __CA_BUNDLE_ACCESS_READONLY__ or __CA_BUNDLE_ACCESS_EDIT__ * @return boolean success or not */ public function setAccessSettingForBundle($ps_table, $ps_bundle, $pn_access) { if (!in_array($pn_access, array(__CA_BUNDLE_ACCESS_NONE__, __CA_BUNDLE_ACCESS_READONLY__, __CA_BUNDLE_ACCESS_EDIT__))) { return false; } if (!$this->getPrimaryKey()) { return false; } if (!$this->getAppDatamodel()->tableExists($ps_table)) { return false; } $va_vars = $this->get('vars'); if (!is_array($va_vars)) { $va_vars = array(); } if (!isset($va_vars['bundle_access_settings'])) { $va_vars['bundle_access_settings'] = array(); } if (!is_array(ca_user_roles::$s_bundle_list) || !is_array(ca_user_roles::$s_bundle_list[$ps_table])) { $t_ui_screens = new ca_editor_ui_screens(); ca_user_roles::$s_bundle_list[$ps_table] = array_keys($t_ui_screens->getAvailableBundles($ps_table, array('dontCache' => true))); } if (!in_array($ps_bundle, ca_user_roles::$s_bundle_list[$ps_table])) { return false; } $va_vars['bundle_access_settings'][$ps_table . "." . $ps_bundle] = $pn_access; $this->set('vars', $va_vars); $vn_old_mode = $this->getMode(); $this->setMode(ACCESS_WRITE); $this->update(); $this->setMode($vn_old_mode); if ($this->numErrors() > 0) { return false; } return true; }
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'); } }
public function savePlacementsFromHTMLForm($po_request, $ps_form_prefix, $ps_placement_code) { if ($vs_bundles = $po_request->getParameter("{$ps_placement_code}{$ps_form_prefix}displayBundleList", pString)) { $va_bundles = explode(';', $vs_bundles); $t_screen = new ca_editor_ui_screens($this->getPrimaryKey()); $va_placements = $t_screen->getPlacements(array('user_id' => $po_request->getUserID())); // remove deleted bundles foreach ($va_placements as $vn_placement_id => $va_bundle_info) { if (!in_array($va_bundle_info['bundle_name'] . '_' . $va_bundle_info['placement_id'], $va_bundles)) { $t_screen->removePlacement($va_bundle_info['placement_id'], array('user_id' => $po_request->getUserID())); if ($t_screen->numErrors()) { $this->errors = $t_screen->errors; return false; } } } $va_locale_list = ca_locales::getLocaleList(array('index_by_code' => true)); $va_available_bundles = $t_screen->getAvailableBundles(); foreach ($va_bundles as $vn_i => $vs_bundle) { // get settings if (preg_match('!^(.*)_([\\d]+)$!', $vs_bundle, $va_matches)) { $vn_placement_id = (int) $va_matches[2]; $vs_bundle = $va_matches[1]; } else { $vn_placement_id = null; } $vs_bundle_proc = str_replace(".", "_", $vs_bundle); $va_settings = array(); foreach ($_REQUEST as $vs_key => $vs_val) { if (preg_match("!^{$vs_bundle_proc}_([\\d]+)_(.*)\$!", $vs_key, $va_matches)) { // is this locale-specific? if (preg_match('!(.*)_([a-z]{2}_[A-Z]{2})$!', $va_matches[2], $va_locale_matches)) { $vn_locale_id = isset($va_locale_list[$va_locale_matches[2]]) ? (int) $va_locale_list[$va_locale_matches[2]]['locale_id'] : 0; // NOTE: we set keys for both locale_id (which how other placement-using editor like ca_search_forms and // ca_bundle_displays do) *AND* the locale code (eg. "en_US"). This is because the settings created in profile and // in pre v1.1 systems are keyed by code, not locale_id. There's nothing wrong with using code - it's just as unique as the locale_id // and it's convenient to use both interchangeably in any event. // $va_settings[(int) $va_matches[1]][$va_locale_matches[1]][$vn_locale_id] = $va_settings[(int) $va_matches[1]][$va_locale_matches[1]][$va_locale_matches[2]] = $vs_val; } else { $va_settings[(int) $va_matches[1]][$va_matches[2]] = $vs_val; } } } if ($vn_placement_id === 0) { $t_screen->addPlacement($vs_bundle, $vs_bundle . ($vn_i + 1), $va_settings[$vn_placement_id], $vn_i + 1, array('user_id' => $po_request->getUserID(), 'additional_settings' => $va_available_bundles[$vs_bundle]['settings'])); if ($t_screen->numErrors()) { $this->errors = $t_screen->errors; return false; } } else { $t_placement = new ca_editor_ui_bundle_placements($vn_placement_id, $va_available_bundles[$vs_bundle]['settings']); $t_placement->setMode(ACCESS_WRITE); $t_placement->set('rank', $vn_i + 1); if (is_array($va_settings[$vn_placement_id])) { foreach ($t_placement->getAvailableSettings() as $vs_setting => $va_setting_info) { $vs_val = isset($va_settings[$vn_placement_id][$vs_setting]) ? $va_settings[$vn_placement_id][$vs_setting] : null; $t_placement->setSetting($vs_setting, $vs_val); } } $t_placement->update(); if ($t_placement->numErrors()) { $this->errors = $t_placement->errors; return false; } } } } return true; }