From aeae7231082a55b1eaff287a47421fbe93c98fc7 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 11 Apr 2013 10:15:53 +0200
Subject: [PATCH] New: Event into calendar use different colors for different
 users.

---
 ChangeLog                         |  1 +
 htdocs/comm/action/index.php      | 41 ++++++++++++++++++++++++++-----
 htdocs/theme/eldy/graph-color.php |  2 +-
 htdocs/theme/eldy/style.css.php   |  2 +-
 4 files changed, 38 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cbca688c6c0..ffff5a7a6e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -4,6 +4,7 @@ English Dolibarr ChangeLog
 
 ***** ChangeLog for 3.4 compared to 3.3.2 *****
 For users:
+- New: Event into calendar use different colors for different users.
 - New: Support revenue stamp onto invoices.
 - New: Add a tab "consumption" on thirdparties to list products bought/sells.
 - New: Some performance enhancements.
diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php
index 0b182c7645f..49a84a28d22 100644
--- a/htdocs/comm/action/index.php
+++ b/htdocs/comm/action/index.php
@@ -942,7 +942,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
     global $user, $conf, $langs;
     global $filter, $filtera, $filtert, $filterd, $status;
     global $theme_datacolor;
-    global $cachethirdparties, $cachecontacts;
+    global $cachethirdparties, $cachecontacts, $colorindexused;
 
     print '<div id="dayevent_'.sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day).'" class="dayevent">'."\n";
     $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
@@ -972,6 +972,9 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
     $i=0; $nummytasks=0; $numother=0; $numbirthday=0; $numical=0; $numicals=array();
     $ymd=sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day);
 
+    $nextindextouse=count($colorindexused);
+	//print $nextindextouse;
+
     foreach ($eventarray as $daykey => $notused)
     {
         $annee = date('Y',$daykey);
@@ -989,10 +992,12 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
                     $color=-1; $cssclass=''; $colorindex=-1;
                     if ((! empty($event->author->id) && $event->author->id == $user->id)
                     || (! empty($event->usertodo->id) && $event->usertodo->id == $user->id)
-                    || (! empty($event->userdone->id) && $event->userdone->id == $user->id)) {
-                    	$nummytasks++; $colorindex=1; $cssclass='family_mytasks';
+                    || (! empty($event->userdone->id) && $event->userdone->id == $user->id))
+                    {
+                    	$nummytasks++; $cssclass='family_mytasks';
                     }
-                    else if ($event->type_code == 'ICALEVENT') {
+                    else if ($event->type_code == 'ICALEVENT')
+                    {
                     	$numical++;
                     	if (! empty($event->icalname)) {
                     		if (! isset($numicals[dol_string_nospecial($event->icalname)])) {
@@ -1004,8 +1009,25 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
                     	$cssclass=(! empty($event->icalname)?'family_'.dol_string_nospecial($event->icalname):'family_other');
                     }
                     else if ($event->type_code == 'BIRTHDAY')  { $numbirthday++; $colorindex=2; $cssclass='family_birthday'; }
-                    else { $numother++; $colorindex=2; $cssclass='family_other'; }
-                    if ($color == -1) $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
+                    else { $numother++; $cssclass='family_other'; }
+                    if ($color == -1)	// Color was not forced. Set color according to color index.
+                    {
+                    	// Define color index if not yet defined
+                    	$idusertouse=($event->usertodo->id?$event->usertodo->id:0);
+                    	if (isset($colorindexused[$idusertouse]))
+                    	{
+                    		$colorindex=$colorindexused[$idusertouse];	// Color already assigned to this user
+                    	}
+                    	else
+                    	{
+                    		$colorindex=$nextindextouse;
+                    		$colorindexused[$idusertouse]=$colorindex;
+                    		if (! empty($theme_datacolor[$nextindextouse+1])) $nextindextouse++;	// Prepare to use next color
+                    	}
+                    	//print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
+						// Define color
+                    	$color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
+                    }
                     $cssclass=$cssclass.' '.$cssclass.'_day_'.$ymd;
 
                     // Show rect of event
@@ -1182,6 +1204,13 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa
     print '</div>'."\n";
 }
 
+/**
+ * Change color with a delta
+ *
+ * @param	string	$color		Color
+ * @param 	int		$minus		Delta
+ * @return	string				New color
+ */
 function dol_color_minus($color, $minus)
 {
 	$newcolor=$color;
diff --git a/htdocs/theme/eldy/graph-color.php b/htdocs/theme/eldy/graph-color.php
index e49f86bce60..ab59c7689a4 100644
--- a/htdocs/theme/eldy/graph-color.php
+++ b/htdocs/theme/eldy/graph-color.php
@@ -28,7 +28,7 @@
 
 global $theme_bordercolor, $theme_datacolor, $theme_bgcolor, $theme_bgcoloronglet;
 $theme_bordercolor = array(235,235,224);
-$theme_datacolor = array(array(125,135,150), array(200,160,180), array(190,190,220), array(170,140,190), array(190,190,170));
+$theme_datacolor = array(array(190,190,220), array(200,160,180), array(125,135,150), array(170,140,190), array(190,190,170));
 $theme_bgcolor = array(hexdec('F4'),hexdec('F4'),hexdec('F4'));
 $theme_bgcoloronglet = array(hexdec('DE'),hexdec('E7'),hexdec('EC'));
 
diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php
index eba9a7cc86d..88da3fd4894 100644
--- a/htdocs/theme/eldy/style.css.php
+++ b/htdocs/theme/eldy/style.css.php
@@ -2100,7 +2100,7 @@ table.cal_month    { border-spacing: 0px; }
 .cal_other_month   { border-top: 0; border-left: solid 1px #C0C0C0; border-right: 0; border-bottom: solid 1px #C0C0C0; }
 .cal_current_month_right { border-right: solid 1px #E0E0E0; }
 .cal_other_month_right   { border-right: solid 1px #C0C0C0; }
-.cal_other_month   { opacity: 0.6; background: #DDDDDD; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
+.cal_other_month   { opacity: 0.6; background: #EAEAEA; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
 .cal_past_month    { opacity: 0.6; background: #EEEEEE; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
 .cal_current_month { background: #FFFFFF; border-left: solid 1px #E0E0E0; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
 .cal_today         { background: #FFFFFF; border: solid 2px #6C7C7B; padding-<?php print $left; ?>: 2px; padding-<?php print $right; ?>: 1px; padding-top: 0px; padding-bottom: 0px; }
-- 
GitLab