]> git.mxchange.org Git - mailer.git/blob - inc/modules/admin/overview-inc.php
0cc18dbc7b6d25c8e61f63650bffd3f5f5c9b422
[mailer.git] / inc / modules / admin / overview-inc.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 07/13/2004 *
4  * ===============                              Last change: 08/02/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : overview-inc.php                                 *
8  * -------------------------------------------------------------------- *
9  * Short description : Output standard task management                  *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Standart-Aufgaben-Management ausgeben            *
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 ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
37         require($INC);
38 }
39
40 function OUTPUT_STANDARD_OVERVIEW(&$result_tasks)
41 {
42         global $cacheArray, $cacheArray;
43
44         // First check for solved and not assigned tasks and assign them to current admin
45         $result_task = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='%s' WHERE assigned_admin < 1 AND status != 'NEW'",
46          array(GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
47
48         // We currently don't want to install an extension so let's find out if we need...
49         $EXT_LOAD_MODE = "register";
50         $JOBS_DONE = true;
51
52         // Open the extension directory
53         $handle = opendir(PATH."inc/extensions/") or mxchange_die("Cannot read extension directory!");
54         while ($file = readdir($handle)) {
55                 // Is this file an extension?
56                 if ((substr($file, 0, 4) == "ext-") && (substr($file, -4) == ".php")) {
57                         //* DEBUG: */ echo $file."<br />\n";
58                         // Possible newly installed extension found so we extract extension's name
59                         $ext = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
60
61                         // Init variables
62                         $ext_ver = "";
63                         $result = false;
64
65                         // Check if extension is installed or not
66                         if ((is_array($cacheArray['extensions']['ext_version'])) && (isset($cacheArray['extensions']['ext_version'][$ext]))) {
67                                 // Load version from cache
68                                 if (!empty($cacheArray['extensions']['ext_version'][$ext])) {
69                                         // Extension is installed so we can get it's version number
70                                         $ext_ver = $cacheArray['extensions']['ext_version'][$ext];
71                                 } else {
72                                         // Extension is not installed so no version number was found
73                                         $ext_ver = "";
74                                 }
75                         } elseif (!EXT_IS_ACTIVE("cache")) {
76                                 // Load data from database
77                                 $result = SQL_QUERY_ESC("SELECT id, ext_version FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
78                                  array($ext), __FILE__, __LINE__);
79                         }
80
81                         // Is the extension not yet installed?
82                         if ((SQL_NUMROWS($result) == 0) && (empty($ext_ver))) {
83                                 // Generate subject line
84                                 $ext_subj = sprintf("[%s:]", $ext);
85
86                                 // Create a task for newly installed extension
87                                 CREATE_NEW_EXTENSION_TASK(GET_ADMIN_ID(get_session('admin_login')), $ext_subj, $ext);
88
89                                 // We maybe want to install an extension so let's test-drive it...
90                                 include(PATH."inc/extensions/".$file);
91                         } else {
92                                 // Maybe we want to update?
93                                 if ((empty($cacheArray['extensions']['ext_version'][$ext])) && (SQL_NUMROWS($result) == 1)) {
94                                         list($dummy, $ext_ver) = SQL_FETCHROW($result);
95                                         SQL_FREERESULT($result);
96                                 }
97
98                                 // Update extension
99                                 if (!empty($ext_ver)) EXTENSION_UPDATE($file, $ext, $ext_ver);
100
101                                 if (!empty($cacheArray['active_extensions'][$ext])) {
102                                         // Maybe we want to keept the current extension active?
103                                         if (($cacheArray['active_extensions'][$ext] == "Y") && (!EXT_IS_ACTIVE($ext))) {
104                                                 // Reactivate this extension!
105                                                 ACTIVATE_EXTENSION($ext);
106                                         } // END - if
107                                 } // END - if
108                         }
109                 } // END - if
110         } // END - while
111
112         // Close directory handle
113         closedir($handle);
114
115         // At last - but not least - check for own and new unassigned tasks...
116         $result_tasks = SQL_QUERY_ESC("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
117 FROM "._MYSQL_PREFIX."_task_system
118 WHERE assigned_admin='%s' OR (assigned_admin='0' AND status='NEW')
119 ORDER BY userid DESC, task_type DESC, subject, task_created DESC",
120          array(GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
121
122         if (SQL_NUMROWS($result_tasks) > 0) {
123                 // New jobs found!
124                 $JOBS_DONE = false;
125         }
126
127         // Free the result
128         SQL_FREERESULT($result);
129
130         // Return status
131         return $JOBS_DONE;
132 }
133
134 //
135 function OUTPUT_SELECTED_TASKS($_POST, $result_tasks) {
136         global $_CONFIG, $NOTES;
137         if ((isset($_POST['assign'])) && (count($_POST['task']) > 0)) {
138                 // Assign / do tasks
139                 $OUT = ""; $SW = 2;
140                 foreach ($_POST['task'] as $id => $sel) {
141                         $result_task = SQL_QUERY_ESC("SELECT id, userid, task_type, subject, text, task_created, status, assigned_admin FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND (assigned_admin='%s' OR (assigned_admin='0' AND status='NEW')) LIMIT 1",
142                          array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
143                         if (SQL_NUMROWS($result_task) == 1) {
144                                 // Task is valid...
145                                 list($tid, $uid, $type, $subj, $text, $created, $status, $aid) = SQL_FETCHROW($result_task);
146                                 SQL_FREERESULT($result_task);
147
148                                 if ($aid == "0") {
149                                         // Assgin current admin to unassgigned task
150                                         $result_assign = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='%s' WHERE id=%s LIMIT 1",
151                                          array(GET_ADMIN_ID(get_session('admin_login')), bigintval($tid)), __FILE__, __LINE__);
152                                 }
153
154                                 $ADD = "";
155                                 if ($type == "SUPPORT_MEMBER") {
156                                         $mode = substr($text, 0, strpos($text, ":"));
157                                         $text = substr($text, strpos($text, ":") + 1);
158                                         $ADD = "<LI>".ADMIN_TASK_SUPPORT_MODE.": <STRONG>".$mode."</STRONG></LI>";
159                                 }
160
161                                 if ($uid > 0) {
162                                         $result_user = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
163                                          array(bigintval($uid)), __FILE__, __LINE__);
164                                         if (SQL_NUMROWS($result_user) == 1)
165                                         {
166                                                 list($gender, $sname, $fname, $email) = SQL_FETCHROW($result_user);
167                                                 SQL_FREERESULT($result_user);
168                                                 $ADD = "<LI>".ADMIN_MEMBER_UID.": <STRONG>".ADMIN_USER_PROFILE_LINK($uid)." (<A href=\"".CREATE_EMAIL_LINK($email, "user_data")."\">".TRANSLATE_GENDER($gender)." ".$sname." ".$fname."</A>)</STRONG></LI>";
169                                         }
170                                 }
171
172                                 // Compile and insert text from task into table template
173                                 $text = LOAD_TEMPLATE("admin_extensions_text", true, COMPILE_CODE($text));
174
175                                 // Initialize variables (no title for SQL commands by default)
176                                 $ext_name = "";
177                                 $title = TASK_NO_TITLE;
178
179                                 // Shall I list SQL commands assigned to an extension installation or update task?
180                                 if (((GET_EXT_VERSION("sql_patches") != '') && ($_CONFIG['verbose_sql'] == "Y")) || (!EXT_IS_ACTIVE("sql_patches"))) {
181                                         $ext_name = substr($subj, 1, strpos($subj, ":") - 1);
182                                         if ($type == "EXTENSION") {
183                                                 // Load SQL commands for registering
184                                                 $SQLs = EXTENSION_REGISTER($ext_name, $id, true);
185
186                                                 // Add notes to text
187                                                 $text .= $NOTES;
188
189                                                 // Set title
190                                                 $title = ADMIN_SQLS_EXECUTED_ON_REGISTER;
191                                         } elseif ($type == "EXTENSION_UPDATE") {
192                                                 // Load SQL commands for update (already done!)
193                                                 $ext_name = substr($ext_name, 7);
194                                                 $ext_name = substr($ext_name, 0, strpos($ext_name, "-"));
195                                                 $test = "[UPDATE-".$ext_name."-";
196                                                 $ext_ver = substr($subj, strlen($test));
197                                                 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ":"));
198
199                                                 // Load SQLs from file
200                                                 $SQLs = EXTENSION_UPDATE("ext-".$ext_name.".php", $ext_name, $ext_ver, true);
201
202                                                 // Add notes to text
203                                                 $text .= $NOTES;
204
205                                                 // Set title
206                                                 $title = ADMIN_SQLS_EXECUTED_ON_UPDATE;
207                                         } else {
208                                                 // Remove extension's name
209                                                 $ext_name = "";
210                                         }
211
212                                         // Add SQLs to a table
213                                         if (empty($SQLs)) $SQLs = array();
214                                         if (empty($title)) $title = "";
215                                         if ((!empty($ext_name)) && (GET_EXT_VERSION("sql_patches")) && ($_CONFIG['verbose_sql'] == "Y")) {
216                                                 // Add verbose SQL table
217                                                 $text .= EXTENSION_VERBOSE_TABLE($SQLs, $title, " class=\"admin_table top2 left2 right2\"", true, "100%")."<br />\n";
218                                         }
219                                 } else {
220                                         // Run SQL commands in dry mode but only return the notes
221                                         $SQLs = EXTENSION_UPDATE("ext-".$ext_name.".php", $ext_name, $ext_ver, true);
222                                         $text .= $NOTES;
223                                 }
224
225                                 // Prepare array for the template
226                                 $content = array(
227                                         'sw'        => $SW,
228                                         'subj'      => $subj,
229                                         'add'       => $ADD,
230                                         'text'      => $text,
231                                         'created'   => MAKE_DATETIME($created, "1"),
232                                         'extension' => $ext_name
233                                 );
234
235                                 // Load template
236                                 $OUT .= LOAD_TEMPLATE("admin_overview_row", true, $content);
237
238                                 // Which task do we actually have here?
239                                 switch ($type)
240                                 {
241                                 case "EXTENSION": // Install new extensions
242                                         $ext_name = substr($subj, 1, strpos($subj, ":") - 1);
243                                         $result_lines = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_extensions WHERE ext_name='%s' LIMIT 1",
244                                          array($ext_name), __FILE__, __LINE__);
245                                         $lines = SQL_NUMROWS($result_lines);
246                                         SQL_FREERESULT($result_lines);
247                                         if ($lines == "0") {
248                                                 // New extension found
249                                                 $OUT .= LOAD_TEMPLATE("admin_ext_reg_form", true, array(
250                                                         'id'       => bigintval($id),
251                                                         'ext_name' => $ext_name
252                                                 ));
253                                         } else {
254                                                 // Task is closed so nothing is todo
255                                                 $OUT .= "<FONT class=\"admin_failed\">".ADMIN_EXT_ALREADY_REGISTERED."</FONT>\n";
256
257                                                 // Close task but not already closes or deleted or update tasks
258                                                 if (($status != "CLOSED") && ($status != "DELETED") && ($type != "EXTENSION_UPDATE")) {
259                                                         ADMIN_SOLVE_TASK($tid);
260                                                 }
261                                         }
262                                         break;
263
264                                 case "EXTENSION_UPDATE":
265                                         // Extension updates are installed automatically
266                                         $OUT .= "<FONT class=\"admin_failed medium\">".ADMIN_EXTENSION_UPDATED."</FONT>\n";
267
268                                         // Close task
269                                         if (($status != "CLOSED") && ($status != "DELETED")) {
270                                                 // Solve the task
271                                                 ADMIN_SOLVE_TASK($tid);
272                                         }
273                                         break;
274
275                                 case "SUPPORT_MEMBER": // Assign on member's support request
276                                         switch ($mode)
277                                         {
278                                         default: // Unknown support mode
279                                                 $OUT .= "<FONT class=\"admin_failed medium\">".ADMIN_UNKNOWN_SUPPORT_MODE_1.$mode.ADMIN_UNKNOWN_SUPPORT_MODE_2."</FONT>\n";
280                                                 break;
281                                         }
282                                         break;
283
284                                 case "PAYOUT_REQUEST": // Payout requests
285                                         if (EXT_IS_ACTIVE("payout"))
286                                         {
287                                                 // Extension is installed so let him send a notification to the user
288                                                 $result_pay = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_payouts WHERE userid=%s AND payout_timestamp=%s LIMIT 1",
289                                                  array(bigintval($uid), bigintval($created)), __FILE__, __LINE__);
290                                                 list($pid) = SQL_FETCHROW($result_pay);
291                                                 SQL_FREERESULT($result_pay);
292
293                                                 if ((!empty($pid)) && ($pid > 0))
294                                                 {
295                                                         // Payout ID can be obtained
296                                                         $content = array(
297                                                                 'pid' => $pid,
298                                                                 'tid' => $tid,
299                                                         );
300                                                         $OUT .= LOAD_TEMPLATE("admin_payout_overview_form", true, $content);
301                                                 }
302                                                  else
303                                                 {
304                                                         // Problem obtaining payout ID
305                                                         $OUT .= "<FONT class=\"admin_failed medium\">".PAYOUT_OBTAIN_ID_FAILED."</FONT>\n";
306                                                 }
307                                         }
308                                          else
309                                         {
310                                                 // Extension is not installed
311                                                 $OUT .= "<FONT class=\"admin_failed medium\">".ADMIN_PAYOUT_NOT_INSTALLED."</FONT>\n";
312                                         }
313                                         break;
314
315                                 case "WERNIS_REQUEST": // Wernis requests
316                                         if (EXT_IS_ACTIVE("wernis"))
317                                         {
318                                                 // Extension is installed so let him send a notification to the user
319                                                 $result_pay = SQL_QUERY_ESC("SELECT id FROM "._MYSQL_PREFIX."_user_wernis WHERE userid=%s AND wernis_timestamp=%s LIMIT 1",
320                                                  array(bigintval($uid), bigintval($created)), __FILE__, __LINE__);
321                                                 list($pid) = SQL_FETCHROW($result_pay);
322                                                 SQL_FREERESULT($result_pay);
323
324                                                 if ((!empty($pid)) && ($pid > 0))
325                                                 {
326                                                         // Payout ID can be obtained
327                                                         $content = array(
328                                                                 'pid' => $pid,
329                                                                 'tid' => $tid,
330                                                         );
331                                                         $OUT .= LOAD_TEMPLATE("admin_wernis_overview_form", true, $content);
332                                                 }
333                                                  else
334                                                 {
335                                                         // Problem obtaining wernis ID
336                                                         $OUT .= "<FONT class=\"admin_failed medium\">".WERNIS_OBTAIN_ID_FAILED."</FONT>\n";
337                                                 }
338                                         }
339                                          else
340                                         {
341                                                 // Extension is not installed
342                                                 $OUT .= "<FONT class=\"admin_failed medium\">".ADMIN_WERNIS_NOT_INSTALLED."</FONT>\n";
343                                         }
344                                         break;
345
346                                 case "HOLIDAY_REQUEST": // Holiday requests
347                                         $OUT .= LOAD_TEMPLATE("admin_task_holiday", true, $uid);
348                                         break;
349
350                                 case "NL_UNSUBSCRIBE": // Newsletter unsubscriptions
351                                         $result = SQL_QUERY_ESC("SELECT nl_timespan FROM "._MYSQL_PREFIX."_user_data WHERE userid=%s LIMIT 1",
352                                          array(bigintval($uid)), __FILE__, __LINE__);
353                                         list($span) = SQL_FETCHROW($result);
354                                         SQL_FREERESULT($result);
355
356                                         if ($span > 0)
357                                         {
358                                                 // Undone unscubscribe request
359                                                 $content = array(
360                                                         'uid' => $uid,
361                                                         'id'  => $tid
362                                                 );
363                                                 $OUT .= LOAD_TEMPLATE("admin_newsletter_tsk", true, $content);
364                                         }
365                                          else
366                                         {
367                                                 // Already unsubscribed
368                                                 $OUT .= "<FONT class=\"admin_failed medium\">".ADMIN_NL_UNSUBSCRIBE_ALREADY."</FONT>\n";
369                                         }
370                                         break;
371
372                                 default: // Unknown task type
373                                         $OUT .= "<FONT class=\"admin_failed medium\">".ADMIN_UNKNOWN_TASK_TYPE_1.$type.ADMIN_UNKNOWN_TASK_TYPE_2.$id.ADMIN_UNKNOWN_TASK_TYPE_3."</FONT>\n";
374                                         break;
375                                 }
376                                 $OUT .= "  </TD>
377   <TD width=\"1%\" class=\"switch_sw".$SW." bottom2 right2\">&nbsp;</TD>
378 </TR>\n";
379                         }
380                         $SW = 3 - $SW;
381                 }
382                 define('__TASK_ROWS', $OUT);
383
384                 // Load final template
385                 LOAD_TEMPLATE("admin_overview_list");
386         }
387          else
388         {
389                 if ((isset($_POST['task'])) && ((sizeof($_POST['task']) > 0) || ($_POST['task'][0] == "1")))
390                 {
391                         // Only unassign / delete tasks when there are selected tasks posted
392                         if (!empty($_POST['unassign']))
393                         {
394                                 // Unassign from tasks
395                                 foreach ($_POST['task'] as $id => $sel)
396                                 {
397                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin=0 WHERE id=%s AND assigned_admin=%s LIMIT 1",
398                                          array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
399                                 }
400                         }
401                          elseif (isset($_POST['del']))
402                         {
403                                 // Delete tasks
404                                 foreach ($_POST['task'] as $id => $sel)
405                                 {
406                                         $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%s AND assigned_admin IN (%s,0) LIMIT 1",
407                                          array(bigintval($id), GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
408                                 }
409                         }
410
411                         // Update query
412                         $result_tasks = SQL_QUERY_ESC("SELECT id, assigned_admin, userid, task_type, subject, text, task_created FROM "._MYSQL_PREFIX."_task_system WHERE assigned_admin=%s OR (assigned_admin=0 AND status='NEW') ORDER BY task_created DESC",
413                          array(GET_ADMIN_ID(get_session('admin_login'))), __FILE__, __LINE__);
414                 }
415
416                 // There are uncompleted jobs!
417                 LOAD_TEMPLATE("admin_overview_header");
418                 $SW = 2;
419                 while (list($id, $admin, $uid, $type, $subj, $text, $created) = SQL_FETCHROW($result_tasks))
420                 {
421                         $infos = "---";
422                         if ($admin == "0")
423                         {
424                                 // No admin currently is assigned
425                                 $admin = "<FONT class=\"admin_note\">".ADMIN_NO_ADMIN_ASSIGNED."</FONT>";
426                         }
427                          else
428                         {
429                                 // Load admin's data
430                                 $login = GET_ADMIN_LOGIN($admin);
431                                 if ($login != "***")
432                                 {
433                                         // Admin found
434                                         $admin = "<A href=\"".URL."/modules.php?module=admin&amp;what=admins_contct&amp;admin=".$admin."\">".$login."</A>";
435                                 }
436                                  else
437                                 {
438                                         // Maybe deleted?
439                                         $admin = "<FONT class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</FONT>";
440                                 }
441                         }
442                         $evl = "\$type_out = ADMIN_TASK_IS_".strtoupper($type).";";
443                         eval($evl);
444                         $type2 = substr($text, 0, strpos($text, ":"));
445                         // Generate infos
446                         switch ($type)
447                         {
448                         case "EXTENSION":
449                         case "EXTENSION_UPDATE":
450                                 $infos = substr($subj, 1, strpos($subj, ":") - 1);
451                                 break;
452                         }
453                         if ($uid > 0)
454                         {
455                                 // Member found otherwise it's a system task
456                                 $uid = ADMIN_USER_PROFILE_LINK($uid);
457                         }
458                          else
459                         {
460                                 $uid = "<I>".ADMIN_IS_SYSTEM_TASK."</I>";
461                         }
462
463                         $content = array(
464                                 'sw'      => $SW,
465                                 'id'      => $id,
466                                 'admin'   => $admin,
467                                 'infos'   => $infos,
468                                 'uid'     => $uid,
469                                 'type'    => $type_out,
470                                 'created' => MAKE_DATETIME($created, "2")
471                         );
472
473                         LOAD_TEMPLATE("admin_overview_list_rows", false, $content);
474                         $SW = 3 - $SW;
475                 }
476                 // Free memory
477                 SQL_FREERESULT($result_tasks);
478
479                 // Load footer template
480                 LOAD_TEMPLATE("admin_overview_footer");
481         }
482 }
483 //
484 ?>