<?php
$pgMod="result_message";
$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){ 

              $insAry = array(
                    "class"     =>  $cls,
                    "message"   =>  $_POST['message'][$i],
                    "percent"   =>  $_POST['percent'][$i],
                    "promote"   =>  $_POST['promote'],
                    "session"   =>  $_SESSION["admin"]["session"],
					"added_by"  =>  $_SESSION["admin"]["uid"]
              );

            $check = $db->getVal("select id from result_message where class='$cls' and session='".$_SESSION["admin"]["session"]."' ");
            if($check > 0){
                $db->updateAry("result_message",$insAry, "where class='$cls' and session='".$_SESSION["admin"]["session"]."' ");
            } else {
    			$db->insertAry("result_message",$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");
?>
<!-- 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> Result Messages</h3>
      </div>
      <!-- / Forms: Top Bar -->
      <input type="hidden" name="session" value="<?php echo $_SESSION["admin"]["session"] ?>">

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

        <br>
            <table class="table" style="width:100%;text-align:center;">
                <tr>
                    <th>Promote </th>
                    <td>
                        Percent wise <input type="radio" name="promote" value="1" <?php if($promote==1)echo "checked"; ?> />
                        Free <input type="radio" name="promote" value="0" <?php if($promote==0)echo "checked"; ?> />
                    </td>
                </tr>
            </table><br>

        <table class="table" style="width:100%;">
                <thead>
                    <tr>
                        <th style="width:50px;">S.No.</th>
                        <th style="width:250px;">Class</th>
                        <th>Message</th>
                        <th style="width:150px;">Promote Percentage</th>
                    </tr>
                </thead>
                <tbody id="tbody2-A">
                  <?php $i=1;
                        foreach($allclass as $cls) 
                        {
                            $data = $db->getRow("select * from result_message where class='$cls[class]' and session='".$_SESSION["admin"]["session"]."' ");
                            ?>
                <tr>
                    <td><?php echo $i; ?> <input type="hidden" name="class[]" value="<?php echo $cls['class']; ?>" /> </td>
                    <td>
                        <label><?php echo $cls['class']; ?></label>
                    </td>
                    <td>
                        <textarea name="message[]" class="input-block-level" style="width:" rows="4"><?php echo $data['message']; ?></textarea>
                    </td>
                    <td>
                        <input type="text" name="percent[]" value="<?php echo $data['percent']; ?>" class="input-block-level" />
                    </td>
                </tr>
                <?php $i++;
                        }  ?>
            </tbody>
        </table>

        <br><br>

        <div class="form-actions">
          <button type="submit" class="btn btn-primary"> Save</button>
          <button type="button" class="btn"> Cancel</button>
        </div>
      </div>

    </div>

  </form>
</div>


