<?php 
$file_name		= "index?page=view_keycode";
$form_action	= "insert";
$button_value 	= "Add";
$table_name 	= "keycode";
$page_name      = "Add Keycode";
$name        = $_REQUEST['keycode_value'];
$id	 = "";
$query_string = "";
$invoice_date = "";

################################################## START EDIT ##################################################
/*
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'edit'){

	$form_action 	= "update";
	$button_value 	= "update";
	$page_name		= "Edit keycode";
	//$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];
	
    $name = $_REQUEST['name'];
    $sql= "SELECT * FROM keycode WHERE name = '$name'";
    $result_edit = mysqli_query($conn,$sql);
    $row_edit = mysqli_fetch_array($result_edit);

    $id= $row_edit['id'];
    $name= $row_edit['name'];
    $code= $row_edit['code'];
    $description= $row_edit['description'];
} */
################################################# END EDIT ################################################# 


################################################## START update ################################################## 
if(isset($_REQUEST['action']) && $_REQUEST['action'] == 'update'){    

	$id= $_REQUEST['id'];
    //$name= $_REQUEST['name'];
    //$code= $_REQUEST['code'];
    $description= $_REQUEST['description'];

    $sql= "UPDATE keycode SET description = '$description' WHERE id = $id";
    mysqli_query($conn,$sql);
    //header("Location: $file_name&message=$tmp updated sucessfully$query_string");
    //exit();
}
################################################# END update ################################################# 

$form_action 	= "update";
$button_value 	= "update";
$page_name		= "";
//$query_string 	=  (isset($_POST['query_string'])) ? $_POST['query_string'] : $_SERVER['QUERY_STRING'];

$name = $_REQUEST['name'];
$page_name = ucfirst(str_replace('_',' ',$name));

$sql= "SELECT * FROM keycode WHERE name = '$name'";
$result_edit = mysqli_query($conn,$sql);
$row_edit = mysqli_fetch_array($result_edit);

$id= $row_edit['id'];
$name= $row_edit['name'];
$code= $row_edit['code'];
$description= $row_edit['description'];

?>
<td width="100%" align="center" valign="top" bgcolor="" class="red">
<h1><?php echo $page_name;?> </h1><br>
<form method="post" name="form1" id="form1" action="index?page=edit_keycode&action=<? echo $form_action; ?>" onsubmit="return valiinvoice_dateForm(this)" >
     <table border=1; style="margin:20px 0px 0px 20px; clear:both;"> 
		  <tr valign="top">		  
			<td style="border:0x solid red">					
				<!--<div id="ed_pro_div"><label class="ed_pro_label" for="name">Name:</label><input class="ed_pro_input" type="text" id="name" name="name" value="<?php echo $name;?>"></div>
				<div id="ed_pro_div"><label class="ed_pro_label" for="code">Code:</label><input class="ed_pro_input" type="text" id="code" name="code" value="<?php echo $code;?>"></div>-->
				<div id="ed_pro_div"><!--<label class="ed_pro_label" for="description">Description:</label>--><input style="width:164px;margin:2px 0px 0px 124px" class="ed_pro_input" type="text" id="description" name="description" value="<?php echo $description;?>"></div>
			</td>    		
		</tr>	
		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>		 
		<tr>
			<td colspan="2" align="center" style="border:0x solid red">
					
					<input type="hidden" id="id" name="id" value="<?php echo $id;?>">
					<input type="hidden" id="name" name="name" value="<?php echo $name;?>">
					<input type="hidden" id="query_string" name="query_string" value="<?php echo $query_string;?>">
					<input type="submit" name="submit" value="<?php echo $button_value;?>" >
			</td>
		</tr>         
		<tr>
			<td colspan="2" align="center" style="border:0x solid red">&nbsp;</td>
		</tr>
     </table>
</form>
</td>
<script type="text/javascript">
//holiday_start_date show calendar
$('#date_of_birth').datepicker({
	changeMonth: true,
    changeYear: true,
	dateFormat: 'dd-mm-yy',
	onSelect: function() {		
	}
});	
$('#project_id').change(function(){
	var project_id	= $(this).val();
	if(project_id !=""){
	var form_data 	= {'project_id' : project_id};
	$.ajax({
		async: false,
		type: "POST",
		url: site_url+"/modules/invoice/index.php?page=ajax_actions&action=show_task_list",
		data: form_data,
		success: function(result){
			$("#task_list_div").html(result);
		}
	});
	}
});
</script>
