<?php


class UIclass{

	public function sendMail($email, $email_content, $subject){
	    global $db, $request, $mail; 
        console(LOG_LEVEL_INFO, "sendmail function arguments123 ::".$email."/".$subject);
		
		$mail->CharSet     = EMAIL_CONFIG_CHARSET; 
		$mail->IsSMTP();                                            // set mailer to use SMTP
		$mail->Host          = EMAIL_CONFIG_HOST;         // specify main and backup server
		$mail->SMTPAuth  = EMAIL_CONFIG_SMTPAUTH;  // turn on SMTP authentication
		$mail->Username   = EMAIL_CONFIG_USERNAME;  // SMTP username
		$mail->Password   = EMAIL_CONFIG_PASSWORD; // SMTP password
		$mail->From         = EMAIL_CONFIG_FROM;
		$mail->FromName  = EMAIL_CONFIG_NAME;
		
       console(LOG_LEVEL_INFO, "mailfunction config ::HOST=>".$mail->Host." / SMTPAuth=>".$mail->SMTPAuth." / Username=>".$mail->Username." / Password=>".$mail->Password." / From=>".$mail->From." / FromName =>".$mail->FromName);
		$mail->IsHTML(true); 

		$to = $email;
      
		$body             = $email_content.$regards;	
		$mail->Subject = $subject;			
		$mail->Body     = $body;
		$mail->AddAddress($to);
		
		$mailids = explode(',',EMAIL_CONFIG_CC);
		console.log(LOG_LEVEL_INFO, "CC mailid :: ".EMAIL_CONFIG_CC); 
		foreach($mailids as $key){
			$mail->AddCC($key);
		}
		console(LOG_LEVEL_INFO, "mailfunction config ::EMAIL_SUBJECT=>".$mail->Subject);
		
		//console(LOG_LEVEL_INFO, "send status ".$this->Send());
		
		if($mail->Send()){
			console(LOG_LEVEL_INFO,"Mail Successfully Sent To :: $email");
			return "Successfully sent";
		}else {
			console(LOG_LEVEL_INFO,"Error in mail Send To :: $email");
		}
		
	}
	public function checkOTP(){
		global $db, $request;
		
		$msisdn=$_SESSION['msisdn'];
		if(strlen($_SESSION['msisdn'])<12) $msisdn='91'.$_SESSION['msisdn'];
		$query = "SELECT id, otp FROM otp_auth where otp='".$request['otp']."' AND msisdn='".$msisdn."' AND status= 'active'";
		
		$result = $db['slave']->getOneRow($query);
		if($result["otp"]!=''){	
				/*$query = "UPDATE register SET status = 'active' WHERE	emailid='".$_SESSION['email']."' AND mobilenumber ='".$msisdn."' " ;
				$db['master']->query($query);*/
				$db['master']->query("UPDATE otp_auth SET status= 'used', usedtime=NOW() WHERE id = ". $result['id']);	
			return "successs";
		}else{
			return "failed";
		}  	
	}
	
	
public function checkOTPmail(){
		global $db, $request;
		
			$emailid=$_SESSION['emailid'];
		
		$query = "SELECT id, otp FROM otp_auth where otp='".$request['otp']."' AND emailid='".$emailid."' AND status= 'active'";
		$result = $db['master']->getOneRow($query);
		if($result["otp"]!=''){	
				/*$query = "UPDATE register SET status = 'active' WHERE	emailid='".$_SESSION['emailid']."'  " ;
				$db['master']->query($query);*/
				$db['master']->query("UPDATE otp_auth SET status= 'used', usedtime=NOW() WHERE id = ". $result['id']);	
			return "successs";
		}else{
			return "failed";
		}  
}

	
	public function showQuesTypes(){
		global $db,$request;

		$query = "SELECT qtypeid,qtype FROM qtypes where status='active' order by qtype";
		$qtypes = $db['master']->getResults($query);
	
		foreach ( $qtypes as $values ){		
			if ( $request['qtypeid'] == $values['qtypeid'] ){
				$qtypelist .= "<option value='" . $values ['qtypeid'] . "' selected>" . $values ['qtype'] ."</option>";
			}else{
				$qtypelist .= "<option value='" . $values ['qtypeid'] . "' >" . $values ['qtype'] ."</option>";
			}	
			
		}
		return $qtypelist;
	}
	
	public function AddTemplate5($pagename=''){
		global $db,$request;
		$tabidexists = $request['tabidval'];
		if($request['header'] != "" && $request['hiddencount'] == ""){  
			$insq = "INSERT INTO tabs(`tabheader`,`main_content`,`qid`,`linetype`) VALUES('".(($request['tabheader']))."','".(($request['header']))."','".$request["tabidval"]."','".$request['maintablinetype']."')";
			$result = $db['master']->query($insq);
			$tabid = $db['master']->getLastID();
			if($result!= "" && $tabidexists == ""){
				if($request["id"]!='' && $pagename == 'listview'){
					$qvid = $request["id"];
				}else if($request['id'] != "" && $pagename == 'questions'){
					$videos = $db['master']->getOneRow("SELECT qvid FROM quesvideos WHERE vqid='".$_SESSION['vqid']."' AND langid='".$_SESSION['langid']."' AND uid='".$_SESSION['uid']."' AND topicid = '".$_SESSION['topicid']."' AND sid= '".$_SESSION['sid']."' AND cid='".$_SESSION['cid']."' AND (branch_id=0 OR branch_id='".$_SESSION['branchid']."') AND status='active'");
					if($videos){
						console(LOG_LEVEL_TRACE, "Already Exists qvid :: ". $videos['qvid']);
						$qvid = $videos['qvid'];
					}else{
						$addquestionvideo = $db['master']->query("INSERT INTO quesvideos(`vqid`,`langid`,`uid`,`topicid`,`sid`,`cid`,`branch_id`) VALUES('".$_SESSION['vqid']."','".$_SESSION['langid']."','".$_SESSION['uid']."','".$_SESSION['topicid']."','".$_SESSION['sid']."','".$_SESSION['cid']."','".$_SESSION['branchid']."')");
						$qvid = $db['master']->getLastID();
						console(LOG_LEVEL_TRACE, "Inserted values in Quesvideos => vqid :: ". $_SESSION['vqid'].", langid :: ".$_SESSION['langid'].", uid :: ".$_SESSION['uid'].", topicid :: ".$_SESSION['topicid'].", sid :: ".$_SESSION['sid'].", cid :: ".$_SESSION['cid'].", qvid :: ".$qvid);
					}
				}
				$tab_header = mysql_real_escape_string($request['tabheader']);
				$addquestions = $db['master']->query("INSERT INTO questions(question,qvtype,pagebelongsto,tabid) VALUES('".(($tab_header))."','tabs','".$qvid."','".$tabid."')");
				console(LOG_LEVEL_TRACE, "Inserted values in Questions => qvtype :: tabs,  pagebelongsto :: ".$qvid." tabid :: ".$tabid);
				$qid = $db['master']->getLastID();
				if($qid){
					$update = $db['master']->query("UPDATE tabs SET qid='".$qid."' WHERE tabid='".$tabid."' AND status='active'");
					console(LOG_LEVEL_TRACE, "Updated Tabs with qid :: ".$qid." where tabid :: ".$tabid);
				}
			}
		}
		else if($request['header'] != "" && $request['hiddencount'] != ""){  
			$count = $request['hiddencount']-1;  //echo $count;
			$insq = "INSERT INTO tabs(`tabheader`,`main_content`,`qid`,`linetype`) VALUES('".(($request['tabheader']))."','".(($request['header']))."','".$request["tabidval"]."','".$request['maintablinetype']."')";
			$result = $db['master']->query($insq);
			$reftabid = $db['master']->getLastID();
			if($request["id"]!='' && $pagename == 'listview'){
				$qvid = $request["id"];
			}else if($request['id'] != "" && $pagename == 'questions'){
				$videos = $db['master']->getOneRow("SELECT qvid FROM quesvideos WHERE vqid='".$_SESSION['vqid']."' AND langid='".$_SESSION['langid']."' AND uid='".$_SESSION['uid']."' AND topicid = '".$_SESSION['topicid']."' AND sid= '".$_SESSION['sid']."' AND cid='".$_SESSION['cid']."' AND (branch_id=0 OR branch_id='".$_SESSION['branchid']."') AND status='active'");
				if($videos){
					console(LOG_LEVEL_TRACE, "Already Exists qvid :: ". $videos['qvid']);
					$qvid = $videos['qvid'];
				}else{
					$addquestionvideo = $db['master']->query("INSERT INTO quesvideos(`vqid`,`langid`,`uid`,`topicid`,`sid`,`cid`,`branch_id`) VALUES('".$_SESSION['vqid']."','".$_SESSION['langid']."','".$_SESSION['uid']."','".$_SESSION['topicid']."','".$_SESSION['sid']."','".$_SESSION['cid']."','".$_SESSION['branchid']."')");
					$qvid = $db['master']->getLastID();
					console(LOG_LEVEL_TRACE, "Inserted values in Quesvideos => vqid :: ". $_SESSION['vqid'].", langid :: ".$_SESSION['langid'].", uid :: ".$_SESSION['uid'].", topicid :: ".$_SESSION['topicid'].", sid :: ".$_SESSION['sid'].", cid :: ".$_SESSION['cid'].", qvid :: ".$qvid." branchid :: ".$_SESSION['branchid']);
				}
			}

			if($request["tabidval"]==""){
				$tab_header = mysql_real_escape_string($request['tabheader']); 
				$addquestions = $db['master']->query("INSERT INTO questions(question,qvtype,pagebelongsto,tabid) VALUES('".(($tab_header))."','tabs','".$qvid."','".$reftabid."')");
				console(LOG_LEVEL_TRACE, "Inserted values in Questions => qvtype :: tabs,  pagebelongsto :: ".$qvid." tabid :: ".$tabid);
				$qid = $db['master']->getLastID();
			}else{
				$qid = $request["tabidval"];
			}
			if($qid){
				$update = $db['master']->query("UPDATE tabs SET qid='".$qid."' WHERE tabid='".$reftabid."' AND status='active'");
				console(LOG_LEVEL_TRACE, "Updated Tabs with qid :: ".$qid." where tabid :: ".$reftabid);
			}
			for($i = 1; $i <= $count; $i++){  
				$subcontent = '';
				$subcontent = $request['subcontent'.$i];
				$linetype = $request['subtablinetype'.$i];
				//$result = $db ['master']->query("INSERT INTO tabs (`reftabid`,`subcontent`,`videopath`,`vname`,`vsize`,`vtype`,`qid`) VALUES ('".$reftabid."','".(($subcontent))."','".$videopath."','".$vname."','".$vsize."','".$vtype."','".$qid."')");
				
				if($subcontent!=''){
				$result = $db ['master']->query("INSERT INTO tabs (`reftabid`,`subcontent`,`qid`,`linetype`) VALUES ('".$reftabid."','".(($subcontent))."','".$qid."','".$linetype."')");
				console(LOG_LEVEL_TRACE, "Inserted Values in Tabs => maincontent :: ".$request['header'].", subcontent :: ".$subcontent.", videopath :: ".$videopath.", videoname :: ".$vname.", videosize :: ".$vsize.", videotype :: ".$vtype);
				if($result!= "" && $tabidexists == ""){
					$tabid = $db['master']->getLastID();
					
					
				}
				}
			}
		}if($db ['master']->affectedRows()>0){
			//return $qvid;
			console(LOG_LEVEL_INFO,"Question Added: ".$qid);
						$pagebelongsto = $qvid;
						$quesid = $qid;
						$txtMsg = "Tab added successfully";
			console(LOG_LEVEL_TRACE, "Message : ". $txtMsg . " quesid  : ".$quesid." qvid : ".$pagebelongsto );
		}else{
						$pagebelongsto = $qvid;
						$quesid = 0;
						$txtMsg = "Error in Inserting Tab";
		}
		
		$retarray = array();
		$retarray[0] = $txtMsg;
		$retarray[1] = $pagebelongsto;
		$retarray[2] = $quesid;
		return $retarray;
	}
	
	public function UpdateTemplate5(){ 
		global $db,$request;
		if($request['headerr'] != ""){  
			$select_tab = $db['master']->getOneRow("SELECT * FROM tabs WHERE tabid='".$request['editmaintabid']."' AND status='active'");
			if($select_tab != ""){  
				if($select_tab['tabheader'] != ""){
					$updateques = $db['master']->query("UPDATE questions SET question = '".$request['tabheaderr']."' WHERE qid='".$select_tab['qid']."' AND status='active'");
				}
				$updateq = $db['master']->query("UPDATE tabs SET tabheader='".$request['tabheaderr']."', main_content='".$request['headerr']."',linetype='".$request['maintablinetype']."' WHERE tabid='".$request['editmaintabid']."'");
				$reftabid = $request['editmaintabid'];
			}else{  
				$insq = "INSERT INTO tabs(`tabheader`,`main_content`,`qid`,`linetype`) VALUES('".(($request['tabheaderr']))."','".(($request['headerr']))."','".$request["qidval"]."','".$request['maintablinetype']."')";
				$result = $db['master']->query($insq);
				$reftabid = $db['master']->getLastID();
			}
				if($request["qvidval"]!=''){
					$qvid = $request["id"];
				}
				if($request['edittabcount'] != ""){
					$count = $request['edittabcount']-1;
				}else if($request['edithiddencount'] != ""){
					$count = $request['edithiddencount']-1;
				}
				if($count == ""){
					$count = 1;
				}
				for($i = 1; $i <= $count; $i++){  
					$subcontent = '';
					$subcontent = $request['subcontent'.$i];
					$linetype = $request['subtablinetype'.$i];
					$subtabid = $request['tabid'.$i];
					if($subcontent!=''){ 
						if($subtabid != ""){
							$result = $db['master']->query("UPDATE tabs SET subcontent='".(($subcontent))."',linetype='".$linetype."' WHERE tabid='".$subtabid."' AND qid='".$request["qidval"]."' AND reftabid='".$reftabid."' AND status='active'");
						}else{
							$result = $db ['master']->query("INSERT INTO tabs (`reftabid`,`subcontent`,`qid`,`linetype`) VALUES ('".$reftabid."','".(($subcontent))."','".$request["qidval"]."','".$linetype."')");
							console(LOG_LEVEL_TRACE, "Inserted Values in Tabs => maincontent :: ".$request['header'].", subcontent :: ".$subcontent);
						}
					}
				}
		}if($db ['master']->affectedRows()>0){
			//return $qvid;
			console(LOG_LEVEL_INFO,"Tabs Added: ".$request["qidval"]);
						$pagebelongsto = $request["qvidval"];
						$quesid = $request["qidval"];
						$txtMsg = "Tab added successfully";
			console(LOG_LEVEL_TRACE, "Message : ". $txtMsg . " quesid  : ".$quesid." qvid : ".$pagebelongsto );
		}else{
						$pagebelongsto = $request["qvidval"];
						$quesid = $request["qidval"];
						$txtMsg = "Error in Inserting Tab";
		}
		
		$retarray = array();
		$retarray[0] = $txtMsg;
		$retarray[1] = $pagebelongsto;
		$retarray[2] = $quesid;
		return $retarray;
	}

	public function CheckQuesVidoes(){
		global $db,$request;

		$vqid 		 = 1;
		$langid 	 = $_SESSION['langid'];
		$uid 		 = $_SESSION['uid'];
		$topicid 	 = $_SESSION['topicid'];
		$sid 		 = $_SESSION['sid'];
		$cid		 = $_SESSION['cid'];
		$semid		 = $_SESSION['semid'];
		$branchid    = (isset($_SESSION['branchid']) && $_SESSION['branchid'] != 0 && $_SESSION['branchid'] != '') ? $_SESSION['branchid'] : ''; 

		$query = "SELECT * from quesvideos where `status`='active' AND vqid='".$vqid."' AND langid='".$langid."' AND uid='".$uid."' AND topicid='".$topicid."' AND sid='".$sid."' AND cid='".$cid."' AND (branch_id=0 OR branch_id='".$branchid."') ORDER BY qvid DESC LIMIT 1";

		$qtypes	= $db['master']->getOneRow($query);
		if($qtypes){
		$qvid = $qtypes['qvid'];
		}else{
		$qvid = 0;
		}
		return $qvid;
	}

	public function AddQuesVidoes(){
		global $db,$request;
		$txtCount 	= $request['txtCount'];
		$videoCount = $request['videoCount'];

		console(LOG_LEVEL_TRACE, "txtCount:".$txtCount." videoCount::".$videoCount);
		$txtMessage = 1;
		$vqid 		 = 1;
		$langid 	 = $_SESSION['langid'];
		$uid 		 = $_SESSION['uid'];
		$topicid 	 = $_SESSION['topicid'];
		$sid 		 = $_SESSION['sid'];
		$cid		 = $_SESSION['cid'];
		$semid		 = $_SESSION['semid'];
		$univid		 = $_SESSION['unid'];
		$branchid    = $_SESSION['branchid'];
		
		$db ['master']->query("INSERT INTO quesvideos (univid,cid,semid,sid,uid,langid,topicid,vqid,branch_id) VALUES ('".$univid."','".$cid."','".$semid."','".$sid."','".$uid."','".$langid."','".$topicid."','".$vqid."','".$branchid."')");
		$pagebelongsto		= $db['master']->getLastID();	
		
	
	if($txtCount>0) {
		$txtaid 	 = explode(",", $request['txtaid']);
			foreach($txtaid as $i){  //print_r($request); exit;
				$questions 	 = $request['qtext'.$i];
				$questionval = $obj1 = $obj2 =$obj3 = $obj4 = $optanswer = '';
				$questionval = $questions[0];
				
				$objective_count = '';				
				$questionsobj 	 = $request['qopt'.$i];				
				$objective_count = count($questionsobj);
				/*$obj1 		 = $questions[1];
				$obj2 		 = $questions[2];
				$obj3 		 = $questions[3];
				$obj4 		 = $questions[4];*/
				$optansval   = $request['qanswer1'];
				console(LOG_LEVEL_TRACE, "optansval:".$optansval);
				$optanswer 	 = $questionsobj[$optansval];
				$aid = '';
				$aid = $i;
				console(LOG_LEVEL_TRACE, "txtCount aid:".$aid);
				if($request['questyp'] != ""){
					$qrykey = ",temp_name";
					$qryval = ",'".$request['questyp']."'";
				}
				$qus = mysql_real_escape_string($questionval);
				$opt_ans = mysql_real_escape_string($optanswer);
				
				$db ['master']->query("INSERT INTO questions (question,optanswer,qvtype,pagebelongsto,aid,orderid $qrykey) VALUES ('".$qus."','". (($opt_ans)) ."','question','".$pagebelongsto."','".$aid."','".$request['questionorderid']."' $qryval)");
				$lastid = $db['master']->getLastID();
				
				$db['master']->query("INSERT INTO explanation_topics (qid,explanation_id,pagebelongsto) VALUES ('".$lastid."','". $request['explanationtxt'] ."','".$pagebelongsto."')");
				
				$quesdetails = $db['master']->getOneRow("SELECT qid,qvtype,pagebelongsto FROM questions WHERE qid='".$lastid."' AND status='active'");

				if($objective_count>0){
					for($jk=0; $jk < $objective_count; $jk++){			
						$objective = '';				
						$objective = $questionsobj[$jk];
						if($objective!=''){
							$obj_opt = mysql_real_escape_string($objective);
							$db ['master']->query("INSERT INTO choose_the_best_answer (qid,objective,pagebelongsto) VALUES ('".$lastid."','".$obj_opt."','".$quesdetails['pagebelongsto']."')");
						}
					}
				}				
				
			$image1 = $image2 = $image3 = $image4 = "";
			if($request['questionpassage'] != ""){
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,passage) VALUES('".$lastid."','".$pagebelongsto."','".mysql_real_escape_string(addslashes($request['questionpassage']))."')";
			}else if($request['questionimgpassage'] != ""){
				$passg = $request['questionimgpassage'];
				if($_FILES['imgpsg']["name"] != ""){
					$randomval = rand(1000,9999);
					$imgname1 = $_FILES['imgpsg']["name"];
					$extension = pathinfo($_FILES['imgpsg']['name'], PATHINFO_EXTENSION);	
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES['imgpsg']["tmp_name"]);
					$imgnme1 = date('YmdHis').'_'.$randomval.'_'.$imgname1;
					if(move_uploaded_file($_FILES['imgpsg']["tmp_name"],USER_UPLOAD_DIR . $imgnme1)){
						console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgnme1);
					}else{
						console(LOG_LEVEL_TRACE, "Error in Moving File to the Path ::".USER_UPLOAD_DIR . $imgnme1);
					}
				}else{
					console(LOG_LEVEL_TRACE, "Audio File is Empty ::".$_FILES['imgpsg']["name"]);
				}
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,passage,image1) VALUES('".$lastid."','".$pagebelongsto."','".mysql_real_escape_string(addslashes($passg))."','".$imgnme1."')";
			}else{
				for($countimg=0; $countimg<=3; $countimg++){
					console(LOG_LEVEL_TRACE, "countimg :: " .$countimg);
					$imgnme = $imgname = "";
					if($_FILES['questionimg']["name"][$countimg] != ""){
						$randomval = rand(1000,9999);
						$imgname = $_FILES['questionimg']["name"][$countimg];
						$extension = pathinfo($_FILES['questionimg']['name'][$countimg], PATHINFO_EXTENSION);	
						console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES['questionimg']["tmp_name"][$countimg]);
						$imgnme = date('YmdHis').'_'.$randomval.'_'.$imgname;
						if(move_uploaded_file($_FILES['questionimg']["tmp_name"][$countimg],USER_UPLOAD_DIR . $imgnme)){
							console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgnme);
							if($countimg == 0){ $image1 = $imgnme; }
							else if($countimg == 1){ $image2 = $imgnme; }
							else if($countimg == 2){ $image3 = $imgnme; }
							else if($countimg == 3){ $image4 = $imgnme; }
						}else{
							console(LOG_LEVEL_TRACE, "Error in Moving File to the Path ::".USER_UPLOAD_DIR . $imgnme);
						}
					}else{
						console(LOG_LEVEL_TRACE, "Audio File is Empty ::".$_FILES['questionimg']["name"][$countimg]);
					}
				}
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,image1,image2,image3,image4) VALUES('".$lastid."','".$pagebelongsto."','".$image1."','".$image2."','".$image3."','".$image4."')";
			}
			$result_quesdtls = $db['master']->query($insq_quesdetls);
				if($request['audiolangcount'] != ""){
					$count = $request['audiolangcount']-1;
				}else{
					$count =1;
				}
					for($i=1; $i<=$count; $i++){
						$language = $request["chooselanguage".$i];
						console(LOG_LEVEL_TRACE, "chooselanguage".$i." :: ".$language);
						$filename = '';
						$filename = "introaudio_val".$i;
						
						console(LOG_LEVEL_TRACE, "filename-->".$filename);
						if($_FILES[$filename]["name"]){
							$randomval = rand(1000,9999);
							$aname = $_FILES[$filename]["name"];
							$atype = $_FILES[$filename]["type"];
							$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
							$asize = $_FILES[$filename]["size"];
							$asize = $this->formatSizeUnits($asize);
							console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
							
							$audiopath = USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							$audioname = "chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);     
							console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);
						}
						
						if($language != "" || $audioname != ""){
							$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$quesdetails['qid']."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$quesdetails['pagebelongsto']."','".$quesdetails['qvtype']."')");
						}else{
							console(LOG_LEVEL_TRACE, "Error in Inserting into LanguageAudios :: Language and File Upload is Empty");
						}
					}
					if($db ['master']->affectedRows()>0){
						console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
						$txtMessage = 1;
						$txtMsg = "Question added successfully";
					}else{
						$txtMessage = 0;
						$txtMsg = "Fail to add Questions";
					}
				}
		}
	
	
		if(isset($request['chooseTheBestImgQuestion'])){
			$answerObjImg = array();
			$optanswer = '';
			for($i = 1; $i <= 4 ; $i++){
				if(!empty($_FILES['queTextAns'.$i]['name'])){
					$randomval = rand(1000,9999);
					$info = pathinfo($_FILES['queTextAns'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['queTextAns'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = CHOOSE_THE_BEST_IMAGE_URL.$pagebelongsto.'_'.$randomval.'_'.$newfilename.$ext;
					//$location = CHOOSE_THE_BEST_IMAGE_URL.$pagebelongsto.'_'.$newfilename.'jpg';
					move_uploaded_file( $_FILES['queTextAns'.$i]['tmp_name'], $location);
					$answerObjImg[] = $location;
					if($request['qanswer1'] == $i){
						$optanswer = $location;
					}
				}
			}
			$qryStrCol = '';
			$qryStr = '';
			$questionval = $request['chooseTheBestImgQuestion'];
			foreach($answerObjImg as $key => $value){
				if($qryStr == ''){
					$qryStrCol = 'obj'.($key+1);
					$qryStr = '\''.$value.'\'';
				}else{
					$qryStrCol .= ',obj'.($key+1);
					$qryStr .= ',\''.$value.'\'';
				}
				
			}
			console(LOG_LEVEL_TRACE, "optansval:".$optanswer);
			$ques = mysql_real_escape_string($questionval);
			$opt_ans = mysql_real_escape_string($optanswer);
			
			$db ['master']->query("INSERT INTO questions (question,".$qryStrCol.",optanswer,qvtype,pagebelongsto,aid,orderid) VALUES ('".$ques."',".$qryStr.",'". (($opt_ans)) ."','chooseTheBestImg','".$pagebelongsto."','1','".$request['chooseorderid']."')");
			
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','chooseTheBestImg')");
					
					}
				}
			}
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$txtMessage = 1;
				$txtMsg = "Question added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Fail to add Questions";
			}
		}	
		$videoMessage = 1;
		
		// video and audio upload base on language start
		if($videoCount>0){
			$videoaid 	 = explode(",", $request['videoaid']);
			console(LOG_LEVEL_TRACE, "video arrangements:".$request['videoaid']);
			foreach($videoaid as $i){
				$filename = "qvideos".$i;	
				$videopath  = USER_UPLOAD_DIR;
				$aid = '';
				$aid = $i;
				$allowedExts = array("mp3", "mp4", "wma");
				$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
				console(LOG_LEVEL_TRACE, "filename:".$filename);
				if ($_FILES[$filename]["error"] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename]["error"]." filename::".$filename);
				}else {
					console(LOG_LEVEL_TRACE, "filename vname:".$filename);
					$vname = date('YmdHis').'_'.$_FILES[$filename]["name"];
					$vtype = $_FILES[$filename]["type"];
					$vsize = $_FILES[$filename]["size"];
					$vsize = $this->formatSizeUnits($vsize);
					console(LOG_LEVEL_TRACE, "video Name::".$vname." video type::".$vtype."video Size".$vsize."Temp file: ".$_FILES[$filename]["tmp_name"]);

					move_uploaded_file($_FILES[$filename]["tmp_name"],
					USER_UPLOAD_DIR . $vname);     
					console(LOG_LEVEL_TRACE, "video Stored in::".USER_UPLOAD_DIR . $_FILES[$filename]["name"]);
				}
	  
		
		
				$videopath = $videopath.$vname;
				$db ['master']->query("INSERT INTO questions (videopath,vname,vsize,vtype,qvtype,pagebelongsto,aid,streamvideo,orderid) VALUES ('".$videopath."','".$vname."','".$vsize."','".$vtype."','video','".$pagebelongsto."','".$aid."','new','".$request['videoorderid']."')");
	
				$videoid		   = $db['master']->getLastID();
				$audio_language	   = $request['audio_language'];						
				$audio_count  	   = count($audio_language);				
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
				for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["videoaudio"]["error"][$i] > 0 || $_FILES["videoaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["videoaudio"]["error"][$i]."Languge audtio filename::"."videoaudio");
					}else if($_FILES["videoaudio"]["tmp_name"][$i]!=''){
					
					$randomval = rand(1000,9999);
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES["videoaudio"]["name"][$i];
					//$aname = $_FILES["videoaudio"]["name"][$i];
					$atype = $_FILES["videoaudio"]["type"][$i];
					$asize = $_FILES["videoaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["videoaudio"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["videoaudio"]["tmp_name"][$i],
					$audiopath.$aname)){	
					$audiopath = $audiopath.$aname;
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$videoid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','video')");
					
					}
			}
				
					
				}			
	
			}
	
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Uploaded Video : ".$vname);
				$videoMessage = 1;
				$videoMsg = "Videos Uploaded Successfully ";
			}else{
				$videoMessage = 0;
				$videoMsg = "Videos Not Uploaded Successfully ";
			}
				
		}
		
		// video and audio upload base on language end
		
		
		// dropdown section start
		
		if(isset($request['drop'])){
			$drop_ques = mysql_real_escape_string($request['drop']);
			
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$drop_ques."','dropdown','".$pagebelongsto."','1','".$request['dropdwnorderid']."')");
			$qid = $db['master']->getLastID();
			
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','dropdown')");
					
					}
				}
			}
			$i = 0;
			for($i=1; $i<=$request['addid']; $i++){
				$opt1 = htmlspecialchars($request['fbopt1_'.$i]);   
				$opt2 = htmlspecialchars($request['fbopt2_'.$i]);   
				$opt3 = htmlspecialchars($request['fbopt3_'.$i]);   
				$ans1 = htmlspecialchars($request['fbans1_'.$i]);   
				$ans2 = htmlspecialchars($request['fbans2_'.$i]);   
				$ans3 = htmlspecialchars($request['fbans3_'.$i]);   
				if($ans1 > 0){ $ans = $opt1;} else if($ans2 > 0){ $ans = $opt2;}else{ $ans = $opt3;}
				
				if($i == 1){ $values = "('".(($qid))."','".(($opt1))."','".(($opt2))."','".(($opt3))."','".(($ans))."')"; }
				else{$values .= ",('".(($qid))."','".(($opt1))."','".(($opt2))."','".(($opt3))."','".(($ans))."')"; }
			}
			$db ['master']->query("INSERT INTO fill_in_the_blank_answer (qid,obj1,obj2,obj3,answer) VALUES ".$values."");
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Dropdown Added: ".$request['drop']);
				$dropdownMessage = 1;
				$dropdownMsg =  "Dropdown added successfully";
			}else{
				$dropdownMessage = 0;
				$dropdownMsg = "Fail to add dropdown";
			}
		}
		
		// dropdown section end
		
		// Fill in the blanks section start
		if(isset($request['blank'])){
			$blank_ques = mysql_real_escape_string($request['blank']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($blank_ques))."','fib','".$pagebelongsto."','1','".$request['fiborderid']."')");
			$qid = $db['master']->getLastID();
			
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','fib')");
					
					}
				}
			}
			$i = 0;
			for($i=1; $i<=$request['addidBlank']; $i++){
				$ans = trim(mysql_real_escape_string($request['fbopt1_'.$i]));  
				if($i == 1){ $values = "('".(($qid))."','".(($ans))."')"; }
				else{$values .= ",('".(($qid))."','".(($ans))."')"; }
			}
			$db ['master']->query("INSERT INTO fill_in_the_blank_answer (qid,answer) VALUES ".$values."");
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Fill in the Blanks Added: ".$request['blank']);
				$fbMessage = 1;
				$fbMsg =  "Fill in the blanks added successfully";
			}else{
				$fbMessage = 0;
				$fbMsg = "Fail to add fill in the blanks";
			}
		}
		
		// Fill in the blanks section end
		
		// Drag & Drop (Text) section Start
		if(isset($request['ddText'])){
			$dd_ques = mysql_real_escape_string($request['ddText']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($dd_ques))."','dragDropText','".$pagebelongsto."','1','".$request['dragdroptorderid']."')");
			$qid = $db['master']->getLastID();
			
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','dragDropText')");
					
					}
				}
			}
			$i = 0;
			for($i=1; $i<=$request['addidText']; $i++){
				$ans = trim(mysql_real_escape_string($request['fbopt1_'.$i]));  
				if($i == 1){ $values = "('".$qid."','".$ans."')"; }
				else{$values .= ",('".$qid."','".$ans."')"; }
			}
			$db ['master']->query("INSERT INTO fill_in_the_blank_answer (qid,answer) VALUES ".$values."");
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Fill in the Blanks Added: ".$request['blank']);
				$fbMessage = 1;
				$fbMsg =  "Fill in the blanks added successfully";
			}else{
				$fbMessage = 0;
				$fbMsg = "Fail to add fill in the blanks";
			}
		}
		// Drag & Drop (Text) section end
		
		// Drag & Drop Section Start
		if(isset($request['drag_question'])){
			
			$section_name1 = mysql_real_escape_string($request['drag_sec_1']);
			$section_name2 = mysql_real_escape_string($request['drag_sec_2']);
			$question = mysql_real_escape_string($request['drag_question']);
			
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($question))."','dragdrop','".$pagebelongsto."','1','".$request['dragdroporderid']."')");
			$qid = $db['master']->getLastID();
			
			$db ['master']->query("INSERT INTO dd_sec_headings (qid,section_name) VALUES ('".$qid."','".(($section_name1))."')");
			$secId1 = $db['master']->getLastID();
			
			$db ['master']->query("INSERT INTO dd_sec_headings (qid,section_name) VALUES ('".$qid."','".(($section_name2))."')");
			$secId2 = $db['master']->getLastID();
			
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','dragdrop')");
					
					}
				}
			}
			for($i = 1; $i <= 6 ; $i++){
				if(!empty($_FILES['drag_upload_'.$i]['name'])){
					$info = pathinfo($_FILES['drag_upload_'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['drag_upload_'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = DRAG_DROP_IMAGE_URL.$newfilename."jpg";
					move_uploaded_file( $_FILES['drag_upload_'.$i]['tmp_name'], $location);
					$section_id = '';
					if($request['drag_1_'.$i] == 1){$section_id = $secId1;}
					else if($request['drag_2_'.$i] == 2){$section_id = $secId2;}	
					else{$section_id = 0;}
					$db ['master']->query("INSERT INTO dd_answers (qid,image_path,section_id) VALUES ('".$qid."','".(($location))."','".$section_id."')");
				}
			}
		
			if($db ['master']->affectedRows()>0){
				$dragMessage = 1;
				$dragMsg = "Drag and drop Uploaded Successfully ";
			}else{
				$dragMessage = 0;
				$dragMsg = "Videos Not Uploaded drag and drop ";
			}
		}
		
		// Drag & Drop Section End
		
		// Match the following Section start
		if($request['matchId'] == 1){
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('matching','matching','".$pagebelongsto."','1','".$request['matchorderid']."')");
			$qid = $db['master']->getLastID();
			
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','matching')");
					
					}
				}
			}
			$i = 0;
			for($i=1; $i<=6; $i++){
				$quetion = '';$answer = '';
				$quetion = trim(mysql_real_escape_string($request['match_ques_'.$i]));   
				$answer = trim(mysql_real_escape_string($request['match_ans_'.$i]));   
				if(($quetion != '') && ($answer != '')){
					$db ['master']->query("INSERT INTO match_the_following (qid,question,answer) VALUES('".$qid."','".(($quetion))."','".(($answer))."')");
				}
			}
			
			if($db ['master']->affectedRows()>0){
				$mtfMessage = 1;
				$mtfMsg =  "Match the following added successfully";
			}else{
				$mtfMessage = 0;
				$mtfMsg = "Fail to add match the following";
			}
		}
		// Match the following Section End
		
		// Image Tab Section start
		if(isset($request['imageTab'])){



			$questionval = mysql_real_escape_string($request['imageTab']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$questionval."','imageTab','".$pagebelongsto."','1','".$request['imagetaborderid']."')");
			$qInsId = $db['master']->getLastID();
			$tempThumbArr = array();
			$tempVideoArr = array();
			for($i = 1; $i <= 10 ; $i++){
				if(!empty($_FILES['thumbnail'.$i]['name'])){
					$fileSize = 0;
					$randomval = rand(1000,9999);
					$fileSize = round(filesize($_FILES['thumbnail'.$i]['tmp_name'])/1024,2);
					$info = pathinfo($_FILES['thumbnail'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['thumbnail'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					//$location = IMAGE_TAB_THUMBNAIL_URL.$qInsId.'_'.$newfilename.'jpg';
					$location = IMAGE_TAB_THUMBNAIL_URL.$qInsId.'_'.$randomval.'_'.$newfilename.$ext;
					$res = move_uploaded_file( $_FILES['thumbnail'.$i]['tmp_name'], $location);
					if($res){ 
						console(LOG_LEVEL_INFO, $location." - Filesize: ".$fileSize." - Thumbnail uploaded successfully");
					} else { 
						console(LOG_LEVEL_TRACE, $location." - Filesize: ".$fileSize." - Thumbnail upload failed");
					}
					$tempThumbArr[$i] = $location;
				}
				
				if(!empty($_FILES['video'.$i]['name'])){
					$fileSize = 0;
					$fileSize = round(filesize($_FILES['video'.$i]['tmp_name'])/1024,2);
					$info = pathinfo($_FILES['video'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['video'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = IMAGE_TAB_VIDEO_URL.$qInsId.'_'.$newfilename.$ext;
					$resVideo = move_uploaded_file( $_FILES['video'.$i]['tmp_name'], $location);
					if($resVideo){ 
						console(LOG_LEVEL_INFO, $location." - Filesize: ".$fileSize." - Video uploaded successfully");
					} else { 
						console(LOG_LEVEL_TRACE, $location." - Filesize: ".$fileSize." - Video upload failed");
					}					
					$tempVideoArr[$i] = $location;
				}
			}
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["type"][$i], PATHINFO_EXTENSION);	
					$aname = $randomval.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					if(move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname)){	
						$audiopath = $audiopath.$aname;
						$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','imageTab')");
					
					}
				}
			}
			for($i = 1; $i <= 10 ; $i++){
				if(trim($request['imageTitle'.$i]) != ''){
					$db ['master']->query("INSERT INTO image_tab (qid,video_title,thumbnail_url,video_url) VALUES ('".$qInsId."','".$request['imageTitle'.$i]."','".$tempThumbArr[$i]."','".$tempVideoArr[$i]."')");
				}
			}
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$txtMessage = 1;
				$txtMsg = "Question added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Fail to add Questions";
			}
		}
		// Image Tab Section End
		
		// Image Template section Start
		if($request['image_template'] == 1){
			
			$img_head = mysql_real_escape_string($request['img_temp_header']);
			
			//Header table Insert
			$db ['master']->query("INSERT INTO header (htext,template_type) VALUES ('".(($img_head))."','Image_Template')");
			$hid = $db['master']->getLastID();
			
			//Questions table Insert
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('Image_Template','Image_Template','".$pagebelongsto."','1','".$hid."','".$request['image_template_qtype']."','".$request['imgtemporderid']."')");
			$qid = $db['master']->getLastID();
			
			//Media Insert Part Start
			$img_temp_label 	 = $request['img_temp_label'];				
			$img_temp_label_count = count($img_temp_label);
			
			for($i=0;$i<$img_temp_label_count;$i++){
				$label = '';$media_name = '';$mid = '';				
				$label = mysql_real_escape_string($img_temp_label[$i]);
				
				if(!empty($_FILES["img_temp_media"]["name"][$i])){
					$randomval = rand(1000,9999);
					$type = $_FILES["img_temp_media"]["type"][$i];
					$extension = pathinfo($_FILES["img_temp_media"]['name'][$i], PATHINFO_EXTENSION);	
					$path = MEDIA_UPLOAD_DIR.$qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					$name = $qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES["img_temp_media"]["tmp_name"][$i],MEDIA_UPLOAD_DIR.$qid. date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Media Stored in :: ".MEDIA_UPLOAD_DIR.$qid. date('YmdHis').'_'.$randomval.'.'.$extension);
										
					$db ['master']->query("INSERT INTO img_temp_media(hid,qid,label,media_type,media_name) VALUES ('".$hid."','".$qid."','".$label."','".$type."','".$name."')");
					$mid = $db['master']->getLastID();
					
					if(!empty($_FILES["img_temp_med_audio"]["name"][$i])){
						$randomval = rand(1000,9999);
						$aname =  $_FILES["img_temp_med_audio"]["name"][$i];
						$atype = $_FILES["img_temp_med_audio"]["type"][$i];
						$extension = pathinfo($_FILES["img_temp_med_audio"]['name'][$i], PATHINFO_EXTENSION);	
						$asize = $_FILES["img_temp_med_audio"]["size"][$i];
						$asize = $this->formatSizeUnits($asize);
						$audiopath = USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension;
						$audioname = $qid. date('YmdHis').'_'.$randomval.'.'.$extension;
						move_uploaded_file($_FILES["img_temp_med_audio"]["tmp_name"][$i],USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);console(LOG_LEVEL_TRACE, "Media Audios Stored in :: ".USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);
						
						$img_temp_med_lang 	 = $request['img_temp_med_lang'];				
						$language = $img_temp_med_lang[$i];
						
						if($language != "" || $audioname != ""){
							$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,mid) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','Image_Template','".$hid."','".$mid."')");
						}else{
							console(LOG_LEVEL_TRACE, "Error in inserting into Media Audios :: Language and file Upload is Empty");
						}
						
					}	
				}
			}
			//Media Insert Part End
			
			//Bulletin Insert Part Start
			$img_temp_bul_level 	 = $request['img_temp_bul_level'];				
			$img_temp_bul_animation 	 = $request['img_temp_bul_animation'];				
			$img_temp_bul_text 	 = $request['img_temp_bul_text'];				
			$img_temp_bul_text_count = count($img_temp_bul_text);
			
			for($i=0;$i<$img_temp_bul_text_count;$i++){
				if (!empty($img_temp_bul_text[$i])) {
				$bul_text = '';$media_name = '';$bid = '';$txt_animation = '';$txt_level = '';				
				$bul_text = $img_temp_bul_text[$i];
				$txt_animation = $img_temp_bul_animation[$i];
				$txt_level = $img_temp_bul_level[$i];
				if($txt_level == ''){$txt_level = 0;}
				$bul_txt = mysql_real_escape_string($bul_text);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,txt_value,txt_animation,txt_level) VALUES ('".$hid."','".(($bul_txt))."','".$txt_animation."','".$txt_level."')");
				$bid = $db['master']->getLastID();
				
				if(!empty($_FILES["commonaudio"]["name"][$i])){
					$randomval = rand(1000,9999);
					$aname =  $_FILES["commonaudio"]["name"][$i];
					$atype = $_FILES["commonaudio"]["type"][$i];
					$extension = pathinfo($_FILES["commonaudio"]['name'][$i], PATHINFO_EXTENSION);	
					$asize = $_FILES["commonaudio"]["size"][$i];
					$asize = $this->formatSizeUnits($asize);
					$audiopath = USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = $qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);console(LOG_LEVEL_TRACE, "Bulletin Audios Stored in :: ".USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);
					
					$audio_language 	 = $request['audio_language'];				
					$language = $audio_language[$i];
					
					if($language != "" || $audioname != ""){
						$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','Image_Template','".$hid."','".$bid."')");
					}else{
						console(LOG_LEVEL_TRACE, "Error in inserting into Bulletin Audios :: Language and file Upload is Empty");
					}
					
				}	
				}
			}
			
			//Bulletin Insert Part End
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$imgTabMessage = 1;
				$imgTabMsg = "Image Template added successfully";
			}else{
				$imgTabMessage = 0;
				$imgTabMsg = "Fail to add Image Template";
			}
			
			
		}

		
	if(isset($request['texttempsubject'])){	
		console.log(LOG_LEVEL_TRACE, "Text_template");
		$template_type  	= 'text_template';
		$subjecttxt  		= mysql_real_escape_string($request['texttempsubject']);	
		$header_animation	= $request['headerimg_animation'];	
		
		$db ['master']->query("INSERT INTO header (template_type,header_animation,subjecttxt) VALUES ('".$template_type."','".$header_animation."','".$subjecttxt."')");
	
		$hid		= $db['master']->getLastID();
	
		// make value in question table for template
			   
		$aid = $this->setArrangementId($pagebelongsto);
			   
		$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$request['texttemporderid']."')");
		
		$qInsId		= $db['master']->getLastID();	
		/* Header Details Part End */
	
		/* Bulletin Details Part Start */
		
		//$blockcount = $request['blockcount'];
		console(LOG_LEVEL_TRACE, "blockcount::".$blockcount);	
		
		
	
		console(LOG_LEVEL_TRACE, "blockcount $j::".$j);
		
		$headertxt = $temptext = $bulletin_level = $tempimg_animation = $bulletin_label_animation = $header_animation = $bulletin_count =  '';
		$temptext_array = $tempimg_animation_array = '';
			
		$temptext_array  			= $request['temptext1'];		
		$tempimg_animation_array 	= $request['tempimg_animation1'];		
			
		
		$bulletin_count 			= count($temptext_array);	
		
		for($i=0; $i < $bulletin_count; $i++){
			
			$bulletin_label = $temptext_value = $bulletin_level = $tempimg_animation = $header_animation = '';
			
			$temptext_value  	= $temptext_array[$i];	
			$tempimg_animation 	= $tempimg_animation_array[$i];
			//$bulletin_label_animation 	= $header_animation_array[$i];	
			
			if($bulletin_level=='')
			$bulletin_level = 0;
			
			$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			$opt_sno		= $i+1;
			$temp_txt = mysql_real_escape_string($temptext_value);
			
			$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$bulletin_level."','".$tempimg_animation."')");
			$bid		= $db['master']->getLastID();
			
	
						
			if($_FILES["tempaudio1"]["tmp_name"][$i]!=''){					
					$randomval  = rand(1000,9999);
					$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio1"]["name"][$i];
					$atype 		= $_FILES["tempaudio1"]["type"][$i];
					$asize 		= $_FILES["tempaudio1"]["size"][$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio1"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["tempaudio1"]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'.$aname)){					
					$langid = 1;
					$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
				}			  
			}	
		}
		
	}
		
		
		// Image Template section End
		// Jumbled List Starts here
		if(isset($request['jumbledList'])){		
			$questionval = mysql_real_escape_string($request['jumbledqtext']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$questionval."','jumbledList','".$pagebelongsto."','1','".$request['jsorderid']."')");
			$qInsId = $db['master']->getLastID();
			$audio_language	   = $request['audio_language'];						
			$audio_count  	   = count($audio_language);				
			$audiopath		   = USER_UPLOAD_DIR.'audios/';
			console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
			for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["commonaudio"]["error"][$i] > 0 || $_FILES["commonaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["commonaudio"]["error"][$i]."Languge audtio filename::"."commonaudio");
				}else if($_FILES["commonaudio"]["tmp_name"][$i]!=''){
					$randomval = rand(1000,9999);
					$extension = pathinfo($_FILES["commonaudio"]["name"][$i], PATHINFO_EXTENSION);	
					$aname = date('YmdHis').'_'.$randomval.'.'.$extension;
					$atype = $_FILES["commonaudio"]["type"][$i];
					$asize = $_FILES["commonaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["commonaudio"]["tmp_name"][$i]);
					move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],$audiopath .$aname);	
					$audiopath = $audiopath.$aname;
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','jumbledList')");
				}
			}
			for($i = 0; $i <= count($request['jumbledList']) ; $i++){
				if(trim($request['jumbledList'][$i]) != ''){
					
					$db ['master']->query("INSERT INTO jumbled_list (qid,jumbled_text) VALUES ('".$qInsId."','".mysql_real_escape_string($request['jumbledList'][$i])."')");
				}
			}
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$txtMessage = 1;
				$txtMsg = "Jumbled list added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Failed to Jumbled list";
			}
		}
		// Jumbled List Ends here
		// Canvas uplod section with zip file start
		console(LOG_LEVEL_TRACE, "zip_file Name::".$_FILES["zip_file"]["name"]);
		if($_FILES["zip_file"]["name"]) {		
		$message = $this->addZipFile($pagebelongsto);
		}
		
		// Canvas uplod section with zip file end
		
		
		// Template upload section start
		
		console(LOG_LEVEL_TRACE, "template type:".$request['temp_type']);	
		
		if(isset($request['temp_type']) && $request['temp_type']!=''){
		
		$temp_type 			  = explode('~',$request['temp_type']);
		$temp_type_val 		  = $temp_type[0];
		
		switch($temp_type_val){
		
		case 'true_false_template':
		$message = $this->truefalsetemplate($pagebelongsto);	// true or false template handled in this section	
		break;
		
		case 'template1':		
		/* 
		 Template1
		 1. header part  text - with audio 
		 2. bullein content - center alignment
		 option 1 - text - with audio
		 option 2 - text - with audio
		 option 3 - text - with audio
		 option 4 - text - with audio
		 etc */
		case 'template2':
		
		/*		
		Template 2
		1. header part
		text - with audio
		2. bullein content - center alignment
		 option 1 - text - with audio
		 option 2 - text - with audio
		 option 3 - text - with audio
		 option 4 - text - with audio
		 etc		 
		3. image - with audio		
		*/
		case 'template3':
		
		/* 
		Template 3 
		1. header text - with audio
		2. left bullet left alignment
		3. right bullet right alignment
		*/
		case 'template4':
		/*		
		Template 4
		1.header text - with audio
		2.left bullet left alignment
		3.right side images		
		*/
		$message = $this->AddHeaderBulletins($pagebelongsto); // template1 to template 4 section handled in this function
		break;					

		case 'imagecontent':
		case 'multiple_block':
		case 'left_right_temp':
		case 'evaltemp':
		case 'animation':
		$message = $this->AddImageContent_MultipleBlock($pagebelongsto); // template1 to template 4 section handled in this function
		break;
		}	
		
		}
	
		// Template upload section End
	
		$retarray = array();
		$retarray[0] = $txtMsg.$videoMsg.$fbMsg.$dropdownMsg.$dragMsg.$message.$mtfMsg;
		$retarray[1] = $pagebelongsto;
		return $retarray;
}

