Skip to content

Commit

Permalink
fixes several issues with parsing and displaying simple controls (cal…
Browse files Browse the repository at this point in the history
…endar, country, datetime, popupdatetime, range, states, & yuicalendar; also updates the date/time formats to values suitable for Windows servers [#885]
  • Loading branch information
dleffler committed Apr 3, 2013
1 parent 792b849 commit d08fb57
Show file tree
Hide file tree
Showing 10 changed files with 164 additions and 53 deletions.
16 changes: 8 additions & 8 deletions framework/conf/data/date_format.dropdown
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,37 @@
November 1

%B %e, %Y
November 1, 2010
November 1, 2013

%m/%d/%y
11/01/10

%b %d %Y
Nov 01 2010
Nov 01 2013

%b %d, %Y
Nov 01, 2010
Nov 01, 2013

%a %b %d %Y
Mon Nov 01 2010
Mon Nov 01 2013

%a, %b %d, %Y
Mon, Nov 01, 2010
Mon, Nov 01, 2013

%d.%m.%y
01.11.10

%d.%m.%Y
01.11.2010
01.11.2013

%d-%m-%y
01-11-10

%d-%m-%Y
01-11-2010
01-11-2013

%d/%m/%y
01/11/10

%d/%m/%Y
01/11/2010
01/11/2013
34 changes: 17 additions & 17 deletions framework/conf/data/datetime_format.dropdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@
# a date format that isn't listed here, and you tell me, I
# will put it in the standard distribution.

%A, %B %e, %l:%M%p
Monday, November 1, 2010, 6:45pm
%A, %B %e, %I:%M%p
Monday, November 1, 2013, 6:45pm

%B %e, %l:%M%p
November 1, 2010, 6:45pm
%B %e, %I:%M%p
November 1, 2013, 6:45pm

%m/%d/%y %T
11/01/10 18:45:00

%m/%d/%y %l:%M%p
%m/%d/%y %I:%M%p
11/01/10 6:45pm

%b %d %Y %H:%M
Nov 01 2010 18:45
Nov 01 2013 18:45

%b %d %Y %l:%M%p
Nov 01 2010 6:45pm
%b %d %Y %I:%M%p
Nov 01 2013 6:45pm

%b %d, %Y %H:%M
Nov 01, 2010 18:45
Nov 01, 2013 18:45

%b %d, %Y %l:%M%p
Nov 01, 2010 6:45pm
%b %d, %Y %I:%M%p
Nov 01, 2013 6:45pm

%a %b %d %Y %H:%M
Mon Nov 01 2010 18:45
Mon Nov 01 2013 18:45

%a %b %d %Y %l:%M%p
Mon Nov 01 2010 6:45pm
%a %b %d %Y %I:%M%p
Mon Nov 01 2013 6:45pm

%a, %b %d, %Y %H:%M
Mon, Nov 01, 2010 18:45
Mon, Nov 01, 2013 18:45

%a, %b %d, %Y %l:%M%p
Mon, Nov 01, 2010 6:45pm
%a, %b %d, %Y %I:%M%p
Mon, Nov 01, 2013 6:45pm
2 changes: 1 addition & 1 deletion framework/conf/extensions/display.defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
if (!defined('FORCE_MOBILE')) define('FORCE_MOBILE','0');
if (!defined('THEME_STYLE_REAL')) define('THEME_STYLE_REAL','');
if (!defined('DISPLAY_ATTRIBUTION')) define('DISPLAY_ATTRIBUTION','username');
if (!defined('DISPLAY_DATETIME_FORMAT')) define('DISPLAY_DATETIME_FORMAT','%m/%d/%y %l:%M%p');
if (!defined('DISPLAY_DATETIME_FORMAT')) define('DISPLAY_DATETIME_FORMAT','%m/%d/%y %I:%M%p');
if (!defined('DISPLAY_DATE_FORMAT')) define('DISPLAY_DATE_FORMAT','%m/%d/%y');
if (!defined('DISPLAY_TIME_FORMAT')) define('DISPLAY_TIME_FORMAT','%I:%M%p');
if (!defined('DISPLAY_START_OF_WEEK')) define('DISPLAY_START_OF_WEEK','0');
Expand Down
45 changes: 37 additions & 8 deletions framework/core/forms/controls/calendarcontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,47 @@ function controlToHTML($name, $label = null) {
}

static function parseData($original_name, $formvalues) {
if (!empty($formvalues[$original_name])) {
return strtotime($formvalues[$original_name]);
if (!empty($formvalues['date-'.$original_name])) {
$date = strtotime($formvalues['date-'.$original_name]);
$time = 0;
if (isset($formvalues['time-h-'.$original_name])) {
if ($formvalues['time-h-'.$original_name] == 12 && $formvalues['ampm-'.$original_name] == 'am') {
// 12 am (right after midnight) is 0:xx
$formvalues['time-h-'.$original_name] = 0;
} else if ($formvalues['time-h-'.$original_name] != 12 && $formvalues['ampm-'.$original_name] == 'pm') {
// 1:00 pm to 11:59 pm shifts 12 hours
$formvalues['time-h-'.$original_name] += 12;
}

$time += $formvalues['time-h-'.$original_name] * 3600 + $formvalues['time-m-'.$original_name] * 60;
}

return $date + $time;
} else return 0;
}

/**
* Display the date data in human readable format
*
* @param $db_data
* @param $ctl
*
* @return string
*/
static function templateFormat($db_data, $ctl) {
// if ($ctl->showtime) {
// return strftime(DISPLAY_DATETIME_FORMAT,$db_data);
// }
// else {
// return strftime(DISPLAY_DATE_FORMAT, $db_data);
// }
if ($ctl->showtime) {
// return strftime(DISPLAY_DATETIME_FORMAT,$db_data);
// return gmstrftime(DISPLAY_DATETIME_FORMAT, $db_data);
$datetime = strftime(DISPLAY_DATETIME_FORMAT, $db_data);
if (!$datetime) $datetime = strftime('%m/%d/%y %I:%M%p', $db_data);
return $datetime;
} else {
// return strftime(DISPLAY_DATE_FORMAT, $db_data);
// return gmstrftime(DISPLAY_DATE_FORMAT, $db_data);
$date = strftime(DISPLAY_DATE_FORMAT, $db_data);
if (!$date) $date = strftime('%m/%d/%y', $db_data);
return $date;
}
}

static function form($object) {
Expand Down
18 changes: 18 additions & 0 deletions framework/core/forms/controls/countrycontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ static function update($values, $object) {
$object->required = isset($values['required']);
return $object;
}

/**
* Format the control's data for user display
*
* @param $db_data
* @param $ctl
* @return string
*/
static function templateFormat($db_data, $ctl) {
global $db;

if (isset($db_data)) {
return $db->selectValue('geo_country', 'name', 'id="' . $db_data . '"');
} else {
return "";
}
}

}

?>
24 changes: 20 additions & 4 deletions framework/core/forms/controls/datetimecontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,33 @@ static function parseData($original_name, $formvalues, $for_db = false) {
}

static function convertData($original_name,$formvalues) {
$tmp = strtotime($formvalues[$original_name]);
return (isset($formvalues[$original_name])?strtotime($formvalues[$original_name]):"");
}

/**
* Display the date data in human readable format
*
* @param $db_data
* @param $ctl
*
* @return string
*/
static function templateFormat($db_data, $ctl) {
if ($ctl->showdate && $ctl->showtime) {
return gmstrftime(DISPLAY_DATETIME_FORMAT, $db_data);
// return gmstrftime(DISPLAY_DATETIME_FORMAT, $db_data);
$datetime = strftime(DISPLAY_DATETIME_FORMAT, $db_data);
if (!$datetime) $datetime = strftime('%m/%d/%y %I:%M%p', $db_data);
return $datetime;
} elseif ($ctl->showdate) {
return gmstrftime(DISPLAY_DATE_FORMAT, $db_data);
// return gmstrftime(DISPLAY_DATE_FORMAT, $db_data);
$date = strftime(DISPLAY_DATE_FORMAT, $db_data);
if (!$date) $date = strftime('%m/%d/%y', $db_data);
return $date;
} elseif ($ctl->showtime) {
return gmstrftime(DISPLAY_TIME_FORMAT, $db_data);
// return gmstrftime(DISPLAY_TIME_FORMAT, $db_data);
$time = strftime(DISPLAY_TIME_FORMAT, $db_data);
if (!$time) $time = strftime('%I:%M%p', $db_data);
return $time;
} else {
return "";
}
Expand Down
22 changes: 18 additions & 4 deletions framework/core/forms/controls/popupdatetimecontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,30 @@ function controlToHTML($name,$label) {

static function parseData($original_name,$formvalues) {
if (!isset($formvalues[$original_name.'_disabled'])) {
return strtotime($formvalues[$original_name.'_hidden']);
//return $formvalues[$original_name.'_hidden'];
// return strtotime($formvalues[$original_name]);
return $formvalues[$original_name];
} else return 0;
}

/**
* Display the date data in human readable format
*
* @param $db_data
* @param $ctl
*
* @return string
*/
static function templateFormat($db_data, $ctl) {
if ($ctl->showtime) {
return strftime(DISPLAY_DATETIME_FORMAT,$db_data);
// return strftime(DISPLAY_DATETIME_FORMAT,$db_data);
$datetime = strftime(DISPLAY_DATETIME_FORMAT, $db_data);
if (!$datetime) $datetime = strftime('%m/%d/%y %I:%M%p', $db_data);
return $datetime;
} else {
return strftime(DISPLAY_DATE_FORMAT, $db_data);
// return strftime(DISPLAY_DATE_FORMAT, $db_data);
$date = strftime(DISPLAY_DATE_FORMAT, $db_data);
if (!$date) $date = strftime('%m/%d/%y', $db_data);
return $date;
}
}

Expand Down
6 changes: 3 additions & 3 deletions framework/core/forms/controls/rangecontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ function controlToHTML($name, $label) {
$html .= ($this->size?" size=\"".$this->size."\"":"");
$html .= ($this->disabled?" disabled ":"");
$html .= ($this->maxlength?" maxlength=\"".$this->maxlength."\"":"");
$html .= ($this->min?" min=\"".$this->min."\"":"");
$html .= ($this->max?" max=\"".$this->max."\"":"");
$html .= ($this->step?" step=\"".$this->step."\"":"");
$html .= ($this->min?" min=\"".$this->min."\"":" min=\"0\"");
$html .= ($this->max?" max=\"".$this->max."\"":" max=\"100\"");
$html .= ($this->step?" step=\"".$this->step."\"":" step=\"1\"");
$html .= ($this->tabindex>=0?" tabindex=\"".$this->tabindex."\"":"");
$html .= ($this->accesskey != ""?" accesskey=\"".$this->accesskey."\"":"");
$html .= ($this->placeholder?" placeholder=\"".$this->placeholder."\"":"");
Expand Down
18 changes: 18 additions & 0 deletions framework/core/forms/controls/statescontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,24 @@ static function update($values, $object) {
$object->required = isset($values['required']);
return $object;
}

/**
* Format the control's data for user display
*
* @param $db_data
* @param $ctl
* @return string
*/
static function templateFormat($db_data, $ctl) {
global $db;

if (isset($db_data)) {
return $db->selectValue('geo_region', 'name', 'id="' . $db_data . '"');
} else {
return "";
}
}

}

?>
32 changes: 24 additions & 8 deletions framework/core/forms/controls/yuicalendarcontrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,16 @@ function onRegister(&$form) {
}

function controlToHTML($name, $label = null) {
if (is_integer($this->default)) {
$default = date('m/d/Y', $this->default);
} else {
$default = $this->default;
}
$html = "
<div class=\"yui3-skin-sam\">
<div id=\"cal" . $name . "Container\"></div>
<div id=\"calinput\">
<input class=\"text\" type=\"text\" name=\"" . $name . "\" id=\"" . $name . "\" value=\"" . date('m/d/Y', $this->default) . "\"/>
<input class=\"text\" type=\"text\" name=\"" . $name . "\" id=\"" . $name . "\" value=\"" . $default . "\"/>
<button class=\"button\" type=\"button\" id=\"update-" . $name . "\">" . gt('Update Calendar') . "</button>
</div>
</div>
Expand All @@ -93,7 +98,7 @@ function controlToHTML($name, $label = null) {
// });
// Parsing the date string into JS Date value
var date = Y.DataType.Date.parse('" . date('m/d/Y', $this->default) . "');
var date = Y.DataType.Date.parse('" . $default . "');
if (date) {
// Highlighting the date stored in the text field
calendar.selectDates(date);
Expand Down Expand Up @@ -146,13 +151,24 @@ static function parseData($original_name, $formvalues) {
} else return 0;
}

/**
* Display the date data in human readable format
*
* @param $db_data
* @param $ctl
*
* @return string
*/
static function templateFormat($db_data, $ctl) {
// if ($ctl->showtime) {
// return strftime(DISPLAY_DATETIME_FORMAT,$db_data);
// }
// else {
// return strftime(DISPLAY_DATE_FORMAT, $db_data);
// }
// if ($ctl->showtime) {
// return strftime(DISPLAY_DATETIME_FORMAT,$db_data);
// } else {
// return strftime(DISPLAY_DATE_FORMAT, $db_data);
// return gmstrftime(DISPLAY_DATE_FORMAT, $db_data);
$date = strftime(DISPLAY_DATE_FORMAT, $db_data);
if (!$date) $date = strftime('%m/%d/%y', $db_data);
return $date;
// }
}

static function form($object) {
Expand Down

0 comments on commit d08fb57

Please sign in to comment.