C:\$Recycle.Bin\S-1-5-21-3967099092-2644009230-141905953-500\$R3GYWM8\uploads.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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
<?php 
/*
ExtCalendar v2
Copyright (C) 2003 Mohamed Moujami (SimoAmi)

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. 
This program is distributed in the hope that it will be useful, 
but WITHOUT ANY WARRANTY; without even the implied warranty of 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
GNU General Public License for more details. 

You should have received a copy of the GNU General Public License 
along with this program; if not, write to the Free Software 
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Date Started : 21/08/2002
Date Last Updated : 16/04/2004
Author(s) : Mohamed Moujami (SimoAmi.com), Kristof De Jaeger
Description : Events Admin

Get the latest version of ExtCalendar at http://extcal.sourceforge.net//
*/

// Report all errors except E_NOTICE
error_reporting (E_ALL E_NOTICE);

require_once 
"config.inc.php";

require_priv('has_admin_access');

$mode = isset($_GET['mode'])?$_GET['mode']:'';
$mode = isset($_POST['mode'])?$_POST['mode']:$mode;

$id = isset($_GET['id'])?$_GET['id']:'';
$id = isset($_POST['id'])?$_POST['id']:$id;

if(!empty(
$mode)) {

    switch(
$mode) {
        case 
'add':
            
pageheader(translate('addevent') . " :: " $CONFIG['app_name']);
            
print_add_event_form();
            break;

        case 
'edit':
            
pageheader(translate('edit') . " :: " $CONFIG['app_name']);
            if(!empty(
$id)) print_edit_event_form($id);
            else 
print_event_list();
          break;
        case 
'del' :
            
pageheader(translate('uploadapplnk') . " :: " $CONFIG['app_name']);
            if(!empty(
$id)) delete_event($id);
            else 
print_event_list();
            break;

        case 
'apr' :
            
pageheader(translate('uploadapplnk') . " :: " $CONFIG['app_name']);
            if(!empty(
$id)) approve_event($id);
            else 
print_event_list();
            break;
    
        case 
'update' :
            
pageheader(translate('uploadapplnk') . " :: " $CONFIG['app_name']);
            
update_event($_POST);
            
//print_event_list();
            
break;

        default:
            
pageheader(translate('uploadapplnk') . " :: " $CONFIG['app_name']);
            
print_event_list();
            break;
    }
} else {
    
pageheader(translate('uploadapplnk') . " :: " $CONFIG['app_name']);
    
print_event_list();
}

# footer
pagefooter();

// Functions

function print_add_event_form() {
/* print a blank owner form so we can add a new owner */

    
global $CONFIG$ME$zoneStamp$errors$day$month$year;

            
$form $_POST;

            
$successful false;
            
            
            
$day = isset($_GET['day'])?$_GET['day']:gmdate("d",$zoneStamp);
            
$month = isset($_GET['month'])?$_GET['month']:gmdate("m",$zoneStamp);
            
$year = isset($_GET['year'])?$_GET['year']:gmdate("Y",$zoneStamp);

            
$day = isset($form['bday'])?$form['bday']:$day;
            
$month = isset($form['bmonth'])?$form['bmonth']:$month;
            
$year = isset($form['byear'])?$form['byear']:$year;

            if (isset(
$form['title'])) $title $form['title']; else $title '';
            if (isset(
$form['description'])) $description $form['description']; else $description '';
            if (isset(
$form['contact'])) $contact $form['contact']; else $contact '';
            if (isset(
$form['email'])) $email $form['email']; else $email '';
            if (isset(
$form['url'])) $url $form['url']; else $url '';
            if (isset(
$form['cat'])) $cat $form['cat']; else $cat '';
            
            if(
count($_POST)) {
                
// Process user submission
                // Form Validation
                
$errors '';
                
$dateok true;
                if (empty(
$title)) { $errors .=  theme_error_string(translate("notitle"));  }
                if (empty(
$description)) { $errors .= theme_error_string(translate("nodescription"));}
                if (empty(
$cat)) { $errors .= theme_error_string(translate("nocat"));  }
                if (empty(
$day)) { $errors .= theme_error_string(translate("noday")); $dateok false;  }
                if (empty(
$month)) { $errors .= theme_error_string(translate("nomonth")); $dateok false; }
                if (empty(
$year)) { $errors .= theme_error_string(translate("noyear"));  $dateok false; }
                if (
$dateok) {
                    
$temp_month = ($month == 'every')?gmdate("m",$zoneStamp):$month;
                    
$temp_year = ($year == 'every')?gmdate("Y",$zoneStamp):$year;
                    if (!
checkdate($temp_month,$day,$temp_year)) { $errors .= theme_error_string(translate("novaliddate")); }
                }


                
# may someone upload picture or not ?
                
if ($CONFIG['addevent_allow_picture'])
                {
                    if (
is_uploaded_file($_FILES['picture']['tmp_name']))
                    {
                        
# check for size of picture
                        
$size $_FILES['picture']['size'];
                        
# check for extension ! 
                        
$name $_FILES['picture']['name'];
                        
$ext explode(".",$name);
                        
$ext array_reverse($ext);
                        
$ext $ext[0];
                        
$valid 0;
                        
$extensions explode('/'$CONFIG['allowed_file_extensions']);
                        for (
$i=0;$i<count($extensions);$i++)
                        {
                            if(
preg_match("/".$extensions[$i]."$/i",$ext))
                            {
                                
$valid 1;
                            }
                        }
                        
$filesize $CONFIG['max_upl_size'];
                        if (
$size $filesize)
                        {
                            
$errors .= theme_error_string(translate("filetolarge") . " (".($CONFIG['max_upl_size'] / 1000)." ".translate("kblimit").")"); 
                        }
                        elseif (
$valid != 1)
                        {
                            
$errors .= theme_error_string(translate("extensionnovalid")); 
                        } 
                    }
                    else 
$picture '';
                } 
                else 
$picture '';
                if(!
$errors) {
                    
$temp_id '';
                    if(
$valid)
                    {
                        
$temp_id substr(md5(time()),0,4);
                        
$picture "$temp_id"."_".$_FILES['picture']['name'];
                        
$picture str_replace(" ","",$picture);
                        
move_uploaded_file($_FILES['picture']['tmp_name'], "upload/".$picture);
                    }
                    
$description nl2br($description);
                    
$url str_replace("http://","",$url);
                    
                    
$approve = (isset($form['approved']))?1:0;
                    
                    
$temp_month = ($month == 'every')?'0':$month;
                    
$temp_year = ($year == 'every')?'0':$year;
                    
$query "INSERT INTO ".$CONFIG['TABLE_EVENTS']." (title,description,contact,url,email,picture,cat,day,month,year,approved) VALUES ('$title','$description','$contact','$url','$email','$picture','$cat','$day',";
                    
$query.= "'$temp_month','$temp_year','$approve')";
                    
db_query($query);

                    
// Successfull message
                    
theme_redirect_dialog(translate("addevent"), translate("thankyou"), translate("continuebutton"), "uploads.php");
                    
// to remember not to display the form again
                    
$successful true;
                } 
            }
            
            
// Render the form
      
if(!$successful) {
                
display_event_form($ME,'add',$form);
            }

}

