<?php
$pgMod="feedback";
$pgAct="view";


if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);



if($_POST)
{

	
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;

	if($flgEr!=TRUE && $pgAct=="add")
	{
		
       $_POST["school_id"]=$_SESSION["admin"]["school_id"];
        $_POST["added_by"]=$_SESSION["admin"]["uid"];
		$flgIn=$db->insertAry("cms_feedback",$_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("cms_feedback",$_POST,"where school_id='".$_SESSION["admin"]["school_id"]."' and 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("cms_feedback","where school_id='".$_SESSION["admin"]["school_id"]."' and 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>complain</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>Student Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
if($pgAct=="edit" && $_GET["id"]!="")
{   
	$aryForm=$db->getRow("SELECT * FROM cms_feedback WHERE  id='".$_GET['id']."'");
//echo "<pre>";echo $db->getLastQuery()."<br>";print_r($aryForm);exit;

}
if($pgAct=="add" || ($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''))
{

 ?>
<!-- Forms --> 

<script language="javascript">

	function getsubname(subname)
	{
	var c=$("#classname").val();
	
	$.post("newajax.php",{type:"getsubname",clsname:c,subname:subname},function(data){
			$("#subdiv").html(data);
		});
	}
	
	$(document).ready(function(){
		getsubname($('#hidden_sname').val());
	});

</script>


<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>

	<div class="row-fluid">
        <form method="post" enctype="multipart/form-data" action="">
			<!-- Forms: Box -->
			<div class="span12">

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

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

 //             $sliderContent=$db->getRows("select notice_type from notice where school_id=".$_SESSION['admin']['school_id']);

//echo "<pre>";print_r($sliderContent);echo"<pre>";
?>           

						
                    <!--    <div class="control-group">
							<label class="control-label" for="Name">Notice type</label>
					    <div class="controls">
            <select  id="notice_type"   name="notice_type"  >
              <option value="0" >Select</option>
              <?php
              $sliderContent=$db->getRows("select notice_type,id from notice where school_id=".$_SESSION['admin']['school_id']);


              foreach($sliderContent as $sdetail){
                    ?>
              <option  value="<?php echo $sdetail['id'];?>" <?php  if($aryForm['id']==$sdetail['id'])echo 'selected="selected"';?> ><?php echo $sdetail['notice_type'];?></option>
              <?php } ?>
            </select>
            
            <?php if($pgAct=="edit" && isset($_REQUEST['id']) && trim($_REQUEST['id']) !=''){
            ?>
            <input type="hidden"  id="hidden_sname" value="<?php echo $aryForm['subject'];?>">
            <?php } ?>
          </div>
						</div> 
						!-->
						
			  <div class="control-group">
          
          <label class="control-label" for="type">Class</label>
          
          <div class="controls">
            <select  id="class"   name="class" onchange="getsubname('classname')" >
              <option value="" >Select</option>
               <option value="all" >All Class</option>
              <?php
              $sliderContent=$db->getRows("select class from class where school_id=".$_SESSION['admin']['school_id']);
              foreach($sliderContent as $sdetail){
                    ?>
              <option  value="<?php echo $sdetail['class'];?>" <?php  if($aryForm['class']==$sdetail['class'])echo 'selected="selected"';?> ><?php echo $sdetail['class'];?></option>
              <?php } ?>
            </select>
            
            <?php if($pgAct=="edit" && isset($_REQUEST['id']) && trim($_REQUEST['id']) !=''){
            ?>
            <input type="hidden"  id="hidden_sname" value="<?php echo $aryForm['subject'];?>">
            <?php } ?>
          </div> 
          
        </div>			
						
                        
                       
                        
                        <div class="control-group">
							<label class="control-label" for="detail">Notice Detail</label>
							<div class="controls">
								<textarea name="detail" id="detail" class="input-block-level" style="resize:none" ><?php echo $aryForm["detail"]; ?></textarea>
							</div>
						</div>
                        
					

                       
                        <!--<div class="control-group" style="display:none">
                          <label class="control-label" for="type">Subject Name</label>
                          <div class="controls" id="subdiv">
                            <select  id="subjectname"  class="form-control" name="subjectname">
                              <option value="0" >Please select Class name first</option>
                            </select>
                          </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{
?>
<style>
.hoverclass{
hover:hoverclass;
}
</style>    

	<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 cms_feedback"); $i=0;

//echo "<pre>";print_r($aryList);echo "<pre>";


	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example">
            
            <thead>

                <tr>

                    <th>Sr No.</th>
                    
                  
  <th>class</th>
                    <th>feedback Detail</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   substr($clist['class'],0,100);	?>
</td>

					<td><?php  echo   substr($clist['detail'],0,100);	?>
</td>


                    <td>
                   
                    <?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></th>
                    <th></th>
                    <th></th>
                    <th colspan="2"></th>
                </tr>
            </tfoot> 
            
        </table>
		<?php
	}
	else{
		?>
        <div class="alert alert-info">
          <a class="close" data-dismiss="alert">×</a>
          <i class="icon icon-warning-sign"></i> <b>complain</b> Record not found </i>
        </div>
        <?php
	} 
	?>
	</div></div></div>
	<?php
}
?>
<!-- / Forms -->