diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 612a1027043..84c4a411aff 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -64,6 +64,7 @@ if (! $user->rights->agenda->allactions->read || $_GET["filter"]=='mine') $year=isset($_REQUEST["year"])?$_REQUEST["year"]:date("Y"); $month=isset($_REQUEST["month"])?$_REQUEST["month"]:date("m"); +$day=isset($_REQUEST["day"])?$_REQUEST["day"]:0; $langs->load("other"); @@ -118,10 +119,10 @@ $next_month = $next['month']; $max_day_in_prev_month = date("t",dolibarr_mktime(0,0,0,$prev_month,1,$prev_year)); $max_day_in_month = date("t",dolibarr_mktime(0,0,0,$month,1,$year)); -$day = -date("w",dolibarr_mktime(0,0,0,$month,1,$year))+2; -if ($day > 1) $day -= 7; -$firstdaytoshow=dolibarr_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$day,$prev_year); -$next_day=7-($max_day_in_month+1-$day)%7; +$tmpday = -date("w",dolibarr_mktime(0,0,0,$month,1,$year))+2; +if ($tmpday > 1) $tmpday -= 7; +$firstdaytoshow=dolibarr_mktime(0,0,0,$prev_month,$max_day_in_prev_month+$tmpday,$prev_year); +$next_day=7-($max_day_in_month+1-$tmpday)%7; if ($next_day < 6) $next_day+=7; $lastdaytoshow=dolibarr_mktime(0,0,0,$next_month,$next_day,$next_year); //print dolibarr_print_date($firstdaytoshow,'day'); @@ -132,15 +133,15 @@ if ($status == 'done') $title=$langs->trans("DoneActions"); if ($status == 'todo') $title=$langs->trans("ToDoActions"); $param=''; -if ($status) $param="&status=".$status; -if ($filter) $param.="&filter=".$filter; +if ($status) $param="&status=".$status; +if ($filter) $param.="&filter=".$filter; if ($filtera) $param.="&filtera=".$filtera; if ($filtert) $param.="&filtert=".$filtert; if ($filterd) $param.="&filterd=".$filterd; -if ($time) $param.="&time=".$_REQUEST["time"]; -if ($socid) $param.="&socid=".$_REQUEST["socid"]; +if ($time) $param.="&time=".$_REQUEST["time"]; +if ($socid) $param.="&socid=".$_REQUEST["socid"]; if ($showbirthday) $param.="&showbirthday=1"; -if ($_GET["type"]) $param.="&type=".$_REQUEST["type"]; +if (! empty($_REQUEST["type"])) $param.="&type=".$_REQUEST["type"]; // Show navigation bar $nav ="".img_previous($langs->trans("Previous"))."\n"; @@ -150,7 +151,7 @@ $nav.=" \n"; $nav.="".img_next($langs->trans("Next"))."\n"; // Must be after the nav definition -$param.='&year='.$year.'&month='.$month; +$param.='&year='.$year.'&month='.$month.($day?'&day='.$day:''); print_fiche_titre($title,$nav,""); @@ -162,7 +163,9 @@ if ($canedit) print ''; print ''; print ''; + print ''; print ''; + print ''; print ''; print ''; print '\n"; } /* Show days of the current month */ - elseif(($day <= $max_day_in_month)) + elseif(($tmpday <= $max_day_in_month)) { - $curtime = dolibarr_mktime (0, 0, 0, $month, $day, $year); + $curtime = dolibarr_mktime (0, 0, 0, $month, $tmpday, $year); if ($curtime < $now) $style='cal_current_month'; @@ -412,7 +431,7 @@ if ($_GET["action"] != 'show_day') $style='cal_current_month'; echo ' \n"; } /* Show days after the current month (next month) */ @@ -420,10 +439,10 @@ if ($_GET["action"] != 'show_day') { $style='cal_other_month'; echo ' \n"; } - $day++; + $tmpday++; } echo " \n"; } @@ -431,7 +450,6 @@ if ($_GET["action"] != 'show_day') } else { - $style='cal_current_month'; $timestamp=dolibarr_mktime(12,0,0,$month,$_GET["day"],$year); $arraytimestamp=adodb_getdate(dolibarr_mktime(12,0,0,$month,$_GET["day"],$year)); @@ -451,6 +469,7 @@ else $db->close(); + llxFooter('$Date$ - $Revision$'); @@ -552,7 +571,9 @@ function show_day_events($db, $day, $month, $year, $style, $actionarray, $maxPri print $action->getNomUrl(0,14,'cal_event','birthday'); } print ''; - print '
'; @@ -218,6 +221,14 @@ if ($_GET["action"] == 'show_day') $sql.= ' AND datep BETWEEN '.$db->idate(dolibarr_mktime(0,0,0,$month,$_GET["day"],$year)); $sql.= ' AND '.$db->idate(dolibarr_mktime(23,59,59,$month,$_GET["day"],$year)); } +else +{ + // To limit array + $startmonth=$month-2; $startyear=$year; if ($startmonth < 1) { $startmonth+=12; $startyear--; } + $endmonth=$month+2; $endyear=$year; if ($endmonth > 12) { $endmonth-=12; $endyear++; } + $sql.= ' AND datep BETWEEN '.$db->idate(dolibarr_mktime(0,0,0,$startmonth,1,$startyear)); + $sql.= ' AND '.$db->idate(dolibarr_mktime(0,0,0,$endmonth,1,$endyear)); +} if ($filtera > 0 || $filtert > 0 || $filterd > 0) { $sql.= " AND ("; @@ -228,8 +239,8 @@ if ($filtera > 0 || $filtert > 0 || $filterd > 0) } if ($status == 'done') { $sql.= " AND a.percent = 100"; } if ($status == 'todo') { $sql.= " AND a.percent < 100"; } -// \TODO Limit select on dates -$sql .= ' ORDER BY datep'; +// Sort on date +$sql.= ' ORDER BY datep'; //print $sql; $resql=$db->query($sql); @@ -298,16 +309,19 @@ else if ($showbirthday) { // Add events in array - $sql = 'SELECT sp.rowid, sp.name, sp.firstname,'; - $sql.= ' '.$db->pdate('sp.birthday').' as birthday'; + $sql = 'SELECT sp.rowid, sp.name, sp.firstname, sp.birthday'; $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp'; $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))'; if ($_GET["action"] == 'show_day') { - $sql.= ' AND birthday BETWEEN '.$db->idate(dolibarr_mktime(0,0,0,$month,$_GET["day"],$year)); - $sql.= ' AND '.$db->idate(dolibarr_mktime(23,59,59,$month,$_GET["day"],$year)); + $sql.= ' AND MONTH(birthday) = '.$month; + $sql.= ' AND DAY(birthday) = '.$_GET["day"]; } - // \TODO Limit select on dates + else + { + $sql.= ' AND MONTH(birthday) = '.$month; + } + // Sort on date $sql .= ' ORDER BY birthday'; //print $sql; @@ -321,8 +335,11 @@ if ($showbirthday) $obj = $db->fetch_object($resql); $action=new ActionComm($db); $action->id=$obj->rowid; // We put contact id in action id for birthdays events - $action->datep=$obj->birthday; - $action->datef=$obj->birthday; + $datebirth=dolibarr_stringtotime($obj->birthday); + //print 'ee'.$obj->birthday.'-'.$datebirth; + $datearray=dolibarr_getdate($datebirth,true); + $action->datep=dolibarr_mktime(0,0,0,$datearray['mon'],$datearray['mday'],$year); + $action->datef=$action->datep; $action->type_code='BIRTHDAY'; $action->libelle=$langs->trans("Birthday").' '.$obj->firstname.' '.$obj->name; $action->percentage=100; @@ -363,9 +380,11 @@ if (is_readable($color_file)) } if (! is_array($theme_datacolor)) $theme_datacolor=array(array(120,130,150), array(200,160,180), array(190,190,220)); +// Add link to show birthdays $link=''; if (empty($showbirthday)) $link.=$langs->trans("AgendaShowBirthdayEvents"); @@ -392,17 +411,17 @@ if ($_GET["action"] != 'show_day') { /* Show days before the beginning of the current month (previous month) */ - if($day <= 0) + if($tmpday <= 0) { $style='cal_other_month'; echo ' '; - show_day_events ($db, $max_day_in_prev_month + $day, $prev_month, $prev_year, $style, $actionarray,3); + show_day_events ($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $style, $actionarray,3); echo " '; - show_day_events($db, $day, $month, $year, $style, $actionarray, 3); + show_day_events($db, $tmpday, $month, $year, $style, $actionarray, 3); echo " '; - show_day_events($db, $day - $max_day_in_month, $next_month, $next_year, $style, $actionarray, 3); + show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $style, $actionarray, 3); echo "
'.$action->getLibStatut(3); + print ''; + if ($action->type_code != 'BIRTHDAY') print $action->getLibStatut(3); + else print ' '; print '
'; $i++; } diff --git a/htdocs/contact.class.php b/htdocs/contact.class.php index 3b4bf9a40b4..40b6875a8ca 100644 --- a/htdocs/contact.class.php +++ b/htdocs/contact.class.php @@ -315,7 +315,7 @@ class Contact extends CommonObject } if ($user) $sql .= ", fk_user_modif=".$user->id; $sql .= " WHERE rowid=".$id; - + //print "update_perso: ".$this->birthday.'-'.$this->db->idate($this->birthday); dolibarr_syslog("Contact::update_perso this->birthday=".$this->birthday." - sql=".$sql); $resql = $this->db->query($sql); if (! $resql) @@ -423,9 +423,9 @@ class Contact extends CommonObject $this->mail = $obj->email; $this->birthday = dolibarr_stringtotime($obj->birthday); + //print "fetch: ".$obj->birthday.'-'.$this->birthday; $this->birthday_alert = $obj->birthday_alert; $this->note = $obj->note; - $this->user_id = $obj->user_id; $this->user_login = $obj->user_login; diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php index b9bc079b8ea..4df9e55ef54 100644 --- a/htdocs/contact/perso.php +++ b/htdocs/contact/perso.php @@ -47,7 +47,8 @@ if ($user->rights->societe->contact->creer) $contact = new Contact($db); $contact->fetch($_POST["contactid"]); - $contact->birthday = dolibarr_mktime(12,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]); + // Note: Correct date should be completed with location to have exact GM time of birth. + $contact->birthday = dolibarr_mktime(0,0,0,$_POST["birthdaymonth"],$_POST["birthdayday"],$_POST["birthdayyear"]); $contact->birthday_alert = $_POST["birthday_alert"]; $result = $contact->update_perso($_POST["contactid"], $user); @@ -193,7 +194,7 @@ else print ''; // Date To Birth - if ($contact->birthday) + if ($contact->birthday != '') { print ''.$langs->trans("DateToBirth").''.dolibarr_print_date($contact->birthday,"day"); print ' ('; diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php index 5778df29c69..62fe12f1315 100644 --- a/htdocs/lib/functions.lib.php +++ b/htdocs/lib/functions.lib.php @@ -404,13 +404,14 @@ function dolibarr_time_plus_duree($time,$duration_value,$duration_unit) /** * \brief Formattage de la date en fonction de la langue $conf->langage - * \param time Date 'timestamp' ou format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS' - * \param format Format d'affichage de la date + * \param time GM Timestamps date (or 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' in server TZ) + * \param format Output date format * "%d %b %Y", * "%d/%m/%Y %H:%M", * "%d/%m/%Y %H:%M:%S", * "day", "daytext", "dayhour", "dayhourldap", "dayhourtext" - * \return string Date formatee ou '' si time null + * \param to_gmt false=output string if for local server TZ users, true=output string is for GMT users + * \return string Formated date or '' if time is null */ function dolibarr_print_date($time,$format='',$to_gmt=false) { @@ -434,6 +435,8 @@ function dolibarr_print_date($time,$format='',$to_gmt=false) // Analyse de la date if (eregi('^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?',$time,$reg)) { + // This part of code should not be used. + dolibarr_syslog("Functions.lib::dolibarr_print_date call to function with deprecated parameter", LOG_WARN); // Date est au format 'YYYY-MM-DD' ou 'YYYY-MM-DD HH:MM:SS' $syear = $reg[1]; $smonth = $reg[2]; @@ -446,25 +449,28 @@ function dolibarr_print_date($time,$format='',$to_gmt=false) } else { - // Date est un timestamps + // Date is a timestamps return adodb_strftime($format,$time,$to_gmt); } } /** - * \brief Convert a string date into a TMS date + * \brief Convert a GM string date into a GM Timestamps date * \param string Date in a string * YYYYMMDD * YYYYMMDDHHMMSS * DD/MM/YY ou DD/MM/YYYY * DD/MM/YY HH:MM:SS ou DD/MM/YYYY HH:MM:SS * \return date Date + * \example 19700101020000 -> 7200 */ function dolibarr_stringtotime($string) { if (eregi('^([0-9]+)\/([0-9]+)\/([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?',$string,$reg)) { + // This part of code should not be used. + dolibarr_syslog("Functions.lib::dolibarr_stringtotime call to function with deprecated parameter", LOG_WARN); // Date est au format 'DD/MM/YY' ou 'DD/MM/YY HH:MM:SS' // Date est au format 'DD/MM/YYYY' ou 'DD/MM/YYYY HH:MM:SS' $sday = $reg[1]; @@ -480,39 +486,39 @@ function dolibarr_stringtotime($string) $string=eregi_replace('[^0-9]','',$string); $tmp=$string.'000000'; - $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4)); + $date=dolibarr_mktime(substr($tmp,8,2),substr($tmp,10,2),substr($tmp,12,2),substr($tmp,4,2),substr($tmp,6,2),substr($tmp,0,4),1); return $date; } /** - \brief Return an array with date info - \param timestamp Timestamp - \param fast Fast mode - \return array Array of informations - If no fast mode: - 'seconds' => $secs, - 'minutes' => $min, - 'hours' => $hour, - 'mday' => $day, - 'wday' => $dow, - 'mon' => $month, - 'year' => $year, - 'yday' => floor($secsInYear/$_day_power), - 'weekday' => gmdate('l',$_day_power*(3+$dow)), - 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), - 0 => $origd - If fast mode: - 'seconds' => $secs, - 'minutes' => $min, - 'hours' => $hour, - 'mday' => $day, - 'mon' => $month, - 'year' => $year, - 'yday' => floor($secsInYear/$_day_power), - 'leap' => $leaf, - 'ndays' => $ndays - \remarks PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows + * \brief Return an array with date info + * \param timestamp Timestamp + * \param fast Fast mode + * \return array Array of informations + * If no fast mode: + * 'seconds' => $secs, + * 'minutes' => $min, + * 'hours' => $hour, + * 'mday' => $day, + * 'wday' => $dow, + * 'mon' => $month, + * 'year' => $year, + * 'yday' => floor($secsInYear/$_day_power), + * 'weekday' => gmdate('l',$_day_power*(3+$dow)), + * 'month' => gmdate('F',mktime(0,0,0,$month,2,1971)), + * 0 => $origd + * If fast mode: + * 'seconds' => $secs, + * 'minutes' => $min, + * 'hours' => $hour, + * 'mday' => $day, + * 'mon' => $month, + * 'year' => $year, + * 'yday' => floor($secsInYear/$_day_power), + * 'leap' => $leaf, + * 'ndays' => $ndays + * \remarks PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows */ function dolibarr_getdate($timestamp,$fast=false) {