C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\mamCAL\admin_categories.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
<?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: admin_categories.php - Category Admin ***incomplete
$Id: admin_categories.php,v 1.8 2005/02/12 12:50:28 simoami Exp $
**********************************************
Get the latest version of ExtCalendar at:
http://extcal.sourceforge.net
**********************************************
*/

define('ADMIN_CATS_PHP'true);

require_once 
"config.inc.php";

require_priv('can_manage_cats');

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

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

if(!empty(
$mode)) {

    switch(
$mode) {
        case 
'add':
            
pageheader($lang_cat_admin_data['add_cat'] . " :: " $lang_cat_admin_data['section_title']);
            
print_add_cat_form();
            break;

        case 
'edit':
            
pageheader($lang_cat_admin_data['edit_cat'] . " :: " $lang_cat_admin_data['section_title']);
            if(!empty(
$cat_id)) print_edit_cat_form($cat_id);
            else 
print_cat_list();
          break;

        case 
'del' :
            
pageheader($lang_cat_admin_data['del_cat'] . " :: " $lang_cat_admin_data['section_title']);
            if(!empty(
$cat_id)) delete_cat($cat_id);
            else 
print_cat_list();
            break;

        default:
            
pageheader($lang_cat_admin_data['section_title']);
            
print_cat_list();
            break;
    }
} else {
    
pageheader($lang_cat_admin_data['section_title']);
    
print_cat_list();
}

// footer
pagefooter();

// Functions

