html.formother.class.php 45 KB

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