html.formother.class.php 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571
  1. <?php
  2. /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  7. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  8. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  9. * Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
  10. * Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
  11. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  12. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/core/class/html.formother.class.php
  29. * \ingroup core
  30. * \brief Fichier de la classe des fonctions predefinie de composants html autre
  31. */
  32. /**
  33. * Classe permettant la generation de composants html autre
  34. * Only common components are here.
  35. */
  36. class FormOther
  37. {
  38. private $db;
  39. /**
  40. * @var string Error code (or message)
  41. */
  42. public $error;
  43. /**
  44. * Constructor
  45. *
  46. * @param DoliDB $db Database handler
  47. */
  48. public function __construct($db)
  49. {
  50. $this->db = $db;
  51. }
  52. /**
  53. * Return the HTML code for scanner tool.
  54. * This must be called into an existing <form>
  55. *
  56. * @param string $jstoexecuteonadd Name of javascript function to call once the barcode scanning session is complete and user has click on "Add".
  57. * @param string $mode 'all' (both product and lot barcode) or 'product' (product barcode only) or 'lot' (lot number only)
  58. * @param int $warehouseselect 0 (disable warehouse select) or 1 (enable warehouse select)
  59. * @return string HTML component
  60. */
  61. public function getHTMLScannerForm($jstoexecuteonadd = 'barcodescannerjs', $mode = 'all', $warehouseselect = 0)
  62. {
  63. global $langs;
  64. $out = '';
  65. $out .= '<!-- Popup for mass barcode scanning -->'."\n";
  66. $out .= '<div class="div-for-modal-topright" style="padding: 15px">';
  67. $out .= '<center>'.img_picto('', 'barcode', 'class="pictofixedwidth"').'<strong>Barcode scanner tool...</strong></center><br>';
  68. if ($mode == 'product') {
  69. $out .= '<input type="hidden" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct">';
  70. } elseif ($mode == 'lot') {
  71. $out .= '<input type="hidden" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial">';
  72. } else { // $mode = 'all'
  73. $out .= '<input type="radio" name="barcodemode" value="barcodeforautodetect" id="barcodeforautodetect" checked="checked"> <label for="barcodeforautodetect">Autodetect if we scan a product barcode or a lot/serial barcode</label><br>';
  74. $out .= '<input type="radio" name="barcodemode" value="barcodeforproduct" id="barcodeforproduct"> <label for="barcodeforproduct">Scan a product barcode</label><br>';
  75. $out .= '<input type="radio" name="barcodemode" value="barcodeforlotserial" id="barcodeforlotserial"> <label for="barcodeforlotserial">Scan a product lot or serial number</label><br>';
  76. }
  77. $stringaddbarcode = $langs->trans("QtyToAddAfterBarcodeScan", "tmphtml");
  78. $htmltoreplaceby = '<select name="selectaddorreplace"><option selected value="add">'.$langs->trans("Add").'</option><option value="replace">'.$langs->trans("ToReplace").'</option></select>';
  79. $stringaddbarcode = str_replace("tmphtml", $htmltoreplaceby, $stringaddbarcode);
  80. $out .= $stringaddbarcode.': <input type="text" name="barcodeproductqty" class="width40 right" value="1"><br>';
  81. if ($warehouseselect > 0) {
  82. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  83. $formproduct = new FormProduct($this->db);
  84. $formproduct->loadWarehouses();
  85. $out .= img_picto('', 'stock', 'class="pictofixedwidth"');
  86. $out .= $formproduct->selectWarehouses('', "warehousenew", '', 0, 0, 0, '', 0, 1);
  87. $out .= '<br>';
  88. $out .= '<br>';
  89. }
  90. $out .= '<textarea type="text" name="barcodelist" class="centpercent" autofocus rows="'.ROWS_3.'" placeholder="'.dol_escape_htmltag($langs->trans("ScanOrTypeOrCopyPasteYourBarCodes")).'"></textarea>';
  91. /*print '<br>'.$langs->trans("or").'<br>';
  92. print '<br>';
  93. print '<input type="text" name="barcodelotserial" class="width200"> &nbsp; &nbsp; Qty <input type="text" name="barcodelotserialqty" class="width50 right" value="1"><br>';
  94. */
  95. $out .= '<br>';
  96. $out .= '<center>';
  97. $out .= '<input type="submit" class="button marginleftonly marginrightonly" id ="exec'.dol_escape_js($jstoexecuteonadd).'" name="addscan" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
  98. $out .= '<input type="submit" class="button marginleftonly marginrightonly" name="cancel" value="'.dol_escape_htmltag($langs->trans("CloseWindow")).'">';
  99. $out .= '</center>';
  100. $out .= '<br>';
  101. $out .= '<div type="text" id="scantoolmessage" class="scantoolmessage ok nopadding"></div>';
  102. $out .= '<script nonce="'.getNonce().'">';
  103. $out .= 'jQuery("#barcodeforautodetect, #barcodeforproduct, #barcodeforlotserial").click(function(){';
  104. $out .= 'console.log("select choice");';
  105. $out .= 'jQuery("#scantoolmessage").text("");';
  106. $out .= '});'."\n";
  107. $out .= '$("#exec'.dol_escape_js($jstoexecuteonadd).'").click(function(){
  108. console.log("We call js to execute \''.dol_escape_js($jstoexecuteonadd).'\'");
  109. '.dol_escape_js($jstoexecuteonadd).'();
  110. return false; /* We want to stay on the scan tool */
  111. })';
  112. $out .= '</script>';
  113. $out .= '</center>';
  114. $out .= '</div>';
  115. return $out;
  116. }
  117. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  118. /**
  119. * Return HTML select list of export models
  120. *
  121. * @param string $selected Id modele pre-selectionne
  122. * @param string $htmlname Nom de la zone select
  123. * @param string $type Type des modeles recherches
  124. * @param int $useempty Show an empty value in list
  125. * @param int $fk_user User we want templates
  126. * @return void
  127. */
  128. public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
  129. {
  130. // phpcs:enable
  131. global $conf, $langs, $user;
  132. $sql = "SELECT rowid, label, fk_user";
  133. $sql .= " FROM ".$this->db->prefix()."export_model";
  134. $sql .= " WHERE type = '".$this->db->escape($type)."'";
  135. if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
  136. $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
  137. }
  138. $sql .= " ORDER BY label";
  139. $result = $this->db->query($sql);
  140. if ($result) {
  141. print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
  142. if ($useempty) {
  143. print '<option value="-1">&nbsp;</option>';
  144. }
  145. $tmpuser = new User($this->db);
  146. $num = $this->db->num_rows($result);
  147. $i = 0;
  148. while ($i < $num) {
  149. $obj = $this->db->fetch_object($result);
  150. $label = $obj->label;
  151. if ($obj->fk_user == 0) {
  152. $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
  153. } elseif ($obj->fk_user > 0) {
  154. $tmpuser->fetch($obj->fk_user);
  155. $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
  156. }
  157. if ($selected == $obj->rowid) {
  158. print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
  159. } else {
  160. print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
  161. }
  162. print $label;
  163. print '</option>';
  164. $i++;
  165. }
  166. print "</select>";
  167. print ajax_combobox($htmlname);
  168. } else {
  169. dol_print_error($this->db);
  170. }
  171. }
  172. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  173. /**
  174. * Return list of export models
  175. *
  176. * @param string $selected Id modele pre-selectionne
  177. * @param string $htmlname Nom de la zone select
  178. * @param string $type Type des modeles recherches
  179. * @param int $useempty Affiche valeur vide dans liste
  180. * @param int $fk_user User that has created the template
  181. * @return void
  182. */
  183. public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
  184. {
  185. // phpcs:enable
  186. global $conf, $langs, $user;
  187. $sql = "SELECT rowid, label, fk_user";
  188. $sql .= " FROM ".$this->db->prefix()."import_model";
  189. $sql .= " WHERE type = '".$this->db->escape($type)."'";
  190. if (!getDolGlobalString('EXPORTS_SHARE_MODELS')) { // EXPORTS_SHARE_MODELS means all templates are visible, whatever is owner.
  191. $sql .= " AND fk_user IN (0, ".((int) $fk_user).")";
  192. }
  193. $sql .= " ORDER BY label";
  194. $result = $this->db->query($sql);
  195. if ($result) {
  196. print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
  197. if ($useempty) {
  198. print '<option value="-1">&nbsp;</option>';
  199. }
  200. $tmpuser = new User($this->db);
  201. $num = $this->db->num_rows($result);
  202. $i = 0;
  203. while ($i < $num) {
  204. $obj = $this->db->fetch_object($result);
  205. $label = $obj->label;
  206. if ($obj->fk_user == 0) {
  207. $label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
  208. } elseif ($obj->fk_user > 0) {
  209. $tmpuser->fetch($obj->fk_user);
  210. $label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
  211. }
  212. if ($selected == $obj->rowid) {
  213. print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
  214. } else {
  215. print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
  216. }
  217. print $label;
  218. print '</option>';
  219. $i++;
  220. }
  221. print "</select>";
  222. print ajax_combobox($htmlname);
  223. } else {
  224. dol_print_error($this->db);
  225. }
  226. }
  227. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  228. /**
  229. * Return list of ecotaxes with label
  230. *
  231. * @param string $selected Preselected ecotaxes
  232. * @param string $htmlname Name of combo list
  233. * @return integer
  234. */
  235. public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
  236. {
  237. // phpcs:enable
  238. global $langs;
  239. $sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
  240. $sql .= " c.label as country";
  241. $sql .= " FROM ".$this->db->prefix()."c_ecotaxe as e,".$this->db->prefix()."c_country as c";
  242. $sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
  243. $sql .= " ORDER BY country, e.organization ASC, e.code ASC";
  244. dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
  245. $resql = $this->db->query($sql);
  246. if ($resql) {
  247. print '<select class="flat" name="'.$htmlname.'">';
  248. $num = $this->db->num_rows($resql);
  249. $i = 0;
  250. print '<option value="-1">&nbsp;</option>'."\n";
  251. if ($num) {
  252. while ($i < $num) {
  253. $obj = $this->db->fetch_object($resql);
  254. if ($selected && $selected == $obj->rowid) {
  255. print '<option value="'.$obj->rowid.'" selected>';
  256. } else {
  257. print '<option value="'.$obj->rowid.'">';
  258. //print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
  259. }
  260. $selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
  261. print $selectOptionValue;
  262. print '</option>';
  263. $i++;
  264. }
  265. }
  266. print '</select>';
  267. return 0;
  268. } else {
  269. dol_print_error($this->db);
  270. return 1;
  271. }
  272. }
  273. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  274. /**
  275. * Return list of revenue stamp for country
  276. *
  277. * @param string $selected Value of preselected revenue stamp
  278. * @param string $htmlname Name of combo list
  279. * @param string $country_code Country Code
  280. * @return string HTML select list
  281. */
  282. public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
  283. {
  284. // phpcs:enable
  285. global $langs;
  286. $out = '';
  287. $sql = "SELECT r.taux, r.revenuestamp_type";
  288. $sql .= " FROM ".$this->db->prefix()."c_revenuestamp as r,".$this->db->prefix()."c_country as c";
  289. $sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
  290. $sql .= " AND c.code = '".$this->db->escape($country_code)."'";
  291. dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
  292. $resql = $this->db->query($sql);
  293. if ($resql) {
  294. $out .= '<select class="flat" name="'.$htmlname.'">';
  295. $num = $this->db->num_rows($resql);
  296. $i = 0;
  297. $out .= '<option value="0">&nbsp;</option>'."\n";
  298. if ($num) {
  299. while ($i < $num) {
  300. $obj = $this->db->fetch_object($resql);
  301. if (($selected && $selected == $obj->taux) || $num == 1) {
  302. $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
  303. } else {
  304. $out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
  305. }
  306. $out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
  307. $out .= '</option>';
  308. $i++;
  309. }
  310. }
  311. $out .= '</select>';
  312. return $out;
  313. } else {
  314. dol_print_error($this->db);
  315. return '';
  316. }
  317. }
  318. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  319. /**
  320. * Return a HTML select list to select a percent
  321. *
  322. * @param integer $selected pourcentage pre-selectionne
  323. * @param string $htmlname nom de la liste deroulante
  324. * @param int $disabled Disabled or not
  325. * @param int $increment increment value
  326. * @param int $start start value
  327. * @param int $end end value
  328. * @param int $showempty Add also an empty line
  329. * @return string HTML select string
  330. */
  331. public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
  332. {
  333. // phpcs:enable
  334. $return = '<select class="flat maxwidth75 right" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
  335. if ($showempty) {
  336. $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'>&nbsp;</option>';
  337. }
  338. for ($i = $start; $i <= $end; $i += $increment) {
  339. if ($selected != '' && (int) $selected == $i) {
  340. $return .= '<option value="'.$i.'" selected>';
  341. } else {
  342. $return .= '<option value="'.$i.'">';
  343. }
  344. $return .= $i.' % ';
  345. $return .= '</option>';
  346. }
  347. $return .= '</select>';
  348. return $return;
  349. }
  350. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  351. /**
  352. * Return select list for categories (to use in form search selectors)
  353. *
  354. * @param int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated.
  355. * @param integer $selected Preselected value
  356. * @param string $htmlname Name of combo list
  357. * @param int $nocateg Show also an entry "Not categorized"
  358. * @param int|string $showempty Add also an empty line
  359. * @param string $morecss More CSS
  360. * @return string Html combo list code
  361. * @see select_all_categories()
  362. */
  363. public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
  364. {
  365. // phpcs:enable
  366. global $conf, $langs;
  367. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  368. // For backward compatibility
  369. if (is_numeric($type)) {
  370. dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
  371. }
  372. // Load list of "categories"
  373. $static_categs = new Categorie($this->db);
  374. $tab_categs = $static_categs->get_full_arbo($type);
  375. $moreforfilter = '';
  376. // Print a select with each of them
  377. $moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
  378. if ($showempty) {
  379. $textforempty = ' ';
  380. if (!empty($conf->use_javascript_ajax)) {
  381. $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
  382. }
  383. if (!is_numeric($showempty)) {
  384. $textforempty = $showempty;
  385. }
  386. $moreforfilter .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '');
  387. //$moreforfilter .= ' data-html="'.dol_escape_htmltag($textforempty).'"';
  388. $moreforfilter .= '>'.dol_escape_htmltag($textforempty).'</option>'."\n";
  389. }
  390. if (is_array($tab_categs)) {
  391. foreach ($tab_categs as $categ) {
  392. $moreforfilter .= '<option value="'.$categ['id'].'"';
  393. if ($categ['id'] == $selected) {
  394. $moreforfilter .= ' selected';
  395. }
  396. $moreforfilter .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$categ['color'].'"').dol_trunc($categ['fulllabel'], 50, 'middle')).'"';
  397. $moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
  398. }
  399. }
  400. if ($nocateg) {
  401. $langs->load("categories");
  402. $moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
  403. }
  404. $moreforfilter .= '</select>';
  405. // Enhance with select2
  406. if ($conf->use_javascript_ajax) {
  407. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  408. $comboenhancement = ajax_combobox('select_categ_'.$htmlname);
  409. $moreforfilter .= $comboenhancement;
  410. }
  411. return $moreforfilter;
  412. }
  413. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  414. /**
  415. * Return select list for categories (to use in form search selectors)
  416. *
  417. * @param string $selected Preselected value
  418. * @param string $htmlname Name of combo list (example: 'search_sale')
  419. * @param User $user Object user
  420. * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
  421. * @param int|string $showempty 1=show also an empty value or text to show for empty
  422. * @param string $morecss More CSS
  423. * @param int $norepresentative Show also an entry "Not categorized"
  424. * @return string Html combo list code
  425. */
  426. public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
  427. {
  428. // phpcs:enable
  429. global $conf, $langs, $hookmanager;
  430. global $action;
  431. $langs->load('users');
  432. $out = '';
  433. $reshook = $hookmanager->executeHooks('addSQLWhereFilterOnSelectSalesRep', array(), $this, $action);
  434. // Select each sales and print them in a select input
  435. $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'">';
  436. if ($showempty) {
  437. $textforempty = ' ';
  438. if (!is_numeric($showempty)) {
  439. $textforempty = $showempty;
  440. }
  441. if (!empty($conf->use_javascript_ajax) && $textforempty == ' ') {
  442. $textforempty = '&nbsp;'; // If we use ajaxcombo, we need &nbsp; here to avoid to have an empty element that is too small.
  443. }
  444. $out .= '<option class="optiongrey" value="'.($showempty < 0 ? $showempty : -1).'"'.($selected == $showempty ? ' selected' : '').'>'.$textforempty.'</option>'."\n";
  445. }
  446. // Get list of users allowed to be viewed
  447. $sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
  448. $sql_usr .= " FROM ".$this->db->prefix()."user as u";
  449. if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
  450. if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
  451. $sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
  452. } else {
  453. $sql_usr .= " WHERE EXISTS (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (".getEntity('usergroup')."))";
  454. $sql_usr .= " OR u.entity = 0"; // Show always superadmin
  455. }
  456. } else {
  457. $sql_usr .= " WHERE u.entity IN (".getEntity('user').")";
  458. }
  459. if (!$user->hasRight('user', 'user', 'lire')) {
  460. $sql_usr .= " AND u.rowid = ".((int) $user->id);
  461. }
  462. if (!empty($user->socid)) {
  463. $sql_usr .= " AND u.fk_soc = ".((int) $user->socid);
  464. }
  465. //Add hook to filter on user (for exemple on usergroup define in custom modules)
  466. if (!empty($reshook)) {
  467. $sql_usr .= $hookmanager->resArray[0];
  468. }
  469. // Add existing sales representatives of thirdparty of external user
  470. if (!$user->hasRight('user', 'user', 'lire') && $user->socid) {
  471. $sql_usr .= " UNION ";
  472. $sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
  473. $sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
  474. if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
  475. if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
  476. $sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
  477. } else {
  478. $sql_usr .= " WHERE EXISTS (SELECT ug2.fk_user FROM ".$this->db->prefix()."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('usergroup')."))";
  479. }
  480. } else {
  481. $sql_usr .= " WHERE u2.entity IN (".getEntity('user').")";
  482. }
  483. $sql_usr .= " AND u2.rowid = sc.fk_user AND sc.fk_soc = ".((int) $user->socid);
  484. //Add hook to filter on user (for exemple on usergroup define in custom modules)
  485. if (!empty($reshook)) {
  486. $sql_usr .= $hookmanager->resArray[1];
  487. }
  488. }
  489. if (!getDolGlobalString('MAIN_FIRSTNAME_NAME_POSITION')) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
  490. $sql_usr .= " ORDER BY status DESC, firstname ASC, lastname ASC";
  491. } else {
  492. $sql_usr .= " ORDER BY status DESC, lastname ASC, firstname ASC";
  493. }
  494. //print $sql_usr;exit;
  495. $resql_usr = $this->db->query($sql_usr);
  496. if ($resql_usr) {
  497. $userstatic = new User($this->db);
  498. while ($obj_usr = $this->db->fetch_object($resql_usr)) {
  499. $userstatic->id = $obj_usr->rowid;
  500. $userstatic->lastname = $obj_usr->lastname;
  501. $userstatic->firstname = $obj_usr->firstname;
  502. $userstatic->photo = $obj_usr->photo;
  503. $userstatic->statut = $obj_usr->status;
  504. $userstatic->entity = $obj_usr->entity;
  505. $userstatic->admin = $obj_usr->admin;
  506. $labeltoshow = dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
  507. if (empty($obj_usr->firstname) && empty($obj_usr->lastname)) {
  508. $labeltoshow = $obj_usr->login;
  509. }
  510. $out .= '<option value="'.$obj_usr->rowid.'"';
  511. if ($obj_usr->rowid == $selected) {
  512. $out .= ' selected';
  513. }
  514. $out .= ' data-html="';
  515. $outhtml = $userstatic->getNomUrl(-3, '', 0, 1, 24, 1, 'login', '', 1).' ';
  516. if ($showstatus >= 0 && $obj_usr->status == 0) {
  517. $outhtml .= '<strike class="opacitymediumxxx">';
  518. }
  519. $outhtml .= $labeltoshow;
  520. if ($showstatus >= 0 && $obj_usr->status == 0) {
  521. $outhtml .= '</strike>';
  522. }
  523. $out .= dol_escape_htmltag($outhtml);
  524. $out .= '">';
  525. $out .= $labeltoshow;
  526. // Complete name with more info
  527. $moreinfo = 0;
  528. if (getDolGlobalString('MAIN_SHOW_LOGIN')) {
  529. $out .= ($moreinfo ? ' - ' : ' (').$obj_usr->login;
  530. $moreinfo++;
  531. }
  532. if ($showstatus >= 0) {
  533. if ($obj_usr->status == 1 && $showstatus == 1) {
  534. $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
  535. $moreinfo++;
  536. }
  537. if ($obj_usr->status == 0) {
  538. $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
  539. $moreinfo++;
  540. }
  541. }
  542. $out .= ($moreinfo ? ')' : '');
  543. $out .= '</option>';
  544. }
  545. $this->db->free($resql_usr);
  546. } else {
  547. dol_print_error($this->db);
  548. }
  549. if ($norepresentative) {
  550. $langs->load("companies");
  551. $out .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
  552. }
  553. $out .= '</select>';
  554. // Enhance with select2
  555. if ($conf->use_javascript_ajax) {
  556. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  557. $comboenhancement = ajax_combobox($htmlname);
  558. if ($comboenhancement) {
  559. $out .= $comboenhancement;
  560. }
  561. }
  562. return $out;
  563. }
  564. /**
  565. * Return list of project and tasks
  566. *
  567. * @param int $selectedtask Pre-selected task
  568. * @param int $projectid Project id
  569. * @param string $htmlname Name of html select
  570. * @param int $modeproject 1 to restrict on projects owned by user
  571. * @param int $modetask 1 to restrict on tasks associated to user
  572. * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
  573. * @param int $useempty 0=Allow empty values
  574. * @param int $disablechildoftaskid 1=Disable task that are child of the provided task id
  575. * @param string $filteronprojstatus Filter on project status ('-1'=no filter, '0,1'=Draft+Validated status)
  576. * @param string $morecss More css
  577. * @return void
  578. */
  579. public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
  580. {
  581. global $user, $langs;
  582. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  583. //print $modeproject.'-'.$modetask;
  584. $task = new Task($this->db);
  585. $tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
  586. if ($tasksarray) {
  587. print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  588. if ($useempty) {
  589. print '<option value="0">&nbsp;</option>';
  590. }
  591. $j = 0;
  592. $level = 0;
  593. $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
  594. print '</select>';
  595. print ajax_combobox($htmlname);
  596. } else {
  597. print '<div class="warning">'.$langs->trans("NoProject").'</div>';
  598. }
  599. }
  600. /**
  601. * Write lines of a project (all lines of a project if parent = 0)
  602. *
  603. * @param int $inc Cursor counter
  604. * @param int $parent Id of parent task we want to see
  605. * @param array $lines Array of task lines
  606. * @param int $level Level
  607. * @param int $selectedtask Id selected task
  608. * @param int $selectedproject Id selected project
  609. * @param int $disablechildoftaskid 1=Disable task that are child of the provided task id
  610. * @return void
  611. */
  612. private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
  613. {
  614. global $langs, $user, $conf;
  615. $lastprojectid = 0;
  616. $numlines = count($lines);
  617. for ($i = 0; $i < $numlines; $i++) {
  618. if ($lines[$i]->fk_task_parent == $parent) {
  619. //var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
  620. // Break on a new project
  621. if ($parent == 0) { // We are on a task at first level
  622. if ($lines[$i]->fk_project != $lastprojectid) { // Break found on project
  623. if ($i > 0) {
  624. print '<option value="0" disabled>----------</option>';
  625. }
  626. print '<option value="'.$lines[$i]->fk_project.'_0"';
  627. if ($selectedproject == $lines[$i]->fk_project) {
  628. print ' selected';
  629. }
  630. $labeltoshow = $lines[$i]->projectref;
  631. //$labeltoshow .= ' '.$lines[$i]->projectlabel;
  632. if (empty($lines[$i]->public)) {
  633. //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
  634. $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
  635. } else {
  636. //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
  637. $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
  638. }
  639. print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
  640. print '>'; // Project -> Task
  641. print $labeltoshow;
  642. print "</option>\n";
  643. $lastprojectid = $lines[$i]->fk_project;
  644. $inc++;
  645. }
  646. }
  647. $newdisablechildoftaskid = $disablechildoftaskid;
  648. // Print task
  649. if (isset($lines[$i]->id)) { // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
  650. // Check if we must disable entry
  651. $disabled = 0;
  652. if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_task_parent == $disablechildoftaskid))) {
  653. $disabled++;
  654. if ($lines[$i]->fk_task_parent == $disablechildoftaskid) {
  655. $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
  656. }
  657. }
  658. print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
  659. if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) {
  660. print ' selected';
  661. }
  662. if ($disabled) {
  663. print ' disabled';
  664. }
  665. $labeltoshow = $lines[$i]->projectref;
  666. //$labeltoshow .= ' '.$lines[$i]->projectlabel;
  667. if (empty($lines[$i]->public)) {
  668. //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')</span>';
  669. $labeltoshow = img_picto($lines[$i]->projectlabel, 'project', 'class="pictofixedwidth"').$labeltoshow;
  670. } else {
  671. //$labeltoshow .= ' <span class="opacitymedium">('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')</span>';
  672. $labeltoshow = img_picto($lines[$i]->projectlabel, 'projectpub', 'class="pictofixedwidth"').$labeltoshow;
  673. }
  674. if ($lines[$i]->id) {
  675. $labeltoshow .= ' > ';
  676. }
  677. for ($k = 0; $k < $level; $k++) {
  678. $labeltoshow .= "&nbsp;&nbsp;&nbsp;";
  679. }
  680. $labeltoshow .= $lines[$i]->ref.' '.$lines[$i]->label;
  681. print ' data-html="'.dol_escape_htmltag($labeltoshow).'"';
  682. print '>';
  683. print $labeltoshow;
  684. print "</option>\n";
  685. $inc++;
  686. }
  687. $level++;
  688. if ($lines[$i]->id) {
  689. $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
  690. }
  691. $level--;
  692. }
  693. }
  694. }
  695. /**
  696. * Output a HTML thumb of color or a text if not defined.
  697. *
  698. * @param string $color String with hex (FFFFFF) or comma RGB ('255,255,255')
  699. * @param string $textifnotdefined Text to show if color not defined
  700. * @return string Show color string
  701. * @see selectColor()
  702. */
  703. public static function showColor($color, $textifnotdefined = '')
  704. {
  705. $textcolor = 'FFF';
  706. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  707. if (colorIsLight($color)) {
  708. $textcolor = '000';
  709. }
  710. $color = colorArrayToHex(colorStringToArray($color, array()), '');
  711. if ($color) {
  712. return '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
  713. } else {
  714. return $textifnotdefined;
  715. }
  716. }
  717. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  718. /**
  719. * Output a HTML code to select a color
  720. *
  721. * @param string $set_color Pre-selected color
  722. * @param string $prefix Name of HTML field
  723. * @param string $form_name Deprecated. Not used.
  724. * @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
  725. * @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
  726. * @return void
  727. * @deprecated Use instead selectColor
  728. * @see selectColor()
  729. */
  730. public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
  731. {
  732. // phpcs:enable
  733. print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
  734. }
  735. /**
  736. * Output a HTML code to select a color. Field will return an hexa color like '334455'.
  737. *
  738. * @param string $set_color Pre-selected color with format '#......'
  739. * @param string $prefix Name of HTML field
  740. * @param string $form_name Deprecated. Not used.
  741. * @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
  742. * @param array $arrayofcolors Array of possible colors to choose in the selector. All colors are possible if empty. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
  743. * @param string $morecss Add css style into input field
  744. * @param string $setpropertyonselect Set this property after selecting a color
  745. * @param string $default Default color
  746. * @return string
  747. * @see showColor()
  748. */
  749. public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '', $setpropertyonselect = '', $default = '')
  750. {
  751. // Deprecation warning
  752. if ($form_name) {
  753. dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
  754. }
  755. global $langs, $conf;
  756. $out = '';
  757. if (!is_array($arrayofcolors) || count($arrayofcolors) < 1) {
  758. // Case of selection of any color
  759. $langs->load("other");
  760. if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax) && !getDolGlobalInt('MAIN_USE_HTML5_COLOR_SELECTOR')) {
  761. $out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
  762. $out .= '<script nonce="'.getNonce().'" type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
  763. $out .= '<script nonce="'.getNonce().'" type="text/javascript">
  764. jQuery(document).ready(function(){
  765. var originalhex = null;
  766. $(\'#colorpicker'.$prefix.'\').jPicker( {
  767. window: {
  768. title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
  769. effects:
  770. {
  771. type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
  772. speed:
  773. {
  774. show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
  775. hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
  776. }
  777. },
  778. position:
  779. {
  780. x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
  781. y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
  782. },
  783. },
  784. images: {
  785. clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
  786. picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
  787. },
  788. localization: // alter these to change the text presented by the picker (e.g. different language)
  789. {
  790. text:
  791. {
  792. title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
  793. newColor: \''.dol_escape_js($langs->trans("New")).'\',
  794. currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
  795. ok: \''.dol_escape_js($langs->trans("Validate")).'\',
  796. cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
  797. }
  798. }
  799. },
  800. function(color, context) { console.log("close color selector"); },
  801. function(color, context) { var hex = color.val(\'hex\'); console.log("new color selected in jpicker "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
  802. if ($setpropertyonselect) {
  803. $out .= 'if (originalhex == null) {';
  804. $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
  805. $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
  806. $out .= '}';
  807. $out .= 'if (hex != null) {';
  808. $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', \'#\'+hex);';
  809. $out .= '}';
  810. }
  811. $out .= '},
  812. function(color, context) {
  813. console.log("cancel selection of color");';
  814. if ($setpropertyonselect) {
  815. $out .= 'if (originalhex != null) {
  816. console.log("Restore old color "+originalhex);
  817. document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', originalhex);
  818. }';
  819. }
  820. $out .= '
  821. }
  822. );
  823. });
  824. </script>';
  825. $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
  826. } else {
  827. $color = ($set_color !== '' ? $set_color : ($default !== '' ? $default : 'FFFFFF'));
  828. $out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat input-nobottom colorselector valignmiddle '.($morecss ? ' '.$morecss : '').'" type="color" data-default="'.$default.'" value="'.dol_escape_htmltag(preg_match('/^#/', $color) ? $color : '#'.$color).'" />';
  829. $out .= '<script nonce="'.getNonce().'" type="text/javascript">
  830. jQuery(document).ready(function(){
  831. var originalhex = null;
  832. jQuery("#colorpicker'.$prefix.'").on(\'change\', function() {
  833. var hex = jQuery("#colorpicker'.$prefix.'").val();
  834. console.log("new color selected in input color "+hex+" setpropertyonselect='.dol_escape_js($setpropertyonselect).'");';
  835. if ($setpropertyonselect) {
  836. $out .= 'if (originalhex == null) {';
  837. $out .= ' originalhex = getComputedStyle(document.querySelector(":root")).getPropertyValue(\'--'.dol_escape_js($setpropertyonselect).'\');';
  838. $out .= ' console.log("original color is saved into originalhex = "+originalhex);';
  839. $out .= '}';
  840. $out .= 'if (hex != null) {';
  841. $out .= ' document.documentElement.style.setProperty(\'--'.dol_escape_js($setpropertyonselect).'\', hex);';
  842. $out .= '}';
  843. }
  844. $out .= '
  845. });
  846. });
  847. </script>';
  848. }
  849. } else {
  850. // In most cases, this is not used. We used instead function with no specific list of colors
  851. if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax)) {
  852. $out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
  853. $out .= '<script nonce="'.getNonce().'" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
  854. $out .= '<script nonce="'.getNonce().'" type="text/javascript">
  855. jQuery(document).ready(function(){
  856. jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
  857. size: 14,
  858. label: \'\',
  859. hide: true
  860. });
  861. });
  862. </script>';
  863. }
  864. $out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
  865. //print '<option value="-1">&nbsp;</option>';
  866. foreach ($arrayofcolors as $val) {
  867. $out .= '<option value="'.$val.'"';
  868. if ($set_color == $val) {
  869. $out .= ' selected';
  870. }
  871. $out .= '>'.$val.'</option>';
  872. }
  873. $out .= '</select>';
  874. }
  875. return $out;
  876. }
  877. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  878. /**
  879. * Creae an image for color
  880. *
  881. * @param string $color Color of image
  882. * @param string $module Name of module
  883. * @param string $name Name of image
  884. * @param int $x Largeur de l'image en pixels
  885. * @param int $y Hauteur de l'image en pixels
  886. * @return void
  887. */
  888. public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
  889. {
  890. // phpcs:enable
  891. global $conf;
  892. $file = $conf->$module->dir_temp.'/'.$name.'.png';
  893. // We create temp directory
  894. if (!file_exists($conf->$module->dir_temp)) {
  895. dol_mkdir($conf->$module->dir_temp);
  896. }
  897. // On cree l'image en vraies couleurs
  898. $image = imagecreatetruecolor($x, $y);
  899. $color = substr($color, 1, 6);
  900. $rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
  901. $vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
  902. $bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
  903. $couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
  904. //print $rouge.$vert.$bleu;
  905. imagefill($image, 0, 0, $couleur); //on remplit l'image
  906. // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
  907. ImagePng($image, $file); //renvoie une image sous format png
  908. ImageDestroy($image);
  909. }
  910. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  911. /**
  912. * Return HTML combo list of week
  913. *
  914. * @param string $selected Preselected value
  915. * @param string $htmlname Nom de la zone select
  916. * @param int $useempty Affiche valeur vide dans liste
  917. * @return string
  918. */
  919. public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
  920. {
  921. // phpcs:enable
  922. global $langs;
  923. $week = array(
  924. 0=>$langs->trans("Day0"),
  925. 1=>$langs->trans("Day1"),
  926. 2=>$langs->trans("Day2"),
  927. 3=>$langs->trans("Day3"),
  928. 4=>$langs->trans("Day4"),
  929. 5=>$langs->trans("Day5"),
  930. 6=>$langs->trans("Day6")
  931. );
  932. $select_week = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
  933. if ($useempty) {
  934. $select_week .= '<option value="-1">&nbsp;</option>';
  935. }
  936. foreach ($week as $key => $val) {
  937. if ($selected == $key) {
  938. $select_week .= '<option value="'.$key.'" selected>';
  939. } else {
  940. $select_week .= '<option value="'.$key.'">';
  941. }
  942. $select_week .= $val;
  943. $select_week .= '</option>';
  944. }
  945. $select_week .= '</select>';
  946. $select_week .= ajax_combobox($htmlname);
  947. return $select_week;
  948. }
  949. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  950. /**
  951. * Return HTML combo list of month
  952. *
  953. * @param string $selected Preselected value
  954. * @param string $htmlname Name of HTML select object
  955. * @param int $useempty Show empty in list
  956. * @param int $longlabel Show long label
  957. * @param string $morecss More Css
  958. * @param bool $addjscombo Add js combo
  959. * @return string
  960. */
  961. public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'minwidth50 maxwidth75imp valignmiddle', $addjscombo = false)
  962. {
  963. // phpcs:enable
  964. global $langs;
  965. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  966. if ($longlabel) {
  967. $montharray = monthArray($langs, 0); // Get array
  968. } else {
  969. $montharray = monthArray($langs, 1);
  970. }
  971. $select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
  972. if ($useempty) {
  973. $select_month .= '<option value="0">&nbsp;</option>';
  974. }
  975. foreach ($montharray as $key => $val) {
  976. if ($selected == $key) {
  977. $select_month .= '<option value="'.$key.'" selected>';
  978. } else {
  979. $select_month .= '<option value="'.$key.'">';
  980. }
  981. $select_month .= $val;
  982. $select_month .= '</option>';
  983. }
  984. $select_month .= '</select>';
  985. // Add code for jquery to use multiselect
  986. if ($addjscombo) {
  987. // Enhance with select2
  988. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  989. $select_month .= ajax_combobox($htmlname);
  990. }
  991. return $select_month;
  992. }
  993. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  994. /**
  995. * Return HTML combo list of years
  996. *
  997. * @param string $selected Preselected value (''=current year, -1=none, year otherwise)
  998. * @param string $htmlname Name of HTML select object
  999. * @param int $useempty Affiche valeur vide dans liste
  1000. * @param int $min_year Offset of minimum year into list (by default current year -10)
  1001. * @param int $max_year Offset of maximum year into list (by default current year + 5)
  1002. * @param int $offset Offset
  1003. * @param int $invert Invert
  1004. * @param string $option Option
  1005. * @param string $morecss More CSS
  1006. * @param bool $addjscombo Add js combo
  1007. * @return void
  1008. * @deprecated
  1009. */
  1010. public function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp', $addjscombo = false)
  1011. {
  1012. // phpcs:enable
  1013. print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss, $addjscombo);
  1014. }
  1015. /**
  1016. * Return HTML combo list of years
  1017. *
  1018. * @param string $selected Preselected value (''=current year, -1=none, year otherwise)
  1019. * @param string $htmlname Name of HTML select object
  1020. * @param int $useempty Affiche valeur vide dans liste
  1021. * @param int $min_year Offset of minimum year into list (by default current year -10)
  1022. * @param int $max_year Offset of maximum year into list (by default current year + 5)
  1023. * @param int $offset Offset
  1024. * @param int $invert Invert
  1025. * @param string $option Option
  1026. * @param string $morecss More css
  1027. * @param bool $addjscombo Add js combo
  1028. * @return string
  1029. */
  1030. public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle width75', $addjscombo = false)
  1031. {
  1032. $out = '';
  1033. $currentyear = date("Y") + $offset;
  1034. $max_year = $currentyear + $max_year;
  1035. $min_year = $currentyear - $min_year;
  1036. if (empty($selected) && empty($useempty)) {
  1037. $selected = $currentyear;
  1038. }
  1039. $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
  1040. if ($useempty) {
  1041. $selected_html = '';
  1042. if ($selected == '') {
  1043. $selected_html = ' selected';
  1044. }
  1045. $out .= '<option value=""'.$selected_html.'>&nbsp;</option>';
  1046. }
  1047. if (!$invert) {
  1048. for ($y = $max_year; $y >= $min_year; $y--) {
  1049. $selected_html = '';
  1050. if ($selected > 0 && $y == $selected) {
  1051. $selected_html = ' selected';
  1052. }
  1053. $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
  1054. }
  1055. } else {
  1056. for ($y = $min_year; $y <= $max_year; $y++) {
  1057. $selected_html = '';
  1058. if ($selected > 0 && $y == $selected) {
  1059. $selected_html = ' selected';
  1060. }
  1061. $out .= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
  1062. }
  1063. }
  1064. $out .= "</select>\n";
  1065. // Add code for jquery to use multiselect
  1066. if ($addjscombo) {
  1067. // Enhance with select2
  1068. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  1069. $out .= ajax_combobox($htmlname);
  1070. }
  1071. return $out;
  1072. }
  1073. /**
  1074. * Get array with HTML tabs with boxes of a particular area including personalized choices of user.
  1075. * Class 'Form' must be known.
  1076. *
  1077. * @param User $user Object User
  1078. * @param String $areacode Code of area for pages - 0 = Home page ... See getListOfPagesForBoxes()
  1079. * @return array array('selectboxlist'=>, 'boxactivated'=>, 'boxlista'=>, 'boxlistb'=>)
  1080. */
  1081. public static function getBoxesArea($user, $areacode)
  1082. {
  1083. global $conf, $langs, $db;
  1084. include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  1085. $confuserzone = 'MAIN_BOXES_'.$areacode;
  1086. // $boxactivated will be array of boxes enabled into global setup
  1087. // $boxidactivatedforuser will be array of boxes choosed by user
  1088. $selectboxlist = '';
  1089. $boxactivated = InfoBox::listBoxes($db, 'activated', $areacode, (empty($user->conf->$confuserzone) ? null : $user), array(), 0); // Search boxes of common+user (or common only if user has no specific setup)
  1090. $boxidactivatedforuser = array();
  1091. foreach ($boxactivated as $box) {
  1092. if (empty($user->conf->$confuserzone) || $box->fk_user == $user->id) {
  1093. $boxidactivatedforuser[$box->id] = $box->id; // We keep only boxes to show for user
  1094. }
  1095. }
  1096. // Define selectboxlist
  1097. $arrayboxtoactivatelabel = array();
  1098. if (!empty($user->conf->$confuserzone)) {
  1099. $boxorder = '';
  1100. $langs->load("boxes"); // Load label of boxes
  1101. foreach ($boxactivated as $box) {
  1102. if (!empty($boxidactivatedforuser[$box->id])) {
  1103. continue; // Already visible for user
  1104. }
  1105. $label = $langs->transnoentitiesnoconv($box->boxlabel);
  1106. //if (preg_match('/graph/',$box->class)) $label.=' ('.$langs->trans("Graph").')';
  1107. if (preg_match('/graph/', $box->class) && $conf->browser->layout != 'phone') {
  1108. $label = $label.' <span class="fas fa-chart-bar"></span>';
  1109. }
  1110. $arrayboxtoactivatelabel[$box->id] = array('label'=>$label, 'data-html'=>img_picto('', $box->boximg, 'class="pictofixedwidth"').$langs->trans($label)); // We keep only boxes not shown for user, to show into combo list
  1111. }
  1112. foreach ($boxidactivatedforuser as $boxid) {
  1113. if (empty($boxorder)) {
  1114. $boxorder .= 'A:';
  1115. }
  1116. $boxorder .= $boxid.',';
  1117. }
  1118. //var_dump($boxidactivatedforuser);
  1119. // Class Form must have been already loaded
  1120. $selectboxlist .= '<!-- Form with select box list -->'."\n";
  1121. $selectboxlist .= '<form id="addbox" name="addbox" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  1122. $selectboxlist .= '<input type="hidden" name="token" value="'.newToken().'">';
  1123. $selectboxlist .= '<input type="hidden" name="addbox" value="addbox">';
  1124. $selectboxlist .= '<input type="hidden" name="userid" value="'.$user->id.'">';
  1125. $selectboxlist .= '<input type="hidden" name="areacode" value="'.$areacode.'">';
  1126. $selectboxlist .= '<input type="hidden" name="boxorder" value="'.$boxorder.'">';
  1127. $selectboxlist .= Form::selectarray('boxcombo', $arrayboxtoactivatelabel, -1, $langs->trans("ChooseBoxToAdd").'...', 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth150onsmartphone hideonprint', 0, 'hidden selected', 0, 0);
  1128. if (empty($conf->use_javascript_ajax)) {
  1129. $selectboxlist .= ' <input type="submit" class="button" value="'.$langs->trans("AddBox").'">';
  1130. }
  1131. $selectboxlist .= '</form>';
  1132. if (!empty($conf->use_javascript_ajax)) {
  1133. include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
  1134. $selectboxlist .= ajax_combobox("boxcombo");
  1135. }
  1136. }
  1137. // Javascript code for dynamic actions
  1138. if (!empty($conf->use_javascript_ajax)) {
  1139. $selectboxlist .= '<script nonce="'.getNonce().'" type="text/javascript">
  1140. // To update list of activated boxes
  1141. function updateBoxOrder(closing) {
  1142. var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
  1143. var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
  1144. var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
  1145. if (boxorder==\'A:A-B:B\' && closing == 1) // There is no more boxes on screen, and we are after a delete of a box so we must hide title
  1146. {
  1147. jQuery.ajax({
  1148. url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=1&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
  1149. async: false
  1150. });
  1151. // We force reload to be sure to get all boxes into list
  1152. window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'&action=delbox&token='.newToken().'\';
  1153. }
  1154. else
  1155. {
  1156. jQuery.ajax({
  1157. url: \''.DOL_URL_ROOT.'/core/ajax/box.php?closing=\'+closing+\'&boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
  1158. async: true
  1159. });
  1160. }
  1161. }
  1162. jQuery(document).ready(function() {
  1163. jQuery("#boxcombo").change(function() {
  1164. var boxid=jQuery("#boxcombo").val();
  1165. if (boxid > 0) {
  1166. console.log("A box widget has been selected for addition, we call ajax page to add it.")
  1167. var left_list = cleanSerialize(jQuery("#boxhalfleft").sortable("serialize"));
  1168. var right_list = cleanSerialize(jQuery("#boxhalfright").sortable("serialize"));
  1169. var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
  1170. jQuery.ajax({
  1171. url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\'
  1172. }).done(function() {
  1173. window.location.search=\'mainmenu='.GETPOST("mainmenu", "aZ09").'&leftmenu='.GETPOST('leftmenu', "aZ09").'\';
  1174. });
  1175. }
  1176. });';
  1177. if (!count($arrayboxtoactivatelabel)) {
  1178. $selectboxlist .= 'jQuery("#boxcombo").hide();';
  1179. }
  1180. $selectboxlist .= '
  1181. jQuery("#boxhalfleft, #boxhalfright").sortable({
  1182. handle: \'.boxhandle\',
  1183. revert: \'invalid\',
  1184. items: \'.boxdraggable\',
  1185. containment: \'document\',
  1186. connectWith: \'#boxhalfleft, #boxhalfright\',
  1187. stop: function(event, ui) {
  1188. console.log("We moved box so we call updateBoxOrder with ajax actions");
  1189. updateBoxOrder(1); /* 1 to avoid message after a move */
  1190. }
  1191. });
  1192. jQuery(".boxclose").click(function() {
  1193. var self = this; // because JQuery can modify this
  1194. var boxid = self.id.substring(8);
  1195. if (boxid > 0) {
  1196. var label = jQuery(\'#boxlabelentry\'+boxid).val();
  1197. console.log("We close box "+boxid);
  1198. jQuery(\'#boxto_\'+boxid).remove();
  1199. jQuery(\'#boxcombo\').append(new Option(label, boxid));
  1200. updateBoxOrder(1); /* 1 to avoid message after a remove */
  1201. }
  1202. });
  1203. });'."\n";
  1204. $selectboxlist .= '</script>'."\n";
  1205. }
  1206. // Define boxlista and boxlistb
  1207. $boxlista = '';
  1208. $boxlistb = '';
  1209. $nbboxactivated = count($boxidactivatedforuser);
  1210. if ($nbboxactivated) {
  1211. // Load translation files required by the page
  1212. $langs->loadLangs(array("boxes", "projects"));
  1213. $emptybox = new ModeleBoxes($db);
  1214. $boxlista .= "\n<!-- Box left container -->\n";
  1215. // Define $box_max_lines
  1216. $box_max_lines = 5;
  1217. if (getDolGlobalString('MAIN_BOXES_MAXLINES')) {
  1218. $box_max_lines = $conf->global->MAIN_BOXES_MAXLINES;
  1219. }
  1220. $ii = 0;
  1221. foreach ($boxactivated as $key => $box) {
  1222. if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
  1223. continue;
  1224. }
  1225. if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
  1226. $box->box_order = 'A'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
  1227. }
  1228. if (preg_match('/^A/i', $box->box_order)) { // column A
  1229. $ii++;
  1230. //print 'box_id '.$boxactivated[$ii]->box_id.' ';
  1231. //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
  1232. // Show box
  1233. $box->loadBox($box_max_lines);
  1234. $boxlista .= $box->showBox(null, null, 1);
  1235. }
  1236. }
  1237. if ($conf->browser->layout != 'phone') {
  1238. $emptybox->box_id = 'A';
  1239. $emptybox->info_box_head = array();
  1240. $emptybox->info_box_contents = array();
  1241. $boxlista .= $emptybox->showBox(array(), array(), 1);
  1242. }
  1243. $boxlista .= "<!-- End box left container -->\n";
  1244. $boxlistb .= "\n<!-- Box right container -->\n";
  1245. $ii = 0;
  1246. foreach ($boxactivated as $key => $box) {
  1247. if ((!empty($user->conf->$confuserzone) && $box->fk_user == 0) || (empty($user->conf->$confuserzone) && $box->fk_user != 0)) {
  1248. continue;
  1249. }
  1250. if (empty($box->box_order) && $ii < ($nbboxactivated / 2)) {
  1251. $box->box_order = 'B'.sprintf("%02d", ($ii + 1)); // When box_order was not yet set to Axx or Bxx and is still 0
  1252. }
  1253. if (preg_match('/^B/i', $box->box_order)) { // colonne B
  1254. $ii++;
  1255. //print 'box_id '.$boxactivated[$ii]->box_id.' ';
  1256. //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
  1257. // Show box
  1258. $box->loadBox($box_max_lines);
  1259. $boxlistb .= $box->showBox(null, null, 1);
  1260. }
  1261. }
  1262. if ($conf->browser->layout != 'phone') {
  1263. $emptybox->box_id = 'B';
  1264. $emptybox->info_box_head = array();
  1265. $emptybox->info_box_contents = array();
  1266. $boxlistb .= $emptybox->showBox(array(), array(), 1);
  1267. }
  1268. $boxlistb .= "<!-- End box right container -->\n";
  1269. }
  1270. return array('selectboxlist'=>count($boxactivated) ? $selectboxlist : '', 'boxactivated'=>$boxactivated, 'boxlista'=>$boxlista, 'boxlistb'=>$boxlistb);
  1271. }
  1272. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
  1273. /**
  1274. * Return a HTML select list of a dictionary
  1275. *
  1276. * @param string $htmlname Name of select zone
  1277. * @param string $dictionarytable Dictionary table
  1278. * @param string $keyfield Field for key
  1279. * @param string $labelfield Label field
  1280. * @param string $selected Selected value
  1281. * @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.
  1282. * @param string $moreattrib More attributes on HTML select tag
  1283. * @return void
  1284. */
  1285. public function select_dictionary($htmlname, $dictionarytable, $keyfield = 'code', $labelfield = 'label', $selected = '', $useempty = 0, $moreattrib = '')
  1286. {
  1287. // phpcs:enable
  1288. global $langs, $conf;
  1289. $langs->load("admin");
  1290. $sql = "SELECT rowid, ".$keyfield.", ".$labelfield;
  1291. $sql .= " FROM ".$this->db->prefix().$dictionarytable;
  1292. $sql .= " ORDER BY ".$labelfield;
  1293. dol_syslog(get_class($this)."::select_dictionary", LOG_DEBUG);
  1294. $result = $this->db->query($sql);
  1295. if ($result) {
  1296. $num = $this->db->num_rows($result);
  1297. $i = 0;
  1298. if ($num) {
  1299. print '<select id="select'.$htmlname.'" class="flat selectdictionary" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>';
  1300. if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
  1301. print '<option value="-1">&nbsp;</option>';
  1302. }
  1303. while ($i < $num) {
  1304. $obj = $this->db->fetch_object($result);
  1305. if ($selected == $obj->rowid || $selected == $obj->{$keyfield}) {
  1306. print '<option value="'.$obj->{$keyfield}.'" selected>';
  1307. } else {
  1308. print '<option value="'.$obj->{$keyfield}.'">';
  1309. }
  1310. $label = ($langs->trans($dictionarytable.$obj->{$keyfield}) != $dictionarytable.$obj->{$labelfield} ? $langs->trans($dictionarytable.$obj->{$keyfield}) : $obj->{$labelfield});
  1311. print $label;
  1312. print '</option>';
  1313. $i++;
  1314. }
  1315. print "</select>";
  1316. } else {
  1317. print $langs->trans("DictionaryEmpty");
  1318. }
  1319. } else {
  1320. dol_print_error($this->db);
  1321. }
  1322. }
  1323. /**
  1324. * Return an html string with a select combo box to choose yes or no
  1325. *
  1326. * @param string $htmlname Name of html select field
  1327. * @param string $value Pre-selected value
  1328. * @param int $option 0 return automatic/manual, 1 return 1/0
  1329. * @param bool $disabled true or false
  1330. * @param int $useempty 1=Add empty line
  1331. * @return string See option
  1332. */
  1333. public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
  1334. {
  1335. global $langs;
  1336. $automatic = "automatic";
  1337. $manual = "manual";
  1338. if ($option) {
  1339. $automatic = "1";
  1340. $manual = "0";
  1341. }
  1342. $disabled = ($disabled ? ' disabled' : '');
  1343. $resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
  1344. if ($useempty) {
  1345. $resultautomanual .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'>&nbsp;</option>'."\n";
  1346. }
  1347. if (("$value" == 'automatic') || ($value == 1)) {
  1348. $resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
  1349. $resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
  1350. } else {
  1351. $selected = (($useempty && $value != '0' && $value != 'manual') ? '' : ' selected');
  1352. $resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
  1353. $resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
  1354. }
  1355. $resultautomanual .= '</select>'."\n";
  1356. return $resultautomanual;
  1357. }
  1358. /**
  1359. * Return HTML select list to select a group by field
  1360. *
  1361. * @param mixed $object Object analyzed
  1362. * @param array $search_groupby Array of preselected fields
  1363. * @param array $arrayofgroupby Array of groupby to fill
  1364. * @param string $morecss More CSS
  1365. * @param string $showempty '1' or 'text'
  1366. * @return string HTML string component
  1367. */
  1368. public function selectGroupByField($object, $search_groupby, &$arrayofgroupby, $morecss = 'minwidth200 maxwidth250', $showempty = '1')
  1369. {
  1370. global $langs, $extrafields, $form;
  1371. $arrayofgroupbylabel = array();
  1372. foreach ($arrayofgroupby as $key => $val) {
  1373. $arrayofgroupbylabel[$key] = $val['label'];
  1374. }
  1375. $result = $form->selectarray('search_groupby', $arrayofgroupbylabel, $search_groupby, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
  1376. return $result;
  1377. }
  1378. /**
  1379. * Return HTML select list to select a group by field
  1380. *
  1381. * @param mixed $object Object analyzed
  1382. * @param array $search_xaxis Array of preselected fields
  1383. * @param array $arrayofxaxis Array of groupby to fill
  1384. * @param string $showempty '1' or 'text'
  1385. * @param string $morecss More css
  1386. * @return string HTML string component
  1387. */
  1388. public function selectXAxisField($object, $search_xaxis, &$arrayofxaxis, $showempty = '1', $morecss = 'minwidth250 maxwidth500')
  1389. {
  1390. global $form;
  1391. $arrayofxaxislabel = array();
  1392. foreach ($arrayofxaxis as $key => $val) {
  1393. $arrayofxaxislabel[$key] = $val['label'];
  1394. }
  1395. $result = $form->selectarray('search_xaxis', $arrayofxaxislabel, $search_xaxis, $showempty, 0, 0, '', 0, 0, 0, '', $morecss, 1);
  1396. return $result;
  1397. }
  1398. }