<?php
ini_set('display_errors', 0);
error_reporting(E_ALL);

session_name('CAKEPHP');
session_start();

$PageSecurity = 1;

include('includes/function_lib.php');
include('includes/session.inc');
include('cocoon_config.php');

//echo'<pre/>';print_r($_SESSION); exit;
if (!defined('_ROOT')) {
	define('_ROOT', 'http://' . $_SERVER['HTTP_HOST'] . '/git/PHP_564/mimhans-2.0/');
}
if (!defined('_ERP')) {
	define('_ERP', 'http://' . $_SERVER['HTTP_HOST'] . '/git/PHP_564/mimhans-3.0/herp');
}
//include('includes/session_for_coocoon_login.inc');
?>

<?php include("includes/function_lib_hmis.php");
include("includes/pagination2.php");
$title = _('Main Menu');
include('Module_Permission.php');

$data          = array();
$pageTypeName = $_REQUEST['search'];
$pageTypeName = $_REQUEST['Search'];
if (isset($_REQUEST['visit_action']) && $_REQUEST['visit_action'] == 'visit') {
	$id = $s->getFieldValue("previous_visit_history", "module_id='" . $_REQUEST['modid'] . "' AND form_id='" . $_REQUEST['frmid'] . "' AND created_by='" . $_SESSION['UserID'] . "'", "id");
	if ($id == '') {
		$data['module_id'] = $_REQUEST['modid'];
		$data['form_id'] = $_REQUEST['frmid'];
		$data['counter'] = 1;
		$data['created_date'] = date('Y-m-d');
		$data['created_by'] = $_SESSION['UserID'];
		$data['CompanyId'] = $_SESSION['ACGCompanyId'];
		$s->RecordInsert("previous_visit_history", $data);
	} else {
		$counter = $s->getFieldValue("previous_visit_history", "id='" . $id . "' ", "counter");
		$data['counter'] = $counter + 1;
		$data['modified_date'] = date('Y-m-d');
		$data['modified_by'] = $_SESSION['UserID'];
		$cond = "id='" . $id . "' ";
		$s->RecordEdit("previous_visit_history", $data, $cond);
	}
	unset($data);
}

if ($_REQUEST['Application'] == ''  && $_REQUEST['frmid'] != '') {
	$module_name = $s->getField('modules', 'id', $_REQUEST['modid'], 'modulename');
	$form_name = $s->getField('modules_form', 'id', $_REQUEST['frmid'], 'frm_name');
	$cat_id = $s->GetFieldValue('modules_form', "moduleid='" . $_REQUEST['modid'] . "' and id='" . $_REQUEST['frmid'] . "'", 'module_form_category_id');
	$category_name = $s->getField('module_form_categories', 'id', $cat_id, 'cat_desc');
	$module_desc = $s->getField('modules', 'id', $_REQUEST['modid'], 'description') . "&modid=" . $_REQUEST['modid'];
	$frm_link = $s->getField('modules_form', 'id', $_REQUEST['frmid'], 'frm_url') . "&modid=" . $_REQUEST['modid'] . "&frmid=" . $_REQUEST['frmid'];
	page_name($link1, $form_name);
}

include('includes/header.inc');
include("includes/Class_Emp.php");
$_SESSION['modid'] = $modid = $_REQUEST['modid'];
$_SESSION['frmid'] = $frmid = $_REQUEST['frmid'];
$rurl = "&modid=" . $_REQUEST['modid'] . "&frmid=" . $_REQUEST['frmid'];

$page_title = $s->GetFieldValue('modules_form', "id='" . $_REQUEST['frmid'] . "'", 'frm_name');


$frmpermission = $px->GetFileAccess($_SESSION['modid'], $_SESSION['frmid'], $_SESSION['ACGRoleId']);
/* Comment By Manish on 2 may, 2013 for exclude erp role
$_SESSION['frmAdd']=$frmpermission[0];
$_SESSION['frmEdit']=$frmpermission[1];
$_SESSION['frmDelete']=$frmpermission[2];
$_SESSION['frmView']=$frmpermission[3];
*/

$_SESSION['frmcreate'] = 1;
$_SESSION['frmAdd'] = 1;
$_SESSION['frmEdit'] = 1;
$_SESSION['frmDelete'] = 1;
$_SESSION['frmView'] = 1;


