diff --git a/calendar/sitemgr/class.module_calendar.inc.php b/calendar/sitemgr/class.module_calendar.inc.php index 71da257f55..ef5d88202e 100644 --- a/calendar/sitemgr/class.module_calendar.inc.php +++ b/calendar/sitemgr/class.module_calendar.inc.php @@ -1,16 +1,17 @@ + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @version $Id$ + */ +/** + * Calendar day selection for sitemgr + */ class module_calendar extends Module { function module_calendar() @@ -28,12 +29,10 @@ class module_calendar extends Module function get_content(&$arguments,$properties) { - if (!is_object($GLOBALS['egw']->jscalendar)) - { - $GLOBALS['egw']->jscalendar =& CreateObject('phpgwapi.jscalendar'); - } $date = (int) (strtotime(get_var('date',array('POST','GET')))); $redirect = $arguments['redirect'] ? $arguments['redirect'] : '#'; - return $GLOBALS['egw']->jscalendar->flat($redirect,$date); + + return $GLOBALS['egw']->jscalendar->get_javascript(). + $GLOBALS['egw']->jscalendar->flat($redirect,$date); } } diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index e43830b1da..d0a2e07459 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -1048,9 +1048,15 @@ abstract class egw_framework /** * Checks to make sure a valid package and file name is provided * - * @param string $package package to be included - * @param string $file file to be included - no ".js" on the end - * @param string $app application directory to search - default = phpgwapi + * Example call syntax: + * a) egw_framework::validate_file('jscalendar','calendar') + * --> /phpgwapi/js/jscalendar/calendar.js + * b) egw_framework::validate_file('/phpgwapi/inc/calendar-setup.js',array('lang'=>'de')) + * --> /phpgwapi/inc/calendar-setup.js?lang=de + * + * @param string $package package or complete path (relative to EGW_SERVER_ROOT) to be included + * @param string|array $file=null file to be included - no ".js" on the end or array with get params + * @param string $app='phpgwapi' application directory to search - default = phpgwapi * @param boolean $append=true should the file be added * * @discuss The browser specific option loads the file which is in the correct @@ -1058,18 +1064,28 @@ abstract class egw_framework * * @returns bool was the file found? */ - static function validate_file($package, $file, $app='phpgwapi') + static function validate_file($package, $file=null, $app='phpgwapi') { //echo "
".__METHOD__."($package,$file,$app) --> ".EGW_INCLUDE_ROOT ."/$app/js/$package/$file.js
\n"; - if (is_readable(EGW_INCLUDE_ROOT.($path="/$app/js/$package/$file.js")) || - $app != 'phpgwapi' && is_readable(EGW_INCLUDE_ROOT.($path="/phpgwapi/js/$package/$file.js"))) + if ($package[0] == '/' && is_readable(EGW_SERVER_ROOT.($path = $package)) || + is_readable(EGW_SERVER_ROOT.($path="/$app/js/$package/$file.js")) || + $app != 'phpgwapi' && is_readable(EGW_SERVER_ROOT.($path="/phpgwapi/js/$package/$file.js"))) { + if (is_array($file)) + { + foreach($file as $name => $val) + { + $args .= (empty($args) ? '?' : '&').$name.'='.urlencode($val); + } + $path .= $args; + } if (!self::$js_include_files || !in_array($path,self::$js_include_files)) { self::$js_include_files[] = $path; } return True; } + error_log(__METHOD__."($package,$file,$app) $path NOT found!"); return False; } @@ -1103,7 +1119,8 @@ abstract class egw_framework { foreach(self::$js_include_files as $file) { - $file .= '?'. filectime(EGW_INCLUDE_ROOT.$file); + list($file,$params) = explode('?',$file,2); + $file .= '?'. filectime(EGW_INCLUDE_ROOT.$file).($params ? '&'.$params : ''); $links .= '\n"; } } @@ -1120,23 +1137,27 @@ abstract class egw_framework /** * Include a css file, either speicified by it's path (relative to EGW_SERVER_ROOT) or appname and css file name * - * @param string $path path (relative to EGW_SERVER_ROOT) or appname (if !is_null($name)) + * @param string $app path (relative to EGW_SERVER_ROOT) or appname (if !is_null($name)) * @param string $name=null name of css file in $app/templates/{default|$this->template}/$name.css * @return boolean false: css file not found, true: file found */ - public static function includeCSS($path,$name=null) + public static function includeCSS($app,$name=null) { if (!is_null($name)) { - $app = basename($path); $path = '/'.$app.'/templates/'.$GLOBALS['egw_info']['server']['template_set'].'/'.$name.'.css'; if (!file_exists(EGW_SERVER_ROOT.$path)) { $path = '/'.$app.'/templates/default/'.$name.'.css'; } } + else + { + $path = $app; + } if (!file_exists(EGW_SERVER_ROOT.$path)) { + error_log(__METHOD__."($app,$name) $path NOT found!"); return false; } if (!in_array($path,self::$css_include_files)) @@ -1145,6 +1166,33 @@ abstract class egw_framework } return true; } + + /** + * Add registered CSS and javascript to ajax response + */ + public static function include_css_js_response() + { + $response = egw_json_response::get(); + $app = $GLOBALS['egw_info']['flags']['currentapp']; + + // try to add app specific css file + self::includeCSS($app,'app'); + + // add all css files from egw_framework::includeCSS() + foreach(self::$css_include_files as $path) + { + $response->includeCSS($GLOBALS['egw_info']['server']['webserver_url'].$path); + } + + // try to add app specific js file + self::validate_file('.', 'app', $app); + + // add all js files from egw_framework::validate_file() + foreach(self::$js_include_files as $path) + { + $response->includeScript($GLOBALS['egw_info']['server']['webserver_url'].$path); + } + } } /** diff --git a/phpgwapi/inc/class.jscalendar.inc.php b/phpgwapi/inc/class.jscalendar.inc.php index 3fd66e3ea6..8728770516 100644 --- a/phpgwapi/inc/class.jscalendar.inc.php +++ b/phpgwapi/inc/class.jscalendar.inc.php @@ -51,24 +51,29 @@ class jscalendar { $args['app'] = 'home'; // home can be granted to anyone. } - if ($do_header && (strpos($GLOBALS['egw_info']['flags']['java_script'],'jscalendar')===false)) + if ($do_header) { - $GLOBALS['egw_info']['flags']['java_script'] .= $this->get_javascript(); + egw_framework::includeCSS('/phpgwapi/js/jscalendar/calendar-blue.css'); + egw_framework::validate_file('jscalendar','calendar'); + $args = array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'],array('lang'=>1,'dateformat'=>1)); + egw_framework::validate_file('/phpgwapi/inc/jscalendar-setup.php',$args); } } - /** + /** * return javascript needed for jscalendar - * - * @return string - */ - function get_javascript() - { - $args = array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'],array('lang'=>1,'dateformat'=>1)); - return -' - - + * + * Only needed if jscalendar runs outside of egw_framework, eg. in sitemgr + * + * @return string + */ + function get_javascript() + { + $args = array_intersect_key($GLOBALS['egw_info']['user']['preferences']['common'],array('lang'=>1,'dateformat'=>1)); + return +' + + '; } @@ -161,10 +166,6 @@ class jscalendar */ function flat($url,$date=null,$weekUrl='',$weekTTip='',$monthUrl='',$monthTTip='',$id='calendar-container') { - if (strpos($GLOBALS['egw_info']['flags']['java_script'],'jscalendar') === false) - { - $javascript = $this->get_javascript(); - } if ($date) // string if format YYYYmmdd or timestamp { $date = is_int($date) ? adodb_date('m/d/Y',$date) : @@ -172,7 +173,6 @@ class jscalendar } return ' -'.$javascript.'