/var/www/onesupportdemo.onesolution.hk/job_bk/views/generate_date_list.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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<?php include ('../../inc/configure.php'); ?>


<style type="text/css">
    div.scroll_to_top {
        position: fixed;
        bottom: 0;
        left: 50%;
        color: white;
        padding: 2px 5px 0px 5px;
    }
</style>

<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;
    }
    td{
        text-align: center;
    }
</style>


<?php

    $sql 
"SELECT * FROM sup_public_holiday WHERE year >= '".date("Y")."' order by holiday_date ASC";
    
$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");
    }
    
$holiday $sth->fetchAll();

    
$allow_edit_mode false;
    if (
Util::isAdmin()) { // admin
        
$allow_edit_mode true;
    } else {
        if (empty(
$job['id'])) { // new job
            
$allow_edit_mode true;
        } else {
            if (
$job['type'] == 4) { // remote service call
                
$allow_edit_mode true;
            }
        }
    }
    
$period      $_GET["period"];
    
$frequency      $_GET["frequency"];
    
$date_from $_GET["date_from"];
    
$date_to   $_GET["date_to"];
    
$selected_week   $_GET["selected_week"];
    
$start_time_weekly   $_GET["start_time_weekly"];
    
$end_time_weekly   $_GET["end_time_weekly"];
    
$start_time_daily   $_GET["start_time_daily"];
    
$end_time_daily   $_GET["end_time_daily"];
    
$whichweek   $_GET["whichweek"];

    
//monthly
    
$selected_week_array explode(','$selected_week);
    
$start_time_array explode(','$start_time_weekly);
    
$end_time_array explode(','$end_time_weekly);

    if(
strtotime($date_from) > strtotime($date_to)){
        echo 
"<div style='color: red;'>Job Date From should be early than Job Date To!</div>";
        exit;
    }

    if(empty(
$date_from) || empty($date_to)){
        echo 
"<div style='color: red;'>Job Date From or Job Date To should not be empty!</div>";
        exit;
    }

    if(
$period == && empty($whichweek)){
        echo 
"<div style='color: red;'>Which Week should not be empty!</div>";
        exit;
    }


    echo 
"<table border='1' cellpadding='5' style='text-align: center;'>
            <tr>
            <th><input type='button' id='toggle2' value='All' onClick='available_date()' style='width: 50px;'/></th>
            <th>Date</th>
            <th>Week</th>
            <th>Start Time</th>
            <th>End Time</th>
            </tr>"
