<?php
$pgMod="content_head";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);
//echo"<pre>";print_r($_SESSION);exit;
if($_POST)
{
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['heading']) || trim($_POST['heading'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter title Name.");
	}elseif(!isset($_POST['linkname']) || trim($_POST['linkname'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please enter Link Name.");
	}
	if($flgEr!=TRUE && $pgAct=="add")
	{
		
           $_POST["added_by"]=$_SESSION["admin"]["uid"];
		   if(isset($_POST['status']))
			$_POST["status"]=1;
			else $_POST["status"]=0;
			
	   $flgIn=$db->insertAry("content_head",$_POST);
	   if(!is_null($flgIn))
	   {
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"cms", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
			
		}
	}
	elseif($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id'])!='')
	{
		$flgUp=$db->updateAry("content_head",$_POST,"where  id='".$_GET['id']."'");
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"cms", "page_id"=>$pgMod)));
		}
		else
		{
			array_push($alert_err,$db->getErMsg());
		
		}
	} 
}		
elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
	$res=$db->delete("content_head","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"=>"cms", "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 content_head WHERE added_by='".$_SESSION["admin"]["uid"]."' and id='".$_GET['id']."'");
}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{
	//echo "<pre>";print_r($aryForm);echo "</pre>".$aryForm['root'];
?>
<!-- Forms --> 
	<div class="row-fluid">
        <form method="post" action="">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create a New Content Head</h3>
				</div>
				<!-- / Forms: Top Bar -->

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

						<div class="control-group">
							<label class="control-label" for="heading">Heading</label>
							<div class="controls">
								<input type="text" id="heading" name="heading" class="input-block-level" value="<?php if($_POST)echo $_POST["heading"]; else echo $aryForm["heading"]; ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="root">Link Name</label>
							<div class="controls">
								<input type="text" id="linkname" name="linkname" class="input-block-level" value="<?php if($_POST)echo $_POST["linkname"]; else  echo $aryForm["linkname"]; ?>"  >
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="status">Status</label>
							<div class="controls">
								<input type="checkbox" id="status" name="status" class="input-block-level" >
							</div>
						</div>
                        
						<div class="form-actions">
                        
							<button type="submit" class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

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

        </form>
	</div>
<?php   
}elseif(3=="above"){
	
?>
	<div class="row-fluid">
        <form method="post" action="">
			<!-- Forms: Box -->
			<div class="span12">

				<!-- Forms: Top Bar -->
				<div class="top-bar">
					<h3><i class="icon-cog"></i> Create a New Class</h3>
				</div>
				<!-- / Forms: Top Bar -->

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

						<div class="control-group">
							<label class="control-label" for="class">Class Name</label>
							<div class="controls">
								<input type="text" id="class" name="class" class="input-block-level" required value="<?php if($_POST)echo $_POST["class"]; else echo $aryForm["class"] ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="fee">Class Fee</label>
							<div class="controls">
								<input type="text" id="fee" name="fee" class="input-block-level" required value="<?php if($_POST)echo $_POST["fee"]; else echo $aryForm["fee"] ?>">
							</div>
						</div>
                        <div class="control-group">
							<label class="control-label" for="fee">No. of Installment</label>
							<div class="controls">
								<input type="number" id="installment" name="installment" required class="input-block-level" value="<?php if($_POST)echo $_POST["installment"]; else echo $aryForm["installment"] ?>">
							(max 12)</div>
						</div>
						<div class="form-actions">
							<button type="submit" class="btn btn-primary"> Save</button>
							<button type="button" class="btn"> Cancel</button>
						</div>
                        
				</div>
				<!-- / Forms: Content -->

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

        </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=cms&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"=>"cms", "page_id"=>$pgMod,"action"=>"add");
        $aryList=$db->getRows("SELECT * FROM content_head "); $i=0;
        if(is_array($aryList) && count($aryList)>0)
        {
            ?>
            <table class="table" id="example"> 
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Link</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 $clist["heading"] ?></td>
                        <td><?php echo $clist["linkname"] ?></td>
                        <!--<td><?php echo $clist["installment"] ?></td>-->
                        <td>
                        
                        <!--<?php $aryPgAct['action']="create";$aryPgAct['page_id']="monthlyReport";$aryPgAct['class']=$clist["class"]; ?>-->
                        <!--     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Monthly Report</button></a>-->
                        <?php $aryPgAct['action']="edit";$aryPgAct['page_id']=$pgMod; ?>
                             <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>
                <tfoot>
                    <tr>
                        <th></th>
                        <th colspan="3"></th>
                    </tr>
                </tfoot>
            </table>
            <?php
        }
        else{
    //window.location.assign(url);
    
            ?>
    <script language="javascript">
    function editData(a)
    {
    alert("val"+a);
    }
    </script> 
         
            <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>-->
              
    <section class="content">
    
      <div class="box edit" style="display:none"> </div>
    
        <div class="box view">
    
       <!-- <div class="box-header" style="border-bottom:1px solid #ccc"> <i class="fa fa-envelope"></i>
    
          <h3 class="box-title"><?php echo ucwords($pgAct." ".$pgHeading) ?></h3>
    
          <div class="btn-group pull-right">
    
            <button type="button" class="btn btn-default">Action</button>
    
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> <span class="sr-only">Toggle Dropdown</span> </button>
    
            <ul class="dropdown-menu" role="menu">
    
              <li><a href="javascript:;" onclick="add_action('delete','<?php echo $pgMod; ?>')">Delete</a></li>
    
              <li><a href="javascript:;" onclick="add_action('active','<?php echo $pgMod; ?>')">Active</a></li>
    
              <li><a href="javascript:;" onclick="add_action('inactive','<?php echo $pgMod; ?>')">InActive</a></li>
    
              <li class="divider"></li>
    
              <li><a href="javascript:;" onClick="editData(0,'<?php echo $pgMod; ?>','add')">Add New <?php echo $pgHeading ?></a></li>
    
            </ul>
    
          </div>
    
        </div>
    -->
        <!-- /.box-header -->
    
        <div class="box-body">
    
          <!--<table ajax-type="content_head" ajax-page_id="content_head" class="table table-bordered table-striped">-->
          
          <table  class="table table-bordered table-striped">
          
    
            <thead>
    
              <tr>
    
                <th>Title</th>
    
                <th>Heading</th>
    
                <th>Status</th>
    
                <th>Action</th>
    
              </tr>
    
            </thead>
    
            <tbody>
            
    <?php  
    	$aryPgAct=array("page_id"=>$pgMod,"action"=>"add");
        $content_heads=$db->getRows("select * from ".CONTENT_HEAD);		
    //	echo "<pre>";print_r($sql_limit);echo "</pre>";
    
     foreach($content_heads as $content_head){
         $aryPgAct["id"]=$content_head['id'];
     ?>
                 <tr>
                     <td><?php echo $content_head['linkname']?></td>
                     <td><?php echo $content_head['heading']?></td>
                     <td><?php
                         if($content_head["status"]==1)
                            echo "<small class='label  bg-green'>Active</small>";
                            else
                            echo "<small class='label  bg-red'>Inactive</small>";
                    ?></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  
    
        $sql_limit=$db->getRows("select * from ".CONTENT_HEAD);		
    
    
    
     ?>
    
    
    
    
    
    
        </div>
    
        <!-- /.box-body --> 
    
      </div>
    
      <!-- /.box --> 
    
    </section>
              
              
              
            </div>
            <?php
        }
        ?>
        </div>
  </div>
</div>
	<?php
}
?>
<!-- / Forms -->