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