59 public $hidden =
false;
115 public $widgettype =
'';
152 $sql =
"SELECT b.rowid as id, b.box_id, b.position, b.box_order, b.fk_user";
153 $sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes as b";
154 $sql .=
" WHERE b.entity = ".$conf->entity;
155 $sql .=
" AND b.rowid = ".((int) $rowid);
156 dol_syslog(get_class($this).
"::fetch rowid=".$rowid);
158 $resql = $this->db->query(
$sql);
160 $obj = $this->db->fetch_object($resql);
162 $this->
id = $obj->id;
163 $this->
rowid = $obj->id;
164 $this->box_id = $obj->box_id;
166 $this->box_order = $obj->box_order;
167 $this->fk_user = $obj->fk_user;
185 public function showBox($head =
null, $contents =
null, $nooutput = 0)
187 global $langs, $user, $conf;
189 if (!empty($this->hidden)) {
190 return '\n<!-- Box ".get_class($this)." hidden -->\n';
193 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
198 $cachedir = DOL_DATA_ROOT.
'/boxes/temp';
199 $fileid = get_class($this).
'id-'.$this->box_id.
'-e'.$conf->entity.
'-u'.$user->id.
'-s'.$user->socid.
'.cache';
200 $filename =
'/box-'.$fileid;
209 if (isset($contents[0])) {
210 $nbcol = count($contents[0]);
212 $nblines = count($contents);
214 $out .=
"\n<!-- Box ".get_class($this).
" start -->\n";
216 $out .=
'<div class="box divboxtable boxdraggable" id="boxto_'.$this->box_id.
'">'.
"\n";
218 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
219 $out .=
'<table summary="boxtable'.$this->box_id.
'" width="100%" class="noborder boxtable">'.
"\n";
223 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto'])) {
224 $out .=
'<tr class="liste_titre box_titre">';
227 $out .=
' colspan="'.$nbcol.
'"';
230 if (!empty($conf->use_javascript_ajax)) {
232 $out .=
'<div class="tdoverflowmax400 maxwidth250onsmartphone float">';
234 if (!empty($head[
'text'])) {
235 $s =
dol_trunc($head[
'text'], isset($head[
'limit']) ? $head[
'limit'] : $MAXLENGTHBOX);
238 if (!empty($conf->use_javascript_ajax)) {
243 if (!empty($conf->use_javascript_ajax)) {
245 if (!empty($head[
'sublink'])) {
246 $sublink .=
'<a href="'.$head[
'sublink'].
'"'.(empty($head[
'target']) ?
'' :
' target="'.$head[
'target'].
'"').
'>';
248 if (!empty($head[
'subpicto'])) {
249 $sublink .=
img_picto($head[
'subtext'], $head[
'subpicto'],
'class="opacitymedium marginleftonly '.(empty($head[
'subclass']) ?
'' : $head[
'subclass']).
'" id="idsubimg'.$this->boxcode.
'"');
251 if (!empty($head[
'sublink'])) {
256 $out .=
'<div class="nocellnopadd boxclose floatright nowraponall">';
259 $out .=
img_picto($langs->trans(
"MoveBox", $this->box_id),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
260 $out .=
img_picto($langs->trans(
"CloseBox", $this->box_id),
'close_title',
'class="opacitymedium boxclose cursorpointer marginleftonly" rel="x:y" id="imgclose'.$this->box_id.
'"');
261 $label = $head[
'text'];
263 if (!empty($head[
'graph'])) {
264 $label .=
' <span class="opacitymedium fa fa-bar-chart"></span>';
266 $out .=
'<input type="hidden" id="boxlabelentry'.$this->box_id.
'" value="'.
dol_escape_htmltag($label).
'">';
278 for ($i = 0, $n = $nblines; $i < $n; $i++) {
279 if (isset($contents[$i])) {
281 if (isset($contents[$i][0][
'tr'])) {
282 $out .=
'<tr '.$contents[$i][0][
'tr'].
'>';
284 $out .=
'<tr class="oddeven">';
288 $nbcolthisline = count($contents[$i]);
289 for ($j = 0; $j < $nbcolthisline; $j++) {
292 if (!empty($contents[$i][$j][
'td'])) {
293 $tdparam .=
' '.$contents[$i][$j][
'td'];
296 $text = isset($contents[$i][$j][
'text']) ? $contents[$i][$j][
'text'] :
'';
297 $textwithnotags = preg_replace(
'/<([^>]+)>/i',
'', $text);
298 $text2 = isset($contents[$i][$j][
'text2']) ? $contents[$i][$j][
'text2'] :
'';
299 $text2withnotags = preg_replace(
'/<([^>]+)>/i',
'', $text2);
301 $textnoformat = isset($contents[$i][$j][
'textnoformat']) ? $contents[$i][$j][
'textnoformat'] :
'';
303 if (empty($contents[$i][$j][
'tooltip'])) {
304 $contents[$i][$j][
'tooltip'] =
"";
306 $tooltip = isset($contents[$i][$j][
'tooltip']) ? $contents[$i][$j][
'tooltip'] :
'';
308 $out .=
'<td'.$tdparam.
'>'.
"\n";
311 if (!empty($contents[$i][$j][
'url']) && empty($contents[$i][$j][
'logo'])) {
312 $out .=
'<a href="'.$contents[$i][$j][
'url'].
'"';
313 if (!empty($tooltip)) {
314 $out .=
' title="'.dol_escape_htmltag($langs->trans(
"Show").
' '.$tooltip, 1).
'" class="classfortooltip"';
317 $out .= isset($contents[$i][$j][
'target']) ?
' target="'.$contents[$i][$j][
'target'].
'"' :
'';
322 if (!empty($contents[$i][$j][
'logo'])) {
323 $logo = preg_replace(
"/^object_/i",
"", $contents[$i][$j][
'logo']);
324 $out .=
'<a href="'.$contents[$i][$j][
'url'].
'">';
325 $out .=
img_object($langs->trans(
"Show").
' '.$tooltip, $logo,
'class="classfortooltip"');
328 $maxlength = $MAXLENGTHBOX;
329 if (isset($contents[$i][$j][
'maxlength'])) {
330 $maxlength = $contents[$i][$j][
'maxlength'];
334 $textwithnotags =
dol_trunc($textwithnotags, $maxlength);
336 if (preg_match(
'/^<(img|div|span)/i', $text) || !empty($contents[$i][$j][
'asis'])) {
339 $out .= $textwithnotags;
343 if (!empty($contents[$i][$j][
'url'])) {
347 if (preg_match(
'/^<(img|div|span)/i', $text2) || !empty($contents[$i][$j][
'asis2'])) {
350 $out .= $text2withnotags;
353 if (!empty($textnoformat)) {
354 $out .=
"\n".$textnoformat.
"\n";
365 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
366 $out .=
"</table>\n";
370 if (empty($head[
'text']) && empty($head[
'sublink']) && empty($head[
'subpicto']) && !$nblines) {
376 $out .=
"<!-- Box ".get_class($this).
" end -->\n\n";
377 if (!empty($conf->global->MAIN_ACTIVATE_FILECACHE)) {
381 dol_syslog(get_class($this).
'::showBoxCached');
382 $out =
"<!-- Box ".get_class($this).
" from cache -->";
405 global $conf, $langs, $db;
410 $iscoreorexternal = array();
416 $dirwidget = array(
'/core/boxes/');
417 if (is_array($forcedirwidget)) {
418 $dirwidget = $forcedirwidget;
421 foreach ($dirwidget as $reldir) {
426 if (!is_dir($newdir)) {
430 $handle = opendir($newdir);
431 if (is_resource($handle)) {
432 while (($file = readdir($handle)) !==
false) {
434 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.php/', $file, $reg)) {
435 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
441 $modName = ucfirst($reg[1]);
443 if (in_array($modName, $modules)) {
444 $langs->load(
"errors");
445 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateWidget", $modName,
"").
'</div>';
448 include_once $newdir.
'/'.$file;
450 print $e->getMessage();
455 $fullpath[$i] = $dir.
'/'.$file;
456 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
457 $iscoreorexternal[$i] = ($reldir ==
'/core/boxes/' ?
'internal' :
'external');
458 $modules[$i] = $modName;
459 $orders[$i] = $part1;
475 foreach ($orders as $key => $value) {
476 $modName = $modules[$key];
477 if (empty($modName)) {
481 if (!class_exists($modName)) {
482 print
'Error: A widget file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
486 $objMod =
new $modName($db);
487 if (is_object($objMod)) {
490 $disabledbymodule = 0;
494 if (preg_match(
'/NORUN$/i', $files[$key])) {
499 $widget[$j][
'picto'] = (empty($objMod->picto) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
500 $widget[$j][
'file'] = $files[$key];
501 $widget[$j][
'fullpath'] = $fullpath[$key];
502 $widget[$j][
'relpath'] = $relpath[$key];
503 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
504 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
505 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick');
506 if ($disabledbyname > 0 || $disabledbymodule > 1) {
507 $widget[$j][
'status'] =
'';
510 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
511 $text .= $objMod->boxlabel.
'<br>';
512 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
513 if ($disabledbymodule == 2) {
514 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
517 $widget[$j][
'info'] = $text;