Location: PHPKode > projects > Druid Defect Control > defectcontrol_0.9.4/tts/newpost.php
<?php ob_start();

require_once 'database.php';
require_once 'history.php'; 
require_once 'usercheck.php';
require_once 'errors.php';

define ("NEW_DEFECT_CODE",0);
define ("PROBLEM_ENCLOSURE_TITLE","Problem");

    if ($fNotifyChanges == 'fNotify') 
        $fNotify = "'true'";
    else
        $fNotify = "'false'";

    // connect to the db
    ttdb_connect($connection);
    ttdb_beginTransaction($connection);

    // prepare the insert clause

    $defectId = ttdb_getSequenceValue($connection, 'defect');
    
    $usernameId = ttus_getLoginUserId($connection);

    $date = date('Y-m-d H:i:s');
    
    $insertsql="insert into defect".
        "(iid,iidproject,iidsoftware,".
        "sheadline,iidrepeat,iiddefecttype,".
        "iiddetectionmethod,iidpriority,bnotifychanges,".
        "iidsubmitter,iiddefectstatus,ddetectdate,iiddetectedinrelease)".
        " values (".
        " $defectId,$fProject,$fSoftware,".
        " '$fHeadline',$fRepeat,$fDefectType,".
        " $fDetectionMethod,$fPriority,$fNotify,$usernameId,".
        NEW_DEFECT_CODE.",'$date',$fDetectedInRelease);";

    // execute it
    $result= ttdb_execQuery($connection,$insertsql);
    if(!$result){
        tter_errorWithBackButton("An error occurred inserting into the database. [$insertsql]</br>");
        ttdb_rollbackTransaction($connection);
        exit;
    }
    
    tt_historyEntry($connection, $defectId, "Created by $ddts_username");
    
    $enclosureId = ttdb_getSequenceValue($connection, 'enclosure');
    
    // insert also the enclosure
    $insertsql="insert into enclosure ".
        "(iid, iiddefect, stitle, stext) ".
        "values ($enclosureId, $defectId, '".
        PROBLEM_ENCLOSURE_TITLE."', '$fDescription');";

    $result= ttdb_execQuery($connection,$insertsql);
    if(!$result){
        tter_errorWithBackButton("An error ocurred inserting description. [$insertsql]</br>");
        ttdb_rollbackTransaction($connection);
        exit;
    }

    tt_historyEntry($connection, $defectId, "Added enclosure ".PROBLEM_ENCLOSURE_TITLE." by $ddts_username");

    // go to the VisualizeForm page
    ttdb_commitTransaction($connection);
    ttdb_close($connection);

    require_once('triggers.php');
    executeTrigger("new", $defectId);
    
    header("Location: visualize.php?iddefect=$defectId");
    ob_end_flush();
?>
Return current item: Druid Defect Control