<?php

$cid = explode('.', $_SERVER['HTTP_HOST'])[0];
$sql = "SELECT * FROM config_template WHERE status=1";
$template = db_query($sql);
$temp = mysqli_fetch_object($template);

if($temp->template_id==1){?>

    <nav class="navbar navbar-expand-lg navbar-light bg-light mb-1 navbar-fixed-top" style="height: 60px !important;" >
        <div class="button-bar ml-0"> <button type="button" id="collapse_sidebar" style="text-align:center" onclick="collapse_sidebar()"><em class="fa fa-caret-left fa-1x" style="line-height:2;"></em ></button>
            <button type="button" id="extract_sidebar"  aria-label="Extract Sidebar" style="text-align:center;display:none" onclick="extract_sidebar()"><em class="fa fa-caret-right fa-2x"></em ></button></div>
        <div class="container-fluid">

            <div class="navbar-header">
                <span style="font-weight:bold;"><?=find_a_field('user_group','group_name','id='.$_SESSION['user']['group']); ?></span>

                <p class="company_name m-0">
                    <?=find_a_field('warehouse','warehouse_name','warehouse_id='.$_SESSION['user']['depot']);?>



                </p>

            </div>



            <div class="clear"></div>

            <div class="userblock" style="right:248px!important;">

                <div id="avatar-upload" class="right circle">

                    <div class="image-overlay dz-message"></div>

           	
					       <? 
						     $find = find_a_field('user_activity_management','user_pic','user_id="'.$_SESSION['user']['id'].'"');
							 
							 if($find!=""){ ?>
							<img src="../../../../public/assets/images/user.png" class="userimg" alt=""/>
							
					        <? }else{ ?>
                           <img src="../../../../public/assets/images/user.png" class="userimg" alt=""/>
                            <? } ?>
                </div>



                <div id="user-settings-overlay" class="userdetail right vertical-centre">

                    <div class="username">

                        <?
                        $user_info = find_all_field('user_activity_management','fname','user_id='.$_SESSION['user']['id']);
                        echo $user_info->fname;
                        ?>            </div>

                    <div class="company_name">
                        <?=$user_info->designation;?>
                    </div>
                    <div class="company_name">
                        <??>
                    </div>


                </div>

            </div>








            <div class="clear"></div>



            <div class="notificationblock" style="right:163px!important;">

                <a href="../../../views/auth/eProc/logout.php" class="help_tooltip" data-toggle="tooltip" data-placement="bottom" data-original-title="Signout"><em class="fas fa-sign-out-alt"></em ></a>
            </div>

            <div id="clock" style="right:12px!important; width: 145px;">
                <span class="date" style="overflow: hidden!important;">{{ date }}</span>
                <span class="time" style="overflow: hidden!important;">{{ time }}</span>
         
            </div>



        </div>

    </nav>


    <?php
}


