<?php
include("_dirinfo.php");
include(PATH_TO_ROOT.'init.php');
include (PATH_TO_ROOT.'_class/createQuestion/Question.php');

$tip = $_POST['tip'];

$test = Question::createQuestion($tip,$db);
$test->createAnswerGrid();
/*
//include (PATH_TO_ROOT."init.php");
include_once (PATH_TO_ROOT."_class/class.Extjs_grid.php");
	

	$name = $_POST['name'];
	$gridName = $_POST['gridName'];
	$tableName = $_POST['tableName'];
	$dataBase = $_POST['dataBase'];
	$data =  $_POST['data']  ;
	$tabName = stripcslashes( $_POST['tabName']);
	$title = $_POST['title'];
	$dataIndex = $_POST['dataIndex'];
	$id = $_POST['id'];
	
	$grid = new MakeGrid();
	
	$grid->setGridName($_POST['name'])

//	$grid->setDatabase('Warpit_delo');
	->setTitle($title)
	->dataArray = "slashDelimitedToArray('$data');";
	;
	
	$grid->addColumn('pos','Position','new Ext.form.NumberField()','int' )->defaultValue('"+ lastRow == 0 ? 1 : ( parseInt(tmpStore.getAt(lastRow-1).data.pos) + 1 ) +"');
					  ;
	$grid->addColumn('ans','Answer','new Ext.form.TextField()')->defaultValue('')->setProperty('tpl','new Ext.XTemplate("<div>nekivezipezimezi</div>")');

	$grid//->setSort('pos')
	->setAutoExpand('ans')
	->addButton('Save',"function(){
	var str = new Array();
	{$grid->getName()}.getStore().each(function(rec){
			str.push(rec.data.pos +' '  + rec.data.ans);
		});
	Ext.Ajax.request(
					{url:'_ajaxManipulators/formDataManipulator.php',params:{action:'update',RMtable:'$tableName',
					id:$id,database:'".$dataBase."',field:'$dataIndex'
					,value:str.join('/') }
					,success:function(){  Ext.getCmp('$gridName').getStore().reload();
					Ext.getCmp('wcbqTabPanel_$tableName').remove({$grid->getName()});  }});
	
	}")
	->addButton('Cancel',"function(){
		Ext.getCmp('wcbqTabPanel_$tableName').remove({$grid->getName()});
	}")
	
	->activateAdd()->activateRemove()
	->addtBarItem("{iconCls:'x-tbar-loading', handler:function(){
	Ext.Msg.show({ title:'Restore changes' ,buttons: Ext.MessageBox.YESNO,msg:'Are you sure?',
	fn: function(btn){if(btn == 'yes'){
	 {$grid->getName()}.getStore().loadData(slashDelimitedToArray('$data') );
	 }}});
	 //Store{$grid->rndID}.removeAll();
	//console.log( slashDelimitedToArray('$data') );
	} }"  )
	;
	$grid->firstEditableColumn = 1;
	$grid->setEditable(false)
	//->addConfig('enableDragDrop','true')
	->addConfig( "stopEditing" ,"function(cancel){
        if(this.editing){
            var ae = this.activeEditor;
            if(ae){
                ae[cancel === true ? 'cancelEdit' : 'completeEdit']();
                this.view.focusCell(ae.row, ae.col);
                

                
                 if(cancel){
	        	if(ae.record.data.ans=='')
	        	{this.getStore().remove(ae.record);}}
            }
            this.activeEditor = null;
        }
        this.editing = false;
       
    }"  )
	->addConfig("onEditComplete", "function(ed, value, startValue){
        this.editing = false;
        this.activeEditor = null;
		var r = ed.record,
            field = this.colModel.getDataIndex(ed.col);
        value = this.postEditValue(value, startValue, r, field);
        if(this.forceValidation === true || String(value) !== String(startValue)){
            var e = {
                grid: this,
                record: r,
                field: field,
                originalValue: startValue,
                value: value,
                row: ed.row,
                column: ed.col,
                cancel:false
            };
            if(this.fireEvent(\"validateedit\", e) !== false && !e.cancel && String(value) !== String(startValue)){
                r.set(field, e.value);
                delete e.cancel;
                this.fireEvent(\"afteredit\", e);
            }
        }
        this.view.focusCell(ed.row, ed.col);
        if(value=='')
        {
        	this.getStore().remove(ed.record);
        }
        
    }")
	;
	$grid->plugins[] = "new Ext.ux.dd.GridDragDropRowOrder()";
	
	
	echo $grid->createGrid();
	
	
	echo $grid->getName().".on('afteredit',function(e){
		e.record.commit();
		if(e.value != '')
		{
			if(e.originalValue  == '')
			{
			
				$name.RMaddRow.defer(100);
			}
		}
		else
		{
			
		//	$name.getStore().removeAt(e.row);
		}
		
	} );";
	
	echo "Ext.getCmp('wcbqTabPanel_$tableName').add(".$grid->getGridName().').show();';*/
?>