57 public $info_box_head = array();
62 public $info_box_contents = array();
82 public $hidden =
false;
143 public $widgettype =
'';
164 public $urltoaddentry;
168 public $msgNoRecords =
'NoRecordFound';
194 $msg = get_class($this).
"::".__FUNCTION__.
" not implemented";
222 $sql =
"SELECT b.rowid as id, b.box_id, b.position, b.box_order, b.fk_user";
223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes as b";
224 $sql .=
" WHERE b.entity = ".$conf->entity;
225 $sql .=
" AND b.rowid = ".((int) $rowid);
227 dol_syslog(get_class($this).
"::fetch rowid=".((
int) $rowid));
229 $resql = $this->db->query($sql);
231 $obj = $this->db->fetch_object($resql);
233 $this->
id = $obj->id;
234 $this->rowid = $obj->id;
235 $this->box_id = $obj->box_id;
237 $this->box_order = $obj->box_order;
238 $this->fk_user = $obj->fk_user;
256 public function showBox($head =
null, $contents =
null, $nooutput = 0)
258 global $langs, $user,
$conf;
260 if (!empty($this->hidden)) {
261 return "\n<!-- Box ".get_class($this).
" hidden -->\n";
264 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
269 $cachedir = DOL_DATA_ROOT.
'/users/temp/widgets';
270 $fileid = get_class($this).
'id-'.$this->box_id.
'-e'.
$conf->entity.
'-u'.$user->id.
'-s'.$user->socid.
'.cache';
271 $filename =
'/box-'.$fileid;
275 if ($contents ===
null) {
284 if (isset($contents[0])) {
285 $nbcol = count($contents[0]);
287 $nblines = count($contents);
289 $out .=
"\n<!-- Box ".get_class($this).
" start -->\n";
291 $out .=
'<div class="box divboxtable boxdraggable" id="boxto_'.$this->box_id.
'">'.
"\n";
292 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
293 $out .=
'<table summary="boxtable'.$this->box_id.
'" class="noborder boxtable centpercent">'.
"\n";
297 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto'])) {
298 $out .=
'<tr class="liste_titre box_titre">';
300 if (!empty($head[
'nbcol'])) {
301 $nbcol = $head[
'nbcol'];
304 $out .=
' colspan="'.$nbcol.
'"';
307 if (!empty(
$conf->use_javascript_ajax)) {
309 $out .=
'<div class="tdoverflowmax400 maxwidth250onsmartphone float">';
311 if (!empty($head[
'text']) && !is_array($head[
'text'])) {
312 $s =
dol_trunc($head[
'text'], isset($head[
'limit']) ? $head[
'limit'] : $MAXLENGTHBOX);
315 if (!empty(
$conf->use_javascript_ajax)) {
320 if (!empty(
$conf->use_javascript_ajax)) {
322 if (!empty($head[
'sublink'])) {
323 $sublink .=
'<a href="'.$head[
'sublink'].
'"'.(empty($head[
'target']) ?
'' :
' target="'.$head[
'target'].
'"').
'>';
325 if (!empty($head[
'subpicto']) && !is_array($head[
'subtext']) && !is_array($head[
'subpicto'])) {
326 $sublink .=
img_picto($head[
'subtext'], $head[
'subpicto'],
'class="opacitymedium marginleftonly '.(empty($head[
'subclass']) ?
'' : $head[
'subclass']).
'" id="idsubimg'.$this->boxcode.
'"');
328 if (!empty($head[
'sublink'])) {
333 $out .=
'<div class="nocellnopadd boxclose floatright nowraponall">';
336 $out .=
img_picto($langs->trans(
"MoveBox", $this->box_id),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
337 $out .=
img_picto($langs->trans(
"CloseBox", $this->box_id),
'close_title',
'class="opacitymedium boxclose cursorpointer marginleftonly" rel="x:y" id="imgclose'.$this->box_id.
'"');
338 $label = $head[
'text'];
340 if (!empty($head[
'graph'])) {
341 $label .=
' <span class="opacitymedium fas fa-chart-bar"></span>';
343 $out .=
'<input type="hidden" id="boxlabelentry'.$this->box_id.
'" value="'.
dol_escape_htmltag($label).
'">';
355 foreach (array_keys($contents) as $i) {
356 if (isset($contents[$i]) && is_array($contents[$i])) {
358 if (isset($contents[$i][0][
'tr'])) {
359 $out .=
'<tr '.$contents[$i][0][
'tr'].
'>';
361 $out .=
'<tr class="oddeven">';
365 $nbcolthisline = count($contents[$i]);
366 foreach (array_keys($contents[$i]) as $j) {
369 if (!empty($contents[$i][$j][
'td'])) {
370 $tdparam .=
' '.$contents[$i][$j][
'td'];
373 $text = isset($contents[$i][$j][
'text']) ? $contents[$i][$j][
'text'] :
'';
374 $textwithnotags = preg_replace(
'/<([^>]+)>/i',
'', $text);
375 $text2 = isset($contents[$i][$j][
'text2']) ? $contents[$i][$j][
'text2'] :
'';
376 $text2withnotags = preg_replace(
'/<([^>]+)>/i',
'', $text2);
378 $textnoformat = isset($contents[$i][$j][
'textnoformat']) ? $contents[$i][$j][
'textnoformat'] :
'';
380 if (empty($contents[$i][$j][
'tooltip'])) {
381 $contents[$i][$j][
'tooltip'] =
"";
383 $tooltip = isset($contents[$i][$j][
'tooltip']) ? $contents[$i][$j][
'tooltip'] :
'';
385 $out .=
'<td'.$tdparam.
'>'.
"\n";
388 if (!empty($contents[$i][$j][
'url']) && empty($contents[$i][$j][
'logo'])) {
389 $out .=
'<a href="'.$contents[$i][$j][
'url'].
'"';
390 if (!empty($tooltip)) {
391 $out .=
' title="'.dol_escape_htmltag($langs->trans(
"Show").
' '.$tooltip, 1).
'" class="classfortooltip"';
394 $out .= isset($contents[$i][$j][
'target']) ?
' target="'.$contents[$i][$j][
'target'].
'"' :
'';
399 if (!empty($contents[$i][$j][
'logo'])) {
400 $logo = preg_replace(
"/^object_/i",
"", $contents[$i][$j][
'logo']);
401 $out .=
'<a href="'.$contents[$i][$j][
'url'].
'">';
402 $out .=
img_object($langs->trans(
"Show").
' '.$tooltip, $logo,
'class="classfortooltip"');
405 $maxlength = $MAXLENGTHBOX;
406 if (isset($contents[$i][$j][
'maxlength'])) {
407 $maxlength = $contents[$i][$j][
'maxlength'];
411 $textwithnotags =
dol_trunc($textwithnotags, $maxlength);
413 if (preg_match(
'/^<(img|div|span)/i', $text) || !empty($contents[$i][$j][
'asis'])) {
416 $out .= $textwithnotags;
420 if (!empty($contents[$i][$j][
'url'])) {
424 if (preg_match(
'/^<(img|div|span)/i', $text2) || !empty($contents[$i][$j][
'asis2'])) {
427 $out .= $text2withnotags;
430 if (!empty($textnoformat)) {
431 $out .=
"\n".$textnoformat.
"\n";
441 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
442 $out .=
'<tr><td colspan="2" class="center"><span class="opacitymedium">'.$langs->trans($this->msgNoRecords).
' </span>';
445 if (!empty($this->urltoaddentry)) {
446 $out .=
'<a href="'.$this->urltoaddentry.
'">'.
img_picto($langs->trans(
"New"),
'add',
'pictofixedwidth').
'</a>';
449 $out .=
'</td></tr>';
453 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
454 $out .=
"</table>\n";
458 if (empty($head[
'text']) && empty($head[
'sublink']) && empty($head[
'subpicto']) && !$nblines) {
464 $out .=
"<!-- Box ".get_class($this).
" end -->\n\n";
469 dol_syslog(get_class($this).
'::showBoxCached');
470 $out =
"<!-- Box ".get_class($this).
" from cache -->";
499 $iscoreorexternal = array();
505 $dirwidget = array(
'/core/boxes/');
506 if (is_array($forcedirwidget)) {
507 $dirwidget = $forcedirwidget;
510 foreach ($dirwidget as $reldir) {
515 if (!is_dir($newdir)) {
519 $handle = opendir($newdir);
520 if (is_resource($handle)) {
521 while (($file = readdir($handle)) !==
false) {
523 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.php/', $file, $reg)) {
524 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
530 $modName = ucfirst($reg[1]);
532 if (in_array($modName, $modules)) {
533 $langs->load(
"errors");
534 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateWidget", $modName,
"").
'</div>';
537 include_once $newdir.
'/'.$file;
539 print $e->getMessage();
544 $fullpath[$i] = $dir.
'/'.$file;
545 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
546 $iscoreorexternal[$i] = ($reldir ==
'/core/boxes/' ?
'internal' :
'external');
547 $modules[$i] = $modName;
548 $orders[$i] = $part1;
564 foreach ($orders as $key => $value) {
565 $modName = $modules[$key];
566 if (empty($modName)) {
570 if (!class_exists($modName)) {
571 print
'Error: A widget file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
575 $objMod =
new $modName($db);
576 '@phan-var-force ModeleBoxes $objMod';
577 if (is_object($objMod)) {
580 $disabledbymodule = 0;
584 if (preg_match(
'/NORUN$/i', $files[$key])) {
589 $widget[$j][
'picto'] = ((!property_exists($objMod,
'picto') || empty($objMod->picto)) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
590 $widget[$j][
'file'] = $files[$key];
591 $widget[$j][
'fullpath'] = $fullpath[$key];
592 $widget[$j][
'relpath'] = $relpath[$key];
593 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
594 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
595 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick');
596 if ($disabledbyname > 0 || $disabledbymodule > 1) {
597 $widget[$j][
'status'] =
'';
600 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
601 $text .= $objMod->boxlabel.
'<br>';
602 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
603 if ($disabledbymodule == 2) {
604 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
607 $widget[$j][
'info'] = $text;
showBox($head=null, $contents=null, $nooutput=0)
Standard method to show a box (usage by boxes not mandatory, a box can still use its own showBox func...
fetch($rowid)
Load a box line from its rowid.
error()
Return last error message.
__construct($db, $param='')
Constructor.
loadBox($max=5)
Load data for box to show them later.
static getWidgetsList($forcedirwidget=null)
Return list of widget.
dol_filecache($directory, $filename, $object)
Store object in file.
dol_readcachefile($directory, $filename)
Read object from cachefile.
dol_cache_refresh($directory, $filename, $cachetime)
Test if Refresh needed.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...