/var/www/(Del)eizo.hkosl.com/global/webadmin/import_serial_number_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
<?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 "serial_number_".$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_serial_number_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="1000" 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="800" align="left" valign="top">

            <form action="import_serial_number_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 Serial Number
                    </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="6">
                                        <div style="width: 20px; height: 20px;background: #99D9EA;display: inline-block;">&nbsp;&nbsp;</div> :New Data
                                        <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'>Serial Number</th>
                                    <th class='content' style="background-color: #d3d3d3;width: 260px;">Checking</th>
                                </tr>

                                <?php
                                    
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 3// set column
                                    //echo "==".$highestRow."<br />";
                                    // 一次讀取一列
                                    
for ($excel_row 2$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){

                                                if(
$excel_column == 3){
                                                    
$file_serial_number $val;
                                                }


                                                
//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.region = ? and model.region = ? 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$file_region$file_region,"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){//make sure the series and model exist

                                                    
$sql "select * from serial_number where series_code=? and model_code=? and serial_number =? and region = ? and deleted=?";
                                                    if (!(
$sth $dbh->prepare($sql))) {
                                                        throw new 
Exception('[' $sth->errorCode() . ']: ' print_r($sth->errorInfo()));
                                                    }

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

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

                                                    if(
$sth->rowCount()>0){
                                                        echo 
"<td class='content'>".$file_serial_number."</td>";
                                                        echo 
"<td class='content' style='background-color: #d3d3d3;'>Exist (No Action)</td>";
                                                    }else{
                                                        echo 
"<td class='content' style='background-color: #99D9EA;'>".$file_serial_number."</td>";
                                                        echo 
"<td class='content' style='background-color: #99D9EA;'>Valid: Insert</td>";
                                                    }


                                                }else{
                                                    echo 
"<td class='content'>".$file_serial_number."</td>";
                                                    echo 
"<td class='content import_product_data_error' >Invalid: Region ,Series and Model do not match<br>".$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>