Skip to content

Commit

Permalink
Merge branch 'hotfix/2.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
cliffparnitzky committed Mar 10, 2016
2 parents f8569c9 + c115818 commit d9d2298
Showing 1 changed file with 70 additions and 73 deletions.
143 changes: 70 additions & 73 deletions CT_ROOT/system/modules/hofff_calendarfield/forms/FormCalendarField.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,78 +73,76 @@ public function parse($arrAttributes=null)
$this->varValue = \Date::parse($dateFormat, strtotime($this->varValue));
}

if (!$this->readonly && !$this->disabled) {

// Initialize the default config
$arrConfig = array(
'showAnim' => "'fadeIn'",
'showOtherMonths' => "true",
'selectOtherMonths' => "true",
'changeMonth' => "true",
'changeYear' => "true"
);

switch ($this->dateDirection) {
case 'ltToday':
$time = strtotime('-1 day');
$arrConfig['maxDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')';
break;

case 'leToday':
$arrConfig['maxDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')';
break;

case 'geToday':
$arrConfig['minDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')';
break;

case 'gtToday':
$time = strtotime('+1 day');
$arrConfig['minDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')';
break;
}

if ($this->dateImage) {
// icon
$strIcon = 'assets/mootools/datepicker/'.DATEPICKER.'/icon.gif';

if (\Validator::isUuid($this->dateImageSRC)) {
$objFile = \FilesModel::findByPk($this->dateImageSRC);

if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) {
$strIcon = $objFile->path;
}
}

$arrSize = @getimagesize(TL_ROOT . '/' . $strIcon);

$arrConfig['showOn'] = "'both'";
$arrConfig['buttonImage'] = "'" . $strIcon . "'";
$arrConfig['buttonImageOnly'] = "true";
$arrConfig['buttonText'] = "'" . $GLOBALS['TL_LANG']['MSC']['calendarfield_tooltip'] . "'";
}

// correctly style the date format
$arrConfig['format'] = "'" . $this->dateformat_PHP_to_jQueryUI($dateFormat) . "'";

if (is_array($this->dateConfig)) {
$arrConfig = array_replace($arrConfig, $this->dateConfig);
}

// HOOK: allow to customize the date picker
if (isset($GLOBALS['TL_HOOKS']['formCalendarField']) && is_array($GLOBALS['TL_HOOKS']['formCalendarField'])) {
foreach ($GLOBALS['TL_HOOKS']['formCalendarField'] as $callback) {
$objCallback = (method_exists($callback[0], 'getInstance') ? call_user_func(array($callback[0], 'getInstance')) : new $callback[0]());
$arrConfig = $objCallback->$callback[1]($arrConfig, $this);
}
}

$arrCompiledConfig = array();
foreach ($arrConfig as $k => $v) {
$arrCompiledConfig[] = " '" . $k . "': " . $v;
}

$this->calendarfieldScript .= "
// Initialize the default config
$arrConfig = array(
'showAnim' => "'fadeIn'",
'showOtherMonths' => "true",
'selectOtherMonths' => "true",
'changeMonth' => "true",
'changeYear' => "true"
);

switch ($this->dateDirection) {
case 'ltToday':
$time = strtotime('-1 day');
$arrConfig['maxDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')';
break;

case 'leToday':
$arrConfig['maxDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')';
break;

case 'geToday':
$arrConfig['minDate'] = 'new Date(' . date('Y') . ', ' . (date('n')-1) . ', ' . date('j') . ')';
break;

case 'gtToday':
$time = strtotime('+1 day');
$arrConfig['minDate'] = 'new Date(' . date('Y', $time) . ', ' . (date('n', $time)-1) . ', ' . date('j', $time) . ')';
break;
}

if ($this->dateImage) {
// icon
$strIcon = 'assets/mootools/datepicker/'.DATEPICKER.'/icon.gif';

if (\Validator::isUuid($this->dateImageSRC)) {
$objFile = \FilesModel::findByPk($this->dateImageSRC);

if ($objFile !== null && is_file(TL_ROOT . '/' . $objFile->path)) {
$strIcon = $objFile->path;
}
}

$arrSize = @getimagesize(TL_ROOT . '/' . $strIcon);

$arrConfig['showOn'] = "'both'";
$arrConfig['buttonImage'] = "'" . $strIcon . "'";
$arrConfig['buttonImageOnly'] = "true";
$arrConfig['buttonText'] = "'" . $GLOBALS['TL_LANG']['MSC']['calendarfield_tooltip'] . "'";
}

// correctly style the date format
$arrConfig['format'] = "'" . $this->dateformat_PHP_to_jQueryUI($dateFormat) . "'";

if (is_array($this->dateConfig)) {
$arrConfig = array_replace($arrConfig, $this->dateConfig);
}

// HOOK: allow to customize the date picker
if (isset($GLOBALS['TL_HOOKS']['formCalendarField']) && is_array($GLOBALS['TL_HOOKS']['formCalendarField'])) {
foreach ($GLOBALS['TL_HOOKS']['formCalendarField'] as $callback) {
$objCallback = (method_exists($callback[0], 'getInstance') ? call_user_func(array($callback[0], 'getInstance')) : new $callback[0]());
$arrConfig = $objCallback->$callback[1]($arrConfig, $this);
}
}

$arrCompiledConfig = array();
foreach ($arrConfig as $k => $v) {
$arrCompiledConfig[] = " '" . $k . "': " . $v;
}

$this->calendarfieldScript .= "
<script>
$(function() {
$.datepicker.regional['" . $objPage->language . "'];
Expand All @@ -153,7 +151,6 @@ public function parse($arrAttributes=null)
});
});
</script>";
}

return parent::parse($arrAttributes);
}
Expand Down

0 comments on commit d9d2298

Please sign in to comment.