<commit_before><?php
/*
 * Copyright 2005-2015 Centreon
 * Centreon is developped by : <NAME> and <NAME> under
 * GPL Licence 2.0.
 *
 * 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 ; either version 2 of the License.
 *
 * 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, see <http://www.gnu.org/licenses>.
 *
 * Linking this program statically or dynamically with other modules is making a
 * combined work based on this program. Thus, the terms and conditions of the GNU
 * General Public License cover the whole combination.
 *
 * As a special exception, the copyright holders of this program give Centreon
 * permission to link this program with independent modules to produce an executable,
 * regardless of the license terms of these independent modules, and to copy and
 * distribute the resulting executable under terms of Centreon choice, provided that
 * Centreon also meet, for each linked independent module, the terms  and conditions
 * of the license of that module. An independent module is a module which is not
 * derived from this program. If you modify this program, you may extend this
 * exception to your version of the program, but you are not obliged to do so. If you
 * do not wish to do so, delete this exception statement from your version.
 *
 * For more information : <EMAIL>
 *
 */

if (!isset($centreon)) {
    exit();
}

if (!$oreon->user->admin) {
    if ($sc_id && $scString != "''" && false === strpos($scString, "'".$sc_id."'")) {
        $msg = new CentreonMsg();
        $msg->setImage("./img/icons/warning.png");
        $msg->setTextStyle("bold");
        $msg->setText(_('You are not allowed to access this service category'));
        return null;
    }
}

/*
 * Database retrieve information for Contact
 */
$cct = array();
if (($o == "c" || $o == "w") && $sc_id)	{
    $DBRESULT = $pearDB->query("SELECT * FROM `service_categories` WHERE `sc_id` = '".$sc_id."' LIMIT 1");
    /*
     * Set base value
     */
    $sc = array_map("myDecode", $DBRESULT->fetchRow());
    $DBRESULT->free();
    $sc['sc_severity_level'] = $sc['level'];
    $sc['sc_severity_icon'] = $sc['icon_id'];

    $sc["sc_svc"] = array();
    $sc["sc_svcTpl"] = array();
    $DBRESULT = $pearDB->query("SELECT scr.service_service_id, s.service_register FROM service_categories_relation scr, service s WHERE s.service_id = scr.service_service_id AND scr.sc_id = '$sc_id'");
    while ($res = $DBRESULT->fetchRow()) {
        if ($res["service_register"] == 1)
            $sc["sc_svc"][] = $res["service_service_id"];
        if ($res["service_register"] == 0)
            $sc["sc_svcTpl"][] = $res["service_service_id"];
    }
    $DBRESULT->free();
}

/*
 * Get Service Template Available
 */
$hServices = array();
$DBRESULT = $pearDB->query("SELECT service_alias, service_description, service_id FROM service WHERE service_register = '0' ORDER BY service_alias, service_description");
while ($elem = $DBRESULT->fetchRow())	{
    $elem["service_description"] = str_replace('#S#', "/", $elem["service_description"]);
    $elem["service_description"] = str_replace('#BS#', "\\", $elem["service_description"]);
    $elem["service_alias"] = str_replace('#S#', "/", $elem["service_alias"]);
    $elem["service_alias"] = str_replace('#BS#', "\\", $elem["service_alias"]);
    $hServicesTpl[$elem["service_id"]] = $elem["service_alias"] . " (".$elem["service_description"].")";
}
$DBRESULT->free();

/*
 * Define Template
 */
$attrsText 		= array("size"=>"30");
$attrsText2 	= array("size"=>"60");
$attrsAdvSelect = array("style" => "width: 300px; height: 150px;");
$attrsTextarea 	= array("rows"=>"5", "cols"=>"40");
$eTemplate	= '<table><tr><td><div class="ams">{label_2}</div>{unselected}</td><td align="center">{add}<br /><br /><br />{remove}</td><td><div class="ams">{label_3}</div>{selected}</td></tr></table>';
$attrServicetemplates = array(
    'datasourceOrigin' => 'ajax',
    'availableDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_servicetemplate&action=list',
    'multiple' => true,
    'linkedObject' => 'centreonServicetemplates'
);

/*
 * Form begin
 */
$form = new HTML_QuickForm('Form', 'post', "?p=".$p);
if ($o == "a")
    $form->addElement('header', 'title', _("Add a Service Category"));
