source: trunk/www/db_po/insert_po.php@ 11444

Last change on this file since 11444 was 11353, checked in by Daniela Dorner, 13 years ago
added script to display and edit entries of the configuration database (ProgramOptions) and scripts which are called by this script
  • Property svn:executable set to *
File size: 3.8 KB
Line 
1<?php
2{
3 ini_set("display_errors", "On");
4 ini_set("mysql.trace_mode", "On");
5
6 if (empty($_GET["fUpdCase"]))
7 {
8 echo "Please specify what kind of change you want to do.<br>";
9 return;
10 }
11 if (empty($_GET["fIndex"]))
12 {
13 echo "Please giv an index.<br>";
14 return;
15 }
16 if (empty($_GET["fProgram"]))
17 {
18 echo "Please select a program.<br>";
19 return;
20 }
21 if (empty($_GET["fKey"]))
22 {
23 echo "Please select a key.<br>";
24 return;
25 }
26 if (empty($_GET["fValue"]))
27 {
28 echo "Please insert a value.<br>";
29 return;
30 }
31 if (empty($_GET["fDescription"]))
32 {
33 echo "Please insert a Description.<br>";
34 return;
35 }
36
37
38
39 include("db.php");
40 $db_id = mysqli_connect($host, $user, $pw, $db);
41 //if ($db_id==FALSE)
42 if (mysqli_connect_errno())
43 {
44 printf("mysql_connect returned the following error: %s\n", mysqli_connect_error());
45 die("");
46 }
47 //mysql_select_db($db);
48
49 //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 {
75 $query0.=" INSERT History SET ";
76 $query0.=" fCounter= (Select Max(fCounter) from ProgramOption) ";
77 $query0.=", fValidFrom=Now() ";
78 }
79
80
81 /*
82 if ($_GET["fUpdCase"]==1 || $_GET["fUpdCase"]==2)
83 $query0 ="INSERT ProgramOption SET ";//insert key or insert value
84 else
85 $query0 ="UPDATE ProgramOption SET ";//update value (includes 'delete')
86
87 if ($_GET["fUpdCase"]==4)//i.e. delete
88 $query0.=" fValue=NULL";
89 else
90 {
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 insert
99 $query0.=", fValidFrom=Now() ";
100
101 if ($_GET["fUpdCase"]==3 || $_GET["fUpdCase"]==4)// only in case of update
102 $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 $result0=mysqli_multi_query($db_id, $query0);
113 if ($result0)
114 {
115 echo "Query \"" . $query0 . "\" was successful.";
116 return 0;
117 }
118 else
119 {
120 echo "Query \"" . $query0 . "\" was not successful.";
121 return 2;
122 }
123
124 mysqli_free_result($result0);
125 mysqli_close($db_id);
126
127 ini_set("display_errors", "Off");
128 ini_set("mysql.trace_mode", "Off");
129}
130?>
Note: See TracBrowser for help on using the repository browser.