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

include_once (PATH_TO_ROOT."init.php");

$projectId = $_POST['projectId'];
$tableName = $_POST['tableName'];
$questionId = $_POST['questionId'];
//we use the same form to show uniqe cawi links!
$title = $tableName;
if($questionId)
$title .= ' - '. $db->get($tableName,$questionId,'q_name',DB_WARPIT_WEBCATI);
else if($id_site = $_POST['id_site'])
{
	$title .= " - links";
}
//iframe source without question ID and show together! we add those to on reloading!
$src = "survey/preview.php?".
		http_build_query(array('projectId' => $projectId,
								'tableName' => $tableName,
								'id_user' => $_SESSION['UserInfo']['id'],
								'preview'=>true,
								'id_language' => $_POST['id_language'],
								'id_site' => $id_site ),'','&');

$iframe = 'iPreview_'.$tableName.'_'.$questionId;
echo "var p = new Ext.Panel({
	title:'$title',
	iconCls:'RMicon_view_details',
	layout:'fit',";
//if($questionId)	
echo "RMconn: new RMajax({
		url: 'webcati/_ajax/buildQuestionare/ajax.buildQuestionnaire.php',
		params: {action : 'getNextQuestion',id_project: $projectId },
		success: function(resp){
			r = Ext.decode(resp.responseText);
			var f = document.getElementById('$iframe');
			p.qId = r.id;
			p.setTitle('$tableName - '+r.qName);
			if(f)
			{
				f.src = \"$src&questionId=\"+r.id
			}
		}
	}),
	qId: '$questionId',
	//buttons for moving between questions!
	tbar:[{
		iconCls:'x-tbar-page-first',
		tooltip:'First Question',
		scale:'small',
		handler:function(){
			p.RMconn.request({
				params: {
					qGet: 'first'
				}
			});
		}
	},{
		iconCls:'x-tbar-page-prev',
		tooltip:'Previous Question',
		scale:'small',
		handler:function(){
			p.RMconn.request({
				params: {
					qGet: 'previous',
					qId: p.qId
				}
			});
		}
	},{
		iconCls:'x-tbar-page-next',
		tooltip:'Next Question',
		scale:'small',
		handler:function(){
			p.RMconn.request({
				params: {
					qGet: 'next',
					qId: p.qId
				}
			});
		}
	},{
		iconCls:'x-tbar-page-last',
		tooltip:'Last Question',
		scale:'small',
		handler:function(){
			p.RMconn.request({
				params: {
					qGet: 'last'
				}
			});
		}
	}],
	listeners:{
		show: function(){
			var f = document.getElementById('$iframe');
			if(f)
				f.src = f.src
		}
	},
	closable:true,
	/*autoLoad:{
		url:'survey/index.php',lalalala
		params:{tableName:'$tableName',projectId:$projectId}
	}*/
	html: '<iframe id=\"$iframe\" width=100% height=100% src=\"$src&".http_build_query(array('questionId' => $questionId,
								'id_showTogether' => $_POST['id_showTogether']
								)). "\"></iframe>'
});
mainTabPanel.add(p).show();
"

?>