<?php include('header.php');?>
<?php include('sidebar.php');?>
<?php
$maintitle="Customers";
$page="customers.php";
$table="tbl_customers";
$field_id="customerid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['content_id'];
if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>
<?php
 
if(isset($_REQUEST['submit'])=="submit"){ 
$required = array("firstname","lastname","email","phone");
$dataexist=array("email","phone");
$values = $_POST;
unset($values['submit']);
unset($values['mode']);

$image=$helper->image_upload($_FILES['frm_filename'],"users");
$photo=array("image"=>$image);
if($photo!=""){
$values=array_merge($values,$photo);
}
print_r($values);
if($_REQUEST['mode']=="add"){
$message=$helper->insert($table,$values,$required);
}
if($_REQUEST['mode']=="edit"){
$message=$helper->update($table, $values,array($field_id=>$_REQUEST['contentid']),$required,$dataexist);
}

}
?>

<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> Dashboard</a></li>
        <li class="active"><?php echo $maintitle;?></li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
    <?php
	if($mode=="edit"){ 
	?>
     <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;List All <?php echo $maintitle;?></button></a>
                   
                </div>
              </div>
            </div> 
            </div> 
            </div>

 <!-- Add / Edit / Delete --> 
<?php
if($mode=="edit"){
$contentdetails=$helper->select($table,"*",array($field_id=>$_REQUEST['contentid']));
}
?>

     <div class="col-md-4">

          <!-- Profile Image -->
          <div class="box box-primary">
            <div class="box-body box-profile">
            <?php
			if($contentdetails[0]['image']!=""){
			?>
              <img class="profile-user-img img-responsive img-circle" src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/users/<?php echo $contentdetails[0]['image'];?>&w=160&h=160" alt="<?php echo $contentdetails[0]['firstname'];?>">
              <?php
			} else {
			?>
             <img class="profile-user-img img-responsive img-circle" src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/no-image.jpg&w=160&h=160" alt="<?php echo $contentdetails[0]['firstname'];?>">
            <?php
			}
			?>
				<h3 class="profile-username text-center"><?php echo $contentdetails[0]['firstname']." ".$contentdetails[0]['middlename']." ".$contentdetails[0]['lastname'];?></h3>

              <p class="text-muted text-center"></p>

              <ul class="list-group list-group-unbordered">
                <li class="list-group-item">
                  <b>Email: </b> <?php echo $contentdetails[0]['email'];?>
                </li>
                <li class="list-group-item">
                  <b>Phone: </b> <?php echo $contentdetails[0]['phone'];?>
                </li>
                <li class="list-group-item">
                  <b>Mobile: </b> <?php echo $contentdetails[0]['mobile'];?>
                </li>
                <li class="list-group-item">
                  <b>Address: </b> <?php echo $contentdetails[0]['address'];?>
                </li>
                 <li class="list-group-item">
                  <b>City: </b> <?php echo $contentdetails[0]['city'];?>
                </li>
                <li class="list-group-item">
                  <?php
                  $mycountry= $helper->select("tbl_country","country",array("countryid"=>$contentdetails[0]['country']));
				  ?>
                  <b>Country: </b> <?php echo $mycountry[0]['country'];?>
                </li>
              </ul>
                 
            </div>
            <!-- /.box-body -->
          </div>
           
        </div>
        <!-- /.col -->
        <div class="col-md-8">
          
          <div class="col-md-12">
          <!-- Horizontal Form -->
          <div class="box box-info">
            <div class="box-header with-border">
              <h3 class="box-title">Customer Information</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
              <div class="box-body">
                <div class="form-group">
                     <input type="hidden" name="mode" value="<?php echo $_REQUEST['mode'];?>"/>
                  <label for="inputEmail3" class="col-sm-3 control-label">First Name</label>

                  <div class="col-sm-8">
                    <input type="text" value="<?php echo $contentdetails[0]['firstname'];?>" class="form-control" id="firstname" name="firstname" placeholder="First Name">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Middle Name</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="middlename" value="<?php echo $contentdetails[0]['middlename'];?>" name="middlename" placeholder="First Name">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Last Name</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="lastname" value="<?php echo $contentdetails[0]['lastname'];?>" name="lastname" placeholder="Last Name">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Email Address</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="<?php echo $contentdetails[0]['email'];?>"  id="email" name="email" placeholder="Email Address">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Phone</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="<?php echo $contentdetails[0]['phone'];?>" id="phone" name="phone" placeholder="Phone">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Mobile</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="mobile" value="<?php echo $contentdetails[0]['mobile'];?>" name="mobile" placeholder="Mobile">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Address</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" value="<?php echo $contentdetails[0]['address'];?>" id="address" name="address" placeholder="Address">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">City</label>

                  <div class="col-sm-8">
                    <input type="text" name="city" class="form-control" id="city" value="<?php echo $contentdetails[0]['city'];?>"  placeholder="City">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Country</label>

                  <div class="col-sm-8">
                  <?php
                  $countries= $helper->select("tbl_country","countryid,country",array());				   
				  ?>
                  <select name="country" class="form-control" id="country">
                  <?php
				  foreach($countries as $country){
				  ?>
                  <option <?php if($country['countryid']==$contentdetails[0]['country']){ echo "selected";}?> value="<?php echo $country['countryid'];?>"><?php echo $country['country'];?></option>
                  <?php
				  }
				  ?>
                  </select>
                   </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Zip Code</label>

                  <div class="col-sm-8">
                    <input type="text" class="form-control" id="zipcode" value="<?php echo $contentdetails[0]['zipcode'];?>" name="zipcode" placeholder="Zipcode">
                  </div>
                </div>
                <div class="form-group">
                  <label for="inputEmail3" class="col-sm-3 control-label">Upload Image</label>

                  <div class="col-sm-8">
                    <input type="file" class="" name="frm_filename">
                  </div>
                </div>
                
              </div>
              <!-- /.box-body -->
              <div class="box-footer">
                <button type="reset" class="btn btn-default">Cancel</button>
                <input type="submit" name="submit" value="Submit" class="btn btn-info pull-right"/>
              </div>
              <!-- /.box-footer -->
            </form>
          </div>
          <!-- /.box -->
           
        </div>
        </div>
        </div>
        <?php
	    }
		else {
	    ?>
        <?php
		if($mode=="delete"){
			 $message=$helper->delete($table, array($field_id=>$_REQUEST['contentid']));
		}
		?>
          <?php
		if($mode=="approve"){
			$helper->update($table, array("status"=>1),array($field_id=>$_REQUEST['contentid']), array());
		}
		?>
         <?php
		if($mode=="pending"){
			$helper->update($table, array("status"=>2),array($field_id=>$_REQUEST['contentid']), array());
		}
		?>
        <div class="row">
        <div class="col-xs-12">
          <div class="box">
            <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" data-toggle="tooltip" title="Add Business Type">
                <div class="btn-group">
                
                </div>
              </div>
            </div>
            <?php
			$listtypes=$helper->selectlimit($table,"*",array(),$start,$limit,array("firstname"=>"ASC","middlename"=>"ASC","lastname"=>"ASC"));			 
			?>
            <!-- /.box-header -->
            <div class="box-body table-responsive no-padding">
            <?php
			if($message!=""){
			?>
            <button class="btn btn-block btn-danger btn-flat" type="button"><?php echo $message;?></button>
			<?php	
			}
			?>
              <table class="table table-hover">
                <tr>
                  <th>Sl.no</th>
                  <th>Name</th>
                  <th>Email Adress</th>
                  <th>Image</th>
                  <th>Status</th>
                  <th>Action</th>
                </tr>
                <?php
				$i=($start*$limit)+1;
				foreach($listtypes as $type){
				?>
                <tr>
                  <td><?php echo $i;?></td>
                  <td><?php echo $type['firstname']." ".$type['middlename']." ".$type['lastname'];?></td>
                  <td><?php echo $type['email'];?></td>
                  <td>
                  <?php
				  if($type['image']!=""){
				?>
                <img src="<?php echo $site_url;?>thumb.php?src=<?php echo $site_url;?>images/users/<?php echo $type['image'];?>&h=50&w=50"/>
                <?php
				  }
				  ?>
                  </td>
                  <td>
                  
                  <?php
				  if($_REQUEST['start']>0){
					  $limitpage=$_REQUEST['start'];
				  }
				  else {
					  $limitpage=1;
				  }
				   
				  if($type['status']==1){
				  ?>
<a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=pending&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>"><span class="label label-success">Approved</span></a>
                  <?php
				  }
				  else {
				  ?>
				  <a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=approve&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage; ?>"><span class="label label-danger">Pending</span></a>
                  <?php
				  }
				  ?>
                  </td>
                  <td><a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=edit&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>"><span class="label label-primary"><i class="fa fa-edit"></i> Edit</span></a>
                   <a href="<?php echo $site_url;?>admin/<?php echo $page;?>?mode=delete&contentid=<?php echo $type[$field_id];?>&start=<?php echo $limitpage;?>" onclick="return getConfirmation()"><span class="label label-danger"><i class="fa fa-times"></i> Delete</span></a>
                   </td>
                </tr>
                <?php
				$i=$i+1;
				}
				?>
                
                
              </table>
              <?php
			   $counter_list= $helper->countofdata($table,array(),$limit,array("status"=>"ASC"));
			  include('pagination/pagination.php');
			  ?>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
      </div>
      <?php
		}
		?>

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