/** construct a dialog definition for adding (uploading) files
  *
  * this constructs an array which defines a file(s) upload dialog.
  * Note that we make a subtle difference between a single-file upload and
  * a multifile upload: I think it looks stupid to start numbering a list
  * of files to upload when there is in fact only a list of exactly 1 file(s).
  * The cost is minimal: two extra strings in the translation file.
  *
  * @param int $num_files the maximum number of file upload fields to add to the dialog (default 1)
  * @return array with dialog definition keyed on field name
  */
 function get_dialogdef_add_files($num_files = 1)
 {
     $num_files = max(1, min(512, intval($num_files)));
     // sane limits: $num_files between 1 and (arbitrary) 512
     $upload_max_filesize = ini_get_int('upload_max_filesize');
     $dialogdef = array('MAX_FILE_SIZE' => array('type' => F_INTEGER, 'name' => 'MAX_FILE_SIZE', 'value' => $upload_max_filesize, 'hidden' => TRUE));
     if ($num_files == 1) {
         $dialogdef['filename'] = array('type' => F_FILE, 'name' => 'filename', 'columns' => 50, 'label' => t('filemanager_add_file_label', 'admin'), 'title' => t('filemanager_add_file_title', 'admin'), 'value' => '');
     } else {
         for ($i = 1; $i <= $num_files; ++$i) {
             $field = sprintf('filename%d', $i);
             $params = array('{INDEX}' => strval($i));
             $dialogdef[$field] = array('type' => F_FILE, 'name' => $field, 'columns' => 50, 'label' => t('filemanager_add_files_label', 'admin', $params), 'title' => t('filemanager_add_files_title', 'admin', $params), 'value' => '');
         }
     }
     $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
     $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
     return $dialogdef;
 }
/** construct an option to select a skin and start an Edit session
 *
 * this defines a dialog where the user can pick a skin from a list
 * of existing skins and subsequently press [Edit] to actually edit
 * the document.
 *
 * @return array dialogdefinition
 */
