@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | abstract class CommonDocGenerator |
| 35 | 35 | { |
| 36 | - var $error=''; |
|
| 36 | + var $error = ''; |
|
| 37 | 37 | protected $db; |
| 38 | 38 | |
| 39 | 39 | |
@@ -55,16 +55,16 @@ discard block |
||
| 55 | 55 | * @param Translate $outputlangs Language object for output |
| 56 | 56 | * @return array Array of substitution key->code |
| 57 | 57 | */ |
| 58 | - function get_substitutionarray_user($user,$outputlangs) |
|
| 58 | + function get_substitutionarray_user($user, $outputlangs) |
|
| 59 | 59 | { |
| 60 | 60 | global $conf; |
| 61 | 61 | |
| 62 | - $logotouse=$conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo; |
|
| 62 | + $logotouse = $conf->user->dir_output.'/'.get_exdir($user->id, 2, 0, 1, $user, 'user').'/'.$user->photo; |
|
| 63 | 63 | |
| 64 | 64 | return array( |
| 65 | 65 | 'myuser_lastname'=>$user->lastname, |
| 66 | 66 | 'myuser_firstname'=>$user->firstname, |
| 67 | - 'myuser_fullname'=>$user->getFullName($outputlangs,1), |
|
| 67 | + 'myuser_fullname'=>$user->getFullName($outputlangs, 1), |
|
| 68 | 68 | 'myuser_login'=>$user->login, |
| 69 | 69 | 'myuser_phone'=>$user->office_phone, |
| 70 | 70 | 'myuser_address'=>$user->address, |
@@ -91,24 +91,24 @@ discard block |
||
| 91 | 91 | * @param Translate $outputlangs Language object for output |
| 92 | 92 | * @return array Array of substitution key->code |
| 93 | 93 | */ |
| 94 | - function get_substitutionarray_mysoc($mysoc,$outputlangs) |
|
| 94 | + function get_substitutionarray_mysoc($mysoc, $outputlangs) |
|
| 95 | 95 | { |
| 96 | 96 | global $conf; |
| 97 | 97 | |
| 98 | - if (empty($mysoc->forme_juridique) && ! empty($mysoc->forme_juridique_code)) |
|
| 98 | + if (empty($mysoc->forme_juridique) && !empty($mysoc->forme_juridique_code)) |
|
| 99 | 99 | { |
| 100 | - $mysoc->forme_juridique=getFormeJuridiqueLabel($mysoc->forme_juridique_code); |
|
| 100 | + $mysoc->forme_juridique = getFormeJuridiqueLabel($mysoc->forme_juridique_code); |
|
| 101 | 101 | } |
| 102 | - if (empty($mysoc->country) && ! empty($mysoc->country_code)) |
|
| 102 | + if (empty($mysoc->country) && !empty($mysoc->country_code)) |
|
| 103 | 103 | { |
| 104 | - $mysoc->country=$outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code); |
|
| 104 | + $mysoc->country = $outputlangs->transnoentitiesnoconv("Country".$mysoc->country_code); |
|
| 105 | 105 | } |
| 106 | - if (empty($mysoc->state) && ! empty($mysoc->state_code)) |
|
| 106 | + if (empty($mysoc->state) && !empty($mysoc->state_code)) |
|
| 107 | 107 | { |
| 108 | - $mysoc->state=getState($mysoc->state_code,0); |
|
| 108 | + $mysoc->state = getState($mysoc->state_code, 0); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $logotouse=$conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; |
|
| 111 | + $logotouse = $conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small; |
|
| 112 | 112 | |
| 113 | 113 | return array( |
| 114 | 114 | 'mycompany_logo'=>$logotouse, |
@@ -149,17 +149,17 @@ discard block |
||
| 149 | 149 | * @param Translate $outputlangs Language object for output |
| 150 | 150 | * @return array Array of substitution key->code |
| 151 | 151 | */ |
| 152 | - function get_substitutionarray_thirdparty($object,$outputlangs) |
|
| 152 | + function get_substitutionarray_thirdparty($object, $outputlangs) |
|
| 153 | 153 | { |
| 154 | 154 | global $conf; |
| 155 | 155 | |
| 156 | - if (empty($object->country) && ! empty($object->country_code)) |
|
| 156 | + if (empty($object->country) && !empty($object->country_code)) |
|
| 157 | 157 | { |
| 158 | - $object->country=$outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 158 | + $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 159 | 159 | } |
| 160 | - if (empty($object->state) && ! empty($object->state_code)) |
|
| 160 | + if (empty($object->state) && !empty($object->state_code)) |
|
| 161 | 161 | { |
| 162 | - $object->state=getState($object->state_code,0); |
|
| 162 | + $object->state = getState($object->state_code, 0); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | $array_thirdparty = array( |
@@ -198,24 +198,24 @@ discard block |
||
| 198 | 198 | ); |
| 199 | 199 | |
| 200 | 200 | // Retrieve extrafields |
| 201 | - if(is_array($object->array_options) && count($object->array_options)) |
|
| 201 | + if (is_array($object->array_options) && count($object->array_options)) |
|
| 202 | 202 | { |
| 203 | 203 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 204 | 204 | $extrafields = new ExtraFields($this->db); |
| 205 | - $extralabels = $extrafields->fetch_name_optionals_label('societe',true); |
|
| 205 | + $extralabels = $extrafields->fetch_name_optionals_label('societe', true); |
|
| 206 | 206 | $object->fetch_optionals(); |
| 207 | 207 | |
| 208 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 208 | + foreach ($extrafields->attribute_label as $key=>$label) |
|
| 209 | 209 | { |
| 210 | - if($extrafields->attribute_type[$key] == 'price') |
|
| 210 | + if ($extrafields->attribute_type[$key] == 'price') |
|
| 211 | 211 | { |
| 212 | - $object->array_options['options_'.$key] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 212 | + $object->array_options['options_'.$key] = price($object->array_options['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency); |
|
| 213 | 213 | } |
| 214 | - else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 214 | + else if ($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 215 | 215 | { |
| 216 | 216 | $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
| 217 | 217 | } |
| 218 | - $array_thirdparty = array_merge($array_thirdparty, array ('company_options_'.$key => $object->array_options ['options_' . $key])); |
|
| 218 | + $array_thirdparty = array_merge($array_thirdparty, array('company_options_'.$key => $object->array_options ['options_'.$key])); |
|
| 219 | 219 | } |
| 220 | 220 | } |
| 221 | 221 | return $array_thirdparty; |
@@ -232,61 +232,61 @@ discard block |
||
| 232 | 232 | function get_substitutionarray_contact($object, $outputlangs, $array_key = 'object') { |
| 233 | 233 | global $conf; |
| 234 | 234 | |
| 235 | - if(empty($object->country) && ! empty($object->country_code)) |
|
| 235 | + if (empty($object->country) && !empty($object->country_code)) |
|
| 236 | 236 | { |
| 237 | - $object->country = $outputlangs->transnoentitiesnoconv("Country" . $object->country_code); |
|
| 237 | + $object->country = $outputlangs->transnoentitiesnoconv("Country".$object->country_code); |
|
| 238 | 238 | } |
| 239 | - if(empty($object->state) && ! empty($object->state_code)) |
|
| 239 | + if (empty($object->state) && !empty($object->state_code)) |
|
| 240 | 240 | { |
| 241 | 241 | $object->state = getState($object->state_code, 0); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - $array_contact = array ( |
|
| 245 | - $array_key . '_fullname' => $object->getFullName($outputlangs, 1), |
|
| 246 | - $array_key . '_lastname' => $object->lastname, |
|
| 247 | - $array_key . '_firstname' => $object->firstname, |
|
| 248 | - $array_key . '_address' => $object->address, |
|
| 249 | - $array_key . '_zip' => $object->zip, |
|
| 250 | - $array_key . '_town' => $object->town, |
|
| 251 | - $array_key . '_state_id' => $object->state_id, |
|
| 252 | - $array_key . '_state_code' => $object->state_code, |
|
| 253 | - $array_key . '_state' => $object->state, |
|
| 254 | - $array_key . '_country_id' => $object->country_id, |
|
| 255 | - $array_key . '_country_code' => $object->country_code, |
|
| 256 | - $array_key . '_country' => $object->country, |
|
| 257 | - $array_key . '_poste' => $object->poste, |
|
| 258 | - $array_key . '_socid' => $object->socid, |
|
| 259 | - $array_key . '_statut' => $object->statut, |
|
| 260 | - $array_key . '_code' => $object->code, |
|
| 261 | - $array_key . '_email' => $object->email, |
|
| 262 | - $array_key . '_jabberid' => $object->jabberid, |
|
| 263 | - $array_key . '_phone_pro' => $object->phone_pro, |
|
| 264 | - $array_key . '_phone_perso' => $object->phone_perso, |
|
| 265 | - $array_key . '_phone_mobile' => $object->phone_mobile, |
|
| 266 | - $array_key . '_fax' => $object->fax, |
|
| 267 | - $array_key . '_birthday' => $object->birthday, |
|
| 268 | - $array_key . '_default_lang' => $object->default_lang, |
|
| 269 | - $array_key . '_note_public' => $object->note_public, |
|
| 270 | - $array_key . '_note_private' => $object->note_private |
|
| 244 | + $array_contact = array( |
|
| 245 | + $array_key.'_fullname' => $object->getFullName($outputlangs, 1), |
|
| 246 | + $array_key.'_lastname' => $object->lastname, |
|
| 247 | + $array_key.'_firstname' => $object->firstname, |
|
| 248 | + $array_key.'_address' => $object->address, |
|
| 249 | + $array_key.'_zip' => $object->zip, |
|
| 250 | + $array_key.'_town' => $object->town, |
|
| 251 | + $array_key.'_state_id' => $object->state_id, |
|
| 252 | + $array_key.'_state_code' => $object->state_code, |
|
| 253 | + $array_key.'_state' => $object->state, |
|
| 254 | + $array_key.'_country_id' => $object->country_id, |
|
| 255 | + $array_key.'_country_code' => $object->country_code, |
|
| 256 | + $array_key.'_country' => $object->country, |
|
| 257 | + $array_key.'_poste' => $object->poste, |
|
| 258 | + $array_key.'_socid' => $object->socid, |
|
| 259 | + $array_key.'_statut' => $object->statut, |
|
| 260 | + $array_key.'_code' => $object->code, |
|
| 261 | + $array_key.'_email' => $object->email, |
|
| 262 | + $array_key.'_jabberid' => $object->jabberid, |
|
| 263 | + $array_key.'_phone_pro' => $object->phone_pro, |
|
| 264 | + $array_key.'_phone_perso' => $object->phone_perso, |
|
| 265 | + $array_key.'_phone_mobile' => $object->phone_mobile, |
|
| 266 | + $array_key.'_fax' => $object->fax, |
|
| 267 | + $array_key.'_birthday' => $object->birthday, |
|
| 268 | + $array_key.'_default_lang' => $object->default_lang, |
|
| 269 | + $array_key.'_note_public' => $object->note_public, |
|
| 270 | + $array_key.'_note_private' => $object->note_private |
|
| 271 | 271 | ); |
| 272 | 272 | |
| 273 | 273 | // Retrieve extrafields |
| 274 | - require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; |
|
| 274 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 275 | 275 | $extrafields = new ExtraFields($this->db); |
| 276 | 276 | $extralabels = $extrafields->fetch_name_optionals_label('socpeople', true); |
| 277 | 277 | $object->fetch_optionals(); |
| 278 | 278 | |
| 279 | - foreach($extrafields->attribute_label as $key => $label) |
|
| 279 | + foreach ($extrafields->attribute_label as $key => $label) |
|
| 280 | 280 | { |
| 281 | 281 | if ($extrafields->attribute_type[$key] == 'price') |
| 282 | 282 | { |
| 283 | - $object->array_options['options_' . $key] = price($object->array_options ['options_' . $key], 0, $outputlangs, 0, 0, - 1, $conf->currency); |
|
| 283 | + $object->array_options['options_'.$key] = price($object->array_options ['options_'.$key], 0, $outputlangs, 0, 0, - 1, $conf->currency); |
|
| 284 | 284 | } |
| 285 | - elseif($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 285 | + elseif ($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 286 | 286 | { |
| 287 | - $object->array_options['options_' . $key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_' . $key]]; |
|
| 287 | + $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
|
| 288 | 288 | } |
| 289 | - $array_contact = array_merge($array_contact, array($array_key.'_options_' . $key => $object->array_options['options_'. $key])); |
|
| 289 | + $array_contact = array_merge($array_contact, array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 290 | 290 | } |
| 291 | 291 | return $array_contact; |
| 292 | 292 | } |
@@ -302,22 +302,22 @@ discard block |
||
| 302 | 302 | { |
| 303 | 303 | global $conf; |
| 304 | 304 | |
| 305 | - $now=dol_now('gmt'); // gmt |
|
| 305 | + $now = dol_now('gmt'); // gmt |
|
| 306 | 306 | $array_other = array( |
| 307 | 307 | // Date in default language |
| 308 | - 'current_date'=>dol_print_date($now,'day','tzuser'), |
|
| 309 | - 'current_datehour'=>dol_print_date($now,'dayhour','tzuser'), |
|
| 310 | - 'current_server_date'=>dol_print_date($now,'day','tzserver'), |
|
| 311 | - 'current_server_datehour'=>dol_print_date($now,'dayhour','tzserver'), |
|
| 308 | + 'current_date'=>dol_print_date($now, 'day', 'tzuser'), |
|
| 309 | + 'current_datehour'=>dol_print_date($now, 'dayhour', 'tzuser'), |
|
| 310 | + 'current_server_date'=>dol_print_date($now, 'day', 'tzserver'), |
|
| 311 | + 'current_server_datehour'=>dol_print_date($now, 'dayhour', 'tzserver'), |
|
| 312 | 312 | // Date in requested output language |
| 313 | - 'current_date_locale'=>dol_print_date($now,'day','tzuser',$outputlangs), |
|
| 314 | - 'current_datehour_locale'=>dol_print_date($now,'dayhour','tzuser',$outputlangs), |
|
| 315 | - 'current_server_date_locale'=>dol_print_date($now,'day','tzserver',$outputlangs), |
|
| 316 | - 'current_server_datehour_locale'=>dol_print_date($now,'dayhour','tzserver',$outputlangs), |
|
| 313 | + 'current_date_locale'=>dol_print_date($now, 'day', 'tzuser', $outputlangs), |
|
| 314 | + 'current_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzuser', $outputlangs), |
|
| 315 | + 'current_server_date_locale'=>dol_print_date($now, 'day', 'tzserver', $outputlangs), |
|
| 316 | + 'current_server_datehour_locale'=>dol_print_date($now, 'dayhour', 'tzserver', $outputlangs), |
|
| 317 | 317 | ); |
| 318 | 318 | |
| 319 | 319 | |
| 320 | - foreach($conf->global as $key => $val) |
|
| 320 | + foreach ($conf->global as $key => $val) |
|
| 321 | 321 | { |
| 322 | 322 | if (preg_match('/(_pass|password|secret|_key|key$)/i', $keyfound)) $newval = '*****forbidden*****'; |
| 323 | 323 | else $newval = $val; |
@@ -336,14 +336,14 @@ discard block |
||
| 336 | 336 | * @param string $array_key Name of the key for return array |
| 337 | 337 | * @return array Array of substitution |
| 338 | 338 | */ |
| 339 | - function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 339 | + function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') |
|
| 340 | 340 | { |
| 341 | 341 | global $conf; |
| 342 | 342 | |
| 343 | - $sumpayed=$sumdeposit=$sumcreditnote=''; |
|
| 343 | + $sumpayed = $sumdeposit = $sumcreditnote = ''; |
|
| 344 | 344 | if ($object->element == 'facture') |
| 345 | 345 | { |
| 346 | - $invoice_source=new Facture($this->db); |
|
| 346 | + $invoice_source = new Facture($this->db); |
|
| 347 | 347 | if ($object->fk_facture_source > 0) |
| 348 | 348 | { |
| 349 | 349 | $invoice_source->fetch($object->fk_facture_source); |
@@ -355,38 +355,38 @@ discard block |
||
| 355 | 355 | |
| 356 | 356 | $date = ($object->element == 'contrat' ? $object->date_contrat : $object->date); |
| 357 | 357 | |
| 358 | - $resarray=array( |
|
| 358 | + $resarray = array( |
|
| 359 | 359 | $array_key.'_id'=>$object->id, |
| 360 | 360 | $array_key.'_ref'=>$object->ref, |
| 361 | 361 | $array_key.'_ref_ext'=>$object->ref_ext, |
| 362 | - $array_key.'_ref_customer'=>(! empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), |
|
| 363 | - $array_key.'_ref_supplier'=>(! empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), |
|
| 362 | + $array_key.'_ref_customer'=>(!empty($object->ref_client) ? $object->ref_client : (empty($object->ref_customer) ? '' : $object->ref_customer)), |
|
| 363 | + $array_key.'_ref_supplier'=>(!empty($object->ref_fournisseur) ? $object->ref_fournisseur : (empty($object->ref_supplier) ? '' : $object->ref_supplier)), |
|
| 364 | 364 | $array_key.'_source_invoice_ref'=>$invoice_source->ref, |
| 365 | 365 | // Dates |
| 366 | - $array_key.'_hour'=>dol_print_date($date,'hour'), |
|
| 367 | - $array_key.'_date'=>dol_print_date($date,'day'), |
|
| 368 | - $array_key.'_date_rfc'=>dol_print_date($date,'dayrfc'), |
|
| 369 | - $array_key.'_date_limit'=>(! empty($object->date_lim_reglement)?dol_print_date($object->date_lim_reglement,'day'):''), |
|
| 370 | - $array_key.'_date_end'=>(! empty($object->fin_validite)?dol_print_date($object->fin_validite,'day'):''), |
|
| 371 | - $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 372 | - $array_key.'_date_modification'=>(! empty($object->date_modification)?dol_print_date($object->date_modification,'day'):''), |
|
| 373 | - $array_key.'_date_validation'=>(! empty($object->date_validation)?dol_print_date($object->date_validation,'dayhour'):''), |
|
| 374 | - $array_key.'_date_delivery_planed'=>(! empty($object->date_livraison)?dol_print_date($object->date_livraison,'day'):''), |
|
| 375 | - $array_key.'_date_close'=>(! empty($object->date_cloture)?dol_print_date($object->date_cloture,'dayhour'):''), |
|
| 366 | + $array_key.'_hour'=>dol_print_date($date, 'hour'), |
|
| 367 | + $array_key.'_date'=>dol_print_date($date, 'day'), |
|
| 368 | + $array_key.'_date_rfc'=>dol_print_date($date, 'dayrfc'), |
|
| 369 | + $array_key.'_date_limit'=>(!empty($object->date_lim_reglement) ?dol_print_date($object->date_lim_reglement, 'day') : ''), |
|
| 370 | + $array_key.'_date_end'=>(!empty($object->fin_validite) ?dol_print_date($object->fin_validite, 'day') : ''), |
|
| 371 | + $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'), |
|
| 372 | + $array_key.'_date_modification'=>(!empty($object->date_modification) ?dol_print_date($object->date_modification, 'day') : ''), |
|
| 373 | + $array_key.'_date_validation'=>(!empty($object->date_validation) ?dol_print_date($object->date_validation, 'dayhour') : ''), |
|
| 374 | + $array_key.'_date_delivery_planed'=>(!empty($object->date_livraison) ?dol_print_date($object->date_livraison, 'day') : ''), |
|
| 375 | + $array_key.'_date_close'=>(!empty($object->date_cloture) ?dol_print_date($object->date_cloture, 'dayhour') : ''), |
|
| 376 | 376 | |
| 377 | 377 | $array_key.'_payment_mode_code'=>$object->mode_reglement_code, |
| 378 | - $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement), |
|
| 378 | + $array_key.'_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code) != 'PaymentType'.$object->mode_reglement_code ? $outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code) : $object->mode_reglement), |
|
| 379 | 379 | $array_key.'_payment_term_code'=>$object->cond_reglement_code, |
| 380 | - $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement), |
|
| 380 | + $array_key.'_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code) != 'PaymentCondition'.$object->cond_reglement_code ? $outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code) : $object->cond_reglement), |
|
| 381 | 381 | |
| 382 | 382 | $array_key.'_total_ht_locale'=>price($object->total_ht, 0, $outputlangs), |
| 383 | - $array_key.'_total_vat_locale'=>(! empty($object->total_vat)?price($object->total_vat, 0, $outputlangs):price($object->total_tva, 0, $outputlangs)), |
|
| 383 | + $array_key.'_total_vat_locale'=>(!empty($object->total_vat) ?price($object->total_vat, 0, $outputlangs) : price($object->total_tva, 0, $outputlangs)), |
|
| 384 | 384 | $array_key.'_total_localtax1_locale'=>price($object->total_localtax1, 0, $outputlangs), |
| 385 | 385 | $array_key.'_total_localtax2_locale'=>price($object->total_localtax2, 0, $outputlangs), |
| 386 | 386 | $array_key.'_total_ttc_locale'=>price($object->total_ttc, 0, $outputlangs), |
| 387 | 387 | |
| 388 | 388 | $array_key.'_total_ht'=>price2num($object->total_ht), |
| 389 | - $array_key.'_total_vat'=>(! empty($object->total_vat)?price2num($object->total_vat):price2num($object->total_tva)), |
|
| 389 | + $array_key.'_total_vat'=>(!empty($object->total_vat) ?price2num($object->total_vat) : price2num($object->total_tva)), |
|
| 390 | 390 | $array_key.'_total_localtax1'=>price2num($object->total_localtax1), |
| 391 | 391 | $array_key.'_total_localtax2'=>price2num($object->total_localtax2), |
| 392 | 392 | $array_key.'_total_ttc'=>price2num($object->total_ttc), |
@@ -402,7 +402,7 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | $array_key.'_note_private'=>$object->note, |
| 404 | 404 | $array_key.'_note_public'=>$object->note_public, |
| 405 | - $array_key.'_note'=>$object->note_public, // For backward compatibility |
|
| 405 | + $array_key.'_note'=>$object->note_public, // For backward compatibility |
|
| 406 | 406 | |
| 407 | 407 | // Payments |
| 408 | 408 | $array_key.'_already_payed_locale'=>price($sumpayed, 0, $outputlangs), |
@@ -429,9 +429,9 @@ discard block |
||
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | // Fetch project information if there is a project assigned to this object |
| 432 | - if ($object->element != "project" && ! empty($object->fk_project) && $object->fk_project > 0) |
|
| 432 | + if ($object->element != "project" && !empty($object->fk_project) && $object->fk_project > 0) |
|
| 433 | 433 | { |
| 434 | - if (! is_object($object->project)) |
|
| 434 | + if (!is_object($object->project)) |
|
| 435 | 435 | { |
| 436 | 436 | $object->fetch_projet(); |
| 437 | 437 | } |
@@ -444,32 +444,32 @@ discard block |
||
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | // Add vat by rates |
| 447 | - if (is_array($object->lines) && count($object->lines)>0) |
|
| 447 | + if (is_array($object->lines) && count($object->lines) > 0) |
|
| 448 | 448 | { |
| 449 | 449 | foreach ($object->lines as $line) |
| 450 | 450 | { |
| 451 | 451 | // $line->tva_tx format depends on database field accuraty, no reliable. This is kept for backward comaptibility |
| 452 | - if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 453 | - $resarray[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 454 | - $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx]=price($resarray[$array_key.'_total_vat_'.$line->tva_tx]); |
|
| 452 | + if (empty($resarray[$array_key.'_total_vat_'.$line->tva_tx])) $resarray[$array_key.'_total_vat_'.$line->tva_tx] = 0; |
|
| 453 | + $resarray[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva; |
|
| 454 | + $resarray[$array_key.'_total_vat_locale_'.$line->tva_tx] = price($resarray[$array_key.'_total_vat_'.$line->tva_tx]); |
|
| 455 | 455 | // $vatformated is vat without not expected chars (so 20, or 8.5 or 5.99 for example) |
| 456 | - $vatformated=vatrate($line->tva_tx); |
|
| 457 | - if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated]=0; |
|
| 458 | - $resarray[$array_key.'_total_vat_'.$vatformated]+=$line->total_tva; |
|
| 459 | - $resarray[$array_key.'_total_vat_locale_'.$vatformated]=price($resarray[$array_key.'_total_vat_'.$vatformated]); |
|
| 456 | + $vatformated = vatrate($line->tva_tx); |
|
| 457 | + if (empty($resarray[$array_key.'_total_vat_'.$vatformated])) $resarray[$array_key.'_total_vat_'.$vatformated] = 0; |
|
| 458 | + $resarray[$array_key.'_total_vat_'.$vatformated] += $line->total_tva; |
|
| 459 | + $resarray[$array_key.'_total_vat_locale_'.$vatformated] = price($resarray[$array_key.'_total_vat_'.$vatformated]); |
|
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | 462 | // Retrieve extrafields |
| 463 | 463 | if (is_array($object->array_options) && count($object->array_options)) |
| 464 | 464 | { |
| 465 | - $extrafieldkey=$object->element; |
|
| 465 | + $extrafieldkey = $object->element; |
|
| 466 | 466 | |
| 467 | 467 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 468 | 468 | $extrafields = new ExtraFields($this->db); |
| 469 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 469 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); |
|
| 470 | 470 | $object->fetch_optionals(); |
| 471 | 471 | |
| 472 | - $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 472 | + $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); |
|
| 473 | 473 | } |
| 474 | 474 | return $resarray; |
| 475 | 475 | } |
@@ -481,21 +481,21 @@ discard block |
||
| 481 | 481 | * @param Translate $outputlangs Lang object to use for output |
| 482 | 482 | * @return array Return a substitution array |
| 483 | 483 | */ |
| 484 | - function get_substitutionarray_lines($line,$outputlangs) |
|
| 484 | + function get_substitutionarray_lines($line, $outputlangs) |
|
| 485 | 485 | { |
| 486 | 486 | global $conf; |
| 487 | 487 | |
| 488 | - $resarray= array( |
|
| 489 | - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 488 | + $resarray = array( |
|
| 489 | + 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs), |
|
| 490 | 490 | 'line_product_ref'=>$line->product_ref, |
| 491 | 491 | 'line_product_label'=>$line->product_label, |
| 492 | 492 | 'line_product_type'=>$line->product_type, |
| 493 | 493 | 'line_desc'=>$line->desc, |
| 494 | - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 494 | + 'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits), |
|
| 495 | 495 | 'line_up'=>price2num($line->subprice), |
| 496 | 496 | 'line_up_locale'=>price($line->subprice, 0, $outputlangs), |
| 497 | 497 | 'line_qty'=>$line->qty, |
| 498 | - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 498 | + 'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''), |
|
| 499 | 499 | 'line_price_ht'=>price2num($line->total_ht), |
| 500 | 500 | 'line_price_ttc'=>price2num($line->total_ttc), |
| 501 | 501 | 'line_price_vat'=>price2num($line->total_tva), |
@@ -524,26 +524,26 @@ discard block |
||
| 524 | 524 | // Units |
| 525 | 525 | if ($conf->global->PRODUCT_USE_UNITS) |
| 526 | 526 | { |
| 527 | - $resarray['line_unit']=$outputlangs->trans($line->getLabelOfUnit('long')); |
|
| 528 | - $resarray['line_unit_short']=$outputlangs->trans($line->getLabelOfUnit('short')); |
|
| 527 | + $resarray['line_unit'] = $outputlangs->trans($line->getLabelOfUnit('long')); |
|
| 528 | + $resarray['line_unit_short'] = $outputlangs->trans($line->getLabelOfUnit('short')); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | // Retrieve extrafields |
| 532 | - $extrafieldkey=$line->element; |
|
| 533 | - $array_key="line"; |
|
| 532 | + $extrafieldkey = $line->element; |
|
| 533 | + $array_key = "line"; |
|
| 534 | 534 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 535 | 535 | $extrafields = new ExtraFields($this->db); |
| 536 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 536 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); |
|
| 537 | 537 | $line->fetch_optionals(); |
| 538 | 538 | |
| 539 | - $resarray = $this->fill_substitutionarray_with_extrafields($line,$resarray,$extrafields,$array_key=$array_key,$outputlangs); |
|
| 539 | + $resarray = $this->fill_substitutionarray_with_extrafields($line, $resarray, $extrafields, $array_key = $array_key, $outputlangs); |
|
| 540 | 540 | |
| 541 | 541 | // Load product data optional fields to the line -> enables to use "line_options_{extrafield}" |
| 542 | 542 | if (isset($line->fk_product) && $line->fk_product > 0) |
| 543 | 543 | { |
| 544 | 544 | $tmpproduct = new Product($this->db); |
| 545 | 545 | $result = $tmpproduct->fetch($line->fk_product); |
| 546 | - foreach($tmpproduct->array_options as $key=>$label) |
|
| 546 | + foreach ($tmpproduct->array_options as $key=>$label) |
|
| 547 | 547 | $resarray["line_".$key] = $label; |
| 548 | 548 | } |
| 549 | 549 | |
@@ -558,21 +558,21 @@ discard block |
||
| 558 | 558 | * @param array_key $array_key Name of the key for return array |
| 559 | 559 | * @return array Array of substitution |
| 560 | 560 | */ |
| 561 | - function get_substitutionarray_shipment($object,$outputlangs,$array_key='object') |
|
| 561 | + function get_substitutionarray_shipment($object, $outputlangs, $array_key = 'object') |
|
| 562 | 562 | { |
| 563 | 563 | global $conf; |
| 564 | 564 | dol_include_once('/core/lib/product.lib.php'); |
| 565 | 565 | $object->list_delivery_methods($object->shipping_method_id); |
| 566 | - $calculatedVolume=($object->trueWidth * $object->trueHeight * $object->trueDepth); |
|
| 566 | + $calculatedVolume = ($object->trueWidth * $object->trueHeight * $object->trueDepth); |
|
| 567 | 567 | |
| 568 | - $array_shipment=array( |
|
| 568 | + $array_shipment = array( |
|
| 569 | 569 | $array_key.'_id'=>$object->id, |
| 570 | 570 | $array_key.'_ref'=>$object->ref, |
| 571 | 571 | $array_key.'_ref_ext'=>$object->ref_ext, |
| 572 | 572 | $array_key.'_ref_customer'=>$object->ref_customer, |
| 573 | - $array_key.'_date_delivery'=>dol_print_date($object->date_delivery,'day'), |
|
| 574 | - $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery,'hour'), |
|
| 575 | - $array_key.'_date_creation'=>dol_print_date($object->date_creation,'day'), |
|
| 573 | + $array_key.'_date_delivery'=>dol_print_date($object->date_delivery, 'day'), |
|
| 574 | + $array_key.'_hour_delivery'=>dol_print_date($object->date_delivery, 'hour'), |
|
| 575 | + $array_key.'_date_creation'=>dol_print_date($object->date_creation, 'day'), |
|
| 576 | 576 | $array_key.'_total_ht'=>price($object->total_ht), |
| 577 | 577 | $array_key.'_total_vat'=>price($object->total_tva), |
| 578 | 578 | $array_key.'_total_ttc'=>price($object->total_ttc), |
@@ -592,8 +592,8 @@ discard block |
||
| 592 | 592 | // Add vat by rates |
| 593 | 593 | foreach ($object->lines as $line) |
| 594 | 594 | { |
| 595 | - if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]=0; |
|
| 596 | - $array_shipment[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; |
|
| 595 | + if (empty($array_shipment[$array_key.'_total_vat_'.$line->tva_tx])) $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] = 0; |
|
| 596 | + $array_shipment[$array_key.'_total_vat_'.$line->tva_tx] += $line->total_tva; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // Retrieve extrafields |
@@ -617,29 +617,29 @@ discard block |
||
| 617 | 617 | * @param Translate $outputlangs Lang object to use for output |
| 618 | 618 | * @return array Substitution array |
| 619 | 619 | */ |
| 620 | - function get_substitutionarray_shipment_lines($line,$outputlangs) |
|
| 620 | + function get_substitutionarray_shipment_lines($line, $outputlangs) |
|
| 621 | 621 | { |
| 622 | 622 | global $conf; |
| 623 | 623 | dol_include_once('/core/lib/product.lib.php'); |
| 624 | 624 | |
| 625 | 625 | return array( |
| 626 | - 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), |
|
| 626 | + 'line_fulldesc'=>doc_getlinedesc($line, $outputlangs), |
|
| 627 | 627 | 'line_product_ref'=>$line->product_ref, |
| 628 | 628 | 'line_product_label'=>$line->product_label, |
| 629 | 629 | 'line_desc'=>$line->desc, |
| 630 | - 'line_vatrate'=>vatrate($line->tva_tx,true,$line->info_bits), |
|
| 630 | + 'line_vatrate'=>vatrate($line->tva_tx, true, $line->info_bits), |
|
| 631 | 631 | 'line_up'=>price($line->subprice), |
| 632 | 632 | 'line_qty'=>$line->qty, |
| 633 | 633 | 'line_qty_shipped'=>$line->qty_shipped, |
| 634 | 634 | 'line_qty_asked'=>$line->qty_asked, |
| 635 | - 'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''), |
|
| 635 | + 'line_discount_percent'=>($line->remise_percent ? $line->remise_percent.'%' : ''), |
|
| 636 | 636 | 'line_price_ht'=>price($line->total_ht), |
| 637 | 637 | 'line_price_ttc'=>price($line->total_ttc), |
| 638 | 638 | 'line_price_vat'=>price($line->total_tva), |
| 639 | - 'line_weight'=>empty($line->weight) ? '' : $line->weight*$line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'), |
|
| 640 | - 'line_length'=>empty($line->length) ? '' : $line->length*$line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'), |
|
| 641 | - 'line_surface'=>empty($line->surface) ? '' : $line->surface*$line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'), |
|
| 642 | - 'line_volume'=>empty($line->volume) ? '' : $line->volume*$line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'), |
|
| 639 | + 'line_weight'=>empty($line->weight) ? '' : $line->weight * $line->qty_shipped.' '.measuring_units_string($line->weight_units, 'weight'), |
|
| 640 | + 'line_length'=>empty($line->length) ? '' : $line->length * $line->qty_shipped.' '.measuring_units_string($line->length_units, 'size'), |
|
| 641 | + 'line_surface'=>empty($line->surface) ? '' : $line->surface * $line->qty_shipped.' '.measuring_units_string($line->surface_units, 'surface'), |
|
| 642 | + 'line_volume'=>empty($line->volume) ? '' : $line->volume * $line->qty_shipped.' '.measuring_units_string($line->volume_units, 'volume'), |
|
| 643 | 643 | ); |
| 644 | 644 | } |
| 645 | 645 | |
@@ -652,16 +652,16 @@ discard block |
||
| 652 | 652 | * @param boolean $recursive Want to fetch child array or child object |
| 653 | 653 | * @return array Array of substitution key->code |
| 654 | 654 | */ |
| 655 | - function get_substitutionarray_each_var_object(&$object,$outputlangs,$recursive=true) { |
|
| 655 | + function get_substitutionarray_each_var_object(&$object, $outputlangs, $recursive = true) { |
|
| 656 | 656 | $array_other = array(); |
| 657 | - if(!empty($object)) { |
|
| 658 | - foreach($object as $key => $value) { |
|
| 659 | - if(!empty($value)) { |
|
| 660 | - if(!is_array($value) && !is_object($value)) { |
|
| 657 | + if (!empty($object)) { |
|
| 658 | + foreach ($object as $key => $value) { |
|
| 659 | + if (!empty($value)) { |
|
| 660 | + if (!is_array($value) && !is_object($value)) { |
|
| 661 | 661 | $array_other['object_'.$key] = $value; |
| 662 | 662 | } |
| 663 | - if(is_array($value) && $recursive){ |
|
| 664 | - $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value,$outputlangs,false); |
|
| 663 | + if (is_array($value) && $recursive) { |
|
| 664 | + $array_other['object_'.$key] = $this->get_substitutionarray_each_var_object($value, $outputlangs, false); |
|
| 665 | 665 | } |
| 666 | 666 | } |
| 667 | 667 | } |
@@ -680,30 +680,30 @@ discard block |
||
| 680 | 680 | * @param Translate $outputlangs Lang object to use for output |
| 681 | 681 | * @return array Substitution array |
| 682 | 682 | */ |
| 683 | - function fill_substitutionarray_with_extrafields($object,$array_to_fill,$extrafields,$array_key,$outputlangs) |
|
| 683 | + function fill_substitutionarray_with_extrafields($object, $array_to_fill, $extrafields, $array_key, $outputlangs) |
|
| 684 | 684 | { |
| 685 | 685 | global $conf; |
| 686 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 686 | + foreach ($extrafields->attribute_label as $key=>$label) |
|
| 687 | 687 | { |
| 688 | - if($extrafields->attribute_type[$key] == 'price') |
|
| 688 | + if ($extrafields->attribute_type[$key] == 'price') |
|
| 689 | 689 | { |
| 690 | 690 | $object->array_options['options_'.$key] = price2num($object->array_options['options_'.$key]); |
| 691 | - $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key],0,$outputlangs,0,0,-1,$conf->currency); |
|
| 691 | + $object->array_options['options_'.$key.'_currency'] = price($object->array_options['options_'.$key], 0, $outputlangs, 0, 0, -1, $conf->currency); |
|
| 692 | 692 | //Add value to store price with currency |
| 693 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); |
|
| 693 | + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_currency' => $object->array_options['options_'.$key.'_currency'])); |
|
| 694 | 694 | } |
| 695 | - else if($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 695 | + else if ($extrafields->attribute_type[$key] == 'select' || $extrafields->attribute_type[$key] == 'checkbox') |
|
| 696 | 696 | { |
| 697 | 697 | $object->array_options['options_'.$key] = $extrafields->attribute_param[$key]['options'][$object->array_options['options_'.$key]]; |
| 698 | 698 | } |
| 699 | - else if($extrafields->attribute_type[$key] == 'date') |
|
| 699 | + else if ($extrafields->attribute_type[$key] == 'date') |
|
| 700 | 700 | { |
| 701 | - if (strlen($object->array_options['options_'.$key])>0) |
|
| 701 | + if (strlen($object->array_options['options_'.$key]) > 0) |
|
| 702 | 702 | { |
| 703 | 703 | $date = $object->array_options['options_'.$key]; |
| 704 | - $object->array_options['options_'.$key] = dol_print_date($date,'day'); // using company output language |
|
| 705 | - $object->array_options['options_'.$key.'_locale'] = dol_print_date($date,'day','tzserver',$outputlangs); // using output language format |
|
| 706 | - $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date,'dayrfc'); // international format |
|
| 704 | + $object->array_options['options_'.$key] = dol_print_date($date, 'day'); // using company output language |
|
| 705 | + $object->array_options['options_'.$key.'_locale'] = dol_print_date($date, 'day', 'tzserver', $outputlangs); // using output language format |
|
| 706 | + $object->array_options['options_'.$key.'_rfc'] = dol_print_date($date, 'dayrfc'); // international format |
|
| 707 | 707 | } |
| 708 | 708 | else |
| 709 | 709 | { |
@@ -711,19 +711,19 @@ discard block |
||
| 711 | 711 | $object->array_options['options_'.$key.'_locale'] = ''; |
| 712 | 712 | $object->array_options['options_'.$key.'_rfc'] = ''; |
| 713 | 713 | } |
| 714 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 715 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 714 | + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 715 | + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 716 | 716 | } |
| 717 | - else if($extrafields->attribute_type[$key] == 'datetime') |
|
| 717 | + else if ($extrafields->attribute_type[$key] == 'datetime') |
|
| 718 | 718 | { |
| 719 | 719 | $datetime = $object->array_options['options_'.$key]; |
| 720 | - $object->array_options['options_'.$key] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); // using company output language |
|
| 721 | - $object->array_options['options_'.$key.'_locale'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour','tzserver',$outputlangs):''); // using output language format |
|
| 722 | - $object->array_options['options_'.$key.'_rfc'] = ($datetime!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhourrfc'):''); // international format |
|
| 723 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 724 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 720 | + $object->array_options['options_'.$key] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhour') : ''); // using company output language |
|
| 721 | + $object->array_options['options_'.$key.'_locale'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhour', 'tzserver', $outputlangs) : ''); // using output language format |
|
| 722 | + $object->array_options['options_'.$key.'_rfc'] = ($datetime != "0000-00-00 00:00:00" ?dol_print_date($object->array_options['options_'.$key], 'dayhourrfc') : ''); // international format |
|
| 723 | + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_locale' => $object->array_options['options_'.$key.'_locale'])); |
|
| 724 | + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key.'_rfc' => $object->array_options['options_'.$key.'_rfc'])); |
|
| 725 | 725 | } |
| 726 | - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 726 | + $array_to_fill = array_merge($array_to_fill, array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | return $array_to_fill; |
@@ -743,12 +743,12 @@ discard block |
||
| 743 | 743 | * @param int $hidebottom Hide bottom |
| 744 | 744 | * @return void |
| 745 | 745 | */ |
| 746 | - function printRect($pdf, $x, $y, $l, $h, $hidetop=0, $hidebottom=0) |
|
| 746 | + function printRect($pdf, $x, $y, $l, $h, $hidetop = 0, $hidebottom = 0) |
|
| 747 | 747 | { |
| 748 | - if (empty($hidetop) || $hidetop==-1) $pdf->line($x, $y, $x+$l, $y); |
|
| 749 | - $pdf->line($x+$l, $y, $x+$l, $y+$h); |
|
| 750 | - if (empty($hidebottom)) $pdf->line($x+$l, $y+$h, $x, $y+$h); |
|
| 751 | - $pdf->line($x, $y+$h, $x, $y); |
|
| 748 | + if (empty($hidetop) || $hidetop == -1) $pdf->line($x, $y, $x + $l, $y); |
|
| 749 | + $pdf->line($x + $l, $y, $x + $l, $y + $h); |
|
| 750 | + if (empty($hidebottom)) $pdf->line($x + $l, $y + $h, $x, $y + $h); |
|
| 751 | + $pdf->line($x, $y + $h, $x, $y); |
|
| 752 | 752 | } |
| 753 | 753 | } |
| 754 | 754 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @var string[] Array of error strings |
| 59 | 59 | */ |
| 60 | - public $errors=array(); |
|
| 60 | + public $errors = array(); |
|
| 61 | 61 | /** |
| 62 | 62 | * @var string |
| 63 | 63 | */ |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | /** |
| 78 | 78 | * @var mixed Contains data to manage extrafields |
| 79 | 79 | */ |
| 80 | - public $array_options=array(); |
|
| 80 | + public $array_options = array(); |
|
| 81 | 81 | /** |
| 82 | 82 | * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
| 83 | 83 | */ |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | /** |
| 104 | 104 | * @var array<string,mixed> Can be used to pass information when only object is provided to method |
| 105 | 105 | */ |
| 106 | - public $context=array(); |
|
| 106 | + public $context = array(); |
|
| 107 | 107 | |
| 108 | 108 | /** |
| 109 | 109 | * @var string Contains canvas name if record is an alternative canvas record |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | * @var mixed Contains comments |
| 315 | 315 | * @see fetchComments() |
| 316 | 316 | */ |
| 317 | - public $comments=array(); |
|
| 317 | + public $comments = array(); |
|
| 318 | 318 | |
| 319 | 319 | /** |
| 320 | 320 | * @var int |
@@ -350,29 +350,29 @@ discard block |
||
| 350 | 350 | * @param string $ref_ext Ref ext of object to check |
| 351 | 351 | * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
| 352 | 352 | */ |
| 353 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 353 | + static function isExistingObject($element, $id, $ref = '', $ref_ext = '') |
|
| 354 | 354 | { |
| 355 | - global $db,$conf; |
|
| 355 | + global $db, $conf; |
|
| 356 | 356 | |
| 357 | 357 | $sql = "SELECT rowid, ref, ref_ext"; |
| 358 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 359 | - $sql.= " WHERE entity IN (".getEntity($element).")" ; |
|
| 358 | + $sql .= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 359 | + $sql .= " WHERE entity IN (".getEntity($element).")"; |
|
| 360 | 360 | |
| 361 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 362 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 363 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 361 | + if ($id > 0) $sql .= " AND rowid = ".$db->escape($id); |
|
| 362 | + else if ($ref) $sql .= " AND ref = '".$db->escape($ref)."'"; |
|
| 363 | + else if ($ref_ext) $sql .= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 364 | 364 | else { |
| 365 | - $error='ErrorWrongParameters'; |
|
| 365 | + $error = 'ErrorWrongParameters'; |
|
| 366 | 366 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
| 367 | 367 | return -1; |
| 368 | 368 | } |
| 369 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 369 | + if ($ref || $ref_ext) $sql .= " AND entity = ".$conf->entity; |
|
| 370 | 370 | |
| 371 | 371 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
| 372 | 372 | $resql = $db->query($sql); |
| 373 | 373 | if ($resql) |
| 374 | 374 | { |
| 375 | - $num=$db->num_rows($resql); |
|
| 375 | + $num = $db->num_rows($resql); |
|
| 376 | 376 | if ($num > 0) return 1; |
| 377 | 377 | else return 0; |
| 378 | 378 | } |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | */ |
| 387 | 387 | function errorsToString() |
| 388 | 388 | { |
| 389 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):''); |
|
| 389 | + return $this->error.(is_array($this->errors) ? (($this->error != '' ? ', ' : '').join(', ', $this->errors)) : ''); |
|
| 390 | 390 | } |
| 391 | 391 | |
| 392 | 392 | /** |
@@ -398,23 +398,23 @@ discard block |
||
| 398 | 398 | * @param int $maxlen Maximum length |
| 399 | 399 | * @return string String with full name |
| 400 | 400 | */ |
| 401 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 401 | + function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0) |
|
| 402 | 402 | { |
| 403 | 403 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
| 404 | - $lastname=$this->lastname; |
|
| 405 | - $firstname=$this->firstname; |
|
| 406 | - if (empty($lastname)) $lastname=(isset($this->lastname)?$this->lastname:(isset($this->name)?$this->name:(isset($this->nom)?$this->nom:(isset($this->societe)?$this->societe:(isset($this->company)?$this->company:''))))); |
|
| 404 | + $lastname = $this->lastname; |
|
| 405 | + $firstname = $this->firstname; |
|
| 406 | + if (empty($lastname)) $lastname = (isset($this->lastname) ? $this->lastname : (isset($this->name) ? $this->name : (isset($this->nom) ? $this->nom : (isset($this->societe) ? $this->societe : (isset($this->company) ? $this->company : ''))))); |
|
| 407 | 407 | |
| 408 | - $ret=''; |
|
| 408 | + $ret = ''; |
|
| 409 | 409 | if ($option && $this->civility_id) |
| 410 | 410 | { |
| 411 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
| 412 | - else $ret.=$this->civility_id.' '; |
|
| 411 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id) != "Civility".$this->civility_id) $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
| 412 | + else $ret .= $this->civility_id.' '; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 415 | + $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 416 | 416 | |
| 417 | - return dol_trunc($ret,$maxlen); |
|
| 417 | + return dol_trunc($ret, $maxlen); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -424,14 +424,14 @@ discard block |
||
| 424 | 424 | * @param string $sep Separator to use to build string |
| 425 | 425 | * @return string Full address string |
| 426 | 426 | */ |
| 427 | - function getFullAddress($withcountry=0,$sep="\n") |
|
| 427 | + function getFullAddress($withcountry = 0, $sep = "\n") |
|
| 428 | 428 | { |
| 429 | 429 | if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
| 430 | 430 | { |
| 431 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 432 | - $tmparray=getCountry($this->country_id,'all'); |
|
| 433 | - $this->country_code=$tmparray['code']; |
|
| 434 | - $this->country =$tmparray['label']; |
|
| 431 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 432 | + $tmparray = getCountry($this->country_id, 'all'); |
|
| 433 | + $this->country_code = $tmparray['code']; |
|
| 434 | + $this->country = $tmparray['label']; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | return dol_format_address($this, $withcountry, $sep); |
@@ -449,96 +449,96 @@ discard block |
||
| 449 | 449 | { |
| 450 | 450 | global $conf, $langs; |
| 451 | 451 | |
| 452 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
| 452 | + $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS |
|
| 453 | 453 | |
| 454 | - $contactid=0; |
|
| 455 | - $thirdpartyid=0; |
|
| 454 | + $contactid = 0; |
|
| 455 | + $thirdpartyid = 0; |
|
| 456 | 456 | if ($this->element == 'societe') |
| 457 | 457 | { |
| 458 | - $thirdpartyid=$this->id; |
|
| 458 | + $thirdpartyid = $this->id; |
|
| 459 | 459 | } |
| 460 | 460 | if ($this->element == 'contact') |
| 461 | 461 | { |
| 462 | - $contactid=$this->id; |
|
| 463 | - $thirdpartyid=$object->fk_soc; |
|
| 462 | + $contactid = $this->id; |
|
| 463 | + $thirdpartyid = $object->fk_soc; |
|
| 464 | 464 | } |
| 465 | 465 | if ($this->element == 'user') |
| 466 | 466 | { |
| 467 | - $contactid=$this->contact_id; |
|
| 468 | - $thirdpartyid=$object->fk_soc; |
|
| 467 | + $contactid = $this->contact_id; |
|
| 468 | + $thirdpartyid = $object->fk_soc; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - $out='<!-- BEGIN part to show address block -->'; |
|
| 471 | + $out = '<!-- BEGIN part to show address block -->'; |
|
| 472 | 472 | |
| 473 | - $outdone=0; |
|
| 474 | - $coords = $this->getFullAddress(1,', '); |
|
| 473 | + $outdone = 0; |
|
| 474 | + $coords = $this->getFullAddress(1, ', '); |
|
| 475 | 475 | if ($coords) |
| 476 | 476 | { |
| 477 | - if (! empty($conf->use_javascript_ajax)) |
|
| 477 | + if (!empty($conf->use_javascript_ajax)) |
|
| 478 | 478 | { |
| 479 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 479 | + $namecoords = $this->getFullName($langs, 1).'<br>'.$coords; |
|
| 480 | 480 | // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
| 481 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
| 482 | - $out.=img_picto($langs->trans("Address"), 'object_address.png'); |
|
| 483 | - $out.='</a> '; |
|
| 481 | + $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">'; |
|
| 482 | + $out .= img_picto($langs->trans("Address"), 'object_address.png'); |
|
| 483 | + $out .= '</a> '; |
|
| 484 | 484 | } |
| 485 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 485 | + $out .= dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 486 | 486 | $outdone++; |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
| 489 | + if (!in_array($this->country_code, $countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
| 490 | 490 | && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
| 491 | 491 | { |
| 492 | - $out.=($outdone?' - ':'').$this->state; |
|
| 492 | + $out .= ($outdone ? ' - ' : '').$this->state; |
|
| 493 | 493 | $outdone++; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - if (! empty($this->phone) || ! empty($this->phone_pro) || ! empty($this->phone_mobile) || ! empty($this->phone_perso) || ! empty($this->fax) || ! empty($this->office_phone) || ! empty($this->user_mobile) || ! empty($this->office_fax)) $out.=($outdone?'<br>':''); |
|
| 497 | - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
| 498 | - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
| 496 | + if (!empty($this->phone) || !empty($this->phone_pro) || !empty($this->phone_mobile) || !empty($this->phone_perso) || !empty($this->fax) || !empty($this->office_phone) || !empty($this->user_mobile) || !empty($this->office_fax)) $out .= ($outdone ? '<br>' : ''); |
|
| 497 | + if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone |
|
| 498 | + $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
| 499 | 499 | } |
| 500 | - if (! empty($this->phone_pro)) { |
|
| 501 | - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
| 500 | + if (!empty($this->phone_pro)) { |
|
| 501 | + $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
| 502 | 502 | } |
| 503 | - if (! empty($this->phone_mobile)) { |
|
| 504 | - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
| 503 | + if (!empty($this->phone_mobile)) { |
|
| 504 | + $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++; |
|
| 505 | 505 | } |
| 506 | - if (! empty($this->phone_perso)) { |
|
| 507 | - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++; |
|
| 506 | + if (!empty($this->phone_perso)) { |
|
| 507 | + $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePerso")); $outdone++; |
|
| 508 | 508 | } |
| 509 | - if (! empty($this->office_phone)) { |
|
| 510 | - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++; |
|
| 509 | + if (!empty($this->office_phone)) { |
|
| 510 | + $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++; |
|
| 511 | 511 | } |
| 512 | - if (! empty($this->user_mobile)) { |
|
| 513 | - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++; |
|
| 512 | + if (!empty($this->user_mobile)) { |
|
| 513 | + $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++; |
|
| 514 | 514 | } |
| 515 | - if (! empty($this->fax)) { |
|
| 516 | - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
| 515 | + if (!empty($this->fax)) { |
|
| 516 | + $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++; |
|
| 517 | 517 | } |
| 518 | - if (! empty($this->office_fax)) { |
|
| 519 | - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; |
|
| 518 | + if (!empty($this->office_fax)) { |
|
| 519 | + $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++; |
|
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - $out.='<div style="clear: both;"></div>'; |
|
| 523 | - $outdone=0; |
|
| 524 | - if (! empty($this->email)) |
|
| 522 | + $out .= '<div style="clear: both;"></div>'; |
|
| 523 | + $outdone = 0; |
|
| 524 | + if (!empty($this->email)) |
|
| 525 | 525 | { |
| 526 | - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
| 526 | + $out .= dol_print_email($this->email, $this->id, $object->id, 'AC_EMAIL', 0, 0, 1); |
|
| 527 | 527 | $outdone++; |
| 528 | 528 | } |
| 529 | - if (! empty($this->url)) |
|
| 529 | + if (!empty($this->url)) |
|
| 530 | 530 | { |
| 531 | - $out.=dol_print_url($this->url,'_goout',0,1); |
|
| 531 | + $out .= dol_print_url($this->url, '_goout', 0, 1); |
|
| 532 | 532 | $outdone++; |
| 533 | 533 | } |
| 534 | - if (! empty($conf->skype->enabled)) |
|
| 534 | + if (!empty($conf->skype->enabled)) |
|
| 535 | 535 | { |
| 536 | - $out.='<div style="clear: both;"></div>'; |
|
| 537 | - if ($this->skype) $out.=dol_print_skype($this->skype,$this->id,$object->id,'AC_SKYPE'); |
|
| 536 | + $out .= '<div style="clear: both;"></div>'; |
|
| 537 | + if ($this->skype) $out .= dol_print_skype($this->skype, $this->id, $object->id, 'AC_SKYPE'); |
|
| 538 | 538 | $outdone++; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | - $out.='<!-- END Part to show address block -->'; |
|
| 541 | + $out .= '<!-- END Part to show address block -->'; |
|
| 542 | 542 | |
| 543 | 543 | return $out; |
| 544 | 544 | } |
@@ -551,17 +551,17 @@ discard block |
||
| 551 | 551 | * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
| 552 | 552 | * @return string Link or empty string if there is no download link |
| 553 | 553 | */ |
| 554 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 554 | + function getLastMainDocLink($modulepart, $initsharekey = 0, $relativelink = 0) |
|
| 555 | 555 | { |
| 556 | 556 | global $user, $dolibarr_main_url_root; |
| 557 | 557 | |
| 558 | 558 | if (empty($this->last_main_doc)) |
| 559 | 559 | { |
| 560 | - return ''; // No known last doc |
|
| 560 | + return ''; // No known last doc |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 564 | - $ecmfile=new EcmFiles($this->db); |
|
| 564 | + $ecmfile = new EcmFiles($this->db); |
|
| 565 | 565 | $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
| 566 | 566 | if ($result < 0) |
| 567 | 567 | { |
@@ -609,26 +609,26 @@ discard block |
||
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // Define $urlwithroot |
| 612 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
| 613 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 612 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
| 613 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 614 | 614 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 615 | 615 | |
| 616 | - $forcedownload=0; |
|
| 616 | + $forcedownload = 0; |
|
| 617 | 617 | |
| 618 | - $paramlink=''; |
|
| 618 | + $paramlink = ''; |
|
| 619 | 619 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
| 620 | 620 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
| 621 | 621 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
| 622 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 623 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 622 | + if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share; // Hash for public share |
|
| 623 | + if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1'; |
|
| 624 | 624 | |
| 625 | 625 | if ($relativelink) |
| 626 | 626 | { |
| 627 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 627 | + $linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : ''); |
|
| 628 | 628 | } |
| 629 | 629 | else |
| 630 | 630 | { |
| 631 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 631 | + $linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : ''); |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | // Here $ecmfile->share is defined |
@@ -645,9 +645,9 @@ discard block |
||
| 645 | 645 | * @param int $notrigger Disable all triggers |
| 646 | 646 | * @return int <0 if KO, >0 if OK |
| 647 | 647 | */ |
| 648 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 648 | + function add_contact($fk_socpeople, $type_contact, $source = 'external', $notrigger = 0) |
|
| 649 | 649 | { |
| 650 | - global $user,$langs; |
|
| 650 | + global $user, $langs; |
|
| 651 | 651 | |
| 652 | 652 | |
| 653 | 653 | dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
@@ -656,43 +656,43 @@ discard block |
||
| 656 | 656 | if ($fk_socpeople <= 0) |
| 657 | 657 | { |
| 658 | 658 | $langs->load("errors"); |
| 659 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1"); |
|
| 660 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 659 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "1"); |
|
| 660 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
| 661 | 661 | return -1; |
| 662 | 662 | } |
| 663 | - if (! $type_contact) |
|
| 663 | + if (!$type_contact) |
|
| 664 | 664 | { |
| 665 | 665 | $langs->load("errors"); |
| 666 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2"); |
|
| 667 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 666 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "2"); |
|
| 667 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
| 668 | 668 | return -2; |
| 669 | 669 | } |
| 670 | 670 | |
| 671 | - $id_type_contact=0; |
|
| 671 | + $id_type_contact = 0; |
|
| 672 | 672 | if (is_numeric($type_contact)) |
| 673 | 673 | { |
| 674 | - $id_type_contact=$type_contact; |
|
| 674 | + $id_type_contact = $type_contact; |
|
| 675 | 675 | } |
| 676 | 676 | else |
| 677 | 677 | { |
| 678 | 678 | // On recherche id type_contact |
| 679 | 679 | $sql = "SELECT tc.rowid"; |
| 680 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 681 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 682 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 683 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 680 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 681 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 682 | + $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 683 | + $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 684 | 684 | //print $sql; |
| 685 | - $resql=$this->db->query($sql); |
|
| 685 | + $resql = $this->db->query($sql); |
|
| 686 | 686 | if ($resql) |
| 687 | 687 | { |
| 688 | 688 | $obj = $this->db->fetch_object($resql); |
| 689 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 689 | + if ($obj) $id_type_contact = $obj->rowid; |
|
| 690 | 690 | } |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | if ($id_type_contact == 0) |
| 694 | 694 | { |
| 695 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 695 | + $this->error = 'CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 696 | 696 | dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT"); |
| 697 | 697 | return -3; |
| 698 | 698 | } |
@@ -700,35 +700,35 @@ discard block |
||
| 700 | 700 | $datecreate = dol_now(); |
| 701 | 701 | |
| 702 | 702 | // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
| 703 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
| 704 | - $already_added=false; |
|
| 705 | - if(!empty($TListeContacts)) { |
|
| 706 | - foreach($TListeContacts as $array_contact) { |
|
| 707 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
| 708 | - $already_added=true; |
|
| 703 | + $TListeContacts = $this->liste_contact(-1, $source); |
|
| 704 | + $already_added = false; |
|
| 705 | + if (!empty($TListeContacts)) { |
|
| 706 | + foreach ($TListeContacts as $array_contact) { |
|
| 707 | + if ($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { |
|
| 708 | + $already_added = true; |
|
| 709 | 709 | break; |
| 710 | 710 | } |
| 711 | 711 | } |
| 712 | 712 | } |
| 713 | 713 | |
| 714 | - if(!$already_added) { |
|
| 714 | + if (!$already_added) { |
|
| 715 | 715 | |
| 716 | 716 | $this->db->begin(); |
| 717 | 717 | |
| 718 | 718 | // Insertion dans la base |
| 719 | 719 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
| 720 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 721 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; |
|
| 722 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 723 | - $sql.= ", 4, ". $id_type_contact; |
|
| 724 | - $sql.= ")"; |
|
| 720 | + $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 721 | + $sql .= " VALUES (".$this->id.", ".$fk_socpeople." , "; |
|
| 722 | + $sql .= "'".$this->db->idate($datecreate)."'"; |
|
| 723 | + $sql .= ", 4, ".$id_type_contact; |
|
| 724 | + $sql .= ")"; |
|
| 725 | 725 | |
| 726 | - $resql=$this->db->query($sql); |
|
| 726 | + $resql = $this->db->query($sql); |
|
| 727 | 727 | if ($resql) |
| 728 | 728 | { |
| 729 | - if (! $notrigger) |
|
| 729 | + if (!$notrigger) |
|
| 730 | 730 | { |
| 731 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 731 | + $result = $this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 732 | 732 | if ($result < 0) |
| 733 | 733 | { |
| 734 | 734 | $this->db->rollback(); |
@@ -743,14 +743,14 @@ discard block |
||
| 743 | 743 | { |
| 744 | 744 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 745 | 745 | { |
| 746 | - $this->error=$this->db->errno(); |
|
| 746 | + $this->error = $this->db->errno(); |
|
| 747 | 747 | $this->db->rollback(); |
| 748 | 748 | echo 'err rollback'; |
| 749 | 749 | return -2; |
| 750 | 750 | } |
| 751 | 751 | else |
| 752 | 752 | { |
| 753 | - $this->error=$this->db->error(); |
|
| 753 | + $this->error = $this->db->error(); |
|
| 754 | 754 | $this->db->rollback(); |
| 755 | 755 | return -1; |
| 756 | 756 | } |
@@ -765,14 +765,14 @@ discard block |
||
| 765 | 765 | * @param string $source Nature of contact ('internal' or 'external') |
| 766 | 766 | * @return int >0 if OK, <0 if KO |
| 767 | 767 | */ |
| 768 | - function copy_linked_contact($objFrom, $source='internal') |
|
| 768 | + function copy_linked_contact($objFrom, $source = 'internal') |
|
| 769 | 769 | { |
| 770 | 770 | $contacts = $objFrom->liste_contact(-1, $source); |
| 771 | - foreach($contacts as $contact) |
|
| 771 | + foreach ($contacts as $contact) |
|
| 772 | 772 | { |
| 773 | 773 | if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
| 774 | 774 | { |
| 775 | - $this->error=$this->db->lasterror(); |
|
| 775 | + $this->error = $this->db->lasterror(); |
|
| 776 | 776 | return -1; |
| 777 | 777 | } |
| 778 | 778 | } |
@@ -788,22 +788,22 @@ discard block |
||
| 788 | 788 | * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
| 789 | 789 | * @return int <0 if KO, >= 0 if OK |
| 790 | 790 | */ |
| 791 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 791 | + function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0) |
|
| 792 | 792 | { |
| 793 | 793 | // Insertion dans la base |
| 794 | 794 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
| 795 | - $sql.= " statut = ".$statut; |
|
| 796 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 797 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 798 | - $sql.= " where rowid = ".$rowid; |
|
| 799 | - $resql=$this->db->query($sql); |
|
| 795 | + $sql .= " statut = ".$statut; |
|
| 796 | + if ($type_contact_id) $sql .= ", fk_c_type_contact = '".$type_contact_id."'"; |
|
| 797 | + if ($fk_socpeople) $sql .= ", fk_socpeople = '".$fk_socpeople."'"; |
|
| 798 | + $sql .= " where rowid = ".$rowid; |
|
| 799 | + $resql = $this->db->query($sql); |
|
| 800 | 800 | if ($resql) |
| 801 | 801 | { |
| 802 | 802 | return 0; |
| 803 | 803 | } |
| 804 | 804 | else |
| 805 | 805 | { |
| 806 | - $this->error=$this->db->lasterror(); |
|
| 806 | + $this->error = $this->db->lasterror(); |
|
| 807 | 807 | return -1; |
| 808 | 808 | } |
| 809 | 809 | } |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | * @param int $notrigger Disable all triggers |
| 816 | 816 | * @return int >0 if OK, <0 if KO |
| 817 | 817 | */ |
| 818 | - function delete_contact($rowid, $notrigger=0) |
|
| 818 | + function delete_contact($rowid, $notrigger = 0) |
|
| 819 | 819 | { |
| 820 | 820 | global $user; |
| 821 | 821 | |
@@ -823,14 +823,14 @@ discard block |
||
| 823 | 823 | $this->db->begin(); |
| 824 | 824 | |
| 825 | 825 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 826 | - $sql.= " WHERE rowid =".$rowid; |
|
| 826 | + $sql .= " WHERE rowid =".$rowid; |
|
| 827 | 827 | |
| 828 | 828 | dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
| 829 | 829 | if ($this->db->query($sql)) |
| 830 | 830 | { |
| 831 | - if (! $notrigger) |
|
| 831 | + if (!$notrigger) |
|
| 832 | 832 | { |
| 833 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 833 | + $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 834 | 834 | if ($result < 0) { $this->db->rollback(); return -1; } |
| 835 | 835 | } |
| 836 | 836 | |
@@ -839,7 +839,7 @@ discard block |
||
| 839 | 839 | } |
| 840 | 840 | else |
| 841 | 841 | { |
| 842 | - $this->error=$this->db->lasterror(); |
|
| 842 | + $this->error = $this->db->lasterror(); |
|
| 843 | 843 | $this->db->rollback(); |
| 844 | 844 | return -1; |
| 845 | 845 | } |
@@ -852,21 +852,21 @@ discard block |
||
| 852 | 852 | * @param string $code Type of contact (code or id) |
| 853 | 853 | * @return int >0 if OK, <0 if KO |
| 854 | 854 | */ |
| 855 | - function delete_linked_contact($source='',$code='') |
|
| 855 | + function delete_linked_contact($source = '', $code = '') |
|
| 856 | 856 | { |
| 857 | 857 | $temp = array(); |
| 858 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 858 | + $typeContact = $this->liste_type_contact($source, '', 0, 0, $code); |
|
| 859 | 859 | |
| 860 | - foreach($typeContact as $key => $value) |
|
| 860 | + foreach ($typeContact as $key => $value) |
|
| 861 | 861 | { |
| 862 | - array_push($temp,$key); |
|
| 862 | + array_push($temp, $key); |
|
| 863 | 863 | } |
| 864 | 864 | $listId = implode(",", $temp); |
| 865 | 865 | |
| 866 | 866 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 867 | - $sql.= " WHERE element_id = ".$this->id; |
|
| 867 | + $sql .= " WHERE element_id = ".$this->id; |
|
| 868 | 868 | if ($listId) |
| 869 | - $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 869 | + $sql .= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 870 | 870 | |
| 871 | 871 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
| 872 | 872 | if ($this->db->query($sql)) |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | } |
| 876 | 876 | else |
| 877 | 877 | { |
| 878 | - $this->error=$this->db->lasterror(); |
|
| 878 | + $this->error = $this->db->lasterror(); |
|
| 879 | 879 | return -1; |
| 880 | 880 | } |
| 881 | 881 | } |
@@ -889,53 +889,53 @@ discard block |
||
| 889 | 889 | * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...) |
| 890 | 890 | * @return array Array of contacts |
| 891 | 891 | */ |
| 892 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 892 | + function liste_contact($statut = -1, $source = 'external', $list = 0, $code = '') |
|
| 893 | 893 | { |
| 894 | 894 | global $langs; |
| 895 | 895 | |
| 896 | - $tab=array(); |
|
| 897 | - |
|
| 898 | - $sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user |
|
| 899 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 900 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 901 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 902 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 903 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 904 | - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 905 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 906 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 907 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
| 908 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 909 | - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 910 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 911 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 912 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 913 | - $sql.= " AND tc.active=1"; |
|
| 914 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 915 | - $sql.=" ORDER BY t.lastname ASC"; |
|
| 896 | + $tab = array(); |
|
| 897 | + |
|
| 898 | + $sql = "SELECT ec.rowid, ec.statut as statuslink, ec.fk_socpeople as id, ec.fk_c_type_contact"; // This field contains id of llx_socpeople or id of llx_user |
|
| 899 | + if ($source == 'internal') $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 900 | + if ($source == 'external' || $source == 'thirdparty') $sql .= ", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 901 | + $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 902 | + $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 903 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 904 | + $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 905 | + if ($source == 'internal') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 906 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 907 | + $sql .= " WHERE ec.element_id =".$this->id; |
|
| 908 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 909 | + $sql .= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 910 | + if ($code) $sql .= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 911 | + if ($source == 'internal') $sql .= " AND tc.source = 'internal'"; |
|
| 912 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " AND tc.source = 'external'"; |
|
| 913 | + $sql .= " AND tc.active=1"; |
|
| 914 | + if ($statut >= 0) $sql .= " AND ec.statut = '".$statut."'"; |
|
| 915 | + $sql .= " ORDER BY t.lastname ASC"; |
|
| 916 | 916 | |
| 917 | 917 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
| 918 | - $resql=$this->db->query($sql); |
|
| 918 | + $resql = $this->db->query($sql); |
|
| 919 | 919 | if ($resql) |
| 920 | 920 | { |
| 921 | - $num=$this->db->num_rows($resql); |
|
| 922 | - $i=0; |
|
| 921 | + $num = $this->db->num_rows($resql); |
|
| 922 | + $i = 0; |
|
| 923 | 923 | while ($i < $num) |
| 924 | 924 | { |
| 925 | 925 | $obj = $this->db->fetch_object($resql); |
| 926 | 926 | |
| 927 | - if (! $list) |
|
| 927 | + if (!$list) |
|
| 928 | 928 | { |
| 929 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 930 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 931 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id, |
|
| 932 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
| 929 | + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 930 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 931 | + $tab[$i] = array('source'=>$obj->source, 'socid'=>$obj->socid, 'id'=>$obj->id, |
|
| 932 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
| 933 | 933 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
| 934 | 934 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
| 935 | 935 | } |
| 936 | 936 | else |
| 937 | 937 | { |
| 938 | - $tab[$i]=$obj->id; |
|
| 938 | + $tab[$i] = $obj->id; |
|
| 939 | 939 | } |
| 940 | 940 | |
| 941 | 941 | $i++; |
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | } |
| 946 | 946 | else |
| 947 | 947 | { |
| 948 | - $this->error=$this->db->lasterror(); |
|
| 948 | + $this->error = $this->db->lasterror(); |
|
| 949 | 949 | dol_print_error($this->db); |
| 950 | 950 | return -1; |
| 951 | 951 | } |
@@ -961,16 +961,16 @@ discard block |
||
| 961 | 961 | function swapContactStatus($rowid) |
| 962 | 962 | { |
| 963 | 963 | $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
| 964 | - $sql.= " tc.code, tc.libelle"; |
|
| 964 | + $sql .= " tc.code, tc.libelle"; |
|
| 965 | 965 | //$sql.= ", s.fk_soc"; |
| 966 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
| 966 | + $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; |
|
| 967 | 967 | //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as s ON ec.fk_socpeople=s.rowid"; // Si contact de type external, alors il est lie a une societe |
| 968 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
| 969 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 970 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 968 | + $sql .= " WHERE ec.rowid =".$rowid; |
|
| 969 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 970 | + $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 971 | 971 | |
| 972 | 972 | dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
| 973 | - $resql=$this->db->query($sql); |
|
| 973 | + $resql = $this->db->query($sql); |
|
| 974 | 974 | if ($resql) |
| 975 | 975 | { |
| 976 | 976 | $obj = $this->db->fetch_object($resql); |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | } |
| 982 | 982 | else |
| 983 | 983 | { |
| 984 | - $this->error=$this->db->error(); |
|
| 984 | + $this->error = $this->db->error(); |
|
| 985 | 985 | dol_print_error($this->db); |
| 986 | 986 | return -1; |
| 987 | 987 | } |
@@ -998,43 +998,43 @@ discard block |
||
| 998 | 998 | * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
| 999 | 999 | * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
| 1000 | 1000 | */ |
| 1001 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1001 | + function liste_type_contact($source = 'internal', $order = 'position', $option = 0, $activeonly = 0, $code = '') |
|
| 1002 | 1002 | { |
| 1003 | 1003 | global $langs; |
| 1004 | 1004 | |
| 1005 | - if (empty($order)) $order='position'; |
|
| 1006 | - if ($order == 'position') $order.=',code'; |
|
| 1005 | + if (empty($order)) $order = 'position'; |
|
| 1006 | + if ($order == 'position') $order .= ',code'; |
|
| 1007 | 1007 | |
| 1008 | 1008 | $tab = array(); |
| 1009 | 1009 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
| 1010 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1011 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1012 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1013 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1014 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1015 | - $sql.= $this->db->order($order,'ASC'); |
|
| 1010 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1011 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1012 | + if ($activeonly == 1) $sql .= " AND tc.active=1"; // only the active types |
|
| 1013 | + if (!empty($source) && $source != 'all') $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1014 | + if (!empty($code)) $sql .= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1015 | + $sql .= $this->db->order($order, 'ASC'); |
|
| 1016 | 1016 | |
| 1017 | 1017 | //print "sql=".$sql; |
| 1018 | - $resql=$this->db->query($sql); |
|
| 1018 | + $resql = $this->db->query($sql); |
|
| 1019 | 1019 | if ($resql) |
| 1020 | 1020 | { |
| 1021 | - $num=$this->db->num_rows($resql); |
|
| 1022 | - $i=0; |
|
| 1021 | + $num = $this->db->num_rows($resql); |
|
| 1022 | + $i = 0; |
|
| 1023 | 1023 | while ($i < $num) |
| 1024 | 1024 | { |
| 1025 | 1025 | $obj = $this->db->fetch_object($resql); |
| 1026 | 1026 | |
| 1027 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1028 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1029 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1030 | - else $tab[$obj->code]=$libelle_type; |
|
| 1027 | + $transkey = "TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1028 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1029 | + if (empty($option)) $tab[$obj->rowid] = $libelle_type; |
|
| 1030 | + else $tab[$obj->code] = $libelle_type; |
|
| 1031 | 1031 | $i++; |
| 1032 | 1032 | } |
| 1033 | 1033 | return $tab; |
| 1034 | 1034 | } |
| 1035 | 1035 | else |
| 1036 | 1036 | { |
| 1037 | - $this->error=$this->db->lasterror(); |
|
| 1037 | + $this->error = $this->db->lasterror(); |
|
| 1038 | 1038 | //dol_print_error($this->db); |
| 1039 | 1039 | return null; |
| 1040 | 1040 | } |
@@ -1051,50 +1051,50 @@ discard block |
||
| 1051 | 1051 | * @param int $status limited to a certain status |
| 1052 | 1052 | * @return array List of id for such contacts |
| 1053 | 1053 | */ |
| 1054 | - function getIdContact($source,$code,$status=0) |
|
| 1054 | + function getIdContact($source, $code, $status = 0) |
|
| 1055 | 1055 | { |
| 1056 | 1056 | global $conf; |
| 1057 | 1057 | |
| 1058 | - $result=array(); |
|
| 1059 | - $i=0; |
|
| 1058 | + $result = array(); |
|
| 1059 | + $i = 0; |
|
| 1060 | 1060 | //cas particulier pour les expeditions |
| 1061 | - if($this->element=='shipping' && $this->origin_id != 0) { |
|
| 1062 | - $id=$this->origin_id; |
|
| 1063 | - $element='commande'; |
|
| 1061 | + if ($this->element == 'shipping' && $this->origin_id != 0) { |
|
| 1062 | + $id = $this->origin_id; |
|
| 1063 | + $element = 'commande'; |
|
| 1064 | 1064 | } else { |
| 1065 | - $id=$this->id; |
|
| 1066 | - $element=$this->element; |
|
| 1065 | + $id = $this->id; |
|
| 1066 | + $element = $this->element; |
|
| 1067 | 1067 | } |
| 1068 | 1068 | |
| 1069 | 1069 | $sql = "SELECT ec.fk_socpeople"; |
| 1070 | - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1071 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1072 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1073 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1074 | - $sql.= " WHERE ec.element_id = ".$id; |
|
| 1075 | - $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
| 1076 | - if ($source == 'internal') $sql.= " AND c.entity IN (0,".$conf->entity.")"; |
|
| 1077 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
| 1078 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1079 | - $sql.= " AND tc.element = '".$element."'"; |
|
| 1080 | - $sql.= " AND tc.source = '".$source."'"; |
|
| 1081 | - $sql.= " AND tc.code = '".$code."'"; |
|
| 1082 | - $sql.= " AND tc.active = 1"; |
|
| 1083 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1070 | + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1071 | + if ($source == 'internal') $sql .= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1072 | + if ($source == 'external') $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1073 | + $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1074 | + $sql .= " WHERE ec.element_id = ".$id; |
|
| 1075 | + $sql .= " AND ec.fk_socpeople = c.rowid"; |
|
| 1076 | + if ($source == 'internal') $sql .= " AND c.entity IN (0,".$conf->entity.")"; |
|
| 1077 | + if ($source == 'external') $sql .= " AND c.entity IN (".getEntity('societe').")"; |
|
| 1078 | + $sql .= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1079 | + $sql .= " AND tc.element = '".$element."'"; |
|
| 1080 | + $sql .= " AND tc.source = '".$source."'"; |
|
| 1081 | + $sql .= " AND tc.code = '".$code."'"; |
|
| 1082 | + $sql .= " AND tc.active = 1"; |
|
| 1083 | + if ($status) $sql .= " AND ec.statut = ".$status; |
|
| 1084 | 1084 | |
| 1085 | 1085 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
| 1086 | - $resql=$this->db->query($sql); |
|
| 1086 | + $resql = $this->db->query($sql); |
|
| 1087 | 1087 | if ($resql) |
| 1088 | 1088 | { |
| 1089 | 1089 | while ($obj = $this->db->fetch_object($resql)) |
| 1090 | 1090 | { |
| 1091 | - $result[$i]=$obj->fk_socpeople; |
|
| 1091 | + $result[$i] = $obj->fk_socpeople; |
|
| 1092 | 1092 | $i++; |
| 1093 | 1093 | } |
| 1094 | 1094 | } |
| 1095 | 1095 | else |
| 1096 | 1096 | { |
| 1097 | - $this->error=$this->db->error(); |
|
| 1097 | + $this->error = $this->db->error(); |
|
| 1098 | 1098 | return null; |
| 1099 | 1099 | } |
| 1100 | 1100 | |
@@ -1107,15 +1107,15 @@ discard block |
||
| 1107 | 1107 | * @param int $contactid Id du contact. Use this->contactid if empty. |
| 1108 | 1108 | * @return int <0 if KO, >0 if OK |
| 1109 | 1109 | */ |
| 1110 | - function fetch_contact($contactid=null) |
|
| 1110 | + function fetch_contact($contactid = null) |
|
| 1111 | 1111 | { |
| 1112 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 1112 | + if (empty($contactid)) $contactid = $this->contactid; |
|
| 1113 | 1113 | |
| 1114 | 1114 | if (empty($contactid)) return 0; |
| 1115 | 1115 | |
| 1116 | 1116 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
| 1117 | 1117 | $contact = new Contact($this->db); |
| 1118 | - $result=$contact->fetch($contactid); |
|
| 1118 | + $result = $contact->fetch($contactid); |
|
| 1119 | 1119 | $this->contact = $contact; |
| 1120 | 1120 | return $result; |
| 1121 | 1121 | } |
@@ -1126,14 +1126,14 @@ discard block |
||
| 1126 | 1126 | * @param int $force_thirdparty_id Force thirdparty id |
| 1127 | 1127 | * @return int <0 if KO, >0 if OK |
| 1128 | 1128 | */ |
| 1129 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1129 | + function fetch_thirdparty($force_thirdparty_id = 0) |
|
| 1130 | 1130 | { |
| 1131 | 1131 | global $conf; |
| 1132 | 1132 | |
| 1133 | 1133 | if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
| 1134 | 1134 | return 0; |
| 1135 | 1135 | |
| 1136 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 1136 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 1137 | 1137 | |
| 1138 | 1138 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
| 1139 | 1139 | if ($force_thirdparty_id) |
@@ -1194,7 +1194,7 @@ discard block |
||
| 1194 | 1194 | |
| 1195 | 1195 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
| 1196 | 1196 | |
| 1197 | - $idtype=$this->barcode_type; |
|
| 1197 | + $idtype = $this->barcode_type; |
|
| 1198 | 1198 | if (empty($idtype) && $idtype != '0') // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined |
| 1199 | 1199 | { |
| 1200 | 1200 | if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
@@ -1207,8 +1207,8 @@ discard block |
||
| 1207 | 1207 | if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) // If data not already loaded |
| 1208 | 1208 | { |
| 1209 | 1209 | $sql = "SELECT rowid, code, libelle as label, coder"; |
| 1210 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1211 | - $sql.= " WHERE rowid = ".$idtype; |
|
| 1210 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1211 | + $sql .= " WHERE rowid = ".$idtype; |
|
| 1212 | 1212 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
| 1213 | 1213 | $resql = $this->db->query($sql); |
| 1214 | 1214 | if ($resql) |
@@ -1239,13 +1239,13 @@ discard block |
||
| 1239 | 1239 | { |
| 1240 | 1240 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
| 1241 | 1241 | |
| 1242 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1242 | + if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1243 | 1243 | if (empty($this->fk_project)) return 0; |
| 1244 | 1244 | |
| 1245 | 1245 | $project = new Project($this->db); |
| 1246 | 1246 | $result = $project->fetch($this->fk_project); |
| 1247 | 1247 | |
| 1248 | - $this->projet = $project; // deprecated |
|
| 1248 | + $this->projet = $project; // deprecated |
|
| 1249 | 1249 | $this->project = $project; |
| 1250 | 1250 | return $result; |
| 1251 | 1251 | } |
@@ -1259,7 +1259,7 @@ discard block |
||
| 1259 | 1259 | function fetch_user($userid) |
| 1260 | 1260 | { |
| 1261 | 1261 | $user = new User($this->db); |
| 1262 | - $result=$user->fetch($userid); |
|
| 1262 | + $result = $user->fetch($userid); |
|
| 1263 | 1263 | $this->user = $user; |
| 1264 | 1264 | return $result; |
| 1265 | 1265 | } |
@@ -1294,14 +1294,14 @@ discard block |
||
| 1294 | 1294 | { |
| 1295 | 1295 | global $conf; |
| 1296 | 1296 | |
| 1297 | - $result=false; |
|
| 1297 | + $result = false; |
|
| 1298 | 1298 | |
| 1299 | 1299 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
| 1300 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1301 | - if (! empty($element)) { |
|
| 1302 | - $sql.= " AND entity IN (".getEntity($element).")"; |
|
| 1300 | + $sql .= " WHERE ".$field." = '".$key."'"; |
|
| 1301 | + if (!empty($element)) { |
|
| 1302 | + $sql .= " AND entity IN (".getEntity($element).")"; |
|
| 1303 | 1303 | } else { |
| 1304 | - $sql.= " AND entity = ".$conf->entity; |
|
| 1304 | + $sql .= " AND entity = ".$conf->entity; |
|
| 1305 | 1305 | } |
| 1306 | 1306 | |
| 1307 | 1307 | dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
@@ -1328,10 +1328,10 @@ discard block |
||
| 1328 | 1328 | */ |
| 1329 | 1329 | function getValueFrom($table, $id, $field) |
| 1330 | 1330 | { |
| 1331 | - $result=false; |
|
| 1331 | + $result = false; |
|
| 1332 | 1332 | if (!empty($id) && !empty($field) && !empty($table)) { |
| 1333 | 1333 | $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
| 1334 | - $sql.= " WHERE rowid = ".$id; |
|
| 1334 | + $sql .= " WHERE rowid = ".$id; |
|
| 1335 | 1335 | |
| 1336 | 1336 | dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
| 1337 | 1337 | $resql = $this->db->query($sql); |
@@ -1359,29 +1359,29 @@ discard block |
||
| 1359 | 1359 | * @return int <0 if KO, >0 if OK |
| 1360 | 1360 | * @see updateExtraField |
| 1361 | 1361 | */ |
| 1362 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='') |
|
| 1362 | + function setValueFrom($field, $value, $table = '', $id = null, $format = '', $id_field = '', $fuser = null, $trigkey = '') |
|
| 1363 | 1363 | { |
| 1364 | - global $user,$langs,$conf; |
|
| 1364 | + global $user, $langs, $conf; |
|
| 1365 | 1365 | |
| 1366 | - if (empty($table)) $table=$this->table_element; |
|
| 1367 | - if (empty($id)) $id=$this->id; |
|
| 1368 | - if (empty($format)) $format='text'; |
|
| 1369 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1366 | + if (empty($table)) $table = $this->table_element; |
|
| 1367 | + if (empty($id)) $id = $this->id; |
|
| 1368 | + if (empty($format)) $format = 'text'; |
|
| 1369 | + if (empty($id_field)) $id_field = 'rowid'; |
|
| 1370 | 1370 | |
| 1371 | - $error=0; |
|
| 1371 | + $error = 0; |
|
| 1372 | 1372 | |
| 1373 | 1373 | $this->db->begin(); |
| 1374 | 1374 | |
| 1375 | 1375 | // Special case |
| 1376 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1376 | + if ($table == 'product' && $field == 'note_private') $field = 'note'; |
|
| 1377 | 1377 | |
| 1378 | 1378 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
| 1379 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1380 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1381 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1382 | - if (! empty($fuser) && is_object($fuser)) $sql.=", fk_user_modif = ".$fuser->id; |
|
| 1383 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", fk_user_modif = ".$user->id; |
|
| 1384 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
| 1379 | + if ($format == 'text') $sql .= $field." = '".$this->db->escape($value)."'"; |
|
| 1380 | + else if ($format == 'int') $sql .= $field." = ".$this->db->escape($value); |
|
| 1381 | + else if ($format == 'date') $sql .= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1382 | + if (!empty($fuser) && is_object($fuser)) $sql .= ", fk_user_modif = ".$fuser->id; |
|
| 1383 | + elseif (empty($fuser) || $fuser != 'none') $sql .= ", fk_user_modif = ".$user->id; |
|
| 1384 | + $sql .= " WHERE ".$id_field." = ".$id; |
|
| 1385 | 1385 | |
| 1386 | 1386 | dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
| 1387 | 1387 | $resql = $this->db->query($sql); |
@@ -1389,11 +1389,11 @@ discard block |
||
| 1389 | 1389 | { |
| 1390 | 1390 | if ($trigkey) |
| 1391 | 1391 | { |
| 1392 | - $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1392 | + $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1393 | 1393 | if ($result < 0) $error++; |
| 1394 | 1394 | } |
| 1395 | 1395 | |
| 1396 | - if (! $error) |
|
| 1396 | + if (!$error) |
|
| 1397 | 1397 | { |
| 1398 | 1398 | if (property_exists($this, $field)) $this->$field = $value; |
| 1399 | 1399 | $this->db->commit(); |
@@ -1407,7 +1407,7 @@ discard block |
||
| 1407 | 1407 | } |
| 1408 | 1408 | else |
| 1409 | 1409 | { |
| 1410 | - $this->error=$this->db->lasterror(); |
|
| 1410 | + $this->error = $this->db->lasterror(); |
|
| 1411 | 1411 | $this->db->rollback(); |
| 1412 | 1412 | return -1; |
| 1413 | 1413 | } |
@@ -1421,13 +1421,13 @@ discard block |
||
| 1421 | 1421 | * @param int $nodbprefix Do not include DB prefix to forge table name |
| 1422 | 1422 | * @return int <0 if KO, >0 if OK |
| 1423 | 1423 | */ |
| 1424 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1424 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) |
|
| 1425 | 1425 | { |
| 1426 | 1426 | global $user; |
| 1427 | 1427 | |
| 1428 | - if (! $this->table_element) |
|
| 1428 | + if (!$this->table_element) |
|
| 1429 | 1429 | { |
| 1430 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
| 1430 | + dol_print_error('', get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined"); |
|
| 1431 | 1431 | return -1; |
| 1432 | 1432 | } |
| 1433 | 1433 | if ($fieldid == 'none') return 1; |
@@ -1442,31 +1442,31 @@ discard block |
||
| 1442 | 1442 | if ($this->element == 'societe') $alias = 'te'; |
| 1443 | 1443 | |
| 1444 | 1444 | $sql = "SELECT MAX(te.".$fieldid.")"; |
| 1445 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1446 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity |
|
| 1447 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid |
|
| 1448 | - else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid |
|
| 1449 | - if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1450 | - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1451 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1452 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1453 | - if (! empty($filter)) |
|
| 1454 | - { |
|
| 1455 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
| 1456 | - $sql.=$filter; |
|
| 1457 | - } |
|
| 1458 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity |
|
| 1459 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid |
|
| 1460 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1461 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1462 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1463 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1445 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1446 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity |
|
| 1447 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid |
|
| 1448 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid |
|
| 1449 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1450 | + $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1451 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
| 1452 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1453 | + if (!empty($filter)) |
|
| 1454 | + { |
|
| 1455 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
| 1456 | + $sql .= $filter; |
|
| 1457 | + } |
|
| 1458 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity |
|
| 1459 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid |
|
| 1460 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1461 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
| 1462 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
| 1463 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
| 1464 | 1464 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1465 | 1465 | |
| 1466 | 1466 | $result = $this->db->query($sql); |
| 1467 | - if (! $result) |
|
| 1467 | + if (!$result) |
|
| 1468 | 1468 | { |
| 1469 | - $this->error=$this->db->lasterror(); |
|
| 1469 | + $this->error = $this->db->lasterror(); |
|
| 1470 | 1470 | return -1; |
| 1471 | 1471 | } |
| 1472 | 1472 | $row = $this->db->fetch_row($result); |
@@ -1474,32 +1474,32 @@ discard block |
||
| 1474 | 1474 | |
| 1475 | 1475 | |
| 1476 | 1476 | $sql = "SELECT MIN(te.".$fieldid.")"; |
| 1477 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1478 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity |
|
| 1479 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid |
|
| 1480 | - else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid |
|
| 1481 | - if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1482 | - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1483 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1484 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1485 | - if (! empty($filter)) |
|
| 1486 | - { |
|
| 1487 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility |
|
| 1488 | - $sql.=$filter; |
|
| 1489 | - } |
|
| 1490 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity |
|
| 1491 | - else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid |
|
| 1492 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1493 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1494 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1495 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1477 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1478 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to entity |
|
| 1479 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid |
|
| 1480 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid |
|
| 1481 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1482 | + $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1483 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
| 1484 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1485 | + if (!empty($filter)) |
|
| 1486 | + { |
|
| 1487 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility |
|
| 1488 | + $sql .= $filter; |
|
| 1489 | + } |
|
| 1490 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity |
|
| 1491 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) $sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid |
|
| 1492 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND te.entity IN ('.getEntity($this->element).')'; |
|
| 1493 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
| 1494 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
| 1495 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
| 1496 | 1496 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1497 | 1497 | // Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null |
| 1498 | 1498 | |
| 1499 | 1499 | $result = $this->db->query($sql); |
| 1500 | - if (! $result) |
|
| 1500 | + if (!$result) |
|
| 1501 | 1501 | { |
| 1502 | - $this->error=$this->db->lasterror(); |
|
| 1502 | + $this->error = $this->db->lasterror(); |
|
| 1503 | 1503 | return -2; |
| 1504 | 1504 | } |
| 1505 | 1505 | $row = $this->db->fetch_row($result); |
@@ -1516,11 +1516,11 @@ discard block |
||
| 1516 | 1516 | * @return array Array of id of contacts (if source=external or internal) |
| 1517 | 1517 | * Array of id of third parties with at least one contact on project (if source=thirdparty) |
| 1518 | 1518 | */ |
| 1519 | - function getListContactId($source='external') |
|
| 1519 | + function getListContactId($source = 'external') |
|
| 1520 | 1520 | { |
| 1521 | 1521 | $contactAlreadySelected = array(); |
| 1522 | - $tab = $this->liste_contact(-1,$source); |
|
| 1523 | - $num=count($tab); |
|
| 1522 | + $tab = $this->liste_contact(-1, $source); |
|
| 1523 | + $num = count($tab); |
|
| 1524 | 1524 | $i = 0; |
| 1525 | 1525 | while ($i < $num) |
| 1526 | 1526 | { |
@@ -1540,24 +1540,24 @@ discard block |
||
| 1540 | 1540 | */ |
| 1541 | 1541 | function setProject($projectid) |
| 1542 | 1542 | { |
| 1543 | - if (! $this->table_element) |
|
| 1543 | + if (!$this->table_element) |
|
| 1544 | 1544 | { |
| 1545 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1545 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR); |
|
| 1546 | 1546 | return -1; |
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | 1549 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1550 | 1550 | if ($this->table_element == 'actioncomm') |
| 1551 | 1551 | { |
| 1552 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1553 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1554 | - $sql.= ' WHERE id = '.$this->id; |
|
| 1552 | + if ($projectid) $sql .= ' SET fk_project = '.$projectid; |
|
| 1553 | + else $sql .= ' SET fk_project = NULL'; |
|
| 1554 | + $sql .= ' WHERE id = '.$this->id; |
|
| 1555 | 1555 | } |
| 1556 | 1556 | else |
| 1557 | 1557 | { |
| 1558 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1559 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1560 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 1558 | + if ($projectid) $sql .= ' SET fk_projet = '.$projectid; |
|
| 1559 | + else $sql .= ' SET fk_projet = NULL'; |
|
| 1560 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 1561 | 1561 | } |
| 1562 | 1562 | |
| 1563 | 1563 | dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
@@ -1603,14 +1603,14 @@ discard block |
||
| 1603 | 1603 | else |
| 1604 | 1604 | { |
| 1605 | 1605 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
| 1606 | - $this->error=$this->db->error(); |
|
| 1606 | + $this->error = $this->db->error(); |
|
| 1607 | 1607 | return -1; |
| 1608 | 1608 | } |
| 1609 | 1609 | } |
| 1610 | 1610 | else |
| 1611 | 1611 | { |
| 1612 | 1612 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
| 1613 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1613 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1614 | 1614 | return -2; |
| 1615 | 1615 | } |
| 1616 | 1616 | } |
@@ -1644,14 +1644,14 @@ discard block |
||
| 1644 | 1644 | else |
| 1645 | 1645 | { |
| 1646 | 1646 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
| 1647 | - $this->error=$this->db->error(); |
|
| 1647 | + $this->error = $this->db->error(); |
|
| 1648 | 1648 | return -1; |
| 1649 | 1649 | } |
| 1650 | 1650 | } |
| 1651 | 1651 | else |
| 1652 | 1652 | { |
| 1653 | 1653 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
| 1654 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1654 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1655 | 1655 | return -2; |
| 1656 | 1656 | } |
| 1657 | 1657 | } |
@@ -1663,7 +1663,7 @@ discard block |
||
| 1663 | 1663 | * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
| 1664 | 1664 | * @return int >0 if OK, <0 if KO |
| 1665 | 1665 | */ |
| 1666 | - function setMulticurrencyRate($rate, $mode=1) |
|
| 1666 | + function setMulticurrencyRate($rate, $mode = 1) |
|
| 1667 | 1667 | { |
| 1668 | 1668 | dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')'); |
| 1669 | 1669 | if ($this->statut >= 0 || $this->element == 'societe') |
@@ -1683,28 +1683,28 @@ discard block |
||
| 1683 | 1683 | { |
| 1684 | 1684 | foreach ($this->lines as &$line) |
| 1685 | 1685 | { |
| 1686 | - if($mode == 1) { |
|
| 1686 | + if ($mode == 1) { |
|
| 1687 | 1687 | $line->subprice = 0; |
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | 1690 | switch ($this->element) { |
| 1691 | 1691 | case 'propal': |
| 1692 | - $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1692 | + $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1693 | 1693 | break; |
| 1694 | 1694 | case 'commande': |
| 1695 | - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1695 | + $this->updateline($line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1696 | 1696 | break; |
| 1697 | 1697 | case 'facture': |
| 1698 | - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1698 | + $this->updateline($line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1699 | 1699 | break; |
| 1700 | 1700 | case 'supplier_proposal': |
| 1701 | - $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, $line->ref_fourn, $line->multicurrency_subprice); |
|
| 1701 | + $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, $line->ref_fourn, $line->multicurrency_subprice); |
|
| 1702 | 1702 | break; |
| 1703 | 1703 | case 'order_supplier': |
| 1704 | - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1704 | + $this->updateline($line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1705 | 1705 | break; |
| 1706 | 1706 | case 'invoice_supplier': |
| 1707 | - $this->updateline($line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1707 | + $this->updateline($line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); |
|
| 1708 | 1708 | break; |
| 1709 | 1709 | default: |
| 1710 | 1710 | dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
@@ -1719,14 +1719,14 @@ discard block |
||
| 1719 | 1719 | else |
| 1720 | 1720 | { |
| 1721 | 1721 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
| 1722 | - $this->error=$this->db->error(); |
|
| 1722 | + $this->error = $this->db->error(); |
|
| 1723 | 1723 | return -1; |
| 1724 | 1724 | } |
| 1725 | 1725 | } |
| 1726 | 1726 | else |
| 1727 | 1727 | { |
| 1728 | 1728 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
| 1729 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1729 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1730 | 1730 | return -2; |
| 1731 | 1731 | } |
| 1732 | 1732 | } |
@@ -1756,20 +1756,20 @@ discard block |
||
| 1756 | 1756 | $this->cond_reglement_id = $id; |
| 1757 | 1757 | // for supplier |
| 1758 | 1758 | if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
| 1759 | - $this->cond_reglement = $id; // for compatibility |
|
| 1759 | + $this->cond_reglement = $id; // for compatibility |
|
| 1760 | 1760 | return 1; |
| 1761 | 1761 | } |
| 1762 | 1762 | else |
| 1763 | 1763 | { |
| 1764 | 1764 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
| 1765 | - $this->error=$this->db->error(); |
|
| 1765 | + $this->error = $this->db->error(); |
|
| 1766 | 1766 | return -1; |
| 1767 | 1767 | } |
| 1768 | 1768 | } |
| 1769 | 1769 | else |
| 1770 | 1770 | { |
| 1771 | 1771 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
| 1772 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1772 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1773 | 1773 | return -2; |
| 1774 | 1774 | } |
| 1775 | 1775 | } |
@@ -1787,7 +1787,7 @@ discard block |
||
| 1787 | 1787 | if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
| 1788 | 1788 | |
| 1789 | 1789 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
| 1790 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1790 | + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1791 | 1791 | |
| 1792 | 1792 | if ($this->db->query($sql)) |
| 1793 | 1793 | { |
@@ -1796,7 +1796,7 @@ discard block |
||
| 1796 | 1796 | } |
| 1797 | 1797 | else |
| 1798 | 1798 | { |
| 1799 | - $this->error=$this->db->error(); |
|
| 1799 | + $this->error = $this->db->error(); |
|
| 1800 | 1800 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
| 1801 | 1801 | return -1; |
| 1802 | 1802 | } |
@@ -1812,29 +1812,29 @@ discard block |
||
| 1812 | 1812 | * |
| 1813 | 1813 | * @return int 1 if OK, 0 if KO |
| 1814 | 1814 | */ |
| 1815 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 1815 | + function setShippingMethod($shipping_method_id, $notrigger = false, $userused = null) |
|
| 1816 | 1816 | { |
| 1817 | 1817 | global $user; |
| 1818 | 1818 | |
| 1819 | - if (empty($userused)) $userused=$user; |
|
| 1819 | + if (empty($userused)) $userused = $user; |
|
| 1820 | 1820 | |
| 1821 | 1821 | $error = 0; |
| 1822 | 1822 | |
| 1823 | - if (! $this->table_element) { |
|
| 1824 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 1823 | + if (!$this->table_element) { |
|
| 1824 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); |
|
| 1825 | 1825 | return -1; |
| 1826 | 1826 | } |
| 1827 | 1827 | |
| 1828 | 1828 | $this->db->begin(); |
| 1829 | 1829 | |
| 1830 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 1830 | + if ($shipping_method_id < 0) $shipping_method_id = 'NULL'; |
|
| 1831 | 1831 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); |
| 1832 | 1832 | |
| 1833 | 1833 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 1834 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 1835 | - $sql.= " WHERE rowid=".$this->id; |
|
| 1834 | + $sql .= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 1835 | + $sql .= " WHERE rowid=".$this->id; |
|
| 1836 | 1836 | $resql = $this->db->query($sql); |
| 1837 | - if (! $resql) { |
|
| 1837 | + if (!$resql) { |
|
| 1838 | 1838 | dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
| 1839 | 1839 | $this->error = $this->db->lasterror(); |
| 1840 | 1840 | $error++; |
@@ -1842,8 +1842,8 @@ discard block |
||
| 1842 | 1842 | if (!$notrigger) |
| 1843 | 1843 | { |
| 1844 | 1844 | // Call trigger |
| 1845 | - $this->context=array('shippingmethodupdate'=>1); |
|
| 1846 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 1845 | + $this->context = array('shippingmethodupdate'=>1); |
|
| 1846 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
| 1847 | 1847 | if ($result < 0) $error++; |
| 1848 | 1848 | // End call trigger |
| 1849 | 1849 | } |
@@ -1853,7 +1853,7 @@ discard block |
||
| 1853 | 1853 | $this->db->rollback(); |
| 1854 | 1854 | return -1; |
| 1855 | 1855 | } else { |
| 1856 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 1856 | + $this->shipping_method_id = ($shipping_method_id == 'NULL') ?null:$shipping_method_id; |
|
| 1857 | 1857 | $this->db->commit(); |
| 1858 | 1858 | return 1; |
| 1859 | 1859 | } |
@@ -1869,23 +1869,23 @@ discard block |
||
| 1869 | 1869 | */ |
| 1870 | 1870 | function setWarehouse($warehouse_id) |
| 1871 | 1871 | { |
| 1872 | - if (! $this->table_element) { |
|
| 1873 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 1872 | + if (!$this->table_element) { |
|
| 1873 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined", LOG_ERR); |
|
| 1874 | 1874 | return -1; |
| 1875 | 1875 | } |
| 1876 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 1876 | + if ($warehouse_id < 0) $warehouse_id = 'NULL'; |
|
| 1877 | 1877 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); |
| 1878 | 1878 | |
| 1879 | 1879 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 1880 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 1881 | - $sql.= " WHERE rowid=".$this->id; |
|
| 1880 | + $sql .= " SET fk_warehouse = ".$warehouse_id; |
|
| 1881 | + $sql .= " WHERE rowid=".$this->id; |
|
| 1882 | 1882 | |
| 1883 | 1883 | if ($this->db->query($sql)) { |
| 1884 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 1884 | + $this->warehouse_id = ($warehouse_id == 'NULL') ?null:$warehouse_id; |
|
| 1885 | 1885 | return 1; |
| 1886 | 1886 | } else { |
| 1887 | 1887 | dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
| 1888 | - $this->error=$this->db->error(); |
|
| 1888 | + $this->error = $this->db->error(); |
|
| 1889 | 1889 | return 0; |
| 1890 | 1890 | } |
| 1891 | 1891 | } |
@@ -1900,25 +1900,25 @@ discard block |
||
| 1900 | 1900 | */ |
| 1901 | 1901 | function setDocModel($user, $modelpdf) |
| 1902 | 1902 | { |
| 1903 | - if (! $this->table_element) |
|
| 1903 | + if (!$this->table_element) |
|
| 1904 | 1904 | { |
| 1905 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 1905 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined", LOG_ERR); |
|
| 1906 | 1906 | return -1; |
| 1907 | 1907 | } |
| 1908 | 1908 | |
| 1909 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 1909 | + $newmodelpdf = dol_trunc($modelpdf, 255); |
|
| 1910 | 1910 | |
| 1911 | 1911 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 1912 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 1913 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 1912 | + $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 1913 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 1914 | 1914 | // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
| 1915 | 1915 | // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
| 1916 | 1916 | |
| 1917 | 1917 | dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
| 1918 | - $resql=$this->db->query($sql); |
|
| 1918 | + $resql = $this->db->query($sql); |
|
| 1919 | 1919 | if ($resql) |
| 1920 | 1920 | { |
| 1921 | - $this->modelpdf=$modelpdf; |
|
| 1921 | + $this->modelpdf = $modelpdf; |
|
| 1922 | 1922 | return 1; |
| 1923 | 1923 | } |
| 1924 | 1924 | else |
@@ -1937,29 +1937,29 @@ discard block |
||
| 1937 | 1937 | * @param User $userused Object user |
| 1938 | 1938 | * @return int 1 if OK, 0 if KO |
| 1939 | 1939 | */ |
| 1940 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 1940 | + function setBankAccount($fk_account, $notrigger = false, $userused = null) |
|
| 1941 | 1941 | { |
| 1942 | 1942 | global $user; |
| 1943 | 1943 | |
| 1944 | - if (empty($userused)) $userused=$user; |
|
| 1944 | + if (empty($userused)) $userused = $user; |
|
| 1945 | 1945 | |
| 1946 | 1946 | $error = 0; |
| 1947 | 1947 | |
| 1948 | - if (! $this->table_element) { |
|
| 1949 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 1948 | + if (!$this->table_element) { |
|
| 1949 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); |
|
| 1950 | 1950 | return -1; |
| 1951 | 1951 | } |
| 1952 | 1952 | $this->db->begin(); |
| 1953 | 1953 | |
| 1954 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 1954 | + if ($fk_account < 0) $fk_account = 'NULL'; |
|
| 1955 | 1955 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); |
| 1956 | 1956 | |
| 1957 | 1957 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 1958 | - $sql.= " SET fk_account = ".$fk_account; |
|
| 1959 | - $sql.= " WHERE rowid=".$this->id; |
|
| 1958 | + $sql .= " SET fk_account = ".$fk_account; |
|
| 1959 | + $sql .= " WHERE rowid=".$this->id; |
|
| 1960 | 1960 | |
| 1961 | 1961 | $resql = $this->db->query($sql); |
| 1962 | - if (! $resql) |
|
| 1962 | + if (!$resql) |
|
| 1963 | 1963 | { |
| 1964 | 1964 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
| 1965 | 1965 | $this->error = $this->db->lasterror(); |
@@ -1970,8 +1970,8 @@ discard block |
||
| 1970 | 1970 | if (!$notrigger) |
| 1971 | 1971 | { |
| 1972 | 1972 | // Call trigger |
| 1973 | - $this->context=array('bankaccountupdate'=>1); |
|
| 1974 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 1973 | + $this->context = array('bankaccountupdate'=>1); |
|
| 1974 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
| 1975 | 1975 | if ($result < 0) $error++; |
| 1976 | 1976 | // End call trigger |
| 1977 | 1977 | } |
@@ -1983,7 +1983,7 @@ discard block |
||
| 1983 | 1983 | } |
| 1984 | 1984 | else |
| 1985 | 1985 | { |
| 1986 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 1986 | + $this->fk_account = ($fk_account == 'NULL') ?null:$fk_account; |
|
| 1987 | 1987 | $this->db->commit(); |
| 1988 | 1988 | return 1; |
| 1989 | 1989 | } |
@@ -2001,25 +2001,25 @@ discard block |
||
| 2001 | 2001 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2002 | 2002 | * @return int <0 if KO, >0 if OK |
| 2003 | 2003 | */ |
| 2004 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2004 | + function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line = true) |
|
| 2005 | 2005 | { |
| 2006 | - if (! $this->table_element_line) |
|
| 2006 | + if (!$this->table_element_line) |
|
| 2007 | 2007 | { |
| 2008 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2008 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined", LOG_ERR); |
|
| 2009 | 2009 | return -1; |
| 2010 | 2010 | } |
| 2011 | - if (! $this->fk_element) |
|
| 2011 | + if (!$this->fk_element) |
|
| 2012 | 2012 | { |
| 2013 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2013 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined", LOG_ERR); |
|
| 2014 | 2014 | return -1; |
| 2015 | 2015 | } |
| 2016 | 2016 | |
| 2017 | 2017 | // Count number of lines to reorder (according to choice $renum) |
| 2018 | - $nl=0; |
|
| 2018 | + $nl = 0; |
|
| 2019 | 2019 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2020 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2021 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2022 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2020 | + $sql .= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2021 | + if (!$renum) $sql .= ' AND rang = 0'; |
|
| 2022 | + if ($renum) $sql .= ' AND rang <> 0'; |
|
| 2023 | 2023 | |
| 2024 | 2024 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
| 2025 | 2025 | $resql = $this->db->query($sql); |
@@ -2033,28 +2033,28 @@ discard block |
||
| 2033 | 2033 | { |
| 2034 | 2034 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
| 2035 | 2035 | // counter that parents. |
| 2036 | - $rows=array(); |
|
| 2036 | + $rows = array(); |
|
| 2037 | 2037 | |
| 2038 | 2038 | // We first search all lines that are parent lines (for multilevel details lines) |
| 2039 | 2039 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2040 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2041 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2042 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2040 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2041 | + if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL'; |
|
| 2042 | + $sql .= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2043 | 2043 | |
| 2044 | 2044 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
| 2045 | 2045 | $resql = $this->db->query($sql); |
| 2046 | 2046 | if ($resql) |
| 2047 | 2047 | { |
| 2048 | - $i=0; |
|
| 2048 | + $i = 0; |
|
| 2049 | 2049 | $num = $this->db->num_rows($resql); |
| 2050 | 2050 | while ($i < $num) |
| 2051 | 2051 | { |
| 2052 | 2052 | $row = $this->db->fetch_row($resql); |
| 2053 | - $rows[] = $row[0]; // Add parent line into array rows |
|
| 2053 | + $rows[] = $row[0]; // Add parent line into array rows |
|
| 2054 | 2054 | $childrens = $this->getChildrenOfLine($row[0]); |
| 2055 | - if (! empty($childrens)) |
|
| 2055 | + if (!empty($childrens)) |
|
| 2056 | 2056 | { |
| 2057 | - foreach($childrens as $child) |
|
| 2057 | + foreach ($childrens as $child) |
|
| 2058 | 2058 | { |
| 2059 | 2059 | array_push($rows, $child); |
| 2060 | 2060 | } |
@@ -2063,11 +2063,11 @@ discard block |
||
| 2063 | 2063 | } |
| 2064 | 2064 | |
| 2065 | 2065 | // Now we set a new number for each lines (parent and children with children included into parent tree) |
| 2066 | - if (! empty($rows)) |
|
| 2066 | + if (!empty($rows)) |
|
| 2067 | 2067 | { |
| 2068 | - foreach($rows as $key => $row) |
|
| 2068 | + foreach ($rows as $key => $row) |
|
| 2069 | 2069 | { |
| 2070 | - $this->updateRangOfLine($row, ($key+1)); |
|
| 2070 | + $this->updateRangOfLine($row, ($key + 1)); |
|
| 2071 | 2071 | } |
| 2072 | 2072 | } |
| 2073 | 2073 | } |
@@ -2087,18 +2087,18 @@ discard block |
||
| 2087 | 2087 | */ |
| 2088 | 2088 | function getChildrenOfLine($id) |
| 2089 | 2089 | { |
| 2090 | - $rows=array(); |
|
| 2090 | + $rows = array(); |
|
| 2091 | 2091 | |
| 2092 | 2092 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2093 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2094 | - $sql.= ' AND fk_parent_line = '.$id; |
|
| 2095 | - $sql.= ' ORDER BY rang ASC'; |
|
| 2093 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2094 | + $sql .= ' AND fk_parent_line = '.$id; |
|
| 2095 | + $sql .= ' ORDER BY rang ASC'; |
|
| 2096 | 2096 | |
| 2097 | 2097 | dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
| 2098 | 2098 | $resql = $this->db->query($sql); |
| 2099 | 2099 | if ($resql) |
| 2100 | 2100 | { |
| 2101 | - $i=0; |
|
| 2101 | + $i = 0; |
|
| 2102 | 2102 | $num = $this->db->num_rows($resql); |
| 2103 | 2103 | while ($i < $num) |
| 2104 | 2104 | { |
@@ -2118,7 +2118,7 @@ discard block |
||
| 2118 | 2118 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2119 | 2119 | * @return void |
| 2120 | 2120 | */ |
| 2121 | - function line_up($rowid, $fk_parent_line=true) |
|
| 2121 | + function line_up($rowid, $fk_parent_line = true) |
|
| 2122 | 2122 | { |
| 2123 | 2123 | $this->line_order(false, 'ASC', $fk_parent_line); |
| 2124 | 2124 | |
@@ -2136,7 +2136,7 @@ discard block |
||
| 2136 | 2136 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2137 | 2137 | * @return void |
| 2138 | 2138 | */ |
| 2139 | - function line_down($rowid, $fk_parent_line=true) |
|
| 2139 | + function line_down($rowid, $fk_parent_line = true) |
|
| 2140 | 2140 | { |
| 2141 | 2141 | $this->line_order(false, 'ASC', $fk_parent_line); |
| 2142 | 2142 | |
@@ -2157,16 +2157,16 @@ discard block |
||
| 2157 | 2157 | * @param int $rang Position |
| 2158 | 2158 | * @return void |
| 2159 | 2159 | */ |
| 2160 | - function updateRangOfLine($rowid,$rang) |
|
| 2160 | + function updateRangOfLine($rowid, $rang) |
|
| 2161 | 2161 | { |
| 2162 | 2162 | $fieldposition = 'rang'; |
| 2163 | 2163 | if ($this->table_element_line == 'ecm_files') $fieldposition = 'position'; |
| 2164 | 2164 | |
| 2165 | 2165 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2166 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2166 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2167 | 2167 | |
| 2168 | 2168 | dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
| 2169 | - if (! $this->db->query($sql)) |
|
| 2169 | + if (!$this->db->query($sql)) |
|
| 2170 | 2170 | { |
| 2171 | 2171 | dol_print_error($this->db); |
| 2172 | 2172 | } |
@@ -2181,9 +2181,9 @@ discard block |
||
| 2181 | 2181 | function line_ajaxorder($rows) |
| 2182 | 2182 | { |
| 2183 | 2183 | $num = count($rows); |
| 2184 | - for ($i = 0 ; $i < $num ; $i++) |
|
| 2184 | + for ($i = 0; $i < $num; $i++) |
|
| 2185 | 2185 | { |
| 2186 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2186 | + $this->updateRangOfLine($rows[$i], ($i + 1)); |
|
| 2187 | 2187 | } |
| 2188 | 2188 | } |
| 2189 | 2189 | |
@@ -2194,18 +2194,18 @@ discard block |
||
| 2194 | 2194 | * @param int $rang Position |
| 2195 | 2195 | * @return void |
| 2196 | 2196 | */ |
| 2197 | - function updateLineUp($rowid,$rang) |
|
| 2197 | + function updateLineUp($rowid, $rang) |
|
| 2198 | 2198 | { |
| 2199 | - if ($rang > 1 ) |
|
| 2199 | + if ($rang > 1) |
|
| 2200 | 2200 | { |
| 2201 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.$rang ; |
|
| 2202 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2203 | - $sql.= ' AND rang = '.($rang - 1); |
|
| 2204 | - if ($this->db->query($sql) ) |
|
| 2201 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.$rang; |
|
| 2202 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2203 | + $sql .= ' AND rang = '.($rang - 1); |
|
| 2204 | + if ($this->db->query($sql)) |
|
| 2205 | 2205 | { |
| 2206 | 2206 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.($rang - 1); |
| 2207 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2208 | - if (! $this->db->query($sql) ) |
|
| 2207 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2208 | + if (!$this->db->query($sql)) |
|
| 2209 | 2209 | { |
| 2210 | 2210 | dol_print_error($this->db); |
| 2211 | 2211 | } |
@@ -2225,18 +2225,18 @@ discard block |
||
| 2225 | 2225 | * @param int $max Max |
| 2226 | 2226 | * @return void |
| 2227 | 2227 | */ |
| 2228 | - function updateLineDown($rowid,$rang,$max) |
|
| 2228 | + function updateLineDown($rowid, $rang, $max) |
|
| 2229 | 2229 | { |
| 2230 | 2230 | if ($rang < $max) |
| 2231 | 2231 | { |
| 2232 | 2232 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.$rang; |
| 2233 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2234 | - $sql.= ' AND rang = '.($rang+1); |
|
| 2235 | - if ($this->db->query($sql) ) |
|
| 2233 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2234 | + $sql .= ' AND rang = '.($rang + 1); |
|
| 2235 | + if ($this->db->query($sql)) |
|
| 2236 | 2236 | { |
| 2237 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.($rang+1); |
|
| 2238 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2239 | - if (! $this->db->query($sql) ) |
|
| 2237 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET rang = '.($rang + 1); |
|
| 2238 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2239 | + if (!$this->db->query($sql)) |
|
| 2240 | 2240 | { |
| 2241 | 2241 | dol_print_error($this->db); |
| 2242 | 2242 | } |
@@ -2257,7 +2257,7 @@ discard block |
||
| 2257 | 2257 | function getRangOfLine($rowid) |
| 2258 | 2258 | { |
| 2259 | 2259 | $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2260 | - $sql.= ' WHERE rowid ='.$rowid; |
|
| 2260 | + $sql .= ' WHERE rowid ='.$rowid; |
|
| 2261 | 2261 | |
| 2262 | 2262 | dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
| 2263 | 2263 | $resql = $this->db->query($sql); |
@@ -2277,8 +2277,8 @@ discard block |
||
| 2277 | 2277 | function getIdOfLine($rang) |
| 2278 | 2278 | { |
| 2279 | 2279 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2280 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2281 | - $sql.= ' AND rang = '.$rang; |
|
| 2280 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2281 | + $sql .= ' AND rang = '.$rang; |
|
| 2282 | 2282 | $resql = $this->db->query($sql); |
| 2283 | 2283 | if ($resql) |
| 2284 | 2284 | { |
@@ -2293,21 +2293,21 @@ discard block |
||
| 2293 | 2293 | * @param int $fk_parent_line Parent line id |
| 2294 | 2294 | * @return int Max value of rang in table of lines |
| 2295 | 2295 | */ |
| 2296 | - function line_max($fk_parent_line=0) |
|
| 2296 | + function line_max($fk_parent_line = 0) |
|
| 2297 | 2297 | { |
| 2298 | 2298 | // Search the last rang with fk_parent_line |
| 2299 | 2299 | if ($fk_parent_line) |
| 2300 | 2300 | { |
| 2301 | 2301 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2302 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2303 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2302 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2303 | + $sql .= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2304 | 2304 | |
| 2305 | 2305 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
| 2306 | 2306 | $resql = $this->db->query($sql); |
| 2307 | 2307 | if ($resql) |
| 2308 | 2308 | { |
| 2309 | 2309 | $row = $this->db->fetch_row($resql); |
| 2310 | - if (! empty($row[0])) |
|
| 2310 | + if (!empty($row[0])) |
|
| 2311 | 2311 | { |
| 2312 | 2312 | return $row[0]; |
| 2313 | 2313 | } |
@@ -2321,7 +2321,7 @@ discard block |
||
| 2321 | 2321 | else |
| 2322 | 2322 | { |
| 2323 | 2323 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2324 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2324 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2325 | 2325 | |
| 2326 | 2326 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
| 2327 | 2327 | $resql = $this->db->query($sql); |
@@ -2341,15 +2341,15 @@ discard block |
||
| 2341 | 2341 | */ |
| 2342 | 2342 | function update_ref_ext($ref_ext) |
| 2343 | 2343 | { |
| 2344 | - if (! $this->table_element) |
|
| 2344 | + if (!$this->table_element) |
|
| 2345 | 2345 | { |
| 2346 | 2346 | dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
| 2347 | 2347 | return -1; |
| 2348 | 2348 | } |
| 2349 | 2349 | |
| 2350 | 2350 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2351 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2352 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2351 | + $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2352 | + $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".$this->id; |
|
| 2353 | 2353 | |
| 2354 | 2354 | dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
| 2355 | 2355 | if ($this->db->query($sql)) |
@@ -2359,7 +2359,7 @@ discard block |
||
| 2359 | 2359 | } |
| 2360 | 2360 | else |
| 2361 | 2361 | { |
| 2362 | - $this->error=$this->db->error(); |
|
| 2362 | + $this->error = $this->db->error(); |
|
| 2363 | 2363 | return -1; |
| 2364 | 2364 | } |
| 2365 | 2365 | } |
@@ -2371,28 +2371,28 @@ discard block |
||
| 2371 | 2371 | * @param string $suffix '', '_public' or '_private' |
| 2372 | 2372 | * @return int <0 if KO, >0 if OK |
| 2373 | 2373 | */ |
| 2374 | - function update_note($note,$suffix='') |
|
| 2374 | + function update_note($note, $suffix = '') |
|
| 2375 | 2375 | { |
| 2376 | 2376 | global $user; |
| 2377 | 2377 | |
| 2378 | - if (! $this->table_element) |
|
| 2378 | + if (!$this->table_element) |
|
| 2379 | 2379 | { |
| 2380 | 2380 | dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
| 2381 | 2381 | return -1; |
| 2382 | 2382 | } |
| 2383 | - if (! in_array($suffix,array('','_public','_private'))) |
|
| 2383 | + if (!in_array($suffix, array('', '_public', '_private'))) |
|
| 2384 | 2384 | { |
| 2385 | 2385 | dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
| 2386 | 2386 | return -2; |
| 2387 | 2387 | } |
| 2388 | 2388 | // Special cas |
| 2389 | 2389 | //var_dump($this->table_element);exit; |
| 2390 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2390 | + if ($this->table_element == 'product') $suffix = ''; |
|
| 2391 | 2391 | |
| 2392 | 2392 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2393 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); |
|
| 2394 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; |
|
| 2395 | - $sql.= " WHERE rowid =". $this->id; |
|
| 2393 | + $sql .= " SET note".$suffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); |
|
| 2394 | + $sql .= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment')) ? "fk_user_mod" : "fk_user_modif")." = ".$user->id; |
|
| 2395 | + $sql .= " WHERE rowid =".$this->id; |
|
| 2396 | 2396 | |
| 2397 | 2397 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
| 2398 | 2398 | if ($this->db->query($sql)) |
@@ -2401,14 +2401,14 @@ discard block |
||
| 2401 | 2401 | else if ($suffix == '_private') $this->note_private = $note; |
| 2402 | 2402 | else |
| 2403 | 2403 | { |
| 2404 | - $this->note = $note; // deprecated |
|
| 2404 | + $this->note = $note; // deprecated |
|
| 2405 | 2405 | $this->note_private = $note; |
| 2406 | 2406 | } |
| 2407 | 2407 | return 1; |
| 2408 | 2408 | } |
| 2409 | 2409 | else |
| 2410 | 2410 | { |
| 2411 | - $this->error=$this->db->lasterror(); |
|
| 2411 | + $this->error = $this->db->lasterror(); |
|
| 2412 | 2412 | return -1; |
| 2413 | 2413 | } |
| 2414 | 2414 | } |
@@ -2423,7 +2423,7 @@ discard block |
||
| 2423 | 2423 | */ |
| 2424 | 2424 | function update_note_public($note) |
| 2425 | 2425 | { |
| 2426 | - return $this->update_note($note,'_public'); |
|
| 2426 | + return $this->update_note($note, '_public'); |
|
| 2427 | 2427 | } |
| 2428 | 2428 | |
| 2429 | 2429 | /** |
@@ -2436,7 +2436,7 @@ discard block |
||
| 2436 | 2436 | * @param Societe $seller If roundingadjust is '0' or '1' or maybe 'auto', it means we recalculate total for lines before calculating total for object and for this, we need seller object. |
| 2437 | 2437 | * @return int <0 if KO, >0 if OK |
| 2438 | 2438 | */ |
| 2439 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2439 | + function update_price($exclspec = 0, $roundingadjust = 'none', $nodatabaseupdate = 0, $seller = null) |
|
| 2440 | 2440 | { |
| 2441 | 2441 | global $conf; |
| 2442 | 2442 | |
@@ -2455,8 +2455,8 @@ discard block |
||
| 2455 | 2455 | elseif ($this->element == 'supplier_proposal') |
| 2456 | 2456 | $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
| 2457 | 2457 | |
| 2458 | - if (! empty($MODULE)) { |
|
| 2459 | - if (! empty($conf->global->$MODULE)) { |
|
| 2458 | + if (!empty($MODULE)) { |
|
| 2459 | + if (!empty($conf->global->$MODULE)) { |
|
| 2460 | 2460 | $modsactivated = explode(',', $conf->global->$MODULE); |
| 2461 | 2461 | foreach ($modsactivated as $mod) { |
| 2462 | 2462 | if ($conf->$mod->enabled) |
@@ -2467,44 +2467,44 @@ discard block |
||
| 2467 | 2467 | |
| 2468 | 2468 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
| 2469 | 2469 | |
| 2470 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2470 | + if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility |
|
| 2471 | 2471 | |
| 2472 | - $forcedroundingmode=$roundingadjust; |
|
| 2473 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2474 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2472 | + $forcedroundingmode = $roundingadjust; |
|
| 2473 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2474 | + elseif ($forcedroundingmode == 'auto') $forcedroundingmode = '0'; |
|
| 2475 | 2475 | |
| 2476 | - $error=0; |
|
| 2476 | + $error = 0; |
|
| 2477 | 2477 | |
| 2478 | 2478 | $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
| 2479 | 2479 | |
| 2480 | 2480 | // Define constants to find lines to sum |
| 2481 | - $fieldtva='total_tva'; |
|
| 2482 | - $fieldlocaltax1='total_localtax1'; |
|
| 2483 | - $fieldlocaltax2='total_localtax2'; |
|
| 2484 | - $fieldup='subprice'; |
|
| 2481 | + $fieldtva = 'total_tva'; |
|
| 2482 | + $fieldlocaltax1 = 'total_localtax1'; |
|
| 2483 | + $fieldlocaltax2 = 'total_localtax2'; |
|
| 2484 | + $fieldup = 'subprice'; |
|
| 2485 | 2485 | if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
| 2486 | 2486 | { |
| 2487 | - $fieldtva='tva'; |
|
| 2488 | - $fieldup='pu_ht'; |
|
| 2487 | + $fieldtva = 'tva'; |
|
| 2488 | + $fieldup = 'pu_ht'; |
|
| 2489 | 2489 | } |
| 2490 | 2490 | if ($this->element == 'expensereport') |
| 2491 | 2491 | { |
| 2492 | - $fieldup='value_unit'; |
|
| 2492 | + $fieldup = 'value_unit'; |
|
| 2493 | 2493 | } |
| 2494 | 2494 | |
| 2495 | 2495 | $sql = 'SELECT rowid, qty, '.$fieldup.' as up, remise_percent, total_ht, '.$fieldtva.' as total_tva, total_ttc, '.$fieldlocaltax1.' as total_localtax1, '.$fieldlocaltax2.' as total_localtax2,'; |
| 2496 | - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2497 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2498 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2499 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2500 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2496 | + $sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2497 | + if ($this->table_element_line == 'facturedet') $sql .= ', situation_percent'; |
|
| 2498 | + $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2499 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2500 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2501 | 2501 | if ($exclspec) |
| 2502 | 2502 | { |
| 2503 | - $product_field='product_type'; |
|
| 2504 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2505 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2503 | + $product_field = 'product_type'; |
|
| 2504 | + if ($this->table_element_line == 'contratdet') $product_field = ''; // contratdet table has no product_type field |
|
| 2505 | + if ($product_field) $sql .= ' AND '.$product_field.' <> 9'; |
|
| 2506 | 2506 | } |
| 2507 | - $sql.= ' ORDER by rowid'; // We want to be sure to always use same order of line to not change lines differently when option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND is used |
|
| 2507 | + $sql .= ' ORDER by rowid'; // We want to be sure to always use same order of line to not change lines differently when option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND is used |
|
| 2508 | 2508 | |
| 2509 | 2509 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
| 2510 | 2510 | $resql = $this->db->query($sql); |
@@ -2518,7 +2518,7 @@ discard block |
||
| 2518 | 2518 | $total_ht_by_vats = array(); |
| 2519 | 2519 | $total_tva_by_vats = array(); |
| 2520 | 2520 | $total_ttc_by_vats = array(); |
| 2521 | - $this->multicurrency_total_ht = 0; |
|
| 2521 | + $this->multicurrency_total_ht = 0; |
|
| 2522 | 2522 | $this->multicurrency_total_tva = 0; |
| 2523 | 2523 | $this->multicurrency_total_ttc = 0; |
| 2524 | 2524 | |
@@ -2531,49 +2531,49 @@ discard block |
||
| 2531 | 2531 | // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
| 2532 | 2532 | if ($forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
| 2533 | 2533 | { |
| 2534 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2535 | - $tmpcal=calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx); |
|
| 2536 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2534 | + $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx); |
|
| 2535 | + $tmpcal = calcul_price_total($obj->qty, $obj->up, $obj->remise_percent, $obj->vatrate, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->product_type, $seller, $localtax_array, (isset($obj->situation_percent) ? $obj->situation_percent : 100), $multicurrency_tx); |
|
| 2536 | + $diff = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2537 | 2537 | if ($diff) |
| 2538 | 2538 | { |
| 2539 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2539 | + $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2540 | 2540 | dol_syslog('We found unconsistent data into detailed line (difference of '.$diff.') for line rowid = '.$obj->rowid." (total vat of line calculated=".$tmpcal[1].", database=".$obj->total_tva."). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix); |
| 2541 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2542 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2541 | + $resqlfix = $this->db->query($sqlfix); |
|
| 2542 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
| 2543 | 2543 | $obj->total_tva = $tmpcal[1]; |
| 2544 | 2544 | $obj->total_ttc = $tmpcal[2]; |
| 2545 | 2545 | // |
| 2546 | 2546 | } |
| 2547 | 2547 | } |
| 2548 | 2548 | |
| 2549 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2549 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2550 | 2550 | $this->total_tva += $obj->total_tva; |
| 2551 | 2551 | $this->total_localtax1 += $obj->total_localtax1; |
| 2552 | 2552 | $this->total_localtax2 += $obj->total_localtax2; |
| 2553 | 2553 | $this->total_ttc += $obj->total_ttc; |
| 2554 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2554 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2555 | 2555 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
| 2556 | 2556 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
| 2557 | 2557 | |
| 2558 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2559 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2560 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 2558 | + if (!isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate] = 0; |
|
| 2559 | + if (!isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate] = 0; |
|
| 2560 | + if (!isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate] = 0; |
|
| 2561 | 2561 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
| 2562 | 2562 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
| 2563 | 2563 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
| 2564 | 2564 | |
| 2565 | 2565 | if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
| 2566 | 2566 | { |
| 2567 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2568 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2567 | + $tmpvat = price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2568 | + $diff = price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat, 'MT', 1); |
|
| 2569 | 2569 | //print 'Line '.$i.' rowid='.$obj->rowid.' vat_rate='.$obj->vatrate.' total_ht='.$obj->total_ht.' total_tva='.$obj->total_tva.' total_ttc='.$obj->total_ttc.' total_ht_by_vats='.$total_ht_by_vats[$obj->vatrate].' total_tva_by_vats='.$total_tva_by_vats[$obj->vatrate].' (new calculation = '.$tmpvat.') total_ttc_by_vats='.$total_ttc_by_vats[$obj->vatrate].($diff?" => DIFF":"")."<br>\n"; |
| 2570 | 2570 | if ($diff) |
| 2571 | 2571 | { |
| 2572 | 2572 | if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; } |
| 2573 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".($obj->total_tva - $diff).", total_ttc = ".($obj->total_ttc - $diff)." WHERE rowid = ".$obj->rowid; |
|
| 2573 | + $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".($obj->total_tva - $diff).", total_ttc = ".($obj->total_ttc - $diff)." WHERE rowid = ".$obj->rowid; |
|
| 2574 | 2574 | dol_syslog('We found a difference of '.$diff.' for line rowid = '.$obj->rowid.". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix); |
| 2575 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2576 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2575 | + $resqlfix = $this->db->query($sqlfix); |
|
| 2576 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
| 2577 | 2577 | $this->total_tva -= $diff; |
| 2578 | 2578 | $this->total_ttc -= $diff; |
| 2579 | 2579 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2586,8 +2586,8 @@ discard block |
||
| 2586 | 2586 | } |
| 2587 | 2587 | |
| 2588 | 2588 | // Add revenue stamp to total |
| 2589 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2590 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 2589 | + $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0; |
|
| 2590 | + $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0; |
|
| 2591 | 2591 | |
| 2592 | 2592 | // Situations totals |
| 2593 | 2593 | if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits')) |
@@ -2609,17 +2609,17 @@ discard block |
||
| 2609 | 2609 | $this->db->free($resql); |
| 2610 | 2610 | |
| 2611 | 2611 | // Now update global field total_ht, total_ttc and tva |
| 2612 | - $fieldht='total_ht'; |
|
| 2613 | - $fieldtva='tva'; |
|
| 2614 | - $fieldlocaltax1='localtax1'; |
|
| 2615 | - $fieldlocaltax2='localtax2'; |
|
| 2616 | - $fieldttc='total_ttc'; |
|
| 2612 | + $fieldht = 'total_ht'; |
|
| 2613 | + $fieldtva = 'tva'; |
|
| 2614 | + $fieldlocaltax1 = 'localtax1'; |
|
| 2615 | + $fieldlocaltax2 = 'localtax2'; |
|
| 2616 | + $fieldttc = 'total_ttc'; |
|
| 2617 | 2617 | // Specific code for backward compatibility with old field names |
| 2618 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2619 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2620 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2621 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2622 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 2618 | + if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht = 'total'; |
|
| 2619 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva'; |
|
| 2620 | + if ($this->element == 'propal') $fieldttc = 'total'; |
|
| 2621 | + if ($this->element == 'expensereport') $fieldtva = 'total_tva'; |
|
| 2622 | + if ($this->element == 'supplier_proposal') $fieldttc = 'total'; |
|
| 2623 | 2623 | |
| 2624 | 2624 | if (empty($nodatabaseupdate)) |
| 2625 | 2625 | { |
@@ -2636,16 +2636,16 @@ discard block |
||
| 2636 | 2636 | |
| 2637 | 2637 | //print "xx".$sql; |
| 2638 | 2638 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
| 2639 | - $resql=$this->db->query($sql); |
|
| 2640 | - if (! $resql) |
|
| 2639 | + $resql = $this->db->query($sql); |
|
| 2640 | + if (!$resql) |
|
| 2641 | 2641 | { |
| 2642 | 2642 | $error++; |
| 2643 | - $this->error=$this->db->lasterror(); |
|
| 2644 | - $this->errors[]=$this->db->lasterror(); |
|
| 2643 | + $this->error = $this->db->lasterror(); |
|
| 2644 | + $this->errors[] = $this->db->lasterror(); |
|
| 2645 | 2645 | } |
| 2646 | 2646 | } |
| 2647 | 2647 | |
| 2648 | - if (! $error) |
|
| 2648 | + if (!$error) |
|
| 2649 | 2649 | { |
| 2650 | 2650 | return 1; |
| 2651 | 2651 | } |
@@ -2656,7 +2656,7 @@ discard block |
||
| 2656 | 2656 | } |
| 2657 | 2657 | else |
| 2658 | 2658 | { |
| 2659 | - dol_print_error($this->db,'Bad request in update_price'); |
|
| 2659 | + dol_print_error($this->db, 'Bad request in update_price'); |
|
| 2660 | 2660 | return -1; |
| 2661 | 2661 | } |
| 2662 | 2662 | } |
@@ -2669,28 +2669,28 @@ discard block |
||
| 2669 | 2669 | * @return int <=0 if KO, >0 if OK |
| 2670 | 2670 | * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
| 2671 | 2671 | */ |
| 2672 | - function add_object_linked($origin=null, $origin_id=null) |
|
| 2672 | + function add_object_linked($origin = null, $origin_id = null) |
|
| 2673 | 2673 | { |
| 2674 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2675 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2674 | + $origin = (!empty($origin) ? $origin : $this->origin); |
|
| 2675 | + $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2676 | 2676 | |
| 2677 | 2677 | // Special case |
| 2678 | - if ($origin == 'order') $origin='commande'; |
|
| 2679 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2678 | + if ($origin == 'order') $origin = 'commande'; |
|
| 2679 | + if ($origin == 'invoice') $origin = 'facture'; |
|
| 2680 | 2680 | |
| 2681 | 2681 | $this->db->begin(); |
| 2682 | 2682 | |
| 2683 | 2683 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; |
| 2684 | - $sql.= "fk_source"; |
|
| 2685 | - $sql.= ", sourcetype"; |
|
| 2686 | - $sql.= ", fk_target"; |
|
| 2687 | - $sql.= ", targettype"; |
|
| 2688 | - $sql.= ") VALUES ("; |
|
| 2689 | - $sql.= $origin_id; |
|
| 2690 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2691 | - $sql.= ", ".$this->id; |
|
| 2692 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2693 | - $sql.= ")"; |
|
| 2684 | + $sql .= "fk_source"; |
|
| 2685 | + $sql .= ", sourcetype"; |
|
| 2686 | + $sql .= ", fk_target"; |
|
| 2687 | + $sql .= ", targettype"; |
|
| 2688 | + $sql .= ") VALUES ("; |
|
| 2689 | + $sql .= $origin_id; |
|
| 2690 | + $sql .= ", '".$this->db->escape($origin)."'"; |
|
| 2691 | + $sql .= ", ".$this->id; |
|
| 2692 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
| 2693 | + $sql .= ")"; |
|
| 2694 | 2694 | |
| 2695 | 2695 | dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
| 2696 | 2696 | if ($this->db->query($sql)) |
@@ -2700,7 +2700,7 @@ discard block |
||
| 2700 | 2700 | } |
| 2701 | 2701 | else |
| 2702 | 2702 | { |
| 2703 | - $this->error=$this->db->lasterror(); |
|
| 2703 | + $this->error = $this->db->lasterror(); |
|
| 2704 | 2704 | $this->db->rollback(); |
| 2705 | 2705 | return 0; |
| 2706 | 2706 | } |
@@ -2724,33 +2724,33 @@ discard block |
||
| 2724 | 2724 | * @return void |
| 2725 | 2725 | * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
| 2726 | 2726 | */ |
| 2727 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1) |
|
| 2727 | + function fetchObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $clause = 'OR', $alsosametype = 1) |
|
| 2728 | 2728 | { |
| 2729 | 2729 | global $conf; |
| 2730 | 2730 | |
| 2731 | - $this->linkedObjectsIds=array(); |
|
| 2732 | - $this->linkedObjects=array(); |
|
| 2731 | + $this->linkedObjectsIds = array(); |
|
| 2732 | + $this->linkedObjects = array(); |
|
| 2733 | 2733 | |
| 2734 | - $justsource=false; |
|
| 2735 | - $justtarget=false; |
|
| 2736 | - $withtargettype=false; |
|
| 2737 | - $withsourcetype=false; |
|
| 2734 | + $justsource = false; |
|
| 2735 | + $justtarget = false; |
|
| 2736 | + $withtargettype = false; |
|
| 2737 | + $withsourcetype = false; |
|
| 2738 | 2738 | |
| 2739 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2739 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) |
|
| 2740 | 2740 | { |
| 2741 | - $justsource=true; // the source (id and type) is a search criteria |
|
| 2742 | - if (! empty($targettype)) $withtargettype=true; |
|
| 2741 | + $justsource = true; // the source (id and type) is a search criteria |
|
| 2742 | + if (!empty($targettype)) $withtargettype = true; |
|
| 2743 | 2743 | } |
| 2744 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2744 | + if (!empty($targetid) && !empty($targettype) && empty($sourceid)) |
|
| 2745 | 2745 | { |
| 2746 | - $justtarget=true; // the target (id and type) is a search criteria |
|
| 2747 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2746 | + $justtarget = true; // the target (id and type) is a search criteria |
|
| 2747 | + if (!empty($sourcetype)) $withsourcetype = true; |
|
| 2748 | 2748 | } |
| 2749 | 2749 | |
| 2750 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2751 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2752 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2753 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2750 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
| 2751 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
| 2752 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2753 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
| 2754 | 2754 | |
| 2755 | 2755 | /*if (empty($sourceid) && empty($targetid)) |
| 2756 | 2756 | { |
@@ -2760,25 +2760,25 @@ discard block |
||
| 2760 | 2760 | |
| 2761 | 2761 | // Links between objects are stored in table element_element |
| 2762 | 2762 | $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
| 2763 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2764 | - $sql.= " WHERE "; |
|
| 2763 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2764 | + $sql .= " WHERE "; |
|
| 2765 | 2765 | if ($justsource || $justtarget) |
| 2766 | 2766 | { |
| 2767 | 2767 | if ($justsource) |
| 2768 | 2768 | { |
| 2769 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2770 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2769 | + $sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2770 | + if ($withtargettype) $sql .= " AND targettype = '".$targettype."'"; |
|
| 2771 | 2771 | } |
| 2772 | 2772 | else if ($justtarget) |
| 2773 | 2773 | { |
| 2774 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2775 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 2774 | + $sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2775 | + if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'"; |
|
| 2776 | 2776 | } |
| 2777 | 2777 | } |
| 2778 | 2778 | else |
| 2779 | 2779 | { |
| 2780 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 2781 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 2780 | + $sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 2781 | + $sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 2782 | 2782 | } |
| 2783 | 2783 | $sql .= ' ORDER BY sourcetype'; |
| 2784 | 2784 | //print $sql; |
@@ -2796,35 +2796,35 @@ discard block |
||
| 2796 | 2796 | { |
| 2797 | 2797 | if ($justsource) |
| 2798 | 2798 | { |
| 2799 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 2799 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
| 2800 | 2800 | } |
| 2801 | 2801 | else if ($justtarget) |
| 2802 | 2802 | { |
| 2803 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 2803 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
| 2804 | 2804 | } |
| 2805 | 2805 | } |
| 2806 | 2806 | else |
| 2807 | 2807 | { |
| 2808 | 2808 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
| 2809 | 2809 | { |
| 2810 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 2810 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
| 2811 | 2811 | } |
| 2812 | 2812 | if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
| 2813 | 2813 | { |
| 2814 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 2814 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
| 2815 | 2815 | } |
| 2816 | 2816 | } |
| 2817 | 2817 | $i++; |
| 2818 | 2818 | } |
| 2819 | 2819 | |
| 2820 | - if (! empty($this->linkedObjectsIds)) |
|
| 2820 | + if (!empty($this->linkedObjectsIds)) |
|
| 2821 | 2821 | { |
| 2822 | - foreach($this->linkedObjectsIds as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
| 2822 | + foreach ($this->linkedObjectsIds as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...) |
|
| 2823 | 2823 | { |
| 2824 | 2824 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
| 2825 | 2825 | $module = $element = $subelement = $objecttype; |
| 2826 | 2826 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
| 2827 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) |
|
| 2827 | + && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) |
|
| 2828 | 2828 | { |
| 2829 | 2829 | $module = $element = $regs[1]; |
| 2830 | 2830 | $subelement = $regs[2]; |
@@ -2832,31 +2832,31 @@ discard block |
||
| 2832 | 2832 | |
| 2833 | 2833 | $classpath = $element.'/class'; |
| 2834 | 2834 | // To work with non standard classpath or module name |
| 2835 | - if ($objecttype == 'facture') { |
|
| 2835 | + if ($objecttype == 'facture') { |
|
| 2836 | 2836 | $classpath = 'compta/facture/class'; |
| 2837 | 2837 | } |
| 2838 | - else if ($objecttype == 'facturerec') { |
|
| 2838 | + else if ($objecttype == 'facturerec') { |
|
| 2839 | 2839 | $classpath = 'compta/facture/class'; $module = 'facture'; |
| 2840 | 2840 | } |
| 2841 | - else if ($objecttype == 'propal') { |
|
| 2841 | + else if ($objecttype == 'propal') { |
|
| 2842 | 2842 | $classpath = 'comm/propal/class'; |
| 2843 | 2843 | } |
| 2844 | - else if ($objecttype == 'supplier_proposal') { |
|
| 2844 | + else if ($objecttype == 'supplier_proposal') { |
|
| 2845 | 2845 | $classpath = 'supplier_proposal/class'; |
| 2846 | 2846 | } |
| 2847 | - else if ($objecttype == 'shipping') { |
|
| 2847 | + else if ($objecttype == 'shipping') { |
|
| 2848 | 2848 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
| 2849 | 2849 | } |
| 2850 | - else if ($objecttype == 'delivery') { |
|
| 2850 | + else if ($objecttype == 'delivery') { |
|
| 2851 | 2851 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
| 2852 | 2852 | } |
| 2853 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
| 2853 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') { |
|
| 2854 | 2854 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
| 2855 | 2855 | } |
| 2856 | - else if ($objecttype == 'fichinter') { |
|
| 2856 | + else if ($objecttype == 'fichinter') { |
|
| 2857 | 2857 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
| 2858 | 2858 | } |
| 2859 | - else if ($objecttype == 'subscription') { |
|
| 2859 | + else if ($objecttype == 'subscription') { |
|
| 2860 | 2860 | $classpath = 'adherents/class'; $module = 'adherent'; |
| 2861 | 2861 | } |
| 2862 | 2862 | |
@@ -2869,16 +2869,16 @@ discard block |
||
| 2869 | 2869 | else if ($objecttype == 'invoice_supplier') { |
| 2870 | 2870 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
| 2871 | 2871 | } |
| 2872 | - else if ($objecttype == 'order_supplier') { |
|
| 2872 | + else if ($objecttype == 'order_supplier') { |
|
| 2873 | 2873 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
| 2874 | 2874 | } |
| 2875 | - else if ($objecttype == 'supplier_proposal') { |
|
| 2875 | + else if ($objecttype == 'supplier_proposal') { |
|
| 2876 | 2876 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
| 2877 | 2877 | } |
| 2878 | - else if ($objecttype == 'facturerec') { |
|
| 2878 | + else if ($objecttype == 'facturerec') { |
|
| 2879 | 2879 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
| 2880 | 2880 | } |
| 2881 | - else if ($objecttype == 'subscription') { |
|
| 2881 | + else if ($objecttype == 'subscription') { |
|
| 2882 | 2882 | $classfile = 'subscription'; $classname = 'Subscription'; |
| 2883 | 2883 | } |
| 2884 | 2884 | |
@@ -2889,7 +2889,7 @@ discard block |
||
| 2889 | 2889 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
| 2890 | 2890 | if (class_exists($classname)) |
| 2891 | 2891 | { |
| 2892 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 2892 | + foreach ($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 2893 | 2893 | { |
| 2894 | 2894 | $object = new $classname($this->db); |
| 2895 | 2895 | $ret = $object->fetch($objectid); |
@@ -2919,28 +2919,28 @@ discard block |
||
| 2919 | 2919 | * @return int >0 if OK, <0 if KO |
| 2920 | 2920 | * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
| 2921 | 2921 | */ |
| 2922 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 2922 | + function updateObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '') |
|
| 2923 | 2923 | { |
| 2924 | - $updatesource=false; |
|
| 2925 | - $updatetarget=false; |
|
| 2924 | + $updatesource = false; |
|
| 2925 | + $updatetarget = false; |
|
| 2926 | 2926 | |
| 2927 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 2928 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 2927 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource = true; |
|
| 2928 | + else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $updatetarget = true; |
|
| 2929 | 2929 | |
| 2930 | 2930 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
| 2931 | 2931 | if ($updatesource) |
| 2932 | 2932 | { |
| 2933 | - $sql.= "fk_source = ".$sourceid; |
|
| 2934 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 2935 | - $sql.= " WHERE fk_target = ".$this->id; |
|
| 2936 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 2933 | + $sql .= "fk_source = ".$sourceid; |
|
| 2934 | + $sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 2935 | + $sql .= " WHERE fk_target = ".$this->id; |
|
| 2936 | + $sql .= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 2937 | 2937 | } |
| 2938 | 2938 | else if ($updatetarget) |
| 2939 | 2939 | { |
| 2940 | - $sql.= "fk_target = ".$targetid; |
|
| 2941 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 2942 | - $sql.= " WHERE fk_source = ".$this->id; |
|
| 2943 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 2940 | + $sql .= "fk_target = ".$targetid; |
|
| 2941 | + $sql .= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 2942 | + $sql .= " WHERE fk_source = ".$this->id; |
|
| 2943 | + $sql .= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 2944 | 2944 | } |
| 2945 | 2945 | |
| 2946 | 2946 | dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
@@ -2950,7 +2950,7 @@ discard block |
||
| 2950 | 2950 | } |
| 2951 | 2951 | else |
| 2952 | 2952 | { |
| 2953 | - $this->error=$this->db->lasterror(); |
|
| 2953 | + $this->error = $this->db->lasterror(); |
|
| 2954 | 2954 | return -1; |
| 2955 | 2955 | } |
| 2956 | 2956 | } |
@@ -2966,42 +2966,42 @@ discard block |
||
| 2966 | 2966 | * @return int >0 if OK, <0 if KO |
| 2967 | 2967 | * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
| 2968 | 2968 | */ |
| 2969 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 2969 | + function deleteObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $rowid = '') |
|
| 2970 | 2970 | { |
| 2971 | - $deletesource=false; |
|
| 2972 | - $deletetarget=false; |
|
| 2971 | + $deletesource = false; |
|
| 2972 | + $deletetarget = false; |
|
| 2973 | 2973 | |
| 2974 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 2975 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 2974 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource = true; |
|
| 2975 | + else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $deletetarget = true; |
|
| 2976 | 2976 | |
| 2977 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2978 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2979 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2980 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2977 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
| 2978 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2979 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
| 2980 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
| 2981 | 2981 | |
| 2982 | 2982 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
| 2983 | - $sql.= " WHERE"; |
|
| 2983 | + $sql .= " WHERE"; |
|
| 2984 | 2984 | if ($rowid > 0) |
| 2985 | 2985 | { |
| 2986 | - $sql.=" rowid = ".$rowid; |
|
| 2986 | + $sql .= " rowid = ".$rowid; |
|
| 2987 | 2987 | } |
| 2988 | 2988 | else |
| 2989 | 2989 | { |
| 2990 | 2990 | if ($deletesource) |
| 2991 | 2991 | { |
| 2992 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 2993 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 2992 | + $sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 2993 | + $sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 2994 | 2994 | } |
| 2995 | 2995 | else if ($deletetarget) |
| 2996 | 2996 | { |
| 2997 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 2998 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 2997 | + $sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 2998 | + $sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 2999 | 2999 | } |
| 3000 | 3000 | else |
| 3001 | 3001 | { |
| 3002 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3003 | - $sql.= " OR"; |
|
| 3004 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3002 | + $sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3003 | + $sql .= " OR"; |
|
| 3004 | + $sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3005 | 3005 | } |
| 3006 | 3006 | } |
| 3007 | 3007 | |
@@ -3012,8 +3012,8 @@ discard block |
||
| 3012 | 3012 | } |
| 3013 | 3013 | else |
| 3014 | 3014 | { |
| 3015 | - $this->error=$this->db->lasterror(); |
|
| 3016 | - $this->errors[]=$this->error; |
|
| 3015 | + $this->error = $this->db->lasterror(); |
|
| 3016 | + $this->errors[] = $this->error; |
|
| 3017 | 3017 | return -1; |
| 3018 | 3018 | } |
| 3019 | 3019 | } |
@@ -3026,55 +3026,55 @@ discard block |
||
| 3026 | 3026 | * @param string $elementType Type of element to force (use this->table_element by default) |
| 3027 | 3027 | * @return int <0 if KO, >0 if OK |
| 3028 | 3028 | */ |
| 3029 | - function setStatut($status,$elementId=null,$elementType='') |
|
| 3029 | + function setStatut($status, $elementId = null, $elementType = '') |
|
| 3030 | 3030 | { |
| 3031 | - global $user,$langs,$conf; |
|
| 3031 | + global $user, $langs, $conf; |
|
| 3032 | 3032 | |
| 3033 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3033 | + $savElementId = $elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3034 | 3034 | |
| 3035 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3036 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3035 | + $elementId = (!empty($elementId) ? $elementId : $this->id); |
|
| 3036 | + $elementTable = (!empty($elementType) ? $elementType : $this->table_element); |
|
| 3037 | 3037 | |
| 3038 | 3038 | $this->db->begin(); |
| 3039 | 3039 | |
| 3040 | - $fieldstatus="fk_statut"; |
|
| 3041 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3042 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3043 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3044 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3040 | + $fieldstatus = "fk_statut"; |
|
| 3041 | + if ($elementTable == 'mailing') $fieldstatus = "statut"; |
|
| 3042 | + if ($elementTable == 'user') $fieldstatus = "statut"; |
|
| 3043 | + if ($elementTable == 'expensereport') $fieldstatus = "fk_statut"; |
|
| 3044 | + if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus = "status"; |
|
| 3045 | 3045 | |
| 3046 | 3046 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
| 3047 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3047 | + $sql .= " SET ".$fieldstatus." = ".$status; |
|
| 3048 | 3048 | // If status = 1 = validated, update also fk_user_valid |
| 3049 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3050 | - $sql.= " WHERE rowid=".$elementId; |
|
| 3049 | + if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = ".$user->id; |
|
| 3050 | + $sql .= " WHERE rowid=".$elementId; |
|
| 3051 | 3051 | |
| 3052 | 3052 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
| 3053 | 3053 | if ($this->db->query($sql)) |
| 3054 | 3054 | { |
| 3055 | 3055 | $error = 0; |
| 3056 | 3056 | |
| 3057 | - $trigkey=''; |
|
| 3058 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3059 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3060 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3061 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3062 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3063 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3057 | + $trigkey = ''; |
|
| 3058 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3059 | + if ($this->element == 'supplier_proposal' && $status == 3) $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3060 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3061 | + if ($this->element == 'fichinter' && $status == 3) $trigkey = 'FICHINTER_CLASSIFY_DONE'; |
|
| 3062 | + if ($this->element == 'fichinter' && $status == 2) $trigkey = 'FICHINTER_CLASSIFY_BILLED'; |
|
| 3063 | + if ($this->element == 'fichinter' && $status == 1) $trigkey = 'FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3064 | 3064 | |
| 3065 | 3065 | if ($trigkey) |
| 3066 | 3066 | { |
| 3067 | 3067 | // Appel des triggers |
| 3068 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3069 | - $interface=new Interfaces($this->db); |
|
| 3070 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3068 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
| 3069 | + $interface = new Interfaces($this->db); |
|
| 3070 | + $result = $interface->run_triggers($trigkey, $this, $user, $langs, $conf); |
|
| 3071 | 3071 | if ($result < 0) { |
| 3072 | - $error++; $this->errors=$interface->errors; |
|
| 3072 | + $error++; $this->errors = $interface->errors; |
|
| 3073 | 3073 | } |
| 3074 | 3074 | // Fin appel triggers |
| 3075 | 3075 | } |
| 3076 | 3076 | |
| 3077 | - if (! $error) |
|
| 3077 | + if (!$error) |
|
| 3078 | 3078 | { |
| 3079 | 3079 | $this->db->commit(); |
| 3080 | 3080 | |
@@ -3089,13 +3089,13 @@ discard block |
||
| 3089 | 3089 | else |
| 3090 | 3090 | { |
| 3091 | 3091 | $this->db->rollback(); |
| 3092 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3092 | + dol_syslog(get_class($this)."::setStatus ".$this->error, LOG_ERR); |
|
| 3093 | 3093 | return -1; |
| 3094 | 3094 | } |
| 3095 | 3095 | } |
| 3096 | 3096 | else |
| 3097 | 3097 | { |
| 3098 | - $this->error=$this->db->lasterror(); |
|
| 3098 | + $this->error = $this->db->lasterror(); |
|
| 3099 | 3099 | $this->db->rollback(); |
| 3100 | 3100 | return -1; |
| 3101 | 3101 | } |
@@ -3109,21 +3109,21 @@ discard block |
||
| 3109 | 3109 | * @param string $ref Record ref |
| 3110 | 3110 | * @return int <0 if KO, 0 if nothing done, >0 if OK |
| 3111 | 3111 | */ |
| 3112 | - function getCanvas($id=0,$ref='') |
|
| 3112 | + function getCanvas($id = 0, $ref = '') |
|
| 3113 | 3113 | { |
| 3114 | 3114 | global $conf; |
| 3115 | 3115 | |
| 3116 | 3116 | if (empty($id) && empty($ref)) return 0; |
| 3117 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3117 | + if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3118 | 3118 | |
| 3119 | 3119 | // Clean parameters |
| 3120 | 3120 | $ref = trim($ref); |
| 3121 | 3121 | |
| 3122 | 3122 | $sql = "SELECT rowid, canvas"; |
| 3123 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3124 | - $sql.= " WHERE entity IN (".getEntity($this->element).")"; |
|
| 3125 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3126 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3123 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3124 | + $sql .= " WHERE entity IN (".getEntity($this->element).")"; |
|
| 3125 | + if (!empty($id)) $sql .= " AND rowid = ".$id; |
|
| 3126 | + if (!empty($ref)) $sql .= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3127 | 3127 | |
| 3128 | 3128 | $resql = $this->db->query($sql); |
| 3129 | 3129 | if ($resql) |
@@ -3131,7 +3131,7 @@ discard block |
||
| 3131 | 3131 | $obj = $this->db->fetch_object($resql); |
| 3132 | 3132 | if ($obj) |
| 3133 | 3133 | { |
| 3134 | - $this->canvas = $obj->canvas; |
|
| 3134 | + $this->canvas = $obj->canvas; |
|
| 3135 | 3135 | return 1; |
| 3136 | 3136 | } |
| 3137 | 3137 | else return 0; |
@@ -3153,7 +3153,7 @@ discard block |
||
| 3153 | 3153 | function getSpecialCode($lineid) |
| 3154 | 3154 | { |
| 3155 | 3155 | $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 3156 | - $sql.= ' WHERE rowid = '.$lineid; |
|
| 3156 | + $sql .= ' WHERE rowid = '.$lineid; |
|
| 3157 | 3157 | $resql = $this->db->query($sql); |
| 3158 | 3158 | if ($resql) |
| 3159 | 3159 | { |
@@ -3169,14 +3169,14 @@ discard block |
||
| 3169 | 3169 | * @param int $id Force id of object |
| 3170 | 3170 | * @return int <0 if KO, 0 if not used, >0 if already used |
| 3171 | 3171 | */ |
| 3172 | - function isObjectUsed($id=0) |
|
| 3172 | + function isObjectUsed($id = 0) |
|
| 3173 | 3173 | { |
| 3174 | 3174 | global $langs; |
| 3175 | 3175 | |
| 3176 | - if (empty($id)) $id=$this->id; |
|
| 3176 | + if (empty($id)) $id = $this->id; |
|
| 3177 | 3177 | |
| 3178 | 3178 | // Check parameters |
| 3179 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3179 | + if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3180 | 3180 | { |
| 3181 | 3181 | dol_print_error('Called isObjectUsed on a class with property this->childtables not defined'); |
| 3182 | 3182 | return -1; |
@@ -3184,42 +3184,42 @@ discard block |
||
| 3184 | 3184 | |
| 3185 | 3185 | $arraytoscan = $this->childtables; |
| 3186 | 3186 | // For backward compatibility, we check if array is old format array('table1', 'table2', ...) |
| 3187 | - $tmparray=array_keys($this->childtables); |
|
| 3187 | + $tmparray = array_keys($this->childtables); |
|
| 3188 | 3188 | if (is_numeric($tmparray[0])) |
| 3189 | 3189 | { |
| 3190 | 3190 | $arraytoscan = array_flip($this->childtables); |
| 3191 | 3191 | } |
| 3192 | 3192 | |
| 3193 | 3193 | // Test if child exists |
| 3194 | - $haschild=0; |
|
| 3195 | - foreach($arraytoscan as $table => $elementname) |
|
| 3194 | + $haschild = 0; |
|
| 3195 | + foreach ($arraytoscan as $table => $elementname) |
|
| 3196 | 3196 | { |
| 3197 | 3197 | //print $id.'-'.$table.'-'.$elementname.'<br>'; |
| 3198 | 3198 | // Check if third party can be deleted |
| 3199 | 3199 | $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
| 3200 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3201 | - $resql=$this->db->query($sql); |
|
| 3200 | + $sql .= " WHERE ".$this->fk_element." = ".$id; |
|
| 3201 | + $resql = $this->db->query($sql); |
|
| 3202 | 3202 | if ($resql) |
| 3203 | 3203 | { |
| 3204 | - $obj=$this->db->fetch_object($resql); |
|
| 3204 | + $obj = $this->db->fetch_object($resql); |
|
| 3205 | 3205 | if ($obj->nb > 0) |
| 3206 | 3206 | { |
| 3207 | 3207 | $langs->load("errors"); |
| 3208 | 3208 | //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
| 3209 | 3209 | $haschild += $obj->nb; |
| 3210 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
| 3211 | - break; // We found at least one, we stop here |
|
| 3210 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname)); |
|
| 3211 | + break; // We found at least one, we stop here |
|
| 3212 | 3212 | } |
| 3213 | 3213 | } |
| 3214 | 3214 | else |
| 3215 | 3215 | { |
| 3216 | - $this->errors[]=$this->db->lasterror(); |
|
| 3216 | + $this->errors[] = $this->db->lasterror(); |
|
| 3217 | 3217 | return -1; |
| 3218 | 3218 | } |
| 3219 | 3219 | } |
| 3220 | 3220 | if ($haschild > 0) |
| 3221 | 3221 | { |
| 3222 | - $this->errors[]="ErrorRecordHasChildren"; |
|
| 3222 | + $this->errors[] = "ErrorRecordHasChildren"; |
|
| 3223 | 3223 | return $haschild; |
| 3224 | 3224 | } |
| 3225 | 3225 | else return 0; |
@@ -3231,18 +3231,18 @@ discard block |
||
| 3231 | 3231 | * @param int $predefined -1=All, 0=Count free product/service only, 1=Count predefined product/service only, 2=Count predefined product, 3=Count predefined service |
| 3232 | 3232 | * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
| 3233 | 3233 | */ |
| 3234 | - function hasProductsOrServices($predefined=-1) |
|
| 3234 | + function hasProductsOrServices($predefined = -1) |
|
| 3235 | 3235 | { |
| 3236 | - $nb=0; |
|
| 3236 | + $nb = 0; |
|
| 3237 | 3237 | |
| 3238 | - foreach($this->lines as $key => $val) |
|
| 3238 | + foreach ($this->lines as $key => $val) |
|
| 3239 | 3239 | { |
| 3240 | - $qualified=0; |
|
| 3241 | - if ($predefined == -1) $qualified=1; |
|
| 3242 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3243 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3244 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3245 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3240 | + $qualified = 0; |
|
| 3241 | + if ($predefined == -1) $qualified = 1; |
|
| 3242 | + if ($predefined == 1 && $val->fk_product > 0) $qualified = 1; |
|
| 3243 | + if ($predefined == 0 && $val->fk_product <= 0) $qualified = 1; |
|
| 3244 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) $qualified = 1; |
|
| 3245 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) $qualified = 1; |
|
| 3246 | 3246 | if ($qualified) $nb++; |
| 3247 | 3247 | } |
| 3248 | 3248 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
@@ -3256,24 +3256,24 @@ discard block |
||
| 3256 | 3256 | */ |
| 3257 | 3257 | function getTotalDiscount() |
| 3258 | 3258 | { |
| 3259 | - $total_discount=0.00; |
|
| 3259 | + $total_discount = 0.00; |
|
| 3260 | 3260 | |
| 3261 | 3261 | $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
| 3262 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3263 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3262 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3263 | + $sql .= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3264 | 3264 | |
| 3265 | 3265 | dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
| 3266 | 3266 | $resql = $this->db->query($sql); |
| 3267 | 3267 | if ($resql) |
| 3268 | 3268 | { |
| 3269 | - $num=$this->db->num_rows($resql); |
|
| 3270 | - $i=0; |
|
| 3269 | + $num = $this->db->num_rows($resql); |
|
| 3270 | + $i = 0; |
|
| 3271 | 3271 | while ($i < $num) |
| 3272 | 3272 | { |
| 3273 | 3273 | $obj = $this->db->fetch_object($resql); |
| 3274 | 3274 | |
| 3275 | 3275 | $pu_ht = $obj->pu_ht; |
| 3276 | - $qty= $obj->qty; |
|
| 3276 | + $qty = $obj->qty; |
|
| 3277 | 3277 | $total_ht = $obj->total_ht; |
| 3278 | 3278 | |
| 3279 | 3279 | $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
@@ -3307,13 +3307,13 @@ discard block |
||
| 3307 | 3307 | { |
| 3308 | 3308 | if (isset($line->qty_asked)) |
| 3309 | 3309 | { |
| 3310 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3311 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3310 | + if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is '' |
|
| 3311 | + $totalOrdered += $line->qty_asked; // defined for shipment only |
|
| 3312 | 3312 | } |
| 3313 | 3313 | if (isset($line->qty_shipped)) |
| 3314 | 3314 | { |
| 3315 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3316 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3315 | + if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is '' |
|
| 3316 | + $totalToShip += $line->qty_shipped; // defined for shipment only |
|
| 3317 | 3317 | } |
| 3318 | 3318 | |
| 3319 | 3319 | // Define qty, weight, volume, weight_units, volume_units |
@@ -3328,21 +3328,21 @@ discard block |
||
| 3328 | 3328 | $weight = $line->weight ? $line->weight : 0; |
| 3329 | 3329 | $volume = $line->volume ? $line->volume : 0; |
| 3330 | 3330 | |
| 3331 | - $weight_units=$line->weight_units; |
|
| 3332 | - $volume_units=$line->volume_units; |
|
| 3331 | + $weight_units = $line->weight_units; |
|
| 3332 | + $volume_units = $line->volume_units; |
|
| 3333 | 3333 | |
| 3334 | - $weightUnit=0; |
|
| 3335 | - $volumeUnit=0; |
|
| 3336 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3337 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3334 | + $weightUnit = 0; |
|
| 3335 | + $volumeUnit = 0; |
|
| 3336 | + if (!empty($weight_units)) $weightUnit = $weight_units; |
|
| 3337 | + if (!empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3338 | 3338 | |
| 3339 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3340 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3339 | + if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is '' |
|
| 3340 | + if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is '' |
|
| 3341 | 3341 | |
| 3342 | 3342 | //var_dump($line->volume_units); |
| 3343 | 3343 | if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
| 3344 | 3344 | { |
| 3345 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3345 | + $trueWeightUnit = pow(10, $weightUnit); |
|
| 3346 | 3346 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3347 | 3347 | } |
| 3348 | 3348 | else { |
@@ -3356,18 +3356,18 @@ discard block |
||
| 3356 | 3356 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3357 | 3357 | } |
| 3358 | 3358 | else |
| 3359 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3359 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3360 | 3360 | } |
| 3361 | 3361 | if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
| 3362 | 3362 | { |
| 3363 | 3363 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
| 3364 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3364 | + $trueVolumeUnit = pow(10, $volumeUnit); |
|
| 3365 | 3365 | //print $line->volume; |
| 3366 | 3366 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
| 3367 | 3367 | } |
| 3368 | 3368 | else |
| 3369 | 3369 | { |
| 3370 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3370 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3371 | 3371 | } |
| 3372 | 3372 | } |
| 3373 | 3373 | |
@@ -3384,17 +3384,17 @@ discard block |
||
| 3384 | 3384 | { |
| 3385 | 3385 | $this->db->begin(); |
| 3386 | 3386 | |
| 3387 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3387 | + $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3388 | 3388 | |
| 3389 | 3389 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 3390 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3391 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 3390 | + $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3391 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 3392 | 3392 | |
| 3393 | 3393 | dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
| 3394 | 3394 | $resql = $this->db->query($sql); |
| 3395 | - if (! $resql) |
|
| 3395 | + if (!$resql) |
|
| 3396 | 3396 | { |
| 3397 | - $this->error=$this->db->lasterror(); |
|
| 3397 | + $this->error = $this->db->lasterror(); |
|
| 3398 | 3398 | $this->db->rollback(); |
| 3399 | 3399 | return -1; |
| 3400 | 3400 | } |
@@ -3427,7 +3427,7 @@ discard block |
||
| 3427 | 3427 | } |
| 3428 | 3428 | } |
| 3429 | 3429 | |
| 3430 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3430 | + $out .= (($res->code && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms; |
|
| 3431 | 3431 | |
| 3432 | 3432 | return $out; |
| 3433 | 3433 | } |
@@ -3473,11 +3473,11 @@ discard block |
||
| 3473 | 3473 | if ($this->id && $this->table_element) |
| 3474 | 3474 | { |
| 3475 | 3475 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 3476 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3477 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3478 | - $sql.= " WHERE rowid = " . $this->id; |
|
| 3476 | + $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3477 | + $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3478 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 3479 | 3479 | dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
| 3480 | - $resql=$this->db->query($sql); |
|
| 3480 | + $resql = $this->db->query($sql); |
|
| 3481 | 3481 | if ($resql) |
| 3482 | 3482 | { |
| 3483 | 3483 | $this->fk_incoterms = $id_incoterm; |
@@ -3529,26 +3529,26 @@ discard block |
||
| 3529 | 3529 | * @param Societe $buyer Object thirdparty who buy |
| 3530 | 3530 | * @return void |
| 3531 | 3531 | */ |
| 3532 | - function formAddObjectLine($dateSelector,$seller,$buyer) |
|
| 3532 | + function formAddObjectLine($dateSelector, $seller, $buyer) |
|
| 3533 | 3533 | { |
| 3534 | - global $conf,$user,$langs,$object,$hookmanager; |
|
| 3535 | - global $form,$bcnd,$var; |
|
| 3534 | + global $conf, $user, $langs, $object, $hookmanager; |
|
| 3535 | + global $form, $bcnd, $var; |
|
| 3536 | 3536 | |
| 3537 | 3537 | //Line extrafield |
| 3538 | 3538 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 3539 | 3539 | $extrafieldsline = new ExtraFields($this->db); |
| 3540 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3540 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3541 | 3541 | |
| 3542 | 3542 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 3543 | 3543 | // Use global variables + $dateSelector + $seller and $buyer |
| 3544 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 3545 | - foreach($dirtpls as $reldir) |
|
| 3544 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 3545 | + foreach ($dirtpls as $reldir) |
|
| 3546 | 3546 | { |
| 3547 | 3547 | $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
| 3548 | 3548 | if (empty($conf->file->strict_mode)) { |
| 3549 | - $res=@include $tpl; |
|
| 3549 | + $res = @include $tpl; |
|
| 3550 | 3550 | } else { |
| 3551 | - $res=include $tpl; // for debug |
|
| 3551 | + $res = include $tpl; // for debug |
|
| 3552 | 3552 | } |
| 3553 | 3553 | if ($res) break; |
| 3554 | 3554 | } |
@@ -3572,30 +3572,30 @@ discard block |
||
| 3572 | 3572 | * @param int $dateSelector 1=Show also date range input fields |
| 3573 | 3573 | * @return void |
| 3574 | 3574 | */ |
| 3575 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3575 | + function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0) |
|
| 3576 | 3576 | { |
| 3577 | 3577 | global $conf, $hookmanager, $langs, $user; |
| 3578 | 3578 | // TODO We should not use global var for this ! |
| 3579 | 3579 | global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
| 3580 | 3580 | |
| 3581 | 3581 | // Define usemargins |
| 3582 | - $usemargins=0; |
|
| 3583 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; |
|
| 3582 | + $usemargins = 0; |
|
| 3583 | + if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) $usemargins = 1; |
|
| 3584 | 3584 | |
| 3585 | 3585 | $num = count($this->lines); |
| 3586 | 3586 | |
| 3587 | 3587 | //Line extrafield |
| 3588 | 3588 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 3589 | 3589 | $extrafieldsline = new ExtraFields($this->db); |
| 3590 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3590 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3591 | 3591 | |
| 3592 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3592 | + $parameters = array('num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3593 | 3593 | $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
| 3594 | 3594 | if (empty($reshook)) |
| 3595 | 3595 | { |
| 3596 | 3596 | print '<tr class="liste_titre nodrag nodrop">'; |
| 3597 | 3597 | |
| 3598 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3598 | + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3599 | 3599 | |
| 3600 | 3600 | // Description |
| 3601 | 3601 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>'; |
@@ -3619,7 +3619,7 @@ discard block |
||
| 3619 | 3619 | // Qty |
| 3620 | 3620 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>'; |
| 3621 | 3621 | |
| 3622 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 3622 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 3623 | 3623 | { |
| 3624 | 3624 | print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>'; |
| 3625 | 3625 | } |
@@ -3628,10 +3628,10 @@ discard block |
||
| 3628 | 3628 | print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>'; |
| 3629 | 3629 | |
| 3630 | 3630 | if ($this->situation_cycle_ref) { |
| 3631 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>'; |
|
| 3631 | + print '<td class="linecolcycleref" align="right">'.$langs->trans('Progress').'</td>'; |
|
| 3632 | 3632 | } |
| 3633 | 3633 | |
| 3634 | - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3634 | + if ($usemargins && !empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3635 | 3635 | { |
| 3636 | 3636 | if (!empty($user->rights->margins->creer)) |
| 3637 | 3637 | { |
@@ -3641,9 +3641,9 @@ discard block |
||
| 3641 | 3641 | print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
| 3642 | 3642 | } |
| 3643 | 3643 | |
| 3644 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3644 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3645 | 3645 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
| 3646 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3646 | + if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3647 | 3647 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
| 3648 | 3648 | } |
| 3649 | 3649 | |
@@ -3655,7 +3655,7 @@ discard block |
||
| 3655 | 3655 | |
| 3656 | 3656 | if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
| 3657 | 3657 | |
| 3658 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3658 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3659 | 3659 | |
| 3660 | 3660 | print '<td class="linecoldelete" width="10"></td>'; |
| 3661 | 3661 | |
@@ -3665,7 +3665,7 @@ discard block |
||
| 3665 | 3665 | } |
| 3666 | 3666 | |
| 3667 | 3667 | $var = true; |
| 3668 | - $i = 0; |
|
| 3668 | + $i = 0; |
|
| 3669 | 3669 | |
| 3670 | 3670 | foreach ($this->lines as $line) |
| 3671 | 3671 | { |
@@ -3678,18 +3678,18 @@ discard block |
||
| 3678 | 3678 | { |
| 3679 | 3679 | if (empty($line->fk_parent_line)) |
| 3680 | 3680 | { |
| 3681 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3682 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3681 | + $parameters = array('line'=>$line, 'var'=>$var, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 3682 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3683 | 3683 | } |
| 3684 | 3684 | else |
| 3685 | 3685 | { |
| 3686 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line); |
|
| 3687 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3686 | + $parameters = array('line'=>$line, 'var'=>$var, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline, 'fk_parent_line'=>$line->fk_parent_line); |
|
| 3687 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3688 | 3688 | } |
| 3689 | 3689 | } |
| 3690 | 3690 | if (empty($reshook)) |
| 3691 | 3691 | { |
| 3692 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3692 | + $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline); |
|
| 3693 | 3693 | } |
| 3694 | 3694 | |
| 3695 | 3695 | $i++; |
@@ -3712,23 +3712,23 @@ discard block |
||
| 3712 | 3712 | * @param int $extrafieldsline Object of extrafield line attribute |
| 3713 | 3713 | * @return void |
| 3714 | 3714 | */ |
| 3715 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3715 | + function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0) |
|
| 3716 | 3716 | { |
| 3717 | - global $conf,$langs,$user,$object,$hookmanager; |
|
| 3718 | - global $form,$bc,$bcdd; |
|
| 3719 | - global $object_rights, $disableedit, $disablemove; // TODO We should not use global var for this ! |
|
| 3717 | + global $conf, $langs, $user, $object, $hookmanager; |
|
| 3718 | + global $form, $bc, $bcdd; |
|
| 3719 | + global $object_rights, $disableedit, $disablemove; // TODO We should not use global var for this ! |
|
| 3720 | 3720 | |
| 3721 | 3721 | $object_rights = $this->getRights(); |
| 3722 | 3722 | |
| 3723 | - $element=$this->element; |
|
| 3723 | + $element = $this->element; |
|
| 3724 | 3724 | |
| 3725 | - $text=''; $description=''; $type=0; |
|
| 3725 | + $text = ''; $description = ''; $type = 0; |
|
| 3726 | 3726 | |
| 3727 | 3727 | // Show product and description |
| 3728 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 3728 | + $type = (!empty($line->product_type) ? $line->product_type : $line->fk_product_type); |
|
| 3729 | 3729 | // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
| 3730 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3731 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 3730 | + if (!empty($line->date_start)) $type = 1; // deprecated |
|
| 3731 | + if (!empty($line->date_end)) $type = 1; // deprecated |
|
| 3732 | 3732 | |
| 3733 | 3733 | // Ligne en mode visu |
| 3734 | 3734 | if ($action != 'editline' || $selected != $line->id) |
@@ -3741,14 +3741,14 @@ discard block |
||
| 3741 | 3741 | |
| 3742 | 3742 | $product_static->ref = $line->ref; //can change ref in hook |
| 3743 | 3743 | $product_static->label = $line->label; //can change label in hook |
| 3744 | - $text=$product_static->getNomUrl(1); |
|
| 3744 | + $text = $product_static->getNomUrl(1); |
|
| 3745 | 3745 | |
| 3746 | 3746 | // Define output language and label |
| 3747 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
| 3747 | + if (!empty($conf->global->MAIN_MULTILANGS)) |
|
| 3748 | 3748 | { |
| 3749 | - if (! is_object($this->thirdparty)) |
|
| 3749 | + if (!is_object($this->thirdparty)) |
|
| 3750 | 3750 | { |
| 3751 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
| 3751 | + dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before'); |
|
| 3752 | 3752 | return; |
| 3753 | 3753 | } |
| 3754 | 3754 | |
@@ -3756,38 +3756,38 @@ discard block |
||
| 3756 | 3756 | $prod->fetch($line->fk_product); |
| 3757 | 3757 | |
| 3758 | 3758 | $outputlangs = $langs; |
| 3759 | - $newlang=''; |
|
| 3760 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
| 3761 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
| 3762 | - if (! empty($newlang)) |
|
| 3759 | + $newlang = ''; |
|
| 3760 | + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); |
|
| 3761 | + if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
| 3762 | + if (!empty($newlang)) |
|
| 3763 | 3763 | { |
| 3764 | - $outputlangs = new Translate("",$conf); |
|
| 3764 | + $outputlangs = new Translate("", $conf); |
|
| 3765 | 3765 | $outputlangs->setDefaultLang($newlang); |
| 3766 | 3766 | } |
| 3767 | 3767 | |
| 3768 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 3768 | + $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 3769 | 3769 | } |
| 3770 | 3770 | else |
| 3771 | 3771 | { |
| 3772 | 3772 | $label = $line->product_label; |
| 3773 | 3773 | } |
| 3774 | 3774 | |
| 3775 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 3776 | - $description.=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. |
|
| 3775 | + $text .= ' - '.(!empty($line->label) ? $line->label : $label); |
|
| 3776 | + $description .= (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. |
|
| 3777 | 3777 | } |
| 3778 | 3778 | |
| 3779 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 3779 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
| 3780 | 3780 | |
| 3781 | 3781 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 3782 | 3782 | // Use global variables + $dateSelector + $seller and $buyer |
| 3783 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 3784 | - foreach($dirtpls as $reldir) |
|
| 3783 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 3784 | + foreach ($dirtpls as $reldir) |
|
| 3785 | 3785 | { |
| 3786 | 3786 | $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
| 3787 | 3787 | if (empty($conf->file->strict_mode)) { |
| 3788 | - $res=@include $tpl; |
|
| 3788 | + $res = @include $tpl; |
|
| 3789 | 3789 | } else { |
| 3790 | - $res=include $tpl; // for debug |
|
| 3790 | + $res = include $tpl; // for debug |
|
| 3791 | 3791 | } |
| 3792 | 3792 | if ($res) break; |
| 3793 | 3793 | } |
@@ -3796,21 +3796,21 @@ discard block |
||
| 3796 | 3796 | // Ligne en mode update |
| 3797 | 3797 | if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
| 3798 | 3798 | { |
| 3799 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 3800 | - $placeholder=' placeholder="'.$langs->trans("Label").'"'; |
|
| 3799 | + $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 3800 | + $placeholder = ' placeholder="'.$langs->trans("Label").'"'; |
|
| 3801 | 3801 | |
| 3802 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 3802 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
| 3803 | 3803 | |
| 3804 | 3804 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 3805 | 3805 | // Use global variables + $dateSelector + $seller and $buyer |
| 3806 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 3807 | - foreach($dirtpls as $reldir) |
|
| 3806 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 3807 | + foreach ($dirtpls as $reldir) |
|
| 3808 | 3808 | { |
| 3809 | 3809 | $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
| 3810 | 3810 | if (empty($conf->file->strict_mode)) { |
| 3811 | - $res=@include $tpl; |
|
| 3811 | + $res = @include $tpl; |
|
| 3812 | 3812 | } else { |
| 3813 | - $res=include $tpl; // for debug |
|
| 3813 | + $res = include $tpl; // for debug |
|
| 3814 | 3814 | } |
| 3815 | 3815 | if ($res) break; |
| 3816 | 3816 | } |
@@ -3830,7 +3830,7 @@ discard block |
||
| 3830 | 3830 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
| 3831 | 3831 | * @return void |
| 3832 | 3832 | */ |
| 3833 | - function printOriginLinesList($restrictlist='') |
|
| 3833 | + function printOriginLinesList($restrictlist = '') |
|
| 3834 | 3834 | { |
| 3835 | 3835 | global $langs, $hookmanager, $conf; |
| 3836 | 3836 | |
@@ -3841,24 +3841,24 @@ discard block |
||
| 3841 | 3841 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; |
| 3842 | 3842 | if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
| 3843 | 3843 | print '<td align="right">'.$langs->trans('Qty').'</td>'; |
| 3844 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 3844 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 3845 | 3845 | { |
| 3846 | 3846 | print '<td align="left">'.$langs->trans('Unit').'</td>'; |
| 3847 | 3847 | } |
| 3848 | 3848 | print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>'; |
| 3849 | 3849 | |
| 3850 | 3850 | $var = true; |
| 3851 | - $i = 0; |
|
| 3851 | + $i = 0; |
|
| 3852 | 3852 | |
| 3853 | 3853 | foreach ($this->lines as $line) |
| 3854 | 3854 | { |
| 3855 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 3855 | + if (is_object($hookmanager) && (($line->product_type == 9 && !empty($line->special_code)) || !empty($line->fk_parent_line))) |
|
| 3856 | 3856 | { |
| 3857 | 3857 | if (empty($line->fk_parent_line)) |
| 3858 | 3858 | { |
| 3859 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i); |
|
| 3860 | - $action=''; |
|
| 3861 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 3859 | + $parameters = array('line'=>$line, 'var'=>$var, 'i'=>$i); |
|
| 3860 | + $action = ''; |
|
| 3861 | + $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 3862 | 3862 | } |
| 3863 | 3863 | } |
| 3864 | 3864 | else |
@@ -3881,91 +3881,91 @@ discard block |
||
| 3881 | 3881 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
| 3882 | 3882 | * @return void |
| 3883 | 3883 | */ |
| 3884 | - function printOriginLine($line, $var, $restrictlist='') |
|
| 3884 | + function printOriginLine($line, $var, $restrictlist = '') |
|
| 3885 | 3885 | { |
| 3886 | 3886 | global $langs, $conf; |
| 3887 | 3887 | |
| 3888 | 3888 | //var_dump($line); |
| 3889 | 3889 | if (!empty($line->date_start)) |
| 3890 | 3890 | { |
| 3891 | - $date_start=$line->date_start; |
|
| 3891 | + $date_start = $line->date_start; |
|
| 3892 | 3892 | } |
| 3893 | 3893 | else |
| 3894 | 3894 | { |
| 3895 | - $date_start=$line->date_debut_prevue; |
|
| 3896 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 3895 | + $date_start = $line->date_debut_prevue; |
|
| 3896 | + if ($line->date_debut_reel) $date_start = $line->date_debut_reel; |
|
| 3897 | 3897 | } |
| 3898 | 3898 | if (!empty($line->date_end)) |
| 3899 | 3899 | { |
| 3900 | - $date_end=$line->date_end; |
|
| 3900 | + $date_end = $line->date_end; |
|
| 3901 | 3901 | } |
| 3902 | 3902 | else |
| 3903 | 3903 | { |
| 3904 | - $date_end=$line->date_fin_prevue; |
|
| 3905 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 3904 | + $date_end = $line->date_fin_prevue; |
|
| 3905 | + if ($line->date_fin_reel) $date_end = $line->date_fin_reel; |
|
| 3906 | 3906 | } |
| 3907 | 3907 | |
| 3908 | 3908 | $this->tpl['label'] = ''; |
| 3909 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
| 3909 | + if (!empty($line->fk_parent_line)) $this->tpl['label'] .= img_picto('', 'rightarrow'); |
|
| 3910 | 3910 | |
| 3911 | 3911 | if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
| 3912 | 3912 | { |
| 3913 | - $discount=new DiscountAbsolute($this->db); |
|
| 3913 | + $discount = new DiscountAbsolute($this->db); |
|
| 3914 | 3914 | $discount->fk_soc = $this->socid; |
| 3915 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 3915 | + $this->tpl['label'] .= $discount->getNomUrl(0, 'discount'); |
|
| 3916 | 3916 | } |
| 3917 | - else if (! empty($line->fk_product)) |
|
| 3917 | + else if (!empty($line->fk_product)) |
|
| 3918 | 3918 | { |
| 3919 | 3919 | $productstatic = new Product($this->db); |
| 3920 | 3920 | $productstatic->id = $line->fk_product; |
| 3921 | 3921 | $productstatic->ref = $line->ref; |
| 3922 | 3922 | $productstatic->type = $line->fk_product_type; |
| 3923 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 3924 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 3923 | + $this->tpl['label'] .= $productstatic->getNomUrl(1); |
|
| 3924 | + $this->tpl['label'] .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); |
|
| 3925 | 3925 | // Dates |
| 3926 | 3926 | if ($line->product_type == 1 && ($date_start || $date_end)) |
| 3927 | 3927 | { |
| 3928 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 3928 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
| 3929 | 3929 | } |
| 3930 | 3930 | } |
| 3931 | 3931 | else |
| 3932 | 3932 | { |
| 3933 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product'))); |
|
| 3933 | + $this->tpl['label'] .= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product'))); |
|
| 3934 | 3934 | if (!empty($line->desc)) { |
| 3935 | - $this->tpl['label'].=$line->desc; |
|
| 3936 | - }else { |
|
| 3937 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 3935 | + $this->tpl['label'] .= $line->desc; |
|
| 3936 | + } else { |
|
| 3937 | + $this->tpl['label'] .= ($line->label ? ' '.$line->label : ''); |
|
| 3938 | 3938 | } |
| 3939 | 3939 | // Dates |
| 3940 | 3940 | if ($line->product_type == 1 && ($date_start || $date_end)) |
| 3941 | 3941 | { |
| 3942 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 3942 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
| 3943 | 3943 | } |
| 3944 | 3944 | } |
| 3945 | 3945 | |
| 3946 | - if (! empty($line->desc)) |
|
| 3946 | + if (!empty($line->desc)) |
|
| 3947 | 3947 | { |
| 3948 | 3948 | if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
| 3949 | 3949 | { |
| 3950 | - $discount=new DiscountAbsolute($this->db); |
|
| 3950 | + $discount = new DiscountAbsolute($this->db); |
|
| 3951 | 3951 | $discount->fetch($line->fk_remise_except); |
| 3952 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
| 3952 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); |
|
| 3953 | 3953 | } |
| 3954 | 3954 | elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
| 3955 | 3955 | { |
| 3956 | - $discount=new DiscountAbsolute($this->db); |
|
| 3956 | + $discount = new DiscountAbsolute($this->db); |
|
| 3957 | 3957 | $discount->fetch($line->fk_remise_except); |
| 3958 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
| 3958 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); |
|
| 3959 | 3959 | } |
| 3960 | 3960 | elseif ($line->desc == '(EXCESS RECEIVED)') |
| 3961 | 3961 | { |
| 3962 | - $discount=new DiscountAbsolute($this->db); |
|
| 3962 | + $discount = new DiscountAbsolute($this->db); |
|
| 3963 | 3963 | $discount->fetch($line->fk_remise_except); |
| 3964 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
| 3964 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0)); |
|
| 3965 | 3965 | } |
| 3966 | 3966 | else |
| 3967 | 3967 | { |
| 3968 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 3968 | + $this->tpl['description'] = dol_trunc($line->desc, 60); |
|
| 3969 | 3969 | } |
| 3970 | 3970 | } |
| 3971 | 3971 | else |
@@ -3976,7 +3976,7 @@ discard block |
||
| 3976 | 3976 | // VAT Rate |
| 3977 | 3977 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
| 3978 | 3978 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
| 3979 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
| 3979 | + if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')'; |
|
| 3980 | 3980 | |
| 3981 | 3981 | $this->tpl['price'] = price($line->subprice); |
| 3982 | 3982 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
@@ -3985,19 +3985,19 @@ discard block |
||
| 3985 | 3985 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
| 3986 | 3986 | |
| 3987 | 3987 | // Is the line strike or not |
| 3988 | - $this->tpl['strike']=0; |
|
| 3989 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 3988 | + $this->tpl['strike'] = 0; |
|
| 3989 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike'] = 1; |
|
| 3990 | 3990 | |
| 3991 | 3991 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 3992 | 3992 | // Use global variables + $dateSelector + $seller and $buyer |
| 3993 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
| 3994 | - foreach($dirtpls as $reldir) |
|
| 3993 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
| 3994 | + foreach ($dirtpls as $reldir) |
|
| 3995 | 3995 | { |
| 3996 | 3996 | $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
| 3997 | 3997 | if (empty($conf->file->strict_mode)) { |
| 3998 | - $res=@include $tpl; |
|
| 3998 | + $res = @include $tpl; |
|
| 3999 | 3999 | } else { |
| 4000 | - $res=include $tpl; // for debug |
|
| 4000 | + $res = include $tpl; // for debug |
|
| 4001 | 4001 | } |
| 4002 | 4002 | if ($res) break; |
| 4003 | 4003 | } |
@@ -4014,25 +4014,25 @@ discard block |
||
| 4014 | 4014 | * @param int $mandatory Mandatory or not |
| 4015 | 4015 | * @return int <=0 if KO, >0 if OK |
| 4016 | 4016 | */ |
| 4017 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4017 | + function add_element_resource($resource_id, $resource_type, $busy = 0, $mandatory = 0) |
|
| 4018 | 4018 | { |
| 4019 | 4019 | $this->db->begin(); |
| 4020 | 4020 | |
| 4021 | 4021 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; |
| 4022 | - $sql.= "resource_id"; |
|
| 4023 | - $sql.= ", resource_type"; |
|
| 4024 | - $sql.= ", element_id"; |
|
| 4025 | - $sql.= ", element_type"; |
|
| 4026 | - $sql.= ", busy"; |
|
| 4027 | - $sql.= ", mandatory"; |
|
| 4028 | - $sql.= ") VALUES ("; |
|
| 4029 | - $sql.= $resource_id; |
|
| 4030 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4031 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4032 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4033 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4034 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4035 | - $sql.= ")"; |
|
| 4022 | + $sql .= "resource_id"; |
|
| 4023 | + $sql .= ", resource_type"; |
|
| 4024 | + $sql .= ", element_id"; |
|
| 4025 | + $sql .= ", element_type"; |
|
| 4026 | + $sql .= ", busy"; |
|
| 4027 | + $sql .= ", mandatory"; |
|
| 4028 | + $sql .= ") VALUES ("; |
|
| 4029 | + $sql .= $resource_id; |
|
| 4030 | + $sql .= ", '".$this->db->escape($resource_type)."'"; |
|
| 4031 | + $sql .= ", '".$this->db->escape($this->id)."'"; |
|
| 4032 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
| 4033 | + $sql .= ", '".$this->db->escape($busy)."'"; |
|
| 4034 | + $sql .= ", '".$this->db->escape($mandatory)."'"; |
|
| 4035 | + $sql .= ")"; |
|
| 4036 | 4036 | |
| 4037 | 4037 | dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
| 4038 | 4038 | if ($this->db->query($sql)) |
@@ -4042,7 +4042,7 @@ discard block |
||
| 4042 | 4042 | } |
| 4043 | 4043 | else |
| 4044 | 4044 | { |
| 4045 | - $this->error=$this->db->lasterror(); |
|
| 4045 | + $this->error = $this->db->lasterror(); |
|
| 4046 | 4046 | $this->db->rollback(); |
| 4047 | 4047 | return 0; |
| 4048 | 4048 | } |
@@ -4056,29 +4056,29 @@ discard block |
||
| 4056 | 4056 | * @param int $notrigger Disable all triggers |
| 4057 | 4057 | * @return int >0 if OK, <0 if KO |
| 4058 | 4058 | */ |
| 4059 | - function delete_resource($rowid, $element, $notrigger=0) |
|
| 4059 | + function delete_resource($rowid, $element, $notrigger = 0) |
|
| 4060 | 4060 | { |
| 4061 | 4061 | global $user; |
| 4062 | 4062 | |
| 4063 | 4063 | $this->db->begin(); |
| 4064 | 4064 | |
| 4065 | 4065 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
| 4066 | - $sql.= " WHERE rowid=".$rowid; |
|
| 4066 | + $sql .= " WHERE rowid=".$rowid; |
|
| 4067 | 4067 | |
| 4068 | 4068 | dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
| 4069 | 4069 | |
| 4070 | - $resql=$this->db->query($sql); |
|
| 4071 | - if (! $resql) |
|
| 4070 | + $resql = $this->db->query($sql); |
|
| 4071 | + if (!$resql) |
|
| 4072 | 4072 | { |
| 4073 | - $this->error=$this->db->lasterror(); |
|
| 4073 | + $this->error = $this->db->lasterror(); |
|
| 4074 | 4074 | $this->db->rollback(); |
| 4075 | 4075 | return -1; |
| 4076 | 4076 | } |
| 4077 | 4077 | else |
| 4078 | 4078 | { |
| 4079 | - if (! $notrigger) |
|
| 4079 | + if (!$notrigger) |
|
| 4080 | 4080 | { |
| 4081 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4081 | + $result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4082 | 4082 | if ($result < 0) { $this->db->rollback(); return -1; } |
| 4083 | 4083 | } |
| 4084 | 4084 | $this->db->commit(); |
@@ -4097,8 +4097,8 @@ discard block |
||
| 4097 | 4097 | // Force a copy of this->lines, otherwise it will point to same object. |
| 4098 | 4098 | if (isset($this->lines) && is_array($this->lines)) |
| 4099 | 4099 | { |
| 4100 | - $nboflines=count($this->lines); |
|
| 4101 | - for($i=0; $i < $nboflines; $i++) |
|
| 4100 | + $nboflines = count($this->lines); |
|
| 4101 | + for ($i = 0; $i < $nboflines; $i++) |
|
| 4102 | 4102 | { |
| 4103 | 4103 | $this->lines[$i] = clone $this->lines[$i]; |
| 4104 | 4104 | } |
@@ -4118,43 +4118,43 @@ discard block |
||
| 4118 | 4118 | * @return int >0 if OK, <0 if KO |
| 4119 | 4119 | * @see addFileIntoDatabaseIndex |
| 4120 | 4120 | */ |
| 4121 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4121 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams = null) |
|
| 4122 | 4122 | { |
| 4123 | 4123 | global $conf, $langs, $user; |
| 4124 | 4124 | |
| 4125 | - $srctemplatepath=''; |
|
| 4125 | + $srctemplatepath = ''; |
|
| 4126 | 4126 | |
| 4127 | 4127 | // Increase limit for PDF build |
| 4128 | - $err=error_reporting(); |
|
| 4128 | + $err = error_reporting(); |
|
| 4129 | 4129 | error_reporting(0); |
| 4130 | 4130 | @set_time_limit(120); |
| 4131 | 4131 | error_reporting($err); |
| 4132 | 4132 | |
| 4133 | 4133 | // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
| 4134 | - $tmp=explode(':',$modele,2); |
|
| 4135 | - if (! empty($tmp[1])) |
|
| 4134 | + $tmp = explode(':', $modele, 2); |
|
| 4135 | + if (!empty($tmp[1])) |
|
| 4136 | 4136 | { |
| 4137 | - $modele=$tmp[0]; |
|
| 4138 | - $srctemplatepath=$tmp[1]; |
|
| 4137 | + $modele = $tmp[0]; |
|
| 4138 | + $srctemplatepath = $tmp[1]; |
|
| 4139 | 4139 | } |
| 4140 | 4140 | |
| 4141 | 4141 | // Search template files |
| 4142 | - $file=''; $classname=''; $filefound=0; |
|
| 4143 | - $dirmodels=array('/'); |
|
| 4144 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4145 | - foreach($dirmodels as $reldir) |
|
| 4142 | + $file = ''; $classname = ''; $filefound = 0; |
|
| 4143 | + $dirmodels = array('/'); |
|
| 4144 | + if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); |
|
| 4145 | + foreach ($dirmodels as $reldir) |
|
| 4146 | 4146 | { |
| 4147 | - foreach(array('doc','pdf') as $prefix) |
|
| 4147 | + foreach (array('doc', 'pdf') as $prefix) |
|
| 4148 | 4148 | { |
| 4149 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
| 4149 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php |
|
| 4150 | 4150 | else $file = $prefix."_".$modele.".modules.php"; |
| 4151 | 4151 | |
| 4152 | 4152 | // On verifie l'emplacement du modele |
| 4153 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4153 | + $file = dol_buildpath($reldir.$modelspath.$file, 0); |
|
| 4154 | 4154 | if (file_exists($file)) |
| 4155 | 4155 | { |
| 4156 | - $filefound=1; |
|
| 4157 | - $classname=$prefix.'_'.$modele; |
|
| 4156 | + $filefound = 1; |
|
| 4157 | + $classname = $prefix.'_'.$modele; |
|
| 4158 | 4158 | break; |
| 4159 | 4159 | } |
| 4160 | 4160 | } |
@@ -4164,7 +4164,7 @@ discard block |
||
| 4164 | 4164 | // If generator was found |
| 4165 | 4165 | if ($filefound) |
| 4166 | 4166 | { |
| 4167 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4167 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4168 | 4168 | |
| 4169 | 4169 | require_once $file; |
| 4170 | 4170 | |
@@ -4173,32 +4173,32 @@ discard block |
||
| 4173 | 4173 | // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
| 4174 | 4174 | if ($obj->type == 'odt' && empty($srctemplatepath)) |
| 4175 | 4175 | { |
| 4176 | - $varfortemplatedir=$obj->scandir; |
|
| 4177 | - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
| 4176 | + $varfortemplatedir = $obj->scandir; |
|
| 4177 | + if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) |
|
| 4178 | 4178 | { |
| 4179 | - $dirtoscan=$conf->global->$varfortemplatedir; |
|
| 4179 | + $dirtoscan = $conf->global->$varfortemplatedir; |
|
| 4180 | 4180 | |
| 4181 | - $listoffiles=array(); |
|
| 4181 | + $listoffiles = array(); |
|
| 4182 | 4182 | |
| 4183 | 4183 | // Now we add first model found in directories scanned |
| 4184 | - $listofdir=explode(',',$dirtoscan); |
|
| 4185 | - foreach($listofdir as $key => $tmpdir) |
|
| 4184 | + $listofdir = explode(',', $dirtoscan); |
|
| 4185 | + foreach ($listofdir as $key => $tmpdir) |
|
| 4186 | 4186 | { |
| 4187 | - $tmpdir=trim($tmpdir); |
|
| 4188 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 4189 | - if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
| 4187 | + $tmpdir = trim($tmpdir); |
|
| 4188 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 4189 | + if (!$tmpdir) { unset($listofdir[$key]); continue; } |
|
| 4190 | 4190 | if (is_dir($tmpdir)) |
| 4191 | 4191 | { |
| 4192 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4193 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4192 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0); |
|
| 4193 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 4194 | 4194 | } |
| 4195 | 4195 | } |
| 4196 | 4196 | |
| 4197 | 4197 | if (count($listoffiles)) |
| 4198 | 4198 | { |
| 4199 | - foreach($listoffiles as $record) |
|
| 4199 | + foreach ($listoffiles as $record) |
|
| 4200 | 4200 | { |
| 4201 | - $srctemplatepath=$record['fullname']; |
|
| 4201 | + $srctemplatepath = $record['fullname']; |
|
| 4202 | 4202 | break; |
| 4203 | 4203 | } |
| 4204 | 4204 | } |
@@ -4206,27 +4206,27 @@ discard block |
||
| 4206 | 4206 | |
| 4207 | 4207 | if (empty($srctemplatepath)) |
| 4208 | 4208 | { |
| 4209 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4209 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4210 | 4210 | return -1; |
| 4211 | 4211 | } |
| 4212 | 4212 | } |
| 4213 | 4213 | |
| 4214 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4214 | + if ($obj->type == 'odt' && !empty($srctemplatepath)) |
|
| 4215 | 4215 | { |
| 4216 | - if (! dol_is_file($srctemplatepath)) |
|
| 4216 | + if (!dol_is_file($srctemplatepath)) |
|
| 4217 | 4217 | { |
| 4218 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4218 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4219 | 4219 | return -1; |
| 4220 | 4220 | } |
| 4221 | 4221 | } |
| 4222 | 4222 | |
| 4223 | 4223 | // We save charset_output to restore it because write_file can change it if needed for |
| 4224 | 4224 | // output format that does not support UTF8. |
| 4225 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 4225 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 4226 | 4226 | |
| 4227 | 4227 | if (in_array(get_class($this), array('Adherent'))) |
| 4228 | 4228 | { |
| 4229 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4229 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4230 | 4230 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
| 4231 | 4231 | } |
| 4232 | 4232 | else |
@@ -4237,40 +4237,40 @@ discard block |
||
| 4237 | 4237 | |
| 4238 | 4238 | if ($resultwritefile > 0) |
| 4239 | 4239 | { |
| 4240 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4240 | + $outputlangs->charset_output = $sav_charset_output; |
|
| 4241 | 4241 | |
| 4242 | 4242 | // We delete old preview |
| 4243 | 4243 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 4244 | 4244 | dol_delete_preview($this); |
| 4245 | 4245 | |
| 4246 | 4246 | // Index file in database |
| 4247 | - if (! empty($obj->result['fullpath'])) |
|
| 4247 | + if (!empty($obj->result['fullpath'])) |
|
| 4248 | 4248 | { |
| 4249 | 4249 | $destfull = $obj->result['fullpath']; |
| 4250 | 4250 | $upload_dir = dirname($destfull); |
| 4251 | 4251 | $destfile = basename($destfull); |
| 4252 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); |
|
| 4252 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir); |
|
| 4253 | 4253 | |
| 4254 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 4254 | + if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir |
|
| 4255 | 4255 | { |
| 4256 | 4256 | $filename = basename($destfile); |
| 4257 | 4257 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); |
| 4258 | 4258 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); |
| 4259 | 4259 | |
| 4260 | 4260 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 4261 | - $ecmfile=new EcmFiles($this->db); |
|
| 4262 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4261 | + $ecmfile = new EcmFiles($this->db); |
|
| 4262 | + $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); |
|
| 4263 | 4263 | |
| 4264 | 4264 | // Set the public "share" key |
| 4265 | 4265 | $setsharekey = false; |
| 4266 | 4266 | if ($this->element == 'propal') |
| 4267 | 4267 | { |
| 4268 | - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4269 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4270 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4268 | + $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4269 | + if ($useonlinesignature) $setsharekey = true; |
|
| 4270 | + if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4271 | 4271 | } |
| 4272 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4273 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4272 | + if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4273 | + if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4274 | 4274 | if ($setsharekey) |
| 4275 | 4275 | { |
| 4276 | 4276 | if (empty($ecmfile->share)) // Because object not found or share not set yet |
@@ -4282,11 +4282,11 @@ discard block |
||
| 4282 | 4282 | |
| 4283 | 4283 | if ($result > 0) |
| 4284 | 4284 | { |
| 4285 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4285 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4286 | 4286 | $ecmfile->fullpath_orig = ''; |
| 4287 | 4287 | $ecmfile->gen_or_uploaded = 'generated'; |
| 4288 | - $ecmfile->description = ''; // indexed content |
|
| 4289 | - $ecmfile->keyword = ''; // keyword content |
|
| 4288 | + $ecmfile->description = ''; // indexed content |
|
| 4289 | + $ecmfile->keyword = ''; // keyword content |
|
| 4290 | 4290 | $result = $ecmfile->update($user); |
| 4291 | 4291 | if ($result < 0) |
| 4292 | 4292 | { |
@@ -4298,11 +4298,11 @@ discard block |
||
| 4298 | 4298 | $ecmfile->entity = $conf->entity; |
| 4299 | 4299 | $ecmfile->filepath = $rel_dir; |
| 4300 | 4300 | $ecmfile->filename = $filename; |
| 4301 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4301 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4302 | 4302 | $ecmfile->fullpath_orig = ''; |
| 4303 | 4303 | $ecmfile->gen_or_uploaded = 'generated'; |
| 4304 | - $ecmfile->description = ''; // indexed content |
|
| 4305 | - $ecmfile->keyword = ''; // keyword content |
|
| 4304 | + $ecmfile->description = ''; // indexed content |
|
| 4305 | + $ecmfile->keyword = ''; // keyword content |
|
| 4306 | 4306 | $result = $ecmfile->create($user); |
| 4307 | 4307 | if ($result < 0) |
| 4308 | 4308 | { |
@@ -4316,14 +4316,14 @@ discard block |
||
| 4316 | 4316 | //var_dump($obj->update_main_doc_field);exit; |
| 4317 | 4317 | |
| 4318 | 4318 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
| 4319 | - $update_main_doc_field=0; |
|
| 4320 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4321 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4319 | + $update_main_doc_field = 0; |
|
| 4320 | + if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1; |
|
| 4321 | + if ($update_main_doc_field && !empty($this->table_element)) |
|
| 4322 | 4322 | { |
| 4323 | 4323 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
| 4324 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 4324 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 4325 | 4325 | $resql = $this->db->query($sql); |
| 4326 | - if (! $resql) dol_print_error($this->db); |
|
| 4326 | + if (!$resql) dol_print_error($this->db); |
|
| 4327 | 4327 | } |
| 4328 | 4328 | } |
| 4329 | 4329 | } |
@@ -4339,7 +4339,7 @@ discard block |
||
| 4339 | 4339 | } |
| 4340 | 4340 | else |
| 4341 | 4341 | { |
| 4342 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4342 | + $outputlangs->charset_output = $sav_charset_output; |
|
| 4343 | 4343 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
| 4344 | 4344 | return -1; |
| 4345 | 4345 | } |
@@ -4347,8 +4347,8 @@ discard block |
||
| 4347 | 4347 | } |
| 4348 | 4348 | else |
| 4349 | 4349 | { |
| 4350 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file); |
|
| 4351 | - dol_print_error('',$this->error); |
|
| 4350 | + $this->error = $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file); |
|
| 4351 | + dol_print_error('', $this->error); |
|
| 4352 | 4352 | return -1; |
| 4353 | 4353 | } |
| 4354 | 4354 | } |
@@ -4364,9 +4364,9 @@ discard block |
||
| 4364 | 4364 | { |
| 4365 | 4365 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
| 4366 | 4366 | |
| 4367 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4367 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4368 | 4368 | |
| 4369 | - $file_osencoded=dol_osencode($file); |
|
| 4369 | + $file_osencoded = dol_osencode($file); |
|
| 4370 | 4370 | if (file_exists($file_osencoded)) |
| 4371 | 4371 | { |
| 4372 | 4372 | // Create small thumbs for company (Ratio is near 16/9) |
@@ -4396,7 +4396,7 @@ discard block |
||
| 4396 | 4396 | * @param string $alternatevalue Alternate value to use |
| 4397 | 4397 | * @return string|string[] Default value (can be an array if the GETPOST return an array) |
| 4398 | 4398 | **/ |
| 4399 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4399 | + function getDefaultCreateValueFor($fieldname, $alternatevalue = null) |
|
| 4400 | 4400 | { |
| 4401 | 4401 | global $conf, $_POST; |
| 4402 | 4402 | |
@@ -4405,16 +4405,16 @@ discard block |
||
| 4405 | 4405 | |
| 4406 | 4406 | if (isset($alternatevalue)) return $alternatevalue; |
| 4407 | 4407 | |
| 4408 | - $newelement=$this->element; |
|
| 4409 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4410 | - if ($newelement == 'commande') $newelement='order'; |
|
| 4408 | + $newelement = $this->element; |
|
| 4409 | + if ($newelement == 'facture') $newelement = 'invoice'; |
|
| 4410 | + if ($newelement == 'commande') $newelement = 'order'; |
|
| 4411 | 4411 | if (empty($newelement)) |
| 4412 | 4412 | { |
| 4413 | 4413 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); |
| 4414 | 4414 | return ''; |
| 4415 | 4415 | } |
| 4416 | 4416 | |
| 4417 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4417 | + $keyforfieldname = strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4418 | 4418 | //var_dump($keyforfieldname); |
| 4419 | 4419 | if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
| 4420 | 4420 | |
@@ -4438,21 +4438,21 @@ discard block |
||
| 4438 | 4438 | */ |
| 4439 | 4439 | function call_trigger($trigger_name, $user) |
| 4440 | 4440 | { |
| 4441 | - global $langs,$conf; |
|
| 4441 | + global $langs, $conf; |
|
| 4442 | 4442 | |
| 4443 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4444 | - $interface=new Interfaces($this->db); |
|
| 4445 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 4443 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
| 4444 | + $interface = new Interfaces($this->db); |
|
| 4445 | + $result = $interface->run_triggers($trigger_name, $this, $user, $langs, $conf); |
|
| 4446 | 4446 | |
| 4447 | 4447 | if ($result < 0) |
| 4448 | 4448 | { |
| 4449 | 4449 | if (!empty($this->errors)) |
| 4450 | 4450 | { |
| 4451 | - $this->errors=array_unique(array_merge($this->errors,$interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice. |
|
| 4451 | + $this->errors = array_unique(array_merge($this->errors, $interface->errors)); // We use array_unique because when a trigger call another trigger on same object, this->errors is added twice. |
|
| 4452 | 4452 | } |
| 4453 | 4453 | else |
| 4454 | 4454 | { |
| 4455 | - $this->errors=$interface->errors; |
|
| 4455 | + $this->errors = $interface->errors; |
|
| 4456 | 4456 | } |
| 4457 | 4457 | } |
| 4458 | 4458 | return $result; |
@@ -4470,16 +4470,16 @@ discard block |
||
| 4470 | 4470 | * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
| 4471 | 4471 | * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
| 4472 | 4472 | */ |
| 4473 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4473 | + function fetch_optionals($rowid = null, $optionsArray = null) |
|
| 4474 | 4474 | { |
| 4475 | - if (empty($rowid)) $rowid=$this->id; |
|
| 4475 | + if (empty($rowid)) $rowid = $this->id; |
|
| 4476 | 4476 | |
| 4477 | 4477 | // To avoid SQL errors. Probably not the better solution though |
| 4478 | 4478 | if (!$this->table_element) { |
| 4479 | 4479 | return 0; |
| 4480 | 4480 | } |
| 4481 | 4481 | |
| 4482 | - if (! is_array($optionsArray)) |
|
| 4482 | + if (!is_array($optionsArray)) |
|
| 4483 | 4483 | { |
| 4484 | 4484 | // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
| 4485 | 4485 | // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
@@ -4513,17 +4513,17 @@ discard block |
||
| 4513 | 4513 | { |
| 4514 | 4514 | if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
| 4515 | 4515 | { |
| 4516 | - $sql.= ", ".$name; |
|
| 4516 | + $sql .= ", ".$name; |
|
| 4517 | 4517 | } |
| 4518 | 4518 | } |
| 4519 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4520 | - $sql.= " WHERE fk_object = ".$rowid; |
|
| 4519 | + $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4520 | + $sql .= " WHERE fk_object = ".$rowid; |
|
| 4521 | 4521 | |
| 4522 | 4522 | dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); |
| 4523 | - $resql=$this->db->query($sql); |
|
| 4523 | + $resql = $this->db->query($sql); |
|
| 4524 | 4524 | if ($resql) |
| 4525 | 4525 | { |
| 4526 | - $numrows=$this->db->num_rows($resql); |
|
| 4526 | + $numrows = $this->db->num_rows($resql); |
|
| 4527 | 4527 | if ($numrows) |
| 4528 | 4528 | { |
| 4529 | 4529 | $tab = $this->db->fetch_array($resql); |
@@ -4531,17 +4531,17 @@ discard block |
||
| 4531 | 4531 | foreach ($tab as $key => $value) |
| 4532 | 4532 | { |
| 4533 | 4533 | // Test fetch_array ! is_int($key) because fetch_array result is a mix table with Key as alpha and Key as int (depend db engine) |
| 4534 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4534 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && !is_int($key)) |
|
| 4535 | 4535 | { |
| 4536 | 4536 | // we can add this attribute to object |
| 4537 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime'))) |
|
| 4537 | + if (!empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) |
|
| 4538 | 4538 | { |
| 4539 | 4539 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
| 4540 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4540 | + $this->array_options["options_".$key] = $this->db->jdate($value); |
|
| 4541 | 4541 | } |
| 4542 | 4542 | else |
| 4543 | 4543 | { |
| 4544 | - $this->array_options["options_".$key]=$value; |
|
| 4544 | + $this->array_options["options_".$key] = $value; |
|
| 4545 | 4545 | } |
| 4546 | 4546 | |
| 4547 | 4547 | //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]); |
@@ -4577,10 +4577,10 @@ discard block |
||
| 4577 | 4577 | |
| 4578 | 4578 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 4579 | 4579 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
| 4580 | - $resql=$this->db->query($sql_del); |
|
| 4581 | - if (! $resql) |
|
| 4580 | + $resql = $this->db->query($sql_del); |
|
| 4581 | + if (!$resql) |
|
| 4582 | 4582 | { |
| 4583 | - $this->error=$this->db->lasterror(); |
|
| 4583 | + $this->error = $this->db->lasterror(); |
|
| 4584 | 4584 | $this->db->rollback(); |
| 4585 | 4585 | return -1; |
| 4586 | 4586 | } |
@@ -4601,36 +4601,36 @@ discard block |
||
| 4601 | 4601 | * @return int -1=error, O=did nothing, 1=OK |
| 4602 | 4602 | * @see updateExtraField, setValueFrom |
| 4603 | 4603 | */ |
| 4604 | - function insertExtraFields($trigger='', $userused=null) |
|
| 4604 | + function insertExtraFields($trigger = '', $userused = null) |
|
| 4605 | 4605 | { |
| 4606 | - global $conf,$langs,$user; |
|
| 4606 | + global $conf, $langs, $user; |
|
| 4607 | 4607 | |
| 4608 | - if (empty($userused)) $userused=$user; |
|
| 4608 | + if (empty($userused)) $userused = $user; |
|
| 4609 | 4609 | |
| 4610 | - $error=0; |
|
| 4610 | + $error = 0; |
|
| 4611 | 4611 | |
| 4612 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4612 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4613 | 4613 | |
| 4614 | - if (! empty($this->array_options)) |
|
| 4614 | + if (!empty($this->array_options)) |
|
| 4615 | 4615 | { |
| 4616 | 4616 | // Check parameters |
| 4617 | 4617 | $langs->load('admin'); |
| 4618 | 4618 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 4619 | 4619 | $extrafields = new ExtraFields($this->db); |
| 4620 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4620 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4621 | 4621 | |
| 4622 | 4622 | //Eliminate copied source object extra_fields that do not exist in target object |
| 4623 | - $new_array_options=array(); |
|
| 4623 | + $new_array_options = array(); |
|
| 4624 | 4624 | foreach ($this->array_options as $key => $value) { |
| 4625 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4625 | + if (in_array(substr($key, 8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4626 | 4626 | $new_array_options[$key] = $value; |
| 4627 | 4627 | elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
| 4628 | 4628 | $new_array_options['options_'.$key] = $value; |
| 4629 | 4629 | } |
| 4630 | 4630 | |
| 4631 | - foreach($new_array_options as $key => $value) |
|
| 4631 | + foreach ($new_array_options as $key => $value) |
|
| 4632 | 4632 | { |
| 4633 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4633 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 4634 | 4634 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
| 4635 | 4635 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
| 4636 | 4636 | $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
@@ -4638,12 +4638,12 @@ discard block |
||
| 4638 | 4638 | |
| 4639 | 4639 | if ($attributeRequired) |
| 4640 | 4640 | { |
| 4641 | - $mandatorypb=false; |
|
| 4642 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4643 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4641 | + $mandatorypb = false; |
|
| 4642 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb = true; |
|
| 4643 | + if ($this->array_options[$key] === '') $mandatorypb = true; |
|
| 4644 | 4644 | if ($mandatorypb) |
| 4645 | 4645 | { |
| 4646 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel); |
|
| 4646 | + $this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel); |
|
| 4647 | 4647 | return -1; |
| 4648 | 4648 | } |
| 4649 | 4649 | } |
@@ -4651,12 +4651,12 @@ discard block |
||
| 4651 | 4651 | switch ($attributeType) |
| 4652 | 4652 | { |
| 4653 | 4653 | case 'int': |
| 4654 | - if (!is_numeric($value) && $value!='') |
|
| 4654 | + if (!is_numeric($value) && $value != '') |
|
| 4655 | 4655 | { |
| 4656 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4656 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4657 | 4657 | return -1; |
| 4658 | 4658 | } |
| 4659 | - elseif ($value=='') |
|
| 4659 | + elseif ($value == '') |
|
| 4660 | 4660 | { |
| 4661 | 4661 | $new_array_options[$key] = null; |
| 4662 | 4662 | } |
@@ -4668,11 +4668,11 @@ discard block |
||
| 4668 | 4668 | } |
| 4669 | 4669 | break;*/ |
| 4670 | 4670 | case 'password': |
| 4671 | - $algo=''; |
|
| 4671 | + $algo = ''; |
|
| 4672 | 4672 | if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
| 4673 | 4673 | { |
| 4674 | 4674 | // If there is an encryption choice, we use it to crypt data before insert |
| 4675 | - $algo=reset(array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])); |
|
| 4675 | + $algo = reset(array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])); |
|
| 4676 | 4676 | if ($algo != '') |
| 4677 | 4677 | { |
| 4678 | 4678 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
@@ -4683,7 +4683,7 @@ discard block |
||
| 4683 | 4683 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
| 4684 | 4684 | if ($this->array_options[$key] == $this->oldcopy->array_options[$key]) // If old value crypted in database is same than submited new value, it means we don't change it, so we don't update. |
| 4685 | 4685 | { |
| 4686 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4686 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4687 | 4687 | } |
| 4688 | 4688 | else |
| 4689 | 4689 | { |
@@ -4694,7 +4694,7 @@ discard block |
||
| 4694 | 4694 | } |
| 4695 | 4695 | else |
| 4696 | 4696 | { |
| 4697 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4697 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4698 | 4698 | } |
| 4699 | 4699 | } |
| 4700 | 4700 | } |
@@ -4713,7 +4713,7 @@ discard block |
||
| 4713 | 4713 | $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
| 4714 | 4714 | break; |
| 4715 | 4715 | case 'link': |
| 4716 | - $param_list=array_keys($attributeParam['options']); |
|
| 4716 | + $param_list = array_keys($attributeParam['options']); |
|
| 4717 | 4717 | // 0 : ObjectName |
| 4718 | 4718 | // 1 : classPath |
| 4719 | 4719 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -4722,18 +4722,18 @@ discard block |
||
| 4722 | 4722 | { |
| 4723 | 4723 | if ($value == '-1') // -1 is key for no defined in combo list of objects |
| 4724 | 4724 | { |
| 4725 | - $new_array_options[$key]=''; |
|
| 4725 | + $new_array_options[$key] = ''; |
|
| 4726 | 4726 | } |
| 4727 | 4727 | elseif ($value) |
| 4728 | 4728 | { |
| 4729 | 4729 | $object = new $InfoFieldList[0]($this->db); |
| 4730 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 4731 | - else $res=$object->fetch('',$value); |
|
| 4730 | + if (is_numeric($value)) $res = $object->fetch($value); |
|
| 4731 | + else $res = $object->fetch('', $value); |
|
| 4732 | 4732 | |
| 4733 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 4733 | + if ($res > 0) $new_array_options[$key] = $object->id; |
|
| 4734 | 4734 | else |
| 4735 | 4735 | { |
| 4736 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 4736 | + $this->error = "Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 4737 | 4737 | $this->db->rollback(); |
| 4738 | 4738 | return -1; |
| 4739 | 4739 | } |
@@ -4757,46 +4757,46 @@ discard block |
||
| 4757 | 4757 | $this->db->query($sql_del); |
| 4758 | 4758 | |
| 4759 | 4759 | $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
| 4760 | - foreach($new_array_options as $key => $value) |
|
| 4760 | + foreach ($new_array_options as $key => $value) |
|
| 4761 | 4761 | { |
| 4762 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4762 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 4763 | 4763 | // Add field of attribut |
| 4764 | 4764 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
| 4765 | - $sql.=",".$attributeKey; |
|
| 4765 | + $sql .= ",".$attributeKey; |
|
| 4766 | 4766 | } |
| 4767 | 4767 | $sql .= ") VALUES (".$this->id; |
| 4768 | 4768 | |
| 4769 | - foreach($new_array_options as $key => $value) |
|
| 4769 | + foreach ($new_array_options as $key => $value) |
|
| 4770 | 4770 | { |
| 4771 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4771 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 4772 | 4772 | // Add field of attribute |
| 4773 | 4773 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
| 4774 | 4774 | { |
| 4775 | 4775 | if ($new_array_options[$key] != '') |
| 4776 | 4776 | { |
| 4777 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 4777 | + $sql .= ",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 4778 | 4778 | } |
| 4779 | 4779 | else |
| 4780 | 4780 | { |
| 4781 | - $sql.=",null"; |
|
| 4781 | + $sql .= ",null"; |
|
| 4782 | 4782 | } |
| 4783 | 4783 | } |
| 4784 | 4784 | } |
| 4785 | - $sql.=")"; |
|
| 4785 | + $sql .= ")"; |
|
| 4786 | 4786 | |
| 4787 | 4787 | dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
| 4788 | 4788 | $resql = $this->db->query($sql); |
| 4789 | - if (! $resql) |
|
| 4789 | + if (!$resql) |
|
| 4790 | 4790 | { |
| 4791 | - $this->error=$this->db->lasterror(); |
|
| 4791 | + $this->error = $this->db->lasterror(); |
|
| 4792 | 4792 | $error++; |
| 4793 | 4793 | } |
| 4794 | 4794 | |
| 4795 | - if (! $error && $trigger) |
|
| 4795 | + if (!$error && $trigger) |
|
| 4796 | 4796 | { |
| 4797 | 4797 | // Call trigger |
| 4798 | - $this->context=array('extrafieldaddupdate'=>1); |
|
| 4799 | - $result=$this->call_trigger($trigger, $userused); |
|
| 4798 | + $this->context = array('extrafieldaddupdate'=>1); |
|
| 4799 | + $result = $this->call_trigger($trigger, $userused); |
|
| 4800 | 4800 | if ($result < 0) $error++; |
| 4801 | 4801 | // End call trigger |
| 4802 | 4802 | } |
@@ -4827,23 +4827,23 @@ discard block |
||
| 4827 | 4827 | */ |
| 4828 | 4828 | function updateExtraField($key, $trigger, $userused) |
| 4829 | 4829 | { |
| 4830 | - global $conf,$langs,$user; |
|
| 4830 | + global $conf, $langs, $user; |
|
| 4831 | 4831 | |
| 4832 | - if (empty($userused)) $userused=$user; |
|
| 4832 | + if (empty($userused)) $userused = $user; |
|
| 4833 | 4833 | |
| 4834 | - $error=0; |
|
| 4834 | + $error = 0; |
|
| 4835 | 4835 | |
| 4836 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4836 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4837 | 4837 | |
| 4838 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 4838 | + if (!empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 4839 | 4839 | { |
| 4840 | 4840 | // Check parameters |
| 4841 | 4841 | $langs->load('admin'); |
| 4842 | 4842 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 4843 | 4843 | $extrafields = new ExtraFields($this->db); |
| 4844 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4844 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4845 | 4845 | |
| 4846 | - $value=$this->array_options["options_".$key]; |
|
| 4846 | + $value = $this->array_options["options_".$key]; |
|
| 4847 | 4847 | |
| 4848 | 4848 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
| 4849 | 4849 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
@@ -4853,12 +4853,12 @@ discard block |
||
| 4853 | 4853 | switch ($attributeType) |
| 4854 | 4854 | { |
| 4855 | 4855 | case 'int': |
| 4856 | - if (!is_numeric($value) && $value!='') |
|
| 4856 | + if (!is_numeric($value) && $value != '') |
|
| 4857 | 4857 | { |
| 4858 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel); |
|
| 4858 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel); |
|
| 4859 | 4859 | return -1; |
| 4860 | 4860 | } |
| 4861 | - elseif ($value=='') |
|
| 4861 | + elseif ($value == '') |
|
| 4862 | 4862 | { |
| 4863 | 4863 | $this->array_options["options_".$key] = null; |
| 4864 | 4864 | } |
@@ -4873,13 +4873,13 @@ discard block |
||
| 4873 | 4873 | $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
| 4874 | 4874 | break; |
| 4875 | 4875 | case 'date': |
| 4876 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 4876 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
| 4877 | 4877 | break; |
| 4878 | 4878 | case 'datetime': |
| 4879 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 4879 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
| 4880 | 4880 | break; |
| 4881 | 4881 | case 'link': |
| 4882 | - $param_list=array_keys($attributeParam['options']); |
|
| 4882 | + $param_list = array_keys($attributeParam['options']); |
|
| 4883 | 4883 | // 0 : ObjectName |
| 4884 | 4884 | // 1 : classPath |
| 4885 | 4885 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -4887,8 +4887,8 @@ discard block |
||
| 4887 | 4887 | if ($value) |
| 4888 | 4888 | { |
| 4889 | 4889 | $object = new $InfoFieldList[0]($this->db); |
| 4890 | - $object->fetch(0,$value); |
|
| 4891 | - $this->array_options["options_".$key]=$object->id; |
|
| 4890 | + $object->fetch(0, $value); |
|
| 4891 | + $this->array_options["options_".$key] = $object->id; |
|
| 4892 | 4892 | } |
| 4893 | 4893 | break; |
| 4894 | 4894 | } |
@@ -4897,17 +4897,17 @@ discard block |
||
| 4897 | 4897 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
| 4898 | 4898 | $sql .= " WHERE fk_object = ".$this->id; |
| 4899 | 4899 | $resql = $this->db->query($sql); |
| 4900 | - if (! $resql) |
|
| 4900 | + if (!$resql) |
|
| 4901 | 4901 | { |
| 4902 | 4902 | $error++; |
| 4903 | - $this->error=$this->db->lasterror(); |
|
| 4903 | + $this->error = $this->db->lasterror(); |
|
| 4904 | 4904 | } |
| 4905 | 4905 | |
| 4906 | - if (! $error && $trigger) |
|
| 4906 | + if (!$error && $trigger) |
|
| 4907 | 4907 | { |
| 4908 | 4908 | // Call trigger |
| 4909 | - $this->context=array('extrafieldupdate'=>1); |
|
| 4910 | - $result=$this->call_trigger($trigger, $userused); |
|
| 4909 | + $this->context = array('extrafieldupdate'=>1); |
|
| 4910 | + $result = $this->call_trigger($trigger, $userused); |
|
| 4911 | 4911 | if ($result < 0) $error++; |
| 4912 | 4912 | // End call trigger |
| 4913 | 4913 | } |
@@ -4940,57 +4940,57 @@ discard block |
||
| 4940 | 4940 | * @param string|int $showsize Value for css to define size. May also be a numeric. |
| 4941 | 4941 | * @return string |
| 4942 | 4942 | */ |
| 4943 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 4943 | + function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $showsize = 0) |
|
| 4944 | 4944 | { |
| 4945 | - global $conf,$langs,$form; |
|
| 4945 | + global $conf, $langs, $form; |
|
| 4946 | 4946 | |
| 4947 | - if (! is_object($form)) |
|
| 4947 | + if (!is_object($form)) |
|
| 4948 | 4948 | { |
| 4949 | 4949 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 4950 | - $form=new Form($this->db); |
|
| 4950 | + $form = new Form($this->db); |
|
| 4951 | 4951 | } |
| 4952 | 4952 | |
| 4953 | 4953 | $objectid = $this->id; |
| 4954 | 4954 | |
| 4955 | - $label= $val['label']; |
|
| 4955 | + $label = $val['label']; |
|
| 4956 | 4956 | $type = $val['type']; |
| 4957 | 4957 | $size = $val['css']; |
| 4958 | 4958 | |
| 4959 | 4959 | // Convert var to be able to share same code than showInputField of extrafields |
| 4960 | 4960 | if (preg_match('/varchar\((\d+)\)/', $type, $reg)) |
| 4961 | 4961 | { |
| 4962 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 4962 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 4963 | 4963 | $size = $reg[1]; |
| 4964 | 4964 | } |
| 4965 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 4966 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 4967 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; |
|
| 4965 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 4966 | + if (is_array($val['arrayofkeyval'])) $type = 'select'; |
|
| 4967 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link'; |
|
| 4968 | 4968 | |
| 4969 | 4969 | //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used |
| 4970 | - $default=$val['default']; |
|
| 4971 | - $computed=$val['computed']; |
|
| 4972 | - $unique=$val['unique']; |
|
| 4973 | - $required=$val['required']; |
|
| 4974 | - $param=$val['param']; |
|
| 4970 | + $default = $val['default']; |
|
| 4971 | + $computed = $val['computed']; |
|
| 4972 | + $unique = $val['unique']; |
|
| 4973 | + $required = $val['required']; |
|
| 4974 | + $param = $val['param']; |
|
| 4975 | 4975 | if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
| 4976 | 4976 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
| 4977 | 4977 | { |
| 4978 | - $type='link'; |
|
| 4979 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 4978 | + $type = 'link'; |
|
| 4979 | + $param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 4980 | 4980 | } |
| 4981 | - $langfile=$val['langfile']; |
|
| 4982 | - $list=$val['list']; |
|
| 4983 | - $hidden=(abs($val['visible'])!=1 ? 1 : 0); |
|
| 4984 | - $help=$val['help']; |
|
| 4981 | + $langfile = $val['langfile']; |
|
| 4982 | + $list = $val['list']; |
|
| 4983 | + $hidden = (abs($val['visible']) != 1 ? 1 : 0); |
|
| 4984 | + $help = $val['help']; |
|
| 4985 | 4985 | |
| 4986 | 4986 | if ($computed) |
| 4987 | 4987 | { |
| 4988 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 4988 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 4989 | 4989 | else return ''; |
| 4990 | 4990 | } |
| 4991 | 4991 | |
| 4992 | 4992 | // Use in priorit showsize from parameters, then $val['css'] then autodefine |
| 4993 | - if (empty($showsize) && ! empty($val['css'])) |
|
| 4993 | + if (empty($showsize) && !empty($val['css'])) |
|
| 4994 | 4994 | { |
| 4995 | 4995 | $showsize = $val['css']; |
| 4996 | 4996 | } |
@@ -5006,18 +5006,18 @@ discard block |
||
| 5006 | 5006 | //$showsize=19; |
| 5007 | 5007 | $showsize = 'minwidth200imp'; |
| 5008 | 5008 | } |
| 5009 | - elseif (in_array($type,array('int','double','price'))) |
|
| 5009 | + elseif (in_array($type, array('int', 'double', 'price'))) |
|
| 5010 | 5010 | { |
| 5011 | 5011 | //$showsize=10; |
| 5012 | 5012 | $showsize = 'maxwidth75'; |
| 5013 | 5013 | } |
| 5014 | 5014 | elseif ($type == 'url') |
| 5015 | 5015 | { |
| 5016 | - $showsize='minwidth400'; |
|
| 5016 | + $showsize = 'minwidth400'; |
|
| 5017 | 5017 | } |
| 5018 | 5018 | elseif ($type == 'boolean') |
| 5019 | 5019 | { |
| 5020 | - $showsize=''; |
|
| 5020 | + $showsize = ''; |
|
| 5021 | 5021 | } |
| 5022 | 5022 | else |
| 5023 | 5023 | { |
@@ -5038,12 +5038,12 @@ discard block |
||
| 5038 | 5038 | } |
| 5039 | 5039 | //var_dump($showsize.' '.$size); |
| 5040 | 5040 | |
| 5041 | - if (in_array($type,array('date','datetime'))) |
|
| 5041 | + if (in_array($type, array('date', 'datetime'))) |
|
| 5042 | 5042 | { |
| 5043 | - $tmp=explode(',',$size); |
|
| 5044 | - $newsize=$tmp[0]; |
|
| 5043 | + $tmp = explode(',', $size); |
|
| 5044 | + $newsize = $tmp[0]; |
|
| 5045 | 5045 | |
| 5046 | - $showtime = in_array($type,array('datetime')) ? 1 : 0; |
|
| 5046 | + $showtime = in_array($type, array('datetime')) ? 1 : 0; |
|
| 5047 | 5047 | |
| 5048 | 5048 | // Do not show current date when field not required (see select_date() method) |
| 5049 | 5049 | if (!$required && $value == '') $value = '-1'; |
@@ -5051,220 +5051,220 @@ discard block |
||
| 5051 | 5051 | // TODO Must also support $moreparam |
| 5052 | 5052 | $out = $form->select_date($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, ($keyprefix != 'search_' ? 1 : 0), 1, 0, 1); |
| 5053 | 5053 | } |
| 5054 | - elseif (in_array($type,array('int','integer'))) |
|
| 5054 | + elseif (in_array($type, array('int', 'integer'))) |
|
| 5055 | 5055 | { |
| 5056 | - $tmp=explode(',',$size); |
|
| 5057 | - $newsize=$tmp[0]; |
|
| 5058 | - $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam?$moreparam:'').'>'; |
|
| 5056 | + $tmp = explode(',', $size); |
|
| 5057 | + $newsize = $tmp[0]; |
|
| 5058 | + $out = '<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.$value.'"'.($moreparam ? $moreparam : '').'>'; |
|
| 5059 | 5059 | } |
| 5060 | 5060 | elseif (preg_match('/varchar/', $type)) |
| 5061 | 5061 | { |
| 5062 | - $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5062 | + $out = '<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
| 5063 | 5063 | } |
| 5064 | 5064 | elseif (in_array($type, array('mail', 'phone', 'url'))) |
| 5065 | 5065 | { |
| 5066 | - $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5066 | + $out = '<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5067 | 5067 | } |
| 5068 | 5068 | elseif ($type == 'text') |
| 5069 | 5069 | { |
| 5070 | 5070 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5071 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,0,ROWS_5,'90%'); |
|
| 5072 | - $out=$doleditor->Create(1); |
|
| 5071 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, 0, ROWS_5, '90%'); |
|
| 5072 | + $out = $doleditor->Create(1); |
|
| 5073 | 5073 | } |
| 5074 | 5074 | elseif ($type == 'html') |
| 5075 | 5075 | { |
| 5076 | 5076 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5077 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); |
|
| 5078 | - $out=$doleditor->Create(1); |
|
| 5077 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); |
|
| 5078 | + $out = $doleditor->Create(1); |
|
| 5079 | 5079 | } |
| 5080 | 5080 | elseif ($type == 'boolean') |
| 5081 | 5081 | { |
| 5082 | - $checked=''; |
|
| 5082 | + $checked = ''; |
|
| 5083 | 5083 | if (!empty($value)) { |
| 5084 | - $checked=' checked value="1" '; |
|
| 5084 | + $checked = ' checked value="1" '; |
|
| 5085 | 5085 | } else { |
| 5086 | - $checked=' value="1" '; |
|
| 5086 | + $checked = ' value="1" '; |
|
| 5087 | 5087 | } |
| 5088 | - $out='<input type="checkbox" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5088 | + $out = '<input type="checkbox" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
| 5089 | 5089 | } |
| 5090 | 5090 | elseif ($type == 'price') |
| 5091 | 5091 | { |
| 5092 | 5092 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 5093 | - $value=price($value); |
|
| 5093 | + $value = price($value); |
|
| 5094 | 5094 | } |
| 5095 | - $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5095 | + $out = '<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5096 | 5096 | } |
| 5097 | 5097 | elseif ($type == 'double') |
| 5098 | 5098 | { |
| 5099 | 5099 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 5100 | - $value=price($value); |
|
| 5100 | + $value = price($value); |
|
| 5101 | 5101 | } |
| 5102 | - $out='<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5102 | + $out = '<input type="text" class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
| 5103 | 5103 | } |
| 5104 | 5104 | elseif ($type == 'select') |
| 5105 | 5105 | { |
| 5106 | 5106 | $out = ''; |
| 5107 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5107 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5108 | 5108 | { |
| 5109 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5110 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5109 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5110 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5111 | 5111 | } |
| 5112 | 5112 | |
| 5113 | - $out.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5114 | - if ((! isset($val['default'])) || ($val['notnull'] != 1)) $out.='<option value="0"> </option>'; |
|
| 5113 | + $out .= '<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5114 | + if ((!isset($val['default'])) || ($val['notnull'] != 1)) $out .= '<option value="0"> </option>'; |
|
| 5115 | 5115 | foreach ($param['options'] as $key => $val) |
| 5116 | 5116 | { |
| 5117 | 5117 | if ((string) $key == '') continue; |
| 5118 | 5118 | list($val, $parent) = explode('|', $val); |
| 5119 | - $out.='<option value="'.$key.'"'; |
|
| 5120 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5121 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5122 | - $out.='>'.$val.'</option>'; |
|
| 5119 | + $out .= '<option value="'.$key.'"'; |
|
| 5120 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
| 5121 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 5122 | + $out .= '>'.$val.'</option>'; |
|
| 5123 | 5123 | } |
| 5124 | - $out.='</select>'; |
|
| 5124 | + $out .= '</select>'; |
|
| 5125 | 5125 | } |
| 5126 | 5126 | elseif ($type == 'sellist') |
| 5127 | 5127 | { |
| 5128 | 5128 | $out = ''; |
| 5129 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5129 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5130 | 5130 | { |
| 5131 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5132 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5131 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5132 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5133 | 5133 | } |
| 5134 | 5134 | |
| 5135 | - $out.='<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5135 | + $out .= '<select class="flat '.$showsize.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5136 | 5136 | if (is_array($param['options'])) |
| 5137 | 5137 | { |
| 5138 | - $param_list=array_keys($param['options']); |
|
| 5138 | + $param_list = array_keys($param['options']); |
|
| 5139 | 5139 | $InfoFieldList = explode(":", $param_list[0]); |
| 5140 | 5140 | // 0 : tableName |
| 5141 | 5141 | // 1 : label field name |
| 5142 | 5142 | // 2 : key fields name (if differ of rowid) |
| 5143 | 5143 | // 3 : key field parent (for dependent lists) |
| 5144 | 5144 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 5145 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5145 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 5146 | 5146 | |
| 5147 | 5147 | |
| 5148 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5148 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) |
|
| 5149 | 5149 | { |
| 5150 | 5150 | if (strpos($InfoFieldList[4], 'extra.') !== false) |
| 5151 | 5151 | { |
| 5152 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5152 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 5153 | 5153 | } else { |
| 5154 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5154 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5155 | 5155 | } |
| 5156 | 5156 | } |
| 5157 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5157 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) |
|
| 5158 | 5158 | { |
| 5159 | 5159 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
| 5160 | - $keyList.= ', '.$parentField; |
|
| 5160 | + $keyList .= ', '.$parentField; |
|
| 5161 | 5161 | } |
| 5162 | 5162 | |
| 5163 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 5163 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 5164 | 5164 | if (is_array($fields_label)) |
| 5165 | 5165 | { |
| 5166 | - $keyList .=', '; |
|
| 5166 | + $keyList .= ', '; |
|
| 5167 | 5167 | $keyList .= implode(', ', $fields_label); |
| 5168 | 5168 | } |
| 5169 | 5169 | |
| 5170 | - $sqlwhere=''; |
|
| 5170 | + $sqlwhere = ''; |
|
| 5171 | 5171 | $sql = 'SELECT '.$keyList; |
| 5172 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5172 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5173 | 5173 | if (!empty($InfoFieldList[4])) |
| 5174 | 5174 | { |
| 5175 | 5175 | // can use SELECT request |
| 5176 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
| 5177 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
| 5176 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
| 5177 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
| 5178 | 5178 | } |
| 5179 | 5179 | |
| 5180 | 5180 | // current object id can be use into filter |
| 5181 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
| 5182 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
| 5181 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
| 5182 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
| 5183 | 5183 | } else { |
| 5184 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 5184 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 5185 | 5185 | } |
| 5186 | 5186 | //We have to join on extrafield table |
| 5187 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5187 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 5188 | 5188 | { |
| 5189 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5190 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5189 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 5190 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 5191 | 5191 | } |
| 5192 | 5192 | else |
| 5193 | 5193 | { |
| 5194 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5194 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 5195 | 5195 | } |
| 5196 | 5196 | } |
| 5197 | 5197 | else |
| 5198 | 5198 | { |
| 5199 | - $sqlwhere.= ' WHERE 1=1'; |
|
| 5199 | + $sqlwhere .= ' WHERE 1=1'; |
|
| 5200 | 5200 | } |
| 5201 | 5201 | // Some tables may have field, some other not. For the moment we disable it. |
| 5202 | - if (in_array($InfoFieldList[0],array('tablewithentity'))) |
|
| 5202 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
| 5203 | 5203 | { |
| 5204 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
| 5204 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 5205 | 5205 | } |
| 5206 | - $sql.=$sqlwhere; |
|
| 5206 | + $sql .= $sqlwhere; |
|
| 5207 | 5207 | //print $sql; |
| 5208 | 5208 | |
| 5209 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label); |
|
| 5209 | + $sql .= ' ORDER BY '.implode(', ', $fields_label); |
|
| 5210 | 5210 | |
| 5211 | 5211 | dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
| 5212 | 5212 | $resql = $this->db->query($sql); |
| 5213 | 5213 | if ($resql) |
| 5214 | 5214 | { |
| 5215 | - $out.='<option value="0"> </option>'; |
|
| 5215 | + $out .= '<option value="0"> </option>'; |
|
| 5216 | 5216 | $num = $this->db->num_rows($resql); |
| 5217 | 5217 | $i = 0; |
| 5218 | 5218 | while ($i < $num) |
| 5219 | 5219 | { |
| 5220 | - $labeltoshow=''; |
|
| 5220 | + $labeltoshow = ''; |
|
| 5221 | 5221 | $obj = $this->db->fetch_object($resql); |
| 5222 | 5222 | |
| 5223 | 5223 | // Several field into label (eq table:code|libelle:rowid) |
| 5224 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 5225 | - if(is_array($fields_label)) |
|
| 5224 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 5225 | + if (is_array($fields_label)) |
|
| 5226 | 5226 | { |
| 5227 | 5227 | $notrans = true; |
| 5228 | 5228 | foreach ($fields_label as $field_toshow) |
| 5229 | 5229 | { |
| 5230 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5230 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 5231 | 5231 | } |
| 5232 | 5232 | } |
| 5233 | 5233 | else |
| 5234 | 5234 | { |
| 5235 | - $labeltoshow=$obj->{$InfoFieldList[1]}; |
|
| 5235 | + $labeltoshow = $obj->{$InfoFieldList[1]}; |
|
| 5236 | 5236 | } |
| 5237 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5237 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5238 | 5238 | |
| 5239 | - if ($value==$obj->rowid) |
|
| 5239 | + if ($value == $obj->rowid) |
|
| 5240 | 5240 | { |
| 5241 | 5241 | foreach ($fields_label as $field_toshow) |
| 5242 | 5242 | { |
| 5243 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 5244 | - if ($translabel!=$obj->$field_toshow) { |
|
| 5245 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5246 | - }else { |
|
| 5247 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5243 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 5244 | + if ($translabel != $obj->$field_toshow) { |
|
| 5245 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 5246 | + } else { |
|
| 5247 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 5248 | 5248 | } |
| 5249 | 5249 | } |
| 5250 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5250 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5251 | 5251 | } |
| 5252 | 5252 | else |
| 5253 | 5253 | { |
| 5254 | - if(!$notrans) |
|
| 5254 | + if (!$notrans) |
|
| 5255 | 5255 | { |
| 5256 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
| 5257 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
| 5258 | - $labeltoshow=dol_trunc($translabel,18); |
|
| 5256 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
| 5257 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
| 5258 | + $labeltoshow = dol_trunc($translabel, 18); |
|
| 5259 | 5259 | } |
| 5260 | 5260 | else { |
| 5261 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
|
| 5261 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]},18); |
|
| 5262 | 5262 | } |
| 5263 | 5263 | } |
| 5264 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5265 | - if ($value==$obj->rowid) |
|
| 5264 | + if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
|
| 5265 | + if ($value == $obj->rowid) |
|
| 5266 | 5266 | { |
| 5267 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5267 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5268 | 5268 | } |
| 5269 | 5269 | |
| 5270 | 5270 | if (!empty($InfoFieldList[3])) |
@@ -5272,10 +5272,10 @@ discard block |
||
| 5272 | 5272 | $parent = $parentName.':'.$obj->{$parentField}; |
| 5273 | 5273 | } |
| 5274 | 5274 | |
| 5275 | - $out.='<option value="'.$obj->rowid.'"'; |
|
| 5276 | - $out.= ($value==$obj->rowid?' selected':''); |
|
| 5277 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5278 | - $out.='>'.$labeltoshow.'</option>'; |
|
| 5275 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 5276 | + $out .= ($value == $obj->rowid ? ' selected' : ''); |
|
| 5277 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 5278 | + $out .= '>'.$labeltoshow.'</option>'; |
|
| 5279 | 5279 | } |
| 5280 | 5280 | |
| 5281 | 5281 | $i++; |
@@ -5286,23 +5286,23 @@ discard block |
||
| 5286 | 5286 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 5287 | 5287 | } |
| 5288 | 5288 | } |
| 5289 | - $out.='</select>'; |
|
| 5289 | + $out .= '</select>'; |
|
| 5290 | 5290 | } |
| 5291 | 5291 | elseif ($type == 'checkbox') |
| 5292 | 5292 | { |
| 5293 | - $value_arr=explode(',',$value); |
|
| 5294 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5293 | + $value_arr = explode(',', $value); |
|
| 5294 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5295 | 5295 | } |
| 5296 | 5296 | elseif ($type == 'radio') |
| 5297 | 5297 | { |
| 5298 | - $out=''; |
|
| 5298 | + $out = ''; |
|
| 5299 | 5299 | foreach ($param['options'] as $keyopt => $val) |
| 5300 | 5300 | { |
| 5301 | - $out.='<input class="flat '.$showsize.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5302 | - $out.=' value="'.$keyopt.'"'; |
|
| 5303 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5304 | - $out.= ($value==$keyopt?'checked':''); |
|
| 5305 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5301 | + $out .= '<input class="flat '.$showsize.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
| 5302 | + $out .= ' value="'.$keyopt.'"'; |
|
| 5303 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5304 | + $out .= ($value == $keyopt ? 'checked' : ''); |
|
| 5305 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5306 | 5306 | } |
| 5307 | 5307 | } |
| 5308 | 5308 | elseif ($type == 'chkbxlst') |
@@ -5322,17 +5322,17 @@ discard block |
||
| 5322 | 5322 | // 2 : key fields name (if differ of rowid) |
| 5323 | 5323 | // 3 : key field parent (for dependent lists) |
| 5324 | 5324 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 5325 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5325 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 5326 | 5326 | |
| 5327 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) { |
|
| 5328 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]); |
|
| 5329 | - $keyList .= ', ' . $parentField; |
|
| 5327 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) { |
|
| 5328 | + list ($parentName, $parentField) = explode('|', $InfoFieldList[3]); |
|
| 5329 | + $keyList .= ', '.$parentField; |
|
| 5330 | 5330 | } |
| 5331 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) { |
|
| 5331 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) { |
|
| 5332 | 5332 | if (strpos($InfoFieldList[4], 'extra.') !== false) { |
| 5333 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5333 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 5334 | 5334 | } else { |
| 5335 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5335 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5336 | 5336 | } |
| 5337 | 5337 | } |
| 5338 | 5338 | |
@@ -5343,50 +5343,50 @@ discard block |
||
| 5343 | 5343 | } |
| 5344 | 5344 | |
| 5345 | 5345 | $sqlwhere = ''; |
| 5346 | - $sql = 'SELECT ' . $keyList; |
|
| 5347 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5348 | - if (! empty($InfoFieldList[4])) { |
|
| 5346 | + $sql = 'SELECT '.$keyList; |
|
| 5347 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5348 | + if (!empty($InfoFieldList[4])) { |
|
| 5349 | 5349 | |
| 5350 | 5350 | // can use SELECT request |
| 5351 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) { |
|
| 5352 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); |
|
| 5351 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) { |
|
| 5352 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]); |
|
| 5353 | 5353 | } |
| 5354 | 5354 | |
| 5355 | 5355 | // current object id can be use into filter |
| 5356 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { |
|
| 5357 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); |
|
| 5356 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) { |
|
| 5357 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]); |
|
| 5358 | 5358 | } else { |
| 5359 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
|
| 5359 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]); |
|
| 5360 | 5360 | } |
| 5361 | 5361 | |
| 5362 | 5362 | // We have to join on extrafield table |
| 5363 | 5363 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
| 5364 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5365 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5364 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 5365 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 5366 | 5366 | } else { |
| 5367 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5367 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 5368 | 5368 | } |
| 5369 | 5369 | } else { |
| 5370 | 5370 | $sqlwhere .= ' WHERE 1=1'; |
| 5371 | 5371 | } |
| 5372 | 5372 | // Some tables may have field, some other not. For the moment we disable it. |
| 5373 | - if (in_array($InfoFieldList[0], array ('tablewithentity'))) |
|
| 5373 | + if (in_array($InfoFieldList[0], array('tablewithentity'))) |
|
| 5374 | 5374 | { |
| 5375 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
| 5375 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 5376 | 5376 | } |
| 5377 | 5377 | // $sql.=preg_replace('/^ AND /','',$sqlwhere); |
| 5378 | 5378 | // print $sql; |
| 5379 | 5379 | |
| 5380 | 5380 | $sql .= $sqlwhere; |
| 5381 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5381 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
| 5382 | 5382 | $resql = $this->db->query($sql); |
| 5383 | 5383 | if ($resql) { |
| 5384 | 5384 | $num = $this->db->num_rows($resql); |
| 5385 | 5385 | $i = 0; |
| 5386 | 5386 | |
| 5387 | - $data=array(); |
|
| 5387 | + $data = array(); |
|
| 5388 | 5388 | |
| 5389 | - while ( $i < $num ) { |
|
| 5389 | + while ($i < $num) { |
|
| 5390 | 5390 | $labeltoshow = ''; |
| 5391 | 5391 | $obj = $this->db->fetch_object($resql); |
| 5392 | 5392 | |
@@ -5394,8 +5394,8 @@ discard block |
||
| 5394 | 5394 | $fields_label = explode('|', $InfoFieldList[1]); |
| 5395 | 5395 | if (is_array($fields_label)) { |
| 5396 | 5396 | $notrans = true; |
| 5397 | - foreach ( $fields_label as $field_toshow ) { |
|
| 5398 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 5397 | + foreach ($fields_label as $field_toshow) { |
|
| 5398 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 5399 | 5399 | } |
| 5400 | 5400 | } else { |
| 5401 | 5401 | $labeltoshow = $obj->{$InfoFieldList[1]}; |
@@ -5403,19 +5403,19 @@ discard block |
||
| 5403 | 5403 | $labeltoshow = dol_trunc($labeltoshow, 45); |
| 5404 | 5404 | |
| 5405 | 5405 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 5406 | - foreach ( $fields_label as $field_toshow ) { |
|
| 5406 | + foreach ($fields_label as $field_toshow) { |
|
| 5407 | 5407 | $translabel = $langs->trans($obj->$field_toshow); |
| 5408 | 5408 | if ($translabel != $obj->$field_toshow) { |
| 5409 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5409 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 5410 | 5410 | } else { |
| 5411 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5411 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 5412 | 5412 | } |
| 5413 | 5413 | } |
| 5414 | 5414 | |
| 5415 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5415 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5416 | 5416 | |
| 5417 | 5417 | } else { |
| 5418 | - if (! $notrans) { |
|
| 5418 | + if (!$notrans) { |
|
| 5419 | 5419 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
| 5420 | 5420 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
| 5421 | 5421 | $labeltoshow = dol_trunc($translabel, 18); |
@@ -5427,41 +5427,41 @@ discard block |
||
| 5427 | 5427 | $labeltoshow = '(not defined)'; |
| 5428 | 5428 | |
| 5429 | 5429 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 5430 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5430 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5431 | 5431 | } |
| 5432 | 5432 | |
| 5433 | - if (! empty($InfoFieldList[3])) { |
|
| 5434 | - $parent = $parentName . ':' . $obj->{$parentField}; |
|
| 5433 | + if (!empty($InfoFieldList[3])) { |
|
| 5434 | + $parent = $parentName.':'.$obj->{$parentField}; |
|
| 5435 | 5435 | } |
| 5436 | 5436 | |
| 5437 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5437 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5438 | 5438 | } |
| 5439 | 5439 | |
| 5440 | - $i ++; |
|
| 5440 | + $i++; |
|
| 5441 | 5441 | } |
| 5442 | 5442 | $this->db->free($resql); |
| 5443 | 5443 | |
| 5444 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5444 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5445 | 5445 | |
| 5446 | 5446 | } else { |
| 5447 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5447 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5448 | 5448 | } |
| 5449 | 5449 | } |
| 5450 | 5450 | $out .= '</select>'; |
| 5451 | 5451 | } |
| 5452 | 5452 | elseif ($type == 'link') |
| 5453 | 5453 | { |
| 5454 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5455 | - $showempty=(($val['notnull'] == 1 && $val['default'] != '')?0:1); |
|
| 5456 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5454 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5455 | + $showempty = (($val['notnull'] == 1 && $val['default'] != '') ? 0 : 1); |
|
| 5456 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5457 | 5457 | } |
| 5458 | 5458 | elseif ($type == 'password') |
| 5459 | 5459 | { |
| 5460 | 5460 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 5461 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$showsize.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5461 | + $out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$showsize.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5462 | 5462 | } |
| 5463 | 5463 | if (!empty($hidden)) { |
| 5464 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5464 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5465 | 5465 | } |
| 5466 | 5466 | /* Add comments |
| 5467 | 5467 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -5484,14 +5484,14 @@ discard block |
||
| 5484 | 5484 | * @param mixed $showsize Value for css to define size. May also be a numeric. |
| 5485 | 5485 | * @return string |
| 5486 | 5486 | */ |
| 5487 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5487 | + function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $showsize = 0) |
|
| 5488 | 5488 | { |
| 5489 | - global $conf,$langs,$form; |
|
| 5489 | + global $conf, $langs, $form; |
|
| 5490 | 5490 | |
| 5491 | - if (! is_object($form)) |
|
| 5491 | + if (!is_object($form)) |
|
| 5492 | 5492 | { |
| 5493 | 5493 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 5494 | - $form=new Form($this->db); |
|
| 5494 | + $form = new Form($this->db); |
|
| 5495 | 5495 | } |
| 5496 | 5496 | |
| 5497 | 5497 | $objectid = $this->id; |
@@ -5502,29 +5502,29 @@ discard block |
||
| 5502 | 5502 | // Convert var to be able to share same code than showOutputField of extrafields |
| 5503 | 5503 | if (preg_match('/varchar\((\d+)\)/', $type, $reg)) |
| 5504 | 5504 | { |
| 5505 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5505 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5506 | 5506 | $size = $reg[1]; |
| 5507 | 5507 | } |
| 5508 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5509 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5510 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link'; |
|
| 5508 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5509 | + if (is_array($val['arrayofkeyval'])) $type = 'select'; |
|
| 5510 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link'; |
|
| 5511 | 5511 | |
| 5512 | 5512 | //$elementtype=$this->attribute_elementtype[$key]; // seems to not be used |
| 5513 | - $default=$val['default']; |
|
| 5514 | - $computed=$val['computed']; |
|
| 5515 | - $unique=$val['unique']; |
|
| 5516 | - $required=$val['required']; |
|
| 5517 | - $param=$val['param']; |
|
| 5513 | + $default = $val['default']; |
|
| 5514 | + $computed = $val['computed']; |
|
| 5515 | + $unique = $val['unique']; |
|
| 5516 | + $required = $val['required']; |
|
| 5517 | + $param = $val['param']; |
|
| 5518 | 5518 | if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
| 5519 | 5519 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) |
| 5520 | 5520 | { |
| 5521 | - $type='link'; |
|
| 5522 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5521 | + $type = 'link'; |
|
| 5522 | + $param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5523 | 5523 | } |
| 5524 | - $langfile=$val['langfile']; |
|
| 5525 | - $list=$val['list']; |
|
| 5526 | - $help=$val['help']; |
|
| 5527 | - $hidden=(($val['visible'] == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 5524 | + $langfile = $val['langfile']; |
|
| 5525 | + $list = $val['list']; |
|
| 5526 | + $help = $val['help']; |
|
| 5527 | + $hidden = (($val['visible'] == 0) ? 1 : 0); // If zero, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
|
| 5528 | 5528 | |
| 5529 | 5529 | if ($hidden) return ''; |
| 5530 | 5530 | |
@@ -5548,18 +5548,18 @@ discard block |
||
| 5548 | 5548 | //$showsize=19; |
| 5549 | 5549 | $showsize = 'minwidth200imp'; |
| 5550 | 5550 | } |
| 5551 | - elseif (in_array($type,array('int','double','price'))) |
|
| 5551 | + elseif (in_array($type, array('int', 'double', 'price'))) |
|
| 5552 | 5552 | { |
| 5553 | 5553 | //$showsize=10; |
| 5554 | 5554 | $showsize = 'maxwidth75'; |
| 5555 | 5555 | } |
| 5556 | 5556 | elseif ($type == 'url') |
| 5557 | 5557 | { |
| 5558 | - $showsize='minwidth400'; |
|
| 5558 | + $showsize = 'minwidth400'; |
|
| 5559 | 5559 | } |
| 5560 | 5560 | elseif ($type == 'boolean') |
| 5561 | 5561 | { |
| 5562 | - $showsize=''; |
|
| 5562 | + $showsize = ''; |
|
| 5563 | 5563 | } |
| 5564 | 5564 | else |
| 5565 | 5565 | { |
@@ -5580,82 +5580,82 @@ discard block |
||
| 5580 | 5580 | } |
| 5581 | 5581 | |
| 5582 | 5582 | // Format output value differently according to properties of field |
| 5583 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5584 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5583 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1); |
|
| 5584 | + elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3); |
|
| 5585 | 5585 | elseif ($type == 'date') |
| 5586 | 5586 | { |
| 5587 | - $value=dol_print_date($value,'day'); |
|
| 5587 | + $value = dol_print_date($value, 'day'); |
|
| 5588 | 5588 | } |
| 5589 | 5589 | elseif ($type == 'datetime') |
| 5590 | 5590 | { |
| 5591 | - $value=dol_print_date($value,'dayhour'); |
|
| 5591 | + $value = dol_print_date($value, 'dayhour'); |
|
| 5592 | 5592 | } |
| 5593 | 5593 | elseif ($type == 'double') |
| 5594 | 5594 | { |
| 5595 | 5595 | if (!empty($value)) { |
| 5596 | - $value=price($value); |
|
| 5596 | + $value = price($value); |
|
| 5597 | 5597 | } |
| 5598 | 5598 | } |
| 5599 | 5599 | elseif ($type == 'boolean') |
| 5600 | 5600 | { |
| 5601 | - $checked=''; |
|
| 5601 | + $checked = ''; |
|
| 5602 | 5602 | if (!empty($value)) { |
| 5603 | - $checked=' checked '; |
|
| 5603 | + $checked = ' checked '; |
|
| 5604 | 5604 | } |
| 5605 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 5605 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
| 5606 | 5606 | } |
| 5607 | 5607 | elseif ($type == 'mail') |
| 5608 | 5608 | { |
| 5609 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 5609 | + $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
| 5610 | 5610 | } |
| 5611 | 5611 | elseif ($type == 'url') |
| 5612 | 5612 | { |
| 5613 | - $value=dol_print_url($value,'_blank',32,1); |
|
| 5613 | + $value = dol_print_url($value, '_blank', 32, 1); |
|
| 5614 | 5614 | } |
| 5615 | 5615 | elseif ($type == 'phone') |
| 5616 | 5616 | { |
| 5617 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 5617 | + $value = dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 5618 | 5618 | } |
| 5619 | 5619 | elseif ($type == 'price') |
| 5620 | 5620 | { |
| 5621 | - $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
| 5621 | + $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
| 5622 | 5622 | } |
| 5623 | 5623 | elseif ($type == 'select') |
| 5624 | 5624 | { |
| 5625 | - $value=$param['options'][$value]; |
|
| 5625 | + $value = $param['options'][$value]; |
|
| 5626 | 5626 | } |
| 5627 | 5627 | elseif ($type == 'sellist') |
| 5628 | 5628 | { |
| 5629 | - $param_list=array_keys($param['options']); |
|
| 5629 | + $param_list = array_keys($param['options']); |
|
| 5630 | 5630 | $InfoFieldList = explode(":", $param_list[0]); |
| 5631 | 5631 | |
| 5632 | - $selectkey="rowid"; |
|
| 5633 | - $keyList='rowid'; |
|
| 5632 | + $selectkey = "rowid"; |
|
| 5633 | + $keyList = 'rowid'; |
|
| 5634 | 5634 | |
| 5635 | - if (count($InfoFieldList)>=3) |
|
| 5635 | + if (count($InfoFieldList) >= 3) |
|
| 5636 | 5636 | { |
| 5637 | 5637 | $selectkey = $InfoFieldList[2]; |
| 5638 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5638 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5639 | 5639 | } |
| 5640 | 5640 | |
| 5641 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 5642 | - if(is_array($fields_label)) { |
|
| 5643 | - $keyList .=', '; |
|
| 5641 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 5642 | + if (is_array($fields_label)) { |
|
| 5643 | + $keyList .= ', '; |
|
| 5644 | 5644 | $keyList .= implode(', ', $fields_label); |
| 5645 | 5645 | } |
| 5646 | 5646 | |
| 5647 | 5647 | $sql = 'SELECT '.$keyList; |
| 5648 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5649 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5648 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5649 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 5650 | 5650 | { |
| 5651 | - $sql.= ' as main'; |
|
| 5651 | + $sql .= ' as main'; |
|
| 5652 | 5652 | } |
| 5653 | - if ($selectkey=='rowid' && empty($value)) { |
|
| 5654 | - $sql.= " WHERE ".$selectkey."=0"; |
|
| 5655 | - } elseif ($selectkey=='rowid') { |
|
| 5656 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 5657 | - }else { |
|
| 5658 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 5653 | + if ($selectkey == 'rowid' && empty($value)) { |
|
| 5654 | + $sql .= " WHERE ".$selectkey."=0"; |
|
| 5655 | + } elseif ($selectkey == 'rowid') { |
|
| 5656 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 5657 | + } else { |
|
| 5658 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 5659 | 5659 | } |
| 5660 | 5660 | |
| 5661 | 5661 | //$sql.= ' AND entity = '.$conf->entity; |
@@ -5664,38 +5664,38 @@ discard block |
||
| 5664 | 5664 | $resql = $this->db->query($sql); |
| 5665 | 5665 | if ($resql) |
| 5666 | 5666 | { |
| 5667 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
| 5667 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 5668 | 5668 | |
| 5669 | 5669 | $obj = $this->db->fetch_object($resql); |
| 5670 | 5670 | |
| 5671 | 5671 | // Several field into label (eq table:code|libelle:rowid) |
| 5672 | - $fields_label = explode('|',$InfoFieldList[1]); |
|
| 5672 | + $fields_label = explode('|', $InfoFieldList[1]); |
|
| 5673 | 5673 | |
| 5674 | - if(is_array($fields_label) && count($fields_label)>1) |
|
| 5674 | + if (is_array($fields_label) && count($fields_label) > 1) |
|
| 5675 | 5675 | { |
| 5676 | 5676 | foreach ($fields_label as $field_toshow) |
| 5677 | 5677 | { |
| 5678 | - $translabel=''; |
|
| 5678 | + $translabel = ''; |
|
| 5679 | 5679 | if (!empty($obj->$field_toshow)) { |
| 5680 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 5680 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 5681 | 5681 | } |
| 5682 | - if ($translabel!=$field_toshow) { |
|
| 5683 | - $value.=dol_trunc($translabel,18).' '; |
|
| 5684 | - }else { |
|
| 5685 | - $value.=$obj->$field_toshow.' '; |
|
| 5682 | + if ($translabel != $field_toshow) { |
|
| 5683 | + $value .= dol_trunc($translabel, 18).' '; |
|
| 5684 | + } else { |
|
| 5685 | + $value .= $obj->$field_toshow.' '; |
|
| 5686 | 5686 | } |
| 5687 | 5687 | } |
| 5688 | 5688 | } |
| 5689 | 5689 | else |
| 5690 | 5690 | { |
| 5691 | - $translabel=''; |
|
| 5691 | + $translabel = ''; |
|
| 5692 | 5692 | if (!empty($obj->{$InfoFieldList[1]})) { |
| 5693 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
|
| 5693 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
|
| 5694 | 5694 | } |
| 5695 | - if ($translabel!=$obj->{$InfoFieldList[1]}) { |
|
| 5696 | - $value=dol_trunc($translabel,18); |
|
| 5697 | - }else { |
|
| 5698 | - $value=$obj->{$InfoFieldList[1]}; |
|
| 5695 | + if ($translabel != $obj->{$InfoFieldList[1]}) { |
|
| 5696 | + $value = dol_trunc($translabel, 18); |
|
| 5697 | + } else { |
|
| 5698 | + $value = $obj->{$InfoFieldList[1]}; |
|
| 5699 | 5699 | } |
| 5700 | 5700 | } |
| 5701 | 5701 | } |
@@ -5703,19 +5703,19 @@ discard block |
||
| 5703 | 5703 | } |
| 5704 | 5704 | elseif ($type == 'radio') |
| 5705 | 5705 | { |
| 5706 | - $value=$param['options'][$value]; |
|
| 5706 | + $value = $param['options'][$value]; |
|
| 5707 | 5707 | } |
| 5708 | 5708 | elseif ($type == 'checkbox') |
| 5709 | 5709 | { |
| 5710 | - $value_arr=explode(',',$value); |
|
| 5711 | - $value=''; |
|
| 5710 | + $value_arr = explode(',', $value); |
|
| 5711 | + $value = ''; |
|
| 5712 | 5712 | if (is_array($value_arr)) |
| 5713 | 5713 | { |
| 5714 | 5714 | foreach ($value_arr as $keyval=>$valueval) { |
| 5715 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 5715 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 5716 | 5716 | } |
| 5717 | 5717 | } |
| 5718 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 5718 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 5719 | 5719 | } |
| 5720 | 5720 | elseif ($type == 'chkbxlst') |
| 5721 | 5721 | { |
@@ -5729,7 +5729,7 @@ discard block |
||
| 5729 | 5729 | |
| 5730 | 5730 | if (count($InfoFieldList) >= 3) { |
| 5731 | 5731 | $selectkey = $InfoFieldList[2]; |
| 5732 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5732 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5733 | 5733 | } |
| 5734 | 5734 | |
| 5735 | 5735 | $fields_label = explode('|', $InfoFieldList[1]); |
@@ -5738,75 +5738,75 @@ discard block |
||
| 5738 | 5738 | $keyList .= implode(', ', $fields_label); |
| 5739 | 5739 | } |
| 5740 | 5740 | |
| 5741 | - $sql = 'SELECT ' . $keyList; |
|
| 5742 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5741 | + $sql = 'SELECT '.$keyList; |
|
| 5742 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5743 | 5743 | if (strpos($InfoFieldList[4], 'extra') !== false) { |
| 5744 | 5744 | $sql .= ' as main'; |
| 5745 | 5745 | } |
| 5746 | 5746 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 5747 | 5747 | // $sql.= ' AND entity = '.$conf->entity; |
| 5748 | 5748 | |
| 5749 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 5749 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
| 5750 | 5750 | $resql = $this->db->query($sql); |
| 5751 | 5751 | if ($resql) { |
| 5752 | 5752 | $value = ''; // value was used, so now we reste it to use it to build final output |
| 5753 | - $toprint=array(); |
|
| 5754 | - while ( $obj = $this->db->fetch_object($resql) ) { |
|
| 5753 | + $toprint = array(); |
|
| 5754 | + while ($obj = $this->db->fetch_object($resql)) { |
|
| 5755 | 5755 | |
| 5756 | 5756 | // Several field into label (eq table:code|libelle:rowid) |
| 5757 | 5757 | $fields_label = explode('|', $InfoFieldList[1]); |
| 5758 | 5758 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 5759 | 5759 | if (is_array($fields_label) && count($fields_label) > 1) { |
| 5760 | - foreach ( $fields_label as $field_toshow ) { |
|
| 5760 | + foreach ($fields_label as $field_toshow) { |
|
| 5761 | 5761 | $translabel = ''; |
| 5762 | - if (! empty($obj->$field_toshow)) { |
|
| 5762 | + if (!empty($obj->$field_toshow)) { |
|
| 5763 | 5763 | $translabel = $langs->trans($obj->$field_toshow); |
| 5764 | 5764 | } |
| 5765 | 5765 | if ($translabel != $field_toshow) { |
| 5766 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 5766 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 5767 | 5767 | } else { |
| 5768 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 5768 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 5769 | 5769 | } |
| 5770 | 5770 | } |
| 5771 | 5771 | } else { |
| 5772 | 5772 | $translabel = ''; |
| 5773 | - if (! empty($obj->{$InfoFieldList[1]})) { |
|
| 5773 | + if (!empty($obj->{$InfoFieldList[1]})) { |
|
| 5774 | 5774 | $translabel = $langs->trans($obj->{$InfoFieldList[1]}); |
| 5775 | 5775 | } |
| 5776 | 5776 | if ($translabel != $obj->{$InfoFieldList[1]}) { |
| 5777 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 5777 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 5778 | 5778 | } else { |
| 5779 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
| 5779 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>'; |
|
| 5780 | 5780 | } |
| 5781 | 5781 | } |
| 5782 | 5782 | } |
| 5783 | 5783 | } |
| 5784 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 5784 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
|
| 5785 | 5785 | |
| 5786 | 5786 | } else { |
| 5787 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 5787 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 5788 | 5788 | } |
| 5789 | 5789 | } |
| 5790 | 5790 | elseif ($type == 'link') |
| 5791 | 5791 | { |
| 5792 | - $out=''; |
|
| 5792 | + $out = ''; |
|
| 5793 | 5793 | |
| 5794 | 5794 | // only if something to display (perf) |
| 5795 | 5795 | if ($value) |
| 5796 | 5796 | { |
| 5797 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5797 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5798 | 5798 | |
| 5799 | 5799 | $InfoFieldList = explode(":", $param_list[0]); |
| 5800 | - $classname=$InfoFieldList[0]; |
|
| 5801 | - $classpath=$InfoFieldList[1]; |
|
| 5802 | - if (! empty($classpath)) |
|
| 5800 | + $classname = $InfoFieldList[0]; |
|
| 5801 | + $classpath = $InfoFieldList[1]; |
|
| 5802 | + if (!empty($classpath)) |
|
| 5803 | 5803 | { |
| 5804 | 5804 | dol_include_once($InfoFieldList[1]); |
| 5805 | 5805 | if ($classname && class_exists($classname)) |
| 5806 | 5806 | { |
| 5807 | 5807 | $object = new $classname($this->db); |
| 5808 | 5808 | $object->fetch($value); |
| 5809 | - $value=$object->getNomUrl(3); |
|
| 5809 | + $value = $object->getNomUrl(3); |
|
| 5810 | 5810 | } |
| 5811 | 5811 | } |
| 5812 | 5812 | else |
@@ -5818,15 +5818,15 @@ discard block |
||
| 5818 | 5818 | } |
| 5819 | 5819 | elseif ($type == 'text' || $type == 'html') |
| 5820 | 5820 | { |
| 5821 | - $value=dol_htmlentitiesbr($value); |
|
| 5821 | + $value = dol_htmlentitiesbr($value); |
|
| 5822 | 5822 | } |
| 5823 | 5823 | elseif ($type == 'password') |
| 5824 | 5824 | { |
| 5825 | - $value=preg_replace('/./i','*',$value); |
|
| 5825 | + $value = preg_replace('/./i', '*', $value); |
|
| 5826 | 5826 | } |
| 5827 | 5827 | |
| 5828 | 5828 | //print $type.'-'.$size; |
| 5829 | - $out=$value; |
|
| 5829 | + $out = $value; |
|
| 5830 | 5830 | |
| 5831 | 5831 | return $out; |
| 5832 | 5832 | } |
@@ -5843,7 +5843,7 @@ discard block |
||
| 5843 | 5843 | * |
| 5844 | 5844 | * @return string |
| 5845 | 5845 | */ |
| 5846 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='') |
|
| 5846 | + function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '') |
|
| 5847 | 5847 | { |
| 5848 | 5848 | global $_POST, $conf, $langs, $action; |
| 5849 | 5849 | |
@@ -5856,28 +5856,28 @@ discard block |
||
| 5856 | 5856 | $out .= "\n"; |
| 5857 | 5857 | |
| 5858 | 5858 | $e = 0; |
| 5859 | - foreach($extrafields->attribute_label as $key=>$label) |
|
| 5859 | + foreach ($extrafields->attribute_label as $key=>$label) |
|
| 5860 | 5860 | { |
| 5861 | - if (empty($extrafields->attribute_list[$key])) continue; // 0 = Never visible field |
|
| 5862 | - if (($mode == 'create' || $mode == 'edit') && abs($extrafields->attribute_list[$key]) != 1 && abs($extrafields->attribute_list[$key]) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 5861 | + if (empty($extrafields->attribute_list[$key])) continue; // 0 = Never visible field |
|
| 5862 | + if (($mode == 'create' || $mode == 'edit') && abs($extrafields->attribute_list[$key]) != 1 && abs($extrafields->attribute_list[$key]) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 5863 | 5863 | |
| 5864 | 5864 | // Load language if required |
| 5865 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 5865 | + if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 5866 | 5866 | |
| 5867 | - if (is_array($params) && count($params)>0) { |
|
| 5868 | - if (array_key_exists('colspan',$params)) { |
|
| 5869 | - $colspan=$params['colspan']; |
|
| 5867 | + if (is_array($params) && count($params) > 0) { |
|
| 5868 | + if (array_key_exists('colspan', $params)) { |
|
| 5869 | + $colspan = $params['colspan']; |
|
| 5870 | 5870 | } |
| 5871 | - }else { |
|
| 5872 | - $colspan='3'; |
|
| 5871 | + } else { |
|
| 5872 | + $colspan = '3'; |
|
| 5873 | 5873 | } |
| 5874 | 5874 | |
| 5875 | - switch($mode) { |
|
| 5875 | + switch ($mode) { |
|
| 5876 | 5876 | case "view": |
| 5877 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 5877 | + $value = $this->array_options["options_".$key.$keysuffix]; |
|
| 5878 | 5878 | break; |
| 5879 | 5879 | case "edit": |
| 5880 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 5880 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 5881 | 5881 | // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc') |
| 5882 | 5882 | if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
| 5883 | 5883 | { |
@@ -5888,7 +5888,7 @@ discard block |
||
| 5888 | 5888 | $value = $getposttemp; |
| 5889 | 5889 | } |
| 5890 | 5890 | } else { |
| 5891 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 5891 | + $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object. |
|
| 5892 | 5892 | } |
| 5893 | 5893 | break; |
| 5894 | 5894 | } |
@@ -5900,45 +5900,45 @@ discard block |
||
| 5900 | 5900 | } |
| 5901 | 5901 | else |
| 5902 | 5902 | { |
| 5903 | - $csstyle=''; |
|
| 5904 | - $class=(!empty($extrafields->attribute_hidden[$key]) ? 'class="hideobject" ' : ''); |
|
| 5905 | - if (is_array($params) && count($params)>0) { |
|
| 5906 | - if (array_key_exists('style',$params)) { |
|
| 5907 | - $csstyle=$params['style']; |
|
| 5903 | + $csstyle = ''; |
|
| 5904 | + $class = (!empty($extrafields->attribute_hidden[$key]) ? 'class="hideobject" ' : ''); |
|
| 5905 | + if (is_array($params) && count($params) > 0) { |
|
| 5906 | + if (array_key_exists('style', $params)) { |
|
| 5907 | + $csstyle = $params['style']; |
|
| 5908 | 5908 | } |
| 5909 | 5909 | } |
| 5910 | - if ( !empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 5910 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 5911 | 5911 | { |
| 5912 | 5912 | $out .= '<tr '.$class.$csstyle.' class="'.$this->element.'_extras_'.$key.'">'; |
| 5913 | - $colspan='0'; |
|
| 5913 | + $colspan = '0'; |
|
| 5914 | 5914 | } |
| 5915 | 5915 | else |
| 5916 | 5916 | { |
| 5917 | 5917 | $out .= '<tr '.$class.$csstyle.' class="'.$this->element.'_extras_'.$key.'">'; |
| 5918 | 5918 | } |
| 5919 | 5919 | // Convert date into timestamp format (value in memory must be a timestamp) |
| 5920 | - if (in_array($extrafields->attribute_type[$key],array('date','datetime'))) |
|
| 5920 | + if (in_array($extrafields->attribute_type[$key], array('date', 'datetime'))) |
|
| 5921 | 5921 | { |
| 5922 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min",'int',3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day",'int',3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year",'int',3)):$this->db->jdate($this->array_options['options_'.$key]); |
|
| 5922 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $this->db->jdate($this->array_options['options_'.$key]); |
|
| 5923 | 5923 | } |
| 5924 | 5924 | // Convert float submited string into real php numeric (value in memory must be a php numeric) |
| 5925 | - if (in_array($extrafields->attribute_type[$key],array('price','double'))) |
|
| 5925 | + if (in_array($extrafields->attribute_type[$key], array('price', 'double'))) |
|
| 5926 | 5926 | { |
| 5927 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix,'int',3)):$this->array_options['options_'.$key]; |
|
| 5927 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'int', 3)) : $this->array_options['options_'.$key]; |
|
| 5928 | 5928 | } |
| 5929 | 5929 | |
| 5930 | 5930 | $labeltoshow = $langs->trans($label); |
| 5931 | 5931 | |
| 5932 | - if($extrafields->attribute_required[$key]) |
|
| 5932 | + if ($extrafields->attribute_required[$key]) |
|
| 5933 | 5933 | { |
| 5934 | - $labeltoshow = '<span'.($mode != 'view' ? ' class="fieldrequired"':'').'>'.$labeltoshow.'</span>'; |
|
| 5934 | + $labeltoshow = '<span'.($mode != 'view' ? ' class="fieldrequired"' : '').'>'.$labeltoshow.'</span>'; |
|
| 5935 | 5935 | } |
| 5936 | 5936 | $out .= '<td>'.$labeltoshow.'</td>'; |
| 5937 | 5937 | |
| 5938 | 5938 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
| 5939 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 5939 | + $out .= '<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan ? ' colspan="'.$colspan.'"' : '').'>'; |
|
| 5940 | 5940 | |
| 5941 | - switch($mode) { |
|
| 5941 | + switch ($mode) { |
|
| 5942 | 5942 | case "view": |
| 5943 | 5943 | $out .= $extrafields->showOutputField($key, $value); |
| 5944 | 5944 | break; |
@@ -5949,14 +5949,14 @@ discard block |
||
| 5949 | 5949 | |
| 5950 | 5950 | $out .= '</td>'; |
| 5951 | 5951 | |
| 5952 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 5952 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 5953 | 5953 | else $out .= '</tr>'; |
| 5954 | 5954 | $e++; |
| 5955 | 5955 | } |
| 5956 | 5956 | } |
| 5957 | 5957 | $out .= "\n"; |
| 5958 | 5958 | // Add code to manage list depending on others |
| 5959 | - if (! empty($conf->use_javascript_ajax)) { |
|
| 5959 | + if (!empty($conf->use_javascript_ajax)) { |
|
| 5960 | 5960 | $out .= ' |
| 5961 | 5961 | <script type="text/javascript"> |
| 5962 | 5962 | jQuery(document).ready(function() { |
@@ -6002,7 +6002,7 @@ discard block |
||
| 6002 | 6002 | global $user; |
| 6003 | 6003 | |
| 6004 | 6004 | $element = $this->element; |
| 6005 | - if ($element == 'facturerec') $element='facture'; |
|
| 6005 | + if ($element == 'facturerec') $element = 'facture'; |
|
| 6006 | 6006 | |
| 6007 | 6007 | return $user->rights->{$element}; |
| 6008 | 6008 | } |
@@ -6019,15 +6019,15 @@ discard block |
||
| 6019 | 6019 | * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) |
| 6020 | 6020 | * @return bool True if success, False if error |
| 6021 | 6021 | */ |
| 6022 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6022 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) |
|
| 6023 | 6023 | { |
| 6024 | 6024 | foreach ($tables as $table) |
| 6025 | 6025 | { |
| 6026 | 6026 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
| 6027 | 6027 | |
| 6028 | - if (! $db->query($sql)) |
|
| 6028 | + if (!$db->query($sql)) |
|
| 6029 | 6029 | { |
| 6030 | - if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. |
|
| 6030 | + if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. |
|
| 6031 | 6031 | //$this->errors = $db->lasterror(); |
| 6032 | 6032 | return false; |
| 6033 | 6033 | } |
@@ -6061,7 +6061,7 @@ discard block |
||
| 6061 | 6061 | else |
| 6062 | 6062 | { |
| 6063 | 6063 | // Get cost price for margin calculation |
| 6064 | - if (! empty($fk_product)) |
|
| 6064 | + if (!empty($fk_product)) |
|
| 6065 | 6065 | { |
| 6066 | 6066 | if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
| 6067 | 6067 | { |
@@ -6098,7 +6098,7 @@ discard block |
||
| 6098 | 6098 | } |
| 6099 | 6099 | } |
| 6100 | 6100 | |
| 6101 | - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) |
|
| 6101 | + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice'))) |
|
| 6102 | 6102 | { |
| 6103 | 6103 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
| 6104 | 6104 | $productFournisseur = new ProductFournisseur($this->db); |
@@ -6127,9 +6127,9 @@ discard block |
||
| 6127 | 6127 | */ |
| 6128 | 6128 | protected function isArray($info) |
| 6129 | 6129 | { |
| 6130 | - if(is_array($info)) |
|
| 6130 | + if (is_array($info)) |
|
| 6131 | 6131 | { |
| 6132 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6132 | + if (isset($info['type']) && $info['type'] == 'array') return true; |
|
| 6133 | 6133 | else return false; |
| 6134 | 6134 | } |
| 6135 | 6135 | else return false; |
@@ -6143,9 +6143,9 @@ discard block |
||
| 6143 | 6143 | */ |
| 6144 | 6144 | protected function isNull($info) |
| 6145 | 6145 | { |
| 6146 | - if(is_array($info)) |
|
| 6146 | + if (is_array($info)) |
|
| 6147 | 6147 | { |
| 6148 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6148 | + if (isset($info['type']) && $info['type'] == 'null') return true; |
|
| 6149 | 6149 | else return false; |
| 6150 | 6150 | } |
| 6151 | 6151 | else return false; |
@@ -6160,7 +6160,7 @@ discard block |
||
| 6160 | 6160 | */ |
| 6161 | 6161 | public function isDate($info) |
| 6162 | 6162 | { |
| 6163 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6163 | + if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) return true; |
|
| 6164 | 6164 | else return false; |
| 6165 | 6165 | } |
| 6166 | 6166 | |
@@ -6172,9 +6172,9 @@ discard block |
||
| 6172 | 6172 | */ |
| 6173 | 6173 | public function isInt($info) |
| 6174 | 6174 | { |
| 6175 | - if(is_array($info)) |
|
| 6175 | + if (is_array($info)) |
|
| 6176 | 6176 | { |
| 6177 | - if(isset($info['type']) && ($info['type']=='int' || $info['type']=='integer' )) return true; |
|
| 6177 | + if (isset($info['type']) && ($info['type'] == 'int' || $info['type'] == 'integer')) return true; |
|
| 6178 | 6178 | else return false; |
| 6179 | 6179 | } |
| 6180 | 6180 | else return false; |
@@ -6188,7 +6188,7 @@ discard block |
||
| 6188 | 6188 | */ |
| 6189 | 6189 | public function isFloat($info) |
| 6190 | 6190 | { |
| 6191 | - if(is_array($info)) |
|
| 6191 | + if (is_array($info)) |
|
| 6192 | 6192 | { |
| 6193 | 6193 | if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true; |
| 6194 | 6194 | else return false; |
@@ -6204,9 +6204,9 @@ discard block |
||
| 6204 | 6204 | */ |
| 6205 | 6205 | public function isText($info) |
| 6206 | 6206 | { |
| 6207 | - if(is_array($info)) |
|
| 6207 | + if (is_array($info)) |
|
| 6208 | 6208 | { |
| 6209 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6209 | + if (isset($info['type']) && $info['type'] == 'text') return true; |
|
| 6210 | 6210 | else return false; |
| 6211 | 6211 | } |
| 6212 | 6212 | else return false; |
@@ -6220,9 +6220,9 @@ discard block |
||
| 6220 | 6220 | */ |
| 6221 | 6221 | protected function isIndex($info) |
| 6222 | 6222 | { |
| 6223 | - if(is_array($info)) |
|
| 6223 | + if (is_array($info)) |
|
| 6224 | 6224 | { |
| 6225 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6225 | + if (isset($info['index']) && $info['index'] == true) return true; |
|
| 6226 | 6226 | else return false; |
| 6227 | 6227 | } |
| 6228 | 6228 | else return false; |
@@ -6238,13 +6238,13 @@ discard block |
||
| 6238 | 6238 | { |
| 6239 | 6239 | global $conf; |
| 6240 | 6240 | |
| 6241 | - $queryarray=array(); |
|
| 6241 | + $queryarray = array(); |
|
| 6242 | 6242 | foreach ($this->fields as $field=>$info) // Loop on definition of fields |
| 6243 | 6243 | { |
| 6244 | 6244 | // Depending on field type ('datetime', ...) |
| 6245 | - if($this->isDate($info)) |
|
| 6245 | + if ($this->isDate($info)) |
|
| 6246 | 6246 | { |
| 6247 | - if(empty($this->{$field})) |
|
| 6247 | + if (empty($this->{$field})) |
|
| 6248 | 6248 | { |
| 6249 | 6249 | $queryarray[$field] = NULL; |
| 6250 | 6250 | } |
@@ -6253,23 +6253,23 @@ discard block |
||
| 6253 | 6253 | $queryarray[$field] = $this->db->idate($this->{$field}); |
| 6254 | 6254 | } |
| 6255 | 6255 | } |
| 6256 | - else if($this->isArray($info)) |
|
| 6256 | + else if ($this->isArray($info)) |
|
| 6257 | 6257 | { |
| 6258 | 6258 | $queryarray[$field] = serialize($this->{$field}); |
| 6259 | 6259 | } |
| 6260 | - else if($this->isInt($info)) |
|
| 6260 | + else if ($this->isInt($info)) |
|
| 6261 | 6261 | { |
| 6262 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity; |
|
| 6262 | + if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity; |
|
| 6263 | 6263 | else |
| 6264 | 6264 | { |
| 6265 | 6265 | $queryarray[$field] = (int) price2num($this->{$field}); |
| 6266 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6266 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6267 | 6267 | } |
| 6268 | 6268 | } |
| 6269 | - else if($this->isFloat($info)) |
|
| 6269 | + else if ($this->isFloat($info)) |
|
| 6270 | 6270 | { |
| 6271 | 6271 | $queryarray[$field] = (double) price2num($this->{$field}); |
| 6272 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6272 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; |
|
| 6273 | 6273 | } |
| 6274 | 6274 | else |
| 6275 | 6275 | { |
@@ -6277,7 +6277,7 @@ discard block |
||
| 6277 | 6277 | } |
| 6278 | 6278 | |
| 6279 | 6279 | if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
| 6280 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6280 | + if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6281 | 6281 | } |
| 6282 | 6282 | |
| 6283 | 6283 | return $queryarray; |
@@ -6292,31 +6292,31 @@ discard block |
||
| 6292 | 6292 | { |
| 6293 | 6293 | foreach ($this->fields as $field => $info) |
| 6294 | 6294 | { |
| 6295 | - if($this->isDate($info)) |
|
| 6295 | + if ($this->isDate($info)) |
|
| 6296 | 6296 | { |
| 6297 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
| 6297 | + if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; |
|
| 6298 | 6298 | else $this->{$field} = strtotime($obj->{$field}); |
| 6299 | 6299 | } |
| 6300 | - elseif($this->isArray($info)) |
|
| 6300 | + elseif ($this->isArray($info)) |
|
| 6301 | 6301 | { |
| 6302 | 6302 | $this->{$field} = @unserialize($obj->{$field}); |
| 6303 | 6303 | // Hack for data not in UTF8 |
| 6304 | - if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); |
|
| 6304 | + if ($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); |
|
| 6305 | 6305 | } |
| 6306 | - elseif($this->isInt($info)) |
|
| 6306 | + elseif ($this->isInt($info)) |
|
| 6307 | 6307 | { |
| 6308 | 6308 | if ($field == 'rowid') $this->id = (int) $obj->{$field}; |
| 6309 | 6309 | else $this->{$field} = (int) $obj->{$field}; |
| 6310 | 6310 | } |
| 6311 | - elseif($this->isFloat($info)) |
|
| 6311 | + elseif ($this->isFloat($info)) |
|
| 6312 | 6312 | { |
| 6313 | 6313 | $this->{$field} = (double) $obj->{$field}; |
| 6314 | 6314 | } |
| 6315 | - elseif($this->isNull($info)) |
|
| 6315 | + elseif ($this->isNull($info)) |
|
| 6316 | 6316 | { |
| 6317 | 6317 | $val = $obj->{$field}; |
| 6318 | 6318 | // zero is not null |
| 6319 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); |
|
| 6319 | + $this->{$field} = (is_null($val) || (empty($val) && $val !== 0 && $val !== '0') ? null : $val); |
|
| 6320 | 6320 | } |
| 6321 | 6321 | else |
| 6322 | 6322 | { |
@@ -6325,7 +6325,7 @@ discard block |
||
| 6325 | 6325 | } |
| 6326 | 6326 | |
| 6327 | 6327 | // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
| 6328 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 6328 | + if (!isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 6329 | 6329 | } |
| 6330 | 6330 | |
| 6331 | 6331 | /** |
@@ -6366,14 +6366,14 @@ discard block |
||
| 6366 | 6366 | |
| 6367 | 6367 | $error = 0; |
| 6368 | 6368 | |
| 6369 | - $now=dol_now(); |
|
| 6369 | + $now = dol_now(); |
|
| 6370 | 6370 | |
| 6371 | 6371 | $fieldvalues = $this->set_save_query(); |
| 6372 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now); |
|
| 6373 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id; |
|
| 6374 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 6372 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation'] = $this->db->idate($now); |
|
| 6373 | + if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat'] = $user->id; |
|
| 6374 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 6375 | 6375 | |
| 6376 | - $keys=array(); |
|
| 6376 | + $keys = array(); |
|
| 6377 | 6377 | $values = array(); |
| 6378 | 6378 | foreach ($fieldvalues as $k => $v) { |
| 6379 | 6379 | $keys[$k] = $k; |
@@ -6382,58 +6382,58 @@ discard block |
||
| 6382 | 6382 | } |
| 6383 | 6383 | |
| 6384 | 6384 | // Clean and check mandatory |
| 6385 | - foreach($keys as $key) |
|
| 6385 | + foreach ($keys as $key) |
|
| 6386 | 6386 | { |
| 6387 | 6387 | // If field is an implicit foreign key field |
| 6388 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; |
|
| 6389 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 6388 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; |
|
| 6389 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; |
|
| 6390 | 6390 | |
| 6391 | 6391 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 6392 | - if ($this->fields[$key]['notnull'] == 1 && ! isset($values[$key])) |
|
| 6392 | + if ($this->fields[$key]['notnull'] == 1 && !isset($values[$key])) |
|
| 6393 | 6393 | { |
| 6394 | 6394 | $error++; |
| 6395 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
| 6395 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']); |
|
| 6396 | 6396 | } |
| 6397 | 6397 | |
| 6398 | 6398 | // If field is an implicit foreign key field |
| 6399 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null'; |
|
| 6400 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 6399 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key] = 'null'; |
|
| 6400 | + if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key] = 'null'; |
|
| 6401 | 6401 | } |
| 6402 | 6402 | |
| 6403 | 6403 | if ($error) return -1; |
| 6404 | 6404 | |
| 6405 | 6405 | $this->db->begin(); |
| 6406 | 6406 | |
| 6407 | - if (! $error) |
|
| 6407 | + if (!$error) |
|
| 6408 | 6408 | { |
| 6409 | 6409 | $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
| 6410 | - $sql.= ' ('.implode( ", ", $keys ).')'; |
|
| 6411 | - $sql.= ' VALUES ('.implode( ", ", $values ).')'; |
|
| 6410 | + $sql .= ' ('.implode(", ", $keys).')'; |
|
| 6411 | + $sql .= ' VALUES ('.implode(", ", $values).')'; |
|
| 6412 | 6412 | |
| 6413 | 6413 | $res = $this->db->query($sql); |
| 6414 | - if ($res===false) { |
|
| 6414 | + if ($res === false) { |
|
| 6415 | 6415 | $error++; |
| 6416 | 6416 | $this->errors[] = $this->db->lasterror(); |
| 6417 | 6417 | } |
| 6418 | 6418 | } |
| 6419 | 6419 | |
| 6420 | - if (! $error) |
|
| 6420 | + if (!$error) |
|
| 6421 | 6421 | { |
| 6422 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 6422 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
| 6423 | 6423 | } |
| 6424 | 6424 | |
| 6425 | 6425 | // Create extrafields |
| 6426 | - if (! $error) |
|
| 6426 | + if (!$error) |
|
| 6427 | 6427 | { |
| 6428 | - $result=$this->insertExtraFields(); |
|
| 6428 | + $result = $this->insertExtraFields(); |
|
| 6429 | 6429 | if ($result < 0) $error++; |
| 6430 | 6430 | } |
| 6431 | 6431 | |
| 6432 | 6432 | // Triggers |
| 6433 | - if (! $error && ! $notrigger) |
|
| 6433 | + if (!$error && !$notrigger) |
|
| 6434 | 6434 | { |
| 6435 | 6435 | // Call triggers |
| 6436 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 6436 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_CREATE', $user); |
|
| 6437 | 6437 | if ($result < 0) { $error++; } |
| 6438 | 6438 | // End call triggers |
| 6439 | 6439 | } |
@@ -6461,10 +6461,10 @@ discard block |
||
| 6461 | 6461 | if (empty($id) && empty($ref)) return false; |
| 6462 | 6462 | |
| 6463 | 6463 | $sql = 'SELECT '.$this->get_field_list(); |
| 6464 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 6464 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 6465 | 6465 | |
| 6466 | - if(!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 6467 | - else $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 6466 | + if (!empty($id)) $sql .= ' WHERE rowid = '.$id; |
|
| 6467 | + else $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 6468 | 6468 | |
| 6469 | 6469 | $res = $this->db->query($sql); |
| 6470 | 6470 | if ($res) |
@@ -6501,14 +6501,14 @@ discard block |
||
| 6501 | 6501 | |
| 6502 | 6502 | $error = 0; |
| 6503 | 6503 | |
| 6504 | - $now=dol_now(); |
|
| 6504 | + $now = dol_now(); |
|
| 6505 | 6505 | |
| 6506 | 6506 | $fieldvalues = $this->set_save_query(); |
| 6507 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now); |
|
| 6508 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id; |
|
| 6509 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 6507 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification'] = $this->db->idate($now); |
|
| 6508 | + if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif'] = $user->id; |
|
| 6509 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 6510 | 6510 | |
| 6511 | - $keys=array(); |
|
| 6511 | + $keys = array(); |
|
| 6512 | 6512 | $values = array(); |
| 6513 | 6513 | foreach ($fieldvalues as $k => $v) { |
| 6514 | 6514 | $keys[$k] = $k; |
@@ -6518,10 +6518,10 @@ discard block |
||
| 6518 | 6518 | } |
| 6519 | 6519 | |
| 6520 | 6520 | // Clean and check mandatory |
| 6521 | - foreach($keys as $key) |
|
| 6521 | + foreach ($keys as $key) |
|
| 6522 | 6522 | { |
| 6523 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field |
|
| 6524 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 6523 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field |
|
| 6524 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; // This is an explicit foreign key field |
|
| 6525 | 6525 | |
| 6526 | 6526 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 6527 | 6527 | /* |
@@ -6532,13 +6532,13 @@ discard block |
||
| 6532 | 6532 | }*/ |
| 6533 | 6533 | } |
| 6534 | 6534 | |
| 6535 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 6535 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(',', $tmp).' WHERE rowid='.$this->id; |
|
| 6536 | 6536 | |
| 6537 | 6537 | $this->db->begin(); |
| 6538 | - if (! $error) |
|
| 6538 | + if (!$error) |
|
| 6539 | 6539 | { |
| 6540 | 6540 | $res = $this->db->query($sql); |
| 6541 | - if ($res===false) |
|
| 6541 | + if ($res === false) |
|
| 6542 | 6542 | { |
| 6543 | 6543 | $error++; |
| 6544 | 6544 | $this->errors[] = $this->db->lasterror(); |
@@ -6546,11 +6546,11 @@ discard block |
||
| 6546 | 6546 | } |
| 6547 | 6547 | |
| 6548 | 6548 | // Update extrafield |
| 6549 | - if (! $error) |
|
| 6549 | + if (!$error) |
|
| 6550 | 6550 | { |
| 6551 | 6551 | if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used |
| 6552 | 6552 | { |
| 6553 | - $result=$this->insertExtraFields(); |
|
| 6553 | + $result = $this->insertExtraFields(); |
|
| 6554 | 6554 | if ($result < 0) |
| 6555 | 6555 | { |
| 6556 | 6556 | $error++; |
@@ -6559,10 +6559,10 @@ discard block |
||
| 6559 | 6559 | } |
| 6560 | 6560 | |
| 6561 | 6561 | // Triggers |
| 6562 | - if (! $error && ! $notrigger) |
|
| 6562 | + if (!$error && !$notrigger) |
|
| 6563 | 6563 | { |
| 6564 | 6564 | // Call triggers |
| 6565 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 6565 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); |
|
| 6566 | 6566 | if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail |
| 6567 | 6567 | // End call triggers |
| 6568 | 6568 | } |
@@ -6586,38 +6586,38 @@ discard block |
||
| 6586 | 6586 | */ |
| 6587 | 6587 | public function deleteCommon(User $user, $notrigger = false) |
| 6588 | 6588 | { |
| 6589 | - $error=0; |
|
| 6589 | + $error = 0; |
|
| 6590 | 6590 | |
| 6591 | 6591 | $this->db->begin(); |
| 6592 | 6592 | |
| 6593 | - if (! $error) { |
|
| 6594 | - if (! $notrigger) { |
|
| 6593 | + if (!$error) { |
|
| 6594 | + if (!$notrigger) { |
|
| 6595 | 6595 | // Call triggers |
| 6596 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 6596 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 6597 | 6597 | if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail |
| 6598 | 6598 | // End call triggers |
| 6599 | 6599 | } |
| 6600 | 6600 | } |
| 6601 | 6601 | |
| 6602 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 6602 | + if (!$error && !empty($this->isextrafieldmanaged)) |
|
| 6603 | 6603 | { |
| 6604 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 6605 | - $sql.= " WHERE fk_object=" . $this->id; |
|
| 6604 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; |
|
| 6605 | + $sql .= " WHERE fk_object=".$this->id; |
|
| 6606 | 6606 | |
| 6607 | 6607 | $resql = $this->db->query($sql); |
| 6608 | - if (! $resql) |
|
| 6608 | + if (!$resql) |
|
| 6609 | 6609 | { |
| 6610 | 6610 | $this->errors[] = $this->db->lasterror(); |
| 6611 | 6611 | $error++; |
| 6612 | 6612 | } |
| 6613 | 6613 | } |
| 6614 | 6614 | |
| 6615 | - if (! $error) |
|
| 6615 | + if (!$error) |
|
| 6616 | 6616 | { |
| 6617 | 6617 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
| 6618 | 6618 | |
| 6619 | 6619 | $res = $this->db->query($sql); |
| 6620 | - if($res===false) { |
|
| 6620 | + if ($res === false) { |
|
| 6621 | 6621 | $error++; |
| 6622 | 6622 | $this->errors[] = $this->db->lasterror(); |
| 6623 | 6623 | } |
@@ -29,17 +29,17 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | class Translate |
| 31 | 31 | { |
| 32 | - public $dir; // Directories that contains /langs subdirectory |
|
| 32 | + public $dir; // Directories that contains /langs subdirectory |
|
| 33 | 33 | |
| 34 | - public $defaultlang; // Current language for current user |
|
| 35 | - public $charset_output='UTF-8'; // Codage used by "trans" method outputs |
|
| 34 | + public $defaultlang; // Current language for current user |
|
| 35 | + public $charset_output = 'UTF-8'; // Codage used by "trans" method outputs |
|
| 36 | 36 | |
| 37 | - public $tab_translate=array(); // Array of all translations key=>value |
|
| 38 | - private $_tab_loaded=array(); // Array to store result after loading each language file |
|
| 37 | + public $tab_translate = array(); // Array of all translations key=>value |
|
| 38 | + private $_tab_loaded = array(); // Array to store result after loading each language file |
|
| 39 | 39 | |
| 40 | - public $cache_labels=array(); // Cache for labels return by getLabelFromKey method |
|
| 41 | - public $cache_currencies=array(); // Cache to store currency symbols |
|
| 42 | - private $cache_currencies_all_loaded=false; |
|
| 40 | + public $cache_labels = array(); // Cache for labels return by getLabelFromKey method |
|
| 41 | + public $cache_currencies = array(); // Cache to store currency symbols |
|
| 42 | + private $cache_currencies_all_loaded = false; |
|
| 43 | 43 | |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -50,9 +50,9 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function __construct($dir, $conf) |
| 52 | 52 | { |
| 53 | - if (! empty($conf->file->character_set_client)) $this->charset_output=$conf->file->character_set_client; // If charset output is forced |
|
| 54 | - if ($dir) $this->dir=array($dir); |
|
| 55 | - else $this->dir=$conf->file->dol_document_root; |
|
| 53 | + if (!empty($conf->file->character_set_client)) $this->charset_output = $conf->file->character_set_client; // If charset output is forced |
|
| 54 | + if ($dir) $this->dir = array($dir); |
|
| 55 | + else $this->dir = $conf->file->dol_document_root; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,65 +62,65 @@ discard block |
||
| 62 | 62 | * @param string $srclang Language to use. If '' or 'auto', we use browser lang. |
| 63 | 63 | * @return void |
| 64 | 64 | */ |
| 65 | - function setDefaultLang($srclang='en_US') |
|
| 65 | + function setDefaultLang($srclang = 'en_US') |
|
| 66 | 66 | { |
| 67 | 67 | global $conf; |
| 68 | 68 | |
| 69 | 69 | //dol_syslog(get_class($this)."::setDefaultLang srclang=".$srclang,LOG_DEBUG); |
| 70 | 70 | |
| 71 | 71 | // If a module ask to force a priority on langs directories (to use its own lang files) |
| 72 | - if (! empty($conf->global->MAIN_FORCELANGDIR)) |
|
| 72 | + if (!empty($conf->global->MAIN_FORCELANGDIR)) |
|
| 73 | 73 | { |
| 74 | - $more=array(); |
|
| 75 | - $i=0; |
|
| 76 | - foreach($conf->file->dol_document_root as $dir) |
|
| 74 | + $more = array(); |
|
| 75 | + $i = 0; |
|
| 76 | + foreach ($conf->file->dol_document_root as $dir) |
|
| 77 | 77 | { |
| 78 | - $newdir=$dir.$conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX' |
|
| 79 | - if (! in_array($newdir,$this->dir)) |
|
| 78 | + $newdir = $dir.$conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX' |
|
| 79 | + if (!in_array($newdir, $this->dir)) |
|
| 80 | 80 | { |
| 81 | - $more['module_'.$i]=$newdir; $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir. |
|
| 81 | + $more['module_'.$i] = $newdir; $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir. |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | - $this->dir=array_merge($more,$this->dir); // Forced dir ($more) are before standard dirs ($this->dir) |
|
| 84 | + $this->dir = array_merge($more, $this->dir); // Forced dir ($more) are before standard dirs ($this->dir) |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - $this->origlang=$srclang; |
|
| 87 | + $this->origlang = $srclang; |
|
| 88 | 88 | |
| 89 | 89 | if (empty($srclang) || $srclang == 'auto') |
| 90 | 90 | { |
| 91 | - $langpref=empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])?'':$_SERVER['HTTP_ACCEPT_LANGUAGE']; |
|
| 92 | - $langpref=preg_replace("/;([^,]*)/i","",$langpref); |
|
| 93 | - $langpref=str_replace("-","_",$langpref); |
|
| 94 | - $langlist=preg_split("/[;,]/",$langpref); |
|
| 95 | - $codetouse=$langlist[0]; |
|
| 91 | + $langpref = empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? '' : $_SERVER['HTTP_ACCEPT_LANGUAGE']; |
|
| 92 | + $langpref = preg_replace("/;([^,]*)/i", "", $langpref); |
|
| 93 | + $langpref = str_replace("-", "_", $langpref); |
|
| 94 | + $langlist = preg_split("/[;,]/", $langpref); |
|
| 95 | + $codetouse = $langlist[0]; |
|
| 96 | 96 | } |
| 97 | - else $codetouse=$srclang; |
|
| 97 | + else $codetouse = $srclang; |
|
| 98 | 98 | |
| 99 | 99 | // We redefine $srclang |
| 100 | - $langpart=explode("_",$codetouse); |
|
| 100 | + $langpart = explode("_", $codetouse); |
|
| 101 | 101 | //print "Short code before _ : ".$langpart[0].' / Short code after _ : '.$langpart[1].'<br>'; |
| 102 | - if (! empty($langpart[1])) // If it's for a codetouse that is a long code xx_YY |
|
| 102 | + if (!empty($langpart[1])) // If it's for a codetouse that is a long code xx_YY |
|
| 103 | 103 | { |
| 104 | 104 | // Array force long code from first part, even if long code is defined |
| 105 | - $longforshort=array('ar'=>'ar_SA'); |
|
| 106 | - $longforshortexcep=array('ar_EG'); |
|
| 107 | - if (isset($longforshort[strtolower($langpart[0])]) && ! in_array($codetouse, $longforshortexcep)) $srclang=$longforshort[strtolower($langpart[0])]; |
|
| 108 | - else if (! is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser |
|
| 109 | - $srclang=strtolower($langpart[0])."_".strtoupper($langpart[1]); |
|
| 110 | - $longforlong=array('no_nb'=>'nb_NO'); |
|
| 111 | - if (isset($longforlong[strtolower($srclang)])) $srclang=$longforlong[strtolower($srclang)]; |
|
| 105 | + $longforshort = array('ar'=>'ar_SA'); |
|
| 106 | + $longforshortexcep = array('ar_EG'); |
|
| 107 | + if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 108 | + else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser |
|
| 109 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[1]); |
|
| 110 | + $longforlong = array('no_nb'=>'nb_NO'); |
|
| 111 | + if (isset($longforlong[strtolower($srclang)])) $srclang = $longforlong[strtolower($srclang)]; |
|
| 112 | 112 | } |
| 113 | - else $srclang=strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
| 113 | + else $srclang = strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
| 114 | 114 | } |
| 115 | 115 | else { // If it's for a codetouse that is a short code xx |
| 116 | 116 | // Array to convert short lang code into long code. |
| 117 | - $longforshort=array('ar'=>'ar_SA', 'el'=>'el_GR', 'ca'=>'ca_ES', 'en'=>'en_US', 'nb'=>'nb_NO', 'no'=>'nb_NO'); |
|
| 118 | - if (isset($longforshort[strtolower($langpart[0])])) $srclang=$longforshort[strtolower($langpart[0])]; |
|
| 119 | - else if (! empty($langpart[0])) $srclang=strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
| 120 | - else $srclang='en_US'; |
|
| 117 | + $longforshort = array('ar'=>'ar_SA', 'el'=>'el_GR', 'ca'=>'ca_ES', 'en'=>'en_US', 'nb'=>'nb_NO', 'no'=>'nb_NO'); |
|
| 118 | + if (isset($longforshort[strtolower($langpart[0])])) $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 119 | + else if (!empty($langpart[0])) $srclang = strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
| 120 | + else $srclang = 'en_US'; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - $this->defaultlang=$srclang; |
|
| 123 | + $this->defaultlang = $srclang; |
|
| 124 | 124 | //print 'this->defaultlang='.$this->defaultlang; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -132,10 +132,10 @@ discard block |
||
| 132 | 132 | * @param int $mode 0=Long language code, 1=Short language code (en, fr, es, ...) |
| 133 | 133 | * @return string Language code used (en_US, en_AU, fr_FR, ...) |
| 134 | 134 | */ |
| 135 | - function getDefaultLang($mode=0) |
|
| 135 | + function getDefaultLang($mode = 0) |
|
| 136 | 136 | { |
| 137 | 137 | if (empty($mode)) return $this->defaultlang; |
| 138 | - else return substr($this->defaultlang,0,2); |
|
| 138 | + else return substr($this->defaultlang, 0, 2); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function loadLangs($domains) |
| 149 | 149 | { |
| 150 | - foreach($domains as $domain) |
|
| 150 | + foreach ($domains as $domain) |
|
| 151 | 151 | { |
| 152 | 152 | $this->load($domain); |
| 153 | 153 | } |
@@ -173,49 +173,49 @@ discard block |
||
| 173 | 173 | * @return int <0 if KO, 0 if already loaded or loading not required, >0 if OK |
| 174 | 174 | * @see loadLangs |
| 175 | 175 | */ |
| 176 | - function load($domain,$alt=0,$stopafterdirection=0,$forcelangdir='',$loadfromfileonly=0) |
|
| 176 | + function load($domain, $alt = 0, $stopafterdirection = 0, $forcelangdir = '', $loadfromfileonly = 0) |
|
| 177 | 177 | { |
| 178 | - global $conf,$db; |
|
| 178 | + global $conf, $db; |
|
| 179 | 179 | |
| 180 | 180 | //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang); |
| 181 | 181 | |
| 182 | 182 | // Check parameters |
| 183 | 183 | if (empty($domain)) |
| 184 | 184 | { |
| 185 | - dol_print_error('',get_class($this)."::Load ErrorWrongParameters"); |
|
| 185 | + dol_print_error('', get_class($this)."::Load ErrorWrongParameters"); |
|
| 186 | 186 | return -1; |
| 187 | 187 | } |
| 188 | - if ($this->defaultlang == 'none_NONE') return 0; // Special language code to not translate keys |
|
| 188 | + if ($this->defaultlang == 'none_NONE') return 0; // Special language code to not translate keys |
|
| 189 | 189 | |
| 190 | 190 | |
| 191 | 191 | // Load $this->tab_translate[] from database |
| 192 | - if (empty($loadfromfileonly) && count($this->tab_translate) == 0) $this->loadFromDatabase($db); // Nothing was loaded yet, so we load database. |
|
| 192 | + if (empty($loadfromfileonly) && count($this->tab_translate) == 0) $this->loadFromDatabase($db); // Nothing was loaded yet, so we load database. |
|
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | $newdomain = $domain; |
| 196 | 196 | $modulename = ''; |
| 197 | 197 | |
| 198 | 198 | // Search if a module directory name is provided into lang file name |
| 199 | - if (preg_match('/^([^@]+)@([^@]+)$/i',$domain,$regs)) |
|
| 199 | + if (preg_match('/^([^@]+)@([^@]+)$/i', $domain, $regs)) |
|
| 200 | 200 | { |
| 201 | 201 | $newdomain = $regs[1]; |
| 202 | 202 | $modulename = $regs[2]; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Check cache |
| 206 | - if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain |
|
| 206 | + if (!empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain |
|
| 207 | 207 | { |
| 208 | 208 | //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); |
| 209 | 209 | return 0; |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - $fileread=0; |
|
| 213 | - $langofdir=(empty($forcelangdir)?$this->defaultlang:$forcelangdir); |
|
| 212 | + $fileread = 0; |
|
| 213 | + $langofdir = (empty($forcelangdir) ? $this->defaultlang : $forcelangdir); |
|
| 214 | 214 | |
| 215 | 215 | // Redefine alt |
| 216 | - $langarray=explode('_',$langofdir); |
|
| 217 | - if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr')))) $alt=1; |
|
| 218 | - if ($alt < 2 && strtolower($langofdir) == 'en_us') $alt=2; |
|
| 216 | + $langarray = explode('_', $langofdir); |
|
| 217 | + if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr')))) $alt = 1; |
|
| 218 | + if ($alt < 2 && strtolower($langofdir) == 'en_us') $alt = 2; |
|
| 219 | 219 | |
| 220 | 220 | if (empty($langofdir)) // This may occurs when load is called without setting the language and without providing a value for forcelangdir |
| 221 | 221 | { |
@@ -223,32 +223,32 @@ discard block |
||
| 223 | 223 | return -1; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - foreach($this->dir as $keydir => $searchdir) |
|
| 226 | + foreach ($this->dir as $keydir => $searchdir) |
|
| 227 | 227 | { |
| 228 | 228 | // Directory of translation files |
| 229 | - $file_lang = $searchdir.($modulename?'/'.$modulename:'')."/langs/".$langofdir."/".$newdomain.".lang"; |
|
| 230 | - $file_lang_osencoded=dol_osencode($file_lang); |
|
| 229 | + $file_lang = $searchdir.($modulename ? '/'.$modulename : '')."/langs/".$langofdir."/".$newdomain.".lang"; |
|
| 230 | + $file_lang_osencoded = dol_osencode($file_lang); |
|
| 231 | 231 | |
| 232 | - $filelangexists=is_file($file_lang_osencoded); |
|
| 232 | + $filelangexists = is_file($file_lang_osencoded); |
|
| 233 | 233 | |
| 234 | 234 | //dol_syslog(get_class($this).'::Load Try to read for alt='.$alt.' langofdir='.$langofdir.' newdomain='.$domain.' modulename='.$modulename.' file_lang='.$file_lang." => filelangexists=".$filelangexists); |
| 235 | 235 | |
| 236 | 236 | if ($filelangexists) |
| 237 | 237 | { |
| 238 | 238 | // TODO Move cache read out of loop on dirs or at least filelangexists |
| 239 | - $found=false; |
|
| 239 | + $found = false; |
|
| 240 | 240 | |
| 241 | 241 | // Enable caching of lang file in memory (not by default) |
| 242 | - $usecachekey=''; |
|
| 242 | + $usecachekey = ''; |
|
| 243 | 243 | // Using a memcached server |
| 244 | - if (! empty($conf->memcached->enabled) && ! empty($conf->global->MEMCACHED_SERVER)) |
|
| 244 | + if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) |
|
| 245 | 245 | { |
| 246 | - $usecachekey=$newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars |
|
| 246 | + $usecachekey = $newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars |
|
| 247 | 247 | } |
| 248 | 248 | // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) |
| 249 | 249 | else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) |
| 250 | 250 | { |
| 251 | - $usecachekey=$newdomain; |
|
| 251 | + $usecachekey = $newdomain; |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | if ($usecachekey) |
@@ -256,23 +256,23 @@ discard block |
||
| 256 | 256 | //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey); |
| 257 | 257 | //global $aaa; $aaa+=1; |
| 258 | 258 | //print $aaa." ".$usecachekey."\n"; |
| 259 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/memory.lib.php'; |
|
| 260 | - $tmparray=dol_getcache($usecachekey); |
|
| 259 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; |
|
| 260 | + $tmparray = dol_getcache($usecachekey); |
|
| 261 | 261 | if (is_array($tmparray) && count($tmparray)) |
| 262 | 262 | { |
| 263 | - $this->tab_translate+=$tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a value already exists into tab_translate, value into tmparaay is not added. |
|
| 263 | + $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a value already exists into tab_translate, value into tmparaay is not added. |
|
| 264 | 264 | //print $newdomain."\n"; |
| 265 | 265 | //var_dump($this->tab_translate); |
| 266 | - if ($alt == 2) $fileread=1; |
|
| 267 | - $found=true; // Found in dolibarr PHP cache |
|
| 266 | + if ($alt == 2) $fileread = 1; |
|
| 267 | + $found = true; // Found in dolibarr PHP cache |
|
| 268 | 268 | } |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if (! $found) |
|
| 271 | + if (!$found) |
|
| 272 | 272 | { |
| 273 | - if ($fp = @fopen($file_lang,"rt")) |
|
| 273 | + if ($fp = @fopen($file_lang, "rt")) |
|
| 274 | 274 | { |
| 275 | - if ($usecachekey) $tabtranslatedomain=array(); // To save lang content in cache |
|
| 275 | + if ($usecachekey) $tabtranslatedomain = array(); // To save lang content in cache |
|
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | 278 | * Read each lines until a '=' (with any combination of spaces around it) |
@@ -314,21 +314,21 @@ discard block |
||
| 314 | 314 | } |
| 315 | 315 | } |
| 316 | 316 | fclose($fp); |
| 317 | - $fileread=1; |
|
| 317 | + $fileread = 1; |
|
| 318 | 318 | |
| 319 | 319 | // TODO Move cache write out of loop on dirs |
| 320 | 320 | // To save lang content for usecachekey into cache |
| 321 | 321 | if ($usecachekey && count($tabtranslatedomain)) |
| 322 | 322 | { |
| 323 | - $ressetcache=dol_setcache($usecachekey,$tabtranslatedomain); |
|
| 323 | + $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain); |
|
| 324 | 324 | if ($ressetcache < 0) |
| 325 | 325 | { |
| 326 | - $error='Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
| 326 | + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
| 327 | 327 | dol_syslog($error, LOG_ERR); |
| 328 | 328 | } |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 331 | + if (empty($conf->global->MAIN_FORCELANGDIR)) break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 332 | 332 | } |
| 333 | 333 | } |
| 334 | 334 | } |
@@ -339,10 +339,10 @@ discard block |
||
| 339 | 339 | { |
| 340 | 340 | // This function MUST NOT contains call to syslog |
| 341 | 341 | //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG); |
| 342 | - $langofdir=strtolower($langarray[0]).'_'.strtoupper($langarray[0]); |
|
| 343 | - if ($langofdir == 'el_EL') $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 344 | - if ($langofdir == 'ar_AR') $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 345 | - $this->load($domain,$alt+1,$stopafterdirection,$langofdir); |
|
| 342 | + $langofdir = strtolower($langarray[0]).'_'.strtoupper($langarray[0]); |
|
| 343 | + if ($langofdir == 'el_EL') $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 344 | + if ($langofdir == 'ar_AR') $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 345 | + $this->load($domain, $alt + 1, $stopafterdirection, $langofdir); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // Now we complete with reference file (en_US) |
@@ -350,38 +350,38 @@ discard block |
||
| 350 | 350 | { |
| 351 | 351 | // This function MUST NOT contains call to syslog |
| 352 | 352 | //dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG); |
| 353 | - $langofdir='en_US'; |
|
| 354 | - $this->load($domain,$alt+1,$stopafterdirection,$langofdir); |
|
| 353 | + $langofdir = 'en_US'; |
|
| 354 | + $this->load($domain, $alt + 1, $stopafterdirection, $langofdir); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // We already are the reference file. No more files to scan to complete. |
| 358 | 358 | if ($alt == 2) |
| 359 | 359 | { |
| 360 | - if ($fileread) $this->_tab_loaded[$newdomain]=1; // Set domain file as loaded |
|
| 360 | + if ($fileread) $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded |
|
| 361 | 361 | |
| 362 | - if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain]=2; // Set this file as found |
|
| 362 | + if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain] = 2; // Set this file as found |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | // This part is deprecated and replaced with table llx_overwrite_trans |
| 366 | 366 | // Kept for backward compatibility. |
| 367 | 367 | if (empty($loadfromfileonly)) |
| 368 | 368 | { |
| 369 | - $overwritekey='MAIN_OVERWRITE_TRANS_'.$this->defaultlang; |
|
| 370 | - if (! empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2 |
|
| 369 | + $overwritekey = 'MAIN_OVERWRITE_TRANS_'.$this->defaultlang; |
|
| 370 | + if (!empty($conf->global->$overwritekey)) // Overwrite translation with key1:newstring1,key2:newstring2 |
|
| 371 | 371 | { |
| 372 | 372 | // Overwrite translation with param MAIN_OVERWRITE_TRANS_xx_XX |
| 373 | - $tmparray=explode(',', $conf->global->$overwritekey); |
|
| 374 | - foreach($tmparray as $tmp) |
|
| 373 | + $tmparray = explode(',', $conf->global->$overwritekey); |
|
| 374 | + foreach ($tmparray as $tmp) |
|
| 375 | 375 | { |
| 376 | - $tmparray2=explode(':',$tmp); |
|
| 377 | - if (! empty($tmparray2[1])) $this->tab_translate[$tmparray2[0]]=$tmparray2[1]; |
|
| 376 | + $tmparray2 = explode(':', $tmp); |
|
| 377 | + if (!empty($tmparray2[1])) $this->tab_translate[$tmparray2[0]] = $tmparray2[1]; |
|
| 378 | 378 | } |
| 379 | 379 | } |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | // Check to be sure that SeparatorDecimal differs from SeparatorThousand |
| 383 | - if (! empty($this->tab_translate["SeparatorDecimal"]) && ! empty($this->tab_translate["SeparatorThousand"]) |
|
| 384 | - && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) $this->tab_translate["SeparatorThousand"]=''; |
|
| 383 | + if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) |
|
| 384 | + && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) $this->tab_translate["SeparatorThousand"] = ''; |
|
| 385 | 385 | |
| 386 | 386 | return 1; |
| 387 | 387 | } |
@@ -402,10 +402,10 @@ discard block |
||
| 402 | 402 | { |
| 403 | 403 | global $conf; |
| 404 | 404 | |
| 405 | - $domain='database'; |
|
| 405 | + $domain = 'database'; |
|
| 406 | 406 | |
| 407 | 407 | // Check parameters |
| 408 | - if (empty($db)) return 0; // Database handler can't be used |
|
| 408 | + if (empty($db)) return 0; // Database handler can't be used |
|
| 409 | 409 | |
| 410 | 410 | //dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang); |
| 411 | 411 | |
@@ -413,19 +413,19 @@ discard block |
||
| 413 | 413 | $modulename = ''; |
| 414 | 414 | |
| 415 | 415 | // Check cache |
| 416 | - if (! empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain |
|
| 416 | + if (!empty($this->_tab_loaded[$newdomain])) // File already loaded for this domain |
|
| 417 | 417 | { |
| 418 | 418 | //dol_syslog("Translate::Load already loaded for newdomain=".$newdomain); |
| 419 | 419 | return 0; |
| 420 | 420 | } |
| 421 | 421 | |
| 422 | - $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only. |
|
| 422 | + $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only. |
|
| 423 | 423 | |
| 424 | - $fileread=0; |
|
| 425 | - $langofdir=(empty($forcelangdir)?$this->defaultlang:$forcelangdir); |
|
| 424 | + $fileread = 0; |
|
| 425 | + $langofdir = (empty($forcelangdir) ? $this->defaultlang : $forcelangdir); |
|
| 426 | 426 | |
| 427 | 427 | // Redefine alt |
| 428 | - $alt=2; |
|
| 428 | + $alt = 2; |
|
| 429 | 429 | |
| 430 | 430 | if (empty($langofdir)) // This may occurs when load is called without setting the language and without providing a value for forcelangdir |
| 431 | 431 | { |
@@ -434,19 +434,19 @@ discard block |
||
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | // TODO Move cache read out of loop on dirs or at least filelangexists |
| 437 | - $found=false; |
|
| 437 | + $found = false; |
|
| 438 | 438 | |
| 439 | 439 | // Enable caching of lang file in memory (not by default) |
| 440 | - $usecachekey=''; |
|
| 440 | + $usecachekey = ''; |
|
| 441 | 441 | // Using a memcached server |
| 442 | - if (! empty($conf->memcached->enabled) && ! empty($conf->global->MEMCACHED_SERVER)) |
|
| 442 | + if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) |
|
| 443 | 443 | { |
| 444 | - $usecachekey=$newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars |
|
| 444 | + $usecachekey = $newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars |
|
| 445 | 445 | } |
| 446 | 446 | // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) |
| 447 | 447 | else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) |
| 448 | 448 | { |
| 449 | - $usecachekey=$newdomain; |
|
| 449 | + $usecachekey = $newdomain; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | if ($usecachekey) |
@@ -454,61 +454,61 @@ discard block |
||
| 454 | 454 | //dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey); |
| 455 | 455 | //global $aaa; $aaa+=1; |
| 456 | 456 | //print $aaa." ".$usecachekey."\n"; |
| 457 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/memory.lib.php'; |
|
| 458 | - $tmparray=dol_getcache($usecachekey); |
|
| 457 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/memory.lib.php'; |
|
| 458 | + $tmparray = dol_getcache($usecachekey); |
|
| 459 | 459 | if (is_array($tmparray) && count($tmparray)) |
| 460 | 460 | { |
| 461 | - $this->tab_translate+=$tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a valuer already exists into tab_translate, value into tmparaay is not added. |
|
| 461 | + $this->tab_translate += $tmparray; // Faster than array_merge($tmparray,$this->tab_translate). Note: If a valuer already exists into tab_translate, value into tmparaay is not added. |
|
| 462 | 462 | //print $newdomain."\n"; |
| 463 | 463 | //var_dump($this->tab_translate); |
| 464 | - $fileread=1; |
|
| 465 | - $found=true; // Found in dolibarr PHP cache |
|
| 464 | + $fileread = 1; |
|
| 465 | + $found = true; // Found in dolibarr PHP cache |
|
| 466 | 466 | } |
| 467 | 467 | } |
| 468 | 468 | |
| 469 | - if (! $found && ! empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) |
|
| 469 | + if (!$found && !empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) |
|
| 470 | 470 | { |
| 471 | 471 | // Overwrite translation with database read |
| 472 | - $sql="SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."'"; |
|
| 473 | - $resql=$db->query($sql); |
|
| 472 | + $sql = "SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."'"; |
|
| 473 | + $resql = $db->query($sql); |
|
| 474 | 474 | |
| 475 | 475 | if ($resql) |
| 476 | 476 | { |
| 477 | 477 | $num = $db->num_rows($resql); |
| 478 | 478 | if ($num) |
| 479 | 479 | { |
| 480 | - if ($usecachekey) $tabtranslatedomain=array(); // To save lang content in cache |
|
| 480 | + if ($usecachekey) $tabtranslatedomain = array(); // To save lang content in cache |
|
| 481 | 481 | |
| 482 | 482 | $i = 0; |
| 483 | 483 | while ($i < $num) // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents |
| 484 | 484 | { |
| 485 | - $obj=$db->fetch_object($resql); |
|
| 485 | + $obj = $db->fetch_object($resql); |
|
| 486 | 486 | |
| 487 | - $key=$obj->transkey; |
|
| 488 | - $value=$obj->transvalue; |
|
| 487 | + $key = $obj->transkey; |
|
| 488 | + $value = $obj->transvalue; |
|
| 489 | 489 | |
| 490 | 490 | //print "Domain=$domain, found a string for $tab[0] with value $tab[1]<br>"; |
| 491 | 491 | if (empty($this->tab_translate[$key])) // If translation was already found, we must not continue, even if MAIN_FORCELANGDIR is set (MAIN_FORCELANGDIR is to replace lang dir, not to overwrite entries) |
| 492 | 492 | { |
| 493 | - $value=trim(preg_replace('/\\n/',"\n",$value)); |
|
| 493 | + $value = trim(preg_replace('/\\n/', "\n", $value)); |
|
| 494 | 494 | |
| 495 | - $this->tab_translate[$key]=$value; |
|
| 496 | - if ($usecachekey) $tabtranslatedomain[$key]=$value; // To save lang content in cache |
|
| 495 | + $this->tab_translate[$key] = $value; |
|
| 496 | + if ($usecachekey) $tabtranslatedomain[$key] = $value; // To save lang content in cache |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $i++; |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - $fileread=1; |
|
| 502 | + $fileread = 1; |
|
| 503 | 503 | |
| 504 | 504 | // TODO Move cache write out of loop on dirs |
| 505 | 505 | // To save lang content for usecachekey into cache |
| 506 | 506 | if ($usecachekey && count($tabtranslatedomain)) |
| 507 | 507 | { |
| 508 | - $ressetcache=dol_setcache($usecachekey,$tabtranslatedomain); |
|
| 508 | + $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain); |
|
| 509 | 509 | if ($ressetcache < 0) |
| 510 | 510 | { |
| 511 | - $error='Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
| 511 | + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
| 512 | 512 | dol_syslog($error, LOG_ERR); |
| 513 | 513 | } |
| 514 | 514 | } |
@@ -520,9 +520,9 @@ discard block |
||
| 520 | 520 | } |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | - if ($fileread) $this->_tab_loaded[$newdomain]=1; // Set domain file as loaded |
|
| 523 | + if ($fileread) $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded |
|
| 524 | 524 | |
| 525 | - if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain]=2; // Marque ce cas comme non trouve (no lines found for language) |
|
| 525 | + if (empty($this->_tab_loaded[$newdomain])) $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
| 526 | 526 | |
| 527 | 527 | return 1; |
| 528 | 528 | } |
@@ -544,34 +544,34 @@ discard block |
||
| 544 | 544 | { |
| 545 | 545 | global $db; |
| 546 | 546 | |
| 547 | - if (! is_string($key)) return 'ErrorBadValueForParamNotAString'; // Avoid multiple errors with code not using function correctly. |
|
| 547 | + if (!is_string($key)) return 'ErrorBadValueForParamNotAString'; // Avoid multiple errors with code not using function correctly. |
|
| 548 | 548 | |
| 549 | - $newstr=$key; |
|
| 550 | - if (preg_match('/^Civility([0-9A-Z]+)$/i',$key,$reg)) |
|
| 549 | + $newstr = $key; |
|
| 550 | + if (preg_match('/^Civility([0-9A-Z]+)$/i', $key, $reg)) |
|
| 551 | 551 | { |
| 552 | - $newstr=$this->getLabelFromKey($db,$reg[1],'c_civility','code','label'); |
|
| 552 | + $newstr = $this->getLabelFromKey($db, $reg[1], 'c_civility', 'code', 'label'); |
|
| 553 | 553 | } |
| 554 | - elseif (preg_match('/^Currency([A-Z][A-Z][A-Z])$/i',$key,$reg)) |
|
| 554 | + elseif (preg_match('/^Currency([A-Z][A-Z][A-Z])$/i', $key, $reg)) |
|
| 555 | 555 | { |
| 556 | - $newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','label'); |
|
| 556 | + $newstr = $this->getLabelFromKey($db, $reg[1], 'c_currencies', 'code_iso', 'label'); |
|
| 557 | 557 | } |
| 558 | - elseif (preg_match('/^SendingMethod([0-9A-Z]+)$/i',$key,$reg)) |
|
| 558 | + elseif (preg_match('/^SendingMethod([0-9A-Z]+)$/i', $key, $reg)) |
|
| 559 | 559 | { |
| 560 | - $newstr=$this->getLabelFromKey($db,$reg[1],'c_shipment_mode','code','libelle'); |
|
| 560 | + $newstr = $this->getLabelFromKey($db, $reg[1], 'c_shipment_mode', 'code', 'libelle'); |
|
| 561 | 561 | } |
| 562 | - elseif (preg_match('/^PaymentTypeShort([0-9A-Z]+)$/i',$key,$reg)) |
|
| 562 | + elseif (preg_match('/^PaymentTypeShort([0-9A-Z]+)$/i', $key, $reg)) |
|
| 563 | 563 | { |
| 564 | - $newstr=$this->getLabelFromKey($db,$reg[1],'c_paiement','code','libelle','',1); |
|
| 564 | + $newstr = $this->getLabelFromKey($db, $reg[1], 'c_paiement', 'code', 'libelle', '', 1); |
|
| 565 | 565 | } |
| 566 | - elseif (preg_match('/^OppStatusShort([0-9A-Z]+)$/i',$key,$reg)) |
|
| 566 | + elseif (preg_match('/^OppStatusShort([0-9A-Z]+)$/i', $key, $reg)) |
|
| 567 | 567 | { |
| 568 | - $newstr=$this->getLabelFromKey($db,$reg[1],'c_lead_status','code','label'); |
|
| 568 | + $newstr = $this->getLabelFromKey($db, $reg[1], 'c_lead_status', 'code', 'label'); |
|
| 569 | 569 | } |
| 570 | - elseif (preg_match('/^OppStatus([0-9A-Z]+)$/i',$key,$reg)) |
|
| 570 | + elseif (preg_match('/^OppStatus([0-9A-Z]+)$/i', $key, $reg)) |
|
| 571 | 571 | { |
| 572 | - $newstr=$this->getLabelFromKey($db,$reg[1],'c_lead_status','code','label'); |
|
| 572 | + $newstr = $this->getLabelFromKey($db, $reg[1], 'c_lead_status', 'code', 'label'); |
|
| 573 | 573 | } |
| 574 | - elseif (preg_match('/^OrderSource([0-9A-Z]+)$/i',$key,$reg)) |
|
| 574 | + elseif (preg_match('/^OrderSource([0-9A-Z]+)$/i', $key, $reg)) |
|
| 575 | 575 | { |
| 576 | 576 | // TODO OrderSourceX must be replaced with content of table llx_c_input_reason or llx_c_input_method |
| 577 | 577 | //$newstr=$this->getLabelFromKey($db,$reg[1],'c_ordersource','code','label'); |
@@ -594,42 +594,42 @@ discard block |
||
| 594 | 594 | * @param int $maxsize Max length of text |
| 595 | 595 | * @return string Translated string (encoded into HTML entities and UTF8) |
| 596 | 596 | */ |
| 597 | - function trans($key, $param1='', $param2='', $param3='', $param4='', $maxsize=0) |
|
| 597 | + function trans($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '', $maxsize = 0) |
|
| 598 | 598 | { |
| 599 | 599 | global $conf; |
| 600 | 600 | |
| 601 | - if (! empty($this->tab_translate[$key])) // Translation is available |
|
| 601 | + if (!empty($this->tab_translate[$key])) // Translation is available |
|
| 602 | 602 | { |
| 603 | - $str=$this->tab_translate[$key]; |
|
| 603 | + $str = $this->tab_translate[$key]; |
|
| 604 | 604 | |
| 605 | 605 | // Make some string replacement after translation |
| 606 | - $replacekey='MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
| 607 | - if (! empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1;string2:newstring2 |
|
| 606 | + $replacekey = 'MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
| 607 | + if (!empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1;string2:newstring2 |
|
| 608 | 608 | { |
| 609 | - $tmparray=explode(';', $conf->global->$replacekey); |
|
| 610 | - foreach($tmparray as $tmp) |
|
| 609 | + $tmparray = explode(';', $conf->global->$replacekey); |
|
| 610 | + foreach ($tmparray as $tmp) |
|
| 611 | 611 | { |
| 612 | - $tmparray2=explode(':',$tmp); |
|
| 613 | - $str=preg_replace('/'.preg_quote($tmparray2[0]).'/',$tmparray2[1],$str); |
|
| 612 | + $tmparray2 = explode(':', $tmp); |
|
| 613 | + $str = preg_replace('/'.preg_quote($tmparray2[0]).'/', $tmparray2[1], $str); |
|
| 614 | 614 | } |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | - if (! preg_match('/^Format/',$key)) |
|
| 617 | + if (!preg_match('/^Format/', $key)) |
|
| 618 | 618 | { |
| 619 | 619 | //print $str; |
| 620 | - $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings. |
|
| 620 | + $str = sprintf($str, $param1, $param2, $param3, $param4); // Replace %s and %d except for FormatXXX strings. |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | - if ($maxsize) $str=dol_trunc($str,$maxsize); |
|
| 623 | + if ($maxsize) $str = dol_trunc($str, $maxsize); |
|
| 624 | 624 | |
| 625 | 625 | // We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities |
| 626 | - $str=str_replace(array('<','>','"',),array('__lt__','__gt__','__quot__'),$str); |
|
| 626 | + $str = str_replace(array('<', '>', '"',), array('__lt__', '__gt__', '__quot__'), $str); |
|
| 627 | 627 | |
| 628 | 628 | // Crypt string into HTML |
| 629 | - $str=htmlentities($str, ENT_COMPAT, $this->charset_output); // Do not convert simple quotes in translation (strings in html are enmbraced by "). Use dol_escape_htmltag around text in HTML content |
|
| 629 | + $str = htmlentities($str, ENT_COMPAT, $this->charset_output); // Do not convert simple quotes in translation (strings in html are enmbraced by "). Use dol_escape_htmltag around text in HTML content |
|
| 630 | 630 | |
| 631 | 631 | // Restore HTML tags |
| 632 | - $str=str_replace(array('__lt__','__gt__','__quot__'),array('<','>','"',),$str); |
|
| 632 | + $str = str_replace(array('__lt__', '__gt__', '__quot__'), array('<', '>', '"',), $str); |
|
| 633 | 633 | |
| 634 | 634 | return $str; |
| 635 | 635 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @param string $param4 chaine de param4 |
| 655 | 655 | * @return string Translated string (encoded into UTF8) |
| 656 | 656 | */ |
| 657 | - function transnoentities($key, $param1='', $param2='', $param3='', $param4='') |
|
| 657 | + function transnoentities($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '') |
|
| 658 | 658 | { |
| 659 | 659 | return $this->convToOutputCharset($this->transnoentitiesnoconv($key, $param1, $param2, $param3, $param4)); |
| 660 | 660 | } |
@@ -674,37 +674,37 @@ discard block |
||
| 674 | 674 | * @param string $param4 chaine de param4 |
| 675 | 675 | * @return string Translated string |
| 676 | 676 | */ |
| 677 | - function transnoentitiesnoconv($key, $param1='', $param2='', $param3='', $param4='') |
|
| 677 | + function transnoentitiesnoconv($key, $param1 = '', $param2 = '', $param3 = '', $param4 = '') |
|
| 678 | 678 | { |
| 679 | 679 | global $conf; |
| 680 | 680 | |
| 681 | - if (! empty($this->tab_translate[$key])) // Translation is available |
|
| 681 | + if (!empty($this->tab_translate[$key])) // Translation is available |
|
| 682 | 682 | { |
| 683 | - $str=$this->tab_translate[$key]; |
|
| 683 | + $str = $this->tab_translate[$key]; |
|
| 684 | 684 | |
| 685 | 685 | // Make some string replacement after translation |
| 686 | - $replacekey='MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
| 687 | - if (! empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1;string2:newstring2 |
|
| 686 | + $replacekey = 'MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
| 687 | + if (!empty($conf->global->$replacekey)) // Replacement translation variable with string1:newstring1;string2:newstring2 |
|
| 688 | 688 | { |
| 689 | - $tmparray=explode(';', $conf->global->$replacekey); |
|
| 690 | - foreach($tmparray as $tmp) |
|
| 689 | + $tmparray = explode(';', $conf->global->$replacekey); |
|
| 690 | + foreach ($tmparray as $tmp) |
|
| 691 | 691 | { |
| 692 | - $tmparray2=explode(':',$tmp); |
|
| 693 | - $str=preg_replace('/'.preg_quote($tmparray2[0]).'/',$tmparray2[1],$str); |
|
| 692 | + $tmparray2 = explode(':', $tmp); |
|
| 693 | + $str = preg_replace('/'.preg_quote($tmparray2[0]).'/', $tmparray2[1], $str); |
|
| 694 | 694 | } |
| 695 | 695 | } |
| 696 | 696 | |
| 697 | - if (! preg_match('/^Format/',$key)) |
|
| 697 | + if (!preg_match('/^Format/', $key)) |
|
| 698 | 698 | { |
| 699 | 699 | //print $str; |
| 700 | - $str=sprintf($str,$param1,$param2,$param3,$param4); // Replace %s and %d except for FormatXXX strings. |
|
| 700 | + $str = sprintf($str, $param1, $param2, $param3, $param4); // Replace %s and %d except for FormatXXX strings. |
|
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | return $str; |
| 704 | 704 | } |
| 705 | 705 | else |
| 706 | 706 | { |
| 707 | - if ($key[0] == '$') { return dol_eval($key,1); } |
|
| 707 | + if ($key[0] == '$') { return dol_eval($key, 1); } |
|
| 708 | 708 | return $this->getTradFromKey($key); |
| 709 | 709 | } |
| 710 | 710 | } |
@@ -745,10 +745,10 @@ discard block |
||
| 745 | 745 | * @param string $pagecodefrom Page code of src string |
| 746 | 746 | * @return string Converted string |
| 747 | 747 | */ |
| 748 | - function convToOutputCharset($str,$pagecodefrom='UTF-8') |
|
| 748 | + function convToOutputCharset($str, $pagecodefrom = 'UTF-8') |
|
| 749 | 749 | { |
| 750 | - if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') $str=utf8_encode($str); |
|
| 751 | - if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') $str=utf8_decode(str_replace('€',chr(128),$str)); |
|
| 750 | + if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') $str = utf8_encode($str); |
|
| 751 | + if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') $str = utf8_decode(str_replace('€', chr(128), $str)); |
|
| 752 | 752 | return $str; |
| 753 | 753 | } |
| 754 | 754 | |
@@ -761,16 +761,16 @@ discard block |
||
| 761 | 761 | * @param int $usecode 1=Show code instead of country name for language variant, 2=Show only code |
| 762 | 762 | * @return array List of languages |
| 763 | 763 | */ |
| 764 | - function get_available_languages($langdir=DOL_DOCUMENT_ROOT,$maxlength=0,$usecode=0) |
|
| 764 | + function get_available_languages($langdir = DOL_DOCUMENT_ROOT, $maxlength = 0, $usecode = 0) |
|
| 765 | 765 | { |
| 766 | 766 | global $conf; |
| 767 | 767 | |
| 768 | 768 | // We scan directory langs to detect available languages |
| 769 | - $handle=opendir($langdir."/langs"); |
|
| 770 | - $langs_available=array(); |
|
| 769 | + $handle = opendir($langdir."/langs"); |
|
| 770 | + $langs_available = array(); |
|
| 771 | 771 | while ($dir = trim(readdir($handle))) |
| 772 | 772 | { |
| 773 | - if (preg_match('/^[a-z]+_[A-Z]+/i',$dir)) |
|
| 773 | + if (preg_match('/^[a-z]+_[A-Z]+/i', $dir)) |
|
| 774 | 774 | { |
| 775 | 775 | $this->load("languages"); |
| 776 | 776 | |
@@ -778,9 +778,9 @@ discard block |
||
| 778 | 778 | { |
| 779 | 779 | $langs_available[$dir] = $dir; |
| 780 | 780 | } |
| 781 | - if ($usecode == 1 || ! empty($conf->global->MAIN_SHOW_LANGUAGE_CODE)) |
|
| 781 | + if ($usecode == 1 || !empty($conf->global->MAIN_SHOW_LANGUAGE_CODE)) |
|
| 782 | 782 | { |
| 783 | - $langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir),$maxlength); |
|
| 783 | + $langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir), $maxlength); |
|
| 784 | 784 | } |
| 785 | 785 | else |
| 786 | 786 | { |
@@ -799,10 +799,10 @@ discard block |
||
| 799 | 799 | * @param integer $searchalt Search also alernate language file |
| 800 | 800 | * @return boolean true if exists and readable |
| 801 | 801 | */ |
| 802 | - function file_exists($filename,$searchalt=0) |
|
| 802 | + function file_exists($filename, $searchalt = 0) |
|
| 803 | 803 | { |
| 804 | 804 | // Test si fichier dans repertoire de la langue |
| 805 | - foreach($this->dir as $searchdir) |
|
| 805 | + foreach ($this->dir as $searchdir) |
|
| 806 | 806 | { |
| 807 | 807 | if (is_readable(dol_osencode($searchdir."/langs/".$this->defaultlang."/".$filename))) return true; |
| 808 | 808 | |
@@ -830,26 +830,26 @@ discard block |
||
| 830 | 830 | * 10 if setDefaultLang was en_US => ten |
| 831 | 831 | * 123 if setDefaultLang was fr_FR => cent vingt trois |
| 832 | 832 | */ |
| 833 | - function getLabelFromNumber($number,$isamount=0) |
|
| 833 | + function getLabelFromNumber($number, $isamount = 0) |
|
| 834 | 834 | { |
| 835 | 835 | global $conf; |
| 836 | 836 | |
| 837 | - $newnumber=$number; |
|
| 837 | + $newnumber = $number; |
|
| 838 | 838 | |
| 839 | - $dirsubstitutions=array_merge(array(),$conf->modules_parts['substitutions']); |
|
| 840 | - foreach($dirsubstitutions as $reldir) |
|
| 839 | + $dirsubstitutions = array_merge(array(), $conf->modules_parts['substitutions']); |
|
| 840 | + foreach ($dirsubstitutions as $reldir) |
|
| 841 | 841 | { |
| 842 | - $dir=dol_buildpath($reldir,0); |
|
| 843 | - $newdir=dol_osencode($dir); |
|
| 842 | + $dir = dol_buildpath($reldir, 0); |
|
| 843 | + $newdir = dol_osencode($dir); |
|
| 844 | 844 | |
| 845 | 845 | // Check if directory exists |
| 846 | - if (! is_dir($newdir)) continue; // We must not use dol_is_dir here, function may not be loaded |
|
| 846 | + if (!is_dir($newdir)) continue; // We must not use dol_is_dir here, function may not be loaded |
|
| 847 | 847 | |
| 848 | - $fonc='numberwords'; |
|
| 848 | + $fonc = 'numberwords'; |
|
| 849 | 849 | if (file_exists($newdir.'/functions_'.$fonc.'.lib.php')) |
| 850 | 850 | { |
| 851 | 851 | include_once $newdir.'/functions_'.$fonc.'.lib.php'; |
| 852 | - $newnumber=numberwords_getLabelFromNumber($this,$number,$isamount); |
|
| 852 | + $newnumber = numberwords_getLabelFromNumber($this, $number, $isamount); |
|
| 853 | 853 | break; |
| 854 | 854 | } |
| 855 | 855 | } |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | * @return string Label in UTF8 (but without entities) |
| 874 | 874 | * @see dol_getIdFromCode |
| 875 | 875 | */ |
| 876 | - function getLabelFromKey($db,$key,$tablename,$fieldkey,$fieldlabel,$keyforselect='',$filteronentity=0) |
|
| 876 | + function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '', $filteronentity = 0) |
|
| 877 | 877 | { |
| 878 | 878 | // If key empty |
| 879 | 879 | if ($key == '') return ''; |
@@ -881,36 +881,36 @@ discard block |
||
| 881 | 881 | //print 'param: '.$key.'-'.$keydatabase.'-'.$this->trans($key); exit; |
| 882 | 882 | |
| 883 | 883 | // Check if a translation is available (this can call getTradFromKey) |
| 884 | - $tmp=$this->transnoentitiesnoconv($key); |
|
| 884 | + $tmp = $this->transnoentitiesnoconv($key); |
|
| 885 | 885 | if ($tmp != $key && $tmp != 'ErrorBadValueForParamNotAString') |
| 886 | 886 | { |
| 887 | - return $tmp; // Found in language array |
|
| 887 | + return $tmp; // Found in language array |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | // Check in cache |
| 891 | 891 | if (isset($this->cache_labels[$tablename][$key])) // Can be defined to 0 or '' |
| 892 | 892 | { |
| 893 | - return $this->cache_labels[$tablename][$key]; // Found in cache |
|
| 893 | + return $this->cache_labels[$tablename][$key]; // Found in cache |
|
| 894 | 894 | } |
| 895 | 895 | |
| 896 | 896 | $sql = "SELECT ".$fieldlabel." as label"; |
| 897 | - $sql.= " FROM ".MAIN_DB_PREFIX.$tablename; |
|
| 898 | - $sql.= " WHERE ".$fieldkey." = '".($keyforselect?$keyforselect:$key)."'"; |
|
| 899 | - if ($filteronentity) $sql.= " AND entity IN (" . getEntity($tablename). ')'; |
|
| 897 | + $sql .= " FROM ".MAIN_DB_PREFIX.$tablename; |
|
| 898 | + $sql .= " WHERE ".$fieldkey." = '".($keyforselect ? $keyforselect : $key)."'"; |
|
| 899 | + if ($filteronentity) $sql .= " AND entity IN (".getEntity($tablename).')'; |
|
| 900 | 900 | dol_syslog(get_class($this).'::getLabelFromKey', LOG_DEBUG); |
| 901 | 901 | $resql = $db->query($sql); |
| 902 | 902 | if ($resql) |
| 903 | 903 | { |
| 904 | 904 | $obj = $db->fetch_object($resql); |
| 905 | - if ($obj) $this->cache_labels[$tablename][$key]=$obj->label; |
|
| 906 | - else $this->cache_labels[$tablename][$key]=$key; |
|
| 905 | + if ($obj) $this->cache_labels[$tablename][$key] = $obj->label; |
|
| 906 | + else $this->cache_labels[$tablename][$key] = $key; |
|
| 907 | 907 | |
| 908 | 908 | $db->free($resql); |
| 909 | 909 | return $this->cache_labels[$tablename][$key]; |
| 910 | 910 | } |
| 911 | 911 | else |
| 912 | 912 | { |
| 913 | - $this->error=$db->lasterror(); |
|
| 913 | + $this->error = $db->lasterror(); |
|
| 914 | 914 | return -1; |
| 915 | 915 | } |
| 916 | 916 | } |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | */ |
| 928 | 928 | function getCurrencyAmount($currency_code, $amount) |
| 929 | 929 | { |
| 930 | - $symbol=$this->getCurrencySymbol($currency_code); |
|
| 930 | + $symbol = $this->getCurrencySymbol($currency_code); |
|
| 931 | 931 | |
| 932 | 932 | if (in_array($currency_code, array('USD'))) return $symbol.$amount; |
| 933 | 933 | else return $amount.$symbol; |
@@ -941,24 +941,24 @@ discard block |
||
| 941 | 941 | * @param integer $forceloadall 1=Force to load all currencies into cache. We know we need to use all of them. By default read and cache only required currency. |
| 942 | 942 | * @return string Currency symbol encoded into UTF8 |
| 943 | 943 | */ |
| 944 | - function getCurrencySymbol($currency_code, $forceloadall=0) |
|
| 944 | + function getCurrencySymbol($currency_code, $forceloadall = 0) |
|
| 945 | 945 | { |
| 946 | - $currency_sign = ''; // By default return iso code |
|
| 946 | + $currency_sign = ''; // By default return iso code |
|
| 947 | 947 | |
| 948 | 948 | if (function_exists("mb_convert_encoding")) |
| 949 | 949 | { |
| 950 | - $this->loadCacheCurrencies($forceloadall?'':$currency_code); |
|
| 950 | + $this->loadCacheCurrencies($forceloadall ? '' : $currency_code); |
|
| 951 | 951 | |
| 952 | - if (isset($this->cache_currencies[$currency_code]) && ! empty($this->cache_currencies[$currency_code]['unicode']) && is_array($this->cache_currencies[$currency_code]['unicode'])) |
|
| 952 | + if (isset($this->cache_currencies[$currency_code]) && !empty($this->cache_currencies[$currency_code]['unicode']) && is_array($this->cache_currencies[$currency_code]['unicode'])) |
|
| 953 | 953 | { |
| 954 | - foreach($this->cache_currencies[$currency_code]['unicode'] as $unicode) |
|
| 954 | + foreach ($this->cache_currencies[$currency_code]['unicode'] as $unicode) |
|
| 955 | 955 | { |
| 956 | 956 | $currency_sign .= mb_convert_encoding("&#{$unicode};", "UTF-8", 'HTML-ENTITIES'); |
| 957 | 957 | } |
| 958 | 958 | } |
| 959 | 959 | } |
| 960 | 960 | |
| 961 | - return ($currency_sign?$currency_sign:$currency_code); |
|
| 961 | + return ($currency_sign ? $currency_sign : $currency_code); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -971,13 +971,13 @@ discard block |
||
| 971 | 971 | { |
| 972 | 972 | global $db; |
| 973 | 973 | |
| 974 | - if ($this->cache_currencies_all_loaded) return 0; // Cache already loaded for all |
|
| 975 | - if (! empty($currency_code) && isset($this->cache_currencies[$currency_code])) return 0; // Cache already loaded for the currency |
|
| 974 | + if ($this->cache_currencies_all_loaded) return 0; // Cache already loaded for all |
|
| 975 | + if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) return 0; // Cache already loaded for the currency |
|
| 976 | 976 | |
| 977 | 977 | $sql = "SELECT code_iso, label, unicode"; |
| 978 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_currencies"; |
|
| 979 | - $sql.= " WHERE active = 1"; |
|
| 980 | - if (! empty($currency_code)) $sql.=" AND code_iso = '".$currency_code."'"; |
|
| 978 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies"; |
|
| 979 | + $sql .= " WHERE active = 1"; |
|
| 980 | + if (!empty($currency_code)) $sql .= " AND code_iso = '".$currency_code."'"; |
|
| 981 | 981 | //$sql.= " ORDER BY code_iso ASC"; // Not required, a sort is done later |
| 982 | 982 | |
| 983 | 983 | dol_syslog(get_class($this).'::loadCacheCurrencies', LOG_DEBUG); |
@@ -985,8 +985,8 @@ discard block |
||
| 985 | 985 | if ($resql) |
| 986 | 986 | { |
| 987 | 987 | $this->load("dict"); |
| 988 | - $label=array(); |
|
| 989 | - if (! empty($currency_code)) foreach($this->cache_currencies as $key => $val) $label[$key]=$val['label']; // Label in already loaded cache |
|
| 988 | + $label = array(); |
|
| 989 | + if (!empty($currency_code)) foreach ($this->cache_currencies as $key => $val) $label[$key] = $val['label']; // Label in already loaded cache |
|
| 990 | 990 | |
| 991 | 991 | $num = $db->num_rows($resql); |
| 992 | 992 | $i = 0; |
@@ -995,12 +995,12 @@ discard block |
||
| 995 | 995 | $obj = $db->fetch_object($resql); |
| 996 | 996 | |
| 997 | 997 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 998 | - $this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency".$obj->code_iso)!="Currency".$obj->code_iso?$this->trans("Currency".$obj->code_iso):($obj->label!='-'?$obj->label:'')); |
|
| 998 | + $this->cache_currencies[$obj->code_iso]['label'] = ($obj->code_iso && $this->trans("Currency".$obj->code_iso) != "Currency".$obj->code_iso ? $this->trans("Currency".$obj->code_iso) : ($obj->label != '-' ? $obj->label : '')); |
|
| 999 | 999 | $this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode($obj->unicode, true); |
| 1000 | 1000 | $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label']; |
| 1001 | 1001 | $i++; |
| 1002 | 1002 | } |
| 1003 | - if (empty($currency_code)) $this->cache_currencies_all_loaded=true; |
|
| 1003 | + if (empty($currency_code)) $this->cache_currencies_all_loaded = true; |
|
| 1004 | 1004 | //print count($label).' '.count($this->cache_currencies); |
| 1005 | 1005 | |
| 1006 | 1006 | // Resort cache |
@@ -1025,7 +1025,7 @@ discard block |
||
| 1025 | 1025 | { |
| 1026 | 1026 | $substitutionarray = array(); |
| 1027 | 1027 | |
| 1028 | - foreach($this->tab_translate as $code => $label) { |
|
| 1028 | + foreach ($this->tab_translate as $code => $label) { |
|
| 1029 | 1029 | $substitutionarray['lang_'.$code] = $label; |
| 1030 | 1030 | $substitutionarray['__('.$code.')__'] = $label; |
| 1031 | 1031 | } |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | class doc_generic_invoice_odt extends ModelePDFFactures |
| 40 | 40 | { |
| 41 | - var $emetteur; // Objet societe qui emet |
|
| 41 | + var $emetteur; // Objet societe qui emet |
|
| 42 | 42 | |
| 43 | - var $phpmin = array(5,2,0); // Minimum version of PHP required by module |
|
| 43 | + var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module |
|
| 44 | 44 | var $version = 'dolibarr'; |
| 45 | 45 | |
| 46 | 46 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function __construct($db) |
| 53 | 53 | { |
| 54 | - global $conf,$langs,$mysoc; |
|
| 54 | + global $conf, $langs, $mysoc; |
|
| 55 | 55 | |
| 56 | 56 | $langs->load("main"); |
| 57 | 57 | $langs->load("companies"); |
@@ -59,32 +59,32 @@ discard block |
||
| 59 | 59 | $this->db = $db; |
| 60 | 60 | $this->name = "ODT/ODS templates"; |
| 61 | 61 | $this->description = $langs->trans("DocumentModelOdt"); |
| 62 | - $this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 62 | + $this->scandir = 'FACTURE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 63 | 63 | |
| 64 | 64 | // Dimension page pour format A4 |
| 65 | 65 | $this->type = 'odt'; |
| 66 | 66 | $this->page_largeur = 0; |
| 67 | 67 | $this->page_hauteur = 0; |
| 68 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
| 69 | - $this->marge_gauche=0; |
|
| 70 | - $this->marge_droite=0; |
|
| 71 | - $this->marge_haute=0; |
|
| 72 | - $this->marge_basse=0; |
|
| 73 | - |
|
| 74 | - $this->option_logo = 1; // Affiche logo |
|
| 75 | - $this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION |
|
| 76 | - $this->option_modereg = 0; // Affiche mode reglement |
|
| 77 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
| 78 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 79 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 80 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 81 | - $this->option_credit_note = 0; // Support credit notes |
|
| 82 | - $this->option_freetext = 1; // Support add of a personalised text |
|
| 83 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 68 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
| 69 | + $this->marge_gauche = 0; |
|
| 70 | + $this->marge_droite = 0; |
|
| 71 | + $this->marge_haute = 0; |
|
| 72 | + $this->marge_basse = 0; |
|
| 73 | + |
|
| 74 | + $this->option_logo = 1; // Affiche logo |
|
| 75 | + $this->option_tva = 0; // Gere option tva FACTURE_TVAOPTION |
|
| 76 | + $this->option_modereg = 0; // Affiche mode reglement |
|
| 77 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
| 78 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 79 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 80 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 81 | + $this->option_credit_note = 0; // Support credit notes |
|
| 82 | + $this->option_freetext = 1; // Support add of a personalised text |
|
| 83 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 84 | 84 | |
| 85 | 85 | // Recupere emetteur |
| 86 | - $this->emetteur=$mysoc; |
|
| 87 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
| 86 | + $this->emetteur = $mysoc; |
|
| 87 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // Par defaut, si n'etait pas defini |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function info($langs) |
| 98 | 98 | { |
| 99 | - global $conf,$langs; |
|
| 99 | + global $conf, $langs; |
|
| 100 | 100 | |
| 101 | 101 | $langs->load("companies"); |
| 102 | 102 | $langs->load("errors"); |
@@ -104,74 +104,74 @@ discard block |
||
| 104 | 104 | $form = new Form($this->db); |
| 105 | 105 | |
| 106 | 106 | $texte = $this->description.".<br>\n"; |
| 107 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 108 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 109 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 110 | - $texte.= '<input type="hidden" name="param1" value="FACTURE_ADDON_PDF_ODT_PATH">'; |
|
| 111 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
| 107 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 108 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 109 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 110 | + $texte .= '<input type="hidden" name="param1" value="FACTURE_ADDON_PDF_ODT_PATH">'; |
|
| 111 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
| 112 | 112 | |
| 113 | 113 | // List of directories area |
| 114 | - $texte.= '<tr><td valign="middle">'; |
|
| 115 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
| 116 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->FACTURE_ADDON_PDF_ODT_PATH))); |
|
| 117 | - $listoffiles=array(); |
|
| 118 | - foreach($listofdir as $key=>$tmpdir) |
|
| 114 | + $texte .= '<tr><td valign="middle">'; |
|
| 115 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
| 116 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->FACTURE_ADDON_PDF_ODT_PATH))); |
|
| 117 | + $listoffiles = array(); |
|
| 118 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 119 | 119 | { |
| 120 | - $tmpdir=trim($tmpdir); |
|
| 121 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 122 | - if (! $tmpdir) { |
|
| 120 | + $tmpdir = trim($tmpdir); |
|
| 121 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 122 | + if (!$tmpdir) { |
|
| 123 | 123 | unset($listofdir[$key]); continue; |
| 124 | 124 | } |
| 125 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 125 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 126 | 126 | else |
| 127 | 127 | { |
| 128 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
| 129 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 128 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
| 129 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 132 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 133 | 133 | // Add list of substitution keys |
| 134 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 135 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 136 | - |
|
| 137 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
| 138 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 139 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
| 140 | - $texte.=$conf->global->FACTURE_ADDON_PDF_ODT_PATH; |
|
| 141 | - $texte.= '</textarea>'; |
|
| 142 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 143 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 144 | - $texte.= '<br></div></div>'; |
|
| 134 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 135 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 136 | + |
|
| 137 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
| 138 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 139 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
| 140 | + $texte .= $conf->global->FACTURE_ADDON_PDF_ODT_PATH; |
|
| 141 | + $texte .= '</textarea>'; |
|
| 142 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 143 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 144 | + $texte .= '<br></div></div>'; |
|
| 145 | 145 | |
| 146 | 146 | // Scan directories |
| 147 | - $nbofiles=count($listoffiles); |
|
| 148 | - if (! empty($conf->global->FACTURE_ADDON_PDF_ODT_PATH)) |
|
| 147 | + $nbofiles = count($listoffiles); |
|
| 148 | + if (!empty($conf->global->FACTURE_ADDON_PDF_ODT_PATH)) |
|
| 149 | 149 | { |
| 150 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 150 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 151 | 151 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
| 152 | - $texte.=count($listoffiles); |
|
| 152 | + $texte .= count($listoffiles); |
|
| 153 | 153 | //$texte.=$nbofiles?'</a>':''; |
| 154 | - $texte.='</b>'; |
|
| 154 | + $texte .= '</b>'; |
|
| 155 | 155 | } |
| 156 | 156 | if ($nbofiles) |
| 157 | 157 | { |
| 158 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 159 | - foreach($listoffiles as $file) |
|
| 158 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 159 | + foreach ($listoffiles as $file) |
|
| 160 | 160 | { |
| 161 | - $texte.=$file['name'].'<br>'; |
|
| 161 | + $texte .= $file['name'].'<br>'; |
|
| 162 | 162 | } |
| 163 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
| 163 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - $texte.= '</td>'; |
|
| 166 | + $texte .= '</td>'; |
|
| 167 | 167 | |
| 168 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 169 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 170 | - $texte.= '</td>'; |
|
| 171 | - $texte.= '</tr>'; |
|
| 168 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 169 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 170 | + $texte .= '</td>'; |
|
| 171 | + $texte .= '</tr>'; |
|
| 172 | 172 | |
| 173 | - $texte.= '</table>'; |
|
| 174 | - $texte.= '</form>'; |
|
| 173 | + $texte .= '</table>'; |
|
| 174 | + $texte .= '</form>'; |
|
| 175 | 175 | |
| 176 | 176 | return $texte; |
| 177 | 177 | } |
@@ -187,9 +187,9 @@ discard block |
||
| 187 | 187 | * @param int $hideref Do not show ref |
| 188 | 188 | * @return int 1 if OK, <=0 if KO |
| 189 | 189 | */ |
| 190 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
| 190 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
| 191 | 191 | { |
| 192 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
| 192 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
| 193 | 193 | |
| 194 | 194 | if (empty($srctemplatepath)) |
| 195 | 195 | { |
@@ -198,17 +198,17 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // Add odtgeneration hook |
| 201 | - if (! is_object($hookmanager)) |
|
| 201 | + if (!is_object($hookmanager)) |
|
| 202 | 202 | { |
| 203 | 203 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
| 204 | - $hookmanager=new HookManager($this->db); |
|
| 204 | + $hookmanager = new HookManager($this->db); |
|
| 205 | 205 | } |
| 206 | 206 | $hookmanager->initHooks(array('odtgeneration')); |
| 207 | 207 | global $action; |
| 208 | 208 | |
| 209 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
| 210 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 211 | - $outputlangs->charset_output='UTF-8'; |
|
| 209 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
| 210 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 211 | + $outputlangs->charset_output = 'UTF-8'; |
|
| 212 | 212 | |
| 213 | 213 | $outputlangs->load("main"); |
| 214 | 214 | $outputlangs->load("dict"); |
@@ -218,28 +218,28 @@ discard block |
||
| 218 | 218 | if ($conf->facture->dir_output) |
| 219 | 219 | { |
| 220 | 220 | // If $object is id instead of object |
| 221 | - if (! is_object($object)) |
|
| 221 | + if (!is_object($object)) |
|
| 222 | 222 | { |
| 223 | 223 | $id = $object; |
| 224 | 224 | $object = new Facture($this->db); |
| 225 | - $result=$object->fetch($id); |
|
| 225 | + $result = $object->fetch($id); |
|
| 226 | 226 | if ($result < 0) |
| 227 | 227 | { |
| 228 | - dol_print_error($this->db,$object->error); |
|
| 228 | + dol_print_error($this->db, $object->error); |
|
| 229 | 229 | return -1; |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | $dir = $conf->facture->dir_output; |
| 234 | 234 | $objectref = dol_sanitizeFileName($object->ref); |
| 235 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
| 236 | - $file = $dir . "/" . $objectref . ".odt"; |
|
| 235 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
| 236 | + $file = $dir."/".$objectref.".odt"; |
|
| 237 | 237 | |
| 238 | - if (! file_exists($dir)) |
|
| 238 | + if (!file_exists($dir)) |
|
| 239 | 239 | { |
| 240 | 240 | if (dol_mkdir($dir) < 0) |
| 241 | 241 | { |
| 242 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 242 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 243 | 243 | return -1; |
| 244 | 244 | } |
| 245 | 245 | } |
@@ -247,26 +247,26 @@ discard block |
||
| 247 | 247 | if (file_exists($dir)) |
| 248 | 248 | { |
| 249 | 249 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
| 250 | - $newfile=basename($srctemplatepath); |
|
| 251 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
| 252 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
| 253 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
| 250 | + $newfile = basename($srctemplatepath); |
|
| 251 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
| 252 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
| 253 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
| 254 | 254 | |
| 255 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
| 255 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
| 256 | 256 | |
| 257 | 257 | // Get extension (ods or odt) |
| 258 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
| 259 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 258 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
| 259 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 260 | 260 | { |
| 261 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
| 262 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
| 263 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
| 261 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
| 262 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
| 263 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
| 264 | 264 | } |
| 265 | 265 | else |
| 266 | 266 | { |
| 267 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
| 267 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
| 268 | 268 | } |
| 269 | - $file=$dir.'/'.$filename; |
|
| 269 | + $file = $dir.'/'.$filename; |
|
| 270 | 270 | //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
| 271 | 271 | //print "newdir=".$dir; |
| 272 | 272 | //print "newfile=".$newfile; |
@@ -277,19 +277,19 @@ discard block |
||
| 277 | 277 | |
| 278 | 278 | |
| 279 | 279 | // If BILLING contact defined on invoice, we use it |
| 280 | - $usecontact=false; |
|
| 281 | - $arrayidcontact=$object->getIdContact('external','BILLING'); |
|
| 280 | + $usecontact = false; |
|
| 281 | + $arrayidcontact = $object->getIdContact('external', 'BILLING'); |
|
| 282 | 282 | if (count($arrayidcontact) > 0) |
| 283 | 283 | { |
| 284 | - $usecontact=true; |
|
| 285 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
| 284 | + $usecontact = true; |
|
| 285 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Recipient name |
| 289 | - if (! empty($usecontact)) |
|
| 289 | + if (!empty($usecontact)) |
|
| 290 | 290 | { |
| 291 | 291 | // On peut utiliser le nom de la societe du contact |
| 292 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 292 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 293 | 293 | else { |
| 294 | 294 | $socobject = $object->thirdparty; |
| 295 | 295 | // if we have a BILLING contact and we dont use it as recipient we store the contact object for later use |
@@ -298,17 +298,17 @@ discard block |
||
| 298 | 298 | } |
| 299 | 299 | else |
| 300 | 300 | { |
| 301 | - $socobject=$object->thirdparty; |
|
| 301 | + $socobject = $object->thirdparty; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | // Fetch info for linked propal |
| 305 | - $object->fetchObjectLinked('','','',''); |
|
| 305 | + $object->fetchObjectLinked('', '', '', ''); |
|
| 306 | 306 | //print_r($object->linkedObjects['propal']); exit; |
| 307 | 307 | |
| 308 | 308 | $propal_object = $object->linkedObjects['propal'][0]; |
| 309 | 309 | |
| 310 | 310 | // Make substitution |
| 311 | - $substitutionarray=array( |
|
| 311 | + $substitutionarray = array( |
|
| 312 | 312 | '__FROM_NAME__' => $this->emetteur->name, |
| 313 | 313 | '__FROM_EMAIL__' => $this->emetteur->email, |
| 314 | 314 | '__TOTAL_TTC__' => $object->total_ttc, |
@@ -317,15 +317,15 @@ discard block |
||
| 317 | 317 | ); |
| 318 | 318 | complete_substitutions_array($substitutionarray, $langs, $object); |
| 319 | 319 | // Call the ODTSubstitution hook |
| 320 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
| 321 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 320 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray); |
|
| 321 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 322 | 322 | |
| 323 | 323 | // Line of free text |
| 324 | - $newfreetext=''; |
|
| 325 | - $paramfreetext='INVOICE_FREE_TEXT'; |
|
| 326 | - if (! empty($conf->global->$paramfreetext)) |
|
| 324 | + $newfreetext = ''; |
|
| 325 | + $paramfreetext = 'INVOICE_FREE_TEXT'; |
|
| 326 | + if (!empty($conf->global->$paramfreetext)) |
|
| 327 | 327 | { |
| 328 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
| 328 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | // Open and load template |
@@ -335,15 +335,15 @@ discard block |
||
| 335 | 335 | $srctemplatepath, |
| 336 | 336 | array( |
| 337 | 337 | 'PATH_TO_TMP' => $conf->facture->dir_temp, |
| 338 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 338 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 339 | 339 | 'DELIMITER_LEFT' => '{', |
| 340 | 340 | 'DELIMITER_RIGHT' => '}' |
| 341 | 341 | ) |
| 342 | 342 | ); |
| 343 | 343 | } |
| 344 | - catch(Exception $e) |
|
| 344 | + catch (Exception $e) |
|
| 345 | 345 | { |
| 346 | - $this->error=$e->getMessage(); |
|
| 346 | + $this->error = $e->getMessage(); |
|
| 347 | 347 | return -1; |
| 348 | 348 | } |
| 349 | 349 | // After construction $odfHandler->contentXml contains content and |
@@ -357,35 +357,35 @@ discard block |
||
| 357 | 357 | try { |
| 358 | 358 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
| 359 | 359 | } |
| 360 | - catch(OdfException $e) |
|
| 360 | + catch (OdfException $e) |
|
| 361 | 361 | { |
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | // Define substitution array |
| 365 | 365 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
| 366 | - $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
| 367 | - $array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
| 368 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
| 369 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
| 370 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
| 371 | - $array_propal=is_object($propal_object)?$this->get_substitutionarray_object($propal_object,$outputlangs,'propal'):array(); |
|
| 372 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
| 366 | + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
| 367 | + $array_objet = $this->get_substitutionarray_object($object, $outputlangs); |
|
| 368 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
| 369 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
| 370 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
| 371 | + $array_propal = is_object($propal_object) ? $this->get_substitutionarray_object($propal_object, $outputlangs, 'propal') : array(); |
|
| 372 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
| 373 | 373 | // retrieve contact information for use in invoice as contact_xxx tags |
| 374 | 374 | $array_thirdparty_contact = array(); |
| 375 | - if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
| 375 | + if ($usecontact) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
| 376 | 376 | |
| 377 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal,$array_other,$array_thirdparty_contact); |
|
| 377 | + $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_propal, $array_other, $array_thirdparty_contact); |
|
| 378 | 378 | complete_substitutions_array($tmparray, $outputlangs, $object); |
| 379 | 379 | |
| 380 | 380 | // Call the ODTSubstitution hook |
| 381 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 382 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 381 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 382 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 383 | 383 | |
| 384 | 384 | //var_dump($tmparray); exit; |
| 385 | - foreach($tmparray as $key=>$value) |
|
| 385 | + foreach ($tmparray as $key=>$value) |
|
| 386 | 386 | { |
| 387 | 387 | try { |
| 388 | - if (preg_match('/logo$/',$key)) // Image |
|
| 388 | + if (preg_match('/logo$/', $key)) // Image |
|
| 389 | 389 | { |
| 390 | 390 | //var_dump($value);exit; |
| 391 | 391 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 397 | 397 | } |
| 398 | 398 | } |
| 399 | - catch(OdfException $e) |
|
| 399 | + catch (OdfException $e) |
|
| 400 | 400 | { |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | try { |
| 408 | 408 | $listlines = $odfHandler->setSegment('lines'); |
| 409 | 409 | } |
| 410 | - catch(OdfException $e) |
|
| 410 | + catch (OdfException $e) |
|
| 411 | 411 | { |
| 412 | 412 | // We may arrive here if tags for lines not present into template |
| 413 | 413 | $foundtagforlines = 0; |
@@ -417,21 +417,21 @@ discard block |
||
| 417 | 417 | { |
| 418 | 418 | foreach ($object->lines as $line) |
| 419 | 419 | { |
| 420 | - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); |
|
| 420 | + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs); |
|
| 421 | 421 | complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
| 422 | 422 | // Call the ODTSubstitutionLine hook |
| 423 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
| 424 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 425 | - foreach($tmparray as $key => $val) |
|
| 423 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); |
|
| 424 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 425 | + foreach ($tmparray as $key => $val) |
|
| 426 | 426 | { |
| 427 | 427 | try |
| 428 | 428 | { |
| 429 | 429 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 430 | 430 | } |
| 431 | - catch(OdfException $e) |
|
| 431 | + catch (OdfException $e) |
|
| 432 | 432 | { |
| 433 | 433 | } |
| 434 | - catch(SegmentException $e) |
|
| 434 | + catch (SegmentException $e) |
|
| 435 | 435 | { |
| 436 | 436 | } |
| 437 | 437 | } |
@@ -440,61 +440,61 @@ discard block |
||
| 440 | 440 | $odfHandler->mergeSegment($listlines); |
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | - catch(OdfException $e) |
|
| 443 | + catch (OdfException $e) |
|
| 444 | 444 | { |
| 445 | - $this->error=$e->getMessage(); |
|
| 445 | + $this->error = $e->getMessage(); |
|
| 446 | 446 | dol_syslog($this->error, LOG_WARNING); |
| 447 | 447 | return -1; |
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | // Replace labels translated |
| 451 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
| 452 | - foreach($tmparray as $key=>$value) |
|
| 451 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
| 452 | + foreach ($tmparray as $key=>$value) |
|
| 453 | 453 | { |
| 454 | 454 | try { |
| 455 | 455 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 456 | 456 | } |
| 457 | - catch(OdfException $e) |
|
| 457 | + catch (OdfException $e) |
|
| 458 | 458 | { |
| 459 | 459 | } |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | // Call the beforeODTSave hook |
| 463 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 464 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 463 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 464 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 465 | 465 | |
| 466 | 466 | // Write new file |
| 467 | 467 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
| 468 | 468 | try { |
| 469 | 469 | $odfHandler->exportAsAttachedPDF($file); |
| 470 | - }catch (Exception $e){ |
|
| 471 | - $this->error=$e->getMessage(); |
|
| 470 | + } catch (Exception $e) { |
|
| 471 | + $this->error = $e->getMessage(); |
|
| 472 | 472 | return -1; |
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | else { |
| 476 | 476 | try { |
| 477 | 477 | $odfHandler->saveToDisk($file); |
| 478 | - }catch (Exception $e){ |
|
| 479 | - $this->error=$e->getMessage(); |
|
| 478 | + } catch (Exception $e) { |
|
| 479 | + $this->error = $e->getMessage(); |
|
| 480 | 480 | return -1; |
| 481 | 481 | } |
| 482 | 482 | } |
| 483 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 484 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 483 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 484 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 485 | 485 | |
| 486 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 486 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 487 | 487 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 488 | 488 | |
| 489 | - $odfHandler=null; // Destroy object |
|
| 489 | + $odfHandler = null; // Destroy object |
|
| 490 | 490 | |
| 491 | 491 | $this->result = array('fullpath'=>$file); |
| 492 | 492 | |
| 493 | - return 1; // Success |
|
| 493 | + return 1; // Success |
|
| 494 | 494 | } |
| 495 | 495 | else |
| 496 | 496 | { |
| 497 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 497 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 498 | 498 | return -1; |
| 499 | 499 | } |
| 500 | 500 | } |
@@ -37,16 +37,16 @@ discard block |
||
| 37 | 37 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 38 | 38 | require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php'; |
| 39 | 39 | require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
| 40 | -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
| 41 | -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 42 | -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; |
|
| 43 | -if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
| 44 | -if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
| 45 | -if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
| 46 | -if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
| 47 | -if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
| 48 | -if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; |
|
| 49 | -if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
| 40 | +if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
| 41 | +if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 42 | +if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; |
|
| 43 | +if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
| 44 | +if (!empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
| 45 | +if (!empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
| 46 | +if (!empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
| 47 | +if (!empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
| 48 | +if (!empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; |
|
| 49 | +if (!empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | 52 | /** |
@@ -54,9 +54,9 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | class doc_generic_task_odt extends ModelePDFTask |
| 56 | 56 | { |
| 57 | - var $emetteur; // Objet societe qui emet |
|
| 57 | + var $emetteur; // Objet societe qui emet |
|
| 58 | 58 | |
| 59 | - var $phpmin = array(5,2,0); // Minimum version of PHP required by module |
|
| 59 | + var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module |
|
| 60 | 60 | var $version = 'dolibarr'; |
| 61 | 61 | |
| 62 | 62 | |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | */ |
| 68 | 68 | function __construct($db) |
| 69 | 69 | { |
| 70 | - global $conf,$langs,$mysoc; |
|
| 70 | + global $conf, $langs, $mysoc; |
|
| 71 | 71 | |
| 72 | 72 | $langs->load("main"); |
| 73 | 73 | $langs->load("companies"); |
@@ -75,32 +75,32 @@ discard block |
||
| 75 | 75 | $this->db = $db; |
| 76 | 76 | $this->name = "ODT templates"; |
| 77 | 77 | $this->description = $langs->trans("DocumentModelOdt"); |
| 78 | - $this->scandir = 'PROJECT_TASK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 78 | + $this->scandir = 'PROJECT_TASK_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 79 | 79 | |
| 80 | 80 | // Dimension page pour format A4 |
| 81 | 81 | $this->type = 'odt'; |
| 82 | 82 | $this->page_largeur = 0; |
| 83 | 83 | $this->page_hauteur = 0; |
| 84 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
| 85 | - $this->marge_gauche=0; |
|
| 86 | - $this->marge_droite=0; |
|
| 87 | - $this->marge_haute=0; |
|
| 88 | - $this->marge_basse=0; |
|
| 89 | - |
|
| 90 | - $this->option_logo = 1; // Affiche logo |
|
| 91 | - $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION |
|
| 92 | - $this->option_modereg = 0; // Affiche mode reglement |
|
| 93 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
| 94 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 95 | - $this->option_multilang = 0; // Dispo en plusieurs langues |
|
| 96 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 97 | - $this->option_credit_note = 0; // Support credit notes |
|
| 98 | - $this->option_freetext = 1; // Support add of a personalised text |
|
| 99 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 84 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
| 85 | + $this->marge_gauche = 0; |
|
| 86 | + $this->marge_droite = 0; |
|
| 87 | + $this->marge_haute = 0; |
|
| 88 | + $this->marge_basse = 0; |
|
| 89 | + |
|
| 90 | + $this->option_logo = 1; // Affiche logo |
|
| 91 | + $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION |
|
| 92 | + $this->option_modereg = 0; // Affiche mode reglement |
|
| 93 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
| 94 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 95 | + $this->option_multilang = 0; // Dispo en plusieurs langues |
|
| 96 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 97 | + $this->option_credit_note = 0; // Support credit notes |
|
| 98 | + $this->option_freetext = 1; // Support add of a personalised text |
|
| 99 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 100 | 100 | |
| 101 | 101 | // Recupere emetteur |
| 102 | - $this->emetteur=$mysoc; |
|
| 103 | - if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
| 102 | + $this->emetteur = $mysoc; |
|
| 103 | + if (!$this->emetteur->pays_code) $this->emetteur->pays_code = substr($langs->defaultlang, -2); // Par defaut, si n'etait pas defini |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | |
@@ -112,19 +112,19 @@ discard block |
||
| 112 | 112 | * @param string $array_key Name of the key for return array |
| 113 | 113 | * @return array Array of substitution |
| 114 | 114 | */ |
| 115 | - function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 115 | + function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') |
|
| 116 | 116 | { |
| 117 | 117 | global $conf; |
| 118 | 118 | |
| 119 | - $resarray=array( |
|
| 119 | + $resarray = array( |
|
| 120 | 120 | $array_key.'_id'=>$object->id, |
| 121 | 121 | $array_key.'_ref'=>$object->ref, |
| 122 | 122 | $array_key.'_title'=>$object->title, |
| 123 | 123 | $array_key.'_description'=>$object->description, |
| 124 | - $array_key.'_date_creation'=>dol_print_date($object->date_c,'day'), |
|
| 125 | - $array_key.'_date_modification'=>dol_print_date($object->date_m,'day'), |
|
| 126 | - $array_key.'_date_start'=>dol_print_date($object->date_start,'day'), |
|
| 127 | - $array_key.'_date_end'=>dol_print_date($object->date_end,'day'), |
|
| 124 | + $array_key.'_date_creation'=>dol_print_date($object->date_c, 'day'), |
|
| 125 | + $array_key.'_date_modification'=>dol_print_date($object->date_m, 'day'), |
|
| 126 | + $array_key.'_date_start'=>dol_print_date($object->date_start, 'day'), |
|
| 127 | + $array_key.'_date_end'=>dol_print_date($object->date_end, 'day'), |
|
| 128 | 128 | $array_key.'_note_private'=>$object->note_private, |
| 129 | 129 | $array_key.'_note_public'=>$object->note_public, |
| 130 | 130 | $array_key.'_public'=>$object->public, |
@@ -134,14 +134,14 @@ discard block |
||
| 134 | 134 | // Retrieve extrafields |
| 135 | 135 | if (is_array($object->array_options) && count($object->array_options)) |
| 136 | 136 | { |
| 137 | - $extrafieldkey=$object->element; |
|
| 137 | + $extrafieldkey = $object->element; |
|
| 138 | 138 | |
| 139 | 139 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 140 | 140 | $extrafields = new ExtraFields($this->db); |
| 141 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 141 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); |
|
| 142 | 142 | $object->fetch_optionals(); |
| 143 | 143 | |
| 144 | - $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 144 | + $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $resarray; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | * @param Translate $outputlangs Lang object to use for output |
| 155 | 155 | * @return array Return a substitution array |
| 156 | 156 | */ |
| 157 | - function get_substitutionarray_tasks($task,$outputlangs) |
|
| 157 | + function get_substitutionarray_tasks($task, $outputlangs) |
|
| 158 | 158 | { |
| 159 | 159 | global $conf; |
| 160 | 160 | |
@@ -169,8 +169,8 @@ discard block |
||
| 169 | 169 | 'task_duration'=>$task->duration, |
| 170 | 170 | 'task_progress'=>$task->progress, |
| 171 | 171 | 'task_public'=>$task->public, |
| 172 | - 'task_date_start'=>dol_print_date($task->date_start,'day'), |
|
| 173 | - 'task_date_end'=>dol_print_date($task->date_end,'day'), |
|
| 172 | + 'task_date_start'=>dol_print_date($task->date_start, 'day'), |
|
| 173 | + 'task_date_end'=>dol_print_date($task->date_end, 'day'), |
|
| 174 | 174 | 'task_note_private'=>$task->note_private, |
| 175 | 175 | 'task_note_public'=>$task->note_public |
| 176 | 176 | ); |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | * @param Translate $outputlangs Lang object to use for output |
| 184 | 184 | * @return array Return a substitution array |
| 185 | 185 | */ |
| 186 | - function get_substitutionarray_project_contacts($contact,$outputlangs) |
|
| 186 | + function get_substitutionarray_project_contacts($contact, $outputlangs) |
|
| 187 | 187 | { |
| 188 | 188 | global $conf; |
| 189 | 189 | |
@@ -206,13 +206,13 @@ discard block |
||
| 206 | 206 | * @param Translate $outputlangs Lang object to use for output |
| 207 | 207 | * @return array Return a substitution array |
| 208 | 208 | */ |
| 209 | - function get_substitutionarray_project_file($file,$outputlangs) |
|
| 209 | + function get_substitutionarray_project_file($file, $outputlangs) |
|
| 210 | 210 | { |
| 211 | 211 | global $conf; |
| 212 | 212 | |
| 213 | 213 | return array( |
| 214 | 214 | 'projfile_name'=>$file['name'], |
| 215 | - 'projfile_date'=>dol_print_date($file['date'],'day'), |
|
| 215 | + 'projfile_date'=>dol_print_date($file['date'], 'day'), |
|
| 216 | 216 | 'projfile_size'=>$file['size'] |
| 217 | 217 | ); |
| 218 | 218 | } |
@@ -224,17 +224,17 @@ discard block |
||
| 224 | 224 | * @param Translate $outputlangs Lang object to use for output |
| 225 | 225 | * @return array Return a substitution array |
| 226 | 226 | */ |
| 227 | - function get_substitutionarray_project_reference($refdetail,$outputlangs) |
|
| 227 | + function get_substitutionarray_project_reference($refdetail, $outputlangs) |
|
| 228 | 228 | { |
| 229 | 229 | global $conf; |
| 230 | 230 | |
| 231 | 231 | return array( |
| 232 | 232 | 'projref_type'=>$refdetail['type'], |
| 233 | 233 | 'projref_ref'=>$refdetail['ref'], |
| 234 | - 'projref_date'=>dol_print_date($refdetail['date'],'day'), |
|
| 234 | + 'projref_date'=>dol_print_date($refdetail['date'], 'day'), |
|
| 235 | 235 | 'projref_socname'=>$refdetail['socname'], |
| 236 | - 'projref_amountht'=>price($refdetail['amountht'],0,$outputlangs), |
|
| 237 | - 'projref_amountttc'=>price($refdetail['amountttc'],0,$outputlangs), |
|
| 236 | + 'projref_amountht'=>price($refdetail['amountht'], 0, $outputlangs), |
|
| 237 | + 'projref_amountttc'=>price($refdetail['amountttc'], 0, $outputlangs), |
|
| 238 | 238 | 'projref_status'=>$refdetail['status'] |
| 239 | 239 | ); |
| 240 | 240 | } |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @param Translate $outputlangs Lang object to use for output |
| 247 | 247 | * @return array Return a substitution array |
| 248 | 248 | */ |
| 249 | - function get_substitutionarray_tasksressource($taskressource,$outputlangs) |
|
| 249 | + function get_substitutionarray_tasksressource($taskressource, $outputlangs) |
|
| 250 | 250 | { |
| 251 | 251 | global $conf; |
| 252 | 252 | //dol_syslog(get_class($this).'::get_substitutionarray_tasksressource taskressource='.var_export($taskressource,true),LOG_DEBUG); |
@@ -268,14 +268,14 @@ discard block |
||
| 268 | 268 | * @param Translate $outputlangs Lang object to use for output |
| 269 | 269 | * @return array Return a substitution array |
| 270 | 270 | */ |
| 271 | - function get_substitutionarray_taskstime($tasktime,$outputlangs) |
|
| 271 | + function get_substitutionarray_taskstime($tasktime, $outputlangs) |
|
| 272 | 272 | { |
| 273 | 273 | global $conf; |
| 274 | 274 | |
| 275 | 275 | return array( |
| 276 | 276 | 'tasktime_rowid'=>$tasktime['rowid'], |
| 277 | - 'tasktime_task_date'=>dol_print_date($tasktime['task_date'],'day'), |
|
| 278 | - 'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'],'all'), |
|
| 277 | + 'tasktime_task_date'=>dol_print_date($tasktime['task_date'], 'day'), |
|
| 278 | + 'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'], 'all'), |
|
| 279 | 279 | 'tasktime_note'=>$tasktime['note'], |
| 280 | 280 | 'tasktime_fk_user'=>$tasktime['fk_user'], |
| 281 | 281 | 'tasktime_user_name'=>$tasktime['name'], |
@@ -291,13 +291,13 @@ discard block |
||
| 291 | 291 | * @param Translate $outputlangs Lang object to use for output |
| 292 | 292 | * @return array Return a substitution array |
| 293 | 293 | */ |
| 294 | - function get_substitutionarray_task_file($file,$outputlangs) |
|
| 294 | + function get_substitutionarray_task_file($file, $outputlangs) |
|
| 295 | 295 | { |
| 296 | 296 | global $conf; |
| 297 | 297 | |
| 298 | 298 | return array( |
| 299 | 299 | 'tasksfile_name'=>$file['name'], |
| 300 | - 'tasksfile_date'=>dol_print_date($file['date'],'day'), |
|
| 300 | + 'tasksfile_date'=>dol_print_date($file['date'], 'day'), |
|
| 301 | 301 | 'tasksfile_size'=>$file['size'] |
| 302 | 302 | ); |
| 303 | 303 | } |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | */ |
| 312 | 312 | function info($langs) |
| 313 | 313 | { |
| 314 | - global $conf,$langs; |
|
| 314 | + global $conf, $langs; |
|
| 315 | 315 | |
| 316 | 316 | $langs->load("companies"); |
| 317 | 317 | $langs->load("errors"); |
@@ -319,75 +319,75 @@ discard block |
||
| 319 | 319 | $form = new Form($this->db); |
| 320 | 320 | |
| 321 | 321 | $texte = $this->description.".<br>\n"; |
| 322 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 323 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 324 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 325 | - $texte.= '<input type="hidden" name="param1" value="PROJECT_TASK_ADDON_PDF_ODT_PATH">'; |
|
| 326 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
| 322 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 323 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 324 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 325 | + $texte .= '<input type="hidden" name="param1" value="PROJECT_TASK_ADDON_PDF_ODT_PATH">'; |
|
| 326 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
| 327 | 327 | |
| 328 | 328 | // List of directories area |
| 329 | - $texte.= '<tr><td>'; |
|
| 330 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
| 331 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH))); |
|
| 332 | - $listoffiles=array(); |
|
| 333 | - foreach($listofdir as $key=>$tmpdir) |
|
| 329 | + $texte .= '<tr><td>'; |
|
| 330 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
| 331 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH))); |
|
| 332 | + $listoffiles = array(); |
|
| 333 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 334 | 334 | { |
| 335 | - $tmpdir=trim($tmpdir); |
|
| 336 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 337 | - if (! $tmpdir) { |
|
| 335 | + $tmpdir = trim($tmpdir); |
|
| 336 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 337 | + if (!$tmpdir) { |
|
| 338 | 338 | unset($listofdir[$key]); continue; |
| 339 | 339 | } |
| 340 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 340 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 341 | 341 | else |
| 342 | 342 | { |
| 343 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
| 344 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 343 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
| 344 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 347 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 348 | 348 | // Add list of substitution keys |
| 349 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 350 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 351 | - |
|
| 352 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
| 353 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 354 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
| 355 | - $texte.=$conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH; |
|
| 356 | - $texte.= '</textarea>'; |
|
| 357 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 358 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 359 | - $texte.= '<br></div></div>'; |
|
| 349 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 350 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 351 | + |
|
| 352 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
| 353 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 354 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
| 355 | + $texte .= $conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH; |
|
| 356 | + $texte .= '</textarea>'; |
|
| 357 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 358 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 359 | + $texte .= '<br></div></div>'; |
|
| 360 | 360 | |
| 361 | 361 | // Scan directories |
| 362 | - $nbofiles=count($listoffiles); |
|
| 363 | - if (! empty($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)) |
|
| 362 | + $nbofiles = count($listoffiles); |
|
| 363 | + if (!empty($conf->global->PROJECT_TASK_ADDON_PDF_ODT_PATH)) |
|
| 364 | 364 | { |
| 365 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 365 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 366 | 366 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
| 367 | - $texte.=$nbofiles; |
|
| 367 | + $texte .= $nbofiles; |
|
| 368 | 368 | //$texte.=$nbofiles?'</a>':''; |
| 369 | - $texte.='</b>'; |
|
| 369 | + $texte .= '</b>'; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | if ($nbofiles) |
| 373 | 373 | { |
| 374 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 375 | - foreach($listoffiles as $file) |
|
| 374 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 375 | + foreach ($listoffiles as $file) |
|
| 376 | 376 | { |
| 377 | - $texte.=$file['name'].'<br>'; |
|
| 377 | + $texte .= $file['name'].'<br>'; |
|
| 378 | 378 | } |
| 379 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
| 379 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - $texte.= '</td>'; |
|
| 382 | + $texte .= '</td>'; |
|
| 383 | 383 | |
| 384 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 385 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 386 | - $texte.= '</td>'; |
|
| 387 | - $texte.= '</tr>'; |
|
| 384 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 385 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 386 | + $texte .= '</td>'; |
|
| 387 | + $texte .= '</tr>'; |
|
| 388 | 388 | |
| 389 | - $texte.= '</table>'; |
|
| 390 | - $texte.= '</form>'; |
|
| 389 | + $texte .= '</table>'; |
|
| 390 | + $texte .= '</form>'; |
|
| 391 | 391 | |
| 392 | 392 | return $texte; |
| 393 | 393 | } |
@@ -400,9 +400,9 @@ discard block |
||
| 400 | 400 | * @param string $srctemplatepath Full path of source filename for generator using a template file |
| 401 | 401 | * @return int 1 if OK, <=0 if KO |
| 402 | 402 | */ |
| 403 | - function write_file($object,$outputlangs,$srctemplatepath) |
|
| 403 | + function write_file($object, $outputlangs, $srctemplatepath) |
|
| 404 | 404 | { |
| 405 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
| 405 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
| 406 | 406 | |
| 407 | 407 | if (empty($srctemplatepath)) |
| 408 | 408 | { |
@@ -410,9 +410,9 @@ discard block |
||
| 410 | 410 | return -1; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
| 414 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 415 | - $outputlangs->charset_output='UTF-8'; |
|
| 413 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
| 414 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 415 | + $outputlangs->charset_output = 'UTF-8'; |
|
| 416 | 416 | |
| 417 | 417 | $outputlangs->load("main"); |
| 418 | 418 | $outputlangs->load("dict"); |
@@ -422,32 +422,32 @@ discard block |
||
| 422 | 422 | if ($conf->projet->dir_output) |
| 423 | 423 | { |
| 424 | 424 | // If $object is id instead of object |
| 425 | - if (! is_object($object)) |
|
| 425 | + if (!is_object($object)) |
|
| 426 | 426 | { |
| 427 | 427 | $id = $object; |
| 428 | 428 | $object = new Task($this->db); |
| 429 | - $result=$object->fetch($id); |
|
| 429 | + $result = $object->fetch($id); |
|
| 430 | 430 | if ($result < 0) |
| 431 | 431 | { |
| 432 | - dol_print_error($this->db,$object->error); |
|
| 432 | + dol_print_error($this->db, $object->error); |
|
| 433 | 433 | return -1; |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | - $project= new Project($this->db); |
|
| 436 | + $project = new Project($this->db); |
|
| 437 | 437 | $project->fetch($object->fk_project); |
| 438 | 438 | $project->fetch_thirdparty(); |
| 439 | 439 | |
| 440 | - $dir = $conf->projet->dir_output. "/" . $project->ref. "/"; |
|
| 440 | + $dir = $conf->projet->dir_output."/".$project->ref."/"; |
|
| 441 | 441 | $objectref = dol_sanitizeFileName($object->ref); |
| 442 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
| 443 | - $file = $dir . "/" . $objectref . ".odt"; |
|
| 442 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
| 443 | + $file = $dir."/".$objectref.".odt"; |
|
| 444 | 444 | |
| 445 | - if (! file_exists($dir)) |
|
| 445 | + if (!file_exists($dir)) |
|
| 446 | 446 | { |
| 447 | 447 | print '$dir'.$dir; |
| 448 | 448 | if (dol_mkdir($dir) < 0) |
| 449 | 449 | { |
| 450 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 450 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 451 | 451 | return -1; |
| 452 | 452 | } |
| 453 | 453 | } |
@@ -456,13 +456,13 @@ discard block |
||
| 456 | 456 | if (file_exists($dir)) |
| 457 | 457 | { |
| 458 | 458 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
| 459 | - $newfile=basename($srctemplatepath); |
|
| 460 | - $newfiletmp=preg_replace('/\.(ods|odt)/i','',$newfile); |
|
| 461 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
| 462 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
| 463 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
| 459 | + $newfile = basename($srctemplatepath); |
|
| 460 | + $newfiletmp = preg_replace('/\.(ods|odt)/i', '', $newfile); |
|
| 461 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
| 462 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
| 463 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
| 464 | 464 | //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
| 465 | - $file=$dir.'/'.$newfiletmp.'.odt'; |
|
| 465 | + $file = $dir.'/'.$newfiletmp.'.odt'; |
|
| 466 | 466 | //print "newdir=".$dir; |
| 467 | 467 | //print "newfile=".$newfile; |
| 468 | 468 | //print "file=".$file; |
@@ -470,17 +470,17 @@ discard block |
||
| 470 | 470 | |
| 471 | 471 | dol_mkdir($conf->projet->dir_temp); |
| 472 | 472 | |
| 473 | - $socobject=$project->thirdparty; |
|
| 473 | + $socobject = $project->thirdparty; |
|
| 474 | 474 | |
| 475 | 475 | // Make substitution |
| 476 | - $substitutionarray=array( |
|
| 476 | + $substitutionarray = array( |
|
| 477 | 477 | '__FROM_NAME__' => $this->emetteur->name, |
| 478 | 478 | '__FROM_EMAIL__' => $this->emetteur->email, |
| 479 | 479 | ); |
| 480 | 480 | complete_substitutions_array($substitutionarray, $langs, $object); |
| 481 | 481 | // Call the ODTSubstitution hook |
| 482 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 483 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 482 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 483 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 484 | 484 | |
| 485 | 485 | // Open and load template |
| 486 | 486 | require_once ODTPHP_PATH.'odf.php'; |
@@ -489,15 +489,15 @@ discard block |
||
| 489 | 489 | $srctemplatepath, |
| 490 | 490 | array( |
| 491 | 491 | 'PATH_TO_TMP' => $conf->projet->dir_temp, |
| 492 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 492 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 493 | 493 | 'DELIMITER_LEFT' => '{', |
| 494 | 494 | 'DELIMITER_RIGHT' => '}' |
| 495 | 495 | ) |
| 496 | 496 | ); |
| 497 | 497 | } |
| 498 | - catch(Exception $e) |
|
| 498 | + catch (Exception $e) |
|
| 499 | 499 | { |
| 500 | - $this->error=$e->getMessage(); |
|
| 500 | + $this->error = $e->getMessage(); |
|
| 501 | 501 | return -1; |
| 502 | 502 | } |
| 503 | 503 | // After construction $odfHandler->contentXml contains content and |
@@ -510,19 +510,19 @@ discard block |
||
| 510 | 510 | // Define substitution array |
| 511 | 511 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
| 512 | 512 | $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
| 513 | - $array_objet=$this->get_substitutionarray_object($project,$outputlangs); |
|
| 514 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
| 515 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
| 516 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
| 517 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
| 513 | + $array_objet = $this->get_substitutionarray_object($project, $outputlangs); |
|
| 514 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
| 515 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
| 516 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
| 517 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
| 518 | 518 | |
| 519 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other); |
|
| 519 | + $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other); |
|
| 520 | 520 | complete_substitutions_array($tmparray, $outputlangs, $object); |
| 521 | 521 | |
| 522 | - foreach($tmparray as $key=>$value) |
|
| 522 | + foreach ($tmparray as $key=>$value) |
|
| 523 | 523 | { |
| 524 | 524 | try { |
| 525 | - if (preg_match('/logo$/',$key)) // Image |
|
| 525 | + if (preg_match('/logo$/', $key)) // Image |
|
| 526 | 526 | { |
| 527 | 527 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
| 528 | 528 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 533 | 533 | } |
| 534 | 534 | } |
| 535 | - catch(OdfException $e) |
|
| 535 | + catch (OdfException $e) |
|
| 536 | 536 | { |
| 537 | 537 | } |
| 538 | 538 | } |
@@ -541,33 +541,33 @@ discard block |
||
| 541 | 541 | try |
| 542 | 542 | { |
| 543 | 543 | // Security check |
| 544 | - $socid=0; |
|
| 544 | + $socid = 0; |
|
| 545 | 545 | if (!empty($project->fk_soc)) $socid = $project->fk_soc; |
| 546 | 546 | |
| 547 | - $tmparray=$this->get_substitutionarray_tasks($object,$outputlangs); |
|
| 547 | + $tmparray = $this->get_substitutionarray_tasks($object, $outputlangs); |
|
| 548 | 548 | complete_substitutions_array($tmparray, $outputlangs, $object); |
| 549 | - foreach($tmparray as $key => $val) |
|
| 549 | + foreach ($tmparray as $key => $val) |
|
| 550 | 550 | { |
| 551 | 551 | try |
| 552 | 552 | { |
| 553 | 553 | $odfHandler->setVars($key, $val, true, 'UTF-8'); |
| 554 | 554 | } |
| 555 | - catch(OdfException $e) |
|
| 555 | + catch (OdfException $e) |
|
| 556 | 556 | { |
| 557 | 557 | } |
| 558 | - catch(SegmentException $e) |
|
| 558 | + catch (SegmentException $e) |
|
| 559 | 559 | { |
| 560 | 560 | } |
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | // Replace tags of lines for contacts task |
| 564 | - $sourcearray=array('internal','external'); |
|
| 565 | - $contact_arrray=array(); |
|
| 564 | + $sourcearray = array('internal', 'external'); |
|
| 565 | + $contact_arrray = array(); |
|
| 566 | 566 | foreach ($sourcearray as $source) { |
| 567 | - $contact_temp=$object->liste_contact(-1,$source); |
|
| 567 | + $contact_temp = $object->liste_contact(-1, $source); |
|
| 568 | 568 | if ((is_array($contact_temp) && count($contact_temp) > 0)) |
| 569 | 569 | { |
| 570 | - $contact_arrray=array_merge($contact_arrray,$contact_temp); |
|
| 570 | + $contact_arrray = array_merge($contact_arrray, $contact_temp); |
|
| 571 | 571 | } |
| 572 | 572 | } |
| 573 | 573 | if ((is_array($contact_arrray) && count($contact_arrray) > 0)) |
@@ -576,32 +576,32 @@ discard block |
||
| 576 | 576 | |
| 577 | 577 | foreach ($contact_arrray as $contact) |
| 578 | 578 | { |
| 579 | - if ($contact['source']=='internal') { |
|
| 580 | - $objectdetail=new User($this->db); |
|
| 579 | + if ($contact['source'] == 'internal') { |
|
| 580 | + $objectdetail = new User($this->db); |
|
| 581 | 581 | $objectdetail->fetch($contact['id']); |
| 582 | - $contact['socname']=$mysoc->name; |
|
| 583 | - } elseif ($contact['source']=='external') { |
|
| 584 | - $objectdetail=new Contact($this->db); |
|
| 582 | + $contact['socname'] = $mysoc->name; |
|
| 583 | + } elseif ($contact['source'] == 'external') { |
|
| 584 | + $objectdetail = new Contact($this->db); |
|
| 585 | 585 | $objectdetail->fetch($contact['id']); |
| 586 | 586 | |
| 587 | - $soc=new Societe($this->db); |
|
| 587 | + $soc = new Societe($this->db); |
|
| 588 | 588 | $soc->fetch($contact['socid']); |
| 589 | - $contact['socname']=$soc->name; |
|
| 589 | + $contact['socname'] = $soc->name; |
|
| 590 | 590 | } |
| 591 | - $contact['fullname']=$objectdetail->getFullName($outputlangs,1); |
|
| 591 | + $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1); |
|
| 592 | 592 | |
| 593 | - $tmparray=$this->get_substitutionarray_tasksressource($contact,$outputlangs); |
|
| 593 | + $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs); |
|
| 594 | 594 | |
| 595 | - foreach($tmparray as $key => $val) |
|
| 595 | + foreach ($tmparray as $key => $val) |
|
| 596 | 596 | { |
| 597 | 597 | try |
| 598 | 598 | { |
| 599 | 599 | $listlinestaskres->setVars($key, $val, true, 'UTF-8'); |
| 600 | 600 | } |
| 601 | - catch(OdfException $e) |
|
| 601 | + catch (OdfException $e) |
|
| 602 | 602 | { |
| 603 | 603 | } |
| 604 | - catch(SegmentException $e) |
|
| 604 | + catch (SegmentException $e) |
|
| 605 | 605 | { |
| 606 | 606 | } |
| 607 | 607 | } |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | |
| 613 | 613 | // Time ressources |
| 614 | 614 | $sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note"; |
| 615 | - $sql.= ", u.lastname, u.firstname"; |
|
| 615 | + $sql .= ", u.lastname, u.firstname"; |
|
| 616 | 616 | $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; |
| 617 | 617 | $sql .= " , ".MAIN_DB_PREFIX."user as u"; |
| 618 | 618 | $sql .= " WHERE t.fk_task =".$object->id; |
@@ -630,26 +630,26 @@ discard block |
||
| 630 | 630 | { |
| 631 | 631 | $row = $this->db->fetch_array($resql); |
| 632 | 632 | if (!empty($row['fk_user'])) { |
| 633 | - $objectdetail=new User($this->db); |
|
| 633 | + $objectdetail = new User($this->db); |
|
| 634 | 634 | $objectdetail->fetch($row['fk_user']); |
| 635 | 635 | // TODO Use a cache to aoid fetch for same user |
| 636 | - $row['fullcivname']=$objectdetail->getFullName($outputlangs,1); |
|
| 636 | + $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1); |
|
| 637 | 637 | } else { |
| 638 | - $row['fullcivname']=''; |
|
| 638 | + $row['fullcivname'] = ''; |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - $tmparray=$this->get_substitutionarray_taskstime($row,$outputlangs); |
|
| 641 | + $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs); |
|
| 642 | 642 | |
| 643 | - foreach($tmparray as $key => $val) |
|
| 643 | + foreach ($tmparray as $key => $val) |
|
| 644 | 644 | { |
| 645 | 645 | try |
| 646 | 646 | { |
| 647 | 647 | $listlinestasktime->setVars($key, $val, true, 'UTF-8'); |
| 648 | 648 | } |
| 649 | - catch(OdfException $e) |
|
| 649 | + catch (OdfException $e) |
|
| 650 | 650 | { |
| 651 | 651 | } |
| 652 | - catch(SegmentException $e) |
|
| 652 | + catch (SegmentException $e) |
|
| 653 | 653 | { |
| 654 | 654 | } |
| 655 | 655 | } |
@@ -666,23 +666,23 @@ discard block |
||
| 666 | 666 | $listtasksfiles = $odfHandler->setSegment('tasksfiles'); |
| 667 | 667 | |
| 668 | 668 | $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($object->ref); |
| 669 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$','name',SORT_ASC,1); |
|
| 669 | + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); |
|
| 670 | 670 | |
| 671 | 671 | |
| 672 | 672 | foreach ($filearray as $filedetail) |
| 673 | 673 | { |
| 674 | - $tmparray=$this->get_substitutionarray_task_file($filedetail,$outputlangs); |
|
| 674 | + $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs); |
|
| 675 | 675 | //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true)); |
| 676 | - foreach($tmparray as $key => $val) |
|
| 676 | + foreach ($tmparray as $key => $val) |
|
| 677 | 677 | { |
| 678 | 678 | try |
| 679 | 679 | { |
| 680 | 680 | $listtasksfiles->setVars($key, $val, true, 'UTF-8'); |
| 681 | 681 | } |
| 682 | - catch(OdfException $e) |
|
| 682 | + catch (OdfException $e) |
|
| 683 | 683 | { |
| 684 | 684 | } |
| 685 | - catch(SegmentException $e) |
|
| 685 | + catch (SegmentException $e) |
|
| 686 | 686 | { |
| 687 | 687 | } |
| 688 | 688 | } |
@@ -693,9 +693,9 @@ discard block |
||
| 693 | 693 | $odfHandler->mergeSegment($listtasksfiles); |
| 694 | 694 | |
| 695 | 695 | } |
| 696 | - catch(OdfException $e) |
|
| 696 | + catch (OdfException $e) |
|
| 697 | 697 | { |
| 698 | - $this->error=$e->getMessage(); |
|
| 698 | + $this->error = $e->getMessage(); |
|
| 699 | 699 | dol_syslog($this->error, LOG_WARNING); |
| 700 | 700 | return -1; |
| 701 | 701 | } |
@@ -708,24 +708,24 @@ discard block |
||
| 708 | 708 | $listlines = $odfHandler->setSegment('projectfiles'); |
| 709 | 709 | |
| 710 | 710 | $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref); |
| 711 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$','name',SORT_ASC,1); |
|
| 711 | + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); |
|
| 712 | 712 | |
| 713 | 713 | |
| 714 | 714 | foreach ($filearray as $filedetail) |
| 715 | 715 | { |
| 716 | 716 | //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true)); |
| 717 | - $tmparray=$this->get_substitutionarray_project_file($filedetail,$outputlangs); |
|
| 717 | + $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs); |
|
| 718 | 718 | |
| 719 | - foreach($tmparray as $key => $val) |
|
| 719 | + foreach ($tmparray as $key => $val) |
|
| 720 | 720 | { |
| 721 | 721 | try |
| 722 | 722 | { |
| 723 | 723 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 724 | 724 | } |
| 725 | - catch(OdfException $e) |
|
| 725 | + catch (OdfException $e) |
|
| 726 | 726 | { |
| 727 | 727 | } |
| 728 | - catch(SegmentException $e) |
|
| 728 | + catch (SegmentException $e) |
|
| 729 | 729 | { |
| 730 | 730 | } |
| 731 | 731 | } |
@@ -733,21 +733,21 @@ discard block |
||
| 733 | 733 | } |
| 734 | 734 | $odfHandler->mergeSegment($listlines); |
| 735 | 735 | } |
| 736 | - catch(OdfException $e) |
|
| 736 | + catch (OdfException $e) |
|
| 737 | 737 | { |
| 738 | - $this->error=$e->getMessage(); |
|
| 738 | + $this->error = $e->getMessage(); |
|
| 739 | 739 | dol_syslog($this->error, LOG_WARNING); |
| 740 | 740 | return -1; |
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | // Replace tags of lines for contacts |
| 744 | - $sourcearray=array('internal','external'); |
|
| 745 | - $contact_arrray=array(); |
|
| 744 | + $sourcearray = array('internal', 'external'); |
|
| 745 | + $contact_arrray = array(); |
|
| 746 | 746 | foreach ($sourcearray as $source) { |
| 747 | - $contact_temp=$project->liste_contact(-1,$source); |
|
| 747 | + $contact_temp = $project->liste_contact(-1, $source); |
|
| 748 | 748 | if ((is_array($contact_temp) && count($contact_temp) > 0)) |
| 749 | 749 | { |
| 750 | - $contact_arrray=array_merge($contact_arrray,$contact_temp); |
|
| 750 | + $contact_arrray = array_merge($contact_arrray, $contact_temp); |
|
| 751 | 751 | } |
| 752 | 752 | } |
| 753 | 753 | if ((is_array($contact_arrray) && count($contact_arrray) > 0)) |
@@ -758,32 +758,32 @@ discard block |
||
| 758 | 758 | |
| 759 | 759 | foreach ($contact_arrray as $contact) |
| 760 | 760 | { |
| 761 | - if ($contact['source']=='internal') { |
|
| 762 | - $objectdetail=new User($this->db); |
|
| 761 | + if ($contact['source'] == 'internal') { |
|
| 762 | + $objectdetail = new User($this->db); |
|
| 763 | 763 | $objectdetail->fetch($contact['id']); |
| 764 | - $contact['socname']=$mysoc->name; |
|
| 765 | - } elseif ($contact['source']=='external') { |
|
| 766 | - $objectdetail=new Contact($this->db); |
|
| 764 | + $contact['socname'] = $mysoc->name; |
|
| 765 | + } elseif ($contact['source'] == 'external') { |
|
| 766 | + $objectdetail = new Contact($this->db); |
|
| 767 | 767 | $objectdetail->fetch($contact['id']); |
| 768 | 768 | |
| 769 | - $soc=new Societe($this->db); |
|
| 769 | + $soc = new Societe($this->db); |
|
| 770 | 770 | $soc->fetch($contact['socid']); |
| 771 | - $contact['socname']=$soc->name; |
|
| 771 | + $contact['socname'] = $soc->name; |
|
| 772 | 772 | } |
| 773 | - $contact['fullname']=$objectdetail->getFullName($outputlangs,1); |
|
| 773 | + $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1); |
|
| 774 | 774 | |
| 775 | - $tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs); |
|
| 775 | + $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs); |
|
| 776 | 776 | |
| 777 | - foreach($tmparray as $key => $val) |
|
| 777 | + foreach ($tmparray as $key => $val) |
|
| 778 | 778 | { |
| 779 | 779 | try |
| 780 | 780 | { |
| 781 | 781 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 782 | 782 | } |
| 783 | - catch(OdfException $e) |
|
| 783 | + catch (OdfException $e) |
|
| 784 | 784 | { |
| 785 | 785 | } |
| 786 | - catch(SegmentException $e) |
|
| 786 | + catch (SegmentException $e) |
|
| 787 | 787 | { |
| 788 | 788 | } |
| 789 | 789 | } |
@@ -791,9 +791,9 @@ discard block |
||
| 791 | 791 | } |
| 792 | 792 | $odfHandler->mergeSegment($listlines); |
| 793 | 793 | } |
| 794 | - catch(OdfException $e) |
|
| 794 | + catch (OdfException $e) |
|
| 795 | 795 | { |
| 796 | - $this->error=$e->getMessage(); |
|
| 796 | + $this->error = $e->getMessage(); |
|
| 797 | 797 | dol_syslog($this->error, LOG_WARNING); |
| 798 | 798 | return -1; |
| 799 | 799 | } |
@@ -801,42 +801,42 @@ discard block |
||
| 801 | 801 | |
| 802 | 802 | |
| 803 | 803 | // Call the beforeODTSave hook |
| 804 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 805 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 804 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 805 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 806 | 806 | |
| 807 | 807 | |
| 808 | 808 | // Write new file |
| 809 | 809 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
| 810 | 810 | try { |
| 811 | 811 | $odfHandler->exportAsAttachedPDF($file); |
| 812 | - }catch (Exception $e){ |
|
| 813 | - $this->error=$e->getMessage(); |
|
| 812 | + } catch (Exception $e) { |
|
| 813 | + $this->error = $e->getMessage(); |
|
| 814 | 814 | return -1; |
| 815 | 815 | } |
| 816 | 816 | } |
| 817 | 817 | else { |
| 818 | 818 | try { |
| 819 | 819 | $odfHandler->saveToDisk($file); |
| 820 | - }catch (Exception $e){ |
|
| 821 | - $this->error=$e->getMessage(); |
|
| 820 | + } catch (Exception $e) { |
|
| 821 | + $this->error = $e->getMessage(); |
|
| 822 | 822 | return -1; |
| 823 | 823 | } |
| 824 | 824 | } |
| 825 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 826 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 825 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 826 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 827 | 827 | |
| 828 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 828 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 829 | 829 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 830 | 830 | |
| 831 | - $odfHandler=null; // Destroy object |
|
| 831 | + $odfHandler = null; // Destroy object |
|
| 832 | 832 | |
| 833 | 833 | $this->result = array('fullpath'=>$file); |
| 834 | 834 | |
| 835 | - return 1; // Success |
|
| 835 | + return 1; // Success |
|
| 836 | 836 | } |
| 837 | 837 | else |
| 838 | 838 | { |
| 839 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 839 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 840 | 840 | return -1; |
| 841 | 841 | } |
| 842 | 842 | } |
@@ -36,16 +36,16 @@ discard block |
||
| 36 | 36 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 37 | 37 | require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php'; |
| 38 | 38 | require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
| 39 | -if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
| 40 | -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 41 | -if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; |
|
| 42 | -if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
| 43 | -if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
| 44 | -if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
| 45 | -if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
| 46 | -if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
| 47 | -if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; |
|
| 48 | -if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
| 39 | +if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
| 40 | +if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
| 41 | +if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; |
|
| 42 | +if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
| 43 | +if (!empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
| 44 | +if (!empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
| 45 | +if (!empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
| 46 | +if (!empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
| 47 | +if (!empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; |
|
| 48 | +if (!empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
|
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -53,9 +53,9 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | class doc_generic_project_odt extends ModelePDFProjects |
| 55 | 55 | { |
| 56 | - var $emetteur; // Objet societe qui emet |
|
| 56 | + var $emetteur; // Objet societe qui emet |
|
| 57 | 57 | |
| 58 | - var $phpmin = array(5,2,0); // Minimum version of PHP required by module |
|
| 58 | + var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module |
|
| 59 | 59 | var $version = 'dolibarr'; |
| 60 | 60 | |
| 61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function __construct($db) |
| 68 | 68 | { |
| 69 | - global $conf,$langs,$mysoc; |
|
| 69 | + global $conf, $langs, $mysoc; |
|
| 70 | 70 | |
| 71 | 71 | $langs->load("main"); |
| 72 | 72 | $langs->load("companies"); |
@@ -74,32 +74,32 @@ discard block |
||
| 74 | 74 | $this->db = $db; |
| 75 | 75 | $this->name = "ODT templates"; |
| 76 | 76 | $this->description = $langs->trans("DocumentModelOdt"); |
| 77 | - $this->scandir = 'PROJECT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 77 | + $this->scandir = 'PROJECT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 78 | 78 | |
| 79 | 79 | // Dimension page pour format A4 |
| 80 | 80 | $this->type = 'odt'; |
| 81 | 81 | $this->page_largeur = 0; |
| 82 | 82 | $this->page_hauteur = 0; |
| 83 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
| 84 | - $this->marge_gauche=0; |
|
| 85 | - $this->marge_droite=0; |
|
| 86 | - $this->marge_haute=0; |
|
| 87 | - $this->marge_basse=0; |
|
| 88 | - |
|
| 89 | - $this->option_logo = 1; // Affiche logo |
|
| 90 | - $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION |
|
| 91 | - $this->option_modereg = 0; // Affiche mode reglement |
|
| 92 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
| 93 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 94 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 95 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 96 | - $this->option_credit_note = 0; // Support credit notes |
|
| 97 | - $this->option_freetext = 1; // Support add of a personalised text |
|
| 98 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 83 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
| 84 | + $this->marge_gauche = 0; |
|
| 85 | + $this->marge_droite = 0; |
|
| 86 | + $this->marge_haute = 0; |
|
| 87 | + $this->marge_basse = 0; |
|
| 88 | + |
|
| 89 | + $this->option_logo = 1; // Affiche logo |
|
| 90 | + $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION |
|
| 91 | + $this->option_modereg = 0; // Affiche mode reglement |
|
| 92 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
| 93 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 94 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 95 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 96 | + $this->option_credit_note = 0; // Support credit notes |
|
| 97 | + $this->option_freetext = 1; // Support add of a personalised text |
|
| 98 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 99 | 99 | |
| 100 | 100 | // Recupere emetteur |
| 101 | - $this->emetteur=$mysoc; |
|
| 102 | - if (! $this->emetteur->pays_code) $this->emetteur->pays_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
| 101 | + $this->emetteur = $mysoc; |
|
| 102 | + if (!$this->emetteur->pays_code) $this->emetteur->pays_code = substr($langs->defaultlang, -2); // Par defaut, si n'etait pas defini |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
@@ -111,19 +111,19 @@ discard block |
||
| 111 | 111 | * @param string $array_key Name of the key for return array |
| 112 | 112 | * @return array Array of substitution |
| 113 | 113 | */ |
| 114 | - function get_substitutionarray_object($object,$outputlangs,$array_key='object') |
|
| 114 | + function get_substitutionarray_object($object, $outputlangs, $array_key = 'object') |
|
| 115 | 115 | { |
| 116 | 116 | global $conf; |
| 117 | 117 | |
| 118 | - $resarray=array( |
|
| 118 | + $resarray = array( |
|
| 119 | 119 | $array_key.'_id'=>$object->id, |
| 120 | 120 | $array_key.'_ref'=>$object->ref, |
| 121 | 121 | $array_key.'_title'=>$object->title, |
| 122 | 122 | $array_key.'_description'=>$object->description, |
| 123 | - $array_key.'_date_creation'=>dol_print_date($object->date_c,'day'), |
|
| 124 | - $array_key.'_date_modification'=>dol_print_date($object->date_m,'day'), |
|
| 125 | - $array_key.'_date_start'=>dol_print_date($object->date_start,'day'), |
|
| 126 | - $array_key.'_date_end'=>dol_print_date($object->date_end,'day'), |
|
| 123 | + $array_key.'_date_creation'=>dol_print_date($object->date_c, 'day'), |
|
| 124 | + $array_key.'_date_modification'=>dol_print_date($object->date_m, 'day'), |
|
| 125 | + $array_key.'_date_start'=>dol_print_date($object->date_start, 'day'), |
|
| 126 | + $array_key.'_date_end'=>dol_print_date($object->date_end, 'day'), |
|
| 127 | 127 | $array_key.'_note_private'=>$object->note_private, |
| 128 | 128 | $array_key.'_note_public'=>$object->note_public, |
| 129 | 129 | $array_key.'_public'=>$object->public, |
@@ -131,14 +131,14 @@ discard block |
||
| 131 | 131 | ); |
| 132 | 132 | |
| 133 | 133 | // Retrieve extrafields |
| 134 | - $extrafieldkey=$object->element; |
|
| 134 | + $extrafieldkey = $object->element; |
|
| 135 | 135 | |
| 136 | 136 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 137 | 137 | $extrafields = new ExtraFields($this->db); |
| 138 | - $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey,true); |
|
| 138 | + $extralabels = $extrafields->fetch_name_optionals_label($extrafieldkey, true); |
|
| 139 | 139 | $object->fetch_optionals(); |
| 140 | 140 | |
| 141 | - $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key,$outputlangs); |
|
| 141 | + $resarray = $this->fill_substitutionarray_with_extrafields($object, $resarray, $extrafields, $array_key, $outputlangs); |
|
| 142 | 142 | |
| 143 | 143 | return $resarray; |
| 144 | 144 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param Translate $outputlangs Lang object to use for output |
| 151 | 151 | * @return array Return a substitution array |
| 152 | 152 | */ |
| 153 | - function get_substitutionarray_tasks($task,$outputlangs) |
|
| 153 | + function get_substitutionarray_tasks($task, $outputlangs) |
|
| 154 | 154 | { |
| 155 | 155 | global $conf; |
| 156 | 156 | |
@@ -165,8 +165,8 @@ discard block |
||
| 165 | 165 | 'task_duration'=>$task->duration, |
| 166 | 166 | 'task_progress'=>$task->progress, |
| 167 | 167 | 'task_public'=>$task->public, |
| 168 | - 'task_date_start'=>dol_print_date($task->date_start,'day'), |
|
| 169 | - 'task_date_end'=>dol_print_date($task->date_end,'day'), |
|
| 168 | + 'task_date_start'=>dol_print_date($task->date_start, 'day'), |
|
| 169 | + 'task_date_end'=>dol_print_date($task->date_end, 'day'), |
|
| 170 | 170 | 'task_note_private'=>$task->note_private, |
| 171 | 171 | 'task_note_public'=>$task->note_public |
| 172 | 172 | ); |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | * @param Translate $outputlangs Lang object to use for output |
| 180 | 180 | * @return array Return a substitution array |
| 181 | 181 | */ |
| 182 | - function get_substitutionarray_project_contacts($contact,$outputlangs) |
|
| 182 | + function get_substitutionarray_project_contacts($contact, $outputlangs) |
|
| 183 | 183 | { |
| 184 | 184 | global $conf; |
| 185 | - $pc='projcontacts_'; // prefix to avoid typos |
|
| 185 | + $pc = 'projcontacts_'; // prefix to avoid typos |
|
| 186 | 186 | |
| 187 | 187 | $ret = array( |
| 188 | 188 | $pc.'id'=>$contact['id'], |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $pc.'email'=>$contact['email'] |
| 197 | 197 | ); |
| 198 | 198 | |
| 199 | - if ($contact['source']=='external') { |
|
| 199 | + if ($contact['source'] == 'external') { |
|
| 200 | 200 | $ret[$pc.'isInternal'] = ''; // not internal |
| 201 | 201 | |
| 202 | 202 | $ct = new Contact($this->db); |
@@ -207,15 +207,15 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | // fetch external user extrafields |
| 209 | 209 | require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); |
| 210 | - $extrafields=new ExtraFields($this->db); |
|
| 211 | - $extralabels=$extrafields->fetch_name_optionals_label($ct->table_element, true); |
|
| 210 | + $extrafields = new ExtraFields($this->db); |
|
| 211 | + $extralabels = $extrafields->fetch_name_optionals_label($ct->table_element, true); |
|
| 212 | 212 | $extrafields_num = $ct->fetch_optionals(); |
| 213 | 213 | //dol_syslog(get_class($this)."::get_substitutionarray_project_contacts: ===== Number of Extrafields found: ".$extrafields_num, LOG_DEBUG); |
| 214 | - foreach($ct->array_options as $efkey => $efval) { |
|
| 214 | + foreach ($ct->array_options as $efkey => $efval) { |
|
| 215 | 215 | dol_syslog(get_class($this)."::get_substitutionarray_project_contacts: +++++ Extrafield ".$efkey." => ".$efval, LOG_DEBUG); |
| 216 | 216 | $ret[$pc.$efkey] = $efval; // add nothing else because it already comes as 'options_XX' |
| 217 | 217 | } |
| 218 | - } elseif ($contact['source']=='internal') { |
|
| 218 | + } elseif ($contact['source'] == 'internal') { |
|
| 219 | 219 | $ret[$pc.'isInternal'] = '1'; // this is an internal user |
| 220 | 220 | |
| 221 | 221 | $ct = new User($this->db); |
@@ -235,13 +235,13 @@ discard block |
||
| 235 | 235 | * @param Translate $outputlangs Lang object to use for output |
| 236 | 236 | * @return array Return a substitution array |
| 237 | 237 | */ |
| 238 | - function get_substitutionarray_project_file($file,$outputlangs) |
|
| 238 | + function get_substitutionarray_project_file($file, $outputlangs) |
|
| 239 | 239 | { |
| 240 | 240 | global $conf; |
| 241 | 241 | |
| 242 | 242 | return array( |
| 243 | 243 | 'projfile_name'=>$file['name'], |
| 244 | - 'projfile_date'=>dol_print_date($file['date'],'day'), |
|
| 244 | + 'projfile_date'=>dol_print_date($file['date'], 'day'), |
|
| 245 | 245 | 'projfile_size'=>$file['size'] |
| 246 | 246 | ); |
| 247 | 247 | } |
@@ -253,17 +253,17 @@ discard block |
||
| 253 | 253 | * @param Translate $outputlangs Lang object to use for output |
| 254 | 254 | * @return array Return a substitution array |
| 255 | 255 | */ |
| 256 | - function get_substitutionarray_project_reference($refdetail,$outputlangs) |
|
| 256 | + function get_substitutionarray_project_reference($refdetail, $outputlangs) |
|
| 257 | 257 | { |
| 258 | 258 | global $conf; |
| 259 | 259 | |
| 260 | 260 | return array( |
| 261 | 261 | 'projref_type'=>$refdetail['type'], |
| 262 | 262 | 'projref_ref'=>$refdetail['ref'], |
| 263 | - 'projref_date'=>dol_print_date($refdetail['date'],'day'), |
|
| 263 | + 'projref_date'=>dol_print_date($refdetail['date'], 'day'), |
|
| 264 | 264 | 'projref_socname'=>$refdetail['socname'], |
| 265 | - 'projref_amountht'=>price($refdetail['amountht'],0,$outputlangs), |
|
| 266 | - 'projref_amountttc'=>price($refdetail['amountttc'],0,$outputlangs), |
|
| 265 | + 'projref_amountht'=>price($refdetail['amountht'], 0, $outputlangs), |
|
| 266 | + 'projref_amountttc'=>price($refdetail['amountttc'], 0, $outputlangs), |
|
| 267 | 267 | 'projref_status'=>$refdetail['status'] |
| 268 | 268 | ); |
| 269 | 269 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @param Translate $outputlangs Lang object to use for output |
| 276 | 276 | * @return array Return a substitution array |
| 277 | 277 | */ |
| 278 | - function get_substitutionarray_tasksressource($taskressource,$outputlangs) |
|
| 278 | + function get_substitutionarray_tasksressource($taskressource, $outputlangs) |
|
| 279 | 279 | { |
| 280 | 280 | global $conf; |
| 281 | 281 | //dol_syslog(get_class($this).'::get_substitutionarray_tasksressource taskressource='.var_export($taskressource,true),LOG_DEBUG); |
@@ -297,15 +297,15 @@ discard block |
||
| 297 | 297 | * @param Translate $outputlangs Lang object to use for output |
| 298 | 298 | * @return array Return a substitution array |
| 299 | 299 | */ |
| 300 | - function get_substitutionarray_taskstime($tasktime,$outputlangs) |
|
| 300 | + function get_substitutionarray_taskstime($tasktime, $outputlangs) |
|
| 301 | 301 | { |
| 302 | 302 | global $conf; |
| 303 | 303 | |
| 304 | 304 | return array( |
| 305 | 305 | 'tasktime_rowid'=>$tasktime['rowid'], |
| 306 | - 'tasktime_task_date'=>dol_print_date($tasktime['task_date'],'day'), |
|
| 306 | + 'tasktime_task_date'=>dol_print_date($tasktime['task_date'], 'day'), |
|
| 307 | 307 | 'tasktime_task_duration_sec'=>$tasktime['task_duration'], |
| 308 | - 'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'],'all'), |
|
| 308 | + 'tasktime_task_duration'=>convertSecondToTime($tasktime['task_duration'], 'all'), |
|
| 309 | 309 | 'tasktime_note'=>$tasktime['note'], |
| 310 | 310 | 'tasktime_fk_user'=>$tasktime['fk_user'], |
| 311 | 311 | 'tasktime_user_name'=>$tasktime['name'], |
@@ -321,13 +321,13 @@ discard block |
||
| 321 | 321 | * @param Translate $outputlangs Lang object to use for output |
| 322 | 322 | * @return array Return a substitution array |
| 323 | 323 | */ |
| 324 | - function get_substitutionarray_task_file($file,$outputlangs) |
|
| 324 | + function get_substitutionarray_task_file($file, $outputlangs) |
|
| 325 | 325 | { |
| 326 | 326 | global $conf; |
| 327 | 327 | |
| 328 | 328 | return array( |
| 329 | 329 | 'tasksfile_name'=>$file['name'], |
| 330 | - 'tasksfile_date'=>dol_print_date($file['date'],'day'), |
|
| 330 | + 'tasksfile_date'=>dol_print_date($file['date'], 'day'), |
|
| 331 | 331 | 'tasksfile_size'=>$file['size'] |
| 332 | 332 | ); |
| 333 | 333 | } |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | */ |
| 342 | 342 | function info($langs) |
| 343 | 343 | { |
| 344 | - global $conf,$langs; |
|
| 344 | + global $conf, $langs; |
|
| 345 | 345 | |
| 346 | 346 | $langs->load("companies"); |
| 347 | 347 | $langs->load("errors"); |
@@ -349,75 +349,75 @@ discard block |
||
| 349 | 349 | $form = new Form($this->db); |
| 350 | 350 | |
| 351 | 351 | $texte = $this->description.".<br>\n"; |
| 352 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 353 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 354 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 355 | - $texte.= '<input type="hidden" name="param1" value="PROJECT_ADDON_PDF_ODT_PATH">'; |
|
| 356 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
| 352 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 353 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 354 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 355 | + $texte .= '<input type="hidden" name="param1" value="PROJECT_ADDON_PDF_ODT_PATH">'; |
|
| 356 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
| 357 | 357 | |
| 358 | 358 | // List of directories area |
| 359 | - $texte.= '<tr><td>'; |
|
| 360 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
| 361 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->PROJECT_ADDON_PDF_ODT_PATH))); |
|
| 362 | - $listoffiles=array(); |
|
| 363 | - foreach($listofdir as $key=>$tmpdir) |
|
| 359 | + $texte .= '<tr><td>'; |
|
| 360 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
| 361 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->PROJECT_ADDON_PDF_ODT_PATH))); |
|
| 362 | + $listoffiles = array(); |
|
| 363 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 364 | 364 | { |
| 365 | - $tmpdir=trim($tmpdir); |
|
| 366 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 367 | - if (! $tmpdir) { |
|
| 365 | + $tmpdir = trim($tmpdir); |
|
| 366 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 367 | + if (!$tmpdir) { |
|
| 368 | 368 | unset($listofdir[$key]); continue; |
| 369 | 369 | } |
| 370 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 370 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 371 | 371 | else |
| 372 | 372 | { |
| 373 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
| 374 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 373 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
| 374 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 377 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 378 | 378 | // Add list of substitution keys |
| 379 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 380 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 381 | - |
|
| 382 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
| 383 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 384 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
| 385 | - $texte.=$conf->global->PROJECT_ADDON_PDF_ODT_PATH; |
|
| 386 | - $texte.= '</textarea>'; |
|
| 387 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 388 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 389 | - $texte.= '<br></div></div>'; |
|
| 379 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 380 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 381 | + |
|
| 382 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
| 383 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 384 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
| 385 | + $texte .= $conf->global->PROJECT_ADDON_PDF_ODT_PATH; |
|
| 386 | + $texte .= '</textarea>'; |
|
| 387 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 388 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 389 | + $texte .= '<br></div></div>'; |
|
| 390 | 390 | |
| 391 | 391 | // Scan directories |
| 392 | - $nbofiles=count($listoffiles); |
|
| 393 | - if (! empty($conf->global->PROJECT_ADDON_PDF_ODT_PATH)) |
|
| 392 | + $nbofiles = count($listoffiles); |
|
| 393 | + if (!empty($conf->global->PROJECT_ADDON_PDF_ODT_PATH)) |
|
| 394 | 394 | { |
| 395 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 395 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 396 | 396 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
| 397 | - $texte.=$nbofiles; |
|
| 397 | + $texte .= $nbofiles; |
|
| 398 | 398 | //$texte.=$nbofiles?'</a>':''; |
| 399 | - $texte.='</b>'; |
|
| 399 | + $texte .= '</b>'; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | if ($nbofiles) |
| 403 | 403 | { |
| 404 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 405 | - foreach($listoffiles as $file) |
|
| 404 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 405 | + foreach ($listoffiles as $file) |
|
| 406 | 406 | { |
| 407 | - $texte.=$file['name'].'<br>'; |
|
| 407 | + $texte .= $file['name'].'<br>'; |
|
| 408 | 408 | } |
| 409 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
| 409 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | - $texte.= '</td>'; |
|
| 412 | + $texte .= '</td>'; |
|
| 413 | 413 | |
| 414 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 415 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 416 | - $texte.= '</td>'; |
|
| 417 | - $texte.= '</tr>'; |
|
| 414 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 415 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 416 | + $texte .= '</td>'; |
|
| 417 | + $texte .= '</tr>'; |
|
| 418 | 418 | |
| 419 | - $texte.= '</table>'; |
|
| 420 | - $texte.= '</form>'; |
|
| 419 | + $texte .= '</table>'; |
|
| 420 | + $texte .= '</form>'; |
|
| 421 | 421 | |
| 422 | 422 | return $texte; |
| 423 | 423 | } |
@@ -430,9 +430,9 @@ discard block |
||
| 430 | 430 | * @param string $srctemplatepath Full path of source filename for generator using a template file |
| 431 | 431 | * @return int 1 if OK, <=0 if KO |
| 432 | 432 | */ |
| 433 | - function write_file($object,$outputlangs,$srctemplatepath) |
|
| 433 | + function write_file($object, $outputlangs, $srctemplatepath) |
|
| 434 | 434 | { |
| 435 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
| 435 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
| 436 | 436 | |
| 437 | 437 | if (empty($srctemplatepath)) |
| 438 | 438 | { |
@@ -441,17 +441,17 @@ discard block |
||
| 441 | 441 | } |
| 442 | 442 | |
| 443 | 443 | // Add odtgeneration hook |
| 444 | - if (! is_object($hookmanager)) |
|
| 444 | + if (!is_object($hookmanager)) |
|
| 445 | 445 | { |
| 446 | 446 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
| 447 | - $hookmanager=new HookManager($this->db); |
|
| 447 | + $hookmanager = new HookManager($this->db); |
|
| 448 | 448 | } |
| 449 | 449 | $hookmanager->initHooks(array('odtgeneration')); |
| 450 | 450 | global $action; |
| 451 | 451 | |
| 452 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
| 453 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 454 | - $outputlangs->charset_output='UTF-8'; |
|
| 452 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
| 453 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 454 | + $outputlangs->charset_output = 'UTF-8'; |
|
| 455 | 455 | |
| 456 | 456 | $outputlangs->load("main"); |
| 457 | 457 | $outputlangs->load("dict"); |
@@ -461,28 +461,28 @@ discard block |
||
| 461 | 461 | if ($conf->projet->dir_output) |
| 462 | 462 | { |
| 463 | 463 | // If $object is id instead of object |
| 464 | - if (! is_object($object)) |
|
| 464 | + if (!is_object($object)) |
|
| 465 | 465 | { |
| 466 | 466 | $id = $object; |
| 467 | 467 | $object = new Project($this->db); |
| 468 | - $result=$object->fetch($id); |
|
| 468 | + $result = $object->fetch($id); |
|
| 469 | 469 | if ($result < 0) |
| 470 | 470 | { |
| 471 | - dol_print_error($this->db,$object->error); |
|
| 471 | + dol_print_error($this->db, $object->error); |
|
| 472 | 472 | return -1; |
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | $dir = $conf->projet->dir_output; |
| 477 | 477 | $objectref = dol_sanitizeFileName($object->ref); |
| 478 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
| 479 | - $file = $dir . "/" . $objectref . ".odt"; |
|
| 478 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
| 479 | + $file = $dir."/".$objectref.".odt"; |
|
| 480 | 480 | |
| 481 | - if (! file_exists($dir)) |
|
| 481 | + if (!file_exists($dir)) |
|
| 482 | 482 | { |
| 483 | 483 | if (dol_mkdir($dir) < 0) |
| 484 | 484 | { |
| 485 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 485 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 486 | 486 | return -1; |
| 487 | 487 | } |
| 488 | 488 | } |
@@ -490,25 +490,25 @@ discard block |
||
| 490 | 490 | if (file_exists($dir)) |
| 491 | 491 | { |
| 492 | 492 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
| 493 | - $newfile=basename($srctemplatepath); |
|
| 494 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
| 495 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
| 496 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
| 497 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
| 493 | + $newfile = basename($srctemplatepath); |
|
| 494 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
| 495 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
| 496 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
| 497 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
| 498 | 498 | //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
| 499 | 499 | // Get extension (ods or odt) |
| 500 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
| 501 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 500 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
| 501 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 502 | 502 | { |
| 503 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
| 504 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
| 505 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
| 503 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
| 504 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
| 505 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
| 506 | 506 | } |
| 507 | 507 | else |
| 508 | 508 | { |
| 509 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
| 509 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
| 510 | 510 | } |
| 511 | - $file=$dir.'/'.$filename; |
|
| 511 | + $file = $dir.'/'.$filename; |
|
| 512 | 512 | //print "newdir=".$dir; |
| 513 | 513 | //print "newfile=".$newfile; |
| 514 | 514 | //print "file=".$file; |
@@ -517,32 +517,32 @@ discard block |
||
| 517 | 517 | dol_mkdir($conf->projet->dir_temp); |
| 518 | 518 | |
| 519 | 519 | // If PROJECTLEADER contact defined on project, we use it |
| 520 | - $usecontact=false; |
|
| 521 | - $arrayidcontact=$object->getIdContact('external','PROJECTLEADER'); |
|
| 520 | + $usecontact = false; |
|
| 521 | + $arrayidcontact = $object->getIdContact('external', 'PROJECTLEADER'); |
|
| 522 | 522 | if (count($arrayidcontact) > 0) |
| 523 | 523 | { |
| 524 | - $usecontact=true; |
|
| 525 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
| 524 | + $usecontact = true; |
|
| 525 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | // Recipient name |
| 529 | - if (! empty($usecontact)) |
|
| 529 | + if (!empty($usecontact)) |
|
| 530 | 530 | { |
| 531 | 531 | // if we have a PROJECTLEADER contact and we dont use it as recipient we store the contact object for later use |
| 532 | 532 | $contactobject = $object->contact; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - $socobject=$object->thirdparty; |
|
| 535 | + $socobject = $object->thirdparty; |
|
| 536 | 536 | |
| 537 | 537 | // Make substitution |
| 538 | - $substitutionarray=array( |
|
| 538 | + $substitutionarray = array( |
|
| 539 | 539 | '__FROM_NAME__' => $this->emetteur->name, |
| 540 | 540 | '__FROM_EMAIL__' => $this->emetteur->email, |
| 541 | 541 | ); |
| 542 | 542 | complete_substitutions_array($substitutionarray, $langs, $object); |
| 543 | 543 | // Call the ODTSubstitution hook |
| 544 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 545 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 544 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 545 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 546 | 546 | |
| 547 | 547 | // Open and load template |
| 548 | 548 | require_once ODTPHP_PATH.'odf.php'; |
@@ -551,15 +551,15 @@ discard block |
||
| 551 | 551 | $srctemplatepath, |
| 552 | 552 | array( |
| 553 | 553 | 'PATH_TO_TMP' => $conf->projet->dir_temp, |
| 554 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 554 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 555 | 555 | 'DELIMITER_LEFT' => '{', |
| 556 | 556 | 'DELIMITER_RIGHT' => '}' |
| 557 | 557 | ) |
| 558 | 558 | ); |
| 559 | 559 | } |
| 560 | - catch(Exception $e) |
|
| 560 | + catch (Exception $e) |
|
| 561 | 561 | { |
| 562 | - $this->error=$e->getMessage(); |
|
| 562 | + $this->error = $e->getMessage(); |
|
| 563 | 563 | return -1; |
| 564 | 564 | } |
| 565 | 565 | // After construction $odfHandler->contentXml contains content and |
@@ -572,26 +572,26 @@ discard block |
||
| 572 | 572 | // Define substitution array |
| 573 | 573 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
| 574 | 574 | $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
| 575 | - $array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
| 576 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
| 577 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
| 578 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
| 579 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
| 575 | + $array_objet = $this->get_substitutionarray_object($object, $outputlangs); |
|
| 576 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
| 577 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
| 578 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
| 579 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
| 580 | 580 | // retrieve contact information for use in project as contact_xxx tags |
| 581 | 581 | $array_project_contact = array(); |
| 582 | - if ($usecontact) $array_project_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
| 582 | + if ($usecontact) $array_project_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
| 583 | 583 | |
| 584 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_project_contact); |
|
| 584 | + $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_project_contact); |
|
| 585 | 585 | complete_substitutions_array($tmparray, $outputlangs, $object); |
| 586 | 586 | |
| 587 | 587 | // Call the ODTSubstitution hook |
| 588 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 589 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 588 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 589 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 590 | 590 | |
| 591 | - foreach($tmparray as $key=>$value) |
|
| 591 | + foreach ($tmparray as $key=>$value) |
|
| 592 | 592 | { |
| 593 | 593 | try { |
| 594 | - if (preg_match('/logo$/',$key)) // Image |
|
| 594 | + if (preg_match('/logo$/', $key)) // Image |
|
| 595 | 595 | { |
| 596 | 596 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
| 597 | 597 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -601,7 +601,7 @@ discard block |
||
| 601 | 601 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 602 | 602 | } |
| 603 | 603 | } |
| 604 | - catch(OdfException $e) |
|
| 604 | + catch (OdfException $e) |
|
| 605 | 605 | { |
| 606 | 606 | } |
| 607 | 607 | } |
@@ -614,41 +614,41 @@ discard block |
||
| 614 | 614 | $taskstatic = new Task($this->db); |
| 615 | 615 | |
| 616 | 616 | // Security check |
| 617 | - $socid=0; |
|
| 617 | + $socid = 0; |
|
| 618 | 618 | if (!empty($object->fk_soc)) $socid = $object->fk_soc; |
| 619 | 619 | |
| 620 | - $tasksarray=$taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); |
|
| 620 | + $tasksarray = $taskstatic->getTasksArray(0, 0, $object->id, $socid, 0); |
|
| 621 | 621 | |
| 622 | 622 | |
| 623 | 623 | foreach ($tasksarray as $task) |
| 624 | 624 | { |
| 625 | - $tmparray=$this->get_substitutionarray_tasks($task,$outputlangs); |
|
| 625 | + $tmparray = $this->get_substitutionarray_tasks($task, $outputlangs); |
|
| 626 | 626 | //complete_substitutions_array($tmparray, $outputlangs, $object, $task, "completesubstitutionarray_lines"); |
| 627 | - foreach($tmparray as $key => $val) |
|
| 627 | + foreach ($tmparray as $key => $val) |
|
| 628 | 628 | { |
| 629 | 629 | try |
| 630 | 630 | { |
| 631 | 631 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 632 | 632 | } |
| 633 | - catch(OdfException $e) |
|
| 633 | + catch (OdfException $e) |
|
| 634 | 634 | { |
| 635 | 635 | } |
| 636 | - catch(SegmentException $e) |
|
| 636 | + catch (SegmentException $e) |
|
| 637 | 637 | { |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | - $taskobj=new Task($this->db); |
|
| 641 | + $taskobj = new Task($this->db); |
|
| 642 | 642 | $taskobj->fetch($task->id); |
| 643 | 643 | |
| 644 | 644 | // Replace tags of lines for contacts task |
| 645 | - $sourcearray=array('internal','external'); |
|
| 646 | - $contact_arrray=array(); |
|
| 645 | + $sourcearray = array('internal', 'external'); |
|
| 646 | + $contact_arrray = array(); |
|
| 647 | 647 | foreach ($sourcearray as $source) { |
| 648 | - $contact_temp=$taskobj->liste_contact(-1,$source); |
|
| 648 | + $contact_temp = $taskobj->liste_contact(-1, $source); |
|
| 649 | 649 | if ((is_array($contact_temp) && count($contact_temp) > 0)) |
| 650 | 650 | { |
| 651 | - $contact_arrray=array_merge($contact_arrray,$contact_temp); |
|
| 651 | + $contact_arrray = array_merge($contact_arrray, $contact_temp); |
|
| 652 | 652 | } |
| 653 | 653 | } |
| 654 | 654 | if ((is_array($contact_arrray) && count($contact_arrray) > 0)) |
@@ -657,32 +657,32 @@ discard block |
||
| 657 | 657 | |
| 658 | 658 | foreach ($contact_arrray as $contact) |
| 659 | 659 | { |
| 660 | - if ($contact['source']=='internal') { |
|
| 661 | - $objectdetail=new User($this->db); |
|
| 660 | + if ($contact['source'] == 'internal') { |
|
| 661 | + $objectdetail = new User($this->db); |
|
| 662 | 662 | $objectdetail->fetch($contact['id']); |
| 663 | - $contact['socname']=$mysoc->name; |
|
| 664 | - } elseif ($contact['source']=='external') { |
|
| 665 | - $objectdetail=new Contact($this->db); |
|
| 663 | + $contact['socname'] = $mysoc->name; |
|
| 664 | + } elseif ($contact['source'] == 'external') { |
|
| 665 | + $objectdetail = new Contact($this->db); |
|
| 666 | 666 | $objectdetail->fetch($contact['id']); |
| 667 | 667 | |
| 668 | - $soc=new Societe($this->db); |
|
| 668 | + $soc = new Societe($this->db); |
|
| 669 | 669 | $soc->fetch($contact['socid']); |
| 670 | - $contact['socname']=$soc->name; |
|
| 670 | + $contact['socname'] = $soc->name; |
|
| 671 | 671 | } |
| 672 | - $contact['fullname']=$objectdetail->getFullName($outputlangs,1); |
|
| 672 | + $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1); |
|
| 673 | 673 | |
| 674 | - $tmparray=$this->get_substitutionarray_tasksressource($contact,$outputlangs); |
|
| 674 | + $tmparray = $this->get_substitutionarray_tasksressource($contact, $outputlangs); |
|
| 675 | 675 | |
| 676 | - foreach($tmparray as $key => $val) |
|
| 676 | + foreach ($tmparray as $key => $val) |
|
| 677 | 677 | { |
| 678 | 678 | try |
| 679 | 679 | { |
| 680 | 680 | $listlinestaskres->setVars($key, $val, true, 'UTF-8'); |
| 681 | 681 | } |
| 682 | - catch(OdfException $e) |
|
| 682 | + catch (OdfException $e) |
|
| 683 | 683 | { |
| 684 | 684 | } |
| 685 | - catch(SegmentException $e) |
|
| 685 | + catch (SegmentException $e) |
|
| 686 | 686 | { |
| 687 | 687 | } |
| 688 | 688 | } |
@@ -692,7 +692,7 @@ discard block |
||
| 692 | 692 | |
| 693 | 693 | //Time ressources |
| 694 | 694 | $sql = "SELECT t.rowid, t.task_date, t.task_duration, t.fk_user, t.note"; |
| 695 | - $sql.= ", u.lastname, u.firstname"; |
|
| 695 | + $sql .= ", u.lastname, u.firstname"; |
|
| 696 | 696 | $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t"; |
| 697 | 697 | $sql .= " , ".MAIN_DB_PREFIX."user as u"; |
| 698 | 698 | $sql .= " WHERE t.fk_task =".$task->id; |
@@ -710,25 +710,25 @@ discard block |
||
| 710 | 710 | { |
| 711 | 711 | $row = $this->db->fetch_array($resql); |
| 712 | 712 | if (!empty($row['fk_user'])) { |
| 713 | - $objectdetail=new User($this->db); |
|
| 713 | + $objectdetail = new User($this->db); |
|
| 714 | 714 | $objectdetail->fetch($row['fk_user']); |
| 715 | - $row['fullcivname']=$objectdetail->getFullName($outputlangs,1); |
|
| 715 | + $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1); |
|
| 716 | 716 | } else { |
| 717 | - $row['fullcivname']=''; |
|
| 717 | + $row['fullcivname'] = ''; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | - $tmparray=$this->get_substitutionarray_taskstime($row,$outputlangs); |
|
| 720 | + $tmparray = $this->get_substitutionarray_taskstime($row, $outputlangs); |
|
| 721 | 721 | |
| 722 | - foreach($tmparray as $key => $val) |
|
| 722 | + foreach ($tmparray as $key => $val) |
|
| 723 | 723 | { |
| 724 | 724 | try |
| 725 | 725 | { |
| 726 | 726 | $listlinestasktime->setVars($key, $val, true, 'UTF-8'); |
| 727 | 727 | } |
| 728 | - catch(OdfException $e) |
|
| 728 | + catch (OdfException $e) |
|
| 729 | 729 | { |
| 730 | 730 | } |
| 731 | - catch(SegmentException $e) |
|
| 731 | + catch (SegmentException $e) |
|
| 732 | 732 | { |
| 733 | 733 | } |
| 734 | 734 | } |
@@ -743,23 +743,23 @@ discard block |
||
| 743 | 743 | $listtasksfiles = $listlines->__get('tasksfiles'); |
| 744 | 744 | |
| 745 | 745 | $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref).'/'.dol_sanitizeFileName($task->ref); |
| 746 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$','name',SORT_ASC,1); |
|
| 746 | + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); |
|
| 747 | 747 | |
| 748 | 748 | |
| 749 | 749 | foreach ($filearray as $filedetail) |
| 750 | 750 | { |
| 751 | - $tmparray=$this->get_substitutionarray_task_file($filedetail,$outputlangs); |
|
| 751 | + $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs); |
|
| 752 | 752 | //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true)); |
| 753 | - foreach($tmparray as $key => $val) |
|
| 753 | + foreach ($tmparray as $key => $val) |
|
| 754 | 754 | { |
| 755 | 755 | try |
| 756 | 756 | { |
| 757 | 757 | $listtasksfiles->setVars($key, $val, true, 'UTF-8'); |
| 758 | 758 | } |
| 759 | - catch(OdfException $e) |
|
| 759 | + catch (OdfException $e) |
|
| 760 | 760 | { |
| 761 | 761 | } |
| 762 | - catch(SegmentException $e) |
|
| 762 | + catch (SegmentException $e) |
|
| 763 | 763 | { |
| 764 | 764 | } |
| 765 | 765 | } |
@@ -769,13 +769,13 @@ discard block |
||
| 769 | 769 | } |
| 770 | 770 | $odfHandler->mergeSegment($listlines); |
| 771 | 771 | } |
| 772 | - catch(OdfException $e) |
|
| 772 | + catch (OdfException $e) |
|
| 773 | 773 | { |
| 774 | - $ExceptionTrace=$e->getTrace(); |
|
| 774 | + $ExceptionTrace = $e->getTrace(); |
|
| 775 | 775 | // no segment defined on ODT is not an error |
| 776 | - if($ExceptionTrace[0]['function'] != 'setSegment') |
|
| 776 | + if ($ExceptionTrace[0]['function'] != 'setSegment') |
|
| 777 | 777 | { |
| 778 | - $this->error=$e->getMessage(); |
|
| 778 | + $this->error = $e->getMessage(); |
|
| 779 | 779 | dol_syslog($this->error, LOG_WARNING); |
| 780 | 780 | return -1; |
| 781 | 781 | } |
@@ -787,23 +787,23 @@ discard block |
||
| 787 | 787 | $listlines = $odfHandler->setSegment('projectfiles'); |
| 788 | 788 | |
| 789 | 789 | $upload_dir = $conf->projet->dir_output.'/'.dol_sanitizeFileName($object->ref); |
| 790 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$','name',SORT_ASC,1); |
|
| 790 | + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); |
|
| 791 | 791 | |
| 792 | 792 | foreach ($filearray as $filedetail) |
| 793 | 793 | { |
| 794 | 794 | //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true)); |
| 795 | - $tmparray=$this->get_substitutionarray_project_file($filedetail,$outputlangs); |
|
| 795 | + $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs); |
|
| 796 | 796 | |
| 797 | - foreach($tmparray as $key => $val) |
|
| 797 | + foreach ($tmparray as $key => $val) |
|
| 798 | 798 | { |
| 799 | 799 | try |
| 800 | 800 | { |
| 801 | 801 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 802 | 802 | } |
| 803 | - catch(OdfException $e) |
|
| 803 | + catch (OdfException $e) |
|
| 804 | 804 | { |
| 805 | 805 | } |
| 806 | - catch(SegmentException $e) |
|
| 806 | + catch (SegmentException $e) |
|
| 807 | 807 | { |
| 808 | 808 | } |
| 809 | 809 | } |
@@ -811,21 +811,21 @@ discard block |
||
| 811 | 811 | } |
| 812 | 812 | $odfHandler->mergeSegment($listlines); |
| 813 | 813 | } |
| 814 | - catch(OdfException $e) |
|
| 814 | + catch (OdfException $e) |
|
| 815 | 815 | { |
| 816 | - $this->error=$e->getMessage(); |
|
| 816 | + $this->error = $e->getMessage(); |
|
| 817 | 817 | dol_syslog($this->error, LOG_WARNING); |
| 818 | 818 | return -1; |
| 819 | 819 | } |
| 820 | 820 | |
| 821 | 821 | // Replace tags of lines for contacts |
| 822 | - $sourcearray=array('internal','external'); |
|
| 823 | - $contact_arrray=array(); |
|
| 822 | + $sourcearray = array('internal', 'external'); |
|
| 823 | + $contact_arrray = array(); |
|
| 824 | 824 | foreach ($sourcearray as $source) { |
| 825 | - $contact_temp=$object->liste_contact(-1,$source); |
|
| 825 | + $contact_temp = $object->liste_contact(-1, $source); |
|
| 826 | 826 | if ((is_array($contact_temp) && count($contact_temp) > 0)) |
| 827 | 827 | { |
| 828 | - $contact_arrray=array_merge($contact_arrray,$contact_temp); |
|
| 828 | + $contact_arrray = array_merge($contact_arrray, $contact_temp); |
|
| 829 | 829 | } |
| 830 | 830 | } |
| 831 | 831 | if ((is_array($contact_arrray) && count($contact_arrray) > 0)) |
@@ -836,31 +836,31 @@ discard block |
||
| 836 | 836 | |
| 837 | 837 | foreach ($contact_arrray as $contact) |
| 838 | 838 | { |
| 839 | - if ($contact['source']=='internal') { |
|
| 840 | - $objectdetail=new User($this->db); |
|
| 839 | + if ($contact['source'] == 'internal') { |
|
| 840 | + $objectdetail = new User($this->db); |
|
| 841 | 841 | $objectdetail->fetch($contact['id']); |
| 842 | - $contact['socname']=$mysoc->name; |
|
| 843 | - } elseif ($contact['source']=='external') { |
|
| 844 | - $objectdetail=new Contact($this->db); |
|
| 842 | + $contact['socname'] = $mysoc->name; |
|
| 843 | + } elseif ($contact['source'] == 'external') { |
|
| 844 | + $objectdetail = new Contact($this->db); |
|
| 845 | 845 | $objectdetail->fetch($contact['id']); |
| 846 | 846 | |
| 847 | - $soc=new Societe($this->db); |
|
| 847 | + $soc = new Societe($this->db); |
|
| 848 | 848 | $soc->fetch($contact['socid']); |
| 849 | - $contact['socname']=$soc->name; |
|
| 849 | + $contact['socname'] = $soc->name; |
|
| 850 | 850 | } |
| 851 | - $contact['fullname']=$objectdetail->getFullName($outputlangs,1); |
|
| 851 | + $contact['fullname'] = $objectdetail->getFullName($outputlangs, 1); |
|
| 852 | 852 | |
| 853 | - $tmparray=$this->get_substitutionarray_project_contacts($contact,$outputlangs); |
|
| 854 | - foreach($tmparray as $key => $val) |
|
| 853 | + $tmparray = $this->get_substitutionarray_project_contacts($contact, $outputlangs); |
|
| 854 | + foreach ($tmparray as $key => $val) |
|
| 855 | 855 | { |
| 856 | 856 | try |
| 857 | 857 | { |
| 858 | 858 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 859 | 859 | } |
| 860 | - catch(OdfException $e) |
|
| 860 | + catch (OdfException $e) |
|
| 861 | 861 | { |
| 862 | 862 | } |
| 863 | - catch(SegmentException $e) |
|
| 863 | + catch (SegmentException $e) |
|
| 864 | 864 | { |
| 865 | 865 | } |
| 866 | 866 | } |
@@ -868,9 +868,9 @@ discard block |
||
| 868 | 868 | } |
| 869 | 869 | $odfHandler->mergeSegment($listlines); |
| 870 | 870 | } |
| 871 | - catch(OdfException $e) |
|
| 871 | + catch (OdfException $e) |
|
| 872 | 872 | { |
| 873 | - $this->error=$e->getMessage(); |
|
| 873 | + $this->error = $e->getMessage(); |
|
| 874 | 874 | dol_syslog($this->error, LOG_WARNING); |
| 875 | 875 | return -1; |
| 876 | 876 | } |
@@ -878,17 +878,17 @@ discard block |
||
| 878 | 878 | |
| 879 | 879 | //List of referent |
| 880 | 880 | |
| 881 | - $listofreferent=array( |
|
| 881 | + $listofreferent = array( |
|
| 882 | 882 | 'propal'=>array( |
| 883 | 883 | 'title'=>"ListProposalsAssociatedProject", |
| 884 | 884 | 'class'=>'Propal', |
| 885 | 885 | 'table'=>'propal', |
| 886 | - 'test'=>$conf->propal->enabled && $user->rights->propale->lire), |
|
| 886 | + 'test'=>$conf->propal->enabled && $user->rights->propale->lire), |
|
| 887 | 887 | 'order'=>array( |
| 888 | 888 | 'title'=>"ListOrdersAssociatedProject", |
| 889 | 889 | 'class'=>'Commande', |
| 890 | 890 | 'table'=>'commande', |
| 891 | - 'test'=>$conf->commande->enabled && $user->rights->commande->lire), |
|
| 891 | + 'test'=>$conf->commande->enabled && $user->rights->commande->lire), |
|
| 892 | 892 | 'invoice'=>array( |
| 893 | 893 | 'title'=>"ListInvoicesAssociatedProject", |
| 894 | 894 | 'class'=>'Facture', |
@@ -898,7 +898,7 @@ discard block |
||
| 898 | 898 | 'title'=>"ListPredefinedInvoicesAssociatedProject", |
| 899 | 899 | 'class'=>'FactureRec', |
| 900 | 900 | 'table'=>'facture_rec', |
| 901 | - 'test'=>$conf->facture->enabled && $user->rights->facture->lire), |
|
| 901 | + 'test'=>$conf->facture->enabled && $user->rights->facture->lire), |
|
| 902 | 902 | 'order_supplier'=>array( |
| 903 | 903 | 'title'=>"ListSupplierOrdersAssociatedProject", |
| 904 | 904 | 'table'=>'commande_fournisseur', |
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | 'title'=>"ListSupplierInvoicesAssociatedProject", |
| 909 | 909 | 'table'=>'facture_fourn', |
| 910 | 910 | 'class'=>'FactureFournisseur', |
| 911 | - 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), |
|
| 911 | + 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), |
|
| 912 | 912 | 'contract'=>array( |
| 913 | 913 | 'title'=>"ListContractAssociatedProject", |
| 914 | 914 | 'class'=>'Contrat', |
@@ -941,72 +941,72 @@ discard block |
||
| 941 | 941 | |
| 942 | 942 | foreach ($listofreferent as $keyref => $valueref) |
| 943 | 943 | { |
| 944 | - $title=$valueref['title']; |
|
| 945 | - $tablename=$valueref['table']; |
|
| 946 | - $classname=$valueref['class']; |
|
| 947 | - $qualified=$valueref['test']; |
|
| 944 | + $title = $valueref['title']; |
|
| 945 | + $tablename = $valueref['table']; |
|
| 946 | + $classname = $valueref['class']; |
|
| 947 | + $qualified = $valueref['test']; |
|
| 948 | 948 | if ($qualified) |
| 949 | 949 | { |
| 950 | 950 | $elementarray = $object->get_element_list($keyref, $tablename); |
| 951 | - if (count($elementarray)>0 && is_array($elementarray)) |
|
| 951 | + if (count($elementarray) > 0 && is_array($elementarray)) |
|
| 952 | 952 | { |
| 953 | - $var=true; |
|
| 953 | + $var = true; |
|
| 954 | 954 | $total_ht = 0; |
| 955 | 955 | $total_ttc = 0; |
| 956 | - $num=count($elementarray); |
|
| 956 | + $num = count($elementarray); |
|
| 957 | 957 | for ($i = 0; $i < $num; $i++) |
| 958 | 958 | { |
| 959 | - $ref_array=array(); |
|
| 960 | - $ref_array['type']=$langs->trans($classname); |
|
| 959 | + $ref_array = array(); |
|
| 960 | + $ref_array['type'] = $langs->trans($classname); |
|
| 961 | 961 | |
| 962 | 962 | $element = new $classname($this->db); |
| 963 | 963 | $element->fetch($elementarray[$i]); |
| 964 | 964 | $element->fetch_thirdparty(); |
| 965 | 965 | |
| 966 | 966 | //Ref object |
| 967 | - $ref_array['ref']=$element->ref; |
|
| 967 | + $ref_array['ref'] = $element->ref; |
|
| 968 | 968 | |
| 969 | 969 | //Date object |
| 970 | - $dateref=$element->date; |
|
| 971 | - if (empty($dateref)) $dateref=$element->datep; |
|
| 972 | - if (empty($dateref)) $dateref=$element->date_contrat; |
|
| 973 | - $ref_array['date']=$dateref; |
|
| 970 | + $dateref = $element->date; |
|
| 971 | + if (empty($dateref)) $dateref = $element->datep; |
|
| 972 | + if (empty($dateref)) $dateref = $element->date_contrat; |
|
| 973 | + $ref_array['date'] = $dateref; |
|
| 974 | 974 | |
| 975 | 975 | //Soc object |
| 976 | 976 | if (is_object($element->thirdparty)) { |
| 977 | - $ref_array['socname']=$element->thirdparty->name; |
|
| 977 | + $ref_array['socname'] = $element->thirdparty->name; |
|
| 978 | 978 | } else { |
| 979 | - $ref_array['socname']=''; |
|
| 979 | + $ref_array['socname'] = ''; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | //Amount object |
| 983 | 983 | if (empty($valueref['disableamount'])) { |
| 984 | 984 | if (!empty($element->total_ht)) { |
| 985 | - $ref_array['amountht']=$element->total_ht; |
|
| 986 | - $ref_array['amountttc']=$element->total_ttc; |
|
| 987 | - }else { |
|
| 988 | - $ref_array['amountht']=0; |
|
| 989 | - $ref_array['amountttc']=0; |
|
| 985 | + $ref_array['amountht'] = $element->total_ht; |
|
| 986 | + $ref_array['amountttc'] = $element->total_ttc; |
|
| 987 | + } else { |
|
| 988 | + $ref_array['amountht'] = 0; |
|
| 989 | + $ref_array['amountttc'] = 0; |
|
| 990 | 990 | } |
| 991 | - }else { |
|
| 992 | - $ref_array['amountht']=''; |
|
| 993 | - $ref_array['amountttc']=''; |
|
| 991 | + } else { |
|
| 992 | + $ref_array['amountht'] = ''; |
|
| 993 | + $ref_array['amountttc'] = ''; |
|
| 994 | 994 | } |
| 995 | 995 | |
| 996 | - $ref_array['status']=$element->getLibStatut(0); |
|
| 996 | + $ref_array['status'] = $element->getLibStatut(0); |
|
| 997 | 997 | |
| 998 | - $tmparray=$this->get_substitutionarray_project_reference($ref_array,$outputlangs); |
|
| 998 | + $tmparray = $this->get_substitutionarray_project_reference($ref_array, $outputlangs); |
|
| 999 | 999 | |
| 1000 | - foreach($tmparray as $key => $val) |
|
| 1000 | + foreach ($tmparray as $key => $val) |
|
| 1001 | 1001 | { |
| 1002 | 1002 | try |
| 1003 | 1003 | { |
| 1004 | 1004 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 1005 | 1005 | } |
| 1006 | - catch(OdfException $e) |
|
| 1006 | + catch (OdfException $e) |
|
| 1007 | 1007 | { |
| 1008 | 1008 | } |
| 1009 | - catch(SegmentException $e) |
|
| 1009 | + catch (SegmentException $e) |
|
| 1010 | 1010 | { |
| 1011 | 1011 | } |
| 1012 | 1012 | } |
@@ -1018,62 +1018,62 @@ discard block |
||
| 1018 | 1018 | $odfHandler->mergeSegment($listlines); |
| 1019 | 1019 | } |
| 1020 | 1020 | } |
| 1021 | - catch(OdfException $e) |
|
| 1021 | + catch (OdfException $e) |
|
| 1022 | 1022 | { |
| 1023 | - $this->error=$e->getMessage(); |
|
| 1023 | + $this->error = $e->getMessage(); |
|
| 1024 | 1024 | dol_syslog($this->error, LOG_WARNING); |
| 1025 | 1025 | return -1; |
| 1026 | 1026 | } |
| 1027 | 1027 | |
| 1028 | 1028 | // Replace labels translated |
| 1029 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
| 1030 | - foreach($tmparray as $key=>$value) |
|
| 1029 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
| 1030 | + foreach ($tmparray as $key=>$value) |
|
| 1031 | 1031 | { |
| 1032 | 1032 | try { |
| 1033 | 1033 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 1034 | 1034 | } |
| 1035 | - catch(OdfException $e) |
|
| 1035 | + catch (OdfException $e) |
|
| 1036 | 1036 | { |
| 1037 | 1037 | } |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | 1040 | // Call the beforeODTSave hook |
| 1041 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 1042 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 1041 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 1042 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 1043 | 1043 | |
| 1044 | 1044 | |
| 1045 | 1045 | // Write new file |
| 1046 | 1046 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
| 1047 | 1047 | try { |
| 1048 | 1048 | $odfHandler->exportAsAttachedPDF($file); |
| 1049 | - }catch (Exception $e){ |
|
| 1050 | - $this->error=$e->getMessage(); |
|
| 1049 | + } catch (Exception $e) { |
|
| 1050 | + $this->error = $e->getMessage(); |
|
| 1051 | 1051 | return -1; |
| 1052 | 1052 | } |
| 1053 | 1053 | } |
| 1054 | 1054 | else { |
| 1055 | 1055 | try { |
| 1056 | 1056 | $odfHandler->saveToDisk($file); |
| 1057 | - }catch (Exception $e){ |
|
| 1058 | - $this->error=$e->getMessage(); |
|
| 1057 | + } catch (Exception $e) { |
|
| 1058 | + $this->error = $e->getMessage(); |
|
| 1059 | 1059 | return -1; |
| 1060 | 1060 | } |
| 1061 | 1061 | } |
| 1062 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 1063 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 1062 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 1063 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 1064 | 1064 | |
| 1065 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 1065 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 1066 | 1066 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 1067 | 1067 | |
| 1068 | - $odfHandler=null; // Destroy object |
|
| 1068 | + $odfHandler = null; // Destroy object |
|
| 1069 | 1069 | |
| 1070 | 1070 | $this->result = array('fullpath'=>$file); |
| 1071 | 1071 | |
| 1072 | - return 1; // Success |
|
| 1072 | + return 1; // Success |
|
| 1073 | 1073 | } |
| 1074 | 1074 | else |
| 1075 | 1075 | { |
| 1076 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 1076 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 1077 | 1077 | return -1; |
| 1078 | 1078 | } |
| 1079 | 1079 | } |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | class doc_generic_contract_odt extends ModelePDFContract |
| 39 | 39 | { |
| 40 | - var $emetteur; // Objet societe qui emet |
|
| 40 | + var $emetteur; // Objet societe qui emet |
|
| 41 | 41 | |
| 42 | - var $phpmin = array(5,2,0); // Minimum version of PHP required by module |
|
| 42 | + var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module |
|
| 43 | 43 | var $version = 'dolibarr'; |
| 44 | 44 | |
| 45 | 45 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function __construct($db) |
| 52 | 52 | { |
| 53 | - global $conf,$langs,$mysoc; |
|
| 53 | + global $conf, $langs, $mysoc; |
|
| 54 | 54 | |
| 55 | 55 | $langs->load("main"); |
| 56 | 56 | $langs->load("companies"); |
@@ -58,32 +58,32 @@ discard block |
||
| 58 | 58 | $this->db = $db; |
| 59 | 59 | $this->name = "ODT templates"; |
| 60 | 60 | $this->description = $langs->trans("DocumentModelOdt"); |
| 61 | - $this->scandir = 'CONTRACT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 61 | + $this->scandir = 'CONTRACT_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 62 | 62 | |
| 63 | 63 | // Dimension page pour format A4 |
| 64 | 64 | $this->type = 'odt'; |
| 65 | 65 | $this->page_largeur = 0; |
| 66 | 66 | $this->page_hauteur = 0; |
| 67 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
| 68 | - $this->marge_gauche=0; |
|
| 69 | - $this->marge_droite=0; |
|
| 70 | - $this->marge_haute=0; |
|
| 71 | - $this->marge_basse=0; |
|
| 72 | - |
|
| 73 | - $this->option_logo = 1; // Affiche logo |
|
| 74 | - $this->option_tva = 0; // Gere option tva CONTRACT_TVAOPTION |
|
| 75 | - $this->option_modereg = 0; // Affiche mode reglement |
|
| 76 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
| 77 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 78 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 79 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 80 | - $this->option_credit_note = 0; // Support credit notes |
|
| 81 | - $this->option_freetext = 1; // Support add of a personalised text |
|
| 82 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 67 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
| 68 | + $this->marge_gauche = 0; |
|
| 69 | + $this->marge_droite = 0; |
|
| 70 | + $this->marge_haute = 0; |
|
| 71 | + $this->marge_basse = 0; |
|
| 72 | + |
|
| 73 | + $this->option_logo = 1; // Affiche logo |
|
| 74 | + $this->option_tva = 0; // Gere option tva CONTRACT_TVAOPTION |
|
| 75 | + $this->option_modereg = 0; // Affiche mode reglement |
|
| 76 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
| 77 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 78 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 79 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 80 | + $this->option_credit_note = 0; // Support credit notes |
|
| 81 | + $this->option_freetext = 1; // Support add of a personalised text |
|
| 82 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 83 | 83 | |
| 84 | 84 | // Recupere emetteur |
| 85 | - $this->emetteur=$mysoc; |
|
| 86 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
| 85 | + $this->emetteur = $mysoc; |
|
| 86 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | function info($langs) |
| 97 | 97 | { |
| 98 | - global $conf,$langs; |
|
| 98 | + global $conf, $langs; |
|
| 99 | 99 | |
| 100 | 100 | $langs->load("companies"); |
| 101 | 101 | $langs->load("errors"); |
@@ -103,66 +103,66 @@ discard block |
||
| 103 | 103 | $form = new Form($this->db); |
| 104 | 104 | |
| 105 | 105 | $texte = $this->description.".<br>\n"; |
| 106 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'; |
|
| 107 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 108 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 109 | - $texte.= '<input type="hidden" name="param1" value="CONTRACT_ADDON_PDF_ODT_PATH">'; |
|
| 110 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
| 106 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'; |
|
| 107 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 108 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 109 | + $texte .= '<input type="hidden" name="param1" value="CONTRACT_ADDON_PDF_ODT_PATH">'; |
|
| 110 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
| 111 | 111 | |
| 112 | 112 | // List of directories area |
| 113 | - $texte.= '<tr><td>'; |
|
| 114 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
| 115 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->CONTRACT_ADDON_PDF_ODT_PATH))); |
|
| 116 | - $listoffiles=array(); |
|
| 117 | - foreach($listofdir as $key=>$tmpdir) |
|
| 113 | + $texte .= '<tr><td>'; |
|
| 114 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
| 115 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->CONTRACT_ADDON_PDF_ODT_PATH))); |
|
| 116 | + $listoffiles = array(); |
|
| 117 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 118 | 118 | { |
| 119 | - $tmpdir=trim($tmpdir); |
|
| 120 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 121 | - if (! $tmpdir) { |
|
| 119 | + $tmpdir = trim($tmpdir); |
|
| 120 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 121 | + if (!$tmpdir) { |
|
| 122 | 122 | unset($listofdir[$key]); continue; |
| 123 | 123 | } |
| 124 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 124 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 125 | 125 | else |
| 126 | 126 | { |
| 127 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
| 128 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 127 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
| 128 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 131 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 132 | 132 | // Add list of substitution keys |
| 133 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 134 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 135 | - |
|
| 136 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
| 137 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 138 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
| 139 | - $texte.=$conf->global->CONTRACT_ADDON_PDF_ODT_PATH; |
|
| 140 | - $texte.= '</textarea>'; |
|
| 141 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 142 | - $texte.= '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'" name="Button">'; |
|
| 143 | - $texte.= '<br></div></div>'; |
|
| 133 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 134 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 135 | + |
|
| 136 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
| 137 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 138 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
| 139 | + $texte .= $conf->global->CONTRACT_ADDON_PDF_ODT_PATH; |
|
| 140 | + $texte .= '</textarea>'; |
|
| 141 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 142 | + $texte .= '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Modify")).'" name="Button">'; |
|
| 143 | + $texte .= '<br></div></div>'; |
|
| 144 | 144 | |
| 145 | 145 | // Scan directories |
| 146 | 146 | if (count($listofdir)) |
| 147 | 147 | { |
| 148 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; |
|
| 148 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'.count($listoffiles).'</b>'; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Add select to upload a new template file. TODO Copy this feature on other admin pages. |
| 152 | - $texte.= '<div>'.$langs->trans("UploadNewTemplate").' <input type="file" name="uploadfile">'; |
|
| 153 | - $texte.= '<input type="hidden" value="CONTRACT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">'; |
|
| 154 | - $texte.= '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Upload")).'" name="upload">'; |
|
| 155 | - $texte.= '</div>'; |
|
| 152 | + $texte .= '<div>'.$langs->trans("UploadNewTemplate").' <input type="file" name="uploadfile">'; |
|
| 153 | + $texte .= '<input type="hidden" value="CONTRACT_ADDON_PDF_ODT_PATH" name="keyforuploaddir">'; |
|
| 154 | + $texte .= '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Upload")).'" name="upload">'; |
|
| 155 | + $texte .= '</div>'; |
|
| 156 | 156 | |
| 157 | - $texte.= '</td>'; |
|
| 157 | + $texte .= '</td>'; |
|
| 158 | 158 | |
| 159 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 160 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 161 | - $texte.= '</td>'; |
|
| 162 | - $texte.= '</tr>'; |
|
| 159 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 160 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 161 | + $texte .= '</td>'; |
|
| 162 | + $texte .= '</tr>'; |
|
| 163 | 163 | |
| 164 | - $texte.= '</table>'; |
|
| 165 | - $texte.= '</form>'; |
|
| 164 | + $texte .= '</table>'; |
|
| 165 | + $texte .= '</form>'; |
|
| 166 | 166 | |
| 167 | 167 | return $texte; |
| 168 | 168 | } |
@@ -178,9 +178,9 @@ discard block |
||
| 178 | 178 | * @param int $hideref Do not show ref |
| 179 | 179 | * @return int 1 if OK, <=0 if KO |
| 180 | 180 | */ |
| 181 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
| 181 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
| 182 | 182 | { |
| 183 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
| 183 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
| 184 | 184 | |
| 185 | 185 | if (empty($srctemplatepath)) |
| 186 | 186 | { |
@@ -189,17 +189,17 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | // Add odtgeneration hook |
| 192 | - if (! is_object($hookmanager)) |
|
| 192 | + if (!is_object($hookmanager)) |
|
| 193 | 193 | { |
| 194 | 194 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
| 195 | - $hookmanager=new HookManager($this->db); |
|
| 195 | + $hookmanager = new HookManager($this->db); |
|
| 196 | 196 | } |
| 197 | 197 | $hookmanager->initHooks(array('odtgeneration')); |
| 198 | 198 | global $action; |
| 199 | 199 | |
| 200 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
| 201 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 202 | - $outputlangs->charset_output='UTF-8'; |
|
| 200 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
| 201 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 202 | + $outputlangs->charset_output = 'UTF-8'; |
|
| 203 | 203 | |
| 204 | 204 | $outputlangs->load("main"); |
| 205 | 205 | $outputlangs->load("dict"); |
@@ -209,28 +209,28 @@ discard block |
||
| 209 | 209 | if ($conf->contrat->dir_output) |
| 210 | 210 | { |
| 211 | 211 | // If $object is id instead of object |
| 212 | - if (! is_object($object)) |
|
| 212 | + if (!is_object($object)) |
|
| 213 | 213 | { |
| 214 | 214 | $id = $object; |
| 215 | 215 | $object = new Contrat($this->db); |
| 216 | - $result=$object->fetch($id); |
|
| 216 | + $result = $object->fetch($id); |
|
| 217 | 217 | if ($result < 0) |
| 218 | 218 | { |
| 219 | - dol_print_error($this->db,$object->error); |
|
| 219 | + dol_print_error($this->db, $object->error); |
|
| 220 | 220 | return -1; |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | $dir = $conf->contrat->dir_output; |
| 225 | 225 | $objectref = dol_sanitizeFileName($object->ref); |
| 226 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
| 227 | - $file = $dir . "/" . $objectref . ".odt"; |
|
| 226 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
| 227 | + $file = $dir."/".$objectref.".odt"; |
|
| 228 | 228 | |
| 229 | - if (! file_exists($dir)) |
|
| 229 | + if (!file_exists($dir)) |
|
| 230 | 230 | { |
| 231 | 231 | if (dol_mkdir($dir) < 0) |
| 232 | 232 | { |
| 233 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 233 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 234 | 234 | return -1; |
| 235 | 235 | } |
| 236 | 236 | } |
@@ -238,26 +238,26 @@ discard block |
||
| 238 | 238 | if (file_exists($dir)) |
| 239 | 239 | { |
| 240 | 240 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
| 241 | - $newfile=basename($srctemplatepath); |
|
| 242 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
| 243 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
| 244 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
| 241 | + $newfile = basename($srctemplatepath); |
|
| 242 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
| 243 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
| 244 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
| 245 | 245 | |
| 246 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
| 246 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
| 247 | 247 | |
| 248 | 248 | // Get extension (ods or odt) |
| 249 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
| 250 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 249 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
| 250 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 251 | 251 | { |
| 252 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
| 253 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
| 254 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
| 252 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
| 253 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
| 254 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
| 255 | 255 | } |
| 256 | 256 | else |
| 257 | 257 | { |
| 258 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
| 258 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
| 259 | 259 | } |
| 260 | - $file=$dir.'/'.$filename; |
|
| 260 | + $file = $dir.'/'.$filename; |
|
| 261 | 261 | //print "newdir=".$dir; |
| 262 | 262 | //print "newfile=".$newfile; |
| 263 | 263 | //print "file=".$file; |
@@ -267,19 +267,19 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | |
| 269 | 269 | // If CUSTOMER contact defined on contract, we use it |
| 270 | - $usecontact=false; |
|
| 271 | - $arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
|
| 270 | + $usecontact = false; |
|
| 271 | + $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); |
|
| 272 | 272 | if (count($arrayidcontact) > 0) |
| 273 | 273 | { |
| 274 | - $usecontact=true; |
|
| 275 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
| 274 | + $usecontact = true; |
|
| 275 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | // Recipient name |
| 279 | - if (! empty($usecontact)) |
|
| 279 | + if (!empty($usecontact)) |
|
| 280 | 280 | { |
| 281 | 281 | // On peut utiliser le nom de la societe du contact |
| 282 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 282 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 283 | 283 | else { |
| 284 | 284 | $socobject = $object->thirdparty; |
| 285 | 285 | // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | } |
| 289 | 289 | else |
| 290 | 290 | { |
| 291 | - $socobject=$object->thirdparty; |
|
| 291 | + $socobject = $object->thirdparty; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $object->fetch_optionals(); |
@@ -296,31 +296,31 @@ discard block |
||
| 296 | 296 | |
| 297 | 297 | // Define substitution array |
| 298 | 298 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
| 299 | - $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
| 300 | - $array_objet=$this->get_substitutionarray_object($object,$outputlangs); // complete with vars not set as properties by get_substitutionarray_each_var_object |
|
| 301 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
| 302 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
| 303 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
| 304 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
| 299 | + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
| 300 | + $array_objet = $this->get_substitutionarray_object($object, $outputlangs); // complete with vars not set as properties by get_substitutionarray_each_var_object |
|
| 301 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
| 302 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
| 303 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
| 304 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
| 305 | 305 | // retrieve contact information for use in contract as contact_xxx tags |
| 306 | 306 | $array_thirdparty_contact = array(); |
| 307 | - if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
| 307 | + if ($usecontact) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
| 308 | 308 | |
| 309 | - $substitutionarray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); |
|
| 309 | + $substitutionarray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact); |
|
| 310 | 310 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
| 311 | 311 | |
| 312 | 312 | $tmparray = $substitutionarray; |
| 313 | 313 | |
| 314 | 314 | // Call the ODTSubstitution hook |
| 315 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 316 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 315 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 316 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 317 | 317 | |
| 318 | 318 | // Line of free text |
| 319 | - $newfreetext=''; |
|
| 320 | - $paramfreetext='CONTRACT_FREE_TEXT'; |
|
| 321 | - if (! empty($conf->global->$paramfreetext)) |
|
| 319 | + $newfreetext = ''; |
|
| 320 | + $paramfreetext = 'CONTRACT_FREE_TEXT'; |
|
| 321 | + if (!empty($conf->global->$paramfreetext)) |
|
| 322 | 322 | { |
| 323 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$tmparray); |
|
| 323 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $tmparray); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | |
@@ -331,15 +331,15 @@ discard block |
||
| 331 | 331 | $srctemplatepath, |
| 332 | 332 | array( |
| 333 | 333 | 'PATH_TO_TMP' => $conf->contrat->dir_temp, |
| 334 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 334 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 335 | 335 | 'DELIMITER_LEFT' => '{', |
| 336 | 336 | 'DELIMITER_RIGHT' => '}' |
| 337 | 337 | ) |
| 338 | 338 | ); |
| 339 | 339 | } |
| 340 | - catch(Exception $e) |
|
| 340 | + catch (Exception $e) |
|
| 341 | 341 | { |
| 342 | - $this->error=$e->getMessage(); |
|
| 342 | + $this->error = $e->getMessage(); |
|
| 343 | 343 | return -1; |
| 344 | 344 | } |
| 345 | 345 | // After construction $odfHandler->contentXml contains content and |
@@ -353,14 +353,14 @@ discard block |
||
| 353 | 353 | try { |
| 354 | 354 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
| 355 | 355 | } |
| 356 | - catch(OdfException $e) |
|
| 356 | + catch (OdfException $e) |
|
| 357 | 357 | { |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - foreach($tmparray as $key=>$value) |
|
| 360 | + foreach ($tmparray as $key=>$value) |
|
| 361 | 361 | { |
| 362 | 362 | try { |
| 363 | - if (preg_match('/logo$/',$key)) // Image |
|
| 363 | + if (preg_match('/logo$/', $key)) // Image |
|
| 364 | 364 | { |
| 365 | 365 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
| 366 | 366 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | - catch(OdfException $e) |
|
| 373 | + catch (OdfException $e) |
|
| 374 | 374 | { |
| 375 | 375 | } |
| 376 | 376 | } |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | try { |
| 383 | 383 | $listlines = $odfHandler->setSegment('lines'); |
| 384 | 384 | } |
| 385 | - catch(OdfException $e) |
|
| 385 | + catch (OdfException $e) |
|
| 386 | 386 | { |
| 387 | 387 | // We may arrive here if tags for lines not present into template |
| 388 | 388 | $foundtagforlines = 0; |
@@ -392,21 +392,21 @@ discard block |
||
| 392 | 392 | { |
| 393 | 393 | foreach ($object->lines as $line) |
| 394 | 394 | { |
| 395 | - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); |
|
| 395 | + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs); |
|
| 396 | 396 | complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
| 397 | 397 | // Call the ODTSubstitutionLine hook |
| 398 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
| 399 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 400 | - foreach($tmparray as $key => $val) |
|
| 398 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); |
|
| 399 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 400 | + foreach ($tmparray as $key => $val) |
|
| 401 | 401 | { |
| 402 | 402 | try |
| 403 | 403 | { |
| 404 | 404 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 405 | 405 | } |
| 406 | - catch(OdfException $e) |
|
| 406 | + catch (OdfException $e) |
|
| 407 | 407 | { |
| 408 | 408 | } |
| 409 | - catch(SegmentException $e) |
|
| 409 | + catch (SegmentException $e) |
|
| 410 | 410 | { |
| 411 | 411 | } |
| 412 | 412 | } |
@@ -415,61 +415,61 @@ discard block |
||
| 415 | 415 | $odfHandler->mergeSegment($listlines); |
| 416 | 416 | } |
| 417 | 417 | } |
| 418 | - catch(OdfException $e) |
|
| 418 | + catch (OdfException $e) |
|
| 419 | 419 | { |
| 420 | - $this->error=$e->getMessage(); |
|
| 420 | + $this->error = $e->getMessage(); |
|
| 421 | 421 | dol_syslog($this->error, LOG_WARNING); |
| 422 | 422 | return -1; |
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | // Replace labels translated |
| 426 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
| 427 | - foreach($tmparray as $key=>$value) |
|
| 426 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
| 427 | + foreach ($tmparray as $key=>$value) |
|
| 428 | 428 | { |
| 429 | 429 | try { |
| 430 | 430 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 431 | 431 | } |
| 432 | - catch(OdfException $e) |
|
| 432 | + catch (OdfException $e) |
|
| 433 | 433 | { |
| 434 | 434 | } |
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | // Call the beforeODTSave hook |
| 438 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); |
|
| 439 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 438 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); |
|
| 439 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 440 | 440 | |
| 441 | 441 | // Write new file |
| 442 | 442 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
| 443 | 443 | try { |
| 444 | 444 | $odfHandler->exportAsAttachedPDF($file); |
| 445 | - }catch (Exception $e){ |
|
| 446 | - $this->error=$e->getMessage(); |
|
| 445 | + } catch (Exception $e) { |
|
| 446 | + $this->error = $e->getMessage(); |
|
| 447 | 447 | return -1; |
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | else { |
| 451 | 451 | try { |
| 452 | 452 | $odfHandler->saveToDisk($file); |
| 453 | - }catch (Exception $e){ |
|
| 454 | - $this->error=$e->getMessage(); |
|
| 453 | + } catch (Exception $e) { |
|
| 454 | + $this->error = $e->getMessage(); |
|
| 455 | 455 | return -1; |
| 456 | 456 | } |
| 457 | 457 | } |
| 458 | 458 | |
| 459 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 459 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 460 | 460 | |
| 461 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 461 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 462 | 462 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 463 | 463 | |
| 464 | - $odfHandler=null; // Destroy object |
|
| 464 | + $odfHandler = null; // Destroy object |
|
| 465 | 465 | |
| 466 | 466 | $this->result = array('fullpath'=>$file); |
| 467 | 467 | |
| 468 | - return 1; // Success |
|
| 468 | + return 1; // Success |
|
| 469 | 469 | } |
| 470 | 470 | else |
| 471 | 471 | { |
| 472 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 472 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 473 | 473 | return -1; |
| 474 | 474 | } |
| 475 | 475 | } |
@@ -37,9 +37,9 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal |
| 39 | 39 | { |
| 40 | - var $emetteur; // Objet societe qui emet |
|
| 40 | + var $emetteur; // Objet societe qui emet |
|
| 41 | 41 | |
| 42 | - var $phpmin = array(5,2,0); // Minimum version of PHP required by module |
|
| 42 | + var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module |
|
| 43 | 43 | var $version = 'dolibarr'; |
| 44 | 44 | |
| 45 | 45 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | function __construct($db) |
| 52 | 52 | { |
| 53 | - global $conf,$langs,$mysoc; |
|
| 53 | + global $conf, $langs, $mysoc; |
|
| 54 | 54 | |
| 55 | 55 | $langs->load("main"); |
| 56 | 56 | $langs->load("companies"); |
@@ -58,32 +58,32 @@ discard block |
||
| 58 | 58 | $this->db = $db; |
| 59 | 59 | $this->name = "ODT templates"; |
| 60 | 60 | $this->description = $langs->trans("DocumentModelOdt"); |
| 61 | - $this->scandir = 'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 61 | + $this->scandir = 'SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 62 | 62 | |
| 63 | 63 | // Dimension page pour format A4 |
| 64 | 64 | $this->type = 'odt'; |
| 65 | 65 | $this->page_largeur = 0; |
| 66 | 66 | $this->page_hauteur = 0; |
| 67 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
| 68 | - $this->marge_gauche=0; |
|
| 69 | - $this->marge_droite=0; |
|
| 70 | - $this->marge_haute=0; |
|
| 71 | - $this->marge_basse=0; |
|
| 72 | - |
|
| 73 | - $this->option_logo = 1; // Affiche logo |
|
| 74 | - $this->option_tva = 0; // Gere option tva PROPALE_TVAOPTION |
|
| 75 | - $this->option_modereg = 0; // Affiche mode reglement |
|
| 76 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
| 77 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 78 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 79 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 80 | - $this->option_credit_note = 0; // Support credit notes |
|
| 81 | - $this->option_freetext = 1; // Support add of a personalised text |
|
| 82 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 67 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
| 68 | + $this->marge_gauche = 0; |
|
| 69 | + $this->marge_droite = 0; |
|
| 70 | + $this->marge_haute = 0; |
|
| 71 | + $this->marge_basse = 0; |
|
| 72 | + |
|
| 73 | + $this->option_logo = 1; // Affiche logo |
|
| 74 | + $this->option_tva = 0; // Gere option tva PROPALE_TVAOPTION |
|
| 75 | + $this->option_modereg = 0; // Affiche mode reglement |
|
| 76 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
| 77 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 78 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 79 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 80 | + $this->option_credit_note = 0; // Support credit notes |
|
| 81 | + $this->option_freetext = 1; // Support add of a personalised text |
|
| 82 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 83 | 83 | |
| 84 | 84 | // Recupere emetteur |
| 85 | - $this->emetteur=$mysoc; |
|
| 86 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
| 85 | + $this->emetteur = $mysoc; |
|
| 86 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | function info($langs) |
| 97 | 97 | { |
| 98 | - global $conf,$langs; |
|
| 98 | + global $conf, $langs; |
|
| 99 | 99 | |
| 100 | 100 | $langs->load("companies"); |
| 101 | 101 | $langs->load("errors"); |
@@ -103,106 +103,106 @@ discard block |
||
| 103 | 103 | $form = new Form($this->db); |
| 104 | 104 | |
| 105 | 105 | $texte = $this->description.".<br>\n"; |
| 106 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 107 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 108 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 109 | - $texte.= '<input type="hidden" name="param1" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH">'; |
|
| 106 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 107 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 108 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 109 | + $texte .= '<input type="hidden" name="param1" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH">'; |
|
| 110 | 110 | if ($conf->global->MAIN_SUPPLIER_PROPOSAL_CHOOSE_ODT_DOCUMENT > 0) |
| 111 | 111 | { |
| 112 | - $texte.= '<input type="hidden" name="param2" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT">'; |
|
| 113 | - $texte.= '<input type="hidden" name="param3" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL">'; |
|
| 114 | - $texte.= '<input type="hidden" name="param4" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED">'; |
|
| 112 | + $texte .= '<input type="hidden" name="param2" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT">'; |
|
| 113 | + $texte .= '<input type="hidden" name="param3" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL">'; |
|
| 114 | + $texte .= '<input type="hidden" name="param4" value="SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED">'; |
|
| 115 | 115 | } |
| 116 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
| 116 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
| 117 | 117 | |
| 118 | 118 | // List of directories area |
| 119 | - $texte.= '<tr><td>'; |
|
| 120 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
| 121 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH))); |
|
| 122 | - $listoffiles=array(); |
|
| 123 | - foreach($listofdir as $key=>$tmpdir) |
|
| 119 | + $texte .= '<tr><td>'; |
|
| 120 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
| 121 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH))); |
|
| 122 | + $listoffiles = array(); |
|
| 123 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 124 | 124 | { |
| 125 | - $tmpdir=trim($tmpdir); |
|
| 126 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 127 | - if (! $tmpdir) { |
|
| 125 | + $tmpdir = trim($tmpdir); |
|
| 126 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 127 | + if (!$tmpdir) { |
|
| 128 | 128 | unset($listofdir[$key]); continue; |
| 129 | 129 | } |
| 130 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 130 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 131 | 131 | else |
| 132 | 132 | { |
| 133 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
| 134 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 133 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
| 134 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 137 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 138 | 138 | // Add list of substitution keys |
| 139 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 140 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 141 | - |
|
| 142 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
| 143 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 144 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
| 145 | - $texte.=$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH; |
|
| 146 | - $texte.= '</textarea>'; |
|
| 147 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 148 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 149 | - $texte.= '<br></div></div>'; |
|
| 139 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 140 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 141 | + |
|
| 142 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
| 143 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 144 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
| 145 | + $texte .= $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH; |
|
| 146 | + $texte .= '</textarea>'; |
|
| 147 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 148 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 149 | + $texte .= '<br></div></div>'; |
|
| 150 | 150 | |
| 151 | 151 | // Scan directories |
| 152 | - $nbofiles=count($listoffiles); |
|
| 153 | - if (! empty($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH)) |
|
| 152 | + $nbofiles = count($listoffiles); |
|
| 153 | + if (!empty($conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_PATH)) |
|
| 154 | 154 | { |
| 155 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 155 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 156 | 156 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
| 157 | - $texte.=count($listoffiles); |
|
| 157 | + $texte .= count($listoffiles); |
|
| 158 | 158 | //$texte.=$nbofiles?'</a>':''; |
| 159 | - $texte.='</b>'; |
|
| 159 | + $texte .= '</b>'; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | if ($nbofiles) |
| 163 | 163 | { |
| 164 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 165 | - foreach($listoffiles as $file) |
|
| 164 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 165 | + foreach ($listoffiles as $file) |
|
| 166 | 166 | { |
| 167 | - $texte.=$file['name'].'<br>'; |
|
| 167 | + $texte .= $file['name'].'<br>'; |
|
| 168 | 168 | } |
| 169 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
| 169 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
| 170 | 170 | |
| 171 | 171 | if ($conf->global->MAIN_SUPPLIER_PROPOSAL_CHOOSE_ODT_DOCUMENT > 0) |
| 172 | 172 | { |
| 173 | 173 | // Model for creation |
| 174 | - $liste=ModelePDFSupplierProposal::liste_modeles($this->db); |
|
| 175 | - $texte.= '<table width="50%;">'; |
|
| 176 | - $texte.= '<tr>'; |
|
| 177 | - $texte.= '<td width="60%;">'.$langs->trans("DefaultModelSupplierProposalCreate").'</td>'; |
|
| 178 | - $texte.= '<td colspan="">'; |
|
| 179 | - $texte.= $form->selectarray('value2',$liste,$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT); |
|
| 180 | - $texte.= "</td></tr>"; |
|
| 181 | - |
|
| 182 | - $texte.= '<tr>'; |
|
| 183 | - $texte.= '<td width="60%;">'.$langs->trans("DefaultModelSupplierProposalToBill").'</td>'; |
|
| 184 | - $texte.= '<td colspan="">'; |
|
| 185 | - $texte.= $form->selectarray('value3',$liste,$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL); |
|
| 186 | - $texte.= "</td></tr>"; |
|
| 187 | - $texte.= '<tr>'; |
|
| 188 | - |
|
| 189 | - $texte.= '<td width="60%;">'.$langs->trans("DefaultModelSupplierProposalClosed").'</td>'; |
|
| 190 | - $texte.= '<td colspan="">'; |
|
| 191 | - $texte.= $form->selectarray('value4',$liste,$conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED); |
|
| 192 | - $texte.= "</td></tr>"; |
|
| 193 | - $texte.= '</table>'; |
|
| 174 | + $liste = ModelePDFSupplierProposal::liste_modeles($this->db); |
|
| 175 | + $texte .= '<table width="50%;">'; |
|
| 176 | + $texte .= '<tr>'; |
|
| 177 | + $texte .= '<td width="60%;">'.$langs->trans("DefaultModelSupplierProposalCreate").'</td>'; |
|
| 178 | + $texte .= '<td colspan="">'; |
|
| 179 | + $texte .= $form->selectarray('value2', $liste, $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_DEFAULT); |
|
| 180 | + $texte .= "</td></tr>"; |
|
| 181 | + |
|
| 182 | + $texte .= '<tr>'; |
|
| 183 | + $texte .= '<td width="60%;">'.$langs->trans("DefaultModelSupplierProposalToBill").'</td>'; |
|
| 184 | + $texte .= '<td colspan="">'; |
|
| 185 | + $texte .= $form->selectarray('value3', $liste, $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_TOBILL); |
|
| 186 | + $texte .= "</td></tr>"; |
|
| 187 | + $texte .= '<tr>'; |
|
| 188 | + |
|
| 189 | + $texte .= '<td width="60%;">'.$langs->trans("DefaultModelSupplierProposalClosed").'</td>'; |
|
| 190 | + $texte .= '<td colspan="">'; |
|
| 191 | + $texte .= $form->selectarray('value4', $liste, $conf->global->SUPPLIER_PROPOSAL_ADDON_PDF_ODT_CLOSED); |
|
| 192 | + $texte .= "</td></tr>"; |
|
| 193 | + $texte .= '</table>'; |
|
| 194 | 194 | } |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $texte.= '</td>'; |
|
| 197 | + $texte .= '</td>'; |
|
| 198 | 198 | |
| 199 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 200 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 201 | - $texte.= '</td>'; |
|
| 202 | - $texte.= '</tr>'; |
|
| 199 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 200 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 201 | + $texte .= '</td>'; |
|
| 202 | + $texte .= '</tr>'; |
|
| 203 | 203 | |
| 204 | - $texte.= '</table>'; |
|
| 205 | - $texte.= '</form>'; |
|
| 204 | + $texte .= '</table>'; |
|
| 205 | + $texte .= '</form>'; |
|
| 206 | 206 | |
| 207 | 207 | return $texte; |
| 208 | 208 | } |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | * @param int $hideref Do not show ref |
| 219 | 219 | * @return int 1 if OK, <=0 if KO |
| 220 | 220 | */ |
| 221 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
| 221 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
| 222 | 222 | { |
| 223 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
| 223 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
| 224 | 224 | |
| 225 | 225 | if (empty($srctemplatepath)) |
| 226 | 226 | { |
@@ -229,17 +229,17 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Add odtgeneration hook |
| 232 | - if (! is_object($hookmanager)) |
|
| 232 | + if (!is_object($hookmanager)) |
|
| 233 | 233 | { |
| 234 | 234 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
| 235 | - $hookmanager=new HookManager($this->db); |
|
| 235 | + $hookmanager = new HookManager($this->db); |
|
| 236 | 236 | } |
| 237 | 237 | $hookmanager->initHooks(array('odtgeneration')); |
| 238 | 238 | global $action; |
| 239 | 239 | |
| 240 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
| 241 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 242 | - $outputlangs->charset_output='UTF-8'; |
|
| 240 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
| 241 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 242 | + $outputlangs->charset_output = 'UTF-8'; |
|
| 243 | 243 | |
| 244 | 244 | $outputlangs->load("main"); |
| 245 | 245 | $outputlangs->load("dict"); |
@@ -249,28 +249,28 @@ discard block |
||
| 249 | 249 | if ($conf->supplier_proposal->dir_output) |
| 250 | 250 | { |
| 251 | 251 | // If $object is id instead of object |
| 252 | - if (! is_object($object)) |
|
| 252 | + if (!is_object($object)) |
|
| 253 | 253 | { |
| 254 | 254 | $id = $object; |
| 255 | 255 | $object = new SupplierProposal($this->db); |
| 256 | - $result=$object->fetch($id); |
|
| 256 | + $result = $object->fetch($id); |
|
| 257 | 257 | if ($result < 0) |
| 258 | 258 | { |
| 259 | - dol_print_error($this->db,$object->error); |
|
| 259 | + dol_print_error($this->db, $object->error); |
|
| 260 | 260 | return -1; |
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | $dir = $conf->supplier_proposal->dir_output; |
| 265 | 265 | $objectref = dol_sanitizeFileName($object->ref); |
| 266 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
| 267 | - $file = $dir . "/" . $objectref . ".odt"; |
|
| 266 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
| 267 | + $file = $dir."/".$objectref.".odt"; |
|
| 268 | 268 | |
| 269 | - if (! file_exists($dir)) |
|
| 269 | + if (!file_exists($dir)) |
|
| 270 | 270 | { |
| 271 | 271 | if (dol_mkdir($dir) < 0) |
| 272 | 272 | { |
| 273 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 273 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 274 | 274 | return -1; |
| 275 | 275 | } |
| 276 | 276 | } |
@@ -278,26 +278,26 @@ discard block |
||
| 278 | 278 | if (file_exists($dir)) |
| 279 | 279 | { |
| 280 | 280 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
| 281 | - $newfile=basename($srctemplatepath); |
|
| 282 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
| 283 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
| 284 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
| 281 | + $newfile = basename($srctemplatepath); |
|
| 282 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
| 283 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
| 284 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
| 285 | 285 | |
| 286 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
| 286 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
| 287 | 287 | |
| 288 | 288 | // Get extension (ods or odt) |
| 289 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
| 290 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 289 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
| 290 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 291 | 291 | { |
| 292 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
| 293 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
| 294 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
| 292 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
| 293 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
| 294 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
| 295 | 295 | } |
| 296 | 296 | else |
| 297 | 297 | { |
| 298 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
| 298 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
| 299 | 299 | } |
| 300 | - $file=$dir.'/'.$filename; |
|
| 300 | + $file = $dir.'/'.$filename; |
|
| 301 | 301 | //print "newdir=".$dir; |
| 302 | 302 | //print "newfile=".$newfile; |
| 303 | 303 | //print "file=".$file; |
@@ -307,28 +307,28 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | |
| 309 | 309 | // If BILLING contact defined on invoice, we use it |
| 310 | - $usecontact=false; |
|
| 311 | - $arrayidcontact=$object->getIdContact('external','BILLING'); |
|
| 310 | + $usecontact = false; |
|
| 311 | + $arrayidcontact = $object->getIdContact('external', 'BILLING'); |
|
| 312 | 312 | if (count($arrayidcontact) > 0) |
| 313 | 313 | { |
| 314 | - $usecontact=true; |
|
| 315 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
| 314 | + $usecontact = true; |
|
| 315 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Recipient name |
| 319 | - if (! empty($usecontact)) |
|
| 319 | + if (!empty($usecontact)) |
|
| 320 | 320 | { |
| 321 | 321 | // On peut utiliser le nom de la societe du contact |
| 322 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 322 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 323 | 323 | else $socobject = $object->thirdparty; |
| 324 | 324 | } |
| 325 | 325 | else |
| 326 | 326 | { |
| 327 | - $socobject=$object->thirdparty; |
|
| 327 | + $socobject = $object->thirdparty; |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | // Make substitution |
| 331 | - $substitutionarray=array( |
|
| 331 | + $substitutionarray = array( |
|
| 332 | 332 | '__FROM_NAME__' => $this->emetteur->name, |
| 333 | 333 | '__FROM_EMAIL__' => $this->emetteur->email, |
| 334 | 334 | '__TOTAL_TTC__' => $object->total_ttc, |
@@ -337,15 +337,15 @@ discard block |
||
| 337 | 337 | ); |
| 338 | 338 | complete_substitutions_array($substitutionarray, $langs, $object); |
| 339 | 339 | // Call the ODTSubstitution hook |
| 340 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
| 341 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 340 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray); |
|
| 341 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 342 | 342 | |
| 343 | 343 | // Line of free text |
| 344 | - $newfreetext=''; |
|
| 345 | - $paramfreetext='SUPPLIER_PROPOSAL_FREE_TEXT'; |
|
| 346 | - if (! empty($conf->global->$paramfreetext)) |
|
| 344 | + $newfreetext = ''; |
|
| 345 | + $paramfreetext = 'SUPPLIER_PROPOSAL_FREE_TEXT'; |
|
| 346 | + if (!empty($conf->global->$paramfreetext)) |
|
| 347 | 347 | { |
| 348 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
| 348 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | // Open and load template |
@@ -355,15 +355,15 @@ discard block |
||
| 355 | 355 | $srctemplatepath, |
| 356 | 356 | array( |
| 357 | 357 | 'PATH_TO_TMP' => $conf->supplier_proposal->dir_temp, |
| 358 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 358 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 359 | 359 | 'DELIMITER_LEFT' => '{', |
| 360 | 360 | 'DELIMITER_RIGHT' => '}' |
| 361 | 361 | ) |
| 362 | 362 | ); |
| 363 | 363 | } |
| 364 | - catch(Exception $e) |
|
| 364 | + catch (Exception $e) |
|
| 365 | 365 | { |
| 366 | - $this->error=$e->getMessage(); |
|
| 366 | + $this->error = $e->getMessage(); |
|
| 367 | 367 | return -1; |
| 368 | 368 | } |
| 369 | 369 | // After construction $odfHandler->contentXml contains content and |
@@ -377,29 +377,29 @@ discard block |
||
| 377 | 377 | try { |
| 378 | 378 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
| 379 | 379 | } |
| 380 | - catch(OdfException $e) |
|
| 380 | + catch (OdfException $e) |
|
| 381 | 381 | { |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | // Define substitution array |
| 385 | 385 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
| 386 | - $array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
| 387 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
| 388 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
| 389 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
| 390 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
| 386 | + $array_objet = $this->get_substitutionarray_object($object, $outputlangs); |
|
| 387 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
| 388 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
| 389 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
| 390 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
| 391 | 391 | |
| 392 | - $tmparray = array_merge($substitutionarray,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other); |
|
| 392 | + $tmparray = array_merge($substitutionarray, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other); |
|
| 393 | 393 | complete_substitutions_array($tmparray, $outputlangs, $object); |
| 394 | 394 | |
| 395 | 395 | // Call the ODTSubstitution hook |
| 396 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 397 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 396 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 397 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 398 | 398 | |
| 399 | - foreach($tmparray as $key=>$value) |
|
| 399 | + foreach ($tmparray as $key=>$value) |
|
| 400 | 400 | { |
| 401 | 401 | try { |
| 402 | - if (preg_match('/logo$/',$key)) // Image |
|
| 402 | + if (preg_match('/logo$/', $key)) // Image |
|
| 403 | 403 | { |
| 404 | 404 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
| 405 | 405 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 410 | 410 | } |
| 411 | 411 | } |
| 412 | - catch(OdfException $e) |
|
| 412 | + catch (OdfException $e) |
|
| 413 | 413 | { |
| 414 | 414 | } |
| 415 | 415 | } |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | try { |
| 421 | 421 | $listlines = $odfHandler->setSegment('lines'); |
| 422 | 422 | } |
| 423 | - catch(OdfException $e) |
|
| 423 | + catch (OdfException $e) |
|
| 424 | 424 | { |
| 425 | 425 | // We may arrive here if tags for lines not present into template |
| 426 | 426 | $foundtagforlines = 0; |
@@ -430,21 +430,21 @@ discard block |
||
| 430 | 430 | { |
| 431 | 431 | foreach ($object->lines as $line) |
| 432 | 432 | { |
| 433 | - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); |
|
| 433 | + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs); |
|
| 434 | 434 | complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
| 435 | 435 | // Call the ODTSubstitutionLine hook |
| 436 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
| 437 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 438 | - foreach($tmparray as $key => $val) |
|
| 436 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); |
|
| 437 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 438 | + foreach ($tmparray as $key => $val) |
|
| 439 | 439 | { |
| 440 | 440 | try |
| 441 | 441 | { |
| 442 | 442 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 443 | 443 | } |
| 444 | - catch(OdfException $e) |
|
| 444 | + catch (OdfException $e) |
|
| 445 | 445 | { |
| 446 | 446 | } |
| 447 | - catch(SegmentException $e) |
|
| 447 | + catch (SegmentException $e) |
|
| 448 | 448 | { |
| 449 | 449 | } |
| 450 | 450 | } |
@@ -453,61 +453,61 @@ discard block |
||
| 453 | 453 | $odfHandler->mergeSegment($listlines); |
| 454 | 454 | } |
| 455 | 455 | } |
| 456 | - catch(OdfException $e) |
|
| 456 | + catch (OdfException $e) |
|
| 457 | 457 | { |
| 458 | - $this->error=$e->getMessage(); |
|
| 458 | + $this->error = $e->getMessage(); |
|
| 459 | 459 | dol_syslog($this->error, LOG_WARNING); |
| 460 | 460 | return -1; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Replace labels translated |
| 464 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
| 465 | - foreach($tmparray as $key=>$value) |
|
| 464 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
| 465 | + foreach ($tmparray as $key=>$value) |
|
| 466 | 466 | { |
| 467 | 467 | try { |
| 468 | 468 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 469 | 469 | } |
| 470 | - catch(OdfException $e) |
|
| 470 | + catch (OdfException $e) |
|
| 471 | 471 | { |
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | // Call the beforeODTSave hook |
| 476 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 477 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 476 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 477 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 478 | 478 | |
| 479 | 479 | // Write new file |
| 480 | 480 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
| 481 | 481 | try { |
| 482 | 482 | $odfHandler->exportAsAttachedPDF($file); |
| 483 | - }catch (Exception $e){ |
|
| 484 | - $this->error=$e->getMessage(); |
|
| 483 | + } catch (Exception $e) { |
|
| 484 | + $this->error = $e->getMessage(); |
|
| 485 | 485 | return -1; |
| 486 | 486 | } |
| 487 | 487 | } |
| 488 | 488 | else { |
| 489 | 489 | try { |
| 490 | 490 | $odfHandler->saveToDisk($file); |
| 491 | - }catch (Exception $e){ |
|
| 492 | - $this->error=$e->getMessage(); |
|
| 491 | + } catch (Exception $e) { |
|
| 492 | + $this->error = $e->getMessage(); |
|
| 493 | 493 | return -1; |
| 494 | 494 | } |
| 495 | 495 | } |
| 496 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 497 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 496 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 497 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 498 | 498 | |
| 499 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 499 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 500 | 500 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 501 | 501 | |
| 502 | - $odfHandler=null; // Destroy object |
|
| 502 | + $odfHandler = null; // Destroy object |
|
| 503 | 503 | |
| 504 | 504 | $this->result = array('fullpath'=>$file); |
| 505 | 505 | |
| 506 | - return 1; // Success |
|
| 506 | + return 1; // Success |
|
| 507 | 507 | } |
| 508 | 508 | else |
| 509 | 509 | { |
| 510 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 510 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 511 | 511 | return -1; |
| 512 | 512 | } |
| 513 | 513 | } |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | class doc_generic_order_odt extends ModelePDFCommandes |
| 40 | 40 | { |
| 41 | - var $emetteur; // Objet societe qui emet |
|
| 41 | + var $emetteur; // Objet societe qui emet |
|
| 42 | 42 | |
| 43 | - var $phpmin = array(5,2,0); // Minimum version of PHP required by module |
|
| 43 | + var $phpmin = array(5, 2, 0); // Minimum version of PHP required by module |
|
| 44 | 44 | var $version = 'dolibarr'; |
| 45 | 45 | |
| 46 | 46 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function __construct($db) |
| 53 | 53 | { |
| 54 | - global $conf,$langs,$mysoc; |
|
| 54 | + global $conf, $langs, $mysoc; |
|
| 55 | 55 | |
| 56 | 56 | $langs->load("main"); |
| 57 | 57 | $langs->load("companies"); |
@@ -59,32 +59,32 @@ discard block |
||
| 59 | 59 | $this->db = $db; |
| 60 | 60 | $this->name = "ODT templates"; |
| 61 | 61 | $this->description = $langs->trans("DocumentModelOdt"); |
| 62 | - $this->scandir = 'COMMANDE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 62 | + $this->scandir = 'COMMANDE_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
| 63 | 63 | |
| 64 | 64 | // Dimension page pour format A4 |
| 65 | 65 | $this->type = 'odt'; |
| 66 | 66 | $this->page_largeur = 0; |
| 67 | 67 | $this->page_hauteur = 0; |
| 68 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
| 69 | - $this->marge_gauche=0; |
|
| 70 | - $this->marge_droite=0; |
|
| 71 | - $this->marge_haute=0; |
|
| 72 | - $this->marge_basse=0; |
|
| 73 | - |
|
| 74 | - $this->option_logo = 1; // Affiche logo |
|
| 75 | - $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION |
|
| 76 | - $this->option_modereg = 0; // Affiche mode reglement |
|
| 77 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
| 78 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 79 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 80 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 81 | - $this->option_credit_note = 0; // Support credit notes |
|
| 82 | - $this->option_freetext = 1; // Support add of a personalised text |
|
| 83 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 68 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
| 69 | + $this->marge_gauche = 0; |
|
| 70 | + $this->marge_droite = 0; |
|
| 71 | + $this->marge_haute = 0; |
|
| 72 | + $this->marge_basse = 0; |
|
| 73 | + |
|
| 74 | + $this->option_logo = 1; // Affiche logo |
|
| 75 | + $this->option_tva = 0; // Gere option tva COMMANDE_TVAOPTION |
|
| 76 | + $this->option_modereg = 0; // Affiche mode reglement |
|
| 77 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
| 78 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
| 79 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
| 80 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
| 81 | + $this->option_credit_note = 0; // Support credit notes |
|
| 82 | + $this->option_freetext = 1; // Support add of a personalised text |
|
| 83 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
| 84 | 84 | |
| 85 | 85 | // Recupere emetteur |
| 86 | - $this->emetteur=$mysoc; |
|
| 87 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
| 86 | + $this->emetteur = $mysoc; |
|
| 87 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | */ |
| 97 | 97 | function info($langs) |
| 98 | 98 | { |
| 99 | - global $conf,$langs; |
|
| 99 | + global $conf, $langs; |
|
| 100 | 100 | |
| 101 | 101 | $langs->load("companies"); |
| 102 | 102 | $langs->load("errors"); |
@@ -104,75 +104,75 @@ discard block |
||
| 104 | 104 | $form = new Form($this->db); |
| 105 | 105 | |
| 106 | 106 | $texte = $this->description.".<br>\n"; |
| 107 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 108 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 109 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 110 | - $texte.= '<input type="hidden" name="param1" value="COMMANDE_ADDON_PDF_ODT_PATH">'; |
|
| 111 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
| 107 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
| 108 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 109 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
| 110 | + $texte .= '<input type="hidden" name="param1" value="COMMANDE_ADDON_PDF_ODT_PATH">'; |
|
| 111 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
| 112 | 112 | |
| 113 | 113 | // List of directories area |
| 114 | - $texte.= '<tr><td>'; |
|
| 115 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
| 116 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->COMMANDE_ADDON_PDF_ODT_PATH))); |
|
| 117 | - $listoffiles=array(); |
|
| 118 | - foreach($listofdir as $key=>$tmpdir) |
|
| 114 | + $texte .= '<tr><td>'; |
|
| 115 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
| 116 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->COMMANDE_ADDON_PDF_ODT_PATH))); |
|
| 117 | + $listoffiles = array(); |
|
| 118 | + foreach ($listofdir as $key=>$tmpdir) |
|
| 119 | 119 | { |
| 120 | - $tmpdir=trim($tmpdir); |
|
| 121 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
| 122 | - if (! $tmpdir) { |
|
| 120 | + $tmpdir = trim($tmpdir); |
|
| 121 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
| 122 | + if (!$tmpdir) { |
|
| 123 | 123 | unset($listofdir[$key]); continue; |
| 124 | 124 | } |
| 125 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
| 125 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
| 126 | 126 | else |
| 127 | 127 | { |
| 128 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
| 129 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 128 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
| 129 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 132 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
| 133 | 133 | // Add list of substitution keys |
| 134 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 135 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 136 | - |
|
| 137 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
| 138 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 139 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
| 140 | - $texte.=$conf->global->COMMANDE_ADDON_PDF_ODT_PATH; |
|
| 141 | - $texte.= '</textarea>'; |
|
| 142 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 143 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 144 | - $texte.= '<br></div></div>'; |
|
| 134 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
| 135 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
| 136 | + |
|
| 137 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
| 138 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
| 139 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
| 140 | + $texte .= $conf->global->COMMANDE_ADDON_PDF_ODT_PATH; |
|
| 141 | + $texte .= '</textarea>'; |
|
| 142 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
| 143 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
| 144 | + $texte .= '<br></div></div>'; |
|
| 145 | 145 | |
| 146 | 146 | // Scan directories |
| 147 | - $nbofiles=count($listoffiles); |
|
| 148 | - if (! empty($conf->global->COMMANDE_ADDON_PDF_ODT_PATH)) |
|
| 147 | + $nbofiles = count($listoffiles); |
|
| 148 | + if (!empty($conf->global->COMMANDE_ADDON_PDF_ODT_PATH)) |
|
| 149 | 149 | { |
| 150 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 150 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
| 151 | 151 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
| 152 | - $texte.=count($listoffiles); |
|
| 152 | + $texte .= count($listoffiles); |
|
| 153 | 153 | //$texte.=$nbofiles?'</a>':''; |
| 154 | - $texte.='</b>'; |
|
| 154 | + $texte .= '</b>'; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if ($nbofiles) |
| 158 | 158 | { |
| 159 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 160 | - foreach($listoffiles as $file) |
|
| 159 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
| 160 | + foreach ($listoffiles as $file) |
|
| 161 | 161 | { |
| 162 | - $texte.=$file['name'].'<br>'; |
|
| 162 | + $texte .= $file['name'].'<br>'; |
|
| 163 | 163 | } |
| 164 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
| 164 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - $texte.= '</td>'; |
|
| 167 | + $texte .= '</td>'; |
|
| 168 | 168 | |
| 169 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 170 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 171 | - $texte.= '</td>'; |
|
| 172 | - $texte.= '</tr>'; |
|
| 169 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
| 170 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
| 171 | + $texte .= '</td>'; |
|
| 172 | + $texte .= '</tr>'; |
|
| 173 | 173 | |
| 174 | - $texte.= '</table>'; |
|
| 175 | - $texte.= '</form>'; |
|
| 174 | + $texte .= '</table>'; |
|
| 175 | + $texte .= '</form>'; |
|
| 176 | 176 | |
| 177 | 177 | return $texte; |
| 178 | 178 | } |
@@ -188,9 +188,9 @@ discard block |
||
| 188 | 188 | * @param int $hideref Do not show ref |
| 189 | 189 | * @return int 1 if OK, <=0 if KO |
| 190 | 190 | */ |
| 191 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
| 191 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
| 192 | 192 | { |
| 193 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
| 193 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
| 194 | 194 | |
| 195 | 195 | if (empty($srctemplatepath)) |
| 196 | 196 | { |
@@ -199,17 +199,17 @@ discard block |
||
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | // Add odtgeneration hook |
| 202 | - if (! is_object($hookmanager)) |
|
| 202 | + if (!is_object($hookmanager)) |
|
| 203 | 203 | { |
| 204 | 204 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
| 205 | - $hookmanager=new HookManager($this->db); |
|
| 205 | + $hookmanager = new HookManager($this->db); |
|
| 206 | 206 | } |
| 207 | 207 | $hookmanager->initHooks(array('odtgeneration')); |
| 208 | 208 | global $action; |
| 209 | 209 | |
| 210 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
| 211 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 212 | - $outputlangs->charset_output='UTF-8'; |
|
| 210 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
| 211 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 212 | + $outputlangs->charset_output = 'UTF-8'; |
|
| 213 | 213 | |
| 214 | 214 | $outputlangs->load("main"); |
| 215 | 215 | $outputlangs->load("dict"); |
@@ -219,28 +219,28 @@ discard block |
||
| 219 | 219 | if ($conf->commande->dir_output) |
| 220 | 220 | { |
| 221 | 221 | // If $object is id instead of object |
| 222 | - if (! is_object($object)) |
|
| 222 | + if (!is_object($object)) |
|
| 223 | 223 | { |
| 224 | 224 | $id = $object; |
| 225 | 225 | $object = new Commande($this->db); |
| 226 | - $result=$object->fetch($id); |
|
| 226 | + $result = $object->fetch($id); |
|
| 227 | 227 | if ($result < 0) |
| 228 | 228 | { |
| 229 | - dol_print_error($this->db,$object->error); |
|
| 229 | + dol_print_error($this->db, $object->error); |
|
| 230 | 230 | return -1; |
| 231 | 231 | } |
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | $dir = $conf->commande->dir_output; |
| 235 | 235 | $objectref = dol_sanitizeFileName($object->ref); |
| 236 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
| 237 | - $file = $dir . "/" . $objectref . ".odt"; |
|
| 236 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
| 237 | + $file = $dir."/".$objectref.".odt"; |
|
| 238 | 238 | |
| 239 | - if (! file_exists($dir)) |
|
| 239 | + if (!file_exists($dir)) |
|
| 240 | 240 | { |
| 241 | 241 | if (dol_mkdir($dir) < 0) |
| 242 | 242 | { |
| 243 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 243 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 244 | 244 | return -1; |
| 245 | 245 | } |
| 246 | 246 | } |
@@ -248,25 +248,25 @@ discard block |
||
| 248 | 248 | if (file_exists($dir)) |
| 249 | 249 | { |
| 250 | 250 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
| 251 | - $newfile=basename($srctemplatepath); |
|
| 252 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
| 253 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
| 254 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
| 255 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
| 251 | + $newfile = basename($srctemplatepath); |
|
| 252 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
| 253 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
| 254 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
| 255 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
| 256 | 256 | //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
| 257 | 257 | // Get extension (ods or odt) |
| 258 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
| 259 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 258 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
| 259 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
| 260 | 260 | { |
| 261 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
| 262 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
| 263 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
| 261 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
| 262 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
| 263 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
| 264 | 264 | } |
| 265 | 265 | else |
| 266 | 266 | { |
| 267 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
| 267 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
| 268 | 268 | } |
| 269 | - $file=$dir.'/'.$filename; |
|
| 269 | + $file = $dir.'/'.$filename; |
|
| 270 | 270 | //print "newdir=".$dir; |
| 271 | 271 | //print "newfile=".$newfile; |
| 272 | 272 | //print "file=".$file; |
@@ -276,19 +276,19 @@ discard block |
||
| 276 | 276 | |
| 277 | 277 | |
| 278 | 278 | // If CUSTOMER contact defined on order, we use it |
| 279 | - $usecontact=false; |
|
| 280 | - $arrayidcontact=$object->getIdContact('external','CUSTOMER'); |
|
| 279 | + $usecontact = false; |
|
| 280 | + $arrayidcontact = $object->getIdContact('external', 'CUSTOMER'); |
|
| 281 | 281 | if (count($arrayidcontact) > 0) |
| 282 | 282 | { |
| 283 | - $usecontact=true; |
|
| 284 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
| 283 | + $usecontact = true; |
|
| 284 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | // Recipient name |
| 288 | - if (! empty($usecontact)) |
|
| 288 | + if (!empty($usecontact)) |
|
| 289 | 289 | { |
| 290 | 290 | // On peut utiliser le nom de la societe du contact |
| 291 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 291 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) $socobject = $object->contact; |
|
| 292 | 292 | else { |
| 293 | 293 | $socobject = $object->thirdparty; |
| 294 | 294 | // if we have a CUSTOMER contact and we dont use it as recipient we store the contact object for later use |
@@ -297,11 +297,11 @@ discard block |
||
| 297 | 297 | } |
| 298 | 298 | else |
| 299 | 299 | { |
| 300 | - $socobject=$object->thirdparty; |
|
| 300 | + $socobject = $object->thirdparty; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | // Make substitution |
| 304 | - $substitutionarray=array( |
|
| 304 | + $substitutionarray = array( |
|
| 305 | 305 | '__FROM_NAME__' => $this->emetteur->name, |
| 306 | 306 | '__FROM_EMAIL__' => $this->emetteur->email, |
| 307 | 307 | '__TOTAL_TTC__' => $object->total_ttc, |
@@ -310,15 +310,15 @@ discard block |
||
| 310 | 310 | ); |
| 311 | 311 | complete_substitutions_array($substitutionarray, $langs, $object); |
| 312 | 312 | // Call the ODTSubstitution hook |
| 313 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
| 314 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 313 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray); |
|
| 314 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 315 | 315 | |
| 316 | 316 | // Line of free text |
| 317 | - $newfreetext=''; |
|
| 318 | - $paramfreetext='ORDER_FREE_TEXT'; |
|
| 319 | - if (! empty($conf->global->$paramfreetext)) |
|
| 317 | + $newfreetext = ''; |
|
| 318 | + $paramfreetext = 'ORDER_FREE_TEXT'; |
|
| 319 | + if (!empty($conf->global->$paramfreetext)) |
|
| 320 | 320 | { |
| 321 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
| 321 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | // Open and load template |
@@ -328,15 +328,15 @@ discard block |
||
| 328 | 328 | $srctemplatepath, |
| 329 | 329 | array( |
| 330 | 330 | 'PATH_TO_TMP' => $conf->commande->dir_temp, |
| 331 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 331 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
| 332 | 332 | 'DELIMITER_LEFT' => '{', |
| 333 | 333 | 'DELIMITER_RIGHT' => '}' |
| 334 | 334 | ) |
| 335 | 335 | ); |
| 336 | 336 | } |
| 337 | - catch(Exception $e) |
|
| 337 | + catch (Exception $e) |
|
| 338 | 338 | { |
| 339 | - $this->error=$e->getMessage(); |
|
| 339 | + $this->error = $e->getMessage(); |
|
| 340 | 340 | return -1; |
| 341 | 341 | } |
| 342 | 342 | // After construction $odfHandler->contentXml contains content and |
@@ -350,33 +350,33 @@ discard block |
||
| 350 | 350 | try { |
| 351 | 351 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
| 352 | 352 | } |
| 353 | - catch(OdfException $e) |
|
| 353 | + catch (OdfException $e) |
|
| 354 | 354 | { |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | // Define substitution array |
| 358 | 358 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
| 359 | - $array_object_from_properties=$this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
| 360 | - $array_objet=$this->get_substitutionarray_object($object,$outputlangs); |
|
| 361 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
| 362 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
| 363 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
| 364 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
| 359 | + $array_object_from_properties = $this->get_substitutionarray_each_var_object($object, $outputlangs); |
|
| 360 | + $array_objet = $this->get_substitutionarray_object($object, $outputlangs); |
|
| 361 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
| 362 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
| 363 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
| 364 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
| 365 | 365 | // retrieve contact information for use in order as contact_xxx tags |
| 366 | 366 | $array_thirdparty_contact = array(); |
| 367 | - if ($usecontact) $array_thirdparty_contact=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
| 367 | + if ($usecontact) $array_thirdparty_contact = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
| 368 | 368 | |
| 369 | - $tmparray = array_merge($substitutionarray,$array_object_from_properties,$array_user,$array_soc,$array_thirdparty,$array_objet,$array_other,$array_thirdparty_contact); |
|
| 369 | + $tmparray = array_merge($substitutionarray, $array_object_from_properties, $array_user, $array_soc, $array_thirdparty, $array_objet, $array_other, $array_thirdparty_contact); |
|
| 370 | 370 | complete_substitutions_array($tmparray, $outputlangs, $object); |
| 371 | 371 | |
| 372 | 372 | // Call the ODTSubstitution hook |
| 373 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 374 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 373 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 374 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 375 | 375 | |
| 376 | - foreach($tmparray as $key=>$value) |
|
| 376 | + foreach ($tmparray as $key=>$value) |
|
| 377 | 377 | { |
| 378 | 378 | try { |
| 379 | - if (preg_match('/logo$/',$key)) // Image |
|
| 379 | + if (preg_match('/logo$/', $key)) // Image |
|
| 380 | 380 | { |
| 381 | 381 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
| 382 | 382 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | - catch(OdfException $e) |
|
| 389 | + catch (OdfException $e) |
|
| 390 | 390 | { |
| 391 | 391 | } |
| 392 | 392 | } |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | try { |
| 398 | 398 | $listlines = $odfHandler->setSegment('lines'); |
| 399 | 399 | } |
| 400 | - catch(OdfException $e) |
|
| 400 | + catch (OdfException $e) |
|
| 401 | 401 | { |
| 402 | 402 | // We may arrive here if tags for lines not present into template |
| 403 | 403 | $foundtagforlines = 0; |
@@ -407,21 +407,21 @@ discard block |
||
| 407 | 407 | { |
| 408 | 408 | foreach ($object->lines as $line) |
| 409 | 409 | { |
| 410 | - $tmparray=$this->get_substitutionarray_lines($line,$outputlangs); |
|
| 410 | + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs); |
|
| 411 | 411 | complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
| 412 | 412 | // Call the ODTSubstitutionLine hook |
| 413 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
| 414 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 415 | - foreach($tmparray as $key => $val) |
|
| 413 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); |
|
| 414 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 415 | + foreach ($tmparray as $key => $val) |
|
| 416 | 416 | { |
| 417 | 417 | try |
| 418 | 418 | { |
| 419 | 419 | $listlines->setVars($key, $val, true, 'UTF-8'); |
| 420 | 420 | } |
| 421 | - catch(OdfException $e) |
|
| 421 | + catch (OdfException $e) |
|
| 422 | 422 | { |
| 423 | 423 | } |
| 424 | - catch(SegmentException $e) |
|
| 424 | + catch (SegmentException $e) |
|
| 425 | 425 | { |
| 426 | 426 | } |
| 427 | 427 | } |
@@ -430,63 +430,63 @@ discard block |
||
| 430 | 430 | $odfHandler->mergeSegment($listlines); |
| 431 | 431 | } |
| 432 | 432 | } |
| 433 | - catch(OdfException $e) |
|
| 433 | + catch (OdfException $e) |
|
| 434 | 434 | { |
| 435 | - $this->error=$e->getMessage(); |
|
| 435 | + $this->error = $e->getMessage(); |
|
| 436 | 436 | dol_syslog($this->error, LOG_WARNING); |
| 437 | 437 | return -1; |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // Replace labels translated |
| 441 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
| 442 | - foreach($tmparray as $key=>$value) |
|
| 441 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
| 442 | + foreach ($tmparray as $key=>$value) |
|
| 443 | 443 | { |
| 444 | 444 | try { |
| 445 | 445 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
| 446 | 446 | } |
| 447 | - catch(OdfException $e) |
|
| 447 | + catch (OdfException $e) |
|
| 448 | 448 | { |
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | // Call the beforeODTSave hook |
| 453 | 453 | |
| 454 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 455 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 454 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 455 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 456 | 456 | |
| 457 | 457 | // Write new file |
| 458 | 458 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
| 459 | 459 | try { |
| 460 | 460 | $odfHandler->exportAsAttachedPDF($file); |
| 461 | - }catch (Exception $e){ |
|
| 462 | - $this->error=$e->getMessage(); |
|
| 461 | + } catch (Exception $e) { |
|
| 462 | + $this->error = $e->getMessage(); |
|
| 463 | 463 | return -1; |
| 464 | 464 | } |
| 465 | 465 | } |
| 466 | 466 | else { |
| 467 | 467 | try { |
| 468 | 468 | $odfHandler->saveToDisk($file); |
| 469 | - }catch (Exception $e){ |
|
| 470 | - $this->error=$e->getMessage(); |
|
| 469 | + } catch (Exception $e) { |
|
| 470 | + $this->error = $e->getMessage(); |
|
| 471 | 471 | return -1; |
| 472 | 472 | } |
| 473 | 473 | } |
| 474 | 474 | |
| 475 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
| 476 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
| 475 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
| 476 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
| 477 | 477 | |
| 478 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 478 | + if (!empty($conf->global->MAIN_UMASK)) |
|
| 479 | 479 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
| 480 | 480 | |
| 481 | - $odfHandler=null; // Destroy object |
|
| 481 | + $odfHandler = null; // Destroy object |
|
| 482 | 482 | |
| 483 | 483 | $this->result = array('fullpath'=>$file); |
| 484 | 484 | |
| 485 | - return 1; // Success |
|
| 485 | + return 1; // Success |
|
| 486 | 486 | } |
| 487 | 487 | else |
| 488 | 488 | { |
| 489 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
| 489 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
| 490 | 490 | return -1; |
| 491 | 491 | } |
| 492 | 492 | } |