2 /************************************************************************
3 * MXChange v0.2.1 Start: 07/13/2004 *
4 * =============== Last change: 08/02/2004 *
6 * -------------------------------------------------------------------- *
7 * File : overview-inc.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Output standard task management *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Standart-Aufgaben-Management ausgeben *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 function OUTPUT_STANDARD_OVERVIEW(&$result_tasks) {
41 global $cacheArray, $_CONFIG;
43 // First check for solved and not assigned tasks and assign them to current admin
44 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET assigned_admin='%s' WHERE assigned_admin < 1 AND status != 'NEW'",
45 array(GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
47 // We currently don't want to install an extension so let's find out if we need...
48 $EXT_LOAD_MODE = "register";
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_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
63 // Check if extension is installed or not
64 $ext_ver = GET_EXT_VERSION($ext_name);
66 // Is the extension not yet installed?
67 if (empty($ext_ver)) {
68 // Generate subject line
69 $ext_subj = sprintf("[%s:]", $ext_name);
71 // We maybe want to install an extension so let's test-drive it...
72 if (LOAD_EXTENSION($ext_name, $EXT_LOAD_MODE)) {
73 // Create a task for newly installed extension
74 CREATE_NEW_EXTENSION_TASK(GET_CURRENT_ADMIN_ID(), $ext_subj, $ext_name);
77 // Test-drive extension in update mode
78 require(sprintf("%sinc/extensions/ext-%s.php", constant('PATH'), $ext_name));
80 // Update extension if extension is installed and outdated
81 //* DEBUG: */ print "ext={$ext_name},ver={$EXT_VERSION}/".GET_EXT_VERSION($ext_name)."<br />\n";
82 if ($EXT_VERSION > $ext_ver) {
83 // Update the extension
84 EXTENSION_UPDATE($ext_name, $ext_ver);
87 if (isset($cacheArray['active_extensions'][$ext_name])) {
88 // Maybe we want to keept the current extension active?
89 if (($cacheArray['active_extensions'][$ext_name] == "Y") && (!EXT_IS_ACTIVE($ext_name))) {
90 // Reactivate this extension!
91 ACTIVATE_EXTENSION($ext_name);
98 // Close directory handle
101 // At last - but not least - check for own and new unassigned tasks...
102 $result_tasks = SQL_QUERY_ESC("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
103 FROM `{!_MYSQL_PREFIX!}_task_system`
104 WHERE assigned_admin='%s' OR (assigned_admin='0' AND `status`='NEW')
105 ORDER BY userid DESC, task_type DESC, subject, task_created DESC",
106 array(GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
108 if (SQL_NUMROWS($result_tasks) > 0) {
114 SQL_FREERESULT($result);
120 // Outputs selected tasks
121 function OUTPUT_SELECTED_TASKS ($POST, $result_tasks) {
122 global $_CONFIG, $NOTES;
123 if ((isset($POST['assign'])) && (count($POST['task']) > 0)) {
126 foreach ($POST['task'] as $id => $sel) {
127 $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",
128 array(bigintval($id), GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
129 if (SQL_NUMROWS($result_task) == 1) {
131 list($tid, $uid, $type, $subj, $text, $created, $status, $aid) = SQL_FETCHROW($result_task);
132 SQL_FREERESULT($result_task);
135 // Assgin current admin to unassgigned task
136 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET assigned_admin='%s' WHERE id=%s LIMIT 1",
137 array(GET_CURRENT_ADMIN_ID(), bigintval($tid)), __FILE__, __LINE__);
141 if ($type == "SUPPORT_MEMBER") {
142 $mode = substr($text, 0, strpos($text, ":"));
143 $text = substr($text, strpos($text, ":") + 1);
144 $ADD = "<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>".$mode."</strong></li>";
148 $result_user = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
149 array(bigintval($uid)), __FILE__, __LINE__);
150 if (SQL_NUMROWS($result_user) == 1) {
151 list($gender, $sname, $fname, $email) = SQL_FETCHROW($result_user);
152 SQL_FREERESULT($result_user);
153 $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>";
157 // Decode entities of the text
158 $text = html_entity_decode($text);
160 // Compile and insert text from task into table template
161 $text = LOAD_TEMPLATE("admin_extensions_text", true, $text);
163 // Initialize variables (no title for SQL commands by default)
165 $title = TASK_NO_TITLE;
167 // Shall I list SQL commands assigned to an extension installation or update task?
168 if (((GET_EXT_VERSION("sql_patches") != '') && (getConfig('verbose_sql') == "Y")) || (!EXT_IS_ACTIVE("sql_patches"))) {
169 $ext_name = substr($subj, 1, strpos($subj, ":") - 1);
170 if ($type == "EXTENSION") {
171 // Load SQL commands for registering
172 $SQLs = EXTENSION_REGISTER($ext_name, $id, true);
178 $title = ADMIN_SQLS_EXECUTED_ON_REGISTER;
179 } elseif ($type == "EXTENSION_UPDATE") {
180 // Prepare extension name and version
181 $ext_name = substr($ext_name, 7);
182 $ext_name = substr($ext_name, 0, strpos($ext_name, "-"));
183 $test = "[UPDATE-".$ext_name."-";
184 $ext_ver = substr($subj, strlen($test));
185 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ":"));
187 // Load SQLs from file
188 $SQLs = EXTENSION_UPDATE($ext_name, $ext_ver, true);
194 $title = ADMIN_SQLS_EXECUTED_ON_UPDATE;
196 // Remove extension's name
200 // Add SQLs to a table
201 if (empty($SQLs)) $SQLs = array();
202 if (empty($title)) $title = "";
203 if ((!empty($ext_name)) && (GET_EXT_VERSION("sql_patches")) && (getConfig('verbose_sql') == "Y")) {
204 // Add verbose SQL table
205 $text .= EXTENSION_VERBOSE_TABLE($SQLs, $title, " class=\"admin_table top2 left2 right2\"", true, "100%")."<br />\n";
208 // Run SQL commands in dry mode but only return the notes
209 $SQLs = EXTENSION_UPDATE($ext_name, $ext_ver, true);
213 // Prepare array for the template
219 'created' => MAKE_DATETIME($created, "1"),
220 'extension' => $ext_name
224 $OUT .= LOAD_TEMPLATE("admin_overview_row", true, $content);
226 // Which task do we actually have here?
227 // @TODO Rewrite this to something with include files
230 case "EXTENSION": // Install new extensions
231 $ext_name = substr($subj, 1, strpos($subj, ":") - 1);
232 $result_lines = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_extensions` WHERE ext_name='%s' LIMIT 1",
233 array($ext_name), __FILE__, __LINE__);
234 $lines = SQL_NUMROWS($result_lines);
235 SQL_FREERESULT($result_lines);
237 // New extension found
238 $OUT .= LOAD_TEMPLATE("admin_ext_reg_form", true, array(
239 'id' => bigintval($id),
240 'ext_name' => $ext_name
243 // Task is closed so nothing is todo
244 $OUT .= "<div class=\"admin_failed\">{--ADMIN_EXT_ALREADY_REGISTERED--}</div>\n";
246 // Close task but not already closes or deleted or update tasks
247 if (($status != "CLOSED") && ($status != "DELETED") && ($type != "EXTENSION_UPDATE")) {
249 RUN_FILTER('solve_task', $tid);
254 case "EXTENSION_UPDATE": // Extension update
255 // Extension updates are installed automatically
256 $OUT .= "<div class=\"admin_failed medium\">{--ADMIN_EXTENSION_UPDATED--}</div>\n";
259 if (($status != "CLOSED") && ($status != "DELETED")) {
261 RUN_FILTER('solve_task', $tid);
265 case "SUPPORT_MEMBER": // Assign on member's support request
268 default: // @TODO Unknown support mode
269 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction!", $mode));
270 $OUT .= "<div class=\"admin_failed medium\">".ADMIN_UNKNOWN_SUPPORT_MODE_1.$mode.ADMIN_UNKNOWN_SUPPORT_MODE_2."</div>\n";
275 case "PAYOUT_REQUEST": // Payout requests
276 if (EXT_IS_ACTIVE("payout")) {
277 // Extension is installed so let him send a notification to the user
278 $result_pay = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_payouts` WHERE userid=%s AND payout_timestamp=%s LIMIT 1",
279 array(bigintval($uid), bigintval($created)), __FILE__, __LINE__);
280 list($pid) = SQL_FETCHROW($result_pay);
281 SQL_FREERESULT($result_pay);
283 if ((!empty($pid)) && ($pid > 0)) {
284 // Payout ID can be obtained
289 $OUT .= LOAD_TEMPLATE("admin_payout_overview_form", true, $content);
291 // Problem obtaining payout ID
292 $OUT .= "<div class=\"admin_failed medium\">".PAYOUT_OBTAIN_ID_FAILED."</div>\n";
295 // Extension is not installed
296 $OUT .= "<div class=\"admin_failed medium\">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>\n";
300 case "WERNIS_REQUEST": // Wernis requests
301 if (EXT_IS_ACTIVE("wernis")) {
302 // Extension is installed so let him send a notification to the user
303 $result_pay = SQL_QUERY_ESC("SELECT id FROM `{!_MYSQL_PREFIX!}_user_wernis` WHERE userid=%s AND wernis_timestamp=%s LIMIT 1",
304 array(bigintval($uid), bigintval($created)), __FILE__, __LINE__);
305 list($pid) = SQL_FETCHROW($result_pay);
306 SQL_FREERESULT($result_pay);
308 if ((!empty($pid)) && ($pid > 0)) {
309 // Payout ID can be obtained
314 $OUT .= LOAD_TEMPLATE("admin_wernis_overview_form", true, $content);
316 // Problem obtaining wernis ID
317 $OUT .= "<div class=\"admin_failed medium\">{--WERNIS_OBTAIN_ID_FAILED--}</div>\n";
320 // Extension is not installed
321 $OUT .= "<div class=\"admin_failed medium\">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>\n";
325 case "HOLIDAY_REQUEST": // Holiday requests
326 $OUT .= LOAD_TEMPLATE("admin_task_holiday", true, $uid);
329 case "NL_UNSUBSCRIBE": // Newsletter unsubscriptions
330 $result = SQL_QUERY_ESC("SELECT nl_timespan FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
331 array(bigintval($uid)), __FILE__, __LINE__);
332 list($span) = SQL_FETCHROW($result);
333 SQL_FREERESULT($result);
336 // Undone unscubscribe request
341 $OUT .= LOAD_TEMPLATE("admin_newsletter_tsk", true, $content);
343 // Already unsubscribed
344 $OUT .= "<div class=\"admin_failed medium\">".ADMIN_NL_UNSUBSCRIBE_ALREADY."</div>\n";
348 default: // Unknown task type
349 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $type));
350 $OUT .= "<div class=\"admin_failed medium\">".ADMIN_UNKNOWN_TASK_TYPE_1.$type.ADMIN_UNKNOWN_TASK_TYPE_2.$id.ADMIN_UNKNOWN_TASK_TYPE_3."</div>\n";
354 <td width=\"1%\" class=\"switch_sw".$SW." bottom2 right2\"> </td>
359 define('__TASK_ROWS', $OUT);
361 // Load final template
362 LOAD_TEMPLATE("admin_overview_list");
364 if ((isset($POST['task'])) && ((sizeof($POST['task']) > 0) || ($POST['task'][0] == "1"))) {
365 // Only unassign / delete tasks when there are selected tasks posted
366 if (!empty($POST['unassign'])) {
367 // Unassign from tasks
368 foreach ($POST['task'] as $id => $sel) {
369 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET assigned_admin=0 WHERE id=%s AND assigned_admin=%s LIMIT 1",
370 array(bigintval($id), GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
372 } elseif (isset($POST['del'])) {
374 foreach ($POST['task'] as $id => $sel) {
375 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s AND assigned_admin IN (%s,0) LIMIT 1",
376 array(bigintval($id), GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
381 $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",
382 array(GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
385 // There are uncompleted jobs!
386 LOAD_TEMPLATE("admin_overview_header");
388 while (list($id, $admin, $uid, $type, $subj, $text, $created) = SQL_FETCHROW($result_tasks)) {
391 // No admin currently is assigned
392 $admin = "<div class=\"admin_note\">{--ADMIN_NO_ADMIN_ASSIGNED--}</div>";
395 $login = GET_ADMIN_LOGIN($admin);
396 if ($login != "***") {
398 $admin = "<a href=\"{!URL!}/modules.php?module=admin&what=admins_contct&admin=".$admin."\">".$login."</a>";
401 $admin = "<div class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</div>";
406 $type_out = constant('ADMIN_TASK_IS_'.strtoupper($type).'');
408 $type2 = substr($text, 0, strpos($text, ":"));
413 case "EXTENSION_UPDATE":
414 $infos = substr($subj, 1, strpos($subj, ":") - 1);
419 // Member found otherwise it's a system task
420 $uid = ADMIN_USER_PROFILE_LINK($uid);
422 $uid = "<em>{--ADMIN_IS_SYSTEM_TASK--}</em>";
433 'created' => MAKE_DATETIME($created, "2")
436 // Do we have extension task?
437 if (($type == "EXTENSION") && (GET_EXT_VERSION($infos) == "")) {
438 // Load extension row template
439 LOAD_TEMPLATE("admin_overview_list_ext_rows", false, $content);
441 // Load default row template
442 LOAD_TEMPLATE("admin_overview_list_rows", false, $content);
449 SQL_FREERESULT($result_tasks);
451 // Load footer template
452 LOAD_TEMPLATE("admin_overview_footer");