else if ($o == "c")
    $form->addElement('header', 'title', _("Modify a Service Category"));
else if ($o == "w")
    $form->addElement('header', 'title', _("View a Service Category"));

/*
 * Contact basic information
 */
$form->addElement('header', 'information', _("Information"));
$form->addElement('header', 'links', _("Relations"));

/*
 * No possibility to change name and alias, because there's no interest
 */
$form->addElement('text', 'sc_name', _("Name"), $attrsText);
$form->addElement('text', 'sc_description', _("Description"), $attrsText);

/*
 * Severity
 */
$sctype = $form->addElement('checkbox', 'sc_type', _('Severity type'), null, array('id' => 'sc_type'));
if (isset($sc_id) && isset($sc['level']) && $sc['level'] != "") {
    $sctype->setValue('1');
}
$form->addElement('text', 'sc_severity_level', _("Level"), array("size" => "10"));
$iconImgs = return_image_list(1);
$form->addElement('select', 'sc_severity_icon', _("Icon"), $iconImgs, array(
                                                                            "id" => "icon_id",
                                                                            "onChange" => "showLogo('icon_id_ctn', this.value)",
                                                                            "onkeyup" => "this.blur(); this.focus();"));

$attrServicetemplate1 = array_merge(
    $attrServicetemplates,
    array('defaultDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_servicetemplate&action=defaultValues&target=servicecategories&field=sc_svcTpl&id=' . $sc_id)
);
$form->addElement('select2', 'sc_svcTpl', _("Linked Service Templates"), array(), $attrServicetemplate1);

$sc_activate[] = HTML_QuickForm::createElement('radio', 'sc_activate', null, _("Enabled"), '1');
$sc_activate[] = HTML_QuickForm::createElement('radio', 'sc_activate', null, _("Disabled"), '0');
$form->addGroup($sc_activate, 'sc_activate', _("Status"), '&nbsp;');
$form->setDefaults(array('sc_activate' => '1'));

$form->addElement('hidden', 'sc_id');
$redirect = $form->addElement('hidden', 'o');
$redirect->setValue($o);

