Merge HEAD, branch 'develop' of github.com:Dolibarr/dolibarr into dev_new_project_task_add_contact

This commit is contained in:
Florian HENRY 2020-12-11 17:38:59 +01:00
commit 79b0f08a8d
9 changed files with 265 additions and 212 deletions

View File

@ -33,8 +33,8 @@ $langs->load("admin");
$action = GETPOST('action', 'aZ09'); $action = GETPOST('action', 'aZ09');
$what = GETPOST('what', 'alpha'); $what = GETPOST('what', 'alpha');
$export_type = GETPOST('export_type', 'alpha'); $export_type = GETPOST('export_type', 'alpha');
$file = GETPOST('zipfilename_template', 'alpha'); $file = trim(GETPOST('zipfilename_template', 'alpha'));
$compression = GETPOST('compression'); $compression = GETPOST('compression', 'aZ09');
$file = dol_sanitizeFileName($file); $file = dol_sanitizeFileName($file);
$file = preg_replace('/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2)$/i', '', $file); $file = preg_replace('/(\.zip|\.tar|\.tgz|\.gz|\.tar\.gz|\.bz2)$/i', '', $file);

View File

@ -6,7 +6,7 @@
* Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr> * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
* Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014-2018 Ferran Marcet <fmarcet@2byte.es> * Copyright (C) 2014-2020 Ferran Marcet <fmarcet@2byte.es>
* Copyright (C) 2014-2016 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2014-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr> * Copyright (C) 2018-2020 Frédéric France <frederic.france@netlogic.fr>
@ -2035,7 +2035,7 @@ if ($action == 'create')
// Send // Send
if (empty($user->socid)) { if (empty($user->socid)) {
if ($object->statut == 1) { if ($object->statut == 1) {
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>'; print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
} else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>'; } else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
} }

View File

@ -97,6 +97,8 @@ class box_funnel_of_prospection extends ModeleBoxes
$sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label"; $sql = "SELECT cls.rowid, cls.code, cls.percent, cls.label";
$sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls"; $sql .= " FROM " . MAIN_DB_PREFIX . "c_lead_status as cls";
$sql .= " WHERE active=1"; $sql .= " WHERE active=1";
$sql .= " AND cls.code <> 'LOST'";
$sql .= $this->db->order('cls.rowid', 'ASC');
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if ($resql) {
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
@ -124,7 +126,6 @@ class box_funnel_of_prospection extends ModeleBoxes
$colorseriesstat[$objp->rowid] = $badgeStatus6; $colorseriesstat[$objp->rowid] = $badgeStatus6;
break; break;
default: default:
$colorseriesstat[$objp->rowid] = $badgeStatus2;
break; break;
} }
$i++; $i++;
@ -134,12 +135,11 @@ class box_funnel_of_prospection extends ModeleBoxes
} }
global $conf, $user, $langs; global $conf, $user, $langs;
$this->max = $max; $this->max = $max;
$this->info_box_head = array( $this->info_box_head = array(
'text' => $langs->trans("Statistics") . ' - ' . $langs->trans("OpportunitiesStatusForOpenedProjects"), 'text' => $langs->trans("Statistics") . ' - ' . $langs->trans("OpportunitiesStatusForOpenedProjects"),
$max 'graph' => '1'
); );
if ($user->rights->projet->lire || !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) { if ($user->rights->projet->lire || !empty($conf->global->PROJECT_USE_OPPORTUNITIES)) {
@ -187,6 +187,8 @@ class box_funnel_of_prospection extends ModeleBoxes
$stringtoprint = ''; $stringtoprint = '';
$stringtoprint .= '<div class="div-table-responsive-no-min ">'; $stringtoprint .= '<div class="div-table-responsive-no-min ">';
$listofstatus = array_keys($listofoppstatus); $listofstatus = array_keys($listofoppstatus);
$liststatus = array();
$data = array('');
foreach ($listofstatus as $status) { foreach ($listofstatus as $status) {
$labelStatus = ''; $labelStatus = '';
if ($status != 7) { if ($status != 7) {
@ -198,7 +200,8 @@ class box_funnel_of_prospection extends ModeleBoxes
$labelStatus = $listofopplabel[$status]; $labelStatus = $listofopplabel[$status];
} }
$dataseries[] = array($labelStatus,(isset($valsamount[$status]) ? (float) $valsamount[$status] : 0)); $data[] = (isset($valsamount[$status]) ? (float) $valsamount[$status] : 0);
$liststatus[] = $labelStatus;
if (!$conf->use_javascript_ajax) { if (!$conf->use_javascript_ajax) {
$stringtoprint .= '<tr class="oddeven">'; $stringtoprint .= '<tr class="oddeven">';
$stringtoprint .= '<td>' . $labelStatus . '</td>'; $stringtoprint .= '<td>' . $labelStatus . '</td>';
@ -207,16 +210,21 @@ class box_funnel_of_prospection extends ModeleBoxes
} }
} }
} }
$dataseries[] = $data;
if ($conf->use_javascript_ajax) { if ($conf->use_javascript_ajax) {
include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/dolgraph.class.php';
$dolgraph = new DolGraph(); $dolgraph = new DolGraph();
$dolgraph->SetMinValue(0);
$dolgraph->SetData($dataseries); $dolgraph->SetData($dataseries);
$dolgraph->SetLegend($liststatus);
$dolgraph->SetDataColor(array_values($colorseriesstat)); $dolgraph->SetDataColor(array_values($colorseriesstat));
//$dolgraph->SetLegend(array('PROSP',$dataseries['PROSP']));
$dolgraph->setShowLegend(2); $dolgraph->setShowLegend(2);
$dolgraph->setShowPercent(1); $dolgraph->setShowPercent(1);
$dolgraph->SetType(array('pie')); $dolgraph->setTitle('FunnelOfProspection');
$dolgraph->SetType(array('horizontalbars'));
$dolgraph->SetHeight('200'); $dolgraph->SetHeight('200');
$dolgraph->SetWidth('600');
$dolgraph->mode = 'depth';
$dolgraph->draw('idgraphstatus'); $dolgraph->draw('idgraphstatus');
$stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1); $stringtoprint .= $dolgraph->show($totaloppnb ? 0 : 1);
} }

View File

