html.formcontract.class.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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.formcontract.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 FormContract
  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 contracts not linked to a third party, id=contracts not linked or linked to third party id)
  43. * @param int $selected Id contract 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 Nbr of project if OK, <0 if KO
  48. */
  49. function select_contract($socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
  50. {
  51. global $db,$user,$conf,$langs;
  52. $hideunselectables = false;
  53. if (! empty($conf->global->PROJECT_HIDE_UNSELECTABLES)) $hideunselectables = true;
  54. // Search all contacts
  55. $sql = 'SELECT c.rowid, c.ref, c.fk_soc, c.statut';
  56. $sql.= ' FROM '.MAIN_DB_PREFIX .'contrat as c';
  57. $sql.= " WHERE c.entity = ".$conf->entity;
  58. //if ($contratListId) $sql.= " AND c.rowid IN (".$contratListId.")";
  59. if ($socid == 0) $sql.= " AND (c.fk_soc = 0 OR c.fk_soc IS NULL)";
  60. if ($socid > 0) $sql.= " AND (c.fk_soc=".$socid." OR c.fk_soc IS NULL)";
  61. $sql.= " ORDER BY c.ref ";
  62. dol_syslog(get_class($this)."::select_contract", LOG_DEBUG);
  63. $resql=$db->query($sql);
  64. if ($resql)
  65. {
  66. print '<select class="flat" name="'.$htmlname.'">';
  67. if ($showempty) print '<option value="0">&nbsp;</option>';
  68. $num = $db->num_rows($resql);
  69. $i = 0;
  70. if ($num)
  71. {
  72. while ($i < $num)
  73. {
  74. $obj = $db->fetch_object($resql);
  75. // 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.
  76. if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
  77. {
  78. // Do nothing
  79. }
  80. else
  81. {
  82. $labeltoshow=dol_trunc($obj->ref,18);
  83. //if ($obj->public) $labeltoshow.=' ('.$langs->trans("SharedProject").')';
  84. //else $labeltoshow.=' ('.$langs->trans("Private").')';
  85. if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
  86. {
  87. print '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
  88. }
  89. else
  90. {
  91. $disabled=0;
  92. if (! $obj->statut > 0)
  93. {
  94. $disabled=1;
  95. $labeltoshow.=' ('.$langs->trans("Draft").')';
  96. }
  97. if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
  98. {
  99. $disabled=1;
  100. $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
  101. }
  102. if ($hideunselectables && $disabled)
  103. {
  104. $resultat='';
  105. }
  106. else
  107. {
  108. $resultat='<option value="'.$obj->rowid.'"';
  109. if ($disabled) $resultat.=' disabled';
  110. //if ($obj->public) $labeltoshow.=' ('.$langs->trans("Public").')';
  111. //else $labeltoshow.=' ('.$langs->trans("Private").')';
  112. $resultat.='>'.$labeltoshow;
  113. $resultat.='</option>';
  114. }
  115. print $resultat;
  116. }
  117. }
  118. $i++;
  119. }
  120. }
  121. print '</select>';
  122. $db->free($resql);
  123. if (!empty($conf->use_javascript_ajax))
  124. {
  125. // Make select dynamic
  126. include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
  127. print ajax_combobox($htmlname);
  128. }
  129. return $num;
  130. }
  131. else
  132. {
  133. dol_print_error($db);
  134. return -1;
  135. }
  136. }
  137. /**
  138. * Show a form to select a contract
  139. *
  140. * @param int $page Page
  141. * @param int $socid Id third party (-1=all, 0=only contracts not linked to a third party, id=contracts not linked or linked to third party id)
  142. * @param int $selected Id contract preselected
  143. * @param string $htmlname Nom de la zone html
  144. * @param int $maxlength Maximum length of label
  145. * @param int $showempty Show empty line
  146. * @return int Nbr of project if OK, <0 if KO
  147. */
  148. function formSelectContract($page, $socid=-1, $selected='', $htmlname='contrattid', $maxlength=16, $showempty=1)
  149. {
  150. global $langs;
  151. print "\n";
  152. print '<form method="post" action="'.$page.'">';
  153. print '<input type="hidden" name="action" value="setcontract">';
  154. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  155. $this->select_contract($socid, $selected, $htmlname, $maxlength, $showempty);
  156. print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
  157. print '</form>';
  158. }
  159. }