source: trunk/www.guidonia.net/wp/wp-content/plugins/odlinks/admin/odl_admin_structure.php@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 9.6 KB
Line 
1<?php
2
3/**
4 * odl_admin_structure.php
5 *
6 * This file handles the Administration of the Categories
7 *
8 * @author Mohammad Forgani
9 * @copyright Copyright 2008, Oh Jung-Su
10 * @version 1.0
11 * @link http://www.forgani.com
12 **/
13
14function process_odlinksstructure(){
15 global $_GET, $_POST, $table_prefix, $PHP_SELF, $wpdb;
16 $odlinkssettings = get_option('odlinksdata');
17 $view = true;
18 $id = $_GET['c_id']*1;
19 if (!$id) $id=0;
20 echo '<div class="wrap"><h2>ODLinks Sturcture - Add/Edit Categories</h2><p>';
21 switch ($_GET['odlinks_admin_action']){
22 case "saveCategory":
23 if ($id==0){
24 $today = date("Y-m-d");
25 if ($_POST['odlinksdata']['c_hide']=='y'){
26 $c_hide = "hidden";
27 }else{$c_hide = "visible";}
28 $position = $wpdb->get_var("SELECT MAX(c_position) FROM {$table_prefix}odcategories")+1;
29 $sql = "INSERT INTO {$table_prefix}odcategories (c_parent, c_name, c_title, c_description, c_keywords, c_position, c_status, c_hide, c_date) values ('".($_POST['odlinksdata']['c_parent']*1)."', '".$wpdb->escape($_POST['odlinksdata']['c_name'])."', '".$wpdb->escape($_POST['odlinksdata']['c_title'])."', '".$wpdb->escape($_POST['odlinksdata']['c_description'])."', '".$wpdb->escape($_POST['odlinksdata']['c_keywords'])."', '".$position."', '".$wpdb->escape($_POST['odlinksdata']['c_status'])."', '".$c_hide."', '".$today."')";
30 $wpdb->query($sql);
31 } else {
32 if ($_POST['odlinksdata']['c_hide']=='y'){
33 $c_hide = "hidden";
34 } else{
35 $c_hide = "visible";
36 }
37 $sql = "UPDATE {$table_prefix}odcategories SET c_status = '".$wpdb->escape($_POST['odlinksdata']['c_status'])."', c_hide = '".$c_hide."', c_parent = '".($_POST['odlinksdata']['c_parent']*1)."', c_title = '".$wpdb->escape(stripslashes($_POST['odlinksdata']['c_title']))."', c_name = '".$wpdb->escape(stripslashes($_POST['odlinksdata']['c_name']))."', c_status = '".$wpdb->escape(stripslashes($_POST['odlinksdata']['c_status']))."', c_hide = '".$c_hide."', c_description = '".$wpdb->escape(stripslashes($_POST['odlinksdata']['c_description']))."' WHERE c_id = '".($_GET['c_id']*1)."'";
38 $wpdb->query($sql);
39 }
40 $msg ="Category Saved.";
41 break;
42 case "editCategory":
43 odl_edit_category($id);
44 $view = false;
45 break;
46 case "deleteCategory":
47 if ($id<>0) {
48 $wpdb->query("DELETE FROM {$table_prefix}odcategories WHERE c_id = '".($id)."'");
49 $wpdb->query("DELETE FROM {$table_prefix}odlinks WHERE l_c_id = '".($id)."'");
50 }
51 break;
52 }
53
54 if ($msg!=''){
55 ?>
56 <div id="message" class="updated fade"><?php echo $msg;?></div>
57 <?php
58 }
59 if ($view) odl_view_category(0);
60 echo '</div>';
61}
62
63
64
65function odl_edit_category($id) {
66 global $_GET, $_POST, $table_prefix, $PHP_SELF, $wpdb;
67 $odlinkssettings = get_option('odlinksdata');
68 $odCategories = $wpdb->get_row("SELECT * FROM {$table_prefix}odcategories WHERE c_id = '".($id)."'", ARRAY_A);
69 ?>
70 <P>
71 <style type="text/css">
72 fieldset {
73 padding: 1em;
74 font:12px;
75 font-weight:bold;
76 border:1px solid #ddd;
77 }
78 label {
79 float:left;
80 width:25%;
81 margin-right:0.5em;
82 padding-top:0.2em;
83 text-align:right;
84 font-weight:bold;}
85 </style>
86
87 <form method="post" id="odl_form_post" name="odl_form_post" action="<?php echo $PHP_SELF;?>?page=odlinksstructure&odlinks_admin_page_arg=<?php echo $_GET['odlinks_admin_page_arg'];?>&odlinks_admin_action=saveCategory&c_id=<?php echo $id; ?>">
88 <fieldset>
89 <legend>Edit Category</legend>
90 <label>Category title:</label>
91 <input type="text" size="50" name="odlinksdata[c_title]" value="<?php echo $odCategories['c_title'];?>">
92 <br>
93 <label>Category name:</label>
94 <input type="text" size="50" name="odlinksdata[c_name]" value="<?php echo $odCategories['c_name'];?>">
95 <br>
96 <label>Category description:</label>
97 <textarea name="odlinksdata[c_description]" rows="3" cols="48"><?php echo $odCategories['c_description'];?></textarea>
98 <br>
99 <label>Category keywords:</label>
100 <input type="text" size="50" name="odlinksdata[c_keywords]" value="<?php echo $odCategories['c_keywords'];?>">
101 <br>
102 <label>Parent category:</label>
103 <select name="odlinksdata[c_parent]">
104 <option value="0">root/ </option>
105 <?php odl_list_cats(0,0,$odCategories['c_id'],$odCategories['c_parent']); ?>
106 </select>
107 <br>
108 <label>Category Status</label>
109 <select name="odlinksdata[c_status]"><option value="active">Open</option>
110 <option value="inactive"<?php echo ($odCategories['c_status']=='inactive')?" selected":"";?>>Closed</option>
111 <option value="readonly"<?php echo ($odCategories['c_status']=='readonly')?" selected":"";?>>Read-Only</option>
112 </select>
113 <br>
114 <label>&nbsp;</label>
115 <input type="checkbox" name="odlinksdata[c_hide]" value="y"<?php echo ($odCategories['c_hide']=='hidden')?" checked":"";?>> -Hide Category?
116 <P>
117 <label>&nbsp;</label>
118 <input type="submit" value="Save category">&nbsp;&nbsp;<input type=button value="Cancel" onclick="history.go(-1);"> </fieldset>
119 </form>
120 <P>
121 <?php
122}
123
124
125
126function odl_view_category($id) {
127 global $_GET, $_POST, $table_prefix, $PHP_SELF, $wpdb;
128 $odlinkssettings = get_option('odlinksdata');
129 $categoy_status = array(active=>"Open",inactive=>"Closed",readonly=>"Read-Only");
130 ?>
131 <input type="button" value="Add Category" onclick="document.location.href='<?php echo $PHP_SELF;?>?page=odlinksstructure&odlinks_admin_page_arg=<?php echo $_GET['odlinks_admin_page_arg'];?>&odlinks_admin_action=editCategory&c_id=0';">
132 <hr>
133 <img src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/odlinks/images/delete.png"> - delete category, including subcategories and all links within.<p>
134
135 <table style="width: 100%; background-color:#fafafa; border:1px #C0C0C0 solid; border-spacing:1px;">
136 <tr><td>
137 <table width="100%" style="border:1px #C0C0C0 solid;">
138 <tr style="background-color:#ccc">
139 <td style="border:1px #C0C0C0 solid; padding-left:2px; background-color:#ccc"><img border=0 src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/odlinks/images/edit.gif"> Title / Name</td>
140 <td style="border:1px #C0C0C0 solid; padding-left:2px; background-color:#ccc" width="150">Number of links</td>
141 <td nowrap style="border:1px #C0C0C0 solid; padding-left:2px; background-color:#ccc">Date</td>
142 <td style="border:1px #C0C0C0 solid; padding-left:2px; background-color:#ccc">Delete</td>
143 </tr>
144 <?php odl_main_cats($id,0,$orderby,$how);?>
145 </table></td>
146 </tr></table>
147 </table>
148 <?php
149} // odl_view_category
150
151
152function odl_list_cats($parent, $lev, $exclude, $selected) {
153 global $table_prefix, $wpdb;
154 $out = "";
155 if ($lev == 0) {
156 echo "\n";
157 }
158 $space = "";
159 for ($x = 0; $x < $lev; $x++) {
160 $space .= "&nbsp;&nbsp;&nbsp;-&nbsp;";
161 }
162 $categories = $wpdb->get_results("SELECT * FROM {$table_prefix}odcategories WHERE c_parent = '$parent' ORDER BY c_title ASC");
163 for ($i=0; $i<count($categories); $i++){
164 $category = $categories[$i];
165 $res = $wpdb->get_row("SELECT * FROM {$table_prefix}odlinks WHERE l_c_id = '".$category->c_id."'", ARRAY_A);
166 $linksNum = count($res);
167 $id = $category->c_id;
168 $title = $category->c_title;
169 $sel = "";
170 if($id == $selected){$sel = " selected ";}
171 if($id != $exclude){echo "<option $sel value=\"$id\">$space$title ($linksNum)</option>";}
172 $out = odl_list_cats($id, $lev + 1, $exclude, $selected);
173 }
174 return $out;
175}
176
177
178function odl_main_cats($parent,$lev,$orderby,$how) {
179 global $table_prefix, $wpdb;
180 $out = "";
181 if($lev == 0){print "\n";}
182 if(!$how){$how = "ASC";}
183 if($orderby <> "c_date"){$orderby = "c_title";}
184 $space = "";
185
186 ?>
187 <script language=javascript>
188 <!--
189 function deleteCategory(x, y){
190 if (confirm("<?php echo ("Are you sure you wish to delete the Category"); ?>\n"+x)){
191 document.location.href = y;
192 }
193 }
194 //-->
195 </script>
196 <?
197
198 for($x=0;$x<$lev;$x++){
199 $space .= "&nbsp;&nbsp;&nbsp;&nbsp;";
200 }
201 $sql = "SELECT * FROM {$table_prefix}odcategories WHERE c_parent = $parent ORDER BY $orderby $how";
202 $categories = $wpdb->get_results($sql);
203 for ($i=0; $i<count($categories); $i++){
204 $category = $categories[$i];
205 $linksCnt = $wpdb->get_row("SELECT count(l_id) as count FROM {$table_prefix}odlinks WHERE l_c_id = '".$category->c_id."'", ARRAY_A);
206 $linksNum = $linksCnt['count'];
207 $id = $category->c_id;
208 $title = $category->c_title;
209 $name = $category->c_name;
210 $categoy_status = array(active=>"Open",inactive=>"Closed",readonly=>"Read-Only");
211
212 $status = $categoy_status[$category->c_status];
213 echo '<tr bgcolor="#F0F0F0" onMouseOver="this.bgColor="#FFFFFF";" onMouseOut="this.bgColor="#E9E9E9";">';
214 echo '<td style="background-color:#E9E9E9">&nbsp;' . $space;
215 ?>
216 <a style="text-decoration: none;" href="<?php echo $PHP_SELF;?>?page=odlinksstructure&odlinks_admin_page_arg=<?php echo $_GET['odlinks_admin_page_arg'];?>&odlinks_admin_action=editCategory&c_id=<?php echo $id;?>"><?php echo ($title . " / " . $name); ?></a>
217 <?php
218 echo "<span class=\"font-size:8px;\">(" . $status;
219 echo ($tfs->c_hide=='hidden')?" and Hidden":"";
220 echo ")</span></td>";
221
222 echo '<td style="background-color:#E9E9E9">(<a href="'. $PHP_SELF .'?page=odlinksstructure&odlinks_admin_page_arg=' . $_GET['odlinks_admin_page_arg'] .'&odlinks_admin_action=viewCategory&c_id=' .$category->c_parent. '">'. $linksNum .'</a>)</td>';
223 echo '<td>'.$category->c_date.'</td>';
224 ?>
225 <td style="background-color:#E9E9E9"><a style="text-decoration: none;" href="javascript:deleteCategory('<?php echo rawurlencode($category->c_title . " " . $category->c_name );?>', '<?php echo $PHP_SELF;?>?page=odlinksstructure&odlinks_admin_page_arg=<?php echo $_GET['odlinks_admin_page_arg'];?>&odlinks_admin_action=deleteCategory&c_id=<?php echo $id;?>');"><img border=0 src="<?php echo get_bloginfo('wpurl'); ?>/wp-content/plugins/odlinks/images/delete.png"></a></td></tr>
226 <?php
227 $print = odl_main_cats($id,$lev + 1,$orderby,$how);
228 }
229 return $out;
230}
231
232?>
Note: See TracBrowser for help on using the repository browser.