| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/(Del)gepgroup.hk/webadmin/ |
Upload File : |
<?php
//include 'config.php';
require_once("configure.php");
// Check if the user is logged in
require_once( realpath(dirname(__FILE__)) . '/../common/config.php');
require_once( realpath(dirname(__FILE__)) . '/function_is_login.php');
if (!is_login())
{
header("Location: index.php");
exit;
}
// check file extension
$file_name = $_FILES['clientdatafile']['name'];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
if (strtolower($file_ext) != 'csv')
{
header("Location: upload_clientdataform.php?msg=Not a csv file");
exit;
}
function fgetcsv_utf8(&$handle, $length = null, $d = ",", $e = '"') {
$d = preg_quote($d);
$e = preg_quote($e);
$_line = "";
$eof=false;
while ($eof != true) {
$_line .= (empty ($length) ? fgets($handle) : fgets($handle, $length));
$itemcnt = preg_match_all('/' . $e . '/', $_line, $dummy);
if ($itemcnt % 2 == 0)
$eof = true;
}
$_csv_line = preg_replace('/(?: |[ ])?$/', $d, trim($_line));
$_csv_pattern = '/(' . $e . '[^' . $e . ']*(?:' . $e . $e . '[^' . $e . ']*)*' . $e . '|[^' . $d . ']*)' . $d . '/';
preg_match_all($_csv_pattern, $_csv_line, $_csv_matches);
$_csv_data = $_csv_matches[1];
for ($_csv_i = 0; $_csv_i < count($_csv_data); $_csv_i++) {
$_csv_data[$_csv_i] = preg_replace("/^" . $e . "(.*)" . $e . "$/s", "$1", $_csv_data[$_csv_i]);
$_csv_data[$_csv_i] = str_replace($e . $e, $e, $_csv_data[$_csv_i]);
}
return empty ($_line) ? false : $_csv_data;
}
if (strlen($_FILES['clientdatafile']['name']))
{
if (($handle = fopen($_FILES['clientdatafile']['tmp_name'], "r")) !== false)
{
$lineNumber = 0;
while (($data = fgetcsv_utf8($handle, 1000, ",")) !== false)
{
$lineNumber++;
if ($lineNumber == 1)
{
// Filter UTF-8 BOM
$utf8bom = "\xEF\xBB\xBF";
if (strpos($data['0'], $utf8bom) === 0)
$data['0'] = substr($data['0'], strlen($utf8bom));
}
$i = 0;
$customer_no = mysql_real_escape_string($data[strval($i++)]);
$login = $customer_no;
$company = mysql_real_escape_string($data[strval($i++)]);
$address = mysql_real_escape_string($data[strval($i++)]);
$contact_person = mysql_real_escape_string($data[strval($i++)]);
$telValue = $data[strval($i++)];
$tel = mysql_real_escape_string($telValue);
$fax = mysql_real_escape_string($data[strval($i++)]);
$email = mysql_real_escape_string($data[strval($i++)]);
$pwValue = $data[strval($i++)];
// $status = mysql_real_escape_string($data[strval($i++)]);
$status = '1';
if (!empty($pwValue))
$pw = md5($pwValue); // override tel password if length > 0
else
$pw = md5($telValue); // tel
$cmsloginid = mysql_real_escape_string($_SESSION['cmsloginid']);
if($customer_no)
{
if ($lineNumber == 1)
{
// // Delete all
// $sql = "DELETE FROM clients";
// if (!mysql_query($sql)) {
// fclose($handle);
// echo 'Import Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
// exit;
// }
// // Reset auto increment
// $sql = "ALTER TABLE clients AUTO_INCREMENT = 1";
// if (!mysql_query($sql)) {
// fclose($handle);
// echo 'Import Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
// exit;
// }
// Update all
$sql = "UPDATE clients SET cstatus = '0' WHERE cstatus = '1'";
if (!mysql_query($sql)) {
fclose($handle);
echo 'Import Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
exit;
}
}
$pwSql = !empty($pwValue) ? "cpw = '$pw', " : "";
$sql = "
update clients set ccompany = '$company', caddress = '$address', ccontactp = '$contact_person', ctel = '$tel', cfax = '$fax', cmail = '$email',
$pwSql
cstatus = '$status', modifyday = NOW(), cmsloginid = '$cmsloginid'
where cno = '$customer_no'
limit 1
";
if(!mysql_query($sql))
{
fclose($handle);
echo 'Import Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
exit;
}
if (mysql_affected_rows() === 0)
{
$sql = "
insert into clients (cno, ccompany, caddress, ccontactp, ctel, cfax, cmail, clogin, cpw, cstatus, creationday, modifyday, cmsloginid) value
('$customer_no', '$company', '$address', '$contact_person', '$tel', '$fax', '$email', '$login', '$pw', '$status', NOW(), NOW(), '$cmsloginid')
";
if(!mysql_query($sql))
{
fclose($handle);
echo 'Import Error:<br />'. mysql_error() .'<br />SQL: '. $sql;
exit;
}
}
}
}
fclose($handle);
}
}
header("Location: upload_clientdataform.php?msg=Modify Successful");