html.formother.class.php 51 KB

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