<?php

	include_once(PATH_TO_ROOT."/mystery/init.php");
	
		
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
  <title>Mystery</title>
  	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/resources/css/ext-all.css" />
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    
  	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>mystery/_css/mainMystery.css" />
   
    <?php if ($_SESSION['UserInfo']['debugMode'] == 1) { ?>
     <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/adapter/ext/ext-base-debug.js"></script>
    <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/ext-all-debug.js"></script>
    <?php } else { ?>
     <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>
	<?php } ?>
	   <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.FileUploadField.js"></script>
    
    <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/MultiSelect.js"></script> 
     <link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/css/MultiSelect.css"/>
    
      	 <!-- for grid filtering! -->
  	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/css/GridFilters.css" />
  	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/css/RangeMenu.css" />
  	
  	<!-- WARNING: ListMenu vas edited (versiont ext303), for combobox filtering... 
  	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/menu/ListMenu.js"></script>-->
  	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/uxFixes/ListMenu.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/menu/RangeMenu.js"></script>
	
  	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/GridFilters.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/filter/Filter.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/filter/StringFilter.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/filter/DateFilter.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/filter/ListFilter.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/filter/NumericFilter.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/gridfilters/filter/BooleanFilter.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/RowLayout.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/CenterLayout.js"></script>
    
    
    
    <!-- Tree Grid -->
		
		<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/treegrid.css" rel="stylesheet" /> 
        
        <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/TreeGridSorter.js"></script> 
        <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/TreeGridColumnResizer.js"></script> 
        <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/TreeGridNodeUI.js"></script> 
        <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/TreeGridLoader.js"></script> 
        <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/TreeGridColumns.js"></script> 
        <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>extjs/examples/ux/treegrid/TreeGrid.js"></script> 
	
		 <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.GridArrowKeys.js"></script>
	
	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.grid.RowActions.css">
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.util.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.grid.Search.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.grid.RowActions.js"></script>
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.grid.RecordForm.js"></script>
	
	<link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.grid.CellActions.css">
	<script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.ux.grid.CellActions.js"></script>
	
    
     <script type="text/javascript" src="<?php echo PATH_TO_ROOT;?>_plugins/Ext.RMmain.js"></script> 
	
	 <link rel="stylesheet" type="text/css" href="<?php echo PATH_TO_ROOT;?>_css/mainWarpit.css" />
	
	
	
	<script type="text/javascript">

	

    
	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});
          
     }
	});

	<?php include (PATH_TO_ROOT.'mystery/_forms/tree.groups.php'); ?>
	<?php include (PATH_TO_ROOT.'mystery/_forms/forms.visits.php'); ?>

	//combobox za statuse   
	//extjs fucking sux it sux balls so much that balls suck!
	//neki ga jebe toti kurac pri filtrih zato mu dam posebej, kurac od extjs
	pregledStatusComboStoreData = [[1,'<?php echo $languagePack['potvrdjena_status']?>'], [2, '<?php echo $languagePack['zavrsena_status']?>'], [3, '<?php echo $languagePack['planirana_status']?>']];
	pregledStatusComboStore = new Ext.data.ArrayStore({
        id: 0,
        fields: [
            'id',
            'name'
        ],
        autoDestroy:false,
        data: pregledStatusComboStoreData
    });
	
	
	var tb = new Ext.Toolbar({
		        	//hidden: true,
		        	items:
					[
			        {
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px"><?php echo $languagePack['pocetna'];?></div>',
			             iconCls: 'iconInstructions',
			             scale: 'large',
			             iconAlign: 'top',
			             width: 80,
			             handler: function () {
			             	checkComponent = Ext.getCmp('StartBlogPanel');
			             	if (checkComponent) checkComponent.show();
			             	else {
			             	 mainTabPanel.add({
									title:'<?php echo $languagePack['pocetna'];?>',
									iconCls:'iconInfoSmall',
									id: 'StartBlogPanel',
									html:'<Br /><Br /><center><img src=../../webProjects/masmi_mystery_logo.jpg border=0><br /><br /><div id="WelcomeBlog" style="height:600px; width:800px"></div></center>',
									closable:true,
									border: false
							  }).show();
							  CallScript("_forms/grid.start-page-blog.php");
			             	}
			             }
			            
			         },'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
			          {		         	
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px"><?php echo $languagePack['pregled_poseta'];?></div>',
	    	           
			             iconCls: 'iconVisitList',
			             scale: 'large',
			             width: 80,
			             iconAlign: 'top',			           
		            	 handler : function() {
		            	 		 
							if( Ext.getCmp('pregledPosetaTabId'))	Ext.getCmp('pregledPosetaTabId').show()
								else {
				        	 			CallScript('_forms/forms.pregledPoseta.php',
				        	 				{ 
						        	 			projectIds: Ext.getCmp('MysteryProjects').getChecked('id').join(),
						        	 			
												tabId:'pregledPosetaTabId',
												title:'<?php echo $languagePack['pregled_poseta'];?>'
					        	  			});         	 			
		            	 			} 
		            	 	}
		            	 				             				            	   
		           	 },
		        	 {		         	
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px"><?php echo $languagePack['pojedinacni_izvestaji'];?></div>',
	    	           
			             iconCls: 'iconReportSingle',
			             scale: 'large',
			             width: 80,
			             iconAlign: 'top',			           
		            	 handler : function() 
		            	 			{	 
        	 							if(!Ext.getCmp('MysteryVisits').rendered) return;
		    			             	var rec = Ext.getCmp('MysteryVisits').selModel.getSelectedNode();
		    			             	if(rec && rec.attributes.leaf)
		    			             	{
			    			             	CallScript('_forms/forms.report.php',{id_project:rec.attributes.id_project,id_record:rec.attributes.id_structure})
		    			             	}
		    			             	else if(rec)
		    			             	{
			    			             	if(Ext.getCmp('singleReportTabId'))
			    			             		Ext.getCmp('singleReportTabId').show();
			    			             	else
		    			             			CallScript('_forms/forms.pregledPoseta.php',{visitsFolder:rec.attributes.id,
													tabId:'singleReportTabId',
													title:'<?php echo $languagePack['pojedinacni_izvestaji'];?>'
			    			             			 });
		    			             	}	
		            	 			} 			             				            	   
		            },
					 {		         	
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px"><?php echo $languagePack['total_report'];?></div>',
	    	           
			             iconCls: 'iconReport',
			             scale: 'large',
			             width: 80,
			             iconAlign: 'top',			           
		            	 handler : function() 
		            	 			{
		            	 				// we check which tab is activated and then we do total report on active tab
		            	 				if (westPanel.getActiveTab().id == "webCatiUniqePanel") {
							            	var rec = Ext.getCmp('MysteryProjects').getChecked();
							            	for(var i=0;i<rec.length;i++)
							             	if(rec[i].attributes.leaf)
							             	{
								             	CallScript('_forms/forms.report.php',{id_project:rec[i].attributes.id})
							             	}
		            	 				} else {
							             	// we check also if we have some tiem selected in visit tree
							             	VisitTree = Ext.getCmp('MysteryVisits');
			  								SelectedNode = VisitTree.getSelectionModel().getSelectedNode();	
			  								//console.log(SelectedNode);
			  								if (SelectedNode != null) CallScript('_forms/forms.report.php',{id_visit : SelectedNode.id });
		            	 				}
		  									
		            	 			} 			             				            	   
		            },
		        	 {		         	
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px"><?php echo $languagePack['statistics'];?></div>',
	    	           
			             iconCls: 'iconBuildQuest',
			             scale: 'large',
			             width: 80,
			             iconAlign: 'top',			           
		            	 handler : function() 
		            	 			{
		            				CallScript('_forms/forms.statistics.php',{})
		            	 			} 			             				            	   
		            },
		            '->',
		        	
		            {
			             xtype:'button',
			             text: '<div style="font-size:12px; font-weight:bold; padding-top:10px"><?php echo $languagePack['help'];?></div>',
			             iconCls: 'iconHelpLarge',
			             scale: 'large',
			             iconAlign: 'top',
			             width: 100,
			             style: 'padding-right:5px',
		            	 handler : function() {
			             		mainTabPanel.add(new Ext.ux.IFrameComponent({ 
				             						closable: true, 
				             						title: '<?php echo $languagePack['help'];?>', 
				             						iconCls:'iconHelpSmall',
				             						id: 101, 
				             						url: '<?php echo $dbConfigTGI['help-link'];?>' 
				             					})
				             	).show(); 
			             }  
		            }
	            
		            ]});
		            
		            
		            
	Ext.onReady(function(){
		
		
		var viewPort = new Ext.Viewport({
			layout:'fit',
			
			items:
			
	       	new Ext.Panel({
	            layout: 'border',
	         	border: false,
	         	id:'MainPanel',
					<?php
						// checking for flag image.... 
						if (file_exists(PATH_TO_ROOT.'_img/flags/flags_'.$_SESSION['UserInfo']['language'].'.png')) $countryFlag = $_SESSION['UserInfo']['language']; else $countryFlag = 0;
					?>
		            title: ' <table border=0 width="100%" height="20" cellpadding=0 cellspacing=0 class="headerFont"><tr><td width=300>&nbsp;<b><?php echo $_SESSION['UserInfo']['country_code'];?></b>&nbsp;<img src="<?php echo PATH_TO_ROOT;?>_img/flags/flags_<?php echo $countryFlag; ?>.png">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><?php echo $languagePack['login-user'];?></b> '+
		            <?php echo "'".$_SESSION['UserInfo']['Firstname']." ".$_SESSION['UserInfo']['Surname']." '"; ?>
		            +'</td><td valign=middle align=center><table cellpadding=0 cellspacing=0><tr><td><a onclick=\"if (tb.isVisible())  tb.hide(); else tb.show();  Ext.getCmp(\'MainPanel\').doLayout();\" href=#><img src=<?php echo PATH_TO_ROOT;?>_img/znakec.png>&nbsp;&nbsp;<b>WARP-IT</b></a></td></tr></table></td><td width=270 align=right><b><?php echo $languagePack['login-time'];?>:</b> '+
		             <?php echo "'".$_SESSION['UserInfo']['LastLogin']."'"; ?> +
		             '</small></td><td width=40 align=right><a onclick="window.onbeforeunload=function(){ };" href=?logOut=1><img id=btn1-ct src=<?php echo PATH_TO_ROOT;?>_img/logOut.png></a>&nbsp;&nbsp;</td></tr></table>',
				       // unstyled : true,
				        tbar: tb,
			            items: [{ 
			            	region: 'center',
			                id: 'north2',
			              	border: true,
			                layout:'border',
							defaults: {
						    	split: true
							}
							,
							items: [
							   // title: 'Main Content',
							   mainTabPanel = new Ext.TabPanel({
								   	collapsible: false,
								    border: false,
								    id : 'mainTabPanel',
								    enableTabScroll : true,
								    region:'center',
								    activeTab:0
								    
								    ,
								    items:[]
							  })
					
			           		]
				           	},
			           		westPanel = new Ext.TabPanel({
				           		title : 'Sklopi',
				                region: 'east',
				                id: 'west-panel', 
				                split: true,
				                minSize: 200,
				                width:300,
				               	collapseMode: 'mini',
				                //border: true,
				              	activeTab       : 0,
					    		//enableTabScroll : true,
						    	//resizeTabs      : false,
								//minTabWidth     : 75,
								items: [	
									webCatiUniqePanel,
									visitsUniqePanel							
								]
			            	})
			           ]
			    })
	      });

			
	      
		  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();
             		}
           		}
           		});
           
		  }
		  mainTabPanel.add({
				title:'<?php echo $languagePack['pocetna'];?>',
				iconCls:'iconInfoSmall',
				id: 'StartBlogPanel',
				html:'<Br /><Br /><center><img src=../../webProjects/masmi_mystery_logo.jpg border=0><br /><br /><div id="WelcomeBlog" style="height:600px; width:800px"></div></center>',
				closable:true,
				border: false
		  }).show();
		  CallScript("_forms/grid.start-page-blog.php");
		 <?php 
			 // autoloading view of visit
			 // this is happening when someone is adding comment on project 
			 // and persons who recieved informational email click on link  
			 if ($_GET['loadComment']) {
			 	$data = explode(",",$_GET['loadComment']);
			 	echo " CallScript(\"_forms/forms.report.php\",{id_project:".$data[0].",id_record:".$data[1]."});";
			 }
		 ?> 
		 
	
	});    
	 </script>
	
</head>
<body>
	<div id="tabTemporary" class="x-hide-display" >
	</div>
</body>
</html>