diff --git a/ChangeLog b/ChangeLog index 1d1f3a0720d..02224d73acd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -171,6 +171,7 @@ NEW: use more recent model by default NEW: VAT can be modified during add of line NEW: write all fields and their properties in asciidoc format NEW: Can add an array of several links in date selector +NEW: Implement MAIN_ACTIVATE_FILECACHE on bithday widget For developers or integrators: ------------------------------ diff --git a/htdocs/admin/system/perf.php b/htdocs/admin/system/perf.php index 10301bf3aed..052031acd14 100644 --- a/htdocs/admin/system/perf.php +++ b/htdocs/admin/system/perf.php @@ -627,6 +627,25 @@ if (!in_array($conf->browser->name, array('chrome', 'opera', 'safari', 'firefox' } print '
'; +// Options +print '
'; +print ''.$langs->trans("Options").':
'; +if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { + print 'MAIN_ACTIVATE_FILECACHE = '.getDolGlobalInt('MAIN_ACTIVATE_FILECACHE').' '.img_picto('', 'tick.png'); +} else { + print 'MAIN_ACTIVATE_FILECACHE = '.getDolGlobalInt('MAIN_ACTIVATE_FILECACHE', 0); + //.' '.img_picto('', 'warning.png'); +} +print '
'; + +if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { + print 'MAIN_ENABLE_AJAX_TOOLTIP = '.getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP').' '.img_picto('', 'tick.png'); +} else { + print 'MAIN_ENABLE_AJAX_TOOLTIP = '.getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP', 0); + //.' '.img_picto('', 'warning.png'); +} +print '
'; + // End of page llxFooter(); $db->close(); diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index ea45580e163..8fa2592811e 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -83,11 +83,12 @@ class box_activity extends ModeleBoxes $totalnb = 0; $line = 0; - $cachetime = 3600; - $fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'-r'.($user->hasRight("societe", "client", "voir") ? '1' : '0').'.cache'; $now = dol_now(); $nbofperiod = 3; + $cachetime = 3600; + $fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'-r'.($user->hasRight("societe", "client", "voir") ? '1' : '0').'.cache'; + if (!empty($conf->global->MAIN_BOX_ACTIVITY_DURATION)) { $nbofperiod = $conf->global->MAIN_BOX_ACTIVITY_DURATION; } @@ -134,12 +135,13 @@ class box_activity extends ModeleBoxes if ($result) { $num = $this->db->num_rows($result); - $j = 0; - while ($j < $num) { - $data[$j] = $this->db->fetch_object($result); - $j++; + $line = 0; + while ($line < $num) { + $data[$line] = $this->db->fetch_object($result); + + $line++; } - if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { + if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { dol_filecache($cachedir, $filename, $data); } $this->db->free($result); @@ -188,7 +190,7 @@ class box_activity extends ModeleBoxes if (count($data) == 0) { $this->info_box_contents[$line][0] = array( 'td' => 'class="center"', - 'text'=>$langs->trans("NoRecordedProposals"), + 'text'=>''.$langs->trans("NoRecordedProposals").'', ); $line++; } @@ -234,7 +236,7 @@ class box_activity extends ModeleBoxes $data[$j] = $this->db->fetch_object($result); $j++; } - if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { + if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { dol_filecache($cachedir, $filename, $data); } $this->db->free($result); @@ -329,7 +331,7 @@ class box_activity extends ModeleBoxes $data[$j] = $this->db->fetch_object($result); $j++; } - if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { + if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { dol_filecache($cachedir, $filename, $data); } $this->db->free($result); @@ -411,7 +413,7 @@ class box_activity extends ModeleBoxes $data[$j] = $this->db->fetch_object($result); $j++; } - if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) { + if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { dol_filecache($cachedir, $filename, $data); } $this->db->free($result); diff --git a/htdocs/core/boxes/box_birthdays.php b/htdocs/core/boxes/box_birthdays.php index 1f5c7e4add7..ce813deb351 100644 --- a/htdocs/core/boxes/box_birthdays.php +++ b/htdocs/core/boxes/box_birthdays.php @@ -71,96 +71,113 @@ class box_birthdays extends ModeleBoxes */ public function loadBox($max = 20) { - global $user, $langs; + global $conf, $user, $langs; + + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $langs->load("boxes"); $this->max = $max; + $cachetime = 3600; + $fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'.cache'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $userstatic = new User($this->db); $this->info_box_head = array('text' => $langs->trans("BoxTitleUserBirthdaysOfMonth")); - if ($user->rights->user->user->lire) { - $tmparray = dol_getdate(dol_now(), true); + if ($user->hasRight('user', 'user', 'lire')) { + $cachedir = DOL_DATA_ROOT.'/users/temp'; + $filename = '/boxbirthdays-'.$fileid; + $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); + $data = array(); + if ($refresh) { + $tmparray = dol_getdate(dol_now(), true); - $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, date_format(u.birth, '%d') as daya, 'birth' as typea, u.email, u.statut as status"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE u.entity IN (".getEntity('user').")"; - $sql .= " AND u.statut = ".User::STATUS_ENABLED; - $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); - $sql .= ' UNION '; - $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, date_format(u.dateemployment, '%d') as daya, 'employment' as typea, u.email, u.statut as status"; - $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql .= " WHERE u.entity IN (".getEntity('user').")"; - $sql .= " AND u.statut = ".User::STATUS_ENABLED; - $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0); - $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year - $sql .= $this->db->plimit($max, 0); + $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth as datea, date_format(u.birth, '%d') as daya, 'birth' as typea, u.email, u.statut as status"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE u.entity IN (".getEntity('user').")"; + $sql .= " AND u.statut = ".User::STATUS_ENABLED; + $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); + $sql .= ' UNION '; + $sql .= "SELECT u.rowid, u.firstname, u.lastname, u.dateemployment as datea, date_format(u.dateemployment, '%d') as daya, 'employment' as typea, u.email, u.statut as status"; + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; + $sql .= " WHERE u.entity IN (".getEntity('user').")"; + $sql .= " AND u.statut = ".User::STATUS_ENABLED; + $sql .= dolSqlDateFilter('u.dateemployment', 0, $tmparray['mon'], 0); + $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year + $sql .= $this->db->plimit($max, 0); - dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $num = $this->db->num_rows($result); + dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); - $line = 0; - while ($line < $num) { - $objp = $this->db->fetch_object($result); + $line = 0; + while ($line < $num) { + $data[$line] = $this->db->fetch_object($resql); - $userstatic->id = $objp->rowid; - $userstatic->firstname = $objp->firstname; - $userstatic->lastname = $objp->lastname; - $userstatic->email = $objp->email; - $userstatic->statut = $objp->status; + $line++; + } - $dateb = $this->db->jdate($objp->datea); + if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { + dol_filecache($cachedir, $filename, $data); + } + + $this->db->free($resql); + } + } else { + $data = dol_readcachefile($cachedir, $filename); + } + + if (!empty($data)) { + $j = 0; + while ($j < count($data)) { + $userstatic->id = $data[$j]->rowid; + $userstatic->firstname = $data[$j]->firstname; + $userstatic->lastname = $data[$j]->lastname; + $userstatic->email = $data[$j]->email; + $userstatic->statut = $data[$j]->status; + + $dateb = $this->db->jdate($data[$j]->datea); $age = date('Y', dol_now()) - date('Y', $dateb); $picb = ''; $pice = ''; - $typea = ($objp->typea == 'birth') ? $picb : $pice; + $typea = ($data[$j]->typea == 'birth') ? $picb : $pice; - $this->info_box_contents[$line][] = array( + $this->info_box_contents[$j][0] = array( 'td' => '', 'text' => $userstatic->getNomUrl(1), 'asis' => 1, ); - $this->info_box_contents[$line][] = array( + $this->info_box_contents[$j][1] = array( 'td' => 'class="center nowraponall"', 'text' => dol_print_date($dateb, "day", 'tzserver') ); - $this->info_box_contents[$line][] = array( + $this->info_box_contents[$j][2] = array( 'td' => 'class="right nowraponall"', 'text' => $age.' '.$langs->trans('DurationYears') ); - $this->info_box_contents[$line][] = array( - 'td' => 'class="center nowraponall"', + $this->info_box_contents[$j][3] = array( + 'td' => 'class="right nowraponall"', 'text' => $typea, 'asis' => 1 ); - /*$this->info_box_contents[$line][] = array( - 'td' => 'class="right" width="18"', - 'text' => $userstatic->LibStatut($objp->status, 3) - );*/ - - $line++; + $j++; } - - if ($num == 0) { - $this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => ''.$langs->trans("None").''); - } - - $this->db->free($result); - } else { + } + if (is_array($data) && count($data) == 0) { $this->info_box_contents[0][0] = array( - 'td' => '', - 'maxlength'=>500, - 'text' => ($this->db->error().' sql='.$sql) + 'td' => 'class="center"', + 'text' => ''.$langs->trans("None").'', ); } } else { diff --git a/htdocs/core/boxes/box_birthdays_members.php b/htdocs/core/boxes/box_birthdays_members.php index 2a66a533e03..7f17e74302d 100644 --- a/htdocs/core/boxes/box_birthdays_members.php +++ b/htdocs/core/boxes/box_birthdays_members.php @@ -71,84 +71,108 @@ class box_birthdays_members extends ModeleBoxes */ public function loadBox($max = 20) { - global $user, $langs; + global $conf, $user, $langs; + + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $langs->load("boxes"); $this->max = $max; + $cachetime = 3600; + $fileid = '-e'.$conf->entity.'-u'.$user->id.'-s'.$user->socid.'.cache'; + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $memberstatic = new Adherent($this->db); $this->info_box_head = array('text' => $langs->trans("BoxTitleMemberNextBirthdays")); - if ($user->rights->adherent->lire) { - $tmparray = dol_getdate(dol_now(), true); + if ($user->hasRight('adherent', 'lire')) { + $cachedir = DOL_DATA_ROOT.'/users/temp'; + $filename = '/boxbirthdays-members'.$fileid; + $refresh = dol_cache_refresh($cachedir, $filename, $cachetime); + $data = array(); + if ($refresh) { + $tmparray = dol_getdate(dol_now(), true); - $sql = "SELECT u.rowid, u.firstname, u.lastname, u.birth, date_format(u.birth, '%d') as daya, u.email, u.statut as status, u.datefin"; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u"; - $sql .= " WHERE u.entity IN (".getEntity('adherent').")"; - $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED; - $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); - $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year - $sql .= $this->db->plimit($max, 0); + $sql = "SELECT u.rowid, u.firstname, u.lastname, u.societe, u.birth, date_format(u.birth, '%d') as daya, u.email, u.statut as status, u.datefin"; + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as u"; + $sql .= " WHERE u.entity IN (".getEntity('adherent').")"; + $sql .= " AND u.statut = ".Adherent::STATUS_VALIDATED; + $sql .= dolSqlDateFilter('u.birth', 0, $tmparray['mon'], 0); + $sql .= " ORDER BY daya ASC"; // We want to have date of the month sorted by the day without taking into consideration the year + $sql .= $this->db->plimit($max, 0); - dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result) { - $num = $this->db->num_rows($result); + dol_syslog(get_class($this)."::loadBox", LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); - $line = 0; - while ($line < $num) { - $objp = $this->db->fetch_object($result); - $memberstatic->id = $objp->rowid; - $memberstatic->firstname = $objp->firstname; - $memberstatic->lastname = $objp->lastname; - $memberstatic->email = $objp->email; - $memberstatic->status = $objp->status; - $memberstatic->statut = $memberstatic->status; - $memberstatic->datefin = $this->db->jdate($objp->datefin); - //$memberstatic->need_subscription = 1; - $dateb = $this->db->jdate($objp->birth); + $line = 0; + while ($line < $num) { + $data[$line] = $this->db->fetch_object($resql); + + $line++; + } + + if (getDolGlobalInt('MAIN_ACTIVATE_FILECACHE')) { + dol_filecache($cachedir, $filename, $data); + } + + $this->db->free($resql); + } + } else { + $data = dol_readcachefile($cachedir, $filename); + } + + if (!empty($data)) { + $j = 0; + while ($j < count($data)) { + $memberstatic->id = $data[$j]->rowid; + $memberstatic->firstname = $data[$j]->firstname; + $memberstatic->lastname = $data[$j]->lastname; + $memberstatic->company = $data[$j]->societe; + $memberstatic->email = $data[$j]->email; + $memberstatic->status = $data[$j]->status; + $memberstatic->statut = $data[$j]->status; + $memberstatic->datefin = $this->db->jdate($data[$j]->datefin); + + $dateb = $this->db->jdate($data[$j]->birth); $age = date('Y', dol_now()) - date('Y', $dateb); $typea = ''; - $this->info_box_contents[$line][] = array( + $this->info_box_contents[$j][0] = array( 'td' => '', 'text' => $memberstatic->getNomUrl(1), 'asis' => 1, ); - $this->info_box_contents[$line][] = array( + $this->info_box_contents[$j][1] = array( 'td' => 'class="center nowraponall"', 'text' => dol_print_date($dateb, "day", 'tzserver').' - '.$age.' '.$langs->trans('DurationYears') ); - $this->info_box_contents[$line][] = array( - 'td' => 'class="center nowraponall"', + $this->info_box_contents[$j][2] = array( + 'td' => 'class="right nowraponall"', 'text' => $typea, 'asis' => 1 ); - /*$this->info_box_contents[$line][] = array( - 'td' => 'class="right" width="18"', - 'text' => $memberstatic->LibStatut($objp->status, 3) - );*/ + /*$this->info_box_contents[$j][3] = array( + 'td' => 'class="right" width="18"', + 'text' => $memberstatic->LibStatut($objp->status, 3) + );*/ - $line++; + $j++; } - - if ($num == 0) { - $this->info_box_contents[$line][0] = array('td' => 'class="center"', 'text' => ''.$langs->trans("None").''); - } - - $this->db->free($result); - } else { + } + if (is_array($data) && count($data) == 0) { $this->info_box_contents[0][0] = array( - 'td' => '', - 'maxlength'=>500, - 'text' => ($this->db->error().' sql='.$sql) + 'td' => 'class="center"', + 'text' => ''.$langs->trans("None").'', ); } } else { diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e246e8ade73..f3d3fd98062 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -719,7 +719,7 @@ abstract class CommonObject } /** - * getTooltipContentArray + * Return array of datas to show into a tooltip. This method must be implemented in each object class. * * @since v18 * @param array $params params to construct tooltip data diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index dbfe56034ad..7de32471c1b 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3342,9 +3342,9 @@ function dol_cache_refresh($directory, $filename, $cachetime) /** * Read object from cachefile. * - * @param string $directory Directory of cache - * @param string $filename Name of filecache - * @return mixed Unserialise from file + * @param string $directory Directory of cache + * @param string $filename Name of filecache + * @return mixed Unserialise from file */ function dol_readcachefile($directory, $filename) { diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index ced127036b7..2901efda215 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -2746,7 +2746,7 @@ class User extends CommonObject } /** - * getTooltipContentArray + * Return array of data to show into tooltips * * @param array $params ex option, infologin * @since v18