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

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

if($_POST)
{
//echo "<pre>";print_r($_POST);exit;

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

$_POST['status']=0;
	
		if(!isset($_POST['notice_type']) || trim($_POST['notice_type'])=='')
		{

			$flgEr=TRUE;

			echo "error==>Please Enter Notice type ";

		}if(isset($_POST['status']) )

		{

			$_POST['status']=1;

		}
	
if($flgEr!=TRUE && $pgAct=="add")
	{
           $_POST["added_by"]=$_SESSION["admin"]["uid"];
			$_POST['school_id']=$_SESSION['admin']['school_id'];
						
	   $flgIn=$db->insertAry("complain",$_POST);
	   if(!is_null($flgIn))
	   {
			$_SESSION['msg']='Saved Successfully';
			unset($_SESSION['form']);
			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("complain",$_POST,"where added_by='".$_SESSION["admin"]["uid"]."' and id='".$_GET['id']."'");
	
		if(!is_null($flgUp))
		{
			$_SESSION['msg']='update Successfully';
			unset($_SESSION['form']);
			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'])!='')
{
	$res=$db->delete("complain","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>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>complain</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
if($pgAct=="edit" && $_GET["id"]!="")
{   
	$aryForm=$db->getRow("SELECT * FROM complain WHERE school_id='".$_SESSION["admin"]["school_id"]."' and id='".$_GET['id']."'");

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

?>
<!-- Forms --> 
	<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 Content Head</h3>
				</div>
				<!-- / Forms: Top Bar -->

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

						
                        <div class="control-group">
							<label class="control-label" for="Name">Notice type</label>
							<div class="controls">
								<input type="text" id="notice_type" name="notice_type" class="input-block-level" value="<?php if(isset($_POST["notice_type"]))echo $_POST["notice_type"]; else  echo $aryForm["notice_type"]; ?>"  >
							</div>
						</div>
                        
                        <div class="control-group">
							<label class="control-label" for="linkname"> Activate  </label>
							<div class="controls">
								<input name="status" type="checkbox" value="1" <?php if($aryForm['status']==1)echo "checked"; ?> > Check this to activate above Content.

							</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 {
color:red;
}
.hoverclass{
color:blue;
}
.unreadclass td{
background-color:#F00 !important;
}

</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>
    </div>
    <div class="well no-padding">
	<?php
	$aryPgAct=array("src"=>"Notice", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("SELECT * FROM teacher_complain order by udate Desc "); $i=0;

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

                    <th>Sr No.</th>
                    
                    <th>Complain By</th>

                    <th>Title</th>

                    <th>Action</th>
                    
	            </tr>
            </thead>
            
            <tbody>
            <?php foreach($aryList as $clist){ $i++; 
	$stu_detail=$objindex->profile($clist['student_id']);
	
$readclass="";	

if($clist['send_by']==2)
{
 $readclass="unreadclass";	
}

			
            $aryPgAct["id"]=$clist['id'];
            ?>
<style>
.abc{
}
</style>            
                <tr class="<?php echo $readclass?>  grade<?php if($i%2==0)echo "C";else "U";?>" > 
                    <td class=""><?php echo $i ?></td>
                    
                    <td><?php echo   $stu_detail['name']."(".$stu_detail['admissionno'].")".$clist['is_read'];	?>
</td>
              
                    <td><a  class="hoverclass" href="<?php echo URL_ROOT."?page_id=complaindetail&id=".$clist['id']; ?>" ><?php echo $clist["detail"] ?></a></td>
                    			
     	            <td >
                    <?php $aryPgAct['action']="edit"; ?>
                         <a style="float:left" href="<?php echo URL_ROOT."?page_id=complaindetail&id=".$clist['id']; ?>"><button type="button" class="btn btn-info">Reply</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></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 -->