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


if($_POST) 
{

// print_r($_POST);
// die();

    $i = 0;
    foreach($_POST['class'] as $cls){

        $db->delete("optional_class", " where class='$cls' and session='".$_SESSION["admin"]["session"]."' ");
        
        foreach($_POST["section_$cls"] as $sec){

            $insAry = array(
                "class"     =>  $cls,
                "section"   =>  $sec,
                "session"   =>  $_SESSION["admin"]["session"],
				"added_by"  =>  $_SESSION["admin"]["uid"]
            );
   			$db->insertAry("optional_class",$insAry);
        }

    $i++;
  }

redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"ExamCBSE", "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
}

    $allclass = $db->getRows("SELECT * FROM class order by id");
    $promote = $db->getVal("select promote from result_message");
    
    $allsections = $db->getRows("select name from section order by name");
?>
<!-- Forms -->
<div class="row-fluid">
  <form method="post" action="">
    <!-- Forms: Box -->
    <div class="span12"> 
      
      <div class="top-bar">
        <h3><i class="icon-cog"></i> Result Messages</h3>
        <button type="submit" class="btn btn-primary" style="float:right;margin-top:10px;"> Save</button>
      </div>

      <div class="well no-padding">

        <br>

        <table class="table" style="width:100%;">
                <thead>
                    <tr>
                        <th style="width:50px;">S.No.</th>
                        <th style="width:250px;">Class</th>
                        <th colspan="<?php echo count($allsections); ?>">Section</th>
                    </tr>
                </thead>
                <tbody id="tbody2-A">
                  <?php $i=1;
                        foreach($allclass as $cls) 
                        {
                            ?> 
                <tr>
                    <td><?php echo $i; ?> <input type="hidden" name="class[]" value="<?php echo $cls['class']; ?>" /> </td>
                    <td><?php echo $cls['class']; ?></td>
                    <?php foreach($allsections as $sec){ 
                    $checkvalue=$db->getVal("select id from optional_class where class='$cls[class]' and section='$sec[name]' and session='".$_SESSION["admin"]["session"]."'   ");
                    ?>
                        <td>
                            <?php echo $sec['name']; ?> 
                            <input type="checkbox" name="section_<?php echo $cls['class']; ?>[]" value="<?php echo $sec['name']; ?>" <?php if($checkvalue > 0) echo "checked"; ?> style="width:20px;height:20px;" />
                        </td>
                    <?php } ?>
                </tr>
                <?php $i++;
                        }  ?>
            </tbody>
        </table>

        <br><br>

        <!--<div class="form-actions">-->
          
        <!--  <button type="button" class="btn"> Cancel</button>-->
        <!--</div>-->
      </div>

    </div>

  </form>
</div>


