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

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

define ("ASSIGNED_DEFECT_CODE", 1);

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

    // the variable with the defect is idDefect

    // first check that the assigned engineer exists
    // in the users table
    
    $lookforsql="select sname from users where iid = $fAssigned ";

    $result = ttdb_execQuery($connection, $lookforsql);

    if(!$result){        
        ttdb_rollbackTransaction($connection);
        tter_errorWithBackButton("An error occurred querying the database. [$lookforsql]");
        exit;
    }
    
    $fields = ttdb_getArray($result);
    
    if(!is_array($fields)){
        tter_errorWithBackButton("The specified engineer number $fAssigned doesn't exist.");
        ttdb_rollbackTransaction($connection);
        exit;
    }

    $updatesql="update defect ".
        "set iidassigned = $fAssigned, ".
        " iiddefectstatus = ".ASSIGNED_DEFECT_CODE.
        " where iid=$iddefect";

    // execute it
    $result= ttdb_execQuery($connection,$updatesql);
    if(!$result){
        tter_errorWithBackButton("An error occurred updating the database. [$updatesql]");
        ttdb_rollbackTransaction($connection);
        exit;
    }

    tt_historyEntry($connection, $iddefect, "Moved to state Assigned (assigned to ".$fields['sname'].") by $ddts_username");    

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

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