box_actions.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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.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 last events
  29. */
  30. class box_actions extends ModeleBoxes
  31. {
  32. public $boxcode = "lastactions";
  33. public $boximg = "object_action";
  34. public $boxlabel = "BoxOldestActions";
  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. include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  67. include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  68. $societestatic = new Societe($this->db);
  69. $actionstatic = new ActionComm($this->db);
  70. $this->info_box_head = array('text' => $langs->trans("BoxTitleOldestActionsToDo", $max));
  71. if ($user->hasRight('agenda', 'myactions', 'read')) {
  72. $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
  73. $sql .= ", ta.code";
  74. $sql .= ", ta.libelle as type_label";
  75. $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
  76. $sql .= ", s.code_client, s.code_compta, s.client";
  77. $sql .= ", s.logo, s.email, s.entity";
  78. $sql .= " FROM ".MAIN_DB_PREFIX."c_actioncomm AS ta, ".MAIN_DB_PREFIX."actioncomm AS a";
  79. if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
  80. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  81. }
  82. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
  83. $sql .= " WHERE a.fk_action = ta.id";
  84. $sql .= " AND a.entity IN (".getEntity('actioncomm').")";
  85. $sql .= " AND a.percent >= 0 AND a.percent < 100";
  86. if (!$user->hasRight('societe', 'client', 'voir') && !$user->socid) {
  87. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
  88. }
  89. if ($user->socid) {
  90. $sql .= " AND s.rowid = ".((int) $user->socid);
  91. }
  92. if (!$user->hasRight('agenda', 'allactions', 'read')) {
  93. $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).")";
  94. }
  95. $sql .= " ORDER BY a.datep ASC";
  96. $sql .= $this->db->plimit($max, 0);
  97. dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
  98. $result = $this->db->query($sql);
  99. if ($result) {
  100. $now = dol_now();
  101. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  102. $num = $this->db->num_rows($result);
  103. $line = 0;
  104. while ($line < $num) {
  105. $late = '';
  106. $objp = $this->db->fetch_object($result);
  107. $datelimite = $this->db->jdate($objp->dp);
  108. $actionstatic->id = $objp->id;
  109. $actionstatic->label = $objp->label;
  110. $actionstatic->type_label = $objp->type_label;
  111. $actionstatic->code = $objp->code;
  112. $societestatic->id = $objp->socid;
  113. $societestatic->name = $objp->name;
  114. //$societestatic->name_alias = $objp->name_alias;
  115. $societestatic->code_client = $objp->code_client;
  116. $societestatic->code_compta = $objp->code_compta;
  117. $societestatic->client = $objp->client;
  118. $societestatic->logo = $objp->logo;
  119. $societestatic->email = $objp->email;
  120. $societestatic->entity = $objp->entity;
  121. if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
  122. $late = img_warning($langs->trans("Late"));
  123. }
  124. //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
  125. //$label = empty($objp->label) ? $objp->type_label : $objp->label;
  126. $this->info_box_contents[$line][0] = array(
  127. 'td' => 'class="tdoverflowmax200"',
  128. 'text' => $actionstatic->getNomUrl(1),
  129. 'text2'=> $late,
  130. 'asis' => 1
  131. );
  132. $this->info_box_contents[$line][1] = array(
  133. 'td' => 'class="tdoverflowmax100"',
  134. 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) : ''),
  135. 'asis' => 1
  136. );
  137. $this->info_box_contents[$line][2] = array(
  138. 'td' => 'class="center nowraponall"',
  139. 'text' => $datelimite ? dol_print_date($datelimite, "dayhour", 'tzuserrel') : '',
  140. 'asis' => 1
  141. );
  142. $this->info_box_contents[$line][3] = array(
  143. 'td' => 'class="right"',
  144. 'text' => ($objp->percentage >= 0 ? $objp->percentage.'%' : ''),
  145. 'asis' => 1
  146. );
  147. $this->info_box_contents[$line][4] = array(
  148. 'td' => 'class="right" width="18"',
  149. 'text' => $actionstatic->LibStatut($objp->percentage, 3),
  150. 'asis' => 1
  151. );
  152. $line++;
  153. }
  154. if ($num == 0) {
  155. $this->info_box_contents[$line][0] = array(
  156. 'td' => 'class="center opacitymedium"',
  157. 'text'=>$langs->trans("NoActionsToDo")
  158. );
  159. }
  160. $this->db->free($result);
  161. } else {
  162. $this->info_box_contents[0][0] = array(
  163. 'td' => '',
  164. 'maxlength'=>500,
  165. 'text' => ($this->db->error().' sql='.$sql)
  166. );
  167. }
  168. } else {
  169. $this->info_box_contents[0][0] = array(
  170. 'td' => 'class="nohover opacitymedium left"',
  171. 'text' => $langs->trans("ReadPermissionNotAllowed")
  172. );
  173. }
  174. }
  175. /**
  176. * Method to show box
  177. *
  178. * @param array $head Array with properties of box title
  179. * @param array $contents Array with properties of box lines
  180. * @param int $nooutput No print, only return string
  181. * @return string
  182. */
  183. public function showBox($head = null, $contents = null, $nooutput = 0)
  184. {
  185. global $langs, $conf;
  186. $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
  187. if (!empty($conf->global->SHOW_DIALOG_HOMEPAGE)) {
  188. $actioncejour = false;
  189. $contents = $this->info_box_contents;
  190. if (is_countable($contents) && count($contents) > 0) {
  191. $nblines = count($contents);
  192. }
  193. if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) {
  194. $out .= '<div id="dialogboxaction" title="'.$nblines." ".$langs->trans("ActionsToDo").'">';
  195. $out .= '<table width=100%>';
  196. for ($line = 0, $n = $nblines; $line < $n; $line++) {
  197. if (isset($contents[$line])) {
  198. // on affiche que les évènement du jours ou passé
  199. // qui ne sont pas à 100%
  200. $actioncejour = true;
  201. // TR
  202. $logo = $contents[$line][0]['logo'];
  203. $label = $contents[$line][1]['text'];
  204. $urlevent = $contents[$line][1]['url'];
  205. $logosoc = $contents[$line][2]['logo'];
  206. $nomsoc = $contents[$line][3]['text'];
  207. $urlsoc = $contents[$line][3]['url'];
  208. $dateligne = $contents[$line][4]['text'];
  209. $percentage = $contents[$line][5]['text'];
  210. $out .= '<tr class="oddeven">';
  211. $out .= '<td class="center">';
  212. $out .= img_object("", $logo);
  213. $out .= '</td>';
  214. $out .= '<td class="center"><a href="'.$urlevent.'">'.$label.'</a></td>';
  215. $out .= '<td class="center"><a href="'.$urlsoc.'">'.img_object("", $logosoc)." ".$nomsoc.'</a></td>';
  216. $out .= '<td class="center">'.$dateligne.'</td>';
  217. $out .= '<td class="center">'.$percentage.'</td>';
  218. $out .= '</tr>';
  219. }
  220. }
  221. $out .= '</table>';
  222. }
  223. $out .= '</div>';
  224. if ($actioncejour) {
  225. $out .= '<script nonce="'.getNonce().'">';
  226. $out .= '$("#dialogboxaction").dialog({ autoOpen: true });';
  227. if ($conf->global->SHOW_DIALOG_HOMEPAGE > 1) { // autoclose after this delay
  228. $out .= 'setTimeout(function(){';
  229. $out .= '$("#dialogboxaction").dialog("close");';
  230. $out .= '}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).');';
  231. }
  232. $out .= '</script>';
  233. } else {
  234. $out .= '<script nonce="'.getNonce().'">';
  235. $out .= '$("#dialogboxaction").dialog({ autoOpen: false });';
  236. $out .= '</script>';
  237. }
  238. }
  239. if ($nooutput) {
  240. return $out;
  241. } else {
  242. print $out;
  243. }
  244. return '';
  245. }
  246. }