-
Notifications
You must be signed in to change notification settings - Fork 0
/
territory.php
137 lines (122 loc) · 5.1 KB
/
territory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?
include "main.php";
include "head.php";
include "menu.php";
$resq = "SELECT user_priveleges FROM users WHERE user='".$HTTP_COOKIE_VARS["user_name"]."' AND passwd='".$HTTP_COOKIE_VARS["user_passwd"]."';";
$rc = &$db->Execute($resq);
if($rc && $rc->RecordCount() && $rc->fields[user_priveleges]==3 || $rc->fields[user_priveleges]==2)
{
if(!$_POST[submit_user_data])
{
$resq = "SHOW TABLES FROM ".$sqlbase." LIKE 'territory';";
$rc = &$db->Execute($resq);
if($rc->RecordCount()==0)
{
$resq = "CREATE TABLE `territory` (`idx` INTEGER(10) AUTO_INCREMENT PRIMARY KEY,`caption` VARCHAR(255),`inc_energy` INTEGER(10),`out_energy` INTEGER(10),`latitude` INTEGER(10),`longitude` INTEGER(10),`height` INTEGER(10),`square` DOUBLE,`cold_period` INTEGER(10),`temperature` DOUBLE,`atm_pressure` DOUBLE,`humidity` DOUBLE,`sunny_days` INTEGER(10));";
if($db->Execute($resq)==false)
echo "Error inserting values ".$db->ErrorMsg();
}
$resq = "SELECT idx,caption FROM territory;";
$rc = &$db->Execute($resq);
if($rc && $rc->RecordCount())
{
$str = "<TABLE>";
$str .="<TR><TD><b>Òåðèèòîðèè:</b></TD></TR>";
while($rc && !$rc->EOF)
{
$str .= '<TR><TD><a href="./territory.php?cmd=lst&idx='.$rc->fields[idx].'">'.$rc->fields[caption].'</a><br></TD></TR>';
$rc->MoveNext();
}
$str .= "</TABLE>";
}
echo $str;
$str = "<TABLE align='center'>";
$str .="<TR><TD><b>Äîáàâèòü íîâóþ òåððèòîðèþ:</b></TD></TR>";
$str .= "</TABLE>";
echo $str;
$myform = new HTML_Form($SELF,"POST");
$myform->addHidden("cmd","new","");
$myform->addText ("caption" , "Íàèìåíîâàíèå","");
$resq = "SELECT * FROM energy_supply;";
$rc = &$db->Execute($resq);
if($rc && $rc->RecordCount())
{
$myform->addText ("" , "","Âõîäÿùèå äàííûå","");
while($rc && !$rc->EOF)
{
$myform->addCheckbox ("in".$rc->fields[id] , $rc->fields[caption],"");
$rc->MoveNext();
}
}
$resq = "SELECT * FROM energy_supply;";
$rc = &$db->Execute($resq);
if($rc && $rc->RecordCount())
{
$myform->addText ("" , "","Èñõîäÿùèå äàííûå","");
while($rc && !$rc->EOF)
{
$myform->addCheckbox ("out".$rc->fields[id] , $rc->fields[caption],"");
$rc->MoveNext();
}
}
$myform->addText ("latitude" , "Øèðîòà","");
$myform->addText ("longitude" , "Äîëãîòà","");
$myform->addText ("height" , "Ïîëîæåíèå íàä óðîâíåì ìîðÿ","");
$myform->addText ("square" , "Çàíèìàåìàÿ ïëîùàäü","");
$myform->addText ("cold_period" , "Ïðîäîëæèòåëüíîñòü îòîïèòåëüíîãî ïåðèîäà","");
$myform->addText ("temperature" , "Ñðåäíåãîäîâàÿ òåìïåðàòóðà","");
$myform->addText ("atm_pressure" , "Ñðåäíåãîäîâîå àòìîñôåðíîå äàâëåíèå","");
$myform->addText ("humidity" , "Ñðåäíåãîäîâàÿ âëàæíîñòü","");
$myform->addText ("sunny_days" , "Ñðåäíåãîäîâîå êîëè÷åñòâî ñîëíå÷íûõ äíåé","");
$myform->addSubmit("submit_user_data", "Îòïðàâèòü");
$myform->display();
}
if($_POST[submit_user_data] && $_POST[cmd]='new')
{
if($_POST[caption]!="" || $_POST[latitude]!="" || $_POST[longitude]!="" || $_POST[height]!="" || $_POST[square]!="" || $_POST[cold_period]!="" || $_POST[temperature]!="" || $_POST[atm_pressure]!="" || $_POST[humidity]!="" || $_POST[sunny_days]!="")
// if($_POST[sunny_days]!="" || $_POST[caption]!="" || $_POST[latitude]!="" || $_POST[longitude]!="" || $_POST[height]!="" || $_POST[square]!="" || $_POST[cold_period]!="" || $_POST[temperature]!="" || $_POST[atm_pressure]!="")
{
$resq = "SELECT * FROM energy_supply;";
$rc = &$db->Execute($resq);
$i = $rc->RecordCount()-1;
$in_str="";
while($i>=0)
{
$s = "in".$i;
if($_POST[$s]=="on")
{$in_str .= "1";}
else
{$in_str .= "0";}
$i=$i-1;
}
$resq = "SELECT * FROM energy_supply;";
$rc = &$db->Execute($resq);
$i = $rc->RecordCount()-1;
$out_str="";
while($i>=0)
{
$s = "out".$i;
if($_POST[$s]=="on")
{$out_str .= "1";}
else
{$out_str .= "0";}
$i=$i-1;
}
$resq = "INSERT INTO territory ";
$resq .= "(caption,inc_energy,out_energy,latitude,longitude,height,square,cold_period,temperature,atm_pressure,humidity,sunny_days) ";
$resq .= "VALUE ";
$resq .= "('".$_POST[caption]."',".bindec($in_str).",".bindec($out_str).",".$_POST[latitude].",".$_POST[longitude].",".$_POST[height].",".$_POST[square].",".$_POST[cold_period].",".$_POST[temperature].",".$_POST[atm_pressure].",".$_POST[humidity].",".$_POST[sunny_days].");";
if($db->Execute($resq)!=false)
{
echo "Âûïîëíåíî";
?><meta http-equiv="refresh" content="2; url=<?echo $SELF;?>"><?
}
else echo "Error ".$db->ErrorMsg();
}else
{echo "Íå âñå äàííûå!!!";
?><meta http-equiv="refresh" content="2; url=<?echo $SELF;?>"><?
}
}
}
include "foot.php";
?>