C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mamCAL\lib\event.inc.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
<?php 
/*
**********************************************
ExtCalendar v2
Copyright (c) 2003-2005 Mohamed Moujami (Simo)
v1 originally written by Kristof De Jaeger
**********************************************
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. 
**********************************************
File Description: event.inc.php - Event class
$Id: event.inc.php,v 1.8 2005/02/12 08:55:21 simoami Exp $
**********************************************
Get the latest version of ExtCalendar at:
http://extcal.sourceforge.net
**********************************************
*/


class Event {
    
// Set default variables for all new objects

        // Info related variables
    
var $title "";
    var 
$description "";
    var 
$contact "";
    var 
$url "";
    var 
$link "";
    var 
$email "";
    var 
$picture "";
    var 
$color "#000000"// black color by default
    
var $catName "";
    var 
$catDesc "";
        
        
// Date related variables
    
var $startDate NULL;
    var 
$endDate NULL;

        var 
$startDay 0;
        var 
$startMonth 0;
        var 
$startYear 0;

        var 
$endDay 0;
        var 
$endMonth 0;
        var 
$endYear 0;

    var 
$recurStartDate NULL// virtual start and end dates used for recurrent events
    
var $recurEndDate NULL;

        
// Other info variables
        
var $id 0;
        var 
$catId 0;
    var 
$status   false;  // true means approved or active event                
    
var $recType NULL// Recurrence type: daily, weekly, monthly, yearly or (null for non recurrent events)
        
var $recInterval 0// Period of recurrence
        
var $recEndDate 0// recurrence limit
    
var $recEndType 0// recurrence end type: 0. repeat indefinitely, 1. repeat a number of occurrences, 2. repeat until date ($recEndDate)
    
var $recEndCount NULL// number of occurrences for a recurrent event. Used in conjunction with $recEndType = 1
    
        
function Event() {
      
// defining the constructor
        //global $CONFIG;
        
        //if($eventId) $this->getEvent($eventId);
        
}
        
        function 
isActive() {
            return 
$this->$this->status;
        }

        function 
loadEvent($eventId) {
        
// function that retrieves and set event info
        
global $CONFIG;
        
$query "SELECT e.*,cat_name, color, c.description AS cat_desc  FROM ".$CONFIG['TABLE_EVENTS']." AS e ";
        
$query .= "LEFT JOIN ".$CONFIG['TABLE_CATEGORIES']." AS c ON e.cat=c.cat_id WHERE id='".$eventId."'";
        
$results db_query($query);
            
$rows db_num_rows($results);
    
        if (!
$rows) { 
            return 
false;
        } else 
        {
            
$row db_fetch_array($results);
                
// additional field processing

                // Store info related variables
            
$this->title $row['title'];
            
$this->description $row['description'];
            
$this->contact $row['contact'];
            if(
$row['url'])
                
$this->url eregi("/^(http[s]?:\/\/)",$row['url'])?$row['url']:"http://".$row['url'];
            else 
$this->url "";
            
$this->link $this->url;
            
$this->email $row['email'];
            
$this->picture $row['picture'];
            
$this->color $row['color'];
            
$this->catName $row['cat_name'];
            
$this->catDesc $row['cat_desc'];
                
                
// Store date related variables
            
$this->startDate strtotime($row['start_date']);
                if(
$row['start_date'] > $row['end_date']) 
                    
$this->endDate $this->startDate;
            else
                
$this->endDate strtotime($row['end_date']);

                
$this->startDay = (int)date("d"$this->startDate);
                
$this->startMonth = (int)date("m"$this->startDate);
                
$this->startYear = (int)date("Y"$this->startDate);

                
$this->endDay = (int)date("d"$this->endDate);
                
$this->endMonth = (int)date("m"$this->endDate);
                
$this->endYear = (int)date("Y"$this->endDate);
        
                    
                
// Store other info variables
                
$this->id $eventId;
                
$this->catId = (int)$row['cat'];
            
$this->status $row['approved']?true:false;
            
$this->recType $row['recur_type'];
                
$this->recInterval = (int)$row['recur_val'];
                
$this->recEndDate strtotime($row['recur_until']);
                
//$this->recWeekDays = $row['rec_weekdays'];
                
$this->recEndType = (int)$row['recur_end_type'];
                
$this->recEndCount = (int)$row['recur_count'];
            }
            
db_free_result($results);  
            return 
true;
        }    
        
        function 
getDuration() {
        
//function datestoduration ($periods = null) {
            
$periods null;
            
            
$seconds $this->endDate $this->startDate;

          
// Force the seconds to be numeric        
          
$seconds = (int)$seconds;                
          
// Define our periods        
          
if (!is_array($periods)) {            
              
$periods = array (                    
              
//'years'     => 31556926,                    
              //'months'    => 2629743,                    
              //'weeks'     => 604800,                    
              
'days'      => 86400,                    
              
'hours'     => 3600,                    
              
'minutes'   => 60,                    
              
//'seconds'   => 1                    
              
);        
          }        

          
// Loop through        
          
foreach ($periods as $period => $value) {            
              
$count floor($seconds $value);            
              
$values[$period] = $count;            
              if (
$count == 0) {                
                  continue;            
              }            
              
$seconds $seconds $value;        
          }        
          
// Return array        
          
if (empty($values)) {            
              
$values null;        
          }
          
        
// fix the all day value
            
if(date("G:i",$this->endDate) == "23:59") { 
                
$values['days']++;
                
$values['hours'] = 0;
                
$values['minutes'] = 0;
            } 
            
          return 
$values;    
        }
        
