<?php
include("access.php");
include("include/admin.class.php");
include("include/conf.class.php");
$userinfo=$cartCore->get_user_info($CARTUSERNAME);
$cartAdminMain->check_grant($userinfo['USER_ID'],$page_name);
$cartCore->get_headder();
$cartCore->view_welcome($userinfo['USERNAME'],$userinfo['IMAGE']);
$cartCore->view_sidebar($userinfo['USER_ID'],$TOKEN_ID);
$cartCore->view_credit($COMPANY_ID,$bk);
if(isset($_GET['delete_enrollment'])){
	$do='delete';
	$company_id=$cartCore->md5_base64_decode($_GET['company_id']);
	$user_id=$cartCore->md5_base64_decode($_GET['userid']);
	$cartAdminMain->add_delete_enrollment($userinfo['USERNAME'],$page_name,$TOKEN_ID,$company_id,$user_id,$_GET['menu_name'],$do);	
	exit;
}

if(isset($_POST['user_id']) and isset($_POST['company_id'])){
	$do='add';
	$company_id=$user_id="";
	$cartAdminMain->add_delete_enrollment($userinfo['USERNAME'],$page_name,$TOKEN_ID,$company_id,$user_id,$_GET['menu_name'],$do);	
	exit;
}
?>
        <!-- top navigation -->
        <div class="top_nav">
          <div class="nav_menu">
            <nav>
              <div class="nav toggle">
                <a id="menu_toggle"><i class="fa fa-bars"></i></a>
              </div>

              <ul class="nav navbar-nav navbar-right">
              
              
              <?=$cartCore->view_userprofile($userinfo['USER_ID'],$userinfo['USERNAME'],$userinfo['IMAGE'],$TOKEN_ID,$COMPANY_ID,$bk)?>

                <li role="presentation" class="dropdown">
                  <a href="javascript:;" class="dropdown-toggle info-number" data-toggle="dropdown" aria-expanded="false">
                    <i class="fa fa-envelope-o"></i>
                    <span class="badge bg-green"><?=$cartAdminMain->getMessageCount($userinfo['USERNAME'])?></span>
                  </a>
                  <ul id="menu1" class="dropdown-menu list-unstyled msg_list" role="menu">
                  <?=$cartAdminMain->getUserMessage($userinfo['USERNAME'])?>
                    <li>
                      <div class="text-center">
                        <a href="message.php?token_id=<?=$TOKEN_ID?>&pid=<?=$cartCore->md5_base64_encode($userinfo['USERNAME'])?>">
                          <strong>See All Alerts</strong>
                          <i class="fa fa-angle-right"></i>
                        </a>
                      </div>
                    </li>
                  </ul>
                </li>
              </ul>
            </nav>
          </div>
        </div>
        <!-- /top navigation -->

        <!-- page content -->
        <div class="right_col" role="main">
          <div class="">
            <div class="page-title">
              <div class="title_left">
                <h3>
				<?php
                if(isset($_GET['menu_name']) && $_GET['menu_name'] != "")
				{
					echo $cartCore->md5_base64_decode($_GET['menu_name']);
				}
				else
				{
					echo $cartCore->getPageHeading($page_name);
				}
				?>
			</h3>
              </div>
            </div>
            <div class="clearfix"></div>

            <div class="row">
              <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="x_panel">
                  <div class="x_title">
                    <h2><?=$cartCore->getMainPageHeading($page_name)?> 
                    <small><?php
                if(isset($_GET['menu_name']) && $_GET['menu_name'] != "")
				{
					echo $cartCore->md5_base64_decode($_GET['menu_name']);
				}
				else
				{
					echo $cartCore->getPageHeading($page_name);
				}
				?></small></h2>
                
                    <ul class="nav navbar-right panel_toolbox">
                      <li><a class="collapse-link"><i class="fa fa-chevron-up"></i></a>
                      </li> 
                    </ul>
                    <div class="clearfix"></div>
                  </div>
                  <div class="x_content">