function print_add_cat_form() {
/* print a blank category form so we can add a new one */

    
global $CONFIG$ME$zone_stamp$errors$lang_cat_admin_data$lang_general;

            
$form $_POST;

            
$successful false;
            
            if(
count($_POST)) {
                
// Process user submission
                // Form Validation
                
$errors '';

                if (empty(
$form['cat_name'])) { $errors .=  theme_error_string($lang_cat_admin_data['no_cat_name']);  }
                if (empty(
$form['description'])) { $errors .= theme_error_string($lang_cat_admin_data['no_cat_desc']);}
                if (empty(
$form['color'])) { $errors .= theme_error_string($lang_cat_admin_data['no_color']);  }


                if(!
$errors) {
                    
$temp_id '';
                    
                    
$cat_name = isset($form['cat_name'])?addslashes($form['cat_name']):"";
                    
$description = isset($form['description'])?addslashes(html_decode($form['description'])):"";

                    
$color = isset($form['color'])?addslashes($form['color']):"";

                    
$admin_auto_approve = (isset($form['adminapproved']))?1:0;
                    
$user_auto_approve = (isset($form['userapproved']))?1:0;
                    
$options $user_auto_approve $admin_auto_approve*2;
                    
$status = (isset($form['status']))?1:0;
                    
                    
$query "INSERT INTO ".$CONFIG['TABLE_CATEGORIES']." (`cat_name`, `description`, `color`, `options`, `enabled`) 
                                        VALUES ('
$cat_name','$description','$color','$options','$status')";
                    
db_query($query);

                    
// Successfull message
                    
theme_redirect_dialog($lang_cat_admin_data['add_cat'], $lang_cat_admin_data['add_cat_success'], $lang_general['continue'], $ME);
                    
// to remember not to display the form again
                    
$successful true;
                } 
            } else {
                
$form['adminapproved'] = true;
                
$form['color'] = "#505054";
            }
            
            
// Render the form
      
if(!$successful) {
                
display_cat_form($ME,'add',$form);
            }

}

function 
print_edit_cat_form($cat_id) {
/* print an existing category form so we can edit it */

    
global $CONFIG$ME$zone_stamp$errors$lang_cat_admin_data$lang_general;

        
$successful false;

    
// Retrieve the form array
    
if(count($_POST)) $form $_POST;
    else {
        
$query "
        SELECT * FROM "
.$CONFIG['TABLE_CATEGORIES']."
        WHERE cat_id = 
$cat_id";
        
$result db_query($query);
        
$form db_fetch_array($result);
        
$form['userapproved'] = $form['options'] & 1;
        
$form['adminapproved'] = $form['options'] & 2;
        
$form['status'] = $form['enabled'];
    }


    if(
count($_POST)) {
        
// Process form submission
        // Form Validation


        
$errors '';
        if (empty(
$form['cat_name'])) { $errors .=  theme_error_string($lang_cat_admin_data['no_cat_name']);  }
        if (empty(
$form['description'])) { $errors .= theme_error_string($lang_cat_admin_data['no_cat_desc']);}
        if (empty(
$form['color'])) { $errors .= theme_error_string($lang_cat_admin_data['no_color']);  }

        if(!
$errors) {

            
$cat_name = isset($form['cat_name'])?addslashes($form['cat_name']):"";
            
$description = isset($form['description'])?addslashes(html_decode($form['description'])):"";
            
$color = isset($form['color'])?addslashes($form['color']):"";

            
$admin_auto_approve = (isset($form['adminapproved']))?1:0;
            
$user_auto_approve = (isset($form['userapproved']))?1:0;
            
$options $user_auto_approve $admin_auto_approve*2;
            
$status = (isset($form['status']))?1:0;
            
            
$query "
            UPDATE "
.$CONFIG['TABLE_CATEGORIES']." SET 
                `cat_name` = '
$cat_name',
                `description` = '
$description',
                `color` = '
$color',
                `options` = '
$options',
                `enabled` = '
$status'
            WHERE cat_id = '
{$form['cat_id']}'";

            
db_query($query);

            
// Successfull message
            
theme_redirect_dialog($lang_cat_admin_data['edit_cat'], $lang_cat_admin_data['edit_cat_success'], $lang_general['continue'], $ME);
            
// to remember not to display the form again
            
$successful true;
        } 
    } 
    
    
// Render the form
  
if(!$successful) {
        
display_cat_form($ME,'edit',$form);
    }

    
}

function 
delete_cat($cat_id) {
/* delete the category identified as $cat_id */

    
global $CONFIG$ME$lang_cat_admin_data$lang_general;


    
// Check to see if there are events under this category
    
$qid db_query("SELECT id FROM ".$CONFIG['TABLE_EVENTS']." WHERE cat = '$cat_id'");
    
$num_events db_num_rows($qid);
    if(
$num_events) {
        
theme_redirect_dialog($lang_cat_admin_data['delete_cat'], sprintf($lang_cat_admin_data['cat_has_events'],$num_events), $lang_general['back'], $ME);
    } else {
        
$qid db_query("DELETE FROM ".$CONFIG['TABLE_CATEGORIES']." WHERE cat_id = '$cat_id'");
        if(!
db_affected_rows()) theme_redirect_dialog($lang_cat_admin_data['delete_cat'], $lang_cat_admin_data['delete_cat_failed'], $lang_general['back'], $ME);
        else 
theme_redirect_dialog($lang_cat_admin_data['delete_cat'], $lang_cat_admin_data['delete_cat_success'], $lang_general['continue'], $ME);
    }
}

function 
print_cat_list() {

    global 
$CONFIG$ME$lang_cat_admin_data$lang_general;

  
$query "SELECT cat_id, cat_name, description, color, bgcolor, enabled, options FROM ".$CONFIG['TABLE_CATEGORIES'] . " ORDER BY cat_id DESC";
    
$result db_query($query);
    
$rows db_num_rows($result);
    
  
// if no rows
  
if (!$rows) { 
        
theme_redirect_dialog($lang_cat_admin_data['section_title'], $lang_cat_admin_data['no_cats'], $lang_general['back'], "calendar.php");
  
# show categorys
  
} else {

        
$total_cats 0;
        
$active_cats 0;
        
$count 0;
        
$cat_rows '';
        
$stats = Array();
    while (
$row db_fetch_object($result))
    {
      
$query "SELECT * FROM ".$CONFIG['TABLE_EVENTS'] . " WHERE cat = $row->cat_id";
      
$result1 db_query($query);
      
$total db_num_rows($result1);
            
$cat_rows[$count]['total_events'] = $total;
            
$cat_rows[$count]['color'] = $row->color;
            
$cat_rows[$count]['cat_link'] = "calendar.php?mode=cat&cat_id=".$row->cat_id;
            
$cat_rows[$count]['cat_desc'] = format_text($row->description,true,false);
            
$cat_rows[$count]['cat_id'] = $row->cat_id;
            
$cat_rows[$count]['cat_name'] = format_text($row->cat_name,false,true);
            
$cat_rows[$count]['options'] = $row->options;
            
$cat_rows[$count]['status'] = $row->enabled?true:false;
            
            
$active_cats += $row->enabled?1:0;
            
$total_cats ++;
            
$count ++;
    }
        
$stats['total_cats'] = $total_cats;
        
$stats['active_cats'] = $active_cats;
        
theme_admin_cats($cat_rows$stats);
  }



}


?>