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

  

if($_POST){

	$_SESSION['form']=$_POST;
	$flgEr=FALSE;
	if(!isset($_POST['class']) || trim($_POST['class'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please select Class.");
	}
    elseif(!isset($_POST['parent_subject']) || trim($_POST['parent_subject'])=='')
	{
		$flgEr=TRUE;
		array_push($alert_err,"Please select subject.");
	}
	
	
    $checkExists = $db->getRow("select * from assignment_new where class='".$_POST["class"]."' and parent_subject='".$_POST["parent_subject"]."' and sub_subject='".$_POST["sub_subject"]."' and chapter='".$_POST["chapter"]."' ");

    if(count($checkExists)>1  && $pgAct=="add"){
		$flgEr=TRUE;
		array_push($alert_err,"Assignment under this Class->Subject->Sub subject->Chapter already exists. Please use 'Add more' option to add content.");
    }
	
	
	if($flgEr!=TRUE && $pgAct=="add")
	{
	   // $checkExists = $db->getRow("select * from assignment_new where class='".$_POST["class"]."' and parent_subject='".$_POST["parent_subject"]."' and sub_subject='".$_POST["sub_subject"]."' and chapter='".$_POST["chapter"]."' and session='".$_SESSION["admin"]["session"]."' ");

    //     if(count($checkExists)>0){
    //         $flgIn = $checkExists["id"];
    //     }
	   // else {
	        $assignmentArray = array(
                            "class"=> $_POST["class"],
                            "parent_subject" => $_POST["parent_subject"],
                            "sub_subject" => $_POST["sub_subject"],
                            "chapter" => $_POST["chapter"],
                            "key_terms" => $_POST["keyterms_file"],
                            "mind_map" => $_POST["mindmap_file"],
                            "key_notes" => $_POST["keynotes_file"],
                            "practical_projects" => $_POST["practical_file"],
                            "session"    => $_SESSION["admin"]["session"]
                            );
 		    $flgIn = $db->insertAry("assignment_new", $assignmentArray);
        // }


	if(is_array($_POST["videolink"]) && count($_POST["videolink"])>0)
	{
		for($i=0; $i<count($_POST["videolink"]); $i++){
			if(trim($_POST["videolink"][$i])!=""){
			    $url_string=$_POST["videolink"][$i];
                $url= str_replace('watch?v=','embed/', $url_string);
                $videodetail=$_POST["videodetail"][$i];
				$insAry = array(
                		        "assignment_id" => $flgIn,
				                "name"=> $url,
            		            "type" => "youtube_link",
            		            "description" => $videodetail,
            		            "session" => $_SESSION["admin"]["session"]
            		            );
				$db->insertAry("assignment_files",$insAry);
			}
		}
	}

    if(isset($_FILES["key_terms"]["name"]) && !empty($_FILES["key_terms"]["name"])){
        $countfiles = count($_FILES["key_terms"]["name"]);
            $keyterms = array();
            for($i=0;$i<$countfiles;$i++){
        		$lfilename = basename($_FILES['key_terms']['name'][$i]);
        		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
        		$lnewfile=md5(microtime()).".".$lext;
        		if(move_uploaded_file($_FILES['key_terms']['tmp_name'][$i],"uploads/keyterms/".$lnewfile))
            		{
            		    $keytermArray = array(
            		        "assignment_id" => $flgIn,
            		        "name" => $lnewfile,
            		        "ordering" => $_POST["keyterms_order$i"],
            		        "description" => $_POST["keyterms_description$i"],
            		        "type" => "key_terms",
            		        "session" => $_SESSION["admin"]["session"]
            		        );
            		        $db->insertAry("assignment_files", $keytermArray);
            		  //  $keyterms []=$lnewfile;
            		}
            }
// 		$_POST["key_terms"]=json_encode($keyterms);
	}

    if(isset($_FILES["mind_map"]["name"]) && !empty($_FILES["mind_map"]["name"])){
        $countfiles = count($_FILES["mind_map"]["name"]);
            $mindmap = array();
            for($i=0;$i<$countfiles;$i++){
        		$lfilename = basename($_FILES['mind_map']['name'][$i]);
        		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
        		$lnewfile=md5(microtime()).".".$lext;
        		if(move_uploaded_file($_FILES['mind_map']['tmp_name'][$i],"uploads/mindmap/".$lnewfile))
            		{
            		    $mindmapArray = array(
            		        "assignment_id" => $flgIn,
            		        "name" => $lnewfile,
            		        "ordering" => $_POST["mindmap_order$i"],
            		        "description" => $_POST["mindmap_description$i"],
            		        "type" => "mind_map",
            		        "session" => $_SESSION["admin"]["session"]
            		        );
            		        $db->insertAry("assignment_files", $mindmapArray);
            		  //  $mindmap []=$lnewfile;
            		}
            }
// 		$_POST["mind_map"]=json_encode($mindmap);
	}

    if(isset($_FILES["key_notes"]["name"]) && !empty($_FILES["key_notes"]["name"])){
        $countfiles = count($_FILES["key_notes"]["name"]);
            $keynotes = array();
            for($i=0;$i<$countfiles;$i++){
        		$lfilename = basename($_FILES['key_notes']['name'][$i]);
        		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
        		$lnewfile=md5(microtime()).".".$lext;
        		if(move_uploaded_file($_FILES['key_notes']['tmp_name'][$i],"uploads/keynotes/".$lnewfile))
            		{
            		    $keynotesArray = array(
            		        "assignment_id" => $flgIn,
            		        "name" => $lnewfile,
            		        "ordering" => $_POST["keynotes_order$i"],
            		        "description" => $_POST["keynotes_description$i"],
            		        "type" => "key_notes",
            		        "session" => $_SESSION["admin"]["session"]
            		        );
            		        $db->insertAry("assignment_files", $keynotesArray);
            		  //  $keynotes []=$lnewfile;
            		}
            }
// 		$_POST["key_notes"]=json_encode($keynotes);
	}
	
    if(isset($_FILES["videos"]["name"]) && !empty($_FILES["videos"]["name"])){
        $countfiles = count($_FILES["videos"]["name"]);
            $videos = array();
            for($i=0;$i<$countfiles;$i++){
        		$lfilename = basename($_FILES['videos']['name'][$i]);
        		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
        		$lnewfile=md5(microtime()).".".$lext;
        		if(move_uploaded_file($_FILES['videos']['tmp_name'][$i],"uploads/videos/".$lnewfile))
            		{
        		    $videosArray = array(
            		        "assignment_id" => $flgIn,
            		        "name" => $lnewfile,
            		        "type" => "videos",
            		        "ordering" => $_POST["videos_order$i"],
            		        "description" => $_POST["videos_description$i"],
            		        "session" => $_SESSION["admin"]["session"]
            		        );
            		        $db->insertAry("assignment_files", $videosArray);
            		  //  $videos []=$lnewfile;
            		}
            }
// 		$_POST["videos"]=json_encode($videos);
	}
	
    if(isset($_FILES["practical_projects"]["name"]) && !empty($_FILES["practical_projects"]["name"])){
        $countfiles = count($_FILES["practical_projects"]["name"]);
            $practicalprojects = array();
            for($i=0;$i<$countfiles;$i++){
        		$lfilename = basename($_FILES['practical_projects']['name'][$i]);
        		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
        		$lnewfile=md5(microtime()).".".$lext;
        		if(move_uploaded_file($_FILES['practical_projects']['tmp_name'][$i],"uploads/practicalprojects/".$lnewfile))
            		{
            		    $practicalArray = array(
            		        "assignment_id" => $flgIn,
            		        "name" => $lnewfile,
            		        "ordering" => $_POST["practical_order$i"],
            		        "description" => $_POST["practical_description$i"],
            		        "type" => "practical_projects",
            		        "session" => $_SESSION["admin"]["session"]
            		        );
            		        $db->insertAry("assignment_files", $practicalArray);
            		}
            }
	}

$subject = $db->getVal("select subject from subject_new where id='".$_POST['parent_subject']."' and type='subject' ");
$chapter = $db->getVal("select subject from subject_new where id='".$_POST['chapter']."' and type='chapter' ");

$session = $_SESSION['admin']['session'];
$class = $_POST['class'];
$set_title = "Assignment Notice.";
$msg = "Dear Parents, A new assignment of $subject in chapter $chapter has been uploaded.";

// Enabling error reporting
error_reporting(-1);
ini_set('display_errors', 'On');

 $upOne = realpath(__DIR__ . '/..');

 $upOne2 = realpath(__DIR__ . '/..'.'api_new/firebase/push.php');

require_once  $upOne.'/api_new/firebase/firebase.php';
require_once  $upOne.'/api_new/firebase/push.php';

$firebase = new Firebase();
$push = new Push();

$tokenlist=$db->getRows("SELECT idno,name,fcm_token from student where class='$class' and session='$session' and status='1' ");

$result_arr = array();

foreach ($tokenlist as $value) {
        $stu_id =  $value['idno'];
        $target_user_name =  $value['name'];
        $fb_token =  $value['fcm_token'];

        if (strlen($fb_token) > 0 ) {
            // optional payload
            $payload = array();
            $payload['name'] = $target_user_name;
            $payload['msg'] = $msg; // whether to include to image or not
            $payload['stu_id'] = $stu_id;
            $include_image = TRUE;
            $push->setTitle($set_title);
            $push->setMessage($msg);
            if ($include_image) {
                $push->setImage('https://api.androidhive.info/images/minion.jpg');
            } else {
                $push->setImage('');
            }
            $push->setIsBackground(FALSE);
            $push->setPayload($payload);
            $json = '';
            $response = '';
            $json = $push->getPush();
       
            $response = $firebase->send($fb_token, $json);
            
            array_push($result_arr,$response);
            
        }
}



        if ($flgIn>0) {
			redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Notice", "page_id"=>$pgMod)));
        }


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

        $assignmentArray = array(
            "class"=> $_POST["class"],
            "parent_subject" => $_POST["parent_subject"],
            "sub_subject" => $_POST["sub_subject"],
            "chapter" => $_POST["chapter"],
        );
 	    $flgUp = $db->updateAry("assignment_new", $assignmentArray, "where id='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."' ");
	    
	    if(count($_POST['keytermid'])> 0){
    	   $i=0;
    	   foreach($_POST['keytermid'] as $kt){
    		    $keytermArray = array(
    		        "ordering" => $_POST["keyterms_order$i"],
    		        "description" => $_POST["keyterms_description$i"],
    		        );
 		    $flgUp = $db->updateAry("assignment_files", $keytermArray, "where id='".$_POST['keytermid'][$i]."' ");
 		    
    	       $i++;
    	   }
	    }

	    
	    if(count($_POST['mindmapid'])> 0){
    	   $i=0;
    	   foreach($_POST['mindmapid'] as $mm){
    		    $mindmapArray = array(
    		        "ordering" => $_POST["mindmap_order$i"],
    		        "description" => $_POST["mindmap_description$i"],
    		        );
 		    $flgUp = $db->updateAry("assignment_files", $mindmapArray, "where id='".$_POST['mindmapid'][$i]."' ");
    	       $i++;
    	   }
	    }
	    
	    if(count($_POST['keynotesid'])> 0){
    	   $i=0;
    	   foreach($_POST['keynotesid'] as $kn){
    		    $keynotesArray = array(
    		        "ordering" => $_POST["keynotes_order$i"],
    		        "description" => $_POST["keynotes_description$i"],
    		        );
 		    $flgUp = $db->updateAry("assignment_files", $keynotesArray, "where id='".$_POST['keynotesid'][$i]."' ");
    	       $i++;
    	   }
	    }
	    
	    if(count($_POST['practicalid'])> 0){
    	   $i=0;
    	   foreach($_POST['practicalid'] as $practical){
    		    $practicalArray = array(
    		        "ordering" => $_POST["practical_order$i"],
    		        "description" => $_POST["practical_description$i"],
    		        );
 		    $flgUp = $db->updateAry("assignment_files", $practicalArray, "where id='".$_POST['practicalid'][$i]."' ");
    	       $i++;
    	   }
	    }
	    
	    if(count($_POST['videosid'])> 0){
    	   $i=0;
    	   foreach($_POST['videosid'] as $video){
    		    $videosArray = array(
    		        "ordering" => $_POST["videos_order$i"],
    		        "description" => $_POST["videos_description$i"],
    		        );
 		    $flgUp = $db->updateAry("assignment_files", $videosArray, "where id='".$_POST['videosid'][$i]."' ");
    	       $i++;
    	   }
	    }

		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=="addmore" && isset($_GET['id']) && trim($_GET['id'])!='')
	{

	    $flgIn = $_GET['id'];

        $assignmentArray = array(
                "key_terms" => $_POST["keyterms_file"],
                "mind_map" => $_POST["mindmap_file"],
                "key_notes" => $_POST["keynotes_file"],
                "practical_projects" => $_POST["practical_file"],
                );
 	    $flgUp = $db->updateAry("assignment_new", $assignmentArray, "where id='".$_GET['id']."' ");	    
 	    
 	    
    	if(is_array($_POST["videolink"]) && count($_POST["videolink"])>0)
    	{
    		for($i=0; $i<count($_POST["videolink"]); $i++){
    			if(trim($_POST["videolink"][$i])!=""){
    			    $url_string=$_POST["videolink"][$i];
                    $url= str_replace('watch?v=','embed/', $url_string);
    			    $videodetail=$_POST["videodetail"][$i];
    				$insAry = array(
                    		        "assignment_id" => $flgIn,
    				                "name"=> $url,
                		            "type" => "youtube_link",
                		            "description" => $videodetail,
                		            "session" => $_SESSION["admin"]["session"]
                		            );
    				$db->insertAry("assignment_files",$insAry);
    			}
    		}
    	}

        if(isset($_FILES["key_terms"]["name"]) && !empty($_FILES["key_terms"]["name"])){
            $countfiles = count($_FILES["key_terms"]["name"]);
                $keyterms = array();
                for($i=0;$i<$countfiles;$i++){
            		$lfilename = basename($_FILES['key_terms']['name'][$i]);
            		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
            		$lnewfile=md5(microtime()).".".$lext;
            		if(move_uploaded_file($_FILES['key_terms']['tmp_name'][$i],"uploads/keyterms/".$lnewfile))
                		{
                		    $keytermArray = array(
                		        "assignment_id" => $flgIn,
                		        "name" => $lnewfile,
                		        "ordering" => $_POST["keyterms_order$i"],
                		        "description" => $_POST["keyterms_description$i"],
                		        "type" => "key_terms",
                		        "session" => $_SESSION["admin"]["session"]
                		        );
                		        $db->insertAry("assignment_files", $keytermArray);
                		}
                }
    	}
    	
    	
	    if(isset($_FILES["mind_map"]["name"]) && !empty($_FILES["mind_map"]["name"])){
            $countfiles = count($_FILES["mind_map"]["name"]);
                $mindmap = array();
                for($i=0;$i<$countfiles;$i++){
            		$lfilename = basename($_FILES['mind_map']['name'][$i]);
            		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
            		$lnewfile=md5(microtime()).".".$lext;
            		if(move_uploaded_file($_FILES['mind_map']['tmp_name'][$i],"uploads/mindmap/".$lnewfile))
                		{
                		    $mindmapArray = array(
                		        "assignment_id" => $flgIn,
                		        "name" => $lnewfile,
                		        "ordering" => $_POST["mindmap_order$i"],
                		        "description" => $_POST["mindmap_description$i"],
                		        "type" => "mind_map",
                		        "session" => $_SESSION["admin"]["session"]
                		        );
                		        $db->insertAry("assignment_files", $mindmapArray);
                		}
                }
    	}

        if(isset($_FILES["key_notes"]["name"]) && !empty($_FILES["key_notes"]["name"])){
            $countfiles = count($_FILES["key_notes"]["name"]);
                $keynotes = array();
                for($i=0;$i<$countfiles;$i++){
            		$lfilename = basename($_FILES['key_notes']['name'][$i]);
            		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
            		$lnewfile=md5(microtime()).".".$lext;
            		if(move_uploaded_file($_FILES['key_notes']['tmp_name'][$i],"uploads/keynotes/".$lnewfile))
                		{
                		    $keynotesArray = array(
                		        "assignment_id" => $flgIn,
                		        "name" => $lnewfile,
                		        "ordering" => $_POST["keynotes_order$i"],
                		        "description" => $_POST["keynotes_description$i"],
                		        "type" => "key_notes",
                		        "session" => $_SESSION["admin"]["session"]
                		        );
                		        $db->insertAry("assignment_files", $keynotesArray);
                		}
                }
    	}
    	
        if(isset($_FILES["videos"]["name"]) && !empty($_FILES["videos"]["name"])){
            $countfiles = count($_FILES["videos"]["name"]);
                $videos = array();
                for($i=0;$i<$countfiles;$i++){
            		$lfilename = basename($_FILES['videos']['name'][$i]);
            		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
            		$lnewfile=md5(microtime()).".".$lext;
            		if(move_uploaded_file($_FILES['videos']['tmp_name'][$i],"uploads/videos/".$lnewfile))
                		{
            		    $videosArray = array(
                		        "assignment_id" => $flgIn,
                		        "name" => $lnewfile,
                		        "type" => "videos",
                		        "ordering" => $_POST["videos_order$i"],
                		        "description" => $_POST["videos_description$i"],
                		        "session" => $_SESSION["admin"]["session"]
                		        );
                		        $db->insertAry("assignment_files", $videosArray);
                		}
                }
    	}
    	
        if(isset($_FILES["practical_projects"]["name"]) && !empty($_FILES["practical_projects"]["name"])){
            $countfiles = count($_FILES["practical_projects"]["name"]);
                $practicalprojects = array();
                for($i=0;$i<$countfiles;$i++){
            		$lfilename = basename($_FILES['practical_projects']['name'][$i]);
            		$lext = strtolower(substr($lfilename, strrpos($lfilename, '.')+1));
            		$lnewfile=md5(microtime()).".".$lext;
            		if(move_uploaded_file($_FILES['practical_projects']['tmp_name'][$i],"uploads/practicalprojects/".$lnewfile))
                		{
                		    $practicalArray = array(
                		        "assignment_id" => $flgIn,
                		        "name" => $lnewfile,
                		        "ordering" => $_POST["practical_order$i"],
                		        "description" => $_POST["practical_description$i"],
                		        "type" => "practical_projects",
                		        "session" => $_SESSION["admin"]["session"]
                		        );
                		        $db->insertAry("assignment_files", $practicalArray);
                		}
                }
    	}

$assgnmnt = $db->getRow("select * from assignment_new where id='".$_GET['id']."' ");

$subject = $db->getVal("select subject from subject_new where id='".$assgnmnt['parent_subject']."' and type='subject' ");
$chapter = $db->getVal("select subject from subject_new where id='".$assgnmnt['chapter']."' and type='chapter' ");

$session = $_SESSION['admin']['session'];
$class = $assgnmnt['class'];
$set_title = "Assignment Notice.";
$msg = "Dear Parents, A new assignment of $subject in chapter $chapter has been uploaded.";

// Enabling error reporting
error_reporting(-1);
ini_set('display_errors', 'On');

 $upOne = realpath(__DIR__ . '/..');

 $upOne2 = realpath(__DIR__ . '/..'.'api_new/firebase/push.php');

require_once  $upOne.'/api_new/firebase/firebase.php';
require_once  $upOne.'/api_new/firebase/push.php';

$firebase = new Firebase();
$push = new Push();

$tokenlist=$db->getRows("SELECT idno,name,fcm_token from student where class='$class' and session='$session' and status='1' ");

$result_arr = array();

foreach ($tokenlist as $value) {
        $stu_id =  $value['idno'];
        $target_user_name =  $value['name'];
        $fb_token =  $value['fcm_token'];

        if (strlen($fb_token) > 0 ) {
            // optional payload
            $payload = array();
            $payload['name'] = $target_user_name;
            $payload['msg'] = $msg; // whether to include to image or not
            $payload['stu_id'] = $stu_id;
            $include_image = TRUE;
            $push->setTitle($set_title);
            $push->setMessage($msg);
            if ($include_image) {
                $push->setImage('https://api.androidhive.info/images/minion.jpg');
            } else {
                $push->setImage('');
            }
            $push->setIsBackground(FALSE);
            $push->setPayload($payload);
            $json = '';
            $response = '';
            $json = $push->getPush();
       
            $response = $firebase->send($fb_token, $json);
            
            array_push($result_arr,$response);
            
        }
}

		redirect(URL_ADMIN_HOME.getQueryString(array("src"=>"Notice", "page_id"=>$pgMod)));



	}
	
 		
}

elseif($pgAct=="delete" && isset($_GET['id']) && trim($_GET['id'])!='')
{
    $files = $db->getRows("select * from assignment_files where assignment_id='".$_GET['id']."' and session='".$_SESSION["admin"]["session"]."'");
    if(count($files)>0){
        foreach($files as $file){
                $img = $file['name'];
                $type = $file['type'];
                
                if($type == "key_terms"){
                    unlink("uploads/keyterms/$img");
                }
                
                if($type == "mind_map"){
                    unlink("uploads/mindmap/$img");
                }
            
                if($type == "key_notes"){
                    unlink("uploads/keynotes/$img");
                }
                
                if($type == "practical_projects"){
                    unlink("uploads/practicalprojects/$img");
                }
                
                if($type == "videos"){
                    unlink("uploads/videos/$img");
                }
                
        }
    }
 	$res=$db->delete("assignment_new","where session='".$_SESSION["admin"]["session"]."' and id='".$_GET['id']."' ");
 	$res=$db->delete("assignment_files","where session='".$_SESSION["admin"]["session"]."' and assignment_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></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></b> <?php echo $alert_err[0] ?></i>
</div>
<?php

}


if(($pgAct=="edit" && $_GET["id"]!="") || ($pgAct=="addmore" && $_GET["id"]!=""))
{
	$aryForm=$db->getRow("SELECT * FROM assignment_new WHERE id='".$_GET['id']."'");
	
	$assignmentData=$db->getRows("SELECT * FROM assignment_files WHERE assignment_id='".$_GET['id']."' order by ordering ASC ");

}

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

	$aryPgAct=array("src"=>"Notice", "page_id"=>$pgMod,"action"=>"add");
    
?>

    <!--<form method="get" action="">-->
    <input type="hidden" name="src" value="Notice" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
<div class="row-fluid">
            <div class="span12">
            <div class="top-bar">
<h3><i class="icon-cog"></i>Add Assignment</h3>
<div>

</div>
</div>
<div class="well no-padding"  id="printDiv2">
<div class="controls controls-row">

<div style="padding:20px;">
  <form method="post" action="" enctype="multipart/form-data" >
    
    <div class="control-group">
    <label class="control-label">Select Class</label>
      <div  class="controls">
      <select name="class" id="class" style="width:100%;" onchange="filterSubject()">
      <option value="">--Select Class--</option>
      <?php $allClasses = $db->getRows("select * from class where school_id=1 and added_by=1 and status=1");
            foreach($allClasses as $class){
                ?>
                <option <?php if($class["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $class['class']; ?>"><?php echo $class['class']; ?></option>
                <?php
                }
            ?>
        </select>
      </div>
      </div>
      
    <div class="control-group">
    <label class="control-label">Subject</label>
      <div  class="controls" id="parent_subject">
        <select id="mySelect1" name="parent_subject" style="width:100%;"  onchange="changeSubject()">
            <option value="">--Select Subject--</option>
          <?php $allSubjects = $db->getRows("select * from subject_new where class='$aryForm[class]' and session='".$_SESSION["admin"]["session"]."' and type='subject' order by id ASC ");
                foreach($allSubjects as $sub){
                ?>
                <option <?php if($sub["id"]==$aryForm["parent_subject"])echo 'selected';?> value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                <?php
                }
            ?>
        </select>
      </div>
    </div>
    
    <div class="control-group">
    <label class="control-label">Sub - Subject</label>
      <div  class="controls" id="sub_subject">
     <select name="sub_subject" style="width:100%;" id="subSubjectid" onchange="filterChapter()">
            <option value="">--Select sub-Subject--</option>
            <?php $allsubSubjects = $db->getRows("select * from subject_new where parent_subject='".$aryForm["parent_subject"]."' and session='".$_SESSION["admin"]["session"]."' and type='sub_subject'  order by id ASC");
            foreach($allsubSubjects as $sub){
                ?>
                <option <?php if($sub["id"]==$aryForm["sub_subject"])echo 'selected'; ?> value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                <?php
                }
            ?>
        </select>
      </div>
    </div>
    
    <div class="control-group">
    <label class="control-label">Chapter</label>
      <div  class="controls" id="chapter_div">
        <select id="chapter" name="chapter" style="width:100%">
            <option value="">--Select Chapter--</option>
            <?php $allChapters = $db->getRows("select * from subject_new where sub_subject='".$aryForm["sub_subject"]."' and session='".$_SESSION["admin"]["session"]."' and type='chapter'  order by id ASC ");
            foreach($allChapters as $chapter){
                ?>
                <option <?php if($chapter["id"]==$aryForm["chapter"])echo 'selected'; ?> value="<?php echo $chapter['id']; ?>"><?php echo $chapter['subject']; ?></option>
                <?php
                }
            ?>            
        </select>
      </div>
    </div>
    
    <div class="control-group">
    <label class="control-label">Key Terms</label>
      <div  class="controls">
          <?php if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
            echo "<div style='min-height:30px;' />";
            $i = 0;
              foreach($assignmentData as $kt){ 
              if($kt['type']=="key_terms"){
                  $aryPgAct["id"]=$kt['id'];
                  ?>
                      <div style="width:250px;display:inline-block;margin:10px;border:solid 2px red;">
                          <input type="hidden" name="keytermid[]"  value="<?php echo $kt['id']; ?>">
                          <embed src="../uploads/keyterms/<?php echo $kt['name']; ?>" style="width:250px;height:100px;"><br>
                          <input type="number" value="<?php echo $kt['ordering']; ?>" style="width:50px;height:40px;border:solid 2px green;" min="1" name="keyterms_order<?php echo $i; ?>" />
                          <textarea style="width:155px;border:solid 2px blue;" name="keyterms_description<?php echo $i; ?>"><?php echo $kt['description'];?></textarea>
                          <a href='../uploads/keyterms/<?php echo $kt['name']; ?>' style='color:blue;' download><button type="button" class="btn" style="background:green;color:white;width:120px;">Download</button></a>
                          <a href="javascript:;" onclick="delete_file('<?php echo $kt['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:120px;">Delete</button></a>   
                      </div>
                  <?php
                 }$i++;
              }
              echo "</div>";
          } else {
              $countkeyterms = $db->getVal("select count(id) from assignment_files where assignment_id='".$_GET['id']."' and type='key_terms' ");
              //echo $countkeyterms;
          ?>
          <div style="margin-top:20px;width:100%;">
              <input type="file" name="key_terms[]" onchange="preview_keyterms('<?php echo $countkeyterms; ?>')" id="upload_keyterms" multiple/><br>
              <input type="radio" value="image" name="keyterms_file" checked <?php if($aryForm['key_terms']=='image' && $countkeyterms>0)echo "checked=checked"; if($countkeyterms>0){echo 'onclick="javascript: return false;"'; } ?>  > Image
              <input type="radio" value="pdf" name="keyterms_file" <?php if($aryForm['key_terms']=='pdf' && $countkeyterms>0)echo "checked=checked"; if($countkeyterms>0){echo 'onclick="javascript: return false;"'; } ?>  > Pdf <br>
              <?php if($countkeyterms>0)echo "<span style='color:red;font-size:10px;'>You can't change file type.</span>" ; ?>
          </div>
            <div id="keyterms_preview" style="display:inline-block;"></div>
        <?php } ?>          
        </div>
    </div>
    
    <div class="control-group">
    <label class="control-label">Mind Map</label>
      <div  class="controls">
          <?php if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
            echo "<div style='min-height:30px;' />";
            $i = 0;
              foreach($assignmentData as $mindmap){
              if($mindmap['type']=="mind_map"){
                  ?>
                      <div style="width:250px;display:inline-block;margin:10px;border:solid 2px red;">
                        <input type="hidden" name="mindmapid[]"  value="<?php echo $mindmap['id']; ?>">
                         <embed src="../uploads/mindmap/<?php echo $mindmap['name']; ?>" style="width:250px;height:100px;"><br>
                         <input type="number" value="<?php echo $mindmap['ordering']; ?>" style="width:50px;height:40px;border:solid 2px green;" min="1" name="mindmap_order<?php echo $i; ?>" />
                          <textarea style="width:155px;border:solid 2px blue;" name="mindmap_description<?php echo $i; ?>"><?php echo $mindmap['description'];?></textarea><br>
                          <a href='../uploads/mindmap/<?php echo $mindmap['name']; ?>' style='color:blue;' download><button type="button" class="btn" style="background:green;color:white;width:120px">Download</button></a>
                        
                            <a href="javascript:;" onclick="delete_file('<?php echo $mindmap['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:120px;">Delete</button></a>
                    </div>
                  <?php $i++;
                 } 
              }
              echo "</div>";
          } else {
        $countmindmap = $db->getVal("select count(id) from assignment_files where assignment_id='".$_GET['id']."' and type='mind_map' ");
          ?>
          <div style="margin-top:20px;width:100%;">
          <input type="file" name="mind_map[]" onchange="preview_mindmap('<?php echo $countmindmap; ?>')" id="upload_mindmap" multiple/><br>
              <input type="radio" value="image" name="mindmap_file" checked <?php if($aryForm['mind_map']=='image')echo "checked=checked"; if($countmindmap>0){echo 'onclick="javascript: return false;"'; }?>> Image
              <input type="radio" value="pdf" name="mindmap_file" <?php if($aryForm['mind_map']=='pdf')echo "checked=checked"; if($countmindmap>0){echo 'onclick="javascript: return false;"'; }?>> Pdf <br>
              <?php if($countmindmap>0)echo "<span style='color:red;font-size:10px;'>You can't change file type.</span>" ; ?>
          </div>
         <div id="mindmap_preview" style="display:inline-block;"></div>
      <?php } ?>
      </div>
    </div>
    
    <div class="control-group">
    <label class="control-label">Key Notes</label>
      <div  class="controls">
          <?php if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
            echo "<div style='min-height:30px;' />";
            $i = 0;
              foreach($assignmentData as $kn){
              if($kn['type']=="key_notes"){
                  ?>
                      <div style="width:250px;display:inline-block;margin:10px;border:solid 2px red;">
                        <input type="hidden" name="keynotesid[]"  value="<?php echo $kn['id']; ?>">
                          <embed src="../uploads/keynotes/<?php echo $kn['name']; ?>" style="width:250px;height:100px;">
                          <input type="number" value="<?php echo $kn['ordering']; ?>" style="width:50px;height:40px;border:solid 2px green;" min="1" name="keynotes_order<?php echo $i; ?>" />
                          <textarea style="width:155px;border:solid 2px blue;" name="keynotes_description<?php echo $i; ?>" ><?php echo $kn['description'];?></textarea>
                          <a href='../uploads/keynotes/<?php echo $kn['name']; ?>' style='color:blue;' download><button type="button" class="btn" style="background:green;color:white;width:120px">Download</button></a>
                            <a href="javascript:;" onclick="delete_file('<?php echo $kn['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:120px;">Delete</button></a>
                  </div>
                  <?php $i++;
                 } 
              }
              echo "</div>";
          } else {
              $countkeynotes = $db->getVal("select count(id) from assignment_files where assignment_id='".$_GET['id']."' and type='key_notes'  ");
          ?>
          <div style="margin-top:20px;width:100%;">
          <input type="file" name="key_notes[]" onchange="preview_keynotes('<?php echo $countkeynotes; ?>')" id="upload_keynotes" multiple/><br>
              <input type="radio" value="image" name="keynotes_file" checked <?php if($aryForm['key_notes']=='image'){echo "checked=checked";} if($countkeynotes>0){echo 'onclick="javascript: return false;"'; }?> > Image
              <input type="radio" value="pdf" name="keynotes_file" <?php if($aryForm['key_notes']=='pdf'){echo "checked=checked";} if($countkeynotes>0){echo 'onclick="javascript: return false;"'; } ?> > Pdf <br>
              <?php if($countkeynotes>0)echo "<span style='color:red;font-size:10px;'>You can't change file type.</span>" ; ?>
        </div>
       <div id="keynotes_preview" style="display:inline-block;"></div>
        <?php } ?>
      </div>
    </div>
    
    <div class="control-group">
    <label class="control-label">Practical & <br>Projects</label>
      <div  class="controls">
          <?php if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
              echo "<div style='min-height:30px;' />";
            $i = 0;
              foreach($assignmentData as $practical){
              if($practical['type']=="practical_projects"){
                  ?>
                      <div style="width:250px;display:inline-block;margin:10px;border:solid 2px red;">
                        <input type="hidden" name="practicalid[]"  value="<?php echo $practical['id']; ?>">
                          <embed src="../uploads/practicalprojects/<?php echo $practical['name']; ?>" style="width:250px;height:100px;">
                          <input type="number" value="<?php echo $practical['ordering']; ?>" style="width:50px;height:40px;border:solid 2px green;" min="1" name="practical_order<?php echo $i; ?>" />
                          <textarea style="width:155px;border:solid 2px blue;" name="practical_description<?php echo $i; ?>" ><?php echo $practical['description'];?></textarea>
                          <a href='../uploads/practicalprojects/<?php echo $practical['name']; ?>' style='color:blue;' download><button type="button" class="btn" style="background:green;color:white;width:120px;">Download</button></a>
                            <a href="javascript:;" onclick="delete_file('<?php echo $practical['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:120px;">Delete</button></a>
                      </div>
                  <?php $i++;
                 }
              }
              echo "</div>";
          } else {
              $countpractical = $db->getVal("select count(id) from assignment_files where assignment_id='".$_GET['id']."' and type='practical_projects' ");
          ?>
          <div style="margin-top:20px;width:100%;">
              <input type="file" name="practical_projects[]" onchange="preview_practical('<?php echo $countpractical; ?>')" id="upload_practical" multiple/><br>
              <input type="radio" value="image" name="practical_file" checked <?php if($aryForm['practical_projects']=='image')echo "checked=checked"; if($countpractical>0){echo 'onclick="javascript: return false;"'; } ?>> Image
              <input type="radio" value="pdf" name="practical_file" <?php if($aryForm['practical_projects']=='pdf')echo "checked=checked"; if($countpractical>0){echo 'onclick="javascript: return false;"'; }?> > Pdf <br>
              <?php if($countpractical>0)echo "<span style='color:red;font-size:10px;'>You can't change file type.</span>" ; ?>
          </div>
           <div id="practical_preview" style="display:inline-block;"></div>
          <?php } ?>
      </div>
    </div>

    <div class="control-group">
    <label class="control-label">Videos</label>
      <div  class="controls"> 
          <?php if($pgAct=="edit" && isset($_GET['id']) && trim($_GET['id']) !=''){
            echo "<div style='min-height:30px;' />";
            $i = 0;
              foreach($assignmentData as $videos){
              if($videos['type']=="videos"){
                  ?> 
                      <div style="width:250px;display:inline-block;margin:10px;border:solid 2px red;">
                        <input type="hidden" name="videosid[]" value="<?php echo $videos['id']; ?>">
                        <video width="250" height="140" controls>
                          <source src="../uploads/videos/<?php echo $videos['name']; ?>">
                        </video>
                          <input type="number" value="<?php echo $videos['ordering']; ?>" style="width:50px;height:40px;border:solid 2px green;" min="1" name="videos_order<?php echo $i; ?>" />
                          <textarea style="width:155px;border:solid 2px blue;" name="videos_description<?php echo $i; ?>"><?php echo $videos['description'];?></textarea>
                          <a href='../uploads/videos/<?php echo $videos['name']; ?>' style='color:blue;' download><button type="button" class="btn" style="background:green;color:white;width:120px;">Download</button></a>
                            <a href="javascript:;" onclick="delete_file('<?php echo $videos['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:120px;">Delete</button></a>
                      </div>
                  <?php $i++;
                 }
              }
            echo "<label>YouTube Videos</label>";
            foreach($assignmentData as $videos){
              if($videos['type']=="youtube_link"){
                  ?> 
                      <div style="width:250px;display:inline-block;margin:10px;border:solid 2px red;">
                        <input type="hidden" name="videosid[]" value="<?php echo $videos['id']; ?>">
                        <iframe width="250" height="140" src="<?php echo $videos['name']; ?>" frameborder="0" allowfullscreen>
                        </iframe>
                          <!--<a href='../uploads/videos/<?php echo $videos['name']; ?>' style='color:blue;' download><button type="button" class="btn" style="background:green;color:white;width:120px;">Download</button></a>-->
                            <textarea style="width:225px;border:solid 2px blue;" name="videos_description<?php echo $i; ?>"><?php echo $videos['description'];?></textarea>
                            <a href="javascript:;" onclick="delete_file('<?php echo $videos['id']; ?>')" class="confirmation"><button type="button" class="btn btn-danger" style="width:120px;">Delete</button></a>
                            
                      </div>
                  <?php $i++;
                 }
              }
              echo "</div>";
          } else {
              $countvideos = $db->getVal("select count(id) from assignment_files where assignment_id='".$_GET['id']."' and type='videos' ");
          ?>
          <div style="margin-top:20px;width:100%;">
              <input type="file" name="videos[]" onchange="preview_videos('<?php echo $countvideos; ?>')" id="upload_videos" multiple/>
          </div>
           <div id="videos_preview" style="display:inline-block;"></div>

            <table  class="table">
            <tr><td colspan="3" style="color:black;">Video Link:</td></tr>
              <tfoot>
                <tr>
                  <td colspan="2"><a id="Addlink" href="javascript:;">
                    <button type="button" class="btn btn-info">Add Other</button>
                    </a>
                  </td>
                </tr>
              </tfoot>
              <tbody id="tbodylink">
                <tr>
                  <td>(1)</td>
                  <td><input type="text" placeholder="Enter url" class="input-block-level" name="videolink[]"></td>
                  <td><textarea name="videodetail[]" placeholder="Video Description"></textarea></td>
                </tr>                  
              </tbody>
              </table>
      <?php } ?>
      </div> 
    </div>



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

        </div>
        <br>
</div>
<!-- / Forms: Content -->
</div>
    </div>

<?php

    
}
else {
    
	?>
	<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=Notice&page_id=<?php echo $pgMod; ?>&action=add'" class="btn" type="button">Add Assignment</button>
    </div>
    <div class="well no-padding">
  
    <div style="z-index: 99999;margin: 30px;">

        <table>
            <tr>
                <td>
                    <label class="control-label">Select Class</label>
                    <select name="class" id="class" style="width:100%;" onchange="filterSubject()">
                      <option value="">--Select Class--</option>
                      <?php $allClasses = $db->getRows("select * from class where school_id=1 and added_by=1 and status=1");
                        foreach($allClasses as $class){
                            ?>
                            <option <?php if($class["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $class['class']; ?>"><?php echo $class['class']; ?></option>
                            <?php
                            }
                        ?>
                    </select>
                </td>
                <td>
                    <label class="control-label">Subject</label>
                                        <div  class="controls" id="parent_subject">

                    <select id="mySelect1" name="parent_subject" style="width:100%;"  onchange="changeSubject()">
                        <option value="">--Select Subject--</option>
                      <?php $allSubjects = $db->getRows("select * from subject_new where class='$aryForm[class]' and session='".$_SESSION["admin"]["session"]."' and type='subject' order by id ASC ");
                            foreach($allSubjects as $sub){
                            ?>
                            <option <?php if($sub["id"]==$aryForm["parent_subject"])echo 'selected';?> value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                            <?php
                            }
                        ?>
                    </select>  
                    </div>
                </td>
                <td>
                    <label class="control-label">Sub - Subject</label>
                          <div  class="controls" id="sub_subject">

                    <select name="sub_subject" style="width:100%;" id="subSubjectid" onchange="filterChapter()">
                        <option value="">--Select sub-Subject--</option>
                        <?php $allsubSubjects = $db->getRows("select * from subject_new where parent_subject='".$aryForm["parent_subject"]."' and session='".$_SESSION["admin"]["session"]."' and type='sub_subject'  order by id ASC");
                        foreach($allsubSubjects as $sub){
                            ?>
                            <option <?php if($sub["id"]==$aryForm["sub_subject"])echo 'selected'; ?> value="<?php echo $sub['id']; ?>"><?php echo $sub['subject']; ?></option>
                            <?php
                            }
                        ?>
                    </select>
                    </div>
                </td>
                <td>
                    <label class="control-label">Chapter</label>
                          <div  class="controls" id="chapter_div">

                    <select id="chapter" name="chapter" style="width:100%">
                        <option value="">--Select Chapter--</option>
                        <?php $allChapters = $db->getRows("select * from subject_new where sub_subject='".$aryForm["sub_subject"]."' and session='".$_SESSION["admin"]["session"]."' and type='chapter'  order by id ASC ");
                        foreach($allChapters as $chapter){
                            ?>
                            <option <?php if($chapter["id"]==$aryForm["chapter"])echo 'selected'; ?> value="<?php echo $chapter['id']; ?>"><?php echo $chapter['subject']; ?></option>
                            <?php
                            }
                        ?>            
                    </select>
                    </div>
                </td>
                <td>
                    <label></label>
                    <button class="btn" style="margin-top:20px;font-size:15px;padding:3px 8px;" onclick="filterRecord()">Search</button>
                </td>
            </tr>
        </table>

    </div>
    
    <div id="filterdata">
            
	<?php
	$aryPgAct=array("src"=>"Notice", "page_id"=>$pgMod,"action"=>"add");
	$aryList=$db->getRows("SELECT * FROM assignment_new  "); 
	    $i = 0;
	if(is_array($aryList) && count($aryList)>0)
	{
		?>
        <table class="table" id="example"> 
            <thead>
                <tr>
                    <th style="width:50px;">S.No.</th>
                    <th>Class</th>
                    <th>Subject</th>
                    <th>Sub-subjects</th>
                    <th>Chapters</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 $clist["class"]; ?></td>
                    <td><?php echo $subject = $db->getVal("select subject from subject_new where id = '".$clist["parent_subject"]."' and type='subject' ") ?></td>
                    <td><?php echo $sub_subject = $db->getVal("select subject from subject_new where id = '".$clist["sub_subject"]."' and type='sub_subject' ") ?></td>
                    <td><?php echo $chapter = $db->getVal("select subject from subject_new where id = '".$clist["chapter"]."' and type='chapter' ") ?></td>
                    <td>
                    <?php $aryPgAct['action']="addmore"; ?>
                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-primary">Add More</button></a>
                    <?php $aryPgAct['action']="edit"; ?>
                     <a style="float:left" href="<?php echo URL_ADMIN_HOME.getQueryString($aryPgAct); ?>"><button type="button" class="btn btn-info">Edit</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 colspan="3"></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>Notice</b> Record not found </i>
        </div>
        <?php
	}
	?>
	</div>
	
	</div></div></div>
	<?php

}
?>
    
    <!--</form>-->


<style type="text/css">
@media print {
    #myPrntbtn {
        display :  none;
    }
}

@media screen {
   #myPrntbtn1 {
        display: none;
    }
}
</style>

<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"bAutoWidth": false
		});
	});

	</script>
	
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>


