diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index af19e7bb17..4f9a61d80b 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2008-07-30 Evi Vanoost + + * include/functions_db.php: Small bug that gave a warning in case there were no events for an agent + + * godmode/agentes/planned_downtime.php: You can now create planned downtime schedules. This + won't work yet as the server doesn't support it yet. + + * general/links_menu.php: The first link will also show up. It wasn't showing up because the mysql function + that was used moved the internal pointer ahead while checking if it existed. Used new functions. + + * pandoradb.sql: Updated with database schema for planned downtime + 2008-07-29 Evi Vanoost * functions_db.php: Style changes, updated process_sql so it can return other diff --git a/pandora_console/general/links_menu.php b/pandora_console/general/links_menu.php index 648858795b..eb1971f018 100644 --- a/pandora_console/general/links_menu.php +++ b/pandora_console/general/links_menu.php @@ -18,14 +18,14 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -$sql1='SELECT link,name FROM tlink ORDER BY name'; -$result=mysql_query($sql1); -if ($row=mysql_fetch_array($result)){ +$sql='SELECT link,name FROM tlink ORDER BY name'; +$result = get_db_all_rows_sql ($sql); +if ($result !== false){ ?>
:: ::
"; } echo ""; diff --git a/pandora_console/godmode/agentes/planned_downtime.php b/pandora_console/godmode/agentes/planned_downtime.php new file mode 100644 index 0000000000..fa191fb327 --- /dev/null +++ b/pandora_console/godmode/agentes/planned_downtime.php @@ -0,0 +1,215 @@ + +// Please see http://pandora.sourceforge.net for full contribution list + +// 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 for version 2. +// 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. +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +/* +Database schema: + +CREATE TABLE `pandora`.`tplanned_downtime` ( +`id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT , +`name` VARCHAR( 100 ) NOT NULL , +`description` TEXT NOT NULL , +`start` INT NOT NULL , +`end` INT NOT NULL , +`module_id` BIGINT( 14 ) NOT NULL , +PRIMARY KEY ( `id` ) , +INDEX ( `start` , `end` , `module_id` ) , +UNIQUE ( +`id` +) +) ENGINE = INNODB + +*/ + +//ACL +require("include/config.php"); +if (give_acl($id_user, 0, "AW")!=1) { + audit_db($id_user,$REMOTE_ADDR, "ACL Violation","Trying to access downtime scheduler"); + require ("general/noaccess.php"); + exit; +}; + +function generate_options ($start, $number, $default = false) { + for($i=$start; $i<$start+$number; $i++) { + $val = str_pad($i,2,0,STR_PAD_LEFT); + echo ''; + } +} +//Initialize data +$id_agente = get_parameter ("id_agente"); +$modules = get_modules_in_agent ($id_agente); +$from_year = date("Y"); +$from_month = date("m"); +$from_day = date("d"); +$to_year = date("Y"); +$to_month = date("m"); +$to_day = date("d"); + +//Here cometh the parsing of the entered form +if(isset ($_GET["delete"])) { + $sql = sprintf ("DELETE FROM tplanned_downtime WHERE id = %d",$_GET["delete"]); + $result = process_sql ($sql); + if ($result === false) { + echo '

'.lang_string ("delete_no").'

'; + } else { + echo '

'.lang_string ("delete_ok").'

'; + } +} elseif(isset ($_POST["crtbutton"])) { + $post_name = get_parameter_post ("downtime_name"); + $post_description = get_parameter_post ("downtime_description"); + $post_module_id = (int) get_parameter_post ("downtime_module_id"); + $post_from_year = (int) get_parameter_post ("from_year"); + $post_from_month = (int) get_parameter_post ("from_month"); + $post_from_day = (int) get_parameter_post ("from_day"); + $post_time_from = explode (":",get_parameter_post ("time_from")); + $post_to_year = (int) get_parameter_post ("to_year"); + $post_to_month = (int) get_parameter_post ("to_month"); + $post_to_day = (int) get_parameter_post ("to_day"); + $post_time_to = explode (":",get_parameter_post ("time_to")); + + $start = mktime ($post_time_from[0],$post_time_from[1],00,$post_from_month,$post_from_day,$post_from_year); + $end = mktime ($post_time_to[0],$post_time_to[1],00,$post_to_month,$post_to_day,$post_to_year); + //make it a unixtime for easy storing/retrieving (int) + + if($start > $end) { + echo '

'.lang_string ("create_no").': START > END

