| Server IP : 104.21.21.239 / Your IP : 216.73.216.11 Web Server : Apache/2.4.68 (Amazon Linux) OpenSSL/3.5.5 System : Linux ip-172-31-69-123.ec2.internal 6.1.176-223.369.amzn2023.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jul 24 13:34:27 UTC 2026 x86_64 User : ec2-user ( 1000) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/hotel-dev/public_html/mod/ |
Upload File : |
<?php include('_mod_security.php'); ?>
<?php
//var_dump($_POST);
//var_dump($_GET);
$err_flag = false;
$validate_function = '';
if ($_POST['submitted'] == 1) :
//var_dump($_FILES);
if (!empty($_FILES['import_file']['name'])) :
$uploaddir = APP_UPLOAD_DIR.'/hoteldb/data_import/'.date('Y_m_d_H_i_s');
if (!is_dir($uploaddir)) :
//echo 'trying to make directory';
mkdir($uploaddir, 0777, true);
endif;
$uploadfile = $uploaddir.'/'.date("Ymd_His").'_'.basename($_FILES['import_file']['name']);
if (move_uploaded_file($_FILES['import_file']['tmp_name'], $uploadfile)) :
//echo 'File upload successful!';
require_once dirname(__FILE__) . '/../vendor_classes/PHPExcel/IOFactory.php';
if (strtoupper(substr(\PhpOffice\PhpSpreadsheet\IOFactory::identify($uploadfile),0,5)) == 'EXCEL') :
$objPHPExcel = \PhpOffice\PhpSpreadsheet\IOFactory::load($uploadfile);
$import_sheet_data = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
//var_dump($import_sheet_data);
if (count($import_sheet_data) <= 1 && count($import_sheet_data[1]) <= 1) :
$err_flag = true;
$form_message = "File does not appear to contain valid import data! Please select a valid Excel file to import.";
else :
if ($_POST['first_row_field_names'] == '1') :
$r_start = 2;
else :
$r_start = 1;
endif;
for ($r = $r_start; $r <= count($import_sheet_data); $r++) :
$status = '';
//*********** Check hotel **********
$sql = "SELECT hotel_id FROM hotels WHERE hotel_name = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['A'])))." ";
$result_hotel = $db->query($sql) or die('Database Error!');
if ($result_hotel->rowCount() > 0) :
if ($result_hotel->rowCount() == 1) :
$row_hotel = $result_hotel->fetch(PDO::FETCH_OBJ);
//******* Check contact ********
if (!empty(trim(strip_tags($import_sheet_data[$r]['D']))) && !empty(trim(strip_tags($import_sheet_data[$r]['E'])))) :
$sql = "SELECT * FROM contacts WHERE hotel_id = ".nz($row_hotel->hotel_id, '0')." ".
"AND first_name = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['D'])))." ".
"AND last_name = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['E'])))." ".
"AND title = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['C'])))." ";
$result_contact = $db->query($sql) or die('Database Error!');
$set = "hotel_id = ".nz($row_hotel->hotel_id, '0').", ".
"title = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['C']))).", ".
"first_name = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['D']))).", ".
"last_name = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['E']))).", ".
"email = ".$db->quote(trim(strip_tags($import_sheet_data[$r]['F']))).", ".
sql_set_update();
if ($result_contact->rowCount() == 0) : //****** new contact - add ******
$sql = "INSERT INTO contacts SET ".
sql_set_create().
$set;
try {
$db->query($sql);
} catch(PDOException $ex) {
die('Database Error! '.$ex->getMessage.' === '.$sql.' === ');
}
$status = 'Record added.';
elseif ($result_contact->rowCount() == 1) : //****** contact exists - update ******
$row_contact = $result_contact->fetch(PDO::FETCH_OBJ);
$sql = "UPDATE contacts SET ".$set.
"WHERE contact_id =".nz($row_contact->contact_id);
try {
$db->query($sql);
} catch(PDOException $ex) {
die('Database Error! '.$ex->getMessage.' === '.$sql.' === ');
}
$last_id = $db->lastInsertId();
$status = 'Record updated.';
else :
$status = '*** ERROR: Multiple contacts with the same name found for hotel! ***';
endif;
else :
$status = '*** ERROR: First and/or Last name missing! ***';
endif;
else :
$status = '*** ERROR: Duplicate hotels with the same name found! ***';
endif;
else :
$status = '*** ERROR: Hotel not found! ***';
endif;
echo '<p>';
echo 'Hotel: '.trim(strip_tags($import_sheet_data[$r]['A'])).' ';
echo 'Title: '.trim(strip_tags($import_sheet_data[$r]['C'])).' ';
echo 'First Name: '.trim(strip_tags($import_sheet_data[$r]['D'])).' ';
echo 'Last Name: '.trim(strip_tags($import_sheet_data[$r]['E'])).' ';
echo 'Email: '.trim(strip_tags($import_sheet_data[$r]['F'])).' ';
echo 'Status: '.$status;
echo '</p>';
endfor;
endif;
else :
$err_flag = true;
$form_message = "File is invalid! Please select a valid Excel<sup>®</sup> file to import.";
endif;
else :
$err_flag = true;
$form_message = "File upload failed! Please select a valid Excel<sup>®</sup> file to import.";
endif;
else :
$err_flag = true;
$form_message = "Please specify import file.";
endif;
endif;
?>
<script>
var active_tab = '';
$(document).ready(function()
{
//switch_tab('<?php echo $active_tab; ?>');
$("#tab_content_general").show();
});
</script>
<h1>Data Load - Contacts</h1>
<?php echo form_message($form_message); ?>
<form name="frm_import" id="frm_import" method="post" action="" enctype="multipart/form-data" target="" >
<input name="submitted" type="hidden" value="1" />
<input name="active_tab" id="active_tab" type="hidden" value="general" />
<div class="cleardiv">
</div>
<div class="tab_content" id="tab_content_general" style="display:block; position:relative;">
<div class="form_header">
Import File Selection
</div>
Select Excel® file to import:
<input type="file" name="import_file" /><br /><br />
<input type="checkbox" name="first_row_field_names" value="1" /> First row contains field names
</div>
<!-- -------------------------------------------------------------------------------------------------------------- -->
<div class="form_strip">
<input type="submit" value="Submit" />
<input type="button" value="Cancel" onclick="window.location.href = 'index.php?IX=hotels';" />
</div>
</form>