<?php
include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");

$compName = "PrisotnostUserGrid".$suffix;
$ajaxFilter = "CRM/_forms/prisotnost/_ajax/ajax.filteredUsers.php";
?>

Ext.ns('Ext.ux.grid');
Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, {
    processEvent : function(name, e, grid, rowIndex, colIndex){
        if (name == 'mousedown') {
            var record = grid.store.getAt(rowIndex);
            var field = grid.getStore().fields.itemAt(colIndex).name;
            record.set(this.dataIndex, !record.data[this.dataIndex]);
            Ext.Ajax.request({
            	url:'<?php echo $ajax;?>',
   				params: { 
   					action: 'update' ,
					id_tel	: record.data.id_tel,
				    field	: field,
					value 	: field == 'changedPresentation' ? (record.data.changedPresentation == true ? <?php echo $projectId;?> : 0) : (record.data.direct_marketing == true ? 1 : 0),
					projectId: '<?php echo $projectId;?>',
					table: '<?php echo WARPIT_CRM."._visitStatistic";?>',
					cati_location: <?php echo $cati_location;?>					
   				}
            });
            record.commit();
            return false; // Cancel row selection.
        } else {
            return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
        }
    },

    renderer : function(v, p, record){
        p.css += ' x-grid3-check-col-td'; 
        return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
    },

    init: Ext.emptyFn
});
Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);
Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;
Ext.grid.Column.types.checkcolumn = Ext.ux.grid.CheckColumn;