function crew_view_dialogdef()
{
    $options = array('0' => array('option' => t('skin_standard_option', 'm_crew'), 'title' => t('skin_standard_title', 'm_crew'), 'css' => 'crew.css'), '1' => array('option' => t('skin_bw_option', 'm_crew'), 'title' => t('skin_bw_title', 'm_crew'), 'css' => 'crew_bw.css'), '2' => array('option' => t('skin_rb_option', 'm_crew'), 'title' => t('skin_rb_title', 'm_crew'), 'css' => 'crew_rb.css'), '3' => array('option' => t('skin_by_option', 'm_crew'), 'title' => t('skin_by_title', 'm_crew'), 'css' => 'crew_by.css'));
    $dialogdef = array('skin' => array('type' => F_LISTBOX, 'name' => 'skin', 'value' => '0', 'options' => $options, 'title' => t('skin_title', 'm_crew'), 'label' => t('skin_label', 'm_crew')), 'button_edit' => dialog_buttondef(BUTTON_EDIT));
    return $dialogdef;
}
 /** construct a dialog definition for pagemanager permissions
  *
  */
 function get_dialogdef_pagemanager($acl_id, $related_acls)
 {
     global $DB;
     //
     // 0 -- initialise
     //
     $roles_area = $this->get_roles_pagemanager(ACL_LEVEL_AREA);
     $roles_site = $this->get_roles_pagemanager(ACL_LEVEL_SITE);
     $dialogdef = array();
     if (!empty($this->dialog)) {
         $dialogdef['dialog'] = array('type' => F_INTEGER, 'name' => 'dialog', 'value' => intval($this->dialog), 'hidden' => TRUE);
     }
     //
     // 1 -- construct site level role widget, fill with current role value if any
     //
     $value = ACL_ROLE_NONE;
     // assume no permissions at all
     $related = array();
     $acls = $this->get_permissions($acl_id, $related_acls, array('acl_id', 'permissions_nodes'));
     foreach ($acls as $id => $acl) {
         $permissions = intval($acl['permissions_nodes']);
         if ($id == $acl_id) {
             $value = $permissions;
         } elseif ($permissions != ACL_ROLE_NONE) {
             $role = isset($roles_site[$permissions]) ? $roles_site[$permissions]['option'] : t('acl_role_unknown', 'admin');
             $related[] = $related_acls[$id] . ': ' . $role;
         }
         // else no related permissions, so keep quiet
     }
     $dialogdef['acl_site'] = array('type' => F_LISTBOX, 'name' => 'acl_site', 'value' => $value, 'old_value' => $value, 'table_name' => 'acls', 'table_field' => 'permissions_nodes', 'table_where' => array('acl_id' => intval($acl_id)), 'options' => $roles_site, 'label' => t('acl_all_areas_label', 'admin'), 'is_modified' => FALSE, 'related' => $related);
     if ($this->area_view_enabled) {
         $dialogdef['acl_site']['area_id'] = 0;
         // sentinel value for site level expand/collapse
         $dialogdef['acl_site']['area_is_open'] = $this->area_view_areas_open === FALSE ? FALSE : TRUE;
         $dialogdef['acl_site']['area_offset'] = 0;
     }
     //
     // 2A -- prepare for area level widgets: calculate total # of elements to show
     //
     $areas = array();
     $this->pagination_total = $this->calc_areas_total($areas);
     if ($this->pagination_enabled) {
         $first = $this->pagination_offset;
         $last = min($this->pagination_total, $first + $this->pagination_limit) - 1;
     } else {
         $first = 0;
         $last = $this->pagination_total - 1;
     }
     if ($this->pagination_total > 0) {
         // there is at least 1 area to show
         $permissions_areas = $this->get_permissions_areas($acl_id, $related_acls, $areas);
         foreach ($areas as $area_id => $area) {
             $value = ACL_ROLE_NONE;
             $related = array();
             $acls = isset($permissions_areas[$area_id]) ? $permissions_areas[$area_id] : array();
             foreach ($acls as $id => $acl) {
                 $permissions = intval($acl['permissions_nodes']);
                 if ($id == $acl_id) {
                     $value = $permissions;
                 } elseif ($permissions != ACL_ROLE_NONE) {
                     $role = isset($roles_area[$permissions]) ? $roles_area[$permissions]['option'] : t('acl_role_unknown', 'admin');
                     $related[] = $related_acls[$id] . ': ' . $role;
                 }
                 // else no related permissions, so keep quiet
             }
             $params = array('{AREA}' => strval($area_id), '{AREA_FULL_NAME}' => $area['title']);
             $is_active = db_bool_is(TRUE, $area['is_active']);
             $label = t($is_active ? 'acl_area_label' : 'acl_area_inactive_label', 'admin', $params);
             $name = 'acl_area_' . strval($area_id);
             // show area itself
             $dialogdef[$name] = array('type' => F_LISTBOX, 'name' => $name, 'value' => $value, 'old_value' => $value, 'table_name' => 'acls_areas', 'table_field' => 'permissions_nodes', 'table_where' => array('acl_id' => intval($acl_id), 'area_id' => intval($area_id)), 'options' => $roles_area, 'label' => $label, 'is_modified' => FALSE, 'related' => $related);
             if ($this->area_view_enabled) {
                 $dialogdef[$name]['area_id'] = $area_id;
                 $dialogdef[$name]['area_is_open'] = $area['show'];
                 $dialogdef[$name]['area_offset'] = $area['first'];
             }
             //
             // maybe show tree of nodes too
             //
             if ($area['show'] && $area['nodes'] > 0) {
                 $index = $area['first'] + 1;
                 $tree = $this->tree_build($area_id);
                 $permissions_nodes = $this->get_permissions_nodes_in_area($area_id, $acl_id, $related_acls);
                 foreach ($tree as $node_id => $node) {
                     $tree[$node_id]['permissions'] = isset($permissions_nodes[$node_id]) ? $permissions_nodes[$node_id] : array();
                 }
                 $this->show_tree_walk($dialogdef, $tree, $permissions_nodes, $index, $tree[0]['first_child_id'], $first, $last, $acl_id, $related_acls);
                 unset($tree);
                 unset($permissions_nodes);
             }
         }
     }
     //
     // 4 -- always finish with Save and Cancel
     //
     $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
     $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
     return $dialogdef;
 }
 /** construct an array with the dialog information
  *
  * @return array the dialog information 
  * @todo implement checklist
  */
 function get_dialogdef()
 {
     $dialogdef = is_array($this->dialogdef_hidden) ? $this->dialogdef_hidden : array();
     if (is_array($this->records)) {
         foreach ($this->records as $id => $record) {
             $extra = $this->get_extra($record['type'], $record['extra']);
             $name = $this->prefix . 'record_' . strval($id);
             $item = array('type' => F_ALPHANUMERIC, 'name' => $name, 'value' => $record['value'], 'label' => t($this->prefix . $record['name'] . '_label', $this->language_domain), 'title' => t($this->prefix . $record['name'] . '_title', $this->language_domain), 'is_modified' => FALSE, 'columns' => 50);
             switch ($record['type']) {
                 case 'b':
                     $item['type'] = F_CHECKBOX;
                     $item['options'] = array(1 => t($this->prefix . $record['name'] . '_option', $this->language_domain));
                     $item['value'] = intval($record['value']) != 0 ? '1' : '';
                     break;
                 case 'c':
                     // not implemented yet
                     break;
                 case 'd':
                     $item['type'] = F_DATE;
                     $item['columns'] = 20;
                     $item['maxlength'] = 20;
                     break;
                 case 'dt':
                     $item['type'] = F_DATETIME;
                     $item['columns'] = 20;
                     $item['maxlength'] = 20;
                     break;
                 case 'f':
                     $item['type'] = F_REAL;
                     if (is_numeric($record['value'])) {
                         $decimals = isset($extra['decimals']) ? abs(intval($extra['decimals'])) : 2;
                         $item['value'] = sprintf("%1." . $decimals . "f", floatval($record['value']));
                     } else {
                         $item['value'] = NULL;
                     }
                     $item['columns'] = 20;
                     $item['maxlength'] = 20;
                     break;
                 case 'i':
                     $item['type'] = F_INTEGER;
                     $item['value'] = is_numeric($record['value']) ? intval($record['value']) : NULL;
                     $item['columns'] = 20;
                     $item['maxlength'] = 12;
                     break;
                 case 'l':
                     $item['type'] = F_LISTBOX;
                     $item['options'] = $this->get_options_from_extra($extra, $record['name']);
                     $item['value'] = $record['value'];
                     break;
                 case 'r':
                     $item['type'] = F_RADIO;
                     $item['options'] = $this->get_options_from_extra($extra, $record['name']);
                     $item['value'] = $record['value'];
                     break;
                 case 's':
                     $item['type'] = F_ALPHANUMERIC;
                     break;
                 case 't':
                     $item['type'] = F_TIME;
                     $item['columns'] = 20;
                     $item['maxlength'] = 20;
                     break;
                 default:
                     break;
             }
             if (!empty($extra)) {
                 foreach ($extra as $k => $v) {
                     if ($k != 'options') {
                         $item[$k] = $v;
                     }
                 }
             }
             $item['old_value'] = $item['value'];
             $dialogdef[$name] = $item;
         }
         // foreach
     }
     // if (any records at all)
     $dialogdef[] = dialog_buttondef(BUTTON_SAVE);
     $dialogdef[] = dialog_buttondef(BUTTON_CANCEL);
     return $dialogdef;
 }
 /** construct the edit user dialog
  *
  * @param int $user_id indicates which user to edit
  * @return bool|array FALSE on error or array with dialog definition and existing data from database
  * @uses $LANGUAGE
  */
 function get_dialogdef_edit_user($user_id)
 {
     global $LANGUAGE;
     $user_id = intval($user_id);
     // 1 -- retrieve data from users-record
     if (($user = $this->get_user_record($user_id)) === FALSE) {
         return FALSE;
     }
     $params = array('{MIN_LENGTH}' => MINIMUM_PASSWORD_LENGTH, '{MIN_LOWER}' => MINIMUM_PASSWORD_LOWERCASE, '{MIN_UPPER}' => MINIMUM_PASSWORD_UPPERCASE, '{MIN_DIGIT}' => MINIMUM_PASSWORD_DIGITS);
     // 2 -- construct dialog definition including current values from database
     $dialogdef = array('dialog' => array('type' => F_INTEGER, 'name' => 'dialog', 'value' => USERMANAGER_DIALOG_EDIT, 'hidden' => TRUE), 'username' => array('type' => F_ALPHANUMERIC, 'name' => 'username', 'minlength' => 1, 'maxlength' => 60, 'columns' => 30, 'label' => t('usermanager_edit_username_label', 'admin'), 'title' => t('usermanager_edit_username_title', 'admin'), 'value' => $user['username'], 'old_value' => $user['username']), 'user_password1' => array('type' => F_PASSWORD, 'name' => 'user_password1', 'minlength' => 0, 'maxlength' => 255, 'columns' => 30, 'label' => t('usermanager_edit_user_password1_label', 'admin', $params), 'title' => t('usermanager_edit_user_password1_title', 'admin', $params), 'value' => ''), 'user_password2' => array('type' => F_PASSWORD, 'name' => 'user_password2', 'minlength' => 0, 'maxlength' => 255, 'columns' => 30, 'label' => t('usermanager_edit_user_password2_label', 'admin', $params), 'title' => t('usermanager_edit_user_password2_title', 'admin', $params), 'value' => ''), 'user_fullname' => array('type' => F_ALPHANUMERIC, 'name' => 'user_fullname', 'minlength' => 1, 'maxlength' => 255, 'columns' => 50, 'label' => t('usermanager_edit_user_fullname_label', 'admin'), 'title' => t('usermanager_edit_user_fullname_title', 'admin'), 'value' => $user['full_name'], 'old_value' => $user['full_name']), 'user_email' => array('type' => F_ALPHANUMERIC, 'name' => 'user_email', 'minlength' => 0, 'maxlength' => 255, 'columns' => 50, 'label' => t('usermanager_edit_user_email_label', 'admin'), 'title' => t('usermanager_edit_user_email_title', 'admin'), 'value' => $user['email'], 'old_value' => $user['email']), 'user_is_active' => array('type' => F_CHECKBOX, 'name' => 'user_is_active', 'options' => array(1 => t('usermanager_edit_user_is_active_check', 'admin')), 'label' => t('usermanager_edit_user_is_active_label', 'admin'), 'title' => t('usermanager_edit_user_is_active_title', 'admin'), 'value' => db_bool_is(TRUE, $user['is_active']) ? '1' : '', 'old_value' => db_bool_is(TRUE, $user['is_active']) ? '1' : ''), 'user_redirect' => array('type' => F_ALPHANUMERIC, 'name' => 'user_redirect', 'minlength' => 0, 'maxlength' => 255, 'columns' => 50, 'label' => t('usermanager_edit_user_redirect_label', 'admin'), 'title' => t('usermanager_edit_user_redirect_title', 'admin'), 'value' => $user['redirect'], 'old_value' => $user['redirect']), 'user_language_key' => array('type' => F_LISTBOX, 'name' => 'user_language_key', 'options' => $LANGUAGE->get_active_language_names(), 'label' => t('usermanager_edit_user_language_label', 'admin'), 'title' => t('usermanager_edit_user_language_title', 'admin'), 'value' => $user['language_key'], 'old_value' => $user['language_key']), 'user_editor' => array('type' => F_LISTBOX, 'name' => 'user_editor', 'options' => $this->get_editor_names(), 'label' => t('usermanager_edit_user_editor_label', 'admin'), 'title' => t('usermanager_edit_user_editor_title', 'admin'), 'value' => $user['editor'], 'old_value' => $user['editor']), 'user_skin' => array('type' => F_LISTBOX, 'name' => 'user_skin', 'options' => $this->get_skin_names(), 'label' => t('usermanager_edit_user_skin_label', 'admin'), 'title' => t('usermanager_edit_user_skin_title', 'admin'), 'value' => $user['skin'], 'old_value' => $user['skin']), 'user_path' => array('type' => F_ALPHANUMERIC, 'name' => 'user_path', 'minlength' => 1, 'maxlength' => 60, 'columns' => 30, 'label' => t('usermanager_edit_user_path_label', 'admin'), 'title' => t('usermanager_edit_user_path_title', 'admin'), 'value' => $user['path'], 'old_value' => $user['path'], 'viewonly' => TRUE), 'button_save' => dialog_buttondef(BUTTON_SAVE), 'button_cancel' => dialog_buttondef(BUTTON_CANCEL));
     return $dialogdef;
 }
 /** construct a dialog definition for editing advanced properties of a node (page or section)
  *
  * this constructs a dialog to edit the advanced properties of a node.
  * There is a slight difference between pages and sections: a section can
  * have neither the 'target' property nor the 'href' property; that only makes
  * sense for a page, so these input fields are not displayed for a section.
  *
  * The readonly-property is a special case. Even if the parameter $viewonly is
  * TRUE, the readonly-field is displayed as 'editable'. This is because this
  * particular field is used to toggle the viewonly mode: if a node is readonly,
  * it cannot be edited, except the removal of the readonly attribute.
  * 
  * @param int $area_id the area in which the node lives
  * @param int $node_id the node that is to be edited
  * @param bool $is_page TRUE if the dialog is for a page, FALSE is for a section
  * @param bool $viewonly if TRUE, most fields are 'dimmed' (uneditable)
  * @return array with definition of the dialog
  */
 function get_dialogdef_edit_advanced_node($node_id, $is_page, $viewonly = FALSE)
 {
     $dialogdef = array('dialog' => array('type' => F_INTEGER, 'name' => 'dialog', 'value' => DIALOG_NODE_EDIT_ADVANCED, 'hidden' => TRUE), 'node_is_readonly' => array('type' => F_CHECKBOX, 'name' => 'node_is_readonly', 'options' => array(1 => t('edit_node_is_readonly_label', 'admin')), 'label' => t('edit_node_is_readonly', 'admin'), 'title' => t('edit_node_is_readonly_title', 'admin')), 'node_area_id' => array('type' => F_LISTBOX, 'name' => 'node_area_id', 'value' => '', 'label' => t('edit_node_area_id', 'admin'), 'title' => t('edit_node_area_id_title', 'admin'), 'options' => $this->get_options_area($node_id, $is_page), 'viewonly' => $viewonly), 'node_link_image' => array('type' => F_ALPHANUMERIC, 'name' => 'node_link_image', 'maxlength' => 240, 'columns' => 50, 'label' => t('edit_node_link_image', 'admin'), 'title' => t('edit_node_link_image_title', 'admin'), 'viewonly' => $viewonly), 'node_link_image_width' => array('type' => F_INTEGER, 'name' => 'node_link_image_width', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 0, 'maxvalue' => 9999, 'label' => t('edit_node_link_image_width', 'admin'), 'title' => t('edit_node_link_image_width_title', 'admin'), 'viewonly' => $viewonly), 'node_link_image_height' => array('type' => F_INTEGER, 'name' => 'node_link_image_height', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 0, 'maxvalue' => 9999, 'label' => t('edit_node_link_image_height', 'admin'), 'title' => t('edit_node_link_image_height_title', 'admin'), 'viewonly' => $viewonly), 'node_is_hidden' => array('type' => F_CHECKBOX, 'name' => 'node_is_hidden', 'options' => array(1 => t('edit_node_is_hidden_label', 'admin')), 'label' => t('edit_node_is_hidden', 'admin'), 'title' => t('edit_node_is_hidden_title', 'admin'), 'viewonly' => $viewonly), 'node_embargo' => array('type' => F_DATETIME, 'name' => 'node_embargo', 'maxlength' => 30, 'columns' => 30, 'minvalue' => '1000-01-01 00:00:00', 'maxvalue' => '9999-12-31 23:59:59', 'label' => t('edit_node_embargo', 'admin'), 'title' => t('edit_node_embargo_title', 'admin'), 'viewonly' => $viewonly), 'node_expiry' => array('type' => F_DATETIME, 'name' => 'node_expiry', 'maxlength' => 30, 'columns' => 30, 'minvalue' => '1000-01-01 00:00:00', 'maxvalue' => '9999-12-31 23:59:59', 'label' => t('edit_node_expiry', 'admin'), 'title' => t('edit_node_expiry_title', 'admin'), 'viewonly' => $viewonly), 'node_style' => array('type' => F_ALPHANUMERIC, 'name' => 'node_style', 'maxlength' => 16383, 'columns' => 70, 'rows' => 10, 'label' => t('edit_node_style_label', 'admin'), 'title' => t('edit_node_style_title', 'admin'), 'viewonly' => $viewonly), 'button_save' => dialog_buttondef(BUTTON_SAVE), 'button_cancel' => dialog_buttondef(BUTTON_CANCEL));
     return $dialogdef;
 }
