@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | class CdavLib |
29 | 29 | { |
30 | 30 | |
31 | - private $db; |
|
31 | + private $db; |
|
32 | 32 | |
33 | - private $user; |
|
33 | + private $user; |
|
34 | 34 | |
35 | - private $langs; |
|
35 | + private $langs; |
|
36 | 36 | |
37 | 37 | /** |
38 | 38 | * Constructor |
@@ -41,25 +41,25 @@ discard block |
||
41 | 41 | * @param DoliDB $db Database handler |
42 | 42 | * @param Translate $langs translation |
43 | 43 | */ |
44 | - function __construct($user, $db, $langs) |
|
45 | - { |
|
46 | - $this->user = $user; |
|
47 | - $this->db = $db; |
|
48 | - $this->langs = $langs; |
|
49 | - } |
|
44 | + function __construct($user, $db, $langs) |
|
45 | + { |
|
46 | + $this->user = $user; |
|
47 | + $this->db = $db; |
|
48 | + $this->langs = $langs; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Base sql request for calendar events |
|
53 | - * |
|
54 | - * @param int $calid Calendard id |
|
55 | - * @param int|boolean $oid Oid |
|
56 | - * @param int|boolean $ouri Ouri |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function getSqlCalEvents($calid, $oid=false, $ouri=false) |
|
60 | - { |
|
61 | - // TODO : replace GROUP_CONCAT by |
|
62 | - $sql = 'SELECT |
|
51 | + /** |
|
52 | + * Base sql request for calendar events |
|
53 | + * |
|
54 | + * @param int $calid Calendard id |
|
55 | + * @param int|boolean $oid Oid |
|
56 | + * @param int|boolean $ouri Ouri |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function getSqlCalEvents($calid, $oid=false, $ouri=false) |
|
60 | + { |
|
61 | + // TODO : replace GROUP_CONCAT by |
|
62 | + $sql = 'SELECT |
|
63 | 63 | a.tms AS lastupd, |
64 | 64 | a.*, |
65 | 65 | sp.firstname, |
@@ -82,223 +82,223 @@ discard block |
||
82 | 82 | LEFT OUTER JOIN '.MAIN_DB_PREFIX.'user AS u ON (u.rowid=fk_element) |
83 | 83 | WHERE ar.element_type=\'user\' AND fk_actioncomm=a.id) AS other_users |
84 | 84 | FROM '.MAIN_DB_PREFIX.'actioncomm AS a'; |
85 | - if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ? |
|
86 | - { |
|
87 | - $sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.') |
|
85 | + if (! $this->user->rights->societe->client->voir )//FIXME si 'voir' on voit plus de chose ? |
|
86 | + { |
|
87 | + $sql.=' LEFT OUTER JOIN '.MAIN_DB_PREFIX.'societe_commerciaux AS sc ON (a.fk_soc = sc.fk_soc AND sc.fk_user='.$this->user->id.') |
|
88 | 88 | LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = sc.fk_soc) |
89 | 89 | LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.fk_soc = sc.fk_soc AND sp.rowid = a.fk_contact) |
90 | 90 | LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)'; |
91 | - } |
|
92 | - else |
|
93 | - { |
|
94 | - $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc) |
|
91 | + } |
|
92 | + else |
|
93 | + { |
|
94 | + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'societe AS s ON (s.rowid = a.fk_soc) |
|
95 | 95 | LEFT JOIN '.MAIN_DB_PREFIX.'socpeople AS sp ON (sp.rowid = a.fk_contact) |
96 | 96 | LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_cdav AS ac ON (a.id = ac.fk_object)'; |
97 | - } |
|
97 | + } |
|
98 | 98 | |
99 | - $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays |
|
99 | + $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON co.rowid = sp.fk_pays |
|
100 | 100 | LEFT JOIN '.MAIN_DB_PREFIX.'c_country as cos ON cos.rowid = s.fk_pays |
101 | 101 | WHERE a.id IN (SELECT ar.fk_actioncomm FROM '.MAIN_DB_PREFIX.'actioncomm_resources ar WHERE ar.element_type=\'user\' AND ar.fk_element='.intval($calid).') |
102 | 102 | AND a.code IN (SELECT cac.code FROM '.MAIN_DB_PREFIX.'c_actioncomm cac WHERE cac.type<>\'systemauto\') |
103 | 103 | AND a.entity IN ('.getEntity('societe', 1).')'; |
104 | - if($oid!==false) { |
|
105 | - if($ouri===false) |
|
106 | - { |
|
107 | - $sql.=' AND a.id = '.intval($oid); |
|
108 | - } |
|
109 | - else |
|
110 | - { |
|
111 | - $sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')'; |
|
112 | - } |
|
113 | - } |
|
104 | + if($oid!==false) { |
|
105 | + if($ouri===false) |
|
106 | + { |
|
107 | + $sql.=' AND a.id = '.intval($oid); |
|
108 | + } |
|
109 | + else |
|
110 | + { |
|
111 | + $sql.=' AND (a.id = '.intval($oid).' OR ac.uuidext = \''.$this->db->escape($ouri).'\')'; |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | - return $sql; |
|
116 | - } |
|
115 | + return $sql; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * Convert calendar row to VCalendar string |
|
120 | - * |
|
121 | - * @param int $calid Calendar id |
|
122 | - * @param Object $obj Object id |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function toVCalendar($calid, $obj) |
|
126 | - { |
|
127 | - /*$categ = array(); |
|
118 | + /** |
|
119 | + * Convert calendar row to VCalendar string |
|
120 | + * |
|
121 | + * @param int $calid Calendar id |
|
122 | + * @param Object $obj Object id |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function toVCalendar($calid, $obj) |
|
126 | + { |
|
127 | + /*$categ = array(); |
|
128 | 128 | if($obj->soc_client) |
129 | 129 | { |
130 | 130 | $nick[] = $obj->soc_code_client; |
131 | 131 | $categ[] = $this->langs->transnoentitiesnoconv('Customer'); |
132 | 132 | }*/ |
133 | 133 | |
134 | - $location=$obj->location; |
|
134 | + $location=$obj->location; |
|
135 | 135 | |
136 | - // contact address |
|
137 | - if(empty($location) && !empty($obj->address)) |
|
138 | - { |
|
139 | - $location = trim(str_replace(array("\r","\t","\n"),' ', $obj->address)); |
|
140 | - $location = trim($location.', '.$obj->zip); |
|
141 | - $location = trim($location.' '.$obj->town); |
|
142 | - $location = trim($location.', '.$obj->country_label); |
|
143 | - } |
|
136 | + // contact address |
|
137 | + if(empty($location) && !empty($obj->address)) |
|
138 | + { |
|
139 | + $location = trim(str_replace(array("\r","\t","\n"),' ', $obj->address)); |
|
140 | + $location = trim($location.', '.$obj->zip); |
|
141 | + $location = trim($location.' '.$obj->town); |
|
142 | + $location = trim($location.', '.$obj->country_label); |
|
143 | + } |
|
144 | 144 | |
145 | - // contact address |
|
146 | - if(empty($location) && !empty($obj->soc_address)) |
|
147 | - { |
|
148 | - $location = trim(str_replace(array("\r","\t","\n"),' ', $obj->soc_address)); |
|
149 | - $location = trim($location.', '.$obj->soc_zip); |
|
150 | - $location = trim($location.' '.$obj->soc_town); |
|
151 | - $location = trim($location.', '.$obj->soc_country_label); |
|
152 | - } |
|
145 | + // contact address |
|
146 | + if(empty($location) && !empty($obj->soc_address)) |
|
147 | + { |
|
148 | + $location = trim(str_replace(array("\r","\t","\n"),' ', $obj->soc_address)); |
|
149 | + $location = trim($location.', '.$obj->soc_zip); |
|
150 | + $location = trim($location.' '.$obj->soc_town); |
|
151 | + $location = trim($location.', '.$obj->soc_country_label); |
|
152 | + } |
|
153 | 153 | |
154 | - $address=explode("\n",$obj->address,2); |
|
155 | - foreach($address as $kAddr => $vAddr) |
|
156 | - { |
|
157 | - $address[$kAddr] = trim(str_replace(array("\r","\t"),' ', str_replace("\n",' | ', trim($vAddr)))); |
|
158 | - } |
|
159 | - $address[]=''; |
|
160 | - $address[]=''; |
|
154 | + $address=explode("\n",$obj->address,2); |
|
155 | + foreach($address as $kAddr => $vAddr) |
|
156 | + { |
|
157 | + $address[$kAddr] = trim(str_replace(array("\r","\t"),' ', str_replace("\n",' | ', trim($vAddr)))); |
|
158 | + } |
|
159 | + $address[]=''; |
|
160 | + $address[]=''; |
|
161 | 161 | |
162 | - if($obj->percent==-1 && trim($obj->datep)!='') |
|
163 | - $type='VEVENT'; |
|
164 | - else |
|
165 | - $type='VTODO'; |
|
162 | + if($obj->percent==-1 && trim($obj->datep)!='') |
|
163 | + $type='VEVENT'; |
|
164 | + else |
|
165 | + $type='VTODO'; |
|
166 | 166 | |
167 | - $timezone = date_default_timezone_get(); |
|
167 | + $timezone = date_default_timezone_get(); |
|
168 | 168 | |
169 | - $caldata ="BEGIN:VCALENDAR\n"; |
|
170 | - $caldata.="VERSION:2.0\n"; |
|
171 | - $caldata.="METHOD:PUBLISH\n"; |
|
172 | - $caldata.="PRODID:-//Dolibarr CDav//FR\n"; |
|
173 | - $caldata.="BEGIN:".$type."\n"; |
|
174 | - $caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n"; |
|
175 | - $caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n"; |
|
176 | - $caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n"; |
|
177 | - if($obj->sourceuid=='') |
|
178 | - $caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n"; |
|
179 | - else |
|
180 | - $caldata.="UID:".$obj->sourceuid."\n"; |
|
181 | - $caldata.="SUMMARY:".$obj->label."\n"; |
|
182 | - $caldata.="LOCATION:".$location."\n"; |
|
183 | - $caldata.="PRIORITY:".$obj->priority."\n"; |
|
184 | - if($obj->fulldayevent) |
|
185 | - { |
|
186 | - $caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n"; |
|
187 | - if($type=='VEVENT') |
|
188 | - { |
|
189 | - if(trim($obj->datep2)!='') |
|
190 | - $caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n"; |
|
191 | - else |
|
192 | - $caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n"; |
|
193 | - } |
|
194 | - elseif(trim($obj->datep2)!='') |
|
195 | - $caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n"; |
|
196 | - } |
|
197 | - else |
|
198 | - { |
|
199 | - $caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
200 | - if($type=='VEVENT') |
|
201 | - { |
|
202 | - if(trim($obj->datep2)!='') |
|
203 | - $caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
204 | - else |
|
205 | - $caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
206 | - } |
|
207 | - elseif(trim($obj->datep2)!='') |
|
208 | - $caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
209 | - } |
|
210 | - $caldata.="CLASS:PUBLIC\n"; |
|
211 | - if($obj->transparency==1) |
|
212 | - $caldata.="TRANSP:TRANSPARENT\n"; |
|
213 | - else |
|
214 | - $caldata.="TRANSP:OPAQUE\n"; |
|
169 | + $caldata ="BEGIN:VCALENDAR\n"; |
|
170 | + $caldata.="VERSION:2.0\n"; |
|
171 | + $caldata.="METHOD:PUBLISH\n"; |
|
172 | + $caldata.="PRODID:-//Dolibarr CDav//FR\n"; |
|
173 | + $caldata.="BEGIN:".$type."\n"; |
|
174 | + $caldata.="CREATED:".gmdate('Ymd\THis', strtotime($obj->datec))."Z\n"; |
|
175 | + $caldata.="LAST-MODIFIED:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n"; |
|
176 | + $caldata.="DTSTAMP:".gmdate('Ymd\THis', strtotime($obj->lastupd))."Z\n"; |
|
177 | + if($obj->sourceuid=='') |
|
178 | + $caldata.="UID:".$obj->id.'-ev-'.$calid.'-cal-'.CDAV_URI_KEY."\n"; |
|
179 | + else |
|
180 | + $caldata.="UID:".$obj->sourceuid."\n"; |
|
181 | + $caldata.="SUMMARY:".$obj->label."\n"; |
|
182 | + $caldata.="LOCATION:".$location."\n"; |
|
183 | + $caldata.="PRIORITY:".$obj->priority."\n"; |
|
184 | + if($obj->fulldayevent) |
|
185 | + { |
|
186 | + $caldata.="DTSTART;VALUE=DATE:".date('Ymd', strtotime($obj->datep))."\n"; |
|
187 | + if($type=='VEVENT') |
|
188 | + { |
|
189 | + if(trim($obj->datep2)!='') |
|
190 | + $caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n"; |
|
191 | + else |
|
192 | + $caldata.="DTEND;VALUE=DATE:".date('Ymd', strtotime($obj->datep)+(25*3600))."\n"; |
|
193 | + } |
|
194 | + elseif(trim($obj->datep2)!='') |
|
195 | + $caldata.="DUE;VALUE=DATE:".date('Ymd', strtotime($obj->datep2)+1)."\n"; |
|
196 | + } |
|
197 | + else |
|
198 | + { |
|
199 | + $caldata.="DTSTART;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
200 | + if($type=='VEVENT') |
|
201 | + { |
|
202 | + if(trim($obj->datep2)!='') |
|
203 | + $caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
204 | + else |
|
205 | + $caldata.="DTEND;TZID=".$timezone.":".strtr($obj->datep,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
206 | + } |
|
207 | + elseif(trim($obj->datep2)!='') |
|
208 | + $caldata.="DUE;TZID=".$timezone.":".strtr($obj->datep2,array(" "=>"T", ":"=>"", "-"=>""))."\n"; |
|
209 | + } |
|
210 | + $caldata.="CLASS:PUBLIC\n"; |
|
211 | + if($obj->transparency==1) |
|
212 | + $caldata.="TRANSP:TRANSPARENT\n"; |
|
213 | + else |
|
214 | + $caldata.="TRANSP:OPAQUE\n"; |
|
215 | 215 | |
216 | - if($type=='VEVENT') |
|
217 | - $caldata.="STATUS:CONFIRMED\n"; |
|
218 | - elseif($obj->percent==0) |
|
219 | - $caldata.="STATUS:NEEDS-ACTION\n"; |
|
220 | - elseif($obj->percent==100) |
|
221 | - $caldata.="STATUS:COMPLETED\n"; |
|
222 | - else |
|
223 | - { |
|
224 | - $caldata.="STATUS:IN-PROCESS\n"; |
|
225 | - $caldata.="PERCENT-COMPLETE:".$obj->percent."\n"; |
|
226 | - } |
|
216 | + if($type=='VEVENT') |
|
217 | + $caldata.="STATUS:CONFIRMED\n"; |
|
218 | + elseif($obj->percent==0) |
|
219 | + $caldata.="STATUS:NEEDS-ACTION\n"; |
|
220 | + elseif($obj->percent==100) |
|
221 | + $caldata.="STATUS:COMPLETED\n"; |
|
222 | + else |
|
223 | + { |
|
224 | + $caldata.="STATUS:IN-PROCESS\n"; |
|
225 | + $caldata.="PERCENT-COMPLETE:".$obj->percent."\n"; |
|
226 | + } |
|
227 | 227 | |
228 | - $caldata.="DESCRIPTION:"; |
|
229 | - $caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>"")); |
|
230 | - if(!empty($obj->soc_nom)) |
|
231 | - $caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom; |
|
232 | - if(!empty($obj->soc_phone)) |
|
233 | - $caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone; |
|
234 | - if(!empty($obj->firstname) || !empty($obj->lastname)) |
|
235 | - $caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname); |
|
236 | - if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile)) |
|
237 | - $caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile); |
|
238 | - if(strpos($obj->other_users,',')) // several |
|
239 | - $caldata.="\\n*DOLIBARR-USR: ".$obj->other_users; |
|
240 | - $caldata.="\n"; |
|
228 | + $caldata.="DESCRIPTION:"; |
|
229 | + $caldata.=strtr($obj->note, array("\n"=>"\\n", "\r"=>"")); |
|
230 | + if(!empty($obj->soc_nom)) |
|
231 | + $caldata.="\\n*DOLIBARR-SOC: ".$obj->soc_nom; |
|
232 | + if(!empty($obj->soc_phone)) |
|
233 | + $caldata.="\\n*DOLIBARR-SOC-TEL: ".$obj->soc_phone; |
|
234 | + if(!empty($obj->firstname) || !empty($obj->lastname)) |
|
235 | + $caldata.="\\n*DOLIBARR-CTC: ".trim($obj->firstname.' '.$obj->lastname); |
|
236 | + if(!empty($obj->phone) || !empty($obj->phone_perso) || !empty($obj->phone_mobile)) |
|
237 | + $caldata.="\\n*DOLIBARR-CTC-TEL: ".trim($obj->phone.' '.$obj->phone_perso.' '.$obj->phone_mobile); |
|
238 | + if(strpos($obj->other_users,',')) // several |
|
239 | + $caldata.="\\n*DOLIBARR-USR: ".$obj->other_users; |
|
240 | + $caldata.="\n"; |
|
241 | 241 | |
242 | - $caldata.="END:".$type."\n"; |
|
243 | - $caldata.="END:VCALENDAR\n"; |
|
242 | + $caldata.="END:".$type."\n"; |
|
243 | + $caldata.="END:VCALENDAR\n"; |
|
244 | 244 | |
245 | - return $caldata; |
|
246 | - } |
|
245 | + return $caldata; |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * getFullCalendarObjects |
|
250 | - * |
|
251 | - * @param int $calendarId Calendar id |
|
252 | - * @param int $bCalendarData Add calendar data |
|
253 | - * @return array|string[][] |
|
254 | - */ |
|
255 | - public function getFullCalendarObjects($calendarId, $bCalendarData) |
|
256 | - { |
|
257 | - $calid = ($calendarId*1); |
|
258 | - $calevents = array(); |
|
248 | + /** |
|
249 | + * getFullCalendarObjects |
|
250 | + * |
|
251 | + * @param int $calendarId Calendar id |
|
252 | + * @param int $bCalendarData Add calendar data |
|
253 | + * @return array|string[][] |
|
254 | + */ |
|
255 | + public function getFullCalendarObjects($calendarId, $bCalendarData) |
|
256 | + { |
|
257 | + $calid = ($calendarId*1); |
|
258 | + $calevents = array(); |
|
259 | 259 | |
260 | - if(! $this->user->rights->agenda->myactions->read) |
|
261 | - return $calevents; |
|
260 | + if(! $this->user->rights->agenda->myactions->read) |
|
261 | + return $calevents; |
|
262 | 262 | |
263 | - if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read)) |
|
264 | - return $calevents; |
|
263 | + if($calid!=$this->user->id && (!isset($this->user->rights->agenda->allactions->read) || !$this->user->rights->agenda->allactions->read)) |
|
264 | + return $calevents; |
|
265 | 265 | |
266 | - $sql = $this->getSqlCalEvents($calid); |
|
266 | + $sql = $this->getSqlCalEvents($calid); |
|
267 | 267 | |
268 | - $result = $this->db->query($sql); |
|
268 | + $result = $this->db->query($sql); |
|
269 | 269 | |
270 | - if ($result) |
|
271 | - { |
|
272 | - while ($obj = $this->db->fetch_object($result)) |
|
273 | - { |
|
274 | - $calendardata = $this->toVCalendar($calid, $obj); |
|
270 | + if ($result) |
|
271 | + { |
|
272 | + while ($obj = $this->db->fetch_object($result)) |
|
273 | + { |
|
274 | + $calendardata = $this->toVCalendar($calid, $obj); |
|
275 | 275 | |
276 | - if($bCalendarData) |
|
277 | - { |
|
278 | - $calevents[] = array( |
|
279 | - 'calendardata' => $calendardata, |
|
280 | - 'uri' => $obj->id.'-ev-'.CDAV_URI_KEY, |
|
281 | - 'lastmodified' => strtotime($obj->lastupd), |
|
282 | - 'etag' => '"'.md5($calendardata).'"', |
|
283 | - 'calendarid' => $calendarId, |
|
284 | - 'size' => strlen($calendardata), |
|
285 | - 'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo', |
|
286 | - ); |
|
287 | - } |
|
288 | - else |
|
289 | - { |
|
290 | - $calevents[] = array( |
|
291 | - // 'calendardata' => $calendardata, not necessary because etag+size are present |
|
292 | - 'uri' => $obj->id.'-ev-'.CDAV_URI_KEY, |
|
293 | - 'lastmodified' => strtotime($obj->lastupd), |
|
294 | - 'etag' => '"'.md5($calendardata).'"', |
|
295 | - 'calendarid' => $calendarId, |
|
296 | - 'size' => strlen($calendardata), |
|
297 | - 'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo', |
|
298 | - ); |
|
299 | - } |
|
300 | - } |
|
301 | - } |
|
302 | - return $calevents; |
|
303 | - } |
|
276 | + if($bCalendarData) |
|
277 | + { |
|
278 | + $calevents[] = array( |
|
279 | + 'calendardata' => $calendardata, |
|
280 | + 'uri' => $obj->id.'-ev-'.CDAV_URI_KEY, |
|
281 | + 'lastmodified' => strtotime($obj->lastupd), |
|
282 | + 'etag' => '"'.md5($calendardata).'"', |
|
283 | + 'calendarid' => $calendarId, |
|
284 | + 'size' => strlen($calendardata), |
|
285 | + 'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo', |
|
286 | + ); |
|
287 | + } |
|
288 | + else |
|
289 | + { |
|
290 | + $calevents[] = array( |
|
291 | + // 'calendardata' => $calendardata, not necessary because etag+size are present |
|
292 | + 'uri' => $obj->id.'-ev-'.CDAV_URI_KEY, |
|
293 | + 'lastmodified' => strtotime($obj->lastupd), |
|
294 | + 'etag' => '"'.md5($calendardata).'"', |
|
295 | + 'calendarid' => $calendarId, |
|
296 | + 'size' => strlen($calendardata), |
|
297 | + 'component' => strpos($calendardata, 'BEGIN:VEVENT')>0 ? 'vevent' : 'vtodo', |
|
298 | + ); |
|
299 | + } |
|
300 | + } |
|
301 | + } |
|
302 | + return $calevents; |
|
303 | + } |
|
304 | 304 | } |
@@ -24,19 +24,19 @@ discard block |
||
24 | 24 | // define CDAV_CONTACT_TAG if not |
25 | 25 | if(!defined('CDAV_CONTACT_TAG')) |
26 | 26 | { |
27 | - if(isset($conf->global->CDAV_CONTACT_TAG)) |
|
28 | - define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG); |
|
29 | - else |
|
30 | - define('CDAV_CONTACT_TAG', ''); |
|
27 | + if(isset($conf->global->CDAV_CONTACT_TAG)) |
|
28 | + define('CDAV_CONTACT_TAG', $conf->global->CDAV_CONTACT_TAG); |
|
29 | + else |
|
30 | + define('CDAV_CONTACT_TAG', ''); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | // define CDAV_URI_KEY if not |
34 | 34 | if(!defined('CDAV_URI_KEY')) |
35 | 35 | { |
36 | - if(isset($conf->global->CDAV_URI_KEY)) |
|
37 | - define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY); |
|
38 | - else |
|
39 | - define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8)); |
|
36 | + if(isset($conf->global->CDAV_URI_KEY)) |
|
37 | + define('CDAV_URI_KEY', $conf->global->CDAV_URI_KEY); |
|
38 | + else |
|
39 | + define('CDAV_URI_KEY', substr(md5($_SERVER['HTTP_HOST']),0,8)); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -49,24 +49,24 @@ discard block |
||
49 | 49 | */ |
50 | 50 | function dav_admin_prepare_head() |
51 | 51 | { |
52 | - global $db, $langs, $conf; |
|
52 | + global $db, $langs, $conf; |
|
53 | 53 | |
54 | - $h = 0; |
|
55 | - $head = array(); |
|
54 | + $h = 0; |
|
55 | + $head = array(); |
|
56 | 56 | |
57 | - $head[$h][0] = DOL_URL_ROOT.'/admin/dav.php?id='.$object->id; |
|
58 | - $head[$h][1] = $langs->trans("WebDAV"); |
|
59 | - $head[$h][2] = 'webdav'; |
|
60 | - $h++; |
|
57 | + $head[$h][0] = DOL_URL_ROOT.'/admin/dav.php?id='.$object->id; |
|
58 | + $head[$h][1] = $langs->trans("WebDAV"); |
|
59 | + $head[$h][2] = 'webdav'; |
|
60 | + $h++; |
|
61 | 61 | |
62 | - // Show more tabs from modules |
|
63 | - // Entries must be declared in modules descriptor with line |
|
64 | - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
65 | - // $this->tabs = array('entity:-tabname); to remove a tab |
|
66 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav'); |
|
62 | + // Show more tabs from modules |
|
63 | + // Entries must be declared in modules descriptor with line |
|
64 | + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
|
65 | + // $this->tabs = array('entity:-tabname); to remove a tab |
|
66 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav'); |
|
67 | 67 | |
68 | - complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav','remove'); |
|
68 | + complete_head_from_modules($conf,$langs,$object,$head,$h,'admindav','remove'); |
|
69 | 69 | |
70 | - return $head; |
|
70 | + return $head; |
|
71 | 71 | } |
72 | 72 |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | $user = new User($db); |
40 | 40 | if(isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_USER']!='') |
41 | 41 | { |
42 | - $user->fetch('',$_SERVER['PHP_AUTH_USER']); |
|
43 | - $user->getrights(); |
|
42 | + $user->fetch('',$_SERVER['PHP_AUTH_USER']); |
|
43 | + $user->getrights(); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | // Load translation files required by the page |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | |
49 | 49 | |
50 | 50 | if(empty($conf->dav->enabled)) |
51 | - accessforbidden(); |
|
51 | + accessforbidden(); |
|
52 | 52 | |
53 | 53 | |
54 | 54 | // settings |
@@ -59,27 +59,27 @@ discard block |
||
59 | 59 | |
60 | 60 | // Authentication callback function |
61 | 61 | $authBackend = new \Sabre\DAV\Auth\Backend\BasicCallBack(function ($username, $password) { |
62 | - global $user; |
|
63 | - global $conf; |
|
64 | - global $dolibarr_main_authentication; |
|
65 | - |
|
66 | - if (empty($user->login)) |
|
67 | - return false; |
|
68 | - if ($user->socid > 0) |
|
69 | - return false; |
|
70 | - if ($user->login != $username) |
|
71 | - return false; |
|
72 | - |
|
73 | - // Authentication mode |
|
74 | - if (empty($dolibarr_main_authentication)) |
|
75 | - $dolibarr_main_authentication='http,dolibarr'; |
|
76 | - $authmode = explode(',',$dolibarr_main_authentication); |
|
77 | - $entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1)); |
|
78 | - |
|
79 | - if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username) |
|
80 | - return false; |
|
81 | - |
|
82 | - return true; |
|
62 | + global $user; |
|
63 | + global $conf; |
|
64 | + global $dolibarr_main_authentication; |
|
65 | + |
|
66 | + if (empty($user->login)) |
|
67 | + return false; |
|
68 | + if ($user->socid > 0) |
|
69 | + return false; |
|
70 | + if ($user->login != $username) |
|
71 | + return false; |
|
72 | + |
|
73 | + // Authentication mode |
|
74 | + if (empty($dolibarr_main_authentication)) |
|
75 | + $dolibarr_main_authentication='http,dolibarr'; |
|
76 | + $authmode = explode(',',$dolibarr_main_authentication); |
|
77 | + $entity = (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1)); |
|
78 | + |
|
79 | + if (checkLoginPassEntity($username,$password,$entity,$authmode) != $username) |
|
80 | + return false; |
|
81 | + |
|
82 | + return true; |
|
83 | 83 | }); |
84 | 84 | |
85 | 85 | $authBackend->setRealm(constant('DOL_APPLICATION_TITLE')); |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | // Public dir |
101 | 101 | if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR)) |
102 | 102 | { |
103 | - $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/public'); |
|
103 | + $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/public'); |
|
104 | 104 | } |
105 | 105 | // Private dir |
106 | 106 | $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/dav/private'); |
107 | 107 | // ECM dir |
108 | 108 | if (! empty($conf->ecm->enabled) && ! empty($conf->global->DAV_ALLOW_ECM_DIR)) |
109 | 109 | { |
110 | - $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/ecm'); |
|
110 | + $nodes[] = new \Sabre\DAV\FS\Directory($dolibarr_main_data_root. '/ecm'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | |
@@ -135,12 +135,12 @@ discard block |
||
135 | 135 | |
136 | 136 | // Add authentication function |
137 | 137 | if ((empty($conf->global->DAV_ALLOW_PUBLIC_DIR) |
138 | - || ! preg_match('/'.preg_quote(DOL_URL_ROOT.'/dav/fileserver.php/public','/').'/', $_SERVER["PHP_SELF"])) |
|
139 | - && ! preg_match('/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER["QUERY_STRING"]) // URL for Sabre browser resources |
|
140 | - ) |
|
138 | + || ! preg_match('/'.preg_quote(DOL_URL_ROOT.'/dav/fileserver.php/public','/').'/', $_SERVER["PHP_SELF"])) |
|
139 | + && ! preg_match('/^sabreAction=asset&assetName=[a-zA-Z0-9%\-\/]+\.(png|css|woff|ico|ttf)$/', $_SERVER["QUERY_STRING"]) // URL for Sabre browser resources |
|
140 | + ) |
|
141 | 141 | { |
142 | - //var_dump($_SERVER["QUERY_STRING"]);exit; |
|
143 | - $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
|
142 | + //var_dump($_SERVER["QUERY_STRING"]);exit; |
|
143 | + $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend)); |
|
144 | 144 | } |
145 | 145 | // Support for LOCK and UNLOCK |
146 | 146 | $lockBackend = new \Sabre\DAV\Locks\Backend\File($tmpDir . '/.locksdb'); |
@@ -30,60 +30,60 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class Export |
32 | 32 | { |
33 | - /** |
|
33 | + /** |
|
34 | 34 | * @var DoliDB Database handler. |
35 | 35 | */ |
36 | 36 | public $db; |
37 | 37 | |
38 | - var $array_export_code=array(); // Tableau de "idmodule_numlot" |
|
39 | - var $array_export_module=array(); // Tableau de "nom de modules" |
|
40 | - var $array_export_label=array(); // Tableau de "libelle de lots" |
|
41 | - var $array_export_sql_start=array(); // Tableau des "requetes sql" |
|
42 | - var $array_export_sql_end=array(); // Tableau des "requetes sql" |
|
43 | - var $array_export_sql_order=array(); // Tableau des "requetes sql" |
|
44 | - |
|
45 | - var $array_export_fields=array(); // Tableau des listes de champ+libelle a exporter |
|
46 | - var $array_export_TypeFields=array(); // Tableau des listes de champ+Type de filtre |
|
47 | - var $array_export_FilterValue=array(); // Tableau des listes de champ+Valeur a filtrer |
|
48 | - var $array_export_entities=array(); // Tableau des listes de champ+alias a exporter |
|
49 | - var $array_export_dependencies=array(); // array of list of entities that must take care of the DISTINCT if a field is added into export |
|
50 | - var $array_export_special=array(); // Tableau des operations speciales sur champ |
|
38 | + var $array_export_code=array(); // Tableau de "idmodule_numlot" |
|
39 | + var $array_export_module=array(); // Tableau de "nom de modules" |
|
40 | + var $array_export_label=array(); // Tableau de "libelle de lots" |
|
41 | + var $array_export_sql_start=array(); // Tableau des "requetes sql" |
|
42 | + var $array_export_sql_end=array(); // Tableau des "requetes sql" |
|
43 | + var $array_export_sql_order=array(); // Tableau des "requetes sql" |
|
44 | + |
|
45 | + var $array_export_fields=array(); // Tableau des listes de champ+libelle a exporter |
|
46 | + var $array_export_TypeFields=array(); // Tableau des listes de champ+Type de filtre |
|
47 | + var $array_export_FilterValue=array(); // Tableau des listes de champ+Valeur a filtrer |
|
48 | + var $array_export_entities=array(); // Tableau des listes de champ+alias a exporter |
|
49 | + var $array_export_dependencies=array(); // array of list of entities that must take care of the DISTINCT if a field is added into export |
|
50 | + var $array_export_special=array(); // Tableau des operations speciales sur champ |
|
51 | 51 | var $array_export_examplevalues=array(); // array with examples |
52 | 52 | |
53 | - // To store export modules |
|
54 | - var $hexa; |
|
55 | - var $hexafiltervalue; |
|
56 | - var $datatoexport; |
|
57 | - var $model_name; |
|
53 | + // To store export modules |
|
54 | + var $hexa; |
|
55 | + var $hexafiltervalue; |
|
56 | + var $datatoexport; |
|
57 | + var $model_name; |
|
58 | 58 | |
59 | - var $sqlusedforexport; |
|
59 | + var $sqlusedforexport; |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Constructor |
|
64 | - * |
|
65 | - * @param DoliDB $db Database handler |
|
66 | - */ |
|
67 | - function __construct($db) |
|
68 | - { |
|
69 | - $this->db=$db; |
|
70 | - } |
|
62 | + /** |
|
63 | + * Constructor |
|
64 | + * |
|
65 | + * @param DoliDB $db Database handler |
|
66 | + */ |
|
67 | + function __construct($db) |
|
68 | + { |
|
69 | + $this->db=$db; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | 73 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
74 | - /** |
|
75 | - * Load an exportable dataset |
|
76 | - * |
|
77 | - * @param User $user Object user making export |
|
78 | - * @param string $filter Load a particular dataset only |
|
79 | - * @return int <0 if KO, >0 if OK |
|
80 | - */ |
|
81 | - function load_arrays($user,$filter='') |
|
82 | - { |
|
74 | + /** |
|
75 | + * Load an exportable dataset |
|
76 | + * |
|
77 | + * @param User $user Object user making export |
|
78 | + * @param string $filter Load a particular dataset only |
|
79 | + * @return int <0 if KO, >0 if OK |
|
80 | + */ |
|
81 | + function load_arrays($user,$filter='') |
|
82 | + { |
|
83 | 83 | // phpcs:enable |
84 | - global $langs,$conf,$mysoc; |
|
84 | + global $langs,$conf,$mysoc; |
|
85 | 85 | |
86 | - dol_syslog(get_class($this)."::load_arrays user=".$user->id." filter=".$filter); |
|
86 | + dol_syslog(get_class($this)."::load_arrays user=".$user->id." filter=".$filter); |
|
87 | 87 | |
88 | 88 | $i=0; |
89 | 89 | |
@@ -92,798 +92,798 @@ discard block |
||
92 | 92 | |
93 | 93 | $modulesdir = dolGetModulesDirs(); |
94 | 94 | |
95 | - foreach($modulesdir as $dir) |
|
96 | - { |
|
97 | - // Search available exports |
|
98 | - $handle=@opendir(dol_osencode($dir)); |
|
99 | - if (is_resource($handle)) |
|
100 | - { |
|
95 | + foreach($modulesdir as $dir) |
|
96 | + { |
|
97 | + // Search available exports |
|
98 | + $handle=@opendir(dol_osencode($dir)); |
|
99 | + if (is_resource($handle)) |
|
100 | + { |
|
101 | 101 | // Search module files |
102 | - while (($file = readdir($handle))!==false) |
|
103 | - { |
|
104 | - if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg)) |
|
105 | - { |
|
106 | - $modulename=$reg[1]; |
|
107 | - |
|
108 | - // Defined if module is enabled |
|
109 | - $enabled=true; |
|
110 | - $part=strtolower(preg_replace('/^mod/i','',$modulename)); |
|
111 | - if ($part == 'propale') $part='propal'; |
|
112 | - if (empty($conf->$part->enabled)) $enabled=false; |
|
113 | - |
|
114 | - if ($enabled) |
|
115 | - { |
|
116 | - // Loading Class |
|
117 | - $file = $dir.$modulename.".class.php"; |
|
118 | - $classname = $modulename; |
|
119 | - require_once $file; |
|
120 | - $module = new $classname($this->db); |
|
121 | - |
|
122 | - if (isset($module->export_code) && is_array($module->export_code)) |
|
123 | - { |
|
124 | - foreach($module->export_code as $r => $value) |
|
125 | - { |
|
102 | + while (($file = readdir($handle))!==false) |
|
103 | + { |
|
104 | + if (is_readable($dir.$file) && preg_match("/^(mod.*)\.class\.php$/i",$file,$reg)) |
|
105 | + { |
|
106 | + $modulename=$reg[1]; |
|
107 | + |
|
108 | + // Defined if module is enabled |
|
109 | + $enabled=true; |
|
110 | + $part=strtolower(preg_replace('/^mod/i','',$modulename)); |
|
111 | + if ($part == 'propale') $part='propal'; |
|
112 | + if (empty($conf->$part->enabled)) $enabled=false; |
|
113 | + |
|
114 | + if ($enabled) |
|
115 | + { |
|
116 | + // Loading Class |
|
117 | + $file = $dir.$modulename.".class.php"; |
|
118 | + $classname = $modulename; |
|
119 | + require_once $file; |
|
120 | + $module = new $classname($this->db); |
|
121 | + |
|
122 | + if (isset($module->export_code) && is_array($module->export_code)) |
|
123 | + { |
|
124 | + foreach($module->export_code as $r => $value) |
|
125 | + { |
|
126 | 126 | //print $i.'-'.$filter.'-'.$modulename.'-'.join(',',$module->export_code).'<br>'; |
127 | - if ($filter && ($filter != $module->export_code[$r])) continue; |
|
127 | + if ($filter && ($filter != $module->export_code[$r])) continue; |
|
128 | 128 | |
129 | 129 | // Test if condition to show are ok |
130 | 130 | if (! empty($module->export_enabled[$r]) && ! verifCond($module->export_enabled[$r])) continue; |
131 | 131 | |
132 | 132 | // Test if permissions are ok |
133 | - $bool=true; |
|
134 | - if (isset($module->export_permission)) |
|
135 | - { |
|
136 | - foreach($module->export_permission[$r] as $val) |
|
137 | - { |
|
138 | - $perm=$val; |
|
139 | - //print_r("$perm[0]-$perm[1]-$perm[2]<br>"); |
|
140 | - if (! empty($perm[2])) |
|
141 | - { |
|
142 | - $bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]}; |
|
143 | - } |
|
144 | - else |
|
145 | - { |
|
146 | - $bool=$user->rights->{$perm[0]}->{$perm[1]}; |
|
147 | - } |
|
148 | - if ($perm[0]=='user' && $user->admin) $bool=true; |
|
149 | - if (! $bool) break; |
|
150 | - } |
|
151 | - } |
|
152 | - //print $bool." $perm[0]"."<br>"; |
|
153 | - |
|
154 | - // Permissions ok |
|
155 | - // if ($bool) |
|
156 | - // { |
|
157 | - // Charge fichier lang en rapport |
|
158 | - $langtoload=$module->getLangFilesArray(); |
|
159 | - if (is_array($langtoload)) |
|
160 | - { |
|
161 | - foreach($langtoload as $key) |
|
162 | - { |
|
163 | - $langs->load($key); |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - // Module |
|
168 | - $this->array_export_module[$i]=$module; |
|
169 | - // Permission |
|
170 | - $this->array_export_perms[$i]=$bool; |
|
171 | - // Icon |
|
172 | - $this->array_export_icon[$i]=(isset($module->export_icon[$r])?$module->export_icon[$r]:$module->picto); |
|
173 | - // Code du dataset export |
|
174 | - $this->array_export_code[$i]=$module->export_code[$r]; |
|
175 | - // Libelle du dataset export |
|
176 | - $this->array_export_label[$i]=$module->getExportDatasetLabel($r); |
|
177 | - // Tableau des champ a exporter (cle=champ, valeur=libelle) |
|
178 | - $this->array_export_fields[$i]=$module->export_fields_array[$r]; |
|
179 | - // Tableau des champs a filtrer (cle=champ, valeur1=type de donnees) on verifie que le module a des filtres |
|
180 | - $this->array_export_TypeFields[$i]=(isset($module->export_TypeFields_array[$r])?$module->export_TypeFields_array[$r]:''); |
|
181 | - // Tableau des entites a exporter (cle=champ, valeur=entite) |
|
182 | - $this->array_export_entities[$i]=$module->export_entities_array[$r]; |
|
183 | - // Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records) |
|
184 | - $this->array_export_dependencies[$i]=(! empty($module->export_dependencies_array[$r])?$module->export_dependencies_array[$r]:''); |
|
185 | - // Tableau des operations speciales sur champ |
|
186 | - $this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:''); |
|
187 | - // Array of examples |
|
188 | - $this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r]; |
|
189 | - |
|
190 | - // Requete sql du dataset |
|
191 | - $this->array_export_sql_start[$i]=$module->export_sql_start[$r]; |
|
192 | - $this->array_export_sql_end[$i]=$module->export_sql_end[$r]; |
|
193 | - $this->array_export_sql_order[$i]=$module->export_sql_order[$r]; |
|
194 | - //$this->array_export_sql[$i]=$module->export_sql[$r]; |
|
195 | - |
|
196 | - dol_syslog(get_class($this)."::load_arrays loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".(! empty($module->export_fields_code[$r])?count($module->export_fields_code[$r]):'')); |
|
197 | - $i++; |
|
198 | - // } |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
133 | + $bool=true; |
|
134 | + if (isset($module->export_permission)) |
|
135 | + { |
|
136 | + foreach($module->export_permission[$r] as $val) |
|
137 | + { |
|
138 | + $perm=$val; |
|
139 | + //print_r("$perm[0]-$perm[1]-$perm[2]<br>"); |
|
140 | + if (! empty($perm[2])) |
|
141 | + { |
|
142 | + $bool=$user->rights->{$perm[0]}->{$perm[1]}->{$perm[2]}; |
|
143 | + } |
|
144 | + else |
|
145 | + { |
|
146 | + $bool=$user->rights->{$perm[0]}->{$perm[1]}; |
|
147 | + } |
|
148 | + if ($perm[0]=='user' && $user->admin) $bool=true; |
|
149 | + if (! $bool) break; |
|
150 | + } |
|
151 | + } |
|
152 | + //print $bool." $perm[0]"."<br>"; |
|
153 | + |
|
154 | + // Permissions ok |
|
155 | + // if ($bool) |
|
156 | + // { |
|
157 | + // Charge fichier lang en rapport |
|
158 | + $langtoload=$module->getLangFilesArray(); |
|
159 | + if (is_array($langtoload)) |
|
160 | + { |
|
161 | + foreach($langtoload as $key) |
|
162 | + { |
|
163 | + $langs->load($key); |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + // Module |
|
168 | + $this->array_export_module[$i]=$module; |
|
169 | + // Permission |
|
170 | + $this->array_export_perms[$i]=$bool; |
|
171 | + // Icon |
|
172 | + $this->array_export_icon[$i]=(isset($module->export_icon[$r])?$module->export_icon[$r]:$module->picto); |
|
173 | + // Code du dataset export |
|
174 | + $this->array_export_code[$i]=$module->export_code[$r]; |
|
175 | + // Libelle du dataset export |
|
176 | + $this->array_export_label[$i]=$module->getExportDatasetLabel($r); |
|
177 | + // Tableau des champ a exporter (cle=champ, valeur=libelle) |
|
178 | + $this->array_export_fields[$i]=$module->export_fields_array[$r]; |
|
179 | + // Tableau des champs a filtrer (cle=champ, valeur1=type de donnees) on verifie que le module a des filtres |
|
180 | + $this->array_export_TypeFields[$i]=(isset($module->export_TypeFields_array[$r])?$module->export_TypeFields_array[$r]:''); |
|
181 | + // Tableau des entites a exporter (cle=champ, valeur=entite) |
|
182 | + $this->array_export_entities[$i]=$module->export_entities_array[$r]; |
|
183 | + // Tableau des entites qui requiert abandon du DISTINCT (cle=entite, valeur=champ id child records) |
|
184 | + $this->array_export_dependencies[$i]=(! empty($module->export_dependencies_array[$r])?$module->export_dependencies_array[$r]:''); |
|
185 | + // Tableau des operations speciales sur champ |
|
186 | + $this->array_export_special[$i]=(! empty($module->export_special_array[$r])?$module->export_special_array[$r]:''); |
|
187 | + // Array of examples |
|
188 | + $this->array_export_examplevalues[$i]=$module->export_examplevalues_array[$r]; |
|
189 | + |
|
190 | + // Requete sql du dataset |
|
191 | + $this->array_export_sql_start[$i]=$module->export_sql_start[$r]; |
|
192 | + $this->array_export_sql_end[$i]=$module->export_sql_end[$r]; |
|
193 | + $this->array_export_sql_order[$i]=$module->export_sql_order[$r]; |
|
194 | + //$this->array_export_sql[$i]=$module->export_sql[$r]; |
|
195 | + |
|
196 | + dol_syslog(get_class($this)."::load_arrays loaded for module ".$modulename." with index ".$i.", dataset=".$module->export_code[$r].", nb of fields=".(! empty($module->export_fields_code[$r])?count($module->export_fields_code[$r]):'')); |
|
197 | + $i++; |
|
198 | + // } |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | 204 | closedir($handle); |
205 | - } |
|
206 | - } |
|
205 | + } |
|
206 | + } |
|
207 | 207 | |
208 | - return 1; |
|
209 | - } |
|
208 | + return 1; |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | 212 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
213 | - /** |
|
214 | - * Build the sql export request. |
|
215 | - * Arrays this->array_export_xxx are already loaded for required datatoexport |
|
216 | - * |
|
217 | - * @param int $indice Indice of export |
|
218 | - * @param array $array_selected Filter fields on array of fields to export |
|
219 | - * @param array $array_filterValue Filter records on array of value for fields |
|
220 | - * @return string SQL String. Example "select s.rowid as r_rowid, s.status as s_status from ..." |
|
221 | - */ |
|
222 | - function build_sql($indice, $array_selected, $array_filterValue) |
|
223 | - { |
|
213 | + /** |
|
214 | + * Build the sql export request. |
|
215 | + * Arrays this->array_export_xxx are already loaded for required datatoexport |
|
216 | + * |
|
217 | + * @param int $indice Indice of export |
|
218 | + * @param array $array_selected Filter fields on array of fields to export |
|
219 | + * @param array $array_filterValue Filter records on array of value for fields |
|
220 | + * @return string SQL String. Example "select s.rowid as r_rowid, s.status as s_status from ..." |
|
221 | + */ |
|
222 | + function build_sql($indice, $array_selected, $array_filterValue) |
|
223 | + { |
|
224 | 224 | // phpcs:enable |
225 | - // Build the sql request |
|
226 | - $sql=$this->array_export_sql_start[$indice]; |
|
227 | - $i=0; |
|
228 | - |
|
229 | - //print_r($array_selected); |
|
230 | - foreach ($this->array_export_fields[$indice] as $key => $value) |
|
231 | - { |
|
232 | - if (! array_key_exists($key, $array_selected)) continue; // Field not selected |
|
225 | + // Build the sql request |
|
226 | + $sql=$this->array_export_sql_start[$indice]; |
|
227 | + $i=0; |
|
228 | + |
|
229 | + //print_r($array_selected); |
|
230 | + foreach ($this->array_export_fields[$indice] as $key => $value) |
|
231 | + { |
|
232 | + if (! array_key_exists($key, $array_selected)) continue; // Field not selected |
|
233 | 233 | if (preg_match('/^none\./', $key)) continue; // A field that must not appears into SQL |
234 | - if ($i > 0) $sql.=', '; |
|
235 | - else $i++; |
|
236 | - |
|
237 | - if (strpos($key, ' as ')===false) { |
|
238 | - $newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key); |
|
239 | - } else { |
|
240 | - $newfield=$key; |
|
241 | - } |
|
242 | - |
|
243 | - $sql.=$newfield; |
|
244 | - } |
|
245 | - $sql.=$this->array_export_sql_end[$indice]; |
|
246 | - |
|
247 | - // Add the WHERE part. Filtering into sql if a filtering array is provided |
|
248 | - if (is_array($array_filterValue) && !empty($array_filterValue)) |
|
249 | - { |
|
250 | - $sqlWhere=''; |
|
251 | - // Loop on each condition to add |
|
252 | - foreach ($array_filterValue as $key => $value) |
|
253 | - { |
|
254 | - if (preg_match('/GROUP_CONCAT/i', $key)) continue; |
|
255 | - if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]); |
|
256 | - } |
|
257 | - $sql.=$sqlWhere; |
|
258 | - } |
|
259 | - |
|
260 | - // Add the order |
|
261 | - $sql.=$this->array_export_sql_order[$indice]; |
|
262 | - |
|
263 | - // Add the HAVING part. |
|
264 | - if (is_array($array_filterValue) && !empty($array_filterValue)) |
|
265 | - { |
|
266 | - // Loop on each condition to add |
|
267 | - foreach ($array_filterValue as $key => $value) |
|
268 | - { |
|
269 | - if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]); |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - return $sql; |
|
274 | - } |
|
234 | + if ($i > 0) $sql.=', '; |
|
235 | + else $i++; |
|
236 | + |
|
237 | + if (strpos($key, ' as ')===false) { |
|
238 | + $newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key); |
|
239 | + } else { |
|
240 | + $newfield=$key; |
|
241 | + } |
|
242 | + |
|
243 | + $sql.=$newfield; |
|
244 | + } |
|
245 | + $sql.=$this->array_export_sql_end[$indice]; |
|
246 | + |
|
247 | + // Add the WHERE part. Filtering into sql if a filtering array is provided |
|
248 | + if (is_array($array_filterValue) && !empty($array_filterValue)) |
|
249 | + { |
|
250 | + $sqlWhere=''; |
|
251 | + // Loop on each condition to add |
|
252 | + foreach ($array_filterValue as $key => $value) |
|
253 | + { |
|
254 | + if (preg_match('/GROUP_CONCAT/i', $key)) continue; |
|
255 | + if ($value != '') $sqlWhere.=" and ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]); |
|
256 | + } |
|
257 | + $sql.=$sqlWhere; |
|
258 | + } |
|
259 | + |
|
260 | + // Add the order |
|
261 | + $sql.=$this->array_export_sql_order[$indice]; |
|
262 | + |
|
263 | + // Add the HAVING part. |
|
264 | + if (is_array($array_filterValue) && !empty($array_filterValue)) |
|
265 | + { |
|
266 | + // Loop on each condition to add |
|
267 | + foreach ($array_filterValue as $key => $value) |
|
268 | + { |
|
269 | + if (preg_match('/GROUP_CONCAT/i', $key) and $value != '') $sql.=" HAVING ".$this->build_filterQuery($this->array_export_TypeFields[$indice][$key], $key, $array_filterValue[$key]); |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + return $sql; |
|
274 | + } |
|
275 | 275 | |
276 | 276 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
277 | - /** |
|
278 | - * Build the conditionnal string from filter the query |
|
279 | - * |
|
280 | - * @param string $TypeField Type of Field to filter |
|
281 | - * @param string $NameField Name of the field to filter |
|
282 | - * @param string $ValueField Value of the field for filter. Must not be '' |
|
283 | - * @return string sql string of then field ex : "field='xxx'>" |
|
284 | - */ |
|
285 | - function build_filterQuery($TypeField, $NameField, $ValueField) |
|
286 | - { |
|
277 | + /** |
|
278 | + * Build the conditionnal string from filter the query |
|
279 | + * |
|
280 | + * @param string $TypeField Type of Field to filter |
|
281 | + * @param string $NameField Name of the field to filter |
|
282 | + * @param string $ValueField Value of the field for filter. Must not be '' |
|
283 | + * @return string sql string of then field ex : "field='xxx'>" |
|
284 | + */ |
|
285 | + function build_filterQuery($TypeField, $NameField, $ValueField) |
|
286 | + { |
|
287 | 287 | // phpcs:enable |
288 | - //print $TypeField." ".$NameField." ".$ValueField; |
|
289 | - $InfoFieldList = explode(":", $TypeField); |
|
290 | - // build the input field on depend of the type of file |
|
291 | - switch ($InfoFieldList[0]) { |
|
292 | - case 'Text': |
|
293 | - if (! (strpos($ValueField, '%') === false)) |
|
294 | - $szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'"; |
|
295 | - else |
|
296 | - $szFilterQuery.=" ".$NameField." = '".$ValueField."'"; |
|
297 | - break; |
|
298 | - case 'Date': |
|
299 | - if (strpos($ValueField, "+") > 0) |
|
300 | - { |
|
301 | - // mode plage |
|
302 | - $ValueArray = explode("+", $ValueField); |
|
303 | - $szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">="); |
|
304 | - $szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")"; |
|
305 | - } |
|
306 | - else |
|
307 | - { |
|
308 | - if (is_numeric(substr($ValueField,0,1))) |
|
309 | - $szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"="); |
|
310 | - else |
|
311 | - $szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1)); |
|
312 | - } |
|
313 | - break; |
|
314 | - case 'Duree': |
|
315 | - break; |
|
316 | - case 'Numeric': |
|
317 | - // si le signe - |
|
318 | - if (strpos($ValueField, "+") > 0) |
|
319 | - { |
|
320 | - // mode plage |
|
321 | - $ValueArray = explode("+", $ValueField); |
|
322 | - $szFilterQuery ="(".$NameField.">=".$ValueArray[0]; |
|
323 | - $szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")"; |
|
324 | - } |
|
325 | - else |
|
326 | - { |
|
327 | - if (is_numeric(substr($ValueField,0,1))) |
|
328 | - $szFilterQuery=" ".$NameField."=".$ValueField; |
|
329 | - else |
|
330 | - $szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1); |
|
331 | - } |
|
332 | - break; |
|
333 | - case 'Boolean': |
|
334 | - $szFilterQuery=" ".$NameField."=".(is_numeric($ValueField) ? $ValueField : ($ValueField =='yes' ? 1: 0) ); |
|
335 | - break; |
|
336 | - case 'Status': |
|
337 | - case 'List': |
|
338 | - if (is_numeric($ValueField)) |
|
339 | - $szFilterQuery=" ".$NameField."=".$ValueField; |
|
340 | - else { |
|
288 | + //print $TypeField." ".$NameField." ".$ValueField; |
|
289 | + $InfoFieldList = explode(":", $TypeField); |
|
290 | + // build the input field on depend of the type of file |
|
291 | + switch ($InfoFieldList[0]) { |
|
292 | + case 'Text': |
|
293 | + if (! (strpos($ValueField, '%') === false)) |
|
294 | + $szFilterQuery.=" ".$NameField." LIKE '".$ValueField."'"; |
|
295 | + else |
|
296 | + $szFilterQuery.=" ".$NameField." = '".$ValueField."'"; |
|
297 | + break; |
|
298 | + case 'Date': |
|
299 | + if (strpos($ValueField, "+") > 0) |
|
300 | + { |
|
301 | + // mode plage |
|
302 | + $ValueArray = explode("+", $ValueField); |
|
303 | + $szFilterQuery ="(".$this->conditionDate($NameField,trim($ValueArray[0]),">="); |
|
304 | + $szFilterQuery.=" AND ".$this->conditionDate($NameField,trim($ValueArray[1]),"<=").")"; |
|
305 | + } |
|
306 | + else |
|
307 | + { |
|
308 | + if (is_numeric(substr($ValueField,0,1))) |
|
309 | + $szFilterQuery=$this->conditionDate($NameField,trim($ValueField),"="); |
|
310 | + else |
|
311 | + $szFilterQuery=$this->conditionDate($NameField,trim(substr($ValueField,1)),substr($ValueField,0,1)); |
|
312 | + } |
|
313 | + break; |
|
314 | + case 'Duree': |
|
315 | + break; |
|
316 | + case 'Numeric': |
|
317 | + // si le signe - |
|
318 | + if (strpos($ValueField, "+") > 0) |
|
319 | + { |
|
320 | + // mode plage |
|
321 | + $ValueArray = explode("+", $ValueField); |
|
322 | + $szFilterQuery ="(".$NameField.">=".$ValueArray[0]; |
|
323 | + $szFilterQuery.=" AND ".$NameField."<=".$ValueArray[1].")"; |
|
324 | + } |
|
325 | + else |
|
326 | + { |
|
327 | + if (is_numeric(substr($ValueField,0,1))) |
|
328 | + $szFilterQuery=" ".$NameField."=".$ValueField; |
|
329 | + else |
|
330 | + $szFilterQuery=" ".$NameField.substr($ValueField,0,1).substr($ValueField,1); |
|
331 | + } |
|
332 | + break; |
|
333 | + case 'Boolean': |
|
334 | + $szFilterQuery=" ".$NameField."=".(is_numeric($ValueField) ? $ValueField : ($ValueField =='yes' ? 1: 0) ); |
|
335 | + break; |
|
336 | + case 'Status': |
|
337 | + case 'List': |
|
338 | + if (is_numeric($ValueField)) |
|
339 | + $szFilterQuery=" ".$NameField."=".$ValueField; |
|
340 | + else { |
|
341 | 341 | if (! (strpos($ValueField, '%') === false)) |
342 | 342 | $szFilterQuery=" ".$NameField." LIKE '".$ValueField."'"; |
343 | 343 | else |
344 | 344 | $szFilterQuery=" ".$NameField." = '".$ValueField."'"; |
345 | - } |
|
346 | - break; |
|
347 | - default: |
|
348 | - dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR); |
|
349 | - } |
|
350 | - |
|
351 | - return $szFilterQuery; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * conditionDate |
|
356 | - * |
|
357 | - * @param string $Field Field operand 1 |
|
358 | - * @param string $Value Value operand 2 |
|
359 | - * @param string $Sens Comparison operator |
|
360 | - * @return string |
|
361 | - */ |
|
362 | - function conditionDate($Field, $Value, $Sens) |
|
363 | - { |
|
364 | - // TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN |
|
365 | - if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'"; |
|
366 | - elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'"; |
|
367 | - else $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value; |
|
368 | - return $Condition; |
|
369 | - } |
|
345 | + } |
|
346 | + break; |
|
347 | + default: |
|
348 | + dol_syslog("Error we try to forge an sql export request with a condition on a field with type '".$InfoFieldList[0]."' (defined into module descriptor) but this type is unknown/not supported. It looks like a bug into module descriptor.", LOG_ERR); |
|
349 | + } |
|
350 | + |
|
351 | + return $szFilterQuery; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * conditionDate |
|
356 | + * |
|
357 | + * @param string $Field Field operand 1 |
|
358 | + * @param string $Value Value operand 2 |
|
359 | + * @param string $Sens Comparison operator |
|
360 | + * @return string |
|
361 | + */ |
|
362 | + function conditionDate($Field, $Value, $Sens) |
|
363 | + { |
|
364 | + // TODO date_format is forbidden, not performant and not portable. Use instead BETWEEN |
|
365 | + if (strlen($Value)==4) $Condition=" date_format(".$Field.",'%Y') ".$Sens." '".$Value."'"; |
|
366 | + elseif (strlen($Value)==6) $Condition=" date_format(".$Field.",'%Y%m') ".$Sens." '".$Value."'"; |
|
367 | + else $Condition=" date_format(".$Field.",'%Y%m%d') ".$Sens." ".$Value; |
|
368 | + return $Condition; |
|
369 | + } |
|
370 | 370 | |
371 | 371 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
372 | - /** |
|
373 | - * Build an input field used to filter the query |
|
374 | - * |
|
375 | - * @param string $TypeField Type of Field to filter. Example: Text, Date, List:c_country:label:rowid, List:c_stcom:label:code, Numeric or Number, Boolean |
|
376 | - * @param string $NameField Name of the field to filter |
|
377 | - * @param string $ValueField Initial value of the field to filter |
|
378 | - * @return string html string of the input field ex : "<input type=text name=... value=...>" |
|
379 | - */ |
|
380 | - function build_filterField($TypeField, $NameField, $ValueField) |
|
381 | - { |
|
372 | + /** |
|
373 | + * Build an input field used to filter the query |
|
374 | + * |
|
375 | + * @param string $TypeField Type of Field to filter. Example: Text, Date, List:c_country:label:rowid, List:c_stcom:label:code, Numeric or Number, Boolean |
|
376 | + * @param string $NameField Name of the field to filter |
|
377 | + * @param string $ValueField Initial value of the field to filter |
|
378 | + * @return string html string of the input field ex : "<input type=text name=... value=...>" |
|
379 | + */ |
|
380 | + function build_filterField($TypeField, $NameField, $ValueField) |
|
381 | + { |
|
382 | 382 | // phpcs:enable |
383 | - global $conf,$langs; |
|
384 | - |
|
385 | - $szFilterField=''; |
|
386 | - $InfoFieldList = explode(":", $TypeField); |
|
387 | - |
|
388 | - // build the input field on depend of the type of file |
|
389 | - switch ($InfoFieldList[0]) |
|
390 | - { |
|
391 | - case 'Text': |
|
392 | - case 'Date': |
|
393 | - $szFilterField='<input type="text" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
394 | - break; |
|
395 | - case 'Duree': |
|
396 | - case 'Numeric': |
|
397 | - case 'Number': |
|
398 | - // Must be a string text to allow to use comparison strings like "<= 999" |
|
399 | - $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
400 | - break; |
|
401 | - case 'Status': |
|
402 | - if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
403 | - else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
404 | - break; |
|
405 | - case 'Boolean': |
|
406 | - $szFilterField='<select name="'.$NameField.'" class="flat">'; |
|
407 | - $szFilterField.='<option '; |
|
408 | - if ($ValueField=='') $szFilterField.=' selected '; |
|
409 | - $szFilterField.=' value=""> </option>'; |
|
410 | - |
|
411 | - $szFilterField.='<option '; |
|
412 | - if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected '; |
|
413 | - $szFilterField.=' value="1">'.yn(1).'</option>'; |
|
414 | - |
|
415 | - $szFilterField.='<option '; |
|
416 | - if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected '; |
|
417 | - $szFilterField.=' value="0">'.yn(0).'</option>'; |
|
418 | - $szFilterField.="</select>"; |
|
419 | - break; |
|
420 | - case 'List': |
|
421 | - // 0 : Type du champ |
|
422 | - // 1 : Nom de la table |
|
423 | - // 2 : Nom du champ contenant le libelle |
|
424 | - // 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list. |
|
425 | - if (count($InfoFieldList)==4) |
|
426 | - $keyList=$InfoFieldList[3]; |
|
427 | - else |
|
428 | - $keyList='rowid'; |
|
429 | - $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code'); |
|
430 | - if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code'); |
|
431 | - if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code'; |
|
432 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1]; |
|
433 | - |
|
434 | - $resql = $this->db->query($sql); |
|
435 | - if ($resql) |
|
436 | - { |
|
437 | - $szFilterField='<select class="flat" name="'.$NameField.'">'; |
|
438 | - $szFilterField.='<option value="0"> </option>'; |
|
439 | - $num = $this->db->num_rows($resql); |
|
440 | - |
|
441 | - $i = 0; |
|
442 | - if ($num) |
|
443 | - { |
|
444 | - while ($i < $num) |
|
445 | - { |
|
446 | - $obj = $this->db->fetch_object($resql); |
|
447 | - if ($obj->label == '-') |
|
448 | - { |
|
449 | - // Discard entry '-' |
|
450 | - $i++; |
|
451 | - continue; |
|
452 | - } |
|
453 | - //var_dump($InfoFieldList[1]); |
|
454 | - $labeltoshow=dol_trunc($obj->label,18); |
|
455 | - if ($InfoFieldList[1] == 'c_stcomm') |
|
456 | - { |
|
457 | - $langs->load("companies"); |
|
458 | - $labeltoshow=(($langs->trans("StatusProspect".$obj->id) != "StatusProspect".$obj->id)?$langs->trans("StatusProspect".$obj->id):$obj->label); |
|
459 | - } |
|
460 | - if ($InfoFieldList[1] == 'c_country') |
|
461 | - { |
|
462 | - //var_dump($sql); |
|
463 | - $langs->load("dict"); |
|
464 | - $labeltoshow=(($langs->trans("Country".$obj->code) != "Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label); |
|
465 | - } |
|
466 | - if (!empty($ValueField) && $ValueField == $obj->rowid) |
|
467 | - { |
|
468 | - $szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
469 | - } |
|
470 | - else |
|
471 | - { |
|
472 | - $szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>'; |
|
473 | - } |
|
474 | - $i++; |
|
475 | - } |
|
476 | - } |
|
477 | - $szFilterField.="</select>"; |
|
478 | - |
|
479 | - $this->db->free($resql); |
|
480 | - } |
|
481 | - else dol_print_error($this->db); |
|
482 | - break; |
|
483 | - } |
|
484 | - |
|
485 | - return $szFilterField; |
|
486 | - } |
|
487 | - |
|
488 | - /** |
|
489 | - * Build an input field used to filter the query |
|
490 | - * |
|
491 | - * @param string $TypeField Type of Field to filter |
|
492 | - * @return string html string of the input field ex : "<input type=text name=... value=...>" |
|
493 | - */ |
|
494 | - function genDocFilter($TypeField) |
|
495 | - { |
|
383 | + global $conf,$langs; |
|
384 | + |
|
385 | + $szFilterField=''; |
|
386 | + $InfoFieldList = explode(":", $TypeField); |
|
387 | + |
|
388 | + // build the input field on depend of the type of file |
|
389 | + switch ($InfoFieldList[0]) |
|
390 | + { |
|
391 | + case 'Text': |
|
392 | + case 'Date': |
|
393 | + $szFilterField='<input type="text" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
394 | + break; |
|
395 | + case 'Duree': |
|
396 | + case 'Numeric': |
|
397 | + case 'Number': |
|
398 | + // Must be a string text to allow to use comparison strings like "<= 999" |
|
399 | + $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
400 | + break; |
|
401 | + case 'Status': |
|
402 | + if (! empty($conf->global->MAIN_ACTIVATE_HTML5)) $szFilterField='<input type="number" size="6" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
403 | + else $szFilterField='<input type="text" size="6" name="'.$NameField.'" value="'.$ValueField.'">'; |
|
404 | + break; |
|
405 | + case 'Boolean': |
|
406 | + $szFilterField='<select name="'.$NameField.'" class="flat">'; |
|
407 | + $szFilterField.='<option '; |
|
408 | + if ($ValueField=='') $szFilterField.=' selected '; |
|
409 | + $szFilterField.=' value=""> </option>'; |
|
410 | + |
|
411 | + $szFilterField.='<option '; |
|
412 | + if ($ValueField=='yes' || $ValueField == '1') $szFilterField.=' selected '; |
|
413 | + $szFilterField.=' value="1">'.yn(1).'</option>'; |
|
414 | + |
|
415 | + $szFilterField.='<option '; |
|
416 | + if ($ValueField=='no' || $ValueField=='0') $szFilterField.=' selected '; |
|
417 | + $szFilterField.=' value="0">'.yn(0).'</option>'; |
|
418 | + $szFilterField.="</select>"; |
|
419 | + break; |
|
420 | + case 'List': |
|
421 | + // 0 : Type du champ |
|
422 | + // 1 : Nom de la table |
|
423 | + // 2 : Nom du champ contenant le libelle |
|
424 | + // 3 : Name of field with key (if it is not "rowid"). Used this field as key for combo list. |
|
425 | + if (count($InfoFieldList)==4) |
|
426 | + $keyList=$InfoFieldList[3]; |
|
427 | + else |
|
428 | + $keyList='rowid'; |
|
429 | + $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code'); |
|
430 | + if ($InfoFieldList[1] == 'c_stcomm') $sql = 'SELECT id as id, '.$keyList.' as rowid, '.$InfoFieldList[2].' as label'.(empty($InfoFieldList[3])?'':', '.$InfoFieldList[3].' as code'); |
|
431 | + if ($InfoFieldList[1] == 'c_country') $sql = 'SELECT '.$keyList.' as rowid, '.$InfoFieldList[2].' as label, code as code'; |
|
432 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[1]; |
|
433 | + |
|
434 | + $resql = $this->db->query($sql); |
|
435 | + if ($resql) |
|
436 | + { |
|
437 | + $szFilterField='<select class="flat" name="'.$NameField.'">'; |
|
438 | + $szFilterField.='<option value="0"> </option>'; |
|
439 | + $num = $this->db->num_rows($resql); |
|
440 | + |
|
441 | + $i = 0; |
|
442 | + if ($num) |
|
443 | + { |
|
444 | + while ($i < $num) |
|
445 | + { |
|
446 | + $obj = $this->db->fetch_object($resql); |
|
447 | + if ($obj->label == '-') |
|
448 | + { |
|
449 | + // Discard entry '-' |
|
450 | + $i++; |
|
451 | + continue; |
|
452 | + } |
|
453 | + //var_dump($InfoFieldList[1]); |
|
454 | + $labeltoshow=dol_trunc($obj->label,18); |
|
455 | + if ($InfoFieldList[1] == 'c_stcomm') |
|
456 | + { |
|
457 | + $langs->load("companies"); |
|
458 | + $labeltoshow=(($langs->trans("StatusProspect".$obj->id) != "StatusProspect".$obj->id)?$langs->trans("StatusProspect".$obj->id):$obj->label); |
|
459 | + } |
|
460 | + if ($InfoFieldList[1] == 'c_country') |
|
461 | + { |
|
462 | + //var_dump($sql); |
|
463 | + $langs->load("dict"); |
|
464 | + $labeltoshow=(($langs->trans("Country".$obj->code) != "Country".$obj->code)?$langs->trans("Country".$obj->code):$obj->label); |
|
465 | + } |
|
466 | + if (!empty($ValueField) && $ValueField == $obj->rowid) |
|
467 | + { |
|
468 | + $szFilterField.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
469 | + } |
|
470 | + else |
|
471 | + { |
|
472 | + $szFilterField.='<option value="'.$obj->rowid.'" >'.$labeltoshow.'</option>'; |
|
473 | + } |
|
474 | + $i++; |
|
475 | + } |
|
476 | + } |
|
477 | + $szFilterField.="</select>"; |
|
478 | + |
|
479 | + $this->db->free($resql); |
|
480 | + } |
|
481 | + else dol_print_error($this->db); |
|
482 | + break; |
|
483 | + } |
|
484 | + |
|
485 | + return $szFilterField; |
|
486 | + } |
|
487 | + |
|
488 | + /** |
|
489 | + * Build an input field used to filter the query |
|
490 | + * |
|
491 | + * @param string $TypeField Type of Field to filter |
|
492 | + * @return string html string of the input field ex : "<input type=text name=... value=...>" |
|
493 | + */ |
|
494 | + function genDocFilter($TypeField) |
|
495 | + { |
|
496 | 496 | global $langs; |
497 | 497 | |
498 | - $szMsg=''; |
|
499 | - $InfoFieldList = explode(":", $TypeField); |
|
500 | - // build the input field on depend of the type of file |
|
501 | - switch ($InfoFieldList[0]) { |
|
502 | - case 'Text': |
|
503 | - $szMsg= $langs->trans('ExportStringFilter'); |
|
504 | - break; |
|
505 | - case 'Date': |
|
506 | - $szMsg = $langs->trans('ExportDateFilter'); |
|
507 | - break; |
|
508 | - case 'Duree': |
|
509 | - break; |
|
510 | - case 'Numeric': |
|
511 | - $szMsg = $langs->trans('ExportNumericFilter'); |
|
512 | - break; |
|
513 | - case 'Boolean': |
|
514 | - break; |
|
515 | - case 'List': |
|
516 | - break; |
|
517 | - } |
|
518 | - return $szMsg; |
|
519 | - } |
|
498 | + $szMsg=''; |
|
499 | + $InfoFieldList = explode(":", $TypeField); |
|
500 | + // build the input field on depend of the type of file |
|
501 | + switch ($InfoFieldList[0]) { |
|
502 | + case 'Text': |
|
503 | + $szMsg= $langs->trans('ExportStringFilter'); |
|
504 | + break; |
|
505 | + case 'Date': |
|
506 | + $szMsg = $langs->trans('ExportDateFilter'); |
|
507 | + break; |
|
508 | + case 'Duree': |
|
509 | + break; |
|
510 | + case 'Numeric': |
|
511 | + $szMsg = $langs->trans('ExportNumericFilter'); |
|
512 | + break; |
|
513 | + case 'Boolean': |
|
514 | + break; |
|
515 | + case 'List': |
|
516 | + break; |
|
517 | + } |
|
518 | + return $szMsg; |
|
519 | + } |
|
520 | 520 | |
521 | 521 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
522 | - /** |
|
523 | - * Build export file. |
|
524 | - * File is built into directory $conf->export->dir_temp.'/'.$user->id |
|
525 | - * Arrays this->array_export_xxx are already loaded for required datatoexport |
|
526 | - * |
|
527 | - * @param User $user User that export |
|
528 | - * @param string $model Export format |
|
529 | - * @param string $datatoexport Name of dataset to export |
|
530 | - * @param array $array_selected Filter on array of fields to export |
|
531 | - * @param array $array_filterValue Filter on array of fields with a filter |
|
532 | - * @param string $sqlquery If set, transmit the sql request for select (otherwise, sql request is generated from arrays) |
|
533 | - * @return int <0 if KO, >0 if OK |
|
534 | - */ |
|
535 | - function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '') |
|
536 | - { |
|
522 | + /** |
|
523 | + * Build export file. |
|
524 | + * File is built into directory $conf->export->dir_temp.'/'.$user->id |
|
525 | + * Arrays this->array_export_xxx are already loaded for required datatoexport |
|
526 | + * |
|
527 | + * @param User $user User that export |
|
528 | + * @param string $model Export format |
|
529 | + * @param string $datatoexport Name of dataset to export |
|
530 | + * @param array $array_selected Filter on array of fields to export |
|
531 | + * @param array $array_filterValue Filter on array of fields with a filter |
|
532 | + * @param string $sqlquery If set, transmit the sql request for select (otherwise, sql request is generated from arrays) |
|
533 | + * @return int <0 if KO, >0 if OK |
|
534 | + */ |
|
535 | + function build_file($user, $model, $datatoexport, $array_selected, $array_filterValue, $sqlquery = '') |
|
536 | + { |
|
537 | 537 | // phpcs:enable |
538 | - global $conf,$langs; |
|
538 | + global $conf,$langs; |
|
539 | 539 | |
540 | - $indice=0; |
|
541 | - asort($array_selected); |
|
540 | + $indice=0; |
|
541 | + asort($array_selected); |
|
542 | 542 | |
543 | - dol_syslog(get_class($this)."::".__FUNCTION__." ".$model.", ".$datatoexport.", ".implode(",", $array_selected)); |
|
543 | + dol_syslog(get_class($this)."::".__FUNCTION__." ".$model.", ".$datatoexport.", ".implode(",", $array_selected)); |
|
544 | 544 | |
545 | - // Check parameters or context properties |
|
546 | - if (empty($this->array_export_fields) || ! is_array($this->array_export_fields)) |
|
547 | - { |
|
548 | - $this->error="ErrorBadParameter"; |
|
549 | - return -1; |
|
550 | - } |
|
545 | + // Check parameters or context properties |
|
546 | + if (empty($this->array_export_fields) || ! is_array($this->array_export_fields)) |
|
547 | + { |
|
548 | + $this->error="ErrorBadParameter"; |
|
549 | + return -1; |
|
550 | + } |
|
551 | 551 | |
552 | - // Creation of class to export using model ExportXXX |
|
553 | - $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; |
|
554 | - $file = "export_".$model.".modules.php"; |
|
555 | - $classname = "Export".$model; |
|
556 | - require_once $dir.$file; |
|
557 | - $objmodel = new $classname($this->db); |
|
552 | + // Creation of class to export using model ExportXXX |
|
553 | + $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; |
|
554 | + $file = "export_".$model.".modules.php"; |
|
555 | + $classname = "Export".$model; |
|
556 | + require_once $dir.$file; |
|
557 | + $objmodel = new $classname($this->db); |
|
558 | 558 | |
559 | - if (! empty($sqlquery)) $sql = $sqlquery; |
|
559 | + if (! empty($sqlquery)) $sql = $sqlquery; |
|
560 | + else |
|
561 | + { |
|
562 | + // Define value for indice from $datatoexport |
|
563 | + $foundindice=0; |
|
564 | + foreach($this->array_export_code as $key => $dataset) |
|
565 | + { |
|
566 | + if ($datatoexport == $dataset) |
|
567 | + { |
|
568 | + $indice=$key; |
|
569 | + $foundindice++; |
|
570 | + //print "Found indice = ".$indice." for dataset=".$datatoexport."\n"; |
|
571 | + break; |
|
572 | + } |
|
573 | + } |
|
574 | + if (empty($foundindice)) |
|
575 | + { |
|
576 | + $this->error="ErrorBadParameter can't find dataset ".$datatoexport." into preload arrays this->array_export_code"; |
|
577 | + return -1; |
|
578 | + } |
|
579 | + $sql=$this->build_sql($indice, $array_selected, $array_filterValue); |
|
580 | + } |
|
581 | + |
|
582 | + // Run the sql |
|
583 | + $this->sqlusedforexport=$sql; |
|
584 | + dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
585 | + $resql = $this->db->query($sql); |
|
586 | + if ($resql) |
|
587 | + { |
|
588 | + //$this->array_export_label[$indice] |
|
589 | + if ($conf->global->EXPORT_PREFIX_SPEC) |
|
590 | + $filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport; |
|
591 | + else |
|
592 | + $filename="export_".$datatoexport; |
|
593 | + $filename.='.'.$objmodel->getDriverExtension(); |
|
594 | + $dirname=$conf->export->dir_temp.'/'.$user->id; |
|
595 | + |
|
596 | + $outputlangs = clone $langs; // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value |
|
597 | + |
|
598 | + // Open file |
|
599 | + dol_mkdir($dirname); |
|
600 | + $result=$objmodel->open_file($dirname."/".$filename, $outputlangs); |
|
601 | + |
|
602 | + if ($result >= 0) |
|
603 | + { |
|
604 | + // Genere en-tete |
|
605 | + $objmodel->write_header($outputlangs); |
|
606 | + |
|
607 | + // Genere ligne de titre |
|
608 | + $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs,$this->array_export_TypeFields[$indice]); |
|
609 | + |
|
610 | + while ($obj = $this->db->fetch_object($resql)) |
|
611 | + { |
|
612 | + // Process special operations |
|
613 | + if (! empty($this->array_export_special[$indice])) |
|
614 | + { |
|
615 | + foreach ($this->array_export_special[$indice] as $key => $value) |
|
616 | + { |
|
617 | + if (! array_key_exists($key, $array_selected)) continue; // Field not selected |
|
618 | + // Operation NULLIFNEG |
|
619 | + if ($this->array_export_special[$indice][$key]=='NULLIFNEG') |
|
620 | + { |
|
621 | + //$alias=$this->array_export_alias[$indice][$key]; |
|
622 | + $alias=str_replace(array('.', '-','(',')'),'_',$key); |
|
623 | + if ($obj->$alias < 0) $obj->$alias=''; |
|
624 | + } |
|
625 | + // Operation ZEROIFNEG |
|
626 | + elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG') |
|
627 | + { |
|
628 | + //$alias=$this->array_export_alias[$indice][$key]; |
|
629 | + $alias=str_replace(array('.', '-','(',')'),'_',$key); |
|
630 | + if ($obj->$alias < 0) $obj->$alias='0'; |
|
631 | + } |
|
632 | + // Operation INVOICEREMAINTOPAY |
|
633 | + elseif ($this->array_export_special[$indice][$key]=='getRemainToPay') |
|
634 | + { |
|
635 | + //$alias=$this->array_export_alias[$indice][$key]; |
|
636 | + $alias=str_replace(array('.', '-','(',')'),'_',$key); |
|
637 | + $remaintopay=''; |
|
638 | + if ($obj->f_rowid > 0) |
|
639 | + { |
|
640 | + global $tmpobjforcomputecall; |
|
641 | + if (! is_object($tmpobjforcomputecall)) |
|
642 | + { |
|
643 | + include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
644 | + $tmpobjforcomputecall=new Facture($this->db); |
|
645 | + } |
|
646 | + $tmpobjforcomputecall->id = $obj->f_rowid; |
|
647 | + $tmpobjforcomputecall->total_ttc = $obj->f_total_ttc; |
|
648 | + $remaintopay=$tmpobjforcomputecall->getRemainToPay(); |
|
649 | + } |
|
650 | + $obj->$alias=$remaintopay; |
|
651 | + } |
|
652 | + else |
|
653 | + { |
|
654 | + // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field |
|
655 | + $computestring=$this->array_export_special[$indice][$key]; |
|
656 | + $tmp=dol_eval($computestring, 1, 0); |
|
657 | + $obj->$alias=$tmp; |
|
658 | + |
|
659 | + $this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field."; |
|
660 | + return -1; |
|
661 | + } |
|
662 | + } |
|
663 | + } |
|
664 | + // end of special operation processing |
|
665 | + $objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]); |
|
666 | + } |
|
667 | + |
|
668 | + // Genere en-tete |
|
669 | + $objmodel->write_footer($outputlangs); |
|
670 | + |
|
671 | + // Close file |
|
672 | + $objmodel->close_file(); |
|
673 | + |
|
674 | + return 1; |
|
675 | + } |
|
676 | + else |
|
677 | + { |
|
678 | + $this->error=$objmodel->error; |
|
679 | + dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR); |
|
680 | + return -1; |
|
681 | + } |
|
682 | + } |
|
683 | + else |
|
684 | + { |
|
685 | + $this->error=$this->db->error()." - sql=".$sql; |
|
686 | + return -1; |
|
687 | + } |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Save an export model in database |
|
692 | + * |
|
693 | + * @param User $user Object user that save |
|
694 | + * @return int <0 if KO, >0 if OK |
|
695 | + */ |
|
696 | + function create($user) |
|
697 | + { |
|
698 | + global $conf; |
|
699 | + |
|
700 | + dol_syslog("Export.class.php::create"); |
|
701 | + |
|
702 | + $this->db->begin(); |
|
703 | + |
|
704 | + $filter=''; |
|
705 | + |
|
706 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model ('; |
|
707 | + $sql.= 'label,'; |
|
708 | + $sql.= 'type,'; |
|
709 | + $sql.= 'field,'; |
|
710 | + $sql.= 'fk_user,'; |
|
711 | + $sql.= 'filter'; |
|
712 | + $sql.= ') VALUES ('; |
|
713 | + $sql.= "'".$this->db->escape($this->model_name)."',"; |
|
714 | + $sql.= "'".$this->db->escape($this->datatoexport)."',"; |
|
715 | + $sql.= "'".$this->db->escape($this->hexa)."',"; |
|
716 | + $sql.= "'".$user->id."',"; |
|
717 | + $sql.= "'".$this->db->escape($this->hexafiltervalue)."'"; |
|
718 | + $sql.= ")"; |
|
719 | + |
|
720 | + dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
721 | + $resql=$this->db->query($sql); |
|
722 | + if ($resql) |
|
723 | + { |
|
724 | + $this->db->commit(); |
|
725 | + return 1; |
|
726 | + } |
|
560 | 727 | else |
561 | - { |
|
562 | - // Define value for indice from $datatoexport |
|
563 | - $foundindice=0; |
|
564 | - foreach($this->array_export_code as $key => $dataset) |
|
565 | - { |
|
566 | - if ($datatoexport == $dataset) |
|
567 | - { |
|
568 | - $indice=$key; |
|
569 | - $foundindice++; |
|
570 | - //print "Found indice = ".$indice." for dataset=".$datatoexport."\n"; |
|
571 | - break; |
|
572 | - } |
|
573 | - } |
|
574 | - if (empty($foundindice)) |
|
575 | - { |
|
576 | - $this->error="ErrorBadParameter can't find dataset ".$datatoexport." into preload arrays this->array_export_code"; |
|
577 | - return -1; |
|
578 | - } |
|
579 | - $sql=$this->build_sql($indice, $array_selected, $array_filterValue); |
|
580 | - } |
|
581 | - |
|
582 | - // Run the sql |
|
583 | - $this->sqlusedforexport=$sql; |
|
584 | - dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
585 | - $resql = $this->db->query($sql); |
|
586 | - if ($resql) |
|
587 | - { |
|
588 | - //$this->array_export_label[$indice] |
|
589 | - if ($conf->global->EXPORT_PREFIX_SPEC) |
|
590 | - $filename=$conf->global->EXPORT_PREFIX_SPEC."_".$datatoexport; |
|
591 | - else |
|
592 | - $filename="export_".$datatoexport; |
|
593 | - $filename.='.'.$objmodel->getDriverExtension(); |
|
594 | - $dirname=$conf->export->dir_temp.'/'.$user->id; |
|
595 | - |
|
596 | - $outputlangs = clone $langs; // We clone to have an object we can modify (for example to change output charset by csv handler) without changing original value |
|
597 | - |
|
598 | - // Open file |
|
599 | - dol_mkdir($dirname); |
|
600 | - $result=$objmodel->open_file($dirname."/".$filename, $outputlangs); |
|
601 | - |
|
602 | - if ($result >= 0) |
|
603 | - { |
|
604 | - // Genere en-tete |
|
605 | - $objmodel->write_header($outputlangs); |
|
606 | - |
|
607 | - // Genere ligne de titre |
|
608 | - $objmodel->write_title($this->array_export_fields[$indice],$array_selected,$outputlangs,$this->array_export_TypeFields[$indice]); |
|
609 | - |
|
610 | - while ($obj = $this->db->fetch_object($resql)) |
|
611 | - { |
|
612 | - // Process special operations |
|
613 | - if (! empty($this->array_export_special[$indice])) |
|
614 | - { |
|
615 | - foreach ($this->array_export_special[$indice] as $key => $value) |
|
616 | - { |
|
617 | - if (! array_key_exists($key, $array_selected)) continue; // Field not selected |
|
618 | - // Operation NULLIFNEG |
|
619 | - if ($this->array_export_special[$indice][$key]=='NULLIFNEG') |
|
620 | - { |
|
621 | - //$alias=$this->array_export_alias[$indice][$key]; |
|
622 | - $alias=str_replace(array('.', '-','(',')'),'_',$key); |
|
623 | - if ($obj->$alias < 0) $obj->$alias=''; |
|
624 | - } |
|
625 | - // Operation ZEROIFNEG |
|
626 | - elseif ($this->array_export_special[$indice][$key]=='ZEROIFNEG') |
|
627 | - { |
|
628 | - //$alias=$this->array_export_alias[$indice][$key]; |
|
629 | - $alias=str_replace(array('.', '-','(',')'),'_',$key); |
|
630 | - if ($obj->$alias < 0) $obj->$alias='0'; |
|
631 | - } |
|
632 | - // Operation INVOICEREMAINTOPAY |
|
633 | - elseif ($this->array_export_special[$indice][$key]=='getRemainToPay') |
|
634 | - { |
|
635 | - //$alias=$this->array_export_alias[$indice][$key]; |
|
636 | - $alias=str_replace(array('.', '-','(',')'),'_',$key); |
|
637 | - $remaintopay=''; |
|
638 | - if ($obj->f_rowid > 0) |
|
639 | - { |
|
640 | - global $tmpobjforcomputecall; |
|
641 | - if (! is_object($tmpobjforcomputecall)) |
|
642 | - { |
|
643 | - include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
644 | - $tmpobjforcomputecall=new Facture($this->db); |
|
645 | - } |
|
646 | - $tmpobjforcomputecall->id = $obj->f_rowid; |
|
647 | - $tmpobjforcomputecall->total_ttc = $obj->f_total_ttc; |
|
648 | - $remaintopay=$tmpobjforcomputecall->getRemainToPay(); |
|
649 | - } |
|
650 | - $obj->$alias=$remaintopay; |
|
651 | - } |
|
652 | - else |
|
653 | - { |
|
654 | - // TODO FIXME Export of compute field does not work. $obj containt $obj->alias_field and formulat will contains $obj->field |
|
655 | - $computestring=$this->array_export_special[$indice][$key]; |
|
656 | - $tmp=dol_eval($computestring, 1, 0); |
|
657 | - $obj->$alias=$tmp; |
|
658 | - |
|
659 | - $this->error="ERROPNOTSUPPORTED. Operation ".$this->array_export_special[$indice][$key]." not supported. Export of 'computed' extrafields is not yet supported, please remove field."; |
|
660 | - return -1; |
|
661 | - } |
|
662 | - } |
|
663 | - } |
|
664 | - // end of special operation processing |
|
665 | - $objmodel->write_record($array_selected,$obj,$outputlangs,$this->array_export_TypeFields[$indice]); |
|
666 | - } |
|
667 | - |
|
668 | - // Genere en-tete |
|
669 | - $objmodel->write_footer($outputlangs); |
|
670 | - |
|
671 | - // Close file |
|
672 | - $objmodel->close_file(); |
|
673 | - |
|
674 | - return 1; |
|
675 | - } |
|
676 | - else |
|
677 | - { |
|
678 | - $this->error=$objmodel->error; |
|
679 | - dol_syslog("Export::build_file Error: ".$this->error, LOG_ERR); |
|
680 | - return -1; |
|
681 | - } |
|
682 | - } |
|
683 | - else |
|
684 | - { |
|
685 | - $this->error=$this->db->error()." - sql=".$sql; |
|
686 | - return -1; |
|
687 | - } |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Save an export model in database |
|
692 | - * |
|
693 | - * @param User $user Object user that save |
|
694 | - * @return int <0 if KO, >0 if OK |
|
695 | - */ |
|
696 | - function create($user) |
|
697 | - { |
|
698 | - global $conf; |
|
699 | - |
|
700 | - dol_syslog("Export.class.php::create"); |
|
701 | - |
|
702 | - $this->db->begin(); |
|
703 | - |
|
704 | - $filter=''; |
|
705 | - |
|
706 | - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'export_model ('; |
|
707 | - $sql.= 'label,'; |
|
708 | - $sql.= 'type,'; |
|
709 | - $sql.= 'field,'; |
|
710 | - $sql.= 'fk_user,'; |
|
711 | - $sql.= 'filter'; |
|
712 | - $sql.= ') VALUES ('; |
|
713 | - $sql.= "'".$this->db->escape($this->model_name)."',"; |
|
714 | - $sql.= "'".$this->db->escape($this->datatoexport)."',"; |
|
715 | - $sql.= "'".$this->db->escape($this->hexa)."',"; |
|
716 | - $sql.= "'".$user->id."',"; |
|
717 | - $sql.= "'".$this->db->escape($this->hexafiltervalue)."'"; |
|
718 | - $sql.= ")"; |
|
719 | - |
|
720 | - dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
721 | - $resql=$this->db->query($sql); |
|
722 | - if ($resql) |
|
723 | - { |
|
724 | - $this->db->commit(); |
|
725 | - return 1; |
|
726 | - } |
|
727 | - else |
|
728 | - { |
|
729 | - $this->error=$this->db->lasterror(); |
|
730 | - $this->errno=$this->db->lasterrno(); |
|
731 | - $this->db->rollback(); |
|
732 | - return -1; |
|
733 | - } |
|
734 | - } |
|
735 | - |
|
736 | - /** |
|
737 | - * Load an export profil from database |
|
738 | - * |
|
739 | - * @param int $id Id of profil to load |
|
740 | - * @return int <0 if KO, >0 if OK |
|
741 | - */ |
|
742 | - function fetch($id) |
|
743 | - { |
|
744 | - $sql = 'SELECT em.rowid, em.label, em.type, em.field, em.filter'; |
|
745 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em'; |
|
746 | - $sql.= ' WHERE em.rowid = '.$id; |
|
747 | - |
|
748 | - dol_syslog("Export::fetch", LOG_DEBUG); |
|
749 | - $result = $this->db->query($sql); |
|
750 | - if ($result) |
|
751 | - { |
|
752 | - $obj = $this->db->fetch_object($result); |
|
753 | - if ($obj) |
|
754 | - { |
|
755 | - $this->id = $obj->rowid; |
|
756 | - $this->model_name = $obj->label; |
|
757 | - $this->datatoexport = $obj->type; |
|
758 | - |
|
759 | - $this->hexa = $obj->field; |
|
760 | - $this->hexafiltervalue = $obj->filter; |
|
761 | - |
|
762 | - return 1; |
|
763 | - } |
|
764 | - else |
|
765 | - { |
|
766 | - $this->error="ModelNotFound"; |
|
767 | - return -2; |
|
768 | - } |
|
769 | - } |
|
770 | - else |
|
771 | - { |
|
772 | - dol_print_error($this->db); |
|
773 | - return -3; |
|
774 | - } |
|
775 | - } |
|
776 | - |
|
777 | - |
|
778 | - /** |
|
779 | - * Delete object in database |
|
780 | - * |
|
781 | - * @param User $user User that delete |
|
782 | - * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
783 | - * @return int <0 if KO, >0 if OK |
|
784 | - */ |
|
785 | - function delete($user, $notrigger=0) |
|
786 | - { |
|
787 | - global $conf, $langs; |
|
788 | - $error=0; |
|
789 | - |
|
790 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."export_model"; |
|
791 | - $sql.= " WHERE rowid=".$this->id; |
|
792 | - |
|
793 | - $this->db->begin(); |
|
794 | - |
|
795 | - dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
796 | - $resql = $this->db->query($sql); |
|
797 | - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
798 | - |
|
799 | - if (! $error) |
|
800 | - { |
|
801 | - if (! $notrigger) |
|
802 | - { |
|
803 | - // Uncomment this and change MYOBJECT to your own tag if you |
|
804 | - // want this action call a trigger. |
|
805 | - |
|
806 | - //// Call triggers |
|
807 | - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
808 | - //$interface=new Interfaces($this->db); |
|
809 | - //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
810 | - //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
811 | - //// End call triggers |
|
812 | - } |
|
813 | - } |
|
814 | - |
|
815 | - // Commit or rollback |
|
816 | - if ($error) |
|
817 | - { |
|
818 | - foreach($this->errors as $errmsg) |
|
819 | - { |
|
820 | - dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
821 | - $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
822 | - } |
|
823 | - $this->db->rollback(); |
|
824 | - return -1*$error; |
|
825 | - } |
|
826 | - else |
|
827 | - { |
|
828 | - $this->db->commit(); |
|
829 | - return 1; |
|
830 | - } |
|
831 | - } |
|
728 | + { |
|
729 | + $this->error=$this->db->lasterror(); |
|
730 | + $this->errno=$this->db->lasterrno(); |
|
731 | + $this->db->rollback(); |
|
732 | + return -1; |
|
733 | + } |
|
734 | + } |
|
735 | + |
|
736 | + /** |
|
737 | + * Load an export profil from database |
|
738 | + * |
|
739 | + * @param int $id Id of profil to load |
|
740 | + * @return int <0 if KO, >0 if OK |
|
741 | + */ |
|
742 | + function fetch($id) |
|
743 | + { |
|
744 | + $sql = 'SELECT em.rowid, em.label, em.type, em.field, em.filter'; |
|
745 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'export_model as em'; |
|
746 | + $sql.= ' WHERE em.rowid = '.$id; |
|
747 | + |
|
748 | + dol_syslog("Export::fetch", LOG_DEBUG); |
|
749 | + $result = $this->db->query($sql); |
|
750 | + if ($result) |
|
751 | + { |
|
752 | + $obj = $this->db->fetch_object($result); |
|
753 | + if ($obj) |
|
754 | + { |
|
755 | + $this->id = $obj->rowid; |
|
756 | + $this->model_name = $obj->label; |
|
757 | + $this->datatoexport = $obj->type; |
|
758 | + |
|
759 | + $this->hexa = $obj->field; |
|
760 | + $this->hexafiltervalue = $obj->filter; |
|
761 | + |
|
762 | + return 1; |
|
763 | + } |
|
764 | + else |
|
765 | + { |
|
766 | + $this->error="ModelNotFound"; |
|
767 | + return -2; |
|
768 | + } |
|
769 | + } |
|
770 | + else |
|
771 | + { |
|
772 | + dol_print_error($this->db); |
|
773 | + return -3; |
|
774 | + } |
|
775 | + } |
|
776 | + |
|
777 | + |
|
778 | + /** |
|
779 | + * Delete object in database |
|
780 | + * |
|
781 | + * @param User $user User that delete |
|
782 | + * @param int $notrigger 0=launch triggers after, 1=disable triggers |
|
783 | + * @return int <0 if KO, >0 if OK |
|
784 | + */ |
|
785 | + function delete($user, $notrigger=0) |
|
786 | + { |
|
787 | + global $conf, $langs; |
|
788 | + $error=0; |
|
789 | + |
|
790 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."export_model"; |
|
791 | + $sql.= " WHERE rowid=".$this->id; |
|
792 | + |
|
793 | + $this->db->begin(); |
|
794 | + |
|
795 | + dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
796 | + $resql = $this->db->query($sql); |
|
797 | + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } |
|
798 | + |
|
799 | + if (! $error) |
|
800 | + { |
|
801 | + if (! $notrigger) |
|
802 | + { |
|
803 | + // Uncomment this and change MYOBJECT to your own tag if you |
|
804 | + // want this action call a trigger. |
|
805 | + |
|
806 | + //// Call triggers |
|
807 | + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
808 | + //$interface=new Interfaces($this->db); |
|
809 | + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); |
|
810 | + //if ($result < 0) { $error++; $this->errors=$interface->errors; } |
|
811 | + //// End call triggers |
|
812 | + } |
|
813 | + } |
|
814 | + |
|
815 | + // Commit or rollback |
|
816 | + if ($error) |
|
817 | + { |
|
818 | + foreach($this->errors as $errmsg) |
|
819 | + { |
|
820 | + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); |
|
821 | + $this->error.=($this->error?', '.$errmsg:$errmsg); |
|
822 | + } |
|
823 | + $this->db->rollback(); |
|
824 | + return -1*$error; |
|
825 | + } |
|
826 | + else |
|
827 | + { |
|
828 | + $this->db->commit(); |
|
829 | + return 1; |
|
830 | + } |
|
831 | + } |
|
832 | 832 | |
833 | 833 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
834 | - /** |
|
835 | - * Output list all export models |
|
836 | - * TODO Move this into a class htmlxxx.class.php |
|
837 | - * |
|
838 | - * @return void |
|
839 | - */ |
|
840 | - function list_export_model() |
|
841 | - { |
|
834 | + /** |
|
835 | + * Output list all export models |
|
836 | + * TODO Move this into a class htmlxxx.class.php |
|
837 | + * |
|
838 | + * @return void |
|
839 | + */ |
|
840 | + function list_export_model() |
|
841 | + { |
|
842 | 842 | // phpcs:enable |
843 | - global $conf, $langs; |
|
844 | - |
|
845 | - $sql = "SELECT em.rowid, em.field, em.label, em.type, em.filter"; |
|
846 | - $sql.= " FROM ".MAIN_DB_PREFIX."export_model as em"; |
|
847 | - $sql.= " ORDER BY rowid"; |
|
848 | - |
|
849 | - $result = $this->db->query($sql); |
|
850 | - if ($result) |
|
851 | - { |
|
852 | - $num = $this->db->num_rows($result); |
|
853 | - $i = 0; |
|
854 | - while ($i < $num) |
|
855 | - { |
|
856 | - $obj = $this->db->fetch_object($result); |
|
857 | - $keyModel = array_search($obj->type, $this->array_export_code); |
|
858 | - print "<tr>"; |
|
859 | - print '<td><a href=export.php?step=2&action=select_model&exportmodelid='.$obj->rowid.'&datatoexport='.$obj->type.'>'.$obj->label.'</a></td>'; |
|
860 | - print '<td>'; |
|
861 | - print img_object($this->array_export_module[$keyModel]->getName(),$this->array_export_icon[$keyModel]).' '; |
|
862 | - print $this->array_export_module[$keyModel]->getName().' - '; |
|
863 | - // recuperation du nom de l'export |
|
864 | - |
|
865 | - $string=$langs->trans($this->array_export_label[$keyModel]); |
|
866 | - print ($string!=$this->array_export_label[$keyModel]?$string:$this->array_export_label[$keyModel]); |
|
867 | - print '</td>'; |
|
868 | - //print '<td>'.$obj->type.$keyModel.'</td>'; |
|
869 | - print '<td>'.str_replace(',',' , ',$obj->field).'</td>'; |
|
870 | - if (! empty($obj->filter)) { |
|
871 | - $filter = json_decode($obj->filter, true); |
|
872 | - print '<td>'.str_replace(',',' , ',$filter['field']).'</td>'; |
|
873 | - print '<td>'.str_replace(',',' , ',$filter['value']).'</td>'; |
|
874 | - } |
|
875 | - // suppression de l'export |
|
876 | - print '<td align="right">'; |
|
877 | - print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteprof&id='.$obj->rowid.'">'; |
|
878 | - print img_delete(); |
|
879 | - print '</a>'; |
|
880 | - print "</tr>"; |
|
881 | - |
|
882 | - $i++; |
|
883 | - } |
|
884 | - } |
|
885 | - else { |
|
886 | - dol_print_error($this->db); |
|
887 | - } |
|
888 | - } |
|
843 | + global $conf, $langs; |
|
844 | + |
|
845 | + $sql = "SELECT em.rowid, em.field, em.label, em.type, em.filter"; |
|
846 | + $sql.= " FROM ".MAIN_DB_PREFIX."export_model as em"; |
|
847 | + $sql.= " ORDER BY rowid"; |
|
848 | + |
|
849 | + $result = $this->db->query($sql); |
|
850 | + if ($result) |
|
851 | + { |
|
852 | + $num = $this->db->num_rows($result); |
|
853 | + $i = 0; |
|
854 | + while ($i < $num) |
|
855 | + { |
|
856 | + $obj = $this->db->fetch_object($result); |
|
857 | + $keyModel = array_search($obj->type, $this->array_export_code); |
|
858 | + print "<tr>"; |
|
859 | + print '<td><a href=export.php?step=2&action=select_model&exportmodelid='.$obj->rowid.'&datatoexport='.$obj->type.'>'.$obj->label.'</a></td>'; |
|
860 | + print '<td>'; |
|
861 | + print img_object($this->array_export_module[$keyModel]->getName(),$this->array_export_icon[$keyModel]).' '; |
|
862 | + print $this->array_export_module[$keyModel]->getName().' - '; |
|
863 | + // recuperation du nom de l'export |
|
864 | + |
|
865 | + $string=$langs->trans($this->array_export_label[$keyModel]); |
|
866 | + print ($string!=$this->array_export_label[$keyModel]?$string:$this->array_export_label[$keyModel]); |
|
867 | + print '</td>'; |
|
868 | + //print '<td>'.$obj->type.$keyModel.'</td>'; |
|
869 | + print '<td>'.str_replace(',',' , ',$obj->field).'</td>'; |
|
870 | + if (! empty($obj->filter)) { |
|
871 | + $filter = json_decode($obj->filter, true); |
|
872 | + print '<td>'.str_replace(',',' , ',$filter['field']).'</td>'; |
|
873 | + print '<td>'.str_replace(',',' , ',$filter['value']).'</td>'; |
|
874 | + } |
|
875 | + // suppression de l'export |
|
876 | + print '<td align="right">'; |
|
877 | + print '<a href="'.$_SERVER["PHP_SELF"].'?action=deleteprof&id='.$obj->rowid.'">'; |
|
878 | + print img_delete(); |
|
879 | + print '</a>'; |
|
880 | + print "</tr>"; |
|
881 | + |
|
882 | + $i++; |
|
883 | + } |
|
884 | + } |
|
885 | + else { |
|
886 | + dol_print_error($this->db); |
|
887 | + } |
|
888 | + } |
|
889 | 889 | } |
@@ -40,85 +40,85 @@ discard block |
||
40 | 40 | // accessforbidden(); |
41 | 41 | |
42 | 42 | $entitytoicon = array( |
43 | - 'invoice' => 'bill', |
|
43 | + 'invoice' => 'bill', |
|
44 | 44 | 'invoice_line' => 'bill', |
45 | - 'order' => 'order', |
|
45 | + 'order' => 'order', |
|
46 | 46 | 'order_line' => 'order', |
47 | - 'propal' => 'propal', |
|
47 | + 'propal' => 'propal', |
|
48 | 48 | 'propal_line' => 'propal', |
49 | - 'intervention' => 'intervention', |
|
49 | + 'intervention' => 'intervention', |
|
50 | 50 | 'inter_line' => 'intervention', |
51 | - 'member' => 'user', |
|
51 | + 'member' => 'user', |
|
52 | 52 | 'member_type' => 'group', |
53 | 53 | 'subscription' => 'payment', |
54 | 54 | 'payment' => 'payment', |
55 | - 'tax' => 'generic', |
|
55 | + 'tax' => 'generic', |
|
56 | 56 | 'tax_type' => 'generic', |
57 | 57 | 'stock' => 'generic', |
58 | 58 | 'other' => 'generic', |
59 | - 'account' => 'account', |
|
60 | - 'product' => 'product', |
|
59 | + 'account' => 'account', |
|
60 | + 'product' => 'product', |
|
61 | 61 | 'virtualproduct'=>'product', |
62 | - 'subproduct' => 'product', |
|
63 | - 'product_supplier_ref' => 'product', |
|
64 | - 'warehouse' => 'stock', |
|
65 | - 'batch' => 'stock', |
|
66 | - 'stockbatch' => 'stock', |
|
67 | - 'category' => 'category', |
|
68 | - 'shipment' => 'sending', |
|
62 | + 'subproduct' => 'product', |
|
63 | + 'product_supplier_ref' => 'product', |
|
64 | + 'warehouse' => 'stock', |
|
65 | + 'batch' => 'stock', |
|
66 | + 'stockbatch' => 'stock', |
|
67 | + 'category' => 'category', |
|
68 | + 'shipment' => 'sending', |
|
69 | 69 | 'shipment_line'=> 'sending', |
70 | 70 | 'reception'=> 'sending', |
71 | 71 | 'reception_line'=> 'sending', |
72 | - 'expensereport'=> 'trip', |
|
72 | + 'expensereport'=> 'trip', |
|
73 | 73 | 'expensereport_line'=> 'trip', |
74 | - 'holiday' => 'holiday', |
|
74 | + 'holiday' => 'holiday', |
|
75 | 75 | 'contract_line' => 'contract', |
76 | 76 | 'translation' => 'generic' |
77 | 77 | ); |
78 | 78 | |
79 | 79 | // Translation code |
80 | 80 | $entitytolang = array( |
81 | - 'user' => 'User', |
|
82 | - 'company' => 'Company', |
|
81 | + 'user' => 'User', |
|
82 | + 'company' => 'Company', |
|
83 | 83 | 'contact' => 'Contact', |
84 | - 'invoice' => 'Bill', |
|
84 | + 'invoice' => 'Bill', |
|
85 | 85 | 'invoice_line' => 'InvoiceLine', |
86 | - 'order' => 'Order', |
|
86 | + 'order' => 'Order', |
|
87 | 87 | 'order_line' => 'OrderLine', |
88 | 88 | 'propal' => 'Proposal', |
89 | 89 | 'propal_line' => 'ProposalLine', |
90 | - 'intervention' => 'Intervention', |
|
90 | + 'intervention' => 'Intervention', |
|
91 | 91 | 'inter_line' => 'InterLine', |
92 | - 'member' => 'Member', |
|
92 | + 'member' => 'Member', |
|
93 | 93 | 'member_type' => 'MemberType', |
94 | 94 | 'subscription' => 'Subscription', |
95 | - 'tax' => 'SocialContribution', |
|
95 | + 'tax' => 'SocialContribution', |
|
96 | 96 | 'tax_type' => 'DictionarySocialContributions', |
97 | - 'account' => 'BankTransactions', |
|
98 | - 'payment' => 'Payment', |
|
99 | - 'product' => 'Product', |
|
100 | - 'virtualproduct' => 'AssociatedProducts', |
|
101 | - 'subproduct' => 'SubProduct', |
|
102 | - 'product_supplier_ref' => 'SupplierPrices', |
|
103 | - 'service' => 'Service', |
|
97 | + 'account' => 'BankTransactions', |
|
98 | + 'payment' => 'Payment', |
|
99 | + 'product' => 'Product', |
|
100 | + 'virtualproduct' => 'AssociatedProducts', |
|
101 | + 'subproduct' => 'SubProduct', |
|
102 | + 'product_supplier_ref' => 'SupplierPrices', |
|
103 | + 'service' => 'Service', |
|
104 | 104 | 'stock' => 'Stock', |
105 | - 'movement' => 'StockMovement', |
|
106 | - 'batch' => 'Batch', |
|
107 | - 'stockbatch' => 'StockDetailPerBatch', |
|
108 | - 'warehouse' => 'Warehouse', |
|
109 | - 'category' => 'Category', |
|
110 | - 'other' => 'Other', |
|
105 | + 'movement' => 'StockMovement', |
|
106 | + 'batch' => 'Batch', |
|
107 | + 'stockbatch' => 'StockDetailPerBatch', |
|
108 | + 'warehouse' => 'Warehouse', |
|
109 | + 'category' => 'Category', |
|
110 | + 'other' => 'Other', |
|
111 | 111 | 'trip' => 'TripsAndExpenses', |
112 | 112 | 'shipment' => 'Shipments', |
113 | 113 | 'shipment_line'=> 'ShipmentLine', |
114 | 114 | 'project' => 'Projects', |
115 | 115 | 'projecttask' => 'Tasks', |
116 | 116 | 'task_time' => 'TaskTimeSpent', |
117 | - 'action' => 'Event', |
|
118 | - 'expensereport'=> 'ExpenseReport', |
|
119 | - 'expensereport_line'=> 'ExpenseReportLine', |
|
120 | - 'holiday' => 'TitreRequestCP', |
|
121 | - 'contract' => 'Contract', |
|
117 | + 'action' => 'Event', |
|
118 | + 'expensereport'=> 'ExpenseReport', |
|
119 | + 'expensereport_line'=> 'ExpenseReportLine', |
|
120 | + 'holiday' => 'TitreRequestCP', |
|
121 | + 'contract' => 'Contract', |
|
122 | 122 | 'contract_line'=> 'ContractLine', |
123 | 123 | 'translation' => 'Translation' |
124 | 124 | ); |
@@ -155,19 +155,19 @@ discard block |
||
155 | 155 | |
156 | 156 | if ($action=='selectfield') // Selection of field at step 2 |
157 | 157 | { |
158 | - $fieldsarray=$objexport->array_export_fields[0]; |
|
159 | - $fieldsentitiesarray=$objexport->array_export_entities[0]; |
|
158 | + $fieldsarray=$objexport->array_export_fields[0]; |
|
159 | + $fieldsentitiesarray=$objexport->array_export_entities[0]; |
|
160 | 160 | $fieldsdependenciesarray=$objexport->array_export_dependencies[0]; |
161 | 161 | |
162 | 162 | if ($field=='all') |
163 | 163 | { |
164 | - foreach($fieldsarray as $key=>$val) |
|
165 | - { |
|
166 | - if (! empty($array_selected[$key])) continue; // If already selected, check next |
|
167 | - $array_selected[$key]=count($array_selected)+1; |
|
168 | - //print_r($array_selected); |
|
169 | - $_SESSION["export_selected_fields"]=$array_selected; |
|
170 | - } |
|
164 | + foreach($fieldsarray as $key=>$val) |
|
165 | + { |
|
166 | + if (! empty($array_selected[$key])) continue; // If already selected, check next |
|
167 | + $array_selected[$key]=count($array_selected)+1; |
|
168 | + //print_r($array_selected); |
|
169 | + $_SESSION["export_selected_fields"]=$array_selected; |
|
170 | + } |
|
171 | 171 | } |
172 | 172 | else |
173 | 173 | { |
@@ -205,33 +205,33 @@ discard block |
||
205 | 205 | } |
206 | 206 | } |
207 | 207 | } |
208 | - //print_r($array_selected); |
|
209 | - $_SESSION["export_selected_fields"]=$array_selected; |
|
208 | + //print_r($array_selected); |
|
209 | + $_SESSION["export_selected_fields"]=$array_selected; |
|
210 | 210 | |
211 | - setEventMessages($warnings, null, 'warnings'); |
|
211 | + setEventMessages($warnings, null, 'warnings'); |
|
212 | 212 | } |
213 | 213 | } |
214 | 214 | if ($action=='unselectfield') |
215 | 215 | { |
216 | 216 | if ($_GET["field"]=='all') |
217 | 217 | { |
218 | - $array_selected=array(); |
|
219 | - $_SESSION["export_selected_fields"]=$array_selected; |
|
218 | + $array_selected=array(); |
|
219 | + $_SESSION["export_selected_fields"]=$array_selected; |
|
220 | 220 | } |
221 | 221 | else |
222 | 222 | { |
223 | - unset($array_selected[$_GET["field"]]); |
|
224 | - // Renumber fields of array_selected (from 1 to nb_elements) |
|
225 | - asort($array_selected); |
|
226 | - $i=0; |
|
227 | - $array_selected_save=$array_selected; |
|
228 | - foreach($array_selected as $code=>$value) |
|
229 | - { |
|
230 | - $i++; |
|
231 | - $array_selected[$code]=$i; |
|
232 | - //print "x $code x $i y<br>"; |
|
233 | - } |
|
234 | - $_SESSION["export_selected_fields"]=$array_selected; |
|
223 | + unset($array_selected[$_GET["field"]]); |
|
224 | + // Renumber fields of array_selected (from 1 to nb_elements) |
|
225 | + asort($array_selected); |
|
226 | + $i=0; |
|
227 | + $array_selected_save=$array_selected; |
|
228 | + foreach($array_selected as $code=>$value) |
|
229 | + { |
|
230 | + $i++; |
|
231 | + $array_selected[$code]=$i; |
|
232 | + //print "x $code x $i y<br>"; |
|
233 | + } |
|
234 | + $_SESSION["export_selected_fields"]=$array_selected; |
|
235 | 235 | } |
236 | 236 | } |
237 | 237 | |
@@ -277,88 +277,88 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | // Build export file |
280 | - $result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue); |
|
281 | - if ($result < 0) |
|
282 | - { |
|
283 | - setEventMessages($objexport->error, $objexport->errors, 'errors'); |
|
284 | - $sqlusedforexport=$objexport->sqlusedforexport; |
|
285 | - } |
|
286 | - else |
|
287 | - { |
|
288 | - setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs'); |
|
289 | - $sqlusedforexport=$objexport->sqlusedforexport; |
|
280 | + $result=$objexport->build_file($user, GETPOST('model','alpha'), $datatoexport, $array_selected, $array_filtervalue); |
|
281 | + if ($result < 0) |
|
282 | + { |
|
283 | + setEventMessages($objexport->error, $objexport->errors, 'errors'); |
|
284 | + $sqlusedforexport=$objexport->sqlusedforexport; |
|
285 | + } |
|
286 | + else |
|
287 | + { |
|
288 | + setEventMessages($langs->trans("FileSuccessfullyBuilt"), null, 'mesgs'); |
|
289 | + $sqlusedforexport=$objexport->sqlusedforexport; |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | 293 | // Delete file |
294 | 294 | if ($step == 5 && $action == 'confirm_deletefile' && $confirm == 'yes') |
295 | 295 | { |
296 | - $file = $upload_dir . "/" . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). |
|
296 | + $file = $upload_dir . "/" . GETPOST('file'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP). |
|
297 | 297 | |
298 | - $ret=dol_delete_file($file); |
|
299 | - if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); |
|
300 | - else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); |
|
301 | - header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport); |
|
302 | - exit; |
|
298 | + $ret=dol_delete_file($file); |
|
299 | + if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); |
|
300 | + else setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors'); |
|
301 | + header('Location: '.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport); |
|
302 | + exit; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | if ($action == 'deleteprof') |
306 | 306 | { |
307 | - if ($_GET["id"]) |
|
308 | - { |
|
309 | - $objexport->fetch($_GET["id"]); |
|
310 | - $result=$objexport->delete($user); |
|
311 | - } |
|
307 | + if ($_GET["id"]) |
|
308 | + { |
|
309 | + $objexport->fetch($_GET["id"]); |
|
310 | + $result=$objexport->delete($user); |
|
311 | + } |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | // TODO The export for filter is not yet implemented (old code created conflicts with step 2). We must use same way of working and same combo list of predefined export than step 2. |
315 | 315 | if ($action == 'add_export_model') |
316 | 316 | { |
317 | - if ($export_name) |
|
318 | - { |
|
319 | - asort($array_selected); |
|
320 | - |
|
321 | - // Set save string |
|
322 | - $hexa=''; |
|
323 | - foreach($array_selected as $key=>$val) |
|
324 | - { |
|
325 | - if ($hexa) $hexa.=','; |
|
326 | - $hexa.=$key; |
|
327 | - } |
|
328 | - |
|
329 | - $hexafiltervalue=''; |
|
330 | - if (! empty($array_filtervalue) && is_array($array_filtervalue)) |
|
331 | - { |
|
332 | - foreach($array_filtervalue as $key=>$val) |
|
333 | - { |
|
334 | - if ($hexafiltervalue) $hexafiltervalue.=','; |
|
335 | - $hexafiltervalue.=$key.'='.$val; |
|
336 | - } |
|
337 | - } |
|
338 | - |
|
339 | - $objexport->model_name = $export_name; |
|
340 | - $objexport->datatoexport = $datatoexport; |
|
341 | - $objexport->hexa = $hexa; |
|
342 | - $objexport->hexafiltervalue = $hexafiltervalue; |
|
343 | - |
|
344 | - $result = $objexport->create($user); |
|
345 | - if ($result >= 0) |
|
346 | - { |
|
347 | - setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs'); |
|
348 | - } |
|
349 | - else |
|
350 | - { |
|
351 | - $langs->load("errors"); |
|
352 | - if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
353 | - setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors'); |
|
354 | - else |
|
355 | - setEventMessages($objexport->error, $objexport->errors, 'errors'); |
|
356 | - } |
|
357 | - } |
|
358 | - else |
|
359 | - { |
|
360 | - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors'); |
|
361 | - } |
|
317 | + if ($export_name) |
|
318 | + { |
|
319 | + asort($array_selected); |
|
320 | + |
|
321 | + // Set save string |
|
322 | + $hexa=''; |
|
323 | + foreach($array_selected as $key=>$val) |
|
324 | + { |
|
325 | + if ($hexa) $hexa.=','; |
|
326 | + $hexa.=$key; |
|
327 | + } |
|
328 | + |
|
329 | + $hexafiltervalue=''; |
|
330 | + if (! empty($array_filtervalue) && is_array($array_filtervalue)) |
|
331 | + { |
|
332 | + foreach($array_filtervalue as $key=>$val) |
|
333 | + { |
|
334 | + if ($hexafiltervalue) $hexafiltervalue.=','; |
|
335 | + $hexafiltervalue.=$key.'='.$val; |
|
336 | + } |
|
337 | + } |
|
338 | + |
|
339 | + $objexport->model_name = $export_name; |
|
340 | + $objexport->datatoexport = $datatoexport; |
|
341 | + $objexport->hexa = $hexa; |
|
342 | + $objexport->hexafiltervalue = $hexafiltervalue; |
|
343 | + |
|
344 | + $result = $objexport->create($user); |
|
345 | + if ($result >= 0) |
|
346 | + { |
|
347 | + setEventMessages($langs->trans("ExportModelSaved",$objexport->model_name), null, 'mesgs'); |
|
348 | + } |
|
349 | + else |
|
350 | + { |
|
351 | + $langs->load("errors"); |
|
352 | + if ($objexport->errno == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
353 | + setEventMessages($langs->trans("ErrorExportDuplicateProfil"), null, 'errors'); |
|
354 | + else |
|
355 | + setEventMessages($objexport->error, $objexport->errors, 'errors'); |
|
356 | + } |
|
357 | + } |
|
358 | + else |
|
359 | + { |
|
360 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("ExportModelName")), null, 'errors'); |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | // Reload an predefined export model |
@@ -373,50 +373,50 @@ discard block |
||
373 | 373 | $result = $objexport->fetch($exportmodelid); |
374 | 374 | if ($result > 0) |
375 | 375 | { |
376 | - $fieldsarray=explode(',',$objexport->hexa); |
|
377 | - $i=1; |
|
378 | - foreach($fieldsarray as $val) |
|
379 | - { |
|
380 | - $array_selected[$val]=$i; |
|
381 | - $i++; |
|
382 | - } |
|
383 | - $_SESSION["export_selected_fields"]=$array_selected; |
|
384 | - |
|
385 | - $fieldsarrayvalue=explode(',',$objexport->hexafiltervalue); |
|
386 | - $i=1; |
|
387 | - foreach($fieldsarrayvalue as $val) |
|
388 | - { |
|
389 | - $tmp=explode('=',$val); |
|
390 | - $array_filtervalue[$tmp[0]]=$tmp[1]; |
|
391 | - $i++; |
|
392 | - } |
|
393 | - $_SESSION["export_filtered_fields"]=$array_filtervalue; |
|
376 | + $fieldsarray=explode(',',$objexport->hexa); |
|
377 | + $i=1; |
|
378 | + foreach($fieldsarray as $val) |
|
379 | + { |
|
380 | + $array_selected[$val]=$i; |
|
381 | + $i++; |
|
382 | + } |
|
383 | + $_SESSION["export_selected_fields"]=$array_selected; |
|
384 | + |
|
385 | + $fieldsarrayvalue=explode(',',$objexport->hexafiltervalue); |
|
386 | + $i=1; |
|
387 | + foreach($fieldsarrayvalue as $val) |
|
388 | + { |
|
389 | + $tmp=explode('=',$val); |
|
390 | + $array_filtervalue[$tmp[0]]=$tmp[1]; |
|
391 | + $i++; |
|
392 | + } |
|
393 | + $_SESSION["export_filtered_fields"]=$array_filtervalue; |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | |
397 | 397 | // Get form with filters |
398 | 398 | if ($step == 4 && $action == 'submitFormField') |
399 | 399 | { |
400 | - // on boucle sur les champs selectionne pour recuperer la valeur |
|
401 | - if (is_array($objexport->array_export_TypeFields[0])) |
|
402 | - { |
|
403 | - $_SESSION["export_filtered_fields"]=array(); |
|
404 | - foreach($objexport->array_export_TypeFields[0] as $code => $type) // $code: s.fieldname $value: Text|Boolean|List:ccc |
|
405 | - { |
|
406 | - $newcode=(string) preg_replace('/\./','_',$code); |
|
407 | - //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>"; |
|
408 | - $filterqualified=1; |
|
409 | - if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0; |
|
410 | - elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0; |
|
411 | - if ($filterqualified) |
|
412 | - { |
|
413 | - //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n"; |
|
414 | - $objexport->array_export_FilterValue[0][$code] = $_POST[$newcode]; |
|
415 | - } |
|
416 | - } |
|
417 | - $array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); |
|
418 | - $_SESSION["export_filtered_fields"]=$array_filtervalue; |
|
419 | - } |
|
400 | + // on boucle sur les champs selectionne pour recuperer la valeur |
|
401 | + if (is_array($objexport->array_export_TypeFields[0])) |
|
402 | + { |
|
403 | + $_SESSION["export_filtered_fields"]=array(); |
|
404 | + foreach($objexport->array_export_TypeFields[0] as $code => $type) // $code: s.fieldname $value: Text|Boolean|List:ccc |
|
405 | + { |
|
406 | + $newcode=(string) preg_replace('/\./','_',$code); |
|
407 | + //print 'xxx'.$code."=".$newcode."=".$type."=".$_POST[$newcode]."\n<br>"; |
|
408 | + $filterqualified=1; |
|
409 | + if (! isset($_POST[$newcode]) || $_POST[$newcode] == '') $filterqualified=0; |
|
410 | + elseif (preg_match('/^List/',$type) && (is_numeric($_POST[$newcode]) && $_POST[$newcode] <= 0)) $filterqualified=0; |
|
411 | + if ($filterqualified) |
|
412 | + { |
|
413 | + //print 'Filter on '.$newcode.' type='.$type.' value='.$_POST[$newcode]."\n"; |
|
414 | + $objexport->array_export_FilterValue[0][$code] = $_POST[$newcode]; |
|
415 | + } |
|
416 | + } |
|
417 | + $array_filtervalue=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); |
|
418 | + $_SESSION["export_filtered_fields"]=$array_filtervalue; |
|
419 | + } |
|
420 | 420 | } |
421 | 421 | |
422 | 422 | |
@@ -465,24 +465,24 @@ discard block |
||
465 | 465 | { |
466 | 466 | $val=!$val; |
467 | 467 | print '<tr '.$bc[$val].'><td nospan="nospan">'; |
468 | - //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' '; |
|
468 | + //print img_object($objexport->array_export_module[$key]->getName(),$export->array_export_module[$key]->picto).' '; |
|
469 | 469 | print $objexport->array_export_module[$key]->getName(); |
470 | 470 | print '</td><td>'; |
471 | - $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[$key]); |
|
472 | - $label=$objexport->array_export_label[$key]; |
|
471 | + $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[$key]); |
|
472 | + $label=$objexport->array_export_label[$key]; |
|
473 | 473 | //print $value.'-'.$icon.'-'.$label."<br>"; |
474 | - print img_object($objexport->array_export_module[$key]->getName(), $icon).' '; |
|
474 | + print img_object($objexport->array_export_module[$key]->getName(), $icon).' '; |
|
475 | 475 | print $label; |
476 | 476 | print '</td><td align="right">'; |
477 | 477 | if ($objexport->array_export_perms[$key]) |
478 | 478 | { |
479 | - print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>'; |
|
479 | + print '<a href="'.DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$objexport->array_export_code[$key].'">'.img_picto($langs->trans("NewExport"),'filenew').'</a>'; |
|
480 | 480 | } |
481 | 481 | else |
482 | 482 | { |
483 | - print $langs->trans("NotEnoughPermissions"); |
|
483 | + print $langs->trans("NotEnoughPermissions"); |
|
484 | 484 | } |
485 | - print '</td></tr>'; |
|
485 | + print '</td></tr>'; |
|
486 | 486 | } |
487 | 487 | } |
488 | 488 | else |
@@ -531,7 +531,7 @@ discard block |
||
531 | 531 | // Lot de donnees a exporter |
532 | 532 | print '<tr><td>'.$langs->trans("DatasetToExport").'</td>'; |
533 | 533 | print '<td>'; |
534 | - $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
534 | + $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
535 | 535 | $label=$objexport->array_export_label[0]; |
536 | 536 | //print $value.'-'.$icon.'-'.$label."<br>"; |
537 | 537 | print img_object($objexport->array_export_module[0]->getName(), $icon).' '; |
@@ -554,7 +554,7 @@ discard block |
||
554 | 554 | print '<table><tr><td colspan="2">'; |
555 | 555 | print $langs->trans("SelectExportFields").' '; |
556 | 556 | if(empty($conf->global->EXPORTS_SHARE_MODELS))$htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1,$user->id); |
557 | - else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1); |
|
557 | + else $htmlother->select_export_model($exportmodelid,'exportmodelid',$datatoexport,1); |
|
558 | 558 | print ' '; |
559 | 559 | print '<input type="submit" class="button" value="'.$langs->trans("Select").'">'; |
560 | 560 | print '</td></tr></table>'; |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | |
564 | 564 | print '<table class="noborder" width="100%">'; |
565 | 565 | print '<tr class="liste_titre">'; |
566 | - print '<td>'.$langs->trans("Entities").'</td>'; |
|
566 | + print '<td>'.$langs->trans("Entities").'</td>'; |
|
567 | 567 | print '<td>'.$langs->trans("ExportableFields").'</td>'; |
568 | 568 | print '<td width="100" align="center">'; |
569 | 569 | print '<a class="liste_titre" title='.$langs->trans("All").' alt='.$langs->trans("All").' href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field=all">'.$langs->trans("All")."</a>"; |
@@ -578,13 +578,13 @@ discard block |
||
578 | 578 | // Select request if all fields are selected |
579 | 579 | $sqlmaxforexport=$objexport->build_sql(0, array(), array()); |
580 | 580 | |
581 | - // $this->array_export_module[0]=$module; |
|
582 | - // $this->array_export_code[0]=$module->export_code[$r]; |
|
583 | - // $this->array_export_label[0]=$module->export_label[$r]; |
|
584 | - // $this->array_export_sql[0]=$module->export_sql[$r]; |
|
585 | - // $this->array_export_fields[0]=$module->export_fields_array[$r]; |
|
586 | - // $this->array_export_entities[0]=$module->export_fields_entities[$r]; |
|
587 | - // $this->array_export_alias[0]=$module->export_fields_alias[$r]; |
|
581 | + // $this->array_export_module[0]=$module; |
|
582 | + // $this->array_export_code[0]=$module->export_code[$r]; |
|
583 | + // $this->array_export_label[0]=$module->export_label[$r]; |
|
584 | + // $this->array_export_sql[0]=$module->export_sql[$r]; |
|
585 | + // $this->array_export_fields[0]=$module->export_fields_array[$r]; |
|
586 | + // $this->array_export_entities[0]=$module->export_fields_entities[$r]; |
|
587 | + // $this->array_export_alias[0]=$module->export_fields_alias[$r]; |
|
588 | 588 | |
589 | 589 | $i = 0; |
590 | 590 | |
@@ -623,16 +623,16 @@ discard block |
||
623 | 623 | { |
624 | 624 | $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>"; |
625 | 625 | } |
626 | - if (! empty($objexport->array_export_examplevalues[0][$code])) |
|
627 | - { |
|
628 | - $htmltext.='<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>'; |
|
629 | - } |
|
630 | - if (! empty($objexport->array_export_TypeFields[0][$code])) |
|
631 | - { |
|
632 | - $htmltext.='<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>'; |
|
633 | - } |
|
634 | - |
|
635 | - if (isset($array_selected[$code]) && $array_selected[$code]) |
|
626 | + if (! empty($objexport->array_export_examplevalues[0][$code])) |
|
627 | + { |
|
628 | + $htmltext.='<b>'.$langs->trans("SourceExample").':</b> '.$objexport->array_export_examplevalues[0][$code].'<br>'; |
|
629 | + } |
|
630 | + if (! empty($objexport->array_export_TypeFields[0][$code])) |
|
631 | + { |
|
632 | + $htmltext.='<b>'.$langs->trans("Type").':</b> '.$objexport->array_export_TypeFields[0][$code].'<br>'; |
|
633 | + } |
|
634 | + |
|
635 | + if (isset($array_selected[$code]) && $array_selected[$code]) |
|
636 | 636 | { |
637 | 637 | // Selected fields |
638 | 638 | print '<td> </td>'; |
@@ -640,16 +640,16 @@ discard block |
||
640 | 640 | print '<td>'; |
641 | 641 | //print $text.'-'.$htmltext."<br>"; |
642 | 642 | print $form->textwithpicto($text,$htmltext); |
643 | - //print ' ('.$code.')'; |
|
643 | + //print ' ('.$code.')'; |
|
644 | 644 | print '</td>'; |
645 | 645 | } |
646 | 646 | else |
647 | 647 | { |
648 | - // Fields not selected |
|
648 | + // Fields not selected |
|
649 | 649 | print '<td>'; |
650 | - //print $text.'-'.$htmltext."<br>"; |
|
651 | - print $form->textwithpicto($text,$htmltext); |
|
652 | - //print ' ('.$code.')'; |
|
650 | + //print $text.'-'.$htmltext."<br>"; |
|
651 | + print $form->textwithpicto($text,$htmltext); |
|
652 | + //print ' ('.$code.')'; |
|
653 | 653 | print '</td>'; |
654 | 654 | print '<td align="center"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?step=2&datatoexport='.$datatoexport.'&action=selectfield&field='.$code.'">'.img_right('default', 0, 'style="max-width: 20px"').'</a></td>'; |
655 | 655 | print '<td> </td>'; |
@@ -667,21 +667,21 @@ discard block |
||
667 | 667 | print '<div class="tabsAction tabsActionNoBottom">'; |
668 | 668 | |
669 | 669 | if (count($array_selected)) |
670 | - { |
|
671 | - // If filters exist |
|
672 | - if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) |
|
673 | - { |
|
674 | - print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>'; |
|
675 | - } |
|
676 | - else |
|
677 | - { |
|
678 | - print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>'; |
|
679 | - } |
|
680 | - } |
|
681 | - else |
|
682 | - { |
|
683 | - print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>'; |
|
684 | - } |
|
670 | + { |
|
671 | + // If filters exist |
|
672 | + if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) |
|
673 | + { |
|
674 | + print '<a class="butAction" href="export.php?step=3&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>'; |
|
675 | + } |
|
676 | + else |
|
677 | + { |
|
678 | + print '<a class="butAction" href="export.php?step=4&datatoexport='.$datatoexport.'">'.$langs->trans("NextStep").'</a>'; |
|
679 | + } |
|
680 | + } |
|
681 | + else |
|
682 | + { |
|
683 | + print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("SelectAtLeastOneField")).'">'.$langs->trans("NextStep").'</a>'; |
|
684 | + } |
|
685 | 685 | |
686 | 686 | print '</div>'; |
687 | 687 | } |
@@ -697,167 +697,167 @@ discard block |
||
697 | 697 | |
698 | 698 | llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); |
699 | 699 | |
700 | - /* |
|
700 | + /* |
|
701 | 701 | * Affichage onglets |
702 | 702 | */ |
703 | - $h = 0; |
|
703 | + $h = 0; |
|
704 | 704 | |
705 | - $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; |
|
706 | - $head[$h][1] = $langs->trans("Step")." 1"; |
|
707 | - $h++; |
|
705 | + $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=1'; |
|
706 | + $head[$h][1] = $langs->trans("Step")." 1"; |
|
707 | + $h++; |
|
708 | 708 | |
709 | - $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport; |
|
710 | - $head[$h][1] = $langs->trans("Step")." 2"; |
|
711 | - $h++; |
|
709 | + $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=2&datatoexport='.$datatoexport; |
|
710 | + $head[$h][1] = $langs->trans("Step")." 2"; |
|
711 | + $h++; |
|
712 | 712 | |
713 | - $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; |
|
714 | - $head[$h][1] = $langs->trans("Step")." 3"; |
|
715 | - $hselected=$h; |
|
716 | - $h++; |
|
713 | + $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; |
|
714 | + $head[$h][1] = $langs->trans("Step")." 3"; |
|
715 | + $hselected=$h; |
|
716 | + $h++; |
|
717 | 717 | |
718 | - dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1); |
|
718 | + dol_fiche_head($head, $hselected, $langs->trans("NewExport"), -1); |
|
719 | 719 | |
720 | 720 | print '<div class="fichecenter">'; |
721 | 721 | print '<div class="underbanner clearboth"></div>'; |
722 | - print '<table width="100%" class="border">'; |
|
723 | - |
|
724 | - // Module |
|
725 | - print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>'; |
|
726 | - print '<td>'; |
|
727 | - //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' '; |
|
728 | - print $objexport->array_export_module[0]->getName(); |
|
729 | - print '</td></tr>'; |
|
730 | - |
|
731 | - // Lot de donnees a exporter |
|
732 | - print '<tr><td>'.$langs->trans("DatasetToExport").'</td>'; |
|
733 | - print '<td>'; |
|
734 | - $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
735 | - $label=$objexport->array_export_label[0]; |
|
736 | - //print $value.'-'.$icon.'-'.$label."<br>"; |
|
737 | - print img_object($objexport->array_export_module[0]->getName(), $icon).' '; |
|
738 | - print $label; |
|
739 | - print '</td></tr>'; |
|
740 | - |
|
741 | - // Nbre champs exportes |
|
742 | - print '<tr><td>'.$langs->trans("ExportedFields").'</td>'; |
|
743 | - $list=''; |
|
744 | - foreach($array_selected as $code=>$value) |
|
745 | - { |
|
746 | - $list.=(! empty($list)?', ':''); |
|
747 | - $list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):''); |
|
748 | - } |
|
749 | - print '<td>'.$list.'</td></tr>'; |
|
750 | - |
|
751 | - print '</table>'; |
|
752 | - print '</div>'; |
|
753 | - |
|
754 | - print '<br>'; |
|
755 | - |
|
756 | - // Combo list of export models |
|
757 | - print $langs->trans("SelectFilterFields").'<br>'; |
|
758 | - |
|
759 | - |
|
760 | - // un formulaire en plus pour recuperer les filtres |
|
761 | - print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">'; |
|
762 | - print '<table class="noborder" width="100%">'; |
|
763 | - print '<tr class="liste_titre">'; |
|
764 | - print '<td>'.$langs->trans("Entities").'</td>'; |
|
765 | - //print '<td>'.$langs->trans("ExportableFields").'</td>'; |
|
766 | - //print '<td align="center"></td>'; |
|
767 | - print '<td>'.$langs->trans("ExportableFields").'</td>'; |
|
768 | - print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>'; |
|
769 | - print '</tr>'; |
|
770 | - |
|
771 | - // Champs exportables |
|
772 | - $fieldsarray=$objexport->array_export_fields[0]; |
|
773 | - // Champs filtrable |
|
774 | - $Typefieldsarray=$objexport->array_export_TypeFields[0]; |
|
775 | - // valeur des filtres |
|
776 | - $ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); |
|
777 | - // Select request if all fields are selected |
|
778 | - $sqlmaxforexport=$objexport->build_sql(0, array(), array()); |
|
779 | - |
|
780 | - $i = 0; |
|
781 | - // on boucle sur les champs |
|
782 | - foreach($fieldsarray as $code => $label) |
|
783 | - { |
|
784 | - print '<tr class="oddeven">'; |
|
785 | - |
|
786 | - $i++; |
|
787 | - $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]); |
|
788 | - $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity); |
|
789 | - $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity); |
|
790 | - |
|
791 | - print '<td class="nowrap">'; |
|
792 | - // If value of entityicon=entitylang='icon:Label' |
|
793 | - $tmparray=explode(':',$entityicon); |
|
794 | - if (count($tmparray) >=2) |
|
795 | - { |
|
796 | - $entityicon=$tmparray[0]; |
|
797 | - $entitylang=$tmparray[1]; |
|
798 | - } |
|
799 | - print img_object('',$entityicon).' '.$langs->trans($entitylang); |
|
800 | - print '</td>'; |
|
801 | - |
|
802 | - // Field name |
|
803 | - $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:''); |
|
804 | - $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:''); |
|
805 | - $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>'); |
|
806 | - |
|
807 | - $tablename=getablenamefromfield($code,$sqlmaxforexport); |
|
808 | - $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>'; |
|
809 | - if (! empty($objexport->array_export_special[0][$code])) |
|
810 | - { |
|
811 | - $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>"; |
|
812 | - } |
|
813 | - else |
|
814 | - { |
|
815 | - $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>"; |
|
816 | - } |
|
817 | - if (! empty($objexport->array_export_examplevalues[0][$code])) |
|
818 | - { |
|
819 | - $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>'; |
|
820 | - } |
|
821 | - if (! empty($objexport->array_export_TypeFields[0][$code])) |
|
822 | - { |
|
823 | - $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>'; |
|
824 | - } |
|
825 | - |
|
826 | - print '<td>'; |
|
827 | - print $form->textwithpicto($text,$htmltext); |
|
828 | - print '</td>'; |
|
829 | - |
|
830 | - // Filter value |
|
831 | - print '<td>'; |
|
832 | - if (! empty($Typefieldsarray[$code])) // Example: Text, List:c_country:label:rowid, Number, Boolean |
|
833 | - { |
|
834 | - $szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]); |
|
835 | - if ($szInfoFiltre) // Is there an info help for this filter ? |
|
836 | - { |
|
837 | - $tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter); |
|
838 | - print $form->textwithpicto($tmp, $szInfoFiltre); |
|
839 | - } |
|
840 | - else |
|
841 | - { |
|
842 | - print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter); |
|
843 | - } |
|
844 | - } |
|
845 | - print '</td>'; |
|
846 | - |
|
847 | - print '</tr>'; |
|
848 | - } |
|
849 | - |
|
850 | - print '</table>'; |
|
851 | - |
|
852 | - print '</div>'; |
|
853 | - |
|
854 | - /* |
|
722 | + print '<table width="100%" class="border">'; |
|
723 | + |
|
724 | + // Module |
|
725 | + print '<tr><td class="titlefield">'.$langs->trans("Module").'</td>'; |
|
726 | + print '<td>'; |
|
727 | + //print img_object($objexport->array_export_module[0]->getName(),$objexport->array_export_module[0]->picto).' '; |
|
728 | + print $objexport->array_export_module[0]->getName(); |
|
729 | + print '</td></tr>'; |
|
730 | + |
|
731 | + // Lot de donnees a exporter |
|
732 | + print '<tr><td>'.$langs->trans("DatasetToExport").'</td>'; |
|
733 | + print '<td>'; |
|
734 | + $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
735 | + $label=$objexport->array_export_label[0]; |
|
736 | + //print $value.'-'.$icon.'-'.$label."<br>"; |
|
737 | + print img_object($objexport->array_export_module[0]->getName(), $icon).' '; |
|
738 | + print $label; |
|
739 | + print '</td></tr>'; |
|
740 | + |
|
741 | + // Nbre champs exportes |
|
742 | + print '<tr><td>'.$langs->trans("ExportedFields").'</td>'; |
|
743 | + $list=''; |
|
744 | + foreach($array_selected as $code=>$value) |
|
745 | + { |
|
746 | + $list.=(! empty($list)?', ':''); |
|
747 | + $list.=(isset($objexport->array_export_fields[0][$code])?$langs->trans($objexport->array_export_fields[0][$code]):''); |
|
748 | + } |
|
749 | + print '<td>'.$list.'</td></tr>'; |
|
750 | + |
|
751 | + print '</table>'; |
|
752 | + print '</div>'; |
|
753 | + |
|
754 | + print '<br>'; |
|
755 | + |
|
756 | + // Combo list of export models |
|
757 | + print $langs->trans("SelectFilterFields").'<br>'; |
|
758 | + |
|
759 | + |
|
760 | + // un formulaire en plus pour recuperer les filtres |
|
761 | + print '<form action="'.$_SERVER["PHP_SELF"].'?step=4&action=submitFormField&datatoexport='.$datatoexport.'" name="FilterField" method="post">'; |
|
762 | + print '<table class="noborder" width="100%">'; |
|
763 | + print '<tr class="liste_titre">'; |
|
764 | + print '<td>'.$langs->trans("Entities").'</td>'; |
|
765 | + //print '<td>'.$langs->trans("ExportableFields").'</td>'; |
|
766 | + //print '<td align="center"></td>'; |
|
767 | + print '<td>'.$langs->trans("ExportableFields").'</td>'; |
|
768 | + print '<td width="25%">'.$langs->trans("FilteredFieldsValues").'</td>'; |
|
769 | + print '</tr>'; |
|
770 | + |
|
771 | + // Champs exportables |
|
772 | + $fieldsarray=$objexport->array_export_fields[0]; |
|
773 | + // Champs filtrable |
|
774 | + $Typefieldsarray=$objexport->array_export_TypeFields[0]; |
|
775 | + // valeur des filtres |
|
776 | + $ValueFiltersarray=(! empty($objexport->array_export_FilterValue[0])?$objexport->array_export_FilterValue[0]:''); |
|
777 | + // Select request if all fields are selected |
|
778 | + $sqlmaxforexport=$objexport->build_sql(0, array(), array()); |
|
779 | + |
|
780 | + $i = 0; |
|
781 | + // on boucle sur les champs |
|
782 | + foreach($fieldsarray as $code => $label) |
|
783 | + { |
|
784 | + print '<tr class="oddeven">'; |
|
785 | + |
|
786 | + $i++; |
|
787 | + $entity=(! empty($objexport->array_export_entities[0][$code])?$objexport->array_export_entities[0][$code]:$objexport->array_export_icon[0]); |
|
788 | + $entityicon=strtolower(! empty($entitytoicon[$entity])?$entitytoicon[$entity]:$entity); |
|
789 | + $entitylang=(! empty($entitytolang[$entity])?$entitytolang[$entity]:$entity); |
|
790 | + |
|
791 | + print '<td class="nowrap">'; |
|
792 | + // If value of entityicon=entitylang='icon:Label' |
|
793 | + $tmparray=explode(':',$entityicon); |
|
794 | + if (count($tmparray) >=2) |
|
795 | + { |
|
796 | + $entityicon=$tmparray[0]; |
|
797 | + $entitylang=$tmparray[1]; |
|
798 | + } |
|
799 | + print img_object('',$entityicon).' '.$langs->trans($entitylang); |
|
800 | + print '</td>'; |
|
801 | + |
|
802 | + // Field name |
|
803 | + $labelName=(! empty($fieldsarray[$code])?$fieldsarray[$code]:''); |
|
804 | + $ValueFilter=(! empty($array_filtervalue[$code])?$array_filtervalue[$code]:''); |
|
805 | + $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>'); |
|
806 | + |
|
807 | + $tablename=getablenamefromfield($code,$sqlmaxforexport); |
|
808 | + $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>'; |
|
809 | + if (! empty($objexport->array_export_special[0][$code])) |
|
810 | + { |
|
811 | + $htmltext.='<b>'.$langs->trans("ComputedField")." -> ".$langs->trans("Method")." :</b> ".$objexport->array_export_special[0][$code]."<br>"; |
|
812 | + } |
|
813 | + else |
|
814 | + { |
|
815 | + $htmltext.='<b>'.$langs->trans("Table")." -> ".$langs->trans("Field").":</b> ".$tablename." -> ".preg_replace('/^.*\./','',$code)."<br>"; |
|
816 | + } |
|
817 | + if (! empty($objexport->array_export_examplevalues[0][$code])) |
|
818 | + { |
|
819 | + $htmltext.=$langs->trans("SourceExample").': <b>'.$objexport->array_export_examplevalues[0][$code].'</b><br>'; |
|
820 | + } |
|
821 | + if (! empty($objexport->array_export_TypeFields[0][$code])) |
|
822 | + { |
|
823 | + $htmltext.=$langs->trans("Type").': <b>'.$objexport->array_export_TypeFields[0][$code].'</b><br>'; |
|
824 | + } |
|
825 | + |
|
826 | + print '<td>'; |
|
827 | + print $form->textwithpicto($text,$htmltext); |
|
828 | + print '</td>'; |
|
829 | + |
|
830 | + // Filter value |
|
831 | + print '<td>'; |
|
832 | + if (! empty($Typefieldsarray[$code])) // Example: Text, List:c_country:label:rowid, Number, Boolean |
|
833 | + { |
|
834 | + $szInfoFiltre=$objexport->genDocFilter($Typefieldsarray[$code]); |
|
835 | + if ($szInfoFiltre) // Is there an info help for this filter ? |
|
836 | + { |
|
837 | + $tmp=$objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter); |
|
838 | + print $form->textwithpicto($tmp, $szInfoFiltre); |
|
839 | + } |
|
840 | + else |
|
841 | + { |
|
842 | + print $objexport->build_filterField($Typefieldsarray[$code], $code, $ValueFilter); |
|
843 | + } |
|
844 | + } |
|
845 | + print '</td>'; |
|
846 | + |
|
847 | + print '</tr>'; |
|
848 | + } |
|
849 | + |
|
850 | + print '</table>'; |
|
851 | + |
|
852 | + print '</div>'; |
|
853 | + |
|
854 | + /* |
|
855 | 855 | * Barre d'action |
856 | 856 | */ |
857 | - print '<div class="tabsAction tabsActionNoBottom">'; |
|
858 | - // il n'est pas obligatoire de filtrer les champs |
|
859 | - print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>'; |
|
860 | - print '</div>'; |
|
857 | + print '<div class="tabsAction tabsActionNoBottom">'; |
|
858 | + // il n'est pas obligatoire de filtrer les champs |
|
859 | + print '<a class="butAction" href="javascript:FilterField.submit();">'.$langs->trans("NextStep").'</a>'; |
|
860 | + print '</div>'; |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | if ($step == 4 && $datatoexport) |
@@ -890,10 +890,10 @@ discard block |
||
890 | 890 | // If filters exist |
891 | 891 | if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) |
892 | 892 | { |
893 | - $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; |
|
894 | - $head[$h][1] = $langs->trans("Step")." 3"; |
|
895 | - $h++; |
|
896 | - $stepoffset++; |
|
893 | + $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; |
|
894 | + $head[$h][1] = $langs->trans("Step")." 3"; |
|
895 | + $h++; |
|
896 | + $stepoffset++; |
|
897 | 897 | } |
898 | 898 | |
899 | 899 | $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport; |
@@ -917,7 +917,7 @@ discard block |
||
917 | 917 | // Lot de donnees a exporter |
918 | 918 | print '<tr><td>'.$langs->trans("DatasetToExport").'</td>'; |
919 | 919 | print '<td>'; |
920 | - $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
920 | + $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
921 | 921 | print img_object($objexport->array_export_module[0]->getName(), $icon).' '; |
922 | 922 | print $objexport->array_export_label[0]; |
923 | 923 | print '</td></tr>'; |
@@ -936,22 +936,22 @@ discard block |
||
936 | 936 | // List of filtered fiels |
937 | 937 | if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) |
938 | 938 | { |
939 | - print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>'; |
|
940 | - $list=''; |
|
941 | - if (! empty($array_filtervalue)) |
|
942 | - { |
|
943 | - foreach($array_filtervalue as $code=>$value) |
|
944 | - { |
|
945 | - if (isset($objexport->array_export_fields[0][$code])) |
|
946 | - { |
|
947 | - $list.=($list?', ':''); |
|
948 | - if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:''); |
|
949 | - else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'"; |
|
950 | - } |
|
951 | - } |
|
952 | - } |
|
953 | - print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>'; |
|
954 | - print '</tr>'; |
|
939 | + print '<tr><td width="25%">'.$langs->trans("FilteredFields").'</td>'; |
|
940 | + $list=''; |
|
941 | + if (! empty($array_filtervalue)) |
|
942 | + { |
|
943 | + foreach($array_filtervalue as $code=>$value) |
|
944 | + { |
|
945 | + if (isset($objexport->array_export_fields[0][$code])) |
|
946 | + { |
|
947 | + $list.=($list?', ':''); |
|
948 | + if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:''); |
|
949 | + else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'"; |
|
950 | + } |
|
951 | + } |
|
952 | + } |
|
953 | + print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>'; |
|
954 | + print '</tr>'; |
|
955 | 955 | } |
956 | 956 | |
957 | 957 | print '</table>'; |
@@ -994,7 +994,7 @@ discard block |
||
994 | 994 | |
995 | 995 | $labelName=$objexport->array_export_fields[0][$code]; |
996 | 996 | |
997 | - $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>'); |
|
997 | + $text=(empty($objexport->array_export_special[0][$code])?'':'<i>').$langs->trans($labelName).(empty($objexport->array_export_special[0][$code])?'':'</i>'); |
|
998 | 998 | |
999 | 999 | $tablename=getablenamefromfield($code,$sqlmaxforexport); |
1000 | 1000 | $htmltext ='<b>'.$langs->trans("Name").':</b> '.$text.'<br>'; |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | |
1018 | 1018 | print '<td>'; |
1019 | 1019 | print $form->textwithpicto($text,$htmltext); |
1020 | - //print ' ('.$code.')'; |
|
1020 | + //print ' ('.$code.')'; |
|
1021 | 1021 | print '</td>'; |
1022 | 1022 | |
1023 | 1023 | print '<td align="right" width="100">'; |
@@ -1051,57 +1051,57 @@ discard block |
||
1051 | 1051 | print '</div>'; |
1052 | 1052 | |
1053 | 1053 | |
1054 | - // Area for profils export |
|
1055 | - if (count($array_selected)) |
|
1054 | + // Area for profils export |
|
1055 | + if (count($array_selected)) |
|
1056 | 1056 | { |
1057 | - print '<br>'; |
|
1057 | + print '<br>'; |
|
1058 | 1058 | print $langs->trans("SaveExportModel"); |
1059 | 1059 | |
1060 | - print '<form class="nocellnopadd" action="export.php" method="post">'; |
|
1061 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
1060 | + print '<form class="nocellnopadd" action="export.php" method="post">'; |
|
1061 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
1062 | 1062 | print '<input type="hidden" name="action" value="add_export_model">'; |
1063 | 1063 | print '<input type="hidden" name="step" value="'.$step.'">'; |
1064 | 1064 | print '<input type="hidden" name="datatoexport" value="'.$datatoexport.'">'; |
1065 | 1065 | print '<input type="hidden" name="hexa" value="'.$hexa.'">'; |
1066 | 1066 | |
1067 | 1067 | print '<table class="noborder" width="100%">'; |
1068 | - print '<tr class="liste_titre">'; |
|
1069 | - print '<td>'.$langs->trans("ExportModelName").'</td>'; |
|
1070 | - print '<td> </td>'; |
|
1071 | - print '</tr>'; |
|
1068 | + print '<tr class="liste_titre">'; |
|
1069 | + print '<td>'.$langs->trans("ExportModelName").'</td>'; |
|
1070 | + print '<td> </td>'; |
|
1071 | + print '</tr>'; |
|
1072 | 1072 | |
1073 | - print '<tr class="oddeven">'; |
|
1074 | - print '<td><input name="export_name" size="32" value=""></td><td align="right">'; |
|
1073 | + print '<tr class="oddeven">'; |
|
1074 | + print '<td><input name="export_name" size="32" value=""></td><td align="right">'; |
|
1075 | 1075 | print '<input type="submit" class="button" value="'.$langs->trans("Save").'">'; |
1076 | 1076 | print '</td></tr>'; |
1077 | 1077 | |
1078 | 1078 | // List of existing export profils |
1079 | - $sql = "SELECT rowid, label"; |
|
1080 | - $sql.= " FROM ".MAIN_DB_PREFIX."export_model"; |
|
1081 | - $sql.= " WHERE type = '".$datatoexport."'"; |
|
1082 | - if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id; |
|
1083 | - $sql.= " ORDER BY rowid"; |
|
1084 | - $resql = $db->query($sql); |
|
1085 | - if ($resql) |
|
1086 | - { |
|
1087 | - $num = $db->num_rows($resql); |
|
1088 | - $i = 0; |
|
1089 | - while ($i < $num) |
|
1090 | - { |
|
1091 | - $obj = $db->fetch_object($resql); |
|
1092 | - print '<tr class="oddeven"><td>'; |
|
1093 | - print $obj->label; |
|
1094 | - print '</td><td align="right">'; |
|
1095 | - print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&id='.$obj->rowid.'">'; |
|
1096 | - print img_delete(); |
|
1097 | - print '</a>'; |
|
1098 | - print '</tr>'; |
|
1099 | - $i++; |
|
1100 | - } |
|
1101 | - } |
|
1102 | - else { |
|
1103 | - dol_print_error($this->db); |
|
1104 | - } |
|
1079 | + $sql = "SELECT rowid, label"; |
|
1080 | + $sql.= " FROM ".MAIN_DB_PREFIX."export_model"; |
|
1081 | + $sql.= " WHERE type = '".$datatoexport."'"; |
|
1082 | + if(empty($conf->global->EXPORTS_SHARE_MODELS))$sql.=" AND fk_user=".$user->id; |
|
1083 | + $sql.= " ORDER BY rowid"; |
|
1084 | + $resql = $db->query($sql); |
|
1085 | + if ($resql) |
|
1086 | + { |
|
1087 | + $num = $db->num_rows($resql); |
|
1088 | + $i = 0; |
|
1089 | + while ($i < $num) |
|
1090 | + { |
|
1091 | + $obj = $db->fetch_object($resql); |
|
1092 | + print '<tr class="oddeven"><td>'; |
|
1093 | + print $obj->label; |
|
1094 | + print '</td><td align="right">'; |
|
1095 | + print '<a href="'.$_SERVER["PHP_SELF"].'?step='.$step.'&datatoexport='.$datatoexport.'&action=deleteprof&id='.$obj->rowid.'">'; |
|
1096 | + print img_delete(); |
|
1097 | + print '</a>'; |
|
1098 | + print '</tr>'; |
|
1099 | + $i++; |
|
1100 | + } |
|
1101 | + } |
|
1102 | + else { |
|
1103 | + dol_print_error($this->db); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | 1106 | print '</table>'; |
1107 | 1107 | print '</form>'; |
@@ -1117,7 +1117,7 @@ discard block |
||
1117 | 1117 | exit; |
1118 | 1118 | } |
1119 | 1119 | |
1120 | - asort($array_selected); |
|
1120 | + asort($array_selected); |
|
1121 | 1121 | |
1122 | 1122 | llxHeader('',$langs->trans("NewExport"),'EN:Module_Exports_En|FR:Module_Exports|ES:Módulo_Exportaciones'); |
1123 | 1123 | |
@@ -1138,10 +1138,10 @@ discard block |
||
1138 | 1138 | // si le filtrage est parametre pour l'export ou pas |
1139 | 1139 | if ($usefilters && isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) |
1140 | 1140 | { |
1141 | - $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; |
|
1142 | - $head[$h][1] = $langs->trans("Step")." 3"; |
|
1143 | - $h++; |
|
1144 | - $stepoffset++; |
|
1141 | + $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=3&datatoexport='.$datatoexport; |
|
1142 | + $head[$h][1] = $langs->trans("Step")." 3"; |
|
1143 | + $h++; |
|
1144 | + $stepoffset++; |
|
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | $head[$h][0] = DOL_URL_ROOT.'/exports/export.php?step=4&datatoexport='.$datatoexport; |
@@ -1160,7 +1160,7 @@ discard block |
||
1160 | 1160 | */ |
1161 | 1161 | if ($action == 'remove_file') |
1162 | 1162 | { |
1163 | - print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); |
|
1163 | + print $form->formconfirm($_SERVER["PHP_SELF"].'?step=5&datatoexport='.$datatoexport.'&file='.urlencode(GETPOST("file")), $langs->trans('DeleteFile'), $langs->trans('ConfirmDeleteFile'), 'confirm_deletefile', '', 0, 1); |
|
1164 | 1164 | } |
1165 | 1165 | |
1166 | 1166 | print '<div class="fichecenter">'; |
@@ -1178,7 +1178,7 @@ discard block |
||
1178 | 1178 | // Lot de donnees a exporter |
1179 | 1179 | print '<tr><td>'.$langs->trans("DatasetToExport").'</td>'; |
1180 | 1180 | print '<td>'; |
1181 | - $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
1181 | + $icon=preg_replace('/:.*$/','',$objexport->array_export_icon[0]); |
|
1182 | 1182 | print img_object($objexport->array_export_module[0]->getName(), $icon).' '; |
1183 | 1183 | print $objexport->array_export_label[0]; |
1184 | 1184 | print '</td></tr>'; |
@@ -1196,22 +1196,22 @@ discard block |
||
1196 | 1196 | // List of filtered fiels |
1197 | 1197 | if (isset($objexport->array_export_TypeFields[0]) && is_array($objexport->array_export_TypeFields[0])) |
1198 | 1198 | { |
1199 | - print '<tr><td>'.$langs->trans("FilteredFields").'</td>'; |
|
1200 | - $list=''; |
|
1201 | - if (! empty($array_filtervalue)) |
|
1202 | - { |
|
1203 | - foreach($array_filtervalue as $code=>$value) |
|
1204 | - { |
|
1205 | - if (isset($objexport->array_export_fields[0][$code])) |
|
1206 | - { |
|
1207 | - $list.=($list?', ':''); |
|
1208 | - if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:''); |
|
1209 | - else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'"; |
|
1210 | - } |
|
1211 | - } |
|
1212 | - } |
|
1213 | - print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>'; |
|
1214 | - print '</tr>'; |
|
1199 | + print '<tr><td>'.$langs->trans("FilteredFields").'</td>'; |
|
1200 | + $list=''; |
|
1201 | + if (! empty($array_filtervalue)) |
|
1202 | + { |
|
1203 | + foreach($array_filtervalue as $code=>$value) |
|
1204 | + { |
|
1205 | + if (isset($objexport->array_export_fields[0][$code])) |
|
1206 | + { |
|
1207 | + $list.=($list?', ':''); |
|
1208 | + if (isset($array_filtervalue[$code]) && preg_match('/^\s*[<>]/',$array_filtervalue[$code])) $list.=$langs->trans($objexport->array_export_fields[0][$code]).(isset($array_filtervalue[$code])?$array_filtervalue[$code]:''); |
|
1209 | + else $list.=$langs->trans($objexport->array_export_fields[0][$code])."='".(isset($array_filtervalue[$code])?$array_filtervalue[$code]:'')."'"; |
|
1210 | + } |
|
1211 | + } |
|
1212 | + } |
|
1213 | + print '<td>'.(! empty($list)?$list:$langs->trans("None")).'</td>'; |
|
1214 | + print '</tr>'; |
|
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | print '</table>'; |
@@ -1233,17 +1233,17 @@ discard block |
||
1233 | 1233 | $listeall=$liste; |
1234 | 1234 | foreach($listeall as $key => $val) |
1235 | 1235 | { |
1236 | - if (preg_match('/__\(Disabled\)__/',$listeall[$key])) |
|
1237 | - { |
|
1238 | - $listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]); |
|
1239 | - unset($liste[$key]); |
|
1240 | - } |
|
1236 | + if (preg_match('/__\(Disabled\)__/',$listeall[$key])) |
|
1237 | + { |
|
1238 | + $listeall[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$listeall[$key]); |
|
1239 | + unset($liste[$key]); |
|
1240 | + } |
|
1241 | 1241 | |
1242 | 1242 | print '<tr class="oddeven">'; |
1243 | 1243 | print '<td width="16">'.img_picto_common($key,$objmodelexport->getPictoForKey($key)).' '; |
1244 | - $text=$objmodelexport->getDriverDescForKey($key); |
|
1245 | - $label=$listeall[$key]; |
|
1246 | - print $form->textwithpicto($label,$text).'</td>'; |
|
1244 | + $text=$objmodelexport->getDriverDescForKey($key); |
|
1245 | + $label=$listeall[$key]; |
|
1246 | + print $form->textwithpicto($label,$text).'</td>'; |
|
1247 | 1247 | print '<td>'.$objmodelexport->getLibLabelForKey($key).'</td>'; |
1248 | 1248 | print '<td align="right">'.$objmodelexport->getLibVersionForKey($key).'</td>'; |
1249 | 1249 | print '</tr>'."\n"; |
@@ -1257,14 +1257,14 @@ discard block |
||
1257 | 1257 | |
1258 | 1258 | if ($sqlusedforexport && $user->admin) |
1259 | 1259 | { |
1260 | - print '<tr><td>'; |
|
1261 | - print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport); |
|
1262 | - print '</td></tr>'; |
|
1260 | + print '<tr><td>'; |
|
1261 | + print info_admin($langs->trans("SQLUsedForExport").':<br> '.$sqlusedforexport); |
|
1262 | + print '</td></tr>'; |
|
1263 | 1263 | } |
1264 | - print '</table>'; |
|
1264 | + print '</table>'; |
|
1265 | 1265 | |
1266 | 1266 | |
1267 | - print '<div class="fichecenter"><div class="fichehalfleft">'; |
|
1267 | + print '<div class="fichecenter"><div class="fichehalfleft">'; |
|
1268 | 1268 | |
1269 | 1269 | if (! is_dir($conf->export->dir_temp)) dol_mkdir($conf->export->dir_temp); |
1270 | 1270 | |
@@ -1293,16 +1293,16 @@ discard block |
||
1293 | 1293 | */ |
1294 | 1294 | function getablenamefromfield($code,$sqlmaxforexport) |
1295 | 1295 | { |
1296 | - $alias=preg_replace('/\.(.*)$/i','',$code); // Keep only 'Alias' and remove '.Fieldname' |
|
1297 | - $regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i'; |
|
1298 | - |
|
1299 | - $newsql=$sqlmaxforexport; |
|
1300 | - $newsql=preg_replace('/^(.*) FROM /i','',$newsql); // Remove part before the FROM |
|
1301 | - $newsql=preg_replace('/WHERE (.*)$/i','',$newsql); // Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE |
|
1302 | - |
|
1303 | - if (preg_match($regexstring,$newsql,$reg)) |
|
1304 | - { |
|
1305 | - return $reg[1]; // The tablename |
|
1306 | - } |
|
1307 | - else return ''; |
|
1296 | + $alias=preg_replace('/\.(.*)$/i','',$code); // Keep only 'Alias' and remove '.Fieldname' |
|
1297 | + $regexstring='/([a-zA-Z_]+) as '.preg_quote($alias).'[, \)]/i'; |
|
1298 | + |
|
1299 | + $newsql=$sqlmaxforexport; |
|
1300 | + $newsql=preg_replace('/^(.*) FROM /i','',$newsql); // Remove part before the FROM |
|
1301 | + $newsql=preg_replace('/WHERE (.*)$/i','',$newsql); // Remove part after the WHERE so we have now only list of table aliases in a string. We must keep the ' ' before WHERE |
|
1302 | + |
|
1303 | + if (preg_match($regexstring,$newsql,$reg)) |
|
1304 | + { |
|
1305 | + return $reg[1]; // The tablename |
|
1306 | + } |
|
1307 | + else return ''; |
|
1308 | 1308 | } |
@@ -91,15 +91,15 @@ discard block |
||
91 | 91 | print '<div class="center">'; |
92 | 92 | if (count($export->array_export_code)) |
93 | 93 | { |
94 | - if ($user->rights->export->creer) |
|
95 | - { |
|
96 | - print '<a class="butActionNew" href="'.DOL_URL_ROOT.'/exports/export.php?leftmenu=export">'.$langs->trans("NewExport").'<span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
97 | - } |
|
98 | - else |
|
99 | - { |
|
100 | - print '<a class="butActionNewRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("NewExport").'<span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
101 | - } |
|
102 | - /* |
|
94 | + if ($user->rights->export->creer) |
|
95 | + { |
|
96 | + print '<a class="butActionNew" href="'.DOL_URL_ROOT.'/exports/export.php?leftmenu=export">'.$langs->trans("NewExport").'<span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
97 | + } |
|
98 | + else |
|
99 | + { |
|
100 | + print '<a class="butActionNewRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("NewExport").'<span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
101 | + } |
|
102 | + /* |
|
103 | 103 | print '<form action="'.DOL_URL_ROOT.'/exports/export.php?leftmenu=export"><input type="submit" class="button" value="'.$langs->trans("NewExport").'"'; |
104 | 104 | print ($user->rights->export->creer?'':' disabled'); |
105 | 105 | print '><div class="center"></div></form>'; |
@@ -127,17 +127,17 @@ discard block |
||
127 | 127 | { |
128 | 128 | if (preg_match('/__\(Disabled\)__/',$liste[$key])) |
129 | 129 | { |
130 | - $liste[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$liste[$key]); |
|
130 | + $liste[$key]=preg_replace('/__\(Disabled\)__/','('.$langs->transnoentitiesnoconv("Disabled").')',$liste[$key]); |
|
131 | 131 | } |
132 | 132 | |
133 | - print '<tr class="oddeven">'; |
|
134 | - print '<td width="16">'.img_picto_common($model->getDriverLabelForKey($key),$model->getPictoForKey($key)).'</td>'; |
|
135 | - $text=$model->getDriverDescForKey($key); |
|
136 | - $label=$liste[$key]; |
|
137 | - print '<td>'.$form->textwithpicto($label,$text).'</td>'; |
|
138 | - print '<td>'.$model->getLibLabelForKey($key).'</td>'; |
|
139 | - print '<td class="nowrap" align="right">'.$model->getLibVersionForKey($key).'</td>'; |
|
140 | - print '</tr>'; |
|
133 | + print '<tr class="oddeven">'; |
|
134 | + print '<td width="16">'.img_picto_common($model->getDriverLabelForKey($key),$model->getPictoForKey($key)).'</td>'; |
|
135 | + $text=$model->getDriverDescForKey($key); |
|
136 | + $label=$liste[$key]; |
|
137 | + print '<td>'.$form->textwithpicto($label,$text).'</td>'; |
|
138 | + print '<td>'.$model->getLibLabelForKey($key).'</td>'; |
|
139 | + print '<td class="nowrap" align="right">'.$model->getLibVersionForKey($key).'</td>'; |
|
140 | + print '</tr>'; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | print '</table>'; |
@@ -57,24 +57,24 @@ discard block |
||
57 | 57 | $pagenext = $page + 1; |
58 | 58 | if (! $sortfield) |
59 | 59 | { |
60 | - if ($id > 0) |
|
61 | - { |
|
62 | - $sortfield="f.datef"; |
|
63 | - $sortorder="DESC"; |
|
64 | - } |
|
65 | - else |
|
66 | - { |
|
67 | - $sortfield="p.ref"; |
|
68 | - $sortorder="ASC"; |
|
69 | - } |
|
60 | + if ($id > 0) |
|
61 | + { |
|
62 | + $sortfield="f.datef"; |
|
63 | + $sortorder="DESC"; |
|
64 | + } |
|
65 | + else |
|
66 | + { |
|
67 | + $sortfield="p.ref"; |
|
68 | + $sortorder="ASC"; |
|
69 | + } |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | $startdate=$enddate=''; |
73 | 73 | |
74 | 74 | if (!empty($_POST['startdatemonth'])) |
75 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
75 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
76 | 76 | if (!empty($_POST['enddatemonth'])) |
77 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
77 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
78 | 78 | |
79 | 79 | |
80 | 80 | /* |
@@ -104,19 +104,19 @@ discard block |
||
104 | 104 | |
105 | 105 | if ($id > 0) { |
106 | 106 | |
107 | - print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>'; |
|
108 | - print '<td class="maxwidthonsmartpone" colspan="4">'; |
|
109 | - print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All'); |
|
110 | - print '</td></tr>'; |
|
107 | + print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>'; |
|
108 | + print '<td class="maxwidthonsmartpone" colspan="4">'; |
|
109 | + print $form->select_produits($id,'id','',20,0,1,2,'',1, array(), 0, 'All'); |
|
110 | + print '</td></tr>'; |
|
111 | 111 | |
112 | - if (! $sortorder) $sortorder="DESC"; |
|
113 | - if (! $sortfield) $sortfield="f.datef"; |
|
112 | + if (! $sortorder) $sortorder="DESC"; |
|
113 | + if (! $sortfield) $sortfield="f.datef"; |
|
114 | 114 | } |
115 | 115 | else { |
116 | - print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>'; |
|
117 | - print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
118 | - print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All'); |
|
119 | - print '</td></tr>'; |
|
116 | + print '<tr><td class="titlefield">'.$langs->trans('ChooseProduct/Service').'</td>'; |
|
117 | + print '<td class="maxwidthonsmartphone" colspan="4">'; |
|
118 | + print $form->select_produits('','id','',20,0,1,2,'',1, array(), 0, 'All'); |
|
119 | + print '</td></tr>'; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | // Categories |
@@ -156,16 +156,16 @@ discard block |
||
156 | 156 | |
157 | 157 | // Margin Rate |
158 | 158 | if (! empty($conf->global->DISPLAY_MARGIN_RATES)) { |
159 | - print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
|
160 | - print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
161 | - print '</td></tr>'; |
|
159 | + print '<tr><td>'.$langs->trans("MarginRate").'</td><td colspan="4">'; |
|
160 | + print '<span id="marginRate"></span>'; // set by jquery (see below) |
|
161 | + print '</td></tr>'; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | // Mark Rate |
165 | 165 | if (! empty($conf->global->DISPLAY_MARK_RATES)) { |
166 | - print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
|
167 | - print '<span id="markRate"></span>'; // set by jquery (see below) |
|
168 | - print '</td></tr>'; |
|
166 | + print '<tr><td>'.$langs->trans("MarkRate").'</td><td colspan="4">'; |
|
167 | + print '<span id="markRate"></span>'; // set by jquery (see below) |
|
168 | + print '</td></tr>'; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | print "</table>"; |
@@ -186,24 +186,24 @@ discard block |
||
186 | 186 | $sql.= ", ".MAIN_DB_PREFIX."facturedet as d"; |
187 | 187 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = d.fk_product"; |
188 | 188 | if (! empty($TSelectedCats)) { |
189 | - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid'; |
|
189 | + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=p.rowid'; |
|
190 | 190 | } |
191 | 191 | $sql.= " WHERE f.fk_soc = s.rowid"; |
192 | 192 | $sql.= ' AND f.entity IN ('.getEntity('invoice').')'; |
193 | 193 | $sql.= " AND f.fk_statut > 0"; |
194 | 194 | $sql.= " AND d.fk_facture = f.rowid"; |
195 | 195 | if ($id > 0) |
196 | - $sql.= " AND d.fk_product =".$id; |
|
196 | + $sql.= " AND d.fk_product =".$id; |
|
197 | 197 | if (! empty($TSelectedCats)) { |
198 | - $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
198 | + $sql .= ' AND cp.fk_categorie IN ('.implode(',', $TSelectedCats) . ')'; |
|
199 | 199 | } |
200 | 200 | if (!empty($startdate)) |
201 | - $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
201 | + $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
202 | 202 | if (!empty($enddate)) |
203 | - $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
203 | + $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
204 | 204 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
205 | 205 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) |
206 | - $sql .= " AND d.buy_price_ht <> 0"; |
|
206 | + $sql .= " AND d.buy_price_ht <> 0"; |
|
207 | 207 | if ($id > 0) $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity, d.fk_product, f.rowid, f.ref, f.total, f.datef, f.paye, f.fk_statut"; |
208 | 208 | else $sql.= " GROUP BY p.label, p.rowid, p.fk_product_type, p.ref, p.entity"; |
209 | 209 | $sql.=$db->order($sortfield,$sortorder); |
@@ -214,137 +214,137 @@ discard block |
||
214 | 214 | $result = $db->query($sql); |
215 | 215 | if ($result) |
216 | 216 | { |
217 | - $num = $db->num_rows($result); |
|
217 | + $num = $db->num_rows($result); |
|
218 | 218 | |
219 | - print '<br>'; |
|
220 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&id=".$id, $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
219 | + print '<br>'; |
|
220 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "&id=".$id, $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
221 | 221 | |
222 | - //var_dump($conf->global->MARGIN_TYPE); |
|
223 | - if ($conf->global->MARGIN_TYPE == "1") |
|
224 | - $labelcostprice='BuyingPrice'; |
|
225 | - else // value is 'costprice' or 'pmp' |
|
226 | - $labelcostprice='CostPrice'; |
|
222 | + //var_dump($conf->global->MARGIN_TYPE); |
|
223 | + if ($conf->global->MARGIN_TYPE == "1") |
|
224 | + $labelcostprice='BuyingPrice'; |
|
225 | + else // value is 'costprice' or 'pmp' |
|
226 | + $labelcostprice='CostPrice'; |
|
227 | 227 | |
228 | - $moreforfilter=''; |
|
228 | + $moreforfilter=''; |
|
229 | 229 | |
230 | - $i = 0; |
|
230 | + $i = 0; |
|
231 | 231 | print '<div class="div-table-responsive">'; |
232 | 232 | print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n"; |
233 | 233 | |
234 | - print '<tr class="liste_titre">'; |
|
235 | - if ($id > 0) { |
|
236 | - print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&id=".$id,'',$sortfield,$sortorder); |
|
237 | - print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&id=".$id,'align="center"',$sortfield,$sortorder); |
|
238 | - } |
|
239 | - else |
|
240 | - { |
|
241 | - print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&id=".$id,'',$sortfield,$sortorder); |
|
242 | - } |
|
243 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
244 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
245 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
246 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
247 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
248 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
249 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
250 | - print "</tr>\n"; |
|
251 | - |
|
252 | - $cumul_achat = 0; |
|
253 | - $cumul_vente = 0; |
|
254 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
255 | - |
|
256 | - if ($num > 0) |
|
257 | - { |
|
258 | - while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
259 | - { |
|
260 | - $objp = $db->fetch_object($result); |
|
261 | - $pa = $objp->buying_price; |
|
262 | - $pv = $objp->selling_price; |
|
263 | - $marge = $objp->marge; |
|
264 | - |
|
265 | - if ($marge < 0) |
|
266 | - { |
|
267 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
268 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
269 | - } |
|
270 | - else |
|
271 | - { |
|
272 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
273 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
274 | - } |
|
275 | - |
|
276 | - print '<tr class="oddeven">'; |
|
277 | - if ($id > 0) { |
|
278 | - print '<td>'; |
|
279 | - $invoicestatic->id=$objp->facid; |
|
280 | - $invoicestatic->ref=$objp->ref; |
|
281 | - print $invoicestatic->getNomUrl(1); |
|
282 | - print "</td>\n"; |
|
283 | - print "<td align=\"center\">"; |
|
284 | - print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
285 | - } |
|
286 | - else { |
|
287 | - print '<td>'; |
|
288 | - if ($objp->rowid > 0) |
|
289 | - { |
|
290 | - $product_static->type=$objp->fk_product_type; |
|
291 | - $product_static->id=$objp->rowid; |
|
292 | - $product_static->ref=$objp->ref; |
|
293 | - $product_static->label=$objp->label; |
|
294 | - $product_static->entity=$objp->pentity; |
|
295 | - $text=$product_static->getNomUrl(1); |
|
296 | - print $text.= ' - '.$objp->label; |
|
297 | - } |
|
298 | - else |
|
299 | - { |
|
300 | - print img_object('', 'product').' '.$langs->trans("NotPredefinedProducts"); |
|
301 | - } |
|
302 | - print "</td>\n"; |
|
303 | - //print "<td>".$product_static->getNomUrl(1)."</td>\n"; |
|
304 | - } |
|
305 | - print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
306 | - print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
307 | - print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
308 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
309 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
310 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
311 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
312 | - print "</tr>\n"; |
|
313 | - |
|
314 | - $i++; |
|
315 | - $cumul_achat += $objp->buying_price; |
|
316 | - $cumul_vente += $objp->selling_price; |
|
317 | - } |
|
318 | - } |
|
319 | - |
|
320 | - // affichage totaux marges |
|
321 | - |
|
322 | - $totalMargin = $cumul_vente - $cumul_achat; |
|
323 | - |
|
324 | - $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
325 | - $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
326 | - |
|
327 | - print '<tr class="liste_total">'; |
|
328 | - if ($id > 0) |
|
329 | - print '<td colspan=2>'; |
|
330 | - else |
|
331 | - print '<td>'; |
|
332 | - print $langs->trans('TotalMargin')."</td>"; |
|
333 | - print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
334 | - print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
335 | - print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
336 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
337 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
338 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
339 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
340 | - print "</tr>\n"; |
|
341 | - |
|
342 | - print "</table>"; |
|
343 | - print '</div>'; |
|
234 | + print '<tr class="liste_titre">'; |
|
235 | + if ($id > 0) { |
|
236 | + print_liste_field_titre("Invoice",$_SERVER["PHP_SELF"],"f.ref","","&id=".$id,'',$sortfield,$sortorder); |
|
237 | + print_liste_field_titre("DateInvoice",$_SERVER["PHP_SELF"],"f.datef","","&id=".$id,'align="center"',$sortfield,$sortorder); |
|
238 | + } |
|
239 | + else |
|
240 | + { |
|
241 | + print_liste_field_titre("ProductService",$_SERVER["PHP_SELF"],"p.ref","","&id=".$id,'',$sortfield,$sortorder); |
|
242 | + } |
|
243 | + print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
244 | + print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
245 | + print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
246 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
247 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
248 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
249 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&id=".$id,'align="right"',$sortfield,$sortorder); |
|
250 | + print "</tr>\n"; |
|
251 | + |
|
252 | + $cumul_achat = 0; |
|
253 | + $cumul_vente = 0; |
|
254 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
255 | + |
|
256 | + if ($num > 0) |
|
257 | + { |
|
258 | + while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
259 | + { |
|
260 | + $objp = $db->fetch_object($result); |
|
261 | + $pa = $objp->buying_price; |
|
262 | + $pv = $objp->selling_price; |
|
263 | + $marge = $objp->marge; |
|
264 | + |
|
265 | + if ($marge < 0) |
|
266 | + { |
|
267 | + $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
268 | + $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
269 | + } |
|
270 | + else |
|
271 | + { |
|
272 | + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
273 | + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
274 | + } |
|
275 | + |
|
276 | + print '<tr class="oddeven">'; |
|
277 | + if ($id > 0) { |
|
278 | + print '<td>'; |
|
279 | + $invoicestatic->id=$objp->facid; |
|
280 | + $invoicestatic->ref=$objp->ref; |
|
281 | + print $invoicestatic->getNomUrl(1); |
|
282 | + print "</td>\n"; |
|
283 | + print "<td align=\"center\">"; |
|
284 | + print dol_print_date($db->jdate($objp->datef),'day')."</td>"; |
|
285 | + } |
|
286 | + else { |
|
287 | + print '<td>'; |
|
288 | + if ($objp->rowid > 0) |
|
289 | + { |
|
290 | + $product_static->type=$objp->fk_product_type; |
|
291 | + $product_static->id=$objp->rowid; |
|
292 | + $product_static->ref=$objp->ref; |
|
293 | + $product_static->label=$objp->label; |
|
294 | + $product_static->entity=$objp->pentity; |
|
295 | + $text=$product_static->getNomUrl(1); |
|
296 | + print $text.= ' - '.$objp->label; |
|
297 | + } |
|
298 | + else |
|
299 | + { |
|
300 | + print img_object('', 'product').' '.$langs->trans("NotPredefinedProducts"); |
|
301 | + } |
|
302 | + print "</td>\n"; |
|
303 | + //print "<td>".$product_static->getNomUrl(1)."</td>\n"; |
|
304 | + } |
|
305 | + print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
306 | + print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
307 | + print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
308 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
309 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
310 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
311 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
312 | + print "</tr>\n"; |
|
313 | + |
|
314 | + $i++; |
|
315 | + $cumul_achat += $objp->buying_price; |
|
316 | + $cumul_vente += $objp->selling_price; |
|
317 | + } |
|
318 | + } |
|
319 | + |
|
320 | + // affichage totaux marges |
|
321 | + |
|
322 | + $totalMargin = $cumul_vente - $cumul_achat; |
|
323 | + |
|
324 | + $marginRate = ($cumul_achat != 0)?(100 * $totalMargin / $cumul_achat):''; |
|
325 | + $markRate = ($cumul_vente != 0)?(100 * $totalMargin / $cumul_vente):''; |
|
326 | + |
|
327 | + print '<tr class="liste_total">'; |
|
328 | + if ($id > 0) |
|
329 | + print '<td colspan=2>'; |
|
330 | + else |
|
331 | + print '<td>'; |
|
332 | + print $langs->trans('TotalMargin')."</td>"; |
|
333 | + print "<td align=\"right\">".price($cumul_vente, null, null, null, null, $rounding)."</td>\n"; |
|
334 | + print "<td align=\"right\">".price($cumul_achat, null, null, null, null, $rounding)."</td>\n"; |
|
335 | + print "<td align=\"right\">".price($totalMargin, null, null, null, null, $rounding)."</td>\n"; |
|
336 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
337 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
338 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
339 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
340 | + print "</tr>\n"; |
|
341 | + |
|
342 | + print "</table>"; |
|
343 | + print '</div>'; |
|
344 | 344 | } |
345 | 345 | else |
346 | 346 | { |
347 | - dol_print_error($db); |
|
347 | + dol_print_error($db); |
|
348 | 348 | } |
349 | 349 | $db->free($result); |
350 | 350 |
@@ -30,25 +30,25 @@ discard block |
||
30 | 30 | */ |
31 | 31 | function marges_admin_prepare_head() |
32 | 32 | { |
33 | - global $langs, $conf; |
|
33 | + global $langs, $conf; |
|
34 | 34 | |
35 | - $h = 0; |
|
36 | - $head = array(); |
|
35 | + $h = 0; |
|
36 | + $head = array(); |
|
37 | 37 | |
38 | - $head[$h][0] = DOL_URL_ROOT."/margin/admin/margin.php"; |
|
39 | - $head[$h][1] = $langs->trans("Parameters"); |
|
40 | - $head[$h][2] = 'parameters'; |
|
41 | - $h++; |
|
38 | + $head[$h][0] = DOL_URL_ROOT."/margin/admin/margin.php"; |
|
39 | + $head[$h][1] = $langs->trans("Parameters"); |
|
40 | + $head[$h][2] = 'parameters'; |
|
41 | + $h++; |
|
42 | 42 | |
43 | - // Show more tabs from modules |
|
44 | - // Entries must be declared in modules descriptor with line |
|
43 | + // Show more tabs from modules |
|
44 | + // Entries must be declared in modules descriptor with line |
|
45 | 45 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
46 | 46 | // $this->tabs = array('entity:-tabname); to remove a tab |
47 | - complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin'); |
|
47 | + complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin'); |
|
48 | 48 | |
49 | - complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin','remove'); |
|
49 | + complete_head_from_modules($conf,$langs,'',$head,$h,'margesadmin','remove'); |
|
50 | 50 | |
51 | - return $head; |
|
51 | + return $head; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -58,45 +58,45 @@ discard block |
||
58 | 58 | */ |
59 | 59 | function marges_prepare_head() |
60 | 60 | { |
61 | - global $langs, $conf, $user; |
|
62 | - $langs->load("margins"); |
|
63 | - |
|
64 | - $h = 0; |
|
65 | - $head = array(); |
|
66 | - |
|
67 | - if ($user->rights->produit->lire) { |
|
68 | - $head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php"; |
|
69 | - $head[$h][1] = $langs->trans("ProductMargins"); |
|
70 | - $head[$h][2] = 'productMargins'; |
|
71 | - $h++; |
|
72 | - } |
|
73 | - |
|
74 | - if ($user->rights->societe->lire) { |
|
75 | - $head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php"; |
|
76 | - $head[$h][1] = $langs->trans("CustomerMargins"); |
|
77 | - $head[$h][2] = 'customerMargins'; |
|
78 | - $h++; |
|
79 | - } |
|
80 | - |
|
81 | - if ($user->rights->margins->read->all) { |
|
82 | - $title = 'UserMargins'; |
|
83 | - } else { |
|
84 | - $title = 'SalesRepresentativeMargins'; |
|
85 | - } |
|
86 | - |
|
87 | - $head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php"; |
|
88 | - $head[$h][1] = $langs->trans($title); |
|
89 | - $head[$h][2] = 'agentMargins'; |
|
61 | + global $langs, $conf, $user; |
|
62 | + $langs->load("margins"); |
|
63 | + |
|
64 | + $h = 0; |
|
65 | + $head = array(); |
|
66 | + |
|
67 | + if ($user->rights->produit->lire) { |
|
68 | + $head[$h][0] = DOL_URL_ROOT."/margin/productMargins.php"; |
|
69 | + $head[$h][1] = $langs->trans("ProductMargins"); |
|
70 | + $head[$h][2] = 'productMargins'; |
|
71 | + $h++; |
|
72 | + } |
|
73 | + |
|
74 | + if ($user->rights->societe->lire) { |
|
75 | + $head[$h][0] = DOL_URL_ROOT."/margin/customerMargins.php"; |
|
76 | + $head[$h][1] = $langs->trans("CustomerMargins"); |
|
77 | + $head[$h][2] = 'customerMargins'; |
|
78 | + $h++; |
|
79 | + } |
|
80 | + |
|
81 | + if ($user->rights->margins->read->all) { |
|
82 | + $title = 'UserMargins'; |
|
83 | + } else { |
|
84 | + $title = 'SalesRepresentativeMargins'; |
|
85 | + } |
|
86 | + |
|
87 | + $head[$h][0] = DOL_URL_ROOT."/margin/agentMargins.php"; |
|
88 | + $head[$h][1] = $langs->trans($title); |
|
89 | + $head[$h][2] = 'agentMargins'; |
|
90 | 90 | |
91 | 91 | |
92 | - if ($user->rights->margins->creer) { |
|
93 | - $h++; |
|
94 | - $head[$h][0] = DOL_URL_ROOT."/margin/checkMargins.php"; |
|
95 | - $head[$h][1] = $langs->trans('CheckMargins'); |
|
96 | - $head[$h][2] = 'checkMargins'; |
|
97 | - } |
|
98 | - |
|
99 | - return $head; |
|
92 | + if ($user->rights->margins->creer) { |
|
93 | + $h++; |
|
94 | + $head[$h][0] = DOL_URL_ROOT."/margin/checkMargins.php"; |
|
95 | + $head[$h][1] = $langs->trans('CheckMargins'); |
|
96 | + $head[$h][2] = 'checkMargins'; |
|
97 | + } |
|
98 | + |
|
99 | + return $head; |
|
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
@@ -113,46 +113,46 @@ discard block |
||
113 | 113 | */ |
114 | 114 | function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht) |
115 | 115 | { |
116 | - global $db, $conf; |
|
117 | - |
|
118 | - $marge_tx_ret=''; |
|
119 | - $marque_tx_ret=''; |
|
120 | - |
|
121 | - if ($fk_pa > 0 && empty($paht)) { |
|
122 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
123 | - $product = new ProductFournisseur($db); |
|
124 | - if ($product->fetch_product_fournisseur_price($fk_pa)) |
|
125 | - { |
|
126 | - $paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); |
|
127 | - } |
|
128 | - else |
|
129 | - { |
|
130 | - $paht_ret = $paht; |
|
131 | - } |
|
132 | - } |
|
133 | - else |
|
134 | - { |
|
135 | - $paht_ret = $paht; |
|
136 | - } |
|
137 | - |
|
138 | - // Calculate selling unit price including line discount |
|
139 | - // We don't use calculate_price, because this function is dedicated to calculation of total with accuracy of total. We need an accuracy of a unit price. |
|
140 | - // Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT |
|
141 | - $pu_ht_remise = $pvht * (1 - ($remise_percent / 100)); |
|
142 | - $pu_ht_remise = price2num($pu_ht_remise, 'MU'); |
|
143 | - |
|
144 | - // calcul marge |
|
145 | - if ($pu_ht_remise < 0) |
|
146 | - $marge = -1 * (abs($pu_ht_remise) - $paht_ret); |
|
147 | - else |
|
148 | - $marge = $pu_ht_remise - $paht_ret; |
|
149 | - |
|
150 | - // calcul taux marge |
|
151 | - if ($paht_ret != 0) |
|
152 | - $marge_tx_ret = (100 * $marge) / $paht_ret; |
|
153 | - // calcul taux marque |
|
154 | - if ($pu_ht_remise != 0) |
|
155 | - $marque_tx_ret = (100 * $marge) / $pu_ht_remise; |
|
156 | - |
|
157 | - return array($paht_ret, $marge_tx_ret, $marque_tx_ret); |
|
116 | + global $db, $conf; |
|
117 | + |
|
118 | + $marge_tx_ret=''; |
|
119 | + $marque_tx_ret=''; |
|
120 | + |
|
121 | + if ($fk_pa > 0 && empty($paht)) { |
|
122 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
123 | + $product = new ProductFournisseur($db); |
|
124 | + if ($product->fetch_product_fournisseur_price($fk_pa)) |
|
125 | + { |
|
126 | + $paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); |
|
127 | + } |
|
128 | + else |
|
129 | + { |
|
130 | + $paht_ret = $paht; |
|
131 | + } |
|
132 | + } |
|
133 | + else |
|
134 | + { |
|
135 | + $paht_ret = $paht; |
|
136 | + } |
|
137 | + |
|
138 | + // Calculate selling unit price including line discount |
|
139 | + // We don't use calculate_price, because this function is dedicated to calculation of total with accuracy of total. We need an accuracy of a unit price. |
|
140 | + // Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT |
|
141 | + $pu_ht_remise = $pvht * (1 - ($remise_percent / 100)); |
|
142 | + $pu_ht_remise = price2num($pu_ht_remise, 'MU'); |
|
143 | + |
|
144 | + // calcul marge |
|
145 | + if ($pu_ht_remise < 0) |
|
146 | + $marge = -1 * (abs($pu_ht_remise) - $paht_ret); |
|
147 | + else |
|
148 | + $marge = $pu_ht_remise - $paht_ret; |
|
149 | + |
|
150 | + // calcul taux marge |
|
151 | + if ($paht_ret != 0) |
|
152 | + $marge_tx_ret = (100 * $marge) / $paht_ret; |
|
153 | + // calcul taux marque |
|
154 | + if ($pu_ht_remise != 0) |
|
155 | + $marque_tx_ret = (100 * $marge) / $pu_ht_remise; |
|
156 | + |
|
157 | + return array($paht_ret, $marge_tx_ret, $marque_tx_ret); |
|
158 | 158 | } |
@@ -46,24 +46,24 @@ discard block |
||
46 | 46 | if (! $sortorder) $sortorder="ASC"; |
47 | 47 | if (! $sortfield) |
48 | 48 | { |
49 | - if ($agentid > 0) |
|
50 | - $sortfield="s.nom"; |
|
51 | - else |
|
52 | - $sortfield="u.lastname"; |
|
49 | + if ($agentid > 0) |
|
50 | + $sortfield="s.nom"; |
|
51 | + else |
|
52 | + $sortfield="u.lastname"; |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | $startdate=$enddate=''; |
56 | 56 | |
57 | 57 | if (!empty($_POST['startdatemonth'])) |
58 | - $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
58 | + $startdate = dol_mktime(0, 0, 0, $_POST['startdatemonth'], $_POST['startdateday'], $_POST['startdateyear']); |
|
59 | 59 | if (!empty($_POST['enddatemonth'])) |
60 | - $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
60 | + $enddate = dol_mktime(23, 59, 59, $_POST['enddatemonth'], $_POST['enddateday'], $_POST['enddateyear']); |
|
61 | 61 | |
62 | 62 | // Security check |
63 | 63 | if ($user->rights->margins->read->all) { |
64 | - $agentid = GETPOST('agentid', 'int'); |
|
64 | + $agentid = GETPOST('agentid', 'int'); |
|
65 | 65 | } else { |
66 | - $agentid = $user->id; |
|
66 | + $agentid = $user->id; |
|
67 | 67 | } |
68 | 68 | $result=restrictedArea($user,'margins'); |
69 | 69 | |
@@ -143,22 +143,22 @@ discard block |
||
143 | 143 | $sql.= " AND sc.fk_soc = f.fk_soc"; |
144 | 144 | $sql.= " AND (d.product_type = 0 OR d.product_type = 1)"; |
145 | 145 | if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
146 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
|
146 | + $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = u.rowid) OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = u.rowid))"; |
|
147 | 147 | else |
148 | - $sql .= " AND sc.fk_user = u.rowid"; |
|
148 | + $sql .= " AND sc.fk_user = u.rowid"; |
|
149 | 149 | $sql.= " AND f.fk_statut > 0"; |
150 | 150 | $sql.= ' AND s.entity IN ('.getEntity('societe').')'; |
151 | 151 | $sql.= " AND d.fk_facture = f.rowid"; |
152 | 152 | if ($agentid > 0) { |
153 | - if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
154 | - $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
155 | - else |
|
156 | - $sql .= " AND sc.fk_user = ".$agentid; |
|
153 | + if (! empty($conf->global->AGENT_CONTACT_TYPE)) |
|
154 | + $sql.= " AND ((e.fk_socpeople IS NULL AND sc.fk_user = ".$agentid.") OR (e.fk_socpeople IS NOT NULL AND e.fk_socpeople = ".$agentid."))"; |
|
155 | + else |
|
156 | + $sql .= " AND sc.fk_user = ".$agentid; |
|
157 | 157 | } |
158 | 158 | if (!empty($startdate)) |
159 | - $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
159 | + $sql.= " AND f.datef >= '".$db->idate($startdate)."'"; |
|
160 | 160 | if (!empty($enddate)) |
161 | - $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
161 | + $sql.= " AND f.datef <= '".$db->idate($enddate)."'"; |
|
162 | 162 | $sql .= " AND d.buy_price_ht IS NOT NULL"; |
163 | 163 | if (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1) $sql .= " AND d.buy_price_ht <> 0"; |
164 | 164 | if ($agentid > 0) $sql.= " GROUP BY s.rowid, s.nom, s.code_client, s.client, u.rowid, u.login, u.lastname, u.firstname"; |
@@ -176,87 +176,87 @@ discard block |
||
176 | 176 | $result = $db->query($sql); |
177 | 177 | if ($result) |
178 | 178 | { |
179 | - $num = $db->num_rows($result); |
|
180 | - |
|
181 | - print '<br>'; |
|
182 | - print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
183 | - |
|
184 | - if ($conf->global->MARGIN_TYPE == "1") |
|
185 | - $labelcostprice='BuyingPrice'; |
|
186 | - else // value is 'costprice' or 'pmp' |
|
187 | - $labelcostprice='CostPrice'; |
|
188 | - |
|
189 | - $i = 0; |
|
190 | - print "<table class=\"noborder\" width=\"100%\">"; |
|
191 | - |
|
192 | - print '<tr class="liste_titre">'; |
|
193 | - if ($agentid > 0) |
|
194 | - print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
195 | - else |
|
196 | - print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
197 | - |
|
198 | - print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
199 | - print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
200 | - print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
201 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
202 | - print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
203 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
204 | - print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
205 | - print "</tr>\n"; |
|
206 | - |
|
207 | - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
208 | - |
|
209 | - if ($num > 0) |
|
210 | - { |
|
211 | - |
|
212 | - while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
213 | - { |
|
214 | - $objp = $db->fetch_object($result); |
|
215 | - |
|
216 | - $pa = $objp->buying_price; |
|
217 | - $pv = $objp->selling_price; |
|
218 | - $marge = $objp->marge; |
|
219 | - |
|
220 | - if ($marge < 0) |
|
221 | - { |
|
222 | - $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
223 | - $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
224 | - } |
|
225 | - else |
|
226 | - { |
|
227 | - $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
228 | - $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
229 | - } |
|
230 | - |
|
231 | - print '<tr class="oddeven">'; |
|
232 | - if ($agentid > 0) { |
|
233 | - $companystatic->id=$objp->socid; |
|
234 | - $companystatic->name=$objp->name; |
|
235 | - $companystatic->client=$objp->client; |
|
236 | - print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n"; |
|
237 | - } |
|
238 | - else { |
|
239 | - $userstatic->fetch($objp->agent); |
|
240 | - print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n"; |
|
241 | - } |
|
242 | - |
|
243 | - print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
244 | - print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
245 | - print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
246 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
247 | - print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
248 | - if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
249 | - print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
250 | - print "</tr>\n"; |
|
251 | - |
|
252 | - $i++; |
|
253 | - } |
|
254 | - } |
|
255 | - print "</table>"; |
|
179 | + $num = $db->num_rows($result); |
|
180 | + |
|
181 | + print '<br>'; |
|
182 | + print_barre_liste($langs->trans("MarginDetails"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num, $num, '', 0, '', '', 0, 1); |
|
183 | + |
|
184 | + if ($conf->global->MARGIN_TYPE == "1") |
|
185 | + $labelcostprice='BuyingPrice'; |
|
186 | + else // value is 'costprice' or 'pmp' |
|
187 | + $labelcostprice='CostPrice'; |
|
188 | + |
|
189 | + $i = 0; |
|
190 | + print "<table class=\"noborder\" width=\"100%\">"; |
|
191 | + |
|
192 | + print '<tr class="liste_titre">'; |
|
193 | + if ($agentid > 0) |
|
194 | + print_liste_field_titre("Customer",$_SERVER["PHP_SELF"],"s.nom","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
195 | + else |
|
196 | + print_liste_field_titre("SalesRepresentative",$_SERVER["PHP_SELF"],"u.lastname","","&agentid=".$agentid,'',$sortfield,$sortorder); |
|
197 | + |
|
198 | + print_liste_field_titre("SellingPrice",$_SERVER["PHP_SELF"],"selling_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
199 | + print_liste_field_titre($labelcostprice,$_SERVER["PHP_SELF"],"buying_price","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
200 | + print_liste_field_titre("Margin",$_SERVER["PHP_SELF"],"marge","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
201 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
202 | + print_liste_field_titre("MarginRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
203 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
204 | + print_liste_field_titre("MarkRate",$_SERVER["PHP_SELF"],"","","&agentid=".$agentid,'align="right"',$sortfield,$sortorder); |
|
205 | + print "</tr>\n"; |
|
206 | + |
|
207 | + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT,$conf->global->MAIN_MAX_DECIMALS_TOT); |
|
208 | + |
|
209 | + if ($num > 0) |
|
210 | + { |
|
211 | + |
|
212 | + while ($i < $num /*&& $i < $conf->liste_limit*/) |
|
213 | + { |
|
214 | + $objp = $db->fetch_object($result); |
|
215 | + |
|
216 | + $pa = $objp->buying_price; |
|
217 | + $pv = $objp->selling_price; |
|
218 | + $marge = $objp->marge; |
|
219 | + |
|
220 | + if ($marge < 0) |
|
221 | + { |
|
222 | + $marginRate = ($pa != 0)?-1*(100 * $marge / $pa):'' ; |
|
223 | + $markRate = ($pv != 0)?-1*(100 * $marge / $pv):'' ; |
|
224 | + } |
|
225 | + else |
|
226 | + { |
|
227 | + $marginRate = ($pa != 0)?(100 * $marge / $pa):'' ; |
|
228 | + $markRate = ($pv != 0)?(100 * $marge / $pv):'' ; |
|
229 | + } |
|
230 | + |
|
231 | + print '<tr class="oddeven">'; |
|
232 | + if ($agentid > 0) { |
|
233 | + $companystatic->id=$objp->socid; |
|
234 | + $companystatic->name=$objp->name; |
|
235 | + $companystatic->client=$objp->client; |
|
236 | + print "<td>".$companystatic->getNomUrl(1,'customer')."</td>\n"; |
|
237 | + } |
|
238 | + else { |
|
239 | + $userstatic->fetch($objp->agent); |
|
240 | + print "<td>".$userstatic->getFullName($langs,0,0,0)."</td>\n"; |
|
241 | + } |
|
242 | + |
|
243 | + print "<td align=\"right\">".price($pv, null, null, null, null, $rounding)."</td>\n"; |
|
244 | + print "<td align=\"right\">".price($pa, null, null, null, null, $rounding)."</td>\n"; |
|
245 | + print "<td align=\"right\">".price($marge, null, null, null, null, $rounding)."</td>\n"; |
|
246 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) |
|
247 | + print "<td align=\"right\">".(($marginRate === '')?'n/a':price($marginRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
248 | + if (! empty($conf->global->DISPLAY_MARK_RATES)) |
|
249 | + print "<td align=\"right\">".(($markRate === '')?'n/a':price($markRate, null, null, null, null, $rounding)."%")."</td>\n"; |
|
250 | + print "</tr>\n"; |
|
251 | + |
|
252 | + $i++; |
|
253 | + } |
|
254 | + } |
|
255 | + print "</table>"; |
|
256 | 256 | } |
257 | 257 | else |
258 | 258 | { |
259 | - dol_print_error($db); |
|
259 | + dol_print_error($db); |
|
260 | 260 | } |
261 | 261 | $db->free($result); |
262 | 262 |