var sm = new Ext.grid.RowSelectionModel({
	singleSelect: true,
	listeners: {
		rowselect: function(row, index, record){
			Ext.getCmp('SubUserGrid<?php echo $suffix;?>').getStore().load({params: {id_tel: record.data.id_tel }});
			
			<?php if(!isset($_SESSION['CRM_login'])){?>
			if(record.data.tip_narocila == 5){
				Ext.getCmp('kreditCalcualte<?php echo $suffix;?>').enable();
			}else{
				Ext.getCmp('kreditCalcualte<?php echo $suffix;?>').disable();
			}
			if(record.data.nacin_pristopa != 0){
				Ext.getCmp('spremeniNarociloButton<?php echo $suffix;?>').enable();
				Ext.getCmp('activityButton<?php echo $suffix;?>').enable();
			}else{
				Ext.getCmp('spremeniNarociloButton<?php echo $suffix;?>').disable();
				Ext.getCmp('activityButton<?php echo $suffix;?>').disable();
			}
			<?php } else { ?>
				if(record.data.nacin_pristopa != 0)
					Ext.getCmp('activityButton<?php echo $suffix;?>').enable();
				else
					Ext.getCmp('activityButton<?php echo $suffix;?>').disable();
			<?php }?>
			if(Ext.getCmp('StatisticGrid')){
				Ext.getCmp('StatisticGrid').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje...");?>');
				Ext.getCmp('StatisticGrid').getStore().load({
					params: { 
						action: 'get',
						project_id: '<?php echo $projectId; ?>'
						<?php if(isset($dan)) echo ", dan: '$dan'";?>
						<?php if(isset($ura)) echo ", ura: '$ura'";?>
						<?php if(isset($cati_location)) echo ", cati_location: '$cati_location'";?>
					},
					callback: function(store, opt, success){
						if(success){
							Ext.getCmp('StatisticGrid').getEl().unmask();
						}
					}
				});
			}
		}
	}
});
var <?php echo $compName;?> = new Ext.grid.EditorGridPanel({
        canEdit: true,
    	store: new Ext.data.Store({
			url: '<?php echo $ajax;?>',			
			baseParams:{
				action: 'get',
				project_id: '<?php echo $projectId;?>'
				<?php if(isset($zipId)) echo ", zipId: '$zipId'";?>
				<?php if(isset($dan)) echo ", dan: '$dan'";?>
				<?php if(isset($ura)) echo ", ura: '$ura'";?>
				<?php if(isset($cati_location)) echo ", cati_location: '$cati_location'";?>
				<?php if(isset($filter)) echo ", filter: '".$filter."'"; ?>
			},
			sortInfo: {
			    field: 'oseba_1',
			    direction: 'ASC' // or 'DESC' (case sensitive for local sorting)
			},
			reader: new Ext.data.JsonReader({		
					root:'rows',
					totalProperty : "results"
				},
				new Ext.data.Record.create([
					{ name:"id", type: 'id' },
					{ name:"projectName", type:'string'},
				 	{ name:"id_tel", type: 'id' },
				 	{ name:"id_sub_tel", type: 'id' },
				 	{ name:"oseba_1", type:'string'},
				 	{ name:"gender", type:'int'},
				 	{ name:"posta", type:'string' },
				 	{ name:"kraj", type:'string' },
					{ name:"oseba_2", type: 'string' },
					{ name:"changedPresentation", type: 'bool'},
					{ name:"email", type: 'string' },
					{ name:"occupation", type: 'string' },
					{ name:"marital_status", type: 'string' },
					{ name:"birth_date", type: 'string' },
					{ name:"agent", type: 'string' },
					{ name:"direct_marketing", type: 'bool' },
					{ name:"phone1", type: 'string' },
					{ name:"phone2", type: 'string' },
					{ name:"phone3", type: 'string' },
					{ name:"nacin_pristopa", type: 'int' },	
					{ name:"cas_odhoda", type:'time' },
					{ name:"vzrok_odhoda", type: 'string'},
					{ name:"Termogram1", type: 'string'},
					{ name:"Termogram2", type: 'string'},
					{ name:"Kisik1", type: 'string'},
					{ name:"Kisik2", type: 'string'},
					{ name:"tip_narocila", type: 'int'}
				])
			)
    	}),
        id: '<?php echo $compName;?>',
        border: false,
        region: 'west',
      	columns: [
      		{
      			header: 'id_tel',
      			dataIndex: 'id_tel',
      			hidden: true
      		},{
      			header: 'id_sub_tel',
      			dataIndex: 'id_sub_tel',
      			hidden: true
      		},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "attendance_type_title","Način prisotnosti");?>', 
      			renderer : function(a, metaData, record) {
	                var st = Ext.getCmp('userCombo<?php echo $suffix;?>').getStore();
	                if(st.find('id',a) != -1){
	                	var r = st.getAt(st.find('id',a));
	                	if(a == 0)
	                		return "<span style='color:red'>"+r.data.value+"</span>";
	                	else
	                		return "<span style='color:green; font-weight: bold'>"+r.data.value+"</span>";
	                }else{
	                	return "<span style='color:red'>"+st.getAt(0).data.value+"</span>";
	                }
                },
      			editor: new Ext.form.ComboBox({ 
      				mode: 'local',
      				triggerAction: 'all',
      				editable: false,
      				id: 'userCombo<?php echo $suffix;?>',
      				lazyRender: true,
      				listeners:{
	      				focus: function(combo){
	      					if(combo.getValue() == 0 || combo.getValue == null)
	      						combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
	      				}
	      			},
      				store: new Ext.data.ArrayStore({
      					fields:['id', 'value'],
						data:[
							<?php 
								$k = array();
								$sql = "SELECT * FROM ".WARPIT_CRM."._attendanceType WHERE deleted = 0 ORDER BY orderBy";
								$res = $db->SQLexecute($sql);
								while($row = $db->fetchAssoc($res)){
									array_push($k, "['".($row['id']-1)."', '".$row['razmejre_naziv']."']");
								}
								echo implode(", ",$k); 
							?>
						  ]
      				}),
      				valueField: 'id',
      				displayField: 'value'
      			}), 
      			dataIndex: 'nacin_pristopa'
      		},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "project_title","Projekt");?>',
      			width: 150, 
      			sortable: true, 
      			id: 'c_project<?php echo $suffix;?>',
      			hidden: true,
      			renderer: function(value, meta, record){
      				return '<a href="#" class="x-link">'+value+'</a>';
      			},
      			dataIndex: 'projectName', 
      			editor: new Ext.form.TextField() 
  			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "name_title","Ime");?>',
      			width: 150, 
      			sortable: true, 
      			dataIndex: 'oseba_1', 
      			editor: new Ext.form.TextField() 
  			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "gender_title","Spol");?>', 
      			sortable: true, 
      			width: 70,
      			dataIndex: 'gender', 
      			renderer: function(a){
                	if(a=="1") return '<?php echo $LangPack->GetLabel("CRM_all", "male_gender_title","Moški");?>';
                	else if(a=="2") return '<?php echo $LangPack->GetLabel("CRM_all", "female_gender_title","Ženski");?>';
                },
                editor:{
	        	 	xtype: 'combo',
	        	 	id: 'IzbiraSpola',
	        	 	typeAhead: true,
	        	 	listeners:{
	      				focus: function(combo){
	      					if(combo.getValue() == 0 || combo.getValue == null)
	      						combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
	      				}
	      			},
	                triggerAction: 'all',
	                selectOnTab: true,
	        		store: [
	                            [1, '<?php echo $LangPack->GetLabel("CRM_all", "male_gender_title","Moški");?>'],
	                            [2, '<?php echo $LangPack->GetLabel("CRM_all", "female_gender_title","Ženski");?>']
	                       ]
        		} 
  			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "post_code_title","Pošta");?>',
      			dataIndex: 'posta', 
      			width: 50, 
      			editor: new Ext.form.NumberField()
  			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "city_title","Kraj");?>',
      			dataIndex: 'kraj', 
      			editor: new Ext.form.TextField()
  			},{
  				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "address_title","Naslov");?>',
  				width: 150, 
  				sortable: true, 
  				dataIndex: 'oseba_2', 
  				editor: new Ext.form.TextField()
			},{
  				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "agent_name","Agent");?>',
  				width: 150, 
  				sortable: true, 
  				dataIndex: 'agent'
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "other_termin_title","Z drugega termina");?>', 
      			sortable: true,
      			width: 110, 
      			dataIndex: 'changedPresentation',
      			xtype: 'checkcolumn'
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "email_title","Email");?>', 
				sortable: true, 
				dataIndex: 'email', 
				editor: new Ext.form.TextField({
					vtype: 'email'
				})
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "occupation_title","Poklic");?>', 
				sortable: true,
				hidden: true, 
				dataIndex: 'occupation', 
				editor: new Ext.form.TextField()
			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "martial_status_title","Zakonski stan");?>', 
      			sortable: true, 
      			dataIndex: 'marital_status', 
	      		renderer: function(a){
                	if(a==2) return '<?php echo $LangPack->GetLabel("CRM_all", "marital_status_maried_title","Poročen");?>';
                	else if(a==1) return '<?php echo $LangPack->GetLabel("CRM_all", "marital_status_single_title","Samski");?>';
                },
                editor:{
	        	 	xtype: 'combo',
	        	 	id: 'IzbiraStana<?php echo $suffix;?>',
	        	 	typeAhead: true,
	                triggerAction: 'all',
	                listeners:{
	      				focus: function(combo){
	      					if(combo.getValue() == 0 || combo.getValue == null)
	      						combo.setValue('<?php echo $LangPack->GetLabel("CRM_all", "select_option_title","Izberite...");?>');
	      				}
	      			},
	                selectOnTab: true,
	        		store: [
	                            [2, '<?php echo $LangPack->GetLabel("CRM_all", "marital_status_maried_title","Pročen");?>'],
	                            [1, '<?php echo $LangPack->GetLabel("CRM_all", "marital_status_single_title","Samski");?>']
	                       ]
        		}
            },{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "date_of_birth_title","Datum rojstva");?>', 
      			sortable: true, 
      			dataIndex: 'birth_date',
      			renderer: function(value){
      				if(value != null){
	      				var date = value.toString().split("-");
	      				if(date[1] == '00' || date[2] == '00'){
	      					if(date[0] != 0)
		      					return date[0];
	      				} else {
	      					return Ext.util.Format.date(value,'d.m.Y');
	      				}
      				}
      			},
      			editor: new Ext.form.DateField()
  			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "direct_marketing_title","Neposredno trženje");?>', 
      			sortable: true,
      			width: 110, 
      			dataIndex: 'direct_marketing',
      			xtype: 'checkcolumn'
      		},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "phone1_title","Telefon 1");?>', 
      			sortable: true, 
      			dataIndex: 'phone1', 
      			editor: new Ext.form.TextField()
  			},{
  				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "phone2_title","Telefon 2");?>', 
  				sortable: true, 
  				dataIndex: 'phone2', 
  				editor: new Ext.form.TextField()
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "phone3_title","Telefon 3");?>', 
				sortable: true, 
				dataIndex: 'phone3', 
				editor: new Ext.form.TextField()
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "termogram1_title","Termogram 1");?>', 
				sortable: true, 
				dataIndex: 'Termogram1', 
				editor: new Ext.form.TextField()
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "termogram2_title","Termogram 2");?>', 
				sortable: true, 
				dataIndex: 'Termogram2', 
				editor: new Ext.form.TextField()
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "oxygen1_title","Kisik 1");?>', 
				sortable: true, 
				dataIndex: 'Kisik1', 
				editor: new Ext.form.TextField()
			},{
				header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "oxygen2_title","Kisik 2");?>', 
				sortable: true, 
				dataIndex: 'Kisik2', 
				editor: new Ext.form.TextField()
			},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "departure_time_title","Čas odhoda");?>',
      			hidden: true,
      			dataIndex: 'cas_odhoda'
      		},{
      			header: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "departure_cause_title","Vzrok odhoda");?>',
      			hidden: true,
      			dataIndex: 'vzrok_odhoda',
      			editor: new Ext.form.TextArea()
      		}
        ],
        sm: sm,
        flex: 1,
        tbar:[{
        	xtpye: 'button',
        	text: '<?php echo $LangPack->GetLabel("CRM_all", "CRM_add_button","Dodaj"); ?>',
        	menu:{
        		xtype: 'menu',
        		items:[{
        			xtype: 'menuitem',
	        		text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "add_person_title","Dodaj novo osebo");?>',
		        	handler: function(){
		        		CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.addUser.php', { suffix: '<?php echo $suffix;?>', dan: '<?php echo $dan;?>', ura: '<?php echo $ura;?>', action: 'add', projectId: <?php echo $projectId;?>, cati_location: '<?php echo $cati_location;?>'});
		        	}
	        	},{
	        		xtype: 'menuitem',
	        		text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "add_escord_title","Dodaj spremljevalca");?>',
		        	handler: function(){
		        		var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
		        		if(sel[0] != null){
		        			var d = sel[0].data;
		        			CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.addUser.php', { suffix: '<?php echo $suffix;?>', dan: '<?php echo $dan;?>', ura: '<?php echo $ura;?>', action: 'addSub', projectId: <?php echo $projectId;?>, id_tel: d.id_tel, cati_location: '<?php echo $cati_location;?>'});
		        		}
		        	}
	        	}]
        	}
        },{
        	xtype: 'button',
        	text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "departure_time_button_title","Čas odhoda"); ?>',
        	hidden: true,
        	handler: function(){
        		var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
        		var last = <?php echo $compName;?>.getSelectionModel().last;
        		if(sel[0] != null){
        			var d = sel[0].data;
        			Ext.Ajax.request({
        				url: '<?php echo $ajax;?>',
        				params:{
        					action: 'updateDate',
        					id_tel: d.id_tel,
        					type: 2,
        					projectId: '<?php echo $projectId;?>'
        				},
        				success: function(resp, opt){
	    					Ext.getCmp('<?php echo $compName;?>').getStore().reload({callback: function(store, opt, success){
	    						if(success){
	    							<?php echo $compName;?>.getSelectionModel().selectRow(last);
	    							Ext.fly(<?php echo $compName;?>.getView().getRow(last)).scrollIntoView();
	    						}
	    					}});
        				}
        			});
        		}
        	}
        },{
			xtype: 'button',
			text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "attended_button","Prisotni"); ?>',
			iconCls: 'RMicon_user_group2',
			enableToggle: true,
			handler: function(){
				Ext.getCmp('<?php echo $compName?>').getEl().mask({msg:"<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje..."); ?>"});
				<?php echo $compName;?>.getStore().load({params: { prisotni: this.pressed }, callback: function(store, opt, success){
					if(success){
						Ext.getCmp('<?php echo $compName?>').getEl().unmask();
					}
				}});
			}
		}
		<?php if($p->hasPremission(WARPIT_PERMISSION_ONLY_INPUT_GROUP)){ 
			
			?>
			
		,{
			xtype: 'button',
			text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "change_order_title","Spremeni naročilo"); ?>',
			id: 'spremeniNarociloButton<?php echo $suffix;?>',
			iconCls:'RMicon_edit_record',
			handler: function(){
				var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
        		if(sel[0] != null){
        			var d = sel[0].data;
					CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.editOrder.php', {suffix: '<?php echo $suffix;?>', dan: '<?php echo $dan;?>', ura: '<?php echo $ura;?>', projectId: <?php echo $projectId;?>, id_tel: d.id_tel, cati_location: '<?php echo $cati_location;?>'});
				}
			}
		}
		<?php }?>
		,{
			xtype: 'button',
			text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "change_person_title","Spremeni osebo"); ?>',
			iconCls: 'RMicon_contact',
			handler: function(){
				var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
        		if(sel[0] != null){
        			var d = sel[0].data;
					CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.editUser.php', {suffix: '<?php echo $suffix;?>', dan: '<?php echo $dan;?>', ura: '<?php echo $ura;?>', projectId: <?php echo $projectId;?>, id_tel: d.id_tel, cati_location: '<?php echo $cati_location;?>'});
				}
			}
		}
		<?php
		if($p->hasCRMPermission(25)){
		?>
		,{
			xtype: 'button',
			text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "change_period_title","Zamenjaj termin"); ?>',
			iconCls: 'RMicon_contact',
			handler: function(){
				var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
        		if(sel[0] != null){
        			var d = sel[0].data;
					CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.changePeriod.php', {id_tel: d.id_tel, projectId: '<?php echo $projectId;?>', gridName: '<?php echo $compName;?>'});
				}
			}
		}
		<?php }?>,{
			xtpye:'button',
			text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "diagnostic_list","Diagnostični list"); ?>',
			handler: function(){
				CallScript('<?php echo CRM_RPATH;?>_forms/prisotnost/window.addDiagnosticList.php', { cati_location: <?php echo $cati_location;?>, dan: '<?php echo $dan;?>', ura: '<?php echo $ura;?>', projectId: '<?php echo $projectId;?>'});
			}
		},{
        	xtpye: 'button',
			id: 'activityButton<?php echo $suffix;?>',
			//disabled: true,
        	text: '<?php echo $LangPack->GetLabel("CRM_all", "CRM_activities_button","Aktivnosti kupca"); ?>',
        	listeners:{
    			click: function(comp){
    				var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
	        		if(sel[0] != null){
	        			var d = sel[0].data;
	        			Ext.Ajax.request({
	        				url: '<?php echo $ajax;?>',
	        				params:{
	        					action: 'canViewActivities',
	        					id: d.id,
	        					project_id: '<?php echo $projectId; ?>'
	        					<?php if(isset($dan)) echo ", dan: '$dan'";?>
								<?php if(isset($ura)) echo ", ura: '$ura'";?>
								<?php if(isset($cati_location)) echo ", cati_location: '$cati_location'";?>
	        				},
	        				success:function(resp, opt){
	        					var res = Ext.decode(resp.responseText);
	        					if(res.success){
	        						if(res.show){
	        							Ext.getCmp('showActivities<?php echo $suffix;?>').enable();
	        						}else{
	        							Ext.getCmp('showActivities<?php echo $suffix;?>').disable();
	        						}
	        					}
	        				}
	        			})
	        		}
    			}
    		},
        	menu:{
        		xtype: 'menu',
        		items:[{
        			xtype: 'menuitem',
	        		text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "add_activitie_title","Dodaj");?>',
		        	handler: function(){
			        	var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
			    		if(sel[0] != null){
			    			var d = sel[0].data;
			    			CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.addActivities.php', { id: d.id, gridName: '<?php echo $compName;?>'});
			    		}
		    		}
	        	},{
	        		xtype: 'menuitem',
	        		disabled: true,
	        		text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "preview_activities_title","Pregled");?>',
	        		id: 'showActivities<?php echo $suffix;?>',
		        	handler: function(){
		        		var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
		        		if(sel[0] != null){
		        			var d = sel[0].data;
		        			CallScript('<?php echo CRM_RPATH;?>_forms/prisotnost/window.previewActivities.php', { id: d.id, gridName: '<?php echo $compName;?>'});
		        		}
		        	}
	        	}]
        	}
        },
		'->'
		<?php
			if(!isset($_SESSION['CRM_login'])){
				?>
				,{
					text:'<?php echo $LangPack->GetLabel("CRM_attendance_panel", "credit_loan_button","Izračun kredita"); ?>',
					id: 'kreditCalcualte<?php echo $suffix;?>',
					disabled: true,
					handler: function(){
						var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
		        		if(sel[0] != null){
		        			var d = sel[0].data;
							CallScript('<?php echo CRM_RPATH; ?>_forms/prisotnost/window.calculateCredit.php', {suffix: '<?php echo $suffix;?>', userId: d.id, gridName: '<?php echo $compName;?>'});
						}
					}
				}
				
				<?php
			}
		?>
		
		,{
			text: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "delete_person_title","Odstrani osebo"); ?>',
			iconCls: 'RMicon_delete_user3',
			handler: function(){
				var sel = <?php echo $compName;?>.getSelectionModel().selections.items;
				if(sel[0] != null){
					var d = sel[0].data;
					Ext.Ajax.request({
						url: '<?php echo $ajax;?>',
						params:{
							action: 'canDelete',
							id_tel: d.id_tel
						},
						success: function(resp, opt){
							var res = Ext.decode(resp.responseText);
							if(res.success){
								Ext.Msg.confirm('<?php echo $LangPack->GetLabel("CRM_attendance_panel", "CRM_delete_message_title","Brisanje"); ?>', '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "CRM_delete_message_msg","Ali res želite izbrisati to osebo?"); ?> ('+d.oseba_1 +')', function(btn){
									if(btn == "yes"){
						    			Ext.Ajax.request({
						    				url: '<?php echo $ajax;?>',
						    				params: {
						    					action: 'delUser',
						    					id_tel: d.id_tel
						    				},
						    				success: function(resp, opt){
						    					<?php echo $compName;?>.getStore().reload();
						    					if(Ext.getCmp('StatisticGrid')){
							    					Ext.getCmp('StatisticGrid').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje..."); ?>');
													Ext.getCmp('StatisticGrid').getStore().load({
														params: { 
															action: 'get',
															project_id: '<?php echo $projectId; ?>',
															dan: '<?php echo $dan;?>',
															ura: '<?php echo $ura;?>',
															cati_location: <?php echo $cati_location;?>
														},
														callback: function(store, opt, success){
															if(success){
																Ext.getCmp('StatisticGrid').getEl().unmask();
															}
														}
													});
												}
						    				}
						    			});	
									}
								});
							}else{
								Ext.Msg.alert('<?php echo $LangPack->GetLabel("CRM_attendance_panel", "wrong_person_alert_title","Wrong Person"); ?>', '<?php echo addslashes($LangPack->GetLabel("CRM_attendance_panel", "wrong_person_alert_msg","You can't delete this person")); ?>');
							}
						}
					});
				}
			}
		}
		<?php if(!isset($_SESSION['CRM_login'])){ ?>
		, {
			xtype: 'checkbox',
			checked: true,
			id: 'searchCheckBox<?php echo $suffix;?>',
			boxLabel: '<?php echo $LangPack->GetLabel("CRM_attendance_panel", "checkbox_search_grid","Iskanje v gridu"); ?>',
			listeners:{
				check: function(comp,a,b){
					 Ext.getCmp('searcheValue<?php echo $suffix;?>').onTrigger1Click();
				}
			}
		}<?php }?>,	new Ext.form.TwinTriggerField({
        		trigger2Class:'x-form-clear-trigger',
        		trigger1Class:'x-form-search-trigger',
        		id: 'searcheValue<?php echo $suffix;?>',
        		<?php if(isset($filter)) echo "value: '".$filter ."',"; ?>
				onTrigger1Click:function(){
					var l = <?php echo $compName;?>.getStore();
					var sl = Ext.getCmp('SubUserGrid<?php echo $suffix;?>').getStore();
				 	l.baseParams.filter = this.getValue();
				 	sl.baseParams.filter = this.getValue();
				 	
				 	
				 	if(this.getValue() != ""){
				 		<?php if(!isset($_SESSION['CRM_login'])){ ?>
				 		if(!Ext.getCmp('searchCheckBox<?php echo $suffix;?>').checked){
					 		var grid = Ext.getCmp('<?php echo $compName;?>');
					 		grid.canEdit = false;
					 		var i = 0;
		       				var count = Ext.getCmp('<?php echo $compName; ?>').getTopToolbar().items.items.lenght;
		       				/*Ext.each(Ext.getCmp('<?php echo $compName; ?>').getTopToolbar().items.items, function(a){
			       					a.disable();
			       				i++;
		       				});*/
						 	grid.getColumnModel().setHidden(grid.getColumnModel().getIndexById('c_project<?php echo $suffix;?>'), false);
						 	
						 	Ext.getCmp('<?php echo $compName?>').getEl().mask({msg:"<?php echo $LangPack->GetLabel("CRM_all", "search_mask_text","Iskanje..."); ?>"});
							l.load({params: { action: 'filter'}, callback: function(records, operation, success){
								if(success){
									Ext.getCmp('<?php echo $compName?>').getEl().unmask();
								}
							}});
							
						 	
					 	}else{
					 		Ext.getCmp('<?php echo $compName?>').getEl().mask({msg:"<?php echo $LangPack->GetLabel("CRM_all", "search_mask_text","Iskanje..."); ?>"});
							l.load({callback: function(records, operation, success){
								if(success){
									Ext.getCmp('<?php echo $compName?>').getEl().unmask();
								}
							}});
							l.load({callback: function(records, operation, success){
                                if(success){
                                    Ext.getCmp('SubUserGrid<?php echo $suffix;?>').getEl().unmask();
                                }
                            }});
					 	}
					 	<?php } else {?> 
					 		Ext.getCmp('<?php echo $compName?>').getEl().mask({msg:"<?php echo $LangPack->GetLabel("CRM_all", "search_mask_text","Iskanje..."); ?>"});
							l.load({callback: function(records, operation, success){
								if(success){
									Ext.getCmp('<?php echo $compName?>').getEl().unmask();
								}
							}});
					 	<?php } ?>
					 	
				 		
						Ext.getCmp('SubUserGrid<?php echo $suffix;?>').getEl().mask({msg:"<?php echo $LangPack->GetLabel("CRM_all", "search_mask_text","Iskanje..."); ?>"});
						var s = Ext.getCmp('SubUserGrid<?php echo $suffix;?>').getStore();
					 	s.baseParams.filter = this.getValue();
						s.load({params: { dan: '<?php echo $dan;?>', ura: '<?php echo $ura;?>', cati_location: '<?php echo $cati_location;?>'},callback: function(records, operation, success){
							if(success){
								Ext.getCmp('SubUserGrid<?php echo $suffix?>').getEl().unmask();
							}
						}});
					}else{
						<?php if(!isset($_SESSION['CRM_login'])){ ?>
						if(!Ext.getCmp('searchCheckBox<?php echo $suffix;?>').checked){
							var grid = Ext.getCmp('<?php echo $compName;?>');
							grid.canEdit = true;
						 	grid.getColumnModel().setHidden(grid.getColumnModel().getIndexById('c_project<?php echo $suffix;?>'), true);
					 	}
					 	<?php }?>
						Ext.getCmp('<?php echo $compName?>').getEl().mask({msg:"<?php echo $LangPack->GetLabel("CRM_all", "search_mask_text","Iskanje..."); ?>"});
						l.load({callback: function(records, operation, success){
							if(success){
								Ext.getCmp('<?php echo $compName?>').getEl().unmask();
							}
						}});
					}
				},
				onTrigger2Click:function(){
					var l = <?php echo $compName;?>.getStore();
					delete l.baseParams.filter;
					this.setValue('');
					l.load({params: {action: 'get'}}); 
					
					var grid = Ext.getCmp('<?php echo $compName;?>');
					grid.canEdit = true;
				 	grid.getColumnModel().setHidden(grid.getColumnModel().getIndexById('c_project<?php echo $suffix;?>'), true);
					
					var s = Ext.getCmp('SubUserGrid<?php echo $suffix;?>').getStore();
				 	delete s.baseParams.filter;
				 	s.load();
				},
				listeners: {
	                specialkey: function(field, e){
	                    // e.HOME, e.END, e.PAGE_UP, e.PAGE_DOWN,
	                    // e.TAB, e.ESC, arrow keys: e.LEFT, e.RIGHT, e.UP, e.DOWN
	                    if (e.getKey() == e.ENTER) {
	                       field.onTrigger1Click();
	                    }
	                }
	            }
			})
         ],
       	listeners: {
       		beforeedit: function(e){
       			if(!e.grid.canEdit){
       				Ext.Msg.alert('<?php echo $LangPack->GetLabel("CRM_all", "warning_alert_title","Opozorilo"); ?>', '<?php echo $LangPack->GetLabel("CRM_all", "warning_alert_msg","Prosim kliknite na link od projekta za urejanje"); ?>');
       				return false;
       			}
       		},
       		afteredit : function(e) {
       			Ext.Ajax.request({
       				url:'<?php echo $ajax;?>',
       				params: { 
       					action: 'update' ,
						id_tel	: e.record.data.id_tel,
					    field	: e.field,
						value 	: e.value,
						oldValue: e.originalValue,
						cati_location: '<?php echo $cati_location;?>',
						projectId: '<?php echo $projectId;?>',
						table: '<?php echo WARPIT_CRM."._visitStatistic";?>'					
       				},
					success : function(resp,opt){ 
						//e.record.commit();
						e.grid.getStore().reload();
						if(Ext.getCmp('StatisticGrid')){
							Ext.getCmp('StatisticGrid').getEl().mask('<?php echo $LangPack->GetLabel("CRM_all", "loading_mask_text","Posodabljanje..."); ?>');
							Ext.getCmp('StatisticGrid').getStore().load({
								params: { 
									action: 'get',
									project_id: '<?php echo $projectId; ?>',
									dan: '<?php echo $dan;?>',
									ura: '<?php echo $ura;?>',
									cati_location: <?php echo $cati_location;?>
								},
								callback: function(store, opt, success){
									if(success){
										Ext.getCmp('StatisticGrid').getEl().unmask();
									}
								}
							});
						}
					}							  							
				})
			},
			cellclick: function(grid, rowIndex, columnIndex, e){
				var record = grid.getStore().getAt(rowIndex);
				
				if(e.getTarget('a.x-link', this.body)){
					Ext.Ajax.request({
						url: '<?php echo $ajaxFilter;?>',
						params:{
							action: 'getData',
							id: record.data.id,
							table: record.data.projectName
						},
						success: function(resp, opt){
							var data = Ext.decode(resp.responseText);
							addTabAuto('webPrisotnost_'+data.ura + '_' + data.dan,'CRM/_forms/prisotnost/forms.mainPanel.php', { projectId: data.projectId, zipId: data.smpl_var, dan: data.dan, ura: data.ura, cati_location: data.smpl_var, tabFilter: Ext.getCmp('searcheValue<?php echo $suffix;?>').getValue() });	
							
						}
					});	
				}
			}	
		}     
    });
<?php echo $compName; ?>.getStore().reload();  