/** construct a dialog definition for a mailpage address configuration
 *
 * @param object &$output collects the html output (if any)
 * @param int $viewonly if TRUE the Save button is not displayed and config values cannot be changed
 * @param int $node_id identifies the current mailpage
 * @param int $address_id identifies the address, 0 for a new one
 * @param int $sort_order is the next available sort order for new records
 * @return array dialog definition
 */
function mailpage_get_dialogdef_address(&$output, $viewonly, $node_id, $address_id, $sort_order = 10)
{
    //
    // 1 -- maybe get existing data from table
    //
    $values = array('name' => '', 'sort_order' => $sort_order, 'email' => '', 'description' => '', 'thankyou' => '', 'message' => '');
    if ($address_id > 0) {
        $table = 'mailpages_addresses';
        $keyfield = 'mailpage_address_id';
        $fields = '*';
        $where = array('node_id' => intval($node_id), $keyfield => intval($address_id));
        if (($record = db_select_single_record($table, $fields, $where)) === FALSE) {
            logger(sprintf('%s(): error retrieving configuration: %s', __FUNCTION__, db_errormessage()));
            $output->add_message(t('error_retrieving_data', 'admin'));
        } else {
            $values = $record;
        }
    }
    //
    // 2 -- define the dialog
    //
    $dialogdef = array('name' => array('type' => F_ALPHANUMERIC, 'name' => 'name', 'minlength' => 0, 'maxlength' => 80, 'columns' => 40, 'label' => t('address_name_label', 'm_mailpage'), 'title' => t('address_name_title', 'm_mailpage'), 'viewonly' => $viewonly, 'value' => $values['name'], 'old_value' => $values['name']), 'email' => array('type' => F_ALPHANUMERIC, 'name' => 'email', 'minlength' => 0, 'maxlength' => 255, 'columns' => 40, 'label' => t('address_email_label', 'm_mailpage'), 'title' => t('address_email_title', 'm_mailpage'), 'viewonly' => $viewonly, 'value' => $values['email'], 'old_value' => $values['email']), 'description' => array('type' => F_ALPHANUMERIC, 'name' => 'description', 'minlength' => 0, 'maxlength' => 240, 'columns' => 40, 'label' => t('address_description_label', 'm_mailpage'), 'title' => t('address_description_title', 'm_mailpage'), 'viewonly' => $viewonly, 'value' => $values['description'], 'old_value' => $values['description']), 'thankyou' => array('type' => F_ALPHANUMERIC, 'name' => 'thankyou', 'minlength' => 0, 'maxlength' => 240, 'columns' => 40, 'label' => t('address_thankyou_label', 'm_mailpage'), 'title' => t('address_thankyou_title', 'm_mailpage'), 'viewonly' => $viewonly, 'value' => $values['thankyou'], 'old_value' => $values['thankyou']), 'sort_order' => array('type' => F_INTEGER, 'name' => 'sort_order', 'minlength' => 0, 'maxlength' => 10, 'columns' => 7, 'minvalue' => 0, 'label' => t('address_sort_order_label', 'm_mailpage'), 'title' => t('address_sort_order_title', 'm_mailpage'), 'viewonly' => $viewonly, 'value' => $values['sort_order'], 'old_value' => $values['sort_order']));
    //
    // 3 -- add buttons: save (mabye), cancel and delete (maybe)
    //
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    if (!$viewonly && $address_id != 0) {
        $dialogdef['button_delete'] = dialog_buttondef(BUTTON_DELETE);
    }
    return $dialogdef;
}
/** construct a dialog definition for the snapshots configuration data
 *
 * @param int $viewonly if TRUE the Save button is not displayed and config values cannot be changed
 * @return array dialog definition
 */