if (is_array($select))	{
    $select_str = NULL;<commit_msg>Fixed issue in add service category<commit_after><?php
/*
 * Copyright 2005-2015 Centreon
 * Centreon is developped by : <NAME> and <NAME> under
 * GPL Licence 2.0.
 *
 * 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 ; either version 2 of the License.
 *
 * 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, see <http://www.gnu.org/licenses>.
 *
 * Linking this program statically or dynamically with other modules is making a
 * combined work based on this program. Thus, the terms and conditions of the GNU
 * General Public License cover the whole combination.
 *
 * As a special exception, the copyright holders of this program give Centreon
 * permission to link this program with independent modules to produce an executable,
 * regardless of the license terms of these independent modules, and to copy and
 * distribute the resulting executable under terms of Centreon choice, provided that
 * Centreon also meet, for each linked independent module, the terms  and conditions
 * of the license of that module. An independent module is a module which is not
 * derived from this program. If you modify this program, you may extend this
 * exception to your version of the program, but you are not obliged to do so. If you
 * do not wish to do so, delete this exception statement from your version.
 *
 * For more information : <EMAIL>
 *
 */

if (!isset($centreon)) {
    exit();
}

if (!$oreon->user->admin) {
    if ($sc_id && $scString != "''" && false === strpos($scString, "'".$sc_id."'")) {
        $msg = new CentreonMsg();
        $msg->setImage("./img/icons/warning.png");
        $msg->setTextStyle("bold");
        $msg->setText(_('You are not allowed to access this service category'));
        return null;
    }
}

/*
 * Database retrieve information for Contact
 */
$cct = array();
if (($o == "c" || $o == "w") && $sc_id)	{
    $DBRESULT = $pearDB->query("SELECT * FROM `service_categories` WHERE `sc_id` = '".$sc_id."' LIMIT 1");
    /*
     * Set base value
     */
    $sc = array_map("myDecode", $DBRESULT->fetchRow());
    $DBRESULT->free();
    $sc['sc_severity_level'] = $sc['level'];
    $sc['sc_severity_icon'] = $sc['icon_id'];

    $sc["sc_svc"] = array();
}

/*
 * Get Service Template Available
 */
$hServices = array();
$DBRESULT = $pearDB->query("SELECT service_alias, service_description, service_id FROM service WHERE service_register = '0' ORDER BY service_alias, service_description");
while ($elem = $DBRESULT->fetchRow())	{
    $elem["service_description"] = str_replace('#S#', "/", $elem["service_description"]);
    $elem["service_description"] = str_replace('#BS#', "\\", $elem["service_description"]);
    $elem["service_alias"] = str_replace('#S#', "/", $elem["service_alias"]);
    $elem["service_alias"] = str_replace('#BS#', "\\", $elem["service_alias"]);
    $hServicesTpl[$elem["service_id"]] = $elem["service_alias"] . " (".$elem["service_description"].")";
}
$DBRESULT->free();

/*
 * Define Template
 */
$attrsText 		= array("size"=>"30");
$attrsText2 	= array("size"=>"60");
$attrsAdvSelect = array("style" => "width: 300px; height: 150px;");
$attrsTextarea 	= array("rows"=>"5", "cols"=>"40");
$eTemplate	= '<table><tr><td><div class="ams">{label_2}</div>{unselected}</td><td align="center">{add}<br /><br /><br />{remove}</td><td><div class="ams">{label_3}</div>{selected}</td></tr></table>';
$attrServicetemplates = array(
    'datasourceOrigin' => 'ajax',
    'availableDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_servicetemplate&action=list',
    'multiple' => true,
    'linkedObject' => 'centreonServicetemplates'
);

/*
 * Form begin
 */
$form = new HTML_QuickForm('Form', 'post', "?p=".$p);
if ($o == "a")
    $form->addElement('header', 'title', _("Add a Service Category"));
else if ($o == "c")
    $form->addElement('header', 'title', _("Modify a Service Category"));
else if ($o == "w")
    $form->addElement('header', 'title', _("View a Service Category"));

/*
 * Contact basic information
 */
$form->addElement('header', 'information', _("Information"));
$form->addElement('header', 'links', _("Relations"));

/*
 * No possibility to change name and alias, because there's no interest
 */
$form->addElement('text', 'sc_name', _("Name"), $attrsText);
$form->addElement('text', 'sc_description', _("Description"), $attrsText);

/*
 * Severity
 */
$sctype = $form->addElement('checkbox', 'sc_type', _('Severity type'), null, array('id' => 'sc_type'));
if (isset($sc_id) && isset($sc['level']) && $sc['level'] != "") {
    $sctype->setValue('1');
}
$form->addElement('text', 'sc_severity_level', _("Level"), array("size" => "10"));
$iconImgs = return_image_list(1);
$form->addElement('select', 'sc_severity_icon', _("Icon"), $iconImgs, array(
                                                                            "id" => "icon_id",
                                                                            "onChange" => "showLogo('icon_id_ctn', this.value)",
                                                                            "onkeyup" => "this.blur(); this.focus();"));

$attrServicetemplate1 = array_merge(
    $attrServicetemplates,
    array('defaultDatasetRoute' => './include/common/webServices/rest/internal.php?object=centreon_configuration_servicetemplate&action=defaultValues&target=servicecategories&field=sc_svcTpl&id=' . $sc_id)
);

$form->addElement('select2', 'sc_svcTpl', _("Linked Service Templates"), array(), $attrServicetemplate1);

$sc_activate[] = HTML_QuickForm::createElement('radio', 'sc_activate', null, _("Enabled"), '1');
$sc_activate[] = HTML_QuickForm::createElement('radio', 'sc_activate', null, _("Disabled"), '0');
$form->addGroup($sc_activate, 'sc_activate', _("Status"), '&nbsp;');
$form->setDefaults(array('sc_activate' => '1'));

$form->addElement('hidden', 'sc_id');
$redirect = $form->addElement('hidden', 'o');
$redirect->setValue($o);

if (is_array($select))	{
    $select_str = NULL;
{'fraction_non_alphanumeric': 0.17649720923216172, 'fraction_numerical': 0.006034092623321768, 'mean_word_length': 4.125241592578276, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 136, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6894027', 'n_tokens_mistral': 4039, 'n_tokens_neox': 3988, 'n_words': 1105}