;

    if(
$period == ){ //daily

        
$startTimeStamp strtotime($date_from);
        
$endTimeStamp strtotime($date_to);

        
$timeDiff abs($endTimeStamp $startTimeStamp);

        
$numberDays $timeDiff/86400;  // 86400 seconds in one day

        // and you might want to convert to integer
        
$numberDays intval($numberDays);
        
$loopnum floor($numberDays/$frequency)+1;


        echo 
"<input type=\"hidden\" id=\"totalloop1\" value='".$loopnum."' />";

        for(
$i 0$i<$loopnum$i++){

            
//$enddate = date(strtotime($startdate . "+1 day"));
            
$NewDate=Date('Y-m-d'strtotime($date_from ."+".$frequency*$i." days"));

            
$NewWeek date("D"strtotime($NewDate));

            
?>
            <tr>
                <td>
                    <input type="checkbox" name="arraynum[]" value='<?=$i?>' class="checkall2"/>
                </td>

                <td>
                    <?//=$NewDate?>
                        <div class="controls" style="padding: 0;margin: 0;" >
                            <div class="input-append date-picker">
                                <input type="text" id="date_<?=$i?>" name="selected_day[]" value="<?= h(Util::value_to_date_string($NewDate)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach($holiday as $holiday_date) if($holiday_date["holiday_date"] == $NewDate || $NewWeek == "Sun") echo "style='color: #FA5858;'"?>/>

                                    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                                    </span>

                            </div>
                        </div>

                </td>

                <td>
                    <div id="week_<?=$i?>" >
                        <?=$NewWeek?>
                    </div>
                </td>

                <td>
                    <?php $attribute 'start_time1'$label 'Start Time'?>

                    <div class="controls" style="padding: 0;margin: 0;">
                        <div class="input-append time-picker">
                            <input type="text" id="<?=$attribute?>" name="<?=$attribute?>[]" value="<?=$start_time_daily?>" class="time" data-format="hh:mm" placeholder="<?=$label?>"<?=$allow_edit_mode '' ' disabled="disabled"'?> />
                            <?php if ($allow_edit_mode): ?>
                                <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                            <?php endif; ?>
                        </div>
                    </div>
                </td>

                <td>
                    <?php $attribute 'end_time1'$label 'End Time'?>

                    <div class="controls" style="padding: 0;margin: 0;">
                        <div class="input-append time-picker">
                            <input type="text" id="<?=$attribute?>" name="<?=$attribute?>[]" value="<?=$end_time_daily?>" class="time" data-format="hh:mm" placeholder="<?=$label?>"<?=$allow_edit_mode '' ' disabled="disabled"'?> />
                            <?php if ($allow_edit_mode): ?>
                                <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                            <?php endif; ?>
                        </div>
                    </div>
                </td>

            </tr>
        <?php
        
}

    }else if(
$period==2){  //weekly

        
$startTimeStamp strtotime($date_from);
        
$endTimeStamp strtotime($date_to);

        
$timeDiff abs($endTimeStamp $startTimeStamp);

        
$numberweeks $timeDiff/86400/7;  // 86400 seconds in one day

        // and you might want to convert to integer
        
$numberweeks intval($numberweeks);
        
$loopnum floor($numberweeks/$frequency)+1;


        
$countrow 0;
        for(
$i 0$i<$loopnum$i++){

            
//$enddate = date(strtotime($startdate . "+1 day"));
            
$NewDate=Date('Y-m-d'strtotime($date_from ."+".$frequency*$i." week"));
            
$NewWeek date("D"strtotime($NewDate));

            
$week = array();
            
$week Job::week();

            for(
$j 1$j <= 7$j++){
                
$adddays $j-1;
                
$NewDate=Date('Y-m-d'strtotime($date_from ."+".$frequency*$i." week +".$adddays." days"));
                
$NewWeek date("D"strtotime($NewDate));
                
$NewWeek_num date("N"strtotime($NewDate));

                
//echo $NewDate."(".$NewWeek."),";
                
foreach($selected_week_array as $key => $targeweek){
                    
//echo $targeweek;

                    
if($NewWeek_num == $targeweek && $NewDate <= $date_to){    //this week equal to the user selected week, that is the target
                        
?>
                        <tr>
                            <td>
                                <input type="checkbox" name="arraynum[]" value='<?=$countrow?>' class="checkall2"/>

                            </td>

                            <td>
                                <?//=$NewDate?>
                                <div class="controls" style="padding: 0;margin: 0;" >
                                    <div class="input-append date-picker">
                                        <input type="text" id="date_<?=$countrow?>" name="selected_day[]" value="<?= h(Util::value_to_date_string($NewDate)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach($holiday as $holiday_date) if($holiday_date["holiday_date"] == $NewDate || $NewWeek == "Sun") echo "style='color: #FA5858;'"?>/>

                                    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" "></i>
                                    </span>

                                    </div>
                                </div>

                            </td>

                            <td>
                                <div id="week_<?=$countrow?>" >
                                    <?=$NewWeek?>
                                </div>
                            </td>

                            <td>
                                <?php $attribute 'start_time1'$label 'Start Time'?>

                                <div class="controls" style="padding: 0;margin: 0;">
                                    <div class="input-append time-picker">
                                        <input type="text" id="<?=$attribute?>" name="<?=$attribute?>[]" value="<?=$start_time_array[$key]?>" class="time" data-format="hh:mm" placeholder="<?=$label?>"<?=$allow_edit_mode '' ' disabled="disabled"'?> />
                                        <?php if ($allow_edit_mode): ?>
                                            <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </td>

                            <td>
                                <?php $attribute 'end_time1'$label 'End Time'?>

                                <div class="controls" style="padding: 0;margin: 0;">
                                    <div class="input-append time-picker">
                                        <input type="text" id="<?=$attribute?>" name="<?=$attribute?>[]" value="<?=$end_time_array[$key]?>" class="time" data-format="hh:mm" placeholder="<?=$label?>"<?=$allow_edit_mode '' ' disabled="disabled"'?> />
                                        <?php if ($allow_edit_mode): ?>
                                            <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </td>

                        </tr>
                        <?php
                        $countrow
++;
                    }
                }
            }
        }

        echo 
"<input type=\"hidden\" id=\"totalloop2\" value='".$countrow."' />";

    }else if(
$period==3){   //monthly
        
$date_from_month date("n"strtotime($date_from)); //1-12

        
$datefrom_year_month_day =  date("Y-m-01"strtotime($date_from));
        
$dateto_year_month_day =  date("Y-m-01"strtotime($date_to));
        
//$datetime1 = date_create($date_from);
        
$datetime1 date_create($datefrom_year_month_day);
        
//$datetime2 = date_create($date_to);
        
$datetime2 date_create($dateto_year_month_day);
        
$interval date_diff($datetime1$datetime2);
        
$numofmonth $interval->format('%m months');
        
$numofyear $interval->format('%y months');

        
$loopnum $numofyear*12+$numofmonth+1;

        
$countrow 0;

        
//testing

        
$datefrom_year_month =  date("Y-m"strtotime($date_from));

        for(
$i 0$i $loopnum$i++){ //how many month between that period

            
for($j 1$j <= 7$j++){
                
$adddays $j-1;

                
//$NewDate=Date('Y-m-d', strtotime($date_from ."+".$frequency*$i." month +".($whichweek-1)." week +".$adddays." days"));
                
$NewDate=Date('Y-m-d'strtotime($datefrom_year_month."-01" ."+".$frequency*$i." month +".($whichweek-1)." week +".$adddays." days"));


                if(
$whichweek==&& date("j"strtotime($NewDate)) <29){
                    break;
                }
                
$NewWeek date("D"strtotime($NewDate));
                
$NewWeek_num date("N"strtotime($NewDate));


                if(
$NewDate $date_to || $NewDate $date_from){

                }else{
                    
//echo $NewDate."(".$NewWeek."),";
                    
foreach($selected_week_array as $key => $targeweek){
                        
//echo $targeweek;

                        
if($NewWeek_num == $targeweek && $NewDate <= $date_to){

                        
?>

                            <tr>
                                <td>
                                    <input type="checkbox" name="arraynum[]" value='<?=$countrow?>' class="checkall2"/>

                                </td>

                                <td>
                                    <?//=$NewDate?>
                                    <div class="controls" style="padding: 0;margin: 0;" >
                                        <div class="input-append date-picker">
                                            <input type="text" id="date_<?=$countrow?>" name="selected_day[]" value="<?= h(Util::value_to_date_string($NewDate)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach($holiday as $holiday_date) if($holiday_date["holiday_date"] == $NewDate || $NewWeek == "Sun") echo "style='color: #FA5858;'"?>/>

                                    <span class="add-on">
                                        <i data-time-icon="icon-time" data-date-icon="icon-calendar" ></i>
                                    </span>

                                        </div>
                                    </div>

                                </td>

                                <td>
                                    <div id="week_<?=$countrow?>" >
                                        <?=$NewWeek?>
                                    </div>
                                </td>

                                <td>
                                    <?php $attribute 'start_time1'$label 'Start Time'?>

                                    <div class="controls" style="padding: 0;margin: 0;">
                                        <div class="input-append time-picker">
                                            <input type="text" id="<?=$attribute?>" name="<?=$attribute?>[]" value="<?=$start_time_array[$key]?>" class="time" data-format="hh:mm" placeholder="<?=$label?>"<?=$allow_edit_mode '' ' disabled="disabled"'?> />
                                            <?php if ($allow_edit_mode): ?>
                                                <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </td>

                                <td>
                                    <?php $attribute 'end_time1'$label 'End Time'?>

                                    <div class="controls" style="padding: 0;margin: 0;">
                                        <div class="input-append time-picker">
                                            <input type="text" id="<?=$attribute?>" name="<?=$attribute?>[]" value="<?=$end_time_array[$key]?>" class="time" data-format="hh:mm" placeholder="<?=$label?>"<?=$allow_edit_mode '' ' disabled="disabled"'?> />
                                            <?php if ($allow_edit_mode): ?>
                                                <span class="add-on">
                            <i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
                        </span>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </td>

                            </tr>
                            <?php
                            $countrow
++;
                        }
                    }
                }
            }

        }

        echo 
"<input type=\"hidden\" id=\"totalloop3\" value='".$countrow."' />";
    }else{}
    
?>



<?php
    $_SESSION
['period'] = $period;
    
$_SESSION['customer_id'] = (int)$_GET["customer_id"];

?>