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
314
315
316
317
318
319
320
321
322
323
|
<?php require_once(__DIR__ . '/../checkuser.php'); session_start(); function addDetail($job_id) { global $dbh;
//----------------------------------------------------------------------------- // Find job by id //----------------------------------------------------------------------------- $sql = "SELECT * FROM sup_job WHERE id = ?"; $parameters = array($job_id); if (!($sth = $dbh->prepare($sql))) { throw new Exception("sql prepare statement failure: $sql"); } $sth->setFetchMode(PDO::FETCH_ASSOC); if (!$sth->execute($parameters)) { throw new Exception("sql execute statement failure: $sql"); } $job = $sth->fetch(PDO::FETCH_ASSOC); if (empty($job)) { throw new Exception('Job not found!'); }
require(__DIR__ . '/add.php');
//----------------------------------------------------------------------------- // Return array parameters //----------------------------------------------------------------------------- $pending_tasks = array(); if (Util::isAdmin()) { /*$sql = " SELECT pending.* FROM sup_job_pending pending INNER JOIN sup_job job ON job.id = pending.job_id WHERE job.customer_id = ? AND pending.actived = ? AND pending.deleted = ? AND pending.job_id='-1' ORDER BY pending.id "; $parameters = array($job['customer_id'], 1, 0); if (!($sth = $dbh->prepare($sql))) { throw new Exception("sql prepare statement failure: $sql"); } $sth->setFetchMode(PDO::FETCH_ASSOC); if (!$sth->execute($parameters)) { throw new Exception("sql execute statement failure: $sql"); } $pending_tasks = $sth->fetchAll();*/ }
//get pendings job
$sql6 = "select job.*,job_detail.*, job_detail.remarks as job_detail_remarks, job_detail.id as job_detail_id, job_detail.status as job_detail_status, job_pending.id as job_pending_id from sup_job job, sup_job_detail job_detail, sup_job_pending job_pending where job.id = job_detail.job_id and job_pending.job_detail_id = job_detail.id and job.customer_id = ? and job_detail.actived = 1 and job_detail.deleted = 0 and job_detail.status = 3 and job_detail.job_id != ? and job.status = ? and ((job.date >= ? and job.job_type = 'JOB') or (job.job_type = 'CALL IN')) and job_detail.follow_up_flag = ? group by job_detail_id";
if (!($sth6 = $dbh->prepare($sql6))) { throw new Exception("sql prepare statement failure: $sql6"); } $sth6->setFetchMode(PDO::FETCH_ASSOC); if (!$sth6->execute(array($job["customer_id"], $job["id"], 2, "2014-01-01", 0))) { throw new Exception("sql execute statement failure: $sql6"); }
$pending_tasks = $sth6->fetchAll();
$sql = "SELECT column_name FROM information_schema.columns WHERE table_schema = (SELECT DATABASE()) AND table_name = ?"; $parameters = array('sup_job_detail'); if (!($sth = $dbh->prepare($sql))) { throw new Exception("sql prepare statement failure: $sql"); } $sth->setFetchMode(PDO::FETCH_ASSOC); if (!$sth->execute($parameters)) { throw new Exception("sql execute statement failure: $sql"); } $job_detail_columns = $sth->fetchAll();
$job_detail_attributes = array(); foreach ($job_detail_columns as $column) { $column = $column['column_name']; $job_detail_attributes[$column] = null; }
$json_details = array(); /*foreach ($pending_tasks as $pending) { $detail = JobPending::convert_to_job_detail($pending, $job_detail_attributes); $json_details[] = json_encode($detail); }*/ if (empty($json_details)) { $detail = $job_detail_attributes; $json_details[] = json_encode($detail); }
return array( 'job' => $job, 'json_details' => $json_details, 'pending_tasks' => $pending_tasks ); } extract(addDetail($_GET['job_id']));
$sql = "SELECT column_name FROM information_schema.columns WHERE table_schema = (SELECT DATABASE()) AND table_name = ?"; $parameters = array('sup_job_detail'); if (!($sth = $dbh->prepare($sql))) { throw new Exception("sql prepare statement failure: $sql"); } $sth->setFetchMode(PDO::FETCH_ASSOC); if (!$sth->execute($parameters)) { throw new Exception("sql execute statement failure: $sql"); } $columns = $sth->fetchAll();
$defaultJobDetail = array(); foreach ($columns as $column) { $column = $column['column_name']; $defaultJobDetail[$column] = null; }
$sql5 = "select * from sup_task_category where deleted = 0 order by task_category_id ASC"; if (!($sth5 = $dbh->prepare($sql5))) { throw new Exception("sql prepare statement failure: $sql5"); }
if (!$sth5->execute()) { throw new Exception("sql execute statement failure: $sql5"); } $task_categories = $sth5->fetchAll();
?><!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ng="http://angularjs.org"> <head>
<?php require(__DIR__ . '/../inc/_head_meta.php'); ?>
<?php require(__DIR__ . '/../inc/_head_css.php'); ?>
<style type="text/css"> body { padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */ padding-bottom: 40px; } </style>
<?php require(__DIR__ . '/../inc/_head_script.php'); ?>
<script type="text/javascript"> function JobDetailControl($scope) { function resetModel() { $.extend($scope, <?=json_encode($defaultJobDetail)?>); }
resetModel(); $.extend($scope, { addDetail: function() { $scope.details.push({ <?php // Example: title: $scope.title, remarks: $scope.remarks... $tmp_values = array(); foreach ($defaultJobDetail as $key => $value) { $tmp_values[] = $key.': $scope.'.$key; } echo implode(', ', $tmp_values); ?> }); resetModel(); }, removeDetail: function(index) { $scope.details.splice(index, 1); }, details: [ <?=isset($json_details) ? implode(', ', $json_details) : ''?> ] }); } </script>
<script type="text/javascript"> $(function () { $(".pending_task").attr("disabled", true); });
function active_pending_task(el, pending_job_detail_id){ //var pending_job_detail_id = $(el).val(); if($(el).prop("checked")){ $(".pending_task_"+pending_job_detail_id).removeAttr("disabled"); }else{ $(".pending_task_"+pending_job_detail_id).attr("disabled", true); }
} </script>
</head> <body>
<?php require( __DIR__ . '/../inc/_navbar.php'); ?>
<div class="container">
<!--<h2>Add Tasks to Job #<?//=h($job['id'])?></h2>--> <h2>Add Tasks to Job <?php foreach($_SESSION["all_job_ids"] as $job_id) echo "#".$job_id." ";?></h2> <form id="form" class="form-horizontal" method="post"> <?php $attribute = 'job_id'; ?> <input type="hidden" name="<?=$attribute?>" value="<?=$_GET['job_id']?>" />
<?php if(!empty($pending_tasks)){ $i = 0; foreach($pending_tasks as $key => $pending_task){ ?> <div> <div class="control-group"> <label class="control-label">#Follow Up Task</label>
<div class="controls" style="margin-bottom: 20px;"> <?php $attribute = 'add_to_job'; ?> <input type="checkbox" name="pending_task[<?=$i?>][<?= $attribute ?>]" value="1" onclick="active_pending_task(this, <?=$pending_task["id"]?>);" />
<div style="display: inline-block; position: relative; top:3px;"> Add to this job </div>
</div>
<div class="controls"> <?php $attribute = 'from_job_pending_id'; ?> <input type="hidden" name="pending_task[<?=$i;?>][<?=$attribute?>]" value="<?=$pending_task["job_pending_id"]?>" /> <?php $attribute = 'job_detail_id'; ?> <input type="hidden" name="pending_task[<?=$i;?>][<?=$attribute?>]" value="<?=$pending_task["id"]?>" class="pending_task pending_task_<?=$pending_task["id"]?>"/>
<?php $attribute = 'task_category_id'; $label = 'Task Category ID';?> <select name="pending_task[<?=$i;?>][<?= $attribute ?>]" placeholder="<?= $label ?>" class="required pending_task pending_task_<?=$pending_task["id"]?>"> <?php foreach ($task_categories as $key22 => $task_category) {
if($task_category["task_category_id"] == $pending_task["task_category_id"]) $selected = "selected"; else $selected = "";
echo '<option value="'.$task_category["task_category_id"].'" '.$selected.'>'.$task_category["category_name"].'</option>';
} ?>
</select> <br><br> <?php $attribute = 'title'; $label = 'Title'; ?> <input type="text" name="pending_task[<?=$i;?>][<?=$attribute?>]" placeholder="<?=$label?>" value="<?=$pending_task["title"]?>" class="required pending_task pending_task_<?=$pending_task["id"]?>"/>
</div> <br> <?php $attribute = 'remarks'; $label = 'Remarks'; ?> <div class="controls"> <textarea name="pending_task[<?=$i;?>][<?=$attribute?>]" class="span6 textarea_style pending_task pending_task_<?=$pending_task["id"]?>" placeholder="<?=$label?>"><?=$pending_task["job_detail_remarks"]?></textarea>
</div>
</div> </div> <?php $i++; } } ?>
<hr>
<div id="ng-app" ng:app="" ng:controller="JobDetailControl"> <div ng:repeat="detail in details"> <div class="control-group"> <label class="control-label">#New Task<!--{{$index+1}}--></label> <div class="controls"> <?php $attribute = 'from_job_pending_id'; ?> <input type="hidden" name="job_detail[{{$index+1}}][<?=$attribute?>]" value="{{detail.<?=$attribute?>}}" />
<?php $attribute = 'task_category_id'; $label = 'Task Category ID';?> <select id="{{detail.id}}" ng:readonly="detail.from_job_pending_id" name="job_detail[{{$index+1}}][<?= $attribute ?>]" class="span2 required" placeholder="<?= $label ?>">
<?php foreach ($task_categories as $key => $task_category) { ?> <option value="<?=$task_category["task_category_id"]?>"><?=$task_category["category_name"]?></option> <?php } ?> </select> <br><br> <?php $attribute = 'title'; $label = 'Title'; ?> <input ng:readonly="detail.from_job_pending_id" type="text" name="job_detail[{{$index+1}}][<?=$attribute?>]" placeholder="<?=$label?>" value="{{detail.<?=$attribute?>}}" class="required" />
</div> <br> <?php $attribute = 'remarks'; $label = 'Remarks'; ?> <div class="controls"> <textarea ng:readonly="detail.from_job_pending_id" name="job_detail[{{$index+1}}][<?=$attribute?>]" class="span6 textarea_style" placeholder="<?=$label?>">{{detail.<?=$attribute?>}}</textarea> <button type="button" ng:click="removeDetail($index)" class="btn btn-danger remove-detail-btn">Delete</button> </div> </div> </div> <div class="control-group"> <div class="controls"> <input type="submit" class="btn btn-primary" value="Save" /> <button type="button" ng:click="addDetail()" class="btn add-detail-btn">Add Task</button> </div> </div> </div> </form>
<script type="text/javascript"> $(function() { function init() { var $removeDetailBtn = $('.remove-detail-btn'); if ($removeDetailBtn.length > 0) { $removeDetailBtn.show(); } else { $removeDetailBtn.hide(); } } $(document).on('click', '.add-detail-btn, .remove-detail-btn', function() { init(); }); init();
$('#form').validate(); }); </script>
<?php require( __DIR__ . '/../inc/_footer.php'); ?>
</div> <!-- /container --> </body> </html>
|