From c36f92396b03890be7367a1398c48dc06ccda990 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 5 Mar 2015 11:13:44 +0100
Subject: [PATCH] Add navigation into the new timesheet week page. Fix bad
 merge

---
 htdocs/core/lib/project.lib.php   | 37 ++++++++++++-----------
 htdocs/langs/en_US/projects.lang  |  3 +-
 htdocs/main.inc.php               |  4 +--
 htdocs/projet/activity/perday.php | 50 +++++++++++++++++++++++++++++--
 4 files changed, 69 insertions(+), 25 deletions(-)

diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php
index eb7617b5c7e..e4015812e62 100644
--- a/htdocs/core/lib/project.lib.php
+++ b/htdocs/core/lib/project.lib.php
@@ -234,10 +234,10 @@ function project_admin_prepare_head()
 /**
  * Show task lines with a particular parent
  *
- * @param	string	 	$inc				Counter that count number of lines legitimate to show (for return)
- * @param 	int			$parent				Id of parent task to start
- * @param 	array		$lines				Array of all tasks
- * @param 	int			$level				Level of task
+ * @param	string	   	$inc				Line number (start to 0, then increased by recursive call)
+ * @param   string		$parent				Id of parent project to show (0 to show all)
+ * @param   Task[]		$lines				Array of lines
+ * @param   int			$level				Level (start to 0, then increased/decrease by recursive call)
  * @param 	string		$var				Color
  * @param 	int			$showproject		Show project columns
  * @param	int			$taskrole			Array of roles of user for each tasks
@@ -482,12 +482,12 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t
 /**
  * Output a task line into a pertime intput mode
  *
- * @param	string	   	$inc					?
- * @param   string		$parent					?
- * @param   Task[]		$lines					?
- * @param   int			$level					?
- * @param   string		$projectsrole			?
- * @param   string		$tasksrole				?
+ * @param	string	   	$inc					Line number (start to 0, then increased by recursive call)
+ * @param   string		$parent					Id of parent project to show (0 to show all)
+ * @param   Task[]		$lines					Array of lines
+ * @param   int			$level					Level (start to 0, then increased/decrease by recursive call)
+ * @param   string		$projectsrole			Array of roles user has on project
+ * @param   string		$tasksrole				Array of roles user has on task
  * @param	string		$mine					Show only task lines I am assigned to
  * @param   int			$restricteditformytask	0=No restriction, 1=Enable add time only if task is a task i am affected to
  * @return  $inc
@@ -628,12 +628,12 @@ function projectLinesPerTime(&$inc, $parent, $lines, &$level, &$projectsrole, &$
 /**
  * Output a task line into a perday intput mode
  *
- * @param	string	   	$inc					?
- * @param   string		$parent					?
- * @param   Task[]		$lines					?
- * @param   int			$level					?
- * @param   string		$projectsrole			?
- * @param   string		$tasksrole				?
+ * @param	string	   	$inc					Line number (start to 0, then increased by recursive call)
+ * @param   string		$parent					Id of parent project to show (0 to show all)
+ * @param   Task[]		$lines					Array of lines
+ * @param   int			$level					Level (start to 0, then increased/decrease by recursive call)
+ * @param   string		$projectsrole			Array of roles user has on project
+ * @param   string		$tasksrole				Array of roles user has on task
  * @param	string		$mine					Show only task lines I am assigned to
  * @param   int			$restricteditformytask	0=No restriction, 1=Enable add time only if task is a task i am affected to
  * @return  $inc
@@ -750,7 +750,7 @@ function projectLinesPerDay(&$inc, $parent, $lines, &$level, &$projectsrole, &$t
 		        {
 		        	$dayWorkLoad = 0;
                     $tableCell ='<td align="center">';
-                    $tableCell.='<input type="text" class="center" size="2" disabled="disabled" value="'.convertSecondToTime($dayWorkLoad,'allhourmin').'">+';
+                    $tableCell.='<span class="timesheetalreadyrecorded"><input type="text" class="center" size="2" disabled="disabled" value="'.convertSecondToTime($dayWorkLoad,'allhourmin').'"></span>+';
 		        	$tableCell.='<input type="text" class="center" size="2" id="task['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2"  maxlength="5"';
 		        	$tableCell.=' onkeypress="return regexEvent(this,event,\'timeChar\')"';
                     $tableCell.= 'onblur="regexEvent(this,event,\''.$modeinput.'\');updateTotal('.$idw.',\''.$modeinput.'\')" />';
@@ -927,7 +927,8 @@ function print_projecttasks_array($db, $socid, $projectsListId, $mytasks=0, $sta
 
 	print "</table>";
 
-	if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE)) {
+	if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
+	{
 		//Add the year filter input
 		print '<table width="100%">';
 		print '<tr>';
diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang
index dc25c1f33b7..936e86ad692 100644
--- a/htdocs/langs/en_US/projects.lang
+++ b/htdocs/langs/en_US/projects.lang
@@ -136,4 +136,5 @@ ProjectMustBeValidatedFirst=Project must be validated first
 ProjectDraft=Draft projects
 FirstAddRessourceToAllocateTime=Associate a ressource to allocate time
 InputPerTime=Input per time
-InputPerDay=Input per day 
\ No newline at end of file
+InputPerDay=Input per day 
+TimeAlreadyRecorded=Time spent already recorded for this task/day and user %s
\ No newline at end of file
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 4818b2d38f1..36e246c42f2 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -1376,9 +1376,7 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a
         // Wrapper to show tooltips
         print "\n".'<script type="text/javascript">
                     jQuery(document).ready(function () {
-                    	jQuery(function() {
-                        	jQuery(".classfortooltip").tipTip({maxWidth: "'.dol_size(600,'width').'px", edgeOffset: 10, delay: 50, fadeIn: 50, fadeOut: 50});
-                        });
+                       	jQuery(".classfortooltip").tipTip({maxWidth: "'.dol_size(600,'width').'px", edgeOffset: 10, delay: 50, fadeIn: 50, fadeOut: 50});
                     });
                 </script>';
     }
diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php
index f7b37ca1ca0..692267d6965 100644
--- a/htdocs/projet/activity/perday.php
+++ b/htdocs/projet/activity/perday.php
@@ -50,6 +50,11 @@ $result = restrictedArea($user, 'projet', $projectid);
 
 $now=dol_now();
 
+$year=GETPOST("year","int")?GETPOST("year","int"):date("Y");
+$month=GETPOST("month","int")?GETPOST("month","int"):date("m");
+$week=GETPOST("week","int")?GETPOST("week","int"):date("W");
+$day=GETPOST("day","int")?GETPOST("day","int"):date("d");
+
 
 /*
  * Actions
@@ -138,6 +143,40 @@ print "\n";
 	dol_fiche_end();
 */
 
