"Fossies" - the Fresh Open Source Software Archive 
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the latest
Fossies "Diffs" side-by-side code changes report for "lib_admin.php3":
1.2.0_vs_1.2.1.
1 <?php
2 #----------------------------------------------------------------->
3 # $Id: lib_admin.php3,v 1.74 2010/05/04 18:29:59 ldrolez Exp $
4 #
5 # Website: http://mythreads.sourceforge.net
6 #
7 # Desc: lib_admin.php3. Amin functions
8 #
9 # License: This code is released under the terms of the GNU GPL
10 # version 2 or later. Please refer to www.gnu.org for a copy
11 # of this license.
12 #
13 #----------------------------------------------------------------->
14
15 #########################
16 # Admin Functions Below #
17 #########################
18
19 #################################################
20 # Admin : show categories in a 'select' menu
21 #################################################
22 function Admin_showCategories($select)
23 {
24 global $config, $mylink;
25
26 static $cache = array();
27
28 $content = "";
29
30 if (count($cache) == 0)
31 {
32 $category = mysqli_query($mylink, "SELECT pathto,cat,title FROM ".$config["pre"]."category order by pathto");
33 while ($info_c = mysqli_fetch_array($category))
34 {
35 $cache[$info_c["cat"]] = $info_c;
36 $patharray = explode(":",$info_c['pathto']);
37 $sub_title = "";
38 while (list($key, $val)=each($patharray))
39 {
40 if ($val != ""){
41 if (isset($cache[$val]["title"])) {
42 $sub_title .= "/".$cache[$val]["title"];
43 } else {
44 $result_sub = mysqli_query($mylink, "SELECT title FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
45 $sub_title_new = mysqli_fetch_array($result_sub);
46 $cache[$val]["title"] = $sub_title_new["title"];
47 $sub_title .= "/".$sub_title_new["title"];
48 }
49 }
50 }
51 $cache[$info_c["cat"]]["full"] = $sub_title;
52 }
53 }
54
55 reset($cache);
56 while (list($n, $info_c) = each($cache) )
57 {
58 $selected = "";
59 if ($select != "") {
60 if ($select == $info_c['cat']) $selected = " SELECTED";
61 }
62 $content .= "<option value=\"$info_c[cat]\"$selected>";
63 $content .= $info_c["full"]."</option>\n";
64 }
65
66 return $content;
67 }
68
69 #################################################
70 # Admin : Add a link form
71 #################################################
72 function Admin_showAddlink()
73 {
74 global $start_script, $start_script_t, $tpl;
75
76 $category = Admin_showCategories("");
77
78 $action = $tpl->get_var("ACTION_ADMIN");
79 $tpl->set_file("addlink", "form_update_link.tpl");
80 $tpl->set_block("addlink", "delete_row", "deleteme");
81 $tpl->set_block("addlink", "email_row", "deleteme");
82 $tpl->set_block("addlink", "security_row", "deleteme");
83 $tpl->set_var( array(
84 "ACTION" => "$action",
85 "SUBMIT_NAME" => "update_link",
86 "TITLE" => "",
87 "OPTIONS" => "$category"
88 ));
89
90 # Needed ?
91 #if (isset ($category)) { $content = $content.$category; }
92
93 $content = $tpl->subst("addlink");
94
95 return $content;
96 }
97
98 #################################################
99 # Show main adminstrator's page
100 #################################################
101 function Admin_showMain()
102 {
103 global $start_script, $start_script_t, $_POST, $tpl;
104 global $config, $mylink;
105
106 $total_delete_waiting = $total_waiting = 0;
107
108 $total_waiting_ref = mysqli_query($mylink, "SELECT COUNT(*) FROM ".$config["pre"]."links where status=1");
109 $total_waiting = mysqli_fetch_array($total_waiting_ref);
110
111 if ($total_waiting[0] < 1 )
112 {
113 $total_waiting[0] = "0";
114 }
115
116 $total_delete_waiting_ref = mysqli_query($mylink, "SELECT COUNT(*) FROM ".$config["pre"]."links where status=2");
117
118 $total_delete_waiting = mysqli_fetch_array($total_delete_waiting_ref);
119
120 if ($total_delete_waiting[0] < 1 )
121 {
122 $total_delete_waiting[0] = "0";
123 }
124
125
126 $total_cat_waiting_ref = mysqli_query($mylink, "SELECT COUNT(*) FROM ".$config["pre"]."waitcat");
127 $total_cat_waiting = mysqli_fetch_array($total_cat_waiting_ref);
128
129 if ($total_cat_waiting[0] < 1 )
130 {
131 $total_cat_waiting[0] = "0";
132 }
133
134
135 $tpl->set_file("adminmain", "form_admin_main.tpl");
136 $tpl->set_var( array(
137 "TOTAL_WAITING" => $total_waiting[0],
138 "TOTAL_DELETE_WAITING" => $total_delete_waiting[0],
139 "TOTAL_CAT_WAITING" => $total_cat_waiting[0]
140 ));
141 $content = $tpl->subst("adminmain");
142
143 return $content;
144 }
145
146 #################################################
147 # Admin : Add a main category form
148 #################################################
149 function Admin_showAddmain()
150 {
151 global $start_script, $start_script_t, $tpl;
152
153 $tpl->set_file("addmain", "form_admin_add_main.tpl");
154 $content = $tpl->subst("addmain");
155
156 return $content;
157 }
158
159 #################################################
160 # Admin : Add a sub category form
161 #################################################
162 function Admin_showGiveAddsub($category)
163 {
164 global $start_script, $start_script_t, $tpl;
165
166 $path = Admin_display_category($category);
167
168 $tpl->set_file("addsub", "form_admin_add_sub.tpl");
169 $tpl->set_var( array(
170 "CATEGORY" => "$category",
171 "PATH" => "$path"
172 ));
173 $content = $tpl->subst("addsub");
174
175 return $content;
176 }
177
178 #################################################
179 # Admin : Edit Sub Category form
180 #################################################
181 function Admin_showEditsub($category)
182 {
183 global $start_script, $start_script_t, $tpl;
184 global $config, $mylink;
185
186 $result_ref = mysqli_query($mylink, "SELECT title,info FROM ".$config["pre"]."category WHERE cat='$category'");
187 $result = mysqli_fetch_array($result_ref);
188 $path = Admin_display_category($category);
189
190 $tpl->set_file("editsub", "form_admin_edit_sub.tpl");
191 $tpl->set_var( array(
192 "CATEGORY" => "$category",
193 "RESULT_TITLE" => "$result[title]",
194 "RESULT_MESSAGE" => "$result[info]",
195 "PATH" => "$path"
196 ));
197 $content = $tpl->subst("editsub");
198
199 return $content;
200 }
201
202 #################################################
203 # Admin : print Main page with just main category's
204 #################################################
205 function Admin_mainPage()
206 {
207 global $config, $start_script, $start_script_t, $mylink;
208
209 $result = mysqli_query($mylink, "SELECT cat,title,ttlinks FROM ".$config["pre"]."category WHERE under='0' ORDER BY title");
210 $links = "<table width=\"100%\"><tr>";
211
212 while ($info = mysqli_fetch_array($result))
213 {
214 $a++;
215 $links .= Message ("admin_cat", array(
216 "INFO_CAT" => $info[cat],
217 "INFO_TITLE" => $info[title],
218 "INFO_TT" => $info[ttlinks]
219 ));
220
221 if ($a == $config["across"])
222 {
223 $links .= "</tr><tr>\n";
224 $a=0;
225 }
226 }
227
228 $links .= "</tr></table>";
229
230 return $links;
231 }
232
233 #################################################
234 #
235 #################################################
236 #
237 # View links page
238 function Admin_viewPage($category)
239 {
240 #########
241 # global variables
242 global $config, $start_script, $start_script_t, $mylink;
243
244 $content .= "<table width=\"100%\" border=0 cellpadding=3><tr>";
245 $result_t = mysqli_query($mylink, "SELECT cat,title,ttlinks FROM ".$config["pre"]."category where under='$category' ORDER BY 'title'");
246
247 while ($info = mysqli_fetch_array($result_t))
248 {
249
250 $a++;
251 $content .= Message ("admin_cat", array(
252 "INFO_CAT" => $info[cat],
253 "INFO_TITLE" => $info[title],
254 "INFO_TT" => $info[ttlinks]
255 ));
256
257 if ($a == $config["across"]) { $content .= "</tr>\n<tr>";$a=0;}
258
259 }
260
261 $content .= "</tr></table>";
262
263 return $content;
264
265 }
266
267 #################################################
268 # This function displays the different categories of links there are.
269 #################################################
270 #
271 function Admin_display_category($category)
272 {
273 global $start_script, $start_script_t;
274 global $config, $mylink;
275
276 $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE pathto LIKE '%:$category:'");
277 $sub_title = mysqli_fetch_array($result_sub);
278
279 $patharray = explode(":",$sub_title[pathto]);
280
281 $top_bt = Message("top_bt");
282
283 $content .= "<a href=\"".$start_script_t."mode=admin&showAddsub=true\">$top_bt</a>";
284 while (list($key, $val)=each($patharray))
285 {
286 if ($val != ""){
287 $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
288 $sub_title_new = mysqli_fetch_array($result_sub);
289 $content.= "/<a href=\"".$start_script_t."mode=admin&category=$sub_title_new[cat]&showAddsub=true\">$sub_title_new[title]</a>";
290 }
291 }
292
293 return $content;
294 }
295
296 #################################################
297 # Admin : add a sub-category directly in the database
298 #################################################
299 function Admin_doAddsub($main,$title,$message)
300 {
301 global $config, $mylink;
302
303 if ($title != "" )
304 {
305 $max_ref = mysqli_query($mylink, "select MAX(cat)+1 from ".$config["pre"]."category");
306 $number = mysqli_fetch_array($max_ref);
307 $pathto_ref = mysqli_query($mylink, "select pathto from ".$config["pre"]."category where cat='$main'");
308 $pathto = mysqli_fetch_array($pathto_ref);
309
310 $su = mysqli_query($mylink, "insert into ".$config["pre"]."category (cat,under,title,info,pathto)
311 values ('$number[0]','$main','$title','$message','$pathto[pathto]$number[0]:' )");
312 $content = Message ("subcat_added", array("TITLE" => "$title"));
313 } else {
314 $content = Message("did_not_fill_title");
315 }
316
317 return $content;
318 }
319
320 #################################################
321 # Admin : add a main category directly in the database
322 #################################################
323 function Admin_doAddmain($title,$message)
324 {
325 global $config, $mylink;
326
327 if ($title != ""){
328 $max_ref = mysqli_query($mylink, "select MAX(cat)+1 from ".$config["pre"]."category");
329 $number = mysqli_fetch_array($max_ref);
330 if ($number[0] == "") $number[0] = 1;
331 $su = mysqli_query($mylink, "insert into ".$config["pre"]."category (cat,under,title,info,pathto)
332 values ('$number[0]','0','$title','$message',':$number[0]:' )");
333
334 $content = Message ("maincat_added", array("TITLE" => "$title"));
335 } else {
336 $content = Message ("did_not_fill_cat_title");
337 }
338
339 return $content;
340 }
341
342 #################################################
343 #
344 #################################################
345 #
346 function Admin_askdeletelink()
347 {
348 global $start_script, $start_script_t, $tpl;
349
350 $tpl->set_file("askdel", "form_admin_ask_delete.tpl");
351 $content = $tpl->subst("askdel");
352
353 return $content;
354 }
355
356 #################################################
357 #
358 #################################################
359 function Admin_showdeletelink($_unused)
360 {
361 global $start_script, $start_script_t, $tpl, $config, $_POST, $mylink;
362
363 $content = "";
364 $result = mysqli_query( $mylink, "SELECT * FROM ".$config["pre"]."links where link='$_POST[url]' and status=0");
365
366 if (mysqli_num_rows($result))
367 {
368 while ($info = mysqli_fetch_array($result)) {
369
370 $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category where pathto LIKE '%:$info[cat]:'");
371
372 $cat = "";
373 while ($info_c = mysqli_fetch_array($category) )
374 {
375 $patharray = explode(":",$info_c[pathto]);
376
377 while (list($key, $val)=each($patharray))
378 {
379 if ($val != ""){
380 $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
381 $sub_title_new = mysqli_fetch_array($result_sub);
382 $cat .= "/$sub_title_new[title]";
383 }
384 }
385 }
386
387 $tpl->set_file("showdelete", "form_admin_show_delete.tpl");
388 $tpl->set_var( array(
389 "CATEGORY" => "$cat",
390 "INFO_TITLE" => "$info[title]",
391 "INFO_MESSAGE" => "$info[message]",
392 "INFO_LINK" => "$info[link]",
393 "INFO_CAT" => "$info[cat]",
394 "INFO_IDX" => "$info[idx]"
395 ));
396 $content .= $tpl->subst("showdelete");
397 }
398 } else {
399 $content = Message ("no_link_for", array ("TEXT" => htmlentities($_POST[url])));
400 }
401
402 return $content;
403 }
404
405 #################################################
406 #
407 #################################################
408 #
409 function Admin_dodeletelink($_unused)
410 {
411 global $config, $_POST, $mylink;
412
413 if ($_POST[idx] != "" && $_POST[cat] != ""){
414 $minus_totals = mysqli_query($mylink, "UPDATE ".$config["pre"]."category SET ttlinks=ttlinks-1 WHERE pathto like '%:".intval($_POST[cat]).":%'");
415
416 $result = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."links where idx='".intval($_POST[idx])."' and status=0");
417
418 $content = Message ("link_deleted", array (
419 "TEXT" => htmlentities($_POST[link])));
420 } else {
421 $content = Message ("no_link_for", array ("TEXT" => htmlentities($_POST[link])));
422 }
423
424 updateRSS();
425
426 return $content;
427 }
428
429 #################################################
430 #
431 #################################################
432 #
433 function Admin_dodeletecat($_unused)
434 {
435 global $config, $_POST, $mylink;
436
437 if (isset($_POST[delete])){
438
439 $result_cat = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."category where pathto LIKE '%:".intval($_POST[category]).":%'");
440 $howmany_cat = mysqli_affected_rows($mylink);
441
442 $result_links = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."links where cat='".intval($_POST[category])."' ");
443 $howmany_links = mysqli_affected_rows($mylink);
444
445 $content = Message ("cat_links_deleted", array (
446 "CAT" => $howmany_cat,
447 "LINKS" => $howmany_links));
448 }
449 elseif(! isset($_POST[delete]) and isset($_POST[title]))
450 {
451
452 $update = mysqli_query($mylink, "UPDATE ".$config["pre"]."category SET title='$_POST[title]' WHERE cat='".intval($_POST[category])."' ") or die (mysqli_error($mylink));
453
454 if ($_POST[message] != "")
455 {
456 $update_message = mysqli_query($mylink, "UPDATE ".$config["pre"]."category SET info='$_POST[message]' WHERE cat='".intval($_POST[category])."' ");
457 }
458
459 $content = Message("cat_info_updated");
460 }
461
462 return $content;
463 }
464
465 #################################################
466 # Show links waiting for a validation
467 #################################################
468 #
469 function Admin_showwaiting()
470 {
471 global $start_script, $start_script_t, $tpl;
472 global $config, $custom, $mylink;
473
474 $tpl->set_file("showwait", "form_admin_show_wait.tpl");
475 $tpl->set_block("showwait", "wait_row", "wait_rows");
476 $tpl->set_var("wait_rows", "");
477
478 $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."links where status=1 order by title");
479 while ($info = mysqli_fetch_array($category) )
480 {
481 $changes = "";
482 $title = validate_url($info['link'], $info['title']);
483
484 $linkcategory_ref = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category where cat='$info[cat]'");
485 $linkcategory = mysqli_fetch_array($linkcategory_ref);
486 $cat = "<select name=\"categoryid:".$info['idx']."\">".Admin_showCategories($info['cat'])."</select>";
487
488 # get old link informations
489 $oldinfo = mysqli_fetch_array(mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."links where idx='".$info["idx"]."' and status=0"));
490 if ($oldinfo['status'] == "") {
491 $changes = Message("new");
492 } else {
493 if ($info['link'] != $oldinfo['link'])
494 $changes .= Message("status_link_changed");
495 if ($info['cat'] != $oldinfo['cat'])
496 $changes .= Message("status_cat_changed");
497 if ($info['title'] != $oldinfo['title'])
498 $changes .= Message("status_title_changed");
499 if ($info['message'] != $oldinfo['message'])
500 $changes .= Message("status_message_changed");
501
502 # custom fields
503 reset($custom);
504 while (list($k,$v) = each($custom)) {
505 if ($info[$k] != $oldinfo[$k])
506 $changes .= "*";
507 }
508 }
509
510 $waitinfo = mysqli_fetch_array(mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."wait where idx='$info[idx]'"));
511
512 $tpl->set_var ( array(
513 "INFO_ID" => "$info[idx]",
514 "TITLE" => "$title",
515 "INFO_MESS" => "$info[message]",
516 "INFO_LINK" => "$info[link]",
517 "INFO_IP" => "$waitinfo[ip]",
518 "INFO_EMAIL" => "$waitinfo[email]",
519 "CHANGES" => "<a href=\"".$start_script_t."mode=admin&more=$info[idx]\">$changes</a>",
520 "CATEGORY" => "$cat"
521 ));
522 $tpl->parse ("wait_rows", "wait_row", true);
523 }
524
525 $content = $tpl->subst("showwait");
526
527 return $content;
528 }
529
530 #################################################
531 # Show categories waiting for a validation
532 #################################################
533 #
534 function Admin_showwaitingcat()
535 {
536 global $start_script, $start_script_t, $tpl;
537 global $config, $mylink;
538
539 $tpl->set_file("showwait", "form_admin_show_waitcat.tpl");
540 $tpl->set_block("showwait", "wait_row", "wait_rows");
541 $tpl->set_var("wait_rows", "");
542
543 $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."waitcat order by title");
544 while ($info = mysqli_fetch_array($category) )
545 {
546
547 $category_list = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category where cat='$info[cat]' or under='$info[cat]'");
548 $options ="<option value=\"0\">Top:/";
549
550 while ($info_c = mysqli_fetch_array($category_list) )
551 {
552 $patharray = explode(":",$info_c[pathto]);
553
554 if ($info[cat] == $info_c[cat])
555 {
556 $options .= "<option value=\"$info_c[cat]\" selected>";
557 } else {
558 $options .= "<option value=\"$info_c[cat]\">";
559 }
560
561 while (list($key, $val)=each($patharray))
562 {
563 if ($val != ""){
564 $result_sub = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category WHERE cat='$val' ORDER BY cat ASC");
565 $sub_title_new = mysqli_fetch_array($result_sub);
566 $options .= "/$sub_title_new[title]";
567 }
568
569 }
570 $options .= "</option>\n";
571 }
572
573 $tpl->set_var ( array(
574 "INFO_ID" => "$info[id]",
575 "INFO_TITLE" => "$info[title]",
576 "INFO_MESS" => "$info[message]",
577 "INFO_IP" => "$info[ip]",
578 "OPTIONS" => "$options"
579 ));
580 $tpl->parse ("wait_rows", "wait_row", true);
581 }
582
583 $content = $tpl->subst("showwait");
584
585 return $content;
586 }
587
588 #################################################
589 # Show links waiting to be deleted
590 #################################################
591 #
592 function Admin_showdeletewaiting()
593 {
594 global $start_script, $start_script_t, $tpl;
595 global $config, $mylink;
596
597 $tpl->set_file("showwait", "form_admin_show_waitdel.tpl");
598 $tpl->set_block("showwait", "wait_row", "wait_rows");
599 $tpl->set_var("wait_rows", "");
600
601 $category = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."links where status=2 order by title");
602 while ($info = mysqli_fetch_array($category) )
603 {
604
605 $oldlink_ref = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."links where idx='$info[idx]' and status=0");
606 $oldlink = mysqli_fetch_array($oldlink_ref);
607 $linkcategory_ref = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category where cat='$oldlink[cat]'");
608 $linkcategory = mysqli_fetch_array($linkcategory_ref);
609 $title = validate_url($oldlink[link],$oldlink[title]);
610
611 $waitinfo = mysqli_fetch_array(mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."wait where idx='$info[idx]'"));
612
613 $tpl->set_var ( array(
614 "INFO_ID" => "$info[idx]",
615 "INFO_OLINK" => "$oldlink[link]",
616 "INFO_MESS" => "$info[message]",
617 "INFO_IP" => "$waitinfo[ip]",
618 "INFO_EMAIL" => "$waitinfo[email]",
619 "TITLE" => "$title",
620 "LTITLE" => "$linkcategory[title]"
621 ));
622 $tpl->parse ("wait_rows", "wait_row", true);
623 }
624
625 $content = $tpl->subst("showwait");
626
627 return $content;
628 }
629
630 #################################################
631 #
632 #################################################
633 #
634 function Admin_dodeletewaiting($_unused)
635 {
636 global $start_script, $start_script_t, $_POST;
637 global $config, $mylink;
638
639 $delete_total = $keep_total = 0;
640
641 ##############
642 # This should only show the posted vars with id: in there name then strip out the other stuff...
643 #
644 while (list($key, $val) = each($_POST) and preg_match("/id:/",$key) and $key = preg_replace("/id:/","",$key))
645 {
646 if ($val == "delete")
647 {
648 $delete_total++;
649 $delete = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."links where idx='".intval($key)."' ");
650 $delete = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."wait where idx='".intval($key)."' ");
651
652 }
653 if ($val == "remove")
654 {
655 $remove_total++;
656 $delete = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."links where idx='".intval($key)."' and status=2");
657 $delete = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."wait where idx='".intval($key)."' ");
658 }
659 else if ($val == "")
660 {
661 $keep_total++;
662 }
663 }
664
665 $content = Message ("delremkept", array(
666 "DEL_TOT" => "$delete_total",
667 "REM_TOT" => "$remove_total",
668 "KEPT_TOT" => "$keep_total" ));
669
670 updateRSS();
671
672 return $content;
673 }
674
675 #################################################
676 # Admin : add/remove waiting links
677 #################################################
678 function Admin_dowaiting($_unused)
679 {
680 global $start_script, $start_script_t, $_POST;
681 global $config, $mylink;
682
683 $delete_total = $keep_total = $add_total =0;
684
685 ##############
686 # This should only show the posted vars with id: in there name then strip out the other stuff...
687 #
688 while (list($key, $val) = each($_POST) and preg_match("/id:/",$key) and $key = preg_replace("/id:/","",$key))
689 {
690 # make sure it''s an integer
691 $key = intval($key);
692 # category info and update: keep it for later
693 if (preg_match("/category/", $key)) continue;
694 if (preg_match("/updid:/", $key)) continue;
695 # else add or delete an entry
696 if ($val == "delete")
697 {
698 $delete_total++;
699 $delete_wait = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."wait where idx='$key' ");
700 $delete_link = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."links where idx='$key' and status=1");
701 }
702 else if ($val == "add")
703 {
704 $add_total++;
705
706 # remove then entry in wait
707 $delete_wait = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."wait where idx='$key' ");
708 # get the current hits
709 $hits = mysqli_fetch_array(mysqli_query($mylink, "select hits from ".$config["pre"]."links where idx='$key' and status=0"));
710 if ($hits[0] == "") $hits[0] = "0";
711 # remove the old entry in links
712 $delete_old = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."links where idx='$key' and status=0");
713 $more = "";
714 if (mysqli_affected_rows($mylink) == 0) {
715 # new link update date
716 $more = ", date=NOW()";
717 }
718 # modify the category here
719 $more .= ", cat='".intval($_POST["categoryid:".$key])."' ";
720
721 # make the waiting link, the active new one
722 $res = mysqli_query($mylink, "UPDATE ".$config["pre"]."links SET status=0, hits=".$hits[0]."$more where idx='$key' and status=1") or die (mysqli_error($mylink));
723
724 # need to update the 'update' date ?
725 if (isset($_POST["updid:".$key])) {
726 $add = mysqli_query($mylink, "UPDATE ".$config["pre"]."links set updated=NOW() where idx='$key' and status=0");
727 }
728 }
729 else if ($val == "")
730 {
731 $keep_total++;
732 }
733 }
734
735 updateRSS();
736
737 $content = Message ("delkeptadd", array (
738 "DEL_TOT" => $delete_total,
739 "KEPT_TOT" => $keep_total,
740 "ADD_TOT" => $add_total));
741
742 return $content;
743 }
744
745 #################################################
746 # Admin : add/delete waiting categories
747 #################################################
748 function Admin_dowaitingcat($_unused)
749 {
750 global $start_script, $start_script_t, $_POST;
751 global $config, $mylink;
752
753 $delete_total = $keep_total = $add_total =0;
754
755 ##############
756 # This should only show the posted vars with id: in there name then strip out the other stuff...
757 #
758 while (list($key, $val) = each($_POST))
759 {
760 if (preg_match("/id:/",$key) and $key = preg_replace("/id:/","",$key))
761 {
762 # make sure it''s an integer
763 $key = preg_replace("/[^0-9]+/", "", $key);
764
765 if ($val == "delete")
766 {
767 $delete_total++;
768
769 $delete_wait = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."waitcat where id='$key'");
770
771 }
772 else if ($val == "add")
773 {
774
775 $add_total++;
776
777 $max_ref = mysqli_query($mylink, "select MAX(cat)+1 from ".$config["pre"]."category");
778 $number = mysqli_fetch_array($max_ref);
779 $newcat = $key.":cat";
780
781 $main = intval($_POST[$newcat]);
782
783 if ($main == 0)
784 {
785 $pathto[pathto] = ":";
786 }
787 else
788 {
789 $pathto_ref = mysqli_query($mylink, "select pathto from ".$config["pre"]."category where cat='$main'");
790 $pathto = mysqli_fetch_array($pathto_ref);
791 }
792
793 $message = $key.":message";
794 $title = $key.":title";
795 if ($number[0] == "") $number[0] = 1;
796 $su = mysqli_query($mylink, "insert into ".$config["pre"]."category (cat,under,title,info,pathto) values ('$number[0]','$main','$_POST[$title]','$_POST[$message]','$pathto[pathto]$number[0]:')");
797 $delete = mysqli_query($mylink, "DELETE FROM ".$config["pre"]."waitcat where id='$key'");
798
799 }
800 else if ($val == "")
801 {
802 $keep_total++;
803 }
804 }
805 }
806
807 $content = Message ("delkeptadd", array (
808 "DEL_TOT" => $delete_total,
809 "KEPT_TOT" => $keep_total,
810 "ADD_TOT" => $add_total));
811 return $content;
812 }
813
814 #################################################
815 #
816 #################################################
817 #
818 function Admin_authorize()
819 {
820 global $start_script, $start_script_t, $tpl;
821
822 $tpl->set_file("admin_auth", "form_admin_auth.tpl");
823 $content = $tpl->subst("admin_auth");
824
825 return $content;
826 }
827
828
829 #################################################
830 #
831 #################################################
832 #
833 function uLinkCount()
834 {
835 global $config, $mylink;
836
837 $update_ref = mysqli_query($mylink, "SELECT * FROM ".$config["pre"]."category");
838 $total=array();
839
840 while($update = mysqli_fetch_array($update_ref))
841 {
842 $result = mysqli_query($mylink, "SELECT COUNT(*) from ".$config["pre"]."links where cat='$update[cat]' and status=0");
843 $cat_total = mysqli_fetch_array($result);
844
845 $update_path = explode(":",$update[pathto]);
846
847 while (list($key, $val)=each($update_path))
848 {
849 if ($val != ""){
850 $total[$val] = $cat_total[0] + $total[$val];
851 }
852 }
853 }
854
855
856 while (list($key, $val)=each($total))
857 {
858 $add_totals = mysqli_query($mylink, "UPDATE ".$config["pre"]."category SET ttlinks=$val WHERE cat='$key'") or die (mysqli_error($mylink));
859 }
860
861 $content = Message("link_count_updated");
862
863 return $content;
864 }
865
866 #################################################
867 # This return the hiddend name password (HNP)
868 #################################################
869 #
870 function setAdminCookie($name,$password)
871 {
872 setcookie("name", "$name", 0,'/');
873 setcookie("password", md5($password), 0,'/');
874 }
875
876 #################################################
877 #
878 #################################################
879 #
880 function validate_url($URL,$title)
881 {
882 global $config;
883
884 if ($config["no_url_check"] == 1) {
885 return (Message ("red_message", array("TXT" => "$title")));
886 }
887
888 $URL2 = preg_replace("/http:\/\//i", "", $URL);
889 $splitURL = explode("/", $URL2, 2);
890 $host= $splitURL[0];
891 $path= $splitURL[1];
892
893 if ( ! preg_match("/(\.|\/$)/", $path)){
894 $path="$path/";
895 }
896
897 if ((preg_match("/\./", $host))){
898 $gh = fsockopen ("$host", 80, $errno, $errstr, 5) or $error = "$errstr";
899
900 $line = "";
901 if (! isset($error)){
902 $hpath= "/".$path;
903 fputs($gh, "HEAD $hpath HTTP/1.1\r\nHOST:$host\r\n\r\n");
904 $line = fgets($gh, 25);
905 }
906
907 if (preg_match("/200 OK/", $line)){
908 $valid = Message ("green_message", array("TXT" => $title));
909 } else {
910 $valid = Message ("red_message", array("TXT" => "$title - $error"));
911 }
912
913 } else {
914 $valid = Message ("red_message", array("TXT" => $title));
915 }
916
917 return $valid;
918 }
919
920
921 #########################
922 #
923 # Below is what controls the above functions...
924
925 No_Search_Footer();
926
927 if (getuser() != "")
928 {
929 if (getuser() == "admin" )
930 {
931 if (!isset($_COOKIE['name']))
932 {
933 setAdminCookie($_POST['name'],$_POST['password']);
934 }
935
936 $tpl->set_var( array(
937 "CATEGORY_TITLE" => Message("admin_logged_in"),
938 "TITLE" => Message("admin_mode")
939 ));
940
941 if (isset($_POST['showAddlink']))
942 {
943 $content = Admin_showAddlink();
944 $tpl->set_var( array( "ADMIN" => $content ));
945
946 showStartTemplate();
947 exit;
948 }
949 else if (isset($_POST['showAddmain']))
950 {
951 $content = Admin_showAddmain();
952 $tpl->set_var( array( "ADMIN" => $content ));
953
954 showStartTemplate();
955 exit;
956 }
957 else if (isset($_POST['showDeletecat']))
958 {
959 $content = Admin_showdeletecat();
960
961 $tpl->set_var( array( "ADMIN" => $content ));
962
963 showStartTemplate();
964 exit;
965 }
966 else if (isset($_POST['update_link']))
967 {
968 $content = Admin_showMain();
969 $content .= doAddWaitLink($_POST, "admin");
970 uLinkCount();
971 $tpl->set_var( array( "ADMIN" => $content ));
972 showStartTemplate();
973
974
975 }
976 else if (isset($_POST['showDeletelink']))
977 {
978
979 $content = Admin_askdeletelink();
980
981 $tpl->set_var( array( "ADMIN" => $content ));
982
983 showStartTemplate();
984 exit;
985 }
986 else if (isset($_POST['GetUrlInfo']))
987 {
988 $content = Admin_showdeletelink($_POST);
989
990 $tpl->set_var( array( "ADMIN" => $content ));
991
992 showStartTemplate();
993 exit;
994 }
995 else if (isset($_POST['DeleteThisLink']))
996 {
997 $content = Admin_showMain();
998 $content .= Admin_dodeletelink($_POST);
999
1000 $tpl->set_var( array( "ADMIN" => $content ));
1001
1002 showStartTemplate();
1003 exit;
1004 }
1005 else if (isset($_POST['EditCategory']))
1006 {
1007 $content = Admin_showMain();
1008 $content .= Admin_dodeletecat($_POST);
1009
1010 $tpl->set_var( array( "ADMIN" => $content ));
1011
1012 showStartTemplate();
1013 exit;
1014 }
1015 else if (isset($_POST['AddMainCategory']))
1016 {
1017 $content = Admin_showMain();
1018 $content .= Admin_doAddmain($_POST[title],
1019 $_POST[message]
1020 );
1021
1022 $tpl->set_var( array( "ADMIN" => $content ));
1023 showStartTemplate();
1024 exit;
1025
1026 }
1027 else if (isset($_POST['showAddsub']) or isset($_GET['showAddsub']))
1028 {
1029
1030
1031 if (isset($_GET['category']))
1032 {
1033 $categories = Admin_viewPage($_GET['category']);
1034 $your_current_location = Admin_display_category($_GET['category']);
1035 $tpl->set_var( array(
1036 "CATEGORIES" => $categories,
1037 "INFO" => $your_current_location
1038 ));
1039 }
1040 else
1041 {
1042 $categories_links = Admin_mainPage();
1043 $tpl->set_var( array(
1044 "CATEGORIES" => $categories_links
1045 ));
1046
1047 }
1048
1049 #$tpl->set_var( array( "ADMIN" => $content ));
1050
1051 showStartTemplate();
1052 exit;
1053
1054 }
1055 else if (isset($_GET['show_add_sub']))
1056 {
1057
1058 $content = Admin_showGiveAddsub($_GET['category']);
1059
1060 $tpl->set_var( array( "ADMIN" => $content ));
1061
1062 showStartTemplate();
1063 exit;
1064
1065 }
1066 else if (isset($_GET['show_edit_sub']))
1067 {
1068
1069 $content = Admin_showEditsub($_GET['category']);
1070
1071 $tpl->set_var( array( "ADMIN" => $content ));
1072
1073 showStartTemplate();
1074 exit;
1075
1076 }
1077 else if (isset($_POST['showWaiting']))
1078 {
1079
1080 $content = Admin_showwaiting();
1081
1082 $tpl->set_var( array( "ADMIN" => $content ));
1083 showStartTemplate();
1084 exit;
1085 }
1086
1087 else if (isset($_POST['showWaitingCat']))
1088 {
1089
1090 $content = Admin_showwaitingcat();
1091
1092 $tpl->set_var( array( "ADMIN" => $content ));
1093 showStartTemplate();
1094 exit;
1095 }
1096 else if (isset($_POST['ProcessWaiting']))
1097 {
1098
1099 $output = Admin_dowaiting($_POST);
1100 $content = Admin_showMain();
1101 $content .= $output;
1102
1103 uLinkCount();
1104
1105 $tpl->set_var( array( "ADMIN" => $content ));
1106 showStartTemplate();
1107 exit;
1108 }
1109 else if (isset($_POST['ProcessWaitingCat']))
1110 {
1111
1112 $output = Admin_dowaitingcat($_POST);
1113 $content = Admin_showMain();
1114 $content .= $output;
1115
1116 uLinkCount();
1117
1118 $tpl->set_var( array( "ADMIN" => $content ));
1119 showStartTemplate();
1120 exit;
1121 }
1122 else if (isset($_POST['showDeleteWaiting']))
1123 {
1124
1125 $content = Admin_showdeletewaiting();
1126
1127 $tpl->set_var( array( "ADMIN" => $content ));
1128 showStartTemplate();
1129 exit;
1130 }
1131
1132 else if (isset($_POST['ProcessDeleteWaiting']))
1133 {
1134 $output = Admin_dodeletewaiting($_POST);
1135 $content = Admin_showMain();
1136 $content .= $output;
1137
1138 uLinkCount();
1139
1140
1141 $tpl->set_var( array( "ADMIN" => $content ));
1142 showStartTemplate();
1143 exit;
1144 }
1145 else if (isset($_POST['AddSubCategory']))
1146 {
1147
1148 $content = Admin_showMain();
1149 $content .= Admin_doAddsub($_POST['category'],
1150 $_POST['title'],
1151 $_POST['message']
1152 );
1153
1154 $tpl->set_var( array( "ADMIN" => $content ));
1155 showStartTemplate();
1156 exit;
1157
1158 }
1159 else if (isset($_POST['uLinkCount']))
1160 {
1161 $content = Admin_showMain();
1162 $content .= uLinkCount();
1163
1164 $tpl->set_var( array( "ADMIN" => $content ));
1165 showStartTemplate();
1166 exit;
1167
1168 }
1169 else if (isset ($_GET["more"]))
1170 {
1171 $your_current_location = Message("details");
1172 $content = showMore($_GET["more"], $your_current_location, 0);
1173 $content .= "<br><hr><br>";
1174 $content .= showMore($_GET["more"], $your_current_location, 1);
1175 $tpl->set_var( array(
1176 "ADMIN" => $content,
1177 "CATEGORY_TITLE" => Message("admin_oldnew")
1178 ));
1179 showStartTemplate();
1180 exit;
1181 }
1182 else
1183 {
1184 $content = Admin_showMain();
1185
1186 $tpl->set_var( array( "ADMIN" => $content ));
1187 showStartTemplate();
1188 exit;
1189
1190 }
1191
1192
1193
1194 }
1195 else
1196 {
1197 $content = Message("not_authorized");
1198
1199 $tpl->set_var( array(
1200 "CATEGORY_TITLE" => Message("admin_forbidden"),
1201 "ADMIN" => $content
1202 ));
1203 showStartTemplate();
1204 exit;
1205 }
1206 }
1207 else
1208 {
1209 $content = Admin_authorize();
1210 $tpl->set_var( array(
1211 "CATEGORY_TITLE" => Message("admin_authreq"),
1212 "ADMIN" => $content
1213 ));
1214 showStartTemplate();
1215 exit;
1216 }
1217 ?>