<?php include('../config.php');
include('inc.session-create.php');
$PageTitle="Legal_team";
$FileName =' legal_team.php';
$validate=new Validation();
if($_SESSION['success']!="")
{
$stat['success']=$_SESSION['success'];
unset($_SESSION['success']);
}

if(isset($_POST['addnewrecord']))
{
$validate->addRule($_POST['title'],'','Title',false);
if($validate->validate() && count($stat)==0)
{
    if(isset($_FILES["thumbnail"]["name"]) && !empty($_FILES["thumbnail"]["name"]))
		{
		  $filename = basename($_FILES['thumbnail']['name']);
		  $ext1 = strtolower(substr($filename, strrpos($filename, '.')+1));
		  if(in_array($ext1,array('jpg','JPG','JPEG','jpeg','png','PNG','gif','svg','webp')))
		  {
			$newfile=date("d-m-Y-h-i-s").rand(1000,9999).".".$ext1;
			move_uploaded_file($_FILES['thumbnail']['tmp_name'],"../uploads/".$newfile);

		  }
		}

				$aryData=array(
						  'token'                     => 		token('legal_team'),
                          'name'           =>       $_POST['name'],
              'number'           =>       $_POST['number'],
              'location'           =>       $_POST['location'],
              'email'           =>       $_POST['email'],
                          'thumbnail'                  =>       $newfile,

						  'status'                    => 		$_POST['status'],
						  );
				$flgIn1 = $db->insertAry("legal_team",$aryData);
        //echo $db->getLastQuery();exit;
				$_SESSION['success']="Submited Successfully";
				redirect($FileName);
				unset($_POST);
 } else {
			$stat['error'] = $validate->errors();
  }
}
elseif(isset($_POST['updaterecord']))
  {
$validate->addRule($_POST['title'],'','Title',false);
if($validate->validate() && count($stat)==0)
{
		if(isset($_FILES["thumbnail"]["name"]) && !empty($_FILES["thumbnail"]["name"]))
		{
		  $filename = basename($_FILES['thumbnail']['name']);
		  $ext1 = strtolower(substr($filename, strrpos($filename, '.')+1));
		  if(in_array($ext1,array('jpg','JPG','JPEG','jpeg','png','PNG','gif','svg','webp')))
		  {
			$newfile=date("d-m-Y-h-i-s").rand(1000,9999).".".$ext1;
			move_uploaded_file($_FILES['thumbnail']['tmp_name'],"../uploads/".$newfile);

		  }
		}else{   $newfile=$_POST['image_old'];  }


			$aryData=array(
						  'name'           =>       $_POST['name'],
              'number'           =>       $_POST['number'],
              'location'           =>       $_POST['location'],
              'email'           =>       $_POST['email'],
                          'thumbnail'                  =>       $newfile,

						  'status'                    => 		$_POST['status'],
						  );
			$flgIn = $db->updateAry("legal_team", $aryData , "where id='".$_GET['id']."' ");
			//		echo $db->getLastQuery();	exit;
			$_SESSION['success']="Update Successfully";
			unset($_POST);
			redirect($FileName);
  } else {
			$stat['error'] = $validate->errors();
  }
}
elseif(($_REQUEST['action']=='delete'))
{
				  $aryData=array(
								'status'                     => 2,
								);
					$flgIn = $db->updateAry("legal_team", $aryData , "where id='".$_GET['id']."' ");
					$_SESSION['success'] = 'Deleted Successfully';
					redirect($FileName);
}
?>
<!DOCTYPE html>
<html>
<head>
<?php include('inc.meta.php'); ?>
</head>
<body class="fixed-left">
<div id="wrapper">
<?php include('inc.header.php'); ?>
  <?php include('inc.sideleft.php'); ?>
  <div class="content-page">
    <div class="content">
      <div class="container">
        <div class="row">
          <div class="col-sm-12">
            <h4 class="page-title"><?php echo $PageTitle; ?></h4>
            <ol class="breadcrumb">
              <li> <a href="<?php echo $iClassName; ?>">Home</a> </li>
              <li class="active"> <?php echo $PageTitle; ?> </li>
            </ol>
          </div>
        </div>
        <div class="row">
          <div class="col-md-12">
            <div class="card-box">
              <div class="row">
                <div class="col-md-9"> <?php echo msg($stat); ?> </div>
                <div class="col-md-3"> <a href="<?php echo $FileName; ?>?action=add"  class="btn btn-default" style="float:right">Add New Record</a> </div>
              </div>
            </div>
            <?php if($_GET['action']=='add') { ?>
            <div class="card-box">
              <form role="form" action="" method="post" enctype="multipart/form-data">
                <div class="row">
                     <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Name</label>
                      <div class="col-md-12">
                      <input   class="required form-control" type="text" name="name"value="<?php echo $_POST['name']; ?>">
                       </div>
                      </div>
                    </div>

                    <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Number</label>
                      <div class="col-md-12">
                      <input  class="required form-control" type="text" name="number"value="<?php echo $_POST['number']; ?>">
                                </div>
            </div>
            </div>
            <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Email</label>
                      <div class="col-md-12">
                      <input  class="required form-control" type="text" name="email"value="<?php echo $_POST['email']; ?>">
                       </div>
            </div>
            </div>
            <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Location</label>
                      <div class="col-md-12">
                      <input  class="required form-control" type="text" name="location"value="<?php echo $_POST['location']; ?>">
                       </div>
            </div>
            </div>

                  <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Image</label>
                      <div class="col-md-12">
                      <input   class="required form-control" type="file" name="thumbnail"  accept="image/*">
                      </div>
                     </div>
                    </div>
                  <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Status</label>
                      <div class="col-md-12">
                      <select  class="required form-control" name="status" >
                      <option value="1" <?php if($_POST['status']=='1') { echo "selected"; } ?>>Active</option>
                      <option value="0" <?php if($_POST['status']=='0') { echo "selected"; } ?>>Inactive</option>
                    </select>
                    </div>
                    </div>
                    </div>
                    </div>


                <div class="row footsect">
                  <div class="col-md-12">
                    <button type="submit" name="addnewrecord" class="btn btn-default">Submit</button>
                    <a  href="<?php echo $FileName; ?>"  class="btn btn-default" >Back</a> </div>
                </div>
              </form>
             </div>
            </div>
            <?php }
  elseif($_GET['action']=='edit') {
      $iSingleRec=$db->getRow("select * from  legal_team where id='".$_GET['id']."'");
          ?>
            <div class="card-box">
              <form role="form" action="" method="post" enctype="multipart/form-data">
              <div class="row">
                    <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Name</label>
                      <div class="col-md-12">
                      <input   class="required form-control" type="text" name="name"value="<?php echo $iSingleRec['name']; ?>">
                       </div>
                      </div>
                    </div>
                    <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">number</label>
                      <div class="col-md-12">
                      <input  class="required form-control" type="text" name="number"value="<?php echo $iSingleRec['number']; ?>">
                       </div>
                      </div>
                    </div>
                     <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Email</label>
                      <div class="col-md-12">
                      <input  class="required form-control" type="text" name="email"value="<?php echo $iSingleRec['email']; ?>">
                       </div>
                      </div>
                    </div>
                    <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Location</label>
                      <div class="col-md-12">
                      <input  class="required form-control" type="text" name="location"value="<?php echo $iSingleRec['location']; ?>">
                    </div>
                      </div>
                    </div>

                    <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Image</label>
                      <div class="col-md-12">
                      <input type="file" class="form-control" name="thumbnail" value="<?php echo $iSingleRec['thumbnail']; ?>"  accept="image/*">
                     <img src="../uploads/<?php echo $iSingleRec['thumbnail']; ?>" style="height:50px;">
                     <input type="hidden"  name="thumbnail" value="<?php echo $iSingleRec['thumbnail']; ?>">
                      </div>
                    </div>
                  </div>
 <div class="col-md-6">
                    <div class="form-group clearfix">
                      <label class="col-md-12 control-label">Status</label>
                      <div class="col-md-12">
                      <select  class="required form-control" name="status" >
                      <option value="0" <?php if($iSingleRec['status']=='0') { echo "selected"; } ?>>Pending</option>
                      <option value="1" <?php if($iSingleRec['status']=='1') { echo "selected"; } ?>>Active</option>
                    </select>
                      </div>
                    </div>
                  </div>
                  </div>

                  <div class="row footsect">
                  <div class="col-md-12">
                    <button type="submit" name="updaterecord" class="btn btn-default">Submit</button>
                    <a  href="<?php echo $FileName; ?>"  class="btn btn-default" >Back</a> </div>
                </div>
              </form>
            </div>
            </div>

            <?php  }  else { ?>
            <div class="card-box">
              <table id="datatable"  class="table table-striped table-bordered">
                <thead>
                  <tr>
                    <th>#</th>
                    <th>Name</th>
                    <th>Location</th>
                    <th>Email Id</th>
                    <th>Number</th>
                    <th>Image</th>
                    <th>status</th>
                    <th>Action</th>
                  </tr>
                </thead>
                <tbody>
                  <?php
      $i=0;
    $aryList=$db->getRows("select * from legal_team where status!='2'  order by id desc");
    foreach($aryList as $iList)  {
      $i=$i+1;  ?>
                  <tr>
                    <td><?php echo $i ?></td>
                    <td><?php echo $iList['name']; ?></td>
            <td><?php echo $iList['location']; ?></td>
          <td><?php echo $iList['email']; ?></td>
              <td><?php echo $iList['number']; ?></td>
        <td><img src="../uploads/<?php echo $iList['thumbnail']; ?>"></td>
                    <td><?php if($iList['status']=='1'){ echo "Active"; }else{echo "Pending"; }?></td>
                    <td><a href="<?php echo $FileName; ?>?action=edit&id=<?php echo $iList['id']; ?>"
                     class="btn-view"><i class="ti-pencil-alt"></i> Edit</a>
                    <a href="javascript:del('<?php echo $FileName; ?>?action=delete&id=<?php echo $iList['id']; ?>')"    class="btn-view" >
                    <i class="ti-trash"></i> Delete</a></td>
                  </tr>
                  <?php } ?>
                </tbody>
              </table>
            </div>

            <?php } ?>
          </div>
        </div>
      </div>
    </div>
    <?php include('inc.footer.php'); ?>
  </div>
</div>
<?php include('inc.js.php'); ?>
</body>
</html>
