<?php include('header.php');?>
<?php include('sidebar.php');?>
<?php 
require('library/php-excel-reader/excel_reader2.php');
require('library/SpreadsheetReader.php');
include('includes/class.usertype.php');
$usertype = new Usertype();
?>
<?php
$maintitle="Upload Data";
$page="uploadhotels.php";
$table="tbl_phase";
$field_id="phaseid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['content_id'];
 
?>
<?php
 
if(isset($_POST['Submit'])){ 
 $mimes = array('application/vnd.ms-excel','text/xls','text/xlsx','application/vnd.oasis.opendocument.spreadsheet','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
    if(in_array($_FILES["file"]["type"],$mimes))
    {
        $uploadFilePath = 'uploads/'.basename($_FILES['file']['name']);
        move_uploaded_file($_FILES['file']['tmp_name'], $uploadFilePath);
        $Reader = new SpreadsheetReader($uploadFilePath);
        $totalSheet = count($Reader->sheets());
         echo "You have total ".$totalSheet." sheets".

		/*$html="<table border='1'>";
        $html.="<tr><th>Title</th><th>Description</th></tr>";*/
        

		/* For Loop for all sheets */
        $k=1;
        for($i=0;$i<$totalSheet;$i++)
        {
            $Reader->ChangeSheet($i);
            foreach ($Reader as $Row)
            {
                if($k>0){
                $html.="<tr>";
                 $no = isset($Row[0]) ? $Row[0] : '';
                 $id = isset($Row[1]) ? $Row[1] : '';
                 $hotelname = isset($Row[2]) ? $Row[2] : '';
                 $status = isset($Row[3]) ? $Row[3] : '';
                 $statusid=$status;
                       /* $selectstatus=$helper->select("tbl_status","*",array("title"=>$status),array());
                        if(count($selectstatus)>0){
                             
                           $statusid=$selectstatus[0]['statusid'];
                        }
                        else {
                           $statusid=$helper->insertextradata("tbl_status", "title",$status) ;
                        }*/
                      $phases = isset($Row[4]) ? $Row[4] : '';
                        $selectphase=$helper->select("tbl_phase","*",array("title"=>$phases),array());                        
                        if(count($selectphase)>0){
                            $phasesid=$selectphase[0]['phaseid'];
                        }
                        else {
                            $phasesid=$helper->insertextradata("tbl_phase", "title",$phases) ;
                        }
                        $hoteltypegroup = isset($Row[5]) ? $Row[5] : '';
                         $hoteltype=$helper->select("tbl_hotel_type_group","*",array("title"=>$hoteltypegroup),array());
                        if(count($hoteltype)>0){
                            $hoteltypeid=$hoteltype[0]['hoteltypeid'];
                        }
                        else {
                            $hoteltypeid=$helper->insertextradata("tbl_hotel_type_group", "title",$hoteltypegroup) ;
                        }               
                 
                 /*$category = isset($Row[6]) ? $Row[6] : '';
                        $categorytype=$helper->select("tbl_category","*",array("title"=>$category),array());
                        $categoryid=$categorytype[0]['categoryid'];
                        if(count($categorytype)>0){
                            $categoryid=$categorytype[0]['categoryid'];
                        }
                        else {
                            $categoryid=$helper->insertextradata("tbl_category", "title",$category) ;
                        }  */ 
                $openingdate = isset($Row[6]) ? $Row[6] : '';
                 $stars = isset($Row[7]) ? $Row[7] : '';
                 $rooms = isset($Row[8]) ? $Row[8] : '';
                 $tbi = isset($Row[9]) ? $Row[9] : '';
                 $city = isset($Row[10]) ? $Row[10] : '';
                 $area = isset($Row[11]) ? $Row[11] : '';
                 $lastupdated = isset($Row[12]) ? $Row[12] : '';
                 $industrytype = isset($Row[13]) ? $Row[13] : '';
                 $latitude = isset($Row[14]) ? $Row[14] : '';
                 $longitude = isset($Row[15]) ? $Row[15] : '';
                 $landmark = isset($Row[16]) ? $Row[16] : '';
                 $plotno = isset($Row[17]) ? $Row[17] : '';
                 $note = isset($Row[18]) ? $Row[18] : '';
                 $scope1 = isset($Row[19]) ? $Row[19] : '';
                 $scope=$helper->escape_string($scope1);
                 $watchman = isset($Row[20]) ? $Row[20] : '';
                 $watchmanno = isset($Row[21]) ? $Row[21] : '';  
                 $group = isset($Row[54]) ? $Row[54] : '';
                  
                   $groupname=$helper->select("tbl_hotelgroups","*",array("groupname"=>$group),array());
                       
                        if(count($groupname)>0){
                             $groupid=$groupname[0]['groupid'];
                        }
                        else {
                            $groupid=$helper->insertextradata("tbl_hotelgroups", "groupname",$group) ;
                        }  
              $hotelid= $helper->inserhoteldata($id,$hotelname,$statusid,$phasesid,$hoteltypeid,$categoryid,$openingdate,$stars,$rooms,$tbi,$city,$groupid,$area,$lastupdated,$industrytype,$latitude,$longitude,$landmark,$plotno,$note,$scope,$watchman,$watchmanno);
               
               $developerowner = isset($Row[22]) ? $Row[22] : ''; 
               $developercompany = isset($Row[23]) ? $Row[23] : ''; 
               $developerphone = isset($Row[24]) ? $Row[24] : ''; 
               $developeraddress = isset($Row[25]) ? $Row[25] : ''; 
               $client_rep_name = isset($Row[26]) ? $Row[26] : ''; 
               $client_rep_phone = isset($Row[27]) ? $Row[27] : ''; 
               $client_rep_email = isset($Row[28]) ? $Row[28] : ''; 
               $client_rep_visit_time = isset($Row[29]) ? $Row[29] : ''; 
               $consultant_company = isset($Row[30]) ? $Row[30] : ''; 
               $consultant_address = isset($Row[31]) ? $Row[31] : ''; 
               $consultant_phone = isset($Row[32]) ? $Row[32] : ''; 
               $consultant_pm_name = isset($Row[33]) ? $Row[33] : '';
               $consultant_pm_phone = isset($Row[34]) ? $Row[34] : '';
               $consultant_pm_email = isset($Row[35]) ? $Row[35] : '';
               
               $contracting_company = isset($Row[36]) ? $Row[36] : ''; 
               $contracting_address = isset($Row[37]) ? $Row[37] : ''; 
               $contracting_phone = isset($Row[38]) ? $Row[38] : ''; 
               $contracting_pm_name = isset($Row[39]) ? $Row[39] : '';
               $contracting_pm_phone = isset($Row[40]) ? $Row[40] : '';
               $contracting_pm_email = isset($Row[41]) ? $Row[41] : '';             
              
               
               $interior_company = isset($Row[42]) ? $Row[42] : ''; 
               $interior_address = isset($Row[43]) ? $Row[43] : ''; 
               $interior_phone = isset($Row[44]) ? $Row[44] : ''; 
               $interior_pm_name = isset($Row[45]) ? $Row[45] : '';
               $interior_pm_phone = isset($Row[46]) ? $Row[46] : '';
               $interior_pm_email = isset($Row[50]) ? $Row[47] : '';
               
                $operator_company = isset($Row[48]) ? $Row[48] : ''; 
               $operator_address = isset($Row[49]) ? $Row[49] : ''; 
               $operator_phone = isset($Row[50]) ? $Row[50] : ''; 
               $operator_pm_name = isset($Row[51]) ? $Row[51] : '';
               $operator_pm_phone = isset($Row[52]) ? $Row[52] : '';
               $operator_pm_email = isset($Row[53]) ? $Row[53] : '';
               $clientposition = isset($Row[55]) ? $Row[55] : '';
               $companyid= $helper->inserhotelcompanies($hotelid,$id,$developerowner,$developercompany,$developerphone,$developeraddress,$client_rep_name,$client_rep_phone,$client_rep_email,$client_rep_visit_time,$consultant_company,$consultant_address,$consultant_phone,$consultant_pm_name,$consultant_pm_phone,$consultant_pm_email,$contracting_company,$contracting_address,$contracting_phone,$contracting_pm_name,$contracting_pm_phone,$contracting_pm_email,$interior_company,$interior_address,$interior_phone,$interior_pm_name,$interior_pm_phone,$interior_pm_email,$operator_company,$operator_address,$operator_phone,$operator_pm_name,$operator_pm_phone,$operator_pm_email,$clientposition);
              
              /*$helper->inserthotelcontractors($hotelid,$investorid,1);
               $helper->inserthotelcontractors($hotelid,$developerid,2);
               $helper->inserthotelcontractors($hotelid,$architectid,3);
               $helper->inserthotelcontractors($hotelid,$generalcontractorid,4);
               $helper->inserthotelcontractors($hotelid,$consultantid,5);
               $helper->inserthotelcontractors($hotelid,$preopeningofficeid,6);
               $helper->inserthotelcontractors($hotelid,$interiordesignerid,7);
               $helper->inserthotelcontractors($hotelid,$purchasingcompanyid,8);
               $helper->inserthotelcontractors($hotelid,$mepcontractorid,9);
               $helper->inserthotelcontractors($hotelid,$operatorid,10);*/
                }
                $k=$k+1;
            }
        }
       /* $html.="</table>";
        echo $html;*/

            echo "<br />Data Inserted in dababase";
        }
        else
        {
            die("<br/>Sorry, File type is not allowed. Only Excel file.");
        }

}
?>

<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1><?php echo $maintitle;?></h1>
      <ol class="breadcrumb">
        <li><a href="dashboard.php"><i class="fa fa-dashboard"></i> <?php echo AL_DASHBOARD;?></a></li>
        <li class="active"><?php echo $maintitle;?></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
     
     <div class="row">
 <!-- Add / Edit / Delete --> 
          <div class="col-sm-12"> 
          <div class="box box-success">
         <div class="box-header">
              <i class="fa fa-building-o"></i>
              <h3 class="box-title"><?php echo $maintitle;?></h3>
              <div class="box-tools pull-right">
                <div class="btn-group">
                <a href="<?php echo $page;?>"><button class="btn btn-danger btn-flat">&nbsp; <?php echo AL_LISTALL;?> <?php echo $maintitle;?></button></a>
                   
                </div>
              </div>
            </div> 
            </div> 
            </div>

 <!-- Add / Edit / Delete --> 
 

     <div class="col-md-10">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title"> <?php echo $maintitle;?></h3>
            </div>
            
            <?php
			if($hotelid!=""){
			?>
            <button class="btn btn-block btn-success btn-flat" type="button">Data Inserted</button>
			<?php	
			}
			?>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">           
              <div class="box-body">             
             <div class="form-group">
                  <div class="col-sm-12">
            <label>Upload Excel File</label>
            <input type="file" name="file" class="form-control">
              <div>
            </div>
            <div class="form-group">
                <div class="col-sm-12"><br/>
            <button type="submit" name="Submit" class="btn btn-success">Upload</button>
                </div>
            </div>
              </div>
                
            </form>
          </div>
         
        </div>
        </div>
         

    </section>
    <!-- /.content -->
  </div>
<?php include('footer.php');  ?>