<?php 
include_once 'includes/processes.php';
$Process = new Login_Process;
$pageLink = basename($_SERVER['REQUEST_URI']);
$Process->check_status($pageLink);
$addModule = $Process->addModule($_POST,$_POST['add_module']);
$updateModule = $Process->updateModule($_POST,$_POST['update_module']);
if(isset($_GET['ed'])) {
	$moduleData = $Process->getModuleInfo($_GET['module_id']);
}

if(isset($_GET['del'])) {
	$dbLink = $Process->connect_db();
	$query = "delete from apl_app_module WHERE module_id = '".$_GET['module_id']."'";
	$runQ = $Process->RunQuery($query,$dbLink);
	if($runQ) {
		$msgDelete = "<div class=\"alert alert-success\">Module deleted Successfully.</div>";
	}
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <title>Module Manager - APL Portal</title>

  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,400,600,700">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,300,700">
  <link rel="stylesheet" href="./css/font-awesome.min.css">
  <link rel="stylesheet" href="./js/libs/css/ui-lightness/jquery-ui-1.9.2.custom.min.css">
  <link rel="stylesheet" href="./css/bootstrap.min.css">

  <!-- Plugin CSS -->
  <link rel="stylesheet" href="./js/plugins/magnific/magnific-popup.css">

  <!-- App CSS -->
  <link rel="stylesheet" href="./css/target-admin.css">
  <link rel="stylesheet" href="./css/custom.css">


  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->
</head>

<body>

<?php include'includes/header.php'; ?>

<div class="container">

  <div class="content">

    <div class="content-container">

      

      <div class="content-header">
        <h2 class="content-header-title">Module Manager</h2>
        <ol class="breadcrumb">
          <li><a href="./">Home</a></li>
          <li class="active">Module Manager</li>
        </ol>
      </div> <!-- /.content-header -->

      

      <div class="row">
		 
        <div class="col-md-12">
			<?php echo $addModule; ?>
			<?php echo $updateModule; ?>
			<?php echo $msgDelete; ?>
		</div>
		
        <div class="col-md-4">
		
		 <div class="portlet">
			<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <div class="portlet-header">

              <h3>
			  <?php if(isset($_GET['ed'])): ?>
				<i class="fa fa-edit"></i>
                Edit Module
			  <?php else: ?>
				<i class="fa fa-plus"></i>
                Add New Module
			  <?php endif; ?>
                
              </h3>
			  <?php if(isset($_GET['ed'])): ?>
				<ul class="portlet-tools pull-right">
                <li>
                  <a href="module.php" class="btn btn-sm btn-default">
                    add new
                  </a>
                </li>
              </ul>
			  <?php endif; ?>
			   

            </div> <!-- /.portlet-header -->

            <div class="portlet-content">           
				
				<input type="hidden" id="module_id" name="module_id" value="<?php echo $moduleData->module_id; ?>" />
				<div class="form-group col-sm-12">
					<label for="item_desc">Module Name</label>
					<input type="text" id="module_name" name="module_name" class="form-control" value="<?php echo $moduleData->module_name; ?>" required />
				</div>
					
				<div class="form-group col-sm-12">
					<label for="item_desc">Module page name</label>
					<input type="text" id="module_page" name="module_page" class="form-control" value="<?php echo $moduleData->module_link; ?>" required />
				</div>
				
				<div class="form-group col-sm-12">
					<label for="item_desc">Menu Position</label>
					<input type="number" id="module_position" name="module_position" class="form-control" value="<?php echo $moduleData->position; ?>" required />
				</div>
				
				<div class="form-group col-sm-12">
					<label for="item_desc">Parent</label>
					<select id="parent_id" name="parent_id" class="form-control">
						<option value="">-- select ---</option>
						<option value="0">Top</option>
						<?php $Process->listModules($moduleData->parent_id); ?>
					</select>
				</div>	
				
				<div class="form-group col-sm-12">
					<label for="item_desc">Module Status</label>
					<select id="module_status" name="module_status" class="form-control" required>
						<option value="">-- select Status ---</option>
						<option value="Active" <?php if($moduleData->status=="Active") { echo "selected"; } ?>>Active Module</option>
						<option value="Disabled" <?php if($moduleData->status=="Disabled") { echo "selected"; } ?>>Disabled Module</option>
					</select>
				</div>				  
				
            </div> <!-- /.portlet-content -->
			<div class="portlet-footer">
			  <?php if(isset($_GET['ed'])): ?>
				<button type="submit" name="update_module" class="btn btn-primary">Update Module</button>
			  <?php else: ?>
				<button type="submit" name="add_module" class="btn btn-primary">Add Module</button>
			  <?php endif; ?>
            </div> <!-- /.portlet-footer -->
			</form>
          </div> <!-- /.portlet -->

		  
        </div> <!-- /.col -->
		 
        <div class="col-md-8">
		
		 <div class="portlet">

            <div class="portlet-header">
              <h3>
                <i class="fa fa-th"></i>
                List Module
              </h3>
            </div> <!-- /.portlet-header -->

            <div class="portlet-content">           
				<?php $Process->getModules(); ?>
            </div> <!-- /.portlet-content -->

          </div> <!-- /.portlet -->

		  
        </div> <!-- /.col -->

      </div> <!-- /.row -->     




    </div> <!-- /.content-container -->
      
  </div> <!-- /.content -->

</div> <!-- /.container -->
	<?php include"includes/footer.php"; ?>

 <script src="./js/libs/jquery-1.10.1.min.js"></script>
  <script src="./js/libs/jquery-ui-1.9.2.custom.min.js"></script>
  <script src="./js/libs/bootstrap.min.js"></script>

  <!--[if lt IE 9]>
  <script src="./js/libs/excanvas.compiled.js"></script>
  <![endif]-->
  
  <!-- Plugin JS -->
  <script src="./js/plugins/datatables/jquery.dataTables.min.js"></script>
  <script src="./js/plugins/datatables/DT_bootstrap.js"></script>
  <script src="./js/plugins/tableCheckable/jquery.tableCheckable.js"></script>
  <script src="./js/plugins/icheck/jquery.icheck.min.js"></script>

  <!-- App JS -->
  <script src="./js/target-admin.js"></script>

  
  <script>
function addItem(divName){
     var newdiv = document.createElement('div');
	
     newdiv.innerHTML = "<div class='col-sm-4'>"+
					"<div class='form-group col-sm-12'>"+
						"<label for='item_desc'>Item Description</label>"+
						"<input type='text' id='item_desc' name='item_desc[]' class='form-control'>"+
					"</div>"+
				"</div>"+
				"<div class='col-sm-4'>"+
					"<div class='form-group col-sm-12'>"+
						"<label for='item_qty'>Item quantity</label>"+
						"<input type='number' id='item_qty' name='item_qty[]' class='form-control'>"+
					"</div>"+				
				"</div>"+
				"<div class='col-sm-4'>"+
					"<div class='form-group col-sm-12'>"+
						"<label for='item_remark'>Remarks</label>"+
						"<input type='text' id='item_remark' name='item_remark[]' class='form-control'>"+
					"</div>"+				
				"</div>";
     document.getElementById(divName).appendChild(newdiv);

}

function removeDesignation(sourceid) {
	var elementid = document.getElementById(sourceid);
	//counter--;
	elementid.remove();
}
</script>
  
</body>
</html>
