예제 #1
0
/**
 * Output a task line into a perday intput mode
 *
 * @param	string	   	$inc					Line number (start to 0, then increased by recursive call)
 * @param	int			$firstdaytoshow			First day to show
 * @param	User|null	$fuser					Restrict list to user if defined
 * @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
 */
function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask = 1)
{
    global $db, $user, $bc, $langs;
    global $form, $formother, $projectstatic, $taskstatic;
    $lastprojectid = 0;
    $var = true;
    $numlines = count($lines);
    for ($i = 0; $i < $numlines; $i++) {
        if ($parent == 0) {
            $level = 0;
        }
        if ($lines[$i]->fk_parent == $parent) {
            // Break on a new project
            if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) {
                $var = !$var;
                $lastprojectid = $lines[$i]->fk_project;
                $projectstatic->id = $lines[$i]->fk_project;
                $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id);
                // Load time spent into this->weekWorkLoad and this->weekWorkLoadPerTaks for all day of a week
            }
            // If we want all or we have a role on task, we show it
            if (empty($mine) || !empty($tasksrole[$lines[$i]->id])) {
                print "<tr " . $bc[$var] . ">\n";
                // Project
                print '<td class="nowrap">';
                $projectstatic->id = $lines[$i]->fk_project;
                $projectstatic->ref = $lines[$i]->projectref;
                $projectstatic->title = $lines[$i]->projectlabel;
                $projectstatic->public = $lines[$i]->public;
                print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole") . ': ' . $projectsrole[$lines[$i]->fk_project]);
                print "</td>";
                // Ref
                print '<td class="nowrap">';
                $taskstatic->id = $lines[$i]->id;
                $taskstatic->ref = $lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id;
                print $taskstatic->getNomUrl(1, 'withproject', 'time');
                print '</td>';
                // Label task
                print "<td>";
                print '<!-- Task id = ' . $lines[$i]->id . ' -->';
                for ($k = 0; $k < $level; $k++) {
                    print "&nbsp;&nbsp;&nbsp;";
                }
                $taskstatic->id = $lines[$i]->id;
                $taskstatic->ref = $lines[$i]->label;
                $taskstatic->date_start = $lines[$i]->date_start;
                $taskstatic->date_end = $lines[$i]->date_end;
                print $taskstatic->getNomUrl(0, 'withproject', 'time');
                //print "<br>";
                //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
                //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
                print "</td>\n";
                // Planned Workload
                print '<td align="right">';
                if ($lines[$i]->planned_workload) {
                    print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
                } else {
                    print '--:--';
                }
                print '</td>';
                // Progress declared %
                print '<td align="right">';
                print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
                print '</td>';
                // Time spent by everybody
                print '<td align="right">';
                // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
                if ($lines[$i]->duration) {
                    print '<a href="' . DOL_URL_ROOT . '/projet/tasks/time.php?id=' . $lines[$i]->id . '">';
                    print convertSecondToTime($lines[$i]->duration, 'allhourmin');
                    print '</a>';
                } else {
                    print '--:--';
                }
                print "</td>\n";
                // Time spent by user
                print '<td align="right">';
                $tmptimespent = $taskstatic->getSummaryOfTimeSpent();
                if ($tmptimespent['total_duration']) {
                    print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
                } else {
                    print '--:--';
                }
                print "</td>\n";
                $disabledproject = 1;
                $disabledtask = 1;
                //print "x".$lines[$i]->fk_project;
                //var_dump($lines[$i]);
                //var_dump($projectsrole[$lines[$i]->fk_project]);
                // If at least one role for project
                if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer) {
                    $disabledproject = 0;
                    $disabledtask = 0;
                }
                // If $restricteditformytask is on and I have no role on task, i disable edit
                if ($restricteditformytask && empty($tasksrole[$lines[$i]->id])) {
                    $disabledtask = 1;
                }
                //var_dump($projectstatic->weekWorkLoadPerTask);
                // Fields to show current time
                $tableCell = '';
                $modeinput = 'hours';
                for ($idw = 0; $idw < 7; $idw++) {
                    $tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
                    $tmparray = dol_getdate($tmpday);
                    $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
                    $alreadyspent = '';
                    if ($dayWorkLoad > 0) {
                        $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
                    }
                    $alttitle = $langs->trans("AddHereTimeSpentForDay", $tmparray['day'], $tmparray['mon']);
                    $tableCell = '<td align="center" class="hide' . $idw . '">';
                    if ($alreadyspent) {
                        $tableCell .= '<span class="timesheetalreadyrecorded"><input type="text" class="center smallpadd" size="2" disabled id="timespent[' . $inc . '][' . $idw . ']" name="task[' . $lines[$i]->id . '][' . $idw . ']" value="' . $alreadyspent . '"></span>';
                        //$placeholder=' placeholder="00:00"';
                        $placeholder = '';
                        //$tableCell.='+';
                    }
                    $tableCell .= '<input type="text" alt="' . ($disabledtask ? '' : $alttitle) . '" title="' . ($disabledtask ? '' : $alttitle) . '" ' . ($disabledtask ? 'disabled' : $placeholder) . ' class="center smallpadd" size="2" id="timeadded[' . $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 . '\')" />';
                    $tableCell .= '</td>';
                    print $tableCell;
                }
                print '<td align="right">';
                if (!$lines[$i]->public && $disabledproject) {
                    print $form->textwithpicto('', $langs->trans("YouAreNotContactOfProject"));
                } else {
                    if ($disabledtask) {
                        print $form->textwithpicto('', $langs->trans("TaskIsNotAffectedToYou"));
                    }
                }
                print '</td>';
                print "</tr>\n";
            }
            $inc++;
            $level++;
            if ($lines[$i]->id) {
                projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask);
            }
            $level--;
        } else {
            //$level--;
        }
    }
    return $inc;
}
예제 #2
0
    print '<td align="right">' . $langs->trans("TimeSpentByUser") . '</td>';
}
$startday = dol_mktime(12, 0, 0, $startdayarray['first_month'], $startdayarray['first_day'], $startdayarray['first_year']);
for ($i = 0; $i < 7; $i++) {
    print '<td width="7%" align="center" class="hide' . $i . '">' . dol_print_date($startday + $i * 3600 * 24, '%a') . '<br>' . dol_print_date($startday + $i * 3600 * 24, 'dayreduceformat') . '</td>';
}
print '<td class="liste_total"></td>';
print "</tr>\n";
// By default, we can edit only tasks we are assigned to
$restrictviewformytask = empty($conf->global->PROJECT_TIME_SHOW_TASK_NOT_ASSIGNED) ? 1 : 0;
if (count($tasksarray) > 0) {
    //var_dump($tasksarray);
    //var_dump($tasksrole);
    $j = 0;
    $level = 0;
    projectLinesPerWeek($j, $firstdaytoshow, $usertoprocess, 0, $tasksarray, $level, $projectsrole, $tasksrole, $mine, $restrictviewformytask);
    print '<tr class="liste_total">
                <td class="liste_total" colspan="7" align="right">' . $langs->trans("Total") . '</td>
                <td class="liste_total hide0" width="7%" align="center"><div id="totalDay[0]">&nbsp;</div></td>
                <td class="liste_total hide1" width="7%" align="center"><div id="totalDay[1]">&nbsp;</div></td>
                <td class="liste_total hide2" width="7%" align="center"><div id="totalDay[2]">&nbsp;</div></td>
                <td class="liste_total hide3" width="7%" align="center"><div id="totalDay[3]">&nbsp;</div></td>
                <td class="liste_total hide4" width="7%" align="center"><div id="totalDay[4]">&nbsp;</div></td>
                <td class="liste_total hide5" width="7%" align="center"><div id="totalDay[5]">&nbsp;</div></td>
                <td class="liste_total hide6" width="7%" align="center"><div id="totalDay[6]">&nbsp;</div></td>
                <td class="liste_total"></td>
    </tr>';
} else {
    print '<tr><td colspan="11">' . $langs->trans("NoTasks") . '</td></tr>';
}
print "</table>";