/var/www/onesupportdemo.onesolution.hk/contract/views/generate_task_period.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
<?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;
            }
        }
    }

    
$sql5 "select * from sup_task_category where deleted = 0 order by sort 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();

    
$period      $_GET["period"];
    
$frequency      $_GET["frequency"];
    
$date_from $_GET["date_from"];
    
$date_to   $_GET["date_to"];

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


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

    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++) {

            
$NewDate     Date('Y-m-d'strtotime($date_from "+" $frequency $i " week"));
            
$NewWeek     date("D"strtotime($NewDate));
            
$NewWeek_num date("N"strtotime($NewDate));

            
//echo $NewDate."(".$NewWeek."),";

            //echo $targeweek;

            
if ($NewDate <= $date_to) { //this week equal to the user selected week, that is the target
                
$task_start_date $NewDate;
                
$task_end_date   Date('Y-m-d'strtotime($date_from "+" . ($frequency * ($i 1)) . " week - 1 days"));
                
?>
                <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="start_date_<?= $countrow ?>" name="start_date_<?= $countrow ?>" value="<?= h(Util::value_to_date_string($task_start_date)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach ($holiday as $holiday_date) if ($holiday_date["holiday_date"] == $task_start_date || $task_start_date == "Sun") echo "style='color: #FA5858;'" ?>/>



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

                            </div>

                            <div class="input-append date-picker">
                                <input type="text" id="end_date_<?= $countrow ?>" name="end_date_<?= $countrow ?>" value="<?= h(Util::value_to_date_string($task_end_date)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach ($holiday as $holiday_date) if ($holiday_date["holiday_date"] == $task_end_date || $task_end_date == "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>



                </tr>
                <?php
                $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
            
$NewDate     Date('Y-m-d'strtotime($date_from "+" $frequency $i " month"));
            
$NewWeek     date("D"strtotime($NewDate));
            
$NewWeek_num date("N"strtotime($NewDate));

            
//echo $NewDate."(".$NewWeek."),";

            //echo $targeweek;

            
if ($NewDate <= $date_to) { //this week equal to the user selected week, that is the target
                
$task_start_date $NewDate;
                
$task_end_date   Date('Y-m-d'strtotime($date_from "+" . ($frequency * ($i 1)) . " month - 1 days"));
                
?>
                <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="start_date_<?= $countrow ?>" name="start_date_<?= $countrow ?>" value="<?= h(Util::value_to_date_string($task_start_date)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach ($holiday as $holiday_date) if ($holiday_date["holiday_date"] == $task_start_date || $task_start_date == "Sun") echo "style='color: #FA5858;'" ?>/>



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

                            </div>

                            <div class="input-append date-picker">
                                <input type="text" id="end_date_<?= $countrow ?>" name="end_date_<?= $countrow ?>" value="<?= h(Util::value_to_date_string($task_end_date)) ?>" class="dateISO" data-format="yyyy-MM-dd" placeholder="Date" <?php foreach ($holiday as $holiday_date) if ($holiday_date["holiday_date"] == $task_end_date || $task_end_date == "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>



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


        }


    }else{}

    echo 
"<input type='hidden' id='totalloop3' value='".$countrow."' name='num_task_period' />";
?>



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

?>