function avatar_selection_edit_form in Avatar Selection 5.2
Same name and namespace in other branches
- 5 avatar_selection.module \avatar_selection_edit_form()
- 6 avatar_selection.admin.inc \avatar_selection_edit_form()
- 7 avatar_selection.admin.inc \avatar_selection_edit_form()
Create the form structure for listing the avatars and managing them in the 'Manage Avatars' tab under the Avatar Selection administration page.
Parameters
$form_values: Array containing the form values submitted.
Return value
Return the structure of the form.
2 string references to 'avatar_selection_edit_form'
- avatar_selection_roles_page in ./
avatar_selection.module - avatar_selection_settings_page in ./
avatar_selection.module - Select which form will be shown to the user, according to the permissions.
File
- ./
avatar_selection.module, line 720 - The Avatar Selection module allows the user to pick an avatar image from a list already loaded by an administrative user, and to the administrator to disable uploading other avatar files by the user.
Code
function avatar_selection_edit_form($form_values = NULL) {
// We need the pager global variables.
global $_GET;
if (!variable_get('user_pictures', 0)) {
drupal_set_message(t('User Pictures option is disabled. You will need to enable this option before you can use the Avatar Selection module. You may configure this setting on the <a href="@url">User settings</a> page.', array(
'@url' => url('admin/user/settings'),
)));
}
drupal_add_css(drupal_get_path('module', 'avatar_selection') . '/avatar_selection.css');
$set_type = arg(4);
$set_id = arg(5);
// We find out the current page number.
$page = 0;
if (isset($_GET['page']) && is_numeric($_GET['page'])) {
$page = $_GET['page'];
}
$avatars_per_page = variable_get('avatar_selection_avatar_per_page', 30);
$selects = _avatar_selection_image_list("", $set_type, $set_id, $page * $avatars_per_page, $avatars_per_page);
if (!count($selects['avatars'])) {
drupal_set_message(t('There are no avatars configured.'));
}
else {
if (!isset($form_values)) {
$step = "list";
}
else {
$step = "edit";
}
$form['step'] = array(
'#type' => 'value',
'#value' => $step,
);
$form['#multistep'] = TRUE;
if ($step == "list") {
$form['#redirect'] = FALSE;
if ($set_type == 'role') {
$sets = avatar_selection_handler_filter_role();
$set_name = $sets[$set_id];
if ($set_id == 0) {
$set_name = 'All roles';
}
$form['title'] = array(
'#value' => '<strong>' . t('Role: %name', array(
'%name' => $set_name,
)) . '</strong>',
);
}
elseif ($set_type == 'og') {
$sets = og_all_groups_options();
$set_name = $sets[$set_id];
if ($set_id == 0) {
$set_name = 'All groups';
}
$form['title'] = array(
'#value' => '<strong>' . t('Organic Group: %name', array(
'%name' => $set_name,
)) . '</strong>',
);
}
drupal_add_js(drupal_get_path('module', 'avatar_selection') . '/js/avatar_selection_pager.js', 'module', 'header');
$js_file = drupal_get_path('module', 'avatar_selection') . '/js/avatar_selection.js';
$form['select_avatar'] = array(
'#type' => 'radios',
'#title' => t('Select an avatar to edit'),
'#options' => $selects['avatars'],
'#required' => TRUE,
'#attributes' => array(
'class' => 'user-avatar-select',
),
'#suffix' => theme('avatar_selection_pager', 'form#avatar-selection-edit-form', 'div.user-avatar-select', $selects['total'], $avatars_per_page, '/' . $js_file),
);
$form['search'] = array(
'#type' => 'submit',
'#value' => t('Edit'),
);
drupal_add_js($js_file, 'module', 'header');
}
elseif ($step == "edit") {
$form['#redirect'] = array(
'admin/settings/avatar_selection/edit',
);
$roles = avatar_selection_handler_filter_role();
$aid = 0;
$weight = 0;
$name = "";
$avs_access = array();
$og_access = array();
$result = db_query("SELECT avs.aid, avatar, name, weight, rid, ogid FROM {avatar_selection} avs LEFT JOIN {avatar_selection_roles} avsr ON avs.aid = avsr.aid LEFT JOIN {avatar_selection_og} avso ON avs.aid = avso.aid WHERE avatar = '%s' ORDER BY weight, name, avatar", $form_values['select_avatar']);
while ($avatar = db_fetch_object($result)) {
$aid = $avatar->aid;
$name = $avatar->name;
$weight = $avatar->weight;
if ($avatar->rid) {
array_push($avs_access, $avatar->rid);
}
if ($avatar->ogid) {
array_push($og_access, $avatar->ogid);
}
}
$image_path = file_create_path('avatar_selection');
$selected_avatar = $form_values['select_avatar'];
$image = theme('image', $image_path . '/' . $selected_avatar);
$form['avatar_image'] = array(
'#value' => $image,
);
$form['aid'] = array(
'#type' => 'value',
'#value' => $aid,
);
$form['select_avatar'] = array(
'#type' => 'value',
'#value' => $form_values['select_avatar'],
);
$form['avatar_name'] = array(
'#type' => 'textfield',
'#title' => t('Name'),
'#description' => t("Image name or title which will be displayed when hovering over the image. It's also used in conjunction with the weight setting for sorting the avatars."),
'#size' => 48,
'#default_value' => $name,
);
$form['avatar_weight'] = array(
'#type' => 'weight',
'#title' => t('Weight'),
'#delta' => 100,
'#description' => t('Avatars with a lower weight appear before higher weighted avatars in lists.'),
'#default_value' => $weight,
);
$form['permissions'] = array(
'#type' => 'fieldset',
'#title' => t('Permissions'),
'#weight' => 1,
);
$form['permissions']['access'] = array(
'#type' => 'checkboxes',
'#title' => t('User Roles'),
'#default_value' => $avs_access,
'#options' => $roles,
'#description' => t('Only the checked roles will be able to see this avatar icon; if no roles are checked, access will not be restricted.'),
);
if (module_exists("og")) {
$form['permissions']['og_access'] = array(
'#type' => 'checkboxes',
'#title' => t('Organic Groups'),
'#default_value' => $og_access,
'#options' => og_all_groups_options(),
'#description' => t('Only users in the checked organic groups will be able to see this avatar icon; if no groups are checked, access will not be restricted.'),
);
}
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 9,
);
$form['delete'] = array(
'#type' => 'submit',
'#value' => t('Delete'),
'#weight' => 10,
);
}
}
return $form;
}