Ejemplo n.º 1
0
function wrsqz_testGetVars(){
	
	$questionId=999999999;
	$program = '<session lang=\"en\" version=\"2.0\"><library closed=\"false\"><mtext style=\"color:#ffc800\" xml:lang=\"es\">variables</mtext><group><command><input><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>a</mi><mo>=</mo><mn>1</mn></math></input></command><command><input><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>p</mi><mo>=</mo><mi>plot</mi><mo>(</mo><mi>sin</mi><mo>(</mo><mi>random</mi><mo>(</mo><mn>0</mn><mo>.</mo><mn>5</mn><mo>,</mo><mn>2</mn><mo>.</mo><mn>0</mn><mo>)</mo><mo>*</mo><mi>x</mi><mo>)</mo><mo>)</mo></math></input></command></group></library></session>';
	
	$data = new StdClass();
	$data->question = $questionId;
	$data->program = $program;
	
	$programId=insert_record('question_wshanprom',$data);
	
	$ok=true;
	
	if($programId===false){
		$ok=false;
		$message = 'Error accessing database.';
	}
	
	$wiris = new StdClass();
	$wiris->question=$questionId;
	$wiris->idcache=0;
	$wiris->md5=md5($program);
	$wiris->eqoption='';
	
	$data=array(
		'seed' => rand(),
		'text' => ' #p  ##Ta',
		'wiris' => $wiris
	);
	
	$result=wrsqz_getInfo('shortanswer',$questionId,$data);
	
	if($result['vars']['##Ta']!='1'){
		$ok = false;
		$message = 'Error with numeric variable';
	}else if(substr($result['vars']['##Wp'],0,7)!='<image>'){
		$ok=false;
		$message = 'Error with image variable';
	}
	
	if($ok){
		$message = wrsqz_assemble('Variables retrieved sucessfully. Look at the plot #p', $result['vars']);
	}
	
	delete_records('question_wshanprom', 'question', $questionId);
	printRow('Variables',$ok,$message);
	
}
/**
 * Creates empty session and response information for the question
 * @param object $cmoptions . if $cmoptions->commonseed==true then this question
 * random seed will be set to $cmoptions->seed;
 */
function wrsqz_create_session_and_responses($questionType, $dbType, &$question, &$state, &$cmoptions, $attempt) {
	
	$state->responses = array('' => '');
  if(isset($cmoptions->commonseed) && $cmoptions->commonseed && isset($cmoptions->seed)){
    $state->seed = $cmoptions->seed;
  }else{
    $state->seed = mt_rand(1, 31415);
  }
  
	$state->vars = array('' => '');
	
	$text = ' ' . $question->questiontext;
	$text .= ' ' . $question->generalfeedback;
	
    $text .= wrsqz_extra_variables($questionType, $question, $state);
	
	/*if ($questionType == 'multianswer') {
        //WARNING: what happens with match questions? is $state valid?
        foreach($question->options->questions as $key => $wrapped) {
            $text .= wrsqz_extra_variables($wrapped->qtype, $wrapped, $state);
        }
    }*/

  // Compute program to get variables.
	$data = array(
		'seed' => $state->seed,
		'text' => $text,
		'wiris' => $question->options->wiris
	);

	$info = wrsqz_getInfo($questionType, $question->id, $data);
	

	if (array_key_exists('id', $info) && $info['id'] != $question->options->wiris->idcache) {		
		$question->options->wiris->idcache = $info['id'];
		update_record('question_' . $questionType . 'wiris', $question->options->wiris);
	}
	
  // The variables are stored in the state session.
	if (isset($info['vars'])) {
		$state->vars = $info['vars'];
	}

	return true;
}
Ejemplo n.º 3
0
function callServlet($vars, $program)
{
    $md5 = md5($program);
    $postdata = array('function' => 'varNonLibrary', 'seed' => '123', 'text' => $vars, 'problem' => $program);
    $postdata['wiris']->md5 = $md5;
    $postdata['wiris']->idcache = 0;
    // not used but avoids a PHP notice
    $message = wrsqz_getInfo('shortanswer', 0, $postdata);
    return $message;
}