function snapshots_get_dialogdef($viewonly)
{
    $options = array('1' => array('option' => t('variant_thumbs_label', 'm_snapshots'), 'title' => t('variant_thumbs_title', 'm_snapshots')), '2' => array('option' => t('variant_first_label', 'm_snapshots'), 'title' => t('variant_first_title', 'm_snapshots')), '3' => array('option' => t('variant_slideshow_label', 'm_snapshots'), 'title' => t('variant_slideshow_title', 'm_snapshots')));
    $dialogdef = array('header' => array('type' => F_ALPHANUMERIC, 'name' => 'header', 'minlength' => 0, 'maxlength' => 240, 'columns' => 30, 'viewonly' => $viewonly, 'label' => t('header_label', 'm_snapshots'), 'title' => t('header_title', 'm_snapshots'), 'value' => ''), 'introduction' => array('type' => F_ALPHANUMERIC, 'name' => 'introduction', 'minlength' => 0, 'maxlength' => 32768, 'columns' => 50, 'rows' => 10, 'viewonly' => $viewonly, 'label' => t('introduction_label', 'm_snapshots'), 'title' => t('introduction_title', 'm_snapshots'), 'value' => ''), 'snapshots_path' => array('type' => F_ALPHANUMERIC, 'name' => 'snapshots_path', 'minlength' => 0, 'maxlength' => 240, 'columns' => 50, 'viewonly' => $viewonly, 'label' => t('snapshots_path_label', 'm_snapshots'), 'title' => t('snapshots_path_title', 'm_snapshots'), 'value' => ''), 'variant' => array('type' => F_RADIO, 'name' => 'variant', 'value' => 1, 'options' => $options, 'viewonly' => $viewonly, 'title' => t('variant_title', 'm_snapshots'), 'label' => t('variant_label', 'm_snapshots')), 'dimension' => array('type' => F_INTEGER, 'name' => 'dimension', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 10, 'maxvalue' => 9999, 'viewonly' => $viewonly, 'title' => t('dimension_title', 'm_snapshots'), 'label' => t('dimension_label', 'm_snapshots')));
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    return $dialogdef;
}
/** construct a dialog definition for the aggregator configuration data
 *
 * @param int $viewonly if TRUE the Save button is not displayed and config values cannot be changed
 * @return array dialog definition
 */
function aggregator_get_dialogdef($viewonly)
{
    $dialogdef = array('header' => array('type' => F_ALPHANUMERIC, 'name' => 'header', 'minlength' => 0, 'maxlength' => 240, 'columns' => 30, 'viewonly' => $viewonly, 'label' => t('header_label', 'm_aggregator'), 'title' => t('header_title', 'm_aggregator'), 'value' => ''), 'introduction' => array('type' => F_ALPHANUMERIC, 'name' => 'introduction', 'minlength' => 0, 'maxlength' => 32768, 'columns' => 50, 'rows' => 10, 'viewonly' => $viewonly, 'label' => t('introduction_label', 'm_aggregator'), 'title' => t('introduction_title', 'm_aggregator'), 'value' => ''), 'node_list' => array('type' => F_ALPHANUMERIC, 'name' => 'node_list', 'minlength' => 0, 'maxlength' => 240, 'columns' => 30, 'viewonly' => $viewonly, 'label' => t('node_list_label', 'm_aggregator'), 'title' => t('node_list_title', 'm_aggregator'), 'value' => ''), 'items' => array('type' => F_INTEGER, 'name' => 'items', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 0, 'maxvalue' => 99, 'viewonly' => $viewonly, 'title' => t('items_title', 'm_aggregator'), 'label' => t('items_label', 'm_aggregator')), 'reverse_order' => array('type' => F_CHECKBOX, 'name' => 'reverse_order', 'options' => array(1 => t('reverse_order_check', 'm_aggregator')), 'viewonly' => $viewonly, 'title' => t('reverse_order_title', 'm_aggregator'), 'label' => t('reverse_order_label', 'm_aggregator')), 'htmlpage_length' => array('type' => F_INTEGER, 'name' => 'htmlpage_length', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 0, 'maxvalue' => 99, 'viewonly' => $viewonly, 'title' => t('htmlpage_length_title', 'm_aggregator'), 'label' => t('htmlpage_length_label', 'm_aggregator')), 'snapshots_width' => array('type' => F_INTEGER, 'name' => 'snapshots_width', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 16, 'maxvalue' => 9999, 'viewonly' => $viewonly, 'title' => t('snapshots_width_title', 'm_aggregator'), 'label' => t('snapshots_width_label', 'm_aggregator')), 'snapshots_height' => array('type' => F_INTEGER, 'name' => 'snapshots_height', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 16, 'maxvalue' => 9999, 'viewonly' => $viewonly, 'title' => t('snapshots_height_title', 'm_aggregator'), 'label' => t('snapshots_height_label', 'm_aggregator')), 'snapshots_visible' => array('type' => F_INTEGER, 'name' => 'snapshots_visible', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 1, 'maxvalue' => 32, 'viewonly' => $viewonly, 'title' => t('snapshots_visible_title', 'm_aggregator'), 'label' => t('snapshots_visible_label', 'm_aggregator')), 'snapshots_showtime' => array('type' => F_INTEGER, 'name' => 'snapshots_showtime', 'columns' => 10, 'maxlength' => 10, 'minvalue' => 1, 'maxvalue' => 3600, 'viewonly' => $viewonly, 'title' => t('snapshots_showtime_title', 'm_aggregator'), 'label' => t('snapshots_showtime_label', 'm_aggregator')));
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    return $dialogdef;
}
 /** construct a simple jumplist to navigate to other areas
  *
  * this constructs a listbox with areas to which the current user has access.
  * The user can pick an area from the list and press the [Go] button to navigate
  * to that area. Only the active areas are displayed. Private areas are only displayed
  * when the user actually has access to those areas.
  *
  * This routine always shows the Submit-button even when JavaScript is turned 'off'. If it is 'on',
  * a tiny snippet auto-submits the form whenever the user selects another area; no need
  * press any button anymore. However, pressing the Go button is necessary when Javascript is 'off'.
  * Rationale: the user will find out soon enough that pressing the button is superfluous, and
  * as a benefit we keep the same look and feel no matter the state of Javascript.
  *
  * We rely on the constructor to provide us with an array of area_id=>area_title pairs
  * in the $this->jumps array.
  *
  * The special preview-mode is implemented by adding the necessary hash in the preview parameter
  * via a hidden field. This will ultimately lead to ourselves, with the preview code so we can
  * never leave for another area in preview mode.
  *
  * @param string $m add readabiliy to output
  * @return string properly indented ready-to-use HTML or an empty string on error
  * @uses dialog_get_widget()
  */
 function get_jumpmenu($m = '')
 {
     // 1 -- KISS form with a whiff of javascript (but don't  get rid of the Go-button)
     $title = t('jumpmenu_area_title', $this->domain);
     $attributes = array('name' => 'area', 'title' => $title, 'onchange' => 'this.form.submit();');
     $jumpmenu = $m . html_form(was_node_url(), 'get') . "\n" . $m . '  ' . t('jumpmenu_area', $this->domain) . "\n";
     // 2 -- maybe add the hidden field that keeps us in preview-mode
     if ($this->preview_mode) {
         $hash = md5($_SESSION['preview_salt'] . $_SESSION['preview_node']);
         $jumpmenu .= $m . '  ' . html_tag('input', array('type' => 'hidden', 'name' => 'preview', 'value' => $hash)) . "\n";
     }
     // 3 -- add a select box with available areas
     $jumpmenu .= $m . "  " . html_tag('select', $attributes) . "\n";
     foreach ($this->jumps as $k => $v) {
         $attributes = array('title' => $title, 'value' => $k);
         if ($k == $this->area_id) {
             $attributes['selected'] = NULL;
         }
         $jumpmenu .= $m . '    ' . html_tag('option', $attributes, $v) . "\n";
     }
     $jumpmenu .= $m . "  </select>\n";
     // 4 -- add button and close all open tags.
     $jumpmenu .= $m . "  " . dialog_get_widget(dialog_buttondef(BUTTON_GO)) . "\n" . $m . html_form_close() . "\n";
     return $jumpmenu;
 }
 /** construct the edit group dialog
  *
  * @param int $group_id the group that will be edited
  * @return array|bool FALSE on errors retrieving data, otherwise array containing the dialog definition
  */
 function get_dialogdef_edit_group($group_id)
 {
     $group_id = intval($group_id);
     // 1A -- retrieve data from groups-record
     if (($group = $this->get_group_record($group_id)) === FALSE) {
         return FALSE;
     }
     // 1B -- retrieve the available capacities for this group (could be 0)
     $capacities = db_select_all_records('groups_capacities', '*', array('group_id' => $group_id), 'sort_order');
     if ($capacities === FALSE) {
         return FALSE;
     }
     // 2 -- construct dialog definition including current values from database
     $dialogdef = array('dialog' => array('type' => F_INTEGER, 'name' => 'dialog', 'value' => GROUPMANAGER_DIALOG_EDIT, 'hidden' => TRUE), 'group_name' => array('type' => F_ALPHANUMERIC, 'name' => 'group_name', 'minlength' => 1, 'maxlength' => 60, 'columns' => 30, 'label' => t('groupmanager_edit_group_name_label', 'admin'), 'title' => t('groupmanager_edit_group_name_title', 'admin'), 'value' => $group['groupname'], 'old_value' => $group['groupname']), 'group_fullname' => array('type' => F_ALPHANUMERIC, 'name' => 'group_fullname', 'minlength' => 1, 'maxlength' => 255, 'columns' => 30, 'label' => t('groupmanager_edit_group_fullname_label', 'admin'), 'title' => t('groupmanager_edit_group_fullname_title', 'admin'), 'value' => $group['full_name'], 'old_value' => $group['full_name']), 'group_is_active' => array('type' => F_CHECKBOX, 'name' => 'group_is_active', 'options' => array(1 => t('groupmanager_edit_group_is_active_check', 'admin')), 'label' => t('groupmanager_edit_group_is_active_label', 'admin'), 'title' => t('groupmanager_edit_group_is_active_title', 'admin'), 'value' => db_bool_is(TRUE, $group['is_active']) ? '1' : '', 'old_value' => db_bool_is(TRUE, $group['is_active']) ? '1' : ''));
     $options = $this->get_options_capacities();
     for ($i = 1; $i <= GROUPMANAGER_MAX_CAPACITIES; ++$i) {
         if (isset($capacities[$i - 1])) {
             $value = intval($capacities[$i - 1]['capacity_code']);
             $sort_order = intval($capacities[$i - 1]['sort_order']);
             $acl_id = intval($capacities[$i - 1]['acl_id']);
         } else {
             $value = CAPACITY_NONE;
             $sort_order = 0;
             $acl_id = 0;
         }
         $dialogdef['group_capacity_' . $i] = array('type' => F_LISTBOX, 'name' => 'group_capacity_' . $i, 'value' => $value, 'old_value' => $value, 'label' => t('groupmanager_edit_group_capacity_label', 'admin', array('{INDEX}' => strval($i))), 'title' => t('groupmanager_edit_group_capacity_title', 'admin'), 'options' => $options, 'sort_order' => $sort_order, 'acl_id' => $acl_id);
     }
     $dialogdef['group_path'] = array('type' => F_ALPHANUMERIC, 'name' => 'group_path', 'minlength' => 1, 'maxlength' => 60, 'columns' => 30, 'label' => t('groupmanager_edit_group_path_label', 'admin'), 'title' => t('groupmanager_edit_group_path_title', 'admin'), 'value' => $group['path'], 'old_value' => $group['path'], 'viewonly' => TRUE);
     $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
     $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
     return $dialogdef;
 }
