~budgester/irm/trunk

« back to all changes in this revision

Viewing changes to lib/stdo.class.php

  • Committer: budgester at budgester
  • Date: 2008-03-05 23:14:13 UTC
  • Revision ID: budgester@budgester.com-20080305231413-k5vqfuckfo09ju42
Initial import of IRM codebase

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/******************************************************************************************************
 
3
/  Class SDTO - Simple DateTime Object
 
4
/               A simple way to handle times and dates and to convert between
 
5
/               System and SQL Formats
 
6
/
 
7
/  (C) 2001-2004 Christian Hansel, CVH, chris@cpi-service.com
 
8
/
 
9
/  Distributed under GPL, may be distributed, modified and utilized if Copyright
 
10
/  notice is maintained and manual is provided and author is notified of modifications
 
11
/
 
12
/  Please support our development by sending remarks or comments or suggestions
 
13
/
 
14
/********************************************************************************************************/
 
15
 
 
16
class SimpleDateTimeObject {
 
17
     var $basetime;            // @private - holds UniX Timestamp
 
18
     var $calctime;            // @private - holds UniX Timestamp Calculations
 
19
     var $stdParamDateList;     // @private - holds StandardParameters for Dropdown-lists
 
20
     var $stdParamAdd;        // @private - holds StandardParameters for Adding/Substracting Periods
 
21
 
 
22
    /* Constructor */
 
23
    function SimpleDateTimeObject ($timestamp = -1) {
 
24
        $this->basetime = ($timestamp == -1) ? mktime() : $timestamp;
 
25
        $this->calctime = $this->basetime;
 
26
        $this->stdParamDateList = array( "start"     => 0,
 
27
                                         "run"         => 5,
 
28
                                         "steps"     => 1,
 
29
                                         "running"    =>"days",
 
30
                                         "format"    =>"d.M.Y H:i",
 
31
                                         "keyformat" => "" ,
 
32
                                         "style" => "");
 
33
 
 
34
        $this->stdParamAdd         = array( "years"=>0,
 
35
                                         "months"=>0,
 
36
                                         "days"=>0,
 
37
                                         "hours"=>0,
 
38
                                         "minutes"=>0,
 
39
                                         "seconds"=>0);
 
40
    }
 
41
 
 
42
 
 
43
 
 
44
    /****************************************************************************************************
 
45
    /   @public Time2Array -
 
46
    /                  Helper Function which Transforms a Time-String
 
47
    /                in SQL Format into an Array of Periods
 
48
    /    Parameters    $timestring - e.g. "-01:00:00)
 
49
    /
 
50
    /********************************************************************************************************/
 
51
 
 
52
 
 
53
    function Time2Array($timestring) {
 
54
        $timestring = preg_replace("#\s#","",$timestring);
 
55
        $timestring = preg_replace("#\:#","",$timestring);
 
56
        $timestring = preg_replace("#\.#","",$timestring);
 
57
        $timestring = preg_replace("#\-#","",$timestring);
 
58
        $timestring = preg_replace("#\/#","",$timestring);
 
59
        $fac = ("-" == substr($timestring,0,1)) ? -1 : 1;
 
60
 
 
61
        $timestring = ("-" == substr($timestring,0,1) || "+" == substr($timestring,0,1)) ? substr($timestring,1,strlen($timestring)-1) : $timestring;
 
62
 
 
63
        $array['hours']     = $fac * substr($timestring, 0,2);
 
64
        $array['minutes']     = $fac * substr($timestring, 2,2) ;
 
65
        $array['seconds']     = (4 < strlen($timestring)) ? $fac * substr($timestring, 4,2) : 0;
 
66
        return $array;
 
67
    }
 
68
 
 
69
 
 
70
    /****************************************************************************************************
 
71
    /   @public DateTime2Array -
 
72
    /                  Helper Function which Transforms a DateTime-String
 
73
    /                in SQL Format into an Array of Periods
 
74
    /    Parameters    $timestring - e.g. "12.01.2004 23:00:00)
 
75
    /
 
76
    /********************************************************************************************************/
 
77
    function DateTime2Array($timestring) {
 
78
        $timestring = preg_replace("#\s#","",$timestring);
 
79
        $timestring = preg_replace("#\:#","",$timestring);
 
80
        $timestring = preg_replace("#\.#","",$timestring);
 
81
        $timestring = preg_replace("#\/#","",$timestring);
 
82
        $timestring = preg_replace("#\-#","",$timestring);
 
83
        $fac = ("-" == substr($timestring,0,1)) ? -1 : 1;
 
84
        $timestring = ("-" == substr($timestring,0,1)) ? substr($timestring,1,strlen($timestring)-1) : $timestring;
 
85
 
 
86
        $array['years']     = (6==strlen($timestamp)) ? $fac * substr($timestamp,0,2): $fac * substr($timestamp,0,4);
 
87
        $array['months']     = (6==strlen($timestamp)) ? $fac * substr($timestamp,2,2): $fac * substr($timestamp,4,2);
 
88
        $array['days']        = (6==strlen($timestamp)) ? $fac * substr($timestamp,4,2): $fac * substr($timestamp,6,2);
 
89
        $array['hours']     = (12 > strlen($timestamp)) ? 0 : $fac * substr($timestamp, 8,2);
 
90
        $array['minutes']     = (12 > strlen($timestamp)) ? 0 : $fac * substr($timestamp, 10,2);
 
91
        $array['seconds']     = (14 > strlen($timestamp)) ? 0 : $fac * substr($timestamp, 12,2);
 
92
        return $array;
 
93
    }
 
94
 
 
95
 
 
96
 
 
97
    /****************************************************************************************************
 
98
    /   @public add -
 
99
    /                  Adds a Period to the BaseTime of the Object
 
100
    /                Returns a Unix Timestamp
 
101
    /    Parameters    $param [Array]- e.g.array("days"=>2, "months"=> 1, "hours"=>4)
 
102
    /                optional $overwrite [Bool] = true - If true the BaseTime of the
 
103
    /                                                    Object will be overwritten with
 
104
    /                                                    or adjusted to the calculated result
 
105
    /
 
106
    /********************************************************************************************************/
 
107
    function add($param = array(), $overwrite = true) {
 
108
        $base_day = date ("d",$this->basetime);
 
109
        $base_month = date ("m",$this->basetime);
 
110
        $base_year = date ("Y",$this->basetime);
 
111
        $base_hour = date ("H",$this->basetime);
 
112
        $base_minute = date ("i",$this->basetime);
 
113
        $base_second = date ("s",$this->basetime);
 
114
 
 
115
        $hours = (isset($param['hours']) && ! empty($param['hours'])) ? $param['hours'] : $this->stdParamAdd['hours'];
 
116
        $minutes = (isset($param['minutes']) && ! empty($param['minutes'])) ? $param['minutes'] : $this->stdParamAdd['minutes'];
 
117
        $seconds = (isset($param['seconds']) && ! empty($param['seconds'])) ? $param['seconds'] : $this->stdParamAdd['seconds'];
 
118
        $days = (isset($param['days']) && ! empty($param['days'])) ? $param['days'] : $this->stdParamAdd['days'];
 
119
        $months = (isset($param['months']) && ! empty($param['months'])) ? $param['months'] : $this->stdParamAdd['months'];
 
120
        $years = (isset($param['years']) && ! empty($param['years'])) ? $param['years'] : $this->stdParamAdd['years'];
 
121
 
 
122
 
 
123
        $this->calctime = mktime ( $base_hour      +     $hours,
 
124
                        $base_minute +     $minutes,
 
125
                        $base_second +     $seconds,
 
126
                        $base_month  +     $months,
 
127
                        $base_day      +     $days,
 
128
                        $base_year      +     $years);
 
129
        if ($overwrite) {
 
130
            $this->basetime = $this->calctime;
 
131
        }
 
132
 
 
133
 
 
134
 
 
135
 
 
136
        return $this->calctime;
 
137
 
 
138
    }
 
139
 
 
140
 
 
141
    /****************************************************************************************************
 
142
    /   @public sub -
 
143
    /                  Subtracts a Period from the BaseTime of the Object
 
144
    /                Returns a Unix Timestamp
 
145
    /    Parameters    $param [Array]- e.g.array("days"=>2, "months"=> 1, "hours"=>4)
 
146
    /                optional $overwrite [Bool] = true - If true the BaseTime of the
 
147
    /                                                    Object will be overwritten with
 
148
    /                                                    or adjusted to the calculated result
 
149
    /
 
150
    /********************************************************************************************************/
 
151
    function sub($param = array(), $overwrite = true) {
 
152
        $base_day = date ("d",$this->basetime);
 
153
        $base_month = date ("m",$this->basetime);
 
154
        $base_year = date ("Y",$this->basetime);
 
155
        $base_hour = date ("H",$this->basetime);
 
156
        $base_minute = date ("i",$this->basetime);
 
157
        $base_second = date ("s",$this->basetime);
 
158
 
 
159
        $hours = (isset($param['hours']) && ! empty($param['hours'])) ? $param['hours'] : $this->stdParamAdd['hours'];
 
160
        $minutes = (isset($param['minutes']) && ! empty($param['minutes'])) ? $param['minutes'] : $this->stdParamAdd['minutes'];
 
161
        $seconds = (isset($param['seconds']) && ! empty($param['seconds'])) ? $param['seconds'] : $this->stdParamAdd['seconds'];
 
162
        $days = (isset($param['days']) && ! empty($param['days'])) ? $param['days'] : $this->stdParamAdd['days'];
 
163
        $months = (isset($param['months']) && ! empty($param['months'])) ? $param['months'] : $this->stdParamAdd['months'];
 
164
        $years = (isset($param['years']) && ! empty($param['years'])) ? $param['years'] : $this->stdParamAdd['years'];
 
165
 
 
166
 
 
167
        $this->calctime = mktime ( $base_hour     -     $hours,
 
168
                        $base_minute -     $minutes,
 
169
                        $base_second -     $seconds,
 
170
                        $base_month  -     $months,
 
171
                        $base_day      -     $days,
 
172
                        $base_year      -     $years);
 
173
        if ($overwrite) {
 
174
            $this->basetime = $this->calctime;
 
175
        }
 
176
 
 
177
 
 
178
 
 
179
 
 
180
        return $this->calctime;
 
181
 
 
182
    }
 
183
 
 
184
 
 
185
 
 
186
    /****************************************************************************************************
 
187
    /   @public  diff_MySQL -
 
188
    /                  Calculates the Difference between a MYSQL Timestamp
 
189
    /                and the Objects Basetime which is useful for SQL commands
 
190
    /                like "SELECT DAT_ADD(mydate, INTERVAL '10 02' DAY_HOUR)
 
191
    /                or to be used in PHP/HTML : print "The time you have to do this job is ".$result['days'];
 
192
    /            returns an array like Array {     "years" => 1 ,
 
193
    /                                            "weeks" => 5 ,
 
194
    /                                            "days"  => 3 ,
 
195
    /                                            "hours" => 0,
 
196
    /                                            "minutes"  => 35 ,
 
197
    /                                            "days"  => 0 }
 
198
    /            when the Parameter $timestring lies 1 year and 5 weeks and 3 days and 35 minutes after
 
199
    /            the Basetime of the Object                                        }
 
200
    /    Parameters    $timestring - A MysQL Dat/DateTime String : e.g. "20040711132712"
 
201
    /                 $allow_negative    -  if true negative Differences will be returned as such
 
202
    /                                    otherwise differences are always positive
 
203
    /
 
204
    /********************************************************************************************************/
 
205
 
 
206
    function diff_MySQL($timestring, $allow_negative = false) {
 
207
        $basetime = $this->basetime;        // 2BRemembered
 
208
        $target = $this->setMySQLDateTime($timestring);
 
209
        if ($target > $basetime) {
 
210
            $diff = $target - $basetime ;
 
211
            $fac = 1;
 
212
        } else {
 
213
            $diff = $basetime-$target;
 
214
            $fac = ($allow_negative)? -1 : 1;
 
215
        }
 
216
        $diffarr['years'] = $fac * $this->extract_from_seconds($diff,"years");
 
217
        $diffarr['weeks'] =  $fac * $this->extract_from_seconds($diff,"weeks");
 
218
        $diffarr['days'] =  $fac * $this->extract_from_seconds($diff,"days");
 
219
        $diffarr['hours'] =  $fac * $this->extract_from_seconds($diff,"hours");
 
220
        $diffarr['minutes'] =  $fac * $this->extract_from_seconds($diff,"minutes");
 
221
        $diffarr['seconds'] =  $fac * $this->extract_from_seconds($diff,"seconds");
 
222
        $this->basetime = $basetime;
 
223
 
 
224
        return $diffarr;
 
225
    }
 
226
 
 
227
 
 
228
    /****************************************************************************************************
 
229
    /   @private / public   extract_from_seconds -
 
230
    /                  extracts full years / days / weeks / hours / or minutes from a Unix Timestamp a
 
231
    /                any period given seconds
 
232
    /            returns an integer of the time unit provided as parameter 2 (e.g. 'hours')
 
233
    /    Parameters    $seconds !!!ByRef!!!     - An integer of seconds
 
234
    /                $what (String)            - What shall be extracted ("hours"/"minutes"/"days"/"weeks"/"years")
 
235
    /
 
236
    /
 
237
    /********************************************************************************************************/
 
238
 
 
239
    function extract_from_seconds(&$seconds,$what) {
 
240
    switch ($what) {
 
241
        case "minutes":    case "minutes": case "minutes": case "i":
 
242
            $value = bcdiv($seconds,60);
 
243
            $seconds =  bcmod($seconds,60);
 
244
            break;
 
245
        case "hours": case "H": case "h": case "hour":
 
246
            $value = bcdiv($seconds,3600);
 
247
            $seconds =  bcmod($seconds,3600);
 
248
            break;
 
249
        case "days": case "D": case "d": case "day":
 
250
            $value         = bcdiv($seconds,3600*24);
 
251
            $seconds     = bcmod($seconds,3600*24);
 
252
            break;
 
253
        case "weeks": case "W": case "w": case "week":
 
254
            $value         = bcdiv($seconds,3600*24*7);
 
255
            $seconds     = bcmod($seconds,3600*24*7);
 
256
            break;
 
257
        case "years": case "year": case "y": case "Y":
 
258
            $value         = bcdiv($seconds,3600*24*365);
 
259
            $seconds     = bcmod($seconds,3600*24*365);
 
260
            break;
 
261
        default:
 
262
            $value = $seconds;
 
263
    }
 
264
    return $value;
 
265
 
 
266
    }
 
267
 
 
268
 
 
269
 
 
270
    /****************************************************************************************************
 
271
    /   @private / public   reset -
 
272
    /                  resets the Object's basetime to the current Systemtime
 
273
    /
 
274
    /
 
275
    /********************************************************************************************************/
 
276
 
 
277
    function reset() {
 
278
        $this->DateTimeObject(mktime());
 
279
    }
 
280
 
 
281
 
 
282
 
 
283
    /****************************************************************************************************
 
284
    /   @public   setMySQLDateTime($timestamp) -
 
285
    /                  Sets the Object's base time to the time provided by Timestring
 
286
    /                return Unix timestamp equivilant
 
287
    /    Parameters : $timestring =     String of MySQL DateTime (e.g ("20010911091200") or "2001-09-11 09:12:00")
 
288
    /
 
289
    /
 
290
    /********************************************************************************************************/
 
291
 
 
292
    function setMySQLDateTime($timestring) {
 
293
        $timestring .="";
 
294
        $timestring = preg_replace("#\s#","",$timestring);
 
295
        $timestring = preg_replace("#\:#","",$timestring);
 
296
        $timestring = preg_replace("#\.#","",$timestring);
 
297
        $timestring = preg_replace("#\-#","",$timestring);
 
298
        $timestring = preg_replace("#\/#","",$timestring);
 
299
        $year     = (6==strlen($timestring)) ? substr($timestring,0,2): substr($timestring,0,4);
 
300
        $month     = (6==strlen($timestring)) ? substr($timestring,2,2): substr($timestring,4,2);
 
301
        $day     = (6==strlen($timestring)) ? substr($timestring,4,2): substr($timestring,6,2);
 
302
        $hour     = (12 > strlen($timestring)) ? 0 : substr($timestring, 8,2);
 
303
        $minute = (12 > strlen($timestring)) ? 0 : substr($timestring, 10,2);
 
304
        $second = (14 > strlen($timestring)) ? 0 : substr($timestring, 12,2);
 
305
 
 
306
        $this->SimpleDateTimeObject(mktime($hour,$minute,$second,$month, $day,$year));
 
307
        return $this->getTimestamp();
 
308
    }
 
309
 
 
310
 
 
311
 
 
312
    /****************************************************************************************************
 
313
    /   @public   getMySQLDateTime() -
 
314
    /                  Returns the Object's base time in preset MySQLFormat "YmdHis"
 
315
    /
 
316
    /
 
317
    /
 
318
    /********************************************************************************************************/
 
319
    function getMySQLDateTime(){
 
320
        return date("YmdHis",$this->basetime);
 
321
    }
 
322
 
 
323
 
 
324
    /****************************************************************************************************
 
325
    /    @public   getTimestamp() -
 
326
    /                  Returns the Object's base time as Unix TimeStamp
 
327
    /
 
328
    /
 
329
    /
 
330
    /********************************************************************************************************/
 
331
    function getTimestamp() {
 
332
        return $this->basetime;
 
333
    }
 
334
 
 
335
 
 
336
    /****************************************************************************************************
 
337
    /   @public   day() -
 
338
    /                  Returns the Day of the Object's base time
 
339
    /    Paramters optional $format - specify the format of the returned value
 
340
    /                                 according to the allowed Format Strings of
 
341
    /                                 PHP 's own date command
 
342
    /             optional $timestamp - specify a time of which a part shall be returned
 
343
    /                                   if not specified the Objects BaseTime will be used
 
344
    /
 
345
    /
 
346
    /********************************************************************************************************/
 
347
 
 
348
    function day( $format = "d", $timestamp = 0) {
 
349
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
350
        } else {return date ($format,$timestamp);}
 
351
    }
 
