<?
/**
* Open Universiteit Nederland
* Handles GTP 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=editLSI");
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 GTP
$GTP = new GTPClass("new");
if (!$GTPId = $GTP->NewCopy($objectTitle,$copyfrom)){
$error = true;
$errors.= $GTP->getError();
} else {
$LSI = $testset->GetLSI();
$LSI->SetGTP($GTP);
}
if(!$error){
showForm($GTP);
exit;
}
} else {
// create a new GTP
$GTP = new GTPClass("new");
if(!$GTPId = $GTP->NewGTP($objectTitle)){ // error with creating splitterclass
$error = true;
$errors.= $GTP->getError();
} else {
// assign it to the testset
$LSI = $testset->GetLSI();
$LSI->SetGTP($GTP);
} // eo create error
if (!$error){
showForm($GTP);
exit;
}
}
}
case "new":
$indexTpl= new tpclass(_FILE_ROOT_."templates/general/New.tpl");
$indexTpl->add_var("NAME","New GTP settings");
// post errors
if($error){
$indexTpl->add_var("ERRORS",formatError($errors));
$error = false;
$errors = '';
}
$indexTpl->add_var("FORM_ACTION","EditGTP.php?action=NewPost&testSet=$id");
$options = '';
$db->exec_noresult("select id,name from gtp");
for($cGtp =0;$cGtp < $db->num_rows();$cGtp++){
list($dbGtpId,$dbGtpName) = $db->next_row();
$options .= "<OPTION VALUE=$dbGtpId>".stripslashes($dbGtpName)."</OPTION>\n";
}
$indexTpl->add_var("OPTIONS",$options);
$layout->addContent($indexTpl->write("SOF_","EOF_",_MODE_RETURN_));
$layout->write();
exit;
case "post":
$GTPId = getReqIntVar("GtpId",$error,$errors,"No or Invalid Gtp id. cannot edit Gtp config\n");
$GTP = new GTPClass($GTPId);
$error = "";
if (!$GTP->postConfig()){
$error = formatError($GTP->getError());
}
showForm($GTP,$error);
break;
default:
$GTPId = getReqIntVar("GtpId",$error,$errors,"No or Invalid Gtp id. cannot edit Gtp config\n");
$GTP = new GTPClass($GTPId);
showform($GTP);
}
// Shows the Settingform
function showForm(&$GTP,$error = ""){
global $layout;
global $id;
$layout->setHeaderContent("Edit GTP settings");
$indexTpl= new tpclass(_FILE_ROOT_."templates/lsi/EditGTP.tpl");
$indexTpl->add_var('NAME',$GTP->getName());
$indexTpl->add_var('TESTSETID',$id);
$indexTpl->add_var('ERROR',$error);
$indexTpl->add_var('TERMDOCFREQ',"VALUE=\"".$GTP->getTermDocFreq()."\"");
$indexTpl->add_var('TERMGLOBALFREQ',"VALUE=\"".$GTP->getTermGlobalFreq()."\"");
// Fill in normalization (Selected box);
$normalizeNo = ($GTP->getNormalize())?"":"SELECTED";
$normalizeYes = ($GTP->getNormalize())?"SELECTED":"";
$indexTpl->add_var('NORMALIZE_NO',$normalizeNo);
$indexTpl->add_var('NORMALIZE_YES',$normalizeYes);
if ($weight = $GTP->getLocalWeight()){
$indexTpl->add_var("W1_$weight"."_SELECTED","SELECTED");
}
if ($weight = $GTP->getGlobalWeight()){
$indexTpl->add_var("W2_$weight"."_SELECTED","SELECTED");
}
$indexTpl->add_var("EXTRA_CHARS",stripslashes($GTP->getExtraChars()));
$indexTpl->add_var("MIN_KEY_LEN",$GTP->getMinKeyLen());
$indexTpl->add_var("MAX_KEY_LEN",$GTP->getMaxKeyLen());
$indexTpl->add_var("COMMON_WORDS",$GTP->getCommonWords());
if ($lanMax = $GTP->getLanMax()){
$indexTpl->add_var("LAN_MAX_CHECKED","CHECKED");
$indexTpl->add_var("LANMAX",$lanMax);
}
if ($maxPairs = $GTP->getMaxPairs()){
$indexTpl->add_var("MAX_PAIRS_CHECKED","CHECKED");
$indexTpl->add_var("MAXPAIRS",$maxPairs);
}
$indexTpl->add_var('POSTACTION',"EditGTP.php?action=post&testSet=$id&GtpId=".$GTP->getId());
$layout->addContent($indexTpl->write("SOF_","EOF_",_MODE_RETURN_));
$layout->write();
}
?>