<?php
	include_once(PATH_TO_ROOT."init.php");
	include_once(PATH_TO_ROOT."CRM/class/class.Language-Pack.php");
	include_once (PATH_TO_ROOT."CRM/_CRM_config.php");
	include_once(PATH_TO_ROOT."CRM/class/class.Permissions.php");


	if (!$UserSession or !$UserSession->IsLoggedIn()) { echo "attack!"; exit; } 
	unset($_SESSION['loadedPlugin']);
	unset($_SESSION['addedTabs']);
	
	$_SESSION['UserInfo']['mc_rootpath'] = WARPIT_WEBPROJECTS;
	
	$p = new Permissions($db);
	
	$dbConfigCapi = configLoader::loadConfig('capi');
	$dbConfigPaths = configLoader::loadConfig('paths');
	//var_dump();
	$sql = "SELECT  translate_key, translate_text 
				FROM  ".DB_WARPIT_MAIN."._languagePack 
					WHERE id_programme = 2 AND id_language = ".$dbConfigCapi['default-language']." AND sub_page = 'capi'";
	//echo $sql;
	$res = $db->SQLexecute($sql);
	while ($zad = $db->fetchAssoc($res)) $languagePack[$zad['translate_key']] = $zad['translate_text'];
	
	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
  <title>Elixor - mindIT</title>
  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/adapter/ext/ext-base.js"></script>
    <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/ext-all.js"></script>
   	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/resources/css/ext-all.css" />
  
  	<link rel="stylesheet" type="text/css" href="../_css/mainWarpit.css" />
  		<link rel="stylesheet" type="text/css" href="_css/mainCRM.css" />
   
     
	<script type="text/javascript">
    Ext.QuickTips.init();
	var selectedProject = 0;
	Ext.ux.IFrameComponent = Ext.extend(Ext.BoxComponent, {
     onRender : function(ct, position){
          this.el = ct.createChild({tag: 'iframe', id: 'iframe-'+ this.id, frameBorder: 0, src: this.url});
     }
	});
	
	var tb = new Ext.Toolbar({
		        	//hidden: true,
		        	items:
					[
					 <?php if($p->hasCRMPermission(24)){ ?>
					{
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px">Presence</div>',
			             iconCls: 'iconProjects',
			             scale: 'large',
			             width: 90,
			             iconAlign: 'top',
			             id: 'ProjectListMenu',
			           	 listeners: {
			           	 	click: function(a, b, c){
			           	 		CallScript('<?php echo CRM_RPATH; ?>_forms/window.presence.php');
			           	 	}
			           	 }
				    }
				   <?php }?>
				    <?php if($p->hasCRMPermission(23)){ ?> 
				    <?php if($p->hasCRMPermission(24)) echo ","; ?>{
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px">Orders</div>',
			             iconCls: 'iconAppointments',
			             scale: 'large',
			             width: 90,
			             iconAlign: 'top',			          
			             handler : function() {
			             	  r = Ext.getCmp('west-panel');		             				
			             	  r.collapse(); 
			             	  CallScript("_forms/orders/forms.Orders.php");
			             }
		            }<?php }?>
		             <?php if($p->hasCRMPermission(22)){ ?>
		             <?php if($p->hasCRMPermission(24) || $p->hasCRMPermission(23)) echo ","; ?>{
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px">Delivery</div>',
			             iconCls: 'iconDelivery',
			             scale: 'large',
			             width: 90,
			             iconAlign: 'top',			          
			             handler : function() {
			             	  r = Ext.getCmp('west-panel');		             				
			             	  r.collapse(); 
			             	  CallScript("_forms/delivery/forms.Delivery.php");
			             }
		            }
		            
		            <?php }?>
		            <?php  if($p->hasCRMPermission(35)){ ?>
		            <?php if($p->hasCRMPermission(24) || $p->hasCRMPermission(23) || $p->hasCRMPermission(22)) echo ","; ?>
					{
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px">Kartoteka</div>',
			             iconCls: 'iconProjects',
			             scale: 'large',
			             width: 90,
			             iconAlign: 'top',
			             id: 'KartotekaListId',
			           	 listeners: {
			           	 	click: function(a, b, c){
			           	 		CallScript('<?php echo CRM_RPATH; ?>_forms/kartoteka/window.selectPerson.php');
			           	 	}
			           	 }
				    }
				    <?php }?>
				    <?php if($p->hasCRMPermission(38)){ ?>
				    <?php if($p->hasCRMPermission(24) || $p->hasCRMPermission(23) || $p->hasCRMPermission(22) || $p->hasCRMPermission(35)) echo ","; ?>
		             {
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px">Delivery Contract</div>',
			             iconCls: 'iconProjects',
			             scale: 'large',
			             width: 90,
			             iconAlign: 'top',			          
			             handler : function() {
			             	  r = Ext.getCmp('west-panel');		             				
			             	  r.collapse(); 
			             	  CallScript('<?php echo CRM_RPATH; ?>_forms/deliveryContract/forms.deliveryContract.php');
			             }
		            }
		            <?php }?>
		            
		            ]});
		            
		            
		            
	Ext.onReady(function(){
  		
		var viewPort = new Ext.Viewport({
			layout:'fit',
			
			items:
			
	       new Ext.Panel({
            layout: 'border',
         	border: false,
         	id:'MainPanel',
				
	        title: ' <table border=0 width="100%" height="20" cellpadding=0 cellspacing=0 class="headerFont"><tr><td width=300>&nbsp;&nbsp;<b><?php echo $languagePack['login-user'];?></b> '+
	            <?php echo "'".$_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname']."'"; ?>
	            +'</td><td align=center>&nbsp;<img src=_img/elixor_logo.png height=20></td><td width=270 align=left><small><b><?php echo $languagePack['login-time'];?>:</b> '+
	             <?php echo "'".$_SESSION['UserInfo']['LastLogin']."'"; ?> +
	             '</small></td></tr></table>',
			       // unstyled : true,
 					tools:[
					{
						  id: 'maximize',
						  qtip: 'Full screen',
					  	  handler: function(evt, toolEl, panel, tc){						  		          
						  	if(toggleFullScreen())
						  	{
						  		if(!Ext.isIE)
						  		{
						  		toolEl.removeClass('x-tool-restore');
					    	  	toolEl.addClass('x-tool-maximize');	
					    	  	toolEl.addClass('x-tool-maximize-f');				    	  	
						  		}
						  	}		 
						  	else			        	  		
						  		if(!Ext.isIE)
						  		{		        	  		
					    	  	toolEl.removeClass('x-tool-maximize');
					    	  	toolEl.addClass('x-tool-restore');
					    	  	toolEl.addClass('x-tool-maximize-f');
						  		}
						  }							  			              
					},
					{
						  id: 'close',
						  qtip: 'Log Out',
						  handler: function(){			        	
						  	//CallScript('index.php',{logOut:'1'});
						  	document.location.href='index.php?logOut=1';
						  }	
					}				      
				],
			       
			tbar: tb,
            items: [
            // create instance immediately
           
            { 
			       
            	region: 'center',
                id: 'north2', // see Ext.getCmp() below
              	border: true,
              		
               // margins: '0 0 0 0',
                layout:'border',
				defaults: {
			  //  collapsible: true,
			    split: true
			    //bodyStyle: 'padding:15px'
				}
			,
			items: [
		
			
			
				   // title: 'Main Content',
				   mainTabPanel = new Ext.TabPanel({
					 
				   	collapsible: false,
				    border: false,
				    id : 'mainTabPanel',
				    enableTabScroll : true,
				    region:'center'
				  
				  
				  })
		
           ]},
          
           		new Ext.TabPanel({
           		//{
                region: 'east',
                id: 'west-panel', 
                split: true,
                minSize: 200,
                width:300,
               	collapseMode: 'mini',
                border: true,
                xtype           : 'tabpanel',
    			activeTab       : 0,
	    		enableTabScroll : true,
		    	resizeTabs      : false,
				minTabWidth     : 75
			
	              , items: 
	               
	               new Ext.grid.EditorGridPanel({
						loadMask: true,
						id:'StatisticGrid',
						
						title: 'Statistika',
						
						store: new Ext.data.Store({
							autoLoad: true,
							url: '../CRM/_forms/prisotnost/_ajax/ajax.statistics.php',
							reader: new Ext.data.JsonReader({
								root: 'rows',
								totalProperty: "results"
							},
								new Ext.data.Record.create([
									{ name: 'Statistika', type: 'string' },
									{ name: 'Stevilo', type: 'string' }
								])
							)		
						}),
						border: false,
						viewConfig:{
							forceFit: true
						},
						columns: [
							{ header: 'Statistika', dataIndex: 'Statistika' },
							{ header: 'Število', dataIndex: 'Stevilo', width: 30 }
						]
					})  
            })
           
           ]
        }) });
     
        
          
		  CallScript = function(loadData,parameters,callBack){
         	  Ext.Ajax.request({
         		 url    : loadData,
           		params: parameters,
           		async: false,
           		success: function(res,opt)
           		{
             		eval(res.responseText);
             		if(callBack!= null)
             		{
                 		callBack();
             		}
           		}
           		});
           
		  }
		 window.onbeforeunload = function(){ return ''; };
		  toggleFullScreen = function(){
			root = document.documentElement;
			if(Ext.isIE) // if it's Internet Explorer
            {
            	//var obj = new ActiveXObject("Wscript.shell");
            	//obj.SendKeys("{F11}");
            	Ext.Msg.show({
                	title:'Info',
                	msg: 'You are using a browser, which does not support this function. Please, press \'F11\' button on your keyboard instead.',
                	buttons: Ext.Msg.OK,
                	icon: Ext.MessageBox.INFO
                	}); 
            	return false;
            }
            else
            {
            	var fullScreenMode = (document.fullScreenElement && document.fullScreenElement !==     null) ||    // alternative standard method  
                (document.mozFullScreen || document.webkitIsFullScreen);
				
				if(!fullScreenMode) {
                	if (root.webkitRequestFullScreen) {
                    	root.webkitRequestFullScreen(window.Element.ALLOW_KEYBOARD_INPUT);
                	} else if (root.mozRequestFullScreen) {
                    	root.mozRequestFullScreen();
                	}
            	}
				else
				{
            		(document.webkitCancelFullScreen||document.mozCancelFullScreen||$.noop).apply(document);
				}
					
 			} 	
 			return fullScreenMode;
		}
    });
    </script>
    <!-- Empty script file...copy into it any response for easier debuging! -->
	
</head>
<body>
	<div id="tabTemporary" class="x-hide-display" >
	</div>
</body>
</html>