Changeset 11505
- Timestamp:
- 07/21/11 11:24:15 (13 years ago)
- Location:
- trunk/www/db_po
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/www/db_po/edit_po.php
r11353 r11505 6 6 echo (file_get_contents("index-header.html")); 7 7 8 //call get_progs() at startup 9 printf("<script type=\"text/javascript\" >\n"); 10 printf("window.onload = function () { get_progs(\"\",\"10\",\"edit\"); }\n"); 11 printf("</script>\n"); 12 8 13 include("db.php"); 9 $db_id = mysql_pconnect($host, $user, $pw); 10 if ($db_id==FALSE) 11 { 12 printf("mysql_connect returned the following error: %s\n", mysql_error()); 13 die(""); 14 } 15 mysql_select_db($db); 16 echo "Hi, this is a test interface for the DB <b>" . $db . "</b>.<br><br>"; 17 18 $query0="SELECT fProgram from ProgramOption GROUP BY fProgram"; 19 20 $result0=mysql_query($query0, $db_id); 21 14 printf("With this page, you can <u>edit</u> the DB <b>%s</b>.\n", $db); 15 printf("For view, please go <a href='view_po.php'>here</a>.<br><br>\n"); 22 16 printf("<table border='0'><tbody>\n"); 23 printf("<tr>\n<td>Please select a program:</td>\n"); 24 printf("<td>\n<select name='prog' size='1' onchange=\"get_keys(this.value)\"class='Width'>\n"); 25 printf("<option value='empty'> ---select program--- </option>\n"); 26 printf("<option value='all'> all programs </option>\n"); 27 while ($row0 = mysql_fetch_row($result0)) 28 printf("<option value='%s'>%s </option>\n", $row0[0], $row0[0]); 29 printf("</select>\n</td>\n</tr>\n"); 30 mysql_free_result($result0); 31 32 echo "<tr id='keyfield'></tr>"; 33 echo "<tr id='valuefield'></tr>"; 34 printf("</tbody></table>\n"); 35 36 mysql_close($db_id); 37 38 39 17 printf("<tr>\n"); 18 printf("<td valign='top' id='progfield'></td>\n"); 19 printf("<td valign='top' id='keyfield'></td>\n"); 20 printf("<td valign='top' id='valuefield1'></td>\n"); 21 printf("</tr>\n</tbody></table>\n"); 40 22 41 23 echo (file_get_contents("index-footer.html")); -
trunk/www/db_po/get_keys.php
r11353 r11505 9 9 return; 10 10 } 11 if (empty($_GET["fKey"])) 12 $_GET["fKey"]=""; 13 if (empty($_GET["fSelectSize"])) 14 $_GET["fSelectSize"]="10"; 15 if (empty($_GET["fMode"])) 16 $_GET["fMode"]="view"; 11 17 12 18 include("db.php"); … … 19 25 mysql_select_db($db); 20 26 21 $query0="SELECT fKey from ProgramOption "; 27 $query1 = "SELECT Max(fCounter) FROM History"; 28 $result1=mysql_query($query1, $db_id); 29 $row1 = mysql_fetch_row($result1); 30 $maxcounter=$row1[0]; 31 mysql_free_result($result1); 32 33 $query0="SELECT Concat(fKey1, fKey2) as ourkeys from ProgramOption "; 34 $query0.="WHERE fCounter=".$maxcounter." "; 22 35 if ($_GET["fProgram"]!="all") 23 $query0.=" WHEREfProgram='".$_GET["fProgram"]."' ";24 $query0.="GROUP BY fKey";36 $query0.="AND fProgram='".$_GET["fProgram"]."' "; 37 $query0.="GROUP BY ourkeys"; 25 38 26 39 $result0=mysql_query($query0, $db_id); 27 40 28 printf("<td>Please select a key:</td>\n"); 29 printf("<td><select name='key' size='1' onchange=\"get_values('%s',this.value)\"class='Width'>\n", $_GET["fProgram"]); 30 printf("<option value='empty'> ---select key--- </option>\n"); 31 printf("<option value='newkey'> add new key </option>\n"); 41 if (strcmp($_GET["fMode"], "edit")==0) 42 printf("select key: <br>\n"); 43 else 44 printf("select key: \n"); 45 printf("<select style='width:200px' id='key' size='%s' onchange=\"get_values(1,'%s',this.value,'%s')\"class='Width'>\n", 46 $_GET["fSelectSize"], $_GET["fProgram"], $_GET["fMode"]); 47 if (!empty($_GET["fKey"]) && strcmp("all", $_GET["fKey"])==0) 48 printf("<option value='all' selected> --- all keys --- </option>\n"); 49 else 50 printf("<option value='all'> --- all keys --- </option>\n"); 32 51 while ($row0 = mysql_fetch_row($result0)) 33 printf("<option value='%s'>%s </option>\n", $row0[0], $row0[0]); 34 printf("</select>\n</td>\n"); 52 if (!empty($_GET["fKey"]) && strcmp($row0[0], $_GET["fKey"])==0) 53 printf("<option value='%s' selected>%s </option>\n", $row0[0], $row0[0]); 54 else 55 printf("<option value='%s'>%s </option>\n", $row0[0], $row0[0]); 56 printf("</select>\n<br>\n"); 57 if (strcmp($_GET["fMode"], "edit")==0) 58 printf("<button onClick='addRow(2,\"%s\",\"\",\"\",\"\",\"\");' id='addrowkey' style='display:inline'>Add Key</button>\n", $_GET["fProgram"]); 35 59 mysql_free_result($result0); 36 60 -
trunk/www/db_po/get_values.php
r11353 r11505 4 4 ini_set("mysql.trace_mode", "On"); 5 5 6 if (empty($_GET["fGetValCase"])) 7 { 8 echo "Please specify how you want to display the table (for view or for insert)."; 9 //1: insert 10 //2: view 11 //3: view compare 12 return; 13 } 6 14 if (empty($_GET["fKey"])) 7 15 { 8 echo "Please select a key. <br>";16 echo "Please select a key."; 9 17 return; 10 18 } 11 19 if (empty($_GET["fProgram"])) 12 20 { 13 echo "Please select a program. <br>";21 echo "Please select a program."; 14 22 return; 15 23 } 16 24 if (empty($_GET["fStatusDate"])) 25 $_GET["fStatusDate"]=""; 17 26 18 27 include("db.php"); … … 26 35 27 36 $query1 = "SELECT Max(fCounter) FROM History"; 37 // get counter of fStatusDate or current status 38 if ($_GET["fGetValCase"]!=1 && $_GET["fStatusDate"]!="") 39 $query1.=" WHERE (fValidFrom < '".$_GET["fStatusDate"]."' OR fValidFrom like '".$_GET["fStatusDate"]."%')"; 40 28 41 $result1=mysql_query($query1, $db_id); 29 42 $row1 = mysql_fetch_row($result1); 30 $ maxcount=$row1[0];31 //echo $maxcount;43 $counter=$row1[0]; 44 mysql_free_result($result1); 32 45 33 $query0 ="SELECT fIndex, fProgram, fKey, fValue, fDescription, fCounter FROM ProgramOption "; 34 $query0.="WHERE fKey='".$_GET["fKey"]."'"; 35 if ($_GET["fProgram"]!="all") 46 //get key1 and key2 separately from DB (for function AddRow()) 47 $query2 = "SELECT fKey1, SUBSTRING(fKey2,2), fType FROM ProgramOption WHERE Concat(fKey1,fKey2)='".$_GET["fKey"]."'"; 48 $result2=mysql_query($query2, $db_id); 49 $row2 = mysql_fetch_row($result2); 50 $key1=$row2[0]; 51 $key2=$row2[1]; 52 $type=$row2[2]; 53 mysql_free_result($result2); 54 55 $query0 ="SELECT fIndex, fValidFrom, fProgram, Concat(fKey1,fKey2), fValue, fDescription, fCounter, fType, fMin, fMax, fKey1, SUBSTRING(fKey2,2), if(fOriginalIndex=0, fIndex, fOriginalIndex) FROM ProgramOption "; 56 $query0.="WHERE 1=1 "; 57 if (strcmp($_GET["fKey"],"all")!=0) 58 $query0.="AND Concat(fKey1,fKey2)='".$_GET["fKey"]."' "; 59 if (strcmp($_GET["fProgram"],"all")!=0) 36 60 $query0.="AND fProgram='".$_GET["fProgram"]."' "; 61 if ($_GET["fGetValCase"]!=1) 62 { 63 $query0.="AND NOT isnull(fValue) "; 64 $query0.="AND fCounter>=".$counter; 65 if ($_GET["fStatusDate"]!="") 66 $query0.=" AND (fValidFrom < '".$_GET["fStatusDate"]."' OR fValidFrom like '".$_GET["fStatusDate"]."%') "; 67 } 68 $query0.=" ORDER BY fOriginalIndex, fIndex"; 37 69 38 70 $result0=mysql_query($query0, $db_id); 39 71 40 printf("<td valign='top'>Please edit:</td>\n"); 41 printf("<td>\n"); 42 printf("<button onClick='ShowCurrent();' id='showcurrent' style='display:none'>Show Current</button>\n"); 43 printf("<button onClick='ShowAll();' id='showall' style='display:inline'>Show All</button>\n"); 44 printf("<button onClick='addRow(\"%s\",\"%s\");' id='addrow' style='display:inline'>Add Row</button>\n", $_GET["fProgram"], $_GET["fKey"]); 45 printf("<table border='1' width='100px' height='100px'><tbody id='valtable'>\n"); 46 printf("<tr><th>Index / Counter</th><th>Program</th><th>Key</th><th>Value</th><th>Description</th>"); 47 printf("<th>Action</th></tr>\n"); 48 while ($row0 = mysql_fetch_row($result0)) 72 if ($_GET["fGetValCase"]==1) 49 73 { 50 if ($row0[5]==$maxcount) 51 printf("<tr id='new%s' style='display:'>\n", $row0[0]); 52 else 53 printf("<tr id='old%s' style='display:none'>\n", $row0[0]); 54 printf("<td> %s / %s</td>\n", $row0[0], $row0[5]); 55 printf("<td id='prog%s'>%s</td>\n", $row0[0], $row0[1]); 56 printf("<td id='key%s'>%s</td>\n", $row0[0], $row0[2]); 57 printf("<td align='right' id='val%s'>%s</td>\n", $row0[0], $row0[3]); 58 printf("<td id='descr%s'>%s</td>\n", $row0[0], $row0[4]); 59 if ($row0[5]==$maxcount) 60 printf("<td id='action%s'><input type='button' value='Edit' onclick='EditRow(\"%s\")'></td>\n</tr>\n", $row0[0], $row0[0]); 61 else 62 printf("<td id='action%s'></td>\n</tr>\n", $row0[0]); 63 $maxindex=$row0[0]; 74 printf("<button onClick='ShowCurrent();' id='showcurrent' style='display:none'>Show Current</button>\n"); 75 printf("<button onClick='ShowAll();' id='showall' style='display:inline'>Show History</button>\n"); 76 printf("<button onClick='addRow(3, \"%s\",\"%s\",\"%s\",\"%s\",\"%s\");' id='addrowvals' style='display:inline'>Add Value</button>\n", 77 $_GET["fProgram"], $_GET["fKey"], $key1, $key2, $type); 64 78 } 65 printf("<div id='addline'></div>"); 66 printf("</tbody></table>\n<br>\n"); 67 printf("<div id='maxindex' style='display:none'>%s</div>\n", $maxindex); 68 printf("</td>\n"); 79 printf("<table font-size='-1' border='1' width='100px' height='100px'><tbody id='valtable%s'>\n", $_GET["fGetValCase"]); 80 printf("<tr>"); 81 printf("<th>Index / Orig / Counter</th>\n"); 82 printf("<th>Valid since</th>\n"); 83 printf("<th>Program</th>\n"); 84 //printf("<th>Key</th>\n"); 85 printf("<th>Key1</th>\n"); 86 printf("<th>Key2</th>\n"); 87 printf("<th>Value</th>\n"); 88 printf("<th>Type</th>\n"); 89 if ($_GET["fGetValCase"]==1)//show only in edit mode 90 printf("<th class='description%d'>Description</th>\n", $_GET["fGetValCase"]); 91 else 92 printf("<th class='description%d' style='display:none'>Description</th>\n", $_GET["fGetValCase"]); 93 if ($_GET["fGetValCase"]==1)//show only in edit mode 94 printf("<th>Action</th>\n"); 95 printf("<th>Min</th>\n"); 96 printf("<th>Max</th>\n"); 97 printf("</tr>\n"); 98 $maxindex=0; 99 if ($result0) 100 while ($row0 = mysql_fetch_row($result0)) 101 { 102 if ($_GET["fGetValCase"]==1) 103 { 104 if ($row0[6]==$counter) 105 printf("<tr id='new%s' style='display:'>\n", $row0[0]); 106 else 107 printf("<tr id='old%s' style='display:none'>\n", $row0[0]); 108 } 109 else 110 printf("<tr id='%scompare%s' style='display:'>\n", $_GET["fGetValCase"], $row0[12]); 69 111 70 mysql_free_result($result0); 112 printf("<td> %s / %s / %s <div id='%dorigindex%s' style='display:none'>%s</div> </td>\n", 113 $row0[0], $row0[12], $row0[6], $_GET["fGetValCase"], $row0[0], $row0[12]); 114 if (strcmp('0000-00-00 00:00:00', $row0[1])==0) 115 printf("<td id='notyetvalid%s'> %s </td>\n", $row0[0], $row0[1]); 116 else 117 printf("<td> %s </td>\n", $row0[1]); 118 printf("<td id='prog%s'>%s</td>\n", $row0[0], $row0[2]); 119 //printf("<td id='key%s'>%s</td>\n", $row0[0], $row0[3]); 120 printf("<td id='1key%s'>%s</td>\n", $row0[0], $row0[10]); 121 printf("<td id='2key%s'>%s</td>\n", $row0[0], $row0[11]); 122 printf("<td align='right' id='val%s'>%s</td>\n", $row0[0], $row0[4]); 123 printf("<td id='type%s'>%s</td>\n", $row0[0], $row0[7]); 124 if ($_GET["fGetValCase"]==1)//show only in edit mode 125 printf("<td class='description%d' id='descr%s'>%s</td>\n", $_GET["fGetValCase"], $row0[0], $row0[5]); 126 else 127 printf("<td class='description%d' style='display:none' id='descr%s'>%s</td>\n", $_GET["fGetValCase"], $row0[0], $row0[5]); 128 if ($_GET["fGetValCase"]==1)//show only in edit mode 129 { 130 if ($row0[6]==$counter) 131 printf("<td id='action%s'><input type='button' value='Edit' onclick='EditRow(\"%s\")'></td>\n", $row0[0], $row0[0]); 132 else 133 printf("<td id='action%s'></td>\n", $row0[0]); 134 } 135 printf("<td id='min%s'>%s</td>\n", $row0[0], $row0[8]); 136 printf("<td id='max%s'>%s</td>\n", $row0[0], $row0[9]); 137 printf("</tr>\n"); 138 if ($row0[0]>$maxindex) 139 $maxindex=$row0[0]; 140 } 141 printf("</tbody></table>\n"); 142 if ($_GET["fGetValCase"]==1) 143 { 144 printf("<button onClick='ShowCurrent();' id='showcurrent2' style='display:none'>Show Current</button>\n"); 145 printf("<button onClick='ShowAll();' id='showall2' style='display:inline'>Show History</button>\n"); 146 printf("<button onClick='addRow(3,\"%s\",\"%s\",\"%s\",\"%s\",\"%s\");' id='addrowvals2' style='display:inline'>Add Value</button>\n", 147 $_GET["fProgram"], $_GET["fKey"], $key1, $key2, $type); 148 } 149 else 150 { 151 printf("<button onClick='HideDescription(%d);' id='hidedescr%d' style='display:none'>Hide Description</button>\n", $_GET["fGetValCase"], $_GET["fGetValCase"]); 152 printf("<button onClick='ShowDescription(%d);' id='showdescr%d' style='display:'>Show Description</button>\n", $_GET["fGetValCase"], $_GET["fGetValCase"]); 153 } 154 155 if ($_GET["fGetValCase"]==3) 156 printf("<div id='maxindex3' style='display:none'>%s</div>\n", $maxindex); 157 else 158 printf("<div id='maxindex' style='display:none'>%s</div>\n", $maxindex); 159 160 if ($result0) 161 mysql_free_result($result0); 71 162 72 163 mysql_close($db_id); -
trunk/www/db_po/insert_po.php
r11353 r11505 11 11 if (empty($_GET["fIndex"])) 12 12 { 13 echo "Please giv an index.<br>";13 echo "Please give an index.<br>"; 14 14 return; 15 15 } … … 19 19 return; 20 20 } 21 if (empty($_GET["fKey"])) 22 { 23 echo "Please select a key.<br>"; 21 if (empty($_GET["fKey1"])) 22 { 23 echo "Please select a key1.<br>"; 24 return; 25 } 26 if (empty($_GET["fKey2"])) 27 { 28 echo "Please select a key2.<br>"; 24 29 return; 25 30 } … … 31 36 if (empty($_GET["fDescription"])) 32 37 { 33 echo "Please insert a Description.<br>"; 34 return; 35 } 36 37 38 echo "Please insert a description.<br>"; 39 return; 40 } 41 if (empty($_GET["fType"])) 42 { 43 echo "Please select a type.<br>"; 44 return; 45 } 46 if (empty($_GET["fOriginalIndex"])) 47 $_GET["fOriginalIndex"]=""; 38 48 39 49 include("db.php"); 40 50 $db_id = mysqli_connect($host, $user, $pw, $db); 41 //if ($db_id==FALSE)42 51 if (mysqli_connect_errno()) 43 52 { … … 45 54 die(""); 46 55 } 47 //mysql_select_db($db); 56 57 //query old entry 58 $query1="SELECT fValue, fProgram, fKey1, fDescription, fType, fMin, fMax, fKey2 from ProgramOption WHERE fIndex='".$_GET["fIndex"]."';"; 59 //compare new values to old values 60 //insert only, if at least one values is new 61 // update counter only if value is updated 62 if (!$result1=mysqli_query($db_id, $query1)) 63 { 64 echo "Error sending query: ".$query1; 65 return; 66 } 67 $row1 = mysqli_fetch_row($result1); 68 69 if ($_GET["fUpdCase"]!=4 70 && strcmp($row1[0],$_GET["fValue"])==0 71 && strcmp($row1[1],$_GET["fProgram"])==0 72 && strcmp($row1[2],$_GET["fKey1"])==0 73 && strcmp($row1[7],$_GET["fKey2"])==0 74 && strcmp($row1[3],$_GET["fDescription"])==0 75 && strcmp($row1[4],$_GET["fType"])==0 76 //&& strcmp($row1[5],$_GET["fMin"])==0 77 //&& strcmp($row1[6],$_GET["fMax"])==0 78 ) 79 { 80 // be careful, this output is evaluated by UpdateRow() in po.js 81 echo "no change"; 82 mysqli_free_result($result1); 83 return; 84 } 85 else 86 mysqli_free_result($result1); 87 88 //check if key alread exists 89 $query2="SELECT Count(*) from ProgramOption WHERE fKey1='".$_GET["fKey1"]."' AND fKey2='.".$_GET["fKey2"]."'"; 90 $query2.=" AND fCounter=(Select Max(fCounter) from History)"; 91 if (!$result2=mysqli_query($db_id, $query2)) 92 { 93 echo "Error sending query: ".$query2; 94 return; 95 } 96 $row2 = mysqli_fetch_row($result2); 97 if (($_GET["fUpdCase"]==1 || $_GET["fUpdCase"]==5) && $row2[0]>0) 98 { 99 // be careful, this output is evaluated by UpdateRow() in po.js 100 echo "key exists"; 101 mysqli_free_result($result2); 102 return; 103 } 104 else 105 mysqli_free_result($result2); 106 107 //check if program alread exists 108 $query3="SELECT Count(*) from ProgramOption WHERE fProgram='".$_GET["fProgram"]."'"; 109 $query3.=" AND fCounter=(Select Max(fCounter) from History)"; 110 if (!$result3=mysqli_query($db_id, $query3)) 111 { 112 echo "Error sending query: ".$query3; 113 return; 114 } 115 $row3 = mysqli_fetch_row($result3); 116 if ($_GET["fUpdCase"]==5 && $row3[0]>0) 117 { 118 // be careful, this output is evaluated by UpdateRow() in po.js 119 echo "prog exists"; 120 mysqli_free_result($result3); 121 return; 122 } 123 else 124 mysqli_free_result($result3); 125 126 //note for fType: 127 //SHOW COLUMNS FROM ProgramOption LIKE 'fType'; 48 128 49 129 //new entry in table ProgramOption 50 $query0="INSERT ProgramOption SET "; 51 $query0.="fProgram='".$_GET["fProgram"]."'"; 52 $query0.=", fKey='".$_GET["fKey"]."'"; 53 if ($_GET["fUpdCase"]==2 || $_GET["fUpdCase"]==3) 54 $query0.=", fValue='".$_GET["fValue"]."'"; 55 if ($_GET["fUpdCase"]==1 || $_GET["fUpdCase"]==4) 56 $query0.=", fValue=NULL"; 57 $query0.=", fDescription='".$_GET["fDescription"]."'"; 58 $query0.=", fValidFrom=Now() "; 59 if ($_GET["fUpdCase"]==1) 60 $query0.=", fCounter= (Select Max(fCounter) from History) ;"; 61 else 62 $query0.=", fCounter= (Select Max(fCounter) from History)+1 ;"; 63 64 //update counter for other valid entries in ProgramOption 65 $query0.=" UPDATE ProgramOption SET "; 66 $query0.=" fCounter= (Select Max(fCounter) from History)+1 "; 67 $query0.=" WHERE fCounter= (Select Max(fCounter) from History) "; 68 if ($_GET["fUpdCase"]==3 || $_GET["fUpdCase"]==4) 69 $query0.=" AND NOT fIndex=".$_GET["fIndex"]; 70 $query0.=" AND NOT ISNULL(fValue); "; 71 72 //insert new counter to history 73 if ($_GET["fUpdCase"]!=1) 74 { 130 //update only in case 3 if value is not changed 131 if ($_GET["fUpdCase"]==6) 132 $query0="DELETE FROM ProgramOption "; 133 else 134 { 135 if (strcmp($row1[0],$_GET["fValue"])==0 && $_GET["fUpdCase"]==3) 136 $query0="UPDATE "; 137 else 138 $query0="INSERT "; 139 $query0.=" ProgramOption SET "; 140 // set program, key, description, type 141 $query0.="fProgram='".$_GET["fProgram"]."'"; 142 if (!empty($_GET["fOriginalIndex"])) 143 $query0.=", fOriginalIndex='".$_GET["fOriginalIndex"]."'"; 144 $query0.=", fKey1='".$_GET["fKey1"]."'"; 145 $query0.=", fKey2='.".$_GET["fKey2"]."'"; 146 $query0.=", fDescription='".$_GET["fDescription"]."'"; 147 $query0.=", fType='".$_GET["fType"]."'"; 148 // set value 149 // change value in case is was 150 if ($_GET["fUpdCase"]==2 //inserted 151 || ($_GET["fUpdCase"]==3 && strcmp($row1[0],$_GET["fValue"])!=0))// changed 152 $query0.=", fValue='".$_GET["fValue"]."'"; 153 // set to NULL in case it was 154 if ($_GET["fUpdCase"]==1 || $_GET["fUpdCase"]==5 //new insert 155 || $_GET["fUpdCase"]==4) //delete 156 $query0.=", fValue=NULL"; 157 //increase counter in case value was 158 if ($_GET["fUpdCase"]==2//created 159 || ($_GET["fUpdCase"]==3 && strcmp($row1[0],$_GET["fValue"])!=0)//changed 160 || $_GET["fUpdCase"]==4)//deleted 161 { 162 $query0.=", fValidFrom=Now() "; 163 $query0.=", fCounter= (Select Max(fCounter) from History)+1 "; 164 } 165 else//else set current counter 166 $query0.=", fCounter= (Select Max(fCounter) from History) "; 167 } 168 //do update only for current row 169 if ((strcmp($row1[0],$_GET["fValue"])==0 && $_GET["fUpdCase"]==3) || $_GET["fUpdCase"]==6) 170 $query0.=" WHERE fIndex=".$_GET["fIndex"]; 171 if ($_GET["fUpdCase"]==6) 172 $query0.=" AND fValidFrom='0000-00-00 00:00:00'"; 173 $query0.=";"; 174 175 //update counter in case value was 176 if ($_GET["fUpdCase"]==2 //created 177 || ($_GET["fUpdCase"]==3 && strcmp($row1[0],$_GET["fValue"])!=0)//changed 178 || $_GET["fUpdCase"]==4)//deleted 179 { 180 //update counter for other valid entries in ProgramOption 181 $query0.=" UPDATE ProgramOption SET "; 182 $query0.=" fCounter= (Select Max(fCounter) from History)+1 "; 183 $query0.=" WHERE fCounter= (Select Max(fCounter) from History) "; 184 if ($_GET["fUpdCase"]==3 || $_GET["fUpdCase"]==4) 185 $query0.=" AND NOT fIndex=".$_GET["fIndex"]; 186 $query0.=" AND ((NOT ISNULL(fValue) AND NOT fValidFrom='0000-00-00 00:00:00') ";//normal entries, but not deleted ones 187 $query0.=" OR (ISNULL(fValue) AND fValidFrom='0000-00-00 00:00:00')); ";//new entries 188 189 //insert new counter to history 75 190 $query0.=" INSERT History SET "; 76 191 $query0.=" fCounter= (Select Max(fCounter) from ProgramOption) "; … … 78 193 } 79 194 80 81 /*82 if ($_GET["fUpdCase"]==1 || $_GET["fUpdCase"]==2)83 $query0 ="INSERT ProgramOption SET ";//insert key or insert value84 else85 $query0 ="UPDATE ProgramOption SET ";//update value (includes 'delete')86 87 if ($_GET["fUpdCase"]==4)//i.e. delete88 $query0.=" fValue=NULL";89 else90 {91 $query0.="fProgram='".$_GET["fProgram"]."'";92 $query0.=", fKey='".$_GET["fKey"]."'";93 $query0.=", fValue='".$_GET["fValue"]."'";94 $query0.=", fDescription='".$_GET["fDescription"]."'";95 $query0.=", fValidFrom=Now() ";96 }97 98 if ($_GET["fUpdCase"]==1 || $_GET["fUpdCase"]==2) //only in case of insert99 $query0.=", fValidFrom=Now() ";100 101 if ($_GET["fUpdCase"]==3 || $_GET["fUpdCase"]==4)// only in case of update102 $query0.="WHERE fIndex=".$_GET["fIndex"]."; ";103 104 if ($_GET["fUpdCase"]==2 || $_GET["fUpdCase"]==3)// only when value is changed (includes insert)105 {106 $query0.="UPDATE ProgramOption SET fCounter=(Select Max(fCounter) from History)+1 WHERE NOT ISNULL(fValue); ";107 $query0.="INSERT History SET fCounter=(Select Max(fCounter) from ProgramOption), fValidFrom=Now(); ";108 }109 */110 111 //echo $query0;112 195 $result0=mysqli_multi_query($db_id, $query0); 113 196 if ($result0) -
trunk/www/db_po/po.js
r11353 r11505 1 2 //function 3 function get_keys(prog) 4 { 5 //alert(prog); 6 7 var xmlhttp; 8 if (window.XMLHttpRequest) 9 {// code for IE7+, Firefox, Chrome, Opera, Safari 10 xmlhttp=new XMLHttpRequest(); 11 } 12 else 13 {// code for IE6, IE5 14 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 15 } 16 xmlhttp.open("GET","get_keys.php?fProgram="+prog,false); 1 var xmlhttp; 2 if (window.XMLHttpRequest) 3 {// code for IE7+, Firefox, Chrome, Opera, Safari 4 xmlhttp=new XMLHttpRequest(); 5 } 6 else 7 {// code for IE6, IE5 8 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 9 } 10 11 //function to get programs from the db 12 function get_progs(prog, selectsize, mode) 13 { 14 xmlhttp.open("GET","get_progs.php?fProgram="+prog+"&fSelectSize="+selectsize+"&fMode="+mode,false); 17 15 xmlhttp.send(); 18 16 if (xmlhttp.readyState==4 && xmlhttp.status==200) 19 17 { 20 document.getElementById('keyfield').innerHTML = xmlhttp.responseText; 21 document.getElementById('valuefield').innerHTML = ""; 22 } 23 else 24 document.getElementById('keyfield').innerHTML = "argh"; 25 26 } 27 28 //function 29 function get_values(prog, key) 30 { 31 //alert(prog+"---"+key); 32 var xmlhttp; 33 if (window.XMLHttpRequest) 34 {// code for IE7+, Firefox, Chrome, Opera, Safari 35 xmlhttp=new XMLHttpRequest(); 36 } 37 else 38 {// code for IE6, IE5 39 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 40 } 41 xmlhttp.open("GET","get_values.php?fKey="+key+"&fProgram="+prog,false); 18 document.getElementById('progfield').innerHTML = xmlhttp.responseText; 19 document.getElementById('keyfield').innerHTML = ""; 20 if (document.getElementById('valuefield1')) 21 document.getElementById('valuefield1').innerHTML = ""; 22 } 23 else 24 document.getElementById('progfield').innerHTML = "argh"; 25 } 26 27 //function to get keys from the db 28 function get_keys(prog, key, selectsize, mode) 29 { 30 xmlhttp.open("GET","get_keys.php?fProgram="+prog+"&fKey="+key+"&fSelectSize="+selectsize+"&fMode="+mode,false); 42 31 xmlhttp.send(); 43 32 if (xmlhttp.readyState==4 && xmlhttp.status==200) 44 33 { 45 document.getElementById('valuefield').innerHTML = xmlhttp.responseText; 46 if (key=='newkey') 47 addRow(prog, key); 48 } 49 else 50 document.getElementById('valuefield').innerHTML = "argh"; 51 } 52 53 function addRow(prog, key) 54 { 55 tabBody=document.getElementById("valtable"); 34 document.getElementById('keyfield').innerHTML = xmlhttp.responseText; 35 if (document.getElementById('valuefield1')) 36 document.getElementById('valuefield1').innerHTML = ""; 37 } 38 else 39 document.getElementById('keyfield').innerHTML = "argh"; 40 41 if(document.getElementById('addrowprog')) 42 document.getElementById('addrowprog').style.display = ""; 43 } 44 45 function get_statusdate(getvalcase, val) 46 { 47 if (!val) 48 { 49 radio=document.getElementsByName('dateformat'+getvalcase); 50 for (i=0; i< radio.length; i++) 51 if (radio[i].checked) 52 val=radio[i].value; 53 } 54 if (val=="pulldown") 55 { 56 year=document.getElementById('year'+getvalcase).value; 57 month=document.getElementById('month'+getvalcase).value; 58 day=document.getElementById('day'+getvalcase).value; 59 hour=document.getElementById('hour'+getvalcase).value; 60 min=document.getElementById('min'+getvalcase).value; 61 sec=document.getElementById('sec'+getvalcase).value; 62 if (year=="empty") 63 statusdate=""; 64 else 65 { 66 statusdate=year; 67 if (month!="empty") 68 { 69 statusdate=statusdate+"-"+month; 70 if (day!="empty") 71 { 72 statusdate=statusdate+"-"+day; 73 if (hour!="empty") 74 { 75 statusdate=statusdate+" "+hour; 76 if (min!="empty") 77 { 78 statusdate=statusdate+":"+min; 79 if (sec!="empty") 80 statusdate=statusdate+":"+sec; 81 } 82 } 83 } 84 } 85 } 86 } 87 if (val=="textinput") 88 statusdate=document.getElementById('statusdate'+getvalcase).value; 89 return statusdate; 90 } 91 92 //function to get values from the db 93 function get_values(getvalcase, prog, key, mode) 94 { 95 if (parseInt(getvalcase)>1) 96 { 97 //get prog and key 98 progselect=document.getElementById("prog"); 99 if (!progselect) 100 prog="all"; 101 else 102 if (progselect.options[progselect.selectedIndex]) 103 prog=progselect.options[progselect.selectedIndex].value; 104 else 105 prog="all"; 106 keyselect=document.getElementById("key"); 107 if (!keyselect) 108 key="all"; 109 else 110 if (keyselect.options[keyselect.selectedIndex]) 111 key=keyselect.options[keyselect.selectedIndex].value; 112 else 113 key="all"; 114 } 115 if (mode=="view" && getvalcase==1) 116 return; 117 //if (getvalcase==3) 118 // document.getElementById('comparevals').style.display = ""; 119 if ((getvalcase==2 || getvalcase==3) && document.getElementById('statusdate'+getvalcase)) 120 { 121 statusdate=get_statusdate(getvalcase); 122 //alert(statusdate); 123 phpcall="get_values.php?fStatusDate="+statusdate+"&fGetValCase="+getvalcase+"&fKey="+key+"&fProgram="+prog; 124 } 125 else 126 phpcall="get_values.php?fGetValCase="+getvalcase+"&fKey="+key+"&fProgram="+prog; 127 128 xmlhttp.open("GET",phpcall,false); 129 xmlhttp.send(); 130 if (xmlhttp.readyState==4 && xmlhttp.status==200) 131 document.getElementById('valuefield'+getvalcase).innerHTML = xmlhttp.responseText; 132 else 133 document.getElementById('valuefield'+getvalcase).innerHTML = "argh"; 134 135 if(document.getElementById('addrowkey')) 136 document.getElementById('addrowkey').style.display = ""; 137 } 138 139 function addRow(addcase, prog, key, key1, key2, type) 140 { 141 if (!prog) 142 { 143 progselect=document.getElementById("prog"); 144 if (progselect.options[progselect.selectedIndex]) 145 prog=progselect.options[progselect.selectedIndex].value; 146 else 147 prog='all'; 148 } 149 if (!key) 150 { 151 keyselect=document.getElementById("key"); 152 if (!keyselect) 153 key='all'; 154 else 155 if (keyselect.options[keyselect.selectedIndex]) 156 key=keyselect.options[keyselect.selectedIndex].value; 157 else 158 key='all'; 159 } 160 switch(addcase) 161 { 162 case 1: 163 get_keys(prog,key,"10", "edit"); 164 case 2: 165 get_values(1, prog, key); 166 } 167 168 if (prog=='all' && (addcase==3 || addcase==2)) 169 addcase=1; 170 if (key=='all' && addcase==3) 171 addcase=2; 172 173 174 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) 175 if(document.getElementById('action'+i)) 176 //document.getElementById('action'+i).innerHTML = ""; 177 document.getElementById('action'+i).style.display = "none"; 178 179 tabBody=document.getElementById("valtable1"); 56 180 row=document.createElement("TR"); 57 181 row.id='val0'; … … 62 186 cell4 = document.createElement("TD"); 63 187 cell5 = document.createElement("TD"); 64 //case add new key (value NULL) 65 if (key=='newkey') 66 { 188 cell6 = document.createElement("TD"); 189 cell7 = document.createElement("TD"); 190 cell8 = document.createElement("TD"); 191 cell9 = document.createElement("TD"); 192 cell10 = document.createElement("TD"); 193 var updcase; 194 195 // addcase: three cases 196 // 1: add new prog+key, val=NULL 197 // 2: add new key, val=NULL, prog=selected 198 // 3: add new val, prog=selected, key=selected, type fixed 199 switch(addcase) 200 { 201 case 1: 202 //field for prog 67 203 input1 = document.createElement("INPUT"); 68 input1.value = prog;69 204 input1.id = 'prog0'; 205 cell1.appendChild(input1); 206 //fields for keys 70 207 input2 = document.createElement("INPUT"); 71 input2.value = 'newkey'; 72 input2.id = 'key0'; 208 input2.id = '1key0'; 209 cell2.appendChild(input2); 210 input10 = document.createElement("INPUT"); 211 input10.id = '2key0'; 212 cell10.appendChild(input10); 213 //field for val 73 214 cell3.id = 'newval0'; 74 215 textnode3=document.createTextNode("NULL"); 75 input4 = document.createElement("INPUT"); 76 input4.id = 'newdescr0'; 77 input5 = document.createElement("input"); 78 input5.value = 'Add'; 79 input5.type = "button"; 80 input5.onclick = function () { UpdateRow(1, 0); onclick() } 81 cell1.appendChild(input1); 216 cell3.appendChild(textnode3); 217 updcase=5; 218 //field type 219 select7 = document.createElement("select"); 220 select7.id = 'newtype0'; 221 select7.option = 'string'; 222 option7a = document.createElement("option"); 223 option7a.text = '-'; 224 option7a.value = ''; 225 select7.appendChild(option7a); 226 option7b = document.createElement("option"); 227 option7b.id = 'int'; 228 option7b.text = 'int'; 229 option7b.value = 'int'; 230 select7.appendChild(option7b); 231 option7c = document.createElement("option"); 232 option7c.id = 'float'; 233 option7c.text = 'float'; 234 option7c.value = 'float'; 235 select7.appendChild(option7c); 236 option7d = document.createElement("option"); 237 option7d.id = 'string'; 238 option7d.text = 'string'; 239 option7d.value = 'string'; 240 select7.appendChild(option7d); 241 option7e = document.createElement("option"); 242 option7e.id = 'bool'; 243 option7e.text = 'bool'; 244 option7e.value = 'bool'; 245 select7.appendChild(option7e); 246 cell7.appendChild(select7); 247 break; 248 case 2: 249 //field for prog 250 cell1.id = 'prog0'; 251 textnode1=document.createTextNode(prog); 252 cell1.appendChild(textnode1); 253 //field for key 254 input2 = document.createElement("INPUT"); 255 input2.id = '1key0'; 82 256 cell2.appendChild(input2); 257 input10 = document.createElement("INPUT"); 258 input10.id = '2key0'; 259 cell10.appendChild(input10); 260 //field for val 261 cell3.id = 'newval0'; 262 textnode3=document.createTextNode("NULL"); 83 263 cell3.appendChild(textnode3); 84 cell4.appendChild(input4); 85 cell5.appendChild(input5); 86 //cell5.appendChild(button5); 87 } 88 //case add new val for same key 89 else 90 { 264 updcase=1; 265 //field type 266 select7 = document.createElement("select"); 267 select7.id = 'newtype0'; 268 select7.option = 'string'; 269 option7a = document.createElement("option"); 270 option7a.text = '-'; 271 option7a.value = ''; 272 select7.appendChild(option7a); 273 option7b = document.createElement("option"); 274 option7b.id = 'int'; 275 option7b.text = 'int'; 276 option7b.value = 'int'; 277 select7.appendChild(option7b); 278 option7c = document.createElement("option"); 279 option7c.id = 'float'; 280 option7c.text = 'float'; 281 option7c.value = 'float'; 282 select7.appendChild(option7c); 283 option7d = document.createElement("option"); 284 option7d.id = 'string'; 285 option7d.text = 'string'; 286 option7d.value = 'string'; 287 select7.appendChild(option7d); 288 option7e = document.createElement("option"); 289 option7e.id = 'bool'; 290 option7e.text = 'bool'; 291 option7e.value = 'bool'; 292 select7.appendChild(option7e); 293 cell7.appendChild(select7); 294 break; 295 case 3: 296 //field for prog 91 297 cell1.id = 'prog0'; 92 cell2.id = 'key0';93 298 textnode1=document.createTextNode(prog); 94 textnode2=document.createTextNode(key); 299 cell1.appendChild(textnode1); 300 //field for key 301 cell2.id = '1key0'; 302 textnode2=document.createTextNode(key1); 303 cell2.appendChild(textnode2); 304 cell10.id = '2key0'; 305 textnode10=document.createTextNode(key2); 306 cell10.appendChild(textnode10); 307 //field for val 95 308 input3 = document.createElement("INPUT"); 96 309 input3.id = 'newval0'; 97 input4 = document.createElement("INPUT");98 input4.id = 'newdescr0';99 input5 = document.createElement("input");100 input5.value = 'Add';101 input5.type = "button";102 input5.onclick = function () { UpdateRow(2, 0); onclick() }103 cell1.appendChild(textnode1);104 cell2.appendChild(textnode2);105 310 cell3.appendChild(input3); 106 cell4.appendChild(input4); 107 cell5.appendChild(input5); 108 } 109 row.appendChild(cell0); 110 row.appendChild(cell1); 111 row.appendChild(cell2); 112 row.appendChild(cell3); 113 row.appendChild(cell4); 114 row.appendChild(cell5); 311 updcase=2; 312 //field type 313 cell7.id = 'type0'; 314 textnode7 = document.createTextNode(type); 315 cell7.appendChild(textnode7); 316 break; 317 default: 318 break; 319 } 320 321 //field descr 322 input4 = document.createElement("INPUT"); 323 input4.id = 'newdescr0'; 324 cell4.appendChild(input4); 325 //field action 326 input5a = document.createElement("input"); 327 input5a.value = 'Add'; 328 input5a.type = "button"; 329 input5a.onclick = function () { UpdateRow(updcase, 0); onclick() } 330 cell5.appendChild(input5a); 331 input5b = document.createElement("input"); 332 input5b.value = 'Cancel'; 333 input5b.type = "button"; 334 input5b.onclick = function () { CancelAddRow(prog, key); onclick() } 335 cell5.appendChild(input5b); 336 337 row.appendChild(cell0);//index, counter 338 row.appendChild(cell6);//valid from 339 row.appendChild(cell1);//prog 340 row.appendChild(cell2);//key1 341 row.appendChild(cell10);//key2 342 row.appendChild(cell3);//value 343 row.appendChild(cell7);//type 344 row.appendChild(cell4);//descr 345 row.appendChild(cell5);//action 346 row.appendChild(cell8);//min 347 row.appendChild(cell9);//max 115 348 tabBody.appendChild(row); 116 349 117 350 // to be removed later when solution for adding multiple new rows is found 118 document.getElementById('addrow').style.display = "none"; 351 document.getElementById('addrowvals').style.display = "none"; 352 document.getElementById('addrowvals2').style.display = "none"; 353 document.getElementById('addrowkey').style.display = "none"; 354 document.getElementById('addrowprog').style.display = "none"; 355 } 356 357 function CancelAddRow(prog, key) 358 { 359 //get select program and key 360 if (!prog) 361 { 362 progselect=document.getElementById("prog"); 363 prog=progselect.options[progselect.selectedIndex].value; 364 } 365 if (!key) 366 { 367 keyselect=document.getElementById("key"); 368 key=keyselect.options[keyselect.selectedIndex].value; 369 } 370 //reload the original content in case of cancel 371 get_values(1, prog, key); 372 373 // to be removed later when solution for adding multiple new rows is found 374 document.getElementById('addrowvals').style.display = ""; 375 document.getElementById('addrowvals2').style.display = ""; 376 document.getElementById('addrowkey').style.display = ""; 377 document.getElementById('addrowprog').style.display = ""; 378 } 379 380 function CancelUpdate() 381 { 382 //get select program and key 383 progselect=document.getElementById("prog"); 384 prog=progselect.options[progselect.selectedIndex].value; 385 keyselect=document.getElementById("key"); 386 key=keyselect.options[keyselect.selectedIndex].value; 387 //reload the original table in case of cancel 388 get_values(1, prog, key); 119 389 } 120 390 121 391 function EditRow(index) 122 392 { 393 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) 394 if(document.getElementById('action'+i) && i!=index) 395 //document.getElementById('action'+i).innerHTML = ""; 396 document.getElementById('action'+i).style.display = "none"; 397 398 //get current values 123 399 oldval=document.getElementById('val'+index).innerHTML; 124 document.getElementById('val'+index).innerHTML = "<input align='right' id='newval"+index+"' value='"+oldval+"'>";125 400 olddescr=document.getElementById('descr'+index).innerHTML; 401 oldtype=document.getElementById('type'+index).innerHTML; 402 if (!oldval) 403 delcase=6; 404 else 405 delcase=4; 406 //set field for value 407 if (oldtype=='bool') 408 { 409 if (oldval=='yes') 410 textval="<input name='boolbox' type='radio' id='newval"+index+"' value='yes' checked> yes"; 411 else 412 textval="<input name='boolbox' type='radio' id='newval"+index+"' value='yes'> yes"; 413 if (oldval=='no') 414 textval=textval+"<input name='boolbox' type='radio' id='newval"+index+"' value='no' checked> no" 415 else 416 textval=textval+"<input name='boolbox' type='radio' id='newval"+index+"' value='no'> no" 417 } 418 else 419 textval="<input align='right' id='newval"+index+"' value='"+oldval+"'>"; 420 document.getElementById('val'+index).innerHTML = textval; 421 //set field for description 126 422 document.getElementById('descr'+index).innerHTML = "<input align='right' id='newdescr"+index+"' value='"+olddescr+"'>"; 127 document.getElementById('action'+index).innerHTML = 128 "<input type='button' value='Update' onclick='UpdateRow(3,"+index+")'>" 129 +"<input type='button' value='Delete' onclick='UpdateRow(4,"+index+")'>"; 423 /* 424 //set field for type 425 typeselecttext="<select id='newtype"+index+"' value='"+oldtype+"'>"+"<option>-</option>"; 426 if (oldtype=='int') 427 typeselecttext=typeselecttext+"<option selected>int</option>"; 428 else 429 typeselecttext=typeselecttext+"<option>int</option>"; 430 if (oldtype=='float') 431 typeselecttext=typeselecttext+"<option selected>float</option>"; 432 else 433 typeselecttext=typeselecttext+"<option>float</option>"; 434 if (oldtype=='string') 435 typeselecttext=typeselecttext+"<option selected>string</option>"; 436 else 437 typeselecttext=typeselecttext+"<option>string</option>"; 438 if (oldtype=='bool') 439 typeselecttext=typeselecttext+"<option selected>bool</option>"; 440 else 441 typeselecttext=typeselecttext+"<option>bool</option>"; 442 typeselecttext=typeselecttext+"</select>"; 443 document.getElementById('type'+index).innerHTML = typeselecttext; 444 */ 445 446 //set field for action 447 actiontext="<input type='button' value='Update' onclick='UpdateRow(3,"+index+")'>"; 448 notyetvalid=document.getElementById('notyetvalid'+index) 449 if (delcase!=6 || notyetvalid) 450 actiontext=actiontext+"<input type='button' value='Delete' onclick='UpdateRow("+delcase+","+index+")'>"; 451 actiontext=actiontext+"<input type='button' value='Cancel' onclick='CancelUpdate()'>"; 452 document.getElementById('action'+index).innerHTML =actiontext; 130 453 } 131 454 132 455 function UpdateRow(updcase,index) 133 456 { 134 // three cases of update 135 // 1: add new key 136 // 2: add new val (for same key) 137 // 3: edit val 138 // 4: delete val (ie set to NULL) 139 if (updcase==1) 140 { 457 // five cases of update corresponds to 458 // 5: add new prog + key addcase 1 459 // 1: add new key addcase 2 460 // 2: add new val (for same key) addcase 3 -> same type 461 // 3: edit val -> same type 462 // 4: delete val (ie set to NULL) -> same type 463 // 6: delete new key (ie val still NULL) -> real delete 464 descr=document.getElementById('newdescr'+index).value; 465 origindex=0; 466 switch(updcase) 467 { 468 case 5: 141 469 prog=document.getElementById('prog'+index).value; 142 key=document.getElementById('key'+index).value; 143 } 144 else 145 { 470 key1=document.getElementById('1key'+index).value; 471 key2=document.getElementById('2key'+index).value; 472 val=document.getElementById('newval'+index).innerHTML; 473 type=document.getElementById('newtype'+index).value; 474 break; 475 case 1: 476 //prog=document.getElementById('prog'+index).value; 146 477 prog=document.getElementById('prog'+index).innerHTML; 147 key=document.getElementById('key'+index).innerHTML; 148 } 149 if (updcase==1) 478 key1=document.getElementById('1key'+index).value; 479 key2=document.getElementById('2key'+index).value; 150 480 val=document.getElementById('newval'+index).innerHTML; 151 else 481 type=document.getElementById('newtype'+index).value; 482 break; 483 case 2: 484 //prog=document.getElementById('prog'+index).value; 485 prog=document.getElementById('prog'+index).innerHTML; 486 key1=document.getElementById('1key'+index).innerHTML; 487 key2=document.getElementById('2key'+index).innerHTML; 152 488 val=document.getElementById('newval'+index).value; 153 descr=document.getElementById('newdescr'+index).value; 489 type=document.getElementById('type'+index).innerHTML; 490 break; 491 case 3: 492 prog=document.getElementById('prog'+index).innerHTML; 493 key1=document.getElementById('1key'+index).innerHTML; 494 key2=document.getElementById('2key'+index).innerHTML; 495 type=document.getElementById('type'+index).innerHTML; 496 val="hallo"; 497 if (type=="bool") 498 { 499 radio=document.getElementsByName('boolbox'); 500 for (i=0; i< radio.length; i++) 501 if (radio[i].checked) 502 val=radio[i].value; 503 } 504 else 505 val=document.getElementById('newval'+index).value; 506 origindex=document.getElementById('1origindex'+index).innerHTML; 507 break; 508 case 4: 509 case 6: 510 answer = confirm("Do you really want to delete the value?"); 511 if (!answer) 512 return; 513 prog=document.getElementById('prog'+index).innerHTML; 514 key1=document.getElementById('1key'+index).innerHTML; 515 key2=document.getElementById('2key'+index).innerHTML; 516 val=document.getElementById('newval'+index).value; 517 if (!val) 518 val="NULL"; 519 type=document.getElementById('type'+index).innerHTML; 520 origindex=document.getElementById('1origindex'+index).innerHTML; 521 break; 522 } 154 523 if (!descr) 155 524 alert("Please insert description!"); 156 if (!key) 157 alert("Please insert key!"); 525 if (!key1) 526 alert("Please insert key1!"); 527 if (!key2) 528 alert("Please insert key2!"); 158 529 if (!val) 159 530 alert("Please insert value!"); 160 if (!val || !descr || !key )531 if (!val || !descr || !key1 || !key2) 161 532 return; 162 533 if (index==0) 163 534 index=-1; 164 535 165 phpcall="insert_po.php?fUpdCase="+updcase+"&fIndex="+index+"&fProgram="+prog+"&fKey="+key+"&fValue="+val+"&fDescription="+descr; 166 //alert("u/i --- "+index+" --- "+prog+" --- "+key+" --- "+val+" --- "+descr); 536 //check if value has correct type 537 // for string no check needed 538 if (updcase==3) 539 { 540 if (type=='int' && parseInt(val)!=val) 541 { 542 alert("Value is not a int."); 543 return; 544 } 545 if (type=='float' && parseFloat(val)!=val) 546 { 547 alert("Value is not a float."); 548 return; 549 } 550 if (type=='bool' && val!='yes' && val!='no') 551 { 552 alert("Value is neither 'yes' not 'no'."); 553 return; 554 } 555 } 556 if (!type && (updcase==2 || updcase==3 || updcase==4)) 557 { 558 alert("Please select type!"); 559 return; 560 } 561 562 phpcall="insert_po.php?fUpdCase="+updcase+"&fIndex="+index+"&fOriginalIndex="+origindex+"&fProgram="+prog 563 +"&fKey1="+key1+"&fKey2="+key2+"&fValue="+val+"&fDescription="+descr+"&fType="+type; 167 564 //alert(phpcall); 168 565 169 var xmlhttp;170 if (window.XMLHttpRequest)171 {// code for IE7+, Firefox, Chrome, Opera, Safari172 xmlhttp=new XMLHttpRequest();173 }174 else175 {// code for IE6, IE5176 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");177 }178 566 xmlhttp.open("GET", phpcall, false); 179 567 xmlhttp.send(); 568 569 // get somehow return value of inser_po.php 570 // to catch cases where insert was rejected due to no update 180 571 if (xmlhttp.readyState==4 && xmlhttp.status==200) 572 { 573 if (xmlhttp.responseText=="no change") 574 { 575 alert("You didn't change anything."); 576 return; 577 } 578 if (xmlhttp.responseText=="key exists") 579 { 580 alert("This key already exists. You cannot insert it a second time."); 581 return; 582 } 583 if (xmlhttp.responseText=="prog exists") 584 { 585 alert("This program already exists. You cannot insert it a second time."); 586 return; 587 } 181 588 alert(xmlhttp.responseText); 589 } 182 590 else 183 591 alert("Mist! "+xmlhttp.responseText); 184 592 185 var xmlhttp2; 186 if (window.XMLHttpRequest) 187 {// code for IE7+, Firefox, Chrome, Opera, Safari 188 xmlhttp2=new XMLHttpRequest(); 189 } 190 else 191 {// code for IE6, IE5 192 xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP"); 193 } 194 xmlhttp2.open("GET","get_values.php?fKey="+key+"&fProgram="+prog,false); 195 xmlhttp2.send(); 196 if (xmlhttp2.readyState==4 && xmlhttp2.status==200) 197 { 198 document.getElementById('valuefield').innerHTML = xmlhttp2.responseText; 199 if (key=='newkey') 200 addRow(prog, key); 201 } 202 else 203 document.getElementById('valuefield').innerHTML = "argh"; 204 } 205 206 207 // printf("<div id='showcurrent'>\n<button onClick='ShowCurrent();'>Show Current</button>\n</div>\n"); 593 //reload the content of the page 594 progselect=document.getElementById("prog"); 595 if (!progselect) 596 oldprog=prog; 597 else 598 if (progselect.options[progselect.selectedIndex]) 599 oldprog=progselect.options[progselect.selectedIndex].value; 600 else 601 oldprog=prog; 602 keyselect=document.getElementById("key"); 603 if (!keyselect) 604 oldkey=key1+"."+key2; 605 else 606 if (keyselect.options[keyselect.selectedIndex]) 607 oldkey=keyselect.options[keyselect.selectedIndex].value; 608 else 609 oldkey=key1+"."+key2; 610 //reload progs and keys 611 get_progs(oldprog, "10", "edit"); 612 get_keys(oldprog, oldkey, "10", "edit"); 613 //reload values 614 xmlhttp.open("GET","get_values.php?fGetValCase=1&fKey="+oldkey+"&fProgram="+oldprog,false); 615 xmlhttp.send(); 616 if (xmlhttp.readyState==4 && xmlhttp.status==200) 617 document.getElementById('valuefield1').innerHTML = xmlhttp.responseText; 618 else 619 document.getElementById('valuefield1').innerHTML = "argh"; 620 } 208 621 209 622 function ShowCurrent() … … 213 626 document.getElementById('old'+i).style.display = "none"; 214 627 document.getElementById('showcurrent').style.display = "none"; 628 document.getElementById('showcurrent2').style.display = "none"; 215 629 document.getElementById('showall').style.display = ""; 630 document.getElementById('showall2').style.display = ""; 216 631 } 217 632 … … 220 635 for (var i = 1 ; i <= document.getElementById('maxindex').innerHTML ; i++) 221 636 if(document.getElementById('old'+i)) 637 { 222 638 document.getElementById('old'+i).style.display = ""; 639 document.getElementById('old'+i).style.color = "grey"; 640 } 223 641 document.getElementById('showcurrent').style.display = ""; 642 document.getElementById('showcurrent2').style.display = ""; 224 643 document.getElementById('showall').style.display = "none"; 225 } 226 227 644 document.getElementById('showall2').style.display = "none"; 645 } 646 647 function InsertRow(table, row) 648 { 649 var x=document.getElementById('valtable'+table).insertRow(row); 650 for (var i = 0 ; i < 9 ; i++) 651 { 652 y=x.insertCell(i); 653 y.innerHTML=" "; 654 } 655 } 656 657 function CompareValues() 658 { 659 counter=0; 660 maxindex2=document.getElementById('maxindex').innerHTML; 661 maxindex3=document.getElementById('maxindex3').innerHTML; 662 //alert(maxindex2); 663 //alert(maxindex3); 664 if (parseInt(maxindex2)>parseInt(maxindex3)) 665 maxindex=maxindex2; 666 else 667 maxindex=maxindex3; 668 669 for (var i = 1 ; i <= maxindex ; i++) 670 { 671 if (document.getElementById('2compare'+i)) 672 { 673 counter++; 674 if (!document.getElementById('3compare'+i)) 675 { 676 InsertRow(3,counter); 677 document.getElementById('2compare'+i).style.color='red'; 678 } 679 else 680 { 681 val2=document.getElementById('2compare'+i).cells[5].innerHTML; 682 val3=document.getElementById('3compare'+i).cells[5].innerHTML; 683 if (val2!=val3) 684 { 685 document.getElementById('2compare'+i).style.color='blue'; 686 document.getElementById('3compare'+i).style.color='blue'; 687 } 688 } 689 } 690 else 691 if (document.getElementById('3compare'+i)) 692 { 693 counter++; 694 InsertRow(2,counter); 695 document.getElementById('3compare'+i).style.color='green'; 696 } 697 } 698 //document.getElementById('comparevals').style.display = "none"; 699 } 700 701 function HideDescription(getvalcase) 702 { 703 for(var i=0;i<document.getElementsByTagName('*').length;i++) 704 if(document.getElementsByTagName('*')[i].className == 'description'+getvalcase) 705 document.getElementsByTagName('*')[i].style.display = 'none'; 706 document.getElementById('hidedescr'+getvalcase).style.display = "none"; 707 document.getElementById('showdescr'+getvalcase).style.display = ""; 708 } 709 710 function ShowDescription(getvalcase) 711 { 712 for(var i=0;i<document.getElementsByTagName('*').length;i++) 713 if(document.getElementsByTagName('*')[i].className == 'description'+getvalcase) 714 document.getElementsByTagName('*')[i].style.display = ''; 715 document.getElementById('showdescr'+getvalcase).style.display = "none"; 716 document.getElementById('hidedescr'+getvalcase).style.display = ""; 717 } 718 719 function ShowDateInput(idx) 720 { 721 document.getElementById('datepulldown'+idx).style.display = "none"; 722 document.getElementById('dateinput'+idx).style.display = ""; 723 set_statusdate(idx, get_statusdate(idx, 'pulldown')); 724 } 725 726 function ShowDatePulldown(idx) 727 { 728 document.getElementById('datepulldown'+idx).style.display = ""; 729 document.getElementById('dateinput'+idx).style.display = "none"; 730 set_statusdate(idx, get_statusdate(idx, 'textinput')); 731 } 732 733 function reset_dates(datename, dateval, dateval2, idx) 734 { 735 radio=document.getElementsByName('dateformat'+idx); 736 for (i=0; i< radio.length; i++) 737 if (radio[i].checked) 738 val=radio[i].value; 739 if (val=="pulldown") 740 { 741 //alert("reset:"+datename+"-"+dateval+"-"+dateval2+"-"+idx); 742 if (datename=="year") 743 { 744 get_dates("year", dateval, dateval2, idx); 745 get_dates("month", dateval, dateval2, idx); 746 } 747 748 if (datename=="year" || datename=="month") 749 if (datename=="month") 750 get_dates("day", dateval, dateval2, idx); 751 else 752 get_dates("day", "empty", "empty", idx); 753 754 if (datename=="year" || datename=="month" || datename=="day") 755 if (datename=="day") 756 get_dates("hour", dateval, dateval2, idx); 757 else 758 get_dates("hour", "empty", "empty", idx); 759 760 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour") 761 if (datename=="hour") 762 get_dates("min", dateval, dateval2, idx); 763 else 764 get_dates("min", "empty", "empty", idx); 765 766 if (datename=="year" || datename=="month" || datename=="day" || datename=="hour" || datename=="min") 767 if (datename=="min") 768 get_dates("sec", dateval, dateval2, idx); 769 else 770 get_dates("sec", "empty", "empty", idx); 771 } 772 if (val=="textinput") 773 document.getElementById('statusdate'+idx).value=""; 774 } 775 function get_dates(datename, dateval, datevalprev, idx, reset) 776 { 777 //alert(datename+"_"+dateval+"_"+datevalprev+"_"+idx); 778 phpcall="get_date.php?fDateValue="+dateval+"&fDateValuePrev="+datevalprev+"&fDateName="+datename+"&fIdx="+idx; 779 //alert(phpcall); 780 xmlhttp.open("GET",phpcall,false); 781 xmlhttp.send(); 782 if (xmlhttp.readyState==4 && xmlhttp.status==200) 783 document.getElementById(datename+'select'+idx).innerHTML = xmlhttp.responseText; 784 else 785 document.getElementById(datename+'select'+idx).innerHTML = "argh"; 786 787 //to be able to do no reset in case when the function is called from reset_dates() 788 if (reset) 789 reset_dates(datename, "empty", "empty", idx); 790 } 791 792 function set_statusdate(getvalcase, statusdate) 793 { 794 //alert(statusdate); 795 796 radio=document.getElementsByName('dateformat'+getvalcase); 797 for (i=0; i< radio.length; i++) 798 if (radio[i].checked) 799 val=radio[i].value; 800 if (val=="pulldown") 801 { 802 //check whole string 803 if (statusdate=="") 804 { 805 //set all values to 'empty' 806 get_dates("year", "empty", "empty", getvalcase, "yes"); 807 return; 808 } 809 dates=statusdate.split("-",3); 810 //check year 811 if (!dates[0]) 812 { 813 get_dates("year", "empty", "empty", getvalcase, "yes"); 814 return; 815 } 816 else 817 get_dates("year", dates[0], dates[0], getvalcase); 818 //check month 819 if (!dates[1]) 820 { 821 get_dates("month", "empty", "empty", getvalcase, "yes"); 822 return; 823 } 824 else 825 get_dates("month", dates[1], dates[0], getvalcase); 826 //check rest of string 827 if (!dates[2]) 828 { 829 get_dates("day", "empty", "empty", getvalcase, "yes"); 830 return; 831 } 832 rests=dates[2].split(" ",2); 833 //check day 834 if (!rests[0]) 835 { 836 get_dates("day", "empty", "empty", getvalcase, "yes"); 837 return; 838 } 839 else 840 get_dates("day", rests[0], dates[1], getvalcase); 841 //check rest of string 842 if (!rests[1]) 843 { 844 get_dates("hour", "empty", "empty", getvalcase, "yes"); 845 return; 846 } 847 times=rests[1].split(":",3); 848 //check hour 849 if (!times[0]) 850 { 851 get_dates("hour", "empty", "empty", getvalcase, "yes"); 852 return; 853 } 854 else 855 get_dates("hour", times[0], rests[0], getvalcase); 856 //check minutes 857 if (!times[1]) 858 { 859 get_dates("min", "empty", "empty", getvalcase, "yes"); 860 return; 861 } 862 else 863 get_dates("min", times[1], times[0], getvalcase); 864 //check seconds 865 if (!times[2]) 866 { 867 get_dates("sec", "empty", "empty", getvalcase, "yes"); 868 return; 869 } 870 else 871 get_dates("sec", times[2], times[1], getvalcase); 872 873 } 874 if (val=="textinput") 875 document.getElementById('statusdate'+getvalcase).value=statusdate; 876 877 } 878 879 880 function get_timestamp(getvalcase, direction) 881 { 882 statusdate=get_statusdate(getvalcase); 883 884 xmlhttp.open("GET","get_timestamp.php?fStatusDate="+statusdate+"&fDirection="+direction,false); 885 xmlhttp.send(); 886 if (xmlhttp.readyState==4 && xmlhttp.status==200) 887 newstatusdate = xmlhttp.responseText; 888 else 889 newstatusdate = "argh"; 890 891 set_statusdate(getvalcase, newstatusdate); 892 }
Note:
See TracChangeset
for help on using the changeset viewer.