-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_assign.php
150 lines (135 loc) · 5.21 KB
/
client_assign.php
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
<?php
require("mysql_connect.php");
//who is assigned already?
$get_s=mysqli_query($dbc, "SELECT * FROM staff ORDER BY lastname ASC,firstname ASC");
while($s=mysqli_fetch_assoc($get_s))
$s_meta[$s['id']]=$s;
$get_c=mysqli_query($dbc, "SELECT * FROM clients ORDER BY name ASC");
while($c=mysqli_fetch_assoc($get_c))
$c_meta[$c['id']]=$c;
$get_assign=mysqli_query($dbc, "SELECT * FROM staff_clients");
while($sc=mysqli_fetch_assoc($get_assign))
$c_assign[$sc['clientID']][]=$sc['staffID'];
$get_s_assign=mysqli_query($dbc, "SELECT * FROM staff_clients ORDER BY clientID");
while($cs=mysqli_fetch_assoc($get_s_assign))
$s_assign[$cs['staffID']][]=$cs['clientID'];
// print_r($c_assign);
// print_r($_POST);
if (isset($_POST['submit'])) {
if(isset($_POST['remove']) && $_POST['remove']==1){
$del=mysqli_query($dbc, "DELETE FROM staff_clients WHERE staffID='{$_POST['staffID']}' AND clientID='{$_POST['clientID']}'");
if($del) $msg='success'; else $msg='error';
die($msg);
} else {
//is this already assigned?
if(!isset($c_assign[$_POST['codemenu']]) || !in_array($_POST['staffmenu'],$c_assign[$_POST['codemenu']])){
$ins=mysqli_query($dbc, "INSERT INTO staff_clients (`staffID`,`clientID`) VALUES ('".$_POST['staffmenu']."','".$_POST['codemenu']."')");
$c_assign[$_POST['codemenu']][]=$_POST['staffmenu'];
}
if (in_array($_POST['staffmenu'],$c_assign[$_POST['codemenu']]) || $ins) {
echo "<font size=2 color=green>Successfully added: <b>";
echo $c_meta[$_POST['codemenu']]['name'] . "</b> to <b>";
echo $s_meta[$_POST['staffmenu']]['firstname'].' '.$s_meta[$_POST['staffmenu']]['lastname']. "</b>'s client field in staff_clients</font><br>";
// echo $query;
} else {
echo "<font color=red>ERROR!</font>";
print mysqli_error($ins);
}
}
}
?>
<html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8">
<!--<link rel="stylesheet" href="css/tablesort.css" type="text/css" charset="utf-8">-->
<!-- <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js" type="text/javascript"></script> -->
<script src="js/jquery.js" type="text/javascript" charset="utf-8"></script>
<script src="js/jquery-ui.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
function removeAssignment(c,s){
var vars='submit=1&remove=1&clientID='+c+'&staffID='+s;
$.post('client_assign.php', vars, function(response) {
alert(response);
if(response.match(/^success/)) $('#s-'+s+'_c-'+c).fadeOut();
});
return false;
}
</script>
</head>
<body>
<?php
include_once('topbar.php');
?>
<div id="wrapper">
<div id="client_profile">
<?php
// echo "<div class='container'>";
echo "<form method=\"POST\" action=\"client_assign.php\" style='padding:0 100px;'>\n";
echo "<br /><br /><br />";
// -- STAFFMENU START
echo "<h2>Add a Staff Assignment</h2>";
echo "<br />";
echo "<select name=\"staffmenu\">\n<option>Select Staff</option>";
foreach ($s_meta as $sid=>$staff) {
$fullname = $staff['firstname'] . " " . $staff['lastname'];
echo "<option value=\"" . $sid . "\" ";
if (isset($_POST['staffmenu']) && $sid == $_POST['staffmenu']) { echo "SELECTED"; }
echo ">" . $fullname;
echo "</option>\n";
}
echo "</select>\n";
// -- STAFFMENU ENDS
// -- CODEMENU START
echo "<select name=\"codemenu\">\n<option>Select Client</option>";
foreach ($c_meta as $cid=>$code) {
echo "<option value=\"" . $cid . "\">";
if ($code['code']) {
echo $code['code'] . " - ";
}
echo $code['name'];
echo "</option>\n";
}
echo "</select>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Add\">\n";
// -- CODEMENU ENDS
echo "<br /><br /><br />";
echo "<h2>".(!empty($c_assign)?"Current Assignments":"No Assigments")."</h2>";
echo "<p style='text-align: center;'><a href='#cli'>View by client</a> or <a href='#con'>by consultant</a></p>";
echo "<a name='con'> </a><br /><br /><br /><h1>Assignments by Consultant</h1><br />";
$i=0;
// foreach ($c_meta as $c=>$client)
foreach ($s_meta as $s=>$staff)
if(isset($s_assign[$s])) {
$cs=$s_assign[$s];
echo "<hr /><h3>".$s_meta[$s]['firstname'].' '.$s_meta[$s]['lastname']."</h3>";
// echo "<div class='client_ct'>".."</div>";
foreach($cs as $k=>$c){
echo "<div id='s-{$s}_c-{$c}'>"
.(!empty($c_meta[$c]['name']) ? $c_meta[$c]['name'] : '')
.(!empty($c_meta[$c]['code']) ? " - ".$c_meta[$c]['code'] : '')
." <sup><a href='#' class='remove' onclick='return removeAssignment({$c},{$s})'>x</a></sup></div>";
}
echo "<br>";
$i++;
}
echo "<a name='cli'> </a><br /><br /><br /><br /><h1>Assignments by Client</h1>";
echo "<p style='text-align: center;'><a href='#cli'>View by client</a> or <a href='#con'>by consultant</a></p><br />";
$i=0;
foreach ($c_meta as $c=>$client)
if(isset($c_assign[$c])) {
$sc=$c_assign[$c];
echo "<h3>".$c_meta[$c]['name'].(!empty($c_meta[$c]['code'])?" - ".$c_meta[$c]['code']:'')."</h3>";
foreach($sc as $k=>$s){
echo "<div id='s-{$s}_c-{$c}'>".$s_meta[$s]['firstname'].' '.$s_meta[$s]['lastname']." <sup><a href='#' class='remove' onclick='return removeAssignment({$c},{$s})'>x</a></sup></div>";
}
echo "<br>";
$i++;
}
echo "</form>";
// echo "</div>";
?>
</div></div>
</body>
</html>