public function GetContentDetailszip($id){
		global $db,$request;
		$query 				= "SELECT * from quesvideos where qvid='".$id."'";
		$qtypes 			= $db['master']->getOneRow($query);
		$quesvideo1  		= "SELECT * from questions where  `status`='active' AND qvtype!='tabs'  AND pagebelongsto='".$qtypes['qvid']."' order by aid";
		$quesvideoQuery1 	= $db['master']->getResults($quesvideo1);
		$combinearray = array();
		$combinearray[0] = $quesvideoQuery1;
		$combinearray[1] = $qtypes;
		return $combinearray;
	}
	
	public function GetContentDetails($id){
		global $db,$request;
		$query 				= "SELECT * from quesvideos where qvid='".$id."'";
		$qtypes 			= $db['master']->getOneRow($query);
		$quesvideo1  		= "SELECT * from questions where  `status`='active' AND pagebelongsto='".$qtypes['qvid']."' order by aid";
		$quesvideoQuery1 	= $db['master']->getResults($quesvideo1);
		$combinearray = array();
		$combinearray[0] = $quesvideoQuery1;
		$combinearray[1] = $qtypes;
		return $combinearray;
	}
	public function GetLastAdded(){
		global $db,$request;

		$query 				= "SELECT * from quesvideos order by qvid desc LIMIT 1";
		$qtypes 			= $db['master']->getOneRow($query);
		$quesvideo1  		= "SELECT * from questions where status='active' AND pagebelongsto='".$qtypes['qvid']."' order by aid";
		$quesvideoQuery1 	= $db['master']->getResults($quesvideo1);
		$combinearray = array();
		$combinearray[0] = $quesvideoQuery1;
		$combinearray[1] = $qtypes;
		return $combinearray;
	}
	public function GetLastAddedTab($id){
		global $db,$request;

		$query 				= "SELECT * from quesvideos where qvid='".$id."'";
		$qtypes 			= $db['master']->getOneRow($query);
		$quesvideo1  		= "SELECT * from questions where status='active' AND pagebelongsto='".$qtypes['qvid']."' order by tabid";
		$quesvideoQuery1 	= $db['master']->getResults($quesvideo1);
		$combinearray = array();
		$combinearray[0] = $quesvideoQuery1;
		$combinearray[1] = $qtypes;
		return $combinearray;
	}
	function delQuestionVideos($type = ''){
		global $db,$request;
		$val = $db['master']->getOneRow("SELECT *  FROM questions WHERE qid='".$request['qvid']."' AND status='active'");
		$del_qry =  "update questions set status='removed'  where qid='".$request['qvid']."' and status='active'";
		$updateQuestions = $db['master']->query ($del_qry);
		
		$table = '';
		
		$del_link = "UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$val['qid']."' and status='active'";
		$updatelinkques = $db['master']->query($del_link);
		
		switch($val['qvtype']){		
		case 'true_false_template':
		$table = 'true_false_template';
		break;	
		
		case 'template1':
		case 'template2':
		case 'template3':
		case 'template4':
		$del_qry1 =  "update header set status='removed'  where hid='".$val['hid']."' and status='active'";
		$updateheader = $db['master']->query ($del_qry1);
		
		$del_qry2 =  "update bulletin_content set status='removed'  where hid='".$val['hid']."' and status='active'";
		$updateheader = $db['master']->query ($del_qry2);
		
		break;
		
		
		case 'imagecontent':
		case 'multiple_block':
		case 'left_right_temp':
		$del_qry1 		=  "update header set status='removed'  where hid='".$val['hid']."' and status='active'";
		$updateheader1  = $db['master']->query ($del_qry1);
		
		$del_qry2 		=  "update bulletin_content set status='removed'  where hid='".$val['hid']."' and status='active'";
		$updateheader2  = $db['master']->query ($del_qry2);
		
		$del_qry3 		=  "update language_audios set status='removed'  where qid='".$val['qid']."' and status='active'";
		$updateheader3  = $db['master']->query ($del_qry3);		
	
		
		break;
		
		case 'evaltemp':
		$del_qry3 		=  "update language_audios set status='removed'  where qid='".$val['qid']."' and status='active'";
		$updateheader3  = $db['master']->query ($del_qry3);		
		break;
		
		case 'tabs':
		$del_qry1 =  "update tabs set status='inactive'  where qid='".$val['qid']."' and status='active'";
		$updateheader = $db['master']->query ($del_qry1);			
		break;
		
		case 'question':		
		$del_choose 	=  "update choose_the_best_answer set status='inactive'  where qid='".$val['qid']."' AND status='active'";
		$update_choose  = $db['master']->query ($del_choose);			
		
		$del_ques 		=  "update language_audios set status='inactive'  where qid='".$val['qid']."' AND qtype='question' AND status='active'";
		$updateques 	= $db['master']->query ($del_ques);			
		break;
		
		case 'video':		
		$del_video 		=  "update language_audios set status='inactive'  where qid='".$val['qid']."' AND qtype='video' AND status='active'";
		$update_video 	= $db['master']->query ($del_video);	
		$quesdetails = $db['master']->getOneRow("SELECT aid,qid,qvtype,pagebelongsto FROM questions WHERE qid='".$val['qid']."' AND status='active'");
		$videoaids = $quesdetails['aid'];		
		break;
		
		}
		
		
		
		if($table!=''){
		$del_qry1 =  "update $table set status='removed'  where qid='".$request['qvid']."' and status='active'";
		$updateQuestions = $db['master']->query ($del_qry1);
		}
		
		
		console(LOG_LEVEL_TRACE,'Deleted Questions videos Id-->'.$request['qvid'].' Deleted Question : '.$val['question']);
		
		if($updateQuestions) {
			return 1;
		}else{
			return 2;
		}
	}
	function updateQuestions(){
		global $db,$request;
		$filename = 'edit_file';

		if($request['edit_file']!=''){

			if ($_FILES[$filename]["error"] > 0)  {  
			console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename]["error"]." filename::".$filename);
			}else {
				$vname = $_FILES[$filename]["name"];
				$vtype = $_FILES[$filename]["type"];
				$vsize = $_FILES[$filename]["size"];
				$vsize = $this->formatSizeUnits($vsize);
				console(LOG_LEVEL_TRACE, "video Name::".$vname." video type::".$vtype."video Size".$vsize."Temp file: ".$_FILES[$filename]["tmp_name"]);
				move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR . $_FILES[$filename]["name"]);     
				console(LOG_LEVEL_TRACE, "video Stored in::".USER_UPLOAD_DIR . $_FILES[$filename]["name"]);
			}
			$videopath = $videopath.$vname;
		
			$update_qry =  "update questions set videopath='".$videopath."',vname='".$vname."',vsize='".$vsize."',vtype='".$vtype."'where qid='".$request['editid']."'";
			$updateQuestions = $db['master']->query ($update_qry);
		}else{
			$update_qry =  "update questions set question='".$request['questions']."',obj1='".$request['obj1']."',obj2='".$request['obj2']."',obj3='".$request['obj3']."',obj4='".$request['obj4']."',optanswer='".$request['optanswer']."' where qid='".$request['editid']."'";
			$updateQuestions = $db['master']->query ($update_qry);
			console(LOG_LEVEL_TRACE, "Updated Question :: ". $request['questions']);
		}
	}
	function getVideoQuality($id){
		global $db,$request;
		$query 				= "SELECT vqdefinition from videoquality where vqid='".$id."'";
		$vqdefinition 		= $db['master']->getOneRow($query);
		$vqdefinition		= $vqdefinition['vqdefinition'];
		return $vqdefinition;
	}
	function formatSizeUnits($bytes){
        if ($bytes >= 1073741824){
            $bytes = number_format($bytes / 1073741824, 2) . ' GB';
        }elseif ($bytes >= 1048576){
            $bytes = number_format($bytes / 1048576, 2) . ' MB';
        }elseif ($bytes >= 1024){
            $bytes = number_format($bytes / 1024, 2) . ' KB';
        }elseif ($bytes > 1){
            $bytes = $bytes . ' bytes';
        }elseif ($bytes == 1){
            $bytes = $bytes . ' byte';
        }else{
            $bytes = '0 bytes';
        }
		return $bytes;
	}
	public function updateQuesVidoes(){
		global $db,$request;
	
		$txtCount 	= $request['txtCount'];
		$videoCount = $request['videoCount'];
		
		console(LOG_LEVEL_TRACE, "txtCount:".$txtCount." videoCount::".$videoCount);
		$txtMessage = 1;
		$vqid 		 = 1;
		$langid 	 = $_SESSION['langid'];
		$uid 		 = $_SESSION['uid'];
		$topicid 	 = $_SESSION['topicid'];
		$sid 		 = $_SESSION['sid'];
		$cid		 = $_SESSION['cid'];
		$semid		 = $_SESSION['semid'];
		$univid		 = $_SESSION['unid'];
		$branchid    = $_SESSION['branchid'];
		
		$query 	= "SELECT qvid from quesvideos where univid='".$univid."' AND cid='".$cid."' AND semid='".$semid."' AND  sid='".$sid."' AND  uid='".$uid."'  AND langid='".$langid."' AND topicid='".$topicid."' AND vqid='".$vqid."' AND branch_id='".$branchid."' AND status='active'";
		$result = $db['master']->getOneRow($query);
		
		if($result['qvid'] != ''){
			$pagebelongsto		= $result['qvid'];
		}else{
			$db ['master']->query("INSERT INTO quesvideos (univid,cid,semid,sid,uid,langid,topicid,vqid,branch_id) VALUES ('".$univid."','".$cid."','".$semid."','".$sid."','".$uid."','".$langid."','".$topicid."','".$vqid."','".$branchid."')");
			$pagebelongsto		= $db['master']->getLastID();
		}
		
		/*if($txtCount>0){
			$txtaid 	 = explode(",", $request['txtaid']);
			foreach($txtaid as $i){
				$questions 	 = $request['qtext'.$i];
				$questionval = $obj1 = $obj2 =$obj3 = $obj4 = $optanswer = '';
				$questionval = $questions[0];
				$obj1 		 = $questions[1];
				$obj2 		 = $questions[2];
				$obj3 		 = $questions[3];
				$obj4 		 = $questions[4];
				$optansval   = $request['qanswer'.$i];
				console(LOG_LEVEL_TRACE, "optansval:".$optansval);
				$optanswer 	 = $questions[$optansval];
				$aid = '';
				//$aid = $i;
				console(LOG_LEVEL_TRACE, "txtCount aid:".$aid);
				$aid = $this->setArrangementId($pagebelongsto);
	
				if($_FILES["introaudio_val"]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES["introaudio_val"]["name"];
					$extension = pathinfo($_FILES["introaudio_val"]['name'], PATHINFO_EXTENSION);	
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES["introaudio_val"]["tmp_name"]);
					
					$audiopath = UPLOAD_AUDIO_URL ."chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = "chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES["introaudio_val"]["tmp_name"],UPLOAD_AUDIO_URL ."chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".UPLOAD_AUDIO_URL ."chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);
				}
	
				$db ['master']->query("INSERT INTO questions (question,obj1,obj2,obj3,obj4,optanswer,qvtype,pagebelongsto,aid) VALUES ('".$questionval."','".$obj1."','". $obj2 ."','". $obj3 ."','". $obj4 ."','". $optanswer ."','question','".$pagebelongsto."','".$aid."')");
	
			}
			if($db ['master']->affectedRows()>0){
				$txtMessage = 1;
				$txtMsg = "Question added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Fail to add Questions";
			}
		}*/
	if($request['qtypechoosevalue'] == 'question'){
		
			$questions 	 = $request['qtext1'];
				$questionval = $obj1 = $obj2 =$obj3 = $obj4 = $optanswer = '';
				$questionval = $questions[0];
				$obj1 		 = $questions[1];
				$objective_count = '';				
				$questionsobj 	 = $request['qopt1'];	
			
				$objective_count = count($questionsobj);
				$optansval   = $request['qanswer1'];
				console(LOG_LEVEL_TRACE, "optansval:".$optansval);
				$optanswer 	 = $questionsobj[$optansval];
				
				$aid = '';
				$aid = $this->setArrangementId($pagebelongsto);
				console(LOG_LEVEL_TRACE, "txtCount aid:".$aid);
				
				if($request['qidchoosevalue'] != ""){
					$quesdetails = $db['master']->getOneRow("SELECT aid,qid,qvtype,pagebelongsto FROM questions WHERE qid='".$request['qidchoosevalue']."' AND status='active'");
					$aid = $quesdetails['aid'];
					$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidchoosevalue']."' AND qvtype='".$request['qtypechoosevalue']."' AND status='active'");
					$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidchoosevalue']."' AND qtype='".$request['qtypechoosevalue']."' AND status='active'");
					$db['master']->query("UPDATE choose_the_best_answer SET status='removed' WHERE qid='".$request['qidchoosevalue']."' AND status='active'");
					$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidchoosevalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
					$db['master']->query("UPDATE explanation_topics SET status='inactive' WHERE qid='".$request['qidchoosevalue']."' AND pagebelongsto='".$pagebelongsto."'");
				$db['master']->query("UPDATE question_details SET status='inactive' WHERE qid='".$request['qidchoosevalue']."' AND pagebelongsto='".$pagebelongsto."' AND status='active'");
				}
				
				if($request['questyp'] != ""){
					$qrykey = ",temp_name";
					$qryval = ",'".$request['questyp']."'";
				}
				
				$ques = mysql_real_escape_string($questionval);
				$opt_ans  = mysql_real_escape_string($optanswer);
				
				$db ['master']->query("INSERT INTO questions (question,optanswer,qvtype,pagebelongsto,aid,orderid $qrykey) VALUES ('".$ques."','". (($opt_ans)) ."','question','".$pagebelongsto."','".$aid."','".$request['editquestionorderid']."' $qryval)");
				$lastid = $db['master']->getLastID();
				
				$db['master']->query("INSERT INTO explanation_topics (qid,explanation_id,pagebelongsto) VALUES ('".$lastid."','". $request['explanationtxt'] ."','".$pagebelongsto."')");
				
			$image1 = $image2 = $image3 = $image4 = "";
			if($request['questionpassage'] != ""){
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,passage) VALUES('".$lastid."','".$pagebelongsto."','".mysql_real_escape_string(addslashes($request['questionpassage']))."')";
			}else if($request['questionimgpassage'] != ""){
				$passg = $request['questionimgpassage'];
				if($_FILES['imgpsg']["name"] != ""){
					$randomval = rand(1000,9999);
					$imgname1 = $_FILES['imgpsg']["name"];
					$extension = pathinfo($_FILES['imgpsg']['name'], PATHINFO_EXTENSION);	
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES['imgpsg']["tmp_name"]);
					$imgnme1 = date('YmdHis').'_'.$randomval.'_'.$imgname1;
					if(move_uploaded_file($_FILES['imgpsg']["tmp_name"],USER_UPLOAD_DIR . $imgnme1)){
						console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgnme1);
					}else{
						console(LOG_LEVEL_TRACE, "Error in Moving File to the Path ::".USER_UPLOAD_DIR . $imgnme1);
					}
				}else if($request['editquestionimg0'] != "" && $imgnme1 == ""){
					$imgnme1 = $request['editquestionimg0'];
				}else{
						console(LOG_LEVEL_TRACE, "Audio File is Empty ::".$_FILES['imgpsg']["name"]);
				}
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,passage,image1) VALUES('".$lastid."','".$pagebelongsto."','".mysql_real_escape_string(addslashes($passg))."','".$imgnme1."')";
			}else{
				for($countimg=0; $countimg<=3; $countimg++){
					console(LOG_LEVEL_TRACE, "countimg :: " .$countimg);
					$imgnme = $imgname = "";
					if($_FILES['questionimg']["name"][$countimg] != ""){
						$randomval = rand(1000,9999);
						$imgname = $_FILES['questionimg']["name"][$countimg];
						console(LOG_LEVEL_TRACE, "File name  with countimg val :: ".$_FILES['questionimg']["name"][$countimg]." 0th Image name :: ".$_FILES['questionimg']["name"][0]);
						$extension = pathinfo($_FILES['questionimg']['name'][$countimg], PATHINFO_EXTENSION);	
						console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES['questionimg']["tmp_name"][$countimg]);
						$imgnme = date('YmdHis').'_'.$randomval.'_'.$imgname;
						if(move_uploaded_file($_FILES['questionimg']["tmp_name"][$countimg],USER_UPLOAD_DIR . $imgnme)){
							console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgnme);
							if($countimg == 0){ $image1 = $imgnme; }
							else if($countimg == 1){ $image2 = $imgnme; }
							else if($countimg == 2){ $image3 = $imgnme; }
							else if($countimg == 3){ $image4 = $imgnme; }
						}else{
							console(LOG_LEVEL_TRACE, "Error in Moving File to the Path ::".USER_UPLOAD_DIR . $imgnme);
						}
					}else if($request['editquestionimg'.$countimg] != ""){
						//$imgcnt = $countimg+1;
						if($countimg == 0 && $image1 == ""){ $image1 = $request['editquestionimg0']; }
						if($countimg == 1 && $image2 == ""){ $image2 = $request['editquestionimg1']; }
						if($countimg == 2 && $image3 == ""){ $image3 = $request['editquestionimg2']; }
						if($countimg == 3 && $image4 == ""){ $image4 = $request['editquestionimg3']; }
						console(LOG_LEVEL_TRACE, "Existing Audio $countimg ::".$request['editquestionimg'.$countimg]);
					}else{
						console(LOG_LEVEL_TRACE, "Audio File is Empty for $countimg uploaded audio::".$_FILES['questionimg']["name"][$countimg]." & edited audio :: ".$request['editquestionimg'.$countimg]);
					}
				}
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,image1,image2,image3,image4) VALUES('".$lastid."','".$pagebelongsto."','".$image1."','".$image2."','".$image3."','".$image4."')";
			}
			$result_quesdtls = $db['master']->query($insq_quesdetls);
				
				$quesdetails = $db['master']->getOneRow("SELECT qid,qvtype,pagebelongsto FROM questions WHERE qid='".$lastid."' AND status='active'");
				
				
				if($objective_count>0){
					for($jk=0; $jk < $objective_count; $jk++){			
						$objective = '';				
						$objective = $questionsobj[$jk];
						if($objective!=''){
						 $object_opt = mysql_real_escape_string($objective);
						$db ['master']->query("INSERT INTO choose_the_best_answer (qid,objective,pagebelongsto) VALUES ('".$lastid."','".$object_opt."','".$quesdetails['pagebelongsto']."')");
						}
					}			
				}
		
					if($request['editchoosecount']){
						$count = $request['editchoosecount']-1; console(LOG_LEVEL_TRACE, "Edit lang Count :: ".$request['editchoosecount']);
					}else if($request['audiochoosecount']){
						$count = $request['audiochoosecount']-1;  console(LOG_LEVEL_TRACE, "Audio lang Count :: ".$request['audiochoosecount']);
					}else if($request['audiolangcount']){
						$count = $request['audiolangcount']-1;
					}
					
					if($count == ""){
						$count = 1;
					}
					console(LOG_LEVEL_TRACE, "count   :: ".$count);
				if($count != ""){
					for($i=1; $i<=$count; $i++){
						$language = $request["chooselanguage".$i];
						console(LOG_LEVEL_TRACE, "chooselanguage".$i." :: ".$language);
						
						$filename = '';
						$filename = "introaudio_val".$i;
						
						console(LOG_LEVEL_TRACE, "filename-->".$filename);
						
						
						
						if($_FILES[$filename]["name"]){
							$randomval = rand(1000,9999);
							$aname = $_FILES[$filename]["name"];
							$atype = $_FILES[$filename]["type"];
							$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
							$asize =  $_FILES[$filename]["size"];
							$asize = $this->formatSizeUnits($asize);
							console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
							
							$audiopath = USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							$audioname = "chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);     
							console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);
						}else if($request["eintroaudio_val".$i] != ""){
								
							//$asize =  $_FILES[$filename]["size"];
							//$asize = $this->formatSizeUnits($asize);
							console(LOG_LEVEL_TRACE, "Temp file :: ".$request["eintroaudio_val".$i]);
							
							$audiopath = USER_UPLOAD_DIR."audios/".$request["eintroaudio_val".$i];
							$audioname = $request["eintroaudio_val".$i];
							$asize = $request["eintroaudio_valsize".$i];
							$atype = $request["eintroaudio_valtype".$i];
							console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
						}
						if($language != "" || $audioname != ""){
							$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$quesdetails['qid']."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$quesdetails['pagebelongsto']."','".$quesdetails['qvtype']."')");
						}else{
							console(LOG_LEVEL_TRACE, "Error in inserting into Language Audios :: Language and file Upload is Empty");
						}
					}
					if($db ['master']->affectedRows()>0){
						console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
						$txtMessage = 1;
						$txtMsg = "Question added successfully";
					}else{
						$txtMessage = 0;
						$txtMsg = "Fail to add Questions";
					}
				}
	}	
		
		
		
		
	if($txtCount>0) {
		$txtaid 	 = explode(",", $request['txtaid']);
			foreach($txtaid as $i){  //print_r($request); exit;
				$questions 	 = $request['qtext'.$i];
				$questionval = $obj1 = $obj2 =$obj3 = $obj4 = $optanswer = '';
				$questionval = $questions[0];
				
				$objective_count = '';				
				$questionsobj 	 = $request['qopt'.$i];				
				$objective_count = count($questionsobj);				
				$optansval   = $request['qanswer1'];
				console(LOG_LEVEL_TRACE, "optansval:".$optansval);
				$optanswer 	 = $questionsobj[$optansval];
				$aid = '';
				$aid = $i;
				console(LOG_LEVEL_TRACE, "txtCount aid:".$aid);
				
				if($request['questyp'] != ""){
					$qrykey = ",temp_name";
					$qryval = ",'".$request['questyp']."'";
				}
				$ques = mysql_real_escape_string($questionval);
				$opt_ans = mysql_real_escape_string($optanswer);
				
				$db ['master']->query("INSERT INTO questions (question,optanswer,qvtype,pagebelongsto,aid,orderid $qrykey) VALUES ('".$ques."','". (($opt_ans)) ."','question','".$pagebelongsto."','".$aid."','".$request['questionorderid']."' $qryval)");
				$lastid = $db['master']->getLastID();
				
				$db['master']->query("INSERT INTO explanation_topics (qid,explanation_id,pagebelongsto) VALUES ('".$lastid."','". $request['explanationtxt'] ."','".$pagebelongsto."')");
				
				$quesdetails = $db['master']->getOneRow("SELECT qid,qvtype,pagebelongsto FROM questions WHERE qid='".$lastid."' AND status='active'");
				
				if($objective_count>0){
					for($jk=0; $jk < $objective_count; $jk++){			
						$objective = '';				
						$objective = $questionsobj[$jk];
						
						if($objective!=''){
						$obj_opt = mysql_real_escape_string($objective);
						$db ['master']->query("INSERT INTO choose_the_best_answer (qid,objective,pagebelongsto) VALUES ('".$lastid."','".$obj_opt."','".$quesdetails['pagebelongsto']."')");
						}
					}				
				}
				
				
		$image1 = $image2 = $image3 = $image4 = "";
		if($request['questionpassage'] != ""){
			$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,passage) VALUES('".$lastid."','".$pagebelongsto."','".mysql_real_escape_string(addslashes($request['questionpassage']))."')";
		}else if($request['questionimgpassage'] != ""){
				$passg = $request['questionimgpassage'];
				if($_FILES['imgpsg']["name"] != ""){
					$randomval = rand(1000,9999);
					$imgname1 = $_FILES['imgpsg']["name"];
					$extension = pathinfo($_FILES['imgpsg']['name'], PATHINFO_EXTENSION);	
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES['imgpsg']["tmp_name"]);
					$imgnme1 = date('YmdHis').'_'.$randomval.'_'.$imgname1;
					if(move_uploaded_file($_FILES['imgpsg']["tmp_name"],USER_UPLOAD_DIR . $imgnme1)){
						console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgnme1);
					}else{
						console(LOG_LEVEL_TRACE, "Error in Moving File to the Path ::".USER_UPLOAD_DIR . $imgnme1);
					}
				}else{
						console(LOG_LEVEL_TRACE, "Audio File is Empty ::".$_FILES['imgpsg']["name"]);
				}
				$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,passage,image1) VALUES('".$lastid."','".$pagebelongsto."','".mysql_real_escape_string(addslashes($passg))."','".$imgnme1."')";
		}else{
			for($countimg=0; $countimg<=3; $countimg++){
				console(LOG_LEVEL_TRACE, "countimg :: " .$countimg);
				$imgnme = $imgname = "";
				if($_FILES['questionimg']["name"][$countimg] != ""){
					$randomval = rand(1000,9999);
					$imgname = $_FILES['questionimg']["name"][$countimg];
					$extension = pathinfo($_FILES['questionimg']['name'][$countimg], PATHINFO_EXTENSION);	
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES['questionimg']["tmp_name"][$countimg]);
					$imgnme = date('YmdHis').'_'.$randomval.'_'.$imgname;
					if(move_uploaded_file($_FILES['questionimg']["tmp_name"][$countimg],USER_UPLOAD_DIR . $imgnme)){
						console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgnme);
						if($countimg == 0){ $image1 = $imgnme; }
						else if($countimg == 1){ $image2 = $imgnme; }
						else if($countimg == 2){ $image3 = $imgnme; }
						else if($countimg == 3){ $image4 = $imgnme; }
					}else{
						console(LOG_LEVEL_TRACE, "Error in Moving File to the Path ::".USER_UPLOAD_DIR . $imgnme);
					}
				}else{
					console(LOG_LEVEL_TRACE, "Audio File is Empty ::".$_FILES['questionimg']["name"][$countimg]);
				}
			}
			$insq_quesdetls = "INSERT INTO question_details(qid,pagebelongsto,image1,image2,image3,image4) VALUES('".$lastid."','".$pagebelongsto."','".$image1."','".$image2."','".$image3."','".$image4."')";
		}
		$result_quesdtls = $db['master']->query($insq_quesdetls);
				$quesdetails = $db['master']->getOneRow("SELECT qid,qvtype,pagebelongsto FROM questions WHERE qid='".$lastid."' AND status='active'");
				
				//if($request['audiolangcount'] != "" || $request['addlangcount'] != "")
				//{
					if($request['audiolangcount'] != ""){
						$count = $request['audiolangcount']-1;
						console(LOG_LEVEL_TRACE, " Audio Lang count :: ".$count);
					}else if($request['addlangcount'] != ""){
						$count = $request['addlangcount']-1;
						console(LOG_LEVEL_TRACE, " Add Lang count :: ".$count);
					}
					
					if($count == ""){
						$count = 1;
					}
					console(LOG_LEVEL_TRACE, "count :: ".$count);
					for($i=1; $i<=$count; $i++){
						$language = $request["chooselanguage".$i];
						console(LOG_LEVEL_TRACE, "i :: " .$i);
						console(LOG_LEVEL_TRACE, "chooselanguage".$i." :: ".$language);
						$filename = "introaudio_val".$i;
						if($_FILES[$filename]["name"]){
							$randomval = rand(1000,9999);
							$aname = $_FILES[$filename]["name"];
							$atype = $_FILES[$filename]["type"];
							$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
							$asize =  $_FILES[$filename]["size"];
							$asize = $this->formatSizeUnits($asize);
							console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
							
							$audiopath = USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							$audioname = "chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);     
							console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/chooseaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);
						}
						if($language != "" || $audioname != ""){
							$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$quesdetails['qid']."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$quesdetails['pagebelongsto']."','".$quesdetails['qvtype']."')");
						}else{
							console(LOG_LEVEL_TRACE, "Error in inserting into Language Audios :: Language and file Upload is Empty");
						}
					}
					if($db ['master']->affectedRows()>0){
						console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
						$txtMessage = 1;
						$txtMsg = "Question added successfully";
					}else{
						$txtMessage = 0;
						$txtMsg = "Fail to add Questions";
					}
				//}
			}
	}
	
	
		$videoMessage = 1;
		if($videoCount>0){
			console(LOG_LEVEL_TRACE, "Edit Video in UpdateQuesVideos  :: ");
			$videoaid 	 = explode(",", $request['videoaid']);
			console(LOG_LEVEL_TRACE, "video arrangements:".$request['videoaid']);
			foreach($videoaid as $i){
				$filename = "qvideos".$i;	
				$videopath  = USER_UPLOAD_DIR;
				$aid = '';
				//$aid = $i;
				$allowedExts = array("mp3", "mp4", "wma");
				$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
				console(LOG_LEVEL_TRACE, "filename:".$filename);
				if ($_FILES[$filename]["error"] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename]["error"]." filename::".$filename);
				}else {
					console(LOG_LEVEL_TRACE, "filename vname:".$filename);
					$vname = date('YmdHis').'_'.$_FILES[$filename]["name"];
					$vtype = $_FILES[$filename]["type"];
					$vsize = $_FILES[$filename]["size"];
					$vsize = $this->formatSizeUnits($vsize);
					console(LOG_LEVEL_TRACE, "video Name::".$vname." video type::".$vtype."video Size".$vsize."Temp file: ".$_FILES[$filename]["tmp_name"]);

					move_uploaded_file($_FILES[$filename]["tmp_name"],
					USER_UPLOAD_DIR . $vname);     
					console(LOG_LEVEL_TRACE, "video Stored in::".USER_UPLOAD_DIR . $_FILES[$filename]["name"]);
				}
	  
				$aid = $this->setArrangementId($pagebelongsto);
				$videopath = $videopath.$vname;
				$db ['master']->query("INSERT INTO questions (videopath,vname,vsize,vtype,qvtype,pagebelongsto,aid,streamvideo,orderid) VALUES ('".$videopath."','".$vname."','".$vsize."','".$vtype."','video','".$pagebelongsto."','".$videoaids."','new','".$request['videoorderid']."')");
	
				
				$videoid		   = $db['master']->getLastID();
				$audio_language	   = $request['audio_language'];						
				$audio_count  	   = count($audio_language);				
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
				for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["videoaudio"]["error"][$i] > 0 || $_FILES["videoaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["videoaudio"]["error"][$i]."Languge audtio filename::"."videoaudio");
					}else if($_FILES["videoaudio"]["tmp_name"][$i]!=''){
					
					$randomval = rand(1000,9999);
					$aname = date('YmdHis').'_'.$randomval.'.'.$_FILES["videoaudio"]["name"][$i];
					//$aname = $_FILES["videoaudio"]["name"][$i];
					$atype = $_FILES["videoaudio"]["type"][$i];
					$asize = $_FILES["videoaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["videoaudio"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["videoaudio"]["tmp_name"][$i],
					$audiopath . $aname)){	
					$audiopath = $audiopath.$aname;
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$videoid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','video')");
					
					}
			}
				
					
				}	
	
			}
	
			if($db ['master']->affectedRows()>0){
				$videoMessage = 1;
				$videoMsg = "Videos Uploaded Successfully ";
			}else{
				$videoMessage = 0;
				$videoMsg = "Videos Not Uploaded Successfully ";
			}
		}	
		
		
		if(isset($request['texttempsubject'])){
			$aid = '';
			if($request['qidtxttemp'] != ""){
				$language_audios = $db['master']->getResults("SELECT audiopath,aname,asize,atype,pagebelongsto FROM language_audios WHERE qid='".$request['qidtxttemp']."' AND qtype='text_template' AND status='active'");
				$aid_res =  $db['master']->getOneRow("SELECT aid,hid FROM questions WHERE qid='".$request['qidtxttemp']."' AND qvtype='text_template' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidtxttemp']."' AND qvtype='text_template' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidtxttemp']."' AND qtype='text_template' AND status='active'");
				$db['master']->query("UPDATE header SET status='removed' WHERE hid='".$aid_res['hid']."' AND status='active'");
				$db['master']->query("UPDATE bulletin_content SET status='removed' WHERE hid='".$aid_res['hid']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidtxttemp']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}
			console.log(LOG_LEVEL_TRACE, "Text_template");
			$template_type  	= 'text_template';
			$subjecttxt  		= mysql_real_escape_string($request['texttempsubject']);	
			$header_animation	= $request['headerimg_animation'];	
			
			$db ['master']->query("INSERT INTO header (template_type,header_animation,subjecttxt) VALUES ('".$template_type."','".$header_animation."','".$subjecttxt."')");
		
			$hid		= $db['master']->getLastID();
		
			// make value in question table for template
				   
				   
			$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$request['texttemporderid']."')");
			
			$qInsId		= $db['master']->getLastID();	
			/* Header Details Part End */
		
			/* Bulletin Details Part Start */

			
			
			$headertxt = $temptext = $bulletin_level = $tempimg_animation = $bulletin_label_animation = $header_animation = $bulletin_count =  '';
			$temptext_array = $tempimg_animation_array = '';
				
			$temptext_array  			= $request['temptext1'];		
			$tempimg_animation_array 	= $request['tempimg_animation1'];		
				
			
			$bulletin_count 			= count($temptext_array);
			console(LOG_LEVEL_TRACE, "bulletin count :: ".$bulletin_count);
			
			for($i=0; $i < $bulletin_count; $i++){
				
				$bulletin_label = $temptext_value = $bulletin_level = $tempimg_animation = $header_animation = '';
				
				$temptext_value  	= $temptext_array[$i];	
				$tempimg_animation 	= $tempimg_animation_array[$i];
				//$bulletin_label_animation 	= $header_animation_array[$i];	
				
				if($bulletin_level=='')
				$bulletin_level = 0;
				
				$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
				$opt_sno		= $i+1;
				$temp_txt = mysql_real_escape_string($temptext_value);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$bulletin_level."','".$tempimg_animation."')");
				$bid		= $db['master']->getLastID();

		
				$k = $i+1;		console(LOG_LEVEL_TRACE, "Count $k::".$k);	
				if($_FILES["tempaudio1"]["tmp_name"][$i]!=''){					
						$randomval  = rand(1000,9999);
						$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio1"]["name"][$i];
						$atype 		= $_FILES["tempaudio1"]["type"][$i];
						$asize 		= $_FILES["tempaudio1"]["size"][$i];
						$asize 		= $this->formatSizeUnits($asize);
						console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio1"]["tmp_name"][$i]);
						
						if(move_uploaded_file($_FILES["tempaudio1"]["tmp_name"][$i],
						USER_UPLOAD_DIR .'audios/'.$aname)){					
							$langid = 1;
							$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
							$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
						}			  
				}else if($request["etxttempaudio".$k] != ""){
					if($language_audios != ""){
						foreach($language_audios as $key => $value){ 
							if($value['aname'] == $request["etxttempaudio".$k]){
								console(LOG_LEVEL_TRACE, "in condition audio exists");
								$easize = $value['asize']; 
								$eatype = $value['atype'];
								$eaname = $value['aname']; 
								//$eaname = $request["etxttempaudio".$k];
								$eaudiopath = $value['audiopath']; 
								console(LOG_LEVEL_TRACE, "Temp file :: ".$request["etxttempaudio".$k]);
								$elangid = 1;
								//$audiopath = USER_UPLOAD_DIR."audios/".$request["etxttempaudio".$i];
								//$aname = $request["etxttempaudio".$i];
							}
						}
						$ins = $db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$eaudiopath."','".$elangid."','".$eaname."','".$easize."','".$eatype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					}
				}	
			}
		}

		// Choose the best Images section Start
		
		if(isset($request['chooseTheBestImgQuestion'])){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}
			$answerObjImg = array();
			$optanswer = '';
			for($i = 1; $i <= 4 ; $i++){
				if(!empty($_FILES['queTextAns'.$i]['name'])){
					$randomval = rand(1000,9999);
					$info = pathinfo($_FILES['queTextAns'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['queTextAns'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = CHOOSE_THE_BEST_IMAGE_URL.$pagebelongsto.'_'.$randomval.'_'.$newfilename.$ext;
					move_uploaded_file( $_FILES['queTextAns'.$i]['tmp_name'], $location);
					$answerObjImg[] = $location;
					if($request['qanswer'] == $i){
						$optanswer = $location;
					}
				}else if($request["hide_choose_img_file_".$i]){
					$answerObjImg[] = $request["hide_choose_img_file_".$i];
					if($request['qanswer'] == $i){
						$optanswer = $request["hide_choose_img_file_".$i];
					}
				}
			}
			$qryStrCol = '';
			$qryStr = '';
			$questionval = $request['chooseTheBestImgQuestion'];
			foreach($answerObjImg as $key => $value){
				if($qryStr == ''){
					$qryStrCol = 'obj'.($key+1);
					$qryStr = '\''.(($value)).'\'';
				}else{
					$qryStrCol .= ',obj'.($key+1);
					$qryStr .= ',\''.(($value)).'\'';
				}
				
			}
			console(LOG_LEVEL_TRACE, "optansval:".$optanswer);
			
			$ques = mysql_real_escape_string($questionval);
			$opt_ans = mysql_real_escape_string($optanswer);
			
			$db ['master']->query("INSERT INTO questions (question,".$qryStrCol.",optanswer,qvtype,pagebelongsto,aid,orderid) VALUES ('".$ques."',".$qryStr.",'". (($opt_ans)) ."','chooseTheBestImg','".$pagebelongsto."','".$aid."','".$request['chooseorderid']."')");
			$qid = $db['master']->getLastID();
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','chooseTheBestImg')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$txtMessage = 1;
				$txtMsg = "Question added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Fail to add Questions";
			}
		}
		// Choose the best Images section End
		
		// Dropdown section Start
			if(isset($request['drop'])){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='dropdown' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='dropdown' AND status='active'");
				$db['master']->query("UPDATE fill_in_the_blank_answer SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='dropdown' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];$addid = $request['edit_addid'];
			}else{
			$aid = $this->setArrangementId($pagebelongsto);
				$addid = $request['addid'];
			}
			
			$ques = mysql_real_escape_string($request['drop']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($ques))."','dropdown','".$pagebelongsto."','".$aid."','".$request['dropdwnorderid']."')");
			$qid = $db['master']->getLastID();
			$i = 0;
			
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','dropdown')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			
			for($i=1; $i<=$addid; $i++){
				$opt1 = mysql_real_escape_string($request['fbopt1_'.$i]);   
				$opt2 = mysql_real_escape_string($request['fbopt2_'.$i]);   
				$opt3 = mysql_real_escape_string($request['fbopt3_'.$i]);   
				$ans = mysql_real_escape_string($request['fbans_'.$i]);   
				if($ans == 1){ $ans = $opt1;} else if($ans == 2){ $ans = $opt2;}else if($ans == 3){ $ans = $opt3;}
				
				if($i == 1){ $values = "('".$qid."','".(($opt1))."','".(($opt2))."','".(($opt3))."','".(($ans))."')"; }
				else{$values .= ",('".$qid."','".(($opt1))."','".(($opt2))."','".(($opt3))."','".(($ans))."')"; }
			}
			$db ['master']->query("INSERT INTO fill_in_the_blank_answer (qid,obj1,obj2,obj3,answer) VALUES ".$values."");
			if($db ['master']->affectedRows()>0){
				$dropdownMessage = 1;
				$dropdownMsg =  "DropdownValidate in the blanks added successfully";
			}else{
				$dropdownMessage = 0;
				$dropdownMsg = "Fail to add dropdown";
			}
		}
		// Dropdown section End
		
		// Fill in the Blanks section Start
		if(isset($request['blank'])){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE fill_in_the_blank_answer SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];$addidBlank = $request['edit_addidBlank'];
			}else{$addidBlank = $request['addidBlank'];$aid = $this->setArrangementId($pagebelongsto);}
			
			$ques = mysql_real_escape_string($request['blank']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($ques))."','fib','".$pagebelongsto."','".$aid."','".$request['fiborderid']."')");
			$qid = $db['master']->getLastID();
			
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','fib')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			$i = 0;
			for($i=1; $i<=$addidBlank; $i++){
				$ans = trim(mysql_real_escape_string($request['fbopt1_'.$i]));   
				if($i == 1){ $values = "('".$qid."','".(($ans))."')"; }
				else{$values .= ",('".$qid."','".(($ans))."')"; }
			}
			$db ['master']->query("INSERT INTO fill_in_the_blank_answer (qid,answer) VALUES ".$values."");
			if($db ['master']->affectedRows()>0){
				$fbMessage = 1;
				$fbMsg =  "Fill in the blanks added successfully";
			}else{
				$fbMessage = 0;
				$fbMsg = "Fail to add fill in the blanks";
			}
		}
		// Fill in the Blanks section End
	
		// Drag & Drop (Text) section Start
			if(isset($request['ddText'])){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE fill_in_the_blank_answer SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];$addidText = $request['edit_addidText'];
			}else{$addidText = $request['addidText'];$aid = $this->setArrangementId($pagebelongsto);}
			
			$ques = mysql_real_escape_string($request['ddText']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($ques))."','dragDropText','".$pagebelongsto."','".$aid."','".$request['dragdroptorderid']."')");
			$qid = $db['master']->getLastID();
			
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','dragDropText')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			$i = 0;
			for($i=1; $i<=$addidText; $i++){
				$ans = trim(mysql_real_escape_string($request['fbopt1_'.$i]));  
				if($i == 1){ $values = "('".$qid."','".$ans."')"; }
				else{$values .= ",('".$qid."','".$ans."')"; }
			}
			$db ['master']->query("INSERT INTO fill_in_the_blank_answer (qid,answer) VALUES ".$values."");
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Fill in the Blanks Added: ".$request['blank']);
				$fbMessage = 1;
				$fbMsg =  "Fill in the blanks added successfully";
			}else{
				$fbMessage = 0;
				$fbMsg = "Fail to add fill in the blanks";
			}
		}
		// Drag & Drop (Text) section end
		
		// Drag & Drop section Start
		if(isset($request['drag_question'])){
			$aid = '';
			if($request['qidvalue'] != ""){
			
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='dragdrop' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='dragdrop' AND status='active'");
				$db['master']->query("UPDATE dd_sec_headings SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE dd_answers SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='dragdrop' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}
			
			$section_name1 = mysql_real_escape_string($request['drag_sec_1']);
			$section_name2 = mysql_real_escape_string($request['drag_sec_2']);
			$question = mysql_real_escape_string($request['drag_question']);
			
			$ques = mysql_real_escape_string($question);
			
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".(($question))."','dragdrop','".$pagebelongsto."','".$aid."','".$request['dragdroporderid']."')");
			$qid = $db['master']->getLastID();
			
			$db ['master']->query("INSERT INTO dd_sec_headings (qid,section_name) VALUES ('".$qid."','".(($section_name1))."')");
			$secId1 = $db['master']->getLastID();
			
			$db ['master']->query("INSERT INTO dd_sec_headings (qid,section_name) VALUES ('".$qid."','".(($section_name2))."')");
			$secId2 = $db['master']->getLastID();
			
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','dragdrop')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			
			for($i = 1; $i <= 6 ; $i++){
				if(!empty($_FILES['drag_upload_'.$i]['name'])){
					$randomval = rand(1000,9999);
					$info = pathinfo($_FILES['drag_upload_'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['drag_upload_'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = DRAG_DROP_IMAGE_URL.$randomval.'_'.$newfilename.$ext;
					move_uploaded_file( $_FILES['drag_upload_'.$i]['tmp_name'], $location);
					$section_id = '';
					if($request['drag_1_'.$i] == 1){$section_id = $secId1;}
					else if($request['drag_2_'.$i] == 2){$section_id = $secId2;}
					else{$section_id = 0;}
					$db ['master']->query("INSERT INTO dd_answers (qid,image_path,section_id) VALUES ('".$qid."','".(($location))."','".$section_id."')");
					
				}else if($request["hide_drag_img_file_".$i]){
					$location = DRAG_DROP_IMAGE_URL.$request["hide_drag_img_file_".$i];
					$section_id = '';
					if($request['drag_1_'.$i] == 1){$section_id = $secId1;}
					else if($request['drag_2_'.$i] == 2){$section_id = $secId2;}
					else{$section_id = 0;}
					$db ['master']->query("INSERT INTO dd_answers (qid,image_path,section_id) VALUES ('".$qid."','".(($location))."','".$section_id."')");
				}
				
			}
		
			if($db ['master']->affectedRows()>0){
				$dragMessage = 1;
				$dragMsg = "drag and drop Uploaded Successfully ";
			}else{
				$dragMessage = 0;
				$dragMsg = "Videos Not Uploaded drag and drop ";
			}
		}
		// Drag & Drop section End
		
		// Match the following section Start
		if($request['matchId'] == 1){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE match_the_following SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('matching','matching','".$pagebelongsto."','".$aid."','".$request['matchorderid']."')");
			$qid = $db['master']->getLastID();
			
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','matching')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qid."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			$i = 0;
			for($i=1; $i<=6; $i++){
				$quetion = '';$answer = '';
				$quetion = trim(mysql_real_escape_string($request['match_ques_'.$i]));   
				$answer = trim(mysql_real_escape_string($request['match_ans_'.$i]));   
				if(($quetion != '') && ($answer != '')){
					$db ['master']->query("INSERT INTO match_the_following (qid,question,answer) VALUES('".$qid."','".(($quetion))."','".(($answer))."')");
				}
			}
			
			if($db ['master']->affectedRows()>0){
				$mtfMessage = 1;
				$mtfMsg =  "Match the following added successfully";
			}else{
				$mtfMessage = 0;
				$mtfMsg = "Fail to add match the following";
			}
		}
		// Match the following End
		
		// Image Tab section Start
		if(isset($request['imageTab'])){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE image_tab SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}
			$questionval = mysql_real_escape_string($request['imageTab']);

			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$questionval."','imageTab','".$pagebelongsto."','".$aid."','".$request['imagetaborderid']."')");
			$qInsId = $db['master']->getLastID();
			if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}else if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qInsId."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','imageTab')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qInsId."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			$tempThumbArr = array();
			$tempVideoArr = array();
			for($i = 1; $i <= 10 ; $i++){
				if(!empty($_FILES['thumbnail'.$i]['name'])){
					$fileSize = 0;
					$randomval = rand(1000,9999);
					$fileSize = round(filesize($_FILES['thumbnail'.$i]['tmp_name'])/1024,2);
					$info = pathinfo($_FILES['thumbnail'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['thumbnail'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = IMAGE_TAB_THUMBNAIL_URL.$qInsId.'_'.$randomval.'_'.$newfilename.'jpg';
					$res = move_uploaded_file( $_FILES['thumbnail'.$i]['tmp_name'], $location);
					if($res){ 
						console(LOG_LEVEL_INFO, $location." - Filesize: ".$fileSize." - Thumbnail uploaded successfully");
					} else { 
						console(LOG_LEVEL_TRACE, $location." - Filesize: ".$fileSize." - Thumbnail upload failed");
					}
					$tempThumbArr[$i] = $location;
				}else if($request["hide_img_tab_thumb_file_".$i]){
					$tempThumbArr[$i] = $request["hide_img_tab_thumb_file_".$i];
				}
				
				if(!empty($_FILES['video'.$i]['name'])){
					$fileSize = 0;
					$randomval = rand(1000,9999);
					$fileSize = round(filesize($_FILES['video'.$i]['tmp_name'])/1024,2);
					$info = pathinfo($_FILES['video'.$i]['name']);
					$ext = $info['extension'];
					$newfilename = basename($_FILES['video'.$i]['name'], $ext);
					$newfilename = str_replace(" ","_",$newfilename);
					$location = IMAGE_TAB_VIDEO_URL.$qInsId.'_'.$randomval.'_'.$newfilename.$ext;
					$resVideo = move_uploaded_file( $_FILES['video'.$i]['tmp_name'], $location);
					if($resVideo){ 
						console(LOG_LEVEL_INFO, $location." - Filesize: ".$fileSize." - Video uploaded successfully");
					} else { 
						console(LOG_LEVEL_TRACE, $location." - Filesize: ".$fileSize." - Video upload failed");
					}					
					$tempVideoArr[$i] = $location;
				}else if($request["hide_img_tab_video_file_".$i]){
					$tempVideoArr[$i] = $request["hide_img_tab_video_file_".$i];
				}
			}
			for($i = 1; $i <= 10 ; $i++){
				if(trim($request['imageTitle'.$i]) != ''){
					$db ['master']->query("INSERT INTO image_tab (qid,video_title,thumbnail_url,video_url) VALUES ('".$qInsId."','".$request['imageTitle'.$i]."','".$tempThumbArr[$i]."','".$tempVideoArr[$i]."')");
				}
			}
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$txtMessage = 1;
				$txtMsg = "Question added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Fail to add Questions";
			}
		}
		// Image Tab section End
		
		// Image Template section Start
		if($request['image_template'] == 1){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE header SET status='removed' WHERE hid='".$request['hidvalue']."' AND status='active'");
				$db['master']->query("UPDATE img_temp_media SET status='removed' WHERE qid='".$request['qidvalue']."' AND  hid='".$request['hidvalue']."' AND status='active'");
				$db['master']->query("UPDATE bulletin_content SET status='removed' WHERE hid='".$request['hidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}
			
			//Header table Insert
			$img_temp_header_insert = mysql_real_escape_string($request['img_temp_header']);
			$db ['master']->query("INSERT INTO header (htext,template_type) VALUES ('".(($img_temp_header_insert))."','Image_Template')");
			$hid = $db['master']->getLastID();
			
			//Questions table Insert
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('Image_Template','Image_Template','".$pagebelongsto."','".$aid."','".$hid."','".$request['image_template_qtype']."','".$request['imgtemporderid']."')");
			$qid = $db['master']->getLastID();
			
			//Media Insert Part Start
			$hide_com_med_audio 	 = $request['hide_com_med_audio'];				
			$img_temp_med_lang 	 = $request['img_temp_med_lang'];	
			$hide_com_med_file 	 = $request['hide_com_med_file'];				
			$img_temp_label 	 = $request['img_temp_label'];				
			$img_temp_label_count = count($img_temp_label);
			
			for($i=0;$i<$img_temp_label_count;$i++){
				$label = '';$media_name = '';$mid = '';				
				$type = '';$path = '';$name = '';				
				$label = mysql_real_escape_string($img_temp_label[$i]);
				
				if(!empty($_FILES["img_temp_media"]["name"][$i])){
					$randomval = rand(1000,9999);
					$type = $_FILES["img_temp_media"]["type"][$i];
					$extension = pathinfo($_FILES["img_temp_media"]['name'][$i], PATHINFO_EXTENSION);	
					$path = MEDIA_UPLOAD_DIR.$qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					$name = $qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES["img_temp_media"]["tmp_name"][$i],MEDIA_UPLOAD_DIR.$qid. date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Media Stored in :: ".MEDIA_UPLOAD_DIR.$qid. date('YmdHis').'_'.$randomval.'.'.$extension);
										
					$db ['master']->query("INSERT INTO img_temp_media(hid,qid,label,media_type,media_name) VALUES ('".$hid."','".$qid."','".$label."','".$type."','".$name."')");
					$mid = $db['master']->getLastID();
				}else if($hide_com_med_file[$i]){
					
					$name = $hide_com_med_file[$i];
					console(LOG_LEVEL_TRACE, "Media Already Stored in :: ".MEDIA_UPLOAD_DIR.$name);
					
					$res2 = $db['master']->getOneRow("SELECT * FROM img_temp_media WHERE qid='".$request['qidvalue']."' AND media_name = '".$name."'");
					
					$db['master']->query("INSERT INTO img_temp_media(hid,qid,label,media_type,media_name) VALUES('".$hid."','".$qid."','".$label."','".$res2['media_type']."','".$name."')");
					$mid = $db['master']->getLastID();
				}
				if(!empty($_FILES["img_temp_med_audio"]["name"][$i])){
					$randomval = rand(1000,9999);
					$aname =  $_FILES["img_temp_med_audio"]["name"][$i];
					$atype = $_FILES["img_temp_med_audio"]["type"][$i];
					$extension = pathinfo($_FILES["img_temp_med_audio"]['name'][$i], PATHINFO_EXTENSION);	
					$asize = $_FILES["img_temp_med_audio"]["size"][$i];
					$asize = $this->formatSizeUnits($asize);
					$audiopath = USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = $qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES["img_temp_med_audio"]["tmp_name"][$i],USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);console(LOG_LEVEL_TRACE, "Media Audios Stored in :: ".USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);
					
								
					$language = $img_temp_med_lang[$i];
					
					if($language != "" || $audioname != ""){
						$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,mid) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','Image_Template','".$hid."','".$mid."')");
					}else{
						console(LOG_LEVEL_TRACE, "Error in inserting into Media Audios :: Language and file Upload is Empty");
					}
					
				}else if($hide_com_med_audio[$i]){
					$language = $img_temp_med_lang[$i];
					$audioname = $hide_com_med_audio[$i];
					$audiopath = USER_UPLOAD_DIR."audios/".$audioname;
					console(LOG_LEVEL_TRACE, "Bulletin Audios Already Stored in :: ".USER_UPLOAD_DIR."audios/".$audioname);
					
					$res1 = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$audioname."'");
					
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,mid) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$res1['asize']."','".$res1['atype']."','".$pagebelongsto."','Image_Template','".$hid."','".$mid."')");
				}
			}
			//Media Insert Part End
			
			//Bulletin Insert Part Start
			$hide_com_bul_file 	 = $request['hide_com_bul_file'];				
			$img_temp_bul_level 	 = $request['img_temp_bul_level'];				
			$img_temp_bul_animation 	 = $request['img_temp_bul_animation'];				
			$img_temp_bul_text 	 = $request['img_temp_bul_text'];				
			$img_temp_bul_text_count = count($img_temp_bul_text);
			$audio_language  = $request['audio_language'];				
					
			for($i=0;$i<$img_temp_bul_text_count;$i++){
				if (!empty($img_temp_bul_text[$i])) {
				$bul_text = '';$media_name = '';$bid = '';$txt_animation = '';$txt_level = '';
				$bul_text = $img_temp_bul_text[$i];
				$txt_animation = $img_temp_bul_animation[$i];
				$txt_level = $img_temp_bul_level[$i];
				if($txt_level == ''){$txt_level = 0;}
				$bul_txt = mysql_real_escape_string($bul_text);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,txt_value,txt_animation,txt_level) VALUES ('".$hid."','".(($bul_txt))."','".$txt_animation."','".$txt_level."')");
				$bid = $db['master']->getLastID();
				
				if(!empty($_FILES["commonaudio"]["name"][$i])){
					$randomval = rand(1000,9999);
					$aname =  $_FILES["commonaudio"]["name"][$i];
					$atype = $_FILES["commonaudio"]["type"][$i];
					$extension = pathinfo($_FILES["commonaudio"]['name'][$i], PATHINFO_EXTENSION);	
					$asize = $_FILES["commonaudio"]["size"][$i];
					$asize = $this->formatSizeUnits($asize);
					$audiopath = USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = $qid. date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES["commonaudio"]["tmp_name"][$i],USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);console(LOG_LEVEL_TRACE, "Bulletin Audios Stored in :: ".USER_UPLOAD_DIR."audios/".$qid. date('YmdHis').'_'.$randomval.'.'.$extension);
					
					$language = $audio_language[$i];
					
					if($language != "" || $audioname != ""){
						$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','Image_Template','".$hid."','".$bid."')");
					}else{
						console(LOG_LEVEL_TRACE, "Error in inserting into Bulletin Audios :: Language and file Upload is Empty");
					}
					
				}else if($hide_com_bul_file[$i]){
					$language = $audio_language[$i];
					$audioname = $hide_com_bul_file[$i];
					$audiopath = USER_UPLOAD_DIR."audios/".$audioname;
					console(LOG_LEVEL_TRACE, "Bulletin Audios Already Stored in :: ".USER_UPLOAD_DIR."audios/".$audioname);
					
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$audioname."'");
					
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qid."','".$audiopath."','".$language."','".$audioname."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','Image_Template','".$hid."','".$bid."')");
				}	
				}
			}
			
			//Bulletin Insert Part End
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$imgTabMessage = 1;
				$imgTabMsg = "Image Template added successfully";
			}else{
				$imgTabMessage = 0;
				$imgTabMsg = "Fail to add Image Template";
			}
			
			
		}
		// Image Template section End
		// Jumbled list starts here
		if(isset($request['jumbledList'])){
			$aid = '';
			if($request['qidvalue'] != ""){
				$aid_res =  $db['master']->getOneRow("SELECT aid FROM questions WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidvalue']."' AND qvtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE jumbled_list SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidvalue']."' AND qtype='".$request['qtypevalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				$aid = $aid_res['aid'];
			}else{
				$aid = $this->setArrangementId($pagebelongsto);
			}

			$questionval = mysql_real_escape_string($request['jumbledqtext']);
			$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$questionval."','jumbledList','".$pagebelongsto."','".$aid."','".$request['jsorderid']."')");
			$qInsId = $db['master']->getLastID();
			
			if($request['edit_com_aud_count'] > 0){
				$count = $request['edit_com_aud_count'];  
			}else if($request['com_aud_count'] > 0) {
				$count = $request['com_aud_count']; 
			}
			for($i=1; $i<=$count; $i++){
				$language = $request["com_aud_lang_".$i];
				console(LOG_LEVEL_TRACE, "com_aud_lang_".$i." :: ".$language);
				$filename = "com_aud_file_".$i;
				
				if($_FILES[$filename]["name"]){
					$randomval = rand(1000,9999);
					$aname = $_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
					$asize =  $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
					
					$audiopath = USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension;
					$audioname = date('YmdHis').'_'.$randomval.'.'.$extension;
					move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);     
					console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/". date('YmdHis').'_'.$randomval.'.'.$extension);
					$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qInsId."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$pagebelongsto."','jumbledList')");
				}else if($request["hide_com_aud_file_".$i]){
						
					//$asize =  $_FILES[$filename]["size"];
					//$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Temp file :: ".$request["hide_com_aud_file_".$i]);
					
					$audiopath = USER_UPLOAD_DIR."audios/".$request["hide_com_aud_file_".$i];
					$audioname = $request["hide_com_aud_file_".$i];
					console(LOG_LEVEL_TRACE, "Audio Already Stored in :: ".USER_UPLOAD_DIR.$audioname);
					$res = $db['master']->getOneRow("SELECT * FROM language_audios WHERE qid='".$request['qidvalue']."' AND aname = '".$request["hide_com_aud_file_".$i]."'");
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$qInsId."','".$audiopath."','".$language."','".$res['aname']."','".$res['asize']."','".$res['atype']."','".$pagebelongsto."','".$res['qtype']."')");
				}
			}
			
			for($i = 0; $i <= count($request['jumbledList']) ; $i++){
				if(trim($request['jumbledList'][$i]) != ''){
					$db ['master']->query("INSERT INTO jumbled_list (qid,jumbled_text) VALUES ('".$qInsId."','".mysql_real_escape_string($request['jumbledList'][$i])."')");
				}
			}
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Question Added: ".$questionval);
				$txtMessage = 1;
				$txtMsg = "Jumbled list added successfully";
			}else{
				$txtMessage = 0;
				$txtMsg = "Failed to Jumbled list";
			}
		}
		// Jumbled list ends here		
		console(LOG_LEVEL_TRACE, "zip_file Name::".$_FILES["zip_file"]["name"]);
		if($_FILES["zip_file"]["name"]) {		
		$message = $this->addZipFile($pagebelongsto);
		}
		console(LOG_LEVEL_TRACE, "template type:".$request['temp_type']);	
		
		if(isset($request['temp_type']) && $request['temp_type']!=''){
		
		$temp_type 			  = explode('~',$request['temp_type']);
		$temp_type_val 		  = $temp_type[0];
		switch($temp_type_val){
		
		case 'true_false_template':
		$message = $this->truefalsetemplate($pagebelongsto);		
		break;
		
		case 'template1':		
		case 'template2':
		case 'template3':
		case 'template4':
		$message = $this->AddHeaderBulletins($pagebelongsto);
		break;		
		
		case 'imagecontent':
		case 'multiple_block':
		case 'left_right_temp':
		case 'evaltemp':
		case 'animation':
		$message = $this->AddImageContent_MultipleBlock($pagebelongsto); // 
		break;
		
		
		}
		
		
		}
	
		
		if($request['qtypetfvalue'] == 'true_false_template'){
			$message = $this->truefalsetemplate($pagebelongsto);
		}
		
		$retarray = array();
		$retarray[0] = $txtMsg.$videoMsg.$fbMsg.$dropdownMsg.$dragMsg.$message.$mtfMsg;
		$retarray[1] = $pagebelongsto;
		return $retarray;
	}
	public function getDownloadData($univId){
		global $db,$request;
		$query = "SELECT univ.univid,univ.university,c.coursename,s.semname,sub.sname,u.uname,t.topicid,t.topic_name,l.lang_name,q.qvid,vq.vqdefinition,
		                        IF(q.branch_id=0,'common',br.branchname) AS branchname FROM university AS univ 
								JOIN course AS c ON (univ.univid = c.univid) 
								JOIN semester AS s ON (c.cid = s.cid) 
								JOIN subject AS sub ON (s.semid = sub.semid) 
								JOIN units AS u ON (sub.sid = u.sid) 
								JOIN topics AS t ON (u.uid = t.uid) 
								JOIN quesvideos AS q ON (t.topicid = q.topicid AND sub.sid = q.sid AND u.uid = q.uid) 
								JOIN language AS l ON q.langid = l.langid 
								JOIN videoquality AS vq ON q.vqid = vq.vqid
								JOIN branch AS br ON (q.branch_id = 0 OR q.branch_id  = br.branch_id)
								WHERE univ.univid ='".$univId."' AND c.status = 'active' 
								AND s.status = 'active' AND sub.status = 'active'
								AND t.status = 'active' AND  q.status = 'active'
								AND l.status = 'active' AND q.publish_status IN ('live','revision') 
								GROUP BY t.topicid
								ORDER BY c.coursename,s.semname,br.branchname,sub.sname,u.uname,t.topic_name,l.lang_name";
								$courseData = $db['master']->getResults($query);		
		return $courseData;
	}
	public function getRatingDataByUniversityId($univId){
		global $db, $request;
		$return_array = array();

		$query = "SELECT r.topicid AS topicid, AVG(r.rating_value) AS avg_rating, COUNT(r.rating_value) AS count_rating 
					FROM feedback_ratings AS r 
					JOIN quesvideos AS q ON (q.topicid = r.topicid)
					JOIN topics AS t ON (t.topicid = q.topicid AND t.topicid = r.topicid)
					WHERE q.univid='".$univId."' AND q.status='active' AND t.status='active' AND r.status='active' AND  q.publish_status IN ('live','revision') GROUP BY r.topicid";
		$ratingData = $db['master']->getResults($query);

		if(!empty($ratingData)){
			foreach($ratingData as $key => $value){
				$return_array[$value['topicid']] = $value;
			}
		}
		return $return_array;

	}
	public function addXmlFileInfo($fileName,$encryptFileName){
		global $db,$request;
		$db ['master']->query("DELETE from xml_file_names where xml_question_id='".$fileName."' AND xml_question_hash='".$encryptFileName.".xml' ");
		$db ['master']->query("INSERT INTO xml_file_names (xml_question_id,xml_question_hash) VALUES ('".$fileName."','".$encryptFileName.".xml')");
	}
	
public function AddImageContent_MultipleBlock($pagebelongsto){
	
		global $db,$request;	
		$template_type  	= $request['temp_type'];
		
		
		$temp_type 			  = explode('~',$request['temp_type']);
		$template_type		  = $temp_type[0];
		$temp_name			  = $temp_type[1];	
		
		
		switch($template_type){
		
		case 'imagecontent':
	
		/* header part details  Start */
		$subjecttxt  		= mysql_real_escape_string($request['subjecttxt']);			
		$header_animation 	= $request['headerimg_animation'];	
		$filename1 			= 'headerimg';
		$filename2 			= 'headerimg_audio';
		/* header part details  End */
	
		if($_FILES['headerimg']["name"]){	
					$randomval 	= rand(1000,9999);					
					$video_image_name 		= date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg']["name"];
					$video_image_type 		= $_FILES['headerimg']["type"];
					$video_image_size 		= $_FILES['headerimg']["size"];
					$video_image_size 		= $this->formatSizeUnits($video_image_size);
					console(LOG_LEVEL_TRACE, "Header Video/image Name::".$video_image_name."Header video/image Type::".$video_image_type."Header /image Size::".$video_image_size."Temp file: ".$_FILES['headerimg']["tmp_name"]);
					
		}
	
		if($_FILES['headerimg_audio']["name"]){	
					$randomval = rand(1000,9999);					
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg_audio']["name"];
					$atype = $_FILES['headerimg_audio']["type"];
					$asize = $_FILES['headerimg_audio']["size"];
					$asize = $this->formatSizeUnits($asize);
					
					console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES['headerimg_audio']["tmp_name"]);	
					
					console(LOG_LEVEL_TRACE, "Audio Stored in::".USER_UPLOAD_DIR . $aname);						
				
		}		
				
	if(move_uploaded_file($_FILES['headerimg']["tmp_name"],
					USER_UPLOAD_DIR . $video_image_name)){	
			console(LOG_LEVEL_TRACE, "Video or Image Stored in::".USER_UPLOAD_DIR . $video_image_name);			
		$db ['master']->query("INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) VALUES ('".$template_type."','".$aname."','".$asize."','".$header_animation."','".$subjecttxt."','".$video_image_name."','".$video_image_size."','".$video_image_type."')");

		$hid		= $db['master']->getLastID();	
		
		 // make value in question table for template
			   
		$aid = $this->setArrangementId($pagebelongsto);
			   

		$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['imgcntorderid']."')");
		
		$qInsId		= $db['master']->getLastID();	

		if(move_uploaded_file($_FILES['headerimg_audio']["tmp_name"],
					USER_UPLOAD_DIR .'audios/'. $aname) && $hid!=''){
		$langid = 1;
		$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
		$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."')");
		}
	
	
		/* Bulletin Part Start */
		
		$bulletin_label  		= $request['bulletin_label'];
		$bulletin_text			= $request['bulletin_text'];
		$filename				= "tempaudio";
		$bulletin_count 		= count($bulletin_text);
		$temptext_animate		= $request['tempimg_animation'];
		$bulletin_level			= $request['bulletin_level'];
		//$bulletin_label_animation 	= $request['headerimg_animation'];	
		
		/* Bulletin Part End */
		console(LOG_LEVEL_TRACE, "bulletin count::".$bulletin_count);
		
		
			for($i=0; $i < $bulletin_count; $i++){
			//print_r($_FILES[$filename]["tmp_name"]);
			
			console(LOG_LEVEL_TRACE, "bulletin count increment $i::".$i);
			$temptext_value = $opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			$opt_sno		= $i+1;
			$temptext_value = $bulletin_text[$i];	
			$txt_animation  = $temptext_animate[$i];
			$txt_level  	= $bulletin_level[$i];
			
			if($txt_level=='')
			$txt_level = 0;
			
			if($temptext_value != ""){
				$temp_text = mysql_real_escape_string($temptext_value);
				$bullet_label = mysql_real_escape_string($bulletin_label);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,bulletin_label,bulletin_label_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$txt_level."','".$txt_animation."','".$bullet_label."','".$bulletin_label_animation."')");
					
			$bid		= $db['master']->getLastID();
						
			if($_FILES["tempaudio"]["tmp_name"][$i]!=''){					
					$randomval  = rand(1000,9999);
					$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio"]["name"][$i];
					$atype 		= $_FILES["tempaudio"]["type"][$i];
					$asize 		= $_FILES["tempaudio"]["size"][$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["tempaudio"]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'.$aname)){					
						$langid = 1;
						$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
						$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					}			  
				}
			}else{
				console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
			}
		}	
	}
	
	break;
	case 'animation':
		console(LOG_LEVEL_TRACE, "Animation :: in AddImageContent_MultipleBlock");
		/* header part details  Start */
		$subjecttxt  		= mysql_real_escape_string($request['subjecttxt']);			
		$header_animation 	= $request['headerimg_animation'];	
		$filename1 			= 'headerimg';
		$filename2 			= 'headerimg_audio';
		$qryid = ""; $qryval = "";
		/* header part details  End */
	
		if($_FILES['headerimg']["name"]){	
					$randomval 	= rand(1000,9999);					
					$video_image_name 		= date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg']["name"];
					$video_image_type 		= $_FILES['headerimg']["type"];
					$video_image_size 		= $_FILES['headerimg']["size"];
					$video_image_size 		= $this->formatSizeUnits($video_image_size);
					console(LOG_LEVEL_TRACE, "Header Video/image Name::".$video_image_name."Header video/image Type::".$video_image_type."Header /image Size::".$video_image_size."Temp file: ".$_FILES['headerimg']["tmp_name"]);
					
		}
	
		if($_FILES['headerimg_audio']["name"]){	
					$randomval = rand(1000,9999);					
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg_audio']["name"];
					$atype = $_FILES['headerimg_audio']["type"];
					$asize = $_FILES['headerimg_audio']["size"];
					$asize = $this->formatSizeUnits($asize);
					
					console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES['headerimg_audio']["tmp_name"]);	
					
					console(LOG_LEVEL_TRACE, "Audio Stored in::".USER_UPLOAD_DIR . $aname);						
				
		}		
				
	if(move_uploaded_file($_FILES['headerimg']["tmp_name"],
					USER_UPLOAD_DIR . $video_image_name)){	
			console(LOG_LEVEL_TRACE, "Video or Image Stored in::".USER_UPLOAD_DIR . $video_image_name);		
				
		$db ['master']->query("INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) VALUES ('".$template_type."','".$aname."','".$asize."','".$header_animation."','".$subjecttxt."','".$video_image_name."','".$video_image_size."','".$video_image_type."')");

		$hid		= $db['master']->getLastID();	
		
		 // make value in question table for template
			   
		$aid = $this->setArrangementId($pagebelongsto);
		
		/*if($video_image_name != ""){
			console(LOG_LEVEL_TRACE, "Video ::". $video_image_name);		
			$ext = explode('.',$video_image_name);
			$extn = $ext[1]; console(LOG_LEVEL_TRACE, "extn ::". $ext[1]);
			if($extn == 'mp4'){
				$qryid = ",streamvideo";
				$qryval = ",'new'";
				console(LOG_LEVEL_TRACE, "qryid ::". $qryid."  Qryval :: ".$qryval);
			}
		}*/ 
		console(LOG_LEVEL_TRACE, "qryid ::". $qryid."  Qryval :: ".$qryval);
		$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['animateorderid']."')");
		
		$qInsId		= $db['master']->getLastID();	

		if(move_uploaded_file($_FILES['headerimg_audio']["tmp_name"],
					USER_UPLOAD_DIR .'audios/'. $aname) && $hid!=''){
		$langid = 1;
		$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
		$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."')");
		}
	}
	
	break;
	case 'multiple_block':
	
		/* Header details Part Start */
		$subjecttxt  		= mysql_real_escape_string($request['subjecttxt']);	

		
		$db ['master']->query("INSERT INTO header (template_type,subjecttxt) VALUES ('".$template_type."','".$subjecttxt."')");
	
		$hid		= $db['master']->getLastID();
	
		// make value in question table for template
			   
		$aid = $this->setArrangementId($pagebelongsto);
			   
		$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['multblckorderid']."')");
		
		$qInsId		= $db['master']->getLastID();	
		/* Header Details Part End */
	
		/* Bulletin Details Part Start */
		
		$blockcount = $request['blockcount'];
		console(LOG_LEVEL_TRACE, "blockcount::".$blockcount);	
		
		
		for($j=1;$j<=$blockcount;$j++){
		console(LOG_LEVEL_TRACE, "blockcount $j::".$j);
		
		$headertxt = $temptext = $bulletin_level = $tempimg_animation = $header_animation = $bulletin_count =  '';
		$bulletin_label_array = $temptext_array = $bulletin_level_array = $tempimg_animation_array = $header_animation_array = '';
		
		$bulletin_label_array		= $request['bulletin_label'.$j];	
		$temptext_array  			= $request['temptext'.$j];
		$bulletin_level_array		= $request['bulletin_level'.$j];		
		$tempimg_animation_array 	= $request['tempimg_animation'.$j];		
		$header_animation_array 	= $request['headerimg_animation'.$j];		
		
		$bulletin_count 			= count($temptext_array);	
		
		for($i=0; $i < $bulletin_count; $i++){
			
			$bulletin_label = $temptext_value = $bulletin_level = $tempimg_animation = $header_animation = '';
			
			$bulletin_label		= $bulletin_label_array[0];	
			$temptext_value  	= $temptext_array[$i];
			$bulletin_level		= $bulletin_level_array[$i];	
			$tempimg_animation 	= $tempimg_animation_array[$i];
			$bulletin_label_animation 	= $header_animation_array[0];	
			
			if($bulletin_level=='')
			$bulletin_level = 0;
			
			$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			$opt_sno		= $i+1;
			
			
			if($temptext_value != ""){
				$temp_txt = mysql_real_escape_string($temptext_value);
				$bullet_label = mysql_real_escape_string($bulletin_label);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,bulletin_label,bulletin_label_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$bulletin_level."','".$tempimg_animation."','".$bullet_label."','".$bulletin_label_animation."')");
					
			$bid		= $db['master']->getLastID();
	
						
			if($_FILES["tempaudio".$j]["tmp_name"][$i]!=''){					
					$randomval  = rand(1000,9999);
					$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio".$j]["name"][$i];
					$atype 		= $_FILES["tempaudio".$j]["type"][$i];
					$asize 		= $_FILES["tempaudio".$j]["size"][$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio".$j]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["tempaudio".$j]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'.$aname)){					
						$langid = 1;
						$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
						$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					}			  
				}
			}else{
				console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
			}
		}
		
	}
		
		/* Bulletin Details Part End */
	
	
	
	
	break;
	
	case 'left_right_temp':
	
		/* Header details Part Start */
		$subjecttxt  		= mysql_real_escape_string($request['lsubjecttxt']);	

		
		$db ['master']->query("INSERT INTO header (template_type,subjecttxt) VALUES ('".$template_type."','".$subjecttxt."')");
	
		$hid		= $db['master']->getLastID();
	
		// make value in question table for template
			   
		$aid = $this->setArrangementId($pagebelongsto);
			   
		$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['lrtemporderid']."')");
		
		$qInsId		= $db['master']->getLastID();	
		/* Header Details Part End */
		
		/* Bulletin Details Part Start */
		
		$temptext_array 		 = $request['ltemptext'];
		$bulletin_level_array 	 = $request['lbulletin_level'];
		$tempimg_animation_array = $request['ltemptext_animation'];
		$temptext_count			 = count($temptext_array);
		console(LOG_LEVEL_TRACE, "Left Bulletin count:".$temptext_count);
		for($i=0;$i<$temptext_count;$i++){
		
			$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
		
			$temptext_value  	= $temptext_array[$i];
			$bulletin_level		= $bulletin_level_array[$i];	
			$txt_animation 		= $tempimg_animation_array[$i];
			
			$opt_sno			= $i+1;
			
			if($bulletin_level=='')
			$bulletin_level = 0;
		
		
		if($temptext_value != ""){
			$temp_text = mysql_real_escape_string($temptext_value);
		
			$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,tp_align) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$bulletin_level."','".$txt_animation."','left')");
					
			$bid		= $db['master']->getLastID();
			
			if($_FILES["ltempaudio"]["tmp_name"][$i]!=''){

					console(LOG_LEVEL_TRACE, "Left Bulletin count increment value:".$i);
					$randomval  = rand(1000,9999);
					$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["ltempaudio"]["name"][$i];
					$atype 		= $_FILES["ltempaudio"]["type"][$i];
					$asize 		= $_FILES["ltempaudio"]["size"][$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["ltempaudio"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["ltempaudio"]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'.$aname)){				
						$langid = 1;
						$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
						$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					}			  
				}
			}else{
				console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
			}
		}
			
			
			$temptext_array 		 = $request['rtemptext_right'];
			$bulletin_level_array 	 = $request['rbulletin_level_right'];
			$tempimg_animation_array = $request['rtemptext_right_animation'];
			$temptext_right_count	 = count($temptext_array);
			
			console(LOG_LEVEL_TRACE, "Right Bulletin count:".$temptext_right_count);
			
			for($i=0;$i<$temptext_right_count;$i++){

			console(LOG_LEVEL_TRACE, "Right Bulletin count increment value:".$i);
			
			$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
		
			$temptext_value  	= $temptext_array[$i];
			$bulletin_level		= $bulletin_level_array[$i];	
			$txt_animation 		= $tempimg_animation_array[$i];
			
			$opt_sno			= $i+1;
			
			if($bulletin_level=='')
			$bulletin_level = 0;	
		
		if($temptext_value != ""){
			$temp_txt = mysql_real_escape_string($temptext_value);
			
			$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,tp_align) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$bulletin_level."','".$txt_animation."','right')");
					
			$bid		= $db['master']->getLastID();
			
			
			if($_FILES["rtempaudio_right"]["tmp_name"][$i]!=''){					
					$randomval  = rand(1000,9999);
					$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["rtempaudio_right"]["name"][$i];
					$atype 		= $_FILES["rtempaudio_right"]["type"][$i];
					$asize 		= $_FILES["rtempaudio_right"]["size"][$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["rtempaudio_right"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["rtempaudio_right"]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'.$aname)){					
					
					$langid = 1;
					$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					}			  
				}
			}else{
				console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
			}
		}			
		
		/* Bulletin Details Part End */
	
	break;
	
	case 'evaltemp':
	
	$evtext = mysql_real_escape_string($request['evtext']);
	
	
	// video and audio upload base on language start
		if($evtext!=''){	

				$aid = $this->setArrangementId($pagebelongsto);		
				
				$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$evtext."','evaltemp','".$pagebelongsto."','".$aid."','".$request['evalorderid']."')");
				
				$qid		= $db['master']->getLastID();
	
				
				$audio_language	   = $request['audio_language'];						
				$audio_count  	   = count($audio_language);				
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				console(LOG_LEVEL_TRACE, "audio_count::".$audio_count."audio_language::".$audio_language);
				
				for($i=0; $i < $audio_count; $i++){				
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				if ($_FILES["videoaudio"]["error"][$i] > 0 || $_FILES["videoaudio"]["error"][$i] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["videoaudio"]["error"][$i]."Languge audtio filename::"."videoaudio");
					}else if($_FILES["videoaudio"]["tmp_name"][$i]!=''){
					
					$randomval = rand(1000,9999);
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES["videoaudio"]["name"][$i];
					//$aname = $_FILES["videoaudio"]["name"][$i];
					$atype = $_FILES["videoaudio"]["type"][$i];
					$asize = $_FILES["videoaudio"]["size"][$i];
					$langid = $audio_language[$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Languge Audio Name::".$aname."Languge Audio Type::".$atype."Languge Audio Size::".$asize." LangugeTemp file: ".$_FILES["videoaudio"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["videoaudio"]["tmp_name"][$i],
					$audiopath.$aname)){	
					$audiopath = $audiopath.$aname;
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','evaltemp')");
					
				}
			}
						
		}			
	
			
	
			if($db ['master']->affectedRows()>0){				
				$videoMessage = 1;
				$videoMsg = "Evaluation template added Successfully ";
			}else{
				$videoMessage = 0;
				$videoMsg = "Evaluation template not added Successfully ";
			}
				
		}

	break;
	
	
	
	
	}
}

public function EditImageContent_MultipleBlock(){
		
		global $db,$request;	
		
		console(LOG_LEVEL_TRACE, "Request Edit Id::".$request['uqid']);	
		
		
		/* header part details  Start */
		$subjecttxt  		= mysql_real_escape_string($request['subjecttxt']);			
		$header_animation 	= $request['headerimg_animation'];	
		$filename1 			= 'headerimg';
		$filename2 			= 'headerimg_audio';
		/* header part details  End */
		$editqid 		= $request['uqid'];	
		$qid = '';		
		
		$question_query		= "SELECT * FROM questions where qid='".$editqid."' AND status='active'";
		$question_details   = $db['master']->getOneRow($question_query);	
		
		$ehid				= $question_details['hid'];
		$template_type		= $question_details['qvtype'];
		$pagebelongsto		= $question_details['pagebelongsto'];
		$temp_name			= $question_details['temp_name'];
		$aid				= $question_details['aid'];
		
		switch($template_type){		
		case 'imagecontent':
			$ques_qry 				=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateques 			= $db['master']->query ($ques_qry);	
			
			$lang_audio_qry 		=  "update language_audios set status='removed'  where qid='".$editqid."'  AND status='active'";
			$updateaudio 			= $db['master']->query ($lang_audio_qry);
			
			$header_qry 			=  "update header set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updateheader			= $db['master']->query ($header_qry);
			
			$bulletin_qry 			=  "update bulletin_content set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updatebulletin			= $db['master']->query ($bulletin_qry);
			
			$link_qry               = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
		
			if($_FILES['headerimg']["name"]){	
					$randomval 				= rand(1000,9999);					
					$video_image_name 		= date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg']["name"];
					$video_image_type 		= $_FILES['headerimg']["type"];
					$video_image_size 		= $_FILES['headerimg']["size"];
					$video_image_size 		= $this->formatSizeUnits($video_image_size);
					console(LOG_LEVEL_TRACE, "Header Video/image Name::".$video_image_name."Header video/image Type::".$video_image_type."Header /image Size::".$video_image_size."Temp file: ".$_FILES['headerimg']["tmp_name"]);	
			}
			else{
				$header_query		= "SELECT * FROM header where hid='".$ehid."' AND status='removed'";
				$headerdetails    	= $db['master']->getOneRow($header_query);				
				$video_image_name 	= $headerdetails['video_image_name'];	
				$video_image_size	= $headerdetails['video_image_size'];
				$video_image_type	= $headerdetails['video_image_type'];
				
				/*$haudiopath 		= $audio_headerdetails['audiopath'];	
				$haname				= $audio_headerdetails['aname'];
				$hasize				= $audio_headerdetails['asize'];	
				$hatype				= $audio_headerdetails['atype'];*/	
				
			}
			if($_FILES['headerimg_audio']["name"]){	
				$randomval 	= rand(1000,9999);					
				$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg_audio']["name"];
				$atype 		= $_FILES['headerimg_audio']["type"];
				$asize 		= $_FILES['headerimg_audio']["size"];
				$asize 		= $this->formatSizeUnits($asize);
				$audiopath 	= USER_UPLOAD_DIR .'audios/'. $aname;
					
				console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES['headerimg_audio']["tmp_name"]);	
					
				console(LOG_LEVEL_TRACE, "Audio Stored in::".USER_UPLOAD_DIR . $aname);						
				
			}
			else{		
				$audio_query			= "SELECT * FROM language_audios where hid='".$ehid."' AND status='removed'";
				$audio_headerdetails    = $db['master']->getOneRow($audio_query);
					
				$audiopath 				= $audio_headerdetails['audiopath'];	
				$aname					= $audio_headerdetails['aname'];
				$asize					= $audio_headerdetails['asize'];	
				$atype					= $audio_headerdetails['atype'];	
			}
			
			if(move_uploaded_file($_FILES['headerimg']["tmp_name"],
					USER_UPLOAD_DIR . $video_image_name) || $video_image_name!='' ){
					
				console(LOG_LEVEL_TRACE, "Video or Image Stored in::".USER_UPLOAD_DIR . $video_image_name);	
				
				$db ['master']->query("INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) VALUES ('".$template_type."','".$aname."','".$asize."','".$header_animation."','".$subjecttxt."','".$video_image_name."','".$video_image_size."','".$video_image_type."')");

				$hid		= $db['master']->getLastID();	
				
				 // make value in question table for template
					   
				//$aid = $this->setArrangementId($pagebelongsto);
					   
				$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid ) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['editimgcntorderid']."')");
				
				$qInsId		= $db['master']->getLastID();	

				if((move_uploaded_file($_FILES['headerimg_audio']["tmp_name"],
							USER_UPLOAD_DIR .'audios/'. $aname) && $hid!='') || $aname!=''){
					$langid = 1;
					$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."')");
				}
				/* Bulletin Part Start */
		
				$bulletin_label  		= $request['bulletin_label'];
				$bulletin_text			= $request['bulletin_text'];
				$filename				= "tempaudio";
				$bulletin_count 		= count($bulletin_text);
				$temptext_animate		= $request['tempimg_animation'];
				$bulletin_level			= $request['bulletin_level'];
				//$bulletin_label_animation 	= $request['headerimg_animation'];	
				
				/* Bulletin Part End */
				console(LOG_LEVEL_TRACE, "bulletin count::".$bulletin_count);
			
			
				for($i=0; $i < $bulletin_count; $i++){
				//print_r($_FILES[$filename]["tmp_name"]);
				
				console(LOG_LEVEL_TRACE, "bulletin count increment $i::".$i);
				$temptext_value = $opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
				$opt_sno		= $i+1;
				$temptext_value = $bulletin_text[$i];	
				$txt_animation  = $temptext_animate[$i];
				$txt_level  	= $bulletin_level[$i];
				
				if($txt_level=='')
				$txt_level = 0;
			
			if($temptext_value != ""){
				$temp_txt = mysql_real_escape_string($temptext_value);
				$bullet_label = mysql_real_escape_string($bulletin_label);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,bulletin_label,bulletin_label_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$txt_level."','".$txt_animation."','".$bullet_label."','".$bulletin_label_animation."')");
						
				$bid		= $db['master']->getLastID();		
				
				$k = $i+1;
				if($_FILES["tempaudio"]["tmp_name"][$i]!=''){	
					console(LOG_LEVEL_TRACE, "Bulletin Audio New File");
					$randomval  = rand(1000,9999);
					$abulletname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio"]["name"][$i];
					$abullettype 		= $_FILES["tempaudio"]["type"][$i];
					$abulletsize 		= $_FILES["tempaudio"]["size"][$i];
					$abulletsize 		= $this->formatSizeUnits($abulletsize);
					console(LOG_LEVEL_TRACE, "Bulletin $i Audio Name::".$abulletname."Bulletin $i Audio Type::".$abullettype."Bulletin $i Audio Size::".$abulletsize."Temp file: ".$_FILES["tempaudio"]["tmp_name"][$i]);
									
					if(move_uploaded_file($_FILES["tempaudio"]["tmp_name"][$i],USER_UPLOAD_DIR .'audios/'.$abulletname)){					
						$langid = 1;
						console(LOG_LEVEL_TRACE, "Bulletin Audio Moved to the Specified Path");
						$audiopath = USER_UPLOAD_DIR .'audios/'. $abulletname;
					}			  
				}else if($request["imgcntbultaudio".$k] != ""){
					console(LOG_LEVEL_TRACE, "Bulletin $k Audio Already Exits"); 
					$abulletname = $request["imgcntbultaudio".$k];
					$abulletsize = $request["imgcntbultaudiosize".$k];
					$abullettype = $request["imgcntbultaudiotype".$k];
					console(LOG_LEVEL_TRACE, "Temp file :: imgcntbultaudio".$k);
					$langid = 1;
				}else if($_FILES["tempaudio"]["tmp_name"][$i]=='' && $request["imgcntbultaudio".$k] == ""){
					console(LOG_LEVEL_TRACE, "Bulletin $i Audio Is NULL"); 
					$abulletname = "";
					$abulletsize = "";
					$abullettype = "";
				}			
						
			//if(move_uploaded_file($_FILES["tempaudio"]["tmp_name"][$i],USER_UPLOAD_DIR .'audios/'.$aname)|| $aname!=''){	
						console(LOG_LEVEL_TRACE, "in condition  Aname ::  ".$abulletname ."   For I value :: ".$i);
						$langid = 1;
						$audiopath = USER_UPLOAD_DIR .'audios/'. $abulletname;
						$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$abulletname."','".$abulletsize."','".$abullettype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					//}			  
				//}
			}else{
				console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
			}
		}	
	}
		// video and audio upload base on language end
		
		break;
			case 'animation':
			console(LOG_LEVEL_TRACE, "Edit Animation  :: EditImageContent_MultipleBlock");	
			$header_query		= "SELECT * FROM header where hid='".$ehid."' AND status='active'";
			$headerdetails    	= $db['master']->getOneRow($header_query);	
				
			$ques_qry 				=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateques 			= $db['master']->query ($ques_qry);	
			
			$lang_audio_qry 		=  "update language_audios set status='removed'  where qid='".$editqid."'  AND status='active'";
			$updateaudio 			= $db['master']->query ($lang_audio_qry);
			
			$header_qry 			=  "update header set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updateheader			= $db['master']->query ($header_qry);
			
			$link_qry               = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
			
		
			if($_FILES['headerimg']["name"]){	
					$randomval 				= rand(1000,9999);					
					$video_image_name 		= date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg']["name"];
					$video_image_type 		= $_FILES['headerimg']["type"];
					$video_image_size 		= $_FILES['headerimg']["size"];
					$video_image_size 		= $this->formatSizeUnits($video_image_size);
					console(LOG_LEVEL_TRACE, "Header Video/image Name::".$video_image_name."Header video/image Type::".$video_image_type."Header /image Size::".$video_image_size."Temp file: ".$_FILES['headerimg']["tmp_name"]);	
			}
			else{			
				$video_image_name 	= $headerdetails['video_image_name'];	
				$video_image_size	= $headerdetails['video_image_size'];
				$video_image_type	= $headerdetails['video_image_type'];
				
				/*$haudiopath 		= $audio_headerdetails['audiopath'];	
				$haname				= $audio_headerdetails['aname'];
				$hasize				= $audio_headerdetails['asize'];	
				$hatype				= $audio_headerdetails['atype'];*/	
				
			}
			if($_FILES['headerimg_audio']["name"]){	
				$randomval 	= rand(1000,9999);					
				$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES['headerimg_audio']["name"];
				$atype 		= $_FILES['headerimg_audio']["type"];
				$asize 		= $_FILES['headerimg_audio']["size"];
				$asize 		= $this->formatSizeUnits($asize);
				$audiopath 	= USER_UPLOAD_DIR .'audios/'. $aname;
					
				console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES['headerimg_audio']["tmp_name"]);	
					
				console(LOG_LEVEL_TRACE, "Audio Stored in::".USER_UPLOAD_DIR . $aname);						
				
			}
			else{		
				$audio_query			= "SELECT * FROM language_audios where hid='".$ehid."' AND status='removed'";
				$audio_headerdetails    = $db['master']->getOneRow($audio_query);
					
				$audiopath 				= $audio_headerdetails['audiopath'];	
				$aname					= $audio_headerdetails['aname'];
				$asize					= $audio_headerdetails['asize'];	
				$atype					= $audio_headerdetails['atype'];	
			}
			
			if(move_uploaded_file($_FILES['headerimg']["tmp_name"],
					USER_UPLOAD_DIR . $video_image_name) || $video_image_name!='' ){
					
				console(LOG_LEVEL_TRACE, "Video or Image Stored in::".USER_UPLOAD_DIR . $video_image_name);	
				
				$db ['master']->query("INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) VALUES ('".$template_type."','".$aname."','".$asize."','".$header_animation."','".$subjecttxt."','".$video_image_name."','".$video_image_size."','".$video_image_type."')");

				$hid		= $db['master']->getLastID();	
				
				 // make value in question table for template
					   
				//$aid = $this->setArrangementId($pagebelongsto);
				
			/*	if($video_image_name != ""){
					console(LOG_LEVEL_TRACE, "Video ::". $video_image_name);		
					$ext = explode('.',$video_image_name);
					$extn = $ext[1]; console(LOG_LEVEL_TRACE, "extn ::". $ext[1]);
					if($extn == 'mp4'){
						$qryid = ",streamvideo";
						$qryval = ",'edited'";
						console(LOG_LEVEL_TRACE, "qryid ::". $qryid."  Qryval :: ".$qryval);
					}
				}*/
					   
				$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid ) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['editanimateorderid']."')");
				
				$qInsId		= $db['master']->getLastID();	

				if((move_uploaded_file($_FILES['headerimg_audio']["tmp_name"],
							USER_UPLOAD_DIR .'audios/'. $aname) && $hid!='') || $aname!=''){
					$langid = 1;
					$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
					$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."')");
				}
			}
		break;
	
		case 'multiple_block':
			$ques_qry 				=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateques 			= $db['master']->query ($ques_qry);	
			
			$lang_audio_qry 		=  "update language_audios set status='removed'  where qid='".$editqid."'  AND status='active'";
			$updateaudio 			= $db['master']->query ($lang_audio_qry);
			
			$header_qry 			=  "update header set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updateheader			= $db['master']->query ($header_qry);
			
			$bulletin_qry 			=  "update bulletin_content set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updatebulletin			= $db['master']->query ($bulletin_qry);
			
			$link_qry               = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
			
				$db ['master']->query("INSERT INTO header (template_type,subjecttxt) VALUES ('".$template_type."','".$subjecttxt."')");
				$hid		= $db['master']->getLastID();
				// make value in question table for template
				   
				//$aid = $this->setArrangementId($pagebelongsto);
				   
				$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['editmultblckorderid']."')");
				$qInsId		= $db['master']->getLastID();	
				/* Header Details Part End */
		
				/* Bulletin Details Part Start */
			
				$blockcount = $request['blockcount'];
				console(LOG_LEVEL_TRACE, "blockcount::".$blockcount);	
				
				for($j=1;$j<=$blockcount;$j++){
					console(LOG_LEVEL_TRACE, "blockcount $j::".$j);
					
					$headertxt = $temptext = $bulletin_level = $tempimg_animation = $header_animation = $bulletin_count =  '';
					$bulletin_label_array = $temptext_array = $bulletin_level_array = $tempimg_animation_array = $header_animation_array = '';
					
					$bulletin_label_array		= $request['bulletin_label'.$j];	
					$temptext_array  			= $request['temptext'.$j];
					$bulletin_level_array		= $request['bulletin_level'.$j];		
					$tempimg_animation_array 	= $request['tempimg_animation'.$j];		
					$header_animation_array 	= $request['headerimg_animation'.$j];
					$old_bulletin_id 			= $request['tempaudiofile'.$j];					
					
					$bulletin_count 			= count($temptext_array);	
					
					for($i=0; $i < $bulletin_count; $i++){
						
						$bulletin_label = $temptext_value = $bulletin_level = $tempimg_animation = $header_animation = '';
						
						$bulletin_label		= $bulletin_label_array[0];	
						$temptext_value  	= $temptext_array[$i];
						$bulletin_level		= $bulletin_level_array[$i];	
						$tempimg_animation 	= $tempimg_animation_array[$i];
						$bulletin_label_animation 	= $header_animation_array[0];
						$old_bid 			= $old_bulletin_id[$i];		
						
						if($bulletin_level=='')
						$bulletin_level = 0;
						
						$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
						$opt_sno		= $i+1;
						
					
					if($temptext_value != ""){	
                        $temp_txt = mysql_real_escape_string($temptext_value);
						$bullet_label = mysql_real_escape_string($bulletin_label);
						
						$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,bulletin_label,bulletin_label_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$bulletin_level."','".$tempimg_animation."','".$bullet_label."','".$bulletin_label_animation."')");	
						$bid		= $db['master']->getLastID();
				
									
						if($_FILES["tempaudio".$j]["tmp_name"][$i]!=''){					
								$randomval  = rand(1000,9999);
								$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio".$j]["name"][$i];
								$atype 		= $_FILES["tempaudio".$j]["type"][$i];
								$asize 		= $_FILES["tempaudio".$j]["size"][$i];
								$asize 		= $this->formatSizeUnits($asize);
								console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio".$j]["tmp_name"][$i]);
						}else{
								$acount = $i +1;
								$audio_query			= "SELECT * FROM language_audios where bid='".$old_bid."' AND hid='".$ehid."' AND status='removed'";
								$audio_tempdetails    = $db['master']->getOneRow($audio_query);
							
								$audiopath 				= $audio_tempdetails['audiopath'];	
								$aname					= $audio_tempdetails['aname'];
								$asize					= $audio_tempdetails['asize'];	
								$atype					= $audio_tempdetails['atype'];
						}
								if(move_uploaded_file($_FILES["tempaudio".$j]["tmp_name"][$i],
								USER_UPLOAD_DIR .'audios/'.$aname) || $aname!=""){					
								$langid = 1;
								$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
								$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
							}			  
						//}	
						}else{
							console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
						}
					}
				}
		break;
		case 'left_right_temp':
			$ques_qry 				=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateques 			= $db['master']->query ($ques_qry);	
				
			$lang_audio_qry 		=  "update language_audios set status='removed'  where qid='".$editqid."'  AND status='active'";
			$updateaudio 			= $db['master']->query ($lang_audio_qry);
				
			$header_qry 			=  "update header set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updateheader			= $db['master']->query ($header_qry);
				
			$bulletin_qry 			=  "update bulletin_content set status='removed'  where hid='".$ehid."'  AND status='active'";
			$updatebulletin			= $db['master']->query ($bulletin_qry);
			
			$link_qry               = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
		
			/* Header details Part Start */
			$subjecttxt  		= mysql_real_escape_string($request['lsubjecttxt']);	

			
			$db ['master']->query("INSERT INTO header (template_type,subjecttxt) VALUES ('".$template_type."','".$subjecttxt."')");
		
			$hid		= $db['master']->getLastID();
		
			// make value in question table for template
				   
			//$aid 		= $this->setArrangementId($pagebelongsto);
				   
			$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$temp_name."','".$request['editlrtemporderid']."')");
			
			$qInsId		= $db['master']->getLastID();	
			/* Header Details Part End */
			
			/* Bulletin Details Part Start */
			
			$temptext_array 		 = $request['ltemptext'];
			$bulletin_level_array 	 = $request['lbulletin_level'];
			$tempimg_animation_array = $request['ltemptext_animation'];
			$temptext_count			 = count($temptext_array);
			console(LOG_LEVEL_TRACE, "Left Bulletin count:".$temptext_count);
			for($i=0;$i<$temptext_count;$i++){
			
				$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			
				$temptext_value  	= $temptext_array[$i];
				$bulletin_level		= $bulletin_level_array[$i];	
				$txt_animation 		= $tempimg_animation_array[$i];
				
				$opt_sno			= $i+1;
				
				if($bulletin_level=='')
				$bulletin_level = 0;
			
			 
			 
			if($temptext_value != ""){
				$temp_txt = mysql_real_escape_string($temptext_value);
			
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,tp_align) VALUES ('".$hid."','".$opt_sno."','".(($temp_txt))."','".$bulletin_level."','".$txt_animation."','left')");
						
				$bid		= $db['master']->getLastID();
				
				if($_FILES["ltempaudio"]["tmp_name"][$i]!=''){

						console(LOG_LEVEL_TRACE, "Left Bulletin count increment value:".$i);
						$randomval  = rand(1000,9999);
						$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["ltempaudio"]["name"][$i];
						$atype 		= $_FILES["ltempaudio"]["type"][$i];
						$asize 		= $_FILES["ltempaudio"]["size"][$i];
						$asize 		= $this->formatSizeUnits($asize);
						console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["ltempaudio"]["tmp_name"][$i]);
				}else{
						$acount = $i +1;
						$audio_query			= "SELECT * FROM language_audios where bid='".$request['linputaudio'.$acount]."' AND hid='".$ehid."' AND status='removed'";
						$audio_tempdetails    = $db['master']->getOneRow($audio_query);
								
						$audiopath 				= $audio_tempdetails['audiopath'];	
						$aname					= $audio_tempdetails['aname'];
						$asize					= $audio_tempdetails['asize'];	
						$atype					= $audio_tempdetails['atype'];
				}
						if(move_uploaded_file($_FILES["ltempaudio"]["tmp_name"][$i],
							USER_UPLOAD_DIR .'audios/'.$aname) || $aname != ""){				
							$langid = 1;
							$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
							$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
						}			  
				}else{
					console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
				}
			}
				
				
				$temptext_array 		 = $request['rtemptext_right'];
				$bulletin_level_array 	 = $request['rbulletin_level_right'];
				$tempimg_animation_array = $request['rtemptext_right_animation'];
				$temptext_right_count	 = count($temptext_array);
				
				console(LOG_LEVEL_TRACE, "Right Bulletin count-->".$temptext_right_count);
				
				for($i=0;$i<$temptext_right_count;$i++){

				console(LOG_LEVEL_TRACE, "Right Bulletin count increment value-->".$i);
				
				$opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			
				$temptext_value  	= $temptext_array[$i];
				$bulletin_level		= $bulletin_level_array[$i];	
				$txt_animation 		= $tempimg_animation_array[$i];
				
				$opt_sno			= $i+1;
				
				if($bulletin_level=='')
				$bulletin_level = 0;	
			  
			if($temptext_value != ""){
				$temp_text = mysql_real_escape_string($temptext_value);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_level,txt_animation,tp_align) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$bulletin_level."','".$txt_animation."','right')");
						
				$bid		= $db['master']->getLastID();
				
				
				if($_FILES["rtempaudio_right"]["tmp_name"][$i]!=''){	
				
						console(LOG_LEVEL_ERROR,"in condition 11");				
						$randomval  = rand(1000,9999);
						$aname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["rtempaudio_right"]["name"][$i];
						$atype 		= $_FILES["rtempaudio_right"]["type"][$i];
						$asize 		= $_FILES["rtempaudio_right"]["size"][$i];
						$asize 		= $this->formatSizeUnits($asize);
						console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["rtempaudio_right"]["tmp_name"][$i]);
				}else{  console(LOG_LEVEL_ERROR,"in condition 12");
						$acount = $i +1;
						$audio_query			= "SELECT * FROM language_audios where bid='".$request['rinputaudio'.$acount]."' AND hid='".$ehid."' AND status='removed'";
						$audio_tempdetails    = $db['master']->getOneRow($audio_query);
								
						$audiopath 				= $audio_tempdetails['audiopath'];	
						$aname					= $audio_tempdetails['aname'];
						$asize					= $audio_tempdetails['asize'];	
						$atype					= $audio_tempdetails['atype'];
				}
						if(move_uploaded_file($_FILES["rtempaudio_right"]["tmp_name"][$i],
						USER_UPLOAD_DIR .'audios/'.$aname) || $aname != ""){					
						
						$langid = 1;
						$audiopath = USER_UPLOAD_DIR .'audios/'. $aname;
						$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
					}			  
				}else{
					console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
				}
			}			
			
			/* Bulletin Details Part End */
		
		break;
		
		case 'evaltemp':

		$pagebelongsto		= $request['id'];

		$evaltext 			=  mysql_real_escape_string($request['evtext']);


		$lang_audioid			= "SELECT audioid FROM language_audios where qid='".$editqid."' AND status='active'";
		$lang_audioid_details	= $db['master']->getResults($lang_audioid);

		if(count($lang_audioid_details)>0){
		foreach($lang_audioid_details as $val_audioids){
		$audioids[] = $val_audioids['audioid'];
		}
		}
				
				
		$db ['master']->query("INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) VALUES ('".$evaltext."','evaltemp','".$pagebelongsto."','".$aid."','".$request['editevalorderid']."')");
	
		$qid		   = $db['master']->getLastID();
		
		$audio_language	   = $request['audio_language'];						
		$audio_count  	   = count($audio_language);				
		$audiopath		   = USER_UPLOAD_DIR.'audios/';
		console(LOG_LEVEL_TRACE, "edit audio_count::".$audio_count."edit audio_language::".$audio_language);
				
				$get_audio_order = 1;
				for($i=0; $i < $audio_count; $i++){	
				$get_audio_order++;
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				$langid = $audio_language[$i];
				
				if($_FILES["videoaudio"]["tmp_name"][$i]!=''){
					
					$randomval  = rand(1000,9999);
					$aname 	    = date('YmdHis').'_'.$randomval.'_'.$_FILES["videoaudio"]["name"][$i];				
					$atype 		= $_FILES["videoaudio"]["type"][$i];
					$asize 		= $_FILES["videoaudio"]["size"][$i];
					$langid 	= $audio_language[$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "edit Languge Audio Name::".$aname."edit Languge Audio Type::".$atype."edit Languge Audio Size::".$asize."edit LangugeTemp file: ".$_FILES["videoaudio"]["tmp_name"][$i]);		
					if(move_uploaded_file($_FILES["videoaudio"]["tmp_name"][$i],
					$audiopath.$aname)){	
					$audiopath = $audiopath.$aname;
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','evaltemp')");					
					}
				}
				else if($langid!=''){	


					$audioid = '';
					$audioid = $audioids[$i];
				
					$lang_query			= "SELECT * FROM language_audios where qid='".$editqid."' AND audioid='".$audioid."' AND status='active'";
				
					$lang_details    	= $db['master']->getOneRow($lang_query);	
			
					$aname 				= $lang_details['aname'];
					$asize 				= $lang_details['asize'];
					$audiopath 			= $lang_details['audiopath'];
					$atype 				= $lang_details['atype'];			
			
					console(LOG_LEVEL_TRACE, "edit Audio Name::".$aname."edit  Audio Size::".$asize."::audiopath-->".$audiopath);
			
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$qid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','evaltemp')");
					}					
				}
			
	
			if($db ['master']->affectedRows()>0){				
				$videoMessage = 1;
				$videoMsg = "Evaluation Template Edited Successfully ";
			}else{
				$videoMessage = 0;
				$videoMsg = "Evaluation Template Not Edited Successfully ";
			}
				
		
		
			$ques_qry 				=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateHeader 			= $db['master']->query ($ques_qry);				
			$lang_audio_qry 		=  "update language_audios set status='removed'  where qid='".$editqid."'  AND status='active'";
			$updateaudio 			= $db['master']->query ($lang_audio_qry);
			$link_qry               = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
		
		// video and audio upload base on language end
		
		break;
	}
}
	
public function AddHeaderBulletins($pagebelongsto){
	global $db,$request;	
	console(LOG_LEVEL_TRACE, "AddHeaderBulletins Function");
	/* header part details  Start */
	$template_type  = $request['temp_type'];
	$header_text 	= $request['headertxt'];		
	$header_animation 	= $request['header_animation'];	
	$filename 		= 'headertxt_audio';
	$audiopath  	= USER_UPLOAD_DIR;

	
	$allowedExts = array("mp3", "mp4", "wma");
	$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
	console(LOG_LEVEL_TRACE, "Header Text Audio Filename:".$filename);
	
	$filename1 = 'img_name';
	$filename2 = 'img_audio';
	$aname = $atype = $asize = "";
	/*if ($_FILES[$filename]["error"] > 0)  {  
		console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename]["error"]." filename::".$filename);
	}*/    
		
	//if($template_type=='template2' || $template_type=='template4' ){
	if($template_type=='template4' ){
		if($_FILES[$filename]["tmp_name"] != "") {
			$randomval = rand(1000,9999);
			console(LOG_LEVEL_TRACE, "Header Audio Uploaded :: ");
			$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename]["name"];
			$atype = $_FILES[$filename]["type"];
			$asize = $_FILES[$filename]["size"];
			$asize = $this->formatSizeUnits($asize);
			if(move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR .'audios/'. $aname)){
				console(LOG_LEVEL_TRACE, "Uploaded Header Audio to the Location ::".$aname);
			}
			console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES[$filename]["tmp_name"]);				
		}else{
			console(LOG_LEVEL_TRACE, "Header Audio Not Uploaded :: ");
			$aname="";
			$atype="";
			$asize="";
		}	
		/*if ($_FILES[$filename1]["error"] > 0 || $_FILES[$filename2]["error"] > 0)  {  
			console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename1]["error"]." filename::".$filename1);
			console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename2]["error"]." filename::".$filename2);
		}*/
		if($_FILES[$filename1]["tmp_name"] !="" && $_FILES[$filename2]["tmp_name"]!="") {
			console(LOG_LEVEL_TRACE, "Image and Audio Uploaded :: ");
			$randomval = rand(1000,9999);
			$imgname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename1]["name"];
			$randomval = rand(1000,9999);
			$img_aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename2]["name"];
			$imgtype = $_FILES[$filename1]["type"];
			$img_size = $_FILES[$filename1]["size"];
			$img_size = $this->formatSizeUnits($img_size);
			console(LOG_LEVEL_TRACE, "Image Name::".$imgname."Image Type::".$imgtype."Image Size::".$img_size."Temp file: ".$_FILES[$filename1]["tmp_name"]);			
			$atype = $_FILES[$filename2]["type"];
			$img_asize = $_FILES[$filename2]["size"];
			$img_asize = $this->formatSizeUnits($img_asize);
			if(move_uploaded_file($_FILES[$filename1]["tmp_name"],USER_UPLOAD_DIR . $imgname)){
				console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgname);
			}
			if(move_uploaded_file($_FILES[$filename2]["tmp_name"],USER_UPLOAD_DIR .'audios/'. $img_aname)){
				console(LOG_LEVEL_TRACE, "Uploaded Audio Moved to the Location ::".USER_UPLOAD_DIR .'audios/'. $img_aname);
			}
			console(LOG_LEVEL_TRACE, "Image Audio Name::".$img_aname."Image Audio Type::".$atype."Image Audio Size::".$img_asize."Temp file: ".$_FILES[$filename2]["tmp_name"]);
		}else if($_FILES[$filename1]["tmp_name"] =="" && $_FILES[$filename2]["tmp_name"]!=""){
			console(LOG_LEVEL_TRACE, "Image Not Uploaded and Audio Uploaded :: ");
			$randomval = rand(1000,9999);
			$imgname = "";
			$randomval = rand(1000,9999);
			$img_aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename2]["name"];
			$imgtype = "";
			$img_size = "";
			console(LOG_LEVEL_TRACE, "Image Name::".$imgname."Image Type::".$imgtype."Image Size::".$img_size."Temp file: ".$_FILES[$filename1]["tmp_name"]);			
			$atype = $_FILES[$filename2]["type"];
			$img_asize = $_FILES[$filename2]["size"];
			$img_asize = $this->formatSizeUnits($img_asize);
			if(move_uploaded_file($_FILES[$filename2]["tmp_name"],USER_UPLOAD_DIR .'audios/'. $img_aname)){
				console(LOG_LEVEL_TRACE, "Uploaded Audio Moved to the Location ::".USER_UPLOAD_DIR .'audios/'. $img_aname);
			}
			console(LOG_LEVEL_TRACE, "Image Audio Name::".$img_aname."Image Audio Type::".$atype."Image Audio Size::".$img_asize."Temp file: ".$_FILES[$filename2]["tmp_name"]);
		}else if($_FILES[$filename1]["tmp_name"] !="" && $_FILES[$filename2]["tmp_name"]==""){
			console(LOG_LEVEL_TRACE, "Image Uploaded and Audio Not Uploaded :: ");
			$randomval = rand(1000,9999);
			$imgname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename1]["name"];
			$randomval = rand(1000,9999);
			$img_aname = "";
			$imgtype = $_FILES[$filename1]["type"];
			$img_size = $_FILES[$filename1]["size"];
			$img_size = $this->formatSizeUnits($img_size);
			console(LOG_LEVEL_TRACE, "Image Name::".$imgname."Image Type::".$imgtype."Image Size::".$img_size."Temp file: ".$_FILES[$filename1]["tmp_name"]);			
			$atype = "";
			$img_asize = "";
			if(move_uploaded_file($_FILES[$filename1]["tmp_name"],USER_UPLOAD_DIR . $imgname)){
				console(LOG_LEVEL_TRACE, "Uploaded Image Moved to the Location ::".USER_UPLOAD_DIR . $imgname);
			}
			console(LOG_LEVEL_TRACE, "Image Audio Name::".$img_aname."Image Audio Type::".$atype."Image Audio Size::".$img_asize."Temp file: ".$_FILES[$filename2]["tmp_name"]);
		}else{
			console(LOG_LEVEL_TRACE, "Image and Audio Not Uploaded :: ");
			$imgname = "";
			$img_aname = "";
			$imgtype = "";
			$img_size = "";
			$atype = "";
			$img_asize = "";
		}
		$audiopath = $audiopath.$aname;
		$head_text = mysql_real_escape_string($header_text);
		$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,imgname,img_aname,img_asize,header_animation) VALUES ('".$head_text."','".$template_type."','".$aname."','".$asize."','".$imgname."','".$img_aname."','".$img_asize."','".$header_animation."')");
	}

	$audiopath = $audiopath.$aname;
	// Header Part File upload and DB Insert
			
	if(($template_type=='template1' || $template_type=='template3' )&& (move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR .'audios/'. $aname))){	
        $head_text = mysql_real_escape_string($header_text);	
		console(LOG_LEVEL_TRACE, "video Stored in::".USER_UPLOAD_DIR . $_FILES[$filename]["name"]);		
		$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,header_animation) VALUES ('".$head_text."','".$template_type."','".$aname."','".$asize."','".$header_animation."')");
	}
	else if(($template_type=='template2') && ((move_uploaded_file($_FILES[$filename1]["tmp_name"],USER_UPLOAD_DIR . $imgname)) && (move_uploaded_file($_FILES[$filename2]["tmp_name"],USER_UPLOAD_DIR .'audios/'.$img_aname)) && (move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR .'audios/'. $aname)))){
		console(LOG_LEVEL_TRACE, "Image Stored in::".USER_UPLOAD_DIR . $_FILES[$filename1]["name"]);
		console(LOG_LEVEL_TRACE, "Image Audio in::".USER_UPLOAD_DIR . $_FILES[$filename2]["name"]);	
        $head_text = mysql_real_escape_string($header_text);			
		$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,imgname,img_aname,img_asize,header_animation) VALUES ('".$head_text."','".$template_type."','".$aname."','".$asize."','".$imgname."','".$img_aname."','".$img_asize."','".$header_animation."')");
	}
	
    $hid  = $db['master']->getLastID();
	// make value in question table for template
	$aid = $this->setArrangementId($pagebelongsto);
	
	if($request['temp4orderid'] != "") $orderid = $request['temp4orderid']; 
	else  $orderid = 0;
	
	$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."','".$orderid."')");
	
	if($template_type=='template1')
		$tp_align = 'center';
	if($template_type=='template2')
		$tp_align = 'center';
	if($template_type=='template3'){
		$tp_align = 'left';
		$tp_align_2 = 'right';
	}
	if($template_type=='template4')
		$tp_align = 'left';

	/* header part details  End */
	$temptext		= $request['temptext'];
	$filename		= "tempaudio";
	$temptext_count = count($temptext);
	$temptext_animate	= $request['temptext_animation'];		
			
	//print_r($_FILES);
	for($i=0; $i < $temptext_count; $i++){
		//print_r($_FILES[$filename]["tmp_name"]);
		$temptext_value = $opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
		$opt_sno		= $i+1;
		$temptext_value = $temptext[$i];	
		$txt_animation  = $temptext_animate[$i];
							
		/*if ($_FILES["tempaudio"]["error"][$i] > 0 || $_FILES["tempaudio"]["error"][$i] > 0)  {  
			console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["tempaudio"]["error"][$i]."options textbox audtio filename::"."tempaudio");
		}*/
	if($temptext_value != ""){
		if($_FILES["tempaudio"]["tmp_name"][$i]!=''){				
			$randomval = rand(1000,9999);
			$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio"]["name"][$i];
			$atype = $_FILES["tempaudio"]["type"][$i];
			$asize = $_FILES["tempaudio"]["size"][$i];
			$asize = $this->formatSizeUnits($asize);
			console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio"]["tmp_name"][$i]);
						
			if(move_uploaded_file($_FILES["tempaudio"]["tmp_name"][$i],USER_UPLOAD_DIR .'audios/'.$aname)){
				console(LOG_LEVEL_TRACE, "AddHeaderBulletins Bulletin Audio Moved to the Specified Folder :: ");
			}
		}else{
			$aname = "";
			$atype = "";
			$asize = "";
		}
		   $temp_text = mysql_real_escape_string($temptext_value);
		   
			$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$aname."','".$asize."','".$tp_align."','".$txt_animation."')");
	}else{
		console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
	}
}	
			
	if($template_type=='template3'){
		$temptext		= $request['temptext_right'];
		$filename		= "tempaudio_right";
		$temptext_count = count($temptext);
		$temptext_right_animation		= $request['temptext_right_animation'];
			
		for($i=0; $i < $temptext_count; $i++){
			$temptext_value = $opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			$opt_sno		= $i+1;
			$temptext_value = $temptext[$i];	
			$txt_animation  = $temptext_right_animation[$i];			
						
			
			if ($_FILES["tempaudio_right"]["error"][$i] > 0 || $_FILES["tempaudio_right"]["error"][$i] > 0)  {  
				console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["tempaudio_right"]["error"][$i]."options textbox audtio filename::"."tempaudio_right");
			}else if($_FILES["tempaudio_right"]["tmp_name"][$i]!=''){
				$randomval = rand(1000,9999);
				$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES["tempaudio_right"]["name"][$i];
				$atype = $_FILES["tempaudio_right"]["type"][$i];
				$asize = $_FILES["tempaudio_right"]["size"][$i];
				$asize = $this->formatSizeUnits($asize);
				console(LOG_LEVEL_TRACE, "options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio_right"]["tmp_name"][$i]);
				
				
				if(move_uploaded_file($_FILES["tempaudio_right"]["tmp_name"][$i],
				USER_UPLOAD_DIR .'audios/'.$aname)){
				$temp_text = mysql_real_escape_string($temptext_value);
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$aname."','".$asize."','".$tp_align_2."','".$txt_animation."')");
				}
			}			
		}
	}
}	
	
	
	public function truefalsetemplate($pagebelongsto){
	global $db,$request;
	
			$truefalse_ques			= $request['truefalse_ques'];
			$truefalse_answer		= $request['truefalse_answer'];			
			$truefalsetext_count 	= count($truefalse_ques);
			
			
			$vqid 		 = 1;
			$langid 	 = $_SESSION['langid'];
			$uid 		 = $_SESSION['uid'];
			$topicid 	 = $_SESSION['topicid'];
			$sid 		 = $_SESSION['sid'];
			$cid		 = $_SESSION['cid'];
			$semid		 = $_SESSION['semid'];
			$univid		 = $_SESSION['unid'];
			$template_type = 'true_false_template';
			$aid = $this->setArrangementId($pagebelongsto);
			
		/*	if($_FILES["upload_audio"]["name"]){
				$randomval = rand(1000,9999);
				$aname = $_FILES["upload_audio"]["name"];
				$extension = pathinfo($_FILES["upload_audio"]['name'], PATHINFO_EXTENSION);	
				$asize = $this->formatSizeUnits($asize);
				console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES["upload_audio"]["tmp_name"]);
				$audiopath = UPLOAD_AUDIO_URL ."tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
				$audioname = "tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
				move_uploaded_file($_FILES["upload_audio"]["tmp_name"],UPLOAD_AUDIO_URL ."tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);     
				console(LOG_LEVEL_TRACE, "Audio Stored in :: ".UPLOAD_AUDIO_URL ."tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);
			}	*/
			
			
			if($request['qidtfvalue']!=""){
			
				$quesdetails = $db['master']->getOneRow("SELECT aid,qid,qvtype,pagebelongsto FROM questions WHERE qid='".$request['qidtfvalue']."' AND status='active'");
				$aid = $quesdetails['aid'];
				
				$db ['master']->query("UPDATE questions SET status='removed' WHERE qid='".$request['qidtfvalue']."' AND qvtype='".$request['qtypetfvalue']."' AND status = 'active'");
				$db['master']->query("UPDATE language_audios SET status='removed' WHERE qid='".$request['qidtfvalue']."' AND qtype='".$request['qtypetfvalue']."' AND status='active'");
				$db['master']->query("UPDATE true_false_template SET status='removed' WHERE qid='".$request['qidtfvalue']."' AND status='active'");
				$db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$request['qidtfvalue']."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
			}
			$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,orderid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','".$request['tforderid']."')");
			$lastid = $db['master']->getLastID();
				
			$quesdetails = $db['master']->getOneRow("SELECT qid,qvtype,pagebelongsto FROM questions WHERE qid='".$lastid."' AND status='active'");
				
				//if($request['addlangcount'] != "" || $request['editlangcount']!="")
				//{
					console(LOG_LEVEL_TRACE, " audio count :: ".$request['audiolangcount']);
					if($request['edittfcount']!=""){
						console(LOG_LEVEL_TRACE, " edit count :: ".$request['edittfcount']);
						$count = $request['edittfcount']-1;
					}else if($request['addtfcount'] != ""){
						console(LOG_LEVEL_TRACE, " addaudio count :: ".$request['addtfcount']);
						$count = $request['addtfcount']-1;
					}else if($request['addlangcount']){
						console(LOG_LEVEL_TRACE, " addaudio count :: ".$request['addlangcount']);
						$count = $request['addlangcount']-1;
					}
					
					if($count == ""){
						$count = 1;
					}
					console(LOG_LEVEL_TRACE, "count :: ".$count);
				if($count != ""){
					for($i=1; $i<=$count; $i++){
						$language = $request["truefalselanguage".$i];
						$filename = "upload_audio".$i;
						/*if(($_FILES["upload_audio".$i]["name"]) != "" ){
							$filename = "upload_audio".$i;
						}else{
							$filename = "eupload_audio".$i;
						}*/
						if($_FILES[$filename]["name"]){
							$randomval = $aname = $atype = $asize = $audiopath = $audioname = '';
							$randomval = rand(1000,9999);
							$aname = $_FILES[$filename]["name"];
							$atype = $_FILES[$filename]["type"];
							$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
							$asize = $_FILES[$filename]["size"];
							$asize = $this->formatSizeUnits($asize);
							console(LOG_LEVEL_TRACE, "Temp file :: ".$_FILES[$filename]["tmp_name"]);
							
							$audiopath = USER_UPLOAD_DIR."audios/tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							$audioname = "tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension;
							move_uploaded_file($_FILES[$filename]["tmp_name"],USER_UPLOAD_DIR."audios/tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);     
							console(LOG_LEVEL_TRACE, "Audio Stored in :: ".USER_UPLOAD_DIR."audios/tfaudio_". date('YmdHis').'_'.$randomval.'.'.$extension);
							$ins_query = $db ['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES('".$quesdetails['qid']."','".$audiopath."','".$language."','".$audioname."','".$asize."','".$atype."','".$quesdetails['pagebelongsto']."','".$quesdetails['qvtype']."')");
						}else if($request["eupload_audio".$i]){
							console(LOG_LEVEL_TRACE, "Temp file :: ".$request["eupload_audio".$i]);
							
							$audiopath = USER_UPLOAD_DIR."audios/".$request["eupload_audio".$i];
							$audioname = $request["eupload_audio".$i];
							$ins = $db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,pagebelongsto,qtype) VALUES('".$quesdetails['qid']."','".$audiopath."','".$language."','".$audioname."','".$quesdetails['pagebelongsto']."','".$quesdetails['qvtype']."')");
						}
						
						
					}
					
				}
			
			
			for($i=0; $i < $truefalsetext_count; $i++){
			$question = $answer = '';
			
			$question = mysql_real_escape_string($truefalse_ques[$i]);
			$answer   = $truefalse_answer[$i];
			if($question!='')
			$db ['master']->query("INSERT INTO true_false_template (question,answer,pagebelongsto,qid) VALUES ('".(($question))."','".$answer."','".$pagebelongsto."','".$lastid."')");
			   // make value in question table for template true_false_template		   
			  
			}
			
		
			
			if($db ['master']->affectedRows()>0){						
				$message =  "True Or False Questions added successfully";
				}
			else{						
				$message = "Fail to add True Or False Questions";
				}
			
			return $message;
			
			
	}
	
	
	
	public function addZipFile($pagebelongsto){
	global $db,$request;
	
		/* Zip file add and extraction */
		
		if($_FILES["zip_file"]["name"]) {
			
			$message = "There was a problem with the upload. Please try again.";
			
				if ($_FILES["zip_file"]["error"] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES["zip_file"]["error"]);
					}else {

					//if($_FILES["zip_file"]["name"]) {												
					
							$zname	= $filename = $_FILES["zip_file"]["name"];
							$source = $_FILES["zip_file"]["tmp_name"];
							$type 	= $_FILES["zip_file"]["type"];	
							$filename = end(explode(".", $zname));
							$zname = $filename[0];
							
							$zsize = $_FILES["zip_file"]["size"];
							$zsize = $this->formatSizeUnits($zsize);
							console(LOG_LEVEL_TRACE, "Zip file Name::".$zname."Zip file size::".$zsize."Temp file: ".$source);		

							
							
							$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
							foreach($accepted_types as $mime_type) {
								if($mime_type == $type) {
									$okay = true;
									console(LOG_LEVEL_TRACE, "accepted_types::".$accepted_types."Zip file size::".$zsize."Temp file: ".$source);
									break;
								} 
							}
							
							$continue = strtolower($name[1]) == 'zip' ? true : false;
							$zipfile =1;
							if(!$continue) {								
								$zipfile = 0;
								
							}
							$aid = $this->setArrangementId($pagebelongsto);
							$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid) VALUES ('canvas','".$pagebelongsto."','1')");
									
							$qid = $db['master']->getLastID();
							$target_filename = $qid."_html5_".$zname;
							$target_path = USER_UPLOAD_DIR."zipfiles/".$target_filename;  // Upload path
							if($zipfile == 1 && move_uploaded_file($source, $target_path)) {
								$zip = new ZipArchive();
								$x = $zip->open($target_path);
								if ($x === true) {
									$zip->extractTo(USER_UPLOAD_DIR."extracted_files/".$target_filename); // Extraction path
									$zip->close();
									
								
									
									$db ['master']->query("INSERT INTO zipfile (qid,fname,fsize) VALUES ('".$qid."','".$target_filename."','".$zsize."')");		
									
									if($db ['master']->affectedRows()>0){						
										$message =  "Zip file added successfully";
									}else{						
										$message = "Fail to add zip files";
									}
							
									//unlink($target_path);
								}
								$message = "Your .zip file was uploaded and unpacked.";
							} else {	
								$message = "There was a problem with the upload. Please try again.";
								if($zipfile==0)
								$message = "The file you are trying to upload is not a .zip file. Please try again.";		
							}
						//}						
					
					console(LOG_LEVEL_TRACE, "message final::".$message);
							
					
					
					
		}
		
		
	}
	return $message;
	}
	
	
public function setArrangementId($pagebelongsto){
global $db,$request;
		$query 			= "SELECT max(aid) as arrangementid from questions where pagebelongsto='".$pagebelongsto."' AND status='active'";
		$arrangeid 		= $db['master']->getOneRow($query);
		$arrangementid	= $arrangeid['arrangementid'];
		if($arrangementid =='' || $arrangementid==NULL || $arrangementid==0)
		$arrangementid  = 1;
		else
		$arrangementid  = $arrangementid+1;
		
		return $arrangementid;


}


public function getSpecialSymbols(){
	/* this function used to get all special symbols mentioned in array list */
	global $db,$request;	
	
	$specialSymbols = array('α','β','γ','δ','ε','ζ','η','θ','ι','κ','λ','μ','ν','ξ','ο','π','ρ','σ','τ','υ','φ','χ','ψ'
	,'ω','≠','≥','≤','±','×','a^b','√a',' 3√a',' 4√a','n√a');
	$i				= 1;
	$tbs_start		= '<table class="table table-striped table-hover table-condensed"><TR>';
	$tbs_end 		= '</TR></table>';
	$input_array 	= array_chunk($specialSymbols,6);
	foreach ($input_array as $values){		
			$specialchars.=$tbs_start;
			$tbs_mid = $j = '';
			foreach ($values as $value) {
			$j++;
			$tbs_mid .= '<TD><button type="button" class="btn btn-primary" name="'.$i.$j.'" onclick="appendSymbolsToText(\'\',\'\',\''.$value.'\');">'.$value.'</button></TD>';		
			}			
			$specialchars.=$tbs_mid.$tbs_end;			
			//console(LOG_LEVEL_TRACE, "specialchars::".$specialchars);			
	}
	return $specialchars;		
	}
	
	
public function getLanguages($langid=''){
	/* this function used to get all keywords from keyword table table */
	global $db,$request;	
	
	
	$query 			= "SELECT langid,lang_name from language where status='active'";
	$languageid 	= $db['master']->getResults($query);
	$languages 		= '<option value="" >Choose Audio Language</option>';	

	
	foreach ($languageid as $values ){					
			if ($values['langid'] == $langid){
			$languages .= "<option value='" . $values ['langid'] . "' selected>" . $values ['lang_name'] ."</option>";
			}
			else{
			$languages .= '<option value="' . $values['langid']. '" >' . $values['lang_name'].'</option>';					
			}
	}
	
	return $languages;
	
	
	}
	
public function getlanguagesCommon($id){
		/* this function used to get all keywords from keyword table table */
		global $db,$request;	
		$query 			= "select l.langid,l.lang_name  from language_audios as la join language as l ON (l.langid = la.langid) where la.pagebelongsto = '".$id."' AND l.status='active' GROUP BY la.langid";
		$languageid 	= $db['master']->getResults($query);   
		
		if($languageid){	
			$languages 		= '<option value="" >Choose Audio Language</option>';	
		}else{ 
			$query 			= "SELECT langid,lang_name from language where status='active'";
			$languageid 	= $db['master']->getResults($query);
			$languages 		= '<option value="" >Choose Audio Language</option>';
		}
		
		foreach ( $languageid as $values ){		
			$languages .= '<option value="' . $values['langid']. '" >' . $values['lang_name'].'</option>';					
		}
		return $languages;
	}


public function GetTemplateValues($type,$qid){
	
	global $db,$request;	
	
	$return_value = $table = '';
	switch($type){
	case 'true_false_template':
	$table = 'true_false_template';
	break;
	case 'matching':
	$table = 'match_the_following';
	break;
	
	}
	
	if($table!=''){
	$query 			= "SELECT question from $table where qid='".$qid."' AND status='active'";
	$values 		= $db['master']->getOneRow($query);
	$return_value	= $values['question'];
	
			$string_length = strlen($return_value);
			if($string_length>=50){
			$str = wordwrap($return_value, 50);
			$str = explode("\n", $str);
			$return_value = $str[0] . '...';}
	}

	return $return_value;
}

function GetMainTab(){
global $db,$request;	
	
	$query 			= "SELECT t.* from tabs t,questions q where q.pagebelongsto='".$request['id']."' AND q.qid=t.qid AND t.reftabid ='0' AND t.status='active'";
	$tabs 			= $db['master']->getResults($query);
	$tabsval 		= '<option value="" >Choose Main Tab to link</option>';		
	foreach ( $tabs as $values ){	

			if($values['tabheader']!='')
			$values['tabheader'] = $values['tabheader'].'=>';
			
			if($values['subcontent']!='')
			$values['subcontent'] = '=>'.$values['subcontent'];
			
			$tabsval .= '<option value="' . $values['tabid']. '" >' .$values['tabheader'].$values['main_content'].$values['subcontent'].'</option>';					
	}	
	return $tabsval;

}	

function ques_aids(){
global $db,$request;

$aid_array = array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);

$orderids 		= '<option value="" >Choose order id</option>';		
	foreach ( $aid_array as $values ){		
		
			$orderids .= '<option value="' . $values. '" >' . $values.'</option>';					
	}	
	return $orderids;


}

function checkQuesLinked($qid){
global $db,$request;
$checkQuesLinked = '';
$query 						= "SELECT lq.*,t.* from link_questions_to_tabs lq,tabs t  where lq.qid ='".$qid."' AND lq.maintabid=t.tabid AND lq.status='active'";
$checkQuesLinked 			= $db['master']->getOneRow($query);

if($checkQuesLinked){
$query2 						= "SELECT * from tabs where tabid='".$checkQuesLinked['subtabid']."' and status='active'";
$subtabLinked 					= $db['master']->getOneRow($query2);
$checkQuesLinked['subcontent'] 	=  $subtabLinked['subcontent']; 
}


return $checkQuesLinked;
}


function link_questions_to_tabs(){
			global $db,$request;
			$qid 			= $request['linkqid'];
			$maintabid  	= $request['maintabs'];
			$subtabid  		= $request['subtabs'];
			$pagebelongsto  = $request['id'];
			$orderid  		= $request['questab_aid'];
			
			if($subtabid=='')
			$subtabid = $maintabid;

			$db ['master']->query("INSERT INTO link_questions_to_tabs (qid,maintabid,subtabid,pagebelongsto,orderid) VALUES ('".$qid."','".$maintabid."','".$subtabid."','".$pagebelongsto."','".$orderid."')");		
									
			if($db ['master']->affectedRows()>0){						
				$message =  "Question Linked successfully";
			}else{						
				$message = "Fail to Link the question to tabs";
			}
			
			return $message;

}

function unlinkQuestion(){

		global $db,$request;
		
		$del_qry =  "update link_questions_to_tabs set status='removed'  where link_qid_tab='".$request['unlinkqid']."' and status='active'";
		$updateQuestions = $db['master']->query ($del_qry);
		
		if($db ['master']->affectedRows()>0){						
				$message =  "Questions UnLinked successfully";
			}else{						
				$message = "Fail to UnLink the question from tabs";
			}
			
			return $message;

}


/*********************************** Edit option functionlity Start ******************************************/
public function EditHeaderBulletins($pagebelongsto){
	global $db,$request;

	console(LOG_LEVEL_TRACE, "EditHeaderBulletins Function");
	
	$qid = $editqid		=	$request["uqid"]; 
	$ques_query			= "SELECT * FROM questions where qid='".$editqid."' AND status='active'";
	$getQuesType    	= $db['master']->getOneRow($ques_query);

	$qvtype				= $getQuesType['qvtype'];
	$pagebelongsto		= $getQuesType['pagebelongsto'];
	$uhid 				= $getQuesType['hid'];
	$aid				= $getQuesType['aid'];
	$tabid				= $getQuesType['tabid'];
				
				
	$ques_qry 		=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
	$updateHeader 	= $db['master']->query ($ques_qry);
			
	$del_qry 		=  "update header set status='removed'  where hid='".$uhid."' and status='active'";
	$updateHeader 	= $db['master']->query ($del_qry);
			
	$bulletin_qry 		=  "update bulletin_content set status='removed'  where hid='".$uhid."' and status='active'";
	$updateHeader 	= $db['master']->query ($bulletin_qry);
	
	$link_qry       = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
				
				
	$headertxt = $request['eheadertxt'];
	$header_animation = $request['eheader_animation'];
	
	$aheadername = $aheadersize = $arightimg = $arightaudio = $arightaudiosize = "";
	
	if($_FILES["eheadertxt_audio"]["tmp_name"]!=''){
		$randomval  = rand(1000,9999);
		$aheadername 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["eheadertxt_audio"]["name"];
		$aheadersize 		= $_FILES["eheadertxt_audio"]["size"];
		$aheadersize 		= $this->formatSizeUnits($aheadersize);
		console(LOG_LEVEL_TRACE, "New header Audio Name::".$aheadername."New header Audio Size::".$aheadersize."Temp file: ".$_FILES["eheadertxt_audio"]["tmp_name"]);
						
		if(move_uploaded_file($_FILES["eheadertxt_audio"]["tmp_name"],USER_UPLOAD_DIR .'audios/'.$aheadername)){					
			$langid = 1;
			$aheaderpath = USER_UPLOAD_DIR .'audios/'. $aheadername;
			console(LOG_LEVEL_TRACE, "Header Audio Moved to the Specified Path");
			//$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
		}	
	}else{
		if($request["etxtaudio"] != ""){
			console(LOG_LEVEL_TRACE, "Header Audio Already Exists");
			$aheadername = $request["etxtaudio"]; 
			$aheadersize = $request["etxtaudiosize"]; 
			console(LOG_LEVEL_TRACE, "Temp file :: ".$request["etxtaudio"]);
			$langid = 1;
		}
	}
	
	
	if($_FILES["eimg_name"]["tmp_name"]!=''){
		$randomval  = rand(1000,9999);
		$arightimg 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["eimg_name"]["name"];
		//$arightimgsize 		= $_FILES["eimg_name"]["size"];
		//$arightimgsize 		= $this->formatSizeUnits($arightimgsize);
		console(LOG_LEVEL_TRACE, "New Right Side Image Name::".$arightimg."New Right Side Image Size::".$arightimgsize."Temp file: ".$_FILES["eimg_name"]["tmp_name"]);
						
		if(move_uploaded_file($_FILES["eimg_name"]["tmp_name"],USER_UPLOAD_DIR .$arightimg)){					
			$langid = 1;
			$aheaderpath = USER_UPLOAD_DIR .$arightimg;
			console(LOG_LEVEL_TRACE, "Right Side Image Moved to the Specified Path");
			//$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
		}	
	}else{
		if($request["eimgnme"] != ""){
			console(LOG_LEVEL_TRACE, "Right Side Image Already Exists");
			$arightimg = $request["eimgnme"]; 
			//$aheadersize = $request["etxtaudiosize"]; 
			console(LOG_LEVEL_TRACE, "Temp file :: ".$request["eimgnme"]);
			$langid = 1;
		}
	}
	
	
	if($_FILES["eimg_audio"]["tmp_name"]!=''){
		$randomval  = rand(1000,9999);
		$arightaudio 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["eimg_audio"]["name"];
		$arightaudiosize 		= $_FILES["eimg_audio"]["size"];
		$arightaudiosize 		= $this->formatSizeUnits($arightaudiosize);
		console(LOG_LEVEL_TRACE, "New Rigth Side Audio Name::".$arightaudio."New Rigth Side Audio Size::".$arightaudiosize."Temp file: ".$_FILES["eimg_audio"]["tmp_name"]);
						
		if(move_uploaded_file($_FILES["eimg_audio"]["tmp_name"],USER_UPLOAD_DIR .'audios/'.$arightaudio)){					
			$langid = 1;
			$arigthpath = USER_UPLOAD_DIR .'audios/'. $arightaudio;
			console(LOG_LEVEL_TRACE, "Rigth Side  Audio Moved to the Specified Path");
			//$db['master']->query("INSERT INTO language_audios(qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$qInsId."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','".$template_type."','".$hid."','".$bid."')");
		}	
	}else if($request["eimgaudio"] != ""){
			console(LOG_LEVEL_TRACE, "Rigth Side Audio Already Exists");
			$arightaudio = $request["eimgaudio"]; 
			$arightaudiosize = $request["eimgaudiosize"]; 
			console(LOG_LEVEL_TRACE, "Temp file :: ".$request["eimgaudio"]);
			$langid = 1;
	}else{
		console(LOG_LEVEL_TRACE, "Rigth Side Audio is NULL");
		$arightaudio = ""; 
		$arightaudiosize = ""; 
	}
	
	$header_text = mysql_real_escape_string($headertxt);
	$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,imgname,img_aname,img_asize,header_animation) VALUES ('".$header_text."','".$qvtype."','".$aheadername."','".$aheadersize."','".$arightimg."','".$arightaudio."','".$arightaudiosize."','".$header_animation."')");
	$hid = $db['master']->getLastID();
	
	$db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid,orderid) VALUES ('".$qvtype."','".$pagebelongsto."','".$aid."','". $hid ."','".$request['edittemp4orderid']."')");
		
	$bullettext_val = $bullettext_animation = $abulletname = $abulletsize = "";	 
	$bulletin_count = count($request['etemptext']);
	console(LOG_LEVEL_TRACE, "Bulletin Count :: ".$bulletin_count);
		
	for($i=0; $i < $bulletin_count; $i++){
		$bullettext_val = $request['etemptext'][$i];
		$bullettext_animation = $request['etemptext_animation'][$i];
		$opt_sno		= $i+1;
	if($bullettext_val != ""){
		if($_FILES["etempaudio"]["tmp_name"][$i]!=''){					
			$randomval  = rand(1000,9999);
			$abulletname 		= date('YmdHis').'_'.$randomval.'_'.$_FILES["etempaudio"]["name"][$i];
			$abullettype 		= $_FILES["etempaudio"]["type"][$i];
			$abulletsize 		= $_FILES["etempaudio"]["size"][$i];
			$abulletsize 		= $this->formatSizeUnits($abulletsize);
			console(LOG_LEVEL_TRACE, "Bulletin $i Audio Name::".$abulletname."Bulletin $i Audio Type::".$abullettype."Bulletin $i Audio Size::".$abulletsize."Temp file: ".$_FILES["etempaudio"]["tmp_name"][$i]);
							
			if(move_uploaded_file($_FILES["etempaudio"]["tmp_name"][$i],USER_UPLOAD_DIR .'audios/'.$abulletname)){					
				$langid = 1;
				console(LOG_LEVEL_TRACE, "Bulletin Audio Moved to the Specified Path");
				$audiopath = USER_UPLOAD_DIR .'audios/'. $abulletname;
			}			  
		}else if($request["ebulletaudio".$i] != ""){
			console(LOG_LEVEL_TRACE, "Bulletin $i Audio Already Exits"); 
			$abulletname = $request["ebulletaudio".$i];
			$abulletsize = $request["ebulletaudiosize".$i];
			console(LOG_LEVEL_TRACE, "Temp file :: ".$request["etxttempaudio".$k]);
			$langid = 1;
		}else if($_FILES["etempaudio"]["tmp_name"][$i]=='' && $request["ebulletaudio".$i] == ""){
			console(LOG_LEVEL_TRACE, "Bulletin $i Audio Is NULL"); 
			$abulletname = "";
			$abulletsize = "";
		}
		
        $bullet_text = mysql_real_escape_string($bullettext_val);		
		$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($bullet_text))."','".$abulletname."','".$abulletsize."','left','".$bullettext_animation."')");
	   }else{
			console(LOG_LEVEL_TRACE, " Bulletin Text $i is Empty");
	   }
	}
}

public function EditHeaderBulletins11($pagebelongsto){
	global $db,$request;	
	
	/* header part details  Start */
	$template_type  	= $request['etemp_type'];
	$header_text 		= $request['eheadertxt'];		
	$header_animation 	= $request['eheader_animation'];	
	$filename 			= 'eheadertxt_audio';
	$audiopath  		= USER_UPLOAD_DIR;

	
	$allowedExts = array("mp3", "mp4", "wma");
	$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
	console(LOG_LEVEL_TRACE, "Header Text Audio Filename:".$filename);	
	$filename1 = 'eimg_name';
	$filename2 = 'eimg_audio';		
				
				
				
				// Header Part File upload and DB Insert
				
				$randomval = rand(1000,9999);
					
				$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename]["name"];
				
				$randomval = rand(1000,9999);
					
				$imgname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename1]["name"];
				
				
				$randomval = rand(1000,9999);
					
				$img_aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename2]["name"];
				
				
				
					
				$qid = $editqid		=	$request["uqid"]; 
				$ques_query			= "SELECT * FROM questions where qid='".$editqid."' AND status='active'";
				$getQuesType    	= $db['master']->getOneRow($ques_query);

				$qvtype				= $getQuesType['qvtype'];
				$pagebelongsto		= $getQuesType['pagebelongsto'];
				$uhid 				= $getQuesType['hid'];
				$aid				= $getQuesType['aid'];
				$tabid				= $getQuesType['tabid'];
				
				

			$ques_qry 		=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateHeader 	= $db['master']->query ($ques_qry);
			
			$del_qry 		=  "update header set status='removed'  where hid='".$uhid."' and status='active'";
			$updateHeader 	= $db['master']->query ($del_qry);
			
			$bulletin_qry 		=  "update bulletin_content set status='removed'  where hid='".$uhid."' and status='active'";
			$updateHeader 	= $db['master']->query ($bulletin_qry);
	
	




				$header_query		= "SELECT * FROM header where hid='".$uhid."' AND status='active'";
				$headerdetails    	= $db['master']->getOneRow($header_query);	
				$header_text 		= $headerdetails['htext'];		
				$header_animation 	= $headerdetails['header_animation'];	
				$headerAudioname	= $headerdetails['txt_aname'];	
				$hasize				= $headerdetails['txt_asize'];	
				$headerAudioPath 	= USER_UPLOAD_DIR.'audios/'.$headerdetails['txt_aname'];
				
				
				
				if(($template_type=='template1' || $template_type=='template3' )&& (move_uploaded_file($_FILES[$filename]["tmp_name"],
					USER_UPLOAD_DIR .'audios/'.$aname))){			
				     
				console(LOG_LEVEL_TRACE, "edit audio Stored in::".USER_UPLOAD_DIR .$aname);

				console(LOG_LEVEL_TRACE, "edit template 1 or template 2::".USER_UPLOAD_DIR . $aname);				
				
					//$randomval = rand(1000,9999);					
					//$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$asize = $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES[$filename]["tmp_name"]);
					$audiopath = $audiopath.$aname;
				
				$head_txt = mysql_real_escape_string($header_text);
				
				$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,header_animation) VALUES ('".$head_txt."','".$template_type."','".$aname."','".$asize."','".$header_animation."')");
				}
				else if(($template_type=='template2' || $template_type=='template4') && ((move_uploaded_file($_FILES[$filename1]["tmp_name"],
					USER_UPLOAD_DIR .$imgname)) || (move_uploaded_file($_FILES[$filename2]["tmp_name"],
					USER_UPLOAD_DIR .'audios/'.$img_aname)) || (move_uploaded_file($_FILES[$filename]["tmp_name"],
					USER_UPLOAD_DIR .'audios/'.$aname)))){
					
					console(LOG_LEVEL_TRACE, "edit Image Stored in::".USER_UPLOAD_DIR . $_FILES[$filename1]["name"]);
					console(LOG_LEVEL_TRACE, "edit Image Audio in::".USER_UPLOAD_DIR . $_FILES[$filename2]["name"]);
					
					$aname = $headerAudioname;
					$asize = $hasize;
					$imgname = $headerdetails['imgname'];
					$img_aname = $headerdetails['img_aname'];
					$img_asize = $headerdetails['img_asize'];



					if($_FILES[$filename]["name"]) {
					$randomval = rand(1000,9999);					
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename]["name"];
					$atype = $_FILES[$filename]["type"];
					$asize = $_FILES[$filename]["size"];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "Header Audio Name::".$aname."Header Audio Type::".$atype."Header Audio Size::".$asize."Temp file: ".$_FILES[$filename]["tmp_name"]);
					$audiopath = $audiopath.$aname;
					}
					
					
					
					/* Image Upload Part Start */
					if($_FILES[$filename1]["name"]) {					
					$randomval = rand(1000,9999);					
					$imgname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename1]["name"];
					$imgtype = $_FILES[$filename1]["type"];
					$img_size = $_FILES[$filename1]["size"];
					$img_size = $this->formatSizeUnits($img_size);
					console(LOG_LEVEL_TRACE, "Image Name::".$imgname."Image Type::".$imgtype."Image Size::".$img_size."Temp file: ".$_FILES[$filename1]["tmp_name"]);
					}					
					
					/* Image Upload Part End */
					
					/* Audio Upload Part Start */	

					if($_FILES[$filename2]["name"]) {
					$randomval = rand(1000,9999);
					$img_aname = date('YmdHis').'_'.$randomval.'_'.$_FILES[$filename2]["name"];
					$atype = $_FILES[$filename2]["type"];
					$img_asize = $_FILES[$filename2]["size"];
					$img_asize = $this->formatSizeUnits($img_asize);
					console(LOG_LEVEL_TRACE, "Image Audio Name::".$img_aname."Image Audio Type::".$atype."Image Audio Size::".$img_asize."Temp file: ".$_FILES[$filename2]["tmp_name"]);
					}				
					
					/* Audio Upload Part End */					
					
					$header_txt = mysql_real_escape_string($header_text);
					$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,imgname,img_aname,img_asize,header_animation) VALUES ('".$header_txt."','".$template_type."','".$aname."','".$asize."','".$imgname."','".$img_aname."','".$img_asize."','".$header_animation."')");
				
				}
				else if($request['eheadertxt']!=''){				
				
				$header_txt = mysql_real_escape_string($request['eheadertxt']);
				if(($template_type=='template2' || $template_type=='template4')){

				$header_text 		= $headerdetails['htext'];		
				$header_animation 	= $headerdetails['header_animation'];	
				$headerAudioname	= $headerdetails['txt_aname'];	
				$hasize				= $headerdetails['txt_asize'];	
				$headerAudioPath 	= USER_UPLOAD_DIR.'audios/'.$headerdetails['txt_aname'];
				
				
				$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,imgname,img_aname,img_asize,header_animation) VALUES ('".$header_txt."','".$template_type."','".$headerAudioname."','".$hasize."','".$headerdetails['imgname']."','".$headerdetails['img_aname']."','".$headerdetails['img_asize']."','".$request['eheader_animation']."')");
				
				}
				else if(($template_type=='template1' || $template_type=='template3')){				
				$db ['master']->query("INSERT INTO header (htext,template_type,txt_aname,txt_asize,header_animation) VALUES ('".$header_txt."','".$template_type."','".$headerAudioname."','".$hasize."','".$request['eheader_animation']."')");
				}
				
				
				

				}
	
	
	
		       $hid		= $db['master']->getLastID();
			   
			   // make value in question table for template
			   
			 //  $aid = $this->setArrangementId($pagebelongsto);
			   
			   $db ['master']->query("INSERT INTO questions (qvtype,pagebelongsto,aid,hid) VALUES ('".$template_type."','".$pagebelongsto."','".$aid."','". $hid ."')");
			   
			   
			   
			   if($template_type=='template1')
			   $tp_align = 'center';
			   if($template_type=='template2')
			   $tp_align = 'center';
			   if($template_type=='template3'){
			   $tp_align = 'left';
			   $tp_align_2 = 'right';
			   }
			   if($template_type=='template4')
			   $tp_align = 'left';
	
	
				/* header part details  End */
			
			
			
			$temptext		= $request['etemptext'];
			$filename		= "etempaudio";
			$temptext_count = count($temptext);
			$temptext_animate	= $request['etemptext_animation'];		
			
			//print_r($_FILES);
			
			for($i=0; $i < $temptext_count; $i++){
			//print_r($_FILES[$filename]["tmp_name"]);
			$temptext_value = $opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			$opt_sno		= $i+1;
			$temptext_value = $temptext[$i];	
			$txt_animation  = $temptext_animate[$i];
						
			
				if($_FILES["etempaudio"]["tmp_name"][$i]!=''){
				
					$randomval = rand(1000,9999);		
				
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES["etempaudio"]["name"][$i];
					$atype = $_FILES["etempaudio"]["type"][$i];
					$asize = $_FILES["etempaudio"]["size"][$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "edit options textbox Audio Name::".$aname."options textbox Audio Type::".$atype."edit  options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio"]["tmp_name"][$i]);
					
					$temp_text = mysql_real_escape_string($temptext_value);
					
					if(move_uploaded_file($_FILES["etempaudio"]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'.$aname)){	
					$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$aname."','".$asize."','".$tp_align."','".$txt_animation."')");
					}
				}	

				else if($temptext_value!=''){
			
				$header_query		= "SELECT * FROM bulletin_content where hid='".$uhid."' AND opt_sno='".$opt_sno."' AND status='active'";
				$bulletin_details    	= $db['master']->getOneRow($header_query);
				
				$aname = $bulletin_details['aname'];
				$asize = $bulletin_details['asize'];
				
				console(LOG_LEVEL_TRACE, "edit Audio Name::".$aname."edit  Audio Size::".$asize);
				$temp_text = mysql_real_escape_string($temptext_value);
				
				$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$aname."','".$asize."','".$tp_align."','".$txt_animation."')");
			
			}
			
			  
			}	
			
			
			
			if($template_type=='template3'){
			
			$temptext		= $request['etemptext_right'];
			$filename		= "etempaudio_right";
			$temptext_count = count($temptext);
			$temptext_right_animation		= $request['etemptext_right_animation'];
			
			for($i=0; $i < $temptext_count; $i++){
			//print_r($_FILES[$filename]["tmp_name"]);
			$temptext_value = $opt_sno = $text_aname = $aname = $asize = $filename = $txt_animation = '';
			$opt_sno		= $i+1;
			$temptext_value = $temptext[$i];	
			$txt_animation  = $temptext_right_animation[$i];			
						
			
			if($_FILES["etempaudio_right"]["tmp_name"][$i]!=''){
					//$aname = $_FILES["etempaudio_right"]["name"][$i];
					$aname = date('YmdHis').'_'.$randomval.'_'.$_FILES["etempaudio_right"]["name"][$i];
					$atype = $_FILES["etempaudio_right"]["type"][$i];
					$asize = $_FILES["etempaudio_right"]["size"][$i];
					$asize = $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "edit  options textbox Audio Name::".$aname."edit options textbox Audio Type::".$atype."edit options textbox Audio Size::".$asize."Temp file: ".$_FILES["tempaudio_right"]["tmp_name"][$i]);
					
					if(move_uploaded_file($_FILES["etempaudio_right"]["tmp_name"][$i],
					USER_UPLOAD_DIR .'audios/'. $aname)){	
					$temp_text = mysql_real_escape_string($temptext_value);
					$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$aname."','".$asize."','".$tp_align_2."','".$txt_animation."')");
					}
				}
			else if($temptext_value!=''){
			
			$header_query		= "SELECT * FROM bulletin_content where hid='".$uhid."' AND opt_sno='".$opt_sno."' AND status='active'";
			$bulletin_details    	= $db['master']->getOneRow($header_query);
			
			$aname = $bulletin_details['aname'];
			$asize = $bulletin_details['asize'];
			
			
			console(LOG_LEVEL_TRACE, "edit Audio Name::".$aname."edit  Audio Size::".$asize);
			
			$temp_text = mysql_real_escape_string($temptext_value);
			
			$db ['master']->query("INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) VALUES ('".$hid."','".$opt_sno."','".(($temp_text))."','".$aname."','".$asize."','".$tp_align."','".$txt_animation."')");
			
			}	
			
			  
			 }
			
			
			}

}

public function editvideos($editqid){
// This function used to edit the video audio files
global $db,$request;
console(LOG_LEVEL_TRACE, "Edit Videos Function :: ".$editqid);
$editqid = $request["evqid"];
$videoCount = $request['videoCount'];
console(LOG_LEVEL_TRACE," videoCount::".$videoCount);
console(LOG_LEVEL_TRACE,"Edit video id::".$editqid);
$vqid 		 = 1;
$langid 	 = $_SESSION['langid'];
$uid 		 = $_SESSION['uid'];
$topicid 	 = $_SESSION['topicid'];
$sid 		 = $_SESSION['sid'];
$cid		 = $_SESSION['cid'];
$semid		 = $_SESSION['semid'];
$univid		 = $_SESSION['unid'];


   

$pagebelongsto		= $request['id'];	
$filename 			= "eqvideos1";	


$lang_audioid			= "SELECT audioid FROM language_audios where qid='".$editqid."' AND status='active'";
$lang_audioid_details	= $db['master']->getResults($lang_audioid);

if(count($lang_audioid_details)>0){
foreach($lang_audioid_details as $val_audioids){
$audioids[] = $val_audioids['audioid'];
}
}


		$video_ques_query		= "SELECT * FROM questions where qid='".$editqid."' AND status='active'";
		$video_ques_details    	= $db['master']->getOneRow($video_ques_query);
		$aid 					= $video_ques_details['aid'];

	// video and audio upload base on language start
		if($_FILES[$filename]['name']){		
			//foreach($videoaid as $i){				
				$videopath  = USER_UPLOAD_DIR;
				$aid = '';
				//$aid = $this->setArrangementId($pagebelongsto);
				$allowedExts = array("mp3", "mp4", "wma");
				$extension = pathinfo($_FILES[$filename]['name'], PATHINFO_EXTENSION);	
				console(LOG_LEVEL_TRACE, "filename:".$filename);
				if ($_FILES[$filename]["error"] > 0)  {  
					console(LOG_LEVEL_TRACE, "Error Return Code::".$_FILES[$filename]["error"]." filename::".$filename);
				}else {
					console(LOG_LEVEL_TRACE, "filename vname:".$filename);
					$vname = date('YmdHis').'_'.$_FILES[$filename]["name"];
					$vtype = $_FILES[$filename]["type"];
					$vsize = $_FILES[$filename]["size"];
					$vsize = $this->formatSizeUnits($vsize);
					console(LOG_LEVEL_TRACE, "edit video Name::".$vname."edit video type::".$vtype."edit video Size".$vsize."Temp file: ".$_FILES[$filename]["tmp_name"]);

					move_uploaded_file($_FILES[$filename]["tmp_name"],
					USER_UPLOAD_DIR . $vname);     
					console(LOG_LEVEL_TRACE, "edit video Stored in::".USER_UPLOAD_DIR . $_FILES[$filename]["name"]);
				}		
				$videopath = $videopath.$vname;
		}
		else{
		
		$videopath				= $video_ques_details['videopath'];
		$vname					= $video_ques_details['vname'];
		$vsize					= $video_ques_details['vsize'];
		$vtype					= $video_ques_details['vtype'];
		$aid					= $video_ques_details['aid'];
		
		}
				
				
				
		$db ['master']->query("INSERT INTO questions (videopath,vname,vsize,vtype,qvtype,pagebelongsto,aid,streamvideo,orderid) VALUES ('".$videopath."','".$vname."','".$vsize."','".$vtype."','video','".$pagebelongsto."','".$aid."','edited','".$request['videoorderid']."')");
	
		$videoid		   = $db['master']->getLastID();
		$audio_language	   = $request['eaudio_language'];						
		$audio_count  	   = count($audio_language);				
		$audiopath		   = USER_UPLOAD_DIR.'audios/';
		console(LOG_LEVEL_TRACE, "edit audio_count::".$audio_count."edit audio_language::".$audio_language);
				
				$get_audio_order = 1;
				for($i=0; $i < $audio_count; $i++){	
				$get_audio_order++;
				$aname = $atype = $asize = $langid = $audiopath = '';
				$audiopath		   = USER_UPLOAD_DIR.'audios/';
				$langid = $audio_language[$i];
				
				if($_FILES["evideoaudio"]["tmp_name"][$i]!=''){
					
					$randomval  = rand(1000,9999);
					$aname 	    = date('YmdHis').'_'.$randomval.'_'.$_FILES["evideoaudio"]["name"][$i];				
					$atype 		= $_FILES["evideoaudio"]["type"][$i];
					$asize 		= $_FILES["evideoaudio"]["size"][$i];
					$langid 	= $audio_language[$i];
					$asize 		= $this->formatSizeUnits($asize);
					console(LOG_LEVEL_TRACE, "edit Languge Audio Name::".$aname."edit Languge Audio Type::".$atype."edit Languge Audio Size::".$asize."edit LangugeTemp file: ".$_FILES["evideoaudio"]["tmp_name"][$i]);		
					if(move_uploaded_file($_FILES["evideoaudio"]["tmp_name"][$i],
					$audiopath.$aname)){	
					$audiopath = $audiopath.$aname;
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$videoid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','video')");					
					}
				}
				else if($langid!=''){	


					$audioid = '';
					$audioid = $audioids[$i];
				
					$lang_query			= "SELECT * FROM language_audios where qid='".$editqid."' AND audioid='".$audioid."' AND status='active'";
				
					$lang_details    	= $db['master']->getOneRow($lang_query);	
			
					$aname 				= $lang_details['aname'];
					$asize 				= $lang_details['asize'];
					$audiopath 			= $lang_details['audiopath'];
					$atype 				= $lang_details['atype'];			
			
					console(LOG_LEVEL_TRACE, "edit Audio Name::".$aname."edit  Audio Size::".$asize."::audiopath-->".$audiopath);
			
					$db ['master']->query("INSERT INTO language_audios (qid,audiopath,langid,aname,asize,atype,pagebelongsto,qtype) VALUES ('".$videoid."','".$audiopath."','".$langid."','".$aname."','".$asize."','".$atype."','".$pagebelongsto."','video')");
					}					
				}
			
	
			if($db ['master']->affectedRows()>0){
				console(LOG_LEVEL_INFO,"Uploaded Video : ".$vname);
				$videoMessage = 1;
				$videoMsg = "Videos Uploaded Successfully ";
			}else{
				$videoMessage = 0;
				$videoMsg = "Videos Not Uploaded Successfully ";
			}
				
		
		
			$ques_qry 				=  "update questions set status='removed'  where qid='".$editqid."' and status='active'";
			$updateHeader 			= $db['master']->query ($ques_qry);				
			$lang_audio_qry 		=  "update language_audios set status='removed'  where qid='".$editqid."'  AND status='active'";
			$updateaudio 			= $db['master']->query ($lang_audio_qry);
			$link_qry               = $db['master']->query("UPDATE link_questions_to_tabs SET status='removed' WHERE qid='".$editqid."' AND status='active' AND pagebelongsto='".$pagebelongsto."'");
		
		// video and audio upload base on language end

}

/*********************************** Edit option functionlity End ******************************************/
public function mapTopic(){
global $db,$request;

$newoptic 		= $request['topic'];
	$searchtopic 	= explode("-", $request['searchtopic']);
	$Existingtopic  = $searchtopic[1];
	// Get values of existing topic id using search topic value
	$existing_topicid = $request['linktopicid'];
	
	console(LOG_LEVEL_TRACE, "newoptic::".$newoptic.'old topic-->'.$Existingtopic.'old topic id-->'.$existing_topicid);

	/* Add topics Start */


	$topic = trim ( $request['topic'] );
	$query = "SELECT topicid FROM topics  WHERE topic_name='".$topic."'  AND uid = '".$_SESSION['uid']."' AND sid = '".$_SESSION['sid']."' AND `status`='active'";
	$res = $db['master']->getOneRow($query);
	
	$already_exist = 0;
	
	
	if($res['topicid'] != ''){
		$message = "Topics Already Exist...";
		
		console(LOG_LEVEL_TRACE, "alert message already exist::".$message);
		$already_exist = 1;
		return false;
	}else{
		$insq = "INSERT INTO topics(`topic_name`,`uid`,`sid`) VALUES('".$topic."','".$_SESSION['uid']."','".$_SESSION['sid']."')";
		$result = $db['master']->query($insq);
		
		$id	= $db['master']->getLastID();
		$newtopicid = $id;
		
		$_SESSION['topicid'] 	= $id;
		$_SESSION['topic_name'] = $request['topic'];
		
		$tagsArray = (explode(",",$request['tagsList']));
		$tagsArrayCount = count($tagsArray);
		console(LOG_LEVEL_TRACE, "Tags Count ::".$tagsArrayCount );
		for($i=0; $i<$tagsArrayCount; $i++){
			$ans = trim($tagsArray[$i]);  
			if($ans != ""){
				if($i == 0){ $values = "('".$id."','".$ans."')"; }
				else{$values .= ",('".$id."','".$ans."')"; }
			}
		}
		if($values != ""){
			$db ['master']->query("INSERT INTO topic_tags (topic_id,tag_name) VALUES ".$values."");
		}else{
			console(LOG_LEVEL_TRACE, "Tag Name Values are Null" );	
		}
		if($db ['master']->affectedRows()>0){
			$message = "Topic Inserted Successfully..."; 
			console(LOG_LEVEL_TRACE, "success message::".$message);
		}
		else{
			$message = "Error in Inserting Topic...";
			console(LOG_LEVEL_TRACE, "error message::".$message);
		}
	}

	/* Add topics End */
	
	// make values in quesvideos table insert new topic values and get new pagebeloongsto or qvid value
	
	$_SESSION['topicid'] 	= $newtopicid;
	
	console(LOG_LEVEL_TRACE, "new topic id::".$newtopicid);
	
	// Get existing qvid value using existing topicid
	
	
	$query 		 	  = "SELECT * FROM quesvideos  WHERE topicid='".$existing_topicid."' AND status='active'";
	$qvidvalues		  = $db['master']->getOneRow($query);
	$exist_qvid		  = $qvidvalues['qvid'];
	console(LOG_LEVEL_TRACE, "old pagebelongsto-->".$exist_qvid." :: old topic id ".$existing_topicid."::new pagebelongsto-->".$new_qvid);
	
	$mapquery = "SELECT * FROM map_topic WHERE new_qid='".$exist_qvid."' AND `status`='active'";
	$mapqvidvalues		  = $db['master']->getOneRow($mapquery);
	if($mapqvidvalues['old_qid']!='') {
		
		$exist_qvid		  = $mapqvidvalues['old_qid'];
		$existing_topicid = $mapqvidvalues['old_topicid'];
		console(LOG_LEVEL_TRACE, "After Mapping check => old pagebelongsto-->".$exist_qvid." :: old topic id ".$existing_topicid."::new pagebelongsto-->".$new_qvid);
	}
	
	
	$addquestionvideo 		= $db['master']->query("INSERT INTO quesvideos(`vqid`,`langid`,`uid`,`topicid`,`sid`,`cid`,`univid`,`semid`,`branch_id`,type,clone_topicid) VALUES('1','1','".$_SESSION['uid']."','".$_SESSION['topicid']."','".$_SESSION['sid']."','".$_SESSION['cid']."','".$_SESSION['unid']."','".$_SESSION['semid']."','".$_SESSION['branchid']."','clone','".$existing_topicid."')");
	$new_qvid 				= $db['master']->getLastID();
	
	
	
	console(LOG_LEVEL_TRACE, "old pagebelongsto-->".$exist_qvid."::new pagebelongsto-->".$new_qvid);
	
	
	$db['master']->query("INSERT INTO `map_topic`(`old_qid`,`new_qid`,`old_topicid`,`new_topicid`) VALUES ('".$exist_qvid."','".$new_qvid."','".$existing_topicid."','".$newtopicid."')");
	
	return true;

}

public function linktopics(){
// this function used to link the new topics to existing topic
global $db,$request;

	$newoptic 		= $request['topic'];
	$searchtopic 	= explode("-", $request['searchtopic']);
	$Existingtopic  = $searchtopic[1];
	// Get values of existing topic id using search topic value
	$existing_topicid = $request['linktopicid'];
	
	if($existing_topicid == ""){
		console(LOG_LEVEL_TRACE, "Link Topic id is Empty");
		return 'failed'; //break;
	}
	console(LOG_LEVEL_TRACE, "newoptic::".$newoptic.'old topic-->'.$Existingtopic.'old topic id-->'.$existing_topicid);

	/* Add topics Start */


	$topic = trim ( $request['topic'] );
	$query = "SELECT topicid FROM topics  WHERE topic_name='".$topic."'  AND uid = '".$_SESSION['uid']."' AND sid = '".$_SESSION['sid']."' AND `status`='active'";
	$res = $db['master']->getOneRow($query);
	
	$already_exist = 0;
	
	
	if($res['topicid'] != ''){
		$message = "Topics Already Exist...";
		
		console(LOG_LEVEL_TRACE, "alert message already exist::".$message);
		$already_exist = 1;
	}else{
		$insq = "INSERT INTO topics(`topic_name`,`uid`,`sid`) VALUES('".$topic."','".$_SESSION['uid']."','".$_SESSION['sid']."')";
		$result = $db['master']->query($insq);
		
		$id	= $db['master']->getLastID();
		$newtopicid = $id;
		
		$_SESSION['topicid'] 	= $id;
		$_SESSION['topic_name'] = $request['topic'];
		
		$tagsArray = (explode(",",$request['tagsList']));
		$tagsArrayCount = count($tagsArray);
		console(LOG_LEVEL_TRACE, "Tags Count ::".$tagsArrayCount );
		for($i=0; $i<$tagsArrayCount; $i++){
			$ans = trim($tagsArray[$i]);  
			if($ans != ""){
				if($i == 0){ $values = "('".$id."','".$ans."')"; }
				else{$values .= ",('".$id."','".$ans."')"; }
			}
		}
		if($values != ""){
			$db ['master']->query("INSERT INTO topic_tags (topic_id,tag_name) VALUES ".$values."");
		}else{
			console(LOG_LEVEL_TRACE, "Tag Name Values are Null" );	
		}
		if($db ['master']->affectedRows()>0){
			$message = "Topic Inserted Successfully..."; 
			console(LOG_LEVEL_TRACE, "success message::".$message);
		}
		else{
			$message = "Error in Inserting Topic...";
			console(LOG_LEVEL_TRACE, "error message::".$message);
		}
	}

	/* Add topics End */
	
if($newtopicid == ""){
		console(LOG_LEVEL_TRACE, "Topic Not Created");
		return 'failed'; //break;
	}else{
	
	// make values in quesvideos table insert new topic values and get new pagebeloongsto or qvid value
	
	$_SESSION['topicid'] 	= $newtopicid;
	
	console(LOG_LEVEL_TRACE, "new topic id::".$newtopicid);
	
	$addquestionvideo 		= $db['master']->query("INSERT INTO quesvideos(`vqid`,`langid`,`uid`,`topicid`,`sid`,`cid`,univid,semid,`branch_id`,type,clone_topicid) VALUES('1','1','".$_SESSION['uid']."','".$_SESSION['topicid']."','".$_SESSION['sid']."','".$_SESSION['cid']."','".$_SESSION['unid']."','".$_SESSION['semid']."','".$_SESSION['branchid']."','clone','".$existing_topicid."')");
	$new_qvid 				= $db['master']->getLastID();
	
	// Get existing qvid value using existing topicid
	
	$query 		 	  = "SELECT * FROM quesvideos  WHERE topicid='".$existing_topicid."' AND status='active'";
	$qvidvalues		  = $db['master']->getOneRow($query);
	$exist_qvid		  = $qvidvalues['qvid'];
	
	console(LOG_LEVEL_TRACE, "old pagebelongsto-->".$exist_qvid."::new pagebelongsto-->".$new_qvid);
	
	// Get All templates values of existing qvid
	
	$ques_query 		 	= "SELECT * FROM questions  WHERE pagebelongsto='".$exist_qvid."' AND status='active'";
	$ques_values		  	= $db['master']->getResults($ques_query);
	
	foreach($ques_values as $values){
	
	$newqid = '';
	$value_qvtype = $values['qvtype'];	
	switch($values['qvtype']){	
	case 'question':
	
	// make value in question table
	$insq = '';
	$insq = "INSERT INTO questions (question, optanswer, qvtype,pagebelongsto,aid,orderid) SELECT question, optanswer,qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	

	
	// make value in choose_the_best_answer table ie.. option objective values 
	$insq_choose = '';
	
	//$insq_choose = "INSERT INTO choose_the_best_answer (qid, objective, pagebelongsto) SELECT  '".$newqid."', objective, '".$new_qvid."'  FROM choose_the_best_answer 	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	
	$insq_choose = "INSERT INTO choose_the_best_answer (qid, objective, pagebelongsto) SELECT  '".$newqid."', objective, '".$new_qvid."'  FROM choose_the_best_answer WHERE  qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq_choose);
	
			// make values in language_audios table
	$insq_audio = '';
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','question'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	
	if(($values['temp_name'] == 'singleimg') || ($values['temp_name'] == 'doubleimg') || ($values['temp_name'] == 'threeimg') || ($values['temp_name'] == 'fourimg')){
		$insqry = "INSERT INTO question_details (qid, pagebelongsto, image1,image2,image3,image4) SELECT '".$newqid."', '".$new_qvid."',image1,image2,image3,image4   FROM question_details
		WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
		$resltqry = $db['master']->query($insqry);
	}else if($values['temp_name'] == 'passage'){
		$insqry = "INSERT INTO question_details (qid, pagebelongsto,passage) SELECT '".$newqid."', '".$new_qvid."',passage   FROM question_details
		WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
		$resltqry = $db['master']->query($insqry);
	}else if($values['temp_name'] == 'imgpassage'){
		$insqry = "INSERT INTO question_details (qid, pagebelongsto,passage,image1) SELECT '".$newqid."', '".$new_qvid."',passage,image1   FROM question_details
		WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
		$resltqry = $db['master']->query($insqry);
	}
	
	break;
	case 'true_false_template':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, optanswer, qvtype,pagebelongsto,aid,orderid) SELECT question, optanswer,qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	// make value in true_false_template table ie.. option objective values 
	
	$insq_truefalse = "INSERT INTO true_false_template (question,answer,pagebelongsto,qid) SELECT  question,answer,'".$new_qvid."','".$newqid."'  FROM true_false_template
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	
	$result_truefalse = $db['master']->query($insq_truefalse);	
	
		// make values in language_audios table
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','true_false_template'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	
	
	break;
	case 'video':
	
	// make value in question table
	$insq_video = "INSERT INTO questions (videopath,vname,vsize,vtype,qvtype,pagebelongsto,aid,streamvideo,orderid) SELECT videopath, vname,vsize,vtype,qvtype, '".$new_qvid."',aid,streamvideo,orderid FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result_video = $db['master']->query($insq_video);
	
	$newqid		  = $db['master']->getLastID();
	
	// make values in language_audios table
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','video'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq_audio);		
	break;	
	case 'template1':
	case 'template2':
	case 'template3':
	case 'template4':	
	$exist_hid = '';
	$exist_hid = $values['hid'];
	
	// make values in header table
	
	//$insq_header = "INSERT INTO header (template_type,imgname,txt_aname,txt_asize,img_aname,img_asize,header_animation) SELECT  template_type,imgname,txt_aname,txt_asize,img_aname,img_asize,header_animation FROM header 	WHERE hid='".$exist_hid."'";
	$insq_header = "INSERT INTO header (`htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type`) SELECT `htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type` FROM header 	WHERE hid='".$exist_hid."' AND `status`='active'";
	
	$insq_header_result 	= $db['master']->query($insq_header);	
	$new_hid				= $db['master']->getLastID();
	
	
	
	// make value in question table
	$insq_template = "INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) SELECT qvtype,'".$new_qvid."',aid,'".$new_hid."',temp_name,orderid FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result_template = $db['master']->query($insq_template);
	
	$newqid		  	 = $db['master']->getLastID();
	
	
	// make values in bulletin_content table

	$insq_bulletin = "INSERT INTO bulletin_content (hid,opt_sno,txt_value,aname,asize,tp_align,txt_animation) SELECT '".$new_hid."',opt_sno,txt_value,aname,asize,tp_align,txt_animation FROM bulletin_content
	WHERE hid='".$exist_hid."'";
	
	$result_bulletin = $db['master']->query($insq_bulletin);
	
	
	// make values in language_audios table
	
	$insq_audio_temp = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','".$values['qvtype']."'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";	
	$result_temp = $db['master']->query($insq_audio_temp);		
	break;
	
	case 'imagecontent':
	case 'multiple_block':
	case 'left_right_temp':
	case 'animation':
	
	
	$exist_hid = $new_hid = $newqid = '';
	$exist_hid = $values['hid'];
	
	// make values in header table
	
	//$insq_header = "INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) SELECT template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type FROM header 	WHERE hid='".$exist_hid."'";
	
		$insq_header = "INSERT INTO header (`htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type`) SELECT `htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type` FROM header 	WHERE hid='".$exist_hid."' AND `status`='active'";
	
	$insq_header_result 	= $db['master']->query($insq_header);	
	$new_hid				= $db['master']->getLastID();
	
	
	if($values['qvtype']=='imagecontent' || $values['qvtype']=='animation'){
	
	$header_lang_audio = "SELECT * from language_audios WHERE hid='".$exist_hid."' AND status='active'";
	$lang_audio_header = $db['master']->getOneRow($header_lang_audio);
	
	
	// make values in language_audios table 
	
	$insq_audio_header = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype,hid) VALUES('".$newqid."', '".$lang_audio_header['audiopath']."','".$lang_audio_header['langid']."','".$lang_audio_header['aname']."','".$lang_audio_header['asize']."','".$lang_audio_header['atype']."','".$new_qvid."','".$values['qvtype']."','".$new_hid."')";	
	$result_temph = $db['master']->query($insq_audio_header);	
	
	}
	
	
	
	// make value in question table
	$insq_template = "INSERT INTO questions (qvtype,pagebelongsto,aid,hid,temp_name,orderid) SELECT qvtype,'".$new_qvid."',aid,'".$new_hid."',temp_name,orderid FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result_template = $db['master']->query($insq_template);
	
	$newqid		  	 = $db['master']->getLastID();
	
	
	// make values in bulletin_content table
	if($values['qvtype']!='animation'){
		$select_bulletin = "SELECT * from bulletin_content WHERE hid='".$exist_hid."'";
		$bulletin_values = $db['master']->getResults($select_bulletin);
		
		
		foreach($bulletin_values as $bulletins){

		$insq_bulletin = "INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_animation,txt_level,bulletin_label,bulletin_label_animation,tp_align) VALUES( '".$new_hid."','".$bulletins['opt_sno']."','".mysql_real_escape_string($bulletins['txt_value'])."','".$bulletins['txt_animation']."','".$bulletins['txt_level']."','".mysql_real_escape_string($bulletins['bulletin_label'])."','".$bulletins['bulletin_label_animation']."','".$bulletins['tp_align']."')";
		
		
		$result_bulletin = $db['master']->query($insq_bulletin);
		$newbid 		 = '';	
		$newbid		  	 = $db['master']->getLastID();
		
		$select_lang_audio = "SELECT * from language_audios WHERE bid='".$bulletins['bid']."'";
		$lang_audio_values = $db['master']->getOneRow($select_lang_audio);
		
		
		// make values in language_audios table
		
		$insq_audio_temp = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$newqid."', '".$lang_audio_values['audiopath']."','".$lang_audio_values['langid']."','".$lang_audio_values['aname']."','".$lang_audio_values['asize']."','".$lang_audio_values['atype']."','".$new_qvid."','".$values['qvtype']."','".$new_hid."','".$newbid."')";	
		$result_temp = $db['master']->query($insq_audio_temp);	
		}
	}
	break;
	case 'Image_Template':
		$exist_hid = $new_hid = $newqid = '';
		$exist_hid = $values['hid'];
		
		$insq_header = "INSERT INTO header (`htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type`) SELECT `htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type` FROM header 	WHERE hid='".$exist_hid."' AND `status`='active'";
		
		//$insq_header = "INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) SELECT template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type FROM header 		WHERE hid='".$exist_hid."'";
		
		$insq_header_result 	= $db['master']->query($insq_header);	
		$new_hid				= $db['master']->getLastID();

		// make value in question table
		$insq_template = "INSERT INTO questions (question,qvtype,pagebelongsto,aid,hid,temp_name,orderid) SELECT question,qvtype,'".$new_qvid."',aid,'".$new_hid."',temp_name,orderid FROM questions
		WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
		$result_template = $db['master']->query($insq_template);
	
		$newqid		  	 = $db['master']->getLastID();
	
		$img_media = "SELECT * FROM img_temp_media WHERE hid='".$exist_hid."' AND qid='".$values['qid']."'";
		$result_imgmedia = $db['master']->getResults($img_media);
		foreach($result_imgmedia as $media){
			$insq_medias = "INSERT INTO img_temp_media(hid,qid,label,media_type,media_name) VALUES( '".$new_hid."','".$newqid."','".$media['label']."','".$media['media_type']."','".$media['media_name']."')";
			$reslt = $db['master']->query($insq_medias);
			$newmid 		 = '';
			$newmid = $db['master']->getLastID();
			
			$media_lang = $db['master']->getOneRow("SELECT * FROM language_audios WHERE mid='".$media['mid']."' AND hid='".$exist_hid."' AND qid='".$values['qid']."' AND status='active'");
			
			$insq_audio_temp_media = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype,hid,mid) VALUES('".$newqid."', '".$media_lang['audiopath']."','".$media_lang['langid']."','".$media_lang['aname']."','".$media_lang['asize']."','".$media_lang['atype']."','".$new_qvid."','".$values['qvtype']."','".$new_hid."','".$newmid."')";	
			$result_temp = $db['master']->query($insq_audio_temp_media);	
		}
	
		$bulletin_content = $db['master']->getResults("SELECT * FROM bulletin_content WHERE hid='".$exist_hid."' AND status='active'");
		
		foreach($bulletin_content as $cont){
			$insq_bulletin = "INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_animation,txt_level,bulletin_label,bulletin_label_animation,tp_align) VALUES( '".$new_hid."','".$cont['opt_sno']."','".mysql_real_escape_string($cont['txt_value'])."','".$cont['txt_animation']."','".$cont['txt_level']."','".mysql_real_escape_string($cont['bulletin_label'])."','".$cont['bulletin_label_animation']."','".$cont['tp_align']."')";
		
		
			$result_bulletin = $db['master']->query($insq_bulletin);
			$newbid 		 = '';	
			$newbid		  	 = $db['master']->getLastID();
			
			$select_lang_audio = "SELECT * from language_audios WHERE bid='".$cont['bid']."' AND hid='".$exist_hid."' AND status='active'";
			$lang_audio_values = $db['master']->getOneRow($select_lang_audio);
			
			
			// make values in language_audios table
			
			$insq_audio_temp = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$newqid."', '".$lang_audio_values['audiopath']."','".$lang_audio_values['langid']."','".$lang_audio_values['aname']."','".$lang_audio_values['asize']."','".$lang_audio_values['atype']."','".$new_qvid."','".$values['qvtype']."','".$new_hid."','".$newbid."')";	
			$result_temp = $db['master']->query($insq_audio_temp);	
		}
		
	break;
	
	
	case 'text_template':
	
	
	$exist_hid = $new_hid = $newqid = '';
	$exist_hid = $values['hid'];
	
	// make values in header table
	
	//$insq_header = "INSERT INTO header (template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type) SELECT template_type,txt_aname,txt_asize,header_animation,subjecttxt,video_image_name,video_image_size,video_image_type FROM header WHERE hid='".$exist_hid."'";
	
	$insq_header = "INSERT INTO header (`htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type`) SELECT `htext`,`template_type`,`imgname`,`txt_aname`,`txt_asize`,`img_aname`,`img_asize`,`status`,`header_animation`,`subjecttxt`,`video_image_name`,`video_image_size`,`video_image_type` FROM header 	WHERE hid='".$exist_hid."' AND `status`='active'";
	
	$insq_header_result 	= $db['master']->query($insq_header);	
	$new_hid				= $db['master']->getLastID();

	// make value in question table
	$insq_template = "INSERT INTO questions (qvtype,pagebelongsto,aid,hid,orderid) SELECT qvtype,'".$new_qvid."',aid,'".$new_hid."',orderid FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result_template = $db['master']->query($insq_template);
	
	$newqid		  	 = $db['master']->getLastID();
	
	
	// make values in bulletin_content table
		$select_bulletin = "SELECT * from bulletin_content WHERE hid='".$exist_hid."'";
		$bulletin_values = $db['master']->getResults($select_bulletin);
		
		
		foreach($bulletin_values as $bulletins){

		$insq_bulletin = "INSERT INTO bulletin_content (hid,opt_sno,txt_value,txt_animation,txt_level,bulletin_label,bulletin_label_animation,tp_align) VALUES( '".$new_hid."','".$bulletins['opt_sno']."','".mysql_real_escape_string($bulletins['txt_value'])."','".$bulletins['txt_animation']."','".$bulletins['txt_level']."','".mysql_real_escape_string($bulletins['bulletin_label'])."','".$bulletins['bulletin_label_animation']."','".$bulletins['tp_align']."')";
		
		
		$result_bulletin = $db['master']->query($insq_bulletin);
		$newbid 		 = '';	
		$newbid		  	 = $db['master']->getLastID();
		
		$select_lang_audio = "SELECT * from language_audios WHERE bid='".$bulletins['bid']."'";
		$lang_audio_values = $db['master']->getOneRow($select_lang_audio);
		
		
		// make values in language_audios table
		
		$insq_audio_temp = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype,hid,bid) VALUES('".$newqid."', '".$lang_audio_values['audiopath']."','".$lang_audio_values['langid']."','".$lang_audio_values['aname']."','".$lang_audio_values['asize']."','".$lang_audio_values['atype']."','".$new_qvid."','".$values['qvtype']."','".$new_hid."','".$newbid."')";	
		$result_temp = $db['master']->query($insq_audio_temp);	
	}
	
	break;
	
	case 'evaltemp':
	
	
	// make value in question table
	$insq_template = "INSERT INTO questions (question,qvtype,pagebelongsto,aid,orderid) SELECT question,qvtype,'".$new_qvid."',aid,orderid FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result_template = $db['master']->query($insq_template);
	
	$newqid		  	 = $db['master']->getLastID();
	
	$insq_audio = '';
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."',qtype  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	break;
	
	case 'fib':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, qvtype,pagebelongsto,aid,orderid) SELECT question, qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	// make value in fill_in_the_blank_answer table ie.. answer ,qid values 
	
	$insqs = "INSERT INTO fill_in_the_blank_answer (qid, answer) SELECT  '".$newqid."', answer  FROM fill_in_the_blank_answer WHERE  qid='".$values['qid']."'";
	
	$result = $db['master']->query($insqs);
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','fib'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	

	break;
	
	case 'dragDropText':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, qvtype,pagebelongsto,aid,orderid) SELECT question, qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	// make value in fill_in_the_blank_answer table ie.. answer ,qid values 
	
	$insq = "INSERT INTO fill_in_the_blank_answer (qid, answer) SELECT  '".$newqid."', answer  FROM fill_in_the_blank_answer WHERE  qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','dragDropText'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	

	break;
	
	case 'dropdown':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, qvtype,pagebelongsto,aid,orderid) SELECT question, qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	// make value in fill_in_the_blank_answer table ie.. answer ,obj1,obj2 values 
	
	$insq = "INSERT INTO fill_in_the_blank_answer (qid,obj1,obj2,obj3,answer) SELECT  '".$newqid."',obj1,obj2,obj3,answer  FROM fill_in_the_blank_answer WHERE  qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','dropdown'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	

	break;
	
	case 'matching':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, qvtype,pagebelongsto,aid,orderid) SELECT question, qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	// make value in match_the_following table ie.. answer ,qid values 
	
	$insq = "INSERT INTO match_the_following (qid,question,answer) SELECT  '".$newqid."',question,answer  FROM match_the_following WHERE  qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','matching'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	

	break;
	
	case 'chooseTheBestImg':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, obj1,obj2,obj3,obj4,optanswer, qvtype,pagebelongsto,aid,orderid) SELECT question,obj1,obj2,obj3,obj4,optanswer,qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','chooseTheBestImg'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	
	break;
	
	case 'imageTab':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, optanswer, qvtype,pagebelongsto,aid,orderid) SELECT question, optanswer,qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	// make value in image_tab table ie.. video_title thumbnail_url values 
	
	$insq = "INSERT INTO image_tab (qid,video_title,thumbnail_url,video_url) SELECT  '".$newqid."', video_title,thumbnail_url,video_url  FROM image_tab WHERE qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','imageTab'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);
	

	break;
	
	case 'dragdrop':
	
	// make value in question table
	$insq = "INSERT INTO questions (question, qvtype,pagebelongsto,aid,orderid) SELECT question, qvtype, '".$new_qvid."',aid,orderid  FROM questions
	WHERE pagebelongsto = '".$exist_qvid."' and qid='".$values['qid']."'";
	
	$result = $db['master']->query($insq);
	
	$newqid	= $db['master']->getLastID();
	
	
	$res = $db['master']->getResults("SELECT * FROM dd_sec_headings WHERE qid='".$values['qid']."' AND status='active'");
	
	foreach($res as $key){ 
	
		$db ['master']->query("INSERT INTO dd_sec_headings (qid,section_name) VALUES ('".$newqid."','".$key['section_name']."')");
		$secId	= $db['master']->getLastID();
		$res1 = $db['master']->getResults("SELECT * FROM dd_answers WHERE qid='".$values['qid']."' AND section_id = '".$key['shid']."' AND status='active'");
		foreach($res1 as $value){ 
		$db ['master']->query("INSERT INTO dd_answers (qid,image_path,section_id) VALUES ('".$newqid."','".$value['image_path']."','".$secId."')");
		}
	}
	
	$insq_audio = "INSERT INTO language_audios (qid, audiopath, langid,aname,asize,atype,pagebelongsto,qtype) SELECT  '".$newqid."', audiopath,langid,aname,asize,atype,'".$new_qvid."','dragdrop'  FROM language_audios
	WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$values['qid']."'";
	$result = $db['master']->query($insq_audio);	
	break;	
	
	}	
	//$exists_qid = $values['qid'];
	
	if($newqid!=''){
	$insq_clone = "INSERT INTO cloned_data(old_qid,new_qid,newpagebelongsto) VALUES('".$values['qid']."','".$newqid."','".$new_qvid."')";
	$result = $db['master']->query($insq_clone);
	}
	console(LOG_LEVEL_TRACE, "old qid::".$values['qid']."new qid->".$newqid);
}
}

$tab_exists         = $db['master']->getResults("SELECT * FROM questions  WHERE pagebelongsto='".$exist_qvid."' AND qvtype='tabs' AND status='active'");
if($tab_exists){
	foreach($tab_exists as $val){
                $this->CloneTabs($exist_qvid,$new_qvid,$val["qid"],$val["aid"]); 
	}
}

}

