e5800717542af3b059bd36bd067b66ea704afb78
[mailer.git] / inc / modules / admin / admin-inc.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/31/2003 *
4  * ===============                              Last change: 11/23/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : admin-inc.php                                    *
8  * -------------------------------------------------------------------- *
9  * Short description : Administrative related functions                 *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Fuer die Administration benoetigte Funktionen    *
12  * -------------------------------------------------------------------- *
13  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
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.                                  *
22  *                                                                      *
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.                         *
27  *                                                                      *
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,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if (ereg(basename(__FILE__), $_SERVER['PHP_SELF']))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40
41 //
42 function REGISTER_ADMIN ($user, $md5, $email=WEBMASTER)
43 {
44         $ret = "failed";
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__);
51                 $ret = "done";
52         } else {
53                 // Free memory
54                 SQL_FREERESULT($result);
55
56                 // Login does already exist
57                 $ret = "already";
58         }
59         return $ret;
60 }
61 // Only be executed on login procedure!
62 function CHECK_ADMIN_LOGIN ($admin_login, $password)
63 {
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];
69                 $ret = "pass";
70                 $_CONFIG['cache_hits']++;
71         } else {
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) {
76                         $ret = "pass";
77                         list($pass) = SQL_FETCHROW($result);
78                         SQL_FREERESULT($result);
79                 }
80         }
81
82         //* DEBUG: */ echo "*".$pass."/".md5($password)."/".$ret."<br />";
83         if ((strlen($pass) == 32) && ($pass == md5($password))) {
84                 // Generate new hash
85                 $pass = generateHash($password);
86
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") == "")) {
90                 // Old hashing way
91                 return $ret;
92         }
93
94         // Generate salt of password
95         define('__SALT', substr($pass, 0, -40));
96         $salt = __SALT;
97
98         // Check if password is same
99         //* DEBUG: */ echo "*".$ret.",".$pass.",".$password.",".$salt."*<br >\n";
100         if (($ret == "pass") && ($pass == generateHash($password, $salt)) && (!empty($salt)))   {
101                 // Change the passord hash here
102                 $pass = generateHash($password);
103
104                 // Update password
105                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET password='%s' WHERE login='%s' LIMIT 1",
106                  array($pass, $admin_login), __FILE__, __LINE__);
107
108                 // Shall I remove the cache file?
109                 if ((EXT_IS_ACTIVE("cache")) && ($cacheInstance != false)) {
110                         if ($cacheInstance->cache_file("admins", true)) $cacheInstance->cache_destroy();
111                 }
112
113                 // Login has failed by default... ;-)
114                 $ret = "failed";
115
116                 // Password matches so login here
117                 if (LOGIN_ADMIN($admin_login, $pass)) {
118                         // All done now
119                         $ret = "done";
120                 }
121         } elseif ((empty($salt)) && ($ret == "pass")) {
122                 // Something bad went wrong
123                 $ret = "failed";
124         } elseif ($ret == "done") {
125                 // Try to login here if we have the old hashing way (sql_patches not installed?)
126                 if (!LOGIN_ADMIN($admin_login, $pass)) {
127                         // Something went wrong
128                         $ret = "failed";
129                 }
130         }
131
132         // Return the result
133         //* DEBUG: */ die("RETURN=".$ret);
134         return $ret;
135 }
136
137 // Try to login the admin by setting some session/cookie variables
138 function LOGIN_ADMIN ($adminLogin, $passHash) {
139         // Now set all session variables and return the result
140         return (
141                 (
142                         set_session("admin_md5", generatePassString($passHash))
143                 ) && (
144                         set_session("admin_login", $adminLogin)
145                 ) && (
146                         set_session("admin_last", time())
147                 ) && (
148                         set_session("admin_to", $_POST['timeout'])
149                 )
150         );
151 }
152
153 // Only be executed on cookie checking
154 function CHECK_ADMIN_COOKIES ($admin_login, $password) {
155         global $cacheArray, $_CONFIG;
156         $ret = "404"; $pass = "";
157         if (!empty($cacheArray['admins']['aid'][$admin_login])) {
158                 // Get password from cache
159                 $pass = $cacheArray['admins']['password'][$admin_login];
160                 $ret = "pass";
161                 $_CONFIG['cache_hits']++;
162         } else {
163                 // Get password from DB
164                 $result = SQL_QUERY_ESC("SELECT password FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
165                  array($admin_login), __FILE__, __LINE__);
166                 if (SQL_NUMROWS($result) == 1) {
167                         // Entry found
168                         $ret = "pass";
169
170                         // Fetch password
171                         list($pass) = SQL_FETCHROW($result);
172                 }
173
174                 // Free result
175                 SQL_FREERESULT($result);
176         }
177
178         //* DEBUG: */ echo __FUNCTION__.":".$pass."(".strlen($pass).")/".$password."(".strlen($password).")<br />\n";
179
180         // Check if password matches
181         if (($ret == "pass") && ((generatePassString($pass) == $password) || ($pass == $password) || ((strlen($pass) == 32) && (md5($password) == $pass)))) {
182                 // Passwords matches!
183                 $ret = "done";
184         }
185
186         // Return result
187         return $ret;
188 }
189 //
190 function admin_WriteData ($file, $comment, $prefix, $suffix, $DATA, $seek=0) {
191         // Initialize some variables
192         $done = false;
193         $seek++;
194         $found = false;
195
196         // Is the file there and read-/write-able?
197         if ((FILE_READABLE($file)) && (is_writeable($file))) {
198                 $search = "CFG: ".$comment;
199                 $tmp = $file.".tmp";
200
201                 // Open the source file
202                 $fp = @fopen($file, 'r') or OUTPUT_HTML("<STRONG>READ:</STRONG> ".$file."<br />");
203
204                 // Is the resource valid?
205                 if (is_resource($fp)) {
206                         // Open temporary file
207                         $fp_tmp = @fopen($tmp, 'w') or OUTPUT_HTML("<STRONG>WRITE:</STRONG> ".$tmp."<br />");
208
209                         // Is the resource again valid?
210                         if (is_resource($fp_tmp)) {
211                                 while (!feof($fp)) {
212                                         // Read from source file
213                                         $line = fgets ($fp, 1024);
214
215                                         if (strpos($line, $search) > -1) { $next = 0; $found = true; }
216
217                                         if ($next > -1) {
218                                                 if ($next == $seek) {
219                                                         $next = -1;
220                                                         $line = $prefix . $DATA . $suffix."\n";
221                                                 } else {
222                                                         $next++;
223                                                 }
224                                         }
225
226                                         // Write to temp file
227                                         fputs($fp_tmp, $line);
228                                 }
229
230                                 // Close temp file
231                                 fclose($fp_tmp);
232
233                                 // Finished writing tmp file
234                                 $done = true;
235                         }
236
237                         // Close source file
238                         fclose($fp);
239
240                         if (($done) && ($found)) {
241                                 // Copy back tmp file and delete tmp :-)
242                                 @copy($tmp, $file);
243                                 @unlink($tmp);
244                                 define('_FATAL', false);
245                         } elseif (!$found) {
246                                 OUTPUT_HTML("<STRONG>CHANGE:</STRONG> 404!");
247                                 define('_FATAL', true);
248                         } else {
249                                 OUTPUT_HTML("<STRONG>TMP:</STRONG> UNDONE!");
250                                 define('_FATAL', true);
251                         }
252                 }
253         } else {
254                 // File not found, not readable or writeable
255                 OUTPUT_HTML("<STRONG>404:</STRONG> ".$file."<br />");
256         }
257 }
258
259 //
260 function ADMIN_DO_ACTION($wht)
261 {
262         global $menuDesription, $menuTitle, $_CONFIG, $cacheArray, $DATA, $DEPTH;
263         //* DEBUG: */ echo __LINE__."*".$wht."/".$GLOBALS['module']."/".$GLOBALS['action']."/".$GLOBALS['what']."*<br />\n";
264         if (EXT_IS_ACTIVE("cache"))
265         {
266                 // Include cache instance
267                 global $cacheInstance;
268         }
269
270         // Remove any spaces from variable
271         if (empty($wht))
272         {
273                 // Default admin action is the overview page
274                 $wht = "overview";
275         }
276          else
277         {
278                 // Compile out some chars
279                 $wht = COMPILE_CODE($wht, false, false, false);
280         }
281
282         // Get action value
283         $act = GET_ACTION($GLOBALS['module'], $wht);
284
285         // Define admin login name and ID number
286         define('__ADMIN_LOGIN', get_session('admin_login'));
287         define('__ADMIN_ID'   , GET_ADMIN_ID(get_session('admin_login')));
288
289         // Preload templates
290         if (EXT_IS_ACTIVE("admins")) {
291                 define('__ADMIN_WELCOME', LOAD_TEMPLATE("admin_welcome_admins", true));
292         } else {
293                 define('__ADMIN_WELCOME', LOAD_TEMPLATE("admin_welcome", true));
294         }
295         define('__ADMIN_FOOTER' , LOAD_TEMPLATE("admin_footer" , true));
296         define('__ADMIN_MENU'   , ADD_ADMIN_MENU($act, $wht, true));
297
298         // Tableset header
299         LOAD_TEMPLATE("admin_main_header");
300
301         // Check if action/what pair is valid
302         $result = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_admin_menu
303 WHERE action='%s' AND ((what='%s' AND what != 'overview') OR ((what='' OR what IS NULL) AND '%s'='overview'))
304 LIMIT 1", array($act, $wht, $wht), __FILE__, __LINE__);
305         if (SQL_NUMROWS($result) == 1)
306         {
307                 // Free memory
308                 SQL_FREERESULT($result);
309
310                 // Is valid but does the inlcude file exists?
311                 $INC = sprintf("%sinc/modules/admin/action-%s.php", PATH, $act);
312                 if ((FILE_READABLE($INC)) && (VALIDATE_MENU_ACTION("admin", $act, $wht)) && (__ACL_ALLOW == true))
313                 {
314                         // Ok, we finally load the admin action module
315                         include($INC);
316                 }
317                  elseif (__ACL_ALLOW == false)
318                 {
319                         // Access denied
320                         LOAD_TEMPLATE("admin_menu_failed", false, ADMINS_ACCESS_DENIED);
321                         ADD_FATAL(ADMINS_ACCESS_DENIED);
322                 }
323                  else
324                 {
325                         // Include file not found! :-(
326                         LOAD_TEMPLATE("admin_menu_failed", false, ADMIN_404_ACTION);
327                         ADD_FATAL(ADMIN_404_ACTION_1.$act.ADMIN_404_ACTION_2);
328                 }
329         } else {
330                 // Invalid action/what pair found!
331                 LOAD_TEMPLATE("admin_menu_failed", false, ADMIN_INVALID_ACTION);
332                 ADD_FATAL(ADMIN_INVALID_ACTION_1.$act."/".$wht.ADMIN_INVALID_ACTION_2);
333         }
334
335         // Tableset footer
336         LOAD_TEMPLATE("admin_main_footer");
337 }
338 //
339 function ADD_ADMIN_MENU($act, $wht,$return=false)
340 {
341         global $menuDesription, $menuTitle;
342         $SUB = false;
343
344         // Menu descriptions
345         $menuDesription = array();
346         $menuTitle = array();
347
348         // Build main menu
349         $result_main = SQL_QUERY("SELECT action, title, descr FROM "._MYSQL_PREFIX."_admin_menu WHERE (what='' OR what IS NULL) ORDER BY sort, id DESC", __FILE__, __LINE__);
350         $OUT = "";
351         if (SQL_NUMROWS($result_main) > 0)
352         {
353                 $OUT = "<TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_menu_main\">
354 <TR><TD colspan=\"2\" height=\"7\" class=\"seperator\">&nbsp;</TD></TR>\n";
355                 while (list($menu, $title, $descr) = SQL_FETCHROW($result_main))
356                 {
357                         if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2"))
358                         {
359                                 $ACL = ADMINS_CHECK_ACL($menu, "");
360                         }
361                          else
362                         {
363                                 // ACL is "allow"... hmmm
364                                 $ACL = true;
365                         }
366                         if ($ACL)
367                         {
368                                 if (!$SUB)
369                                 {
370                                         // Insert compiled menu title and description
371                                         $menuTitle[$menu]        = $title;
372                                         $menuDesription[$menu] = $descr;
373                                 }
374                                 $OUT .= "<TR>
375         <TD class=\"admin_menu\" colspan=\"2\">
376                 <NOBR>&nbsp;<STRONG>&middot;</STRONG>&nbsp;";
377                                         if (($menu == $act) && (empty($wht)))
378                                 {
379                                         $OUT .= "<STRONG>";
380                                 }
381                                  else
382                                 {
383                                         $OUT .= "[<A href=\"".URL."/modules.php?module=admin&amp;action=".$menu."\">";
384                                 }
385                                 $OUT .= $title;
386                                         if (($menu == $act) && (empty($wht)))
387                                 {
388                                         $OUT .= "</STRONG>";
389                                 }
390                                  else
391                                 {
392                                         $OUT .= "</A>]";
393                                 }
394                                 $OUT .= "</NOBR></TD>
395 </TR>\n";
396                                 $result_what = SQL_QUERY_ESC("SELECT what, title, descr FROM "._MYSQL_PREFIX."_admin_menu WHERE action='%s' AND what != '' ORDER BY sort, id DESC",
397                                  array($menu), __FILE__, __LINE__);
398                                 if ((SQL_NUMROWS($result_what) > 0) && ($act == $menu))
399                                 {
400                                         $menuDesription = array();
401                                         $menuTitle = array(); $SUB = true;
402                                         $OUT .= "<TR>
403         <TD width=\"10\" class=\"seperator\">&nbsp;</TD>
404         <TD class=\"admin_menu\">
405                 <TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"admin_menu_sub\">\n";
406                                                 while (list($wht_sub, $title_what, $desc_what) = SQL_FETCHROW($result_what))
407                                         {
408                                                 // Filename
409                                                 $INC = sprintf("%sinc/modules/admin/what-%s.php", PATH, $wht_sub);
410                                                 if ((EXT_IS_ACTIVE("admins")) && (GET_EXT_VERSION("admins") > "0.2"))
411                                                 {
412                                                         $ACL = ADMINS_CHECK_ACL("", $wht_sub);
413                                                 }
414                                                  else
415                                                 {
416                                                         // ACL is "allow"... hmmm
417                                                         $ACL = true;
418                                                 }
419                                                 $readable = FILE_READABLE($INC);
420                                                 if ($ACL)
421                                                 {
422                                                         // Insert compiled title and description
423                                                         $menuTitle[$wht_sub]        = $title_what;
424                                                         $menuDesription[$wht_sub] = $desc_what;
425                                                         $OUT .= "<TR>
426         <TD class=\"admin_menu\" colspan=\"2\">
427                 <NOBR>&nbsp;<STRONG>--&gt;</STRONG>&nbsp;";
428                                                         if ($readable)
429                                                         {
430                                                                 if ($wht == $wht_sub)
431                                                                 {
432                                                                         $OUT .= "<STRONG>";
433                                                                 }
434                                                                  else
435                                                                 {
436                                                                         $OUT .= "[<A href=\"".URL."/modules.php?module=admin&amp;what=".$wht_sub."\">";
437                                                                 }
438                                                         }
439                                                          else
440                                                         {
441                                                                 $OUT .= "<I class=\"admin_note\">";
442                                                         }
443                                                         $OUT .= $title_what;
444                                                         if ($readable)
445                                                         {
446                                                                 if ($wht == $wht_sub)
447                                                                 {
448                                                                         $OUT .= "</STRONG>";
449                                                                 }
450                                                                  else
451                                                                 {
452                                                                         $OUT .= "</A>]";
453                                                                 }
454                                                         }
455                                                          else
456                                                         {
457                                                                 $OUT .= "</I>";
458                                                         }
459                                                         $OUT .= "</NOBR></TD>
460 </TR>\n";
461                                                 }
462                                         }
463
464                                         // Free memory
465                                         SQL_FREERESULT($result_what);
466                                         $OUT .= "    </TABLE>
467         </TD>
468 </TR>\n";
469                                 }
470                                 $OUT .= "<TR><TD height=\"7\" colspan=\"2\"></TD></TR>\n";
471                         }
472                 }
473
474                 // Free memory
475                 SQL_FREERESULT($result_main);
476                 $OUT .= "</TABLE>\n";
477         }
478
479         // Compile and run the code here. This inserts all constants into the
480         // HTML output. Costs me some time to figure this out... *sigh* Quix0r
481         $eval = "\$OUT = \"".COMPILE_CODE(addslashes($OUT))."\";";
482         eval($eval);
483
484         // Return or output content?
485         if ($return) {
486                 return $OUT;
487         } else {
488                 OUTPUT_HTML($OUT);
489         }
490 }
491 //
492 function ADD_MEMBER_SELECTION_BOX ($def="0", $add_all=false, $return=false, $none=false)
493 {
494         // Output selection form with all confirmed user accounts listed
495         $result = SQL_QUERY("SELECT userid, surname, family FROM "._MYSQL_PREFIX."_user_data ORDER BY userid", __FILE__, __LINE__);
496         $OUT = "";
497
498         // USe this only for adding points (e.g. adding refs really makes no sence ;-) )
499         if ($add_all) $OUT = "      <OPTION value=\"all\">".ALL_MEMBERS."</OPTION>\n";
500          elseif ($none) $OUT = "      <OPTION value=\"0\">".SELECT_NONE."</OPTION>\n";
501         while (list($id, $sname, $fname) = SQL_FETCHROW($result))
502         {
503                 $OUT .= "      <OPTION value=\"".bigintval($id)."\"";
504                 if ($def == $id) $OUT .= " selected=\"selected\"";
505                 $OUT .= ">".$sname." ".$fname." (".bigintval($id).")</OPTION>\n";
506         }
507
508         // Free memory
509         SQL_FREERESULT($result);
510
511         if (!$return) {
512                 // Remeber options in constant
513                 define('_MEMBER_SELECTION', $OUT);
514
515                 // Display selection box
516                 define('__LANG_VALUE', GET_LANGUAGE());
517
518                 // Load template
519                 LOAD_TEMPLATE("admin_member_selection_box", false, $GLOBALS['what']);
520         } else {
521                 // Return content
522                 return "<select name=\"userid\" size=\"1\">\n".$OUT."</select>\n";
523         }
524 }
525 //
526 function ADMIN_MENU_SELECTION($MODE, $default="", $defid="") {
527         $wht = "what != ''";
528         if ($MODE == "action") $wht = "(what='' OR what IS NULL) AND action !='login'";
529         $result = SQL_QUERY_ESC("SELECT %s, title FROM "._MYSQL_PREFIX."_admin_menu WHERE ".$wht." ORDER BY sort",
530          array($MODE), __FILE__, __LINE__);
531         if (SQL_NUMROWS($result) > 0) {
532                 // Load menu as selection
533                 $OUT = "<SELECT name=\"".$MODE."_menu";
534                 if ((!empty($defid)) || ($defid == "0")) $OUT .= "[".$defid."]";
535                 $OUT .= "\" size=\"1\" class=\"admin_select\">
536         <OPTION value=\"\">".SELECT_NONE."</OPTION>\n";
537                 while (list($menu, $title) = SQL_FETCHROW($result)) {
538                         $OUT .= "  <OPTION value=\"".$menu."\"";
539                         if ((!empty($default)) && ($default == $menu)) $OUT .= " selected=\"selected\"";
540                         $OUT .= ">".$title."</OPTION>\n";
541                 } // END - while
542
543                 // Free memory
544                 SQL_FREERESULT($result);
545                 $OUT .= "</SELECT>\n";
546         } else {
547                 // No menus???
548                 $OUT = ADMIN_PROBLEM_NO_MENU;
549         }
550
551         // Return output
552         return $OUT;
553 }
554 // Save settings to the database
555 function ADMIN_SAVE_SETTINGS (&$POST, $tableName="_config", $whereStatement="config=0", $translateComma=array(), $alwaysAdd=false) {
556         global $_CONFIG, $cacheArray, $cacheInstance;
557
558         // Prepare all arrays, variables
559         $DATA = array();
560         $skip = false;
561
562         // Now, walk through all entries and prepare them for saving
563         foreach ($POST as $id => $val) {
564                 // Process only formular field but not submit buttons ;)
565                 if ($id != "ok") {
566                         // Do not save the ok value
567                         CONVERT_SELECTIONS_TO_TIMESTAMP($POST, $DATA, $id, $skip);
568
569                         // Shall we process this ID? It muss not be empty, of course
570                         if ((!$skip) && (!empty($id))) {
571                                 // Save this entry
572                                 $val = COMPILE_CODE($val);
573
574                                 // Translate the value? (comma to dot!)
575                                 if ((is_array($translateComma)) && (in_array($id, $translateComma))) {
576                                         // Then do it here... :)
577                                         $val = str_replace(",", ".", $val);
578                                 } // END - if
579
580                                 // Shall we add numbers or strings?
581                                 $test = (float)$val;
582                                 if ("".$val."" == "".$test."") {
583                                         // Add numbers
584                                         $DATA[] = $id."=".$val."";
585                                 } else {
586                                         // Add strings
587                                         $DATA[] = $id."='".trim($val)."'";
588                                 }
589
590                                 // Update current configuration
591                                 $_CONFIG[$id] = $val;
592                         } // END - if
593                 } // END - if
594         } // END - foreach
595
596         // Check if entry does exist
597         $result = false;
598         if (!$alwaysAdd) {
599                 if (!empty($whereStatement)) {
600                         $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX.$tableName." WHERE ".$whereStatement." LIMIT 1", __FILE__, __LINE__);
601                 } else {
602                         $result = SQL_QUERY("SELECT * FROM "._MYSQL_PREFIX.$tableName." LIMIT 1", __FILE__, __LINE__);
603                 }
604         } // END - if
605
606         if (SQL_NUMROWS($result) == 1) {
607                 // "Implode" all data to single string
608                 $DATA_UPDATE = implode(", ", $DATA);
609
610                 // Generate SQL string
611                 $SQL = "UPDATE "._MYSQL_PREFIX.$tableName." SET ".$DATA_UPDATE." WHERE ".$whereStatement." LIMIT 1";
612         } else {
613                 // Add Line (does only work with auto_increment!
614                 $KEYs = array(); $VALUEs = array();
615                 foreach ($DATA as $entry) {
616                         // Split up
617                         $line = explode("=", $entry);
618                         $KEYs[] = $line[0]; $VALUEs[] = $line[1];
619                 } // END - foreach
620
621                 // Add both in one line
622                 $KEYs = implode(", ", $KEYs);
623                 $VALUEs = implode(", ", $VALUEs);
624
625                 // Generate SQL string
626                 $SQL = "INSERT INTO "._MYSQL_PREFIX.$tableName." (".$KEYs.") VALUES(".$VALUEs.")";
627         }
628
629         // Free memory
630         SQL_FREERESULT($result);
631
632         // Simply run generated SQL string
633         $result = SQL_QUERY($SQL, __FILE__, __LINE__);
634
635         // Is the config table updated and the cache extension installed?
636         if ((GET_EXT_VERSION("cache") >= "0.1.2") && ($tableName == "_config")) {
637                 // Remove it here...
638                 if ($cacheInstance->cache_file("config", true)) $cacheInstance->cache_destroy();
639                 unset($cacheArray);
640         } // END - if
641
642         // Settings saved
643         LOAD_TEMPLATE("admin_settings_saved", false, "<STRONG class=\"admin_done\">".SETTINGS_SAVED."</STRONG>");
644 }
645 //
646 function ADMIN_MAKE_MENU_SELECTION($menu, $type, $name, $default="") {
647         // Open the requested menu directory
648         $handle = opendir(sprintf("%sinc/modules/%s/", PATH, $menu)) or mxchange_die("Cannot load menu ".$menu."!");
649
650         // Init the selection box
651         $OUT = "<SELECT name=\"".$name."\" class=\"admin_select\" size=\"1\">\n <OPTION value=\"\">".IS_TOP_MENU."</OPTION>\n";
652
653         // Walk through all files
654         while ($file = readdir($handle)) {
655                 // Is this a PHP script?
656                 if (($file != ".") && ($file != "..") && ($file != "lost+found") && (strpos($file, "".$type."-") > -1) && (strpos($file, ".php") > 0)) {
657                         // Then test if the file is readable
658                         $test = sprintf("%sinc/modules/%s/%s", PATH, $menu, $file);
659                         if ((is_file($test)) && (is_readable($test))) {
660                                 // Extract the value for what=xxx
661                                 $part = substr($file, (strlen($type) + 1));
662                                 $part = substr($part, 0, -4);
663
664                                 // Is that part different from the overview?
665                                 if ($part != "overview") {
666                                         $OUT .= "       <OPTION value=\"".$part."\"";
667                                         if ($part == $default) $OUT .= "selected";
668                                         $OUT .= ">".$part."</OPTION>\n";
669                                 } // END - if
670                         } // END - if
671                 } // END - if
672         } // END - while
673
674         // Close dir and selection box
675         closedir($handle);
676         $OUT .= "</SELECT>\n";
677         return $OUT;
678 }
679 //
680 function ADMIN_USER_PROFILE_LINK($uid, $title="", $wht="list_user") {
681         if (($title == "") && ($title != "0")) {
682                 // Set userid as title
683                 $title = $uid;
684         } // END - if
685
686         if (($title == "0") && ($wht == "list_refs")) {
687                 // Return title again
688                 return $title;
689         } // END - if
690
691         //* DEBUG: */ echo "A:".$title."<br />";
692         // Return link
693         return "<A href=\"".URL."/modules.php?module=admin&amp;what=".$wht."&amp;u_id=".$uid."\" title=\"".ADMIN_USER_PROFILE_TITLE."\">".$title."</A>";
694 }
695 //
696 function ADMIN_CHECK_MENU_MODE() {
697         global $_CONFIG, $cacheArray;
698
699         // Set the global mode as the mode for all admins
700         $MODE = $_CONFIG['admin_menu']; $ADMIN = $MODE;
701
702         // Check individual settings of current admin
703         if (isset($cacheArray['admins']['la_mode'][get_session('admin_login')])) {
704                 // Load from cache
705                 $ADMIN = $cacheArray['admins']['la_mode'][get_session('admin_login')];
706                 $_CONFIG['cache_hits']++;
707         } elseif (GET_EXT_VERSION("admins") >= "0.6.7") {
708                 // Load from database when version of "admins" is enough
709                 $result = SQL_QUERY_ESC("SELECT la_mode FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
710                  array(get_session('admin_login')), __FILE__, __LINE__);
711                 if (SQL_NUMROWS($result) == 1) {
712                         // Load data
713                         list($ADMIN) = SQL_FETCHROW($result);
714                 }
715
716                 // Free memory
717                 SQL_FREERESULT($result);
718         }
719
720         // Check what the admin wants and set it when it's not the global mode
721         if ($ADMIN != "global") $MODE = $ADMIN;
722
723         // Return admin-menu's mode
724         return $MODE;
725 }
726 // Change activation status
727 function ADMIN_CHANGE_ACTIVATION_STATUS ($IDs, $table, $row, $idRow = "id") {
728         global $_CONFIG;
729         $cnt = 0; $newStatus = "Y";
730         if ((is_array($IDs)) && (count($IDs) > 0)) {
731                 // "Walk" all through and count them
732                 foreach ($IDs as $id => $selected) {
733                         // Secure the ID number
734                         $id = bigintval($id);
735
736                         // Should always be 1 ;-)
737                         if ($selected == 1) {
738                                 // Determine new status
739                                 $result = SQL_QUERY_ESC("SELECT %s FROM "._MYSQL_PREFIX."_%s WHERE %s=%s LIMIT 1",
740                                         array($row, $table, $idRow, $id), __FILE__, __LINE__);
741
742                                 // Row found?
743                                 if (SQL_NUMROWS($result) == 1) {
744                                         // Load the status
745                                         list($currStatus) = SQL_FETCHROW($result);
746                                         if ($currStatus == "Y") $newStatus='N'; else $newStatus = "Y";
747
748                                         // Change this status
749                                         SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_%s SET %s='%s' WHERE %s=%s LIMIT 1",
750                                                 array($table, $row, $newStatus, $idRow, $id), __FILE__, __LINE__);
751
752                                         // Count up affected rows
753                                         $cnt += SQL_AFFECTEDROWS();
754                                 }
755
756                                 // Free the result
757                                 SQL_FREERESULT($result);
758                         }
759                 }
760
761                 // Output status
762                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_STATUS_CHANGED_1.$cnt.ADMIN_STATUS_CHANGED_2.count($IDs).ADMIN_STATUS_CHANGED_3);
763         } else {
764                 // Nothing selected!
765                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_NOTHING_SELECTED_CHANGE);
766         }
767 }
768 // Send mails for del/edit/lock build modes
769 function ADMIN_SEND_BUILD_MAILS ($mode, $table, $content, $id, $subjectPart="") {
770         // Default subject is the subject part
771         $subject = $subjectPart;
772
773         // Is the subject part not set?
774         if (empty($subjectPart)) {
775                 // Then use it from the mode
776                 $subject = strtoupper($mode);
777         } // END - if
778
779         // Is the raw userid set?
780         if ($_POST['uid_raw'][$id] > 0) {
781                 // Generate subject
782                 $eval = "\$subjectLine = MEMBER_".$subject."_".strtoupper($table)."_SUBJECT;";
783                 eval($eval);
784
785                 // Load email template
786                 if (!empty($subjectPart)) {
787                         $mail = LOAD_EMAIL_TEMPLATE("member_".$mode."_".strtolower($subjectPart)."_".$table, $content);
788                 } else {
789                         $mail = LOAD_EMAIL_TEMPLATE("member_".$mode."_".$table, $content);
790                 }
791
792                 // Send email out
793                 SEND_EMAIL($_POST['uid_raw'][$id], $subjectLine, $mail);
794         } // END - if
795
796         // Generate subject
797         $eval = "\$subjectLine = ADMIN_".$subject."_".strtoupper($table)."_SUBJECT;";
798         eval($eval);
799
800         // Send admin notification out
801         if (!empty($subjectPart)) {
802                 SEND_ADMIN_NOTIFICATION($subjectLine, "admin_".$mode."_".strtolower($subjectPart)."_".$table, $content, $_POST['uid_raw'][$id]);
803         } else {
804                 SEND_ADMIN_NOTIFICATION($subjectLine, "admin_".$mode."_".$table, $content, $_POST['uid_raw'][$id]);
805         }
806 }
807 // Build a special template list
808 function ADMIN_BUILD_LIST ($listType, $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn) {
809         global $_CONFIG;
810         $OUT = ""; $SW = 2;
811
812         // "Walk" through all entries
813         foreach ($IDs as $id => $selected) {
814                 // Secure ID number
815                 $id = bigintval($id);
816
817                 // Get result from a given column array and table name
818                 $result = SQL_RESULT_FROM_ARRAY($table, $columns, $idColumn, $id);
819
820                 // Is there one entry?
821                 if (SQL_NUMROWS($result) == 1) {
822                         // Load all data
823                         $content = SQL_FETCHARRAY($result);
824
825                         // Filter all data
826                         foreach ($content as $key => $value) {
827                                 // Search index
828                                 $idx = array_search($key, $columns, true);
829
830                                 // Do we have a userid?
831                                 if ($key == "userid") {
832                                         // Add it again as raw id
833                                         $content['uid'] = bigintval($value);
834                                 } // END - if
835
836                                 // Handle the call in external function
837                                 $content[$key] = HANDLE_EXTRA_VALUES($filterFunctions[$idx], $value, $extraValues[$idx]);
838                         } // END - foreach
839
840                         // Add color switching
841                         $content['sw'] = $SW;
842
843                         // Then list it
844                         $OUT .= LOAD_TEMPLATE("admin_".$listType."_".$table."_row", true, $content);
845
846                         // Switch color
847                         $SW = 3 - $SW;
848                 } // END - if
849
850                 // Free the result
851                 SQL_FREERESULT($result);
852         } // END - foreach
853
854         // Load master template
855         LOAD_TEMPLATE("admin_".$listType."_".$table."", false, $OUT);
856 }
857 // Delete rows by given ID numbers
858 function ADMIN_DELETE_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $deleteNow=false, $idColumn="id", $userIdColumn="userid") {
859         // All valid entries? (We hope so here!)
860         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) {
861                 // Shall we delete here or list for deletion?
862                 if ($deleteNow) {
863                         // Delete them
864                         $SQL = "DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_%s WHERE %s IN (%s)";
865                         $idList = "";
866                         foreach ($IDs as $id => $sel) {
867                                 // Is there a userid?
868                                 if (isset($_POST['uid_raw'][$id])) {
869                                         // Load all data from that id
870                                         $result = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_%s WHERE %s=%s LIMIT 1",
871                                                 array($table, $idColumn, $id), __FILE__, __LINE__);
872
873                                         // Fetch the data
874                                         $content = SQL_FETCHARRAY($result);
875
876                                         // Free the result
877                                         SQL_FREERESULT($result);
878
879                                         // Send "build mails" out
880                                         ADMIN_SEND_BUILD_MAILS("del", $table, $content, $id);
881                                 } // END - if
882
883                                 // Add id number
884                                 $idList .= $id.",";
885                         } // END - if
886
887                         // Run the query
888                         SQL_QUERY($SQL, array($table, $idColumn, substr($idList, 0, -1)), __FILE__, __LINE__);
889
890                         // Was this fine?
891                         if (SQL_AFFECTEDROWS() == count($IDs)) {
892                                 // All deleted
893                                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ALL_ENTRIES_REMOVED);
894                         } else {
895                                 // Some are still there :(
896                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_SOME_ENTRIES_NOT_DELETED, SQL_AFFECTEDROWS(), count($IDs)));
897                         }
898                 } else {
899                         // List for deletion confirmation
900                         ADMIN_BUILD_LIST("del", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
901                 }
902         } // END - if
903 }
904 // Edit rows by given ID numbers
905 function ADMIN_EDIT_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $editNow=false, $idColumn="id", $userIdColumn="userid") {
906         // All valid entries? (We hope so here!)
907         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues))) {
908                 // Shall we change here or list for editing?
909                 if ($editNow) {
910                         // Change them all
911                         $affected = 0;
912                         foreach ($IDs as $id => $sel) {
913                                 // Prepare content array (new values)
914                                 $content = array();
915
916                                 // Prepare SQL for this row
917                                 $SQL = "UPDATE "._MYSQL_PREFIX."_".$table." SET";
918                                 foreach ($_POST as $key => $entries) {
919                                         // Skip raw userid which is always invalid
920                                         if ($key == "uid_raw") {
921                                                 // Continue with next field
922                                                 continue;
923                                         } // END - if
924
925                                         // Is entries an array?
926                                         if (($key != $idColumn) && (is_array($entries)) && (isset($entries[$id]))) {
927                                                 // Add this entry to content
928                                                 $content[$key] = $entries[$id];
929
930                                                 // Send data through the filter function if found
931                                                 if ((isset($filterFunctions[$key])) && (isset($extraValues[$key]))) {
932                                                         // Filter function set!
933                                                         $entries[$id] = HANDLE_EXTRA_VALUES($filterFunctions[$key], $entries[$id], $extraValues[$key]);
934                                                 } // END - if
935
936                                                 // Then add this value
937                                                 $SQL .= sprintf(" %s='%s',",
938                                                         SQL_ESCAPE($key),
939                                                         SQL_ESCAPE($entries[$id])
940                                                 );
941                                         } elseif (($key != $idColumn) && (!is_array($entries))) {
942                                                 // Add normal entries as well!
943                                                 $content[$key] =  $entries;
944                                         }
945
946                                         // Do we have an URL?
947                                         if ($key == "url") {
948                                                 // Then add a framekiller test as well
949                                                 $content['frametester'] = FRAMETESTER($content[$key]);
950                                         } // END - if
951                                 }
952                                 $SQL = substr($SQL, 0, -1) . " WHERE ".$idColumn."=".bigintval($id)." LIMIT 1";
953
954                                 // Run this query
955                                 SQL_QUERY($SQL, __FILE__, __LINE__);
956
957                                 // Add affected rows
958                                 $affected += SQL_AFFECTEDROWS();
959
960                                 // Load all data from that id
961                                 $result = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_%s WHERE %s=%s LIMIT 1",
962                                         array($table, $idColumn, $id), __FILE__, __LINE__);
963
964                                 // Fetch the data
965                                 global $DATA;
966                                 $DATA = SQL_FETCHARRAY($result);
967
968                                 // Free the result
969                                 SQL_FREERESULT($result);
970
971                                 // Send "build mails" out
972                                 ADMIN_SEND_BUILD_MAILS("edit", $table, $content, $id);
973                         } // END - foreach
974
975                         // Was this fine?
976                         if ($affected == count($IDs)) {
977                                 // All deleted
978                                 LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_ALL_ENTRIES_EDITED);
979                         } else {
980                                 // Some are still there :(
981                                 LOAD_TEMPLATE("admin_settings_saved", false, sprintf(ADMIN_SOME_ENTRIES_NOT_EDITED, $affected, count($IDs)));
982                         }
983                 } else {
984                         // List for editing
985                         ADMIN_BUILD_LIST("edit", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
986                 }
987         } // END - if
988 }
989 // Un-/lock rows by given ID numbers
990 function ADMIN_LOCK_ENTRIES_CONFIRM ($IDs, $table, $columns=array(), $filterFunctions=array(), $extraValues=array(), $statusArray=array(), $lockNow=false, $idColumn="id", $userIdColumn="userid") {
991         // All valid entries? (We hope so here!)
992         if ((is_array($IDs)) && (count($IDs) > 0) && (count($columns) == count($filterFunctions)) && (count($columns) == count($extraValues)) && ((!$lockNow) || (count($statusArray) == 1))) {
993                 // Shall we un-/lock here or list for locking?
994                 if ($lockNow) {
995                         // Un-/lock entries
996                         foreach ($IDs as $id => $sel) {
997                                 // Construct SQL query
998                                 $SQL = "UPDATE "._MYSQL_PREFIX."_".$table." SET";
999
1000                                 // Load data of entry
1001                                 $result = SQL_QUERY_ESC("SELECT * FROM "._MYSQL_PREFIX."_%s WHERE %s=%s LIMIT 1",
1002                                         array($table, $idColumn, $id), __FILE__, __LINE__);
1003
1004                                 // Fetch the data
1005                                 $content = SQL_FETCHARRAY($result);
1006
1007                                 // Free the result
1008                                 SQL_FREERESULT($result);
1009
1010                                 // Add all status entries (e.g. status column last_updated or so)
1011                                 $newStatus = "UNKNOWN";
1012                                 $oldStatus = "UNKNOWN";
1013                                 $statusColumn = "unknown";
1014                                 foreach ($statusArray as $column => $statusInfo) {
1015                                         // Does the entry exist?
1016                                         if ((isset($content[$column])) && (isset($statusInfo[$content[$column]]))) {
1017                                                 // Add these entries for update
1018                                                 $SQL .= sprintf(" %s='%s',", SQL_ESCAPE($column), SQL_ESCAPE($statusInfo[$content[$column]]));
1019
1020                                                 // Remember status
1021                                                 if ($statusColumn == "unknown") {
1022                                                         // Always (!!!) change status column first!
1023                                                         $oldStatus = $content[$column];
1024                                                         $newStatus = $statusInfo[$oldStatus];
1025                                                         $statusColumn = $column;
1026                                                 } // END - if
1027                                         } elseif (isset($content[$column])) {
1028                                                 // Unfinished!
1029                                                 die("UNFINISHED: {$column}[".gettype($statusInfo)."] = {$content[$column]}");
1030                                         }
1031                                 } // END - foreach
1032
1033                                 // Add other columns as well
1034                                 foreach ($_POST as $key => $entries) {
1035                                         // Skip id, raw userid and 'do_lock'
1036                                         if (!in_array($key, array($idColumn, 'uid_raw', 'do_lock'))) {
1037                                                 // Are there brackets () at the end?
1038                                                 if (substr($entries[$id], -2, 2) == "()") {
1039                                                         // Direct SQL command found
1040                                                         $SQL .= sprintf(" %s=%s,", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
1041                                                 } else {
1042                                                         // Add regular entry
1043                                                         $SQL .= sprintf(" %s='%s',", SQL_ESCAPE($key), SQL_ESCAPE($entries[$id]));
1044                                                 }
1045                                         } // END - if
1046                                 } // END - if
1047
1048                                 // Finish SQL statement
1049                                 $SQL = substr($SQL, 0, -1) . " WHERE ".$idColumn."=".bigintval($id)." AND ".$statusColumn."='".$oldStatus."' LIMIT 1";
1050
1051                                 // Run the SQL
1052                                 SQL_QUERY($SQL, __FILE__, __LINE__);
1053
1054                                 // Do we have an URL?
1055                                 if (isset($content['url'])) {
1056                                         // Then add a framekiller test as well
1057                                         $content['frametester'] = FRAMETESTER($content['url']);
1058                                 } // END - if
1059
1060                                 // Send "build mails" out
1061                                 ADMIN_SEND_BUILD_MAILS("lock", $table, $content, $id, $statusInfo[$content[$column]]);
1062                         } // END - if
1063                 } else {
1064                         // List for editing
1065                         ADMIN_BUILD_LIST("lock", $IDs, $table, $columns, $filterFunctions, $extraValues, $idColumn, $userIdColumn);
1066                 }
1067         } // END - if
1068 }
1069 // Checks proxy settins by fetching check-updates3.php from www.mxchange.org
1070 function ADMIN_TEST_PROXY_SETTINGS ($settingsArray) {
1071         global $_CONFIG;
1072
1073         // Set temporary the new settings
1074         $_CONFIG = array_merge($_CONFIG, $settingsArray);
1075
1076         // Now get the test URL
1077         $content = GET_URL("check-updates3.php");
1078
1079         // Is the first line with "200 OK"?
1080         $valid = eregi("200 OK", $content[0]);
1081
1082         // Return result
1083         return $valid;
1084 }
1085 // Sends out a link to the given email adress so the admin can reset his/her password
1086 function ADMIN_SEND_PASSWORD_RESET_LINK ($email) {
1087         global $_CONFIG;
1088         // Init output
1089         $OUT = "";
1090
1091         // Compile out security characters (must be for looking up!)
1092         $email = COMPILE_CODE($email);
1093
1094         // Look up administator login
1095         $result = SQL_QUERY_ESC("SELECT id, login, password FROM "._MYSQL_PREFIX."_admins WHERE email='%s' LIMIT 1",
1096                 array($email), __FILE__, __LINE__);
1097
1098         // Is there an account?
1099         if (SQL_NUMROWS($result) == 0) {
1100                 // No account found!
1101                 return ADMIN_NO_LOGIN_WITH_EMAIL;
1102         } // END - if
1103
1104         // Load all data
1105         $content = SQL_FETCHARRAY($result);
1106
1107         // Free result
1108         SQL_FREERESULT($result);
1109
1110         // Generate hash for reset link
1111         $content['hash'] = generateHash(URL.":".$content['id'].":".$content['login'].":".$content['password'], substr($content['password'], 10));
1112
1113         // Remove some data
1114         unset($content['id']);
1115         unset($content['password']);
1116
1117         // Prepare email
1118         $mailText = LOAD_EMAIL_TEMPLATE("admin_reset_password", $content);
1119
1120         // Send it out
1121         SEND_EMAIL($email, ADMIN_RESET_PASS_LINK_SUBJ, $mailText);
1122
1123         // Prepare output
1124         return ADMIN_RESET_LINK_SENT;
1125 }
1126 // Validate hash and login for password reset
1127 function ADMIN_VALIDATE_RESET_LINK_HASH_LOGIN ($hash, $login) {
1128         // By default nothing validates... ;)
1129         $valid = false;
1130
1131         // Compile the login for lookup
1132         $login = COMPILE_CODE($login);
1133
1134         // Then try to find that user
1135         $result = SQL_QUERY_ESC("SELECT id, password, email FROM "._MYSQL_PREFIX."_admins WHERE login='%s' LIMIT 1",
1136                 array($login), __FILE__, __LINE__);
1137
1138         // Is an account here?
1139         if (SQL_NUMROWS($result) == 1) {
1140                 // Load all data
1141                 $content = SQL_FETCHARRAY($result);
1142
1143                 // Generate hash again
1144                 $hashFromData = generateHash(URL.":".$content['id'].":".$login.":".$content['password'], substr($content['password'], 10));
1145
1146                 // Does both match?
1147                 $valid = ($hash == $hashFromData);
1148         } // END - if
1149
1150         // Free result
1151         SQL_FREERESULT($result);
1152
1153         // Return result
1154         return $valid;
1155 }
1156 // Reset the password for the login. Do NOT call this function without calling above function first!
1157 function ADMIN_RESET_PASSWORD ($login, $password) {
1158         // Init hash
1159         $passHash = "";
1160
1161         // Now check if we have sql_patches installed
1162         if (GET_EXT_VERSION("sql_patches") >= "0.3.6") {
1163                 // Use new way of hashing
1164                 $passHash = generateHash($password);
1165         } else {
1166                 // Old MD5 method
1167                 $passHash = md5($password);
1168         }
1169
1170         // Update database
1171         SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_admins SET password='%s' WHERE login='%s' LIMIT 1",
1172                 array($passHash, $login), __FILE__, __LINE__);
1173
1174         // Return output
1175         return ADMIN_PASSWORD_RESET_DONE;
1176 }
1177 // Solves a task by given id number
1178 function ADMIN_SOLVE_TASK ($id) {
1179         // Update the task data
1180         ADMIN_UPDATE_TASK_DATA($id, "status", "SOLVED");
1181 }
1182 // Marks a given task as deleted
1183 function ADMIN_DELETE_TASK ($id) {
1184         // Update the task data
1185         ADMIN_UPDATE_TASK_DATA($id, "status", "DELETED");
1186 }
1187 // Function to update task data
1188 function ADMIN_UPDATE_TASK_DATA ($id, $row, $data) {
1189         // Update the task
1190         SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET %s='%s' WHERE id=%s LIMIT 1",
1191                 array($row, $data, bigintval($id)), __FILE__, __LINE__);
1192 }
1193 //
1194 ?>