/var/www/(Del)eizo.hkosl.com/global/webadmin/import_product_data_preview.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
<?php
    
include 'config.php';
    
// Check if the user is logged in
    
if ((!isSet($_SESSION['loginname'])) || ($loggin <> '1')) {
        
header("Location: login.php");
        exit;
    }


    
$excel_mimetypes = array(
        
"application/vnd.ms-excel",
        
"application/vnd.ms-excel.addin.macroEnabled.12",
        
"application/vnd.ms-excel.sheet.binary.macroEnabled.12",
        
"application/vnd.ms-excel.sheet.macroEnabled.12",
        
"application/vnd.ms-excel.template.macroEnabled.12",
        
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    
);


    if (
in_array($_FILES['excelfile']['type'], $excel_mimetypes)) {
        
// possible excel file
        // copy the file and save it to service
        
$uplodetime date("Y-m-d_H-i-s");
        
$tmp_file_name $_FILES["excelfile"]["tmp_name"];
        
$file_name $_FILES["excelfile"]["name"];

        
preg_match("/\.([^\.]+)$/"$file_name$file_ext);
        
$file_name "product_data_".$uplodetime.".".$file_ext[1]; // default length 8

        
move_uploaded_file($tmp_file_name"excel_file/$file_name");


    }else{
        echo 
"<script>alert('The file type is not a excel file type. Please upload the excel file!'); window.location.href='import_product_data_index.php';</script>";
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>Content Management System (CMS) - Powered by One Solution Limited</title>
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <!-- Main Menu -->
    <link rel="stylesheet" type="text/css" href="css/menu.css"/>
    <script type="text/javascript" src="js/jquery-1.10.1.min.js"></script>
    <script type="text/javascript" src="js/jquery-migrate-1.2.1.min.js"></script>
    <script type="text/javascript" src="js/ddaccordion.js"></script>
    <script type="text/javascript" src="js/menuddaccordion.js"></script>
    <!-- End Main Menu -->
</head>

<body>

<table width="1300" height="600" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="200" align="left" valign="top">
            <table width="200" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td height="70" align="left" valign="middle">&nbsp;</td>
                </tr>
                <tr>
                    <td width="200" align="left" valign="top"><!-- Main Menu -->
                        <?php require("menu.php");?><!-- End Main Menu --></td>
                </tr>
            </table>
        </td>
        <td width="1100" align="left" valign="top">

            <form action="import_product_data_post.php" method="post" name="modifyform" enctype="multipart/form-data">
                <input type="hidden" name="excelfile_name" value="<?=$file_name?>"/>
                <table width="100%" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td height="70" align="right" valign="middle" class="icontxt">
                            <table border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td width="50" align="center">
                                        <a href="#" onClick="modifyform.submit()"><img src="images/iconSave.png" alt="Save" width="32" height="32" border="0"><br>
                                            &nbsp;Save&nbsp;&nbsp;</a></td>
                                    <td width="50" align="center">
                                        <a href="import_product_data_index.php"><img src="images/iconCancel.png" alt="Cancel" width="32" height="32" border="0"><br>
                                            &nbsp;Back&nbsp;&nbsp;</a></td>
                                    <td>&nbsp;</td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                <span style="float:left;" class="pagetitletxt">&nbsp;&nbsp;<b><img src="images/iconList.jpg" width="48" height="48" align="absmiddle"/>
                        Preview Import Product Data
                        </b></span>
                        </td>
                    </tr>
                    <tr>
                        <td height="25" align="left" valign="middle" class="msg"></td>
                    </tr>
                    <tr>
                        <td align="left" valign="middle"><!-- Content -->
                            <table width="100%" border="1" cellpadding="5" cellspacing="0">
                            <tr>
                                <td colspan="15">
                                    <div style="width: 20px; height: 20px;background: yellow;display: inline-block;">&nbsp;&nbsp;</div> : Data has changed
                                    <div style="width: 20px; height: 20px;background: #F78181;display: inline-block;">&nbsp;&nbsp;</div> : Data has error
                                </td>
                            </tr>

                                <tr>
                                    <th class='content'>Region</th>
                                    <th class='content'>Series</th>
                                    <th class='content'>Model</th>
                                    <th class='content'>Free On-site Calibration</th>
                                    <th class='content'>Fixed Warranty Year</th>
                                    <th class='content'>Extend Warranty Year</th>
                                    <th class='content'>Promote Date From</th>
                                    <th class='content'>Promote Date To</th>
                                    <th class='content'>Warranty Detail(SC)</th>
                                    <th class='content'>Warranty Detail(TC)</th>
                                    <th class='content'>Warranty Detail(EN)</th>
                                    <th class='content'>Warranty Detail-Extend(SC)</th>
                                    <th class='content'>Warranty Detail-Extend(TC)</th>
                                    <th class='content'>Warranty Detail-Extend(EN)</th>
                                    <th class='content' style="background-color: #d3d3d3;">Checking</th>
                                </tr>

                                <?php
                                    
function validateDate($date$format 'Y-m-d H:i:s')
                                    {
                                        
$d DateTime::createFromFormat($format$date);
                                        return 
$d && $d->format($format) == $date;
                                    }

                                    include 
'phpexcel/PHPExcel.php';
                                    include 
'phpexcel/PHPExcel/Writer/Excel2007.php';
                                    require_once 
'phpexcel/PHPExcel/IOFactory.php';

                                    
$reader PHPExcel_IOFactory::createReader('Excel2007'); // 讀取2007 excel 檔案
                                    
$PHPExcel $reader->load("excel_file/$file_name"); // 檔案名稱
                                    
$sheet $PHPExcel->getSheet(0); // 讀取第一個工作表(編號從 0 開始)
                                    //$highestRow = $sheet->getHighestRow(); // 取得總列數
                                    
$highestRow $sheet->getHighestDataRow(); // 取得總列數

                                    
$highestColumn 13// set column
                                    //echo "==".$highestRow."<br />";
                                    // 一次讀取一列
                                    
for ($excel_row 3$excel_row <= $highestRow$excel_row++) {
                                        echo 
"<tr>";
                                        
$error_msg "";
                                        for (
$excel_column 0$excel_column <= $highestColumn$excel_column++) {
                                            
$val $sheet->getCellByColumnAndRow($excel_column$excel_row)->getValue();
                                            
// $val . ',';

                                            
if($excel_column == 0){
                                                
$file_region $val;
                                                if(
$file_region == "CN" || $file_region == "HK"){
                                                    echo 
"<td class='content'>".$val."</td>";
                                                }else{
                                                    echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                    
$error_msg .= "Region: Only HK or CN allowed, ";
                                                }

                                            }

                                            if(
$excel_column == 1){
                                                
$file_series_code $val;
                                                echo 
"<td class='content'>".$val."</td>";
                                            }

                                            if(
$excel_column == 2){
                                                
$file_model_code $val;
                                                echo 
"<td class='content'>".$val."</td>";
                                            }

                                            if(
$excel_column 2){
                                                
//checking the change and highlight it
                                                //$sql = "select * from series series, model model where model.series_id = series.series_id and series.series_code = ? and model.model_code = ? and series.status =? and series.deleted = ? and model.status = ? and model.deleted=? group by model.model_id ";
                                                
$sql "select * from series series, model model where model.series_id = series.series_id and series.series_code = ? and model.model_code = ? and series.deleted=? and model.deleted=? group by model.model_id ";
                                                if (!(
$sth $dbh->prepare($sql))) {
                                                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                                                }

                                                
//$parameter = array($file_series_code,$file_model_code, "1", "0", "1", "0" );
                                                
$parameter = array($file_series_code,$file_model_code,"0""0" );
                                                if (!
$sth->execute($parameter)) {
                                                    throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                                                }

                                                
$row $sth->fetch(PDO::FETCH_ASSOC);

                                                if(
$sth->rowCount() > 0){ //updated record
                                                    
$action "Update";
                                                    if(
$excel_column == 3){//free_mix_color
                                                        //$file_free_mix_color = $val;
                                                        
if($val == "Yes" || $val == "N/A"){
                                                            if(
$val == "Yes"){
                                                                
$file_free_mix_color 1;
                                                            }else if(
$val == "N/A"){
                                                                
$file_free_mix_color 0;
                                                            }

                                                            if(
$row{"free_mix_color"} == $file_free_mix_color){
                                                                echo 
"<td class='content'>".$val."</td>";
                                                            }else{
                                                                echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                            }


                                                        }else{
                                                            echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                            
$error_msg .= "Free Mix Color: Only N/A or Yes allowed, ";
                                                        }



                                                    }else if(
$excel_column == 4){//fixed_warranty_year
                                                        
if(is_numeric($val) && (int)$val == $val){
                                                            if(
$row{"fixed_warranty_year"} == $val){
                                                                echo 
"<td class='content'>".$val."</td>";
                                                            }else{
                                                                echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                            }
                                                        }else{
                                                            echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                            
$error_msg .= "Fixed Warranty Year: Only Decimal Number allowed, ";
                                                        }

                                                    }else if(
$excel_column == 5){//extend_warranty_year
                                                        
if(is_numeric($val) && (int)$val == $val){
                                                            if(
$row{"extend_warranty_year"} == $val){
                                                                echo 
"<td class='content'>".$val."</td>";
                                                            }else{
                                                                echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                            }
                                                        }else{
                                                            echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                            
$error_msg .= "Extend Warranty Year: Only Decimal Number allowed, ";
                                                        }


                                                    }else if(
$excel_column == 6){//promote datefrom
                                                        //$file_promote_datefrom = $val;
                                                        
$file_promote_datefrom PHPExcel_Style_NumberFormat::toFormattedString($val"YYYY-MM-DD");
                                                        if (
$row{"promote_datefrom"} == $file_promote_datefrom || empty($file_promote_datefrom)) {
                                                            echo 
"<td class='content'>" $file_promote_datefrom "</td>";
                                                        } else {
                                                            if (!
validateDate($file_promote_datefrom'Y-m-d')) {
                                                                echo 
"<td class='content import_product_data_error'>" $file_promote_datefrom "</td>";
                                                                
$valid_row 0;
                                                                
$error_msg .= "Promote Date From: Wrong date format, ";
                                                            } else {
                                                                echo 
"<td class='content import_product_data_changed'>" $file_promote_datefrom "</td>";
                                                            }
                                                        }
                                                    }else if(
$excel_column == 7){//promote dateto
                                                        
$file_promote_dateto PHPExcel_Style_NumberFormat::toFormattedString($val"YYYY-MM-DD");
                                                        if (
$row{"promote_dateto"} == $file_promote_dateto || empty($file_promote_dateto)) {
                                                            echo 
"<td class='content'>" $file_promote_dateto "</td>";
                                                        } else {
                                                            if (!
validateDate($file_promote_dateto'Y-m-d')) {
                                                                echo 
"<td class='content import_product_data_error'>" $file_promote_dateto "</td>";
                                                                
$valid_row 0;
                                                                
$error_msg .= "Promote Date From: Wrong date format, ";
                                                            } else {
                                                                echo 
"<td class='content import_product_data_changed'>" $file_promote_dateto "</td>";
                                                            }
                                                        }
                                                    }else if(
$excel_column == 8){//warranty_detail_sc
                                                        
if($row{"warranty_detail_sc"} == $val){
                                                            echo 
"<td class='content'>".$val."</td>";
                                                        }else{
                                                            echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                        }
                                                    }else if(
$excel_column == 9){//warranty_detail_tc
                                                        
if($row{"warranty_detail_tc"} == $val){
                                                            echo 
"<td class='content'>".$val."</td>";
                                                        }else{
                                                            echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                        }
                                                    }else if(
$excel_column == 10){//warranty_detail_en
                                                        
if($row{"warranty_detail_en"} == $val){
                                                            echo 
"<td class='content'>".$val."</td>";
                                                        }else{
                                                            echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                        }
                                                    }else if(
$excel_column == 11){//warranty_detail_en
                                                        
if($row{"warranty_detail_extend_sc"} == $val){
                                                            echo 
"<td class='content'>".$val."</td>";
                                                        }else{
                                                            echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                        }
                                                    }else if(
$excel_column == 12){//warranty_detail_en
                                                        
if($row{"warranty_detail_extend_tc"} == $val){
                                                            echo 
"<td class='content'>".$val."</td>";
                                                        }else{
                                                            echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                        }
                                                    }else if(
$excel_column == 13){//warranty_detail_en
                                                        
if($row{"warranty_detail_extend_en"} == $val){
                                                            echo 
"<td class='content'>".$val."</td>";
                                                        }else{
                                                            echo 
"<td class='content import_product_data_changed'>".$val."</td>";
                                                        }
                                                    }else{}


                                                }else{ 
//new record

                                                    
$action "Insert";
                                                    if(
$excel_column == 3){//free_mix_color
                                                        //$file_free_mix_color = $val;
                                                        
if($val == "Yes" || $val == "N/A"){
                                                            if(
$val == "Yes"){
                                                                
$file_free_mix_color 1;
                                                            }else if(
$val == "N/A"){
                                                                
$file_free_mix_color 0;
                                                            }

                                                                echo 
"<td class='content'>".$val."</td>";

                                                        }else{
                                                            echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                            
$error_msg .= "Free On-site Calibration: Only N/A or Yes allowed, ";
                                                        }



                                                    }else if(
$excel_column == 4){//fixed_warranty_year
                                                        
if(is_numeric($val)){

                                                                echo 
"<td class='content'>".$val."</td>";

                                                        }else{
                                                            echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                            
$error_msg .= "Fixed Warranty Year: Only Number allowed, ";
                                                        }

                                                    }else if(
$excel_column == 5){//extend_warranty_year

                                                        
if(is_numeric($val)){

                                                                echo 
"<td class='content'>".$val."</td>";

                                                        }else{
                                                            echo 
"<td class='content import_product_data_error'>".$val."</td>";
                                                            
$error_msg .= "Extend Warranty Year: Only Number allowed, ";
                                                        }
                                                    }

                                                    if(
$excel_column 5){
                                                        echo 
"<td class='content'>".$val."</td>";
                                                    }
                                                }

                                            }
                                        }

                                        
//show the checking result
                                        
if(empty($error_msg)){
                                            
$valid "Valid";
                                            echo 
"<td class='content' style='width:60px;background-color: #d3d3d3;'>".$valid.": ".$action."</td>";
                                        }else{
                                            
$valid "Invalid";
                                            echo 
"<td class='content' style='width:100px;background-color: #FA5858;'>".$valid.": ".$error_msg."</td>";
                                        }

                                        echo 
"</tr>";
                                    }
                                
?>


                            </table>
                            <!-- End Content --></td>
                    </tr>
                    <tr>
                        <td align="left" valign="middle">&nbsp;</td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
</table>
</body>
</html>