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

if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['name']) || trim($_POST['name'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Name.");
	}
	if($flgEr!=TRUE && $pgAct=="add")
	{
        $_POST["session"]   =   $_SESSION["admin"]["session"];
        $_POST["added_by"]  =   $_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("admission_agent",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Enquiry", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
		$flgUp=$db->updateAry("admission_agent",$_POST,"where id='".$_GET['id']."'");
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Enquiry", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("admission_agent","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"=>"Enquiry", "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 admission_agent WHERE id='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{
?>
	<div class="row-fluid">
        <form method="post" action="">
			<div class="span12">

				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create a New Admission Agent</h3>
				</div>

				<div class="well no-padding">

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

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

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

					<div class="control-group">
						<label class="control-label">Address</label>
						<div class="controls">
                            <textarea name="address" class="input-block-level"><?php if($_POST)echo $_POST["address"]; else echo $aryForm["address"] ?></textarea>
                        </div>
					</div>
					
					<div class="form-actions">
						<button type="submit" class="btn btn-primary"> Save</button>
						<button type="button" class="btn"> Cancel</button>
					</div>

				</div>

			</div>

        </form>
	</div>
<?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=Enquiry&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"=>"Enquiry", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("SELECT * FROM admission_agent "); $i=0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example">
            <thead>
                <tr>
                    <th>S.No.</th>
                    <th>Name</th>
                    <th>Mobile</th>
                    <th>Email</th>
                    <th>Address</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];$aryPgAct['page_id']=$pgMod;
            ?>
                <tr class="grade<?php if($i%2==0)echo "C";else "U";?>">
                    <td><?php echo $i; ?></td>
                    <td><?php echo $clist["name"] ?></td>
                    <td><?php echo $clist["mobile"] ?></td>
                    <td><?php echo $clist["email"] ?></td>
                    <td><?php echo $clist["address"] ?></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
}
?>
<!-- / Forms -->