352
    /****************************************************************************************************
 
353
    /   @public   month() -
 
354
    /                  Returns the Month of the Object's base time
 
355
    /    Paramters optional $format - specify the format of the returned value
 
356
    /                                 according to the allowed Format Strings of
 
357
    /                                 PHP 's own date command
 
358
    /             optional $timestamp - specify a time of which a part shall be returned
 
359
    /                                   if not specified the Objects BaseTime will be used
 
360
    /
 
361
    /
 
362
    /********************************************************************************************************/
 
363
    function month ( $format = "m", $timestamp = 0) {
 
364
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
365
        } else {return date ($format,$timestamp);}
 
366
    }
 
367
    /****************************************************************************************************
 
368
    /   @public  year() -
 
369
    /                  Returns the Year of the Object's base time
 
370
    /    Paramters optional $format - specify the format of the returned value
 
371
    /                                 according to the allowed Format Strings of
 
372
    /                                 PHP 's own date command
 
373
    /             optional $timestamp - specify a time of which a part shall be returned
 
374
    /                                   if not specified the Objects BaseTime will be used
 
375
    /
 
376
    /
 
377
    /********************************************************************************************************/
 
378
    function year ( $format = "Y", $timestamp = 0) {
 
379
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
380
        } else {return date ($format,$timestamp);}
 
