Zikula_Template_Plugins
[ class tree: Zikula_Template_Plugins ] [ index: Zikula_Template_Plugins ] [ all elements ]

Source for file function.pncalendarinput.php

Documentation is available at function.pncalendarinput.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2004, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pncalendarinput.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Template_Plugins
  10.  * @subpackage Functions
  11.  */
  12.  
  13. /**
  14.  * Smarty function to display a calendar input control
  15.  *
  16.  * This function displays a javascript (jscalendar) calendar control
  17.  *
  18.  * Available parameters:
  19.  *   - objectname     The name of the object the field will be placed in
  20.  *   - htmlname:      The html fieldname under which the date value will be submitted
  21.  *   - dateformat:    The dateformat to use for displaying the chosen date
  22.  *   - defaultstring: The String to display before a value has been selected
  23.  *   - defaultdate:   The Date the calendar should to default to (format: Y/m/d)
  24.  *   - hidden:        Boolean to show a hidden input or not
  25.  *   - display:       Boolean to show a display output (when date is added in a hidden field)
  26.  *   - class:         The class to apply to the html elements
  27.  *   - time:          If set show time selection
  28.  *
  29.  * Example
  30.  * <!--[pncalendarinput objectname=myobject htmlname=from dateformat='%Y-%m-%d' defaultdate='2005/12/31']-->
  31.  *
  32.  * @author       Mark West
  33.  * @author       Robert Gasch
  34.  * @since        25/10/2005
  35.  * @param        array       $params      All attributes passed to this function from the template
  36.  * @param        object      &$smarty     Reference to the Smarty object
  37.  * @param        assign      The smarty variable to assign the resulting menu HTML to
  38.  * @return       string      the language constant
  39.  */
  40. function smarty_function_pncalendarinput($params&$smarty)
  41. {
  42.     if (!isset($params['objectname'])) {
  43.         $smarty->trigger_error('pncalendarinput: parameter [objectname] required');
  44.         return false;
  45.     }
  46.     if (!isset($params['htmlname'])) {
  47.         $smarty->trigger_error('pncalendarinput: parameter [htmlname] required');
  48.         return false;
  49.     }
  50.     if (!isset($params['dateformat'])) {
  51.         $smarty->trigger_error('pncalendarinput: parameter [dateformat] required');
  52.         return false;
  53.     }
  54.  
  55.     // start of old pncalendarinit
  56.     // pagevars make an extra pncalendarinit obsolete, they take care about the fact
  57.     // that the styles/jsvascript do not get loaded multiple times
  58.     static $langFile
  59.     
  60.     if (!isset($langFile)) {
  61.         $currentLang SessionUtil::getVar('lang');
  62.         if (!file_exists ($langFile 'javascript/jscalendar/lang/calendar-' convcallang($currentLang'.js')) {
  63.             $langFile 'javascript/jscalendar/lang/calendar-en.js';
  64.         }
  65.     }
  66.  
  67.     PageUtil::addVar('stylesheet''javascript/jscalendar/calendar-win2k-cold-2.css');
  68.     PageUtil::addVar('javascript''javascript/jscalendar/calendar.js');
  69.     PageUtil::addVar('javascript'$langFile);
  70.     PageUtil::addVar('javascript''javascript/jscalendar/calendar-setup.js');
  71.     // end of old pncalendarinit
  72.  
  73.     if (!isset($params['defaultstring'])) $params['defaultstring'null;
  74.     if (!isset($params['defaultdate'])) $params['defaultdate'null;
  75.  
  76.     $html '';
  77.  
  78.     $fieldKey    $params['htmlname'];
  79.     if ($params['objectname']{
  80.         $fieldKey  $params['objectname''[' $params['htmlname'']';
  81.     }
  82.  
  83.     $triggerName 'trigger_' $params['htmlname'];
  84.     $displayName 'display_' $params['htmlname'];
  85.  
  86.     if (isset($params['class']&& !empty($params['class'])) {
  87.         $params['class'' class="' DataUtil::formatForDisplay($params['class']'"';
  88.     }
  89.  
  90.     if (isset($params['display']&& $params['display']{
  91.         $html .= '<span id="'.$displayName.'"'.$params['class'].'>'.$params['defaultstring'].'</span>';
  92.     }
  93.     $html .= '&nbsp;';
  94.     if (isset($params['hidden']&& $params['hidden']{
  95.         $html .= '<input type="hidden" name="'.$fieldKey.'" id="'.$params['htmlname'].'" value="'.$params['defaultdate'].'" />';
  96.     }
  97.  
  98.     $html .= '<img src="javascript/jscalendar/img.gif" id="'.$triggerName.'" style="cursor: pointer; border: 0px solid blue;" title="' DataUtil::formatForDisplay(_DATE_SELECTOR'"  alt="' DataUtil::formatForDisplay(_DATE_SELECTOR'" onmouseover="this.style.background=\'blue\';" onmouseout="this.style.background=\'\'" />';
  99.  
  100.     $html .= '<script type="text/javascript"> Calendar.setup({';
  101.     //$html .= 'ifFormat    : "%Y-%m-%d %H:%M:00",'; // universal format, don't change this!
  102.     $html .= 'ifFormat    : "'.$params['dateformat'].'",';
  103.     $html .= 'inputField  : "'.$params['htmlname'].'",';
  104.     $html .= 'displayArea : "'.$displayName.'",';
  105.     $html .= 'daFormat    : "'.$params['dateformat'].'",';
  106.     $html .= 'button      : "'.$triggerName.'",';
  107.     $html .= 'defaultDate : "'.$params['defaultdate'].'",';
  108.     $html .= 'align       : "Tl",';
  109.  
  110.     if (isset($params['defaultdate']&& $params['defaultdate']{
  111.         $d strtotime ($params['defaultdate']);
  112.         $d date ('Y/m/d'$d);
  113.         $html .= 'date : "'.$d.'",';
  114.     }
  115.  
  116.     if (isset($params['time'])) {    
  117.         $html .= 'showsTime      :    true,';
  118.         $html .= 'timeFormat     :    "' DataUtil::formatForDisplay(_TIMEFORMAT'",';
  119.     }
  120.  
  121.     $html .= 'singleClick : true }); </script>';
  122.  
  123.     return $html;
  124.  
  125. }
  126.  
  127. function convcallang($currentlang
  128. {
  129.     $alllangs array('afr' => 'af',
  130.                       'sqi' => 'al',
  131.                       '???' => 'bg',
  132.                       'por' => 'br'// ??
  133.                       '???' => 'ca',
  134.                       'ces' => 'cs-win',
  135.                       'dan' => 'da',
  136.                       'deu' => 'de',
  137.                       '???' => 'du',
  138.                       '???' => 'el',
  139.                       'eng' => 'en',
  140.                       'soa' => 'es',
  141.                       'fin' => 'fi',
  142.                       'fra' => 'fr',
  143.                       'scr' => 'hr',
  144.                       'hun' => 'hu',
  145.                       'ita' => 'it',
  146.                       '???' => 'jp',
  147.                       '???' => 'ko',
  148.                       '???' => 'lt',
  149.                       '???' => 'lv',
  150.                       'nld' => 'nl',
  151.                       'nor' => 'no',
  152.                       'pol' => 'pl',
  153.                       'por' => 'pt',  // ??
  154.                       'ron' => 'ro',
  155.                       'rus' => 'ru',
  156.                       'slv' => 'si',
  157.                       'slk' => 'sk',
  158.                       '???' => 'sp',
  159.                       'swe' => 'sv',
  160.                       'tur' => 'tr',
  161.                       'zho' => 'zh');
  162.     if (array_key_exists($currentlang$alllangs)) {
  163.         return $alllangs[$currentlang];
  164.     }
  165.     return 'en';
  166. }

Documentation generated on Fri, 18 Jul 2008 21:45:37 +0200 by phpDocumentor 1.4.1