html.formother.class.php 61 KB

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