function 
print_edit_event_form($eventid) {
/* print a blank owner form so we can add a new owner */

    
global $CONFIG$ME$zoneStamp$errors$day$month$year;

            if(
count($_POST)) $form $_POST;
            else {
                
$query "
                SELECT * FROM "
.$CONFIG['TABLE_EVENTS']."
                WHERE id = 
$eventid";
                
$result db_query($query);
                
$form db_fetch_array($result);
                
$form['origpicture'] = $form['picture'];
            }
            
$successful false;
            
            
$day $form['day'];
            
$month $form['month'];
            
$year $form['year'];

            if (isset(
$form['title'])) $title $form['title']; else $title '';
            if (isset(
$form['description'])) $description $form['description']; else $description '';
            if (isset(
$form['contact'])) $contact $form['contact']; else $contact '';
            if (isset(
$form['email'])) $email $form['email']; else $email '';
            if (isset(
$form['url'])) $url $form['url']; else $url '';
            if (isset(
$form['cat'])) $cat $form['cat']; else $cat '';
            
            if(
count($_POST)) {
                
// Process user submission
                // Form Validation
                
$errors '';
                
$dateok true;
                if (empty(
$title)) { $errors .=  theme_error_string(translate("notitle"));  }
                if (empty(
$description)) { $errors .= theme_error_string(translate("nodescription"));}
                if (empty(
$cat)) { $errors .= theme_error_string(translate("nocat"));  }
                if (empty(
$day)) { $errors .= theme_error_string(translate("noday")); $dateok false;  }
                if (empty(
$month)) { $errors .= theme_error_string(translate("nomonth")); $dateok false; }
                if (empty(
$year)) { $errors .= theme_error_string(translate("noyear"));  $dateok false; }
                if (
$dateok) {
                    
$temp_month = ($month == 'every')?gmdate("m",$zoneStamp):$month;
                    
$temp_year = ($year == 'every')?gmdate("Y",$zoneStamp):$year;
                    if (!
checkdate($temp_month,$day,$temp_year)) { $errors .= theme_error_string(translate("novaliddate")); }
                }


                
# may someone upload picture or not ?
                
if ($CONFIG['addevent_allow_picture'])
                {
                    if (
is_uploaded_file($_FILES['picture']['tmp_name']))
                    {
                        
# check for size of picture
                        
$size $_FILES['picture']['size'];
                        
# check for extension ! 
                        
$name $_FILES['picture']['name'];
                        
$ext explode(".",$name);
                        
$ext array_reverse($ext);
                        
$ext $ext[0];
                        
$valid 0;
                        
$extensions explode('/'$CONFIG['allowed_file_extensions']);
                        for (
$i=0;$i<count($extensions);$i++)
                        {
                            if(
preg_match("/".$extensions[$i]."$/i",$ext))
                            {
                                
$valid 1;
                            }
                        }
                        
$filesize $CONFIG['max_upl_size'];
                        if (
$size $filesize)
                        {
                            
$errors .= theme_error_string(translate("filetolarge") . " (".($CONFIG['max_upl_size'] / 1000)." ".translate("kblimit").")"); 
                        }
                        elseif (
$valid != 1)
                        {
                            
$errors .= theme_error_string(translate("extensionnovalid")); 
                        } 
                    }
                    else 
$picture '';
                } 
                else 
$picture '';
                if(!
$errors) {
                    
$temp_id '';

                    if(isset(
$form['origpicture']) && (isset($form['delpicture']) || $valid) ) {
                        
unlink("upload/".$form['origpicture']);
                    } else 
$picture $form['origpicture'];

                    if(
$valid)
                    {
                        
$temp_id substr(md5(time()),0,4);
                        
$picture "$temp_id"."_".$_FILES['picture']['name'];
                        
$picture str_replace(" ","",$picture);
                        
move_uploaded_file($_FILES['picture']['tmp_name'], "upload/".$picture);
                    }

                    
$description nl2br($description);
                    
$url str_replace("http://","",$url);
                    
                    
$approve = (isset($form['approved']))?1:0;
                    
                    
$temp_month = ($month == 'every')?'0':$month;
                    
$temp_year = ($year == 'every')?'0':$year;
                    
                    
$query "
                    UPDATE "
.$CONFIG['TABLE_EVENTS']." SET 
                        title = '
$title',
                        description = '
$description',
                        contact = '
$contact',
                        url = '
$url',
                        email = '
$email',
                        picture = '
$picture',
                        cat = '
$cat',
                        day = '
$day',
                        month = '
$temp_month',
                        year = '
$temp_year',
                        approved = '
$approve'
                    WHERE id = '
{$form['id']}'";
                    
                    
db_query($query);

                    
// Successfull message
                    
theme_redirect_dialog(translate("edit"), translate("eventedited"), translate("continuebutton"), "uploads.php");
                    
// to remember not to display the form again
                    
$successful true;
                } 
            }
            
            
// Render the form
      
if(!$successful) {
                
display_event_form($ME,'edit',$form);
            }

    
}

