<?php

require "commonincludefiles.php";

$UserArray = array();
$Faculty_Pages = "49,101,69,98,92,34,94,24,17,73,37,85,36,97,96,95,107,22,27,31,43,105,112,57,12,48
";
$Faculty_Pages_array = explode(',', $Faculty_Pages);

$Faculty_Menu   = "2,4,5,6,7,10,11,12";
$Faculty_Menu_array = explode(',', $Faculty_Menu);

$Faculty_Module = "1,3";
$$Faculty_Module_array = explode(',', $Faculty_Module);

$get_user= "SELECT `user_id` FROM `cms_usermaster` WHERE `user_name` in 
			('amit','vandita','hiral','krina','minu','pritesh','jaspal','sehul','vijay','vinit','naitik','kevan','dipak','amisha',
				'bhavik','hetal','mital','narendra','parth','mayank','pankaj','nisrag',
				'jimit','parita','sangeeta','hasmukh','kritarth',
				'sunil','manish','bhavna','piyush','rafik','harsh','harish','mehul','kinjal',
				'keyur','partham','arun','jay','vijay','harmish','digant','kunjan','rakesh',
				'mihir','nisha','srujal','bhavesh','ranjit','shuvajit',
				'vishal','keval','megha','jigna','jayv','parin','chahat','vijayj')";
$Res_get_user = dbQuery($get_user);

while($row = dbArray($Res_get_user))
{
	$UserArray[]= $row['user_id'];
	
	$Update_User = "UPDATE `cms_usermaster` 
								SET `user_role`= 'Faculty',
								`menu_ids`= '$Faculty_Menu',
								`module_ids`= '$Faculty_Module',
								`page_ids`='$Faculty_Pages',
								`createdon`= NOW() WHERE `user_id` = ".$row['user_id'];
	$Res_update = dbQuery($Update_User);
	
	if($Res_update)
	{
		$delete_from_access = dbQuery("DELETE FROM `cms_useraccess` WHERE `user_id` = ".$row['user_id']);
		if($delete_from_access)
		{
			
			for($i=0;$i<count($Faculty_Pages_array);$i++)
			{	
				$temp = array();
				$get_access_query = "SELECT  
									 p.`access`, 
									 p.`menu_id`,
									( SELECT `module_id` FROM `cms_menumaster` WHERE `menu_id` = p.`menu_id`) as module_id
									 FROM `cms_pagemaster` as p 
									 WHERE `page_id`=".$Faculty_Pages_array[$i];
				
				$get_access_res = dbQuery($get_access_query);
				
				while($get_access_row = dbArray($get_access_res))
				{
					$temp['access'] = explode(',',$get_access_row['access']);
					$temp['menu_id'] = $get_access_row['menu_id'];	
					$temp['module_id'] = $get_access_row['module_id'];
				}
			$insert_access = "INSERT INTO `cms_useraccess`
							(`user_id`, 
							 `module_id`, 
							 `menu_id`, 
							 `page_id`, 
							 `useraccess_add`, 
							 `useraccess_edit`, 
							 `useraccess_delete`, 
							 `useraccess_view`,
							 `login_id`, 
							 `createdon`) 
							   VALUES ('".$row['user_id']."',
							   		   '".$temp['module_id']."',
							   		   '".$temp['menu_id']."',
							   		   '".$Faculty_Pages_array[$i]."',
							   		   '".$temp['access'][0]."',
							   		   '".$temp['access'][1]."',
							   		   '".$temp['access'][2]."',
							   		   '1',
							   		   '1',
							   		   NOW())";
					
					 dbQuery($insert_access);
			}
		}
	}
}
echo"<pre>";
print_r($UserArray);
//print_r($UserArray[0]);

/*,'hardikr','vandita','hiral','krina','minu','pritesh',
				'jaspal','sehul','vijay','vinit','naitik','kevan','dipak','amisha',
				'bhavik','hetal','mital','narendra','parth','mayank','pankaj','nisrag',
				'jimit','parita','sangeeta','hasmukh','kritarth',
				'sunil','manish','bhavna','piyush','rafik','harsh','harish','mehul','kinjal',
				'keyur','partham','arun','jay','vijay','harmish','digant','kunjan','rakesh',
				'mihir','nisha','srujal','bhavesh','ranjit','shuvajit',
				'vishal','keval','megha','jigna','jayv','parin','chahat','vijayj')";

*/


/*hod list:
 
 comphod,echod,electhod,handashod,civilhod,mechhod,autohod
 */
/*power User
 'imageeti','nirav','darsh','principal'
 * /
 */

?>