'; + } else { + if($_POST["crtbutton"] == "Add") { + $sql = sprintf ("INSERT INTO tplanned_downtime (`name`, `description`, `start`, `end`, `module_id`) + VALUES ('%s','%s',%d,%d,%d)",$post_name,$post_description,$start,$end,$post_module_id); + } elseif ($_POST["crtbutton"] == "Update") { + $upd_id = (int) get_parameter_post ("update_id"); + $sql = sprintf ("UPDATE tplanned_downtime + SET `name`='%s', `description`='%s', `start`=%d, `end`=%d, `module_id`=%d + WHERE `id` = '%d'",$post_name,$post_description,$start,$end,$post_module_id,$upd_id); + } else { + die("Unspecified crtbutton"); + } + + $result = process_sql ($sql); + if ($result === false) { + echo '

'.lang_string ("create_no").'

'; + } else { + echo '

'.lang_string ("create_ok").'

'; + } + } +} elseif (isset ($_GET["update"])) { + $sql = sprintf ("SELECT `id`, `name`, `description`, `start`, `end`, `module_id` FROM `tplanned_downtime` WHERE `id` = %d",$_GET["update"]); + $result = get_db_row_sql ($sql); + $name = $result["name"]; + $description = $result["description"]; + $module_id = $result["module_id"]; + $start = $result["start"]; + $end = $result["end"]; + $from_year = date("Y",$start); + $from_month = date("m",$start); + $from_day = date("d",$start); + $to_year = date("Y",$end); + $to_month = date("m",$end); + $to_day = date("d",$end); + $time_from = date("H:i",$start); + $time_to = date("H:i",$end); +} +//--- + +//Page header +echo '

'.lang_string ("Planned Downtime Form").'

'; + +//Table header +echo '
+ + + '; + +//Description +echo ' + + +
'.lang_string ("name").':'.lang_string ("modules").''; + +//Select modules +echo '
'.lang_string ("description").':
'.lang_string ("time_from").': +'.lang_string ("time_to").':
'; +if (!isset ($_GET["update"])) { + echo ''; +} else { + echo ' + '; +} +//Finish form table +echo '
'; + +//Start Overview of existing planned downtime +echo '

'.lang_string ("Planned Downtime").':

'; +echo ' + + '; +$sql = sprintf ("SELECT tplanned_downtime.id, tplanned_downtime.name, tplanned_downtime.module_id, tplanned_downtime.start, tplanned_downtime.end + FROM tplanned_downtime, tagente_modulo WHERE tplanned_downtime.module_id = tagente_modulo.id_agente_modulo + AND tagente_modulo.id_agente = %d AND end > UNIX_TIMESTAMP(NOW())",$id_agente); +$result = get_db_all_rows_sql ($sql); +if ($result === false) { + echo ''; + $result = array(); +} +foreach($result as $row) { + echo ' + + '; +} +echo '
'.lang_string ("name").':'.lang_string ("module").':'.lang_string ("time_from").':'.lang_string ("time_to").':
'.lang_string ("No planned downtime").'
'.$row['name'].''.dame_nombre_modulo_agentemodulo ($row['module_id']).''.date ("Y-m-d H:i",$row['start']).''.date ("Y-m-d H:i",$row['end']).' + '.lang_string ( + + Update
'; +?> diff --git a/pandora_console/include/functions_db.php b/pandora_console/include/functions_db.php index 6cf775ab7f..95708ea63b 100644 --- a/pandora_console/include/functions_db.php +++ b/pandora_console/include/functions_db.php @@ -1884,6 +1884,8 @@ function smal_event_table ($filter = "", $limit = 10, $width = 440) { echo "".lang_string ('id_user').""; echo "".lang_string ('timestamp').""; $result = get_db_all_rows_sql ($sql); + if($result === false) + $result = array(); foreach ($result as $event) { $id_grupo = $event["id_grupo"]; if (! give_acl ($config["id_user"], $id_grupo, "AR")) { diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 13697bf531..61393e8d87 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -713,15 +713,15 @@ CREATE TABLE `tserver_export_data` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `tplanned_downtime` ( - `id` int(20) unsigned NOT NULL auto_increment, - `description` varchar(255) NOT NULL default '', - `start` date NOT NULL default '0000-00-00', - `stop` date NOT NULL default '0000-00-00', - `start_time` time NOT NULL default '00:00:00', - `stop_time` time NOT NULL default '00:00:00', - `executed` tinyint(2) NOT NULL default '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; + `id` MEDIUMINT( 8 ) NOT NULL AUTO_INCREMENT , + `name` VARCHAR( 100 ) NOT NULL , + `description` TEXT NOT NULL , + `start` INT NOT NULL , + `end` INT NOT NULL , + `module_id` BIGINT( 14 ) NOT NULL , + PRIMARY KEY ( `id` ) , + INDEX ( `start` , `end` , `module_id` ) , +) ENGINE = InnoDB DEFAULT CHARSET=utf8; CREATE TABLE `tplanned_downtime_agents` ( `id` int(20) unsigned NOT NULL auto_increment,