/** construct a dialog definition for the sitemap 'scope' value
 *
 * @param int $viewonly if TRUE the Save button is not displayed and config values cannot be changed by the user
 * @return array dialog definition
 */
function sitemap_get_dialogdef($viewonly)
{
    $options = array('0' => array('option' => t('scope_small_label', 'm_sitemap'), 'title' => t('scope_small_title', 'm_sitemap')), '1' => array('option' => t('scope_medium_label', 'm_sitemap'), 'title' => t('scope_medium_title', 'm_sitemap')), '2' => array('option' => t('scope_large_label', 'm_sitemap'), 'title' => t('scope_large_title', 'm_sitemap')));
    $dialogdef = array('header' => array('type' => F_ALPHANUMERIC, 'name' => 'header', 'minlength' => 0, 'maxlength' => 240, 'columns' => 30, 'label' => t('header_label', 'm_sitemap'), 'title' => t('header_title', 'm_sitemap'), 'value' => ''), 'introduction' => array('type' => F_ALPHANUMERIC, 'name' => 'introduction', 'minlength' => 0, 'maxlength' => 32768, 'columns' => 50, 'rows' => 10, 'label' => t('introduction_label', 'm_sitemap'), 'title' => t('introduction_title', 'm_sitemap'), 'value' => ''), 'scope' => array('type' => F_RADIO, 'name' => 'scope', 'value' => 0, 'options' => $options, 'viewonly' => $viewonly, 'title' => t('scope_title', 'm_sitemap'), 'label' => t('scope_label', 'm_sitemap')));
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    return $dialogdef;
}
/** present the user with a dialog to modify the content that is connected to node $node_id
 *
 * this prepares a dialog for the user filled with existing data (if any), possibly allowing
 * the user to modify the content. If the flag $viewonly is TRUE, this routine should only
 * display the content rather than let the user edit it. If the flag $edit_again is TRUE,
 * the routine should use the data available in the $_POST array, otherwise it should read
 * the data from the database (or wherever the data comes from). The parameter $href is the
 * place where the form should be POST'ed.
 *
 * The dialog should be added to the $output object. Useful routines are:
 * <code>
 * $output->add_content($content): add $content to the content area
 * $output->add_message($message): add $message to the message area (feedback to the user)
 * $output->add_popup_bottom($message): make $message popup in the browser after loading the page (uses javascript)
 * $output->add_popup_top($message): make $message popup in the browser before loading the page (uses javascript)
 * </code>
 * 
 * @param object &$output collects the html output (if any)
 * @param int $area_id the area in which $node_id resides
 * @param int $node_id the node to which this module is connected
 * @param array $module the module record straight from the database
 * @param bool $viewonly if TRUE, editing is not allowed (but simply showing the content is allowed)
 * @param bool $edit_again if TRUE start with data from $_POST, else use data from database
 * @param string $href the action property of the HTML-form, the placa where data will be POST'ed
 * @return bool TRUE on success + output stored via $output, FALSE otherwise
 */