<?php
//display message affter submit

		if(isset($_GET['success_msg']) && $_GET['success_msg']!="")
		{	
			echo $cartCore->display_sucess_msg($cartCore->md5_base64_decode($_GET['success_msg']));		  
		}
		if(isset($_GET['warning_msg']) && $_GET['warning_msg']!="")
		{	
			echo $cartCore->display_warning_msg($cartCore->md5_base64_decode($_GET['warning_msg']));		  
		}	
?>

<?php
if(!isset($_GET['step']))
{
?>
<h6>Step 01</h6>
                    <form class="form-horizontal form-label-left" novalidate action="<?=$page_name?>?token_id=<?=$TOKEN_ID?>&step=<?=$cartCore->md5_base64_encode('step02')?>&menu_name=<?=$_GET['menu_name']?>" method="post">
                      
                       <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Company Name <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select class="form-control col-md-7 col-xs-12" name="company_id">
                 			      <?=$cartAdminMain->find_selected_company(); ?>
                          </select>
                        </div>
                      </div>
                      
                      <div class="ln_solid"></div>
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="send" type="submit" class="btn btn-success">Next</button>
                        </div>
                      </div>
                    </form>
                  </div>
                  <?php
}
				  if(isset($_GET['step']))
					{
						if(isset($_POST['company_id'])){
						$get_company_details=$cartAdminMain->get_global_config_for_add($_POST['company_id']);
						}
						else{
							$get_company_details=$cartAdminMain->get_global_config_for_add($_GET['company_id']);
						}
						
				  ?>
<h6>Step 02 - Selected Company : <b><?=$get_company_details['COMPANY_NAME']?></b></h6>
                   <form class="form-horizontal form-label-left" novalidate action="<?=$page_name?>?token_id=<?=$TOKEN_ID?>&step=<?=$cartCore->md5_base64_encode('step02')?>&menu_name=<?=$_GET['menu_name']?>" method="post">  
                   <input type="hidden" name="company_id" value="<?=$get_company_details['GLOBAL_ID']?>" />
                   <div class="item form-group">
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">New User <span class="required">*</span>
                        </label>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                          <select class="form-control col-md-7 col-xs-12" name="user_id">
                 			      <?=$cartAdminMain->find_selected_permission_username(); ?>
                          </select>
                        </div>
                   </div>   
                      <div class="form-group">
                        <div class="col-md-6 col-md-offset-3">
                          <button id="send" type="submit" class="btn btn-success">Submit</button>
                        </div>
                      </div>
                    </form>
                  <div class="ln_solid"></div>

                   <table id="datatable-buttons" class="table table-striped table-bordered">
                      <thead>
                        <tr>
                        <th>Username</th>
                        <th>Full name</th>
                        <th>Enroll by</th>
                        <th>Enroll date</th>
                          <th>Option</th>
                        </tr>
                      </thead>
                      <tbody>
                      <?=$cartAdminMain->get_user_enrollment($TOKEN_ID,$userinfo['USERNAME'],$_GET['menu_name'],$get_company_details['GLOBAL_ID'])?>
                      </tbody>
                    </table>
                    <script type="text/javascript">
	
					function delete_enrollment(gid){
					var answer = confirm ("Are you sure want to delete this enrollment?");
					if (answer)
					window.location="<?=$_SERVER['PHP_SELF']?>?delete_enrollment="+gid;
					}
					</script>
                    <?php }?>
                </div>
              </div>
            </div>
          </div>
        </div>
        <!-- /page content -->

        <!-- footer content --><?=$cartCore->get_footer();?>
        <!-- /footer content -->
      </div>
    </div>

    <!-- jQuery -->
    <script src="../vendors/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap -->
    <script src="../vendors/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- FastClick -->
    <script src="../vendors/fastclick/lib/fastclick.js"></script>
    <!-- NProgress -->
    <script src="../vendors/nprogress/nprogress.js"></script>
    <!-- validator -->
    <script src="../vendors/validator/validator.js"></script>

    <!-- Custom Theme Scripts -->
    <script src="../build/js/custom.min.js"></script>
	
  </body>
</html>