aboutsummaryrefslogtreecommitdiff
path: root/views/default
diff options
context:
space:
mode:
authorcash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-08-21 20:51:26 +0000
committercash <cash@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-08-21 20:51:26 +0000
commit64aafb5ca73d329663a93f80ac9cf3e68a082866 (patch)
treef6462c3112d26aea2ad09cdb76b38abb74183757 /views/default
parentc3cbea030adb2201e29897915bfae19f1628c967 (diff)
downloadelgg-64aafb5ca73d329663a93f80ac9cf3e68a082866.tar.gz
elgg-64aafb5ca73d329663a93f80ac9cf3e68a082866.tar.bz2
Merged r6534-6559 from 1.7 branch to trunk
git-svn-id: http://code.elgg.org/elgg/trunk@6840 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'views/default')
-rw-r--r--views/default/friends/picker.php8
-rw-r--r--views/default/input/checkboxes.php109
2 files changed, 85 insertions, 32 deletions
diff --git a/views/default/friends/picker.php b/views/default/friends/picker.php
index 4b8d10111..7b47ed675 100644
--- a/views/default/friends/picker.php
+++ b/views/default/friends/picker.php
@@ -83,6 +83,14 @@ if (is_array($vars['entities']) && sizeof($vars['entities'])) {
}
}
+// sort users in letters alphabetically
+foreach ($users as $letter => $letter_users) {
+ usort($letter_users, create_function('$a, $b', '
+ return strcasecmp($a->name, $b->name);
+ '));
+ $users[$letter] = $letter_users;
+}
+
if (!$callback) {
?>
diff --git a/views/default/input/checkboxes.php b/views/default/input/checkboxes.php
index fa7c0c34c..088a97709 100644
--- a/views/default/input/checkboxes.php
+++ b/views/default/input/checkboxes.php
@@ -2,52 +2,97 @@
/**
* Elgg checkbox input
* Displays a checkbox input field
+ * NB: This also includes a hidden input with the same name as the checkboxes
+ * to make sure something is sent to the server. The default value is 0.
+ * If using JS, be specific to avoid selecting the hidden default value:
+ * $('input[type=checkbox][name=internalname])
*
* @package Elgg
* @subpackage Core
* @author Curverider Ltd
* @link http://elgg.org/
*
- * @uses $vars['value'] The current value, if any
- * @uses $vars['js'] Any Javascript to enter into the input tag
- * @uses $vars['internalname'] The name of the input field
- * @uses $vars['options'] An array of strings representing the label => options for the checkbox field
+ * @uses string $vars['internalname'] The name of the input fields (Forced to an array by appending [])
+ * @uses array $vars['options'] An array of strings representing the label => option for the each checkbox field
+ * @uses string $vars['internalid'] The id for each input field. Optional (Only use this with a single value.)
+ * @uses string $vars['default'] The default value to send if nothing is checked. Optional, defaults to 0.
+ * @uses bool $vars['disabled'] Make all input elements disabled. Optional.
+ * @uses string $vars['value'] The current value. Optional.
+ * @uses string $vars['class'] The class of each input element. Optional.
+ * @uses string $vars['js'] Any Javascript to enter into the input tag. Optional.
*
*/
-$class = $vars['class'];
-if (!$class) {
- $class = "input_checkboxes";
+if (!isset($vars['value']) || $vars['value'] === FALSE) {
+ $vars['value'] = elgg_get_sticky_value($vars['internalname']);
}
-if (!isset($vars['value']) || $vars['value'] === FALSE) {
- $vars['value'] = elgg_get_sticky_value($vars['internalname']);
-}
+$class = (isset($vars['class'])) ? $vars['class'] : 'input_checkboxes';
+$value = (isset($vars['value'])) ? $vars['value'] : NULL;
+$value_array = (is_array($value)) ? array_map('strtolower', $value) : array(strtolower($value));
+$internalname = (isset($vars['internalname'])) ? $vars['internalname'] : '';
+$options = (isset($vars['options']) && is_array($vars['options'])) ? $vars['options'] : array();
+$default = (isset($vars['default'])) ? $vars['default'] : 0;
-foreach($vars['options'] as $label => $option) {
- //if (!in_array($option,$vars['value'])) {
- if (is_array($vars['value'])) {
- $valarray = $vars['value'];
- $valarray = array_map('strtolower', $valarray);
- if (!in_array(strtolower($option),$valarray)) {
- $selected = "";
- } else {
- $selected = "checked = \"checked\"";
+$id = (isset($vars['internalid'])) ? $vars['internalid'] : '';
+$disabled = (isset($vars['disabled'])) ? $vars['disabled'] : FALSE;
+$js = (isset($vars['js'])) ? $vars['js'] : '';
+
+if ($options) {
+ // include a default value so if nothing is checked 0 will be passed.
+ if ($internalname) {
+ echo "<input type=\"hidden\" name=\"$internalname\" value=\"$default\">";
+ }
+
+ foreach($options as $label => $option) {
+ // @hack - This sorta checks if options is not an assoc array and then
+ // ignores the label (because it's just the index) and sets the value ($option)
+ // as the label.
+ // Wow.
+ $labelint = (int) $label;
+
+ if ("{$label}" == "{$labelint}") {
+ $label = $option;
}
- } else {
- if (strtolower($option) != strtolower($vars['value'])) {
- $selected = "";
+
+ if (!in_array(strtolower($option), $value_array)) {
+ $selected = FALSE;
} else {
- $selected = "checked = \"checked\"";
+ $selected = TRUE;
+ }
+
+ $attr = array(
+ 'type="checkbox"',
+ 'value="' . htmlentities($option, ENT_QUOTES, 'UTF-8') . '"'
+ );
+
+ if ($id) {
+ $attr[] = "id=\"$id\"";
}
- }
- $labelint = (int) $label;
- if ("{$label}" == "{$labelint}") {
- $label = $option;
- }
- if (isset($vars['internalid'])) $id = "id=\"{$vars['internalid']}\"";
- $disabled = "";
- if ($vars['disabled']) $disabled = ' disabled="yes" ';
- echo "<label><input type=\"checkbox\" $id $disabled {$vars['js']} name=\"{$vars['internalname']}[]\" value=\"".htmlentities($option, ENT_QUOTES, 'UTF-8')."\" {$selected} class=\"$class\" />{$label}</label><br />";
+ if ($class) {
+ $attr[] = "class=\"$class\"";
+ }
+
+ if ($disabled) {
+ $attr[] = 'disabled="yes"';
+ }
+
+ if ($selected) {
+ $attr[] = 'checked = "checked"';
+ }
+
+ if ($js) {
+ $attr[] = $js;
+ }
+
+ if ($internalname) {
+ // @todo this really, really should only add the []s if there are > 1 element in options.
+ $attr[] = "name=\"{$internalname}[]\"";
+ }
+
+ $attr_str = implode(' ', $attr);
+
+ echo "<label><input $attr_str />$label</label><br />";
+ }
} \ No newline at end of file