Ejemplo n.º 1
0
 /**
  * 
  *
  * @param array $pa_options Array of options passed through to _initView 
  */
 public function SetAccess($pa_options = null)
 {
     list($vn_subject_id, $t_subject) = $this->_initView($pa_options);
     if (!$this->_checkAccess($t_subject)) {
         return false;
     }
     if (!$t_subject->isSaveable($this->request) || !$this->request->user->canDoAction('can_change_acl_' . $t_subject->tableName())) {
         $this->response->setRedirect($this->request->config->get('error_display_url') . '/n/2570?r=' . urlencode($this->request->getFullUrlPath()));
         return;
     }
     $vs_form_prefix = $this->request->getParameter('_formName', pString);
     // Save user ACL's
     $va_users_to_set = array();
     foreach ($_REQUEST as $vs_key => $vs_val) {
         if (preg_match("!^{$vs_form_prefix}_user_id(.*)\$!", $vs_key, $va_matches)) {
             $vn_user_id = (int) $this->request->getParameter($vs_form_prefix . '_user_id' . $va_matches[1], pInteger);
             $vn_access = $this->request->getParameter($vs_form_prefix . '_user_access_' . $va_matches[1], pInteger);
             if ($vn_access >= 0) {
                 $va_users_to_set[$vn_user_id] = $vn_access;
             }
         }
     }
     $t_subject->setACLUsers($va_users_to_set);
     // Save group ACL's
     $va_groups_to_set = array();
     foreach ($_REQUEST as $vs_key => $vs_val) {
         if (preg_match("!^{$vs_form_prefix}_group_id(.*)\$!", $vs_key, $va_matches)) {
             $vn_group_id = (int) $this->request->getParameter($vs_form_prefix . '_group_id' . $va_matches[1], pInteger);
             $vn_access = $this->request->getParameter($vs_form_prefix . '_group_access_' . $va_matches[1], pInteger);
             if ($vn_access >= 0) {
                 $va_groups_to_set[$vn_group_id] = $vn_access;
             }
         }
     }
     $t_subject->setACLUserGroups($va_groups_to_set);
     // Save "world" ACL
     $t_subject->setACLWorldAccess($this->request->getParameter("{$vs_form_prefix}_access_world", pInteger));
     // Propagate ACL settings to records that inherit from this one
     if ((bool) $t_subject->getProperty('SUPPORTS_ACL_INHERITANCE')) {
         ca_acl::applyACLInheritanceToChildrenFromRow($t_subject);
         if (is_array($va_inheritors = $t_subject->getProperty('ACL_INHERITANCE_LIST'))) {
             foreach ($va_inheritors as $vs_inheritor_table) {
                 ca_acl::applyACLInheritanceToRelatedFromRow($t_subject, $vs_inheritor_table);
             }
         }
     }
     // Set ACL-related intrinsic fields
     if ($t_subject->hasField('acl_inherit_from_ca_collections') || $t_subject->hasField('acl_inherit_from_parent')) {
         $t_subject->setMode(ACCESS_WRITE);
         if ($t_subject->hasField('acl_inherit_from_ca_collections')) {
             $t_subject->set('acl_inherit_from_ca_collections', $this->request->getParameter('acl_inherit_from_ca_collections', pString));
         }
         if ($t_subject->hasField('acl_inherit_from_parent')) {
             $t_subject->set('acl_inherit_from_parent', $this->request->getParameter('acl_inherit_from_parent', pString));
         }
         $t_subject->update();
         if ($t_subject->numErrors()) {
             $this->postError(1250, _t('Could not set ACL inheritance settings: %1', join("; ", $t_subject->getErrors())), "BaseEditorController->SetAccess()");
         }
     }
     $this->Access();
 }