<?php session_start();
include ('../inc/dbcon.php');
include ('../inc/functions.php');
if(isset($_SESSION["axeslogin"]) && $_SESSION["axeslogin"] == true){
$_SESSION['cuPages']='prj_typecteate.php';   
$cuPage='prj_typecteate.php';    
$aid=$_SESSION['uid'];
$uty=$_SESSION['utype'];    
$brid=$_SESSION['abrid'];     
}else{
header('Location:../index.php');
exit;    
}
$mhead='project';
$menuh='Manage Project';
$phead='typcreate';
$page='Project Type Create';
$dtnow = date("Y-m-d h:i:s", time());
$today = strftime("%Y-%m-%d", time());
?>
<?php 
if(isset($_POST['save_type'])){
	$name = ucwords(remove_junk(escape($_POST['name'])));
    $description = remove_junk(escape($_POST['description']));
	
	if(isset($_POST['name'])){
	$ducode = mysqli_query($con,"SELECT * FROM tbl_prjtype WHERE name = '$name'");
	}
	
	if($ducode->num_rows > 0) {
	save_msg('i','Type alrady used! Plz try another');
	echo "<script>window.location='prj_typecteate.php'</script>";
	}else{   
    $sql="INSERT INTO tbl_prjtype(name,description,brid,uid,date) VALUES ('$name','$description','$brid','$aid','$dtnow')";    
	$result = mysqli_query($con,$sql) or die(mysqli_error($con));
    $efid=mysqli_affected_rows($con);    
    if($efid>0){
    $act =remove_junk(escape('Type name: '.$name));    
    write_activity($aid,'TYP','New Type has been created',$act);    
    save_msg('s','Data Successfully Saved!');
    }else{
    save_msg('w','Data Fail to Saved!');    
    }
    echo "<script>window.location='prj_typecteate.php'</script>";  
	}  
}
?>
<?php
include('../layout/head.php');
include('../layout/header.php');
include('../layout/side_nav.php');
?>

<div class="content-wrapper">
<?php include('../layout/page_head.php'); ?>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-md-8">
<div class="box box-solid">
<div class="box-header with-border">
<h3 class="box-title">Create New Type</h3>
</div>
<div class="box-body">
<?php echo display_msg();?>  
<form action="prj_typecteate.php" onsubmit="return validate()" enctype="multipart/form-data" method="post" accept-charset="utf-8">
<div class="col-md-12 popup_details_div">

<div class="row">
<div class="col-md-12">
<div class="col-md-3"></div>
<div class="col-md-6">
<div class="row">
<div class="col-md-12">    
<div class="form-group">
<label>Type</label>
<input type="text" name="name" maxlength="35" value="" id="cname" class="form-control" placeholder="e.g Civil"  />
</div>
</div>    
</div>        
<div class="form-group">
<label>Description</label>
<textarea class="form-control" maxlength="150" rows="6" name="description" placeholder="Description"></textarea>
</div>   
</div>    
<div class="col-md-3"></div>    
</div>    
</div>    

</div>
<div class="clearfix" ></div>
<div class="col-md-12 nopadding widgets_area"></div>    
<div class="row"style="margin-top: 15px" >
<div class="col-md-8"></div>
<div class="col-md-4 text-right" >
<input type="submit" name="save_type" id="submit" class="btn btn-flat bg-purple btn-sm " value="Save"/> <a href="prj_typelist.php" class="btn btn-flat bg-gray  ">Close</a>
</div> 
</div>     
</form>    
</div>
</div>
</div>
<div class="col-md-4">
<div class="row">
<div class="col-md-12">
<div class="box box-solid">
<div class="box-header">
<h3 class="box-title">History </h3>
</div>
<!-- /.box-header -->
<div class="box-body" >
<?php if($_SESSION['utype']=='1'){echo read_activity($aid,'TYP','A');}else{echo read_activity($aid,'TYP','U');}?>
</div>
</div>
</div>
</div>
</div>
</div>
    
<?php include('../layout/quick.php');?>    
</section>
<!-- /.main content -->    
</div>
<?php
include('../layout/footer.php');
?>
<!-- page script -->
<script type="text/javascript">
$(document).ready(function () {  
var pname = new LiveValidation('cname');
pname.add(Validate.Presence);
}); 
</script>    
<!-- /page script -->
</html>