-
Notifications
You must be signed in to change notification settings - Fork 0
/
mFrontAjax.php
313 lines (305 loc) · 10.1 KB
/
mFrontAjax.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
<?php
session_start();
require_once("classes/tasksConnection.php");
require_once("classes/hrConnection.php");
require_once("_inc/mFunctions.php");
if(!empty($_POST['action']) && $_POST['action'] == "showAttachs"){
$attachId = $_POST['attachId'];
$images = array();
$others = array();
$res = "";
if(!empty($attachId)){
$db->query("SELECT * FROM attachments WHERE attach_group_id = :atid");
$db->bind(":atid",$attachId);
$getAttaches = $db->fetchAll();
if(!empty($getAttaches)){
foreach($getAttaches AS $row){
$ext = pathinfo($row['attach_desc'], PATHINFO_EXTENSION);
if(strtolower($ext) == "jpg" || strtolower($ext) == "jpeg" || strtolower($ext) == "png" || strtolower($ext) == "gif"){
array_push($images, $row['attach_desc']);
}else{
array_push($others, $row['attach_desc']);
}
}
}
if(!empty($images)){
$res .= '<ul id="Grid" class="list-unstyled" style="min-height: 300px">';
for($i = 0; $i < count($images); $i++){
$res .= '<li class="col-md-3 col-sm-6 col-xs-12 mix category_1 gallery-img" data-cat="1" style="display:block">
<div class="portfolio-item">
<a class="thumb-info" href="taskFiles/'.$images[$i].'" data-lightbox="gallery" data-title="'.$images[$i].'">
<img src="taskFiles/'.$images[$i].'" class="img-responsive" alt="">
<span class="thumb-info-title"> '.$images[$i].' </span>
</a>
<div class="tools tools-bottom">
<a href="taskFiles/'.$images[$i].'" download>
<i class="fa fa-download"></i>
</a>
<!-- a href="#">
<i class="fa fa-pencil"></i>
</a>
<a href="#">
<i class="fa fa-trash-o"></i>
</a -->
</div>
</div>
</li>';
}
$res .= '</ul>';
$res .= '<br />';
}
if(!empty($others)){
for($i = 0; $i < count($others); $i++){
if(strtolower(pathinfo($others[$i], PATHINFO_EXTENSION)) == 'pdf'){
$icon = 'filesIcons/pdfIcon.png';
}elseif(strtolower(pathinfo($others[$i], PATHINFO_EXTENSION)) == 'txt'){
$icon = 'filesIcons/textIcon.png';
}elseif(strtolower(pathinfo($others[$i], PATHINFO_EXTENSION)) == 'xlsx' || strtolower(pathinfo($others[$i], PATHINFO_EXTENSION)) == 'csv'){
$icon = 'filesIcons/excel.png';
}elseif(strtolower(pathinfo($others[$i], PATHINFO_EXTENSION)) == 'docx'){
$icon = 'filesIcons/wordIcon.png';
}else{
$icon = 'filesIcons/unknown.png';
}
$res .= '<div style="min-width:50px">';
$res .= '<div style="width:8%;height: 100%;float: left;">';
$res .= '<img style="width:100%;height: 115px" src="'.$icon.'" />';
$res .= '</div>';
$res .= '<span style="float:left;margin: 57px 13px;font-size:16px"><a href="taskFiles/'.$others[$i].'" target="_blankg">'.$others[$i].'</a></span>';
$res .= '</div>';
$res .= '<br style="clear:both" />';
}
}
}
echo $res;
}if(!empty($_POST['action']) && $_POST['action'] == "RateTask"){
$taskId = $_POST['taskId'];
$value = $_POST['value'];
$assignee = $_POST['assignee'];
try {
$db->beginTransaction();
$db->query("UPDATE tasks SET rating = :rte WHERE task_id = :tid");
$db->bind(":rte",$value);
$db->bind(":tid",$taskId);
$update = $db->execute();
if($value == NULL){
$desc = 'There is a rate on a task that you assigned is cleared <a href="taskDetails.php?k='.$taskId.'">GO?</a>';
}else{
$desc = 'There is a task that you assigned to is rated <a href="taskDetails.php?k='.$taskId.'">GO?</a>';
}
mInsertNotification($db,$assignee,$desc);
$db->endTransaction();
$res = 1;
} catch (Exception $e) {
$db->cancelTransaction();
$res = 2;
}
echo $res;
}if(!empty($_POST['action']) && $_POST['action'] == "commentOnTask"){
$commentarea = $_POST['commentarea'];
$attach_id = $_POST['attach_id'];
$usr = $_POST['usr'];
$task = $_POST['task'];
$commentors = $_POST['commentors'];
$commentors = array_values(array_unique($commentors));
if(($key = array_search($usr, $commentors)) !== false) {
unset($commentors[$key]);
}
$commentors = array_values(array_unique($commentors));
$data = '';
if($attach_id == "e"){
$attach_id = 0;
}
try {
$db->beginTransaction();
$db->query("INSERT INTO comments
SET
`comment_desc` = :cmnt,
`user_id` = :usr,
`task_id` = :tsk,
`attach_group_id` = :atch");
$db->bind(":cmnt",$commentarea);
$db->bind(":usr",$usr);
$db->bind(":tsk",$task);
$db->bind(":atch",$attach_id);
$insert = $db->execute();
if(!empty($commentors)){
$desc = 'There is a comment in a task that related to you';
mInsertNotification($db,$commentors,$desc);
}
$db->endTransaction();
$flag = 1;
} catch (Exception $e) {
$db->cancelTransaction();
$flag = 2;
}
if($flag == 1){
$db->query("SELECT * FROM comments WHERE task_id = :tsk");
$db->bind(":tsk",$task);
$comments = $db->fetchAll();
if(!empty($comments)){
foreach($comments AS $row){
$hr->query("SELECT users.*, jobs.job FROM users
INNER JOIN employees ON users.emp_id = employees.emp_id
INNER JOIN jobs ON employees.job_id = jobs.jobId
WHERE users.emp_id = :emp");
$hr->bind(":emp",$row['user_id']);
$getUser = $hr->fetch();
if(!empty($getUser)){
$userName = $getUser['name'];
$userImg = "http://iravin.com/devteam/attendance/assets/profileImages/".$getUser['img'];
$userJob = $getUser['job'];
}else{
$userName = "User Name";
$userImg = "http://iravin.com/devteam/attendance/assets/profileImages/avatar-1-xl.jpg";
$userJob = "User Role";
}
$data .= '<li class="messages-item">
<img class="messages-item-avatar" src="'.$userImg.'" alt="">
<span class="messages-item-from">'.$userName.'</span>';
if($row['attach_group_id'] != 0){
$data .= '<span class="messages-item-attachment">
<i class="fa fa-paperclip mAttachs" data-attach="'.$row['attach_group_id'].'"></i>
</span>';
}
$data .= '<span class="messages-item-subject">'.$userJob.'</span>
<span class="messages-item-preview">'.$row['comment_desc'].'<input type="hidden" name="commentor" class="commentor" value="'.$row['user_id'].'" /></span>
</li>';
}
}
}
echo $data;
}elseif(!empty($_GET['aid'])){
$aid = $_GET['aid'];
if(!empty($_FILES)){
foreach($_FILES as $file)
{
$file_name = "comment-".time().".".pathinfo($file['name'],PATHINFO_EXTENSION);
if(move_uploaded_file($file['tmp_name'], "taskFiles/".$file_name))
{
$flag = 1;
try {
$db->beginTransaction();
if($aid == "e"){
$db->query("SELECT IFNULL(MAX(attach_group_id),0) + 1 AS newId FROM attachments");
$newId = $db->fetch();
if(!empty($newId)){
$newId = $newId['newId'];
}else{
$newId = 1;
}
}else{
$newId = $aid;
}
$db->query("INSERT INTO attachments SET attach_group_id = :n, attach_desc = :d");
$db->bind(":n",$newId);
$db->bind(":d",$file_name);
$db->execute();
$db->endTransaction();
$flag = 1;
$status = "The file uploaded successuflly";
} catch (Exception $e) {
$db->cancelTransaction();
$flag = 2;
$status = "Failed to add the file please try again later";
}
}
else
{
$status = "Failed to upload file please try again later";
$flag = 2;
}
}
}else{
$status = "";
$flag = "";
$newId = "";
}
$array_res = array(
"status" => $status,
"flag" => $flag,
"naid" => $newId
);
echo json_encode($array_res);
}if(!empty($_POST['action']) && $_POST['action'] == "disputAction"){
$task = $_POST['task'];
$creator = $_POST['creator'];
$emps = array();
$hr->query("SELECT emp_loc.emp_id FROM emp_loc
INNER JOIN employees ON emp_loc.job_id = employees.job_id
WHERE employees.emp_id = :emp");
$hr->bind(":emp",$creator);
$getManagers = $hr->fetchAll();
if(!empty($getManagers)){
foreach($getManagers AS $row){
array_push($emps, $row['emp_id']);
}
}
if(!empty($emps)){
try {
$db->beginTransaction();
for($i = 0; $i < count($emps); $i++){
//HERE WE GONNA INSERT THE FOLLOWERS AND SEND A NOTIFICATION
$db->query("SELECT id FROM tasks_followers WHERE task_id = :tid AND follower_id = :fid LIMIT :lmt");
$db->bind(":tid", $task);
$db->bind(":fid", $emps[$i]);
$db->bind(":lmt", 1);
$get = $db->fetch();
if(empty($get)){
$db->query("INSERT INTO tasks_followers (task_id,follower_id) VALUES (:tsk,:flowr)");
$db->bind(":tsk",$task);
$db->bind(":flowr",$emps[$i]);
$db->execute();
}
}
$desc = 'You are called in a task by the assignee of that task <a href="taskDetails.php?k='.$task.'">GO?</a>';
mInsertNotification($db,$emps,$desc);
$db->endTransaction();
$res = 1;
} catch (Exception $e) {
$db->cancelTransaction();
$res = 3;
}
}else{
$res = 2;
}
echo $res;
}elseif(!empty($_POST['action']) && $_POST['action'] == "loginAction"){
$username = $_POST['username'];
$passowrd = $_POST['passowrd'];
$remember = $_POST['remember'];
$hr->query("SELECT * FROM users WHERE `email` = :em AND pass = :pass LIMIT 1");
$hr->bind(":em",$username);
$hr->bind(":pass",md5($passowrd));
$getUser = $hr->fetch();
if(!empty($getUser)){
$_SESSION['tasks_empId'] = $getUser['emp_id'];
$_SESSION['tasks_userName'] = $getUser['name'];
$_SESSION['tasks_userImg'] = $getUser['img'];
$_SESSION['tasks_isLogged'] = 1;
if($remember == 1){
setcookie("tasks_empId", $getUser['emp_loc'], time() + (86400 * 30), "/");
setcookie("tasks_userName", $getUser['emp_loc'], time() + (86400 * 30), "/");
setcookie("tasks_userImg", $getUser['emp_loc'], time() + (86400 * 30), "/");
setcookie("tasks_cookie", 1, time() + (86400 * 30), "/");
}
$flag = 1;
}else{
$flag = 2;
}
echo $flag;
}elseif(!empty($_POST['action']) && $_POST['action'] == "logoutAction"){
unset($_SESSION['tasks_empId']);
unset($_SESSION['tasks_userName']);
unset($_SESSION['tasks_userImg']);
unset($_SESSION['tasks_isLogged']);
if(!empty($_COOKIE['tasks_cookie'])){
unset($_COOKIE['tasks_cookie']);
}
$res =1;
echo $res;
}
//CLOSE ALL CONNECTIONS
$db->closeConn();
$hr->closeConn();
////////////////////////////////////////////////////////////////////////////