28 include_once DOL_DOCUMENT_ROOT.
'/core/boxes/modules_boxes.php';
35 public $boxcode =
"lastactions";
36 public $boximg =
"object_action";
37 public $boxlabel =
"BoxOldestActions";
38 public $depends = array(
"agenda");
47 public $info_box_head = array();
48 public $info_box_contents = array();
63 $this->enabled = $conf->agenda->enabled;
65 $this->hidden = !($user->hasRight(
'agenda',
'myactions',
'read'));
76 global $user, $langs, $conf;
80 include_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
81 include_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
85 $this->info_box_head = array(
'text' => $langs->trans(
"BoxTitleOldestActionsToDo", $max));
87 if ($user->rights->agenda->myactions->read) {
88 $sql =
"SELECT a.id, a.label, a.datep as dp, a.percent as percentage";
90 $sql .=
", ta.libelle as type_label";
91 $sql .=
", s.rowid as socid, s.nom as name, s.name_alias";
92 $sql .=
", s.code_client, s.code_compta, s.client";
93 $sql .=
", s.logo, s.email, s.entity";
94 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_actioncomm AS ta, ".MAIN_DB_PREFIX.
"actioncomm AS a";
95 if (empty($user->rights->societe->client->voir) && !$user->socid) {
96 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
98 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON a.fk_soc = s.rowid";
99 $sql .=
" WHERE a.fk_action = ta.id";
100 $sql .=
" AND a.entity IN (".getEntity(
'actioncomm').
")";
101 $sql .=
" AND a.percent >= 0 AND a.percent < 100";
102 if (empty($user->rights->societe->client->voir) && !$user->socid) {
103 $sql .=
" AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).
")";
106 $sql .=
" AND s.rowid = ".((int) $user->socid);
108 if (empty($user->rights->agenda->allactions->read)) {
109 $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).
")";
111 $sql .=
" ORDER BY a.datep ASC";
112 $sql .= $this->
db->plimit($max, 0);
114 dol_syslog(get_class($this).
"::loadBox", LOG_DEBUG);
115 $result = $this->
db->query($sql);
118 $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
120 $num = $this->
db->num_rows($result);
123 while ($line < $num) {
125 $objp = $this->
db->fetch_object($result);
126 $datelimite = $this->
db->jdate($objp->dp);
128 $actionstatic->id = $objp->id;
129 $actionstatic->label = $objp->label;
130 $actionstatic->type_label = $objp->type_label;
131 $actionstatic->code = $objp->code;
133 $societestatic->id = $objp->socid;
134 $societestatic->name = $objp->name;
136 $societestatic->code_client = $objp->code_client;
137 $societestatic->code_compta = $objp->code_compta;
138 $societestatic->client = $objp->client;
139 $societestatic->logo = $objp->logo;
140 $societestatic->email = $objp->email;
141 $societestatic->entity = $objp->entity;
143 if ($objp->percentage >= 0 && $objp->percentage < 100 && $datelimite < ($now - $delay_warning)) {
148 $label = empty($objp->label) ? $objp->type_label : $objp->label;
150 $this->info_box_contents[$line][0] = array(
151 'td' =>
'class="tdoverflowmax200"',
152 'text' => $actionstatic->getNomUrl(1),
157 $this->info_box_contents[$line][1] = array(
158 'td' =>
'class="tdoverflowmax100"',
159 'text' => ($societestatic->id > 0 ? $societestatic->getNomUrl(1) :
''),
163 $this->info_box_contents[$line][2] = array(
164 'td' =>
'class="center nowraponall"',
165 'text' => $datelimite ?
dol_print_date($datelimite,
"dayhour",
'tzuserrel') :
'',
169 $this->info_box_contents[$line][3] = array(
170 'td' =>
'class="right"',
171 'text' => ($objp->percentage >= 0 ? $objp->percentage.
'%' :
''),
175 $this->info_box_contents[$line][4] = array(
176 'td' =>
'class="right" width="18"',
177 'text' => $actionstatic->LibStatut($objp->percentage, 3),
185 $this->info_box_contents[$line][0] = array(
186 'td' =>
'class="center opacitymedium"',
187 'text'=>$langs->trans(
"NoActionsToDo")
191 $this->
db->free($result);
193 $this->info_box_contents[0][0] = array(
196 'text' => ($this->
db->error().
' sql='.$sql)
200 $this->info_box_contents[0][0] = array(
201 'td' =>
'class="nohover opacitymedium left"',
202 'text' => $langs->trans(
"ReadPermissionNotAllowed")
215 public function showBox($head =
null, $contents =
null, $nooutput = 0)
217 global $langs, $conf;
218 $out = parent::showBox($this->info_box_head, $this->info_box_contents, 1);
220 if (!empty($conf->global->SHOW_DIALOG_HOMEPAGE)) {
221 $actioncejour =
false;
222 $contents = $this->info_box_contents;
223 if (is_countable($contents) && count($contents) > 0) {
224 $nblines = count($contents);
226 if ($contents[0][0][
'text'] != $langs->trans(
"NoActionsToDo")) {
227 $out .=
'<div id="dialogboxaction" title="'.$nblines.
" ".$langs->trans(
"ActionsToDo").
'">';
228 $out .=
'<table width=100%>';
229 for ($line = 0, $n = $nblines; $line < $n; $line++) {
230 if (isset($contents[$line])) {
233 $actioncejour =
true;
236 $logo = $contents[$line][0][
'logo'];
237 $label = $contents[$line][1][
'text'];
238 $urlevent = $contents[$line][1][
'url'];
239 $logosoc = $contents[$line][2][
'logo'];
240 $nomsoc = $contents[$line][3][
'text'];
241 $urlsoc = $contents[$line][3][
'url'];
242 $dateligne = $contents[$line][4][
'text'];
243 $percentage = $contents[$line][5][
'text'];
244 $out .=
'<tr class="oddeven">';
245 $out .=
'<td class="center">';
248 $out .=
'<td class="center"><a href="'.$urlevent.
'">'.$label.
'</a></td>';
249 $out .=
'<td class="center"><a href="'.$urlsoc.
'">'.
img_object(
"", $logosoc).
" ".$nomsoc.
'</a></td>';
250 $out .=
'<td class="center">'.$dateligne.
'</td>';
251 $out .=
'<td class="center">'.$percentage.
'</td>';
260 $out .=
'$("#dialogboxaction").dialog({ autoOpen: true });';
261 if ($conf->global->SHOW_DIALOG_HOMEPAGE > 1) {
262 $out .=
'setTimeout(function(){';
263 $out .=
'$("#dialogboxaction").dialog("close");';
264 $out .=
'}, '.($conf->global->SHOW_DIALOG_HOMEPAGE * 1000).
');';
269 $out .=
'$("#dialogboxaction").dialog({ autoOpen: false });';
Class to manage agenda events (actions)
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last events.
loadBox($max=5)
Load data for box to show them later.
__construct($db, $param)
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.