<?php
	include("my_functions.php");
	$pagetitle = "Mange targets";
	require('includes/applicationtop.php');
	require('includes/applicationmenu.php');
	
	$err= "";

    $actual_link = 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
		$parts = explode('managetasks' , $actual_link);
		
    $fromdate = false;
    $command = false;
	
	$startdatevalid = false;
	
	 
		 
        if(!empty($_POST["name"]) and !empty($_POST["amount"])   ){

  
            $month = date('Y-m-d', strtotime($_POST["name"]));  
            $bill     = $_POST["amount"]; 
            DB::startTransaction();
					DB::query("SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE");
					DB::insert
					('targets', 
						array
						(
							'target' => $bill,
                            'tperiod' => $month,
                             
                        ) 
					);
					
					DB::commit(); 
                    
                    
                    ?>
						<script>
							window.location = "<?= $base_url?>managetargets";
						</script>
                        <?php
			
			 
			
			 
			 
		 
	} 
?>
			<!-- Content Wrapper. Contains page content -->
			<div class="content-wrapper">
			 

				<!-- Main content -->
				<section class="content">
					<!-- Default card -->
					<div class="card card-primary">
						<?php
							if($_SESSION["connectedusergroup"] == 1 || $_SESSION["connectedusergroup"] == 3)
							{
						?>
						<div class="card-body">
							<div id="servererrormessage">
							</div>
							
							<?php
								if($err!="")
								{
							?>
							<div class="alert alert-danger alert-dismissable">
								<i class="fa fa-ban"></i>
								<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button><br>
								<?php 
									echo $err; 
								?>
							</div>
							<?php
								}
							?>
							
							<div class="card card-info">
                                <div class="card-header">
                                    <h6 class="card-title"><?= $pagetitle ?></h6>
                                </div>
                                <div class="card-body">
                            
                               
							
							 
								<?php
									if($err=="" )
									{
								?>
								   

                                 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

                                 <div class="form-group  ">

                                 <div class="form-group">
										<label for="firstname"> Month</label>
                                        
										<input type="date" name="name" id="name" maxlength="40" class="form-control" value="<?= date('Y-m-d');?>" >
									</div><!-- form-group -->
									
									<div class="form-group">
										<label for="lastname">Target</label>
										<input type="text" name="amount" id="amount" maxlength="40" class="form-control" value="<?php if(!empty(($_POST['amount']) )){ echo $_POST['amount'];}   ?>" >
									</div><!-- form-group -->
									 
            

                                            <div class="btn-list">
								<div class="text-right">
									<a href="dashboard.php" class="btn btn-danger"><i class="glyphicon glyphicon-remove"></i> Cancel</a>
									
									<button type="submit" name="savedatabtn" id="savedatabtn" class="btn btn-success"><i class="glyphicon glyphicon-floppy-disk"></i> Save</button>
								</div>
							</div>

                         

                                    </form>
								  
								   
                                     

                                </div>
                            </div>
              <!-- /.card-body -->
            </div>
									 
								
								   
								 
										 
								
								
								
								</div>
							</div>
						</div><!-- /.card-body -->
						<?php
							}
							}
							else
							{
						?>
						<div class="alert alert-danger alert-dismissable">
							<i class="fa fa-ban-circle"></i><br>
							Limited Access
						</div>
						<?php
							}
						?>
					</div><!-- /.card -->
				</section><!-- /.content -->
			</div><!-- /.content-wrapper -->
 
		</div><!-- ./wrapper -->
		
		<div class="modal" id="waitdialogmodal"  data-backdrop="static">
            <div class="modal-dialog modal-sm">
              <div class="modal-content">
                  <div class="modal-body">
					<div class="text-center">
						<img src="<?php echo $base_url . $ajax_loading_image; ?>" />
					</div>
				  </div>
              </div>
            </div>
        </div>

		 
	
	
	
	
 <?php include ('includes/general_footer.php')?>  
 
<script>
 
		$(function(){
			 
			$('#from').datepicker();
			$('#to').datepicker();
			 
			 
		});
	</script>

	 
		<script src="plugins/bert/storepos.js" type="text/javascript"></script>
		<script src="plugins/bert/store.js" type="text/javascript"></script>
	</body>
</html>