Remove cutenews/yui, use twitter bootstrap css
[contractdashboard.git] / categories.mdu
1 <?PHP
2 $result="";
3 if($member_db[1] != 1){ msg("error", "Access Denied", "You don't have permission to edit categories"); }
4
5 // ********************************************************************************
6 // Add Category
7 // ********************************************************************************
8 if($action == "add")
9 {
10 $cat_name = htmlspecialchars(stripslashes($cat_name));
11 if(!$cat_name){ msg("error","Error !!!","Please enter name of the category", "javascript:history.go(-1)"); }
12 $cat_icon = preg_replace("/ /", "", $cat_icon);
13 if($cat_icon == "(optional)"){ $cat_icon = ""; }
14
15 $big_num = file("./data/cat.num.php");
16 $big_num = $big_num[0];
17 if(!$big_num or $big_num == ""){ $big_num = 1; }
18
19 $all_cats = file("./data/category.db.php");
20 foreach($all_cats as $cat_line)
21 {
22 $cat_arr = explode("|", $cat_line);
23 if($cat_arr[1] == $cat_name){ msg("error", "Error !!!", "Category with this name already exist", "?mod=categories"); }
24 if($cat_arr[0] == $big_num){ $big_num = 33; }
25 }
26 $new_cats = fopen("./data/category.db.php", "a");
27 $cat_name = stripslashes( preg_replace(array("'\|'",), array("&#124",), $cat_name) );
28 $cat_icon = stripslashes( preg_replace(array("'\|'",), array("&#124",), $cat_icon) );
29 fwrite($new_cats, "$big_num|$cat_name|$cat_icon|$cat_access|||\n");
30 fclose($new_cats);
31 $big_num ++;
32
33 $num_file = fopen("./data/cat.num.php", "w");
34 fwrite($num_file, $big_num);
35 fclose($num_file);
36 }
37 // ********************************************************************************
38 // Remove Category
39 // ********************************************************************************
40 elseif($action == "remove")
41 {
42 if(!$catid){ msg("error","Error !!!","No category ID", "$PHP_SELF?mod=categories"); }
43
44 $old_cats = file("./data/category.db.php");
45 $new_cats = fopen("./data/category.db.php", "w");
46
47 foreach($old_cats as $old_cats_line){
48 $cat_arr = explode("|", $old_cats_line);
49 if($cat_arr[0] != $catid){
50 fwrite($new_cats, $old_cats_line);
51 }
52 }
53 fclose($new_cats);
54 }
55 // ********************************************************************************
56 // Edit Category
57 // ********************************************************************************
58 elseif($action == "edit")
59 {
60 if(!$catid){ msg("error","Error !!!","No category ID", "$PHP_SELF?mod=categories"); }
61
62 $all_cats = file("./data/category.db.php");
63 foreach($all_cats as $cat_line){
64 $cat_arr = explode("|", $cat_line);
65 if($cat_arr[0] == $catid){
66
67 $if_all_access = ($cat_arr[3] == "" || $cat_arr[3] == "0") ? "selected" : "";
68
69 $if_1_access = ($cat_arr[3] == "1") ? "selected" : "";
70 $if_2_access = ($cat_arr[3] == "2") ? "selected" : "";
71
72
73 $msg=<<<HTML
74 <form action=$PHP_SELF?mod=categories method=post>
75 <table border="0" >
76 <tr>
77 <td width="100" >Name</td>
78 <td ><input value="$cat_arr[1]" type=text name=cat_name></td>
79 </tr>
80 <tr>
81 <td >Icon</td>
82 <td ><input value="$cat_arr[2]" type=text name=cat_icon></td>
83 </tr>
84
85
86 <tr>
87 <td >
88 Category Access
89 <td >
90
91 <select name="cat_access">
92 <option $if_all_access value="0" selected>Everyone Can Write</option>
93 <option $if_2_access value="2">Only Editors and Admin</option>
94 <option $if_1_access value="1">Only Admin</option>
95
96 </select>
97
98 </tr>
99
100
101 <tr>
102 <td></td>
103 <td ><br><input type=submit value="Save Changes"</td>
104 </tr>
105 </table>
106 <input type=hidden name=action value=doedit>
107 <input type=hidden name=catid value=$catid>
108 </form>
109 HTML;
110
111 msg("options", "Edit Category", $msg);
112
113 }
114 }
115 }
116 // ********************************************************************************
117 // DO Edit Category
118 // ********************************************************************************
119 elseif($action == "doedit")
120 {
121 $cat_name = htmlspecialchars(stripslashes($cat_name));
122 if(!$catid){ msg("error","Error !!!","No category ID", "$PHP_SELF?mod=categories"); }
123 if($cat_name == ""){ msg("error", "Error !!!", "Category name can not be blank", "javascript:history.go(-1)"); }
124
125 $old_cats = file("./data/category.db.php");
126 $new_cats = fopen("./data/category.db.php", "w");
127 foreach($old_cats as $cat_line){
128 $cat_arr = explode("|", $cat_line);
129 if($cat_arr[0] == $catid){
130 fwrite($new_cats, "$catid|$cat_name|$cat_icon|$cat_access|||\n");
131 }else{
132 fwrite($new_cats, "$cat_line");
133 }
134 }
135 fclose($new_cats);
136 }
137 // ********************************************************************************
138 // List all Categories
139 // ********************************************************************************
140 echoheader("options", "Categories");
141 echo<<<HTML
142
143 <table border=0 cellpading=0 cellspacing=0 width="645" >
144 <form method=post action="$PHP_SELF">
145 <td width=321 height="33">
146 <b>Add Category</b>
147 <table border=0 cellpading=0 cellspacing=0 width=300 class="panel" >
148 <tr>
149 <td width=130 height="25">
150 &nbsp;Name
151 <td height="25">
152 <input type=text name=cat_name>
153 </tr>
154 <tr>
155 <td height="22">
156 &nbsp;Icon URL
157 <td height="22">
158 <input onFocus="this.select()" value="(optional)" type=text name=cat_icon>
159 </tr>
160
161
162 <tr>
163 <td height="22">
164 &nbsp;Category Access
165 <td height="22">
166
167 <select name="cat_access">
168 <option value="0" selected>Everyone Can Write</option>
169 <option value="2">Only Editors and Admin</option>
170 <option value="1">Only Admin</option>
171
172 </select>
173
174 </tr>
175
176
177 <tr>
178 <td width=98 height="32">
179 &nbsp;
180 <td width=206 height="32">
181 <input type=submit value=" Add Category ">
182 <input type=hidden name=mod value=categories>
183 <input type=hidden name=action value=add>
184 </tr>
185 </form>
186 </table>
187
188
189 <td width=320 height="33" align="center">
190 <!-- HELP -->
191 <table height="25" cellspacing="0" cellpadding="0">
192 <tr>
193 <td width="25" align=middle><img border="0" src="skins/images/help_small.gif"></td>
194 <td >&nbsp;<a onClick="javascript:Help('categories')" href="#">What are categories and<br>
195 &nbsp;How to use them</a></td>
196 </tr>
197 </table><br>
198 <!-- END HELP -->
199
200 <tr>
201 <td width=654 colspan="2" height="11">
202 <img height=20 border=0 src="skins/images/blank.gif" width=1>
203 </tr>
204 HTML;
205
206
207 $all_cats = file("./data/category.db.php");
208 $count_categories = 0;
209 foreach($all_cats as $cat_line)
210 {
211 if($i%2 != 0){ $bg = "bgcolor=#F7F6F4"; }else{ $bg = ""; }
212 $i++;
213 $cat_arr = explode("|", $cat_line);
214 $cat_arr[1] = stripslashes( preg_replace(array("'\"'", "'\''"), array("&quot;", "&#039;"), $cat_arr[1]) );
215 $cat_help_names[] = $cat_arr[1];
216 $cat_help_ids[] = $cat_arr[0];
217 $result .= "
218
219 <tr>
220 <td $bg >&nbsp;<b>$cat_arr[0]</b></td>
221 <td $bg >$cat_arr[1]</td>
222 <td $bg >";
223 if($cat_arr[2] != ""){ $result .= "<img border=0 src=\"$cat_arr[2]\" high=40 width=40 alt=\"$cat_arr[2]\">"; }
224 else{ $result .= "---"; }
225 $result .= "</td><td $bg >";