Skip to content

Commit

Permalink
set date with timezone in js + php
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary-Clb committed Dec 21, 2023
1 parent 6dc0f7b commit 57f47aa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function sendCheck(int $id)
try {
$res = $api->sendCheckToAnHost($id);
$sentcheckok = __('Check sent', 'centreon');
return '$sentcheckok';
return $sentcheckok;
} catch (\Exception $e) {
$error_msg = $e->getMessage();
return $error_msg;
Expand All @@ -225,8 +225,6 @@ public function sendCheck(int $id)
}
public function setDowntime(int $id, array $params)
{

$params['author_id'] = filter_var($params['author_id'], FILTER_VALIDATE_INT);
$params['is_fixed'] = filter_var($params['is_fixed'], FILTER_VALIDATE_BOOLEAN);
$params['with_services'] = filter_var($params['with_services'], FILTER_VALIDATE_BOOLEAN);
$params['start_time'] = $this->convertDateToIso8601($params['start_time']);
Expand All @@ -242,11 +240,13 @@ public function setDowntime(int $id, array $params)
}
unset($params['time_select']);
unset($params['author_id']);
\Toolbox::logDebug($params);
$api = new ApiClient();
$res = $api->connectionRequest();
if (isset($res["security"]["token"])) {
try {
$res = $api->setDowntimeOnAHost($id, ['json' => $params]);
\Toolbox::logDebug($res);
return $res;
} catch (\Exception $e) {
$error_msg = $e->getMessage();
Expand All @@ -257,7 +257,7 @@ public function setDowntime(int $id, array $params)

public function convertDateToIso8601($date)
{
$timezone = new \DateTimeZone('Europe/Paris');
$timezone = new \DateTimeZone($_SESSION['glpi_tz'] ?? date_default_timezone_get());
$new_date = new \DateTime($date, $timezone);
$iso_date = $new_date->format(DATE_ATOM);
return $iso_date;
Expand Down
5 changes: 4 additions & 1 deletion templates/host.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,6 @@
$('#check').click(function(){
$('.toggle').toggleClass('d-none');
$.post(CFG_GLPI['root_doc'] + "/" + GLPI_PLUGINS_PATH.centreon + "/ajax/sendCheck.php?hostid=" + {{ hostid }}, function(response){
console.log(response);
reloadTab('');
$('#check').addClass('btn-lime');
$('.toggle').toggleClass('d-none');
Expand All @@ -311,6 +310,10 @@
var params = $('#setdowntime').serializeArray();
var flatparams = {};
$.each(params, function() {
if (this.name.includes('time')) {
var date = new Date(this.value);
this.value = date.toISOString();
}
flatparams[this.name] = this.value;
});
$.ajax({
Expand Down

0 comments on commit 57f47aa

Please sign in to comment.