Location: PHPKode > projects > DATA system > datasystem-0.8.7/html/u/addunitid.php
<?
/*
 *  addunitid.php
 *  Add unit id definition
 *
 *  Changes:
 *  Aug. 09, 2005  Shinya Meguro <hide@address.com>
 *                 - New creation
 */

adminonly();

pageheader("main", "Add new Unit ID definition");

if (GET) {

    print <<<__EOD__
    <form method="post" action="addunitid.php">
    <h2>Add new Unit ID definition</h2>

    <table>
      <tr>
        <td>ID :</td>
        <td><input type="text" name="id" value="" /></td>
      </tr>
      <tr>
        <td>Name :</td>
        <td><input type="text" name="name" value="" /></td>
      </tr>
      <tr>
        <td>Note :</td>
        <td><input type="text" name="comment" value="" /></td>
      </tr>
      <tr>
        <td><input type="submit" name="doSubmit" value="Add ID"></td>
      </tr>
    </table>
    <br>
__EOD__;


    $data = db_getUnitIds();

    print <<<__EOD__
    <table frame="box" cellpadding="2" cellspacing="0">
    <tr>
__EOD__;

    $names = $data[0];

    foreach ($names as $name)
        print("<th>$name</th>\n");
    print("</tr>\n");

    /*  $Data array
     *  [0] --- id
     *  [1] --- name (upper case, start from "UT_")
     *  [2] --- comment (optional description)
     */

    for ($line = 1; $line < count($data); $line++)
    {
        print("<tr align=\"center\" bgcolor=\"".(($line)%2 ? "#ffffff" : "#d0ffd0")."\">\n");
        foreach ($data[$line] as $col)
            print("<td>".stripslashes(trim($col))."</td>\n");
        print("</tr>\n");
    }

    print("</table>\n");

    pagefooter();


} elseif (POST && ($params["doSubmit"] == "Add ID")) {


    if (ereg("^[0-9]+$",$params["id"])) {
        $id = $params["id"];
    } else {
        errorfooter("Invalid ID.");
    }

    if (ereg("^UT_[0-9A-Z_\-]+$",$params["name"])) {
        $name = pg_escape_string($params["name"]);
    } else {
        errorfooter("Invalid unit name.");
    }

    if (isset($params["comment"])) {
        $comment = htmlentities(pg_escape_string($params["comment"]));
    } else {
        $comment = "";
    }

    db_addUnitId($id, $name, $comment);

		// Remove old ID setting file (php/p/idsetting.php)
	if (file_exists($idfile=DS_PHP_PATH.'p/idsetting.php')) {
		unlink($idfile);
	}

	setLocation("./listunitid.php");

}

?>
Return current item: DATA system