html.formother.class.php 48 KB

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