fb6eb9080f023e3c33945457ec2878d865e91d5a
[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         if ((isPostRequestElementSet(('assign'))) && (countPostSelection() > 0)) {
88                 // Assign / do tasks
89                 loadIncludeOnce("inc/modules/admin/overview-inc.php");
90                 if (empty($dmy)) $dmy = '';
91                 outputSeletectedTasks(postRequestArray(), $dmy);
92         } else {
93                 // Start listing tasks matching selected filter
94                 $result_tasks = SQL_QUERY('SELECT
95         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
96 FROM
97         `{?_MYSQL_PREFIX?}_task_system`
98 WHERE
99         '.$whereStatement.'
100 ORDER BY
101         `userid` DESC,
102         `task_type` DESC,
103         `subject` ASC,
104         `task_created` DESC',
105                         __FILE__, __LINE__);
106                 if ((countPostSelection() > 0) && (!isDemoModeActive())) {
107                         // Only unassign / delete tasks when there are selected tasks posted
108                         if (isPostRequestElementSet('unassign')) {
109                                 // Unassign from tasks
110                                 foreach (postRequestElement('task') as $id => $sel) {
111                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=0 WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
112                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
113                                 }
114                         } elseif (isPostRequestElementSet('del')) {
115                                 // Delete tasks
116                                 foreach (postRequestElement('task') as $id => $sel) {
117                                         if (getRequestElement('type') == 'deleted') {
118                                                 // Delete task immediately
119                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
120                                                         array(bigintval($id)),__FILE__, __LINE__);
121                                         } else {
122                                                 // Mark task as to be deleted (purged by autopurge extension)
123                                                 adminDeleteTask($id);
124                                         }
125                                 }
126                         } else {
127                                 // Unknown action performed
128                                 debug_report_bug(sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r(postRequestArray(), true)));
129                         }
130
131                         // Update query
132                         $result_tasks = SQL_QUERY('SELECT
133         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
134 FROM
135         `{?_MYSQL_PREFIX?}_task_system`
136 WHERE
137         '.$whereStatement.'
138 ORDER BY
139         `subject` ASC,
140         `task_created` DESC', __FILE__, __LINE__);
141                 }
142
143                 // There are uncompleted jobs!
144                 $type = getMessage('ADMIN_OVERVIEW_TASK_'.strtoupper(getRequestElement('type')).'_TYPE');
145                 // @TODO Rewrite these templates to one and add $OUT
146                 loadTemplate('admin_overview_header_task', false, array(
147                         'message' => $type,
148                         'type'    => getRequestElement('type')
149                 ));
150                 $OUT = ''; $SW = 2;
151                 while ($content = SQL_FETCHARRAY($result_tasks)) {
152                         // Init infos
153                         $content['infos'] = '---';
154
155                         // Generate link
156                         $content['assigned_admin'] = generateAdminLink($content['assigned_admin']);
157
158                         // Get admin task
159                         $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
160
161                         // Generate infos
162                         switch ($content['task_type']) {
163                                 case 'EXTENSION':
164                                 case 'EXTENSION_UPDATE':
165                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
166                                         break;
167                         } // END - switch
168
169                         // Member assigned with task?
170                         if ($content['userid'] > 0) {
171                                 // Member found otherwise it's a system task
172                                 $content['userid'] = generateUserProfileLink($content['userid']);
173                         } else {
174                                 // Is a system task!
175                                 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
176                         }
177
178                         // Prepare content
179                         // @TODO Rewritings: admin->assigned_admin,userid->userid,type->task_type_msg in template
180                         $content = merge_array($content, array(
181                                 'sw'      => $SW,
182                                 'admin'   => $content['assigned_admin'],
183                                 'userid'  => $content['userid'],
184                                 'type'    => $content['task_type_msg'],
185                                 'created' => generateDateTime($content['task_created'], 2)
186                         ));
187
188                         // Do we have an extension task?
189                         if (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))) {
190                                 // Load extension row template
191                                 // @TODO Rewrite this to $OUT .= ..., true, ...
192                                 loadTemplate('admin_list_task_ext_rows', false, $content);
193                         } else {
194                                 // Load default row template
195                                 // @TODO Rewrite this to $OUT .= ..., true, ...
196                                 loadTemplate('admin_list_task_rows', false, $content);
197                         }
198
199                         // Switch colors
200                         $SW = 3 - $SW;
201                 }
202
203                 // Free memory
204                 SQL_FREERESULT($result_tasks);
205
206                 // Load footer template
207                 if (getRequestElement('type') == 'deleted') {
208                         // Delete now button
209                         loadTemplate('admin_overview_footer_task');
210                 } else {
211                         // Normal footer
212                         loadTemplate('admin_overview_footer');
213                 }
214         }
215 }
216
217 // [EOF]
218 ?>