| [ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - API jsCalendar wrapper-class * 4 * http://www.eGroupWare.org * 5 * Written by Ralf Becker <RalfBecker@outdoor-training.de> * 6 * -------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: class.jscalendar.inc.php 20295 2006-02-15 12:31:25Z $ */ 14 15 /*! 16 @class jscalendar 17 @author ralfbecker 18 @abstract wrapper for the jsCalendar 19 @discussion the constructor load the necessary javascript-files 20 */ 21 class jscalendar 22 { 23 /*! 24 @function jscalendar 25 @syntax jscalendar( $do_header=True ) 26 @author ralfbecker 27 @abstract constructor of the class 28 @param $do_header if true, necessary javascript and css gets loaded, only needed for input 29 */ 30 function jscalendar($do_header=True,$path='jscalendar') 31 { 32 $this->jscalendar_url = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/'.$path; 33 $this->dateformat = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; 34 35 if ($do_header && !strstr($GLOBALS['egw_info']['flags']['java_script'],'jscalendar')) 36 { 37 $GLOBALS['egw_info']['flags']['java_script'] .= 38 '<link rel="stylesheet" type="text/css" media="all" href="'.$this->jscalendar_url.'/calendar-blue.css" title="blue" /> 39 <script type="text/javascript" src="'.$this->jscalendar_url.'/calendar.js"></script> 40 <script type="text/javascript" src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','',$GLOBALS['egw']->link('/phpgwapi/inc/jscalendar-setup.php')).'"></script> 41 '; 42 } 43 } 44 45 /*! 46 @function input 47 @syntax input( $name,$date,$year=0,$month=0,$day=0 ) 48 @author ralfbecker 49 @abstract creates an inputfield for the jscalendar (returns the necessary html and js) 50 @param $name name and id of the input-field (it also names the id of the img $name.'-toggle') 51 @param $date date as string or unix timestamp (in server timezone) 52 @param $year,$month,$day if $date is not used 53 @param $helpmsg a helpmessage for the statusline of the browser 54 @param $options any other options to the inputfield 55 */ 56 function input($name,$date,$year=0,$month=0,$day=0,$helpmsg='',$options='',$jsreturn=false) 57 { 58 //echo "<p>jscalendar::input(name='$name', date='$date'='".date('Y-m-d',$date)."', year='$year', month='$month', day='$day')</p>\n"; 59 60 if ($date && (is_int($date) || is_numeric($date))) 61 { 62 $year = (int)adodb_date('Y',$date); 63 $month = (int)adodb_date('n',$date); 64 $day = (int)adodb_date('d',$date); 65 } 66 if ($year && $month && $day) 67 { 68 $date = adodb_date($this->dateformat,$ts = adodb_mktime(12,0,0,$month,$day,$year)); 69 if (strpos($this->dateformat,'M') !== False) 70 { 71 $short = lang(adodb_date('M',$ts)); // check if we have a translation of the short-cut 72 if (substr($short,-1) == '*') // if not generate one by truncating the translation of the long name 73 { 74 $short = substr(lang(adodb_date('F',$ts)),0,(int) lang('3 number of chars for month-shortcut')); 75 } 76 $date = str_replace(adodb_date('M',$ts),$short,$date); 77 } 78 } 79 if ($helpmsg !== '') 80 { 81 $options .= " onFocus=\"self.status='".addslashes($helpmsg)."'; return true;\"" . 82 " onBlur=\"self.status=''; return true;\""; 83 } 84 85 if ($jsreturn) 86 { 87 $return_array = array( 88 'html' => '<input type="text" id="'.$name.'" name="'.$name.'" size="10" value="'.$date.'"'.$options.'/><img id="'.$name.'-trigger" src="'.$GLOBALS['egw']->common->find_image('phpgwpai','datepopup').'" title="'.lang('Select date').'" style="cursor:pointer; cursor:hand;"/>', 89 'js' => 'Calendar.setup({inputField : "'.$name.'",button: "'.$name.'-trigger" });' 90 ); 91 92 return $return_array; 93 } 94 return 95 '<input type="text" id="'.$name.'" name="'.$name.'" size="10" value="'.$date.'"'.$options.'/> 96 <script type="text/javascript"> 97 document.writeln(\'<img id="'.$name.'-trigger" src="'.$GLOBALS['egw']->common->find_image('phpgwpai','datepopup').'" title="'.lang('Select date').'" style="cursor:pointer; cursor:hand;"/>\'); 98 Calendar.setup( 99 { 100 inputField : "'.$name.'", 101 button : "'.$name.'-trigger" 102 } 103 ); 104 </script> 105 '; 106 } 107 108 function flat($url,$date=False,$weekUrl=False,$weekTTip=False,$monthUrl=False,$monthTTip=False,$id='calendar-container') 109 { 110 if ($date) // string if format YYYYmmdd or timestamp 111 { 112 $date = is_int($date) ? adodb_date('m/d/Y',$date) : 113 substr($date,4,2).'/'.substr($date,6,2).'/'.substr($date,0,4); 114 } 115 return ' 116 <div id="'.$id.'"></div> 117 118 <script type="text/javascript"> 119 function dateChanged(calendar) { 120 '. // Beware that this function is called even if the end-user only 121 // changed the month/year. In order to determine if a date was 122 // clicked you can use the dateClicked property of the calendar: 123 // redirect to $url extended with a &date=YYYYMMDD 124 ' if (calendar.dateClicked) { 125 window.location = "'.$url.'&date=" + calendar.date.print("%Y%m%d"); 126 } 127 }; 128 '.($weekUrl ? ' 129 function weekClicked(calendar,weekstart) { 130 window.location = "'.$weekUrl.'&date=" + weekstart.print("%Y%m%d"); 131 } 132 ' : '').($monthUrl ? ' 133 function monthClicked(calendar,monthstart) { 134 window.location = "'.$monthUrl.'&date=" + monthstart.print("%Y%m%d"); 135 } 136 ' : '').' 137 Calendar.setup( 138 { 139 flat : "'.$id.'", 140 flatCallback : dateChanged'.($weekUrl ? ', 141 flatWeekCallback : weekClicked' : '').($weekTTip ? ', 142 flatWeekTTip : "'.addslashes($weekTTip).'"' : '').($monthUrl ? ', 143 flatMonthCallback : monthClicked' : '').($monthTTip ? ', 144 flatMonthTTip : "'.addslashes($monthTTip).'"' : '').($date ? ', 145 date : "'.$date.'" 146 ' : '').' } 147 ); 148 </script>'; 149 } 150 151 /*! 152 @function input2date 153 @syntax input2date( $datestr,$raw='raw',$day='day',$month='month',$year='year' ) 154 @author ralfbecker 155 @abstract converts the date-string back to an array with year, month, day and a timestamp 156 @param $datestr content of the inputfield generated by jscalendar::input() 157 @param $raw key of the timestamp-field in the returned array or False of no timestamp 158 @param $day,$month,$year keys for the array, eg. to set mday instead of day 159 */ 160 function input2date($datestr,$raw='raw',$day='day',$month='month',$year='year') 161 { 162 //echo "<p>jscalendar::input2date('$datestr') ".print_r($fields,True)."</p>\n"; 163 if ($datestr === '') 164 { 165 return False; 166 } 167 $fields = split('[./-]',$datestr); 168 foreach(split('[./-]',$this->dateformat) as $n => $field) 169 { 170 if ($field == 'M') 171 { 172 if (!is_numeric($fields[$n])) 173 { 174 $partcial_match = 0; 175 for($i = 1; $i <= 12; $i++) 176 { 177 $long_name = lang(adodb_date('F',mktime(12,0,0,$i,1,2000))); 178 $short_name = lang(adodb_date('M',mktime(12,0,0,$i,1,2000))); // do we have a translation of the short-cut 179 if (substr($short_name,-1) == '*') // if not generate one by truncating the translation of the long name 180 { 181 $short_name = substr($long_name,0,(int) lang('3 number of chars for month-shortcut')); 182 } 183 //echo "<br>checking '".$fields[$n]."' against '$long_name' or '$short_name'"; 184 if ($fields[$n] == $long_name || $fields[$n] == $short_name) 185 { 186 //echo " ==> OK<br>"; 187 $fields[$n] = $i; 188 break; 189 } 190 if (strstr($long_name,$fields[$n]) == $long_name) // partcial match => multibyte saver 191 { 192 $partcial_match = $i; 193 } 194 } 195 if ($i > 12 && $partcial_match) // nothing found, but a partcial match 196 { 197 $fields[$n] = $partcial_match; 198 } 199 } 200 $field = 'm'; 201 } 202 $date[$field] = (int)$fields[$n]; 203 } 204 $ret = array( 205 $year => $date['Y'], 206 $month => $date['m'], 207 $day => $date['d'] 208 ); 209 if ($raw) 210 { 211 $ret[$raw] = adodb_mktime(12,0,0,$date['m'],$date['d'],$date['Y']); 212 } 213 //echo "<p>jscalendar::input2date('$datestr','$raw',$day','$month','$year') = "; print_r($ret); echo "</p>\n"; 214 215 return $ret; 216 } 217 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |