<?php
ob_clean();
include("../../../include/startup.php"); 
if(isset($_REQUEST['action']) && $_REQUEST['action']=='set_order'){
	$order = explode(",",$_REQUEST['order']);
	$i = 1;
	foreach($order as $key => $id){
		if($id == ""){
			continue;
		}
		mysqli_query($conn,"UPDATE document_template_section SET ord='".$i."' WHERE id='".$id."' ");
		$i++;
	}
	//echo "Order updated successfully";
}elseif(isset($_REQUEST['action']) && $_REQUEST['action']=='get_template_section_by_template_id'){
	$document_template_id = $_REQUEST['document_template_id'];
	$section_string = "";
	$sql = "SELECT * FROM document_template_section WHERE document_template_id = '$document_template_id' ORDER BY ord";
	$rs = mysqli_query($conn,$sql);
	if(mysqli_num_rows($rs) > 0){
			$section_string .= '<label for="Document Template Section" class="control-label">Document Template Section</label><br>';
		while($row = mysqli_fetch_array($rs)){ 
			$section_string .= "<div class='col-sm-3' style='margin-bottom:5px;'>".$row['section']." <input type='checkbox' class='checkbox_div flat-red section_checkbox' name='section_ids[]' value='".$row['id']."'></div>";
		}
		echo $section_string;
	}else{
		echo "<div class='col-sm-3'>There is no section in this template.</div>";
	}
}
die;
?>