<?php
require "../commonincludefiles.php";
error_reporting(1);
$i = 0;

if ($_SESSION["VedantnrCollegeId"] != "" && isset($_SESSION["VedantnrCollegeId"])) {

	/*$sql = "
			  SELECT
				  CONCAT(sm.student_surname,' ',sm.student_firstname) AS student_name,
				  sm.student_id,
				  sm.student_firstname,
				  sm.student_birthdate,
				  sm.student_gturegno,
				  um.user_name,
				  um.user_password
			  FROM
				  cms_studentmaster sm LEFT JOIN cms_usermaster um ON sm.student_id = um.student_id ,
					 cms_studentdetail sd	 
			  WHERE 
				  sm.student_id = sd.student_id AND
				  sm.student_active = 1 AND
				  
				  sd.cur_branchid = ".Escape($_REQUEST['branch_name'])." AND 
				  sd.year_id = ".Escape($_REQUEST['year_name'])." AND 
				  sd.cur_branchyear_id = ".Escape($_REQUEST['branchyear_name'])." AND 
				  sd.cur_semesterid = ".Escape($_REQUEST['semester_name'])." 
				  ORDER BY student_gturegno ASC, student_name ASC";	
					  $rs = dbQuery($sql);		*/


	$condition = "";



	if ($_REQUEST['branch_name'] != '') {
		$condition .= " and sd.cur_branchid = " . Escape($_REQUEST['branch_name']) . " ";
	}
	if ($_REQUEST['year_name'] != '') {
		$condition .= " and sd.year_id = " . Escape($_REQUEST['year_name']) . " ";
	}
	if ($_REQUEST['branchyear_name'] != '') {
		$condition .= " and sd.cur_branchyearid = " . Escape($_REQUEST['branchyear_name']) . " ";
	}
	if ($_REQUEST['semester_name'] != '') {
		$condition .= " and sd.cur_semesterid = " . Escape($_REQUEST['semester_name']) . " ";
	}
	$condition .= " ORDER BY student_gturegno ASC, student_name ASC ";
	$objStudentMgmt = new StudentMgmt();
	$rs = $objStudentMgmt->getuserpassword($condition);
	$total = dbRows($rs);


	$SetupData = array("count" => $total, "data" => array());
	$j = 0;
	if (dbRows($rs) > 0) {
		while ($row = dbArray($rs)) {
			$temparray["student_id"] = $row["student_id"];
			$temparray["student_name"] = $row["student_name"];
			$temparray["student_gturegno"] = $row["student_gturegno"];

			if ($_REQUEST['autogenerate'] == '1') {
				$day = date('d', strtotime($row["student_birthdate"]));
				$month = date('m', strtotime($row["student_birthdate"]));
				$temparray["user_name"] = $row["student_gturegno"];
				$temparray["user_password"] = substr($row["student_firstname"], 0, 4) . $day . $month;
			} else {
				$temparray["user_name"] = $row["user_name"];
				$temparray["user_password"] = $row["user_password"];
			}

			$SetupData["data"][$i] = $temparray;
			$i++;
		}
	}
	echo json_encode($SetupData);
} else {
	echo '{"success":"false","msg":"session expiry"}';
}
?>