This repository was archived by the owner on Aug 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtaskassign.php
More file actions
156 lines (146 loc) · 5.83 KB
/
taskassign.php
File metadata and controls
156 lines (146 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
include_once('globals.php');
include_once('checklogin.php');
include_once('classes/task.php');
function peopleSort($array)
{
$newArray = array();
foreach($array as $person)
$newArray[$person->getCommaName()] = $person;
ksort($newArray);
return $newArray;
}
if(is_numeric($_GET['taskid']))
{
$task = new Task($_GET['taskid'], $currentGroup->getType(), $currentGroup->getSemester(), $db);
if($task->isValid())
{
if($currentUser->getID() != $task->getCreator()->getID() && !$currentUser->isGroupModerator($currentGroup))
errorPage('Access Denied', 'You must be either the task owner or a group moderator to make assignments to a task.', 403);
//else OK
}
else
errorPage('Invalid Task ID', 'The task ID provided is invalid.', 400);
if($_POST['form'] == 'submit')
{
$oldassigned = $task->getAllAssigned();
$db->query('delete from TaskAssignments where iTaskID='.$task->getID());
//$db->query('delete from TaskSubgroupAssignments where iTaskID='.$task->getID());
if(is_array($_POST['person']))
{
foreach($_POST['person'] as $id => $person)
if(is_numeric($id))
$task->assignPerson(new Person($id, $db));
}
/*if(is_array($_POST['subgroup']))
{
foreach($_POST['subgroup'] as $id => $subgroup)
$db->query('insert into TaskSubgroupAssignments (iTaskID, iSubgroupID) values ('.$task->getID().", $id)");
}*/
//Inform newly-assigned and newly-deassigned people of the change
$newassigned = $task->getAllAssigned();
$selGroup = $currentGroup->getID().'z'.$currentGroup->getType().'z'.$currentGroup->getSemester();
foreach($newassigned as $id => $person)
{
if(!array_key_exists($id, $oldassigned) && $person->receivesNotifications())
{
$msg = "This is an auto-generated $appname notification to let you know that you have been assigned to a task. Task information is below.\n\n";
$msg .= "Group: {$task->team->getName()}\nTask Name: {$task->getName()}\nURL: $appurl/taskview.php?taskid={$task->getID()}&selectedGroup=$selGroup\n\n";
$msg .= "--- $appname System Auto-Generated Massage\n\n";
$msg .= "To stop receiving task assignment notifications, visit $appurl/contactinfo.php";
mail($person->getEmail(), "[$appname] Task Assignment", $msg, "From: $appname Support <$contactemail>");
}
}
foreach($oldassigned as $id => $person)
{
if(!array_key_exists($id, $newassigned) && $person->receivesNotifications())
{
$msg = "This is an auto-generated $appname notification to let you know that you have been unassigned from a task. Task information is below.\n\n";
$msg .= "Group: {$task->team->getName()}\nTask Name: {$task->getName()}\nURL: $appurl/taskview.php?taskid={$task->getID()}&selectedGroup=$selGroup\n\n";
$msg .= "--- $appname System Auto-Generated Massage\n\n";
$msg .= "To stop receiving task assignment notifications, visit $appurl/contactinfo.php";
mail($person->getEmail(), "[$appname] Task Assignment", $msg, "From: $appname Support <$contactemail>");
}
}
header('Location: taskview.php?taskid='.$task->getID());
}
}
else if($_GET['taskid'])
errorPage('Invalid Task ID', 'The task ID provided is invalid.', 400);
else
errorPage('Missing Task ID', 'No task ID was provided.', 400);
//------Start XHTML Output--------------------------------------//
require('doctype.php');
require('appearance.php');
echo "<link rel=\"stylesheet\" href=\"skins/$skin/tasks.css\" type=\"text/css\" title=\"$skin\" />\n";
foreach($altskins as $altskin)
echo "<link rel=\"alternate stylesheet\" href=\"skins/$altskin/tasks.css\" type=\"text/css\" title=\"$altskin\" />\n";
?>
<title><?php echo $appname; ?> - Task Assignments</title>
</head>
<body>
<?php
/**** begin html head *****/
require('htmlhead.php'); //starts main container
/****end html head content ****/
?>
<?php
echo '<p>We are assigning tasks for <b>'.$task->getName()."</b></p>\n";
echo "<form method=\"post\" action=\"taskassign.php?taskid={$_GET['taskid']}\">\n";
echo "<fieldset><fieldset id=\"people\"><legend>People</legend>\n";
echo "<table>\n";
$members = $currentGroup->getGroupMembers();
$members = peopleSort($members);
$people = $task->getAssignedPeople();
$i = 1;
foreach($members as $person)
{
if($i == 1)
echo '<tr>';
if($people[$person->getID()])
echo '<td><input type="checkbox" name="person['.$person->getID().']" id="person'.$person->getID().'" checked="checked" /></td>';
else
echo '<td><input type="checkbox" name="person['.$person->getID().']" id="person'.$person->getID().'" /></td>';
echo '<td><label for="person'.$person->getID().'">'.$person->getFullName().'</label></td>';
if($i == 3)
{
print "</tr>\n";
$i = 1;
}
else
$i++;
}
echo "</table></fieldset><br />\n";
/*$subgroups = $currentGroup->getSubGroups();
if($subgroups)
{
$subgr = $task->getAssignedSubgroups();
echo "<fieldset id=\"subgroups\"><legend>Subgroups:</legend>\n";
echo "<table>\n";
$i=1;
foreach($subgroups as $subgroup)
{
if($i == 1)
echo '<tr>';
echo '<td><input type="checkbox" id="subgroup'.$subgroup->getID().'" name="subgroup['.$subgroup->getID().']"'.(($subgr[$subgroup->getID()]) ? ' checked="checked"' : '').' /> ';
echo '<label for="subgroup'.$subgroup->getID().'">'.$subgroup->getName().'</label></td>';
if($i == 3)
{
echo "</tr>\n";
$i = 1;
}
else
$i++;
}
if($i != 1)
echo '</tr>';
echo "</table></fieldset>\n";
}*/
echo "<input type=\"submit\" value=\"Submit Assignments\" /><input type=\"reset\" /><input type=\"hidden\" name=\"form\" value=\"submit\" /></fieldset></form>\n";
echo "<p>Cancel and <a href=\"tasks.php\">return to main tasks listing</a> or <a href=\"taskview.php?taskid={$task->getID()}\">return to task</a></p>\n";
?>
<?php
//include rest of html layout file
require('htmlcontentfoot.php');// ends main container
?>
</body></html>