Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
enh(conf/contact) Fixed PHP warning when adding a contact with a non-…
Browse files Browse the repository at this point in the history
…admin user (#10345)
  • Loading branch information
callapa committed Oct 22, 2021
1 parent c90660d commit 48be495
Showing 1 changed file with 27 additions and 26 deletions.
53 changes: 27 additions & 26 deletions www/include/configuration/configObject/contact/formContact.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/*
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
Expand Down Expand Up @@ -84,7 +85,7 @@
$dbResult->closeCursor();

$cct = array();
if (($o == "c" || $o == "w") && $contactId) {
if (($o == MODIFY_CONTACT || $o == WATCH_CONTACT) && $contactId) {
/**
* Init Tables informations
*/
Expand Down Expand Up @@ -146,7 +147,7 @@
*/
$langs = array();
$langs = getLangs();
if ($o == "mc") {
if ($o == MASSIVE_CHANGE) {
array_unshift($langs, null);
}

Expand Down Expand Up @@ -236,7 +237,7 @@
* @var $moduleFormManager \Centreon\Domain\Service\ModuleFormManager
*/

if ($o == "a") {
if ($o == ADD_CONTACT) {
$form->addElement('header', 'title', _("Add a User"));

$eventDispatcher->notify(
Expand All @@ -248,7 +249,7 @@
'contact_id' => $contactId
]
);
} elseif ($o == "c") {
} elseif ($o == MODIFY_CONTACT) {
$form->addElement('header', 'title', _("Modify a User"));

$eventDispatcher->notify(
Expand All @@ -260,7 +261,7 @@
'contact_id' => $contactId
]
);
} elseif ($o == "w") {
} elseif ($o == WATCH_CONTACT) {
$form->addElement('header', 'title', _("View a User"));

$eventDispatcher->notify(
Expand All @@ -272,7 +273,7 @@
'contact_id' => $contactId
]
);
} elseif ($o == "mc") {
} elseif ($o == MASSIVE_CHANGE) {
$form->addElement('header', 'title', _("Massive Change"));

$eventDispatcher->notify(
Expand Down Expand Up @@ -301,7 +302,7 @@
* Don't change contact name and alias in massif change
* Don't change contact name, alias or autologin key in massive change
*/
if ($o != "mc") {
if ($o != MASSIVE_CHANGE) {
$form->addElement('text', 'contact_name', _("Full Name"), $attrsTextDescr);
$form->addElement('text', 'contact_alias', _("Alias / Login"), $attrsText);
$form->addElement('text', 'contact_autologin_key', _("Autologin Key"), array("size" => "90", "id" => "aKey"));
Expand All @@ -328,7 +329,7 @@
* Contact Groups Field
*/
$form->addElement('header', 'groupLinks', _("Group Relations"));
if ($o == "mc") {
if ($o == MASSIVE_CHANGE) {
$mc_mod_cg = array();
$mc_mod_cg[] = $form->createElement('radio', 'mc_mod_cg', null, _("Incremental"), '0');
$mc_mod_cg[] = $form->createElement('radio', 'mc_mod_cg', null, _("Replacement"), '1');
Expand Down Expand Up @@ -396,7 +397,7 @@
/**
* ACL configurations
*/
if ($o == "mc") {
if ($o == MASSIVE_CHANGE) {
$mc_mod_cg = array();
$mc_mod_cg[] = $form->createElement('radio', 'mc_mod_acl', null, _("Incremental"), '0');
$mc_mod_cg[] = $form->createElement('radio', 'mc_mod_acl', null, _("Replacement"), '1');
Expand Down Expand Up @@ -432,7 +433,7 @@
);
$form->addElement('select2', 'contact_location', _("Timezone / Location"), array(), $attrTimezones);

if ($o != "mc") {
if ($o != MASSIVE_CHANGE) {
$auth_type = array();
} else {
$auth_type = array(null => null);
Expand All @@ -446,7 +447,7 @@
$dnElement->freeze();
}
}
if ($o != "mc") {
if ($o != MASSIVE_CHANGE) {
$form->setDefaults(array(
'contact_oreon' => '1',
'contact_admin' => '0',
Expand All @@ -466,7 +467,7 @@
$tab[] = $form->createElement('radio', 'contact_enable_notifications', null, _("No"), '0');
$tab[] = $form->createElement('radio', 'contact_enable_notifications', null, _("Default"), '2');
$form->addGroup($tab, 'contact_enable_notifications', _("Enable Notifications"), '&nbsp;');
if ($o != "mc") {
if ($o != MASSIVE_CHANGE) {
$form->setDefaults(array('contact_enable_notifications' => '2'));
}

Expand Down Expand Up @@ -529,7 +530,7 @@

unset($hostNotifOpt);

if ($o == "mc") {
if ($o == MASSIVE_CHANGE) {
$mc_mod_hcmds = array();
$mc_mod_hcmds[] = $form->createElement('radio', 'mc_mod_hcmds', null, _("Incremental"), '0');
$mc_mod_hcmds[] = $form->createElement('radio', 'mc_mod_hcmds', null, _("Replacement"), '1');
Expand Down Expand Up @@ -615,7 +616,7 @@
);
$form->addElement('select2', 'timeperiod_tp_id2', _("Service Notification Period"), array(), $attrTimeperiod2);

if ($o == "mc") {
if ($o == MASSIVE_CHANGE) {
$mc_mod_svcmds = array();
$mc_mod_svcmds[] = $form->createElement('radio', 'mc_mod_svcmds', null, _("Incremental"), '0');
$mc_mod_svcmds[] = $form->createElement('radio', 'mc_mod_svcmds', null, _("Replacement"), '1');
Expand Down Expand Up @@ -645,7 +646,7 @@
$cctActivation[] = $form->createElement('radio', 'contact_activate', null, _("Disabled"), '0');
$form->addGroup($cctActivation, 'contact_activate', _("Status"), '&nbsp;');
$form->setDefaults(array('contact_activate' => '1'));
if ($o == "c" && $centreon->user->get_id() == $cct["contact_id"]) {
if ($o == MODIFY_CONTACT && $centreon->user->get_id() == $cct["contact_id"]) {
$form->freeze('contact_activate');
}

Expand Down Expand Up @@ -683,7 +684,7 @@ function myReplace()
$form->applyFilter('__ALL__', 'myTrim');
$form->applyFilter('contact_name', 'myReplace');
$from_list_menu = false;
if ($o != "mc") {
if ($o != MASSIVE_CHANGE) {
$ret = $form->getSubmitValues();
$form->addRule('contact_name', _("Compulsory Name"), 'required');
$form->addRule('contact_alias', _("Compulsory Alias"), 'required');
Expand Down Expand Up @@ -727,7 +728,7 @@ function myReplace()
_("You have to keep at least one contact to access to Centreon"),
'keepOneContactAtLeast'
);
} elseif ($o == "mc") {
} elseif ($o == MASSIVE_CHANGE) {
if ($form->getSubmitValue("submitMC")) {
$from_list_menu = false;
} else {
Expand All @@ -750,7 +751,7 @@ function myReplace()
$helptext .= '<span style="display:none" id="help:' . $key . '">' . $text . '</span>' . "\n";
}
$tpl->assign("helptext", $helptext);
if ($o == "w") {
if ($o == WATCH_CONTACT) {
# Just watch a contact information
if ($centreon->user->access->page($p) != 2) {
$form->addElement(
Expand All @@ -762,16 +763,16 @@ function myReplace()
}
$form->setDefaults($cct);
$form->freeze();
} elseif ($o == "c") {
} elseif ($o == MODIFY_CONTACT) {
# Modify a contact information
$subC = $form->addElement('submit', 'submitC', _("Save"), array("class" => "btc bt_success"));
$res = $form->addElement('reset', 'reset', _("Reset"), array("class" => "btc bt_default"));
$form->setDefaults($cct);
} elseif ($o == "a") {
} elseif ($o == ADD_CONTACT) {
# Add a contact information
$subA = $form->addElement('submit', 'submitA', _("Save"), array("class" => "btc bt_success"));
$res = $form->addElement('reset', 'reset', _("Reset"), array("class" => "btc bt_default"));
} elseif ($o == "mc") {
} elseif ($o == MASSIVE_CHANGE) {
# Massive Change
$subMC = $form->addElement('submit', 'submitMC', _("Save"), array("class" => "btc bt_success"));
$res = $form->addElement('reset', 'reset', _("Reset"), array("class" => "btc bt_default"));
Expand All @@ -788,7 +789,7 @@ function myReplace()

if ($form->validate() && $from_list_menu == false) {
$cctObj = $form->getElement('contact_id');
if (!$centreon->user->admin && $contact_id) {
if (!$centreon->user->admin && $contactId) {
$form->removeElement('contact_admin');
$form->removeElement('reach_api');
$form->removeElement('reach_api_rt');
Expand Down Expand Up @@ -818,16 +819,16 @@ function myReplace()
);
} elseif ($form->getSubmitValue("submitMC")) {
$select = explode(",", $select);
foreach ($select as $key => $contactId) {
if ($contactId) {
updateContactInDB($contactId, true);
foreach ($select as $key => $selectedContactId) {
if ($selectedContactId) {
updateContactInDB($selectedContactId, true);

$eventDispatcher->notify(
'contact.form',
EventDispatcher::EVENT_UPDATE,
[
'form' => $form,
'contact_id' => $contactId
'contact_id' => $selectedContactId
]
);
}
Expand Down

0 comments on commit 48be495

Please sign in to comment.