57 public $info_box_head = array();
62 public $info_box_contents = array();
82 public $hidden =
false;
138 public $widgettype =
'';
193 $sql =
"SELECT b.rowid as id, b.box_id, b.position, b.box_order, b.fk_user";
194 $sql .=
" FROM ".MAIN_DB_PREFIX.
"boxes as b";
195 $sql .=
" WHERE b.entity = ".$conf->entity;
196 $sql .=
" AND b.rowid = ".((int) $rowid);
198 dol_syslog(get_class($this).
"::fetch rowid=".((
int) $rowid));
200 $resql = $this->db->query($sql);
202 $obj = $this->db->fetch_object($resql);
204 $this->
id = $obj->id;
205 $this->
rowid = $obj->id;
206 $this->box_id = $obj->box_id;
208 $this->box_order = $obj->box_order;
209 $this->fk_user = $obj->fk_user;
227 public function showBox($head =
null, $contents =
null, $nooutput = 0)
229 global $langs, $user, $conf;
231 if (!empty($this->hidden)) {
232 return "\n<!-- Box ".get_class($this).
" hidden -->\n";
235 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
240 $cachedir = DOL_DATA_ROOT.
'/users/temp/widgets';
241 $fileid = get_class($this).
'id-'.$this->box_id.
'-e'.$conf->entity.
'-u'.$user->id.
'-s'.$user->socid.
'.cache';
242 $filename =
'/box-'.$fileid;
246 if ($contents ===
null) {
255 if (isset($contents[0])) {
256 $nbcol = count($contents[0]);
258 $nblines = count($contents);
260 $out .=
"\n<!-- Box ".get_class($this).
" start -->\n";
262 $out .=
'<div class="box divboxtable boxdraggable" id="boxto_'.$this->box_id.
'">'.
"\n";
263 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
264 $out .=
'<table summary="boxtable'.$this->box_id.
'" width="100%" class="noborder boxtable">'.
"\n";
268 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto'])) {
269 $out .=
'<tr class="liste_titre box_titre">';
271 if (!empty($head[
'nbcol'])) {
272 $nbcol = $head[
'nbcol'];
275 $out .=
' colspan="'.$nbcol.
'"';
278 if (!empty($conf->use_javascript_ajax)) {
280 $out .=
'<div class="tdoverflowmax400 maxwidth250onsmartphone float">';
282 if (!empty($head[
'text'])) {
283 $s =
dol_trunc($head[
'text'], isset($head[
'limit']) ? $head[
'limit'] : $MAXLENGTHBOX);
286 if (!empty($conf->use_javascript_ajax)) {
291 if (!empty($conf->use_javascript_ajax)) {
293 if (!empty($head[
'sublink'])) {
294 $sublink .=
'<a href="'.$head[
'sublink'].
'"'.(empty($head[
'target']) ?
'' :
' target="'.$head[
'target'].
'"').
'>';
296 if (!empty($head[
'subpicto'])) {
297 $sublink .=
img_picto($head[
'subtext'], $head[
'subpicto'],
'class="opacitymedium marginleftonly '.(empty($head[
'subclass']) ?
'' : $head[
'subclass']).
'" id="idsubimg'.$this->boxcode.
'"');
299 if (!empty($head[
'sublink'])) {
304 $out .=
'<div class="nocellnopadd boxclose floatright nowraponall">';
307 $out .=
img_picto($langs->trans(
"MoveBox", $this->box_id),
'grip_title',
'class="opacitymedium boxhandle hideonsmartphone cursormove marginleftonly"');
308 $out .=
img_picto($langs->trans(
"CloseBox", $this->box_id),
'close_title',
'class="opacitymedium boxclose cursorpointer marginleftonly" rel="x:y" id="imgclose'.$this->box_id.
'"');
309 $label = $head[
'text'];
311 if (!empty($head[
'graph'])) {
312 $label .=
' <span class="opacitymedium fas fa-chart-bar"></span>';
314 $out .=
'<input type="hidden" id="boxlabelentry'.$this->box_id.
'" value="'.
dol_escape_htmltag($label).
'">';
326 foreach (array_keys($contents) as $i) {
327 if (isset($contents[$i]) && is_array($contents[$i])) {
329 if (isset($contents[$i][0][
'tr'])) {
330 $out .=
'<tr '.$contents[$i][0][
'tr'].
'>';
332 $out .=
'<tr class="oddeven">';
336 $nbcolthisline = count($contents[$i]);
337 foreach (array_keys($contents[$i]) as $j) {
340 if (!empty($contents[$i][$j][
'td'])) {
341 $tdparam .=
' '.$contents[$i][$j][
'td'];
344 $text = isset($contents[$i][$j][
'text']) ? $contents[$i][$j][
'text'] :
'';
345 $textwithnotags = preg_replace(
'/<([^>]+)>/i',
'', $text);
346 $text2 = isset($contents[$i][$j][
'text2']) ? $contents[$i][$j][
'text2'] :
'';
347 $text2withnotags = preg_replace(
'/<([^>]+)>/i',
'', $text2);
349 $textnoformat = isset($contents[$i][$j][
'textnoformat']) ? $contents[$i][$j][
'textnoformat'] :
'';
351 if (empty($contents[$i][$j][
'tooltip'])) {
352 $contents[$i][$j][
'tooltip'] =
"";
354 $tooltip = isset($contents[$i][$j][
'tooltip']) ? $contents[$i][$j][
'tooltip'] :
'';
356 $out .=
'<td'.$tdparam.
'>'.
"\n";
359 if (!empty($contents[$i][$j][
'url']) && empty($contents[$i][$j][
'logo'])) {
360 $out .=
'<a href="'.$contents[$i][$j][
'url'].
'"';
361 if (!empty($tooltip)) {
362 $out .=
' title="'.dol_escape_htmltag($langs->trans(
"Show").
' '.$tooltip, 1).
'" class="classfortooltip"';
365 $out .= isset($contents[$i][$j][
'target']) ?
' target="'.$contents[$i][$j][
'target'].
'"' :
'';
370 if (!empty($contents[$i][$j][
'logo'])) {
371 $logo = preg_replace(
"/^object_/i",
"", $contents[$i][$j][
'logo']);
372 $out .=
'<a href="'.$contents[$i][$j][
'url'].
'">';
373 $out .=
img_object($langs->trans(
"Show").
' '.$tooltip, $logo,
'class="classfortooltip"');
376 $maxlength = $MAXLENGTHBOX;
377 if (isset($contents[$i][$j][
'maxlength'])) {
378 $maxlength = $contents[$i][$j][
'maxlength'];
382 $textwithnotags =
dol_trunc($textwithnotags, $maxlength);
384 if (preg_match(
'/^<(img|div|span)/i', $text) || !empty($contents[$i][$j][
'asis'])) {
387 $out .= $textwithnotags;
391 if (!empty($contents[$i][$j][
'url'])) {
395 if (preg_match(
'/^<(img|div|span)/i', $text2) || !empty($contents[$i][$j][
'asis2'])) {
398 $out .= $text2withnotags;
401 if (!empty($textnoformat)) {
402 $out .=
"\n".$textnoformat.
"\n";
413 if (!empty($head[
'text']) || !empty($head[
'sublink']) || !empty($head[
'subpicto']) || $nblines) {
414 $out .=
"</table>\n";
418 if (empty($head[
'text']) && empty($head[
'sublink']) && empty($head[
'subpicto']) && !$nblines) {
424 $out .=
"<!-- Box ".get_class($this).
" end -->\n\n";
429 dol_syslog(get_class($this).
'::showBoxCached');
430 $out =
"<!-- Box ".get_class($this).
" from cache -->";
459 $iscoreorexternal = array();
465 $dirwidget = array(
'/core/boxes/');
466 if (is_array($forcedirwidget)) {
467 $dirwidget = $forcedirwidget;
470 foreach ($dirwidget as $reldir) {
475 if (!is_dir($newdir)) {
479 $handle = opendir($newdir);
480 if (is_resource($handle)) {
481 while (($file = readdir($handle)) !==
false) {
483 if (is_readable($newdir.
'/'.$file) && preg_match(
'/^(.+)\.php/', $file, $reg)) {
484 if (preg_match(
'/\.back$/', $file) || preg_match(
'/^(.+)\.disabled\.php/', $file)) {
490 $modName = ucfirst($reg[1]);
492 if (in_array($modName, $modules)) {
493 $langs->load(
"errors");
494 print
'<div class="error">'.$langs->trans(
"Error").
' : '.$langs->trans(
"ErrorDuplicateWidget", $modName,
"").
'</div>';
497 include_once $newdir.
'/'.$file;
499 print $e->getMessage();
504 $fullpath[$i] = $dir.
'/'.$file;
505 $relpath[$i] = preg_replace(
'/^\//',
'', $reldir).
'/'.$file;
506 $iscoreorexternal[$i] = ($reldir ==
'/core/boxes/' ?
'internal' :
'external');
507 $modules[$i] = $modName;
508 $orders[$i] = $part1;
524 foreach ($orders as $key => $value) {
525 $modName = $modules[$key];
526 if (empty($modName)) {
530 if (!class_exists($modName)) {
531 print
'Error: A widget file was found but its class "'.$modName.
'" was not found.'.
"<br>\n";
535 $objMod =
new $modName($db);
536 '@phan-var-force ModeleBoxes $objMod';
537 if (is_object($objMod)) {
540 $disabledbymodule = 0;
544 if (preg_match(
'/NORUN$/i', $files[$key])) {
549 $widget[$j][
'picto'] = ((!property_exists($objMod,
'picto') || empty($objMod->picto)) ? (empty($objMod->boximg) ?
img_object(
'',
'generic') : $objMod->boximg) :
img_object(
'', $objMod->picto));
550 $widget[$j][
'file'] = $files[$key];
551 $widget[$j][
'fullpath'] = $fullpath[$key];
552 $widget[$j][
'relpath'] = $relpath[$key];
553 $widget[$j][
'iscoreorexternal'] = $iscoreorexternal[$key];
554 $widget[$j][
'version'] = empty($objMod->version) ?
'' : $objMod->version;
555 $widget[$j][
'status'] =
img_picto($langs->trans(
"Active"),
'tick');
556 if ($disabledbyname > 0 || $disabledbymodule > 1) {
557 $widget[$j][
'status'] =
'';
560 $text =
'<b>'.$langs->trans(
"Description").
':</b><br>';
561 $text .= $objMod->boxlabel.
'<br>';
562 $text .=
'<br><b>'.$langs->trans(
"Status").
':</b><br>';
563 if ($disabledbymodule == 2) {
564 $text .= $langs->trans(
"WidgetDisabledAsModuleDisabled", $module).
'<br>';
567 $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.
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid