box_actions_future.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2014 Charles-Fr BENKE <charles.fr@benke.fr>
  6. * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/core/boxes/box_actions_future.php
  23. * \ingroup actions
  24. * \brief Module to build boxe for events
  25. */
  26. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  27. /**
  28. * Class to manage the box to show events in future
  29. */
  30. class box_actions_future extends ModeleBoxes
  31. {
  32. public $boxcode = "futureactions";
  33. public $boximg = "object_action";
  34. public $boxlabel = "BoxTitleFutureActions";
  35. public $depends = array("agenda");
  36. /**
  37. * @var DoliDB Database handler.
  38. */
  39. public $db;
  40. public $enabled = 1;
  41. public $info_box_head = array();
  42. public $info_box_contents = array();
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. * @param string $param More parameters
  48. */
  49. public function __construct($db, $param)
  50. {
  51. global $user;
  52. $this->db = $db;
  53. $this->enabled = isModEnabled('agenda');
  54. $this->hidden = !($user->hasRight('agenda', 'myactions', 'read'));
  55. }
  56. /**
  57. * Load data for box to show them later
  58. *
  59. * @param int $max Maximum number of records to load
  60. * @return void
  61. */
  62. public function loadBox($max = 5)
  63. {
  64. global $user, $langs, $conf;
  65. $this->max = $max;
  66. $now = dol_now();
  67. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  68. include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  69. $societestatic = new Societe($this->db);
  70. $actionstatic = new ActionComm($this->db);
  71. $this->info_box_head = array('text' => $langs->trans("BoxTitleFutureActions", $max));
  72. if ($user->hasRight('agenda', 'myactions', 'read')) {
  73. $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
  74. $sql .= ", ta.code";
  75. $sql .= ", ta.libelle as type_label";
  76. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  77. $sql .= ", s.code_client, s.code_compta, s.client";
  78. $sql .= ", s.logo, s.email, s.entity";
  79. $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
  80. if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
  81. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  82. }
  83. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
  84. $sql .= " WHERE a.fk_action = ta.id";
  85. $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
  86. //$sql .= " AND a.percent >= 0 AND a.percent < 100";
  87. if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
  88. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
  89. }
  90. if ($user->socid) {
  91. $sql .= " AND s.rowid = ".((int) $user->socid);
  92. }
  93. if (!$user->hasRight('agenda', 'allactions', 'read')) {
  94. $sql .= " AND (a.fk_user_author = ".((int) $user->id)." OR a.fk_user_action = ".((int) $user->id)." OR a.fk_user_done = ".((int) $user->id).")";
  95. }
  96. $sql .= " AND a.datep > '".$this->db->idate($now)."'";
  97. $sql .= " ORDER BY a.datep ASC";
  98. $sql .= $this->db->plimit($max, 0);
  99. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  100. $result = $this->db->query($sql);
  101. if ($result) {
  102. $now = dol_now();
  103. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  104. $num = $this->db->num_rows($result);
  105. $line = 0;
  106. while ($line < $num) {
  107. $late = '';
  108. $objp = $this->db->fetch_object($result);
  109. $datelimite = $this->db->jdate($objp->dp);
  110. $actionstatic->id = $objp->id;
  111. $actionstatic->label = $objp->label;
  112. $actionstatic->type_label = $objp->type_label;
  113. $actionstatic->code = $objp->code;
  114. $societestatic->id = $objp->socid;
  115. $societestatic->name = $objp->name;
  116. //$societestatic->name_alias = $objp->name_alias;
  117. $societestatic->code_client = $objp->code_client;
  118. $societestatic->code_compta = $objp->code_compta;
  119. $societestatic->client = $objp->client;
  120. $societestatic->logo = $objp->logo;
  121. $societestatic->email = $objp->email;
  122. $societestatic->entity = $objp->entity;
  123. if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
  124. $late = img_warning($langs->trans("Late"));
  125. }
  126. //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
  127. //$label = empty($objp->label) ? $objp->type_label : $objp->label;
  128. $this->info_box_contents[$line][0] = array(
  129. 'td' => 'class="tdoverflowmax200"',
  130. 'text' => $actionstatic->getNomUrl(1),
  131. 'text2'=> $late,
  132. 'asis' => 1
  133. );
  134. $this->info_box_contents[$line][1] = array(
  135. 'td' => 'class="tdoverflowmax100"',
  136. 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
  137. 'asis' => 1
  138. );
  139. $this->info_box_contents[$line][2] = array(
  140. 'td' => 'class="center nowraponall"',
  141. 'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
  142. 'asis' => 1
  143. );
  144. $this->info_box_contents[$line][3] = array(
  145. 'td' => 'class="right"',
  146. 'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
  147. 'asis' => 1
  148. );
  149. $this->info_box_contents[$line][4] = array(
  150. 'td' => 'class="right" width="18"',
  151. 'text' => $actionstatic->LibStatut($objp->percentage, 3),
  152. 'asis' => 1
  153. );
  154. $line++;
  155. }
  156. if ($num == 0) {
  157. $this->info_box_contents[$line][0] = array(
  158. 'td' => 'class="center"',
  159. 'text'=> '<span class="opacitymedium">'.$langs->trans("NoActionsToDo").'</span>'
  160. );
  161. }
  162. $this->db->free($result);
  163. } else {
  164. $this->info_box_contents[0][0] = array(
  165. 'td' => '',
  166. 'maxlength'=>500,
  167. 'text' => ($this->db->error().' sql='.$sql)
  168. );
  169. }
  170. } else {
  171. $this->info_box_contents[0][0] = array(
  172. 'td' => 'class="nohover left"',
  173. 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
  174. );
  175. }
  176. }
  177. /**
  178. * Method to show box
  179. *
  180. * @param array $head Array with properties of box title
  181. * @param array $contents Array with properties of box lines
  182. * @param int $nooutput No print, only return string
  183. * @return string
  184. */
  185. public function showBox($head = null, $contents = null, $nooutput = 0)
  186. {
  187. global $langs, $conf;
  188. $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
  189. if (getDolGlobalString('SHOW_DIALOG_HOMEPAGE')) {
  190. $actioncejour = false;
  191. $contents = $this->info_box_contents;
  192. if (is_countable($contents) && count($contents) > 0) {
  193. $nblines = count($contents);
  194. }
  195. if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
  196. $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
  197. $out .= '<table width=100%>';
  198. for ($line = 0, $n = $nblines; $line < $n; $line++) {
  199. if (isset($contents[$line])) {
  200. // on affiche que les évènement du jours ou passé
  201. // qui ne sont pas à 100%
  202. $actioncejour = true;
  203. // TR
  204. $logo = $contents[$line][0]['logo'];
  205. $label = $contents[$line][1]['text'];
  206. $urlevent = $contents[$line][1]['url'];
  207. $logosoc = $contents[$line][2]['logo'];
  208. $nomsoc = $contents[$line][3]['text'];
  209. $urlsoc = $contents[$line][3]['url'];
  210. $dateligne = $contents[$line][4]['text'];
  211. $percentage = $contents[$line][5]['text'];
  212. $out .= '<tr class="oddeven">';
  213. $out .= '<td class="center">';
  214. $out .= img_object("", $logo);
  215. $out .= '</td>';
  216. $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
  217. $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
  218. $out .= '<td class="center">'.$dateligne.'</td>';
  219. $out .= '<td class="center">'.$percentage.'</td>';
  220. $out .= '</tr>';
  221. }
  222. }
  223. $out .= '</table>';
  224. }
  225. $out .= '</div>';
  226. if ($actioncejour) {
  227. $out .= '<script nonce="'.getNonce().'">';
  228. $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
  229. if (getDolGlobalInt('SHOW_DIALOG_HOMEPAGE') > 1) { // autoclose after this delay
  230. $out .= 'setTimeout(function(){';
  231. $out .= '$("#dialogboxaction").dialog("close");';
  232. $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
  233. }
  234. $out .= '</script>';
  235. } else {
  236. $out .= '<script nonce="'.getNonce().'">';
  237. $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
  238. $out .= '</script>';
  239. }
  240. }
  241. if ($nooutput) {
  242. return $out;
  243. } else {
  244. print $out;
  245. }
  246. return '';
  247. }
  248. }