2 /************************************************************************
3 * MXChange v0.2.1 Start: 08/31/2003 *
4 * =============== Last change: 11/23/2004 *
6 * -------------------------------------------------------------------- *
7 * File : admin-inc.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Administrative related functions *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Fuer die Administration benoetigte Funktionen *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
37 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42 function REGISTER_ADMIN ($user, $md5, $email=WEBMASTER)
45 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
46 array($user), __FILE__, __LINE__);
47 if (SQL_NUMROWS($result) == 0) {
48 // Ok, let's create the admin login
49 $result = SQL_QUERY_ESC("INSERT INTO "._MYSQL_PREFIX."_admins (login, password, email) VALUES('%s', '%s', '%s')",
50 array($user, $md5, $email), __FILE__, __LINE__);
54 SQL_FREERESULT($result);
56 // Login does already exist
61 // Only be executed on login procedure!
62 function CHECK_ADMIN_LOGIN ($admin_login, $password)
64 global $cacheArray, $_CONFIG, $cacheInstance;
65 $ret = "404"; $pass = "";
66 if (!empty($cacheArray['admins']['aid'][$admin_login])) {
67 // Get password from cache
68 $pass = $cacheArray['admins']['password'][$admin_login];
70 $_CONFIG['cache_hits']++;
72 // Get password from DB
73 $result = SQL_QUERY_ESC("SELECT password FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
74 array($admin_login), __FILE__, __LINE__);
75 if (SQL_NUMROWS($result) == 1) {
77 list($pass) = SQL_FETCHROW($result);
78 SQL_FREERESULT($result);
82 //* DEBUG: */ echo "*".$pass."/".md5($password)."/".$ret."<br />";
83 if ((strlen($pass) == 32) && ($pass == md5($password))) {
85 $pass = generateHash($password);
87 // Is the sql_patches not installed, than we cannot have a valid hashed password here!
88 if (($ret == "pass") && ((GET_EXT_VERSION("sql_patches") < "0.3.6") || (GET_EXT_VERSION("sql_patches") == ""))) $ret = "done";
89 } elseif ((GET_EXT_VERSION("sql_patches") < "0.3.6") || (GET_EXT_VERSION("sql_patches") == "")) {
94 // Generate salt of password
95 define('__SALT', substr($pass, 0, -40));
98 // Check if password is same
99 if (($ret == "pass") && ($pass == generateHash($password, $salt)) && (!empty($salt))) {
100 // Change the passord hash here
101 $pass = generateHash($password);
104 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET password='%s' WHERE login='%s' LIMIT 1",
105 array($pass, $admin_login), __FILE__, __LINE__);
107 // Shall I remove the cache file?
108 if ((EXT_IS_ACTIVE("cache")) && ($cacheInstance != false)) {
109 if ($cacheInstance->cache_file("admins", true)) $cacheInstance->cache_destroy();
112 // Login has failed by default... ;-)
115 // Password matches so login here
116 if (LOGIN_ADMIN($admin_login, $pass)) {
120 } elseif ((empty($salt)) && ($ret == "pass")) {
121 // Something bad went wrong
129 // Try to login the admin by setting some session/cookie variables
130 function LOGIN_ADMIN ($adminLogin, $passHash) {
131 // Now set all session variables and return the result
134 set_session("admin_md5", generatePassString($passHash))
136 set_session("admin_login", $adminLogin)
138 set_session("admin_last", time())
140 set_session("admin_to", $_POST['timeout'])
145 // Only be executed on cookie checking
146 function CHECK_ADMIN_COOKIES ($admin_login, $password) {
147 global $cacheArray, $_CONFIG;
148 $ret = "404"; $pass = "";
149 if (!empty($cacheArray['admins']['aid'][$admin_login])) {
150 // Get password from cache
151 $pass = $cacheArray['admins']['password'][$admin_login];
153 $_CONFIG['cache_hits']++;
155 // Get password from DB
156 $result = SQL_QUERY_ESC("SELECT password FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
157 array($admin_login), __FILE__, __LINE__);
158 if (SQL_NUMROWS($result) == 1) {
163 list($pass) = SQL_FETCHROW($result);
167 SQL_FREERESULT($result);
170 //* DEBUG: */ echo __FUNCTION__.":".$pass."(".strlen($pass).")/".$password."(".strlen($password).")<br />\n";
172 // Check if password matches
173 if (($ret == "pass") && ((generatePassString($pass) == $password) || ($pass == $password) || ((strlen($pass) == 32) && (md5($password) == $pass)))) {
174 // Passwords matches!
182 function admin_WriteData ($file, $comment, $prefix, $suffix, $DATA, $seek=0) {
183 // Initialize some variables
188 // Is the file there and read-/write-able?
189 if ((file_exists($file)) && (is_readable($file)) && (is_writeable($file))) {
190 $search = "CFG: ".$comment;
193 // Open the source file
194 $fp = @fopen($file, 'r') or OUTPUT_HTML("<STRONG>READ:</STRONG> ".$file."<br />");
196 // Is the resource valid?
197 if (is_resource($fp)) {
198 // Open temporary file
199 $fp_tmp = @fopen($tmp, 'w') or OUTPUT_HTML("<STRONG>WRITE:</STRONG> ".$tmp."<br />");
201 // Is the resource again valid?
202 if (is_resource($fp_tmp)) {
204 // Read from source file
205 $line = fgets ($fp, 1024);
207 if (strpos($line, $search) > -1) { $next = 0; $found = true; }
210 if ($next == $seek) {
212 $line = $prefix . $DATA . $suffix."\n";
218 // Write to temp file
219 fputs($fp_tmp, $line);
225 // Finished writing tmp file
232 if (($done) && ($found)) {
233 // Copy back tmp file and delete tmp :-)
236 define('_FATAL', false);
238 OUTPUT_HTML("<STRONG>CHANGE:</STRONG> 404!");
239 define('_FATAL', true);
241 OUTPUT_HTML("<STRONG>TMP:</STRONG> UNDONE!");
242 define('_FATAL', true);
246 // File not found, not readable or writeable
247 OUTPUT_HTML("<STRONG>404:</STRONG> ".$file."<br />");
252 function ADMIN_DO_ACTION($wht)
254 global $menuDesription, $menuTitle, $_CONFIG, $cacheArray, $link, $DATA, $DEPTH;
255 //* DEBUG: */ echo __LINE__."*".$wht."/".$GLOBALS['module']."/".$GLOBALS['action']."/".$GLOBALS['what']."*<br />\n";
256 if (EXT_IS_ACTIVE("cache"))
258 // Include cache instance
259 global $cacheInstance;
262 // Remove any spaces from variable
265 // Default admin action is the overview page
270 // Compile out some chars
271 $wht = COMPILE_CODE($wht, false, false, false);
275 $act = GET_ACTION($GLOBALS['module'], $wht);
277 // Define admin login name and ID number
278 define('__ADMIN_LOGIN', SQL_ESCAPE(get_session('admin_login')));
279 define('__ADMIN_ID' , GET_ADMIN_ID(get_session('admin_login')));
282 if (EXT_IS_ACTIVE("admins")) {
283 define('__ADMIN_WELCOME', LOAD_TEMPLATE("admin_welcome_admins", true));
285 define('__ADMIN_WELCOME', LOAD_TEMPLATE("admin_welcome", true));
287 define('__ADMIN_FOOTER' , LOAD_TEMPLATE("admin_footer" , true));
288 define('__ADMIN_MENU' , ADD_ADMIN_MENU($act, $wht, true));
291 LOAD_TEMPLATE("admin_main_header");
293 // Check if action/what pair is valid
294 $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_admin_menu
295 WHERE action='%s' AND ((what='%s' AND what != 'overview') OR (what='' AND '%s'='overview'))
296 LIMIT 1", array($act, $wht, $wht), __FILE__, __LINE__);
297 if (SQL_NUMROWS($result) == 1)
300 SQL_FREERESULT($result);
302 // Is valid but does the inlcude file exists?
303 $INC = sprintf(PATH."inc/modules/admin/action-%s.php", $act);
304 if ((file_exists($INC)) && (is_readable($INC)) && (VALIDATE_MENU_ACTION("admin", $act, $wht)) && (__ACL_ALLOW == true))
306 // Ok, we finally load the admin action module
309 elseif (__ACL_ALLOW == false)
312 LOAD_TEMPLATE("admin_menu_failed", false, ADMINS_ACCESS_DENIED);
313 ADD_FATAL(ADMINS_ACCESS_DENIED);
317 // Include file not found! :-(
318 LOAD_TEMPLATE("admin_menu_failed", false, ADMIN_404_ACTION);
319 ADD_FATAL(ADMIN_404_ACTION_1.$act.ADMIN_404_ACTION_2);
322 // Invalid action/what pair found!
323 LOAD_TEMPLATE("admin_menu_failed", false, ADMIN_INVALID_ACTION);
324 ADD_FATAL(ADMIN_INVALID_ACTION_1.$act."/".$wht.ADMIN_INVALID_ACTION_2);
328 LOAD_TEMPLATE("admin_main_footer");
331 function ADD_ADMIN_MENU($act, $wht,$return=false)
333 global $menuDesription, $menuTitle, $link;
337 $menuDesription = array();
338 $menuTitle = array();
341 $result_main = SQL_QUERY("SELECT action, title, descr FROM "._MYSQL_PREFIX."_admin_menu WHERE what='' ORDER BY sort, id DESC", __FILE__, __LINE__);
343 if (SQL_NUMROWS($result_main) > 0)
345 $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_menu_main\">
346 <TR><TD colspan=\"2\" height=\"7\" class=\"seperator\"> </TD></TR>\n";
347 while (list($menu, $title, $descr) = SQL_FETCHROW($result_main))
349 if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2"))
351 $ACL = ADMINS_CHECK_ACL($menu, "");
355 // ACL is "allow"... hmmm
362 // Insert compiled menu title and description
363 $menuTitle[$menu] = $title;
364 $menuDesription[$menu] = $descr;
367 <TD class=\"admin_menu\" colspan=\"2\">
368 <NOBR> <STRONG>·</STRONG> ";
369 if (($menu == $act) && (empty($wht)))
375 $OUT .= "[ <A href=\"".URL."/modules.php?module=admin&action=".$menu."\">";
378 if (($menu == $act) && (empty($wht)))
384 $OUT .= "</A> ]";
386 $OUT .= "</NOBR></TD>
388 $result_what = SQL_QUERY_ESC("SELECT what, title, descr FROM "._MYSQL_PREFIX."_admin_menu WHERE action='%s' AND what != '' ORDER BY sort, id DESC",
389 array($menu), __FILE__, __LINE__);
390 if ((SQL_NUMROWS($result_what) > 0) && ($act == $menu))
392 $menuDesription = array();
393 $menuTitle = array(); $SUB = true;
395 <TD width=\"10\" class=\"seperator\"> </TD>
396 <TD class=\"admin_menu\">
397 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_menu_sub\">\n";
398 while (list($wht_sub, $title_what, $desc_what) = SQL_FETCHROW($result_what))
401 $INC = sprintf(PATH."inc/modules/admin/what-%s.php", $wht_sub);
402 if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2"))
404 $ACL = ADMINS_CHECK_ACL("", $wht_sub);
408 // ACL is "allow"... hmmm
411 $readable = ((file_exists($INC)) && (is_readable($INC)));
414 // Insert compiled title and description
415 $menuTitle[$wht_sub] = $title_what;
416 $menuDesription[$wht_sub] = $desc_what;
418 <TD class=\"admin_menu\" colspan=\"2\">
419 <NOBR> <STRONG>--></STRONG> ";
422 if ($wht == $wht_sub)
428 $OUT .= "[ <A href=\"".URL."/modules.php?module=admin&what=".$wht_sub."\">";
433 $OUT .= "<I class=\"admin_note\">";
438 if ($wht == $wht_sub)
444 $OUT .= "</A> ]";
451 $OUT .= "</NOBR></TD>
457 SQL_FREERESULT($result_what);
462 $OUT .= "<TR><TD height=\"7\" colspan=\"2\"></TD></TR>\n";
467 SQL_FREERESULT($result_main);
468 $OUT .= "</TABLE>\n";
471 // Compile and run the code here. This inserts all constants into the
472 // HTML output. Costs me some time to figure this out... *sigh* Quix0r
473 $eval = "\$OUT = \"".COMPILE_CODE(addslashes($OUT))."\";";
476 // Return or output content?
484 function ADD_MEMBER_SELECTION_BOX($add_all = false, $return = false, $none = false, $def = "0")
486 // Output selection form with all confirmed user accounts listed
487 $result = SQL_QUERY("SELECT userid, surname, family FROM "._MYSQL_PREFIX."_user_data ORDER BY userid", __FILE__, __LINE__);
490 // USe this only for adding points (e.g. adding refs really makes no sence ;-) )
491 if ($add_all) $OUT = " <OPTION value=\"all\">".ALL_MEMBERS."</OPTION>\n";
492 elseif ($none) $OUT = " <OPTION value=\"0\">".SELECT_NONE."</OPTION>\n";
493 while (list($id, $sname, $fname) = SQL_FETCHROW($result))
495 $OUT .= " <OPTION value=\"".$id."\"";
496 if ($def == $id) $OUT .= " selected=\"selected\"";
497 $OUT .= ">".$sname." ".$fname." (".$id.")</OPTION>\n";
501 SQL_FREERESULT($result);
503 // Remeber options in constant
504 define('_MEMBER_SELECTION', $OUT);
507 // Display selection box
508 define('__LANG_VALUE', GET_LANGUAGE());
511 LOAD_TEMPLATE("admin_member_selection_box", false, $GLOBALS['what']);
515 function ADMIN_MENU_SELECTION($MODE, $default="", $defid="") {
517 if ($MODE == "action") $wht = "what='' AND action !='login'";
518 $result = SQL_QUERY_ESC("SELECT %s, title FROM "._MYSQL_PREFIX."_admin_menu WHERE ".$wht." ORDER BY sort",
519 array($MODE), __FILE__, __LINE__);
520 if (SQL_NUMROWS($result) > 0)
522 // Load menu as selection
523 $OUT = "<SELECT name=\"".$MODE."_menu";
524 if ((!empty($defid)) || ($defid == "0")) $OUT .= "[".$defid."]";
525 $OUT .= "\" size=\"1\" class=\"admin_select\">
526 <OPTION value=\"\">".SELECT_NONE."</OPTION>\n";
527 while (list($menu, $title) = SQL_FETCHROW($result))
529 $OUT .= " <OPTION value=\"".$menu."\"";
530 if ((!empty($default)) && ($default == $menu)) $OUT .= " selected=\"selected\"";
531 $OUT .= ">".$title."</OPTION>\n";
535 SQL_FREERESULT($result);
536 $OUT .= "</SELECT>\n";
541 $OUT = ADMIN_PROBLEM_NO_MENU;
548 function ADMIN_SAVE_SETTINGS (&$POST, $tableName="_config", $whereStatement="config=0", $translateComma = array(), $alwaysAdd=false)
550 global $_CONFIG, $cacheArray, $cacheInstance;
552 $skip = false; $TEST2 = "";
553 foreach ($POST as $id=>$val) {
554 // Process only formular field but not submit buttons ;)
556 // Do not save the ok value
557 $TEST = substr($id, -3);
558 if ((($TEST == "_ye") || ($TEST == "_mo") || ($TEST == "_we") || ($TEST == "_da") || ($TEST == "_ho") || ($TEST == "_mi") || ($TEST == "_se")) && (isset($val))) {
559 // Found a multi-selection for timings?
560 $TEST = substr($id, 0, -3);
561 if ((isset($POST[$TEST."_ye"])) && (isset($POST[$TEST."_mo"])) && (isset($POST[$TEST."_we"])) && (isset($POST[$TEST."_da"])) && (isset($POST[$TEST."_ho"])) && (isset($POST[$TEST."_mi"])) && (isset($POST[$TEST."_se"])) && ($TEST != $TEST2)) {
562 // Generate timestamp
563 $POST[$TEST] = CREATE_TIMESTAMP_FROM_SELECTIONS($TEST, $POST);
564 $DATA[] = "$TEST='".$POST[$TEST]."'";
566 // Remove data from array
567 unset($POST[$TEST."_ye"]);
568 unset($POST[$TEST."_mo"]);
569 unset($POST[$TEST."_we"]);
570 unset($POST[$TEST."_da"]);
571 unset($POST[$TEST."_ho"]);
572 unset($POST[$TEST."_mi"]);
573 unset($POST[$TEST."_se"]);
576 unset($id); $skip = true; $TEST2 = $TEST;
579 // Process this entry
580 $skip = false; $TEST2 = "";
583 // Shall we process this ID? It muss not be empty, of course
584 if ((!$skip) && (!empty($id))) {
586 $val = COMPILE_CODE($val);
588 // Translate the value? (comma to dot!)
589 if ((is_array($translateComma)) && (in_array($id, $translateComma))) {
590 // Then do it here... :)
591 $val = str_replace(",", ".", $val);
594 // Shall we add numbers or strings?
596 if ("".$val."" == "".$test."") {
598 $DATA[] = $id."=".$val."";
601 $DATA[] = $id."='".trim($val)."'";
604 // Update current configuration
605 $_CONFIG[$id] = $val;
610 // Check if entry does exist
613 if (!empty($whereStatement)) {
614 $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX.$tableName." WHERE ".$whereStatement." LIMIT 1", __FILE__, __LINE__);
616 $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX.$tableName." LIMIT 1", __FILE__, __LINE__);
620 if (SQL_NUMROWS($result) == 1) {
621 // "Implode" all data to single string
622 $DATA_UPDATE = implode(", ", $DATA);
624 // Generate SQL string
625 $SQL = "UPDATE "._MYSQL_PREFIX.$tableName." SET ".$DATA_UPDATE." WHERE ".$whereStatement." LIMIT 1";
627 // Add Line (does only work with auto_increment!
628 $KEYs = array(); $VALUEs = array();
629 foreach ($DATA as $entry) {
631 $line = explode("=", $entry);
632 $KEYs[] = $line[0]; $VALUEs[] = $line[1];
635 // Add both in one line
636 $KEYs = implode(", ", $KEYs);
637 $VALUEs = implode(", ", $VALUEs);
639 // Generate SQL string
640 $SQL = "INSERT INTO "._MYSQL_PREFIX.$tableName." (".$KEYs.") VALUES(".$VALUEs.")";
644 SQL_FREERESULT($result);
646 // Simply run generated SQL string
647 $result = SQL_QUERY($SQL, __FILE__, __LINE__);
649 // Is the config table updated and the cache extension installed?
650 if ((GET_EXT_VERSION("cache") >= "0.1.2") && ($tableName == "_config")) {
652 if ($cacheInstance->cache_file("config", true)) $cacheInstance->cache_destroy();
657 LOAD_TEMPLATE("admin_settings_saved", false, "<STRONG class=\"admin_done\">".SETTINGS_SAVED."</STRONG>");
660 function ADMIN_MAKE_MENU_SELECTION($menu, $type, $name, $default="") {
661 // Init the selection box
662 $OUT = "<SELECT name=\"".$name."\" class=\"admin_select\" size=\"1\">\n <OPTION value=\"\">".IS_TOP_MENU."</OPTION>\n";
664 // Open the requested menu directory
665 $handle = opendir(PATH."inc/modules/".$menu."/") or mxchange_die("Cannot load menu ".$menu."!");
666 while ($file = readdir($handle)) {
667 // Is this a PHP script?
668 if (($file != ".") && ($file != "..") && ($file != "lost+found") && (strpos($file, "".$type."-") > -1) && (strpos($file, ".php") > 0)) {
669 // Then test if the file is readable
670 $test = PATH."inc/modules/".$menu."/".$file;
671 if (is_readable($test)) {
672 // Extract the value for what=xxx
673 $part = substr($file, (strlen($type) + 1)); $part = substr($part, 0, strpos($part, ".php"));
675 // Is that part different from the overview?
676 if ($part != "overview") {
677 $OUT .= " <OPTION value=\"".$part."\"";
678 if ($part == $default) $OUT .= "selected";
679 $OUT .= ">".$part."</OPTION>\n";
685 $OUT .= "</SELECT>\n";
689 function ADMIN_USER_PROFILE_LINK($uid, $title="", $wht="list_user")
691 if (($title == "") && ($title != "0")) { $title = $uid; }
692 if (($title == "0") && ($wht == "list_refs"))
694 // Return title again
698 //* DEBUG: */ echo "A:".$title."<br />";
700 return "<A href=\"".URL."/modules.php?module=admin&what=".$wht."&u_id=".$uid."\" title=\"".ADMIN_USER_PROFILE_TITLE."\">".$title."</A>";
703 function ADMIN_CHECK_MENU_MODE()
705 global $_CONFIG, $cacheArray;
707 // Set the global mode as the mode for all admins
708 $MODE = $_CONFIG['admin_menu']; $ADMIN = $MODE;
710 // Check individual settings of current admin
711 if (isset($cacheArray['admins']['la_mode'][get_session('admin_login')]))
714 $ADMIN = $cacheArray['admins']['la_mode'][get_session('admin_login')];
715 $_CONFIG['cache_hits']++;
717 elseif (GET_EXT_VERSION("admins") >= "0.6.7")
719 // Load from database when version of "admins" is enough
720 $result = SQL_QUERY_ESC("SELECT la_mode FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
721 array(get_session('admin_login')), __FILE__, __LINE__);
722 if (SQL_NUMROWS($result) == 1)
725 list($ADMIN) = SQL_FETCHROW($result);
729 SQL_FREERESULT($result);
732 // Check what the admin wants and set it when it's not the global mode
733 if ($ADMIN != "global") $MODE = $ADMIN;
735 // Return admin-menu's mode
738 // Change activation status
739 function ADMIN_CHANGE_ACTIVATION_STATUS ($IDs, $table, $row, $idRow = "id") {
741 $cnt = 0; $newStatus = 'Y';
742 if ((is_array($IDs)) && (count($IDs) > 0)) {
743 // "Walk" all through and count them
744 foreach ($IDs as $id=>$selected) {
745 // Secure the ID number
746 $id = bigintval($id);
748 // Should always be 1 ;-)
749 if ($selected == 1) {
750 // Determine new status
751 $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_%s WHERE %s=%d LIMIT 1",
752 array($row, $table, $idRow, $id), __FILE__, __LINE__);
755 if (SQL_NUMROWS($result) == 1) {
757 list($currStatus) = SQL_FETCHROW($result);
758 if ($currStatus == 'Y') $newStatus='N'; else $newStatus = 'Y';
760 // Change this status
761 SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_%s SET %s='%s' WHERE %s=%d LIMIT 1",
762 array($table, $row, $newStatus, $idRow, $id), __FILE__, __LINE__);
764 // Count up affected rows
765 $cnt += SQL_AFFECTEDROWS();
769 SQL_FREERESULT($result);
774 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_STATUS_CHANGED_1.$cnt.ADMIN_STATUS_CHANGED_2.count($IDs).ADMIN_STATUS_CHANGED_3);
777 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NOTHING_SELECTED_CHANGE);
780 // Delete rows by given ID numbers
781 function ADMIN_DELETE_ENTRIES_CONFIRM ($IDs, $table, $row, $columns = array(), $filterFunctions = array(), $deleteNow=false, $idRow="id") {
784 if ((is_array($IDs)) && (count($IDs) > 0)) {
785 // "Walk" through all entries and count them
789 // List for confirmation
790 foreach ($IDs as $id=>$selected) {
792 $id = bigintval($id);
794 // Will always be 1 ;-)
795 if ($selected == 1) {
796 // Get result from a given column array and table name
797 $result = SQL_RESULT_FROM_ARRAY($table, $columns, $idRow, $id);
799 // Is there one entry?
800 if (SQL_NUMROWS($result) == 1) {
802 $content = SQL_FETCHARRAY($result);
805 foreach ($content as $key=>$value) {
806 // Is a filter function set?
807 $idx = array_search($key, $columns, true);
808 if (!empty($filterFunctions[$idx])) {
810 $content[$key] = call_user_func($filterFunctions[$idx], $value);
814 // Add color switching
815 $content['sw'] = $SW;
817 // Then list it again...
818 $OUT .= LOAD_TEMPLATE("admin_del_".$table."_row", true, $content);
823 SQL_FREERESULT($result);
827 // Load master template
828 LOAD_TEMPLATE("admin_del_".$table."", false, $OUT);