<?PHP
/*
	This program will convert current questions and answers in the format defined
	in the profile_questions.php file in the language directory for language specific
	conversions.

*/
if ( !defined( 'SMARTY_DIR' ) ){
	include_once( '../init.php' );
}

include ( 'sessioninc.php' );

$file = TEMP_DIR . 'profile_questions.php';
$fp = @fopen($file,'wb');
fwrite($fp,'<?php '.chr(13).chr(10));

$sections =& $osDB->getAll('select id, section from !',array(SECTIONS_TABLE));
foreach ($sections as $x=> $section) {
	fwrite($fp, "\$lang['sections']['".$section['id']."'] = '".addslashes($section['section'])."';\n\r");
}

unset($sections);

$questions =& $osDB->getAll('select id, question, description, guideline, control_type, extsearchhead from ! ', array(QUESTIONS_TABLE));
foreach ($questions as $x => $rec) {
	fwrite($fp, "\$profile_questions['".$rec['id']."']['question'] = '".addslashes($rec['question'])."';\n\r");
	fwrite($fp, "\$profile_questions['".$rec['id']."']['description'] = '".addslashes($rec['description'])."';\n\r");
	fwrite($fp, "\$profile_questions['".$rec['id']."']['guideline'] = '".addslashes($rec['guideline'])."';\n\r");
	fwrite($fp, "\$profile_questions['".$rec['id']."']['extsearchhead'] = '".addslashes($rec['extsearchhead'])."';\n\r");
	if ($rec['control_type'] != 'textarea') {
		$options =& $osDB->getAll('select id, answer from ! where questionid = ? order by questionid, id', array(OPTIONS_TABLE, $rec['id']) );
		foreach ($options as $x => $ans) {
			fwrite($fp, "\$profile_questions['".$rec['id']."']['".$ans['id']."'] = '".addslashes($ans['answer'])."';\n\r");
		}
		unset($options);
	}
}
fwrite($fp,'?>');
fclose($fp);

unset($questions);

$t->assign('file',$file);

$t->assign('rendered_page', $t->fetch('admin/generate_prof_quest_file.tpl'));

$t->display( 'admin/index.tpl' );

?>