public function CloneTabs($exist_qvid,$new_qvid,$exist_qid,$aid){
                global $db,$request;
                $arrLinkData = array();
                $arrclonedata = array();
                
                // Getting New qid
                $insq = "INSERT INTO questions (question, qvtype,pagebelongsto,aid) SELECT question,qvtype, '".$new_qvid."',aid  FROM questions
                WHERE pagebelongsto = '".$exist_qvid."' AND qid='".$exist_qid."'";
                $result = $db['master']->query($insq);
                
                $newqid              = $db['master']->getLastID();
                
				$existingQid = array();
                //  Getting Linking qid Value using pagebelongsto id
                $linkid = $db['master']->getResults("SELECT qid,maintabid,subtabid,pagebelongsto FROM link_questions_to_tabs WHERE pagebelongsto='".$exist_qvid."'  AND `status`='active' ");
                foreach($linkid as $key=>$val){
                   $arrLinkData[$val['maintabid']][$val['subtabid']][] = $val['qid'];
				   console(LOG_LEVEL_TRACE, "Condition 1 :: LINK ID  :: ".$val['qid'] );
                } 
				
                 $linkids = $db['master']->getResults("SELECT qid FROM questions WHERE pagebelongsto='".$new_qvid."'");
				 foreach($linkids as $key=>$val){
					$existingQid[] = $val['qid'];
					console(LOG_LEVEL_TRACE, "Condition 2 :: Existing QID   :: ".$val['qid'] );
                 } 				
			
                //   Value of cloned qid for the existing qid
                $clonedid = $db['master']->getResults("SELECT old_qid,new_qid,newpagebelongsto FROM cloned_data WHERE newpagebelongsto='".$new_qvid."' and new_qid in (".implode(",",$existingQid).")");
                //$clonedid = $db['master']->getResults("SELECT old_qid,new_qid,newpagebelongsto FROM cloned_data WHERE newpagebelongsto='164'");
                foreach($clonedid as $key=>$cloneval){
                   $arrclonedata[$cloneval['old_qid']]=$cloneval['new_qid'];
				   console(LOG_LEVEL_TRACE, "Condition 3 :: Cloned New QID   :: ".$cloneval['new_qid'] );
                }
               
   //   existing MainTab
   $exist_tabsval = $db['master']->getResults("SELECT  tabid,tabheader,main_content,qid,reftabid,linetype  FROM tabs WHERE  qid='".$exist_qid."' AND reftabid='0' AND `status`='active' ");

   foreach($exist_tabsval as $key=>$exist_tab){
      $insq_tabs = "INSERT INTO tabs (tabheader,main_content,qid,reftabid,linetype) VALUES('".mysql_escape_string($exist_tab['tabheader'])."','".mysql_escape_string($exist_tab['main_content'])."','".$newqid."','".$exist_tab['reftabid']."','".$exist_tab['linetype']."')";
      $result_tabs = $db['master']->query($insq_tabs);
      $newreftabid = $db['master']->getLastID();
	  console(LOG_LEVEL_TRACE, "Condition 4 ::  New Tab ID   ::  ".$newreftabid );
      $updq = $db['master']->query("UPDATE questions SET tabid='".$newreftabid."' WHERE pagebelongsto = '".$new_qvid."' AND qid='".$newqid."'");
	  //          existing SubTab
      $subtabs = $db['master']->getResults("SELECT tabid,subcontent,linetype FROM tabs WHERE qid='".$exist_qid."' AND reftabid='".$exist_tab['tabid']."'");
                
	  $sublinkcount = count($subtabs);
	  console(LOG_LEVEL_TRACE, "Condition 5 ::  Sub Tab Count   ::  ".$sublinkcount );
	  $arrMainTabarr = array();
	  $arrMainTabarr = $arrLinkData[$exist_tab['tabid']][$exist_tab['tabid']];
	  console(LOG_LEVEL_TRACE, "Condition 6 ::  arrMainTabarr Count   ::  ".count($arrMainTabarr) );
	  if(is_array($arrLinkData) && count($arrMainTabarr)>0){
		  console(LOG_LEVEL_TRACE, "Condition 7 ::  IF Condition 1st  ::  ");
		  foreach($arrMainTabarr as $mainarr) {
			  console(LOG_LEVEL_TRACE, "Condition 8 ::  IF Condition 2nd  ::  ");
			  $old_qid = $mainarr; 
			  $new_qid = $arrclonedata[$old_qid];
			  if($new_qid != ""){
				  console(LOG_LEVEL_TRACE, "Condition 9 ::  New QID  ::  ".$new_qid);
				  $insq_linktab = "INSERT INTO link_questions_to_tabs(qid,maintabid,subtabid,pagebelongsto,orderid) VALUES('".$new_qid."','".$newreftabid."','".$newreftabid."','".$new_qvid."','".$aid."')";
				  $result_cloned = $db['master']->query($insq_linktab);
		 	  }
          }
		  if($sublinkcount>0) {
				console(LOG_LEVEL_TRACE, "Condition 10 ::  ELSE IF Condition ::  1st ");
				foreach($subtabs as $key){ 
					console(LOG_LEVEL_TRACE, "Condition 11 ::  ELSE IF Condition ::  2nd ");
                    $insq_subtab = "INSERT INTO tabs(subcontent,qid,reftabid,linetype) VALUES('".mysql_escape_string($key['subcontent'])."','".$newqid."','".$newreftabid."','".$key['linetype']."')";
                    $result_subtab = $db['master']->query($insq_subtab);
                    $subtabid = $db['master']->getLastID();  console(LOG_LEVEL_TRACE, " Inserted Sub tab ID :: ". $subtabid);
				    $mainsublinkcount =0;
					$mainsublinkcount = count($arrLinkData[$exist_tab['tabid']][$key['tabid']]);
                    if(is_array($arrLinkData) && $mainsublinkcount>0){
						console(LOG_LEVEL_TRACE, "Condition 12 ::  Main Sub Link Count ::   ".$mainsublinkcount);
                        //if(is_array($arrLinkData) && $arrLinkData[$exist_tab['tabid']][$key['tabid']]!=''){
                        // echo "test::";
                        foreach($arrLinkData[$exist_tab['tabid']][$key['tabid']] as $mtabval){
							 console(LOG_LEVEL_TRACE, "Condition 13 ::  Foreach  ELSE IF ::   ");
							if($mtabval!=''){
								 console(LOG_LEVEL_TRACE, "Condition 14 ::  mtabval NOT NULL  ::   ".$mtabval);
                              // echo "okok";
                              $old_qid = $mtabval; 
							  console(LOG_LEVEL_TRACE, " old_qid from arrLinkData array :: ". $old_qid);
                              $new_qid = $arrclonedata[$old_qid];  console(LOG_LEVEL_TRACE, " new_qid from arrclonedata array :: ". $new_qid);
                              if($new_qid != ""){
								console(LOG_LEVEL_TRACE, "Condition 15 ::  new_qid NOT NULL  ::   ".$new_qid);
								$insq_linktab = "INSERT INTO link_questions_to_tabs(qid,maintabid,subtabid,pagebelongsto,orderid) VALUES('".$new_qid."','".$newreftabid."','".$subtabid."','".$new_qvid."','".$aid."')";
								$result_cloned = $db['master']->query($insq_linktab);
                               }
                            }
						}
                    }					 
			   }
		  }
	 }
	 else if($sublinkcount>0) {
		console(LOG_LEVEL_TRACE, "Condition 10 ::  ELSE IF Condition ::  1st ");
		foreach($subtabs as $key){ 
			console(LOG_LEVEL_TRACE, "Condition 11 ::  ELSE IF Condition ::  2nd ");
            $insq_subtab = "INSERT INTO tabs(subcontent,qid,reftabid,linetype) VALUES('".mysql_escape_string($key['subcontent'])."','".$newqid."','".$newreftabid."','".$key['linetype']."')";
            $result_subtab = $db['master']->query($insq_subtab);
            $subtabid = $db['master']->getLastID();  console(LOG_LEVEL_TRACE, " Inserted Sub tab ID :: ". $subtabid);
			$mainsublinkcount =0;
			$mainsublinkcount = count($arrLinkData[$exist_tab['tabid']][$key['tabid']]);
            if(is_array($arrLinkData) && $mainsublinkcount>0){
				console(LOG_LEVEL_TRACE, "Condition 12 ::  Main Sub Link Count ::   ".$mainsublinkcount);
                //if(is_array($arrLinkData) && $arrLinkData[$exist_tab['tabid']][$key['tabid']]!=''){
                // echo "test::";
                foreach($arrLinkData[$exist_tab['tabid']][$key['tabid']] as $mtabval){
					console(LOG_LEVEL_TRACE, "Condition 13 ::  Foreach  ELSE IF ::   ");
					if($mtabval!=''){
						console(LOG_LEVEL_TRACE, "Condition 14 ::  mtabval NOT NULL  ::   ".$mtabval);
                        // echo "okok";
                        $old_qid = $mtabval; 
						console(LOG_LEVEL_TRACE, " old_qid from arrLinkData array :: ". $old_qid);
                        $new_qid = $arrclonedata[$old_qid];  console(LOG_LEVEL_TRACE, " new_qid from arrclonedata array :: ". $new_qid);
                        if($new_qid != ""){
							console(LOG_LEVEL_TRACE, "Condition 15 ::  new_qid NOT NULL  ::   ".$new_qid);
							$insq_linktab = "INSERT INTO link_questions_to_tabs(qid,maintabid,subtabid,pagebelongsto,orderid) VALUES('".$new_qid."','".$newreftabid."','".$subtabid."','".$new_qvid."','".$aid."')";
							$result_cloned = $db['master']->query($insq_linktab);
                        }
                     }
				  }
              }                                               
          }
	  }
				//exit;				
            }
}


public function getAnimationEffects($effect=''){
/* this function used to get all keywords from keyword table table */
	global $db,$request;	
	
	$effects_array = array('Right to Left'=>'fadeInLeft','Left to Right'=>'fadeInRight','Top to Bottom'=>'fadeInDown','Bottom to Top'=>'fadeInUp','Flash'=>'flash','ZoomIn'=>'zoomIn','ZoomOut'=>'zoomOut');
	
	$effects .= '<option value="">Choose the Text Animation</option>';
	
	foreach ($effects_array as $key=>$value ){					
			if ($value == $effect){
			$effects .= '<option value="' . $value. '" selected>' . $key .'</option>';
			}
			else{
			$effects .= '<option value="' . $value. '" >' . $key.'</option>';					
			}
	}

	return $effects;
}

	public function getVideoThumbnail($qid){
		global $db,$request;
		if(empty($qid)){
			return '';
		}
		$query = "SELECT vname FROM questions WHERE qvtype = 'video' AND `status` = 'active' AND pagebelongsto = '".$qid."' ORDER BY qid DESC LIMIT 0,1";
		$thumbnail = $db['master']->getOneRow($query);
		if($thumbnail['vname'] != ''){
			$filename = pathinfo($thumbnail['vname'], PATHINFO_FILENAME);
			//$thumbnailPath = 'storage/upload/useruploads/thumb/'.$filename.'.jpeg';
			$thumbnailPath = $filename.'.png';
		}else{
			//$thumbnailPath = 'storage/upload/useruploads/thumb/default.jpeg';
			$thumbnailPath = $filename.'.png';
		}
		return $thumbnailPath;
	}
	
	
	public function getTopicName($pagebelongsto){
		global $db;
		$query = "SELECT t.topicid,t.topic_name FROM topics AS t,quesvideos AS q WHERE q.topicid=t.topicid AND q.qvid='".$pagebelongsto."'";
		$topicname = $db['master']->getOneRow($query);
		return $topicname["topic_name"];
	}
	public function getUserList(){
		global $db;
		$query = "SELECT * FROM appusers WHERE user_type = 'mtutor' AND status = 'active' ";
		$userList = $db['master']->getResults($query);
		return $userList;
	}
	public function assignTopic(){
		global $request,$db;


		$uid = $request['uid'];
		$user = $request['user'];
		$topicOpt = $request['topicOpt'];
		$topicids =  $request['topicids'];

		$qry =  "update map_user_topic set status = 'inactive'  where topicid IN (".$topicids.") AND iduser = ".$user." AND status='active'";
		console(LOG_LEVEL_TRACE, "Update Qry". $qry);
		$updateTopic = $db['master']->query($qry);
		
		$insQry = "INSERT INTO map_user_topic (iduser,topicid,status) VALUES ";
		$insConCatQry = '';
		foreach($topicOpt as $key){
			if($insConCatQry == ''){
				$insConCatQry = "('".$user."','".$key."','active')";
			}else{
				$insConCatQry .= ",('".$user."','".$key."','active')";
			}
		}
		$qry = $insQry.$insConCatQry;
		console(LOG_LEVEL_TRACE, "Insert Qry". $qry);
		$result = $db['master']->query($qry);
		return $lastid = $db['master']->getLastID();
	}
	public function getAssignedTopic(){
		global $request,$db;
		$query = "SELECT GROUP_CONCAT(topicid) as topicids FROM map_user_topic WHERE iduser = ".$request['userid']." AND status = 'active' GROUP BY iduser ";
		$topicList = $db['master']->getOneRow($query);
		if($topicList['topicids'] == ''){
			$topicList['topicids'] = 'No topic found';
		}
		return $topicList['topicids'];
	}
	public function getMainTabCount($mainTabId){
		global $db,$request;
		$query = "SELECT COUNT(*) maintabs FROM tabs WHERE qid =".$mainTabId." AND reftabid = 0";
		$result = $db['master']->getOneRow($query);
		return $result['maintabs'];
	}
	public function getAllVideoCount($qid){
		global $db, $request;
		$questionQuery = "SELECT COUNT(*) AS video_count FROM questions WHERE STATUS='active' AND pagebelongsto = ".$qid." AND qvtype = 'video' "; 
		$questionsResult = $db['master']->getOneRow($questionQuery);
		
		$imgTabQuery = "SELECT COUNT(*) AS video_count  FROM image_tab WHERE STATUS='active' AND qid IN (SELECT qid FROM questions WHERE pagebelongsto = ".$qid." AND qvtype = 'imageTab') ";
		$imgTabResult = $db['master']->getOneRow($imgTabQuery);
		
		$imgTempQuery = "SELECT COUNT(*) AS video_count  FROM img_temp_media WHERE STATUS='active' AND media_type = 'video/mp4' AND qid IN (SELECT qid FROM questions WHERE pagebelongsto = ".$qid." AND qvtype = 'Image_template') ";
		$imgTempResult = $db['master']->getOneRow($imgTempQuery);
		
		$headerQuery = "SELECT COUNT(1) AS video_count  FROM header AS h, questions AS q WHERE h.hid=q.hid AND h.video_image_type = 'video/mp4' AND h.STATUS = 'active' AND q.pagebelongsto = ".$qid." AND q.qvtype = 'imagecontent'";
		$headerResult = $db['master']->getOneRow($headerQuery);
		
		$count = 0;
		if(isset($questionsResult['video_count'])){ $count = $questionsResult['video_count']; }
		if(isset($imgTabResult['video_count'])){ $count = $imgTabResult['video_count']+$count; }
		if(isset($imgTempResult['video_count'])){ $count = $imgTempResult['video_count']+$count; }
		if(isset($headerResult['video_count'])){ $count = $headerResult['video_count']+$count; }
		
		return $count;
	}
	public function getAllImageCount($qid){
		global $db, $request;
		$chooseQuery = "SELECT SUM(IF(obj1 != '',1,0) + IF(obj2 != '',1,0) + IF(obj3 != '',1,0) + IF(obj4 != '',1,0)) AS image_count 
								FROM questions WHERE qvtype = 'chooseTheBestImg' AND pagebelongsto = ".$qid." AND status = 'active'"; 
		$chooseResult = $db['master']->getOneRow($chooseQuery);
		
		$ddQuery = "SELECT COUNT(*) AS image_count FROM dd_answers WHERE  status = 'active' AND qid IN 
								(SELECT qid FROM questions WHERE qvtype = 'dragdrop' AND pagebelongsto = ".$qid." AND status = 'active')";
		$ddResult = $db['master']->getOneRow($ddQuery);
		
		$headQuery = "SELECT COUNT(*) AS image_count FROM header AS h 
							JOIN questions AS q ON (h.hid = q.hid) 
							WHERE q.qvtype = 'imagecontent' AND q.pagebelongsto = ".$qid." AND q.STATUS = 'active' AND h.STATUS = 'active' 
							AND h.video_image_type = 'image/jpeg'";
		$headResult = $db['master']->getOneRow($headQuery);
		
		$summaryQuery = "SELECT COUNT(*) AS image_count FROM header AS h 
							JOIN questions AS q ON (h.hid = q.hid) 
							WHERE q.qvtype = 'template4' AND q.pagebelongsto = ".$qid." AND q.STATUS = 'active' AND h.STATUS = 'active'";
		$summaryResult = $db['master']->getOneRow($summaryQuery);
		
		$imageTemplateQuery = "SELECT COUNT(*) AS image_count FROM img_temp_media AS itm 
									JOIN questions AS q ON (itm.hid = q.hid) 
									WHERE q.qvtype = 'Image_Template' AND q.pagebelongsto = ".$qid." AND q.STATUS = 'active' AND itm.STATUS = 'active' 
									AND itm.media_type LIKE '%image%'";
		$imageTemplateResult = $db['master']->getOneRow($imageTemplateQuery);
		
		$imageTabQuery = "SELECT COUNT(*) AS image_count FROM image_tab AS i 
									JOIN questions AS q ON (i.qid = q.qid) 
									WHERE q.qvtype = 'imageTab' AND q.pagebelongsto = ".$qid." AND q.STATUS = 'active' AND i.STATUS = 'active' ";
		$imageTabResult = $db['master']->getOneRow($imageTabQuery);		
		
		$count = 0;
		if(isset($chooseResult['image_count'])){ $count = $chooseResult['image_count']; }
		if(isset($ddResult['image_count'])){ $count = $ddResult['image_count']+$count; }
		if(isset($headResult['image_count'])){ $count = $headResult['image_count']+$count; }
		if(isset($summaryResult['image_count'])){ $count = $summaryResult['image_count']+$count; }
		if(isset($imageTemplateResult['image_count'])){ $count = $imageTemplateResult['image_count']+$count; }
		if(isset($imageTabResult['image_count'])){ $count = $imageTabResult['image_count']+$count; }

		return $count;
	}
	public function getQuestionTitle($hid){
		global $db, $request;
		$query = "SELECT htext,subjecttxt FROM header WHERE hid = ".$hid." AND STATUS = 'active'";
		$result = $db['master']->getOneRow($query);
		
		$questionTitle = '';
		if($result['htext'] != ''){
			$questionTitle = $result['htext'];
		}elseif($result['subjecttxt'] != ''){
			$questionTitle = $result['subjecttxt'];
		}
	
		return $questionTitle;
	}
		public function GetTxtTemplateValues($type,$hid){
		global $db,$request;	
		
		if($type!=''){
			$query 			= "SELECT subjecttxt from header where hid='".$hid."' AND status='active'";
			$values 		= $db['master']->getOneRow($query); 

			$string_length = strlen($values['subjecttxt']);  
			if($string_length>=50){
				$str = wordwrap($values['subjecttxt'], 50);
				$str = explode("\n", $str);
				$return_value = $str[0] . '...';
				console(LOG_LEVEL_INFO,"return_value :: ".$return_value);
			}else{
				$return_value = $values['subjecttxt'];
			}
		}
		return $return_value;
	}

	public function ListTopics(){
		global $db, $request;
		$addquery = '';
		$arrMapUser = array("12"=>3,"13"=>4,"14"=>5,"15"=>6,"16"=>7,"17"=>8);
		if($request['course']!='') $addquery=$addquery." AND q.cid='".$request['course']."' ";
		if($request['semester']!='') $addquery=$addquery." AND q.semid='".$request['semester']."' ";
		if($request['subject']!='') $addquery=$addquery." AND q.sid='".$request['subject']."' ";
		if($request['unit']!='') $addquery=$addquery."  AND q.uid='".$request['unit']."' ";
		
		if($request['branch'] != 0 && $request['branch'] != ''){
			$addquery = $addquery." AND q.branch_id='".$request['branch']."' ";
			$branch    = " AND q.branch_id=bru.branch_id";
		}
		
		if($_SESSION['usertype']=="pm")  $addquery=$addquery."  AND q.publish_status='development' ";
		
		if($_SESSION['usertype']=="qc")  $addquery=$addquery."  AND q.publish_status='qc' ";
		
		//$select_topics = "SELECT t.topicid,t.topic_name,q.qvid,q.publish_status FROM topics t, quesvideos q WHERE t.topicid=q.topicid AND q.univid='".$request['university']."' AND q.status='active' AND t.status='active' $addquery GROUP BY t.topicid";
		
		
		$select_topics = "SELECT t.topicid,t.topic_name,q.qvid,q.publish_status FROM topics t, quesvideos q,course c,semester s,`subject` su,units u,branch bru WHERE t.topicid=q.topicid AND q.univid='".$request['university']."' AND q.status='active' AND t.status='active' AND q.cid=c.cid AND c.status='active' AND q.semid=s.semid AND s.status='active' AND q.sid=su.sid AND su.status='active' AND q.uid=u.uid AND  u.status='active' $addquery $branch  GROUP BY t.topicid order by q.qvid desc";
		
		if($_SESSION['usertype']=="pm"){
			$select_topics = "SELECT t.topicid,t.topic_name,q.qvid,q.publish_status FROM topics t, quesvideos q,course c,semester s,`subject` su,units u,map_user_topic mu,branch bru WHERE t.topicid=q.topicid AND q.univid='".$request['university']."' AND q.status='active' AND t.status='active' AND q.cid=c.cid  AND c.status='active' AND q.semid=s.semid AND s.status='active' AND q.sid=su.sid AND su.status='active'  AND q.uid=u.uid AND  u.status='active' AND q.topicid=mu.topicid AND mu.iduser='".$arrMapUser[$_SESSION['iduser']]."' $addquery  $branch GROUP BY mu.iduser,q.topicid  order by q.qvid desc";
		}
		$results = $db['master']->getResults($select_topics);
		return $results;
	}
	
	public function ListCloneUniversity($univid){
		global $db, $request;
		$select_univ = "SELECT univid,university FROM university WHERE univid!='".$univid."' AND status='active'";
		$univ = $db['master']->getResults($select_univ);
		return $univ;
	}

	public function getEditRestriction($id){
		global $db, $request;
		$query = "SELECT * FROM edit_restriction WHERE pagebelongsto = ".$id." AND STATUS = 'active'";
		$result = $db['master']->getOneRow($query);
		return $result;
	}
    
	public function NewsContentDeleteService($id){
		global $db, $request;
		if($id != ''){
			$querys = "UPDATE news_content SET status = 'inactive' WHERE news_id = '".$id."' AND status = 'active'";
			$db['master']->query($querys);
			
		}
	}
	public function NewsContentInsertUpdateService($content, $id=''){
		global $db, $request;
		$check_res = '';  $content_res_id = array();
		if(isset($id) && $id != ''){
			$select_only = "SELECT * FROM news_content WHERE news_id = '".$id."' AND status = 'active'";
			$check_res = $db['master']->getResults($select_only);
		}
        if($check_res != ''){
			$querys = "UPDATE news_content SET content = '".$content."' WHERE news_id = '".$id."' AND status = 'active'";
			$content_res_id['type'] = 'Updated';
		}else{
			$querys = "INSERT INTO news_content(content) VALUES('".$content."')";
			$content_res_id['type'] = 'Insert';
		}	
		$content_res_id['id'] = $db['master']->query($querys);
		return $content_res_id;
	}
	public function AddAndUpdateMappingIds($map_ids, $qid){
		global $db,$request;
		
		if($qid != ''){
			$select_query = "SELECT * FROM mapped_advance_topic WHERE qid =".$qid." AND status = 'active'";
			$get_existing_val = $db['master']->getResults($select_query);
			if(isset($get_existing_val) && count($get_existing_val) > 0){
				$update_query = "UPDATE mapped_advance_topic set advancetopicids = '".$map_ids."' WHERE qid = '".$qid."' AND status = 'active'";
				$update_id    = $db['master']->query($update_query);
				$sel_query = "SELECT * FROM mapped_advance_topic WHERE qid =".$qid." AND status = 'active'";
				return $result = $db['master']->getResults($sel_query);
			}else{
				$insert_query = "INSERT INTO mapped_advance_topic (qid,advancetopicids,status) VALUES ('".$qid."', '".$map_ids."', 'active')";
				$insert_id    = $db['master']->query($insert_query);
				$sel_query = "SELECT * FROM mapped_advance_topic WHERE qid =".$qid." AND status = 'active'";
				return $result = $db['master']->getResults($sel_query);
			}
		}
		return '';
	}
	
	public function RetriveMappingIds($qid){
		global $db,$request;
		if($qid != ''){
			$select_query = "SELECT qid,advancetopicids FROM mapped_advance_topic WHERE qid =".$qid." AND status = 'active'";
			return $get_existing_val = $db['master']->getResults($select_query);
		}
		return '';
	}
	public function getVideoThumbnailWithTopic($qid){
		global $db,$request;
		
		if(empty($qid)){
			return array();
		}
		
		$cloneqid = $db['master']->getOneRow("SELECT old_qid FROM map_topic WHERE new_qid='".$qid."' AND `status`='active'");
		
		if($cloneqid["old_qid"]!='') $qid = $cloneqid["old_qid"];
		
		$videothumbnail = array();
		$query = "SELECT vname FROM questions WHERE qvtype = 'video' AND `status` = 'active' AND pagebelongsto = '".$qid."' ORDER BY qid DESC LIMIT 0,1";
		
		$thumbnail = $db['master']->getOneRow($query);
		if($thumbnail['vname'] != ''){
			$filename = trim(pathinfo($thumbnail['vname'], PATHINFO_FILENAME));
			//$thumbnailPath = 'storage/upload/useruploads/thumb/'.$filename.'.jpeg';
			$thumbnailPath = $filename.'.png';
		}else{
			$thumbnailPath = 'default.jpeg';
			//$thumbnailPath = $filename.'.png';
		}

		$sel_query = "SELECT topicid FROM quesvideos WHERE qvid='".$qid."' AND status='active'";
		$gettopicid = $db['master']->getOneRow($sel_query);
		
		if(isset($gettopicid['topicid'])){
			$topicid = $gettopicid['topicid'];
			$sel_query = "SELECT topic_name FROM topics WHERE topicid='".$topicid."' AND status='active'";
			$gettopic = $db['master']->getOneRow($sel_query);
			if($gettopic['topic_name'] != ''){
				$videothumbnail['qid'] = $qid;
				$videothumbnail['topic_id']  = $topicid;
				$videothumbnail['topic_name']= $gettopic['topic_name'];
				$videothumbnail['thumbnail'] = $thumbnailPath;
			}
		}
		return $videothumbnail;
	}
	
	
	
	
public function mapNewTopic(){
global $db,$request;

$newoptic 		= $request['topic'];
	$searchtopic 	= explode("-", $request['searchtopic']);
	$Existingtopic  = $searchtopic[1];
	// Get values of existing topic id using search topic value
	$existing_topicid = $request['linktopicid'];
	
	console(LOG_LEVEL_TRACE, "newoptic::".$newoptic.'old topic-->'.$Existingtopic.'old topic id-->'.$existing_topicid);

	/* Add topics Start */
	if($_SESSION['uid'] == '' || $_SESSION['sid'] == '' || $_SESSION['cid'] == '' || $_SESSION['unid'] == '' || $_SESSION['semid'] == ''){
		$message = "Values are not Selected Properly";
		console(LOG_LEVEL_TRACE, "alert message to Map topic to the university ::".$message);
		$already_exist = 1;
		return false;
	}

	$topic = trim (mysql_real_escape_string($request['topic']));
	$query = "SELECT topicid FROM topics  WHERE topic_name='".$topic."'  AND uid = '".$_SESSION['uid']."' AND sid = '".$_SESSION['sid']."' AND `status`='active'";
	$res = $db['master']->getOneRow($query);
	
	$already_exist = 0;
	
	
	if($res['topicid'] != ''){
		$message = "Topics Already Exist...";
		if($_SESSION['langid'] == ""){
			$_SESSION['langid'] = 1;
		}
		
		$query = "SELECT * from quesvideos where `status`='active' AND vqid='".$vqid."' AND langid='".$_SESSION['langid']."' AND uid='".$_SESSION['uid']."' AND topicid='".$_SESSION['topicid']."' AND sid='".$_SESSION['sid']."' AND cid='".$_SESSION['cid']."' AND ( branch_id = 0 OR branch_id='".$_SESSION['branchid']."' ) ORDER BY qvid DESC LIMIT 1";
		$qtypes	= $db['master']->getOneRow($query);
		
		if($qtypes['qvid'] != ""){
			$message = "Topics Already Exist and Content also exists...";
			console(LOG_LEVEL_TRACE, "alert message content already exist::".$message);
			$already_exist = 1;
			return false;
		}else{
			//$insq = "INSERT INTO topics(`topic_name`,`uid`,`sid`) VALUES('".$topic."','".$_SESSION['uid']."','".$_SESSION['sid']."')";
			//$result = $db['master']->query($insq);
		
			$id	= $res['topicid'];
			$newtopicid = $id;
		
			$_SESSION['topicid'] 	= $id;
			$_SESSION['topic_name'] = $request['topic'];
		
			$tagsArray = (explode(",",$request['tagsList']));
			$tagsArrayCount = count($tagsArray);
			console(LOG_LEVEL_TRACE, "Tags Count ::".$tagsArrayCount );
			for($i=0; $i<$tagsArrayCount; $i++){
				$ans = trim($tagsArray[$i]);  
				if($ans != ""){
					if($i == 0){ $values = "('".$id."','".$ans."')"; }
					else{$values .= ",('".$id."','".$ans."')"; }
				}
			}
			if($values != ""){
				$db ['master']->query("INSERT INTO topic_tags (topic_id,tag_name) VALUES ".$values."");
			}else{
				console(LOG_LEVEL_TRACE, "Tag Name Values are Null" );	
			}
			if($db ['master']->affectedRows()>0){
				$message = "Topic Inserted Successfully..."; 
				console(LOG_LEVEL_TRACE, "success message::".$message);
			}
			else{
				$message = "Error in Inserting Topic...";
				console(LOG_LEVEL_TRACE, "error message::".$message);
			}
	

			/* Add topics End */
	
			// make values in quesvideos table insert new topic values and get new pagebeloongsto or qvid value
	
			$_SESSION['topicid'] 	= $newtopicid;
	
			console(LOG_LEVEL_TRACE, "new topic id::".$newtopicid);
	
			$addquestionvideo 		= $db['master']->query("INSERT INTO quesvideos(`vqid`,`langid`,`uid`,`topicid`,`sid`,`cid`,univid,semid,branch_id,type,clone_topicid) VALUES('1','1','".$_SESSION['uid']."','".$_SESSION['topicid']."','".$_SESSION['sid']."','".$_SESSION['cid']."','".$_SESSION['unid']."','".$_SESSION['semid']."','".$_SESSION['branchid']."','clone','".$existing_topicid."')");
			$new_qvid 				= $db['master']->getLastID();
	
			// Get existing qvid value using existing topicid
	
			$query 		 	  = "SELECT * FROM quesvideos  WHERE topicid='".$existing_topicid."' AND status='active'";
			$qvidvalues		  = $db['master']->getOneRow($query);
			$exist_qvid		  = $qvidvalues['qvid'];
	
			console(LOG_LEVEL_TRACE, "old pagebelongsto-->".$exist_qvid."::new pagebelongsto-->".$new_qvid);
	
	
			$db['master']->query("INSERT INTO `map_topic`(`old_qid`,`new_qid`,`old_topicid`,`new_topicid`) VALUES ('".$exist_qvid."','".$new_qvid."','".$existing_topicid."','".$newtopicid."')");
	
			return $new_qvid;
		}
	}else{
		$insq = "INSERT INTO topics(`topic_name`,`uid`,`sid`) VALUES('".$topic."','".$_SESSION['uid']."','".$_SESSION['sid']."')";
		$result = $db['master']->query($insq);
		
		$id	= $db['master']->getLastID();
		$newtopicid = $id;
		
		$_SESSION['topicid'] 	= $id;
		$_SESSION['topic_name'] = $request['topic'];
		
		$tagsArray = (explode(",",$request['tagsList']));
		$tagsArrayCount = count($tagsArray);
		console(LOG_LEVEL_TRACE, "Tags Count ::".$tagsArrayCount );
		for($i=0; $i<$tagsArrayCount; $i++){
			$ans = trim($tagsArray[$i]);  
			if($ans != ""){
				if($i == 0){ $values = "('".$id."','".$ans."')"; }
				else{$values .= ",('".$id."','".$ans."')"; }
			}
		}
		if($values != ""){
			$db ['master']->query("INSERT INTO topic_tags (topic_id,tag_name) VALUES ".$values."");
		}else{
			console(LOG_LEVEL_TRACE, "Tag Name Values are Null" );	
		}
		if($db ['master']->affectedRows()>0){
			$message = "Topic Inserted Successfully..."; 
			console(LOG_LEVEL_TRACE, "success message::".$message);
		}
		else{
			$message = "Error in Inserting Topic...";
			console(LOG_LEVEL_TRACE, "error message::".$message);
		}
	}

	/* Add topics End */
	
	// make values in quesvideos table insert new topic values and get new pagebeloongsto or qvid value
	
	$_SESSION['topicid'] 	= $newtopicid;
	
	console(LOG_LEVEL_TRACE, "new topic id::".$newtopicid);
	
	$addquestionvideo 		= $db['master']->query("INSERT INTO quesvideos(`vqid`,`langid`,`uid`,`topicid`,`sid`,`cid`,univid,semid,branch_id,type,clone_topicid) VALUES('1','1','".$_SESSION['uid']."','".$_SESSION['topicid']."','".$_SESSION['sid']."','".$_SESSION['cid']."','".$_SESSION['unid']."','".$_SESSION['semid']."','".$_SESSION['branchid']."','clone','".$existing_topicid."')");
	$new_qvid 				= $db['master']->getLastID();
	
	// Get existing qvid value using existing topicid
	
	$query 		 	  = "SELECT * FROM quesvideos  WHERE topicid='".$existing_topicid."' AND status='active'";
	$qvidvalues		  = $db['master']->getOneRow($query);
	$exist_qvid		  = $qvidvalues['qvid'];
	
	console(LOG_LEVEL_TRACE, "old pagebelongsto-->".$exist_qvid."::new pagebelongsto-->".$new_qvid);
	
	
	$db['master']->query("INSERT INTO `map_topic`(`old_qid`,`new_qid`,`old_topicid`,`new_topicid`) VALUES ('".$exist_qvid."','".$new_qvid."','".$existing_topicid."','".$newtopicid."')");
	
	return $new_qvid; //return true;

}


}
?>