381
    }
 
382
    /****************************************************************************************************
 
383
    /   @public  hour() -
 
384
    /                  Returns the hour of the Object's base time
 
385
    /    Paramters optional $format - specify the format of the returned value
 
386
    /                                 according to the allowed Format Strings of
 
387
    /                                 PHP 's own date command
 
388
    /             optional $timestamp - specify a time of which a part shall be returned
 
389
    /                                   if not specified the Objects BaseTime will be used
 
390
    /
 
391
    /
 
392
    /********************************************************************************************************/
 
393
    function hour ( $format = "H", $timestamp = 0) {
 
394
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
395
        } else {return date ($format,$timestamp);}
 
396
    }
 
397
    /****************************************************************************************************
 
398
    /   @public  minute() -
 
399
    /                  Returns the Minutes of the Object's base time
 
400
    /    Paramters optional $format - specify the format of the returned value
 
401
    /                                 according to the allowed Format Strings of
 
402
    /                                 PHP 's own date command
 
403
    /             optional $timestamp - specify a time of which a part shall be returned
 
404
    /                                   if not specified the Objects BaseTime will be used
 
405
    /
 
406
    /
 
407
    /********************************************************************************************************/
 
408
    function minute ( $format = "i", $timestamp = 0) {
 
409
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
410
        } else {return date ($format,$timestamp);}
 
