html.formother.class.php 59 KB

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