'.__('You don\'t have enough privileges to access this area!').'');
}
// max chars in line for file operations
$max_chars = 4096;
if (isset($_POST['doImport'])) {
// check for form validity
if (!$_FILES['importFile']['name']) {
utility::jsAlert(__('Please select the file to import!'));
exit();
} else if (empty($_POST['fieldSep']) OR empty($_POST['fieldEnc'])) {
utility::jsAlert(__('Required fields (*) must be filled correctly!'));
exit();
} else {
// set PHP time limit
set_time_limit(7200);
// set ob implicit flush
ob_implicit_flush();
// create upload object
$upload = new simbio_file_upload();
// get system temporary directory location
$temp_dir = sys_get_temp_dir();
// set max size
$max_size = $sysconf['max_upload']*1024;
$upload->setAllowableFormat(array('.csv'));
$upload->setMaxSize($max_size);
$upload->setUploadDir($temp_dir);
$upload_status = $upload->doUpload('importFile');
if ($upload_status != UPLOAD_SUCCESS) {
utility::jsAlert(__('Upload failed! File type not allowed or the size is more than').' '.($sysconf['max_upload']/1024).' MB'); //mfc
exit();
}
// uploaded file path
$uploaded_file = $temp_dir.DS.$_FILES['importFile']['name'];
$row_count = 0;
// check for import setting
$record_num = intval($_POST['recordNum']);
$field_enc = trim($_POST['fieldEnc']);
$field_sep = trim($_POST['fieldSep']);
$record_offset = intval($_POST['recordOffset']);
$record_offset = $record_offset-1;
// get current datetime
$curr_datetime = date('Y-m-d H:i:s');
$curr_datetime = '\''.$curr_datetime.'\'';
// foreign key id cache
$mtype_id_cache = array();
// read file line by line
$inserted_row = 0;
$file = fopen($uploaded_file, 'r');
while (!feof($file)) {
// record count
if ($record_num > 0 AND $row_count == $record_num) {
break;
}
// go to offset
if ($row_count < $record_offset) {
// pass and continue to next loop
$row = fgets($file, $max_chars);
$row_count++;
continue;
} else {
// get an array of field
$field = fgetcsv($file, $max_chars, $field_sep, $field_enc);
if ($field) {
// strip escape chars from all fields
foreach ($field as $idx => $value) {
$field[$idx] = str_replace('\\', '', trim($value));
$field[$idx] = $dbs->escape_string($field[$idx]);
}
// strip leading field encloser if any
$member_id = preg_replace('@^\\\s*'.$field_enc.'@i', '', $field[0]);
$member_id = '\''.$member_id.'\'';
$member_name = '\''.$field[1].'\'';
$gender = ( ! empty($field[2])) ? $field[2] : 0; // patched by Indra Sutriadi
$member_type_id = utility::getID($dbs, 'mst_member_type', 'member_type_id', 'member_type_name', $field[3], $mtype_id_cache);
$member_email = $field[4]?'\''.$field[4].'\'':'NULL';
$member_address = $field[5]?'\''.$field[5].'\'':'NULL';
$postal_code = $field[6]?'\''.$field[6].'\'':'NULL';
$inst_name = $field[7]?'\''.$field[7].'\'':'NULL';
$is_new = $field[8]?$field[8]:'0';
$member_image = $field[9]?'\''.$field[9].'\'':'NULL';
$pin = $field[10]?'\''.$field[10].'\'':'NULL';
$member_phone = $field[11]?'\''.$field[11].'\'':'NULL';
$member_fax = $field[12]?'\''.$field[12].'\'':'NULL';
$member_since_date = '\''.$field[13].'\'';
$register_date = '\''.$field[14].'\'';
$expire_date = '\''.$field[15].'\'';
$birth_date = $field[16]?'\''.$field[16].'\'':'NULL';
$member_notes = preg_replace('@\\\s*'.$field_enc.'$@i', '', $field[17]);
$member_notes = $member_notes?'\''.$member_notes.'\'':'NULL';
// sql insert string
$sql_str = "INSERT IGNORE INTO member
(member_id, member_name, gender,
member_type_id, member_email, member_address, postal_code,
inst_name, is_new, member_image, pin, member_phone,
member_fax, member_since_date, register_date,
expire_date, birth_date, member_notes,
input_date, last_update)
VALUES ($member_id, $member_name, $gender,
$member_type_id, $member_email, $member_address, $postal_code,
$inst_name, $is_new,
$member_image, $pin, $member_phone,
$member_fax, $member_since_date, $register_date,
$expire_date, $birth_date, $member_notes,
$curr_datetime, $curr_datetime)";
// send query
@$dbs->query($sql_str);
if (!$dbs->error) {
$inserted_row++;
} else {
echo $sql_str.'
';
echo $dbs->error.'