//$frmpermission= $px->GetFileAccess($_SESSION['modid'],$_SESSION['frmid'], $_SESSION['ACGRoleId']);
//$_SESSION['frmEdit']=$frmpermission[1];
//$_SESSION['frmDelete']=$frmpermission[2];
//$_SESSION['frmView']=$frmpermission[3];
// $_SESSION['frmcreate']=$frmpermission[0];
if (isset($_GET['Application'])) {
	$_SESSION['Module'] = $_GET['Application'];
}
if (isset($_REQUEST['modid'])) { ?>
	<div class="contentmain">
		<div class="barmenu" onclick="openNav()" title="Main Menu" id="mmenu"><i class="fa fa-bars micons"></i><span class="m-menu">Main Menu</span></div>
		<div id="mySidenav" class="sidenav">
			<h3><i class="fa fa-bars" aria-hidden="true" style="margin-right:10px;"></i> Main Menu <a href="javascript:void(0)" class="closebtn" onclick="closeNav()"><i class="fa fa-angle-double-left" aria-hidden="true"></i>
				</a></h3>
			<!-- Menu start -->
			<?php include('includes/main_menu.php'); ?>
			<!-- Menu end -->
		</div>
		<div class="mainwrapper">
			<div class="mwrapper">
				<div class="pg-link">
					<div>
						<div id="bread">
							<div class="wful">
								<ul class="pull-left">
									<?php if ($_REQUEST['Application'] == ''  && $_REQUEST['frmid'] != '') { ?>
										<li><a accesskey='0' title='Home' href='../'><i class='glyphicon glyphicon-home'></i></a></li>
										<li><a role="button" data-toggle="collapse" data-target="#moduledetail" aria-expanded="false" aria-controls="moduledetail"><?php echo $module_name; ?></a></li>
										<li><?php echo $category_name; ?></li>
										<li><a href="index.php?route=<?php echo $frm_link; ?>"><?php echo $form_name; ?></a></li>
									<?php } ?>
								</ul>
							</div>
							<div class="collapse bg-col" id="moduledetail">
								<div class="">

									<style type="text/css">
										.modwrapper,
										#modchild {
											width: 100%;
											height: auto;
											float: left;
										}

										/*.modwrapper{margin-bottom:10px;}*/
										.modchildin {
											margin-bottom: 10px;
										}

										.modwrapper {
											/*border:rgba(149,199,250,0.6) 1px solid; background-color: rgba(149,199,250,0.2);*/
											margin-bottom: 5px;
										}

										.modwrapper h1,
										#modchild h2 {
											background-color: rgba(149, 199, 250, 0.4);
											border-bottom: 1px solid #1362a5;
											border-radius: 0;
											font-size: 15px;
											font-weight: 600;
											line-height: 22px;
											margin: 0 0 8px;
											padding: 5px 10px;
										}

										/*#modchild{background-color: rgba(255,255,255,1.0); border:rgba(149,199,250,0.2) 1px solid; padding:3px;}*/
										.modchildin {
											width: 18%;
											height: auto;
											float: left;
											margin: 3px;
											min-height: 150px;
											border: 1px solid rgba(0, 0, 0, 0.5);
											background-color: rgba(255, 255, 255, 1.0);
										}

										#modchild h2 {
											background-color: rgba(0, 0, 0, 0.9);
											border-bottom: 0px solid #5c9cdd;
											font-size: 12px;
											font-weight: bold;
											line-height: 30px;
											text-align: center;
											margin: 0;
											text-transform: uppercase;
											color: #fff;
										}

										#modchild ul {
											list-style: none;
											margin: 0;
											padding: 0;
										}

										#modchild ul li {
											display: block;
											position: relative;
											/* padding:2px 10px 2px 15px;*/
											border-bottom: 1px solid rgba(0, 0, 0, 0.5);
											padding: 0;
										}

										#modchild ul li:last-child {
											border-bottom: 0;
										}

										#modchild ul li a {
											display: block;
											position: relative;
											padding: 2px 6px;
											line-height: 20px;
											color: #242424;
										}

										#modchild ul li:before {
											content: '';
										}

										/*#modchild ul li:before{position: absolute; top:1px; left:3px; font-family:"FontAwesome"; content:'\f0da'; font-size: 13px; color: #718fa8;}
#modchild ul li:first-child:before{content:'\f0da';}*/
										#modchild ul li a:hover {
											background-color: #bad9f9;
											text-decoration: none;
										}

										#modchild a.child-active {
											color: #0b8b38;
											font-weight: bold;
										}
									</style>
									<?php
									$modid = $_REQUEST['modid'];

									$sql_form = DB_query("select frm_moduleid from  company_profile where 
					 roll_id='" . $_SESSION['ACGRoleId'] . "'", $db);
									while ($roledata = DB_fetch_array($sql_form)) {
										$formarray[] = $roledata['frm_moduleid'];
									}
									//print_r($formarray);
									//if($formarray!='')
									$selected_moduleid = implode("','", $formarray); //moduleid='".$_REQUEST['modid']."'  and					

									$sql_form1 = DB_query("SELECT module_form_category_id FROM modules_form where id in('" . $selected_moduleid . "')
			                    and   moduleid=$modid", $db);
									while ($roledata1 = DB_fetch_array($sql_form1)) {
										$formarray1[] = $roledata1['module_form_category_id'];
									}
									//print_r($formarray);
									// if($formarray1!='')
									$selected_moduleid1 = implode("','", $formarray1);

									$categories = "Select * from module_form_categories where module_id=$modid and id in('" . $selected_moduleid1 . "') and status='Y' order by sequence ASC";
									$categories_res = DB_query($categories, $db);
									$colspan = DB_num_rows($categories_res);
									?>
									<div class="menu-list" id="accordion">
										<div class="">
											<div class="col-sm-12">
												<div class="modwrapper">
													<div id="modchild">
														<?php while ($category_row = DB_fetch_array($categories_res)) { ?>
															<div class="modchildin">
																<h2><?php echo $category_row['cat_desc']; ?></h2>
																<ul>
																	<?php
																	$forms = "Select * from modules_form where  moduleid=$modid and id in('" . $selected_moduleid . "') and module_form_category_id='" . $category_row['id'] . "' and status='Y' order by sequence ASC";
																	$forms_result = DB_query($forms, $db);
																	while ($forms_row = DB_fetch_array($forms_result)) {
																	?>
																		<li><a href="index.php?route=<?php echo $forms_row['frm_url']; ?>&modid=<?php echo $modid; ?>&frmid=<?php echo $forms_row['id']; ?>" class="tablelink"><?php echo $forms_row['frm_name']; ?></a></li>
																	<?php } ?>
																</ul>
															</div>
														<?php } ?>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="rightpanelmain">
					<div>
						<?php


						//echo "gautam <pre>";print_r($_SESSION); echo "</pre>";

						if ($_REQUEST['route'] != '') {
							echo '<div class="formsarea">';

							include($_REQUEST['route'] . ".php");
							echo '</div>';
						} else {
							echo '<div class="formsarea">';

							if ($_REQUEST['Application'] == 'emp') {

								include("TaskMgt/emplyee_portal_index.php");
							}
							else if ($_REQUEST['Application'] != '') {
								include("table_of_content.php");
							}
							echo '</div>';
						}
						//echo '<img src="'.$rootpath.'/css/'.$theme.'/images/dashboard.jpg" />';

						?>
					</div>
				</div>
			</div>
		</div>
		<div style="clear:both;"></div>
	</div>
<?php
} else { ?>
	<div align="center">
		<div class="contentmain">
			<div class="barmenu" onclick="openNav()" title="Main Menu" id="mmenu"><i class="fa fa-bars micons"></i><span class="m-menu">Main Menu</span></div>
			<div id="mySidenav" class="sidenav">
				<h3><i class="fa fa-bars" aria-hidden="true" style="margin-right:10px;"></i> Main Menu <a href="javascript:void(0)" class="closebtn" onclick="closeNav()"><i class="fa fa-angle-double-left" aria-hidden="true"></i>
					</a></h3>
				<!-- Menu start -->
				<?php include('includes/main_menu.php'); ?>
				<!-- Menu end -->
			</div>

			<?php
			$flag = 1;
			$dash_id = explode(',', $_SESSION['dashboard']);
			for ($i = 0; $i < count($dash_id); $i++) {
				$data = $s->getField('dashboard_master', 'id', $dash_id[$i], 'dashboard_url');
				if ($data != '') {
					$flag = 1;
				}
			}
			//echo $data;
			if ($flag == 0 || $data == '')
				include('dashboard11.php');
			else
				include($data);
			?>
			<?php // echo '<img src="'.$rootpath.'/css/'.$theme.'/images/dashboard.jpg" />';
			?>
			<div style="clear:both;"></div>
		</div>
	</div>
<?php
}
include('includes/footer.inc');
?>
