/** * Outputs calendar driven field * * @param string $name Name of field * @param null|string $label Label of field * @param boolean $required Is required ? * @param null|string $value Current value * @param boolean $readOnly Read-only field ? * @param boolean $showTime Show time too ? * @param null|int $minYear Minimum year to display * @param null|int $maxYear Maximum year to display * @param null|string $attributes Other HTML attributes * @param boolean $serverTimeOffset False: don't offset, true: offset if time also in $date * @param null|string|int $offsetOverride Offset override for time display * @return string HTML for calendar */ public function cbAddCalendar( $name, $label = null, $required = false, $value = null, $readOnly = false, $showTime = false, $minYear = null, $maxYear = null, $attributes = null, $serverTimeOffset = true, $offsetOverride = null ) { global $_CB_framework; if ( ( ! $value ) || ( $value == '0000-00-00 00:00:00' ) || ( $value == '0000-00-00' ) ) { if ( $showTime ) { $value = '0000-00-00 00:00:00'; } else { $value = '0000-00-00'; } } else { // Something sent an invalid format length; lets pad the date to fix this: if ( strlen( $value ) < 10 ) { if ( strlen( $value ) < 5 ) { // We seam to only have the year; lets give fake month-day: $value = $value . '-01-01'; } else { if ( preg_match( '/\d{4}-\d+/i', $value ) ) { // We seam to have year and month; lets fake day: $value = rtrim( $value, '-' ) . '-01'; } else { // We seam to have month-day: lets fake the year: $value = '1970-' . ltrim( $value, '-' ); } } } // We always expect an SQL formatted date or timestamp; if it's anything otherwise then this function was used wrong: $value = $_CB_framework->getUTCDate( 'Y-m-d' . ( $showTime ? ' H:i:s' : null ), $value ); } if ( ( ! $value ) || ( $value == '0000-00-00 00:00:00' ) || ( $value == '0000-00-00' ) ) { $isEmpty = true; $value = ''; } else { $isEmpty = false; } // Initially set the offset value to the current value and we'll pass it through offset parsing if we need to: $offsetValue = $value; if ( ( $this->calendarType == 2 ) && ( ! $readOnly ) ) { $addPopup = true; } else { $addPopup = false; } $return = null; // When name is missing the bindings break so lets just make one: if ( ! $name ) { $name = uniqid(); } $inputId = moscomprofilerHTML::htmlId( $name ); if ( $readOnly ) { $return = htmlspecialchars( $value ); } else { $attributes .= ' data-cbdatepicker-calendartype="' . (int) $this->calendarType . '"' . ' data-cbdatepicker-target="#' . htmlspecialchars( $inputId ) . '"'; if ( ( $minYear !== null ) && ( $maxYear !== null ) ) { $attributes .= ' data-cbdatepicker-minyear="' . (int) $minYear . '" data-cbdatepicker-maxyear="' . (int) $maxYear . '"'; } if ( $_CB_framework->document->getDirection() == 'rtl' ) { $attributes .= ' data-cbdatepicker-isrtl="true"'; } if ( in_array( $this->calendarType, array( 2, 3 ) ) ) { $tooltipTarget = '#' . htmlspecialchars( $inputId ) . 'Picker + .combodate'; $attributes .= ' data-cbtooltip-open-target="' . $tooltipTarget . '" data-cbtooltip-close-target="' . $tooltipTarget . '" data-cbtooltip-position-target="' . $tooltipTarget . '"' . ' data-cbdatepicker-format="' . htmlspecialchars( $this->dateFormat[2][2] . ( $showTime ? ' ' . $this->timeFormat[2][2] : null ) ) . '"' . ' data-cbdatepicker-template="' . htmlspecialchars( $this->dateFormat[2][1] . ( $showTime ? ' ' . $this->timeFormat[2][1] : null ) ) . '"'; if ( $required && ( ! $isEmpty ) ) { $attributes .= ' data-cbdatepicker-firstitem="none"'; } } if ( ( $this->calendarType == 1 ) || $addPopup ) { $return = ' <span id="' . htmlspecialchars( $inputId ) . 'Calendar" class="hasCalendar fa fa-calendar" title="' . htmlspecialchars( CBTxt::T( 'UE_CALENDAR_TITLE', 'Calendar' ) ) . '"></span>'; if ( $showTime ) { $attributes .= ' data-cbdatepicker-showtime="true" data-cbdatepicker-timeformat="' . htmlspecialchars( $this->timeFormat[1] ) . '"'; } if ( $addPopup ) { $attributes .= ' data-cbdatepicker-addpopup="true"'; } $firstDay = CBTxt::T( 'UE_CALENDAR_FIRSTDAY', '' ); if ( $firstDay != '' ) { $attributes .= ' data-cbdatepicker-firstday="' . (int) CBTxt::T( 'UE_CALENDAR_FIRSTDAY', '' ) . '"'; } $attributes .= ' data-cbdatepicker-dateformat="' . htmlspecialchars( $this->dateFormat[1] ) . '"'; } // If server time offset is enabled then tell jquery the offset in minutes: if ( $showTime && $serverTimeOffset ) { $offset = ( $offsetOverride !== null ? $offsetOverride : $_CB_framework->getCfg( 'offset' ) ); // Ignore offset entirely if there is no offset value: if ( $offset ) { // If the date has a time then offset it and send it to the jquery: if ( ( strlen( $offsetValue ) > 10 ) && $offsetValue ) { $offsetValue = $_CB_framework->getUTCDate( 'Y-m-d H:i:s', $offsetValue, $offset ); } // Pass the UTC offset in minutes for momentjs: $attributes .= ' data-cbdatepicker-offset="' . htmlspecialchars( ( $_CB_framework->getUTCDate( 'Z', null, $offset ) / 60 ) ) . '"'; } } $return = '<input type="hidden" name="' . htmlspecialchars( $name ) . '" id="' . htmlspecialchars( $inputId ) . '" value="' . htmlspecialchars( $value ) . '" />' . '<input type="text" id="' . htmlspecialchars( $inputId ) . 'Picker" value="' . htmlspecialchars( $offsetValue ) . '" class="cbDatePicker form-control' . ( $required ? ' required' : null ) . '"' . ( $readOnly ? ' disabled="disabled"' : null ) . ( $label ? ' title="' . htmlspecialchars( $label ) . '"' : null ) . ( trim( $attributes ) ? ' ' . $attributes : null ) . ' />' . $return; } return $return; }
static function selectList(&$arr, $tag_name, $tag_attribs, $key, $text, $selected, $required = 0, $htmlspecialcharText = true, $addBlank = null) { reset($arr); $id_name = moscomprofilerHTML::htmlId($tag_name); $html = "\n" . '<select name="' . htmlspecialchars($tag_name) . '" id="' . htmlspecialchars($id_name) . '" ' . $tag_attribs . '>'; if ($addBlank === null) { $addBlank = (!$required || (is_array($selected) ? count($selected) == 0 : $selected == '')) && !(isset($arr[0]) && $arr[0]->{$key} == ''); } if ($addBlank) { $html .= "\n\t<option value=\"\"> </option>"; } foreach ($arr as $option) { $t = $option->{$text}; $id = isset($option->id) ? $option->id : null; $extra = ''; if ($id) { $extra .= ' id="' . $option->id . '"'; } if (is_array($option->{$key})) { $a = $option->{$key}; if ($a[0] == 'optgroup') { $html .= "\n <optgroup label=\"" . htmlspecialchars($t) . "\"{$extra}>"; } else { $html .= "\n </optgroup>"; } } else { $k = $option->{$key}; if (is_array($selected)) { foreach ($selected as $obj) { if (is_object($obj)) { $k2 = $obj->{$key}; } else { $k2 = $obj; } if ($k === $k2) { $extra .= ' selected="selected"'; break; } } } else { if ($k == $selected) { $extra .= ' selected="selected"'; } } $html .= "\n\t<option value=\"" . htmlspecialchars($k) . "\"{$extra}>"; if ($htmlspecialcharText) { $html .= htmlspecialchars(getLangDefinition($t)); } else { $html .= getLangDefinition($t); } $html .= "</option>"; } } $html .= "\n</select>\n"; return $html; }
function control_id( $control_name, $name ) { return moscomprofilerHTML::htmlId( $this->control_name( $control_name, $name ) ); /* if ( $control_name ) { return str_replace( array( '[', ']' ), array( '__', '' ), $control_name ) .'__'. $name; } else { return $name; } */ }
/** * Creates a checkbox input array from $arr options list * * @param array $arr * @param string $tagName * @param null|string $tagAttributes * @param int|string $key * @param string $text * @param string $selected * @param int $required * @param null|array $classes * @param boolean $translate * @return array */ public static function checkboxListArr($arr, $tagName, $tagAttributes = null, $key = 'value', $text = 'text', $selected = null, $required = 0, $classes = null, $translate = true) { reset($arr); $idName = moscomprofilerHTML::htmlId($tagName); $html = array(); if ($classes === null) { $classes = array(); } if ($required) { $classes[] = 'required'; } foreach ($arr as $i => $option) { $k = $option->{$key}; $t = $option->{$text}; if (isset($option->id) && trim($option->id) != '') { $id = $option->id; } else { $id = $idName . '__cbf' . $i; } $extra = ' id="' . htmlspecialchars($id) . '"'; if (is_array($selected)) { foreach ($selected as $obj) { if (is_object($obj)) { $k2 = $obj->{$key}; } else { $k2 = $obj; } if ((string) $k === (string) $k2) { $extra .= ' checked="checked"'; break; } } } else { $extra .= (string) $k === (string) $selected ? ' checked="checked"' : null; } if (isset($option->class) && trim($option->class) != '') { $classes[] = htmlspecialchars($option->class); } if (count($classes) > 0) { $tagAttributes .= ' class="' . implode(' ', $classes) . '"'; } $extra .= (trim($tagAttributes) ? ' ' . $tagAttributes : null) . (isset($option->extra) && $option->extra ? ' ' . $option->extra : null); $html[] = '<label for="' . htmlspecialchars($id) . '" class="checkbox-inline">' . '<input type="checkbox" name="' . htmlspecialchars($tagName) . '" value="' . htmlspecialchars($k) . '"' . $extra . ' />' . ' ' . ($translate ? CBTxt::Th($t) : $t) . ' ' . '</label>'; } return $html; }