| 1 |
<?php |
<?php |
| 2 |
// $Id: activeselect.module,v 1.5 2006/03/28 13:23:35 jaza Exp $ |
// $Id: activeselect.module,v 1.6 2006/03/29 12:51:48 jaza Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 29 |
} |
} |
| 30 |
|
|
| 31 |
/** |
/** |
| 32 |
* First step in array serializing, to be called before |
* Converts the string of values passed to an activeselect callback function |
| 33 |
* activeselect_implode_activeselect(). |
* into an array. |
|
*/ |
|
|
function activeselect_implode_array($array) { |
|
|
$output = array(); |
|
|
foreach ($array as $k => $v) { |
|
|
$output[] = str_replace('|', '|', $k) .'|'. $v; |
|
|
} |
|
|
return implode('||', $output); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Implode a PHP array into a string that can be decoded by the activeselect |
|
|
* JS routines. |
|
| 34 |
* |
* |
| 35 |
* Items are separated by quadruple pipes. Each item consists of a key-value |
* @param $string |
| 36 |
* pair separated by triple pipes. Entities are used to ensure pipes in the |
* The string of values passed to an activeselect callback. |
| 37 |
* strings pass unharmed. |
* |
| 38 |
|
* @return |
| 39 |
|
* An array of values, in the form $key => $value. |
| 40 |
*/ |
*/ |
| 41 |
function activeselect_implode_activeselect($array) { |
function activeselect_explode_values($string) { |
| 42 |
$output = array(); |
$array = explode('||', $string); |
| 43 |
foreach ($array as $k => $v) { |
foreach ($array as $key => $value) { |
| 44 |
$output[] = $k .'|||'. $v; |
$match = explode('|', $value); |
| 45 |
|
$array[$match[0]] = html_entity_decode($match[1]); |
| 46 |
|
unset($array[$key]); |
| 47 |
} |
} |
| 48 |
return implode('||||', $output); |
|
| 49 |
|
return $array; |
| 50 |
} |
} |
| 51 |
|
|
| 52 |
function activeselect_set_header_nocache() { |
function activeselect_set_header_nocache() { |
| 72 |
*/ |
*/ |
| 73 |
function theme_activeselect($element) { |
function theme_activeselect($element) { |
| 74 |
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : ''; |
$size = $element['#size'] ? ' size="' . $element['#size'] . '"' : ''; |
| 75 |
$class = ''; |
$class = array(); |
| 76 |
$extra = ''; |
$extra = ''; |
| 77 |
if ($element['#activeselect_path'] && $element['#activeselect_targets']) { |
if ($element['#activeselect_path'] && $element['#activeselect_targets']) { |
| 78 |
$module_path = drupal_get_path('module', 'activeselect'). '/'; |
$module_path = drupal_get_path('module', 'activeselect'). '/'; |
| 79 |
theme('add_style', $module_path. 'activeselect.css'); |
theme('add_style', $module_path. 'activeselect.css'); |
| 80 |
drupal_add_js($module_path. 'activeselect.js'); |
drupal_add_js($module_path. 'activeselect.js'); |
| 81 |
$class = ' form-activeselect'; |
$class[] = ' form-activeselect'; |
| 82 |
$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"; |
$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"; |
| 83 |
$targets = explode(',', $element['#activeselect_targets']); |
$targets = explode(',', $element['#activeselect_targets']); |
| 84 |
foreach ($targets as $key => $target) { |
foreach ($targets as $key => $target) { |
| 87 |
$extra .= '<input class="activeselect-targets" type="hidden" id="'. $element['#id'] .'-activeselect-targets" value="'. implode(',', $targets) .'" disabled="disabled" />'. "\n"; |
$extra .= '<input class="activeselect-targets" type="hidden" id="'. $element['#id'] .'-activeselect-targets" value="'. implode(',', $targets) .'" disabled="disabled" />'. "\n"; |
| 88 |
$extra .= '<input class="activeselect-extra" type="hidden" id="'. $element['#id'] .'-activeselect-extra" value="'. check_plain($element['#activeselect_extra']) .'" disabled="disabled" />'. "\n"; |
$extra .= '<input class="activeselect-extra" type="hidden" id="'. $element['#id'] .'-activeselect-extra" value="'. check_plain($element['#activeselect_extra']) .'" disabled="disabled" />'. "\n"; |
| 89 |
} |
} |
| 90 |
$class = _form_get_class($class, $element['#required'], form_get_error($element)); |
_form_set_class($element, $class); |
| 91 |
|
|
| 92 |
return theme('form_element', $element['#title'], '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size. ($class ? 'class="'. $class. '"' : ''). '>'. form_select_options($element) .'</select>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element)). $extra; |
return theme('form_element', $element['#title'], '<select name="'. $element['#name'] .''. ($element['#multiple'] ? '[]' : '') .'"'. ($element['#multiple'] ? ' multiple="multiple" ' : '') . drupal_attributes($element['#attributes']) .' id="' . $element['#id'] .'" '. $size. '>'. form_select_options($element) .'</select>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element)). $extra; |
| 93 |
} |
} |