dolibarr 19.0.3
html.formpropal.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2012 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2022 Josep LluĂ­s Amador <joseplluis@lliuretic.cat>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
30{
34 public $db;
35
39 public $error = '';
40
41
47 public function __construct($db)
48 {
49 $this->db = $db;
50 }
51
65 public function selectProposalStatus($selected = '', $short = 0, $excludedraft = 0, $showempty = 1, $mode = 'customer', $htmlname = 'propal_statut', $morecss = '')
66 {
67 global $langs;
68
69 $prefix = '';
70 $listofstatus = array();
71 if ($mode == 'supplier') {
72 $prefix = 'SupplierProposalStatus';
73
74 $langs->load("supplier_proposal");
75 $listofstatus = array(
76 0=>array('id'=>0, 'code'=>'PR_DRAFT'),
77 1=>array('id'=>1, 'code'=>'PR_OPEN'),
78 2=>array('id'=>2, 'code'=>'PR_SIGNED'),
79 3=>array('id'=>3, 'code'=>'PR_NOTSIGNED'),
80 4=>array('id'=>4, 'code'=>'PR_CLOSED')
81 );
82 } else {
83 $prefix = "PropalStatus";
84
85 $sql = "SELECT id, code, label, active FROM ".$this->db->prefix()."c_propalst";
86 $sql .= " WHERE active = 1";
87 dol_syslog(get_class($this)."::selectProposalStatus", LOG_DEBUG);
88 $resql = $this->db->query($sql);
89 if ($resql) {
90 $num = $this->db->num_rows($resql);
91 $i = 0;
92 if ($num) {
93 while ($i < $num) {
94 $obj = $this->db->fetch_object($resql);
95 $listofstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>$obj->label);
96 $i++;
97 }
98 }
99 } else {
100 dol_print_error($this->db);
101 }
102 }
103
104 print '<select id="'.$htmlname.'" name="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
105 if ($showempty) {
106 print '<option value="-1">&nbsp;</option>';
107 }
108
109 $i = 0;
110 foreach ($listofstatus as $key => $obj) {
111 if ($excludedraft) {
112 if ($obj['code'] == 'Draft' || $obj['code'] == 'PR_DRAFT') {
113 $i++;
114 continue;
115 }
116 }
117 if ($selected != '' && $selected == $obj['id']) {
118 print '<option value="'.$obj['id'].'" selected>';
119 } else {
120 print '<option value="'.$obj['id'].'">';
121 }
122 $key = $obj['code'];
123 if ($langs->trans($prefix.$key.($short ? 'Short' : '')) != $prefix.$key.($short ? 'Short' : '')) {
124 print $langs->trans($prefix.$key.($short ? 'Short' : ''));
125 } else {
126 $conv_to_new_code = array('PR_DRAFT'=>'Draft', 'PR_OPEN'=>'Validated', 'PR_CLOSED'=>'Closed', 'PR_SIGNED'=>'Signed', 'PR_NOTSIGNED'=>'NotSigned', 'PR_FAC'=>'Billed');
127 if (!empty($conv_to_new_code[$obj['code']])) {
128 $key = $conv_to_new_code[$obj['code']];
129 }
130
131 print ($langs->trans($prefix.$key.($short ? 'Short' : '')) != $prefix.$key.($short ? 'Short' : '')) ? $langs->trans($prefix.$key.($short ? 'Short' : '')) : ($obj['label'] ? $obj['label'] : $obj['code']);
132 }
133 print '</option>';
134 $i++;
135 }
136 // Option for Signed+Billed
137 if ($mode == 'customer') {
138 if ($selected != '' && $selected == "2,4") {
139 print '<option value="2,4" selected>';
140 } else {
141 print '<option value="2,4">';
142 }
143 print($langs->trans($prefix.'Signed'.($short ? 'Short' : '')).' '.$langs->trans("or").' '.$langs->trans($prefix.'Billed'.($short ? 'Short' : '')));
144 print '</option>';
145 }
146 print '</select>';
147
148 print ajax_combobox($htmlname, array(), 0, 0, 'resolve', ($showempty < 0 ? (string) $showempty : '-1'), $morecss);
149 }
150}
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:455
Class to manage generation of HTML components for proposal management.
selectProposalStatus($selected='', $short=0, $excludedraft=0, $showempty=1, $mode='customer', $htmlname='propal_statut', $morecss='')
Return combo list of differents status of a proposal Values are id of table c_propalst.
__construct($db)
Constructor.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.