RevBomb patch applied (thanks to profi-concept)
[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:: 856                                                    $ *
14  * $Date:: 2009-03-06 20:24:32 +0100 (Fr, 06. Mär 2009)              $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author:: stelzi                                                   $ *
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                  *
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')) || (!IS_ADMIN())) {
41         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
42         require($INC);
43 } elseif (!EXT_IS_ACTIVE("task")) {
44         addFatalMessage(__FILE__, __LINE__, getMessage('EXTENSION_PROBLEM_EXT_INACTIVE'), "task");
45         return;
46 }
47
48 // Add description as navigation point
49 ADD_DESCR("admin", __FILE__);
50
51 $whereStatement = "";
52 if (!REQUEST_ISSET_GET(('type'))) REQUEST_SET_GET('type', "your");
53
54 switch (REQUEST_GET('type'))
55 {
56 case "your": // List only your own open (new) tasks
57         $whereStatement = "assigned_admin='".GET_CURRENT_ADMIN_ID()."' AND `status`='NEW' AND task_type != 'EXTENSION_UPDATE'";
58         break;
59
60 case "updates": // List only updates assigned to you
61         $whereStatement = "assigned_admin=".GET_CURRENT_ADMIN_ID()." 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=".GET_CURRENT_ADMIN_ID()." 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=".GET_CURRENT_ADMIN_ID()." AND `status`='CLOSED'";
78         break;
79
80 default: // Unknown type
81         DEBUG_LOG(__FILE__, __LINE__, sprintf("Unknown task type %s detected.", REQUEST_GET('type')));
82         LOAD_TEMPLATE("admin_settings_saved", false, sprintf(getMessage('ADMIN_TASK_UNKNOWN_MODE'), REQUEST_GET('type')));
83         break;
84 }
85
86 if (!empty($whereStatement)) {
87         $SEL = 0;
88         if (REQUEST_ISSET_POST(('task'))) $SEL = SELECTION_COUNT(REQUEST_POST('task'));
89
90         if ((REQUEST_ISSET_POST(('assign'))) && ($SEL > 0)) {
91                 // Assign / do tasks
92                 LOAD_INC_ONCE("inc/modules/admin/overview-inc.php");
93                 if (empty($dmy)) $dmy = "";
94                 OUTPUT_SELECTED_TASKS(REQUEST_POST_ARRAY(), $dmy);
95         } else {
96                 // Start listing tasks matching selected filter
97                 $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
98 FROM `{!_MYSQL_PREFIX!}_task_system`
99 WHERE ".$whereStatement."
100 ORDER BY userid DESC, task_type DESC, subject, task_created DESC", __FILE__, __LINE__);
101                 if (($SEL > 0) && (!IS_DEMO())) {
102                         // Only unassign / delete tasks when there are selected tasks posted
103                         if (REQUEST_ISSET_POST(('unassign'))) {
104                                 // Unassign from tasks
105                                 foreach (REQUEST_POST('task') as $id => $sel) {
106                                         SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_task_system` SET assigned_admin=0 WHERE id=%s AND assigned_admin=%s LIMIT 1",
107                                                 array(bigintval($id), GET_CURRENT_ADMIN_ID()), __FILE__, __LINE__);
108                                 }
109                         } elseif (REQUEST_ISSET_POST('del')) {
110                                 // Delete tasks
111                                 foreach (REQUEST_POST('task') as $id => $sel) {
112                                         if (REQUEST_GET('type') == "deleted") {
113                                                 // Delete task immediately
114                                                 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_task_system` WHERE id=%s LIMIT 1",
115                                                         array(bigintval($id)),__FILE__, __LINE__);
116                                         } else {
117                                                 // Mark task as to be deleted (purged by autppurge extension)
118                                                 ADMIN_DELETE_TASK($id);
119                                         }
120                                 }
121                         }
122
123                         // Update query
124                         $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created FROM `{!_MYSQL_PREFIX!}_task_system` WHERE ".$whereStatement." ORDER BY subject, task_created DESC", __FILE__, __LINE__);
125                 }
126
127                 // There are uncompleted jobs!
128                 $type = getMessage('ADMIN_OVERVIEW_TASK_'.strtoupper(REQUEST_GET('type')).'_TYPE');
129                 // @TODO Rewrite these templates to one and add $OUT
130                 LOAD_TEMPLATE("admin_overview_header_task", false, array(
131                         'message' => $type,
132                         'type'    => REQUEST_GET('type')
133                 ));
134                 $OUT = ""; $SW = 2;
135                 while ($content = SQL_FETCHARRAY($result_tasks)) {
136                         // Init infos
137                         $content['infos'] = "---";
138
139                         // Generate link
140                         $content['assigned_admin'] = GENERATE_AID_LINK($content['assigned_admin']);
141
142                         // Get admin task
143                         $content['task_type_msg'] = getMessage('ADMIN_TASK_IS_'.strtoupper($content['task_type']).'');
144
145                         // Generate infos
146                         switch ($content['task_type'])
147                         {
148                         case "EXTENSION":
149                         case "EXTENSION_UPDATE":
150                                 $content['infos'] = substr($content['subject'], 1, strpos($content['subject'], ":") - 1);
151                                 break;
152                         }
153
154                         // Member assigned with task?
155                         if ($content['userid'] > 0) {
156                                 // Member found otherwise it's a system task
157                                 $content['userid'] = ADMIN_USER_PROFILE_LINK($content['userid']);
158                         } else {
159                                 // Is a system task!
160                                 $content['userid'] = "<em>{--ADMIN_IS_SYSTEM_TASK--}</em>";
161                         }
162
163                         // Prepare content
164                         // @TODO Rewritings: admin->assigned_admin,uid->userid,type->task_type_msg in template
165                         $content = merge_array($content, array(
166                                 'sw'      => $SW,
167                                 'admin'   => $content['assigned_admin'],
168                                 'uid'     => $content['userid'],
169                                 'type'    => $content['task_type_msg'],
170                                 'created' => MAKE_DATETIME($content['task_created'], "2")
171                         ));
172
173                         // Do we have an extension task?
174                         if (($content['task_type'] == "EXTENSION") && (GET_EXT_VERSION($content['infos']) == "")) {
175                                 // Load extension row template
176                                 // @TODO Rewrite this to $OUT .= ..., true, ...
177                                 LOAD_TEMPLATE("admin_list_task_ext_rows", false, $content);
178                         } else {
179                                 // Load default row template
180                                 // @TODO Rewrite this to $OUT .= ..., true, ...
181                                 LOAD_TEMPLATE("admin_list_task_rows", false, $content);
182                         }
183
184                         // Switch colors
185                         $SW = 3 - $SW;
186                 }
187
188                 // Free memory
189                 SQL_FREERESULT($result_tasks);
190
191                 // Load footer template
192                 if (REQUEST_GET('type') == "deleted") {
193                         // Delete now button
194                         LOAD_TEMPLATE("admin_overview_footer_task");
195                 } else {
196                         // Normal footer
197                         LOAD_TEMPLATE("admin_overview_footer");
198                 }
199         }
200 }
201 //
202 ?>