html.formwebsite.class.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /* Copyright (C) 2017 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 3 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. */
  17. /**
  18. * \file htdocs/core/class/html.formwebsite.class.php
  19. * \ingroup core
  20. * \brief File of class to manage component html for module website
  21. */
  22. /**
  23. * Class to manage component html for module website
  24. */
  25. class FormWebsite
  26. {
  27. private $db;
  28. /**
  29. * @var string Error code (or message)
  30. */
  31. public $error;
  32. /**
  33. * Constructor
  34. *
  35. * @param DoliDB $db Database handler
  36. */
  37. function __construct($db)
  38. {
  39. $this->db = $db;
  40. }
  41. /**
  42. * Return HTML select list of export models
  43. *
  44. * @param string $selected Id modele pre-selectionne
  45. * @param string $htmlname Name of HTML select
  46. * @param int $useempty Show empty value or not
  47. * @return string Html component
  48. */
  49. function selectWebsite($selected='',$htmlname='exportmodelid',$useempty=0)
  50. {
  51. $out='';
  52. $sql = "SELECT rowid, ref";
  53. $sql.= " FROM ".MAIN_DB_PREFIX."website";
  54. $sql.= " WHERE 1 = 1";
  55. $sql.= " ORDER BY rowid";
  56. $result = $this->db->query($sql);
  57. if ($result)
  58. {
  59. $out.='<select class="flat minwidth100" name="'.$htmlname.'" id="'.$htmlname.'">';
  60. if ($useempty)
  61. {
  62. $out.='<option value="-1">&nbsp;</option>';
  63. }
  64. $num = $this->db->num_rows($result);
  65. $i = 0;
  66. while ($i < $num)
  67. {
  68. $obj = $this->db->fetch_object($result);
  69. if ($selected == $obj->rowid)
  70. {
  71. $out.='<option value="'.$obj->rowid.'" selected>';
  72. }
  73. else
  74. {
  75. $out.='<option value="'.$obj->rowid.'">';
  76. }
  77. $out.=$obj->ref;
  78. $out.='</option>';
  79. $i++;
  80. }
  81. $out.="</select>";
  82. }
  83. else {
  84. dol_print_error($this->db);
  85. }
  86. return $out;
  87. }
  88. /**
  89. * Return a HTML select list of a dictionary
  90. *
  91. * @param string $htmlname Name of select zone
  92. * @param string $selected Selected value
  93. * @param int $useempty 1=Add an empty value in list, 2=Add an empty value in list only if there is more than 2 entries.
  94. * @param string $moreattrib More attributes on HTML select tag
  95. * @return void
  96. */
  97. function selectTypeOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='')
  98. {
  99. global $langs, $conf, $user;
  100. $langs->load("admin");
  101. $sql = "SELECT rowid, code, label, entity";
  102. $sql.= " FROM ".MAIN_DB_PREFIX.'c_type_container';
  103. $sql.= " WHERE active = 1 AND entity IN (".getEntity('c_type_container').")";
  104. $sql.= " ORDER BY label";
  105. dol_syslog(get_class($this)."::selectTypeOfContainer", LOG_DEBUG);
  106. $result = $this->db->query($sql);
  107. if ($result)
  108. {
  109. $num = $this->db->num_rows($result);
  110. $i = 0;
  111. if ($num)
  112. {
  113. print '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
  114. if ($useempty == 1 || ($useempty == 2 && $num > 1))
  115. {
  116. print '<option value="-1">&nbsp;</option>';
  117. }
  118. while ($i < $num)
  119. {
  120. $obj = $this->db->fetch_object($result);
  121. if ($selected == $obj->rowid || $selected == $obj->code)
  122. {
  123. print '<option value="'.$obj->code.'" selected>';
  124. }
  125. else
  126. {
  127. print '<option value="'.$obj->code.'">';
  128. }
  129. print $obj->label;
  130. print '</option>';
  131. $i++;
  132. }
  133. print "</select>";
  134. if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
  135. }
  136. else
  137. {
  138. print $langs->trans("NoTypeOfPagePleaseEditDictionary");
  139. }
  140. }
  141. else {
  142. dol_print_error($this->db);
  143. }
  144. }
  145. /**
  146. * Return a HTML select list of a dictionary
  147. *
  148. * @param string $htmlname Name of select zone
  149. * @param string $selected Selected value
  150. * @param int $useempty 1=Add an empty value in list
  151. * @param string $moreattrib More attributes on HTML select tag
  152. * @return void
  153. */
  154. function selectSampleOfContainer($htmlname, $selected='', $useempty=0, $moreattrib='')
  155. {
  156. global $langs, $conf, $user;
  157. $langs->load("admin");
  158. $arrayofsamples=array('empty'=>'EmptyPage', 'corporatehome'=>'CorporateHomePage');
  159. $out = '';
  160. $out .= '<select id="select'.$htmlname.'" class="flat selectTypeOfContainer" name="'.$htmlname.'"'.($moreattrib?' '.$moreattrib:'').'>';
  161. if ($useempty == 1 || $useempty == 2)
  162. {
  163. $out .= '<option value="-1">&nbsp;</option>';
  164. }
  165. foreach($arrayofsamples as $key => $val)
  166. {
  167. if ($selected == $key)
  168. {
  169. $out .= '<option value="'.$key.'" selected>';
  170. }
  171. else
  172. {
  173. $out .= '<option value="'.$key.'">';
  174. }
  175. $out .= $langs->trans($val);
  176. $out .= '</option>';
  177. }
  178. $out .= "</select>";
  179. return $out;
  180. }
  181. }