Location: PHPKode > projects > Druid Defect Control > defectcontrol_0.9.4/tts/admininserts.php
<?php 
require_once 'database.php';
require_once 'errors.php';
require_once 'usercheck.php';
?>

<html>
<link rel="stylesheet" href="style.css">

<body>
<?php include 'header.php' ?> 

<?php
    ttdb_connect($db);

    // this functionality is only available as administrator. 
    if (ttus_userIsAdmin($db) != "t") {
        tter_errorWithBackButton("You are not an administrator, and thus, ".
            "are not allowed to perform this operation.", "Access level error");
        exit;
     }
?>

<h1>Table 'insert' generator</h1>
<p>You can specify here one table, and their values will be printed for you. </p>
<p>Note that if you use this utility for replication, you should remember to update 
  the sequences initialization value also. </p>
<form method="get" action="admininserts.php">
  Table name: 
  <select name="table">
    <option value="defect">Defects</option>
    <option value="defecttype">Defect types</option>
    <option value="detectionmethod">Detection methods</option>
    <option value="enclosure">Enclosures</option>
    <option value="history">History</option>
    <option value="priority">Priorities</option>
    <option value="project" selected>Projects</option>
    <option value="resolution">Resolution types</option>
    <option value="releases">Releases</option>
    <option value="repeat">Repeatibilities</option>
    <option value="software">Software</option>
    <option value="users">Users</option>
  </select>
  <input type="submit" name="Submit" value="Get table">
</form>
<hr width="90%">
<p><?php 

function printInserts($db, $table) {

    echo "Inserts for table $table:<br>\n";
    
    $query = "select * from $table";
    $res = ttdb_execQuery($db, $query);

    echo "<br><pre>\n";
    
    while (($fields = ttdb_getArray($res)) != false) {
        
        echo "INSERT INTO $table (";

        $a = 0;
        foreach ($fields as $key => $value) {        
            echo "$key";
            if ($a++ != (count($fields) - 1)) 
                echo ", ";
        }  // foreach

        echo ") VALUES (";

        $a = 0;
        foreach ($fields as $key => $value) {        
            $type = ttdb_getFieldType($res, $a);
            $value = htmlspecialchars($value);
            //echo "'$type'";
            if ($type == "int4") echo "$value"; else echo "'$value'";            
            if ($a++ != (count($fields) - 1)) 
                echo ", ";
        } // foreach

        echo ");<br>\n";       
        
    }  // while 
    
    echo "</pre><br>\n";

}


    if ($table == "") {
        printInserts($db, "detectionmethod");
        printInserts($db, "repeat");
        printInserts($db, "priority");
        printInserts($db, "defecttype");
        printInserts($db, "defectstatus");
        printInserts($db, "releases");
        printInserts($db, "project");
        printInserts($db, "software");
        printInserts($db, "resolution");
        printInserts($db, "detectionmethod");
    } else {
        printInserts($db, $table);
    }


?> <?php ttdb_close($db); ?> </p>



<p>&nbsp;</p>
<?php include 'footer.php' ?>
</html>
Return current item: Druid Defect Control