/** get pertinent user information in core
  *
  * Note:
  * We used to have a bool named 'high_visibility' in both the users table
  * and this class. That changed with version 0.90.4 (April 2012) and we now
  * have a field and variable 'skin' which is a varchar(20). The values were
  * mapped as follows: high_availability=FALSE -> skin='base' and 
  * high_availability=TRUE -> skin='textonly'. The extra test for the
  * existence of $record['skin'] was necessary for the case where the user
  * wanted to upgrade from 0.90.3 to 0.90.4 where 'skin' replaced 'high_visibility'.
  * 
  * @param int $user_id identifies data from which user to load, 0 means no user/a passerby
  * @return void
  */
 function Useraccount($user_id = 0)
 {
     $user_id = intval($user_id);
     $this->user_id = $user_id;
     if ($this->user_id == 0) {
         // just a passerby gets no privileges
         return FALSE;
     }
     // Now try to fetch data for this user from database
     $fields = '*';
     $record = db_select_single_record('users', $fields, array('user_id' => $user_id, 'is_active' => TRUE));
     if ($record === FALSE) {
         logger('useraccount: cannot find record for user_id \'' . $user_id . '\'', WLOG_INFO, $user_id);
         return FALSE;
     }
     $this->username = $record['username'];
     $this->full_name = $record['full_name'];
     $this->email = $record['email'];
     $this->language_key = $record['language_key'];
     $this->path = $record['path'];
     $this->editor = $record['editor'];
     $this->skin = isset($record['skin']) ? $record['skin'] : 'base';
     // see note above
     // Prepare for retrieval of acls/permissions
     $this->acl_id = intval($record['acl_id']);
     $this->related_acls = calc_user_related_acls($user_id);
     // Always fetch the site-wide permissions from acls table (others are cached on demand)
     $fields = array_keys($this->acls);
     $where = $this->where_acl_id();
     $records = db_select_all_records('acls', $fields, $where);
     if ($records === FALSE) {
         logger('useraccount: cannot find acls records for user_id \'' . $user_id . '\'', WLOG_INFO, $user_id);
     } else {
         foreach ($records as $record) {
             foreach ($fields as $field) {
                 $this->acls[$field] |= $record[$field];
             }
         }
     }
     // get all properties for this user in 2D array (sections, entries)
     $tablename = 'users_properties';
     $fields = array('section', 'name', 'type', 'value');
     $where = array('user_id' => $user_id);
     $order = array('section', 'name');
     $records = db_select_all_records($tablename, $fields, $where, $order);
     if ($records !== FALSE) {
         $properties = array();
         foreach ($records as $rec) {
             $properties[$rec['section']][$rec['name']] = convert_to_type($rec['type'], $rec['value']);
         }
         $this->properties = $properties;
     }
     return TRUE;
 }
 /** show a dialog for modifying page manager permissions for a user
  *
  * @return void results are returned as output in $this->output
  * @uses $WAS_SCRIPT_NAME
  * @uses $CFG
  */
 function user_pagemanager()
 {
     global $WAS_SCRIPT_NAME, $CFG;
     //
     // 0 -- sanity check
     //
     $user_id = get_parameter_int('user', NULL);
     if (is_null($user_id)) {
         logger("usermanager->user_pagemanager(): unspecified parameter user");
         $this->output->add_message(t('error_invalid_parameters', 'admin'));
         $this->users_overview();
         return;
     }
     //
     // 1 -- maybe change the state of the open/closed areas
     //
     if (!isset($_SESSION['aclmanager_open_areas'])) {
         $_SESSION['aclmanager_open_areas'] = FALSE;
         // default: everything is closed
     }
     $area_id = get_parameter_int('area', NULL);
     $_SESSION['aclmanager_open_areas'] = $this->areas_expand_collapse($_SESSION['aclmanager_open_areas'], $area_id);
     //
     // 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);
     $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;
     }
     //
     // 3B -- setup Aclmanager to do the dirty work
     //
     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(USERMANAGER_DIALOG_PAGEMANAGER);
     // 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
     $acl->enable_area_view($a_params, $_SESSION['aclmanager_open_areas']);
     //
     // 4 -- show dialog + menu
     //
     $acl->show_dialog();
     $this->show_menu_user($user_id, TASK_USER_PAGEMANAGER);
 }