Merge branch 'develop' of github.com:Dolibarr/dolibarr into NEW_global_search_go_direct_on_card
This commit is contained in:
commit
d63d8088ed
@ -163,16 +163,17 @@ class AccountancyCategory // extends CommonObject
|
||||
|
||||
// Insert request
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_accounting_category(";
|
||||
if ($this->rowid > 0) $sql.= "rowid,";
|
||||
$sql.= "code,";
|
||||
$sql.= "label,";
|
||||
$sql.= "range_account,";
|
||||
$sql.= "sens,";
|
||||
$sql.= "category_type,";
|
||||
$sql.= "formula,";
|
||||
$sql.= "position,";
|
||||
$sql.= "fk_country,";
|
||||
$sql.= "active";
|
||||
if ($this->rowid > 0) $sql.= "rowid, ";
|
||||
$sql.= "code, ";
|
||||
$sql.= "label, ";
|
||||
$sql.= "range_account, ";
|
||||
$sql.= "sens, ";
|
||||
$sql.= "category_type, ";
|
||||
$sql.= "formula, ";
|
||||
$sql.= "position, ";
|
||||
$sql.= "fk_country, ";
|
||||
$sql.= "active, ";
|
||||
$sql.= "entity";
|
||||
$sql.= ") VALUES (";
|
||||
if ($this->rowid > 0) $sql.= " ".$this->rowid.",";
|
||||
$sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
|
||||
@ -184,6 +185,7 @@ class AccountancyCategory // extends CommonObject
|
||||
$sql.= " ".(! isset($this->position)?'NULL':$this->db->escape($this->position)).",";
|
||||
$sql.= " ".(! isset($this->fk_country)?'NULL':$this->db->escape($this->fk_country)).",";
|
||||
$sql.= " ".(! isset($this->active)?'NULL':$this->db->escape($this->active));
|
||||
$sql.= ", ".$conf->entity;
|
||||
$sql.= ")";
|
||||
|
||||
$this->db->begin();
|
||||
@ -237,9 +239,8 @@ class AccountancyCategory // extends CommonObject
|
||||
* @param string $label Label
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function fetch($id,$code='',$label='')
|
||||
function fetch($id, $code='', $label='')
|
||||
{
|
||||
global $langs;
|
||||
$sql = "SELECT";
|
||||
$sql.= " t.rowid,";
|
||||
$sql.= " t.code,";
|
||||
@ -253,8 +254,12 @@ class AccountancyCategory // extends CommonObject
|
||||
$sql.= " t.active";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as t";
|
||||
if ($id) $sql.= " WHERE t.rowid = ".$id;
|
||||
elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
|
||||
elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
|
||||
else
|
||||
{
|
||||
$sql.= " WHERE t.entity IN (".getEntity('c_accounting_category').")"; // Dont't use entity if you use rowid
|
||||
if ($code) $sql.= " AND t.code = '".$this->db->escape($code)."'";
|
||||
elseif ($label) $sql.= " AND t.label = '".$this->db->escape($label)."'";
|
||||
}
|
||||
|
||||
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
|
||||
$resql=$this->db->query($sql);
|
||||
@ -480,7 +485,7 @@ class AccountancyCategory // extends CommonObject
|
||||
$sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version";
|
||||
$sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS;
|
||||
$sql .= " AND aa.active = 1";
|
||||
$sql .= " AND aa.entity = = " . $conf->entity . ")";
|
||||
$sql .= " AND aa.entity = " . $conf->entity . ")";
|
||||
$sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref";
|
||||
$sql .= " ORDER BY t.numero_compte";
|
||||
|
||||
@ -713,27 +718,32 @@ class AccountancyCategory // extends CommonObject
|
||||
* Function to show result of an accounting account from the ledger with a direction and a period
|
||||
*
|
||||
* @param int $cpt Id accounting account
|
||||
* @param string $month Specifig month - Can be empty
|
||||
* @param string $date_start Date start
|
||||
* @param string $date_end Date end
|
||||
* @param int $sens Sens of the account: 0: credit - debit, 1: debit - credit
|
||||
* @param string $thirdparty_code Thirdparty code
|
||||
* @param string $month Specifig month - Can be empty
|
||||
* @param string $year Specifig year - Can be empty
|
||||
* @return integer Result in table
|
||||
*/
|
||||
public function getResult($cpt, $month, $date_start, $date_end, $sens, $thirdparty_code='nofilter')
|
||||
public function getSumDebitCredit($cpt, $date_start, $date_end, $sens, $thirdparty_code='nofilter', $month=0, $year=0)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t";
|
||||
$sql .= " WHERE t.numero_compte = '" . $cpt."'";
|
||||
if (! empty($date_start) && ! empty($date_end))
|
||||
$sql.= " AND t.doc_date >= '".$this->db->idate($date_start)."' AND t.doc_date <= '".$this->db->idate($date_end)."'";
|
||||
if (! empty($month)) {
|
||||
$sql .= " AND MONTH(t.doc_date) = " . $month;
|
||||
$sql .= " WHERE t.numero_compte = '" . $this->db->escape($cpt) . "'";
|
||||
if (! empty($date_start) && ! empty($date_end) && (empty($month) || empty($year))) // If month/year provided, it is stronger than filter date_start/date_end
|
||||
$sql .= " AND t.doc_date BETWEEN '".$this->db->idate($date_start)."' AND '".$this->db->idate($date_end)."'";
|
||||
if (! empty($month) && ! empty($year)) {
|
||||
$sql .= " AND t.doc_date BETWEEN '".$this->db->idate(dol_get_first_day($year, $month))."' AND '".$this->db->idate(dol_get_last_day($year, $month))."'";
|
||||
}
|
||||
if ($thirdparty_code != 'nofilter')
|
||||
{
|
||||
$sql .= " AND thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
|
||||
$sql .= " AND t.thirdparty_code = '".$this->db->escape($thirdparty_code)."'";
|
||||
}
|
||||
$sql .= " AND t.entity = ".$conf->entity;
|
||||
//print $sql;
|
||||
|
||||
dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
@ -766,7 +776,7 @@ class AccountancyCategory // extends CommonObject
|
||||
*/
|
||||
public function getCats($categorytype=-1)
|
||||
{
|
||||
global $db, $langs, $user, $mysoc, $conf;
|
||||
global $conf, $mysoc;
|
||||
|
||||
if (empty($mysoc->country_id)) {
|
||||
dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined');
|
||||
@ -775,7 +785,7 @@ class AccountancyCategory // extends CommonObject
|
||||
|
||||
$sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c";
|
||||
$sql .= " WHERE c.active = 1 ";
|
||||
$sql .= " WHERE c.active = 1";
|
||||
$sql .= " AND c.entity = " . $conf->entity;
|
||||
if ($categorytype >= 0) $sql.=" AND c.category_type = 1";
|
||||
$sql .= " AND (c.fk_country = ".$mysoc->country_id." OR c.fk_country = 0)";
|
||||
@ -823,7 +833,7 @@ class AccountancyCategory // extends CommonObject
|
||||
*/
|
||||
public function getCptsCat($cat_id, $predefinedgroupwhere='')
|
||||
{
|
||||
global $mysoc;
|
||||
global $conf, $mysoc;
|
||||
$sql = '';
|
||||
|
||||
if (empty($mysoc->country_id) && empty($mysoc->country_code)) {
|
||||
@ -836,6 +846,7 @@ class AccountancyCategory // extends CommonObject
|
||||
$sql = "SELECT t.rowid, t.account_number, t.label as account_label";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
|
||||
$sql .= " WHERE t.fk_accounting_category = ".$cat_id;
|
||||
$sql .= " AND t.entity = " . $conf->entity;
|
||||
$sql .= " ORDER BY t.account_number";
|
||||
}
|
||||
else
|
||||
@ -843,6 +854,7 @@ class AccountancyCategory // extends CommonObject
|
||||
$sql = "SELECT t.rowid, t.account_number, t.label as account_label";
|
||||
$sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t";
|
||||
$sql .= " WHERE ".$predefinedgroupwhere;
|
||||
$sql .= " AND t.entity = " . $conf->entity;
|
||||
$sql .= " ORDER BY t.account_number";
|
||||
}
|
||||
//echo $sql;
|
||||
@ -856,13 +868,12 @@ class AccountancyCategory // extends CommonObject
|
||||
if ($num) {
|
||||
while ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
$name_cat = $obj->name_cat;
|
||||
$data[] = array (
|
||||
'id' => $obj->rowid,
|
||||
'account_number' => $obj->account_number,
|
||||
'account_label' => $obj->account_label,
|
||||
);
|
||||
$i ++;
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
|
||||
@ -24,6 +24,7 @@
|
||||
|
||||
require '../main.inc.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/dolgeoip.class.php';
|
||||
|
||||
// Security check
|
||||
@ -150,6 +151,25 @@ if ($geoip)
|
||||
if ($result) print $result;
|
||||
else print $langs->trans("Error");
|
||||
*/
|
||||
//var_dump($_SERVER);
|
||||
$ip = getUserRemoteIP();
|
||||
//$ip='91.161.249.43';
|
||||
$isip=is_ip($ip);
|
||||
if ($isip == 1)
|
||||
{
|
||||
print '<br>'.$ip.' -> ';
|
||||
$result=dol_print_ip($ip,1);
|
||||
if ($result) print $result;
|
||||
else print $langs->trans("Error");
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<br>'.$ip.' -> ';
|
||||
$result=dol_print_ip($ip,1);
|
||||
if ($result) print $result;
|
||||
else print $langs->trans("NotAPublicIp");
|
||||
}
|
||||
|
||||
$geoip->close();
|
||||
}
|
||||
|
||||
|
||||
@ -303,7 +303,7 @@ if ($modecompta == 'BOOKKEEPING')
|
||||
|
||||
foreach($cpts as $i => $cpt)
|
||||
{
|
||||
$return = $AccCat->getResult($cpt['account_number'], 0, $date_start, $date_end, $cpt['dc']);
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']);
|
||||
if ($return < 0) {
|
||||
setEventMessages(null, $AccCat->errors, 'errors');
|
||||
$resultN=0;
|
||||
|
||||
@ -78,7 +78,7 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end
|
||||
{
|
||||
// We define date_start and date_end
|
||||
$year_end=$year_start + ($nbofyear - 1);
|
||||
$month_start=GETPOST("month")?GETPOST("month"):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
|
||||
$month_start=GETPOST("month",'int')?GETPOST("month",'int'):($conf->global->SOCIETE_FISCAL_MONTH_START?($conf->global->SOCIETE_FISCAL_MONTH_START):1);
|
||||
$date_startmonth = $month_start;
|
||||
if (! GETPOST('month'))
|
||||
{
|
||||
@ -108,8 +108,10 @@ if (($date_start < dol_time_plus_duree($date_end, -1, 'y')) || ($date_start > $d
|
||||
// $date_start and $date_end are defined. We force $start_year and $nbofyear
|
||||
$tmps=dol_getdate($date_start);
|
||||
$start_year = $tmps['year'];
|
||||
$start_month = $tmps['mon'];
|
||||
$tmpe=dol_getdate($date_end);
|
||||
$year_end = $tmpe['year'];
|
||||
$month_end = $tmpe['mon'];
|
||||
$nbofyear = ($year_end - $start_year) + 1;
|
||||
|
||||
$date_start_previous = dol_time_plus_duree($date_start, -1, 'y');
|
||||
@ -231,13 +233,13 @@ print '<th class="liste_titre" align="right">'.$langs->trans("SelectedPeriod").'
|
||||
foreach($months as $k => $v){
|
||||
if (($k+1) >= $date_startmonth)
|
||||
{
|
||||
print '<th class="liste_titre width50" align="right" >'.$langs->trans($v).'</th>';
|
||||
print '<th class="liste_titre width50" align="right" >'.$langs->trans('MonthShort'.sprintf("%02s",($k+1))).'</th>';
|
||||
}
|
||||
}
|
||||
foreach($months as $k => $v){
|
||||
if (($k+1) < $date_startmonth)
|
||||
{
|
||||
print '<th class="liste_titre width50" align="right" >'.$langs->trans($v).'</th>';
|
||||
print '<th class="liste_titre width50" align="right" >'.$langs->trans('MonthShort'.sprintf("%02s",($k+1))).'</th>';
|
||||
}
|
||||
}
|
||||
print '</tr>';
|
||||
@ -374,7 +376,6 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
print "</tr>\n";
|
||||
|
||||
//var_dump($sommes);
|
||||
@ -390,7 +391,7 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
$totCat['M'][$k] = 0;
|
||||
}
|
||||
|
||||
// Set $cpts of with array of accounts in the category/group
|
||||
// Set $cpts with array of accounts in the category/group
|
||||
$cpts = $AccCat->getCptsCat($cat['rowid']);
|
||||
|
||||
print "<tr>";
|
||||
@ -428,13 +429,15 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
|
||||
$code = $cat['code'];
|
||||
|
||||
// Set value into column NPrevious, N and each month M ($totCat)
|
||||
// This make 14 calls for each detail of account (NP, N and month m)
|
||||
foreach($cpts as $i => $cpt)
|
||||
// Set value into column N-1, N and each month M ($totCat)
|
||||
// This make 14 calls for each detail of account (N-1, N and 12 monthes m)
|
||||
foreach($cpts as $i => $cpt) // Loop on each account.
|
||||
{
|
||||
// N-1
|
||||
$return = $AccCat->getResult($cpt['account_number'], 0, $date_start_previous, $date_end_previous, $cpt['dc']);
|
||||
// We make 1 loop for each account because we may want detail.
|
||||
// @TODO Optimize mode when $showaccountdetail == 'no'
|
||||
|
||||
// N-1
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start_previous, $date_end_previous, $cpt['dc']);
|
||||
if ($return < 0) {
|
||||
setEventMessages(null, $AccCat->errors, 'errors');
|
||||
$resultNP=0;
|
||||
@ -442,8 +445,8 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
$resultNP=$AccCat->sdc;
|
||||
}
|
||||
|
||||
//N
|
||||
$return = $AccCat->getResult($cpt['account_number'], 0, $date_start, $date_end, $cpt['dc']);
|
||||
// N
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc']);
|
||||
if ($return < 0) {
|
||||
setEventMessages(null, $AccCat->errors, 'errors');
|
||||
$resultN=0;
|
||||
@ -458,9 +461,15 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
$totPerAccount[$cpt['account_number']]['NP'] = $resultNP;
|
||||
$totPerAccount[$cpt['account_number']]['N'] = $resultN;
|
||||
|
||||
// Each month
|
||||
foreach($months as $k => $v)
|
||||
{
|
||||
$return = $AccCat->getResult($cpt['account_number'], $k+1, $date_start, $date_end, $cpt['dc']);
|
||||
$monthtoprocess = $k+1; // ($k+1) is month 1, 2, ..., 12
|
||||
$yeartoprocess = $start_year;
|
||||
if (($k+1) < $start_month) $yeartoprocess++;
|
||||
|
||||
//var_dump($monthtoprocess.'_'.$yeartoprocess);
|
||||
$return = $AccCat->getSumDebitCredit($cpt['account_number'], $date_start, $date_end, $cpt['dc'], 'nofilter', $monthtoprocess, $yeartoprocess);
|
||||
if ($return < 0) {
|
||||
setEventMessages(null, $AccCat->errors, 'errors');
|
||||
$resultM=0;
|
||||
@ -488,7 +497,7 @@ elseif ($modecompta=="BOOKKEEPING")
|
||||
print "</tr>\n";
|
||||
|
||||
// Loop on detail of all accounts
|
||||
// This make 14 calls for each detail of account (NP, N and month m)
|
||||
// This make 14 calls for each detail of account (N-1, N and 12 monthes m)
|
||||
if ($showaccountdetail != 'no')
|
||||
{
|
||||
foreach($cpts as $i => $cpt)
|
||||
|
||||
@ -137,6 +137,7 @@ class Events // extends CommonObject
|
||||
|
||||
// Clean parameters
|
||||
$this->description=trim($this->description);
|
||||
if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
// Check parameters
|
||||
if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
|
||||
@ -153,8 +154,8 @@ class Events // extends CommonObject
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= " '".$this->db->escape($this->type)."',";
|
||||
$sql.= " ".$conf->entity.",";
|
||||
$sql.= " '".$this->db->escape($_SERVER['REMOTE_ADDR'])."',";
|
||||
$sql.= " ".($_SERVER['HTTP_USER_AGENT']?"'".$this->db->escape(dol_trunc($_SERVER['HTTP_USER_AGENT'],250))."'":'NULL').",";
|
||||
$sql.= " '".$this->db->escape(getUserRemoteIP())."',";
|
||||
$sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').",";
|
||||
$sql.= " '".$this->db->idate($this->dateevent)."',";
|
||||
$sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').",";
|
||||
$sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'";
|
||||
|
||||
@ -2665,6 +2665,20 @@ function dol_print_ip($ip,$mode=0)
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the IP of remote user.
|
||||
* Take HTTP_X_FORWARDED_FOR (defined when using proxy)
|
||||
* Then HTTP_CLIENT_IP if defined (rare)
|
||||
* Then REMOTE_ADDR (not way to be modified by user but may be wrong if using proxy)
|
||||
*
|
||||
* @return string Ip of remote user.
|
||||
*/
|
||||
function getUserRemoteIP()
|
||||
{
|
||||
$ip = $_SERVER['HTTP_X_FORWARDED_FOR']?$_SERVER['HTTP_X_FORWARDED_FOR']:(($_SERVER['HTTP_CLIENT_IP']?$_SERVER['HTTP_CLIENT_IP']:$_SERVER['REMOTE_ADDR']));
|
||||
return $ip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a country code from IP. Empty string if not found.
|
||||
*
|
||||
@ -2708,7 +2722,7 @@ function dol_user_country()
|
||||
$ret='';
|
||||
if (! empty($conf->geoipmaxmind->enabled))
|
||||
{
|
||||
$ip=$_SERVER["REMOTE_ADDR"];
|
||||
$ip=getUserRemoteIP();
|
||||
$datafile=$conf->global->GEOIPMAXMIND_COUNTRY_DATAFILE;
|
||||
//$ip='24.24.24.24';
|
||||
//$datafile='E:\Mes Sites\Web\Admin1\awstats\maxmind\GeoIP.dat';
|
||||
@ -5783,7 +5797,7 @@ function getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $ob
|
||||
'__USER_FIRSTNAME__' => (string) $user->firstname,
|
||||
'__USER_FULLNAME__' => (string) $user->getFullName($outputlangs),
|
||||
'__USER_SUPERVISOR_ID__' => (string) ($user->fk_user ? $user->fk_user : '0'),
|
||||
'__USER_REMOTE_IP__' => (string) $_SERVER['REMOTE_ADDR']
|
||||
'__USER_REMOTE_IP__' => (string) getUserRemoteIP()
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -6770,6 +6784,216 @@ function picto_from_langcode($codelang, $moreatt = '')
|
||||
return img_picto_common($codelang, 'flags/'.strtolower($flagImage).'.png', $moreatt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return default language from country code
|
||||
*
|
||||
* @param string $countrycode Country code like 'US', 'FR', 'CA', ...
|
||||
* @return string Value of locale like 'en_US', 'fr_FR', ...
|
||||
*/
|
||||
function getLanguageCodeFromCountryCode($countrycode)
|
||||
{
|
||||
global $mysoc;
|
||||
|
||||
if (strtoupper($countrycode) == 'MQ') return 'fr_CA';
|
||||
if (strtoupper($countrycode) == 'SE') return 'sv_SE'; // se_SE is Sami/Sweden, and we want in priority sv_SE for SE country
|
||||
if (strtoupper($countrycode) == 'CH')
|
||||
{
|
||||
if ($mysoc->country_code == 'FR') return 'fr_CH';
|
||||
if ($mysoc->country_code == 'DE') return 'de_CH';
|
||||
}
|
||||
|
||||
// Locale list taken from:
|
||||
// http://stackoverflow.com/questions/3191664/
|
||||
// list-of-all-locales-and-their-short-codes
|
||||
$locales = array(
|
||||
'af-ZA',
|
||||
'am-ET',
|
||||
'ar-AE',
|
||||
'ar-BH',
|
||||
'ar-DZ',
|
||||
'ar-EG',
|
||||
'ar-IQ',
|
||||
'ar-JO',
|
||||
'ar-KW',
|
||||
'ar-LB',
|
||||
'ar-LY',
|
||||
'ar-MA',
|
||||
'ar-OM',
|
||||
'ar-QA',
|
||||
'ar-SA',
|
||||
'ar-SY',
|
||||
'ar-TN',
|
||||
'ar-YE',
|
||||
'as-IN',
|
||||
'ba-RU',
|
||||
'be-BY',
|
||||
'bg-BG',
|
||||
'bn-BD',
|
||||
'bn-IN',
|
||||
'bo-CN',
|
||||
'br-FR',
|
||||
'ca-ES',
|
||||
'co-FR',
|
||||
'cs-CZ',
|
||||
'cy-GB',
|
||||
'da-DK',
|
||||
'de-AT',
|
||||
'de-CH',
|
||||
'de-DE',
|
||||
'de-LI',
|
||||
'de-LU',
|
||||
'dv-MV',
|
||||
'el-GR',
|
||||
'en-AU',
|
||||
'en-BZ',
|
||||
'en-CA',
|
||||
'en-GB',
|
||||
'en-IE',
|
||||
'en-IN',
|
||||
'en-JM',
|
||||
'en-MY',
|
||||
'en-NZ',
|
||||
'en-PH',
|
||||
'en-SG',
|
||||
'en-TT',
|
||||
'en-US',
|
||||
'en-ZA',
|
||||
'en-ZW',
|
||||
'es-AR',
|
||||
'es-BO',
|
||||
'es-CL',
|
||||
'es-CO',
|
||||
'es-CR',
|
||||
'es-DO',
|
||||
'es-EC',
|
||||
'es-ES',
|
||||
'es-GT',
|
||||
'es-HN',
|
||||
'es-MX',
|
||||
'es-NI',
|
||||
'es-PA',
|
||||
'es-PE',
|
||||
'es-PR',
|
||||
'es-PY',
|
||||
'es-SV',
|
||||
'es-US',
|
||||
'es-UY',
|
||||
'es-VE',
|
||||
'et-EE',
|
||||
'eu-ES',
|
||||
'fa-IR',
|
||||
'fi-FI',
|
||||
'fo-FO',
|
||||
'fr-BE',
|
||||
'fr-CA',
|
||||
'fr-CH',
|
||||
'fr-FR',
|
||||
'fr-LU',
|
||||
'fr-MC',
|
||||
'fy-NL',
|
||||
'ga-IE',
|
||||
'gd-GB',
|
||||
'gl-ES',
|
||||
'gu-IN',
|
||||
'he-IL',
|
||||
'hi-IN',
|
||||
'hr-BA',
|
||||
'hr-HR',
|
||||
'hu-HU',
|
||||
'hy-AM',
|
||||
'id-ID',
|
||||
'ig-NG',
|
||||
'ii-CN',
|
||||
'is-IS',
|
||||
'it-CH',
|
||||
'it-IT',
|
||||
'ja-JP',
|
||||
'ka-GE',
|
||||
'kk-KZ',
|
||||
'kl-GL',
|
||||
'km-KH',
|
||||
'kn-IN',
|
||||
'ko-KR',
|
||||
'ky-KG',
|
||||
'lb-LU',
|
||||
'lo-LA',
|
||||
'lt-LT',
|
||||
'lv-LV',
|
||||
'mi-NZ',
|
||||
'mk-MK',
|
||||
'ml-IN',
|
||||
'mn-MN',
|
||||
'mr-IN',
|
||||
'ms-BN',
|
||||
'ms-MY',
|
||||
'mt-MT',
|
||||
'nb-NO',
|
||||
'ne-NP',
|
||||
'nl-BE',
|
||||
'nl-NL',
|
||||
'nn-NO',
|
||||
'oc-FR',
|
||||
'or-IN',
|
||||
'pa-IN',
|
||||
'pl-PL',
|
||||
'ps-AF',
|
||||
'pt-BR',
|
||||
'pt-PT',
|
||||
'rm-CH',
|
||||
'ro-RO',
|
||||
'ru-RU',
|
||||
'rw-RW',
|
||||
'sa-IN',
|
||||
'se-FI',
|
||||
'se-NO',
|
||||
'se-SE',
|
||||
'si-LK',
|
||||
'sk-SK',
|
||||
'sl-SI',
|
||||
'sq-AL',
|
||||
'sv-FI',
|
||||
'sv-SE',
|
||||
'sw-KE',
|
||||
'syr-SY',
|
||||
'ta-IN',
|
||||
'te-IN',
|
||||
'th-TH',
|
||||
'tk-TM',
|
||||
'tn-ZA',
|
||||
'tr-TR',
|
||||
'tt-RU',
|
||||
'ug-CN',
|
||||
'uk-UA',
|
||||
'ur-PK',
|
||||
'vi-VN',
|
||||
'wo-SN',
|
||||
'xh-ZA',
|
||||
'yo-NG',
|
||||
'zh-CN',
|
||||
'zh-HK',
|
||||
'zh-MO',
|
||||
'zh-SG',
|
||||
'zh-TW',
|
||||
'zu-ZA',
|
||||
);
|
||||
|
||||
$buildprimarykeytotest = strtolower($countrycode).'-'.strtoupper($countrycode);
|
||||
if (in_array($buildprimarykeytotest, $locales)) return strtolower($countrycode).'_'.strtoupper($countrycode);
|
||||
|
||||
foreach ($locales as $locale)
|
||||
{
|
||||
$locale_language = locale_get_primary_language($locale);
|
||||
$locale_region = locale_get_region($locale);
|
||||
if (strtoupper($countrycode) == $locale_region)
|
||||
{
|
||||
//var_dump($locale.'-'.$locale_language.'-'.$locale_region);
|
||||
return strtolower($locale_language).'_'.strtoupper($locale_region);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Complete or removed entries into a head array (used to build tabs).
|
||||
* For example, with value added by external modules. Such values are declared into $conf->modules_parts['tab'].
|
||||
|
||||
@ -48,7 +48,7 @@ if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is
|
||||
* @backupStaticAttributes enabled
|
||||
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||
*/
|
||||
class FunctionsLibTest extends PHPUnit_Framework_TestCase
|
||||
class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $savconf;
|
||||
protected $savuser;
|
||||
@ -325,6 +325,57 @@ class FunctionsLibTest extends PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* testGetLanguageCodeFromCountryCode
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testGetLanguageCodeFromCountryCode()
|
||||
{
|
||||
global $mysoc;
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('US');
|
||||
$this->assertEquals('en_US', $language, 'US');
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('ES');
|
||||
$this->assertEquals('es_ES', $language, 'ES');
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('CL');
|
||||
$this->assertEquals('es_CL', $language, 'CL');
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('CA');
|
||||
$this->assertEquals('en_CA', $language, 'CA');
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('MQ');
|
||||
$this->assertEquals('fr_CA', $language);
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('FR');
|
||||
$this->assertEquals('fr_FR', $language);
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('BE');
|
||||
$this->assertEquals('fr_BE', $language);
|
||||
|
||||
$mysoc->country_code = 'FR';
|
||||
$language = getLanguageCodeFromCountryCode('CH');
|
||||
$this->assertEquals('fr_CH', $language);
|
||||
|
||||
$mysoc->country_code = 'DE';
|
||||
$language = getLanguageCodeFromCountryCode('CH');
|
||||
$this->assertEquals('de_CH', $language);
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('DE');
|
||||
$this->assertEquals('de_DE', $language);
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('SA');
|
||||
$this->assertEquals('ar_SA', $language);
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('SE');
|
||||
$this->assertEquals('sv_SE', $language);
|
||||
|
||||
$language = getLanguageCodeFromCountryCode('DK');
|
||||
$this->assertEquals('da_DK', $language);
|
||||
}
|
||||
|
||||
/**
|
||||
* testDolTextIsHtml
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user