+
+$startdayarray=dol_get_first_day_week($day, $month, $year);
+
+$prev = $startdayarray;
+$prev_year  = $prev['prev_year'];
+$prev_month = $prev['prev_month'];
+$prev_day   = $prev['prev_day'];
+$first_day  = $prev['first_day'];
+$first_month= $prev['first_month'];
+$first_year = $prev['first_year'];
+$week = $prev['week'];
+
+$day = (int) $day;
+$next = dol_get_next_week($first_day, $week, $first_month, $first_year);
+$next_year  = $next['year'];
+$next_month = $next['month'];
+$next_day   = $next['day'];
+
+// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
+$firstdaytoshow=dol_mktime(0,0,0,$first_month,$first_day,$first_year);
+$lastdaytoshow=dol_time_plus_duree($firstdaytoshow, 7, 'd');
+
+$tmpday = $first_day;
+
+// Show navigation bar
+$nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
+$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$first_month,$first_day,$first_year),"%Y").", ".$langs->trans("Week")." ".$week;
+$nav.=" </span>\n";
+$nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day.$param."\">".img_next($langs->trans("Next"))."</a>\n";
+$nav.=" &nbsp; (<a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a>)";
+$picto='calendarweek';
+print '<div align="right">'.$nav.'</div>';
+
+
 print '<table class="noborder" width="100%">';
 print '<tr class="liste_titre">';
 print '<td>'.$langs->trans("Project").'</td>';
@@ -147,8 +186,6 @@ print '<td align="right">'.$langs->trans("PlannedWorkload").'</td>';
 print '<td align="right">'.$langs->trans("ProgressDeclared").'</td>';
 //print '<td align="right">'.$langs->trans("TimeSpent").'</td>';
 
-$tmp=dol_getdate($now);
-$startdayarray=dol_get_first_day_week($tmp['mday'], $tmp['mon'], $tmp['year']);
 $startday=dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']);
 
 for($i=0;$i<7;$i++)
@@ -192,7 +229,14 @@ print '<div class="center">';
 print '<input type="button" class="button" name="save" value="'.dol_escape_htmltag($langs->trans("Save")).'">';
 print '</div>';
 
-print '</form>';
+print '</form>'."\n\n";
+
+
+print '<script type="text/javascript">';
+print "jQuery(document).ready(function () {\n";
+print '		jQuery(".timesheetalreadyrecorded").tipTip({ maxWidth: "600px", edgeOffset: 10, delay: 50, fadeIn: 50, fadeOut: 50, content: \''.dol_escape_js($langs->trans("TimeAlreadyRecorded", $user->getFullName($langs))).'\'});';
+print "});";
+print '</script>';
 
 
 llxFooter();
-- 
GitLab