query masking rewritten in more SQLs, several cleanups and fix on beg link
[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  *                                                                      *
14  * -------------------------------------------------------------------- *
15  * Copyright (c) 2003 - 2008 by Roland Haeder                           *
16  * For more information visit: http://www.mxchange.org                  *
17  *                                                                      *
18  * This program is free software; you can redistribute it and/or modify *
19  * it under the terms of the GNU General Public License as published by *
20  * the Free Software Foundation; either version 2 of the License, or    *
21  * (at your option) any later version.                                  *
22  *                                                                      *
23  * This program is distributed in the hope that it will be useful,      *
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
26  * GNU General Public License for more details.                         *
27  *                                                                      *
28  * You should have received a copy of the GNU General Public License    *
29  * along with this program; if not, write to the Free Software          *
30  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
31  * MA  02110-1301  USA                                                  *
32  ************************************************************************/
33
34 // Some security stuff...
35 if ((ereg(basename(__FILE__), $_SERVER['PHP_SELF'])) || (!IS_ADMIN()))
36 {
37         $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
38         require($INC);
39 }
40 // Add description as navigation point
41 ADD_DESCR("admin", basename(__FILE__));
42
43 $WHERE = "";
44 if (empty($_GET['type'])) $_GET['type'] = "your";
45
46 switch ($_GET['type'])
47 {
48 case "your": // List only your own open (new) tasks
49         $WHERE = "assigned_admin='".GET_ADMIN_ID($_COOKIE['admin_login'])."' AND status='NEW' AND task_type != 'EXTENSION_UPDATE'";
50         break;
51
52 case "updates": // List only updates assigned to you
53         $WHERE = "assigned_admin='".GET_ADMIN_ID($_COOKIE['admin_login'])."' AND status='NEW' AND task_type = 'EXTENSION_UPDATE'";
54         break;
55
56 case "solved": // List only solved tasks assigned to you
57         $WHERE = "assigned_admin='".GET_ADMIN_ID($_COOKIE['admin_login'])."' AND status='SOLVED'";
58         break;
59
60 case "unassigned": // List unassigned (but not deleted) tasks
61         $WHERE = "assigned_admin='0' AND status != 'DELETED'";
62         break;
63
64 case "deleted": // List all deleted
65         $WHERE = "status='DELETED'";
66         break;
67
68 case "closed": // List all closed
69         $WHERE = "assigned_admin='".GET_ADMIN_ID($_COOKIE['admin_login'])."' AND status='CLOSED'";
70         break;
71
72 default: // Unknown type
73         LOAD_TEMPLATE("admin_settings_saved", false, TASK_ADMIN_UNKNOWN_MODE_1.$_GET['type'].TASK_ADMIN_UNKNOWN_MODE_2);
74         break;
75 }
76
77 if (!empty($WHERE))
78 {
79         $SEL = 0;
80         if (isset($_POST['task'])) $SEL = SELECTION_COUNT($_POST['task']);
81         if ((isset($_POST['assign'])) && ($SEL > 0))
82         {
83                 // Assign / do tasks
84                 require_once(PATH."inc/modules/admin/overview-inc.php");
85                 if (empty($dmy)) $dmy = "";
86                 OUTPUT_SELECTED_TASKS($_POST, $dmy);
87         }
88          else
89         {
90                 // Start listing tasks matching selected filter
91                 $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created
92 FROM "._MYSQL_PREFIX."_task_system
93 WHERE ".$WHERE."
94 ORDER BY userid DESC, task_type DESC, subject, task_created DESC", __FILE__, __LINE__);
95                 if (($SEL > 0) && (!IS_DEMO()))
96                 {
97                         // Only unassign / delete tasks when there are selected tasks posted
98                         if (isset($_POST['unassign']))
99                         {
100                                 // Unassign from tasks
101                                 foreach ($_POST['task'] as $id=>$sel)
102                                 {
103                                         $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET assigned_admin='0' WHERE id=%d AND assigned_admin='%s' LIMIT 1",
104                                          array(bigintval($id), GET_ADMIN_ID($_COOKIE['admin_login'])), __FILE__, __LINE__);
105                                 }
106                         }
107                          elseif (isset($_POST['del']))
108                         {
109                                 // Delete tasks
110                                 foreach ($_POST['task'] as $id=>$sel)
111                                 {
112                                         if ($_GET['type'] == "deleted")
113                                         {
114                                                 // Delete task immediately
115                                                 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_task_system WHERE id=%d LIMIT 1",
116                                                  array(bigintval($id)),__FILE__, __LINE__);
117                                         }
118                                          else
119                                         {
120                                                 // Mark task as to be deleted (purged by autppurge extension)
121                                                 $result = SQL_QUERY_ESC("UPDATE "._MYSQL_PREFIX."_task_system SET status='DELETED' WHERE id=%d LIMIT 1",
122                                                  array(bigintval($id)), __FILE__, __LINE__);
123                                         }
124                                 }
125                         }
126
127                         // Update query
128                         $result_tasks = SQL_QUERY("SELECT id, assigned_admin, userid, task_type, subject, text, task_created FROM "._MYSQL_PREFIX."_task_system WHERE ".$WHERE." ORDER BY subject, task_created DESC", __FILE__, __LINE__);
129                 }
130
131                 // There are uncompleted jobs!
132                 $eval = "\$type = ADMIN_OVERVIEW_TASK_".strtoupper($_GET['type'])."_TYPE;";
133                 eval($eval);
134                 LOAD_TEMPLATE("admin_overview_header_task", false, array(
135                         'message' => $type,
136                         'type'    => $_GET['type']
137                 ));
138                 $SW = 2;
139                 while (list($id, $admin, $uid, $type, $subj, $text, $created) = SQL_FETCHROW($result_tasks))
140                 {
141                         $infos = "---";
142                         if ($admin == "0")
143                         {
144                                 // No admin currently is assigned
145                                 $admin = "<FONT class=\"admin_note\">".ADMIN_NO_ADMIN_ASSIGNED."</FONT>";
146                         }
147                          else
148                         {
149                                 // Load admin's data
150                                 $login = GET_ADMIN_LOGIN($admin);
151                                 if ($login != "***")
152                                 {
153                                         // Admin found
154                                         $admin = "<A href=\"".URL."/modules.php?module=admin&amp;what=admins_contct&amp;admin=".$admin."\">".$login."</A>";
155                                 }
156                                  else
157                                 {
158                                         // Maybe deleted?
159                                         $admin = "<FONT class=\"admin_note\">".ADMIN_ID_404_1.$admin.ADMIN_ID_404_2."</FONT>";
160                                 }
161                         }
162                         $evl = "\$type_out = ADMIN_TASK_IS_".strtoupper($type).";";
163                         eval($evl);
164                         $type2 = substr($text, 0, strpos($text, ":"));
165                         // Generate infos
166                         switch ($type)
167                         {
168                         case "EXTENSION":
169                         case "EXTENSION_UPDATE":
170                                 $infos = substr($subj, 1, strpos($subj, ":") - 1);
171                                 break;
172                         }
173                         if ($uid > 0)
174                         {
175                                 // Member found otherwise it's a system task
176                                 $uid = ADMIN_USER_PROFILE_LINK($uid);
177                         }
178                          else
179                         {
180                                 $uid = "<I>".ADMIN_IS_SYSTEM_TASK."</I>";
181                         }
182                         $content = array(
183                                 'sw'      => $SW,
184                                 'id'      => $id,
185                                 'admin'   => $admin,
186                                 'infos'   => $infos,
187                                 'uid'     => $uid,
188                                 'type'    => $type_out,
189                                 'created' => MAKE_DATETIME($created, "2")
190                         );
191                         LOAD_TEMPLATE("admin_list_task_rows", false, $content);
192                         $SW = 3 - $SW;
193                 }
194
195                 // Free memory
196                 SQL_FREERESULT($result_tasks);
197
198                 // Load footer template
199                 if ($_GET['type'] == "deleted")
200                 {
201                         // Delete now button
202                         LOAD_TEMPLATE("admin_overview_footer_task");
203                 }
204                  else
205                 {
206                         // Normal footer
207                         LOAD_TEMPLATE("admin_overview_footer");
208                 }
209         }
210 }
211 //
212 ?>