// 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
'; ?>