function htmlpage_show_edit(&$output, $area_id, $node_id, $module, $viewonly, $edit_again, $href)
{
    if ($edit_again) {
        $value = magic_unquote($_POST['htmlpage_content']);
    } else {
        $where = array('node_id' => intval($node_id));
        $order = array('version DESC');
        $retval = db_select_single_record('htmlpages', '*', $where, $order);
        if ($retval === FALSE) {
            $value = '??error??';
            $version = 0;
        } else {
            $value = $retval['page_data'];
            $version = $retval['version'];
        }
    }
    $dialogdef = array('htmlpage_content' => array('type' => F_RICHTEXT, 'name' => 'htmlpage_content', 'value' => $value, 'rows' => 20, 'columns' => 80, 'maxlength' => 655360, 'viewonly' => $viewonly, 'alt' => 'STUB: alttext goes here', 'title' => 'STUB: mouse-over goes here'));
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    $output->add_content(dialog_quickform($href, $dialogdef));
    return TRUE;
}
 /** show the name of an area and ask the user for a confirmation of deletion
  *
  * this displays a confirmation question for deletion of an area.
  * If the user presses Delete button, the area will be deleted,
  * if the user presses Cancel then nothing is deleted.
  *
  * @param int $area_id
  * @param array &$areas records with area information of all areas
  * @return void results are returned as output in $this->output
  */
 function show_dialog_confirm_delete($area_id, &$areas)
 {
     global $WAS_SCRIPT_NAME;
     $dialogdef = array('dialog' => array('type' => F_INTEGER, 'name' => 'dialog', 'value' => AREAMANAGER_DIALOG_DELETE, 'hidden' => TRUE), dialog_buttondef(BUTTON_DELETE), dialog_buttondef(BUTTON_CANCEL));
     $area = $areas[$area_id];
     $params = array('{AREA}' => $area_id, '{AREA_FULL_NAME}' => $area['title']);
     $this->output->add_content('<h2>' . t('delete_an_area_header', 'admin', $params) . '</h2>');
     $this->output->add_content(t('delete_area_explanation', 'admin'));
     $this->output->add_content('<ul>');
     $area_description = t(db_bool_is(TRUE, $area['is_private']) ? 'area_delete_private_title' : 'area_delete_public_title', 'admin', $params);
     $area_description .= db_bool_is(TRUE, $area['is_active']) ? '' : ' (' . t('inactive', 'admin') . ')';
     $this->output->add_content('  <li class="level0">' . $area_description);
     $this->output->add_content('</ul>');
     $this->output->add_content(t('delete_are_you_sure', 'admin'));
     $href = href($WAS_SCRIPT_NAME, $this->a_param(AREAMANAGER_CHORE_DELETE, $area_id));
     $this->output->add_content(dialog_quickform($href, $dialogdef));
 }
/** present the user with a dialog to modify the content that is connected to node $node_id
 *
 * this prepares a dialog for the user filled with existing data (if any), possibly allowing
 * the user to modify the content. If the flag $viewonly is TRUE, this routine should only
 * display the content rather than let the user edit it. If the flag $edit_again is TRUE,
 * the routine should use the data available in the $_POST array, otherwise it should read
 * the data from the database (or wherever the data comes from). The parameter $href is the
 * place where the form should be POST'ed.
 *
 * The dialog should be added to the $output object. Useful routines are:
 * <code>
 * $output->add_content($content): add $content to the content area
 * $output->add_message($message): add $message to the message area (feedback to the user)
 * $output->add_popup_bottom($message): make $message popup in the browser after loading the page (uses javascript)
 * $output->add_popup_top($message): make $message popup in the browser before loading the page (uses javascript)
 * </code>
 * 
 * @param object &$output collects the html output (if any)
 * @param int $area_id the area in which $node_id resides
 * @param int $node_id the node to which this module is connected
 * @param array $module the module record straight from the database
 * @param bool $viewonly if TRUE, editing is not allowed (but simply showing the content is allowed)
 * @param bool $edit_again if TRUE start with data from $_POST, else use data from database
 * @param string $href the action property of the HTML-form, the placa where data will be POST'ed
 * @return bool TRUE on success + output stored via $output, FALSE otherwise
 */
function guestbook_show_edit(&$output, $area_id, $node_id, $module, $viewonly, $edit_again, $href)
{
    $output->add_content('<h2>STUB - Edit Content Dialog (' . $module['name'] . ')</h2>');
    $output->add_content('STUB: ' . __FUNCTION__ . '() in ' . __FILE__ . ' (' . __LINE__ . ')' . "<br>viewonly = {$viewonly}<br>edit_again = {$edit_again}<br>href = {$href}<p>\n" . "Note that this is just a stub with two buttons. It really does nothing but exercise the module interface.<p>\n");
    $dialogdef = array(array('type' => F_CHECKBOX, 'name' => 'fail', 'options' => array(1 => 'STUB: Check the bo~x to let the save routine fail'), 'title' => 'STUB - check the box to test failure of the save routine()'), dialog_buttondef(BUTTON_SAVE), dialog_buttondef(BUTTON_CANCEL));
    $output->add_content(dialog_quickform($href, $dialogdef));
    return TRUE;
}
/** show a preview of the message to the visitor
 *
 * this shows a preview of the message to visitor.
 * Nothing is editable, it is view-only. The only option
 * is to either press the Send-button to actually send
 * the messate OR to press the Edit button to go back
 * to the editable form.
 *
 * Sending a message is a two-step procedure by design.
 *
 * @param object &$theme collects the (html) output
 * @param array mailpage configuration data in a (nested) array
 * @param array $dialogdef array that defines the input fields
 * @param string $ip_addr the originating IP-address
 * @return void output writted to $theme
 */
function mailpage_show_preview(&$theme, $config, $dialogdef, $ip_addr)
{
    $destinations = $forbidden = array(chr(10), chr(13), chr(34), '\\');
    $mailfrom = sprintf('&quot;%s&quot; &lt;%s&gt;', htmlspecialchars(str_replace($forbidden, '', trim($dialogdef['fullname']['value']))), htmlspecialchars(str_replace($forbidden, '', trim($dialogdef['email']['value']))));
    $subject = htmlspecialchars(trim($dialogdef['subject']['value']));
    $message = nl2br(htmlspecialchars(trim($dialogdef['message']['value'])));
    $remote_addr = htmlspecialchars($ip_addr);
    //
    // 2 -- actually output the preview
    //
    $theme->add_content(html_tag('h2', '', t('preview_header', 'm_mailpage')));
    $theme->add_content('<div>');
    $theme->add_content(sprintf('<strong>%s</strong>: %s<br>', t('from', 'm_mailpage'), $mailfrom));
    if (1 < sizeof($config['addresses'])) {
        // only show destination if there is more than 1
        $index = isset($dialogdef['destination']) ? $dialogdef['destination']['value'] : 0;
        $destination = $config['addresses'][$index]['name'];
        $sendto = htmlspecialchars('"' . str_replace($forbidden, '', trim($destination)) . '"');
        $theme->add_content(sprintf('<strong>%s</strong>: %s<br>', t('to', 'm_mailpage'), $sendto));
    }
    $theme->add_content(sprintf('<strong>%s</strong>: %s<br>', t('subject', 'm_mailpage'), $subject));
    $theme->add_content(sprintf('<strong>%s</strong>: %s<br>', t('date', 'm_mailpage'), date('r')));
    $theme->add_content(sprintf('<strong>%s</strong>: %s<br>', t('ip_addr', 'm_mailpage'), $remote_addr));
    $theme->add_content(sprintf("<strong>%s</strong>:<br>\n%s<br>", t('message', 'm_mailpage'), $message));
    $theme->add_content('</div>');
    //
    // 3 -- finish with navigation for the visitor
    //
    $previewdef = array('token' => $dialogdef['token'], 'button_edit' => dialog_buttondef(BUTTON_EDIT), 'button_send' => dialog_buttondef('button_send', t('button_send', 'm_mailpage')), 'button_cancel' => dialog_buttondef(BUTTON_CANCEL));
    $href = was_node_url($theme->node_record);
    $theme->add_content(dialog_quickform($href, $previewdef));
}
/** construct a dialog definition for the redirect 'scope' value
 *
 * @param int $viewonly if TRUE the Save button is not displayed and config values cannot be changed by the user
 * @return array dialog definition
 */
function redirect_get_dialogdef($viewonly)
{
    $dialogdef = array('link_href' => array('type' => F_ALPHANUMERIC, 'name' => 'link_href', 'maxlength' => 240, 'minlength' => 1, 'columns' => 50, 'label' => t('link_href', 'm_redirect'), 'title' => t('link_href_title', 'm_redirect'), 'viewonly' => $viewonly), 'link_target' => array('type' => F_ALPHANUMERIC, 'name' => 'link_target', 'maxlength' => 240, 'columns' => 50, 'label' => t('link_target', 'm_redirect'), 'title' => t('link_target_title', 'm_redirect'), 'viewonly' => $viewonly));
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    return $dialogdef;
}
/** construct a dialog definition for the workshop configuration
 *
 * this generates an array which defines the dialog for workshop configuration.
 * There are a few plain fields that simply go into the appropriate workshops
 * record and the save and cancel button. However, there may also be items
 * related to ACLs. These fields are used to define the user's roles and the
 * should be presented in a table. We abuse the field names for this purpose:
 * if the first 3 characters are 'acl' we put the widgets in an HTML-table, otherwise
 * it is just an ordinary widget.
 *
 * Note that in the case of a single simple user without any aquaintances (ie. a user
 * that is not member of any group) the user is not able to add herself to the list
 * of authorised users. What is the point of having a _collaborative_ workshop when
 * you are the only one to collaborate with? (However, it would be fairly easy to force/add
 * an entry for this user if the tmp table would turn out empty. Maybe later....?)
 * @param object &$output collects the html output (if any)
 * @param int $viewonly if TRUE the Save button is not displayed and values cannot be changed
 * @param int $module_id indicates the id of the crew module in the database (needed for ACL)
 * @param int $area_id indicates the area where node_id lives (needed for ACL)
 * @param int $node_id indicates which page we are loooking at (needed for ACL)
 * @param int $user_id indicates the current user (needed for ACL)
 * @return array dialog definition
 */
