PageRenderTime 51ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/core/class/html.formother.class.php

https://github.com/asterix14/dolibarr
PHP | 729 lines | 467 code | 68 blank | 194 comment | 77 complexity | 373bf514077d8976f26803f530fedc1b MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 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-2011 Regis Houssin <regis@dolibarr.fr>
  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 2 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. * \class FormOther
  33. * \brief Classe permettant la generation de composants html autre
  34. * \remarks Only common components must be here.
  35. */
  36. class FormOther
  37. {
  38. var $db;
  39. var $error;
  40. /**
  41. * Constructeur
  42. * @param DB Database handler
  43. */
  44. function FormOther($DB)
  45. {
  46. $this->db = $DB;
  47. return 1;
  48. }
  49. /**
  50. * Return HTML select list of export models
  51. * @param selected Id modele pre-selectionne
  52. * @param htmlname Nom de la zone select
  53. * @param type Type des modeles recherches
  54. * @param useempty Affiche valeur vide dans liste
  55. */
  56. function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
  57. {
  58. $sql = "SELECT rowid, label";
  59. $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
  60. $sql.= " WHERE type = '".$type."'";
  61. $sql.= " ORDER BY rowid";
  62. $result = $this->db->query($sql);
  63. if ($result)
  64. {
  65. print '<select class="flat" name="'.$htmlname.'">';
  66. if ($useempty)
  67. {
  68. print '<option value="-1">&nbsp;</option>';
  69. }
  70. $num = $this->db->num_rows($result);
  71. $i = 0;
  72. while ($i < $num)
  73. {
  74. $obj = $this->db->fetch_object($result);
  75. if ($selected == $obj->rowid)
  76. {
  77. print '<option value="'.$obj->rowid.'" selected="selected">';
  78. }
  79. else
  80. {
  81. print '<option value="'.$obj->rowid.'">';
  82. }
  83. print $obj->label;
  84. print '</option>';
  85. $i++;
  86. }
  87. print "</select>";
  88. }
  89. else {
  90. dol_print_error($this->db);
  91. }
  92. }
  93. /**
  94. * Return list of export models
  95. * @param selected Id modele pre-selectionne
  96. * @param htmlname Nom de la zone select
  97. * @param type Type des modeles recherches
  98. * @param useempty Affiche valeur vide dans liste
  99. */
  100. function select_import_model($selected='',$htmlname='importmodelid',$type='',$useempty=0)
  101. {
  102. $sql = "SELECT rowid, label";
  103. $sql.= " FROM ".MAIN_DB_PREFIX."import_model";
  104. $sql.= " WHERE type = '".$type."'";
  105. $sql.= " ORDER BY rowid";
  106. $result = $this->db->query($sql);
  107. if ($result)
  108. {
  109. print '<select class="flat" name="'.$htmlname.'">';
  110. if ($useempty)
  111. {
  112. print '<option value="-1">&nbsp;</option>';
  113. }
  114. $num = $this->db->num_rows($result);
  115. $i = 0;
  116. while ($i < $num)
  117. {
  118. $obj = $this->db->fetch_object($result);
  119. if ($selected == $obj->rowid)
  120. {
  121. print '<option value="'.$obj->rowid.'" selected="selected">';
  122. }
  123. else
  124. {
  125. print '<option value="'.$obj->rowid.'">';
  126. }
  127. print $obj->label;
  128. print '</option>';
  129. $i++;
  130. }
  131. print "</select>";
  132. }
  133. else {
  134. dol_print_error($this->db);
  135. }
  136. }
  137. /**
  138. * Retourne la liste des ecotaxes avec tooltip sur le libelle
  139. * @param selected code ecotaxes pre-selectionne
  140. * @param htmlname nom de la liste deroulante
  141. */
  142. function select_ecotaxes($selected='',$htmlname='ecotaxe_id')
  143. {
  144. global $langs;
  145. $sql = "SELECT e.rowid, e.code, e.libelle, e.price, e.organization,";
  146. $sql.= " p.libelle as pays";
  147. $sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_pays as p";
  148. $sql.= " WHERE e.active = 1 AND e.fk_pays = p.rowid";
  149. $sql.= " ORDER BY pays, e.organization ASC, e.code ASC";
  150. $resql=$this->db->query($sql);
  151. if ($resql)
  152. {
  153. print '<select class="flat" name="'.$htmlname.'">';
  154. $num = $this->db->num_rows($resql);
  155. $i = 0;
  156. print '<option value="-1">&nbsp;</option>'."\n";
  157. if ($num)
  158. {
  159. while ($i < $num)
  160. {
  161. $obj = $this->db->fetch_object($resql);
  162. if ($selected && $selected == $obj->rowid)
  163. {
  164. print '<option value="'.$obj->rowid.'" selected="selected">';
  165. }
  166. else
  167. {
  168. print '<option value="'.$obj->rowid.'">';
  169. //print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
  170. }
  171. $selectOptionValue = $obj->code.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
  172. print $selectOptionValue;
  173. print '</option>';
  174. $i++;
  175. }
  176. }
  177. print '</select>';
  178. return 0;
  179. }
  180. else
  181. {
  182. dol_print_error($this->db);
  183. return 1;
  184. }
  185. }
  186. /**
  187. * Return a HTML select list to select a percent
  188. * @param selected pourcentage pre-selectionne
  189. * @param htmlname nom de la liste deroulante
  190. * @param increment increment value
  191. * @param start start value
  192. * @param end end value
  193. * @return return combo
  194. */
  195. function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100)
  196. {
  197. $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled="disabled"':'').'>';
  198. for ($i = $start ; $i <= $end ; $i += $increment)
  199. {
  200. if ($selected == $i)
  201. {
  202. $return.= '<option value="'.$i.'" selected="selected">';
  203. }
  204. else
  205. {
  206. $return.= '<option value="'.$i.'">';
  207. }
  208. $return.= $i.' % ';
  209. $return.= '</option>';
  210. }
  211. $return.= '</select>';
  212. return $return;
  213. }
  214. /**
  215. * Return select list for categories (to use in form search selectors)
  216. * @param type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
  217. * @param selected Preselected value
  218. * @param htmlname Name of combo list
  219. * @return return Html combo list code
  220. */
  221. function select_categories($type,$selected=0,$htmlname='search_categ')
  222. {
  223. global $langs;
  224. require_once(DOL_DOCUMENT_ROOT."/categories/class/categorie.class.php");
  225. // Load list of "categories"
  226. $static_categs = new Categorie($this->db);
  227. $tab_categs = $static_categs->get_full_arbo($type);
  228. // Print a select with each of them
  229. $moreforfilter ='<select class="flat" name="'.$htmlname.'">';
  230. $moreforfilter.='<option value="">&nbsp;</option>';
  231. if (is_array($tab_categs))
  232. {
  233. foreach ($tab_categs as $categ)
  234. {
  235. $moreforfilter.='<option value="'.$categ['id'].'"';
  236. if ($categ['id'] == $selected) $moreforfilter.=' selected="selected"';
  237. $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
  238. }
  239. }
  240. $moreforfilter.='</select>';
  241. return $moreforfilter;
  242. }
  243. /**
  244. * Return select list for categories (to use in form search selectors)
  245. * @param selected Preselected value
  246. * @param htmlname Name of combo list
  247. * @param user Object user
  248. * @return return Html combo list code
  249. */
  250. function select_salesrepresentatives($selected=0,$htmlname='search_sale',$user)
  251. {
  252. global $conf;
  253. // Select each sales and print them in a select input
  254. $moreforfilter ='<select class="flat" name="'.$htmlname.'">';
  255. $moreforfilter.='<option value="">&nbsp;</option>';
  256. // Get list of users allowed to be viewed
  257. $sql_usr = "SELECT u.rowid, u.name as name, u.firstname, u.login";
  258. $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
  259. $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
  260. if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.fk_societe = ".($user->societe_id?$user->societe_id:0);
  261. // Add existing sales representatives of company
  262. if (empty($user->rights->user->user->lire) && $user->societe_id)
  263. {
  264. $sql_usr.=" UNION ";
  265. $sql_usr.= "SELECT u2.rowid, u2.name as name, u2.firstname, u2.login";
  266. $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  267. $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
  268. $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
  269. }
  270. $sql_usr.= " ORDER BY name ASC";
  271. //print $sql_usr;exit;
  272. $resql_usr = $this->db->query($sql_usr);
  273. if ($resql_usr)
  274. {
  275. while ($obj_usr = $this->db->fetch_object($resql_usr))
  276. {
  277. $moreforfilter.='<option value="'.$obj_usr->rowid.'"';
  278. if ($obj_usr->rowid == $selected) $moreforfilter.=' selected="selected"';
  279. $moreforfilter.='>';
  280. $moreforfilter.=$obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
  281. $moreforfilter.='</option>';
  282. $i++;
  283. }
  284. $this->db->free($resql_usr);
  285. }
  286. else
  287. {
  288. dol_print_error($this->db);
  289. }
  290. $moreforfilter.='</select>';
  291. return $moreforfilter;
  292. }
  293. /**
  294. * Return list of project and tasks
  295. * @param selectedtask Pre-selected task
  296. * @param projectid Project id
  297. * @param htmlname Name of html select
  298. * @param modeproject 1 to restrict on projects owned by user
  299. * @param modetask 1 to restrict on tasks associated to user
  300. * @param mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
  301. * @param useempty 0=Allow empty values
  302. */
  303. function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0)
  304. {
  305. global $user, $langs;
  306. require_once(DOL_DOCUMENT_ROOT."/projet/class/task.class.php");
  307. //print $modeproject.'-'.$modetask;
  308. $task=new Task($this->db);
  309. $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode);
  310. if ($tasksarray)
  311. {
  312. print '<select class="flat" name="'.$htmlname.'">';
  313. if ($useempty) print '<option value="0">&nbsp;</option>';
  314. $j=0;
  315. $level=0;
  316. PLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid);
  317. print '</select>';
  318. }
  319. else
  320. {
  321. print '<div class="warning">'.$langs->trans("NoProject").'</div>';
  322. }
  323. }
  324. /**
  325. * Output a HTML code to select a color
  326. * @param set_color Pre-selected color
  327. * @param prefix Name of HTML field
  328. * @param form_name Name of form
  329. * @param showcolorbox 1=Show color code and color box, 0=Show only color code
  330. * @param arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
  331. */
  332. function select_color($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='')
  333. {
  334. global $langs;
  335. if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
  336. {
  337. $langs->load("other");
  338. print '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
  339. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
  340. print '<script type="text/javascript">
  341. jQuery(document).ready(function(){
  342. $(\'#colorpicker'.$prefix.'\').jPicker( {
  343. window: {
  344. title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
  345. effects:
  346. {
  347. type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
  348. speed:
  349. {
  350. show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
  351. hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
  352. }
  353. },
  354. position:
  355. {
  356. x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
  357. y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
  358. },
  359. },
  360. images: {
  361. clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
  362. picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
  363. },
  364. localization: // alter these to change the text presented by the picker (e.g. different language)
  365. {
  366. text:
  367. {
  368. title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
  369. newColor: \''.dol_escape_js($langs->trans("New")).'\',
  370. currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
  371. ok: \''.dol_escape_js($langs->trans("Change")).'\',
  372. cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
  373. }
  374. }
  375. } ); });
  376. </script>';
  377. print '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat" type="text" value="'.$set_color.'" />';
  378. /*
  379. // No list of colors forced, we can suggest any color
  380. print "\n".'<table class="nobordernopadding"><tr><td valign="middle">';
  381. print '<script type="text/javascript" src="'.DOL_URL_ROOT.'/core/lib/lib_colorpicker.js"></script>'."\n";
  382. print '<script type="text/javascript">
  383. window.onload = function()
  384. {
  385. fctLoad();
  386. }
  387. window.onscroll = function()
  388. {
  389. fctShow();
  390. }
  391. window.onresize = function()
  392. {
  393. fctShow();
  394. }
  395. </script>'."\n";
  396. print '<input type="text" size="10" name="'.$prefix.'" value="'.$set_color.'" maxlength="7" class="flat">'."\n";
  397. print '</td><td valign="middle">';
  398. print '<img src="'.DOL_URL_ROOT.'/theme/common/colorpicker.png" width="21" height="18" border="0" onClick="fctShow(document.'.$form_name.'.'.$prefix.');" style="cursor:pointer;">'."\n";
  399. print '</td>';
  400. if ($showcolorbox)
  401. {
  402. print '<td style="padding-left: 4px" nowrap="nowrap">';
  403. print '<!-- Box color '.$set_color.' -->';
  404. print '<table style="border-collapse: collapse; margin:0px; padding: 0px; border: 1px solid #888888; background: #'.(preg_replace('/#/','',$set_color)).';" width="12" height="10">';
  405. print '<tr class="nocellnopadd"><td></td></tr>';
  406. print '</table>';
  407. print '</td>';
  408. }
  409. print '</tr></table>';
  410. */
  411. }
  412. else // In most cases, this is not used. We used instead function with no specific list of colors
  413. {
  414. print '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
  415. print '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
  416. print '<script type="text/javascript">
  417. jQuery(document).ready(function(){
  418. jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
  419. size: 14,
  420. label: \'\',
  421. hide: true
  422. });
  423. });
  424. </script>';
  425. print '<select id="colorpicker'.$prefix.'" class="flat" name="'.$prefix.'">';
  426. //print '<option value="-1">&nbsp;</option>';
  427. foreach ($arrayofcolors as $val)
  428. {
  429. print '<option value="'.$val.'"';
  430. if ($set_color == $val) print ' selected="selected"';
  431. print '>'.$val.'</option>';
  432. }
  433. print '</select>';
  434. }
  435. }
  436. /**
  437. * Creation d'un icone de couleur
  438. * @param color Couleur de l'image
  439. * @param module Nom du module
  440. * @param name Nom de l'image
  441. * @param x Largeur de l'image en pixels
  442. * @param y Hauteur de l'image en pixels
  443. */
  444. function CreateColorIcon($color,$module,$name,$x='12',$y='12')
  445. {
  446. global $conf;
  447. $file = $conf->$module->dir_temp.'/'.$name.'.png';
  448. // On cree le repertoire contenant les icones
  449. if (! file_exists($conf->$module->dir_temp))
  450. {
  451. create_exdir($conf->$module->dir_temp);
  452. }
  453. // On cree l'image en vraies couleurs
  454. $image = imagecreatetruecolor($x,$y);
  455. $color = substr($color,1,6);
  456. $rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
  457. $vert = hexdec(substr($color,2,2)); //conversion du canal vert
  458. $bleu = hexdec(substr($color,4,2)); //conversion du canal bleu
  459. $couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
  460. //print $rouge.$vert.$bleu;
  461. imagefill($image,0,0,$couleur); //on remplit l'image
  462. // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
  463. ImagePng($image,$file); //renvoie une image sous format png
  464. ImageDestroy($image);
  465. }
  466. /**
  467. * Return HTML combo list of week
  468. * @param selected Preselected value
  469. * @param htmlname Nom de la zone select
  470. * @param useempty Affiche valeur vide dans liste
  471. */
  472. function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
  473. {
  474. global $langs;
  475. $week = array( 0=>$langs->trans("Day0"),
  476. 1=>$langs->trans("Day1"),
  477. 2=>$langs->trans("Day2"),
  478. 3=>$langs->trans("Day3"),
  479. 4=>$langs->trans("Day4"),
  480. 5=>$langs->trans("Day5"),
  481. 6=>$langs->trans("Day6"));
  482. $select_week = '<select class="flat" name="'.$htmlname.'">';
  483. if ($useempty)
  484. {
  485. $select_week .= '<option value="-1">&nbsp;</option>';
  486. }
  487. foreach ($week as $key => $val)
  488. {
  489. if ($selected == $key)
  490. {
  491. $select_week .= '<option value="'.$key.'" selected="selected">';
  492. }
  493. else
  494. {
  495. $select_week .= '<option value="'.$key.'">';
  496. }
  497. $select_week .= $val;
  498. }
  499. $select_week .= '</select>';
  500. return $select_week;
  501. }
  502. /**
  503. * Return HTML combo list of month
  504. * @param selected Preselected value
  505. * @param htmlname Nom de la zone select
  506. * @param useempty Affiche valeur vide dans liste
  507. */
  508. function select_month($selected='',$htmlname='monthid',$useempty=0)
  509. {
  510. require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  511. $month = monthArrayOrSelected(-1); // Get array
  512. $select_month = '<select class="flat" name="'.$htmlname.'">';
  513. if ($useempty)
  514. {
  515. $select_month .= '<option value="0">&nbsp;</option>';
  516. }
  517. foreach ($month as $key => $val)
  518. {
  519. if ($selected == $key)
  520. {
  521. $select_month .= '<option value="'.$key.'" selected="selected">';
  522. }
  523. else
  524. {
  525. $select_month .= '<option value="'.$key.'">';
  526. }
  527. $select_month .= $val;
  528. }
  529. $select_month .= '</select>';
  530. return $select_month;
  531. }
  532. /**
  533. * Return HTML combo list of years
  534. * @param selected Preselected value (''=current year, -1=none, year otherwise)
  535. * @param htmlname Name of HTML select object
  536. * @param useempty Affiche valeur vide dans liste
  537. * @param $min_year Offset of minimum year into list (by default current year -10)
  538. * @param $max_year Offset of maximum year into list (by default current year + 5)
  539. */
  540. function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
  541. {
  542. print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option);
  543. }
  544. /**
  545. * Return HTML combo list of years
  546. * @param selected Preselected value (''=current year, -1=none, year otherwise)
  547. * @param htmlname Name of HTML select object
  548. * @param useempty Affiche valeur vide dans liste
  549. * @param $min_year Offset of minimum year into list (by default current year -10)
  550. * @param $max_year Offset of maximum year into list (by default current year + 5)
  551. */
  552. function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
  553. {
  554. $out='';
  555. $currentyear = date("Y")+$offset;
  556. $max_year = $currentyear+$max_year;
  557. $min_year = $currentyear-$min_year;
  558. if(empty($selected)) $selected = $currentyear;
  559. $out.= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
  560. if($useempty)
  561. {
  562. if ($selected == '') $selected_html = ' selected="selected"';
  563. $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
  564. }
  565. if (! $invert)
  566. {
  567. for ($y = $max_year; $y >= $min_year; $y--)
  568. {
  569. $selected_html='';
  570. if ($selected > 0 && $y == $selected) $selected_html = ' selected="selected"';
  571. $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
  572. }
  573. }
  574. else
  575. {
  576. for ($y = $min_year; $y <= $max_year; $y++)
  577. {
  578. $selected_html='';
  579. if ($selected > 0 && $y == $selected) $selected_html = ' selected="selected"';
  580. $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
  581. }
  582. }
  583. $out.= "</select>\n";
  584. return $out;
  585. }
  586. }
  587. /**
  588. * Write all lines of a project (if parent = 0)
  589. * @param $inc
  590. * @param $parent
  591. * @param $lines
  592. * @param $level
  593. * @param $selectedtask
  594. * @param $selectedproject
  595. */
  596. function PLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0)
  597. {
  598. global $langs, $user, $conf;
  599. $lastprojectid=0;
  600. $numlines=count($lines);
  601. for ($i = 0 ; $i < $numlines ; $i++)
  602. {
  603. if ($lines[$i]->fk_parent == $parent)
  604. {
  605. $var = !$var;
  606. // Break on a new project
  607. if ($parent == 0)
  608. {
  609. if ($lines[$i]->fk_project != $lastprojectid)
  610. {
  611. if ($i > 0 && $conf->browser->firefox) print '<option value="0" disabled="disabled">----------</option>';
  612. print '<option value="'.$lines[$i]->fk_project.'_0"';
  613. if ($selectedproject == $lines[$i]->fk_project) print ' selected="selected"';
  614. print '>'; // Project -> Task
  615. print $langs->trans("Project").' '.$lines[$i]->projectref;
  616. if (empty($lines[$i]->public))
  617. {
  618. print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
  619. }
  620. else
  621. {
  622. print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
  623. }
  624. //print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
  625. print "</option>\n";
  626. $lastprojectid=$lines[$i]->fk_project;
  627. $inc++;
  628. }
  629. }
  630. // Print task
  631. if ($lines[$i]->id > 0)
  632. {
  633. print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
  634. if ($lines[$i]->id == $selectedtask) print ' selected="selected"';
  635. print '>';
  636. print $langs->trans("Project").' '.$lines[$i]->projectref;
  637. if (empty($lines[$i]->public))
  638. {
  639. print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
  640. }
  641. else
  642. {
  643. print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
  644. }
  645. if ($lines[$i]->id) print ' > ';
  646. for ($k = 0 ; $k < $level ; $k++)
  647. {
  648. print "&nbsp;&nbsp;&nbsp;";
  649. }
  650. print $lines[$i]->label."</option>\n";
  651. $inc++;
  652. }
  653. $level++;
  654. if ($lines[$i]->id) PLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject);
  655. $level--;
  656. }
  657. }
  658. }
  659. ?>