/var/www/onesupportsys.onesolution.hk/project/index.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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
require_once(__DIR__ '/../checkuser.php');
function 
index() {
    global 
$dbh$sqlsrv_dbh;
    
    
$get_keys = array('id','project_id''customer_id''project_date''staff_id''status');
    
$get = array();
    foreach (
$get_keys as $get_key) {
        $
$get_key = isset($_GET[$get_key]) ? $_GET[$get_key] : null;
        
$get[$get_key] = &$$get_key;
    }

    
// Default search
    
$tmp_now = new DateTime;
    if (!isset(
$_GET['start_date']) && empty($start_date) && $_GET["today"]==1) {
        
$start_date Util::date_to_string($tmp_now);
    }
    if (!isset(
$_GET['end_date']) && empty($end_date) && $_GET["today"]==1) {
        
$end_date Util::date_to_string($tmp_now);
    }
    if (!isset(
$_GET['staff_id']) && empty($staff_id)) {
        if (!
Util::isAdmin()) {
            
$staff_id $_SESSION['webadmin']['id'];
        }

    }else{
        
$staff_id $_GET['staff_id'];
    }

    if (!isset(
$_GET['status']) && empty($status)) {
        
//$status = 1; // Open
    
}


    
// Show all
    
if ($_GET['show_all'] == 1) {
        foreach (
$get_keys as $get_key) {
            if (
Util::isGuest() && $get_key == 'staff_id') {
                continue;
            }
            $
$get_key null;
        }
    }

    
$sql "
SELECT job.*, job.status as job_status
FROM sup_job job
WHERE
    (COALESCE(LENGTH(?), 0) = 0 OR job.id = ?)
    AND (COALESCE(LENGTH(?), 0) = 0 OR job.customer_id = ?)
    AND (COALESCE(LENGTH(?), 0) = 0 OR job.staff_id = ?)
    AND (COALESCE(LENGTH(?), 0) = 0 OR job.status = ?)
    AND (COALESCE(LENGTH(?), 0) = 0 OR job.date = ?)
    AND job.project_id IS NOT NULL
ORDER BY job.id ASC
"
;
    
$parameters = array(
        
$id$id,
        
$customer_id$customer_id,
        
$staff_id$staff_id,
        
$status$status,
        
$project_date$project_date,
    );


    
$pagination = new MySqlPagination($sql$parameters);
    
$sql .= $pagination->getSqlLimitAndOffset();

    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");
    }

    
$jobs $sth->fetchAll();
    
    
$sql "SELECT * FROM v_cm_customer_support V_CM_CUSTOMER_SUPPORT ORDER BY company_name";
    if (!(
$sth $dbh->prepare($sql))) {
        throw new 
Exception("sql prepare statement failure: $sql");
    }
    
$sth->setFetchMode(PDO::FETCH_ASSOC);
    if (!
$sth->execute()) {
        throw new 
Exception("sql execute statement failure: $sql");
    }
    
$customers $sth->fetchAll();
    
    
$sql "SELECT * FROM sys_login WHERE deleted = ? ORDER BY username";
    
$parameters = array(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");
    }
    
$staffs $sth->fetchAll();
    
    
$tmp_customer_map = array();
    foreach (
$customers as &$tmp_customer) {
        
$tmp_customer_id $tmp_customer['cust_id'];
        
$tmp_customer_map[$tmp_customer_id] = $tmp_customer;
    }
    
    
$tmp_staff_map = array();
    foreach (
$staffs as &$tmp_staff) {
        
$tmp_staff_id $tmp_staff['id'];
        
$tmp_staff_map[$tmp_staff_id] = $tmp_staff;
    }


    
$sql "SELECT * FROM sup_project WHERE status = 1  ORDER BY project_name ASC";
    if (!(
$sth $dbh->prepare($sql))) {
        throw new 
Exception("sql prepare statement failure: $sql");
    }
    
$sth->setFetchMode(PDO::FETCH_ASSOC);
    if (!
$sth->execute()) {
        throw new 
Exception("sql execute statement failure: $sql");
    }
    
