[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/phpgwapi/inc/ -> jscalendar-setup.php (source)

   1  <?php
   2  /**************************************************************************\
   3  * eGroupWare - API jsCalendar setup (set up jsCalendar with user prefs)    *
   4  * http://www.eGroupWare.org                                                *
   5  * Modified by Ralf Becker <RalfBecker@outdoor-training.de>                 *
   6  * This file is derived from jscalendar's calendar-setup.js file and the    *
   7  * english translation in lang/calendar-en.js.                              *
   8  * --------------------------------------------                             *
   9  *  This program is free software; you can redistribute it and/or modify it *
  10  *  under the terms of the GNU General Public License as published by the   *
  11  *  Free Software Foundation; either version 2 of the License, or (at your  *
  12  *  option) any later version.                                              *
  13  \**************************************************************************/
  14  
  15  /* $Id: jscalendar-setup.php 22182 2006-07-31 19:43:46Z ralfbecker $ */
  16  
  17  $GLOBALS['egw_info'] = array(
  18      'flags' => Array(
  19          'currentapp'  => 'home',        // can't be phpgwapi, nor jscalendar (no own directory)
  20          'noheader'    => True,
  21          'nonavbar'    => True,
  22          'noappheader' => True,
  23          'noappfooter' => True,
  24          'nofooter'    => True,
  25          'nocachecontrol' => True            // allow cacheing
  26      )
  27  );
  28  
  29  include('../../header.inc.php');
  30  
  31  header('Content-type: text/javascript; charset='.$GLOBALS['egw']->translation->charset());
  32  $GLOBALS['egw']->translation->add_app('jscalendar');
  33  
  34  $dateformat = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
  35  if (empty($dateformat)) $dateformat = 'Y-m-d';
  36  $jsDateFormat = str_replace(array('Y','d','m','M'),array('%Y','%d','%m','%b'),$dateformat);
  37  $dayFirst = strpos($dateformat,'d') < strpos($dateformat,'m');
  38  $jsLongDateFormat = '%a, '.($dayFirst ? '%e' : '%b').($dateformat[1] == '.' ? '. ' : ' ').($dayFirst ? '%b' : '%e');
  39  
  40  /*  Copyright Mihai Bazon, 2002, 2003  |  http://dynarch.com/mishoo/
  41   * ---------------------------------------------------------------------------
  42   *
  43   * The DHTML Calendar
  44   *
  45   * Details and latest version at:
  46   * http://dynarch.com/mishoo/calendar.epl
  47   *
  48   * This script is distributed under the GNU Lesser General Public License.
  49   * Read the entire license text here: http://www.gnu.org/licenses/lgpl.html
  50   *
  51   * This file defines helper functions for setting up the calendar.  They are
  52   * intended to help non-programmers get a working calendar on their site
  53   * quickly.  This script should not be seen as part of the calendar.  It just
  54   * shows you what one can do with the calendar, while in the same time
  55   * providing a quick and simple method for setting it up.  If you need
  56   * exhaustive customization of the calendar creation process feel free to
  57   * modify this code to suit your needs (this is recommended and much better
  58   * than modifying calendar.js itself).
  59   */
  60  
  61  // $Id: jscalendar-setup.php 22182 2006-07-31 19:43:46Z ralfbecker $
  62  
  63  /**
  64   *  This function "patches" an input field (or other element) to use a calendar
  65   *  widget for date selection.
  66   *
  67   *  The "params" is a single object that can have the following properties:
  68   *
  69   *    prop. name   | description
  70   *  -------------------------------------------------------------------------------------------------
  71   *   inputField    | the ID of an input field to store the date
  72   *   displayArea   | the ID of a DIV or other element to show the date
  73   *   button        | ID of a button or other element that will trigger the calendar
  74   *   eventName     | event that will trigger the calendar, without the "on" prefix (default: "click")
  75   *   ifFormat      | date format that will be stored in the input field
  76   *   daFormat      | the date format that will be used to display the date in displayArea
  77   *   titleFormat   | the format to show the month in the title, default '%B, %Y'
  78   *   singleClick   | (true/false) wether the calendar is in single click mode or not (default: true)
  79   *   firstDay      | numeric: 0 to 6.  "0" means display Sunday first, "1" means display Monday first, etc.
  80   *   disableFirstDowChange| (true/false) disables manual change of first day of week
  81   *   align         | alignment (default: "Br"); if you don't know what's this see the calendar documentation
  82   *   range         | array with 2 elements.  Default: [1900, 2999] -- the range of years available
  83   *   weekNumbers   | (true/false) if it's true (default) the calendar will display week numbers
  84   *   flat          | null or element ID; if not null the calendar will be a flat calendar having the parent with the given ID
  85   *   flatCallback  | function that receives a JS Date object and returns an URL to point the browser to (for flat calendar)
  86   *   flatWeekCallback| gets called if a weeknumber get clicked, params are the cal-object and a date-object representing the start of the week
  87   *   flatWeekTTip  | Tooltip for the weeknumber (shown only if flatWeekCallback is set)
  88   *   flatMonthCallback| gets called if a month (title) get clicked, params are the cal-object and a date-object representing the start of the month
  89   *   flatMonthTTip | Tooltip for the month (shown only if flatMonthCallback is set)
  90   *   disableFunc   | function that receives a JS Date object and should return true if that date has to be disabled in the calendar
  91   *   onSelect      | function that gets called when a date is selected.  You don't _have_ to supply this (the default is generally okay)
  92   *   onClose       | function that gets called when the calendar is closed.  [default]
  93   *   onUpdate      | function that gets called after the date is updated in the input field.  Receives a reference to the calendar.
  94   *   date          | the date that the calendar will be initially displayed to
  95   *   showsTime     | default: false; if true the calendar will include a time selector
  96   *   timeFormat    | the time format; can be "12" or "24", default is "12"
  97   *   electric      | if true (default) then given fields/date areas are updated for each move; otherwise they're updated only on close
  98   *   step          | configures the step of the years in drop-down boxes; default: 2
  99   *   position      | configures the calendar absolute position; default: null
 100   *   cache         | if "true" (but default: "false") it will reuse the same calendar object, where possible
 101   *   showOthers    | if "true" (but default: "false") it will show days from other months too
 102   *
 103   *  None of them is required, they all have default values.  However, if you
 104   *  pass none of "inputField", "displayArea" or "button" you'll get a warning
 105   *  saying "nothing to setup".
 106   */
 107  ?>
 108  //<pre>
 109  Calendar.setup = function (params) {
 110  	function param_default(pname, def) { if (typeof params[pname] == "undefined") { params[pname] = def; } };
 111  
 112      param_default("inputField",     null);
 113      param_default("displayArea",    null);
 114      param_default("button",         null);
 115      param_default("eventName",      "click");
 116      param_default("ifFormat",      "<?php /* was "%Y/%m/%d" */ echo $jsDateFormat; ?>");
 117      param_default("daFormat",      "<?php /* was "%Y/%m/%d" */ echo $jsDateFormat; ?>");
 118      param_default("titleFormat",    "%B %Y");
 119      param_default("singleClick",    true);
 120      param_default("disableFunc",    null);
 121      param_default("dateStatusFunc", params["disableFunc"]);    // takes precedence if both are defined
 122      param_default("disableFirstDowChange", true);
 123      param_default("firstDay",       <?php // was 0 defaults to "Sunday" first
 124      $day2int = array('Sunday'=>0,'Monday'=>1,'Tuesday'=>2,'Wednesday'=>3,'Thursday'=>4,'Friday'=>5,'Saturday'=>6);
 125      echo (int) @$day2int[$GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']]; ?>); // <?php echo $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts']."\n"; ?>
 126      param_default("align",          "Bl");
 127      param_default("range",          [1900, 2999]);
 128      param_default("weekNumbers",    true);
 129      param_default("flat",           null);
 130      param_default("flatCallback",   null);
 131      param_default("flatWeekCallback",null);
 132      param_default("flatWeekTTip",   null);
 133      param_default("flatmonthCallback",null);
 134      param_default("flatmonthTTip",  null);
 135      param_default("onSelect",       null);
 136      param_default("onClose",        null);
 137      param_default("onUpdate",       null);
 138      param_default("date",           null);
 139      param_default("showsTime",      false);
 140      param_default("timeFormat",     "<?php /* was 24 */ echo $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] ? $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] : 24; ?>");
 141      param_default("electric",       true);
 142      param_default("step",           2);
 143      param_default("position",       null);
 144      param_default("cache",          true);
 145      param_default("showOthers",     true); <?php /* was false */ ?>
 146  
 147      var tmp = ["inputField", "displayArea", "button"];
 148      for (var i in tmp) {
 149          if (typeof params[tmp[i]] == "string") {
 150              params[tmp[i]] = document.getElementById(params[tmp[i]]);
 151          }
 152      }
 153      if (!(params.flat || params.inputField || params.displayArea || params.button)) {
 154          alert("Calendar.setup:\n  Nothing to setup (no fields found).  Please check your code");
 155          return false;
 156      }
 157  
 158  	function onSelect(cal) {
 159          var p = cal.params;
 160          var update = (cal.dateClicked || p.electric);
 161          if (update && p.flat) {
 162              if (typeof p.flatCallback == "function")
 163                  p.flatCallback(cal);
 164              else
 165                  alert("No flatCallback given -- doing nothing.");
 166              return false;
 167          }
 168          if (update && p.inputField) {
 169              p.inputField.value = cal.date.print(p.ifFormat);
 170              if (typeof p.inputField.onchange == "function")
 171                  p.inputField.onchange();
 172          }
 173          if (update && p.displayArea)
 174              p.displayArea.innerHTML = cal.date.print(p.daFormat);
 175          if (update && p.singleClick && cal.dateClicked)
 176              cal.callCloseHandler();
 177          if (update && typeof p.onUpdate == "function")
 178              p.onUpdate(cal);
 179      };
 180  
 181      if (params.flat != null) {
 182          if (typeof params.flat == "string")
 183              params.flat = document.getElementById(params.flat);
 184          if (!params.flat) {
 185              alert("Calendar.setup:\n  Flat specified but can't find parent.");
 186              return false;
 187          }
 188          var cal = new Calendar(params.firstDay, params.date, params.onSelect || onSelect);
 189          cal.showsTime = params.showsTime;
 190          cal.time24 = (params.timeFormat == "24");
 191          cal.params = params;
 192          cal.weekNumbers = params.weekNumbers;
 193          cal.setRange(params.range[0], params.range[1]);
 194          cal.setDateStatusHandler(params.dateStatusFunc);
 195          cal.showsOtherMonths = params.showOthers;
 196          cal.create(params.flat);
 197          cal.show();
 198          return false;
 199      }
 200  
 201      var triggerEl = params.button || params.displayArea || params.inputField;
 202      triggerEl["on" + params.eventName] = function() {
 203          var dateEl = params.inputField || params.displayArea;
 204          var dateFmt = params.inputField ? params.ifFormat : params.daFormat;
 205          var mustCreate = false;
 206          var cal = window.calendar;
 207          if (!(cal && params.cache)) {
 208              window.calendar = cal = new Calendar(params.firstDay,
 209                                   params.date,
 210                                   params.onSelect || onSelect,
 211                                   params.onClose || function(cal) { cal.hide(); });
 212              cal.showsTime = params.showsTime;
 213              cal.time24 = (params.timeFormat == "24");
 214              cal.weekNumbers = params.weekNumbers;
 215              mustCreate = true;
 216          } else {
 217              if (params.date)
 218                  cal.setDate(params.date);
 219              cal.hide();
 220          }
 221          cal.showsOtherMonths = params.showOthers;
 222          cal.yearStep = params.step;
 223          cal.setRange(params.range[0], params.range[1]);
 224          cal.params = params;
 225          cal.setDateStatusHandler(params.dateStatusFunc);
 226          cal.setDateFormat(dateFmt);
 227          if (mustCreate)
 228              cal.create();
 229          cal.parseDate(dateEl.value || dateEl.innerHTML);
 230          cal.refresh();
 231          if (!params.position)
 232              cal.showAtElement(params.button || params.displayArea || params.inputField, params.align);
 233          else
 234              cal.showAt(params.position[0], params.position[1]);
 235          return false;
 236      };
 237  };
 238  
 239  // eGroupWare translations, are read from the database
 240  
 241  // ** I18N
 242  
 243  // Calendar EN language
 244  // Author: Mihai Bazon, <mishoo@infoiasi.ro>
 245  // Encoding: any
 246  // Distributed under the same terms as the calendar itself.
 247  
 248  Calendar._DN = new Array
 249  (<?php // full day names
 250  foreach($day2int as $name => $n)
 251  {
 252      echo "\n \"".lang($name).'"'.($n < 6 ? ',' : '');
 253  }
 254  ?>);
 255  
 256  Calendar._SDN = new Array
 257  (<?php // short day names
 258  $chars_shortcut = (int) lang('3 number of chars for day-shortcut');        // < 0 to take the chars from the end
 259  foreach($day2int as $name => $n)
 260  {
 261      echo "\n \"".($chars_shortcut > 0 ? substr(lang($name),0,$chars_shortcut) : 
 262          substr(lang($name),$chars_shortcut)).'"'.($n < 6 ? ',' : '');
 263  }
 264  ?>);
 265  Calendar._SDN_len = <?php echo abs((int) lang('3 number of chars for day-shortcut')); ?>;
 266  
 267  Calendar._MN = new Array
 268  (<?php // full month names
 269  $monthnames = array('January','February','March','April','May','June','July','August','September','October','November','December');
 270  foreach($monthnames as $n => $name)
 271  {
 272      echo "\n \"".lang($name).'"'.($n < 11 ? ',' : '');
 273  }
 274  ?>);
 275  
 276  Calendar._SMN = new Array
 277  (<?php // short month names
 278  $monthnames = array('January','February','March','April','May','June','July','August','September','October','November','December');
 279  foreach($monthnames as $n => $name)
 280  {
 281      $short = lang(substr($name,0,3));    // test if our lang-file have a translation for the english short with 3 chars
 282      if (substr($short,-1) == '*')        // else create one by truncating the full translation to x chars
 283      {
 284          $chars_shortcut = (int)lang('3 number of chars for month-shortcut');    // < 0 to take the chars from the end
 285          $short = $chars_shortcut > 0 ? substr(lang($name),0,$chars_shortcut) : substr(lang($name),$chars_shortcut);
 286      }
 287      echo "\n \"".$short.'"'.($n < 11 ? ',' : '');
 288  }
 289  ?>);
 290  Calendar._SMN_len = <?php echo abs((int) lang('3 number of chars for month-shortcut')); ?>;
 291  
 292  // tooltips
 293  Calendar._TT = {};
 294  Calendar._TT["INFO"] = "<?php echo lang('About the calendar'); ?>";
 295  
 296  Calendar._TT["ABOUT"] =
 297  "DHTML Date/Time Selector\n" +
 298  "(c) dynarch.com 2002-2003\n" + // don't translate this this ;-)
 299  "For latest version visit: http://dynarch.com/mishoo/calendar.epl\n" +
 300  "Distributed under GNU LGPL.  See http://gnu.org/licenses/lgpl.html for details." +
 301  "\n\n" +
 302  "<?php echo lang('Date selection:'); ?>\n" +
 303  "<?php echo lang('- Use the %1, %2 buttons to select year','\xab','\xbb'); ?>\n" +
 304  "<?php echo lang('- Use the %1, %2 buttons to select month','" + String.fromCharCode(0x2039) + "','" + String.fromCharCode(0x203a) + "'); ?>\n" +
 305  "<?php echo lang('- Hold mouse button on any of the above buttons for faster selection.'); ?>";
 306  Calendar._TT["ABOUT_TIME"] = "\n\n" +
 307  "<?php echo lang('Time selection:'); ?>\n" +
 308  "<?php echo lang('- Click on any of the time parts to increase it'); ?>\n" +
 309  "<?php echo lang('- or Shift-click to decrease it'); ?>\n" +
 310  "<?php echo lang('- or click and drag for faster selection.'); ?>";
 311  
 312  Calendar._TT["TOGGLE"] = "<?php echo lang('Toggle first day of week'); ?>";
 313  Calendar._TT["PREV_YEAR"] = "<?php echo lang('Prev. year (hold for menu)'); ?>";
 314  Calendar._TT["PREV_MONTH"] = "<?php echo lang('Prev. month (hold for menu)'); ?>";
 315  Calendar._TT["GO_TODAY"] = "<?php echo lang('Go Today'); ?>";
 316  Calendar._TT["NEXT_MONTH"] = "<?php echo lang('Next month (hold for menu)'); ?>";
 317  Calendar._TT["NEXT_YEAR"] = "<?php echo lang('Next year (hold for menu)'); ?>";
 318  Calendar._TT["SEL_DATE"] = "<?php echo lang('Select date'); ?>";
 319  Calendar._TT["DRAG_TO_MOVE"] = "<?php echo lang('Drag to move'); ?>";
 320  Calendar._TT["PART_TODAY"] = " (<?php echo lang('today'); ?>)";
 321  
 322  // the following is to inform that "%s" is to be the first day of week
 323  // %s will be replaced with the day name.
 324  Calendar._TT["DAY_FIRST"] = "<?php echo lang('Display %s first'); ?>";
 325  
 326  // This may be locale-dependent.  It specifies the week-end days, as an array
 327  // of comma-separated numbers.  The numbers are from 0 to 6: 0 means Sunday, 1
 328  // means Monday, etc.
 329  Calendar._TT["WEEKEND"] = "0,6";
 330  
 331  Calendar._TT["CLOSE"] = "<?php echo lang('Close'); ?>";
 332  Calendar._TT["TODAY"] = "<?php echo lang('Today'); ?>";
 333  Calendar._TT["TIME_PART"] = "<?php echo lang('(Shift-)Click or drag to change value'); ?>";
 334  
 335  // date formats
 336  //Calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d";
 337  Calendar._TT["DEF_DATE_FORMAT"] = "<?php echo $jsDateFormat; ?>";
 338  //Calendar._TT["TT_DATE_FORMAT"] = "%a, %b %e";
 339  Calendar._TT["TT_DATE_FORMAT"] = "<?php echo $jsLongDateFormat; ?>";
 340  
 341  Calendar._TT["WK"] = "<?php echo lang('Wk'); ?>";
 342  Calendar._TT["TIME"] = "<?php echo lang('Time'); ?>:";


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7