PageRenderTime 56ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://bitbucket.org/speedealing/speedealing
PHP | 1045 lines | 694 code | 109 blank | 242 comment | 100 complexity | 87414b654de06819240469afdb17a85b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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. * Copyright (C) 2010-2011 Herve Prot <herve.prot@symeos.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 3 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. */
  27. /**
  28. * \file htdocs/core/class/html.formother.class.php
  29. * \ingroup core
  30. * \brief Fichier de la classe des fonctions predefinie de composants html autre
  31. */
  32. /**
  33. * Classe permettant la generation de composants html autre
  34. * Only common components are here.
  35. */
  36. class FormOther
  37. {
  38. var $db;
  39. var $error;
  40. /**
  41. * Constructor
  42. *
  43. * @param DoliDB $db Database handler
  44. */
  45. function __construct($db = '')
  46. {
  47. $this->db = $db;
  48. return 1;
  49. }
  50. /**
  51. * Return HTML select list of export models
  52. *
  53. * @param string $selected Id modele pre-selectionne
  54. * @param string $htmlname Nom de la zone select
  55. * @param string $type Type des modeles recherches
  56. * @param int $useempty Affiche valeur vide dans liste
  57. * @return void
  58. */
  59. function select_export_model($selected='',$htmlname='exportmodelid',$type='',$useempty=0)
  60. {
  61. $sql = "SELECT rowid, label";
  62. $sql.= " FROM ".MAIN_DB_PREFIX."export_model";
  63. $sql.= " WHERE type = '".$type."'";
  64. $sql.= " ORDER BY rowid";
  65. $result = $this->db->query($sql);
  66. if ($result)
  67. {
  68. print '<select class="flat" name="'.$htmlname.'">';
  69. if ($useempty)
  70. {
  71. print '<option value="-1">&nbsp;</option>';
  72. }
  73. $num = $this->db->num_rows($result);
  74. $i = 0;
  75. while ($i < $num)
  76. {
  77. $obj = $this->db->fetch_object($result);
  78. if ($selected == $obj->rowid)
  79. {
  80. print '<option value="'.$obj->rowid.'" selected="selected">';
  81. }
  82. else
  83. {
  84. print '<option value="'.$obj->rowid.'">';
  85. }
  86. print $obj->label;
  87. print '</option>';
  88. $i++;
  89. }
  90. print "</select>";
  91. }
  92. else {
  93. dol_print_error($this->db);
  94. }
  95. }
  96. /**
  97. * Return list of export models
  98. *
  99. * @param string $selected Id modele pre-selectionne
  100. * @param string $htmlname Nom de la zone select
  101. * @param string $type Type des modeles recherches
  102. * @param int $useempty Affiche valeur vide dans liste
  103. * @return void
  104. */
  105. function select_import_model($selected='',$htmlname='importmodelid',$type='',$useempty=0)
  106. {
  107. $sql = "SELECT rowid, label";
  108. $sql.= " FROM ".MAIN_DB_PREFIX."import_model";
  109. $sql.= " WHERE type = '".$type."'";
  110. $sql.= " ORDER BY rowid";
  111. $result = $this->db->query($sql);
  112. if ($result)
  113. {
  114. print '<select class="flat" name="'.$htmlname.'">';
  115. if ($useempty)
  116. {
  117. print '<option value="-1">&nbsp;</option>';
  118. }
  119. $num = $this->db->num_rows($result);
  120. $i = 0;
  121. while ($i < $num)
  122. {
  123. $obj = $this->db->fetch_object($result);
  124. if ($selected == $obj->rowid)
  125. {
  126. print '<option value="'.$obj->rowid.'" selected="selected">';
  127. }
  128. else
  129. {
  130. print '<option value="'.$obj->rowid.'">';
  131. }
  132. print $obj->label;
  133. print '</option>';
  134. $i++;
  135. }
  136. print "</select>";
  137. }
  138. else {
  139. dol_print_error($this->db);
  140. }
  141. }
  142. /**
  143. * Retourne la liste des ecotaxes avec tooltip sur le libelle
  144. *
  145. * @param string $selected code ecotaxes pre-selectionne
  146. * @param string $htmlname nom de la liste deroulante
  147. * @return void
  148. */
  149. function select_ecotaxes($selected='',$htmlname='ecotaxe_id')
  150. {
  151. global $langs;
  152. $sql = "SELECT e.rowid, e.code, e.libelle, e.price, e.organization,";
  153. $sql.= " p.libelle as pays";
  154. $sql.= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_pays as p";
  155. $sql.= " WHERE e.active = 1 AND e.fk_pays = p.rowid";
  156. $sql.= " ORDER BY pays, e.organization ASC, e.code ASC";
  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 a HTML select list to select a percent
  195. *
  196. * @param string $selected pourcentage pre-selectionne
  197. * @param string $htmlname nom de la liste deroulante
  198. * @param int $disabled Disabled or not
  199. * @param int $increment increment value
  200. * @param int $start start value
  201. * @param int $end end value
  202. * @return string HTML select string
  203. */
  204. function select_percent($selected=0,$htmlname='percent',$disabled=0,$increment=5,$start=0,$end=100)
  205. {
  206. $return = '<select class="flat" name="'.$htmlname.'" '.($disabled?'disabled="disabled"':'').'>';
  207. for ($i = $start ; $i <= $end ; $i += $increment)
  208. {
  209. if ($selected == $i)
  210. {
  211. $return.= '<option value="'.$i.'" selected="selected">';
  212. }
  213. else
  214. {
  215. $return.= '<option value="'.$i.'">';
  216. }
  217. $return.= $i.' % ';
  218. $return.= '</option>';
  219. }
  220. $return.= '</select>';
  221. return $return;
  222. }
  223. /**
  224. * Return select list for categories (to use in form search selectors)
  225. *
  226. * @param int $type Type of categories (0=product, 1=suppliers, 2=customers, 3=members)
  227. * @param string $selected Preselected value
  228. * @param string $htmlname Name of combo list
  229. * @param int $nocateg Show also an entry "Not categorized"
  230. * @return string Html combo list code
  231. */
  232. function select_categories($type,$selected=0,$htmlname='search_categ',$nocateg=0)
  233. {
  234. global $langs;
  235. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  236. // Load list of "categories"
  237. $static_categs = new Categorie($this->db);
  238. $tab_categs = $static_categs->get_full_arbo($type);
  239. // Print a select with each of them
  240. $moreforfilter ='<select class="flat" name="'.$htmlname.'">';
  241. $moreforfilter.='<option value="">&nbsp;</option>'; // Should use -1 to say nothing
  242. if (is_array($tab_categs))
  243. {
  244. foreach ($tab_categs as $categ)
  245. {
  246. $moreforfilter.='<option value="'.$categ['id'].'"';
  247. if ($categ['id'] == $selected) $moreforfilter.=' selected="selected"';
  248. $moreforfilter.='>'.dol_trunc($categ['fulllabel'],50,'middle').'</option>';
  249. }
  250. }
  251. if ($nocateg)
  252. {
  253. $langs->load("categories");
  254. $moreforfilter.='<option value="-2"'.($selected == -2 ? ' selected="selected"':'').'>- '.$langs->trans("NotCategorized").' -</option>';
  255. }
  256. $moreforfilter.='</select>';
  257. return $moreforfilter;
  258. }
  259. /**
  260. * Return select list for categories (to use in form search selectors)
  261. *
  262. * @param string $selected Preselected value
  263. * @param string $htmlname Name of combo list (example: 'search_sale')
  264. * @param User $user Object user
  265. * @return string Html combo list code
  266. */
  267. function select_salesrepresentatives($selected,$htmlname,$user)
  268. {
  269. global $conf;
  270. // Select each sales and print them in a select input
  271. $moreforfilter ='<select class="flat" name="'.$htmlname.'">';
  272. $moreforfilter.='<option value="">&nbsp;</option>';
  273. // Get list of users allowed to be viewed
  274. $sql_usr = "SELECT u.rowid, u.name as name, u.firstname, u.login";
  275. $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
  276. $sql_usr.= " WHERE u.entity IN (0,".$conf->entity.")";
  277. if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.fk_societe = ".($user->societe_id?$user->societe_id:0);
  278. // Add existing sales representatives of company
  279. if (empty($user->rights->user->user->lire) && $user->societe_id)
  280. {
  281. $sql_usr.=" UNION ";
  282. $sql_usr.= "SELECT u2.rowid, u2.name as name, u2.firstname, u2.login";
  283. $sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  284. $sql_usr.= " WHERE u2.entity IN (0,".$conf->entity.")";
  285. $sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->societe_id;
  286. }
  287. $sql_usr.= " ORDER BY name ASC";
  288. //print $sql_usr;exit;
  289. $resql_usr = $this->db->query($sql_usr);
  290. if ($resql_usr)
  291. {
  292. while ($obj_usr = $this->db->fetch_object($resql_usr))
  293. {
  294. $moreforfilter.='<option value="'.$obj_usr->rowid.'"';
  295. if ($obj_usr->rowid == $selected) $moreforfilter.=' selected="selected"';
  296. $moreforfilter.='>';
  297. $moreforfilter.=$obj_usr->firstname." ".$obj_usr->name." (".$obj_usr->login.')';
  298. $moreforfilter.='</option>';
  299. }
  300. $this->db->free($resql_usr);
  301. }
  302. else
  303. {
  304. dol_print_error($this->db);
  305. }
  306. $moreforfilter.='</select>';
  307. return $moreforfilter;
  308. }
  309. /**
  310. * Return list of project and tasks
  311. *
  312. * @param int $selectedtask Pre-selected task
  313. * @param int $projectid Project id
  314. * @param string $htmlname Name of html select
  315. * @param int $modeproject 1 to restrict on projects owned by user
  316. * @param int $modetask 1 to restrict on tasks associated to user
  317. * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
  318. * @param int $useempty 0=Allow empty values
  319. * @return void
  320. */
  321. function selectProjectTasks($selectedtask='', $projectid=0, $htmlname='task_parent', $modeproject=0, $modetask=0, $mode=0, $useempty=0)
  322. {
  323. global $user, $langs;
  324. require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
  325. //print $modeproject.'-'.$modetask;
  326. $task=new Task($this->db);
  327. $tasksarray=$task->getTasksArray($modetask?$user:0, $modeproject?$user:0, $projectid, 0, $mode);
  328. if ($tasksarray)
  329. {
  330. print '<select class="flat" name="'.$htmlname.'">';
  331. if ($useempty) print '<option value="0">&nbsp;</option>';
  332. $j=0;
  333. $level=0;
  334. $this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid);
  335. print '</select>';
  336. }
  337. else
  338. {
  339. print '<div class="warning">'.$langs->trans("NoProject").'</div>';
  340. }
  341. }
  342. /**
  343. * Write all lines of a project (if parent = 0)
  344. *
  345. * @param int &$inc Cursor counter
  346. * @param int $parent Id parent
  347. * @param Object $lines Line object
  348. * @param int $level Level
  349. * @param int $selectedtask Id selected task
  350. * @param int $selectedproject Id selected project
  351. * @return void
  352. */
  353. private function _pLineSelect(&$inc, $parent, $lines, $level=0, $selectedtask=0, $selectedproject=0)
  354. {
  355. global $langs, $user, $conf;
  356. $lastprojectid=0;
  357. $numlines=count($lines);
  358. for ($i = 0 ; $i < $numlines ; $i++)
  359. {
  360. if ($lines[$i]->fk_parent == $parent)
  361. {
  362. $var = !$var;
  363. // Break on a new project
  364. if ($parent == 0)
  365. {
  366. if ($lines[$i]->fk_project != $lastprojectid)
  367. {
  368. if ($i > 0 && $conf->browser->firefox) print '<option value="0" disabled="disabled">----------</option>';
  369. print '<option value="'.$lines[$i]->fk_project.'_0"';
  370. if ($selectedproject == $lines[$i]->fk_project) print ' selected="selected"';
  371. print '>'; // Project -> Task
  372. print $langs->trans("Project").' '.$lines[$i]->projectref;
  373. if (empty($lines[$i]->public))
  374. {
  375. print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
  376. }
  377. else
  378. {
  379. print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
  380. }
  381. //print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
  382. print "</option>\n";
  383. $lastprojectid=$lines[$i]->fk_project;
  384. $inc++;
  385. }
  386. }
  387. // Print task
  388. if ($lines[$i]->id > 0)
  389. {
  390. print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
  391. if ($lines[$i]->id == $selectedtask) print ' selected="selected"';
  392. print '>';
  393. print $langs->trans("Project").' '.$lines[$i]->projectref;
  394. if (empty($lines[$i]->public))
  395. {
  396. print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
  397. }
  398. else
  399. {
  400. print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
  401. }
  402. if ($lines[$i]->id) print ' > ';
  403. for ($k = 0 ; $k < $level ; $k++)
  404. {
  405. print "&nbsp;&nbsp;&nbsp;";
  406. }
  407. print $lines[$i]->label."</option>\n";
  408. $inc++;
  409. }
  410. $level++;
  411. if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject);
  412. $level--;
  413. }
  414. }
  415. }
  416. /**
  417. * Output a HTML code to select a color
  418. *
  419. * @param string $set_color Pre-selected color
  420. * @param string $prefix Name of HTML field
  421. * @param string $form_name Name of form
  422. * @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
  423. * @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
  424. * @return void
  425. */
  426. function select_color($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='')
  427. {
  428. print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
  429. }
  430. /**
  431. * Output a HTML code to select a color
  432. *
  433. * @param string $set_color Pre-selected color
  434. * @param string $prefix Name of HTML field
  435. * @param string $form_name Name of form
  436. * @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
  437. * @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
  438. * @return void
  439. */
  440. function selectColor($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='')
  441. {
  442. global $langs;
  443. $out='';
  444. if (! is_array($arrayofcolors) || count($arrayofcolors) < 1)
  445. {
  446. $langs->load("other");
  447. $out.= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
  448. $out.= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
  449. $out.= '<script type="text/javascript">
  450. jQuery(document).ready(function(){
  451. $(\'#colorpicker'.$prefix.'\').jPicker( {
  452. window: {
  453. title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
  454. effects:
  455. {
  456. type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
  457. speed:
  458. {
  459. show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
  460. hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
  461. }
  462. },
  463. position:
  464. {
  465. x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
  466. y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
  467. },
  468. },
  469. images: {
  470. clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
  471. picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
  472. },
  473. localization: // alter these to change the text presented by the picker (e.g. different language)
  474. {
  475. text:
  476. {
  477. title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
  478. newColor: \''.dol_escape_js($langs->trans("New")).'\',
  479. currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
  480. ok: \''.dol_escape_js($langs->trans("Save")).'\',
  481. cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
  482. }
  483. }
  484. } ); });
  485. </script>';
  486. $out.= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat" type="text" value="'.$set_color.'" />';
  487. }
  488. else // In most cases, this is not used. We used instead function with no specific list of colors
  489. {
  490. $out.= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
  491. $out.= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
  492. $out.= '<script type="text/javascript">
  493. jQuery(document).ready(function(){
  494. jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
  495. size: 14,
  496. label: \'\',
  497. hide: true
  498. });
  499. });
  500. </script>';
  501. $out.= '<select id="colorpicker'.$prefix.'" class="flat" name="'.$prefix.'">';
  502. //print '<option value="-1">&nbsp;</option>';
  503. foreach ($arrayofcolors as $val)
  504. {
  505. $out.= '<option value="'.$val.'"';
  506. if ($set_color == $val) $out.= ' selected="selected"';
  507. $out.= '>'.$val.'</option>';
  508. }
  509. $out.= '</select>';
  510. }
  511. return $out;
  512. }
  513. /**
  514. * Creation d'un icone de couleur
  515. *
  516. * @param string $color Couleur de l'image
  517. * @param string $module Nom du module
  518. * @param string $name Nom de l'image
  519. * @param int $x Largeur de l'image en pixels
  520. * @param int $y Hauteur de l'image en pixels
  521. * @return void
  522. */
  523. function CreateColorIcon($color,$module,$name,$x='12',$y='12')
  524. {
  525. global $conf;
  526. $file = $conf->$module->dir_temp.'/'.$name.'.png';
  527. // On cree le repertoire contenant les icones
  528. if (! file_exists($conf->$module->dir_temp))
  529. {
  530. dol_mkdir($conf->$module->dir_temp);
  531. }
  532. // On cree l'image en vraies couleurs
  533. $image = imagecreatetruecolor($x,$y);
  534. $color = substr($color,1,6);
  535. $rouge = hexdec(substr($color,0,2)); //conversion du canal rouge
  536. $vert = hexdec(substr($color,2,2)); //conversion du canal vert
  537. $bleu = hexdec(substr($color,4,2)); //conversion du canal bleu
  538. $couleur = imagecolorallocate($image,$rouge,$vert,$bleu);
  539. //print $rouge.$vert.$bleu;
  540. imagefill($image,0,0,$couleur); //on remplit l'image
  541. // On cree la couleur et on l'attribue a une variable pour ne pas la perdre
  542. ImagePng($image,$file); //renvoie une image sous format png
  543. ImageDestroy($image);
  544. }
  545. /**
  546. * Return HTML combo list of week
  547. *
  548. * @param string $selected Preselected value
  549. * @param string $htmlname Nom de la zone select
  550. * @param int $useempty Affiche valeur vide dans liste
  551. * @return void
  552. */
  553. function select_dayofweek($selected='',$htmlname='weekid',$useempty=0)
  554. {
  555. global $langs;
  556. $week = array( 0=>$langs->trans("Day0"),
  557. 1=>$langs->trans("Day1"),
  558. 2=>$langs->trans("Day2"),
  559. 3=>$langs->trans("Day3"),
  560. 4=>$langs->trans("Day4"),
  561. 5=>$langs->trans("Day5"),
  562. 6=>$langs->trans("Day6"));
  563. $select_week = '<select class="flat" name="'.$htmlname.'">';
  564. if ($useempty)
  565. {
  566. $select_week .= '<option value="-1">&nbsp;</option>';
  567. }
  568. foreach ($week as $key => $val)
  569. {
  570. if ($selected == $key)
  571. {
  572. $select_week .= '<option value="'.$key.'" selected="selected">';
  573. }
  574. else
  575. {
  576. $select_week .= '<option value="'.$key.'">';
  577. }
  578. $select_week .= $val;
  579. }
  580. $select_week .= '</select>';
  581. return $select_week;
  582. }
  583. /**
  584. * Return HTML combo list of month
  585. *
  586. * @param string $selected Preselected value
  587. * @param string $htmlname Nom de la zone select
  588. * @param int $useempty Affiche valeur vide dans liste
  589. * @return void
  590. */
  591. function select_month($selected='',$htmlname='monthid',$useempty=0)
  592. {
  593. global $langs;
  594. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  595. $montharray = monthArray($langs); // Get array
  596. $select_month = '<select class="flat" name="'.$htmlname.'">';
  597. if ($useempty)
  598. {
  599. $select_month .= '<option value="0">&nbsp;</option>';
  600. }
  601. foreach ($montharray as $key => $val)
  602. {
  603. if ($selected == $key)
  604. {
  605. $select_month .= '<option value="'.$key.'" selected="selected">';
  606. }
  607. else
  608. {
  609. $select_month .= '<option value="'.$key.'">';
  610. }
  611. $select_month .= $val;
  612. }
  613. $select_month .= '</select>';
  614. return $select_month;
  615. }
  616. /**
  617. * Return HTML combo list of years
  618. *
  619. * @param string $selected Preselected value (''=current year, -1=none, year otherwise)
  620. * @param string $htmlname Name of HTML select object
  621. * @param int $useempty Affiche valeur vide dans liste
  622. * @param int $min_year Offset of minimum year into list (by default current year -10)
  623. * @param int $max_year Offset of maximum year into list (by default current year + 5)
  624. * @param int $offset Offset
  625. * @param int $invert Invert
  626. * @param string $option Option
  627. * @return void
  628. */
  629. function select_year($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
  630. {
  631. print $this->selectyear($selected,$htmlname,$useempty,$min_year,$max_year,$offset,$invert,$option);
  632. }
  633. /**
  634. * Return HTML combo list of years
  635. *
  636. * @param string $selected Preselected value (''=current year, -1=none, year otherwise)
  637. * @param string $htmlname Name of HTML select object
  638. * @param int $useempty Affiche valeur vide dans liste
  639. * @param int $min_year Offset of minimum year into list (by default current year -10)
  640. * @param int $max_year Offset of maximum year into list (by default current year + 5)
  641. * @param int $offset Offset
  642. * @param int $invert Invert
  643. * @param string $option Option
  644. * @return void
  645. */
  646. function selectyear($selected='',$htmlname='yearid',$useempty=0, $min_year=10, $max_year=5, $offset=0, $invert=0, $option='')
  647. {
  648. $out='';
  649. $currentyear = date("Y")+$offset;
  650. $max_year = $currentyear+$max_year;
  651. $min_year = $currentyear-$min_year;
  652. if(empty($selected) && empty($useempty)) $selected = $currentyear;
  653. $out.= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '"'.$option.' >';
  654. if($useempty)
  655. {
  656. $selected_html='';
  657. if ($selected == '') $selected_html = ' selected="selected"';
  658. $out.= '<option value=""' . $selected_html . '>&nbsp;</option>';
  659. }
  660. if (! $invert)
  661. {
  662. for ($y = $max_year; $y >= $min_year; $y--)
  663. {
  664. $selected_html='';
  665. if ($selected > 0 && $y == $selected) $selected_html = ' selected="selected"';
  666. $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
  667. }
  668. }
  669. else
  670. {
  671. for ($y = $min_year; $y <= $max_year; $y++)
  672. {
  673. $selected_html='';
  674. if ($selected > 0 && $y == $selected) $selected_html = ' selected="selected"';
  675. $out.= '<option value="'.$y.'"'.$selected_html.' >'.$y.'</option>';
  676. }
  677. }
  678. $out.= "</select>\n";
  679. return $out;
  680. }
  681. /**
  682. * Return select list for stcomm (to use in form search selectors)
  683. * @param type Type of stcomm
  684. * @param selected Preselected value
  685. * @param htmlname Name of combo list
  686. * @return return Html combo list code
  687. */
  688. function select_stcomm($type,$selected='',$htmlname='pstcomm')
  689. {
  690. global $conf;
  691. // Select each sales and print them in a select input
  692. $moreforfilter ='<select class="flat" name="'.$htmlname.'">';
  693. $moreforfilter.='<option value="">&nbsp;</option>';
  694. // Get list of users allowed to be viewed
  695. $sql_usr = "SELECT st.id, st.libelle";
  696. $sql_usr.= " FROM ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."c_stcomm as sel";
  697. $sql_usr.= " WHERE st.active = 1";
  698. if($type!='')
  699. $sql_usr.= " AND st.type = ".$type;
  700. elseif($selected!='')
  701. $sql_usr.= " AND st.type = sel.type AND sel.id = ".$selected;
  702. $sql_usr.= " GROUP BY st.id";
  703. //print $sql_usr;exit;
  704. $resql_usr = $this->db->query($sql_usr);
  705. if ($resql_usr)
  706. {
  707. while ($obj_usr = $this->db->fetch_object($resql_usr))
  708. {
  709. $moreforfilter.='<option value="'.$obj_usr->id.'"';
  710. if ($obj_usr->id == $selected) $moreforfilter.=' selected="selected"';
  711. $moreforfilter.='>';
  712. $moreforfilter.=$obj_usr->libelle;
  713. $moreforfilter.='</option>';
  714. $i++;
  715. }
  716. $this->db->free($resql_usr);
  717. }
  718. else
  719. {
  720. dol_print_error($this->db);
  721. }
  722. $moreforfilter.='</select>';
  723. return $moreforfilter;
  724. }
  725. /**
  726. * Show form to select address
  727. *
  728. * @param int $page Page
  729. * @param string $selected Id condition pre-selectionne
  730. * @param int $socid Id of third party
  731. * @param string $htmlname Nom du formulaire select
  732. * @param string $origin Origine de l'appel pour pouvoir creer un retour
  733. * @param int $originid Id de l'origine
  734. * @return void
  735. */
  736. function form_address($page, $selected, $socid, $htmlname='address_id', $origin='', $originid='')
  737. {
  738. global $langs,$conf;
  739. global $form;
  740. if ($htmlname != "none")
  741. {
  742. print '<form method="post" action="'.$page.'">';
  743. print '<input type="hidden" name="action" value="setaddress">';
  744. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  745. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  746. print '<tr><td>';
  747. $form->select_address($selected, $socid, $htmlname, 1);
  748. print '</td>';
  749. print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  750. $langs->load("companies");
  751. print ' &nbsp; <a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$socid.'&action=create&origin='.$origin.'&originid='.$originid.'>'.$langs->trans("AddAddress").'</a>';
  752. print '</td></tr></table></form>';
  753. }
  754. else
  755. {
  756. if ($selected)
  757. {
  758. require_once DOL_DOCUMENT_ROOT .'/societe/class/address.class.php';
  759. $address=new Address($this->db);
  760. $result=$address->fetch_address($selected);
  761. print '<a href='.DOL_URL_ROOT.'/comm/address.php?socid='.$address->socid.'&id='.$address->id.'&action=edit&origin='.$origin.'&originid='.$originid.'>'.$address->label.'</a>';
  762. }
  763. else
  764. {
  765. print "&nbsp;";
  766. }
  767. }
  768. }
  769. /**
  770. * Show a HTML Tab with boxes of a particular area including personalized choices of user
  771. *
  772. * @param User $user Object User
  773. * @param String $areacode Code of area for pages (0=value for Home page)
  774. * @return int <0 if KO, Nb of boxes shown of OK (0 to n)
  775. */
  776. static function printBoxesArea($user,$areacode)
  777. {
  778. global $conf,$langs,$db;
  779. include_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  780. //$infobox=new InfoBox($db);
  781. $boxactivated=InfoBox::listBoxes($db,'activated',$areacode,$user);
  782. $arrayboxactivatedid=array();
  783. foreach($boxactivated as $box) $arrayboxactivatedid[$box->id]=$box->id;
  784. $selectboxlist='';
  785. if (! empty($conf->use_javascript_ajax))
  786. {
  787. $emptyuser=new User($db);
  788. $boxavailable=InfoBox::listBoxes($db,'activated',$areacode,$emptyuser,$arrayboxactivatedid); // Get list of box available for empty user (minus already activated for user)
  789. $arrayboxtoactivatelabel=array();
  790. foreach($boxavailable as $box)
  791. {
  792. $arrayboxtoactivatelabel[$box->id]=$box->boxlabel;
  793. }
  794. $form=new Form($db);
  795. $selectboxlist=$form->selectarray('boxcombo', $arrayboxtoactivatelabel,'',1);
  796. }
  797. if (! empty($conf->use_javascript_ajax))
  798. {
  799. print '<script type="text/javascript" language="javascript">
  800. jQuery(document).ready(function() {
  801. jQuery("#boxcombo").change(function() {
  802. var boxid=jQuery("#boxcombo").val();
  803. if (boxid > 0) {
  804. var left_list = cleanSerialize(jQuery("#left").sortable("serialize"));
  805. var right_list = cleanSerialize(jQuery("#right").sortable("serialize"));
  806. var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
  807. jQuery.ajax({
  808. url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&boxid=\'+boxid+\'&zone='.$areacode.'&userid='.$user->id.'\',
  809. async: false
  810. });
  811. window.location.search=\'mainmenu='.GETPOST("mainmenu").'&leftmenu='.GETPOST('leftmenu').'&action=addbox&boxid=\'+boxid;
  812. }
  813. });';
  814. if (! count($arrayboxtoactivatelabel)) print 'jQuery("#boxcombo").hide();';
  815. print '
  816. });
  817. </script>';
  818. }
  819. $nbboxactivated=count($boxactivated);
  820. print load_fiche_titre(($nbboxactivated?$langs->trans("OtherInformationsBoxes"):''),$selectboxlist,'','','otherboxes');
  821. if ($nbboxactivated)
  822. {
  823. print '<table width="100%" class="notopnoleftnoright">';
  824. print '<tr><td class="notopnoleftnoright">'."\n";
  825. print '<div class="fichehalfleft">';
  826. print "\n<!-- Box left container -->\n";
  827. print '<div id="left" class="connectedSortable">'."\n";
  828. // Define $box_max_lines
  829. $box_max_lines=5;
  830. if (! empty($conf->global->MAIN_BOXES_MAXLINES)) $box_max_lines=$conf->global->MAIN_BOXES_MAXLINES;
  831. $ii=0;
  832. foreach ($boxactivated as $key => $box)
  833. {
  834. 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
  835. if (preg_match('/^A/i',$box->box_order)) // column A
  836. {
  837. $ii++;
  838. //print 'box_id '.$boxactivated[$ii]->box_id.' ';
  839. //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
  840. // Affichage boite key
  841. $box->loadBox($box_max_lines);
  842. $box->showBox();
  843. }
  844. }
  845. $emptybox=new ModeleBoxes($db);
  846. $emptybox->box_id='A';
  847. $emptybox->info_box_head=array();
  848. $emptybox->info_box_contents=array();
  849. $emptybox->showBox(array(),array());
  850. print "</div>\n";
  851. print "<!-- End box container -->\n";
  852. print '</div><div class="fichehalfright"><div class="ficheaddleft">';
  853. print "\n<!-- Box right container -->\n";
  854. print '<div id="right" class="connectedSortable">'."\n";
  855. $ii=0;
  856. foreach ($boxactivated as $key => $box)
  857. {
  858. 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
  859. if (preg_match('/^B/i',$box->box_order)) // colonne B
  860. {
  861. $ii++;
  862. //print 'box_id '.$boxactivated[$ii]->box_id.' ';
  863. //print 'box_order '.$boxactivated[$ii]->box_order.'<br>';
  864. // Affichage boite key
  865. $box->loadBox($box_max_lines);
  866. $box->showBox();
  867. }
  868. }
  869. $emptybox=new ModeleBoxes($db);
  870. $emptybox->box_id='B';
  871. $emptybox->info_box_head=array();
  872. $emptybox->info_box_contents=array();
  873. $emptybox->showBox(array(),array());
  874. print "</div>\n";
  875. print "<!-- End box container -->\n";
  876. print '</div></div>';
  877. print "\n";
  878. print "</td></tr>";
  879. print "</table>";
  880. if ($conf->use_javascript_ajax)
  881. {
  882. print "\n";
  883. print '<script type="text/javascript" language="javascript">';
  884. // For moving
  885. print 'jQuery(function() {
  886. jQuery("#left, #right").sortable({
  887. /* placeholder: \'ui-state-highlight\', */
  888. handle: \'.boxhandle\',
  889. revert: \'invalid\',
  890. items: \'.box\',
  891. containment: \'.fiche\',
  892. connectWith: \'.connectedSortable\',
  893. stop: function(event, ui) {
  894. updateBoxOrder(0);
  895. }
  896. });
  897. });
  898. '."\n";
  899. // To update list of activated boxes
  900. print 'function updateBoxOrder(closing) {
  901. var left_list = cleanSerialize(jQuery("#left").sortable("serialize"));
  902. var right_list = cleanSerialize(jQuery("#right").sortable("serialize"));
  903. var boxorder = \'A:\' + left_list + \'-B:\' + right_list;
  904. 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
  905. {
  906. jQuery.ajax({
  907. url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
  908. async: false
  909. });
  910. // We force reload to be sure to get all boxes into list
  911. window.location.search=\'mainmenu='.GETPOST("mainmenu").'&leftmenu='.GETPOST('leftmenu').'&action=delbox\';
  912. }
  913. else
  914. {
  915. jQuery.ajax({
  916. url: \''.DOL_URL_ROOT.'/core/ajax/box.php?boxorder=\'+boxorder+\'&zone='.$areacode.'&userid=\'+'.$user->id.',
  917. async: true
  918. });
  919. }
  920. }'."\n";
  921. // For closing
  922. print 'jQuery(document).ready(function() {
  923. jQuery(".boxclose").click(function() {
  924. var self = this; // because JQuery can modify this
  925. var boxid=self.id.substring(8);
  926. jQuery(\'#boxto_\'+boxid).remove();
  927. updateBoxOrder(1);
  928. });
  929. });'."\n";
  930. print '</script>'."\n";
  931. }
  932. }
  933. return count($boxactivated);
  934. }
  935. }
  936. ?>