trailing spaces
[plewww.git] / plekit / php / datepicker.php
1 <?php
2
3   // $Id$
4
5   // see the demo at http://www.frequency-decoder.com/demo/date-picker-v4/
6
7 drupal_set_html_head('
8 <script type="text/javascript" src="/plekit/datepicker/datepicker.js"></script>
9 <link href="/plekit/datepicker/datepicker.css" rel="stylesheet" type="text/css" />
10 ');
11
12 // supported options
13 // (*) inline (default=true)
14 // (*) format (default 2010/Jan/01), php-equiv. Y/M/d, which in this paradigm translates into Y-sl-m-sl-d
15 // (*) value : the value to display initially - default ''
16
17 class PlekitDatepicker {
18
19   var $id;
20
21   function __construct ($id,$display,$options=NULL) {
22     $datepicker_default_options =
23       array ('inline'=>true,
24              'format'=>'Y-sl-M-sl-d',
25              'value'=>'');
26     if (!$options) $options=array();
27     $this->id=$id;
28     $this->display=$display;
29     $this->options=array_merge($datepicker_default_options,$options);
30
31   }
32
33   function html () {
34     $inline=$this->options['inline'];
35     $format=$this->options['format'];
36     $value=$this->options['value'];
37
38     $html="";
39     $html .= "<label for='$this->id'>$this->display</label>";
40     $html .= "<input size=13 type='text'";
41     $html .= " class='dateformat-$format";
42     $html .= " opacity-60";
43     if ($inline) $html .= " display-inline";
44     $html .= "' id='$this->id' name='$this->id' value='$value' />";
45     return $html;
46   }
47
48   function today () {
49     // works for default format only for now
50     $this->options['value']=date('Y/M/d');
51   }
52
53 }