Location: PHPKode > projects > GUP: GTP Usability Prototype > EditQs.php
<?
/**
 * Open Universiteit Nederland
 * Handles query settings
 * Last modified 17 January 2006 
 */
 
include "default.php";

$layout = new layoutClass();
$layout->addMenuItemsFromName(home);

$db = new data();
$db->connect();

// always need a testset to work on:
$id= getReqIntVar("testSet",$error,$errors,"You have to supply a valid testsetid");
if($error){
	$layout->addContent(formatError($errors));
	$layout->write();
	exit;
}

$action = $_GET["action"];
switch($action){

	case "save":
  	   header("Location: "._WEB_ROOT_."index.php?action=editQuery");
	exit;

	case "NewPost":
		// derived from EditDs.php
		$objectTitle = getReqVar("objectTitle",$error,$errors,"Please use a name between 3 and 50 characters\n",3,50);

		if($copy = getCheckboxValue("copy")){
			$copyfrom = getReqIntVar("from",$error,$errors,"Please select a source to copy from.\n");
		}

		if (!$error){
			$testset = new TestSetClass($id);
			if ($copy){
				// create a copied query
				$query = new QueryClass("new");
				if (!$queryId = $query->NewCopy($objectTitle,$copyfrom)){
					$error = true;
					$errors.= $query->getError();
				} else {
					$testset->SetQuery($query);
				}
					if(!$error){
						showForm($query);
						exit;
					}
			} else {
				// create a new Query
				$query = new QueryClass("new");
				if(!$queryId = $query->NewQuery($objectTitle)){ // error with creating QueryClass
					$error = true;
					$errors.= $query->getError();
				} else {
					$testset->SetQuery($query);
				} // eo create error
				if (!$error){
				  showForm($query);
				  exit;
				}
			}		
		}
		
	case "new":
		$layout->setHeaderContent("New Query setting");
		$indexTpl= new tpclass(_FILE_ROOT_."templates/general/New.tpl");
		
		// post errors
		if($error){
			$indexTpl->add_var("ERRORS",formatError($errors));
			$error = false;
			$errors = '';
		}
		
		$indexTpl->add_var("NAME","Query setting");
		$indexTpl->add_var("FORM_ACTION","EditQs.php?action=NewPost&testSet=$id");

		$options = '';
		$db->exec_noresult("select id,name from query");
			for($cQuery =0;$cQuery < $db->num_rows();$cQuery++){
				list($dbQueryId,$dbQueryName) = $db->next_row();
				$options .= "<OPTION VALUE=$dbQueryId>".stripslashes($dbQueryName)."</OPTION>\n";
			}
		$indexTpl->add_var("OPTIONS",$options);
		$layout->addContent($indexTpl->write("SOF_","EOF_",_MODE_RETURN_));
		$layout->write();
		exit;			

	case "QSPost":
		$error = false;
		$QueryId = getReqIntVar("QueryId",$error,$errors,"No or Invalid Query setting. cannot edit Query settings\n");
		if ($error){
			$layout->addContent(formatError($errors));
			$layout->write();
			exit;
		}
		$query = new QueryClass($QueryId);
		
		$scale = getCheckboxValue("scale");

		$lowerTreshold = getReqIntVar("lowerTreshold",$error,$errors,"You have to specify a lower treshold between -1 and 1",-1,1);
		$upperTreshold = getReqIntVar("upperTreshold",$error,$errors,"You have to specify an upper treshold between the lowertreshold and 1",$lowerTreshold,1);
		$maxResults = getIntVar("AmountResults",0);
		if ($error){
			$layout->addContent(formatError($errors));
		} else {
			$query->setSettings($scale,$lowerTreshold,$upperTreshold,$maxResults);
		}

		showForm($query);

	default:
		$error = false;
		$QueryId = getReqIntVar("QueryId",$error,$errors,"No or Invalid Query setting. cannot edit Query settings\n");
		if ($error){
			$layout->addContent(formatError($errors));
			$layout->write();
			exit;
		}
		$query = new QueryClass($QueryId);
		showForm($query);

}


function showForm(&$query){
	global $layout;
	global $id;
	$layout->setHeaderContent("Edit Query settings");
	$indexTpl= new tpclass(_FILE_ROOT_."templates/query/EditQs.tpl");
	$indexTpl->add_var('NAME',$query->getName());
	$indexTpl->add_var('TESTSETID',$id);
	$indexTpl->add_var('ACTION',"EditQs.php?testSet=$id&QueryId=".$query->getId()."&action=QSPost");
	$scaleChecked = ($query->getScale())?"CHECKED":"";
	$indexTpl->add_var('SCALE_CHECKED',$scaleChecked);
	$indexTpl->add_var('LOWER_TRESHOLD',$query->getLowerTreshold());
	$indexTpl->add_var('UPPER_TRESHOLD',$query->getUpperTreshold());
	$indexTpl->add_var('AMOUNT_RESULTS',$query->getMaxResults());

	$layout->addContent($indexTpl->write("SOF_","EOF_",_MODE_RETURN_));
	$layout->write();
}



?>
Return current item: GUP: GTP Usability Prototype