<?php
$pgMod="sales_person";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
 

if($_POST)
{
    // print_r($_POST);
    // die();
    
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(isset($_FILES["photo"]["name"]) && !empty($_FILES["photo"]["name"])){
		$lfilename = basename($_FILES['photo']['name']);
		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
		$lnewfile=md5(microtime()).".".$lext;
		if(move_uploaded_file($_FILES['photo']['tmp_name'],PATH_MEDIA."photo".DS.$lnewfile))
		{
			$_POST["photo"]=$lnewfile;
		}
	}

	if($flgEr!=TRUE && $pgAct=="add")
	{
		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("sales_person",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			sms($_POST["mobile"],"Dear Parent, You are successfully joined  ".$LinksDetails["site_name"]." , heartly congrates from ".$LinksDetails["site_name"]." campus.","faculty_enrollment");
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"ERP", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
		$flgUp=$db->updateAry("sales_person",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			sms($_POST["mobile"],"Dear Parent, Your detail is updated successfully in ".$LinksDetails["site_name"],"faculty_enrollment");
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"ERP", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		}
	}
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$flgUp=$db->delete("sales_person","where id='".$_GET['id']."'");
	if(!is_null($res)) { $_SESSION['msg']='Deleted Successfully'; }
	else { array_push($alert_err,$db->getErMsg()); }
	redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"ERP", "page_id"=>$pgMod)));
}
if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
if($pgAct=="edit" && $_GET["id"]!="")
{   
	$aryForm=$db->getRow("SELECT * FROM sales_person WHERE school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{ 
	if(isset($_SESSION['form']))
	{
		$aryForm=$_SESSION['form'];
		unset($_SESSION['form']);
	}
?>
<!-- Forms --> 
<style>.top-bar-minimize{display:none;}
thead, tfoot {display: table-header-group;}
.top-bar+.well,.accordion .accordion-heading+.accordion-body{display: inline-block !important;width: 96.7% !important;overflow: inherit !important;} 
</style>
<form method="post" action="" id="printableDiv" enctype="multipart/form-data">
     <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Create New Admission</h3>
                <div style="float:right; margin-top:5px">
                	<!--<button type="button" onclick="printDiv('printableDiv')" class="btn btn-primary">Print</button>-->
                    <button type="submit" class="btn btn-primary"> Save</button>
                    <button type="reset" class="btn"> Cancel</button>
                </div>
            </div>
            <div class="well">
			<!-- Forms: Box -->
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

						<div class="control-group">
							<label class="control-label">ID NO.</label>
							<div class="controls">
                            	<input type="hidden" name="session" value="<?php echo $_SESSION["admin"]["session"] ?>"	/> 
								<input type="text" name="id" readonly class="input-block-level" value="<?php
                                if($aryForm["id"]!="")
								{
									echo $aryForm["id"];
								}
								else{
									echo (int)($db->getVal("select max(id) from sales_person where school_id='".$_SESSION["admin"]["school_id"]."'")+1);	
								}
								?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" >Date of Joining</label>
                            <div class="controls">
                                    <input type="date" name="doj"  class="input-block-level" value="<?php echo $aryForm["doj"]; ?>">
                                </div>
                        </div>
                        <div class="control-group">
							<label class="control-label">Location</label>
							<div class="controls">
								<select class="span12" name="location">
									<option value="">--Select Location--</option>
                                    <option value="Noida" <?php if($aryForm["location"]=="Noida")echo 'selected';?> >Noida</option>
                                    <option value="Ghaziabad" <?php if($aryForm["location"]=="Ghaziabad")echo 'selected';?>>Ghaziabad</option>
                                    <option value="Aligarh" <?php if($aryForm["location"]=="Aligarh")echo 'selected';?> >Aligarh</option>
                                    <option value="Bihar" <?php if($aryForm["location"]=="Bihar")echo 'selected';?> >Bihar</option>
								</select>
							</div>
						</div>
      <!--                  <div class="control-group">-->
						<!--	<label class="control-label" for="designation">Designation</label>-->
						<!--	<div class="controls">-->
      <!--                          <input type="text" id="designation" name="designation" class="input-block-level" value="<?php echo $aryForm["designation"]; ?>" >-->
						<!--	</div>-->
						<!--</div>-->
                        <div class="control-group">
							<label class="control-label" >salary</label>
							<div class="controls">
								<input type="text" name="salery" class="input-block-level" value="<?php echo $aryForm["salery"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" >Sex</label>
							<div class="controls">
								<select class="span12" name="sex" >
									<option <?php if("Male"==$aryForm["sex"])echo 'selected';?> value="Male">Male</option>
									<option <?php if("Female"==$aryForm["sex"])echo 'selected';?> value="Female">FeMale</option>
								</select>
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" >Qualification</label>
							<div class="controls">
								<input type="text" name="qualification" class="input-block-level" value="<?php echo $aryForm["qualification"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" >User Id</label>
							<div class="controls">
								<input type="text" name="userid" class="input-block-level" value="<?php echo $aryForm["userid"]; ?>" >
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" >Password</label>
							<div class="controls">
								<input type="text" name="pwd" class="input-block-level" value="<?php echo $aryForm["pwd"]; ?>" >
							</div>
						</div>

      <!--                   <div class="control-group">-->
						<!--	<label class="control-label" for="experience">Password</label>-->
						<!--	<div class="controls">-->
						<!--		<input type="text" id="experience" name="password" class="input-block-level" value="<?php echo $aryForm["password"]; ?>" >-->
						<!--	</div>-->
						<!--</div>-->

				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
			<!-- Forms: Box -->
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

					<!-- Forms: Form -->
                    
						<div class="control-group">
							<label class="control-label" for="name">Name</label>
							<div class="controls">
								<input type="text" id="name" name="name" class="input-block-level" value="<?php echo $aryForm["name"]; ?>" required>
							</div>
						</div>

                        <div class="control-group">
							<label class="control-label" >Date of Birth</label>
                            <div class="controls">
                                    <input type="date" id="dob" name="dob"  class="input-block-level" value="<?php echo $aryForm["dob"]; ?>">
                                </div>
                        </div>

	 					<div class="control-group">
							<label class="control-label" for="fname">Father's Name</label>
							<div class="controls">
								<input type="text" id="fname" name="fname" class="input-block-level" value="<?php echo $aryForm["fname"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="mname">Mother's Name</label>
							<div class="controls">
								<input type="text" id="mname" name="mname" class="input-block-level" value="<?php echo $aryForm["mname"]; ?>" >
							</div>
						</div>
      <!--                  <div class="control-group">-->
						<!--	<label class="control-label" for="foccupation">Husband Name</label>-->
						<!--	<div class="controls">-->
						<!--		<input type="text" id="foccupation" name="foccupation" class="input-block-level" value="<?php echo $aryForm["foccupation"]; ?>" >-->
						<!--	</div>-->
						<!--</div>-->

                        <div class="control-group">
							<label class="control-label" for="email">Email Id</label>
							<div class="controls">
								<input type="text" id="email" name="email" class="input-block-level" value="<?php echo $aryForm["email"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="mobile">Mobile No.</label>
							<div class="controls">
								<input type="text" id="mobile" name="mobile" class="input-block-level" value="<?php echo $aryForm["mobile"]; ?>" >
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="address">Address</label>
							<div class="controls">
							<textarea rows="3" class="span12" name="address" id="address"><?php echo $aryForm["address"]; ?></textarea>
							</div>
						</div>
						<!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
            <!-- Forms: Box --><?php //echo "<pre>";print_r($aryForm);echo "</pre>"; ?>
			<div class="span4">

				<!-- Forms: Top Bar -->
				
				<!-- / Forms: Top Bar -->

				<!-- Forms: Content -->
				<div class="well no-padding">

					<!-- Forms: Form -->
						<!-- Forms: Normal input field -->
                        <?php
						if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
							?>
                            <div class="control-group">
                                <label class="control-label" for="photo">Photo</label>
                                <div class="controls">
                                	<?php if($aryForm["photo"]!=""){
										?><img src="../media/photo/<?php echo $aryForm["photo"]; ?>" style="height:60px" /><?php
									}?>
                                    <a href="javascript:;" onclick="$('#photo').click()">Change Photo</a>
                                    <input type="file" name="photo" style="display:none" id="photo"/>
                                </div>
                            </div>

							<?php
						}else{?>
                        <div class="control-group">
							<label class="control-label" for="photo">Photo</label>
							<div class="controls">
								<input type="file" name="photo" id="photo"/>
							</div>
						</div>

                        <div id="ins"></div>
                        <div id="busins"></div>
                        <?php
						}?>
						<!-- / Forms: Normal input field -->


						<!-- Forms: Form Actions -->
						
						<!-- / Forms: Form Actions -->
	 
					<!-- / Forms: Form -->           

				</div>
				<!-- / Forms: Content -->

			</div>
			<!-- / Forms: Box -->
            </div>
        </div>
        
	</div>
</form>
<!-- / Forms -->
<?php
}
else{
	?>
	<div class="row-fluid"><div class="span12"><div class="top-bar">
    <h3><i class="icon-eye-open"></i> <?php echo ucwords($pgAct." ".$pgMod); ?></h3>
    <button style="float:right; margin-top:5px" onclick="window.location='./?src=ERP&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add <?php echo $pgMod; ?></button>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"ERP", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select * from sales_person where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 order by name");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example">
            <thead>
                <tr>
                    <th>S. No.</th>
                    <th>Name</th>
                    <th>Father Name</th>
                    <th>Location</th>
                    <th>Email</th>
                    <th>Contact</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <tr>
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["name"] ?></td>
                    <td><?php echo $clist["fname"] ?></td>
                    <td><?php echo $clist["location"] ?></td>
                    <td><?php echo $clist["email"] ?></td>
                    <td><?php echo $clist["mobile"] ?></td>
                    <td>
                        <?php $aryPgAct['action']="edit"; ?>
                        <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</button></a>
                        <?php $aryPgAct['action']="delete"; ?>
                        <a href="javascript:;" onclick="del('<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>')" class="confirmation"><button type="button" class="btn btn-danger">Delete</button></a>  
                    </td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div></div></div>
	<?php
}
?>