box_actions.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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@capnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/core/boxes/box_actions.php
  21. * \ingroup actions
  22. * \brief Module to build boxe for events
  23. */
  24. include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
  25. /**
  26. * Class to manage the box to show last events
  27. */
  28. class box_actions extends ModeleBoxes
  29. {
  30. var $boxcode="lastactions";
  31. var $boximg="object_action";
  32. var $boxlabel="BoxLastActions";
  33. var $depends = array("agenda");
  34. var $db;
  35. var $param;
  36. var $info_box_head = array();
  37. var $info_box_contents = array();
  38. /**
  39. * Load data for box to show them later
  40. *
  41. * @param int $max Maximum number of records to load
  42. * @return void
  43. */
  44. function loadBox($max=5)
  45. {
  46. global $user, $langs, $db, $conf;
  47. $this->max=$max;
  48. include_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  49. $actionstatic=new ActionComm($db);
  50. $this->info_box_head = array('text' => $langs->trans("BoxTitleLastActionsToDo",$max));
  51. if ($user->rights->agenda->myactions->read)
  52. {
  53. $sql = "SELECT a.id, a.label, a.datep as dp, a.percent as percentage,";
  54. $sql.= " ta.code,";
  55. $sql.= " s.nom, s.rowid as socid";
  56. $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm AS ta, ";
  57. $sql.= MAIN_DB_PREFIX."actioncomm AS a)";
  58. if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  59. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
  60. $sql.= " WHERE a.fk_action = ta.id";
  61. $sql.= " AND a.entity = ".$conf->entity;
  62. $sql.= " AND a.percent >= 0 AND a.percent < 100";
  63. if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")";
  64. if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
  65. if (! $user->rights->agenda->allactions->read) $sql.= " AND (a.fk_user_author = ".$user->id . " OR a.fk_user_action = ".$user->id . " OR a.fk_user_done = ".$user->id . ")";
  66. $sql.= " ORDER BY a.datec DESC";
  67. $sql.= $db->plimit($max, 0);
  68. dol_syslog("Box_actions::loadBox sql=".$sql, LOG_DEBUG);
  69. $result = $db->query($sql);
  70. if ($result)
  71. {
  72. $now=dol_now();
  73. $delay_warning=$conf->global->MAIN_DELAY_ACTIONS_TODO*24*60*60;
  74. $num = $db->num_rows($result);
  75. $i = 0;
  76. while ($i < $num)
  77. {
  78. $late = '';
  79. $objp = $db->fetch_object($result);
  80. $datelimite=$db->jdate($objp->dp);
  81. if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) $late=img_warning($langs->trans("Late"));
  82. //($langs->transnoentities("Action".$objp->code)!=("Action".$objp->code) ? $langs->transnoentities("Action".$objp->code) : $objp->label)
  83. $label=$objp->label;
  84. $this->info_box_contents[$i][0] = array('td' => 'align="left" width="16"',
  85. 'logo' => ("action"),
  86. 'url' => DOL_URL_ROOT."/comm/action/fiche.php?id=".$objp->id);
  87. $this->info_box_contents[$i][1] = array('td' => 'align="left"',
  88. 'text' => dol_trunc($label,32),
  89. 'text2'=> $late,
  90. 'url' => DOL_URL_ROOT."/comm/action/fiche.php?id=".$objp->id);
  91. $this->info_box_contents[$i][2] = array('td' => 'align="left" width="16"',
  92. 'logo' => ($objp->socid?'company':''),
  93. 'url' => ($objp->socid?DOL_URL_ROOT."/societe/soc.php?socid=".$objp->socid:''));
  94. $this->info_box_contents[$i][3] = array('td' => 'align="left"',
  95. 'text' => dol_trunc($objp->nom,24),
  96. 'url' => DOL_URL_ROOT."/societe/soc.php?socid=".$objp->socid);
  97. $this->info_box_contents[$i][4] = array('td' => 'align="left" class="nowrap"',
  98. 'text' => dol_print_date($datelimite, "dayhour"));
  99. $this->info_box_contents[$i][5] = array('td' => 'align="right"',
  100. 'text' => ($objp->percentage>= 0?$objp->percentage.'%':''));
  101. $this->info_box_contents[$i][6] = array('td' => 'align="right" width="18"',
  102. 'text' => $actionstatic->LibStatut($objp->percentage,3));
  103. $i++;
  104. }
  105. if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoActionsToDo"));
  106. $db->free($result);
  107. }
  108. else {
  109. $this->info_box_contents[0][0] = array( 'td' => 'align="left"',
  110. 'maxlength'=>500,
  111. 'text' => ($db->error().' sql='.$sql));
  112. }
  113. }
  114. else {
  115. $this->info_box_contents[0][0] = array('align' => 'left',
  116. 'text' => $langs->trans("ReadPermissionNotAllowed"));
  117. }
  118. }
  119. /**
  120. * Method to show box
  121. *
  122. * @param array $head Array with properties of box title
  123. * @param array $contents Array with properties of box lines
  124. * @return void
  125. */
  126. function showBox($head = null, $contents = null)
  127. {
  128. parent::showBox($this->info_box_head, $this->info_box_contents);
  129. }
  130. }