-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinc.controller.php
More file actions
executable file
·189 lines (172 loc) · 5.41 KB
/
inc.controller.php
File metadata and controls
executable file
·189 lines (172 loc) · 5.41 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php
function ColHead($edit=false) {
if(!$edit) {
print "\t\t<tr class='loadB'>\n";
iF($edit)
print "<td class='colHead'> </td>";
print "<td class='colHead'>Date</td>"
."<td class='colHead'>Origin</td>"
."<td class='colHead'>Dest.</span></td>"
."<td class='colHead'>Equip.</span></td>"
."<td class='colHead'>Weight</span></td>"
."<td class='colHead'>Team</span></td>"
."</tr>";
}
}
function startTable($edit) {
if(!$edit)
print "<div class='messagediv'>\n\t";
print "<table>\n";
}
function endTable($edit) {
print "</table>";
if(!$edit) print "</div>";
}
function printLoadsXML($file, $edit=false) {
$xml = simplexml_load_file($file);
$count = 1;
$total = 0;
startTable($edit);
colHead($edit);
foreach($xml->children() AS $load)
{
$origin = $load->origin->city.", ".$load->origin->state;
$destination = $load->destination->city.", ".$load->destination->state;
$equipment = $load->equipment;
$date = $load->date;
$weight = $load->weight;
$rate = $load->rate;
if($count<=LOADSPERPAGE) {
if($count%2==1) {
print "<tr class='loadB'>";
if($edit) print "<td><input type='radio' value='".$total++."' name='selection' /></td>";
} else {
print "<tr class='loadA'>";
if($edit) print "<td><input type='radio' value='".$total++."' name='selection' /></td>";
}
print "<td>".$date."</td>"
."<td>".$origin."</td>"
."<td>".$destination."</td>"
."<td>".$equipment."</td>"
."<td><span>".$weight."</span></td>"
."<td><span>".$rate."</span></td>";
$count++;
} else {
endTable($edit);
startTable($edit);
if(!$edit)
ColHead();
if($count%2==1) {
print "<tr class='loadB'>";
if($edit) print "<td><input type='radio' value='".$total++."' name='selection' /></td>";
} else {
print "<tr class='loadA'>";
}
print "<td>".$date."</td>"
."<td>".$origin."</td>"
."<td>".$destination."</td>"
."<td>".$equipment."</td>"
."<td><span>".$weight."</span></td>"
."<td><span>".$rate."</span></td>";
$count = 1;
}
}
if($count<=10)
endTable($edit);
}
function writeLoadsXML($file) {
if(validate() ) {
$xml = simplexml_load_file($file);
$origState= $_REQUEST['origState'];
$destState= $_REQUEST['destState'];
$equipment= $_REQUEST['equipment'];
$load = $xml->addChild("load");
$origin = $load->addChild("origin");
$origin->addChild("city", $_REQUEST['origCity']);
$origin->addChild("state", $origState[0]);
$destination = $load->addChild("destination");
$destination->addChild("city", $_REQUEST['destCity']);
$destination->addChild("state", $destState[0]);
$load->addChild("equipment", $equipment[0]);
$load->addChild("date", $_REQUEST['date']);
$load->addChild("weight", $_REQUEST['weight']);
$load->addChild("rate", $_REQUEST['rate']);
$xml->asXML($file);
}
}
function removeLoadXML($index, $file) {
$xml = simplexml_load_file($file);
//print $index;
$count = 0;
foreach($xml as $load) {
if($count == $index)
unset($xml->load[$count]);
$count++;
}
$xml->asXML($file);
}
function validate() {
if(isset($_REQUEST['submit'])) {
$error = '';
if( $_REQUEST['date']=='' ) { $error .= "<div class='err'>Date is missing.</div>"; }
if( $_REQUEST['origCity']=='' ) { $error .= "<div class='err'>Origin City is missing.</div>"; }
if( $_REQUEST['origState']=='') { $error .= "<div class='err'>Origin State is missing.</div>"; }
if( $_REQUEST['destCity']=='') { $error .= "<div class='err'>Destination City is missing.</div>"; }
if( $_REQUEST['destState']=='') { $error .= "<div class='err'>Destination State is missing.</div>"; }
if( $_REQUEST['equipment']=='') { $error .= "<div class='err'>Equipment is missing.</div>"; }
if( $_REQUEST['weight']=='') { $error .= "<div class='err'>Weight is missing.</div>"; }
if( $_REQUEST['rate']=='') { $error .= "<div class='err'>Rate is missing.</div>"; }
if( strlen($_REQUEST['origCity'])>8 ) { $error .= "<div class='err'>Origin City must be 8 characters or less.</div>"; }
if( strlen($_REQUEST['destCity'])>8 ) { $error .= "<div class='err'>Destination City must be 8 characters or less.</div>"; }
if($error != '') {
print $error;
return false;
}
else return true;
} else return false;
}
function buildDropDown($array, $n, $selection){
$string = '';
foreach($array as $k => $v){
if($k == $selection)
$string .= '<option value="'.$k.'" SELECTED>'.$k.'</option>'."\n";
else
$string .= '<option value="'.$k.'">'.$k.'</option>'."\n";
}
return $string;
}
function requestArrToStr() {
if(isset($_REQUEST)) {
$reqStr = '?';
foreach( $_REQUEST AS $var => $val ) {
if($reqStr=='?')
$reqStr .= $var;
else
$reqStr .= "&$var";
if($val != '')
$reqStr .= "=$val";
}
}
return $reqStr;
}
function getLoadXML($index, $file) {
$xml = simplexml_load_file($file);
$count = 0;
foreach($xml->children() AS $load)
{
if($count == $index) {
return array(
"origCity" => $load->origin->city,
"origState" => $load->origin->state,
"destCity" => $load->destination->city,
"destState" => $load->destination->state,
"equipment" => $load->equipment,
"date" => $load->date,
"weight" => $load->weight,
"rate" => $load->rate
);
}
$count++;
}
}
?>