411
    }
 
412
    /****************************************************************************************************
 
413
    /   @public  second() -
 
414
    /                  Returns the Seconds of the Object's base time
 
415
    /    Paramters optional $format - specify the format of the returned value
 
416
    /                                 according to the allowed Format Strings of
 
417
    /                                 PHP 's own date command
 
418
    /             optional $timestamp - specify a time of which a part shall be returned
 
419
    /                                   if not specified the Objects BaseTime will be used
 
420
    /
 
421
    /
 
422
    /********************************************************************************************************/
 
423
    function second ( $format = "s", $timestamp = 0) {
 
424
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
425
        } else {return date ($format,$timestamp);}
 
426
    }
 
427
    /****************************************************************************************************
 
428
    /  @public  getString -
 
429
    /                  Returns the Formated Time of the Object's base time
 
430
    /    Paramters optional $format - specify the format of the returned value
 
431
    /                                 according to the allowed Format Strings of
 
432
    /                                 PHP 's own date command
 
433
    /             optional $timestamp - specify a time of which a part shall be returned
 
434
    /                                   if not specified the Objects BaseTime will be used
 
435
    /
 
436
    /
 
437
    /********************************************************************************************************/
 
438
 
 
439
    function getString ( $format = "M, dS Y h:i a", $timestamp = 0) {
 
440
        if ($timestamp == 0) { return date ($format,$this->basetime);
 
441
        } else {return date ($format,$timestamp);}
 
442
    }
 
