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
|
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004 Ian Berry |
| |
| 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. |
+-------------------------------------------------------------------------+
| cacti: a php-based graphing solution |
+-------------------------------------------------------------------------+
| Most of this code has been designed, written and is maintained by |
| Ian Berry. See about.php for specific developer credit. Any questions |
| or comments regarding this code should be directed to: |
| - iberry@raxnet.net |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/ |
+-------------------------------------------------------------------------+
*/
include("./include/auth.php");
/* set default action */
if (!isset($_REQUEST["action"])) { $_REQUEST["action"] = ""; }
switch ($_REQUEST["action"]) {
case 'save':
form_save();
break;
case 'remove':
color_remove();
header ("Location: color.php");
break;
case 'edit':
include_once("./include/top_header.php");
color_edit();
include_once("./include/bottom_footer.php");
break;
default:
include_once("./include/top_header.php");
color();
include_once("./include/bottom_footer.php");
break;
}
/* --------------------------
The Save Function
-------------------------- */
function form_save() {
if (isset($_POST["save_component_color"])) {
$save["id"] = $_POST["id"];
$save["hex"] = form_input_validate($_POST["hex"], "hex", "^[a-fA-F0-9]+$", false, 3);
if (!is_error_message()) {
$color_id = sql_save($save, "colors");
if ($color_id) {
raise_message(1);
}else{
raise_message(2);
}
}
if (is_error_message()) {
header("Location: color.php?action=edit&id=" . (empty($color_id) ? $_POST["id"] : $color_id));
}else{
header("Location: color.php");
}
}
}
/* -----------------------
Color Functions
----------------------- */
function color_remove() {
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
db_execute("delete from colors where id=" . $_GET["id"]);
}
function color_edit() {
global $colors, $fields_color_edit;
/* ================= input validation ================= */
input_validate_input_number(get_request_var("id"));
/* ==================================================== */
if (!empty($_GET["id"])) {
$color = db_fetch_row("select * from colors where id=" . $_GET["id"]);
$header_label = "[edit: " . $color["hex"] . "]";
}else{
$header_label = "[new]";
}
html_start_box("<strong>Colors</strong> $header_label", "98%", $colors["header"], "3", "center", "");
draw_edit_form(array(
"config" => array(),
"fields" => inject_form_variables($fields_color_edit, (isset($color) ? $color : array()))
));
html_end_box();
form_save_button("color.php");
}
function color() {
global $colors;
html_start_box("<strong>Colors</strong>", "98%", $colors["header"], "3", "center", "color.php?action=edit");
print "<tr bgcolor='#" . $colors["header_panel"] . "'>";
DrawMatrixHeaderItem("Hex Value",$colors["header_text"],1);
DrawMatrixHeaderItem("Color",$colors["header_text"],1);
DrawMatrixHeaderItem(" ",$colors["header_text"],1);
## Space
DrawMatrixHeaderItem(" ",$colors["header_text"],1);
DrawMatrixHeaderItem("Hex Value",$colors["header_text"],1);
DrawMatrixHeaderItem("Color",$colors["header_text"],1);
DrawMatrixHeaderItem(" ",$colors["header_text"],1);
print "</tr>";
$color_list = db_fetch_assoc("select * from colors order by hex");
$i = 0;
if (sizeof($color_list) > 0) {
$j=0; ## even/odd counter
foreach ($color_list as $color) {
$j++;
if ($j % 2 == 1) {
form_alternate_row_color($colors["alternate"],$colors["light"],$i); $i++;
?>
<td>
<a class="linkEditMain" href="color.php?action=edit&id=<?php print $color["id"];?>"><?php print $color["hex"];?></a>
</td>
<td bgcolor="#<?php print $color["hex"];?>" width="1%"> </td>
<td align="right">
<a href="color.php?action=remove&id=<?php print $color["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
</td>
<?php $j=1;
} else { ?>
<td></td>
<td>
<a class="linkEditMain" href="color.php?action=edit&id=<?php print $color["id"];?>"><?php print $color["hex"];?></a>
</td>
<td bgcolor="#<?php print $color["hex"];?>" width="1%"> </td>
<td align="right">
<a href="color.php?action=remove&id=<?php print $color["id"];?>"><img src="images/delete_icon.gif" width="10" height="10" border="0" alt="Delete"></a>
</td>
</tr>
<?php
}
}
## check for completion of odd number second column:
if ($j == 1) {
?>
<td colspan=4></td>
</tr>
<?php
}
}
html_end_box();
}
?>
|