<?php 

include_once("_dirinfo.php");
include_once(PATH_TO_ROOT."init.php");
$projectId = $_POST['projectId'];
$tableName = $_POST['tableName'];
$id_language = $_POST['id_language'];

$iframe = 'iPrint_'.$tableName;
$src = "survey/printQuestionnaire.php?".
		http_build_query(array('projectId' => $projectId,
								'tableName' => $tableName,
								'id_language' => $id_language,
								'ids' => $_POST['ids'] ));
if(!$id_language) $id_language = $db->get('_Projects',$projectId,'language',DB_WARPIT_WEBCATI_BASE);
$url = "webcati/_forms/_ajax/ajax.statistics.php";
echo "
	var srcParams = [0,false];
	var recordCombo = new Ext.form.ComboBox({xtype:'combo',store: new Ext.data.JsonStore({
		url:'$url',
		baseParams : {
			action: 'userRecords',
			id_project: $projectId
		},
		fields: ['id','name','flag_bad'],
		root:'rows'
	}),displayField:'name',valueField:'id',triggerAction:'all',mode:'local'
	  ,
		listeners:{
			'select': function(c,r){
				srcParams[0] = r.data.id;
				var f = document.getElementById('$iframe');
				if(f)
					f.src = '$src&id_record='+srcParams[0] + '&edit='+srcParams[1];
				this.ownerCt.confCombo.setValue( r.data.flag_bad == 101 ? 1 : 2  );
			}
		}  });

	
	var p = new Ext.Panel({
	title:'Print - $tableName',
	iconCls:'RMicon_printer',
	closable:true,
	listeners:{
		show: function(){
			var f = document.getElementById('$iframe');
			if(f)
				f.src = f.src
		}
	},
	tbar:['Watch: User',{xtype:'combo',store: new Ext.data.JsonStore({
		url:'webcati/_forms/_ajax/ajax.statistics.php',
		baseParams : {
			action: 'compareUsers',
			id_project: $projectId
		},
		fields: ['id','name'],
		autoLoad:true,root:'rows'
	}),
		listeners:{
			'select': function(c,r){
				recordCombo.store.reload({
					params: {
						id_record: r.data.id
					}
				});
				
			}
		},displayField:'name',valueField:'id',triggerAction:'all'  },' Record: ',
	recordCombo,
	' Confirmed:',
	{
		xtype:'combo',
		ref:'confCombo',
		store:[[1,'Yes'],[2,'No']],
		editable:false,
		triggerAction:'all',
		RMconn:new RMajax({
			url:'$url',
			params : {
			action: 'confirmRecord',
			id_project: $projectId
			}
			
		}),
		listeners:{
			'select':function(c,r)
			{
				var zzz = recordCombo.store.getById(recordCombo.getValue());
				if(!zzz) return;
				zzz.data.flag_bad = this.getValue() == 1 ? 101 : 99;
				
				this.RMconn.request({
					params: {
						id_record:recordCombo.getValue(),
						value:this.getValue()
					}
				});
			}
		}
	},
	{
		text:'Edit',
		iconCls:'RMicon_edit_record',
		enableToggle:true,
		toggleHandler:function(b,s){
			var f = document.getElementById('$iframe');
				srcParams[1] = s;
				if(f)
					f.src = '$src&id_record='+srcParams[0] + '&edit='+srcParams[1];
		}
	}
	],
	html: '<iframe id=$iframe width=100% height=100% src=\"$src\"></iframe>'
});
mainTabPanel.add(p).show();
"

?>