443
 
 
444
 
 
445
 
 
446
    /****************************************************************************************************
 
447
    / @public   dropdown
 
448
    /                   - returns a string containing a HTML DropDown Field (SELECT) based on the current basetime
 
449
    /           Parameters :
 
450
    /                   $name - Name of the HTML-Select Tag
 
451
    /                   optional $param - Array of Paramaters configuring the Select Field
 
452
                                    ['formatshow']        -     Specify the way the entries will be showed
 
453
    /                               ['format']          -   Specify the kind of Field to be produced (months / years / days ..
 
454
                                                            What will be run?
 
455
                                    ['start']           -   Specify a start value
 
456
                                                            From where will be run?
 
457
    /                               ['run']             -   Specify the number of entries to be produced
 
458
    /                                                       How far will be run?/
 
459
    /                               ['style']           -   Specify a CSS - Class to be used
 
460
    /                               ['selectsize']      -   Specify the Size of the Select Tag ( 1 Row or multirow)
 
461
    /                               ['selecteddate']    -   preselected Date
 
462
    /
 
463
    /***************************************************************************************************/
 
464
    function dropdown ($name, $param=array()) {
 
465
        $start = (isset($param['start']) && ! empty($param['start'])) ? $param['start'] : $this->stdParamAdd['start'];
 
466
        $run = (isset($param['run']) && ! empty($param['run'])) ? $param['run'] : $this->stdParamAdd['run'];
 
467
        $format = (isset($param['format']) && ! empty($param['format'])) ? $param['format'] : "d";
 
468
        $style = (isset($param['style']) && ! empty($param['style'])) ? $param['style'] : "";
 
469
        $selectsize  = (isset($param['selectsize']) && ! empty($param['selectsize'])) ? $param['selectsize'] : 1;
 
470
 
 
471
        $selecteddate = (isset($param['selecteddate']) && ! empty($param['selecteddate'])) ? $param['selecteddate'] : $this->basetime;
 
472
 
 
473
        $base_day = date ("d",$this->basetime);
 
474
        $base_month = date ("m",$this->basetime);
 
475
        $base_year = date ("Y",$this->basetime);
 
476
        $base_hour = date ("H",$this->basetime);
 
477
        $base_minute = date ("i",$this->basetime);
 
478
        $base_second = date ("s",$this->basetime);
 
479
 
 
480
 
 
481
        switch ($format) {
 
482
            case "months": case "month": case "m":
 
483
                $frm = "m"; $field = &$base_month; $base_day=1;  // As there are months which don't have 29th,30th,31st
 
484
                break;
 
485
            case "years": case "year": case "y": $base_day=1;  // As there are months which don't have 29th,30th,31st
 
486
                $frm = "Y"; $field = &$base_year;
 
487
                break;
 
488
            case "hours": case "hour": case "h":
 
489
                $frm = "H"; $field = &$base_hour;
 
490
                break;
 
491
            case "minutes": case "minute": case "i":
 
492
                $frm = "i"; $field = &$base_minute;
 
493
                break;
 
494
            case "seconds": case "second": case "s":
 
495
                $frm = "s"; $field = &$base_second;
 
496
                break;
 
497
            case "days": case "day": case "d": default:
 
498
                $frm = "d"; $field = &$base_day;
 
499
                break;
 
500
 
 
501
        }
 
502
 
 
503
        $formatshow = (isset($param['formatshow']) && ! empty($param['formatshow'])) ? $param['formatshow'] : $frm;
 
504
 
 
505
        $start = date($frm, $this->basetime) + $start;
 
506
        $selected = date($frm, $selecteddate);
 
507
 
 
508
        for($field=$start; $field<=$start+$run; $field++)
 
509
        {
 
510
             $key = date ($frm,mktime ( $base_hour, $base_minute, $base_second, $base_month, $base_day, $base_year));
 
511
            $value = date ($formatshow,mktime ( $base_hour, $base_minute, $base_second, $base_month, $base_day, $base_year));
 
512
            $outputString .= ($key == $selected) ? '  <option value="'.$key.'" selected="selected">'.$value."</option>\n" : '  <option value="'.$key.'">'.$value."</option>\n";
 
513
        }
 
514
        return  "<select name=\"".$name."\" class=\"$style\" size=\"$selectsize\">\n".$outputString."</select>\n";
 
515
 
 
516
 
 
517
    }
 
