PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/core/boxes/modules_boxes.php

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