1 | <?php
|
---|
2 | /*
|
---|
3 | $Id: taskgroup_submit.php 2178 2009-04-07 09:29:01Z andrewsimpson $
|
---|
4 |
|
---|
5 | (c) 2002 - 2009 Andrew Simpson <andrew.simpson at paradise.net.nz>
|
---|
6 |
|
---|
7 | WebCollab
|
---|
8 | ---------------------------------------
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under the
|
---|
11 | terms of the GNU General Public License as published by the Free Software Foundation;
|
---|
12 | either version 2 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
---|
15 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
---|
16 | PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
---|
17 |
|
---|
18 | You should have received a copy of the GNU General Public License along with this
|
---|
19 | program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
---|
20 | Cambridge, MA 02139, USA.
|
---|
21 |
|
---|
22 | Function:
|
---|
23 | ---------
|
---|
24 |
|
---|
25 | Add a taskgroup to the database
|
---|
26 |
|
---|
27 | */
|
---|
28 |
|
---|
29 | //security check
|
---|
30 | if(! defined('UID' ) ) {
|
---|
31 | die('Direct file access not permitted' );
|
---|
32 | }
|
---|
33 |
|
---|
34 | //admins only
|
---|
35 | if(! ADMIN) {
|
---|
36 | error('Unauthorised access', 'This function is for admins only.' );
|
---|
37 | }
|
---|
38 |
|
---|
39 | if(empty($_POST['action']) ) {
|
---|
40 | error('Taskgroups submit', 'No action given' );
|
---|
41 | }
|
---|
42 |
|
---|
43 | //check for valid form token
|
---|
44 | $token = (isset($_POST['token'])) ? (safe_data($_POST['token'])) : null;
|
---|
45 | token_check($token );
|
---|
46 |
|
---|
47 | //if user aborts, let the script carry onto the end
|
---|
48 | ignore_user_abort(TRUE);
|
---|
49 |
|
---|
50 | switch($_POST['action'] ) {
|
---|
51 |
|
---|
52 | //delete a taskgroup
|
---|
53 | case 'submit_del':
|
---|
54 |
|
---|
55 | if(! @safe_integer($_POST['taskgroupid']) ) {
|
---|
56 | error('Taskgroup submit', 'Not a valid value for taskgroupid' );
|
---|
57 | }
|
---|
58 | $taskgroupid = $_POST['taskgroupid'];
|
---|
59 |
|
---|
60 | //if taskgroup exists we can delete it :)
|
---|
61 | if(db_result(db_query('SELECT COUNT(*) FROM '.PRE.'taskgroups WHERE id='.$taskgroupid ), 0, 0 ) ) {
|
---|
62 | db_begin();
|
---|
63 | //set the affected tasks to have no taskgroup
|
---|
64 | @db_query('UPDATE '.PRE.'tasks SET taskgroupid=0 WHERE taskgroupid='.$taskgroupid );
|
---|
65 | //delete the group
|
---|
66 | db_query('DELETE FROM '.PRE.'taskgroups WHERE id='.$taskgroupid );
|
---|
67 | db_commit();
|
---|
68 | }
|
---|
69 | break;
|
---|
70 |
|
---|
71 | //insert a new taskgroup
|
---|
72 | case 'submit_insert':
|
---|
73 |
|
---|
74 | if(empty($_POST['name'] ) ){
|
---|
75 | warning($lang['value_missing'], sprintf($lang['field_sprt'], $lang['taskgroup_name'] ) );
|
---|
76 | }
|
---|
77 |
|
---|
78 | $name = safe_data($_POST['name']);
|
---|
79 | $description = safe_data($_POST['description']);
|
---|
80 |
|
---|
81 | //check for duplicates
|
---|
82 | if(db_result(db_query('SELECT COUNT(*) FROM '.PRE.'taskgroups WHERE name=\''.$name.'\'' ), 0, 0 ) > 0 )
|
---|
83 | warning($lang['add_taskgroup'], sprintf($lang['taskgroup_dup_sprt'], $name ) );
|
---|
84 |
|
---|
85 | db_query('INSERT INTO '.PRE.'taskgroups(name, description) VALUES (\''.$name.'\', \''.$description.'\')' );
|
---|
86 |
|
---|
87 | break;
|
---|
88 |
|
---|
89 |
|
---|
90 | //edit an existing taskgroup
|
---|
91 | case 'submit_edit':
|
---|
92 |
|
---|
93 | if(! @safe_integer($_POST['taskgroupid'] ) ){
|
---|
94 | error('Taskgroup submit', 'Not a valid value for taskgroupid' );
|
---|
95 | }
|
---|
96 |
|
---|
97 | if(empty($_POST['name'] ) ){
|
---|
98 | warning($lang['value_missing'], sprintf($lang['field_sprt'], $lang['taskgroup_name'] ) );
|
---|
99 | }
|
---|
100 |
|
---|
101 | $name = safe_data($_POST['name'] );
|
---|
102 | $description = safe_data($_POST['description'] );
|
---|
103 | $taskgroupid = $_POST['taskgroupid'];
|
---|
104 |
|
---|
105 | db_query('UPDATE '.PRE.'taskgroups SET name=\''.$name.'\', description=\''.$description.'\' WHERE id='.$taskgroupid );
|
---|
106 |
|
---|
107 | break;
|
---|
108 |
|
---|
109 | //error case
|
---|
110 | default:
|
---|
111 | error('Taskgroup submit', 'Invalid request given' );
|
---|
112 | break;
|
---|
113 | }
|
---|
114 |
|
---|
115 | header('Location: '.BASE_URL.'taskgroups.php?x='.X.'&action=manage');
|
---|
116 |
|
---|
117 | ?>
|
---|