New function isValidUserid() introduced, more rewrites to EL:
[mailer.git] / inc / modules / admin / what-list_task.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                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  * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
22  * For more information visit: http://www.mxchange.org                  *
23  *                                                                      *
24  * This program is free software; you can redistribute it and/or modify *
25  * it under the terms of the GNU General Public License as published by *
26  * the Free Software Foundation; either version 2 of the License, or    *
27  * (at your option) any later version.                                  *
28  *                                                                      *
29  * This program is distributed in the hope that it will be useful,      *
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
32  * GNU General Public License for more details.                         *
33  *                                                                      *
34  * You should have received a copy of the GNU General Public License    *
35  * along with this program; if not, write to the Free Software          *
36  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
37  * MA  02110-1301  USA                                                  *
38  ************************************************************************/
39
40 // Some security stuff...
41 if ((!defined('__SECURITY')) || (!isAdmin())) {
42         die();
43 } // END - if
44
45 // Add description as navigation point
46 addMenuDescription('admin', __FILE__);
47
48 if (!isExtensionActive('task')) {
49         loadTemplate('admin_settings_saved', false, generateExtensionInactiveNotInstalledMessage('task'));
50         return;
51 } // END - if
52
53 $whereStatement = '';
54 if (!isGetRequestParameterSet('type')) setGetRequestParameter('type', 'your');
55
56 switch (getRequestParameter('type')) {
57         case 'your': // List only your own open (new) tasks
58                 $whereStatement = "`assigned_admin`='".getCurrentAdminId()."' AND `status`='NEW' AND `task_type` != 'EXTENSION_UPDATE'";
59                 break;
60
61         case 'updates': // List only updates assigned to you
62                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='NEW' AND `task_type`='EXTENSION_UPDATE'";
63                 break;
64
65         case 'solved': // List only solved tasks assigned to you
66                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='SOLVED'";
67                 break;
68
69         case 'unassigned': // List unassigned (but not deleted) tasks
70                 $whereStatement = "`assigned_admin`=0 AND `status` != 'DELETED'";
71                 break;
72
73         case 'deleted': // List all deleted
74                 $whereStatement = "`status`='DELETED'";
75                 break;
76
77         case 'closed': // List all closed
78                 $whereStatement = "`assigned_admin`=".getCurrentAdminId()." AND `status`='CLOSED'";
79                 break;
80
81         default: // Unknown type
82                 logDebugMessage(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", getRequestParameter('type')));
83                 loadTemplate('admin_settings_saved', false, getMaskedMessage('ADMIN_TASK_UNKNOWN_MODE', getRequestParameter('type')));
84                 break;
85 } // END - switch
86
87 if (!empty($whereStatement)) {
88         if ((isPostRequestParameterSet('assign')) && (countPostSelection() > 0)) {
89                 // Assign / do tasks
90                 loadIncludeOnce('inc/modules/admin/overview-inc.php');
91                 if (empty($dmy)) $dmy = '';
92                 outputSeletectedTasks(postRequestArray(), $dmy);
93         } else {
94                 // Start listing tasks matching selected filter
95                 $result_tasks = SQL_QUERY('SELECT
96         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
97 FROM
98         `{?_MYSQL_PREFIX?}_task_system`
99 WHERE
100         '.$whereStatement.'
101 ORDER BY
102         `userid` DESC,
103         `task_type` DESC,
104         `subject` ASC,
105         `task_created` DESC',
106                         __FILE__, __LINE__);
107                 if ((countPostSelection() > 0) && (!isDemoModeActive())) {
108                         // Only unassign / delete tasks when there are selected tasks posted
109                         if (isPostRequestParameterSet('unassign')) {
110                                 // Unassign from tasks
111                                 foreach (postRequestParameter('sel') as $id => $sel) {
112                                         SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_task_system` SET `assigned_admin`=0 WHERE `id`=%s AND `assigned_admin`=%s LIMIT 1",
113                                                 array(bigintval($id), getCurrentAdminId()), __FILE__, __LINE__);
114                                 } // END - foreach
115                         } elseif (isFormSent('del')) {
116                                 // Delete tasks
117                                 foreach (postRequestParameter('sel') as $id => $sel) {
118                                         if (getRequestParameter('type') == 'deleted') {
119                                                 // Delete task immediately
120                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_task_system` WHERE `id`=%s LIMIT 1",
121                                                         array(bigintval($id)),__FILE__, __LINE__);
122                                         } else {
123                                                 // Mark task as to be deleted (purged by autopurge extension)
124                                                 adminDeleteTask($id);
125                                         }
126                                 } // END - foreach
127                         } else {
128                                 // Unknown action performed
129                                 debug_report_bug(__FILE__, __LINE__, sprintf("Unknown task action performed. data=<pre>%s</pre>", print_r(postRequestArray(), true)));
130                         }
131
132                         // Update query
133                         $result_tasks = SQL_QUERY('SELECT
134         `id`, `assigned_admin`, `userid`, `task_type`, `subject`, `text`, `task_created`
135 FROM
136         `{?_MYSQL_PREFIX?}_task_system`
137 WHERE
138         '.$whereStatement.'
139 ORDER BY
140         `subject` ASC,
141         `task_created` DESC', __FILE__, __LINE__);
142                 }
143
144                 // There are uncompleted jobs!
145                 $type = getMessage('ADMIN_OVERVIEW_TASK_'.strtoupper(getRequestParameter('type')).'_TYPE');
146                 // @TODO Rewrite these templates to one and add $OUT
147                 loadTemplate('admin_overview_header_task', false, array(
148                         'message' => $type,
149                         'type'    => getRequestParameter('type')
150                 ));
151                 $OUT = ''; $SW = 2;
152                 while ($content = SQL_FETCHARRAY($result_tasks)) {
153                         // Init infos
154                         $content['infos'] = '---';
155
156                         // Generate link
157                         $content['assigned_admin'] = generateAdminLink($content['assigned_admin']);
158
159                         // Get admin task
160                         $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
161
162                         // Generate infos
163                         switch ($content['task_type']) {
164                                 case 'EXTENSION':
165                                 case 'EXTENSION_UPDATE':
166                                         $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ':') - 1);
167                                         break;
168                         } // END - switch
169
170                         // Member assigned with task?
171                         if (isValidUserId($content['userid'])) {
172                                 // Member found otherwise it's a system task
173                                 $content['userid'] = generateUserProfileLink($content['userid']);
174                         } else {
175                                 // Is a system task!
176                                 $content['userid'] = '<em>{--ADMIN_IS_SYSTEM_TASK--}</em>';
177                         }
178
179                         // Prepare content
180                         // @TODO Rewritings: admin->assigned_admin,type->task_type_msg in template
181                         $content = merge_array($content, array(
182                                 'sw'      => $SW,
183                                 'admin'   => $content['assigned_admin'],
184                                 'userid'  => $content['userid'],
185                                 'type'    => $content['task_type_msg'],
186                                 'created' => generateDateTime($content['task_created'], 2)
187                         ));
188
189                         // Do we have an extension task?
190                         if (($content['task_type'] == 'EXTENSION') && (isExtensionNameValid($content['infos'])) && (!isExtensionInstalled($content['infos']))) {
191                                 // Load extension row template
192                                 // @TODO Rewrite this to $OUT .= ..., true, ...
193                                 loadTemplate('admin_list_task_ext_rows', false, $content);
194                         } else {
195                                 // Load default row template
196                                 // @TODO Rewrite this to $OUT .= ..., true, ...
197                                 loadTemplate('admin_list_task_rows', false, $content);
198                         }
199
200                         // Switch colors
201                         $SW = 3 - $SW;
202                 } // END - while
203
204                 // Free memory
205                 SQL_FREERESULT($result_tasks);
206
207                 // Load footer template
208                 if (getRequestParameter('type') == 'deleted') {
209                         // Delete now button
210                         loadTemplate('admin_overview_footer_task');
211                 } else {
212                         // Normal footer
213                         loadTemplate('admin_overview_footer');
214                 }
215         }
216 } // END - if
217
218 // [EOF]
219 ?>