00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 class JSCalendar
00031 {
00033 var $config = array();
00034
00036 var $jsSent = false;
00037
00039 var $lang = null;
00040
00049 function JSCalendar() {
00050
00051 $this->config['backPath'] = $GLOBALS['BACK_PATH'] . (TYPO3_MODE == 'BE' ? '../' : '');
00052 $this->config['relPath'] = $this->config['backPath'] . t3lib_extMgm::siteRelPath('date2cal');
00053 $this->config['absPath'] = t3lib_extMgm::extPath('date2cal');
00054
00055
00056 $this->lang = TYPO3_MODE == 'FE' ? $GLOBALS['TSFE'] : $GLOBALS['LANG'];
00057
00058
00059 $this->setNLP(true);
00060 $this->setCSS();
00061 $this->setLanguage();
00062 $this->setDateFormat();
00063
00064
00065 $this->setConfigOption('helpPage', $this->config['relPath'] . 'res/helpPage.html');
00066 }
00067
00074 function &getInstance() {
00075 static $instance;
00076 if (!isset($instance))
00077 $instance = new JSCalendar();
00078 return $instance;
00079 }
00080
00094 function render($value, $name = '', $calImg = '', $helpImg = '') {
00095
00096 if (!isset($this->config['inputField']))
00097 $this->setInputField('date');
00098
00099
00100 $name = $name == '' ? $this->config['inputField'] : $name;
00101 $content = '<input type="checkbox" name="' . $name . '_cb" class="jscalendar_cb" ' .
00102 'id ="' . $this->config['inputField'] . '_cb" ' .
00103 'onclick="date2cal_setDatetime(\'' . $this->config['inputField'] . '_hr\', ' .
00104 strftime($this->config['calConfig']['ifFormat']) . ');" /> ';
00105 $size = $this->config['calConfig']['showsTime'] ? 16 : 10;
00106 $content .= '<input type="text" size="' . $size . '" maxlength="' . $size . '" ' .
00107 'name="' . $name . '" id="' . $this->config['inputField'] . '_hr" class="jscalendar" ' .
00108 'onchange="date2cal_activeDateField(\'' . $this->config['inputField'] . '_cb\', \'' .
00109 $this->config['inputField'] . '_hr\');" value="' . $value . '" />';
00110
00111
00112 $content .= $this->renderImages($calImg, $helpImg);
00113
00114 return $content;
00115 }
00116
00125 function renderImages($calImg = '', $helpImg = '') {
00126
00127 $calImg = $calImg == '' ? $this->config['relPath'] . 'res/calendar.png' : $calImg;
00128 $helpImg = $helpImg == '' ? $this->config['relPath'] . 'res/helpIcon.gif' : $helpImg;
00129
00130
00131 $valign = TYPO3_MODE == 'FE' ? 'vertical-align: middle;' : '';
00132
00133
00134 $calImgTitle = $this->lang->sL('LLL:EXT:date2cal/locallang.xml:calendar_wizard');
00135 $helpImgTitle = $this->lang->sL('LLL:EXT:date2cal/locallang.xml:help');
00136
00137
00138 $content .= ' <img class="date2cal_img_cal absMiddle" src="' . $calImg . '" ' .
00139 'id="' . $this->config['inputField'] . '_trigger" style="cursor: pointer; ' . $valign . '" ' .
00140 'title="' . $calImgTitle . '" alt="' . $calImgTitle . '" />' . "\n";
00141
00142
00143 if ($this->config['natLangParser']) {
00144 $content .= '<img class="date2cal_img_help absMiddle" src="' . $helpImg . '" ' .
00145 'id="' . $this->config['inputField'] . '_help" style="cursor: pointer; ' . $valign . '" ' .
00146 'title="' . $helpImgTitle . '" alt="' . $helpImgTitle . '" />' . "\n";
00147 }
00148
00149
00150 $content .= $this->getConfigJS();
00151
00152 return $content;
00153 }
00154
00166 function setConfigOption($option, $value, $nonString=false) {
00167 $this->config['calConfig'][$option] = !$nonString ? '\'' . $value . '\'' : $value;
00168 }
00169
00178 function setInputField($field) {
00179 $this->config['inputField'] = $field;
00180 $this->setConfigOption('inputField', $field . '_hr');
00181 $this->setConfigOption('button', $field . '_trigger');
00182 }
00183
00189 function getInputField() {
00190 return $this->config['inputField'];
00191 }
00192
00200 function setLanguage($lang='') {
00201
00202 if ($lang == '') {
00203 if (TYPO3_MODE == 'FE')
00204 $lang = $GLOBALS['TSFE']->config['config']['language'];
00205 else
00206 $lang = $GLOBALS['LANG']->lang;
00207 }
00208
00209
00210 $this->config['lang'] = $this->languageCheck($lang);
00211 }
00212
00219 function setCSS($calendarCSS = 'aqua') {
00220 $this->config['calendarCSS'] = $calendarCSS;
00221 if (!is_file($this->config['absPath'] . 'js/jscalendar/skins/' . $calendarCSS . '/theme.css'))
00222 $this->config['calendarCSS'] = 'aqua';
00223 }
00224
00232 function setNLP($mode) {
00233 $this->config['natLangParser'] = true;
00234 if (!$mode || t3lib_div::int_from_ver(TYPO3_version) < 4001000)
00235 $this->config['natLangParser'] = false;
00236 }
00237
00246 function setDateFormat($time=false) {
00247 $jsDate = $GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ?
00248 '%m-%d-%Y' : '%d-%m-%Y';
00249 $jsDate = ($time ? '%H:%M ' : '') . $jsDate;
00250
00251 $value = $time ? 'true' : 'false';
00252 $this->setConfigOption('showsTime', $value, true);
00253 $this->setConfigOption('time24', $value, true);
00254 $this->setConfigOption('ifFormat', $jsDate);
00255 }
00256
00262 function getConfigJS()
00263 {
00264
00265 $tmp = array();
00266 foreach($this->config['calConfig'] as $label => $value)
00267 $tmp[] = $label . ': ' . $value;
00268 $config = implode(",\n", $tmp);
00269
00270
00271 if ($this->config['natLangParser']) {
00272 $js = '
00273 <script type="text/javascript">
00274 new DatetimeToolbocks ({
00275 format: ' . $this->config['calConfig']['ifFormat'] . ',
00276 inputName: \'' . $this->config['inputField'] . '\',
00277 elementId: \'' . $this->config['inputField'] . '\',
00278 calendarOptions: {
00279 ' . $config . '
00280 }
00281 });
00282 </script>';
00283 } else {
00284 $js = '
00285 <script type="text/javascript">
00286 Calendar.setup ({
00287 ' . $config . '
00288 });
00289 </script>';
00290 }
00291
00292 return $js;
00293 }
00294
00301 function getMainJS()
00302 {
00303
00304 if ($this->jsSent)
00305 return '';
00306 $this->jsSent = true;
00307
00308
00309 $relPath = $this->config['relPath'] . 'js/';
00310 $js = '<!-- inclusion of JSCalendar -->
00311 <script type="text/javascript" src="' . $relPath . 'jscalendar/calendar.js"></script>
00312 <script type="text/javascript" src="' . $relPath .
00313 'jscalendar/lang/calendar-en.js"></script>' . "\n";
00314 if ($this->config['lang'] != 'en')
00315 $js .= '<script type="text/javascript" src="' . $relPath . 'jscalendar/lang/calendar-' .
00316 $this->config['lang'] . '.js"></script>' . "\n";
00317 $js .= '<script type="text/javascript" src="' . $relPath .
00318 'jscalendar/calendar-setup.js"></script>
00319 <link rel="stylesheet" type="text/css" href="' . $relPath . 'jscalendar/skins/' .
00320 $this->config['calendarCSS'] . '/theme.css" />
00321 <script type="text/javascript" src="' . $relPath . 'date2cal.js"></script>' . "\n";
00322
00323
00324 if ($this->config['natLangParser']) {
00325 $js .= '<!-- inclusion of datetime_toolbocks.js -->
00326 <script type="text/javascript" src="' . $this->config['backPath'] .
00327 'typo3/contrib/prototype/prototype.js"></script>
00328 <script type="text/javascript" src="' . $relPath .
00329 'naturalLanguageParser.js"></script>' . "\n";
00330 }
00331
00332 return $js;
00333 }
00334
00345 function languageCheck($lang)
00346 {
00347
00348 if (array_key_exists($lang, $this->lang->csConvObj->isoArray))
00349 $lang = $this->lang->csConvObj->isoArray[$lang];
00350
00351
00352 $absPath = $this->config['absPath'] . 'js/';
00353 if ($GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] == 'utf-8' &&
00354 is_file($absPath . 'jscalendar/lang/calendar-' . $lang . '-utf8.js'))
00355 return $lang . '-utf8';
00356
00357
00358 if (!is_file($absPath . 'jscalendar/lang/calendar-' . $lang . '.js'))
00359 return 'en';
00360
00361 return $lang;
00362 }
00363 }
00364 ?>