function 
approve_event($eventid) {
/* delete the owner who's identified as $ownerid */

    
global $CONFIG$ME;
    
$qid db_query("UPDATE ".$CONFIG['TABLE_EVENTS']." SET approved = 1 WHERE id = '$eventid'");
    if(!
db_affected_rows()) theme_redirect_dialog(translate("nonapproved"), translate("cantapprevent"), translate("returnbutton"), $ME);
    else 
theme_redirect_dialog(translate("nonapproved"), translate("appreventok"), translate("returnbutton"), $ME);

}

function 
delete_event($eventid) {
/* delete the owner who's identified as $ownerid */

    
global $CONFIG$ME;
    
$qid db_query("DELETE FROM ".$CONFIG['TABLE_EVENTS']." WHERE id = '$eventid'");
    if(!
db_affected_rows()) theme_redirect_dialog(translate("delev"), translate("cantdelevent"), translate("returnbutton"), $ME);
    else 
theme_redirect_dialog(translate("delev"), translate("deleventok"), translate("returnbutton"), $ME);

}

function 
print_event_list() {

    global 
$CONFIG$ME$maand;

    
$query "SELECT id,title,e.description,url,cat,cat_name,day,month,year, color FROM ".$CONFIG['TABLE_EVENTS']." AS e LEFT JOIN ".$CONFIG['TABLE_CATEGORIES']." AS c ON e.cat=c.cat_id ";
    
$query .= "WHERE approved = '0' ";
    
$query .= "ORDER BY year ASC, month ASC, day ASC";
    
$result db_query($query);
    
$rows db_num_rows($result);
    
    if (
$rows == 0)    { 
        
theme_caption_dialog(translate("nonapproved"), translate("nononapproved"));
    }    else {

        
$num_rows $rows;

        
$count 0;
        while (
$row mysql_fetch_object($result))
        {
            
$event_results[$count]['event_id'] = $row->id;
            
$event_results[$count]['event_title'] = htmlentities($row->title);
            
$event_results[$count]['event_link'] = "href='uploads.php?op=view&id=".$row->id."'";
            
            
$de htmlentities($row->description);
            
$de stripslashes($de);
            if(
strlen($de) > 100$de substr($de,0,100)." ...";

            
$event_results[$count]['event_desc'] = $de;
            
            
$event_results[$count]['cat_id'] = $row->cat;
            
$event_results[$count]['cat_name'] = $row->cat_name;
            
$event_results[$count]['date'] = $row->day ." ".$maand[$row->month]." ".$row->year;
            
$count++;
        }

        
theme_admin_events($event_results$num_rows);
    }

}


?>