html.formother.class.php 49 KB

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