html.formintervention.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. /**
  29. * @var DoliDB Database handler.
  30. */
  31. public $db;
  32. /**
  33. * @var string Error code (or message)
  34. */
  35. public $error='';
  36. /**
  37. * Constructor
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. $this->db = $db;
  44. }
  45. // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
  46. /**
  47. * Show a combo list with contracts qualified for a third party
  48. *
  49. * @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)
  50. * @param int $selected Id intervention preselected
  51. * @param string $htmlname Nom de la zone html
  52. * @param int $maxlength Maximum length of label
  53. * @param int $showempty Show empty line
  54. * @return int Nbre of project if OK, <0 if KO
  55. */
  56. function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1)
  57. {
  58. // phpcs:enable
  59. global $db,$user,$conf,$langs;
  60. $out='';
  61. $hideunselectables=false;
  62. // Search all contacts
  63. $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut';
  64. $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f';
  65. $sql.= " WHERE f.entity = ".$conf->entity;
  66. if ($socid != '')
  67. {
  68. if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
  69. else $sql.= " AND f.fk_soc = ".$socid;
  70. }
  71. dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
  72. $resql=$db->query($sql);
  73. if ($resql)
  74. {
  75. $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
  76. if ($showempty) $out.='<option value="0">&nbsp;</option>';
  77. $num = $db->num_rows($resql);
  78. $i = 0;
  79. if ($num)
  80. {
  81. while ($i < $num)
  82. {
  83. $obj = $db->fetch_object($resql);
  84. // 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.
  85. if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
  86. {
  87. // Do nothing
  88. }
  89. else
  90. {
  91. $labeltoshow=dol_trunc($obj->ref,18);
  92. if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
  93. {
  94. $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
  95. }
  96. else
  97. {
  98. $disabled=0;
  99. if (! $obj->fk_statut > 0)
  100. {
  101. $disabled=1;
  102. $labeltoshow.=' ('.$langs->trans("Draft").')';
  103. }
  104. if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
  105. {
  106. $disabled=1;
  107. $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
  108. }
  109. if ($hideunselectables && $disabled)
  110. {
  111. $resultat='';
  112. }
  113. else
  114. {
  115. $resultat='<option value="'.$obj->rowid.'"';
  116. if ($disabled) $resultat.=' disabled';
  117. $resultat.='>'.$labeltoshow;
  118. $resultat.='</option>';
  119. }
  120. $out.=$resultat;
  121. }
  122. }
  123. $i++;
  124. }
  125. }
  126. $out.='</select>';
  127. $db->free($resql);
  128. return $out;
  129. }
  130. else
  131. {
  132. dol_print_error($db);
  133. return '';
  134. }
  135. }
  136. }