New: Can navigate into the "day view" of calendar

This commit is contained in:
Laurent Destailleur 2011-02-02 15:51:18 +00:00
parent 344219cb13
commit 5cb5aef53c
5 changed files with 198 additions and 139 deletions

View File

@ -72,6 +72,8 @@ $day=GETPOST("day","int")?GETPOST("day","int"):0;
$pid=GETPOST("projectid","int")?GETPOST("projectid","int"):0; $pid=GETPOST("projectid","int")?GETPOST("projectid","int"):0;
$status=GETPOST("status"); $status=GETPOST("status");
if (GETPOST('viewcal')) $day=''; // View by month
$langs->load("other"); $langs->load("other");
$langs->load("commercial"); $langs->load("commercial");
@ -96,9 +98,9 @@ if (! empty($_POST["viewlist"]))
if ($action=='delete_action') if ($action=='delete_action')
{ {
$actioncomm = new ActionComm($db); $event = new ActionComm($db);
$actioncomm->fetch($actionid); $event->fetch($actionid);
$result=$actioncomm->delete(); $result=$event->delete();
} }
@ -114,13 +116,13 @@ $form=new Form($db);
$companystatic=new Societe($db); $companystatic=new Societe($db);
$contactstatic=new Contact($db); $contactstatic=new Contact($db);
//print $langs->trans("FeatureNotYetAvailable");
$now=dol_now('tzref'); $now=dol_now('tzref');
if (empty($action) || $action=='show_month')
{
$prev = dol_get_prev_month($month, $year); $prev = dol_get_prev_month($month, $year);
$prev_year = $prev['year']; $prev_year = $prev['year'];
$prev_month = $prev['month']; $prev_month = $prev['month'];
$next = dol_get_next_month($month, $year); $next = dol_get_next_month($month, $year);
$next_year = $next['year']; $next_year = $next['year'];
$next_month = $next['month']; $next_month = $next['month'];
@ -136,6 +138,24 @@ $firstdaytoshow=dol_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$pre
$next_day=7-($max_day_in_month+1-$tmpday)%7; $next_day=7-($max_day_in_month+1-$tmpday)%7;
if ($next_day < 6) $next_day+=7; if ($next_day < 6) $next_day+=7;
$lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year); $lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
}
if ($action=='show_day')
{
$prev = dol_get_prev_day($day, $month, $year);
$prev_year = $prev['year'];
$prev_month = $prev['month'];
$prev_day = $prev['day'];
$next = dol_get_next_day($day, $month, $year);
$next_year = $next['year'];
$next_month = $next['month'];
$next_day = $next['day'];
// Define firstdaytoshow and lastdaytoshow
$firstdaytoshow=dol_mktime(0,0,0,$prev_month,$prev_day,$prev_year);
$lastdaytoshow=dol_mktime(0,0,0,$next_month,$next_day,$next_year);
}
//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
//print dol_print_date($firstdaytoshow,'day'); //print dol_print_date($firstdaytoshow,'day');
//print dol_print_date($lastdaytoshow,'day'); //print dol_print_date($lastdaytoshow,'day');
@ -152,25 +172,36 @@ if ($filterd) $param.="&filterd=".$filterd;
if ($socid) $param.="&socid=".$socid; if ($socid) $param.="&socid=".$socid;
if ($showbirthday) $param.="&showbirthday=1"; if ($showbirthday) $param.="&showbirthday=1";
if ($pid) $param.="&projectid=".$pid; if ($pid) $param.="&projectid=".$pid;
if (! empty($_REQUEST["type"])) $param.="&type=".$_REQUEST["type"]; if (GETPOST("type")) $param.="&type=".GETPOST("type");
if ($action == 'show_day') $param.='&action='.$action;
// Show navigation bar // Show navigation bar
if (empty($action) || $action=='show_month')
{
$nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;region=".$region.$param."\">".img_previous($langs->trans("Previous"))."</a>\n"; $nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;region=".$region.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%b"); $nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,1,$year),"%b %Y");
$nav.=" ".$year;
$nav.=" </span>\n"; $nav.=" </span>\n";
$nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;region=".$region.$param."\">".img_next($langs->trans("Next"))."</a>\n"; $nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;region=".$region.$param."\">".img_next($langs->trans("Next"))."</a>\n";
}
if ($action=='show_day')
{
$nav ="<a href=\"?year=".$prev_year."&amp;month=".$prev_month."&amp;day=".$prev_day."&amp;region=".$region.$param."\">".img_previous($langs->trans("Previous"))."</a>\n";
$nav.=" <span id=\"month_name\">".dol_print_date(dol_mktime(0,0,0,$month,$day,$year),"daytextshort");
$nav.=" </span>\n";
$nav.="<a href=\"?year=".$next_year."&amp;month=".$next_month."&amp;day=".$next_day."&amp;region=".$region.$param."\">".img_next($langs->trans("Next"))."</a>\n";
}
// Must be after the nav definition // Must be after the nav definition
$param.='&year='.$year.'&month='.$month.($day?'&day='.$day:''); $param.='&year='.$year.'&month='.$month.($day?'&day='.$day:'');
//print 'x'.$param;
print_fiche_titre($title,$nav); print_fiche_titre($title,$nav);
print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$action,$filtera,$filtert,$filterd,$pid,$socid); print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$filtera,$filtert,$filterd,$pid,$socid);
// Get event in an array // Get event in an array
$actionarray=array(); $eventarray=array();
$sql = 'SELECT a.id,a.label,'; $sql = 'SELECT a.id,a.label,';
$sql.= ' a.datep,'; $sql.= ' a.datep,';
@ -190,7 +221,7 @@ $sql.= ' AND a.fk_user_author = u.rowid';
$sql.= ' AND u.entity in (0,'.$conf->entity.')'; // To limit to entity $sql.= ' AND u.entity in (0,'.$conf->entity.')'; // To limit to entity
if ($user->societe_id) $sql.= ' AND a.fk_soc = '.$user->societe_id; // To limit to external user company if ($user->societe_id) $sql.= ' AND a.fk_soc = '.$user->societe_id; // To limit to external user company
if ($pid) $sql.=" AND a.fk_project=".addslashes($pid); if ($pid) $sql.=" AND a.fk_project=".addslashes($pid);
if ($_GET["action"] == 'show_day') if ($action == 'show_day')
{ {
$sql.= " AND ("; $sql.= " AND (";
$sql.= " (datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'"; $sql.= " (datep BETWEEN '".$db->idate(dol_mktime(0,0,0,$month,$day,$year))."'";
@ -242,57 +273,57 @@ if ($resql)
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
// Create a new object action // Create a new object action
$action=new ActionComm($db); $event=new ActionComm($db);
$action->id=$obj->id; $event->id=$obj->id;
$action->datep=$db->jdate($obj->datep); $event->datep=$db->jdate($obj->datep);
$action->datef=$db->jdate($obj->datep2); $event->datef=$db->jdate($obj->datep2);
$action->type_code=$obj->code; $event->type_code=$obj->code;
$action->libelle=$obj->label; $event->libelle=$obj->label;
$action->percentage=$obj->percent; $event->percentage=$obj->percent;
$action->author->id=$obj->fk_user_author; $event->author->id=$obj->fk_user_author;
$action->usertodo->id=$obj->fk_user_action; $event->usertodo->id=$obj->fk_user_action;
$action->userdone->id=$obj->fk_user_done; $event->userdone->id=$obj->fk_user_done;
$action->priority=$obj->priority; $event->priority=$obj->priority;
$action->fulldayevent=$obj->fulldayevent; $event->fulldayevent=$obj->fulldayevent;
$action->location=$obj->location; $event->location=$obj->location;
$action->societe->id=$obj->fk_soc; $event->societe->id=$obj->fk_soc;
$action->contact->id=$obj->fk_contact; $event->contact->id=$obj->fk_contact;
// Defined date_start_in_calendar and date_end_in_calendar property // Defined date_start_in_calendar and date_end_in_calendar property
// They are date start and end of action but modified to not be outside calendar view. // They are date start and end of action but modified to not be outside calendar view.
if ($action->percentage <= 0) if ($event->percentage <= 0)
{ {
$action->date_start_in_calendar=$action->datep; $event->date_start_in_calendar=$event->datep;
if ($action->datef != '' && $action->datef >= $action->datep) $action->date_end_in_calendar=$action->datef; if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
else $action->date_end_in_calendar=$action->datep; else $event->date_end_in_calendar=$event->datep;
} }
else else
{ {
$action->date_start_in_calendar=$action->datep; $event->date_start_in_calendar=$event->datep;
if ($action->datef != '' && $action->datef >= $action->datep) $action->date_end_in_calendar=$action->datef; if ($event->datef != '' && $event->datef >= $event->datep) $event->date_end_in_calendar=$event->datef;
else $action->date_end_in_calendar=$action->datep; else $event->date_end_in_calendar=$event->datep;
} }
// Define ponctual property // Define ponctual property
if ($action->date_start_in_calendar == $action->date_end_in_calendar) if ($event->date_start_in_calendar == $event->date_end_in_calendar)
{ {
$action->ponctuel=1; $event->ponctuel=1;
} }
// Check values // Check values
if ($action->date_end_in_calendar < $firstdaytoshow || if ($event->date_end_in_calendar < $firstdaytoshow ||
$action->date_start_in_calendar > $lastdaytoshow) $event->date_start_in_calendar > $lastdaytoshow)
{ {
// This record is out of visible range // This record is out of visible range
} }
else else
{ {
if ($action->date_start_in_calendar < $firstdaytoshow) $action->date_start_in_calendar=$firstdaytoshow; if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
if ($action->date_end_in_calendar > $lastdaytoshow) $action->date_end_in_calendar=$lastdaytoshow; if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=$lastdaytoshow;
// Add an entry in actionarray for each day // Add an entry in actionarray for each day
$daycursor=$action->date_start_in_calendar; $daycursor=$event->date_start_in_calendar;
$annee = date('Y',$daycursor); $annee = date('Y',$daycursor);
$mois = date('m',$daycursor); $mois = date('m',$daycursor);
$jour = date('d',$daycursor); $jour = date('d',$daycursor);
@ -302,18 +333,18 @@ if ($resql)
$daykey=dol_mktime(0,0,0,$mois,$jour,$annee); $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
do do
{ {
//if ($action->id==408) print 'daykey='.$daykey.' '.$action->datep.' '.$action->datef.'<br>'; //if ($event->id==408) print 'daykey='.$daykey.' '.$event->datep.' '.$event->datef.'<br>';
$actionarray[$daykey][]=$action; $eventarray[$daykey][]=$event;
$j++; $j++;
$daykey+=60*60*24; $daykey+=60*60*24;
if ($daykey > $action->date_end_in_calendar) $loop=false; if ($daykey > $event->date_end_in_calendar) $loop=false;
} }
while ($loop); while ($loop);
//print 'Event '.$i.' id='.$action->id.' (start='.dol_print_date($action->datep).'-end='.dol_print_date($action->datef); //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
//print ' startincalendar='.dol_print_date($action->date_start_in_calendar).'-endincalendar='.dol_print_date($action->date_end_in_calendar).') was added in '.$j.' different index key of array<br>'; //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
} }
$i++; $i++;
@ -331,7 +362,7 @@ if ($showbirthday)
$sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp'; $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
$sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))'; $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))';
$sql.= ' AND sp.entity = '.$conf->entity; $sql.= ' AND sp.entity = '.$conf->entity;
if ($_GET["action"] == 'show_day') if ($action == 'show_day')
{ {
$sql.= ' AND MONTH(birthday) = '.$month; $sql.= ' AND MONTH(birthday) = '.$month;
$sql.= ' AND DAY(birthday) = '.$day; $sql.= ' AND DAY(birthday) = '.$day;
@ -351,23 +382,23 @@ if ($showbirthday)
while ($i < $num) while ($i < $num)
{ {
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$action=new ActionComm($db); $event=new ActionComm($db);
$action->id=$obj->rowid; // We put contact id in action id for birthdays events $event->id=$obj->rowid; // We put contact id in action id for birthdays events
$datebirth=dol_stringtotime($obj->birthday); $datebirth=dol_stringtotime($obj->birthday);
//print 'ee'.$obj->birthday.'-'.$datebirth; //print 'ee'.$obj->birthday.'-'.$datebirth;
$datearray=dol_getdate($datebirth,true); $datearray=dol_getdate($datebirth,true);
$action->datep=dol_mktime(0,0,0,$datearray['mon'],$datearray['mday'],$year); $event->datep=dol_mktime(0,0,0,$datearray['mon'],$datearray['mday'],$year);
$action->datef=$action->datep; $event->datef=$event->datep;
$action->type_code='BIRTHDAY'; $event->type_code='BIRTHDAY';
$action->libelle=$langs->trans("Birthday").' '.$obj->firstname.' '.$obj->name; $event->libelle=$langs->trans("Birthday").' '.$obj->firstname.' '.$obj->name;
$action->percentage=100; $event->percentage=100;
$action->date_start_in_calendar=$action->datep; $event->date_start_in_calendar=$event->datep;
$action->date_end_in_calendar=$action->datef; $event->date_end_in_calendar=$event->datef;
$action->ponctuel=0; $event->ponctuel=0;
// Add an entry in actionarray for each day // Add an entry in actionarray for each day
$daycursor=$action->date_start_in_calendar; $daycursor=$event->date_start_in_calendar;
$annee = date('Y',$daycursor); $annee = date('Y',$daycursor);
$mois = date('m',$daycursor); $mois = date('m',$daycursor);
$jour = date('d',$daycursor); $jour = date('d',$daycursor);
@ -376,9 +407,9 @@ if ($showbirthday)
$daykey=dol_mktime(0,0,0,$mois,$jour,$annee); $daykey=dol_mktime(0,0,0,$mois,$jour,$annee);
do do
{ {
$actionarray[$daykey][]=$action; $eventarray[$daykey][]=$event;
$daykey+=60*60*24; $daykey+=60*60*24;
if ($daykey > $action->date_end_in_calendar) $loop=false; if ($daykey > $event->date_end_in_calendar) $loop=false;
} }
while ($loop); while ($loop);
$i++; $i++;
@ -404,9 +435,9 @@ if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), arr
// Add link to show birthdays // Add link to show birthdays
$link='<a href="'.$_SERVER['PHP_SELF']; $link='<a href="'.$_SERVER['PHP_SELF'];
$newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$param); $newparam=$param;
$newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam);
if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1'; if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1';
if ($_REQUEST['action']) $newparam.='&action='.$_REQUEST['action'];
$link.='?'.$newparam; $link.='?'.$newparam;
$link.='">'; $link.='">';
if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents"); if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents");
@ -427,7 +458,7 @@ if ($_GET["action"] != 'show_day') // View by month
echo " </tr>\n"; echo " </tr>\n";
// In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month) // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
//var_dump($actionarray); //var_dump($eventarray);
//print $tmpday; //print $tmpday;
for($iter_week = 0; $iter_week < 6 ; $iter_week++) for($iter_week = 0; $iter_week < 6 ; $iter_week++)
{ {
@ -439,7 +470,7 @@ if ($_GET["action"] != 'show_day') // View by month
{ {
$style='cal_other_month'; $style='cal_other_month';
echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">'; echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
show_day_events ($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $actionarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW, $maxlength, $newparam); show_day_events ($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW, $maxlength, $newparam);
echo " </td>\n"; echo " </td>\n";
} }
/* Show days of the current month */ /* Show days of the current month */
@ -455,7 +486,7 @@ if ($_GET["action"] != 'show_day') // View by month
$style='cal_current_month'; $style='cal_current_month';
echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">'; echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
show_day_events($db, $tmpday, $month, $year, $month, $style, $actionarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW, $maxlength, $newparam); show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW, $maxlength, $newparam);
echo " </td>\n"; echo " </td>\n";
} }
/* Show days after the current month (next month) */ /* Show days after the current month (next month) */
@ -463,7 +494,7 @@ if ($_GET["action"] != 'show_day') // View by month
{ {
$style='cal_other_month'; $style='cal_other_month';
echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">'; echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $actionarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW, $maxlength, $newparam); show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW, $maxlength, $newparam);
echo "</td>\n"; echo "</td>\n";
} }
$tmpday++; $tmpday++;
@ -484,7 +515,7 @@ else // View by day
echo " </tr>\n"; echo " </tr>\n";
echo " <tr>\n"; echo " <tr>\n";
echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">'; echo ' <td class="'.$style.'" width="14%" valign="top" nowrap="nowrap">';
show_day_events ($db, $day, $month, $year, $month, $style, $actionarray, 0, 80, $newparam, 1); show_day_events ($db, $day, $month, $year, $month, $style, $eventarray, 0, 80, $newparam, 1);
echo "</td>\n"; echo "</td>\n";
echo " </tr>\n"; echo " </tr>\n";
echo '</table>'; echo '</table>';
@ -506,13 +537,13 @@ llxFooter('$Date$ - $Revision$');
* @param $year Year * @param $year Year
* @param $monthshown Current month shown in calendar view * @param $monthshown Current month shown in calendar view
* @param $style Style to use for this day * @param $style Style to use for this day
* @param $actionarray Array of actions * @param $eventarray Array of events
* @param $maxPrint Nb of actions to show each day on month view (0 means non limit) * @param $maxPrint Nb of actions to show each day on month view (0 means non limit)
* @param $maxnbofchar Nb of characters to show for event line * @param $maxnbofchar Nb of characters to show for event line
* @param $newparam Parameters on current URL * @param $newparam Parameters on current URL
* @param $showinfo Add extended information (used by day view) * @param $showinfo Add extended information (used by day view)
*/ */
function show_day_events($db, $day, $month, $year, $monthshown, $style, &$actionarray, $maxPrint=0, $maxnbofchar=14, $newparam='', $showinfo=0) function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxPrint=0, $maxnbofchar=14, $newparam='', $showinfo=0)
{ {
global $user, $conf, $langs; global $user, $conf, $langs;
global $filter, $filtera, $filtert, $filterd, $status; global $filter, $filtera, $filtert, $filterd, $status;
@ -527,7 +558,10 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
print '<table class="nobordernopadding" width="100%">'; print '<table class="nobordernopadding" width="100%">';
print '<tr style="background: #EEEEEE"><td align="left" nowrap="nowrap">'; print '<tr style="background: #EEEEEE"><td align="left" nowrap="nowrap">';
print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.$month.'&year='.$year.'">'.dol_print_date($curtime,'%a %d').'</a>'; print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?action=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.$month.'&year='.$year.'">';
if ($showinfo) print dol_print_date($curtime,'daytext');
else print dol_print_date($curtime,'%d');
print '</a>';
print '</td><td align="right" nowrap="nowrap">'; print '</td><td align="right" nowrap="nowrap">';
if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create)
{ {
@ -542,47 +576,47 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
//$curtime = dol_mktime (0, 0, 0, $month, $day, $year); //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
$i=0; $i=0;
foreach ($actionarray as $daykey => $notused) foreach ($eventarray as $daykey => $notused)
{ {
$annee = date('Y',$daykey); $annee = date('Y',$daykey);
$mois = date('m',$daykey); $mois = date('m',$daykey);
$jour = date('d',$daykey); $jour = date('d',$daykey);
if ($day==$jour && $month==$mois && $year==$annee) if ($day==$jour && $month==$mois && $year==$annee)
{ {
foreach ($actionarray[$daykey] as $index => $action) foreach ($eventarray[$daykey] as $index => $event)
{ {
if ($i < $maxPrint || $maxPrint == 0) if ($i < $maxPrint || $maxPrint == 0)
{ {
$ponct=($action->date_start_in_calendar == $action->date_end_in_calendar); $ponct=($event->date_start_in_calendar == $event->date_end_in_calendar);
// Show rect of event // Show rect of event
$colorindex=0; $colorindex=0;
if ($action->author->id == $user->id || $action->usertodo->id == $user->id || $action->userdone->id == $user->id) $colorindex=1; if ($event->author->id == $user->id || $event->usertodo->id == $user->id || $event->userdone->id == $user->id) $colorindex=1;
if ($action->type_code == 'BIRTHDAY') $colorindex=2; if ($event->type_code == 'BIRTHDAY') $colorindex=2;
$color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]); $color=sprintf("%02x%02x%02x",$theme_datacolor[$colorindex][0],$theme_datacolor[$colorindex][1],$theme_datacolor[$colorindex][2]);
//print "x".$color; //print "x".$color;
print '<table class="cal_event" style="background: #'.$color.'; -moz-border-radius:4px; " width="100%"><tr>'; print '<table class="cal_event" style="background: #'.$color.'; -moz-border-radius:4px; " width="100%"><tr>';
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
if ($action->type_code != 'BIRTHDAY') if ($event->type_code != 'BIRTHDAY')
{ {
if ($showinfo) if ($showinfo)
{ {
print $action->getNomUrl(2).' '; print $event->getNomUrl(2).' ';
} }
if (empty($action->fulldayevent)) if (empty($event->fulldayevent))
{ {
// Show hours (start ... end) // Show hours (start ... end)
$tmpyearstart = date('Y',$action->date_start_in_calendar); $tmpyearstart = date('Y',$event->date_start_in_calendar);
$tmpmonthstart = date('m',$action->date_start_in_calendar); $tmpmonthstart = date('m',$event->date_start_in_calendar);
$tmpdaystart = date('d',$action->date_start_in_calendar); $tmpdaystart = date('d',$event->date_start_in_calendar);
$tmpyearend = date('Y',$action->date_end_in_calendar); $tmpyearend = date('Y',$event->date_end_in_calendar);
$tmpmonthend = date('m',$action->date_end_in_calendar); $tmpmonthend = date('m',$event->date_end_in_calendar);
$tmpdayend = date('d',$action->date_end_in_calendar); $tmpdayend = date('d',$event->date_end_in_calendar);
// Hour start // Hour start
if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour)
{ {
print dol_print_date($action->date_start_in_calendar,'%H:%M'); print dol_print_date($event->date_start_in_calendar,'%H:%M');
if ($action->date_end_in_calendar && $action->date_start_in_calendar != $action->date_end_in_calendar) if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
{ {
if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend)
print '-'; print '-';
@ -590,7 +624,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
//print '...'; //print '...';
} }
} }
if ($action->date_end_in_calendar && $action->date_start_in_calendar != $action->date_end_in_calendar) if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
{ {
if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend)
{ {
@ -598,10 +632,10 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
} }
} }
// Hour end // Hour end
if ($action->date_end_in_calendar && $action->date_start_in_calendar != $action->date_end_in_calendar) if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar)
{ {
if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour)
print dol_print_date($action->date_end_in_calendar,'%H:%M'); print dol_print_date($event->date_end_in_calendar,'%H:%M');
} }
print '<br>'."\n"; print '<br>'."\n";
} }
@ -615,24 +649,24 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
// If action related to company / contact // If action related to company / contact
$linerelatedto='';$length=16; $linerelatedto='';$length=16;
if (! empty($action->societe->id) && ! empty($action->contact->id)) $length=8; if (! empty($event->societe->id) && ! empty($event->contact->id)) $length=8;
if (! empty($action->societe->id)) if (! empty($event->societe->id))
{ {
if (empty($cachethirdparties[$action->societe->id])) if (empty($cachethirdparties[$event->societe->id]))
{ {
$thirdparty=new Societe($db); $thirdparty=new Societe($db);
$thirdparty->fetch($action->societe->id); $thirdparty->fetch($event->societe->id);
$cachethirdparties[$action->societe->id]=$thirdparty; $cachethirdparties[$event->societe->id]=$thirdparty;
} }
$linerelatedto.=$thirdparty->getNomUrl(1,'',$length); $linerelatedto.=$thirdparty->getNomUrl(1,'',$length);
} }
if (! empty($action->contact->id)) if (! empty($event->contact->id))
{ {
if (empty($cachetcontact[$action->societe->id])) if (empty($cachetcontact[$event->societe->id]))
{ {
$contact=new Contact($db); $contact=new Contact($db);
$contact->fetch($action->contact->id); $contact->fetch($event->contact->id);
$cachethirdparties[$action->contact->id]=$thirdparty; $cachethirdparties[$event->contact->id]=$thirdparty;
} }
if ($linerelatedto) $linerelatedto.=' / '; if ($linerelatedto) $linerelatedto.=' / ';
$linerelatedto.=$contact->getNomUrl(1,'',$length); $linerelatedto.=$contact->getNomUrl(1,'',$length);
@ -640,25 +674,25 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
if ($linerelatedto) print $linerelatedto.'<br>'; if ($linerelatedto) print $linerelatedto.'<br>';
// Show label // Show label
print $action->getNomUrl(0,$maxnbofchar,'cal_event'); print $event->getNomUrl(0,$maxnbofchar,'cal_event');
} }
else // It's a birthday else // It's a birthday
{ {
print $action->getNomUrl(1,$maxnbofchar,'cal_event','birthday','contact'); print $event->getNomUrl(1,$maxnbofchar,'cal_event','birthday','contact');
} }
// Show location // Show location
if ($showinfo) if ($showinfo)
{ {
if ($action->location) if ($event->location)
{ {
print '<br>'; print '<br>';
print $langs->trans("Location").': '.$action->location; print $langs->trans("Location").': '.$event->location;
} }
} }
print '</td>'; print '</td>';
// Status - Percent // Status - Percent
print '<td align="right" nowrap="nowrap">'; print '<td align="right" nowrap="nowrap">';
if ($action->type_code != 'BIRTHDAY') print $action->getLibStatut(3); if ($event->type_code != 'BIRTHDAY') print $event->getLibStatut(3);
else print '&nbsp;'; else print '&nbsp;';
print '</td></tr></table>'; print '</td></tr></table>';
$i++; $i++;
@ -669,7 +703,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$action
print ($status?'&status='.$status:'').($filter?'&filter='.$filter:''); print ($status?'&status='.$status:'').($filter?'&filter='.$filter:'');
print ($filtera?'&filtera='.$filtera:'').($filtert?'&filtert='.$filtert:'').($filterd?'&filterd='.$filterd:''); print ($filtera?'&filtera='.$filtera:'').($filtert?'&filtert='.$filtert:'').($filterd?'&filterd='.$filterd:'');
print '">'.img_picto("all","1downarrow_selected.png").' ...'; print '">'.img_picto("all","1downarrow_selected.png").' ...';
print ' +'.(sizeof($actionarray[$daykey])-$maxPrint); print ' +'.(sizeof($eventarray[$daykey])-$maxPrint);
print '</a>'; print '</a>';
break; break;
//$ok=false; // To avoid to show twice the link //$ok=false; // To avoid to show twice the link

View File

@ -186,7 +186,7 @@ if ($resql)
//print '<br>'; //print '<br>';
print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$action,$filtera,$filtert,$filterd,$pid,$socid); print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$filtera,$filtert,$filterd,$pid,$socid);
$i = 0; $i = 0;
print "<table class=\"noborder\" width=\"100%\">"; print "<table class=\"noborder\" width=\"100%\">";

View File

@ -34,14 +34,13 @@
* @param $month * @param $month
* @param $day * @param $day
* @param $showborthday * @param $showborthday
* @param $action
* @param $filtera * @param $filtera
* @param $filtert * @param $filtert
* @param $filterd * @param $filterd
* @param $pid * @param $pid
* @param $socid * @param $socid
*/ */
function print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$action,$filtera,$filtert,$filterd,$pid,$socid) function print_actions_filter($form,$canedit,$status,$year,$month,$day,$showborthday,$filtera,$filtert,$filterd,$pid,$socid)
{ {
global $conf,$langs; global $conf,$langs;
@ -55,7 +54,6 @@ function print_actions_filter($form,$canedit,$status,$year,$month,$day,$showbort
print '<input type="hidden" name="month" value="'.$month.'">'; print '<input type="hidden" name="month" value="'.$month.'">';
print '<input type="hidden" name="day" value="'.$day.'">'; print '<input type="hidden" name="day" value="'.$day.'">';
print '<input type="hidden" name="showbirthday" value="'.$showbirthday.'">'; print '<input type="hidden" name="showbirthday" value="'.$showbirthday.'">';
print '<input type="hidden" name="action" value="'.$action.'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
if ($canedit || $conf->projet->enabled) if ($canedit || $conf->projet->enabled)
{ {

View File

@ -104,6 +104,34 @@ function ConvertSecondToTime($iSecond,$format='all',$lengthOfDay=86400)
} }
/** Return previous day
* @param day Day
* @param month Month
* @param year Year
* @return array Previous year,month,day
*/
function dol_get_prev_day($day, $month, $year)
{
$time=dol_mktime(12,0,0,$month,$day,$year,1,0);
$time-=24*60*60;
$tmparray=dol_getdate($time,true);
return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
/** Return next day
* @param day Day
* @param month Month
* @param year Year
* @return array Next year,month,day
*/
function dol_get_next_day($day, $month, $year)
{
$time=dol_mktime(12,0,0,$month,$day,$year,1,0);
$time+=24*60*60;
$tmparray=dol_getdate($time,true);
return array('year' => $tmparray['year'], 'month' => $tmparray['mon'], 'day' => $tmparray['mday']);
}
/** Return previous month /** Return previous month
* @param month Month * @param month Month
* @param year Year * @param year Year

View File

@ -517,7 +517,7 @@ function dolibarr_print_date($time,$format='',$to_gmt=false,$outputlangs='',$enc
* 'tzuser'=output string is for local browser TZ usage * 'tzuser'=output string is for local browser TZ usage
* @param outputlangs Object lang that contains language for text translation. * @param outputlangs Object lang that contains language for text translation.
* @return string Formated date or '' if time is null * @return string Formated date or '' if time is null
* @see dol_mktime, dol_stringtotime * @see dol_mktime, dol_stringtotime, dol_getdate
*/ */
function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$encodetooutput=false) function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$encodetooutput=false)
{ {
@ -657,7 +657,7 @@ function dol_print_date($time,$format='',$tzoutput='tzserver',$outputlangs='',$e
* 19700101020000 -> 7200 * 19700101020000 -> 7200
* @param gm 1=Input date is GM date, 0=Input date is local date * @param gm 1=Input date is GM date, 0=Input date is local date
* @return date Date * @return date Date
* @see dol_print_date, dol_mktime * @see dol_print_date, dol_mktime, dol_getdate
*/ */
function dol_stringtotime($string, $gm=1) function dol_stringtotime($string, $gm=1)
{ {
@ -686,10 +686,11 @@ function dol_stringtotime($string, $gm=1)
/** /**
* \brief Return an array with date info * Return an array with date info
* \param timestamp Timestamp * PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows.
* \param fast Fast mode * @param timestamp Timestamp
* \return array Array of informations * @param fast Fast mode
* @return array Array of informations
* If no fast mode: * If no fast mode:
* 'seconds' => $secs, * 'seconds' => $secs,
* 'minutes' => $min, * 'minutes' => $min,
@ -701,7 +702,6 @@ function dol_stringtotime($string, $gm=1)
* 'yday' => floor($secsInYear/$_day_power), * 'yday' => floor($secsInYear/$_day_power),
* 'weekday' => gmdate('l',$_day_power*(3+$dow)), * 'weekday' => gmdate('l',$_day_power*(3+$dow)),
* 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), * 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)),
* 0 => $origd
* If fast mode: * If fast mode:
* 'seconds' => $secs, * 'seconds' => $secs,
* 'minutes' => $min, * 'minutes' => $min,
@ -712,7 +712,6 @@ function dol_stringtotime($string, $gm=1)
* 'yday' => floor($secsInYear/$_day_power), * 'yday' => floor($secsInYear/$_day_power),
* 'leap' => $leaf, * 'leap' => $leaf,
* 'ndays' => $ndays * 'ndays' => $ndays
* \remarks PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows
*/ */
function dol_getdate($timestamp,$fast=false) function dol_getdate($timestamp,$fast=false)
{ {
@ -832,11 +831,11 @@ function dol_date($fmt, $timestamp, $gm=false)
/** /**
* \brief Return string with formated size * Return string with formated size
* \param size Size to print * @param size Size to print
* \param shortvalue Tell if we want long value to use another unit (Ex: 1.5Kb instead of 1500b) * @param shortvalue Tell if we want long value to use another unit (Ex: 1.5Kb instead of 1500b)
* \param shortunit Use short value of size unit * @param shortunit Use short value of size unit
* \return string Link * @return string Link
*/ */
function dol_print_size($size,$shortvalue=0,$shortunit=0) function dol_print_size($size,$shortvalue=0,$shortunit=0)
{ {