518
    /****************************************************************************************************
 
519
    / @public   datelist
 
520
    /                   - returns a string containing a HTML DropDown Field (SELECT) based on the current basetime
 
521
    /           Parameters :
 
522
    /                   $name - Name of the HTML-Select Tag
 
523
    /                   optional $param - Array of Paramaters configuring the Select Field
 
524
    /                               ['format']          -   Specify the format of the Labels in the Selectbox
 
525
                                    ['keyformat']       -   Specify the format of the value in the option tags
 
526
                                    ['running']         -   Specify iteration / What will be run ? (e.g. "hours", "years")
 
527
                                    ['start']           -   Specify a start value
 
528
                                                            From where will be run?
 
529
    /                               ['run']             -   Specify the number of entries to be produced
 
530
    /                                                       How far will be run?/
 
531
                                    ['steps']           -   Specify the distance between the entries in X format
 
532
    /                               ['style']           -   Specify a CSS - Class to be used
 
533
    /                               ['selectsize']      -   Specify the Size of the Select Tag ( 1 Row or multirow)
 
534
    /                               ['selecteddate']    -   preselected Date
 
535
    /
 
536
    /***************************************************************************************************/
 
537
    function datelist (    $name, $param = array()) {
 
538
        $base_day = date ("d",$this->basetime);
 
539
        $base_month = date ("m",$this->basetime);
 
540
        $base_year = date ("Y",$this->basetime);
 
541
        $base_hour = date ("H",$this->basetime);
 
542
        $base_minute = date ("i",$this->basetime);
 
543
        $base_second = date ("s",$this->basetime);
 
544
 
 
545
        $start = (isset($param['start']) && ! empty($param['start'])) ? $param['start'] : $this->stdParamAdd['start'];
 
546
        $run = (isset($param['run']) && ! empty($param['run'])) ? $param['run'] : $this->stdParamAdd['run'];
 
547
        $steps = (isset($param['steps']) && ! empty($param['steps'])) ? $param['steps'] : $this->stdParamAdd['steps'];
 
548
        $running = (isset($param['running']) && ! empty($param['running'])) ? $param['running'] : $this->stdParamAdd['running'];
 
549
        $format = (isset($param['format']) && ! empty($param['format'])) ? $param['format'] : $this->stdParamAdd['format'];
 
550
        $keyformat = (isset($param['keyformat']) && ! empty($param['keyformat'])) ? $param['keyformat'] : $this->stdParamAdd['keyformat'];
 
551
        $style = (isset($param['style']) && ! empty($param['style'])) ? $param['style'] : "";
 
552
        $selectsize  = (isset($param['selectsize']) && ! empty($param['selectsize'])) ? $param['selectsize'] : 1;
 
553
        $selecteddate = (isset($param['selecteddate']) && ! empty($param['selecteddate'])) ? $param['selecteddate'] : $this->basetime;
 
554
 
 
555
        $steps = ($steps<1) ? 1 : $steps;
 
556
        switch ($running) {
 
557
            case "days": case "day": case "d":
 
558
                $field = &$base_day; $frm = "d";
 
559
                break;
 
560
            case "months": case "month": case "m":
 
561
                $field = &$base_month; $frm = "m";
 
562
                break;
 
563
            case "years": case "year": case "y":
 
564
                $field = &$base_year; $frm = "Y";
 
565
                break;
 
566
            case "hours": case "hour": case "h":
 
567
                $field = &$base_hour; $frm = "H";
 
568
                break;
 
569
            case "minutes": case "minute": case "i":
 
570
                $field = &$base_minute; $frm = "i";
 
571
                break;
 
572
            case "seconds": case "second": case "s":
 
573
                $field = &$base_second; $frm = "s";
 
574
                break;
 
575
        }
 
576
        $start = date($frm, $this->basetime) + $start;
 
577
        $selected = date($keyformat, $selecteddate);
 
578
 
 
579
        for($field=$start; $field<=$start+$run; $field=$field+$steps)
 
580
        {
 
581
            if ("" == $keyformat) {
 
582
                $key = mktime ( $base_hour, $base_minute, $base_second, $base_month, $base_day, $base_year);
 
583
            } else { $key = date($keyformat,mktime ( $base_hour, $base_minute, $base_second, $base_month, $base_day, $base_year));     }
 
584
            $value = date($format,mktime ( $base_hour, $base_minute, $base_second, $base_month, $base_day, $base_year));
 
585
 
 
586
            $outputString .= ($key==$selected)? '  <option value="'.$key.'" selected="selected">'.$value."</option>\n" : '  <option value="'.$key.'">'.$value."</option>\n";
 
587
 
 
588
        }
 
589
        return  "<select name=\"".$name."\" class=\"$style\" size=\"$selectsize\">\n".$outputString."</select>\n";
 
590
 
 
591
 
 
592
    }
 
593
}
 
594
 
 
595
if (! function_exists('bcdiv')) {
 
596
    function bcdiv($divident, $divisor)  // Ganzzahldivision - ERsatz f�r bcdiv
 
597
    {
 
598
        return floor($divident/$divisor);
 
599
    }
 
600
}
 
601
if (! function_exists('bcmod')) {
 
602
    function bcmod($divident, $divisor) // Ganzzahldivisionsmodulo - Eratz f�r bcmod
 
603
    {
 
604
        return $divident - ($divisor*bcdiv($divident,$divisor));
 
605
    }
 
606
}
 
607
?>