public static function dropdown($data, $selected = NULL, $extra = '') { // standardize the $data as an array, strings default to the class_type if (!is_array($data)) { $data = array('name' => $data); } // add in all the defaults if they are not provided $data += array('nullOption' => 'Account Default'); $data = arr::update($data, 'class', ' callid_dropdown'); // see if the module wants to allow null selections if (!empty($data['nullOption'])) { $options = array('0' => $data['nullOption']); } else { $options = array(); } unset($data['nullOption']); // build an array of netlists sutable for the dropdown helper $numbers = Doctrine_Query::create()->from('Number n')->Where('LENGTH(n.number) >= 10 ')->execute(array(), Doctrine::HYDRATE_ARRAY); foreach ($numbers as $number) { $matches = array(); preg_match('/^\\+?1?([2-9][0-8][0-9])([2-9][0-9][0-9])([0-9]{4})$/', $number['number'], $matches); if (count($matches) == 4) { $options[$number['number_id']] = '( ' . $matches[1] . ' ) ' . $matches[2] . ' - ' . $matches[3]; } else { $options[$number['number_id']] = $number['number']; } } return form::dropdown($data, $options, $selected, $extra); }
public static function dropdownUserType($data, $selected = NULL, $extra = '') { // standardize the $data as an array, strings default to the class_type if (!is_array($data)) { $data = array('name' => $data); } // add in all the defaults if they are not provided $data += array('nullOption' => FALSE); // append or insert the class $data = arr::update($data, 'class', 'user_type_dropdown'); // render a null option if its been set in data if (!empty($data['nullOption'])) { $options = array(0 => $data['nullOption']); } else { $options = array(); } unset($data['nullOption']); $userTypes = self::getUserTypes(); foreach ($userTypes as $userType => $displayName) { if ($userType <= users::getAttr('user_type')) { $options[$userType] = $displayName; } } // use kohana helper to generate the markup return form::dropdown($data, $options, $selected, $extra); }
public static function dropdownCIDFormat($data, $selected = NULL, $extra = '') { // standardize the $data as an array, strings default to the class_type if (!is_array($data)) { $data = array('name' => $data); } // add in all the defaults if they are not provided $data += array('nullOption' => FALSE); // append or insert the class $data = arr::update($data, 'class', ' sip_invite_format_dropdown'); // render a null option if its been set in data if (!empty($data['nullOption'])) { $options = array(0 => $data['nullOption']); } else { $options = array(); } unset($data['nullOption']); $options = Sip_Plugin::getCIDFormats(); // use kohana helper to generate the markup return form::dropdown($data, $options, $selected, $extra); }
public static function dropdown($data, $selected = NULL, $extra = '', $nullOption = 'None') { // standardize the $data as an array, strings default to the class_type if (!is_array($data)) { $data = array('name' => $data); } // add in all the defaults if they are not provided $data += array('nullOption' => 'None'); arr::update($data, 'class', ' voicemail_dropdown'); // see if the module wants to allow null selections if (!empty($data['nullOption'])) { $options = array('0' => __($data['nullOption'])); } else { $options = array(); } unset($data['nullOption']); $voicemails = Doctrine::getTable('Voicemail')->findAll(Doctrine::HYDRATE_ARRAY); foreach ($voicemails as $voicemail) { $options[$voicemail['voicemail_id']] = $voicemail['name']; } return form::dropdown($data, $options, $selected, $extra); }
public static function nextAvaliableLink($bindTo, $title = NULL, $attributes = array(), $javascript = TRUE) { if (empty($bindTo)) { return FALSE; } // standardize the $data as an array, strings default to the class_type if (!is_array($attributes)) { $attributes = array('id' => $attributes); } // add in all the defaults if they are not provided $attributes += array('id' => 'next' . $bindTo . 'Link', 'translate' => TRUE, 'jgrowl' => TRUE); // ensure we have our distint class $attributes = arr::update($attributes, 'class', ' nxt_aval_link'); // if there is no title then use the default if (empty($title)) { $title = 'Next Avaliable Number'; } // unless instructed otherwise translate this title if ($attributes['translate']) { $title = __($title); } // if the user is not going to roll their own js do it for them if ($javascript) { // if the user wants to use jgrowl make sure it will be avaliable if ($attributes['jgrowl']) { jquery::addPlugin('growl'); } // generate a js script to select the next avaliable number $script = ' $("#' . $attributes['id'] . '").bind("click", function(e) { e.preventDefault(); numberDrop = $("#' . $bindTo . '"); selected = []; $(numberDrop).find("option:selected").each( function() { selected[selected.length] = $(this).text(); }); success = false; $(numberDrop).find("option").each(function () { text = $(this).text(); if (jQuery.inArray(text, selected) == -1) { $(this).attr("selected", "selected"); $(numberDrop).trigger("change"); '; // if the user wants to use jgrowl add it to our js script if ($attributes['jgrowl']) { $script .= '$.jGrowl("' . __('Assigned number') . ' " + text, { theme: "success", life: 5000 }); '; } $script .= 'success = true; return false; } }); '; // if the user wants to use jgrowl add it to our js script if ($attributes['jgrowl']) { $script .= 'if (!success) $.jGrowl("' . __('Unable to find an avaliable number!') . '", { theme: "error", life: 5000 });'; } $script .= "\n" . ' });' . "\n"; // put our script in the render stream javascript::codeBlock($script); } // dont inlcude the tranlaste in the html attributes unset($attributes['translate'], $attributes['jgrowl']); // Parsed URL return '<a href="#" ' . html::attributes($attributes) . '><span>' . $title . '</span></a>'; }
protected static function _addDefaults() { $args = func_get_args(); $formElement = array_shift($args); // create a string of all default classes, with special cases if ($formElement == 'open_fieldset') { $defaultClasses = "fieldset"; } else { $defaultClasses = "{$formElement}"; } // all skins and other things to append custom classes if (array_key_exists($formElement, self::$customClasses)) { $custom = (array) self::$customClasses[$formElement]; $defaultClasses .= ' ' . implode(' ', $custom); } else { if (array_key_exists('all', self::$customClasses)) { $custom = (array) self::$customClasses['all']; $defaultClasses .= ' ' . implode(' ', $custom); } } $defaultClasses = ' ' . strtolower($defaultClasses); // run the appopriate logic based on the form element switch ($formElement) { case 'open': case 'open_multipart': // create pointers to the parameters $action =& $args[0]; $attr =& $args[1]; $hidden =& $args[2]; // if attr is not an array then make it one! if (!is_array($attr) || empty($attr)) { // this may confuse people who are loosing the stuff so log if (is_string($attr)) { kohana::log('error', 'The second argument to form::' . $formElement . ' must be an array! OVERWRITING!'); } $attr = array(); } if (empty($attr['id'])) { $attr['id'] = trim(preg_replace('/[^a-zA-Z_{}]+/imx', '_', url::current()), '_'); } // set a default hidden field with the forms name if (!is_array($hidden)) { $hidden = array(); } $hidden += array('bluebox_form_name' => $attr['id']); // special cases for the forms if ($formElement == 'open') { $defaultClasses = " form"; } else { if ($formElement == 'open_multipart') { $defaultClasses = " form multipart"; } } // Append the classes $attr = arr::update($attr, 'class', $defaultClasses); break; case 'close': // create pointers to the parameters $extra =& $args[0]; break; case 'label': // create pointers to the parameters $data =& $args[0]; $text =& $args[1]; $extra =& $args[2]; // standardize the $data var if (!is_array($data)) { if (is_string($data)) { // Specify the input this label is for $data = array('for' => $data); } else { // No input specified $data = array(); } } if (!isset($data['for'])) { break; } // If the element does not have an id then generate one for it if (!empty($data['for']) && empty($data['id'])) { $data['id'] = 'label_' . trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['for']), '_'); } // If the element this label belongs to has an error append a // has_error class to it if (!empty($data['for']) && self::_getError($data['for'])) { $defaultClasses .= ' has_error'; } $text = self::_i18n($text); // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; case 'legend': // create pointers to the parameters $text =& $args[0]; $data =& $args[1]; $extra =& $args[2]; // standardize the $data var $data = (array) $data; // if we have enough info to make an id and there is none do so if (!empty($text) && empty($data['id'])) { $data['id'] = 'legend_' . trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', strtolower($text)), '_'); } $text = self::_i18n($text); // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; case 'open_fieldset': // create pointers to the parameters $data =& $args[0]; $extra =& $args[1]; // standardize the $data var $data = (array) $data; // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; case 'close_fieldset': break; case 'hidden': // create pointers to the parameters $name =& $args[0]; $value =& $args[1]; // check if we should attempt to fill the value $value = self::_attemptRePopulate($name, $value); // hidden fields dont have classes coming in, but expect them array_push($args, $defaultClasses); break; case 'input': case 'password': case 'upload': case 'textarea': // create pointers to the parameters $data =& $args[0]; $value =& $args[1]; $extra =& $args[2]; // standardize the $data var if (!is_array($data)) { $data = array('name' => $data); } if (!isset($data['name'])) { break; } // If the element does not have an id then generate one for it if (empty($data['id'])) { $data['id'] = $data['name']; } $data['id'] = trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['id']), '_'); if ($formElement != 'button' && $formElement != 'submit') { // check if we should attempt to fill the value $value = self::_attemptRePopulate($data['name'], $value); // If this field has an error append the has_error class... if (self::_getError($data['name'])) { $defaultClasses .= ' has_error'; } } if ($formElement == 'textarea') { if (empty($data['rows'])) { $data['rows'] = '2'; } if (empty($data['cols'])) { $data['cols'] = '20'; } } // Some elements reuses form::input(), so dont re-append a new set of classes if (!empty($data['class']) && strstr($data['class'], $defaultClasses)) { break; } // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; case 'submit': case 'button': // create pointers to the parameters $data =& $args[0]; $value =& $args[1]; $extra =& $args[2]; // standardize the $data var if (!is_array($data)) { $data = array('name' => $data); } if (!isset($data['name'])) { break; } // If the element does not have an id then generate one for it if (empty($data['id'])) { $data['id'] = $data['name'] . '_' . $value; } $data['id'] = trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['id']), '_'); if ($formElement == 'button' && empty($data['value'])) { $data['value'] = strtolower($value); } if ($formElement == 'button' || $formElement == 'submit') { $value = self::_i18n($value); } // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; case 'dropdown': case 'dualListBox': // create pointers to the parameters $data =& $args[0]; $options =& $args[1]; $selected =& $args[2]; $extra =& $args[3]; // standardize the $data var if (!is_array($data)) { $data = array('name' => $data); } if (!isset($data['name'])) { break; } // check if we should attempt to fill the selected $selected = self::_attemptRePopulate($data['name'], $selected); // If the element does not have an id then generate one for it if (empty($data['id'])) { $data['id'] = $data['name']; } $data['id'] = trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['id']), '_'); // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; // data, value, checked, extra // data, value, checked, extra case 'checkbox': // create pointers to the parameters $data =& $args[0]; $value =& $args[1]; $checked =& $args[2]; $extra =& $args[3]; // if there is no default value then use bool true if (is_null($value)) { $value = TRUE; } // standardize the $data var if (!is_array($data)) { $data = array('name' => $data); } if (!isset($data['name'])) { break; } // check if we should attempt to fill checked $checked = self::_attemptRePopulate($data['name'], $checked, $value); // see if we have a unchecked value or can quess it if (!isset($data['unchecked'])) { if (is_bool($value)) { if ($value) { $data['unchecked'] = 0; } else { $data['unchecked'] = 1; } } else { $data['unchecked'] = 0; } } // If the element does not have an id then generate one for it if (empty($data['id'])) { $data['id'] = $data['name']; } $data['id'] = trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['id']), '_'); // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; case 'radio': // create pointers to the parameters $data =& $args[0]; $value =& $args[1]; $checked =& $args[2]; $extra =& $args[3]; // standardize the $data var if (!is_array($data)) { $data = array('name' => $data); } if (!isset($data['name'])) { break; } if (is_null($checked)) { // check if we should attempt to fill checked $repopulate = self::_attemptRePopulate($data['name'], $checked, $value); $checked = FALSE; if ($repopulate == $value) { $checked = TRUE; } } // If the element does not have an id then generate one for it if (empty($data['id'])) { $data['id'] = $data['name']; } $data['id'] = trim(preg_replace('/[^a-zA-Z0-9_{}]+/imx', '_', $data['id']), '_'); // Append the classes $data = arr::update($data, 'class', $defaultClasses); break; } return $args; }
/** * Render a dropdown of users * * Additional Data Options: * nullOption = If this is a string then it is used as the '0' option, or * if false then no such option will exist * * @param string|array input name or an array of HTML attributes * @param string option key that should be selected by default * @param string a string to be attached to the end of the attributes * @return string */ public static function dropdown($data, $selected = NULL, $extra = '') { $users = Doctrine::getTable('User')->findAll(Doctrine::HYDRATE_ARRAY); // standardize the $data as an array, strings default to the class_type if (!is_array($data)) { $data = array('name' => $data); } // add in all the defaults if they are not provided $data += array('nullOption' => FALSE); // see if the module wants to allow null selections if (!empty($data['nullOption'])) { $options = array('0' => $nullOption); } else { $options = array(); } foreach ($users as $user) { $options[$user['user_id']] = $user['first_name'] . ' ' . $user['last_name']; } // set a class name to define the user dropdown $data = arr::update($data, 'class', ' users_dropdown'); // unset any keys that are options for this method unset($data['nullOption']); // Render a dropdown using the form helper return form::dropdown($data, $options, $selected, $extra); }