- change jscalendar-setup url to include lang&dateformat, to force the browser to reload the file, if the user changes his prefs (we had a lot of bug-reports about not working jscal because of this in the past, maybe this should be commited to 1.2 too)

- documentation update
This commit is contained in:
Ralf Becker 2006-09-12 11:51:02 +00:00
parent cd69f5bb27
commit ab05b3eef6

View File

@ -1,31 +1,62 @@
<?php
/**************************************************************************\
* eGroupWare - API jsCalendar wrapper-class *
* http://www.eGroupWare.org *
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
/*!
@class jscalendar
@author ralfbecker
@abstract wrapper for the jsCalendar
@discussion the constructor load the necessary javascript-files
/**
* generates html with methods representing html-tags or higher widgets
*
* @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$
*/
class jscalendar
{
/*!
@function jscalendar
@syntax jscalendar( $do_header=True )
@author ralfbecker
@abstract constructor of the class
@param $do_header if true, necessary javascript and css gets loaded, only needed for input
/**************************************************************************\
* eGroupWare - API jsCalendar wrapper-class *
* http://www.eGroupWare.org *
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
/*!
@class jscalendar
@author ralfbecker
@abstract wrapper for the jsCalendar
@discussion the constructor load the necessary javascript-files
*/
/**
* Wrapper for the jsCalendar
*
* The constructor load the necessary javascript-files.
*
* @package api
* @subpackage html
* @access public
*/
class jscalendar
{
/**
* url to the jscalendar files
*
* @var string
*/
var $jscalendar_url;
/**
* dateformat from the user-prefs
*
* @var string
*/
var $dateformat;
/**
* Constructor
*
* @param boolean $do_header=true if true, necessary javascript and css gets loaded, only needed for input
* @param string $path='jscalendar'
* @return jscalendar
*/
function jscalendar($do_header=True,$path='jscalendar')
{
@ -37,21 +68,24 @@
$GLOBALS['egw_info']['flags']['java_script'] .=
'<link rel="stylesheet" type="text/css" media="all" href="'.$this->jscalendar_url.'/calendar-blue.css" title="blue" />
<script type="text/javascript" src="'.$this->jscalendar_url.'/calendar.js"></script>
<script type="text/javascript" src="'.ereg_replace('[?&]*click_history=[0-9a-f]*','',$GLOBALS['egw']->link('/phpgwapi/inc/jscalendar-setup.php')).'"></script>
<script type="text/javascript" src="'.$GLOBALS['egw']->link('/phpgwapi/inc/jscalendar-setup.php',
array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'],array('lang'=>1,'dateformat'=>1))).'"></script>
';
}
}
/*!
@function input
@syntax input( $name,$date,$year=0,$month=0,$day=0 )
@author ralfbecker
@abstract creates an inputfield for the jscalendar (returns the necessary html and js)
@param $name name and id of the input-field (it also names the id of the img $name.'-toggle')
@param $date date as string or unix timestamp (in server timezone)
@param $year,$month,$day if $date is not used
@param $helpmsg a helpmessage for the statusline of the browser
@param $options any other options to the inputfield
/**
* Creates an inputfield for the jscalendar (returns the necessary html and js)
*
* @param string $name name and id of the input-field (it also names the id of the img $name.'-toggle')
* @param int/string $date date as string or unix timestamp (in server timezone)
* @param int $year=0 if $date is not used
* @param int $month=0 if $date is not used
* @param int $day=0 if $date is not used
* @param string $helpmsg='' a helpmessage for the statusline of the browser
* @param string $options='' any other options to the inputfield
* @param boolean $jsreturn=false
* @return string html
*/
function input($name,$date,$year=0,$month=0,$day=0,$helpmsg='',$options='',$jsreturn=false)
{
@ -94,18 +128,30 @@
return
'<input type="text" id="'.$name.'" name="'.$name.'" size="10" value="'.$date.'"'.$options.'/>
<script type="text/javascript">
document.writeln(\'<img id="'.$name.'-trigger" src="'.$GLOBALS['egw']->common->find_image('phpgwpai','datepopup').'" title="'.lang('Select date').'" style="cursor:pointer; cursor:hand;"/>\');
Calendar.setup(
{
document.writeln(\'<img id="'.$name.'-trigger" src="'.$GLOBALS['egw']->common->find_image('phpgwpai','datepopup').'" title="'.lang('Select date').'" style="cursor:pointer; cursor:hand;"/>\');
Calendar.setup(
{
inputField : "'.$name.'",
button : "'.$name.'-trigger"
}
);
}
);
</script>
';
}
function flat($url,$date=False,$weekUrl=False,$weekTTip=False,$monthUrl=False,$monthTTip=False,$id='calendar-container')
/**
* Flat jscalendar with tooltips and url's for days, weeks and month
*
* @param string $url url to call if user clicks on a date (&date=YYYYmmdd is appended automatically)
* @param string/int $date=null format YYYYmmdd or timestamp
* @param string $weekUrl=''
* @param string $weekTTip=''
* @param string $monthUrl=''
* @param string $monthTTip=''
* @param string $id='calendar-container'
* @return string html
*/
function flat($url,$date=null,$weekUrl='',$weekTTip='',$monthUrl='',$monthTTip='',$id='calendar-container')
{
if ($date) // string if format YYYYmmdd or timestamp
{
@ -116,26 +162,26 @@
<div id="'.$id.'"></div>
<script type="text/javascript">
function dateChanged(calendar) {
function dateChanged(calendar) {
'. // Beware that this function is called even if the end-user only
// changed the month/year. In order to determine if a date was
// clicked you can use the dateClicked property of the calendar:
// redirect to $url extended with a &date=YYYYMMDD
// changed the month/year. In order to determine if a date was
// clicked you can use the dateClicked property of the calendar:
// redirect to $url extended with a &date=YYYYMMDD
' if (calendar.dateClicked) {
window.location = "'.$url.'&date=" + calendar.date.print("%Y%m%d");
}
};
}
};
'.($weekUrl ? '
function weekClicked(calendar,weekstart) {
function weekClicked(calendar,weekstart) {
window.location = "'.$weekUrl.'&date=" + weekstart.print("%Y%m%d");
}
}
' : '').($monthUrl ? '
function monthClicked(calendar,monthstart) {
function monthClicked(calendar,monthstart) {
window.location = "'.$monthUrl.'&date=" + monthstart.print("%Y%m%d");
}
}
' : '').'
Calendar.setup(
{
Calendar.setup(
{
flat : "'.$id.'",
flatCallback : dateChanged'.($weekUrl ? ',
flatWeekCallback : weekClicked' : '').($weekTTip ? ',
@ -144,18 +190,19 @@
flatMonthTTip : "'.addslashes($monthTTip).'"' : '').($date ? ',
date : "'.$date.'"
' : '').' }
);
);
</script>';
}
/*!
@function input2date
@syntax input2date( $datestr,$raw='raw',$day='day',$month='month',$year='year' )
@author ralfbecker
@abstract converts the date-string back to an array with year, month, day and a timestamp
@param $datestr content of the inputfield generated by jscalendar::input()
@param $raw key of the timestamp-field in the returned array or False of no timestamp
@param $day,$month,$year keys for the array, eg. to set mday instead of day
/**
* Converts the date-string back to an array with year, month, day and a timestamp
*
* @param string $datestr content of the inputfield generated by jscalendar::input()
* @param boolean/string $raw='raw' key of the timestamp-field in the returned array or False of no timestamp
* @param string $day='day' keys for the array, eg. to set mday instead of day
* @param string $month='month' keys for the array
* @param string $year='year' keys for the array
* @return array/boolean array with the specified keys and values or false if $datestr == ''
*/
function input2date($datestr,$raw='raw',$day='day',$month='month',$year='year')
{
@ -214,4 +261,21 @@
return $ret;
}
}
if (!function_exists('array_intersect_key')) // php5.1 function
{
function array_intersect_key($array1,$array2)
{
$intersection = $keys = array();
foreach(func_get_args() as $arr)
{
$keys[] = array_keys((array)$arr);
}
foreach(call_user_func_array('array_intersect',$keys) as $key)
{
$intersection[$key] = $array1[$key];
}
return $intersection;
}
}