$projects $sth->fetchAll();


    return 
array_merge($get, array(
        
'jobs' => $jobs,
        
'projects' => $projects,
        
'message' => $_GET['message'],
        
'customers' => $customers,
        
'staffs' => $staffs,
        
'statusOptions' => Job::statusOptions(),
        
'pagination' => $pagination->toString(),
    ));
}
extract(index());
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<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'); ?>
    
</head>
<body>
    
    <?php require(__DIR__ '/../inc/_navbar.php'); ?>
    
    <div class="container">
        
        <?php if (isset($message) && !empty($message)): ?>
        <div class="alert alert-info">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <h5 class="alert-heading">Note:</h5>
            <p><?=$message?></p>
        </div>
        <?php endif; ?>

        <?php if (isset($_SESSION["remark_project_id"]) && !empty($_SESSION["remark_project_id"])): ?>
            <div class="alert alert-info">
                <button type="button" class="close" data-dismiss="alert">&times;</button>
                <h5 class="alert-heading">Last Add/Modify Project:</h5>
                <p>
                    <?php
                        
echo "<a href='../project/modifyform.php?id=".$_SESSION["remark_project_id"]."' target='_blank'> Project ID: ".$_SESSION["remark_project_id"]."</a><br>";
                    
?>
                </p>
            </div>
        <?php endif; ?>


        <h2>Project</h2>

        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span12">
                    <div class="hero-unit" style="padding:10px">
                        <a href="#" id="search_btn" class="btn btn-link"><h4><i class="icon-list-alt"></i> Search Form</h4></a>
                        <script type="text/javascript">
                            $(function() {
                                $('#search_btn').click(function(event) {
                                    event.preventDefault();
                                    $('#search_form').toggle();
                                });
                                $('.date-picker').datetimepicker({ pickTime: false });
                                $('.time-picker').datetimepicker({ pickDate: false, pickSeconds: false });
                                $('.select2').select2();
                                $('#search_form').validate();
                            });
                        </script>
                        <form id="search_form" class="form-horizontal" method="get">
                            <div class="control-group">
                                <?php $attribute 'id'$label 'Job no.'?>
                                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                                <div class="controls">
                                    <input type="text" id="<?=$attribute?>" name="<?=$attribute?>" placeholder="<?=$label?>" class="digits" value="<?=$$attribute?>" />
                                </div>
                            </div>

                            <div class="control-group">
                                <?php $attribute 'project_id'$label 'Project Name'?>
                                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                                <div class="controls">
                                    <select id="<?=$attribute?>" name="<?=$attribute?>" placeholder="Select a <?=$label?>" class="select2">
                                        <option value=""></option>
                                        <?php foreach ($projects as $project): ?>
                                            <option value="<?=$project['id']?>"<?=$project['id'] == $$attribute ' selected="selected"' ''?>><?=h($project['project_name'])?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>


                            <div class="control-group">
                                <?php $attribute 'customer_id'$label 'Customer'?>
                                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                                <div class="controls">
                                    <select id="<?=$attribute?>" name="<?=$attribute?>" placeholder="Select a <?=$label?>" class="select2">
                                        <option value=""></option>
                                        <?php foreach ($customers as $customer): ?>
                                        <option value="<?=$customer['cust_id']?>"<?=$customer['cust_id'] == $$attribute ' selected="selected"' ''?>><?=$customer['enable'] == '' '[Disabled] '?><?=h($customer['company_name'])?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <?php $attribute 'staff_id'$label 'Staff'?>
                                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                                <div class="controls">
                                    <select id="<?=$attribute?>" name="<?=$attribute?>" placeholder="Select a <?=$label?>" class="select2">
                                        <option value=""></option>
                                        <?php /*$num_staff_id = preg_replace("/[^0-9]/", '', $$attribute); */foreach ($staffs as $staff): ?>
                                        <option value="<?=$staff['id']?>"<?=$staff['id'] == $$attribute ' selected="selected"' ''?>><?=$staff['actived'] == '' '[Disabled] '?><?=h($staff['username'])?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="control-group">
                                <?php $attribute 'project_date'$label 'Project Date'?>
                                <label class="control-label" for="<?=$attribute?>"><?=$label?></label>
                                <div class="controls">
                                    <div class="input-append date-picker">
                                        <input type="text" id="<?=$attribute?>" name="<?=$attribute?>" class="dateISO" data-format="yyyy-MM-dd" value="<?=$$attribute?>" placeholder="<?=$label?>" />
                                        <span class="add-on">
                                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                                        </span>
                                    </div>
                                </div>
                            </div>

                            <div class="control-group">
                                <?php $attribute 'status'$label 'Status'$statusOptions Project::statusOptions();?>
                                <label class="control-label"><?=$label?></label>
                                <div class="controls">
                                    <select id="<?=$attribute?>" name="<?=$attribute?>" placeholder="Select a <?=$label?>">
                                        <option value=""></option>
                                        <?php foreach ($statusOptions as $value => $label): ?>
                                        <option value="<?=$value?>"<?=$value == $$attribute ' selected="selected"' ''?>><?=$label?></option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>

                            <div class="control-group">
                                <div class="controls">
                                    <button type="submit" class="btn btn-primary"><i class="icon-search icon-white"></i> Search</button>
                                    <a href="index.php?show_all=1" class="btn">Show All</a>
                                </div>
                            </div>
                        </form>
                    </div>
                </div><!--/span-->
            </div><!--/row-->
        </div>
        
        <?=$pagination?>

        <table class="table table-striped">
            <caption class="text-left hide"><h2>Project</h2></caption>
            <thead>
                <tr>
                    <th>&nbsp;</th>
                    <th>Number</th>
                    <th>Project Name</th>
                    <th>Customer</th>
                    <th>Date</th>
                    <th>Time</th>
                    <th>Staff</th>
                    <th>Status</th>
                </tr>
            </thead>
            <tbody>
                <?php
                    
