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

Commit

Permalink
fix(lang): replace default language value from 'NULL' to 'browser'
Browse files Browse the repository at this point in the history
  • Loading branch information
sc979 committed Jan 3, 2019
1 parent 909d649 commit 6a1dd52
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 13 deletions.
64 changes: 64 additions & 0 deletions www/api/class/centreon_datepicker_i18n.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright 2005-2018 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus 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 : contact@centreon.com
*
*/

/**
* Webservice that allow to load the datepicker library from user's language if the file exists.
*/
class CentreonDatepickerI18n extends CentreonWebService
{
/**
* Used to search and load the right datepicker library if it exists.
*
* @return string|null
*/
public function getDatepickerLibrary()
{
$data = $this->arguments['data'];
$path = __DIR__ . "/../../include/common/javascript/datepicker/";

// check if the fullLocale library exist
$datepickerFileToFound = "datepicker-" . substr($data, 0, 5) . ".js";
$valid = file_exists($path . $datepickerFileToFound);

// if not found, then check if the shortLocale library exist
if ($valid !== true) {
$datepickerFileToFound = "datepicker-" . substr($data, 0, 2) . ".js";
$valid = file_exists($path . $datepickerFileToFound);
}

//sending result
return ($valid === true) ? $datepickerFileToFound : null;
}
}
11 changes: 6 additions & 5 deletions www/class/centreonLang.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public function __construct($centreon_path, $centreon = null)
$this->lang = $centreon->user->lang;
}
}

$this->path = $centreon_path;
$this->setCharsetList();
}
Expand Down Expand Up @@ -124,8 +123,9 @@ private function parseHttpAcceptHeader()
}

/**
* Used to get the language set in the browser
*
* @return type
* @return string
*/
private function getBrowserDefaultLanguage()
{
Expand All @@ -137,14 +137,15 @@ private function getBrowserDefaultLanguage()
} else {
$currentLocale .= $this->parseHttpAcceptHeader();
}

return $this->getFullLocale($currentLocale);
}

/**
* Used to convert the browser language's from a short string to a string
*
* @param type $shortLocale
* @return string
* @param string $shortLocale
* @return string $fullLocale
*/
private function getFullLocale($shortLocale)
{
Expand Down
2 changes: 1 addition & 1 deletion www/include/Administration/myAccount/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function updateContact($contact_id = null)
$rq .= "contact_lang = ";
isset($ret["contact_lang"]) && $ret["contact_lang"] != null
? $rq .= "'" . htmlentities($ret["contact_lang"], ENT_QUOTES, "UTF-8") . "', "
: $rq .= "NULL, ";
: $rq .= "browser, ";
$rq .= "contact_email = ";
isset($ret["contact_email"]) && $ret["contact_email"] != null
? $rq .= "'" . htmlentities($ret["contact_email"], ENT_QUOTES, "UTF-8") . "', "
Expand Down
12 changes: 7 additions & 5 deletions www/include/configuration/configObject/contact/DB-Func.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ function insertContact($ret = array())

isset($ret["contact_lang"]) && $ret["contact_lang"] != null
? $rq .= "'" . htmlentities($ret["contact_lang"], ENT_QUOTES, "UTF-8") . "', "
: $rq .= "NULL, ";
: $rq .= "browser, ";
isset($ret["contact_template_id"]) && $ret["contact_template_id"] != null
? $rq .= "'" . htmlentities($ret["contact_template_id"], ENT_QUOTES, "UTF-8") . "', "
: $rq .= "NULL, ";
Expand Down Expand Up @@ -627,7 +627,7 @@ function updateContact($contact_id = null, $from_MC = false)
$rq .= "contact_lang = ";
isset($ret["contact_lang"]) && $ret["contact_lang"] != null
? $rq .= "'" . htmlentities($ret["contact_lang"], ENT_QUOTES, "UTF-8") . "', "
: $rq .= "NULL, ";
: $rq .= "browser, ";
$rq .= "contact_host_notification_options = ";
isset($ret["contact_hostNotifOpts"]) && $ret["contact_hostNotifOpts"] != null
? $rq .= "'" . implode(",", array_keys($ret["contact_hostNotifOpts"])) . "', "
Expand Down Expand Up @@ -780,9 +780,11 @@ function updateContact_MC($contact_id = null)
$dependencyInjector['utils']->encodePass($ret["contact_passwd"], 'md5') . "', ";
}
}
if (isset($ret["contact_lang"]) && $ret["contact_lang"] != null && $ret['contact_lang']) {
$rq .= "contact_lang = '" . htmlentities($ret["contact_lang"], ENT_QUOTES, "UTF-8") . "', ";
}
$rq .= "contact_lang = ";
isset($ret["contact_lang"]) && $ret["contact_lang"] != null && $ret['contact_lang']
? $rq .= "'" . htmlentities($ret["contact_lang"], ENT_QUOTES, "UTF-8") . "', "
: $rq .= "browser, ";

if (isset($ret['contact_enable_notifications']['contact_enable_notifications']) &&
$ret['contact_enable_notifications']['contact_enable_notifications'] != null
) {
Expand Down
2 changes: 1 addition & 1 deletion www/install/createTables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ CREATE TABLE `contact` (
`contact_name` varchar(200) DEFAULT NULL,
`contact_alias` varchar(200) DEFAULT NULL,
`contact_passwd` varchar(255) DEFAULT NULL,
`contact_lang` varchar(255) DEFAULT NULL,
`contact_lang` varchar(255) DEFAULT 'browser',
`contact_host_notification_options` varchar(200) DEFAULT NULL,
`contact_service_notification_options` varchar(200) DEFAULT NULL,
`contact_email` varchar(200) DEFAULT NULL,
Expand Down
6 changes: 5 additions & 1 deletion www/install/sql/centreon/Update-DB-18.10.2_to_18.10.3.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
UPDATE `informations` SET `value` = '18.10.3' WHERE CONVERT( `informations`.`key` USING utf8 ) = 'version' AND CONVERT ( `informations`.`value` USING utf8 ) = '18.10.2' LIMIT 1;

-- Remove old progressbar lib
DELETE FROM topology_JS WHERE PathName_js LIKE '%aculous%';
DELETE FROM topology_JS WHERE PathName_js LIKE '%aculous%';

-- Changing contact_lang default value to 'browser' and each of its value from NULL to 'browser'
ALTER TABLE contact MODIFY `contact_lang` varchar(255) DEFAULT 'browser';
UPDATE contact SET `contact_lang` = 'browser' WHERE `contact_lang` IS NULL;

0 comments on commit 6a1dd52

Please sign in to comment.