| 1 |
<?php
|
| 2 |
// $Id: activeselect.module,v 1.8 2006/04/17 07:11:39 jaza Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Defines the activeselect form element, which allows modules to have
|
| 7 |
* AJAX-enabled select boxes.
|
| 8 |
*/
|
| 9 |
|
| 10 |
/**
|
| 11 |
* Implementation of hook_help().
|
| 12 |
*/
|
| 13 |
function activeselect_help($section) {
|
| 14 |
switch ($section) {
|
| 15 |
case 'admin/help#activeselect':
|
| 16 |
return '<p>'. t('The activeselect module defines the activeselect form element. An activeselect element is the same as a regular select element, except that when the user selects a new option (or set of options), a different select element (the target element) gets its list updated. This is done using AJAX, and it is designed to degrade gracefully if the required JavaScript support is not present. The target element can be either a regular select box, or another activeselect box (which in turn can trigger another target box, which can trigger yet another, resulting in a hierarchical cascade of activeselect elements).') .'</p>';
|
| 17 |
}
|
| 18 |
}
|
| 19 |
|
| 20 |
/**
|
| 21 |
* Implementation of hook_elements().
|
| 22 |
*/
|
| 23 |
function activeselect_elements() {
|
| 24 |
$type['activeselect'] = array('#input' => TRUE);
|
| 25 |
|
| 26 |
return $type;
|
| 27 |
}
|
| 28 |
|
| 29 |
/**
|
| 30 |
* Converts the string of values passed to an activeselect callback function
|
| 31 |
* into an array.
|
| 32 |
*
|
| 33 |
* @param $string
|
| 34 |
* The string of values passed to an activeselect callback.
|
| 35 |
*
|
| 36 |
* @return
|
| 37 |
* An array of values, in the form $key => $value.
|
| 38 |
*/
|
| 39 |
function activeselect_explode_values($string) {
|
| 40 |
$array = explode('||', $string);
|
| 41 |
foreach ($array as $key => $value) {
|
| 42 |
$match = explode('|', $value);
|
| 43 |
$array[$match[0]] = html_entity_decode($match[1]);
|
| 44 |
unset($array[$key]);
|
| 45 |
}
|
| 46 |
|
| 47 |
return $array;
|
| 48 |
}
|
| 49 |
|
| 50 |
function activeselect_set_header_nocache() {
|
| 51 |
header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
|
| 52 |
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
|
| 53 |
header("Cache-Control: no-store, no-cache, must-revalidate");
|
| 54 |
header("Cache-Control: post-check=0, pre-check=0", false);
|
| 55 |
header("Pragma: no-cache");
|
| 56 |
}
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Format a dropdown menu or scrolling selection box.
|
| 60 |
*
|
| 61 |
* @param $element
|
| 62 |
* An associative array containing the properties of the element.
|
| 63 |
* Properties used: title, value, options, description, extra, multiple, required
|
| 64 |
* @return
|
| 65 |
* A themed HTML string representing the form element.
|
| 66 |
*
|
| 67 |
* It is possible to group options together; to do this, change the format of
|
| 68 |
* $options to an associative array in which the keys are group labels, and the
|
| 69 |
* values are associative arrays in the normal $options format.
|
| 70 |
*/
|
| 71 |
function theme_activeselect($element) {
|
| 72 |
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : '';
|
| 73 |
$class = array();
|
| 74 |
$extra = '';
|
| 75 |
if ($element['#activeselect_path'] && $element['#activeselect_targets']) {
|
| 76 |
$module_path = drupal_get_path('module', 'activeselect'). '/';
|
| 77 |
drupal_add_css($module_path. 'activeselect.css');
|
| 78 |
drupal_add_js($module_path. 'activeselect.js');
|
| 79 |
$class[] = ' form-activeselect';
|
| 80 |
$extra = '<input class="activeselect-path" type="hidden" id="'. $element['#id'] .'-activeselect-path" value="'. check_url(url($element['#activeselect_path'], NULL, NULL, TRUE)) .'" disabled="disabled" />'. "\n";
|
| 81 |
$targets = explode(',', $element['#activeselect_targets']);
|
| 82 |
foreach ($targets as $key => $target) {
|
| 83 |
$targets[$key] = 'edit-'. check_plain($target);
|
| 84 |
}
|
| 85 |
$extra .= '<input class="activeselect-targets" type="hidden" id="'. $element['#id'] .'-activeselect-targets" value="'. implode(',', $targets) .'" disabled="disabled" />'. "\n";
|
| 86 |
$extra .= '<input class="activeselect-extra" type="hidden" id="'. $element['#id'] .'-activeselect-extra" value="'. check_plain($element['#activeselect_extra']) .'" disabled="disabled" />'. "\n";
|
| 87 |
}
|
| 88 |
_form_set_class($element, $class);
|
| 89 |
|
| 90 |
return theme('form_element', $element, '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size. '>'. form_select_options($element) .'</select>'). $extra;
|
| 91 |
}
|