function readXML($file, $table, $table_id) { if (!file_exists($file)) { $arr = array('result' => false, 'message' => 'File does not exist'); echo json_encode($arr); return false; } $model = new modelManager(); $i = 0; $j = 0; $str = ''; $xml = simplexml_load_file($file); foreach ($xml->Worksheet->Table->Row as $row) { $name = $model->_changeDauNhay($row->Cell[0]->Data); $email = $model->_checkEmail($row->Cell[1]->Data); $phone = ''; if (isset($row->Cell[2]->Data)) { $phone = $model->_changeDauNhay($row->Cell[2]->Data); } $address = ''; if (isset($row->Cell[3]->Data)) { $address = $model->_changeDauNhay($row->Cell[3]->Data); } $city = ''; if (isset($row->Cell[4]->Data)) { $city = $model->_changeDauNhay($row->Cell[4]->Data); } $country = ''; if (isset($row->Cell[5]->Data)) { $country = $model->_changeDauNhay($row->Cell[5]->Data); } $birthday = ''; if (isset($row->Cell[6]->Data)) { $birthday = $model->_changeDauNhay($row->Cell[6]->Data); } $company = ''; if (isset($row->Cell[7]->Data)) { $company = $model->_changeDauNhay($row->Cell[7]->Data); } if ($birthday != '') { $birthday = strtotime($birthday); } $arr = array('select' => '`id`', 'from' => '`mn_customer`', 'where' => "`email`='{$email}'", 'limit' => 1); $data = $model->_select($arr); $total = count($data); if ($name != '' && $email != false && $total == 0) { $i++; $customer_id = $model->_insertCustomer($name, $phone, $email, $address, $city, $country, $birthday, $company); if ($table == 'mn_contract') { $model->_insertContractCustomer($table_id, $customer_id); } else { if ($table == 'mn_class') { $model->_insertClassCustomer($table_id, $customer_id); } } } else { if ($name != '' && $email != false && $total == 1) { $row = $data[0]; $customer_id = $row['id']; if ($table == 'mn_contract') { $arr = array('select' => '`id`', 'from' => '`mn_contract_customer`', 'where' => "`contract_id`='{$table_id}' AND `customer_id`='{$customer_id}'", 'limit' => 1); $data = $model->_select($arr); if (count($data) == 0) { $i++; $model->_insertContractCustomer($table_id, $customer_id); } } else { if ($table == 'mn_class') { $arr = array('select' => '`id`', 'from' => '`mn_class_info`', 'where' => "`class_id`='{$table_id}' AND `_table`='mn_customer' AND `table_id`='{$customer_id}'", 'limit' => 1); $data = $model->_select($arr); if (count($data) == 0) { $i++; $model->_insertClassCustomer($table_id, $customer_id); } } } } else { if ($name == '' || $email == false) { $j++; $str .= "{$j}.{$name} - {$email} - {$phone} <span class='error'>kiểm tra data</span><br />"; } } } } //end for }