html.formother.class.php 61 KB

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