/** save data from a dialog for a group/capacity
  *
  * @return void data saved and results are returned as readable output in $this->output
  * @uses $WAS_SCRIPT_NAME
  * @uses $CFG
  */
 function capacity_save()
 {
     global $WAS_SCRIPT_NAME, $CFG;
     $group_id = get_parameter_int('group', NULL);
     $capacity_code = get_parameter_int('capacity', NULL);
     // 1 -- sanity check
     if (!$this->valid_group_capacity($group_id, $capacity_code)) {
         $this->groups_overview();
         return;
     }
     // 2 -- user wants to bail out?
     if (isset($_POST['button_cancel'])) {
         $this->output->add_message(t('cancelled', 'admin'));
         $this->capacity_overview();
         return;
     }
     // 3 -- which acl to use?
     if (($acl_id = $this->calc_acl_id($group_id, $capacity_code)) === FALSE) {
         $this->capacity_overview();
         return;
     }
     // 4 -- did they specify a dialog?
     if (!isset($_POST['dialog'])) {
         logger(sprintf("%s.%s(): weird: 'dialog' not set", __CLASS__, __FUNCTION__), WLOG_DEBUG);
         $this->capacity_overview();
         return;
     }
     $dialog = intval($_POST['dialog']);
     // 5 -- prepare necessary parameters and process dialog
     $a_params = $this->a_params(TASK_GROUP_CAPACITY_SAVE, $group_id, $capacity_code);
     $params = $this->get_group_capacity_names($group_id, $capacity_code);
     switch ($dialog) {
         case GROUPMANAGER_DIALOG_CAPACITY_INTRANET:
             include_once $CFG->progdir . '/lib/aclmanager.class.php';
             $acl = new AclManager($this->output, $acl_id, ACL_TYPE_INTRANET);
             $acl->set_action($a_params);
             $acl->set_header(t('groupmanager_capacity_intranet_header', 'admin', $params));
             $acl->set_intro(t('groupmanager_capacity_intranet_explanation', 'admin', $params));
             $acl->set_dialog($dialog);
             if (!$acl->save_data()) {
                 $acl->show_dialog();
                 // redo dialog, but without a distracting menu this time
                 return;
             }
             break;
         case GROUPMANAGER_DIALOG_CAPACITY_ADMIN:
             include_once $CFG->progdir . '/lib/aclmanager.class.php';
             $acl = new AclManager($this->output, $acl_id, ACL_TYPE_ADMIN);
             $acl->set_action($a_params);
             $acl->set_header(t('groupmanager_capacity_admin_header', 'admin', $params));
             $acl->set_intro(t('groupmanager_capacity_admin_explanation', 'admin', $params));
             $acl->set_dialog($dialog);
             if (!$acl->save_data()) {
                 $acl->show_dialog();
                 // redo dialog, but without a distracting menu this time
                 return;
             }
             break;
         case GROUPMANAGER_DIALOG_CAPACITY_PAGEMANAGER:
             $limit = get_parameter_int('limit', $CFG->pagination_height);
             $offset = get_parameter_int('offset', 0);
             if ($limit != $CFG->pagination_height) {
                 $a_params['limit'] = $limit;
             }
             if ($offset != 0) {
                 $a_params['offset'] = $offset;
             }
             include_once $CFG->progdir . '/lib/aclmanager.class.php';
             $acl = new AclManager($this->output, $acl_id, ACL_TYPE_PAGEMANAGER);
             $acl->set_action($a_params);
             $acl->set_header(t('groupmanager_capacity_pagemanager_header', 'admin', $params));
             $acl->set_intro(t('groupmanager_capacity_pagemanager_explanation', 'admin', $params));
             $acl->set_dialog($dialog);
             // Enable pagination for this one: the list of nodes can be very very long so split up in smaller screens.
             $a_params = $this->a_params(TASK_GROUP_CAPACITY_PAGEMANAGER, $group_id, $capacity_code);
             $acl->enable_pagination($a_params, $limit, $offset);
             // Also enable the expand/collapse feature
             if (!isset($_SESSION['aclmanager_open_areas'])) {
                 $_SESSION['aclmanager_open_areas'] = FALSE;
                 // default: everything is closed
             }
             $acl->enable_area_view($a_params, $_SESSION['aclmanager_open_areas']);
             if (!$acl->save_data()) {
                 $acl->show_dialog();
                 // redo dialog, but without a distracting menu this time
                 return;
             }
             break;
         default:
             logger(sprintf("%s.%s(): weird: dialog='%d'. Huh?", __CLASS__, __FUNCTION__, $dialog), WLOG_DEBUG);
             break;
     }
     // 6 -- we always end up in the capacity overview screen
     $this->capacity_overview();
 }
 /** save edited user data to the database
  *
  * @output void work done and output via $this->output
  */
 function user_save()
 {
     global $WAS_SCRIPT_NAME, $CFG;
     // 0 -- sanity check
     $user_id = get_parameter_int('user', NULL);
     if (is_null($user_id)) {
         logger("usermanager->user_save(): unspecified parameter user");
         $this->output->add_message(t('error_invalid_parameters', 'admin'));
         $this->users_overview();
         return;
     }
     // 1 -- bail out if the user pressed cancel button
     $dialog = isset($_POST['dialog']) ? intval($_POST['dialog']) : 0;
     if (isset($_POST['button_cancel'])) {
         $this->output->add_message(t('cancelled', 'admin'));
         if ($dialog != USERMANAGER_DIALOG_EDIT) {
             $this->user_edit();
         } else {
             $this->users_overview();
         }
         return;
     }
     if ($dialog == USERMANAGER_DIALOG_EDIT) {
         $this->user_save_basic($user_id);
         return;
     }
     // What remains are the acl-type save actions.
     // 2 -- which acl to use?
     if (($acl_id = $this->calc_acl_id($user_id)) === FALSE) {
         $this->user_edit();
         return;
     }
     // 3A -- construct necessary parameters for dialog
     $related_acls = calc_user_related_acls($user_id);
     $a_params = $this->a_params(TASK_USER_SAVE, $user_id);
     $params = $this->get_user_names($user_id);
     // 3B -- save data (and perhaps redo dialog if an error occurred)
     switch ($dialog) {
         case USERMANAGER_DIALOG_INTRANET:
             include_once $CFG->progdir . '/lib/aclmanager.class.php';
             $acl = new AclManager($this->output, $acl_id, ACL_TYPE_INTRANET);
             $acl->set_related_acls($related_acls);
             $acl->set_action($a_params);
             $acl->set_header(t('usermanager_intranet_header', 'admin', $params));
             $acl->set_intro(t('usermanager_intranet_explanation', 'admin', $params));
             $acl->set_dialog($dialog);
             if (!$acl->save_data()) {
                 $acl->show_dialog();
                 // redo dialog, but without a distracting menu this time
                 return;
             }
             break;
         case USERMANAGER_DIALOG_ADMIN:
             include_once $CFG->progdir . '/lib/aclmanager.class.php';
             $acl = new AclManager($this->output, $acl_id, ACL_TYPE_ADMIN);
             $acl->set_related_acls($related_acls);
             $acl->set_action($a_params);
             $acl->set_header(t('usermanager_admin_header', 'admin', $params));
             $acl->set_intro(t('usermanager_admin_explanation', 'admin', $params));
             $acl->set_dialog($dialog);
             if (!$acl->save_data()) {
                 $acl->show_dialog();
                 // redo dialog, but without a distracting menu this time
                 return;
             }
             break;
         case USERMANAGER_DIALOG_PAGEMANAGER:
             $limit = get_parameter_int('limit', $CFG->pagination_height);
             $offset = get_parameter_int('offset', 0);
             if ($limit != $CFG->pagination_height) {
                 $a_params['limit'] = $limit;
             }
             if ($offset != 0) {
                 $a_params['offset'] = $offset;
             }
             include_once $CFG->progdir . '/lib/aclmanager.class.php';
             $acl = new AclManager($this->output, $acl_id, ACL_TYPE_PAGEMANAGER);
             $acl->set_related_acls($related_acls);
             $acl->set_action($a_params);
             $acl->set_header(t('usermanager_pagemanager_header', 'admin', $params));
             $acl->set_intro(t('usermanager_pagemanager_explanation', 'admin', $params));
             $acl->set_dialog($dialog);
             // Enable pagination for this one: the list of nodes can be very very long so split up in smaller screens.
             $a_params = $this->a_params(TASK_USER_PAGEMANAGER, $user_id);
             $acl->enable_pagination($a_params, $limit, $offset);
             // Also enable the expand/collapse feature
             if (!isset($_SESSION['aclmanager_open_areas'])) {
                 $_SESSION['aclmanager_open_areas'] = FALSE;
                 // default: everything is closed
             }
             $acl->enable_area_view($a_params, $_SESSION['aclmanager_open_areas']);
             if (!$acl->save_data()) {
                 $acl->show_dialog();
                 // redo dialog, but without a distracting menu this time
                 return;
             }
             break;
         default:
             logger(sprintf("usermanager->save_data(): weird: dialog='%d'. Huh?", $dialog), WLOG_DEBUG);
             break;
     }
     // 4 -- we always end up in the basic properties screen (if we're still here)
     $this->user_edit();
 }