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


if($_POST)
{
	$_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'],"media/photo/".$lnewfile))
		{
			$_POST["photo"]=$lnewfile;
		}
	}
	//echo "<pre>";print_r($_POST);exit;
	if($flgEr!=TRUE && $pgAct=="add")
	{
		$_POST["school_id"]=$_SESSION["admin"]["school_id"];
$_POST["session"]=$_SESSION["admin"]["session"];
		$flgIn=$db->insertAry("admin",$_POST);
		if(!is_null($flgIn))
		{
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			//sms($_POST["mobile"],"Dear ".$_POST["name"].", You are successfully joined  ".$LinksDetails["site_name"]." , heartly congrates from ".$LinksDetails["site_name"]." campus.","faculty_enrollment");
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Notice", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
        
		$flgUp=$db->updateAry("admin",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");
	
		if(!is_null($flgUp))
		{
		    
			//echo $db->getlastQuery();exit;
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			//sms($_POST["mobile"],"Dear ".$_POST["name"].", Your detail is updated successfully in ".$LinksDetails["site_name"],"faculty_enrollment");
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Notice", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$flgUp=$db->delete("admin","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"=>"Notice", "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 admin 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" for="name">Name</label>
                            <div class="controls">
                                    <input type="text" id="name" name="name"  class="input-block-level" value="<?php echo $aryForm["name"]; ?>">
                                </div>
                        </div>
                        
                       
                        
                        <!--<div class="control-group">
							<label class="control-label" for="medium">Medium</label>
							<div class="controls">
								<select class="span12" name="medium" id="medium">
									<option <?php if("hindi"==$aryForm["sibling"])echo 'selected';?> value="hindi">Hindi</option>
									<option <?php if("english"==$aryForm["sibling"])echo 'selected';?> value="english">English</option>
                                    <option <?php if("both"==$aryForm["sibling"])echo 'selected';?> value="both">Both</option>
								</select>
							</div>
						</div>-->
                    
                        <div class="control-group">
							<label class="control-label" for="experience">mobile</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="password">Password</label>
							<div class="controls">
								<input type="text" id="password" name="password" class="input-block-level" value="<?php echo $aryForm["password"]; ?>" >
							</div>
						</div>

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

			</div>
			<!-- / Forms: Box -->
			<!-- Forms: Box -->
		
			<!-- / 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>
                            
                            <div class="control-group">
							<label class="control-label" for="medium">Assign Role</label>
							<div class="controls">
								<select class="span12" name="role_id">
								    <option value="">-- Select Role --</option>
								    <?php 
								        $allroles = $db->getRows("SELECT * from admin_role");
								        foreach($allroles as $role){ ?>
								            <option <?php if($role[id]==$aryForm["role_id"])echo 'selected';?> value="<?php echo $role[id];?>"><?php echo $role[role_name] ?></option>";
								            <?php
								        }
								    ?>

								</select>
							</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 class="control-group">
							<label class="control-label" for="medium">Assign Role</label>
							<div class="controls">
								<select class="span12" name="role_id">
								    <option value="">-- Select Role --</option>
								    <?php 
								        $allroles = $db->getRows("SELECT * from admin_role");
								        foreach($allroles as $role){ ?>
								            <option value="<?php echo $role[id] ?>"><?php echo $role[role_name] ?></option>";
								            <?php
								        }
								    ?>

								</select>
							</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=Notice&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"=>"Notice", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("select * from admin where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'  order by name");
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example">
            <thead>
                <tr>
                    <th>Serial No</th>
                    <th>Name</th>
                    <th>mobile</th>
                    <th>password</th>
                    <th>login ID</th>

                    <th>Action</th>
                </tr>
            </thead>

            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
            $aryPgAct["id"]=$clist['id'];
            ?>
                <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["password"] ?></td>
                    <td><?php echo $clist["login_id"] ?></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> !-->
                <a href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>&id=<?php echo $clist['id'] ?>" 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
}
?>