3 * jsCalendar wrapper-class
5 * @author Ralf Becker <RalfBecker@outdoor-training.de>
6 * @copyright Copyright (C) 2003,2004 Free Software Foundation, Inc. http://www.fsf.org/
7 * @license http://www.fsf.org/licenses/gpl.html GNU General Public License
10 * @version $Id: class.jscalendar.inc.php,v 1.1.2.12 2004/05/01 09:24:53 skwashd Exp $
14 * jsCalendar wrapper-class
18 * @internal The constructor load the necessary javascript-files
24 @syntax jscalendar( $do_header=True )
26 @abstract constructor of the class
27 @param $do_header if true, necessary javascript and css gets loaded, only needed for input
29 function jscalendar($do_header=True)
31 if(!is_object($GLOBALS['phpgw']->js))
33 $GLOBALS['phpgw']->js = createObject('phpgwapi.javascript');
35 $GLOBALS['phpgw']->js->validate_file('jscalendar', 'calendar');
36 $this->phpgw_js_url = $GLOBALS['phpgw_info']['server']['webserver_url'].'/phpgwapi/js';
37 $this->dateformat = $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
39 if ($do_header && !strstr($GLOBALS['phpgw_info']['flags']['css'],'jscalendar'))
41 $GLOBALS['phpgw_info']['flags']['css'] .= "-->\n</style>\n"
42 . '<link rel="stylesheet" type="text/css" media="all" href="'
44 . '/jscalendar/calendar-win2k-cold-1.css" title="win2k-cold-1" />'
45 . "\n<style type=\"text/css\">\n<!--\n";
47 $GLOBALS['phpgw_info']['flags']['java_script'] .= "\n"
48 . '<script type="text/javascript" src="'
49 . $GLOBALS['phpgw']->link('/phpgwapi/js/jscalendar/jscalendar-setup.php')
56 @syntax input( $name,$date,$year=0,$month=0,$day=0 )
58 @abstract creates an inputfield for the jscalendar (returns the necessary html and js)
59 @param $name name and id of the input-field (it also names the id of the img $name.'-toggle')
60 @param $date date as string or unix timestamp (in users localtime)
61 @param $year,$month,$day if $date is not used
62 @param $helpmsg a helpmessage for the statusline of the browser
63 @param $options any other options to the inputfield
64 @param $setup any other calendar setup options
66 function input($name,$date,$year=0,$month=0,$day=0,$helpmsg='',$options='',$setup='')
68 //echo "<p>jscalendar::input(name='$name', date='$date'='".date('Y-m-d',$date)."', year='$year', month='$month', day='$day')</p>\n";
70 if ($date && (is_int($date) || is_numeric($date)))
72 $year = intval($GLOBALS['phpgw']->common->show_date($date,'Y'));
73 $month = intval($GLOBALS['phpgw']->common->show_date($date,'n'));
74 $day = intval($GLOBALS['phpgw']->common->show_date($date,'d'));
76 if ($year && $month && $day)
78 $date = date($this->dateformat,mktime(12,0,0,$month,$day,$year));
82 $options .= " onFocus=\"self.status='".addslashes($helpmsg)."'; return true;\"" .
83 " onBlur=\"self.status=''; return true;\"";
86 '<input type="text" id="'.$name.'" name="'.$name.'" size="12" value="'.$date.'"'.$options.'/>
87 <script type="text/javascript">
88 document.writeln(\'<img id="'.$name.'-trigger" src="'.$GLOBALS['phpgw']->common->find_image('phpgwapi','cal').'" title="'.lang('Select date').'" style="cursor:pointer; cursor:hand;"/>\');
91 inputField : "'.$name.'",
92 button : "'.$name.'-trigger",
102 @syntax input2date( $datestr,$raw='raw',$day='day',$month='month',$year='year' )
104 @abstract converts the date-string back to an array with year, month, day and a timestamp
105 @param $datestr content of the inputfield generated by jscalendar::input()
106 @param $raw key of the timestamp-field in the returned array or False of no timestamp
107 @param $day,$month,$year keys for the array, eg. to set mday instead of day
109 function input2date($datestr,$raw='raw',$day='day',$month='month',$year='year')
115 $fields = split('[./-]',$datestr);
116 foreach(split('[./-]',$this->dateformat) as $n => $field)
118 $date[$field] = intval($fields[$n]);
121 for($i=1; $i <=12; $i++)
123 if(date('M',mktime(0,0,0,$i,1,2000)) == $fields[$n])
132 $month => $date['m'],
137 $ret[$raw] = mktime(12,0,0,$date['m'],$date['d'],$date['Y']);
139 //echo "<p>jscalendar::input2date('$datestr','$raw',$day','$month','$year') = "; print_r($ret); echo "</p>\n";