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

//echo "asdfasdf".$_SESSION["admin"]["uid"];


if($_POST)
{
    
    // print_r($_POST);
	$_SESSION['form']=$_POST;
	$flgEr=FALSE;

	$flgUp=$db->delete("student_control"," where 1");

		foreach($_POST["modules"] as $name){

			$aryData=array(	'module_name'	=>	trim($name),
								'school_id'	=>	$_SESSION["admin"]["school_id"],
								'added_by'	=>	$_SESSION["admin"]["uid"]
            				);
        // echo $_POST[$name];
        if($_POST["$name"]){
			$flgIn=$db->insertAry("student_control",$aryData);
        }

		}
		if($db->getErMsg()=="")
		{
			$_SESSION['msg']='Saved Successfully';
		//	redirect(URL_ADMIN_HOME.getQueryString(array("page_id"=>$pgMod,"action"=>$pgAct,"id"=>$_GET["id"])));
		}else{
			$alert_err[0]=$db->getErMsg();
		}
	
 
}

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
}

	error_reporting(22);


    $allmodules = array("AdmitCard","OnlineStudy","OnlineContent", "OldLiveClass", "LiveClass","LiveClassMeet","YoutubeLive","Attendance", "Homework", "Circular", "OnlinePayment", "ViewFees", "Exam", "Results",
                    "Syllabus", "TimeTable", "Performance", "SchoolWebsite", "Communicate", "Transport", "ImageGallery", "Birthday", "MyTeacher", "Calendar", "MyClassmate",
        "Facebook", "Location","Survey","GPS","Dictionary","Notifications","Inventory","OnlineContentSchool","FeedbackForTeacher","LiveVehicleTracking");

    if ($_SERVER['HTTP_HOST'] == 'bps.savarnacloud.com'){
        $allmodules[] = "SchoolData";
    }

	?>
    <form method="post" action="">
	<table class="responsive display table table-bordered" width="100%">
		<thead>
        	<tr>
            	<th class="first"><div>Sr.No</div></th>
				<th>Module Name</th>
                <th>Active</th>
                <th class="last" width="25px">Inactive</th>
            </tr>
       </thead>
       <tbody>
	<?php $i=0;
	foreach($allmodules as $module)
	{
		$i++;
            $per = $db->getVal("select count(*) from student_control where module_name='$module' ");
			?>
            <tr>
            	<td><?php echo $i;?></td>
            	<td><input type="hidden" name="modules[]" value="<?php echo $module; ?>" /><?php echo $module; ?></td>
                <td><input type="radio" name="<?php echo $module; ?>" value="1" <?php if($per)echo "checked"; ?> /></td>
                <td><input type="radio" name="<?php echo $module; ?>" value="0" <?php if(!$per)echo "checked"; ?> /></td>
            </tr>
			<?php
		
	}
	?></tbody>
    </table>
    <div class="form-row row-fluid">
                <div class="span12">
                    <div class="row-fluid">
                        <div class="form-actions">
                        <div class="span3"></div>
                        <div class="span9 controls">
                            <button type="submit" class="btn btn-info">Save changes</button>
                            <button type="button" onclick="window.location=''" class="btn">Cancel</button>
                        </div>
                        </div>
                    </div>
                </div> 
            </div>
    </form>