elseif($temp->template_id==2){?>

    <nav class="navbar navbar-expand-lg navbar-light bg-light m-0 pl-0 navbar-fixed-top" style="height: 60px !important;" >
        <div class="button-bar ml-0"> <button type="button" id="collapse_sidebar" style="text-align:center" onclick="collapse_sidebar()"><em class="fa fa-caret-left fa-1x" style="line-height:2;"></em ></button>
            <button type="button" id="extract_sidebar"  aria-label="Extract Sidebar" style="text-align:center;display:none" onclick="extract_sidebar()"><em class="fa fa-caret-right fa-2x"></em ></button></div>

        <div class="sidemenu ml-0">
			<em class="open fa-duotone fa-circle-chevron-left"></em >
			<em class=" close1 fa-solid fa-circle-chevron-right"></em >
           
       
        </div>

        <div class="container-fluid">
            <div class="navbar-header" style=" margin-left: 8px;">

                <span  class="theme_color" style="font-weight:bold;">
                <?      if($_SESSION['user_type'] == 'vendor'){?>
                    <a class="nav-link menu-option " href="../../../views/vendor_mod/eProc_vendor/vendor_entry.php"><img src="../../../../public/assets/images/logo/default_logo.png" class="userimg" alt="" style=" width: 60px; height: 60px; "/></a>
				<?} if ($_SESSION['user_type'] == 'admin'){?>
                    <a class="nav-link menu-option " href="../../../views/eProcurement_mod/eProcurement/eprocurement_entry.php"><img src="../../../../public/assets/images/logo/default_logo.png" class="userimg" alt="" style=" width: 60px; height: 60px; "/></a>


                <?}?>
				</span>

                <p class="company_name theme_color m-0">
                  
                </p>
            </div>


            <div class="clear"></div>
            <div class="userblock" style="right:300px">
                <div id="avatar-upload" class="right circle">
                    <div class="image-overlay dz-message"></div>
					
	
					
					       <? 
						     $find = find_a_field('user_activity_management','user_pic','user_id="'.$_SESSION['user']['id'].'"');
							 
							 if($find!=""){ ?>
                        
							<img src="../../../../public/assets/images/user.png" class="userimg" alt=""/>
							
					        <? }else{ ?>
                           <img src="../../../../public/assets/images/user.png" class="userimg" alt=""/>
                            <? } ?>
							
							
					
                </div>

                <div id="user-settings-overlay" class="userdetail right vertical-centre theme_color">

                    <p class="username m-0 pr-5" style="font-size: 14px;">

                        <?
                       if ($_SESSION['user_type'] == 'admin'){
                        $user_info = find_all_field('user_activity_management','fname','user_id='.$_SESSION['user']['id']);
                        echo $user_info->fname;
                       }
                       if($_SESSION['user_type'] == 'vendor'){
                        //  echo "ddddddddddddddd".$_SESSION['vendor']['id'];
                        $user_info = find_all_field('vendor','email','vendor_id='.$_SESSION['vendor']['id']);
                        echo $user_info->vendor_name;
                       }
                        
                        ?>            </p>

                    <p class="company_name m-0 p-0">
                        <?=$user_info->designation;?>
                    </p>
                </div>
            </div>





            <div class="clear"></div>
            <div class="notificationblock" >
                <a href="#" class="bell-massage" data-toggle="tooltip" data-placement="bottom" data-original-title="Notifications">
                    <span class="badge animated zoomIn"></span>
                    <em class="fas fa-bell"></em >
                </a>

                <a href="#" class="bell-massage" data-toggle="tooltip" data-placement="bottom" data-original-title="massage">
                    <span class="badge animated zoomIn"></span>
                    <em class="fas fa-envelope"></em >
                </a>

<? if ($_SESSION['user_type'] == 'admin'){?>
                <a href="../../../views/auth/eProc/logout.php" class="sing-out" data-toggle="tooltip" data-placement="bottom" data-original-title="Signout">
                    <em class="fas fa-sign-out-alt"></em >
                </a>
<? } elseif($_SESSION['user_type'] == 'vendor'){?> 
               
                <a href="../../../views/vendor_mod/eProc_vendor/update_pass.php" title="Change Password" class="sing-out" data-toggle="tooltip" data-placement="bottom" data-original-title="Signout">
                    <em class="fas fa-lock"></em >
                </a>
                <a href="../../../views/auth/vendor/logout.php" class="sing-out" data-toggle="tooltip" data-placement="bottom" data-original-title="Signout">
                    <em class="fas fa-sign-out-alt"></em >
                </a>
<? } else{?> 
                <a href="../../../views/auth/masters/logout.php" class="sing-out" data-toggle="tooltip" data-placement="bottom" data-original-title="Signout">
                    <em class="fas fa-sign-out-alt"></em >
                </a>
<? } ?>
            </div>


			
			<div class="today-clock">
			  	<div id="today_date"></div>
			  	<div id="now_time"></div>
           
            </div>



        </div>
    </nav>

 
    <script>
        let menuToggle = document.querySelector('.sidemenu');
        let sidebar = document.querySelector('.sidebar');
        let main_content = document.querySelector('.main_content');
        let left1 = document.querySelector('.left1');
        menuToggle.onclick = function(){
            menuToggle.classList.toggle('active');
            sidebar.classList.toggle('active');
            main_content.classList.toggle('active');
            left1.classList.toggle('active');
        }
    </script>



  <script>
    function updateTime() {
      try {
        const now = new Date();
        const dateElement = document.getElementById('today_date');
        const timeElement = document.getElementById('now_time');

        if (!dateElement || !timeElement) {
          throw new Error('Required elements not found.');
        }

        const options = { weekday: 'short', day: '2-digit', month: 'short', year: 'numeric' };
        const formattedDate = now.toLocaleDateString('en-US', options).replace(',', '.');

        const formattedTime = [
          String(now.getHours()).padStart(2, '0'),
          String(now.getMinutes()).padStart(2, '0'),
          String(now.getSeconds()).padStart(2, '0')
        ].join(':');

        dateElement.textContent = formattedDate;
        timeElement.textContent = formattedTime;
      } catch (error) {
        console.error('An error occurred while updating the time:', error);
      }
    }

    updateTime(); // Call immediately to avoid delay on first load
    setInterval(updateTime, 1000);
  </script>
  
  
  
    <?php
}


else{

    echo "No records matching.";
}

?>


