<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2006-2008 Xinn.org |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| ClearSite/ALOE, A Long Overdue Enterprise network managment solution! |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Xinn.org. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://aloeusers.net |
| http://clearsite.sourceforge.net |
| http://aloenms.net |
| http://clear-site.net |
| http://clear-site.info |
| http://xinn.org/ClearSite.html |
+-------------------------------------------------------------------------+
*/
extract($_POST);
extract($_GET);
mysql_connect("$DBhost:$DBport",$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
if (!empty($site_dbfunc)) {
if ($site_dbfunc == "add") {
if (!empty($office_address) and !empty($city) and strlen($city) <= 32) {
$sqlquery = "INSERT INTO location SET office_address=\"$office_address\", city=\"$city\", state=\"$state\", zip_code=\"$zip_code\", country_code=\"$country_code\", main_phone=\"$main_phone\", fax=\"$fax\", contact=\"$contact\", office_head=\"$office_head\", priority_ID=\"$priority_ID\", time_zone=\"$time_zone\", added_to_DB = NOW()";
$result = mysql_query($sqlquery);
print "$city, $state Added<p />";
} else {
$add_error = "";
$act = "add";
if (empty($office_address)) {
$add_error .= "Address must be filled out.<br />";
};
if (empty($city)) {
$add_error .= "City must be filled out.<br />";
};
if (strlen($city) >= 32) {
$add_error .= "City must be 32 charcters or less.<br />";
};
};
} else if ($site_dbfunc == "edit") {
$sqlquery = "UPDATE location SET office_address=\"$office_address\", city=\"$city\", state=\"$state\", zip_code=\"$zip_code\", country_code=\"$country_code\", main_phone=\"$main_phone\", fax=\"$fax\", contact=\"$contact\", office_head=\"$office_head\", priority_ID=\"$priority_ID\", time_zone=\"$time_zone\" WHERE location_ID=\"$location_ID\"";
$result = mysql_query($sqlquery);
print "$city, $state Edited<p />";
} else if ($site_dbfunc == "delete") {
$sqlquery = "DELETE FROM location WHERE location_ID=\"$location_ID\"";
$result = mysql_query($sqlquery);
print "$city, $state Deleted<p />";
};
};
if (empty($act)) {
if (empty($oby)) {
$oby = "t1.city";
};
$sqlquery = "SELECT t1.location_ID, t1.city, t1.state, t2.country_abbr FROM location AS t1, country_codes AS t2 WHERE t1.country_code = t2.country_code ORDER BY $oby";
$result = mysql_query($sqlquery);
$location_num = mysql_num_rows($result);
print "
<p><a href=\"$ClearsiteBaseURL/admin.php?act=add&adpage=site\"><img src=\"$ClearsiteBaseURL/images/add-site.png\" class=\"admin_img\"></a></p>
<fieldset class=\"site_admin\">
<div class=\"alt_six_odd\">
<div class=\"six_cell_row\">
<div class=\"cell_one\">
<p><a href=\"$ClearsiteBaseURL/admin.php?oby=t1.city\">City</a></p>
</div>
<div class=\"cell_two\">
<p><a href=\"$ClearsiteBaseURL/admin.php?oby=t1.state\">State</a></p>
</div>
<div class=\"cell_three\">
<p><a href=\"$ClearsiteBaseURL/admin.php?oby=t2.country_abbr\">Country</a></p>
</div>
<div class=\"cell_four\">
<p>Devices</p>
</div>
<div class=\"cell_five\">
<p> <p>
</div>
<div class=\"cell_six\">
<p> <p>
</div>
<div class=\"tbl_spacer\"></div>
</div>
</div>
";
$div_class = "alt_six_odd";
$total_num = 0;
while ($row = mysql_fetch_assoc($result)) {
if ($div_class == "alt_six_odd"){
$div_class = "alt_six_even";
} else {
$div_class = "alt_six_odd";
};
$device_num_query = "SELECT device_ID FROM devices WHERE location_ID = \"$row[location_ID]\"";
$device_num_results = mysql_query($device_num_query);
$device_num = mysql_num_rows($device_num_results);
$total_num = $total_num + $device_num;
print "
<div class=\"$div_class\">
<div class=\"six_cell_row\">
<div class=\"cell_one\">
<p><a class=\"toggleinto-device_$row[location_ID]\" href=\"$ClearsiteBaseURL/include/admin/device_admin.php?location_ID=$row[location_ID]\"><img src=\"$ClearsiteBaseURL/images/plus-1.png\" alt=\"\" class=\"admin_img\" /> $row[city]</a></p>
</div>
<div class=\"cell_two\">
<p>$row[state]</p>
</div>
<div class=\"cell_three\">
<p>$row[country_abbr]</p>
</div>
<div class=\"cell_four\">
<p>$device_num</p>
</div>
<div class=\"cell_five\">
<p><a href=\"$ClearsiteBaseURL/admin.php?adpage=site&act=edit&location_ID=$row[location_ID]\"><img src=\"$ClearsiteBaseURL/images/edit.png\" class=\"admin_img\"></a><p>
</div>
<div class=\"cell_six\">
<p><a href=\"$ClearsiteBaseURL/admin.php?adpage=site&act=delete&location_ID=$row[location_ID]\"><img src=\"$ClearsiteBaseURL/images/delete.png\" class=\"admin_img\"></a><p>
</div>
<div class=\"tbl_spacer\"></div>
</div>
</div>
<div id=\"device_$row[location_ID]\">";
if ($location_num == 1) {
$location_ID = $row['location_ID'];
include('device_admin.php');
};
print "</div>
";
};
$total_ds = 0;
$interface_total_query = "SELECT interface_ID from interfaces WHERE ifoperstatus=\"up\"";
$interface_total_result = mysql_query($interface_total_query);
$interface_num = mysql_num_rows($interface_total_result);
$total_ds = $total_ds + $interface_num;
$cpu_total_query = "SELECT cpu_ID from cpus";
$cpu_total_result = mysql_query($cpu_total_query);
$cpu_num = mysql_num_rows($cpu_total_result);
$total_ds = $total_ds + $cpu_num;
$cr_total_query = "SELECT cr_ID from css_cr";
$cr_total_result = mysql_query($cr_total_query);
$cr_num = mysql_num_rows($cr_total_result);
$total_ds = $total_ds + $cr_num;
$owner_total_query = "SELECT owner_ID from css_owner";
$owner_total_result = mysql_query($owner_total_query);
$owner_num = mysql_num_rows($owner_total_result);
$total_ds = $total_ds + $owner_num;
$sv_total_query = "SELECT sv_ID from css_sv";
$sv_total_result = mysql_query($sv_total_query);
$sv_num = mysql_num_rows($sv_total_result);
$total_ds = $total_ds + $sv_num;
print "<p><b>Total Number of Devices:</b> $total_num</p>
<dl>
<dt>Total Number of Data Sources: $total_ds</dt>
<dd>Number of Interfaces: $interface_num</dd>
<dd>Number of CPUs: $cpu_num</dd>
<dd>Number of Owners: $owner_num</dd>
<dd>Number of Content Rules: $cr_num</dd>
<dd>Number of Services: $sv_num</dd>
</dl>
</fieldset>
";
} else if ($act == "add") {
if (!empty($add_error)) {
print "<font class=\"admin_error\">$add_error</font><p>
";
};
print "
<fieldset class=\"site_admin\">
<form action=\"$ClearsiteBaseURL/admin.php\" method=\"POST\">
<input type=\"hidden\" name=\"adpage\" value=\"site\">
<input type=\"hidden\" name=\"site_dbfunc\" value=\"add\">
<label for=\"address\">Address:</label><input id=\"address\" type=\"text\" name=\"office_address\" size=\"56\"";
if (isset($office_address)) {
print " value=\"$office_address\"";
};
print "><br />
<label for=\"city\">City:</label><input id=\"city\" type=\"text\" name=\"city\" size=\"32\"";
if (isset($city)) {
print " value=\"$city\"";
};
print "><br />
<label for=\"state\">State:</label><input id=\"state\" type=\"text\" name=\"state\" size=\"2\"";
if (isset($state)) {
print " value=\"$state\"";
};
print "><br />
<label for=\"zip\">Zip Code:</label><input id=\"zip\" type=\"text\" name=\"zip_code\" size=\"10\"";
if (isset($zip_code)) {
print " value=\"$zip_code\"";
};
print "><br />
<label for=\"country\">Country:</label><select id=\"country\" name=\"country_code\">
";
$sqlquery = "SELECT country_code, country_full FROM country_codes ORDER BY country_full";
$result = mysql_query($sqlquery);
while ($row = mysql_fetch_assoc($result)) {
print "
<option value=\"$row[country_code]\"";
if (isset($country_code) and $country_code == $row["country_code"]) {
print " selected";
};
print ">$row[country_full]</option>";
};
print "
</select><br />
<label for=\"phone\">Main Phone:</label><input id=\"phone\" type=\"text\" name=\"main_phone\" size=\"12\"";
if (isset($main_phone)) {
print " value=\"$main_phone\"";
};
print "><br />
<label for=\"fax\">Fax:</label><input id=\"fax\" type=\"text\" name=\"fax\" size=\"12\"";
if (isset($fax)) {
print " value=\"$fax\"";
};
print "><br />
<label for=\"contact\">Contact:</label><input id=\"contact\" type=\"text\" name=\"contact\" size=\"30\"";
if (isset($contact)) {
print " value=\"$contact\"";
};
print "><br />
<label for=\"head\">Office Head:</label><input id=\"head\" type=\"text\" name=\"office_head\" size=\"30\"";
if (isset($office_head)) {
print " value=\"$office_head\"";
};
print "><br />
<label for=\"priority\">Priority:</label><select id=\"priority\" name=\"priority_ID\">
";
$sqlquery = "SELECT priority_ID, priority FROM location_priority ORDER BY priority_ID";
$result = mysql_query($sqlquery);
while ($row = mysql_fetch_assoc($result)) {
print "
<option value=\"$row[priority_ID]\"";
if (isset($priority_ID) and $priority_ID == $row["priority_ID"]) {
print " selected";
};
print ">$row[priority]</option>";
};
print "
</select><br />
<label for=\"zone\">Time Zone</label><input id=\"zone\" type=\"text\" name=\"time_zone\" size=\"3\"";
if (isset($time_zone)) {
print " value=\"$time_zone\"";
};
print "><br />
<p><input type=\"image\" name=\"Add\" value=\"Add\" src=\"$ClearsiteBaseURL/images/add.png\">     <a href=\"$ClearsiteBaseURL/admin.php\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
</form>
</fieldset>
";
} else if ($act == "edit") {
$sqlquery = "SELECT office_address, city, state, zip_code, country_code, main_phone, fax, contact, office_head, priority_ID, time_zone FROM location WHERE location_ID=\"$location_ID\"";
$result = mysql_query($sqlquery);
$row = mysql_fetch_assoc($result);
print "
<fieldset class=\"site_admin\">
<form action=\"$ClearsiteBaseURL/admin.php\" method=\"POST\">
<input type=\"hidden\" name=\"adpage\" value=\"site\">
<input type=\"hidden\" name=\"site_dbfunc\" value=\"edit\">
<input type=\"hidden\" name=\"location_ID\" value=\"$location_ID\">
<label for=\"address\">Address</label><input id=\"address\" type=\"text\" name=\"office_address\" size=\"56\" value=\"$row[office_address]\"><br />
<label for=\"city\">City</label><input id=\"city\" type=\"text\" name=\"city\" size=\"32\" value=\"$row[city]\"><br />
<label for=\"state\">State</label><input id=\"state\" type=\"text\" name=\"state\" size=\"2\" value=\"$row[state]\"><br />
<label for=\"zip\">Zip Code</label><input id=\"zip\" type=\"text\" name=\"zip_code\" size=\"10\" value=\"$row[zip_code]\"><br />
<label for=\"country\">Country</label><select id=\"country\" name=\"country_code\">
";
$sqlquery2 = "SELECT country_code, country_full FROM country_codes ORDER BY country_full";
$result2 = mysql_query($sqlquery2);
while ($row2 = mysql_fetch_assoc($result2)) {
print "
<option value=\"$row2[country_code]\""; if ($row["country_code"] == $row2["country_code"]) { print " selected"; }; print ">$row2[country_full]</option>";
};
print "
</select><br />
<label for=\"phone\">Main Phone</label><input id=\"phone\" type=\"text\" name=\"main_phone\" size=\"12\" value=\"$row[main_phone]\"><br />
<label for=\"fax\">Fax</label><input id=\"fax\" type=\"text\" name=\"fax\" size=\"12\" value=\"$row[fax]\"><br />
<label for=\"contact\">Contact</label><input id=\"contact\" type=\"text\" name=\"contact\" size=\"30\" value=\"$row[contact]\"><br />
<label for=\"head\">Office Head</label><input id=\"head\" type=\"text\" name=\"office_head\" size=\"30\" value=\"$row[office_head]\"><br />
<label for=\"priority\">Priority</label><select id=\"priority\" name=\"priority_ID\">
";
$sqlquery3 = "SELECT priority_ID, priority FROM location_priority ORDER BY priority_ID";
$result3 = mysql_query($sqlquery3);
while ($row3 = mysql_fetch_assoc($result3)) {
print "
<option value=\"$row3[priority_ID]\""; if ($row["priority_ID"] == $row3["priority_ID"]) { print " selected"; }; print ">$row3[priority]</option>";
};
print "
</select><br />
<label for=\"zone\">Time Zone</label><input id=\"zone\" type=\"text\" name=\"time_zone\" size=\"3\" value=\"$row[time_zone]\"><br />
<p><input type=\"image\" name=\"Submit\" value=\"Submit\" src=\"$ClearsiteBaseURL/images/submit.png\">   <a href=\"$ClearsiteBaseURL/admin.php?act=edit&location_ID=$location_ID\"><img src=\"$ClearsiteBaseURL/images/reset.png\" class=\"admin_img\"></a>  <a href=\"$ClearsiteBaseURL/admin.php\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
</form>
</fieldset>
";
} else if ($act == "delete") {
$sqlquery = "SELECT t1.office_address, t1.city, t1.state, t1.zip_code, t2.country_full, t1.main_phone, t1.fax, t1.contact, t1.office_head, t3.priority, t1.time_zone FROM location AS t1, country_codes AS t2, location_priority AS t3 WHERE t1.location_ID = \"$location_ID\" AND t1.country_code = t2.country_code AND t1.priority_ID = t3.priority_ID";
$result = mysql_query($sqlquery);
$row = mysql_fetch_assoc($result);
print "
<fieldset class=\"site_admin\">
<label for=\"address\">Address:</label>$row[office_address]<br />
<label for=\"city\">City:</label>$row[city]<br />
<label for=\"state\">State:</label>$row[state]<br />
<label for=\"zip\">Zip Code:</label>$row[zip_code]<br />
<label for=\"country\">Country:</label>$row[country_full]<br />
<label for=\"phone\">Main Phone:</label>$row[main_phone]<br />
<label for=\"fax\">Fax:</label>$row[fax]<br />
<label for=\"contact\">Contact:</label>$row[contact]<br />
<label for=\"head\">Office Head:</label>$row[office_head]<br />
<label for=\"priority\">Priority:</label>$row[priority]<br />
<label for=\"zone\">Time Zone:</label>$row[time_zone]<br />
<form action=\"$ClearsiteBaseURL/admin.php\" method=\"POST\">
<input type=\"hidden\" name=\"site_dbfunc\" value=\"delete\">
<input type=\"hidden\" name=\"city\" value=\"$row[city]\">
<input type=\"hidden\" name=\"state\" value=\"$row[state]\">
<input type=\"hidden\" name=\"location_ID\" value=\"$location_ID\">
<p><input type=\"image\" name=\"Delete\" value=\"Delete\" src=\"$ClearsiteBaseURL/images/delete.png\">     <a href=\"$ClearsiteBaseURL/admin.php\"><img src=\"$ClearsiteBaseURL/images/cancel.png\" class=\"admin_img\"></a></p>
</form>
</fieldset>
";
};
mysql_close();
?>