        function 
isRecurrent() {
            return empty(
$this->recType)?false:true;
        }
        
        function 
setStartDate($start_date) {
            
            
$this->startDate $start_date;
            
$this->startDay = (int)date("d"$this->startDate);
            
$this->startMonth = (int)date("m"$this->startDate);
            
$this->startYear = (int)date("Y"$this->startDate);
        }

        function 
setEndDate($end_date) {
            
$this->endDate $end_date;
            
$this->endDay = (int)date("d"$this->endDate);
            
$this->endMonth = (int)date("m"$this->endDate);
            
$this->endYear = (int)date("Y"$this->endDate);
        }

        function 
isRecurrentOn($target_stamp) {
            global 
$CONFIG;
            if(!
$this->isRecurrent()) return false;
            
$day $this->startDay;
            
$month $this->startMonth;
            
$year $this->startYear;
            
$current_stamp mktime(0,0,0,$month,$day,$year); // reproduce the start date without time info
            
$duration mktime(0,0,0,$this->endMonth,$this->endDay,$this->endYear) - mktime(0,0,0,$this->startMonth,$this->startDay,$this->startYear);
            
            if(
$this->recEndType == && ($this->recEndDate $duration $target_stamp)) return false;

            
$target_day = (int)date("d"$target_stamp);
            
$target_month = (int)date("m"$target_stamp);
            
$target_year = (int)date("Y"$target_stamp);
            
$target_stamp mktime(0,0,0,$target_month,$target_day,$target_year); // reformat the target date without time info
            
$recur_count 1;

            while((
$this->recEndType != && $current_stamp <= $target_stamp) || ($this->recEndType == && $recur_count <= $this->recEndCount)) {
                switch(
$this->recType) {
                    case 
"day":
                            
$current_stamp mktime(0,0,0,$month,$day+=$this->recInterval,$year);
                            break;
                    case 
"week":
                            
$current_stamp mktime(0,0,0,$month,$day+=$this->recInterval*7,$year);
                            break;
                    case 
"month":
                            
$current_stamp mktime(0,0,0,$month+=$this->recInterval,$day,$year);
                            break;
                    case 
"year":
                            
$current_stamp mktime(0,0,0,$month,$day,$year+=$this->recInterval);
                            break;
                    default:
                }
                
$condition_all $current_stamp <= $target_stamp && ($current_stamp $duration) >= $target_stamp;
                
$condition_bounds = ($current_stamp == $target_stamp || ($current_stamp $duration) == $target_stamp);
                
$condition_start $current_stamp == $target_stamp;
                
                if(((
$condition_all && $CONFIG['multi_day_events']=="all") || ($condition_bounds && $CONFIG['multi_day_events']=="bounds") || ($condition_start && $CONFIG['multi_day_events']=="start")) && ($this->recEndType != || $this->recEndDate >= $current_stamp)) {
                    
$this->recurStartDate $current_stamp;
                    
$this->recurEndDate $current_stamp $duration;
                    return 
true;
                }
                
$recur_count++;
            }
            
            
// no match
            
return false;
            
        }

        function 
get_icon($day_stamp,$start_stamp,$end_stamp) {
            
            
$startbound date('Ymd',$day_stamp) - date('Ymd',$start_stamp); // 0 means event starts same day
            
$endbound date('Ymd',$end_stamp) - date('Ymd',$day_stamp); // 0 means event ends same day
            //echo "STR:".date('Ymd',$start_stamp) . " STO:".date('Ymd',$end_stamp). " DAY:".date('Ymd',$day_stamp)."<br>";
            
            
$image "icon-event-onedate.gif"// default event icon
            
if(!$startbound && !$endbound$image "icon-event-onedate.gif";
            elseif(!
$startbound && $endbound>0$image "icon-event-startdate.gif";
            elseif(
$startbound>&& !$endbound$image "icon-event-enddate.gif";
            elseif(
$startbound>&& $endbound>0$image "icon-event-middate.gif";
            
//else return false;
            
            
return $image;
        
        }
        
        function 
get_style($day_stamp,$start_stamp,$end_stamp) {
            
            
$startbound date('Ymd',$day_stamp) - date('Ymd',$start_stamp); // 0 means event starts same day
            
$endbound date('Ymd',$end_stamp) - date('Ymd',$day_stamp); // 0 means event ends same day
            
            
$class "eventfull"// default event class
            
if(!$startbound && !$endbound$class "eventfull";
            elseif(!
$startbound && $endbound>0$class "eventstart";
            elseif(
$startbound>&& !$endbound$class "eventend";
            elseif(
$startbound>&& $endbound>0$class "eventmiddle";
            
//else return false;
            
            
return $class;
        
        }

}

?>