html.formintervention.class.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /* Copyright (C) 2012-2013 Charles-Fr BENKE <charles.fr@benke.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. * or see http://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/class/html.formintervention.class.php
  20. * \ingroup core
  21. * \brief File of class with all html predefined components
  22. */
  23. /**
  24. * Class to manage generation of HTML components for contract module
  25. */
  26. class FormIntervention
  27. {
  28. var $db;
  29. var $error;
  30. /**
  31. * Constructor
  32. *
  33. * @param DoliDB $db Database handler
  34. */
  35. public function __construct($db)
  36. {
  37. $this->db = $db;
  38. }
  39. /**
  40. * Show a combo list with contracts qualified for a third party
  41. *
  42. * @param int $socid Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id)
  43. * @param int $selected Id intervention preselected
  44. * @param string $htmlname Nom de la zone html
  45. * @param int $maxlength Maximum length of label
  46. * @param int $showempty Show empty line
  47. * @return int Nbre of project if OK, <0 if KO
  48. */
  49. function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1)
  50. {
  51. global $db,$user,$conf,$langs;
  52. $out='';
  53. $hideunselectables=false;
  54. // Search all contacts
  55. $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut';
  56. $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f';
  57. $sql.= " WHERE f.entity = ".$conf->entity;
  58. if ($socid != '')
  59. {
  60. if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
  61. else $sql.= " AND f.fk_soc = ".$socid;
  62. }
  63. dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
  64. $resql=$db->query($sql);
  65. if ($resql)
  66. {
  67. $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
  68. if ($showempty) $out.='<option value="0">&nbsp;</option>';
  69. $num = $db->num_rows($resql);
  70. $i = 0;
  71. if ($num)
  72. {
  73. while ($i < $num)
  74. {
  75. $obj = $db->fetch_object($resql);
  76. // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
  77. if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
  78. {
  79. // Do nothing
  80. }
  81. else
  82. {
  83. $labeltoshow=dol_trunc($obj->ref,18);
  84. if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
  85. {
  86. $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
  87. }
  88. else
  89. {
  90. $disabled=0;
  91. if (! $obj->fk_statut > 0)
  92. {
  93. $disabled=1;
  94. $labeltoshow.=' ('.$langs->trans("Draft").')';
  95. }
  96. if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
  97. {
  98. $disabled=1;
  99. $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
  100. }
  101. if ($hideunselectables && $disabled)
  102. {
  103. $resultat='';
  104. }
  105. else
  106. {
  107. $resultat='<option value="'.$obj->rowid.'"';
  108. if ($disabled) $resultat.=' disabled';
  109. $resultat.='>'.$labeltoshow;
  110. $resultat.='</option>';
  111. }
  112. $out.=$resultat;
  113. }
  114. }
  115. $i++;
  116. }
  117. }
  118. $out.='</select>';
  119. $db->free($resql);
  120. return $out;
  121. }
  122. else
  123. {
  124. dol_print_error($db);
  125. return '';
  126. }
  127. }
  128. }