2 /************************************************************************
3 * Mailer v0.2.1-FINAL 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 : Standard-Aufgaben-Management ausgeben *
12 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * -------------------------------------------------------------------- *
18 * Copyright (c) 2003 - 2009 by Roland Haeder *
19 * Copyright (c) 2009 - 2012 by Mailer Developer Team *
20 * For more information visit: http://mxchange.org *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
27 * This program is distributed in the hope that it will be useful, *
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30 * GNU General Public License for more details. *
32 * You should have received a copy of the GNU General Public License *
33 * along with this program; if not, write to the Free Software *
34 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
36 ************************************************************************/
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAdmin())) {
43 // @TODO This function does also check for uncompleted tasks
44 function outputStandardOverview (&$result_tasks) {
45 // First check for solved and not assigned tasks and assign them to current admin
46 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `assigned_admin` IS NULL AND status != 'NEW'",
47 array(getCurrentAdminId()), __FILE__, __LINE__);
49 // We currently don't want to install an extension so let's find out if we need...
50 setExtensionMode('test');
53 // Open the extension directory
54 $extensionList = getArrayFromDirectory('inc/extensions/', 'ext-', false, false);
55 foreach ($extensionList as $file) {
56 // Only file name is required... :(
57 $file = basename($file);
59 // Is this file an extension?
60 if ((substr($file, 0, 4) == 'ext-') && (substr($file, -4) == '.php')) {
61 // Possible newly installed extension found so we extract extension's name
62 $ext_name = strtolower(substr($file, 4, -4)); // Keep always extension names on lower case!!!
67 // Check if extension is installed or not
68 $extInstalled = (isExtensionInstalled($ext_name) && (isExtensionActive($ext_name)));
70 // Is the extension not yet installed?
71 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ext_name=' . $ext_name . ',extInstalled=' . intval($extInstalled));
72 if ($extInstalled === false) {
73 // We maybe want to install an extension so let's test-drive it...
74 if (loadExtension($ext_name, 'test', '0.0.0', true)) {
75 // Create a task for newly installed extension (we ignore the task id here)
76 createNewExtensionTask($ext_name);
79 // Test-drive extension
80 loadExtension($ext_name, 'test');
82 // Get extension version
83 $ext_ver = getExtensionVersion($ext_name);
84 //* DEBUG: */ debugOutput($ext_name.'='.$ext_ver);
86 // Update extension if extension is installed and outdated
87 //* DEBUG: */ debugOutput('ext=' . $ext_name . ',ver=' . getThisExtensionVersion() . '/' . getExtensionVersion($ext_name));
88 if (getThisExtensionVersion() > $ext_ver) {
89 // Update the extension
90 updateExtension($ext_name, $ext_ver);
93 if (isset($GLOBALS['cache_array']['always_active'][$ext_name])) {
94 // Maybe we want to keept the current extension active?
95 if (($GLOBALS['cache_array']['always_active'][$ext_name] == 'Y') && (!isExtensionActive($ext_name))) {
96 // Reactivate this extension!
97 doActivateExtension($ext_name);
104 // At last - but not least - check for own and new unassigned tasks...
105 $result_tasks = SQL_QUERY_ESC("SELECT
114 `{?_MYSQL_PREFIX?}_task_system`
116 `assigned_admin`=%s OR ((`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status`='NEW')
121 `task_created` DESC",
122 array(getCurrentAdminId()), __FILE__, __LINE__);
124 if (!SQL_HASZERONUMS($result_tasks)) {
130 SQL_FREERESULT($result);
136 // Outputs selected tasks
137 function outputSeletectedTasks ($postData, $result_tasks) {
138 if ((isset($postData['assign'])) && (count($postData['sel']) > 0)) {
141 foreach ($postData['sel'] as $taskId => $sel) {
142 $result_task = SQL_QUERY_ESC("SELECT
143 `id`,`userid`,`task_type`,`subject`,`text`,`task_created`,`status`,`assigned_admin`
145 `{?_MYSQL_PREFIX?}_task_system`
147 `id`=%s AND (`assigned_admin`=%s OR ((`assigned_admin`=0 OR `assigned_admin` IS NULL) AND `status`='NEW'))
152 ), __FILE__, __LINE__);
155 if (SQL_NUMROWS($result_task) == 1) {
156 // Task is valid so load it's data
157 $taskData = SQL_FETCHARRAY($result_task);
159 if ($taskData['assigned_admin'] == '0') {
160 // Assgin current admin to unassgigned task
161 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=%s WHERE `id`=%s AND `assigned_admin` IS NULL LIMIT 1",
164 bigintval($taskData['id'])
165 ), __FILE__, __LINE__);
169 // @TODO Rewrite this to a filter
170 if ($taskData['task_type'] == 'MEMBER_SUPPORT') {
171 $mode = substr($taskData['text'], 0, strpos($taskData['text'], ':'));
172 $taskData['text'] = substr($taskData['text'], strpos($taskData['text'], ':') + 1);
173 $add = '<li>{--ADMIN_TASK_SUPPORT_MODE--}: <strong>' . $mode . '</strong></li>';
176 // Is a userid assign?
177 if ($taskData['userid'] > 0) {
178 // Then load his data!
179 if (fetchUserData($taskData['userid'])) {
181 $content = getUserDataArray();
183 // Generate HTML list entry
184 $add = '<li>{--ADMIN_MEMBER_USERID--}: <strong>' . generateUserProfileLink($taskData['userid'], 'user_data') . ' (<a href="' . generateEmailLink($content['email'], 'user_data') . '">{%pipe,translateGender=' . $content['gender'] . '%} ' . $content['surname'] . ' ' . $content['family'] . '</a>)</strong></li>';
186 // Invalid userid, so log and zero it
187 logDebugMessage(__FUNCTION__, __LINE__, 'fetchUserData() failed: userid=' . $taskData['userid'] . ' not found.');
188 $taskData['userid'] = '0';
192 // Decode entities of the text
193 $taskData['text'] = decodeEntities($taskData['text']);
195 // Compile and insert text from task into table template
196 $taskData['text'] = loadTemplate('admin_extensions_text', true, $taskData['text']);
198 // Initialize variables (no title for SQL commands by default)
199 $ext_name = ''; $ext_ver = '';
200 $title = '{--ADMIN_TASK_NO_SQL_TITLE--}';
202 // Shall I list SQL commands assigned to an extension installation or update task?
203 if ((isVerboseSqlEnabled()) || (!isExtensionInstalled('sql_patches'))) {
204 // Extract extension name from subject
205 $ext_name = substr($taskData['subject'], 1, strpos($taskData['subject'], ':') - 1);
207 // Update task or extension task?
208 if (($taskData['task_type'] == 'EXTENSION') && (!isExtensionInstalled($ext_name))) {
209 // Load SQL commands for registering in dry-run
210 registerExtension($ext_name, $taskId, true);
212 // Is this non-productive?
213 if (isExtensionProductive() === false) {
215 $taskData['text'] = displayMessage('{%message,ADMIN_EXTENSION_IS_NON_PRODUCTIVE=' . $ext_name . '%}', true) . $taskData['text'];
218 // Set current extension name
219 setCurrentExtensionName($ext_name);
222 $taskData['text'] .= getExtensionNotes();
225 $title = '{--ADMIN_SQLS_EXECUTED_ON_REGISTER--}';
226 } elseif ($taskData['task_type'] == 'EXTENSION_UPDATE') {
227 // Prepare extension name and version
228 $ext_name = substr($ext_name, 7);
229 $ext_name = substr($ext_name, 0, strpos($ext_name, '-'));
230 $test = '[UPDATE-' . $ext_name . '-';
231 $ext_ver = substr($taskData['subject'], strlen($test));
232 $ext_ver = substr($ext_ver, 0, strpos($ext_ver, ':'));
234 // Load SQLs from file
235 updateExtension($ext_name, $ext_ver, true);
237 // Set current extension name
238 setCurrentExtensionName($ext_name);
241 $taskData['text'] .= getExtensionNotes();
244 $title = '{--ADMIN_SQLS_EXECUTED_ON_UPDATE--}';
246 // Remove extension's name
250 // Add SQLs to a table
251 if ((!empty($ext_name)) && (isVerboseSqlEnabled())) {
252 // Add verbose SQL table
253 $taskData['text'] .= addExtensionVerboseSqlTable($title);
255 } elseif ((!empty($ext_name)) && (!empty($ext_ver))) {
256 // Run SQL commands in dry mode but only return the notes
257 updateExtension($ext_name, $ext_ver, true);
259 // Set current extension name
260 setCurrentExtensionName($ext_name);
263 $taskData['text'] .= getExtensionNotes();
265 // This should not normally happen!
266 reportBug(__FILE__, __LINE__, 'ext_name(' . $ext_name . ') or ext_ver(' . $ext_ver . ') is empty! isVerboseSqlEnabled=' . intval(isVerboseSqlEnabled()));
269 // Prepare array for the template
271 'subject' => $taskData['subject'],
273 'text' => $taskData['text'],
274 'task_created' => generateDateTime($taskData['task_created'], '1'),
275 'ext_name' => $ext_name
279 $OUT .= loadTemplate('admin_overview_row', true, $content);
281 // Which task do we actually have here?
282 // @TODO Rewrite this to something with include files and/or filter
283 switch ($taskData['task_type']) {
284 case 'EXTENSION': // Install new extensions
285 $ext_name = substr($taskData['subject'], 1, strpos($taskData['subject'], ':') - 1);
286 if (!isExtensionInstalled($ext_name)) {
287 // New (not yet installed) extension found
288 $OUT .= loadTemplate('admin_extension_reg_form', true, array(
289 'id' => bigintval($taskId),
290 'ext_name' => $ext_name
293 // Extension is already installed
294 $OUT .= '<div class="notice">{--ADMIN_EXTENSION_ALREADY_REGISTERED--}</div>';
296 // Close task but not already closed, solved, deleted or update tasks
297 if ((!in_array($taskData['status'], array('CLOSED', 'DELETED', 'SOLVED'))) && ($taskData['task_type'] != 'EXTENSION_UPDATE')) {
299 runFilterChain('solve_task', $taskData['id']);
304 case 'EXTENSION_UPDATE': // Extension update
305 // Extension updates are installed automatically
306 $OUT .= '<div class="notice medium">{--ADMIN_EXTENSION_UPDATED--}</div>';
308 // Close task if not closed or deleted
309 if (!in_array($taskData['status'], array('CLOSED', 'DELETED'))) {
311 runFilterChain('solve_task', $taskData['id']);
315 case 'MEMBER_SUPPORT': // Assign on member's support request
316 // @TODO This may also be rewritten to include files
318 default: // @TODO Unknown support mode
319 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown support mode %s detected. This part is under construction.", $mode));
320 $OUT .= '<div class="notice medium">{%message,ADMIN_UNKNOWN_SUPPORT_MODE=' . $mode . '%}</div>';
325 case 'PAYOUT_REQUEST': // Payout requests
326 if (isExtensionActive('payout')) {
327 // Extension is installed so let him send a notification to the user
328 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_payouts` WHERE `userid`=%s AND `payout_timestamp`=%s LIMIT 1",
329 array(bigintval($taskData['userid']), bigintval($taskData['task_created'])), __FILE__, __LINE__);
330 list($pid) = SQL_FETCHROW($result_pay);
331 SQL_FREERESULT($result_pay);
333 if ((!empty($pid)) && ($pid > 0)) {
334 // Payout id can be obtained
337 'tid' => $taskData['id'],
341 $OUT .= loadTemplate('admin_payout_overview_form', true, $content);
343 // Problem obtaining payout id
344 $OUT .= '<div class="notice medium">{--ADMIN_PAYOUT_OBTAIN_ID_FAILED--}</div>';
347 // Extension is not installed
348 $OUT .= '<div class="notice medium">{--ADMIN_PAYOUT_NOT_INSTALLED--}</div>';
352 case 'WERNIS_REQUEST': // Wernis requests
353 if (isExtensionActive('wernis')) {
354 // Extension is installed so let him send a notification to the user
355 $result_pay = SQL_QUERY_ESC("SELECT `id` FROM `{?_MYSQL_PREFIX?}_user_wernis` WHERE `userid`=%s AND wernis_timestamp=%s LIMIT 1",
356 array(bigintval($taskData['userid']), bigintval($taskData['task_created'])), __FILE__, __LINE__);
357 list($pid) = SQL_FETCHROW($result_pay);
358 SQL_FREERESULT($result_pay);
360 if ((!empty($pid)) && ($pid > 0)) {
361 // Payout id can be obtained
364 'tid' => $taskData['id'],
366 $OUT .= loadTemplate('admin_wernis_overview_form', true, $content);
368 // Problem obtaining wernis id
369 $OUT .= '<div class="notice medium">{--WERNIS_OBTAIN_ID_FAILED--}</div>';
372 // Extension is not installed
373 $OUT .= '<div class="notice medium">{--ADMIN_WERNIS_NOT_INSTALLED--}</div>';
377 case 'HOLIDAY_REQUEST': // Holiday requests
378 $OUT .= loadTemplate('admin_task_holiday', true, $taskData['userid']);
381 case 'MEMBER_ORDER': // Member mail orders
382 $OUT .= loadTemplate('admin_task_order', true, $taskId);
385 default: // Unknown task type
386 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", $taskData['task_type']));
387 $OUT .= '<div class="notice medium">' . sprintf(getMessage('ADMIN_UNKNOWN_TASK_TYPE'), $taskData['task_type'], $taskId) . '</div>';
396 SQL_FREERESULT($result_task);
399 // Load final template
400 loadTemplate('admin_overview_list', false, $OUT);
402 if ((isset($postData['sel'])) && ((count($postData['sel']) > 0) || ($postData['sel'][0] == 1))) {
403 // Only unassign / delete tasks when there are selected tasks posted
404 if (!empty($postData['unassign'])) {
405 // Unassign from tasks
406 foreach ($postData['sel'] as $taskId => $sel) {
407 SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=NULL WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
408 array(bigintval($taskId), getCurrentAdminId()), __FILE__, __LINE__);
410 } elseif (!empty($postData['delete'])) {
412 foreach ($postData['sel'] as $taskId => $sel) {
413 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s AND `assigned_admin` IN (%s,0,NULL) LIMIT 1",
414 array(bigintval($taskId), getCurrentAdminId()), __FILE__, __LINE__);
418 reportBug(__FILE__, __LINE__, sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r($postData, true)));
422 $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 OR `assigned_admin` IS NULL) AND `status`='NEW') ORDER BY `task_created` DESC",
423 array(getCurrentAdminId()), __FILE__, __LINE__);
426 // There are uncompleted jobs!
428 while ($content = SQL_FETCHARRAY($result_tasks)) {
430 $content['infos'] = '';
433 // @TODO Try to move this in includes
434 switch ($content['task_type']) {
436 case 'EXTENSION_UPDATE':
437 $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
441 if (isValidUserId($content['userid'])) {
442 // Member found otherwise it's a system task
443 $content['userid'] = generateUserProfileLink($content['userid']);
445 $content['userid'] = '{--ADMIN_IS_SYSTEM_TASK--}';
448 // Add/translate some content
449 $content['task_created'] = generateDateTime($content['task_created'], 2);
451 // Is there extension task?
452 if (isExtensionTask($content)) {
453 // Load extension row template
454 $OUT .= loadTemplate('admin_overview_list_ext_rows', true, $content);
456 // Load default row template
457 $OUT .= loadTemplate('admin_overview_list_rows', true, $content);
462 SQL_FREERESULT($result_tasks);
464 // Load footer template
465 loadTemplate('admin_overview_table', false, $OUT);