diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php index ce739bb10f..10e95c8012 100644 --- a/pandora_console/include/functions_api.php +++ b/pandora_console/include/functions_api.php @@ -3516,6 +3516,104 @@ function api_set_stop_downtime($id, $thrash1, $other, $thrash3) { returnData('string', array('type' => 'string', 'data' => __('Downtime stopped.'))); } +/** + * Return all planned downtime. + * + * @param $thrash1 Don't use. + * @param array $other it's array, $other as param is ;;;;; in this order + * and separator char (after text ; ) and separator (pass in param othermode as othermode=url_encode_separator_) + * example: + * + * api.php?op=set&op2=all_planned_downtimes&other=test|0|quiet|periodically|weekly&other_mode=url_encode_separator_|&return_type=json + * + * @param type of return json or csv. + */ + +function api_get_all_planned_downtimes ($thrash1, $thrash2, $other, $returnType) { + if (defined ('METACONSOLE')) { + return; + } + + $values = array(); + $values = array( + 'name' => $other['data'][0] + ); + + if (isset($other['data'][1]) && ($other['data'][1] != false )) + $values['id_group'] = $other['data'][1]; + if (isset($other['data'][2]) && ($other['data'][2] != false)) + $values['type_downtime'] = $other['data'][2]; + if (isset($other['data'][3]) && ($other['data'][3]!= false) ) + $values['type_execution'] = $other['data'][3]; + if (isset($other['data'][4]) && ($other['data'][4] != false) ) + $values['type_periodicity'] = $other['data'][4]; + + + $returned = all_planned_downtimes($values); + + returnData($returnType, + array('type' => 'array', 'data' => $returned)); +} + +/** + * Return all items of planned downtime. + * + * @param $id id of planned downtime. + * @param + * example: + * + * api.php?op=set&op2=planned_downtimes_items&id=10&other_mode=url_encode_separator_|&return_type=json + * + * @param type of return json or csv. + */ + +function api_get_planned_downtimes_items ($id, $thrash2, $other, $returnType = 'json') { + if (defined ('METACONSOLE')) { + return; + } + + $values = array(); + $values = array( + 'id_downtime' => $id + ); + + $returned = planned_downtimes_items($values); + + if ( $returnType == 'json' ) + unset($returned['list_index']); + + returnData($returnType, + array('type' => 'array', 'data' => $returned)); +} + +/** + * Delete planned downtime. + * + * @param $id id of planned downtime. + * @param $thrash1 not use. + * @param $thrash2 not use. + * + * api.php?op=set&op2=planned_downtimes_deleted &id=10&return_type=json + * + * @param type of return json or csv. + */ + +function api_set_planned_downtimes_deleted ($id, $thrash1, $thrash2, $returnType) { + if (defined ('METACONSOLE')) { + return; + } + + $values = array(); + $values = array( + 'id_downtime' => $id + ); + + $returned = delete_planned_downtimes($values); + + returnData($returnType, + array('type' => 'string', 'data' => $returned)); +} + /** * Create a new planned downtime. * @@ -3532,7 +3630,7 @@ function api_set_stop_downtime($id, $thrash1, $other, $thrash3) { * @param $thrash3 Don't use. */ -function api_set_planned_downtimes_created($id, $thrash1, $other, $thrash3) { +function api_set_planned_downtimes_created ($id, $thrash1, $other, $thrash3) { if (defined ('METACONSOLE')) { return; } @@ -3585,7 +3683,7 @@ function api_set_planned_downtimes_created($id, $thrash1, $other, $thrash3) { * @param $thrash3 Don't use. */ -function api_set_planned_downtimes_additem($id, $thrash1, $other, $thrash3) { +function api_set_planned_downtimes_additem ($id, $thrash1, $other, $thrash3) { if (defined ('METACONSOLE')) { return; } diff --git a/pandora_console/include/functions_planned_downtimes.php b/pandora_console/include/functions_planned_downtimes.php index 3794def7bc..3be7e4833e 100644 --- a/pandora_console/include/functions_planned_downtimes.php +++ b/pandora_console/include/functions_planned_downtimes.php @@ -734,4 +734,69 @@ function planned_downtimes_created ($values) { return $return; } + +function all_planned_downtimes ($filter) { + + $fields = 'id, name, description, date_from, date_to, id_group, monday, + tuesday, wednesday, thursday, friday, saturday, sunday, + periodically_time_from, periodically_time_to, periodically_day_from, + periodically_day_to, type_downtime, type_execution, type_periodicity, id_user'; + + $result = db_get_all_rows_filter('tplanned_downtime',$filter, $fields); + + return $result; +} + +function planned_downtimes_items ($filter) { + + $downtime_agents = db_get_all_rows_filter('tplanned_downtime_agents',$filter, 'id_agent,id_downtime,all_modules'); + $downtime = db_get_row_filter('tplanned_downtime',array('id' => $filter['id_downtime']), 'type_downtime'); + + $return = array('list_index'=>array('id_agents','id_downtime','all_modules')); + + foreach ( $downtime_agents as $key => $data ) { + $return[$key] = $data; + $modules = array(); + if ($downtime['type_downtime'] === 'quiet') { + if (!$data['all_modules']) { + $second_filter = array( + 'id_agent' => $data['id_agent'], + 'id_downtime' => $data['id_downtime']); + + $downtime_modules = db_get_all_rows_filter('tplanned_downtime_modules',$second_filter, 'id_agent_module'); + if ( $downtime_modules ) { + foreach ( $downtime_modules as $data2 ) { + $modules[] = $data2['id_agent_module']; + } + $return[$key]['modules'] = implode(',', $modules); + } + } + } + } + + if ($downtime['type_downtime'] === 'quiet') { + $return['list_index'][] = 'modules'; + } + + return $return; +} + +function delete_planned_downtimes ($filter) { + + + $downtime_execute = db_get_row_filter('tplanned_downtime',array('id' => $filter['id_downtime']), 'execute'); + + if ( $downtime_execute ) + $return = __("This planned downtime are executed now. Can't delete in this moment."); + else { + $delete = db_process_sql_delete ('tplanned_downtime', + array('id'=>$filter['id_downtime'])); + if ($delete) + $return = __("Deleted this planned downtime successfully."); + else + $return = __("Problems for deleted this planned downtime."); + } + + return $return; +} ?> \ No newline at end of file