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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!IS_ADMIN())) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 function OUTPUT_STANDARD_OVERVIEW (&$result_tasks) {
46 // First check for solved and not assigned tasks and assign them to current admin
47 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET `assigned_admin`=%s WHERE assigned_admin < 1 AND status != 'NEW'",
48 array(getCurrentAdminId()), __FILE__, __LINE__);
50 // We currently don't want to install an extension so let's find out if we need...
51 $EXT_LOAD_MODE = 'register';
54 // Open the extension directory
55 $extensionList = getArrayFromDirectory("inc/extensions/", "ext-", false, false);
56 foreach ($extensionList as $file) {
57 // Is this file an extension?
58 if ((substr($file, 0, 4) == "ext-") && (substr($file, -4) == '.php')) {
59 //* DEBUG: */ echo $file."<br />\n";
60 // Possible newly installed extension found so we extract extension's name
61 $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
66 // Check if extension is installed or not
67 $ext_ver = GET_EXT_VERSION($ext_name);
69 // Is the extension not yet installed?
70 if (empty($ext_ver)) {
71 // Generate subject line
72 $ext_subj = sprintf("[%s:]", $ext_name);
74 // We maybe want to install an extension so let's test-drive it...
75 if (LOAD_EXTENSION($ext_name, $EXT_LOAD_MODE)) {
76 // Create a task for newly installed extension
77 CREATE_NEW_EXTENSION_TASK(getCurrentAdminId(), $ext_subj, $ext_name);
80 // Test-drive extension in update mode
81 require(sprintf("%sinc/extensions/ext-%s.php", constant('PATH'), $ext_name));
83 // Update extension if extension is installed and outdated
84 //* DEBUG: */ print "ext={$ext_name},ver={EXT_GET_VERSION()}/".GET_EXT_VERSION($ext_name)."<br />\n";
85 if (EXT_GET_VERSION() > $ext_ver) {
86 // Update the extension
87 EXTENSION_UPDATE($ext_name, $ext_ver);
90 if (isset($GLOBALS['cache_array']['active_extensions'][$ext_name])) {
91 // Maybe we want to keept the current extension active?
92 if (($GLOBALS['cache_array']['active_extensions'][$ext_name] == 'Y') && (!EXT_IS_ACTIVE($ext_name))) {
93 // Reactivate this extension!
94 ACTIVATE_EXTENSION($ext_name);
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` ASC, `task_created` DESC",
106 array(getCurrentAdminId()), __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 if ((isset($POST['assign'])) && (count($POST['task']) > 0)) {
125 foreach ($POST['task'] as $id => $sel) {
126 $result_task = SQL_QUERY_ESC("SELECT `id`, `userid`, `task_type`, `subject`, `text`, `task_created`, `status`, `assigned_admin`
127 FROM `{!_MYSQL_PREFIX!}_task_system`
128 WHERE `id`=%s AND (`assigned_admin`=%s OR (`assigned_admin`=0 AND `status`='NEW'))
130 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
133 if (SQL_NUMROWS($result_task) == 1) {
135 list($tid, $uid, $type, $subj, $text, $created, $status, $aid) = SQL_FETCHROW($result_task);
138 // Assgin current admin to unassgigned task
139 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET `assigned_admin`=%s WHERE `id`=%s LIMIT 1",
140 array(getCurrentAdminId(), bigintval($tid)), __FILE__, __LINE__);
144 // @TODO Rewrite this to a filter
145 if ($type == 'SUPPORT_MEMBER') {
146 $mode = substr($text, 0, strpos($text, ':'));
147 $text = substr($text, strpos($text, ':') + 1);
148 $add = "<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>".$mode."</strong></li>";
151 // Is a userid assign?
153 // Then load his data!
154 // @TODO Can this SQL be encapsulated in a function, so all similar queries can be rewritten?
155 $result_user = SQL_QUERY_ESC("SELECT gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
156 array(bigintval($uid)), __FILE__, __LINE__);
159 if (SQL_NUMROWS($result_user) == 1) {
160 list($gender, $sname, $fname, $email) = SQL_FETCHROW($result_user);
161 $add = "<li>{--ADMIN_MEMBER_UID--}: <strong>".generateUserProfileLink($uid)." (<a href=\"".generateMemberEmailLink($email, "user_data")."\">".translateGender($gender)." ".$sname." ".$fname."</a>)</strong></li>";
163 // Invalid userid, so log and zero it
164 DEBUG_LOG(__FUNCTION__, __LINE__, 'Invalid userid=' . $uid . '-> Not found!');
169 SQL_FREERESULT($result_user);
172 // Decode entities of the text
173 $text = decodeEntities($text);
175 // Compile and insert text from task into table template
176 $text = LOAD_TEMPLATE('admin_extensions_text', true, $text);
178 // Initialize variables (no title for SQL commands by default)
179 $ext_name = ''; $ext_ver = '';
180 $title = getMessage('TASK_NO_TITLE');
182 // Shall I list SQL commands assigned to an extension installation or update task?
183 // OLD WAY: if (((GET_EXT_VERSION('sql_patches') != '') && (getConfig('verbose_sql') == 'Y')) || (!EXT_IS_ACTIVE('sql_patches'))) {
184 if ((getConfig('verbose_sql') == 'Y')) {
185 // Extract extension name from subject
186 $ext_name = substr($subj, 1, strpos($subj, ':') - 1);
188 // Update task or extension task?
189 if ($type == 'EXTENSION') {
190 // Load SQL commands for registering
191 REGISTER_EXTENSION($ext_name, $id, true);
194 $text .= EXT_GET_NOTES();
197 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_REGISTER');
198 } elseif ($type == 'EXTENSION_UPDATE') {
199 // Prepare extension name and version
200 $ext_name = substr($ext_name, 7);
201 $ext_name = substr($ext_name, 0, strpos($ext_name, '-'));
202 $test = '[UPDATE-' . $ext_name . '-';
203 $ext_ver = substr($subj, strlen($test));
204 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ':'));
206 // Load SQLs from file
207 EXTENSION_UPDATE($ext_name, $ext_ver, true);
210 $text .= EXT_GET_NOTES();
213 $title = getMessage('ADMIN_SQLS_EXECUTED_ON_UPDATE');
215 // Remove extension's name
219 // Auto-init SQL handler
220 if (!IS_SQLS_VALID()) INIT_SQLS();
222 // Add SQLs to a table
223 if ((!empty($ext_name)) && (GET_EXT_VERSION('sql_patches')) && (getConfig('verbose_sql') == 'Y')) {
224 // Add verbose SQL table
225 $text .= EXTENSION_VERBOSE_TABLE($title, " class=\"admin_table top2 left2 right2\"", true, '100%')."<br />\n";
227 } elseif ((!empty($ext_name)) && (!empty($ext_ver))) {
228 // Run SQL commands in dry mode but only return the notes
229 EXTENSION_UPDATE($ext_name, $ext_ver, true);
230 $text .= EXT_GET_NOTES();
232 // This should not normally happen!
233 debug_report_bug('ext_name(' . $ext_name . ') or ext_ver(' . $ext_ver . ') is empty! sql_patches=' . GET_EXT_VERSION('sql_patches') . '/verbose_sql=' . getConfig('verbose_sql'));
236 // Prepare array for the template
242 'created' => generateDateTime($created, '1'),
243 'extension' => $ext_name
247 $OUT .= LOAD_TEMPLATE('admin_overview_row', true, $content);
249 // Which task do we actually have here?
250 // @TODO Rewrite this to something with include files
252 case 'EXTENSION': // Install new extensions
253 $ext_name = substr($subj, 1, strpos($subj, ':') - 1);
254 $result_lines = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_extensions` WHERE `ext_name`='%s' LIMIT 1",
255 array($ext_name), __FILE__, __LINE__);
256 $lines = SQL_NUMROWS($result_lines);
257 SQL_FREERESULT($result_lines);
259 // New extension found
260 $OUT .= LOAD_TEMPLATE('admin_ext_reg_form', true, array(
261 'id' => bigintval($id),
262 'ext_name' => $ext_name
265 // Task is closed so nothing is todo
266 $OUT .= "<div class=\"admin_failed\">{--ADMIN_EXT_ALREADY_REGISTERED--}</div>\n";
268 // Close task but not already closes or deleted or update tasks
269 if (($status != 'CLOSED') && ($status != 'DELETED') && ($type != 'EXTENSION_UPDATE')) {
271 runFilterChain('solve_task', $tid);
276 case 'EXTENSION_UPDATE': // Extension update
277 // Extension updates are installed automatically
278 $OUT .= "<div class=\"admin_failed medium\">{--ADMIN_EXTENSION_UPDATED--}</div>\n";
281 if (($status != 'CLOSED') && ($status != 'DELETED')) {
283 runFilterChain('solve_task', $tid);
287 case 'SUPPORT_MEMBER': // Assign on member's support request
288 // @TODO This may also be rewritten to include files
290 default: // @TODO Unknown support mode
291 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction!", $mode));
292 $OUT .= "<div class=\"admin_failed medium\">".sprintf(getMessage('ADMIN_UNKNOWN_SUPPORT_MODE'), $mode)."</div>\n";
297 case 'PAYOUT_REQUEST': // Payout requests
298 if (EXT_IS_ACTIVE('payout')) {
299 // Extension is installed so let him send a notification to the user
300 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_user_payouts` WHERE userid=%s AND payout_timestamp=%s LIMIT 1",
301 array(bigintval($uid), bigintval($created)), __FILE__, __LINE__);
302 list($pid) = SQL_FETCHROW($result_pay);
303 SQL_FREERESULT($result_pay);
305 if ((!empty($pid)) && ($pid > 0)) {
306 // Payout ID can be obtained
311 $OUT .= LOAD_TEMPLATE('admin_payout_overview_form', true, $content);
313 // Problem obtaining payout ID
314 $OUT .= "<div class=\"admin_failed medium\">{--PAYOUT_OBTAIN_ID_FAILED--}</div>\n";
317 // Extension is not installed
318 $OUT .= "<div class=\"admin_failed medium\">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>\n";
322 case 'WERNIS_REQUEST': // Wernis requests
323 if (EXT_IS_ACTIVE('wernis')) {
324 // Extension is installed so let him send a notification to the user
325 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{!_MYSQL_PREFIX!}_user_wernis` WHERE userid=%s AND wernis_timestamp=%s LIMIT 1",
326 array(bigintval($uid), bigintval($created)), __FILE__, __LINE__);
327 list($pid) = SQL_FETCHROW($result_pay);
328 SQL_FREERESULT($result_pay);
330 if ((!empty($pid)) && ($pid > 0)) {
331 // Payout ID can be obtained
336 $OUT .= LOAD_TEMPLATE('admin_wernis_overview_form', true, $content);
338 // Problem obtaining wernis ID
339 $OUT .= "<div class=\"admin_failed medium\">{--WERNIS_OBTAIN_ID_FAILED--}</div>\n";
342 // Extension is not installed
343 $OUT .= "<div class=\"admin_failed medium\">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>\n";
347 case 'HOLIDAY_REQUEST': // Holiday requests
348 $OUT .= LOAD_TEMPLATE('admin_task_holiday', true, $uid);
351 case 'NL_UNSUBSCRIBE': // Newsletter unsubscriptions
352 $result = SQL_QUERY_ESC("SELECT nl_timespan FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
353 array(bigintval($uid)), __FILE__, __LINE__);
354 list($span) = SQL_FETCHROW($result);
355 SQL_FREERESULT($result);
358 // Undone unscubscribe request
363 $OUT .= LOAD_TEMPLATE('admin_newsletter_tsk', true, $content);
365 // Already unsubscribed
366 $OUT .= "<div class=\"admin_failed medium\">".ADMIN_NL_UNSUBSCRIBE_ALREADY."</div>\n";
370 default: // Unknown task type
371 DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $type));
372 $OUT .= "<div class=\"admin_failed medium\">".sprintf(getMessage('ADMIN_UNKNOWN_TASK_TYPE'), $type, $id)."</div>\n";
376 <td width=\"1%\" class=\"switch_sw".$SW." bottom2 right2\"> </td>
381 SQL_FREERESULT($result_task);
386 define('__TASK_ROWS', $OUT);
388 // Load final template
389 LOAD_TEMPLATE('admin_overview_list');
391 if ((isset($POST['task'])) && ((count($POST['task']) > 0) || ($POST['task'][0] == '1'))) {
392 // Only unassign / delete tasks when there are selected tasks posted
393 if (!empty($POST['unassign'])) {
394 // Unassign from tasks
395 foreach ($POST['task'] as $id => $sel) {
396 SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET `assigned_admin`=0 WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
397 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
399 } elseif (isset($POST['del'])) {
401 foreach ($POST['task'] as $id => $sel) {
402 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE `id`=%s AND assigned_admin IN (%s,0) LIMIT 1",
403 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
408 $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",
409 array(getCurrentAdminId()), __FILE__, __LINE__);
412 // There are uncompleted jobs!
414 while ($content = SQL_FETCHARRAY($result_tasks)) {
416 $content['infos'] = '---';
418 // Generate assign link
419 $content['assigned_admin'] = generateAdminLink($content['assigned_admin']);
422 switch ($content['task_type'])
425 case 'EXTENSION_UPDATE':
426 $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
431 $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
433 if ($content['userid'] > 0) {
434 // Member found otherwise it's a system task
435 $content['userid'] = generateUserProfileLink($content['userid']);
437 $content['userid'] = "<em>{--ADMIN_IS_SYSTEM_TASK--}</em>";
441 // @TODO Rewritings: admin->assigned_admin,uid->userid,type->task_type_msg in template
442 $content = merge_array($content, array(
444 'admin' => $content['assigned_admin'],
445 'uid' => $content['userid'],
446 'type' => $content['task_type_msg'],
447 'created' => generateDateTime($content['task_created'], '2')
450 // Do we have extension task?
451 if (($content['task_type'] == 'EXTENSION') && (GET_EXT_VERSION($content['infos']) == '')) {
452 // Load extension row template
453 $OUT .= LOAD_TEMPLATE("admin_overview_list_ext_rows", true, $content);
455 // Load default row template
456 $OUT .= LOAD_TEMPLATE("admin_overview_list_rows", true, $content);
464 SQL_FREERESULT($result_tasks);
466 // Load footer template
467 LOAD_TEMPLATE("admin_overview_table", false, $OUT);