2
0
forked from Wavyzz/dolibarr
develop_mc

Conflicts:
	ChangeLog
This commit is contained in:
Regis Houssin
2018-12-03 08:46:03 +01:00
303 changed files with 35025 additions and 5383 deletions

View File

@@ -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 = empty($_SERVER['HTTP_X_FORWARDED_FOR'])? (empty($_SERVER['HTTP_CLIENT_IP'])?(empty($_SERVER['REMOTE_ADDR'])?'':$_SERVER['REMOTE_ADDR']):$_SERVER['HTTP_CLIENT_IP']) : $_SERVER['HTTP_X_FORWARDED_FOR'];
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';
@@ -2890,188 +2904,6 @@ function dol_substr($string, $start, $length, $stringencoding='', $trunconbytes=
}
/**
* Show a javascript graph.
* Do not use this function anymore. Use DolGraph class instead.
*
* @param string $htmlid Html id name
* @param int $width Width in pixel
* @param int $height Height in pixel
* @param array $data Data array
* @param int $showlegend 1 to show legend, 0 otherwise
* @param string $type Type of graph ('pie', 'barline')
* @param int $showpercent Show percent (with type='pie' only)
* @param string $url Param to add an url to click values
* @param int $combineother 0=No combine, 0.05=Combine if lower than 5%
* @param int $shownographyet Show graph to say there is not enough data
* @return void
* @deprecated
* @see DolGraph
*/
function dol_print_graph($htmlid,$width,$height,$data,$showlegend=0,$type='pie',$showpercent=0,$url='',$combineother=0.05,$shownographyet=0)
{
dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
global $conf,$langs;
global $theme_datacolor; // To have var kept when function is called several times
if ($shownographyet)
{
print '<div class="nographyet" style="width:'.$width.'px;height:'.$height.'px;"></div>';
print '<div class="nographyettext">'.$langs->trans("NotEnoughDataYet").'</div>';
return;
}
if (empty($conf->use_javascript_ajax)) return;
$jsgraphlib='flot';
$datacolor=array();
// Load colors of theme into $datacolor array
$color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/graph-color.php";
if (is_readable($color_file))
{
include_once $color_file;
if (isset($theme_datacolor))
{
$datacolor=array();
foreach($theme_datacolor as $val)
{
$datacolor[]="#".sprintf("%02x",$val[0]).sprintf("%02x",$val[1]).sprintf("%02x",$val[2]);
}
}
}
print '<div id="'.$htmlid.'" style="width:'.$width.'px;height:'.$height.'px;"></div>';
// We use Flot js lib
if ($jsgraphlib == 'flot')
{
if ($type == 'pie')
{
// data is array('series'=>array(serie1,serie2,...),
// 'seriestype'=>array('bar','line',...),
// 'seriescolor'=>array(0=>'#999999',1=>'#999999',...)
// 'xlabel'=>array(0=>labelx1,1=>labelx2,...));
// serieX is array('label'=>'label', data=>val)
print '
<script type="text/javascript">
$(function () {
var data = '.json_encode($data['series']).';
function plotWithOptions() {
$.plot($("#'.$htmlid.'"), data,
{
series: {
pie: {
show: true,
radius: 0.8,';
if ($combineother)
{
print '
combine: {
threshold: '.$combineother.'
},';
}
print '
label: {
show: true,
radius: 0.9,
formatter: function(label, series) {
var percent=Math.round(series.percent);
var number=series.data[0][1];
return \'';
print '<div style="font-size:8pt;text-align:center;padding:2px;color:black;">';
if ($url) print '<a style="color: #FFFFFF;" border="0" href="'.$url.'">';
print '\'+'.($showlegend?'number':'label+\' \'+number');
if (! empty($showpercent)) print '+\'<br/>\'+percent+\'%\'';
print '+\'';
if ($url) print '</a>';
print '</div>\';
},
background: {
opacity: 0.0,
color: \'#000000\'
},
}
}
},
zoom: {
interactive: true
},
pan: {
interactive: true
},';
if (count($datacolor))
{
print 'colors: '.(! empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
}
print 'legend: {show: '.($showlegend?'true':'false').', position: \'ne\' }
});
}
plotWithOptions();
});
</script>';
}
else if ($type == 'barline')
{
// data is array('series'=>array(serie1,serie2,...),
// 'seriestype'=>array('bar','line',...),
// 'seriescolor'=>array(0=>'#999999',1=>'#999999',...)
// 'xlabel'=>array(0=>labelx1,1=>labelx2,...));
// serieX is array('label'=>'label', data=>array(0=>y1,1=>y2,...)) with same nb of value than into xlabel
print '
<script type="text/javascript">
$(function () {
var data = [';
$i=0; $outputserie=0;
foreach($data['series'] as $serie)
{
if ($data['seriestype'][$i]=='line') { $i++; continue; };
if ($outputserie > 0) print ',';
print '{ bars: { stack: 0, show: true, barWidth: 0.9, align: \'center\' }, label: \''.dol_escape_js($serie['label']).'\', data: '.json_encode($serie['data']).'}'."\n";
$outputserie++; $i++;
}
if ($outputserie) print ', ';
//print '];
//var datalines = [';
$i=0; $outputserie=0;
foreach($data['series'] as $serie)
{
if (empty($data['seriestype'][$i]) || $data['seriestype'][$i]=='bar') { $i++; continue; };
if ($outputserie > 0) print ',';
print '{ lines: { show: true }, label: \''.dol_escape_js($serie['label']).'\', data: '.json_encode($serie['data']).'}'."\n";
$outputserie++; $i++;
}
print '];
var dataticks = '.json_encode($data['xlabel']).'
function plotWithOptions() {
$.plot(jQuery("#'.$htmlid.'"), data,
{
series: {
stack: 0
},
zoom: {
interactive: true
},
pan: {
interactive: true
},';
if (count($datacolor))
{
print 'colors: '.json_encode($datacolor).',';
}
print 'legend: {show: '.($showlegend?'true':'false').'},
xaxis: {ticks: dataticks}
});
}
plotWithOptions();
});
</script>';
}
else print 'BadValueForParameterType';
}
}
/**
* Truncate a string to a particular length adding '...' if string larger than length.
* If length = max length+1, we do no truncate to avoid having just 1 char replaced with '...'.
@@ -4222,10 +4054,10 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png',
if ($picto == 'setup') $picto='title_generic.png';
$return.= "\n";
$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 2px;"><tr>';
$return.= '<table '.($id?'id="'.$id.'" ':'').'summary="" class="centpercent notopnoleftnoright'.($morecssontable?' '.$morecssontable:'').'" style="margin-bottom: 6px;"><tr>'; // maring bottom must be same than into print_barre_list
if ($picto) $return.= '<td class="nobordernopadding widthpictotitle opacityhigh" valign="middle">'.img_picto('',$picto, 'class="valignmiddle widthpictotitle pictotitle"', $pictoisfullpath).'</td>';
$return.= '<td class="nobordernopadding" valign="middle">';
$return.= '<div class="titre">'.$titre.'</div>';
$return.= '<td class="nobordernopadding valignmiddle">';
$return.= '<div class="titre inline-block">'.$titre.'</div>';
$return.= '</td>';
if (dol_strlen($morehtmlcenter))
{
@@ -4284,7 +4116,7 @@ function print_barre_liste($titre, $page, $file, $options='', $sortfield='', $so
print "\n";
print "<!-- Begin title '".$titre."' -->\n";
print '<table width="100%" border="0" class="notopnoleftnoright'.($morecss?' '.$morecss:'').'" style="margin-bottom: 6px;"><tr>';
print '<table border="0" class="centpercent notopnoleftnoright'.($morecss?' '.$morecss:'').'" style="margin-bottom: 6px;"><tr>'; // maring bottom must be same than into load_fiche_tire
// Left
//if ($picto && $titre) print '<td class="nobordernopadding hideonsmartphone" width="40" align="left" valign="middle">'.img_picto('', $picto, 'id="pictotitle"', $pictoisfullpath).'</td>';
@@ -5913,7 +5745,7 @@ function dol_textishtml($msg,$option=0)
*
* @param string $text1 Text 1
* @param string $text2 Text 2
* @param bool $forxml false=Use <br>, true=Use <br />
* @param bool $forxml false=Use <br> instead of \n if html content detected, true=Use <br /> instead of \n if html content detected
* @return string Text 1 + new line + Text2
* @see dol_textishtml
*/
@@ -5965,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()
)
);
}
@@ -6952,6 +6784,215 @@ 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',
'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'].