<?php include('header.php');?>
<?php include('sidebar.php');?>
<?php
$maintitle="Countries";
$page="countries.php";
$table="tbl_country";
$field_id="countryid";
$mode=$_REQUEST['mode'];
$content_id=$_REQUEST['content_id'];
if(isset($_REQUEST['start'])){
$start=$_REQUEST['start']-1;
}
else {
$start=0;
}
?>

<?php /*?><?php
 
if(isset($_REQUEST['submit'])=="submit"){ 
$required = array("title","customurl","description");
$values = $_POST;
unset($values['customurl']);
  $slug=str_replace(" ","-",strtolower($_POST['customurl']));
  if($slug==""){
	  $slug=$helper->escape_string(strtolower($_POST['title']));
  }
  $sluge=str_replace(" ","-",$slug); 
  $slugexist=$helper->slug_exist($sluge,$table,$content_id,$field_id);
unset($values['submit']);
unset($values['mode']);
$customurl=array("customurl"=>$slugexist);
$values=array_merge($values,$customurl);
$image=$helper->image_upload($_FILES['frm_filename'],"cms");
$photo=array("image"=>$image);
if($photo!=""){
$values=array_merge($values,$photo);
}

$userid=array("user_id"=>$user_id);
$values=array_merge($values,$userid);
if($_REQUEST['mode']=="add"){
$message=$helper->insert($table,$values,$required);
}
if($_REQUEST['mode']=="edit"){
$message=$helper->update($table, $values,array("user_id"=>$user_id,$field_id=>$_REQUEST['contentid']),$required);
}

}
?><?php */?>

<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=="add" || $mode=="edit"){ 
	?>
     
        <?php
	    }
		else {
	    ?>
       <?php /*?> <?php
		if($mode=="delete"){
			 $message=$helper->delete($table, array("user_id"=>$user_id,$field_id=>$_REQUEST['contentid']));
		}
		?><?php */?>
          <?php
		if($mode=="approve"){
			$helper->update($table, array("status"=>1),array("user_id"=>$user_id,$field_id=>$_REQUEST['contentid']), array());
		}
		?>
         <?php
		if($mode=="pending"){
			$helper->update($table, array("status"=>2),array("user_id"=>$user_id,$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("status"=>"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>Country Name</th>
                  <th>Country CODE</th>
                  <th>Status</th>
                </tr>
                <?php
				$i=($start*$limit)+1;
				foreach($listtypes as $type){
				?>
                <tr>
                  <td><?php echo $i;?></td>
                  <td><?php echo $type['country'];?></td>
                  <td><?php echo $type['iso2'];?></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>
                 
                </tr>
                <?php
				$i=$i+1;
				}
				?>
                
                
              </table>
              <?php
			  $counter_list= $helper->countofdata($table,array("user_id"=>$user_id),$limit,array("status"=>"ASC"));
			  include('pagination/pagination.php');
			  ?>
            </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
      </div>
      <?php
		}
		?>

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