PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/boxes/modules_boxes.php

https://bitbucket.org/speedealing/speedealing
PHP | 260 lines | 154 code | 38 blank | 68 comment | 38 complexity | 8c2dacaeece9e4863bcdd015fe4456fa MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. * or see http://www.gnu.org/
  18. */
  19. /**
  20. * \file htdocs/core/boxes/modules_boxes.php
  21. * \ingroup facture
  22. * \brief Fichier contenant la classe mere des boites
  23. */
  24. /**
  25. * Parent class of boxes
  26. */
  27. class ModeleBoxes // Can't be abtract as it is instanciated to build "empty" boxes
  28. {
  29. var $db;
  30. var $error='';
  31. var $max=5;
  32. var $rowid;
  33. var $id;
  34. var $position;
  35. var $box_order;
  36. var $fk_user;
  37. var $sourcefile;
  38. var $box_id;
  39. var $note;
  40. /**
  41. * Constructor
  42. *
  43. * @param DoliDB $db Database hanlder
  44. */
  45. function __construct($db = '')
  46. {
  47. $this->db=$db;
  48. }
  49. /**
  50. * Return last error message
  51. *
  52. * @return string Error message
  53. */
  54. function error()
  55. {
  56. return $this->error;
  57. }
  58. /**
  59. * Load a box line from its rowid
  60. *
  61. * @param int $rowid Row id to load
  62. * @return int <0 if KO, >0 if OK
  63. */
  64. function fetch($rowid)
  65. {
  66. global $conf;
  67. // Recupere liste des boites d'un user si ce dernier a sa propre liste
  68. $sql = "SELECT b.rowid, b.box_id, b.position, b.box_order, b.fk_user";
  69. $sql.= " FROM ".MAIN_DB_PREFIX."boxes as b";
  70. $sql.= " WHERE b.entity = ".$conf->entity;
  71. $sql.= " AND b.rowid = ".$rowid;
  72. dol_syslog(get_class($this)."::fetch rowid=".$rowid);
  73. $resql = $this->db->query($sql);
  74. if ($resql)
  75. {
  76. $obj = $this->db->fetch_object($resql);
  77. if ($obj)
  78. {
  79. $this->rowid=$obj->rowid;
  80. $this->box_id=$obj->box_id;
  81. $this->position=$obj->position;
  82. $this->box_order=$obj->box_order;
  83. $this->fk_user=$obj->fk_user;
  84. return 1;
  85. }
  86. else
  87. {
  88. return -1;
  89. }
  90. }
  91. else
  92. {
  93. return -1;
  94. }
  95. }
  96. /**
  97. * Standard method to show a box (usage by boxes not mandatory, a box can still use its own function)
  98. *
  99. * @param array $head Array with properties of box title
  100. * @param array $contents Array with properties of box lines
  101. * @return void
  102. */
  103. function showBox($head, $contents)
  104. {
  105. global $langs,$conf;
  106. $MAXLENGTHBOX=60; // Mettre 0 pour pas de limite
  107. $bcx[0] = 'class="box_pair"';
  108. $bcx[1] = 'class="box_impair"';
  109. $var = false;
  110. dol_syslog(get_Class($this));
  111. // Define nbcol and nblines of the box to show
  112. $nbcol=0;
  113. if (isset($contents[0])) $nbcol=count($contents[0]);
  114. $nblines=count($contents);
  115. print "\n\n<!-- Box start -->\n";
  116. print '<div class="box" id="boxto_'.$this->box_id.'">'."\n";
  117. if (! empty($head['text']) || ! empty($head['sublink']) || $nblines)
  118. {
  119. print '<table summary="boxtable'.$this->box_id.'" width="100%" class="noborder boxtable">'."\n";
  120. }
  121. // Show box title
  122. if (! empty($head['text']) || ! empty($head['sublink']))
  123. {
  124. //print '<div id="boxto_'.$this->box_id.'_title">'."\n";
  125. //print '<table summary="boxtabletitle'.$this->box_id.'" width="100%" class="noborder">'."\n";
  126. print '<tr class="box_titre">';
  127. print '<td';
  128. if ($nbcol > 0) { print ' colspan="'.$nbcol.'"'; }
  129. print '>';
  130. if ($conf->use_javascript_ajax)
  131. {
  132. print '<table summary="" class="nobordernopadding" width="100%"><tr><td>';
  133. }
  134. if (! empty($head['text']))
  135. {
  136. $s=dol_trunc($head['text'],isset($head['limit'])?$head['limit']:$MAXLENGTHBOX);
  137. print $s;
  138. }
  139. if (! empty($head['sublink']))
  140. {
  141. print ' <a href="'.$head['sublink'].'" target="_blank">'.img_picto($head['subtext'],$head['subpicto']).'</a>';
  142. }
  143. if ($conf->use_javascript_ajax)
  144. {
  145. print '</td><td class="nocellnopadd" width="30" nowrap="nowrap">';
  146. // The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object
  147. print img_picto($langs->trans("MoveBox",$this->box_id),'grip','class="boxhandle" style="cursor:move;"');
  148. print img_picto($langs->trans("Close",$this->box_id),'close','class="boxclose" style="cursor:pointer;" id="imgclose'.$this->box_id.'"');
  149. print '</td></tr></table>';
  150. }
  151. print '</td>';
  152. print "</tr>\n";
  153. // print "</table>\n";
  154. // print "</div>\n";
  155. }
  156. // Show box lines
  157. if ($nblines)
  158. {
  159. //print '<table summary="boxtablelines'.$this->box_id.'" width="100%" class="noborder">'."\n";
  160. // Loop on each record
  161. for ($i=0, $n=$nblines; $i < $n; $i++)
  162. {
  163. if (isset($contents[$i]))
  164. {
  165. $var=!$var;
  166. // TR
  167. if (isset($contents[$i][0]['tr'])) print '<tr valign="top" '.$contents[$i][0]['tr'].'>';
  168. else print '<tr valign="top" '.$bcx[$var].'>';
  169. // Loop on each TD
  170. $nbcolthisline=count($contents[$i]);
  171. for ($j=0; $j < $nbcolthisline; $j++)
  172. {
  173. // Define tdparam
  174. $tdparam='';
  175. if (isset($contents[$i][$j]['td'])) $tdparam.=' '.$contents[$i][$j]['td'];
  176. if (empty($contents[$i][$j]['text'])) $contents[$i][$j]['text']="";
  177. $texte=isset($contents[$i][$j]['text'])?$contents[$i][$j]['text']:'';
  178. $textewithnotags=preg_replace('/<([^>]+)>/i','',$texte);
  179. $texte2=isset($contents[$i][$j]['text2'])?$contents[$i][$j]['text2']:'';
  180. $texte2withnotags=preg_replace('/<([^>]+)>/i','',$texte2);
  181. //print "xxx $textewithnotags y";
  182. print '<td'.$tdparam.'>';
  183. // Url
  184. if (! empty($contents[$i][$j]['url']))
  185. {
  186. print '<a href="'.$contents[$i][$j]['url'].'" title="'.$textewithnotags.'"';
  187. //print ' alt="'.$textewithnotags.'"'; // Pas de alt sur un "<a href>"
  188. print isset($contents[$i][$j]['target'])?' target="'.$contents[$i][$j]['target'].'"':'';
  189. print '>';
  190. }
  191. // Logo
  192. if (! empty($contents[$i][$j]['logo']))
  193. {
  194. $logo=preg_replace("/^object_/i","",$contents[$i][$j]['logo']);
  195. print img_object($langs->trans("Show"),$logo);
  196. }
  197. $maxlength=$MAXLENGTHBOX;
  198. if (! empty($contents[$i][$j]['maxlength'])) $maxlength=$contents[$i][$j]['maxlength'];
  199. if ($maxlength) $textewithnotags=dol_trunc($textewithnotags,$maxlength);
  200. if (preg_match('/^<img/i',$texte) || ! empty($contents[$i][$j]['asis'])) print $texte; // show text with no html cleaning
  201. else print $textewithnotags; // show text with html cleaning
  202. // End Url
  203. if (! empty($contents[$i][$j]['url'])) print '</a>';
  204. if (preg_match('/^<img/i',$texte2) || ! empty($contents[$i][$j]['asis2'])) print $texte2; // show text with no html cleaning
  205. else print $texte2withnotags; // show text with html cleaning
  206. print "</td>";
  207. }
  208. print "</tr>\n";
  209. }
  210. }
  211. }
  212. if (! empty($head['text']) || ! empty($head['sublink']) || $nblines)
  213. {
  214. print "</table>\n";
  215. }
  216. // If invisible box with no contents
  217. if (empty($head['text']) && empty($head['sublink']) && ! $nblines) print "<br>\n";
  218. print "</div>\n";
  219. print "<!-- Box end -->\n\n";
  220. }
  221. }
  222. ?>