<?php ob_start();
require_once 'database.php';
require_once 'history.php';
require_once 'usercheck.php';
require_once 'errors.php';
define ("DUPLICATED_DEFECT_CODE",5);
// connect to the db
ttdb_connect($connection);
ttdb_beginTransaction($connection);
// first check whether the bug to set as duplicate
// of this one exits
$lookforsql="select iid from defect where iid=$fDuplicate;";
$result = ttdb_execQuery($connection,$lookforsql);
if(!$result){
tter_errorWithBackButton("An error occurred querying the database. [$lookforsql]</br>");
ttdb_rollbackTransaction($connection);
exit;
}
$fields = ttdb_getArray($result);
if (!is_array($fields)) {
tter_errorWithBackButton("The defect $fDuplicate doesn't exist.");
ttdb_rollbackTransaction($connection);
exit;
}
// the variable with the defect is idDefect
$updatesql="update defect ".
"set iidduplicated = $fDuplicate, ".
" iiddefectstatus = ".DUPLICATED_DEFECT_CODE.
" where iid=$iddefect;";
// execute it
$result= ttdb_execQuery($connection,$updatesql);
if(!$result){
tter_errorWithBackButton("An error occurred updating the database. [$updatesql]</br>");
ttdb_rollbackTransaction($connection);
exit;
}
tt_historyEntry($connection, $iddefect, "Moved to state Duplicated (duplicate of ".
$fDuplicate.") by $ddts_username");
// go to the VisualizeForm page
ttdb_commitTransaction($connection);
ttdb_close($connection);
require_once('triggers.php');
executeTrigger("duplicate", $iddefect);
header("Location: visualize.php?iddefect=$iddefect");
ob_end_flush();
?>