@ -103,9 +103,8 @@ class DolGraph
$this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220)); $this->datacolor = array(array(120, 130, 150), array(160, 160, 180), array(190, 190, 220));
$this->bgcolor = array(235, 235, 224); $this->bgcolor = array(235, 235, 224);
$color_file = DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; $color_file = DOL_DOCUMENT_ROOT . '/theme/' . $conf->theme . '/theme_vars.inc.php';
if (is_readable($color_file)) if (is_readable($color_file)) {
{
include_once $color_file; include_once $color_file;
if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor; if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor;
if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor; if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor;
@ -261,7 +260,7 @@ class DolGraph
* Set type * Set type
* *
* @param array $type Array with type for each serie. Example: array('type1', 'type2', ...) where type can be: * @param array $type Array with type for each serie. Example: array('type1', 'type2', ...) where type can be:
* 'pie', 'piesemicircle', 'polar', 'lines', 'linesnopoint', 'bars', 'horirontalbars'... * 'pie', 'piesemicircle', 'polar', 'lines', 'linesnopoint', 'bars', 'horizontalbars'...
* @return void * @return void
*/ */
public function SetType($type) public function SetType($type)
@ -466,10 +465,8 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $theme_bgcolor, $theme_bgcoloronglet; global $theme_bgcolor, $theme_bgcoloronglet;
if (!is_array($bg_color)) if (!is_array($bg_color)) {
{ if ($bg_color == 'onglet') {
if ($bg_color == 'onglet')
{
//print 'ee'.join(',',$theme_bgcoloronglet); //print 'ee'.join(',',$theme_bgcoloronglet);
$this->bgcolor = $theme_bgcoloronglet; $this->bgcolor = $theme_bgcoloronglet;
} else { } else {
@ -492,10 +489,8 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $theme_bgcolor, $theme_bgcoloronglet; global $theme_bgcolor, $theme_bgcoloronglet;
if (!is_array($bg_colorgrid)) if (!is_array($bg_colorgrid)) {
{ if ($bg_colorgrid == 'onglet') {
if ($bg_colorgrid == 'onglet')
{
//print 'ee'.join(',',$theme_bgcoloronglet); //print 'ee'.join(',',$theme_bgcoloronglet);
$this->bgcolorgrid = $theme_bgcoloronglet; $this->bgcolorgrid = $theme_bgcoloronglet;
} else { } else {
@ -535,10 +530,8 @@ class DolGraph
$nblines = count($this->data); $nblines = count($this->data);
$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1); $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
for ($j = 0; $j < $nblines; $j++) for ($j = 0; $j < $nblines; $j++) {
{ for ($i = 0; $i < $nbvalues; $i++) {
for ($i = 0; $i < $nbvalues; $i++)
{
$vals[$k] = $this->data[$j][$i + 1]; $vals[$k] = $this->data[$j][$i + 1];
$k++; $k++;
} }
@ -564,10 +557,8 @@ class DolGraph
$nblines = count($this->data); $nblines = count($this->data);
$nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1); $nbvalues = (empty($this->data[0]) ? 0 : count($this->data[0]) - 1);
for ($j = 0; $j < $nblines; $j++) for ($j = 0; $j < $nblines; $j++) {
{ for ($i = 0; $i < $nbvalues; $i++) {
for ($i = 0; $i < $nbvalues; $i++)
{
$vals[$k] = $this->data[$j][$i + 1]; $vals[$k] = $this->data[$j][$i + 1];
$k++; $k++;
} }
@ -589,8 +580,7 @@ class DolGraph
if ($max != 0) $max++; if ($max != 0) $max++;
$size = dol_strlen(abs(ceil($max))); $size = dol_strlen(abs(ceil($max)));
$factor = 1; $factor = 1;
for ($i = 0; $i < ($size - 1); $i++) for ($i = 0; $i < ($size - 1); $i++) {
{
$factor *= 10; $factor *= 10;
} }
@ -615,8 +605,7 @@ class DolGraph
if ($min != 0) $min--; if ($min != 0) $min--;
$size = dol_strlen(abs(floor($min))); $size = dol_strlen(abs(floor($min)));
$factor = 1; $factor = 1;
for ($i = 0; $i < ($size - 1); $i++) for ($i = 0; $i < ($size - 1); $i++) {
{
$factor *= 10; $factor *= 10;
} }
@ -635,24 +624,21 @@ class DolGraph
*/ */
public function draw($file, $fileurl = '') public function draw($file, $fileurl = '')
{ {
if (empty($file)) if (empty($file)) {
{
$this->error = "Call to draw method was made with empty value for parameter file."; $this->error = "Call to draw method was made with empty value for parameter file.";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR);
return -2; return -2;
} }
if (!is_array($this->data)) if (!is_array($this->data)) {
{
$this->error = "Call to draw method was made but SetData was not called or called with an empty dataset for parameters"; $this->error = "Call to draw method was made but SetData was not called or called with an empty dataset for parameters";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_ERR); dol_syslog(get_class($this) . "::draw " . $this->error, LOG_ERR);
return -1; return -1;
} }
if (count($this->data) < 1) if (count($this->data) < 1) {
{
$this->error = "Call to draw method was made but SetData was is an empty dataset"; $this->error = "Call to draw method was made but SetData was is an empty dataset";
dol_syslog(get_class($this)."::draw ".$this->error, LOG_WARNING); dol_syslog(get_class($this) . "::draw " . $this->error, LOG_WARNING);
} }
$call = "draw_".$this->_library; $call = "draw_" . $this->_library;
call_user_func_array(array($this, $call), array($file, $fileurl)); call_user_func_array(array($this, $call), array($file, $fileurl));
} }
@ -678,10 +664,9 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
dol_syslog(get_class($this)."::draw_jflot this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); dol_syslog(get_class($this) . "::draw_jflot this->type=" . join(',', $this->type) . " this->MaxValue=" . $this->MaxValue);
if (empty($this->width) && empty($this->height)) if (empty($this->width) && empty($this->height)) {
{
print 'Error width or height not set'; print 'Error width or height not set';
return; return;
} }
@ -701,7 +686,7 @@ class DolGraph
while ($i < $nblot) // Loop on each serie while ($i < $nblot) // Loop on each serie
{ {
$values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x $values = array(); // Array with horizontal y values (specific values of a serie) for each abscisse x
$serie[$i] = "var d".$i." = [];\n"; $serie[$i] = "var d" . $i . " = [];\n";
// Fill array $values // Fill array $values
$x = 0; $x = 0;
@ -712,14 +697,13 @@ class DolGraph
$x++; $x++;
} }
if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) {
{
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) $serie[$i] .= 'd'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; if (isset($y)) $serie[$i] .= 'd' . $i . '.push({"label":"' . dol_escape_js($legends[$x]) . '", "data":' . $y . '});' . "\n";
} }
} else { } else {
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) $serie[$i] .= 'd'.$i.'.push(['.$x.', '.$y.']);'."\n"; if (isset($y)) $serie[$i] .= 'd' . $i . '.push([' . $x . ', ' . $y . ']);' . "\n";
} }
} }
@ -728,43 +712,39 @@ class DolGraph
} }
$tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.'))));
$this->stringtoshow = '<!-- Build using jflot -->'."\n"; $this->stringtoshow = '<!-- Build using jflot -->' . "\n";
if (!empty($this->title)) $this->stringtoshow .= '<div class="center dolgraphtitle'.(empty($this->cssprefix) ? '' : ' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; if (!empty($this->title)) $this->stringtoshow .= '<div class="center dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>';
if (!empty($this->shownographyet)) if (!empty($this->shownographyet)) {
{ $this->stringtoshow .= '<div style="width:' . $this->width . 'px;height:' . $this->height . 'px;" class="nographyet"></div>';
$this->stringtoshow .= '<div style="width:'.$this->width.'px;height:'.$this->height.'px;" class="nographyet"></div>'; $this->stringtoshow .= '<div class="nographyettext margintoponly">' . $langs->trans("NotEnoughDataYet") . '...</div>';
$this->stringtoshow .= '<div class="nographyettext margintoponly">'.$langs->trans("NotEnoughDataYet").'...</div>';
return; return;
} }
// Start the div that will contains all the graph // Start the div that will contains all the graph
$dolxaxisvertical = ''; $dolxaxisvertical = '';
if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical'; if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical';
$this->stringtoshow .= '<div id="placeholder_'.$tag.'" style="width:'.$this->width.'px;height:'.$this->height.'px;" class="dolgraph'.(empty($dolxaxisvertical) ? '' : ' '.$dolxaxisvertical).(empty($this->cssprefix) ? '' : ' dolgraph'.$this->cssprefix).' center"></div>'."\n"; $this->stringtoshow .= '<div id="placeholder_' . $tag . '" style="width:' . $this->width . 'px;height:' . $this->height . 'px;" class="dolgraph' . (empty($dolxaxisvertical) ? '' : ' ' . $dolxaxisvertical) . (empty($this->cssprefix) ? '' : ' dolgraph' . $this->cssprefix) . ' center"></div>' . "\n";
$this->stringtoshow .= '<script id="'.$tag.'">'."\n"; $this->stringtoshow .= '<script id="' . $tag . '">' . "\n";
$this->stringtoshow .= '$(function () {'."\n"; $this->stringtoshow .= '$(function () {' . "\n";
$i = $firstlot; $i = $firstlot;
if ($nblot < 0) if ($nblot < 0) {
{ $this->stringtoshow .= '<!-- No series of data -->' . "\n";
$this->stringtoshow .= '<!-- No series of data -->'."\n";
} else { } else {
while ($i < $nblot) while ($i < $nblot) {
{ $this->stringtoshow .= '<!-- Serie ' . $i . ' -->' . "\n";
$this->stringtoshow .= '<!-- Serie '.$i.' -->'."\n"; $this->stringtoshow .= $serie[$i] . "\n";
$this->stringtoshow .= $serie[$i]."\n";
$i++; $i++;
} }
} }
$this->stringtoshow .= "\n"; $this->stringtoshow .= "\n";
// Special case for Graph of type 'pie' // Special case for Graph of type 'pie'
if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) if (isset($this->type[$firstlot]) && in_array($this->type[$firstlot], array('pie', 'piesemicircle', 'polar'))) {
{
$datacolor = array(); $datacolor = array();
foreach ($this->datacolor as $val) { foreach ($this->datacolor as $val) {
if (is_array($val)) $datacolor[] = "#".sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]); // If datacolor is array(R, G, B) if (is_array($val)) $datacolor[] = "#" . sprintf("%02x%02x%02x", $val[0], $val[1], $val[2]); // If datacolor is array(R, G, B)
else $datacolor[] = "#".str_replace(array('#', '-'), '', $val); // If $val is '124' or '#124' else $datacolor[] = "#" . str_replace(array('#', '-'), '', $val); // If $val is '124' or '#124'
} }
$urltemp = ''; // TODO Add support for url link into labels $urltemp = ''; // TODO Add support for url link into labels
@ -773,17 +753,17 @@ class DolGraph
$showpercent = $this->showpercent; $showpercent = $this->showpercent;
$this->stringtoshow .= ' $this->stringtoshow .= '
function plotWithOptions_'.$tag.'() { function plotWithOptions_' . $tag . '() {
$.plot($("#placeholder_'.$tag.'"), d0, $.plot($("#placeholder_' . $tag . '"), d0,
{ {
series: { series: {
pie: { pie: {
show: true, show: true,
radius: 0.8, radius: 0.8,
'.($this->combine ? ' ' . ($this->combine ? '
combine: { combine: {
threshold: '.$this->combine.' threshold: ' . $this->combine . '
},' : '').' },' : '') . '
label: { label: {
show: true, show: true,
radius: 0.9, radius: 0.9,
@ -792,7 +772,7 @@ class DolGraph
var number=series.data[0][1]; var number=series.data[0][1];
return \''; return \'';
$this->stringtoshow .= '<span style="font-size:8pt;text-align:center;padding:2px;color:black;">'; $this->stringtoshow .= '<span style="font-size:8pt;text-align:center;padding:2px;color:black;">';
if ($urltemp) $this->stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">'; if ($urltemp) $this->stringtoshow .= '<a style="color: #FFFFFF;" border="0" href="' . $urltemp . '">';
$this->stringtoshow .= '\'+'; $this->stringtoshow .= '\'+';
$this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend $this->stringtoshow .= ($showlegend ? '' : 'label+\' \'+'); // Hide label if already shown in legend
$this->stringtoshow .= ($showpointvalue ? 'number+' : ''); $this->stringtoshow .= ($showpointvalue ? 'number+' : '');
@ -814,21 +794,20 @@ class DolGraph
pan: { pan: {
interactive: true interactive: true
},'; },';
if (count($datacolor)) if (count($datacolor)) {
{ $this->stringtoshow .= 'colors: ' . (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)) . ',';
$this->stringtoshow .= 'colors: '.(!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)).',';
} }
$this->stringtoshow .= 'legend: {show: '.($showlegend ? 'true' : 'false').', position: \'ne\' } $this->stringtoshow .= 'legend: {show: ' . ($showlegend ? 'true' : 'false') . ', position: \'ne\' }
}); });
}'."\n"; }' . "\n";
} }
// Other cases, graph of type 'bars', 'lines' // Other cases, graph of type 'bars', 'lines'
else { else {
// Add code to support tooltips // Add code to support tooltips
// TODO: remove js css and use graph-tooltip-inner class instead by adding css in each themes // TODO: remove js css and use graph-tooltip-inner class instead by adding css in each themes
$this->stringtoshow .= ' $this->stringtoshow .= '
function showTooltip_'.$tag.'(x, y, contents) { function showTooltip_' . $tag . '(x, y, contents) {
$(\'<div class="graph-tooltip-inner" id="tooltip_'.$tag.'">\' + contents + \'</div>\').css({ $(\'<div class="graph-tooltip-inner" id="tooltip_' . $tag . '">\' + contents + \'</div>\').css({
position: \'absolute\', position: \'absolute\',
display: \'none\', display: \'none\',
top: y + 10, top: y + 10,
@ -844,7 +823,7 @@ class DolGraph
} }
var previousPoint = null; var previousPoint = null;
$("#placeholder_'.$tag.'").bind("plothover", function (event, pos, item) { $("#placeholder_' . $tag . '").bind("plothover", function (event, pos, item) {
$("#x").text(pos.x.toFixed(2)); $("#x").text(pos.x.toFixed(2));
$("#y").text(pos.y.toFixed(2)); $("#y").text(pos.y.toFixed(2));
@ -859,26 +838,25 @@ class DolGraph
var z = item.series.xaxis.ticks[item.dataIndex].label; var z = item.series.xaxis.ticks[item.dataIndex].label;
'; ';
if ($this->showpointvalue > 0) $this->stringtoshow .= ' if ($this->showpointvalue > 0) $this->stringtoshow .= '
showTooltip_'.$tag.'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y); showTooltip_' . $tag . '(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y);
'; ';
$this->stringtoshow .= ' $this->stringtoshow .= '
} }
} }
else { else {
$("#tooltip_'.$tag.'").remove(); $("#tooltip_' . $tag . '").remove();
previousPoint = null; previousPoint = null;
} }
}); });
'; ';
$this->stringtoshow .= 'var stack = null, steps = false;'."\n"; $this->stringtoshow .= 'var stack = null, steps = false;' . "\n";
$this->stringtoshow .= 'function plotWithOptions_'.$tag.'() {'."\n"; $this->stringtoshow .= 'function plotWithOptions_' . $tag . '() {' . "\n";
$this->stringtoshow .= '$.plot($("#placeholder_'.$tag.'"), [ '."\n"; $this->stringtoshow .= '$.plot($("#placeholder_' . $tag . '"), [ ' . "\n";
$i = $firstlot; $i = $firstlot;
while ($i < $nblot) while ($i < $nblot) {
{ if ($i > $firstlot) $this->stringtoshow .= ', ' . "\n";
if ($i > $firstlot) $this->stringtoshow .= ', '."\n";
$color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]); $color = sprintf("%02x%02x%02x", $this->datacolor[$i][0], $this->datacolor[$i][1], $this->datacolor[$i][2]);
$this->stringtoshow .= '{ '; $this->stringtoshow .= '{ ';
if (!isset($this->type[$i]) || $this->type[$i] == 'bars') { if (!isset($this->type[$i]) || $this->type[$i] == 'bars') {
@ -886,42 +864,41 @@ class DolGraph
if ($i == $firstlot) $align = 'right'; if ($i == $firstlot) $align = 'right';
elseif ($i == $firstlot + 1) $align = 'center'; elseif ($i == $firstlot + 1) $align = 'center';
else $align = 'left'; else $align = 'left';
$this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "'.$align.'", barWidth: 0.45 }, '; $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "' . $align . '", barWidth: 0.45 }, ';
} else $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "'.($i == $firstlot ? 'center' : 'left').'", barWidth: 0.5 }, '; } else $this->stringtoshow .= 'bars: { lineWidth: 1, show: true, align: "' . ($i == $firstlot ? 'center' : 'left') . '", barWidth: 0.5 }, ';
} }
if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow .= 'lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, '; if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow .= 'lines: { show: true, fill: false }, points: { show: ' . ($this->type[$i] == 'linesnopoint' ? 'false' : 'true') . ' }, ';
$this->stringtoshow .= 'color: "#'.$color.'", label: "'.(isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '').'", data: d'.$i.' }'; $this->stringtoshow .= 'color: "#' . $color . '", label: "' . (isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '') . '", data: d' . $i . ' }';
$i++; $i++;
} }
// shadowSize: 0 -> Drawing is faster without shadows // shadowSize: 0 -> Drawing is faster without shadows
$this->stringtoshow .= "\n".' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6, fillColor: { colors: [{opacity: 0.9 }, {opacity: 0.85}] }} }'."\n"; $this->stringtoshow .= "\n" . ' ], { series: { shadowSize: 0, stack: stack, lines: { fill: false, steps: steps }, bars: { barWidth: 0.6, fillColor: { colors: [{opacity: 0.9 }, {opacity: 0.85}] }} }' . "\n";
// Xaxis // Xaxis
$this->stringtoshow .= ', xaxis: { ticks: ['."\n"; $this->stringtoshow .= ', xaxis: { ticks: [' . "\n";
$x = 0; $x = 0;
foreach ($this->data as $key => $valarray) foreach ($this->data as $key => $valarray) {
{ if ($x > 0) $this->stringtoshow .= ', ' . "\n";
if ($x > 0) $this->stringtoshow .= ', '."\n"; $this->stringtoshow .= ' [' . $x . ', "' . $valarray[0] . '"]';
$this->stringtoshow .= ' ['.$x.', "'.$valarray[0].'"]';
$x++; $x++;
} }
$this->stringtoshow .= '] }'."\n"; $this->stringtoshow .= '] }' . "\n";
// Yaxis // Yaxis
$this->stringtoshow .= ', yaxis: { min: '.$this->MinValue.', max: '.($this->MaxValue).' }'."\n"; $this->stringtoshow .= ', yaxis: { min: ' . $this->MinValue . ', max: ' . ($this->MaxValue) . ' }' . "\n";
// Background color // Background color
$color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]); $color1 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[0], $this->bgcolorgrid[2]);
$color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]); $color2 = sprintf("%02x%02x%02x", $this->bgcolorgrid[0], $this->bgcolorgrid[1], $this->bgcolorgrid[2]);
$this->stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#'.$color1.'", "#'.$color2.'"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }'."\n"; $this->stringtoshow .= ', grid: { hoverable: true, backgroundColor: { colors: ["#' . $color1 . '", "#' . $color2 . '"] }, borderWidth: 1, borderColor: \'#e6e6e6\', tickColor : \'#e6e6e6\' }' . "\n";
//$this->stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this //$this->stringtoshow.=', shadowSize: 20'."\n"; TODO Uncommet this
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
} }
$this->stringtoshow .= 'plotWithOptions_'.$tag.'();'."\n"; $this->stringtoshow .= 'plotWithOptions_' . $tag . '();' . "\n";
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
$this->stringtoshow .= '</script>'."\n"; $this->stringtoshow .= '</script>' . "\n";
} }
@ -947,10 +924,9 @@ class DolGraph
// phpcs:enable // phpcs:enable
global $conf, $langs; global $conf, $langs;
dol_syslog(get_class($this)."::draw_chart this->type=".join(',', $this->type)." this->MaxValue=".$this->MaxValue); dol_syslog(get_class($this) . "::draw_chart this->type=" . join(',', $this->type) . " this->MaxValue=" . $this->MaxValue);
if (empty($this->width) && empty($this->height)) if (empty($this->width) && empty($this->height)) {
{
print 'Error width or height not set'; print 'Error width or height not set';
return; return;
} }
@ -971,7 +947,8 @@ class DolGraph
// Works with line but not with bars // Works with line but not with bars
//if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x
$serie = array(); $arrayofgroupslegend = array(); $serie = array();
$arrayofgroupslegend = array();
//var_dump($this->data); //var_dump($this->data);
$i = $firstlot; $i = $firstlot;
@ -989,15 +966,15 @@ class DolGraph
$alabelexists = 1; $alabelexists = 1;
$tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3); $tmpykey = explode('_', ($array_of_ykeys[$i + ($alabelexists ? 1 : 0)]), 3);
if (!empty($tmpykey[2]) || $tmpykey[2] == '0') { // This is a 'Group by' array if (!empty($tmpykey[2]) || $tmpykey[2] == '0') { // This is a 'Group by' array
$tmpvalue = (array_key_exists('y_'.$tmpykey[1].'_'.$tmpykey[2], $valarray) ? $valarray['y_'.$tmpykey[1].'_'.$tmpykey[2]] : $valarray[$i + 1]); $tmpvalue = (array_key_exists('y_' . $tmpykey[1] . '_' . $tmpykey[2], $valarray) ? $valarray['y_' . $tmpykey[1] . '_' . $tmpykey[2]] : $valarray[$i + 1]);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
$arrayofgroupslegend[$i] = array( $arrayofgroupslegend[$i] = array(
'stacknum'=> $tmpykey[1], 'stacknum' => $tmpykey[1],
'legend' => $this->Legend[$tmpykey[1]], 'legend' => $this->Legend[$tmpykey[1]],
'legendwithgroup' => $this->Legend[$tmpykey[1]].' - '.$tmpykey[2] 'legendwithgroup' => $this->Legend[$tmpykey[1]] . ' - ' . $tmpykey[2]
); );
} else { } else {
$tmpvalue = (array_key_exists('y_'.$i, $valarray) ? $valarray['y_'.$i] : $valarray[$i + 1]); $tmpvalue = (array_key_exists('y_' . $i, $valarray) ? $valarray['y_' . $i] : $valarray[$i + 1]);
//var_dump($i.'_'.$x.'_'.$tmpvalue); //var_dump($i.'_'.$x.'_'.$tmpvalue);
$values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null); $values[$x] = (is_numeric($tmpvalue) ? $tmpvalue : null);
} }
@ -1007,9 +984,9 @@ class DolGraph
$j = 0; $j = 0;
foreach ($values as $x => $y) { foreach ($values as $x => $y) {
if (isset($y)) { if (isset($y)) {
$serie[$i] .= ($j > 0 ? ", " : "").$y; $serie[$i] .= ($j > 0 ? ", " : "") . $y;
} else { } else {
$serie[$i] .= ($j > 0 ? ", " : "").'null'; $serie[$i] .= ($j > 0 ? ", " : "") . 'null';
} }
$j++; $j++;
} }
@ -1022,12 +999,11 @@ class DolGraph
$tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.')))); $tag = dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file), '_', array('-', '.'))));
$this->stringtoshow = '<!-- Build using chart -->'."\n"; $this->stringtoshow = '<!-- Build using chart -->' . "\n";
if (!empty($this->title)) $this->stringtoshow .= '<div class="center dolgraphtitle'.(empty($this->cssprefix) ? '' : ' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; if (!empty($this->title)&&$this->title!='FunnelOfProspection') $this->stringtoshow .= '<div class="center dolgraphtitle' . (empty($this->cssprefix) ? '' : ' dolgraphtitle' . $this->cssprefix) . '">' . $this->title . '</div>';
if (!empty($this->shownographyet)) if (!empty($this->shownographyet)) {
{ $this->stringtoshow .= '<div style="width:' . $this->width . (strpos($this->width, '%') > 0 ? '' : 'px') . '; height:' . $this->height . 'px;" class="nographyet"></div>';
$this->stringtoshow .= '<div style="width:'.$this->width.(strpos($this->width, '%') > 0 ? '' : 'px').'; height:'.$this->height.'px;" class="nographyet"></div>'; $this->stringtoshow .= '<div class="nographyettext margintoponly">' . $langs->trans("NotEnoughDataYet") . '...</div>';
$this->stringtoshow .= '<div class="nographyettext margintoponly">'.$langs->trans("NotEnoughDataYet").'...</div>';
return; return;
} }
@ -1036,17 +1012,15 @@ class DolGraph
if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical'; if (count($this->data) > 20) $dolxaxisvertical = 'dol-xaxis-vertical';
// No height for the pie grah // No height for the pie grah
$cssfordiv = 'dolgraphchart'; $cssfordiv = 'dolgraphchart';
if (isset($this->type[$firstlot])) $cssfordiv .= ' dolgraphchar'.$this->type[$firstlot]; if (isset($this->type[$firstlot])) $cssfordiv .= ' dolgraphchar' . $this->type[$firstlot];
$this->stringtoshow .= '<div id="placeholder_'.$tag.'" style="min-height: '.$this->height.(strpos($this->height, '%') > 0 ? '' : 'px').'; width:'.$this->width.(strpos($this->width, '%') > 0 ? '' : 'px').';" class="'.$cssfordiv.' dolgraph'.(empty($dolxaxisvertical) ? '' : ' '.$dolxaxisvertical).(empty($this->cssprefix) ? '' : ' dolgraph'.$this->cssprefix).' center"><canvas id="canvas_'.$tag.'"></canvas></div>'."\n"; $this->stringtoshow .= '<div id="placeholder_' . $tag . '" style="min-height: ' . $this->height . (strpos($this->height, '%') > 0 ? '' : 'px') . '; width:' . $this->width . (strpos($this->width, '%') > 0 ? '' : 'px') . ';" class="' . $cssfordiv . ' dolgraph' . (empty($dolxaxisvertical) ? '' : ' ' . $dolxaxisvertical) . (empty($this->cssprefix) ? '' : ' dolgraph' . $this->cssprefix) . ' center"><canvas id="canvas_' . $tag . '"></canvas></div>' . "\n";
$this->stringtoshow .= '<script id="'.$tag.'">'."\n"; $this->stringtoshow .= '<script id="' . $tag . '">' . "\n";
$i = $firstlot; $i = $firstlot;
if ($nblot < 0) if ($nblot < 0) {
{
$this->stringtoshow .= '<!-- No series of data -->'; $this->stringtoshow .= '<!-- No series of data -->';
} else { } else {
while ($i < $nblot) while ($i < $nblot) {
{
//$this->stringtoshow .= '<!-- Series '.$i.' -->'."\n"; //$this->stringtoshow .= '<!-- Series '.$i.' -->'."\n";
//$this->stringtoshow .= $serie[$i]."\n"; //$this->stringtoshow .= $serie[$i]."\n";
$i++; $i++;
@ -1055,69 +1029,69 @@ class DolGraph
$this->stringtoshow .= "\n"; $this->stringtoshow .= "\n";
// Special case for Graph of type 'pie', 'piesemicircle', or 'polar' // Special case for Graph of type 'pie', 'piesemicircle', or 'polar'
if (isset($this->type[$firstlot]) && (in_array($this->type[$firstlot], array('pie', 'polar', 'piesemicircle')))) if (isset($this->type[$firstlot]) && (in_array($this->type[$firstlot], array('pie', 'polar', 'piesemicircle')))) {
{
$type = $this->type[$firstlot]; // pie or polar $type = $this->type[$firstlot]; // pie or polar
$this->stringtoshow .= 'var options = {'."\n"; $this->stringtoshow .= 'var options = {' . "\n";
$legendMaxLines = 0; // Does not work $legendMaxLines = 0; // Does not work
if (empty($showlegend)) { if (empty($showlegend)) {
$this->stringtoshow .= 'legend: { display: false }, '; $this->stringtoshow .= 'legend: { display: false }, ';
} else { } else {
$this->stringtoshow .= 'legend: { position: \''.($showlegend == 2 ? 'right' : 'top').'\''; $this->stringtoshow .= 'legend: { position: \'' . ($showlegend == 2 ? 'right' : 'top') . '\'';
if (!empty($legendMaxLines)) { if (!empty($legendMaxLines)) {
$this->stringtoshow .= ', maxLines: '.$legendMaxLines.''; $this->stringtoshow .= ', maxLines: ' . $legendMaxLines . '';
} }
$this->stringtoshow .= ' }, '."\n"; $this->stringtoshow .= ' }, ' . "\n";
} }
if ($this->type[$firstlot] == 'piesemicircle') { if ($this->type[$firstlot] == 'piesemicircle') {
$this->stringtoshow .= 'circumference: Math.PI,'."\n"; $this->stringtoshow .= 'circumference: Math.PI,' . "\n";
$this->stringtoshow .= 'rotation: -Math.PI,'."\n"; $this->stringtoshow .= 'rotation: -Math.PI,' . "\n";
} }
$this->stringtoshow .= 'elements: { arc: {'."\n"; $this->stringtoshow .= 'elements: { arc: {' . "\n";
// Color of earch arc // Color of earch arc
$this->stringtoshow .= 'backgroundColor: ['; $this->stringtoshow .= 'backgroundColor: [';
$i = 0; $foundnegativecolor = 0; $i = 0;
$foundnegativecolor = 0;
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '."\n"; if ($i > 0) $this->stringtoshow .= ', ' . "\n";
if (is_array($this->datacolor[$i])) $color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].')'; // If datacolor is array(R, G, B) if (is_array($this->datacolor[$i])) $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')'; // If datacolor is array(R, G, B)
else { else {
$tmp = str_replace('#', '', $this->datacolor[$i]); $tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) { if (strpos($tmp, '-') !== false) {
$foundnegativecolor++; $foundnegativecolor++;
$color = '#FFFFFF'; // If $val is '-123' $color = '#FFFFFF'; // If $val is '-123'
} else $color = "#".$tmp; // If $val is '123' or '#123' } else $color = "#" . $tmp; // If $val is '123' or '#123'
} }
$this->stringtoshow .= "'".$color."'"; $this->stringtoshow .= "'" . $color . "'";
$i++; $i++;
} }
$this->stringtoshow .= '], '."\n"; $this->stringtoshow .= '], ' . "\n";
// Border color // Border color
if ($foundnegativecolor) { if ($foundnegativecolor) {
$this->stringtoshow .= 'borderColor: ['; $this->stringtoshow .= 'borderColor: [';
$i = 0; $i = 0;
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '."\n"; if ($i > 0) $this->stringtoshow .= ', ' . "\n";
if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B) if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B)
else { else {
$tmp = str_replace('#', '', $this->datacolor[$i]); $tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) $color = '#'.str_replace('-', '', $tmp); // If $val is '-123' if (strpos($tmp, '-') !== false) $color = '#' . str_replace('-', '', $tmp); // If $val is '-123'
else $color = 'null'; // If $val is '123' or '#123' else $color = 'null'; // If $val is '123' or '#123'
} }
$this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'".$color."'"); $this->stringtoshow .= ($color == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $color . "'");
$i++; $i++;
} }
$this->stringtoshow .= ']'; $this->stringtoshow .= ']';
} }
$this->stringtoshow .= '} } };'."\n"; $this->stringtoshow .= '} } };' . "\n";
$this->stringtoshow .= ' $this->stringtoshow .= '
var ctx = document.getElementById("canvas_'.$tag.'").getContext("2d"); var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d");
var chart = new Chart(ctx, { var chart = new Chart(ctx, {
// The type of chart we want to create // The type of chart we want to create
type: \''.(in_array($type, array('pie', 'piesemicircle')) ? 'doughnut' : 'polarArea').'\', type: \'' . (in_array($type, array('pie', 'piesemicircle')) ? 'doughnut' : 'polarArea') . '\',
// Configuration options go here // Configuration options go here
options: options, options: options,
data: { data: {
@ -1127,7 +1101,7 @@ class DolGraph
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '; if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; $this->stringtoshow .= "'" . dol_escape_js(dol_trunc($val, 32)) . "'";
$i++; $i++;
} }
@ -1137,26 +1111,28 @@ class DolGraph
$i = 0; $i = 0;
while ($i < $nblot) // Loop on each serie while ($i < $nblot) // Loop on each serie
{ {
$color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].')'; $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')';
//$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)); //$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor));
if ($i > 0) $this->stringtoshow .= ', '."\n"; if ($i > 0) $this->stringtoshow .= ', ' . "\n";
$this->stringtoshow .= '{'."\n"; $this->stringtoshow .= '{' . "\n";
//$this->stringtoshow .= 'borderColor: \''.$color.'\', '; //$this->stringtoshow .= 'borderColor: \''.$color.'\', ';
//$this->stringtoshow .= 'backgroundColor: \''.$color.'\', '; //$this->stringtoshow .= 'backgroundColor: \''.$color.'\', ';
$this->stringtoshow .= ' data: ['.$serie[$i].']'; $this->stringtoshow .= ' data: [' . $serie[$i] . ']';
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
$i++; $i++;
} }
$this->stringtoshow .= ']'."\n"; $this->stringtoshow .= ']' . "\n";
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
} }
// Other cases, graph of type 'bars', 'lines', 'linesnopoint' // Other cases, graph of type 'bars', 'lines', 'linesnopoint'
else { else {
$type = 'bar'; $type = 'bar';
$isfunnel = false;
if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars') $type = 'bar'; if (!isset($this->type[$firstlot]) || $this->type[$firstlot] == 'bars') $type = 'bar';
if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars') $type = 'horizontalBar'; if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'horizontalbars') $type = 'horizontalBar';
if ($this->title == 'FunnelOfProspection') $isfunnel = true;
if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines' || $this->type[$firstlot] == 'linesnopoint')) $type = 'line'; if (isset($this->type[$firstlot]) && ($this->type[$firstlot] == 'lines' || $this->type[$firstlot] == 'linesnopoint')) $type = 'line';
$this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, '; $this->stringtoshow .= 'var options = { maintainAspectRatio: false, aspectRatio: 2.5, ';
@ -1164,6 +1140,9 @@ class DolGraph
$this->stringtoshow .= 'legend: { display: false }, '; $this->stringtoshow .= 'legend: { display: false }, ';
} }
$this->stringtoshow .= 'scales: { xAxes: [{ '; $this->stringtoshow .= 'scales: { xAxes: [{ ';
if ($isfunnel) {
$this->stringtoshow .= ' ticks: { beginAtZero: true}, display: false,';
}
//$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js //$this->stringtoshow .= 'type: \'time\', '; // Need Moment.js
$this->stringtoshow .= 'distribution: \'linear\''; $this->stringtoshow .= 'distribution: \'linear\'';
if ($type == 'bar' && count($arrayofgroupslegend) > 0) { if ($type == 'bar' && count($arrayofgroupslegend) > 0) {
@ -1174,25 +1153,38 @@ class DolGraph
$this->stringtoshow .= ', yAxes: [{ stacked: true }]'; $this->stringtoshow .= ', yAxes: [{ stacked: true }]';
} }
$this->stringtoshow .= ' }'; $this->stringtoshow .= ' }';
if ($isfunnel) {
$this->stringtoshow .= ', tooltips: {mode: \'nearest\',
callbacks: {
title: function(tooltipItem, data) {
return data.datasets[tooltipItem[0].datasetIndex].label;
},
label: function(tooltipItem, data) {
return data.datasets[tooltipItem.datasetIndex].data[0][1];
}
}
},';
}
$this->stringtoshow .= '};'; $this->stringtoshow .= '};';
$this->stringtoshow .= ' $this->stringtoshow .= '
var ctx = document.getElementById("canvas_'.$tag.'").getContext("2d"); var ctx = document.getElementById("canvas_' . $tag . '").getContext("2d");
var chart = new Chart(ctx, { var chart = new Chart(ctx, {
// The type of chart we want to create // The type of chart we want to create
type: \''.$type.'\', type: \'' . $type . '\',
// Configuration options go here // Configuration options go here
options: options, options: options,
data: { data: {
labels: ['; labels: [';
$i = 0; $i = 0;
if (!$isfunnel);{
foreach ($legends as $val) // Loop on each serie foreach ($legends as $val) // Loop on each serie
{ {
if ($i > 0) $this->stringtoshow .= ', '; if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'"; $this->stringtoshow .= "'".dol_escape_js(dol_trunc($val, 32))."'";
$i++; $i++;
} }
}
//var_dump($arrayofgroupslegend); //var_dump($arrayofgroupslegend);
@ -1205,6 +1197,7 @@ class DolGraph
$oldstacknum = -1; $oldstacknum = -1;
while ($i < $nblot) // Loop on each serie while ($i < $nblot) // Loop on each serie
{ {
$foundnegativecolor = 0;
$usecolorvariantforgroupby = 0; $usecolorvariantforgroupby = 0;
// We used a 'group by' and we have too many colors so we generated color variants per // We used a 'group by' and we have too many colors so we generated color variants per
if (is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by. if (is_array($arrayofgroupslegend[$i]) && count($arrayofgroupslegend[$i]) > 0) { // If we used a group by.
@ -1233,7 +1226,7 @@ class DolGraph
$ratio = min(95, 10 + 10 * $iinstack); // step of 20 $ratio = min(95, 10 + 10 * $iinstack); // step of 20
$brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10 $brightnessratio = min(90, 5 + 5 * $iinstack); // step of 10
} else { // We decrease agressiveness of reference color for color 3, 5, 7, .. } else { // We decrease agressiveness of reference color for color 3, 5, 7, ..
$ratio = max(-100, - 15 * $iinstack + 10); // step of -20 $ratio = max(-100, -15 * $iinstack + 10); // step of -20
$brightnessratio = min(90, 10 * $iinstack); // step of 20 $brightnessratio = min(90, 10 * $iinstack); // step of 20
} }
//var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio); //var_dump('Color '.($iinstack+1).' : '.$ratio.' '.$brightnessratio);
@ -1242,37 +1235,65 @@ class DolGraph
} }
$oldstacknum = $arrayofgroupslegend[$i]['stacknum']; $oldstacknum = $arrayofgroupslegend[$i]['stacknum'];
$color = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].', 0.9)'; $color = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ', 0.9)';
$bordercolor = 'rgb('.$newcolor[0].', '.$newcolor[1].', '.$newcolor[2].')'; $bordercolor = 'rgb(' . $newcolor[0] . ', ' . $newcolor[1] . ', ' . $newcolor[2] . ')';
} else { // We do not use a 'group by' } else { // We do not use a 'group by'
$color = 'rgb('.$this->datacolor[$i][0].', '.$this->datacolor[$i][1].', '.$this->datacolor[$i][2].', 0.9)'; if (is_array($this->datacolor[$i])) $color = 'rgb(' . $this->datacolor[$i][0] . ', ' . $this->datacolor[$i][1] . ', ' . $this->datacolor[$i][2] . ')'; // If datacolor is array(R, G, B)
else {
$tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) {
$foundnegativecolor++;
$color = '#FFFFFF'; // If $val is '-123'
} else {
$color = "#" . $tmp; // If $val is '123' or '#123'
$bordercolor = $color; $bordercolor = $color;
//$color = (!empty($data['seriescolor']) ? json_encode($data['seriescolor']) : json_encode($datacolor)); }
if ($foundnegativecolor) {
if (is_array($this->datacolor[$i])) $color = 'null'; // If datacolor is array(R, G, B)
else {
$tmp = str_replace('#', '', $this->datacolor[$i]);
if (strpos($tmp, '-') !== false) $bordercolor = '#' . str_replace('-', '', $tmp); // If $val is '-123'
else $bordercolor = 'null'; // If $val is '123' or '#123'
}
$bordercolor == 'null' ? "'rgba(0,0,0,0.2)'" : "'" . $bordercolor . "'";
}
}
} }
if ($i > 0) $this->stringtoshow .= ', '; if ($i > 0) $this->stringtoshow .= ', ';
$this->stringtoshow .= "\n"; $this->stringtoshow .= "\n";
$this->stringtoshow .= '{'; $this->stringtoshow .= '{';
$this->stringtoshow .= 'dolibarrinfo: \'y_'.$i.'\', '; $this->stringtoshow .= 'dolibarrinfo: \'y_' . $i . '\', ';
$this->stringtoshow .= 'label: \''.dol_escape_js(dol_string_nohtmltag($textoflegend)).'\', '; $this->stringtoshow .= 'label: \'' . dol_escape_js(dol_string_nohtmltag($textoflegend)) . '\', ';
$this->stringtoshow .= 'pointStyle: \''.($this->type[$i] == 'linesnopoint' ? 'line' : 'circle').'\', '; $this->stringtoshow .= 'pointStyle: \'' . ($this->type[$i] == 'linesnopoint' ? 'line' : 'circle') . '\', ';
$this->stringtoshow .= 'fill: '.($type == 'bar' ? 'true' : 'false').', '; $this->stringtoshow .= 'fill: ' . ($type == 'bar' ? 'true' : 'false') . ', ';
if ($type == 'bar') { $this->stringtoshow .= 'borderWidth: \'1\', '; } if ($isfunnel){
$this->stringtoshow .= 'borderColor: \''.$bordercolor.'\', '; $this->stringtoshow .= 'borderWidth: \'2\', ';
$this->stringtoshow .= 'backgroundColor: \''.$color.'\', '; }
if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \''.$arrayofgroupslegend[$i]['stacknum'].'\', '; elseif ($type == 'bar' || $type == 'horizontalBar') {
$this->stringtoshow .= 'data: ['.$serie[$i].']'; $this->stringtoshow .= 'borderWidth: \'1\', ';
$this->stringtoshow .= '}'."\n"; }
$this->stringtoshow .= 'borderColor: \'' . $bordercolor . '\', ';
$this->stringtoshow .= 'backgroundColor: \'' . $color . '\', ';
if ($arrayofgroupslegend[$i]) $this->stringtoshow .= 'stack: \'' . $arrayofgroupslegend[$i]['stacknum'] . '\', ';
$this->stringtoshow .='data: [';
if ($isfunnel){
$this->stringtoshow .= '['.-$serie[$i].','.$serie[$i].']';
}else {
$this->stringtoshow .= $serie[$i];
}
$this->stringtoshow .=']';
$this->stringtoshow .= '}' . "\n";
$i++; $i++;
$iinstack++; $iinstack++;
} }
$this->stringtoshow .= ']'."\n"; $this->stringtoshow .= ']' . "\n";
$this->stringtoshow .= '}'."\n"; $this->stringtoshow .= '}' . "\n";
$this->stringtoshow .= '});'."\n"; $this->stringtoshow .= '});' . "\n";
} }
$this->stringtoshow .= '</script>'."\n"; $this->stringtoshow .= '</script>' . "\n";
} }
@ -1301,14 +1322,13 @@ class DolGraph
{ {
global $langs; global $langs;
if ($shownographyet) if ($shownographyet) {
{ $s = '<div class="nographyet" style="width:' . (preg_match('/%/', $this->width) ? $this->width : $this->width . 'px') . '; height:' . (preg_match('/%/', $this->height) ? $this->height : $this->height . 'px') . ';"></div>';
$s = '<div class="nographyet" style="width:'.(preg_match('/%/', $this->width) ? $this->width : $this->width.'px').'; height:'.(preg_match('/%/', $this->height) ? $this->height : $this->height.'px').';"></div>';
$s .= '<div class="nographyettext margintoponly">'; $s .= '<div class="nographyettext margintoponly">';
if (is_numeric($shownographyet)) { if (is_numeric($shownographyet)) {
$s .= $langs->trans("NotEnoughDataYet").'...'; $s .= $langs->trans("NotEnoughDataYet") . '...';
} else { } else {
$s .= $shownographyet.'...'; $s .= $shownographyet . '...';
} }
$s .= '</div>'; $s .= '</div>';
return $s; return $s;

View File

@ -1995,7 +1995,7 @@ class Form
if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) { if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
$urloption .= '&socid='.$socid; $urloption .= '&socid='.$socid;
} }
$out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 1, $ajaxoptions);
if (!empty($conf->variants->enabled)) { if (!empty($conf->variants->enabled)) {
$out .= ' $out .= '
@ -6197,6 +6197,7 @@ class Form
$tmpfieldstoshow = ''; $tmpfieldstoshow = '';
foreach ($objecttmp->fields as $key => $val) foreach ($objecttmp->fields as $key => $val)
{ {
if (!dol_eval($val['enabled'], 1, 1)) continue;
if ($val['showoncombobox']) $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '').'t.'.$key; if ($val['showoncombobox']) $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '').'t.'.$key;
} }
if ($tmpfieldstoshow) $fieldstoshow = $tmpfieldstoshow; if ($tmpfieldstoshow) $fieldstoshow = $tmpfieldstoshow;
@ -6294,8 +6295,7 @@ class Form
} }
if (empty($outputmode)) if (empty($outputmode))
{ {
if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
{
$out .= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>'; $out .= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>';
} else { } else {
$out .= '<option value="'.$obj->rowid.'">'.$label.'</option>'; $out .= '<option value="'.$obj->rowid.'">'.$label.'</option>';

View File

@ -34,7 +34,7 @@
* @param string $url Ajax Url to call for request: /path/page.php. Must return a json array ('key'=>id, 'value'=>String shown into input field once selected, 'label'=>String shown into combo list) * @param string $url Ajax Url to call for request: /path/page.php. Must return a json array ('key'=>id, 'value'=>String shown into input field once selected, 'label'=>String shown into combo list)
* @param string $urloption More parameters on URL request * @param string $urloption More parameters on URL request
* @param int $minLength Minimum number of chars to trigger that Ajax search * @param int $minLength Minimum number of chars to trigger that Ajax search
* @param int $autoselect Automatic selection if just one value * @param int $autoselect Automatic selection if just one value (trigger("change") on field is done is search return only 1 result)
* @param array $ajaxoptions Multiple options array * @param array $ajaxoptions Multiple options array
* - Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done * - Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done
* - Ex: array('disabled'=> ) * - Ex: array('disabled'=> )

View File

@ -931,8 +931,9 @@ function dol_sanitizeFileName($str, $newstr = '_', $unaccent = 1)
// List of special chars for filenames in windows are defined on page https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file // List of special chars for filenames in windows are defined on page https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
// Char '>' '<' '|' '$' and ';' are special chars for shells. // Char '>' '<' '|' '$' and ';' are special chars for shells.
// Char '/' and '\' are file delimiters. // Char '/' and '\' are file delimiters.
$filesystem_forbidden_chars = array('<', '>', '/', '\\', '?', '*', '|', '"', ':', '°', '$', ';'); // -- car can be used into filename to inject special paramaters like --use-compress-program to make command with file as parameter making remote execution of command
return dol_string_nospecial($unaccent ?dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars); $filesystem_forbidden_chars = array('<', '>', '/', '\\', '?', '*', '|', '"', ':', '°', '$', ';', '--');
return dol_string_nospecial($unaccent ? dol_string_unaccent($str) : $str, $newstr, $filesystem_forbidden_chars);
} }
/** /**

View File

@ -413,6 +413,7 @@ class Product extends CommonObject
public $fields = array( public $fields = array(
'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'), 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'), 'ref' =>array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
'barcode' =>array('type'=>'varchar(255)', 'label'=>'Barcode', 'enabled'=>'!empty($conf->barcode->enabled)', 'visible'=>-1, 'showoncombobox'=>1),
'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20), 'entity' =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1), 'label' =>array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1),
'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61), 'note_public' =>array('type'=>'html', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>61),

View File

@ -376,7 +376,7 @@ class SecurityTest extends PHPUnit\Framework\TestCase
$login=checkLoginPassEntity('admin', 'admin', 1, array('dolibarr')); // Should works because admin/admin exists $login=checkLoginPassEntity('admin', 'admin', 1, array('dolibarr')); // Should works because admin/admin exists
print __METHOD__." login=".$login."\n"; print __METHOD__." login=".$login."\n";
$this->assertEquals($login, 'admin'); $this->assertEquals($login, 'admin', 'The test to check if pass of user "admin" is "admin" has failed');
$login=checkLoginPassEntity('admin', 'admin', 1, array('http','dolibarr')); // Should work because of second authetntication method $login=checkLoginPassEntity('admin', 'admin', 1, array('http','dolibarr')); // Should work because of second authetntication method
print __METHOD__." login=".$login."\n"; print __METHOD__." login=".$login."\n";
@ -553,4 +553,27 @@ class SecurityTest extends PHPUnit\Framework\TestCase
return 0; return 0;
} }
/**
* testDolSanitizeFileName
*
* @return void
*/
public function testDolSanitizeFileName()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
//$dummyuser=new User($db);
//$result=restrictedArea($dummyuser,'societe');
$result=dol_sanitizeFileName('bad file | evilaction');
$this->assertEquals('bad file _ evilaction', $result);
$result=dol_sanitizeFileName('bad file --evilparam');
$this->assertEquals('bad file _evilparam', $result);
}
} }