<script>
function filterSubject(){
   	var classname = document.getElementById("class").value;
    $.post( "Notice/ajax.php", { type: "filter_subject" ,classname: classname } , function( data ) {
        document.getElementById("parent_subject").innerHTML = data;
	});

}

function changeSubject(){
    var subject = document.getElementById("mySelect1").value;
    $.post( "Notice/ajax.php", { type: "filterSubSubject" ,subject: subject } , function( data ) {
        document.getElementById("sub_subject").innerHTML = data;
	});
    
}

function filterChapter(){
    var subject = document.getElementById("subSubjectid").value;
    $.post( "Notice/ajax.php", { type: "filterChapter" ,subject: subject } , function( data ) {
        document.getElementById("chapter_div").innerHTML = data;
	});
	
}

function delete_file(id){
  var r = confirm("Are you sure want to delete?");
  if (r == true) {
    $.post( "Notice/ajax.php", { type: "delete_file" , id: id } , function( data ) {
        location.reload();
//        alert(data);
	});
  }

}
 

function preview_keyterms(n)
{
document.getElementById('keyterms_preview').innerHTML = '';
var total_file=document.getElementById("upload_keyterms").files.length;
    
var filetype = $("input:radio[name=keyterms_file]:checked").val()

var bool = true;
if(filetype=='image'){
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_keyterms").files[i];
        if(!file.type.match('image.*')){
            document.getElementById("upload_keyterms").value = "";
            alert('Please select Image file to upload.');
            bool= false;
            break;
        }
   }
}
else if(filetype=='pdf') {
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_keyterms").files[i];
        if(!file.type.match('application/pdf')){
            document.getElementById("upload_keyterms").value = "";
            alert('Please select PDF file to upload.');
            bool= false;
            break;
        }
   }
}
if(bool){
 var j =1;
 if(n>0){
     var num  = (parseInt(n)+1);
     for(var i=0;i<total_file;i++)
     {
      $('#keyterms_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+num+"' name='keyterms_order"+i+"'><textarea placeholder='Description' name='keyterms_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      num++;
     }
 }
 else {
     for(var i=0;i<total_file;i++)
     {
      $('#keyterms_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+j+"' name='keyterms_order"+i+"'><textarea placeholder='Description' name='keyterms_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      j++;
     }
 }
}
}

function preview_mindmap(n)
{
document.getElementById('mindmap_preview').innerHTML = '';
var total_file=document.getElementById("upload_mindmap").files.length;

var filetype = $("input:radio[name=mindmap_file]:checked").val()

var bool = true;
if(filetype=='image'){
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_mindmap").files[i];
        if(!file.type.match('image.*')){
            document.getElementById("upload_mindmap").value = "";
            alert('Please select image file to upload.');
            bool= false;
            break;
        }
   }
}
else if(filetype=='pdf') {
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_mindmap").files[i];
        if(!file.type.match('application/pdf')){
            document.getElementById("upload_mindmap").value = "";
            alert('Please select PDF file to upload.');
            bool= false;            
            break;
        }
   }
}
if(bool){
var j =1;
 if(n>0){
     var num  = (parseInt(n)+1);
     for(var i=0;i<total_file;i++)
     {
      $('#mindmap_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+num+"' name='mindmap_order"+i+"'><textarea placeholder='Description' name='mindmap_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      num++;         
     }
 }
 else {
     for(var i=0;i<total_file;i++)
     {
      $('#mindmap_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+j+"' name='mindmap_order"+i+"'><textarea placeholder='Description' name='mindmap_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      j++;
     }
    }
 }
}

function preview_keynotes(n) 
{
document.getElementById('keynotes_preview').innerHTML = '';    
 var total_file=document.getElementById("upload_keynotes").files.length;
 var filetype = $("input:radio[name=keynotes_file]:checked").val()

var bool = true;
if(filetype=='image'){
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_keynotes").files[i];
        if(!file.type.match('image.*')){
            document.getElementById("upload_keynotes").value = "";
            alert('Please select image file to upload.');
            bool= false;
            break;
        }
   }
}
else if(filetype=='pdf') {
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_keynotes").files[i];
        if(!file.type.match('application/pdf')){
            document.getElementById("upload_keynotes").value = "";
            alert('Please select PDF file to upload.');
            bool= false;            
            break;
        }
   }
}
if(bool){
var j =1;
 if(n>0){
     var num  = (parseInt(n)+1);
     for(var i=0;i<total_file;i++)
     {
      $('#keynotes_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+num+"' name='keynotes_order"+i+"'><textarea placeholder='Description' name='keynotes_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      num++;
     }
 }
else {
 for(var i=0;i<total_file;i++)
 {
  $('#keynotes_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+j+"' name='keynotes_order"+i+"'><textarea placeholder='Description' name='keynotes_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
  j++;
  }
 }
}
}

function preview_practical(n) 
{
document.getElementById('practical_preview').innerHTML = '';
var total_file=document.getElementById("upload_practical").files.length;
var filetype = $("input:radio[name=practical_file]:checked").val()

var bool = true;
if(filetype=='image'){
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_practical").files[i];
        if(!file.type.match('image.*')){
            document.getElementById("upload_practical").value = "";
            alert('Please select image file to upload.');
            bool= false;
            break;
        }
   }
}
else if(filetype=='pdf') {
   for(var i=0;i<total_file;i++){
       var file =document.getElementById("upload_practical").files[i];
        if(!file.type.match('application/pdf')){
            document.getElementById("upload_practical").value = "";
            alert('Please select PDF file to upload.');
            bool= false;            
            break;
        }
   }
}
if(bool){ 
var j =1;
 if(n>0){
     var num  = (parseInt(n)+1);
     for(var i=0;i<total_file;i++)
     {
       $('#practical_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+num+"' name='practical_order"+i+"'><textarea placeholder='Description' name='practical_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      num++;
     }
 }
else {
 for(var i=0;i<total_file;i++)
 {
  $('#practical_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><embed src='"+URL.createObjectURL(event.target.files[i])+"' style='width:250px;height:100px;'><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+j+"' name='practical_order"+i+"'><textarea placeholder='Description' name='practical_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
  j++;
 }
}
}
}

function preview_videos(n) 
{
 document.getElementById('videos_preview').innerHTML = '';    
 var total_file=document.getElementById("upload_videos").files.length;
 var j =1;
  if(n>0){
     var num  = (parseInt(n)+1);
     for(var i=0;i<total_file;i++)
     {
      $('#videos_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><video style='width:250px;height:100px;'><source src='"+URL.createObjectURL(event.target.files[i])+"'></video><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+num+"' name='videos_order"+i+"'><textarea placeholder='Description' name='videos_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
      num++;   
     }
  }
  else {
 for(var i=0;i<total_file;i++)
 {
  $('#videos_preview').append("<div style='display:inline-block;width:250px;margin:10px;border:solid 2px red;'><video style='width:250px;height:100px;'><source src='"+URL.createObjectURL(event.target.files[i])+"'></video><br><input type='number' style='width:50px;height:40px;border:solid 2px green;' placeholder='No.' min='1' value='"+j+"' name='videos_order"+i+"'><textarea placeholder='Description' name='videos_description"+i+"' style='width:160px;border:solid 2px blue;'></textarea></div>");
  j++;
 }
}
}


function filterRecord(){
 
 var classname = document.getElementById("class").value;
 var subject = document.getElementById("mySelect1").value;
 var subsubject = document.getElementById("subSubjectid").value;  
 var chapter = document.getElementById("chapter").value;   

    $.post( "Notice/ajax.php", { type: "filterRecord" ,classname: classname ,subject: subject ,subsubject: subsubject , chapter: chapter} , function( data ) {
//alert(data);
  document.getElementById('filterdata').innerHTML = data;
    });
}

	//$(document).ready(function() {
    //$('#example').DataTable();
//} );


	$("#Addlink").click(function(){
		var rowCount = ($('#tbodylink tr').length)+1;
		var add_tr_skill='<tr><td>('+rowCount+')</td><td><input class="input-block-level" type="text" placeholder="Enter url" name="videolink[]"></td><td><textarea name="videodetail[]" placeholder="Video Description"></textarea></td><td><a class="delete" href="javascript:;"><button type="button" class="btn btn-info">Remove</button></a></td></tr>';
		$("#tbodylink").append($(add_tr_skill));
		$('#tbodylink td a.delete').click(function() { 
			$(this).parent().parent().remove(); 
		});	
	});


// function validateForm() {
//   var sclass = document.forms["myForm"]["class"].value;
//   var parent_subject = document.forms["myForm"]["parent_subject"].value;
//   var sub_subject = document.forms["myForm"]["sub_subject"].value;
//   var chapter = document.forms["myForm"]["chapter"].value;
  
//     alert("select * from assignment_new where class='".sclass."' and parent_subject='".parent_subject."' and sub_subject='".sub_subject."' and chapter='".chapter."' ");  
// //   alert(sclass);
// //   alert(parent_subject);
// //   alert(sub_subject);
// //   alert(chapter);
// //   if (x == "") {
// //     alert("Name must be filled out");
//     return false;
// //   }
// }

</script>
