<?php

/*--------------------------------------------------\
| Onlinksoft   	|   System   | Alshamsi             |
|---------------------------------------------------|
| For use with:                                    	|
| Onlinksoft Systems Only 							|
| https://www.Onlinksoft.com/  	            		|
| by Dr Abdullah Y.A.M Alshamsi                     |
| Mobile 00967733393330		                    	|
\--------------------------------------------------*/

include_once("icodes.inc");

global $saai_options;
create_tbl_option(); 
$saai_options = GetAllThemeOptions();

function addhttp($url) {
		    if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
		        $url = "http://" . $url;
		    }
		    return $url;
		}
	class renderer{
		function get_icon($category){
			global  $path_to_root, $SysPrefs;

			if ($SysPrefs->show_menu_category_icons)
				$img = $category == '' ? 'right.gif' : $category.'.png';
			else	
				$img = 'right.gif';
			return "<img src='$path_to_root/themes/".user_theme()."/images/$img' style='vertical-align:middle;' border='0'>&nbsp;&nbsp;";
		}

		function wa_header(){
			global $saai_options; 			
			if(isset($_GET['application']) && ($_GET['application'] == 'orders' || $_GET['application'] == 'orders#header'))
				page(_($help_context = "Sales"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'AP'|| $_GET['application'] == 'AP#header'))
				page(_($help_context = "Purchases"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'stock'|| $_GET['application'] == 'stock#header'))
				page(_($help_context = "Items & Inventory"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'manuf'|| $_GET['application'] == 'manuf#header'))
				page(_($help_context = "Manufacturing"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'proj'|| $_GET['application'] == 'proj#header'))
				page(_($help_context = "Dimensions"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'assets'|| $_GET['application'] == 'assets#header'))
				page(_($help_context = "Fixed Assets"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'GL'|| $_GET['application'] == 'GL#header'))
				page(_($help_context = "GL & Banking"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'extendedhrm'|| $_GET['application'] == 'extendedhrm#header'))
				page(_($help_context = "HRM and Payroll"), false, true);
			elseif(isset($_GET['application']) && ($_GET['application'] == 'system'|| $_GET['application'] == 'system#header'))
				page(_($help_context = "Setup Menu"), false, true);
			elseif((!isset($_GET['application']) || ($_GET['application'] == 'dashboard'|| $_GET['application'] == 'dashboard#header') ) && $saai_options['hide_dashboard'] == 0 )
				page(_($help_context = "Dashboard"), false, true);
			else
				page(_($help_context = "Main Menu"), false, true);
		}

		function wa_footer(){
			end_page(false, true);
		}

		function menu_header($title, $no_menu, $is_index){
			global $path_to_root, $SysPrefs, $db_connections, $icon_root, $version, $installed_extensions, $saai_options, $fonts_list;			
			
			require_once("ExtraSettings.php"); ?>
			<script> 
			(function() {
			    var link = document.querySelector("link[rel*='icon']") || document.createElement('link');
			    link.type = 'image/x-icon';
			    link.rel = 'shortcut icon';
			    <?php if(isset($saai_options['favicon']) && file_exists(dirname(__FILE__).'/images/'.$saai_options['favicon']) && !is_dir(dirname(__FILE__).'/images/'.$saai_options['favicon'])){
			    	echo " link.href = '$path_to_root/themes/".user_theme()."/images/".$saai_options['favicon']."?".rand(2,5)."'; ";
			    }else {
			    	echo "link.href = '$path_to_root/themes/".user_theme()."/images/favicon.ico?".rand(2,5)."';";
			    } ?>
			    
			    document.getElementsByTagName('head')[0].appendChild(link);
			}());
			</script> <?php 
		echo '</style><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
		<link href="'.$path_to_root.'/themes/onlinksoft/css/fontello.css" rel="stylesheet" type="text/css"> 
 <link rel="stylesheet" href="'.$path_to_root.'/themes/onlinksoft/css/animation.css">
 <link href="https://fonts.googleapis.com/css2?family='.$fonts_list[$saai_options['font']]['link'].'&display=swap" rel="stylesheet"><style> 
 html, body { font-family : '.$fonts_list[$saai_options['font']]['font-family'].';}';

 if(isset($saai_options['hide_back_button']) && $saai_options['hide_back_button'] == 1) { 
 	echo 'a[href="javascript:goBack();"]{ display: none;}';
 } else {
 	echo 'a[href="javascript:goBack();"][ display: block;  line-height: 40px; color: #006fd0;}';
 }

echo '</style>
 <script src="'.$path_to_root.'/themes/'.user_theme().'/js/jquery.js"></script>';
 
			$color_scheme = $saai_options['color_scheme']; 
			if(!$color_scheme)
				$color_scheme= 'default';		
			if($color_scheme == 'custom'){ 
				require_once('custom_color.php');
			}else 	
				echo '<link rel="stylesheet" href="'.$path_to_root.'/themes/onlinksoft/css/colorschemes/'.$color_scheme.'.css">';
			require_once("ExtraSettings.php"); 
			echo '<div class="wrapper">'; // tabs

			$indicator = "$path_to_root/themes/".user_theme(). "/images/ajax-loader.gif";
			if (!$no_menu)			{
				$applications = $_SESSION['App']->applications;
				$local_path_to_root = $path_to_root;
				$sel_app = $_SESSION['sel_app'];
				if(isset($saai_options['logo']) && file_exists(dirname(__FILE__) .'/images/'.$saai_options['logo']) && !is_dir(dirname(__FILE__) .'/images/'.$saai_options['logo'])){
				$kv_logo = $saai_options['logo'];}
			// }else
			// $logo_img = 'LTE.png?'.rand(2,5);
				if(isset($saai_options['use_software_logo']) && $saai_options['use_software_logo'] == 1){
					if(file_exists($path_to_root.'/themes/onlinksoft/images/'.$kv_logo) && !is_dir($path_to_root.'/themes/onlinksoft/images/'.$kv_logo)){
						$logo_img = $path_to_root.'/themes/onlinksoft/images/'.$kv_logo.'?'.rand(2,5);
					}else
						$logo_img = $path_to_root.'/themes/onlinksoft/images/onlinksoft.png?'.rand(2,5);
				} else {
					$coy_logo = get_company_pref("coy_logo");
					if(file_exists(company_path() .'/images/'.$coy_logo) && !is_dir(company_path() .'/images/'.$coy_logo)){
						$logo_img = company_path().'/images/'.$coy_logo.'?'.rand(2,5);
					}else
						$logo_img = $path_to_root.'/themes/onlinksoft/images/onlinksoft.png?'.rand(2,5);
				}
				$hide_dashboard = $saai_options['hide_dashboard']; 
				if($hide_dashboard == 0){
					$root_url = $path_to_root.'?application=dashboard';
				} else
					$root_url = $path_to_root.'?application='.$_SESSION['wa_current_user']->prefs->startup_tab;

				echo '<div class="sidebar" id="sidebar">
      <div class="sidebar-wrapper">
        <div class="logo">
          <a href="'.$root_url.'"> <img src="'. $logo_img.'" style="max-width:200px; max-height:80px;"><!--'.$db_connections[user_company()]["name"].' --> </a>
          <a class="simple-text" href="'. $path_to_root.'/admin/display_prefs.php?" > '.$_SESSION['wa_current_user']->name.'</a>   <a href="'.$root_url.'" class="small-logo"><img src="'.$path_to_root.'/themes/onlinksoft/images/kv_logo.png"></a> </div>';


                   echo '<div class="icons"> <a class="right" href="'. $path_to_root.'/admin/change_current_user_password.php?selected_id=' . $_SESSION["wa_current_user"]->username . '"> <span class="icon-account_circle"></span></a>
			  <a class="right" href="'. $path_to_root.'/admin/display_prefs.php?" style="padding:0 5px;" > <span class="icon-th-large"></span></a>';
                  $MasterRole = $saai_options['theme'];

                  if(!$MasterRole || user_check_access('SA_SETUPCOMPANY')){
                  echo '<a class="right" href="'. $path_to_root.'/themes/onlinksoft/theme-options.php?" style="padding:0 5px;"><span class="icon-burst_mode"></span></a>';
                 }

// <div class="logo">
//           <a href=".?application=dashboard"> <img src="./company/0/images/logo_frontaccounting.jpg?5" style="max-width:200px; max-height:80px;"><!--Saai Theme Demo --> </a>
//           <a class="simple-text" href="./admin/display_prefs.php?"> Theme  Demo </a>   <a href=".?application=dashboard" class="small-logo"><img src="./themes/onlinksoft/images/kv_logo.png"></a>   </div>
// display_error($_SESSION['wa_current_user']);

        
       echo '</div><div class="user-panel user-panel-dropdown">';
	if(isset($saai_options['enable_master_login']) && $saai_options['enable_master_login'] == 1) {

		include_once($path_to_root."/themes/onlinksoft/includes/users.php");
		$row = get_master_login($_SESSION['wa_current_user']->loginname);
		$companies = unserialize(base64_decode($row['companies']));
		$local_path_to_root = $path_to_root; 
		if(!empty($companies)){
			if(!in_array($_SESSION["wa_current_user"]->company, $companies)){
				$_SESSION['wa_current_user']->company = $companies[0];
				header("location:index.php");
			}
		}

       echo '<select name="CompanyName" class="ChangeCompany" data-live-search="true">';
		echo '<option value="'.$_SESSION['wa_current_user']->company.'" selected> '.$db_connections[$_SESSION['wa_current_user']->company]['name'].'</option>';
		foreach($db_connections as $cid => $single){
			if(!empty($companies) && in_array($cid, $companies) && $cid != $_SESSION['wa_current_user']->company)
				echo '<option value="'.$cid.'">' . $db_connections[$cid]["name"] .'</option>';
		}
        echo '</select>';
    }
    echo  '</div>
        <nav id="nav"><ul class="nav">';
	if($hide_dashboard == 0){
		echo '<li>  <a class="'.((isset($_GET['application']) && $_GET['application']=='dashboard') ? 'active' : '').'" href="'.$path_to_root.'?application=dashboard" accesskey="D"> <i class="icon-av_timer"></i> <span> '._("Dashboard").' </span></a> </li>';
	}
		
    $icon_root ='av_timer';
	foreach($applications as $app){
        if ($_SESSION["wa_current_user"]->check_application_access($app))  {
            if(trim($app->id) == 'orders')
				$icon_root = 'monetization_on';
			elseif(trim($app->id) == 'AP')
				$icon_root = 'add_shopping_cart';
			elseif(trim($app->id) == 'stock')
				$icon_root = 'storage';
			elseif(trim($app->id) == 'manuf')
				$icon_root = 'location_city';
			elseif(trim($app->id) == 'assets')
				$icon_root = 'receipt';
			elseif(trim($app->id) == 'proj')
				$icon_root = 'dialpad';
			elseif(trim($app->id) == 'GL')
				$icon_root = 'account_balance_wallet';
			elseif(trim($app->id) == 'system')
				$icon_root = 'settings';
			else
				$icon_root ='av_timer';
            $acc = access_string($app->name);						
			echo "<li><a class='".($sel_app == $app->id ? 'active' : '')."' href='$local_path_to_root/index.php?application=".$app->id."'$acc[1]> <i class='icon-".$icon_root."'></i> <span>" .($app->id == 'GL' ? 'GL & Banking' : $acc[0] ). " </span></a>";
        }
	}

	if(isset($saai_options['enable_master_login']) && $saai_options['enable_master_login'] == 1) 
		echo ($_SESSION['wa_current_user']->company == 0 ? '<li><a href="'.$path_to_root.'/themes/onlinksoft/master-login.php"><i class="icon-lock_outline"></i> <span>Master Login </span></li>' : '');

	echo  "</ul></nav></div> </div> 
  				 <!-- End of Sidebar --> ";	// top status bar				
				if($sel_app == 'orders')
								$icon_root = 'monetization_on';
							elseif($sel_app == 'AP')
								$icon_root = 'add_shopping_cart';
							elseif($sel_app == 'stock')
								$icon_root = 'storage';
							elseif($sel_app == 'manuf')
								$icon_root = 'location_city';
							elseif($sel_app == 'assets')
								$icon_root = 'receipt';
							elseif($sel_app == 'proj')
								$icon_root = 'dialpad';
							elseif($sel_app == 'GL')
								$icon_root = 'account_balance_wallet';
							else
								$icon_root = 'settings';							

				echo '<div class="main-panel" id="main-panel">
			    <div class="navbar">
			      <div class="container-fluid">
			      <div class="left_menu" >
				  <!-- Sidebar Toggle Button -->
                    <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
                        <img src="'. $path_to_root.'/themes/onlinksoft/images/img_77200.png" alt="">
                    </a>
                    <!-- End of Sidebar Toggle Button -->
			      <a href="#header" onclick="toggleMenu();" class="toggle">  <i class=" icon-apps" > </i></a> 
			      <span class="left"> <i class="icon-'.$icon_root.'"></i>  '.(isset($title) ? $title : '').' </span>
			      <div style="clear:both;"> </div></div>
			       <div class="right_menu">
			      <div class="dropdown">
				  <button class="dropbtn"> <i class="icon-add"></i>Create</button>
				  <div class="dropdown-content">
				    <a href="'. $path_to_root.'/sales/sales_order_entry.php?NewInvoice=0">Sales Invoice</a>
				    <a href="'. $path_to_root.'/purchasing/po_entry_items.php?NewInvoice=Yes">Purchase Invoice</a>
				    <a href="'. $path_to_root.'/sales/manage/customers.php?">Customer</a>
				    <a href="'. $path_to_root.'/purchasing/manage/suppliers.php?">Supplier</a>
				  
				</div></div>';

      			include_once("$path_to_root/themes/".user_theme()."/notification.php");
            	$noti = new show_notification();
				echo '<ul id="menu">';					
					$noti->get_overdue_invoices();
					$noti->get_inventory_reorder();
					$noti->get_supplier_payments();			

			      if ($SysPrefs->help_base_url != null && $saai_options['hide_help_link'] == 0 ){	
				      echo '<li><a class="menutopright" onclick="javascript:openWindow(this.href,this.target); return false;" href="'. help_url().'"> <span class="icon-donut_large"></span></a></li>';
				  }
			     
				   echo '<li><a class="menutopright" href="'.$local_path_to_root.'/themes/onlinksoft/logout.php?"> <span class="icon-power_settings_new"></span></a></li>';
				 echo '</ul>
				 <div style="clear:both;"> </div>
				 </div>';
                 foreach($installed_extensions as $key => $single){
					if($single['package'] == 'ExtendedHRM' && $single['active']){
						$sql = "SELECT COUNT(`cv`.`empl_id`) FROM ".TB_PREF."kv_empl_cv AS cv  INNER JOIN ".TB_PREF."kv_empl_doc_type AS type ON `type`.`id` = `cv`.`doc_type` INNER JOIN ".TB_PREF."kv_empl_info AS info ON `cv`.`empl_id` = `info`.`empl_id` WHERE 1=1  AND cv.notify_from < '".date('Y-m-d')."'  ORDER BY cv.notify_from ASC ";
						$res = db_query($sql, "Can't get count");
						if($row = db_fetch_row($res)){
							if($row[0]> 0 ){
								echo ' <a class="right notification" href="'. $path_to_root.'/modules/ExtendedHRM/inquires/document_inquiry.php?" style="padding:0 5px;" > <span class="icon-description"></span><span class="count_doc"> '.$row[0].' </span></a> '; ?>
						    <style>
						    .count_doc {   position: absolute;    top: -15px;    height: 25px;	    vertical-align: top;    right: 180px;}
						    .notification .icon-description { background: #FFC107;   border-radius: 50%;   padding: 6px;  font-size: 1.5em; }
			    			</style> <?php 
							}
						}							
					}
				}
               echo '</div>
			    </div> 
			    <div class="content">';	
			}			
			if ($no_menu){	// ajax indicator for installer and popups
				echo "<center><table class='tablestyle_noborder'>"
					."<tr><td><img id='ajaxmark' src='$indicator' align='center' style='visibility:hidden;' alt='ajaxmark'></td></tr>"
					."</table></center> ";
					echo '<div class="content">';
			} elseif ($title && !$is_index)	{
				/*echo "<center><table id='title'><tr><td width='100%' class='titletext'>$title</td>"
				."<td align=right>"
				.(user_hints() ? "<span id='hints'></span>" : '')
				."</td>"
				."</tr></table></center>";	*/			
			}
			echo "<img id='ajaxmark' src='$indicator' align='center' style='visibility:hidden;' alt='ajaxmark'>";
		}

		function menu_footer($no_menu, $is_index){
			global $version, $path_to_root, $Pagehelp, $Ajax, $SysPrefs, $saai_options, $saai_version;

			include_once($path_to_root . "/includes/date_functions.inc");
			$app_title = isset($saai_options['powered_name']) ? $saai_options['powered_name'] : 'FrontAccounting';
			if(!$app_title)
				$app_title = 'onlinksoft';
			
			$powered_url = isset($saai_options['powered_url']) ? addhttp($saai_options['powered_url']) : false;
			if(!$powered_url)
				$powered_url = 'http://frontaccounting.com';			
			
			echo '<div style="clear: both;"></div></div></div></div></div>';

			if ($no_menu == false){

				if(isset($_GET['application']) && $_GET['application'] == 'stock')
					echo '</div>';
				echo '<footer class="footer">
            	<div class="container-fluid">
                <nav class="pull-left" style="padding-left:250px;">
                    <ul> <li     style="min-width: 250px;"> <a target="_blank" href="'.$powered_url.'" tabindex="-1">'.$app_title.' ';
					if($saai_options['hide_version']== 0 ){		echo $version;		}
			//	echo '</a> - <a href="http://www.onlinksoft.com" >  onlinksoft </a>' .show_users_online().' ';
					echo '</a> - <a href="http://www.Onlinksoft.com" >   تطوير و برمجة أون لينك سوفت </a>' .show_users_online().' ';
				if (isset($_SESSION['wa_current_user'])) {
					$phelp = implode('; ', $Pagehelp);
					$Ajax->addUpdate(true, 'hotkeyshelp', $phelp);
					echo "<span class='help_text'> ".$phelp." </span>";
				}
				echo '</li></ul>
                </nav>
                <p class="copyright pull-right"> Copyrights &copy; '.date('Y').' <a href="'.$powered_url.'" target="_blank"></a> </p>
            </div>
         </footer>';
    } echo ''; ?>
	<script>

	var toggleMenu = function(){
				var m = document.getElementById('sidebar'),
					c = m.className;
				  m.className = c.match( ' active' ) ? c.replace( ' active', '' ) : c + ' active';
				  var m = document.getElementById('main-panel'),
					c = m.className;
				  m.className = c.match( ' active' ) ? c.replace( ' active', '' ) : c + ' active';
			}		
	$('[data-toggle="push-menu"]').on( 'click', function() {
		$('body').toggleClass('sidebar-collapse');
	});

	function myFunction() {
		var x = document.getElementById("CompanyList");
		if (x.className.indexOf("w3-show") == -1) {
			x.className += " w3-show";
		} else { 
			x.className = x.className.replace(" w3-show", "");
		}
	}
	$(".ChangeCompany").on('change', function (e) {
		var Cid = $(this).val();			   		
		$.ajax({
			type: "POST",
			url: "<?php echo $path_to_root; ?>/themes/onlinksoft/includes/ajax.php?ChangeCompany="+Cid,
			data: 0,
			success: function(data){        
				if(data.trim()){
				    window.location.reload();				           
			   	}else{
			        alert("Failed to change". data);
			    }               
			}
		});
	});
				   
	$(document).ready(function() {

		$(".notificationLink").click(function() {
			//$(".notificationContainer").hide(300);
			$(this).next(".notificationContainer").fadeToggle(300);
			$(this).prev(".notification_count").fadeOut("slow");
			return false;
		});
		//Document Click hiding the popup 
		$(document).click(function() {
			$(".notificationContainer").hide();
		});
		//Popup on click
		/*$(".notificationContainer").click(function() {
			return false;
		});*/
	});
	</script>

	<?php if(get_company_pref('no_item_list') == 1 || get_company_pref('no_customer_list') ==1 || get_company_pref('no_supplier_list') == 1) { ?>
		<link rel="stylesheet" href="<?php echo $path_to_root.'/themes/onlinksoft/css/select2.min.css'; ?>">
		<script src="<?php echo $path_to_root.'/themes/onlinksoft/js/select2.full.min.js' ; ?>"></script>
		<script type="text/javascript">
				$(function() {
						<?php if(get_company_pref('no_item_list') == 1) {?>
						call_icodes_select2('stock_id');
					<?php } if(get_company_pref('no_customer_list')) {?>
						call_icodes_select2('customer_id');

					<?php } if(get_company_pref('no_supplier_list')) {?>
						call_icodes_select2('supplier_id');
					<?php } ?>					
				});
		</script>
	<?php } ?>
		<script type="text/javascript">			
		function icodes_theme_refresh_select2(){
			<?php if(get_company_pref('no_item_list') == 1) {?>
						call_icodes_select2('stock_id');
			<?php } if(get_company_pref('no_customer_list')) {?>
						call_icodes_select2('customer_id');
						call_icodes_select2('PARAM_2');
			<?php } if(get_company_pref('no_supplier_list')) {?>
						call_icodes_select2('supplier_id');
			<?php } ?>
			//call_icodes_select2('branch_id');
		}
		
		function call_icodes_select2(elementId){			
			if($("#"+elementId).length > 0 ){
				if(elementId == 'stock_id'){
					var type_string = $('#'+elementId).parent().next().next('img').attr('onclick');
					var index_pos = type_string.indexOf('type');
					type_string = type_string.substr(index_pos);
					index_pos = type_string.indexOf('&')-5;
					type_string = type_string.substr(5, index_pos);
				} else {
					var type_string = '';
				}
				$("#"+elementId).select2({
					allowClear :  true, 
					ajax : {
						url : "<?php echo $path_to_root.'/themes/onlinksoft/includes/ajax.php?search_dropdown='; ?>"+elementId+"&type="+type_string,
						dataType: 'json',
						delay : 250,
						processResults : function(data){
							return { results : data };
						},
						cache : true
					}
				});
			}
		}
		</script></div></div><?php 
		}
		function display_applications(&$waapp)	{
			global $path_to_root, $saai_options;

			$selected_app = $waapp->get_selected_application();
			if (!$_SESSION["wa_current_user"]->check_application_access($selected_app))
				return;

			if (method_exists($selected_app, 'render_index'))	{
				$selected_app->render_index();
				return;
			}

			if( (!isset($_GET['application']) || $_GET['application'] == 'dashboard' ) && $saai_options['hide_dashboard'] == 0){	
				require("dashboard.php");
			} else {
				echo '<div class="MenuPage"> ';
				$kv=1;
				foreach ($selected_app->modules as $module)	{
	        		if (!$_SESSION["wa_current_user"]->check_module_access($module))
	        			continue;
					// image
					if($kv == 1 ){
						echo '<button class="subHeaders active"> '.$module->name.'</button><div class="panel" style="display:block;" ><ul class="left">';
						$kv++;
					} else {
						echo '<button class="subHeaders "> '.$module->name.'</button><div class="panel" ><ul class="left">';
					}
					foreach ($module->lappfunctions as $appfunction){
						$img = $this->get_icon($appfunction->category);
						if ($appfunction->label == "")
							echo "&nbsp;<br>";
						elseif ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) {
							echo '<li>'.$img.menu_link($appfunction->link, $appfunction->label)."</li>";
						}						
					}
					echo "</ul>";
					if (sizeof($module->rappfunctions) > 0)	{
						echo "<ul class='right'>";
						foreach ($module->rappfunctions as $appfunction){
							$img = $this->get_icon($appfunction->category);
							if ($appfunction->label == "")
								echo "&nbsp;<br>";
							elseif ($_SESSION["wa_current_user"]->can_access_page($appfunction->access)) {
								echo '<li>'.$img.menu_link($appfunction->link, $appfunction->label)."</li>";
							}
							//elseif (!$_SESSION["wa_current_user"]->hide_inaccessible_menu_items())	{
								//echo '<li>'.$img.'<span class="inactive">'.access_string($appfunction->label, true)."</span></li>";
							//}
						}
						echo "</ul>";
					}
					echo "<div style='clear: both;'></div> </div>";
				}
				echo "</div> ";
			}	?><script>
				var acc = document.getElementsByClassName("subHeaders");
				for (i = 0; i < acc.length; i++) {
				  acc[i].addEventListener("click", function() {
					this.classList.toggle("active");
					var panel = this.nextElementSibling;
					if (panel.style.display === "block") {
					  panel.style.display = "none";
					} else {
					  panel.style.display = "block";
					}
				  });
				}
			</script> <?php 
  		}
	} ?>