foreach ($jobs as $job):

                        if(!empty(
$_GET["project_id"]) && $job["project_id"] != $_GET["project_id"]){
                            continue;
                        }
                
?>
                <tr>
                    <td><a href="../job/modifyform.php?id=<?=$job['id']?>" class="btn"><i class="icon-pencil"></i></a></td>
                    <td><?=$job['id']?></td>
                    <td>
                        <?php
                            $sql 
"SELECT * FROM sup_project WHERE id = ?";
                            if (!(
$sth $dbh->prepare($sql))) {
                                throw new 
Exception("sql prepare statement failure: $sql");
                            }
                            if (!
$sth->execute(array($job['project_id']))) {
                                throw new 
Exception("sql execute statement failure: $sql");
                            }
                            
$project $sth->fetch(PDO::FETCH_ASSOC);
                        
?>
                        <?=$project['project_name']?>

                    </td>
                    <td><?php $customer_detail Customer::company_name((int)$job['customer_id']); echo $customer_detail[0]["company_name"]?></td>
                    <td><?=$job['date']?></td>
                    <td><?=$job['start_time']."<br>to ".$job['end_time']?></td>
                    <td>
                        <?php
                            $staff_detail 
Staff::staff_name((int)$job['staff_id']); echo $staff_detail[0]["username"];
                        
?>
                    </td>

                    <td>
                        <i class="<?=in_array($job['job_status'], array(12)) ? 'icon-ok' 'icon-remove'?>"></i>
                        <?=h($statusOptions[$job['job_status']])?>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        
        <?=$pagination?>
        
        <div class="scroll_to_top">
            <a href="#" class="btn btn-link btn-mini scroll-to-top">Scroll to Top</a>
        </div>
        
        <script type="text/javascript">
        $(function() {
            $('.job-status, .job-time').tooltip({ html: true });
            $('.scroll-to-top').click(function(event) {
                event.preventDefault();
                scrollToTop();
            });
        });
        </script>
        
        <?php require(__DIR__ '/../inc/_footer.php'); ?>

    </div> <!-- /container -->
</body>
</html>

<?php
    
unset($_SESSION["remark_project_id"]);
?>