Changeset 13315 for trunk


Ignore:
Timestamp:
04/05/12 13:07:37 (13 years ago)
Author:
Daniela Dorner
Message:
included SequenceComments database
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Mars/datacenter/db/run_comment.php

    r12931 r13315  
    1212
    1313    if (empty($_GET["fRunID"]))
    14         $_GET["fRunID"]="001";
     14        $_GET["fRunID"]="all";
     15
     16    if (empty($_GET["fSequenceID"]))
     17        $_GET["fSequenceID"]="all";
     18
     19    if (empty($_GET["fTable"]))
     20    {
     21        $_GET["fTable"]="RunComments";
     22//        $_GET["fTable"]="SequenceComments";
     23        $sign=strpos($_SERVER['REQUEST_URI'], "?")==false ? "?" : "&";
     24        $_SERVER['REQUEST_URI']=$_SERVER['REQUEST_URI'] . $sign . "fTable=RunComments";
     25    }
    1526
    1627    if (empty($_GET["fNight"]))
     
    1930    if (strcmp($_GET["fMode"], "tooltip")!=0)
    2031        echo (file_get_contents("index-header.html"));
    21 
    2232
    2333
     
    5262            //for insert
    5363            if (strcmp($_GET["fMode"], "insert")==0)
    54                 $query0 = "INSERT RunComments SET ";
     64                $query0 = "INSERT " . $_GET["fTable"] . " SET ";
    5565            //for update
    5666            if (strcmp($_GET["fMode"], "update")==0)
    57                 $query0 = "UPDATE RunComments SET ";
     67                $query0 = "UPDATE " . $_GET["fTable"] . " SET ";
    5868            //for both
    5969            $query0.= " fComment='".str_replace("'", "\'", $_GET["fComment"])."'";
     
    6373            {
    6474                $query0.=", fNight=".$_GET["fNight"];
    65                 $query0.= ", fRunID=".$_GET["fRunID"];
     75                if (strcmp($_GET["fTable"], "RunComments")==0)
     76                    $query0.= ", fRunID=".$_GET["fRunID"];
     77                if (strcmp($_GET["fTable"], "SequenceComments")==0)
     78                    $query0.= ", fSequenceID=".$_GET["fSequenceID"];
    6679            }
    6780            //for update
    6881            if (strcmp($_GET["fMode"], "update")==0)
    6982            {
    70                 $query2="SELECT fCommentKEY FROM RunComments ";
     83                $query2="SELECT fCommentKEY FROM " . $_GET["fTable"];
    7184                $query2.=" WHERE fNight=".$_GET["fNight"];
    72                 $query2.=" AND fRunID=".$_GET["fRunID"];
     85                if (strcmp($_GET["fTable"], "RunComments")==0)
     86                    $query2.=" AND fRunID=".$_GET["fRunID"];
     87                if (strcmp($_GET["fTable"], "SequenceComments")==0)
     88                    $query2.=" AND fSequenceID=".$_GET["fSequenceID"];
    7389                $query2.=" AND fComment='".str_replace("'", "\'", $_GET["fOldComment"])."'";
    7490                $result2=mysql_query($query2, $db_id);
     
    7894                $query0.=" WHERE fCommentKEY=".$commentkey;
    7995            }
     96            //echo "insert query: " . $query0 . "<br>";
    8097            $result0=mysql_query($query0, $db_id);
    8198            mysql_close($db_id);
     
    91108    if (strcmp($_GET["fMode"], "tooltip")!=0)
    92109    {
     110        //mode
    93111        printf("With this page, you can \n");
    94112        //view mode
    95113        if (strcmp($_GET["fMode"], "view")==0)
    96             printf("view,\n");
     114            printf("<b>view</b>,\n");
    97115        else
    98116            printf("<a href='%s'>view</a>,\n", str_replace($_GET["fMode"], 'view', $_SERVER['REQUEST_URI']));
    99117        //update mode
    100118        if (strcmp($_GET["fMode"], "update")==0)
    101             printf("update and\n");
     119            printf("<b>update</b> and\n");
    102120        else
    103121            printf("<a href='%s'>update</a> and \n", str_replace($_GET["fMode"], 'update', $_SERVER['REQUEST_URI']));
    104122        //insert mode
    105123        if (strcmp($_GET["fMode"], "insert")==0)
    106             printf("insert\n");
     124            printf("<b>insert</b>\n");
    107125        else
    108126            printf("<a href='%s'>insert</a> \n", str_replace($_GET["fMode"], 'insert', $_SERVER['REQUEST_URI']));
    109         printf("entries in the table <b>RunComment</b> from the DB <b>%s</b>.<br><br>\n", $db);
    110 
    111         //insert field for run number
     127
     128        //table
     129        printf("entries in the tables <b>%s</b> \n", $_GET["fTable"]);
     130        if (strcmp($_GET["fTable"], "RunComments")==0)
     131            printf(" and <a href='%s'>SequenceComments</a> \n", str_replace($_GET["fTable"], 'SequenceComments', $_SERVER['REQUEST_URI']));
     132        else
     133            printf(" and <a href='%s'>RunComments</a> \n", str_replace($_GET["fTable"], 'RunComments', $_SERVER['REQUEST_URI']));
     134        //database
     135        printf("from the DB %s.<br><br>\n", $db);
     136
     137        //insert field for run/sequence number
    112138        printf("<form action=\"run_comment.php\" METHOD=\"GET\">\n");
    113         printf("Run#&nbsp;(YYYYMMDD_FFF)&nbsp;<input name=\"fNight\" type=\"text\" size=\"8\" maxlength=\"8\" value=\"%s\">\n", $_GET["fNight"]);
    114         printf("_ <input name=\"fRunID\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"%s\">\n", $_GET["fRunID"]);
     139        if (strcmp($_GET["fTable"], "RunComments")==0)
     140        {
     141            printf("Run#&nbsp;(YYYYMMDD_FFF)&nbsp;<input title='Enter here Night in the format YYYYMMDD or \"all\" to query all comments.' name=\"fNight\" type=\"text\" size=\"8\" maxlength=\"8\" value=\"%s\">\n", $_GET["fNight"]);
     142            printf("_ <input title='Enter here RunID in the format FFF or \"all\" (only viewing mode) to query all comments of one night.' name=\"fRunID\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"%s\">\n", $_GET["fRunID"]);
     143        }
     144        if (strcmp($_GET["fTable"], "SequenceComments")==0)
     145        {
     146            printf("Sequence#&nbsp;(YYYYMMDD_FFF)&nbsp;<input title='Enter here Night in the format YYYYMMDD or \"all\" to query all comments.' name=\"fNight\" type=\"text\" size=\"8\" maxlength=\"8\" value=\"%s\">\n", $_GET["fNight"]);
     147            printf("_ <input title='Enter here SequenceID in the format FFF or \"all\" (only viewing mode) to query all comments of one night.' name=\"fSequenceID\" type=\"text\" size=\"3\" maxlength=\"3\" value=\"%s\">\n", $_GET["fSequenceID"]);
     148        }
    115149        printf("<input type='hidden' name='fMode' value='%s'>", $_GET["fMode"]);
     150        printf("<input type='hidden' name='fTable' value='%s'>", $_GET["fTable"]);
    116151        printf("<input type='submit' value='Get Comments'><br><br>\n");
    117152        printf("</form>\n");
    118153    }
    119154
     155    if (!(preg_match("/20[0-9][0-9][01][0-9][0-3][0-9]/",$_GET["fNight"])
     156          || (preg_match("/all/",$_GET["fNight"]) && strcmp($_GET["fMode"], "view")==0)))
     157    {
     158        printf("-%s-<br>", $_GET["fMode"]);
     159        printf("Please enter a valid number for the Night (format: YYYYMMDD).");
     160        return;
     161    }
     162
     163    if (strcmp($_GET["fTable"], "RunComments")==0 &&
     164        (!(preg_match("/[0-9][0-9][0-9]/",$_GET["fRunID"])
     165           || (preg_match("/all/",$_GET["fRunID"]) && strcmp($_GET["fMode"], "view")==0))))
     166    {
     167        printf("Please enter a valid number for the RunID (format: FFF, e.g. 001).");
     168        return;
     169    }
     170
     171    if (strcmp($_GET["fTable"], "SequenceComments")==0 &&
     172        (!(preg_match("/[0-9][0-9][0-9]/",$_GET["fSequenceID"])
     173          || (preg_match("/all/",$_GET["fSequenceID"]) && strcmp($_GET["fMode"], "view")==0))))
     174    {
     175        printf("Please enter a valid number for the SequenceID (format: FFF, e.g. 001).");
     176        return;
     177    }
     178
    120179    $db_id = mysql_pconnect($host, $user, $pw);
    121180    if ($db_id==FALSE)
     
    126185    mysql_select_db($db);
    127186
    128     $query1 = "SELECT CONCAT(fNight,'_', LPAD(fRunID, 3, 0)), fComment FROM RunComments ";
    129     $query1 .= "WHERE fNight=".$_GET["fNight"]." AND fRunID=".$_GET["fRunID"];
     187    if (strcmp($_GET["fTable"], "RunComments")==0)
     188        $query1 = "SELECT CONCAT(fNight,'_', LPAD(fRunID, 3, 0))";
     189    if (strcmp($_GET["fTable"], "SequenceComments")==0)
     190        $query1 = "SELECT CONCAT(fNight,'_', LPAD(fSequenceID, 3, 0))";
     191    $query1 .= ", fComment FROM " . $_GET["fTable"] . "  ";
     192
     193    if (strcmp($_GET["fNight"], "all")!=0)
     194    {
     195        $query1 .= "WHERE fNight=".$_GET["fNight"];
     196        if (strcmp($_GET["fTable"], "RunComments")==0)
     197            if (strcmp($_GET["fRunID"], "all")!=0)
     198                $query1 .=" AND fRunID=".$_GET["fRunID"];
     199        if (strcmp($_GET["fTable"], "SequenceComments")==0)
     200            if (strcmp($_GET["fSequenceID"], "all")!=0)
     201                $query1 .=" AND fSequenceID=".$_GET["fSequenceID"];
     202    }
     203    if (strcmp($_GET["fTable"], "RunComments")==0)
     204        $query1 .= " ORDER BY fNight, fRunID, fCommentKEY ";
     205    if (strcmp($_GET["fTable"], "SequenceComments")==0)
     206        $query1 .= " ORDER BY fNight, fSequenceID, fCommentKEY ";
     207
     208    //printf("Query: %s <br>\n\n", $query1);
    130209    $result1=mysql_query($query1, $db_id);
    131210    printf("Found %d comment(s).\n\n", mysql_num_rows($result1));
     
    158237                printf("<input type='hidden' name='fNight' value='%s'>\n", $_GET["fNight"]);
    159238                printf("<input type='hidden' name='fRunID' value='%s'>\n", $_GET["fRunID"]);
     239                printf("<input type='hidden' name='fSequenceID' value='%s'>\n", $_GET["fSequenceID"]);
     240                printf("<input type='hidden' name='fTable' value='%s'>\n", $_GET["fTable"]);
    160241                printf("<input type='submit' value='Update Comment'>\n");
    161242                printf("</td>\n");
     
    167248        }
    168249        else
    169             printf("%s_%s: %s\n", $_GET["fNight"], $_GET["fRunID"], $row1[1]);
     250        {
     251            if (strcmp($_GET["fTable"], "RunComments")==0)
     252                printf("%s_%s: %s\n", $_GET["fNight"], $_GET["fRunID"], $row1[1]);
     253            if (strcmp($_GET["fTable"], "SequenceComments")==0)
     254                printf("%s_%s: %s\n", $_GET["fNight"], $_GET["fSequenceID"], $row1[1]);
     255        }
    170256    }
    171257    //insert mode
     
    173259    {
    174260        printf("<tr BGCOLOR='#C0C0C0'>");
    175         printf("<td>%s_%s</td>\n", $_GET["fNight"], $_GET["fRunID"]);
     261        if (strcmp($_GET["fTable"], "RunComments")==0)
     262            printf("<td>%s_%s</td>\n", $_GET["fNight"], $_GET["fRunID"]);
     263        if (strcmp($_GET["fTable"], "SequenceComments")==0)
     264            printf("<td>%s_%s</td>\n", $_GET["fNight"], $_GET["fSequenceID"]);
    176265        printf("<td>\n");
    177266        printf("<form style='display:inline' action=\"run_comment.php\" METHOD=\"GET\">\n");
     
    180269        printf("<input type='hidden' name='fNight' value='%s'>\n", $_GET["fNight"]);
    181270        printf("<input type='hidden' name='fRunID' value='%s'>\n", $_GET["fRunID"]);
     271        printf("<input type='hidden' name='fSequenceID' value='%s'>\n", $_GET["fSequenceID"]);
     272        printf("<input type='hidden' name='fTable' value='%s'>\n", $_GET["fTable"]);
    182273        printf("<input type='submit' value='Insert Comment'>\n");
    183274        printf("</form>\n");
Note: See TracChangeset for help on using the changeset viewer.