Compilation time added, some compileCode() calles removed, ADMIN_WHAT_404 added
[mailer.git] / inc / modules / admin / what-list_task.php
1 <?php
2 /************************************************************************
3  * MXChange v0.2.1                                    Start: 08/03/2004 *
4  * ================                             Last change: 08/07/2004 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : what-list_task.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : List all tasks                                   *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : Alle Aufgaben auflisten                          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
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 - 2009 by Roland Haeder                           *
21  * For more information visit: http://www.mxchange.org                  *
22  *                                                                      *
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.                                  *
27  *                                                                      *
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.                         *
32  *                                                                      *
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,               *
36  * MA  02110-1301  USA                                                  *
37  ************************************************************************/
38
39 // Some security stuff...
40 if ((!defined('__SECURITY')) || (!isAdmin())) {
41         die();
42 } // END - if
43
44 // Add description as navigation point
45 addMenuDescription('admin', __FILE__);
46
47 if (!isExtensionActive('task')) {
48         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('task'));
49         return;
50 } // END - if
51
52 $whereStatement = '';
53 if (!isGetRequestElementSet(('type'))) setRequestGetElement('type', 'your');
54
55 switch (getRequestElement('type')) {
56         case 'your': // List only your own open (new) tasks
57                 $whereStatement = "`assigned_admin`='".getCurrentAdminId()."' AND `status`='NEW' AND `task_type` != 'EXTENSION_UPDATE'";
58                 break;
59
60         case 'updates': // List only updates assigned to you
61                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='NEW' AND `task_type`='EXTENSION_UPDATE'";
62                 break;
63
64         case 'solved': // List only solved tasks assigned to you
65                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='SOLVED'";
66                 break;
67
68         case 'unassigned': // List unassigned (but not deleted) tasks
69                 $whereStatement = "`assigned_admin`=0 AND `status` != 'DELETED'";
70                 break;
71
72         case 'deleted': // List all deleted
73                 $whereStatement = "`status`='DELETED'";
74                 break;
75
76         case 'closed': // List all closed
77                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='CLOSED'";
78                 break;
79
80         default: // Unknown type
81                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", getRequestElement('type')));
82                 loadTemplate('admin_settings_saved', false, sprintf(getMessage('ADMIN_TASK_UNKNOWN_MODE'), getRequestElement('type')));
83                 break;
84 }
85
86 if (!empty($whereStatement)) {
87         $SEL = 0;
88         if (isPostRequestElementSet(('task'))) $SEL = countSelection(postRequestElement('task'));
89
90         if ((isPostRequestElementSet(('assign'))) && ($SEL > 0)) {
91                 // Assign / do tasks
92                 loadIncludeOnce("inc/modules/admin/overview-inc.php");
93                 if (empty($dmy)) $dmy = '';
94                 outputSeletectedTasks(postRequestArray(), $dmy);
95         } else {
96                 // Start listing tasks matching selected filter
97                 $result_tasks = SQL_QUERY('SELECT
98         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
99 FROM
100         `{?_MYSQL_PREFIX?}_task_system`
101 WHERE
102         '.$whereStatement.'
103 ORDER BY
104         `userid` DESC,
105         `task_type` DESC,
106         `subject` ASC,
107         `task_created` DESC',
108                         __FILE__, __LINE__);
109                 if (($SEL > 0) && (!isDemoModeActive())) {
110                         // Only unassign / delete tasks when there are selected tasks posted
111                         if (isPostRequestElementSet('unassign')) {
112                                 // Unassign from tasks
113                                 foreach (postRequestElement('task') as $id => $sel) {
114                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=0 WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
115                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
116                                 }
117                         } elseif (isPostRequestElementSet('del')) {
118                                 // Delete tasks
119                                 foreach (postRequestElement('task') as $id => $sel) {
120                                         if (getRequestElement('type') == 'deleted') {
121                                                 // Delete task immediately
122                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
123                                                         array(bigintval($id)),__FILE__, __LINE__);
124                                         } else {
125                                                 // Mark task as to be deleted (purged by autopurge extension)
126                                                 adminDeleteTask($id);
127                                         }
128                                 }
129                         } else {
130                                 // Unknown action performed
131                                 debug_report_bug(sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r(postRequestArray(), true)));
132                         }
133
134                         // Update query
135                         $result_tasks = SQL_QUERY('SELECT
136         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
137 FROM
138         `{?_MYSQL_PREFIX?}_task_system`
139 WHERE
140         '.$whereStatement.'
141 ORDER BY
142         `subject` ASC,
143         `task_created` DESC', __FILE__, __LINE__);
144                 }
145
146                 // There are uncompleted jobs!
147                 $type = getMessage('ADMIN_OVERVIEW_TASK_'.strtoupper(getRequestElement('type')).'_TYPE');
148                 // @TODO Rewrite these templates to one and add $OUT
149                 loadTemplate('admin_overview_header_task', false, array(
150                         'message' => $type,
151                         'type'    => getRequestElement('type')
152                 ));
153                 $OUT = ''; $SW = 2;
154                 while ($content = SQL_FETCHARRAY($result_tasks)) {
155                         // Init infos
156                         $content['infos'] = '---';
157
158                         // Generate link
159                         $content['assigned_admin'] = generateAdminLink($content['assigned_admin']);
160
161                         // Get admin task
162                         $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
163
164                         // Generate infos
165                         switch ($content['task_type']) {
166                                 case 'EXTENSION':
167                                 case 'EXTENSION_UPDATE':
168                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
169                                         break;
170                         } // END - switch
171
172                         // Member assigned with task?
173                         if ($content['userid'] > 0) {
174                                 // Member found otherwise it's a system task
175                                 $content['userid'] = generateUserProfileLink($content['userid']);
176                         } else {
177                                 // Is a system task!
178                                 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
179                         }
180
181                         // Prepare content
182                         // @TODO Rewritings: admin->assigned_admin,userid->userid,type->task_type_msg in template
183                         $content = merge_array($content, array(
184                                 'sw'      => $SW,
185                                 'admin'   => $content['assigned_admin'],
186                                 'userid'  => $content['userid'],
187                                 'type'    => $content['task_type_msg'],
188                                 'created' => generateDateTime($content['task_created'], 2)
189                         ));
190
191                         // Do we have an extension task?
192                         if (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))) {
193                                 // Load extension row template
194                                 // @TODO Rewrite this to $OUT .= ..., true, ...
195                                 loadTemplate('admin_list_task_ext_rows', false, $content);
196                         } else {
197                                 // Load default row template
198                                 // @TODO Rewrite this to $OUT .= ..., true, ...
199                                 loadTemplate('admin_list_task_rows', false, $content);
200                         }
201
202                         // Switch colors
203                         $SW = 3 - $SW;
204                 }
205
206                 // Free memory
207                 SQL_FREERESULT($result_tasks);
208
209                 // Load footer template
210                 if (getRequestElement('type') == 'deleted') {
211                         // Delete now button
212                         loadTemplate('admin_overview_footer_task');
213                 } else {
214                         // Normal footer
215                         loadTemplate('admin_overview_footer');
216                 }
217         }
218 }
219
220 // [EOF]
221 ?>