function crew_get_dialogdef(&$output, $viewonly, $module_id, $area_id, $node_id, $user_id)
{
    global $DB, $USER;
    static $dialogdef = NULL;
    if (!is_null($dialogdef)) {
        // recycle
        return $dialogdef;
    }
    $visibilities = array('2' => array('option' => t('visibility_world_label', 'm_crew'), 'title' => t('visibility_world_title', 'm_crew')), '1' => array('option' => t('visibility_all_label', 'm_crew'), 'title' => t('visibility_all_title', 'm_crew')), '0' => array('option' => t('visibility_workers_label', 'm_crew'), 'title' => t('visibility_workers_title', 'm_crew')));
    $roles = array(ACL_ROLE_NONE => array('option' => t('acl_role_none_option', 'admin'), 'title' => t('acl_role_none_title', 'admin')), CREW_ACL_ROLE_READONLY => array('option' => t('crew_acl_role_readonly_option', 'm_crew'), 'title' => t('crew_acl_role_readonly_title', 'm_crew')), CREW_ACL_ROLE_READWRITE => array('option' => t('crew_acl_role_readwrite_option', 'm_crew'), 'title' => t('crew_acl_role_readwrite_title', 'm_crew')), ACL_ROLE_GURU => array('option' => t('acl_role_guru_option', 'admin'), 'title' => t('acl_role_guru_title', 'admin')));
    // 1 -- plain & simple fields
    // make a fresh start with data from the database
    $dialogdef = array('header' => array('type' => F_ALPHANUMERIC, 'name' => 'header', 'minlength' => 0, 'maxlength' => 240, 'columns' => 30, 'label' => t('header_label', 'm_crew'), 'title' => t('header_title', 'm_crew'), 'viewonly' => $viewonly, 'value' => '', 'old_value' => ''), 'introduction' => array('type' => F_ALPHANUMERIC, 'name' => 'introduction', 'minlength' => 0, 'maxlength' => 32768, 'columns' => 50, 'rows' => 10, 'label' => t('introduction_label', 'm_crew'), 'title' => t('introduction_title', 'm_crew'), 'viewonly' => $viewonly, 'value' => '', 'old_value' => ''), 'visibility' => array('type' => F_RADIO, 'name' => 'visibility', 'value' => 0, 'old_value' => 0, 'options' => $visibilities, 'viewonly' => $viewonly, 'title' => t('visibility_title', 'm_crew'), 'label' => t('visibility_label', 'm_crew')));
    $table = 'workshops';
    $fields = array('header', 'introduction', 'visibility');
    $where = array('node_id' => intval($node_id));
    if (($record = db_select_single_record($table, $fields, $where)) === FALSE) {
        logger(sprintf('%s(): error retrieving CREW configuration: %s', __FUNCTION__, db_errormessage()));
        $output->add_message(t('error_retrieving_data', 'admin'));
    } else {
        foreach ($record as $name => $value) {
            $dialogdef[$name]['value'] = $dialogdef[$name]['old_value'] = $value;
        }
    }
    $sql = sprintf('DROP TEMPORARY TABLE IF EXISTS %screw_tmp', $DB->prefix);
    $retval = $DB->exec($sql);
    if ($USER->has_job_permissions(JOB_PERMISSION_ACCOUNTMANAGER)) {
        // Allow $USER to set/edit any user's permission because she is already able
        // to manipulate useraccounts, _all_ useraccounts. We are sure that $USER is a
        // valid user with at least JOB_PERMISSION_STARTCENTER or else we would not be here.
        $sql = sprintf('CREATE TEMPORARY TABLE %screw_tmp ' . 'SELECT u.acl_id, u.username, u.full_name, amn.permissions_modules ' . 'FROM %susers u ' . 'LEFT JOIN %sacls_modules_nodes amn ' . 'ON amn.acl_id = u.acl_id AND amn.module_id = %d AND amn.node_id = %d ' . 'ORDER BY u.full_name', $DB->prefix, $DB->prefix, $DB->prefix, $module_id, $node_id);
    } else {
        // Only allow $USER to set permissions for all her acquaintances, ie. all users
        // that are members of the group(s) that $USER is a also member of.
        $sql = sprintf('CREATE TEMPORARY TABLE %screw_tmp ' . 'SELECT DISTINCT u.acl_id, u.username, u.full_name, amn.permissions_modules ' . 'FROM %susers u ' . 'INNER JOIN %susers_groups_capacities ugc1 USING(user_id) ' . 'INNER JOIN %susers_groups_capacities ugc2 USING(group_id) ' . 'LEFT JOIN %sacls_modules_nodes amn ' . 'ON amn.acl_id = u.acl_id AND amn.module_id = %d AND amn.node_id = %d ' . 'WHERE ugc2.user_id = %d ' . 'ORDER BY u.full_name', $DB->prefix, $DB->prefix, $DB->prefix, $DB->prefix, $DB->prefix, $module_id, $node_id, $user_id);
    }
    $retval = $DB->exec($sql);
    // at this point we have a temporary table with all 'editable' accounts
    // we first add those to the dialogdef.
    $table = 'crew_tmp';
    $fields = '*';
    $where = '';
    $order = array('full_name', 'username');
    if (($records = db_select_all_records($table, $fields, $where, $order)) === FALSE) {
        logger(sprintf('%s(): error retrieving elegible CREW-members: %s', __FUNCTION__, db_errormessage()));
        $output->add_message(t('error_retrieving_data', 'admin'));
    } else {
        foreach ($records as $record) {
            $acl_id = intval($record['acl_id']);
            $name = 'acl_rw_' . $acl_id;
            $dialogdef[$name] = array('type' => F_LISTBOX, 'name' => $name, 'value' => is_null($record['permissions_modules']) ? 0 : $record['permissions_modules'], 'old_value' => $record['permissions_modules'], 'acl_id' => $acl_id, 'options' => $roles, 'viewonly' => $viewonly, 'title' => $record['username'], 'label' => $record['full_name']);
        }
    }
    // the next step is to generate a list of any OTHER accounts that happen to have
    // permissions for this module on this node other than ACL_ROLE_NONE.
    // This list consists of a few UNIONs that effectively yields all accounts that
    // somehow have a non-0 permissions_modules, either global (acls), any node for
    // this module (acls_modules), any node within this area (acls_modules_area),
    // any node that is an ancestor of node_id (acls_modules_nodes) OR this specific
    // node for a user that is NOT an acquaintance (ie. who is not in the temp table).
    // Note that we don't check the ancestors (parents) when node happens to be at
    // the top level within the area, ie. when parent is 0. We also peek inside
    // 'acls_areas' and 'acls_nodes'. Pfew, complicated...
    // All these OTHER accounts cannot be manipulated by $USER because all accounts
    // would then be in the temp table, so there.
    // Since there may be more records for the same user (or rather acl_id), we need
    // to drill down the results. As all permissions are additive we can simply OR
    // these together per acl_id/user which yields a single combined role for that user.
    $tree = tree_build($area_id);
    $ancestors = array();
    for ($next_id = $tree[$node_id]['parent_id']; $next_id; $next_id = $tree[$next_id]['parent_id']) {
        $ancestors[] = $next_id;
    }
    unset($tree);
    $sql = empty($ancestors) ? '' : sprintf('SELECT u.acl_id, u.username, u.full_name, amn.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_modules_nodes amn USING (acl_id) ' . 'WHERE amn.permissions_modules <> 0 AND amn.module_id = %d AND amn.node_id IN (%s)', $DB->prefix, $DB->prefix, $module_id, join(',', $ancestors)) . ' UNION ' . sprintf('SELECT u.acl_id, u.username, u.full_name, an.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_nodes an USING (acl_id) ' . 'WHERE an.permissions_modules <> 0 AND an.node_id IN (%s)', $DB->prefix, $DB->prefix, join(',', $ancestors)) . ' UNION ';
    $sql .= sprintf('SELECT u.acl_id, u.username, u.full_name, a.permissions_modules ' . 'FROM %susers u INNER JOIN %sacls a USING (acl_id) ' . 'WHERE a.permissions_modules <> 0', $DB->prefix, $DB->prefix) . ' UNION ' . sprintf('SELECT u.acl_id, u.username, u.full_name, am.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_modules am USING (acl_id) ' . 'WHERE am.permissions_modules <> 0 AND am.module_id = %d', $DB->prefix, $DB->prefix, $module_id) . ' UNION ' . sprintf('SELECT u.acl_id, u.username, u.full_name, aa.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_areas aa USING (acl_id) ' . 'WHERE aa.permissions_modules <> 0 AND aa.area_id = %d', $DB->prefix, $DB->prefix, $area_id) . ' UNION ' . sprintf('SELECT u.acl_id, u.username, u.full_name, ama.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_modules_areas ama USING (acl_id) ' . 'WHERE ama.permissions_modules <> 0 AND ama.module_id = %d AND ama.area_id = %d', $DB->prefix, $DB->prefix, $module_id, $area_id) . ' UNION ' . sprintf('SELECT u.acl_id, u.username, u.full_name, an.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_nodes an USING (acl_id) ' . 'WHERE an.permissions_modules <> 0 AND an.node_id = %d', $DB->prefix, $DB->prefix, $node_id) . ' UNION ' . sprintf('SELECT u.acl_id, u.username, u.full_name, amn.permissions_modules  ' . 'FROM %susers u INNER JOIN %sacls_modules_nodes amn USING (acl_id) ' . 'LEFT JOIN %screw_tmp tmp USING(acl_id) ' . 'WHERE amn.permissions_modules <> 0 AND amn.module_id = %d AND amn.node_id = %d ' . 'AND tmp.acl_id IS NULL ', $DB->prefix, $DB->prefix, $DB->prefix, $module_id, $node_id) . 'ORDER BY full_name, acl_id';
    if (($result = $DB->query($sql)) === FALSE) {
        logger(sprintf('%s(): error retrieving other account names: %s', __FUNCTION__, db_errormessage()));
        $output->add_message(t('error_retrieving_data', 'admin'));
    } else {
        if ($result->num_rows > 0) {
            $records = array();
            while (($record = $result->fetch_row_assoc()) !== FALSE) {
                $acl_id = intval($record['acl_id']);
                if (isset($records[$acl_id])) {
                    $records[$acl_id]['permissions_modules'] |= intval($record['permissions_modules']);
                } else {
                    $records[$acl_id] = $record;
                }
            }
            $result->close();
            foreach ($records as $acl_id => $record) {
                $name = 'acl_ro_' . $acl_id;
                $dialogdef[$name] = array('type' => F_LISTBOX, 'name' => $name, 'value' => is_null($record['permissions_modules']) ? 0 : $record['permissions_modules'], 'options' => $roles, 'viewonly' => TRUE, 'title' => $record['username'], 'label' => $record['full_name']);
            }
        }
    }
    if (!$viewonly) {
        $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
    }
    $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
    return $dialogdef;
}
 /** construct the translation dialog for selected language and domain
  *
  * this constructs a translation dialog definition, filled with translations
  * for language $language_key and domain $full_domain. The labels for the fields
  * are derived from the English texts in $full_domain, in the order specified by
  * the English file. If the English file contains comments, these are added to
  * the item too (to be displayed as additional information for the translator).
  * The current translation of the $full_domain is retrieved the usual way, via
  * function t() (shorthand for $LANGUAGE->get_phrase()) but without translating
  * any variables (e.g. {VALUE}).
  * Note that if a translation of a phrase does not exist in the target language,
  * the get_phrase() routine will eventually yield the English translation (after
  * trying the language parents first). Also note that the translated phrases
  * could be retrieved from a user file (ie. a file from 
  * $CFG->datadir/languages/$language_key/$full_domain).
  *
  * @param string $language_key identifies the language to edit
  * @param string $full_domain identifies the language domain
  * @return array contains the dialog definition
  * @uses $USER
  * @uses $CFG
  * @todo try to figure this out: when the delimiter in $name was a dot '.' $_POST contained a '_' instead. WTF?
  *       (it seems that a colon works... for now)
  */
 function get_dialogdef_language_domain($language_key = '', $full_domain = '')
 {
     global $USER, $CFG;
     // 1 -- get the source language English ('en') (both strings and comments)
     $dialogdef = array();
     $strings = array();
     $comments = array();
     $this->get_strings_system('en', $full_domain, $strings, $comments);
     // 2 -- get the existing translation (if any) via the regular translation routine t() and make dialogdef.
     $i = 0;
     foreach ($strings as $k => $v) {
         $name = $full_domain . ':' . $k;
         // weird: when this delimiter was a dot '.' $_POST contained a '_' instead. WTF?
         $dialogdef[$name] = array('type' => F_ALPHANUMERIC, 'name' => $name, 'key' => $k, 'minlength' => 0, 'maxlength' => 65432, 'columns' => 70, 'rows' => $this->guess_row_count($v), 'label' => sprintf("<strong>%d</strong>: %s", ++$i, $this->code_highlight($v)), 'title' => $k, 'value' => t($k, $full_domain, '', '', $language_key), 'comment' => isset($comments[$k]) ? nl2br(htmlspecialchars($comments[$k])) : '');
     }
     // 3 -- add fields for storing metainformation about this translation file
     $submit = '1';
     $full_name = $USER->full_name;
     $email = $USER->email;
     $notes = '';
     $filename = sprintf('%s/languages/%s/%s.php', $CFG->datadir, $language_key, $full_domain);
     if (db_bool_is(TRUE, $this->languages[$language_key]['dialect_in_database']) || db_bool_is(TRUE, $this->languages[$language_key]['dialect_in_file']) && file_exists($filename)) {
         $full_name = t('_full_name', $full_domain, '', '', $language_key);
         $email = t('_email', $full_domain, '', '', $language_key);
         $notes = t('_notes', $full_domain, '', '', $language_key);
     }
     $dialogdef['_submit'] = array('type' => F_CHECKBOX, 'name' => '_submit', 'options' => array(1 => t('translatetool_submit_check', 'admin')), 'title' => t('translatetool_submit_title', 'admin'), 'comment' => t('translatetool_submit_label', 'admin'), 'value' => $submit);
     $dialogdef['_full_name'] = array('type' => F_ALPHANUMERIC, 'name' => '_full_name', 'minlength' => 1, 'maxlength' => 255, 'columns' => 70, 'label' => t('translatetool_full_name_label', 'admin'), 'title' => t('translatetool_full_name_title', 'admin'), 'value' => $full_name);
     $dialogdef['_email'] = array('type' => F_ALPHANUMERIC, 'name' => '_email', 'minlength' => 0, 'maxlength' => 255, 'columns' => 70, 'label' => t('translatetool_email_label', 'admin'), 'title' => t('translatetool_email_title', 'admin'), 'value' => $email);
     $dialogdef['_notes'] = array('type' => F_ALPHANUMERIC, 'name' => '_notes', 'minlength' => 0, 'maxlength' => 65432, 'columns' => 70, 'rows' => 10, 'label' => t('translatetool_notes_label', 'admin'), 'title' => t('translatetool_notes_title', 'admin'), 'value' => $notes);
     // 4 -- always finish with submit buttons
     $dialogdef['button_save'] = dialog_buttondef(BUTTON_SAVE);
     $dialogdef['button_cancel'] = dialog_buttondef(BUTTON_CANCEL);
     return $dialogdef;
 }