@@ -36,8 +36,8 @@ discard block |
||
| 36 | 36 | //! Used to store current currency (ISO code like 'USD', 'EUR', ...) |
| 37 | 37 | public $currency; |
| 38 | 38 | //! Used to store current css (from theme) |
| 39 | - public $theme; // Contains current theme ("eldy", "auguria", ...)
|
|
| 40 | - public $css; // Contains full path of css page ("/theme/eldy/style.css.php", ...)
|
|
| 39 | + public $theme; // Contains current theme ("eldy", "auguria", ...)
|
|
| 40 | + public $css; // Contains full path of css page ("/theme/eldy/style.css.php", ...)
|
|
| 41 | 41 | //! Used to store current menu handler |
| 42 | 42 | public $standard_menu; |
| 43 | 43 | public $modules = array(); // List of activated modules |
@@ -54,11 +54,11 @@ discard block |
||
| 54 | 54 | public $entity = 1; |
| 55 | 55 | //! Used to store list of entities to use for each element |
| 56 | 56 | public $entities = array(); |
| 57 | - public $dol_hide_topmenu; // Set if we force param dol_hide_topmenu into login url |
|
| 58 | - public $dol_hide_leftmenu; // Set if we force param dol_hide_leftmenu into login url |
|
| 57 | + public $dol_hide_topmenu; // Set if we force param dol_hide_topmenu into login url |
|
| 58 | + public $dol_hide_leftmenu; // Set if we force param dol_hide_leftmenu into login url |
|
| 59 | 59 | public $dol_optimize_smallscreen; // Set if we force param dol_optimize_smallscreen into login url or if browser is smartphone |
| 60 | - public $dol_no_mouse_hover; // Set if we force param dol_no_mouse_hover into login url or if browser is smartphone |
|
| 61 | - public $dol_use_jmobile; // Set if we force param dol_use_jmobile into login url |
|
| 60 | + public $dol_no_mouse_hover; // Set if we force param dol_no_mouse_hover into login url or if browser is smartphone |
|
| 61 | + public $dol_use_jmobile; // Set if we force param dol_use_jmobile into login url |
|
| 62 | 62 | |
| 63 | 63 | /** |
| 64 | 64 | * Constructor |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $this->multicompany = new \stdClass(); |
| 80 | 80 | |
| 81 | 81 | //! Charset for HTML output and for storing data in memory |
| 82 | - $this->file->character_set_client = 'UTF-8'; // UTF-8, ISO-8859-1 |
|
| 82 | + $this->file->character_set_client = 'UTF-8'; // UTF-8, ISO-8859-1 |
|
| 83 | 83 | // First level object |
| 84 | 84 | // TODO Remove this part. |
| 85 | 85 | $this->expedition_bon = new \stdClass(); |
@@ -113,13 +113,13 @@ discard block |
||
| 113 | 113 | {
|
| 114 | 114 | global $conf; |
| 115 | 115 | |
| 116 | - dol_syslog(get_class($this) . "::setValues"); |
|
| 116 | + dol_syslog(get_class($this)."::setValues"); |
|
| 117 | 117 | |
| 118 | 118 | //Define all global constants into $this->global->key=value |
| 119 | - $sql = "SELECT " . $db->decrypt('name') . " as name,";
|
|
| 120 | - $sql .= " " . $db->decrypt('value') . " as value, entity";
|
|
| 121 | - $sql .= " FROM " . MAIN_DB_PREFIX . "const"; |
|
| 122 | - $sql .= " WHERE entity IN (0," . $this->entity . ")"; |
|
| 119 | + $sql = "SELECT ".$db->decrypt('name')." as name,";
|
|
| 120 | + $sql .= " ".$db->decrypt('value')." as value, entity";
|
|
| 121 | + $sql .= " FROM ".MAIN_DB_PREFIX."const"; |
|
| 122 | + $sql .= " WHERE entity IN (0,".$this->entity.")"; |
|
| 123 | 123 | $sql .= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite. |
| 124 | 124 | |
| 125 | 125 | $resql = $db->query($sql); |
@@ -159,13 +159,13 @@ discard block |
||
| 159 | 159 | if (is_array($arrValue) && !empty($arrValue)) |
| 160 | 160 | $value = $arrValue; |
| 161 | 161 | else if (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl')))
|
| 162 | - $value = '/' . $modulename . '/core/' . $partname . '/'; |
|
| 162 | + $value = '/'.$modulename.'/core/'.$partname.'/'; |
|
| 163 | 163 | else if (in_array($partname, array('models', 'theme')))
|
| 164 | - $value = '/' . $modulename . '/'; |
|
| 164 | + $value = '/'.$modulename.'/'; |
|
| 165 | 165 | else if (in_array($partname, array('sms')))
|
| 166 | - $value = '/' . $modulename . '/'; |
|
| 166 | + $value = '/'.$modulename.'/'; |
|
| 167 | 167 | else if ($value == 1) |
| 168 | - $value = '/' . $modulename . '/core/modules/' . $partname . '/'; // ex: partname = societe |
|
| 168 | + $value = '/'.$modulename.'/core/modules/'.$partname.'/'; // ex: partname = societe |
|
| 169 | 169 | $this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value)); // $value may be a string or an array |
| 170 | 170 | } |
| 171 | 171 | // If this is a module constant (must be at end) |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | if (!isset($this->$modulename) || !is_object($this->$modulename)) |
| 179 | 179 | $this->$modulename = new \stdClass(); |
| 180 | 180 | $this->$modulename->enabled = true; |
| 181 | - $this->modules[] = $modulename; // Add this module in list of enabled modules |
|
| 181 | + $this->modules[] = $modulename; // Add this module in list of enabled modules |
|
| 182 | 182 | } |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | $filesList = explode(":", $this->global->LOCAL_CONSTS_FILES);
|
| 194 | 194 | foreach ($filesList as $file) {
|
| 195 | 195 | $file = dol_sanitizeFileName($file); |
| 196 | - include_once DOL_DOCUMENT_ROOT . "/" . $file . "/" . $file . "_consts.php"; |
|
| 196 | + include_once DOL_DOCUMENT_ROOT."/".$file."/".$file."_consts.php"; |
|
| 197 | 197 | foreach ($file2bddconsts as $key => $value) {
|
| 198 | 198 | $this->global->$key = $value; |
| 199 | 199 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | try {
|
| 210 | 210 | date_default_timezone_set($this->global->MAIN_SERVER_TZ); |
| 211 | 211 | } catch (Exception $e) {
|
| 212 | - dol_syslog("Error: Bad value for parameter MAIN_SERVER_TZ=" . $this->global->MAIN_SERVER_TZ, LOG_ERR);
|
|
| 212 | + dol_syslog("Error: Bad value for parameter MAIN_SERVER_TZ=".$this->global->MAIN_SERVER_TZ, LOG_ERR);
|
|
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | 215 | |
@@ -269,18 +269,18 @@ discard block |
||
| 269 | 269 | $rootforuser = DOL_DATA_ROOT; |
| 270 | 270 | // If multicompany module is enabled, we redefine the root of data |
| 271 | 271 | if (!empty($this->multicompany->enabled) && !empty($this->entity) && $this->entity > 1) {
|
| 272 | - $rootfordata .= '/' . $this->entity; |
|
| 272 | + $rootfordata .= '/'.$this->entity; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // Define default dir_output and dir_temp for directories of modules |
| 276 | 276 | foreach ($this->modules as $module) {
|
| 277 | 277 | //var_dump($module); |
| 278 | 278 | // For multicompany sharings |
| 279 | - $this->$module->multidir_output = array($this->entity => $rootfordata . "/" . $module); |
|
| 280 | - $this->$module->multidir_temp = array($this->entity => $rootfordata . "/" . $module . "/temp"); |
|
| 279 | + $this->$module->multidir_output = array($this->entity => $rootfordata."/".$module); |
|
| 280 | + $this->$module->multidir_temp = array($this->entity => $rootfordata."/".$module."/temp"); |
|
| 281 | 281 | // For backward compatibility |
| 282 | - $this->$module->dir_output = $rootfordata . "/" . $module; |
|
| 283 | - $this->$module->dir_temp = $rootfordata . "/" . $module . "/temp"; |
|
| 282 | + $this->$module->dir_output = $rootfordata."/".$module; |
|
| 283 | + $this->$module->dir_temp = $rootfordata."/".$module."/temp"; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // External modules storage |
@@ -290,45 +290,45 @@ discard block |
||
| 290 | 290 | foreach ($dirs as $type => $name) {
|
| 291 | 291 | $subdir = ($type == 'temp' ? '/temp' : ''); |
| 292 | 292 | // For multicompany sharings |
| 293 | - $varname = 'multidir_' . $type; |
|
| 294 | - $this->$module->$varname = array($this->entity => $rootfordata . "/" . $name . $subdir); |
|
| 293 | + $varname = 'multidir_'.$type; |
|
| 294 | + $this->$module->$varname = array($this->entity => $rootfordata."/".$name.$subdir); |
|
| 295 | 295 | // For backward compatibility |
| 296 | - $varname = 'dir_' . $type; |
|
| 297 | - $this->$module->$varname = $rootfordata . "/" . $name . $subdir; |
|
| 296 | + $varname = 'dir_'.$type; |
|
| 297 | + $this->$module->$varname = $rootfordata."/".$name.$subdir; |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | // For mycompany storage |
| 304 | - $this->mycompany->dir_output = $rootfordata . "/mycompany"; |
|
| 305 | - $this->mycompany->dir_temp = $rootfordata . "/mycompany/temp"; |
|
| 304 | + $this->mycompany->dir_output = $rootfordata."/mycompany"; |
|
| 305 | + $this->mycompany->dir_temp = $rootfordata."/mycompany/temp"; |
|
| 306 | 306 | |
| 307 | 307 | // For admin storage |
| 308 | - $this->admin->dir_output = $rootfordata . '/admin'; |
|
| 309 | - $this->admin->dir_temp = $rootfordata . '/admin/temp'; |
|
| 308 | + $this->admin->dir_output = $rootfordata.'/admin'; |
|
| 309 | + $this->admin->dir_temp = $rootfordata.'/admin/temp'; |
|
| 310 | 310 | |
| 311 | 311 | // For user storage |
| 312 | - $this->user->multidir_output = array($this->entity => $rootfordata . "/users"); |
|
| 313 | - $this->user->multidir_temp = array($this->entity => $rootfordata . "/users/temp"); |
|
| 312 | + $this->user->multidir_output = array($this->entity => $rootfordata."/users"); |
|
| 313 | + $this->user->multidir_temp = array($this->entity => $rootfordata."/users/temp"); |
|
| 314 | 314 | // For backward compatibility |
| 315 | - $this->user->dir_output = $rootforuser . "/users"; |
|
| 316 | - $this->user->dir_temp = $rootforuser . "/users/temp"; |
|
| 315 | + $this->user->dir_output = $rootforuser."/users"; |
|
| 316 | + $this->user->dir_temp = $rootforuser."/users/temp"; |
|
| 317 | 317 | |
| 318 | 318 | // For usergroup storage |
| 319 | - $this->usergroup->dir_output = $rootforuser . "/usergroups"; |
|
| 320 | - $this->usergroup->dir_temp = $rootforuser . "/usergroups/temp"; |
|
| 319 | + $this->usergroup->dir_output = $rootforuser."/usergroups"; |
|
| 320 | + $this->usergroup->dir_temp = $rootforuser."/usergroups/temp"; |
|
| 321 | 321 | |
| 322 | 322 | // For proposal storage |
| 323 | - $this->propal->multidir_output = array($this->entity => $rootfordata . "/propale"); |
|
| 324 | - $this->propal->multidir_temp = array($this->entity => $rootfordata . "/propale/temp"); |
|
| 323 | + $this->propal->multidir_output = array($this->entity => $rootfordata."/propale"); |
|
| 324 | + $this->propal->multidir_temp = array($this->entity => $rootfordata."/propale/temp"); |
|
| 325 | 325 | // For backward compatibility |
| 326 | - $this->propal->dir_output = $rootfordata . "/propale"; |
|
| 327 | - $this->propal->dir_temp = $rootfordata . "/propale/temp"; |
|
| 326 | + $this->propal->dir_output = $rootfordata."/propale"; |
|
| 327 | + $this->propal->dir_temp = $rootfordata."/propale/temp"; |
|
| 328 | 328 | |
| 329 | 329 | // For medias storage |
| 330 | - $this->medias->multidir_output = array($this->entity => $rootfordata . "/medias"); |
|
| 331 | - $this->medias->multidir_temp = array($this->entity => $rootfordata . "/medias/temp"); |
|
| 330 | + $this->medias->multidir_output = array($this->entity => $rootfordata."/medias"); |
|
| 331 | + $this->medias->multidir_temp = array($this->entity => $rootfordata."/medias/temp"); |
|
| 332 | 332 | |
| 333 | 333 | // Exception: Some dir are not the name of module. So we keep exception here for backward compatibility. |
| 334 | 334 | // Sous module bons d'expedition |
@@ -339,72 +339,72 @@ discard block |
||
| 339 | 339 | // Module fournisseur |
| 340 | 340 | if (!empty($this->fournisseur)) {
|
| 341 | 341 | $this->fournisseur->commande = new \stdClass(); |
| 342 | - $this->fournisseur->commande->multidir_output = array($this->entity => $rootfordata . "/fournisseur/commande"); |
|
| 343 | - $this->fournisseur->commande->multidir_temp = array($this->entity => $rootfordata . "/fournisseur/commande/temp"); |
|
| 344 | - $this->fournisseur->commande->dir_output = $rootfordata . "/fournisseur/commande"; // For backward compatibility |
|
| 345 | - $this->fournisseur->commande->dir_temp = $rootfordata . "/fournisseur/commande/temp"; // For backward compatibility |
|
| 342 | + $this->fournisseur->commande->multidir_output = array($this->entity => $rootfordata."/fournisseur/commande"); |
|
| 343 | + $this->fournisseur->commande->multidir_temp = array($this->entity => $rootfordata."/fournisseur/commande/temp"); |
|
| 344 | + $this->fournisseur->commande->dir_output = $rootfordata."/fournisseur/commande"; // For backward compatibility |
|
| 345 | + $this->fournisseur->commande->dir_temp = $rootfordata."/fournisseur/commande/temp"; // For backward compatibility |
|
| 346 | 346 | $this->fournisseur->facture = new \stdClass(); |
| 347 | - $this->fournisseur->facture->multidir_output = array($this->entity => $rootfordata . "/fournisseur/facture"); |
|
| 348 | - $this->fournisseur->facture->multidir_temp = array($this->entity => $rootfordata . "/fournisseur/facture/temp"); |
|
| 349 | - $this->fournisseur->facture->dir_output = $rootfordata . "/fournisseur/facture"; // For backward compatibility |
|
| 350 | - $this->fournisseur->facture->dir_temp = $rootfordata . "/fournisseur/facture/temp"; // For backward compatibility |
|
| 347 | + $this->fournisseur->facture->multidir_output = array($this->entity => $rootfordata."/fournisseur/facture"); |
|
| 348 | + $this->fournisseur->facture->multidir_temp = array($this->entity => $rootfordata."/fournisseur/facture/temp"); |
|
| 349 | + $this->fournisseur->facture->dir_output = $rootfordata."/fournisseur/facture"; // For backward compatibility |
|
| 350 | + $this->fournisseur->facture->dir_temp = $rootfordata."/fournisseur/facture/temp"; // For backward compatibility |
|
| 351 | 351 | $this->supplierproposal = new \stdClass(); |
| 352 | - $this->supplierproposal->multidir_output = array($this->entity => $rootfordata . "/supplier_proposal"); |
|
| 353 | - $this->supplierproposal->multidir_temp = array($this->entity => $rootfordata . "/supplier_proposal/temp"); |
|
| 354 | - $this->supplierproposal->dir_output = $rootfordata . "/supplier_proposal"; // For backward compatibility |
|
| 355 | - $this->supplierproposal->dir_temp = $rootfordata . "/supplier_proposal/temp"; // For backward compatibility |
|
| 352 | + $this->supplierproposal->multidir_output = array($this->entity => $rootfordata."/supplier_proposal"); |
|
| 353 | + $this->supplierproposal->multidir_temp = array($this->entity => $rootfordata."/supplier_proposal/temp"); |
|
| 354 | + $this->supplierproposal->dir_output = $rootfordata."/supplier_proposal"; // For backward compatibility |
|
| 355 | + $this->supplierproposal->dir_temp = $rootfordata."/supplier_proposal/temp"; // For backward compatibility |
|
| 356 | 356 | $this->fournisseur->payment = new \stdClass(); |
| 357 | - $this->fournisseur->payment->multidir_output = array($this->entity => $rootfordata . "/fournisseur/payment"); |
|
| 358 | - $this->fournisseur->payment->multidir_temp = array($this->entity => $rootfordata . "/fournisseur/payment/temp"); |
|
| 359 | - $this->fournisseur->payment->dir_output = $rootfordata . "/fournisseur/payment"; // For backward compatibility |
|
| 360 | - $this->fournisseur->payment->dir_temp = $rootfordata . "/fournisseur/payment/temp"; // For backward compatibility |
|
| 357 | + $this->fournisseur->payment->multidir_output = array($this->entity => $rootfordata."/fournisseur/payment"); |
|
| 358 | + $this->fournisseur->payment->multidir_temp = array($this->entity => $rootfordata."/fournisseur/payment/temp"); |
|
| 359 | + $this->fournisseur->payment->dir_output = $rootfordata."/fournisseur/payment"; // For backward compatibility |
|
| 360 | + $this->fournisseur->payment->dir_temp = $rootfordata."/fournisseur/payment/temp"; // For backward compatibility |
|
| 361 | 361 | // To prepare split of module fournisseur into fournisseur + supplier_order + supplier_invoice |
| 362 | 362 | if (!empty($this->fournisseur->enabled) && empty($this->global->MAIN_USE_NEW_SUPPLIERMOD)) { // By default, if module supplier is on, we set new properties
|
| 363 | 363 | $this->supplier_order = new \stdClass(); |
| 364 | 364 | $this->supplier_order->enabled = 1; |
| 365 | - $this->supplier_order->multidir_output = array($this->entity => $rootfordata . "/fournisseur/commande"); |
|
| 366 | - $this->supplier_order->multidir_temp = array($this->entity => $rootfordata . "/fournisseur/commande/temp"); |
|
| 367 | - $this->supplier_order->dir_output = $rootfordata . "/fournisseur/commande"; // For backward compatibility |
|
| 368 | - $this->supplier_order->dir_temp = $rootfordata . "/fournisseur/commande/temp"; // For backward compatibility |
|
| 365 | + $this->supplier_order->multidir_output = array($this->entity => $rootfordata."/fournisseur/commande"); |
|
| 366 | + $this->supplier_order->multidir_temp = array($this->entity => $rootfordata."/fournisseur/commande/temp"); |
|
| 367 | + $this->supplier_order->dir_output = $rootfordata."/fournisseur/commande"; // For backward compatibility |
|
| 368 | + $this->supplier_order->dir_temp = $rootfordata."/fournisseur/commande/temp"; // For backward compatibility |
|
| 369 | 369 | $this->supplier_invoice = new \stdClass(); |
| 370 | 370 | $this->supplier_invoice->enabled = 1; |
| 371 | - $this->supplier_invoice->multidir_output = array($this->entity => $rootfordata . "/fournisseur/facture"); |
|
| 372 | - $this->supplier_invoice->multidir_temp = array($this->entity => $rootfordata . "/fournisseur/facture/temp"); |
|
| 373 | - $this->supplier_invoice->dir_output = $rootfordata . "/fournisseur/facture"; // For backward compatibility |
|
| 374 | - $this->supplier_invoice->dir_temp = $rootfordata . "/fournisseur/facture/temp"; // For backward compatibility |
|
| 371 | + $this->supplier_invoice->multidir_output = array($this->entity => $rootfordata."/fournisseur/facture"); |
|
| 372 | + $this->supplier_invoice->multidir_temp = array($this->entity => $rootfordata."/fournisseur/facture/temp"); |
|
| 373 | + $this->supplier_invoice->dir_output = $rootfordata."/fournisseur/facture"; // For backward compatibility |
|
| 374 | + $this->supplier_invoice->dir_temp = $rootfordata."/fournisseur/facture/temp"; // For backward compatibility |
|
| 375 | 375 | $this->supplierproposal = new \stdClass(); |
| 376 | - $this->supplierproposal->multidir_output = array($this->entity => $rootfordata . "/supplier_proposal"); |
|
| 377 | - $this->supplierproposal->multidir_temp = array($this->entity => $rootfordata . "/supplier_proposal/temp"); |
|
| 378 | - $this->supplierproposal->dir_output = $rootfordata . "/supplier_proposal"; // For backward compatibility |
|
| 379 | - $this->supplierproposal->dir_temp = $rootfordata . "/supplier_proposal/temp"; // For backward compatibility |
|
| 376 | + $this->supplierproposal->multidir_output = array($this->entity => $rootfordata."/supplier_proposal"); |
|
| 377 | + $this->supplierproposal->multidir_temp = array($this->entity => $rootfordata."/supplier_proposal/temp"); |
|
| 378 | + $this->supplierproposal->dir_output = $rootfordata."/supplier_proposal"; // For backward compatibility |
|
| 379 | + $this->supplierproposal->dir_temp = $rootfordata."/supplier_proposal/temp"; // For backward compatibility |
|
| 380 | 380 | } |
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | // Module product/service |
| 384 | - $this->product->multidir_output = array($this->entity => $rootfordata . "/produit"); |
|
| 385 | - $this->product->multidir_temp = array($this->entity => $rootfordata . "/produit/temp"); |
|
| 386 | - $this->service->multidir_output = array($this->entity => $rootfordata . "/produit"); |
|
| 387 | - $this->service->multidir_temp = array($this->entity => $rootfordata . "/produit/temp"); |
|
| 384 | + $this->product->multidir_output = array($this->entity => $rootfordata."/produit"); |
|
| 385 | + $this->product->multidir_temp = array($this->entity => $rootfordata."/produit/temp"); |
|
| 386 | + $this->service->multidir_output = array($this->entity => $rootfordata."/produit"); |
|
| 387 | + $this->service->multidir_temp = array($this->entity => $rootfordata."/produit/temp"); |
|
| 388 | 388 | // For backward compatibility |
| 389 | - $this->product->dir_output = $rootfordata . "/produit"; |
|
| 390 | - $this->product->dir_temp = $rootfordata . "/produit/temp"; |
|
| 391 | - $this->service->dir_output = $rootfordata . "/produit"; |
|
| 392 | - $this->service->dir_temp = $rootfordata . "/produit/temp"; |
|
| 389 | + $this->product->dir_output = $rootfordata."/produit"; |
|
| 390 | + $this->product->dir_temp = $rootfordata."/produit/temp"; |
|
| 391 | + $this->service->dir_output = $rootfordata."/produit"; |
|
| 392 | + $this->service->dir_temp = $rootfordata."/produit/temp"; |
|
| 393 | 393 | |
| 394 | 394 | // Module productbatch |
| 395 | - $this->productbatch->multidir_output = array($this->entity => $rootfordata . "/produitlot"); |
|
| 396 | - $this->productbatch->multidir_temp = array($this->entity => $rootfordata . "/produitlot/temp"); |
|
| 395 | + $this->productbatch->multidir_output = array($this->entity => $rootfordata."/produitlot"); |
|
| 396 | + $this->productbatch->multidir_temp = array($this->entity => $rootfordata."/produitlot/temp"); |
|
| 397 | 397 | |
| 398 | 398 | // Module contrat |
| 399 | - $this->contrat->multidir_output = array($this->entity => $rootfordata . "/contract"); |
|
| 400 | - $this->contrat->multidir_temp = array($this->entity => $rootfordata . "/contract/temp"); |
|
| 399 | + $this->contrat->multidir_output = array($this->entity => $rootfordata."/contract"); |
|
| 400 | + $this->contrat->multidir_temp = array($this->entity => $rootfordata."/contract/temp"); |
|
| 401 | 401 | // For backward compatibility |
| 402 | - $this->contrat->dir_output = $rootfordata . "/contract"; |
|
| 403 | - $this->contrat->dir_temp = $rootfordata . "/contract/temp"; |
|
| 402 | + $this->contrat->dir_output = $rootfordata."/contract"; |
|
| 403 | + $this->contrat->dir_temp = $rootfordata."/contract/temp"; |
|
| 404 | 404 | |
| 405 | 405 | // Module bank |
| 406 | - $this->bank->dir_output = $rootfordata . "/bank"; |
|
| 407 | - $this->bank->dir_temp = $rootfordata . "/bank/temp"; |
|
| 406 | + $this->bank->dir_output = $rootfordata."/bank"; |
|
| 407 | + $this->bank->dir_temp = $rootfordata."/bank/temp"; |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | 410 | // Set some default values |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | if (empty($this->global->USER_PASSWORD_GENERATED)) |
| 428 | 428 | $this->global->USER_PASSWORD_GENERATED = 'standard'; // Default password generator |
| 429 | 429 | if (empty($this->global->MAIN_UMASK)) |
| 430 | - $this->global->MAIN_UMASK = '0664'; // Default mask |
|
| 430 | + $this->global->MAIN_UMASK = '0664'; // Default mask |
|
| 431 | 431 | |
| 432 | 432 | |
| 433 | 433 | |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | $this->currency = $this->global->MAIN_MONNAIE; |
| 467 | 467 | |
| 468 | 468 | if (empty($this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)) |
| 469 | - $this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; // Less than 1 minutes to be sure |
|
| 469 | + $this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; // Less than 1 minutes to be sure |
|
| 470 | 470 | |
| 471 | 471 | |
| 472 | 472 | |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | |
| 475 | 475 | // conf->global->ACCOUNTING_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...) |
| 476 | 476 | if (empty($this->global->ACCOUNTING_MODE)) |
| 477 | - $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES'; // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' |
|
| 477 | + $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES'; // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' |
|
| 478 | 478 | |
| 479 | 479 | |
| 480 | 480 | |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | $this->global->MAIN_THEME = $this->global->MAIN_FORCETHEME; |
| 505 | 505 | $this->theme = $this->global->MAIN_THEME; |
| 506 | 506 | //$this->css = "/theme/".$this->theme."/style.css.php"; |
| 507 | - $this->css = '?controller=theme/' . $this->theme . '&method=style.css'; |
|
| 507 | + $this->css = '?controller=theme/'.$this->theme.'&method=style.css'; |
|
| 508 | 508 | |
| 509 | 509 | // conf->email_from = email pour envoi par dolibarr des mails automatiques |
| 510 | 510 | $this->email_from = "[email protected]"; |
@@ -524,8 +524,8 @@ discard block |
||
| 524 | 524 | $this->global->MAIN_EMAIL_ADD_TRACK_ID = 1; |
| 525 | 525 | |
| 526 | 526 | // Format for date (used by default when not found or not searched in lang) |
| 527 | - $this->format_date_short = "%d/%m/%Y"; // Format of day with PHP/C tags (strftime functions) |
|
| 528 | - $this->format_date_short_java = "dd/MM/yyyy"; // Format of day with Java tags |
|
| 527 | + $this->format_date_short = "%d/%m/%Y"; // Format of day with PHP/C tags (strftime functions) |
|
| 528 | + $this->format_date_short_java = "dd/MM/yyyy"; // Format of day with Java tags |
|
| 529 | 529 | $this->format_hour_short = "%H:%M"; |
| 530 | 530 | $this->format_hour_short_duration = "%H:%M"; |
| 531 | 531 | $this->format_date_text_short = "%d %b %Y"; |
@@ -549,9 +549,9 @@ discard block |
||
| 549 | 549 | |
| 550 | 550 | // Default pdf option |
| 551 | 551 | if (!isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) |
| 552 | - $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1; // use dash between lines |
|
| 552 | + $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1; // use dash between lines |
|
| 553 | 553 | if (!isset($this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) |
| 554 | - $this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT = 1; // allow html content into free footer text |
|
| 554 | + $this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT = 1; // allow html content into free footer text |
|
| 555 | 555 | |
| 556 | 556 | |
| 557 | 557 | |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | |
| 567 | 567 | // By default, we propagate contacts |
| 568 | 568 | if (!isset($this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) |
| 569 | - $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN = '*'; // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented) |
|
| 569 | + $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN = '*'; // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented) |
|
| 570 | 570 | |
| 571 | 571 | |
| 572 | 572 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,agenda,resource,adherent,blockedlog'; // '' means 'all'. Note that contact is added here as it should be a module later. |
| 590 | 590 | if (!empty($this->modules_parts['moduleforexternal'])) { // Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list
|
| 591 | 591 | foreach ($this->modules_parts['moduleforexternal'] as $key => $value) |
| 592 | - $this->global->MAIN_MODULES_FOR_EXTERNAL .= "," . $key; |
|
| 592 | + $this->global->MAIN_MODULES_FOR_EXTERNAL .= ",".$key; |
|
| 593 | 593 | } |
| 594 | 594 | |
| 595 | 595 | // Enable select2 |
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | |
| 683 | 683 | // Save inconsistent option |
| 684 | 684 | if (empty($this->global->AGENDA_USE_EVENT_TYPE) && (!isset($this->global->AGENDA_DEFAULT_FILTER_TYPE) || $this->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO')) {
|
| 685 | - $this->global->AGENDA_DEFAULT_FILTER_TYPE = '0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on. |
|
| 685 | + $this->global->AGENDA_DEFAULT_FILTER_TYPE = '0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on. |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | if (!isset($this->global->MAIN_EXTRAFIELDS_IN_ONE_TD)) |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | $dir = dol_buildpath($reldir, 0); |
| 724 | 724 | $newdir = dol_osencode($dir); |
| 725 | 725 | if (is_dir($newdir)) {
|
| 726 | - $file = $newdir . $handler . '.php'; |
|
| 726 | + $file = $newdir.$handler.'.php'; |
|
| 727 | 727 | if (file_exists($file)) {
|
| 728 | 728 | $handler_files[] = $file; |
| 729 | 729 | } |
@@ -731,7 +731,7 @@ discard block |
||
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | if (empty($handler_files)) {
|
| 734 | - throw new Exception('Missing log handler file ' . $handler . '.php');
|
|
| 734 | + throw new Exception('Missing log handler file '.$handler.'.php');
|
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | require_once $handler_files[0]; |
@@ -156,27 +156,32 @@ discard block |
||
| 156 | 156 | $this->modules_parts[$partname] = array(); |
| 157 | 157 | } |
| 158 | 158 | $arrValue = json_decode($value, true); |
| 159 | - if (is_array($arrValue) && !empty($arrValue)) |
|
| 160 | - $value = $arrValue; |
|
| 161 | - else if (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl')))
|
|
| 162 | - $value = '/' . $modulename . '/core/' . $partname . '/'; |
|
| 163 | - else if (in_array($partname, array('models', 'theme')))
|
|
| 164 | - $value = '/' . $modulename . '/'; |
|
| 165 | - else if (in_array($partname, array('sms')))
|
|
| 166 | - $value = '/' . $modulename . '/'; |
|
| 167 | - else if ($value == 1) |
|
| 168 | - $value = '/' . $modulename . '/core/modules/' . $partname . '/'; // ex: partname = societe |
|
| 159 | + if (is_array($arrValue) && !empty($arrValue)) { |
|
| 160 | + $value = $arrValue; |
|
| 161 | + } else if (in_array($partname, array('login', 'menus', 'substitutions', 'triggers', 'tpl'))) { |
|
| 162 | + $value = '/' . $modulename . '/core/' . $partname . '/'; |
|
| 163 | + } else if (in_array($partname, array('models', 'theme'))) { |
|
| 164 | + $value = '/' . $modulename . '/'; |
|
| 165 | + } else if (in_array($partname, array('sms'))) { |
|
| 166 | + $value = '/' . $modulename . '/'; |
|
| 167 | + } else if ($value == 1) { |
|
| 168 | + $value = '/' . $modulename . '/core/modules/' . $partname . '/'; |
|
| 169 | + } |
|
| 170 | + // ex: partname = societe |
|
| 169 | 171 | $this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value)); // $value may be a string or an array |
| 170 | 172 | } |
| 171 | 173 | // If this is a module constant (must be at end) |
| 172 | 174 | elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)$/i', $key, $reg)) {
|
| 173 | 175 | $modulename = strtolower($reg[1]); |
| 174 | - if ($modulename == 'propale') |
|
| 175 | - $modulename = 'propal'; |
|
| 176 | - if ($modulename == 'supplierproposal') |
|
| 177 | - $modulename = 'supplier_proposal'; |
|
| 178 | - if (!isset($this->$modulename) || !is_object($this->$modulename)) |
|
| 179 | - $this->$modulename = new \stdClass(); |
|
| 176 | + if ($modulename == 'propale') { |
|
| 177 | + $modulename = 'propal'; |
|
| 178 | + } |
|
| 179 | + if ($modulename == 'supplierproposal') { |
|
| 180 | + $modulename = 'supplier_proposal'; |
|
| 181 | + } |
|
| 182 | + if (!isset($this->$modulename) || !is_object($this->$modulename)) { |
|
| 183 | + $this->$modulename = new \stdClass(); |
|
| 184 | + } |
|
| 180 | 185 | $this->$modulename->enabled = true; |
| 181 | 186 | $this->modules[] = $modulename; // Add this module in list of enabled modules |
| 182 | 187 | } |
@@ -224,46 +229,60 @@ discard block |
||
| 224 | 229 | } |
| 225 | 230 | |
| 226 | 231 | // Clean some variables |
| 227 | - if (empty($this->global->MAIN_MENU_STANDARD)) |
|
| 228 | - $this->global->MAIN_MENU_STANDARD = "eldy_menu.php"; |
|
| 229 | - if (empty($this->global->MAIN_MENUFRONT_STANDARD)) |
|
| 230 | - $this->global->MAIN_MENUFRONT_STANDARD = "eldy_menu.php"; |
|
| 231 | - if (empty($this->global->MAIN_MENU_SMARTPHONE)) |
|
| 232 | - $this->global->MAIN_MENU_SMARTPHONE = "eldy_menu.php"; // Use eldy by default because smartphone does not work on all phones |
|
| 233 | - if (empty($this->global->MAIN_MENUFRONT_SMARTPHONE)) |
|
| 234 | - $this->global->MAIN_MENUFRONT_SMARTPHONE = "eldy_menu.php"; // Use eldy by default because smartphone does not work on all phones |
|
| 232 | + if (empty($this->global->MAIN_MENU_STANDARD)) { |
|
| 233 | + $this->global->MAIN_MENU_STANDARD = "eldy_menu.php"; |
|
| 234 | + } |
|
| 235 | + if (empty($this->global->MAIN_MENUFRONT_STANDARD)) { |
|
| 236 | + $this->global->MAIN_MENUFRONT_STANDARD = "eldy_menu.php"; |
|
| 237 | + } |
|
| 238 | + if (empty($this->global->MAIN_MENU_SMARTPHONE)) { |
|
| 239 | + $this->global->MAIN_MENU_SMARTPHONE = "eldy_menu.php"; |
|
| 240 | + } |
|
| 241 | + // Use eldy by default because smartphone does not work on all phones |
|
| 242 | + if (empty($this->global->MAIN_MENUFRONT_SMARTPHONE)) { |
|
| 243 | + $this->global->MAIN_MENUFRONT_SMARTPHONE = "eldy_menu.php"; |
|
| 244 | + } |
|
| 245 | + // Use eldy by default because smartphone does not work on all phones |
|
| 235 | 246 | |
| 236 | 247 | |
| 237 | 248 | |
| 238 | 249 | |
| 239 | 250 | // Clean var use vat for company |
| 240 | - if (!isset($this->global->FACTURE_TVAOPTION)) |
|
| 241 | - $this->global->FACTURE_TVAOPTION = 1; |
|
| 242 | - else if (!empty($this->global->FACTURE_TVAOPTION) && !is_numeric($this->global->FACTURE_TVAOPTION)) {
|
|
| 251 | + if (!isset($this->global->FACTURE_TVAOPTION)) { |
|
| 252 | + $this->global->FACTURE_TVAOPTION = 1; |
|
| 253 | + } else if (!empty($this->global->FACTURE_TVAOPTION) && !is_numeric($this->global->FACTURE_TVAOPTION)) {
|
|
| 243 | 254 | // Old value of option, we clean to use new value (0 or 1) |
| 244 | - if ($this->global->FACTURE_TVAOPTION != "franchise") |
|
| 245 | - $this->global->FACTURE_TVAOPTION = 1; |
|
| 246 | - else |
|
| 247 | - $this->global->FACTURE_TVAOPTION = 0; |
|
| 255 | + if ($this->global->FACTURE_TVAOPTION != "franchise") { |
|
| 256 | + $this->global->FACTURE_TVAOPTION = 1; |
|
| 257 | + } else { |
|
| 258 | + $this->global->FACTURE_TVAOPTION = 0; |
|
| 259 | + } |
|
| 248 | 260 | } |
| 249 | 261 | |
| 250 | 262 | // Variable globales LDAP |
| 251 | - if (empty($this->global->LDAP_FIELD_FULLNAME)) |
|
| 252 | - $this->global->LDAP_FIELD_FULLNAME = ''; |
|
| 253 | - if (!isset($this->global->LDAP_KEY_USERS)) |
|
| 254 | - $this->global->LDAP_KEY_USERS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 255 | - if (!isset($this->global->LDAP_KEY_GROUPS)) |
|
| 256 | - $this->global->LDAP_KEY_GROUPS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 257 | - if (!isset($this->global->LDAP_KEY_CONTACTS)) |
|
| 258 | - $this->global->LDAP_KEY_CONTACTS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 259 | - if (!isset($this->global->LDAP_KEY_MEMBERS)) |
|
| 260 | - $this->global->LDAP_KEY_MEMBERS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 261 | - if (!isset($this->global->LDAP_KEY_MEMBERS_TYPES)) |
|
| 262 | - $this->global->LDAP_KEY_MEMBERS_TYPES = $this->global->LDAP_FIELD_FULLNAME; |
|
| 263 | + if (empty($this->global->LDAP_FIELD_FULLNAME)) { |
|
| 264 | + $this->global->LDAP_FIELD_FULLNAME = ''; |
|
| 265 | + } |
|
| 266 | + if (!isset($this->global->LDAP_KEY_USERS)) { |
|
| 267 | + $this->global->LDAP_KEY_USERS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 268 | + } |
|
| 269 | + if (!isset($this->global->LDAP_KEY_GROUPS)) { |
|
| 270 | + $this->global->LDAP_KEY_GROUPS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 271 | + } |
|
| 272 | + if (!isset($this->global->LDAP_KEY_CONTACTS)) { |
|
| 273 | + $this->global->LDAP_KEY_CONTACTS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 274 | + } |
|
| 275 | + if (!isset($this->global->LDAP_KEY_MEMBERS)) { |
|
| 276 | + $this->global->LDAP_KEY_MEMBERS = $this->global->LDAP_FIELD_FULLNAME; |
|
| 277 | + } |
|
| 278 | + if (!isset($this->global->LDAP_KEY_MEMBERS_TYPES)) { |
|
| 279 | + $this->global->LDAP_KEY_MEMBERS_TYPES = $this->global->LDAP_FIELD_FULLNAME; |
|
| 280 | + } |
|
| 263 | 281 | |
| 264 | 282 | // Load translation object with current language |
| 265 | - if (empty($this->global->MAIN_LANG_DEFAULT)) |
|
| 266 | - $this->global->MAIN_LANG_DEFAULT = "en_US"; |
|
| 283 | + if (empty($this->global->MAIN_LANG_DEFAULT)) { |
|
| 284 | + $this->global->MAIN_LANG_DEFAULT = "en_US"; |
|
| 285 | + } |
|
| 267 | 286 | |
| 268 | 287 | $rootfordata = DOL_DATA_ROOT; |
| 269 | 288 | $rootforuser = DOL_DATA_ROOT; |
@@ -413,21 +432,29 @@ discard block |
||
| 413 | 432 | $this->global->MAIN_MAIL_USE_MULTI_PART = 1; |
| 414 | 433 | |
| 415 | 434 | // societe |
| 416 | - if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) |
|
| 417 | - $this->global->SOCIETE_CODECLIENT_ADDON = "mod_codeclient_leopard"; |
|
| 418 | - if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) |
|
| 419 | - $this->global->SOCIETE_CODECOMPTA_ADDON = "mod_codecompta_panicum"; |
|
| 420 | - |
|
| 421 | - if (empty($this->global->CHEQUERECEIPTS_ADDON)) |
|
| 422 | - $this->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint'; |
|
| 423 | - if (empty($conf->global->TICKETSUP_ADDON)) |
|
| 424 | - $this->global->TICKETSUP_ADDON = 'mod_ticket_simple'; |
|
| 435 | + if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) { |
|
| 436 | + $this->global->SOCIETE_CODECLIENT_ADDON = "mod_codeclient_leopard"; |
|
| 437 | + } |
|
| 438 | + if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) { |
|
| 439 | + $this->global->SOCIETE_CODECOMPTA_ADDON = "mod_codecompta_panicum"; |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + if (empty($this->global->CHEQUERECEIPTS_ADDON)) { |
|
| 443 | + $this->global->CHEQUERECEIPTS_ADDON = 'mod_chequereceipt_mint'; |
|
| 444 | + } |
|
| 445 | + if (empty($conf->global->TICKETSUP_ADDON)) { |
|
| 446 | + $this->global->TICKETSUP_ADDON = 'mod_ticket_simple'; |
|
| 447 | + } |
|
| 425 | 448 | |
| 426 | 449 | // Security |
| 427 | - if (empty($this->global->USER_PASSWORD_GENERATED)) |
|
| 428 | - $this->global->USER_PASSWORD_GENERATED = 'standard'; // Default password generator |
|
| 429 | - if (empty($this->global->MAIN_UMASK)) |
|
| 430 | - $this->global->MAIN_UMASK = '0664'; // Default mask |
|
| 450 | + if (empty($this->global->USER_PASSWORD_GENERATED)) { |
|
| 451 | + $this->global->USER_PASSWORD_GENERATED = 'standard'; |
|
| 452 | + } |
|
| 453 | + // Default password generator |
|
| 454 | + if (empty($this->global->MAIN_UMASK)) { |
|
| 455 | + $this->global->MAIN_UMASK = '0664'; |
|
| 456 | + } |
|
| 457 | + // Default mask |
|
| 431 | 458 | |
| 432 | 459 | |
| 433 | 460 | |
@@ -435,8 +462,9 @@ discard block |
||
| 435 | 462 | |
| 436 | 463 | // conf->use_javascript_ajax |
| 437 | 464 | $this->use_javascript_ajax = 1; |
| 438 | - if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) |
|
| 439 | - $this->use_javascript_ajax = !$this->global->MAIN_DISABLE_JAVASCRIPT; |
|
| 465 | + if (isset($this->global->MAIN_DISABLE_JAVASCRIPT)) { |
|
| 466 | + $this->use_javascript_ajax = !$this->global->MAIN_DISABLE_JAVASCRIPT; |
|
| 467 | + } |
|
| 440 | 468 | // If no javascript_ajax, Ajax features are disabled. |
| 441 | 469 | if (empty($this->use_javascript_ajax)) {
|
| 442 | 470 | unset($this->global->PRODUIT_USE_SEARCH_TO_SELECT); |
@@ -452,29 +480,34 @@ discard block |
||
| 452 | 480 | $this->global->STOCK_CALCULATE_ON_SHIPMENT_CLOSE = 0; |
| 453 | 481 | $this->global->STOCK_CALCULATE_ON_SUPPLIER_BILL = 0; |
| 454 | 482 | $this->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER = 0; |
| 455 | - if (empty($this->reception->enabled)) |
|
| 456 | - $this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER = 1; |
|
| 457 | - else {
|
|
| 483 | + if (empty($this->reception->enabled)) { |
|
| 484 | + $this->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER = 1; |
|
| 485 | + } else {
|
|
| 458 | 486 | $this->global->STOCK_CALCULATE_ON_RECEPTION = 1; |
| 459 | 487 | $this->global->STOCK_CALCULATE_ON_RECEPTION_CLOSE = 0; |
| 460 | 488 | } |
| 461 | 489 | } |
| 462 | 490 | |
| 463 | 491 | // conf->currency |
| 464 | - if (empty($this->global->MAIN_MONNAIE)) |
|
| 465 | - $this->global->MAIN_MONNAIE = 'EUR'; |
|
| 492 | + if (empty($this->global->MAIN_MONNAIE)) { |
|
| 493 | + $this->global->MAIN_MONNAIE = 'EUR'; |
|
| 494 | + } |
|
| 466 | 495 | $this->currency = $this->global->MAIN_MONNAIE; |
| 467 | 496 | |
| 468 | - if (empty($this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)) |
|
| 469 | - $this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; // Less than 1 minutes to be sure |
|
| 497 | + if (empty($this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)) { |
|
| 498 | + $this->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; |
|
| 499 | + } |
|
| 500 | + // Less than 1 minutes to be sure |
|
| 470 | 501 | |
| 471 | 502 | |
| 472 | 503 | |
| 473 | 504 | |
| 474 | 505 | |
| 475 | 506 | // conf->global->ACCOUNTING_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...) |
| 476 | - if (empty($this->global->ACCOUNTING_MODE)) |
|
| 477 | - $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES'; // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' |
|
| 507 | + if (empty($this->global->ACCOUNTING_MODE)) { |
|
| 508 | + $this->global->ACCOUNTING_MODE = 'RECETTES-DEPENSES'; |
|
| 509 | + } |
|
| 510 | + // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' |
|
| 478 | 511 | |
| 479 | 512 | |
| 480 | 513 | |
@@ -484,44 +517,53 @@ discard block |
||
| 484 | 517 | $this->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS = 1; |
| 485 | 518 | |
| 486 | 519 | // MAIN_HTML_TITLE |
| 487 | - if (!isset($this->global->MAIN_HTML_TITLE)) |
|
| 488 | - $this->global->MAIN_HTML_TITLE = 'noapp,thirdpartynameonly,contactnameonly,projectnameonly'; |
|
| 520 | + if (!isset($this->global->MAIN_HTML_TITLE)) { |
|
| 521 | + $this->global->MAIN_HTML_TITLE = 'noapp,thirdpartynameonly,contactnameonly,projectnameonly'; |
|
| 522 | + } |
|
| 489 | 523 | |
| 490 | 524 | // conf->liste_limit = constante de taille maximale des listes |
| 491 | - if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) |
|
| 492 | - $this->global->MAIN_SIZE_LISTE_LIMIT = 25; |
|
| 525 | + if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) { |
|
| 526 | + $this->global->MAIN_SIZE_LISTE_LIMIT = 25; |
|
| 527 | + } |
|
| 493 | 528 | $this->liste_limit = $this->global->MAIN_SIZE_LISTE_LIMIT; |
| 494 | 529 | |
| 495 | 530 | // conf->product->limit_size = constante de taille maximale des select de produit |
| 496 | - if (!isset($this->global->PRODUIT_LIMIT_SIZE)) |
|
| 497 | - $this->global->PRODUIT_LIMIT_SIZE = 1000; |
|
| 531 | + if (!isset($this->global->PRODUIT_LIMIT_SIZE)) { |
|
| 532 | + $this->global->PRODUIT_LIMIT_SIZE = 1000; |
|
| 533 | + } |
|
| 498 | 534 | $this->product->limit_size = $this->global->PRODUIT_LIMIT_SIZE; |
| 499 | 535 | |
| 500 | 536 | // conf->theme et $this->css |
| 501 | - if (empty($this->global->MAIN_THEME)) |
|
| 502 | - $this->global->MAIN_THEME = "eldy"; |
|
| 503 | - if (!empty($this->global->MAIN_FORCETHEME)) |
|
| 504 | - $this->global->MAIN_THEME = $this->global->MAIN_FORCETHEME; |
|
| 537 | + if (empty($this->global->MAIN_THEME)) { |
|
| 538 | + $this->global->MAIN_THEME = "eldy"; |
|
| 539 | + } |
|
| 540 | + if (!empty($this->global->MAIN_FORCETHEME)) { |
|
| 541 | + $this->global->MAIN_THEME = $this->global->MAIN_FORCETHEME; |
|
| 542 | + } |
|
| 505 | 543 | $this->theme = $this->global->MAIN_THEME; |
| 506 | 544 | //$this->css = "/theme/".$this->theme."/style.css.php"; |
| 507 | 545 | $this->css = '?controller=theme/' . $this->theme . '&method=style.css'; |
| 508 | 546 | |
| 509 | 547 | // conf->email_from = email pour envoi par dolibarr des mails automatiques |
| 510 | 548 | $this->email_from = "[email protected]"; |
| 511 | - if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) |
|
| 512 | - $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM; |
|
| 549 | + if (!empty($this->global->MAIN_MAIL_EMAIL_FROM)) { |
|
| 550 | + $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM; |
|
| 551 | + } |
|
| 513 | 552 | |
| 514 | 553 | // conf->notification->email_from = email pour envoi par Dolibarr des notifications |
| 515 | 554 | $this->notification->email_from = $this->email_from; |
| 516 | - if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) |
|
| 517 | - $this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM; |
|
| 555 | + if (!empty($this->global->NOTIFICATION_EMAIL_FROM)) { |
|
| 556 | + $this->notification->email_from = $this->global->NOTIFICATION_EMAIL_FROM; |
|
| 557 | + } |
|
| 518 | 558 | |
| 519 | 559 | // conf->mailing->email_from = email pour envoi par Dolibarr des mailings |
| 520 | 560 | $this->mailing->email_from = $this->email_from; |
| 521 | - if (!empty($this->global->MAILING_EMAIL_FROM)) |
|
| 522 | - $this->mailing->email_from = $this->global->MAILING_EMAIL_FROM; |
|
| 523 | - if (!isset($this->global->MAIN_EMAIL_ADD_TRACK_ID)) |
|
| 524 | - $this->global->MAIN_EMAIL_ADD_TRACK_ID = 1; |
|
| 561 | + if (!empty($this->global->MAILING_EMAIL_FROM)) { |
|
| 562 | + $this->mailing->email_from = $this->global->MAILING_EMAIL_FROM; |
|
| 563 | + } |
|
| 564 | + if (!isset($this->global->MAIN_EMAIL_ADD_TRACK_ID)) { |
|
| 565 | + $this->global->MAIN_EMAIL_ADD_TRACK_ID = 1; |
|
| 566 | + } |
|
| 525 | 567 | |
| 526 | 568 | // Format for date (used by default when not found or not searched in lang) |
| 527 | 569 | $this->format_date_short = "%d/%m/%Y"; // Format of day with PHP/C tags (strftime functions) |
@@ -536,81 +578,105 @@ discard block |
||
| 536 | 578 | $this->format_date_hour_text = "%d %B %Y %H:%M"; |
| 537 | 579 | |
| 538 | 580 | // Duration of workday |
| 539 | - if (!isset($this->global->MAIN_DURATION_OF_WORKDAY)) |
|
| 540 | - $this->global->MAIN_DURATION_OF_WORKDAY = 86400; |
|
| 581 | + if (!isset($this->global->MAIN_DURATION_OF_WORKDAY)) { |
|
| 582 | + $this->global->MAIN_DURATION_OF_WORKDAY = 86400; |
|
| 583 | + } |
|
| 541 | 584 | |
| 542 | 585 | // Limites decimales si non definie (peuvent etre egale a 0) |
| 543 | - if (!isset($this->global->MAIN_MAX_DECIMALS_UNIT)) |
|
| 544 | - $this->global->MAIN_MAX_DECIMALS_UNIT = 5; |
|
| 545 | - if (!isset($this->global->MAIN_MAX_DECIMALS_TOT)) |
|
| 546 | - $this->global->MAIN_MAX_DECIMALS_TOT = 2; |
|
| 547 | - if (!isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) |
|
| 548 | - $this->global->MAIN_MAX_DECIMALS_SHOWN = 8; |
|
| 586 | + if (!isset($this->global->MAIN_MAX_DECIMALS_UNIT)) { |
|
| 587 | + $this->global->MAIN_MAX_DECIMALS_UNIT = 5; |
|
| 588 | + } |
|
| 589 | + if (!isset($this->global->MAIN_MAX_DECIMALS_TOT)) { |
|
| 590 | + $this->global->MAIN_MAX_DECIMALS_TOT = 2; |
|
| 591 | + } |
|
| 592 | + if (!isset($this->global->MAIN_MAX_DECIMALS_SHOWN)) { |
|
| 593 | + $this->global->MAIN_MAX_DECIMALS_SHOWN = 8; |
|
| 594 | + } |
|
| 549 | 595 | |
| 550 | 596 | // Default pdf option |
| 551 | - if (!isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) |
|
| 552 | - $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1; // use dash between lines |
|
| 553 | - if (!isset($this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) |
|
| 554 | - $this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT = 1; // allow html content into free footer text |
|
| 597 | + if (!isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) { |
|
| 598 | + $this->global->MAIN_PDF_DASH_BETWEEN_LINES = 1; |
|
| 599 | + } |
|
| 600 | + // use dash between lines |
|
| 601 | + if (!isset($this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) { |
|
| 602 | + $this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT = 1; |
|
| 603 | + } |
|
| 604 | + // allow html content into free footer text |
|
| 555 | 605 | |
| 556 | 606 | |
| 557 | 607 | |
| 558 | 608 | |
| 559 | 609 | |
| 560 | 610 | // Set default value to MAIN_SHOW_LOGO |
| 561 | - if (!isset($this->global->MAIN_SHOW_LOGO)) |
|
| 562 | - $this->global->MAIN_SHOW_LOGO = 1; |
|
| 611 | + if (!isset($this->global->MAIN_SHOW_LOGO)) { |
|
| 612 | + $this->global->MAIN_SHOW_LOGO = 1; |
|
| 613 | + } |
|
| 563 | 614 | |
| 564 | 615 | // Default max file size for upload |
| 565 | 616 | $this->maxfilesize = (empty($this->global->MAIN_UPLOAD_DOC) ? 0 : (int) $this->global->MAIN_UPLOAD_DOC * 1024); |
| 566 | 617 | |
| 567 | 618 | // By default, we propagate contacts |
| 568 | - if (!isset($this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) |
|
| 569 | - $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN = '*'; // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented) |
|
| 619 | + if (!isset($this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) { |
|
| 620 | + $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN = '*'; |
|
| 621 | + } |
|
| 622 | + // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented) |
|
| 570 | 623 | |
| 571 | 624 | |
| 572 | 625 | |
| 573 | 626 | |
| 574 | 627 | |
| 575 | 628 | // By default, we do not use the zip town table but the table of third parties |
| 576 | - if (!isset($this->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) |
|
| 577 | - $this->global->MAIN_USE_ZIPTOWN_DICTIONNARY = 0; |
|
| 629 | + if (!isset($this->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) { |
|
| 630 | + $this->global->MAIN_USE_ZIPTOWN_DICTIONNARY = 0; |
|
| 631 | + } |
|
| 578 | 632 | |
| 579 | 633 | // By default, we open card if one found |
| 580 | - if (!isset($this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE)) |
|
| 581 | - $this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE = 1; |
|
| 634 | + if (!isset($this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE)) { |
|
| 635 | + $this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE = 1; |
|
| 636 | + } |
|
| 582 | 637 | |
| 583 | 638 | // By default, we show state code in combo list |
| 584 | - if (!isset($this->global->MAIN_SHOW_STATE_CODE)) |
|
| 585 | - $this->global->MAIN_SHOW_STATE_CODE = 1; |
|
| 639 | + if (!isset($this->global->MAIN_SHOW_STATE_CODE)) { |
|
| 640 | + $this->global->MAIN_SHOW_STATE_CODE = 1; |
|
| 641 | + } |
|
| 586 | 642 | |
| 587 | 643 | // Define list of limited modules (value must be key found for "name" property of module, so for example 'supplierproposal' for Module "Supplier Proposal" |
| 588 | - if (!isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) |
|
| 589 | - $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,agenda,resource,adherent,blockedlog'; // '' means 'all'. Note that contact is added here as it should be a module later. |
|
| 644 | + if (!isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) { |
|
| 645 | + $this->global->MAIN_MODULES_FOR_EXTERNAL = 'user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,agenda,resource,adherent,blockedlog'; |
|
| 646 | + } |
|
| 647 | + // '' means 'all'. Note that contact is added here as it should be a module later. |
|
| 590 | 648 | if (!empty($this->modules_parts['moduleforexternal'])) { // Module part to include an external module into the MAIN_MODULES_FOR_EXTERNAL list
|
| 591 | - foreach ($this->modules_parts['moduleforexternal'] as $key => $value) |
|
| 592 | - $this->global->MAIN_MODULES_FOR_EXTERNAL .= "," . $key; |
|
| 649 | + foreach ($this->modules_parts['moduleforexternal'] as $key => $value) { |
|
| 650 | + $this->global->MAIN_MODULES_FOR_EXTERNAL .= "," . $key; |
|
| 651 | + } |
|
| 593 | 652 | } |
| 594 | 653 | |
| 595 | 654 | // Enable select2 |
| 596 | - if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT) || $this->global->MAIN_USE_JQUERY_MULTISELECT == '1') |
|
| 597 | - $this->global->MAIN_USE_JQUERY_MULTISELECT = 'select2'; |
|
| 655 | + if (empty($this->global->MAIN_USE_JQUERY_MULTISELECT) || $this->global->MAIN_USE_JQUERY_MULTISELECT == '1') { |
|
| 656 | + $this->global->MAIN_USE_JQUERY_MULTISELECT = 'select2'; |
|
| 657 | + } |
|
| 598 | 658 | |
| 599 | 659 | // Timeouts |
| 600 | - if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) |
|
| 601 | - $this->global->MAIN_USE_CONNECT_TIMEOUT = 10; |
|
| 602 | - if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) |
|
| 603 | - $this->global->MAIN_USE_RESPONSE_TIMEOUT = 30; |
|
| 660 | + if (empty($this->global->MAIN_USE_CONNECT_TIMEOUT)) { |
|
| 661 | + $this->global->MAIN_USE_CONNECT_TIMEOUT = 10; |
|
| 662 | + } |
|
| 663 | + if (empty($this->global->MAIN_USE_RESPONSE_TIMEOUT)) { |
|
| 664 | + $this->global->MAIN_USE_RESPONSE_TIMEOUT = 30; |
|
| 665 | + } |
|
| 604 | 666 | |
| 605 | 667 | // Set default variable to calculate VAT as if option tax_mode was 0 (standard) |
| 606 | - if (empty($this->global->TAX_MODE_SELL_PRODUCT)) |
|
| 607 | - $this->global->TAX_MODE_SELL_PRODUCT = 'invoice'; |
|
| 608 | - if (empty($this->global->TAX_MODE_BUY_PRODUCT)) |
|
| 609 | - $this->global->TAX_MODE_BUY_PRODUCT = 'invoice'; |
|
| 610 | - if (empty($this->global->TAX_MODE_SELL_SERVICE)) |
|
| 611 | - $this->global->TAX_MODE_SELL_SERVICE = 'payment'; |
|
| 612 | - if (empty($this->global->TAX_MODE_BUY_SERVICE)) |
|
| 613 | - $this->global->TAX_MODE_BUY_SERVICE = 'payment'; |
|
| 668 | + if (empty($this->global->TAX_MODE_SELL_PRODUCT)) { |
|
| 669 | + $this->global->TAX_MODE_SELL_PRODUCT = 'invoice'; |
|
| 670 | + } |
|
| 671 | + if (empty($this->global->TAX_MODE_BUY_PRODUCT)) { |
|
| 672 | + $this->global->TAX_MODE_BUY_PRODUCT = 'invoice'; |
|
| 673 | + } |
|
| 674 | + if (empty($this->global->TAX_MODE_SELL_SERVICE)) { |
|
| 675 | + $this->global->TAX_MODE_SELL_SERVICE = 'payment'; |
|
| 676 | + } |
|
| 677 | + if (empty($this->global->TAX_MODE_BUY_SERVICE)) { |
|
| 678 | + $this->global->TAX_MODE_BUY_SERVICE = 'payment'; |
|
| 679 | + } |
|
| 614 | 680 | |
| 615 | 681 | // Delay before warnings |
| 616 | 682 | // Avoid strict errors. TODO: Replace xxx->warning_delay with a property ->warning_delay_xxx |
@@ -618,8 +684,9 @@ discard block |
||
| 618 | 684 | $this->adherent->subscription = new \stdClass(); |
| 619 | 685 | $this->adherent->subscription->warning_delay = (isset($this->global->MAIN_DELAY_MEMBERS) ? $this->global->MAIN_DELAY_MEMBERS : 0) * 24 * 60 * 60; |
| 620 | 686 | } |
| 621 | - if (isset($this->agenda)) |
|
| 622 | - $this->agenda->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 24 * 60 * 60; |
|
| 687 | + if (isset($this->agenda)) { |
|
| 688 | + $this->agenda->warning_delay = (isset($this->global->MAIN_DELAY_ACTIONS_TODO) ? $this->global->MAIN_DELAY_ACTIONS_TODO : 7) * 24 * 60 * 60; |
|
| 689 | + } |
|
| 623 | 690 | if (isset($this->projet)) {
|
| 624 | 691 | $this->projet->warning_delay = (isset($this->global->MAIN_DELAY_PROJECT_TO_CLOSE) ? $this->global->MAIN_DELAY_PROJECT_TO_CLOSE : 7) * 24 * 60 * 60; |
| 625 | 692 | $this->projet->task = new StdClass(); |
@@ -669,44 +736,55 @@ discard block |
||
| 669 | 736 | } |
| 670 | 737 | |
| 671 | 738 | // For modules that want to disable top or left menu |
| 672 | - if (!empty($this->global->MAIN_HIDE_TOP_MENU)) |
|
| 673 | - $this->dol_hide_topmenu = $this->global->MAIN_HIDE_TOP_MENU; |
|
| 674 | - if (!empty($this->global->MAIN_HIDE_LEFT_MENU)) |
|
| 675 | - $this->dol_hide_leftmenu = $this->global->MAIN_HIDE_LEFT_MENU; |
|
| 739 | + if (!empty($this->global->MAIN_HIDE_TOP_MENU)) { |
|
| 740 | + $this->dol_hide_topmenu = $this->global->MAIN_HIDE_TOP_MENU; |
|
| 741 | + } |
|
| 742 | + if (!empty($this->global->MAIN_HIDE_LEFT_MENU)) { |
|
| 743 | + $this->dol_hide_leftmenu = $this->global->MAIN_HIDE_LEFT_MENU; |
|
| 744 | + } |
|
| 676 | 745 | |
| 677 | - if (empty($this->global->MAIN_SIZE_SHORTLIST_LIMIT)) |
|
| 678 | - $this->global->MAIN_SIZE_SHORTLIST_LIMIT = 3; |
|
| 746 | + if (empty($this->global->MAIN_SIZE_SHORTLIST_LIMIT)) { |
|
| 747 | + $this->global->MAIN_SIZE_SHORTLIST_LIMIT = 3; |
|
| 748 | + } |
|
| 679 | 749 | |
| 680 | - if (!isset($this->global->THEME_HIDE_BORDER_ON_INPUT)) |
|
| 681 | - $this->global->THEME_HIDE_BORDER_ON_INPUT = 0; |
|
| 750 | + if (!isset($this->global->THEME_HIDE_BORDER_ON_INPUT)) { |
|
| 751 | + $this->global->THEME_HIDE_BORDER_ON_INPUT = 0; |
|
| 752 | + } |
|
| 682 | 753 | |
| 683 | 754 | // Save inconsistent option |
| 684 | 755 | if (empty($this->global->AGENDA_USE_EVENT_TYPE) && (!isset($this->global->AGENDA_DEFAULT_FILTER_TYPE) || $this->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO')) {
|
| 685 | 756 | $this->global->AGENDA_DEFAULT_FILTER_TYPE = '0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on. |
| 686 | 757 | } |
| 687 | 758 | |
| 688 | - if (!isset($this->global->MAIN_EXTRAFIELDS_IN_ONE_TD)) |
|
| 689 | - $this->global->MAIN_EXTRAFIELDS_IN_ONE_TD = 1; |
|
| 759 | + if (!isset($this->global->MAIN_EXTRAFIELDS_IN_ONE_TD)) { |
|
| 760 | + $this->global->MAIN_EXTRAFIELDS_IN_ONE_TD = 1; |
|
| 761 | + } |
|
| 690 | 762 | |
| 691 | 763 | $this->global->MAIN_MODULE_DOLISTORE_API_SRV = 'https://www.dolistore.com'; |
| 692 | 764 | $this->global->MAIN_MODULE_DOLISTORE_API_KEY = 'dolistorecatalogpublickey1234567'; |
| 693 | 765 | |
| 694 | 766 | // For backward compatibility |
| 695 | - if (isset($this->product)) |
|
| 696 | - $this->produit = $this->product; |
|
| 697 | - if (isset($this->facture)) |
|
| 698 | - $this->invoice = $this->facture; |
|
| 699 | - if (isset($this->commande)) |
|
| 700 | - $this->order = $this->commande; |
|
| 701 | - if (isset($this->contrat)) |
|
| 702 | - $this->contract = $this->contrat; |
|
| 703 | - if (isset($this->categorie)) |
|
| 704 | - $this->category = $this->categorie; |
|
| 767 | + if (isset($this->product)) { |
|
| 768 | + $this->produit = $this->product; |
|
| 769 | + } |
|
| 770 | + if (isset($this->facture)) { |
|
| 771 | + $this->invoice = $this->facture; |
|
| 772 | + } |
|
| 773 | + if (isset($this->commande)) { |
|
| 774 | + $this->order = $this->commande; |
|
| 775 | + } |
|
| 776 | + if (isset($this->contrat)) { |
|
| 777 | + $this->contract = $this->contrat; |
|
| 778 | + } |
|
| 779 | + if (isset($this->categorie)) { |
|
| 780 | + $this->category = $this->categorie; |
|
| 781 | + } |
|
| 705 | 782 | |
| 706 | 783 | // Object $mc |
| 707 | 784 | if (!defined('NOREQUIREMC') && !empty($this->multicompany->enabled)) {
|
| 708 | - if (is_object($mc)) |
|
| 709 | - $mc->setValues($this); |
|
| 785 | + if (is_object($mc)) { |
|
| 786 | + $mc->setValues($this); |
|
| 787 | + } |
|
| 710 | 788 | } |
| 711 | 789 | |
| 712 | 790 | // We init log handlers |
@@ -35,8 +35,8 @@ discard block |
||
| 35 | 35 | * @var DoliDB Database handler. |
| 36 | 36 | */ |
| 37 | 37 | // public $db; |
| 38 | - var $type_user; // Put 0 for internal users, 1 for external users |
|
| 39 | - var $atarget = ""; // To store default target to use onto links |
|
| 38 | + var $type_user; // Put 0 for internal users, 1 for external users |
|
| 39 | + var $atarget = ""; // To store default target to use onto links |
|
| 40 | 40 | var $name = "eldy"; |
| 41 | 41 | var $menu_array; |
| 42 | 42 | var $menu_array_after; |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | $leftmenu = $forceleftmenu; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - require_once DOL_DOCUMENT_ROOT . '/core/class/menubase.class.php'; |
|
| 107 | + require_once DOL_DOCUMENT_ROOT.'/core/class/menubase.class.php'; |
|
| 108 | 108 | $tabMenu = array(); |
| 109 | 109 | $menuArbo = new Menubase('eldy');
|
| 110 | 110 | $menuArbo->menuLoad($mainmenu, $leftmenu, $this->type_user, 'eldy', $tabMenu); |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | //var_dump($this->tabMenu); |
| 129 | 129 | |
| 130 | - require_once DOL_DOCUMENT_ROOT . '/core/menus/standard/eldy.lib.php'; |
|
| 130 | + require_once DOL_DOCUMENT_ROOT.'/core/menus/standard/eldy.lib.php'; |
|
| 131 | 131 | |
| 132 | 132 | if ($this->type_user == 1) {
|
| 133 | 133 | $conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED = 1; |
| 134 | 134 | $conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED = 1; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - require_once DOL_DOCUMENT_ROOT . '/core/class/menu.class.php'; |
|
| 137 | + require_once DOL_DOCUMENT_ROOT.'/core/class/menu.class.php'; |
|
| 138 | 138 | $this->menu = new Menu(); |
| 139 | 139 | |
| 140 | 140 | if (empty($conf->global->MAIN_MENU_INVERT)) {
|
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | if ($mode == 'topnb') {
|
| 158 | - print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output |
|
| 158 | + print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // no output |
|
| 159 | 159 | return $this->menu->getNbOfVisibleMenuEntries(); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | if ($mode == 'jmobile') { // Used to get menu in xml ul/li
|
| 163 | - print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // Fill this->menu that is empty with top menu |
|
| 163 | + print_eldy_menu($this->db, $this->atarget, $this->type_user, $this->tabMenu, $this->menu, 1, $mode); // Fill this->menu that is empty with top menu |
|
| 164 | 164 | // $this->menu->liste is top menu |
| 165 | 165 | //var_dump($this->menu->liste);exit; |
| 166 | 166 | $lastlevel = array(); |
| 167 | - print '<!-- Generate menu list from menu handler ' . $this->name . ' -->' . "\n"; |
|
| 167 | + print '<!-- Generate menu list from menu handler '.$this->name.' -->'."\n"; |
|
| 168 | 168 | foreach ($this->menu->liste as $key => $val) { // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu'
|
| 169 | 169 | print '<ul class="ulmenu" data-inset="true">'; |
| 170 | 170 | print '<li class="lilevel0">'; |
@@ -185,13 +185,13 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | print $val['titre']; |
| 188 | - print '</a>' . "\n"; |
|
| 188 | + print '</a>'."\n"; |
|
| 189 | 189 | |
| 190 | 190 | // Search submenu fot this mainmenu entry |
| 191 | 191 | $tmpmainmenu = $val['mainmenu']; |
| 192 | 192 | $tmpleftmenu = 'all'; |
| 193 | 193 | $submenu = new Menu(); |
| 194 | - print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home) |
|
| 194 | + print_left_eldy_menu($this->db, $this->menu_array, $this->menu_array_after, $this->tabMenu, $submenu, 1, $tmpmainmenu, $tmpleftmenu); // Fill $submenu (example with tmpmainmenu='home' tmpleftmenu='all', return left menu tree of Home) |
|
| 195 | 195 | // Note: $submenu contains menu entry with substitution not yet done |
| 196 | 196 | //if ($tmpmainmenu.'-'.$tmpleftmenu == 'home-all') { var_dump($submenu); exit; }
|
| 197 | 197 | //if ($tmpmainmenu=='accountancy') { var_dump($submenu->liste); exit; }
|
@@ -201,21 +201,21 @@ discard block |
||
| 201 | 201 | $canonnexturl = preg_replace('/\?.*$/', '', $nexturl);
|
| 202 | 202 | //var_dump($canonrelurl); |
| 203 | 203 | //var_dump($canonnexturl); |
| 204 | - print '<ul>' . "\n"; |
|
| 204 | + print '<ul>'."\n"; |
|
| 205 | 205 | if (($canonrelurl != $canonnexturl && !in_array($val['mainmenu'], array('tools'))) || (strpos($canonrelurl, '/product/index.php') !== false || strpos($canonrelurl, '/compta/bank/list.php') !== false)) {
|
| 206 | 206 | // We add sub entry |
| 207 | - print str_pad('', 1) . '<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
|
|
| 208 | - print '<a href="' . $relurl . '">'; |
|
| 209 | - if ($langs->trans(ucfirst($val['mainmenu']) . "Dashboard") == ucfirst($val['mainmenu']) . "Dashboard") { // No translation
|
|
| 207 | + print str_pad('', 1).'<li class="lilevel1 ui-btn-icon-right ui-btn">'; // ui-btn to highlight on clic
|
|
| 208 | + print '<a href="'.$relurl.'">'; |
|
| 209 | + if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") { // No translation
|
|
| 210 | 210 | if (in_array($val['mainmenu'], array('cashdesk', 'externalsite', 'website', 'collab'))) {
|
| 211 | 211 | print $langs->trans("Access");
|
| 212 | 212 | } else {
|
| 213 | 213 | print $langs->trans("Dashboard");
|
| 214 | 214 | } |
| 215 | 215 | } else |
| 216 | - print $langs->trans(ucfirst($val['mainmenu']) . "Dashboard"); |
|
| 216 | + print $langs->trans(ucfirst($val['mainmenu'])."Dashboard"); |
|
| 217 | 217 | print '</a>'; |
| 218 | - print '</li>' . "\n"; |
|
| 218 | + print '</li>'."\n"; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | if ($val['level'] == 0) {
|
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | if ($showmenu) { // Visible (option to hide when not allowed is off or allowed)
|
| 250 | 250 | $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
|
| 251 | 251 | $substitarray['__USERID__'] = $user->id; // For backward compatibility |
| 252 | - $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__ |
|
| 252 | + $val2['url'] = make_substitutions($val2['url'], $substitarray); // Make also substitution of __(XXX)__ and __[XXX]__ |
|
| 253 | 253 | |
| 254 | 254 | if (!preg_match("/^(http:\/\/|https:\/\/)/i", $val2['url'])) {
|
| 255 | 255 | $relurl2 = dol_buildpath($val2['url'], 1); |
@@ -268,14 +268,14 @@ discard block |
||
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | print str_pad('', $val2['level'] + 1);
|
| 271 | - print '<li class="lilevel' . ($val2['level'] + 1); |
|
| 271 | + print '<li class="lilevel'.($val2['level'] + 1); |
|
| 272 | 272 | if ($val2['level'] == 0) {
|
| 273 | - print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic |
|
| 273 | + print ' ui-btn-icon-right ui-btn'; // ui-btn to highlight on clic |
|
| 274 | 274 | } |
| 275 | - print $disabled . '">'; // ui-btn to highlight on clic |
|
| 275 | + print $disabled.'">'; // ui-btn to highlight on clic |
|
| 276 | 276 | if ($relurl2) {
|
| 277 | 277 | if ($val2['enabled']) { // Allowed
|
| 278 | - print '<a href="' . $relurl2 . '"'; |
|
| 278 | + print '<a href="'.$relurl2.'"'; |
|
| 279 | 279 | //print ' data-ajax="false"'; |
| 280 | 280 | print '>'; |
| 281 | 281 | $lastlevel2[$val2['level']] = 'enabled'; |
@@ -299,17 +299,17 @@ discard block |
||
| 299 | 299 | else |
| 300 | 300 | print '</a>'; |
| 301 | 301 | } |
| 302 | - print '</li>' . "\n"; |
|
| 302 | + print '</li>'."\n"; |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | //var_dump($submenu); |
| 306 | 306 | print '</ul>'; |
| 307 | 307 | } |
| 308 | 308 | if ($val['enabled'] == 2) {
|
| 309 | - print '<font class="vsmenudisabled">' . $val['titre'] . '</font>'; |
|
| 309 | + print '<font class="vsmenudisabled">'.$val['titre'].'</font>'; |
|
| 310 | 310 | } |
| 311 | 311 | print '</li>'; |
| 312 | - print '</ul>' . "\n"; |
|
| 312 | + print '</ul>'."\n"; |
|
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | 315 | |
@@ -210,8 +210,9 @@ discard block |
||
| 210 | 210 | } else {
|
| 211 | 211 | print $langs->trans("Dashboard");
|
| 212 | 212 | } |
| 213 | - } else |
|
| 214 | - print $langs->trans(ucfirst($val['mainmenu']) . "Dashboard"); |
|
| 213 | + } else { |
|
| 214 | + print $langs->trans(ucfirst($val['mainmenu']) . "Dashboard"); |
|
| 215 | + } |
|
| 215 | 216 | print '</a>'; |
| 216 | 217 | print '</li>' . "\n"; |
| 217 | 218 | } |
@@ -292,10 +293,12 @@ discard block |
||
| 292 | 293 | //var_dump($lastlevel2); |
| 293 | 294 | print $val2['titre']; |
| 294 | 295 | if ($relurl2) {
|
| 295 | - if ($val2['enabled']) // Allowed |
|
| 296 | - print '</a>'; |
|
| 297 | - else |
|
| 298 | - print '</a>'; |
|
| 296 | + if ($val2['enabled']) { |
|
| 297 | + // Allowed |
|
| 298 | + print '</a>'; |
|
| 299 | + } else { |
|
| 300 | + print '</a>'; |
|
| 301 | + } |
|
| 299 | 302 | } |
| 300 | 303 | print '</li>' . "\n"; |
| 301 | 304 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | public $skype; |
| 55 | 55 | public $twitter; |
| 56 | 56 | public $facebook; |
| 57 | - public $job; // job position |
|
| 57 | + public $job; // job position |
|
| 58 | 58 | public $signature; |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public $address; |
| 64 | 64 | public $zip; |
| 65 | 65 | public $town; |
| 66 | - public $state_id; // The state/department |
|
| 66 | + public $state_id; // The state/department |
|
| 67 | 67 | public $state_code; |
| 68 | 68 | public $state; |
| 69 | 69 | public $office_phone; |
@@ -117,26 +117,26 @@ discard block |
||
| 117 | 117 | public $datepreviouslogin; |
| 118 | 118 | public $photo; |
| 119 | 119 | public $lang; |
| 120 | - public $rights; // Array of permissions user->rights->permx |
|
| 121 | - public $all_permissions_are_loaded; // All permission are loaded |
|
| 122 | - public $nb_rights; // Number of rights granted to the user |
|
| 123 | - private $_tab_loaded = array(); // Cache array of already loaded permissions |
|
| 124 | - public $conf; // To store personal config |
|
| 125 | - public $default_values; // To store default values for user |
|
| 126 | - public $lastsearch_values_tmp; // To store current search criterias for user |
|
| 127 | - public $lastsearch_values; // To store last saved search criterias for user |
|
| 128 | - public $users = array(); // To store all tree of users hierarchy |
|
| 129 | - public $parentof; // To store an array of all parents for all ids. |
|
| 120 | + public $rights; // Array of permissions user->rights->permx |
|
| 121 | + public $all_permissions_are_loaded; // All permission are loaded |
|
| 122 | + public $nb_rights; // Number of rights granted to the user |
|
| 123 | + private $_tab_loaded = array(); // Cache array of already loaded permissions |
|
| 124 | + public $conf; // To store personal config |
|
| 125 | + public $default_values; // To store default values for user |
|
| 126 | + public $lastsearch_values_tmp; // To store current search criterias for user |
|
| 127 | + public $lastsearch_values; // To store last saved search criterias for user |
|
| 128 | + public $users = array(); // To store all tree of users hierarchy |
|
| 129 | + public $parentof; // To store an array of all parents for all ids. |
|
| 130 | 130 | private $cache_childids; |
| 131 | - public $accountancy_code; // Accountancy code in prevision of the complete accountancy module |
|
| 132 | - public $thm; // Average cost of employee - Used for valuation of time spent |
|
| 133 | - public $tjm; // Average cost of employee |
|
| 134 | - public $salary; // Monthly salary - Denormalized value from llx_user_employment |
|
| 135 | - public $salaryextra; // Monthly salary extra - Denormalized value from llx_user_employment |
|
| 136 | - public $weeklyhours; // Weekly hours - Denormalized value from llx_user_employment |
|
| 137 | - public $color; // Define background color for user in agenda |
|
| 138 | - public $dateemployment; // Define date of employment by company |
|
| 139 | - public $dateemploymentend; // Define date of employment end by company |
|
| 131 | + public $accountancy_code; // Accountancy code in prevision of the complete accountancy module |
|
| 132 | + public $thm; // Average cost of employee - Used for valuation of time spent |
|
| 133 | + public $tjm; // Average cost of employee |
|
| 134 | + public $salary; // Monthly salary - Denormalized value from llx_user_employment |
|
| 135 | + public $salaryextra; // Monthly salary extra - Denormalized value from llx_user_employment |
|
| 136 | + public $weeklyhours; // Weekly hours - Denormalized value from llx_user_employment |
|
| 137 | + public $color; // Define background color for user in agenda |
|
| 138 | + public $dateemployment; // Define date of employment by company |
|
| 139 | + public $dateemploymentend; // Define date of employment end by company |
|
| 140 | 140 | public $default_c_exp_tax_cat; |
| 141 | 141 | public $default_range; |
| 142 | 142 | public $fields = array( |
@@ -211,37 +211,37 @@ discard block |
||
| 211 | 211 | $sql .= " u.color,"; |
| 212 | 212 | $sql .= " u.dateemployment, u.dateemploymentend,"; |
| 213 | 213 | $sql .= " u.ref_int, u.ref_ext,"; |
| 214 | - $sql .= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode |
|
| 214 | + $sql .= " u.default_range, u.default_c_exp_tax_cat,"; // Expense report default mode |
|
| 215 | 215 | $sql .= " c.code as country_code, c.label as country,"; |
| 216 | 216 | $sql .= " d.code_departement as state_code, d.nom as state"; |
| 217 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
|
| 218 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as c ON u.fk_country = c.rowid"; |
|
| 219 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_departements as d ON u.fk_state = d.rowid"; |
|
| 217 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
| 218 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON u.fk_country = c.rowid"; |
|
| 219 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as d ON u.fk_state = d.rowid"; |
|
| 220 | 220 | |
| 221 | 221 | if ($entity < 0) {
|
| 222 | 222 | if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
|
| 223 | - $sql .= " WHERE u.entity IN (0," . Globals::$conf->entity . ")"; |
|
| 223 | + $sql .= " WHERE u.entity IN (0,".Globals::$conf->entity.")"; |
|
| 224 | 224 | } else {
|
| 225 | - $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database |
|
| 225 | + $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database |
|
| 226 | 226 | } |
| 227 | 227 | } else { // The fetch was forced on an entity
|
| 228 | 228 | if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 229 | - $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database |
|
| 229 | + $sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database |
|
| 230 | 230 | } else {
|
| 231 | - $sql .= " WHERE u.entity IN (0, " . (($entity != '' && $entity >= 0) ? $entity : Globals::$conf->entity) . ")"; // search in entity provided in parameter |
|
| 231 | + $sql .= " WHERE u.entity IN (0, ".(($entity != '' && $entity >= 0) ? $entity : Globals::$conf->entity).")"; // search in entity provided in parameter |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | if ($sid) { // permet une recherche du user par son SID ActiveDirectory ou Samba
|
| 236 | 236 | //$sql .= " AND (u.ldap_sid = '" . Config::$dbEngine->escape($sid) . "' OR u.login = '" . Config::$dbEngine->escape($login) . "') LIMIT 1"; |
| 237 | - $sql .= " AND (u.ldap_sid = '" . $sid . "' OR u.login = '" . Config::$dbEngine->escape($login) . "') LIMIT 1"; |
|
| 237 | + $sql .= " AND (u.ldap_sid = '".$sid."' OR u.login = '".Config::$dbEngine->escape($login)."') LIMIT 1"; |
|
| 238 | 238 | } else if ($login) {
|
| 239 | 239 | // $sql .= " AND u.login = '" . Config::$dbEngine->escape($login) . "'"; |
| 240 | - $sql .= " AND u.login = '" . $login . "'"; |
|
| 240 | + $sql .= " AND u.login = '".$login."'"; |
|
| 241 | 241 | } else {
|
| 242 | - $sql .= " AND u.rowid = " . $id; |
|
| 242 | + $sql .= " AND u.rowid = ".$id; |
|
| 243 | 243 | } |
| 244 | - $sql .= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities |
|
| 244 | + $sql .= " ORDER BY u.entity ASC"; // Avoid random result when there is 2 login in 2 different entities |
|
| 245 | 245 | |
| 246 | 246 | $result = Config::$dbEngine->select($sql); |
| 247 | 247 | // echo "<p>SQL in 2477 of User: '$sql'</p>"; |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $this->datelastlogin = $obj->datel; |
| 328 | 328 | $this->datepreviouslogin = $obj->datep; |
| 329 | 329 | |
| 330 | - $this->societe_id = $obj->fk_soc; // deprecated |
|
| 330 | + $this->societe_id = $obj->fk_soc; // deprecated |
|
| 331 | 331 | $this->contact_id = $obj->fk_socpeople; // deprecated |
| 332 | 332 | $this->socid = $obj->fk_soc; |
| 333 | 333 | $this->contactid = $obj->fk_socpeople; |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $this->fetch_optionals(); |
| 349 | 349 | } else {
|
| 350 | 350 | $this->error = "USERNOTFOUND"; |
| 351 | - DolUtils::dol_syslog(get_class($this) . "::fetch user not found", LOG_DEBUG); |
|
| 351 | + DolUtils::dol_syslog(get_class($this)."::fetch user not found", LOG_DEBUG); |
|
| 352 | 352 | return 0; |
| 353 | 353 | } |
| 354 | 354 | } else {
|
@@ -359,9 +359,9 @@ discard block |
||
| 359 | 359 | // To get back the global configuration unique to the user |
| 360 | 360 | if ($loadpersonalconf) {
|
| 361 | 361 | // Load user->conf for user |
| 362 | - $sql = "SELECT param, value FROM " . MAIN_DB_PREFIX . "user_param"; |
|
| 363 | - $sql .= " WHERE fk_user = " . $this->id; |
|
| 364 | - $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 362 | + $sql = "SELECT param, value FROM ".MAIN_DB_PREFIX."user_param"; |
|
| 363 | + $sql .= " WHERE fk_user = ".$this->id; |
|
| 364 | + $sql .= " AND entity = ".Globals::$conf->entity; |
|
| 365 | 365 | //DolUtils::dol_syslog(get_class($this).'::fetch load personalized conf', LOG_DEBUG); |
| 366 | 366 | $resql = Config::$dbEngine->select($sql); |
| 367 | 367 | if (is_array($resql)) {
|
@@ -399,9 +399,9 @@ discard block |
||
| 399 | 399 | // global $conf; |
| 400 | 400 | // Load user->default_values for user. TODO Save this in memcached ? |
| 401 | 401 | $sql = "SELECT rowid, entity, type, page, param, value"; |
| 402 | - $sql .= " FROM " . MAIN_DB_PREFIX . "default_values"; |
|
| 403 | - $sql .= " WHERE entity IN (" . ($this->entity > 0 ? $this->entity . ", " : "") . Globals::$conf->entity . ")"; // Entity of user (if defined) + current entity
|
|
| 404 | - $sql .= " AND user_id IN (0" . ($this->id > 0 ? ", " . $this->id : "") . ")"; // User 0 (all) + me (if defined) |
|
| 402 | + $sql .= " FROM ".MAIN_DB_PREFIX."default_values"; |
|
| 403 | + $sql .= " WHERE entity IN (".($this->entity > 0 ? $this->entity.", " : "").Globals::$conf->entity.")"; // Entity of user (if defined) + current entity
|
|
| 404 | + $sql .= " AND user_id IN (0".($this->id > 0 ? ", ".$this->id : "").")"; // User 0 (all) + me (if defined) |
|
| 405 | 405 | $resql = Config::$dbEngine->select($sql); |
| 406 | 406 | if (is_array($resql)) {
|
| 407 | 407 | foreach ($resql as $array) {
|
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | $entity = (!empty($entity) ? $entity : Globals::$conf->entity); |
| 452 | 452 | |
| 453 | - DolUtils::dol_syslog(get_class($this) . "::addrights $rid, $allmodule, $allperms, $entity"); |
|
| 453 | + DolUtils::dol_syslog(get_class($this)."::addrights $rid, $allmodule, $allperms, $entity"); |
|
| 454 | 454 | $error = 0; |
| 455 | 455 | $whereforadd = ''; |
| 456 | 456 | |
@@ -460,9 +460,9 @@ discard block |
||
| 460 | 460 | // Si on a demande ajout d'un droit en particulier, on recupere |
| 461 | 461 | // les caracteristiques (module, perms et subperms) de ce droit. |
| 462 | 462 | $sql = "SELECT module, perms, subperms"; |
| 463 | - $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def"; |
|
| 464 | - $sql .= " WHERE id = '" . Config::$dbEngine->escape($rid) . "'"; |
|
| 465 | - $sql .= " AND entity = " . $entity; |
|
| 463 | + $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; |
|
| 464 | + $sql .= " WHERE id = '".Config::$dbEngine->escape($rid)."'"; |
|
| 465 | + $sql .= " AND entity = ".$entity; |
|
| 466 | 466 | |
| 467 | 467 | $result = Config::$dbEngine->query($sql); |
| 468 | 468 | if ($result) {
|
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | } |
| 477 | 477 | |
| 478 | 478 | // Where pour la liste des droits a ajouter |
| 479 | - $whereforadd = "id=" . Config::$dbEngine->escape($rid); |
|
| 479 | + $whereforadd = "id=".Config::$dbEngine->escape($rid); |
|
| 480 | 480 | // Ajout des droits induits |
| 481 | 481 | if (!empty($subperms)) {
|
| 482 | 482 | $whereforadd .= " OR (module='$module' AND perms='$perms' AND (subperms='lire' OR subperms='read'))"; |
@@ -493,9 +493,9 @@ discard block |
||
| 493 | 493 | if ($allmodule == 'allmodules') {
|
| 494 | 494 | $whereforadd = 'allmodules'; |
| 495 | 495 | } else {
|
| 496 | - $whereforadd = "module='" . Config::$dbEngine->escape($allmodule) . "'"; |
|
| 496 | + $whereforadd = "module='".Config::$dbEngine->escape($allmodule)."'"; |
|
| 497 | 497 | if (!empty($allperms)) {
|
| 498 | - $whereforadd .= " AND perms='" . Config::$dbEngine->escape($allperms) . "'"; |
|
| 498 | + $whereforadd .= " AND perms='".Config::$dbEngine->escape($allperms)."'"; |
|
| 499 | 499 | } |
| 500 | 500 | } |
| 501 | 501 | } |
@@ -505,10 +505,10 @@ discard block |
||
| 505 | 505 | if (!empty($whereforadd)) {
|
| 506 | 506 | //print "$module-$perms-$subperms"; |
| 507 | 507 | $sql = "SELECT id"; |
| 508 | - $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def"; |
|
| 509 | - $sql .= " WHERE entity = " . $entity; |
|
| 508 | + $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; |
|
| 509 | + $sql .= " WHERE entity = ".$entity; |
|
| 510 | 510 | if (!empty($whereforadd) && $whereforadd != 'allmodules') {
|
| 511 | - $sql .= " AND " . $whereforadd; |
|
| 511 | + $sql .= " AND ".$whereforadd; |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | 514 | $result = Config::$dbEngine->query($sql); |
@@ -519,10 +519,10 @@ discard block |
||
| 519 | 519 | $obj = Config::$dbEngine->fetch_object($result); |
| 520 | 520 | $nid = $obj->id; |
| 521 | 521 | |
| 522 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights WHERE fk_user = " . $this->id . " AND fk_id=" . $nid . " AND entity = " . $entity; |
|
| 522 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = ".$this->id." AND fk_id=".$nid." AND entity = ".$entity; |
|
| 523 | 523 | if (!Config::$dbEngine->query($sql)) |
| 524 | 524 | $error++; |
| 525 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_rights (entity, fk_user, fk_id) VALUES (" . $entity . ", " . $this->id . ", " . $nid . ")";
|
|
| 525 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (entity, fk_user, fk_id) VALUES (".$entity.", ".$this->id.", ".$nid.")";
|
|
| 526 | 526 | if (!Config::$dbEngine->query($sql)) |
| 527 | 527 | $error++; |
| 528 | 528 | |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | |
| 538 | 538 | if (!$error && !$notrigger) {
|
| 539 | 539 | $langs->load("other");
|
| 540 | - $this->context = array('audit' => $langs->trans("PermissionsAdd") . ($rid ? ' (id=' . $rid . ')' : ''));
|
|
| 540 | + $this->context = array('audit' => $langs->trans("PermissionsAdd").($rid ? ' (id='.$rid.')' : ''));
|
|
| 541 | 541 | |
| 542 | 542 | // Call trigger |
| 543 | 543 | $result = $this->call_trigger('USER_MODIFY', $user);
|
@@ -581,9 +581,9 @@ discard block |
||
| 581 | 581 | // Si on a demande supression d'un droit en particulier, on recupere |
| 582 | 582 | // les caracteristiques module, perms et subperms de ce droit. |
| 583 | 583 | $sql = "SELECT module, perms, subperms"; |
| 584 | - $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def"; |
|
| 585 | - $sql .= " WHERE id = '" . Config::$dbEngine->escape($rid) . "'"; |
|
| 586 | - $sql .= " AND entity = " . $entity; |
|
| 584 | + $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; |
|
| 585 | + $sql .= " WHERE id = '".Config::$dbEngine->escape($rid)."'"; |
|
| 586 | + $sql .= " AND entity = ".$entity; |
|
| 587 | 587 | |
| 588 | 588 | $result = Config::$dbEngine->query($sql); |
| 589 | 589 | if ($result) {
|
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | // Where pour la liste des droits a supprimer |
| 600 | - $wherefordel = "id=" . Config::$dbEngine->escape($rid); |
|
| 600 | + $wherefordel = "id=".Config::$dbEngine->escape($rid); |
|
| 601 | 601 | // Suppression des droits induits |
| 602 | 602 | if ($subperms == 'lire' || $subperms == 'read') {
|
| 603 | 603 | $wherefordel .= " OR (module='$module' AND perms='$perms' AND subperms IS NOT NULL)"; |
@@ -612,9 +612,9 @@ discard block |
||
| 612 | 612 | if ($allmodule == 'allmodules') {
|
| 613 | 613 | $wherefordel = 'allmodules'; |
| 614 | 614 | } else {
|
| 615 | - $wherefordel = "module='" . Config::$dbEngine->escape($allmodule) . "'"; |
|
| 615 | + $wherefordel = "module='".Config::$dbEngine->escape($allmodule)."'"; |
|
| 616 | 616 | if (!empty($allperms)) {
|
| 617 | - $whereforadd .= " AND perms='" . Config::$dbEngine->escape($allperms) . "'"; |
|
| 617 | + $whereforadd .= " AND perms='".Config::$dbEngine->escape($allperms)."'"; |
|
| 618 | 618 | } |
| 619 | 619 | } |
| 620 | 620 | } |
@@ -624,10 +624,10 @@ discard block |
||
| 624 | 624 | if (!empty($wherefordel)) {
|
| 625 | 625 | //print "$module-$perms-$subperms"; |
| 626 | 626 | $sql = "SELECT id"; |
| 627 | - $sql .= " FROM " . MAIN_DB_PREFIX . "rights_def"; |
|
| 628 | - $sql .= " WHERE entity = " . $entity; |
|
| 627 | + $sql .= " FROM ".MAIN_DB_PREFIX."rights_def"; |
|
| 628 | + $sql .= " WHERE entity = ".$entity; |
|
| 629 | 629 | if (!empty($wherefordel) && $wherefordel != 'allmodules') {
|
| 630 | - $sql .= " AND " . $wherefordel; |
|
| 630 | + $sql .= " AND ".$wherefordel; |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | $result = Config::$dbEngine->query($sql); |
@@ -638,9 +638,9 @@ discard block |
||
| 638 | 638 | $obj = Config::$dbEngine->fetch_object($result); |
| 639 | 639 | $nid = $obj->id; |
| 640 | 640 | |
| 641 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights"; |
|
| 642 | - $sql .= " WHERE fk_user = " . $this->id . " AND fk_id=" . $nid; |
|
| 643 | - $sql .= " AND entity = " . $entity; |
|
| 641 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights"; |
|
| 642 | + $sql .= " WHERE fk_user = ".$this->id." AND fk_id=".$nid; |
|
| 643 | + $sql .= " AND entity = ".$entity; |
|
| 644 | 644 | if (!Config::$dbEngine->query($sql)) {
|
| 645 | 645 | $error++; |
| 646 | 646 | } |
@@ -655,7 +655,7 @@ discard block |
||
| 655 | 655 | |
| 656 | 656 | if (!$error && !$notrigger) {
|
| 657 | 657 | $langs->load("other");
|
| 658 | - $this->context = array('audit' => $langs->trans("PermissionsDelete") . ($rid ? ' (id=' . $rid . ')' : ''));
|
|
| 658 | + $this->context = array('audit' => $langs->trans("PermissionsDelete").($rid ? ' (id='.$rid.')' : ''));
|
|
| 659 | 659 | |
| 660 | 660 | // Call trigger |
| 661 | 661 | $result = $this->call_trigger('USER_MODIFY', $user);
|
@@ -682,7 +682,7 @@ discard block |
||
| 682 | 682 | */ |
| 683 | 683 | function clearrights() |
| 684 | 684 | {
|
| 685 | - DolUtils::dol_syslog(get_class($this) . "::clearrights reset user->rights"); |
|
| 685 | + DolUtils::dol_syslog(get_class($this)."::clearrights reset user->rights"); |
|
| 686 | 686 | $this->rights = ''; |
| 687 | 687 | $this->all_permissions_are_loaded = false; |
| 688 | 688 | $this->_tab_loaded = array(); |
@@ -715,19 +715,19 @@ discard block |
||
| 715 | 715 | // Recuperation des droits utilisateurs + recuperation des droits groupes |
| 716 | 716 | // D'abord les droits utilisateurs |
| 717 | 717 | $sql = "SELECT DISTINCT r.module, r.perms, r.subperms"; |
| 718 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user_rights as ur"; |
|
| 719 | - $sql .= ", " . MAIN_DB_PREFIX . "rights_def as r"; |
|
| 718 | + $sql .= " FROM ".MAIN_DB_PREFIX."user_rights as ur"; |
|
| 719 | + $sql .= ", ".MAIN_DB_PREFIX."rights_def as r"; |
|
| 720 | 720 | $sql .= " WHERE r.id = ur.fk_id"; |
| 721 | 721 | if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
|
| 722 | - $sql .= " AND r.entity IN (0," . (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "") . Globals::$conf->entity . ")"; |
|
| 722 | + $sql .= " AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "").Globals::$conf->entity.")"; |
|
| 723 | 723 | } else {
|
| 724 | - $sql .= " AND ur.entity = " . Globals::$conf->entity; |
|
| 724 | + $sql .= " AND ur.entity = ".Globals::$conf->entity; |
|
| 725 | 725 | } |
| 726 | - $sql .= " AND ur.fk_user= " . $this->id; |
|
| 726 | + $sql .= " AND ur.fk_user= ".$this->id; |
|
| 727 | 727 | $sql .= " AND r.perms IS NOT NULL"; |
| 728 | 728 | if ($moduletag) {
|
| 729 | 729 | // $sql .= " AND r.module = '" . Config::$dbEngine->escape($moduletag) . "'"; |
| 730 | - $sql .= " AND r.module = '" . $moduletag . "'"; |
|
| 730 | + $sql .= " AND r.module = '".$moduletag."'"; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | $resql = Config::$dbEngine->select($sql); |
@@ -768,25 +768,25 @@ discard block |
||
| 768 | 768 | |
| 769 | 769 | // Maintenant les droits groupes |
| 770 | 770 | $sql = "SELECT DISTINCT r.module, r.perms, r.subperms"; |
| 771 | - $sql .= " FROM " . MAIN_DB_PREFIX . "usergroup_rights as gr,"; |
|
| 772 | - $sql .= " " . MAIN_DB_PREFIX . "usergroup_user as gu,"; |
|
| 773 | - $sql .= " " . MAIN_DB_PREFIX . "rights_def as r"; |
|
| 771 | + $sql .= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr,"; |
|
| 772 | + $sql .= " ".MAIN_DB_PREFIX."usergroup_user as gu,"; |
|
| 773 | + $sql .= " ".MAIN_DB_PREFIX."rights_def as r"; |
|
| 774 | 774 | $sql .= " WHERE r.id = gr.fk_id"; |
| 775 | 775 | if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
|
| 776 | 776 | if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 777 | - $sql .= " AND gu.entity IN (0," . Globals::$conf->entity . ")"; |
|
| 777 | + $sql .= " AND gu.entity IN (0,".Globals::$conf->entity.")"; |
|
| 778 | 778 | } else {
|
| 779 | - $sql .= " AND r.entity = " . Globals::$conf->entity; |
|
| 779 | + $sql .= " AND r.entity = ".Globals::$conf->entity; |
|
| 780 | 780 | } |
| 781 | 781 | } else {
|
| 782 | - $sql .= " AND gr.entity = " . Globals::$conf->entity; |
|
| 783 | - $sql .= " AND r.entity = " . Globals::$conf->entity; |
|
| 782 | + $sql .= " AND gr.entity = ".Globals::$conf->entity; |
|
| 783 | + $sql .= " AND r.entity = ".Globals::$conf->entity; |
|
| 784 | 784 | } |
| 785 | 785 | $sql .= " AND gr.fk_usergroup = gu.fk_usergroup"; |
| 786 | - $sql .= " AND gu.fk_user = " . $this->id; |
|
| 786 | + $sql .= " AND gu.fk_user = ".$this->id; |
|
| 787 | 787 | $sql .= " AND r.perms IS NOT NULL"; |
| 788 | 788 | if ($moduletag) {
|
| 789 | - $sql .= " AND r.module = '" . $moduletag . "'"; |
|
| 789 | + $sql .= " AND r.module = '".$moduletag."'"; |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | $resql = Config::$dbEngine->select($sql); |
@@ -866,12 +866,12 @@ discard block |
||
| 866 | 866 | Config::$dbEngine->begin(); |
| 867 | 867 | |
| 868 | 868 | // Deactivate user |
| 869 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user"; |
|
| 870 | - $sql .= " SET statut = " . $this->statut; |
|
| 871 | - $sql .= " WHERE rowid = " . $this->id; |
|
| 869 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
| 870 | + $sql .= " SET statut = ".$this->statut; |
|
| 871 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 872 | 872 | $result = Config::$dbEngine->query($sql); |
| 873 | 873 | |
| 874 | - DolUtils::dol_syslog(get_class($this) . "::setstatus", LOG_DEBUG); |
|
| 874 | + DolUtils::dol_syslog(get_class($this)."::setstatus", LOG_DEBUG); |
|
| 875 | 875 | if ($result) {
|
| 876 | 876 | // Call trigger |
| 877 | 877 | $result = $this->call_trigger('USER_ENABLEDISABLE', $user);
|
@@ -908,7 +908,7 @@ discard block |
||
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | // Get current categories |
| 911 | - require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; |
|
| 911 | + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
| 912 | 912 | $c = new Categorie(Config::$dbEngine); |
| 913 | 913 | $existing = $c->containing($this->id, Categorie::TYPE_USER, 'id'); |
| 914 | 914 | |
@@ -951,10 +951,10 @@ discard block |
||
| 951 | 951 | |
| 952 | 952 | $this->fetch($this->id); |
| 953 | 953 | |
| 954 | - DolUtils::dol_syslog(get_class($this) . "::delete", LOG_DEBUG); |
|
| 954 | + DolUtils::dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 955 | 955 | |
| 956 | 956 | // Remove rights |
| 957 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights WHERE fk_user = " . $this->id; |
|
| 957 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = ".$this->id; |
|
| 958 | 958 | |
| 959 | 959 | if (!$error && !Config::$dbEngine->query($sql)) {
|
| 960 | 960 | $error++; |
@@ -962,7 +962,7 @@ discard block |
||
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | // Remove group |
| 965 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "usergroup_user WHERE fk_user = " . $this->id; |
|
| 965 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user WHERE fk_user = ".$this->id; |
|
| 966 | 966 | if (!$error && !Config::$dbEngine->query($sql)) {
|
| 967 | 967 | $error++; |
| 968 | 968 | $this->error = Config::$dbEngine->lasterror(); |
@@ -970,7 +970,7 @@ discard block |
||
| 970 | 970 | |
| 971 | 971 | // If contact, remove link |
| 972 | 972 | if ($this->contact_id) {
|
| 973 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "socpeople SET fk_user_creat = null WHERE rowid = " . $this->contact_id; |
|
| 973 | + $sql = "UPDATE ".MAIN_DB_PREFIX."socpeople SET fk_user_creat = null WHERE rowid = ".$this->contact_id; |
|
| 974 | 974 | if (!$error && !Config::$dbEngine->query($sql)) {
|
| 975 | 975 | $error++; |
| 976 | 976 | $this->error = Config::$dbEngine->lasterror(); |
@@ -982,14 +982,14 @@ discard block |
||
| 982 | 982 | $result = $this->deleteExtraFields(); |
| 983 | 983 | if ($result < 0) {
|
| 984 | 984 | $error++; |
| 985 | - DolUtils::dol_syslog(get_class($this) . "::delete error -4 " . $this->error, LOG_ERR); |
|
| 985 | + DolUtils::dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR); |
|
| 986 | 986 | } |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | // Remove user |
| 990 | 990 | if (!$error) {
|
| 991 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user WHERE rowid = " . $this->id; |
|
| 992 | - DolUtils::dol_syslog(get_class($this) . "::delete", LOG_DEBUG); |
|
| 991 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user WHERE rowid = ".$this->id; |
|
| 992 | + DolUtils::dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 993 | 993 | if (!Config::$dbEngine->query($sql)) {
|
| 994 | 994 | $error++; |
| 995 | 995 | $this->error = Config::$dbEngine->lasterror(); |
@@ -1031,7 +1031,7 @@ discard block |
||
| 1031 | 1031 | if (!isset($this->entity)) {
|
| 1032 | 1032 | $this->entity = Globals::$conf->entity; // If not defined, we use default value |
| 1033 | 1033 | } |
| 1034 | - DolUtils::dol_syslog(get_class($this) . "::create login=" . $this->login . ", user=" . (is_object($user) ? $user->id : ''), LOG_DEBUG); |
|
| 1034 | + DolUtils::dol_syslog(get_class($this)."::create login=".$this->login.", user=".(is_object($user) ? $user->id : ''), LOG_DEBUG); |
|
| 1035 | 1035 | |
| 1036 | 1036 | // Check parameters |
| 1037 | 1037 | if (!empty($conf->global->USER_MAIL_REQUIRED) && !isValidEMail($this->email)) {
|
@@ -1050,11 +1050,11 @@ discard block |
||
| 1050 | 1050 | $error = 0; |
| 1051 | 1051 | Config::$dbEngine->begin(); |
| 1052 | 1052 | |
| 1053 | - $sql = "SELECT login FROM " . MAIN_DB_PREFIX . "user"; |
|
| 1054 | - $sql .= " WHERE login ='" . Config::$dbEngine->escape($this->login) . "'"; |
|
| 1055 | - $sql .= " AND entity IN (0," . Config::$dbEngine->escape($conf->entity) . ")"; |
|
| 1053 | + $sql = "SELECT login FROM ".MAIN_DB_PREFIX."user"; |
|
| 1054 | + $sql .= " WHERE login ='".Config::$dbEngine->escape($this->login)."'"; |
|
| 1055 | + $sql .= " AND entity IN (0,".Config::$dbEngine->escape($conf->entity).")"; |
|
| 1056 | 1056 | |
| 1057 | - DolUtils::dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
|
| 1057 | + DolUtils::dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 1058 | 1058 | $resql = Config::$dbEngine->query($sql); |
| 1059 | 1059 | if ($resql) {
|
| 1060 | 1060 | $num = Config::$dbEngine->num_rows($resql); |
@@ -1062,17 +1062,17 @@ discard block |
||
| 1062 | 1062 | |
| 1063 | 1063 | if ($num) {
|
| 1064 | 1064 | $this->error = 'ErrorLoginAlreadyExists'; |
| 1065 | - DolUtils::dol_syslog(get_class($this) . "::create " . $this->error, LOG_WARNING); |
|
| 1065 | + DolUtils::dol_syslog(get_class($this)."::create ".$this->error, LOG_WARNING); |
|
| 1066 | 1066 | Config::$dbEngine->rollback(); |
| 1067 | 1067 | return -6; |
| 1068 | 1068 | } else {
|
| 1069 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user (datec,login,ldap_sid,entity)"; |
|
| 1070 | - $sql .= " VALUES('" . Config::$dbEngine->idate($this->datec) . "','" . Config::$dbEngine->escape($this->login) . "','" . Config::$dbEngine->escape($this->ldap_sid) . "'," . Config::$dbEngine->escape($this->entity) . ")";
|
|
| 1069 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."user (datec,login,ldap_sid,entity)"; |
|
| 1070 | + $sql .= " VALUES('".Config::$dbEngine->idate($this->datec)."','".Config::$dbEngine->escape($this->login)."','".Config::$dbEngine->escape($this->ldap_sid)."',".Config::$dbEngine->escape($this->entity).")";
|
|
| 1071 | 1071 | $result = Config::$dbEngine->query($sql); |
| 1072 | 1072 | |
| 1073 | - DolUtils::dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
|
| 1073 | + DolUtils::dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 1074 | 1074 | if ($result) {
|
| 1075 | - $this->id = Config::$dbEngine->last_insert_id(MAIN_DB_PREFIX . "user"); |
|
| 1075 | + $this->id = Config::$dbEngine->last_insert_id(MAIN_DB_PREFIX."user"); |
|
| 1076 | 1076 | |
| 1077 | 1077 | // Set default rights |
| 1078 | 1078 | if ($this->set_default_rights() < 0) {
|
@@ -1089,7 +1089,7 @@ discard block |
||
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | if (!empty($conf->global->STOCK_USERSTOCK_AUTOCREATE)) {
|
| 1092 | - require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; |
|
| 1092 | + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; |
|
| 1093 | 1093 | $langs->load("stocks");
|
| 1094 | 1094 | $entrepot = new Entrepot(Config::$dbEngine); |
| 1095 | 1095 | $entrepot->libelle = $langs->trans("PersonalStock", $this->getFullName($langs));
|
@@ -1113,7 +1113,7 @@ discard block |
||
| 1113 | 1113 | return $this->id; |
| 1114 | 1114 | } else {
|
| 1115 | 1115 | //$this->error=$interface->error; |
| 1116 | - DolUtils::dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR); |
|
| 1116 | + DolUtils::dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR); |
|
| 1117 | 1117 | Config::$dbEngine->rollback(); |
| 1118 | 1118 | return -3; |
| 1119 | 1119 | } |
@@ -1166,7 +1166,7 @@ discard block |
||
| 1166 | 1166 | $this->employee = 0; |
| 1167 | 1167 | |
| 1168 | 1168 | if (empty($login)) {
|
| 1169 | - $login = strtolower(substr($contact->firstname, 0, 4)) . strtolower(substr($contact->lastname, 0, 4)); |
|
| 1169 | + $login = strtolower(substr($contact->firstname, 0, 4)).strtolower(substr($contact->lastname, 0, 4)); |
|
| 1170 | 1170 | } |
| 1171 | 1171 | $this->login = $login; |
| 1172 | 1172 | |
@@ -1175,15 +1175,15 @@ discard block |
||
| 1175 | 1175 | // Cree et positionne $this->id |
| 1176 | 1176 | $result = $this->create($user); |
| 1177 | 1177 | if ($result > 0) {
|
| 1178 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user"; |
|
| 1179 | - $sql .= " SET fk_socpeople=" . $contact->id; |
|
| 1178 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
| 1179 | + $sql .= " SET fk_socpeople=".$contact->id; |
|
| 1180 | 1180 | if ($contact->socid) {
|
| 1181 | - $sql .= ", fk_soc=" . $contact->socid; |
|
| 1181 | + $sql .= ", fk_soc=".$contact->socid; |
|
| 1182 | 1182 | } |
| 1183 | - $sql .= " WHERE rowid=" . $this->id; |
|
| 1183 | + $sql .= " WHERE rowid=".$this->id; |
|
| 1184 | 1184 | $resql = Config::$dbEngine->query($sql); |
| 1185 | 1185 | |
| 1186 | - DolUtils::dol_syslog(get_class($this) . "::create_from_contact", LOG_DEBUG); |
|
| 1186 | + DolUtils::dol_syslog(get_class($this)."::create_from_contact", LOG_DEBUG); |
|
| 1187 | 1187 | if ($resql) {
|
| 1188 | 1188 | $this->context['createfromcontact'] = 'createfromcontact'; |
| 1189 | 1189 | |
@@ -1206,7 +1206,7 @@ discard block |
||
| 1206 | 1206 | } |
| 1207 | 1207 | } else {
|
| 1208 | 1208 | // $this->error deja positionne |
| 1209 | - DolUtils::dol_syslog(get_class($this) . "::create_from_contact - 0"); |
|
| 1209 | + DolUtils::dol_syslog(get_class($this)."::create_from_contact - 0"); |
|
| 1210 | 1210 | |
| 1211 | 1211 | Config::$dbEngine->rollback(); |
| 1212 | 1212 | return $result; |
@@ -1241,7 +1241,7 @@ discard block |
||
| 1241 | 1241 | $this->country_id = $member->country_id; |
| 1242 | 1242 | |
| 1243 | 1243 | if (empty($login)) {
|
| 1244 | - $login = strtolower(substr($member->firstname, 0, 4)) . strtolower(substr($member->lastname, 0, 4)); |
|
| 1244 | + $login = strtolower(substr($member->firstname, 0, 4)).strtolower(substr($member->lastname, 0, 4)); |
|
| 1245 | 1245 | } |
| 1246 | 1246 | $this->login = $login; |
| 1247 | 1247 | |
@@ -1256,11 +1256,11 @@ discard block |
||
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | if ($result > 0 && $member->fk_soc) { // If member is linked to a thirdparty
|
| 1259 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user"; |
|
| 1260 | - $sql .= " SET fk_soc=" . $member->fk_soc; |
|
| 1261 | - $sql .= " WHERE rowid=" . $this->id; |
|
| 1259 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
| 1260 | + $sql .= " SET fk_soc=".$member->fk_soc; |
|
| 1261 | + $sql .= " WHERE rowid=".$this->id; |
|
| 1262 | 1262 | |
| 1263 | - DolUtils::dol_syslog(get_class($this) . "::create_from_member", LOG_DEBUG); |
|
| 1263 | + DolUtils::dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); |
|
| 1264 | 1264 | $resql = Config::$dbEngine->query($sql); |
| 1265 | 1265 | if ($resql) {
|
| 1266 | 1266 | Config::$dbEngine->commit(); |
@@ -1295,9 +1295,9 @@ discard block |
||
| 1295 | 1295 | // phpcs:enable |
| 1296 | 1296 | global $conf; |
| 1297 | 1297 | |
| 1298 | - $sql = "SELECT id FROM " . MAIN_DB_PREFIX . "rights_def"; |
|
| 1298 | + $sql = "SELECT id FROM ".MAIN_DB_PREFIX."rights_def"; |
|
| 1299 | 1299 | $sql .= " WHERE bydefault = 1"; |
| 1300 | - $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 1300 | + $sql .= " AND entity = ".Globals::$conf->entity; |
|
| 1301 | 1301 | |
| 1302 | 1302 | $resql = Config::$dbEngine->query($sql); |
| 1303 | 1303 | if ($resql) {
|
@@ -1314,10 +1314,10 @@ discard block |
||
| 1314 | 1314 | $i = 0; |
| 1315 | 1315 | while ($i < $num) {
|
| 1316 | 1316 | |
| 1317 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]"; |
|
| 1317 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_rights WHERE fk_user = $this->id AND fk_id=$rd[$i]"; |
|
| 1318 | 1318 | $result = Config::$dbEngine->query($sql); |
| 1319 | 1319 | |
| 1320 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])"; |
|
| 1320 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_rights (fk_user, fk_id) VALUES ($this->id, $rd[$i])"; |
|
| 1321 | 1321 | $result = Config::$dbEngine->query($sql); |
| 1322 | 1322 | if (!$result) {
|
| 1323 | 1323 | return -1; |
@@ -1345,7 +1345,7 @@ discard block |
||
| 1345 | 1345 | $nbrowsaffected = 0; |
| 1346 | 1346 | $error = 0; |
| 1347 | 1347 | |
| 1348 | - DolUtils::dol_syslog(get_class($this) . "::update notrigger=" . $notrigger . ", nosyncmember=" . $nosyncmember . ", nosyncmemberpass=" . $nosyncmemberpass); |
|
| 1348 | + DolUtils::dol_syslog(get_class($this)."::update notrigger=".$notrigger.", nosyncmember=".$nosyncmember.", nosyncmemberpass=".$nosyncmemberpass); |
|
| 1349 | 1349 | |
| 1350 | 1350 | // Clean parameters |
| 1351 | 1351 | $this->lastname = trim($this->lastname); |
@@ -1373,7 +1373,7 @@ discard block |
||
| 1373 | 1373 | $this->job = trim($this->job); |
| 1374 | 1374 | $this->signature = trim($this->signature); |
| 1375 | 1375 | $this->note = trim($this->note); |
| 1376 | - $this->openid = trim(empty($this->openid) ? '' : $this->openid); // Avoid warning |
|
| 1376 | + $this->openid = trim(empty($this->openid) ? '' : $this->openid); // Avoid warning |
|
| 1377 | 1377 | $this->admin = $this->admin ? $this->admin : 0; |
| 1378 | 1378 | $this->address = empty($this->address) ? '' : $this->address; |
| 1379 | 1379 | $this->zip = empty($this->zip) ? '' : $this->zip; |
@@ -1398,59 +1398,59 @@ discard block |
||
| 1398 | 1398 | Config::$dbEngine->begin(); |
| 1399 | 1399 | |
| 1400 | 1400 | // Update datas |
| 1401 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET"; |
|
| 1402 | - $sql .= " lastname = '" . Config::$dbEngine->escape($this->lastname) . "'"; |
|
| 1403 | - $sql .= ", firstname = '" . Config::$dbEngine->escape($this->firstname) . "'"; |
|
| 1404 | - $sql .= ", employee = " . $this->employee; |
|
| 1405 | - $sql .= ", login = '" . Config::$dbEngine->escape($this->login) . "'"; |
|
| 1406 | - $sql .= ", api_key = " . ($this->api_key ? "'" . Config::$dbEngine->escape($this->api_key) . "'" : "null"); |
|
| 1407 | - $sql .= ", gender = " . ($this->gender != -1 ? "'" . Config::$dbEngine->escape($this->gender) . "'" : "null"); // 'man' or 'woman' |
|
| 1408 | - $sql .= ", birth=" . (strval($this->birth) != '' ? "'" . Config::$dbEngine->idate($this->birth) . "'" : 'null'); |
|
| 1401 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; |
|
| 1402 | + $sql .= " lastname = '".Config::$dbEngine->escape($this->lastname)."'"; |
|
| 1403 | + $sql .= ", firstname = '".Config::$dbEngine->escape($this->firstname)."'"; |
|
| 1404 | + $sql .= ", employee = ".$this->employee; |
|
| 1405 | + $sql .= ", login = '".Config::$dbEngine->escape($this->login)."'"; |
|
| 1406 | + $sql .= ", api_key = ".($this->api_key ? "'".Config::$dbEngine->escape($this->api_key)."'" : "null"); |
|
| 1407 | + $sql .= ", gender = ".($this->gender != -1 ? "'".Config::$dbEngine->escape($this->gender)."'" : "null"); // 'man' or 'woman' |
|
| 1408 | + $sql .= ", birth=".(strval($this->birth) != '' ? "'".Config::$dbEngine->idate($this->birth)."'" : 'null'); |
|
| 1409 | 1409 | if (!empty($user->admin)) {
|
| 1410 | - $sql .= ", admin = " . $this->admin; // admin flag can be set/unset only by an admin user |
|
| 1411 | - } |
|
| 1412 | - $sql .= ", address = '" . Config::$dbEngine->escape($this->address) . "'"; |
|
| 1413 | - $sql .= ", zip = '" . Config::$dbEngine->escape($this->zip) . "'"; |
|
| 1414 | - $sql .= ", town = '" . Config::$dbEngine->escape($this->town) . "'"; |
|
| 1415 | - $sql .= ", fk_state = " . ((!empty($this->state_id) && $this->state_id > 0) ? "'" . Config::$dbEngine->escape($this->state_id) . "'" : "null"); |
|
| 1416 | - $sql .= ", fk_country = " . ((!empty($this->country_id) && $this->country_id > 0) ? "'" . Config::$dbEngine->escape($this->country_id) . "'" : "null"); |
|
| 1417 | - $sql .= ", office_phone = '" . Config::$dbEngine->escape($this->office_phone) . "'"; |
|
| 1418 | - $sql .= ", office_fax = '" . Config::$dbEngine->escape($this->office_fax) . "'"; |
|
| 1419 | - $sql .= ", user_mobile = '" . Config::$dbEngine->escape($this->user_mobile) . "'"; |
|
| 1420 | - $sql .= ", email = '" . Config::$dbEngine->escape($this->email) . "'"; |
|
| 1421 | - $sql .= ", skype = '" . Config::$dbEngine->escape($this->skype) . "'"; |
|
| 1422 | - $sql .= ", twitter = '" . Config::$dbEngine->escape($this->twitter) . "'"; |
|
| 1423 | - $sql .= ", facebook = '" . Config::$dbEngine->escape($this->facebook) . "'"; |
|
| 1424 | - $sql .= ", job = '" . Config::$dbEngine->escape($this->job) . "'"; |
|
| 1425 | - $sql .= ", signature = '" . Config::$dbEngine->escape($this->signature) . "'"; |
|
| 1426 | - $sql .= ", accountancy_code = '" . Config::$dbEngine->escape($this->accountancy_code) . "'"; |
|
| 1427 | - $sql .= ", color = '" . Config::$dbEngine->escape($this->color) . "'"; |
|
| 1428 | - $sql .= ", dateemployment=" . (strval($this->dateemployment) != '' ? "'" . Config::$dbEngine->idate($this->dateemployment) . "'" : 'null'); |
|
| 1429 | - $sql .= ", dateemploymentend=" . (strval($this->dateemploymentend) != '' ? "'" . Config::$dbEngine->idate($this->dateemploymentend) . "'" : 'null'); |
|
| 1430 | - $sql .= ", note = '" . Config::$dbEngine->escape($this->note) . "'"; |
|
| 1431 | - $sql .= ", photo = " . ($this->photo ? "'" . Config::$dbEngine->escape($this->photo) . "'" : "null"); |
|
| 1432 | - $sql .= ", openid = " . ($this->openid ? "'" . Config::$dbEngine->escape($this->openid) . "'" : "null"); |
|
| 1433 | - $sql .= ", fk_user = " . ($this->fk_user > 0 ? "'" . Config::$dbEngine->escape($this->fk_user) . "'" : "null"); |
|
| 1410 | + $sql .= ", admin = ".$this->admin; // admin flag can be set/unset only by an admin user |
|
| 1411 | + } |
|
| 1412 | + $sql .= ", address = '".Config::$dbEngine->escape($this->address)."'"; |
|
| 1413 | + $sql .= ", zip = '".Config::$dbEngine->escape($this->zip)."'"; |
|
| 1414 | + $sql .= ", town = '".Config::$dbEngine->escape($this->town)."'"; |
|
| 1415 | + $sql .= ", fk_state = ".((!empty($this->state_id) && $this->state_id > 0) ? "'".Config::$dbEngine->escape($this->state_id)."'" : "null"); |
|
| 1416 | + $sql .= ", fk_country = ".((!empty($this->country_id) && $this->country_id > 0) ? "'".Config::$dbEngine->escape($this->country_id)."'" : "null"); |
|
| 1417 | + $sql .= ", office_phone = '".Config::$dbEngine->escape($this->office_phone)."'"; |
|
| 1418 | + $sql .= ", office_fax = '".Config::$dbEngine->escape($this->office_fax)."'"; |
|
| 1419 | + $sql .= ", user_mobile = '".Config::$dbEngine->escape($this->user_mobile)."'"; |
|
| 1420 | + $sql .= ", email = '".Config::$dbEngine->escape($this->email)."'"; |
|
| 1421 | + $sql .= ", skype = '".Config::$dbEngine->escape($this->skype)."'"; |
|
| 1422 | + $sql .= ", twitter = '".Config::$dbEngine->escape($this->twitter)."'"; |
|
| 1423 | + $sql .= ", facebook = '".Config::$dbEngine->escape($this->facebook)."'"; |
|
| 1424 | + $sql .= ", job = '".Config::$dbEngine->escape($this->job)."'"; |
|
| 1425 | + $sql .= ", signature = '".Config::$dbEngine->escape($this->signature)."'"; |
|
| 1426 | + $sql .= ", accountancy_code = '".Config::$dbEngine->escape($this->accountancy_code)."'"; |
|
| 1427 | + $sql .= ", color = '".Config::$dbEngine->escape($this->color)."'"; |
|
| 1428 | + $sql .= ", dateemployment=".(strval($this->dateemployment) != '' ? "'".Config::$dbEngine->idate($this->dateemployment)."'" : 'null'); |
|
| 1429 | + $sql .= ", dateemploymentend=".(strval($this->dateemploymentend) != '' ? "'".Config::$dbEngine->idate($this->dateemploymentend)."'" : 'null'); |
|
| 1430 | + $sql .= ", note = '".Config::$dbEngine->escape($this->note)."'"; |
|
| 1431 | + $sql .= ", photo = ".($this->photo ? "'".Config::$dbEngine->escape($this->photo)."'" : "null"); |
|
| 1432 | + $sql .= ", openid = ".($this->openid ? "'".Config::$dbEngine->escape($this->openid)."'" : "null"); |
|
| 1433 | + $sql .= ", fk_user = ".($this->fk_user > 0 ? "'".Config::$dbEngine->escape($this->fk_user)."'" : "null"); |
|
| 1434 | 1434 | if (isset($this->thm) || $this->thm != '') {
|
| 1435 | - $sql .= ", thm= " . ($this->thm != '' ? "'" . Config::$dbEngine->escape($this->thm) . "'" : "null"); |
|
| 1435 | + $sql .= ", thm= ".($this->thm != '' ? "'".Config::$dbEngine->escape($this->thm)."'" : "null"); |
|
| 1436 | 1436 | } |
| 1437 | 1437 | if (isset($this->tjm) || $this->tjm != '') {
|
| 1438 | - $sql .= ", tjm= " . ($this->tjm != '' ? "'" . Config::$dbEngine->escape($this->tjm) . "'" : "null"); |
|
| 1438 | + $sql .= ", tjm= ".($this->tjm != '' ? "'".Config::$dbEngine->escape($this->tjm)."'" : "null"); |
|
| 1439 | 1439 | } |
| 1440 | 1440 | if (isset($this->salary) || $this->salary != '') {
|
| 1441 | - $sql .= ", salary= " . ($this->salary != '' ? "'" . Config::$dbEngine->escape($this->salary) . "'" : "null"); |
|
| 1441 | + $sql .= ", salary= ".($this->salary != '' ? "'".Config::$dbEngine->escape($this->salary)."'" : "null"); |
|
| 1442 | 1442 | } |
| 1443 | 1443 | if (isset($this->salaryextra) || $this->salaryextra != '') {
|
| 1444 | - $sql .= ", salaryextra= " . ($this->salaryextra != '' ? "'" . Config::$dbEngine->escape($this->salaryextra) . "'" : "null"); |
|
| 1444 | + $sql .= ", salaryextra= ".($this->salaryextra != '' ? "'".Config::$dbEngine->escape($this->salaryextra)."'" : "null"); |
|
| 1445 | 1445 | } |
| 1446 | - $sql .= ", weeklyhours= " . ($this->weeklyhours != '' ? "'" . Config::$dbEngine->escape($this->weeklyhours) . "'" : "null"); |
|
| 1447 | - $sql .= ", entity = '" . Config::$dbEngine->escape($this->entity) . "'"; |
|
| 1448 | - $sql .= ", default_range = " . ($this->default_range > 0 ? $this->default_range : 'null'); |
|
| 1449 | - $sql .= ", default_c_exp_tax_cat = " . ($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); |
|
| 1446 | + $sql .= ", weeklyhours= ".($this->weeklyhours != '' ? "'".Config::$dbEngine->escape($this->weeklyhours)."'" : "null"); |
|
| 1447 | + $sql .= ", entity = '".Config::$dbEngine->escape($this->entity)."'"; |
|
| 1448 | + $sql .= ", default_range = ".($this->default_range > 0 ? $this->default_range : 'null'); |
|
| 1449 | + $sql .= ", default_c_exp_tax_cat = ".($this->default_c_exp_tax_cat > 0 ? $this->default_c_exp_tax_cat : 'null'); |
|
| 1450 | 1450 | |
| 1451 | - $sql .= " WHERE rowid = " . $this->id; |
|
| 1451 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 1452 | 1452 | |
| 1453 | - DolUtils::dol_syslog(get_class($this) . "::update", LOG_DEBUG); |
|
| 1453 | + DolUtils::dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 1454 | 1454 | $resql = Config::$dbEngine->query($sql); |
| 1455 | 1455 | if ($resql) {
|
| 1456 | 1456 | $nbrowsaffected += Config::$dbEngine->affected_rows($resql); |
@@ -1468,8 +1468,8 @@ discard block |
||
| 1468 | 1468 | |
| 1469 | 1469 | // If user is linked to a member, remove old link to this member |
| 1470 | 1470 | if ($this->fk_member > 0) {
|
| 1471 | - DolUtils::dol_syslog(get_class($this) . "::update remove link with member. We will recreate it later", LOG_DEBUG); |
|
| 1472 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET fk_member = NULL where fk_member = " . $this->fk_member; |
|
| 1471 | + DolUtils::dol_syslog(get_class($this)."::update remove link with member. We will recreate it later", LOG_DEBUG); |
|
| 1472 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member = NULL where fk_member = ".$this->fk_member; |
|
| 1473 | 1473 | $resql = Config::$dbEngine->query($sql); |
| 1474 | 1474 | if (!$resql) {
|
| 1475 | 1475 | $this->error = Config::$dbEngine->error(); |
@@ -1478,8 +1478,8 @@ discard block |
||
| 1478 | 1478 | } |
| 1479 | 1479 | } |
| 1480 | 1480 | // Set link to user |
| 1481 | - DolUtils::dol_syslog(get_class($this) . "::update set link with member", LOG_DEBUG); |
|
| 1482 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET fk_member =" . ($this->fk_member > 0 ? $this->fk_member : 'null') . " where rowid = " . $this->id; |
|
| 1481 | + DolUtils::dol_syslog(get_class($this)."::update set link with member", LOG_DEBUG); |
|
| 1482 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET fk_member =".($this->fk_member > 0 ? $this->fk_member : 'null')." where rowid = ".$this->id; |
|
| 1483 | 1483 | $resql = Config::$dbEngine->query($sql); |
| 1484 | 1484 | if (!$resql) {
|
| 1485 | 1485 | $this->error = Config::$dbEngine->error(); |
@@ -1489,9 +1489,9 @@ discard block |
||
| 1489 | 1489 | |
| 1490 | 1490 | if ($nbrowsaffected) { // If something has changed in data
|
| 1491 | 1491 | if ($this->fk_member > 0 && !$nosyncmember) {
|
| 1492 | - DolUtils::dol_syslog(get_class($this) . "::update user is linked with a member. We try to update member too.", LOG_DEBUG); |
|
| 1492 | + DolUtils::dol_syslog(get_class($this)."::update user is linked with a member. We try to update member too.", LOG_DEBUG); |
|
| 1493 | 1493 | |
| 1494 | - require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; |
|
| 1494 | + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
| 1495 | 1495 | |
| 1496 | 1496 | // This user is linked with a member, so we also update member information |
| 1497 | 1497 | // if this is an update. |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | if ($result < 0) {
|
| 1532 | 1532 | $this->error = $adh->error; |
| 1533 | 1533 | $this->errors = $adh->errors; |
| 1534 | - DolUtils::dol_syslog(get_class($this) . "::update error after calling adh->update to sync it with user: " . $this->error, LOG_ERR); |
|
| 1534 | + DolUtils::dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); |
|
| 1535 | 1535 | $error++; |
| 1536 | 1536 | } |
| 1537 | 1537 | } else {
|
@@ -1542,9 +1542,9 @@ discard block |
||
| 1542 | 1542 | } |
| 1543 | 1543 | |
| 1544 | 1544 | if ($this->contact_id > 0 && !$nosynccontact) {
|
| 1545 | - DolUtils::dol_syslog(get_class($this) . "::update user is linked with a contact. We try to update contact too.", LOG_DEBUG); |
|
| 1545 | + DolUtils::dol_syslog(get_class($this)."::update user is linked with a contact. We try to update contact too.", LOG_DEBUG); |
|
| 1546 | 1546 | |
| 1547 | - require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; |
|
| 1547 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 1548 | 1548 | |
| 1549 | 1549 | // This user is linked with a contact, so we also update contact information |
| 1550 | 1550 | // if this is an update. |
@@ -1584,7 +1584,7 @@ discard block |
||
| 1584 | 1584 | if ($result < 0) {
|
| 1585 | 1585 | $this->error = $tmpobj->error; |
| 1586 | 1586 | $this->errors = $tmpobj->errors; |
| 1587 | - DolUtils::dol_syslog(get_class($this) . "::update error after calling adh->update to sync it with user: " . $this->error, LOG_ERR); |
|
| 1587 | + DolUtils::dol_syslog(get_class($this)."::update error after calling adh->update to sync it with user: ".$this->error, LOG_ERR); |
|
| 1588 | 1588 | $error++; |
| 1589 | 1589 | } |
| 1590 | 1590 | } else {
|
@@ -1618,7 +1618,7 @@ discard block |
||
| 1618 | 1618 | Config::$dbEngine->commit(); |
| 1619 | 1619 | return $nbrowsaffected; |
| 1620 | 1620 | } else {
|
| 1621 | - DolUtils::dol_syslog(get_class($this) . "::update error=" . $this->error, LOG_ERR); |
|
| 1621 | + DolUtils::dol_syslog(get_class($this)."::update error=".$this->error, LOG_ERR); |
|
| 1622 | 1622 | Config::$dbEngine->rollback(); |
| 1623 | 1623 | return -1; |
| 1624 | 1624 | } |
@@ -1641,20 +1641,20 @@ discard block |
||
| 1641 | 1641 | // phpcs:enable |
| 1642 | 1642 | $now = dol_now(); |
| 1643 | 1643 | |
| 1644 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user SET"; |
|
| 1644 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user SET"; |
|
| 1645 | 1645 | $sql .= " datepreviouslogin = datelastlogin,"; |
| 1646 | - $sql .= " datelastlogin = '" . Config::$dbEngine->idate($now) . "',"; |
|
| 1647 | - $sql .= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion |
|
| 1648 | - $sql .= " WHERE rowid = " . $this->id; |
|
| 1646 | + $sql .= " datelastlogin = '".Config::$dbEngine->idate($now)."',"; |
|
| 1647 | + $sql .= " tms = tms"; // La date de derniere modif doit changer sauf pour la mise a jour de date de derniere connexion |
|
| 1648 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 1649 | 1649 | |
| 1650 | - DolUtils::dol_syslog(get_class($this) . "::update_last_login_date user->id=" . $this->id . " " . $sql, LOG_DEBUG); |
|
| 1650 | + DolUtils::dol_syslog(get_class($this)."::update_last_login_date user->id=".$this->id." ".$sql, LOG_DEBUG); |
|
| 1651 | 1651 | $resql = Config::$dbEngine->query($sql); |
| 1652 | 1652 | if ($resql) {
|
| 1653 | 1653 | $this->datepreviouslogin = $this->datelastlogin; |
| 1654 | 1654 | $this->datelastlogin = $now; |
| 1655 | 1655 | return 1; |
| 1656 | 1656 | } else {
|
| 1657 | - $this->error = Config::$dbEngine->lasterror() . ' sql=' . $sql; |
|
| 1657 | + $this->error = Config::$dbEngine->lasterror().' sql='.$sql; |
|
| 1658 | 1658 | return -1; |
| 1659 | 1659 | } |
| 1660 | 1660 | } |
@@ -1672,11 +1672,11 @@ discard block |
||
| 1672 | 1672 | function setPassword($user, $password = '', $changelater = 0, $notrigger = 0, $nosyncmember = 0) |
| 1673 | 1673 | {
|
| 1674 | 1674 | global $conf, $langs; |
| 1675 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/security2.lib.php'; |
|
| 1675 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 1676 | 1676 | |
| 1677 | 1677 | $error = 0; |
| 1678 | 1678 | |
| 1679 | - DolUtils::dol_syslog(get_class($this) . "::setPassword user=" . $user->id . " password=" . preg_replace('/./i', '*', $password) . " changelater=" . $changelater . " notrigger=" . $notrigger . " nosyncmember=" . $nosyncmember, LOG_DEBUG);
|
|
| 1679 | + DolUtils::dol_syslog(get_class($this)."::setPassword user=".$user->id." password=".preg_replace('/./i', '*', $password)." changelater=".$changelater." notrigger=".$notrigger." nosyncmember=".$nosyncmember, LOG_DEBUG);
|
|
| 1680 | 1680 | |
| 1681 | 1681 | // If new password not provided, we generate one |
| 1682 | 1682 | if (!$password) {
|
@@ -1694,17 +1694,17 @@ discard block |
||
| 1694 | 1694 | |
| 1695 | 1695 | Config::$dbEngine->begin(); |
| 1696 | 1696 | |
| 1697 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user"; |
|
| 1698 | - $sql .= " SET pass_crypted = '" . Config::$dbEngine->escape($password_crypted) . "',"; |
|
| 1697 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
| 1698 | + $sql .= " SET pass_crypted = '".Config::$dbEngine->escape($password_crypted)."',"; |
|
| 1699 | 1699 | $sql .= " pass_temp = null"; |
| 1700 | 1700 | if (!empty($conf->global->DATABASE_PWD_ENCRYPTED)) {
|
| 1701 | 1701 | $sql .= ", pass = null"; |
| 1702 | 1702 | } else {
|
| 1703 | - $sql .= ", pass = '" . Config::$dbEngine->escape($password) . "'"; |
|
| 1703 | + $sql .= ", pass = '".Config::$dbEngine->escape($password)."'"; |
|
| 1704 | 1704 | } |
| 1705 | - $sql .= " WHERE rowid = " . $this->id; |
|
| 1705 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 1706 | 1706 | |
| 1707 | - DolUtils::dol_syslog(get_class($this) . "::setPassword", LOG_DEBUG); |
|
| 1707 | + DolUtils::dol_syslog(get_class($this)."::setPassword", LOG_DEBUG); |
|
| 1708 | 1708 | $result = Config::$dbEngine->query($sql); |
| 1709 | 1709 | if ($result) {
|
| 1710 | 1710 | if (Config::$dbEngine->affected_rows($result)) {
|
@@ -1713,7 +1713,7 @@ discard block |
||
| 1713 | 1713 | $this->pass_indatabase_crypted = $password_crypted; |
| 1714 | 1714 | |
| 1715 | 1715 | if ($this->fk_member && !$nosyncmember) {
|
| 1716 | - require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; |
|
| 1716 | + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
| 1717 | 1717 | |
| 1718 | 1718 | // This user is linked with a member, so we also update members informations |
| 1719 | 1719 | // if this is an update. |
@@ -1724,7 +1724,7 @@ discard block |
||
| 1724 | 1724 | $result = $adh->setPassword($user, $this->pass, (empty($conf->global->DATABASE_PWD_ENCRYPTED) ? 0 : 1), 1); // Cryptage non gere dans module adherent |
| 1725 | 1725 | if ($result < 0) {
|
| 1726 | 1726 | $this->error = $adh->error; |
| 1727 | - DolUtils::dol_syslog(get_class($this) . "::setPassword " . $this->error, LOG_ERR); |
|
| 1727 | + DolUtils::dol_syslog(get_class($this)."::setPassword ".$this->error, LOG_ERR); |
|
| 1728 | 1728 | $error++; |
| 1729 | 1729 | } |
| 1730 | 1730 | } else {
|
@@ -1733,7 +1733,7 @@ discard block |
||
| 1733 | 1733 | } |
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | - DolUtils::dol_syslog(get_class($this) . "::setPassword notrigger=" . $notrigger . " error=" . $error, LOG_DEBUG); |
|
| 1736 | + DolUtils::dol_syslog(get_class($this)."::setPassword notrigger=".$notrigger." error=".$error, LOG_DEBUG); |
|
| 1737 | 1737 | |
| 1738 | 1738 | if (!$error && !$notrigger) {
|
| 1739 | 1739 | // Call trigger |
@@ -1760,11 +1760,11 @@ discard block |
||
| 1760 | 1760 | } else {
|
| 1761 | 1761 | // We store clear password in password temporary field. |
| 1762 | 1762 | // After receiving confirmation link, we will crypt it and store it in pass_crypted |
| 1763 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "user"; |
|
| 1764 | - $sql .= " SET pass_temp = '" . Config::$dbEngine->escape($password) . "'"; |
|
| 1765 | - $sql .= " WHERE rowid = " . $this->id; |
|
| 1763 | + $sql = "UPDATE ".MAIN_DB_PREFIX."user"; |
|
| 1764 | + $sql .= " SET pass_temp = '".Config::$dbEngine->escape($password)."'"; |
|
| 1765 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 1766 | 1766 | |
| 1767 | - DolUtils::dol_syslog(get_class($this) . "::setPassword", LOG_DEBUG); // No log |
|
| 1767 | + DolUtils::dol_syslog(get_class($this)."::setPassword", LOG_DEBUG); // No log |
|
| 1768 | 1768 | $result = Config::$dbEngine->query($sql); |
| 1769 | 1769 | if ($result) {
|
| 1770 | 1770 | return $password; |
@@ -1790,7 +1790,7 @@ discard block |
||
| 1790 | 1790 | global $conf, $langs; |
| 1791 | 1791 | global $dolibarr_main_url_root; |
| 1792 | 1792 | |
| 1793 | - require_once DOL_DOCUMENT_ROOT . '/core/class/CMailFile.class.php'; |
|
| 1793 | + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; |
|
| 1794 | 1794 | |
| 1795 | 1795 | $msgishtml = 0; |
| 1796 | 1796 | |
@@ -1815,36 +1815,36 @@ discard block |
||
| 1815 | 1815 | $subject = $outputlangs->transnoentitiesnoconv("SubjectNewPassword", $appli);
|
| 1816 | 1816 | |
| 1817 | 1817 | // Define $urlwithroot |
| 1818 | - $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root));
|
|
| 1819 | - $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 1818 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
|
|
| 1819 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 1820 | 1820 | |
| 1821 | 1821 | if (!$changelater) {
|
| 1822 | - $url = $urlwithroot . '/'; |
|
| 1822 | + $url = $urlwithroot.'/'; |
|
| 1823 | 1823 | |
| 1824 | - $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived") . ".\n";
|
|
| 1825 | - $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs") . " :\n\n";
|
|
| 1826 | - $mesg .= $outputlangs->transnoentitiesnoconv("Login") . " = " . $this->login . "\n";
|
|
| 1827 | - $mesg .= $outputlangs->transnoentitiesnoconv("Password") . " = " . $password . "\n\n";
|
|
| 1824 | + $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived").".\n";
|
|
| 1825 | + $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyIs")." :\n\n";
|
|
| 1826 | + $mesg .= $outputlangs->transnoentitiesnoconv("Login")." = ".$this->login."\n";
|
|
| 1827 | + $mesg .= $outputlangs->transnoentitiesnoconv("Password")." = ".$password."\n\n";
|
|
| 1828 | 1828 | $mesg .= "\n"; |
| 1829 | 1829 | |
| 1830 | - $mesg .= $outputlangs->transnoentitiesnoconv("ClickHereToGoTo", $appli) . ': ' . $url . "\n\n";
|
|
| 1830 | + $mesg .= $outputlangs->transnoentitiesnoconv("ClickHereToGoTo", $appli).': '.$url."\n\n";
|
|
| 1831 | 1831 | $mesg .= "--\n"; |
| 1832 | 1832 | $mesg .= $user->getFullName($outputlangs); // Username that make then sending |
| 1833 | 1833 | |
| 1834 | - DolUtils::dol_syslog(get_class($this) . "::send_password changelater is off, url=" . $url); |
|
| 1834 | + DolUtils::dol_syslog(get_class($this)."::send_password changelater is off, url=".$url); |
|
| 1835 | 1835 | } else {
|
| 1836 | - $url = $urlwithroot . '/user/passwordforgotten.php?action=validatenewpassword&username=' . $this->login . "&passwordhash=" . dol_hash($password); |
|
| 1836 | + $url = $urlwithroot.'/user/passwordforgotten.php?action=validatenewpassword&username='.$this->login."&passwordhash=".dol_hash($password); |
|
| 1837 | 1837 | |
| 1838 | - $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived") . "\n";
|
|
| 1839 | - $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyWillBe") . " :\n\n";
|
|
| 1840 | - $mesg .= $outputlangs->transnoentitiesnoconv("Login") . " = " . $this->login . "\n";
|
|
| 1841 | - $mesg .= $outputlangs->transnoentitiesnoconv("Password") . " = " . $password . "\n\n";
|
|
| 1838 | + $mesg .= $outputlangs->transnoentitiesnoconv("RequestToResetPasswordReceived")."\n";
|
|
| 1839 | + $mesg .= $outputlangs->transnoentitiesnoconv("NewKeyWillBe")." :\n\n";
|
|
| 1840 | + $mesg .= $outputlangs->transnoentitiesnoconv("Login")." = ".$this->login."\n";
|
|
| 1841 | + $mesg .= $outputlangs->transnoentitiesnoconv("Password")." = ".$password."\n\n";
|
|
| 1842 | 1842 | $mesg .= "\n"; |
| 1843 | - $mesg .= $outputlangs->transnoentitiesnoconv("YouMustClickToChange") . " :\n";
|
|
| 1844 | - $mesg .= $url . "\n\n"; |
|
| 1845 | - $mesg .= $outputlangs->transnoentitiesnoconv("ForgetIfNothing") . "\n\n";
|
|
| 1843 | + $mesg .= $outputlangs->transnoentitiesnoconv("YouMustClickToChange")." :\n";
|
|
| 1844 | + $mesg .= $url."\n\n"; |
|
| 1845 | + $mesg .= $outputlangs->transnoentitiesnoconv("ForgetIfNothing")."\n\n";
|
|
| 1846 | 1846 | |
| 1847 | - DolUtils::dol_syslog(get_class($this) . "::send_password changelater is on, url=" . $url); |
|
| 1847 | + DolUtils::dol_syslog(get_class($this)."::send_password changelater is on, url=".$url); |
|
| 1848 | 1848 | } |
| 1849 | 1849 | |
| 1850 | 1850 | $mailfile = new CMailFile( |
@@ -1855,7 +1855,7 @@ discard block |
||
| 1855 | 1855 | return 1; |
| 1856 | 1856 | } else {
|
| 1857 | 1857 | $langs->trans("errors");
|
| 1858 | - $this->error = $langs->trans("ErrorFailedToSendPassword") . ' ' . $mailfile->error;
|
|
| 1858 | + $this->error = $langs->trans("ErrorFailedToSendPassword").' '.$mailfile->error;
|
|
| 1859 | 1859 | return -1; |
| 1860 | 1860 | } |
| 1861 | 1861 | } |
@@ -1880,8 +1880,8 @@ discard block |
||
| 1880 | 1880 | {
|
| 1881 | 1881 | // phpcs:enable |
| 1882 | 1882 | $sql = "SELECT url, login, pass, poste "; |
| 1883 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user_clicktodial as u"; |
|
| 1884 | - $sql .= " WHERE u.fk_user = " . $this->id; |
|
| 1883 | + $sql .= " FROM ".MAIN_DB_PREFIX."user_clicktodial as u"; |
|
| 1884 | + $sql .= " WHERE u.fk_user = ".$this->id; |
|
| 1885 | 1885 | |
| 1886 | 1886 | $resql = Config::$dbEngine->query($sql); |
| 1887 | 1887 | if ($resql) {
|
@@ -1915,21 +1915,21 @@ discard block |
||
| 1915 | 1915 | // phpcs:enable |
| 1916 | 1916 | Config::$dbEngine->begin(); |
| 1917 | 1917 | |
| 1918 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_clicktodial"; |
|
| 1919 | - $sql .= " WHERE fk_user = " . $this->id; |
|
| 1918 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."user_clicktodial"; |
|
| 1919 | + $sql .= " WHERE fk_user = ".$this->id; |
|
| 1920 | 1920 | |
| 1921 | - DolUtils::dol_syslog(get_class($this) . '::update_clicktodial', LOG_DEBUG); |
|
| 1921 | + DolUtils::dol_syslog(get_class($this).'::update_clicktodial', LOG_DEBUG); |
|
| 1922 | 1922 | $result = Config::$dbEngine->query($sql); |
| 1923 | 1923 | |
| 1924 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_clicktodial"; |
|
| 1924 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."user_clicktodial"; |
|
| 1925 | 1925 | $sql .= " (fk_user,url,login,pass,poste)"; |
| 1926 | - $sql .= " VALUES (" . $this->id;
|
|
| 1927 | - $sql .= ", '" . Config::$dbEngine->escape($this->clicktodial_url) . "'"; |
|
| 1928 | - $sql .= ", '" . Config::$dbEngine->escape($this->clicktodial_login) . "'"; |
|
| 1929 | - $sql .= ", '" . Config::$dbEngine->escape($this->clicktodial_password) . "'"; |
|
| 1930 | - $sql .= ", '" . Config::$dbEngine->escape($this->clicktodial_poste) . "')"; |
|
| 1926 | + $sql .= " VALUES (".$this->id;
|
|
| 1927 | + $sql .= ", '".Config::$dbEngine->escape($this->clicktodial_url)."'"; |
|
| 1928 | + $sql .= ", '".Config::$dbEngine->escape($this->clicktodial_login)."'"; |
|
| 1929 | + $sql .= ", '".Config::$dbEngine->escape($this->clicktodial_password)."'"; |
|
| 1930 | + $sql .= ", '".Config::$dbEngine->escape($this->clicktodial_poste)."')"; |
|
| 1931 | 1931 | |
| 1932 | - DolUtils::dol_syslog(get_class($this) . '::update_clicktodial', LOG_DEBUG); |
|
| 1932 | + DolUtils::dol_syslog(get_class($this).'::update_clicktodial', LOG_DEBUG); |
|
| 1933 | 1933 | $result = Config::$dbEngine->query($sql); |
| 1934 | 1934 | if ($result) {
|
| 1935 | 1935 | Config::$dbEngine->commit(); |
@@ -1959,20 +1959,20 @@ discard block |
||
| 1959 | 1959 | |
| 1960 | 1960 | Config::$dbEngine->begin(); |
| 1961 | 1961 | |
| 1962 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "usergroup_user"; |
|
| 1963 | - $sql .= " WHERE fk_user = " . $this->id; |
|
| 1964 | - $sql .= " AND fk_usergroup = " . $group; |
|
| 1965 | - $sql .= " AND entity = " . $entity; |
|
| 1962 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; |
|
| 1963 | + $sql .= " WHERE fk_user = ".$this->id; |
|
| 1964 | + $sql .= " AND fk_usergroup = ".$group; |
|
| 1965 | + $sql .= " AND entity = ".$entity; |
|
| 1966 | 1966 | |
| 1967 | 1967 | $result = Config::$dbEngine->query($sql); |
| 1968 | 1968 | |
| 1969 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "usergroup_user (entity, fk_user, fk_usergroup)"; |
|
| 1970 | - $sql .= " VALUES (" . $entity . "," . $this->id . "," . $group . ")";
|
|
| 1969 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."usergroup_user (entity, fk_user, fk_usergroup)"; |
|
| 1970 | + $sql .= " VALUES (".$entity.",".$this->id.",".$group.")";
|
|
| 1971 | 1971 | |
| 1972 | 1972 | $result = Config::$dbEngine->query($sql); |
| 1973 | 1973 | if ($result) {
|
| 1974 | 1974 | if (!$error && !$notrigger) {
|
| 1975 | - $this->newgroupid = $group; // deprecated. Remove this. |
|
| 1975 | + $this->newgroupid = $group; // deprecated. Remove this. |
|
| 1976 | 1976 | $this->context = array('audit' => $langs->trans("UserSetInGroup"), 'newgroupid' => $group);
|
| 1977 | 1977 | |
| 1978 | 1978 | // Call trigger |
@@ -1987,7 +1987,7 @@ discard block |
||
| 1987 | 1987 | Config::$dbEngine->commit(); |
| 1988 | 1988 | return 1; |
| 1989 | 1989 | } else {
|
| 1990 | - DolUtils::dol_syslog(get_class($this) . "::SetInGroup " . $this->error, LOG_ERR); |
|
| 1990 | + DolUtils::dol_syslog(get_class($this)."::SetInGroup ".$this->error, LOG_ERR); |
|
| 1991 | 1991 | Config::$dbEngine->rollback(); |
| 1992 | 1992 | return -2; |
| 1993 | 1993 | } |
@@ -2016,15 +2016,15 @@ discard block |
||
| 2016 | 2016 | |
| 2017 | 2017 | Config::$dbEngine->begin(); |
| 2018 | 2018 | |
| 2019 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "usergroup_user"; |
|
| 2020 | - $sql .= " WHERE fk_user = " . $this->id; |
|
| 2021 | - $sql .= " AND fk_usergroup = " . $group; |
|
| 2022 | - $sql .= " AND entity = " . $entity; |
|
| 2019 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."usergroup_user"; |
|
| 2020 | + $sql .= " WHERE fk_user = ".$this->id; |
|
| 2021 | + $sql .= " AND fk_usergroup = ".$group; |
|
| 2022 | + $sql .= " AND entity = ".$entity; |
|
| 2023 | 2023 | |
| 2024 | 2024 | $result = Config::$dbEngine->query($sql); |
| 2025 | 2025 | if ($result) {
|
| 2026 | 2026 | if (!$error && !$notrigger) {
|
| 2027 | - $this->oldgroupid = $group; // deprecated. Remove this. |
|
| 2027 | + $this->oldgroupid = $group; // deprecated. Remove this. |
|
| 2028 | 2028 | $this->context = array('audit' => $langs->trans("UserRemovedFromGroup"), 'oldgroupid' => $group);
|
| 2029 | 2029 | |
| 2030 | 2030 | // Call trigger |
@@ -2040,7 +2040,7 @@ discard block |
||
| 2040 | 2040 | return 1; |
| 2041 | 2041 | } else {
|
| 2042 | 2042 | $this->error = $interface->error; |
| 2043 | - DolUtils::dol_syslog(get_class($this) . "::RemoveFromGroup " . $this->error, LOG_ERR); |
|
| 2043 | + DolUtils::dol_syslog(get_class($this)."::RemoveFromGroup ".$this->error, LOG_ERR); |
|
| 2044 | 2044 | Config::$dbEngine->rollback(); |
| 2045 | 2045 | return -2; |
| 2046 | 2046 | } |
@@ -2064,7 +2064,7 @@ discard block |
||
| 2064 | 2064 | function getPhotoUrl($width, $height, $cssclass = '', $imagesize = '') |
| 2065 | 2065 | {
|
| 2066 | 2066 | // $result = '<a href="' . DOL_URL_ROOT . '/user/card.php?id=' . $this->id . '">'; |
| 2067 | - $result = '<a href="' . BASE_URI . '?controller=user&method=card&id=' . $this->id . '">'; |
|
| 2067 | + $result = '<a href="'.BASE_URI.'?controller=user&method=card&id='.$this->id.'">'; |
|
| 2068 | 2068 | $result .= Form::showphoto('userphoto', $this, $width, $height, 0, $cssclass, $imagesize);
|
| 2069 | 2069 | $result .= '</a>'; |
| 2070 | 2070 | |
@@ -2114,49 +2114,49 @@ discard block |
||
| 2114 | 2114 | |
| 2115 | 2115 | // Info Login |
| 2116 | 2116 | $label .= '<div class="centpercent">'; |
| 2117 | - $label .= '<u>' . $langs->trans("User") . '</u><br>';
|
|
| 2118 | - $label .= '<b>' . $langs->trans('Name') . ':</b> ' . $this->getFullName($langs, '');
|
|
| 2117 | + $label .= '<u>'.$langs->trans("User").'</u><br>';
|
|
| 2118 | + $label .= '<b>'.$langs->trans('Name').':</b> '.$this->getFullName($langs, '');
|
|
| 2119 | 2119 | if (!empty($this->login)) {
|
| 2120 | - $label .= '<br><b>' . $langs->trans('Login') . ':</b> ' . $this->login;
|
|
| 2120 | + $label .= '<br><b>'.$langs->trans('Login').':</b> '.$this->login;
|
|
| 2121 | 2121 | } |
| 2122 | - $label .= '<br><b>' . $langs->trans("EMail") . ':</b> ' . $this->email;
|
|
| 2122 | + $label .= '<br><b>'.$langs->trans("EMail").':</b> '.$this->email;
|
|
| 2123 | 2123 | if (!empty($this->admin)) {
|
| 2124 | - $label .= '<br><b>' . $langs->trans("Administrator") . '</b>: ' . yn($this->admin);
|
|
| 2124 | + $label .= '<br><b>'.$langs->trans("Administrator").'</b>: '.yn($this->admin);
|
|
| 2125 | 2125 | } |
| 2126 | 2126 | if (!empty($this->socid)) { // Add thirdparty for external users
|
| 2127 | 2127 | $thirdpartystatic = new Societe($db); |
| 2128 | 2128 | $thirdpartystatic->fetch($this->socid); |
| 2129 | 2129 | if (empty($hidethirdpartylogo)) {
|
| 2130 | - $companylink = ' ' . $thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company |
|
| 2130 | + $companylink = ' '.$thirdpartystatic->getNomUrl(2, (($option == 'nolink') ? 'nolink' : '')); // picto only of company |
|
| 2131 | 2131 | } |
| 2132 | - $company = ' (' . $langs->trans("Company") . ': ' . $thirdpartystatic->name . ')';
|
|
| 2132 | + $company = ' ('.$langs->trans("Company").': '.$thirdpartystatic->name.')';
|
|
| 2133 | 2133 | } |
| 2134 | - $type = ($this->socid ? $langs->trans("External") . $company : $langs->trans("Internal"));
|
|
| 2135 | - $label .= '<br><b>' . $langs->trans("Type") . ':</b> ' . $type;
|
|
| 2136 | - $label .= '<br><b>' . $langs->trans("Status") . '</b>: ' . $this->getLibStatut(0);
|
|
| 2134 | + $type = ($this->socid ? $langs->trans("External").$company : $langs->trans("Internal"));
|
|
| 2135 | + $label .= '<br><b>'.$langs->trans("Type").':</b> '.$type;
|
|
| 2136 | + $label .= '<br><b>'.$langs->trans("Status").'</b>: '.$this->getLibStatut(0);
|
|
| 2137 | 2137 | $label .= '</div>'; |
| 2138 | 2138 | if ($infologin > 0) {
|
| 2139 | 2139 | $label .= '<br>'; |
| 2140 | - $label .= '<br><u>' . $langs->trans("Connection") . '</u>';
|
|
| 2141 | - $label .= '<br><b>' . $langs->trans("IPAddress") . '</b>: ' . $_SERVER["REMOTE_ADDR"];
|
|
| 2140 | + $label .= '<br><u>'.$langs->trans("Connection").'</u>';
|
|
| 2141 | + $label .= '<br><b>'.$langs->trans("IPAddress").'</b>: '.$_SERVER["REMOTE_ADDR"];
|
|
| 2142 | 2142 | if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) {
|
| 2143 | - $label .= '<br><b>' . $langs->trans("ConnectedOnMultiCompany") . ':</b> ' . Globals::$conf->entity . ' (user entity ' . $this->entity . ')';
|
|
| 2143 | + $label .= '<br><b>'.$langs->trans("ConnectedOnMultiCompany").':</b> '.Globals::$conf->entity.' (user entity '.$this->entity.')';
|
|
| 2144 | 2144 | } |
| 2145 | - $label .= '<br><b>' . $langs->trans("AuthenticationMode") . ':</b> ' . $_SESSION["dol_authmode"] . (empty($dolibarr_main_demo) ? '' : ' (demo)');
|
|
| 2146 | - $label .= '<br><b>' . $langs->trans("ConnectedSince") . ':</b> ' . dol_print_date($this->datelastlogin, "dayhour", 'tzuser');
|
|
| 2147 | - $label .= '<br><b>' . $langs->trans("PreviousConnexion") . ':</b> ' . dol_print_date($this->datepreviouslogin, "dayhour", 'tzuser');
|
|
| 2148 | - $label .= '<br><b>' . $langs->trans("CurrentTheme") . ':</b> ' . Globals::$conf->theme;
|
|
| 2149 | - $label .= '<br><b>' . $langs->trans("CurrentMenuManager") . ':</b> ' . $menumanager->name;
|
|
| 2145 | + $label .= '<br><b>'.$langs->trans("AuthenticationMode").':</b> '.$_SESSION["dol_authmode"].(empty($dolibarr_main_demo) ? '' : ' (demo)');
|
|
| 2146 | + $label .= '<br><b>'.$langs->trans("ConnectedSince").':</b> '.dol_print_date($this->datelastlogin, "dayhour", 'tzuser');
|
|
| 2147 | + $label .= '<br><b>'.$langs->trans("PreviousConnexion").':</b> '.dol_print_date($this->datepreviouslogin, "dayhour", 'tzuser');
|
|
| 2148 | + $label .= '<br><b>'.$langs->trans("CurrentTheme").':</b> '.Globals::$conf->theme;
|
|
| 2149 | + $label .= '<br><b>'.$langs->trans("CurrentMenuManager").':</b> '.$menumanager->name;
|
|
| 2150 | 2150 | $s = picto_from_langcode($langs->getDefaultLang()); |
| 2151 | - $label .= '<br><b>' . $langs->trans("CurrentUserLanguage") . ':</b> ' . ($s ? $s . ' ' : '') . $langs->getDefaultLang();
|
|
| 2152 | - $label .= '<br><b>' . $langs->trans("Browser") . ':</b> ' . Globals::$conf->browser->name . ($conf->browser->version ? ' ' . Globals::$conf->browser->version : '') . ' (' . $_SERVER['HTTP_USER_AGENT'] . ')';
|
|
| 2153 | - $label .= '<br><b>' . $langs->trans("Layout") . ':</b> ' . Globals::$conf->browser->layout;
|
|
| 2154 | - $label .= '<br><b>' . $langs->trans("Screen") . ':</b> ' . $_SESSION['dol_screenwidth'] . ' x ' . $_SESSION['dol_screenheight'];
|
|
| 2151 | + $label .= '<br><b>'.$langs->trans("CurrentUserLanguage").':</b> '.($s ? $s.' ' : '').$langs->getDefaultLang();
|
|
| 2152 | + $label .= '<br><b>'.$langs->trans("Browser").':</b> '.Globals::$conf->browser->name.($conf->browser->version ? ' '.Globals::$conf->browser->version : '').' ('.$_SERVER['HTTP_USER_AGENT'].')';
|
|
| 2153 | + $label .= '<br><b>'.$langs->trans("Layout").':</b> '.Globals::$conf->browser->layout;
|
|
| 2154 | + $label .= '<br><b>'.$langs->trans("Screen").':</b> '.$_SESSION['dol_screenwidth'].' x '.$_SESSION['dol_screenheight'];
|
|
| 2155 | 2155 | if ($conf->browser->layout == 'phone') {
|
| 2156 | - $label .= '<br><b>' . $langs->trans("Phone") . ':</b> ' . $langs->trans("Yes");
|
|
| 2156 | + $label .= '<br><b>'.$langs->trans("Phone").':</b> '.$langs->trans("Yes");
|
|
| 2157 | 2157 | } |
| 2158 | 2158 | if (!empty($_SESSION["disablemodules"])) {
|
| 2159 | - $label .= '<br><b>' . $langs->trans("DisabledModules") . ':</b> <br>' . join(', ', explode(',', $_SESSION["disablemodules"]));
|
|
| 2159 | + $label .= '<br><b>'.$langs->trans("DisabledModules").':</b> <br>'.join(', ', explode(',', $_SESSION["disablemodules"]));
|
|
| 2160 | 2160 | } |
| 2161 | 2161 | } |
| 2162 | 2162 | if ($infologin < 0) {
|
@@ -2164,10 +2164,10 @@ discard block |
||
| 2164 | 2164 | } |
| 2165 | 2165 | |
| 2166 | 2166 | // $url = DOL_URL_ROOT . '/user/card.php?id=' . $this->id; |
| 2167 | - $url = BASE_URI . '?controller=user&method=card&id=' . $this->id; |
|
| 2167 | + $url = BASE_URI.'?controller=user&method=card&id='.$this->id; |
|
| 2168 | 2168 | if ($option == 'leave') {
|
| 2169 | 2169 | //$url = DOL_URL_ROOT . '/holiday/list.php?id=' . $this->id; |
| 2170 | - $url = BASE_URI . '?controller=holiday&method=list&id=' . $this->id; |
|
| 2170 | + $url = BASE_URI.'?controller=holiday&method=list&id='.$this->id; |
|
| 2171 | 2171 | } |
| 2172 | 2172 | if ($option != 'nolink') {
|
| 2173 | 2173 | // Add param to save lastsearch_values or not |
@@ -2180,16 +2180,16 @@ discard block |
||
| 2180 | 2180 | } |
| 2181 | 2181 | } |
| 2182 | 2182 | |
| 2183 | - $linkstart = '<a href="' . $url . '"'; |
|
| 2183 | + $linkstart = '<a href="'.$url.'"'; |
|
| 2184 | 2184 | $linkclose = ""; |
| 2185 | 2185 | if (empty($notooltip)) {
|
| 2186 | 2186 | if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
|
| 2187 | 2187 | $langs->load("users");
|
| 2188 | 2188 | $label = $langs->trans("ShowUser");
|
| 2189 | - $linkclose .= ' alt="' . dol_escape_htmltag($label, 1) . '"'; |
|
| 2189 | + $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; |
|
| 2190 | 2190 | } |
| 2191 | - $linkclose .= ' title="' . dol_escape_htmltag($label, 1) . '"'; |
|
| 2192 | - $linkclose .= ' class="classfortooltip' . ($morecss ? ' ' . $morecss : '') . '"'; |
|
| 2191 | + $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; |
|
| 2192 | + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; |
|
| 2193 | 2193 | |
| 2194 | 2194 | /* |
| 2195 | 2195 | $hookmanager->initHooks(array('userdao'));
|
@@ -2199,7 +2199,7 @@ discard block |
||
| 2199 | 2199 | */ |
| 2200 | 2200 | } |
| 2201 | 2201 | |
| 2202 | - $linkstart .= $linkclose . '>'; |
|
| 2202 | + $linkstart .= $linkclose.'>'; |
|
| 2203 | 2203 | $linkend = '</a>'; |
| 2204 | 2204 | |
| 2205 | 2205 | //if ($withpictoimg == -1) $result.='<div class="nowrap">'; |
@@ -2211,15 +2211,15 @@ discard block |
||
| 2211 | 2211 | } |
| 2212 | 2212 | // Only picto |
| 2213 | 2213 | if ($withpictoimg > 0) {
|
| 2214 | - $picto = '<!-- picto user --><div class="inline-block nopadding userimg' . ($morecss ? ' ' . $morecss : '') . '">' . img_object('', 'user', $paddafterimage . ' ' . ($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1) . '</div>';
|
|
| 2214 | + $picto = '<!-- picto user --><div class="inline-block nopadding userimg'.($morecss ? ' '.$morecss : '').'">'.img_object('', 'user', $paddafterimage.' '.($notooltip ? '' : 'class="classfortooltip"'), 0, 0, $notooltip ? 0 : 1).'</div>';
|
|
| 2215 | 2215 | } else { // Picto must be a photo
|
| 2216 | - $picto = '<!-- picto photo user --><div class="inline-block nopadding userimg' . ($morecss ? ' ' . $morecss : '') . '"' . ($paddafterimage ? ' ' . $paddafterimage : '') . '>' . Form::showphoto('userphoto', $this, 0, 0, 0, 'userphoto' . ($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1) . '</div>';
|
|
| 2216 | + $picto = '<!-- picto photo user --><div class="inline-block nopadding userimg'.($morecss ? ' '.$morecss : '').'"'.($paddafterimage ? ' '.$paddafterimage : '').'>'.Form::showphoto('userphoto', $this, 0, 0, 0, 'userphoto'.($withpictoimg == -3 ? 'small' : ''), 'mini', 0, 1).'</div>';
|
|
| 2217 | 2217 | } |
| 2218 | 2218 | $result .= $picto; |
| 2219 | 2219 | } |
| 2220 | 2220 | if ($withpictoimg > -2 && $withpictoimg != 2) {
|
| 2221 | 2221 | if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
|
| 2222 | - $result .= '<div class="inline-block nopadding valignmiddle usertext' . ((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled') . ($morecss ? ' ' . $morecss : '') . '">'; |
|
| 2222 | + $result .= '<div class="inline-block nopadding valignmiddle usertext'.((!isset($this->statut) || $this->statut) ? '' : ' strikefordisabled').($morecss ? ' '.$morecss : '').'">'; |
|
| 2223 | 2223 | } |
| 2224 | 2224 | if ($mode == 'login') {
|
| 2225 | 2225 | $result .= dol_trunc($this->login, $maxlen); |
@@ -2237,7 +2237,7 @@ discard block |
||
| 2237 | 2237 | global $action; |
| 2238 | 2238 | $hookmanager->initHooks(array('userdao'));
|
| 2239 | 2239 | $parameters = array('id' => $this->id, 'getnomurl' => $result);
|
| 2240 | - $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 2240 | + $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 2241 | 2241 | if ($reshook > 0) {
|
| 2242 | 2242 | $result = $hookmanager->resPrint; |
| 2243 | 2243 | } else {
|
@@ -2261,7 +2261,7 @@ discard block |
||
| 2261 | 2261 | $result = ''; |
| 2262 | 2262 | |
| 2263 | 2263 | // $linkstart = '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$this->id.'">'; |
| 2264 | - $linkstart = '<a href="' . BASE_URI . '?controller=user&method=card&id=' . $this->id . '">'; |
|
| 2264 | + $linkstart = '<a href="'.BASE_URI.'?controller=user&method=card&id='.$this->id.'">'; |
|
| 2265 | 2265 | $linkend = '</a>'; |
| 2266 | 2266 | |
| 2267 | 2267 | //Check user's rights to see an other user |
@@ -2271,7 +2271,7 @@ discard block |
||
| 2271 | 2271 | |
| 2272 | 2272 | if ($option == 'xxx') {
|
| 2273 | 2273 | //$linkstart = '<a href="'.DOL_URL_ROOT.'/user/card.php?id='.$this->id.'">'; |
| 2274 | - $linkstart = '<a href="' . BASE_URI . '?controller=user&method=card.php&id=' . $this->id . '">'; |
|
| 2274 | + $linkstart = '<a href="'.BASE_URI.'?controller=user&method=card.php&id='.$this->id.'">'; |
|
| 2275 | 2275 | $linkend = '</a>'; |
| 2276 | 2276 | } |
| 2277 | 2277 | |
@@ -2328,9 +2328,9 @@ discard block |
||
| 2328 | 2328 | } |
| 2329 | 2329 | } elseif ($mode == 2) {
|
| 2330 | 2330 | if ($statut == 1) {
|
| 2331 | - return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans('Enabled');
|
|
| 2331 | + return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
|
|
| 2332 | 2332 | } elseif ($statut == 0) {
|
| 2333 | - return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans('Disabled');
|
|
| 2333 | + return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
|
|
| 2334 | 2334 | } |
| 2335 | 2335 | } elseif ($mode == 3) {
|
| 2336 | 2336 | if ($statut == 1) {
|
@@ -2340,15 +2340,15 @@ discard block |
||
| 2340 | 2340 | } |
| 2341 | 2341 | } elseif ($mode == 4) {
|
| 2342 | 2342 | if ($statut == 1) {
|
| 2343 | - return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"') . ' ' . $langs->trans('Enabled');
|
|
| 2343 | + return img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"').' '.$langs->trans('Enabled');
|
|
| 2344 | 2344 | } elseif ($statut == 0) {
|
| 2345 | - return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"') . ' ' . $langs->trans('Disabled');
|
|
| 2345 | + return img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"').' '.$langs->trans('Disabled');
|
|
| 2346 | 2346 | } |
| 2347 | 2347 | } elseif ($mode == 5) {
|
| 2348 | 2348 | if ($statut == 1) {
|
| 2349 | - return $langs->trans('Enabled') . ' ' . img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"');
|
|
| 2349 | + return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4', 'class="pictostatus"');
|
|
| 2350 | 2350 | } elseif ($statut == 0) {
|
| 2351 | - return $langs->trans('Disabled') . ' ' . img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"');
|
|
| 2351 | + return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5', 'class="pictostatus"');
|
|
| 2352 | 2352 | } |
| 2353 | 2353 | } |
| 2354 | 2354 | } |
@@ -2369,11 +2369,11 @@ discard block |
||
| 2369 | 2369 | global $conf; |
| 2370 | 2370 | $dn = ''; |
| 2371 | 2371 | if ($mode == 0) {
|
| 2372 | - $dn = Globals::$conf->global->LDAP_KEY_USERS . "=" . $info[$conf->global->LDAP_KEY_USERS] . "," . Globals::$conf->global->LDAP_USER_DN; |
|
| 2372 | + $dn = Globals::$conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS].",".Globals::$conf->global->LDAP_USER_DN; |
|
| 2373 | 2373 | } elseif ($mode == 1) {
|
| 2374 | 2374 | $dn = Globals::$conf->global->LDAP_USER_DN; |
| 2375 | 2375 | } elseif ($mode == 2) {
|
| 2376 | - $dn = Globals::$conf->global->LDAP_KEY_USERS . "=" . $info[$conf->global->LDAP_KEY_USERS]; |
|
| 2376 | + $dn = Globals::$conf->global->LDAP_KEY_USERS."=".$info[$conf->global->LDAP_KEY_USERS]; |
|
| 2377 | 2377 | } |
| 2378 | 2378 | return $dn; |
| 2379 | 2379 | } |
@@ -2571,8 +2571,8 @@ discard block |
||
| 2571 | 2571 | {
|
| 2572 | 2572 | $sql = "SELECT u.rowid, u.login as ref, u.datec,"; |
| 2573 | 2573 | $sql .= " u.tms as date_modification, u.entity"; |
| 2574 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
|
| 2575 | - $sql .= " WHERE u.rowid = " . $id; |
|
| 2574 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
| 2575 | + $sql .= " WHERE u.rowid = ".$id; |
|
| 2576 | 2576 | |
| 2577 | 2577 | $result = Config::$dbEngine->query($sql); |
| 2578 | 2578 | if ($result) {
|
@@ -2601,9 +2601,9 @@ discard block |
||
| 2601 | 2601 | function getNbOfEMailings() |
| 2602 | 2602 | {
|
| 2603 | 2603 | $sql = "SELECT count(mc.email) as nb"; |
| 2604 | - $sql .= " FROM " . MAIN_DB_PREFIX . "mailing_cibles as mc"; |
|
| 2605 | - $sql .= " WHERE mc.email = '" . Config::$dbEngine->escape($this->email) . "'"; |
|
| 2606 | - $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes |
|
| 2604 | + $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc"; |
|
| 2605 | + $sql .= " WHERE mc.email = '".Config::$dbEngine->escape($this->email)."'"; |
|
| 2606 | + $sql .= " AND mc.statut NOT IN (-1,0)"; // -1 erreur, 0 non envoye, 1 envoye avec succes |
|
| 2607 | 2607 | |
| 2608 | 2608 | $resql = Config::$dbEngine->query($sql); |
| 2609 | 2609 | if ($resql) {
|
@@ -2631,19 +2631,19 @@ discard block |
||
| 2631 | 2631 | global $conf; |
| 2632 | 2632 | |
| 2633 | 2633 | $sql = "SELECT count(rowid) as nb"; |
| 2634 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user"; |
|
| 2634 | + $sql .= " FROM ".MAIN_DB_PREFIX."user"; |
|
| 2635 | 2635 | if ($option == 'superadmin') {
|
| 2636 | 2636 | $sql .= " WHERE entity = 0"; |
| 2637 | 2637 | if ($admin >= 0) {
|
| 2638 | - $sql .= " AND admin = " . $admin; |
|
| 2638 | + $sql .= " AND admin = ".$admin; |
|
| 2639 | 2639 | } |
| 2640 | 2640 | } else {
|
| 2641 | - $sql .= " WHERE entity IN (" . getEntity('user', 0) . ")";
|
|
| 2641 | + $sql .= " WHERE entity IN (".getEntity('user', 0).")";
|
|
| 2642 | 2642 | if ($limitTo == 'active') {
|
| 2643 | 2643 | $sql .= " AND statut = 1"; |
| 2644 | 2644 | } |
| 2645 | 2645 | if ($admin >= 0) {
|
| 2646 | - $sql .= " AND admin = " . $admin; |
|
| 2646 | + $sql .= " AND admin = ".$admin; |
|
| 2647 | 2647 | } |
| 2648 | 2648 | } |
| 2649 | 2649 | |
@@ -2694,7 +2694,7 @@ discard block |
||
| 2694 | 2694 | |
| 2695 | 2695 | $result = $this->update($user); |
| 2696 | 2696 | |
| 2697 | - DolUtils::dol_syslog(get_class($this) . "::update_ldap2dolibarr result=" . $result, LOG_DEBUG); |
|
| 2697 | + DolUtils::dol_syslog(get_class($this)."::update_ldap2dolibarr result=".$result, LOG_DEBUG); |
|
| 2698 | 2698 | |
| 2699 | 2699 | return $result; |
| 2700 | 2700 | } |
@@ -2709,10 +2709,10 @@ discard block |
||
| 2709 | 2709 | function get_children() |
| 2710 | 2710 | {
|
| 2711 | 2711 | // phpcs:enable |
| 2712 | - $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "user"; |
|
| 2713 | - $sql .= " WHERE fk_user = " . $this->id; |
|
| 2712 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."user"; |
|
| 2713 | + $sql .= " WHERE fk_user = ".$this->id; |
|
| 2714 | 2714 | |
| 2715 | - DolUtils::dol_syslog(get_class($this) . "::get_children result=" . $result, LOG_DEBUG); |
|
| 2715 | + DolUtils::dol_syslog(get_class($this)."::get_children result=".$result, LOG_DEBUG); |
|
| 2716 | 2716 | $res = Config::$dbEngine->query($sql); |
| 2717 | 2717 | if ($res) {
|
| 2718 | 2718 | $users = array(); |
@@ -2741,11 +2741,11 @@ discard block |
||
| 2741 | 2741 | |
| 2742 | 2742 | // Load array[child]=parent |
| 2743 | 2743 | $sql = "SELECT fk_user as id_parent, rowid as id_son"; |
| 2744 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user"; |
|
| 2744 | + $sql .= " FROM ".MAIN_DB_PREFIX."user"; |
|
| 2745 | 2745 | $sql .= " WHERE fk_user <> 0"; |
| 2746 | - $sql .= " AND entity IN (" . getEntity('user') . ")";
|
|
| 2746 | + $sql .= " AND entity IN (".getEntity('user').")";
|
|
| 2747 | 2747 | |
| 2748 | - DolUtils::dol_syslog(get_class($this) . "::loadParentOf", LOG_DEBUG); |
|
| 2748 | + DolUtils::dol_syslog(get_class($this)."::loadParentOf", LOG_DEBUG); |
|
| 2749 | 2749 | $resql = Config::$dbEngine->query($sql); |
| 2750 | 2750 | if ($resql) {
|
| 2751 | 2751 | while ($obj = Config::$dbEngine->fetch_object($resql)) {
|
@@ -2788,20 +2788,20 @@ discard block |
||
| 2788 | 2788 | |
| 2789 | 2789 | // Init $this->users array |
| 2790 | 2790 | $sql = "SELECT DISTINCT u.rowid, u.firstname, u.lastname, u.fk_user, u.fk_soc, u.login, u.email, u.gender, u.admin, u.statut, u.photo, u.entity"; // Distinct reduce pb with old tables with duplicates |
| 2791 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
|
| 2791 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
| 2792 | 2792 | // Add fields from hooks |
| 2793 | 2793 | $parameters = array(); |
| 2794 | - $reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
|
| 2794 | + $reshook = $hookmanager->executeHooks('printUserListWhere', $parameters); // Note that $action and $object may have been modified by hook
|
|
| 2795 | 2795 | if ($reshook > 0) {
|
| 2796 | 2796 | $sql .= $hookmanager->resPrint; |
| 2797 | 2797 | } else {
|
| 2798 | - $sql .= " WHERE u.entity IN (" . getEntity('user') . ")";
|
|
| 2798 | + $sql .= " WHERE u.entity IN (".getEntity('user').")";
|
|
| 2799 | 2799 | } |
| 2800 | 2800 | if ($filter) {
|
| 2801 | - $sql .= " AND " . $filter; |
|
| 2801 | + $sql .= " AND ".$filter; |
|
| 2802 | 2802 | } |
| 2803 | 2803 | |
| 2804 | - DolUtils::dol_syslog(get_class($this) . "::get_full_tree get user list", LOG_DEBUG); |
|
| 2804 | + DolUtils::dol_syslog(get_class($this)."::get_full_tree get user list", LOG_DEBUG); |
|
| 2805 | 2805 | $resql = Config::$dbEngine->query($sql); |
| 2806 | 2806 | if ($resql) {
|
| 2807 | 2807 | $i = 0; |
@@ -2827,7 +2827,7 @@ discard block |
||
| 2827 | 2827 | } |
| 2828 | 2828 | |
| 2829 | 2829 | // We add the fullpath property to each elements of first level (no parent exists) |
| 2830 | - DolUtils::dol_syslog(get_class($this) . "::get_full_tree call to build_path_from_id_user", LOG_DEBUG); |
|
| 2830 | + DolUtils::dol_syslog(get_class($this)."::get_full_tree call to build_path_from_id_user", LOG_DEBUG); |
|
| 2831 | 2831 | foreach ($this->users as $key => $val) {
|
| 2832 | 2832 | $result = $this->build_path_from_id_user($key, 0); // Process a branch from the root user key (this user has no parent) |
| 2833 | 2833 | if ($result < 0) {
|
@@ -2839,18 +2839,18 @@ discard block |
||
| 2839 | 2839 | // Exclude leaf including $deleteafterid from tree |
| 2840 | 2840 | if ($deleteafterid) {
|
| 2841 | 2841 | //print "Look to discard user ".$deleteafterid."\n"; |
| 2842 | - $keyfilter1 = '^' . $deleteafterid . '$'; |
|
| 2843 | - $keyfilter2 = '_' . $deleteafterid . '$'; |
|
| 2844 | - $keyfilter3 = '^' . $deleteafterid . '_'; |
|
| 2845 | - $keyfilter4 = '_' . $deleteafterid . '_'; |
|
| 2842 | + $keyfilter1 = '^'.$deleteafterid.'$'; |
|
| 2843 | + $keyfilter2 = '_'.$deleteafterid.'$'; |
|
| 2844 | + $keyfilter3 = '^'.$deleteafterid.'_'; |
|
| 2845 | + $keyfilter4 = '_'.$deleteafterid.'_'; |
|
| 2846 | 2846 | foreach ($this->users as $key => $val) {
|
| 2847 | - if (preg_match('/' . $keyfilter1 . '/', $val['fullpath']) || preg_match('/' . $keyfilter2 . '/', $val['fullpath']) || preg_match('/' . $keyfilter3 . '/', $val['fullpath']) || preg_match('/' . $keyfilter4 . '/', $val['fullpath'])) {
|
|
| 2847 | + if (preg_match('/'.$keyfilter1.'/', $val['fullpath']) || preg_match('/'.$keyfilter2.'/', $val['fullpath']) || preg_match('/'.$keyfilter3.'/', $val['fullpath']) || preg_match('/'.$keyfilter4.'/', $val['fullpath'])) {
|
|
| 2848 | 2848 | unset($this->users[$key]); |
| 2849 | 2849 | } |
| 2850 | 2850 | } |
| 2851 | 2851 | } |
| 2852 | 2852 | |
| 2853 | - DolUtils::dol_syslog(get_class($this) . "::get_full_tree dol_sort_array", LOG_DEBUG); |
|
| 2853 | + DolUtils::dol_syslog(get_class($this)."::get_full_tree dol_sort_array", LOG_DEBUG); |
|
| 2854 | 2854 | $this->users = dol_sort_array($this->users, 'fullname', 'asc', true, false); |
| 2855 | 2855 | |
| 2856 | 2856 | //var_dump($this->users); |
@@ -2878,10 +2878,10 @@ discard block |
||
| 2878 | 2878 | |
| 2879 | 2879 | $idtoscan = $this->id; |
| 2880 | 2880 | |
| 2881 | - DolUtils::dol_syslog("Build childid for id = " . $idtoscan);
|
|
| 2881 | + DolUtils::dol_syslog("Build childid for id = ".$idtoscan);
|
|
| 2882 | 2882 | foreach ($this->users as $id => $val) {
|
| 2883 | 2883 | //var_dump($val['fullpath']); |
| 2884 | - if (preg_match('/_' . $idtoscan . '_/', $val['fullpath'])) {
|
|
| 2884 | + if (preg_match('/_'.$idtoscan.'_/', $val['fullpath'])) {
|
|
| 2885 | 2885 | $childids[$val['id']] = $val['id']; |
| 2886 | 2886 | } |
| 2887 | 2887 | } |
@@ -2907,16 +2907,16 @@ discard block |
||
| 2907 | 2907 | function build_path_from_id_user($id_user, $protection = 0) |
| 2908 | 2908 | {
|
| 2909 | 2909 | // phpcs:enable |
| 2910 | - DolUtils::dol_syslog(get_class($this) . "::build_path_from_id_user id_user=" . $id_user . " protection=" . $protection, LOG_DEBUG); |
|
| 2910 | + DolUtils::dol_syslog(get_class($this)."::build_path_from_id_user id_user=".$id_user." protection=".$protection, LOG_DEBUG); |
|
| 2911 | 2911 | |
| 2912 | 2912 | if (!empty($this->users[$id_user]['fullpath'])) {
|
| 2913 | 2913 | // Already defined |
| 2914 | - DolUtils::dol_syslog(get_class($this) . "::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING); |
|
| 2914 | + DolUtils::dol_syslog(get_class($this)."::build_path_from_id_user fullpath and fullname already defined", LOG_WARNING); |
|
| 2915 | 2915 | return 0; |
| 2916 | 2916 | } |
| 2917 | 2917 | |
| 2918 | 2918 | // Define fullpath and fullname |
| 2919 | - $this->users[$id_user]['fullpath'] = '_' . $id_user; |
|
| 2919 | + $this->users[$id_user]['fullpath'] = '_'.$id_user; |
|
| 2920 | 2920 | $this->users[$id_user]['fullname'] = $this->users[$id_user]['lastname']; |
| 2921 | 2921 | $i = 0; |
| 2922 | 2922 | $cursor_user = $id_user; |
@@ -2925,11 +2925,11 @@ discard block |
||
| 2925 | 2925 | while (!empty($this->parentof[$cursor_user])) {
|
| 2926 | 2926 | if (in_array($this->parentof[$cursor_user], $useridfound)) {
|
| 2927 | 2927 | DolUtils::dol_syslog("The hierarchy of user has a recursive loop", LOG_WARNING);
|
| 2928 | - return -1; // Should not happen. Protection against looping hierarchy |
|
| 2928 | + return -1; // Should not happen. Protection against looping hierarchy |
|
| 2929 | 2929 | } |
| 2930 | 2930 | $useridfound[] = $this->parentof[$cursor_user]; |
| 2931 | - $this->users[$id_user]['fullpath'] = '_' . $this->parentof[$cursor_user] . $this->users[$id_user]['fullpath']; |
|
| 2932 | - $this->users[$id_user]['fullname'] = $this->users[$this->parentof[$cursor_user]]['lastname'] . ' >> ' . $this->users[$id_user]['fullname']; |
|
| 2931 | + $this->users[$id_user]['fullpath'] = '_'.$this->parentof[$cursor_user].$this->users[$id_user]['fullpath']; |
|
| 2932 | + $this->users[$id_user]['fullname'] = $this->users[$this->parentof[$cursor_user]]['lastname'].' >> '.$this->users[$id_user]['fullname']; |
|
| 2933 | 2933 | $i++; |
| 2934 | 2934 | $cursor_user = $this->parentof[$cursor_user]; |
| 2935 | 2935 | } |
@@ -2971,10 +2971,10 @@ discard block |
||
| 2971 | 2971 | $this->nb = array(); |
| 2972 | 2972 | |
| 2973 | 2973 | $sql = "SELECT count(u.rowid) as nb"; |
| 2974 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
|
| 2974 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
| 2975 | 2975 | $sql .= " WHERE u.statut > 0"; |
| 2976 | 2976 | //$sql.= " AND employee != 0"; |
| 2977 | - $sql .= " AND u.entity IN (" . getEntity('user') . ")";
|
|
| 2977 | + $sql .= " AND u.entity IN (".getEntity('user').")";
|
|
| 2978 | 2978 | |
| 2979 | 2979 | $resql = Config::$dbEngine->query($sql); |
| 2980 | 2980 | if ($resql) {
|
@@ -3039,8 +3039,8 @@ discard block |
||
| 3039 | 3039 | } |
| 3040 | 3040 | |
| 3041 | 3041 | $sql = "SELECT rowid, email, user_mobile, civility, lastname, firstname"; |
| 3042 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user"; |
|
| 3043 | - $sql .= " WHERE rowid = '" . $rowid . "'"; |
|
| 3042 | + $sql .= " FROM ".MAIN_DB_PREFIX."user"; |
|
| 3043 | + $sql .= " WHERE rowid = '".$rowid."'"; |
|
| 3044 | 3044 | |
| 3045 | 3045 | $resql = Config::$dbEngine->query($sql); |
| 3046 | 3046 | if ($resql) {
|
@@ -3050,7 +3050,7 @@ discard block |
||
| 3050 | 3050 | $obj = Config::$dbEngine->fetch_object($resql); |
| 3051 | 3051 | |
| 3052 | 3052 | if ($mode == 'email') {
|
| 3053 | - $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">"; |
|
| 3053 | + $user_property = dolGetFirstLastname($obj->firstname, $obj->lastname)." <".$obj->email.">"; |
|
| 3054 | 3054 | } else if ($mode == 'mobile') {
|
| 3055 | 3055 | $user_property = $obj->user_mobile; |
| 3056 | 3056 | } |
@@ -3077,7 +3077,7 @@ discard block |
||
| 3077 | 3077 | global $conf; |
| 3078 | 3078 | |
| 3079 | 3079 | $sql = "SELECT t.rowid"; |
| 3080 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t '; |
|
| 3080 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t '; |
|
| 3081 | 3081 | $sql .= " WHERE 1"; |
| 3082 | 3082 | |
| 3083 | 3083 | // Manage filter |
@@ -3085,25 +3085,25 @@ discard block |
||
| 3085 | 3085 | if (!empty($filter)) {
|
| 3086 | 3086 | foreach ($filter as $key => $value) {
|
| 3087 | 3087 | if ($key == 't.rowid') {
|
| 3088 | - $sqlwhere[] = $key . '=' . $value; |
|
| 3088 | + $sqlwhere[] = $key.'='.$value; |
|
| 3089 | 3089 | } elseif (strpos($key, 'date') !== false) {
|
| 3090 | - $sqlwhere[] = $key . ' = \'' . Config::$dbEngine->idate($value) . '\''; |
|
| 3090 | + $sqlwhere[] = $key.' = \''.Config::$dbEngine->idate($value).'\''; |
|
| 3091 | 3091 | } elseif ($key == 'customsql') {
|
| 3092 | 3092 | $sqlwhere[] = $value; |
| 3093 | 3093 | } else {
|
| 3094 | - $sqlwhere[] = $key . ' LIKE \'%' . Config::$dbEngine->escape($value) . '%\''; |
|
| 3094 | + $sqlwhere[] = $key.' LIKE \'%'.Config::$dbEngine->escape($value).'%\''; |
|
| 3095 | 3095 | } |
| 3096 | 3096 | } |
| 3097 | 3097 | } |
| 3098 | 3098 | if (count($sqlwhere) > 0) {
|
| 3099 | - $sql .= ' AND (' . implode(' ' . $filtermode . ' ', $sqlwhere) . ')';
|
|
| 3099 | + $sql .= ' AND ('.implode(' '.$filtermode.' ', $sqlwhere).')';
|
|
| 3100 | 3100 | } |
| 3101 | 3101 | $sql .= Config::$dbEngine->order($sortfield, $sortorder); |
| 3102 | 3102 | if ($limit) {
|
| 3103 | 3103 | $sql .= Config::$dbEngine->plimit($limit + 1, $offset); |
| 3104 | 3104 | } |
| 3105 | 3105 | |
| 3106 | - DolUtils::dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); |
|
| 3106 | + DolUtils::dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); |
|
| 3107 | 3107 | |
| 3108 | 3108 | $resql = Config::$dbEngine->query($sql); |
| 3109 | 3109 | if ($resql) {
|
@@ -520,16 +520,17 @@ discard block |
||
| 520 | 520 | $nid = $obj->id; |
| 521 | 521 | |
| 522 | 522 | $sql = "DELETE FROM " . MAIN_DB_PREFIX . "user_rights WHERE fk_user = " . $this->id . " AND fk_id=" . $nid . " AND entity = " . $entity; |
| 523 | - if (!Config::$dbEngine->query($sql)) |
|
| 524 | - $error++; |
|
| 523 | + if (!Config::$dbEngine->query($sql)) { |
|
| 524 | + $error++; |
|
| 525 | + } |
|
| 525 | 526 | $sql = "INSERT INTO " . MAIN_DB_PREFIX . "user_rights (entity, fk_user, fk_id) VALUES (" . $entity . ", " . $this->id . ", " . $nid . ")";
|
| 526 | - if (!Config::$dbEngine->query($sql)) |
|
| 527 | - $error++; |
|
| 527 | + if (!Config::$dbEngine->query($sql)) { |
|
| 528 | + $error++; |
|
| 529 | + } |
|
| 528 | 530 | |
| 529 | 531 | $i++; |
| 530 | 532 | } |
| 531 | - } |
|
| 532 | - else {
|
|
| 533 | + } else {
|
|
| 533 | 534 | $error++; |
| 534 | 535 | dol_print_error(Config::$dbEngine); |
| 535 | 536 | } |
@@ -2226,8 +2227,9 @@ discard block |
||
| 2226 | 2227 | } else {
|
| 2227 | 2228 | $result .= $this->getFullName($langs, '', ($mode == 'firstname' ? 2 : -1), $maxlen); |
| 2228 | 2229 | } |
| 2229 | - if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
| 2230 | - $result .= '</div>'; |
|
| 2230 | + if (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
|
| 2231 | + $result .= '</div>'; |
|
| 2232 | + } |
|
| 2231 | 2233 | } |
| 2232 | 2234 | $result .= (($option == 'nolink') ? '' : $linkend); |
| 2233 | 2235 | //if ($withpictoimg == -1) $result.='</div>'; |
@@ -131,7 +131,7 @@ |
||
| 131 | 131 | */ |
| 132 | 132 | function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arrayofjs = '', $arrayofcss = '', $disablejmobile = 0, $disablenofollow = 0) |
| 133 | 133 | { |
| 134 | - $this->top_httphead(); // TODO: Null method! |
|
| 134 | + $this->top_httphead(); // TODO: Null method! |
|
| 135 | 135 | // TODO: Nothing to do? |
| 136 | 136 | return; |
| 137 | 137 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | public $titre; |
| 84 | 84 | //public Globals::$langs; |
| 85 | 85 | public $level; |
| 86 | - public $leftmenu; //<! Not used |
|
| 86 | + public $leftmenu; //<! Not used |
|
| 87 | 87 | public $perms; |
| 88 | 88 | public $enabled; |
| 89 | 89 | //public $user; |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $this->type = trim($this->type); |
| 118 | 118 | $this->mainmenu = trim($this->mainmenu); |
| 119 | 119 | $this->leftmenu = trim($this->leftmenu); |
| 120 | - $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined |
|
| 120 | + $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined |
|
| 121 | 121 | $this->fk_mainmenu = trim($this->fk_mainmenu); |
| 122 | 122 | $this->fk_leftmenu = trim($this->fk_leftmenu); |
| 123 | 123 | $this->position = (int) $this->position; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | // may use an already used value because its internal cursor does not increase when we do |
| 145 | 145 | // an insert with a forced id. |
| 146 | 146 | if (in_array(Globals::$db->type, array('pgsql'))) {
|
| 147 | - $sql = "SELECT MAX(rowid) as maxrowid FROM " . MAIN_DB_PREFIX . "menu"; |
|
| 147 | + $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu"; |
|
| 148 | 148 | $resqlrowid = Globals::$db->query($sql); |
| 149 | 149 | if ($resqlrowid) {
|
| 150 | 150 | $obj = Globals::$db->fetch_object($resqlrowid); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $maxrowid = 1; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - $sql = "SELECT setval('" . MAIN_DB_PREFIX . "menu_rowid_seq', " . ($maxrowid) . ")";
|
|
| 158 | + $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")";
|
|
| 159 | 159 | //print $sql; exit; |
| 160 | 160 | $resqlrowidset = Globals::$db->query($sql); |
| 161 | 161 | if (!$resqlrowidset) {
|
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql |
| 170 | 170 | $sql = "SELECT count(*)"; |
| 171 | - $sql .= " FROM " . MAIN_DB_PREFIX . "menu"; |
|
| 172 | - $sql .= " WHERE menu_handler = '" . Globals::$db->escape($this->menu_handler) . "'"; |
|
| 173 | - $sql .= " AND fk_menu = " . ((int) $this->fk_menu); |
|
| 174 | - $sql .= " AND position = " . ((int) $this->position); |
|
| 175 | - $sql .= " AND url = '" . Globals::$db->escape($this->url) . "'"; |
|
| 176 | - $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 171 | + $sql .= " FROM ".MAIN_DB_PREFIX."menu"; |
|
| 172 | + $sql .= " WHERE menu_handler = '".Globals::$db->escape($this->menu_handler)."'"; |
|
| 173 | + $sql .= " AND fk_menu = ".((int) $this->fk_menu); |
|
| 174 | + $sql .= " AND position = ".((int) $this->position); |
|
| 175 | + $sql .= " AND url = '".Globals::$db->escape($this->url)."'"; |
|
| 176 | + $sql .= " AND entity = ".Globals::$conf->entity; |
|
| 177 | 177 | |
| 178 | 178 | $result = Globals::$db->query($sql); |
| 179 | 179 | if ($result) {
|
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | |
| 182 | 182 | if ($row[0] == 0) { // If not found
|
| 183 | 183 | // Insert request |
| 184 | - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "menu(";
|
|
| 184 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu(";
|
|
| 185 | 185 | $sql .= "menu_handler,"; |
| 186 | 186 | $sql .= "entity,"; |
| 187 | 187 | $sql .= "module,"; |
@@ -200,38 +200,38 @@ discard block |
||
| 200 | 200 | $sql .= "enabled,"; |
| 201 | 201 | $sql .= "usertype"; |
| 202 | 202 | $sql .= ") VALUES (";
|
| 203 | - $sql .= " '" . Globals::$db->escape($this->menu_handler) . "',"; |
|
| 204 | - $sql .= " '" . Globals::$db->escape($conf->entity) . "',"; |
|
| 205 | - $sql .= " '" . Globals::$db->escape($this->module) . "',"; |
|
| 206 | - $sql .= " '" . Globals::$db->escape($this->type) . "',"; |
|
| 207 | - $sql .= " " . ($this->mainmenu ? "'" . Globals::$db->escape($this->mainmenu) . "'" : "''") . ","; // Can't be null |
|
| 208 | - $sql .= " " . ($this->leftmenu ? "'" . Globals::$db->escape($this->leftmenu) . "'" : "null") . ","; |
|
| 209 | - $sql .= " " . ((int) $this->fk_menu) . ","; |
|
| 210 | - $sql .= " " . ($this->fk_mainmenu ? "'" . Globals::$db->escape($this->fk_mainmenu) . "'" : "null") . ","; |
|
| 211 | - $sql .= " " . ($this->fk_leftmenu ? "'" . Globals::$db->escape($this->fk_leftmenu) . "'" : "null") . ","; |
|
| 212 | - $sql .= " " . ((int) $this->position) . ","; |
|
| 213 | - $sql .= " '" . Globals::$db->escape($this->url) . "',"; |
|
| 214 | - $sql .= " '" . Globals::$db->escape($this->target) . "',"; |
|
| 215 | - $sql .= " '" . Globals::$db->escape($this->titre) . "',"; |
|
| 216 | - $sql .= " '" . Globals::$db->escape($this->langs) . "',"; |
|
| 217 | - $sql .= " '" . Globals::$db->escape($this->perms) . "',"; |
|
| 218 | - $sql .= " '" . Globals::$db->escape($this->enabled) . "',"; |
|
| 219 | - $sql .= " '" . Globals::$db->escape($this->user) . "'"; |
|
| 203 | + $sql .= " '".Globals::$db->escape($this->menu_handler)."',"; |
|
| 204 | + $sql .= " '".Globals::$db->escape($conf->entity)."',"; |
|
| 205 | + $sql .= " '".Globals::$db->escape($this->module)."',"; |
|
| 206 | + $sql .= " '".Globals::$db->escape($this->type)."',"; |
|
| 207 | + $sql .= " ".($this->mainmenu ? "'".Globals::$db->escape($this->mainmenu)."'" : "''").","; // Can't be null |
|
| 208 | + $sql .= " ".($this->leftmenu ? "'".Globals::$db->escape($this->leftmenu)."'" : "null").","; |
|
| 209 | + $sql .= " ".((int) $this->fk_menu).","; |
|
| 210 | + $sql .= " ".($this->fk_mainmenu ? "'".Globals::$db->escape($this->fk_mainmenu)."'" : "null").","; |
|
| 211 | + $sql .= " ".($this->fk_leftmenu ? "'".Globals::$db->escape($this->fk_leftmenu)."'" : "null").","; |
|
| 212 | + $sql .= " ".((int) $this->position).","; |
|
| 213 | + $sql .= " '".Globals::$db->escape($this->url)."',"; |
|
| 214 | + $sql .= " '".Globals::$db->escape($this->target)."',"; |
|
| 215 | + $sql .= " '".Globals::$db->escape($this->titre)."',"; |
|
| 216 | + $sql .= " '".Globals::$db->escape($this->langs)."',"; |
|
| 217 | + $sql .= " '".Globals::$db->escape($this->perms)."',"; |
|
| 218 | + $sql .= " '".Globals::$db->escape($this->enabled)."',"; |
|
| 219 | + $sql .= " '".Globals::$db->escape($this->user)."'"; |
|
| 220 | 220 | $sql .= ")"; |
| 221 | 221 | |
| 222 | - DolUtils::dol_syslog(get_class($this) . "::create", LOG_DEBUG); |
|
| 222 | + DolUtils::dol_syslog(get_class($this)."::create", LOG_DEBUG); |
|
| 223 | 223 | $resql = Globals::$db->query($sql); |
| 224 | 224 | if ($resql) {
|
| 225 | - $this->id = Globals::$db->last_insert_id(MAIN_DB_PREFIX . "menu"); |
|
| 226 | - DolUtils::dol_syslog(get_class($this) . "::create record added has rowid=" . $this->id, LOG_DEBUG); |
|
| 225 | + $this->id = Globals::$db->last_insert_id(MAIN_DB_PREFIX."menu"); |
|
| 226 | + DolUtils::dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG); |
|
| 227 | 227 | |
| 228 | 228 | return $this->id; |
| 229 | 229 | } else {
|
| 230 | - $this->error = "Error " . Globals::$db->lasterror(); |
|
| 230 | + $this->error = "Error ".Globals::$db->lasterror(); |
|
| 231 | 231 | return -1; |
| 232 | 232 | } |
| 233 | 233 | } else {
|
| 234 | - DolUtils::dol_syslog(get_class($this) . "::create menu entry already exists", LOG_WARNING); |
|
| 234 | + DolUtils::dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING); |
|
| 235 | 235 | $this->error = 'Error Menu entry already exists'; |
| 236 | 236 | return 0; |
| 237 | 237 | } |
@@ -272,29 +272,29 @@ discard block |
||
| 272 | 272 | // Check parameters |
| 273 | 273 | // Put here code to add control on parameters values |
| 274 | 274 | // Update request |
| 275 | - $sql = "UPDATE " . MAIN_DB_PREFIX . "menu SET"; |
|
| 276 | - $sql .= " menu_handler='" . Globals::$db->escape($this->menu_handler) . "',"; |
|
| 277 | - $sql .= " module='" . Globals::$db->escape($this->module) . "',"; |
|
| 278 | - $sql .= " type='" . Globals::$db->escape($this->type) . "',"; |
|
| 279 | - $sql .= " mainmenu='" . Globals::$db->escape($this->mainmenu) . "',"; |
|
| 280 | - $sql .= " leftmenu='" . Globals::$db->escape($this->leftmenu) . "',"; |
|
| 281 | - $sql .= " fk_menu=" . $this->fk_menu . ","; |
|
| 282 | - $sql .= " fk_mainmenu=" . ($this->fk_mainmenu ? "'" . Globals::$db->escape($this->fk_mainmenu) . "'" : "null") . ","; |
|
| 283 | - $sql .= " fk_leftmenu=" . ($this->fk_leftmenu ? "'" . Globals::$db->escape($this->fk_leftmenu) . "'" : "null") . ","; |
|
| 284 | - $sql .= " position=" . ($this->position > 0 ? $this->position : 0) . ","; |
|
| 285 | - $sql .= " url='" . Globals::$db->escape($this->url) . "',"; |
|
| 286 | - $sql .= " target='" . Globals::$db->escape($this->target) . "',"; |
|
| 287 | - $sql .= " titre='" . Globals::$db->escape($this->titre) . "',"; |
|
| 288 | - $sql .= " langs='" . Globals::$db->escape($this->langs) . "',"; |
|
| 289 | - $sql .= " perms='" . Globals::$db->escape($this->perms) . "',"; |
|
| 290 | - $sql .= " enabled='" . Globals::$db->escape($this->enabled) . "',"; |
|
| 291 | - $sql .= " usertype='" . Globals::$db->escape($this->user) . "'"; |
|
| 292 | - $sql .= " WHERE rowid=" . $this->id; |
|
| 293 | - |
|
| 294 | - DolUtils::dol_syslog(get_class($this) . "::update", LOG_DEBUG); |
|
| 275 | + $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET"; |
|
| 276 | + $sql .= " menu_handler='".Globals::$db->escape($this->menu_handler)."',"; |
|
| 277 | + $sql .= " module='".Globals::$db->escape($this->module)."',"; |
|
| 278 | + $sql .= " type='".Globals::$db->escape($this->type)."',"; |
|
| 279 | + $sql .= " mainmenu='".Globals::$db->escape($this->mainmenu)."',"; |
|
| 280 | + $sql .= " leftmenu='".Globals::$db->escape($this->leftmenu)."',"; |
|
| 281 | + $sql .= " fk_menu=".$this->fk_menu.","; |
|
| 282 | + $sql .= " fk_mainmenu=".($this->fk_mainmenu ? "'".Globals::$db->escape($this->fk_mainmenu)."'" : "null").","; |
|
| 283 | + $sql .= " fk_leftmenu=".($this->fk_leftmenu ? "'".Globals::$db->escape($this->fk_leftmenu)."'" : "null").","; |
|
| 284 | + $sql .= " position=".($this->position > 0 ? $this->position : 0).","; |
|
| 285 | + $sql .= " url='".Globals::$db->escape($this->url)."',"; |
|
| 286 | + $sql .= " target='".Globals::$db->escape($this->target)."',"; |
|
| 287 | + $sql .= " titre='".Globals::$db->escape($this->titre)."',"; |
|
| 288 | + $sql .= " langs='".Globals::$db->escape($this->langs)."',"; |
|
| 289 | + $sql .= " perms='".Globals::$db->escape($this->perms)."',"; |
|
| 290 | + $sql .= " enabled='".Globals::$db->escape($this->enabled)."',"; |
|
| 291 | + $sql .= " usertype='".Globals::$db->escape($this->user)."'"; |
|
| 292 | + $sql .= " WHERE rowid=".$this->id; |
|
| 293 | + |
|
| 294 | + DolUtils::dol_syslog(get_class($this)."::update", LOG_DEBUG); |
|
| 295 | 295 | $resql = Globals::$db->query($sql); |
| 296 | 296 | if (!$resql) {
|
| 297 | - $this->error = "Error " . Globals::$db->lasterror(); |
|
| 297 | + $this->error = "Error ".Globals::$db->lasterror(); |
|
| 298 | 298 | return -1; |
| 299 | 299 | } |
| 300 | 300 | |
@@ -332,10 +332,10 @@ discard block |
||
| 332 | 332 | $sql .= " t.enabled,"; |
| 333 | 333 | $sql .= " t.usertype as user,"; |
| 334 | 334 | $sql .= " t.tms"; |
| 335 | - $sql .= " FROM " . MAIN_DB_PREFIX . "menu as t"; |
|
| 336 | - $sql .= " WHERE t.rowid = " . $id; |
|
| 335 | + $sql .= " FROM ".MAIN_DB_PREFIX."menu as t"; |
|
| 336 | + $sql .= " WHERE t.rowid = ".$id; |
|
| 337 | 337 | |
| 338 | - DolUtils::dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); |
|
| 338 | + DolUtils::dol_syslog(get_class($this)."::fetch", LOG_DEBUG); |
|
| 339 | 339 | $resql = Globals::$db->query($sql); |
| 340 | 340 | if ($resql) {
|
| 341 | 341 | if (Globals::$db->num_rows($resql)) {
|
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | return 1; |
| 368 | 368 | } else {
|
| 369 | - $this->error = "Error " . Globals::$db->lasterror(); |
|
| 369 | + $this->error = "Error ".Globals::$db->lasterror(); |
|
| 370 | 370 | return -1; |
| 371 | 371 | } |
| 372 | 372 | } |
@@ -381,13 +381,13 @@ discard block |
||
| 381 | 381 | {
|
| 382 | 382 | // global $conf, Globals::$langs; |
| 383 | 383 | |
| 384 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "menu"; |
|
| 385 | - $sql .= " WHERE rowid=" . $this->id; |
|
| 384 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu"; |
|
| 385 | + $sql .= " WHERE rowid=".$this->id; |
|
| 386 | 386 | |
| 387 | - DolUtils::dol_syslog(get_class($this) . "::delete", LOG_DEBUG); |
|
| 387 | + DolUtils::dol_syslog(get_class($this)."::delete", LOG_DEBUG); |
|
| 388 | 388 | $resql = Globals::$db->query($sql); |
| 389 | 389 | if (!$resql) {
|
| 390 | - $this->error = "Error " . Globals::$db->lasterror(); |
|
| 390 | + $this->error = "Error ".Globals::$db->lasterror(); |
|
| 391 | 391 | return -1; |
| 392 | 392 | } |
| 393 | 393 | |
@@ -438,8 +438,8 @@ discard block |
||
| 438 | 438 | // global Globals::$langs, $user, $conf; // To export to DolUtils::dol_eval function |
| 439 | 439 | // global $mainmenu, $leftmenu; // To export to DolUtils::dol_eval function |
| 440 | 440 | |
| 441 | - $mainmenu = $mymainmenu; // To export to DolUtils::dol_eval function |
|
| 442 | - $leftmenu = $myleftmenu; // To export to DolUtils::dol_eval function |
|
| 441 | + $mainmenu = $mymainmenu; // To export to DolUtils::dol_eval function |
|
| 442 | + $leftmenu = $myleftmenu; // To export to DolUtils::dol_eval function |
|
| 443 | 443 | |
| 444 | 444 | $newTabMenu = array(); |
| 445 | 445 | foreach ($tabMenu as $val) {
|
@@ -468,8 +468,8 @@ discard block |
||
| 468 | 468 | //global Globals::$langs, $user, $conf; // To export to DolUtils::dol_eval function |
| 469 | 469 | // global $mainmenu, $leftmenu; // To export to DolUtils::dol_eval function |
| 470 | 470 | |
| 471 | - $mainmenu = $mymainmenu; // To export to DolUtils::dol_eval function |
|
| 472 | - $leftmenu = $myleftmenu; // To export to DolUtils::dol_eval function |
|
| 471 | + $mainmenu = $mymainmenu; // To export to DolUtils::dol_eval function |
|
| 472 | + $leftmenu = $myleftmenu; // To export to DolUtils::dol_eval function |
|
| 473 | 473 | // Detect what is top mainmenu id |
| 474 | 474 | $menutopid = ''; |
| 475 | 475 | foreach ($tabMenu as $key => $val) {
|
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | if ($found) {
|
| 525 | 525 | $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']); |
| 526 | 526 | } else {
|
| 527 | - DolUtils::dol_syslog("Error. Modules " . $val['module'] . " has defined a menu entry with a parent='fk_mainmenu=" . $val['fk_leftmenu'] . ",fk_leftmenu=" . $val['fk_leftmenu'] . "' and position=" . $val['position'] . '. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING);
|
|
| 527 | + DolUtils::dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING);
|
|
| 528 | 528 | //print "Parent menu not found !!<br>"; |
| 529 | 529 | } |
| 530 | 530 | } |
@@ -550,13 +550,13 @@ discard block |
||
| 550 | 550 | //global $mainmenu, $leftmenu; // To export to DolUtils::dol_eval function |
| 551 | 551 | |
| 552 | 552 | $menutopid = 0; |
| 553 | - $mainmenu = $mymainmenu; // To export to DolUtils::dol_eval function |
|
| 554 | - $leftmenu = $myleftmenu; // To export to DolUtils::dol_eval function |
|
| 553 | + $mainmenu = $mymainmenu; // To export to DolUtils::dol_eval function |
|
| 554 | + $leftmenu = $myleftmenu; // To export to DolUtils::dol_eval function |
|
| 555 | 555 | |
| 556 | 556 | $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position"; |
| 557 | - $sql .= " FROM " . MAIN_DB_PREFIX . "menu as m"; |
|
| 558 | - $sql .= " WHERE m.entity IN (0," . Globals::$conf->entity . ")"; |
|
| 559 | - $sql .= " AND m.menu_handler IN ('" . $menu_handler . "','all')";
|
|
| 557 | + $sql .= " FROM ".MAIN_DB_PREFIX."menu as m"; |
|
| 558 | + $sql .= " WHERE m.entity IN (0,".Globals::$conf->entity.")"; |
|
| 559 | + $sql .= " AND m.menu_handler IN ('".$menu_handler."','all')";
|
|
| 560 | 560 | if ($type_user == 0) {
|
| 561 | 561 | $sql .= " AND m.usertype IN (0,2)"; |
| 562 | 562 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | //print $sql; |
| 568 | 568 | //$tmp1=microtime(true); |
| 569 | 569 | //print '>>> 1 0<br>'; |
| 570 | - DolUtils::dol_syslog(get_class($this) . "::menuLoad mymainmenu=" . $mymainmenu . " myleftmenu=" . $myleftmenu . " type_user=" . $type_user . " menu_handler=" . $menu_handler . " tabMenu size=" . count($tabMenu) . "", LOG_DEBUG); |
|
| 570 | + DolUtils::dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG); |
|
| 571 | 571 | $resql = Config::$dbEngine->select($sql); |
| 572 | 572 | if (is_array($resql)) {
|
| 573 | 573 | $a = 0; |
@@ -600,7 +600,7 @@ discard block |
||
| 600 | 600 | |
| 601 | 601 | // Define $title |
| 602 | 602 | if ($enabled) {
|
| 603 | - $title = Globals::$langs->trans($menu['titre']); // If $menu['titre'] start with $, a DolUtils::dol_eval is done. |
|
| 603 | + $title = Globals::$langs->trans($menu['titre']); // If $menu['titre'] start with $, a DolUtils::dol_eval is done. |
|
| 604 | 604 | //var_dump($title.'-'.$menu['titre']); |
| 605 | 605 | if ($title == $menu['titre']) { // Translation not found
|
| 606 | 606 | if (!empty($menu['langs'])) { // If there is a dedicated translation file
|
@@ -613,7 +613,7 @@ discard block |
||
| 613 | 613 | |
| 614 | 614 | if (preg_match("/\//", $menu['titre'])) { // To manage translation when title is string1/string2
|
| 615 | 615 | $tab_titre = explode("/", $menu['titre']);
|
| 616 | - $title = Globals::$langs->trans($tab_titre[0]) . "/" . Globals::$langs->trans($tab_titre[1]); |
|
| 616 | + $title = Globals::$langs->trans($tab_titre[0])."/".Globals::$langs->trans($tab_titre[1]); |
|
| 617 | 617 | } else if (preg_match('/\|\|/', $menu['titre'])) { // To manage different translation (Title||AltTitle@ConditionForAltTitle)
|
| 618 | 618 | $tab_title = explode("||", $menu['titre']);
|
| 619 | 619 | $alt_title = explode("@", $tab_title[1]);
|
@@ -632,9 +632,9 @@ discard block |
||
| 632 | 632 | $tabMenu[$b]['url'] = $menu['url']; |
| 633 | 633 | if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url'])) {
|
| 634 | 634 | if (preg_match('/\?/', $tabMenu[$b]['url'])) {
|
| 635 | - $tabMenu[$b]['url'] .= '&idmenu=' . $menu['rowid']; |
|
| 635 | + $tabMenu[$b]['url'] .= '&idmenu='.$menu['rowid']; |
|
| 636 | 636 | } else {
|
| 637 | - $tabMenu[$b]['url'] .= '?idmenu=' . $menu['rowid']; |
|
| 637 | + $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid']; |
|
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | $tabMenu[$b]['titre'] = $title; |
@@ -20,7382 +20,7382 @@ |
||
| 20 | 20 | |
| 21 | 21 | abstract class CommonObject |
| 22 | 22 | {
|
| 23 | - /** |
|
| 23 | + /** |
|
| 24 | 24 | * @var int The object identifier |
| 25 | 25 | */ |
| 26 | - public $id; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * @var string Error string |
|
| 30 | - * @see errors |
|
| 31 | - */ |
|
| 32 | - public $error; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var string[] Array of error strings |
|
| 36 | - */ |
|
| 37 | - public $errors=array(); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string ID to identify managed object |
|
| 41 | - */ |
|
| 42 | - public $element; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var string Name of table without prefix where object is stored |
|
| 46 | - */ |
|
| 47 | - public $table_element; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var int Name of subtable line |
|
| 51 | - */ |
|
| 52 | - public $table_element_line=''; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * @var string Key value used to track if data is coming from import wizard |
|
| 56 | - */ |
|
| 57 | - public $import_key; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @var mixed Contains data to manage extrafields |
|
| 61 | - */ |
|
| 62 | - public $array_options=array(); |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
|
| 66 | - */ |
|
| 67 | - public $linkedObjectsIds; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @var mixed Array of linked objects. Loaded by ->fetchObjectLinked |
|
| 71 | - */ |
|
| 72 | - public $linkedObjects; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var Object To store a cloned copy of object before to edit it and keep track of old properties |
|
| 76 | - */ |
|
| 77 | - public $oldcopy; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @var string Column name of the ref field. |
|
| 81 | - */ |
|
| 82 | - protected $table_ref_field = ''; |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @var array<string,mixed> Can be used to pass information when only object is provided to method |
|
| 90 | - */ |
|
| 91 | - public $context=array(); |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @var string Contains canvas name if record is an alternative canvas record |
|
| 95 | - */ |
|
| 96 | - public $canvas; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var Project The related project |
|
| 100 | - * @see fetch_projet() |
|
| 101 | - */ |
|
| 102 | - public $project; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @var int The related project ID |
|
| 106 | - * @see setProject(), project |
|
| 107 | - */ |
|
| 108 | - public $fk_project; |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @deprecated |
|
| 112 | - * @see project |
|
| 113 | - */ |
|
| 114 | - public $projet; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @var Contact a related contact |
|
| 118 | - * @see fetch_contact() |
|
| 119 | - */ |
|
| 120 | - public $contact; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @var int The related contact ID |
|
| 124 | - * @see fetch_contact() |
|
| 125 | - */ |
|
| 126 | - public $contact_id; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @var Societe A related thirdparty |
|
| 130 | - * @see fetch_thirdparty() |
|
| 131 | - */ |
|
| 132 | - public $thirdparty; |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @var User A related user |
|
| 136 | - * @see fetch_user() |
|
| 137 | - */ |
|
| 138 | - public $user; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * @var string The type of originating object ('commande', 'facture', ...)
|
|
| 142 | - * @see fetch_origin() |
|
| 143 | - */ |
|
| 144 | - public $origin; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @var int The id of originating object |
|
| 148 | - * @see fetch_origin() |
|
| 149 | - */ |
|
| 150 | - public $origin_id; |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @var string The object's reference |
|
| 154 | - */ |
|
| 155 | - public $ref; |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * @var string The object's previous reference |
|
| 159 | - */ |
|
| 160 | - public $ref_previous; |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * @var string The object's next reference |
|
| 164 | - */ |
|
| 165 | - public $ref_next; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @var string An external reference for the object |
|
| 169 | - */ |
|
| 170 | - public $ref_ext; |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @var int The object's status |
|
| 174 | - * @see setStatut() |
|
| 175 | - */ |
|
| 176 | - public $statut; |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * @var string |
|
| 180 | - * @see getFullAddress() |
|
| 181 | - */ |
|
| 182 | - public $country; |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @var int |
|
| 186 | - * @see getFullAddress(), country |
|
| 187 | - */ |
|
| 188 | - public $country_id; |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * @var string |
|
| 192 | - * @see getFullAddress(), isInEEC(), country |
|
| 193 | - */ |
|
| 194 | - public $country_code; |
|
| 26 | + public $id; |
|
| 195 | 27 | |
| 196 | 28 | /** |
| 197 | - * @var string |
|
| 198 | - * @see getFullAddress() |
|
| 199 | - */ |
|
| 200 | - public $state; |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * @var int |
|
| 204 | - * @see getFullAddress(), state |
|
| 205 | - */ |
|
| 206 | - public $state_id; |
|
| 29 | + * @var string Error string |
|
| 30 | + * @see errors |
|
| 31 | + */ |
|
| 32 | + public $error; |
|
| 207 | 33 | |
| 208 | - /** |
|
| 209 | - * @var string |
|
| 210 | - * @see getFullAddress(), state |
|
| 211 | - */ |
|
| 212 | - public $state_code; |
|
| 34 | + /** |
|
| 35 | + * @var string[] Array of error strings |
|
| 36 | + */ |
|
| 37 | + public $errors=array(); |
|
| 213 | 38 | |
| 214 | 39 | /** |
| 215 | - * @var string |
|
| 216 | - * @see getFullAddress(), region |
|
| 217 | - */ |
|
| 218 | - public $region; |
|
| 40 | + * @var string ID to identify managed object |
|
| 41 | + */ |
|
| 42 | + public $element; |
|
| 219 | 43 | |
| 220 | - /** |
|
| 221 | - * @var string |
|
| 222 | - * @see getFullAddress(), region |
|
| 223 | - */ |
|
| 224 | - public $region_code; |
|
| 44 | + /** |
|
| 45 | + * @var string Name of table without prefix where object is stored |
|
| 46 | + */ |
|
| 47 | + public $table_element; |
|
| 225 | 48 | |
| 226 | - /** |
|
| 227 | - * @var int |
|
| 228 | - * @see fetch_barcode() |
|
| 229 | - */ |
|
| 230 | - public $barcode_type; |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @var string |
|
| 234 | - * @see fetch_barcode(), barcode_type |
|
| 235 | - */ |
|
| 236 | - public $barcode_type_code; |
|
| 237 | - |
|
| 238 | - /** |
|
| 239 | - * @var string |
|
| 240 | - * @see fetch_barcode(), barcode_type |
|
| 241 | - */ |
|
| 242 | - public $barcode_type_label; |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * @var string |
|
| 246 | - * @see fetch_barcode(), barcode_type |
|
| 247 | - */ |
|
| 248 | - public $barcode_type_coder; |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @var int Payment method ID (cheque, cash, ...) |
|
| 252 | - * @see setPaymentMethods() |
|
| 253 | - */ |
|
| 254 | - public $mode_reglement_id; |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @var int Payment terms ID |
|
| 258 | - * @see setPaymentTerms() |
|
| 259 | - */ |
|
| 260 | - public $cond_reglement_id; |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * @var int Payment terms ID |
|
| 264 | - * @deprecated Kept for compatibility |
|
| 265 | - * @see cond_reglement_id; |
|
| 266 | - */ |
|
| 267 | - public $cond_reglement; |
|
| 268 | - |
|
| 269 | - /** |
|
| 270 | - * @var int Delivery address ID |
|
| 271 | - * @deprecated |
|
| 272 | - * @see setDeliveryAddress() |
|
| 273 | - */ |
|
| 274 | - public $fk_delivery_address; |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * @var int Shipping method ID |
|
| 278 | - * @see setShippingMethod() |
|
| 279 | - */ |
|
| 280 | - public $shipping_method_id; |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * @var string |
|
| 284 | - * @see SetDocModel() |
|
| 285 | - */ |
|
| 286 | - public $modelpdf; |
|
| 287 | - |
|
| 288 | - /** |
|
| 289 | - * @var int Bank account ID |
|
| 290 | - * @see SetBankAccount() |
|
| 291 | - */ |
|
| 292 | - public $fk_account; |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @var string Public note |
|
| 296 | - * @see update_note() |
|
| 297 | - */ |
|
| 298 | - public $note_public; |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @var string Private note |
|
| 302 | - * @see update_note() |
|
| 303 | - */ |
|
| 304 | - public $note_private; |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * @deprecated |
|
| 308 | - * @see note_public |
|
| 309 | - */ |
|
| 310 | - public $note; |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * @var float Total amount before taxes |
|
| 314 | - * @see update_price() |
|
| 315 | - */ |
|
| 316 | - public $total_ht; |
|
| 317 | - |
|
| 318 | - /** |
|
| 319 | - * @var float Total VAT amount |
|
| 320 | - * @see update_price() |
|
| 321 | - */ |
|
| 322 | - public $total_tva; |
|
| 323 | - |
|
| 324 | - /** |
|
| 325 | - * @var float Total local tax 1 amount |
|
| 326 | - * @see update_price() |
|
| 327 | - */ |
|
| 328 | - public $total_localtax1; |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * @var float Total local tax 2 amount |
|
| 332 | - * @see update_price() |
|
| 333 | - */ |
|
| 334 | - public $total_localtax2; |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * @var float Total amount with taxes |
|
| 338 | - * @see update_price() |
|
| 339 | - */ |
|
| 340 | - public $total_ttc; |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @var CommonObjectLine[] |
|
| 344 | - */ |
|
| 345 | - public $lines; |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @var mixed Contains comments |
|
| 349 | - * @see fetchComments() |
|
| 350 | - */ |
|
| 351 | - public $comments=array(); |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * @var int |
|
| 355 | - * @see setIncoterms() |
|
| 356 | - */ |
|
| 357 | - public $fk_incoterms; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * @var string |
|
| 361 | - * @see SetIncoterms() |
|
| 362 | - */ |
|
| 363 | - public $libelle_incoterms; |
|
| 364 | - |
|
| 365 | - /** |
|
| 366 | - * @var string |
|
| 367 | - * @see display_incoterms() |
|
| 368 | - */ |
|
| 369 | - public $location_incoterms; |
|
| 370 | - |
|
| 371 | - public $name; |
|
| 372 | - public $lastname; |
|
| 373 | - public $firstname; |
|
| 374 | - public $civility_id; |
|
| 375 | - |
|
| 376 | - // Dates |
|
| 377 | - public $date_creation; // Date creation |
|
| 378 | - public $date_validation; // Date validation |
|
| 379 | - public $date_modification; // Date last change (tms field) |
|
| 380 | - |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - // No constructor as it is an abstract class |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Check an object id/ref exists |
|
| 387 | - * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch |
|
| 388 | - * |
|
| 389 | - * @param string $element String of element ('product', 'facture', ...)
|
|
| 390 | - * @param int $id Id of object |
|
| 391 | - * @param string $ref Ref of object to check |
|
| 392 | - * @param string $ref_ext Ref ext of object to check |
|
| 393 | - * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
|
| 394 | - */ |
|
| 395 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 396 | - {
|
|
| 397 | - global $db,$conf; |
|
| 398 | - |
|
| 399 | - $sql = "SELECT rowid, ref, ref_ext"; |
|
| 400 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 401 | - $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
|
| 402 | - |
|
| 403 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 404 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 405 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 406 | - else {
|
|
| 407 | - $error='ErrorWrongParameters'; |
|
| 408 | - dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
| 409 | - return -1; |
|
| 410 | - } |
|
| 411 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 412 | - |
|
| 413 | - dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
| 414 | - $resql = $db->query($sql); |
|
| 415 | - if ($resql) |
|
| 416 | - {
|
|
| 417 | - $num=$db->num_rows($resql); |
|
| 418 | - if ($num > 0) return 1; |
|
| 419 | - else return 0; |
|
| 420 | - } |
|
| 421 | - return -1; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Method to output saved errors |
|
| 426 | - * |
|
| 427 | - * @return string String with errors |
|
| 428 | - */ |
|
| 429 | - function errorsToString() |
|
| 430 | - {
|
|
| 431 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):'');
|
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Return full name (civility+' '+name+' '+lastname) |
|
| 436 | - * |
|
| 437 | - * @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
| 438 | - * @param int $option 0=No option, 1=Add civility |
|
| 439 | - * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname |
|
| 440 | - * @param int $maxlen Maximum length |
|
| 441 | - * @return string String with full name |
|
| 442 | - */ |
|
| 443 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 444 | - {
|
|
| 445 | - //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
| 446 | - $lastname=$this->lastname; |
|
| 447 | - $firstname=$this->firstname; |
|
| 448 | - 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:''))))); |
|
| 449 | - |
|
| 450 | - $ret=''; |
|
| 451 | - if ($option && $this->civility_id) |
|
| 452 | - {
|
|
| 453 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 454 | - else $ret.=$this->civility_id.' '; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 458 | - |
|
| 459 | - return dol_trunc($ret,$maxlen); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Return full address of contact |
|
| 464 | - * |
|
| 465 | - * @param int $withcountry 1=Add country into address string |
|
| 466 | - * @param string $sep Separator to use to build string |
|
| 467 | - * @param int $withregion 1=Add region into address string |
|
| 468 | - * @return string Full address string |
|
| 469 | - */ |
|
| 470 | - function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
| 471 | - {
|
|
| 472 | - if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
|
| 473 | - {
|
|
| 474 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 475 | - $tmparray=getCountry($this->country_id,'all'); |
|
| 476 | - $this->country_code=$tmparray['code']; |
|
| 477 | - $this->country =$tmparray['label']; |
|
| 478 | - } |
|
| 49 | + /** |
|
| 50 | + * @var int Name of subtable line |
|
| 51 | + */ |
|
| 52 | + public $table_element_line=''; |
|
| 479 | 53 | |
| 480 | - if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
|
| 481 | - {
|
|
| 482 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 483 | - $tmparray=getState($this->state_id,'all',0,1); |
|
| 484 | - $this->state_code =$tmparray['code']; |
|
| 485 | - $this->state =$tmparray['label']; |
|
| 486 | - $this->region_code =$tmparray['region_code']; |
|
| 487 | - $this->region =$tmparray['region']; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - return dol_format_address($this, $withcountry, $sep); |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - |
|
| 494 | - /** |
|
| 495 | - * Return full address for banner |
|
| 496 | - * |
|
| 497 | - * @param string $htmlkey HTML id to make banner content unique |
|
| 498 | - * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
| 499 | - * @return string Full address string |
|
| 500 | - */ |
|
| 501 | - function getBannerAddress($htmlkey, $object) |
|
| 502 | - {
|
|
| 503 | - global $conf, $langs; |
|
| 504 | - |
|
| 505 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
|
|
| 506 | - |
|
| 507 | - $contactid=0; |
|
| 508 | - $thirdpartyid=0; |
|
| 509 | - if ($this->element == 'societe') |
|
| 510 | - {
|
|
| 511 | - $thirdpartyid=$this->id; |
|
| 512 | - } |
|
| 513 | - if ($this->element == 'contact') |
|
| 514 | - {
|
|
| 515 | - $contactid=$this->id; |
|
| 516 | - $thirdpartyid=$object->fk_soc; |
|
| 517 | - } |
|
| 518 | - if ($this->element == 'user') |
|
| 519 | - {
|
|
| 520 | - $contactid=$this->contact_id; |
|
| 521 | - $thirdpartyid=$object->fk_soc; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $out='<!-- BEGIN part to show address block -->'; |
|
| 525 | - |
|
| 526 | - $outdone=0; |
|
| 527 | - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 528 | - if ($coords) |
|
| 529 | - {
|
|
| 530 | - if (! empty($conf->use_javascript_ajax)) |
|
| 531 | - {
|
|
| 532 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 533 | - // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
| 534 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
|
|
| 535 | - $out.=img_picto($langs->trans("Address"), 'object_address.png');
|
|
| 536 | - $out.='</a> '; |
|
| 537 | - } |
|
| 538 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 539 | - $outdone++; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - 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 |
|
| 543 | - && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
|
| 544 | - {
|
|
| 545 | - if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
|
|
| 546 | - $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
| 547 | - } |
|
| 548 | - else {
|
|
| 549 | - $out.=($outdone?' - ':'').$this->state; |
|
| 550 | - } |
|
| 551 | - $outdone++; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - 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>':''); |
|
| 555 | - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
|
|
| 556 | - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 557 | - } |
|
| 558 | - if (! empty($this->phone_pro)) {
|
|
| 559 | - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 560 | - } |
|
| 561 | - if (! empty($this->phone_mobile)) {
|
|
| 562 | - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++;
|
|
| 563 | - } |
|
| 564 | - if (! empty($this->phone_perso)) {
|
|
| 565 | - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++;
|
|
| 566 | - } |
|
| 567 | - if (! empty($this->office_phone)) {
|
|
| 568 | - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 569 | - } |
|
| 570 | - if (! empty($this->user_mobile)) {
|
|
| 571 | - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++;
|
|
| 572 | - } |
|
| 573 | - if (! empty($this->fax)) {
|
|
| 574 | - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++;
|
|
| 575 | - } |
|
| 576 | - if (! empty($this->office_fax)) {
|
|
| 577 | - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++;
|
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - $out.='<div style="clear: both;"></div>'; |
|
| 581 | - $outdone=0; |
|
| 582 | - if (! empty($this->email)) |
|
| 583 | - {
|
|
| 584 | - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
| 585 | - $outdone++; |
|
| 586 | - } |
|
| 587 | - if (! empty($this->url)) |
|
| 588 | - {
|
|
| 589 | - $out.=dol_print_url($this->url,'_goout',0,1); |
|
| 590 | - $outdone++; |
|
| 591 | - } |
|
| 592 | - $out.='<div style="clear: both;">'; |
|
| 593 | - if (! empty($conf->socialnetworks->enabled)) |
|
| 594 | - {
|
|
| 595 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 596 | - $outdone++; |
|
| 597 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 598 | - $outdone++; |
|
| 599 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 600 | - $outdone++; |
|
| 601 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 602 | - $outdone++; |
|
| 603 | - } |
|
| 604 | - $out.='</div>'; |
|
| 605 | - |
|
| 606 | - $out.='<!-- END Part to show address block -->'; |
|
| 607 | - |
|
| 608 | - return $out; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Return the link of last main doc file for direct public download. |
|
| 613 | - * |
|
| 614 | - * @param string $modulepart Module related to document |
|
| 615 | - * @param int $initsharekey Init the share key if it was not yet defined |
|
| 616 | - * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
|
| 617 | - * @return string Link or empty string if there is no download link |
|
| 618 | - */ |
|
| 619 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 620 | - {
|
|
| 621 | - global $user, $dolibarr_main_url_root; |
|
| 622 | - |
|
| 623 | - if (empty($this->last_main_doc)) |
|
| 624 | - {
|
|
| 625 | - return ''; // No way to known which document name to use |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 629 | - $ecmfile=new EcmFiles($this->db); |
|
| 630 | - $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
|
| 631 | - if ($result < 0) |
|
| 632 | - {
|
|
| 633 | - $this->error = $ecmfile->error; |
|
| 634 | - $this->errors = $ecmfile->errors; |
|
| 635 | - return -1; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - if (empty($ecmfile->id)) |
|
| 639 | - {
|
|
| 640 | - // Add entry into index |
|
| 641 | - if ($initsharekey) |
|
| 642 | - {
|
|
| 643 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 644 | - // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
|
| 645 | - /* |
|
| 646 | - $ecmfile->filepath = $rel_dir; |
|
| 647 | - $ecmfile->filename = $filename; |
|
| 648 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 649 | - $ecmfile->fullpath_orig = ''; |
|
| 650 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
| 651 | - $ecmfile->description = ''; // indexed content |
|
| 652 | - $ecmfile->keyword = ''; // keyword content |
|
| 653 | - $ecmfile->share = getRandomPassword(true); |
|
| 654 | - $result = $ecmfile->create($user); |
|
| 655 | - if ($result < 0) |
|
| 656 | - {
|
|
| 657 | - $this->error = $ecmfile->error; |
|
| 658 | - $this->errors = $ecmfile->errors; |
|
| 659 | - } |
|
| 660 | - */ |
|
| 661 | - } |
|
| 662 | - else return ''; |
|
| 663 | - } |
|
| 664 | - elseif (empty($ecmfile->share)) |
|
| 665 | - {
|
|
| 666 | - // Add entry into index |
|
| 667 | - if ($initsharekey) |
|
| 668 | - {
|
|
| 669 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 670 | - $ecmfile->share = getRandomPassword(true); |
|
| 671 | - $ecmfile->update($user); |
|
| 672 | - } |
|
| 673 | - else return ''; |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - // Define $urlwithroot |
|
| 677 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
|
|
| 678 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 679 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 680 | - |
|
| 681 | - $forcedownload=0; |
|
| 682 | - |
|
| 683 | - $paramlink=''; |
|
| 684 | - //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
|
| 685 | - //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
|
| 686 | - //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
|
| 687 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 688 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 689 | - |
|
| 690 | - if ($relativelink) |
|
| 691 | - {
|
|
| 692 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 693 | - } |
|
| 694 | - else |
|
| 695 | - {
|
|
| 696 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - // Here $ecmfile->share is defined |
|
| 700 | - return $linktoreturn; |
|
| 701 | - } |
|
| 54 | + /** |
|
| 55 | + * @var string Key value used to track if data is coming from import wizard |
|
| 56 | + */ |
|
| 57 | + public $import_key; |
|
| 702 | 58 | |
| 59 | + /** |
|
| 60 | + * @var mixed Contains data to manage extrafields |
|
| 61 | + */ |
|
| 62 | + public $array_options=array(); |
|
| 703 | 63 | |
| 704 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 705 | - /** |
|
| 706 | - * Add a link between element $this->element and a contact |
|
| 707 | - * |
|
| 708 | - * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link |
|
| 709 | - * @param int $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL |
|
| 710 | - * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) |
|
| 711 | - * @param int $notrigger Disable all triggers |
|
| 712 | - * @return int <0 if KO, >0 if OK |
|
| 713 | - */ |
|
| 714 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 715 | - {
|
|
| 716 | - // phpcs:enable |
|
| 717 | - global $user,$langs; |
|
| 718 | - |
|
| 719 | - |
|
| 720 | - dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
| 721 | - |
|
| 722 | - // Check parameters |
|
| 723 | - if ($fk_socpeople <= 0) |
|
| 724 | - {
|
|
| 725 | - $langs->load("errors");
|
|
| 726 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1");
|
|
| 727 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 728 | - return -1; |
|
| 729 | - } |
|
| 730 | - if (! $type_contact) |
|
| 731 | - {
|
|
| 732 | - $langs->load("errors");
|
|
| 733 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2");
|
|
| 734 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 735 | - return -2; |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - $id_type_contact=0; |
|
| 739 | - if (is_numeric($type_contact)) |
|
| 740 | - {
|
|
| 741 | - $id_type_contact=$type_contact; |
|
| 742 | - } |
|
| 743 | - else |
|
| 744 | - {
|
|
| 745 | - // We look for id type_contact |
|
| 746 | - $sql = "SELECT tc.rowid"; |
|
| 747 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 748 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 749 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 750 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 751 | - //print $sql; |
|
| 752 | - $resql=$this->db->query($sql); |
|
| 753 | - if ($resql) |
|
| 754 | - {
|
|
| 755 | - $obj = $this->db->fetch_object($resql); |
|
| 756 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 757 | - } |
|
| 758 | - } |
|
| 759 | - |
|
| 760 | - if ($id_type_contact == 0) |
|
| 761 | - {
|
|
| 762 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 763 | - dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact."' does not exists or is not active for element ".$this->element.", we can ignore it");
|
|
| 764 | - return -3; |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - $datecreate = dol_now(); |
|
| 768 | - |
|
| 769 | - // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
|
| 770 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
| 771 | - $already_added=false; |
|
| 772 | - if(!empty($TListeContacts)) {
|
|
| 773 | - foreach($TListeContacts as $array_contact) {
|
|
| 774 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
|
| 775 | - $already_added=true; |
|
| 776 | - break; |
|
| 777 | - } |
|
| 778 | - } |
|
| 779 | - } |
|
| 64 | + /** |
|
| 65 | + * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
|
| 66 | + */ |
|
| 67 | + public $linkedObjectsIds; |
|
| 780 | 68 | |
| 781 | - if(!$already_added) {
|
|
| 69 | + /** |
|
| 70 | + * @var mixed Array of linked objects. Loaded by ->fetchObjectLinked |
|
| 71 | + */ |
|
| 72 | + public $linkedObjects; |
|
| 782 | 73 | |
| 783 | - $this->db->begin(); |
|
| 74 | + /** |
|
| 75 | + * @var Object To store a cloned copy of object before to edit it and keep track of old properties |
|
| 76 | + */ |
|
| 77 | + public $oldcopy; |
|
| 784 | 78 | |
| 785 | - // Insert into database |
|
| 786 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
| 787 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 788 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
|
| 789 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 790 | - $sql.= ", 4, ". $id_type_contact; |
|
| 791 | - $sql.= ")"; |
|
| 79 | + /** |
|
| 80 | + * @var string Column name of the ref field. |
|
| 81 | + */ |
|
| 82 | + protected $table_ref_field = ''; |
|
| 792 | 83 | |
| 793 | - $resql=$this->db->query($sql); |
|
| 794 | - if ($resql) |
|
| 795 | - {
|
|
| 796 | - if (! $notrigger) |
|
| 797 | - {
|
|
| 798 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 799 | - if ($result < 0) |
|
| 800 | - {
|
|
| 801 | - $this->db->rollback(); |
|
| 802 | - return -1; |
|
| 803 | - } |
|
| 804 | - } |
|
| 805 | 84 | |
| 806 | - $this->db->commit(); |
|
| 807 | - return 1; |
|
| 808 | - } |
|
| 809 | - else |
|
| 810 | - {
|
|
| 811 | - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
| 812 | - {
|
|
| 813 | - $this->error=$this->db->errno(); |
|
| 814 | - $this->db->rollback(); |
|
| 815 | - echo 'err rollback'; |
|
| 816 | - return -2; |
|
| 817 | - } |
|
| 818 | - else |
|
| 819 | - {
|
|
| 820 | - $this->error=$this->db->error(); |
|
| 821 | - $this->db->rollback(); |
|
| 822 | - return -1; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - } else return 0; |
|
| 826 | - } |
|
| 827 | 85 | |
| 828 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 829 | - /** |
|
| 830 | - * Copy contact from one element to current |
|
| 831 | - * |
|
| 832 | - * @param CommonObject $objFrom Source element |
|
| 833 | - * @param string $source Nature of contact ('internal' or 'external')
|
|
| 834 | - * @return int >0 if OK, <0 if KO |
|
| 835 | - */ |
|
| 836 | - function copy_linked_contact($objFrom, $source='internal') |
|
| 837 | - {
|
|
| 838 | - // phpcs:enable |
|
| 839 | - $contacts = $objFrom->liste_contact(-1, $source); |
|
| 840 | - foreach($contacts as $contact) |
|
| 841 | - {
|
|
| 842 | - if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
|
| 843 | - {
|
|
| 844 | - $this->error=$this->db->lasterror(); |
|
| 845 | - return -1; |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - return 1; |
|
| 849 | - } |
|
| 86 | + // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. |
|
| 850 | 87 | |
| 851 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 852 | - /** |
|
| 853 | - * Update a link to contact line |
|
| 854 | - * |
|
| 855 | - * @param int $rowid Id of line contact-element |
|
| 856 | - * @param int $statut New status of link |
|
| 857 | - * @param int $type_contact_id Id of contact type (not modified if 0) |
|
| 858 | - * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
|
| 859 | - * @return int <0 if KO, >= 0 if OK |
|
| 860 | - */ |
|
| 861 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 862 | - {
|
|
| 863 | - // phpcs:enable |
|
| 864 | - // Insert into database |
|
| 865 | - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
| 866 | - $sql.= " statut = ".$statut; |
|
| 867 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 868 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 869 | - $sql.= " where rowid = ".$rowid; |
|
| 870 | - $resql=$this->db->query($sql); |
|
| 871 | - if ($resql) |
|
| 872 | - {
|
|
| 873 | - return 0; |
|
| 874 | - } |
|
| 875 | - else |
|
| 876 | - {
|
|
| 877 | - $this->error=$this->db->lasterror(); |
|
| 878 | - return -1; |
|
| 879 | - } |
|
| 880 | - } |
|
| 88 | + /** |
|
| 89 | + * @var array<string,mixed> Can be used to pass information when only object is provided to method |
|
| 90 | + */ |
|
| 91 | + public $context=array(); |
|
| 881 | 92 | |
| 882 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 883 | - /** |
|
| 884 | - * Delete a link to contact line |
|
| 885 | - * |
|
| 886 | - * @param int $rowid Id of contact link line to delete |
|
| 887 | - * @param int $notrigger Disable all triggers |
|
| 888 | - * @return int >0 if OK, <0 if KO |
|
| 889 | - */ |
|
| 890 | - function delete_contact($rowid, $notrigger=0) |
|
| 891 | - {
|
|
| 892 | - // phpcs:enable |
|
| 893 | - global $user; |
|
| 93 | + /** |
|
| 94 | + * @var string Contains canvas name if record is an alternative canvas record |
|
| 95 | + */ |
|
| 96 | + public $canvas; |
|
| 894 | 97 | |
| 98 | + /** |
|
| 99 | + * @var Project The related project |
|
| 100 | + * @see fetch_projet() |
|
| 101 | + */ |
|
| 102 | + public $project; |
|
| 895 | 103 | |
| 896 | - $this->db->begin(); |
|
| 104 | + /** |
|
| 105 | + * @var int The related project ID |
|
| 106 | + * @see setProject(), project |
|
| 107 | + */ |
|
| 108 | + public $fk_project; |
|
| 897 | 109 | |
| 898 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 899 | - $sql.= " WHERE rowid =".$rowid; |
|
| 110 | + /** |
|
| 111 | + * @deprecated |
|
| 112 | + * @see project |
|
| 113 | + */ |
|
| 114 | + public $projet; |
|
| 900 | 115 | |
| 901 | - dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
| 902 | - if ($this->db->query($sql)) |
|
| 903 | - {
|
|
| 904 | - if (! $notrigger) |
|
| 905 | - {
|
|
| 906 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 907 | - if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - $this->db->commit(); |
|
| 911 | - return 1; |
|
| 912 | - } |
|
| 913 | - else |
|
| 914 | - {
|
|
| 915 | - $this->error=$this->db->lasterror(); |
|
| 916 | - $this->db->rollback(); |
|
| 917 | - return -1; |
|
| 918 | - } |
|
| 919 | - } |
|
| 116 | + /** |
|
| 117 | + * @var Contact a related contact |
|
| 118 | + * @see fetch_contact() |
|
| 119 | + */ |
|
| 120 | + public $contact; |
|
| 920 | 121 | |
| 921 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 922 | - /** |
|
| 923 | - * Delete all links between an object $this and all its contacts |
|
| 924 | - * |
|
| 925 | - * @param string $source '' or 'internal' or 'external' |
|
| 926 | - * @param string $code Type of contact (code or id) |
|
| 927 | - * @return int >0 if OK, <0 if KO |
|
| 928 | - */ |
|
| 929 | - function delete_linked_contact($source='',$code='') |
|
| 930 | - {
|
|
| 931 | - // phpcs:enable |
|
| 932 | - $temp = array(); |
|
| 933 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 934 | - |
|
| 935 | - foreach($typeContact as $key => $value) |
|
| 936 | - {
|
|
| 937 | - array_push($temp,$key); |
|
| 938 | - } |
|
| 939 | - $listId = implode(",", $temp);
|
|
| 940 | - |
|
| 941 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 942 | - $sql.= " WHERE element_id = ".$this->id; |
|
| 943 | - if ($listId) |
|
| 944 | - $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 945 | - |
|
| 946 | - dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
| 947 | - if ($this->db->query($sql)) |
|
| 948 | - {
|
|
| 949 | - return 1; |
|
| 950 | - } |
|
| 951 | - else |
|
| 952 | - {
|
|
| 953 | - $this->error=$this->db->lasterror(); |
|
| 954 | - return -1; |
|
| 955 | - } |
|
| 956 | - } |
|
| 122 | + /** |
|
| 123 | + * @var int The related contact ID |
|
| 124 | + * @see fetch_contact() |
|
| 125 | + */ |
|
| 126 | + public $contact_id; |
|
| 957 | 127 | |
| 958 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 959 | - /** |
|
| 960 | - * Get array of all contacts for an object |
|
| 961 | - * |
|
| 962 | - * @param int $statut Status of links to get (-1=all) |
|
| 963 | - * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) |
|
| 964 | - * @param int $list 0:Return array contains all properties, 1:Return array contains just id |
|
| 965 | - * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
|
|
| 966 | - * @return array|int Array of contacts, -1 if error |
|
| 967 | - */ |
|
| 968 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 969 | - {
|
|
| 970 | - // phpcs:enable |
|
| 971 | - global $langs; |
|
| 972 | - |
|
| 973 | - $tab=array(); |
|
| 974 | - |
|
| 975 | - $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 |
|
| 976 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 977 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 978 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 979 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 980 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 981 | - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 982 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 983 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 984 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
| 985 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 986 | - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 987 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 988 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 989 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 990 | - $sql.= " AND tc.active=1"; |
|
| 991 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 992 | - $sql.=" ORDER BY t.lastname ASC"; |
|
| 993 | - |
|
| 994 | - dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
| 995 | - $resql=$this->db->query($sql); |
|
| 996 | - if ($resql) |
|
| 997 | - {
|
|
| 998 | - $num=$this->db->num_rows($resql); |
|
| 999 | - $i=0; |
|
| 1000 | - while ($i < $num) |
|
| 1001 | - {
|
|
| 1002 | - $obj = $this->db->fetch_object($resql); |
|
| 128 | + /** |
|
| 129 | + * @var Societe A related thirdparty |
|
| 130 | + * @see fetch_thirdparty() |
|
| 131 | + */ |
|
| 132 | + public $thirdparty; |
|
| 1003 | 133 | |
| 1004 | - if (! $list) |
|
| 1005 | - {
|
|
| 1006 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1007 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1008 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,
|
|
| 1009 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1010 | - 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
|
| 1011 | - 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
|
| 1012 | - } |
|
| 1013 | - else |
|
| 1014 | - {
|
|
| 1015 | - $tab[$i]=$obj->id; |
|
| 1016 | - } |
|
| 134 | + /** |
|
| 135 | + * @var User A related user |
|
| 136 | + * @see fetch_user() |
|
| 137 | + */ |
|
| 138 | + public $user; |
|
| 1017 | 139 | |
| 1018 | - $i++; |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - return $tab; |
|
| 1022 | - } |
|
| 1023 | - else |
|
| 1024 | - {
|
|
| 1025 | - $this->error=$this->db->lasterror(); |
|
| 1026 | - dol_print_error($this->db); |
|
| 1027 | - return -1; |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - |
|
| 1032 | - /** |
|
| 1033 | - * Update status of a contact linked to object |
|
| 1034 | - * |
|
| 1035 | - * @param int $rowid Id of link between object and contact |
|
| 1036 | - * @return int <0 if KO, >=0 if OK |
|
| 1037 | - */ |
|
| 1038 | - function swapContactStatus($rowid) |
|
| 1039 | - {
|
|
| 1040 | - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
|
| 1041 | - $sql.= " tc.code, tc.libelle"; |
|
| 1042 | - //$sql.= ", s.fk_soc"; |
|
| 1043 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
|
|
| 1044 | - //$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 |
|
| 1045 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
| 1046 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1047 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1048 | - |
|
| 1049 | - dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
| 1050 | - $resql=$this->db->query($sql); |
|
| 1051 | - if ($resql) |
|
| 1052 | - {
|
|
| 1053 | - $obj = $this->db->fetch_object($resql); |
|
| 1054 | - $newstatut = ($obj->statut == 4) ? 5 : 4; |
|
| 1055 | - $result = $this->update_contact($rowid, $newstatut); |
|
| 1056 | - $this->db->free($resql); |
|
| 1057 | - return $result; |
|
| 1058 | - } |
|
| 1059 | - else |
|
| 1060 | - {
|
|
| 1061 | - $this->error=$this->db->error(); |
|
| 1062 | - dol_print_error($this->db); |
|
| 1063 | - return -1; |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 140 | + /** |
|
| 141 | + * @var string The type of originating object ('commande', 'facture', ...)
|
|
| 142 | + * @see fetch_origin() |
|
| 143 | + */ |
|
| 144 | + public $origin; |
|
| 1066 | 145 | |
| 1067 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1068 | - /** |
|
| 1069 | - * Return array with list of possible values for type of contacts |
|
| 1070 | - * |
|
| 1071 | - * @param string $source 'internal', 'external' or 'all' |
|
| 1072 | - * @param string $order Sort order by : 'position', 'code', 'rowid'... |
|
| 1073 | - * @param int $option 0=Return array id->label, 1=Return array code->label |
|
| 1074 | - * @param int $activeonly 0=all status of contact, 1=only the active |
|
| 1075 | - * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
|
| 1076 | - * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
|
| 1077 | - */ |
|
| 1078 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1079 | - {
|
|
| 1080 | - // phpcs:enable |
|
| 1081 | - global $langs; |
|
| 1082 | - |
|
| 1083 | - if (empty($order)) $order='position'; |
|
| 1084 | - if ($order == 'position') $order.=',code'; |
|
| 1085 | - |
|
| 1086 | - $tab = array(); |
|
| 1087 | - $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
|
| 1088 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1089 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1090 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1091 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1092 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1093 | - $sql.= $this->db->order($order,'ASC'); |
|
| 1094 | - |
|
| 1095 | - //print "sql=".$sql; |
|
| 1096 | - $resql=$this->db->query($sql); |
|
| 1097 | - if ($resql) |
|
| 1098 | - {
|
|
| 1099 | - $num=$this->db->num_rows($resql); |
|
| 1100 | - $i=0; |
|
| 1101 | - while ($i < $num) |
|
| 1102 | - {
|
|
| 1103 | - $obj = $this->db->fetch_object($resql); |
|
| 1104 | - |
|
| 1105 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1106 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1107 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1108 | - else $tab[$obj->code]=$libelle_type; |
|
| 1109 | - $i++; |
|
| 1110 | - } |
|
| 1111 | - return $tab; |
|
| 1112 | - } |
|
| 1113 | - else |
|
| 1114 | - {
|
|
| 1115 | - $this->error=$this->db->lasterror(); |
|
| 1116 | - //dol_print_error($this->db); |
|
| 1117 | - return null; |
|
| 1118 | - } |
|
| 1119 | - } |
|
| 1120 | - |
|
| 1121 | - /** |
|
| 1122 | - * Return id of contacts for a source and a contact code. |
|
| 1123 | - * Example: contact client de facturation ('external', 'BILLING')
|
|
| 1124 | - * Example: contact client de livraison ('external', 'SHIPPING')
|
|
| 1125 | - * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL')
|
|
| 1126 | - * |
|
| 1127 | - * @param string $source 'external' or 'internal' |
|
| 1128 | - * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... |
|
| 1129 | - * @param int $status limited to a certain status |
|
| 1130 | - * @return array List of id for such contacts |
|
| 1131 | - */ |
|
| 1132 | - function getIdContact($source,$code,$status=0) |
|
| 1133 | - {
|
|
| 1134 | - global $conf; |
|
| 1135 | - |
|
| 1136 | - $result=array(); |
|
| 1137 | - $i=0; |
|
| 1138 | - //cas particulier pour les expeditions |
|
| 1139 | - if($this->element=='shipping' && $this->origin_id != 0) {
|
|
| 1140 | - $id=$this->origin_id; |
|
| 1141 | - $element='commande'; |
|
| 1142 | - } else if($this->element=='reception' && $this->origin_id != 0) {
|
|
| 1143 | - $id=$this->origin_id; |
|
| 1144 | - $element='order_supplier'; |
|
| 1145 | - } else {
|
|
| 1146 | - $id=$this->id; |
|
| 1147 | - $element=$this->element; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - $sql = "SELECT ec.fk_socpeople"; |
|
| 1151 | - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1152 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1153 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1154 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1155 | - $sql.= " WHERE ec.element_id = ".$id; |
|
| 1156 | - $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
| 1157 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1158 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1159 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1160 | - $sql.= " AND tc.element = '".$element."'"; |
|
| 1161 | - $sql.= " AND tc.source = '".$source."'"; |
|
| 1162 | - $sql.= " AND tc.code = '".$code."'"; |
|
| 1163 | - $sql.= " AND tc.active = 1"; |
|
| 1164 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1165 | - |
|
| 1166 | - dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
| 1167 | - $resql=$this->db->query($sql); |
|
| 1168 | - if ($resql) |
|
| 1169 | - {
|
|
| 1170 | - while ($obj = $this->db->fetch_object($resql)) |
|
| 1171 | - {
|
|
| 1172 | - $result[$i]=$obj->fk_socpeople; |
|
| 1173 | - $i++; |
|
| 1174 | - } |
|
| 1175 | - } |
|
| 1176 | - else |
|
| 1177 | - {
|
|
| 1178 | - $this->error=$this->db->error(); |
|
| 1179 | - return null; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return $result; |
|
| 1183 | - } |
|
| 146 | + /** |
|
| 147 | + * @var int The id of originating object |
|
| 148 | + * @see fetch_origin() |
|
| 149 | + */ |
|
| 150 | + public $origin_id; |
|
| 1184 | 151 | |
| 1185 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1186 | - /** |
|
| 1187 | - * Load object contact with id=$this->contactid into $this->contact |
|
| 1188 | - * |
|
| 1189 | - * @param int $contactid Id du contact. Use this->contactid if empty. |
|
| 1190 | - * @return int <0 if KO, >0 if OK |
|
| 1191 | - */ |
|
| 1192 | - function fetch_contact($contactid=null) |
|
| 1193 | - {
|
|
| 1194 | - // phpcs:enable |
|
| 1195 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 152 | + /** |
|
| 153 | + * @var string The object's reference |
|
| 154 | + */ |
|
| 155 | + public $ref; |
|
| 1196 | 156 | |
| 1197 | - if (empty($contactid)) return 0; |
|
| 157 | + /** |
|
| 158 | + * @var string The object's previous reference |
|
| 159 | + */ |
|
| 160 | + public $ref_previous; |
|
| 1198 | 161 | |
| 1199 | - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 1200 | - $contact = new Contact($this->db); |
|
| 1201 | - $result=$contact->fetch($contactid); |
|
| 1202 | - $this->contact = $contact; |
|
| 1203 | - return $result; |
|
| 1204 | - } |
|
| 162 | + /** |
|
| 163 | + * @var string The object's next reference |
|
| 164 | + */ |
|
| 165 | + public $ref_next; |
|
| 1205 | 166 | |
| 1206 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1207 | - /** |
|
| 1208 | - * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty |
|
| 1209 | - * |
|
| 1210 | - * @param int $force_thirdparty_id Force thirdparty id |
|
| 1211 | - * @return int <0 if KO, >0 if OK |
|
| 1212 | - */ |
|
| 1213 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1214 | - {
|
|
| 1215 | - // phpcs:enable |
|
| 1216 | - global $conf; |
|
| 167 | + /** |
|
| 168 | + * @var string An external reference for the object |
|
| 169 | + */ |
|
| 170 | + public $ref_ext; |
|
| 1217 | 171 | |
| 1218 | - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1219 | - return 0; |
|
| 172 | + /** |
|
| 173 | + * @var int The object's status |
|
| 174 | + * @see setStatut() |
|
| 175 | + */ |
|
| 176 | + public $statut; |
|
| 1220 | 177 | |
| 1221 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 178 | + /** |
|
| 179 | + * @var string |
|
| 180 | + * @see getFullAddress() |
|
| 181 | + */ |
|
| 182 | + public $country; |
|
| 1222 | 183 | |
| 1223 | - $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
|
| 1224 | - if ($force_thirdparty_id) |
|
| 1225 | - $idtofetch = $force_thirdparty_id; |
|
| 184 | + /** |
|
| 185 | + * @var int |
|
| 186 | + * @see getFullAddress(), country |
|
| 187 | + */ |
|
| 188 | + public $country_id; |
|
| 1226 | 189 | |
| 1227 | - if ($idtofetch) {
|
|
| 1228 | - $thirdparty = new Societe($this->db); |
|
| 1229 | - $result = $thirdparty->fetch($idtofetch); |
|
| 1230 | - $this->thirdparty = $thirdparty; |
|
| 190 | + /** |
|
| 191 | + * @var string |
|
| 192 | + * @see getFullAddress(), isInEEC(), country |
|
| 193 | + */ |
|
| 194 | + public $country_code; |
|
| 1231 | 195 | |
| 1232 | - // Use first price level if level not defined for third party |
|
| 1233 | - if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) {
|
|
| 1234 | - $this->thirdparty->price_level = 1; |
|
| 1235 | - } |
|
| 196 | + /** |
|
| 197 | + * @var string |
|
| 198 | + * @see getFullAddress() |
|
| 199 | + */ |
|
| 200 | + public $state; |
|
| 1236 | 201 | |
| 1237 | - return $result; |
|
| 1238 | - } else |
|
| 1239 | - return -1; |
|
| 1240 | - } |
|
| 202 | + /** |
|
| 203 | + * @var int |
|
| 204 | + * @see getFullAddress(), state |
|
| 205 | + */ |
|
| 206 | + public $state_id; |
|
| 1241 | 207 | |
| 208 | + /** |
|
| 209 | + * @var string |
|
| 210 | + * @see getFullAddress(), state |
|
| 211 | + */ |
|
| 212 | + public $state_code; |
|
| 1242 | 213 | |
| 1243 | - /** |
|
| 1244 | - * Looks for an object with ref matching the wildcard provided |
|
| 1245 | - * It does only work when $this->table_ref_field is set |
|
| 1246 | - * |
|
| 1247 | - * @param string $ref Wildcard |
|
| 1248 | - * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO |
|
| 1249 | - */ |
|
| 1250 | - public function fetchOneLike($ref) |
|
| 1251 | - {
|
|
| 1252 | - if (!$this->table_ref_field) {
|
|
| 1253 | - return 0; |
|
| 1254 | - } |
|
| 214 | + /** |
|
| 215 | + * @var string |
|
| 216 | + * @see getFullAddress(), region |
|
| 217 | + */ |
|
| 218 | + public $region; |
|
| 1255 | 219 | |
| 1256 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
| 220 | + /** |
|
| 221 | + * @var string |
|
| 222 | + * @see getFullAddress(), region |
|
| 223 | + */ |
|
| 224 | + public $region_code; |
|
| 1257 | 225 | |
| 1258 | - $query = $this->db->query($sql); |
|
| 226 | + /** |
|
| 227 | + * @var int |
|
| 228 | + * @see fetch_barcode() |
|
| 229 | + */ |
|
| 230 | + public $barcode_type; |
|
| 1259 | 231 | |
| 1260 | - if (!$this->db->num_rows($query)) {
|
|
| 1261 | - return 0; |
|
| 1262 | - } |
|
| 232 | + /** |
|
| 233 | + * @var string |
|
| 234 | + * @see fetch_barcode(), barcode_type |
|
| 235 | + */ |
|
| 236 | + public $barcode_type_code; |
|
| 1263 | 237 | |
| 1264 | - $result = $this->db->fetch_object($query); |
|
| 238 | + /** |
|
| 239 | + * @var string |
|
| 240 | + * @see fetch_barcode(), barcode_type |
|
| 241 | + */ |
|
| 242 | + public $barcode_type_label; |
|
| 1265 | 243 | |
| 1266 | - return $this->fetch($result->rowid); |
|
| 1267 | - } |
|
| 244 | + /** |
|
| 245 | + * @var string |
|
| 246 | + * @see fetch_barcode(), barcode_type |
|
| 247 | + */ |
|
| 248 | + public $barcode_type_coder; |
|
| 1268 | 249 | |
| 1269 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1270 | - /** |
|
| 1271 | - * Load data for barcode into properties ->barcode_type* |
|
| 1272 | - * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but |
|
| 1273 | - * if it is not defined, ->element must be defined to know default barcode type. |
|
| 1274 | - * |
|
| 1275 | - * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) |
|
| 1276 | - */ |
|
| 1277 | - function fetch_barcode() |
|
| 1278 | - {
|
|
| 1279 | - // phpcs:enable |
|
| 1280 | - global $conf; |
|
| 250 | + /** |
|
| 251 | + * @var int Payment method ID (cheque, cash, ...) |
|
| 252 | + * @see setPaymentMethods() |
|
| 253 | + */ |
|
| 254 | + public $mode_reglement_id; |
|
| 1281 | 255 | |
| 1282 | - dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
| 256 | + /** |
|
| 257 | + * @var int Payment terms ID |
|
| 258 | + * @see setPaymentTerms() |
|
| 259 | + */ |
|
| 260 | + public $cond_reglement_id; |
|
| 1283 | 261 | |
| 1284 | - $idtype=$this->barcode_type; |
|
| 1285 | - 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 |
|
| 1286 | - {
|
|
| 1287 | - if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1288 | - else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1289 | - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
|
|
| 1290 | - } |
|
| 262 | + /** |
|
| 263 | + * @var int Payment terms ID |
|
| 264 | + * @deprecated Kept for compatibility |
|
| 265 | + * @see cond_reglement_id; |
|
| 266 | + */ |
|
| 267 | + public $cond_reglement; |
|
| 1291 | 268 | |
| 1292 | - if ($idtype > 0) |
|
| 1293 | - {
|
|
| 1294 | - 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 |
|
| 1295 | - {
|
|
| 1296 | - $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1297 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1298 | - $sql.= " WHERE rowid = ".$idtype; |
|
| 1299 | - dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
| 1300 | - $resql = $this->db->query($sql); |
|
| 1301 | - if ($resql) |
|
| 1302 | - {
|
|
| 1303 | - $obj = $this->db->fetch_object($resql); |
|
| 1304 | - $this->barcode_type = $obj->rowid; |
|
| 1305 | - $this->barcode_type_code = $obj->code; |
|
| 1306 | - $this->barcode_type_label = $obj->label; |
|
| 1307 | - $this->barcode_type_coder = $obj->coder; |
|
| 1308 | - return 1; |
|
| 1309 | - } |
|
| 1310 | - else |
|
| 1311 | - {
|
|
| 1312 | - dol_print_error($this->db); |
|
| 1313 | - return -1; |
|
| 1314 | - } |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - return 0; |
|
| 1318 | - } |
|
| 269 | + /** |
|
| 270 | + * @var int Delivery address ID |
|
| 271 | + * @deprecated |
|
| 272 | + * @see setDeliveryAddress() |
|
| 273 | + */ |
|
| 274 | + public $fk_delivery_address; |
|
| 1319 | 275 | |
| 1320 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1321 | - /** |
|
| 1322 | - * Load the project with id $this->fk_project into this->project |
|
| 1323 | - * |
|
| 1324 | - * @return int <0 if KO, >=0 if OK |
|
| 1325 | - */ |
|
| 1326 | - function fetch_projet() |
|
| 1327 | - {
|
|
| 1328 | - // phpcs:enable |
|
| 1329 | - include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 276 | + /** |
|
| 277 | + * @var int Shipping method ID |
|
| 278 | + * @see setShippingMethod() |
|
| 279 | + */ |
|
| 280 | + public $shipping_method_id; |
|
| 1330 | 281 | |
| 1331 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1332 | - if (empty($this->fk_project)) return 0; |
|
| 282 | + /** |
|
| 283 | + * @var string |
|
| 284 | + * @see SetDocModel() |
|
| 285 | + */ |
|
| 286 | + public $modelpdf; |
|
| 1333 | 287 | |
| 1334 | - $project = new Project($this->db); |
|
| 1335 | - $result = $project->fetch($this->fk_project); |
|
| 288 | + /** |
|
| 289 | + * @var int Bank account ID |
|
| 290 | + * @see SetBankAccount() |
|
| 291 | + */ |
|
| 292 | + public $fk_account; |
|
| 1336 | 293 | |
| 1337 | - $this->projet = $project; // deprecated |
|
| 1338 | - $this->project = $project; |
|
| 1339 | - return $result; |
|
| 1340 | - } |
|
| 294 | + /** |
|
| 295 | + * @var string Public note |
|
| 296 | + * @see update_note() |
|
| 297 | + */ |
|
| 298 | + public $note_public; |
|
| 1341 | 299 | |
| 1342 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1343 | - /** |
|
| 1344 | - * Load the product with id $this->fk_product into this->product |
|
| 1345 | - * |
|
| 1346 | - * @return int <0 if KO, >=0 if OK |
|
| 1347 | - */ |
|
| 1348 | - function fetch_product() |
|
| 1349 | - {
|
|
| 1350 | - // phpcs:enable |
|
| 1351 | - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 300 | + /** |
|
| 301 | + * @var string Private note |
|
| 302 | + * @see update_note() |
|
| 303 | + */ |
|
| 304 | + public $note_private; |
|
| 1352 | 305 | |
| 1353 | - if (empty($this->fk_product)) return 0; |
|
| 306 | + /** |
|
| 307 | + * @deprecated |
|
| 308 | + * @see note_public |
|
| 309 | + */ |
|
| 310 | + public $note; |
|
| 1354 | 311 | |
| 1355 | - $product = new Product($this->db); |
|
| 1356 | - $result = $product->fetch($this->fk_product); |
|
| 312 | + /** |
|
| 313 | + * @var float Total amount before taxes |
|
| 314 | + * @see update_price() |
|
| 315 | + */ |
|
| 316 | + public $total_ht; |
|
| 1357 | 317 | |
| 1358 | - $this->product = $product; |
|
| 1359 | - return $result; |
|
| 1360 | - } |
|
| 318 | + /** |
|
| 319 | + * @var float Total VAT amount |
|
| 320 | + * @see update_price() |
|
| 321 | + */ |
|
| 322 | + public $total_tva; |
|
| 1361 | 323 | |
| 1362 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1363 | - /** |
|
| 1364 | - * Load the user with id $userid into this->user |
|
| 1365 | - * |
|
| 1366 | - * @param int $userid Id du contact |
|
| 1367 | - * @return int <0 if KO, >0 if OK |
|
| 1368 | - */ |
|
| 1369 | - function fetch_user($userid) |
|
| 1370 | - {
|
|
| 1371 | - // phpcs:enable |
|
| 1372 | - $user = new User($this->db); |
|
| 1373 | - $result=$user->fetch($userid); |
|
| 1374 | - $this->user = $user; |
|
| 1375 | - return $result; |
|
| 1376 | - } |
|
| 324 | + /** |
|
| 325 | + * @var float Total local tax 1 amount |
|
| 326 | + * @see update_price() |
|
| 327 | + */ |
|
| 328 | + public $total_localtax1; |
|
| 1377 | 329 | |
| 1378 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1379 | - /** |
|
| 1380 | - * Read linked origin object |
|
| 1381 | - * |
|
| 1382 | - * @return void |
|
| 1383 | - */ |
|
| 1384 | - function fetch_origin() |
|
| 1385 | - {
|
|
| 1386 | - // phpcs:enable |
|
| 1387 | - if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1388 | - if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1389 | - if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 330 | + /** |
|
| 331 | + * @var float Total local tax 2 amount |
|
| 332 | + * @see update_price() |
|
| 333 | + */ |
|
| 334 | + public $total_localtax2; |
|
| 1390 | 335 | |
| 1391 | - $origin = $this->origin; |
|
| 336 | + /** |
|
| 337 | + * @var float Total amount with taxes |
|
| 338 | + * @see update_price() |
|
| 339 | + */ |
|
| 340 | + public $total_ttc; |
|
| 1392 | 341 | |
| 1393 | - $classname = ucfirst($origin); |
|
| 1394 | - $this->$origin = new $classname($this->db); |
|
| 1395 | - $this->$origin->fetch($this->origin_id); |
|
| 1396 | - } |
|
| 342 | + /** |
|
| 343 | + * @var CommonObjectLine[] |
|
| 344 | + */ |
|
| 345 | + public $lines; |
|
| 1397 | 346 | |
| 1398 | - /** |
|
| 1399 | - * Load object from specific field |
|
| 1400 | - * |
|
| 1401 | - * @param string $table Table element or element line |
|
| 1402 | - * @param string $field Field selected |
|
| 1403 | - * @param string $key Import key |
|
| 1404 | - * @param string $element Element name |
|
| 1405 | - * @return int <0 if KO, >0 if OK |
|
| 347 | + /** |
|
| 348 | + * @var mixed Contains comments |
|
| 349 | + * @see fetchComments() |
|
| 1406 | 350 | */ |
| 1407 | - function fetchObjectFrom($table, $field, $key, $element = null) |
|
| 1408 | - {
|
|
| 1409 | - global $conf; |
|
| 1410 | - |
|
| 1411 | - $result=false; |
|
| 1412 | - |
|
| 1413 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
| 1414 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1415 | - if (! empty($element)) {
|
|
| 1416 | - $sql.= " AND entity IN (".getEntity($element).")";
|
|
| 1417 | - } else {
|
|
| 1418 | - $sql.= " AND entity = ".$conf->entity; |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
| 1422 | - $resql = $this->db->query($sql); |
|
| 1423 | - if ($resql) |
|
| 1424 | - {
|
|
| 1425 | - $row = $this->db->fetch_row($resql); |
|
| 1426 | - // Test for avoid error -1 |
|
| 1427 | - if ($row[0] > 0) {
|
|
| 1428 | - $result = $this->fetch($row[0]); |
|
| 1429 | - } |
|
| 1430 | - } |
|
| 1431 | - |
|
| 1432 | - return $result; |
|
| 1433 | - } |
|
| 1434 | - |
|
| 1435 | - /** |
|
| 1436 | - * Getter generic. Load value from a specific field |
|
| 1437 | - * |
|
| 1438 | - * @param string $table Table of element or element line |
|
| 1439 | - * @param int $id Element id |
|
| 1440 | - * @param string $field Field selected |
|
| 1441 | - * @return int <0 if KO, >0 if OK |
|
| 1442 | - */ |
|
| 1443 | - function getValueFrom($table, $id, $field) |
|
| 1444 | - {
|
|
| 1445 | - $result=false; |
|
| 1446 | - if (!empty($id) && !empty($field) && !empty($table)) {
|
|
| 1447 | - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
| 1448 | - $sql.= " WHERE rowid = ".$id; |
|
| 1449 | - |
|
| 1450 | - dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
| 1451 | - $resql = $this->db->query($sql); |
|
| 1452 | - if ($resql) |
|
| 1453 | - {
|
|
| 1454 | - $row = $this->db->fetch_row($resql); |
|
| 1455 | - $result = $row[0]; |
|
| 1456 | - } |
|
| 1457 | - } |
|
| 1458 | - return $result; |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - /** |
|
| 1462 | - * Setter generic. Update a specific field into database. |
|
| 1463 | - * Warning: Trigger is run only if param trigkey is provided. |
|
| 1464 | - * |
|
| 1465 | - * @param string $field Field to update |
|
| 1466 | - * @param mixed $value New value |
|
| 1467 | - * @param string $table To force other table element or element line (should not be used) |
|
| 1468 | - * @param int $id To force other object id (should not be used) |
|
| 1469 | - * @param string $format Data format ('text', 'date'). 'text' is used if not defined
|
|
| 1470 | - * @param string $id_field To force rowid field name. 'rowid' is used if not defined |
|
| 1471 | - * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' |
|
| 1472 | - * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') |
|
| 1473 | - * @param string $fk_user_field Name of field to save user id making change |
|
| 1474 | - * @return int <0 if KO, >0 if OK |
|
| 1475 | - * @see updateExtraField |
|
| 1476 | - */ |
|
| 1477 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
| 1478 | - {
|
|
| 1479 | - global $user,$langs,$conf; |
|
| 1480 | - |
|
| 1481 | - if (empty($table)) $table=$this->table_element; |
|
| 1482 | - if (empty($id)) $id=$this->id; |
|
| 1483 | - if (empty($format)) $format='text'; |
|
| 1484 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1485 | - |
|
| 1486 | - $error=0; |
|
| 1487 | - |
|
| 1488 | - $this->db->begin(); |
|
| 1489 | - |
|
| 1490 | - // Special case |
|
| 1491 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1492 | - if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
|
| 1493 | - |
|
| 1494 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
| 1495 | - |
|
| 1496 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1497 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1498 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1499 | - |
|
| 1500 | - if ($fk_user_field) |
|
| 1501 | - {
|
|
| 1502 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1503 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1504 | - } |
|
| 1505 | - |
|
| 1506 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
| 1507 | - |
|
| 1508 | - dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
| 1509 | - $resql = $this->db->query($sql); |
|
| 1510 | - if ($resql) |
|
| 1511 | - {
|
|
| 1512 | - if ($trigkey) |
|
| 1513 | - {
|
|
| 1514 | - // call trigger with updated object values |
|
| 1515 | - if (empty($this->fields) && method_exists($this, 'fetch')) |
|
| 1516 | - {
|
|
| 1517 | - $result = $this->fetch($id); |
|
| 1518 | - } |
|
| 1519 | - else |
|
| 1520 | - {
|
|
| 1521 | - $result = $this->fetchCommon($id); |
|
| 1522 | - } |
|
| 1523 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1524 | - if ($result < 0) $error++; |
|
| 1525 | - } |
|
| 351 | + public $comments=array(); |
|
| 1526 | 352 | |
| 1527 | - if (! $error) |
|
| 1528 | - {
|
|
| 1529 | - if (property_exists($this, $field)) $this->$field = $value; |
|
| 1530 | - $this->db->commit(); |
|
| 1531 | - return 1; |
|
| 1532 | - } |
|
| 1533 | - else |
|
| 1534 | - {
|
|
| 1535 | - $this->db->rollback(); |
|
| 1536 | - return -2; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - else |
|
| 1540 | - {
|
|
| 1541 | - $this->error=$this->db->lasterror(); |
|
| 1542 | - $this->db->rollback(); |
|
| 1543 | - return -1; |
|
| 1544 | - } |
|
| 1545 | - } |
|
| 353 | + /** |
|
| 354 | + * @var int |
|
| 355 | + * @see setIncoterms() |
|
| 356 | + */ |
|
| 357 | + public $fk_incoterms; |
|
| 1546 | 358 | |
| 1547 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1548 | - /** |
|
| 1549 | - * Load properties id_previous and id_next by comparing $fieldid with $this->ref |
|
| 1550 | - * |
|
| 1551 | - * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" |
|
| 1552 | - * @param string $fieldid Name of field to use for the select MAX and MIN |
|
| 1553 | - * @param int $nodbprefix Do not include DB prefix to forge table name |
|
| 1554 | - * @return int <0 if KO, >0 if OK |
|
| 1555 | - */ |
|
| 1556 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1557 | - {
|
|
| 1558 | - // phpcs:enable |
|
| 1559 | - global $conf, $user; |
|
| 1560 | - |
|
| 1561 | - if (! $this->table_element) |
|
| 1562 | - {
|
|
| 1563 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
|
| 1564 | - return -1; |
|
| 1565 | - } |
|
| 1566 | - if ($fieldid == 'none') return 1; |
|
| 1567 | - |
|
| 1568 | - // Security on socid |
|
| 1569 | - $socid = 0; |
|
| 1570 | - if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 1571 | - |
|
| 1572 | - // this->ismultientitymanaged contains |
|
| 1573 | - // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
| 1574 | - $alias = 's'; |
|
| 1575 | - if ($this->element == 'societe') $alias = 'te'; |
|
| 1576 | - |
|
| 1577 | - $sql = "SELECT MAX(te.".$fieldid.")"; |
|
| 1578 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1579 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1580 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1581 | - } |
|
| 1582 | - 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 |
|
| 1583 | - 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 |
|
| 1584 | - 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 |
|
| 1585 | - 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"; |
|
| 1586 | - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1587 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1588 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1589 | - if (! empty($filter)) |
|
| 1590 | - {
|
|
| 1591 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1592 | - $sql.=$filter; |
|
| 1593 | - } |
|
| 1594 | - 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 |
|
| 1595 | - 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 |
|
| 1596 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1597 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1598 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1599 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1600 | - } else {
|
|
| 1601 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1602 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1603 | - } |
|
| 1604 | - } else {
|
|
| 1605 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1606 | - } |
|
| 1607 | - } |
|
| 1608 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1609 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1610 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1611 | - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 1612 | - |
|
| 1613 | - $result = $this->db->query($sql); |
|
| 1614 | - if (! $result) |
|
| 1615 | - {
|
|
| 1616 | - $this->error=$this->db->lasterror(); |
|
| 1617 | - return -1; |
|
| 1618 | - } |
|
| 1619 | - $row = $this->db->fetch_row($result); |
|
| 1620 | - $this->ref_previous = $row[0]; |
|
| 1621 | - |
|
| 1622 | - |
|
| 1623 | - $sql = "SELECT MIN(te.".$fieldid.")"; |
|
| 1624 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1625 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1626 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1627 | - } |
|
| 1628 | - 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 |
|
| 1629 | - 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 |
|
| 1630 | - 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 |
|
| 1631 | - 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"; |
|
| 1632 | - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1633 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1634 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1635 | - if (! empty($filter)) |
|
| 1636 | - {
|
|
| 1637 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1638 | - $sql.=$filter; |
|
| 1639 | - } |
|
| 1640 | - 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 |
|
| 1641 | - 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 |
|
| 1642 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1643 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1644 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1645 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1646 | - } else {
|
|
| 1647 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1648 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1649 | - } |
|
| 1650 | - } else {
|
|
| 1651 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1652 | - } |
|
| 1653 | - } |
|
| 1654 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1655 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1656 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1657 | - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 1658 | - // 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 |
|
| 1659 | - |
|
| 1660 | - $result = $this->db->query($sql); |
|
| 1661 | - if (! $result) |
|
| 1662 | - {
|
|
| 1663 | - $this->error=$this->db->lasterror(); |
|
| 1664 | - return -2; |
|
| 1665 | - } |
|
| 1666 | - $row = $this->db->fetch_row($result); |
|
| 1667 | - $this->ref_next = $row[0]; |
|
| 1668 | - |
|
| 1669 | - return 1; |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - |
|
| 1673 | - /** |
|
| 1674 | - * Return list of id of contacts of object |
|
| 1675 | - * |
|
| 1676 | - * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) |
|
| 1677 | - * @return array Array of id of contacts (if source=external or internal) |
|
| 1678 | - * Array of id of third parties with at least one contact on object (if source=thirdparty) |
|
| 1679 | - */ |
|
| 1680 | - function getListContactId($source='external') |
|
| 1681 | - {
|
|
| 1682 | - $contactAlreadySelected = array(); |
|
| 1683 | - $tab = $this->liste_contact(-1,$source); |
|
| 1684 | - $num=count($tab); |
|
| 1685 | - $i = 0; |
|
| 1686 | - while ($i < $num) |
|
| 1687 | - {
|
|
| 1688 | - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1689 | - else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1690 | - $i++; |
|
| 1691 | - } |
|
| 1692 | - return $contactAlreadySelected; |
|
| 1693 | - } |
|
| 1694 | - |
|
| 1695 | - |
|
| 1696 | - /** |
|
| 1697 | - * Link element with a project |
|
| 1698 | - * |
|
| 1699 | - * @param int $projectid Project id to link element to |
|
| 1700 | - * @return int <0 if KO, >0 if OK |
|
| 1701 | - */ |
|
| 1702 | - function setProject($projectid) |
|
| 1703 | - {
|
|
| 1704 | - if (! $this->table_element) |
|
| 1705 | - {
|
|
| 1706 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1707 | - return -1; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1711 | - if ($this->table_element == 'actioncomm') |
|
| 1712 | - {
|
|
| 1713 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1714 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1715 | - $sql.= ' WHERE id = '.$this->id; |
|
| 1716 | - } |
|
| 1717 | - else |
|
| 1718 | - {
|
|
| 1719 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1720 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1721 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 1722 | - } |
|
| 1723 | - |
|
| 1724 | - dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
| 1725 | - if ($this->db->query($sql)) |
|
| 1726 | - {
|
|
| 1727 | - $this->fk_project = $projectid; |
|
| 1728 | - return 1; |
|
| 1729 | - } |
|
| 1730 | - else |
|
| 1731 | - {
|
|
| 1732 | - dol_print_error($this->db); |
|
| 1733 | - return -1; |
|
| 1734 | - } |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - /** |
|
| 1738 | - * Change the payments methods |
|
| 1739 | - * |
|
| 1740 | - * @param int $id Id of new payment method |
|
| 1741 | - * @return int >0 if OK, <0 if KO |
|
| 1742 | - */ |
|
| 1743 | - function setPaymentMethods($id) |
|
| 1744 | - {
|
|
| 1745 | - dol_syslog(get_class($this).'::setPaymentMethods('.$id.')');
|
|
| 1746 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1747 | - {
|
|
| 1748 | - // TODO uniformize field name |
|
| 1749 | - $fieldname = 'fk_mode_reglement'; |
|
| 1750 | - if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1751 | - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 1752 | - |
|
| 1753 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1754 | - $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1755 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1756 | - |
|
| 1757 | - if ($this->db->query($sql)) |
|
| 1758 | - {
|
|
| 1759 | - $this->mode_reglement_id = $id; |
|
| 1760 | - // for supplier |
|
| 1761 | - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1762 | - return 1; |
|
| 1763 | - } |
|
| 1764 | - else |
|
| 1765 | - {
|
|
| 1766 | - dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
| 1767 | - $this->error=$this->db->error(); |
|
| 1768 | - return -1; |
|
| 1769 | - } |
|
| 1770 | - } |
|
| 1771 | - else |
|
| 1772 | - {
|
|
| 1773 | - dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
| 1774 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1775 | - return -2; |
|
| 1776 | - } |
|
| 1777 | - } |
|
| 1778 | - |
|
| 1779 | - /** |
|
| 1780 | - * Change the multicurrency code |
|
| 1781 | - * |
|
| 1782 | - * @param string $code multicurrency code |
|
| 1783 | - * @return int >0 if OK, <0 if KO |
|
| 1784 | - */ |
|
| 1785 | - function setMulticurrencyCode($code) |
|
| 1786 | - {
|
|
| 1787 | - dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')');
|
|
| 1788 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1789 | - {
|
|
| 1790 | - $fieldname = 'multicurrency_code'; |
|
| 1791 | - |
|
| 1792 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1793 | - $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
| 1794 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1795 | - |
|
| 1796 | - if ($this->db->query($sql)) |
|
| 1797 | - {
|
|
| 1798 | - $this->multicurrency_code = $code; |
|
| 359 | + /** |
|
| 360 | + * @var string |
|
| 361 | + * @see SetIncoterms() |
|
| 362 | + */ |
|
| 363 | + public $libelle_incoterms; |
|
| 1799 | 364 | |
| 1800 | - list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
|
| 1801 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 365 | + /** |
|
| 366 | + * @var string |
|
| 367 | + * @see display_incoterms() |
|
| 368 | + */ |
|
| 369 | + public $location_incoterms; |
|
| 1802 | 370 | |
| 1803 | - return 1; |
|
| 1804 | - } |
|
| 1805 | - else |
|
| 1806 | - {
|
|
| 1807 | - dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
| 1808 | - $this->error=$this->db->error(); |
|
| 1809 | - return -1; |
|
| 1810 | - } |
|
| 1811 | - } |
|
| 1812 | - else |
|
| 1813 | - {
|
|
| 1814 | - dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
| 1815 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1816 | - return -2; |
|
| 1817 | - } |
|
| 1818 | - } |
|
| 1819 | - |
|
| 1820 | - /** |
|
| 1821 | - * Change the multicurrency rate |
|
| 1822 | - * |
|
| 1823 | - * @param double $rate multicurrency rate |
|
| 1824 | - * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
|
| 1825 | - * @return int >0 if OK, <0 if KO |
|
| 1826 | - */ |
|
| 1827 | - function setMulticurrencyRate($rate, $mode=1) |
|
| 1828 | - {
|
|
| 1829 | - dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')');
|
|
| 1830 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1831 | - {
|
|
| 1832 | - $fieldname = 'multicurrency_tx'; |
|
| 1833 | - |
|
| 1834 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1835 | - $sql .= ' SET '.$fieldname.' = '.$rate; |
|
| 1836 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1837 | - |
|
| 1838 | - if ($this->db->query($sql)) |
|
| 1839 | - {
|
|
| 1840 | - $this->multicurrency_tx = $rate; |
|
| 371 | + public $name; |
|
| 372 | + public $lastname; |
|
| 373 | + public $firstname; |
|
| 374 | + public $civility_id; |
|
| 1841 | 375 | |
| 1842 | - // Update line price |
|
| 1843 | - if (!empty($this->lines)) |
|
| 1844 | - {
|
|
| 1845 | - foreach ($this->lines as &$line) |
|
| 1846 | - {
|
|
| 1847 | - if($mode == 1) {
|
|
| 1848 | - $line->subprice = 0; |
|
| 1849 | - } |
|
| 376 | + // Dates |
|
| 377 | + public $date_creation; // Date creation |
|
| 378 | + public $date_validation; // Date validation |
|
| 379 | + public $date_modification; // Date last change (tms field) |
|
| 1850 | 380 | |
| 1851 | - switch ($this->element) {
|
|
| 1852 | - case 'propal': |
|
| 1853 | - $this->updateline( |
|
| 1854 | - $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1855 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1856 | - $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
|
| 1857 | - $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1858 | - ); |
|
| 1859 | - break; |
|
| 1860 | - case 'commande': |
|
| 1861 | - $this->updateline( |
|
| 1862 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1863 | - $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
|
| 1864 | - $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1865 | - $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1866 | - ); |
|
| 1867 | - break; |
|
| 1868 | - case 'facture': |
|
| 1869 | - $this->updateline( |
|
| 1870 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1871 | - $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
|
| 1872 | - $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1873 | - $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
|
| 1874 | - ); |
|
| 1875 | - break; |
|
| 1876 | - case 'supplier_proposal': |
|
| 1877 | - $this->updateline( |
|
| 1878 | - $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1879 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1880 | - $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
|
| 1881 | - $line->ref_fourn, $line->multicurrency_subprice |
|
| 1882 | - ); |
|
| 1883 | - break; |
|
| 1884 | - case 'order_supplier': |
|
| 1885 | - $this->updateline( |
|
| 1886 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1887 | - $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
|
| 1888 | - $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1889 | - ); |
|
| 1890 | - break; |
|
| 1891 | - case 'invoice_supplier': |
|
| 1892 | - $this->updateline( |
|
| 1893 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1894 | - $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
|
| 1895 | - $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1896 | - ); |
|
| 1897 | - break; |
|
| 1898 | - default: |
|
| 1899 | - dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
| 1900 | - break; |
|
| 1901 | - } |
|
| 1902 | - } |
|
| 1903 | - } |
|
| 1904 | 381 | |
| 1905 | - return 1; |
|
| 1906 | - } |
|
| 1907 | - else |
|
| 1908 | - {
|
|
| 1909 | - dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
| 1910 | - $this->error=$this->db->error(); |
|
| 1911 | - return -1; |
|
| 1912 | - } |
|
| 1913 | - } |
|
| 1914 | - else |
|
| 1915 | - {
|
|
| 1916 | - dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
| 1917 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1918 | - return -2; |
|
| 1919 | - } |
|
| 1920 | - } |
|
| 1921 | - |
|
| 1922 | - /** |
|
| 1923 | - * Change the payments terms |
|
| 1924 | - * |
|
| 1925 | - * @param int $id Id of new payment terms |
|
| 1926 | - * @return int >0 if OK, <0 if KO |
|
| 1927 | - */ |
|
| 1928 | - function setPaymentTerms($id) |
|
| 1929 | - {
|
|
| 1930 | - dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
|
|
| 1931 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1932 | - {
|
|
| 1933 | - // TODO uniformize field name |
|
| 1934 | - $fieldname = 'fk_cond_reglement'; |
|
| 1935 | - if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1936 | - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 1937 | - |
|
| 1938 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1939 | - $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1940 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1941 | - |
|
| 1942 | - if ($this->db->query($sql)) |
|
| 1943 | - {
|
|
| 1944 | - $this->cond_reglement_id = $id; |
|
| 1945 | - // for supplier |
|
| 1946 | - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 1947 | - $this->cond_reglement = $id; // for compatibility |
|
| 1948 | - return 1; |
|
| 1949 | - } |
|
| 1950 | - else |
|
| 1951 | - {
|
|
| 1952 | - dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
| 1953 | - $this->error=$this->db->error(); |
|
| 1954 | - return -1; |
|
| 1955 | - } |
|
| 1956 | - } |
|
| 1957 | - else |
|
| 1958 | - {
|
|
| 1959 | - dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
| 1960 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1961 | - return -2; |
|
| 1962 | - } |
|
| 1963 | - } |
|
| 1964 | - |
|
| 1965 | - /** |
|
| 1966 | - * Define delivery address |
|
| 1967 | - * @deprecated |
|
| 1968 | - * |
|
| 1969 | - * @param int $id Address id |
|
| 1970 | - * @return int <0 si ko, >0 si ok |
|
| 1971 | - */ |
|
| 1972 | - function setDeliveryAddress($id) |
|
| 1973 | - {
|
|
| 1974 | - $fieldname = 'fk_delivery_address'; |
|
| 1975 | - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 1976 | - |
|
| 1977 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
| 1978 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1979 | - |
|
| 1980 | - if ($this->db->query($sql)) |
|
| 1981 | - {
|
|
| 1982 | - $this->fk_delivery_address = $id; |
|
| 1983 | - return 1; |
|
| 1984 | - } |
|
| 1985 | - else |
|
| 1986 | - {
|
|
| 1987 | - $this->error=$this->db->error(); |
|
| 1988 | - dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
| 1989 | - return -1; |
|
| 1990 | - } |
|
| 1991 | - } |
|
| 1992 | - |
|
| 1993 | - |
|
| 1994 | - /** |
|
| 1995 | - * Change the shipping method |
|
| 1996 | - * |
|
| 1997 | - * @param int $shipping_method_id Id of shipping method |
|
| 1998 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 1999 | - * @param User $userused Object user |
|
| 2000 | - * |
|
| 2001 | - * @return int 1 if OK, 0 if KO |
|
| 2002 | - */ |
|
| 2003 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 2004 | - {
|
|
| 2005 | - global $user; |
|
| 2006 | 382 | |
| 2007 | - if (empty($userused)) $userused=$user; |
|
| 383 | + // No constructor as it is an abstract class |
|
| 2008 | 384 | |
| 2009 | - $error = 0; |
|
| 385 | + /** |
|
| 386 | + * Check an object id/ref exists |
|
| 387 | + * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch |
|
| 388 | + * |
|
| 389 | + * @param string $element String of element ('product', 'facture', ...)
|
|
| 390 | + * @param int $id Id of object |
|
| 391 | + * @param string $ref Ref of object to check |
|
| 392 | + * @param string $ref_ext Ref ext of object to check |
|
| 393 | + * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
|
| 394 | + */ |
|
| 395 | + static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 396 | + {
|
|
| 397 | + global $db,$conf; |
|
| 398 | + |
|
| 399 | + $sql = "SELECT rowid, ref, ref_ext"; |
|
| 400 | + $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 401 | + $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
|
| 402 | + |
|
| 403 | + if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 404 | + else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 405 | + else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 406 | + else {
|
|
| 407 | + $error='ErrorWrongParameters'; |
|
| 408 | + dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
| 409 | + return -1; |
|
| 410 | + } |
|
| 411 | + if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 2010 | 412 | |
| 2011 | - if (! $this->table_element) {
|
|
| 2012 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 2013 | - return -1; |
|
| 2014 | - } |
|
| 413 | + dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
| 414 | + $resql = $db->query($sql); |
|
| 415 | + if ($resql) |
|
| 416 | + {
|
|
| 417 | + $num=$db->num_rows($resql); |
|
| 418 | + if ($num > 0) return 1; |
|
| 419 | + else return 0; |
|
| 420 | + } |
|
| 421 | + return -1; |
|
| 422 | + } |
|
| 2015 | 423 | |
| 2016 | - $this->db->begin(); |
|
| 424 | + /** |
|
| 425 | + * Method to output saved errors |
|
| 426 | + * |
|
| 427 | + * @return string String with errors |
|
| 428 | + */ |
|
| 429 | + function errorsToString() |
|
| 430 | + {
|
|
| 431 | + return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):'');
|
|
| 432 | + } |
|
| 2017 | 433 | |
| 2018 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2019 | - dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
|
| 434 | + /** |
|
| 435 | + * Return full name (civility+' '+name+' '+lastname) |
|
| 436 | + * |
|
| 437 | + * @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
| 438 | + * @param int $option 0=No option, 1=Add civility |
|
| 439 | + * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname |
|
| 440 | + * @param int $maxlen Maximum length |
|
| 441 | + * @return string String with full name |
|
| 442 | + */ |
|
| 443 | + function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 444 | + {
|
|
| 445 | + //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
| 446 | + $lastname=$this->lastname; |
|
| 447 | + $firstname=$this->firstname; |
|
| 448 | + 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:''))))); |
|
| 2020 | 449 | |
| 2021 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2022 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2023 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2024 | - $resql = $this->db->query($sql); |
|
| 2025 | - if (! $resql) {
|
|
| 2026 | - dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
| 2027 | - $this->error = $this->db->lasterror(); |
|
| 2028 | - $error++; |
|
| 2029 | - } else {
|
|
| 2030 | - if (!$notrigger) |
|
| 2031 | - {
|
|
| 2032 | - // Call trigger |
|
| 2033 | - $this->context=array('shippingmethodupdate'=>1);
|
|
| 2034 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2035 | - if ($result < 0) $error++; |
|
| 2036 | - // End call trigger |
|
| 2037 | - } |
|
| 450 | + $ret=''; |
|
| 451 | + if ($option && $this->civility_id) |
|
| 452 | + {
|
|
| 453 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 454 | + else $ret.=$this->civility_id.' '; |
|
| 2038 | 455 | } |
| 2039 | - if ($error) |
|
| 456 | + |
|
| 457 | + $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 458 | + |
|
| 459 | + return dol_trunc($ret,$maxlen); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Return full address of contact |
|
| 464 | + * |
|
| 465 | + * @param int $withcountry 1=Add country into address string |
|
| 466 | + * @param string $sep Separator to use to build string |
|
| 467 | + * @param int $withregion 1=Add region into address string |
|
| 468 | + * @return string Full address string |
|
| 469 | + */ |
|
| 470 | + function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
| 471 | + {
|
|
| 472 | + if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
|
| 2040 | 473 | {
|
| 2041 | - $this->db->rollback(); |
|
| 2042 | - return -1; |
|
| 2043 | - } else {
|
|
| 2044 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 2045 | - $this->db->commit(); |
|
| 2046 | - return 1; |
|
| 474 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 475 | + $tmparray=getCountry($this->country_id,'all'); |
|
| 476 | + $this->country_code=$tmparray['code']; |
|
| 477 | + $this->country =$tmparray['label']; |
|
| 2047 | 478 | } |
| 2048 | - } |
|
| 2049 | - |
|
| 2050 | - |
|
| 2051 | - /** |
|
| 2052 | - * Change the warehouse |
|
| 2053 | - * |
|
| 2054 | - * @param int $warehouse_id Id of warehouse |
|
| 2055 | - * @return int 1 if OK, 0 if KO |
|
| 2056 | - */ |
|
| 2057 | - function setWarehouse($warehouse_id) |
|
| 2058 | - {
|
|
| 2059 | - if (! $this->table_element) {
|
|
| 2060 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 2061 | - return -1; |
|
| 2062 | - } |
|
| 2063 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2064 | - dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
|
| 2065 | - |
|
| 2066 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2067 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 2068 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2069 | - |
|
| 2070 | - if ($this->db->query($sql)) {
|
|
| 2071 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 2072 | - return 1; |
|
| 2073 | - } else {
|
|
| 2074 | - dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
| 2075 | - $this->error=$this->db->error(); |
|
| 2076 | - return 0; |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - |
|
| 2080 | - |
|
| 2081 | - /** |
|
| 2082 | - * Set last model used by doc generator |
|
| 2083 | - * |
|
| 2084 | - * @param User $user User object that make change |
|
| 2085 | - * @param string $modelpdf Modele name |
|
| 2086 | - * @return int <0 if KO, >0 if OK |
|
| 2087 | - */ |
|
| 2088 | - function setDocModel($user, $modelpdf) |
|
| 2089 | - {
|
|
| 2090 | - if (! $this->table_element) |
|
| 2091 | - {
|
|
| 2092 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 2093 | - return -1; |
|
| 2094 | - } |
|
| 2095 | - |
|
| 2096 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 2097 | - |
|
| 2098 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2099 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2100 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 2101 | - // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
|
| 2102 | - // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
|
| 2103 | - |
|
| 2104 | - dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
| 2105 | - $resql=$this->db->query($sql); |
|
| 2106 | - if ($resql) |
|
| 2107 | - {
|
|
| 2108 | - $this->modelpdf=$modelpdf; |
|
| 2109 | - return 1; |
|
| 2110 | - } |
|
| 2111 | - else |
|
| 2112 | - {
|
|
| 2113 | - dol_print_error($this->db); |
|
| 2114 | - return 0; |
|
| 2115 | - } |
|
| 2116 | - } |
|
| 2117 | - |
|
| 2118 | - |
|
| 2119 | - /** |
|
| 2120 | - * Change the bank account |
|
| 2121 | - * |
|
| 2122 | - * @param int $fk_account Id of bank account |
|
| 2123 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 2124 | - * @param User $userused Object user |
|
| 2125 | - * @return int 1 if OK, 0 if KO |
|
| 2126 | - */ |
|
| 2127 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 2128 | - {
|
|
| 2129 | - global $user; |
|
| 2130 | 479 | |
| 2131 | - if (empty($userused)) $userused=$user; |
|
| 480 | + if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
|
| 481 | + {
|
|
| 482 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 483 | + $tmparray=getState($this->state_id,'all',0,1); |
|
| 484 | + $this->state_code =$tmparray['code']; |
|
| 485 | + $this->state =$tmparray['label']; |
|
| 486 | + $this->region_code =$tmparray['region_code']; |
|
| 487 | + $this->region =$tmparray['region']; |
|
| 488 | + } |
|
| 2132 | 489 | |
| 2133 | - $error = 0; |
|
| 490 | + return dol_format_address($this, $withcountry, $sep); |
|
| 491 | + } |
|
| 2134 | 492 | |
| 2135 | - if (! $this->table_element) {
|
|
| 2136 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 2137 | - return -1; |
|
| 2138 | - } |
|
| 2139 | - $this->db->begin(); |
|
| 2140 | 493 | |
| 2141 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2142 | - dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
|
| 494 | + /** |
|
| 495 | + * Return full address for banner |
|
| 496 | + * |
|
| 497 | + * @param string $htmlkey HTML id to make banner content unique |
|
| 498 | + * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
| 499 | + * @return string Full address string |
|
| 500 | + */ |
|
| 501 | + function getBannerAddress($htmlkey, $object) |
|
| 502 | + {
|
|
| 503 | + global $conf, $langs; |
|
| 2143 | 504 | |
| 2144 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2145 | - $sql.= " SET fk_account = ".$fk_account; |
|
| 2146 | - $sql.= " WHERE rowid=".$this->id; |
|
| 505 | + $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
|
|
| 2147 | 506 | |
| 2148 | - $resql = $this->db->query($sql); |
|
| 2149 | - if (! $resql) |
|
| 507 | + $contactid=0; |
|
| 508 | + $thirdpartyid=0; |
|
| 509 | + if ($this->element == 'societe') |
|
| 2150 | 510 | {
|
| 2151 | - dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
| 2152 | - $this->error = $this->db->lasterror(); |
|
| 2153 | - $error++; |
|
| 511 | + $thirdpartyid=$this->id; |
|
| 2154 | 512 | } |
| 2155 | - else |
|
| 513 | + if ($this->element == 'contact') |
|
| 2156 | 514 | {
|
| 2157 | - if (!$notrigger) |
|
| 515 | + $contactid=$this->id; |
|
| 516 | + $thirdpartyid=$object->fk_soc; |
|
| 517 | + } |
|
| 518 | + if ($this->element == 'user') |
|
| 519 | + {
|
|
| 520 | + $contactid=$this->contact_id; |
|
| 521 | + $thirdpartyid=$object->fk_soc; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $out='<!-- BEGIN part to show address block -->'; |
|
| 525 | + |
|
| 526 | + $outdone=0; |
|
| 527 | + $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 528 | + if ($coords) |
|
| 529 | + {
|
|
| 530 | + if (! empty($conf->use_javascript_ajax)) |
|
| 2158 | 531 | {
|
| 2159 | - // Call trigger |
|
| 2160 | - $this->context=array('bankaccountupdate'=>1);
|
|
| 2161 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2162 | - if ($result < 0) $error++; |
|
| 2163 | - // End call trigger |
|
| 532 | + $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 533 | + // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
| 534 | + $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
|
|
| 535 | + $out.=img_picto($langs->trans("Address"), 'object_address.png');
|
|
| 536 | + $out.='</a> '; |
|
| 2164 | 537 | } |
| 538 | + $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 539 | + $outdone++; |
|
| 2165 | 540 | } |
| 2166 | - if ($error) |
|
| 541 | + |
|
| 542 | + 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 |
|
| 543 | + && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
|
| 2167 | 544 | {
|
| 2168 | - $this->db->rollback(); |
|
| 2169 | - return -1; |
|
| 545 | + if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
|
|
| 546 | + $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
| 547 | + } |
|
| 548 | + else {
|
|
| 549 | + $out.=($outdone?' - ':'').$this->state; |
|
| 550 | + } |
|
| 551 | + $outdone++; |
|
| 2170 | 552 | } |
| 2171 | - else |
|
| 553 | + |
|
| 554 | + 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>':''); |
|
| 555 | + if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
|
|
| 556 | + $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 557 | + } |
|
| 558 | + if (! empty($this->phone_pro)) {
|
|
| 559 | + $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 560 | + } |
|
| 561 | + if (! empty($this->phone_mobile)) {
|
|
| 562 | + $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++;
|
|
| 563 | + } |
|
| 564 | + if (! empty($this->phone_perso)) {
|
|
| 565 | + $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++;
|
|
| 566 | + } |
|
| 567 | + if (! empty($this->office_phone)) {
|
|
| 568 | + $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 569 | + } |
|
| 570 | + if (! empty($this->user_mobile)) {
|
|
| 571 | + $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++;
|
|
| 572 | + } |
|
| 573 | + if (! empty($this->fax)) {
|
|
| 574 | + $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++;
|
|
| 575 | + } |
|
| 576 | + if (! empty($this->office_fax)) {
|
|
| 577 | + $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++;
|
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + $out.='<div style="clear: both;"></div>'; |
|
| 581 | + $outdone=0; |
|
| 582 | + if (! empty($this->email)) |
|
| 2172 | 583 | {
|
| 2173 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 2174 | - $this->db->commit(); |
|
| 2175 | - return 1; |
|
| 584 | + $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
| 585 | + $outdone++; |
|
| 586 | + } |
|
| 587 | + if (! empty($this->url)) |
|
| 588 | + {
|
|
| 589 | + $out.=dol_print_url($this->url,'_goout',0,1); |
|
| 590 | + $outdone++; |
|
| 591 | + } |
|
| 592 | + $out.='<div style="clear: both;">'; |
|
| 593 | + if (! empty($conf->socialnetworks->enabled)) |
|
| 594 | + {
|
|
| 595 | + if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 596 | + $outdone++; |
|
| 597 | + if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 598 | + $outdone++; |
|
| 599 | + if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 600 | + $outdone++; |
|
| 601 | + if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 602 | + $outdone++; |
|
| 2176 | 603 | } |
| 604 | + $out.='</div>'; |
|
| 605 | + |
|
| 606 | + $out.='<!-- END Part to show address block -->'; |
|
| 607 | + |
|
| 608 | + return $out; |
|
| 2177 | 609 | } |
| 2178 | 610 | |
| 611 | + /** |
|
| 612 | + * Return the link of last main doc file for direct public download. |
|
| 613 | + * |
|
| 614 | + * @param string $modulepart Module related to document |
|
| 615 | + * @param int $initsharekey Init the share key if it was not yet defined |
|
| 616 | + * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
|
| 617 | + * @return string Link or empty string if there is no download link |
|
| 618 | + */ |
|
| 619 | + function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 620 | + {
|
|
| 621 | + global $user, $dolibarr_main_url_root; |
|
| 2179 | 622 | |
| 2180 | - // TODO: Move line related operations to CommonObjectLine? |
|
| 623 | + if (empty($this->last_main_doc)) |
|
| 624 | + {
|
|
| 625 | + return ''; // No way to known which document name to use |
|
| 626 | + } |
|
| 2181 | 627 | |
| 2182 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2183 | - /** |
|
| 2184 | - * Save a new position (field rang) for details lines. |
|
| 2185 | - * You can choose to set position for lines with already a position or lines without any position defined. |
|
| 2186 | - * |
|
| 2187 | - * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. |
|
| 2188 | - * @param string $rowidorder ASC or DESC |
|
| 2189 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2190 | - * @return int <0 if KO, >0 if OK |
|
| 2191 | - */ |
|
| 2192 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2193 | - {
|
|
| 2194 | - // phpcs:enable |
|
| 2195 | - if (! $this->table_element_line) |
|
| 2196 | - {
|
|
| 2197 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2198 | - return -1; |
|
| 2199 | - } |
|
| 2200 | - if (! $this->fk_element) |
|
| 2201 | - {
|
|
| 2202 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2203 | - return -1; |
|
| 2204 | - } |
|
| 2205 | - |
|
| 2206 | - // Count number of lines to reorder (according to choice $renum) |
|
| 2207 | - $nl=0; |
|
| 2208 | - $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2209 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2210 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2211 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2212 | - |
|
| 2213 | - dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
| 2214 | - $resql = $this->db->query($sql); |
|
| 2215 | - if ($resql) |
|
| 2216 | - {
|
|
| 2217 | - $row = $this->db->fetch_row($resql); |
|
| 2218 | - $nl = $row[0]; |
|
| 2219 | - } |
|
| 2220 | - else dol_print_error($this->db); |
|
| 2221 | - if ($nl > 0) |
|
| 2222 | - {
|
|
| 2223 | - // The goal of this part is to reorder all lines, with all children lines sharing the same |
|
| 2224 | - // counter that parents. |
|
| 2225 | - $rows=array(); |
|
| 2226 | - |
|
| 2227 | - // We first search all lines that are parent lines (for multilevel details lines) |
|
| 2228 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2229 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2230 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2231 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2232 | - |
|
| 2233 | - dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
| 2234 | - $resql = $this->db->query($sql); |
|
| 2235 | - if ($resql) |
|
| 2236 | - {
|
|
| 2237 | - $i=0; |
|
| 2238 | - $num = $this->db->num_rows($resql); |
|
| 2239 | - while ($i < $num) |
|
| 2240 | - {
|
|
| 2241 | - $row = $this->db->fetch_row($resql); |
|
| 2242 | - $rows[] = $row[0]; // Add parent line into array rows |
|
| 2243 | - $childrens = $this->getChildrenOfLine($row[0]); |
|
| 2244 | - if (! empty($childrens)) |
|
| 2245 | - {
|
|
| 2246 | - foreach($childrens as $child) |
|
| 2247 | - {
|
|
| 2248 | - array_push($rows, $child); |
|
| 2249 | - } |
|
| 2250 | - } |
|
| 2251 | - $i++; |
|
| 2252 | - } |
|
| 628 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 629 | + $ecmfile=new EcmFiles($this->db); |
|
| 630 | + $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
|
| 631 | + if ($result < 0) |
|
| 632 | + {
|
|
| 633 | + $this->error = $ecmfile->error; |
|
| 634 | + $this->errors = $ecmfile->errors; |
|
| 635 | + return -1; |
|
| 636 | + } |
|
| 2253 | 637 | |
| 2254 | - // Now we set a new number for each lines (parent and children with children included into parent tree) |
|
| 2255 | - if (! empty($rows)) |
|
| 638 | + if (empty($ecmfile->id)) |
|
| 639 | + {
|
|
| 640 | + // Add entry into index |
|
| 641 | + if ($initsharekey) |
|
| 642 | + {
|
|
| 643 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 644 | + // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
|
| 645 | + /* |
|
| 646 | + $ecmfile->filepath = $rel_dir; |
|
| 647 | + $ecmfile->filename = $filename; |
|
| 648 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 649 | + $ecmfile->fullpath_orig = ''; |
|
| 650 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
| 651 | + $ecmfile->description = ''; // indexed content |
|
| 652 | + $ecmfile->keyword = ''; // keyword content |
|
| 653 | + $ecmfile->share = getRandomPassword(true); |
|
| 654 | + $result = $ecmfile->create($user); |
|
| 655 | + if ($result < 0) |
|
| 2256 | 656 | {
|
| 2257 | - foreach($rows as $key => $row) |
|
| 2258 | - {
|
|
| 2259 | - $this->updateRangOfLine($row, ($key+1)); |
|
| 2260 | - } |
|
| 657 | + $this->error = $ecmfile->error; |
|
| 658 | + $this->errors = $ecmfile->errors; |
|
| 2261 | 659 | } |
| 2262 | - } |
|
| 2263 | - else |
|
| 2264 | - {
|
|
| 2265 | - dol_print_error($this->db); |
|
| 2266 | - } |
|
| 2267 | - } |
|
| 2268 | - return 1; |
|
| 2269 | - } |
|
| 2270 | - |
|
| 2271 | - /** |
|
| 2272 | - * Get children of line |
|
| 2273 | - * |
|
| 2274 | - * @param int $id Id of parent line |
|
| 2275 | - * @return array Array with list of children lines id |
|
| 2276 | - */ |
|
| 2277 | - function getChildrenOfLine($id) |
|
| 2278 | - {
|
|
| 2279 | - $rows=array(); |
|
| 2280 | - |
|
| 2281 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2282 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2283 | - $sql.= ' AND fk_parent_line = '.$id; |
|
| 2284 | - $sql.= ' ORDER BY rang ASC'; |
|
| 2285 | - |
|
| 2286 | - dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
| 2287 | - $resql = $this->db->query($sql); |
|
| 2288 | - if ($resql) |
|
| 2289 | - {
|
|
| 2290 | - $i=0; |
|
| 2291 | - $num = $this->db->num_rows($resql); |
|
| 2292 | - while ($i < $num) |
|
| 2293 | - {
|
|
| 2294 | - $row = $this->db->fetch_row($resql); |
|
| 2295 | - $rows[$i] = $row[0]; |
|
| 2296 | - $i++; |
|
| 2297 | - } |
|
| 2298 | - } |
|
| 660 | + */ |
|
| 661 | + } |
|
| 662 | + else return ''; |
|
| 663 | + } |
|
| 664 | + elseif (empty($ecmfile->share)) |
|
| 665 | + {
|
|
| 666 | + // Add entry into index |
|
| 667 | + if ($initsharekey) |
|
| 668 | + {
|
|
| 669 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 670 | + $ecmfile->share = getRandomPassword(true); |
|
| 671 | + $ecmfile->update($user); |
|
| 672 | + } |
|
| 673 | + else return ''; |
|
| 674 | + } |
|
| 2299 | 675 | |
| 2300 | - return $rows; |
|
| 2301 | - } |
|
| 676 | + // Define $urlwithroot |
|
| 677 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
|
|
| 678 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 679 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 2302 | 680 | |
| 2303 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2304 | - /** |
|
| 2305 | - * Update a line to have a lower rank |
|
| 2306 | - * |
|
| 2307 | - * @param int $rowid Id of line |
|
| 2308 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2309 | - * @return void |
|
| 2310 | - */ |
|
| 2311 | - function line_up($rowid, $fk_parent_line=true) |
|
| 2312 | - {
|
|
| 2313 | - // phpcs:enable |
|
| 2314 | - $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 681 | + $forcedownload=0; |
|
| 2315 | 682 | |
| 2316 | - // Get rang of line |
|
| 2317 | - $rang = $this->getRangOfLine($rowid); |
|
| 683 | + $paramlink=''; |
|
| 684 | + //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
|
| 685 | + //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
|
| 686 | + //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
|
| 687 | + if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 688 | + if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 2318 | 689 | |
| 2319 | - // Update position of line |
|
| 2320 | - $this->updateLineUp($rowid, $rang); |
|
| 2321 | - } |
|
| 690 | + if ($relativelink) |
|
| 691 | + {
|
|
| 692 | + $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 693 | + } |
|
| 694 | + else |
|
| 695 | + {
|
|
| 696 | + $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 697 | + } |
|
| 2322 | 698 | |
| 2323 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2324 | - /** |
|
| 2325 | - * Update a line to have a higher rank |
|
| 2326 | - * |
|
| 2327 | - * @param int $rowid Id of line |
|
| 2328 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2329 | - * @return void |
|
| 2330 | - */ |
|
| 2331 | - function line_down($rowid, $fk_parent_line=true) |
|
| 2332 | - {
|
|
| 2333 | - // phpcs:enable |
|
| 2334 | - $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 2335 | - |
|
| 2336 | - // Get rang of line |
|
| 2337 | - $rang = $this->getRangOfLine($rowid); |
|
| 2338 | - |
|
| 2339 | - // Get max value for rang |
|
| 2340 | - $max = $this->line_max(); |
|
| 2341 | - |
|
| 2342 | - // Update position of line |
|
| 2343 | - $this->updateLineDown($rowid, $rang, $max); |
|
| 2344 | - } |
|
| 2345 | - |
|
| 2346 | - /** |
|
| 2347 | - * Update position of line (rang) |
|
| 2348 | - * |
|
| 2349 | - * @param int $rowid Id of line |
|
| 2350 | - * @param int $rang Position |
|
| 2351 | - * @return void |
|
| 2352 | - */ |
|
| 2353 | - function updateRangOfLine($rowid,$rang) |
|
| 2354 | - {
|
|
| 2355 | - $fieldposition = 'rang'; |
|
| 2356 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2357 | - |
|
| 2358 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2359 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2360 | - |
|
| 2361 | - dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
| 2362 | - if (! $this->db->query($sql)) |
|
| 2363 | - {
|
|
| 2364 | - dol_print_error($this->db); |
|
| 2365 | - } |
|
| 2366 | - } |
|
| 699 | + // Here $ecmfile->share is defined |
|
| 700 | + return $linktoreturn; |
|
| 701 | + } |
|
| 2367 | 702 | |
| 2368 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2369 | - /** |
|
| 2370 | - * Update position of line with ajax (rang) |
|
| 2371 | - * |
|
| 2372 | - * @param array $rows Array of rows |
|
| 2373 | - * @return void |
|
| 2374 | - */ |
|
| 2375 | - function line_ajaxorder($rows) |
|
| 2376 | - {
|
|
| 2377 | - // phpcs:enable |
|
| 2378 | - $num = count($rows); |
|
| 2379 | - for ($i = 0 ; $i < $num ; $i++) |
|
| 2380 | - {
|
|
| 2381 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2382 | - } |
|
| 2383 | - } |
|
| 2384 | - |
|
| 2385 | - /** |
|
| 2386 | - * Update position of line up (rang) |
|
| 2387 | - * |
|
| 2388 | - * @param int $rowid Id of line |
|
| 2389 | - * @param int $rang Position |
|
| 2390 | - * @return void |
|
| 2391 | - */ |
|
| 2392 | - function updateLineUp($rowid,$rang) |
|
| 2393 | - {
|
|
| 2394 | - if ($rang > 1) |
|
| 2395 | - {
|
|
| 2396 | - $fieldposition = 'rang'; |
|
| 2397 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2398 | - |
|
| 2399 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
| 2400 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2401 | - $sql.= ' AND rang = '.($rang - 1); |
|
| 2402 | - if ($this->db->query($sql) ) |
|
| 2403 | - {
|
|
| 2404 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
| 2405 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2406 | - if (! $this->db->query($sql) ) |
|
| 2407 | - {
|
|
| 2408 | - dol_print_error($this->db); |
|
| 2409 | - } |
|
| 2410 | - } |
|
| 2411 | - else |
|
| 2412 | - {
|
|
| 2413 | - dol_print_error($this->db); |
|
| 2414 | - } |
|
| 2415 | - } |
|
| 2416 | - } |
|
| 2417 | - |
|
| 2418 | - /** |
|
| 2419 | - * Update position of line down (rang) |
|
| 2420 | - * |
|
| 2421 | - * @param int $rowid Id of line |
|
| 2422 | - * @param int $rang Position |
|
| 2423 | - * @param int $max Max |
|
| 2424 | - * @return void |
|
| 2425 | - */ |
|
| 2426 | - function updateLineDown($rowid,$rang,$max) |
|
| 2427 | - {
|
|
| 2428 | - if ($rang < $max) |
|
| 2429 | - {
|
|
| 2430 | - $fieldposition = 'rang'; |
|
| 2431 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2432 | - |
|
| 2433 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2434 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2435 | - $sql.= ' AND rang = '.($rang+1); |
|
| 2436 | - if ($this->db->query($sql) ) |
|
| 2437 | - {
|
|
| 2438 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
| 2439 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2440 | - if (! $this->db->query($sql) ) |
|
| 2441 | - {
|
|
| 2442 | - dol_print_error($this->db); |
|
| 2443 | - } |
|
| 2444 | - } |
|
| 2445 | - else |
|
| 2446 | - {
|
|
| 2447 | - dol_print_error($this->db); |
|
| 2448 | - } |
|
| 2449 | - } |
|
| 2450 | - } |
|
| 2451 | - |
|
| 2452 | - /** |
|
| 2453 | - * Get position of line (rang) |
|
| 2454 | - * |
|
| 2455 | - * @param int $rowid Id of line |
|
| 2456 | - * @return int Value of rang in table of lines |
|
| 2457 | - */ |
|
| 2458 | - function getRangOfLine($rowid) |
|
| 2459 | - {
|
|
| 2460 | - $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2461 | - $sql.= ' WHERE rowid ='.$rowid; |
|
| 2462 | - |
|
| 2463 | - dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
| 2464 | - $resql = $this->db->query($sql); |
|
| 2465 | - if ($resql) |
|
| 2466 | - {
|
|
| 2467 | - $row = $this->db->fetch_row($resql); |
|
| 2468 | - return $row[0]; |
|
| 2469 | - } |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - /** |
|
| 2473 | - * Get rowid of the line relative to its position |
|
| 2474 | - * |
|
| 2475 | - * @param int $rang Rang value |
|
| 2476 | - * @return int Rowid of the line |
|
| 2477 | - */ |
|
| 2478 | - function getIdOfLine($rang) |
|
| 2479 | - {
|
|
| 2480 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2481 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2482 | - $sql.= ' AND rang = '.$rang; |
|
| 2483 | - $resql = $this->db->query($sql); |
|
| 2484 | - if ($resql) |
|
| 2485 | - {
|
|
| 2486 | - $row = $this->db->fetch_row($resql); |
|
| 2487 | - return $row[0]; |
|
| 2488 | - } |
|
| 2489 | - } |
|
| 2490 | 703 | |
| 2491 | 704 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 2492 | - /** |
|
| 2493 | - * Get max value used for position of line (rang) |
|
| 2494 | - * |
|
| 2495 | - * @param int $fk_parent_line Parent line id |
|
| 2496 | - * @return int Max value of rang in table of lines |
|
| 2497 | - */ |
|
| 2498 | - function line_max($fk_parent_line=0) |
|
| 2499 | - {
|
|
| 705 | + /** |
|
| 706 | + * Add a link between element $this->element and a contact |
|
| 707 | + * |
|
| 708 | + * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link |
|
| 709 | + * @param int $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL |
|
| 710 | + * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) |
|
| 711 | + * @param int $notrigger Disable all triggers |
|
| 712 | + * @return int <0 if KO, >0 if OK |
|
| 713 | + */ |
|
| 714 | + function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 715 | + {
|
|
| 2500 | 716 | // phpcs:enable |
| 2501 | - // Search the last rang with fk_parent_line |
|
| 2502 | - if ($fk_parent_line) |
|
| 2503 | - {
|
|
| 2504 | - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2505 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2506 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2507 | - |
|
| 2508 | - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2509 | - $resql = $this->db->query($sql); |
|
| 2510 | - if ($resql) |
|
| 2511 | - {
|
|
| 2512 | - $row = $this->db->fetch_row($resql); |
|
| 2513 | - if (! empty($row[0])) |
|
| 2514 | - {
|
|
| 2515 | - return $row[0]; |
|
| 2516 | - } |
|
| 2517 | - else |
|
| 2518 | - {
|
|
| 2519 | - return $this->getRangOfLine($fk_parent_line); |
|
| 2520 | - } |
|
| 2521 | - } |
|
| 2522 | - } |
|
| 2523 | - // If not, search the last rang of element |
|
| 2524 | - else |
|
| 2525 | - {
|
|
| 2526 | - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2527 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2528 | - |
|
| 2529 | - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2530 | - $resql = $this->db->query($sql); |
|
| 2531 | - if ($resql) |
|
| 2532 | - {
|
|
| 2533 | - $row = $this->db->fetch_row($resql); |
|
| 2534 | - return $row[0]; |
|
| 2535 | - } |
|
| 2536 | - } |
|
| 2537 | - } |
|
| 717 | + global $user,$langs; |
|
| 2538 | 718 | |
| 2539 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2540 | - /** |
|
| 2541 | - * Update external ref of element |
|
| 2542 | - * |
|
| 2543 | - * @param string $ref_ext Update field ref_ext |
|
| 2544 | - * @return int <0 if KO, >0 if OK |
|
| 2545 | - */ |
|
| 2546 | - function update_ref_ext($ref_ext) |
|
| 2547 | - {
|
|
| 2548 | - // phpcs:enable |
|
| 2549 | - if (! $this->table_element) |
|
| 2550 | - {
|
|
| 2551 | - dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
| 2552 | - return -1; |
|
| 2553 | - } |
|
| 2554 | - |
|
| 2555 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2556 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2557 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2558 | - |
|
| 2559 | - dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
| 2560 | - if ($this->db->query($sql)) |
|
| 2561 | - {
|
|
| 2562 | - $this->ref_ext = $ref_ext; |
|
| 2563 | - return 1; |
|
| 2564 | - } |
|
| 2565 | - else |
|
| 2566 | - {
|
|
| 2567 | - $this->error=$this->db->error(); |
|
| 2568 | - return -1; |
|
| 2569 | - } |
|
| 2570 | - } |
|
| 2571 | 719 | |
| 2572 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2573 | - /** |
|
| 2574 | - * Update note of element |
|
| 2575 | - * |
|
| 2576 | - * @param string $note New value for note |
|
| 2577 | - * @param string $suffix '', '_public' or '_private' |
|
| 2578 | - * @return int <0 if KO, >0 if OK |
|
| 2579 | - */ |
|
| 2580 | - function update_note($note, $suffix='') |
|
| 2581 | - {
|
|
| 2582 | - // phpcs:enable |
|
| 2583 | - global $user; |
|
| 2584 | - |
|
| 2585 | - if (! $this->table_element) |
|
| 2586 | - {
|
|
| 2587 | - $this->error='update_note was called on objet with property table_element not defined'; |
|
| 2588 | - dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
| 2589 | - return -1; |
|
| 2590 | - } |
|
| 2591 | - if (! in_array($suffix,array('','_public','_private')))
|
|
| 2592 | - {
|
|
| 2593 | - $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2594 | - dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
| 2595 | - return -2; |
|
| 2596 | - } |
|
| 2597 | - // Special cas |
|
| 2598 | - //var_dump($this->table_element);exit; |
|
| 2599 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2600 | - |
|
| 2601 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2602 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
|
| 2603 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id;
|
|
| 2604 | - $sql.= " WHERE rowid =". $this->id; |
|
| 2605 | - |
|
| 2606 | - dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
| 2607 | - if ($this->db->query($sql)) |
|
| 2608 | - {
|
|
| 2609 | - if ($suffix == '_public') $this->note_public = $note; |
|
| 2610 | - else if ($suffix == '_private') $this->note_private = $note; |
|
| 2611 | - else |
|
| 2612 | - {
|
|
| 2613 | - $this->note = $note; // deprecated |
|
| 2614 | - $this->note_private = $note; |
|
| 2615 | - } |
|
| 2616 | - return 1; |
|
| 2617 | - } |
|
| 2618 | - else |
|
| 2619 | - {
|
|
| 2620 | - $this->error=$this->db->lasterror(); |
|
| 2621 | - return -1; |
|
| 2622 | - } |
|
| 2623 | - } |
|
| 720 | + dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
| 2624 | 721 | |
| 2625 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2626 | - /** |
|
| 2627 | - * Update public note (kept for backward compatibility) |
|
| 2628 | - * |
|
| 2629 | - * @param string $note New value for note |
|
| 2630 | - * @return int <0 if KO, >0 if OK |
|
| 2631 | - * @deprecated |
|
| 2632 | - * @see update_note() |
|
| 2633 | - */ |
|
| 2634 | - function update_note_public($note) |
|
| 2635 | - {
|
|
| 2636 | - // phpcs:enable |
|
| 2637 | - return $this->update_note($note,'_public'); |
|
| 2638 | - } |
|
| 722 | + // Check parameters |
|
| 723 | + if ($fk_socpeople <= 0) |
|
| 724 | + {
|
|
| 725 | + $langs->load("errors");
|
|
| 726 | + $this->error=$langs->trans("ErrorWrongValueForParameterX","1");
|
|
| 727 | + dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 728 | + return -1; |
|
| 729 | + } |
|
| 730 | + if (! $type_contact) |
|
| 731 | + {
|
|
| 732 | + $langs->load("errors");
|
|
| 733 | + $this->error=$langs->trans("ErrorWrongValueForParameterX","2");
|
|
| 734 | + dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 735 | + return -2; |
|
| 736 | + } |
|
| 2639 | 737 | |
| 2640 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2641 | - /** |
|
| 2642 | - * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). |
|
| 2643 | - * Must be called at end of methods addline or updateline. |
|
| 2644 | - * |
|
| 2645 | - * @param int $exclspec >0 = Exclude special product (product_type=9) |
|
| 2646 | - * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode total of rounding, '1'=Force mode rounding of total |
|
| 2647 | - * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. |
|
| 2648 | - * @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. |
|
| 2649 | - * @return int <0 if KO, >0 if OK |
|
| 2650 | - */ |
|
| 2651 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2652 | - {
|
|
| 2653 | - // phpcs:enable |
|
| 2654 | - global $conf, $hookmanager, $action; |
|
| 2655 | - |
|
| 2656 | - // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
|
| 2657 | - $MODULE = ""; |
|
| 2658 | - if ($this->element == 'propal') |
|
| 2659 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2660 | - elseif ($this->element == 'order') |
|
| 2661 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2662 | - elseif ($this->element == 'facture') |
|
| 2663 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2664 | - elseif ($this->element == 'facture_fourn') |
|
| 2665 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2666 | - elseif ($this->element == 'order_supplier') |
|
| 2667 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2668 | - elseif ($this->element == 'supplier_proposal') |
|
| 2669 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2670 | - |
|
| 2671 | - if (! empty($MODULE)) {
|
|
| 2672 | - if (! empty($conf->global->$MODULE)) {
|
|
| 2673 | - $modsactivated = explode(',', $conf->global->$MODULE);
|
|
| 2674 | - foreach ($modsactivated as $mod) {
|
|
| 2675 | - if ($conf->$mod->enabled) |
|
| 2676 | - return 1; // update was disabled by specific setup |
|
| 2677 | - } |
|
| 2678 | - } |
|
| 2679 | - } |
|
| 2680 | - |
|
| 2681 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
| 2682 | - |
|
| 2683 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2684 | - |
|
| 2685 | - $forcedroundingmode=$roundingadjust; |
|
| 2686 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2687 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2688 | - |
|
| 2689 | - $error=0; |
|
| 2690 | - |
|
| 2691 | - $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
|
| 2692 | - |
|
| 2693 | - // Define constants to find lines to sum |
|
| 2694 | - $fieldtva='total_tva'; |
|
| 2695 | - $fieldlocaltax1='total_localtax1'; |
|
| 2696 | - $fieldlocaltax2='total_localtax2'; |
|
| 2697 | - $fieldup='subprice'; |
|
| 2698 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 2699 | - {
|
|
| 2700 | - $fieldtva='tva'; |
|
| 2701 | - $fieldup='pu_ht'; |
|
| 2702 | - } |
|
| 2703 | - if ($this->element == 'expensereport') |
|
| 2704 | - {
|
|
| 2705 | - $fieldup='value_unit'; |
|
| 2706 | - } |
|
| 2707 | - |
|
| 2708 | - $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,'; |
|
| 2709 | - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2710 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2711 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2712 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2713 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2714 | - if ($exclspec) |
|
| 2715 | - {
|
|
| 2716 | - $product_field='product_type'; |
|
| 2717 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2718 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2719 | - } |
|
| 2720 | - $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 |
|
| 2721 | - |
|
| 2722 | - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2723 | - $resql = $this->db->query($sql); |
|
| 2724 | - if ($resql) |
|
| 2725 | - {
|
|
| 2726 | - $this->total_ht = 0; |
|
| 2727 | - $this->total_tva = 0; |
|
| 2728 | - $this->total_localtax1 = 0; |
|
| 2729 | - $this->total_localtax2 = 0; |
|
| 2730 | - $this->total_ttc = 0; |
|
| 2731 | - $total_ht_by_vats = array(); |
|
| 2732 | - $total_tva_by_vats = array(); |
|
| 2733 | - $total_ttc_by_vats = array(); |
|
| 2734 | - $this->multicurrency_total_ht = 0; |
|
| 2735 | - $this->multicurrency_total_tva = 0; |
|
| 2736 | - $this->multicurrency_total_ttc = 0; |
|
| 2737 | - |
|
| 2738 | - $num = $this->db->num_rows($resql); |
|
| 2739 | - $i = 0; |
|
| 2740 | - while ($i < $num) |
|
| 2741 | - {
|
|
| 2742 | - $obj = $this->db->fetch_object($resql); |
|
| 738 | + $id_type_contact=0; |
|
| 739 | + if (is_numeric($type_contact)) |
|
| 740 | + {
|
|
| 741 | + $id_type_contact=$type_contact; |
|
| 742 | + } |
|
| 743 | + else |
|
| 744 | + {
|
|
| 745 | + // We look for id type_contact |
|
| 746 | + $sql = "SELECT tc.rowid"; |
|
| 747 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 748 | + $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 749 | + $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 750 | + $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 751 | + //print $sql; |
|
| 752 | + $resql=$this->db->query($sql); |
|
| 753 | + if ($resql) |
|
| 754 | + {
|
|
| 755 | + $obj = $this->db->fetch_object($resql); |
|
| 756 | + if ($obj) $id_type_contact=$obj->rowid; |
|
| 757 | + } |
|
| 758 | + } |
|
| 2743 | 759 | |
| 2744 | - // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
|
| 2745 | - $parameters=array('fk_element' => $obj->rowid);
|
|
| 2746 | - $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 760 | + if ($id_type_contact == 0) |
|
| 761 | + {
|
|
| 762 | + $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 763 | + dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact."' does not exists or is not active for element ".$this->element.", we can ignore it");
|
|
| 764 | + return -3; |
|
| 765 | + } |
|
| 2747 | 766 | |
| 2748 | - if (empty($reshook) && $forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 2749 | - {
|
|
| 2750 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2751 | - $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); |
|
| 2752 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2753 | - if ($diff) |
|
| 2754 | - {
|
|
| 2755 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2756 | - 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);
|
|
| 2757 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2758 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2759 | - $obj->total_tva = $tmpcal[1]; |
|
| 2760 | - $obj->total_ttc = $tmpcal[2]; |
|
| 2761 | - // |
|
| 2762 | - } |
|
| 2763 | - } |
|
| 767 | + $datecreate = dol_now(); |
|
| 768 | + |
|
| 769 | + // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
|
| 770 | + $TListeContacts=$this->liste_contact(-1, $source); |
|
| 771 | + $already_added=false; |
|
| 772 | + if(!empty($TListeContacts)) {
|
|
| 773 | + foreach($TListeContacts as $array_contact) {
|
|
| 774 | + if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
|
| 775 | + $already_added=true; |
|
| 776 | + break; |
|
| 777 | + } |
|
| 778 | + } |
|
| 779 | + } |
|
| 2764 | 780 | |
| 2765 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2766 | - $this->total_tva += $obj->total_tva; |
|
| 2767 | - $this->total_localtax1 += $obj->total_localtax1; |
|
| 2768 | - $this->total_localtax2 += $obj->total_localtax2; |
|
| 2769 | - $this->total_ttc += $obj->total_ttc; |
|
| 2770 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2771 | - $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
|
| 2772 | - $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
|
| 2773 | - |
|
| 2774 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2775 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2776 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 2777 | - $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
|
| 2778 | - $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
|
| 2779 | - $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
|
| 2780 | - |
|
| 2781 | - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2782 | - {
|
|
| 2783 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2784 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2785 | - //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"; |
|
| 2786 | - if ($diff) |
|
| 2787 | - {
|
|
| 2788 | - if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; }
|
|
| 2789 | - $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; |
|
| 2790 | - 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);
|
|
| 2791 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2792 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2793 | - $this->total_tva -= $diff; |
|
| 2794 | - $this->total_ttc -= $diff; |
|
| 2795 | - $total_tva_by_vats[$obj->vatrate] -= $diff; |
|
| 2796 | - $total_ttc_by_vats[$obj->vatrate] -= $diff; |
|
| 2797 | - } |
|
| 2798 | - } |
|
| 781 | + if(!$already_added) {
|
|
| 2799 | 782 | |
| 2800 | - $i++; |
|
| 2801 | - } |
|
| 783 | + $this->db->begin(); |
|
| 2802 | 784 | |
| 2803 | - // Add revenue stamp to total |
|
| 2804 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2805 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 785 | + // Insert into database |
|
| 786 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
| 787 | + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 788 | + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
|
| 789 | + $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 790 | + $sql.= ", 4, ". $id_type_contact; |
|
| 791 | + $sql.= ")"; |
|
| 2806 | 792 | |
| 2807 | - // Situations totals |
|
| 2808 | - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
| 2809 | - {
|
|
| 2810 | - $prev_sits = $this->get_prev_sits(); |
|
| 2811 | - |
|
| 2812 | - foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch.
|
|
| 2813 | - $this->total_ht -= $sit->total_ht; |
|
| 2814 | - $this->total_tva -= $sit->total_tva; |
|
| 2815 | - $this->total_localtax1 -= $sit->total_localtax1; |
|
| 2816 | - $this->total_localtax2 -= $sit->total_localtax2; |
|
| 2817 | - $this->total_ttc -= $sit->total_ttc; |
|
| 2818 | - $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; |
|
| 2819 | - $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; |
|
| 2820 | - $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; |
|
| 2821 | - } |
|
| 2822 | - } |
|
| 2823 | - |
|
| 2824 | - $this->db->free($resql); |
|
| 2825 | - |
|
| 2826 | - // Now update global field total_ht, total_ttc and tva |
|
| 2827 | - $fieldht='total_ht'; |
|
| 2828 | - $fieldtva='tva'; |
|
| 2829 | - $fieldlocaltax1='localtax1'; |
|
| 2830 | - $fieldlocaltax2='localtax2'; |
|
| 2831 | - $fieldttc='total_ttc'; |
|
| 2832 | - // Specific code for backward compatibility with old field names |
|
| 2833 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2834 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2835 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2836 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2837 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 2838 | - |
|
| 2839 | - if (empty($nodatabaseupdate)) |
|
| 2840 | - {
|
|
| 2841 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
| 2842 | - $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
| 2843 | - $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
| 2844 | - $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
| 2845 | - $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
| 2846 | - $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
| 2847 | - $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
| 2848 | - $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
| 2849 | - $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
| 2850 | - $sql .= ' WHERE rowid = '.$this->id; |
|
| 2851 | - |
|
| 2852 | - |
|
| 2853 | - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2854 | - $resql=$this->db->query($sql); |
|
| 2855 | - if (! $resql) |
|
| 2856 | - {
|
|
| 2857 | - $error++; |
|
| 2858 | - $this->error=$this->db->lasterror(); |
|
| 2859 | - $this->errors[]=$this->db->lasterror(); |
|
| 2860 | - } |
|
| 2861 | - } |
|
| 793 | + $resql=$this->db->query($sql); |
|
| 794 | + if ($resql) |
|
| 795 | + {
|
|
| 796 | + if (! $notrigger) |
|
| 797 | + {
|
|
| 798 | + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 799 | + if ($result < 0) |
|
| 800 | + {
|
|
| 801 | + $this->db->rollback(); |
|
| 802 | + return -1; |
|
| 803 | + } |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + $this->db->commit(); |
|
| 807 | + return 1; |
|
| 808 | + } |
|
| 809 | + else |
|
| 810 | + {
|
|
| 811 | + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
| 812 | + {
|
|
| 813 | + $this->error=$this->db->errno(); |
|
| 814 | + $this->db->rollback(); |
|
| 815 | + echo 'err rollback'; |
|
| 816 | + return -2; |
|
| 817 | + } |
|
| 818 | + else |
|
| 819 | + {
|
|
| 820 | + $this->error=$this->db->error(); |
|
| 821 | + $this->db->rollback(); |
|
| 822 | + return -1; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + } else return 0; |
|
| 826 | + } |
|
| 2862 | 827 | |
| 2863 | - if (! $error) |
|
| 2864 | - {
|
|
| 2865 | - return 1; |
|
| 2866 | - } |
|
| 2867 | - else |
|
| 2868 | - {
|
|
| 2869 | - return -1; |
|
| 2870 | - } |
|
| 2871 | - } |
|
| 2872 | - else |
|
| 2873 | - {
|
|
| 2874 | - dol_print_error($this->db,'Bad request in update_price'); |
|
| 2875 | - return -1; |
|
| 2876 | - } |
|
| 2877 | - } |
|
| 828 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 829 | + /** |
|
| 830 | + * Copy contact from one element to current |
|
| 831 | + * |
|
| 832 | + * @param CommonObject $objFrom Source element |
|
| 833 | + * @param string $source Nature of contact ('internal' or 'external')
|
|
| 834 | + * @return int >0 if OK, <0 if KO |
|
| 835 | + */ |
|
| 836 | + function copy_linked_contact($objFrom, $source='internal') |
|
| 837 | + {
|
|
| 838 | + // phpcs:enable |
|
| 839 | + $contacts = $objFrom->liste_contact(-1, $source); |
|
| 840 | + foreach($contacts as $contact) |
|
| 841 | + {
|
|
| 842 | + if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
|
| 843 | + {
|
|
| 844 | + $this->error=$this->db->lasterror(); |
|
| 845 | + return -1; |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + return 1; |
|
| 849 | + } |
|
| 2878 | 850 | |
| 2879 | 851 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 2880 | - /** |
|
| 2881 | - * Add objects linked in llx_element_element. |
|
| 2882 | - * |
|
| 2883 | - * @param string $origin Linked element type |
|
| 2884 | - * @param int $origin_id Linked element id |
|
| 2885 | - * @return int <=0 if KO, >0 if OK |
|
| 2886 | - * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
|
| 2887 | - */ |
|
| 2888 | - function add_object_linked($origin=null, $origin_id=null) |
|
| 2889 | - {
|
|
| 852 | + /** |
|
| 853 | + * Update a link to contact line |
|
| 854 | + * |
|
| 855 | + * @param int $rowid Id of line contact-element |
|
| 856 | + * @param int $statut New status of link |
|
| 857 | + * @param int $type_contact_id Id of contact type (not modified if 0) |
|
| 858 | + * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
|
| 859 | + * @return int <0 if KO, >= 0 if OK |
|
| 860 | + */ |
|
| 861 | + function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 862 | + {
|
|
| 2890 | 863 | // phpcs:enable |
| 2891 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2892 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2893 | - |
|
| 2894 | - // Special case |
|
| 2895 | - if ($origin == 'order') $origin='commande'; |
|
| 2896 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2897 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2898 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 2899 | - $this->db->begin(); |
|
| 2900 | - |
|
| 2901 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
|
| 2902 | - $sql.= "fk_source"; |
|
| 2903 | - $sql.= ", sourcetype"; |
|
| 2904 | - $sql.= ", fk_target"; |
|
| 2905 | - $sql.= ", targettype"; |
|
| 2906 | - $sql.= ") VALUES (";
|
|
| 2907 | - $sql.= $origin_id; |
|
| 2908 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2909 | - $sql.= ", ".$this->id; |
|
| 2910 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2911 | - $sql.= ")"; |
|
| 2912 | - |
|
| 2913 | - dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
| 2914 | - if ($this->db->query($sql)) |
|
| 2915 | - {
|
|
| 2916 | - $this->db->commit(); |
|
| 2917 | - return 1; |
|
| 2918 | - } |
|
| 2919 | - else |
|
| 2920 | - {
|
|
| 2921 | - $this->error=$this->db->lasterror(); |
|
| 2922 | - $this->db->rollback(); |
|
| 2923 | - return 0; |
|
| 2924 | - } |
|
| 2925 | - } |
|
| 2926 | - |
|
| 2927 | - /** |
|
| 2928 | - * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into |
|
| 2929 | - * this->linkedObjectsIds array and |
|
| 2930 | - * this->linkedObjects array if $loadalsoobjects = 1 |
|
| 2931 | - * Possible usage for parameters: |
|
| 2932 | - * - all parameters empty -> we look all link to current object (current object can be source or target) |
|
| 2933 | - * - source id+type -> will get target list linked to source |
|
| 2934 | - * - target id+type -> will get source list linked to target |
|
| 2935 | - * - source id+type + target type -> will get target list of the type |
|
| 2936 | - * - target id+type + target source -> will get source list of the type |
|
| 2937 | - * |
|
| 2938 | - * @param int $sourceid Object source id (if not defined, id of object) |
|
| 2939 | - * @param string $sourcetype Object source type (if not defined, element name of object) |
|
| 2940 | - * @param int $targetid Object target id (if not defined, id of object) |
|
| 2941 | - * @param string $targettype Object target type (if not defined, elemennt name of object) |
|
| 2942 | - * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided |
|
| 2943 | - * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. |
|
| 2944 | - * @param string $orderby SQL 'ORDER BY' clause |
|
| 2945 | - * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) |
|
| 2946 | - * @return int <0 if KO, >0 if OK |
|
| 2947 | - * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
|
| 2948 | - */ |
|
| 2949 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
| 2950 | - {
|
|
| 2951 | - global $conf; |
|
| 2952 | - |
|
| 2953 | - $this->linkedObjectsIds=array(); |
|
| 2954 | - $this->linkedObjects=array(); |
|
| 2955 | - |
|
| 2956 | - $justsource=false; |
|
| 2957 | - $justtarget=false; |
|
| 2958 | - $withtargettype=false; |
|
| 2959 | - $withsourcetype=false; |
|
| 2960 | - |
|
| 2961 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2962 | - {
|
|
| 2963 | - $justsource=true; // the source (id and type) is a search criteria |
|
| 2964 | - if (! empty($targettype)) $withtargettype=true; |
|
| 2965 | - } |
|
| 2966 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2967 | - {
|
|
| 2968 | - $justtarget=true; // the target (id and type) is a search criteria |
|
| 2969 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2970 | - } |
|
| 2971 | - |
|
| 2972 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2973 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2974 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2975 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2976 | - |
|
| 2977 | - /*if (empty($sourceid) && empty($targetid)) |
|
| 2978 | - {
|
|
| 2979 | - dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR);
|
|
| 2980 | - return -1; |
|
| 2981 | - }*/ |
|
| 864 | + // Insert into database |
|
| 865 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
| 866 | + $sql.= " statut = ".$statut; |
|
| 867 | + if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 868 | + if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 869 | + $sql.= " where rowid = ".$rowid; |
|
| 870 | + $resql=$this->db->query($sql); |
|
| 871 | + if ($resql) |
|
| 872 | + {
|
|
| 873 | + return 0; |
|
| 874 | + } |
|
| 875 | + else |
|
| 876 | + {
|
|
| 877 | + $this->error=$this->db->lasterror(); |
|
| 878 | + return -1; |
|
| 879 | + } |
|
| 880 | + } |
|
| 2982 | 881 | |
| 2983 | - // Links between objects are stored in table element_element |
|
| 2984 | - $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
|
| 2985 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2986 | - $sql.= " WHERE "; |
|
| 2987 | - if ($justsource || $justtarget) |
|
| 2988 | - {
|
|
| 2989 | - if ($justsource) |
|
| 2990 | - {
|
|
| 2991 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2992 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2993 | - } |
|
| 2994 | - else if ($justtarget) |
|
| 2995 | - {
|
|
| 2996 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2997 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 2998 | - } |
|
| 2999 | - } |
|
| 3000 | - else |
|
| 3001 | - {
|
|
| 3002 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3003 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3004 | - } |
|
| 3005 | - $sql .= ' ORDER BY '.$orderby; |
|
| 3006 | - |
|
| 3007 | - dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
| 3008 | - $resql = $this->db->query($sql); |
|
| 3009 | - if ($resql) |
|
| 3010 | - {
|
|
| 3011 | - $num = $this->db->num_rows($resql); |
|
| 3012 | - $i = 0; |
|
| 3013 | - while ($i < $num) |
|
| 3014 | - {
|
|
| 3015 | - $obj = $this->db->fetch_object($resql); |
|
| 3016 | - if ($justsource || $justtarget) |
|
| 3017 | - {
|
|
| 3018 | - if ($justsource) |
|
| 3019 | - {
|
|
| 3020 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3021 | - } |
|
| 3022 | - else if ($justtarget) |
|
| 3023 | - {
|
|
| 3024 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3025 | - } |
|
| 3026 | - } |
|
| 3027 | - else |
|
| 3028 | - {
|
|
| 3029 | - if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
|
| 3030 | - {
|
|
| 3031 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3032 | - } |
|
| 3033 | - if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
|
| 3034 | - {
|
|
| 3035 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3036 | - } |
|
| 3037 | - } |
|
| 3038 | - $i++; |
|
| 3039 | - } |
|
| 882 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 883 | + /** |
|
| 884 | + * Delete a link to contact line |
|
| 885 | + * |
|
| 886 | + * @param int $rowid Id of contact link line to delete |
|
| 887 | + * @param int $notrigger Disable all triggers |
|
| 888 | + * @return int >0 if OK, <0 if KO |
|
| 889 | + */ |
|
| 890 | + function delete_contact($rowid, $notrigger=0) |
|
| 891 | + {
|
|
| 892 | + // phpcs:enable |
|
| 893 | + global $user; |
|
| 3040 | 894 | |
| 3041 | - if (! empty($this->linkedObjectsIds)) |
|
| 3042 | - {
|
|
| 3043 | - $tmparray = $this->linkedObjectsIds; |
|
| 3044 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3045 | - {
|
|
| 3046 | - // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
|
| 3047 | - $module = $element = $subelement = $objecttype; |
|
| 3048 | - if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
|
| 3049 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
|
| 3050 | - {
|
|
| 3051 | - $module = $element = $regs[1]; |
|
| 3052 | - $subelement = $regs[2]; |
|
| 3053 | - } |
|
| 3054 | - |
|
| 3055 | - $classpath = $element.'/class'; |
|
| 3056 | - // To work with non standard classpath or module name |
|
| 3057 | - if ($objecttype == 'facture') {
|
|
| 3058 | - $classpath = 'compta/facture/class'; |
|
| 3059 | - } |
|
| 3060 | - else if ($objecttype == 'facturerec') {
|
|
| 3061 | - $classpath = 'compta/facture/class'; $module = 'facture'; |
|
| 3062 | - } |
|
| 3063 | - else if ($objecttype == 'propal') {
|
|
| 3064 | - $classpath = 'comm/propal/class'; |
|
| 3065 | - } |
|
| 3066 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3067 | - $classpath = 'supplier_proposal/class'; |
|
| 3068 | - } |
|
| 3069 | - else if ($objecttype == 'shipping') {
|
|
| 3070 | - $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
|
| 3071 | - } |
|
| 3072 | - else if ($objecttype == 'delivery') {
|
|
| 3073 | - $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
|
| 3074 | - } |
|
| 3075 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3076 | - $classpath = 'fourn/class'; $module = 'fournisseur'; |
|
| 3077 | - } |
|
| 3078 | - else if ($objecttype == 'fichinter') {
|
|
| 3079 | - $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
|
| 3080 | - } |
|
| 3081 | - else if ($objecttype == 'subscription') {
|
|
| 3082 | - $classpath = 'adherents/class'; $module = 'adherent'; |
|
| 3083 | - } |
|
| 3084 | - |
|
| 3085 | - // Set classfile |
|
| 3086 | - $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
|
| 3087 | - |
|
| 3088 | - if ($objecttype == 'order') {
|
|
| 3089 | - $classfile = 'commande'; $classname = 'Commande'; |
|
| 3090 | - } |
|
| 3091 | - else if ($objecttype == 'invoice_supplier') {
|
|
| 3092 | - $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
|
| 3093 | - } |
|
| 3094 | - else if ($objecttype == 'order_supplier') {
|
|
| 3095 | - $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
|
| 3096 | - } |
|
| 3097 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3098 | - $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
|
| 3099 | - } |
|
| 3100 | - else if ($objecttype == 'facturerec') {
|
|
| 3101 | - $classfile = 'facture-rec'; $classname = 'FactureRec'; |
|
| 3102 | - } |
|
| 3103 | - else if ($objecttype == 'subscription') {
|
|
| 3104 | - $classfile = 'subscription'; $classname = 'Subscription'; |
|
| 3105 | - } |
|
| 3106 | - |
|
| 3107 | - // Here $module, $classfile and $classname are set |
|
| 3108 | - if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) |
|
| 3109 | - {
|
|
| 3110 | - if ($loadalsoobjects) |
|
| 3111 | - {
|
|
| 3112 | - dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
|
|
| 3113 | - //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
|
| 3114 | - if (class_exists($classname)) |
|
| 3115 | - {
|
|
| 3116 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3117 | - {
|
|
| 3118 | - $object = new $classname($this->db); |
|
| 3119 | - $ret = $object->fetch($objectid); |
|
| 3120 | - if ($ret >= 0) |
|
| 3121 | - {
|
|
| 3122 | - $this->linkedObjects[$objecttype][$i] = $object; |
|
| 3123 | - } |
|
| 3124 | - } |
|
| 3125 | - } |
|
| 3126 | - } |
|
| 3127 | - } |
|
| 3128 | - else |
|
| 3129 | - {
|
|
| 3130 | - unset($this->linkedObjectsIds[$objecttype]); |
|
| 3131 | - } |
|
| 3132 | - } |
|
| 3133 | - } |
|
| 3134 | - return 1; |
|
| 3135 | - } |
|
| 3136 | - else |
|
| 3137 | - {
|
|
| 3138 | - dol_print_error($this->db); |
|
| 3139 | - return -1; |
|
| 3140 | - } |
|
| 3141 | - } |
|
| 3142 | - |
|
| 3143 | - /** |
|
| 3144 | - * Update object linked of a current object |
|
| 3145 | - * |
|
| 3146 | - * @param int $sourceid Object source id |
|
| 3147 | - * @param string $sourcetype Object source type |
|
| 3148 | - * @param int $targetid Object target id |
|
| 3149 | - * @param string $targettype Object target type |
|
| 3150 | - * @return int >0 if OK, <0 if KO |
|
| 3151 | - * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
|
| 3152 | - */ |
|
| 3153 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 3154 | - {
|
|
| 3155 | - $updatesource=false; |
|
| 3156 | - $updatetarget=false; |
|
| 3157 | - |
|
| 3158 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3159 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3160 | - |
|
| 3161 | - $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
| 3162 | - if ($updatesource) |
|
| 3163 | - {
|
|
| 3164 | - $sql.= "fk_source = ".$sourceid; |
|
| 3165 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3166 | - $sql.= " WHERE fk_target = ".$this->id; |
|
| 3167 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3168 | - } |
|
| 3169 | - else if ($updatetarget) |
|
| 3170 | - {
|
|
| 3171 | - $sql.= "fk_target = ".$targetid; |
|
| 3172 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3173 | - $sql.= " WHERE fk_source = ".$this->id; |
|
| 3174 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3175 | - } |
|
| 3176 | - |
|
| 3177 | - dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
| 3178 | - if ($this->db->query($sql)) |
|
| 3179 | - {
|
|
| 3180 | - return 1; |
|
| 3181 | - } |
|
| 3182 | - else |
|
| 3183 | - {
|
|
| 3184 | - $this->error=$this->db->lasterror(); |
|
| 3185 | - return -1; |
|
| 3186 | - } |
|
| 3187 | - } |
|
| 3188 | - |
|
| 3189 | - /** |
|
| 3190 | - * Delete all links between an object $this |
|
| 3191 | - * |
|
| 3192 | - * @param int $sourceid Object source id |
|
| 3193 | - * @param string $sourcetype Object source type |
|
| 3194 | - * @param int $targetid Object target id |
|
| 3195 | - * @param string $targettype Object target type |
|
| 3196 | - * @param int $rowid Row id of line to delete. If defined, other parameters are not used. |
|
| 3197 | - * @return int >0 if OK, <0 if KO |
|
| 3198 | - * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
|
| 3199 | - */ |
|
| 3200 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 3201 | - {
|
|
| 3202 | - $deletesource=false; |
|
| 3203 | - $deletetarget=false; |
|
| 3204 | - |
|
| 3205 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3206 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3207 | - |
|
| 3208 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 3209 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3210 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3211 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 3212 | - |
|
| 3213 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
| 3214 | - $sql.= " WHERE"; |
|
| 3215 | - if ($rowid > 0) |
|
| 3216 | - {
|
|
| 3217 | - $sql.=" rowid = ".$rowid; |
|
| 3218 | - } |
|
| 3219 | - else |
|
| 3220 | - {
|
|
| 3221 | - if ($deletesource) |
|
| 3222 | - {
|
|
| 3223 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3224 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3225 | - } |
|
| 3226 | - else if ($deletetarget) |
|
| 3227 | - {
|
|
| 3228 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3229 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3230 | - } |
|
| 3231 | - else |
|
| 3232 | - {
|
|
| 3233 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3234 | - $sql.= " OR"; |
|
| 3235 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3236 | - } |
|
| 3237 | - } |
|
| 3238 | - |
|
| 3239 | - dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
| 3240 | - if ($this->db->query($sql)) |
|
| 3241 | - {
|
|
| 3242 | - return 1; |
|
| 3243 | - } |
|
| 3244 | - else |
|
| 3245 | - {
|
|
| 3246 | - $this->error=$this->db->lasterror(); |
|
| 3247 | - $this->errors[]=$this->error; |
|
| 3248 | - return -1; |
|
| 3249 | - } |
|
| 3250 | - } |
|
| 3251 | - |
|
| 3252 | - /** |
|
| 3253 | - * Set status of an object |
|
| 3254 | - * |
|
| 3255 | - * @param int $status Status to set |
|
| 3256 | - * @param int $elementId Id of element to force (use this->id by default) |
|
| 3257 | - * @param string $elementType Type of element to force (use this->table_element by default) |
|
| 3258 | - * @param string $trigkey Trigger key to use for trigger |
|
| 3259 | - * @return int <0 if KO, >0 if OK |
|
| 3260 | - */ |
|
| 3261 | - function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
| 3262 | - {
|
|
| 3263 | - global $user,$langs,$conf; |
|
| 3264 | - |
|
| 3265 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3266 | - |
|
| 3267 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3268 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3269 | - |
|
| 3270 | - $this->db->begin(); |
|
| 3271 | - |
|
| 3272 | - $fieldstatus="fk_statut"; |
|
| 3273 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3274 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3275 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3276 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3277 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3278 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3279 | - |
|
| 3280 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
| 3281 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3282 | - // If status = 1 = validated, update also fk_user_valid |
|
| 3283 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3284 | - $sql.= " WHERE rowid=".$elementId; |
|
| 3285 | - |
|
| 3286 | - dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
| 3287 | - if ($this->db->query($sql)) |
|
| 3288 | - {
|
|
| 3289 | - $error = 0; |
|
| 3290 | - |
|
| 3291 | - // Try autoset of trigkey |
|
| 3292 | - if (empty($trigkey)) |
|
| 3293 | - {
|
|
| 3294 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3295 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3296 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3297 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3298 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3299 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3300 | - } |
|
| 3301 | - |
|
| 3302 | - if ($trigkey) |
|
| 3303 | - {
|
|
| 3304 | - // Appel des triggers |
|
| 3305 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3306 | - $interface=new Interfaces($this->db); |
|
| 3307 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3308 | - if ($result < 0) {
|
|
| 3309 | - $error++; $this->errors=$interface->errors; |
|
| 3310 | - } |
|
| 3311 | - // Fin appel triggers |
|
| 3312 | - } |
|
| 3313 | 895 | |
| 3314 | - if (! $error) |
|
| 3315 | - {
|
|
| 3316 | - $this->db->commit(); |
|
| 896 | + $this->db->begin(); |
|
| 3317 | 897 | |
| 3318 | - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3319 | - {
|
|
| 3320 | - $this->statut = $status; |
|
| 3321 | - $this->status = $status; |
|
| 3322 | - } |
|
| 898 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 899 | + $sql.= " WHERE rowid =".$rowid; |
|
| 3323 | 900 | |
| 3324 | - return 1; |
|
| 3325 | - } |
|
| 3326 | - else |
|
| 3327 | - {
|
|
| 3328 | - $this->db->rollback(); |
|
| 3329 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3330 | - return -1; |
|
| 3331 | - } |
|
| 3332 | - } |
|
| 3333 | - else |
|
| 3334 | - {
|
|
| 3335 | - $this->error=$this->db->lasterror(); |
|
| 3336 | - $this->db->rollback(); |
|
| 3337 | - return -1; |
|
| 3338 | - } |
|
| 3339 | - } |
|
| 3340 | - |
|
| 3341 | - |
|
| 3342 | - /** |
|
| 3343 | - * Load type of canvas of an object if it exists |
|
| 3344 | - * |
|
| 3345 | - * @param int $id Record id |
|
| 3346 | - * @param string $ref Record ref |
|
| 3347 | - * @return int <0 if KO, 0 if nothing done, >0 if OK |
|
| 3348 | - */ |
|
| 3349 | - function getCanvas($id=0,$ref='') |
|
| 3350 | - {
|
|
| 3351 | - global $conf; |
|
| 3352 | - |
|
| 3353 | - if (empty($id) && empty($ref)) return 0; |
|
| 3354 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3355 | - |
|
| 3356 | - // Clean parameters |
|
| 3357 | - $ref = trim($ref); |
|
| 3358 | - |
|
| 3359 | - $sql = "SELECT rowid, canvas"; |
|
| 3360 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3361 | - $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
|
| 3362 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3363 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3364 | - |
|
| 3365 | - $resql = $this->db->query($sql); |
|
| 3366 | - if ($resql) |
|
| 3367 | - {
|
|
| 3368 | - $obj = $this->db->fetch_object($resql); |
|
| 3369 | - if ($obj) |
|
| 3370 | - {
|
|
| 3371 | - $this->canvas = $obj->canvas; |
|
| 3372 | - return 1; |
|
| 3373 | - } |
|
| 3374 | - else return 0; |
|
| 3375 | - } |
|
| 3376 | - else |
|
| 3377 | - {
|
|
| 3378 | - dol_print_error($this->db); |
|
| 3379 | - return -1; |
|
| 3380 | - } |
|
| 3381 | - } |
|
| 3382 | - |
|
| 3383 | - |
|
| 3384 | - /** |
|
| 3385 | - * Get special code of a line |
|
| 3386 | - * |
|
| 3387 | - * @param int $lineid Id of line |
|
| 3388 | - * @return int Special code |
|
| 3389 | - */ |
|
| 3390 | - function getSpecialCode($lineid) |
|
| 3391 | - {
|
|
| 3392 | - $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 3393 | - $sql.= ' WHERE rowid = '.$lineid; |
|
| 3394 | - $resql = $this->db->query($sql); |
|
| 3395 | - if ($resql) |
|
| 3396 | - {
|
|
| 3397 | - $row = $this->db->fetch_row($resql); |
|
| 3398 | - return $row[0]; |
|
| 3399 | - } |
|
| 3400 | - } |
|
| 3401 | - |
|
| 3402 | - /** |
|
| 3403 | - * Function to check if an object is used by others. |
|
| 3404 | - * Check is done into this->childtables. There is no check into llx_element_element. |
|
| 3405 | - * |
|
| 3406 | - * @param int $id Force id of object |
|
| 3407 | - * @return int <0 if KO, 0 if not used, >0 if already used |
|
| 3408 | - */ |
|
| 3409 | - function isObjectUsed($id=0) |
|
| 3410 | - {
|
|
| 3411 | - global $langs; |
|
| 3412 | - |
|
| 3413 | - if (empty($id)) $id=$this->id; |
|
| 3414 | - |
|
| 3415 | - // Check parameters |
|
| 3416 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3417 | - {
|
|
| 3418 | - dol_print_error('Called isObjectUsed on a class with property this->childtables not defined');
|
|
| 3419 | - return -1; |
|
| 3420 | - } |
|
| 3421 | - |
|
| 3422 | - $arraytoscan = $this->childtables; |
|
| 3423 | - // For backward compatibility, we check if array is old format array('table1', 'table2', ...)
|
|
| 3424 | - $tmparray=array_keys($this->childtables); |
|
| 3425 | - if (is_numeric($tmparray[0])) |
|
| 3426 | - {
|
|
| 3427 | - $arraytoscan = array_flip($this->childtables); |
|
| 3428 | - } |
|
| 3429 | - |
|
| 3430 | - // Test if child exists |
|
| 3431 | - $haschild=0; |
|
| 3432 | - foreach($arraytoscan as $table => $elementname) |
|
| 3433 | - {
|
|
| 3434 | - //print $id.'-'.$table.'-'.$elementname.'<br>'; |
|
| 3435 | - // Check if third party can be deleted |
|
| 3436 | - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
| 3437 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3438 | - $resql=$this->db->query($sql); |
|
| 3439 | - if ($resql) |
|
| 3440 | - {
|
|
| 3441 | - $obj=$this->db->fetch_object($resql); |
|
| 3442 | - if ($obj->nb > 0) |
|
| 3443 | - {
|
|
| 3444 | - $langs->load("errors");
|
|
| 3445 | - //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
|
| 3446 | - $haschild += $obj->nb; |
|
| 3447 | - if (is_numeric($elementname)) // old usage |
|
| 3448 | - {
|
|
| 3449 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3450 | - } |
|
| 3451 | - else // new usage: $elementname=Translation key |
|
| 3452 | - {
|
|
| 3453 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
|
| 3454 | - } |
|
| 3455 | - break; // We found at least one, we stop here |
|
| 3456 | - } |
|
| 3457 | - } |
|
| 3458 | - else |
|
| 3459 | - {
|
|
| 3460 | - $this->errors[]=$this->db->lasterror(); |
|
| 3461 | - return -1; |
|
| 3462 | - } |
|
| 3463 | - } |
|
| 3464 | - if ($haschild > 0) |
|
| 3465 | - {
|
|
| 3466 | - $this->errors[]="ErrorRecordHasChildren"; |
|
| 3467 | - return $haschild; |
|
| 3468 | - } |
|
| 3469 | - else return 0; |
|
| 3470 | - } |
|
| 3471 | - |
|
| 3472 | - /** |
|
| 3473 | - * Function to say how many lines object contains |
|
| 3474 | - * |
|
| 3475 | - * @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 |
|
| 3476 | - * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
|
| 3477 | - */ |
|
| 3478 | - function hasProductsOrServices($predefined=-1) |
|
| 3479 | - {
|
|
| 3480 | - $nb=0; |
|
| 3481 | - |
|
| 3482 | - foreach($this->lines as $key => $val) |
|
| 3483 | - {
|
|
| 3484 | - $qualified=0; |
|
| 3485 | - if ($predefined == -1) $qualified=1; |
|
| 3486 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3487 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3488 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3489 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3490 | - if ($qualified) $nb++; |
|
| 3491 | - } |
|
| 3492 | - dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
| 3493 | - return $nb; |
|
| 3494 | - } |
|
| 3495 | - |
|
| 3496 | - /** |
|
| 3497 | - * Function that returns the total amount HT of discounts applied for all lines. |
|
| 3498 | - * |
|
| 3499 | - * @return float |
|
| 3500 | - */ |
|
| 3501 | - function getTotalDiscount() |
|
| 3502 | - {
|
|
| 3503 | - $total_discount=0.00; |
|
| 3504 | - |
|
| 3505 | - $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
|
| 3506 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3507 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3508 | - |
|
| 3509 | - dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
| 3510 | - $resql = $this->db->query($sql); |
|
| 3511 | - if ($resql) |
|
| 3512 | - {
|
|
| 3513 | - $num=$this->db->num_rows($resql); |
|
| 3514 | - $i=0; |
|
| 3515 | - while ($i < $num) |
|
| 3516 | - {
|
|
| 3517 | - $obj = $this->db->fetch_object($resql); |
|
| 3518 | - |
|
| 3519 | - $pu_ht = $obj->pu_ht; |
|
| 3520 | - $qty= $obj->qty; |
|
| 3521 | - $total_ht = $obj->total_ht; |
|
| 3522 | - |
|
| 3523 | - $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
|
| 3524 | - $total_discount += $total_discount_line; |
|
| 3525 | - |
|
| 3526 | - $i++; |
|
| 3527 | - } |
|
| 3528 | - } |
|
| 3529 | - |
|
| 3530 | - //print $total_discount; exit; |
|
| 3531 | - return price2num($total_discount); |
|
| 3532 | - } |
|
| 3533 | - |
|
| 3534 | - |
|
| 3535 | - /** |
|
| 3536 | - * Return into unit=0, the calculated total of weight and volume of all lines * qty |
|
| 3537 | - * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. |
|
| 3538 | - * |
|
| 3539 | - * @return array array('weight'=>...,'volume'=>...)
|
|
| 3540 | - */ |
|
| 3541 | - function getTotalWeightVolume() |
|
| 3542 | - {
|
|
| 3543 | - $totalWeight = 0; |
|
| 3544 | - $totalVolume = 0; |
|
| 3545 | - // defined for shipment only |
|
| 3546 | - $totalOrdered = ''; |
|
| 3547 | - // defined for shipment only |
|
| 3548 | - $totalToShip = ''; |
|
| 3549 | - |
|
| 3550 | - foreach ($this->lines as $line) |
|
| 3551 | - {
|
|
| 3552 | - if (isset($line->qty_asked)) |
|
| 3553 | - {
|
|
| 3554 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3555 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3556 | - } |
|
| 3557 | - if (isset($line->qty_shipped)) |
|
| 3558 | - {
|
|
| 3559 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3560 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3561 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 901 | + dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
| 902 | + if ($this->db->query($sql)) |
|
| 903 | + {
|
|
| 904 | + if (! $notrigger) |
|
| 3562 | 905 | {
|
| 3563 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3564 | - $totalToShip+=$line->qty; // defined for reception only |
|
| 3565 | - } |
|
| 3566 | - |
|
| 3567 | - // Define qty, weight, volume, weight_units, volume_units |
|
| 3568 | - if ($this->element == 'shipping') {
|
|
| 3569 | - // for shipments |
|
| 3570 | - $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
|
| 3571 | - } |
|
| 3572 | - else {
|
|
| 3573 | - $qty = $line->qty ? $line->qty : 0; |
|
| 3574 | - } |
|
| 3575 | - |
|
| 3576 | - $weight = $line->weight ? $line->weight : 0; |
|
| 3577 | - ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
| 3578 | - $volume = $line->volume ? $line->volume : 0; |
|
| 3579 | - ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
| 906 | + $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 907 | + if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 908 | + } |
|
| 3580 | 909 | |
| 3581 | - $weight_units=$line->weight_units; |
|
| 3582 | - ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
| 3583 | - $volume_units=$line->volume_units; |
|
| 3584 | - ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
| 910 | + $this->db->commit(); |
|
| 911 | + return 1; |
|
| 912 | + } |
|
| 913 | + else |
|
| 914 | + {
|
|
| 915 | + $this->error=$this->db->lasterror(); |
|
| 916 | + $this->db->rollback(); |
|
| 917 | + return -1; |
|
| 918 | + } |
|
| 919 | + } |
|
| 3585 | 920 | |
| 3586 | - $weightUnit=0; |
|
| 3587 | - $volumeUnit=0; |
|
| 3588 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3589 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 921 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 922 | + /** |
|
| 923 | + * Delete all links between an object $this and all its contacts |
|
| 924 | + * |
|
| 925 | + * @param string $source '' or 'internal' or 'external' |
|
| 926 | + * @param string $code Type of contact (code or id) |
|
| 927 | + * @return int >0 if OK, <0 if KO |
|
| 928 | + */ |
|
| 929 | + function delete_linked_contact($source='',$code='') |
|
| 930 | + {
|
|
| 931 | + // phpcs:enable |
|
| 932 | + $temp = array(); |
|
| 933 | + $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 3590 | 934 | |
| 3591 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3592 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 935 | + foreach($typeContact as $key => $value) |
|
| 936 | + {
|
|
| 937 | + array_push($temp,$key); |
|
| 938 | + } |
|
| 939 | + $listId = implode(",", $temp);
|
|
| 3593 | 940 | |
| 3594 | - //var_dump($line->volume_units); |
|
| 3595 | - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3596 | - {
|
|
| 3597 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3598 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3599 | - } |
|
| 3600 | - else {
|
|
| 3601 | - if ($weight_units == 99) {
|
|
| 3602 | - // conversion 1 Pound = 0.45359237 KG |
|
| 3603 | - $trueWeightUnit = 0.45359237; |
|
| 3604 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3605 | - } elseif ($weight_units == 98) {
|
|
| 3606 | - // conversion 1 Ounce = 0.0283495 KG |
|
| 3607 | - $trueWeightUnit = 0.0283495; |
|
| 3608 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3609 | - } |
|
| 3610 | - else |
|
| 3611 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3612 | - } |
|
| 3613 | - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3614 | - {
|
|
| 3615 | - //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
|
| 3616 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3617 | - //print $line->volume; |
|
| 3618 | - $totalVolume += $volume * $qty * $trueVolumeUnit; |
|
| 3619 | - } |
|
| 3620 | - else |
|
| 3621 | - {
|
|
| 3622 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3623 | - } |
|
| 3624 | - } |
|
| 3625 | - |
|
| 3626 | - return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip);
|
|
| 3627 | - } |
|
| 3628 | - |
|
| 3629 | - |
|
| 3630 | - /** |
|
| 3631 | - * Set extra parameters |
|
| 3632 | - * |
|
| 3633 | - * @return int <0 if KO, >0 if OK |
|
| 3634 | - */ |
|
| 3635 | - function setExtraParameters() |
|
| 3636 | - {
|
|
| 3637 | - $this->db->begin(); |
|
| 3638 | - |
|
| 3639 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3640 | - |
|
| 3641 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3642 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3643 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 3644 | - |
|
| 3645 | - dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
| 3646 | - $resql = $this->db->query($sql); |
|
| 3647 | - if (! $resql) |
|
| 3648 | - {
|
|
| 3649 | - $this->error=$this->db->lasterror(); |
|
| 3650 | - $this->db->rollback(); |
|
| 3651 | - return -1; |
|
| 3652 | - } |
|
| 3653 | - else |
|
| 3654 | - {
|
|
| 3655 | - $this->db->commit(); |
|
| 3656 | - return 1; |
|
| 3657 | - } |
|
| 3658 | - } |
|
| 941 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 942 | + $sql.= " WHERE element_id = ".$this->id; |
|
| 943 | + if ($listId) |
|
| 944 | + $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 3659 | 945 | |
| 946 | + dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
| 947 | + if ($this->db->query($sql)) |
|
| 948 | + {
|
|
| 949 | + return 1; |
|
| 950 | + } |
|
| 951 | + else |
|
| 952 | + {
|
|
| 953 | + $this->error=$this->db->lasterror(); |
|
| 954 | + return -1; |
|
| 955 | + } |
|
| 956 | + } |
|
| 3660 | 957 | |
| 3661 | 958 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 3662 | - /** |
|
| 3663 | - * Return incoterms informations |
|
| 3664 | - * TODO Use a cache for label get |
|
| 3665 | - * |
|
| 3666 | - * @return string incoterms info |
|
| 3667 | - */ |
|
| 3668 | - function display_incoterms() |
|
| 3669 | - {
|
|
| 959 | + /** |
|
| 960 | + * Get array of all contacts for an object |
|
| 961 | + * |
|
| 962 | + * @param int $statut Status of links to get (-1=all) |
|
| 963 | + * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) |
|
| 964 | + * @param int $list 0:Return array contains all properties, 1:Return array contains just id |
|
| 965 | + * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
|
|
| 966 | + * @return array|int Array of contacts, -1 if error |
|
| 967 | + */ |
|
| 968 | + function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 969 | + {
|
|
| 3670 | 970 | // phpcs:enable |
| 3671 | - $out = ''; |
|
| 3672 | - $this->libelle_incoterms = ''; |
|
| 3673 | - if (!empty($this->fk_incoterms)) |
|
| 3674 | - {
|
|
| 3675 | - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3676 | - $result = $this->db->query($sql); |
|
| 3677 | - if ($result) |
|
| 3678 | - {
|
|
| 3679 | - $res = $this->db->fetch_object($result); |
|
| 3680 | - $out .= $res->code; |
|
| 3681 | - } |
|
| 3682 | - } |
|
| 3683 | - |
|
| 3684 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3685 | - |
|
| 3686 | - return $out; |
|
| 3687 | - } |
|
| 3688 | - |
|
| 3689 | - /** |
|
| 3690 | - * Return incoterms informations for pdf display |
|
| 3691 | - * |
|
| 3692 | - * @return string incoterms info |
|
| 3693 | - */ |
|
| 3694 | - function getIncotermsForPDF() |
|
| 3695 | - {
|
|
| 3696 | - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3697 | - $resql = $this->db->query($sql); |
|
| 3698 | - if ($resql) |
|
| 3699 | - {
|
|
| 3700 | - $num = $this->db->num_rows($resql); |
|
| 3701 | - if ($num > 0) |
|
| 3702 | - {
|
|
| 3703 | - $res = $this->db->fetch_object($resql); |
|
| 3704 | - return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
| 3705 | - } |
|
| 3706 | - else |
|
| 3707 | - {
|
|
| 3708 | - return ''; |
|
| 3709 | - } |
|
| 3710 | - } |
|
| 3711 | - else |
|
| 3712 | - {
|
|
| 3713 | - $this->errors[] = $this->db->lasterror(); |
|
| 3714 | - return false; |
|
| 3715 | - } |
|
| 3716 | - } |
|
| 3717 | - |
|
| 3718 | - /** |
|
| 3719 | - * Define incoterms values of current object |
|
| 3720 | - * |
|
| 3721 | - * @param int $id_incoterm Id of incoterm to set or '' to remove |
|
| 3722 | - * @param string $location location of incoterm |
|
| 3723 | - * @return int <0 if KO, >0 if OK |
|
| 3724 | - */ |
|
| 3725 | - function setIncoterms($id_incoterm, $location) |
|
| 3726 | - {
|
|
| 3727 | - if ($this->id && $this->table_element) |
|
| 3728 | - {
|
|
| 3729 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3730 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3731 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3732 | - $sql.= " WHERE rowid = " . $this->id; |
|
| 3733 | - dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
| 3734 | - $resql=$this->db->query($sql); |
|
| 3735 | - if ($resql) |
|
| 3736 | - {
|
|
| 3737 | - $this->fk_incoterms = $id_incoterm; |
|
| 3738 | - $this->location_incoterms = $location; |
|
| 3739 | - |
|
| 3740 | - $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3741 | - $res = $this->db->query($sql); |
|
| 3742 | - if ($res) |
|
| 3743 | - {
|
|
| 3744 | - $obj = $this->db->fetch_object($res); |
|
| 3745 | - $this->libelle_incoterms = $obj->libelle; |
|
| 3746 | - } |
|
| 3747 | - return 1; |
|
| 3748 | - } |
|
| 3749 | - else |
|
| 3750 | - {
|
|
| 3751 | - $this->errors[] = $this->db->lasterror(); |
|
| 3752 | - return -1; |
|
| 3753 | - } |
|
| 3754 | - } |
|
| 3755 | - else return -1; |
|
| 3756 | - } |
|
| 3757 | - |
|
| 3758 | - |
|
| 3759 | - // -------------------- |
|
| 3760 | - // TODO: All functions here must be redesigned and moved as they are not business functions but output functions |
|
| 3761 | - // -------------------- |
|
| 3762 | - |
|
| 3763 | - /* This is to show add lines */ |
|
| 3764 | - |
|
| 3765 | - /** |
|
| 3766 | - * Show add free and predefined products/services form |
|
| 3767 | - * |
|
| 3768 | - * @param int $dateSelector 1=Show also date range input fields |
|
| 3769 | - * @param Societe $seller Object thirdparty who sell |
|
| 3770 | - * @param Societe $buyer Object thirdparty who buy |
|
| 3771 | - * @return void |
|
| 3772 | - */ |
|
| 3773 | - function formAddObjectLine($dateSelector, $seller, $buyer) |
|
| 3774 | - {
|
|
| 3775 | - global $conf,$user,$langs,$object,$hookmanager; |
|
| 3776 | - global $form,$bcnd,$var; |
|
| 3777 | - |
|
| 3778 | - // Line extrafield |
|
| 3779 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3780 | - $extrafieldsline = new ExtraFields($this->db); |
|
| 3781 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3782 | - |
|
| 3783 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 3784 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 3785 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 3786 | - foreach($dirtpls as $reldir) |
|
| 3787 | - {
|
|
| 3788 | - $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
| 3789 | - if (empty($conf->file->strict_mode)) {
|
|
| 3790 | - $res=@include $tpl; |
|
| 3791 | - } else {
|
|
| 3792 | - $res=include $tpl; // for debug |
|
| 3793 | - } |
|
| 3794 | - if ($res) break; |
|
| 3795 | - } |
|
| 3796 | - } |
|
| 3797 | - |
|
| 3798 | - |
|
| 3799 | - |
|
| 3800 | - /* This is to show array of line of details */ |
|
| 3801 | - |
|
| 3802 | - |
|
| 3803 | - /** |
|
| 3804 | - * Return HTML table for object lines |
|
| 3805 | - * TODO Move this into an output class file (htmlline.class.php) |
|
| 3806 | - * If lines are into a template, title must also be into a template |
|
| 3807 | - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 3808 | - * |
|
| 3809 | - * @param string $action Action code |
|
| 3810 | - * @param string $seller Object of seller third party |
|
| 3811 | - * @param string $buyer Object of buyer third party |
|
| 3812 | - * @param int $selected Object line selected |
|
| 3813 | - * @param int $dateSelector 1=Show also date range input fields |
|
| 3814 | - * @return void |
|
| 3815 | - */ |
|
| 3816 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3817 | - {
|
|
| 3818 | - global $conf, $hookmanager, $langs, $user; |
|
| 3819 | - // TODO We should not use global var for this ! |
|
| 3820 | - global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
|
| 3821 | - |
|
| 3822 | - // Define usemargins |
|
| 3823 | - $usemargins=0; |
|
| 3824 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
|
|
| 3825 | - |
|
| 3826 | - $num = count($this->lines); |
|
| 3827 | - |
|
| 3828 | - // Line extrafield |
|
| 3829 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3830 | - $extrafieldsline = new ExtraFields($this->db); |
|
| 3831 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3832 | - |
|
| 3833 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3834 | - $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3835 | - if (empty($reshook)) |
|
| 3836 | - {
|
|
| 3837 | - // Title line |
|
| 3838 | - print "<thead>\n"; |
|
| 3839 | - |
|
| 3840 | - print '<tr class="liste_titre nodrag nodrop">'; |
|
| 3841 | - |
|
| 3842 | - // Adds a line numbering column |
|
| 3843 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3844 | - |
|
| 3845 | - // Description |
|
| 3846 | - print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
|
| 3847 | - |
|
| 3848 | - if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') |
|
| 3849 | - {
|
|
| 3850 | - print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>';
|
|
| 3851 | - } |
|
| 3852 | - |
|
| 3853 | - // VAT |
|
| 3854 | - print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>';
|
|
| 971 | + global $langs; |
|
| 972 | + |
|
| 973 | + $tab=array(); |
|
| 974 | + |
|
| 975 | + $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 |
|
| 976 | + if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 977 | + if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 978 | + $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 979 | + $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 980 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 981 | + $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 982 | + if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 983 | + if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 984 | + $sql.= " WHERE ec.element_id =".$this->id; |
|
| 985 | + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 986 | + $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 987 | + if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 988 | + if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 989 | + if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 990 | + $sql.= " AND tc.active=1"; |
|
| 991 | + if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 992 | + $sql.=" ORDER BY t.lastname ASC"; |
|
| 993 | + |
|
| 994 | + dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
| 995 | + $resql=$this->db->query($sql); |
|
| 996 | + if ($resql) |
|
| 997 | + {
|
|
| 998 | + $num=$this->db->num_rows($resql); |
|
| 999 | + $i=0; |
|
| 1000 | + while ($i < $num) |
|
| 1001 | + {
|
|
| 1002 | + $obj = $this->db->fetch_object($resql); |
|
| 1003 | + |
|
| 1004 | + if (! $list) |
|
| 1005 | + {
|
|
| 1006 | + $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1007 | + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1008 | + $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,
|
|
| 1009 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1010 | + 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
|
| 1011 | + 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
|
| 1012 | + } |
|
| 1013 | + else |
|
| 1014 | + {
|
|
| 1015 | + $tab[$i]=$obj->id; |
|
| 1016 | + } |
|
| 1017 | + |
|
| 1018 | + $i++; |
|
| 1019 | + } |
|
| 3855 | 1020 | |
| 3856 | - // Price HT |
|
| 3857 | - print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
|
|
| 1021 | + return $tab; |
|
| 1022 | + } |
|
| 1023 | + else |
|
| 1024 | + {
|
|
| 1025 | + $this->error=$this->db->lasterror(); |
|
| 1026 | + dol_print_error($this->db); |
|
| 1027 | + return -1; |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 3858 | 1030 | |
| 3859 | - // Multicurrency |
|
| 3860 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
|
|
| 3861 | 1031 | |
| 3862 | - if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
|
|
| 1032 | + /** |
|
| 1033 | + * Update status of a contact linked to object |
|
| 1034 | + * |
|
| 1035 | + * @param int $rowid Id of link between object and contact |
|
| 1036 | + * @return int <0 if KO, >=0 if OK |
|
| 1037 | + */ |
|
| 1038 | + function swapContactStatus($rowid) |
|
| 1039 | + {
|
|
| 1040 | + $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
|
| 1041 | + $sql.= " tc.code, tc.libelle"; |
|
| 1042 | + //$sql.= ", s.fk_soc"; |
|
| 1043 | + $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
|
|
| 1044 | + //$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 |
|
| 1045 | + $sql.= " WHERE ec.rowid =".$rowid; |
|
| 1046 | + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1047 | + $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1048 | + |
|
| 1049 | + dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
| 1050 | + $resql=$this->db->query($sql); |
|
| 1051 | + if ($resql) |
|
| 1052 | + {
|
|
| 1053 | + $obj = $this->db->fetch_object($resql); |
|
| 1054 | + $newstatut = ($obj->statut == 4) ? 5 : 4; |
|
| 1055 | + $result = $this->update_contact($rowid, $newstatut); |
|
| 1056 | + $this->db->free($resql); |
|
| 1057 | + return $result; |
|
| 1058 | + } |
|
| 1059 | + else |
|
| 1060 | + {
|
|
| 1061 | + $this->error=$this->db->error(); |
|
| 1062 | + dol_print_error($this->db); |
|
| 1063 | + return -1; |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 3863 | 1066 | |
| 3864 | - // Qty |
|
| 3865 | - print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
|
| 1067 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1068 | + /** |
|
| 1069 | + * Return array with list of possible values for type of contacts |
|
| 1070 | + * |
|
| 1071 | + * @param string $source 'internal', 'external' or 'all' |
|
| 1072 | + * @param string $order Sort order by : 'position', 'code', 'rowid'... |
|
| 1073 | + * @param int $option 0=Return array id->label, 1=Return array code->label |
|
| 1074 | + * @param int $activeonly 0=all status of contact, 1=only the active |
|
| 1075 | + * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
|
| 1076 | + * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
|
| 1077 | + */ |
|
| 1078 | + function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1079 | + {
|
|
| 1080 | + // phpcs:enable |
|
| 1081 | + global $langs; |
|
| 1082 | + |
|
| 1083 | + if (empty($order)) $order='position'; |
|
| 1084 | + if ($order == 'position') $order.=',code'; |
|
| 1085 | + |
|
| 1086 | + $tab = array(); |
|
| 1087 | + $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
|
| 1088 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1089 | + $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1090 | + if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1091 | + if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1092 | + if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1093 | + $sql.= $this->db->order($order,'ASC'); |
|
| 1094 | + |
|
| 1095 | + //print "sql=".$sql; |
|
| 1096 | + $resql=$this->db->query($sql); |
|
| 1097 | + if ($resql) |
|
| 1098 | + {
|
|
| 1099 | + $num=$this->db->num_rows($resql); |
|
| 1100 | + $i=0; |
|
| 1101 | + while ($i < $num) |
|
| 1102 | + {
|
|
| 1103 | + $obj = $this->db->fetch_object($resql); |
|
| 3866 | 1104 | |
| 3867 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 3868 | - {
|
|
| 3869 | - print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
|
|
| 3870 | - } |
|
| 1105 | + $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1106 | + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1107 | + if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1108 | + else $tab[$obj->code]=$libelle_type; |
|
| 1109 | + $i++; |
|
| 1110 | + } |
|
| 1111 | + return $tab; |
|
| 1112 | + } |
|
| 1113 | + else |
|
| 1114 | + {
|
|
| 1115 | + $this->error=$this->db->lasterror(); |
|
| 1116 | + //dol_print_error($this->db); |
|
| 1117 | + return null; |
|
| 1118 | + } |
|
| 1119 | + } |
|
| 3871 | 1120 | |
| 3872 | - // Reduction short |
|
| 3873 | - print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
|
|
| 1121 | + /** |
|
| 1122 | + * Return id of contacts for a source and a contact code. |
|
| 1123 | + * Example: contact client de facturation ('external', 'BILLING')
|
|
| 1124 | + * Example: contact client de livraison ('external', 'SHIPPING')
|
|
| 1125 | + * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL')
|
|
| 1126 | + * |
|
| 1127 | + * @param string $source 'external' or 'internal' |
|
| 1128 | + * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... |
|
| 1129 | + * @param int $status limited to a certain status |
|
| 1130 | + * @return array List of id for such contacts |
|
| 1131 | + */ |
|
| 1132 | + function getIdContact($source,$code,$status=0) |
|
| 1133 | + {
|
|
| 1134 | + global $conf; |
|
| 3874 | 1135 | |
| 3875 | - if ($this->situation_cycle_ref) {
|
|
| 3876 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
|
|
| 3877 | - } |
|
| 1136 | + $result=array(); |
|
| 1137 | + $i=0; |
|
| 1138 | + //cas particulier pour les expeditions |
|
| 1139 | + if($this->element=='shipping' && $this->origin_id != 0) {
|
|
| 1140 | + $id=$this->origin_id; |
|
| 1141 | + $element='commande'; |
|
| 1142 | + } else if($this->element=='reception' && $this->origin_id != 0) {
|
|
| 1143 | + $id=$this->origin_id; |
|
| 1144 | + $element='order_supplier'; |
|
| 1145 | + } else {
|
|
| 1146 | + $id=$this->id; |
|
| 1147 | + $element=$this->element; |
|
| 1148 | + } |
|
| 3878 | 1149 | |
| 3879 | - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3880 | - {
|
|
| 3881 | - if (!empty($user->rights->margins->creer)) |
|
| 3882 | - {
|
|
| 3883 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 3884 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
|
|
| 3885 | - else |
|
| 3886 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
|
| 3887 | - } |
|
| 1150 | + $sql = "SELECT ec.fk_socpeople"; |
|
| 1151 | + $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1152 | + if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1153 | + if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1154 | + $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1155 | + $sql.= " WHERE ec.element_id = ".$id; |
|
| 1156 | + $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
| 1157 | + if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1158 | + if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1159 | + $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1160 | + $sql.= " AND tc.element = '".$element."'"; |
|
| 1161 | + $sql.= " AND tc.source = '".$source."'"; |
|
| 1162 | + $sql.= " AND tc.code = '".$code."'"; |
|
| 1163 | + $sql.= " AND tc.active = 1"; |
|
| 1164 | + if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1165 | + |
|
| 1166 | + dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
| 1167 | + $resql=$this->db->query($sql); |
|
| 1168 | + if ($resql) |
|
| 1169 | + {
|
|
| 1170 | + while ($obj = $this->db->fetch_object($resql)) |
|
| 1171 | + {
|
|
| 1172 | + $result[$i]=$obj->fk_socpeople; |
|
| 1173 | + $i++; |
|
| 1174 | + } |
|
| 1175 | + } |
|
| 1176 | + else |
|
| 1177 | + {
|
|
| 1178 | + $this->error=$this->db->error(); |
|
| 1179 | + return null; |
|
| 1180 | + } |
|
| 3888 | 1181 | |
| 3889 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3890 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
|
| 3891 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3892 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
|
| 3893 | - } |
|
| 1182 | + return $result; |
|
| 1183 | + } |
|
| 3894 | 1184 | |
| 3895 | - // Total HT |
|
| 3896 | - print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
|
|
| 1185 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1186 | + /** |
|
| 1187 | + * Load object contact with id=$this->contactid into $this->contact |
|
| 1188 | + * |
|
| 1189 | + * @param int $contactid Id du contact. Use this->contactid if empty. |
|
| 1190 | + * @return int <0 if KO, >0 if OK |
|
| 1191 | + */ |
|
| 1192 | + function fetch_contact($contactid=null) |
|
| 1193 | + {
|
|
| 1194 | + // phpcs:enable |
|
| 1195 | + if (empty($contactid)) $contactid=$this->contactid; |
|
| 3897 | 1196 | |
| 3898 | - // Multicurrency |
|
| 3899 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
|
|
| 1197 | + if (empty($contactid)) return 0; |
|
| 3900 | 1198 | |
| 3901 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
|
| 1199 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 1200 | + $contact = new Contact($this->db); |
|
| 1201 | + $result=$contact->fetch($contactid); |
|
| 1202 | + $this->contact = $contact; |
|
| 1203 | + return $result; |
|
| 1204 | + } |
|
| 3902 | 1205 | |
| 3903 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 1206 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1207 | + /** |
|
| 1208 | + * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty |
|
| 1209 | + * |
|
| 1210 | + * @param int $force_thirdparty_id Force thirdparty id |
|
| 1211 | + * @return int <0 if KO, >0 if OK |
|
| 1212 | + */ |
|
| 1213 | + function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1214 | + {
|
|
| 1215 | + // phpcs:enable |
|
| 1216 | + global $conf; |
|
| 3904 | 1217 | |
| 3905 | - print '<td class="linecoldelete" width="10"></td>'; |
|
| 1218 | + if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1219 | + return 0; |
|
| 3906 | 1220 | |
| 3907 | - print '<td class="linecolmove" width="10"></td>'; |
|
| 1221 | + require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 3908 | 1222 | |
| 3909 | - if($action == 'selectlines') |
|
| 3910 | - {
|
|
| 3911 | - print '<td class="linecolcheckall" align="center">'; |
|
| 3912 | - print '<input type="checkbox" class="linecheckboxtoggle" />'; |
|
| 3913 | - print '<script type="text/javascript">$(document).ready(function() {$(".linecheckboxtoggle").click(function() {var checkBoxes = $(".linecheckbox");checkBoxes.prop("checked", this.checked);})});</script>';
|
|
| 3914 | - print '</td>'; |
|
| 3915 | - } |
|
| 3916 | - |
|
| 3917 | - print "</tr>\n"; |
|
| 3918 | - print "</thead>\n"; |
|
| 3919 | - } |
|
| 3920 | - |
|
| 3921 | - $var = true; |
|
| 3922 | - $i = 0; |
|
| 3923 | - |
|
| 3924 | - print "<tbody>\n"; |
|
| 3925 | - foreach ($this->lines as $line) |
|
| 3926 | - {
|
|
| 3927 | - //Line extrafield |
|
| 3928 | - $line->fetch_optionals(); |
|
| 3929 | - |
|
| 3930 | - //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 3931 | - if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 3932 | - {
|
|
| 3933 | - if (empty($line->fk_parent_line)) |
|
| 3934 | - {
|
|
| 3935 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3936 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3937 | - } |
|
| 3938 | - else |
|
| 3939 | - {
|
|
| 3940 | - $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);
|
|
| 3941 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3942 | - } |
|
| 3943 | - } |
|
| 3944 | - if (empty($reshook)) |
|
| 3945 | - {
|
|
| 3946 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3947 | - } |
|
| 3948 | - |
|
| 3949 | - $i++; |
|
| 3950 | - } |
|
| 3951 | - print "</tbody>\n"; |
|
| 3952 | - } |
|
| 3953 | - |
|
| 3954 | - /** |
|
| 3955 | - * Return HTML content of a detail line |
|
| 3956 | - * TODO Move this into an output class file (htmlline.class.php) |
|
| 3957 | - * |
|
| 3958 | - * @param string $action GET/POST action |
|
| 3959 | - * @param CommonObjectLine $line Selected object line to output |
|
| 3960 | - * @param string $var Is it a an odd line (true) |
|
| 3961 | - * @param int $num Number of line (0) |
|
| 3962 | - * @param int $i I |
|
| 3963 | - * @param int $dateSelector 1=Show also date range input fields |
|
| 3964 | - * @param string $seller Object of seller third party |
|
| 3965 | - * @param string $buyer Object of buyer third party |
|
| 3966 | - * @param int $selected Object line selected |
|
| 3967 | - * @param int $extrafieldsline Object of extrafield line attribute |
|
| 3968 | - * @return void |
|
| 3969 | - */ |
|
| 3970 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3971 | - {
|
|
| 3972 | - global $conf,$langs,$user,$object,$hookmanager; |
|
| 3973 | - global $form,$bc,$bcdd; |
|
| 3974 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3975 | - |
|
| 3976 | - $object_rights = $this->getRights(); |
|
| 3977 | - |
|
| 3978 | - $element=$this->element; |
|
| 3979 | - |
|
| 3980 | - $text=''; $description=''; $type=0; |
|
| 3981 | - |
|
| 3982 | - // Show product and description |
|
| 3983 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 3984 | - // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
|
| 3985 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3986 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 3987 | - |
|
| 3988 | - // Ligne en mode visu |
|
| 3989 | - if ($action != 'editline' || $selected != $line->id) |
|
| 3990 | - {
|
|
| 3991 | - // Product |
|
| 3992 | - if ($line->fk_product > 0) |
|
| 3993 | - {
|
|
| 3994 | - $product_static = new Product($this->db); |
|
| 3995 | - $product_static->fetch($line->fk_product); |
|
| 1223 | + $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
|
| 1224 | + if ($force_thirdparty_id) |
|
| 1225 | + $idtofetch = $force_thirdparty_id; |
|
| 3996 | 1226 | |
| 3997 | - $product_static->ref = $line->ref; //can change ref in hook |
|
| 3998 | - $product_static->label = $line->label; //can change label in hook |
|
| 3999 | - $text=$product_static->getNomUrl(1); |
|
| 1227 | + if ($idtofetch) {
|
|
| 1228 | + $thirdparty = new Societe($this->db); |
|
| 1229 | + $result = $thirdparty->fetch($idtofetch); |
|
| 1230 | + $this->thirdparty = $thirdparty; |
|
| 4000 | 1231 | |
| 4001 | - // Define output language and label |
|
| 4002 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
| 4003 | - {
|
|
| 4004 | - if (! is_object($this->thirdparty)) |
|
| 4005 | - {
|
|
| 4006 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
|
|
| 4007 | - return; |
|
| 4008 | - } |
|
| 4009 | - |
|
| 4010 | - $prod = new Product($this->db); |
|
| 4011 | - $prod->fetch($line->fk_product); |
|
| 4012 | - |
|
| 4013 | - $outputlangs = $langs; |
|
| 4014 | - $newlang=''; |
|
| 4015 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4016 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
| 4017 | - if (! empty($newlang)) |
|
| 4018 | - {
|
|
| 4019 | - $outputlangs = new Translate("",$conf);
|
|
| 4020 | - $outputlangs->setDefaultLang($newlang); |
|
| 4021 | - } |
|
| 4022 | - |
|
| 4023 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4024 | - } |
|
| 4025 | - else |
|
| 4026 | - {
|
|
| 4027 | - $label = $line->product_label; |
|
| 4028 | - } |
|
| 1232 | + // Use first price level if level not defined for third party |
|
| 1233 | + if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) {
|
|
| 1234 | + $this->thirdparty->price_level = 1; |
|
| 1235 | + } |
|
| 4029 | 1236 | |
| 4030 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 4031 | - $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. |
|
| 4032 | - } |
|
| 1237 | + return $result; |
|
| 1238 | + } else |
|
| 1239 | + return -1; |
|
| 1240 | + } |
|
| 4033 | 1241 | |
| 4034 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4035 | 1242 | |
| 4036 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4037 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 4038 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4039 | - foreach($dirtpls as $reldir) |
|
| 4040 | - {
|
|
| 4041 | - $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
| 4042 | - if (empty($conf->file->strict_mode)) {
|
|
| 4043 | - $res=@include $tpl; |
|
| 4044 | - } else {
|
|
| 4045 | - $res=include $tpl; // for debug |
|
| 4046 | - } |
|
| 4047 | - if ($res) break; |
|
| 4048 | - } |
|
| 4049 | - } |
|
| 4050 | - |
|
| 4051 | - // Ligne en mode update |
|
| 4052 | - if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
|
| 4053 | - {
|
|
| 4054 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4055 | - $placeholder=' placeholder="'.$langs->trans("Label").'"';
|
|
| 4056 | - |
|
| 4057 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4058 | - |
|
| 4059 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4060 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 4061 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4062 | - foreach($dirtpls as $reldir) |
|
| 4063 | - {
|
|
| 4064 | - $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
| 4065 | - if (empty($conf->file->strict_mode)) {
|
|
| 4066 | - $res=@include $tpl; |
|
| 4067 | - } else {
|
|
| 4068 | - $res=include $tpl; // for debug |
|
| 4069 | - } |
|
| 4070 | - if ($res) break; |
|
| 4071 | - } |
|
| 4072 | - } |
|
| 4073 | - } |
|
| 4074 | - |
|
| 4075 | - |
|
| 4076 | - /* This is to show array of line of details of source object */ |
|
| 4077 | - |
|
| 4078 | - |
|
| 4079 | - /** |
|
| 4080 | - * Return HTML table table of source object lines |
|
| 4081 | - * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4082 | - * If lines are into a template, title must also be into a template |
|
| 4083 | - * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. |
|
| 4084 | - * |
|
| 4085 | - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
|
| 4086 | - * @return void |
|
| 4087 | - */ |
|
| 4088 | - function printOriginLinesList($restrictlist='') |
|
| 4089 | - {
|
|
| 4090 | - global $langs, $hookmanager, $conf; |
|
| 4091 | - |
|
| 4092 | - print '<tr class="liste_titre">'; |
|
| 4093 | - print '<td>'.$langs->trans('Ref').'</td>';
|
|
| 4094 | - print '<td>'.$langs->trans('Description').'</td>';
|
|
| 4095 | - print '<td align="right">'.$langs->trans('VATRate').'</td>';
|
|
| 4096 | - print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
|
| 4097 | - if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
|
|
| 4098 | - print '<td align="right">'.$langs->trans('Qty').'</td>';
|
|
| 4099 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 4100 | - {
|
|
| 4101 | - print '<td align="left">'.$langs->trans('Unit').'</td>';
|
|
| 4102 | - } |
|
| 4103 | - print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
|
|
| 4104 | - |
|
| 4105 | - $var = true; |
|
| 4106 | - $i = 0; |
|
| 4107 | - |
|
| 4108 | - if (! empty($this->lines)) |
|
| 4109 | - {
|
|
| 4110 | - foreach ($this->lines as $line) |
|
| 4111 | - {
|
|
| 4112 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 4113 | - {
|
|
| 4114 | - if (empty($line->fk_parent_line)) |
|
| 4115 | - {
|
|
| 4116 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i);
|
|
| 4117 | - $action=''; |
|
| 4118 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
| 4119 | - } |
|
| 4120 | - } |
|
| 4121 | - else |
|
| 4122 | - {
|
|
| 4123 | - $this->printOriginLine($line, $var, $restrictlist); |
|
| 4124 | - } |
|
| 1243 | + /** |
|
| 1244 | + * Looks for an object with ref matching the wildcard provided |
|
| 1245 | + * It does only work when $this->table_ref_field is set |
|
| 1246 | + * |
|
| 1247 | + * @param string $ref Wildcard |
|
| 1248 | + * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO |
|
| 1249 | + */ |
|
| 1250 | + public function fetchOneLike($ref) |
|
| 1251 | + {
|
|
| 1252 | + if (!$this->table_ref_field) {
|
|
| 1253 | + return 0; |
|
| 1254 | + } |
|
| 4125 | 1255 | |
| 4126 | - $i++; |
|
| 4127 | - } |
|
| 4128 | - } |
|
| 4129 | - } |
|
| 4130 | - |
|
| 4131 | - /** |
|
| 4132 | - * Return HTML with a line of table array of source object lines |
|
| 4133 | - * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4134 | - * If lines are into a template, title must also be into a template |
|
| 4135 | - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 4136 | - * |
|
| 4137 | - * @param CommonObjectLine $line Line |
|
| 4138 | - * @param string $var Var |
|
| 4139 | - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
|
| 4140 | - * @return void |
|
| 4141 | - */ |
|
| 4142 | - function printOriginLine($line, $var, $restrictlist='') |
|
| 4143 | - {
|
|
| 4144 | - global $langs, $conf; |
|
| 4145 | - |
|
| 4146 | - //var_dump($line); |
|
| 4147 | - if (!empty($line->date_start)) |
|
| 4148 | - {
|
|
| 4149 | - $date_start=$line->date_start; |
|
| 4150 | - } |
|
| 4151 | - else |
|
| 4152 | - {
|
|
| 4153 | - $date_start=$line->date_debut_prevue; |
|
| 4154 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4155 | - } |
|
| 4156 | - if (!empty($line->date_end)) |
|
| 4157 | - {
|
|
| 4158 | - $date_end=$line->date_end; |
|
| 4159 | - } |
|
| 4160 | - else |
|
| 4161 | - {
|
|
| 4162 | - $date_end=$line->date_fin_prevue; |
|
| 4163 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4164 | - } |
|
| 4165 | - |
|
| 4166 | - $this->tpl['label'] = ''; |
|
| 4167 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4168 | - |
|
| 4169 | - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4170 | - {
|
|
| 4171 | - $discount=new DiscountAbsolute($this->db); |
|
| 4172 | - $discount->fk_soc = $this->socid; |
|
| 4173 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 4174 | - } |
|
| 4175 | - else if (! empty($line->fk_product)) |
|
| 4176 | - {
|
|
| 4177 | - $productstatic = new Product($this->db); |
|
| 4178 | - $productstatic->id = $line->fk_product; |
|
| 4179 | - $productstatic->ref = $line->ref; |
|
| 4180 | - $productstatic->type = $line->fk_product_type; |
|
| 4181 | - if(empty($productstatic->ref)){
|
|
| 4182 | - $line->fetch_product(); |
|
| 4183 | - $productstatic = $line->product; |
|
| 4184 | - } |
|
| 4185 | - |
|
| 4186 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 4187 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 4188 | - // Dates |
|
| 4189 | - if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4190 | - {
|
|
| 4191 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4192 | - } |
|
| 4193 | - } |
|
| 4194 | - else |
|
| 4195 | - {
|
|
| 4196 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
|
| 4197 | - if (!empty($line->desc)) {
|
|
| 4198 | - $this->tpl['label'].=$line->desc; |
|
| 4199 | - }else {
|
|
| 4200 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 4201 | - } |
|
| 4202 | - |
|
| 4203 | - // Dates |
|
| 4204 | - if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4205 | - {
|
|
| 4206 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4207 | - } |
|
| 4208 | - } |
|
| 1256 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
| 4209 | 1257 | |
| 4210 | - if (! empty($line->desc)) |
|
| 4211 | - {
|
|
| 4212 | - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4213 | - {
|
|
| 4214 | - $discount=new DiscountAbsolute($this->db); |
|
| 4215 | - $discount->fetch($line->fk_remise_except); |
|
| 4216 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
|
| 4217 | - } |
|
| 4218 | - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4219 | - {
|
|
| 4220 | - $discount=new DiscountAbsolute($this->db); |
|
| 4221 | - $discount->fetch($line->fk_remise_except); |
|
| 4222 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
|
| 4223 | - } |
|
| 4224 | - elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4225 | - {
|
|
| 4226 | - $discount=new DiscountAbsolute($this->db); |
|
| 4227 | - $discount->fetch($line->fk_remise_except); |
|
| 4228 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
|
| 4229 | - } |
|
| 4230 | - elseif ($line->desc == '(EXCESS PAID)') |
|
| 4231 | - {
|
|
| 4232 | - $discount=new DiscountAbsolute($this->db); |
|
| 4233 | - $discount->fetch($line->fk_remise_except); |
|
| 4234 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
|
| 4235 | - } |
|
| 4236 | - else |
|
| 4237 | - {
|
|
| 4238 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 4239 | - } |
|
| 4240 | - } |
|
| 4241 | - else |
|
| 4242 | - {
|
|
| 4243 | - $this->tpl['description'] = ' '; |
|
| 4244 | - } |
|
| 1258 | + $query = $this->db->query($sql); |
|
| 4245 | 1259 | |
| 4246 | - // VAT Rate |
|
| 4247 | - $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
|
| 4248 | - $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
|
| 4249 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 1260 | + if (!$this->db->num_rows($query)) {
|
|
| 1261 | + return 0; |
|
| 1262 | + } |
|
| 4250 | 1263 | |
| 4251 | - $this->tpl['price'] = price($line->subprice); |
|
| 4252 | - $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
|
| 4253 | - $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
|
| 4254 | - if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
|
|
| 4255 | - $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
|
| 4256 | - |
|
| 4257 | - // Is the line strike or not |
|
| 4258 | - $this->tpl['strike']=0; |
|
| 4259 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4260 | - |
|
| 4261 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4262 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 4263 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4264 | - foreach($dirtpls as $reldir) |
|
| 4265 | - {
|
|
| 4266 | - $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
| 4267 | - if (empty($conf->file->strict_mode)) {
|
|
| 4268 | - $res=@include $tpl; |
|
| 4269 | - } else {
|
|
| 4270 | - $res=include $tpl; // for debug |
|
| 4271 | - } |
|
| 4272 | - if ($res) break; |
|
| 4273 | - } |
|
| 4274 | - } |
|
| 1264 | + $result = $this->db->fetch_object($query); |
|
| 4275 | 1265 | |
| 1266 | + return $this->fetch($result->rowid); |
|
| 1267 | + } |
|
| 4276 | 1268 | |
| 4277 | 1269 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 4278 | - /** |
|
| 4279 | - * Add resources to the current object : add entry into llx_element_resources |
|
| 4280 | - * Need $this->element & $this->id |
|
| 4281 | - * |
|
| 4282 | - * @param int $resource_id Resource id |
|
| 4283 | - * @param string $resource_type 'resource' |
|
| 4284 | - * @param int $busy Busy or not |
|
| 4285 | - * @param int $mandatory Mandatory or not |
|
| 4286 | - * @return int <=0 if KO, >0 if OK |
|
| 4287 | - */ |
|
| 4288 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4289 | - {
|
|
| 1270 | + /** |
|
| 1271 | + * Load data for barcode into properties ->barcode_type* |
|
| 1272 | + * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but |
|
| 1273 | + * if it is not defined, ->element must be defined to know default barcode type. |
|
| 1274 | + * |
|
| 1275 | + * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) |
|
| 1276 | + */ |
|
| 1277 | + function fetch_barcode() |
|
| 1278 | + {
|
|
| 4290 | 1279 | // phpcs:enable |
| 4291 | - $this->db->begin(); |
|
| 4292 | - |
|
| 4293 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
|
| 4294 | - $sql.= "resource_id"; |
|
| 4295 | - $sql.= ", resource_type"; |
|
| 4296 | - $sql.= ", element_id"; |
|
| 4297 | - $sql.= ", element_type"; |
|
| 4298 | - $sql.= ", busy"; |
|
| 4299 | - $sql.= ", mandatory"; |
|
| 4300 | - $sql.= ") VALUES (";
|
|
| 4301 | - $sql.= $resource_id; |
|
| 4302 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4303 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4304 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4305 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4306 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4307 | - $sql.= ")"; |
|
| 4308 | - |
|
| 4309 | - dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
| 4310 | - if ($this->db->query($sql)) |
|
| 4311 | - {
|
|
| 4312 | - $this->db->commit(); |
|
| 4313 | - return 1; |
|
| 4314 | - } |
|
| 4315 | - else |
|
| 4316 | - {
|
|
| 4317 | - $this->error=$this->db->lasterror(); |
|
| 4318 | - $this->db->rollback(); |
|
| 4319 | - return 0; |
|
| 4320 | - } |
|
| 4321 | - } |
|
| 1280 | + global $conf; |
|
| 1281 | + |
|
| 1282 | + dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
| 1283 | + |
|
| 1284 | + $idtype=$this->barcode_type; |
|
| 1285 | + 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 |
|
| 1286 | + {
|
|
| 1287 | + if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1288 | + else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1289 | + else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
|
|
| 1290 | + } |
|
| 1291 | + |
|
| 1292 | + if ($idtype > 0) |
|
| 1293 | + {
|
|
| 1294 | + 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 |
|
| 1295 | + {
|
|
| 1296 | + $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1297 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1298 | + $sql.= " WHERE rowid = ".$idtype; |
|
| 1299 | + dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
| 1300 | + $resql = $this->db->query($sql); |
|
| 1301 | + if ($resql) |
|
| 1302 | + {
|
|
| 1303 | + $obj = $this->db->fetch_object($resql); |
|
| 1304 | + $this->barcode_type = $obj->rowid; |
|
| 1305 | + $this->barcode_type_code = $obj->code; |
|
| 1306 | + $this->barcode_type_label = $obj->label; |
|
| 1307 | + $this->barcode_type_coder = $obj->coder; |
|
| 1308 | + return 1; |
|
| 1309 | + } |
|
| 1310 | + else |
|
| 1311 | + {
|
|
| 1312 | + dol_print_error($this->db); |
|
| 1313 | + return -1; |
|
| 1314 | + } |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + return 0; |
|
| 1318 | + } |
|
| 4322 | 1319 | |
| 4323 | 1320 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 4324 | - /** |
|
| 4325 | - * Delete a link to resource line |
|
| 4326 | - * |
|
| 4327 | - * @param int $rowid Id of resource line to delete |
|
| 4328 | - * @param int $element element name (for trigger) TODO: use $this->element into commonobject class |
|
| 4329 | - * @param int $notrigger Disable all triggers |
|
| 4330 | - * @return int >0 if OK, <0 if KO |
|
| 4331 | - */ |
|
| 4332 | - function delete_resource($rowid, $element, $notrigger=0) |
|
| 4333 | - {
|
|
| 1321 | + /** |
|
| 1322 | + * Load the project with id $this->fk_project into this->project |
|
| 1323 | + * |
|
| 1324 | + * @return int <0 if KO, >=0 if OK |
|
| 1325 | + */ |
|
| 1326 | + function fetch_projet() |
|
| 1327 | + {
|
|
| 4334 | 1328 | // phpcs:enable |
| 4335 | - global $user; |
|
| 4336 | - |
|
| 4337 | - $this->db->begin(); |
|
| 1329 | + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 4338 | 1330 | |
| 4339 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
| 4340 | - $sql.= " WHERE rowid=".$rowid; |
|
| 1331 | + if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1332 | + if (empty($this->fk_project)) return 0; |
|
| 4341 | 1333 | |
| 4342 | - dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
| 1334 | + $project = new Project($this->db); |
|
| 1335 | + $result = $project->fetch($this->fk_project); |
|
| 4343 | 1336 | |
| 4344 | - $resql=$this->db->query($sql); |
|
| 4345 | - if (! $resql) |
|
| 4346 | - {
|
|
| 4347 | - $this->error=$this->db->lasterror(); |
|
| 4348 | - $this->db->rollback(); |
|
| 4349 | - return -1; |
|
| 4350 | - } |
|
| 4351 | - else |
|
| 4352 | - {
|
|
| 4353 | - if (! $notrigger) |
|
| 4354 | - {
|
|
| 4355 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4356 | - if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 4357 | - } |
|
| 4358 | - $this->db->commit(); |
|
| 4359 | - return 1; |
|
| 4360 | - } |
|
| 4361 | - } |
|
| 4362 | - |
|
| 4363 | - |
|
| 4364 | - /** |
|
| 4365 | - * Overwrite magic function to solve problem of cloning object that are kept as references |
|
| 4366 | - * |
|
| 4367 | - * @return void |
|
| 4368 | - */ |
|
| 4369 | - function __clone() |
|
| 4370 | - {
|
|
| 4371 | - // Force a copy of this->lines, otherwise it will point to same object. |
|
| 4372 | - if (isset($this->lines) && is_array($this->lines)) |
|
| 4373 | - {
|
|
| 4374 | - $nboflines=count($this->lines); |
|
| 4375 | - for($i=0; $i < $nboflines; $i++) |
|
| 4376 | - {
|
|
| 4377 | - $this->lines[$i] = clone $this->lines[$i]; |
|
| 4378 | - } |
|
| 4379 | - } |
|
| 4380 | - } |
|
| 4381 | - |
|
| 4382 | - /** |
|
| 4383 | - * Common function for all objects extending CommonObject for generating documents |
|
| 4384 | - * |
|
| 4385 | - * @param string $modelspath Relative folder where generators are placed |
|
| 4386 | - * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
|
|
| 4387 | - * @param Translate $outputlangs Output language to use |
|
| 4388 | - * @param int $hidedetails 1 to hide details. 0 by default |
|
| 4389 | - * @param int $hidedesc 1 to hide product description. 0 by default |
|
| 4390 | - * @param int $hideref 1 to hide product reference. 0 by default |
|
| 4391 | - * @param null|array $moreparams Array to provide more information |
|
| 4392 | - * @return int >0 if OK, <0 if KO |
|
| 4393 | - * @see addFileIntoDatabaseIndex |
|
| 4394 | - */ |
|
| 4395 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4396 | - {
|
|
| 4397 | - global $conf, $langs, $user; |
|
| 4398 | - |
|
| 4399 | - $srctemplatepath=''; |
|
| 4400 | - |
|
| 4401 | - // Increase limit for PDF build |
|
| 4402 | - $err=error_reporting(); |
|
| 4403 | - error_reporting(0); |
|
| 4404 | - @set_time_limit(120); |
|
| 4405 | - error_reporting($err); |
|
| 4406 | - |
|
| 4407 | - // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
|
| 4408 | - $tmp=explode(':',$modele,2);
|
|
| 4409 | - if (! empty($tmp[1])) |
|
| 4410 | - {
|
|
| 4411 | - $modele=$tmp[0]; |
|
| 4412 | - $srctemplatepath=$tmp[1]; |
|
| 4413 | - } |
|
| 4414 | - |
|
| 4415 | - // Search template files |
|
| 4416 | - $file=''; $classname=''; $filefound=0; |
|
| 4417 | - $dirmodels=array('/');
|
|
| 4418 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4419 | - foreach($dirmodels as $reldir) |
|
| 4420 | - {
|
|
| 4421 | - foreach(array('doc','pdf') as $prefix)
|
|
| 4422 | - {
|
|
| 4423 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4424 | - else $file = $prefix."_".$modele.".modules.php"; |
|
| 1337 | + $this->projet = $project; // deprecated |
|
| 1338 | + $this->project = $project; |
|
| 1339 | + return $result; |
|
| 1340 | + } |
|
| 4425 | 1341 | |
| 4426 | - // On verifie l'emplacement du modele |
|
| 4427 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4428 | - if (file_exists($file)) |
|
| 4429 | - {
|
|
| 4430 | - $filefound=1; |
|
| 4431 | - $classname=$prefix.'_'.$modele; |
|
| 4432 | - break; |
|
| 4433 | - } |
|
| 4434 | - } |
|
| 4435 | - if ($filefound) break; |
|
| 4436 | - } |
|
| 1342 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1343 | + /** |
|
| 1344 | + * Load the product with id $this->fk_product into this->product |
|
| 1345 | + * |
|
| 1346 | + * @return int <0 if KO, >=0 if OK |
|
| 1347 | + */ |
|
| 1348 | + function fetch_product() |
|
| 1349 | + {
|
|
| 1350 | + // phpcs:enable |
|
| 1351 | + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 4437 | 1352 | |
| 4438 | - // If generator was found |
|
| 4439 | - if ($filefound) |
|
| 4440 | - {
|
|
| 4441 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 1353 | + if (empty($this->fk_product)) return 0; |
|
| 4442 | 1354 | |
| 4443 | - require_once $file; |
|
| 1355 | + $product = new Product($this->db); |
|
| 1356 | + $result = $product->fetch($this->fk_product); |
|
| 4444 | 1357 | |
| 4445 | - $obj = new $classname($this->db); |
|
| 1358 | + $this->product = $product; |
|
| 1359 | + return $result; |
|
| 1360 | + } |
|
| 4446 | 1361 | |
| 4447 | - // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
|
| 4448 | - if ($obj->type == 'odt' && empty($srctemplatepath)) |
|
| 4449 | - {
|
|
| 4450 | - $varfortemplatedir=$obj->scandir; |
|
| 4451 | - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
| 4452 | - {
|
|
| 4453 | - $dirtoscan=$conf->global->$varfortemplatedir; |
|
| 4454 | - |
|
| 4455 | - $listoffiles=array(); |
|
| 4456 | - |
|
| 4457 | - // Now we add first model found in directories scanned |
|
| 4458 | - $listofdir=explode(',',$dirtoscan);
|
|
| 4459 | - foreach($listofdir as $key => $tmpdir) |
|
| 4460 | - {
|
|
| 4461 | - $tmpdir=trim($tmpdir); |
|
| 4462 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
|
| 4463 | - if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
|
| 4464 | - if (is_dir($tmpdir)) |
|
| 4465 | - {
|
|
| 4466 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4467 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4468 | - } |
|
| 4469 | - } |
|
| 4470 | - |
|
| 4471 | - if (count($listoffiles)) |
|
| 4472 | - {
|
|
| 4473 | - foreach($listoffiles as $record) |
|
| 4474 | - {
|
|
| 4475 | - $srctemplatepath=$record['fullname']; |
|
| 4476 | - break; |
|
| 4477 | - } |
|
| 4478 | - } |
|
| 4479 | - } |
|
| 1362 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1363 | + /** |
|
| 1364 | + * Load the user with id $userid into this->user |
|
| 1365 | + * |
|
| 1366 | + * @param int $userid Id du contact |
|
| 1367 | + * @return int <0 if KO, >0 if OK |
|
| 1368 | + */ |
|
| 1369 | + function fetch_user($userid) |
|
| 1370 | + {
|
|
| 1371 | + // phpcs:enable |
|
| 1372 | + $user = new User($this->db); |
|
| 1373 | + $result=$user->fetch($userid); |
|
| 1374 | + $this->user = $user; |
|
| 1375 | + return $result; |
|
| 1376 | + } |
|
| 4480 | 1377 | |
| 4481 | - if (empty($srctemplatepath)) |
|
| 4482 | - {
|
|
| 4483 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4484 | - return -1; |
|
| 4485 | - } |
|
| 4486 | - } |
|
| 1378 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1379 | + /** |
|
| 1380 | + * Read linked origin object |
|
| 1381 | + * |
|
| 1382 | + * @return void |
|
| 1383 | + */ |
|
| 1384 | + function fetch_origin() |
|
| 1385 | + {
|
|
| 1386 | + // phpcs:enable |
|
| 1387 | + if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1388 | + if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1389 | + if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 4487 | 1390 | |
| 4488 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4489 | - {
|
|
| 4490 | - if (! dol_is_file($srctemplatepath)) |
|
| 4491 | - {
|
|
| 4492 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4493 | - return -1; |
|
| 4494 | - } |
|
| 4495 | - } |
|
| 1391 | + $origin = $this->origin; |
|
| 4496 | 1392 | |
| 4497 | - // We save charset_output to restore it because write_file can change it if needed for |
|
| 4498 | - // output format that does not support UTF8. |
|
| 4499 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 1393 | + $classname = ucfirst($origin); |
|
| 1394 | + $this->$origin = new $classname($this->db); |
|
| 1395 | + $this->$origin->fetch($this->origin_id); |
|
| 1396 | + } |
|
| 4500 | 1397 | |
| 4501 | - if (in_array(get_class($this), array('Adherent')))
|
|
| 4502 | - {
|
|
| 4503 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4504 | - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
|
| 4505 | - } |
|
| 4506 | - else |
|
| 4507 | - {
|
|
| 4508 | - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
| 4509 | - } |
|
| 4510 | - // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. |
|
| 1398 | + /** |
|
| 1399 | + * Load object from specific field |
|
| 1400 | + * |
|
| 1401 | + * @param string $table Table element or element line |
|
| 1402 | + * @param string $field Field selected |
|
| 1403 | + * @param string $key Import key |
|
| 1404 | + * @param string $element Element name |
|
| 1405 | + * @return int <0 if KO, >0 if OK |
|
| 1406 | + */ |
|
| 1407 | + function fetchObjectFrom($table, $field, $key, $element = null) |
|
| 1408 | + {
|
|
| 1409 | + global $conf; |
|
| 4511 | 1410 | |
| 4512 | - if ($resultwritefile > 0) |
|
| 4513 | - {
|
|
| 4514 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 1411 | + $result=false; |
|
| 4515 | 1412 | |
| 4516 | - // We delete old preview |
|
| 4517 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 4518 | - dol_delete_preview($this); |
|
| 1413 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
| 1414 | + $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1415 | + if (! empty($element)) {
|
|
| 1416 | + $sql.= " AND entity IN (".getEntity($element).")";
|
|
| 1417 | + } else {
|
|
| 1418 | + $sql.= " AND entity = ".$conf->entity; |
|
| 1419 | + } |
|
| 4519 | 1420 | |
| 4520 | - // Index file in database |
|
| 4521 | - if (! empty($obj->result['fullpath'])) |
|
| 4522 | - {
|
|
| 4523 | - $destfull = $obj->result['fullpath']; |
|
| 4524 | - $upload_dir = dirname($destfull); |
|
| 4525 | - $destfile = basename($destfull); |
|
| 4526 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
|
| 4527 | - |
|
| 4528 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4529 | - {
|
|
| 4530 | - $filename = basename($destfile); |
|
| 4531 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
|
| 4532 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
|
| 4533 | - |
|
| 4534 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 4535 | - $ecmfile=new EcmFiles($this->db); |
|
| 4536 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4537 | - |
|
| 4538 | - // Set the public "share" key |
|
| 4539 | - $setsharekey = false; |
|
| 4540 | - if ($this->element == 'propal') |
|
| 4541 | - {
|
|
| 4542 | - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4543 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4544 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4545 | - } |
|
| 4546 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4547 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4548 | - if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4549 | - |
|
| 4550 | - if ($setsharekey) |
|
| 4551 | - {
|
|
| 4552 | - if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4553 | - {
|
|
| 4554 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4555 | - $ecmfile->share = getRandomPassword(true); |
|
| 4556 | - } |
|
| 4557 | - } |
|
| 1421 | + dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
| 1422 | + $resql = $this->db->query($sql); |
|
| 1423 | + if ($resql) |
|
| 1424 | + {
|
|
| 1425 | + $row = $this->db->fetch_row($resql); |
|
| 1426 | + // Test for avoid error -1 |
|
| 1427 | + if ($row[0] > 0) {
|
|
| 1428 | + $result = $this->fetch($row[0]); |
|
| 1429 | + } |
|
| 1430 | + } |
|
| 4558 | 1431 | |
| 4559 | - if ($result > 0) |
|
| 4560 | - {
|
|
| 4561 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4562 | - $ecmfile->fullpath_orig = ''; |
|
| 4563 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4564 | - $ecmfile->description = ''; // indexed content |
|
| 4565 | - $ecmfile->keyword = ''; // keyword content |
|
| 4566 | - $result = $ecmfile->update($user); |
|
| 4567 | - if ($result < 0) |
|
| 4568 | - {
|
|
| 4569 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4570 | - } |
|
| 4571 | - } |
|
| 4572 | - else |
|
| 4573 | - {
|
|
| 4574 | - $ecmfile->entity = $conf->entity; |
|
| 4575 | - $ecmfile->filepath = $rel_dir; |
|
| 4576 | - $ecmfile->filename = $filename; |
|
| 4577 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4578 | - $ecmfile->fullpath_orig = ''; |
|
| 4579 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4580 | - $ecmfile->description = ''; // indexed content |
|
| 4581 | - $ecmfile->keyword = ''; // keyword content |
|
| 4582 | - $ecmfile->src_object_type = $this->table_element; |
|
| 4583 | - $ecmfile->src_object_id = $this->id; |
|
| 4584 | - |
|
| 4585 | - $result = $ecmfile->create($user); |
|
| 4586 | - if ($result < 0) |
|
| 4587 | - {
|
|
| 4588 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4589 | - } |
|
| 4590 | - } |
|
| 1432 | + return $result; |
|
| 1433 | + } |
|
| 4591 | 1434 | |
| 4592 | - /*$this->result['fullname']=$destfull; |
|
| 4593 | - $this->result['filepath']=$ecmfile->filepath; |
|
| 4594 | - $this->result['filename']=$ecmfile->filename;*/ |
|
| 4595 | - //var_dump($obj->update_main_doc_field);exit; |
|
| 4596 | - |
|
| 4597 | - // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
|
| 4598 | - $update_main_doc_field=0; |
|
| 4599 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4600 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4601 | - {
|
|
| 4602 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
| 4603 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 4604 | - $resql = $this->db->query($sql); |
|
| 4605 | - if (! $resql) dol_print_error($this->db); |
|
| 4606 | - } |
|
| 4607 | - } |
|
| 4608 | - } |
|
| 4609 | - else |
|
| 4610 | - {
|
|
| 4611 | - dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
|
|
| 4612 | - } |
|
| 1435 | + /** |
|
| 1436 | + * Getter generic. Load value from a specific field |
|
| 1437 | + * |
|
| 1438 | + * @param string $table Table of element or element line |
|
| 1439 | + * @param int $id Element id |
|
| 1440 | + * @param string $field Field selected |
|
| 1441 | + * @return int <0 if KO, >0 if OK |
|
| 1442 | + */ |
|
| 1443 | + function getValueFrom($table, $id, $field) |
|
| 1444 | + {
|
|
| 1445 | + $result=false; |
|
| 1446 | + if (!empty($id) && !empty($field) && !empty($table)) {
|
|
| 1447 | + $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
| 1448 | + $sql.= " WHERE rowid = ".$id; |
|
| 1449 | + |
|
| 1450 | + dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
| 1451 | + $resql = $this->db->query($sql); |
|
| 1452 | + if ($resql) |
|
| 1453 | + {
|
|
| 1454 | + $row = $this->db->fetch_row($resql); |
|
| 1455 | + $result = $row[0]; |
|
| 1456 | + } |
|
| 1457 | + } |
|
| 1458 | + return $result; |
|
| 1459 | + } |
|
| 4613 | 1460 | |
| 4614 | - // Success in building document. We build meta file. |
|
| 4615 | - dol_meta_create($this); |
|
| 1461 | + /** |
|
| 1462 | + * Setter generic. Update a specific field into database. |
|
| 1463 | + * Warning: Trigger is run only if param trigkey is provided. |
|
| 1464 | + * |
|
| 1465 | + * @param string $field Field to update |
|
| 1466 | + * @param mixed $value New value |
|
| 1467 | + * @param string $table To force other table element or element line (should not be used) |
|
| 1468 | + * @param int $id To force other object id (should not be used) |
|
| 1469 | + * @param string $format Data format ('text', 'date'). 'text' is used if not defined
|
|
| 1470 | + * @param string $id_field To force rowid field name. 'rowid' is used if not defined |
|
| 1471 | + * @param User|string $fuser Update the user of last update field with this user. If not provided, current user is used except if value is 'none' |
|
| 1472 | + * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') |
|
| 1473 | + * @param string $fk_user_field Name of field to save user id making change |
|
| 1474 | + * @return int <0 if KO, >0 if OK |
|
| 1475 | + * @see updateExtraField |
|
| 1476 | + */ |
|
| 1477 | + function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
| 1478 | + {
|
|
| 1479 | + global $user,$langs,$conf; |
|
| 4616 | 1480 | |
| 4617 | - return 1; |
|
| 4618 | - } |
|
| 4619 | - else |
|
| 4620 | - {
|
|
| 4621 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4622 | - dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
| 4623 | - return -1; |
|
| 4624 | - } |
|
| 4625 | - } |
|
| 4626 | - else |
|
| 4627 | - {
|
|
| 4628 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
|
| 4629 | - dol_print_error('',$this->error);
|
|
| 4630 | - return -1; |
|
| 4631 | - } |
|
| 4632 | - } |
|
| 4633 | - |
|
| 4634 | - /** |
|
| 4635 | - * Build thumb |
|
| 4636 | - * @TODO Move this into files.lib.php |
|
| 4637 | - * |
|
| 4638 | - * @param string $file Path file in UTF8 to original file to create thumbs from. |
|
| 4639 | - * @return void |
|
| 4640 | - */ |
|
| 4641 | - function addThumbs($file) |
|
| 4642 | - {
|
|
| 4643 | - global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
|
| 4644 | - |
|
| 4645 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4646 | - |
|
| 4647 | - $file_osencoded=dol_osencode($file); |
|
| 4648 | - if (file_exists($file_osencoded)) |
|
| 4649 | - {
|
|
| 4650 | - // Create small thumbs for company (Ratio is near 16/9) |
|
| 4651 | - // Used on logon for example |
|
| 4652 | - vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); |
|
| 4653 | - |
|
| 4654 | - // Create mini thumbs for company (Ratio is near 16/9) |
|
| 4655 | - // Used on menu or for setup page for example |
|
| 4656 | - vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); |
|
| 4657 | - } |
|
| 4658 | - } |
|
| 4659 | - |
|
| 4660 | - |
|
| 4661 | - /* Functions common to commonobject and commonobjectline */ |
|
| 4662 | - |
|
| 4663 | - /* For default values */ |
|
| 4664 | - |
|
| 4665 | - /** |
|
| 4666 | - * Return the default value to use for a field when showing the create form of object. |
|
| 4667 | - * Return values in this order: |
|
| 4668 | - * 1) If parameter is available into POST, we return it first. |
|
| 4669 | - * 2) If not but an alternate value was provided as parameter of function, we return it. |
|
| 4670 | - * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). |
|
| 4671 | - * 4) Return value found into database (TODO No yet implemented) |
|
| 4672 | - * |
|
| 4673 | - * @param string $fieldname Name of field |
|
| 4674 | - * @param string $alternatevalue Alternate value to use |
|
| 4675 | - * @return string|string[] Default value (can be an array if the GETPOST return an array) |
|
| 4676 | - **/ |
|
| 4677 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4678 | - {
|
|
| 4679 | - global $conf, $_POST; |
|
| 4680 | - |
|
| 4681 | - // If param here has been posted, we use this value first. |
|
| 4682 | - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 4683 | - |
|
| 4684 | - if (isset($alternatevalue)) return $alternatevalue; |
|
| 4685 | - |
|
| 4686 | - $newelement=$this->element; |
|
| 4687 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4688 | - if ($newelement == 'commande') $newelement='order'; |
|
| 4689 | - if (empty($newelement)) |
|
| 4690 | - {
|
|
| 4691 | - dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
|
| 4692 | - return ''; |
|
| 4693 | - } |
|
| 4694 | - |
|
| 4695 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4696 | - //var_dump($keyforfieldname); |
|
| 4697 | - if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
|
| 4698 | - |
|
| 4699 | - // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
|
| 4700 | - } |
|
| 4701 | - |
|
| 4702 | - |
|
| 4703 | - /* For triggers */ |
|
| 1481 | + if (empty($table)) $table=$this->table_element; |
|
| 1482 | + if (empty($id)) $id=$this->id; |
|
| 1483 | + if (empty($format)) $format='text'; |
|
| 1484 | + if (empty($id_field)) $id_field='rowid'; |
|
| 4704 | 1485 | |
| 1486 | + $error=0; |
|
| 4705 | 1487 | |
| 4706 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4707 | - /** |
|
| 4708 | - * Call trigger based on this instance. |
|
| 4709 | - * Some context information may also be provided into array property this->context. |
|
| 4710 | - * NB: Error from trigger are stacked in interface->errors |
|
| 4711 | - * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. |
|
| 4712 | - * |
|
| 4713 | - * @param string $trigger_name trigger's name to execute |
|
| 4714 | - * @param User $user Object user |
|
| 4715 | - * @return int Result of run_triggers |
|
| 4716 | - */ |
|
| 4717 | - function call_trigger($trigger_name, $user) |
|
| 4718 | - {
|
|
| 4719 | - // phpcs:enable |
|
| 4720 | - global $langs,$conf; |
|
| 1488 | + $this->db->begin(); |
|
| 4721 | 1489 | |
| 4722 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4723 | - $interface=new Interfaces($this->db); |
|
| 4724 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 1490 | + // Special case |
|
| 1491 | + if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1492 | + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
|
| 4725 | 1493 | |
| 4726 | - if ($result < 0) |
|
| 4727 | - {
|
|
| 4728 | - if (!empty($this->errors)) |
|
| 4729 | - {
|
|
| 4730 | - $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. |
|
| 4731 | - } |
|
| 4732 | - else |
|
| 4733 | - {
|
|
| 4734 | - $this->errors=$interface->errors; |
|
| 4735 | - } |
|
| 4736 | - } |
|
| 4737 | - return $result; |
|
| 4738 | - } |
|
| 1494 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
| 4739 | 1495 | |
| 1496 | + if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1497 | + else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1498 | + else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 4740 | 1499 | |
| 4741 | - /* Functions for extrafields */ |
|
| 1500 | + if ($fk_user_field) |
|
| 1501 | + {
|
|
| 1502 | + if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1503 | + elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1504 | + } |
|
| 4742 | 1505 | |
| 1506 | + $sql.= " WHERE ".$id_field." = ".$id; |
|
| 4743 | 1507 | |
| 4744 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4745 | - /** |
|
| 4746 | - * Function to get extra fields of an object into $this->array_options |
|
| 4747 | - * This method is in most cases called by method fetch of objects but you can call it separately. |
|
| 4748 | - * |
|
| 4749 | - * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. |
|
| 4750 | - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
|
| 4751 | - * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
|
| 4752 | - */ |
|
| 4753 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4754 | - {
|
|
| 4755 | - // phpcs:enable |
|
| 4756 | - if (empty($rowid)) $rowid=$this->id; |
|
| 4757 | - |
|
| 4758 | - // To avoid SQL errors. Probably not the better solution though |
|
| 4759 | - if (!$this->table_element) {
|
|
| 4760 | - return 0; |
|
| 4761 | - } |
|
| 4762 | - |
|
| 4763 | - $this->array_options=array(); |
|
| 4764 | - |
|
| 4765 | - if (! is_array($optionsArray)) |
|
| 4766 | - {
|
|
| 4767 | - // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
|
| 4768 | - // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
|
| 4769 | - // global $extrafields; |
|
| 4770 | - //if (! is_object($extrafields)) |
|
| 4771 | - //{
|
|
| 4772 | - // require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4773 | - $extrafields = new ExtraFields(); |
|
| 4774 | - //} |
|
| 1508 | + dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
| 1509 | + $resql = $this->db->query($sql); |
|
| 1510 | + if ($resql) |
|
| 1511 | + {
|
|
| 1512 | + if ($trigkey) |
|
| 1513 | + {
|
|
| 1514 | + // call trigger with updated object values |
|
| 1515 | + if (empty($this->fields) && method_exists($this, 'fetch')) |
|
| 1516 | + {
|
|
| 1517 | + $result = $this->fetch($id); |
|
| 1518 | + } |
|
| 1519 | + else |
|
| 1520 | + {
|
|
| 1521 | + $result = $this->fetchCommon($id); |
|
| 1522 | + } |
|
| 1523 | + if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1524 | + if ($result < 0) $error++; |
|
| 1525 | + } |
|
| 4775 | 1526 | |
| 4776 | - // Load array of extrafields for elementype = $this->table_element |
|
| 4777 | - if (empty($extrafields->attributes[$this->table_element]['loaded'])) |
|
| 4778 | - {
|
|
| 4779 | - $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4780 | - } |
|
| 4781 | - $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
| 4782 | - } |
|
| 4783 | - else |
|
| 4784 | - {
|
|
| 4785 | - global $extrafields; |
|
| 4786 | - dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
|
|
| 4787 | - } |
|
| 4788 | - |
|
| 4789 | - $table_element = $this->table_element; |
|
| 4790 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4791 | - |
|
| 4792 | - // Request to get complementary values |
|
| 4793 | - if (is_array($optionsArray) && count($optionsArray) > 0) |
|
| 4794 | - {
|
|
| 4795 | - $sql = "SELECT rowid"; |
|
| 4796 | - foreach ($optionsArray as $name => $label) |
|
| 4797 | - {
|
|
| 4798 | - if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
|
| 4799 | - {
|
|
| 4800 | - $sql.= ", ".$name; |
|
| 4801 | - } |
|
| 4802 | - } |
|
| 4803 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4804 | - $sql.= " WHERE fk_object = ".$rowid; |
|
| 1527 | + if (! $error) |
|
| 1528 | + {
|
|
| 1529 | + if (property_exists($this, $field)) $this->$field = $value; |
|
| 1530 | + $this->db->commit(); |
|
| 1531 | + return 1; |
|
| 1532 | + } |
|
| 1533 | + else |
|
| 1534 | + {
|
|
| 1535 | + $this->db->rollback(); |
|
| 1536 | + return -2; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + else |
|
| 1540 | + {
|
|
| 1541 | + $this->error=$this->db->lasterror(); |
|
| 1542 | + $this->db->rollback(); |
|
| 1543 | + return -1; |
|
| 1544 | + } |
|
| 1545 | + } |
|
| 4805 | 1546 | |
| 4806 | - //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
|
| 4807 | - $resql=$this->db->query($sql); |
|
| 4808 | - if ($resql) |
|
| 4809 | - {
|
|
| 4810 | - $this->array_options = array(); |
|
| 4811 | - $numrows=$this->db->num_rows($resql); |
|
| 4812 | - if ($numrows) |
|
| 4813 | - {
|
|
| 4814 | - $tab = $this->db->fetch_array($resql); |
|
| 4815 | - |
|
| 4816 | - foreach ($tab as $key => $value) |
|
| 4817 | - {
|
|
| 4818 | - // 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) |
|
| 4819 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4820 | - {
|
|
| 4821 | - // we can add this attribute to object |
|
| 4822 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime')))
|
|
| 4823 | - {
|
|
| 4824 | - //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
|
| 4825 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4826 | - } |
|
| 4827 | - else |
|
| 4828 | - {
|
|
| 4829 | - $this->array_options["options_".$key]=$value; |
|
| 4830 | - } |
|
| 1547 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1548 | + /** |
|
| 1549 | + * Load properties id_previous and id_next by comparing $fieldid with $this->ref |
|
| 1550 | + * |
|
| 1551 | + * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" |
|
| 1552 | + * @param string $fieldid Name of field to use for the select MAX and MIN |
|
| 1553 | + * @param int $nodbprefix Do not include DB prefix to forge table name |
|
| 1554 | + * @return int <0 if KO, >0 if OK |
|
| 1555 | + */ |
|
| 1556 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1557 | + {
|
|
| 1558 | + // phpcs:enable |
|
| 1559 | + global $conf, $user; |
|
| 4831 | 1560 | |
| 4832 | - //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]);
|
|
| 4833 | - } |
|
| 4834 | - } |
|
| 4835 | - } |
|
| 1561 | + if (! $this->table_element) |
|
| 1562 | + {
|
|
| 1563 | + dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
|
| 1564 | + return -1; |
|
| 1565 | + } |
|
| 1566 | + if ($fieldid == 'none') return 1; |
|
| 4836 | 1567 | |
| 4837 | - $this->db->free($resql); |
|
| 1568 | + // Security on socid |
|
| 1569 | + $socid = 0; |
|
| 1570 | + if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 4838 | 1571 | |
| 4839 | - if ($numrows) return $numrows; |
|
| 4840 | - else return 0; |
|
| 4841 | - } |
|
| 4842 | - else |
|
| 4843 | - {
|
|
| 4844 | - dol_print_error($this->db); |
|
| 4845 | - return -1; |
|
| 4846 | - } |
|
| 4847 | - } |
|
| 4848 | - return 0; |
|
| 4849 | - } |
|
| 4850 | - |
|
| 4851 | - /** |
|
| 4852 | - * Delete all extra fields values for the current object. |
|
| 4853 | - * |
|
| 4854 | - * @return int <0 if KO, >0 if OK |
|
| 4855 | - */ |
|
| 4856 | - function deleteExtraFields() |
|
| 4857 | - {
|
|
| 4858 | - $this->db->begin(); |
|
| 4859 | - |
|
| 4860 | - $table_element = $this->table_element; |
|
| 4861 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4862 | - |
|
| 4863 | - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 4864 | - dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
| 4865 | - $resql=$this->db->query($sql_del); |
|
| 4866 | - if (! $resql) |
|
| 4867 | - {
|
|
| 4868 | - $this->error=$this->db->lasterror(); |
|
| 4869 | - $this->db->rollback(); |
|
| 4870 | - return -1; |
|
| 4871 | - } |
|
| 4872 | - else |
|
| 4873 | - {
|
|
| 4874 | - $this->db->commit(); |
|
| 4875 | - return 1; |
|
| 4876 | - } |
|
| 4877 | - } |
|
| 4878 | - |
|
| 4879 | - /** |
|
| 4880 | - * Add/Update all extra fields values for the current object. |
|
| 4881 | - * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 4882 | - * This function delete record with all extrafields and insert them again from the array $this->array_options. |
|
| 4883 | - * |
|
| 4884 | - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 4885 | - * @param User $userused Object user |
|
| 4886 | - * @return int -1=error, O=did nothing, 1=OK |
|
| 4887 | - * @see updateExtraField, setValueFrom |
|
| 4888 | - */ |
|
| 4889 | - function insertExtraFields($trigger='', $userused=null) |
|
| 4890 | - {
|
|
| 4891 | - global $conf,$langs,$user; |
|
| 4892 | - |
|
| 4893 | - if (empty($userused)) $userused=$user; |
|
| 4894 | - |
|
| 4895 | - $error=0; |
|
| 4896 | - |
|
| 4897 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4898 | - |
|
| 4899 | - if (! empty($this->array_options)) |
|
| 4900 | - {
|
|
| 4901 | - // Check parameters |
|
| 4902 | - $langs->load('admin');
|
|
| 4903 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4904 | - $extrafields = new ExtraFields($this->db); |
|
| 4905 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4906 | - |
|
| 4907 | - //Eliminate copied source object extra_fields that do not exist in target object |
|
| 4908 | - $new_array_options=array(); |
|
| 4909 | - foreach ($this->array_options as $key => $value) {
|
|
| 4910 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4911 | - $new_array_options[$key] = $value; |
|
| 4912 | - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 4913 | - $new_array_options['options_'.$key] = $value; |
|
| 4914 | - } |
|
| 4915 | - |
|
| 4916 | - foreach($new_array_options as $key => $value) |
|
| 4917 | - {
|
|
| 4918 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4919 | - $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
|
| 4920 | - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
|
| 4921 | - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
|
| 4922 | - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; |
|
| 4923 | - |
|
| 4924 | - if ($attributeRequired) |
|
| 4925 | - {
|
|
| 4926 | - $mandatorypb=false; |
|
| 4927 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4928 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4929 | - if ($mandatorypb) |
|
| 4930 | - {
|
|
| 4931 | - dol_syslog($this->error); |
|
| 4932 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel);
|
|
| 4933 | - return -1; |
|
| 4934 | - } |
|
| 4935 | - } |
|
| 4936 | - |
|
| 4937 | - //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 4938 | - //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 4939 | - |
|
| 4940 | - switch ($attributeType) |
|
| 4941 | - {
|
|
| 4942 | - case 'int': |
|
| 4943 | - if (!is_numeric($value) && $value!='') |
|
| 4944 | - {
|
|
| 4945 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4946 | - return -1; |
|
| 4947 | - } |
|
| 4948 | - elseif ($value=='') |
|
| 4949 | - {
|
|
| 4950 | - $new_array_options[$key] = null; |
|
| 4951 | - } |
|
| 4952 | - break; |
|
| 4953 | - case 'double': |
|
| 4954 | - $value = price2num($value); |
|
| 4955 | - if (!is_numeric($value) && $value!='') |
|
| 4956 | - {
|
|
| 4957 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 4958 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4959 | - return -1; |
|
| 4960 | - } |
|
| 4961 | - elseif ($value=='') |
|
| 4962 | - {
|
|
| 4963 | - $new_array_options[$key] = null; |
|
| 4964 | - } |
|
| 4965 | - //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 4966 | - $new_array_options[$key] = $value; |
|
| 4967 | - break; |
|
| 4968 | - /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 4969 | - if ($value=='-1') |
|
| 4970 | - {
|
|
| 4971 | - $this->array_options[$key] = null; |
|
| 4972 | - } |
|
| 4973 | - break;*/ |
|
| 4974 | - case 'password': |
|
| 4975 | - $algo=''; |
|
| 4976 | - if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
|
| 4977 | - {
|
|
| 4978 | - // If there is an encryption choice, we use it to crypt data before insert |
|
| 4979 | - $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
|
| 4980 | - $algo=reset($tmparrays); |
|
| 4981 | - if ($algo != '') |
|
| 4982 | - {
|
|
| 4983 | - //global $action; // $action may be 'create', 'update', 'update_extras'... |
|
| 4984 | - //var_dump($action); |
|
| 4985 | - //var_dump($this->oldcopy);exit; |
|
| 4986 | - if (is_object($this->oldcopy)) // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 4987 | - {
|
|
| 4988 | - //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
|
| 4989 | - 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. |
|
| 4990 | - {
|
|
| 4991 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4992 | - } |
|
| 4993 | - else |
|
| 4994 | - {
|
|
| 4995 | - // var_dump($algo); |
|
| 4996 | - $newvalue = dol_hash($this->array_options[$key], $algo); |
|
| 4997 | - $new_array_options[$key] = $newvalue; |
|
| 4998 | - } |
|
| 4999 | - } |
|
| 5000 | - else |
|
| 5001 | - {
|
|
| 5002 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5003 | - } |
|
| 5004 | - } |
|
| 5005 | - } |
|
| 5006 | - else // Common usage |
|
| 5007 | - {
|
|
| 5008 | - $new_array_options[$key] = $this->array_options[$key]; |
|
| 5009 | - } |
|
| 5010 | - break; |
|
| 5011 | - case 'price': |
|
| 5012 | - $new_array_options[$key] = price2num($this->array_options[$key]); |
|
| 5013 | - break; |
|
| 5014 | - case 'date': |
|
| 5015 | - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5016 | - break; |
|
| 5017 | - case 'datetime': |
|
| 5018 | - // If data is a string instead of a timestamp, we convert it |
|
| 5019 | - if (! is_int($this->array_options[$key])) {
|
|
| 5020 | - $this->array_options[$key] = strtotime($this->array_options[$key]); |
|
| 5021 | - } |
|
| 5022 | - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5023 | - break; |
|
| 5024 | - case 'link': |
|
| 5025 | - $param_list=array_keys($attributeParam['options']); |
|
| 5026 | - // 0 : ObjectName |
|
| 5027 | - // 1 : classPath |
|
| 5028 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5029 | - dol_include_once($InfoFieldList[1]); |
|
| 5030 | - if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
|
| 5031 | - {
|
|
| 5032 | - if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5033 | - {
|
|
| 5034 | - $new_array_options[$key]=''; |
|
| 5035 | - } |
|
| 5036 | - elseif ($value) |
|
| 5037 | - {
|
|
| 5038 | - $object = new $InfoFieldList[0]($this->db); |
|
| 5039 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5040 | - else $res=$object->fetch('',$value);
|
|
| 5041 | - |
|
| 5042 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5043 | - else |
|
| 5044 | - {
|
|
| 5045 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5046 | - $this->db->rollback(); |
|
| 5047 | - return -1; |
|
| 5048 | - } |
|
| 5049 | - } |
|
| 5050 | - } |
|
| 5051 | - else |
|
| 5052 | - {
|
|
| 5053 | - dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 5054 | - } |
|
| 5055 | - break; |
|
| 5056 | - } |
|
| 5057 | - } |
|
| 1572 | + // this->ismultientitymanaged contains |
|
| 1573 | + // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
| 1574 | + $alias = 's'; |
|
| 1575 | + if ($this->element == 'societe') $alias = 'te'; |
|
| 5058 | 1576 | |
| 5059 | - $this->db->begin(); |
|
| 1577 | + $sql = "SELECT MAX(te.".$fieldid.")"; |
|
| 1578 | + $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1579 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1580 | + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1581 | + } |
|
| 1582 | + 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 |
|
| 1583 | + 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 |
|
| 1584 | + 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 |
|
| 1585 | + 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"; |
|
| 1586 | + $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1587 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1588 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1589 | + if (! empty($filter)) |
|
| 1590 | + {
|
|
| 1591 | + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1592 | + $sql.=$filter; |
|
| 1593 | + } |
|
| 1594 | + 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 |
|
| 1595 | + 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 |
|
| 1596 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1597 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1598 | + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1599 | + $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1600 | + } else {
|
|
| 1601 | + $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1602 | + $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1603 | + } |
|
| 1604 | + } else {
|
|
| 1605 | + $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1606 | + } |
|
| 1607 | + } |
|
| 1608 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1609 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1610 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1611 | + //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 5060 | 1612 | |
| 5061 | - $table_element = $this->table_element; |
|
| 5062 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 1613 | + $result = $this->db->query($sql); |
|
| 1614 | + if (! $result) |
|
| 1615 | + {
|
|
| 1616 | + $this->error=$this->db->lasterror(); |
|
| 1617 | + return -1; |
|
| 1618 | + } |
|
| 1619 | + $row = $this->db->fetch_row($result); |
|
| 1620 | + $this->ref_previous = $row[0]; |
|
| 5063 | 1621 | |
| 5064 | - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 5065 | - dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
| 5066 | - $this->db->query($sql_del); |
|
| 5067 | 1622 | |
| 5068 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
| 5069 | - foreach($new_array_options as $key => $value) |
|
| 5070 | - {
|
|
| 5071 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5072 | - // Add field of attribut |
|
| 5073 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5074 | - $sql.=",".$attributeKey; |
|
| 5075 | - } |
|
| 5076 | - $sql .= ") VALUES (".$this->id;
|
|
| 5077 | - |
|
| 5078 | - foreach($new_array_options as $key => $value) |
|
| 5079 | - {
|
|
| 5080 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5081 | - // Add field of attribute |
|
| 5082 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5083 | - {
|
|
| 5084 | - if ($new_array_options[$key] != '') |
|
| 5085 | - {
|
|
| 5086 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5087 | - } |
|
| 5088 | - else |
|
| 5089 | - {
|
|
| 5090 | - $sql.=",null"; |
|
| 5091 | - } |
|
| 5092 | - } |
|
| 5093 | - } |
|
| 5094 | - $sql.=")"; |
|
| 1623 | + $sql = "SELECT MIN(te.".$fieldid.")"; |
|
| 1624 | + $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1625 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1626 | + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1627 | + } |
|
| 1628 | + 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 |
|
| 1629 | + 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 |
|
| 1630 | + 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 |
|
| 1631 | + 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"; |
|
| 1632 | + $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1633 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1634 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1635 | + if (! empty($filter)) |
|
| 1636 | + {
|
|
| 1637 | + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1638 | + $sql.=$filter; |
|
| 1639 | + } |
|
| 1640 | + 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 |
|
| 1641 | + 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 |
|
| 1642 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1643 | + if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1644 | + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1645 | + $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1646 | + } else {
|
|
| 1647 | + $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1648 | + $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1649 | + } |
|
| 1650 | + } else {
|
|
| 1651 | + $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1652 | + } |
|
| 1653 | + } |
|
| 1654 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1655 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1656 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1657 | + //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 1658 | + // 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 |
|
| 1659 | + |
|
| 1660 | + $result = $this->db->query($sql); |
|
| 1661 | + if (! $result) |
|
| 1662 | + {
|
|
| 1663 | + $this->error=$this->db->lasterror(); |
|
| 1664 | + return -2; |
|
| 1665 | + } |
|
| 1666 | + $row = $this->db->fetch_row($result); |
|
| 1667 | + $this->ref_next = $row[0]; |
|
| 5095 | 1668 | |
| 5096 | - dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
| 5097 | - $resql = $this->db->query($sql); |
|
| 5098 | - if (! $resql) |
|
| 5099 | - {
|
|
| 5100 | - $this->error=$this->db->lasterror(); |
|
| 5101 | - $error++; |
|
| 5102 | - } |
|
| 1669 | + return 1; |
|
| 1670 | + } |
|
| 5103 | 1671 | |
| 5104 | - if (! $error && $trigger) |
|
| 5105 | - {
|
|
| 5106 | - // Call trigger |
|
| 5107 | - $this->context=array('extrafieldaddupdate'=>1);
|
|
| 5108 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5109 | - if ($result < 0) $error++; |
|
| 5110 | - // End call trigger |
|
| 5111 | - } |
|
| 5112 | - |
|
| 5113 | - if ($error) |
|
| 5114 | - {
|
|
| 5115 | - $this->db->rollback(); |
|
| 5116 | - return -1; |
|
| 5117 | - } |
|
| 5118 | - else |
|
| 5119 | - {
|
|
| 5120 | - $this->db->commit(); |
|
| 5121 | - return 1; |
|
| 5122 | - } |
|
| 5123 | - } |
|
| 5124 | - else return 0; |
|
| 5125 | - } |
|
| 5126 | - |
|
| 5127 | - /** |
|
| 5128 | - * Update an extra field value for the current object. |
|
| 5129 | - * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 5130 | - * |
|
| 5131 | - * @param string $key Key of the extrafield (without starting 'options_') |
|
| 5132 | - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 5133 | - * @param User $userused Object user |
|
| 5134 | - * @return int -1=error, O=did nothing, 1=OK |
|
| 5135 | - * @see setValueFrom, insertExtraFields |
|
| 5136 | - */ |
|
| 5137 | - function updateExtraField($key, $trigger=null, $userused=null) |
|
| 5138 | - {
|
|
| 5139 | - global $conf,$langs,$user; |
|
| 5140 | - |
|
| 5141 | - if (empty($userused)) $userused=$user; |
|
| 5142 | - |
|
| 5143 | - $error=0; |
|
| 5144 | - |
|
| 5145 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5146 | - |
|
| 5147 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5148 | - {
|
|
| 5149 | - // Check parameters |
|
| 5150 | - $langs->load('admin');
|
|
| 5151 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 5152 | - $extrafields = new ExtraFields($this->db); |
|
| 5153 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5154 | - |
|
| 5155 | - $value=$this->array_options["options_".$key]; |
|
| 5156 | - |
|
| 5157 | - $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
|
| 5158 | - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
|
| 5159 | - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; |
|
| 5160 | - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; |
|
| 5161 | - |
|
| 5162 | - //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 5163 | - //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 5164 | - |
|
| 5165 | - switch ($attributeType) |
|
| 5166 | - {
|
|
| 5167 | - case 'int': |
|
| 5168 | - if (!is_numeric($value) && $value!='') |
|
| 5169 | - {
|
|
| 5170 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
|
| 5171 | - return -1; |
|
| 5172 | - } |
|
| 5173 | - elseif ($value=='') |
|
| 5174 | - {
|
|
| 5175 | - $this->array_options["options_".$key] = null; |
|
| 5176 | - } |
|
| 5177 | - break; |
|
| 5178 | - case 'double': |
|
| 5179 | - $value = price2num($value); |
|
| 5180 | - if (!is_numeric($value) && $value!='') |
|
| 5181 | - {
|
|
| 5182 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 5183 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5184 | - return -1; |
|
| 5185 | - } |
|
| 5186 | - elseif ($value=='') |
|
| 5187 | - {
|
|
| 5188 | - $this->array_options["options_".$key] = null; |
|
| 5189 | - } |
|
| 5190 | - //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 5191 | - $this->array_options["options_".$key] = $value; |
|
| 5192 | - break; |
|
| 5193 | - /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 5194 | - if ($value=='-1') |
|
| 5195 | - {
|
|
| 5196 | - $this->array_options[$key] = null; |
|
| 5197 | - } |
|
| 5198 | - break;*/ |
|
| 5199 | - case 'price': |
|
| 5200 | - $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
| 5201 | - break; |
|
| 5202 | - case 'date': |
|
| 5203 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5204 | - break; |
|
| 5205 | - case 'datetime': |
|
| 5206 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5207 | - break; |
|
| 5208 | - case 'link': |
|
| 5209 | - $param_list=array_keys($attributeParam['options']); |
|
| 5210 | - // 0 : ObjectName |
|
| 5211 | - // 1 : classPath |
|
| 5212 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5213 | - dol_include_once($InfoFieldList[1]); |
|
| 5214 | - if ($value) |
|
| 5215 | - {
|
|
| 5216 | - $object = new $InfoFieldList[0]($this->db); |
|
| 5217 | - $object->fetch(0,$value); |
|
| 5218 | - $this->array_options["options_".$key]=$object->id; |
|
| 5219 | - } |
|
| 5220 | - break; |
|
| 5221 | - } |
|
| 5222 | - |
|
| 5223 | - $this->db->begin(); |
|
| 5224 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
| 5225 | - $sql .= " WHERE fk_object = ".$this->id; |
|
| 5226 | - $resql = $this->db->query($sql); |
|
| 5227 | - if (! $resql) |
|
| 5228 | - {
|
|
| 5229 | - $error++; |
|
| 5230 | - $this->error=$this->db->lasterror(); |
|
| 5231 | - } |
|
| 5232 | 1672 | |
| 5233 | - if (! $error && $trigger) |
|
| 5234 | - {
|
|
| 5235 | - // Call trigger |
|
| 5236 | - $this->context=array('extrafieldupdate'=>1);
|
|
| 5237 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5238 | - if ($result < 0) $error++; |
|
| 5239 | - // End call trigger |
|
| 5240 | - } |
|
| 5241 | - |
|
| 5242 | - if ($error) |
|
| 5243 | - {
|
|
| 5244 | - dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
| 5245 | - $this->db->rollback(); |
|
| 5246 | - return -1; |
|
| 5247 | - } |
|
| 5248 | - else |
|
| 5249 | - {
|
|
| 5250 | - $this->db->commit(); |
|
| 5251 | - return 1; |
|
| 5252 | - } |
|
| 5253 | - } |
|
| 5254 | - else return 0; |
|
| 5255 | - } |
|
| 5256 | - |
|
| 5257 | - |
|
| 5258 | - /** |
|
| 5259 | - * Return HTML string to put an input field into a page |
|
| 5260 | - * Code very similar with showInputField of extra fields |
|
| 5261 | - * |
|
| 5262 | - * @param array $val Array of properties for field to show |
|
| 5263 | - * @param string $key Key of attribute |
|
| 5264 | - * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
| 5265 | - * @param string $moreparam To add more parameters on html input tag |
|
| 5266 | - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5267 | - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5268 | - * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
|
| 5269 | - * @return string |
|
| 5270 | - */ |
|
| 5271 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
| 5272 | - {
|
|
| 5273 | - global $conf,$langs,$form; |
|
| 5274 | - |
|
| 5275 | - if (! is_object($form)) |
|
| 5276 | - {
|
|
| 5277 | - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5278 | - $form=new Form($this->db); |
|
| 5279 | - } |
|
| 5280 | - |
|
| 5281 | - $val=$this->fields[$key]; |
|
| 5282 | - |
|
| 5283 | - $out=''; |
|
| 5284 | - $type=''; |
|
| 5285 | - $param = array(); |
|
| 5286 | - $param['options']=array(); |
|
| 5287 | - $size =$this->fields[$key]['size']; |
|
| 5288 | - // Because we work on extrafields |
|
| 5289 | - if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){
|
|
| 5290 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5291 | - $type ='link'; |
|
| 5292 | - } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5293 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5294 | - $type ='link'; |
|
| 5295 | - } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5296 | - $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5297 | - $type ='sellist'; |
|
| 5298 | - } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) {
|
|
| 5299 | - $param['options']=array(); |
|
| 5300 | - $type ='varchar'; |
|
| 5301 | - $size=$reg[1]; |
|
| 5302 | - } elseif(preg_match('/varchar/', $val['type'])) {
|
|
| 5303 | - $param['options']=array(); |
|
| 5304 | - $type ='varchar'; |
|
| 5305 | - } elseif(is_array($this->fields[$key]['arrayofkeyval'])) {
|
|
| 5306 | - $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
| 5307 | - $type ='select'; |
|
| 5308 | - } else {
|
|
| 5309 | - $param['options']=array(); |
|
| 5310 | - $type =$this->fields[$key]['type']; |
|
| 1673 | + /** |
|
| 1674 | + * Return list of id of contacts of object |
|
| 1675 | + * |
|
| 1676 | + * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) |
|
| 1677 | + * @return array Array of id of contacts (if source=external or internal) |
|
| 1678 | + * Array of id of third parties with at least one contact on object (if source=thirdparty) |
|
| 1679 | + */ |
|
| 1680 | + function getListContactId($source='external') |
|
| 1681 | + {
|
|
| 1682 | + $contactAlreadySelected = array(); |
|
| 1683 | + $tab = $this->liste_contact(-1,$source); |
|
| 1684 | + $num=count($tab); |
|
| 1685 | + $i = 0; |
|
| 1686 | + while ($i < $num) |
|
| 1687 | + {
|
|
| 1688 | + if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1689 | + else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1690 | + $i++; |
|
| 5311 | 1691 | } |
| 1692 | + return $contactAlreadySelected; |
|
| 1693 | + } |
|
| 5312 | 1694 | |
| 5313 | - $label=$this->fields[$key]['label']; |
|
| 5314 | - //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
|
| 5315 | - $default=$this->fields[$key]['default']; |
|
| 5316 | - $computed=$this->fields[$key]['computed']; |
|
| 5317 | - $unique=$this->fields[$key]['unique']; |
|
| 5318 | - $required=$this->fields[$key]['required']; |
|
| 5319 | 1695 | |
| 5320 | - $langfile=$this->fields[$key]['langfile']; |
|
| 5321 | - $list=$this->fields[$key]['list']; |
|
| 5322 | - $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
| 1696 | + /** |
|
| 1697 | + * Link element with a project |
|
| 1698 | + * |
|
| 1699 | + * @param int $projectid Project id to link element to |
|
| 1700 | + * @return int <0 if KO, >0 if OK |
|
| 1701 | + */ |
|
| 1702 | + function setProject($projectid) |
|
| 1703 | + {
|
|
| 1704 | + if (! $this->table_element) |
|
| 1705 | + {
|
|
| 1706 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1707 | + return -1; |
|
| 1708 | + } |
|
| 5323 | 1709 | |
| 5324 | - $objectid = $this->id; |
|
| 1710 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1711 | + if ($this->table_element == 'actioncomm') |
|
| 1712 | + {
|
|
| 1713 | + if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1714 | + else $sql.= ' SET fk_project = NULL'; |
|
| 1715 | + $sql.= ' WHERE id = '.$this->id; |
|
| 1716 | + } |
|
| 1717 | + else |
|
| 1718 | + {
|
|
| 1719 | + if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1720 | + else $sql.= ' SET fk_projet = NULL'; |
|
| 1721 | + $sql.= ' WHERE rowid = '.$this->id; |
|
| 1722 | + } |
|
| 5325 | 1723 | |
| 1724 | + dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
| 1725 | + if ($this->db->query($sql)) |
|
| 1726 | + {
|
|
| 1727 | + $this->fk_project = $projectid; |
|
| 1728 | + return 1; |
|
| 1729 | + } |
|
| 1730 | + else |
|
| 1731 | + {
|
|
| 1732 | + dol_print_error($this->db); |
|
| 1733 | + return -1; |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 5326 | 1736 | |
| 5327 | - if ($computed) |
|
| 5328 | - {
|
|
| 5329 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5330 | - else return ''; |
|
| 5331 | - } |
|
| 1737 | + /** |
|
| 1738 | + * Change the payments methods |
|
| 1739 | + * |
|
| 1740 | + * @param int $id Id of new payment method |
|
| 1741 | + * @return int >0 if OK, <0 if KO |
|
| 1742 | + */ |
|
| 1743 | + function setPaymentMethods($id) |
|
| 1744 | + {
|
|
| 1745 | + dol_syslog(get_class($this).'::setPaymentMethods('.$id.')');
|
|
| 1746 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1747 | + {
|
|
| 1748 | + // TODO uniformize field name |
|
| 1749 | + $fieldname = 'fk_mode_reglement'; |
|
| 1750 | + if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1751 | + if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 5332 | 1752 | |
| 1753 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1754 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1755 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 5333 | 1756 | |
| 5334 | - // Use in priority showsize from parameters, then $val['css'] then autodefine |
|
| 5335 | - if (empty($morecss) && ! empty($val['css'])) |
|
| 5336 | - {
|
|
| 5337 | - $showsize = $val['css']; |
|
| 5338 | - } |
|
| 5339 | - if (empty($morecss)) |
|
| 5340 | - {
|
|
| 5341 | - if ($type == 'date') |
|
| 5342 | - {
|
|
| 5343 | - $morecss = 'minwidth100imp'; |
|
| 5344 | - } |
|
| 5345 | - elseif ($type == 'datetime') |
|
| 5346 | - {
|
|
| 5347 | - $morecss = 'minwidth200imp'; |
|
| 5348 | - } |
|
| 5349 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5350 | - {
|
|
| 5351 | - $morecss = 'maxwidth75'; |
|
| 5352 | - }elseif ($type == 'url') |
|
| 5353 | - {
|
|
| 5354 | - $morecss='minwidth400'; |
|
| 5355 | - } |
|
| 5356 | - elseif ($type == 'boolean') |
|
| 5357 | - {
|
|
| 5358 | - $morecss=''; |
|
| 5359 | - } |
|
| 5360 | - else |
|
| 5361 | - {
|
|
| 5362 | - if (round($size) < 12) |
|
| 5363 | - {
|
|
| 5364 | - $morecss = 'minwidth100'; |
|
| 5365 | - } |
|
| 5366 | - else if (round($size) <= 48) |
|
| 5367 | - {
|
|
| 5368 | - $morecss = 'minwidth200'; |
|
| 5369 | - } |
|
| 5370 | - else |
|
| 5371 | - {
|
|
| 5372 | - $morecss = 'minwidth400'; |
|
| 5373 | - } |
|
| 5374 | - } |
|
| 5375 | - } |
|
| 5376 | - |
|
| 5377 | - if (in_array($type,array('date','datetime')))
|
|
| 5378 | - {
|
|
| 5379 | - $tmp=explode(',',$size);
|
|
| 5380 | - $newsize=$tmp[0]; |
|
| 5381 | - |
|
| 5382 | - $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
|
| 5383 | - |
|
| 5384 | - // Do not show current date when field not required (see selectDate() method) |
|
| 5385 | - if (!$required && $value == '') $value = '-1'; |
|
| 5386 | - |
|
| 5387 | - // TODO Must also support $moreparam |
|
| 5388 | - $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
| 5389 | - } |
|
| 5390 | - elseif (in_array($type,array('int','integer')))
|
|
| 5391 | - {
|
|
| 5392 | - $tmp=explode(',',$size);
|
|
| 5393 | - $newsize=$tmp[0]; |
|
| 5394 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5395 | - } |
|
| 5396 | - elseif (preg_match('/varchar/', $type))
|
|
| 5397 | - {
|
|
| 5398 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5399 | - } |
|
| 5400 | - elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5401 | - {
|
|
| 5402 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5403 | - } |
|
| 5404 | - elseif ($type == 'text') |
|
| 5405 | - {
|
|
| 5406 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5407 | - {
|
|
| 5408 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5409 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 5410 | - $out=$doleditor->Create(1); |
|
| 5411 | - } |
|
| 5412 | - else |
|
| 5413 | - {
|
|
| 5414 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5415 | - } |
|
| 5416 | - } |
|
| 5417 | - elseif ($type == 'html') |
|
| 5418 | - {
|
|
| 5419 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5420 | - {
|
|
| 5421 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5422 | - $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%'); |
|
| 5423 | - $out=$doleditor->Create(1); |
|
| 5424 | - } |
|
| 5425 | - else |
|
| 5426 | - {
|
|
| 5427 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5428 | - } |
|
| 5429 | - } |
|
| 5430 | - elseif ($type == 'boolean') |
|
| 5431 | - {
|
|
| 5432 | - $checked=''; |
|
| 5433 | - if (!empty($value)) {
|
|
| 5434 | - $checked=' checked value="1" '; |
|
| 5435 | - } else {
|
|
| 5436 | - $checked=' value="1" '; |
|
| 5437 | - } |
|
| 5438 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5439 | - } |
|
| 5440 | - elseif ($type == 'price') |
|
| 5441 | - {
|
|
| 5442 | - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5443 | - $value=price($value); |
|
| 5444 | - } |
|
| 5445 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5446 | - } |
|
| 5447 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5448 | - {
|
|
| 5449 | - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5450 | - $value=price($value); |
|
| 5451 | - } |
|
| 5452 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5453 | - } |
|
| 5454 | - elseif ($type == 'select') |
|
| 5455 | - {
|
|
| 5456 | - $out = ''; |
|
| 5457 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5458 | - {
|
|
| 5459 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5460 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5461 | - } |
|
| 1757 | + if ($this->db->query($sql)) |
|
| 1758 | + {
|
|
| 1759 | + $this->mode_reglement_id = $id; |
|
| 1760 | + // for supplier |
|
| 1761 | + if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1762 | + return 1; |
|
| 1763 | + } |
|
| 1764 | + else |
|
| 1765 | + {
|
|
| 1766 | + dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
| 1767 | + $this->error=$this->db->error(); |
|
| 1768 | + return -1; |
|
| 1769 | + } |
|
| 1770 | + } |
|
| 1771 | + else |
|
| 1772 | + {
|
|
| 1773 | + dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
| 1774 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1775 | + return -2; |
|
| 1776 | + } |
|
| 1777 | + } |
|
| 5462 | 1778 | |
| 5463 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5464 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5465 | - foreach ($param['options'] as $key => $val) |
|
| 5466 | - {
|
|
| 5467 | - if ((string) $key == '') continue; |
|
| 5468 | - list($val, $parent) = explode('|', $val);
|
|
| 5469 | - $out.='<option value="'.$key.'"'; |
|
| 5470 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5471 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5472 | - $out.='>'.$val.'</option>'; |
|
| 5473 | - } |
|
| 5474 | - $out.='</select>'; |
|
| 5475 | - } |
|
| 5476 | - elseif ($type == 'sellist') |
|
| 5477 | - {
|
|
| 5478 | - $out = ''; |
|
| 5479 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5480 | - {
|
|
| 5481 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5482 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5483 | - } |
|
| 1779 | + /** |
|
| 1780 | + * Change the multicurrency code |
|
| 1781 | + * |
|
| 1782 | + * @param string $code multicurrency code |
|
| 1783 | + * @return int >0 if OK, <0 if KO |
|
| 1784 | + */ |
|
| 1785 | + function setMulticurrencyCode($code) |
|
| 1786 | + {
|
|
| 1787 | + dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')');
|
|
| 1788 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1789 | + {
|
|
| 1790 | + $fieldname = 'multicurrency_code'; |
|
| 5484 | 1791 | |
| 5485 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5486 | - if (is_array($param['options'])) |
|
| 5487 | - {
|
|
| 5488 | - $param_list=array_keys($param['options']); |
|
| 5489 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5490 | - $parentName=''; |
|
| 5491 | - $parentField=''; |
|
| 5492 | - // 0 : tableName |
|
| 5493 | - // 1 : label field name |
|
| 5494 | - // 2 : key fields name (if differ of rowid) |
|
| 5495 | - // 3 : key field parent (for dependent lists) |
|
| 5496 | - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5497 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5498 | - |
|
| 5499 | - |
|
| 5500 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5501 | - {
|
|
| 5502 | - if (strpos($InfoFieldList[4], 'extra.') !== false) |
|
| 5503 | - {
|
|
| 5504 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5505 | - } else {
|
|
| 5506 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5507 | - } |
|
| 5508 | - } |
|
| 5509 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5510 | - {
|
|
| 5511 | - list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
|
|
| 5512 | - $keyList.= ', '.$parentField; |
|
| 5513 | - } |
|
| 1792 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1793 | + $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
| 1794 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 5514 | 1795 | |
| 5515 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5516 | - if (is_array($fields_label)) |
|
| 5517 | - {
|
|
| 5518 | - $keyList .=', '; |
|
| 5519 | - $keyList .= implode(', ', $fields_label);
|
|
| 5520 | - } |
|
| 1796 | + if ($this->db->query($sql)) |
|
| 1797 | + {
|
|
| 1798 | + $this->multicurrency_code = $code; |
|
| 5521 | 1799 | |
| 5522 | - $sqlwhere=''; |
|
| 5523 | - $sql = 'SELECT '.$keyList; |
|
| 5524 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5525 | - if (!empty($InfoFieldList[4])) |
|
| 5526 | - {
|
|
| 5527 | - // can use SELECT request |
|
| 5528 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5529 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5530 | - } |
|
| 5531 | - |
|
| 5532 | - // current object id can be use into filter |
|
| 5533 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5534 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5535 | - } else {
|
|
| 5536 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5537 | - } |
|
| 5538 | - //We have to join on extrafield table |
|
| 5539 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5540 | - {
|
|
| 5541 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5542 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5543 | - } |
|
| 5544 | - else |
|
| 5545 | - {
|
|
| 5546 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5547 | - } |
|
| 5548 | - } |
|
| 5549 | - else |
|
| 5550 | - {
|
|
| 5551 | - $sqlwhere.= ' WHERE 1=1'; |
|
| 5552 | - } |
|
| 5553 | - // Some tables may have field, some other not. For the moment we disable it. |
|
| 5554 | - if (in_array($InfoFieldList[0],array('tablewithentity')))
|
|
| 5555 | - {
|
|
| 5556 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
| 5557 | - } |
|
| 5558 | - $sql.=$sqlwhere; |
|
| 5559 | - //print $sql; |
|
| 1800 | + list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
|
| 1801 | + if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 5560 | 1802 | |
| 5561 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label);
|
|
| 1803 | + return 1; |
|
| 1804 | + } |
|
| 1805 | + else |
|
| 1806 | + {
|
|
| 1807 | + dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
| 1808 | + $this->error=$this->db->error(); |
|
| 1809 | + return -1; |
|
| 1810 | + } |
|
| 1811 | + } |
|
| 1812 | + else |
|
| 1813 | + {
|
|
| 1814 | + dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
| 1815 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1816 | + return -2; |
|
| 1817 | + } |
|
| 1818 | + } |
|
| 5562 | 1819 | |
| 5563 | - dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
| 5564 | - $resql = $this->db->query($sql); |
|
| 5565 | - if ($resql) |
|
| 5566 | - {
|
|
| 5567 | - $out.='<option value="0"> </option>'; |
|
| 5568 | - $num = $this->db->num_rows($resql); |
|
| 5569 | - $i = 0; |
|
| 5570 | - while ($i < $num) |
|
| 5571 | - {
|
|
| 5572 | - $labeltoshow=''; |
|
| 5573 | - $obj = $this->db->fetch_object($resql); |
|
| 5574 | - |
|
| 5575 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 5576 | - $notrans = false; |
|
| 5577 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5578 | - if (is_array($fields_label)) |
|
| 5579 | - {
|
|
| 5580 | - $notrans = true; |
|
| 5581 | - foreach ($fields_label as $field_toshow) |
|
| 5582 | - {
|
|
| 5583 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5584 | - } |
|
| 5585 | - } |
|
| 5586 | - else |
|
| 5587 | - {
|
|
| 5588 | - $labeltoshow=$obj->{$InfoFieldList[1]};
|
|
| 5589 | - } |
|
| 5590 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5591 | - |
|
| 5592 | - if ($value == $obj->rowid) |
|
| 5593 | - {
|
|
| 5594 | - foreach ($fields_label as $field_toshow) |
|
| 5595 | - {
|
|
| 5596 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 5597 | - if ($translabel!=$obj->$field_toshow) {
|
|
| 5598 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5599 | - }else {
|
|
| 5600 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5601 | - } |
|
| 5602 | - } |
|
| 5603 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5604 | - } |
|
| 5605 | - else |
|
| 5606 | - {
|
|
| 5607 | - if (! $notrans) |
|
| 5608 | - {
|
|
| 5609 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5610 | - if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 5611 | - $labeltoshow=dol_trunc($translabel,18); |
|
| 5612 | - } |
|
| 5613 | - else {
|
|
| 5614 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
|
| 5615 | - } |
|
| 5616 | - } |
|
| 5617 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5618 | - if ($value==$obj->rowid) |
|
| 5619 | - {
|
|
| 5620 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5621 | - } |
|
| 1820 | + /** |
|
| 1821 | + * Change the multicurrency rate |
|
| 1822 | + * |
|
| 1823 | + * @param double $rate multicurrency rate |
|
| 1824 | + * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
|
| 1825 | + * @return int >0 if OK, <0 if KO |
|
| 1826 | + */ |
|
| 1827 | + function setMulticurrencyRate($rate, $mode=1) |
|
| 1828 | + {
|
|
| 1829 | + dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')');
|
|
| 1830 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1831 | + {
|
|
| 1832 | + $fieldname = 'multicurrency_tx'; |
|
| 5622 | 1833 | |
| 5623 | - if (!empty($InfoFieldList[3]) && $parentField) |
|
| 5624 | - {
|
|
| 5625 | - $parent = $parentName.':'.$obj->{$parentField};
|
|
| 5626 | - } |
|
| 1834 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1835 | + $sql .= ' SET '.$fieldname.' = '.$rate; |
|
| 1836 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 5627 | 1837 | |
| 5628 | - $out.='<option value="'.$obj->rowid.'"'; |
|
| 5629 | - $out.= ($value==$obj->rowid?' selected':''); |
|
| 5630 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5631 | - $out.='>'.$labeltoshow.'</option>'; |
|
| 5632 | - } |
|
| 1838 | + if ($this->db->query($sql)) |
|
| 1839 | + {
|
|
| 1840 | + $this->multicurrency_tx = $rate; |
|
| 1841 | + |
|
| 1842 | + // Update line price |
|
| 1843 | + if (!empty($this->lines)) |
|
| 1844 | + {
|
|
| 1845 | + foreach ($this->lines as &$line) |
|
| 1846 | + {
|
|
| 1847 | + if($mode == 1) {
|
|
| 1848 | + $line->subprice = 0; |
|
| 1849 | + } |
|
| 1850 | + |
|
| 1851 | + switch ($this->element) {
|
|
| 1852 | + case 'propal': |
|
| 1853 | + $this->updateline( |
|
| 1854 | + $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1855 | + ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1856 | + $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
|
| 1857 | + $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1858 | + ); |
|
| 1859 | + break; |
|
| 1860 | + case 'commande': |
|
| 1861 | + $this->updateline( |
|
| 1862 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1863 | + $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
|
| 1864 | + $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1865 | + $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1866 | + ); |
|
| 1867 | + break; |
|
| 1868 | + case 'facture': |
|
| 1869 | + $this->updateline( |
|
| 1870 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1871 | + $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
|
| 1872 | + $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1873 | + $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
|
| 1874 | + ); |
|
| 1875 | + break; |
|
| 1876 | + case 'supplier_proposal': |
|
| 1877 | + $this->updateline( |
|
| 1878 | + $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1879 | + ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1880 | + $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
|
| 1881 | + $line->ref_fourn, $line->multicurrency_subprice |
|
| 1882 | + ); |
|
| 1883 | + break; |
|
| 1884 | + case 'order_supplier': |
|
| 1885 | + $this->updateline( |
|
| 1886 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1887 | + $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
|
| 1888 | + $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1889 | + ); |
|
| 1890 | + break; |
|
| 1891 | + case 'invoice_supplier': |
|
| 1892 | + $this->updateline( |
|
| 1893 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1894 | + $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
|
| 1895 | + $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1896 | + ); |
|
| 1897 | + break; |
|
| 1898 | + default: |
|
| 1899 | + dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
| 1900 | + break; |
|
| 1901 | + } |
|
| 1902 | + } |
|
| 1903 | + } |
|
| 1904 | + |
|
| 1905 | + return 1; |
|
| 1906 | + } |
|
| 1907 | + else |
|
| 1908 | + {
|
|
| 1909 | + dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
| 1910 | + $this->error=$this->db->error(); |
|
| 1911 | + return -1; |
|
| 1912 | + } |
|
| 1913 | + } |
|
| 1914 | + else |
|
| 1915 | + {
|
|
| 1916 | + dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
| 1917 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1918 | + return -2; |
|
| 1919 | + } |
|
| 1920 | + } |
|
| 5633 | 1921 | |
| 5634 | - $i++; |
|
| 5635 | - } |
|
| 5636 | - $this->db->free($resql); |
|
| 5637 | - } |
|
| 5638 | - else {
|
|
| 5639 | - print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5640 | - } |
|
| 5641 | - } |
|
| 5642 | - $out.='</select>'; |
|
| 5643 | - } |
|
| 5644 | - elseif ($type == 'checkbox') |
|
| 5645 | - {
|
|
| 5646 | - $value_arr=explode(',',$value);
|
|
| 5647 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5648 | - } |
|
| 5649 | - elseif ($type == 'radio') |
|
| 5650 | - {
|
|
| 5651 | - $out=''; |
|
| 5652 | - foreach ($param['options'] as $keyopt => $val) |
|
| 5653 | - {
|
|
| 5654 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5655 | - $out.=' value="'.$keyopt.'"'; |
|
| 5656 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5657 | - $out.= ($value==$keyopt?'checked':''); |
|
| 5658 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5659 | - } |
|
| 5660 | - } |
|
| 5661 | - elseif ($type == 'chkbxlst') |
|
| 5662 | - {
|
|
| 5663 | - if (is_array($value)) {
|
|
| 5664 | - $value_arr = $value; |
|
| 5665 | - } |
|
| 5666 | - else {
|
|
| 5667 | - $value_arr = explode(',', $value);
|
|
| 5668 | - } |
|
| 5669 | - |
|
| 5670 | - if (is_array($param['options'])) {
|
|
| 5671 | - $param_list = array_keys($param['options']); |
|
| 5672 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5673 | - $parentName=''; |
|
| 5674 | - $parentField=''; |
|
| 5675 | - // 0 : tableName |
|
| 5676 | - // 1 : label field name |
|
| 5677 | - // 2 : key fields name (if differ of rowid) |
|
| 5678 | - // 3 : key field parent (for dependent lists) |
|
| 5679 | - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5680 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5681 | - |
|
| 5682 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
|
|
| 5683 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
|
|
| 5684 | - $keyList .= ', ' . $parentField; |
|
| 5685 | - } |
|
| 5686 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
|
|
| 5687 | - if (strpos($InfoFieldList[4], 'extra.') !== false) {
|
|
| 5688 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5689 | - } else {
|
|
| 5690 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5691 | - } |
|
| 5692 | - } |
|
| 1922 | + /** |
|
| 1923 | + * Change the payments terms |
|
| 1924 | + * |
|
| 1925 | + * @param int $id Id of new payment terms |
|
| 1926 | + * @return int >0 if OK, <0 if KO |
|
| 1927 | + */ |
|
| 1928 | + function setPaymentTerms($id) |
|
| 1929 | + {
|
|
| 1930 | + dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
|
|
| 1931 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1932 | + {
|
|
| 1933 | + // TODO uniformize field name |
|
| 1934 | + $fieldname = 'fk_cond_reglement'; |
|
| 1935 | + if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1936 | + if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 1937 | + |
|
| 1938 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1939 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1940 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 1941 | + |
|
| 1942 | + if ($this->db->query($sql)) |
|
| 1943 | + {
|
|
| 1944 | + $this->cond_reglement_id = $id; |
|
| 1945 | + // for supplier |
|
| 1946 | + if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 1947 | + $this->cond_reglement = $id; // for compatibility |
|
| 1948 | + return 1; |
|
| 1949 | + } |
|
| 1950 | + else |
|
| 1951 | + {
|
|
| 1952 | + dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
| 1953 | + $this->error=$this->db->error(); |
|
| 1954 | + return -1; |
|
| 1955 | + } |
|
| 1956 | + } |
|
| 1957 | + else |
|
| 1958 | + {
|
|
| 1959 | + dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
| 1960 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1961 | + return -2; |
|
| 1962 | + } |
|
| 1963 | + } |
|
| 1964 | + |
|
| 1965 | + /** |
|
| 1966 | + * Define delivery address |
|
| 1967 | + * @deprecated |
|
| 1968 | + * |
|
| 1969 | + * @param int $id Address id |
|
| 1970 | + * @return int <0 si ko, >0 si ok |
|
| 1971 | + */ |
|
| 1972 | + function setDeliveryAddress($id) |
|
| 1973 | + {
|
|
| 1974 | + $fieldname = 'fk_delivery_address'; |
|
| 1975 | + if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 1976 | + |
|
| 1977 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
| 1978 | + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1979 | + |
|
| 1980 | + if ($this->db->query($sql)) |
|
| 1981 | + {
|
|
| 1982 | + $this->fk_delivery_address = $id; |
|
| 1983 | + return 1; |
|
| 1984 | + } |
|
| 1985 | + else |
|
| 1986 | + {
|
|
| 1987 | + $this->error=$this->db->error(); |
|
| 1988 | + dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
| 1989 | + return -1; |
|
| 1990 | + } |
|
| 1991 | + } |
|
| 1992 | + |
|
| 1993 | + |
|
| 1994 | + /** |
|
| 1995 | + * Change the shipping method |
|
| 1996 | + * |
|
| 1997 | + * @param int $shipping_method_id Id of shipping method |
|
| 1998 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 1999 | + * @param User $userused Object user |
|
| 2000 | + * |
|
| 2001 | + * @return int 1 if OK, 0 if KO |
|
| 2002 | + */ |
|
| 2003 | + function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 2004 | + {
|
|
| 2005 | + global $user; |
|
| 2006 | + |
|
| 2007 | + if (empty($userused)) $userused=$user; |
|
| 2008 | + |
|
| 2009 | + $error = 0; |
|
| 2010 | + |
|
| 2011 | + if (! $this->table_element) {
|
|
| 2012 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 2013 | + return -1; |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + $this->db->begin(); |
|
| 2017 | + |
|
| 2018 | + if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2019 | + dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
|
| 2020 | + |
|
| 2021 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2022 | + $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2023 | + $sql.= " WHERE rowid=".$this->id; |
|
| 2024 | + $resql = $this->db->query($sql); |
|
| 2025 | + if (! $resql) {
|
|
| 2026 | + dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
| 2027 | + $this->error = $this->db->lasterror(); |
|
| 2028 | + $error++; |
|
| 2029 | + } else {
|
|
| 2030 | + if (!$notrigger) |
|
| 2031 | + {
|
|
| 2032 | + // Call trigger |
|
| 2033 | + $this->context=array('shippingmethodupdate'=>1);
|
|
| 2034 | + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2035 | + if ($result < 0) $error++; |
|
| 2036 | + // End call trigger |
|
| 2037 | + } |
|
| 2038 | + } |
|
| 2039 | + if ($error) |
|
| 2040 | + {
|
|
| 2041 | + $this->db->rollback(); |
|
| 2042 | + return -1; |
|
| 2043 | + } else {
|
|
| 2044 | + $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 2045 | + $this->db->commit(); |
|
| 2046 | + return 1; |
|
| 2047 | + } |
|
| 2048 | + } |
|
| 2049 | + |
|
| 2050 | + |
|
| 2051 | + /** |
|
| 2052 | + * Change the warehouse |
|
| 2053 | + * |
|
| 2054 | + * @param int $warehouse_id Id of warehouse |
|
| 2055 | + * @return int 1 if OK, 0 if KO |
|
| 2056 | + */ |
|
| 2057 | + function setWarehouse($warehouse_id) |
|
| 2058 | + {
|
|
| 2059 | + if (! $this->table_element) {
|
|
| 2060 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 2061 | + return -1; |
|
| 2062 | + } |
|
| 2063 | + if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2064 | + dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
|
| 2065 | + |
|
| 2066 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2067 | + $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 2068 | + $sql.= " WHERE rowid=".$this->id; |
|
| 2069 | + |
|
| 2070 | + if ($this->db->query($sql)) {
|
|
| 2071 | + $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 2072 | + return 1; |
|
| 2073 | + } else {
|
|
| 2074 | + dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
| 2075 | + $this->error=$this->db->error(); |
|
| 2076 | + return 0; |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + |
|
| 2080 | + |
|
| 2081 | + /** |
|
| 2082 | + * Set last model used by doc generator |
|
| 2083 | + * |
|
| 2084 | + * @param User $user User object that make change |
|
| 2085 | + * @param string $modelpdf Modele name |
|
| 2086 | + * @return int <0 if KO, >0 if OK |
|
| 2087 | + */ |
|
| 2088 | + function setDocModel($user, $modelpdf) |
|
| 2089 | + {
|
|
| 2090 | + if (! $this->table_element) |
|
| 2091 | + {
|
|
| 2092 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 2093 | + return -1; |
|
| 2094 | + } |
|
| 2095 | + |
|
| 2096 | + $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 2097 | + |
|
| 2098 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2099 | + $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2100 | + $sql.= " WHERE rowid = ".$this->id; |
|
| 2101 | + // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
|
| 2102 | + // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
|
| 2103 | + |
|
| 2104 | + dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
| 2105 | + $resql=$this->db->query($sql); |
|
| 2106 | + if ($resql) |
|
| 2107 | + {
|
|
| 2108 | + $this->modelpdf=$modelpdf; |
|
| 2109 | + return 1; |
|
| 2110 | + } |
|
| 2111 | + else |
|
| 2112 | + {
|
|
| 2113 | + dol_print_error($this->db); |
|
| 2114 | + return 0; |
|
| 2115 | + } |
|
| 2116 | + } |
|
| 2117 | + |
|
| 2118 | + |
|
| 2119 | + /** |
|
| 2120 | + * Change the bank account |
|
| 2121 | + * |
|
| 2122 | + * @param int $fk_account Id of bank account |
|
| 2123 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 2124 | + * @param User $userused Object user |
|
| 2125 | + * @return int 1 if OK, 0 if KO |
|
| 2126 | + */ |
|
| 2127 | + function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 2128 | + {
|
|
| 2129 | + global $user; |
|
| 2130 | + |
|
| 2131 | + if (empty($userused)) $userused=$user; |
|
| 2132 | + |
|
| 2133 | + $error = 0; |
|
| 2134 | + |
|
| 2135 | + if (! $this->table_element) {
|
|
| 2136 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 2137 | + return -1; |
|
| 2138 | + } |
|
| 2139 | + $this->db->begin(); |
|
| 2140 | + |
|
| 2141 | + if ($fk_account<0) $fk_account='NULL'; |
|
| 2142 | + dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
|
| 2143 | + |
|
| 2144 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2145 | + $sql.= " SET fk_account = ".$fk_account; |
|
| 2146 | + $sql.= " WHERE rowid=".$this->id; |
|
| 2147 | + |
|
| 2148 | + $resql = $this->db->query($sql); |
|
| 2149 | + if (! $resql) |
|
| 2150 | + {
|
|
| 2151 | + dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
| 2152 | + $this->error = $this->db->lasterror(); |
|
| 2153 | + $error++; |
|
| 2154 | + } |
|
| 2155 | + else |
|
| 2156 | + {
|
|
| 2157 | + if (!$notrigger) |
|
| 2158 | + {
|
|
| 2159 | + // Call trigger |
|
| 2160 | + $this->context=array('bankaccountupdate'=>1);
|
|
| 2161 | + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2162 | + if ($result < 0) $error++; |
|
| 2163 | + // End call trigger |
|
| 2164 | + } |
|
| 2165 | + } |
|
| 2166 | + if ($error) |
|
| 2167 | + {
|
|
| 2168 | + $this->db->rollback(); |
|
| 2169 | + return -1; |
|
| 2170 | + } |
|
| 2171 | + else |
|
| 2172 | + {
|
|
| 2173 | + $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 2174 | + $this->db->commit(); |
|
| 2175 | + return 1; |
|
| 2176 | + } |
|
| 2177 | + } |
|
| 2178 | + |
|
| 2179 | + |
|
| 2180 | + // TODO: Move line related operations to CommonObjectLine? |
|
| 2181 | + |
|
| 2182 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2183 | + /** |
|
| 2184 | + * Save a new position (field rang) for details lines. |
|
| 2185 | + * You can choose to set position for lines with already a position or lines without any position defined. |
|
| 2186 | + * |
|
| 2187 | + * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. |
|
| 2188 | + * @param string $rowidorder ASC or DESC |
|
| 2189 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2190 | + * @return int <0 if KO, >0 if OK |
|
| 2191 | + */ |
|
| 2192 | + function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2193 | + {
|
|
| 2194 | + // phpcs:enable |
|
| 2195 | + if (! $this->table_element_line) |
|
| 2196 | + {
|
|
| 2197 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2198 | + return -1; |
|
| 2199 | + } |
|
| 2200 | + if (! $this->fk_element) |
|
| 2201 | + {
|
|
| 2202 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2203 | + return -1; |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + // Count number of lines to reorder (according to choice $renum) |
|
| 2207 | + $nl=0; |
|
| 2208 | + $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2209 | + $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2210 | + if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2211 | + if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2212 | + |
|
| 2213 | + dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
| 2214 | + $resql = $this->db->query($sql); |
|
| 2215 | + if ($resql) |
|
| 2216 | + {
|
|
| 2217 | + $row = $this->db->fetch_row($resql); |
|
| 2218 | + $nl = $row[0]; |
|
| 2219 | + } |
|
| 2220 | + else dol_print_error($this->db); |
|
| 2221 | + if ($nl > 0) |
|
| 2222 | + {
|
|
| 2223 | + // The goal of this part is to reorder all lines, with all children lines sharing the same |
|
| 2224 | + // counter that parents. |
|
| 2225 | + $rows=array(); |
|
| 2226 | + |
|
| 2227 | + // We first search all lines that are parent lines (for multilevel details lines) |
|
| 2228 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2229 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2230 | + if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2231 | + $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2232 | + |
|
| 2233 | + dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
| 2234 | + $resql = $this->db->query($sql); |
|
| 2235 | + if ($resql) |
|
| 2236 | + {
|
|
| 2237 | + $i=0; |
|
| 2238 | + $num = $this->db->num_rows($resql); |
|
| 2239 | + while ($i < $num) |
|
| 2240 | + {
|
|
| 2241 | + $row = $this->db->fetch_row($resql); |
|
| 2242 | + $rows[] = $row[0]; // Add parent line into array rows |
|
| 2243 | + $childrens = $this->getChildrenOfLine($row[0]); |
|
| 2244 | + if (! empty($childrens)) |
|
| 2245 | + {
|
|
| 2246 | + foreach($childrens as $child) |
|
| 2247 | + {
|
|
| 2248 | + array_push($rows, $child); |
|
| 2249 | + } |
|
| 2250 | + } |
|
| 2251 | + $i++; |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + // Now we set a new number for each lines (parent and children with children included into parent tree) |
|
| 2255 | + if (! empty($rows)) |
|
| 2256 | + {
|
|
| 2257 | + foreach($rows as $key => $row) |
|
| 2258 | + {
|
|
| 2259 | + $this->updateRangOfLine($row, ($key+1)); |
|
| 2260 | + } |
|
| 2261 | + } |
|
| 2262 | + } |
|
| 2263 | + else |
|
| 2264 | + {
|
|
| 2265 | + dol_print_error($this->db); |
|
| 2266 | + } |
|
| 2267 | + } |
|
| 2268 | + return 1; |
|
| 2269 | + } |
|
| 2270 | + |
|
| 2271 | + /** |
|
| 2272 | + * Get children of line |
|
| 2273 | + * |
|
| 2274 | + * @param int $id Id of parent line |
|
| 2275 | + * @return array Array with list of children lines id |
|
| 2276 | + */ |
|
| 2277 | + function getChildrenOfLine($id) |
|
| 2278 | + {
|
|
| 2279 | + $rows=array(); |
|
| 2280 | + |
|
| 2281 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2282 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2283 | + $sql.= ' AND fk_parent_line = '.$id; |
|
| 2284 | + $sql.= ' ORDER BY rang ASC'; |
|
| 2285 | + |
|
| 2286 | + dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
| 2287 | + $resql = $this->db->query($sql); |
|
| 2288 | + if ($resql) |
|
| 2289 | + {
|
|
| 2290 | + $i=0; |
|
| 2291 | + $num = $this->db->num_rows($resql); |
|
| 2292 | + while ($i < $num) |
|
| 2293 | + {
|
|
| 2294 | + $row = $this->db->fetch_row($resql); |
|
| 2295 | + $rows[$i] = $row[0]; |
|
| 2296 | + $i++; |
|
| 2297 | + } |
|
| 2298 | + } |
|
| 2299 | + |
|
| 2300 | + return $rows; |
|
| 2301 | + } |
|
| 2302 | + |
|
| 2303 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2304 | + /** |
|
| 2305 | + * Update a line to have a lower rank |
|
| 2306 | + * |
|
| 2307 | + * @param int $rowid Id of line |
|
| 2308 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2309 | + * @return void |
|
| 2310 | + */ |
|
| 2311 | + function line_up($rowid, $fk_parent_line=true) |
|
| 2312 | + {
|
|
| 2313 | + // phpcs:enable |
|
| 2314 | + $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 2315 | + |
|
| 2316 | + // Get rang of line |
|
| 2317 | + $rang = $this->getRangOfLine($rowid); |
|
| 2318 | + |
|
| 2319 | + // Update position of line |
|
| 2320 | + $this->updateLineUp($rowid, $rang); |
|
| 2321 | + } |
|
| 2322 | + |
|
| 2323 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2324 | + /** |
|
| 2325 | + * Update a line to have a higher rank |
|
| 2326 | + * |
|
| 2327 | + * @param int $rowid Id of line |
|
| 2328 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2329 | + * @return void |
|
| 2330 | + */ |
|
| 2331 | + function line_down($rowid, $fk_parent_line=true) |
|
| 2332 | + {
|
|
| 2333 | + // phpcs:enable |
|
| 2334 | + $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 2335 | + |
|
| 2336 | + // Get rang of line |
|
| 2337 | + $rang = $this->getRangOfLine($rowid); |
|
| 2338 | + |
|
| 2339 | + // Get max value for rang |
|
| 2340 | + $max = $this->line_max(); |
|
| 2341 | + |
|
| 2342 | + // Update position of line |
|
| 2343 | + $this->updateLineDown($rowid, $rang, $max); |
|
| 2344 | + } |
|
| 2345 | + |
|
| 2346 | + /** |
|
| 2347 | + * Update position of line (rang) |
|
| 2348 | + * |
|
| 2349 | + * @param int $rowid Id of line |
|
| 2350 | + * @param int $rang Position |
|
| 2351 | + * @return void |
|
| 2352 | + */ |
|
| 2353 | + function updateRangOfLine($rowid,$rang) |
|
| 2354 | + {
|
|
| 2355 | + $fieldposition = 'rang'; |
|
| 2356 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2357 | + |
|
| 2358 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2359 | + $sql.= ' WHERE rowid = '.$rowid; |
|
| 2360 | + |
|
| 2361 | + dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
| 2362 | + if (! $this->db->query($sql)) |
|
| 2363 | + {
|
|
| 2364 | + dol_print_error($this->db); |
|
| 2365 | + } |
|
| 2366 | + } |
|
| 2367 | + |
|
| 2368 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2369 | + /** |
|
| 2370 | + * Update position of line with ajax (rang) |
|
| 2371 | + * |
|
| 2372 | + * @param array $rows Array of rows |
|
| 2373 | + * @return void |
|
| 2374 | + */ |
|
| 2375 | + function line_ajaxorder($rows) |
|
| 2376 | + {
|
|
| 2377 | + // phpcs:enable |
|
| 2378 | + $num = count($rows); |
|
| 2379 | + for ($i = 0 ; $i < $num ; $i++) |
|
| 2380 | + {
|
|
| 2381 | + $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2382 | + } |
|
| 2383 | + } |
|
| 2384 | + |
|
| 2385 | + /** |
|
| 2386 | + * Update position of line up (rang) |
|
| 2387 | + * |
|
| 2388 | + * @param int $rowid Id of line |
|
| 2389 | + * @param int $rang Position |
|
| 2390 | + * @return void |
|
| 2391 | + */ |
|
| 2392 | + function updateLineUp($rowid,$rang) |
|
| 2393 | + {
|
|
| 2394 | + if ($rang > 1) |
|
| 2395 | + {
|
|
| 2396 | + $fieldposition = 'rang'; |
|
| 2397 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2398 | + |
|
| 2399 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
| 2400 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2401 | + $sql.= ' AND rang = '.($rang - 1); |
|
| 2402 | + if ($this->db->query($sql) ) |
|
| 2403 | + {
|
|
| 2404 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
| 2405 | + $sql.= ' WHERE rowid = '.$rowid; |
|
| 2406 | + if (! $this->db->query($sql) ) |
|
| 2407 | + {
|
|
| 2408 | + dol_print_error($this->db); |
|
| 2409 | + } |
|
| 2410 | + } |
|
| 2411 | + else |
|
| 2412 | + {
|
|
| 2413 | + dol_print_error($this->db); |
|
| 2414 | + } |
|
| 2415 | + } |
|
| 2416 | + } |
|
| 2417 | + |
|
| 2418 | + /** |
|
| 2419 | + * Update position of line down (rang) |
|
| 2420 | + * |
|
| 2421 | + * @param int $rowid Id of line |
|
| 2422 | + * @param int $rang Position |
|
| 2423 | + * @param int $max Max |
|
| 2424 | + * @return void |
|
| 2425 | + */ |
|
| 2426 | + function updateLineDown($rowid,$rang,$max) |
|
| 2427 | + {
|
|
| 2428 | + if ($rang < $max) |
|
| 2429 | + {
|
|
| 2430 | + $fieldposition = 'rang'; |
|
| 2431 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2432 | + |
|
| 2433 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2434 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2435 | + $sql.= ' AND rang = '.($rang+1); |
|
| 2436 | + if ($this->db->query($sql) ) |
|
| 2437 | + {
|
|
| 2438 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
| 2439 | + $sql.= ' WHERE rowid = '.$rowid; |
|
| 2440 | + if (! $this->db->query($sql) ) |
|
| 2441 | + {
|
|
| 2442 | + dol_print_error($this->db); |
|
| 2443 | + } |
|
| 2444 | + } |
|
| 2445 | + else |
|
| 2446 | + {
|
|
| 2447 | + dol_print_error($this->db); |
|
| 2448 | + } |
|
| 2449 | + } |
|
| 2450 | + } |
|
| 2451 | + |
|
| 2452 | + /** |
|
| 2453 | + * Get position of line (rang) |
|
| 2454 | + * |
|
| 2455 | + * @param int $rowid Id of line |
|
| 2456 | + * @return int Value of rang in table of lines |
|
| 2457 | + */ |
|
| 2458 | + function getRangOfLine($rowid) |
|
| 2459 | + {
|
|
| 2460 | + $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2461 | + $sql.= ' WHERE rowid ='.$rowid; |
|
| 2462 | + |
|
| 2463 | + dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
| 2464 | + $resql = $this->db->query($sql); |
|
| 2465 | + if ($resql) |
|
| 2466 | + {
|
|
| 2467 | + $row = $this->db->fetch_row($resql); |
|
| 2468 | + return $row[0]; |
|
| 2469 | + } |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + /** |
|
| 2473 | + * Get rowid of the line relative to its position |
|
| 2474 | + * |
|
| 2475 | + * @param int $rang Rang value |
|
| 2476 | + * @return int Rowid of the line |
|
| 2477 | + */ |
|
| 2478 | + function getIdOfLine($rang) |
|
| 2479 | + {
|
|
| 2480 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2481 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2482 | + $sql.= ' AND rang = '.$rang; |
|
| 2483 | + $resql = $this->db->query($sql); |
|
| 2484 | + if ($resql) |
|
| 2485 | + {
|
|
| 2486 | + $row = $this->db->fetch_row($resql); |
|
| 2487 | + return $row[0]; |
|
| 2488 | + } |
|
| 2489 | + } |
|
| 2490 | + |
|
| 2491 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2492 | + /** |
|
| 2493 | + * Get max value used for position of line (rang) |
|
| 2494 | + * |
|
| 2495 | + * @param int $fk_parent_line Parent line id |
|
| 2496 | + * @return int Max value of rang in table of lines |
|
| 2497 | + */ |
|
| 2498 | + function line_max($fk_parent_line=0) |
|
| 2499 | + {
|
|
| 2500 | + // phpcs:enable |
|
| 2501 | + // Search the last rang with fk_parent_line |
|
| 2502 | + if ($fk_parent_line) |
|
| 2503 | + {
|
|
| 2504 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2505 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2506 | + $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2507 | + |
|
| 2508 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2509 | + $resql = $this->db->query($sql); |
|
| 2510 | + if ($resql) |
|
| 2511 | + {
|
|
| 2512 | + $row = $this->db->fetch_row($resql); |
|
| 2513 | + if (! empty($row[0])) |
|
| 2514 | + {
|
|
| 2515 | + return $row[0]; |
|
| 2516 | + } |
|
| 2517 | + else |
|
| 2518 | + {
|
|
| 2519 | + return $this->getRangOfLine($fk_parent_line); |
|
| 2520 | + } |
|
| 2521 | + } |
|
| 2522 | + } |
|
| 2523 | + // If not, search the last rang of element |
|
| 2524 | + else |
|
| 2525 | + {
|
|
| 2526 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2527 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2528 | + |
|
| 2529 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2530 | + $resql = $this->db->query($sql); |
|
| 2531 | + if ($resql) |
|
| 2532 | + {
|
|
| 2533 | + $row = $this->db->fetch_row($resql); |
|
| 2534 | + return $row[0]; |
|
| 2535 | + } |
|
| 2536 | + } |
|
| 2537 | + } |
|
| 2538 | + |
|
| 2539 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2540 | + /** |
|
| 2541 | + * Update external ref of element |
|
| 2542 | + * |
|
| 2543 | + * @param string $ref_ext Update field ref_ext |
|
| 2544 | + * @return int <0 if KO, >0 if OK |
|
| 2545 | + */ |
|
| 2546 | + function update_ref_ext($ref_ext) |
|
| 2547 | + {
|
|
| 2548 | + // phpcs:enable |
|
| 2549 | + if (! $this->table_element) |
|
| 2550 | + {
|
|
| 2551 | + dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
| 2552 | + return -1; |
|
| 2553 | + } |
|
| 2554 | + |
|
| 2555 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2556 | + $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2557 | + $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2558 | + |
|
| 2559 | + dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
| 2560 | + if ($this->db->query($sql)) |
|
| 2561 | + {
|
|
| 2562 | + $this->ref_ext = $ref_ext; |
|
| 2563 | + return 1; |
|
| 2564 | + } |
|
| 2565 | + else |
|
| 2566 | + {
|
|
| 2567 | + $this->error=$this->db->error(); |
|
| 2568 | + return -1; |
|
| 2569 | + } |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2573 | + /** |
|
| 2574 | + * Update note of element |
|
| 2575 | + * |
|
| 2576 | + * @param string $note New value for note |
|
| 2577 | + * @param string $suffix '', '_public' or '_private' |
|
| 2578 | + * @return int <0 if KO, >0 if OK |
|
| 2579 | + */ |
|
| 2580 | + function update_note($note, $suffix='') |
|
| 2581 | + {
|
|
| 2582 | + // phpcs:enable |
|
| 2583 | + global $user; |
|
| 2584 | + |
|
| 2585 | + if (! $this->table_element) |
|
| 2586 | + {
|
|
| 2587 | + $this->error='update_note was called on objet with property table_element not defined'; |
|
| 2588 | + dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
| 2589 | + return -1; |
|
| 2590 | + } |
|
| 2591 | + if (! in_array($suffix,array('','_public','_private')))
|
|
| 2592 | + {
|
|
| 2593 | + $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2594 | + dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
| 2595 | + return -2; |
|
| 2596 | + } |
|
| 2597 | + // Special cas |
|
| 2598 | + //var_dump($this->table_element);exit; |
|
| 2599 | + if ($this->table_element == 'product') $suffix=''; |
|
| 2600 | + |
|
| 2601 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2602 | + $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
|
| 2603 | + $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id;
|
|
| 2604 | + $sql.= " WHERE rowid =". $this->id; |
|
| 2605 | + |
|
| 2606 | + dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
| 2607 | + if ($this->db->query($sql)) |
|
| 2608 | + {
|
|
| 2609 | + if ($suffix == '_public') $this->note_public = $note; |
|
| 2610 | + else if ($suffix == '_private') $this->note_private = $note; |
|
| 2611 | + else |
|
| 2612 | + {
|
|
| 2613 | + $this->note = $note; // deprecated |
|
| 2614 | + $this->note_private = $note; |
|
| 2615 | + } |
|
| 2616 | + return 1; |
|
| 2617 | + } |
|
| 2618 | + else |
|
| 2619 | + {
|
|
| 2620 | + $this->error=$this->db->lasterror(); |
|
| 2621 | + return -1; |
|
| 2622 | + } |
|
| 2623 | + } |
|
| 2624 | + |
|
| 2625 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2626 | + /** |
|
| 2627 | + * Update public note (kept for backward compatibility) |
|
| 2628 | + * |
|
| 2629 | + * @param string $note New value for note |
|
| 2630 | + * @return int <0 if KO, >0 if OK |
|
| 2631 | + * @deprecated |
|
| 2632 | + * @see update_note() |
|
| 2633 | + */ |
|
| 2634 | + function update_note_public($note) |
|
| 2635 | + {
|
|
| 2636 | + // phpcs:enable |
|
| 2637 | + return $this->update_note($note,'_public'); |
|
| 2638 | + } |
|
| 2639 | + |
|
| 2640 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2641 | + /** |
|
| 2642 | + * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). |
|
| 2643 | + * Must be called at end of methods addline or updateline. |
|
| 2644 | + * |
|
| 2645 | + * @param int $exclspec >0 = Exclude special product (product_type=9) |
|
| 2646 | + * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force mode total of rounding, '1'=Force mode rounding of total |
|
| 2647 | + * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. |
|
| 2648 | + * @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. |
|
| 2649 | + * @return int <0 if KO, >0 if OK |
|
| 2650 | + */ |
|
| 2651 | + function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2652 | + {
|
|
| 2653 | + // phpcs:enable |
|
| 2654 | + global $conf, $hookmanager, $action; |
|
| 2655 | + |
|
| 2656 | + // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
|
| 2657 | + $MODULE = ""; |
|
| 2658 | + if ($this->element == 'propal') |
|
| 2659 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2660 | + elseif ($this->element == 'order') |
|
| 2661 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2662 | + elseif ($this->element == 'facture') |
|
| 2663 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2664 | + elseif ($this->element == 'facture_fourn') |
|
| 2665 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2666 | + elseif ($this->element == 'order_supplier') |
|
| 2667 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2668 | + elseif ($this->element == 'supplier_proposal') |
|
| 2669 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2670 | + |
|
| 2671 | + if (! empty($MODULE)) {
|
|
| 2672 | + if (! empty($conf->global->$MODULE)) {
|
|
| 2673 | + $modsactivated = explode(',', $conf->global->$MODULE);
|
|
| 2674 | + foreach ($modsactivated as $mod) {
|
|
| 2675 | + if ($conf->$mod->enabled) |
|
| 2676 | + return 1; // update was disabled by specific setup |
|
| 2677 | + } |
|
| 2678 | + } |
|
| 2679 | + } |
|
| 2680 | + |
|
| 2681 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
| 2682 | + |
|
| 2683 | + if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2684 | + |
|
| 2685 | + $forcedroundingmode=$roundingadjust; |
|
| 2686 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2687 | + elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2688 | + |
|
| 2689 | + $error=0; |
|
| 2690 | + |
|
| 2691 | + $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
|
| 2692 | + |
|
| 2693 | + // Define constants to find lines to sum |
|
| 2694 | + $fieldtva='total_tva'; |
|
| 2695 | + $fieldlocaltax1='total_localtax1'; |
|
| 2696 | + $fieldlocaltax2='total_localtax2'; |
|
| 2697 | + $fieldup='subprice'; |
|
| 2698 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 2699 | + {
|
|
| 2700 | + $fieldtva='tva'; |
|
| 2701 | + $fieldup='pu_ht'; |
|
| 2702 | + } |
|
| 2703 | + if ($this->element == 'expensereport') |
|
| 2704 | + {
|
|
| 2705 | + $fieldup='value_unit'; |
|
| 2706 | + } |
|
| 2707 | + |
|
| 2708 | + $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,'; |
|
| 2709 | + $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2710 | + if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2711 | + $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2712 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2713 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2714 | + if ($exclspec) |
|
| 2715 | + {
|
|
| 2716 | + $product_field='product_type'; |
|
| 2717 | + if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2718 | + if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2719 | + } |
|
| 2720 | + $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 |
|
| 2721 | + |
|
| 2722 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2723 | + $resql = $this->db->query($sql); |
|
| 2724 | + if ($resql) |
|
| 2725 | + {
|
|
| 2726 | + $this->total_ht = 0; |
|
| 2727 | + $this->total_tva = 0; |
|
| 2728 | + $this->total_localtax1 = 0; |
|
| 2729 | + $this->total_localtax2 = 0; |
|
| 2730 | + $this->total_ttc = 0; |
|
| 2731 | + $total_ht_by_vats = array(); |
|
| 2732 | + $total_tva_by_vats = array(); |
|
| 2733 | + $total_ttc_by_vats = array(); |
|
| 2734 | + $this->multicurrency_total_ht = 0; |
|
| 2735 | + $this->multicurrency_total_tva = 0; |
|
| 2736 | + $this->multicurrency_total_ttc = 0; |
|
| 2737 | + |
|
| 2738 | + $num = $this->db->num_rows($resql); |
|
| 2739 | + $i = 0; |
|
| 2740 | + while ($i < $num) |
|
| 2741 | + {
|
|
| 2742 | + $obj = $this->db->fetch_object($resql); |
|
| 2743 | + |
|
| 2744 | + // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
|
| 2745 | + $parameters=array('fk_element' => $obj->rowid);
|
|
| 2746 | + $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 2747 | + |
|
| 2748 | + if (empty($reshook) && $forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 2749 | + {
|
|
| 2750 | + $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2751 | + $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); |
|
| 2752 | + $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2753 | + if ($diff) |
|
| 2754 | + {
|
|
| 2755 | + $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2756 | + 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);
|
|
| 2757 | + $resqlfix=$this->db->query($sqlfix); |
|
| 2758 | + if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2759 | + $obj->total_tva = $tmpcal[1]; |
|
| 2760 | + $obj->total_ttc = $tmpcal[2]; |
|
| 2761 | + // |
|
| 2762 | + } |
|
| 2763 | + } |
|
| 2764 | + |
|
| 2765 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2766 | + $this->total_tva += $obj->total_tva; |
|
| 2767 | + $this->total_localtax1 += $obj->total_localtax1; |
|
| 2768 | + $this->total_localtax2 += $obj->total_localtax2; |
|
| 2769 | + $this->total_ttc += $obj->total_ttc; |
|
| 2770 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2771 | + $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
|
| 2772 | + $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
|
| 2773 | + |
|
| 2774 | + if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2775 | + if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2776 | + if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 2777 | + $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
|
| 2778 | + $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
|
| 2779 | + $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
|
| 2780 | + |
|
| 2781 | + if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2782 | + {
|
|
| 2783 | + $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2784 | + $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2785 | + //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"; |
|
| 2786 | + if ($diff) |
|
| 2787 | + {
|
|
| 2788 | + if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; }
|
|
| 2789 | + $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; |
|
| 2790 | + 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);
|
|
| 2791 | + $resqlfix=$this->db->query($sqlfix); |
|
| 2792 | + if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2793 | + $this->total_tva -= $diff; |
|
| 2794 | + $this->total_ttc -= $diff; |
|
| 2795 | + $total_tva_by_vats[$obj->vatrate] -= $diff; |
|
| 2796 | + $total_ttc_by_vats[$obj->vatrate] -= $diff; |
|
| 2797 | + } |
|
| 2798 | + } |
|
| 2799 | + |
|
| 2800 | + $i++; |
|
| 2801 | + } |
|
| 2802 | + |
|
| 2803 | + // Add revenue stamp to total |
|
| 2804 | + $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2805 | + $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 2806 | + |
|
| 2807 | + // Situations totals |
|
| 2808 | + if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
| 2809 | + {
|
|
| 2810 | + $prev_sits = $this->get_prev_sits(); |
|
| 2811 | + |
|
| 2812 | + foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch.
|
|
| 2813 | + $this->total_ht -= $sit->total_ht; |
|
| 2814 | + $this->total_tva -= $sit->total_tva; |
|
| 2815 | + $this->total_localtax1 -= $sit->total_localtax1; |
|
| 2816 | + $this->total_localtax2 -= $sit->total_localtax2; |
|
| 2817 | + $this->total_ttc -= $sit->total_ttc; |
|
| 2818 | + $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; |
|
| 2819 | + $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; |
|
| 2820 | + $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; |
|
| 2821 | + } |
|
| 2822 | + } |
|
| 2823 | + |
|
| 2824 | + $this->db->free($resql); |
|
| 2825 | + |
|
| 2826 | + // Now update global field total_ht, total_ttc and tva |
|
| 2827 | + $fieldht='total_ht'; |
|
| 2828 | + $fieldtva='tva'; |
|
| 2829 | + $fieldlocaltax1='localtax1'; |
|
| 2830 | + $fieldlocaltax2='localtax2'; |
|
| 2831 | + $fieldttc='total_ttc'; |
|
| 2832 | + // Specific code for backward compatibility with old field names |
|
| 2833 | + if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2834 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2835 | + if ($this->element == 'propal') $fieldttc='total'; |
|
| 2836 | + if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2837 | + if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 2838 | + |
|
| 2839 | + if (empty($nodatabaseupdate)) |
|
| 2840 | + {
|
|
| 2841 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
| 2842 | + $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
| 2843 | + $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
| 2844 | + $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
| 2845 | + $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
| 2846 | + $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
| 2847 | + $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
| 2848 | + $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
| 2849 | + $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
| 2850 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 2851 | + |
|
| 2852 | + |
|
| 2853 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2854 | + $resql=$this->db->query($sql); |
|
| 2855 | + if (! $resql) |
|
| 2856 | + {
|
|
| 2857 | + $error++; |
|
| 2858 | + $this->error=$this->db->lasterror(); |
|
| 2859 | + $this->errors[]=$this->db->lasterror(); |
|
| 2860 | + } |
|
| 2861 | + } |
|
| 2862 | + |
|
| 2863 | + if (! $error) |
|
| 2864 | + {
|
|
| 2865 | + return 1; |
|
| 2866 | + } |
|
| 2867 | + else |
|
| 2868 | + {
|
|
| 2869 | + return -1; |
|
| 2870 | + } |
|
| 2871 | + } |
|
| 2872 | + else |
|
| 2873 | + {
|
|
| 2874 | + dol_print_error($this->db,'Bad request in update_price'); |
|
| 2875 | + return -1; |
|
| 2876 | + } |
|
| 2877 | + } |
|
| 2878 | + |
|
| 2879 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2880 | + /** |
|
| 2881 | + * Add objects linked in llx_element_element. |
|
| 2882 | + * |
|
| 2883 | + * @param string $origin Linked element type |
|
| 2884 | + * @param int $origin_id Linked element id |
|
| 2885 | + * @return int <=0 if KO, >0 if OK |
|
| 2886 | + * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
|
| 2887 | + */ |
|
| 2888 | + function add_object_linked($origin=null, $origin_id=null) |
|
| 2889 | + {
|
|
| 2890 | + // phpcs:enable |
|
| 2891 | + $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2892 | + $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2893 | + |
|
| 2894 | + // Special case |
|
| 2895 | + if ($origin == 'order') $origin='commande'; |
|
| 2896 | + if ($origin == 'invoice') $origin='facture'; |
|
| 2897 | + if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2898 | + if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 2899 | + $this->db->begin(); |
|
| 2900 | + |
|
| 2901 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
|
| 2902 | + $sql.= "fk_source"; |
|
| 2903 | + $sql.= ", sourcetype"; |
|
| 2904 | + $sql.= ", fk_target"; |
|
| 2905 | + $sql.= ", targettype"; |
|
| 2906 | + $sql.= ") VALUES (";
|
|
| 2907 | + $sql.= $origin_id; |
|
| 2908 | + $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2909 | + $sql.= ", ".$this->id; |
|
| 2910 | + $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2911 | + $sql.= ")"; |
|
| 2912 | + |
|
| 2913 | + dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
| 2914 | + if ($this->db->query($sql)) |
|
| 2915 | + {
|
|
| 2916 | + $this->db->commit(); |
|
| 2917 | + return 1; |
|
| 2918 | + } |
|
| 2919 | + else |
|
| 2920 | + {
|
|
| 2921 | + $this->error=$this->db->lasterror(); |
|
| 2922 | + $this->db->rollback(); |
|
| 2923 | + return 0; |
|
| 2924 | + } |
|
| 2925 | + } |
|
| 2926 | + |
|
| 2927 | + /** |
|
| 2928 | + * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into |
|
| 2929 | + * this->linkedObjectsIds array and |
|
| 2930 | + * this->linkedObjects array if $loadalsoobjects = 1 |
|
| 2931 | + * Possible usage for parameters: |
|
| 2932 | + * - all parameters empty -> we look all link to current object (current object can be source or target) |
|
| 2933 | + * - source id+type -> will get target list linked to source |
|
| 2934 | + * - target id+type -> will get source list linked to target |
|
| 2935 | + * - source id+type + target type -> will get target list of the type |
|
| 2936 | + * - target id+type + target source -> will get source list of the type |
|
| 2937 | + * |
|
| 2938 | + * @param int $sourceid Object source id (if not defined, id of object) |
|
| 2939 | + * @param string $sourcetype Object source type (if not defined, element name of object) |
|
| 2940 | + * @param int $targetid Object target id (if not defined, id of object) |
|
| 2941 | + * @param string $targettype Object target type (if not defined, elemennt name of object) |
|
| 2942 | + * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided |
|
| 2943 | + * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. |
|
| 2944 | + * @param string $orderby SQL 'ORDER BY' clause |
|
| 2945 | + * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) |
|
| 2946 | + * @return int <0 if KO, >0 if OK |
|
| 2947 | + * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
|
| 2948 | + */ |
|
| 2949 | + function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
| 2950 | + {
|
|
| 2951 | + global $conf; |
|
| 2952 | + |
|
| 2953 | + $this->linkedObjectsIds=array(); |
|
| 2954 | + $this->linkedObjects=array(); |
|
| 2955 | + |
|
| 2956 | + $justsource=false; |
|
| 2957 | + $justtarget=false; |
|
| 2958 | + $withtargettype=false; |
|
| 2959 | + $withsourcetype=false; |
|
| 2960 | + |
|
| 2961 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2962 | + {
|
|
| 2963 | + $justsource=true; // the source (id and type) is a search criteria |
|
| 2964 | + if (! empty($targettype)) $withtargettype=true; |
|
| 2965 | + } |
|
| 2966 | + if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2967 | + {
|
|
| 2968 | + $justtarget=true; // the target (id and type) is a search criteria |
|
| 2969 | + if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2970 | + } |
|
| 2971 | + |
|
| 2972 | + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2973 | + $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2974 | + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2975 | + $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2976 | + |
|
| 2977 | + /*if (empty($sourceid) && empty($targetid)) |
|
| 2978 | + {
|
|
| 2979 | + dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR);
|
|
| 2980 | + return -1; |
|
| 2981 | + }*/ |
|
| 2982 | + |
|
| 2983 | + // Links between objects are stored in table element_element |
|
| 2984 | + $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
|
| 2985 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2986 | + $sql.= " WHERE "; |
|
| 2987 | + if ($justsource || $justtarget) |
|
| 2988 | + {
|
|
| 2989 | + if ($justsource) |
|
| 2990 | + {
|
|
| 2991 | + $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2992 | + if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2993 | + } |
|
| 2994 | + else if ($justtarget) |
|
| 2995 | + {
|
|
| 2996 | + $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2997 | + if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 2998 | + } |
|
| 2999 | + } |
|
| 3000 | + else |
|
| 3001 | + {
|
|
| 3002 | + $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3003 | + $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3004 | + } |
|
| 3005 | + $sql .= ' ORDER BY '.$orderby; |
|
| 3006 | + |
|
| 3007 | + dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
| 3008 | + $resql = $this->db->query($sql); |
|
| 3009 | + if ($resql) |
|
| 3010 | + {
|
|
| 3011 | + $num = $this->db->num_rows($resql); |
|
| 3012 | + $i = 0; |
|
| 3013 | + while ($i < $num) |
|
| 3014 | + {
|
|
| 3015 | + $obj = $this->db->fetch_object($resql); |
|
| 3016 | + if ($justsource || $justtarget) |
|
| 3017 | + {
|
|
| 3018 | + if ($justsource) |
|
| 3019 | + {
|
|
| 3020 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3021 | + } |
|
| 3022 | + else if ($justtarget) |
|
| 3023 | + {
|
|
| 3024 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3025 | + } |
|
| 3026 | + } |
|
| 3027 | + else |
|
| 3028 | + {
|
|
| 3029 | + if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
|
| 3030 | + {
|
|
| 3031 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3032 | + } |
|
| 3033 | + if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
|
| 3034 | + {
|
|
| 3035 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3036 | + } |
|
| 3037 | + } |
|
| 3038 | + $i++; |
|
| 3039 | + } |
|
| 3040 | + |
|
| 3041 | + if (! empty($this->linkedObjectsIds)) |
|
| 3042 | + {
|
|
| 3043 | + $tmparray = $this->linkedObjectsIds; |
|
| 3044 | + foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3045 | + {
|
|
| 3046 | + // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
|
| 3047 | + $module = $element = $subelement = $objecttype; |
|
| 3048 | + if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
|
| 3049 | + && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
|
| 3050 | + {
|
|
| 3051 | + $module = $element = $regs[1]; |
|
| 3052 | + $subelement = $regs[2]; |
|
| 3053 | + } |
|
| 3054 | + |
|
| 3055 | + $classpath = $element.'/class'; |
|
| 3056 | + // To work with non standard classpath or module name |
|
| 3057 | + if ($objecttype == 'facture') {
|
|
| 3058 | + $classpath = 'compta/facture/class'; |
|
| 3059 | + } |
|
| 3060 | + else if ($objecttype == 'facturerec') {
|
|
| 3061 | + $classpath = 'compta/facture/class'; $module = 'facture'; |
|
| 3062 | + } |
|
| 3063 | + else if ($objecttype == 'propal') {
|
|
| 3064 | + $classpath = 'comm/propal/class'; |
|
| 3065 | + } |
|
| 3066 | + else if ($objecttype == 'supplier_proposal') {
|
|
| 3067 | + $classpath = 'supplier_proposal/class'; |
|
| 3068 | + } |
|
| 3069 | + else if ($objecttype == 'shipping') {
|
|
| 3070 | + $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
|
| 3071 | + } |
|
| 3072 | + else if ($objecttype == 'delivery') {
|
|
| 3073 | + $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
|
| 3074 | + } |
|
| 3075 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3076 | + $classpath = 'fourn/class'; $module = 'fournisseur'; |
|
| 3077 | + } |
|
| 3078 | + else if ($objecttype == 'fichinter') {
|
|
| 3079 | + $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
|
| 3080 | + } |
|
| 3081 | + else if ($objecttype == 'subscription') {
|
|
| 3082 | + $classpath = 'adherents/class'; $module = 'adherent'; |
|
| 3083 | + } |
|
| 3084 | + |
|
| 3085 | + // Set classfile |
|
| 3086 | + $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
|
| 3087 | + |
|
| 3088 | + if ($objecttype == 'order') {
|
|
| 3089 | + $classfile = 'commande'; $classname = 'Commande'; |
|
| 3090 | + } |
|
| 3091 | + else if ($objecttype == 'invoice_supplier') {
|
|
| 3092 | + $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
|
| 3093 | + } |
|
| 3094 | + else if ($objecttype == 'order_supplier') {
|
|
| 3095 | + $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
|
| 3096 | + } |
|
| 3097 | + else if ($objecttype == 'supplier_proposal') {
|
|
| 3098 | + $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
|
| 3099 | + } |
|
| 3100 | + else if ($objecttype == 'facturerec') {
|
|
| 3101 | + $classfile = 'facture-rec'; $classname = 'FactureRec'; |
|
| 3102 | + } |
|
| 3103 | + else if ($objecttype == 'subscription') {
|
|
| 3104 | + $classfile = 'subscription'; $classname = 'Subscription'; |
|
| 3105 | + } |
|
| 3106 | + |
|
| 3107 | + // Here $module, $classfile and $classname are set |
|
| 3108 | + if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) |
|
| 3109 | + {
|
|
| 3110 | + if ($loadalsoobjects) |
|
| 3111 | + {
|
|
| 3112 | + dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
|
|
| 3113 | + //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
|
| 3114 | + if (class_exists($classname)) |
|
| 3115 | + {
|
|
| 3116 | + foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3117 | + {
|
|
| 3118 | + $object = new $classname($this->db); |
|
| 3119 | + $ret = $object->fetch($objectid); |
|
| 3120 | + if ($ret >= 0) |
|
| 3121 | + {
|
|
| 3122 | + $this->linkedObjects[$objecttype][$i] = $object; |
|
| 3123 | + } |
|
| 3124 | + } |
|
| 3125 | + } |
|
| 3126 | + } |
|
| 3127 | + } |
|
| 3128 | + else |
|
| 3129 | + {
|
|
| 3130 | + unset($this->linkedObjectsIds[$objecttype]); |
|
| 3131 | + } |
|
| 3132 | + } |
|
| 3133 | + } |
|
| 3134 | + return 1; |
|
| 3135 | + } |
|
| 3136 | + else |
|
| 3137 | + {
|
|
| 3138 | + dol_print_error($this->db); |
|
| 3139 | + return -1; |
|
| 3140 | + } |
|
| 3141 | + } |
|
| 3142 | + |
|
| 3143 | + /** |
|
| 3144 | + * Update object linked of a current object |
|
| 3145 | + * |
|
| 3146 | + * @param int $sourceid Object source id |
|
| 3147 | + * @param string $sourcetype Object source type |
|
| 3148 | + * @param int $targetid Object target id |
|
| 3149 | + * @param string $targettype Object target type |
|
| 3150 | + * @return int >0 if OK, <0 if KO |
|
| 3151 | + * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
|
| 3152 | + */ |
|
| 3153 | + function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 3154 | + {
|
|
| 3155 | + $updatesource=false; |
|
| 3156 | + $updatetarget=false; |
|
| 3157 | + |
|
| 3158 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3159 | + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3160 | + |
|
| 3161 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
| 3162 | + if ($updatesource) |
|
| 3163 | + {
|
|
| 3164 | + $sql.= "fk_source = ".$sourceid; |
|
| 3165 | + $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3166 | + $sql.= " WHERE fk_target = ".$this->id; |
|
| 3167 | + $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3168 | + } |
|
| 3169 | + else if ($updatetarget) |
|
| 3170 | + {
|
|
| 3171 | + $sql.= "fk_target = ".$targetid; |
|
| 3172 | + $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3173 | + $sql.= " WHERE fk_source = ".$this->id; |
|
| 3174 | + $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3175 | + } |
|
| 3176 | + |
|
| 3177 | + dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
| 3178 | + if ($this->db->query($sql)) |
|
| 3179 | + {
|
|
| 3180 | + return 1; |
|
| 3181 | + } |
|
| 3182 | + else |
|
| 3183 | + {
|
|
| 3184 | + $this->error=$this->db->lasterror(); |
|
| 3185 | + return -1; |
|
| 3186 | + } |
|
| 3187 | + } |
|
| 3188 | + |
|
| 3189 | + /** |
|
| 3190 | + * Delete all links between an object $this |
|
| 3191 | + * |
|
| 3192 | + * @param int $sourceid Object source id |
|
| 3193 | + * @param string $sourcetype Object source type |
|
| 3194 | + * @param int $targetid Object target id |
|
| 3195 | + * @param string $targettype Object target type |
|
| 3196 | + * @param int $rowid Row id of line to delete. If defined, other parameters are not used. |
|
| 3197 | + * @return int >0 if OK, <0 if KO |
|
| 3198 | + * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
|
| 3199 | + */ |
|
| 3200 | + function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 3201 | + {
|
|
| 3202 | + $deletesource=false; |
|
| 3203 | + $deletetarget=false; |
|
| 3204 | + |
|
| 3205 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3206 | + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3207 | + |
|
| 3208 | + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 3209 | + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3210 | + $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3211 | + $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 3212 | + |
|
| 3213 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
| 3214 | + $sql.= " WHERE"; |
|
| 3215 | + if ($rowid > 0) |
|
| 3216 | + {
|
|
| 3217 | + $sql.=" rowid = ".$rowid; |
|
| 3218 | + } |
|
| 3219 | + else |
|
| 3220 | + {
|
|
| 3221 | + if ($deletesource) |
|
| 3222 | + {
|
|
| 3223 | + $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3224 | + $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3225 | + } |
|
| 3226 | + else if ($deletetarget) |
|
| 3227 | + {
|
|
| 3228 | + $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3229 | + $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3230 | + } |
|
| 3231 | + else |
|
| 3232 | + {
|
|
| 3233 | + $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3234 | + $sql.= " OR"; |
|
| 3235 | + $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3236 | + } |
|
| 3237 | + } |
|
| 3238 | + |
|
| 3239 | + dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
| 3240 | + if ($this->db->query($sql)) |
|
| 3241 | + {
|
|
| 3242 | + return 1; |
|
| 3243 | + } |
|
| 3244 | + else |
|
| 3245 | + {
|
|
| 3246 | + $this->error=$this->db->lasterror(); |
|
| 3247 | + $this->errors[]=$this->error; |
|
| 3248 | + return -1; |
|
| 3249 | + } |
|
| 3250 | + } |
|
| 3251 | + |
|
| 3252 | + /** |
|
| 3253 | + * Set status of an object |
|
| 3254 | + * |
|
| 3255 | + * @param int $status Status to set |
|
| 3256 | + * @param int $elementId Id of element to force (use this->id by default) |
|
| 3257 | + * @param string $elementType Type of element to force (use this->table_element by default) |
|
| 3258 | + * @param string $trigkey Trigger key to use for trigger |
|
| 3259 | + * @return int <0 if KO, >0 if OK |
|
| 3260 | + */ |
|
| 3261 | + function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
| 3262 | + {
|
|
| 3263 | + global $user,$langs,$conf; |
|
| 3264 | + |
|
| 3265 | + $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3266 | + |
|
| 3267 | + $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3268 | + $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3269 | + |
|
| 3270 | + $this->db->begin(); |
|
| 3271 | + |
|
| 3272 | + $fieldstatus="fk_statut"; |
|
| 3273 | + if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3274 | + if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3275 | + if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3276 | + if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3277 | + if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3278 | + if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3279 | + |
|
| 3280 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
| 3281 | + $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3282 | + // If status = 1 = validated, update also fk_user_valid |
|
| 3283 | + if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3284 | + $sql.= " WHERE rowid=".$elementId; |
|
| 3285 | + |
|
| 3286 | + dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
| 3287 | + if ($this->db->query($sql)) |
|
| 3288 | + {
|
|
| 3289 | + $error = 0; |
|
| 3290 | + |
|
| 3291 | + // Try autoset of trigkey |
|
| 3292 | + if (empty($trigkey)) |
|
| 3293 | + {
|
|
| 3294 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3295 | + if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3296 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3297 | + if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3298 | + if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3299 | + if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3300 | + } |
|
| 3301 | + |
|
| 3302 | + if ($trigkey) |
|
| 3303 | + {
|
|
| 3304 | + // Appel des triggers |
|
| 3305 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3306 | + $interface=new Interfaces($this->db); |
|
| 3307 | + $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3308 | + if ($result < 0) {
|
|
| 3309 | + $error++; $this->errors=$interface->errors; |
|
| 3310 | + } |
|
| 3311 | + // Fin appel triggers |
|
| 3312 | + } |
|
| 3313 | + |
|
| 3314 | + if (! $error) |
|
| 3315 | + {
|
|
| 3316 | + $this->db->commit(); |
|
| 3317 | + |
|
| 3318 | + if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3319 | + {
|
|
| 3320 | + $this->statut = $status; |
|
| 3321 | + $this->status = $status; |
|
| 3322 | + } |
|
| 3323 | + |
|
| 3324 | + return 1; |
|
| 3325 | + } |
|
| 3326 | + else |
|
| 3327 | + {
|
|
| 3328 | + $this->db->rollback(); |
|
| 3329 | + dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3330 | + return -1; |
|
| 3331 | + } |
|
| 3332 | + } |
|
| 3333 | + else |
|
| 3334 | + {
|
|
| 3335 | + $this->error=$this->db->lasterror(); |
|
| 3336 | + $this->db->rollback(); |
|
| 3337 | + return -1; |
|
| 3338 | + } |
|
| 3339 | + } |
|
| 3340 | + |
|
| 3341 | + |
|
| 3342 | + /** |
|
| 3343 | + * Load type of canvas of an object if it exists |
|
| 3344 | + * |
|
| 3345 | + * @param int $id Record id |
|
| 3346 | + * @param string $ref Record ref |
|
| 3347 | + * @return int <0 if KO, 0 if nothing done, >0 if OK |
|
| 3348 | + */ |
|
| 3349 | + function getCanvas($id=0,$ref='') |
|
| 3350 | + {
|
|
| 3351 | + global $conf; |
|
| 3352 | + |
|
| 3353 | + if (empty($id) && empty($ref)) return 0; |
|
| 3354 | + if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3355 | + |
|
| 3356 | + // Clean parameters |
|
| 3357 | + $ref = trim($ref); |
|
| 3358 | + |
|
| 3359 | + $sql = "SELECT rowid, canvas"; |
|
| 3360 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3361 | + $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
|
| 3362 | + if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3363 | + if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3364 | + |
|
| 3365 | + $resql = $this->db->query($sql); |
|
| 3366 | + if ($resql) |
|
| 3367 | + {
|
|
| 3368 | + $obj = $this->db->fetch_object($resql); |
|
| 3369 | + if ($obj) |
|
| 3370 | + {
|
|
| 3371 | + $this->canvas = $obj->canvas; |
|
| 3372 | + return 1; |
|
| 3373 | + } |
|
| 3374 | + else return 0; |
|
| 3375 | + } |
|
| 3376 | + else |
|
| 3377 | + {
|
|
| 3378 | + dol_print_error($this->db); |
|
| 3379 | + return -1; |
|
| 3380 | + } |
|
| 3381 | + } |
|
| 3382 | + |
|
| 3383 | + |
|
| 3384 | + /** |
|
| 3385 | + * Get special code of a line |
|
| 3386 | + * |
|
| 3387 | + * @param int $lineid Id of line |
|
| 3388 | + * @return int Special code |
|
| 3389 | + */ |
|
| 3390 | + function getSpecialCode($lineid) |
|
| 3391 | + {
|
|
| 3392 | + $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 3393 | + $sql.= ' WHERE rowid = '.$lineid; |
|
| 3394 | + $resql = $this->db->query($sql); |
|
| 3395 | + if ($resql) |
|
| 3396 | + {
|
|
| 3397 | + $row = $this->db->fetch_row($resql); |
|
| 3398 | + return $row[0]; |
|
| 3399 | + } |
|
| 3400 | + } |
|
| 3401 | + |
|
| 3402 | + /** |
|
| 3403 | + * Function to check if an object is used by others. |
|
| 3404 | + * Check is done into this->childtables. There is no check into llx_element_element. |
|
| 3405 | + * |
|
| 3406 | + * @param int $id Force id of object |
|
| 3407 | + * @return int <0 if KO, 0 if not used, >0 if already used |
|
| 3408 | + */ |
|
| 3409 | + function isObjectUsed($id=0) |
|
| 3410 | + {
|
|
| 3411 | + global $langs; |
|
| 3412 | + |
|
| 3413 | + if (empty($id)) $id=$this->id; |
|
| 3414 | + |
|
| 3415 | + // Check parameters |
|
| 3416 | + if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3417 | + {
|
|
| 3418 | + dol_print_error('Called isObjectUsed on a class with property this->childtables not defined');
|
|
| 3419 | + return -1; |
|
| 3420 | + } |
|
| 3421 | + |
|
| 3422 | + $arraytoscan = $this->childtables; |
|
| 3423 | + // For backward compatibility, we check if array is old format array('table1', 'table2', ...)
|
|
| 3424 | + $tmparray=array_keys($this->childtables); |
|
| 3425 | + if (is_numeric($tmparray[0])) |
|
| 3426 | + {
|
|
| 3427 | + $arraytoscan = array_flip($this->childtables); |
|
| 3428 | + } |
|
| 3429 | + |
|
| 3430 | + // Test if child exists |
|
| 3431 | + $haschild=0; |
|
| 3432 | + foreach($arraytoscan as $table => $elementname) |
|
| 3433 | + {
|
|
| 3434 | + //print $id.'-'.$table.'-'.$elementname.'<br>'; |
|
| 3435 | + // Check if third party can be deleted |
|
| 3436 | + $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
| 3437 | + $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3438 | + $resql=$this->db->query($sql); |
|
| 3439 | + if ($resql) |
|
| 3440 | + {
|
|
| 3441 | + $obj=$this->db->fetch_object($resql); |
|
| 3442 | + if ($obj->nb > 0) |
|
| 3443 | + {
|
|
| 3444 | + $langs->load("errors");
|
|
| 3445 | + //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
|
| 3446 | + $haschild += $obj->nb; |
|
| 3447 | + if (is_numeric($elementname)) // old usage |
|
| 3448 | + {
|
|
| 3449 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3450 | + } |
|
| 3451 | + else // new usage: $elementname=Translation key |
|
| 3452 | + {
|
|
| 3453 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
|
| 3454 | + } |
|
| 3455 | + break; // We found at least one, we stop here |
|
| 3456 | + } |
|
| 3457 | + } |
|
| 3458 | + else |
|
| 3459 | + {
|
|
| 3460 | + $this->errors[]=$this->db->lasterror(); |
|
| 3461 | + return -1; |
|
| 3462 | + } |
|
| 3463 | + } |
|
| 3464 | + if ($haschild > 0) |
|
| 3465 | + {
|
|
| 3466 | + $this->errors[]="ErrorRecordHasChildren"; |
|
| 3467 | + return $haschild; |
|
| 3468 | + } |
|
| 3469 | + else return 0; |
|
| 3470 | + } |
|
| 3471 | + |
|
| 3472 | + /** |
|
| 3473 | + * Function to say how many lines object contains |
|
| 3474 | + * |
|
| 3475 | + * @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 |
|
| 3476 | + * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
|
| 3477 | + */ |
|
| 3478 | + function hasProductsOrServices($predefined=-1) |
|
| 3479 | + {
|
|
| 3480 | + $nb=0; |
|
| 3481 | + |
|
| 3482 | + foreach($this->lines as $key => $val) |
|
| 3483 | + {
|
|
| 3484 | + $qualified=0; |
|
| 3485 | + if ($predefined == -1) $qualified=1; |
|
| 3486 | + if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3487 | + if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3488 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3489 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3490 | + if ($qualified) $nb++; |
|
| 3491 | + } |
|
| 3492 | + dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
| 3493 | + return $nb; |
|
| 3494 | + } |
|
| 3495 | + |
|
| 3496 | + /** |
|
| 3497 | + * Function that returns the total amount HT of discounts applied for all lines. |
|
| 3498 | + * |
|
| 3499 | + * @return float |
|
| 3500 | + */ |
|
| 3501 | + function getTotalDiscount() |
|
| 3502 | + {
|
|
| 3503 | + $total_discount=0.00; |
|
| 3504 | + |
|
| 3505 | + $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
|
| 3506 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3507 | + $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3508 | + |
|
| 3509 | + dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
| 3510 | + $resql = $this->db->query($sql); |
|
| 3511 | + if ($resql) |
|
| 3512 | + {
|
|
| 3513 | + $num=$this->db->num_rows($resql); |
|
| 3514 | + $i=0; |
|
| 3515 | + while ($i < $num) |
|
| 3516 | + {
|
|
| 3517 | + $obj = $this->db->fetch_object($resql); |
|
| 3518 | + |
|
| 3519 | + $pu_ht = $obj->pu_ht; |
|
| 3520 | + $qty= $obj->qty; |
|
| 3521 | + $total_ht = $obj->total_ht; |
|
| 3522 | + |
|
| 3523 | + $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
|
| 3524 | + $total_discount += $total_discount_line; |
|
| 3525 | + |
|
| 3526 | + $i++; |
|
| 3527 | + } |
|
| 3528 | + } |
|
| 3529 | + |
|
| 3530 | + //print $total_discount; exit; |
|
| 3531 | + return price2num($total_discount); |
|
| 3532 | + } |
|
| 3533 | + |
|
| 3534 | + |
|
| 3535 | + /** |
|
| 3536 | + * Return into unit=0, the calculated total of weight and volume of all lines * qty |
|
| 3537 | + * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. |
|
| 3538 | + * |
|
| 3539 | + * @return array array('weight'=>...,'volume'=>...)
|
|
| 3540 | + */ |
|
| 3541 | + function getTotalWeightVolume() |
|
| 3542 | + {
|
|
| 3543 | + $totalWeight = 0; |
|
| 3544 | + $totalVolume = 0; |
|
| 3545 | + // defined for shipment only |
|
| 3546 | + $totalOrdered = ''; |
|
| 3547 | + // defined for shipment only |
|
| 3548 | + $totalToShip = ''; |
|
| 3549 | + |
|
| 3550 | + foreach ($this->lines as $line) |
|
| 3551 | + {
|
|
| 3552 | + if (isset($line->qty_asked)) |
|
| 3553 | + {
|
|
| 3554 | + if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3555 | + $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3556 | + } |
|
| 3557 | + if (isset($line->qty_shipped)) |
|
| 3558 | + {
|
|
| 3559 | + if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3560 | + $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3561 | + }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3562 | + {
|
|
| 3563 | + if (empty($totalToShip)) $totalToShip=0; |
|
| 3564 | + $totalToShip+=$line->qty; // defined for reception only |
|
| 3565 | + } |
|
| 3566 | + |
|
| 3567 | + // Define qty, weight, volume, weight_units, volume_units |
|
| 3568 | + if ($this->element == 'shipping') {
|
|
| 3569 | + // for shipments |
|
| 3570 | + $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
|
| 3571 | + } |
|
| 3572 | + else {
|
|
| 3573 | + $qty = $line->qty ? $line->qty : 0; |
|
| 3574 | + } |
|
| 3575 | + |
|
| 3576 | + $weight = $line->weight ? $line->weight : 0; |
|
| 3577 | + ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
| 3578 | + $volume = $line->volume ? $line->volume : 0; |
|
| 3579 | + ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
| 3580 | + |
|
| 3581 | + $weight_units=$line->weight_units; |
|
| 3582 | + ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
| 3583 | + $volume_units=$line->volume_units; |
|
| 3584 | + ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
| 3585 | + |
|
| 3586 | + $weightUnit=0; |
|
| 3587 | + $volumeUnit=0; |
|
| 3588 | + if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3589 | + if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3590 | + |
|
| 3591 | + if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3592 | + if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3593 | + |
|
| 3594 | + //var_dump($line->volume_units); |
|
| 3595 | + if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3596 | + {
|
|
| 3597 | + $trueWeightUnit=pow(10, $weightUnit); |
|
| 3598 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3599 | + } |
|
| 3600 | + else {
|
|
| 3601 | + if ($weight_units == 99) {
|
|
| 3602 | + // conversion 1 Pound = 0.45359237 KG |
|
| 3603 | + $trueWeightUnit = 0.45359237; |
|
| 3604 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3605 | + } elseif ($weight_units == 98) {
|
|
| 3606 | + // conversion 1 Ounce = 0.0283495 KG |
|
| 3607 | + $trueWeightUnit = 0.0283495; |
|
| 3608 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3609 | + } |
|
| 3610 | + else |
|
| 3611 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3612 | + } |
|
| 3613 | + if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3614 | + {
|
|
| 3615 | + //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
|
| 3616 | + $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3617 | + //print $line->volume; |
|
| 3618 | + $totalVolume += $volume * $qty * $trueVolumeUnit; |
|
| 3619 | + } |
|
| 3620 | + else |
|
| 3621 | + {
|
|
| 3622 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3623 | + } |
|
| 3624 | + } |
|
| 3625 | + |
|
| 3626 | + return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip);
|
|
| 3627 | + } |
|
| 3628 | + |
|
| 3629 | + |
|
| 3630 | + /** |
|
| 3631 | + * Set extra parameters |
|
| 3632 | + * |
|
| 3633 | + * @return int <0 if KO, >0 if OK |
|
| 3634 | + */ |
|
| 3635 | + function setExtraParameters() |
|
| 3636 | + {
|
|
| 3637 | + $this->db->begin(); |
|
| 3638 | + |
|
| 3639 | + $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3640 | + |
|
| 3641 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3642 | + $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3643 | + $sql.= " WHERE rowid = ".$this->id; |
|
| 3644 | + |
|
| 3645 | + dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
| 3646 | + $resql = $this->db->query($sql); |
|
| 3647 | + if (! $resql) |
|
| 3648 | + {
|
|
| 3649 | + $this->error=$this->db->lasterror(); |
|
| 3650 | + $this->db->rollback(); |
|
| 3651 | + return -1; |
|
| 3652 | + } |
|
| 3653 | + else |
|
| 3654 | + {
|
|
| 3655 | + $this->db->commit(); |
|
| 3656 | + return 1; |
|
| 3657 | + } |
|
| 3658 | + } |
|
| 3659 | + |
|
| 3660 | + |
|
| 3661 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 3662 | + /** |
|
| 3663 | + * Return incoterms informations |
|
| 3664 | + * TODO Use a cache for label get |
|
| 3665 | + * |
|
| 3666 | + * @return string incoterms info |
|
| 3667 | + */ |
|
| 3668 | + function display_incoterms() |
|
| 3669 | + {
|
|
| 3670 | + // phpcs:enable |
|
| 3671 | + $out = ''; |
|
| 3672 | + $this->libelle_incoterms = ''; |
|
| 3673 | + if (!empty($this->fk_incoterms)) |
|
| 3674 | + {
|
|
| 3675 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3676 | + $result = $this->db->query($sql); |
|
| 3677 | + if ($result) |
|
| 3678 | + {
|
|
| 3679 | + $res = $this->db->fetch_object($result); |
|
| 3680 | + $out .= $res->code; |
|
| 3681 | + } |
|
| 3682 | + } |
|
| 3683 | + |
|
| 3684 | + $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3685 | + |
|
| 3686 | + return $out; |
|
| 3687 | + } |
|
| 3688 | + |
|
| 3689 | + /** |
|
| 3690 | + * Return incoterms informations for pdf display |
|
| 3691 | + * |
|
| 3692 | + * @return string incoterms info |
|
| 3693 | + */ |
|
| 3694 | + function getIncotermsForPDF() |
|
| 3695 | + {
|
|
| 3696 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3697 | + $resql = $this->db->query($sql); |
|
| 3698 | + if ($resql) |
|
| 3699 | + {
|
|
| 3700 | + $num = $this->db->num_rows($resql); |
|
| 3701 | + if ($num > 0) |
|
| 3702 | + {
|
|
| 3703 | + $res = $this->db->fetch_object($resql); |
|
| 3704 | + return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
| 3705 | + } |
|
| 3706 | + else |
|
| 3707 | + {
|
|
| 3708 | + return ''; |
|
| 3709 | + } |
|
| 3710 | + } |
|
| 3711 | + else |
|
| 3712 | + {
|
|
| 3713 | + $this->errors[] = $this->db->lasterror(); |
|
| 3714 | + return false; |
|
| 3715 | + } |
|
| 3716 | + } |
|
| 3717 | + |
|
| 3718 | + /** |
|
| 3719 | + * Define incoterms values of current object |
|
| 3720 | + * |
|
| 3721 | + * @param int $id_incoterm Id of incoterm to set or '' to remove |
|
| 3722 | + * @param string $location location of incoterm |
|
| 3723 | + * @return int <0 if KO, >0 if OK |
|
| 3724 | + */ |
|
| 3725 | + function setIncoterms($id_incoterm, $location) |
|
| 3726 | + {
|
|
| 3727 | + if ($this->id && $this->table_element) |
|
| 3728 | + {
|
|
| 3729 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3730 | + $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3731 | + $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3732 | + $sql.= " WHERE rowid = " . $this->id; |
|
| 3733 | + dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
| 3734 | + $resql=$this->db->query($sql); |
|
| 3735 | + if ($resql) |
|
| 3736 | + {
|
|
| 3737 | + $this->fk_incoterms = $id_incoterm; |
|
| 3738 | + $this->location_incoterms = $location; |
|
| 3739 | + |
|
| 3740 | + $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3741 | + $res = $this->db->query($sql); |
|
| 3742 | + if ($res) |
|
| 3743 | + {
|
|
| 3744 | + $obj = $this->db->fetch_object($res); |
|
| 3745 | + $this->libelle_incoterms = $obj->libelle; |
|
| 3746 | + } |
|
| 3747 | + return 1; |
|
| 3748 | + } |
|
| 3749 | + else |
|
| 3750 | + {
|
|
| 3751 | + $this->errors[] = $this->db->lasterror(); |
|
| 3752 | + return -1; |
|
| 3753 | + } |
|
| 3754 | + } |
|
| 3755 | + else return -1; |
|
| 3756 | + } |
|
| 3757 | + |
|
| 3758 | + |
|
| 3759 | + // -------------------- |
|
| 3760 | + // TODO: All functions here must be redesigned and moved as they are not business functions but output functions |
|
| 3761 | + // -------------------- |
|
| 3762 | + |
|
| 3763 | + /* This is to show add lines */ |
|
| 3764 | + |
|
| 3765 | + /** |
|
| 3766 | + * Show add free and predefined products/services form |
|
| 3767 | + * |
|
| 3768 | + * @param int $dateSelector 1=Show also date range input fields |
|
| 3769 | + * @param Societe $seller Object thirdparty who sell |
|
| 3770 | + * @param Societe $buyer Object thirdparty who buy |
|
| 3771 | + * @return void |
|
| 3772 | + */ |
|
| 3773 | + function formAddObjectLine($dateSelector, $seller, $buyer) |
|
| 3774 | + {
|
|
| 3775 | + global $conf,$user,$langs,$object,$hookmanager; |
|
| 3776 | + global $form,$bcnd,$var; |
|
| 3777 | + |
|
| 3778 | + // Line extrafield |
|
| 3779 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3780 | + $extrafieldsline = new ExtraFields($this->db); |
|
| 3781 | + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3782 | + |
|
| 3783 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 3784 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 3785 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 3786 | + foreach($dirtpls as $reldir) |
|
| 3787 | + {
|
|
| 3788 | + $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
| 3789 | + if (empty($conf->file->strict_mode)) {
|
|
| 3790 | + $res=@include $tpl; |
|
| 3791 | + } else {
|
|
| 3792 | + $res=include $tpl; // for debug |
|
| 3793 | + } |
|
| 3794 | + if ($res) break; |
|
| 3795 | + } |
|
| 3796 | + } |
|
| 3797 | + |
|
| 3798 | + |
|
| 3799 | + |
|
| 3800 | + /* This is to show array of line of details */ |
|
| 3801 | + |
|
| 3802 | + |
|
| 3803 | + /** |
|
| 3804 | + * Return HTML table for object lines |
|
| 3805 | + * TODO Move this into an output class file (htmlline.class.php) |
|
| 3806 | + * If lines are into a template, title must also be into a template |
|
| 3807 | + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 3808 | + * |
|
| 3809 | + * @param string $action Action code |
|
| 3810 | + * @param string $seller Object of seller third party |
|
| 3811 | + * @param string $buyer Object of buyer third party |
|
| 3812 | + * @param int $selected Object line selected |
|
| 3813 | + * @param int $dateSelector 1=Show also date range input fields |
|
| 3814 | + * @return void |
|
| 3815 | + */ |
|
| 3816 | + function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3817 | + {
|
|
| 3818 | + global $conf, $hookmanager, $langs, $user; |
|
| 3819 | + // TODO We should not use global var for this ! |
|
| 3820 | + global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
|
| 3821 | + |
|
| 3822 | + // Define usemargins |
|
| 3823 | + $usemargins=0; |
|
| 3824 | + if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
|
|
| 3825 | + |
|
| 3826 | + $num = count($this->lines); |
|
| 3827 | + |
|
| 3828 | + // Line extrafield |
|
| 3829 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3830 | + $extrafieldsline = new ExtraFields($this->db); |
|
| 3831 | + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3832 | + |
|
| 3833 | + $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3834 | + $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3835 | + if (empty($reshook)) |
|
| 3836 | + {
|
|
| 3837 | + // Title line |
|
| 3838 | + print "<thead>\n"; |
|
| 3839 | + |
|
| 3840 | + print '<tr class="liste_titre nodrag nodrop">'; |
|
| 3841 | + |
|
| 3842 | + // Adds a line numbering column |
|
| 3843 | + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3844 | + |
|
| 3845 | + // Description |
|
| 3846 | + print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
|
| 3847 | + |
|
| 3848 | + if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') |
|
| 3849 | + {
|
|
| 3850 | + print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>';
|
|
| 3851 | + } |
|
| 3852 | + |
|
| 3853 | + // VAT |
|
| 3854 | + print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>';
|
|
| 3855 | + |
|
| 3856 | + // Price HT |
|
| 3857 | + print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
|
|
| 3858 | + |
|
| 3859 | + // Multicurrency |
|
| 3860 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
|
|
| 3861 | + |
|
| 3862 | + if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
|
|
| 3863 | + |
|
| 3864 | + // Qty |
|
| 3865 | + print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
|
| 3866 | + |
|
| 3867 | + if($conf->global->PRODUCT_USE_UNITS) |
|
| 3868 | + {
|
|
| 3869 | + print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
|
|
| 3870 | + } |
|
| 3871 | + |
|
| 3872 | + // Reduction short |
|
| 3873 | + print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
|
|
| 3874 | + |
|
| 3875 | + if ($this->situation_cycle_ref) {
|
|
| 3876 | + print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
|
|
| 3877 | + } |
|
| 3878 | + |
|
| 3879 | + if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3880 | + {
|
|
| 3881 | + if (!empty($user->rights->margins->creer)) |
|
| 3882 | + {
|
|
| 3883 | + if ($conf->global->MARGIN_TYPE == "1") |
|
| 3884 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
|
|
| 3885 | + else |
|
| 3886 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
|
| 3887 | + } |
|
| 3888 | + |
|
| 3889 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3890 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
|
| 3891 | + if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3892 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
|
| 3893 | + } |
|
| 3894 | + |
|
| 3895 | + // Total HT |
|
| 3896 | + print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
|
|
| 3897 | + |
|
| 3898 | + // Multicurrency |
|
| 3899 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
|
|
| 3900 | + |
|
| 3901 | + if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
|
| 3902 | + |
|
| 3903 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3904 | + |
|
| 3905 | + print '<td class="linecoldelete" width="10"></td>'; |
|
| 3906 | + |
|
| 3907 | + print '<td class="linecolmove" width="10"></td>'; |
|
| 3908 | + |
|
| 3909 | + if($action == 'selectlines') |
|
| 3910 | + {
|
|
| 3911 | + print '<td class="linecolcheckall" align="center">'; |
|
| 3912 | + print '<input type="checkbox" class="linecheckboxtoggle" />'; |
|
| 3913 | + print '<script type="text/javascript">$(document).ready(function() {$(".linecheckboxtoggle").click(function() {var checkBoxes = $(".linecheckbox");checkBoxes.prop("checked", this.checked);})});</script>';
|
|
| 3914 | + print '</td>'; |
|
| 3915 | + } |
|
| 3916 | + |
|
| 3917 | + print "</tr>\n"; |
|
| 3918 | + print "</thead>\n"; |
|
| 3919 | + } |
|
| 3920 | + |
|
| 3921 | + $var = true; |
|
| 3922 | + $i = 0; |
|
| 3923 | + |
|
| 3924 | + print "<tbody>\n"; |
|
| 3925 | + foreach ($this->lines as $line) |
|
| 3926 | + {
|
|
| 3927 | + //Line extrafield |
|
| 3928 | + $line->fetch_optionals(); |
|
| 3929 | + |
|
| 3930 | + //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 3931 | + if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 3932 | + {
|
|
| 3933 | + if (empty($line->fk_parent_line)) |
|
| 3934 | + {
|
|
| 3935 | + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3936 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3937 | + } |
|
| 3938 | + else |
|
| 3939 | + {
|
|
| 3940 | + $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);
|
|
| 3941 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3942 | + } |
|
| 3943 | + } |
|
| 3944 | + if (empty($reshook)) |
|
| 3945 | + {
|
|
| 3946 | + $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3947 | + } |
|
| 3948 | + |
|
| 3949 | + $i++; |
|
| 3950 | + } |
|
| 3951 | + print "</tbody>\n"; |
|
| 3952 | + } |
|
| 3953 | + |
|
| 3954 | + /** |
|
| 3955 | + * Return HTML content of a detail line |
|
| 3956 | + * TODO Move this into an output class file (htmlline.class.php) |
|
| 3957 | + * |
|
| 3958 | + * @param string $action GET/POST action |
|
| 3959 | + * @param CommonObjectLine $line Selected object line to output |
|
| 3960 | + * @param string $var Is it a an odd line (true) |
|
| 3961 | + * @param int $num Number of line (0) |
|
| 3962 | + * @param int $i I |
|
| 3963 | + * @param int $dateSelector 1=Show also date range input fields |
|
| 3964 | + * @param string $seller Object of seller third party |
|
| 3965 | + * @param string $buyer Object of buyer third party |
|
| 3966 | + * @param int $selected Object line selected |
|
| 3967 | + * @param int $extrafieldsline Object of extrafield line attribute |
|
| 3968 | + * @return void |
|
| 3969 | + */ |
|
| 3970 | + function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3971 | + {
|
|
| 3972 | + global $conf,$langs,$user,$object,$hookmanager; |
|
| 3973 | + global $form,$bc,$bcdd; |
|
| 3974 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3975 | + |
|
| 3976 | + $object_rights = $this->getRights(); |
|
| 3977 | + |
|
| 3978 | + $element=$this->element; |
|
| 3979 | + |
|
| 3980 | + $text=''; $description=''; $type=0; |
|
| 3981 | + |
|
| 3982 | + // Show product and description |
|
| 3983 | + $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 3984 | + // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
|
| 3985 | + if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3986 | + if (! empty($line->date_end)) $type=1; // deprecated |
|
| 3987 | + |
|
| 3988 | + // Ligne en mode visu |
|
| 3989 | + if ($action != 'editline' || $selected != $line->id) |
|
| 3990 | + {
|
|
| 3991 | + // Product |
|
| 3992 | + if ($line->fk_product > 0) |
|
| 3993 | + {
|
|
| 3994 | + $product_static = new Product($this->db); |
|
| 3995 | + $product_static->fetch($line->fk_product); |
|
| 3996 | + |
|
| 3997 | + $product_static->ref = $line->ref; //can change ref in hook |
|
| 3998 | + $product_static->label = $line->label; //can change label in hook |
|
| 3999 | + $text=$product_static->getNomUrl(1); |
|
| 4000 | + |
|
| 4001 | + // Define output language and label |
|
| 4002 | + if (! empty($conf->global->MAIN_MULTILANGS)) |
|
| 4003 | + {
|
|
| 4004 | + if (! is_object($this->thirdparty)) |
|
| 4005 | + {
|
|
| 4006 | + dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
|
|
| 4007 | + return; |
|
| 4008 | + } |
|
| 4009 | + |
|
| 4010 | + $prod = new Product($this->db); |
|
| 4011 | + $prod->fetch($line->fk_product); |
|
| 4012 | + |
|
| 4013 | + $outputlangs = $langs; |
|
| 4014 | + $newlang=''; |
|
| 4015 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4016 | + if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
| 4017 | + if (! empty($newlang)) |
|
| 4018 | + {
|
|
| 4019 | + $outputlangs = new Translate("",$conf);
|
|
| 4020 | + $outputlangs->setDefaultLang($newlang); |
|
| 4021 | + } |
|
| 4022 | + |
|
| 4023 | + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4024 | + } |
|
| 4025 | + else |
|
| 4026 | + {
|
|
| 4027 | + $label = $line->product_label; |
|
| 4028 | + } |
|
| 4029 | + |
|
| 4030 | + $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 4031 | + $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. |
|
| 4032 | + } |
|
| 4033 | + |
|
| 4034 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4035 | + |
|
| 4036 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4037 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 4038 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4039 | + foreach($dirtpls as $reldir) |
|
| 4040 | + {
|
|
| 4041 | + $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
| 4042 | + if (empty($conf->file->strict_mode)) {
|
|
| 4043 | + $res=@include $tpl; |
|
| 4044 | + } else {
|
|
| 4045 | + $res=include $tpl; // for debug |
|
| 4046 | + } |
|
| 4047 | + if ($res) break; |
|
| 4048 | + } |
|
| 4049 | + } |
|
| 4050 | + |
|
| 4051 | + // Ligne en mode update |
|
| 4052 | + if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
|
| 4053 | + {
|
|
| 4054 | + $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4055 | + $placeholder=' placeholder="'.$langs->trans("Label").'"';
|
|
| 4056 | + |
|
| 4057 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4058 | + |
|
| 4059 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4060 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 4061 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4062 | + foreach($dirtpls as $reldir) |
|
| 4063 | + {
|
|
| 4064 | + $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
| 4065 | + if (empty($conf->file->strict_mode)) {
|
|
| 4066 | + $res=@include $tpl; |
|
| 4067 | + } else {
|
|
| 4068 | + $res=include $tpl; // for debug |
|
| 4069 | + } |
|
| 4070 | + if ($res) break; |
|
| 4071 | + } |
|
| 4072 | + } |
|
| 4073 | + } |
|
| 4074 | + |
|
| 4075 | + |
|
| 4076 | + /* This is to show array of line of details of source object */ |
|
| 4077 | + |
|
| 4078 | + |
|
| 4079 | + /** |
|
| 4080 | + * Return HTML table table of source object lines |
|
| 4081 | + * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4082 | + * If lines are into a template, title must also be into a template |
|
| 4083 | + * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. |
|
| 4084 | + * |
|
| 4085 | + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
|
| 4086 | + * @return void |
|
| 4087 | + */ |
|
| 4088 | + function printOriginLinesList($restrictlist='') |
|
| 4089 | + {
|
|
| 4090 | + global $langs, $hookmanager, $conf; |
|
| 4091 | + |
|
| 4092 | + print '<tr class="liste_titre">'; |
|
| 4093 | + print '<td>'.$langs->trans('Ref').'</td>';
|
|
| 4094 | + print '<td>'.$langs->trans('Description').'</td>';
|
|
| 4095 | + print '<td align="right">'.$langs->trans('VATRate').'</td>';
|
|
| 4096 | + print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
|
| 4097 | + if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
|
|
| 4098 | + print '<td align="right">'.$langs->trans('Qty').'</td>';
|
|
| 4099 | + if($conf->global->PRODUCT_USE_UNITS) |
|
| 4100 | + {
|
|
| 4101 | + print '<td align="left">'.$langs->trans('Unit').'</td>';
|
|
| 4102 | + } |
|
| 4103 | + print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
|
|
| 4104 | + |
|
| 4105 | + $var = true; |
|
| 4106 | + $i = 0; |
|
| 4107 | + |
|
| 4108 | + if (! empty($this->lines)) |
|
| 4109 | + {
|
|
| 4110 | + foreach ($this->lines as $line) |
|
| 4111 | + {
|
|
| 4112 | + if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 4113 | + {
|
|
| 4114 | + if (empty($line->fk_parent_line)) |
|
| 4115 | + {
|
|
| 4116 | + $parameters=array('line'=>$line,'var'=>$var,'i'=>$i);
|
|
| 4117 | + $action=''; |
|
| 4118 | + $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
| 4119 | + } |
|
| 4120 | + } |
|
| 4121 | + else |
|
| 4122 | + {
|
|
| 4123 | + $this->printOriginLine($line, $var, $restrictlist); |
|
| 4124 | + } |
|
| 4125 | + |
|
| 4126 | + $i++; |
|
| 4127 | + } |
|
| 4128 | + } |
|
| 4129 | + } |
|
| 4130 | + |
|
| 4131 | + /** |
|
| 4132 | + * Return HTML with a line of table array of source object lines |
|
| 4133 | + * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4134 | + * If lines are into a template, title must also be into a template |
|
| 4135 | + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 4136 | + * |
|
| 4137 | + * @param CommonObjectLine $line Line |
|
| 4138 | + * @param string $var Var |
|
| 4139 | + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
|
| 4140 | + * @return void |
|
| 4141 | + */ |
|
| 4142 | + function printOriginLine($line, $var, $restrictlist='') |
|
| 4143 | + {
|
|
| 4144 | + global $langs, $conf; |
|
| 4145 | + |
|
| 4146 | + //var_dump($line); |
|
| 4147 | + if (!empty($line->date_start)) |
|
| 4148 | + {
|
|
| 4149 | + $date_start=$line->date_start; |
|
| 4150 | + } |
|
| 4151 | + else |
|
| 4152 | + {
|
|
| 4153 | + $date_start=$line->date_debut_prevue; |
|
| 4154 | + if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4155 | + } |
|
| 4156 | + if (!empty($line->date_end)) |
|
| 4157 | + {
|
|
| 4158 | + $date_end=$line->date_end; |
|
| 4159 | + } |
|
| 4160 | + else |
|
| 4161 | + {
|
|
| 4162 | + $date_end=$line->date_fin_prevue; |
|
| 4163 | + if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4164 | + } |
|
| 4165 | + |
|
| 4166 | + $this->tpl['label'] = ''; |
|
| 4167 | + if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4168 | + |
|
| 4169 | + if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4170 | + {
|
|
| 4171 | + $discount=new DiscountAbsolute($this->db); |
|
| 4172 | + $discount->fk_soc = $this->socid; |
|
| 4173 | + $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 4174 | + } |
|
| 4175 | + else if (! empty($line->fk_product)) |
|
| 4176 | + {
|
|
| 4177 | + $productstatic = new Product($this->db); |
|
| 4178 | + $productstatic->id = $line->fk_product; |
|
| 4179 | + $productstatic->ref = $line->ref; |
|
| 4180 | + $productstatic->type = $line->fk_product_type; |
|
| 4181 | + if(empty($productstatic->ref)){
|
|
| 4182 | + $line->fetch_product(); |
|
| 4183 | + $productstatic = $line->product; |
|
| 4184 | + } |
|
| 4185 | + |
|
| 4186 | + $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 4187 | + $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 4188 | + // Dates |
|
| 4189 | + if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4190 | + {
|
|
| 4191 | + $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4192 | + } |
|
| 4193 | + } |
|
| 4194 | + else |
|
| 4195 | + {
|
|
| 4196 | + $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
|
| 4197 | + if (!empty($line->desc)) {
|
|
| 4198 | + $this->tpl['label'].=$line->desc; |
|
| 4199 | + }else {
|
|
| 4200 | + $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 4201 | + } |
|
| 4202 | + |
|
| 4203 | + // Dates |
|
| 4204 | + if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4205 | + {
|
|
| 4206 | + $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4207 | + } |
|
| 4208 | + } |
|
| 4209 | + |
|
| 4210 | + if (! empty($line->desc)) |
|
| 4211 | + {
|
|
| 4212 | + if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4213 | + {
|
|
| 4214 | + $discount=new DiscountAbsolute($this->db); |
|
| 4215 | + $discount->fetch($line->fk_remise_except); |
|
| 4216 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
|
| 4217 | + } |
|
| 4218 | + elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4219 | + {
|
|
| 4220 | + $discount=new DiscountAbsolute($this->db); |
|
| 4221 | + $discount->fetch($line->fk_remise_except); |
|
| 4222 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
|
| 4223 | + } |
|
| 4224 | + elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4225 | + {
|
|
| 4226 | + $discount=new DiscountAbsolute($this->db); |
|
| 4227 | + $discount->fetch($line->fk_remise_except); |
|
| 4228 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
|
| 4229 | + } |
|
| 4230 | + elseif ($line->desc == '(EXCESS PAID)') |
|
| 4231 | + {
|
|
| 4232 | + $discount=new DiscountAbsolute($this->db); |
|
| 4233 | + $discount->fetch($line->fk_remise_except); |
|
| 4234 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
|
| 4235 | + } |
|
| 4236 | + else |
|
| 4237 | + {
|
|
| 4238 | + $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 4239 | + } |
|
| 4240 | + } |
|
| 4241 | + else |
|
| 4242 | + {
|
|
| 4243 | + $this->tpl['description'] = ' '; |
|
| 4244 | + } |
|
| 4245 | + |
|
| 4246 | + // VAT Rate |
|
| 4247 | + $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
|
| 4248 | + $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
|
| 4249 | + if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 4250 | + |
|
| 4251 | + $this->tpl['price'] = price($line->subprice); |
|
| 4252 | + $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
|
| 4253 | + $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
|
| 4254 | + if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
|
|
| 4255 | + $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
|
| 4256 | + |
|
| 4257 | + // Is the line strike or not |
|
| 4258 | + $this->tpl['strike']=0; |
|
| 4259 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4260 | + |
|
| 4261 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4262 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 4263 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4264 | + foreach($dirtpls as $reldir) |
|
| 4265 | + {
|
|
| 4266 | + $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
| 4267 | + if (empty($conf->file->strict_mode)) {
|
|
| 4268 | + $res=@include $tpl; |
|
| 4269 | + } else {
|
|
| 4270 | + $res=include $tpl; // for debug |
|
| 4271 | + } |
|
| 4272 | + if ($res) break; |
|
| 4273 | + } |
|
| 4274 | + } |
|
| 4275 | + |
|
| 4276 | + |
|
| 4277 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4278 | + /** |
|
| 4279 | + * Add resources to the current object : add entry into llx_element_resources |
|
| 4280 | + * Need $this->element & $this->id |
|
| 4281 | + * |
|
| 4282 | + * @param int $resource_id Resource id |
|
| 4283 | + * @param string $resource_type 'resource' |
|
| 4284 | + * @param int $busy Busy or not |
|
| 4285 | + * @param int $mandatory Mandatory or not |
|
| 4286 | + * @return int <=0 if KO, >0 if OK |
|
| 4287 | + */ |
|
| 4288 | + function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4289 | + {
|
|
| 4290 | + // phpcs:enable |
|
| 4291 | + $this->db->begin(); |
|
| 4292 | + |
|
| 4293 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
|
| 4294 | + $sql.= "resource_id"; |
|
| 4295 | + $sql.= ", resource_type"; |
|
| 4296 | + $sql.= ", element_id"; |
|
| 4297 | + $sql.= ", element_type"; |
|
| 4298 | + $sql.= ", busy"; |
|
| 4299 | + $sql.= ", mandatory"; |
|
| 4300 | + $sql.= ") VALUES (";
|
|
| 4301 | + $sql.= $resource_id; |
|
| 4302 | + $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4303 | + $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4304 | + $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4305 | + $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4306 | + $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4307 | + $sql.= ")"; |
|
| 4308 | + |
|
| 4309 | + dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
| 4310 | + if ($this->db->query($sql)) |
|
| 4311 | + {
|
|
| 4312 | + $this->db->commit(); |
|
| 4313 | + return 1; |
|
| 4314 | + } |
|
| 4315 | + else |
|
| 4316 | + {
|
|
| 4317 | + $this->error=$this->db->lasterror(); |
|
| 4318 | + $this->db->rollback(); |
|
| 4319 | + return 0; |
|
| 4320 | + } |
|
| 4321 | + } |
|
| 4322 | + |
|
| 4323 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4324 | + /** |
|
| 4325 | + * Delete a link to resource line |
|
| 4326 | + * |
|
| 4327 | + * @param int $rowid Id of resource line to delete |
|
| 4328 | + * @param int $element element name (for trigger) TODO: use $this->element into commonobject class |
|
| 4329 | + * @param int $notrigger Disable all triggers |
|
| 4330 | + * @return int >0 if OK, <0 if KO |
|
| 4331 | + */ |
|
| 4332 | + function delete_resource($rowid, $element, $notrigger=0) |
|
| 4333 | + {
|
|
| 4334 | + // phpcs:enable |
|
| 4335 | + global $user; |
|
| 4336 | + |
|
| 4337 | + $this->db->begin(); |
|
| 4338 | + |
|
| 4339 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
| 4340 | + $sql.= " WHERE rowid=".$rowid; |
|
| 4341 | + |
|
| 4342 | + dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
| 4343 | + |
|
| 4344 | + $resql=$this->db->query($sql); |
|
| 4345 | + if (! $resql) |
|
| 4346 | + {
|
|
| 4347 | + $this->error=$this->db->lasterror(); |
|
| 4348 | + $this->db->rollback(); |
|
| 4349 | + return -1; |
|
| 4350 | + } |
|
| 4351 | + else |
|
| 4352 | + {
|
|
| 4353 | + if (! $notrigger) |
|
| 4354 | + {
|
|
| 4355 | + $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4356 | + if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 4357 | + } |
|
| 4358 | + $this->db->commit(); |
|
| 4359 | + return 1; |
|
| 4360 | + } |
|
| 4361 | + } |
|
| 4362 | + |
|
| 4363 | + |
|
| 4364 | + /** |
|
| 4365 | + * Overwrite magic function to solve problem of cloning object that are kept as references |
|
| 4366 | + * |
|
| 4367 | + * @return void |
|
| 4368 | + */ |
|
| 4369 | + function __clone() |
|
| 4370 | + {
|
|
| 4371 | + // Force a copy of this->lines, otherwise it will point to same object. |
|
| 4372 | + if (isset($this->lines) && is_array($this->lines)) |
|
| 4373 | + {
|
|
| 4374 | + $nboflines=count($this->lines); |
|
| 4375 | + for($i=0; $i < $nboflines; $i++) |
|
| 4376 | + {
|
|
| 4377 | + $this->lines[$i] = clone $this->lines[$i]; |
|
| 4378 | + } |
|
| 4379 | + } |
|
| 4380 | + } |
|
| 4381 | + |
|
| 4382 | + /** |
|
| 4383 | + * Common function for all objects extending CommonObject for generating documents |
|
| 4384 | + * |
|
| 4385 | + * @param string $modelspath Relative folder where generators are placed |
|
| 4386 | + * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
|
|
| 4387 | + * @param Translate $outputlangs Output language to use |
|
| 4388 | + * @param int $hidedetails 1 to hide details. 0 by default |
|
| 4389 | + * @param int $hidedesc 1 to hide product description. 0 by default |
|
| 4390 | + * @param int $hideref 1 to hide product reference. 0 by default |
|
| 4391 | + * @param null|array $moreparams Array to provide more information |
|
| 4392 | + * @return int >0 if OK, <0 if KO |
|
| 4393 | + * @see addFileIntoDatabaseIndex |
|
| 4394 | + */ |
|
| 4395 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4396 | + {
|
|
| 4397 | + global $conf, $langs, $user; |
|
| 4398 | + |
|
| 4399 | + $srctemplatepath=''; |
|
| 4400 | + |
|
| 4401 | + // Increase limit for PDF build |
|
| 4402 | + $err=error_reporting(); |
|
| 4403 | + error_reporting(0); |
|
| 4404 | + @set_time_limit(120); |
|
| 4405 | + error_reporting($err); |
|
| 4406 | + |
|
| 4407 | + // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
|
| 4408 | + $tmp=explode(':',$modele,2);
|
|
| 4409 | + if (! empty($tmp[1])) |
|
| 4410 | + {
|
|
| 4411 | + $modele=$tmp[0]; |
|
| 4412 | + $srctemplatepath=$tmp[1]; |
|
| 4413 | + } |
|
| 4414 | + |
|
| 4415 | + // Search template files |
|
| 4416 | + $file=''; $classname=''; $filefound=0; |
|
| 4417 | + $dirmodels=array('/');
|
|
| 4418 | + if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4419 | + foreach($dirmodels as $reldir) |
|
| 4420 | + {
|
|
| 4421 | + foreach(array('doc','pdf') as $prefix)
|
|
| 4422 | + {
|
|
| 4423 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4424 | + else $file = $prefix."_".$modele.".modules.php"; |
|
| 4425 | + |
|
| 4426 | + // On verifie l'emplacement du modele |
|
| 4427 | + $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4428 | + if (file_exists($file)) |
|
| 4429 | + {
|
|
| 4430 | + $filefound=1; |
|
| 4431 | + $classname=$prefix.'_'.$modele; |
|
| 4432 | + break; |
|
| 4433 | + } |
|
| 4434 | + } |
|
| 4435 | + if ($filefound) break; |
|
| 4436 | + } |
|
| 4437 | + |
|
| 4438 | + // If generator was found |
|
| 4439 | + if ($filefound) |
|
| 4440 | + {
|
|
| 4441 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4442 | + |
|
| 4443 | + require_once $file; |
|
| 4444 | + |
|
| 4445 | + $obj = new $classname($this->db); |
|
| 4446 | + |
|
| 4447 | + // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
|
| 4448 | + if ($obj->type == 'odt' && empty($srctemplatepath)) |
|
| 4449 | + {
|
|
| 4450 | + $varfortemplatedir=$obj->scandir; |
|
| 4451 | + if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
| 4452 | + {
|
|
| 4453 | + $dirtoscan=$conf->global->$varfortemplatedir; |
|
| 4454 | + |
|
| 4455 | + $listoffiles=array(); |
|
| 4456 | + |
|
| 4457 | + // Now we add first model found in directories scanned |
|
| 4458 | + $listofdir=explode(',',$dirtoscan);
|
|
| 4459 | + foreach($listofdir as $key => $tmpdir) |
|
| 4460 | + {
|
|
| 4461 | + $tmpdir=trim($tmpdir); |
|
| 4462 | + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
|
| 4463 | + if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
|
| 4464 | + if (is_dir($tmpdir)) |
|
| 4465 | + {
|
|
| 4466 | + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4467 | + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4468 | + } |
|
| 4469 | + } |
|
| 4470 | + |
|
| 4471 | + if (count($listoffiles)) |
|
| 4472 | + {
|
|
| 4473 | + foreach($listoffiles as $record) |
|
| 4474 | + {
|
|
| 4475 | + $srctemplatepath=$record['fullname']; |
|
| 4476 | + break; |
|
| 4477 | + } |
|
| 4478 | + } |
|
| 4479 | + } |
|
| 4480 | + |
|
| 4481 | + if (empty($srctemplatepath)) |
|
| 4482 | + {
|
|
| 4483 | + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4484 | + return -1; |
|
| 4485 | + } |
|
| 4486 | + } |
|
| 4487 | + |
|
| 4488 | + if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4489 | + {
|
|
| 4490 | + if (! dol_is_file($srctemplatepath)) |
|
| 4491 | + {
|
|
| 4492 | + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4493 | + return -1; |
|
| 4494 | + } |
|
| 4495 | + } |
|
| 4496 | + |
|
| 4497 | + // We save charset_output to restore it because write_file can change it if needed for |
|
| 4498 | + // output format that does not support UTF8. |
|
| 4499 | + $sav_charset_output=$outputlangs->charset_output; |
|
| 4500 | + |
|
| 4501 | + if (in_array(get_class($this), array('Adherent')))
|
|
| 4502 | + {
|
|
| 4503 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4504 | + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
|
| 4505 | + } |
|
| 4506 | + else |
|
| 4507 | + {
|
|
| 4508 | + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
| 4509 | + } |
|
| 4510 | + // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. |
|
| 4511 | + |
|
| 4512 | + if ($resultwritefile > 0) |
|
| 4513 | + {
|
|
| 4514 | + $outputlangs->charset_output=$sav_charset_output; |
|
| 4515 | + |
|
| 4516 | + // We delete old preview |
|
| 4517 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 4518 | + dol_delete_preview($this); |
|
| 4519 | + |
|
| 4520 | + // Index file in database |
|
| 4521 | + if (! empty($obj->result['fullpath'])) |
|
| 4522 | + {
|
|
| 4523 | + $destfull = $obj->result['fullpath']; |
|
| 4524 | + $upload_dir = dirname($destfull); |
|
| 4525 | + $destfile = basename($destfull); |
|
| 4526 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
|
| 4527 | + |
|
| 4528 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4529 | + {
|
|
| 4530 | + $filename = basename($destfile); |
|
| 4531 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
|
| 4532 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
|
| 4533 | + |
|
| 4534 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 4535 | + $ecmfile=new EcmFiles($this->db); |
|
| 4536 | + $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4537 | + |
|
| 4538 | + // Set the public "share" key |
|
| 4539 | + $setsharekey = false; |
|
| 4540 | + if ($this->element == 'propal') |
|
| 4541 | + {
|
|
| 4542 | + $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4543 | + if ($useonlinesignature) $setsharekey=true; |
|
| 4544 | + if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4545 | + } |
|
| 4546 | + if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4547 | + if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4548 | + if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4549 | + |
|
| 4550 | + if ($setsharekey) |
|
| 4551 | + {
|
|
| 4552 | + if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4553 | + {
|
|
| 4554 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4555 | + $ecmfile->share = getRandomPassword(true); |
|
| 4556 | + } |
|
| 4557 | + } |
|
| 4558 | + |
|
| 4559 | + if ($result > 0) |
|
| 4560 | + {
|
|
| 4561 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4562 | + $ecmfile->fullpath_orig = ''; |
|
| 4563 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4564 | + $ecmfile->description = ''; // indexed content |
|
| 4565 | + $ecmfile->keyword = ''; // keyword content |
|
| 4566 | + $result = $ecmfile->update($user); |
|
| 4567 | + if ($result < 0) |
|
| 4568 | + {
|
|
| 4569 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4570 | + } |
|
| 4571 | + } |
|
| 4572 | + else |
|
| 4573 | + {
|
|
| 4574 | + $ecmfile->entity = $conf->entity; |
|
| 4575 | + $ecmfile->filepath = $rel_dir; |
|
| 4576 | + $ecmfile->filename = $filename; |
|
| 4577 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4578 | + $ecmfile->fullpath_orig = ''; |
|
| 4579 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4580 | + $ecmfile->description = ''; // indexed content |
|
| 4581 | + $ecmfile->keyword = ''; // keyword content |
|
| 4582 | + $ecmfile->src_object_type = $this->table_element; |
|
| 4583 | + $ecmfile->src_object_id = $this->id; |
|
| 4584 | + |
|
| 4585 | + $result = $ecmfile->create($user); |
|
| 4586 | + if ($result < 0) |
|
| 4587 | + {
|
|
| 4588 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4589 | + } |
|
| 4590 | + } |
|
| 4591 | + |
|
| 4592 | + /*$this->result['fullname']=$destfull; |
|
| 4593 | + $this->result['filepath']=$ecmfile->filepath; |
|
| 4594 | + $this->result['filename']=$ecmfile->filename;*/ |
|
| 4595 | + //var_dump($obj->update_main_doc_field);exit; |
|
| 4596 | + |
|
| 4597 | + // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
|
| 4598 | + $update_main_doc_field=0; |
|
| 4599 | + if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4600 | + if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4601 | + {
|
|
| 4602 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
| 4603 | + $sql.= ' WHERE rowid = '.$this->id; |
|
| 4604 | + $resql = $this->db->query($sql); |
|
| 4605 | + if (! $resql) dol_print_error($this->db); |
|
| 4606 | + } |
|
| 4607 | + } |
|
| 4608 | + } |
|
| 4609 | + else |
|
| 4610 | + {
|
|
| 4611 | + dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
|
|
| 4612 | + } |
|
| 4613 | + |
|
| 4614 | + // Success in building document. We build meta file. |
|
| 4615 | + dol_meta_create($this); |
|
| 4616 | + |
|
| 4617 | + return 1; |
|
| 4618 | + } |
|
| 4619 | + else |
|
| 4620 | + {
|
|
| 4621 | + $outputlangs->charset_output=$sav_charset_output; |
|
| 4622 | + dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
| 4623 | + return -1; |
|
| 4624 | + } |
|
| 4625 | + } |
|
| 4626 | + else |
|
| 4627 | + {
|
|
| 4628 | + $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
|
| 4629 | + dol_print_error('',$this->error);
|
|
| 4630 | + return -1; |
|
| 4631 | + } |
|
| 4632 | + } |
|
| 4633 | + |
|
| 4634 | + /** |
|
| 4635 | + * Build thumb |
|
| 4636 | + * @TODO Move this into files.lib.php |
|
| 4637 | + * |
|
| 4638 | + * @param string $file Path file in UTF8 to original file to create thumbs from. |
|
| 4639 | + * @return void |
|
| 4640 | + */ |
|
| 4641 | + function addThumbs($file) |
|
| 4642 | + {
|
|
| 4643 | + global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
|
| 4644 | + |
|
| 4645 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4646 | + |
|
| 4647 | + $file_osencoded=dol_osencode($file); |
|
| 4648 | + if (file_exists($file_osencoded)) |
|
| 4649 | + {
|
|
| 4650 | + // Create small thumbs for company (Ratio is near 16/9) |
|
| 4651 | + // Used on logon for example |
|
| 4652 | + vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); |
|
| 4653 | + |
|
| 4654 | + // Create mini thumbs for company (Ratio is near 16/9) |
|
| 4655 | + // Used on menu or for setup page for example |
|
| 4656 | + vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); |
|
| 4657 | + } |
|
| 4658 | + } |
|
| 4659 | + |
|
| 4660 | + |
|
| 4661 | + /* Functions common to commonobject and commonobjectline */ |
|
| 4662 | + |
|
| 4663 | + /* For default values */ |
|
| 4664 | + |
|
| 4665 | + /** |
|
| 4666 | + * Return the default value to use for a field when showing the create form of object. |
|
| 4667 | + * Return values in this order: |
|
| 4668 | + * 1) If parameter is available into POST, we return it first. |
|
| 4669 | + * 2) If not but an alternate value was provided as parameter of function, we return it. |
|
| 4670 | + * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). |
|
| 4671 | + * 4) Return value found into database (TODO No yet implemented) |
|
| 4672 | + * |
|
| 4673 | + * @param string $fieldname Name of field |
|
| 4674 | + * @param string $alternatevalue Alternate value to use |
|
| 4675 | + * @return string|string[] Default value (can be an array if the GETPOST return an array) |
|
| 4676 | + **/ |
|
| 4677 | + function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4678 | + {
|
|
| 4679 | + global $conf, $_POST; |
|
| 4680 | + |
|
| 4681 | + // If param here has been posted, we use this value first. |
|
| 4682 | + if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 4683 | + |
|
| 4684 | + if (isset($alternatevalue)) return $alternatevalue; |
|
| 4685 | + |
|
| 4686 | + $newelement=$this->element; |
|
| 4687 | + if ($newelement == 'facture') $newelement='invoice'; |
|
| 4688 | + if ($newelement == 'commande') $newelement='order'; |
|
| 4689 | + if (empty($newelement)) |
|
| 4690 | + {
|
|
| 4691 | + dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
|
| 4692 | + return ''; |
|
| 4693 | + } |
|
| 4694 | + |
|
| 4695 | + $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4696 | + //var_dump($keyforfieldname); |
|
| 4697 | + if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
|
| 4698 | + |
|
| 4699 | + // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
|
| 4700 | + } |
|
| 4701 | + |
|
| 4702 | + |
|
| 4703 | + /* For triggers */ |
|
| 4704 | + |
|
| 4705 | + |
|
| 4706 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4707 | + /** |
|
| 4708 | + * Call trigger based on this instance. |
|
| 4709 | + * Some context information may also be provided into array property this->context. |
|
| 4710 | + * NB: Error from trigger are stacked in interface->errors |
|
| 4711 | + * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. |
|
| 4712 | + * |
|
| 4713 | + * @param string $trigger_name trigger's name to execute |
|
| 4714 | + * @param User $user Object user |
|
| 4715 | + * @return int Result of run_triggers |
|
| 4716 | + */ |
|
| 4717 | + function call_trigger($trigger_name, $user) |
|
| 4718 | + {
|
|
| 4719 | + // phpcs:enable |
|
| 4720 | + global $langs,$conf; |
|
| 4721 | + |
|
| 4722 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4723 | + $interface=new Interfaces($this->db); |
|
| 4724 | + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 4725 | + |
|
| 4726 | + if ($result < 0) |
|
| 4727 | + {
|
|
| 4728 | + if (!empty($this->errors)) |
|
| 4729 | + {
|
|
| 4730 | + $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. |
|
| 4731 | + } |
|
| 4732 | + else |
|
| 4733 | + {
|
|
| 4734 | + $this->errors=$interface->errors; |
|
| 4735 | + } |
|
| 4736 | + } |
|
| 4737 | + return $result; |
|
| 4738 | + } |
|
| 4739 | + |
|
| 4740 | + |
|
| 4741 | + /* Functions for extrafields */ |
|
| 4742 | + |
|
| 4743 | + |
|
| 4744 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4745 | + /** |
|
| 4746 | + * Function to get extra fields of an object into $this->array_options |
|
| 4747 | + * This method is in most cases called by method fetch of objects but you can call it separately. |
|
| 4748 | + * |
|
| 4749 | + * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. |
|
| 4750 | + * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
|
| 4751 | + * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
|
| 4752 | + */ |
|
| 4753 | + function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4754 | + {
|
|
| 4755 | + // phpcs:enable |
|
| 4756 | + if (empty($rowid)) $rowid=$this->id; |
|
| 4757 | + |
|
| 4758 | + // To avoid SQL errors. Probably not the better solution though |
|
| 4759 | + if (!$this->table_element) {
|
|
| 4760 | + return 0; |
|
| 4761 | + } |
|
| 4762 | + |
|
| 4763 | + $this->array_options=array(); |
|
| 4764 | + |
|
| 4765 | + if (! is_array($optionsArray)) |
|
| 4766 | + {
|
|
| 4767 | + // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
|
| 4768 | + // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
|
| 4769 | + // global $extrafields; |
|
| 4770 | + //if (! is_object($extrafields)) |
|
| 4771 | + //{
|
|
| 4772 | + // require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4773 | + $extrafields = new ExtraFields(); |
|
| 4774 | + //} |
|
| 4775 | + |
|
| 4776 | + // Load array of extrafields for elementype = $this->table_element |
|
| 4777 | + if (empty($extrafields->attributes[$this->table_element]['loaded'])) |
|
| 4778 | + {
|
|
| 4779 | + $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4780 | + } |
|
| 4781 | + $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
| 4782 | + } |
|
| 4783 | + else |
|
| 4784 | + {
|
|
| 4785 | + global $extrafields; |
|
| 4786 | + dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
|
|
| 4787 | + } |
|
| 4788 | + |
|
| 4789 | + $table_element = $this->table_element; |
|
| 4790 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4791 | + |
|
| 4792 | + // Request to get complementary values |
|
| 4793 | + if (is_array($optionsArray) && count($optionsArray) > 0) |
|
| 4794 | + {
|
|
| 4795 | + $sql = "SELECT rowid"; |
|
| 4796 | + foreach ($optionsArray as $name => $label) |
|
| 4797 | + {
|
|
| 4798 | + if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
|
| 4799 | + {
|
|
| 4800 | + $sql.= ", ".$name; |
|
| 4801 | + } |
|
| 4802 | + } |
|
| 4803 | + $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4804 | + $sql.= " WHERE fk_object = ".$rowid; |
|
| 4805 | + |
|
| 4806 | + //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
|
| 4807 | + $resql=$this->db->query($sql); |
|
| 4808 | + if ($resql) |
|
| 4809 | + {
|
|
| 4810 | + $this->array_options = array(); |
|
| 4811 | + $numrows=$this->db->num_rows($resql); |
|
| 4812 | + if ($numrows) |
|
| 4813 | + {
|
|
| 4814 | + $tab = $this->db->fetch_array($resql); |
|
| 4815 | + |
|
| 4816 | + foreach ($tab as $key => $value) |
|
| 4817 | + {
|
|
| 4818 | + // 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) |
|
| 4819 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4820 | + {
|
|
| 4821 | + // we can add this attribute to object |
|
| 4822 | + if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime')))
|
|
| 4823 | + {
|
|
| 4824 | + //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
|
| 4825 | + $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4826 | + } |
|
| 4827 | + else |
|
| 4828 | + {
|
|
| 4829 | + $this->array_options["options_".$key]=$value; |
|
| 4830 | + } |
|
| 4831 | + |
|
| 4832 | + //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]);
|
|
| 4833 | + } |
|
| 4834 | + } |
|
| 4835 | + } |
|
| 4836 | + |
|
| 4837 | + $this->db->free($resql); |
|
| 4838 | + |
|
| 4839 | + if ($numrows) return $numrows; |
|
| 4840 | + else return 0; |
|
| 4841 | + } |
|
| 4842 | + else |
|
| 4843 | + {
|
|
| 4844 | + dol_print_error($this->db); |
|
| 4845 | + return -1; |
|
| 4846 | + } |
|
| 4847 | + } |
|
| 4848 | + return 0; |
|
| 4849 | + } |
|
| 4850 | + |
|
| 4851 | + /** |
|
| 4852 | + * Delete all extra fields values for the current object. |
|
| 4853 | + * |
|
| 4854 | + * @return int <0 if KO, >0 if OK |
|
| 4855 | + */ |
|
| 4856 | + function deleteExtraFields() |
|
| 4857 | + {
|
|
| 4858 | + $this->db->begin(); |
|
| 4859 | + |
|
| 4860 | + $table_element = $this->table_element; |
|
| 4861 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4862 | + |
|
| 4863 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 4864 | + dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
| 4865 | + $resql=$this->db->query($sql_del); |
|
| 4866 | + if (! $resql) |
|
| 4867 | + {
|
|
| 4868 | + $this->error=$this->db->lasterror(); |
|
| 4869 | + $this->db->rollback(); |
|
| 4870 | + return -1; |
|
| 4871 | + } |
|
| 4872 | + else |
|
| 4873 | + {
|
|
| 4874 | + $this->db->commit(); |
|
| 4875 | + return 1; |
|
| 4876 | + } |
|
| 4877 | + } |
|
| 4878 | + |
|
| 4879 | + /** |
|
| 4880 | + * Add/Update all extra fields values for the current object. |
|
| 4881 | + * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 4882 | + * This function delete record with all extrafields and insert them again from the array $this->array_options. |
|
| 4883 | + * |
|
| 4884 | + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 4885 | + * @param User $userused Object user |
|
| 4886 | + * @return int -1=error, O=did nothing, 1=OK |
|
| 4887 | + * @see updateExtraField, setValueFrom |
|
| 4888 | + */ |
|
| 4889 | + function insertExtraFields($trigger='', $userused=null) |
|
| 4890 | + {
|
|
| 4891 | + global $conf,$langs,$user; |
|
| 4892 | + |
|
| 4893 | + if (empty($userused)) $userused=$user; |
|
| 4894 | + |
|
| 4895 | + $error=0; |
|
| 4896 | + |
|
| 4897 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4898 | + |
|
| 4899 | + if (! empty($this->array_options)) |
|
| 4900 | + {
|
|
| 4901 | + // Check parameters |
|
| 4902 | + $langs->load('admin');
|
|
| 4903 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4904 | + $extrafields = new ExtraFields($this->db); |
|
| 4905 | + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4906 | + |
|
| 4907 | + //Eliminate copied source object extra_fields that do not exist in target object |
|
| 4908 | + $new_array_options=array(); |
|
| 4909 | + foreach ($this->array_options as $key => $value) {
|
|
| 4910 | + if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4911 | + $new_array_options[$key] = $value; |
|
| 4912 | + elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 4913 | + $new_array_options['options_'.$key] = $value; |
|
| 4914 | + } |
|
| 4915 | + |
|
| 4916 | + foreach($new_array_options as $key => $value) |
|
| 4917 | + {
|
|
| 4918 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4919 | + $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
|
| 4920 | + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
|
| 4921 | + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
|
| 4922 | + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; |
|
| 4923 | + |
|
| 4924 | + if ($attributeRequired) |
|
| 4925 | + {
|
|
| 4926 | + $mandatorypb=false; |
|
| 4927 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4928 | + if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4929 | + if ($mandatorypb) |
|
| 4930 | + {
|
|
| 4931 | + dol_syslog($this->error); |
|
| 4932 | + $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel);
|
|
| 4933 | + return -1; |
|
| 4934 | + } |
|
| 4935 | + } |
|
| 4936 | + |
|
| 4937 | + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 4938 | + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 4939 | + |
|
| 4940 | + switch ($attributeType) |
|
| 4941 | + {
|
|
| 4942 | + case 'int': |
|
| 4943 | + if (!is_numeric($value) && $value!='') |
|
| 4944 | + {
|
|
| 4945 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4946 | + return -1; |
|
| 4947 | + } |
|
| 4948 | + elseif ($value=='') |
|
| 4949 | + {
|
|
| 4950 | + $new_array_options[$key] = null; |
|
| 4951 | + } |
|
| 4952 | + break; |
|
| 4953 | + case 'double': |
|
| 4954 | + $value = price2num($value); |
|
| 4955 | + if (!is_numeric($value) && $value!='') |
|
| 4956 | + {
|
|
| 4957 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 4958 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4959 | + return -1; |
|
| 4960 | + } |
|
| 4961 | + elseif ($value=='') |
|
| 4962 | + {
|
|
| 4963 | + $new_array_options[$key] = null; |
|
| 4964 | + } |
|
| 4965 | + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 4966 | + $new_array_options[$key] = $value; |
|
| 4967 | + break; |
|
| 4968 | + /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 4969 | + if ($value=='-1') |
|
| 4970 | + {
|
|
| 4971 | + $this->array_options[$key] = null; |
|
| 4972 | + } |
|
| 4973 | + break;*/ |
|
| 4974 | + case 'password': |
|
| 4975 | + $algo=''; |
|
| 4976 | + if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
|
| 4977 | + {
|
|
| 4978 | + // If there is an encryption choice, we use it to crypt data before insert |
|
| 4979 | + $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
|
| 4980 | + $algo=reset($tmparrays); |
|
| 4981 | + if ($algo != '') |
|
| 4982 | + {
|
|
| 4983 | + //global $action; // $action may be 'create', 'update', 'update_extras'... |
|
| 4984 | + //var_dump($action); |
|
| 4985 | + //var_dump($this->oldcopy);exit; |
|
| 4986 | + if (is_object($this->oldcopy)) // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 4987 | + {
|
|
| 4988 | + //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
|
| 4989 | + 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. |
|
| 4990 | + {
|
|
| 4991 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4992 | + } |
|
| 4993 | + else |
|
| 4994 | + {
|
|
| 4995 | + // var_dump($algo); |
|
| 4996 | + $newvalue = dol_hash($this->array_options[$key], $algo); |
|
| 4997 | + $new_array_options[$key] = $newvalue; |
|
| 4998 | + } |
|
| 4999 | + } |
|
| 5000 | + else |
|
| 5001 | + {
|
|
| 5002 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5003 | + } |
|
| 5004 | + } |
|
| 5005 | + } |
|
| 5006 | + else // Common usage |
|
| 5007 | + {
|
|
| 5008 | + $new_array_options[$key] = $this->array_options[$key]; |
|
| 5009 | + } |
|
| 5010 | + break; |
|
| 5011 | + case 'price': |
|
| 5012 | + $new_array_options[$key] = price2num($this->array_options[$key]); |
|
| 5013 | + break; |
|
| 5014 | + case 'date': |
|
| 5015 | + $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5016 | + break; |
|
| 5017 | + case 'datetime': |
|
| 5018 | + // If data is a string instead of a timestamp, we convert it |
|
| 5019 | + if (! is_int($this->array_options[$key])) {
|
|
| 5020 | + $this->array_options[$key] = strtotime($this->array_options[$key]); |
|
| 5021 | + } |
|
| 5022 | + $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5023 | + break; |
|
| 5024 | + case 'link': |
|
| 5025 | + $param_list=array_keys($attributeParam['options']); |
|
| 5026 | + // 0 : ObjectName |
|
| 5027 | + // 1 : classPath |
|
| 5028 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5029 | + dol_include_once($InfoFieldList[1]); |
|
| 5030 | + if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
|
| 5031 | + {
|
|
| 5032 | + if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5033 | + {
|
|
| 5034 | + $new_array_options[$key]=''; |
|
| 5035 | + } |
|
| 5036 | + elseif ($value) |
|
| 5037 | + {
|
|
| 5038 | + $object = new $InfoFieldList[0]($this->db); |
|
| 5039 | + if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5040 | + else $res=$object->fetch('',$value);
|
|
| 5041 | + |
|
| 5042 | + if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5043 | + else |
|
| 5044 | + {
|
|
| 5045 | + $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5046 | + $this->db->rollback(); |
|
| 5047 | + return -1; |
|
| 5048 | + } |
|
| 5049 | + } |
|
| 5050 | + } |
|
| 5051 | + else |
|
| 5052 | + {
|
|
| 5053 | + dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 5054 | + } |
|
| 5055 | + break; |
|
| 5056 | + } |
|
| 5057 | + } |
|
| 5058 | + |
|
| 5059 | + $this->db->begin(); |
|
| 5060 | + |
|
| 5061 | + $table_element = $this->table_element; |
|
| 5062 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5063 | + |
|
| 5064 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 5065 | + dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
| 5066 | + $this->db->query($sql_del); |
|
| 5067 | + |
|
| 5068 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
| 5069 | + foreach($new_array_options as $key => $value) |
|
| 5070 | + {
|
|
| 5071 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5072 | + // Add field of attribut |
|
| 5073 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5074 | + $sql.=",".$attributeKey; |
|
| 5075 | + } |
|
| 5076 | + $sql .= ") VALUES (".$this->id;
|
|
| 5077 | + |
|
| 5078 | + foreach($new_array_options as $key => $value) |
|
| 5079 | + {
|
|
| 5080 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5081 | + // Add field of attribute |
|
| 5082 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5083 | + {
|
|
| 5084 | + if ($new_array_options[$key] != '') |
|
| 5085 | + {
|
|
| 5086 | + $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5087 | + } |
|
| 5088 | + else |
|
| 5089 | + {
|
|
| 5090 | + $sql.=",null"; |
|
| 5091 | + } |
|
| 5092 | + } |
|
| 5093 | + } |
|
| 5094 | + $sql.=")"; |
|
| 5095 | + |
|
| 5096 | + dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
| 5097 | + $resql = $this->db->query($sql); |
|
| 5098 | + if (! $resql) |
|
| 5099 | + {
|
|
| 5100 | + $this->error=$this->db->lasterror(); |
|
| 5101 | + $error++; |
|
| 5102 | + } |
|
| 5103 | + |
|
| 5104 | + if (! $error && $trigger) |
|
| 5105 | + {
|
|
| 5106 | + // Call trigger |
|
| 5107 | + $this->context=array('extrafieldaddupdate'=>1);
|
|
| 5108 | + $result=$this->call_trigger($trigger, $userused); |
|
| 5109 | + if ($result < 0) $error++; |
|
| 5110 | + // End call trigger |
|
| 5111 | + } |
|
| 5112 | + |
|
| 5113 | + if ($error) |
|
| 5114 | + {
|
|
| 5115 | + $this->db->rollback(); |
|
| 5116 | + return -1; |
|
| 5117 | + } |
|
| 5118 | + else |
|
| 5119 | + {
|
|
| 5120 | + $this->db->commit(); |
|
| 5121 | + return 1; |
|
| 5122 | + } |
|
| 5123 | + } |
|
| 5124 | + else return 0; |
|
| 5125 | + } |
|
| 5126 | + |
|
| 5127 | + /** |
|
| 5128 | + * Update an extra field value for the current object. |
|
| 5129 | + * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 5130 | + * |
|
| 5131 | + * @param string $key Key of the extrafield (without starting 'options_') |
|
| 5132 | + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 5133 | + * @param User $userused Object user |
|
| 5134 | + * @return int -1=error, O=did nothing, 1=OK |
|
| 5135 | + * @see setValueFrom, insertExtraFields |
|
| 5136 | + */ |
|
| 5137 | + function updateExtraField($key, $trigger=null, $userused=null) |
|
| 5138 | + {
|
|
| 5139 | + global $conf,$langs,$user; |
|
| 5140 | + |
|
| 5141 | + if (empty($userused)) $userused=$user; |
|
| 5142 | + |
|
| 5143 | + $error=0; |
|
| 5144 | + |
|
| 5145 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5146 | + |
|
| 5147 | + if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5148 | + {
|
|
| 5149 | + // Check parameters |
|
| 5150 | + $langs->load('admin');
|
|
| 5151 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 5152 | + $extrafields = new ExtraFields($this->db); |
|
| 5153 | + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5154 | + |
|
| 5155 | + $value=$this->array_options["options_".$key]; |
|
| 5156 | + |
|
| 5157 | + $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
|
| 5158 | + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
|
| 5159 | + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; |
|
| 5160 | + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; |
|
| 5161 | + |
|
| 5162 | + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 5163 | + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 5164 | + |
|
| 5165 | + switch ($attributeType) |
|
| 5166 | + {
|
|
| 5167 | + case 'int': |
|
| 5168 | + if (!is_numeric($value) && $value!='') |
|
| 5169 | + {
|
|
| 5170 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
|
| 5171 | + return -1; |
|
| 5172 | + } |
|
| 5173 | + elseif ($value=='') |
|
| 5174 | + {
|
|
| 5175 | + $this->array_options["options_".$key] = null; |
|
| 5176 | + } |
|
| 5177 | + break; |
|
| 5178 | + case 'double': |
|
| 5179 | + $value = price2num($value); |
|
| 5180 | + if (!is_numeric($value) && $value!='') |
|
| 5181 | + {
|
|
| 5182 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 5183 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5184 | + return -1; |
|
| 5185 | + } |
|
| 5186 | + elseif ($value=='') |
|
| 5187 | + {
|
|
| 5188 | + $this->array_options["options_".$key] = null; |
|
| 5189 | + } |
|
| 5190 | + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 5191 | + $this->array_options["options_".$key] = $value; |
|
| 5192 | + break; |
|
| 5193 | + /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 5194 | + if ($value=='-1') |
|
| 5195 | + {
|
|
| 5196 | + $this->array_options[$key] = null; |
|
| 5197 | + } |
|
| 5198 | + break;*/ |
|
| 5199 | + case 'price': |
|
| 5200 | + $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
| 5201 | + break; |
|
| 5202 | + case 'date': |
|
| 5203 | + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5204 | + break; |
|
| 5205 | + case 'datetime': |
|
| 5206 | + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5207 | + break; |
|
| 5208 | + case 'link': |
|
| 5209 | + $param_list=array_keys($attributeParam['options']); |
|
| 5210 | + // 0 : ObjectName |
|
| 5211 | + // 1 : classPath |
|
| 5212 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5213 | + dol_include_once($InfoFieldList[1]); |
|
| 5214 | + if ($value) |
|
| 5215 | + {
|
|
| 5216 | + $object = new $InfoFieldList[0]($this->db); |
|
| 5217 | + $object->fetch(0,$value); |
|
| 5218 | + $this->array_options["options_".$key]=$object->id; |
|
| 5219 | + } |
|
| 5220 | + break; |
|
| 5221 | + } |
|
| 5222 | + |
|
| 5223 | + $this->db->begin(); |
|
| 5224 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
| 5225 | + $sql .= " WHERE fk_object = ".$this->id; |
|
| 5226 | + $resql = $this->db->query($sql); |
|
| 5227 | + if (! $resql) |
|
| 5228 | + {
|
|
| 5229 | + $error++; |
|
| 5230 | + $this->error=$this->db->lasterror(); |
|
| 5231 | + } |
|
| 5232 | + |
|
| 5233 | + if (! $error && $trigger) |
|
| 5234 | + {
|
|
| 5235 | + // Call trigger |
|
| 5236 | + $this->context=array('extrafieldupdate'=>1);
|
|
| 5237 | + $result=$this->call_trigger($trigger, $userused); |
|
| 5238 | + if ($result < 0) $error++; |
|
| 5239 | + // End call trigger |
|
| 5240 | + } |
|
| 5241 | + |
|
| 5242 | + if ($error) |
|
| 5243 | + {
|
|
| 5244 | + dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
| 5245 | + $this->db->rollback(); |
|
| 5246 | + return -1; |
|
| 5247 | + } |
|
| 5248 | + else |
|
| 5249 | + {
|
|
| 5250 | + $this->db->commit(); |
|
| 5251 | + return 1; |
|
| 5252 | + } |
|
| 5253 | + } |
|
| 5254 | + else return 0; |
|
| 5255 | + } |
|
| 5256 | + |
|
| 5257 | + |
|
| 5258 | + /** |
|
| 5259 | + * Return HTML string to put an input field into a page |
|
| 5260 | + * Code very similar with showInputField of extra fields |
|
| 5261 | + * |
|
| 5262 | + * @param array $val Array of properties for field to show |
|
| 5263 | + * @param string $key Key of attribute |
|
| 5264 | + * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
| 5265 | + * @param string $moreparam To add more parameters on html input tag |
|
| 5266 | + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5267 | + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5268 | + * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
|
| 5269 | + * @return string |
|
| 5270 | + */ |
|
| 5271 | + function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
| 5272 | + {
|
|
| 5273 | + global $conf,$langs,$form; |
|
| 5274 | + |
|
| 5275 | + if (! is_object($form)) |
|
| 5276 | + {
|
|
| 5277 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5278 | + $form=new Form($this->db); |
|
| 5279 | + } |
|
| 5280 | + |
|
| 5281 | + $val=$this->fields[$key]; |
|
| 5282 | + |
|
| 5283 | + $out=''; |
|
| 5284 | + $type=''; |
|
| 5285 | + $param = array(); |
|
| 5286 | + $param['options']=array(); |
|
| 5287 | + $size =$this->fields[$key]['size']; |
|
| 5288 | + // Because we work on extrafields |
|
| 5289 | + if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){
|
|
| 5290 | + $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5291 | + $type ='link'; |
|
| 5292 | + } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5293 | + $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5294 | + $type ='link'; |
|
| 5295 | + } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5296 | + $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5297 | + $type ='sellist'; |
|
| 5298 | + } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) {
|
|
| 5299 | + $param['options']=array(); |
|
| 5300 | + $type ='varchar'; |
|
| 5301 | + $size=$reg[1]; |
|
| 5302 | + } elseif(preg_match('/varchar/', $val['type'])) {
|
|
| 5303 | + $param['options']=array(); |
|
| 5304 | + $type ='varchar'; |
|
| 5305 | + } elseif(is_array($this->fields[$key]['arrayofkeyval'])) {
|
|
| 5306 | + $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
| 5307 | + $type ='select'; |
|
| 5308 | + } else {
|
|
| 5309 | + $param['options']=array(); |
|
| 5310 | + $type =$this->fields[$key]['type']; |
|
| 5311 | + } |
|
| 5693 | 5312 | |
| 5694 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5695 | - if (is_array($fields_label)) {
|
|
| 5696 | - $keyList .= ', '; |
|
| 5697 | - $keyList .= implode(', ', $fields_label);
|
|
| 5698 | - } |
|
| 5313 | + $label=$this->fields[$key]['label']; |
|
| 5314 | + //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
|
| 5315 | + $default=$this->fields[$key]['default']; |
|
| 5316 | + $computed=$this->fields[$key]['computed']; |
|
| 5317 | + $unique=$this->fields[$key]['unique']; |
|
| 5318 | + $required=$this->fields[$key]['required']; |
|
| 5319 | + |
|
| 5320 | + $langfile=$this->fields[$key]['langfile']; |
|
| 5321 | + $list=$this->fields[$key]['list']; |
|
| 5322 | + $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
| 5323 | + |
|
| 5324 | + $objectid = $this->id; |
|
| 5325 | + |
|
| 5326 | + |
|
| 5327 | + if ($computed) |
|
| 5328 | + {
|
|
| 5329 | + if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5330 | + else return ''; |
|
| 5331 | + } |
|
| 5332 | + |
|
| 5333 | + |
|
| 5334 | + // Use in priority showsize from parameters, then $val['css'] then autodefine |
|
| 5335 | + if (empty($morecss) && ! empty($val['css'])) |
|
| 5336 | + {
|
|
| 5337 | + $showsize = $val['css']; |
|
| 5338 | + } |
|
| 5339 | + if (empty($morecss)) |
|
| 5340 | + {
|
|
| 5341 | + if ($type == 'date') |
|
| 5342 | + {
|
|
| 5343 | + $morecss = 'minwidth100imp'; |
|
| 5344 | + } |
|
| 5345 | + elseif ($type == 'datetime') |
|
| 5346 | + {
|
|
| 5347 | + $morecss = 'minwidth200imp'; |
|
| 5348 | + } |
|
| 5349 | + elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5350 | + {
|
|
| 5351 | + $morecss = 'maxwidth75'; |
|
| 5352 | + }elseif ($type == 'url') |
|
| 5353 | + {
|
|
| 5354 | + $morecss='minwidth400'; |
|
| 5355 | + } |
|
| 5356 | + elseif ($type == 'boolean') |
|
| 5357 | + {
|
|
| 5358 | + $morecss=''; |
|
| 5359 | + } |
|
| 5360 | + else |
|
| 5361 | + {
|
|
| 5362 | + if (round($size) < 12) |
|
| 5363 | + {
|
|
| 5364 | + $morecss = 'minwidth100'; |
|
| 5365 | + } |
|
| 5366 | + else if (round($size) <= 48) |
|
| 5367 | + {
|
|
| 5368 | + $morecss = 'minwidth200'; |
|
| 5369 | + } |
|
| 5370 | + else |
|
| 5371 | + {
|
|
| 5372 | + $morecss = 'minwidth400'; |
|
| 5373 | + } |
|
| 5374 | + } |
|
| 5375 | + } |
|
| 5376 | + |
|
| 5377 | + if (in_array($type,array('date','datetime')))
|
|
| 5378 | + {
|
|
| 5379 | + $tmp=explode(',',$size);
|
|
| 5380 | + $newsize=$tmp[0]; |
|
| 5381 | + |
|
| 5382 | + $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
|
| 5383 | + |
|
| 5384 | + // Do not show current date when field not required (see selectDate() method) |
|
| 5385 | + if (!$required && $value == '') $value = '-1'; |
|
| 5386 | + |
|
| 5387 | + // TODO Must also support $moreparam |
|
| 5388 | + $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
| 5389 | + } |
|
| 5390 | + elseif (in_array($type,array('int','integer')))
|
|
| 5391 | + {
|
|
| 5392 | + $tmp=explode(',',$size);
|
|
| 5393 | + $newsize=$tmp[0]; |
|
| 5394 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5395 | + } |
|
| 5396 | + elseif (preg_match('/varchar/', $type))
|
|
| 5397 | + {
|
|
| 5398 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5399 | + } |
|
| 5400 | + elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5401 | + {
|
|
| 5402 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5403 | + } |
|
| 5404 | + elseif ($type == 'text') |
|
| 5405 | + {
|
|
| 5406 | + if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5407 | + {
|
|
| 5408 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5409 | + $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 5410 | + $out=$doleditor->Create(1); |
|
| 5411 | + } |
|
| 5412 | + else |
|
| 5413 | + {
|
|
| 5414 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5415 | + } |
|
| 5416 | + } |
|
| 5417 | + elseif ($type == 'html') |
|
| 5418 | + {
|
|
| 5419 | + if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5420 | + {
|
|
| 5421 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5422 | + $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%'); |
|
| 5423 | + $out=$doleditor->Create(1); |
|
| 5424 | + } |
|
| 5425 | + else |
|
| 5426 | + {
|
|
| 5427 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5428 | + } |
|
| 5429 | + } |
|
| 5430 | + elseif ($type == 'boolean') |
|
| 5431 | + {
|
|
| 5432 | + $checked=''; |
|
| 5433 | + if (!empty($value)) {
|
|
| 5434 | + $checked=' checked value="1" '; |
|
| 5435 | + } else {
|
|
| 5436 | + $checked=' value="1" '; |
|
| 5437 | + } |
|
| 5438 | + $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5439 | + } |
|
| 5440 | + elseif ($type == 'price') |
|
| 5441 | + {
|
|
| 5442 | + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5443 | + $value=price($value); |
|
| 5444 | + } |
|
| 5445 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5446 | + } |
|
| 5447 | + elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5448 | + {
|
|
| 5449 | + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5450 | + $value=price($value); |
|
| 5451 | + } |
|
| 5452 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5453 | + } |
|
| 5454 | + elseif ($type == 'select') |
|
| 5455 | + {
|
|
| 5456 | + $out = ''; |
|
| 5457 | + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5458 | + {
|
|
| 5459 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5460 | + $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5461 | + } |
|
| 5462 | + |
|
| 5463 | + $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5464 | + if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5465 | + foreach ($param['options'] as $key => $val) |
|
| 5466 | + {
|
|
| 5467 | + if ((string) $key == '') continue; |
|
| 5468 | + list($val, $parent) = explode('|', $val);
|
|
| 5469 | + $out.='<option value="'.$key.'"'; |
|
| 5470 | + $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5471 | + $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5472 | + $out.='>'.$val.'</option>'; |
|
| 5473 | + } |
|
| 5474 | + $out.='</select>'; |
|
| 5475 | + } |
|
| 5476 | + elseif ($type == 'sellist') |
|
| 5477 | + {
|
|
| 5478 | + $out = ''; |
|
| 5479 | + if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5480 | + {
|
|
| 5481 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5482 | + $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5483 | + } |
|
| 5484 | + |
|
| 5485 | + $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5486 | + if (is_array($param['options'])) |
|
| 5487 | + {
|
|
| 5488 | + $param_list=array_keys($param['options']); |
|
| 5489 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5490 | + $parentName=''; |
|
| 5491 | + $parentField=''; |
|
| 5492 | + // 0 : tableName |
|
| 5493 | + // 1 : label field name |
|
| 5494 | + // 2 : key fields name (if differ of rowid) |
|
| 5495 | + // 3 : key field parent (for dependent lists) |
|
| 5496 | + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5497 | + $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5498 | + |
|
| 5499 | + |
|
| 5500 | + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5501 | + {
|
|
| 5502 | + if (strpos($InfoFieldList[4], 'extra.') !== false) |
|
| 5503 | + {
|
|
| 5504 | + $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5505 | + } else {
|
|
| 5506 | + $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5507 | + } |
|
| 5508 | + } |
|
| 5509 | + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5510 | + {
|
|
| 5511 | + list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
|
|
| 5512 | + $keyList.= ', '.$parentField; |
|
| 5513 | + } |
|
| 5514 | + |
|
| 5515 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5516 | + if (is_array($fields_label)) |
|
| 5517 | + {
|
|
| 5518 | + $keyList .=', '; |
|
| 5519 | + $keyList .= implode(', ', $fields_label);
|
|
| 5520 | + } |
|
| 5521 | + |
|
| 5522 | + $sqlwhere=''; |
|
| 5523 | + $sql = 'SELECT '.$keyList; |
|
| 5524 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5525 | + if (!empty($InfoFieldList[4])) |
|
| 5526 | + {
|
|
| 5527 | + // can use SELECT request |
|
| 5528 | + if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5529 | + $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5530 | + } |
|
| 5531 | + |
|
| 5532 | + // current object id can be use into filter |
|
| 5533 | + if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5534 | + $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5535 | + } else {
|
|
| 5536 | + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5537 | + } |
|
| 5538 | + //We have to join on extrafield table |
|
| 5539 | + if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5540 | + {
|
|
| 5541 | + $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5542 | + $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5543 | + } |
|
| 5544 | + else |
|
| 5545 | + {
|
|
| 5546 | + $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5547 | + } |
|
| 5548 | + } |
|
| 5549 | + else |
|
| 5550 | + {
|
|
| 5551 | + $sqlwhere.= ' WHERE 1=1'; |
|
| 5552 | + } |
|
| 5553 | + // Some tables may have field, some other not. For the moment we disable it. |
|
| 5554 | + if (in_array($InfoFieldList[0],array('tablewithentity')))
|
|
| 5555 | + {
|
|
| 5556 | + $sqlwhere.= ' AND entity = '.$conf->entity; |
|
| 5557 | + } |
|
| 5558 | + $sql.=$sqlwhere; |
|
| 5559 | + //print $sql; |
|
| 5560 | + |
|
| 5561 | + $sql .= ' ORDER BY ' . implode(', ', $fields_label);
|
|
| 5562 | + |
|
| 5563 | + dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
| 5564 | + $resql = $this->db->query($sql); |
|
| 5565 | + if ($resql) |
|
| 5566 | + {
|
|
| 5567 | + $out.='<option value="0"> </option>'; |
|
| 5568 | + $num = $this->db->num_rows($resql); |
|
| 5569 | + $i = 0; |
|
| 5570 | + while ($i < $num) |
|
| 5571 | + {
|
|
| 5572 | + $labeltoshow=''; |
|
| 5573 | + $obj = $this->db->fetch_object($resql); |
|
| 5574 | + |
|
| 5575 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 5576 | + $notrans = false; |
|
| 5577 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5578 | + if (is_array($fields_label)) |
|
| 5579 | + {
|
|
| 5580 | + $notrans = true; |
|
| 5581 | + foreach ($fields_label as $field_toshow) |
|
| 5582 | + {
|
|
| 5583 | + $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5584 | + } |
|
| 5585 | + } |
|
| 5586 | + else |
|
| 5587 | + {
|
|
| 5588 | + $labeltoshow=$obj->{$InfoFieldList[1]};
|
|
| 5589 | + } |
|
| 5590 | + $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5591 | + |
|
| 5592 | + if ($value == $obj->rowid) |
|
| 5593 | + {
|
|
| 5594 | + foreach ($fields_label as $field_toshow) |
|
| 5595 | + {
|
|
| 5596 | + $translabel=$langs->trans($obj->$field_toshow); |
|
| 5597 | + if ($translabel!=$obj->$field_toshow) {
|
|
| 5598 | + $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5599 | + }else {
|
|
| 5600 | + $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5601 | + } |
|
| 5602 | + } |
|
| 5603 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5604 | + } |
|
| 5605 | + else |
|
| 5606 | + {
|
|
| 5607 | + if (! $notrans) |
|
| 5608 | + {
|
|
| 5609 | + $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5610 | + if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 5611 | + $labeltoshow=dol_trunc($translabel,18); |
|
| 5612 | + } |
|
| 5613 | + else {
|
|
| 5614 | + $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
|
| 5615 | + } |
|
| 5616 | + } |
|
| 5617 | + if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5618 | + if ($value==$obj->rowid) |
|
| 5619 | + {
|
|
| 5620 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5621 | + } |
|
| 5622 | + |
|
| 5623 | + if (!empty($InfoFieldList[3]) && $parentField) |
|
| 5624 | + {
|
|
| 5625 | + $parent = $parentName.':'.$obj->{$parentField};
|
|
| 5626 | + } |
|
| 5627 | + |
|
| 5628 | + $out.='<option value="'.$obj->rowid.'"'; |
|
| 5629 | + $out.= ($value==$obj->rowid?' selected':''); |
|
| 5630 | + $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5631 | + $out.='>'.$labeltoshow.'</option>'; |
|
| 5632 | + } |
|
| 5633 | + |
|
| 5634 | + $i++; |
|
| 5635 | + } |
|
| 5636 | + $this->db->free($resql); |
|
| 5637 | + } |
|
| 5638 | + else {
|
|
| 5639 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5640 | + } |
|
| 5641 | + } |
|
| 5642 | + $out.='</select>'; |
|
| 5643 | + } |
|
| 5644 | + elseif ($type == 'checkbox') |
|
| 5645 | + {
|
|
| 5646 | + $value_arr=explode(',',$value);
|
|
| 5647 | + $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5648 | + } |
|
| 5649 | + elseif ($type == 'radio') |
|
| 5650 | + {
|
|
| 5651 | + $out=''; |
|
| 5652 | + foreach ($param['options'] as $keyopt => $val) |
|
| 5653 | + {
|
|
| 5654 | + $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5655 | + $out.=' value="'.$keyopt.'"'; |
|
| 5656 | + $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5657 | + $out.= ($value==$keyopt?'checked':''); |
|
| 5658 | + $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5659 | + } |
|
| 5660 | + } |
|
| 5661 | + elseif ($type == 'chkbxlst') |
|
| 5662 | + {
|
|
| 5663 | + if (is_array($value)) {
|
|
| 5664 | + $value_arr = $value; |
|
| 5665 | + } |
|
| 5666 | + else {
|
|
| 5667 | + $value_arr = explode(',', $value);
|
|
| 5668 | + } |
|
| 5669 | + |
|
| 5670 | + if (is_array($param['options'])) {
|
|
| 5671 | + $param_list = array_keys($param['options']); |
|
| 5672 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5673 | + $parentName=''; |
|
| 5674 | + $parentField=''; |
|
| 5675 | + // 0 : tableName |
|
| 5676 | + // 1 : label field name |
|
| 5677 | + // 2 : key fields name (if differ of rowid) |
|
| 5678 | + // 3 : key field parent (for dependent lists) |
|
| 5679 | + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5680 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5681 | + |
|
| 5682 | + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
|
|
| 5683 | + list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
|
|
| 5684 | + $keyList .= ', ' . $parentField; |
|
| 5685 | + } |
|
| 5686 | + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
|
|
| 5687 | + if (strpos($InfoFieldList[4], 'extra.') !== false) {
|
|
| 5688 | + $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5689 | + } else {
|
|
| 5690 | + $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5691 | + } |
|
| 5692 | + } |
|
| 5693 | + |
|
| 5694 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5695 | + if (is_array($fields_label)) {
|
|
| 5696 | + $keyList .= ', '; |
|
| 5697 | + $keyList .= implode(', ', $fields_label);
|
|
| 5698 | + } |
|
| 5699 | + |
|
| 5700 | + $sqlwhere = ''; |
|
| 5701 | + $sql = 'SELECT ' . $keyList; |
|
| 5702 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5703 | + if (! empty($InfoFieldList[4])) {
|
|
| 5704 | + |
|
| 5705 | + // can use SELECT request |
|
| 5706 | + if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5707 | + $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5708 | + } |
|
| 5709 | + |
|
| 5710 | + // current object id can be use into filter |
|
| 5711 | + if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5712 | + $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5713 | + } else {
|
|
| 5714 | + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5715 | + } |
|
| 5716 | + |
|
| 5717 | + // We have to join on extrafield table |
|
| 5718 | + if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 5719 | + $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5720 | + $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5721 | + } else {
|
|
| 5722 | + $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5723 | + } |
|
| 5724 | + } else {
|
|
| 5725 | + $sqlwhere .= ' WHERE 1=1'; |
|
| 5726 | + } |
|
| 5727 | + // Some tables may have field, some other not. For the moment we disable it. |
|
| 5728 | + if (in_array($InfoFieldList[0], array ('tablewithentity')))
|
|
| 5729 | + {
|
|
| 5730 | + $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
| 5731 | + } |
|
| 5732 | + // $sql.=preg_replace('/^ AND /','',$sqlwhere);
|
|
| 5733 | + // print $sql; |
|
| 5734 | + |
|
| 5735 | + $sql .= $sqlwhere; |
|
| 5736 | + dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5737 | + $resql = $this->db->query($sql); |
|
| 5738 | + if ($resql) {
|
|
| 5739 | + $num = $this->db->num_rows($resql); |
|
| 5740 | + $i = 0; |
|
| 5741 | + |
|
| 5742 | + $data=array(); |
|
| 5743 | + |
|
| 5744 | + while ( $i < $num ) {
|
|
| 5745 | + $labeltoshow = ''; |
|
| 5746 | + $obj = $this->db->fetch_object($resql); |
|
| 5747 | + |
|
| 5748 | + $notrans = false; |
|
| 5749 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 5750 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5751 | + if (is_array($fields_label)) {
|
|
| 5752 | + $notrans = true; |
|
| 5753 | + foreach ( $fields_label as $field_toshow ) {
|
|
| 5754 | + $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 5755 | + } |
|
| 5756 | + } else {
|
|
| 5757 | + $labeltoshow = $obj->{$InfoFieldList[1]};
|
|
| 5758 | + } |
|
| 5759 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5760 | + |
|
| 5761 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5762 | + foreach ( $fields_label as $field_toshow ) {
|
|
| 5763 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 5764 | + if ($translabel != $obj->$field_toshow) {
|
|
| 5765 | + $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5766 | + } else {
|
|
| 5767 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5768 | + } |
|
| 5769 | + } |
|
| 5770 | + |
|
| 5771 | + $data[$obj->rowid]=$labeltoshow; |
|
| 5772 | + } else {
|
|
| 5773 | + if (! $notrans) {
|
|
| 5774 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5775 | + if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 5776 | + $labeltoshow = dol_trunc($translabel, 18); |
|
| 5777 | + } else {
|
|
| 5778 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
|
| 5779 | + } |
|
| 5780 | + } |
|
| 5781 | + if (empty($labeltoshow)) |
|
| 5782 | + $labeltoshow = '(not defined)'; |
|
| 5783 | + |
|
| 5784 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5785 | + $data[$obj->rowid]=$labeltoshow; |
|
| 5786 | + } |
|
| 5787 | + |
|
| 5788 | + if (! empty($InfoFieldList[3]) && $parentField) {
|
|
| 5789 | + $parent = $parentName . ':' . $obj->{$parentField};
|
|
| 5790 | + } |
|
| 5791 | + |
|
| 5792 | + $data[$obj->rowid]=$labeltoshow; |
|
| 5793 | + } |
|
| 5794 | + |
|
| 5795 | + $i ++; |
|
| 5796 | + } |
|
| 5797 | + $this->db->free($resql); |
|
| 5798 | + |
|
| 5799 | + $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5800 | + } else {
|
|
| 5801 | + print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5802 | + } |
|
| 5803 | + } |
|
| 5804 | + } |
|
| 5805 | + elseif ($type == 'link') |
|
| 5806 | + {
|
|
| 5807 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5808 | + $showempty=(($required && $default != '')?0:1); |
|
| 5809 | + $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5810 | + if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
|
| 5811 | + {
|
|
| 5812 | + list($class,$classfile)=explode(':',$param_list[0]);
|
|
| 5813 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5814 | + else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 5815 | + $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5816 | + // TODO Add Javascript code to add input fields contents to new elements urls |
|
| 5817 | + } |
|
| 5818 | + } |
|
| 5819 | + elseif ($type == 'password') |
|
| 5820 | + {
|
|
| 5821 | + // If prefix is 'search_', field is used as a filter, we use a common text field. |
|
| 5822 | + $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5823 | + } |
|
| 5824 | + elseif ($type == 'array') |
|
| 5825 | + {
|
|
| 5826 | + $newval = $val; |
|
| 5827 | + $newval['type'] = 'varchar(256)'; |
|
| 5828 | + |
|
| 5829 | + $out=''; |
|
| 5830 | + |
|
| 5831 | + $inputs = array(); |
|
| 5832 | + if(! empty($value)) {
|
|
| 5833 | + foreach($value as $option) {
|
|
| 5834 | + $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5835 | + $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5836 | + } |
|
| 5837 | + } |
|
| 5838 | + |
|
| 5839 | + $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5840 | + |
|
| 5841 | + $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5842 | + $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5843 | + |
|
| 5844 | + if(! empty($conf->use_javascript_ajax)) {
|
|
| 5845 | + $out.= ' |
|
| 5846 | + <script type="text/javascript"> |
|
| 5847 | + $(document).ready(function() {
|
|
| 5848 | + $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() {
|
|
| 5849 | + $("'.dol_escape_js($newInput).'").insertBefore(this);
|
|
| 5850 | + }); |
|
| 5851 | + |
|
| 5852 | + $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() {
|
|
| 5853 | + $(this).parent().remove(); |
|
| 5854 | + }); |
|
| 5855 | + }); |
|
| 5856 | + </script>'; |
|
| 5857 | + } |
|
| 5858 | + } |
|
| 5859 | + if (!empty($hidden)) {
|
|
| 5860 | + $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5861 | + } |
|
| 5862 | + /* Add comments |
|
| 5863 | + if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
|
| 5864 | + elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; |
|
| 5865 | + */ |
|
| 5866 | + return $out; |
|
| 5867 | + } |
|
| 5868 | + |
|
| 5869 | + /** |
|
| 5870 | + * Return HTML string to show a field into a page |
|
| 5871 | + * Code very similar with showOutputField of extra fields |
|
| 5872 | + * |
|
| 5873 | + * @param array $val Array of properties of field to show |
|
| 5874 | + * @param string $key Key of attribute |
|
| 5875 | + * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
| 5876 | + * @param string $moreparam To add more parametes on html input tag |
|
| 5877 | + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5878 | + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5879 | + * @param mixed $showsize Value for css to define size. May also be a numeric. |
|
| 5880 | + * @return string |
|
| 5881 | + */ |
|
| 5882 | + function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5883 | + {
|
|
| 5884 | + global $conf,$langs,$form; |
|
| 5885 | + |
|
| 5886 | + if (! is_object($form)) |
|
| 5887 | + {
|
|
| 5888 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5889 | + $form=new Form($this->db); |
|
| 5890 | + } |
|
| 5891 | + |
|
| 5892 | + $objectid = $this->id; |
|
| 5893 | + $label = $val['label']; |
|
| 5894 | + $type = $val['type']; |
|
| 5895 | + $size = $val['css']; |
|
| 5896 | + |
|
| 5897 | + // Convert var to be able to share same code than showOutputField of extrafields |
|
| 5898 | + if (preg_match('/varchar\((\d+)\)/', $type, $reg))
|
|
| 5899 | + {
|
|
| 5900 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5901 | + $size = $reg[1]; |
|
| 5902 | + } |
|
| 5903 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5904 | + if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5905 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 5906 | + |
|
| 5907 | + $default=$val['default']; |
|
| 5908 | + $computed=$val['computed']; |
|
| 5909 | + $unique=$val['unique']; |
|
| 5910 | + $required=$val['required']; |
|
| 5911 | + $param=$val['param']; |
|
| 5912 | + if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 5913 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
|
| 5914 | + {
|
|
| 5915 | + $type='link'; |
|
| 5916 | + $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5917 | + } |
|
| 5918 | + $langfile=$val['langfile']; |
|
| 5919 | + $list=$val['list']; |
|
| 5920 | + $help=$val['help']; |
|
| 5921 | + $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) |
|
| 5922 | + |
|
| 5923 | + if ($hidden) return ''; |
|
| 5924 | + |
|
| 5925 | + // If field is a computed field, value must become result of compute |
|
| 5926 | + if ($computed) |
|
| 5927 | + {
|
|
| 5928 | + // Make the eval of compute string |
|
| 5929 | + //var_dump($computed); |
|
| 5930 | + $value = dol_eval($computed, 1, 0); |
|
| 5931 | + } |
|
| 5932 | + |
|
| 5933 | + if (empty($showsize)) |
|
| 5934 | + {
|
|
| 5935 | + if ($type == 'date') |
|
| 5936 | + {
|
|
| 5937 | + //$showsize=10; |
|
| 5938 | + $showsize = 'minwidth100imp'; |
|
| 5939 | + } |
|
| 5940 | + elseif ($type == 'datetime') |
|
| 5941 | + {
|
|
| 5942 | + //$showsize=19; |
|
| 5943 | + $showsize = 'minwidth200imp'; |
|
| 5944 | + } |
|
| 5945 | + elseif (in_array($type,array('int','double','price')))
|
|
| 5946 | + {
|
|
| 5947 | + //$showsize=10; |
|
| 5948 | + $showsize = 'maxwidth75'; |
|
| 5949 | + } |
|
| 5950 | + elseif ($type == 'url') |
|
| 5951 | + {
|
|
| 5952 | + $showsize='minwidth400'; |
|
| 5953 | + } |
|
| 5954 | + elseif ($type == 'boolean') |
|
| 5955 | + {
|
|
| 5956 | + $showsize=''; |
|
| 5957 | + } |
|
| 5958 | + else |
|
| 5959 | + {
|
|
| 5960 | + if (round($size) < 12) |
|
| 5961 | + {
|
|
| 5962 | + $showsize = 'minwidth100'; |
|
| 5963 | + } |
|
| 5964 | + else if (round($size) <= 48) |
|
| 5965 | + {
|
|
| 5966 | + $showsize = 'minwidth200'; |
|
| 5967 | + } |
|
| 5968 | + else |
|
| 5969 | + {
|
|
| 5970 | + //$showsize=48; |
|
| 5971 | + $showsize = 'minwidth400'; |
|
| 5972 | + } |
|
| 5973 | + } |
|
| 5974 | + } |
|
| 5975 | + |
|
| 5976 | + // Format output value differently according to properties of field |
|
| 5977 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5978 | + elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5979 | + elseif ($type == 'date') |
|
| 5980 | + {
|
|
| 5981 | + if(! empty($value)) {
|
|
| 5982 | + $value=dol_print_date($value,'day'); |
|
| 5983 | + } else {
|
|
| 5984 | + $value=''; |
|
| 5985 | + } |
|
| 5986 | + } |
|
| 5987 | + elseif ($type == 'datetime') |
|
| 5988 | + {
|
|
| 5989 | + if(! empty($value)) {
|
|
| 5990 | + $value=dol_print_date($value,'dayhour'); |
|
| 5991 | + } else {
|
|
| 5992 | + $value=''; |
|
| 5993 | + } |
|
| 5994 | + } |
|
| 5995 | + elseif ($type == 'double') |
|
| 5996 | + {
|
|
| 5997 | + if (!empty($value)) {
|
|
| 5998 | + $value=price($value); |
|
| 5999 | + } |
|
| 6000 | + } |
|
| 6001 | + elseif ($type == 'boolean') |
|
| 6002 | + {
|
|
| 6003 | + $checked=''; |
|
| 6004 | + if (!empty($value)) {
|
|
| 6005 | + $checked=' checked '; |
|
| 6006 | + } |
|
| 6007 | + $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 6008 | + } |
|
| 6009 | + elseif ($type == 'mail') |
|
| 6010 | + {
|
|
| 6011 | + $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 6012 | + } |
|
| 6013 | + elseif ($type == 'url') |
|
| 6014 | + {
|
|
| 6015 | + $value=dol_print_url($value,'_blank',32,1); |
|
| 6016 | + } |
|
| 6017 | + elseif ($type == 'phone') |
|
| 6018 | + {
|
|
| 6019 | + $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6020 | + } |
|
| 6021 | + elseif ($type == 'price') |
|
| 6022 | + {
|
|
| 6023 | + $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
| 6024 | + } |
|
| 6025 | + elseif ($type == 'select') |
|
| 6026 | + {
|
|
| 6027 | + $value=$param['options'][$value]; |
|
| 6028 | + } |
|
| 6029 | + elseif ($type == 'sellist') |
|
| 6030 | + {
|
|
| 6031 | + $param_list=array_keys($param['options']); |
|
| 6032 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6033 | + |
|
| 6034 | + $selectkey="rowid"; |
|
| 6035 | + $keyList='rowid'; |
|
| 6036 | + |
|
| 6037 | + if (count($InfoFieldList)>=3) |
|
| 6038 | + {
|
|
| 6039 | + $selectkey = $InfoFieldList[2]; |
|
| 6040 | + $keyList=$InfoFieldList[2].' as rowid'; |
|
| 6041 | + } |
|
| 6042 | + |
|
| 6043 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6044 | + if(is_array($fields_label)) {
|
|
| 6045 | + $keyList .=', '; |
|
| 6046 | + $keyList .= implode(', ', $fields_label);
|
|
| 6047 | + } |
|
| 6048 | + |
|
| 6049 | + $sql = 'SELECT '.$keyList; |
|
| 6050 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 6051 | + if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 6052 | + {
|
|
| 6053 | + $sql.= ' as main'; |
|
| 6054 | + } |
|
| 6055 | + if ($selectkey=='rowid' && empty($value)) {
|
|
| 6056 | + $sql.= " WHERE ".$selectkey."=0"; |
|
| 6057 | + } elseif ($selectkey=='rowid') {
|
|
| 6058 | + $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6059 | + }else {
|
|
| 6060 | + $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6061 | + } |
|
| 6062 | + |
|
| 6063 | + //$sql.= ' AND entity = '.$conf->entity; |
|
| 6064 | + |
|
| 6065 | + dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
| 6066 | + $resql = $this->db->query($sql); |
|
| 6067 | + if ($resql) |
|
| 6068 | + {
|
|
| 6069 | + $value=''; // value was used, so now we reste it to use it to build final output |
|
| 6070 | + |
|
| 6071 | + $obj = $this->db->fetch_object($resql); |
|
| 6072 | + |
|
| 6073 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 6074 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6075 | + |
|
| 6076 | + if(is_array($fields_label) && count($fields_label)>1) |
|
| 6077 | + {
|
|
| 6078 | + foreach ($fields_label as $field_toshow) |
|
| 6079 | + {
|
|
| 6080 | + $translabel=''; |
|
| 6081 | + if (!empty($obj->$field_toshow)) {
|
|
| 6082 | + $translabel=$langs->trans($obj->$field_toshow); |
|
| 6083 | + } |
|
| 6084 | + if ($translabel!=$field_toshow) {
|
|
| 6085 | + $value.=dol_trunc($translabel,18).' '; |
|
| 6086 | + }else {
|
|
| 6087 | + $value.=$obj->$field_toshow.' '; |
|
| 6088 | + } |
|
| 6089 | + } |
|
| 6090 | + } |
|
| 6091 | + else |
|
| 6092 | + {
|
|
| 6093 | + $translabel=''; |
|
| 6094 | + if (!empty($obj->{$InfoFieldList[1]})) {
|
|
| 6095 | + $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6096 | + } |
|
| 6097 | + if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 6098 | + $value=dol_trunc($translabel,18); |
|
| 6099 | + }else {
|
|
| 6100 | + $value=$obj->{$InfoFieldList[1]};
|
|
| 6101 | + } |
|
| 6102 | + } |
|
| 6103 | + } |
|
| 6104 | + else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6105 | + } |
|
| 6106 | + elseif ($type == 'radio') |
|
| 6107 | + {
|
|
| 6108 | + $value=$param['options'][$value]; |
|
| 6109 | + } |
|
| 6110 | + elseif ($type == 'checkbox') |
|
| 6111 | + {
|
|
| 6112 | + $value_arr=explode(',',$value);
|
|
| 6113 | + $value=''; |
|
| 6114 | + if (is_array($value_arr) && count($value_arr)>0) |
|
| 6115 | + {
|
|
| 6116 | + foreach ($value_arr as $keyval=>$valueval) {
|
|
| 6117 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6118 | + } |
|
| 6119 | + $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6120 | + } |
|
| 6121 | + } |
|
| 6122 | + elseif ($type == 'chkbxlst') |
|
| 6123 | + {
|
|
| 6124 | + $value_arr = explode(',', $value);
|
|
| 6125 | + |
|
| 6126 | + $param_list = array_keys($param['options']); |
|
| 6127 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6128 | + |
|
| 6129 | + $selectkey = "rowid"; |
|
| 6130 | + $keyList = 'rowid'; |
|
| 6131 | + |
|
| 6132 | + if (count($InfoFieldList) >= 3) {
|
|
| 6133 | + $selectkey = $InfoFieldList[2]; |
|
| 6134 | + $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 6135 | + } |
|
| 6136 | + |
|
| 6137 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6138 | + if (is_array($fields_label)) {
|
|
| 6139 | + $keyList .= ', '; |
|
| 6140 | + $keyList .= implode(', ', $fields_label);
|
|
| 6141 | + } |
|
| 6142 | + |
|
| 6143 | + $sql = 'SELECT ' . $keyList; |
|
| 6144 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 6145 | + if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 6146 | + $sql .= ' as main'; |
|
| 6147 | + } |
|
| 6148 | + // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6149 | + // $sql.= ' AND entity = '.$conf->entity; |
|
| 6150 | + |
|
| 6151 | + dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 6152 | + $resql = $this->db->query($sql); |
|
| 6153 | + if ($resql) {
|
|
| 6154 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 6155 | + $toprint=array(); |
|
| 6156 | + while ( $obj = $this->db->fetch_object($resql) ) {
|
|
| 6157 | + |
|
| 6158 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 6159 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6160 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 6161 | + if (is_array($fields_label) && count($fields_label) > 1) {
|
|
| 6162 | + foreach ( $fields_label as $field_toshow ) {
|
|
| 6163 | + $translabel = ''; |
|
| 6164 | + if (! empty($obj->$field_toshow)) {
|
|
| 6165 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 6166 | + } |
|
| 6167 | + if ($translabel != $field_toshow) {
|
|
| 6168 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6169 | + } else {
|
|
| 6170 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 6171 | + } |
|
| 6172 | + } |
|
| 6173 | + } else {
|
|
| 6174 | + $translabel = ''; |
|
| 6175 | + if (! empty($obj->{$InfoFieldList[1]})) {
|
|
| 6176 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6177 | + } |
|
| 6178 | + if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 6179 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6180 | + } else {
|
|
| 6181 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
|
|
| 6182 | + } |
|
| 6183 | + } |
|
| 6184 | + } |
|
| 6185 | + } |
|
| 6186 | + $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6187 | + } else {
|
|
| 6188 | + dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 6189 | + } |
|
| 6190 | + } |
|
| 6191 | + elseif ($type == 'link') |
|
| 6192 | + {
|
|
| 6193 | + $out=''; |
|
| 6194 | + |
|
| 6195 | + // only if something to display (perf) |
|
| 6196 | + if ($value) |
|
| 6197 | + {
|
|
| 6198 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 6199 | + |
|
| 6200 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6201 | + $classname=$InfoFieldList[0]; |
|
| 6202 | + $classpath=$InfoFieldList[1]; |
|
| 6203 | + $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6204 | + if (! empty($classpath)) |
|
| 6205 | + {
|
|
| 6206 | + dol_include_once($InfoFieldList[1]); |
|
| 6207 | + if ($classname && class_exists($classname)) |
|
| 6208 | + {
|
|
| 6209 | + $object = new $classname($this->db); |
|
| 6210 | + $object->fetch($value); |
|
| 6211 | + $value=$object->getNomUrl($getnomurlparam); |
|
| 6212 | + } |
|
| 6213 | + } |
|
| 6214 | + else |
|
| 6215 | + {
|
|
| 6216 | + dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 6217 | + return 'Error bad setup of extrafield'; |
|
| 6218 | + } |
|
| 6219 | + } |
|
| 6220 | + else $value=''; |
|
| 6221 | + } |
|
| 6222 | + elseif ($type == 'text' || $type == 'html') |
|
| 6223 | + {
|
|
| 6224 | + $value=dol_htmlentitiesbr($value); |
|
| 6225 | + } |
|
| 6226 | + elseif ($type == 'password') |
|
| 6227 | + {
|
|
| 6228 | + $value=preg_replace('/./i','*',$value);
|
|
| 6229 | + } |
|
| 6230 | + elseif ($type == 'array') |
|
| 6231 | + {
|
|
| 6232 | + $value = implode('<br>', $value);
|
|
| 6233 | + } |
|
| 6234 | + |
|
| 6235 | + //print $type.'-'.$size; |
|
| 6236 | + $out=$value; |
|
| 6237 | + |
|
| 6238 | + return $out; |
|
| 6239 | + } |
|
| 6240 | + |
|
| 6241 | + |
|
| 6242 | + /** |
|
| 6243 | + * Function to show lines of extrafields with output datas |
|
| 6244 | + * |
|
| 6245 | + * @param Extrafields $extrafields Extrafield Object |
|
| 6246 | + * @param string $mode Show output (view) or input (edit) for extrafield |
|
| 6247 | + * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
|
|
| 6248 | + * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) |
|
| 6249 | + * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) |
|
| 6250 | + * @param string $onetrtd All fields in same tr td |
|
| 6251 | + * @return string |
|
| 6252 | + */ |
|
| 6253 | + function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
| 6254 | + {
|
|
| 6255 | + global $db, $conf, $langs, $action, $form; |
|
| 6256 | + |
|
| 6257 | + if (! is_object($form)) $form=new Form($db); |
|
| 6258 | + |
|
| 6259 | + $out = ''; |
|
| 6260 | + |
|
| 6261 | + if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) |
|
| 6262 | + {
|
|
| 6263 | + $out .= "\n"; |
|
| 6264 | + $out .= '<!-- showOptionalsInput --> '; |
|
| 6265 | + $out .= "\n"; |
|
| 5699 | 6266 | |
| 5700 | - $sqlwhere = ''; |
|
| 5701 | - $sql = 'SELECT ' . $keyList; |
|
| 5702 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5703 | - if (! empty($InfoFieldList[4])) {
|
|
| 5704 | - |
|
| 5705 | - // can use SELECT request |
|
| 5706 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5707 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5708 | - } |
|
| 5709 | - |
|
| 5710 | - // current object id can be use into filter |
|
| 5711 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5712 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5713 | - } else {
|
|
| 5714 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5715 | - } |
|
| 5716 | - |
|
| 5717 | - // We have to join on extrafield table |
|
| 5718 | - if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 5719 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5720 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5721 | - } else {
|
|
| 5722 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5723 | - } |
|
| 5724 | - } else {
|
|
| 5725 | - $sqlwhere .= ' WHERE 1=1'; |
|
| 5726 | - } |
|
| 5727 | - // Some tables may have field, some other not. For the moment we disable it. |
|
| 5728 | - if (in_array($InfoFieldList[0], array ('tablewithentity')))
|
|
| 5729 | - {
|
|
| 5730 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
| 5731 | - } |
|
| 5732 | - // $sql.=preg_replace('/^ AND /','',$sqlwhere);
|
|
| 5733 | - // print $sql; |
|
| 5734 | - |
|
| 5735 | - $sql .= $sqlwhere; |
|
| 5736 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5737 | - $resql = $this->db->query($sql); |
|
| 5738 | - if ($resql) {
|
|
| 5739 | - $num = $this->db->num_rows($resql); |
|
| 5740 | - $i = 0; |
|
| 5741 | - |
|
| 5742 | - $data=array(); |
|
| 5743 | - |
|
| 5744 | - while ( $i < $num ) {
|
|
| 5745 | - $labeltoshow = ''; |
|
| 5746 | - $obj = $this->db->fetch_object($resql); |
|
| 5747 | - |
|
| 5748 | - $notrans = false; |
|
| 5749 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 5750 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5751 | - if (is_array($fields_label)) {
|
|
| 5752 | - $notrans = true; |
|
| 5753 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 5754 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 6267 | + $e = 0; |
|
| 6268 | + foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6269 | + {
|
|
| 6270 | + // Show only the key field in params |
|
| 6271 | + if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 6272 | + |
|
| 6273 | + $enabled = 1; |
|
| 6274 | + if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
|
| 6275 | + {
|
|
| 6276 | + $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1); |
|
| 6277 | + } |
|
| 6278 | + |
|
| 6279 | + $perms = 1; |
|
| 6280 | + if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) |
|
| 6281 | + {
|
|
| 6282 | + $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
|
| 6283 | + } |
|
| 6284 | + |
|
| 6285 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6286 | + if (empty($perms)) continue; |
|
| 6287 | + |
|
| 6288 | + // Load language if required |
|
| 6289 | + if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6290 | + |
|
| 6291 | + $colspan='3'; |
|
| 6292 | + if (is_array($params) && count($params)>0) {
|
|
| 6293 | + if (array_key_exists('colspan',$params)) {
|
|
| 6294 | + $colspan=$params['colspan']; |
|
| 6295 | + } |
|
| 6296 | + } |
|
| 6297 | + |
|
| 6298 | + switch($mode) {
|
|
| 6299 | + case "view": |
|
| 6300 | + $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 6301 | + break; |
|
| 6302 | + case "edit": |
|
| 6303 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6304 | + // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
|
|
| 6305 | + if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
|
| 6306 | + {
|
|
| 6307 | + if (is_array($getposttemp)) {
|
|
| 6308 | + // $getposttemp is an array but following code expects a comma separated string |
|
| 6309 | + $value = implode(",", $getposttemp);
|
|
| 6310 | + } else {
|
|
| 6311 | + $value = $getposttemp; |
|
| 6312 | + } |
|
| 6313 | + } else {
|
|
| 6314 | + $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6315 | + } |
|
| 6316 | + //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
|
| 6317 | + break; |
|
| 6318 | + } |
|
| 6319 | + |
|
| 6320 | + if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
|
| 6321 | + {
|
|
| 6322 | + $out .= $extrafields->showSeparator($key, $this); |
|
| 6323 | + } |
|
| 6324 | + else |
|
| 6325 | + {
|
|
| 6326 | + $csstyle=''; |
|
| 6327 | + $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6328 | + if (is_array($params) && count($params)>0) {
|
|
| 6329 | + if (array_key_exists('style',$params)) {
|
|
| 6330 | + $csstyle=$params['style']; |
|
| 6331 | + } |
|
| 6332 | + } |
|
| 6333 | + |
|
| 6334 | + // add html5 elements |
|
| 6335 | + $domData = ' data-element="extrafield"'; |
|
| 6336 | + $domData .= ' data-targetelement="'.$this->element.'"'; |
|
| 6337 | + $domData .= ' data-targetid="'.$this->id.'"'; |
|
| 6338 | + |
|
| 6339 | + $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
| 6340 | + |
|
| 6341 | + $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
| 6342 | + |
|
| 6343 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 6344 | + {
|
|
| 6345 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; }
|
|
| 6346 | + } |
|
| 6347 | + |
|
| 6348 | + if ($action == 'selectlines') { $colspan++; }
|
|
| 6349 | + |
|
| 6350 | + // Convert date into timestamp format (value in memory must be a timestamp) |
|
| 6351 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
|
| 6352 | + {
|
|
| 6353 | + $datenotinstring = $this->array_options['options_' . $key]; |
|
| 6354 | + if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6355 | + {
|
|
| 6356 | + $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6357 | + } |
|
| 6358 | + $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)):$datenotinstring; |
|
| 6359 | + } |
|
| 6360 | + // Convert float submited string into real php numeric (value in memory must be a php numeric) |
|
| 6361 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double')))
|
|
| 6362 | + {
|
|
| 6363 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
| 6364 | + } |
|
| 6365 | + |
|
| 6366 | + $labeltoshow = $langs->trans($label); |
|
| 6367 | + |
|
| 6368 | + $out .= '<td class="titlefield'; |
|
| 6369 | + if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6370 | + if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6371 | + $out .= '">'; |
|
| 6372 | + if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6373 | + else $out .= $labeltoshow; |
|
| 6374 | + $out .= '</td>'; |
|
| 6375 | + |
|
| 6376 | + $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
| 6377 | + $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 6378 | + |
|
| 6379 | + switch($mode) {
|
|
| 6380 | + case "view": |
|
| 6381 | + $out .= $extrafields->showOutputField($key, $value); |
|
| 6382 | + break; |
|
| 6383 | + case "edit": |
|
| 6384 | + $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); |
|
| 6385 | + break; |
|
| 6386 | + } |
|
| 6387 | + |
|
| 6388 | + $out .= '</td>'; |
|
| 6389 | + |
|
| 6390 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6391 | + else $out .= '</tr>'; |
|
| 6392 | + $e++; |
|
| 6393 | + } |
|
| 6394 | + } |
|
| 6395 | + $out .= "\n"; |
|
| 6396 | + // Add code to manage list depending on others |
|
| 6397 | + if (! empty($conf->use_javascript_ajax)) {
|
|
| 6398 | + $out .= ' |
|
| 6399 | + <script type="text/javascript"> |
|
| 6400 | + jQuery(document).ready(function() {
|
|
| 6401 | + function showOptions(child_list, parent_list) |
|
| 6402 | + {
|
|
| 6403 | + var val = $("select[name=\"options_"+parent_list+"\"]").val();
|
|
| 6404 | + var parentVal = parent_list + ":" + val; |
|
| 6405 | + if(val > 0) {
|
|
| 6406 | + $("select[name=\""+child_list+"\"] option[parent]").hide();
|
|
| 6407 | + $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
|
|
| 6408 | + } else {
|
|
| 6409 | + $("select[name=\""+child_list+"\"] option").show();
|
|
| 5755 | 6410 | } |
| 5756 | - } else {
|
|
| 5757 | - $labeltoshow = $obj->{$InfoFieldList[1]};
|
|
| 6411 | + } |
|
| 6412 | + function setListDependencies() {
|
|
| 6413 | + jQuery("select option[parent]").parent().each(function() {
|
|
| 6414 | + var child_list = $(this).attr("name");
|
|
| 6415 | + var parent = $(this).find("option[parent]:first").attr("parent");
|
|
| 6416 | + var infos = parent.split(":");
|
|
| 6417 | + var parent_list = infos[0]; |
|
| 6418 | + $("select[name=\""+parent_list+"\"]").change(function() {
|
|
| 6419 | + showOptions(child_list, parent_list); |
|
| 6420 | + }); |
|
| 6421 | + }); |
|
| 5758 | 6422 | } |
| 5759 | - $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5760 | - |
|
| 5761 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5762 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 5763 | - $translabel = $langs->trans($obj->$field_toshow); |
|
| 5764 | - if ($translabel != $obj->$field_toshow) {
|
|
| 5765 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5766 | - } else {
|
|
| 5767 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5768 | - } |
|
| 5769 | - } |
|
| 5770 | 6423 | |
| 5771 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5772 | - } else {
|
|
| 5773 | - if (! $notrans) {
|
|
| 5774 | - $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5775 | - if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 5776 | - $labeltoshow = dol_trunc($translabel, 18); |
|
| 5777 | - } else {
|
|
| 5778 | - $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
|
| 5779 | - } |
|
| 5780 | - } |
|
| 5781 | - if (empty($labeltoshow)) |
|
| 5782 | - $labeltoshow = '(not defined)'; |
|
| 6424 | + setListDependencies(); |
|
| 6425 | + }); |
|
| 6426 | + </script>'."\n"; |
|
| 6427 | + $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
| 6428 | + } |
|
| 6429 | + } |
|
| 6430 | + return $out; |
|
| 6431 | + } |
|
| 5783 | 6432 | |
| 5784 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5785 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5786 | - } |
|
| 5787 | 6433 | |
| 5788 | - if (! empty($InfoFieldList[3]) && $parentField) {
|
|
| 5789 | - $parent = $parentName . ':' . $obj->{$parentField};
|
|
| 5790 | - } |
|
| 6434 | + /** |
|
| 6435 | + * Returns the rights used for this class |
|
| 6436 | + * @return stdClass |
|
| 6437 | + */ |
|
| 6438 | + public function getRights() |
|
| 6439 | + {
|
|
| 6440 | + global $user; |
|
| 5791 | 6441 | |
| 5792 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5793 | - } |
|
| 6442 | + $element = $this->element; |
|
| 6443 | + if ($element == 'facturerec') $element='facture'; |
|
| 5794 | 6444 | |
| 5795 | - $i ++; |
|
| 5796 | - } |
|
| 5797 | - $this->db->free($resql); |
|
| 6445 | + return $user->rights->{$element};
|
|
| 6446 | + } |
|
| 5798 | 6447 | |
| 5799 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5800 | - } else {
|
|
| 5801 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5802 | - } |
|
| 5803 | - } |
|
| 5804 | - } |
|
| 5805 | - elseif ($type == 'link') |
|
| 5806 | - {
|
|
| 5807 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5808 | - $showempty=(($required && $default != '')?0:1); |
|
| 5809 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5810 | - if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
|
| 5811 | - {
|
|
| 5812 | - list($class,$classfile)=explode(':',$param_list[0]);
|
|
| 5813 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5814 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 5815 | - $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5816 | - // TODO Add Javascript code to add input fields contents to new elements urls |
|
| 5817 | - } |
|
| 5818 | - } |
|
| 5819 | - elseif ($type == 'password') |
|
| 5820 | - {
|
|
| 5821 | - // If prefix is 'search_', field is used as a filter, we use a common text field. |
|
| 5822 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5823 | - } |
|
| 5824 | - elseif ($type == 'array') |
|
| 5825 | - {
|
|
| 5826 | - $newval = $val; |
|
| 5827 | - $newval['type'] = 'varchar(256)'; |
|
| 5828 | - |
|
| 5829 | - $out=''; |
|
| 5830 | - |
|
| 5831 | - $inputs = array(); |
|
| 5832 | - if(! empty($value)) {
|
|
| 5833 | - foreach($value as $option) {
|
|
| 5834 | - $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5835 | - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5836 | - } |
|
| 5837 | - } |
|
| 6448 | + /** |
|
| 6449 | + * Function used to replace a thirdparty id with another one. |
|
| 6450 | + * This function is meant to be called from replaceThirdparty with the appropiate tables |
|
| 6451 | + * Column name fk_soc MUST be used to identify thirdparties |
|
| 6452 | + * |
|
| 6453 | + * @param DoliDB $db Database handler |
|
| 6454 | + * @param int $origin_id Old thirdparty id (the thirdparty to delete) |
|
| 6455 | + * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) |
|
| 6456 | + * @param string[] $tables Tables that need to be changed |
|
| 6457 | + * @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) |
|
| 6458 | + * @return bool True if success, False if error |
|
| 6459 | + */ |
|
| 6460 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6461 | + {
|
|
| 6462 | + foreach ($tables as $table) |
|
| 6463 | + {
|
|
| 6464 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
| 5838 | 6465 | |
| 5839 | - $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 6466 | + if (! $db->query($sql)) |
|
| 6467 | + {
|
|
| 6468 | + 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. |
|
| 6469 | + //$this->errors = $db->lasterror(); |
|
| 6470 | + return false; |
|
| 6471 | + } |
|
| 6472 | + } |
|
| 5840 | 6473 | |
| 5841 | - $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5842 | - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 6474 | + return true; |
|
| 6475 | + } |
|
| 5843 | 6476 | |
| 5844 | - if(! empty($conf->use_javascript_ajax)) {
|
|
| 5845 | - $out.= ' |
|
| 5846 | - <script type="text/javascript"> |
|
| 5847 | - $(document).ready(function() {
|
|
| 5848 | - $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() {
|
|
| 5849 | - $("'.dol_escape_js($newInput).'").insertBefore(this);
|
|
| 5850 | - }); |
|
| 6477 | + /** |
|
| 6478 | + * Get buy price to use for margin calculation. This function is called when buy price is unknown. |
|
| 6479 | + * Set buy price = sell price if ForceBuyingPriceIfNull configured, |
|
| 6480 | + * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice |
|
| 6481 | + * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice |
|
| 6482 | + * else set min buy price as buy price |
|
| 6483 | + * |
|
| 6484 | + * @param float $unitPrice Product unit price |
|
| 6485 | + * @param float $discountPercent Line discount percent |
|
| 6486 | + * @param int $fk_product Product id |
|
| 6487 | + * @return float <0 if KO, buyprice if OK |
|
| 6488 | + */ |
|
| 6489 | + public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) |
|
| 6490 | + {
|
|
| 6491 | + global $conf; |
|
| 5851 | 6492 | |
| 5852 | - $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() {
|
|
| 5853 | - $(this).parent().remove(); |
|
| 5854 | - }); |
|
| 5855 | - }); |
|
| 5856 | - </script>'; |
|
| 5857 | - } |
|
| 5858 | - } |
|
| 5859 | - if (!empty($hidden)) {
|
|
| 5860 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5861 | - } |
|
| 5862 | - /* Add comments |
|
| 5863 | - if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
|
| 5864 | - elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; |
|
| 5865 | - */ |
|
| 5866 | - return $out; |
|
| 5867 | - } |
|
| 5868 | - |
|
| 5869 | - /** |
|
| 5870 | - * Return HTML string to show a field into a page |
|
| 5871 | - * Code very similar with showOutputField of extra fields |
|
| 5872 | - * |
|
| 5873 | - * @param array $val Array of properties of field to show |
|
| 5874 | - * @param string $key Key of attribute |
|
| 5875 | - * @param string $value Preselected value to show (for date type it must be in timestamp format, for amount or price it must be a php numeric value) |
|
| 5876 | - * @param string $moreparam To add more parametes on html input tag |
|
| 5877 | - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5878 | - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5879 | - * @param mixed $showsize Value for css to define size. May also be a numeric. |
|
| 5880 | - * @return string |
|
| 5881 | - */ |
|
| 5882 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5883 | - {
|
|
| 5884 | - global $conf,$langs,$form; |
|
| 5885 | - |
|
| 5886 | - if (! is_object($form)) |
|
| 5887 | - {
|
|
| 5888 | - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5889 | - $form=new Form($this->db); |
|
| 5890 | - } |
|
| 5891 | - |
|
| 5892 | - $objectid = $this->id; |
|
| 5893 | - $label = $val['label']; |
|
| 5894 | - $type = $val['type']; |
|
| 5895 | - $size = $val['css']; |
|
| 5896 | - |
|
| 5897 | - // Convert var to be able to share same code than showOutputField of extrafields |
|
| 5898 | - if (preg_match('/varchar\((\d+)\)/', $type, $reg))
|
|
| 5899 | - {
|
|
| 5900 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5901 | - $size = $reg[1]; |
|
| 5902 | - } |
|
| 5903 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5904 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5905 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 5906 | - |
|
| 5907 | - $default=$val['default']; |
|
| 5908 | - $computed=$val['computed']; |
|
| 5909 | - $unique=$val['unique']; |
|
| 5910 | - $required=$val['required']; |
|
| 5911 | - $param=$val['param']; |
|
| 5912 | - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 5913 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
|
| 5914 | - {
|
|
| 5915 | - $type='link'; |
|
| 5916 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5917 | - } |
|
| 5918 | - $langfile=$val['langfile']; |
|
| 5919 | - $list=$val['list']; |
|
| 5920 | - $help=$val['help']; |
|
| 5921 | - $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) |
|
| 5922 | - |
|
| 5923 | - if ($hidden) return ''; |
|
| 5924 | - |
|
| 5925 | - // If field is a computed field, value must become result of compute |
|
| 5926 | - if ($computed) |
|
| 5927 | - {
|
|
| 5928 | - // Make the eval of compute string |
|
| 5929 | - //var_dump($computed); |
|
| 5930 | - $value = dol_eval($computed, 1, 0); |
|
| 5931 | - } |
|
| 5932 | - |
|
| 5933 | - if (empty($showsize)) |
|
| 5934 | - {
|
|
| 5935 | - if ($type == 'date') |
|
| 5936 | - {
|
|
| 5937 | - //$showsize=10; |
|
| 5938 | - $showsize = 'minwidth100imp'; |
|
| 5939 | - } |
|
| 5940 | - elseif ($type == 'datetime') |
|
| 5941 | - {
|
|
| 5942 | - //$showsize=19; |
|
| 5943 | - $showsize = 'minwidth200imp'; |
|
| 5944 | - } |
|
| 5945 | - elseif (in_array($type,array('int','double','price')))
|
|
| 5946 | - {
|
|
| 5947 | - //$showsize=10; |
|
| 5948 | - $showsize = 'maxwidth75'; |
|
| 5949 | - } |
|
| 5950 | - elseif ($type == 'url') |
|
| 5951 | - {
|
|
| 5952 | - $showsize='minwidth400'; |
|
| 5953 | - } |
|
| 5954 | - elseif ($type == 'boolean') |
|
| 5955 | - {
|
|
| 5956 | - $showsize=''; |
|
| 5957 | - } |
|
| 5958 | - else |
|
| 5959 | - {
|
|
| 5960 | - if (round($size) < 12) |
|
| 5961 | - {
|
|
| 5962 | - $showsize = 'minwidth100'; |
|
| 5963 | - } |
|
| 5964 | - else if (round($size) <= 48) |
|
| 5965 | - {
|
|
| 5966 | - $showsize = 'minwidth200'; |
|
| 5967 | - } |
|
| 5968 | - else |
|
| 5969 | - {
|
|
| 5970 | - //$showsize=48; |
|
| 5971 | - $showsize = 'minwidth400'; |
|
| 5972 | - } |
|
| 5973 | - } |
|
| 5974 | - } |
|
| 5975 | - |
|
| 5976 | - // Format output value differently according to properties of field |
|
| 5977 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5978 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5979 | - elseif ($type == 'date') |
|
| 5980 | - {
|
|
| 5981 | - if(! empty($value)) {
|
|
| 5982 | - $value=dol_print_date($value,'day'); |
|
| 5983 | - } else {
|
|
| 5984 | - $value=''; |
|
| 5985 | - } |
|
| 5986 | - } |
|
| 5987 | - elseif ($type == 'datetime') |
|
| 5988 | - {
|
|
| 5989 | - if(! empty($value)) {
|
|
| 5990 | - $value=dol_print_date($value,'dayhour'); |
|
| 5991 | - } else {
|
|
| 5992 | - $value=''; |
|
| 5993 | - } |
|
| 5994 | - } |
|
| 5995 | - elseif ($type == 'double') |
|
| 5996 | - {
|
|
| 5997 | - if (!empty($value)) {
|
|
| 5998 | - $value=price($value); |
|
| 5999 | - } |
|
| 6000 | - } |
|
| 6001 | - elseif ($type == 'boolean') |
|
| 6002 | - {
|
|
| 6003 | - $checked=''; |
|
| 6004 | - if (!empty($value)) {
|
|
| 6005 | - $checked=' checked '; |
|
| 6006 | - } |
|
| 6007 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 6008 | - } |
|
| 6009 | - elseif ($type == 'mail') |
|
| 6010 | - {
|
|
| 6011 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 6012 | - } |
|
| 6013 | - elseif ($type == 'url') |
|
| 6014 | - {
|
|
| 6015 | - $value=dol_print_url($value,'_blank',32,1); |
|
| 6016 | - } |
|
| 6017 | - elseif ($type == 'phone') |
|
| 6018 | - {
|
|
| 6019 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6020 | - } |
|
| 6021 | - elseif ($type == 'price') |
|
| 6022 | - {
|
|
| 6023 | - $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
| 6024 | - } |
|
| 6025 | - elseif ($type == 'select') |
|
| 6026 | - {
|
|
| 6027 | - $value=$param['options'][$value]; |
|
| 6028 | - } |
|
| 6029 | - elseif ($type == 'sellist') |
|
| 6030 | - {
|
|
| 6031 | - $param_list=array_keys($param['options']); |
|
| 6032 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6033 | - |
|
| 6034 | - $selectkey="rowid"; |
|
| 6035 | - $keyList='rowid'; |
|
| 6036 | - |
|
| 6037 | - if (count($InfoFieldList)>=3) |
|
| 6038 | - {
|
|
| 6039 | - $selectkey = $InfoFieldList[2]; |
|
| 6040 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 6041 | - } |
|
| 6042 | - |
|
| 6043 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6044 | - if(is_array($fields_label)) {
|
|
| 6045 | - $keyList .=', '; |
|
| 6046 | - $keyList .= implode(', ', $fields_label);
|
|
| 6047 | - } |
|
| 6048 | - |
|
| 6049 | - $sql = 'SELECT '.$keyList; |
|
| 6050 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 6051 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 6052 | - {
|
|
| 6053 | - $sql.= ' as main'; |
|
| 6054 | - } |
|
| 6055 | - if ($selectkey=='rowid' && empty($value)) {
|
|
| 6056 | - $sql.= " WHERE ".$selectkey."=0"; |
|
| 6057 | - } elseif ($selectkey=='rowid') {
|
|
| 6058 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6059 | - }else {
|
|
| 6060 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6061 | - } |
|
| 6062 | - |
|
| 6063 | - //$sql.= ' AND entity = '.$conf->entity; |
|
| 6064 | - |
|
| 6065 | - dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
| 6066 | - $resql = $this->db->query($sql); |
|
| 6067 | - if ($resql) |
|
| 6068 | - {
|
|
| 6069 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
| 6493 | + $buyPrice = 0; |
|
| 6494 | + |
|
| 6495 | + if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false |
|
| 6496 | + {
|
|
| 6497 | + $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
| 6498 | + } |
|
| 6499 | + else |
|
| 6500 | + {
|
|
| 6501 | + // Get cost price for margin calculation |
|
| 6502 | + if (! empty($fk_product)) |
|
| 6503 | + {
|
|
| 6504 | + if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
|
| 6505 | + {
|
|
| 6506 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6507 | + $product = new Product($this->db); |
|
| 6508 | + $result = $product->fetch($fk_product); |
|
| 6509 | + if ($result <= 0) |
|
| 6510 | + {
|
|
| 6511 | + $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6512 | + return -1; |
|
| 6513 | + } |
|
| 6514 | + if ($product->cost_price > 0) |
|
| 6515 | + {
|
|
| 6516 | + $buyPrice = $product->cost_price; |
|
| 6517 | + } |
|
| 6518 | + else if ($product->pmp > 0) |
|
| 6519 | + {
|
|
| 6520 | + $buyPrice = $product->pmp; |
|
| 6521 | + } |
|
| 6522 | + } |
|
| 6523 | + else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
| 6524 | + {
|
|
| 6525 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6526 | + $product = new Product($this->db); |
|
| 6527 | + $result = $product->fetch($fk_product); |
|
| 6528 | + if ($result <= 0) |
|
| 6529 | + {
|
|
| 6530 | + $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6531 | + return -1; |
|
| 6532 | + } |
|
| 6533 | + if ($product->pmp > 0) |
|
| 6534 | + {
|
|
| 6535 | + $buyPrice = $product->pmp; |
|
| 6536 | + } |
|
| 6537 | + } |
|
| 6538 | + |
|
| 6539 | + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice')))
|
|
| 6540 | + {
|
|
| 6541 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
| 6542 | + $productFournisseur = new ProductFournisseur($this->db); |
|
| 6543 | + if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
|
| 6544 | + {
|
|
| 6545 | + $buyPrice = $productFournisseur->fourn_unitprice; |
|
| 6546 | + } |
|
| 6547 | + else if ($result < 0) |
|
| 6548 | + {
|
|
| 6549 | + $this->errors[] = $productFournisseur->error; |
|
| 6550 | + return -2; |
|
| 6551 | + } |
|
| 6552 | + } |
|
| 6553 | + } |
|
| 6554 | + } |
|
| 6555 | + return $buyPrice; |
|
| 6556 | + } |
|
| 6557 | + |
|
| 6558 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 6559 | + /** |
|
| 6560 | + * Show photos of an object (nbmax maximum), into several columns |
|
| 6561 | + * |
|
| 6562 | + * @param string $modulepart 'product', 'ticket', ... |
|
| 6563 | + * @param string $sdir Directory to scan (full absolute path) |
|
| 6564 | + * @param int $size 0=original size, 1='small' use thumbnail if possible |
|
| 6565 | + * @param int $nbmax Nombre maximum de photos (0=pas de max) |
|
| 6566 | + * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. |
|
| 6567 | + * @param int $showfilename 1=Show filename |
|
| 6568 | + * @param int $showaction 1=Show icon with action links (resize, delete) |
|
| 6569 | + * @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image. |
|
| 6570 | + * @param int $maxWidth Max width of original image when size='small' |
|
| 6571 | + * @param int $nolink Do not add a href link to view enlarged imaged into a new tab |
|
| 6572 | + * @param int $notitle Do not add title tag on image |
|
| 6573 | + * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
|
| 6574 | + * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
|
| 6575 | + */ |
|
| 6576 | + function show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0) |
|
| 6577 | + {
|
|
| 6578 | + // phpcs:enable |
|
| 6579 | + global $conf,$user,$langs; |
|
| 6580 | + |
|
| 6581 | + include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
| 6582 | + include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
| 6583 | + |
|
| 6584 | + $sortfield='position_name'; |
|
| 6585 | + $sortorder='asc'; |
|
| 6586 | + |
|
| 6587 | + $dir = $sdir . '/'; |
|
| 6588 | + $pdir = '/'; |
|
| 6589 | + if ($modulepart == 'ticket') |
|
| 6590 | + {
|
|
| 6591 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6592 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6593 | + } |
|
| 6594 | + else |
|
| 6595 | + {
|
|
| 6596 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6597 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6598 | + } |
|
| 6599 | + |
|
| 6600 | + // For backward compatibility |
|
| 6601 | + if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
| 6602 | + {
|
|
| 6603 | + $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6604 | + $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6605 | + } |
|
| 6606 | + |
|
| 6607 | + // Defined relative dir to DOL_DATA_ROOT |
|
| 6608 | + $relativedir = ''; |
|
| 6609 | + if ($dir) |
|
| 6610 | + {
|
|
| 6611 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
|
| 6612 | + $relativedir = preg_replace('/^[\\/]/','',$relativedir);
|
|
| 6613 | + $relativedir = preg_replace('/[\\/]$/','',$relativedir);
|
|
| 6614 | + } |
|
| 6615 | + |
|
| 6616 | + $dirthumb = $dir.'thumbs/'; |
|
| 6617 | + $pdirthumb = $pdir.'thumbs/'; |
|
| 6618 | + |
|
| 6619 | + $return ='<!-- Photo -->'."\n"; |
|
| 6620 | + $nbphoto=0; |
|
| 6621 | + |
|
| 6622 | + $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6623 | + |
|
| 6624 | + /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
|
| 6625 | + {
|
|
| 6626 | + $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6627 | + $filearray=array_merge($filearray, $filearrayold); |
|
| 6628 | + }*/ |
|
| 6629 | + |
|
| 6630 | + completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
| 6631 | + |
|
| 6632 | + if (count($filearray)) |
|
| 6633 | + {
|
|
| 6634 | + if ($sortfield && $sortorder) |
|
| 6635 | + {
|
|
| 6636 | + $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6637 | + } |
|
| 6638 | + |
|
| 6639 | + foreach($filearray as $key => $val) |
|
| 6640 | + {
|
|
| 6641 | + $photo=''; |
|
| 6642 | + $file = $val['name']; |
|
| 6643 | + |
|
| 6644 | + //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
|
| 6645 | + |
|
| 6646 | + //if (dol_is_file($dir.$file) && image_format_supported($file) >= 0) |
|
| 6647 | + if (image_format_supported($file) >= 0) |
|
| 6648 | + {
|
|
| 6649 | + $nbphoto++; |
|
| 6650 | + $photo = $file; |
|
| 6651 | + $viewfilename = $file; |
|
| 6652 | + |
|
| 6653 | + if ($size == 1 || $size == 'small') { // Format vignette
|
|
| 6654 | + |
|
| 6655 | + // Find name of thumb file |
|
| 6656 | + $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6657 | + if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 6658 | + |
|
| 6659 | + // Get filesize of original file |
|
| 6660 | + $imgarray=dol_getImageSize($dir.$photo); |
|
| 6661 | + |
|
| 6662 | + if ($nbbyrow > 0) |
|
| 6663 | + {
|
|
| 6664 | + if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 6665 | + |
|
| 6666 | + if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 6667 | + $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
| 6668 | + } |
|
| 6669 | + else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 6670 | + |
|
| 6671 | + $return.= "\n"; |
|
| 6672 | + |
|
| 6673 | + $relativefile=preg_replace('/^\//', '', $pdir.$photo);
|
|
| 6674 | + if (empty($nolink)) |
|
| 6675 | + {
|
|
| 6676 | + $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
| 6677 | + if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6678 | + else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 6679 | + } |
|
| 6680 | + |
|
| 6681 | + // Show image (width height=$maxHeight) |
|
| 6682 | + // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
|
| 6683 | + $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
| 6684 | + $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
| 6685 | + if ($notitle) $alt=''; |
|
| 6686 | + |
|
| 6687 | + if ($usesharelink) |
|
| 6688 | + {
|
|
| 6689 | + if ($val['share']) |
|
| 6690 | + {
|
|
| 6691 | + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6692 | + {
|
|
| 6693 | + $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6694 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6695 | + } |
|
| 6696 | + else {
|
|
| 6697 | + $return.= '<!-- Show original file -->'; |
|
| 6698 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6699 | + } |
|
| 6700 | + } |
|
| 6701 | + else |
|
| 6702 | + {
|
|
| 6703 | + $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6704 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6705 | + } |
|
| 6706 | + } |
|
| 6707 | + else |
|
| 6708 | + {
|
|
| 6709 | + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6710 | + {
|
|
| 6711 | + $return.= '<!-- Show thumb -->'; |
|
| 6712 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6713 | + } |
|
| 6714 | + else {
|
|
| 6715 | + $return.= '<!-- Show original file -->'; |
|
| 6716 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6717 | + } |
|
| 6718 | + } |
|
| 6719 | + |
|
| 6720 | + if (empty($nolink)) $return.= '</a>'; |
|
| 6721 | + $return.="\n"; |
|
| 6722 | + |
|
| 6723 | + if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6724 | + if ($showaction) |
|
| 6725 | + {
|
|
| 6726 | + $return.= '<br>'; |
|
| 6727 | + // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
|
| 6728 | + if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
|
| 6729 | + {
|
|
| 6730 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>';
|
|
| 6731 | + } |
|
| 6732 | + // Special cas for product |
|
| 6733 | + if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6734 | + {
|
|
| 6735 | + // Link to resize |
|
| 6736 | + $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6737 | + |
|
| 6738 | + // Link to delete |
|
| 6739 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6740 | + $return.= img_delete().'</a>'; |
|
| 6741 | + } |
|
| 6742 | + } |
|
| 6743 | + $return.= "\n"; |
|
| 6744 | + |
|
| 6745 | + if ($nbbyrow > 0) |
|
| 6746 | + {
|
|
| 6747 | + $return.= '</td>'; |
|
| 6748 | + if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6749 | + } |
|
| 6750 | + else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6751 | + } |
|
| 6752 | + |
|
| 6753 | + if (empty($size)) { // Format origine
|
|
| 6754 | + $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6755 | + |
|
| 6756 | + if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6757 | + if ($showaction) |
|
| 6758 | + {
|
|
| 6759 | + // Special case for product |
|
| 6760 | + if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6761 | + {
|
|
| 6762 | + // Link to resize |
|
| 6763 | + $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6764 | + |
|
| 6765 | + // Link to delete |
|
| 6766 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6767 | + $return.= img_delete().'</a>'; |
|
| 6768 | + } |
|
| 6769 | + } |
|
| 6770 | + } |
|
| 6771 | + |
|
| 6772 | + // On continue ou on arrete de boucler ? |
|
| 6773 | + if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 6774 | + } |
|
| 6775 | + } |
|
| 6776 | + |
|
| 6777 | + if ($size==1 || $size=='small') |
|
| 6778 | + {
|
|
| 6779 | + if ($nbbyrow > 0) |
|
| 6780 | + {
|
|
| 6781 | + // Ferme tableau |
|
| 6782 | + while ($nbphoto % $nbbyrow) |
|
| 6783 | + {
|
|
| 6784 | + $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
| 6785 | + $nbphoto++; |
|
| 6786 | + } |
|
| 6787 | + |
|
| 6788 | + if ($nbphoto) $return.= '</table>'; |
|
| 6789 | + } |
|
| 6790 | + } |
|
| 6791 | + } |
|
| 6792 | + |
|
| 6793 | + $this->nbphoto = $nbphoto; |
|
| 6794 | + |
|
| 6795 | + return $return; |
|
| 6796 | + } |
|
| 6797 | + |
|
| 6798 | + |
|
| 6799 | + /** |
|
| 6800 | + * Function test if type is array |
|
| 6801 | + * |
|
| 6802 | + * @param array $info content informations of field |
|
| 6803 | + * @return bool |
|
| 6804 | + */ |
|
| 6805 | + protected function isArray($info) |
|
| 6806 | + {
|
|
| 6807 | + if(is_array($info)) |
|
| 6808 | + {
|
|
| 6809 | + if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6810 | + else return false; |
|
| 6811 | + } |
|
| 6812 | + else return false; |
|
| 6813 | + } |
|
| 6814 | + |
|
| 6815 | + /** |
|
| 6816 | + * Function test if type is null |
|
| 6817 | + * |
|
| 6818 | + * @param array $info content informations of field |
|
| 6819 | + * @return bool |
|
| 6820 | + */ |
|
| 6821 | + protected function isNull($info) |
|
| 6822 | + {
|
|
| 6823 | + if(is_array($info)) |
|
| 6824 | + {
|
|
| 6825 | + if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6826 | + else return false; |
|
| 6827 | + } |
|
| 6828 | + else return false; |
|
| 6829 | + } |
|
| 6830 | + |
|
| 6831 | + /** |
|
| 6832 | + * Function test if type is date |
|
| 6833 | + * |
|
| 6834 | + * @param array $info content informations of field |
|
| 6835 | + * @return bool |
|
| 6836 | + */ |
|
| 6837 | + public function isDate($info) |
|
| 6838 | + {
|
|
| 6839 | + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6840 | + else return false; |
|
| 6841 | + } |
|
| 6842 | + |
|
| 6843 | + /** |
|
| 6844 | + * Function test if type is integer |
|
| 6845 | + * |
|
| 6846 | + * @param array $info content informations of field |
|
| 6847 | + * @return bool |
|
| 6848 | + */ |
|
| 6849 | + public function isInt($info) |
|
| 6850 | + {
|
|
| 6851 | + if(is_array($info)) |
|
| 6852 | + {
|
|
| 6853 | + if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6854 | + else return false; |
|
| 6855 | + } |
|
| 6856 | + else return false; |
|
| 6857 | + } |
|
| 6858 | + |
|
| 6859 | + /** |
|
| 6860 | + * Function test if type is float |
|
| 6861 | + * |
|
| 6862 | + * @param array $info content informations of field |
|
| 6863 | + * @return bool |
|
| 6864 | + */ |
|
| 6865 | + public function isFloat($info) |
|
| 6866 | + {
|
|
| 6867 | + if(is_array($info)) |
|
| 6868 | + {
|
|
| 6869 | + if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
|
| 6870 | + else return false; |
|
| 6871 | + } |
|
| 6872 | + else return false; |
|
| 6873 | + } |
|
| 6874 | + |
|
| 6875 | + /** |
|
| 6876 | + * Function test if type is text |
|
| 6877 | + * |
|
| 6878 | + * @param array $info content informations of field |
|
| 6879 | + * @return bool |
|
| 6880 | + */ |
|
| 6881 | + public function isText($info) |
|
| 6882 | + {
|
|
| 6883 | + if(is_array($info)) |
|
| 6884 | + {
|
|
| 6885 | + if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6886 | + else return false; |
|
| 6887 | + } |
|
| 6888 | + else return false; |
|
| 6889 | + } |
|
| 6890 | + |
|
| 6891 | + /** |
|
| 6892 | + * Function test if is indexed |
|
| 6893 | + * |
|
| 6894 | + * @param array $info content informations of field |
|
| 6895 | + * @return bool |
|
| 6896 | + */ |
|
| 6897 | + protected function isIndex($info) |
|
| 6898 | + {
|
|
| 6899 | + if(is_array($info)) |
|
| 6900 | + {
|
|
| 6901 | + if(isset($info['index']) && $info['index']==true) return true; |
|
| 6902 | + else return false; |
|
| 6903 | + } |
|
| 6904 | + else return false; |
|
| 6905 | + } |
|
| 6906 | + |
|
| 6907 | + /** |
|
| 6908 | + * Function to prepare the values to insert. |
|
| 6909 | + * Note $this->${field} are set by the page that make the createCommon or the updateCommon.
|
|
| 6910 | + * |
|
| 6911 | + * @return array |
|
| 6912 | + */ |
|
| 6913 | + protected function setSaveQuery() |
|
| 6914 | + {
|
|
| 6915 | + global $conf; |
|
| 6916 | + |
|
| 6917 | + $queryarray=array(); |
|
| 6918 | + foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 6919 | + {
|
|
| 6920 | + // Depending on field type ('datetime', ...)
|
|
| 6921 | + if($this->isDate($info)) |
|
| 6922 | + {
|
|
| 6923 | + if(empty($this->{$field}))
|
|
| 6924 | + {
|
|
| 6925 | + $queryarray[$field] = null; |
|
| 6926 | + } |
|
| 6927 | + else |
|
| 6928 | + {
|
|
| 6929 | + $queryarray[$field] = $this->db->idate($this->{$field});
|
|
| 6930 | + } |
|
| 6931 | + } |
|
| 6932 | + else if($this->isArray($info)) |
|
| 6933 | + {
|
|
| 6934 | + if(! empty($this->{$field})) {
|
|
| 6935 | + if(! is_array($this->{$field})) {
|
|
| 6936 | + $this->{$field} = array($this->{$field});
|
|
| 6937 | + } |
|
| 6938 | + $queryarray[$field] = serialize($this->{$field});
|
|
| 6939 | + } else {
|
|
| 6940 | + $queryarray[$field] = null; |
|
| 6941 | + } |
|
| 6942 | + } |
|
| 6943 | + else if($this->isInt($info)) |
|
| 6944 | + {
|
|
| 6945 | + if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity;
|
|
| 6946 | + else |
|
| 6947 | + {
|
|
| 6948 | + $queryarray[$field] = (int) price2num($this->{$field});
|
|
| 6949 | + if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6950 | + } |
|
| 6951 | + } |
|
| 6952 | + else if($this->isFloat($info)) |
|
| 6953 | + {
|
|
| 6954 | + $queryarray[$field] = (double) price2num($this->{$field});
|
|
| 6955 | + if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6956 | + } |
|
| 6957 | + else |
|
| 6958 | + {
|
|
| 6959 | + $queryarray[$field] = $this->{$field};
|
|
| 6960 | + } |
|
| 6961 | + |
|
| 6962 | + if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6963 | + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6964 | + } |
|
| 6965 | + |
|
| 6966 | + return $queryarray; |
|
| 6967 | + } |
|
| 6968 | + |
|
| 6969 | + /** |
|
| 6970 | + * Function to load data from a SQL pointer into properties of current object $this |
|
| 6971 | + * |
|
| 6972 | + * @param stdClass $obj Contain data of object from database |
|
| 6973 | + * @return void |
|
| 6974 | + */ |
|
| 6975 | + protected function setVarsFromFetchObj(&$obj) |
|
| 6976 | + {
|
|
| 6977 | + foreach ($this->fields as $field => $info) |
|
| 6978 | + {
|
|
| 6979 | + if($this->isDate($info)) |
|
| 6980 | + {
|
|
| 6981 | + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6982 | + else $this->{$field} = strtotime($obj->{$field});
|
|
| 6983 | + } |
|
| 6984 | + elseif($this->isArray($info)) |
|
| 6985 | + {
|
|
| 6986 | + if(! empty($obj->{$field})) {
|
|
| 6987 | + $this->{$field} = @unserialize($obj->{$field});
|
|
| 6988 | + // Hack for data not in UTF8 |
|
| 6989 | + if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 6990 | + } else {
|
|
| 6991 | + $this->{$field} = array();
|
|
| 6992 | + } |
|
| 6993 | + } |
|
| 6994 | + elseif($this->isInt($info)) |
|
| 6995 | + {
|
|
| 6996 | + if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
|
| 6997 | + else $this->{$field} = (int) $obj->{$field};
|
|
| 6998 | + } |
|
| 6999 | + elseif($this->isFloat($info)) |
|
| 7000 | + {
|
|
| 7001 | + $this->{$field} = (double) $obj->{$field};
|
|
| 7002 | + } |
|
| 7003 | + elseif($this->isNull($info)) |
|
| 7004 | + {
|
|
| 7005 | + $val = $obj->{$field};
|
|
| 7006 | + // zero is not null |
|
| 7007 | + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
|
| 7008 | + } |
|
| 7009 | + else |
|
| 7010 | + {
|
|
| 7011 | + $this->{$field} = $obj->{$field};
|
|
| 7012 | + } |
|
| 7013 | + } |
|
| 7014 | + |
|
| 7015 | + // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
|
| 7016 | + if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7017 | + } |
|
| 7018 | + |
|
| 7019 | + /** |
|
| 7020 | + * Function to concat keys of fields |
|
| 7021 | + * |
|
| 7022 | + * @return string |
|
| 7023 | + */ |
|
| 7024 | + protected function getFieldList() |
|
| 7025 | + {
|
|
| 7026 | + $keys = array_keys($this->fields); |
|
| 7027 | + return implode(',', $keys);
|
|
| 7028 | + } |
|
| 7029 | + |
|
| 7030 | + /** |
|
| 7031 | + * Add quote to field value if necessary |
|
| 7032 | + * |
|
| 7033 | + * @param string|int $value Value to protect |
|
| 7034 | + * @param array $fieldsentry Properties of field |
|
| 7035 | + * @return string |
|
| 7036 | + */ |
|
| 7037 | + protected function quote($value, $fieldsentry) |
|
| 7038 | + {
|
|
| 7039 | + if (is_null($value)) return 'NULL'; |
|
| 7040 | + else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
|
|
| 7041 | + else return "'".$this->db->escape($value)."'"; |
|
| 7042 | + } |
|
| 7043 | + |
|
| 7044 | + |
|
| 7045 | + /** |
|
| 7046 | + * Create object into database |
|
| 7047 | + * |
|
| 7048 | + * @param User $user User that creates |
|
| 7049 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7050 | + * @return int <0 if KO, Id of created object if OK |
|
| 7051 | + */ |
|
| 7052 | + public function createCommon(User $user, $notrigger = false) |
|
| 7053 | + {
|
|
| 7054 | + global $langs; |
|
| 6070 | 7055 | |
| 6071 | - $obj = $this->db->fetch_object($resql); |
|
| 7056 | + $error = 0; |
|
| 6072 | 7057 | |
| 6073 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 6074 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 7058 | + $now=dol_now(); |
|
| 6075 | 7059 | |
| 6076 | - if(is_array($fields_label) && count($fields_label)>1) |
|
| 6077 | - {
|
|
| 6078 | - foreach ($fields_label as $field_toshow) |
|
| 6079 | - {
|
|
| 6080 | - $translabel=''; |
|
| 6081 | - if (!empty($obj->$field_toshow)) {
|
|
| 6082 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 6083 | - } |
|
| 6084 | - if ($translabel!=$field_toshow) {
|
|
| 6085 | - $value.=dol_trunc($translabel,18).' '; |
|
| 6086 | - }else {
|
|
| 6087 | - $value.=$obj->$field_toshow.' '; |
|
| 6088 | - } |
|
| 6089 | - } |
|
| 6090 | - } |
|
| 6091 | - else |
|
| 6092 | - {
|
|
| 6093 | - $translabel=''; |
|
| 6094 | - if (!empty($obj->{$InfoFieldList[1]})) {
|
|
| 6095 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6096 | - } |
|
| 6097 | - if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 6098 | - $value=dol_trunc($translabel,18); |
|
| 6099 | - }else {
|
|
| 6100 | - $value=$obj->{$InfoFieldList[1]};
|
|
| 6101 | - } |
|
| 6102 | - } |
|
| 6103 | - } |
|
| 6104 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6105 | - } |
|
| 6106 | - elseif ($type == 'radio') |
|
| 6107 | - {
|
|
| 6108 | - $value=$param['options'][$value]; |
|
| 6109 | - } |
|
| 6110 | - elseif ($type == 'checkbox') |
|
| 6111 | - {
|
|
| 6112 | - $value_arr=explode(',',$value);
|
|
| 6113 | - $value=''; |
|
| 6114 | - if (is_array($value_arr) && count($value_arr)>0) |
|
| 6115 | - {
|
|
| 6116 | - foreach ($value_arr as $keyval=>$valueval) {
|
|
| 6117 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6118 | - } |
|
| 6119 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6120 | - } |
|
| 6121 | - } |
|
| 6122 | - elseif ($type == 'chkbxlst') |
|
| 6123 | - {
|
|
| 6124 | - $value_arr = explode(',', $value);
|
|
| 6125 | - |
|
| 6126 | - $param_list = array_keys($param['options']); |
|
| 6127 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6128 | - |
|
| 6129 | - $selectkey = "rowid"; |
|
| 6130 | - $keyList = 'rowid'; |
|
| 6131 | - |
|
| 6132 | - if (count($InfoFieldList) >= 3) {
|
|
| 6133 | - $selectkey = $InfoFieldList[2]; |
|
| 6134 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 6135 | - } |
|
| 6136 | - |
|
| 6137 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6138 | - if (is_array($fields_label)) {
|
|
| 6139 | - $keyList .= ', '; |
|
| 6140 | - $keyList .= implode(', ', $fields_label);
|
|
| 6141 | - } |
|
| 6142 | - |
|
| 6143 | - $sql = 'SELECT ' . $keyList; |
|
| 6144 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 6145 | - if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 6146 | - $sql .= ' as main'; |
|
| 6147 | - } |
|
| 6148 | - // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6149 | - // $sql.= ' AND entity = '.$conf->entity; |
|
| 6150 | - |
|
| 6151 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 6152 | - $resql = $this->db->query($sql); |
|
| 6153 | - if ($resql) {
|
|
| 6154 | - $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 6155 | - $toprint=array(); |
|
| 6156 | - while ( $obj = $this->db->fetch_object($resql) ) {
|
|
| 6157 | - |
|
| 6158 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 6159 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6160 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 6161 | - if (is_array($fields_label) && count($fields_label) > 1) {
|
|
| 6162 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 6163 | - $translabel = ''; |
|
| 6164 | - if (! empty($obj->$field_toshow)) {
|
|
| 6165 | - $translabel = $langs->trans($obj->$field_toshow); |
|
| 6166 | - } |
|
| 6167 | - if ($translabel != $field_toshow) {
|
|
| 6168 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6169 | - } else {
|
|
| 6170 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 6171 | - } |
|
| 6172 | - } |
|
| 6173 | - } else {
|
|
| 6174 | - $translabel = ''; |
|
| 6175 | - if (! empty($obj->{$InfoFieldList[1]})) {
|
|
| 6176 | - $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6177 | - } |
|
| 6178 | - if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 6179 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6180 | - } else {
|
|
| 6181 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
|
|
| 6182 | - } |
|
| 6183 | - } |
|
| 6184 | - } |
|
| 6185 | - } |
|
| 6186 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6187 | - } else {
|
|
| 6188 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 6189 | - } |
|
| 6190 | - } |
|
| 6191 | - elseif ($type == 'link') |
|
| 6192 | - {
|
|
| 6193 | - $out=''; |
|
| 6194 | - |
|
| 6195 | - // only if something to display (perf) |
|
| 6196 | - if ($value) |
|
| 6197 | - {
|
|
| 6198 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 7060 | + $fieldvalues = $this->setSaveQuery(); |
|
| 7061 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7062 | + if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7063 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 6199 | 7064 | |
| 6200 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6201 | - $classname=$InfoFieldList[0]; |
|
| 6202 | - $classpath=$InfoFieldList[1]; |
|
| 6203 | - $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6204 | - if (! empty($classpath)) |
|
| 6205 | - {
|
|
| 6206 | - dol_include_once($InfoFieldList[1]); |
|
| 6207 | - if ($classname && class_exists($classname)) |
|
| 6208 | - {
|
|
| 6209 | - $object = new $classname($this->db); |
|
| 6210 | - $object->fetch($value); |
|
| 6211 | - $value=$object->getNomUrl($getnomurlparam); |
|
| 6212 | - } |
|
| 6213 | - } |
|
| 6214 | - else |
|
| 6215 | - {
|
|
| 6216 | - dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 6217 | - return 'Error bad setup of extrafield'; |
|
| 6218 | - } |
|
| 6219 | - } |
|
| 6220 | - else $value=''; |
|
| 6221 | - } |
|
| 6222 | - elseif ($type == 'text' || $type == 'html') |
|
| 6223 | - {
|
|
| 6224 | - $value=dol_htmlentitiesbr($value); |
|
| 6225 | - } |
|
| 6226 | - elseif ($type == 'password') |
|
| 6227 | - {
|
|
| 6228 | - $value=preg_replace('/./i','*',$value);
|
|
| 6229 | - } |
|
| 6230 | - elseif ($type == 'array') |
|
| 6231 | - {
|
|
| 6232 | - $value = implode('<br>', $value);
|
|
| 6233 | - } |
|
| 6234 | - |
|
| 6235 | - //print $type.'-'.$size; |
|
| 6236 | - $out=$value; |
|
| 6237 | - |
|
| 6238 | - return $out; |
|
| 6239 | - } |
|
| 6240 | - |
|
| 6241 | - |
|
| 6242 | - /** |
|
| 6243 | - * Function to show lines of extrafields with output datas |
|
| 6244 | - * |
|
| 6245 | - * @param Extrafields $extrafields Extrafield Object |
|
| 6246 | - * @param string $mode Show output (view) or input (edit) for extrafield |
|
| 6247 | - * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
|
|
| 6248 | - * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) |
|
| 6249 | - * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) |
|
| 6250 | - * @param string $onetrtd All fields in same tr td |
|
| 6251 | - * @return string |
|
| 6252 | - */ |
|
| 6253 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
| 6254 | - {
|
|
| 6255 | - global $db, $conf, $langs, $action, $form; |
|
| 6256 | - |
|
| 6257 | - if (! is_object($form)) $form=new Form($db); |
|
| 6258 | - |
|
| 6259 | - $out = ''; |
|
| 6260 | - |
|
| 6261 | - if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) |
|
| 6262 | - {
|
|
| 6263 | - $out .= "\n"; |
|
| 6264 | - $out .= '<!-- showOptionalsInput --> '; |
|
| 6265 | - $out .= "\n"; |
|
| 6266 | - |
|
| 6267 | - $e = 0; |
|
| 6268 | - foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6269 | - {
|
|
| 6270 | - // Show only the key field in params |
|
| 6271 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 7065 | + $keys=array(); |
|
| 7066 | + $values = array(); |
|
| 7067 | + foreach ($fieldvalues as $k => $v) {
|
|
| 7068 | + $keys[$k] = $k; |
|
| 7069 | + $value = $this->fields[$k]; |
|
| 7070 | + $values[$k] = $this->quote($v, $value); |
|
| 7071 | + } |
|
| 6272 | 7072 | |
| 6273 | - $enabled = 1; |
|
| 6274 | - if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
|
| 6275 | - {
|
|
| 6276 | - $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1); |
|
| 6277 | - } |
|
| 7073 | + // Clean and check mandatory |
|
| 7074 | + foreach($keys as $key) |
|
| 7075 | + {
|
|
| 7076 | + // If field is an implicit foreign key field |
|
| 7077 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7078 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 6278 | 7079 | |
| 6279 | - $perms = 1; |
|
| 6280 | - if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) |
|
| 6281 | - {
|
|
| 6282 | - $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
|
| 6283 | - } |
|
| 7080 | + //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7081 | + if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
| 7082 | + {
|
|
| 7083 | + $error++; |
|
| 7084 | + $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7085 | + } |
|
| 6284 | 7086 | |
| 6285 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6286 | - if (empty($perms)) continue; |
|
| 7087 | + // If field is an implicit foreign key field |
|
| 7088 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7089 | + if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7090 | + } |
|
| 6287 | 7091 | |
| 6288 | - // Load language if required |
|
| 6289 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 7092 | + if ($error) return -1; |
|
| 6290 | 7093 | |
| 6291 | - $colspan='3'; |
|
| 6292 | - if (is_array($params) && count($params)>0) {
|
|
| 6293 | - if (array_key_exists('colspan',$params)) {
|
|
| 6294 | - $colspan=$params['colspan']; |
|
| 6295 | - } |
|
| 6296 | - } |
|
| 7094 | + $this->db->begin(); |
|
| 6297 | 7095 | |
| 6298 | - switch($mode) {
|
|
| 6299 | - case "view": |
|
| 6300 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 6301 | - break; |
|
| 6302 | - case "edit": |
|
| 6303 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6304 | - // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
|
|
| 6305 | - if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
|
| 6306 | - {
|
|
| 6307 | - if (is_array($getposttemp)) {
|
|
| 6308 | - // $getposttemp is an array but following code expects a comma separated string |
|
| 6309 | - $value = implode(",", $getposttemp);
|
|
| 6310 | - } else {
|
|
| 6311 | - $value = $getposttemp; |
|
| 6312 | - } |
|
| 6313 | - } else {
|
|
| 6314 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6315 | - } |
|
| 6316 | - //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
|
| 6317 | - break; |
|
| 6318 | - } |
|
| 7096 | + if (! $error) |
|
| 7097 | + {
|
|
| 7098 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7099 | + $sql.= ' ('.implode( ", ", $keys ).')';
|
|
| 7100 | + $sql.= ' VALUES ('.implode( ", ", $values ).')';
|
|
| 7101 | + |
|
| 7102 | + $res = $this->db->query($sql); |
|
| 7103 | + if ($res===false) {
|
|
| 7104 | + $error++; |
|
| 7105 | + $this->errors[] = $this->db->lasterror(); |
|
| 7106 | + } |
|
| 7107 | + } |
|
| 6319 | 7108 | |
| 6320 | - if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
|
| 6321 | - {
|
|
| 6322 | - $out .= $extrafields->showSeparator($key, $this); |
|
| 6323 | - } |
|
| 6324 | - else |
|
| 6325 | - {
|
|
| 6326 | - $csstyle=''; |
|
| 6327 | - $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6328 | - if (is_array($params) && count($params)>0) {
|
|
| 6329 | - if (array_key_exists('style',$params)) {
|
|
| 6330 | - $csstyle=$params['style']; |
|
| 6331 | - } |
|
| 6332 | - } |
|
| 7109 | + if (! $error) |
|
| 7110 | + {
|
|
| 7111 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 7112 | + } |
|
| 6333 | 7113 | |
| 6334 | - // add html5 elements |
|
| 6335 | - $domData = ' data-element="extrafield"'; |
|
| 6336 | - $domData .= ' data-targetelement="'.$this->element.'"'; |
|
| 6337 | - $domData .= ' data-targetid="'.$this->id.'"'; |
|
| 7114 | + // Create extrafields |
|
| 7115 | + if (! $error) |
|
| 7116 | + {
|
|
| 7117 | + $result=$this->insertExtraFields(); |
|
| 7118 | + if ($result < 0) $error++; |
|
| 7119 | + } |
|
| 6338 | 7120 | |
| 6339 | - $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
| 7121 | + // Triggers |
|
| 7122 | + if (! $error && ! $notrigger) |
|
| 7123 | + {
|
|
| 7124 | + // Call triggers |
|
| 7125 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 7126 | + if ($result < 0) { $error++; }
|
|
| 7127 | + // End call triggers |
|
| 7128 | + } |
|
| 6340 | 7129 | |
| 6341 | - $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
| 7130 | + // Commit or rollback |
|
| 7131 | + if ($error) {
|
|
| 7132 | + $this->db->rollback(); |
|
| 7133 | + return -1; |
|
| 7134 | + } else {
|
|
| 7135 | + $this->db->commit(); |
|
| 7136 | + return $this->id; |
|
| 7137 | + } |
|
| 7138 | + } |
|
| 6342 | 7139 | |
| 6343 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 6344 | - {
|
|
| 6345 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; }
|
|
| 6346 | - } |
|
| 6347 | 7140 | |
| 6348 | - if ($action == 'selectlines') { $colspan++; }
|
|
| 7141 | + /** |
|
| 7142 | + * Load object in memory from the database |
|
| 7143 | + * |
|
| 7144 | + * @param int $id Id object |
|
| 7145 | + * @param string $ref Ref |
|
| 7146 | + * @param string $morewhere More SQL filters (' AND ...')
|
|
| 7147 | + * @return int <0 if KO, 0 if not found, >0 if OK |
|
| 7148 | + */ |
|
| 7149 | + public function fetchCommon($id, $ref = null, $morewhere = '') |
|
| 7150 | + {
|
|
| 7151 | + if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 6349 | 7152 | |
| 6350 | - // Convert date into timestamp format (value in memory must be a timestamp) |
|
| 6351 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
|
| 6352 | - {
|
|
| 6353 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
| 6354 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6355 | - {
|
|
| 6356 | - $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6357 | - } |
|
| 6358 | - $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)):$datenotinstring; |
|
| 6359 | - } |
|
| 6360 | - // Convert float submited string into real php numeric (value in memory must be a php numeric) |
|
| 6361 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double')))
|
|
| 6362 | - {
|
|
| 6363 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
| 6364 | - } |
|
| 6365 | - |
|
| 6366 | - $labeltoshow = $langs->trans($label); |
|
| 6367 | - |
|
| 6368 | - $out .= '<td class="titlefield'; |
|
| 6369 | - if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6370 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6371 | - $out .= '">'; |
|
| 6372 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6373 | - else $out .= $labeltoshow; |
|
| 6374 | - $out .= '</td>'; |
|
| 6375 | - |
|
| 6376 | - $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
| 6377 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 6378 | - |
|
| 6379 | - switch($mode) {
|
|
| 6380 | - case "view": |
|
| 6381 | - $out .= $extrafields->showOutputField($key, $value); |
|
| 6382 | - break; |
|
| 6383 | - case "edit": |
|
| 6384 | - $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); |
|
| 6385 | - break; |
|
| 6386 | - } |
|
| 6387 | - |
|
| 6388 | - $out .= '</td>'; |
|
| 6389 | - |
|
| 6390 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6391 | - else $out .= '</tr>'; |
|
| 6392 | - $e++; |
|
| 6393 | - } |
|
| 6394 | - } |
|
| 6395 | - $out .= "\n"; |
|
| 6396 | - // Add code to manage list depending on others |
|
| 6397 | - if (! empty($conf->use_javascript_ajax)) {
|
|
| 6398 | - $out .= ' |
|
| 6399 | - <script type="text/javascript"> |
|
| 6400 | - jQuery(document).ready(function() {
|
|
| 6401 | - function showOptions(child_list, parent_list) |
|
| 6402 | - {
|
|
| 6403 | - var val = $("select[name=\"options_"+parent_list+"\"]").val();
|
|
| 6404 | - var parentVal = parent_list + ":" + val; |
|
| 6405 | - if(val > 0) {
|
|
| 6406 | - $("select[name=\""+child_list+"\"] option[parent]").hide();
|
|
| 6407 | - $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
|
|
| 6408 | - } else {
|
|
| 6409 | - $("select[name=\""+child_list+"\"] option").show();
|
|
| 6410 | - } |
|
| 6411 | - } |
|
| 6412 | - function setListDependencies() {
|
|
| 6413 | - jQuery("select option[parent]").parent().each(function() {
|
|
| 6414 | - var child_list = $(this).attr("name");
|
|
| 6415 | - var parent = $(this).find("option[parent]:first").attr("parent");
|
|
| 6416 | - var infos = parent.split(":");
|
|
| 6417 | - var parent_list = infos[0]; |
|
| 6418 | - $("select[name=\""+parent_list+"\"]").change(function() {
|
|
| 6419 | - showOptions(child_list, parent_list); |
|
| 6420 | - }); |
|
| 6421 | - }); |
|
| 6422 | - } |
|
| 7153 | + $sql = 'SELECT '.$this->getFieldList(); |
|
| 7154 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 6423 | 7155 | |
| 6424 | - setListDependencies(); |
|
| 6425 | - }); |
|
| 6426 | - </script>'."\n"; |
|
| 6427 | - $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
| 6428 | - } |
|
| 6429 | - } |
|
| 6430 | - return $out; |
|
| 6431 | - } |
|
| 6432 | - |
|
| 6433 | - |
|
| 6434 | - /** |
|
| 6435 | - * Returns the rights used for this class |
|
| 6436 | - * @return stdClass |
|
| 6437 | - */ |
|
| 6438 | - public function getRights() |
|
| 6439 | - {
|
|
| 6440 | - global $user; |
|
| 6441 | - |
|
| 6442 | - $element = $this->element; |
|
| 6443 | - if ($element == 'facturerec') $element='facture'; |
|
| 6444 | - |
|
| 6445 | - return $user->rights->{$element};
|
|
| 6446 | - } |
|
| 6447 | - |
|
| 6448 | - /** |
|
| 6449 | - * Function used to replace a thirdparty id with another one. |
|
| 6450 | - * This function is meant to be called from replaceThirdparty with the appropiate tables |
|
| 6451 | - * Column name fk_soc MUST be used to identify thirdparties |
|
| 6452 | - * |
|
| 6453 | - * @param DoliDB $db Database handler |
|
| 6454 | - * @param int $origin_id Old thirdparty id (the thirdparty to delete) |
|
| 6455 | - * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) |
|
| 6456 | - * @param string[] $tables Tables that need to be changed |
|
| 6457 | - * @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) |
|
| 6458 | - * @return bool True if success, False if error |
|
| 6459 | - */ |
|
| 6460 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6461 | - {
|
|
| 6462 | - foreach ($tables as $table) |
|
| 6463 | - {
|
|
| 6464 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
| 6465 | - |
|
| 6466 | - if (! $db->query($sql)) |
|
| 6467 | - {
|
|
| 6468 | - 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. |
|
| 6469 | - //$this->errors = $db->lasterror(); |
|
| 6470 | - return false; |
|
| 6471 | - } |
|
| 6472 | - } |
|
| 6473 | - |
|
| 6474 | - return true; |
|
| 6475 | - } |
|
| 6476 | - |
|
| 6477 | - /** |
|
| 6478 | - * Get buy price to use for margin calculation. This function is called when buy price is unknown. |
|
| 6479 | - * Set buy price = sell price if ForceBuyingPriceIfNull configured, |
|
| 6480 | - * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice |
|
| 6481 | - * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice |
|
| 6482 | - * else set min buy price as buy price |
|
| 6483 | - * |
|
| 6484 | - * @param float $unitPrice Product unit price |
|
| 6485 | - * @param float $discountPercent Line discount percent |
|
| 6486 | - * @param int $fk_product Product id |
|
| 6487 | - * @return float <0 if KO, buyprice if OK |
|
| 6488 | - */ |
|
| 6489 | - public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) |
|
| 6490 | - {
|
|
| 6491 | - global $conf; |
|
| 6492 | - |
|
| 6493 | - $buyPrice = 0; |
|
| 6494 | - |
|
| 6495 | - if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false |
|
| 6496 | - {
|
|
| 6497 | - $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
| 6498 | - } |
|
| 6499 | - else |
|
| 6500 | - {
|
|
| 6501 | - // Get cost price for margin calculation |
|
| 6502 | - if (! empty($fk_product)) |
|
| 6503 | - {
|
|
| 6504 | - if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
|
| 6505 | - {
|
|
| 6506 | - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6507 | - $product = new Product($this->db); |
|
| 6508 | - $result = $product->fetch($fk_product); |
|
| 6509 | - if ($result <= 0) |
|
| 6510 | - {
|
|
| 6511 | - $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6512 | - return -1; |
|
| 6513 | - } |
|
| 6514 | - if ($product->cost_price > 0) |
|
| 6515 | - {
|
|
| 6516 | - $buyPrice = $product->cost_price; |
|
| 6517 | - } |
|
| 6518 | - else if ($product->pmp > 0) |
|
| 6519 | - {
|
|
| 6520 | - $buyPrice = $product->pmp; |
|
| 6521 | - } |
|
| 6522 | - } |
|
| 6523 | - else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
| 6524 | - {
|
|
| 6525 | - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6526 | - $product = new Product($this->db); |
|
| 6527 | - $result = $product->fetch($fk_product); |
|
| 6528 | - if ($result <= 0) |
|
| 6529 | - {
|
|
| 6530 | - $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6531 | - return -1; |
|
| 6532 | - } |
|
| 6533 | - if ($product->pmp > 0) |
|
| 6534 | - {
|
|
| 6535 | - $buyPrice = $product->pmp; |
|
| 6536 | - } |
|
| 6537 | - } |
|
| 7156 | + if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7157 | + elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7158 | + else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7159 | + if ($morewhere) $sql.= $morewhere; |
|
| 7160 | + $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 6538 | 7161 | |
| 6539 | - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice')))
|
|
| 6540 | - {
|
|
| 6541 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
| 6542 | - $productFournisseur = new ProductFournisseur($this->db); |
|
| 6543 | - if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
|
| 6544 | - {
|
|
| 6545 | - $buyPrice = $productFournisseur->fourn_unitprice; |
|
| 6546 | - } |
|
| 6547 | - else if ($result < 0) |
|
| 6548 | - {
|
|
| 6549 | - $this->errors[] = $productFournisseur->error; |
|
| 6550 | - return -2; |
|
| 6551 | - } |
|
| 6552 | - } |
|
| 6553 | - } |
|
| 6554 | - } |
|
| 6555 | - return $buyPrice; |
|
| 6556 | - } |
|
| 7162 | + $res = $this->db->query($sql); |
|
| 7163 | + if ($res) |
|
| 7164 | + {
|
|
| 7165 | + $obj = $this->db->fetch_object($res); |
|
| 7166 | + if ($obj) |
|
| 7167 | + {
|
|
| 7168 | + $this->setVarsFromFetchObj($obj); |
|
| 7169 | + return $this->id; |
|
| 7170 | + } |
|
| 7171 | + else |
|
| 7172 | + {
|
|
| 7173 | + return 0; |
|
| 7174 | + } |
|
| 7175 | + } |
|
| 7176 | + else |
|
| 7177 | + {
|
|
| 7178 | + $this->error = $this->db->lasterror(); |
|
| 7179 | + $this->errors[] = $this->error; |
|
| 7180 | + return -1; |
|
| 7181 | + } |
|
| 7182 | + } |
|
| 6557 | 7183 | |
| 6558 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 6559 | - /** |
|
| 6560 | - * Show photos of an object (nbmax maximum), into several columns |
|
| 6561 | - * |
|
| 6562 | - * @param string $modulepart 'product', 'ticket', ... |
|
| 6563 | - * @param string $sdir Directory to scan (full absolute path) |
|
| 6564 | - * @param int $size 0=original size, 1='small' use thumbnail if possible |
|
| 6565 | - * @param int $nbmax Nombre maximum de photos (0=pas de max) |
|
| 6566 | - * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. |
|
| 6567 | - * @param int $showfilename 1=Show filename |
|
| 6568 | - * @param int $showaction 1=Show icon with action links (resize, delete) |
|
| 6569 | - * @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image. |
|
| 6570 | - * @param int $maxWidth Max width of original image when size='small' |
|
| 6571 | - * @param int $nolink Do not add a href link to view enlarged imaged into a new tab |
|
| 6572 | - * @param int $notitle Do not add title tag on image |
|
| 6573 | - * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
|
| 6574 | - * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
|
| 6575 | - */ |
|
| 6576 | - function show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0) |
|
| 6577 | - {
|
|
| 6578 | - // phpcs:enable |
|
| 6579 | - global $conf,$user,$langs; |
|
| 6580 | - |
|
| 6581 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
| 6582 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
| 6583 | - |
|
| 6584 | - $sortfield='position_name'; |
|
| 6585 | - $sortorder='asc'; |
|
| 6586 | - |
|
| 6587 | - $dir = $sdir . '/'; |
|
| 6588 | - $pdir = '/'; |
|
| 6589 | - if ($modulepart == 'ticket') |
|
| 6590 | - {
|
|
| 6591 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6592 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6593 | - } |
|
| 6594 | - else |
|
| 6595 | - {
|
|
| 6596 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6597 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6598 | - } |
|
| 6599 | - |
|
| 6600 | - // For backward compatibility |
|
| 6601 | - if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
| 6602 | - {
|
|
| 6603 | - $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6604 | - $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6605 | - } |
|
| 6606 | - |
|
| 6607 | - // Defined relative dir to DOL_DATA_ROOT |
|
| 6608 | - $relativedir = ''; |
|
| 6609 | - if ($dir) |
|
| 6610 | - {
|
|
| 6611 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
|
| 6612 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir);
|
|
| 6613 | - $relativedir = preg_replace('/[\\/]$/','',$relativedir);
|
|
| 6614 | - } |
|
| 6615 | - |
|
| 6616 | - $dirthumb = $dir.'thumbs/'; |
|
| 6617 | - $pdirthumb = $pdir.'thumbs/'; |
|
| 6618 | - |
|
| 6619 | - $return ='<!-- Photo -->'."\n"; |
|
| 6620 | - $nbphoto=0; |
|
| 6621 | - |
|
| 6622 | - $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6623 | - |
|
| 6624 | - /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
|
| 6625 | - {
|
|
| 6626 | - $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6627 | - $filearray=array_merge($filearray, $filearrayold); |
|
| 6628 | - }*/ |
|
| 7184 | + /** |
|
| 7185 | + * Update object into database |
|
| 7186 | + * |
|
| 7187 | + * @param User $user User that modifies |
|
| 7188 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7189 | + * @return int <0 if KO, >0 if OK |
|
| 7190 | + */ |
|
| 7191 | + public function updateCommon(User $user, $notrigger = false) |
|
| 7192 | + {
|
|
| 7193 | + global $conf, $langs; |
|
| 6629 | 7194 | |
| 6630 | - completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
| 7195 | + $error = 0; |
|
| 6631 | 7196 | |
| 6632 | - if (count($filearray)) |
|
| 6633 | - {
|
|
| 6634 | - if ($sortfield && $sortorder) |
|
| 6635 | - {
|
|
| 6636 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6637 | - } |
|
| 7197 | + $now=dol_now(); |
|
| 6638 | 7198 | |
| 6639 | - foreach($filearray as $key => $val) |
|
| 6640 | - {
|
|
| 6641 | - $photo=''; |
|
| 6642 | - $file = $val['name']; |
|
| 7199 | + $fieldvalues = $this->setSaveQuery(); |
|
| 7200 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7201 | + if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7202 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 6643 | 7203 | |
| 6644 | - //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
|
| 7204 | + $keys=array(); |
|
| 7205 | + $values = array(); |
|
| 7206 | + foreach ($fieldvalues as $k => $v) {
|
|
| 7207 | + $keys[$k] = $k; |
|
| 7208 | + $value = $this->fields[$k]; |
|
| 7209 | + $values[$k] = $this->quote($v, $value); |
|
| 7210 | + $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
| 7211 | + } |
|
| 6645 | 7212 | |
| 6646 | - //if (dol_is_file($dir.$file) && image_format_supported($file) >= 0) |
|
| 6647 | - if (image_format_supported($file) >= 0) |
|
| 6648 | - {
|
|
| 6649 | - $nbphoto++; |
|
| 6650 | - $photo = $file; |
|
| 6651 | - $viewfilename = $file; |
|
| 7213 | + // Clean and check mandatory |
|
| 7214 | + foreach($keys as $key) |
|
| 7215 | + {
|
|
| 7216 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7217 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7218 | + |
|
| 7219 | + //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7220 | + /* |
|
| 7221 | + if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) |
|
| 7222 | + {
|
|
| 7223 | + $error++; |
|
| 7224 | + $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7225 | + }*/ |
|
| 7226 | + } |
|
| 6652 | 7227 | |
| 6653 | - if ($size == 1 || $size == 'small') { // Format vignette
|
|
| 7228 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 6654 | 7229 | |
| 6655 | - // Find name of thumb file |
|
| 6656 | - $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6657 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 7230 | + $this->db->begin(); |
|
| 7231 | + if (! $error) |
|
| 7232 | + {
|
|
| 7233 | + $res = $this->db->query($sql); |
|
| 7234 | + if ($res===false) |
|
| 7235 | + {
|
|
| 7236 | + $error++; |
|
| 7237 | + $this->errors[] = $this->db->lasterror(); |
|
| 7238 | + } |
|
| 7239 | + } |
|
| 6658 | 7240 | |
| 6659 | - // Get filesize of original file |
|
| 6660 | - $imgarray=dol_getImageSize($dir.$photo); |
|
| 7241 | + // Update extrafield |
|
| 7242 | + if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
| 7243 | + {
|
|
| 7244 | + $result=$this->insertExtraFields(); |
|
| 7245 | + if ($result < 0) |
|
| 7246 | + {
|
|
| 7247 | + $error++; |
|
| 7248 | + } |
|
| 7249 | + } |
|
| 6661 | 7250 | |
| 6662 | - if ($nbbyrow > 0) |
|
| 6663 | - {
|
|
| 6664 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7251 | + // Triggers |
|
| 7252 | + if (! $error && ! $notrigger) |
|
| 7253 | + {
|
|
| 7254 | + // Call triggers |
|
| 7255 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 7256 | + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
|
|
| 7257 | + // End call triggers |
|
| 7258 | + } |
|
| 6665 | 7259 | |
| 6666 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 6667 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
| 6668 | - } |
|
| 6669 | - else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 7260 | + // Commit or rollback |
|
| 7261 | + if ($error) {
|
|
| 7262 | + $this->db->rollback(); |
|
| 7263 | + return -1; |
|
| 7264 | + } else {
|
|
| 7265 | + $this->db->commit(); |
|
| 7266 | + return $this->id; |
|
| 7267 | + } |
|
| 7268 | + } |
|
| 6670 | 7269 | |
| 6671 | - $return.= "\n"; |
|
| 7270 | + /** |
|
| 7271 | + * Delete object in database |
|
| 7272 | + * |
|
| 7273 | + * @param User $user User that deletes |
|
| 7274 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7275 | + * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
|
| 7276 | + * @return int <=0 if KO, >0 if OK |
|
| 7277 | + */ |
|
| 7278 | + public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
| 7279 | + {
|
|
| 7280 | + $error=0; |
|
| 6672 | 7281 | |
| 6673 | - $relativefile=preg_replace('/^\//', '', $pdir.$photo);
|
|
| 6674 | - if (empty($nolink)) |
|
| 6675 | - {
|
|
| 6676 | - $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
| 6677 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6678 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 6679 | - } |
|
| 7282 | + $this->db->begin(); |
|
| 6680 | 7283 | |
| 6681 | - // Show image (width height=$maxHeight) |
|
| 6682 | - // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
|
| 6683 | - $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
| 6684 | - $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
| 6685 | - if ($notitle) $alt=''; |
|
| 6686 | - |
|
| 6687 | - if ($usesharelink) |
|
| 6688 | - {
|
|
| 6689 | - if ($val['share']) |
|
| 6690 | - {
|
|
| 6691 | - if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6692 | - {
|
|
| 6693 | - $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6694 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6695 | - } |
|
| 6696 | - else {
|
|
| 6697 | - $return.= '<!-- Show original file -->'; |
|
| 6698 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6699 | - } |
|
| 6700 | - } |
|
| 6701 | - else |
|
| 6702 | - {
|
|
| 6703 | - $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6704 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6705 | - } |
|
| 6706 | - } |
|
| 6707 | - else |
|
| 6708 | - {
|
|
| 6709 | - if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6710 | - {
|
|
| 6711 | - $return.= '<!-- Show thumb -->'; |
|
| 6712 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6713 | - } |
|
| 6714 | - else {
|
|
| 6715 | - $return.= '<!-- Show original file -->'; |
|
| 6716 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6717 | - } |
|
| 6718 | - } |
|
| 7284 | + if ($forcechilddeletion) |
|
| 7285 | + {
|
|
| 7286 | + foreach($this->childtables as $table) |
|
| 7287 | + {
|
|
| 7288 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 7289 | + $resql = $this->db->query($sql); |
|
| 7290 | + if (! $resql) |
|
| 7291 | + {
|
|
| 7292 | + $this->error=$this->db->lasterror(); |
|
| 7293 | + $this->errors[]=$this->error; |
|
| 7294 | + $this->db->rollback(); |
|
| 7295 | + return -1; |
|
| 7296 | + } |
|
| 7297 | + } |
|
| 7298 | + } |
|
| 7299 | + elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7300 | + {
|
|
| 7301 | + $objectisused = $this->isObjectUsed($this->id); |
|
| 7302 | + if (! empty($objectisused)) |
|
| 7303 | + {
|
|
| 7304 | + dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
| 7305 | + $this->error='ErrorRecordHasChildren'; |
|
| 7306 | + $this->errors[]=$this->error; |
|
| 7307 | + $this->db->rollback(); |
|
| 7308 | + return 0; |
|
| 7309 | + } |
|
| 7310 | + } |
|
| 6719 | 7311 | |
| 6720 | - if (empty($nolink)) $return.= '</a>'; |
|
| 6721 | - $return.="\n"; |
|
| 6722 | - |
|
| 6723 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6724 | - if ($showaction) |
|
| 6725 | - {
|
|
| 6726 | - $return.= '<br>'; |
|
| 6727 | - // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
|
| 6728 | - if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
|
| 6729 | - {
|
|
| 6730 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>';
|
|
| 6731 | - } |
|
| 6732 | - // Special cas for product |
|
| 6733 | - if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6734 | - {
|
|
| 6735 | - // Link to resize |
|
| 6736 | - $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6737 | - |
|
| 6738 | - // Link to delete |
|
| 6739 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6740 | - $return.= img_delete().'</a>'; |
|
| 6741 | - } |
|
| 6742 | - } |
|
| 6743 | - $return.= "\n"; |
|
| 7312 | + if (! $error) {
|
|
| 7313 | + if (! $notrigger) {
|
|
| 7314 | + // Call triggers |
|
| 7315 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7316 | + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
|
|
| 7317 | + // End call triggers |
|
| 7318 | + } |
|
| 7319 | + } |
|
| 6744 | 7320 | |
| 6745 | - if ($nbbyrow > 0) |
|
| 6746 | - {
|
|
| 6747 | - $return.= '</td>'; |
|
| 6748 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6749 | - } |
|
| 6750 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6751 | - } |
|
| 6752 | - |
|
| 6753 | - if (empty($size)) { // Format origine
|
|
| 6754 | - $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6755 | - |
|
| 6756 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6757 | - if ($showaction) |
|
| 6758 | - {
|
|
| 6759 | - // Special case for product |
|
| 6760 | - if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6761 | - {
|
|
| 6762 | - // Link to resize |
|
| 6763 | - $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6764 | - |
|
| 6765 | - // Link to delete |
|
| 6766 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6767 | - $return.= img_delete().'</a>'; |
|
| 6768 | - } |
|
| 6769 | - } |
|
| 6770 | - } |
|
| 7321 | + if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 7322 | + {
|
|
| 7323 | + $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 7324 | + $sql.= " WHERE fk_object=" . $this->id; |
|
| 6771 | 7325 | |
| 6772 | - // On continue ou on arrete de boucler ? |
|
| 6773 | - if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 6774 | - } |
|
| 6775 | - } |
|
| 7326 | + $resql = $this->db->query($sql); |
|
| 7327 | + if (! $resql) |
|
| 7328 | + {
|
|
| 7329 | + $this->errors[] = $this->db->lasterror(); |
|
| 7330 | + $error++; |
|
| 7331 | + } |
|
| 7332 | + } |
|
| 6776 | 7333 | |
| 6777 | - if ($size==1 || $size=='small') |
|
| 6778 | - {
|
|
| 6779 | - if ($nbbyrow > 0) |
|
| 6780 | - {
|
|
| 6781 | - // Ferme tableau |
|
| 6782 | - while ($nbphoto % $nbbyrow) |
|
| 6783 | - {
|
|
| 6784 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
| 6785 | - $nbphoto++; |
|
| 6786 | - } |
|
| 6787 | - |
|
| 6788 | - if ($nbphoto) $return.= '</table>'; |
|
| 6789 | - } |
|
| 6790 | - } |
|
| 6791 | - } |
|
| 6792 | - |
|
| 6793 | - $this->nbphoto = $nbphoto; |
|
| 6794 | - |
|
| 6795 | - return $return; |
|
| 6796 | - } |
|
| 6797 | - |
|
| 6798 | - |
|
| 6799 | - /** |
|
| 6800 | - * Function test if type is array |
|
| 6801 | - * |
|
| 6802 | - * @param array $info content informations of field |
|
| 6803 | - * @return bool |
|
| 6804 | - */ |
|
| 6805 | - protected function isArray($info) |
|
| 6806 | - {
|
|
| 6807 | - if(is_array($info)) |
|
| 6808 | - {
|
|
| 6809 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6810 | - else return false; |
|
| 6811 | - } |
|
| 6812 | - else return false; |
|
| 6813 | - } |
|
| 6814 | - |
|
| 6815 | - /** |
|
| 6816 | - * Function test if type is null |
|
| 6817 | - * |
|
| 6818 | - * @param array $info content informations of field |
|
| 6819 | - * @return bool |
|
| 6820 | - */ |
|
| 6821 | - protected function isNull($info) |
|
| 6822 | - {
|
|
| 6823 | - if(is_array($info)) |
|
| 6824 | - {
|
|
| 6825 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6826 | - else return false; |
|
| 6827 | - } |
|
| 6828 | - else return false; |
|
| 6829 | - } |
|
| 6830 | - |
|
| 6831 | - /** |
|
| 6832 | - * Function test if type is date |
|
| 6833 | - * |
|
| 6834 | - * @param array $info content informations of field |
|
| 6835 | - * @return bool |
|
| 6836 | - */ |
|
| 6837 | - public function isDate($info) |
|
| 6838 | - {
|
|
| 6839 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6840 | - else return false; |
|
| 6841 | - } |
|
| 6842 | - |
|
| 6843 | - /** |
|
| 6844 | - * Function test if type is integer |
|
| 6845 | - * |
|
| 6846 | - * @param array $info content informations of field |
|
| 6847 | - * @return bool |
|
| 6848 | - */ |
|
| 6849 | - public function isInt($info) |
|
| 6850 | - {
|
|
| 6851 | - if(is_array($info)) |
|
| 6852 | - {
|
|
| 6853 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6854 | - else return false; |
|
| 6855 | - } |
|
| 6856 | - else return false; |
|
| 6857 | - } |
|
| 6858 | - |
|
| 6859 | - /** |
|
| 6860 | - * Function test if type is float |
|
| 6861 | - * |
|
| 6862 | - * @param array $info content informations of field |
|
| 6863 | - * @return bool |
|
| 6864 | - */ |
|
| 6865 | - public function isFloat($info) |
|
| 6866 | - {
|
|
| 6867 | - if(is_array($info)) |
|
| 6868 | - {
|
|
| 6869 | - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
|
| 6870 | - else return false; |
|
| 6871 | - } |
|
| 6872 | - else return false; |
|
| 6873 | - } |
|
| 6874 | - |
|
| 6875 | - /** |
|
| 6876 | - * Function test if type is text |
|
| 6877 | - * |
|
| 6878 | - * @param array $info content informations of field |
|
| 6879 | - * @return bool |
|
| 6880 | - */ |
|
| 6881 | - public function isText($info) |
|
| 6882 | - {
|
|
| 6883 | - if(is_array($info)) |
|
| 6884 | - {
|
|
| 6885 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6886 | - else return false; |
|
| 6887 | - } |
|
| 6888 | - else return false; |
|
| 6889 | - } |
|
| 6890 | - |
|
| 6891 | - /** |
|
| 6892 | - * Function test if is indexed |
|
| 6893 | - * |
|
| 6894 | - * @param array $info content informations of field |
|
| 6895 | - * @return bool |
|
| 6896 | - */ |
|
| 6897 | - protected function isIndex($info) |
|
| 6898 | - {
|
|
| 6899 | - if(is_array($info)) |
|
| 6900 | - {
|
|
| 6901 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6902 | - else return false; |
|
| 6903 | - } |
|
| 6904 | - else return false; |
|
| 6905 | - } |
|
| 6906 | - |
|
| 6907 | - /** |
|
| 6908 | - * Function to prepare the values to insert. |
|
| 6909 | - * Note $this->${field} are set by the page that make the createCommon or the updateCommon.
|
|
| 6910 | - * |
|
| 6911 | - * @return array |
|
| 6912 | - */ |
|
| 6913 | - protected function setSaveQuery() |
|
| 6914 | - {
|
|
| 6915 | - global $conf; |
|
| 6916 | - |
|
| 6917 | - $queryarray=array(); |
|
| 6918 | - foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 6919 | - {
|
|
| 6920 | - // Depending on field type ('datetime', ...)
|
|
| 6921 | - if($this->isDate($info)) |
|
| 6922 | - {
|
|
| 6923 | - if(empty($this->{$field}))
|
|
| 6924 | - {
|
|
| 6925 | - $queryarray[$field] = null; |
|
| 6926 | - } |
|
| 6927 | - else |
|
| 6928 | - {
|
|
| 6929 | - $queryarray[$field] = $this->db->idate($this->{$field});
|
|
| 6930 | - } |
|
| 6931 | - } |
|
| 6932 | - else if($this->isArray($info)) |
|
| 6933 | - {
|
|
| 6934 | - if(! empty($this->{$field})) {
|
|
| 6935 | - if(! is_array($this->{$field})) {
|
|
| 6936 | - $this->{$field} = array($this->{$field});
|
|
| 6937 | - } |
|
| 6938 | - $queryarray[$field] = serialize($this->{$field});
|
|
| 6939 | - } else {
|
|
| 6940 | - $queryarray[$field] = null; |
|
| 6941 | - } |
|
| 6942 | - } |
|
| 6943 | - else if($this->isInt($info)) |
|
| 6944 | - {
|
|
| 6945 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity;
|
|
| 6946 | - else |
|
| 6947 | - {
|
|
| 6948 | - $queryarray[$field] = (int) price2num($this->{$field});
|
|
| 6949 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6950 | - } |
|
| 6951 | - } |
|
| 6952 | - else if($this->isFloat($info)) |
|
| 6953 | - {
|
|
| 6954 | - $queryarray[$field] = (double) price2num($this->{$field});
|
|
| 6955 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6956 | - } |
|
| 6957 | - else |
|
| 6958 | - {
|
|
| 6959 | - $queryarray[$field] = $this->{$field};
|
|
| 6960 | - } |
|
| 7334 | + if (! $error) |
|
| 7335 | + {
|
|
| 7336 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
| 6961 | 7337 | |
| 6962 | - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6963 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6964 | - } |
|
| 7338 | + $res = $this->db->query($sql); |
|
| 7339 | + if($res===false) {
|
|
| 7340 | + $error++; |
|
| 7341 | + $this->errors[] = $this->db->lasterror(); |
|
| 7342 | + } |
|
| 7343 | + } |
|
| 6965 | 7344 | |
| 6966 | - return $queryarray; |
|
| 6967 | - } |
|
| 7345 | + // Commit or rollback |
|
| 7346 | + if ($error) {
|
|
| 7347 | + $this->db->rollback(); |
|
| 7348 | + return -1; |
|
| 7349 | + } else {
|
|
| 7350 | + $this->db->commit(); |
|
| 7351 | + return 1; |
|
| 7352 | + } |
|
| 7353 | + } |
|
| 6968 | 7354 | |
| 6969 | - /** |
|
| 6970 | - * Function to load data from a SQL pointer into properties of current object $this |
|
| 6971 | - * |
|
| 6972 | - * @param stdClass $obj Contain data of object from database |
|
| 7355 | + /** |
|
| 7356 | + * Initialise object with example values |
|
| 7357 | + * Id must be 0 if object instance is a specimen |
|
| 7358 | + * |
|
| 6973 | 7359 | * @return void |
| 6974 | - */ |
|
| 6975 | - protected function setVarsFromFetchObj(&$obj) |
|
| 6976 | - {
|
|
| 6977 | - foreach ($this->fields as $field => $info) |
|
| 6978 | - {
|
|
| 6979 | - if($this->isDate($info)) |
|
| 6980 | - {
|
|
| 6981 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6982 | - else $this->{$field} = strtotime($obj->{$field});
|
|
| 6983 | - } |
|
| 6984 | - elseif($this->isArray($info)) |
|
| 6985 | - {
|
|
| 6986 | - if(! empty($obj->{$field})) {
|
|
| 6987 | - $this->{$field} = @unserialize($obj->{$field});
|
|
| 6988 | - // Hack for data not in UTF8 |
|
| 6989 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 6990 | - } else {
|
|
| 6991 | - $this->{$field} = array();
|
|
| 6992 | - } |
|
| 6993 | - } |
|
| 6994 | - elseif($this->isInt($info)) |
|
| 6995 | - {
|
|
| 6996 | - if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
|
| 6997 | - else $this->{$field} = (int) $obj->{$field};
|
|
| 6998 | - } |
|
| 6999 | - elseif($this->isFloat($info)) |
|
| 7000 | - {
|
|
| 7001 | - $this->{$field} = (double) $obj->{$field};
|
|
| 7002 | - } |
|
| 7003 | - elseif($this->isNull($info)) |
|
| 7004 | - {
|
|
| 7005 | - $val = $obj->{$field};
|
|
| 7006 | - // zero is not null |
|
| 7007 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
|
| 7008 | - } |
|
| 7009 | - else |
|
| 7010 | - {
|
|
| 7011 | - $this->{$field} = $obj->{$field};
|
|
| 7012 | - } |
|
| 7013 | - } |
|
| 7014 | - |
|
| 7015 | - // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
|
| 7016 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7017 | - } |
|
| 7018 | - |
|
| 7019 | - /** |
|
| 7020 | - * Function to concat keys of fields |
|
| 7021 | - * |
|
| 7022 | - * @return string |
|
| 7023 | - */ |
|
| 7024 | - protected function getFieldList() |
|
| 7025 | - {
|
|
| 7026 | - $keys = array_keys($this->fields); |
|
| 7027 | - return implode(',', $keys);
|
|
| 7028 | - } |
|
| 7029 | - |
|
| 7030 | - /** |
|
| 7031 | - * Add quote to field value if necessary |
|
| 7032 | - * |
|
| 7033 | - * @param string|int $value Value to protect |
|
| 7034 | - * @param array $fieldsentry Properties of field |
|
| 7035 | - * @return string |
|
| 7036 | - */ |
|
| 7037 | - protected function quote($value, $fieldsentry) |
|
| 7360 | + */ |
|
| 7361 | + public function initAsSpecimenCommon() |
|
| 7038 | 7362 | {
|
| 7039 | - if (is_null($value)) return 'NULL'; |
|
| 7040 | - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
|
|
| 7041 | - else return "'".$this->db->escape($value)."'"; |
|
| 7042 | - } |
|
| 7043 | - |
|
| 7044 | - |
|
| 7045 | - /** |
|
| 7046 | - * Create object into database |
|
| 7047 | - * |
|
| 7048 | - * @param User $user User that creates |
|
| 7049 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7050 | - * @return int <0 if KO, Id of created object if OK |
|
| 7051 | - */ |
|
| 7052 | - public function createCommon(User $user, $notrigger = false) |
|
| 7053 | - {
|
|
| 7054 | - global $langs; |
|
| 7055 | - |
|
| 7056 | - $error = 0; |
|
| 7057 | - |
|
| 7058 | - $now=dol_now(); |
|
| 7059 | - |
|
| 7060 | - $fieldvalues = $this->setSaveQuery(); |
|
| 7061 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7062 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7063 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 7064 | - |
|
| 7065 | - $keys=array(); |
|
| 7066 | - $values = array(); |
|
| 7067 | - foreach ($fieldvalues as $k => $v) {
|
|
| 7068 | - $keys[$k] = $k; |
|
| 7069 | - $value = $this->fields[$k]; |
|
| 7070 | - $values[$k] = $this->quote($v, $value); |
|
| 7071 | - } |
|
| 7072 | - |
|
| 7073 | - // Clean and check mandatory |
|
| 7074 | - foreach($keys as $key) |
|
| 7075 | - {
|
|
| 7076 | - // If field is an implicit foreign key field |
|
| 7077 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7078 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7079 | - |
|
| 7080 | - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7081 | - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
| 7082 | - {
|
|
| 7083 | - $error++; |
|
| 7084 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7085 | - } |
|
| 7086 | - |
|
| 7087 | - // If field is an implicit foreign key field |
|
| 7088 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7089 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7090 | - } |
|
| 7091 | - |
|
| 7092 | - if ($error) return -1; |
|
| 7093 | - |
|
| 7094 | - $this->db->begin(); |
|
| 7363 | + $this->id = 0; |
|
| 7095 | 7364 | |
| 7096 | - if (! $error) |
|
| 7097 | - {
|
|
| 7098 | - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7099 | - $sql.= ' ('.implode( ", ", $keys ).')';
|
|
| 7100 | - $sql.= ' VALUES ('.implode( ", ", $values ).')';
|
|
| 7365 | + // TODO... |
|
| 7366 | + } |
|
| 7101 | 7367 | |
| 7102 | - $res = $this->db->query($sql); |
|
| 7103 | - if ($res===false) {
|
|
| 7104 | - $error++; |
|
| 7105 | - $this->errors[] = $this->db->lasterror(); |
|
| 7106 | - } |
|
| 7107 | - } |
|
| 7108 | - |
|
| 7109 | - if (! $error) |
|
| 7110 | - {
|
|
| 7111 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 7112 | - } |
|
| 7113 | - |
|
| 7114 | - // Create extrafields |
|
| 7115 | - if (! $error) |
|
| 7116 | - {
|
|
| 7117 | - $result=$this->insertExtraFields(); |
|
| 7118 | - if ($result < 0) $error++; |
|
| 7119 | - } |
|
| 7120 | - |
|
| 7121 | - // Triggers |
|
| 7122 | - if (! $error && ! $notrigger) |
|
| 7123 | - {
|
|
| 7124 | - // Call triggers |
|
| 7125 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 7126 | - if ($result < 0) { $error++; }
|
|
| 7127 | - // End call triggers |
|
| 7128 | - } |
|
| 7129 | - |
|
| 7130 | - // Commit or rollback |
|
| 7131 | - if ($error) {
|
|
| 7132 | - $this->db->rollback(); |
|
| 7133 | - return -1; |
|
| 7134 | - } else {
|
|
| 7135 | - $this->db->commit(); |
|
| 7136 | - return $this->id; |
|
| 7137 | - } |
|
| 7138 | - } |
|
| 7139 | - |
|
| 7140 | - |
|
| 7141 | - /** |
|
| 7142 | - * Load object in memory from the database |
|
| 7143 | - * |
|
| 7144 | - * @param int $id Id object |
|
| 7145 | - * @param string $ref Ref |
|
| 7146 | - * @param string $morewhere More SQL filters (' AND ...')
|
|
| 7147 | - * @return int <0 if KO, 0 if not found, >0 if OK |
|
| 7148 | - */ |
|
| 7149 | - public function fetchCommon($id, $ref = null, $morewhere = '') |
|
| 7150 | - {
|
|
| 7151 | - if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 7152 | - |
|
| 7153 | - $sql = 'SELECT '.$this->getFieldList(); |
|
| 7154 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7155 | - |
|
| 7156 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7157 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7158 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7159 | - if ($morewhere) $sql.= $morewhere; |
|
| 7160 | - $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 7161 | - |
|
| 7162 | - $res = $this->db->query($sql); |
|
| 7163 | - if ($res) |
|
| 7164 | - {
|
|
| 7165 | - $obj = $this->db->fetch_object($res); |
|
| 7166 | - if ($obj) |
|
| 7167 | - {
|
|
| 7168 | - $this->setVarsFromFetchObj($obj); |
|
| 7169 | - return $this->id; |
|
| 7170 | - } |
|
| 7171 | - else |
|
| 7172 | - {
|
|
| 7173 | - return 0; |
|
| 7174 | - } |
|
| 7175 | - } |
|
| 7176 | - else |
|
| 7177 | - {
|
|
| 7178 | - $this->error = $this->db->lasterror(); |
|
| 7179 | - $this->errors[] = $this->error; |
|
| 7180 | - return -1; |
|
| 7181 | - } |
|
| 7182 | - } |
|
| 7183 | - |
|
| 7184 | - /** |
|
| 7185 | - * Update object into database |
|
| 7186 | - * |
|
| 7187 | - * @param User $user User that modifies |
|
| 7188 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7189 | - * @return int <0 if KO, >0 if OK |
|
| 7190 | - */ |
|
| 7191 | - public function updateCommon(User $user, $notrigger = false) |
|
| 7192 | - {
|
|
| 7193 | - global $conf, $langs; |
|
| 7194 | - |
|
| 7195 | - $error = 0; |
|
| 7196 | - |
|
| 7197 | - $now=dol_now(); |
|
| 7198 | - |
|
| 7199 | - $fieldvalues = $this->setSaveQuery(); |
|
| 7200 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7201 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7202 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 7203 | - |
|
| 7204 | - $keys=array(); |
|
| 7205 | - $values = array(); |
|
| 7206 | - foreach ($fieldvalues as $k => $v) {
|
|
| 7207 | - $keys[$k] = $k; |
|
| 7208 | - $value = $this->fields[$k]; |
|
| 7209 | - $values[$k] = $this->quote($v, $value); |
|
| 7210 | - $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
| 7211 | - } |
|
| 7212 | - |
|
| 7213 | - // Clean and check mandatory |
|
| 7214 | - foreach($keys as $key) |
|
| 7215 | - {
|
|
| 7216 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7217 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7218 | - |
|
| 7219 | - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7220 | - /* |
|
| 7221 | - if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) |
|
| 7222 | - {
|
|
| 7223 | - $error++; |
|
| 7224 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7225 | - }*/ |
|
| 7226 | - } |
|
| 7227 | 7368 | |
| 7228 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 7369 | + /* Part for comments */ |
|
| 7229 | 7370 | |
| 7230 | - $this->db->begin(); |
|
| 7231 | - if (! $error) |
|
| 7232 | - {
|
|
| 7233 | - $res = $this->db->query($sql); |
|
| 7234 | - if ($res===false) |
|
| 7235 | - {
|
|
| 7236 | - $error++; |
|
| 7237 | - $this->errors[] = $this->db->lasterror(); |
|
| 7238 | - } |
|
| 7239 | - } |
|
| 7240 | - |
|
| 7241 | - // Update extrafield |
|
| 7242 | - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
| 7243 | - {
|
|
| 7244 | - $result=$this->insertExtraFields(); |
|
| 7245 | - if ($result < 0) |
|
| 7246 | - {
|
|
| 7247 | - $error++; |
|
| 7248 | - } |
|
| 7249 | - } |
|
| 7250 | - |
|
| 7251 | - // Triggers |
|
| 7252 | - if (! $error && ! $notrigger) |
|
| 7253 | - {
|
|
| 7254 | - // Call triggers |
|
| 7255 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 7256 | - if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
|
|
| 7257 | - // End call triggers |
|
| 7258 | - } |
|
| 7259 | - |
|
| 7260 | - // Commit or rollback |
|
| 7261 | - if ($error) {
|
|
| 7262 | - $this->db->rollback(); |
|
| 7263 | - return -1; |
|
| 7264 | - } else {
|
|
| 7265 | - $this->db->commit(); |
|
| 7266 | - return $this->id; |
|
| 7267 | - } |
|
| 7268 | - } |
|
| 7269 | - |
|
| 7270 | - /** |
|
| 7271 | - * Delete object in database |
|
| 7272 | - * |
|
| 7273 | - * @param User $user User that deletes |
|
| 7274 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7275 | - * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
|
| 7276 | - * @return int <=0 if KO, >0 if OK |
|
| 7277 | - */ |
|
| 7278 | - public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
| 7279 | - {
|
|
| 7280 | - $error=0; |
|
| 7281 | - |
|
| 7282 | - $this->db->begin(); |
|
| 7283 | - |
|
| 7284 | - if ($forcechilddeletion) |
|
| 7285 | - {
|
|
| 7286 | - foreach($this->childtables as $table) |
|
| 7287 | - {
|
|
| 7288 | - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 7289 | - $resql = $this->db->query($sql); |
|
| 7290 | - if (! $resql) |
|
| 7291 | - {
|
|
| 7292 | - $this->error=$this->db->lasterror(); |
|
| 7293 | - $this->errors[]=$this->error; |
|
| 7294 | - $this->db->rollback(); |
|
| 7295 | - return -1; |
|
| 7296 | - } |
|
| 7297 | - } |
|
| 7298 | - } |
|
| 7299 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7300 | - {
|
|
| 7301 | - $objectisused = $this->isObjectUsed($this->id); |
|
| 7302 | - if (! empty($objectisused)) |
|
| 7303 | - {
|
|
| 7304 | - dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
| 7305 | - $this->error='ErrorRecordHasChildren'; |
|
| 7306 | - $this->errors[]=$this->error; |
|
| 7307 | - $this->db->rollback(); |
|
| 7308 | - return 0; |
|
| 7309 | - } |
|
| 7310 | - } |
|
| 7311 | - |
|
| 7312 | - if (! $error) {
|
|
| 7313 | - if (! $notrigger) {
|
|
| 7314 | - // Call triggers |
|
| 7315 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7316 | - if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
|
|
| 7317 | - // End call triggers |
|
| 7318 | - } |
|
| 7319 | - } |
|
| 7320 | - |
|
| 7321 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 7322 | - {
|
|
| 7323 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 7324 | - $sql.= " WHERE fk_object=" . $this->id; |
|
| 7325 | - |
|
| 7326 | - $resql = $this->db->query($sql); |
|
| 7327 | - if (! $resql) |
|
| 7328 | - {
|
|
| 7329 | - $this->errors[] = $this->db->lasterror(); |
|
| 7330 | - $error++; |
|
| 7331 | - } |
|
| 7332 | - } |
|
| 7371 | + /** |
|
| 7372 | + * Load comments linked with current task |
|
| 7373 | + * @return boolean 1 if ok |
|
| 7374 | + */ |
|
| 7375 | + public function fetchComments() |
|
| 7376 | + {
|
|
| 7377 | + require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
| 7333 | 7378 | |
| 7334 | - if (! $error) |
|
| 7335 | - {
|
|
| 7336 | - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
| 7379 | + $comment = new Comment($this->db); |
|
| 7380 | + $result=$comment->fetchAllFor($this->element, $this->id); |
|
| 7381 | + if ($result<0) {
|
|
| 7382 | + $this->errors=array_merge($this->errors, $comment->errors); |
|
| 7383 | + return -1; |
|
| 7384 | + } else {
|
|
| 7385 | + $this->comments = $comment->comments; |
|
| 7386 | + } |
|
| 7387 | + return count($this->comments); |
|
| 7388 | + } |
|
| 7337 | 7389 | |
| 7338 | - $res = $this->db->query($sql); |
|
| 7339 | - if($res===false) {
|
|
| 7340 | - $error++; |
|
| 7341 | - $this->errors[] = $this->db->lasterror(); |
|
| 7342 | - } |
|
| 7343 | - } |
|
| 7344 | - |
|
| 7345 | - // Commit or rollback |
|
| 7346 | - if ($error) {
|
|
| 7347 | - $this->db->rollback(); |
|
| 7348 | - return -1; |
|
| 7349 | - } else {
|
|
| 7350 | - $this->db->commit(); |
|
| 7351 | - return 1; |
|
| 7352 | - } |
|
| 7353 | - } |
|
| 7354 | - |
|
| 7355 | - /** |
|
| 7356 | - * Initialise object with example values |
|
| 7357 | - * Id must be 0 if object instance is a specimen |
|
| 7358 | - * |
|
| 7359 | - * @return void |
|
| 7360 | - */ |
|
| 7361 | - public function initAsSpecimenCommon() |
|
| 7362 | - {
|
|
| 7363 | - $this->id = 0; |
|
| 7364 | - |
|
| 7365 | - // TODO... |
|
| 7366 | - } |
|
| 7367 | - |
|
| 7368 | - |
|
| 7369 | - /* Part for comments */ |
|
| 7370 | - |
|
| 7371 | - /** |
|
| 7372 | - * Load comments linked with current task |
|
| 7373 | - * @return boolean 1 if ok |
|
| 7374 | - */ |
|
| 7375 | - public function fetchComments() |
|
| 7376 | - {
|
|
| 7377 | - require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
| 7378 | - |
|
| 7379 | - $comment = new Comment($this->db); |
|
| 7380 | - $result=$comment->fetchAllFor($this->element, $this->id); |
|
| 7381 | - if ($result<0) {
|
|
| 7382 | - $this->errors=array_merge($this->errors, $comment->errors); |
|
| 7383 | - return -1; |
|
| 7384 | - } else {
|
|
| 7385 | - $this->comments = $comment->comments; |
|
| 7386 | - } |
|
| 7387 | - return count($this->comments); |
|
| 7388 | - } |
|
| 7389 | - |
|
| 7390 | - /** |
|
| 7391 | - * Return nb comments already posted |
|
| 7392 | - * |
|
| 7393 | - * @return int |
|
| 7394 | - */ |
|
| 7395 | - public function getNbComments() |
|
| 7396 | - {
|
|
| 7397 | - return count($this->comments); |
|
| 7398 | - } |
|
| 7390 | + /** |
|
| 7391 | + * Return nb comments already posted |
|
| 7392 | + * |
|
| 7393 | + * @return int |
|
| 7394 | + */ |
|
| 7395 | + public function getNbComments() |
|
| 7396 | + {
|
|
| 7397 | + return count($this->comments); |
|
| 7398 | + } |
|
| 7399 | 7399 | |
| 7400 | 7400 | /** |
| 7401 | 7401 | * Trim object parameters |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | /** |
| 35 | 35 | * @var string[] Array of error strings |
| 36 | 36 | */ |
| 37 | - public $errors=array(); |
|
| 37 | + public $errors = array(); |
|
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | 40 | * @var string ID to identify managed object |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * @var int Name of subtable line |
| 51 | 51 | */ |
| 52 | - public $table_element_line=''; |
|
| 52 | + public $table_element_line = ''; |
|
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | 55 | * @var string Key value used to track if data is coming from import wizard |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | /** |
| 60 | 60 | * @var mixed Contains data to manage extrafields |
| 61 | 61 | */ |
| 62 | - public $array_options=array(); |
|
| 62 | + public $array_options = array(); |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | /** |
| 89 | 89 | * @var array<string,mixed> Can be used to pass information when only object is provided to method |
| 90 | 90 | */ |
| 91 | - public $context=array(); |
|
| 91 | + public $context = array(); |
|
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * @var string Contains canvas name if record is an alternative canvas record |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | * @var mixed Contains comments |
| 349 | 349 | * @see fetchComments() |
| 350 | 350 | */ |
| 351 | - public $comments=array(); |
|
| 351 | + public $comments = array(); |
|
| 352 | 352 | |
| 353 | 353 | /** |
| 354 | 354 | * @var int |
@@ -374,9 +374,9 @@ discard block |
||
| 374 | 374 | public $civility_id; |
| 375 | 375 | |
| 376 | 376 | // Dates |
| 377 | - public $date_creation; // Date creation |
|
| 378 | - public $date_validation; // Date validation |
|
| 379 | - public $date_modification; // Date last change (tms field) |
|
| 377 | + public $date_creation; // Date creation |
|
| 378 | + public $date_validation; // Date validation |
|
| 379 | + public $date_modification; // Date last change (tms field) |
|
| 380 | 380 | |
| 381 | 381 | |
| 382 | 382 | |
@@ -392,29 +392,29 @@ discard block |
||
| 392 | 392 | * @param string $ref_ext Ref ext of object to check |
| 393 | 393 | * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
| 394 | 394 | */ |
| 395 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 395 | + static function isExistingObject($element, $id, $ref = '', $ref_ext = '') |
|
| 396 | 396 | {
|
| 397 | - global $db,$conf; |
|
| 397 | + global $db, $conf; |
|
| 398 | 398 | |
| 399 | 399 | $sql = "SELECT rowid, ref, ref_ext"; |
| 400 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 401 | - $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
|
| 400 | + $sql .= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 401 | + $sql .= " WHERE entity IN (".getEntity($element).")";
|
|
| 402 | 402 | |
| 403 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 404 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 405 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 403 | + if ($id > 0) $sql .= " AND rowid = ".$db->escape($id); |
|
| 404 | + else if ($ref) $sql .= " AND ref = '".$db->escape($ref)."'"; |
|
| 405 | + else if ($ref_ext) $sql .= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 406 | 406 | else {
|
| 407 | - $error='ErrorWrongParameters'; |
|
| 407 | + $error = 'ErrorWrongParameters'; |
|
| 408 | 408 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
| 409 | 409 | return -1; |
| 410 | 410 | } |
| 411 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 411 | + if ($ref || $ref_ext) $sql .= " AND entity = ".$conf->entity; |
|
| 412 | 412 | |
| 413 | 413 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
| 414 | 414 | $resql = $db->query($sql); |
| 415 | 415 | if ($resql) |
| 416 | 416 | {
|
| 417 | - $num=$db->num_rows($resql); |
|
| 417 | + $num = $db->num_rows($resql); |
|
| 418 | 418 | if ($num > 0) return 1; |
| 419 | 419 | else return 0; |
| 420 | 420 | } |
@@ -428,7 +428,7 @@ discard block |
||
| 428 | 428 | */ |
| 429 | 429 | function errorsToString() |
| 430 | 430 | {
|
| 431 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):'');
|
|
| 431 | + return $this->error.(is_array($this->errors) ? (($this->error != '' ? ', ' : '').join(', ', $this->errors)) : '');
|
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -440,23 +440,23 @@ discard block |
||
| 440 | 440 | * @param int $maxlen Maximum length |
| 441 | 441 | * @return string String with full name |
| 442 | 442 | */ |
| 443 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 443 | + function getFullName($langs, $option = 0, $nameorder = -1, $maxlen = 0) |
|
| 444 | 444 | {
|
| 445 | 445 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
| 446 | - $lastname=$this->lastname; |
|
| 447 | - $firstname=$this->firstname; |
|
| 448 | - 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:''))))); |
|
| 446 | + $lastname = $this->lastname; |
|
| 447 | + $firstname = $this->firstname; |
|
| 448 | + 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 : ''))))); |
|
| 449 | 449 | |
| 450 | - $ret=''; |
|
| 450 | + $ret = ''; |
|
| 451 | 451 | if ($option && $this->civility_id) |
| 452 | 452 | {
|
| 453 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 454 | - else $ret.=$this->civility_id.' '; |
|
| 453 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id) != "Civility".$this->civility_id) $ret .= $langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 454 | + else $ret .= $this->civility_id.' '; |
|
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 457 | + $ret .= dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 458 | 458 | |
| 459 | - return dol_trunc($ret,$maxlen); |
|
| 459 | + return dol_trunc($ret, $maxlen); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -467,24 +467,24 @@ discard block |
||
| 467 | 467 | * @param int $withregion 1=Add region into address string |
| 468 | 468 | * @return string Full address string |
| 469 | 469 | */ |
| 470 | - function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
| 470 | + function getFullAddress($withcountry = 0, $sep = "\n", $withregion = 0) |
|
| 471 | 471 | {
|
| 472 | 472 | if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
| 473 | 473 | {
|
| 474 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 475 | - $tmparray=getCountry($this->country_id,'all'); |
|
| 476 | - $this->country_code=$tmparray['code']; |
|
| 477 | - $this->country =$tmparray['label']; |
|
| 474 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 475 | + $tmparray = getCountry($this->country_id, 'all'); |
|
| 476 | + $this->country_code = $tmparray['code']; |
|
| 477 | + $this->country = $tmparray['label']; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
| 481 | 481 | {
|
| 482 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 483 | - $tmparray=getState($this->state_id,'all',0,1); |
|
| 484 | - $this->state_code =$tmparray['code']; |
|
| 485 | - $this->state =$tmparray['label']; |
|
| 486 | - $this->region_code =$tmparray['region_code']; |
|
| 487 | - $this->region =$tmparray['region']; |
|
| 482 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 483 | + $tmparray = getState($this->state_id, 'all', 0, 1); |
|
| 484 | + $this->state_code = $tmparray['code']; |
|
| 485 | + $this->state = $tmparray['label']; |
|
| 486 | + $this->region_code = $tmparray['region_code']; |
|
| 487 | + $this->region = $tmparray['region']; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | return dol_format_address($this, $withcountry, $sep); |
@@ -502,108 +502,108 @@ discard block |
||
| 502 | 502 | {
|
| 503 | 503 | global $conf, $langs; |
| 504 | 504 | |
| 505 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
|
|
| 505 | + $countriesusingstate = array('AU', 'US', 'IN', 'GB', 'ES', 'UK', 'TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
|
|
| 506 | 506 | |
| 507 | - $contactid=0; |
|
| 508 | - $thirdpartyid=0; |
|
| 507 | + $contactid = 0; |
|
| 508 | + $thirdpartyid = 0; |
|
| 509 | 509 | if ($this->element == 'societe') |
| 510 | 510 | {
|
| 511 | - $thirdpartyid=$this->id; |
|
| 511 | + $thirdpartyid = $this->id; |
|
| 512 | 512 | } |
| 513 | 513 | if ($this->element == 'contact') |
| 514 | 514 | {
|
| 515 | - $contactid=$this->id; |
|
| 516 | - $thirdpartyid=$object->fk_soc; |
|
| 515 | + $contactid = $this->id; |
|
| 516 | + $thirdpartyid = $object->fk_soc; |
|
| 517 | 517 | } |
| 518 | 518 | if ($this->element == 'user') |
| 519 | 519 | {
|
| 520 | - $contactid=$this->contact_id; |
|
| 521 | - $thirdpartyid=$object->fk_soc; |
|
| 520 | + $contactid = $this->contact_id; |
|
| 521 | + $thirdpartyid = $object->fk_soc; |
|
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - $out='<!-- BEGIN part to show address block -->'; |
|
| 524 | + $out = '<!-- BEGIN part to show address block -->'; |
|
| 525 | 525 | |
| 526 | - $outdone=0; |
|
| 527 | - $coords = $this->getFullAddress(1,', ',$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 526 | + $outdone = 0; |
|
| 527 | + $coords = $this->getFullAddress(1, ', ', $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 528 | 528 | if ($coords) |
| 529 | 529 | {
|
| 530 | - if (! empty($conf->use_javascript_ajax)) |
|
| 530 | + if (!empty($conf->use_javascript_ajax)) |
|
| 531 | 531 | {
|
| 532 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 532 | + $namecoords = $this->getFullName($langs, 1).'<br>'.$coords; |
|
| 533 | 533 | // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
| 534 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
|
|
| 535 | - $out.=img_picto($langs->trans("Address"), 'object_address.png');
|
|
| 536 | - $out.='</a> '; |
|
| 534 | + $out .= '<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
|
|
| 535 | + $out .= img_picto($langs->trans("Address"), 'object_address.png');
|
|
| 536 | + $out .= '</a> '; |
|
| 537 | 537 | } |
| 538 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 538 | + $out .= dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 539 | 539 | $outdone++; |
| 540 | 540 | } |
| 541 | 541 | |
| 542 | - 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 |
|
| 542 | + 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 |
|
| 543 | 543 | && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) |
| 544 | 544 | {
|
| 545 | 545 | if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
|
| 546 | - $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
|
| 546 | + $out .= ($outdone ? ' - ' : '').$this->region.' - '.$this->state; |
|
| 547 | 547 | } |
| 548 | 548 | else {
|
| 549 | - $out.=($outdone?' - ':'').$this->state; |
|
| 549 | + $out .= ($outdone ? ' - ' : '').$this->state; |
|
| 550 | 550 | } |
| 551 | 551 | $outdone++; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - 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>':''); |
|
| 555 | - if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
|
|
| 556 | - $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 554 | + 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>' : ''); |
|
| 555 | + if (!empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
|
|
| 556 | + $out .= dol_print_phone($this->phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++;
|
|
| 557 | 557 | } |
| 558 | - if (! empty($this->phone_pro)) {
|
|
| 559 | - $out.=dol_print_phone($this->phone_pro,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 558 | + if (!empty($this->phone_pro)) {
|
|
| 559 | + $out .= dol_print_phone($this->phone_pro, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++;
|
|
| 560 | 560 | } |
| 561 | - if (! empty($this->phone_mobile)) {
|
|
| 562 | - $out.=dol_print_phone($this->phone_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++;
|
|
| 561 | + if (!empty($this->phone_mobile)) {
|
|
| 562 | + $out .= dol_print_phone($this->phone_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++;
|
|
| 563 | 563 | } |
| 564 | - if (! empty($this->phone_perso)) {
|
|
| 565 | - $out.=dol_print_phone($this->phone_perso,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePerso")); $outdone++;
|
|
| 564 | + if (!empty($this->phone_perso)) {
|
|
| 565 | + $out .= dol_print_phone($this->phone_perso, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePerso")); $outdone++;
|
|
| 566 | 566 | } |
| 567 | - if (! empty($this->office_phone)) {
|
|
| 568 | - $out.=dol_print_phone($this->office_phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
|
| 567 | + if (!empty($this->office_phone)) {
|
|
| 568 | + $out .= dol_print_phone($this->office_phone, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'phone', $langs->trans("PhonePro")); $outdone++;
|
|
| 569 | 569 | } |
| 570 | - if (! empty($this->user_mobile)) {
|
|
| 571 | - $out.=dol_print_phone($this->user_mobile,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','mobile',$langs->trans("PhoneMobile")); $outdone++;
|
|
| 570 | + if (!empty($this->user_mobile)) {
|
|
| 571 | + $out .= dol_print_phone($this->user_mobile, $this->country_code, $contactid, $thirdpartyid, 'AC_TEL', ' ', 'mobile', $langs->trans("PhoneMobile")); $outdone++;
|
|
| 572 | 572 | } |
| 573 | - if (! empty($this->fax)) {
|
|
| 574 | - $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++;
|
|
| 573 | + if (!empty($this->fax)) {
|
|
| 574 | + $out .= dol_print_phone($this->fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++;
|
|
| 575 | 575 | } |
| 576 | - if (! empty($this->office_fax)) {
|
|
| 577 | - $out.=dol_print_phone($this->office_fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++;
|
|
| 576 | + if (!empty($this->office_fax)) {
|
|
| 577 | + $out .= dol_print_phone($this->office_fax, $this->country_code, $contactid, $thirdpartyid, 'AC_FAX', ' ', 'fax', $langs->trans("Fax")); $outdone++;
|
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - $out.='<div style="clear: both;"></div>'; |
|
| 581 | - $outdone=0; |
|
| 582 | - if (! empty($this->email)) |
|
| 580 | + $out .= '<div style="clear: both;"></div>'; |
|
| 581 | + $outdone = 0; |
|
| 582 | + if (!empty($this->email)) |
|
| 583 | 583 | {
|
| 584 | - $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); |
|
| 584 | + $out .= dol_print_email($this->email, $this->id, $object->id, 'AC_EMAIL', 0, 0, 1); |
|
| 585 | 585 | $outdone++; |
| 586 | 586 | } |
| 587 | - if (! empty($this->url)) |
|
| 587 | + if (!empty($this->url)) |
|
| 588 | 588 | {
|
| 589 | - $out.=dol_print_url($this->url,'_goout',0,1); |
|
| 589 | + $out .= dol_print_url($this->url, '_goout', 0, 1); |
|
| 590 | 590 | $outdone++; |
| 591 | 591 | } |
| 592 | - $out.='<div style="clear: both;">'; |
|
| 593 | - if (! empty($conf->socialnetworks->enabled)) |
|
| 592 | + $out .= '<div style="clear: both;">'; |
|
| 593 | + if (!empty($conf->socialnetworks->enabled)) |
|
| 594 | 594 | {
|
| 595 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 595 | + if ($this->skype) $out .= dol_print_socialnetworks($this->skype, $this->id, $object->id, 'skype'); |
|
| 596 | 596 | $outdone++; |
| 597 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 597 | + if ($this->jabberid) $out .= dol_print_socialnetworks($this->jabberid, $this->id, $object->id, 'jabber'); |
|
| 598 | 598 | $outdone++; |
| 599 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 599 | + if ($this->twitter) $out .= dol_print_socialnetworks($this->twitter, $this->id, $object->id, 'twitter'); |
|
| 600 | 600 | $outdone++; |
| 601 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 601 | + if ($this->facebook) $out .= dol_print_socialnetworks($this->facebook, $this->id, $object->id, 'facebook'); |
|
| 602 | 602 | $outdone++; |
| 603 | 603 | } |
| 604 | - $out.='</div>'; |
|
| 604 | + $out .= '</div>'; |
|
| 605 | 605 | |
| 606 | - $out.='<!-- END Part to show address block -->'; |
|
| 606 | + $out .= '<!-- END Part to show address block -->'; |
|
| 607 | 607 | |
| 608 | 608 | return $out; |
| 609 | 609 | } |
@@ -616,17 +616,17 @@ discard block |
||
| 616 | 616 | * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
| 617 | 617 | * @return string Link or empty string if there is no download link |
| 618 | 618 | */ |
| 619 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 619 | + function getLastMainDocLink($modulepart, $initsharekey = 0, $relativelink = 0) |
|
| 620 | 620 | {
|
| 621 | 621 | global $user, $dolibarr_main_url_root; |
| 622 | 622 | |
| 623 | 623 | if (empty($this->last_main_doc)) |
| 624 | 624 | {
|
| 625 | - return ''; // No way to known which document name to use |
|
| 625 | + return ''; // No way to known which document name to use |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 629 | - $ecmfile=new EcmFiles($this->db); |
|
| 629 | + $ecmfile = new EcmFiles($this->db); |
|
| 630 | 630 | $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
| 631 | 631 | if ($result < 0) |
| 632 | 632 | {
|
@@ -674,26 +674,26 @@ discard block |
||
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | // Define $urlwithroot |
| 677 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
|
|
| 678 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 677 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
|
|
| 678 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 679 | 679 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
| 680 | 680 | |
| 681 | - $forcedownload=0; |
|
| 681 | + $forcedownload = 0; |
|
| 682 | 682 | |
| 683 | - $paramlink=''; |
|
| 683 | + $paramlink = ''; |
|
| 684 | 684 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
| 685 | 685 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
| 686 | 686 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
| 687 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 688 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 687 | + if (!empty($ecmfile->share)) $paramlink .= ($paramlink ? '&' : '').'hashp='.$ecmfile->share; // Hash for public share |
|
| 688 | + if ($forcedownload) $paramlink .= ($paramlink ? '&' : '').'attachment=1'; |
|
| 689 | 689 | |
| 690 | 690 | if ($relativelink) |
| 691 | 691 | {
|
| 692 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 692 | + $linktoreturn = 'document.php'.($paramlink ? '?'.$paramlink : ''); |
|
| 693 | 693 | } |
| 694 | 694 | else |
| 695 | 695 | {
|
| 696 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 696 | + $linktoreturn = $urlwithroot.'/document.php'.($paramlink ? '?'.$paramlink : ''); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | // Here $ecmfile->share is defined |
@@ -711,10 +711,10 @@ discard block |
||
| 711 | 711 | * @param int $notrigger Disable all triggers |
| 712 | 712 | * @return int <0 if KO, >0 if OK |
| 713 | 713 | */ |
| 714 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 714 | + function add_contact($fk_socpeople, $type_contact, $source = 'external', $notrigger = 0) |
|
| 715 | 715 | {
|
| 716 | 716 | // phpcs:enable |
| 717 | - global $user,$langs; |
|
| 717 | + global $user, $langs; |
|
| 718 | 718 | |
| 719 | 719 | |
| 720 | 720 | dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
@@ -723,43 +723,43 @@ discard block |
||
| 723 | 723 | if ($fk_socpeople <= 0) |
| 724 | 724 | {
|
| 725 | 725 | $langs->load("errors");
|
| 726 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1");
|
|
| 727 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 726 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "1");
|
|
| 727 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
| 728 | 728 | return -1; |
| 729 | 729 | } |
| 730 | - if (! $type_contact) |
|
| 730 | + if (!$type_contact) |
|
| 731 | 731 | {
|
| 732 | 732 | $langs->load("errors");
|
| 733 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2");
|
|
| 734 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 733 | + $this->error = $langs->trans("ErrorWrongValueForParameterX", "2");
|
|
| 734 | + dol_syslog(get_class($this)."::add_contact ".$this->error, LOG_ERR); |
|
| 735 | 735 | return -2; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - $id_type_contact=0; |
|
| 738 | + $id_type_contact = 0; |
|
| 739 | 739 | if (is_numeric($type_contact)) |
| 740 | 740 | {
|
| 741 | - $id_type_contact=$type_contact; |
|
| 741 | + $id_type_contact = $type_contact; |
|
| 742 | 742 | } |
| 743 | 743 | else |
| 744 | 744 | {
|
| 745 | 745 | // We look for id type_contact |
| 746 | 746 | $sql = "SELECT tc.rowid"; |
| 747 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 748 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 749 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 750 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 747 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 748 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 749 | + $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 750 | + $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 751 | 751 | //print $sql; |
| 752 | - $resql=$this->db->query($sql); |
|
| 752 | + $resql = $this->db->query($sql); |
|
| 753 | 753 | if ($resql) |
| 754 | 754 | {
|
| 755 | 755 | $obj = $this->db->fetch_object($resql); |
| 756 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 756 | + if ($obj) $id_type_contact = $obj->rowid; |
|
| 757 | 757 | } |
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | if ($id_type_contact == 0) |
| 761 | 761 | {
|
| 762 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 762 | + $this->error = 'CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 763 | 763 | dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT: Code type of contact '".$type_contact."' does not exists or is not active for element ".$this->element.", we can ignore it");
|
| 764 | 764 | return -3; |
| 765 | 765 | } |
@@ -767,35 +767,35 @@ discard block |
||
| 767 | 767 | $datecreate = dol_now(); |
| 768 | 768 | |
| 769 | 769 | // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
| 770 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
| 771 | - $already_added=false; |
|
| 772 | - if(!empty($TListeContacts)) {
|
|
| 773 | - foreach($TListeContacts as $array_contact) {
|
|
| 774 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
|
| 775 | - $already_added=true; |
|
| 770 | + $TListeContacts = $this->liste_contact(-1, $source); |
|
| 771 | + $already_added = false; |
|
| 772 | + if (!empty($TListeContacts)) {
|
|
| 773 | + foreach ($TListeContacts as $array_contact) {
|
|
| 774 | + if ($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
|
| 775 | + $already_added = true; |
|
| 776 | 776 | break; |
| 777 | 777 | } |
| 778 | 778 | } |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | - if(!$already_added) {
|
|
| 781 | + if (!$already_added) {
|
|
| 782 | 782 | |
| 783 | 783 | $this->db->begin(); |
| 784 | 784 | |
| 785 | 785 | // Insert into database |
| 786 | 786 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
| 787 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 788 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
|
| 789 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 790 | - $sql.= ", 4, ". $id_type_contact; |
|
| 791 | - $sql.= ")"; |
|
| 787 | + $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 788 | + $sql .= " VALUES (".$this->id.", ".$fk_socpeople." , ";
|
|
| 789 | + $sql .= "'".$this->db->idate($datecreate)."'"; |
|
| 790 | + $sql .= ", 4, ".$id_type_contact; |
|
| 791 | + $sql .= ")"; |
|
| 792 | 792 | |
| 793 | - $resql=$this->db->query($sql); |
|
| 793 | + $resql = $this->db->query($sql); |
|
| 794 | 794 | if ($resql) |
| 795 | 795 | {
|
| 796 | - if (! $notrigger) |
|
| 796 | + if (!$notrigger) |
|
| 797 | 797 | {
|
| 798 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 798 | + $result = $this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 799 | 799 | if ($result < 0) |
| 800 | 800 | {
|
| 801 | 801 | $this->db->rollback(); |
@@ -810,14 +810,14 @@ discard block |
||
| 810 | 810 | {
|
| 811 | 811 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 812 | 812 | {
|
| 813 | - $this->error=$this->db->errno(); |
|
| 813 | + $this->error = $this->db->errno(); |
|
| 814 | 814 | $this->db->rollback(); |
| 815 | 815 | echo 'err rollback'; |
| 816 | 816 | return -2; |
| 817 | 817 | } |
| 818 | 818 | else |
| 819 | 819 | {
|
| 820 | - $this->error=$this->db->error(); |
|
| 820 | + $this->error = $this->db->error(); |
|
| 821 | 821 | $this->db->rollback(); |
| 822 | 822 | return -1; |
| 823 | 823 | } |
@@ -833,15 +833,15 @@ discard block |
||
| 833 | 833 | * @param string $source Nature of contact ('internal' or 'external')
|
| 834 | 834 | * @return int >0 if OK, <0 if KO |
| 835 | 835 | */ |
| 836 | - function copy_linked_contact($objFrom, $source='internal') |
|
| 836 | + function copy_linked_contact($objFrom, $source = 'internal') |
|
| 837 | 837 | {
|
| 838 | 838 | // phpcs:enable |
| 839 | 839 | $contacts = $objFrom->liste_contact(-1, $source); |
| 840 | - foreach($contacts as $contact) |
|
| 840 | + foreach ($contacts as $contact) |
|
| 841 | 841 | {
|
| 842 | 842 | if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
| 843 | 843 | {
|
| 844 | - $this->error=$this->db->lasterror(); |
|
| 844 | + $this->error = $this->db->lasterror(); |
|
| 845 | 845 | return -1; |
| 846 | 846 | } |
| 847 | 847 | } |
@@ -858,23 +858,23 @@ discard block |
||
| 858 | 858 | * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
| 859 | 859 | * @return int <0 if KO, >= 0 if OK |
| 860 | 860 | */ |
| 861 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 861 | + function update_contact($rowid, $statut, $type_contact_id = 0, $fk_socpeople = 0) |
|
| 862 | 862 | {
|
| 863 | 863 | // phpcs:enable |
| 864 | 864 | // Insert into database |
| 865 | 865 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
| 866 | - $sql.= " statut = ".$statut; |
|
| 867 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 868 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 869 | - $sql.= " where rowid = ".$rowid; |
|
| 870 | - $resql=$this->db->query($sql); |
|
| 866 | + $sql .= " statut = ".$statut; |
|
| 867 | + if ($type_contact_id) $sql .= ", fk_c_type_contact = '".$type_contact_id."'"; |
|
| 868 | + if ($fk_socpeople) $sql .= ", fk_socpeople = '".$fk_socpeople."'"; |
|
| 869 | + $sql .= " where rowid = ".$rowid; |
|
| 870 | + $resql = $this->db->query($sql); |
|
| 871 | 871 | if ($resql) |
| 872 | 872 | {
|
| 873 | 873 | return 0; |
| 874 | 874 | } |
| 875 | 875 | else |
| 876 | 876 | {
|
| 877 | - $this->error=$this->db->lasterror(); |
|
| 877 | + $this->error = $this->db->lasterror(); |
|
| 878 | 878 | return -1; |
| 879 | 879 | } |
| 880 | 880 | } |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | * @param int $notrigger Disable all triggers |
| 888 | 888 | * @return int >0 if OK, <0 if KO |
| 889 | 889 | */ |
| 890 | - function delete_contact($rowid, $notrigger=0) |
|
| 890 | + function delete_contact($rowid, $notrigger = 0) |
|
| 891 | 891 | {
|
| 892 | 892 | // phpcs:enable |
| 893 | 893 | global $user; |
@@ -896,14 +896,14 @@ discard block |
||
| 896 | 896 | $this->db->begin(); |
| 897 | 897 | |
| 898 | 898 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 899 | - $sql.= " WHERE rowid =".$rowid; |
|
| 899 | + $sql .= " WHERE rowid =".$rowid; |
|
| 900 | 900 | |
| 901 | 901 | dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
| 902 | 902 | if ($this->db->query($sql)) |
| 903 | 903 | {
|
| 904 | - if (! $notrigger) |
|
| 904 | + if (!$notrigger) |
|
| 905 | 905 | {
|
| 906 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 906 | + $result = $this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 907 | 907 | if ($result < 0) { $this->db->rollback(); return -1; }
|
| 908 | 908 | } |
| 909 | 909 | |
@@ -912,7 +912,7 @@ discard block |
||
| 912 | 912 | } |
| 913 | 913 | else |
| 914 | 914 | {
|
| 915 | - $this->error=$this->db->lasterror(); |
|
| 915 | + $this->error = $this->db->lasterror(); |
|
| 916 | 916 | $this->db->rollback(); |
| 917 | 917 | return -1; |
| 918 | 918 | } |
@@ -926,22 +926,22 @@ discard block |
||
| 926 | 926 | * @param string $code Type of contact (code or id) |
| 927 | 927 | * @return int >0 if OK, <0 if KO |
| 928 | 928 | */ |
| 929 | - function delete_linked_contact($source='',$code='') |
|
| 929 | + function delete_linked_contact($source = '', $code = '') |
|
| 930 | 930 | {
|
| 931 | 931 | // phpcs:enable |
| 932 | 932 | $temp = array(); |
| 933 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 933 | + $typeContact = $this->liste_type_contact($source, '', 0, 0, $code); |
|
| 934 | 934 | |
| 935 | - foreach($typeContact as $key => $value) |
|
| 935 | + foreach ($typeContact as $key => $value) |
|
| 936 | 936 | {
|
| 937 | - array_push($temp,$key); |
|
| 937 | + array_push($temp, $key); |
|
| 938 | 938 | } |
| 939 | 939 | $listId = implode(",", $temp);
|
| 940 | 940 | |
| 941 | 941 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 942 | - $sql.= " WHERE element_id = ".$this->id; |
|
| 942 | + $sql .= " WHERE element_id = ".$this->id; |
|
| 943 | 943 | if ($listId) |
| 944 | - $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 944 | + $sql .= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 945 | 945 | |
| 946 | 946 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
| 947 | 947 | if ($this->db->query($sql)) |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | } |
| 951 | 951 | else |
| 952 | 952 | {
|
| 953 | - $this->error=$this->db->lasterror(); |
|
| 953 | + $this->error = $this->db->lasterror(); |
|
| 954 | 954 | return -1; |
| 955 | 955 | } |
| 956 | 956 | } |
@@ -965,54 +965,54 @@ discard block |
||
| 965 | 965 | * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
|
| 966 | 966 | * @return array|int Array of contacts, -1 if error |
| 967 | 967 | */ |
| 968 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 968 | + function liste_contact($statut = -1, $source = 'external', $list = 0, $code = '') |
|
| 969 | 969 | {
|
| 970 | 970 | // phpcs:enable |
| 971 | 971 | global $langs; |
| 972 | 972 | |
| 973 | - $tab=array(); |
|
| 974 | - |
|
| 975 | - $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 |
|
| 976 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 977 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 978 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 979 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 980 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 981 | - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 982 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 983 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 984 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
| 985 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 986 | - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 987 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 988 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 989 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 990 | - $sql.= " AND tc.active=1"; |
|
| 991 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 992 | - $sql.=" ORDER BY t.lastname ASC"; |
|
| 973 | + $tab = array(); |
|
| 974 | + |
|
| 975 | + $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 |
|
| 976 | + if ($source == 'internal') $sql .= ", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 977 | + if ($source == 'external' || $source == 'thirdparty') $sql .= ", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 978 | + $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 979 | + $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 980 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 981 | + $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 982 | + if ($source == 'internal') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 983 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 984 | + $sql .= " WHERE ec.element_id =".$this->id; |
|
| 985 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 986 | + $sql .= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 987 | + if ($code) $sql .= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 988 | + if ($source == 'internal') $sql .= " AND tc.source = 'internal'"; |
|
| 989 | + if ($source == 'external' || $source == 'thirdparty') $sql .= " AND tc.source = 'external'"; |
|
| 990 | + $sql .= " AND tc.active=1"; |
|
| 991 | + if ($statut >= 0) $sql .= " AND ec.statut = '".$statut."'"; |
|
| 992 | + $sql .= " ORDER BY t.lastname ASC"; |
|
| 993 | 993 | |
| 994 | 994 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
| 995 | - $resql=$this->db->query($sql); |
|
| 995 | + $resql = $this->db->query($sql); |
|
| 996 | 996 | if ($resql) |
| 997 | 997 | {
|
| 998 | - $num=$this->db->num_rows($resql); |
|
| 999 | - $i=0; |
|
| 998 | + $num = $this->db->num_rows($resql); |
|
| 999 | + $i = 0; |
|
| 1000 | 1000 | while ($i < $num) |
| 1001 | 1001 | {
|
| 1002 | 1002 | $obj = $this->db->fetch_object($resql); |
| 1003 | 1003 | |
| 1004 | - if (! $list) |
|
| 1004 | + if (!$list) |
|
| 1005 | 1005 | {
|
| 1006 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1007 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1008 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,
|
|
| 1009 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1006 | + $transkey = "TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1007 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1008 | + $tab[$i] = array('source'=>$obj->source, 'socid'=>$obj->socid, 'id'=>$obj->id,
|
|
| 1009 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1010 | 1010 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
| 1011 | 1011 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
| 1012 | 1012 | } |
| 1013 | 1013 | else |
| 1014 | 1014 | {
|
| 1015 | - $tab[$i]=$obj->id; |
|
| 1015 | + $tab[$i] = $obj->id; |
|
| 1016 | 1016 | } |
| 1017 | 1017 | |
| 1018 | 1018 | $i++; |
@@ -1022,7 +1022,7 @@ discard block |
||
| 1022 | 1022 | } |
| 1023 | 1023 | else |
| 1024 | 1024 | {
|
| 1025 | - $this->error=$this->db->lasterror(); |
|
| 1025 | + $this->error = $this->db->lasterror(); |
|
| 1026 | 1026 | dol_print_error($this->db); |
| 1027 | 1027 | return -1; |
| 1028 | 1028 | } |
@@ -1038,16 +1038,16 @@ discard block |
||
| 1038 | 1038 | function swapContactStatus($rowid) |
| 1039 | 1039 | {
|
| 1040 | 1040 | $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
| 1041 | - $sql.= " tc.code, tc.libelle"; |
|
| 1041 | + $sql .= " tc.code, tc.libelle"; |
|
| 1042 | 1042 | //$sql.= ", s.fk_soc"; |
| 1043 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
|
|
| 1043 | + $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
|
|
| 1044 | 1044 | //$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 |
| 1045 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
| 1046 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1047 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1045 | + $sql .= " WHERE ec.rowid =".$rowid; |
|
| 1046 | + $sql .= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1047 | + $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1048 | 1048 | |
| 1049 | 1049 | dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
| 1050 | - $resql=$this->db->query($sql); |
|
| 1050 | + $resql = $this->db->query($sql); |
|
| 1051 | 1051 | if ($resql) |
| 1052 | 1052 | {
|
| 1053 | 1053 | $obj = $this->db->fetch_object($resql); |
@@ -1058,7 +1058,7 @@ discard block |
||
| 1058 | 1058 | } |
| 1059 | 1059 | else |
| 1060 | 1060 | {
|
| 1061 | - $this->error=$this->db->error(); |
|
| 1061 | + $this->error = $this->db->error(); |
|
| 1062 | 1062 | dol_print_error($this->db); |
| 1063 | 1063 | return -1; |
| 1064 | 1064 | } |
@@ -1075,44 +1075,44 @@ discard block |
||
| 1075 | 1075 | * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
| 1076 | 1076 | * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
| 1077 | 1077 | */ |
| 1078 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1078 | + function liste_type_contact($source = 'internal', $order = 'position', $option = 0, $activeonly = 0, $code = '') |
|
| 1079 | 1079 | {
|
| 1080 | 1080 | // phpcs:enable |
| 1081 | 1081 | global $langs; |
| 1082 | 1082 | |
| 1083 | - if (empty($order)) $order='position'; |
|
| 1084 | - if ($order == 'position') $order.=',code'; |
|
| 1083 | + if (empty($order)) $order = 'position'; |
|
| 1084 | + if ($order == 'position') $order .= ',code'; |
|
| 1085 | 1085 | |
| 1086 | 1086 | $tab = array(); |
| 1087 | 1087 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
| 1088 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1089 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1090 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1091 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1092 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1093 | - $sql.= $this->db->order($order,'ASC'); |
|
| 1088 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1089 | + $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1090 | + if ($activeonly == 1) $sql .= " AND tc.active=1"; // only the active types |
|
| 1091 | + if (!empty($source) && $source != 'all') $sql .= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1092 | + if (!empty($code)) $sql .= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1093 | + $sql .= $this->db->order($order, 'ASC'); |
|
| 1094 | 1094 | |
| 1095 | 1095 | //print "sql=".$sql; |
| 1096 | - $resql=$this->db->query($sql); |
|
| 1096 | + $resql = $this->db->query($sql); |
|
| 1097 | 1097 | if ($resql) |
| 1098 | 1098 | {
|
| 1099 | - $num=$this->db->num_rows($resql); |
|
| 1100 | - $i=0; |
|
| 1099 | + $num = $this->db->num_rows($resql); |
|
| 1100 | + $i = 0; |
|
| 1101 | 1101 | while ($i < $num) |
| 1102 | 1102 | {
|
| 1103 | 1103 | $obj = $this->db->fetch_object($resql); |
| 1104 | 1104 | |
| 1105 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1106 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1107 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1108 | - else $tab[$obj->code]=$libelle_type; |
|
| 1105 | + $transkey = "TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1106 | + $libelle_type = ($langs->trans($transkey) != $transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1107 | + if (empty($option)) $tab[$obj->rowid] = $libelle_type; |
|
| 1108 | + else $tab[$obj->code] = $libelle_type; |
|
| 1109 | 1109 | $i++; |
| 1110 | 1110 | } |
| 1111 | 1111 | return $tab; |
| 1112 | 1112 | } |
| 1113 | 1113 | else |
| 1114 | 1114 | {
|
| 1115 | - $this->error=$this->db->lasterror(); |
|
| 1115 | + $this->error = $this->db->lasterror(); |
|
| 1116 | 1116 | //dol_print_error($this->db); |
| 1117 | 1117 | return null; |
| 1118 | 1118 | } |
@@ -1129,53 +1129,53 @@ discard block |
||
| 1129 | 1129 | * @param int $status limited to a certain status |
| 1130 | 1130 | * @return array List of id for such contacts |
| 1131 | 1131 | */ |
| 1132 | - function getIdContact($source,$code,$status=0) |
|
| 1132 | + function getIdContact($source, $code, $status = 0) |
|
| 1133 | 1133 | {
|
| 1134 | 1134 | global $conf; |
| 1135 | 1135 | |
| 1136 | - $result=array(); |
|
| 1137 | - $i=0; |
|
| 1136 | + $result = array(); |
|
| 1137 | + $i = 0; |
|
| 1138 | 1138 | //cas particulier pour les expeditions |
| 1139 | - if($this->element=='shipping' && $this->origin_id != 0) {
|
|
| 1140 | - $id=$this->origin_id; |
|
| 1141 | - $element='commande'; |
|
| 1142 | - } else if($this->element=='reception' && $this->origin_id != 0) {
|
|
| 1143 | - $id=$this->origin_id; |
|
| 1144 | - $element='order_supplier'; |
|
| 1139 | + if ($this->element == 'shipping' && $this->origin_id != 0) {
|
|
| 1140 | + $id = $this->origin_id; |
|
| 1141 | + $element = 'commande'; |
|
| 1142 | + } else if ($this->element == 'reception' && $this->origin_id != 0) {
|
|
| 1143 | + $id = $this->origin_id; |
|
| 1144 | + $element = 'order_supplier'; |
|
| 1145 | 1145 | } else {
|
| 1146 | - $id=$this->id; |
|
| 1147 | - $element=$this->element; |
|
| 1146 | + $id = $this->id; |
|
| 1147 | + $element = $this->element; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | $sql = "SELECT ec.fk_socpeople"; |
| 1151 | - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1152 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1153 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1154 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1155 | - $sql.= " WHERE ec.element_id = ".$id; |
|
| 1156 | - $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
| 1157 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1158 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1159 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1160 | - $sql.= " AND tc.element = '".$element."'"; |
|
| 1161 | - $sql.= " AND tc.source = '".$source."'"; |
|
| 1162 | - $sql.= " AND tc.code = '".$code."'"; |
|
| 1163 | - $sql.= " AND tc.active = 1"; |
|
| 1164 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1151 | + $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1152 | + if ($source == 'internal') $sql .= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1153 | + if ($source == 'external') $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1154 | + $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1155 | + $sql .= " WHERE ec.element_id = ".$id; |
|
| 1156 | + $sql .= " AND ec.fk_socpeople = c.rowid"; |
|
| 1157 | + if ($source == 'internal') $sql .= " AND c.entity IN (".getEntity('user').")";
|
|
| 1158 | + if ($source == 'external') $sql .= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1159 | + $sql .= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1160 | + $sql .= " AND tc.element = '".$element."'"; |
|
| 1161 | + $sql .= " AND tc.source = '".$source."'"; |
|
| 1162 | + $sql .= " AND tc.code = '".$code."'"; |
|
| 1163 | + $sql .= " AND tc.active = 1"; |
|
| 1164 | + if ($status) $sql .= " AND ec.statut = ".$status; |
|
| 1165 | 1165 | |
| 1166 | 1166 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
| 1167 | - $resql=$this->db->query($sql); |
|
| 1167 | + $resql = $this->db->query($sql); |
|
| 1168 | 1168 | if ($resql) |
| 1169 | 1169 | {
|
| 1170 | 1170 | while ($obj = $this->db->fetch_object($resql)) |
| 1171 | 1171 | {
|
| 1172 | - $result[$i]=$obj->fk_socpeople; |
|
| 1172 | + $result[$i] = $obj->fk_socpeople; |
|
| 1173 | 1173 | $i++; |
| 1174 | 1174 | } |
| 1175 | 1175 | } |
| 1176 | 1176 | else |
| 1177 | 1177 | {
|
| 1178 | - $this->error=$this->db->error(); |
|
| 1178 | + $this->error = $this->db->error(); |
|
| 1179 | 1179 | return null; |
| 1180 | 1180 | } |
| 1181 | 1181 | |
@@ -1189,16 +1189,16 @@ discard block |
||
| 1189 | 1189 | * @param int $contactid Id du contact. Use this->contactid if empty. |
| 1190 | 1190 | * @return int <0 if KO, >0 if OK |
| 1191 | 1191 | */ |
| 1192 | - function fetch_contact($contactid=null) |
|
| 1192 | + function fetch_contact($contactid = null) |
|
| 1193 | 1193 | {
|
| 1194 | 1194 | // phpcs:enable |
| 1195 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 1195 | + if (empty($contactid)) $contactid = $this->contactid; |
|
| 1196 | 1196 | |
| 1197 | 1197 | if (empty($contactid)) return 0; |
| 1198 | 1198 | |
| 1199 | 1199 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
| 1200 | 1200 | $contact = new Contact($this->db); |
| 1201 | - $result=$contact->fetch($contactid); |
|
| 1201 | + $result = $contact->fetch($contactid); |
|
| 1202 | 1202 | $this->contact = $contact; |
| 1203 | 1203 | return $result; |
| 1204 | 1204 | } |
@@ -1210,7 +1210,7 @@ discard block |
||
| 1210 | 1210 | * @param int $force_thirdparty_id Force thirdparty id |
| 1211 | 1211 | * @return int <0 if KO, >0 if OK |
| 1212 | 1212 | */ |
| 1213 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1213 | + function fetch_thirdparty($force_thirdparty_id = 0) |
|
| 1214 | 1214 | {
|
| 1215 | 1215 | // phpcs:enable |
| 1216 | 1216 | global $conf; |
@@ -1218,7 +1218,7 @@ discard block |
||
| 1218 | 1218 | if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
| 1219 | 1219 | return 0; |
| 1220 | 1220 | |
| 1221 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 1221 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 1222 | 1222 | |
| 1223 | 1223 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
| 1224 | 1224 | if ($force_thirdparty_id) |
@@ -1281,7 +1281,7 @@ discard block |
||
| 1281 | 1281 | |
| 1282 | 1282 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
| 1283 | 1283 | |
| 1284 | - $idtype=$this->barcode_type; |
|
| 1284 | + $idtype = $this->barcode_type; |
|
| 1285 | 1285 | 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 |
| 1286 | 1286 | {
|
| 1287 | 1287 | if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
@@ -1294,8 +1294,8 @@ discard block |
||
| 1294 | 1294 | 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 |
| 1295 | 1295 | {
|
| 1296 | 1296 | $sql = "SELECT rowid, code, libelle as label, coder"; |
| 1297 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1298 | - $sql.= " WHERE rowid = ".$idtype; |
|
| 1297 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1298 | + $sql .= " WHERE rowid = ".$idtype; |
|
| 1299 | 1299 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
| 1300 | 1300 | $resql = $this->db->query($sql); |
| 1301 | 1301 | if ($resql) |
@@ -1328,13 +1328,13 @@ discard block |
||
| 1328 | 1328 | // phpcs:enable |
| 1329 | 1329 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
| 1330 | 1330 | |
| 1331 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1331 | + if (empty($this->fk_project) && !empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1332 | 1332 | if (empty($this->fk_project)) return 0; |
| 1333 | 1333 | |
| 1334 | 1334 | $project = new Project($this->db); |
| 1335 | 1335 | $result = $project->fetch($this->fk_project); |
| 1336 | 1336 | |
| 1337 | - $this->projet = $project; // deprecated |
|
| 1337 | + $this->projet = $project; // deprecated |
|
| 1338 | 1338 | $this->project = $project; |
| 1339 | 1339 | return $result; |
| 1340 | 1340 | } |
@@ -1370,7 +1370,7 @@ discard block |
||
| 1370 | 1370 | {
|
| 1371 | 1371 | // phpcs:enable |
| 1372 | 1372 | $user = new User($this->db); |
| 1373 | - $result=$user->fetch($userid); |
|
| 1373 | + $result = $user->fetch($userid); |
|
| 1374 | 1374 | $this->user = $user; |
| 1375 | 1375 | return $result; |
| 1376 | 1376 | } |
@@ -1408,14 +1408,14 @@ discard block |
||
| 1408 | 1408 | {
|
| 1409 | 1409 | global $conf; |
| 1410 | 1410 | |
| 1411 | - $result=false; |
|
| 1411 | + $result = false; |
|
| 1412 | 1412 | |
| 1413 | 1413 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
| 1414 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1415 | - if (! empty($element)) {
|
|
| 1416 | - $sql.= " AND entity IN (".getEntity($element).")";
|
|
| 1414 | + $sql .= " WHERE ".$field." = '".$key."'"; |
|
| 1415 | + if (!empty($element)) {
|
|
| 1416 | + $sql .= " AND entity IN (".getEntity($element).")";
|
|
| 1417 | 1417 | } else {
|
| 1418 | - $sql.= " AND entity = ".$conf->entity; |
|
| 1418 | + $sql .= " AND entity = ".$conf->entity; |
|
| 1419 | 1419 | } |
| 1420 | 1420 | |
| 1421 | 1421 | dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
@@ -1442,10 +1442,10 @@ discard block |
||
| 1442 | 1442 | */ |
| 1443 | 1443 | function getValueFrom($table, $id, $field) |
| 1444 | 1444 | {
|
| 1445 | - $result=false; |
|
| 1445 | + $result = false; |
|
| 1446 | 1446 | if (!empty($id) && !empty($field) && !empty($table)) {
|
| 1447 | 1447 | $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
| 1448 | - $sql.= " WHERE rowid = ".$id; |
|
| 1448 | + $sql .= " WHERE rowid = ".$id; |
|
| 1449 | 1449 | |
| 1450 | 1450 | dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
| 1451 | 1451 | $resql = $this->db->query($sql); |
@@ -1474,36 +1474,36 @@ discard block |
||
| 1474 | 1474 | * @return int <0 if KO, >0 if OK |
| 1475 | 1475 | * @see updateExtraField |
| 1476 | 1476 | */ |
| 1477 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
| 1477 | + function setValueFrom($field, $value, $table = '', $id = null, $format = '', $id_field = '', $fuser = null, $trigkey = '', $fk_user_field = 'fk_user_modif') |
|
| 1478 | 1478 | {
|
| 1479 | - global $user,$langs,$conf; |
|
| 1479 | + global $user, $langs, $conf; |
|
| 1480 | 1480 | |
| 1481 | - if (empty($table)) $table=$this->table_element; |
|
| 1482 | - if (empty($id)) $id=$this->id; |
|
| 1483 | - if (empty($format)) $format='text'; |
|
| 1484 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1481 | + if (empty($table)) $table = $this->table_element; |
|
| 1482 | + if (empty($id)) $id = $this->id; |
|
| 1483 | + if (empty($format)) $format = 'text'; |
|
| 1484 | + if (empty($id_field)) $id_field = 'rowid'; |
|
| 1485 | 1485 | |
| 1486 | - $error=0; |
|
| 1486 | + $error = 0; |
|
| 1487 | 1487 | |
| 1488 | 1488 | $this->db->begin(); |
| 1489 | 1489 | |
| 1490 | 1490 | // Special case |
| 1491 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1491 | + if ($table == 'product' && $field == 'note_private') $field = 'note'; |
|
| 1492 | 1492 | if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
| 1493 | 1493 | |
| 1494 | 1494 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
| 1495 | 1495 | |
| 1496 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1497 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1498 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1496 | + if ($format == 'text') $sql .= $field." = '".$this->db->escape($value)."'"; |
|
| 1497 | + else if ($format == 'int') $sql .= $field." = ".$this->db->escape($value); |
|
| 1498 | + else if ($format == 'date') $sql .= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1499 | 1499 | |
| 1500 | 1500 | if ($fk_user_field) |
| 1501 | 1501 | {
|
| 1502 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1503 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1502 | + if (!empty($fuser) && is_object($fuser)) $sql .= ", ".$fk_user_field." = ".$fuser->id; |
|
| 1503 | + elseif (empty($fuser) || $fuser != 'none') $sql .= ", ".$fk_user_field." = ".$user->id; |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
| 1506 | + $sql .= " WHERE ".$id_field." = ".$id; |
|
| 1507 | 1507 | |
| 1508 | 1508 | dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
| 1509 | 1509 | $resql = $this->db->query($sql); |
@@ -1520,11 +1520,11 @@ discard block |
||
| 1520 | 1520 | {
|
| 1521 | 1521 | $result = $this->fetchCommon($id); |
| 1522 | 1522 | } |
| 1523 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1523 | + if ($result >= 0) $result = $this->call_trigger($trigkey, (!empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1524 | 1524 | if ($result < 0) $error++; |
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | - if (! $error) |
|
| 1527 | + if (!$error) |
|
| 1528 | 1528 | {
|
| 1529 | 1529 | if (property_exists($this, $field)) $this->$field = $value; |
| 1530 | 1530 | $this->db->commit(); |
@@ -1538,7 +1538,7 @@ discard block |
||
| 1538 | 1538 | } |
| 1539 | 1539 | else |
| 1540 | 1540 | {
|
| 1541 | - $this->error=$this->db->lasterror(); |
|
| 1541 | + $this->error = $this->db->lasterror(); |
|
| 1542 | 1542 | $this->db->rollback(); |
| 1543 | 1543 | return -1; |
| 1544 | 1544 | } |
@@ -1553,14 +1553,14 @@ discard block |
||
| 1553 | 1553 | * @param int $nodbprefix Do not include DB prefix to forge table name |
| 1554 | 1554 | * @return int <0 if KO, >0 if OK |
| 1555 | 1555 | */ |
| 1556 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1556 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix = 0) |
|
| 1557 | 1557 | {
|
| 1558 | 1558 | // phpcs:enable |
| 1559 | 1559 | global $conf, $user; |
| 1560 | 1560 | |
| 1561 | - if (! $this->table_element) |
|
| 1561 | + if (!$this->table_element) |
|
| 1562 | 1562 | {
|
| 1563 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
|
| 1563 | + dol_print_error('', get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
|
| 1564 | 1564 | return -1; |
| 1565 | 1565 | } |
| 1566 | 1566 | if ($fieldid == 'none') return 1; |
@@ -1575,45 +1575,45 @@ discard block |
||
| 1575 | 1575 | if ($this->element == 'societe') $alias = 'te'; |
| 1576 | 1576 | |
| 1577 | 1577 | $sql = "SELECT MAX(te.".$fieldid.")"; |
| 1578 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1579 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1580 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1581 | - } |
|
| 1582 | - 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 |
|
| 1583 | - 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 |
|
| 1584 | - 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 |
|
| 1585 | - 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"; |
|
| 1586 | - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1587 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1588 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1589 | - if (! empty($filter)) |
|
| 1590 | - {
|
|
| 1591 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1592 | - $sql.=$filter; |
|
| 1593 | - } |
|
| 1594 | - 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 |
|
| 1595 | - 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 |
|
| 1578 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1579 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1580 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1581 | + } |
|
| 1582 | + 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 |
|
| 1583 | + 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 |
|
| 1584 | + 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 |
|
| 1585 | + 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"; |
|
| 1586 | + $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1587 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
| 1588 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1589 | + if (!empty($filter)) |
|
| 1590 | + {
|
|
| 1591 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility
|
|
| 1592 | + $sql .= $filter; |
|
| 1593 | + } |
|
| 1594 | + 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 |
|
| 1595 | + 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 |
|
| 1596 | 1596 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
| 1597 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1598 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1599 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1597 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1598 | + if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1599 | + $sql .= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1600 | 1600 | } else {
|
| 1601 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1602 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1601 | + $sql .= " AND ug.fk_user = te.rowid"; |
|
| 1602 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1603 | 1603 | } |
| 1604 | 1604 | } else {
|
| 1605 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1605 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1606 | 1606 | } |
| 1607 | 1607 | } |
| 1608 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1609 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1610 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1608 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
| 1609 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
| 1610 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
| 1611 | 1611 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1612 | 1612 | |
| 1613 | 1613 | $result = $this->db->query($sql); |
| 1614 | - if (! $result) |
|
| 1614 | + if (!$result) |
|
| 1615 | 1615 | {
|
| 1616 | - $this->error=$this->db->lasterror(); |
|
| 1616 | + $this->error = $this->db->lasterror(); |
|
| 1617 | 1617 | return -1; |
| 1618 | 1618 | } |
| 1619 | 1619 | $row = $this->db->fetch_row($result); |
@@ -1621,46 +1621,46 @@ discard block |
||
| 1621 | 1621 | |
| 1622 | 1622 | |
| 1623 | 1623 | $sql = "SELECT MIN(te.".$fieldid.")"; |
| 1624 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1625 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1626 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1627 | - } |
|
| 1628 | - 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 |
|
| 1629 | - 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 |
|
| 1630 | - 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 |
|
| 1631 | - 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"; |
|
| 1632 | - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1633 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1634 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1635 | - if (! empty($filter)) |
|
| 1636 | - {
|
|
| 1637 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1638 | - $sql.=$filter; |
|
| 1639 | - } |
|
| 1640 | - 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 |
|
| 1641 | - 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 |
|
| 1624 | + $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1625 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1626 | + $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1627 | + } |
|
| 1628 | + 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 |
|
| 1629 | + 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 |
|
| 1630 | + 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 |
|
| 1631 | + 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"; |
|
| 1632 | + $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1633 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id; |
|
| 1634 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql .= " AND (sc.fk_user = ".$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1635 | + if (!empty($filter)) |
|
| 1636 | + {
|
|
| 1637 | + if (!preg_match('/^\s*AND/i', $filter)) $sql .= " AND "; // For backward compatibility
|
|
| 1638 | + $sql .= $filter; |
|
| 1639 | + } |
|
| 1640 | + 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 |
|
| 1641 | + 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 |
|
| 1642 | 1642 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
| 1643 | - if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1644 | - if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1645 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1643 | + if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1644 | + if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
|
| 1645 | + $sql .= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1646 | 1646 | } else {
|
| 1647 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1648 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1647 | + $sql .= " AND ug.fk_user = te.rowid"; |
|
| 1648 | + $sql .= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1649 | 1649 | } |
| 1650 | 1650 | } else {
|
| 1651 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1651 | + $sql .= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1652 | 1652 | } |
| 1653 | 1653 | } |
| 1654 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1655 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1656 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1654 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql .= ' AND te.fk_soc = '.$socid; |
|
| 1655 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql .= ' AND (te.fk_soc = '.$socid.' OR te.fk_soc IS NULL)'; |
|
| 1656 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql .= ' AND te.rowid = '.$socid; |
|
| 1657 | 1657 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1658 | 1658 | // 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 |
| 1659 | 1659 | |
| 1660 | 1660 | $result = $this->db->query($sql); |
| 1661 | - if (! $result) |
|
| 1661 | + if (!$result) |
|
| 1662 | 1662 | {
|
| 1663 | - $this->error=$this->db->lasterror(); |
|
| 1663 | + $this->error = $this->db->lasterror(); |
|
| 1664 | 1664 | return -2; |
| 1665 | 1665 | } |
| 1666 | 1666 | $row = $this->db->fetch_row($result); |
@@ -1677,11 +1677,11 @@ discard block |
||
| 1677 | 1677 | * @return array Array of id of contacts (if source=external or internal) |
| 1678 | 1678 | * Array of id of third parties with at least one contact on object (if source=thirdparty) |
| 1679 | 1679 | */ |
| 1680 | - function getListContactId($source='external') |
|
| 1680 | + function getListContactId($source = 'external') |
|
| 1681 | 1681 | {
|
| 1682 | 1682 | $contactAlreadySelected = array(); |
| 1683 | - $tab = $this->liste_contact(-1,$source); |
|
| 1684 | - $num=count($tab); |
|
| 1683 | + $tab = $this->liste_contact(-1, $source); |
|
| 1684 | + $num = count($tab); |
|
| 1685 | 1685 | $i = 0; |
| 1686 | 1686 | while ($i < $num) |
| 1687 | 1687 | {
|
@@ -1701,24 +1701,24 @@ discard block |
||
| 1701 | 1701 | */ |
| 1702 | 1702 | function setProject($projectid) |
| 1703 | 1703 | {
|
| 1704 | - if (! $this->table_element) |
|
| 1704 | + if (!$this->table_element) |
|
| 1705 | 1705 | {
|
| 1706 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1706 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined", LOG_ERR); |
|
| 1707 | 1707 | return -1; |
| 1708 | 1708 | } |
| 1709 | 1709 | |
| 1710 | 1710 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1711 | 1711 | if ($this->table_element == 'actioncomm') |
| 1712 | 1712 | {
|
| 1713 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1714 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1715 | - $sql.= ' WHERE id = '.$this->id; |
|
| 1713 | + if ($projectid) $sql .= ' SET fk_project = '.$projectid; |
|
| 1714 | + else $sql .= ' SET fk_project = NULL'; |
|
| 1715 | + $sql .= ' WHERE id = '.$this->id; |
|
| 1716 | 1716 | } |
| 1717 | 1717 | else |
| 1718 | 1718 | {
|
| 1719 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1720 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1721 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 1719 | + if ($projectid) $sql .= ' SET fk_projet = '.$projectid; |
|
| 1720 | + else $sql .= ' SET fk_projet = NULL'; |
|
| 1721 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 1722 | 1722 | } |
| 1723 | 1723 | |
| 1724 | 1724 | dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
@@ -1764,14 +1764,14 @@ discard block |
||
| 1764 | 1764 | else |
| 1765 | 1765 | {
|
| 1766 | 1766 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
| 1767 | - $this->error=$this->db->error(); |
|
| 1767 | + $this->error = $this->db->error(); |
|
| 1768 | 1768 | return -1; |
| 1769 | 1769 | } |
| 1770 | 1770 | } |
| 1771 | 1771 | else |
| 1772 | 1772 | {
|
| 1773 | 1773 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
| 1774 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1774 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1775 | 1775 | return -2; |
| 1776 | 1776 | } |
| 1777 | 1777 | } |
@@ -1798,21 +1798,21 @@ discard block |
||
| 1798 | 1798 | $this->multicurrency_code = $code; |
| 1799 | 1799 | |
| 1800 | 1800 | list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
| 1801 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 1801 | + if ($rate) $this->setMulticurrencyRate($rate, 2); |
|
| 1802 | 1802 | |
| 1803 | 1803 | return 1; |
| 1804 | 1804 | } |
| 1805 | 1805 | else |
| 1806 | 1806 | {
|
| 1807 | 1807 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
| 1808 | - $this->error=$this->db->error(); |
|
| 1808 | + $this->error = $this->db->error(); |
|
| 1809 | 1809 | return -1; |
| 1810 | 1810 | } |
| 1811 | 1811 | } |
| 1812 | 1812 | else |
| 1813 | 1813 | {
|
| 1814 | 1814 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
| 1815 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1815 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1816 | 1816 | return -2; |
| 1817 | 1817 | } |
| 1818 | 1818 | } |
@@ -1824,7 +1824,7 @@ discard block |
||
| 1824 | 1824 | * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
| 1825 | 1825 | * @return int >0 if OK, <0 if KO |
| 1826 | 1826 | */ |
| 1827 | - function setMulticurrencyRate($rate, $mode=1) |
|
| 1827 | + function setMulticurrencyRate($rate, $mode = 1) |
|
| 1828 | 1828 | {
|
| 1829 | 1829 | dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')');
|
| 1830 | 1830 | if ($this->statut >= 0 || $this->element == 'societe') |
@@ -1844,7 +1844,7 @@ discard block |
||
| 1844 | 1844 | {
|
| 1845 | 1845 | foreach ($this->lines as &$line) |
| 1846 | 1846 | {
|
| 1847 | - if($mode == 1) {
|
|
| 1847 | + if ($mode == 1) {
|
|
| 1848 | 1848 | $line->subprice = 0; |
| 1849 | 1849 | } |
| 1850 | 1850 | |
@@ -1852,14 +1852,14 @@ discard block |
||
| 1852 | 1852 | case 'propal': |
| 1853 | 1853 | $this->updateline( |
| 1854 | 1854 | $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
| 1855 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1855 | + ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1856 | 1856 | $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
| 1857 | 1857 | $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
| 1858 | 1858 | ); |
| 1859 | 1859 | break; |
| 1860 | 1860 | case 'commande': |
| 1861 | 1861 | $this->updateline( |
| 1862 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1862 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1863 | 1863 | $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
| 1864 | 1864 | $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
| 1865 | 1865 | $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
@@ -1867,7 +1867,7 @@ discard block |
||
| 1867 | 1867 | break; |
| 1868 | 1868 | case 'facture': |
| 1869 | 1869 | $this->updateline( |
| 1870 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1870 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1871 | 1871 | $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
| 1872 | 1872 | $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
| 1873 | 1873 | $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
@@ -1876,21 +1876,21 @@ discard block |
||
| 1876 | 1876 | case 'supplier_proposal': |
| 1877 | 1877 | $this->updateline( |
| 1878 | 1878 | $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
| 1879 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1879 | + ($line->description ? $line->description : $line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1880 | 1880 | $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
| 1881 | 1881 | $line->ref_fourn, $line->multicurrency_subprice |
| 1882 | 1882 | ); |
| 1883 | 1883 | break; |
| 1884 | 1884 | case 'order_supplier': |
| 1885 | 1885 | $this->updateline( |
| 1886 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1886 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1887 | 1887 | $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
| 1888 | 1888 | $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
| 1889 | 1889 | ); |
| 1890 | 1890 | break; |
| 1891 | 1891 | case 'invoice_supplier': |
| 1892 | 1892 | $this->updateline( |
| 1893 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1893 | + $line->id, ($line->description ? $line->description : $line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1894 | 1894 | $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
| 1895 | 1895 | $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
| 1896 | 1896 | ); |
@@ -1907,14 +1907,14 @@ discard block |
||
| 1907 | 1907 | else |
| 1908 | 1908 | {
|
| 1909 | 1909 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
| 1910 | - $this->error=$this->db->error(); |
|
| 1910 | + $this->error = $this->db->error(); |
|
| 1911 | 1911 | return -1; |
| 1912 | 1912 | } |
| 1913 | 1913 | } |
| 1914 | 1914 | else |
| 1915 | 1915 | {
|
| 1916 | 1916 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
| 1917 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1917 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1918 | 1918 | return -2; |
| 1919 | 1919 | } |
| 1920 | 1920 | } |
@@ -1944,20 +1944,20 @@ discard block |
||
| 1944 | 1944 | $this->cond_reglement_id = $id; |
| 1945 | 1945 | // for supplier |
| 1946 | 1946 | if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
| 1947 | - $this->cond_reglement = $id; // for compatibility |
|
| 1947 | + $this->cond_reglement = $id; // for compatibility |
|
| 1948 | 1948 | return 1; |
| 1949 | 1949 | } |
| 1950 | 1950 | else |
| 1951 | 1951 | {
|
| 1952 | 1952 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
| 1953 | - $this->error=$this->db->error(); |
|
| 1953 | + $this->error = $this->db->error(); |
|
| 1954 | 1954 | return -1; |
| 1955 | 1955 | } |
| 1956 | 1956 | } |
| 1957 | 1957 | else |
| 1958 | 1958 | {
|
| 1959 | 1959 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
| 1960 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1960 | + $this->error = 'Status of the object is incompatible '.$this->statut; |
|
| 1961 | 1961 | return -2; |
| 1962 | 1962 | } |
| 1963 | 1963 | } |
@@ -1975,7 +1975,7 @@ discard block |
||
| 1975 | 1975 | if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
| 1976 | 1976 | |
| 1977 | 1977 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
| 1978 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1978 | + $sql .= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1979 | 1979 | |
| 1980 | 1980 | if ($this->db->query($sql)) |
| 1981 | 1981 | {
|
@@ -1984,7 +1984,7 @@ discard block |
||
| 1984 | 1984 | } |
| 1985 | 1985 | else |
| 1986 | 1986 | {
|
| 1987 | - $this->error=$this->db->error(); |
|
| 1987 | + $this->error = $this->db->error(); |
|
| 1988 | 1988 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
| 1989 | 1989 | return -1; |
| 1990 | 1990 | } |
@@ -2000,29 +2000,29 @@ discard block |
||
| 2000 | 2000 | * |
| 2001 | 2001 | * @return int 1 if OK, 0 if KO |
| 2002 | 2002 | */ |
| 2003 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 2003 | + function setShippingMethod($shipping_method_id, $notrigger = false, $userused = null) |
|
| 2004 | 2004 | {
|
| 2005 | 2005 | global $user; |
| 2006 | 2006 | |
| 2007 | - if (empty($userused)) $userused=$user; |
|
| 2007 | + if (empty($userused)) $userused = $user; |
|
| 2008 | 2008 | |
| 2009 | 2009 | $error = 0; |
| 2010 | 2010 | |
| 2011 | - if (! $this->table_element) {
|
|
| 2012 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 2011 | + if (!$this->table_element) {
|
|
| 2012 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined", LOG_ERR); |
|
| 2013 | 2013 | return -1; |
| 2014 | 2014 | } |
| 2015 | 2015 | |
| 2016 | 2016 | $this->db->begin(); |
| 2017 | 2017 | |
| 2018 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2018 | + if ($shipping_method_id < 0) $shipping_method_id = 'NULL'; |
|
| 2019 | 2019 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
| 2020 | 2020 | |
| 2021 | 2021 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2022 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2023 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2022 | + $sql .= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2023 | + $sql .= " WHERE rowid=".$this->id; |
|
| 2024 | 2024 | $resql = $this->db->query($sql); |
| 2025 | - if (! $resql) {
|
|
| 2025 | + if (!$resql) {
|
|
| 2026 | 2026 | dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
| 2027 | 2027 | $this->error = $this->db->lasterror(); |
| 2028 | 2028 | $error++; |
@@ -2030,8 +2030,8 @@ discard block |
||
| 2030 | 2030 | if (!$notrigger) |
| 2031 | 2031 | {
|
| 2032 | 2032 | // Call trigger |
| 2033 | - $this->context=array('shippingmethodupdate'=>1);
|
|
| 2034 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2033 | + $this->context = array('shippingmethodupdate'=>1);
|
|
| 2034 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
| 2035 | 2035 | if ($result < 0) $error++; |
| 2036 | 2036 | // End call trigger |
| 2037 | 2037 | } |
@@ -2041,7 +2041,7 @@ discard block |
||
| 2041 | 2041 | $this->db->rollback(); |
| 2042 | 2042 | return -1; |
| 2043 | 2043 | } else {
|
| 2044 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 2044 | + $this->shipping_method_id = ($shipping_method_id == 'NULL') ?null:$shipping_method_id; |
|
| 2045 | 2045 | $this->db->commit(); |
| 2046 | 2046 | return 1; |
| 2047 | 2047 | } |
@@ -2056,23 +2056,23 @@ discard block |
||
| 2056 | 2056 | */ |
| 2057 | 2057 | function setWarehouse($warehouse_id) |
| 2058 | 2058 | {
|
| 2059 | - if (! $this->table_element) {
|
|
| 2060 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 2059 | + if (!$this->table_element) {
|
|
| 2060 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined", LOG_ERR); |
|
| 2061 | 2061 | return -1; |
| 2062 | 2062 | } |
| 2063 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2063 | + if ($warehouse_id < 0) $warehouse_id = 'NULL'; |
|
| 2064 | 2064 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
| 2065 | 2065 | |
| 2066 | 2066 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2067 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 2068 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2067 | + $sql .= " SET fk_warehouse = ".$warehouse_id; |
|
| 2068 | + $sql .= " WHERE rowid=".$this->id; |
|
| 2069 | 2069 | |
| 2070 | 2070 | if ($this->db->query($sql)) {
|
| 2071 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 2071 | + $this->warehouse_id = ($warehouse_id == 'NULL') ?null:$warehouse_id; |
|
| 2072 | 2072 | return 1; |
| 2073 | 2073 | } else {
|
| 2074 | 2074 | dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
| 2075 | - $this->error=$this->db->error(); |
|
| 2075 | + $this->error = $this->db->error(); |
|
| 2076 | 2076 | return 0; |
| 2077 | 2077 | } |
| 2078 | 2078 | } |
@@ -2087,25 +2087,25 @@ discard block |
||
| 2087 | 2087 | */ |
| 2088 | 2088 | function setDocModel($user, $modelpdf) |
| 2089 | 2089 | {
|
| 2090 | - if (! $this->table_element) |
|
| 2090 | + if (!$this->table_element) |
|
| 2091 | 2091 | {
|
| 2092 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 2092 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined", LOG_ERR); |
|
| 2093 | 2093 | return -1; |
| 2094 | 2094 | } |
| 2095 | 2095 | |
| 2096 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 2096 | + $newmodelpdf = dol_trunc($modelpdf, 255); |
|
| 2097 | 2097 | |
| 2098 | 2098 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2099 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2100 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 2099 | + $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2100 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 2101 | 2101 | // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
| 2102 | 2102 | // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
| 2103 | 2103 | |
| 2104 | 2104 | dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
| 2105 | - $resql=$this->db->query($sql); |
|
| 2105 | + $resql = $this->db->query($sql); |
|
| 2106 | 2106 | if ($resql) |
| 2107 | 2107 | {
|
| 2108 | - $this->modelpdf=$modelpdf; |
|
| 2108 | + $this->modelpdf = $modelpdf; |
|
| 2109 | 2109 | return 1; |
| 2110 | 2110 | } |
| 2111 | 2111 | else |
@@ -2124,29 +2124,29 @@ discard block |
||
| 2124 | 2124 | * @param User $userused Object user |
| 2125 | 2125 | * @return int 1 if OK, 0 if KO |
| 2126 | 2126 | */ |
| 2127 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 2127 | + function setBankAccount($fk_account, $notrigger = false, $userused = null) |
|
| 2128 | 2128 | {
|
| 2129 | 2129 | global $user; |
| 2130 | 2130 | |
| 2131 | - if (empty($userused)) $userused=$user; |
|
| 2131 | + if (empty($userused)) $userused = $user; |
|
| 2132 | 2132 | |
| 2133 | 2133 | $error = 0; |
| 2134 | 2134 | |
| 2135 | - if (! $this->table_element) {
|
|
| 2136 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 2135 | + if (!$this->table_element) {
|
|
| 2136 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined", LOG_ERR); |
|
| 2137 | 2137 | return -1; |
| 2138 | 2138 | } |
| 2139 | 2139 | $this->db->begin(); |
| 2140 | 2140 | |
| 2141 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2141 | + if ($fk_account < 0) $fk_account = 'NULL'; |
|
| 2142 | 2142 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
| 2143 | 2143 | |
| 2144 | 2144 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 2145 | - $sql.= " SET fk_account = ".$fk_account; |
|
| 2146 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2145 | + $sql .= " SET fk_account = ".$fk_account; |
|
| 2146 | + $sql .= " WHERE rowid=".$this->id; |
|
| 2147 | 2147 | |
| 2148 | 2148 | $resql = $this->db->query($sql); |
| 2149 | - if (! $resql) |
|
| 2149 | + if (!$resql) |
|
| 2150 | 2150 | {
|
| 2151 | 2151 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
| 2152 | 2152 | $this->error = $this->db->lasterror(); |
@@ -2157,8 +2157,8 @@ discard block |
||
| 2157 | 2157 | if (!$notrigger) |
| 2158 | 2158 | {
|
| 2159 | 2159 | // Call trigger |
| 2160 | - $this->context=array('bankaccountupdate'=>1);
|
|
| 2161 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2160 | + $this->context = array('bankaccountupdate'=>1);
|
|
| 2161 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $userused); |
|
| 2162 | 2162 | if ($result < 0) $error++; |
| 2163 | 2163 | // End call trigger |
| 2164 | 2164 | } |
@@ -2170,7 +2170,7 @@ discard block |
||
| 2170 | 2170 | } |
| 2171 | 2171 | else |
| 2172 | 2172 | {
|
| 2173 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 2173 | + $this->fk_account = ($fk_account == 'NULL') ?null:$fk_account; |
|
| 2174 | 2174 | $this->db->commit(); |
| 2175 | 2175 | return 1; |
| 2176 | 2176 | } |
@@ -2189,26 +2189,26 @@ discard block |
||
| 2189 | 2189 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2190 | 2190 | * @return int <0 if KO, >0 if OK |
| 2191 | 2191 | */ |
| 2192 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2192 | + function line_order($renum = false, $rowidorder = 'ASC', $fk_parent_line = true) |
|
| 2193 | 2193 | {
|
| 2194 | 2194 | // phpcs:enable |
| 2195 | - if (! $this->table_element_line) |
|
| 2195 | + if (!$this->table_element_line) |
|
| 2196 | 2196 | {
|
| 2197 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2197 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined", LOG_ERR); |
|
| 2198 | 2198 | return -1; |
| 2199 | 2199 | } |
| 2200 | - if (! $this->fk_element) |
|
| 2200 | + if (!$this->fk_element) |
|
| 2201 | 2201 | {
|
| 2202 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2202 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined", LOG_ERR); |
|
| 2203 | 2203 | return -1; |
| 2204 | 2204 | } |
| 2205 | 2205 | |
| 2206 | 2206 | // Count number of lines to reorder (according to choice $renum) |
| 2207 | - $nl=0; |
|
| 2207 | + $nl = 0; |
|
| 2208 | 2208 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2209 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2210 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2211 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2209 | + $sql .= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2210 | + if (!$renum) $sql .= ' AND rang = 0'; |
|
| 2211 | + if ($renum) $sql .= ' AND rang <> 0'; |
|
| 2212 | 2212 | |
| 2213 | 2213 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
| 2214 | 2214 | $resql = $this->db->query($sql); |
@@ -2222,28 +2222,28 @@ discard block |
||
| 2222 | 2222 | {
|
| 2223 | 2223 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
| 2224 | 2224 | // counter that parents. |
| 2225 | - $rows=array(); |
|
| 2225 | + $rows = array(); |
|
| 2226 | 2226 | |
| 2227 | 2227 | // We first search all lines that are parent lines (for multilevel details lines) |
| 2228 | 2228 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2229 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2230 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2231 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2229 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2230 | + if ($fk_parent_line) $sql .= ' AND fk_parent_line IS NULL'; |
|
| 2231 | + $sql .= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2232 | 2232 | |
| 2233 | 2233 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
| 2234 | 2234 | $resql = $this->db->query($sql); |
| 2235 | 2235 | if ($resql) |
| 2236 | 2236 | {
|
| 2237 | - $i=0; |
|
| 2237 | + $i = 0; |
|
| 2238 | 2238 | $num = $this->db->num_rows($resql); |
| 2239 | 2239 | while ($i < $num) |
| 2240 | 2240 | {
|
| 2241 | 2241 | $row = $this->db->fetch_row($resql); |
| 2242 | - $rows[] = $row[0]; // Add parent line into array rows |
|
| 2242 | + $rows[] = $row[0]; // Add parent line into array rows |
|
| 2243 | 2243 | $childrens = $this->getChildrenOfLine($row[0]); |
| 2244 | - if (! empty($childrens)) |
|
| 2244 | + if (!empty($childrens)) |
|
| 2245 | 2245 | {
|
| 2246 | - foreach($childrens as $child) |
|
| 2246 | + foreach ($childrens as $child) |
|
| 2247 | 2247 | {
|
| 2248 | 2248 | array_push($rows, $child); |
| 2249 | 2249 | } |
@@ -2252,11 +2252,11 @@ discard block |
||
| 2252 | 2252 | } |
| 2253 | 2253 | |
| 2254 | 2254 | // Now we set a new number for each lines (parent and children with children included into parent tree) |
| 2255 | - if (! empty($rows)) |
|
| 2255 | + if (!empty($rows)) |
|
| 2256 | 2256 | {
|
| 2257 | - foreach($rows as $key => $row) |
|
| 2257 | + foreach ($rows as $key => $row) |
|
| 2258 | 2258 | {
|
| 2259 | - $this->updateRangOfLine($row, ($key+1)); |
|
| 2259 | + $this->updateRangOfLine($row, ($key + 1)); |
|
| 2260 | 2260 | } |
| 2261 | 2261 | } |
| 2262 | 2262 | } |
@@ -2276,18 +2276,18 @@ discard block |
||
| 2276 | 2276 | */ |
| 2277 | 2277 | function getChildrenOfLine($id) |
| 2278 | 2278 | {
|
| 2279 | - $rows=array(); |
|
| 2279 | + $rows = array(); |
|
| 2280 | 2280 | |
| 2281 | 2281 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2282 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2283 | - $sql.= ' AND fk_parent_line = '.$id; |
|
| 2284 | - $sql.= ' ORDER BY rang ASC'; |
|
| 2282 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2283 | + $sql .= ' AND fk_parent_line = '.$id; |
|
| 2284 | + $sql .= ' ORDER BY rang ASC'; |
|
| 2285 | 2285 | |
| 2286 | 2286 | dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
| 2287 | 2287 | $resql = $this->db->query($sql); |
| 2288 | 2288 | if ($resql) |
| 2289 | 2289 | {
|
| 2290 | - $i=0; |
|
| 2290 | + $i = 0; |
|
| 2291 | 2291 | $num = $this->db->num_rows($resql); |
| 2292 | 2292 | while ($i < $num) |
| 2293 | 2293 | {
|
@@ -2308,7 +2308,7 @@ discard block |
||
| 2308 | 2308 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2309 | 2309 | * @return void |
| 2310 | 2310 | */ |
| 2311 | - function line_up($rowid, $fk_parent_line=true) |
|
| 2311 | + function line_up($rowid, $fk_parent_line = true) |
|
| 2312 | 2312 | {
|
| 2313 | 2313 | // phpcs:enable |
| 2314 | 2314 | $this->line_order(false, 'ASC', $fk_parent_line); |
@@ -2328,7 +2328,7 @@ discard block |
||
| 2328 | 2328 | * @param boolean $fk_parent_line Table with fk_parent_line field or not |
| 2329 | 2329 | * @return void |
| 2330 | 2330 | */ |
| 2331 | - function line_down($rowid, $fk_parent_line=true) |
|
| 2331 | + function line_down($rowid, $fk_parent_line = true) |
|
| 2332 | 2332 | {
|
| 2333 | 2333 | // phpcs:enable |
| 2334 | 2334 | $this->line_order(false, 'ASC', $fk_parent_line); |
@@ -2350,16 +2350,16 @@ discard block |
||
| 2350 | 2350 | * @param int $rang Position |
| 2351 | 2351 | * @return void |
| 2352 | 2352 | */ |
| 2353 | - function updateRangOfLine($rowid,$rang) |
|
| 2353 | + function updateRangOfLine($rowid, $rang) |
|
| 2354 | 2354 | {
|
| 2355 | 2355 | $fieldposition = 'rang'; |
| 2356 | 2356 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
| 2357 | 2357 | |
| 2358 | 2358 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2359 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2359 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2360 | 2360 | |
| 2361 | 2361 | dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
| 2362 | - if (! $this->db->query($sql)) |
|
| 2362 | + if (!$this->db->query($sql)) |
|
| 2363 | 2363 | {
|
| 2364 | 2364 | dol_print_error($this->db); |
| 2365 | 2365 | } |
@@ -2376,9 +2376,9 @@ discard block |
||
| 2376 | 2376 | {
|
| 2377 | 2377 | // phpcs:enable |
| 2378 | 2378 | $num = count($rows); |
| 2379 | - for ($i = 0 ; $i < $num ; $i++) |
|
| 2379 | + for ($i = 0; $i < $num; $i++) |
|
| 2380 | 2380 | {
|
| 2381 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2381 | + $this->updateRangOfLine($rows[$i], ($i + 1)); |
|
| 2382 | 2382 | } |
| 2383 | 2383 | } |
| 2384 | 2384 | |
@@ -2389,21 +2389,21 @@ discard block |
||
| 2389 | 2389 | * @param int $rang Position |
| 2390 | 2390 | * @return void |
| 2391 | 2391 | */ |
| 2392 | - function updateLineUp($rowid,$rang) |
|
| 2392 | + function updateLineUp($rowid, $rang) |
|
| 2393 | 2393 | {
|
| 2394 | 2394 | if ($rang > 1) |
| 2395 | 2395 | {
|
| 2396 | 2396 | $fieldposition = 'rang'; |
| 2397 | 2397 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
| 2398 | 2398 | |
| 2399 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
| 2400 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2401 | - $sql.= ' AND rang = '.($rang - 1); |
|
| 2402 | - if ($this->db->query($sql) ) |
|
| 2399 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2400 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2401 | + $sql .= ' AND rang = '.($rang - 1); |
|
| 2402 | + if ($this->db->query($sql)) |
|
| 2403 | 2403 | {
|
| 2404 | 2404 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
| 2405 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2406 | - if (! $this->db->query($sql) ) |
|
| 2405 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2406 | + if (!$this->db->query($sql)) |
|
| 2407 | 2407 | {
|
| 2408 | 2408 | dol_print_error($this->db); |
| 2409 | 2409 | } |
@@ -2423,7 +2423,7 @@ discard block |
||
| 2423 | 2423 | * @param int $max Max |
| 2424 | 2424 | * @return void |
| 2425 | 2425 | */ |
| 2426 | - function updateLineDown($rowid,$rang,$max) |
|
| 2426 | + function updateLineDown($rowid, $rang, $max) |
|
| 2427 | 2427 | {
|
| 2428 | 2428 | if ($rang < $max) |
| 2429 | 2429 | {
|
@@ -2431,13 +2431,13 @@ discard block |
||
| 2431 | 2431 | if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
| 2432 | 2432 | |
| 2433 | 2433 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2434 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2435 | - $sql.= ' AND rang = '.($rang+1); |
|
| 2436 | - if ($this->db->query($sql) ) |
|
| 2434 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2435 | + $sql .= ' AND rang = '.($rang + 1); |
|
| 2436 | + if ($this->db->query($sql)) |
|
| 2437 | 2437 | {
|
| 2438 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
| 2439 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2440 | - if (! $this->db->query($sql) ) |
|
| 2438 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang + 1); |
|
| 2439 | + $sql .= ' WHERE rowid = '.$rowid; |
|
| 2440 | + if (!$this->db->query($sql)) |
|
| 2441 | 2441 | {
|
| 2442 | 2442 | dol_print_error($this->db); |
| 2443 | 2443 | } |
@@ -2458,7 +2458,7 @@ discard block |
||
| 2458 | 2458 | function getRangOfLine($rowid) |
| 2459 | 2459 | {
|
| 2460 | 2460 | $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2461 | - $sql.= ' WHERE rowid ='.$rowid; |
|
| 2461 | + $sql .= ' WHERE rowid ='.$rowid; |
|
| 2462 | 2462 | |
| 2463 | 2463 | dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
| 2464 | 2464 | $resql = $this->db->query($sql); |
@@ -2478,8 +2478,8 @@ discard block |
||
| 2478 | 2478 | function getIdOfLine($rang) |
| 2479 | 2479 | {
|
| 2480 | 2480 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2481 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2482 | - $sql.= ' AND rang = '.$rang; |
|
| 2481 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2482 | + $sql .= ' AND rang = '.$rang; |
|
| 2483 | 2483 | $resql = $this->db->query($sql); |
| 2484 | 2484 | if ($resql) |
| 2485 | 2485 | {
|
@@ -2495,22 +2495,22 @@ discard block |
||
| 2495 | 2495 | * @param int $fk_parent_line Parent line id |
| 2496 | 2496 | * @return int Max value of rang in table of lines |
| 2497 | 2497 | */ |
| 2498 | - function line_max($fk_parent_line=0) |
|
| 2498 | + function line_max($fk_parent_line = 0) |
|
| 2499 | 2499 | {
|
| 2500 | 2500 | // phpcs:enable |
| 2501 | 2501 | // Search the last rang with fk_parent_line |
| 2502 | 2502 | if ($fk_parent_line) |
| 2503 | 2503 | {
|
| 2504 | 2504 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2505 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2506 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2505 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2506 | + $sql .= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2507 | 2507 | |
| 2508 | 2508 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
| 2509 | 2509 | $resql = $this->db->query($sql); |
| 2510 | 2510 | if ($resql) |
| 2511 | 2511 | {
|
| 2512 | 2512 | $row = $this->db->fetch_row($resql); |
| 2513 | - if (! empty($row[0])) |
|
| 2513 | + if (!empty($row[0])) |
|
| 2514 | 2514 | {
|
| 2515 | 2515 | return $row[0]; |
| 2516 | 2516 | } |
@@ -2524,7 +2524,7 @@ discard block |
||
| 2524 | 2524 | else |
| 2525 | 2525 | {
|
| 2526 | 2526 | $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2527 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2527 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2528 | 2528 | |
| 2529 | 2529 | dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
| 2530 | 2530 | $resql = $this->db->query($sql); |
@@ -2546,15 +2546,15 @@ discard block |
||
| 2546 | 2546 | function update_ref_ext($ref_ext) |
| 2547 | 2547 | {
|
| 2548 | 2548 | // phpcs:enable |
| 2549 | - if (! $this->table_element) |
|
| 2549 | + if (!$this->table_element) |
|
| 2550 | 2550 | {
|
| 2551 | 2551 | dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
| 2552 | 2552 | return -1; |
| 2553 | 2553 | } |
| 2554 | 2554 | |
| 2555 | 2555 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2556 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2557 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2556 | + $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2557 | + $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".$this->id; |
|
| 2558 | 2558 | |
| 2559 | 2559 | dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
| 2560 | 2560 | if ($this->db->query($sql)) |
@@ -2564,7 +2564,7 @@ discard block |
||
| 2564 | 2564 | } |
| 2565 | 2565 | else |
| 2566 | 2566 | {
|
| 2567 | - $this->error=$this->db->error(); |
|
| 2567 | + $this->error = $this->db->error(); |
|
| 2568 | 2568 | return -1; |
| 2569 | 2569 | } |
| 2570 | 2570 | } |
@@ -2577,31 +2577,31 @@ discard block |
||
| 2577 | 2577 | * @param string $suffix '', '_public' or '_private' |
| 2578 | 2578 | * @return int <0 if KO, >0 if OK |
| 2579 | 2579 | */ |
| 2580 | - function update_note($note, $suffix='') |
|
| 2580 | + function update_note($note, $suffix = '') |
|
| 2581 | 2581 | {
|
| 2582 | 2582 | // phpcs:enable |
| 2583 | 2583 | global $user; |
| 2584 | 2584 | |
| 2585 | - if (! $this->table_element) |
|
| 2585 | + if (!$this->table_element) |
|
| 2586 | 2586 | {
|
| 2587 | - $this->error='update_note was called on objet with property table_element not defined'; |
|
| 2587 | + $this->error = 'update_note was called on objet with property table_element not defined'; |
|
| 2588 | 2588 | dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
| 2589 | 2589 | return -1; |
| 2590 | 2590 | } |
| 2591 | - if (! in_array($suffix,array('','_public','_private')))
|
|
| 2591 | + if (!in_array($suffix, array('', '_public', '_private')))
|
|
| 2592 | 2592 | {
|
| 2593 | - $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2593 | + $this->error = 'update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2594 | 2594 | dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
| 2595 | 2595 | return -2; |
| 2596 | 2596 | } |
| 2597 | 2597 | // Special cas |
| 2598 | 2598 | //var_dump($this->table_element);exit; |
| 2599 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2599 | + if ($this->table_element == 'product') $suffix = ''; |
|
| 2600 | 2600 | |
| 2601 | 2601 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2602 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
|
| 2603 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id;
|
|
| 2604 | - $sql.= " WHERE rowid =". $this->id; |
|
| 2602 | + $sql .= " SET note".$suffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL");
|
|
| 2603 | + $sql .= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment')) ? "fk_user_mod" : "fk_user_modif")." = ".$user->id;
|
|
| 2604 | + $sql .= " WHERE rowid =".$this->id; |
|
| 2605 | 2605 | |
| 2606 | 2606 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
| 2607 | 2607 | if ($this->db->query($sql)) |
@@ -2610,14 +2610,14 @@ discard block |
||
| 2610 | 2610 | else if ($suffix == '_private') $this->note_private = $note; |
| 2611 | 2611 | else |
| 2612 | 2612 | {
|
| 2613 | - $this->note = $note; // deprecated |
|
| 2613 | + $this->note = $note; // deprecated |
|
| 2614 | 2614 | $this->note_private = $note; |
| 2615 | 2615 | } |
| 2616 | 2616 | return 1; |
| 2617 | 2617 | } |
| 2618 | 2618 | else |
| 2619 | 2619 | {
|
| 2620 | - $this->error=$this->db->lasterror(); |
|
| 2620 | + $this->error = $this->db->lasterror(); |
|
| 2621 | 2621 | return -1; |
| 2622 | 2622 | } |
| 2623 | 2623 | } |
@@ -2634,7 +2634,7 @@ discard block |
||
| 2634 | 2634 | function update_note_public($note) |
| 2635 | 2635 | {
|
| 2636 | 2636 | // phpcs:enable |
| 2637 | - return $this->update_note($note,'_public'); |
|
| 2637 | + return $this->update_note($note, '_public'); |
|
| 2638 | 2638 | } |
| 2639 | 2639 | |
| 2640 | 2640 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -2648,7 +2648,7 @@ discard block |
||
| 2648 | 2648 | * @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. |
| 2649 | 2649 | * @return int <0 if KO, >0 if OK |
| 2650 | 2650 | */ |
| 2651 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2651 | + function update_price($exclspec = 0, $roundingadjust = 'none', $nodatabaseupdate = 0, $seller = null) |
|
| 2652 | 2652 | {
|
| 2653 | 2653 | // phpcs:enable |
| 2654 | 2654 | global $conf, $hookmanager, $action; |
@@ -2668,8 +2668,8 @@ discard block |
||
| 2668 | 2668 | elseif ($this->element == 'supplier_proposal') |
| 2669 | 2669 | $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
| 2670 | 2670 | |
| 2671 | - if (! empty($MODULE)) {
|
|
| 2672 | - if (! empty($conf->global->$MODULE)) {
|
|
| 2671 | + if (!empty($MODULE)) {
|
|
| 2672 | + if (!empty($conf->global->$MODULE)) {
|
|
| 2673 | 2673 | $modsactivated = explode(',', $conf->global->$MODULE);
|
| 2674 | 2674 | foreach ($modsactivated as $mod) {
|
| 2675 | 2675 | if ($conf->$mod->enabled) |
@@ -2680,44 +2680,44 @@ discard block |
||
| 2680 | 2680 | |
| 2681 | 2681 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
| 2682 | 2682 | |
| 2683 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2683 | + if ($roundingadjust == '-1') $roundingadjust = 'auto'; // For backward compatibility |
|
| 2684 | 2684 | |
| 2685 | - $forcedroundingmode=$roundingadjust; |
|
| 2686 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2687 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2685 | + $forcedroundingmode = $roundingadjust; |
|
| 2686 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode = $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2687 | + elseif ($forcedroundingmode == 'auto') $forcedroundingmode = '0'; |
|
| 2688 | 2688 | |
| 2689 | - $error=0; |
|
| 2689 | + $error = 0; |
|
| 2690 | 2690 | |
| 2691 | 2691 | $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
| 2692 | 2692 | |
| 2693 | 2693 | // Define constants to find lines to sum |
| 2694 | - $fieldtva='total_tva'; |
|
| 2695 | - $fieldlocaltax1='total_localtax1'; |
|
| 2696 | - $fieldlocaltax2='total_localtax2'; |
|
| 2697 | - $fieldup='subprice'; |
|
| 2694 | + $fieldtva = 'total_tva'; |
|
| 2695 | + $fieldlocaltax1 = 'total_localtax1'; |
|
| 2696 | + $fieldlocaltax2 = 'total_localtax2'; |
|
| 2697 | + $fieldup = 'subprice'; |
|
| 2698 | 2698 | if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
| 2699 | 2699 | {
|
| 2700 | - $fieldtva='tva'; |
|
| 2701 | - $fieldup='pu_ht'; |
|
| 2700 | + $fieldtva = 'tva'; |
|
| 2701 | + $fieldup = 'pu_ht'; |
|
| 2702 | 2702 | } |
| 2703 | 2703 | if ($this->element == 'expensereport') |
| 2704 | 2704 | {
|
| 2705 | - $fieldup='value_unit'; |
|
| 2705 | + $fieldup = 'value_unit'; |
|
| 2706 | 2706 | } |
| 2707 | 2707 | |
| 2708 | 2708 | $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,'; |
| 2709 | - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2710 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2711 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2712 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2713 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2709 | + $sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2710 | + if ($this->table_element_line == 'facturedet') $sql .= ', situation_percent'; |
|
| 2711 | + $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2712 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2713 | + $sql .= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2714 | 2714 | if ($exclspec) |
| 2715 | 2715 | {
|
| 2716 | - $product_field='product_type'; |
|
| 2717 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2718 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2716 | + $product_field = 'product_type'; |
|
| 2717 | + if ($this->table_element_line == 'contratdet') $product_field = ''; // contratdet table has no product_type field |
|
| 2718 | + if ($product_field) $sql .= ' AND '.$product_field.' <> 9'; |
|
| 2719 | 2719 | } |
| 2720 | - $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 |
|
| 2720 | + $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 |
|
| 2721 | 2721 | |
| 2722 | 2722 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
| 2723 | 2723 | $resql = $this->db->query($sql); |
@@ -2731,7 +2731,7 @@ discard block |
||
| 2731 | 2731 | $total_ht_by_vats = array(); |
| 2732 | 2732 | $total_tva_by_vats = array(); |
| 2733 | 2733 | $total_ttc_by_vats = array(); |
| 2734 | - $this->multicurrency_total_ht = 0; |
|
| 2734 | + $this->multicurrency_total_ht = 0; |
|
| 2735 | 2735 | $this->multicurrency_total_tva = 0; |
| 2736 | 2736 | $this->multicurrency_total_ttc = 0; |
| 2737 | 2737 | |
@@ -2742,54 +2742,54 @@ discard block |
||
| 2742 | 2742 | $obj = $this->db->fetch_object($resql); |
| 2743 | 2743 | |
| 2744 | 2744 | // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
| 2745 | - $parameters=array('fk_element' => $obj->rowid);
|
|
| 2745 | + $parameters = array('fk_element' => $obj->rowid);
|
|
| 2746 | 2746 | $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
| 2747 | 2747 | |
| 2748 | 2748 | if (empty($reshook) && $forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
| 2749 | 2749 | {
|
| 2750 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2751 | - $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); |
|
| 2752 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2750 | + $localtax_array = array($obj->localtax1_type, $obj->localtax1_tx, $obj->localtax2_type, $obj->localtax2_tx); |
|
| 2751 | + $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); |
|
| 2752 | + $diff = price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2753 | 2753 | if ($diff) |
| 2754 | 2754 | {
|
| 2755 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2755 | + $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2756 | 2756 | 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);
|
| 2757 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2758 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2757 | + $resqlfix = $this->db->query($sqlfix); |
|
| 2758 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
| 2759 | 2759 | $obj->total_tva = $tmpcal[1]; |
| 2760 | 2760 | $obj->total_ttc = $tmpcal[2]; |
| 2761 | 2761 | // |
| 2762 | 2762 | } |
| 2763 | 2763 | } |
| 2764 | 2764 | |
| 2765 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2765 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2766 | 2766 | $this->total_tva += $obj->total_tva; |
| 2767 | 2767 | $this->total_localtax1 += $obj->total_localtax1; |
| 2768 | 2768 | $this->total_localtax2 += $obj->total_localtax2; |
| 2769 | 2769 | $this->total_ttc += $obj->total_ttc; |
| 2770 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2770 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2771 | 2771 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
| 2772 | 2772 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
| 2773 | 2773 | |
| 2774 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2775 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2776 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 2774 | + if (!isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate] = 0; |
|
| 2775 | + if (!isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate] = 0; |
|
| 2776 | + if (!isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate] = 0; |
|
| 2777 | 2777 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
| 2778 | 2778 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
| 2779 | 2779 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
| 2780 | 2780 | |
| 2781 | 2781 | if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
| 2782 | 2782 | {
|
| 2783 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2784 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2783 | + $tmpvat = price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2784 | + $diff = price2num($total_tva_by_vats[$obj->vatrate] - $tmpvat, 'MT', 1); |
|
| 2785 | 2785 | //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"; |
| 2786 | 2786 | if ($diff) |
| 2787 | 2787 | {
|
| 2788 | 2788 | if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; }
|
| 2789 | - $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; |
|
| 2789 | + $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; |
|
| 2790 | 2790 | 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);
|
| 2791 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2792 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2791 | + $resqlfix = $this->db->query($sqlfix); |
|
| 2792 | + if (!$resqlfix) dol_print_error($this->db, 'Failed to update line'); |
|
| 2793 | 2793 | $this->total_tva -= $diff; |
| 2794 | 2794 | $this->total_ttc -= $diff; |
| 2795 | 2795 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2801,11 +2801,11 @@ discard block |
||
| 2801 | 2801 | } |
| 2802 | 2802 | |
| 2803 | 2803 | // Add revenue stamp to total |
| 2804 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2805 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 2804 | + $this->total_ttc += isset($this->revenuestamp) ? $this->revenuestamp : 0; |
|
| 2805 | + $this->multicurrency_total_ttc += isset($this->revenuestamp) ? ($this->revenuestamp * $multicurrency_tx) : 0; |
|
| 2806 | 2806 | |
| 2807 | 2807 | // Situations totals |
| 2808 | - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
| 2808 | + if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE) |
|
| 2809 | 2809 | {
|
| 2810 | 2810 | $prev_sits = $this->get_prev_sits(); |
| 2811 | 2811 | |
@@ -2824,17 +2824,17 @@ discard block |
||
| 2824 | 2824 | $this->db->free($resql); |
| 2825 | 2825 | |
| 2826 | 2826 | // Now update global field total_ht, total_ttc and tva |
| 2827 | - $fieldht='total_ht'; |
|
| 2828 | - $fieldtva='tva'; |
|
| 2829 | - $fieldlocaltax1='localtax1'; |
|
| 2830 | - $fieldlocaltax2='localtax2'; |
|
| 2831 | - $fieldttc='total_ttc'; |
|
| 2827 | + $fieldht = 'total_ht'; |
|
| 2828 | + $fieldtva = 'tva'; |
|
| 2829 | + $fieldlocaltax1 = 'localtax1'; |
|
| 2830 | + $fieldlocaltax2 = 'localtax2'; |
|
| 2831 | + $fieldttc = 'total_ttc'; |
|
| 2832 | 2832 | // Specific code for backward compatibility with old field names |
| 2833 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2834 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2835 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2836 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2837 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 2833 | + if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht = 'total'; |
|
| 2834 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva = 'total_tva'; |
|
| 2835 | + if ($this->element == 'propal') $fieldttc = 'total'; |
|
| 2836 | + if ($this->element == 'expensereport') $fieldtva = 'total_tva'; |
|
| 2837 | + if ($this->element == 'supplier_proposal') $fieldttc = 'total'; |
|
| 2838 | 2838 | |
| 2839 | 2839 | if (empty($nodatabaseupdate)) |
| 2840 | 2840 | {
|
@@ -2851,16 +2851,16 @@ discard block |
||
| 2851 | 2851 | |
| 2852 | 2852 | |
| 2853 | 2853 | dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
| 2854 | - $resql=$this->db->query($sql); |
|
| 2855 | - if (! $resql) |
|
| 2854 | + $resql = $this->db->query($sql); |
|
| 2855 | + if (!$resql) |
|
| 2856 | 2856 | {
|
| 2857 | 2857 | $error++; |
| 2858 | - $this->error=$this->db->lasterror(); |
|
| 2859 | - $this->errors[]=$this->db->lasterror(); |
|
| 2858 | + $this->error = $this->db->lasterror(); |
|
| 2859 | + $this->errors[] = $this->db->lasterror(); |
|
| 2860 | 2860 | } |
| 2861 | 2861 | } |
| 2862 | 2862 | |
| 2863 | - if (! $error) |
|
| 2863 | + if (!$error) |
|
| 2864 | 2864 | {
|
| 2865 | 2865 | return 1; |
| 2866 | 2866 | } |
@@ -2871,7 +2871,7 @@ discard block |
||
| 2871 | 2871 | } |
| 2872 | 2872 | else |
| 2873 | 2873 | {
|
| 2874 | - dol_print_error($this->db,'Bad request in update_price'); |
|
| 2874 | + dol_print_error($this->db, 'Bad request in update_price'); |
|
| 2875 | 2875 | return -1; |
| 2876 | 2876 | } |
| 2877 | 2877 | } |
@@ -2885,30 +2885,30 @@ discard block |
||
| 2885 | 2885 | * @return int <=0 if KO, >0 if OK |
| 2886 | 2886 | * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
| 2887 | 2887 | */ |
| 2888 | - function add_object_linked($origin=null, $origin_id=null) |
|
| 2888 | + function add_object_linked($origin = null, $origin_id = null) |
|
| 2889 | 2889 | {
|
| 2890 | 2890 | // phpcs:enable |
| 2891 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2892 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2891 | + $origin = (!empty($origin) ? $origin : $this->origin); |
|
| 2892 | + $origin_id = (!empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2893 | 2893 | |
| 2894 | 2894 | // Special case |
| 2895 | - if ($origin == 'order') $origin='commande'; |
|
| 2896 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2897 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2898 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 2895 | + if ($origin == 'order') $origin = 'commande'; |
|
| 2896 | + if ($origin == 'invoice') $origin = 'facture'; |
|
| 2897 | + if ($origin == 'invoice_template') $origin = 'facturerec'; |
|
| 2898 | + if ($origin == 'supplierorder') $origin = 'order_supplier'; |
|
| 2899 | 2899 | $this->db->begin(); |
| 2900 | 2900 | |
| 2901 | 2901 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
| 2902 | - $sql.= "fk_source"; |
|
| 2903 | - $sql.= ", sourcetype"; |
|
| 2904 | - $sql.= ", fk_target"; |
|
| 2905 | - $sql.= ", targettype"; |
|
| 2906 | - $sql.= ") VALUES (";
|
|
| 2907 | - $sql.= $origin_id; |
|
| 2908 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2909 | - $sql.= ", ".$this->id; |
|
| 2910 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2911 | - $sql.= ")"; |
|
| 2902 | + $sql .= "fk_source"; |
|
| 2903 | + $sql .= ", sourcetype"; |
|
| 2904 | + $sql .= ", fk_target"; |
|
| 2905 | + $sql .= ", targettype"; |
|
| 2906 | + $sql .= ") VALUES (";
|
|
| 2907 | + $sql .= $origin_id; |
|
| 2908 | + $sql .= ", '".$this->db->escape($origin)."'"; |
|
| 2909 | + $sql .= ", ".$this->id; |
|
| 2910 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
| 2911 | + $sql .= ")"; |
|
| 2912 | 2912 | |
| 2913 | 2913 | dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
| 2914 | 2914 | if ($this->db->query($sql)) |
@@ -2918,7 +2918,7 @@ discard block |
||
| 2918 | 2918 | } |
| 2919 | 2919 | else |
| 2920 | 2920 | {
|
| 2921 | - $this->error=$this->db->lasterror(); |
|
| 2921 | + $this->error = $this->db->lasterror(); |
|
| 2922 | 2922 | $this->db->rollback(); |
| 2923 | 2923 | return 0; |
| 2924 | 2924 | } |
@@ -2946,33 +2946,33 @@ discard block |
||
| 2946 | 2946 | * @return int <0 if KO, >0 if OK |
| 2947 | 2947 | * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
| 2948 | 2948 | */ |
| 2949 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
| 2949 | + function fetchObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $clause = 'OR', $alsosametype = 1, $orderby = 'sourcetype', $loadalsoobjects = 1) |
|
| 2950 | 2950 | {
|
| 2951 | 2951 | global $conf; |
| 2952 | 2952 | |
| 2953 | - $this->linkedObjectsIds=array(); |
|
| 2954 | - $this->linkedObjects=array(); |
|
| 2953 | + $this->linkedObjectsIds = array(); |
|
| 2954 | + $this->linkedObjects = array(); |
|
| 2955 | 2955 | |
| 2956 | - $justsource=false; |
|
| 2957 | - $justtarget=false; |
|
| 2958 | - $withtargettype=false; |
|
| 2959 | - $withsourcetype=false; |
|
| 2956 | + $justsource = false; |
|
| 2957 | + $justtarget = false; |
|
| 2958 | + $withtargettype = false; |
|
| 2959 | + $withsourcetype = false; |
|
| 2960 | 2960 | |
| 2961 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2961 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid)) |
|
| 2962 | 2962 | {
|
| 2963 | - $justsource=true; // the source (id and type) is a search criteria |
|
| 2964 | - if (! empty($targettype)) $withtargettype=true; |
|
| 2963 | + $justsource = true; // the source (id and type) is a search criteria |
|
| 2964 | + if (!empty($targettype)) $withtargettype = true; |
|
| 2965 | 2965 | } |
| 2966 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2966 | + if (!empty($targetid) && !empty($targettype) && empty($sourceid)) |
|
| 2967 | 2967 | {
|
| 2968 | - $justtarget=true; // the target (id and type) is a search criteria |
|
| 2969 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2968 | + $justtarget = true; // the target (id and type) is a search criteria |
|
| 2969 | + if (!empty($sourcetype)) $withsourcetype = true; |
|
| 2970 | 2970 | } |
| 2971 | 2971 | |
| 2972 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2973 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2974 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2975 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2972 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
| 2973 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
| 2974 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2975 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
| 2976 | 2976 | |
| 2977 | 2977 | /*if (empty($sourceid) && empty($targetid)) |
| 2978 | 2978 | {
|
@@ -2982,25 +2982,25 @@ discard block |
||
| 2982 | 2982 | |
| 2983 | 2983 | // Links between objects are stored in table element_element |
| 2984 | 2984 | $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
| 2985 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2986 | - $sql.= " WHERE "; |
|
| 2985 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2986 | + $sql .= " WHERE "; |
|
| 2987 | 2987 | if ($justsource || $justtarget) |
| 2988 | 2988 | {
|
| 2989 | 2989 | if ($justsource) |
| 2990 | 2990 | {
|
| 2991 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2992 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2991 | + $sql .= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2992 | + if ($withtargettype) $sql .= " AND targettype = '".$targettype."'"; |
|
| 2993 | 2993 | } |
| 2994 | 2994 | else if ($justtarget) |
| 2995 | 2995 | {
|
| 2996 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2997 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 2996 | + $sql .= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2997 | + if ($withsourcetype) $sql .= " AND sourcetype = '".$sourcetype."'"; |
|
| 2998 | 2998 | } |
| 2999 | 2999 | } |
| 3000 | 3000 | else |
| 3001 | 3001 | {
|
| 3002 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3003 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3002 | + $sql .= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3003 | + $sql .= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3004 | 3004 | } |
| 3005 | 3005 | $sql .= ' ORDER BY '.$orderby; |
| 3006 | 3006 | |
@@ -3017,36 +3017,36 @@ discard block |
||
| 3017 | 3017 | {
|
| 3018 | 3018 | if ($justsource) |
| 3019 | 3019 | {
|
| 3020 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3020 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
| 3021 | 3021 | } |
| 3022 | 3022 | else if ($justtarget) |
| 3023 | 3023 | {
|
| 3024 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3024 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
| 3025 | 3025 | } |
| 3026 | 3026 | } |
| 3027 | 3027 | else |
| 3028 | 3028 | {
|
| 3029 | 3029 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
| 3030 | 3030 | {
|
| 3031 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3031 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid] = $obj->fk_target; |
|
| 3032 | 3032 | } |
| 3033 | 3033 | if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
| 3034 | 3034 | {
|
| 3035 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3035 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid] = $obj->fk_source; |
|
| 3036 | 3036 | } |
| 3037 | 3037 | } |
| 3038 | 3038 | $i++; |
| 3039 | 3039 | } |
| 3040 | 3040 | |
| 3041 | - if (! empty($this->linkedObjectsIds)) |
|
| 3041 | + if (!empty($this->linkedObjectsIds)) |
|
| 3042 | 3042 | {
|
| 3043 | 3043 | $tmparray = $this->linkedObjectsIds; |
| 3044 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3044 | + foreach ($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3045 | 3045 | {
|
| 3046 | 3046 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
| 3047 | 3047 | $module = $element = $subelement = $objecttype; |
| 3048 | 3048 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
| 3049 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
|
| 3049 | + && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs))
|
|
| 3050 | 3050 | {
|
| 3051 | 3051 | $module = $element = $regs[1]; |
| 3052 | 3052 | $subelement = $regs[2]; |
@@ -3054,31 +3054,31 @@ discard block |
||
| 3054 | 3054 | |
| 3055 | 3055 | $classpath = $element.'/class'; |
| 3056 | 3056 | // To work with non standard classpath or module name |
| 3057 | - if ($objecttype == 'facture') {
|
|
| 3057 | + if ($objecttype == 'facture') {
|
|
| 3058 | 3058 | $classpath = 'compta/facture/class'; |
| 3059 | 3059 | } |
| 3060 | - else if ($objecttype == 'facturerec') {
|
|
| 3060 | + else if ($objecttype == 'facturerec') {
|
|
| 3061 | 3061 | $classpath = 'compta/facture/class'; $module = 'facture'; |
| 3062 | 3062 | } |
| 3063 | - else if ($objecttype == 'propal') {
|
|
| 3063 | + else if ($objecttype == 'propal') {
|
|
| 3064 | 3064 | $classpath = 'comm/propal/class'; |
| 3065 | 3065 | } |
| 3066 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3066 | + else if ($objecttype == 'supplier_proposal') {
|
|
| 3067 | 3067 | $classpath = 'supplier_proposal/class'; |
| 3068 | 3068 | } |
| 3069 | - else if ($objecttype == 'shipping') {
|
|
| 3069 | + else if ($objecttype == 'shipping') {
|
|
| 3070 | 3070 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
| 3071 | 3071 | } |
| 3072 | - else if ($objecttype == 'delivery') {
|
|
| 3072 | + else if ($objecttype == 'delivery') {
|
|
| 3073 | 3073 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
| 3074 | 3074 | } |
| 3075 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3075 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3076 | 3076 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
| 3077 | 3077 | } |
| 3078 | - else if ($objecttype == 'fichinter') {
|
|
| 3078 | + else if ($objecttype == 'fichinter') {
|
|
| 3079 | 3079 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
| 3080 | 3080 | } |
| 3081 | - else if ($objecttype == 'subscription') {
|
|
| 3081 | + else if ($objecttype == 'subscription') {
|
|
| 3082 | 3082 | $classpath = 'adherents/class'; $module = 'adherent'; |
| 3083 | 3083 | } |
| 3084 | 3084 | |
@@ -3091,16 +3091,16 @@ discard block |
||
| 3091 | 3091 | else if ($objecttype == 'invoice_supplier') {
|
| 3092 | 3092 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
| 3093 | 3093 | } |
| 3094 | - else if ($objecttype == 'order_supplier') {
|
|
| 3094 | + else if ($objecttype == 'order_supplier') {
|
|
| 3095 | 3095 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
| 3096 | 3096 | } |
| 3097 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3097 | + else if ($objecttype == 'supplier_proposal') {
|
|
| 3098 | 3098 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
| 3099 | 3099 | } |
| 3100 | - else if ($objecttype == 'facturerec') {
|
|
| 3100 | + else if ($objecttype == 'facturerec') {
|
|
| 3101 | 3101 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
| 3102 | 3102 | } |
| 3103 | - else if ($objecttype == 'subscription') {
|
|
| 3103 | + else if ($objecttype == 'subscription') {
|
|
| 3104 | 3104 | $classfile = 'subscription'; $classname = 'Subscription'; |
| 3105 | 3105 | } |
| 3106 | 3106 | |
@@ -3113,7 +3113,7 @@ discard block |
||
| 3113 | 3113 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
| 3114 | 3114 | if (class_exists($classname)) |
| 3115 | 3115 | {
|
| 3116 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3116 | + foreach ($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3117 | 3117 | {
|
| 3118 | 3118 | $object = new $classname($this->db); |
| 3119 | 3119 | $ret = $object->fetch($objectid); |
@@ -3150,28 +3150,28 @@ discard block |
||
| 3150 | 3150 | * @return int >0 if OK, <0 if KO |
| 3151 | 3151 | * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
| 3152 | 3152 | */ |
| 3153 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 3153 | + function updateObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '') |
|
| 3154 | 3154 | {
|
| 3155 | - $updatesource=false; |
|
| 3156 | - $updatetarget=false; |
|
| 3155 | + $updatesource = false; |
|
| 3156 | + $updatetarget = false; |
|
| 3157 | 3157 | |
| 3158 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3159 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3158 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource = true; |
|
| 3159 | + else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $updatetarget = true; |
|
| 3160 | 3160 | |
| 3161 | 3161 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
| 3162 | 3162 | if ($updatesource) |
| 3163 | 3163 | {
|
| 3164 | - $sql.= "fk_source = ".$sourceid; |
|
| 3165 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3166 | - $sql.= " WHERE fk_target = ".$this->id; |
|
| 3167 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3164 | + $sql .= "fk_source = ".$sourceid; |
|
| 3165 | + $sql .= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3166 | + $sql .= " WHERE fk_target = ".$this->id; |
|
| 3167 | + $sql .= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3168 | 3168 | } |
| 3169 | 3169 | else if ($updatetarget) |
| 3170 | 3170 | {
|
| 3171 | - $sql.= "fk_target = ".$targetid; |
|
| 3172 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3173 | - $sql.= " WHERE fk_source = ".$this->id; |
|
| 3174 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3171 | + $sql .= "fk_target = ".$targetid; |
|
| 3172 | + $sql .= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3173 | + $sql .= " WHERE fk_source = ".$this->id; |
|
| 3174 | + $sql .= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3175 | 3175 | } |
| 3176 | 3176 | |
| 3177 | 3177 | dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
@@ -3181,7 +3181,7 @@ discard block |
||
| 3181 | 3181 | } |
| 3182 | 3182 | else |
| 3183 | 3183 | {
|
| 3184 | - $this->error=$this->db->lasterror(); |
|
| 3184 | + $this->error = $this->db->lasterror(); |
|
| 3185 | 3185 | return -1; |
| 3186 | 3186 | } |
| 3187 | 3187 | } |
@@ -3197,42 +3197,42 @@ discard block |
||
| 3197 | 3197 | * @return int >0 if OK, <0 if KO |
| 3198 | 3198 | * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
| 3199 | 3199 | */ |
| 3200 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 3200 | + function deleteObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $rowid = '') |
|
| 3201 | 3201 | {
|
| 3202 | - $deletesource=false; |
|
| 3203 | - $deletetarget=false; |
|
| 3202 | + $deletesource = false; |
|
| 3203 | + $deletetarget = false; |
|
| 3204 | 3204 | |
| 3205 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3206 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3205 | + if (!empty($sourceid) && !empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource = true; |
|
| 3206 | + else if (empty($sourceid) && empty($sourcetype) && !empty($targetid) && !empty($targettype)) $deletetarget = true; |
|
| 3207 | 3207 | |
| 3208 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 3209 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3210 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3211 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 3208 | + $sourceid = (!empty($sourceid) ? $sourceid : $this->id); |
|
| 3209 | + $sourcetype = (!empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3210 | + $targetid = (!empty($targetid) ? $targetid : $this->id); |
|
| 3211 | + $targettype = (!empty($targettype) ? $targettype : $this->element); |
|
| 3212 | 3212 | |
| 3213 | 3213 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
| 3214 | - $sql.= " WHERE"; |
|
| 3214 | + $sql .= " WHERE"; |
|
| 3215 | 3215 | if ($rowid > 0) |
| 3216 | 3216 | {
|
| 3217 | - $sql.=" rowid = ".$rowid; |
|
| 3217 | + $sql .= " rowid = ".$rowid; |
|
| 3218 | 3218 | } |
| 3219 | 3219 | else |
| 3220 | 3220 | {
|
| 3221 | 3221 | if ($deletesource) |
| 3222 | 3222 | {
|
| 3223 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3224 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3223 | + $sql .= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3224 | + $sql .= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3225 | 3225 | } |
| 3226 | 3226 | else if ($deletetarget) |
| 3227 | 3227 | {
|
| 3228 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3229 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3228 | + $sql .= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3229 | + $sql .= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3230 | 3230 | } |
| 3231 | 3231 | else |
| 3232 | 3232 | {
|
| 3233 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3234 | - $sql.= " OR"; |
|
| 3235 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3233 | + $sql .= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3234 | + $sql .= " OR"; |
|
| 3235 | + $sql .= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3236 | 3236 | } |
| 3237 | 3237 | } |
| 3238 | 3238 | |
@@ -3243,8 +3243,8 @@ discard block |
||
| 3243 | 3243 | } |
| 3244 | 3244 | else |
| 3245 | 3245 | {
|
| 3246 | - $this->error=$this->db->lasterror(); |
|
| 3247 | - $this->errors[]=$this->error; |
|
| 3246 | + $this->error = $this->db->lasterror(); |
|
| 3247 | + $this->errors[] = $this->error; |
|
| 3248 | 3248 | return -1; |
| 3249 | 3249 | } |
| 3250 | 3250 | } |
@@ -3258,30 +3258,30 @@ discard block |
||
| 3258 | 3258 | * @param string $trigkey Trigger key to use for trigger |
| 3259 | 3259 | * @return int <0 if KO, >0 if OK |
| 3260 | 3260 | */ |
| 3261 | - function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
| 3261 | + function setStatut($status, $elementId = null, $elementType = '', $trigkey = '') |
|
| 3262 | 3262 | {
|
| 3263 | - global $user,$langs,$conf; |
|
| 3263 | + global $user, $langs, $conf; |
|
| 3264 | 3264 | |
| 3265 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3265 | + $savElementId = $elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3266 | 3266 | |
| 3267 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3268 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3267 | + $elementId = (!empty($elementId) ? $elementId : $this->id); |
|
| 3268 | + $elementTable = (!empty($elementType) ? $elementType : $this->table_element); |
|
| 3269 | 3269 | |
| 3270 | 3270 | $this->db->begin(); |
| 3271 | 3271 | |
| 3272 | - $fieldstatus="fk_statut"; |
|
| 3273 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3274 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3275 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3276 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3277 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3278 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3272 | + $fieldstatus = "fk_statut"; |
|
| 3273 | + if ($elementTable == 'facture_rec') $fieldstatus = "suspended"; |
|
| 3274 | + if ($elementTable == 'mailing') $fieldstatus = "statut"; |
|
| 3275 | + if ($elementTable == 'cronjob') $fieldstatus = "status"; |
|
| 3276 | + if ($elementTable == 'user') $fieldstatus = "statut"; |
|
| 3277 | + if ($elementTable == 'expensereport') $fieldstatus = "fk_statut"; |
|
| 3278 | + if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus = "status"; |
|
| 3279 | 3279 | |
| 3280 | 3280 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
| 3281 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3281 | + $sql .= " SET ".$fieldstatus." = ".$status; |
|
| 3282 | 3282 | // If status = 1 = validated, update also fk_user_valid |
| 3283 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3284 | - $sql.= " WHERE rowid=".$elementId; |
|
| 3283 | + if ($status == 1 && $elementTable == 'expensereport') $sql .= ", fk_user_valid = ".$user->id; |
|
| 3284 | + $sql .= " WHERE rowid=".$elementId; |
|
| 3285 | 3285 | |
| 3286 | 3286 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
| 3287 | 3287 | if ($this->db->query($sql)) |
@@ -3291,27 +3291,27 @@ discard block |
||
| 3291 | 3291 | // Try autoset of trigkey |
| 3292 | 3292 | if (empty($trigkey)) |
| 3293 | 3293 | {
|
| 3294 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3295 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3296 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3297 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3298 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3299 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3294 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey = 'SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3295 | + if ($this->element == 'supplier_proposal' && $status == 3) $trigkey = 'SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3296 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey = 'SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3297 | + if ($this->element == 'fichinter' && $status == 3) $trigkey = 'FICHINTER_CLASSIFY_DONE'; |
|
| 3298 | + if ($this->element == 'fichinter' && $status == 2) $trigkey = 'FICHINTER_CLASSIFY_BILLED'; |
|
| 3299 | + if ($this->element == 'fichinter' && $status == 1) $trigkey = 'FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3300 | 3300 | } |
| 3301 | 3301 | |
| 3302 | 3302 | if ($trigkey) |
| 3303 | 3303 | {
|
| 3304 | 3304 | // Appel des triggers |
| 3305 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3306 | - $interface=new Interfaces($this->db); |
|
| 3307 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3305 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
| 3306 | + $interface = new Interfaces($this->db); |
|
| 3307 | + $result = $interface->run_triggers($trigkey, $this, $user, $langs, $conf); |
|
| 3308 | 3308 | if ($result < 0) {
|
| 3309 | - $error++; $this->errors=$interface->errors; |
|
| 3309 | + $error++; $this->errors = $interface->errors; |
|
| 3310 | 3310 | } |
| 3311 | 3311 | // Fin appel triggers |
| 3312 | 3312 | } |
| 3313 | 3313 | |
| 3314 | - if (! $error) |
|
| 3314 | + if (!$error) |
|
| 3315 | 3315 | {
|
| 3316 | 3316 | $this->db->commit(); |
| 3317 | 3317 | |
@@ -3326,13 +3326,13 @@ discard block |
||
| 3326 | 3326 | else |
| 3327 | 3327 | {
|
| 3328 | 3328 | $this->db->rollback(); |
| 3329 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3329 | + dol_syslog(get_class($this)."::setStatus ".$this->error, LOG_ERR); |
|
| 3330 | 3330 | return -1; |
| 3331 | 3331 | } |
| 3332 | 3332 | } |
| 3333 | 3333 | else |
| 3334 | 3334 | {
|
| 3335 | - $this->error=$this->db->lasterror(); |
|
| 3335 | + $this->error = $this->db->lasterror(); |
|
| 3336 | 3336 | $this->db->rollback(); |
| 3337 | 3337 | return -1; |
| 3338 | 3338 | } |
@@ -3346,21 +3346,21 @@ discard block |
||
| 3346 | 3346 | * @param string $ref Record ref |
| 3347 | 3347 | * @return int <0 if KO, 0 if nothing done, >0 if OK |
| 3348 | 3348 | */ |
| 3349 | - function getCanvas($id=0,$ref='') |
|
| 3349 | + function getCanvas($id = 0, $ref = '') |
|
| 3350 | 3350 | {
|
| 3351 | 3351 | global $conf; |
| 3352 | 3352 | |
| 3353 | 3353 | if (empty($id) && empty($ref)) return 0; |
| 3354 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3354 | + if (!empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3355 | 3355 | |
| 3356 | 3356 | // Clean parameters |
| 3357 | 3357 | $ref = trim($ref); |
| 3358 | 3358 | |
| 3359 | 3359 | $sql = "SELECT rowid, canvas"; |
| 3360 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3361 | - $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
|
| 3362 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3363 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3360 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3361 | + $sql .= " WHERE entity IN (".getEntity($this->element).")";
|
|
| 3362 | + if (!empty($id)) $sql .= " AND rowid = ".$id; |
|
| 3363 | + if (!empty($ref)) $sql .= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3364 | 3364 | |
| 3365 | 3365 | $resql = $this->db->query($sql); |
| 3366 | 3366 | if ($resql) |
@@ -3368,7 +3368,7 @@ discard block |
||
| 3368 | 3368 | $obj = $this->db->fetch_object($resql); |
| 3369 | 3369 | if ($obj) |
| 3370 | 3370 | {
|
| 3371 | - $this->canvas = $obj->canvas; |
|
| 3371 | + $this->canvas = $obj->canvas; |
|
| 3372 | 3372 | return 1; |
| 3373 | 3373 | } |
| 3374 | 3374 | else return 0; |
@@ -3390,7 +3390,7 @@ discard block |
||
| 3390 | 3390 | function getSpecialCode($lineid) |
| 3391 | 3391 | {
|
| 3392 | 3392 | $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 3393 | - $sql.= ' WHERE rowid = '.$lineid; |
|
| 3393 | + $sql .= ' WHERE rowid = '.$lineid; |
|
| 3394 | 3394 | $resql = $this->db->query($sql); |
| 3395 | 3395 | if ($resql) |
| 3396 | 3396 | {
|
@@ -3406,14 +3406,14 @@ discard block |
||
| 3406 | 3406 | * @param int $id Force id of object |
| 3407 | 3407 | * @return int <0 if KO, 0 if not used, >0 if already used |
| 3408 | 3408 | */ |
| 3409 | - function isObjectUsed($id=0) |
|
| 3409 | + function isObjectUsed($id = 0) |
|
| 3410 | 3410 | {
|
| 3411 | 3411 | global $langs; |
| 3412 | 3412 | |
| 3413 | - if (empty($id)) $id=$this->id; |
|
| 3413 | + if (empty($id)) $id = $this->id; |
|
| 3414 | 3414 | |
| 3415 | 3415 | // Check parameters |
| 3416 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3416 | + if (!isset($this->childtables) || !is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3417 | 3417 | {
|
| 3418 | 3418 | dol_print_error('Called isObjectUsed on a class with property this->childtables not defined');
|
| 3419 | 3419 | return -1; |
@@ -3421,24 +3421,24 @@ discard block |
||
| 3421 | 3421 | |
| 3422 | 3422 | $arraytoscan = $this->childtables; |
| 3423 | 3423 | // For backward compatibility, we check if array is old format array('table1', 'table2', ...)
|
| 3424 | - $tmparray=array_keys($this->childtables); |
|
| 3424 | + $tmparray = array_keys($this->childtables); |
|
| 3425 | 3425 | if (is_numeric($tmparray[0])) |
| 3426 | 3426 | {
|
| 3427 | 3427 | $arraytoscan = array_flip($this->childtables); |
| 3428 | 3428 | } |
| 3429 | 3429 | |
| 3430 | 3430 | // Test if child exists |
| 3431 | - $haschild=0; |
|
| 3432 | - foreach($arraytoscan as $table => $elementname) |
|
| 3431 | + $haschild = 0; |
|
| 3432 | + foreach ($arraytoscan as $table => $elementname) |
|
| 3433 | 3433 | {
|
| 3434 | 3434 | //print $id.'-'.$table.'-'.$elementname.'<br>'; |
| 3435 | 3435 | // Check if third party can be deleted |
| 3436 | 3436 | $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
| 3437 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3438 | - $resql=$this->db->query($sql); |
|
| 3437 | + $sql .= " WHERE ".$this->fk_element." = ".$id; |
|
| 3438 | + $resql = $this->db->query($sql); |
|
| 3439 | 3439 | if ($resql) |
| 3440 | 3440 | {
|
| 3441 | - $obj=$this->db->fetch_object($resql); |
|
| 3441 | + $obj = $this->db->fetch_object($resql); |
|
| 3442 | 3442 | if ($obj->nb > 0) |
| 3443 | 3443 | {
|
| 3444 | 3444 | $langs->load("errors");
|
@@ -3446,24 +3446,24 @@ discard block |
||
| 3446 | 3446 | $haschild += $obj->nb; |
| 3447 | 3447 | if (is_numeric($elementname)) // old usage |
| 3448 | 3448 | {
|
| 3449 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3449 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3450 | 3450 | } |
| 3451 | 3451 | else // new usage: $elementname=Translation key |
| 3452 | 3452 | {
|
| 3453 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
|
| 3453 | + $this->errors[] = $langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
|
| 3454 | 3454 | } |
| 3455 | - break; // We found at least one, we stop here |
|
| 3455 | + break; // We found at least one, we stop here |
|
| 3456 | 3456 | } |
| 3457 | 3457 | } |
| 3458 | 3458 | else |
| 3459 | 3459 | {
|
| 3460 | - $this->errors[]=$this->db->lasterror(); |
|
| 3460 | + $this->errors[] = $this->db->lasterror(); |
|
| 3461 | 3461 | return -1; |
| 3462 | 3462 | } |
| 3463 | 3463 | } |
| 3464 | 3464 | if ($haschild > 0) |
| 3465 | 3465 | {
|
| 3466 | - $this->errors[]="ErrorRecordHasChildren"; |
|
| 3466 | + $this->errors[] = "ErrorRecordHasChildren"; |
|
| 3467 | 3467 | return $haschild; |
| 3468 | 3468 | } |
| 3469 | 3469 | else return 0; |
@@ -3475,18 +3475,18 @@ discard block |
||
| 3475 | 3475 | * @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 |
| 3476 | 3476 | * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
| 3477 | 3477 | */ |
| 3478 | - function hasProductsOrServices($predefined=-1) |
|
| 3478 | + function hasProductsOrServices($predefined = -1) |
|
| 3479 | 3479 | {
|
| 3480 | - $nb=0; |
|
| 3480 | + $nb = 0; |
|
| 3481 | 3481 | |
| 3482 | - foreach($this->lines as $key => $val) |
|
| 3482 | + foreach ($this->lines as $key => $val) |
|
| 3483 | 3483 | {
|
| 3484 | - $qualified=0; |
|
| 3485 | - if ($predefined == -1) $qualified=1; |
|
| 3486 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3487 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3488 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3489 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3484 | + $qualified = 0; |
|
| 3485 | + if ($predefined == -1) $qualified = 1; |
|
| 3486 | + if ($predefined == 1 && $val->fk_product > 0) $qualified = 1; |
|
| 3487 | + if ($predefined == 0 && $val->fk_product <= 0) $qualified = 1; |
|
| 3488 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type == 0) $qualified = 1; |
|
| 3489 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type == 1) $qualified = 1; |
|
| 3490 | 3490 | if ($qualified) $nb++; |
| 3491 | 3491 | } |
| 3492 | 3492 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
@@ -3500,24 +3500,24 @@ discard block |
||
| 3500 | 3500 | */ |
| 3501 | 3501 | function getTotalDiscount() |
| 3502 | 3502 | {
|
| 3503 | - $total_discount=0.00; |
|
| 3503 | + $total_discount = 0.00; |
|
| 3504 | 3504 | |
| 3505 | 3505 | $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
| 3506 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3507 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3506 | + $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3507 | + $sql .= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3508 | 3508 | |
| 3509 | 3509 | dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
| 3510 | 3510 | $resql = $this->db->query($sql); |
| 3511 | 3511 | if ($resql) |
| 3512 | 3512 | {
|
| 3513 | - $num=$this->db->num_rows($resql); |
|
| 3514 | - $i=0; |
|
| 3513 | + $num = $this->db->num_rows($resql); |
|
| 3514 | + $i = 0; |
|
| 3515 | 3515 | while ($i < $num) |
| 3516 | 3516 | {
|
| 3517 | 3517 | $obj = $this->db->fetch_object($resql); |
| 3518 | 3518 | |
| 3519 | 3519 | $pu_ht = $obj->pu_ht; |
| 3520 | - $qty= $obj->qty; |
|
| 3520 | + $qty = $obj->qty; |
|
| 3521 | 3521 | $total_ht = $obj->total_ht; |
| 3522 | 3522 | |
| 3523 | 3523 | $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
@@ -3551,17 +3551,17 @@ discard block |
||
| 3551 | 3551 | {
|
| 3552 | 3552 | if (isset($line->qty_asked)) |
| 3553 | 3553 | {
|
| 3554 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3555 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3554 | + if (empty($totalOrdered)) $totalOrdered = 0; // Avoid warning because $totalOrdered is '' |
|
| 3555 | + $totalOrdered += $line->qty_asked; // defined for shipment only |
|
| 3556 | 3556 | } |
| 3557 | 3557 | if (isset($line->qty_shipped)) |
| 3558 | 3558 | {
|
| 3559 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3560 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3561 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3559 | + if (empty($totalToShip)) $totalToShip = 0; // Avoid warning because $totalToShip is '' |
|
| 3560 | + $totalToShip += $line->qty_shipped; // defined for shipment only |
|
| 3561 | + } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3562 | 3562 | {
|
| 3563 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3564 | - $totalToShip+=$line->qty; // defined for reception only |
|
| 3563 | + if (empty($totalToShip)) $totalToShip = 0; |
|
| 3564 | + $totalToShip += $line->qty; // defined for reception only |
|
| 3565 | 3565 | } |
| 3566 | 3566 | |
| 3567 | 3567 | // Define qty, weight, volume, weight_units, volume_units |
@@ -3574,27 +3574,27 @@ discard block |
||
| 3574 | 3574 | } |
| 3575 | 3575 | |
| 3576 | 3576 | $weight = $line->weight ? $line->weight : 0; |
| 3577 | - ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
| 3577 | + ($weight == 0 && !empty($line->product->weight)) ? $weight = $line->product->weight : 0; |
|
| 3578 | 3578 | $volume = $line->volume ? $line->volume : 0; |
| 3579 | - ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
| 3579 | + ($volume == 0 && !empty($line->product->volume)) ? $volume = $line->product->volume : 0; |
|
| 3580 | 3580 | |
| 3581 | - $weight_units=$line->weight_units; |
|
| 3582 | - ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
| 3583 | - $volume_units=$line->volume_units; |
|
| 3584 | - ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
| 3581 | + $weight_units = $line->weight_units; |
|
| 3582 | + ($weight_units == 0 && !empty($line->product->weight_units)) ? $weight_units = $line->product->weight_units : 0; |
|
| 3583 | + $volume_units = $line->volume_units; |
|
| 3584 | + ($volume_units == 0 && !empty($line->product->volume_units)) ? $volume_units = $line->product->volume_units : 0; |
|
| 3585 | 3585 | |
| 3586 | - $weightUnit=0; |
|
| 3587 | - $volumeUnit=0; |
|
| 3588 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3589 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3586 | + $weightUnit = 0; |
|
| 3587 | + $volumeUnit = 0; |
|
| 3588 | + if (!empty($weight_units)) $weightUnit = $weight_units; |
|
| 3589 | + if (!empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3590 | 3590 | |
| 3591 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3592 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3591 | + if (empty($totalWeight)) $totalWeight = 0; // Avoid warning because $totalWeight is '' |
|
| 3592 | + if (empty($totalVolume)) $totalVolume = 0; // Avoid warning because $totalVolume is '' |
|
| 3593 | 3593 | |
| 3594 | 3594 | //var_dump($line->volume_units); |
| 3595 | 3595 | if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
| 3596 | 3596 | {
|
| 3597 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3597 | + $trueWeightUnit = pow(10, $weightUnit); |
|
| 3598 | 3598 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3599 | 3599 | } |
| 3600 | 3600 | else {
|
@@ -3608,18 +3608,18 @@ discard block |
||
| 3608 | 3608 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3609 | 3609 | } |
| 3610 | 3610 | else |
| 3611 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3611 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3612 | 3612 | } |
| 3613 | 3613 | if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
| 3614 | 3614 | {
|
| 3615 | 3615 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
| 3616 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3616 | + $trueVolumeUnit = pow(10, $volumeUnit); |
|
| 3617 | 3617 | //print $line->volume; |
| 3618 | 3618 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
| 3619 | 3619 | } |
| 3620 | 3620 | else |
| 3621 | 3621 | {
|
| 3622 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3622 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3623 | 3623 | } |
| 3624 | 3624 | } |
| 3625 | 3625 | |
@@ -3636,17 +3636,17 @@ discard block |
||
| 3636 | 3636 | {
|
| 3637 | 3637 | $this->db->begin(); |
| 3638 | 3638 | |
| 3639 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3639 | + $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3640 | 3640 | |
| 3641 | 3641 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 3642 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3643 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 3642 | + $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3643 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 3644 | 3644 | |
| 3645 | 3645 | dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
| 3646 | 3646 | $resql = $this->db->query($sql); |
| 3647 | - if (! $resql) |
|
| 3647 | + if (!$resql) |
|
| 3648 | 3648 | {
|
| 3649 | - $this->error=$this->db->lasterror(); |
|
| 3649 | + $this->error = $this->db->lasterror(); |
|
| 3650 | 3650 | $this->db->rollback(); |
| 3651 | 3651 | return -1; |
| 3652 | 3652 | } |
@@ -3681,7 +3681,7 @@ discard block |
||
| 3681 | 3681 | } |
| 3682 | 3682 | } |
| 3683 | 3683 | |
| 3684 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3684 | + $out .= (($res->code && $this->location_incoterms) ? ' - ' : '').$this->location_incoterms; |
|
| 3685 | 3685 | |
| 3686 | 3686 | return $out; |
| 3687 | 3687 | } |
@@ -3727,11 +3727,11 @@ discard block |
||
| 3727 | 3727 | if ($this->id && $this->table_element) |
| 3728 | 3728 | {
|
| 3729 | 3729 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
| 3730 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3731 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3732 | - $sql.= " WHERE rowid = " . $this->id; |
|
| 3730 | + $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3731 | + $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3732 | + $sql .= " WHERE rowid = ".$this->id; |
|
| 3733 | 3733 | dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
| 3734 | - $resql=$this->db->query($sql); |
|
| 3734 | + $resql = $this->db->query($sql); |
|
| 3735 | 3735 | if ($resql) |
| 3736 | 3736 | {
|
| 3737 | 3737 | $this->fk_incoterms = $id_incoterm; |
@@ -3772,24 +3772,24 @@ discard block |
||
| 3772 | 3772 | */ |
| 3773 | 3773 | function formAddObjectLine($dateSelector, $seller, $buyer) |
| 3774 | 3774 | {
|
| 3775 | - global $conf,$user,$langs,$object,$hookmanager; |
|
| 3776 | - global $form,$bcnd,$var; |
|
| 3775 | + global $conf, $user, $langs, $object, $hookmanager; |
|
| 3776 | + global $form, $bcnd, $var; |
|
| 3777 | 3777 | |
| 3778 | 3778 | // Line extrafield |
| 3779 | 3779 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 3780 | 3780 | $extrafieldsline = new ExtraFields($this->db); |
| 3781 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3781 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3782 | 3782 | |
| 3783 | 3783 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 3784 | 3784 | // Use global variables + $dateSelector + $seller and $buyer |
| 3785 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 3786 | - foreach($dirtpls as $reldir) |
|
| 3785 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 3786 | + foreach ($dirtpls as $reldir) |
|
| 3787 | 3787 | {
|
| 3788 | 3788 | $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
| 3789 | 3789 | if (empty($conf->file->strict_mode)) {
|
| 3790 | - $res=@include $tpl; |
|
| 3790 | + $res = @include $tpl; |
|
| 3791 | 3791 | } else {
|
| 3792 | - $res=include $tpl; // for debug |
|
| 3792 | + $res = include $tpl; // for debug |
|
| 3793 | 3793 | } |
| 3794 | 3794 | if ($res) break; |
| 3795 | 3795 | } |
@@ -3813,24 +3813,24 @@ discard block |
||
| 3813 | 3813 | * @param int $dateSelector 1=Show also date range input fields |
| 3814 | 3814 | * @return void |
| 3815 | 3815 | */ |
| 3816 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3816 | + function printObjectLines($action, $seller, $buyer, $selected = 0, $dateSelector = 0) |
|
| 3817 | 3817 | {
|
| 3818 | 3818 | global $conf, $hookmanager, $langs, $user; |
| 3819 | 3819 | // TODO We should not use global var for this ! |
| 3820 | 3820 | global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
| 3821 | 3821 | |
| 3822 | 3822 | // Define usemargins |
| 3823 | - $usemargins=0; |
|
| 3824 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
|
|
| 3823 | + $usemargins = 0; |
|
| 3824 | + if (!empty($conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) $usemargins = 1;
|
|
| 3825 | 3825 | |
| 3826 | 3826 | $num = count($this->lines); |
| 3827 | 3827 | |
| 3828 | 3828 | // Line extrafield |
| 3829 | 3829 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 3830 | 3830 | $extrafieldsline = new ExtraFields($this->db); |
| 3831 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3831 | + $extralabelslines = $extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3832 | 3832 | |
| 3833 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3833 | + $parameters = array('num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3834 | 3834 | $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
| 3835 | 3835 | if (empty($reshook)) |
| 3836 | 3836 | {
|
@@ -3840,7 +3840,7 @@ discard block |
||
| 3840 | 3840 | print '<tr class="liste_titre nodrag nodrop">'; |
| 3841 | 3841 | |
| 3842 | 3842 | // Adds a line numbering column |
| 3843 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3843 | + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3844 | 3844 | |
| 3845 | 3845 | // Description |
| 3846 | 3846 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
@@ -3864,7 +3864,7 @@ discard block |
||
| 3864 | 3864 | // Qty |
| 3865 | 3865 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
| 3866 | 3866 | |
| 3867 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 3867 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 3868 | 3868 | {
|
| 3869 | 3869 | print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
|
| 3870 | 3870 | } |
@@ -3873,10 +3873,10 @@ discard block |
||
| 3873 | 3873 | print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
|
| 3874 | 3874 | |
| 3875 | 3875 | if ($this->situation_cycle_ref) {
|
| 3876 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
|
|
| 3876 | + print '<td class="linecolcycleref" align="right">'.$langs->trans('Progress').'</td>';
|
|
| 3877 | 3877 | } |
| 3878 | 3878 | |
| 3879 | - if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3879 | + if ($usemargins && !empty($conf->margin->enabled) && empty($user->societe_id)) |
|
| 3880 | 3880 | {
|
| 3881 | 3881 | if (!empty($user->rights->margins->creer)) |
| 3882 | 3882 | {
|
@@ -3886,9 +3886,9 @@ discard block |
||
| 3886 | 3886 | print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
| 3887 | 3887 | } |
| 3888 | 3888 | |
| 3889 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3889 | + if (!empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3890 | 3890 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
| 3891 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3891 | + if (!empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3892 | 3892 | print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
| 3893 | 3893 | } |
| 3894 | 3894 | |
@@ -3900,13 +3900,13 @@ discard block |
||
| 3900 | 3900 | |
| 3901 | 3901 | if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
| 3902 | 3902 | |
| 3903 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3903 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3904 | 3904 | |
| 3905 | 3905 | print '<td class="linecoldelete" width="10"></td>'; |
| 3906 | 3906 | |
| 3907 | 3907 | print '<td class="linecolmove" width="10"></td>'; |
| 3908 | 3908 | |
| 3909 | - if($action == 'selectlines') |
|
| 3909 | + if ($action == 'selectlines') |
|
| 3910 | 3910 | {
|
| 3911 | 3911 | print '<td class="linecolcheckall" align="center">'; |
| 3912 | 3912 | print '<input type="checkbox" class="linecheckboxtoggle" />'; |
@@ -3919,7 +3919,7 @@ discard block |
||
| 3919 | 3919 | } |
| 3920 | 3920 | |
| 3921 | 3921 | $var = true; |
| 3922 | - $i = 0; |
|
| 3922 | + $i = 0; |
|
| 3923 | 3923 | |
| 3924 | 3924 | print "<tbody>\n"; |
| 3925 | 3925 | foreach ($this->lines as $line) |
@@ -3932,18 +3932,18 @@ discard block |
||
| 3932 | 3932 | {
|
| 3933 | 3933 | if (empty($line->fk_parent_line)) |
| 3934 | 3934 | {
|
| 3935 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3936 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3935 | + $parameters = array('line'=>$line, 'var'=>$var, 'num'=>$num, 'i'=>$i, 'dateSelector'=>$dateSelector, 'seller'=>$seller, 'buyer'=>$buyer, 'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3936 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3937 | 3937 | } |
| 3938 | 3938 | else |
| 3939 | 3939 | {
|
| 3940 | - $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);
|
|
| 3941 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3940 | + $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);
|
|
| 3941 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3942 | 3942 | } |
| 3943 | 3943 | } |
| 3944 | 3944 | if (empty($reshook)) |
| 3945 | 3945 | {
|
| 3946 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3946 | + $this->printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected, $extrafieldsline); |
|
| 3947 | 3947 | } |
| 3948 | 3948 | |
| 3949 | 3949 | $i++; |
@@ -3967,23 +3967,23 @@ discard block |
||
| 3967 | 3967 | * @param int $extrafieldsline Object of extrafield line attribute |
| 3968 | 3968 | * @return void |
| 3969 | 3969 | */ |
| 3970 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3970 | + function printObjectLine($action, $line, $var, $num, $i, $dateSelector, $seller, $buyer, $selected = 0, $extrafieldsline = 0) |
|
| 3971 | 3971 | {
|
| 3972 | - global $conf,$langs,$user,$object,$hookmanager; |
|
| 3973 | - global $form,$bc,$bcdd; |
|
| 3974 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3972 | + global $conf, $langs, $user, $object, $hookmanager; |
|
| 3973 | + global $form, $bc, $bcdd; |
|
| 3974 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3975 | 3975 | |
| 3976 | 3976 | $object_rights = $this->getRights(); |
| 3977 | 3977 | |
| 3978 | - $element=$this->element; |
|
| 3978 | + $element = $this->element; |
|
| 3979 | 3979 | |
| 3980 | - $text=''; $description=''; $type=0; |
|
| 3980 | + $text = ''; $description = ''; $type = 0; |
|
| 3981 | 3981 | |
| 3982 | 3982 | // Show product and description |
| 3983 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 3983 | + $type = (!empty($line->product_type) ? $line->product_type : $line->fk_product_type); |
|
| 3984 | 3984 | // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
| 3985 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3986 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 3985 | + if (!empty($line->date_start)) $type = 1; // deprecated |
|
| 3986 | + if (!empty($line->date_end)) $type = 1; // deprecated |
|
| 3987 | 3987 | |
| 3988 | 3988 | // Ligne en mode visu |
| 3989 | 3989 | if ($action != 'editline' || $selected != $line->id) |
@@ -3996,14 +3996,14 @@ discard block |
||
| 3996 | 3996 | |
| 3997 | 3997 | $product_static->ref = $line->ref; //can change ref in hook |
| 3998 | 3998 | $product_static->label = $line->label; //can change label in hook |
| 3999 | - $text=$product_static->getNomUrl(1); |
|
| 3999 | + $text = $product_static->getNomUrl(1); |
|
| 4000 | 4000 | |
| 4001 | 4001 | // Define output language and label |
| 4002 | - if (! empty($conf->global->MAIN_MULTILANGS)) |
|
| 4002 | + if (!empty($conf->global->MAIN_MULTILANGS)) |
|
| 4003 | 4003 | {
|
| 4004 | - if (! is_object($this->thirdparty)) |
|
| 4004 | + if (!is_object($this->thirdparty)) |
|
| 4005 | 4005 | {
|
| 4006 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
|
|
| 4006 | + dol_print_error('', 'Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
|
|
| 4007 | 4007 | return; |
| 4008 | 4008 | } |
| 4009 | 4009 | |
@@ -4011,38 +4011,38 @@ discard block |
||
| 4011 | 4011 | $prod->fetch($line->fk_product); |
| 4012 | 4012 | |
| 4013 | 4013 | $outputlangs = $langs; |
| 4014 | - $newlang=''; |
|
| 4015 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4016 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
| 4017 | - if (! empty($newlang)) |
|
| 4014 | + $newlang = ''; |
|
| 4015 | + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09');
|
|
| 4016 | + if (!empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
| 4017 | + if (!empty($newlang)) |
|
| 4018 | 4018 | {
|
| 4019 | - $outputlangs = new Translate("",$conf);
|
|
| 4019 | + $outputlangs = new Translate("", $conf);
|
|
| 4020 | 4020 | $outputlangs->setDefaultLang($newlang); |
| 4021 | 4021 | } |
| 4022 | 4022 | |
| 4023 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4023 | + $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4024 | 4024 | } |
| 4025 | 4025 | else |
| 4026 | 4026 | {
|
| 4027 | 4027 | $label = $line->product_label; |
| 4028 | 4028 | } |
| 4029 | 4029 | |
| 4030 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 4031 | - $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. |
|
| 4030 | + $text .= ' - '.(!empty($line->label) ? $line->label : $label); |
|
| 4031 | + $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. |
|
| 4032 | 4032 | } |
| 4033 | 4033 | |
| 4034 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4034 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
| 4035 | 4035 | |
| 4036 | 4036 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4037 | 4037 | // Use global variables + $dateSelector + $seller and $buyer |
| 4038 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4039 | - foreach($dirtpls as $reldir) |
|
| 4038 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4039 | + foreach ($dirtpls as $reldir) |
|
| 4040 | 4040 | {
|
| 4041 | 4041 | $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
| 4042 | 4042 | if (empty($conf->file->strict_mode)) {
|
| 4043 | - $res=@include $tpl; |
|
| 4043 | + $res = @include $tpl; |
|
| 4044 | 4044 | } else {
|
| 4045 | - $res=include $tpl; // for debug |
|
| 4045 | + $res = include $tpl; // for debug |
|
| 4046 | 4046 | } |
| 4047 | 4047 | if ($res) break; |
| 4048 | 4048 | } |
@@ -4051,21 +4051,21 @@ discard block |
||
| 4051 | 4051 | // Ligne en mode update |
| 4052 | 4052 | if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
| 4053 | 4053 | {
|
| 4054 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4055 | - $placeholder=' placeholder="'.$langs->trans("Label").'"';
|
|
| 4054 | + $label = (!empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4055 | + $placeholder = ' placeholder="'.$langs->trans("Label").'"';
|
|
| 4056 | 4056 | |
| 4057 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4057 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx / 100)), 'MU'); |
|
| 4058 | 4058 | |
| 4059 | 4059 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4060 | 4060 | // Use global variables + $dateSelector + $seller and $buyer |
| 4061 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4062 | - foreach($dirtpls as $reldir) |
|
| 4061 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4062 | + foreach ($dirtpls as $reldir) |
|
| 4063 | 4063 | {
|
| 4064 | 4064 | $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
| 4065 | 4065 | if (empty($conf->file->strict_mode)) {
|
| 4066 | - $res=@include $tpl; |
|
| 4066 | + $res = @include $tpl; |
|
| 4067 | 4067 | } else {
|
| 4068 | - $res=include $tpl; // for debug |
|
| 4068 | + $res = include $tpl; // for debug |
|
| 4069 | 4069 | } |
| 4070 | 4070 | if ($res) break; |
| 4071 | 4071 | } |
@@ -4085,7 +4085,7 @@ discard block |
||
| 4085 | 4085 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
| 4086 | 4086 | * @return void |
| 4087 | 4087 | */ |
| 4088 | - function printOriginLinesList($restrictlist='') |
|
| 4088 | + function printOriginLinesList($restrictlist = '') |
|
| 4089 | 4089 | {
|
| 4090 | 4090 | global $langs, $hookmanager, $conf; |
| 4091 | 4091 | |
@@ -4096,26 +4096,26 @@ discard block |
||
| 4096 | 4096 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
| 4097 | 4097 | if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
|
| 4098 | 4098 | print '<td align="right">'.$langs->trans('Qty').'</td>';
|
| 4099 | - if($conf->global->PRODUCT_USE_UNITS) |
|
| 4099 | + if ($conf->global->PRODUCT_USE_UNITS) |
|
| 4100 | 4100 | {
|
| 4101 | 4101 | print '<td align="left">'.$langs->trans('Unit').'</td>';
|
| 4102 | 4102 | } |
| 4103 | 4103 | print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
|
| 4104 | 4104 | |
| 4105 | 4105 | $var = true; |
| 4106 | - $i = 0; |
|
| 4106 | + $i = 0; |
|
| 4107 | 4107 | |
| 4108 | - if (! empty($this->lines)) |
|
| 4108 | + if (!empty($this->lines)) |
|
| 4109 | 4109 | {
|
| 4110 | 4110 | foreach ($this->lines as $line) |
| 4111 | 4111 | {
|
| 4112 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 4112 | + if (is_object($hookmanager) && (($line->product_type == 9 && !empty($line->special_code)) || !empty($line->fk_parent_line))) |
|
| 4113 | 4113 | {
|
| 4114 | 4114 | if (empty($line->fk_parent_line)) |
| 4115 | 4115 | {
|
| 4116 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i);
|
|
| 4117 | - $action=''; |
|
| 4118 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
| 4116 | + $parameters = array('line'=>$line, 'var'=>$var, 'i'=>$i);
|
|
| 4117 | + $action = ''; |
|
| 4118 | + $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 4119 | 4119 | } |
| 4120 | 4120 | } |
| 4121 | 4121 | else |
@@ -4139,103 +4139,103 @@ discard block |
||
| 4139 | 4139 | * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
| 4140 | 4140 | * @return void |
| 4141 | 4141 | */ |
| 4142 | - function printOriginLine($line, $var, $restrictlist='') |
|
| 4142 | + function printOriginLine($line, $var, $restrictlist = '') |
|
| 4143 | 4143 | {
|
| 4144 | 4144 | global $langs, $conf; |
| 4145 | 4145 | |
| 4146 | 4146 | //var_dump($line); |
| 4147 | 4147 | if (!empty($line->date_start)) |
| 4148 | 4148 | {
|
| 4149 | - $date_start=$line->date_start; |
|
| 4149 | + $date_start = $line->date_start; |
|
| 4150 | 4150 | } |
| 4151 | 4151 | else |
| 4152 | 4152 | {
|
| 4153 | - $date_start=$line->date_debut_prevue; |
|
| 4154 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4153 | + $date_start = $line->date_debut_prevue; |
|
| 4154 | + if ($line->date_debut_reel) $date_start = $line->date_debut_reel; |
|
| 4155 | 4155 | } |
| 4156 | 4156 | if (!empty($line->date_end)) |
| 4157 | 4157 | {
|
| 4158 | - $date_end=$line->date_end; |
|
| 4158 | + $date_end = $line->date_end; |
|
| 4159 | 4159 | } |
| 4160 | 4160 | else |
| 4161 | 4161 | {
|
| 4162 | - $date_end=$line->date_fin_prevue; |
|
| 4163 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4162 | + $date_end = $line->date_fin_prevue; |
|
| 4163 | + if ($line->date_fin_reel) $date_end = $line->date_fin_reel; |
|
| 4164 | 4164 | } |
| 4165 | 4165 | |
| 4166 | 4166 | $this->tpl['label'] = ''; |
| 4167 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4167 | + if (!empty($line->fk_parent_line)) $this->tpl['label'] .= img_picto('', 'rightarrow');
|
|
| 4168 | 4168 | |
| 4169 | 4169 | if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
| 4170 | 4170 | {
|
| 4171 | - $discount=new DiscountAbsolute($this->db); |
|
| 4171 | + $discount = new DiscountAbsolute($this->db); |
|
| 4172 | 4172 | $discount->fk_soc = $this->socid; |
| 4173 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 4173 | + $this->tpl['label'] .= $discount->getNomUrl(0, 'discount'); |
|
| 4174 | 4174 | } |
| 4175 | - else if (! empty($line->fk_product)) |
|
| 4175 | + else if (!empty($line->fk_product)) |
|
| 4176 | 4176 | {
|
| 4177 | 4177 | $productstatic = new Product($this->db); |
| 4178 | 4178 | $productstatic->id = $line->fk_product; |
| 4179 | 4179 | $productstatic->ref = $line->ref; |
| 4180 | 4180 | $productstatic->type = $line->fk_product_type; |
| 4181 | - if(empty($productstatic->ref)){
|
|
| 4181 | + if (empty($productstatic->ref)) {
|
|
| 4182 | 4182 | $line->fetch_product(); |
| 4183 | 4183 | $productstatic = $line->product; |
| 4184 | 4184 | } |
| 4185 | 4185 | |
| 4186 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 4187 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 4186 | + $this->tpl['label'] .= $productstatic->getNomUrl(1); |
|
| 4187 | + $this->tpl['label'] .= ' - '.(!empty($line->label) ? $line->label : $line->product_label); |
|
| 4188 | 4188 | // Dates |
| 4189 | 4189 | if ($line->product_type == 1 && ($date_start || $date_end)) |
| 4190 | 4190 | {
|
| 4191 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4191 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
| 4192 | 4192 | } |
| 4193 | 4193 | } |
| 4194 | 4194 | else |
| 4195 | 4195 | {
|
| 4196 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
|
| 4196 | + $this->tpl['label'] .= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''), 'service') : img_object($langs->trans(''), 'product')));
|
|
| 4197 | 4197 | if (!empty($line->desc)) {
|
| 4198 | - $this->tpl['label'].=$line->desc; |
|
| 4199 | - }else {
|
|
| 4200 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 4198 | + $this->tpl['label'] .= $line->desc; |
|
| 4199 | + } else {
|
|
| 4200 | + $this->tpl['label'] .= ($line->label ? ' '.$line->label : ''); |
|
| 4201 | 4201 | } |
| 4202 | 4202 | |
| 4203 | 4203 | // Dates |
| 4204 | 4204 | if ($line->product_type == 1 && ($date_start || $date_end)) |
| 4205 | 4205 | {
|
| 4206 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4206 | + $this->tpl['label'] .= get_date_range($date_start, $date_end); |
|
| 4207 | 4207 | } |
| 4208 | 4208 | } |
| 4209 | 4209 | |
| 4210 | - if (! empty($line->desc)) |
|
| 4210 | + if (!empty($line->desc)) |
|
| 4211 | 4211 | {
|
| 4212 | 4212 | if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
| 4213 | 4213 | {
|
| 4214 | - $discount=new DiscountAbsolute($this->db); |
|
| 4214 | + $discount = new DiscountAbsolute($this->db); |
|
| 4215 | 4215 | $discount->fetch($line->fk_remise_except); |
| 4216 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
|
| 4216 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0));
|
|
| 4217 | 4217 | } |
| 4218 | 4218 | elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
| 4219 | 4219 | {
|
| 4220 | - $discount=new DiscountAbsolute($this->db); |
|
| 4220 | + $discount = new DiscountAbsolute($this->db); |
|
| 4221 | 4221 | $discount->fetch($line->fk_remise_except); |
| 4222 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
|
| 4222 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0));
|
|
| 4223 | 4223 | } |
| 4224 | 4224 | elseif ($line->desc == '(EXCESS RECEIVED)') |
| 4225 | 4225 | {
|
| 4226 | - $discount=new DiscountAbsolute($this->db); |
|
| 4226 | + $discount = new DiscountAbsolute($this->db); |
|
| 4227 | 4227 | $discount->fetch($line->fk_remise_except); |
| 4228 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
|
| 4228 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0));
|
|
| 4229 | 4229 | } |
| 4230 | 4230 | elseif ($line->desc == '(EXCESS PAID)') |
| 4231 | 4231 | {
|
| 4232 | - $discount=new DiscountAbsolute($this->db); |
|
| 4232 | + $discount = new DiscountAbsolute($this->db); |
|
| 4233 | 4233 | $discount->fetch($line->fk_remise_except); |
| 4234 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
|
| 4234 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0));
|
|
| 4235 | 4235 | } |
| 4236 | 4236 | else |
| 4237 | 4237 | {
|
| 4238 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 4238 | + $this->tpl['description'] = dol_trunc($line->desc, 60); |
|
| 4239 | 4239 | } |
| 4240 | 4240 | } |
| 4241 | 4241 | else |
@@ -4246,7 +4246,7 @@ discard block |
||
| 4246 | 4246 | // VAT Rate |
| 4247 | 4247 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
| 4248 | 4248 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
| 4249 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 4249 | + if (!empty($line->vat_src_code) && !preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'] .= ' ('.$line->vat_src_code.')';
|
|
| 4250 | 4250 | |
| 4251 | 4251 | $this->tpl['price'] = price($line->subprice); |
| 4252 | 4252 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
@@ -4255,19 +4255,19 @@ discard block |
||
| 4255 | 4255 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
| 4256 | 4256 | |
| 4257 | 4257 | // Is the line strike or not |
| 4258 | - $this->tpl['strike']=0; |
|
| 4259 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4258 | + $this->tpl['strike'] = 0; |
|
| 4259 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike'] = 1; |
|
| 4260 | 4260 | |
| 4261 | 4261 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4262 | 4262 | // Use global variables + $dateSelector + $seller and $buyer |
| 4263 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
|
|
| 4264 | - foreach($dirtpls as $reldir) |
|
| 4263 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4264 | + foreach ($dirtpls as $reldir) |
|
| 4265 | 4265 | {
|
| 4266 | 4266 | $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
| 4267 | 4267 | if (empty($conf->file->strict_mode)) {
|
| 4268 | - $res=@include $tpl; |
|
| 4268 | + $res = @include $tpl; |
|
| 4269 | 4269 | } else {
|
| 4270 | - $res=include $tpl; // for debug |
|
| 4270 | + $res = include $tpl; // for debug |
|
| 4271 | 4271 | } |
| 4272 | 4272 | if ($res) break; |
| 4273 | 4273 | } |
@@ -4285,26 +4285,26 @@ discard block |
||
| 4285 | 4285 | * @param int $mandatory Mandatory or not |
| 4286 | 4286 | * @return int <=0 if KO, >0 if OK |
| 4287 | 4287 | */ |
| 4288 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4288 | + function add_element_resource($resource_id, $resource_type, $busy = 0, $mandatory = 0) |
|
| 4289 | 4289 | {
|
| 4290 | 4290 | // phpcs:enable |
| 4291 | 4291 | $this->db->begin(); |
| 4292 | 4292 | |
| 4293 | 4293 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
| 4294 | - $sql.= "resource_id"; |
|
| 4295 | - $sql.= ", resource_type"; |
|
| 4296 | - $sql.= ", element_id"; |
|
| 4297 | - $sql.= ", element_type"; |
|
| 4298 | - $sql.= ", busy"; |
|
| 4299 | - $sql.= ", mandatory"; |
|
| 4300 | - $sql.= ") VALUES (";
|
|
| 4301 | - $sql.= $resource_id; |
|
| 4302 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4303 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4304 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4305 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4306 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4307 | - $sql.= ")"; |
|
| 4294 | + $sql .= "resource_id"; |
|
| 4295 | + $sql .= ", resource_type"; |
|
| 4296 | + $sql .= ", element_id"; |
|
| 4297 | + $sql .= ", element_type"; |
|
| 4298 | + $sql .= ", busy"; |
|
| 4299 | + $sql .= ", mandatory"; |
|
| 4300 | + $sql .= ") VALUES (";
|
|
| 4301 | + $sql .= $resource_id; |
|
| 4302 | + $sql .= ", '".$this->db->escape($resource_type)."'"; |
|
| 4303 | + $sql .= ", '".$this->db->escape($this->id)."'"; |
|
| 4304 | + $sql .= ", '".$this->db->escape($this->element)."'"; |
|
| 4305 | + $sql .= ", '".$this->db->escape($busy)."'"; |
|
| 4306 | + $sql .= ", '".$this->db->escape($mandatory)."'"; |
|
| 4307 | + $sql .= ")"; |
|
| 4308 | 4308 | |
| 4309 | 4309 | dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
| 4310 | 4310 | if ($this->db->query($sql)) |
@@ -4314,7 +4314,7 @@ discard block |
||
| 4314 | 4314 | } |
| 4315 | 4315 | else |
| 4316 | 4316 | {
|
| 4317 | - $this->error=$this->db->lasterror(); |
|
| 4317 | + $this->error = $this->db->lasterror(); |
|
| 4318 | 4318 | $this->db->rollback(); |
| 4319 | 4319 | return 0; |
| 4320 | 4320 | } |
@@ -4329,7 +4329,7 @@ discard block |
||
| 4329 | 4329 | * @param int $notrigger Disable all triggers |
| 4330 | 4330 | * @return int >0 if OK, <0 if KO |
| 4331 | 4331 | */ |
| 4332 | - function delete_resource($rowid, $element, $notrigger=0) |
|
| 4332 | + function delete_resource($rowid, $element, $notrigger = 0) |
|
| 4333 | 4333 | {
|
| 4334 | 4334 | // phpcs:enable |
| 4335 | 4335 | global $user; |
@@ -4337,22 +4337,22 @@ discard block |
||
| 4337 | 4337 | $this->db->begin(); |
| 4338 | 4338 | |
| 4339 | 4339 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
| 4340 | - $sql.= " WHERE rowid=".$rowid; |
|
| 4340 | + $sql .= " WHERE rowid=".$rowid; |
|
| 4341 | 4341 | |
| 4342 | 4342 | dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
| 4343 | 4343 | |
| 4344 | - $resql=$this->db->query($sql); |
|
| 4345 | - if (! $resql) |
|
| 4344 | + $resql = $this->db->query($sql); |
|
| 4345 | + if (!$resql) |
|
| 4346 | 4346 | {
|
| 4347 | - $this->error=$this->db->lasterror(); |
|
| 4347 | + $this->error = $this->db->lasterror(); |
|
| 4348 | 4348 | $this->db->rollback(); |
| 4349 | 4349 | return -1; |
| 4350 | 4350 | } |
| 4351 | 4351 | else |
| 4352 | 4352 | {
|
| 4353 | - if (! $notrigger) |
|
| 4353 | + if (!$notrigger) |
|
| 4354 | 4354 | {
|
| 4355 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4355 | + $result = $this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4356 | 4356 | if ($result < 0) { $this->db->rollback(); return -1; }
|
| 4357 | 4357 | } |
| 4358 | 4358 | $this->db->commit(); |
@@ -4371,8 +4371,8 @@ discard block |
||
| 4371 | 4371 | // Force a copy of this->lines, otherwise it will point to same object. |
| 4372 | 4372 | if (isset($this->lines) && is_array($this->lines)) |
| 4373 | 4373 | {
|
| 4374 | - $nboflines=count($this->lines); |
|
| 4375 | - for($i=0; $i < $nboflines; $i++) |
|
| 4374 | + $nboflines = count($this->lines); |
|
| 4375 | + for ($i = 0; $i < $nboflines; $i++) |
|
| 4376 | 4376 | {
|
| 4377 | 4377 | $this->lines[$i] = clone $this->lines[$i]; |
| 4378 | 4378 | } |
@@ -4392,43 +4392,43 @@ discard block |
||
| 4392 | 4392 | * @return int >0 if OK, <0 if KO |
| 4393 | 4393 | * @see addFileIntoDatabaseIndex |
| 4394 | 4394 | */ |
| 4395 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4395 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams = null) |
|
| 4396 | 4396 | {
|
| 4397 | 4397 | global $conf, $langs, $user; |
| 4398 | 4398 | |
| 4399 | - $srctemplatepath=''; |
|
| 4399 | + $srctemplatepath = ''; |
|
| 4400 | 4400 | |
| 4401 | 4401 | // Increase limit for PDF build |
| 4402 | - $err=error_reporting(); |
|
| 4402 | + $err = error_reporting(); |
|
| 4403 | 4403 | error_reporting(0); |
| 4404 | 4404 | @set_time_limit(120); |
| 4405 | 4405 | error_reporting($err); |
| 4406 | 4406 | |
| 4407 | 4407 | // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
| 4408 | - $tmp=explode(':',$modele,2);
|
|
| 4409 | - if (! empty($tmp[1])) |
|
| 4408 | + $tmp = explode(':', $modele, 2);
|
|
| 4409 | + if (!empty($tmp[1])) |
|
| 4410 | 4410 | {
|
| 4411 | - $modele=$tmp[0]; |
|
| 4412 | - $srctemplatepath=$tmp[1]; |
|
| 4411 | + $modele = $tmp[0]; |
|
| 4412 | + $srctemplatepath = $tmp[1]; |
|
| 4413 | 4413 | } |
| 4414 | 4414 | |
| 4415 | 4415 | // Search template files |
| 4416 | - $file=''; $classname=''; $filefound=0; |
|
| 4417 | - $dirmodels=array('/');
|
|
| 4418 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4419 | - foreach($dirmodels as $reldir) |
|
| 4416 | + $file = ''; $classname = ''; $filefound = 0; |
|
| 4417 | + $dirmodels = array('/');
|
|
| 4418 | + if (is_array($conf->modules_parts['models'])) $dirmodels = array_merge($dirmodels, $conf->modules_parts['models']); |
|
| 4419 | + foreach ($dirmodels as $reldir) |
|
| 4420 | 4420 | {
|
| 4421 | - foreach(array('doc','pdf') as $prefix)
|
|
| 4421 | + foreach (array('doc', 'pdf') as $prefix)
|
|
| 4422 | 4422 | {
|
| 4423 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4423 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4424 | 4424 | else $file = $prefix."_".$modele.".modules.php"; |
| 4425 | 4425 | |
| 4426 | 4426 | // On verifie l'emplacement du modele |
| 4427 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4427 | + $file = dol_buildpath($reldir.$modelspath.$file, 0); |
|
| 4428 | 4428 | if (file_exists($file)) |
| 4429 | 4429 | {
|
| 4430 | - $filefound=1; |
|
| 4431 | - $classname=$prefix.'_'.$modele; |
|
| 4430 | + $filefound = 1; |
|
| 4431 | + $classname = $prefix.'_'.$modele; |
|
| 4432 | 4432 | break; |
| 4433 | 4433 | } |
| 4434 | 4434 | } |
@@ -4438,7 +4438,7 @@ discard block |
||
| 4438 | 4438 | // If generator was found |
| 4439 | 4439 | if ($filefound) |
| 4440 | 4440 | {
|
| 4441 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4441 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4442 | 4442 | |
| 4443 | 4443 | require_once $file; |
| 4444 | 4444 | |
@@ -4447,32 +4447,32 @@ discard block |
||
| 4447 | 4447 | // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
| 4448 | 4448 | if ($obj->type == 'odt' && empty($srctemplatepath)) |
| 4449 | 4449 | {
|
| 4450 | - $varfortemplatedir=$obj->scandir; |
|
| 4451 | - if ($varfortemplatedir && ! empty($conf->global->$varfortemplatedir)) |
|
| 4450 | + $varfortemplatedir = $obj->scandir; |
|
| 4451 | + if ($varfortemplatedir && !empty($conf->global->$varfortemplatedir)) |
|
| 4452 | 4452 | {
|
| 4453 | - $dirtoscan=$conf->global->$varfortemplatedir; |
|
| 4453 | + $dirtoscan = $conf->global->$varfortemplatedir; |
|
| 4454 | 4454 | |
| 4455 | - $listoffiles=array(); |
|
| 4455 | + $listoffiles = array(); |
|
| 4456 | 4456 | |
| 4457 | 4457 | // Now we add first model found in directories scanned |
| 4458 | - $listofdir=explode(',',$dirtoscan);
|
|
| 4459 | - foreach($listofdir as $key => $tmpdir) |
|
| 4458 | + $listofdir = explode(',', $dirtoscan);
|
|
| 4459 | + foreach ($listofdir as $key => $tmpdir) |
|
| 4460 | 4460 | {
|
| 4461 | - $tmpdir=trim($tmpdir); |
|
| 4462 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
|
| 4463 | - if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
|
| 4461 | + $tmpdir = trim($tmpdir); |
|
| 4462 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir);
|
|
| 4463 | + if (!$tmpdir) { unset($listofdir[$key]); continue; }
|
|
| 4464 | 4464 | if (is_dir($tmpdir)) |
| 4465 | 4465 | {
|
| 4466 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4467 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4466 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0); |
|
| 4467 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
| 4468 | 4468 | } |
| 4469 | 4469 | } |
| 4470 | 4470 | |
| 4471 | 4471 | if (count($listoffiles)) |
| 4472 | 4472 | {
|
| 4473 | - foreach($listoffiles as $record) |
|
| 4473 | + foreach ($listoffiles as $record) |
|
| 4474 | 4474 | {
|
| 4475 | - $srctemplatepath=$record['fullname']; |
|
| 4475 | + $srctemplatepath = $record['fullname']; |
|
| 4476 | 4476 | break; |
| 4477 | 4477 | } |
| 4478 | 4478 | } |
@@ -4480,27 +4480,27 @@ discard block |
||
| 4480 | 4480 | |
| 4481 | 4481 | if (empty($srctemplatepath)) |
| 4482 | 4482 | {
|
| 4483 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4483 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4484 | 4484 | return -1; |
| 4485 | 4485 | } |
| 4486 | 4486 | } |
| 4487 | 4487 | |
| 4488 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4488 | + if ($obj->type == 'odt' && !empty($srctemplatepath)) |
|
| 4489 | 4489 | {
|
| 4490 | - if (! dol_is_file($srctemplatepath)) |
|
| 4490 | + if (!dol_is_file($srctemplatepath)) |
|
| 4491 | 4491 | {
|
| 4492 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4492 | + $this->error = 'ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4493 | 4493 | return -1; |
| 4494 | 4494 | } |
| 4495 | 4495 | } |
| 4496 | 4496 | |
| 4497 | 4497 | // We save charset_output to restore it because write_file can change it if needed for |
| 4498 | 4498 | // output format that does not support UTF8. |
| 4499 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 4499 | + $sav_charset_output = $outputlangs->charset_output; |
|
| 4500 | 4500 | |
| 4501 | 4501 | if (in_array(get_class($this), array('Adherent')))
|
| 4502 | 4502 | {
|
| 4503 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4503 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4504 | 4504 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
| 4505 | 4505 | } |
| 4506 | 4506 | else |
@@ -4511,41 +4511,41 @@ discard block |
||
| 4511 | 4511 | |
| 4512 | 4512 | if ($resultwritefile > 0) |
| 4513 | 4513 | {
|
| 4514 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4514 | + $outputlangs->charset_output = $sav_charset_output; |
|
| 4515 | 4515 | |
| 4516 | 4516 | // We delete old preview |
| 4517 | 4517 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
| 4518 | 4518 | dol_delete_preview($this); |
| 4519 | 4519 | |
| 4520 | 4520 | // Index file in database |
| 4521 | - if (! empty($obj->result['fullpath'])) |
|
| 4521 | + if (!empty($obj->result['fullpath'])) |
|
| 4522 | 4522 | {
|
| 4523 | 4523 | $destfull = $obj->result['fullpath']; |
| 4524 | 4524 | $upload_dir = dirname($destfull); |
| 4525 | 4525 | $destfile = basename($destfull); |
| 4526 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
|
| 4526 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir);
|
|
| 4527 | 4527 | |
| 4528 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4528 | + if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4529 | 4529 | {
|
| 4530 | 4530 | $filename = basename($destfile); |
| 4531 | 4531 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
| 4532 | 4532 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
| 4533 | 4533 | |
| 4534 | 4534 | include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
| 4535 | - $ecmfile=new EcmFiles($this->db); |
|
| 4536 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4535 | + $ecmfile = new EcmFiles($this->db); |
|
| 4536 | + $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); |
|
| 4537 | 4537 | |
| 4538 | 4538 | // Set the public "share" key |
| 4539 | 4539 | $setsharekey = false; |
| 4540 | 4540 | if ($this->element == 'propal') |
| 4541 | 4541 | {
|
| 4542 | - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4543 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4544 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4542 | + $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4543 | + if ($useonlinesignature) $setsharekey = true; |
|
| 4544 | + if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4545 | 4545 | } |
| 4546 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4547 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4548 | - if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4546 | + if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4547 | + if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4548 | + if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey = true; |
|
| 4549 | 4549 | |
| 4550 | 4550 | if ($setsharekey) |
| 4551 | 4551 | {
|
@@ -4558,11 +4558,11 @@ discard block |
||
| 4558 | 4558 | |
| 4559 | 4559 | if ($result > 0) |
| 4560 | 4560 | {
|
| 4561 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4561 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4562 | 4562 | $ecmfile->fullpath_orig = ''; |
| 4563 | 4563 | $ecmfile->gen_or_uploaded = 'generated'; |
| 4564 | - $ecmfile->description = ''; // indexed content |
|
| 4565 | - $ecmfile->keyword = ''; // keyword content |
|
| 4564 | + $ecmfile->description = ''; // indexed content |
|
| 4565 | + $ecmfile->keyword = ''; // keyword content |
|
| 4566 | 4566 | $result = $ecmfile->update($user); |
| 4567 | 4567 | if ($result < 0) |
| 4568 | 4568 | {
|
@@ -4574,11 +4574,11 @@ discard block |
||
| 4574 | 4574 | $ecmfile->entity = $conf->entity; |
| 4575 | 4575 | $ecmfile->filepath = $rel_dir; |
| 4576 | 4576 | $ecmfile->filename = $filename; |
| 4577 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4577 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4578 | 4578 | $ecmfile->fullpath_orig = ''; |
| 4579 | 4579 | $ecmfile->gen_or_uploaded = 'generated'; |
| 4580 | - $ecmfile->description = ''; // indexed content |
|
| 4581 | - $ecmfile->keyword = ''; // keyword content |
|
| 4580 | + $ecmfile->description = ''; // indexed content |
|
| 4581 | + $ecmfile->keyword = ''; // keyword content |
|
| 4582 | 4582 | $ecmfile->src_object_type = $this->table_element; |
| 4583 | 4583 | $ecmfile->src_object_id = $this->id; |
| 4584 | 4584 | |
@@ -4595,14 +4595,14 @@ discard block |
||
| 4595 | 4595 | //var_dump($obj->update_main_doc_field);exit; |
| 4596 | 4596 | |
| 4597 | 4597 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
| 4598 | - $update_main_doc_field=0; |
|
| 4599 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4600 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4598 | + $update_main_doc_field = 0; |
|
| 4599 | + if (!empty($obj->update_main_doc_field)) $update_main_doc_field = 1; |
|
| 4600 | + if ($update_main_doc_field && !empty($this->table_element)) |
|
| 4601 | 4601 | {
|
| 4602 | 4602 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
| 4603 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 4603 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 4604 | 4604 | $resql = $this->db->query($sql); |
| 4605 | - if (! $resql) dol_print_error($this->db); |
|
| 4605 | + if (!$resql) dol_print_error($this->db); |
|
| 4606 | 4606 | } |
| 4607 | 4607 | } |
| 4608 | 4608 | } |
@@ -4618,15 +4618,15 @@ discard block |
||
| 4618 | 4618 | } |
| 4619 | 4619 | else |
| 4620 | 4620 | {
|
| 4621 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4621 | + $outputlangs->charset_output = $sav_charset_output; |
|
| 4622 | 4622 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
| 4623 | 4623 | return -1; |
| 4624 | 4624 | } |
| 4625 | 4625 | } |
| 4626 | 4626 | else |
| 4627 | 4627 | {
|
| 4628 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
|
| 4629 | - dol_print_error('',$this->error);
|
|
| 4628 | + $this->error = $langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists", $file);
|
|
| 4629 | + dol_print_error('', $this->error);
|
|
| 4630 | 4630 | return -1; |
| 4631 | 4631 | } |
| 4632 | 4632 | } |
@@ -4642,9 +4642,9 @@ discard block |
||
| 4642 | 4642 | {
|
| 4643 | 4643 | global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
| 4644 | 4644 | |
| 4645 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4645 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4646 | 4646 | |
| 4647 | - $file_osencoded=dol_osencode($file); |
|
| 4647 | + $file_osencoded = dol_osencode($file); |
|
| 4648 | 4648 | if (file_exists($file_osencoded)) |
| 4649 | 4649 | {
|
| 4650 | 4650 | // Create small thumbs for company (Ratio is near 16/9) |
@@ -4674,7 +4674,7 @@ discard block |
||
| 4674 | 4674 | * @param string $alternatevalue Alternate value to use |
| 4675 | 4675 | * @return string|string[] Default value (can be an array if the GETPOST return an array) |
| 4676 | 4676 | **/ |
| 4677 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4677 | + function getDefaultCreateValueFor($fieldname, $alternatevalue = null) |
|
| 4678 | 4678 | {
|
| 4679 | 4679 | global $conf, $_POST; |
| 4680 | 4680 | |
@@ -4683,16 +4683,16 @@ discard block |
||
| 4683 | 4683 | |
| 4684 | 4684 | if (isset($alternatevalue)) return $alternatevalue; |
| 4685 | 4685 | |
| 4686 | - $newelement=$this->element; |
|
| 4687 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4688 | - if ($newelement == 'commande') $newelement='order'; |
|
| 4686 | + $newelement = $this->element; |
|
| 4687 | + if ($newelement == 'facture') $newelement = 'invoice'; |
|
| 4688 | + if ($newelement == 'commande') $newelement = 'order'; |
|
| 4689 | 4689 | if (empty($newelement)) |
| 4690 | 4690 | {
|
| 4691 | 4691 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
| 4692 | 4692 | return ''; |
| 4693 | 4693 | } |
| 4694 | 4694 | |
| 4695 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4695 | + $keyforfieldname = strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4696 | 4696 | //var_dump($keyforfieldname); |
| 4697 | 4697 | if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
| 4698 | 4698 | |
@@ -4717,21 +4717,21 @@ discard block |
||
| 4717 | 4717 | function call_trigger($trigger_name, $user) |
| 4718 | 4718 | {
|
| 4719 | 4719 | // phpcs:enable |
| 4720 | - global $langs,$conf; |
|
| 4720 | + global $langs, $conf; |
|
| 4721 | 4721 | |
| 4722 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4723 | - $interface=new Interfaces($this->db); |
|
| 4724 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 4722 | + include_once DOL_DOCUMENT_ROOT.'/core/class/interfaces.class.php'; |
|
| 4723 | + $interface = new Interfaces($this->db); |
|
| 4724 | + $result = $interface->run_triggers($trigger_name, $this, $user, $langs, $conf); |
|
| 4725 | 4725 | |
| 4726 | 4726 | if ($result < 0) |
| 4727 | 4727 | {
|
| 4728 | 4728 | if (!empty($this->errors)) |
| 4729 | 4729 | {
|
| 4730 | - $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. |
|
| 4730 | + $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. |
|
| 4731 | 4731 | } |
| 4732 | 4732 | else |
| 4733 | 4733 | {
|
| 4734 | - $this->errors=$interface->errors; |
|
| 4734 | + $this->errors = $interface->errors; |
|
| 4735 | 4735 | } |
| 4736 | 4736 | } |
| 4737 | 4737 | return $result; |
@@ -4750,19 +4750,19 @@ discard block |
||
| 4750 | 4750 | * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
| 4751 | 4751 | * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
| 4752 | 4752 | */ |
| 4753 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4753 | + function fetch_optionals($rowid = null, $optionsArray = null) |
|
| 4754 | 4754 | {
|
| 4755 | 4755 | // phpcs:enable |
| 4756 | - if (empty($rowid)) $rowid=$this->id; |
|
| 4756 | + if (empty($rowid)) $rowid = $this->id; |
|
| 4757 | 4757 | |
| 4758 | 4758 | // To avoid SQL errors. Probably not the better solution though |
| 4759 | 4759 | if (!$this->table_element) {
|
| 4760 | 4760 | return 0; |
| 4761 | 4761 | } |
| 4762 | 4762 | |
| 4763 | - $this->array_options=array(); |
|
| 4763 | + $this->array_options = array(); |
|
| 4764 | 4764 | |
| 4765 | - if (! is_array($optionsArray)) |
|
| 4765 | + if (!is_array($optionsArray)) |
|
| 4766 | 4766 | {
|
| 4767 | 4767 | // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
| 4768 | 4768 | // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
@@ -4778,7 +4778,7 @@ discard block |
||
| 4778 | 4778 | {
|
| 4779 | 4779 | $extrafields->fetch_name_optionals_label($this->table_element); |
| 4780 | 4780 | } |
| 4781 | - $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
| 4781 | + $optionsArray = (!empty($extrafields->attributes[$this->table_element]['label']) ? $extrafields->attributes[$this->table_element]['label'] : null); |
|
| 4782 | 4782 | } |
| 4783 | 4783 | else |
| 4784 | 4784 | {
|
@@ -4797,18 +4797,18 @@ discard block |
||
| 4797 | 4797 | {
|
| 4798 | 4798 | if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
| 4799 | 4799 | {
|
| 4800 | - $sql.= ", ".$name; |
|
| 4800 | + $sql .= ", ".$name; |
|
| 4801 | 4801 | } |
| 4802 | 4802 | } |
| 4803 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4804 | - $sql.= " WHERE fk_object = ".$rowid; |
|
| 4803 | + $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4804 | + $sql .= " WHERE fk_object = ".$rowid; |
|
| 4805 | 4805 | |
| 4806 | 4806 | //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
| 4807 | - $resql=$this->db->query($sql); |
|
| 4807 | + $resql = $this->db->query($sql); |
|
| 4808 | 4808 | if ($resql) |
| 4809 | 4809 | {
|
| 4810 | 4810 | $this->array_options = array(); |
| 4811 | - $numrows=$this->db->num_rows($resql); |
|
| 4811 | + $numrows = $this->db->num_rows($resql); |
|
| 4812 | 4812 | if ($numrows) |
| 4813 | 4813 | {
|
| 4814 | 4814 | $tab = $this->db->fetch_array($resql); |
@@ -4816,17 +4816,17 @@ discard block |
||
| 4816 | 4816 | foreach ($tab as $key => $value) |
| 4817 | 4817 | {
|
| 4818 | 4818 | // 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) |
| 4819 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4819 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && !is_int($key)) |
|
| 4820 | 4820 | {
|
| 4821 | 4821 | // we can add this attribute to object |
| 4822 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime')))
|
|
| 4822 | + if (!empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
|
|
| 4823 | 4823 | {
|
| 4824 | 4824 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
| 4825 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4825 | + $this->array_options["options_".$key] = $this->db->jdate($value); |
|
| 4826 | 4826 | } |
| 4827 | 4827 | else |
| 4828 | 4828 | {
|
| 4829 | - $this->array_options["options_".$key]=$value; |
|
| 4829 | + $this->array_options["options_".$key] = $value; |
|
| 4830 | 4830 | } |
| 4831 | 4831 | |
| 4832 | 4832 | //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]);
|
@@ -4862,10 +4862,10 @@ discard block |
||
| 4862 | 4862 | |
| 4863 | 4863 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 4864 | 4864 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
| 4865 | - $resql=$this->db->query($sql_del); |
|
| 4866 | - if (! $resql) |
|
| 4865 | + $resql = $this->db->query($sql_del); |
|
| 4866 | + if (!$resql) |
|
| 4867 | 4867 | {
|
| 4868 | - $this->error=$this->db->lasterror(); |
|
| 4868 | + $this->error = $this->db->lasterror(); |
|
| 4869 | 4869 | $this->db->rollback(); |
| 4870 | 4870 | return -1; |
| 4871 | 4871 | } |
@@ -4886,36 +4886,36 @@ discard block |
||
| 4886 | 4886 | * @return int -1=error, O=did nothing, 1=OK |
| 4887 | 4887 | * @see updateExtraField, setValueFrom |
| 4888 | 4888 | */ |
| 4889 | - function insertExtraFields($trigger='', $userused=null) |
|
| 4889 | + function insertExtraFields($trigger = '', $userused = null) |
|
| 4890 | 4890 | {
|
| 4891 | - global $conf,$langs,$user; |
|
| 4891 | + global $conf, $langs, $user; |
|
| 4892 | 4892 | |
| 4893 | - if (empty($userused)) $userused=$user; |
|
| 4893 | + if (empty($userused)) $userused = $user; |
|
| 4894 | 4894 | |
| 4895 | - $error=0; |
|
| 4895 | + $error = 0; |
|
| 4896 | 4896 | |
| 4897 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4897 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 4898 | 4898 | |
| 4899 | - if (! empty($this->array_options)) |
|
| 4899 | + if (!empty($this->array_options)) |
|
| 4900 | 4900 | {
|
| 4901 | 4901 | // Check parameters |
| 4902 | 4902 | $langs->load('admin');
|
| 4903 | 4903 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 4904 | 4904 | $extrafields = new ExtraFields($this->db); |
| 4905 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4905 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4906 | 4906 | |
| 4907 | 4907 | //Eliminate copied source object extra_fields that do not exist in target object |
| 4908 | - $new_array_options=array(); |
|
| 4908 | + $new_array_options = array(); |
|
| 4909 | 4909 | foreach ($this->array_options as $key => $value) {
|
| 4910 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4910 | + if (in_array(substr($key, 8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4911 | 4911 | $new_array_options[$key] = $value; |
| 4912 | 4912 | elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
| 4913 | 4913 | $new_array_options['options_'.$key] = $value; |
| 4914 | 4914 | } |
| 4915 | 4915 | |
| 4916 | - foreach($new_array_options as $key => $value) |
|
| 4916 | + foreach ($new_array_options as $key => $value) |
|
| 4917 | 4917 | {
|
| 4918 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4918 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 4919 | 4919 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
| 4920 | 4920 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
| 4921 | 4921 | $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
@@ -4923,13 +4923,13 @@ discard block |
||
| 4923 | 4923 | |
| 4924 | 4924 | if ($attributeRequired) |
| 4925 | 4925 | {
|
| 4926 | - $mandatorypb=false; |
|
| 4927 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4928 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4926 | + $mandatorypb = false; |
|
| 4927 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb = true; |
|
| 4928 | + if ($this->array_options[$key] === '') $mandatorypb = true; |
|
| 4929 | 4929 | if ($mandatorypb) |
| 4930 | 4930 | {
|
| 4931 | 4931 | dol_syslog($this->error); |
| 4932 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel);
|
|
| 4932 | + $this->errors[] = $langs->trans('ErrorFieldRequired', $attributeLabel);
|
|
| 4933 | 4933 | return -1; |
| 4934 | 4934 | } |
| 4935 | 4935 | } |
@@ -4940,25 +4940,25 @@ discard block |
||
| 4940 | 4940 | switch ($attributeType) |
| 4941 | 4941 | {
|
| 4942 | 4942 | case 'int': |
| 4943 | - if (!is_numeric($value) && $value!='') |
|
| 4943 | + if (!is_numeric($value) && $value != '') |
|
| 4944 | 4944 | {
|
| 4945 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4945 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4946 | 4946 | return -1; |
| 4947 | 4947 | } |
| 4948 | - elseif ($value=='') |
|
| 4948 | + elseif ($value == '') |
|
| 4949 | 4949 | {
|
| 4950 | 4950 | $new_array_options[$key] = null; |
| 4951 | 4951 | } |
| 4952 | 4952 | break; |
| 4953 | 4953 | case 'double': |
| 4954 | 4954 | $value = price2num($value); |
| 4955 | - if (!is_numeric($value) && $value!='') |
|
| 4955 | + if (!is_numeric($value) && $value != '') |
|
| 4956 | 4956 | {
|
| 4957 | 4957 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
| 4958 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4958 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4959 | 4959 | return -1; |
| 4960 | 4960 | } |
| 4961 | - elseif ($value=='') |
|
| 4961 | + elseif ($value == '') |
|
| 4962 | 4962 | {
|
| 4963 | 4963 | $new_array_options[$key] = null; |
| 4964 | 4964 | } |
@@ -4972,12 +4972,12 @@ discard block |
||
| 4972 | 4972 | } |
| 4973 | 4973 | break;*/ |
| 4974 | 4974 | case 'password': |
| 4975 | - $algo=''; |
|
| 4975 | + $algo = ''; |
|
| 4976 | 4976 | if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
| 4977 | 4977 | {
|
| 4978 | 4978 | // If there is an encryption choice, we use it to crypt data before insert |
| 4979 | 4979 | $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
| 4980 | - $algo=reset($tmparrays); |
|
| 4980 | + $algo = reset($tmparrays); |
|
| 4981 | 4981 | if ($algo != '') |
| 4982 | 4982 | {
|
| 4983 | 4983 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
@@ -4988,7 +4988,7 @@ discard block |
||
| 4988 | 4988 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
| 4989 | 4989 | 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. |
| 4990 | 4990 | {
|
| 4991 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4991 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4992 | 4992 | } |
| 4993 | 4993 | else |
| 4994 | 4994 | {
|
@@ -4999,7 +4999,7 @@ discard block |
||
| 4999 | 4999 | } |
| 5000 | 5000 | else |
| 5001 | 5001 | {
|
| 5002 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5002 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5003 | 5003 | } |
| 5004 | 5004 | } |
| 5005 | 5005 | } |
@@ -5016,13 +5016,13 @@ discard block |
||
| 5016 | 5016 | break; |
| 5017 | 5017 | case 'datetime': |
| 5018 | 5018 | // If data is a string instead of a timestamp, we convert it |
| 5019 | - if (! is_int($this->array_options[$key])) {
|
|
| 5019 | + if (!is_int($this->array_options[$key])) {
|
|
| 5020 | 5020 | $this->array_options[$key] = strtotime($this->array_options[$key]); |
| 5021 | 5021 | } |
| 5022 | 5022 | $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
| 5023 | 5023 | break; |
| 5024 | 5024 | case 'link': |
| 5025 | - $param_list=array_keys($attributeParam['options']); |
|
| 5025 | + $param_list = array_keys($attributeParam['options']); |
|
| 5026 | 5026 | // 0 : ObjectName |
| 5027 | 5027 | // 1 : classPath |
| 5028 | 5028 | $InfoFieldList = explode(":", $param_list[0]);
|
@@ -5031,18 +5031,18 @@ discard block |
||
| 5031 | 5031 | {
|
| 5032 | 5032 | if ($value == '-1') // -1 is key for no defined in combo list of objects |
| 5033 | 5033 | {
|
| 5034 | - $new_array_options[$key]=''; |
|
| 5034 | + $new_array_options[$key] = ''; |
|
| 5035 | 5035 | } |
| 5036 | 5036 | elseif ($value) |
| 5037 | 5037 | {
|
| 5038 | 5038 | $object = new $InfoFieldList[0]($this->db); |
| 5039 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5040 | - else $res=$object->fetch('',$value);
|
|
| 5039 | + if (is_numeric($value)) $res = $object->fetch($value); |
|
| 5040 | + else $res = $object->fetch('', $value);
|
|
| 5041 | 5041 | |
| 5042 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5042 | + if ($res > 0) $new_array_options[$key] = $object->id; |
|
| 5043 | 5043 | else |
| 5044 | 5044 | {
|
| 5045 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5045 | + $this->error = "Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5046 | 5046 | $this->db->rollback(); |
| 5047 | 5047 | return -1; |
| 5048 | 5048 | } |
@@ -5066,46 +5066,46 @@ discard block |
||
| 5066 | 5066 | $this->db->query($sql_del); |
| 5067 | 5067 | |
| 5068 | 5068 | $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
| 5069 | - foreach($new_array_options as $key => $value) |
|
| 5069 | + foreach ($new_array_options as $key => $value) |
|
| 5070 | 5070 | {
|
| 5071 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5071 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 5072 | 5072 | // Add field of attribut |
| 5073 | 5073 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
| 5074 | - $sql.=",".$attributeKey; |
|
| 5074 | + $sql .= ",".$attributeKey; |
|
| 5075 | 5075 | } |
| 5076 | 5076 | $sql .= ") VALUES (".$this->id;
|
| 5077 | 5077 | |
| 5078 | - foreach($new_array_options as $key => $value) |
|
| 5078 | + foreach ($new_array_options as $key => $value) |
|
| 5079 | 5079 | {
|
| 5080 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5080 | + $attributeKey = substr($key, 8); // Remove 'options_' prefix |
|
| 5081 | 5081 | // Add field of attribute |
| 5082 | 5082 | if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
| 5083 | 5083 | {
|
| 5084 | 5084 | if ($new_array_options[$key] != '') |
| 5085 | 5085 | {
|
| 5086 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5086 | + $sql .= ",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5087 | 5087 | } |
| 5088 | 5088 | else |
| 5089 | 5089 | {
|
| 5090 | - $sql.=",null"; |
|
| 5090 | + $sql .= ",null"; |
|
| 5091 | 5091 | } |
| 5092 | 5092 | } |
| 5093 | 5093 | } |
| 5094 | - $sql.=")"; |
|
| 5094 | + $sql .= ")"; |
|
| 5095 | 5095 | |
| 5096 | 5096 | dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
| 5097 | 5097 | $resql = $this->db->query($sql); |
| 5098 | - if (! $resql) |
|
| 5098 | + if (!$resql) |
|
| 5099 | 5099 | {
|
| 5100 | - $this->error=$this->db->lasterror(); |
|
| 5100 | + $this->error = $this->db->lasterror(); |
|
| 5101 | 5101 | $error++; |
| 5102 | 5102 | } |
| 5103 | 5103 | |
| 5104 | - if (! $error && $trigger) |
|
| 5104 | + if (!$error && $trigger) |
|
| 5105 | 5105 | {
|
| 5106 | 5106 | // Call trigger |
| 5107 | - $this->context=array('extrafieldaddupdate'=>1);
|
|
| 5108 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5107 | + $this->context = array('extrafieldaddupdate'=>1);
|
|
| 5108 | + $result = $this->call_trigger($trigger, $userused); |
|
| 5109 | 5109 | if ($result < 0) $error++; |
| 5110 | 5110 | // End call trigger |
| 5111 | 5111 | } |
@@ -5134,25 +5134,25 @@ discard block |
||
| 5134 | 5134 | * @return int -1=error, O=did nothing, 1=OK |
| 5135 | 5135 | * @see setValueFrom, insertExtraFields |
| 5136 | 5136 | */ |
| 5137 | - function updateExtraField($key, $trigger=null, $userused=null) |
|
| 5137 | + function updateExtraField($key, $trigger = null, $userused = null) |
|
| 5138 | 5138 | {
|
| 5139 | - global $conf,$langs,$user; |
|
| 5139 | + global $conf, $langs, $user; |
|
| 5140 | 5140 | |
| 5141 | - if (empty($userused)) $userused=$user; |
|
| 5141 | + if (empty($userused)) $userused = $user; |
|
| 5142 | 5142 | |
| 5143 | - $error=0; |
|
| 5143 | + $error = 0; |
|
| 5144 | 5144 | |
| 5145 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5145 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5146 | 5146 | |
| 5147 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5147 | + if (!empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5148 | 5148 | {
|
| 5149 | 5149 | // Check parameters |
| 5150 | 5150 | $langs->load('admin');
|
| 5151 | 5151 | require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
| 5152 | 5152 | $extrafields = new ExtraFields($this->db); |
| 5153 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5153 | + $target_extrafields = $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5154 | 5154 | |
| 5155 | - $value=$this->array_options["options_".$key]; |
|
| 5155 | + $value = $this->array_options["options_".$key]; |
|
| 5156 | 5156 | |
| 5157 | 5157 | $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
| 5158 | 5158 | $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
@@ -5165,25 +5165,25 @@ discard block |
||
| 5165 | 5165 | switch ($attributeType) |
| 5166 | 5166 | {
|
| 5167 | 5167 | case 'int': |
| 5168 | - if (!is_numeric($value) && $value!='') |
|
| 5168 | + if (!is_numeric($value) && $value != '') |
|
| 5169 | 5169 | {
|
| 5170 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
|
| 5170 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5171 | 5171 | return -1; |
| 5172 | 5172 | } |
| 5173 | - elseif ($value=='') |
|
| 5173 | + elseif ($value == '') |
|
| 5174 | 5174 | {
|
| 5175 | 5175 | $this->array_options["options_".$key] = null; |
| 5176 | 5176 | } |
| 5177 | 5177 | break; |
| 5178 | 5178 | case 'double': |
| 5179 | 5179 | $value = price2num($value); |
| 5180 | - if (!is_numeric($value) && $value!='') |
|
| 5180 | + if (!is_numeric($value) && $value != '') |
|
| 5181 | 5181 | {
|
| 5182 | 5182 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
| 5183 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5183 | + $this->errors[] = $langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5184 | 5184 | return -1; |
| 5185 | 5185 | } |
| 5186 | - elseif ($value=='') |
|
| 5186 | + elseif ($value == '') |
|
| 5187 | 5187 | {
|
| 5188 | 5188 | $this->array_options["options_".$key] = null; |
| 5189 | 5189 | } |
@@ -5200,13 +5200,13 @@ discard block |
||
| 5200 | 5200 | $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
| 5201 | 5201 | break; |
| 5202 | 5202 | case 'date': |
| 5203 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5203 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
| 5204 | 5204 | break; |
| 5205 | 5205 | case 'datetime': |
| 5206 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5206 | + $this->array_options["options_".$key] = $this->db->idate($this->array_options["options_".$key]); |
|
| 5207 | 5207 | break; |
| 5208 | 5208 | case 'link': |
| 5209 | - $param_list=array_keys($attributeParam['options']); |
|
| 5209 | + $param_list = array_keys($attributeParam['options']); |
|
| 5210 | 5210 | // 0 : ObjectName |
| 5211 | 5211 | // 1 : classPath |
| 5212 | 5212 | $InfoFieldList = explode(":", $param_list[0]);
|
@@ -5214,8 +5214,8 @@ discard block |
||
| 5214 | 5214 | if ($value) |
| 5215 | 5215 | {
|
| 5216 | 5216 | $object = new $InfoFieldList[0]($this->db); |
| 5217 | - $object->fetch(0,$value); |
|
| 5218 | - $this->array_options["options_".$key]=$object->id; |
|
| 5217 | + $object->fetch(0, $value); |
|
| 5218 | + $this->array_options["options_".$key] = $object->id; |
|
| 5219 | 5219 | } |
| 5220 | 5220 | break; |
| 5221 | 5221 | } |
@@ -5224,24 +5224,24 @@ discard block |
||
| 5224 | 5224 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
| 5225 | 5225 | $sql .= " WHERE fk_object = ".$this->id; |
| 5226 | 5226 | $resql = $this->db->query($sql); |
| 5227 | - if (! $resql) |
|
| 5227 | + if (!$resql) |
|
| 5228 | 5228 | {
|
| 5229 | 5229 | $error++; |
| 5230 | - $this->error=$this->db->lasterror(); |
|
| 5230 | + $this->error = $this->db->lasterror(); |
|
| 5231 | 5231 | } |
| 5232 | 5232 | |
| 5233 | - if (! $error && $trigger) |
|
| 5233 | + if (!$error && $trigger) |
|
| 5234 | 5234 | {
|
| 5235 | 5235 | // Call trigger |
| 5236 | - $this->context=array('extrafieldupdate'=>1);
|
|
| 5237 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5236 | + $this->context = array('extrafieldupdate'=>1);
|
|
| 5237 | + $result = $this->call_trigger($trigger, $userused); |
|
| 5238 | 5238 | if ($result < 0) $error++; |
| 5239 | 5239 | // End call trigger |
| 5240 | 5240 | } |
| 5241 | 5241 | |
| 5242 | 5242 | if ($error) |
| 5243 | 5243 | {
|
| 5244 | - dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
| 5244 | + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); |
|
| 5245 | 5245 | $this->db->rollback(); |
| 5246 | 5246 | return -1; |
| 5247 | 5247 | } |
@@ -5268,71 +5268,71 @@ discard block |
||
| 5268 | 5268 | * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
| 5269 | 5269 | * @return string |
| 5270 | 5270 | */ |
| 5271 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
| 5271 | + function showInputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $morecss = 0) |
|
| 5272 | 5272 | {
|
| 5273 | - global $conf,$langs,$form; |
|
| 5273 | + global $conf, $langs, $form; |
|
| 5274 | 5274 | |
| 5275 | - if (! is_object($form)) |
|
| 5275 | + if (!is_object($form)) |
|
| 5276 | 5276 | {
|
| 5277 | 5277 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 5278 | - $form=new Form($this->db); |
|
| 5278 | + $form = new Form($this->db); |
|
| 5279 | 5279 | } |
| 5280 | 5280 | |
| 5281 | - $val=$this->fields[$key]; |
|
| 5281 | + $val = $this->fields[$key]; |
|
| 5282 | 5282 | |
| 5283 | - $out=''; |
|
| 5284 | - $type=''; |
|
| 5283 | + $out = ''; |
|
| 5284 | + $type = ''; |
|
| 5285 | 5285 | $param = array(); |
| 5286 | - $param['options']=array(); |
|
| 5287 | - $size =$this->fields[$key]['size']; |
|
| 5286 | + $param['options'] = array(); |
|
| 5287 | + $size = $this->fields[$key]['size']; |
|
| 5288 | 5288 | // Because we work on extrafields |
| 5289 | - if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){
|
|
| 5290 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5291 | - $type ='link'; |
|
| 5292 | - } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5293 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5294 | - $type ='link'; |
|
| 5295 | - } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5296 | - $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5297 | - $type ='sellist'; |
|
| 5298 | - } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) {
|
|
| 5299 | - $param['options']=array(); |
|
| 5300 | - $type ='varchar'; |
|
| 5301 | - $size=$reg[1]; |
|
| 5302 | - } elseif(preg_match('/varchar/', $val['type'])) {
|
|
| 5303 | - $param['options']=array(); |
|
| 5304 | - $type ='varchar'; |
|
| 5305 | - } elseif(is_array($this->fields[$key]['arrayofkeyval'])) {
|
|
| 5306 | - $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
| 5307 | - $type ='select'; |
|
| 5289 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5290 | + $param['options'] = array($reg[1].':'.$reg[2]=>'N'); |
|
| 5291 | + $type = 'link'; |
|
| 5292 | + } elseif (preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5293 | + $param['options'] = array($reg[1].':'.$reg[2]=>'N'); |
|
| 5294 | + $type = 'link'; |
|
| 5295 | + } elseif (preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5296 | + $param['options'] = array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5297 | + $type = 'sellist'; |
|
| 5298 | + } elseif (preg_match('/varchar\((\d+)\)/', $val['type'], $reg)) {
|
|
| 5299 | + $param['options'] = array(); |
|
| 5300 | + $type = 'varchar'; |
|
| 5301 | + $size = $reg[1]; |
|
| 5302 | + } elseif (preg_match('/varchar/', $val['type'])) {
|
|
| 5303 | + $param['options'] = array(); |
|
| 5304 | + $type = 'varchar'; |
|
| 5305 | + } elseif (is_array($this->fields[$key]['arrayofkeyval'])) {
|
|
| 5306 | + $param['options'] = $this->fields[$key]['arrayofkeyval']; |
|
| 5307 | + $type = 'select'; |
|
| 5308 | 5308 | } else {
|
| 5309 | - $param['options']=array(); |
|
| 5310 | - $type =$this->fields[$key]['type']; |
|
| 5309 | + $param['options'] = array(); |
|
| 5310 | + $type = $this->fields[$key]['type']; |
|
| 5311 | 5311 | } |
| 5312 | 5312 | |
| 5313 | - $label=$this->fields[$key]['label']; |
|
| 5313 | + $label = $this->fields[$key]['label']; |
|
| 5314 | 5314 | //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
| 5315 | - $default=$this->fields[$key]['default']; |
|
| 5316 | - $computed=$this->fields[$key]['computed']; |
|
| 5317 | - $unique=$this->fields[$key]['unique']; |
|
| 5318 | - $required=$this->fields[$key]['required']; |
|
| 5315 | + $default = $this->fields[$key]['default']; |
|
| 5316 | + $computed = $this->fields[$key]['computed']; |
|
| 5317 | + $unique = $this->fields[$key]['unique']; |
|
| 5318 | + $required = $this->fields[$key]['required']; |
|
| 5319 | 5319 | |
| 5320 | - $langfile=$this->fields[$key]['langfile']; |
|
| 5321 | - $list=$this->fields[$key]['list']; |
|
| 5322 | - $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
| 5320 | + $langfile = $this->fields[$key]['langfile']; |
|
| 5321 | + $list = $this->fields[$key]['list']; |
|
| 5322 | + $hidden = abs($this->fields[$key]['visible']) != 1 ? 1 : 0; |
|
| 5323 | 5323 | |
| 5324 | 5324 | $objectid = $this->id; |
| 5325 | 5325 | |
| 5326 | 5326 | |
| 5327 | 5327 | if ($computed) |
| 5328 | 5328 | {
|
| 5329 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5329 | + if (!preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5330 | 5330 | else return ''; |
| 5331 | 5331 | } |
| 5332 | 5332 | |
| 5333 | 5333 | |
| 5334 | 5334 | // Use in priority showsize from parameters, then $val['css'] then autodefine |
| 5335 | - if (empty($morecss) && ! empty($val['css'])) |
|
| 5335 | + if (empty($morecss) && !empty($val['css'])) |
|
| 5336 | 5336 | {
|
| 5337 | 5337 | $showsize = $val['css']; |
| 5338 | 5338 | } |
@@ -5346,16 +5346,16 @@ discard block |
||
| 5346 | 5346 | {
|
| 5347 | 5347 | $morecss = 'minwidth200imp'; |
| 5348 | 5348 | } |
| 5349 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5349 | + elseif (in_array($type, array('int', 'integer', 'price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
|
|
| 5350 | 5350 | {
|
| 5351 | 5351 | $morecss = 'maxwidth75'; |
| 5352 | 5352 | }elseif ($type == 'url') |
| 5353 | 5353 | {
|
| 5354 | - $morecss='minwidth400'; |
|
| 5354 | + $morecss = 'minwidth400'; |
|
| 5355 | 5355 | } |
| 5356 | 5356 | elseif ($type == 'boolean') |
| 5357 | 5357 | {
|
| 5358 | - $morecss=''; |
|
| 5358 | + $morecss = ''; |
|
| 5359 | 5359 | } |
| 5360 | 5360 | else |
| 5361 | 5361 | {
|
@@ -5374,12 +5374,12 @@ discard block |
||
| 5374 | 5374 | } |
| 5375 | 5375 | } |
| 5376 | 5376 | |
| 5377 | - if (in_array($type,array('date','datetime')))
|
|
| 5377 | + if (in_array($type, array('date', 'datetime')))
|
|
| 5378 | 5378 | {
|
| 5379 | - $tmp=explode(',',$size);
|
|
| 5380 | - $newsize=$tmp[0]; |
|
| 5379 | + $tmp = explode(',', $size);
|
|
| 5380 | + $newsize = $tmp[0]; |
|
| 5381 | 5381 | |
| 5382 | - $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
|
| 5382 | + $showtime = in_array($type, array('datetime')) ? 1 : 0;
|
|
| 5383 | 5383 | |
| 5384 | 5384 | // Do not show current date when field not required (see selectDate() method) |
| 5385 | 5385 | if (!$required && $value == '') $value = '-1'; |
@@ -5387,237 +5387,237 @@ discard block |
||
| 5387 | 5387 | // TODO Must also support $moreparam |
| 5388 | 5388 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 5389 | 5389 | } |
| 5390 | - elseif (in_array($type,array('int','integer')))
|
|
| 5390 | + elseif (in_array($type, array('int', 'integer')))
|
|
| 5391 | 5391 | {
|
| 5392 | - $tmp=explode(',',$size);
|
|
| 5393 | - $newsize=$tmp[0]; |
|
| 5394 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5392 | + $tmp = explode(',', $size);
|
|
| 5393 | + $newsize = $tmp[0]; |
|
| 5394 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
| 5395 | 5395 | } |
| 5396 | 5396 | elseif (preg_match('/varchar/', $type))
|
| 5397 | 5397 | {
|
| 5398 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
|
| 5398 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam ? $moreparam : '').'>'; |
|
| 5399 | 5399 | } |
| 5400 | 5400 | elseif (in_array($type, array('mail', 'phone', 'url')))
|
| 5401 | 5401 | {
|
| 5402 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5402 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5403 | 5403 | } |
| 5404 | 5404 | elseif ($type == 'text') |
| 5405 | 5405 | {
|
| 5406 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5406 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5407 | 5407 | {
|
| 5408 | 5408 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5409 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 5410 | - $out=$doleditor->Create(1); |
|
| 5409 | + $doleditor = new DolEditor($keyprefix.$key.$keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, false, ROWS_5, '90%'); |
|
| 5410 | + $out = $doleditor->Create(1); |
|
| 5411 | 5411 | } |
| 5412 | 5412 | else |
| 5413 | 5413 | {
|
| 5414 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5414 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5415 | 5415 | } |
| 5416 | 5416 | } |
| 5417 | 5417 | elseif ($type == 'html') |
| 5418 | 5418 | {
|
| 5419 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5419 | + if (!preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5420 | 5420 | {
|
| 5421 | 5421 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 5422 | - $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%'); |
|
| 5423 | - $out=$doleditor->Create(1); |
|
| 5422 | + $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%'); |
|
| 5423 | + $out = $doleditor->Create(1); |
|
| 5424 | 5424 | } |
| 5425 | 5425 | else |
| 5426 | 5426 | {
|
| 5427 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5427 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5428 | 5428 | } |
| 5429 | 5429 | } |
| 5430 | 5430 | elseif ($type == 'boolean') |
| 5431 | 5431 | {
|
| 5432 | - $checked=''; |
|
| 5432 | + $checked = ''; |
|
| 5433 | 5433 | if (!empty($value)) {
|
| 5434 | - $checked=' checked value="1" '; |
|
| 5434 | + $checked = ' checked value="1" '; |
|
| 5435 | 5435 | } else {
|
| 5436 | - $checked=' value="1" '; |
|
| 5436 | + $checked = ' value="1" '; |
|
| 5437 | 5437 | } |
| 5438 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5438 | + $out = '<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam ? $moreparam : '').'>'; |
|
| 5439 | 5439 | } |
| 5440 | 5440 | elseif ($type == 'price') |
| 5441 | 5441 | {
|
| 5442 | 5442 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
| 5443 | - $value=price($value); |
|
| 5443 | + $value = price($value); |
|
| 5444 | 5444 | } |
| 5445 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5445 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '.$langs->getCurrencySymbol($conf->currency); |
|
| 5446 | 5446 | } |
| 5447 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5447 | + elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/', $type))
|
|
| 5448 | 5448 | {
|
| 5449 | 5449 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
| 5450 | - $value=price($value); |
|
| 5450 | + $value = price($value); |
|
| 5451 | 5451 | } |
| 5452 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5452 | + $out = '<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'> '; |
|
| 5453 | 5453 | } |
| 5454 | 5454 | elseif ($type == 'select') |
| 5455 | 5455 | {
|
| 5456 | 5456 | $out = ''; |
| 5457 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5457 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5458 | 5458 | {
|
| 5459 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5460 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5459 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5460 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5461 | 5461 | } |
| 5462 | 5462 | |
| 5463 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5464 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5463 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5464 | + if ((!isset($this->fields[$key]['default'])) || ($this->fields[$key]['notnull'] != 1))$out .= '<option value="0"> </option>'; |
|
| 5465 | 5465 | foreach ($param['options'] as $key => $val) |
| 5466 | 5466 | {
|
| 5467 | 5467 | if ((string) $key == '') continue; |
| 5468 | 5468 | list($val, $parent) = explode('|', $val);
|
| 5469 | - $out.='<option value="'.$key.'"'; |
|
| 5470 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5471 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5472 | - $out.='>'.$val.'</option>'; |
|
| 5469 | + $out .= '<option value="'.$key.'"'; |
|
| 5470 | + $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
|
| 5471 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 5472 | + $out .= '>'.$val.'</option>'; |
|
| 5473 | 5473 | } |
| 5474 | - $out.='</select>'; |
|
| 5474 | + $out .= '</select>'; |
|
| 5475 | 5475 | } |
| 5476 | 5476 | elseif ($type == 'sellist') |
| 5477 | 5477 | {
|
| 5478 | 5478 | $out = ''; |
| 5479 | - if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5479 | + if (!empty($conf->use_javascript_ajax) && !empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
|
| 5480 | 5480 | {
|
| 5481 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5482 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5481 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5482 | + $out .= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5483 | 5483 | } |
| 5484 | 5484 | |
| 5485 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5485 | + $out .= '<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5486 | 5486 | if (is_array($param['options'])) |
| 5487 | 5487 | {
|
| 5488 | - $param_list=array_keys($param['options']); |
|
| 5488 | + $param_list = array_keys($param['options']); |
|
| 5489 | 5489 | $InfoFieldList = explode(":", $param_list[0]);
|
| 5490 | - $parentName=''; |
|
| 5491 | - $parentField=''; |
|
| 5490 | + $parentName = ''; |
|
| 5491 | + $parentField = ''; |
|
| 5492 | 5492 | // 0 : tableName |
| 5493 | 5493 | // 1 : label field name |
| 5494 | 5494 | // 2 : key fields name (if differ of rowid) |
| 5495 | 5495 | // 3 : key field parent (for dependent lists) |
| 5496 | 5496 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 5497 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5497 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 5498 | 5498 | |
| 5499 | 5499 | |
| 5500 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5500 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) |
|
| 5501 | 5501 | {
|
| 5502 | 5502 | if (strpos($InfoFieldList[4], 'extra.') !== false) |
| 5503 | 5503 | {
|
| 5504 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5504 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 5505 | 5505 | } else {
|
| 5506 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5506 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5507 | 5507 | } |
| 5508 | 5508 | } |
| 5509 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5509 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) |
|
| 5510 | 5510 | {
|
| 5511 | 5511 | list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
|
| 5512 | - $keyList.= ', '.$parentField; |
|
| 5512 | + $keyList .= ', '.$parentField; |
|
| 5513 | 5513 | } |
| 5514 | 5514 | |
| 5515 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5515 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5516 | 5516 | if (is_array($fields_label)) |
| 5517 | 5517 | {
|
| 5518 | - $keyList .=', '; |
|
| 5518 | + $keyList .= ', '; |
|
| 5519 | 5519 | $keyList .= implode(', ', $fields_label);
|
| 5520 | 5520 | } |
| 5521 | 5521 | |
| 5522 | - $sqlwhere=''; |
|
| 5522 | + $sqlwhere = ''; |
|
| 5523 | 5523 | $sql = 'SELECT '.$keyList; |
| 5524 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5524 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5525 | 5525 | if (!empty($InfoFieldList[4])) |
| 5526 | 5526 | {
|
| 5527 | 5527 | // can use SELECT request |
| 5528 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5529 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5528 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) {
|
|
| 5529 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
|
|
| 5530 | 5530 | } |
| 5531 | 5531 | |
| 5532 | 5532 | // current object id can be use into filter |
| 5533 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5534 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5533 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) {
|
|
| 5534 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]);
|
|
| 5535 | 5535 | } else {
|
| 5536 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5536 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
|
|
| 5537 | 5537 | } |
| 5538 | 5538 | //We have to join on extrafield table |
| 5539 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5539 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 5540 | 5540 | {
|
| 5541 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5542 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5541 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 5542 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 5543 | 5543 | } |
| 5544 | 5544 | else |
| 5545 | 5545 | {
|
| 5546 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5546 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 5547 | 5547 | } |
| 5548 | 5548 | } |
| 5549 | 5549 | else |
| 5550 | 5550 | {
|
| 5551 | - $sqlwhere.= ' WHERE 1=1'; |
|
| 5551 | + $sqlwhere .= ' WHERE 1=1'; |
|
| 5552 | 5552 | } |
| 5553 | 5553 | // Some tables may have field, some other not. For the moment we disable it. |
| 5554 | - if (in_array($InfoFieldList[0],array('tablewithentity')))
|
|
| 5554 | + if (in_array($InfoFieldList[0], array('tablewithentity')))
|
|
| 5555 | 5555 | {
|
| 5556 | - $sqlwhere.= ' AND entity = '.$conf->entity; |
|
| 5556 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 5557 | 5557 | } |
| 5558 | - $sql.=$sqlwhere; |
|
| 5558 | + $sql .= $sqlwhere; |
|
| 5559 | 5559 | //print $sql; |
| 5560 | 5560 | |
| 5561 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label);
|
|
| 5561 | + $sql .= ' ORDER BY '.implode(', ', $fields_label);
|
|
| 5562 | 5562 | |
| 5563 | 5563 | dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
| 5564 | 5564 | $resql = $this->db->query($sql); |
| 5565 | 5565 | if ($resql) |
| 5566 | 5566 | {
|
| 5567 | - $out.='<option value="0"> </option>'; |
|
| 5567 | + $out .= '<option value="0"> </option>'; |
|
| 5568 | 5568 | $num = $this->db->num_rows($resql); |
| 5569 | 5569 | $i = 0; |
| 5570 | 5570 | while ($i < $num) |
| 5571 | 5571 | {
|
| 5572 | - $labeltoshow=''; |
|
| 5572 | + $labeltoshow = ''; |
|
| 5573 | 5573 | $obj = $this->db->fetch_object($resql); |
| 5574 | 5574 | |
| 5575 | 5575 | // Several field into label (eq table:code|libelle:rowid) |
| 5576 | 5576 | $notrans = false; |
| 5577 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5577 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5578 | 5578 | if (is_array($fields_label)) |
| 5579 | 5579 | {
|
| 5580 | 5580 | $notrans = true; |
| 5581 | 5581 | foreach ($fields_label as $field_toshow) |
| 5582 | 5582 | {
|
| 5583 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5583 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 5584 | 5584 | } |
| 5585 | 5585 | } |
| 5586 | 5586 | else |
| 5587 | 5587 | {
|
| 5588 | - $labeltoshow=$obj->{$InfoFieldList[1]};
|
|
| 5588 | + $labeltoshow = $obj->{$InfoFieldList[1]};
|
|
| 5589 | 5589 | } |
| 5590 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5590 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5591 | 5591 | |
| 5592 | 5592 | if ($value == $obj->rowid) |
| 5593 | 5593 | {
|
| 5594 | 5594 | foreach ($fields_label as $field_toshow) |
| 5595 | 5595 | {
|
| 5596 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 5597 | - if ($translabel!=$obj->$field_toshow) {
|
|
| 5598 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5599 | - }else {
|
|
| 5600 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5596 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 5597 | + if ($translabel != $obj->$field_toshow) {
|
|
| 5598 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 5599 | + } else {
|
|
| 5600 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 5601 | 5601 | } |
| 5602 | 5602 | } |
| 5603 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5603 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5604 | 5604 | } |
| 5605 | 5605 | else |
| 5606 | 5606 | {
|
| 5607 | - if (! $notrans) |
|
| 5607 | + if (!$notrans) |
|
| 5608 | 5608 | {
|
| 5609 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5610 | - if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 5611 | - $labeltoshow=dol_trunc($translabel,18); |
|
| 5609 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5610 | + if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 5611 | + $labeltoshow = dol_trunc($translabel, 18); |
|
| 5612 | 5612 | } |
| 5613 | 5613 | else {
|
| 5614 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
|
| 5614 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]},18);
|
|
| 5615 | 5615 | } |
| 5616 | 5616 | } |
| 5617 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5618 | - if ($value==$obj->rowid) |
|
| 5617 | + if (empty($labeltoshow)) $labeltoshow = '(not defined)'; |
|
| 5618 | + if ($value == $obj->rowid) |
|
| 5619 | 5619 | {
|
| 5620 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5620 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5621 | 5621 | } |
| 5622 | 5622 | |
| 5623 | 5623 | if (!empty($InfoFieldList[3]) && $parentField) |
@@ -5625,10 +5625,10 @@ discard block |
||
| 5625 | 5625 | $parent = $parentName.':'.$obj->{$parentField};
|
| 5626 | 5626 | } |
| 5627 | 5627 | |
| 5628 | - $out.='<option value="'.$obj->rowid.'"'; |
|
| 5629 | - $out.= ($value==$obj->rowid?' selected':''); |
|
| 5630 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5631 | - $out.='>'.$labeltoshow.'</option>'; |
|
| 5628 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 5629 | + $out .= ($value == $obj->rowid ? ' selected' : ''); |
|
| 5630 | + $out .= (!empty($parent) ? ' parent="'.$parent.'"' : ''); |
|
| 5631 | + $out .= '>'.$labeltoshow.'</option>'; |
|
| 5632 | 5632 | } |
| 5633 | 5633 | |
| 5634 | 5634 | $i++; |
@@ -5639,23 +5639,23 @@ discard block |
||
| 5639 | 5639 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 5640 | 5640 | } |
| 5641 | 5641 | } |
| 5642 | - $out.='</select>'; |
|
| 5642 | + $out .= '</select>'; |
|
| 5643 | 5643 | } |
| 5644 | 5644 | elseif ($type == 'checkbox') |
| 5645 | 5645 | {
|
| 5646 | - $value_arr=explode(',',$value);
|
|
| 5647 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5646 | + $value_arr = explode(',', $value);
|
|
| 5647 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options']) ?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5648 | 5648 | } |
| 5649 | 5649 | elseif ($type == 'radio') |
| 5650 | 5650 | {
|
| 5651 | - $out=''; |
|
| 5651 | + $out = ''; |
|
| 5652 | 5652 | foreach ($param['options'] as $keyopt => $val) |
| 5653 | 5653 | {
|
| 5654 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5655 | - $out.=' value="'.$keyopt.'"'; |
|
| 5656 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5657 | - $out.= ($value==$keyopt?'checked':''); |
|
| 5658 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5654 | + $out .= '<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam ? $moreparam : ''); |
|
| 5655 | + $out .= ' value="'.$keyopt.'"'; |
|
| 5656 | + $out .= ' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5657 | + $out .= ($value == $keyopt ? 'checked' : ''); |
|
| 5658 | + $out .= '/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5659 | 5659 | } |
| 5660 | 5660 | } |
| 5661 | 5661 | elseif ($type == 'chkbxlst') |
@@ -5670,24 +5670,24 @@ discard block |
||
| 5670 | 5670 | if (is_array($param['options'])) {
|
| 5671 | 5671 | $param_list = array_keys($param['options']); |
| 5672 | 5672 | $InfoFieldList = explode(":", $param_list[0]);
|
| 5673 | - $parentName=''; |
|
| 5674 | - $parentField=''; |
|
| 5673 | + $parentName = ''; |
|
| 5674 | + $parentField = ''; |
|
| 5675 | 5675 | // 0 : tableName |
| 5676 | 5676 | // 1 : label field name |
| 5677 | 5677 | // 2 : key fields name (if differ of rowid) |
| 5678 | 5678 | // 3 : key field parent (for dependent lists) |
| 5679 | 5679 | // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
| 5680 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5680 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2].' as rowid'); |
|
| 5681 | 5681 | |
| 5682 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
|
|
| 5683 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
|
|
| 5684 | - $keyList .= ', ' . $parentField; |
|
| 5682 | + if (count($InfoFieldList) > 3 && !empty($InfoFieldList[3])) {
|
|
| 5683 | + list ($parentName, $parentField) = explode('|', $InfoFieldList[3]);
|
|
| 5684 | + $keyList .= ', '.$parentField; |
|
| 5685 | 5685 | } |
| 5686 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
|
|
| 5686 | + if (count($InfoFieldList) > 4 && !empty($InfoFieldList[4])) {
|
|
| 5687 | 5687 | if (strpos($InfoFieldList[4], 'extra.') !== false) {
|
| 5688 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5688 | + $keyList = 'main.'.$InfoFieldList[2].' as rowid'; |
|
| 5689 | 5689 | } else {
|
| 5690 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5690 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 5691 | 5691 | } |
| 5692 | 5692 | } |
| 5693 | 5693 | |
@@ -5698,50 +5698,50 @@ discard block |
||
| 5698 | 5698 | } |
| 5699 | 5699 | |
| 5700 | 5700 | $sqlwhere = ''; |
| 5701 | - $sql = 'SELECT ' . $keyList; |
|
| 5702 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5703 | - if (! empty($InfoFieldList[4])) {
|
|
| 5701 | + $sql = 'SELECT '.$keyList; |
|
| 5702 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 5703 | + if (!empty($InfoFieldList[4])) {
|
|
| 5704 | 5704 | |
| 5705 | 5705 | // can use SELECT request |
| 5706 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5707 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5706 | + if (strpos($InfoFieldList[4], '$SEL$') !== false) {
|
|
| 5707 | + $InfoFieldList[4] = str_replace('$SEL$', 'SELECT', $InfoFieldList[4]);
|
|
| 5708 | 5708 | } |
| 5709 | 5709 | |
| 5710 | 5710 | // current object id can be use into filter |
| 5711 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5712 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5711 | + if (strpos($InfoFieldList[4], '$ID$') !== false && !empty($objectid)) {
|
|
| 5712 | + $InfoFieldList[4] = str_replace('$ID$', $objectid, $InfoFieldList[4]);
|
|
| 5713 | 5713 | } else {
|
| 5714 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5714 | + $InfoFieldList[4] = str_replace('$ID$', '0', $InfoFieldList[4]);
|
|
| 5715 | 5715 | } |
| 5716 | 5716 | |
| 5717 | 5717 | // We have to join on extrafield table |
| 5718 | 5718 | if (strpos($InfoFieldList[4], 'extra') !== false) {
|
| 5719 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5720 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5719 | + $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; |
|
| 5720 | + $sqlwhere .= ' WHERE extra.fk_object=main.'.$InfoFieldList[2].' AND '.$InfoFieldList[4]; |
|
| 5721 | 5721 | } else {
|
| 5722 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5722 | + $sqlwhere .= ' WHERE '.$InfoFieldList[4]; |
|
| 5723 | 5723 | } |
| 5724 | 5724 | } else {
|
| 5725 | 5725 | $sqlwhere .= ' WHERE 1=1'; |
| 5726 | 5726 | } |
| 5727 | 5727 | // Some tables may have field, some other not. For the moment we disable it. |
| 5728 | - if (in_array($InfoFieldList[0], array ('tablewithentity')))
|
|
| 5728 | + if (in_array($InfoFieldList[0], array('tablewithentity')))
|
|
| 5729 | 5729 | {
|
| 5730 | - $sqlwhere .= ' AND entity = ' . $conf->entity; |
|
| 5730 | + $sqlwhere .= ' AND entity = '.$conf->entity; |
|
| 5731 | 5731 | } |
| 5732 | 5732 | // $sql.=preg_replace('/^ AND /','',$sqlwhere);
|
| 5733 | 5733 | // print $sql; |
| 5734 | 5734 | |
| 5735 | 5735 | $sql .= $sqlwhere; |
| 5736 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5736 | + dol_syslog(get_class($this).'::showInputField type=chkbxlst', LOG_DEBUG); |
|
| 5737 | 5737 | $resql = $this->db->query($sql); |
| 5738 | 5738 | if ($resql) {
|
| 5739 | 5739 | $num = $this->db->num_rows($resql); |
| 5740 | 5740 | $i = 0; |
| 5741 | 5741 | |
| 5742 | - $data=array(); |
|
| 5742 | + $data = array(); |
|
| 5743 | 5743 | |
| 5744 | - while ( $i < $num ) {
|
|
| 5744 | + while ($i < $num) {
|
|
| 5745 | 5745 | $labeltoshow = ''; |
| 5746 | 5746 | $obj = $this->db->fetch_object($resql); |
| 5747 | 5747 | |
@@ -5750,8 +5750,8 @@ discard block |
||
| 5750 | 5750 | $fields_label = explode('|', $InfoFieldList[1]);
|
| 5751 | 5751 | if (is_array($fields_label)) {
|
| 5752 | 5752 | $notrans = true; |
| 5753 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 5754 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 5753 | + foreach ($fields_label as $field_toshow) {
|
|
| 5754 | + $labeltoshow .= $obj->$field_toshow.' '; |
|
| 5755 | 5755 | } |
| 5756 | 5756 | } else {
|
| 5757 | 5757 | $labeltoshow = $obj->{$InfoFieldList[1]};
|
@@ -5759,18 +5759,18 @@ discard block |
||
| 5759 | 5759 | $labeltoshow = dol_trunc($labeltoshow, 45); |
| 5760 | 5760 | |
| 5761 | 5761 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
| 5762 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 5762 | + foreach ($fields_label as $field_toshow) {
|
|
| 5763 | 5763 | $translabel = $langs->trans($obj->$field_toshow); |
| 5764 | 5764 | if ($translabel != $obj->$field_toshow) {
|
| 5765 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5765 | + $labeltoshow = dol_trunc($translabel, 18).' '; |
|
| 5766 | 5766 | } else {
|
| 5767 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5767 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18).' '; |
|
| 5768 | 5768 | } |
| 5769 | 5769 | } |
| 5770 | 5770 | |
| 5771 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5771 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5772 | 5772 | } else {
|
| 5773 | - if (! $notrans) {
|
|
| 5773 | + if (!$notrans) {
|
|
| 5774 | 5774 | $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
| 5775 | 5775 | if ($translabel != $obj->{$InfoFieldList[1]}) {
|
| 5776 | 5776 | $labeltoshow = dol_trunc($translabel, 18); |
@@ -5782,67 +5782,67 @@ discard block |
||
| 5782 | 5782 | $labeltoshow = '(not defined)'; |
| 5783 | 5783 | |
| 5784 | 5784 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
| 5785 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5785 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5786 | 5786 | } |
| 5787 | 5787 | |
| 5788 | - if (! empty($InfoFieldList[3]) && $parentField) {
|
|
| 5789 | - $parent = $parentName . ':' . $obj->{$parentField};
|
|
| 5788 | + if (!empty($InfoFieldList[3]) && $parentField) {
|
|
| 5789 | + $parent = $parentName.':'.$obj->{$parentField};
|
|
| 5790 | 5790 | } |
| 5791 | 5791 | |
| 5792 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5792 | + $data[$obj->rowid] = $labeltoshow; |
|
| 5793 | 5793 | } |
| 5794 | 5794 | |
| 5795 | - $i ++; |
|
| 5795 | + $i++; |
|
| 5796 | 5796 | } |
| 5797 | 5797 | $this->db->free($resql); |
| 5798 | 5798 | |
| 5799 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5799 | + $out = $form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5800 | 5800 | } else {
|
| 5801 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5801 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5802 | 5802 | } |
| 5803 | 5803 | } |
| 5804 | 5804 | } |
| 5805 | 5805 | elseif ($type == 'link') |
| 5806 | 5806 | {
|
| 5807 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5808 | - $showempty=(($required && $default != '')?0:1); |
|
| 5809 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5807 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5808 | + $showempty = (($required && $default != '') ? 0 : 1); |
|
| 5809 | + $out = $form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5810 | 5810 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
| 5811 | 5811 | {
|
| 5812 | - list($class,$classfile)=explode(':',$param_list[0]);
|
|
| 5813 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5814 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 5815 | - $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5812 | + list($class, $classfile) = explode(':', $param_list[0]);
|
|
| 5813 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path = dol_buildpath(dirname(dirname($classfile)).'/card.php', 1); |
|
| 5814 | + else $url_path = dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php', 1); |
|
| 5815 | + $out .= '<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5816 | 5816 | // TODO Add Javascript code to add input fields contents to new elements urls |
| 5817 | 5817 | } |
| 5818 | 5818 | } |
| 5819 | 5819 | elseif ($type == 'password') |
| 5820 | 5820 | {
|
| 5821 | 5821 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 5822 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5822 | + $out = '<input type="'.($keyprefix == 'search_' ? 'text' : 'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam ? $moreparam : '').'>'; |
|
| 5823 | 5823 | } |
| 5824 | 5824 | elseif ($type == 'array') |
| 5825 | 5825 | {
|
| 5826 | 5826 | $newval = $val; |
| 5827 | 5827 | $newval['type'] = 'varchar(256)'; |
| 5828 | 5828 | |
| 5829 | - $out=''; |
|
| 5829 | + $out = ''; |
|
| 5830 | 5830 | |
| 5831 | 5831 | $inputs = array(); |
| 5832 | - if(! empty($value)) {
|
|
| 5833 | - foreach($value as $option) {
|
|
| 5834 | - $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5835 | - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5832 | + if (!empty($value)) {
|
|
| 5833 | + foreach ($value as $option) {
|
|
| 5834 | + $out .= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5835 | + $out .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5836 | 5836 | } |
| 5837 | 5837 | } |
| 5838 | 5838 | |
| 5839 | - $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5839 | + $out .= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5840 | 5840 | |
| 5841 | 5841 | $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
| 5842 | - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5842 | + $newInput .= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5843 | 5843 | |
| 5844 | - if(! empty($conf->use_javascript_ajax)) {
|
|
| 5845 | - $out.= ' |
|
| 5844 | + if (!empty($conf->use_javascript_ajax)) {
|
|
| 5845 | + $out .= ' |
|
| 5846 | 5846 | <script type="text/javascript"> |
| 5847 | 5847 | $(document).ready(function() {
|
| 5848 | 5848 | $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() {
|
@@ -5857,7 +5857,7 @@ discard block |
||
| 5857 | 5857 | } |
| 5858 | 5858 | } |
| 5859 | 5859 | if (!empty($hidden)) {
|
| 5860 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5860 | + $out = '<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5861 | 5861 | } |
| 5862 | 5862 | /* Add comments |
| 5863 | 5863 | if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
@@ -5879,14 +5879,14 @@ discard block |
||
| 5879 | 5879 | * @param mixed $showsize Value for css to define size. May also be a numeric. |
| 5880 | 5880 | * @return string |
| 5881 | 5881 | */ |
| 5882 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5882 | + function showOutputField($val, $key, $value, $moreparam = '', $keysuffix = '', $keyprefix = '', $showsize = 0) |
|
| 5883 | 5883 | {
|
| 5884 | - global $conf,$langs,$form; |
|
| 5884 | + global $conf, $langs, $form; |
|
| 5885 | 5885 | |
| 5886 | - if (! is_object($form)) |
|
| 5886 | + if (!is_object($form)) |
|
| 5887 | 5887 | {
|
| 5888 | 5888 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
| 5889 | - $form=new Form($this->db); |
|
| 5889 | + $form = new Form($this->db); |
|
| 5890 | 5890 | } |
| 5891 | 5891 | |
| 5892 | 5892 | $objectid = $this->id; |
@@ -5897,28 +5897,28 @@ discard block |
||
| 5897 | 5897 | // Convert var to be able to share same code than showOutputField of extrafields |
| 5898 | 5898 | if (preg_match('/varchar\((\d+)\)/', $type, $reg))
|
| 5899 | 5899 | {
|
| 5900 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5900 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5901 | 5901 | $size = $reg[1]; |
| 5902 | 5902 | } |
| 5903 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5904 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5905 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 5903 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5904 | + if (is_array($val['arrayofkeyval'])) $type = 'select'; |
|
| 5905 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type = 'link';
|
|
| 5906 | 5906 | |
| 5907 | - $default=$val['default']; |
|
| 5908 | - $computed=$val['computed']; |
|
| 5909 | - $unique=$val['unique']; |
|
| 5910 | - $required=$val['required']; |
|
| 5911 | - $param=$val['param']; |
|
| 5907 | + $default = $val['default']; |
|
| 5908 | + $computed = $val['computed']; |
|
| 5909 | + $unique = $val['unique']; |
|
| 5910 | + $required = $val['required']; |
|
| 5911 | + $param = $val['param']; |
|
| 5912 | 5912 | if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
| 5913 | 5913 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
| 5914 | 5914 | {
|
| 5915 | - $type='link'; |
|
| 5916 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5915 | + $type = 'link'; |
|
| 5916 | + $param['options'] = array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5917 | 5917 | } |
| 5918 | - $langfile=$val['langfile']; |
|
| 5919 | - $list=$val['list']; |
|
| 5920 | - $help=$val['help']; |
|
| 5921 | - $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) |
|
| 5918 | + $langfile = $val['langfile']; |
|
| 5919 | + $list = $val['list']; |
|
| 5920 | + $help = $val['help']; |
|
| 5921 | + $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) |
|
| 5922 | 5922 | |
| 5923 | 5923 | if ($hidden) return ''; |
| 5924 | 5924 | |
@@ -5942,18 +5942,18 @@ discard block |
||
| 5942 | 5942 | //$showsize=19; |
| 5943 | 5943 | $showsize = 'minwidth200imp'; |
| 5944 | 5944 | } |
| 5945 | - elseif (in_array($type,array('int','double','price')))
|
|
| 5945 | + elseif (in_array($type, array('int', 'double', 'price')))
|
|
| 5946 | 5946 | {
|
| 5947 | 5947 | //$showsize=10; |
| 5948 | 5948 | $showsize = 'maxwidth75'; |
| 5949 | 5949 | } |
| 5950 | 5950 | elseif ($type == 'url') |
| 5951 | 5951 | {
|
| 5952 | - $showsize='minwidth400'; |
|
| 5952 | + $showsize = 'minwidth400'; |
|
| 5953 | 5953 | } |
| 5954 | 5954 | elseif ($type == 'boolean') |
| 5955 | 5955 | {
|
| 5956 | - $showsize=''; |
|
| 5956 | + $showsize = ''; |
|
| 5957 | 5957 | } |
| 5958 | 5958 | else |
| 5959 | 5959 | {
|
@@ -5974,90 +5974,90 @@ discard block |
||
| 5974 | 5974 | } |
| 5975 | 5975 | |
| 5976 | 5976 | // Format output value differently according to properties of field |
| 5977 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5978 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5977 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value = $this->getNomUrl(1, '', 0, '', 1); |
|
| 5978 | + elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value = $this->getLibStatut(3); |
|
| 5979 | 5979 | elseif ($type == 'date') |
| 5980 | 5980 | {
|
| 5981 | - if(! empty($value)) {
|
|
| 5982 | - $value=dol_print_date($value,'day'); |
|
| 5981 | + if (!empty($value)) {
|
|
| 5982 | + $value = dol_print_date($value, 'day'); |
|
| 5983 | 5983 | } else {
|
| 5984 | - $value=''; |
|
| 5984 | + $value = ''; |
|
| 5985 | 5985 | } |
| 5986 | 5986 | } |
| 5987 | 5987 | elseif ($type == 'datetime') |
| 5988 | 5988 | {
|
| 5989 | - if(! empty($value)) {
|
|
| 5990 | - $value=dol_print_date($value,'dayhour'); |
|
| 5989 | + if (!empty($value)) {
|
|
| 5990 | + $value = dol_print_date($value, 'dayhour'); |
|
| 5991 | 5991 | } else {
|
| 5992 | - $value=''; |
|
| 5992 | + $value = ''; |
|
| 5993 | 5993 | } |
| 5994 | 5994 | } |
| 5995 | 5995 | elseif ($type == 'double') |
| 5996 | 5996 | {
|
| 5997 | 5997 | if (!empty($value)) {
|
| 5998 | - $value=price($value); |
|
| 5998 | + $value = price($value); |
|
| 5999 | 5999 | } |
| 6000 | 6000 | } |
| 6001 | 6001 | elseif ($type == 'boolean') |
| 6002 | 6002 | {
|
| 6003 | - $checked=''; |
|
| 6003 | + $checked = ''; |
|
| 6004 | 6004 | if (!empty($value)) {
|
| 6005 | - $checked=' checked '; |
|
| 6005 | + $checked = ' checked '; |
|
| 6006 | 6006 | } |
| 6007 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 6007 | + $value = '<input type="checkbox" '.$checked.' '.($moreparam ? $moreparam : '').' readonly disabled>'; |
|
| 6008 | 6008 | } |
| 6009 | 6009 | elseif ($type == 'mail') |
| 6010 | 6010 | {
|
| 6011 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 6011 | + $value = dol_print_email($value, 0, 0, 0, 64, 1, 1); |
|
| 6012 | 6012 | } |
| 6013 | 6013 | elseif ($type == 'url') |
| 6014 | 6014 | {
|
| 6015 | - $value=dol_print_url($value,'_blank',32,1); |
|
| 6015 | + $value = dol_print_url($value, '_blank', 32, 1); |
|
| 6016 | 6016 | } |
| 6017 | 6017 | elseif ($type == 'phone') |
| 6018 | 6018 | {
|
| 6019 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6019 | + $value = dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6020 | 6020 | } |
| 6021 | 6021 | elseif ($type == 'price') |
| 6022 | 6022 | {
|
| 6023 | - $value=price($value,0,$langs,0,0,-1,$conf->currency); |
|
| 6023 | + $value = price($value, 0, $langs, 0, 0, -1, $conf->currency); |
|
| 6024 | 6024 | } |
| 6025 | 6025 | elseif ($type == 'select') |
| 6026 | 6026 | {
|
| 6027 | - $value=$param['options'][$value]; |
|
| 6027 | + $value = $param['options'][$value]; |
|
| 6028 | 6028 | } |
| 6029 | 6029 | elseif ($type == 'sellist') |
| 6030 | 6030 | {
|
| 6031 | - $param_list=array_keys($param['options']); |
|
| 6031 | + $param_list = array_keys($param['options']); |
|
| 6032 | 6032 | $InfoFieldList = explode(":", $param_list[0]);
|
| 6033 | 6033 | |
| 6034 | - $selectkey="rowid"; |
|
| 6035 | - $keyList='rowid'; |
|
| 6034 | + $selectkey = "rowid"; |
|
| 6035 | + $keyList = 'rowid'; |
|
| 6036 | 6036 | |
| 6037 | - if (count($InfoFieldList)>=3) |
|
| 6037 | + if (count($InfoFieldList) >= 3) |
|
| 6038 | 6038 | {
|
| 6039 | 6039 | $selectkey = $InfoFieldList[2]; |
| 6040 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 6040 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 6041 | 6041 | } |
| 6042 | 6042 | |
| 6043 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6044 | - if(is_array($fields_label)) {
|
|
| 6045 | - $keyList .=', '; |
|
| 6043 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6044 | + if (is_array($fields_label)) {
|
|
| 6045 | + $keyList .= ', '; |
|
| 6046 | 6046 | $keyList .= implode(', ', $fields_label);
|
| 6047 | 6047 | } |
| 6048 | 6048 | |
| 6049 | 6049 | $sql = 'SELECT '.$keyList; |
| 6050 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 6051 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 6050 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 6051 | + if (strpos($InfoFieldList[4], 'extra') !== false) |
|
| 6052 | 6052 | {
|
| 6053 | - $sql.= ' as main'; |
|
| 6053 | + $sql .= ' as main'; |
|
| 6054 | 6054 | } |
| 6055 | - if ($selectkey=='rowid' && empty($value)) {
|
|
| 6056 | - $sql.= " WHERE ".$selectkey."=0"; |
|
| 6057 | - } elseif ($selectkey=='rowid') {
|
|
| 6058 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6059 | - }else {
|
|
| 6060 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6055 | + if ($selectkey == 'rowid' && empty($value)) {
|
|
| 6056 | + $sql .= " WHERE ".$selectkey."=0"; |
|
| 6057 | + } elseif ($selectkey == 'rowid') {
|
|
| 6058 | + $sql .= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6059 | + } else {
|
|
| 6060 | + $sql .= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6061 | 6061 | } |
| 6062 | 6062 | |
| 6063 | 6063 | //$sql.= ' AND entity = '.$conf->entity; |
@@ -6066,38 +6066,38 @@ discard block |
||
| 6066 | 6066 | $resql = $this->db->query($sql); |
| 6067 | 6067 | if ($resql) |
| 6068 | 6068 | {
|
| 6069 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
| 6069 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 6070 | 6070 | |
| 6071 | 6071 | $obj = $this->db->fetch_object($resql); |
| 6072 | 6072 | |
| 6073 | 6073 | // Several field into label (eq table:code|libelle:rowid) |
| 6074 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6074 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6075 | 6075 | |
| 6076 | - if(is_array($fields_label) && count($fields_label)>1) |
|
| 6076 | + if (is_array($fields_label) && count($fields_label) > 1) |
|
| 6077 | 6077 | {
|
| 6078 | 6078 | foreach ($fields_label as $field_toshow) |
| 6079 | 6079 | {
|
| 6080 | - $translabel=''; |
|
| 6080 | + $translabel = ''; |
|
| 6081 | 6081 | if (!empty($obj->$field_toshow)) {
|
| 6082 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 6082 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 6083 | 6083 | } |
| 6084 | - if ($translabel!=$field_toshow) {
|
|
| 6085 | - $value.=dol_trunc($translabel,18).' '; |
|
| 6086 | - }else {
|
|
| 6087 | - $value.=$obj->$field_toshow.' '; |
|
| 6084 | + if ($translabel != $field_toshow) {
|
|
| 6085 | + $value .= dol_trunc($translabel, 18).' '; |
|
| 6086 | + } else {
|
|
| 6087 | + $value .= $obj->$field_toshow.' '; |
|
| 6088 | 6088 | } |
| 6089 | 6089 | } |
| 6090 | 6090 | } |
| 6091 | 6091 | else |
| 6092 | 6092 | {
|
| 6093 | - $translabel=''; |
|
| 6093 | + $translabel = ''; |
|
| 6094 | 6094 | if (!empty($obj->{$InfoFieldList[1]})) {
|
| 6095 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6095 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6096 | 6096 | } |
| 6097 | - if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 6098 | - $value=dol_trunc($translabel,18); |
|
| 6099 | - }else {
|
|
| 6100 | - $value=$obj->{$InfoFieldList[1]};
|
|
| 6097 | + if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 6098 | + $value = dol_trunc($translabel, 18); |
|
| 6099 | + } else {
|
|
| 6100 | + $value = $obj->{$InfoFieldList[1]};
|
|
| 6101 | 6101 | } |
| 6102 | 6102 | } |
| 6103 | 6103 | } |
@@ -6105,18 +6105,18 @@ discard block |
||
| 6105 | 6105 | } |
| 6106 | 6106 | elseif ($type == 'radio') |
| 6107 | 6107 | {
|
| 6108 | - $value=$param['options'][$value]; |
|
| 6108 | + $value = $param['options'][$value]; |
|
| 6109 | 6109 | } |
| 6110 | 6110 | elseif ($type == 'checkbox') |
| 6111 | 6111 | {
|
| 6112 | - $value_arr=explode(',',$value);
|
|
| 6113 | - $value=''; |
|
| 6114 | - if (is_array($value_arr) && count($value_arr)>0) |
|
| 6112 | + $value_arr = explode(',', $value);
|
|
| 6113 | + $value = ''; |
|
| 6114 | + if (is_array($value_arr) && count($value_arr) > 0) |
|
| 6115 | 6115 | {
|
| 6116 | 6116 | foreach ($value_arr as $keyval=>$valueval) {
|
| 6117 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6117 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6118 | 6118 | } |
| 6119 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6119 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6120 | 6120 | } |
| 6121 | 6121 | } |
| 6122 | 6122 | elseif ($type == 'chkbxlst') |
@@ -6131,7 +6131,7 @@ discard block |
||
| 6131 | 6131 | |
| 6132 | 6132 | if (count($InfoFieldList) >= 3) {
|
| 6133 | 6133 | $selectkey = $InfoFieldList[2]; |
| 6134 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 6134 | + $keyList = $InfoFieldList[2].' as rowid'; |
|
| 6135 | 6135 | } |
| 6136 | 6136 | |
| 6137 | 6137 | $fields_label = explode('|', $InfoFieldList[1]);
|
@@ -6140,75 +6140,75 @@ discard block |
||
| 6140 | 6140 | $keyList .= implode(', ', $fields_label);
|
| 6141 | 6141 | } |
| 6142 | 6142 | |
| 6143 | - $sql = 'SELECT ' . $keyList; |
|
| 6144 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 6143 | + $sql = 'SELECT '.$keyList; |
|
| 6144 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; |
|
| 6145 | 6145 | if (strpos($InfoFieldList[4], 'extra') !== false) {
|
| 6146 | 6146 | $sql .= ' as main'; |
| 6147 | 6147 | } |
| 6148 | 6148 | // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 6149 | 6149 | // $sql.= ' AND entity = '.$conf->entity; |
| 6150 | 6150 | |
| 6151 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 6151 | + dol_syslog(get_class($this).':showOutputField:$type=chkbxlst', LOG_DEBUG); |
|
| 6152 | 6152 | $resql = $this->db->query($sql); |
| 6153 | 6153 | if ($resql) {
|
| 6154 | 6154 | $value = ''; // value was used, so now we reste it to use it to build final output |
| 6155 | - $toprint=array(); |
|
| 6156 | - while ( $obj = $this->db->fetch_object($resql) ) {
|
|
| 6155 | + $toprint = array(); |
|
| 6156 | + while ($obj = $this->db->fetch_object($resql)) {
|
|
| 6157 | 6157 | |
| 6158 | 6158 | // Several field into label (eq table:code|libelle:rowid) |
| 6159 | 6159 | $fields_label = explode('|', $InfoFieldList[1]);
|
| 6160 | 6160 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
| 6161 | 6161 | if (is_array($fields_label) && count($fields_label) > 1) {
|
| 6162 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 6162 | + foreach ($fields_label as $field_toshow) {
|
|
| 6163 | 6163 | $translabel = ''; |
| 6164 | - if (! empty($obj->$field_toshow)) {
|
|
| 6164 | + if (!empty($obj->$field_toshow)) {
|
|
| 6165 | 6165 | $translabel = $langs->trans($obj->$field_toshow); |
| 6166 | 6166 | } |
| 6167 | 6167 | if ($translabel != $field_toshow) {
|
| 6168 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6168 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6169 | 6169 | } else {
|
| 6170 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 6170 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->$field_toshow.'</li>'; |
|
| 6171 | 6171 | } |
| 6172 | 6172 | } |
| 6173 | 6173 | } else {
|
| 6174 | 6174 | $translabel = ''; |
| 6175 | - if (! empty($obj->{$InfoFieldList[1]})) {
|
|
| 6175 | + if (!empty($obj->{$InfoFieldList[1]})) {
|
|
| 6176 | 6176 | $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
| 6177 | 6177 | } |
| 6178 | 6178 | if ($translabel != $obj->{$InfoFieldList[1]}) {
|
| 6179 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6179 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6180 | 6180 | } else {
|
| 6181 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
|
|
| 6181 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
|
|
| 6182 | 6182 | } |
| 6183 | 6183 | } |
| 6184 | 6184 | } |
| 6185 | 6185 | } |
| 6186 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6186 | + $value = '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6187 | 6187 | } else {
|
| 6188 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 6188 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6189 | 6189 | } |
| 6190 | 6190 | } |
| 6191 | 6191 | elseif ($type == 'link') |
| 6192 | 6192 | {
|
| 6193 | - $out=''; |
|
| 6193 | + $out = ''; |
|
| 6194 | 6194 | |
| 6195 | 6195 | // only if something to display (perf) |
| 6196 | 6196 | if ($value) |
| 6197 | 6197 | {
|
| 6198 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 6198 | + $param_list = array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 6199 | 6199 | |
| 6200 | 6200 | $InfoFieldList = explode(":", $param_list[0]);
|
| 6201 | - $classname=$InfoFieldList[0]; |
|
| 6202 | - $classpath=$InfoFieldList[1]; |
|
| 6203 | - $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6204 | - if (! empty($classpath)) |
|
| 6201 | + $classname = $InfoFieldList[0]; |
|
| 6202 | + $classpath = $InfoFieldList[1]; |
|
| 6203 | + $getnomurlparam = (empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6204 | + if (!empty($classpath)) |
|
| 6205 | 6205 | {
|
| 6206 | 6206 | dol_include_once($InfoFieldList[1]); |
| 6207 | 6207 | if ($classname && class_exists($classname)) |
| 6208 | 6208 | {
|
| 6209 | 6209 | $object = new $classname($this->db); |
| 6210 | 6210 | $object->fetch($value); |
| 6211 | - $value=$object->getNomUrl($getnomurlparam); |
|
| 6211 | + $value = $object->getNomUrl($getnomurlparam); |
|
| 6212 | 6212 | } |
| 6213 | 6213 | } |
| 6214 | 6214 | else |
@@ -6217,15 +6217,15 @@ discard block |
||
| 6217 | 6217 | return 'Error bad setup of extrafield'; |
| 6218 | 6218 | } |
| 6219 | 6219 | } |
| 6220 | - else $value=''; |
|
| 6220 | + else $value = ''; |
|
| 6221 | 6221 | } |
| 6222 | 6222 | elseif ($type == 'text' || $type == 'html') |
| 6223 | 6223 | {
|
| 6224 | - $value=dol_htmlentitiesbr($value); |
|
| 6224 | + $value = dol_htmlentitiesbr($value); |
|
| 6225 | 6225 | } |
| 6226 | 6226 | elseif ($type == 'password') |
| 6227 | 6227 | {
|
| 6228 | - $value=preg_replace('/./i','*',$value);
|
|
| 6228 | + $value = preg_replace('/./i', '*', $value);
|
|
| 6229 | 6229 | } |
| 6230 | 6230 | elseif ($type == 'array') |
| 6231 | 6231 | {
|
@@ -6233,7 +6233,7 @@ discard block |
||
| 6233 | 6233 | } |
| 6234 | 6234 | |
| 6235 | 6235 | //print $type.'-'.$size; |
| 6236 | - $out=$value; |
|
| 6236 | + $out = $value; |
|
| 6237 | 6237 | |
| 6238 | 6238 | return $out; |
| 6239 | 6239 | } |
@@ -6250,11 +6250,11 @@ discard block |
||
| 6250 | 6250 | * @param string $onetrtd All fields in same tr td |
| 6251 | 6251 | * @return string |
| 6252 | 6252 | */ |
| 6253 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
| 6253 | + function showOptionals($extrafields, $mode = 'view', $params = null, $keysuffix = '', $keyprefix = '', $onetrtd = 0) |
|
| 6254 | 6254 | {
|
| 6255 | 6255 | global $db, $conf, $langs, $action, $form; |
| 6256 | 6256 | |
| 6257 | - if (! is_object($form)) $form=new Form($db); |
|
| 6257 | + if (!is_object($form)) $form = new Form($db); |
|
| 6258 | 6258 | |
| 6259 | 6259 | $out = ''; |
| 6260 | 6260 | |
@@ -6265,10 +6265,10 @@ discard block |
||
| 6265 | 6265 | $out .= "\n"; |
| 6266 | 6266 | |
| 6267 | 6267 | $e = 0; |
| 6268 | - foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6268 | + foreach ($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6269 | 6269 | {
|
| 6270 | 6270 | // Show only the key field in params |
| 6271 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 6271 | + if (is_array($params) && array_key_exists('onlykey', $params) && $key != $params['onlykey']) continue;
|
|
| 6272 | 6272 | |
| 6273 | 6273 | $enabled = 1; |
| 6274 | 6274 | if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
@@ -6282,25 +6282,25 @@ discard block |
||
| 6282 | 6282 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
| 6283 | 6283 | } |
| 6284 | 6284 | |
| 6285 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6285 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6286 | 6286 | if (empty($perms)) continue; |
| 6287 | 6287 | |
| 6288 | 6288 | // Load language if required |
| 6289 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6289 | + if (!empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6290 | 6290 | |
| 6291 | - $colspan='3'; |
|
| 6292 | - if (is_array($params) && count($params)>0) {
|
|
| 6293 | - if (array_key_exists('colspan',$params)) {
|
|
| 6294 | - $colspan=$params['colspan']; |
|
| 6291 | + $colspan = '3'; |
|
| 6292 | + if (is_array($params) && count($params) > 0) {
|
|
| 6293 | + if (array_key_exists('colspan', $params)) {
|
|
| 6294 | + $colspan = $params['colspan']; |
|
| 6295 | 6295 | } |
| 6296 | 6296 | } |
| 6297 | 6297 | |
| 6298 | - switch($mode) {
|
|
| 6298 | + switch ($mode) {
|
|
| 6299 | 6299 | case "view": |
| 6300 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 6300 | + $value = $this->array_options["options_".$key.$keysuffix]; |
|
| 6301 | 6301 | break; |
| 6302 | 6302 | case "edit": |
| 6303 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6303 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6304 | 6304 | // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
|
| 6305 | 6305 | if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
| 6306 | 6306 | {
|
@@ -6311,7 +6311,7 @@ discard block |
||
| 6311 | 6311 | $value = $getposttemp; |
| 6312 | 6312 | } |
| 6313 | 6313 | } else {
|
| 6314 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6314 | + $value = $this->array_options["options_".$key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6315 | 6315 | } |
| 6316 | 6316 | //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
| 6317 | 6317 | break; |
@@ -6323,11 +6323,11 @@ discard block |
||
| 6323 | 6323 | } |
| 6324 | 6324 | else |
| 6325 | 6325 | {
|
| 6326 | - $csstyle=''; |
|
| 6327 | - $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6328 | - if (is_array($params) && count($params)>0) {
|
|
| 6329 | - if (array_key_exists('style',$params)) {
|
|
| 6330 | - $csstyle=$params['style']; |
|
| 6326 | + $csstyle = ''; |
|
| 6327 | + $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6328 | + if (is_array($params) && count($params) > 0) {
|
|
| 6329 | + if (array_key_exists('style', $params)) {
|
|
| 6330 | + $csstyle = $params['style']; |
|
| 6331 | 6331 | } |
| 6332 | 6332 | } |
| 6333 | 6333 | |
@@ -6340,43 +6340,43 @@ discard block |
||
| 6340 | 6340 | |
| 6341 | 6341 | $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
| 6342 | 6342 | |
| 6343 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 6343 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) |
|
| 6344 | 6344 | {
|
| 6345 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan='0'; }
|
|
| 6345 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) { $colspan = '0'; }
|
|
| 6346 | 6346 | } |
| 6347 | 6347 | |
| 6348 | 6348 | if ($action == 'selectlines') { $colspan++; }
|
| 6349 | 6349 | |
| 6350 | 6350 | // Convert date into timestamp format (value in memory must be a timestamp) |
| 6351 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
|
| 6351 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime')))
|
|
| 6352 | 6352 | {
|
| 6353 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
| 6354 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6353 | + $datenotinstring = $this->array_options['options_'.$key]; |
|
| 6354 | + if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility |
|
| 6355 | 6355 | {
|
| 6356 | 6356 | $datenotinstring = $this->db->jdate($datenotinstring); |
| 6357 | 6357 | } |
| 6358 | - $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)):$datenotinstring; |
|
| 6358 | + $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)) : $datenotinstring; |
|
| 6359 | 6359 | } |
| 6360 | 6360 | // Convert float submited string into real php numeric (value in memory must be a php numeric) |
| 6361 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double')))
|
|
| 6361 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double')))
|
|
| 6362 | 6362 | {
|
| 6363 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
| 6363 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix) ?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)) : $this->array_options['options_'.$key]; |
|
| 6364 | 6364 | } |
| 6365 | 6365 | |
| 6366 | 6366 | $labeltoshow = $langs->trans($label); |
| 6367 | 6367 | |
| 6368 | 6368 | $out .= '<td class="titlefield'; |
| 6369 | - if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6370 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6369 | + if (GETPOST('action', 'none') == 'create') $out .= 'create';
|
|
| 6370 | + if ($mode != 'view' && !empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6371 | 6371 | $out .= '">'; |
| 6372 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6372 | + if (!empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6373 | 6373 | else $out .= $labeltoshow; |
| 6374 | 6374 | $out .= '</td>'; |
| 6375 | 6375 | |
| 6376 | 6376 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
| 6377 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 6377 | + $out .= '<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan ? ' colspan="'.$colspan.'"' : '').'>'; |
|
| 6378 | 6378 | |
| 6379 | - switch($mode) {
|
|
| 6379 | + switch ($mode) {
|
|
| 6380 | 6380 | case "view": |
| 6381 | 6381 | $out .= $extrafields->showOutputField($key, $value); |
| 6382 | 6382 | break; |
@@ -6387,14 +6387,14 @@ discard block |
||
| 6387 | 6387 | |
| 6388 | 6388 | $out .= '</td>'; |
| 6389 | 6389 | |
| 6390 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6390 | + if (!empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6391 | 6391 | else $out .= '</tr>'; |
| 6392 | 6392 | $e++; |
| 6393 | 6393 | } |
| 6394 | 6394 | } |
| 6395 | 6395 | $out .= "\n"; |
| 6396 | 6396 | // Add code to manage list depending on others |
| 6397 | - if (! empty($conf->use_javascript_ajax)) {
|
|
| 6397 | + if (!empty($conf->use_javascript_ajax)) {
|
|
| 6398 | 6398 | $out .= ' |
| 6399 | 6399 | <script type="text/javascript"> |
| 6400 | 6400 | jQuery(document).ready(function() {
|
@@ -6440,7 +6440,7 @@ discard block |
||
| 6440 | 6440 | global $user; |
| 6441 | 6441 | |
| 6442 | 6442 | $element = $this->element; |
| 6443 | - if ($element == 'facturerec') $element='facture'; |
|
| 6443 | + if ($element == 'facturerec') $element = 'facture'; |
|
| 6444 | 6444 | |
| 6445 | 6445 | return $user->rights->{$element};
|
| 6446 | 6446 | } |
@@ -6457,15 +6457,15 @@ discard block |
||
| 6457 | 6457 | * @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) |
| 6458 | 6458 | * @return bool True if success, False if error |
| 6459 | 6459 | */ |
| 6460 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6460 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) |
|
| 6461 | 6461 | {
|
| 6462 | 6462 | foreach ($tables as $table) |
| 6463 | 6463 | {
|
| 6464 | 6464 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
| 6465 | 6465 | |
| 6466 | - if (! $db->query($sql)) |
|
| 6466 | + if (!$db->query($sql)) |
|
| 6467 | 6467 | {
|
| 6468 | - 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. |
|
| 6468 | + 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. |
|
| 6469 | 6469 | //$this->errors = $db->lasterror(); |
| 6470 | 6470 | return false; |
| 6471 | 6471 | } |
@@ -6499,7 +6499,7 @@ discard block |
||
| 6499 | 6499 | else |
| 6500 | 6500 | {
|
| 6501 | 6501 | // Get cost price for margin calculation |
| 6502 | - if (! empty($fk_product)) |
|
| 6502 | + if (!empty($fk_product)) |
|
| 6503 | 6503 | {
|
| 6504 | 6504 | if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'costprice') |
| 6505 | 6505 | {
|
@@ -6536,7 +6536,7 @@ discard block |
||
| 6536 | 6536 | } |
| 6537 | 6537 | } |
| 6538 | 6538 | |
| 6539 | - if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice')))
|
|
| 6539 | + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice')))
|
|
| 6540 | 6540 | {
|
| 6541 | 6541 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
| 6542 | 6542 | $productFournisseur = new ProductFournisseur($this->db); |
@@ -6573,18 +6573,18 @@ discard block |
||
| 6573 | 6573 | * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
| 6574 | 6574 | * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
| 6575 | 6575 | */ |
| 6576 | - function show_photos($modulepart, $sdir, $size=0, $nbmax=0, $nbbyrow=5, $showfilename=0, $showaction=0, $maxHeight=120, $maxWidth=160, $nolink=0, $notitle=0, $usesharelink=0) |
|
| 6576 | + function show_photos($modulepart, $sdir, $size = 0, $nbmax = 0, $nbbyrow = 5, $showfilename = 0, $showaction = 0, $maxHeight = 120, $maxWidth = 160, $nolink = 0, $notitle = 0, $usesharelink = 0) |
|
| 6577 | 6577 | {
|
| 6578 | 6578 | // phpcs:enable |
| 6579 | - global $conf,$user,$langs; |
|
| 6579 | + global $conf, $user, $langs; |
|
| 6580 | 6580 | |
| 6581 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
| 6582 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
| 6581 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 6582 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; |
|
| 6583 | 6583 | |
| 6584 | - $sortfield='position_name'; |
|
| 6585 | - $sortorder='asc'; |
|
| 6584 | + $sortfield = 'position_name'; |
|
| 6585 | + $sortorder = 'asc'; |
|
| 6586 | 6586 | |
| 6587 | - $dir = $sdir . '/'; |
|
| 6587 | + $dir = $sdir.'/'; |
|
| 6588 | 6588 | $pdir = '/'; |
| 6589 | 6589 | if ($modulepart == 'ticket') |
| 6590 | 6590 | {
|
@@ -6598,28 +6598,28 @@ discard block |
||
| 6598 | 6598 | } |
| 6599 | 6599 | |
| 6600 | 6600 | // For backward compatibility |
| 6601 | - if ($modulepart == 'product' && ! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
| 6601 | + if ($modulepart == 'product' && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) |
|
| 6602 | 6602 | {
|
| 6603 | - $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6604 | - $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6603 | + $dir = $sdir.'/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
| 6604 | + $pdir = '/'.get_exdir($this->id, 2, 0, 0, $this, $modulepart).$this->id."/photos/"; |
|
| 6605 | 6605 | } |
| 6606 | 6606 | |
| 6607 | 6607 | // Defined relative dir to DOL_DATA_ROOT |
| 6608 | 6608 | $relativedir = ''; |
| 6609 | 6609 | if ($dir) |
| 6610 | 6610 | {
|
| 6611 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
|
| 6612 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir);
|
|
| 6613 | - $relativedir = preg_replace('/[\\/]$/','',$relativedir);
|
|
| 6611 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $dir);
|
|
| 6612 | + $relativedir = preg_replace('/^[\\/]/', '', $relativedir);
|
|
| 6613 | + $relativedir = preg_replace('/[\\/]$/', '', $relativedir);
|
|
| 6614 | 6614 | } |
| 6615 | 6615 | |
| 6616 | 6616 | $dirthumb = $dir.'thumbs/'; |
| 6617 | 6617 | $pdirthumb = $pdir.'thumbs/'; |
| 6618 | 6618 | |
| 6619 | - $return ='<!-- Photo -->'."\n"; |
|
| 6620 | - $nbphoto=0; |
|
| 6619 | + $return = '<!-- Photo -->'."\n"; |
|
| 6620 | + $nbphoto = 0; |
|
| 6621 | 6621 | |
| 6622 | - $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6622 | + $filearray = dol_dir_list($dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); |
|
| 6623 | 6623 | |
| 6624 | 6624 | /*if (! empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
| 6625 | 6625 | {
|
@@ -6633,12 +6633,12 @@ discard block |
||
| 6633 | 6633 | {
|
| 6634 | 6634 | if ($sortfield && $sortorder) |
| 6635 | 6635 | {
|
| 6636 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6636 | + $filearray = dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6637 | 6637 | } |
| 6638 | 6638 | |
| 6639 | - foreach($filearray as $key => $val) |
|
| 6639 | + foreach ($filearray as $key => $val) |
|
| 6640 | 6640 | {
|
| 6641 | - $photo=''; |
|
| 6641 | + $photo = ''; |
|
| 6642 | 6642 | $file = $val['name']; |
| 6643 | 6643 | |
| 6644 | 6644 | //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
@@ -6653,36 +6653,36 @@ discard block |
||
| 6653 | 6653 | if ($size == 1 || $size == 'small') { // Format vignette
|
| 6654 | 6654 | |
| 6655 | 6655 | // Find name of thumb file |
| 6656 | - $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6657 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 6656 | + $photo_vignette = basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6657 | + if (!dol_is_file($dirthumb.$photo_vignette)) $photo_vignette = ''; |
|
| 6658 | 6658 | |
| 6659 | 6659 | // Get filesize of original file |
| 6660 | - $imgarray=dol_getImageSize($dir.$photo); |
|
| 6660 | + $imgarray = dol_getImageSize($dir.$photo); |
|
| 6661 | 6661 | |
| 6662 | 6662 | if ($nbbyrow > 0) |
| 6663 | 6663 | {
|
| 6664 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 6664 | + if ($nbphoto == 1) $return .= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 6665 | 6665 | |
| 6666 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 6667 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
| 6666 | + if ($nbphoto % $nbbyrow == 1) $return .= '<tr align=center valign=middle border=1>'; |
|
| 6667 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%" class="photo">'; |
|
| 6668 | 6668 | } |
| 6669 | 6669 | else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
| 6670 | 6670 | |
| 6671 | - $return.= "\n"; |
|
| 6671 | + $return .= "\n"; |
|
| 6672 | 6672 | |
| 6673 | - $relativefile=preg_replace('/^\//', '', $pdir.$photo);
|
|
| 6673 | + $relativefile = preg_replace('/^\//', '', $pdir.$photo);
|
|
| 6674 | 6674 | if (empty($nolink)) |
| 6675 | 6675 | {
|
| 6676 | - $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
| 6677 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6678 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 6676 | + $urladvanced = getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
| 6677 | + if ($urladvanced) $return .= '<a href="'.$urladvanced.'">'; |
|
| 6678 | + else $return .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 6679 | 6679 | } |
| 6680 | 6680 | |
| 6681 | 6681 | // Show image (width height=$maxHeight) |
| 6682 | 6682 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
| 6683 | - $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
| 6684 | - $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
| 6685 | - if ($notitle) $alt=''; |
|
| 6683 | + $alt = $langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
| 6684 | + $alt .= ' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
| 6685 | + if ($notitle) $alt = ''; |
|
| 6686 | 6686 | |
| 6687 | 6687 | if ($usesharelink) |
| 6688 | 6688 | {
|
@@ -6690,81 +6690,81 @@ discard block |
||
| 6690 | 6690 | {
|
| 6691 | 6691 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6692 | 6692 | {
|
| 6693 | - $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6694 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6693 | + $return .= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6694 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6695 | 6695 | } |
| 6696 | 6696 | else {
|
| 6697 | - $return.= '<!-- Show original file -->'; |
|
| 6698 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6697 | + $return .= '<!-- Show original file -->'; |
|
| 6698 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6699 | 6699 | } |
| 6700 | 6700 | } |
| 6701 | 6701 | else |
| 6702 | 6702 | {
|
| 6703 | - $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6704 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6703 | + $return .= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6704 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6705 | 6705 | } |
| 6706 | 6706 | } |
| 6707 | 6707 | else |
| 6708 | 6708 | {
|
| 6709 | 6709 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6710 | 6710 | {
|
| 6711 | - $return.= '<!-- Show thumb -->'; |
|
| 6712 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6711 | + $return .= '<!-- Show thumb -->'; |
|
| 6712 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6713 | 6713 | } |
| 6714 | 6714 | else {
|
| 6715 | - $return.= '<!-- Show original file -->'; |
|
| 6716 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6715 | + $return .= '<!-- Show original file -->'; |
|
| 6716 | + $return .= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6717 | 6717 | } |
| 6718 | 6718 | } |
| 6719 | 6719 | |
| 6720 | - if (empty($nolink)) $return.= '</a>'; |
|
| 6721 | - $return.="\n"; |
|
| 6720 | + if (empty($nolink)) $return .= '</a>'; |
|
| 6721 | + $return .= "\n"; |
|
| 6722 | 6722 | |
| 6723 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6723 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
| 6724 | 6724 | if ($showaction) |
| 6725 | 6725 | {
|
| 6726 | - $return.= '<br>'; |
|
| 6726 | + $return .= '<br>'; |
|
| 6727 | 6727 | // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
| 6728 | 6728 | if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
| 6729 | 6729 | {
|
| 6730 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>';
|
|
| 6730 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'), 'refresh').' </a>';
|
|
| 6731 | 6731 | } |
| 6732 | 6732 | // Special cas for product |
| 6733 | 6733 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
| 6734 | 6734 | {
|
| 6735 | 6735 | // Link to resize |
| 6736 | - $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6736 | + $return .= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6737 | 6737 | |
| 6738 | 6738 | // Link to delete |
| 6739 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6740 | - $return.= img_delete().'</a>'; |
|
| 6739 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6740 | + $return .= img_delete().'</a>'; |
|
| 6741 | 6741 | } |
| 6742 | 6742 | } |
| 6743 | - $return.= "\n"; |
|
| 6743 | + $return .= "\n"; |
|
| 6744 | 6744 | |
| 6745 | 6745 | if ($nbbyrow > 0) |
| 6746 | 6746 | {
|
| 6747 | - $return.= '</td>'; |
|
| 6748 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6747 | + $return .= '</td>'; |
|
| 6748 | + if (($nbphoto % $nbbyrow) == 0) $return .= '</tr>'; |
|
| 6749 | 6749 | } |
| 6750 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6750 | + else if ($nbbyrow < 0) $return .= '</div>'; |
|
| 6751 | 6751 | } |
| 6752 | 6752 | |
| 6753 | 6753 | if (empty($size)) { // Format origine
|
| 6754 | - $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6754 | + $return .= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6755 | 6755 | |
| 6756 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6756 | + if ($showfilename) $return .= '<br>'.$viewfilename; |
|
| 6757 | 6757 | if ($showaction) |
| 6758 | 6758 | {
|
| 6759 | 6759 | // Special case for product |
| 6760 | 6760 | if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
| 6761 | 6761 | {
|
| 6762 | 6762 | // Link to resize |
| 6763 | - $return.= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6763 | + $return .= '<a href="'.DOL_URL_ROOT.'/core/photos_resize.php?modulepart='.urlencode('produit|service').'&id='.$this->id.'&file='.urlencode($pdir.$viewfilename).'" title="'.dol_escape_htmltag($langs->trans("Resize")).'">'.img_picto($langs->trans("Resize"), 'resize', '').'</a> ';
|
|
| 6764 | 6764 | |
| 6765 | 6765 | // Link to delete |
| 6766 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6767 | - $return.= img_delete().'</a>'; |
|
| 6766 | + $return .= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6767 | + $return .= img_delete().'</a>'; |
|
| 6768 | 6768 | } |
| 6769 | 6769 | } |
| 6770 | 6770 | } |
@@ -6774,18 +6774,18 @@ discard block |
||
| 6774 | 6774 | } |
| 6775 | 6775 | } |
| 6776 | 6776 | |
| 6777 | - if ($size==1 || $size=='small') |
|
| 6777 | + if ($size == 1 || $size == 'small') |
|
| 6778 | 6778 | {
|
| 6779 | 6779 | if ($nbbyrow > 0) |
| 6780 | 6780 | {
|
| 6781 | 6781 | // Ferme tableau |
| 6782 | 6782 | while ($nbphoto % $nbbyrow) |
| 6783 | 6783 | {
|
| 6784 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
| 6784 | + $return .= '<td width="'.ceil(100 / $nbbyrow).'%"> </td>'; |
|
| 6785 | 6785 | $nbphoto++; |
| 6786 | 6786 | } |
| 6787 | 6787 | |
| 6788 | - if ($nbphoto) $return.= '</table>'; |
|
| 6788 | + if ($nbphoto) $return .= '</table>'; |
|
| 6789 | 6789 | } |
| 6790 | 6790 | } |
| 6791 | 6791 | } |
@@ -6804,9 +6804,9 @@ discard block |
||
| 6804 | 6804 | */ |
| 6805 | 6805 | protected function isArray($info) |
| 6806 | 6806 | {
|
| 6807 | - if(is_array($info)) |
|
| 6807 | + if (is_array($info)) |
|
| 6808 | 6808 | {
|
| 6809 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6809 | + if (isset($info['type']) && $info['type'] == 'array') return true; |
|
| 6810 | 6810 | else return false; |
| 6811 | 6811 | } |
| 6812 | 6812 | else return false; |
@@ -6820,9 +6820,9 @@ discard block |
||
| 6820 | 6820 | */ |
| 6821 | 6821 | protected function isNull($info) |
| 6822 | 6822 | {
|
| 6823 | - if(is_array($info)) |
|
| 6823 | + if (is_array($info)) |
|
| 6824 | 6824 | {
|
| 6825 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6825 | + if (isset($info['type']) && $info['type'] == 'null') return true; |
|
| 6826 | 6826 | else return false; |
| 6827 | 6827 | } |
| 6828 | 6828 | else return false; |
@@ -6836,7 +6836,7 @@ discard block |
||
| 6836 | 6836 | */ |
| 6837 | 6837 | public function isDate($info) |
| 6838 | 6838 | {
|
| 6839 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6839 | + if (isset($info['type']) && ($info['type'] == 'date' || $info['type'] == 'datetime' || $info['type'] == 'timestamp')) return true; |
|
| 6840 | 6840 | else return false; |
| 6841 | 6841 | } |
| 6842 | 6842 | |
@@ -6848,9 +6848,9 @@ discard block |
||
| 6848 | 6848 | */ |
| 6849 | 6849 | public function isInt($info) |
| 6850 | 6850 | {
|
| 6851 | - if(is_array($info)) |
|
| 6851 | + if (is_array($info)) |
|
| 6852 | 6852 | {
|
| 6853 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6853 | + if (isset($info['type']) && ($info['type'] == 'int' || preg_match('/^integer/i', $info['type']))) return true;
|
|
| 6854 | 6854 | else return false; |
| 6855 | 6855 | } |
| 6856 | 6856 | else return false; |
@@ -6864,7 +6864,7 @@ discard block |
||
| 6864 | 6864 | */ |
| 6865 | 6865 | public function isFloat($info) |
| 6866 | 6866 | {
|
| 6867 | - if(is_array($info)) |
|
| 6867 | + if (is_array($info)) |
|
| 6868 | 6868 | {
|
| 6869 | 6869 | if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
| 6870 | 6870 | else return false; |
@@ -6880,9 +6880,9 @@ discard block |
||
| 6880 | 6880 | */ |
| 6881 | 6881 | public function isText($info) |
| 6882 | 6882 | {
|
| 6883 | - if(is_array($info)) |
|
| 6883 | + if (is_array($info)) |
|
| 6884 | 6884 | {
|
| 6885 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6885 | + if (isset($info['type']) && $info['type'] == 'text') return true; |
|
| 6886 | 6886 | else return false; |
| 6887 | 6887 | } |
| 6888 | 6888 | else return false; |
@@ -6896,9 +6896,9 @@ discard block |
||
| 6896 | 6896 | */ |
| 6897 | 6897 | protected function isIndex($info) |
| 6898 | 6898 | {
|
| 6899 | - if(is_array($info)) |
|
| 6899 | + if (is_array($info)) |
|
| 6900 | 6900 | {
|
| 6901 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6901 | + if (isset($info['index']) && $info['index'] == true) return true; |
|
| 6902 | 6902 | else return false; |
| 6903 | 6903 | } |
| 6904 | 6904 | else return false; |
@@ -6914,13 +6914,13 @@ discard block |
||
| 6914 | 6914 | {
|
| 6915 | 6915 | global $conf; |
| 6916 | 6916 | |
| 6917 | - $queryarray=array(); |
|
| 6917 | + $queryarray = array(); |
|
| 6918 | 6918 | foreach ($this->fields as $field=>$info) // Loop on definition of fields |
| 6919 | 6919 | {
|
| 6920 | 6920 | // Depending on field type ('datetime', ...)
|
| 6921 | - if($this->isDate($info)) |
|
| 6921 | + if ($this->isDate($info)) |
|
| 6922 | 6922 | {
|
| 6923 | - if(empty($this->{$field}))
|
|
| 6923 | + if (empty($this->{$field}))
|
|
| 6924 | 6924 | {
|
| 6925 | 6925 | $queryarray[$field] = null; |
| 6926 | 6926 | } |
@@ -6929,10 +6929,10 @@ discard block |
||
| 6929 | 6929 | $queryarray[$field] = $this->db->idate($this->{$field});
|
| 6930 | 6930 | } |
| 6931 | 6931 | } |
| 6932 | - else if($this->isArray($info)) |
|
| 6932 | + else if ($this->isArray($info)) |
|
| 6933 | 6933 | {
|
| 6934 | - if(! empty($this->{$field})) {
|
|
| 6935 | - if(! is_array($this->{$field})) {
|
|
| 6934 | + if (!empty($this->{$field})) {
|
|
| 6935 | + if (!is_array($this->{$field})) {
|
|
| 6936 | 6936 | $this->{$field} = array($this->{$field});
|
| 6937 | 6937 | } |
| 6938 | 6938 | $queryarray[$field] = serialize($this->{$field});
|
@@ -6940,19 +6940,19 @@ discard block |
||
| 6940 | 6940 | $queryarray[$field] = null; |
| 6941 | 6941 | } |
| 6942 | 6942 | } |
| 6943 | - else if($this->isInt($info)) |
|
| 6943 | + else if ($this->isInt($info)) |
|
| 6944 | 6944 | {
|
| 6945 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity;
|
|
| 6945 | + if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field] = $conf->entity;
|
|
| 6946 | 6946 | else |
| 6947 | 6947 | {
|
| 6948 | 6948 | $queryarray[$field] = (int) price2num($this->{$field});
|
| 6949 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6949 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6950 | 6950 | } |
| 6951 | 6951 | } |
| 6952 | - else if($this->isFloat($info)) |
|
| 6952 | + else if ($this->isFloat($info)) |
|
| 6953 | 6953 | {
|
| 6954 | 6954 | $queryarray[$field] = (double) price2num($this->{$field});
|
| 6955 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6955 | + if (empty($queryarray[$field])) $queryarray[$field] = 0; |
|
| 6956 | 6956 | } |
| 6957 | 6957 | else |
| 6958 | 6958 | {
|
@@ -6960,7 +6960,7 @@ discard block |
||
| 6960 | 6960 | } |
| 6961 | 6961 | |
| 6962 | 6962 | if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
| 6963 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6963 | + if (!empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6964 | 6964 | } |
| 6965 | 6965 | |
| 6966 | 6966 | return $queryarray; |
@@ -6976,35 +6976,35 @@ discard block |
||
| 6976 | 6976 | {
|
| 6977 | 6977 | foreach ($this->fields as $field => $info) |
| 6978 | 6978 | {
|
| 6979 | - if($this->isDate($info)) |
|
| 6979 | + if ($this->isDate($info)) |
|
| 6980 | 6980 | {
|
| 6981 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6981 | + if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6982 | 6982 | else $this->{$field} = strtotime($obj->{$field});
|
| 6983 | 6983 | } |
| 6984 | - elseif($this->isArray($info)) |
|
| 6984 | + elseif ($this->isArray($info)) |
|
| 6985 | 6985 | {
|
| 6986 | - if(! empty($obj->{$field})) {
|
|
| 6986 | + if (!empty($obj->{$field})) {
|
|
| 6987 | 6987 | $this->{$field} = @unserialize($obj->{$field});
|
| 6988 | 6988 | // Hack for data not in UTF8 |
| 6989 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 6989 | + if ($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 6990 | 6990 | } else {
|
| 6991 | 6991 | $this->{$field} = array();
|
| 6992 | 6992 | } |
| 6993 | 6993 | } |
| 6994 | - elseif($this->isInt($info)) |
|
| 6994 | + elseif ($this->isInt($info)) |
|
| 6995 | 6995 | {
|
| 6996 | 6996 | if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
| 6997 | 6997 | else $this->{$field} = (int) $obj->{$field};
|
| 6998 | 6998 | } |
| 6999 | - elseif($this->isFloat($info)) |
|
| 6999 | + elseif ($this->isFloat($info)) |
|
| 7000 | 7000 | {
|
| 7001 | 7001 | $this->{$field} = (double) $obj->{$field};
|
| 7002 | 7002 | } |
| 7003 | - elseif($this->isNull($info)) |
|
| 7003 | + elseif ($this->isNull($info)) |
|
| 7004 | 7004 | {
|
| 7005 | 7005 | $val = $obj->{$field};
|
| 7006 | 7006 | // zero is not null |
| 7007 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
|
| 7007 | + $this->{$field} = (is_null($val) || (empty($val) && $val !== 0 && $val !== '0') ? null : $val);
|
|
| 7008 | 7008 | } |
| 7009 | 7009 | else |
| 7010 | 7010 | {
|
@@ -7013,7 +7013,7 @@ discard block |
||
| 7013 | 7013 | } |
| 7014 | 7014 | |
| 7015 | 7015 | // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
| 7016 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7016 | + if (!isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7017 | 7017 | } |
| 7018 | 7018 | |
| 7019 | 7019 | /** |
@@ -7055,14 +7055,14 @@ discard block |
||
| 7055 | 7055 | |
| 7056 | 7056 | $error = 0; |
| 7057 | 7057 | |
| 7058 | - $now=dol_now(); |
|
| 7058 | + $now = dol_now(); |
|
| 7059 | 7059 | |
| 7060 | 7060 | $fieldvalues = $this->setSaveQuery(); |
| 7061 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7062 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7063 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 7061 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation'] = $this->db->idate($now);
|
|
| 7062 | + if (array_key_exists('fk_user_creat', $fieldvalues) && !($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat'] = $user->id;
|
|
| 7063 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 7064 | 7064 | |
| 7065 | - $keys=array(); |
|
| 7065 | + $keys = array(); |
|
| 7066 | 7066 | $values = array(); |
| 7067 | 7067 | foreach ($fieldvalues as $k => $v) {
|
| 7068 | 7068 | $keys[$k] = $k; |
@@ -7071,58 +7071,58 @@ discard block |
||
| 7071 | 7071 | } |
| 7072 | 7072 | |
| 7073 | 7073 | // Clean and check mandatory |
| 7074 | - foreach($keys as $key) |
|
| 7074 | + foreach ($keys as $key) |
|
| 7075 | 7075 | {
|
| 7076 | 7076 | // If field is an implicit foreign key field |
| 7077 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7078 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7077 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = '';
|
|
| 7078 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; |
|
| 7079 | 7079 | |
| 7080 | 7080 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7081 | - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
| 7081 | + if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && !isset($values[$key]) && is_null($val['default'])) |
|
| 7082 | 7082 | {
|
| 7083 | 7083 | $error++; |
| 7084 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7084 | + $this->errors[] = $langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7085 | 7085 | } |
| 7086 | 7086 | |
| 7087 | 7087 | // If field is an implicit foreign key field |
| 7088 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7089 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7088 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key] = 'null';
|
|
| 7089 | + if (!empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key] = 'null'; |
|
| 7090 | 7090 | } |
| 7091 | 7091 | |
| 7092 | 7092 | if ($error) return -1; |
| 7093 | 7093 | |
| 7094 | 7094 | $this->db->begin(); |
| 7095 | 7095 | |
| 7096 | - if (! $error) |
|
| 7096 | + if (!$error) |
|
| 7097 | 7097 | {
|
| 7098 | 7098 | $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
| 7099 | - $sql.= ' ('.implode( ", ", $keys ).')';
|
|
| 7100 | - $sql.= ' VALUES ('.implode( ", ", $values ).')';
|
|
| 7099 | + $sql .= ' ('.implode(", ", $keys).')';
|
|
| 7100 | + $sql .= ' VALUES ('.implode(", ", $values).')';
|
|
| 7101 | 7101 | |
| 7102 | 7102 | $res = $this->db->query($sql); |
| 7103 | - if ($res===false) {
|
|
| 7103 | + if ($res === false) {
|
|
| 7104 | 7104 | $error++; |
| 7105 | 7105 | $this->errors[] = $this->db->lasterror(); |
| 7106 | 7106 | } |
| 7107 | 7107 | } |
| 7108 | 7108 | |
| 7109 | - if (! $error) |
|
| 7109 | + if (!$error) |
|
| 7110 | 7110 | {
|
| 7111 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 7111 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); |
|
| 7112 | 7112 | } |
| 7113 | 7113 | |
| 7114 | 7114 | // Create extrafields |
| 7115 | - if (! $error) |
|
| 7115 | + if (!$error) |
|
| 7116 | 7116 | {
|
| 7117 | - $result=$this->insertExtraFields(); |
|
| 7117 | + $result = $this->insertExtraFields(); |
|
| 7118 | 7118 | if ($result < 0) $error++; |
| 7119 | 7119 | } |
| 7120 | 7120 | |
| 7121 | 7121 | // Triggers |
| 7122 | - if (! $error && ! $notrigger) |
|
| 7122 | + if (!$error && !$notrigger) |
|
| 7123 | 7123 | {
|
| 7124 | 7124 | // Call triggers |
| 7125 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 7125 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_CREATE', $user); |
|
| 7126 | 7126 | if ($result < 0) { $error++; }
|
| 7127 | 7127 | // End call triggers |
| 7128 | 7128 | } |
@@ -7151,13 +7151,13 @@ discard block |
||
| 7151 | 7151 | if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
| 7152 | 7152 | |
| 7153 | 7153 | $sql = 'SELECT '.$this->getFieldList(); |
| 7154 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7154 | + $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7155 | 7155 | |
| 7156 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7157 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7158 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7159 | - if ($morewhere) $sql.= $morewhere; |
|
| 7160 | - $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 7156 | + if (!empty($id)) $sql .= ' WHERE rowid = '.$id; |
|
| 7157 | + elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7158 | + else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7159 | + if ($morewhere) $sql .= $morewhere; |
|
| 7160 | + $sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 7161 | 7161 | |
| 7162 | 7162 | $res = $this->db->query($sql); |
| 7163 | 7163 | if ($res) |
@@ -7194,14 +7194,14 @@ discard block |
||
| 7194 | 7194 | |
| 7195 | 7195 | $error = 0; |
| 7196 | 7196 | |
| 7197 | - $now=dol_now(); |
|
| 7197 | + $now = dol_now(); |
|
| 7198 | 7198 | |
| 7199 | 7199 | $fieldvalues = $this->setSaveQuery(); |
| 7200 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7201 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7202 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 7200 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification'] = $this->db->idate($now);
|
|
| 7201 | + if (array_key_exists('fk_user_modif', $fieldvalues) && !($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif'] = $user->id;
|
|
| 7202 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 7203 | 7203 | |
| 7204 | - $keys=array(); |
|
| 7204 | + $keys = array(); |
|
| 7205 | 7205 | $values = array(); |
| 7206 | 7206 | foreach ($fieldvalues as $k => $v) {
|
| 7207 | 7207 | $keys[$k] = $k; |
@@ -7211,10 +7211,10 @@ discard block |
||
| 7211 | 7211 | } |
| 7212 | 7212 | |
| 7213 | 7213 | // Clean and check mandatory |
| 7214 | - foreach($keys as $key) |
|
| 7214 | + foreach ($keys as $key) |
|
| 7215 | 7215 | {
|
| 7216 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7217 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7216 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key] = ''; // This is an implicit foreign key field
|
|
| 7217 | + if (!empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key] = ''; // This is an explicit foreign key field |
|
| 7218 | 7218 | |
| 7219 | 7219 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7220 | 7220 | /* |
@@ -7225,13 +7225,13 @@ discard block |
||
| 7225 | 7225 | }*/ |
| 7226 | 7226 | } |
| 7227 | 7227 | |
| 7228 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 7228 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(',', $tmp).' WHERE rowid='.$this->id;
|
|
| 7229 | 7229 | |
| 7230 | 7230 | $this->db->begin(); |
| 7231 | - if (! $error) |
|
| 7231 | + if (!$error) |
|
| 7232 | 7232 | {
|
| 7233 | 7233 | $res = $this->db->query($sql); |
| 7234 | - if ($res===false) |
|
| 7234 | + if ($res === false) |
|
| 7235 | 7235 | {
|
| 7236 | 7236 | $error++; |
| 7237 | 7237 | $this->errors[] = $this->db->lasterror(); |
@@ -7239,9 +7239,9 @@ discard block |
||
| 7239 | 7239 | } |
| 7240 | 7240 | |
| 7241 | 7241 | // Update extrafield |
| 7242 | - if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) |
|
| 7242 | + if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) |
|
| 7243 | 7243 | {
|
| 7244 | - $result=$this->insertExtraFields(); |
|
| 7244 | + $result = $this->insertExtraFields(); |
|
| 7245 | 7245 | if ($result < 0) |
| 7246 | 7246 | {
|
| 7247 | 7247 | $error++; |
@@ -7249,10 +7249,10 @@ discard block |
||
| 7249 | 7249 | } |
| 7250 | 7250 | |
| 7251 | 7251 | // Triggers |
| 7252 | - if (! $error && ! $notrigger) |
|
| 7252 | + if (!$error && !$notrigger) |
|
| 7253 | 7253 | {
|
| 7254 | 7254 | // Call triggers |
| 7255 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 7255 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); |
|
| 7256 | 7256 | if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
|
| 7257 | 7257 | // End call triggers |
| 7258 | 7258 | } |
@@ -7275,68 +7275,68 @@ discard block |
||
| 7275 | 7275 | * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
| 7276 | 7276 | * @return int <=0 if KO, >0 if OK |
| 7277 | 7277 | */ |
| 7278 | - public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
| 7278 | + public function deleteCommon(User $user, $notrigger = false, $forcechilddeletion = 0) |
|
| 7279 | 7279 | {
|
| 7280 | - $error=0; |
|
| 7280 | + $error = 0; |
|
| 7281 | 7281 | |
| 7282 | 7282 | $this->db->begin(); |
| 7283 | 7283 | |
| 7284 | 7284 | if ($forcechilddeletion) |
| 7285 | 7285 | {
|
| 7286 | - foreach($this->childtables as $table) |
|
| 7286 | + foreach ($this->childtables as $table) |
|
| 7287 | 7287 | {
|
| 7288 | 7288 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
| 7289 | 7289 | $resql = $this->db->query($sql); |
| 7290 | - if (! $resql) |
|
| 7290 | + if (!$resql) |
|
| 7291 | 7291 | {
|
| 7292 | - $this->error=$this->db->lasterror(); |
|
| 7293 | - $this->errors[]=$this->error; |
|
| 7292 | + $this->error = $this->db->lasterror(); |
|
| 7293 | + $this->errors[] = $this->error; |
|
| 7294 | 7294 | $this->db->rollback(); |
| 7295 | 7295 | return -1; |
| 7296 | 7296 | } |
| 7297 | 7297 | } |
| 7298 | 7298 | } |
| 7299 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7299 | + elseif (!empty($this->fk_element) && !empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7300 | 7300 | {
|
| 7301 | 7301 | $objectisused = $this->isObjectUsed($this->id); |
| 7302 | - if (! empty($objectisused)) |
|
| 7302 | + if (!empty($objectisused)) |
|
| 7303 | 7303 | {
|
| 7304 | 7304 | dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
| 7305 | - $this->error='ErrorRecordHasChildren'; |
|
| 7306 | - $this->errors[]=$this->error; |
|
| 7305 | + $this->error = 'ErrorRecordHasChildren'; |
|
| 7306 | + $this->errors[] = $this->error; |
|
| 7307 | 7307 | $this->db->rollback(); |
| 7308 | 7308 | return 0; |
| 7309 | 7309 | } |
| 7310 | 7310 | } |
| 7311 | 7311 | |
| 7312 | - if (! $error) {
|
|
| 7313 | - if (! $notrigger) {
|
|
| 7312 | + if (!$error) {
|
|
| 7313 | + if (!$notrigger) {
|
|
| 7314 | 7314 | // Call triggers |
| 7315 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7315 | + $result = $this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7316 | 7316 | if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
|
| 7317 | 7317 | // End call triggers |
| 7318 | 7318 | } |
| 7319 | 7319 | } |
| 7320 | 7320 | |
| 7321 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 7321 | + if (!$error && !empty($this->isextrafieldmanaged)) |
|
| 7322 | 7322 | {
|
| 7323 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 7324 | - $sql.= " WHERE fk_object=" . $this->id; |
|
| 7323 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; |
|
| 7324 | + $sql .= " WHERE fk_object=".$this->id; |
|
| 7325 | 7325 | |
| 7326 | 7326 | $resql = $this->db->query($sql); |
| 7327 | - if (! $resql) |
|
| 7327 | + if (!$resql) |
|
| 7328 | 7328 | {
|
| 7329 | 7329 | $this->errors[] = $this->db->lasterror(); |
| 7330 | 7330 | $error++; |
| 7331 | 7331 | } |
| 7332 | 7332 | } |
| 7333 | 7333 | |
| 7334 | - if (! $error) |
|
| 7334 | + if (!$error) |
|
| 7335 | 7335 | {
|
| 7336 | 7336 | $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
| 7337 | 7337 | |
| 7338 | 7338 | $res = $this->db->query($sql); |
| 7339 | - if($res===false) {
|
|
| 7339 | + if ($res === false) {
|
|
| 7340 | 7340 | $error++; |
| 7341 | 7341 | $this->errors[] = $this->db->lasterror(); |
| 7342 | 7342 | } |
@@ -7377,9 +7377,9 @@ discard block |
||
| 7377 | 7377 | require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
| 7378 | 7378 | |
| 7379 | 7379 | $comment = new Comment($this->db); |
| 7380 | - $result=$comment->fetchAllFor($this->element, $this->id); |
|
| 7381 | - if ($result<0) {
|
|
| 7382 | - $this->errors=array_merge($this->errors, $comment->errors); |
|
| 7380 | + $result = $comment->fetchAllFor($this->element, $this->id); |
|
| 7381 | + if ($result < 0) {
|
|
| 7382 | + $this->errors = array_merge($this->errors, $comment->errors); |
|
| 7383 | 7383 | return -1; |
| 7384 | 7384 | } else {
|
| 7385 | 7385 | $this->comments = $comment->comments; |
@@ -400,23 +400,31 @@ discard block |
||
| 400 | 400 | $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
| 401 | 401 | $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
| 402 | 402 | |
| 403 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 404 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 405 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 406 | - else {
|
|
| 403 | + if ($id > 0) { |
|
| 404 | + $sql.= " AND rowid = ".$db->escape($id); |
|
| 405 | + } else if ($ref) { |
|
| 406 | + $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 407 | + } else if ($ref_ext) { |
|
| 408 | + $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 409 | + } else {
|
|
| 407 | 410 | $error='ErrorWrongParameters'; |
| 408 | 411 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
| 409 | 412 | return -1; |
| 410 | 413 | } |
| 411 | - if ($ref || $ref_ext) $sql.= " AND entity = ".$conf->entity; |
|
| 414 | + if ($ref || $ref_ext) { |
|
| 415 | + $sql.= " AND entity = ".$conf->entity; |
|
| 416 | + } |
|
| 412 | 417 | |
| 413 | 418 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
| 414 | 419 | $resql = $db->query($sql); |
| 415 | 420 | if ($resql) |
| 416 | 421 | {
|
| 417 | 422 | $num=$db->num_rows($resql); |
| 418 | - if ($num > 0) return 1; |
|
| 419 | - else return 0; |
|
| 423 | + if ($num > 0) { |
|
| 424 | + return 1; |
|
| 425 | + } else { |
|
| 426 | + return 0; |
|
| 427 | + } |
|
| 420 | 428 | } |
| 421 | 429 | return -1; |
| 422 | 430 | } |
@@ -445,13 +453,18 @@ discard block |
||
| 445 | 453 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
| 446 | 454 | $lastname=$this->lastname; |
| 447 | 455 | $firstname=$this->firstname; |
| 448 | - 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:''))))); |
|
| 456 | + if (empty($lastname)) { |
|
| 457 | + $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:''))))); |
|
| 458 | + } |
|
| 449 | 459 | |
| 450 | 460 | $ret=''; |
| 451 | 461 | if ($option && $this->civility_id) |
| 452 | 462 | {
|
| 453 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 454 | - else $ret.=$this->civility_id.' '; |
|
| 463 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) { |
|
| 464 | + $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
| 465 | + } else { |
|
| 466 | + $ret.=$this->civility_id.' '; |
|
| 467 | + } |
|
| 455 | 468 | } |
| 456 | 469 | |
| 457 | 470 | $ret.=dolGetFirstLastname($firstname, $lastname, $nameorder); |
@@ -544,14 +557,15 @@ discard block |
||
| 544 | 557 | {
|
| 545 | 558 | if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
|
| 546 | 559 | $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
| 547 | - } |
|
| 548 | - else {
|
|
| 560 | + } else {
|
|
| 549 | 561 | $out.=($outdone?' - ':'').$this->state; |
| 550 | 562 | } |
| 551 | 563 | $outdone++; |
| 552 | 564 | } |
| 553 | 565 | |
| 554 | - 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>':''); |
|
| 566 | + 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)) { |
|
| 567 | + $out.=($outdone?'<br>':''); |
|
| 568 | + } |
|
| 555 | 569 | if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
|
| 556 | 570 | $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
| 557 | 571 | } |
@@ -592,13 +606,21 @@ discard block |
||
| 592 | 606 | $out.='<div style="clear: both;">'; |
| 593 | 607 | if (! empty($conf->socialnetworks->enabled)) |
| 594 | 608 | {
|
| 595 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 609 | + if ($this->skype) { |
|
| 610 | + $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 611 | + } |
|
| 596 | 612 | $outdone++; |
| 597 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 613 | + if ($this->jabberid) { |
|
| 614 | + $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 615 | + } |
|
| 598 | 616 | $outdone++; |
| 599 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 617 | + if ($this->twitter) { |
|
| 618 | + $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 619 | + } |
|
| 600 | 620 | $outdone++; |
| 601 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 621 | + if ($this->facebook) { |
|
| 622 | + $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 623 | + } |
|
| 602 | 624 | $outdone++; |
| 603 | 625 | } |
| 604 | 626 | $out.='</div>'; |
@@ -658,10 +680,10 @@ discard block |
||
| 658 | 680 | $this->errors = $ecmfile->errors; |
| 659 | 681 | } |
| 660 | 682 | */ |
| 661 | - } |
|
| 662 | - else return ''; |
|
| 663 | - } |
|
| 664 | - elseif (empty($ecmfile->share)) |
|
| 683 | + } else { |
|
| 684 | + return ''; |
|
| 685 | + } |
|
| 686 | + } elseif (empty($ecmfile->share)) |
|
| 665 | 687 | {
|
| 666 | 688 | // Add entry into index |
| 667 | 689 | if ($initsharekey) |
@@ -669,8 +691,9 @@ discard block |
||
| 669 | 691 | require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
| 670 | 692 | $ecmfile->share = getRandomPassword(true); |
| 671 | 693 | $ecmfile->update($user); |
| 672 | - } |
|
| 673 | - else return ''; |
|
| 694 | + } else { |
|
| 695 | + return ''; |
|
| 696 | + } |
|
| 674 | 697 | } |
| 675 | 698 | |
| 676 | 699 | // Define $urlwithroot |
@@ -684,14 +707,18 @@ discard block |
||
| 684 | 707 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
| 685 | 708 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
| 686 | 709 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
| 687 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 688 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 710 | + if (! empty($ecmfile->share)) { |
|
| 711 | + $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; |
|
| 712 | + } |
|
| 713 | + // Hash for public share |
|
| 714 | + if ($forcedownload) { |
|
| 715 | + $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 716 | + } |
|
| 689 | 717 | |
| 690 | 718 | if ($relativelink) |
| 691 | 719 | {
|
| 692 | 720 | $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
| 693 | - } |
|
| 694 | - else |
|
| 721 | + } else |
|
| 695 | 722 | {
|
| 696 | 723 | $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
| 697 | 724 | } |
@@ -739,8 +766,7 @@ discard block |
||
| 739 | 766 | if (is_numeric($type_contact)) |
| 740 | 767 | {
|
| 741 | 768 | $id_type_contact=$type_contact; |
| 742 | - } |
|
| 743 | - else |
|
| 769 | + } else |
|
| 744 | 770 | {
|
| 745 | 771 | // We look for id type_contact |
| 746 | 772 | $sql = "SELECT tc.rowid"; |
@@ -753,7 +779,9 @@ discard block |
||
| 753 | 779 | if ($resql) |
| 754 | 780 | {
|
| 755 | 781 | $obj = $this->db->fetch_object($resql); |
| 756 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 782 | + if ($obj) { |
|
| 783 | + $id_type_contact=$obj->rowid; |
|
| 784 | + } |
|
| 757 | 785 | } |
| 758 | 786 | } |
| 759 | 787 | |
@@ -805,8 +833,7 @@ discard block |
||
| 805 | 833 | |
| 806 | 834 | $this->db->commit(); |
| 807 | 835 | return 1; |
| 808 | - } |
|
| 809 | - else |
|
| 836 | + } else |
|
| 810 | 837 | {
|
| 811 | 838 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 812 | 839 | {
|
@@ -814,15 +841,16 @@ discard block |
||
| 814 | 841 | $this->db->rollback(); |
| 815 | 842 | echo 'err rollback'; |
| 816 | 843 | return -2; |
| 817 | - } |
|
| 818 | - else |
|
| 844 | + } else |
|
| 819 | 845 | {
|
| 820 | 846 | $this->error=$this->db->error(); |
| 821 | 847 | $this->db->rollback(); |
| 822 | 848 | return -1; |
| 823 | 849 | } |
| 824 | 850 | } |
| 825 | - } else return 0; |
|
| 851 | + } else { |
|
| 852 | + return 0; |
|
| 853 | + } |
|
| 826 | 854 | } |
| 827 | 855 | |
| 828 | 856 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -864,15 +892,18 @@ discard block |
||
| 864 | 892 | // Insert into database |
| 865 | 893 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
| 866 | 894 | $sql.= " statut = ".$statut; |
| 867 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 868 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 895 | + if ($type_contact_id) { |
|
| 896 | + $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 897 | + } |
|
| 898 | + if ($fk_socpeople) { |
|
| 899 | + $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 900 | + } |
|
| 869 | 901 | $sql.= " where rowid = ".$rowid; |
| 870 | 902 | $resql=$this->db->query($sql); |
| 871 | 903 | if ($resql) |
| 872 | 904 | {
|
| 873 | 905 | return 0; |
| 874 | - } |
|
| 875 | - else |
|
| 906 | + } else |
|
| 876 | 907 | {
|
| 877 | 908 | $this->error=$this->db->lasterror(); |
| 878 | 909 | return -1; |
@@ -909,8 +940,7 @@ discard block |
||
| 909 | 940 | |
| 910 | 941 | $this->db->commit(); |
| 911 | 942 | return 1; |
| 912 | - } |
|
| 913 | - else |
|
| 943 | + } else |
|
| 914 | 944 | {
|
| 915 | 945 | $this->error=$this->db->lasterror(); |
| 916 | 946 | $this->db->rollback(); |
@@ -940,15 +970,15 @@ discard block |
||
| 940 | 970 | |
| 941 | 971 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 942 | 972 | $sql.= " WHERE element_id = ".$this->id; |
| 943 | - if ($listId) |
|
| 944 | - $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 973 | + if ($listId) { |
|
| 974 | + $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 975 | + } |
|
| 945 | 976 | |
| 946 | 977 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
| 947 | 978 | if ($this->db->query($sql)) |
| 948 | 979 | {
|
| 949 | 980 | return 1; |
| 950 | - } |
|
| 951 | - else |
|
| 981 | + } else |
|
| 952 | 982 | {
|
| 953 | 983 | $this->error=$this->db->lasterror(); |
| 954 | 984 | return -1; |
@@ -973,22 +1003,38 @@ discard block |
||
| 973 | 1003 | $tab=array(); |
| 974 | 1004 | |
| 975 | 1005 | $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 |
| 976 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 977 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 1006 | + if ($source == 'internal') { |
|
| 1007 | + $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 1008 | + } |
|
| 1009 | + if ($source == 'external' || $source == 'thirdparty') { |
|
| 1010 | + $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 1011 | + } |
|
| 978 | 1012 | $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
| 979 | 1013 | $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
| 980 | 1014 | $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
| 981 | 1015 | $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
| 982 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 983 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 1016 | + if ($source == 'internal') { |
|
| 1017 | + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 1018 | + } |
|
| 1019 | + if ($source == 'external'|| $source == 'thirdparty') { |
|
| 1020 | + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 1021 | + } |
|
| 984 | 1022 | $sql.= " WHERE ec.element_id =".$this->id; |
| 985 | 1023 | $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
| 986 | 1024 | $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
| 987 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 988 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 989 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 1025 | + if ($code) { |
|
| 1026 | + $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 1027 | + } |
|
| 1028 | + if ($source == 'internal') { |
|
| 1029 | + $sql.= " AND tc.source = 'internal'"; |
|
| 1030 | + } |
|
| 1031 | + if ($source == 'external' || $source == 'thirdparty') { |
|
| 1032 | + $sql.= " AND tc.source = 'external'"; |
|
| 1033 | + } |
|
| 990 | 1034 | $sql.= " AND tc.active=1"; |
| 991 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1035 | + if ($statut >= 0) { |
|
| 1036 | + $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1037 | + } |
|
| 992 | 1038 | $sql.=" ORDER BY t.lastname ASC"; |
| 993 | 1039 | |
| 994 | 1040 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
@@ -1009,8 +1055,7 @@ discard block |
||
| 1009 | 1055 | 'nom'=>$obj->lastname, // For backward compatibility |
| 1010 | 1056 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
| 1011 | 1057 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
| 1012 | - } |
|
| 1013 | - else |
|
| 1058 | + } else |
|
| 1014 | 1059 | {
|
| 1015 | 1060 | $tab[$i]=$obj->id; |
| 1016 | 1061 | } |
@@ -1019,8 +1064,7 @@ discard block |
||
| 1019 | 1064 | } |
| 1020 | 1065 | |
| 1021 | 1066 | return $tab; |
| 1022 | - } |
|
| 1023 | - else |
|
| 1067 | + } else |
|
| 1024 | 1068 | {
|
| 1025 | 1069 | $this->error=$this->db->lasterror(); |
| 1026 | 1070 | dol_print_error($this->db); |
@@ -1055,8 +1099,7 @@ discard block |
||
| 1055 | 1099 | $result = $this->update_contact($rowid, $newstatut); |
| 1056 | 1100 | $this->db->free($resql); |
| 1057 | 1101 | return $result; |
| 1058 | - } |
|
| 1059 | - else |
|
| 1102 | + } else |
|
| 1060 | 1103 | {
|
| 1061 | 1104 | $this->error=$this->db->error(); |
| 1062 | 1105 | dol_print_error($this->db); |
@@ -1080,16 +1123,27 @@ discard block |
||
| 1080 | 1123 | // phpcs:enable |
| 1081 | 1124 | global $langs; |
| 1082 | 1125 | |
| 1083 | - if (empty($order)) $order='position'; |
|
| 1084 | - if ($order == 'position') $order.=',code'; |
|
| 1126 | + if (empty($order)) { |
|
| 1127 | + $order='position'; |
|
| 1128 | + } |
|
| 1129 | + if ($order == 'position') { |
|
| 1130 | + $order.=',code'; |
|
| 1131 | + } |
|
| 1085 | 1132 | |
| 1086 | 1133 | $tab = array(); |
| 1087 | 1134 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
| 1088 | 1135 | $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
| 1089 | 1136 | $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
| 1090 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1091 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1092 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1137 | + if ($activeonly == 1) { |
|
| 1138 | + $sql.= " AND tc.active=1"; |
|
| 1139 | + } |
|
| 1140 | + // only the active types |
|
| 1141 | + if (! empty($source) && $source != 'all') { |
|
| 1142 | + $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1143 | + } |
|
| 1144 | + if (! empty($code)) { |
|
| 1145 | + $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1146 | + } |
|
| 1093 | 1147 | $sql.= $this->db->order($order,'ASC'); |
| 1094 | 1148 | |
| 1095 | 1149 | //print "sql=".$sql; |
@@ -1104,13 +1158,15 @@ discard block |
||
| 1104 | 1158 | |
| 1105 | 1159 | $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
| 1106 | 1160 | $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
| 1107 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1108 | - else $tab[$obj->code]=$libelle_type; |
|
| 1161 | + if (empty($option)) { |
|
| 1162 | + $tab[$obj->rowid]=$libelle_type; |
|
| 1163 | + } else { |
|
| 1164 | + $tab[$obj->code]=$libelle_type; |
|
| 1165 | + } |
|
| 1109 | 1166 | $i++; |
| 1110 | 1167 | } |
| 1111 | 1168 | return $tab; |
| 1112 | - } |
|
| 1113 | - else |
|
| 1169 | + } else |
|
| 1114 | 1170 | {
|
| 1115 | 1171 | $this->error=$this->db->lasterror(); |
| 1116 | 1172 | //dol_print_error($this->db); |
@@ -1149,19 +1205,29 @@ discard block |
||
| 1149 | 1205 | |
| 1150 | 1206 | $sql = "SELECT ec.fk_socpeople"; |
| 1151 | 1207 | $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
| 1152 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1153 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1208 | + if ($source == 'internal') { |
|
| 1209 | + $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1210 | + } |
|
| 1211 | + if ($source == 'external') { |
|
| 1212 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1213 | + } |
|
| 1154 | 1214 | $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
| 1155 | 1215 | $sql.= " WHERE ec.element_id = ".$id; |
| 1156 | 1216 | $sql.= " AND ec.fk_socpeople = c.rowid"; |
| 1157 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1158 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1217 | + if ($source == 'internal') { |
|
| 1218 | + $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
| 1219 | + } |
|
| 1220 | + if ($source == 'external') { |
|
| 1221 | + $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
| 1222 | + } |
|
| 1159 | 1223 | $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
| 1160 | 1224 | $sql.= " AND tc.element = '".$element."'"; |
| 1161 | 1225 | $sql.= " AND tc.source = '".$source."'"; |
| 1162 | 1226 | $sql.= " AND tc.code = '".$code."'"; |
| 1163 | 1227 | $sql.= " AND tc.active = 1"; |
| 1164 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1228 | + if ($status) { |
|
| 1229 | + $sql.= " AND ec.statut = ".$status; |
|
| 1230 | + } |
|
| 1165 | 1231 | |
| 1166 | 1232 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
| 1167 | 1233 | $resql=$this->db->query($sql); |
@@ -1172,8 +1238,7 @@ discard block |
||
| 1172 | 1238 | $result[$i]=$obj->fk_socpeople; |
| 1173 | 1239 | $i++; |
| 1174 | 1240 | } |
| 1175 | - } |
|
| 1176 | - else |
|
| 1241 | + } else |
|
| 1177 | 1242 | {
|
| 1178 | 1243 | $this->error=$this->db->error(); |
| 1179 | 1244 | return null; |
@@ -1192,9 +1257,13 @@ discard block |
||
| 1192 | 1257 | function fetch_contact($contactid=null) |
| 1193 | 1258 | {
|
| 1194 | 1259 | // phpcs:enable |
| 1195 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 1260 | + if (empty($contactid)) { |
|
| 1261 | + $contactid=$this->contactid; |
|
| 1262 | + } |
|
| 1196 | 1263 | |
| 1197 | - if (empty($contactid)) return 0; |
|
| 1264 | + if (empty($contactid)) { |
|
| 1265 | + return 0; |
|
| 1266 | + } |
|
| 1198 | 1267 | |
| 1199 | 1268 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
| 1200 | 1269 | $contact = new Contact($this->db); |
@@ -1215,14 +1284,16 @@ discard block |
||
| 1215 | 1284 | // phpcs:enable |
| 1216 | 1285 | global $conf; |
| 1217 | 1286 | |
| 1218 | - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1219 | - return 0; |
|
| 1287 | + if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) { |
|
| 1288 | + return 0; |
|
| 1289 | + } |
|
| 1220 | 1290 | |
| 1221 | 1291 | require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
| 1222 | 1292 | |
| 1223 | 1293 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
| 1224 | - if ($force_thirdparty_id) |
|
| 1225 | - $idtofetch = $force_thirdparty_id; |
|
| 1294 | + if ($force_thirdparty_id) { |
|
| 1295 | + $idtofetch = $force_thirdparty_id; |
|
| 1296 | + } |
|
| 1226 | 1297 | |
| 1227 | 1298 | if ($idtofetch) {
|
| 1228 | 1299 | $thirdparty = new Societe($this->db); |
@@ -1235,8 +1306,9 @@ discard block |
||
| 1235 | 1306 | } |
| 1236 | 1307 | |
| 1237 | 1308 | return $result; |
| 1238 | - } else |
|
| 1239 | - return -1; |
|
| 1309 | + } else { |
|
| 1310 | + return -1; |
|
| 1311 | + } |
|
| 1240 | 1312 | } |
| 1241 | 1313 | |
| 1242 | 1314 | |
@@ -1282,18 +1354,24 @@ discard block |
||
| 1282 | 1354 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
| 1283 | 1355 | |
| 1284 | 1356 | $idtype=$this->barcode_type; |
| 1285 | - 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 |
|
| 1357 | + if (empty($idtype) && $idtype != '0') { |
|
| 1358 | + // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined |
|
| 1286 | 1359 | {
|
| 1287 | - if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1288 | - else if ($this->element == 'societe') $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1289 | - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
|
|
| 1360 | + if ($this->element == 'product') $idtype = $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1361 | + } else if ($this->element == 'societe') { |
|
| 1362 | + $idtype = $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1363 | + } else { |
|
| 1364 | + dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); |
|
| 1365 | + } |
|
| 1290 | 1366 | } |
| 1291 | 1367 | |
| 1292 | 1368 | if ($idtype > 0) |
| 1293 | 1369 | {
|
| 1294 | - 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 |
|
| 1370 | + if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) { |
|
| 1371 | + // If data not already loaded |
|
| 1295 | 1372 | {
|
| 1296 | - $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1373 | + $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1374 | + } |
|
| 1297 | 1375 | $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
| 1298 | 1376 | $sql.= " WHERE rowid = ".$idtype; |
| 1299 | 1377 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
@@ -1306,8 +1384,7 @@ discard block |
||
| 1306 | 1384 | $this->barcode_type_label = $obj->label; |
| 1307 | 1385 | $this->barcode_type_coder = $obj->coder; |
| 1308 | 1386 | return 1; |
| 1309 | - } |
|
| 1310 | - else |
|
| 1387 | + } else |
|
| 1311 | 1388 | {
|
| 1312 | 1389 | dol_print_error($this->db); |
| 1313 | 1390 | return -1; |
@@ -1328,8 +1405,13 @@ discard block |
||
| 1328 | 1405 | // phpcs:enable |
| 1329 | 1406 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
| 1330 | 1407 | |
| 1331 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1332 | - if (empty($this->fk_project)) return 0; |
|
| 1408 | + if (empty($this->fk_project) && ! empty($this->fk_projet)) { |
|
| 1409 | + $this->fk_project = $this->fk_projet; |
|
| 1410 | + } |
|
| 1411 | + // For backward compatibility |
|
| 1412 | + if (empty($this->fk_project)) { |
|
| 1413 | + return 0; |
|
| 1414 | + } |
|
| 1333 | 1415 | |
| 1334 | 1416 | $project = new Project($this->db); |
| 1335 | 1417 | $result = $project->fetch($this->fk_project); |
@@ -1350,7 +1432,9 @@ discard block |
||
| 1350 | 1432 | // phpcs:enable |
| 1351 | 1433 | include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
| 1352 | 1434 | |
| 1353 | - if (empty($this->fk_product)) return 0; |
|
| 1435 | + if (empty($this->fk_product)) { |
|
| 1436 | + return 0; |
|
| 1437 | + } |
|
| 1354 | 1438 | |
| 1355 | 1439 | $product = new Product($this->db); |
| 1356 | 1440 | $result = $product->fetch($this->fk_product); |
@@ -1384,9 +1468,15 @@ discard block |
||
| 1384 | 1468 | function fetch_origin() |
| 1385 | 1469 | {
|
| 1386 | 1470 | // phpcs:enable |
| 1387 | - if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1388 | - if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1389 | - if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 1471 | + if ($this->origin == 'shipping') { |
|
| 1472 | + $this->origin = 'expedition'; |
|
| 1473 | + } |
|
| 1474 | + if ($this->origin == 'delivery') { |
|
| 1475 | + $this->origin = 'livraison'; |
|
| 1476 | + } |
|
| 1477 | + if ($this->origin == 'order_supplier') { |
|
| 1478 | + $this->origin = 'commandeFournisseur'; |
|
| 1479 | + } |
|
| 1390 | 1480 | |
| 1391 | 1481 | $origin = $this->origin; |
| 1392 | 1482 | |
@@ -1478,29 +1568,48 @@ discard block |
||
| 1478 | 1568 | {
|
| 1479 | 1569 | global $user,$langs,$conf; |
| 1480 | 1570 | |
| 1481 | - if (empty($table)) $table=$this->table_element; |
|
| 1482 | - if (empty($id)) $id=$this->id; |
|
| 1483 | - if (empty($format)) $format='text'; |
|
| 1484 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1571 | + if (empty($table)) { |
|
| 1572 | + $table=$this->table_element; |
|
| 1573 | + } |
|
| 1574 | + if (empty($id)) { |
|
| 1575 | + $id=$this->id; |
|
| 1576 | + } |
|
| 1577 | + if (empty($format)) { |
|
| 1578 | + $format='text'; |
|
| 1579 | + } |
|
| 1580 | + if (empty($id_field)) { |
|
| 1581 | + $id_field='rowid'; |
|
| 1582 | + } |
|
| 1485 | 1583 | |
| 1486 | 1584 | $error=0; |
| 1487 | 1585 | |
| 1488 | 1586 | $this->db->begin(); |
| 1489 | 1587 | |
| 1490 | 1588 | // Special case |
| 1491 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1492 | - if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
|
| 1589 | + if ($table == 'product' && $field == 'note_private') { |
|
| 1590 | + $field='note'; |
|
| 1591 | + } |
|
| 1592 | + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) { |
|
| 1593 | + $fk_user_field = 'fk_user_mod'; |
|
| 1594 | + } |
|
| 1493 | 1595 | |
| 1494 | 1596 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
| 1495 | 1597 | |
| 1496 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1497 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1498 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1598 | + if ($format == 'text') { |
|
| 1599 | + $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1600 | + } else if ($format == 'int') { |
|
| 1601 | + $sql.= $field." = ".$this->db->escape($value); |
|
| 1602 | + } else if ($format == 'date') { |
|
| 1603 | + $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1604 | + } |
|
| 1499 | 1605 | |
| 1500 | 1606 | if ($fk_user_field) |
| 1501 | 1607 | {
|
| 1502 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1503 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1608 | + if (! empty($fuser) && is_object($fuser)) { |
|
| 1609 | + $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1610 | + } elseif (empty($fuser) || $fuser != 'none') { |
|
| 1611 | + $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1612 | + } |
|
| 1504 | 1613 | } |
| 1505 | 1614 | |
| 1506 | 1615 | $sql.= " WHERE ".$id_field." = ".$id; |
@@ -1515,28 +1624,32 @@ discard block |
||
| 1515 | 1624 | if (empty($this->fields) && method_exists($this, 'fetch')) |
| 1516 | 1625 | {
|
| 1517 | 1626 | $result = $this->fetch($id); |
| 1518 | - } |
|
| 1519 | - else |
|
| 1627 | + } else |
|
| 1520 | 1628 | {
|
| 1521 | 1629 | $result = $this->fetchCommon($id); |
| 1522 | 1630 | } |
| 1523 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1524 | - if ($result < 0) $error++; |
|
| 1631 | + if ($result >= 0) { |
|
| 1632 | + $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); |
|
| 1633 | + } |
|
| 1634 | + // This may set this->errors |
|
| 1635 | + if ($result < 0) { |
|
| 1636 | + $error++; |
|
| 1637 | + } |
|
| 1525 | 1638 | } |
| 1526 | 1639 | |
| 1527 | 1640 | if (! $error) |
| 1528 | 1641 | {
|
| 1529 | - if (property_exists($this, $field)) $this->$field = $value; |
|
| 1642 | + if (property_exists($this, $field)) { |
|
| 1643 | + $this->$field = $value; |
|
| 1644 | + } |
|
| 1530 | 1645 | $this->db->commit(); |
| 1531 | 1646 | return 1; |
| 1532 | - } |
|
| 1533 | - else |
|
| 1647 | + } else |
|
| 1534 | 1648 | {
|
| 1535 | 1649 | $this->db->rollback(); |
| 1536 | 1650 | return -2; |
| 1537 | 1651 | } |
| 1538 | - } |
|
| 1539 | - else |
|
| 1652 | + } else |
|
| 1540 | 1653 | {
|
| 1541 | 1654 | $this->error=$this->db->lasterror(); |
| 1542 | 1655 | $this->db->rollback(); |
@@ -1563,36 +1676,66 @@ discard block |
||
| 1563 | 1676 | dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
| 1564 | 1677 | return -1; |
| 1565 | 1678 | } |
| 1566 | - if ($fieldid == 'none') return 1; |
|
| 1679 | + if ($fieldid == 'none') { |
|
| 1680 | + return 1; |
|
| 1681 | + } |
|
| 1567 | 1682 | |
| 1568 | 1683 | // Security on socid |
| 1569 | 1684 | $socid = 0; |
| 1570 | - if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 1685 | + if ($user->societe_id > 0) { |
|
| 1686 | + $socid = $user->societe_id; |
|
| 1687 | + } |
|
| 1571 | 1688 | |
| 1572 | 1689 | // this->ismultientitymanaged contains |
| 1573 | 1690 | // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
| 1574 | 1691 | $alias = 's'; |
| 1575 | - if ($this->element == 'societe') $alias = 'te'; |
|
| 1692 | + if ($this->element == 'societe') { |
|
| 1693 | + $alias = 'te'; |
|
| 1694 | + } |
|
| 1576 | 1695 | |
| 1577 | 1696 | $sql = "SELECT MAX(te.".$fieldid.")"; |
| 1578 | 1697 | $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
| 1579 | 1698 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1580 | 1699 | $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
| 1581 | 1700 | } |
| 1582 | - 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 |
|
| 1583 | - 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 |
|
| 1584 | - 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 |
|
| 1585 | - 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"; |
|
| 1701 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1702 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1703 | + } |
|
| 1704 | + // If we need to link to societe to limit select to entity |
|
| 1705 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1706 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1707 | + } |
|
| 1708 | + // If we need to link to societe to limit select to socid |
|
| 1709 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1710 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; |
|
| 1711 | + } |
|
| 1712 | + // If we need to link to societe to limit select to socid |
|
| 1713 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) { |
|
| 1714 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1715 | + } |
|
| 1586 | 1716 | $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
| 1587 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1588 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1717 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1718 | + $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1719 | + } |
|
| 1720 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1721 | + $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1722 | + } |
|
| 1589 | 1723 | if (! empty($filter)) |
| 1590 | 1724 | {
|
| 1591 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1725 | + if (! preg_match('/^\s*AND/i', $filter)) { |
|
| 1726 | + $sql.=" AND "; |
|
| 1727 | + } |
|
| 1728 | + // For backward compatibility |
|
| 1592 | 1729 | $sql.=$filter; |
| 1593 | 1730 | } |
| 1594 | - 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 |
|
| 1595 | - 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 |
|
| 1731 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1732 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1733 | + } |
|
| 1734 | + // If we need to link to societe to limit select to entity |
|
| 1735 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1736 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1737 | + } |
|
| 1738 | + // If we need to link to societe to limit select to socid |
|
| 1596 | 1739 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
| 1597 | 1740 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1598 | 1741 | if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
@@ -1605,9 +1748,15 @@ discard block |
||
| 1605 | 1748 | $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
| 1606 | 1749 | } |
| 1607 | 1750 | } |
| 1608 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1609 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1610 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1751 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') { |
|
| 1752 | + $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1753 | + } |
|
| 1754 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') { |
|
| 1755 | + $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1756 | + } |
|
| 1757 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') { |
|
| 1758 | + $sql.= ' AND te.rowid = ' . $socid; |
|
| 1759 | + } |
|
| 1611 | 1760 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1612 | 1761 | |
| 1613 | 1762 | $result = $this->db->query($sql); |
@@ -1625,20 +1774,44 @@ discard block |
||
| 1625 | 1774 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1626 | 1775 | $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
| 1627 | 1776 | } |
| 1628 | - 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 |
|
| 1629 | - 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 |
|
| 1630 | - 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 |
|
| 1631 | - 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"; |
|
| 1777 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1778 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1779 | + } |
|
| 1780 | + // If we need to link to societe to limit select to entity |
|
| 1781 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1782 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1783 | + } |
|
| 1784 | + // If we need to link to societe to limit select to socid |
|
| 1785 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1786 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; |
|
| 1787 | + } |
|
| 1788 | + // If we need to link to societe to limit select to socid |
|
| 1789 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) { |
|
| 1790 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1791 | + } |
|
| 1632 | 1792 | $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
| 1633 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1634 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1793 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1794 | + $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1795 | + } |
|
| 1796 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1797 | + $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1798 | + } |
|
| 1635 | 1799 | if (! empty($filter)) |
| 1636 | 1800 | {
|
| 1637 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1801 | + if (! preg_match('/^\s*AND/i', $filter)) { |
|
| 1802 | + $sql.=" AND "; |
|
| 1803 | + } |
|
| 1804 | + // For backward compatibility |
|
| 1638 | 1805 | $sql.=$filter; |
| 1639 | 1806 | } |
| 1640 | - 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 |
|
| 1641 | - 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 |
|
| 1807 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1808 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1809 | + } |
|
| 1810 | + // If we need to link to societe to limit select to entity |
|
| 1811 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1812 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1813 | + } |
|
| 1814 | + // If we need to link to societe to limit select to socid |
|
| 1642 | 1815 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
| 1643 | 1816 | if ($this->element == 'user' && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1644 | 1817 | if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
@@ -1651,9 +1824,15 @@ discard block |
||
| 1651 | 1824 | $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
| 1652 | 1825 | } |
| 1653 | 1826 | } |
| 1654 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1655 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1656 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1827 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') { |
|
| 1828 | + $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1829 | + } |
|
| 1830 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') { |
|
| 1831 | + $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1832 | + } |
|
| 1833 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') { |
|
| 1834 | + $sql.= ' AND te.rowid = ' . $socid; |
|
| 1835 | + } |
|
| 1657 | 1836 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1658 | 1837 | // 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 |
| 1659 | 1838 | |
@@ -1685,8 +1864,11 @@ discard block |
||
| 1685 | 1864 | $i = 0; |
| 1686 | 1865 | while ($i < $num) |
| 1687 | 1866 | {
|
| 1688 | - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1689 | - else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1867 | + if ($source == 'thirdparty') { |
|
| 1868 | + $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1869 | + } else { |
|
| 1870 | + $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1871 | + } |
|
| 1690 | 1872 | $i++; |
| 1691 | 1873 | } |
| 1692 | 1874 | return $contactAlreadySelected; |
@@ -1710,14 +1892,19 @@ discard block |
||
| 1710 | 1892 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1711 | 1893 | if ($this->table_element == 'actioncomm') |
| 1712 | 1894 | {
|
| 1713 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1714 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1895 | + if ($projectid) { |
|
| 1896 | + $sql.= ' SET fk_project = '.$projectid; |
|
| 1897 | + } else { |
|
| 1898 | + $sql.= ' SET fk_project = NULL'; |
|
| 1899 | + } |
|
| 1715 | 1900 | $sql.= ' WHERE id = '.$this->id; |
| 1716 | - } |
|
| 1717 | - else |
|
| 1901 | + } else |
|
| 1718 | 1902 | {
|
| 1719 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1720 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1903 | + if ($projectid) { |
|
| 1904 | + $sql.= ' SET fk_projet = '.$projectid; |
|
| 1905 | + } else { |
|
| 1906 | + $sql.= ' SET fk_projet = NULL'; |
|
| 1907 | + } |
|
| 1721 | 1908 | $sql.= ' WHERE rowid = '.$this->id; |
| 1722 | 1909 | } |
| 1723 | 1910 | |
@@ -1726,8 +1913,7 @@ discard block |
||
| 1726 | 1913 | {
|
| 1727 | 1914 | $this->fk_project = $projectid; |
| 1728 | 1915 | return 1; |
| 1729 | - } |
|
| 1730 | - else |
|
| 1916 | + } else |
|
| 1731 | 1917 | {
|
| 1732 | 1918 | dol_print_error($this->db); |
| 1733 | 1919 | return -1; |
@@ -1747,8 +1933,12 @@ discard block |
||
| 1747 | 1933 | {
|
| 1748 | 1934 | // TODO uniformize field name |
| 1749 | 1935 | $fieldname = 'fk_mode_reglement'; |
| 1750 | - if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1751 | - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 1936 | + if ($this->element == 'societe') { |
|
| 1937 | + $fieldname = 'mode_reglement'; |
|
| 1938 | + } |
|
| 1939 | + if (get_class($this) == 'Fournisseur') { |
|
| 1940 | + $fieldname = 'mode_reglement_supplier'; |
|
| 1941 | + } |
|
| 1752 | 1942 | |
| 1753 | 1943 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1754 | 1944 | $sql .= ' SET '.$fieldname.' = '.$id; |
@@ -1758,17 +1948,17 @@ discard block |
||
| 1758 | 1948 | {
|
| 1759 | 1949 | $this->mode_reglement_id = $id; |
| 1760 | 1950 | // for supplier |
| 1761 | - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1951 | + if (get_class($this) == 'Fournisseur') { |
|
| 1952 | + $this->mode_reglement_supplier_id = $id; |
|
| 1953 | + } |
|
| 1762 | 1954 | return 1; |
| 1763 | - } |
|
| 1764 | - else |
|
| 1955 | + } else |
|
| 1765 | 1956 | {
|
| 1766 | 1957 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
| 1767 | 1958 | $this->error=$this->db->error(); |
| 1768 | 1959 | return -1; |
| 1769 | 1960 | } |
| 1770 | - } |
|
| 1771 | - else |
|
| 1961 | + } else |
|
| 1772 | 1962 | {
|
| 1773 | 1963 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
| 1774 | 1964 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1798,18 +1988,18 @@ discard block |
||
| 1798 | 1988 | $this->multicurrency_code = $code; |
| 1799 | 1989 | |
| 1800 | 1990 | list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
| 1801 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 1991 | + if ($rate) { |
|
| 1992 | + $this->setMulticurrencyRate($rate,2); |
|
| 1993 | + } |
|
| 1802 | 1994 | |
| 1803 | 1995 | return 1; |
| 1804 | - } |
|
| 1805 | - else |
|
| 1996 | + } else |
|
| 1806 | 1997 | {
|
| 1807 | 1998 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
| 1808 | 1999 | $this->error=$this->db->error(); |
| 1809 | 2000 | return -1; |
| 1810 | 2001 | } |
| 1811 | - } |
|
| 1812 | - else |
|
| 2002 | + } else |
|
| 1813 | 2003 | {
|
| 1814 | 2004 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
| 1815 | 2005 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1903,15 +2093,13 @@ discard block |
||
| 1903 | 2093 | } |
| 1904 | 2094 | |
| 1905 | 2095 | return 1; |
| 1906 | - } |
|
| 1907 | - else |
|
| 2096 | + } else |
|
| 1908 | 2097 | {
|
| 1909 | 2098 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
| 1910 | 2099 | $this->error=$this->db->error(); |
| 1911 | 2100 | return -1; |
| 1912 | 2101 | } |
| 1913 | - } |
|
| 1914 | - else |
|
| 2102 | + } else |
|
| 1915 | 2103 | {
|
| 1916 | 2104 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
| 1917 | 2105 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1932,8 +2120,12 @@ discard block |
||
| 1932 | 2120 | {
|
| 1933 | 2121 | // TODO uniformize field name |
| 1934 | 2122 | $fieldname = 'fk_cond_reglement'; |
| 1935 | - if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1936 | - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 2123 | + if ($this->element == 'societe') { |
|
| 2124 | + $fieldname = 'cond_reglement'; |
|
| 2125 | + } |
|
| 2126 | + if (get_class($this) == 'Fournisseur') { |
|
| 2127 | + $fieldname = 'cond_reglement_supplier'; |
|
| 2128 | + } |
|
| 1937 | 2129 | |
| 1938 | 2130 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1939 | 2131 | $sql .= ' SET '.$fieldname.' = '.$id; |
@@ -1943,18 +2135,18 @@ discard block |
||
| 1943 | 2135 | {
|
| 1944 | 2136 | $this->cond_reglement_id = $id; |
| 1945 | 2137 | // for supplier |
| 1946 | - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 2138 | + if (get_class($this) == 'Fournisseur') { |
|
| 2139 | + $this->cond_reglement_supplier_id = $id; |
|
| 2140 | + } |
|
| 1947 | 2141 | $this->cond_reglement = $id; // for compatibility |
| 1948 | 2142 | return 1; |
| 1949 | - } |
|
| 1950 | - else |
|
| 2143 | + } else |
|
| 1951 | 2144 | {
|
| 1952 | 2145 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
| 1953 | 2146 | $this->error=$this->db->error(); |
| 1954 | 2147 | return -1; |
| 1955 | 2148 | } |
| 1956 | - } |
|
| 1957 | - else |
|
| 2149 | + } else |
|
| 1958 | 2150 | {
|
| 1959 | 2151 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
| 1960 | 2152 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1972,7 +2164,9 @@ discard block |
||
| 1972 | 2164 | function setDeliveryAddress($id) |
| 1973 | 2165 | {
|
| 1974 | 2166 | $fieldname = 'fk_delivery_address'; |
| 1975 | - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 2167 | + if ($this->element == 'delivery' || $this->element == 'shipping') { |
|
| 2168 | + $fieldname = 'fk_address'; |
|
| 2169 | + } |
|
| 1976 | 2170 | |
| 1977 | 2171 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
| 1978 | 2172 | $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
@@ -1981,8 +2175,7 @@ discard block |
||
| 1981 | 2175 | {
|
| 1982 | 2176 | $this->fk_delivery_address = $id; |
| 1983 | 2177 | return 1; |
| 1984 | - } |
|
| 1985 | - else |
|
| 2178 | + } else |
|
| 1986 | 2179 | {
|
| 1987 | 2180 | $this->error=$this->db->error(); |
| 1988 | 2181 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
@@ -2004,7 +2197,9 @@ discard block |
||
| 2004 | 2197 | {
|
| 2005 | 2198 | global $user; |
| 2006 | 2199 | |
| 2007 | - if (empty($userused)) $userused=$user; |
|
| 2200 | + if (empty($userused)) { |
|
| 2201 | + $userused=$user; |
|
| 2202 | + } |
|
| 2008 | 2203 | |
| 2009 | 2204 | $error = 0; |
| 2010 | 2205 | |
@@ -2015,7 +2210,9 @@ discard block |
||
| 2015 | 2210 | |
| 2016 | 2211 | $this->db->begin(); |
| 2017 | 2212 | |
| 2018 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2213 | + if ($shipping_method_id<0) { |
|
| 2214 | + $shipping_method_id='NULL'; |
|
| 2215 | + } |
|
| 2019 | 2216 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
| 2020 | 2217 | |
| 2021 | 2218 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2032,7 +2229,9 @@ discard block |
||
| 2032 | 2229 | // Call trigger |
| 2033 | 2230 | $this->context=array('shippingmethodupdate'=>1);
|
| 2034 | 2231 | $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
| 2035 | - if ($result < 0) $error++; |
|
| 2232 | + if ($result < 0) { |
|
| 2233 | + $error++; |
|
| 2234 | + } |
|
| 2036 | 2235 | // End call trigger |
| 2037 | 2236 | } |
| 2038 | 2237 | } |
@@ -2060,7 +2259,9 @@ discard block |
||
| 2060 | 2259 | dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
| 2061 | 2260 | return -1; |
| 2062 | 2261 | } |
| 2063 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2262 | + if ($warehouse_id<0) { |
|
| 2263 | + $warehouse_id='NULL'; |
|
| 2264 | + } |
|
| 2064 | 2265 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
| 2065 | 2266 | |
| 2066 | 2267 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2107,8 +2308,7 @@ discard block |
||
| 2107 | 2308 | {
|
| 2108 | 2309 | $this->modelpdf=$modelpdf; |
| 2109 | 2310 | return 1; |
| 2110 | - } |
|
| 2111 | - else |
|
| 2311 | + } else |
|
| 2112 | 2312 | {
|
| 2113 | 2313 | dol_print_error($this->db); |
| 2114 | 2314 | return 0; |
@@ -2128,7 +2328,9 @@ discard block |
||
| 2128 | 2328 | {
|
| 2129 | 2329 | global $user; |
| 2130 | 2330 | |
| 2131 | - if (empty($userused)) $userused=$user; |
|
| 2331 | + if (empty($userused)) { |
|
| 2332 | + $userused=$user; |
|
| 2333 | + } |
|
| 2132 | 2334 | |
| 2133 | 2335 | $error = 0; |
| 2134 | 2336 | |
@@ -2138,7 +2340,9 @@ discard block |
||
| 2138 | 2340 | } |
| 2139 | 2341 | $this->db->begin(); |
| 2140 | 2342 | |
| 2141 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2343 | + if ($fk_account<0) { |
|
| 2344 | + $fk_account='NULL'; |
|
| 2345 | + } |
|
| 2142 | 2346 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
| 2143 | 2347 | |
| 2144 | 2348 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2151,15 +2355,16 @@ discard block |
||
| 2151 | 2355 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
| 2152 | 2356 | $this->error = $this->db->lasterror(); |
| 2153 | 2357 | $error++; |
| 2154 | - } |
|
| 2155 | - else |
|
| 2358 | + } else |
|
| 2156 | 2359 | {
|
| 2157 | 2360 | if (!$notrigger) |
| 2158 | 2361 | {
|
| 2159 | 2362 | // Call trigger |
| 2160 | 2363 | $this->context=array('bankaccountupdate'=>1);
|
| 2161 | 2364 | $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
| 2162 | - if ($result < 0) $error++; |
|
| 2365 | + if ($result < 0) { |
|
| 2366 | + $error++; |
|
| 2367 | + } |
|
| 2163 | 2368 | // End call trigger |
| 2164 | 2369 | } |
| 2165 | 2370 | } |
@@ -2167,8 +2372,7 @@ discard block |
||
| 2167 | 2372 | {
|
| 2168 | 2373 | $this->db->rollback(); |
| 2169 | 2374 | return -1; |
| 2170 | - } |
|
| 2171 | - else |
|
| 2375 | + } else |
|
| 2172 | 2376 | {
|
| 2173 | 2377 | $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
| 2174 | 2378 | $this->db->commit(); |
@@ -2207,8 +2411,12 @@ discard block |
||
| 2207 | 2411 | $nl=0; |
| 2208 | 2412 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2209 | 2413 | $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
| 2210 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2211 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2414 | + if (! $renum) { |
|
| 2415 | + $sql.= ' AND rang = 0'; |
|
| 2416 | + } |
|
| 2417 | + if ($renum) { |
|
| 2418 | + $sql.= ' AND rang <> 0'; |
|
| 2419 | + } |
|
| 2212 | 2420 | |
| 2213 | 2421 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
| 2214 | 2422 | $resql = $this->db->query($sql); |
@@ -2216,8 +2424,9 @@ discard block |
||
| 2216 | 2424 | {
|
| 2217 | 2425 | $row = $this->db->fetch_row($resql); |
| 2218 | 2426 | $nl = $row[0]; |
| 2219 | - } |
|
| 2220 | - else dol_print_error($this->db); |
|
| 2427 | + } else { |
|
| 2428 | + dol_print_error($this->db); |
|
| 2429 | + } |
|
| 2221 | 2430 | if ($nl > 0) |
| 2222 | 2431 | {
|
| 2223 | 2432 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
@@ -2227,7 +2436,9 @@ discard block |
||
| 2227 | 2436 | // We first search all lines that are parent lines (for multilevel details lines) |
| 2228 | 2437 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2229 | 2438 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
| 2230 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2439 | + if ($fk_parent_line) { |
|
| 2440 | + $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2441 | + } |
|
| 2231 | 2442 | $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
| 2232 | 2443 | |
| 2233 | 2444 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
@@ -2259,8 +2470,7 @@ discard block |
||
| 2259 | 2470 | $this->updateRangOfLine($row, ($key+1)); |
| 2260 | 2471 | } |
| 2261 | 2472 | } |
| 2262 | - } |
|
| 2263 | - else |
|
| 2473 | + } else |
|
| 2264 | 2474 | {
|
| 2265 | 2475 | dol_print_error($this->db); |
| 2266 | 2476 | } |
@@ -2353,7 +2563,9 @@ discard block |
||
| 2353 | 2563 | function updateRangOfLine($rowid,$rang) |
| 2354 | 2564 | {
|
| 2355 | 2565 | $fieldposition = 'rang'; |
| 2356 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2566 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2567 | + $fieldposition = 'position'; |
|
| 2568 | + } |
|
| 2357 | 2569 | |
| 2358 | 2570 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2359 | 2571 | $sql.= ' WHERE rowid = '.$rowid; |
@@ -2394,7 +2606,9 @@ discard block |
||
| 2394 | 2606 | if ($rang > 1) |
| 2395 | 2607 | {
|
| 2396 | 2608 | $fieldposition = 'rang'; |
| 2397 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2609 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2610 | + $fieldposition = 'position'; |
|
| 2611 | + } |
|
| 2398 | 2612 | |
| 2399 | 2613 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
| 2400 | 2614 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
@@ -2407,8 +2621,7 @@ discard block |
||
| 2407 | 2621 | {
|
| 2408 | 2622 | dol_print_error($this->db); |
| 2409 | 2623 | } |
| 2410 | - } |
|
| 2411 | - else |
|
| 2624 | + } else |
|
| 2412 | 2625 | {
|
| 2413 | 2626 | dol_print_error($this->db); |
| 2414 | 2627 | } |
@@ -2428,7 +2641,9 @@ discard block |
||
| 2428 | 2641 | if ($rang < $max) |
| 2429 | 2642 | {
|
| 2430 | 2643 | $fieldposition = 'rang'; |
| 2431 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2644 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2645 | + $fieldposition = 'position'; |
|
| 2646 | + } |
|
| 2432 | 2647 | |
| 2433 | 2648 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2434 | 2649 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
@@ -2441,8 +2656,7 @@ discard block |
||
| 2441 | 2656 | {
|
| 2442 | 2657 | dol_print_error($this->db); |
| 2443 | 2658 | } |
| 2444 | - } |
|
| 2445 | - else |
|
| 2659 | + } else |
|
| 2446 | 2660 | {
|
| 2447 | 2661 | dol_print_error($this->db); |
| 2448 | 2662 | } |
@@ -2513,8 +2727,7 @@ discard block |
||
| 2513 | 2727 | if (! empty($row[0])) |
| 2514 | 2728 | {
|
| 2515 | 2729 | return $row[0]; |
| 2516 | - } |
|
| 2517 | - else |
|
| 2730 | + } else |
|
| 2518 | 2731 | {
|
| 2519 | 2732 | return $this->getRangOfLine($fk_parent_line); |
| 2520 | 2733 | } |
@@ -2561,8 +2774,7 @@ discard block |
||
| 2561 | 2774 | {
|
| 2562 | 2775 | $this->ref_ext = $ref_ext; |
| 2563 | 2776 | return 1; |
| 2564 | - } |
|
| 2565 | - else |
|
| 2777 | + } else |
|
| 2566 | 2778 | {
|
| 2567 | 2779 | $this->error=$this->db->error(); |
| 2568 | 2780 | return -1; |
@@ -2596,7 +2808,9 @@ discard block |
||
| 2596 | 2808 | } |
| 2597 | 2809 | // Special cas |
| 2598 | 2810 | //var_dump($this->table_element);exit; |
| 2599 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2811 | + if ($this->table_element == 'product') { |
|
| 2812 | + $suffix=''; |
|
| 2813 | + } |
|
| 2600 | 2814 | |
| 2601 | 2815 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2602 | 2816 | $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
@@ -2606,16 +2820,17 @@ discard block |
||
| 2606 | 2820 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
| 2607 | 2821 | if ($this->db->query($sql)) |
| 2608 | 2822 | {
|
| 2609 | - if ($suffix == '_public') $this->note_public = $note; |
|
| 2610 | - else if ($suffix == '_private') $this->note_private = $note; |
|
| 2611 | - else |
|
| 2823 | + if ($suffix == '_public') { |
|
| 2824 | + $this->note_public = $note; |
|
| 2825 | + } else if ($suffix == '_private') { |
|
| 2826 | + $this->note_private = $note; |
|
| 2827 | + } else |
|
| 2612 | 2828 | {
|
| 2613 | 2829 | $this->note = $note; // deprecated |
| 2614 | 2830 | $this->note_private = $note; |
| 2615 | 2831 | } |
| 2616 | 2832 | return 1; |
| 2617 | - } |
|
| 2618 | - else |
|
| 2833 | + } else |
|
| 2619 | 2834 | {
|
| 2620 | 2835 | $this->error=$this->db->lasterror(); |
| 2621 | 2836 | return -1; |
@@ -2655,36 +2870,45 @@ discard block |
||
| 2655 | 2870 | |
| 2656 | 2871 | // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
| 2657 | 2872 | $MODULE = ""; |
| 2658 | - if ($this->element == 'propal') |
|
| 2659 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2660 | - elseif ($this->element == 'order') |
|
| 2661 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2662 | - elseif ($this->element == 'facture') |
|
| 2663 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2664 | - elseif ($this->element == 'facture_fourn') |
|
| 2665 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2666 | - elseif ($this->element == 'order_supplier') |
|
| 2667 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2668 | - elseif ($this->element == 'supplier_proposal') |
|
| 2669 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2873 | + if ($this->element == 'propal') { |
|
| 2874 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2875 | + } elseif ($this->element == 'order') { |
|
| 2876 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2877 | + } elseif ($this->element == 'facture') { |
|
| 2878 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2879 | + } elseif ($this->element == 'facture_fourn') { |
|
| 2880 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2881 | + } elseif ($this->element == 'order_supplier') { |
|
| 2882 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2883 | + } elseif ($this->element == 'supplier_proposal') { |
|
| 2884 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2885 | + } |
|
| 2670 | 2886 | |
| 2671 | 2887 | if (! empty($MODULE)) {
|
| 2672 | 2888 | if (! empty($conf->global->$MODULE)) {
|
| 2673 | 2889 | $modsactivated = explode(',', $conf->global->$MODULE);
|
| 2674 | 2890 | foreach ($modsactivated as $mod) {
|
| 2675 | - if ($conf->$mod->enabled) |
|
| 2676 | - return 1; // update was disabled by specific setup |
|
| 2891 | + if ($conf->$mod->enabled) { |
|
| 2892 | + return 1; |
|
| 2893 | + } |
|
| 2894 | + // update was disabled by specific setup |
|
| 2677 | 2895 | } |
| 2678 | 2896 | } |
| 2679 | 2897 | } |
| 2680 | 2898 | |
| 2681 | 2899 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
| 2682 | 2900 | |
| 2683 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2901 | + if ($roundingadjust == '-1') { |
|
| 2902 | + $roundingadjust='auto'; |
|
| 2903 | + } |
|
| 2904 | + // For backward compatibility |
|
| 2684 | 2905 | |
| 2685 | 2906 | $forcedroundingmode=$roundingadjust; |
| 2686 | - if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2687 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2907 | + if ($forcedroundingmode == 'auto' && isset($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) { |
|
| 2908 | + $forcedroundingmode=$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2909 | + } elseif ($forcedroundingmode == 'auto') { |
|
| 2910 | + $forcedroundingmode='0'; |
|
| 2911 | + } |
|
| 2688 | 2912 | |
| 2689 | 2913 | $error=0; |
| 2690 | 2914 | |
@@ -2707,15 +2931,22 @@ discard block |
||
| 2707 | 2931 | |
| 2708 | 2932 | $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,'; |
| 2709 | 2933 | $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
| 2710 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2934 | + if ($this->table_element_line == 'facturedet') { |
|
| 2935 | + $sql.= ', situation_percent'; |
|
| 2936 | + } |
|
| 2711 | 2937 | $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
| 2712 | 2938 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2713 | 2939 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
| 2714 | 2940 | if ($exclspec) |
| 2715 | 2941 | {
|
| 2716 | 2942 | $product_field='product_type'; |
| 2717 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2718 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2943 | + if ($this->table_element_line == 'contratdet') { |
|
| 2944 | + $product_field=''; |
|
| 2945 | + } |
|
| 2946 | + // contratdet table has no product_type field |
|
| 2947 | + if ($product_field) { |
|
| 2948 | + $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2949 | + } |
|
| 2719 | 2950 | } |
| 2720 | 2951 | $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 |
| 2721 | 2952 | |
@@ -2745,9 +2976,11 @@ discard block |
||
| 2745 | 2976 | $parameters=array('fk_element' => $obj->rowid);
|
| 2746 | 2977 | $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
| 2747 | 2978 | |
| 2748 | - if (empty($reshook) && $forcedroundingmode == '0') // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 2979 | + if (empty($reshook) && $forcedroundingmode == '0') { |
|
| 2980 | + // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 2749 | 2981 | {
|
| 2750 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2982 | + $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2983 | + } |
|
| 2751 | 2984 | $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); |
| 2752 | 2985 | $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
| 2753 | 2986 | if ($diff) |
@@ -2755,7 +2988,9 @@ discard block |
||
| 2755 | 2988 | $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
| 2756 | 2989 | 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);
|
| 2757 | 2990 | $resqlfix=$this->db->query($sqlfix); |
| 2758 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2991 | + if (! $resqlfix) { |
|
| 2992 | + dol_print_error($this->db,'Failed to update line'); |
|
| 2993 | + } |
|
| 2759 | 2994 | $obj->total_tva = $tmpcal[1]; |
| 2760 | 2995 | $obj->total_ttc = $tmpcal[2]; |
| 2761 | 2996 | // |
@@ -2771,16 +3006,24 @@ discard block |
||
| 2771 | 3006 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
| 2772 | 3007 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
| 2773 | 3008 | |
| 2774 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2775 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2776 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 3009 | + if (! isset($total_ht_by_vats[$obj->vatrate])) { |
|
| 3010 | + $total_ht_by_vats[$obj->vatrate]=0; |
|
| 3011 | + } |
|
| 3012 | + if (! isset($total_tva_by_vats[$obj->vatrate])) { |
|
| 3013 | + $total_tva_by_vats[$obj->vatrate]=0; |
|
| 3014 | + } |
|
| 3015 | + if (! isset($total_ttc_by_vats[$obj->vatrate])) { |
|
| 3016 | + $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 3017 | + } |
|
| 2777 | 3018 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
| 2778 | 3019 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
| 2779 | 3020 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
| 2780 | 3021 | |
| 2781 | - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 3022 | + if ($forcedroundingmode == '1') { |
|
| 3023 | + // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2782 | 3024 | {
|
| 2783 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 3025 | + $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 3026 | + } |
|
| 2784 | 3027 | $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
| 2785 | 3028 | //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"; |
| 2786 | 3029 | if ($diff) |
@@ -2789,7 +3032,9 @@ discard block |
||
| 2789 | 3032 | $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; |
| 2790 | 3033 | 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);
|
| 2791 | 3034 | $resqlfix=$this->db->query($sqlfix); |
| 2792 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 3035 | + if (! $resqlfix) { |
|
| 3036 | + dol_print_error($this->db,'Failed to update line'); |
|
| 3037 | + } |
|
| 2793 | 3038 | $this->total_tva -= $diff; |
| 2794 | 3039 | $this->total_ttc -= $diff; |
| 2795 | 3040 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2830,11 +3075,21 @@ discard block |
||
| 2830 | 3075 | $fieldlocaltax2='localtax2'; |
| 2831 | 3076 | $fieldttc='total_ttc'; |
| 2832 | 3077 | // Specific code for backward compatibility with old field names |
| 2833 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2834 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2835 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2836 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2837 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 3078 | + if ($this->element == 'facture' || $this->element == 'facturerec') { |
|
| 3079 | + $fieldht='total'; |
|
| 3080 | + } |
|
| 3081 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { |
|
| 3082 | + $fieldtva='total_tva'; |
|
| 3083 | + } |
|
| 3084 | + if ($this->element == 'propal') { |
|
| 3085 | + $fieldttc='total'; |
|
| 3086 | + } |
|
| 3087 | + if ($this->element == 'expensereport') { |
|
| 3088 | + $fieldtva='total_tva'; |
|
| 3089 | + } |
|
| 3090 | + if ($this->element == 'supplier_proposal') { |
|
| 3091 | + $fieldttc='total'; |
|
| 3092 | + } |
|
| 2838 | 3093 | |
| 2839 | 3094 | if (empty($nodatabaseupdate)) |
| 2840 | 3095 | {
|
@@ -2863,13 +3118,11 @@ discard block |
||
| 2863 | 3118 | if (! $error) |
| 2864 | 3119 | {
|
| 2865 | 3120 | return 1; |
| 2866 | - } |
|
| 2867 | - else |
|
| 3121 | + } else |
|
| 2868 | 3122 | {
|
| 2869 | 3123 | return -1; |
| 2870 | 3124 | } |
| 2871 | - } |
|
| 2872 | - else |
|
| 3125 | + } else |
|
| 2873 | 3126 | {
|
| 2874 | 3127 | dol_print_error($this->db,'Bad request in update_price'); |
| 2875 | 3128 | return -1; |
@@ -2892,10 +3145,18 @@ discard block |
||
| 2892 | 3145 | $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
| 2893 | 3146 | |
| 2894 | 3147 | // Special case |
| 2895 | - if ($origin == 'order') $origin='commande'; |
|
| 2896 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2897 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2898 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 3148 | + if ($origin == 'order') { |
|
| 3149 | + $origin='commande'; |
|
| 3150 | + } |
|
| 3151 | + if ($origin == 'invoice') { |
|
| 3152 | + $origin='facture'; |
|
| 3153 | + } |
|
| 3154 | + if ($origin == 'invoice_template') { |
|
| 3155 | + $origin='facturerec'; |
|
| 3156 | + } |
|
| 3157 | + if ($origin == 'supplierorder') { |
|
| 3158 | + $origin='order_supplier'; |
|
| 3159 | + } |
|
| 2899 | 3160 | $this->db->begin(); |
| 2900 | 3161 | |
| 2901 | 3162 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
@@ -2915,8 +3176,7 @@ discard block |
||
| 2915 | 3176 | {
|
| 2916 | 3177 | $this->db->commit(); |
| 2917 | 3178 | return 1; |
| 2918 | - } |
|
| 2919 | - else |
|
| 3179 | + } else |
|
| 2920 | 3180 | {
|
| 2921 | 3181 | $this->error=$this->db->lasterror(); |
| 2922 | 3182 | $this->db->rollback(); |
@@ -2961,12 +3221,16 @@ discard block |
||
| 2961 | 3221 | if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
| 2962 | 3222 | {
|
| 2963 | 3223 | $justsource=true; // the source (id and type) is a search criteria |
| 2964 | - if (! empty($targettype)) $withtargettype=true; |
|
| 3224 | + if (! empty($targettype)) { |
|
| 3225 | + $withtargettype=true; |
|
| 3226 | + } |
|
| 2965 | 3227 | } |
| 2966 | 3228 | if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
| 2967 | 3229 | {
|
| 2968 | 3230 | $justtarget=true; // the target (id and type) is a search criteria |
| 2969 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 3231 | + if (! empty($sourcetype)) { |
|
| 3232 | + $withsourcetype=true; |
|
| 3233 | + } |
|
| 2970 | 3234 | } |
| 2971 | 3235 | |
| 2972 | 3236 | $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
@@ -2989,15 +3253,17 @@ discard block |
||
| 2989 | 3253 | if ($justsource) |
| 2990 | 3254 | {
|
| 2991 | 3255 | $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
| 2992 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2993 | - } |
|
| 2994 | - else if ($justtarget) |
|
| 3256 | + if ($withtargettype) { |
|
| 3257 | + $sql.= " AND targettype = '".$targettype."'"; |
|
| 3258 | + } |
|
| 3259 | + } else if ($justtarget) |
|
| 2995 | 3260 | {
|
| 2996 | 3261 | $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
| 2997 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3262 | + if ($withsourcetype) { |
|
| 3263 | + $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3264 | + } |
|
| 2998 | 3265 | } |
| 2999 | - } |
|
| 3000 | - else |
|
| 3266 | + } else |
|
| 3001 | 3267 | {
|
| 3002 | 3268 | $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
| 3003 | 3269 | $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
@@ -3018,13 +3284,11 @@ discard block |
||
| 3018 | 3284 | if ($justsource) |
| 3019 | 3285 | {
|
| 3020 | 3286 | $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
| 3021 | - } |
|
| 3022 | - else if ($justtarget) |
|
| 3287 | + } else if ($justtarget) |
|
| 3023 | 3288 | {
|
| 3024 | 3289 | $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
| 3025 | 3290 | } |
| 3026 | - } |
|
| 3027 | - else |
|
| 3291 | + } else |
|
| 3028 | 3292 | {
|
| 3029 | 3293 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
| 3030 | 3294 | {
|
@@ -3041,10 +3305,12 @@ discard block |
||
| 3041 | 3305 | if (! empty($this->linkedObjectsIds)) |
| 3042 | 3306 | {
|
| 3043 | 3307 | $tmparray = $this->linkedObjectsIds; |
| 3044 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3308 | + foreach($tmparray as $objecttype => $objectids) { |
|
| 3309 | + // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3045 | 3310 | {
|
| 3046 | 3311 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
| 3047 | - $module = $element = $subelement = $objecttype; |
|
| 3312 | + $module = $element = $subelement = $objecttype; |
|
| 3313 | + } |
|
| 3048 | 3314 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
| 3049 | 3315 | && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
| 3050 | 3316 | {
|
@@ -3056,29 +3322,21 @@ discard block |
||
| 3056 | 3322 | // To work with non standard classpath or module name |
| 3057 | 3323 | if ($objecttype == 'facture') {
|
| 3058 | 3324 | $classpath = 'compta/facture/class'; |
| 3059 | - } |
|
| 3060 | - else if ($objecttype == 'facturerec') {
|
|
| 3325 | + } else if ($objecttype == 'facturerec') {
|
|
| 3061 | 3326 | $classpath = 'compta/facture/class'; $module = 'facture'; |
| 3062 | - } |
|
| 3063 | - else if ($objecttype == 'propal') {
|
|
| 3327 | + } else if ($objecttype == 'propal') {
|
|
| 3064 | 3328 | $classpath = 'comm/propal/class'; |
| 3065 | - } |
|
| 3066 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3329 | + } else if ($objecttype == 'supplier_proposal') {
|
|
| 3067 | 3330 | $classpath = 'supplier_proposal/class'; |
| 3068 | - } |
|
| 3069 | - else if ($objecttype == 'shipping') {
|
|
| 3331 | + } else if ($objecttype == 'shipping') {
|
|
| 3070 | 3332 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
| 3071 | - } |
|
| 3072 | - else if ($objecttype == 'delivery') {
|
|
| 3333 | + } else if ($objecttype == 'delivery') {
|
|
| 3073 | 3334 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
| 3074 | - } |
|
| 3075 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3335 | + } else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3076 | 3336 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
| 3077 | - } |
|
| 3078 | - else if ($objecttype == 'fichinter') {
|
|
| 3337 | + } else if ($objecttype == 'fichinter') {
|
|
| 3079 | 3338 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
| 3080 | - } |
|
| 3081 | - else if ($objecttype == 'subscription') {
|
|
| 3339 | + } else if ($objecttype == 'subscription') {
|
|
| 3082 | 3340 | $classpath = 'adherents/class'; $module = 'adherent'; |
| 3083 | 3341 | } |
| 3084 | 3342 | |
@@ -3087,20 +3345,15 @@ discard block |
||
| 3087 | 3345 | |
| 3088 | 3346 | if ($objecttype == 'order') {
|
| 3089 | 3347 | $classfile = 'commande'; $classname = 'Commande'; |
| 3090 | - } |
|
| 3091 | - else if ($objecttype == 'invoice_supplier') {
|
|
| 3348 | + } else if ($objecttype == 'invoice_supplier') {
|
|
| 3092 | 3349 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
| 3093 | - } |
|
| 3094 | - else if ($objecttype == 'order_supplier') {
|
|
| 3350 | + } else if ($objecttype == 'order_supplier') {
|
|
| 3095 | 3351 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
| 3096 | - } |
|
| 3097 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3352 | + } else if ($objecttype == 'supplier_proposal') {
|
|
| 3098 | 3353 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
| 3099 | - } |
|
| 3100 | - else if ($objecttype == 'facturerec') {
|
|
| 3354 | + } else if ($objecttype == 'facturerec') {
|
|
| 3101 | 3355 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
| 3102 | - } |
|
| 3103 | - else if ($objecttype == 'subscription') {
|
|
| 3356 | + } else if ($objecttype == 'subscription') {
|
|
| 3104 | 3357 | $classfile = 'subscription'; $classname = 'Subscription'; |
| 3105 | 3358 | } |
| 3106 | 3359 | |
@@ -3113,9 +3366,11 @@ discard block |
||
| 3113 | 3366 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
| 3114 | 3367 | if (class_exists($classname)) |
| 3115 | 3368 | {
|
| 3116 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3369 | + foreach($objectids as $i => $objectid) { |
|
| 3370 | + // $i is rowid into llx_element_element |
|
| 3117 | 3371 | {
|
| 3118 | - $object = new $classname($this->db); |
|
| 3372 | + $object = new $classname($this->db); |
|
| 3373 | + } |
|
| 3119 | 3374 | $ret = $object->fetch($objectid); |
| 3120 | 3375 | if ($ret >= 0) |
| 3121 | 3376 | {
|
@@ -3124,16 +3379,14 @@ discard block |
||
| 3124 | 3379 | } |
| 3125 | 3380 | } |
| 3126 | 3381 | } |
| 3127 | - } |
|
| 3128 | - else |
|
| 3382 | + } else |
|
| 3129 | 3383 | {
|
| 3130 | 3384 | unset($this->linkedObjectsIds[$objecttype]); |
| 3131 | 3385 | } |
| 3132 | 3386 | } |
| 3133 | 3387 | } |
| 3134 | 3388 | return 1; |
| 3135 | - } |
|
| 3136 | - else |
|
| 3389 | + } else |
|
| 3137 | 3390 | {
|
| 3138 | 3391 | dol_print_error($this->db); |
| 3139 | 3392 | return -1; |
@@ -3155,8 +3408,11 @@ discard block |
||
| 3155 | 3408 | $updatesource=false; |
| 3156 | 3409 | $updatetarget=false; |
| 3157 | 3410 | |
| 3158 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3159 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3411 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) { |
|
| 3412 | + $updatesource=true; |
|
| 3413 | + } else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) { |
|
| 3414 | + $updatetarget=true; |
|
| 3415 | + } |
|
| 3160 | 3416 | |
| 3161 | 3417 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
| 3162 | 3418 | if ($updatesource) |
@@ -3165,8 +3421,7 @@ discard block |
||
| 3165 | 3421 | $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
| 3166 | 3422 | $sql.= " WHERE fk_target = ".$this->id; |
| 3167 | 3423 | $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
| 3168 | - } |
|
| 3169 | - else if ($updatetarget) |
|
| 3424 | + } else if ($updatetarget) |
|
| 3170 | 3425 | {
|
| 3171 | 3426 | $sql.= "fk_target = ".$targetid; |
| 3172 | 3427 | $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
@@ -3178,8 +3433,7 @@ discard block |
||
| 3178 | 3433 | if ($this->db->query($sql)) |
| 3179 | 3434 | {
|
| 3180 | 3435 | return 1; |
| 3181 | - } |
|
| 3182 | - else |
|
| 3436 | + } else |
|
| 3183 | 3437 | {
|
| 3184 | 3438 | $this->error=$this->db->lasterror(); |
| 3185 | 3439 | return -1; |
@@ -3202,8 +3456,11 @@ discard block |
||
| 3202 | 3456 | $deletesource=false; |
| 3203 | 3457 | $deletetarget=false; |
| 3204 | 3458 | |
| 3205 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3206 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3459 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) { |
|
| 3460 | + $deletesource=true; |
|
| 3461 | + } else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) { |
|
| 3462 | + $deletetarget=true; |
|
| 3463 | + } |
|
| 3207 | 3464 | |
| 3208 | 3465 | $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
| 3209 | 3466 | $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
@@ -3215,20 +3472,17 @@ discard block |
||
| 3215 | 3472 | if ($rowid > 0) |
| 3216 | 3473 | {
|
| 3217 | 3474 | $sql.=" rowid = ".$rowid; |
| 3218 | - } |
|
| 3219 | - else |
|
| 3475 | + } else |
|
| 3220 | 3476 | {
|
| 3221 | 3477 | if ($deletesource) |
| 3222 | 3478 | {
|
| 3223 | 3479 | $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
| 3224 | 3480 | $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
| 3225 | - } |
|
| 3226 | - else if ($deletetarget) |
|
| 3481 | + } else if ($deletetarget) |
|
| 3227 | 3482 | {
|
| 3228 | 3483 | $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
| 3229 | 3484 | $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
| 3230 | - } |
|
| 3231 | - else |
|
| 3485 | + } else |
|
| 3232 | 3486 | {
|
| 3233 | 3487 | $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
| 3234 | 3488 | $sql.= " OR"; |
@@ -3240,8 +3494,7 @@ discard block |
||
| 3240 | 3494 | if ($this->db->query($sql)) |
| 3241 | 3495 | {
|
| 3242 | 3496 | return 1; |
| 3243 | - } |
|
| 3244 | - else |
|
| 3497 | + } else |
|
| 3245 | 3498 | {
|
| 3246 | 3499 | $this->error=$this->db->lasterror(); |
| 3247 | 3500 | $this->errors[]=$this->error; |
@@ -3270,17 +3523,31 @@ discard block |
||
| 3270 | 3523 | $this->db->begin(); |
| 3271 | 3524 | |
| 3272 | 3525 | $fieldstatus="fk_statut"; |
| 3273 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3274 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3275 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3276 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3277 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3278 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3526 | + if ($elementTable == 'facture_rec') { |
|
| 3527 | + $fieldstatus="suspended"; |
|
| 3528 | + } |
|
| 3529 | + if ($elementTable == 'mailing') { |
|
| 3530 | + $fieldstatus="statut"; |
|
| 3531 | + } |
|
| 3532 | + if ($elementTable == 'cronjob') { |
|
| 3533 | + $fieldstatus="status"; |
|
| 3534 | + } |
|
| 3535 | + if ($elementTable == 'user') { |
|
| 3536 | + $fieldstatus="statut"; |
|
| 3537 | + } |
|
| 3538 | + if ($elementTable == 'expensereport') { |
|
| 3539 | + $fieldstatus="fk_statut"; |
|
| 3540 | + } |
|
| 3541 | + if ($elementTable == 'commande_fournisseur_dispatch') { |
|
| 3542 | + $fieldstatus="status"; |
|
| 3543 | + } |
|
| 3279 | 3544 | |
| 3280 | 3545 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
| 3281 | 3546 | $sql.= " SET ".$fieldstatus." = ".$status; |
| 3282 | 3547 | // If status = 1 = validated, update also fk_user_valid |
| 3283 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3548 | + if ($status == 1 && $elementTable == 'expensereport') { |
|
| 3549 | + $sql.=", fk_user_valid = ".$user->id; |
|
| 3550 | + } |
|
| 3284 | 3551 | $sql.= " WHERE rowid=".$elementId; |
| 3285 | 3552 | |
| 3286 | 3553 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
@@ -3291,12 +3558,27 @@ discard block |
||
| 3291 | 3558 | // Try autoset of trigkey |
| 3292 | 3559 | if (empty($trigkey)) |
| 3293 | 3560 | {
|
| 3294 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3295 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3296 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3297 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3298 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3299 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3561 | + if ($this->element == 'supplier_proposal' && $status == 2) { |
|
| 3562 | + $trigkey='SUPPLIER_PROPOSAL_SIGN'; |
|
| 3563 | + } |
|
| 3564 | + // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3565 | + if ($this->element == 'supplier_proposal' && $status == 3) { |
|
| 3566 | + $trigkey='SUPPLIER_PROPOSAL_REFUSE'; |
|
| 3567 | + } |
|
| 3568 | + // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3569 | + if ($this->element == 'supplier_proposal' && $status == 4) { |
|
| 3570 | + $trigkey='SUPPLIER_PROPOSAL_CLOSE'; |
|
| 3571 | + } |
|
| 3572 | + // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3573 | + if ($this->element == 'fichinter' && $status == 3) { |
|
| 3574 | + $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3575 | + } |
|
| 3576 | + if ($this->element == 'fichinter' && $status == 2) { |
|
| 3577 | + $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3578 | + } |
|
| 3579 | + if ($this->element == 'fichinter' && $status == 1) { |
|
| 3580 | + $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3581 | + } |
|
| 3300 | 3582 | } |
| 3301 | 3583 | |
| 3302 | 3584 | if ($trigkey) |
@@ -3315,22 +3597,22 @@ discard block |
||
| 3315 | 3597 | {
|
| 3316 | 3598 | $this->db->commit(); |
| 3317 | 3599 | |
| 3318 | - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3600 | + if (empty($savElementId)) { |
|
| 3601 | + // If the element we update was $this (so $elementId is null) |
|
| 3319 | 3602 | {
|
| 3320 | - $this->statut = $status; |
|
| 3603 | + $this->statut = $status; |
|
| 3604 | + } |
|
| 3321 | 3605 | $this->status = $status; |
| 3322 | 3606 | } |
| 3323 | 3607 | |
| 3324 | 3608 | return 1; |
| 3325 | - } |
|
| 3326 | - else |
|
| 3609 | + } else |
|
| 3327 | 3610 | {
|
| 3328 | 3611 | $this->db->rollback(); |
| 3329 | 3612 | dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
| 3330 | 3613 | return -1; |
| 3331 | 3614 | } |
| 3332 | - } |
|
| 3333 | - else |
|
| 3615 | + } else |
|
| 3334 | 3616 | {
|
| 3335 | 3617 | $this->error=$this->db->lasterror(); |
| 3336 | 3618 | $this->db->rollback(); |
@@ -3350,8 +3632,13 @@ discard block |
||
| 3350 | 3632 | {
|
| 3351 | 3633 | global $conf; |
| 3352 | 3634 | |
| 3353 | - if (empty($id) && empty($ref)) return 0; |
|
| 3354 | - if (! empty($conf->global->MAIN_DISABLE_CANVAS)) return 0; // To increase speed. Not enabled by default. |
|
| 3635 | + if (empty($id) && empty($ref)) { |
|
| 3636 | + return 0; |
|
| 3637 | + } |
|
| 3638 | + if (! empty($conf->global->MAIN_DISABLE_CANVAS)) { |
|
| 3639 | + return 0; |
|
| 3640 | + } |
|
| 3641 | + // To increase speed. Not enabled by default. |
|
| 3355 | 3642 | |
| 3356 | 3643 | // Clean parameters |
| 3357 | 3644 | $ref = trim($ref); |
@@ -3359,8 +3646,12 @@ discard block |
||
| 3359 | 3646 | $sql = "SELECT rowid, canvas"; |
| 3360 | 3647 | $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
| 3361 | 3648 | $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
| 3362 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3363 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3649 | + if (! empty($id)) { |
|
| 3650 | + $sql.= " AND rowid = ".$id; |
|
| 3651 | + } |
|
| 3652 | + if (! empty($ref)) { |
|
| 3653 | + $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3654 | + } |
|
| 3364 | 3655 | |
| 3365 | 3656 | $resql = $this->db->query($sql); |
| 3366 | 3657 | if ($resql) |
@@ -3370,10 +3661,10 @@ discard block |
||
| 3370 | 3661 | {
|
| 3371 | 3662 | $this->canvas = $obj->canvas; |
| 3372 | 3663 | return 1; |
| 3373 | - } |
|
| 3374 | - else return 0; |
|
| 3375 | - } |
|
| 3376 | - else |
|
| 3664 | + } else { |
|
| 3665 | + return 0; |
|
| 3666 | + } |
|
| 3667 | + } else |
|
| 3377 | 3668 | {
|
| 3378 | 3669 | dol_print_error($this->db); |
| 3379 | 3670 | return -1; |
@@ -3410,7 +3701,9 @@ discard block |
||
| 3410 | 3701 | {
|
| 3411 | 3702 | global $langs; |
| 3412 | 3703 | |
| 3413 | - if (empty($id)) $id=$this->id; |
|
| 3704 | + if (empty($id)) { |
|
| 3705 | + $id=$this->id; |
|
| 3706 | + } |
|
| 3414 | 3707 | |
| 3415 | 3708 | // Check parameters |
| 3416 | 3709 | if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
@@ -3444,18 +3737,18 @@ discard block |
||
| 3444 | 3737 | $langs->load("errors");
|
| 3445 | 3738 | //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
| 3446 | 3739 | $haschild += $obj->nb; |
| 3447 | - if (is_numeric($elementname)) // old usage |
|
| 3740 | + if (is_numeric($elementname)) { |
|
| 3741 | + // old usage |
|
| 3448 | 3742 | {
|
| 3449 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3450 | - } |
|
| 3451 | - else // new usage: $elementname=Translation key |
|
| 3743 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
| 3744 | + } |
|
| 3745 | + } else // new usage: $elementname=Translation key |
|
| 3452 | 3746 | {
|
| 3453 | 3747 | $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
| 3454 | 3748 | } |
| 3455 | 3749 | break; // We found at least one, we stop here |
| 3456 | 3750 | } |
| 3457 | - } |
|
| 3458 | - else |
|
| 3751 | + } else |
|
| 3459 | 3752 | {
|
| 3460 | 3753 | $this->errors[]=$this->db->lasterror(); |
| 3461 | 3754 | return -1; |
@@ -3465,8 +3758,9 @@ discard block |
||
| 3465 | 3758 | {
|
| 3466 | 3759 | $this->errors[]="ErrorRecordHasChildren"; |
| 3467 | 3760 | return $haschild; |
| 3468 | - } |
|
| 3469 | - else return 0; |
|
| 3761 | + } else { |
|
| 3762 | + return 0; |
|
| 3763 | + } |
|
| 3470 | 3764 | } |
| 3471 | 3765 | |
| 3472 | 3766 | /** |
@@ -3482,12 +3776,24 @@ discard block |
||
| 3482 | 3776 | foreach($this->lines as $key => $val) |
| 3483 | 3777 | {
|
| 3484 | 3778 | $qualified=0; |
| 3485 | - if ($predefined == -1) $qualified=1; |
|
| 3486 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3487 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3488 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3489 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3490 | - if ($qualified) $nb++; |
|
| 3779 | + if ($predefined == -1) { |
|
| 3780 | + $qualified=1; |
|
| 3781 | + } |
|
| 3782 | + if ($predefined == 1 && $val->fk_product > 0) { |
|
| 3783 | + $qualified=1; |
|
| 3784 | + } |
|
| 3785 | + if ($predefined == 0 && $val->fk_product <= 0) { |
|
| 3786 | + $qualified=1; |
|
| 3787 | + } |
|
| 3788 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) { |
|
| 3789 | + $qualified=1; |
|
| 3790 | + } |
|
| 3791 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) { |
|
| 3792 | + $qualified=1; |
|
| 3793 | + } |
|
| 3794 | + if ($qualified) { |
|
| 3795 | + $nb++; |
|
| 3796 | + } |
|
| 3491 | 3797 | } |
| 3492 | 3798 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
| 3493 | 3799 | return $nb; |
@@ -3551,16 +3857,24 @@ discard block |
||
| 3551 | 3857 | {
|
| 3552 | 3858 | if (isset($line->qty_asked)) |
| 3553 | 3859 | {
|
| 3554 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3860 | + if (empty($totalOrdered)) { |
|
| 3861 | + $totalOrdered=0; |
|
| 3862 | + } |
|
| 3863 | + // Avoid warning because $totalOrdered is '' |
|
| 3555 | 3864 | $totalOrdered+=$line->qty_asked; // defined for shipment only |
| 3556 | 3865 | } |
| 3557 | 3866 | if (isset($line->qty_shipped)) |
| 3558 | 3867 | {
|
| 3559 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3868 | + if (empty($totalToShip)) { |
|
| 3869 | + $totalToShip=0; |
|
| 3870 | + } |
|
| 3871 | + // Avoid warning because $totalToShip is '' |
|
| 3560 | 3872 | $totalToShip+=$line->qty_shipped; // defined for shipment only |
| 3561 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3873 | + } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3562 | 3874 | {
|
| 3563 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3875 | + if (empty($totalToShip)) { |
|
| 3876 | + $totalToShip=0; |
|
| 3877 | + } |
|
| 3564 | 3878 | $totalToShip+=$line->qty; // defined for reception only |
| 3565 | 3879 | } |
| 3566 | 3880 | |
@@ -3568,8 +3882,7 @@ discard block |
||
| 3568 | 3882 | if ($this->element == 'shipping') {
|
| 3569 | 3883 | // for shipments |
| 3570 | 3884 | $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
| 3571 | - } |
|
| 3572 | - else {
|
|
| 3885 | + } else {
|
|
| 3573 | 3886 | $qty = $line->qty ? $line->qty : 0; |
| 3574 | 3887 | } |
| 3575 | 3888 | |
@@ -3585,19 +3898,30 @@ discard block |
||
| 3585 | 3898 | |
| 3586 | 3899 | $weightUnit=0; |
| 3587 | 3900 | $volumeUnit=0; |
| 3588 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3589 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3590 | - |
|
| 3591 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3592 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3901 | + if (! empty($weight_units)) { |
|
| 3902 | + $weightUnit = $weight_units; |
|
| 3903 | + } |
|
| 3904 | + if (! empty($volume_units)) { |
|
| 3905 | + $volumeUnit = $volume_units; |
|
| 3906 | + } |
|
| 3907 | + |
|
| 3908 | + if (empty($totalWeight)) { |
|
| 3909 | + $totalWeight=0; |
|
| 3910 | + } |
|
| 3911 | + // Avoid warning because $totalWeight is '' |
|
| 3912 | + if (empty($totalVolume)) { |
|
| 3913 | + $totalVolume=0; |
|
| 3914 | + } |
|
| 3915 | + // Avoid warning because $totalVolume is '' |
|
| 3593 | 3916 | |
| 3594 | 3917 | //var_dump($line->volume_units); |
| 3595 | - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3918 | + if ($weight_units < 50) { |
|
| 3919 | + // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3596 | 3920 | {
|
| 3597 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3921 | + $trueWeightUnit=pow(10, $weightUnit); |
|
| 3922 | + } |
|
| 3598 | 3923 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3599 | - } |
|
| 3600 | - else {
|
|
| 3924 | + } else {
|
|
| 3601 | 3925 | if ($weight_units == 99) {
|
| 3602 | 3926 | // conversion 1 Pound = 0.45359237 KG |
| 3603 | 3927 | $trueWeightUnit = 0.45359237; |
@@ -3606,18 +3930,20 @@ discard block |
||
| 3606 | 3930 | // conversion 1 Ounce = 0.0283495 KG |
| 3607 | 3931 | $trueWeightUnit = 0.0283495; |
| 3608 | 3932 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3609 | - } |
|
| 3610 | - else |
|
| 3611 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3933 | + } else { |
|
| 3934 | + $totalWeight += $weight * $qty; |
|
| 3935 | + } |
|
| 3936 | + // This may be wrong if we mix different units |
|
| 3612 | 3937 | } |
| 3613 | - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3938 | + if ($volume_units < 50) { |
|
| 3939 | + // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3614 | 3940 | {
|
| 3615 | 3941 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
| 3616 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3942 | + $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3943 | + } |
|
| 3617 | 3944 | //print $line->volume; |
| 3618 | 3945 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
| 3619 | - } |
|
| 3620 | - else |
|
| 3946 | + } else |
|
| 3621 | 3947 | {
|
| 3622 | 3948 | $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
| 3623 | 3949 | } |
@@ -3649,8 +3975,7 @@ discard block |
||
| 3649 | 3975 | $this->error=$this->db->lasterror(); |
| 3650 | 3976 | $this->db->rollback(); |
| 3651 | 3977 | return -1; |
| 3652 | - } |
|
| 3653 | - else |
|
| 3978 | + } else |
|
| 3654 | 3979 | {
|
| 3655 | 3980 | $this->db->commit(); |
| 3656 | 3981 | return 1; |
@@ -3702,13 +4027,11 @@ discard block |
||
| 3702 | 4027 | {
|
| 3703 | 4028 | $res = $this->db->fetch_object($resql); |
| 3704 | 4029 | return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
| 3705 | - } |
|
| 3706 | - else |
|
| 4030 | + } else |
|
| 3707 | 4031 | {
|
| 3708 | 4032 | return ''; |
| 3709 | 4033 | } |
| 3710 | - } |
|
| 3711 | - else |
|
| 4034 | + } else |
|
| 3712 | 4035 | {
|
| 3713 | 4036 | $this->errors[] = $this->db->lasterror(); |
| 3714 | 4037 | return false; |
@@ -3745,14 +4068,14 @@ discard block |
||
| 3745 | 4068 | $this->libelle_incoterms = $obj->libelle; |
| 3746 | 4069 | } |
| 3747 | 4070 | return 1; |
| 3748 | - } |
|
| 3749 | - else |
|
| 4071 | + } else |
|
| 3750 | 4072 | {
|
| 3751 | 4073 | $this->errors[] = $this->db->lasterror(); |
| 3752 | 4074 | return -1; |
| 3753 | 4075 | } |
| 3754 | - } |
|
| 3755 | - else return -1; |
|
| 4076 | + } else { |
|
| 4077 | + return -1; |
|
| 4078 | + } |
|
| 3756 | 4079 | } |
| 3757 | 4080 | |
| 3758 | 4081 | |
@@ -3791,7 +4114,9 @@ discard block |
||
| 3791 | 4114 | } else {
|
| 3792 | 4115 | $res=include $tpl; // for debug |
| 3793 | 4116 | } |
| 3794 | - if ($res) break; |
|
| 4117 | + if ($res) { |
|
| 4118 | + break; |
|
| 4119 | + } |
|
| 3795 | 4120 | } |
| 3796 | 4121 | } |
| 3797 | 4122 | |
@@ -3821,7 +4146,9 @@ discard block |
||
| 3821 | 4146 | |
| 3822 | 4147 | // Define usemargins |
| 3823 | 4148 | $usemargins=0; |
| 3824 | - if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1;
|
|
| 4149 | + if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) { |
|
| 4150 | + $usemargins=1; |
|
| 4151 | + } |
|
| 3825 | 4152 | |
| 3826 | 4153 | $num = count($this->lines); |
| 3827 | 4154 | |
@@ -3840,7 +4167,9 @@ discard block |
||
| 3840 | 4167 | print '<tr class="liste_titre nodrag nodrop">'; |
| 3841 | 4168 | |
| 3842 | 4169 | // Adds a line numbering column |
| 3843 | - if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 4170 | + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { |
|
| 4171 | + print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 4172 | + } |
|
| 3844 | 4173 | |
| 3845 | 4174 | // Description |
| 3846 | 4175 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
@@ -3857,9 +4186,13 @@ discard block |
||
| 3857 | 4186 | print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
|
| 3858 | 4187 | |
| 3859 | 4188 | // Multicurrency |
| 3860 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>';
|
|
| 4189 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { |
|
| 4190 | + print '<td class="linecoluht_currency" align="right" width="80">'.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).'</td>'; |
|
| 4191 | + } |
|
| 3861 | 4192 | |
| 3862 | - if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
|
|
| 4193 | + if ($inputalsopricewithtax) { |
|
| 4194 | + print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
| 4195 | + } |
|
| 3863 | 4196 | |
| 3864 | 4197 | // Qty |
| 3865 | 4198 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
@@ -3880,25 +4213,32 @@ discard block |
||
| 3880 | 4213 | {
|
| 3881 | 4214 | if (!empty($user->rights->margins->creer)) |
| 3882 | 4215 | {
|
| 3883 | - if ($conf->global->MARGIN_TYPE == "1") |
|
| 3884 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
|
|
| 3885 | - else |
|
| 3886 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
|
| 4216 | + if ($conf->global->MARGIN_TYPE == "1") { |
|
| 4217 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 4218 | + } else { |
|
| 4219 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
| 4220 | + } |
|
| 3887 | 4221 | } |
| 3888 | 4222 | |
| 3889 | - if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3890 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
|
| 3891 | - if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3892 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
|
| 4223 | + if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { |
|
| 4224 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
| 4225 | + } |
|
| 4226 | + if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) { |
|
| 4227 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
| 4228 | + } |
|
| 3893 | 4229 | } |
| 3894 | 4230 | |
| 3895 | 4231 | // Total HT |
| 3896 | 4232 | print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
|
| 3897 | 4233 | |
| 3898 | 4234 | // Multicurrency |
| 3899 | - if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>';
|
|
| 4235 | + if (!empty($conf->multicurrency->enabled) && $this->multicurrency_code != $conf->currency) { |
|
| 4236 | + print '<td class="linecoltotalht_currency" align="right">'.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).'</td>'; |
|
| 4237 | + } |
|
| 3900 | 4238 | |
| 3901 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
|
| 4239 | + if ($outputalsopricetotalwithtax) { |
|
| 4240 | + print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
| 4241 | + } |
|
| 3902 | 4242 | |
| 3903 | 4243 | print '<td class="linecoledit"></td>'; // No width to allow autodim |
| 3904 | 4244 | |
@@ -3928,14 +4268,15 @@ discard block |
||
| 3928 | 4268 | $line->fetch_optionals(); |
| 3929 | 4269 | |
| 3930 | 4270 | //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
| 3931 | - if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 4271 | + if (is_object($hookmanager)) { |
|
| 4272 | + // Old code is commented on preceding line. |
|
| 3932 | 4273 | {
|
| 3933 | 4274 | if (empty($line->fk_parent_line)) |
| 3934 | 4275 | {
|
| 3935 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 4276 | + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 4277 | + } |
|
| 3936 | 4278 | $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
| 3937 | - } |
|
| 3938 | - else |
|
| 4279 | + } else |
|
| 3939 | 4280 | {
|
| 3940 | 4281 | $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);
|
| 3941 | 4282 | $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
@@ -3982,8 +4323,14 @@ discard block |
||
| 3982 | 4323 | // Show product and description |
| 3983 | 4324 | $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
| 3984 | 4325 | // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
| 3985 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3986 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 4326 | + if (! empty($line->date_start)) { |
|
| 4327 | + $type=1; |
|
| 4328 | + } |
|
| 4329 | + // deprecated |
|
| 4330 | + if (! empty($line->date_end)) { |
|
| 4331 | + $type=1; |
|
| 4332 | + } |
|
| 4333 | + // deprecated |
|
| 3987 | 4334 | |
| 3988 | 4335 | // Ligne en mode visu |
| 3989 | 4336 | if ($action != 'editline' || $selected != $line->id) |
@@ -4012,8 +4359,13 @@ discard block |
||
| 4012 | 4359 | |
| 4013 | 4360 | $outputlangs = $langs; |
| 4014 | 4361 | $newlang=''; |
| 4015 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4016 | - if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer |
|
| 4362 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
| 4363 | + $newlang=GETPOST('lang_id','aZ09'); |
|
| 4364 | + } |
|
| 4365 | + if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) { |
|
| 4366 | + $newlang=$this->thirdparty->default_lang; |
|
| 4367 | + } |
|
| 4368 | + // For language to language of customer |
|
| 4017 | 4369 | if (! empty($newlang)) |
| 4018 | 4370 | {
|
| 4019 | 4371 | $outputlangs = new Translate("",$conf);
|
@@ -4021,8 +4373,7 @@ discard block |
||
| 4021 | 4373 | } |
| 4022 | 4374 | |
| 4023 | 4375 | $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
| 4024 | - } |
|
| 4025 | - else |
|
| 4376 | + } else |
|
| 4026 | 4377 | {
|
| 4027 | 4378 | $label = $line->product_label; |
| 4028 | 4379 | } |
@@ -4044,7 +4395,9 @@ discard block |
||
| 4044 | 4395 | } else {
|
| 4045 | 4396 | $res=include $tpl; // for debug |
| 4046 | 4397 | } |
| 4047 | - if ($res) break; |
|
| 4398 | + if ($res) { |
|
| 4399 | + break; |
|
| 4400 | + } |
|
| 4048 | 4401 | } |
| 4049 | 4402 | } |
| 4050 | 4403 | |
@@ -4067,7 +4420,9 @@ discard block |
||
| 4067 | 4420 | } else {
|
| 4068 | 4421 | $res=include $tpl; // for debug |
| 4069 | 4422 | } |
| 4070 | - if ($res) break; |
|
| 4423 | + if ($res) { |
|
| 4424 | + break; |
|
| 4425 | + } |
|
| 4071 | 4426 | } |
| 4072 | 4427 | } |
| 4073 | 4428 | } |
@@ -4094,7 +4449,9 @@ discard block |
||
| 4094 | 4449 | print '<td>'.$langs->trans('Description').'</td>';
|
| 4095 | 4450 | print '<td align="right">'.$langs->trans('VATRate').'</td>';
|
| 4096 | 4451 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
| 4097 | - if (!empty($conf->multicurrency->enabled)) print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>';
|
|
| 4452 | + if (!empty($conf->multicurrency->enabled)) { |
|
| 4453 | + print '<td align="right">'.$langs->trans('PriceUHTCurrency').'</td>'; |
|
| 4454 | + } |
|
| 4098 | 4455 | print '<td align="right">'.$langs->trans('Qty').'</td>';
|
| 4099 | 4456 | if($conf->global->PRODUCT_USE_UNITS) |
| 4100 | 4457 | {
|
@@ -4117,8 +4474,7 @@ discard block |
||
| 4117 | 4474 | $action=''; |
| 4118 | 4475 | $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
| 4119 | 4476 | } |
| 4120 | - } |
|
| 4121 | - else |
|
| 4477 | + } else |
|
| 4122 | 4478 | {
|
| 4123 | 4479 | $this->printOriginLine($line, $var, $restrictlist); |
| 4124 | 4480 | } |
@@ -4147,32 +4503,37 @@ discard block |
||
| 4147 | 4503 | if (!empty($line->date_start)) |
| 4148 | 4504 | {
|
| 4149 | 4505 | $date_start=$line->date_start; |
| 4150 | - } |
|
| 4151 | - else |
|
| 4506 | + } else |
|
| 4152 | 4507 | {
|
| 4153 | 4508 | $date_start=$line->date_debut_prevue; |
| 4154 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4509 | + if ($line->date_debut_reel) { |
|
| 4510 | + $date_start=$line->date_debut_reel; |
|
| 4511 | + } |
|
| 4155 | 4512 | } |
| 4156 | 4513 | if (!empty($line->date_end)) |
| 4157 | 4514 | {
|
| 4158 | 4515 | $date_end=$line->date_end; |
| 4159 | - } |
|
| 4160 | - else |
|
| 4516 | + } else |
|
| 4161 | 4517 | {
|
| 4162 | 4518 | $date_end=$line->date_fin_prevue; |
| 4163 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4519 | + if ($line->date_fin_reel) { |
|
| 4520 | + $date_end=$line->date_fin_reel; |
|
| 4521 | + } |
|
| 4164 | 4522 | } |
| 4165 | 4523 | |
| 4166 | 4524 | $this->tpl['label'] = ''; |
| 4167 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4525 | + if (! empty($line->fk_parent_line)) { |
|
| 4526 | + $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
| 4527 | + } |
|
| 4168 | 4528 | |
| 4169 | - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4529 | + if (($line->info_bits & 2) == 2) { |
|
| 4530 | + // TODO Not sure this is used for source object |
|
| 4170 | 4531 | {
|
| 4171 | - $discount=new DiscountAbsolute($this->db); |
|
| 4532 | + $discount=new DiscountAbsolute($this->db); |
|
| 4533 | + } |
|
| 4172 | 4534 | $discount->fk_soc = $this->socid; |
| 4173 | 4535 | $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
| 4174 | - } |
|
| 4175 | - else if (! empty($line->fk_product)) |
|
| 4536 | + } else if (! empty($line->fk_product)) |
|
| 4176 | 4537 | {
|
| 4177 | 4538 | $productstatic = new Product($this->db); |
| 4178 | 4539 | $productstatic->id = $line->fk_product; |
@@ -4190,13 +4551,12 @@ discard block |
||
| 4190 | 4551 | {
|
| 4191 | 4552 | $this->tpl['label'].= get_date_range($date_start,$date_end); |
| 4192 | 4553 | } |
| 4193 | - } |
|
| 4194 | - else |
|
| 4554 | + } else |
|
| 4195 | 4555 | {
|
| 4196 | 4556 | $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
| 4197 | 4557 | if (!empty($line->desc)) {
|
| 4198 | 4558 | $this->tpl['label'].=$line->desc; |
| 4199 | - }else {
|
|
| 4559 | + } else {
|
|
| 4200 | 4560 | $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
| 4201 | 4561 | } |
| 4202 | 4562 | |
@@ -4209,36 +4569,35 @@ discard block |
||
| 4209 | 4569 | |
| 4210 | 4570 | if (! empty($line->desc)) |
| 4211 | 4571 | {
|
| 4212 | - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4572 | + if ($line->desc == '(CREDIT_NOTE)') { |
|
| 4573 | + // TODO Not sure this is used for source object |
|
| 4213 | 4574 | {
|
| 4214 | - $discount=new DiscountAbsolute($this->db); |
|
| 4575 | + $discount=new DiscountAbsolute($this->db); |
|
| 4576 | + } |
|
| 4215 | 4577 | $discount->fetch($line->fk_remise_except); |
| 4216 | 4578 | $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
| 4217 | - } |
|
| 4218 | - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4579 | + } elseif ($line->desc == '(DEPOSIT)') { |
|
| 4580 | + // TODO Not sure this is used for source object |
|
| 4219 | 4581 | {
|
| 4220 | - $discount=new DiscountAbsolute($this->db); |
|
| 4582 | + $discount=new DiscountAbsolute($this->db); |
|
| 4583 | + } |
|
| 4221 | 4584 | $discount->fetch($line->fk_remise_except); |
| 4222 | 4585 | $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
| 4223 | - } |
|
| 4224 | - elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4586 | + } elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4225 | 4587 | {
|
| 4226 | 4588 | $discount=new DiscountAbsolute($this->db); |
| 4227 | 4589 | $discount->fetch($line->fk_remise_except); |
| 4228 | 4590 | $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
| 4229 | - } |
|
| 4230 | - elseif ($line->desc == '(EXCESS PAID)') |
|
| 4591 | + } elseif ($line->desc == '(EXCESS PAID)') |
|
| 4231 | 4592 | {
|
| 4232 | 4593 | $discount=new DiscountAbsolute($this->db); |
| 4233 | 4594 | $discount->fetch($line->fk_remise_except); |
| 4234 | 4595 | $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
| 4235 | - } |
|
| 4236 | - else |
|
| 4596 | + } else |
|
| 4237 | 4597 | {
|
| 4238 | 4598 | $this->tpl['description'] = dol_trunc($line->desc,60); |
| 4239 | 4599 | } |
| 4240 | - } |
|
| 4241 | - else |
|
| 4600 | + } else |
|
| 4242 | 4601 | {
|
| 4243 | 4602 | $this->tpl['description'] = ' '; |
| 4244 | 4603 | } |
@@ -4246,17 +4605,23 @@ discard block |
||
| 4246 | 4605 | // VAT Rate |
| 4247 | 4606 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
| 4248 | 4607 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
| 4249 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 4608 | + if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) { |
|
| 4609 | + $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
| 4610 | + } |
|
| 4250 | 4611 | |
| 4251 | 4612 | $this->tpl['price'] = price($line->subprice); |
| 4252 | 4613 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
| 4253 | 4614 | $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
| 4254 | - if ($conf->global->PRODUCT_USE_UNITS) $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
|
|
| 4615 | + if ($conf->global->PRODUCT_USE_UNITS) { |
|
| 4616 | + $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); |
|
| 4617 | + } |
|
| 4255 | 4618 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
| 4256 | 4619 | |
| 4257 | 4620 | // Is the line strike or not |
| 4258 | 4621 | $this->tpl['strike']=0; |
| 4259 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4622 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) { |
|
| 4623 | + $this->tpl['strike']=1; |
|
| 4624 | + } |
|
| 4260 | 4625 | |
| 4261 | 4626 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4262 | 4627 | // Use global variables + $dateSelector + $seller and $buyer |
@@ -4269,7 +4634,9 @@ discard block |
||
| 4269 | 4634 | } else {
|
| 4270 | 4635 | $res=include $tpl; // for debug |
| 4271 | 4636 | } |
| 4272 | - if ($res) break; |
|
| 4637 | + if ($res) { |
|
| 4638 | + break; |
|
| 4639 | + } |
|
| 4273 | 4640 | } |
| 4274 | 4641 | } |
| 4275 | 4642 | |
@@ -4311,8 +4678,7 @@ discard block |
||
| 4311 | 4678 | {
|
| 4312 | 4679 | $this->db->commit(); |
| 4313 | 4680 | return 1; |
| 4314 | - } |
|
| 4315 | - else |
|
| 4681 | + } else |
|
| 4316 | 4682 | {
|
| 4317 | 4683 | $this->error=$this->db->lasterror(); |
| 4318 | 4684 | $this->db->rollback(); |
@@ -4347,8 +4713,7 @@ discard block |
||
| 4347 | 4713 | $this->error=$this->db->lasterror(); |
| 4348 | 4714 | $this->db->rollback(); |
| 4349 | 4715 | return -1; |
| 4350 | - } |
|
| 4351 | - else |
|
| 4716 | + } else |
|
| 4352 | 4717 | {
|
| 4353 | 4718 | if (! $notrigger) |
| 4354 | 4719 | {
|
@@ -4415,13 +4780,20 @@ discard block |
||
| 4415 | 4780 | // Search template files |
| 4416 | 4781 | $file=''; $classname=''; $filefound=0; |
| 4417 | 4782 | $dirmodels=array('/');
|
| 4418 | - if (is_array($conf->modules_parts['models'])) $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4783 | + if (is_array($conf->modules_parts['models'])) { |
|
| 4784 | + $dirmodels=array_merge($dirmodels,$conf->modules_parts['models']); |
|
| 4785 | + } |
|
| 4419 | 4786 | foreach($dirmodels as $reldir) |
| 4420 | 4787 | {
|
| 4421 | 4788 | foreach(array('doc','pdf') as $prefix)
|
| 4422 | 4789 | {
|
| 4423 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4424 | - else $file = $prefix."_".$modele.".modules.php"; |
|
| 4790 | + if (in_array(get_class($this), array('Adherent'))) { |
|
| 4791 | + $file = $prefix."_".$modele.".class.php"; |
|
| 4792 | + } |
|
| 4793 | + // Member module use prefix_module.class.php |
|
| 4794 | + else { |
|
| 4795 | + $file = $prefix."_".$modele.".modules.php"; |
|
| 4796 | + } |
|
| 4425 | 4797 | |
| 4426 | 4798 | // On verifie l'emplacement du modele |
| 4427 | 4799 | $file=dol_buildpath($reldir.$modelspath.$file,0); |
@@ -4432,7 +4804,9 @@ discard block |
||
| 4432 | 4804 | break; |
| 4433 | 4805 | } |
| 4434 | 4806 | } |
| 4435 | - if ($filefound) break; |
|
| 4807 | + if ($filefound) { |
|
| 4808 | + break; |
|
| 4809 | + } |
|
| 4436 | 4810 | } |
| 4437 | 4811 | |
| 4438 | 4812 | // If generator was found |
@@ -4464,7 +4838,9 @@ discard block |
||
| 4464 | 4838 | if (is_dir($tmpdir)) |
| 4465 | 4839 | {
|
| 4466 | 4840 | $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
| 4467 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4841 | + if (count($tmpfiles)) { |
|
| 4842 | + $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4843 | + } |
|
| 4468 | 4844 | } |
| 4469 | 4845 | } |
| 4470 | 4846 | |
@@ -4502,8 +4878,7 @@ discard block |
||
| 4502 | 4878 | {
|
| 4503 | 4879 | $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
| 4504 | 4880 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
| 4505 | - } |
|
| 4506 | - else |
|
| 4881 | + } else |
|
| 4507 | 4882 | {
|
| 4508 | 4883 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
| 4509 | 4884 | } |
@@ -4525,9 +4900,11 @@ discard block |
||
| 4525 | 4900 | $destfile = basename($destfull); |
| 4526 | 4901 | $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
| 4527 | 4902 | |
| 4528 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4903 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { |
|
| 4904 | + // If not a tmp dir |
|
| 4529 | 4905 | {
|
| 4530 | - $filename = basename($destfile); |
|
| 4906 | + $filename = basename($destfile); |
|
| 4907 | + } |
|
| 4531 | 4908 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
| 4532 | 4909 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
| 4533 | 4910 | |
@@ -4540,18 +4917,30 @@ discard block |
||
| 4540 | 4917 | if ($this->element == 'propal') |
| 4541 | 4918 | {
|
| 4542 | 4919 | $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
| 4543 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4544 | - if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4920 | + if ($useonlinesignature) { |
|
| 4921 | + $setsharekey=true; |
|
| 4922 | + } |
|
| 4923 | + if (! empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4924 | + $setsharekey=true; |
|
| 4925 | + } |
|
| 4545 | 4926 | } |
| 4546 | - if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4547 | - if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4548 | - if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) $setsharekey=true; |
|
| 4927 | + if ($this->element == 'commande' && ! empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4928 | + $setsharekey=true; |
|
| 4929 | + } |
|
| 4930 | + if ($this->element == 'facture' && ! empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4931 | + $setsharekey=true; |
|
| 4932 | + } |
|
| 4933 | + if ($this->element == 'bank_account' && ! empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4934 | + $setsharekey=true; |
|
| 4935 | + } |
|
| 4549 | 4936 | |
| 4550 | 4937 | if ($setsharekey) |
| 4551 | 4938 | {
|
| 4552 | - if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4939 | + if (empty($ecmfile->share)) { |
|
| 4940 | + // Because object not found or share not set yet |
|
| 4553 | 4941 | {
|
| 4554 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4942 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4943 | + } |
|
| 4555 | 4944 | $ecmfile->share = getRandomPassword(true); |
| 4556 | 4945 | } |
| 4557 | 4946 | } |
@@ -4568,8 +4957,7 @@ discard block |
||
| 4568 | 4957 | {
|
| 4569 | 4958 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 4570 | 4959 | } |
| 4571 | - } |
|
| 4572 | - else |
|
| 4960 | + } else |
|
| 4573 | 4961 | {
|
| 4574 | 4962 | $ecmfile->entity = $conf->entity; |
| 4575 | 4963 | $ecmfile->filepath = $rel_dir; |
@@ -4596,17 +4984,20 @@ discard block |
||
| 4596 | 4984 | |
| 4597 | 4985 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
| 4598 | 4986 | $update_main_doc_field=0; |
| 4599 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4987 | + if (! empty($obj->update_main_doc_field)) { |
|
| 4988 | + $update_main_doc_field=1; |
|
| 4989 | + } |
|
| 4600 | 4990 | if ($update_main_doc_field && ! empty($this->table_element)) |
| 4601 | 4991 | {
|
| 4602 | 4992 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
| 4603 | 4993 | $sql.= ' WHERE rowid = '.$this->id; |
| 4604 | 4994 | $resql = $this->db->query($sql); |
| 4605 | - if (! $resql) dol_print_error($this->db); |
|
| 4995 | + if (! $resql) { |
|
| 4996 | + dol_print_error($this->db); |
|
| 4997 | + } |
|
| 4606 | 4998 | } |
| 4607 | 4999 | } |
| 4608 | - } |
|
| 4609 | - else |
|
| 5000 | + } else |
|
| 4610 | 5001 | {
|
| 4611 | 5002 | dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING);
|
| 4612 | 5003 | } |
@@ -4615,15 +5006,13 @@ discard block |
||
| 4615 | 5006 | dol_meta_create($this); |
| 4616 | 5007 | |
| 4617 | 5008 | return 1; |
| 4618 | - } |
|
| 4619 | - else |
|
| 5009 | + } else |
|
| 4620 | 5010 | {
|
| 4621 | 5011 | $outputlangs->charset_output=$sav_charset_output; |
| 4622 | 5012 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
| 4623 | 5013 | return -1; |
| 4624 | 5014 | } |
| 4625 | - } |
|
| 4626 | - else |
|
| 5015 | + } else |
|
| 4627 | 5016 | {
|
| 4628 | 5017 | $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
| 4629 | 5018 | dol_print_error('',$this->error);
|
@@ -4679,13 +5068,21 @@ discard block |
||
| 4679 | 5068 | global $conf, $_POST; |
| 4680 | 5069 | |
| 4681 | 5070 | // If param here has been posted, we use this value first. |
| 4682 | - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 5071 | + if (isset($_POST[$fieldname])) { |
|
| 5072 | + return GETPOST($fieldname, 2); |
|
| 5073 | + } |
|
| 4683 | 5074 | |
| 4684 | - if (isset($alternatevalue)) return $alternatevalue; |
|
| 5075 | + if (isset($alternatevalue)) { |
|
| 5076 | + return $alternatevalue; |
|
| 5077 | + } |
|
| 4685 | 5078 | |
| 4686 | 5079 | $newelement=$this->element; |
| 4687 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4688 | - if ($newelement == 'commande') $newelement='order'; |
|
| 5080 | + if ($newelement == 'facture') { |
|
| 5081 | + $newelement='invoice'; |
|
| 5082 | + } |
|
| 5083 | + if ($newelement == 'commande') { |
|
| 5084 | + $newelement='order'; |
|
| 5085 | + } |
|
| 4689 | 5086 | if (empty($newelement)) |
| 4690 | 5087 | {
|
| 4691 | 5088 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
@@ -4694,7 +5091,9 @@ discard block |
||
| 4694 | 5091 | |
| 4695 | 5092 | $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
| 4696 | 5093 | //var_dump($keyforfieldname); |
| 4697 | - if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; |
|
| 5094 | + if (isset($conf->global->$keyforfieldname)) { |
|
| 5095 | + return $conf->global->$keyforfieldname; |
|
| 5096 | + } |
|
| 4698 | 5097 | |
| 4699 | 5098 | // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
| 4700 | 5099 | } |
@@ -4728,8 +5127,7 @@ discard block |
||
| 4728 | 5127 | if (!empty($this->errors)) |
| 4729 | 5128 | {
|
| 4730 | 5129 | $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. |
| 4731 | - } |
|
| 4732 | - else |
|
| 5130 | + } else |
|
| 4733 | 5131 | {
|
| 4734 | 5132 | $this->errors=$interface->errors; |
| 4735 | 5133 | } |
@@ -4753,7 +5151,9 @@ discard block |
||
| 4753 | 5151 | function fetch_optionals($rowid=null, $optionsArray=null) |
| 4754 | 5152 | {
|
| 4755 | 5153 | // phpcs:enable |
| 4756 | - if (empty($rowid)) $rowid=$this->id; |
|
| 5154 | + if (empty($rowid)) { |
|
| 5155 | + $rowid=$this->id; |
|
| 5156 | + } |
|
| 4757 | 5157 | |
| 4758 | 5158 | // To avoid SQL errors. Probably not the better solution though |
| 4759 | 5159 | if (!$this->table_element) {
|
@@ -4779,15 +5179,17 @@ discard block |
||
| 4779 | 5179 | $extrafields->fetch_name_optionals_label($this->table_element); |
| 4780 | 5180 | } |
| 4781 | 5181 | $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
| 4782 | - } |
|
| 4783 | - else |
|
| 5182 | + } else |
|
| 4784 | 5183 | {
|
| 4785 | 5184 | global $extrafields; |
| 4786 | 5185 | dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
|
| 4787 | 5186 | } |
| 4788 | 5187 | |
| 4789 | 5188 | $table_element = $this->table_element; |
| 4790 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5189 | + if ($table_element == 'categorie') { |
|
| 5190 | + $table_element = 'categories'; |
|
| 5191 | + } |
|
| 5192 | + // For compatibility |
|
| 4791 | 5193 | |
| 4792 | 5194 | // Request to get complementary values |
| 4793 | 5195 | if (is_array($optionsArray) && count($optionsArray) > 0) |
@@ -4823,8 +5225,7 @@ discard block |
||
| 4823 | 5225 | {
|
| 4824 | 5226 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
| 4825 | 5227 | $this->array_options["options_".$key]=$this->db->jdate($value); |
| 4826 | - } |
|
| 4827 | - else |
|
| 5228 | + } else |
|
| 4828 | 5229 | {
|
| 4829 | 5230 | $this->array_options["options_".$key]=$value; |
| 4830 | 5231 | } |
@@ -4836,10 +5237,12 @@ discard block |
||
| 4836 | 5237 | |
| 4837 | 5238 | $this->db->free($resql); |
| 4838 | 5239 | |
| 4839 | - if ($numrows) return $numrows; |
|
| 4840 | - else return 0; |
|
| 4841 | - } |
|
| 4842 | - else |
|
| 5240 | + if ($numrows) { |
|
| 5241 | + return $numrows; |
|
| 5242 | + } else { |
|
| 5243 | + return 0; |
|
| 5244 | + } |
|
| 5245 | + } else |
|
| 4843 | 5246 | {
|
| 4844 | 5247 | dol_print_error($this->db); |
| 4845 | 5248 | return -1; |
@@ -4858,7 +5261,10 @@ discard block |
||
| 4858 | 5261 | $this->db->begin(); |
| 4859 | 5262 | |
| 4860 | 5263 | $table_element = $this->table_element; |
| 4861 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5264 | + if ($table_element == 'categorie') { |
|
| 5265 | + $table_element = 'categories'; |
|
| 5266 | + } |
|
| 5267 | + // For compatibility |
|
| 4862 | 5268 | |
| 4863 | 5269 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 4864 | 5270 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
@@ -4868,8 +5274,7 @@ discard block |
||
| 4868 | 5274 | $this->error=$this->db->lasterror(); |
| 4869 | 5275 | $this->db->rollback(); |
| 4870 | 5276 | return -1; |
| 4871 | - } |
|
| 4872 | - else |
|
| 5277 | + } else |
|
| 4873 | 5278 | {
|
| 4874 | 5279 | $this->db->commit(); |
| 4875 | 5280 | return 1; |
@@ -4890,11 +5295,16 @@ discard block |
||
| 4890 | 5295 | {
|
| 4891 | 5296 | global $conf,$langs,$user; |
| 4892 | 5297 | |
| 4893 | - if (empty($userused)) $userused=$user; |
|
| 5298 | + if (empty($userused)) { |
|
| 5299 | + $userused=$user; |
|
| 5300 | + } |
|
| 4894 | 5301 | |
| 4895 | 5302 | $error=0; |
| 4896 | 5303 | |
| 4897 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5304 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 5305 | + return 0; |
|
| 5306 | + } |
|
| 5307 | + // For avoid conflicts if trigger used |
|
| 4898 | 5308 | |
| 4899 | 5309 | if (! empty($this->array_options)) |
| 4900 | 5310 | {
|
@@ -4907,10 +5317,13 @@ discard block |
||
| 4907 | 5317 | //Eliminate copied source object extra_fields that do not exist in target object |
| 4908 | 5318 | $new_array_options=array(); |
| 4909 | 5319 | foreach ($this->array_options as $key => $value) {
|
| 4910 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4911 | - $new_array_options[$key] = $value; |
|
| 4912 | - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 4913 | - $new_array_options['options_'.$key] = $value; |
|
| 5320 | + if (in_array(substr($key,8), array_keys($target_extrafields))) { |
|
| 5321 | + // We remove the 'options_' from $key for test |
|
| 5322 | + $new_array_options[$key] = $value; |
|
| 5323 | + } elseif (in_array($key, array_keys($target_extrafields))) { |
|
| 5324 | + // We test on $key that does not contains the 'options_' prefix |
|
| 5325 | + $new_array_options['options_'.$key] = $value; |
|
| 5326 | + } |
|
| 4914 | 5327 | } |
| 4915 | 5328 | |
| 4916 | 5329 | foreach($new_array_options as $key => $value) |
@@ -4924,8 +5337,12 @@ discard block |
||
| 4924 | 5337 | if ($attributeRequired) |
| 4925 | 5338 | {
|
| 4926 | 5339 | $mandatorypb=false; |
| 4927 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4928 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 5340 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') { |
|
| 5341 | + $mandatorypb=true; |
|
| 5342 | + } |
|
| 5343 | + if ($this->array_options[$key] === '') { |
|
| 5344 | + $mandatorypb=true; |
|
| 5345 | + } |
|
| 4929 | 5346 | if ($mandatorypb) |
| 4930 | 5347 | {
|
| 4931 | 5348 | dol_syslog($this->error); |
@@ -4944,8 +5361,7 @@ discard block |
||
| 4944 | 5361 | {
|
| 4945 | 5362 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
| 4946 | 5363 | return -1; |
| 4947 | - } |
|
| 4948 | - elseif ($value=='') |
|
| 5364 | + } elseif ($value=='') |
|
| 4949 | 5365 | {
|
| 4950 | 5366 | $new_array_options[$key] = null; |
| 4951 | 5367 | } |
@@ -4957,8 +5373,7 @@ discard block |
||
| 4957 | 5373 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
| 4958 | 5374 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
| 4959 | 5375 | return -1; |
| 4960 | - } |
|
| 4961 | - elseif ($value=='') |
|
| 5376 | + } elseif ($value=='') |
|
| 4962 | 5377 | {
|
| 4963 | 5378 | $new_array_options[$key] = null; |
| 4964 | 5379 | } |
@@ -4983,27 +5398,27 @@ discard block |
||
| 4983 | 5398 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
| 4984 | 5399 | //var_dump($action); |
| 4985 | 5400 | //var_dump($this->oldcopy);exit; |
| 4986 | - if (is_object($this->oldcopy)) // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 5401 | + if (is_object($this->oldcopy)) { |
|
| 5402 | + // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 4987 | 5403 | {
|
| 4988 | 5404 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
| 4989 | 5405 | 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. |
| 4990 | 5406 | {
|
| 4991 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 4992 | - } |
|
| 4993 | - else |
|
| 5407 | + $new_array_options[$key] = $this->array_options[$key]; |
|
| 5408 | + } |
|
| 5409 | + // Value is kept |
|
| 5410 | + } else |
|
| 4994 | 5411 | {
|
| 4995 | 5412 | // var_dump($algo); |
| 4996 | 5413 | $newvalue = dol_hash($this->array_options[$key], $algo); |
| 4997 | 5414 | $new_array_options[$key] = $newvalue; |
| 4998 | 5415 | } |
| 4999 | - } |
|
| 5000 | - else |
|
| 5416 | + } else |
|
| 5001 | 5417 | {
|
| 5002 | 5418 | $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
| 5003 | 5419 | } |
| 5004 | 5420 | } |
| 5005 | - } |
|
| 5006 | - else // Common usage |
|
| 5421 | + } else // Common usage |
|
| 5007 | 5422 | {
|
| 5008 | 5423 | $new_array_options[$key] = $this->array_options[$key]; |
| 5009 | 5424 | } |
@@ -5029,26 +5444,30 @@ discard block |
||
| 5029 | 5444 | dol_include_once($InfoFieldList[1]); |
| 5030 | 5445 | if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
| 5031 | 5446 | {
|
| 5032 | - if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5447 | + if ($value == '-1') { |
|
| 5448 | + // -1 is key for no defined in combo list of objects |
|
| 5033 | 5449 | {
|
| 5034 | - $new_array_options[$key]=''; |
|
| 5035 | - } |
|
| 5036 | - elseif ($value) |
|
| 5450 | + $new_array_options[$key]=''; |
|
| 5451 | + } |
|
| 5452 | + } elseif ($value) |
|
| 5037 | 5453 | {
|
| 5038 | 5454 | $object = new $InfoFieldList[0]($this->db); |
| 5039 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5040 | - else $res=$object->fetch('',$value);
|
|
| 5041 | - |
|
| 5042 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5043 | - else |
|
| 5455 | + if (is_numeric($value)) { |
|
| 5456 | + $res=$object->fetch($value); |
|
| 5457 | + } else { |
|
| 5458 | + $res=$object->fetch('',$value); |
|
| 5459 | + } |
|
| 5460 | + |
|
| 5461 | + if ($res > 0) { |
|
| 5462 | + $new_array_options[$key]=$object->id; |
|
| 5463 | + } else |
|
| 5044 | 5464 | {
|
| 5045 | 5465 | $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
| 5046 | 5466 | $this->db->rollback(); |
| 5047 | 5467 | return -1; |
| 5048 | 5468 | } |
| 5049 | 5469 | } |
| 5050 | - } |
|
| 5051 | - else |
|
| 5470 | + } else |
|
| 5052 | 5471 | {
|
| 5053 | 5472 | dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
| 5054 | 5473 | } |
@@ -5059,7 +5478,10 @@ discard block |
||
| 5059 | 5478 | $this->db->begin(); |
| 5060 | 5479 | |
| 5061 | 5480 | $table_element = $this->table_element; |
| 5062 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5481 | + if ($table_element == 'categorie') { |
|
| 5482 | + $table_element = 'categories'; |
|
| 5483 | + } |
|
| 5484 | + // For compatibility |
|
| 5063 | 5485 | |
| 5064 | 5486 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 5065 | 5487 | dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
@@ -5070,8 +5492,10 @@ discard block |
||
| 5070 | 5492 | {
|
| 5071 | 5493 | $attributeKey = substr($key,8); // Remove 'options_' prefix |
| 5072 | 5494 | // Add field of attribut |
| 5073 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5074 | - $sql.=",".$attributeKey; |
|
| 5495 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { |
|
| 5496 | + // Only for other type than separator |
|
| 5497 | + $sql.=",".$attributeKey; |
|
| 5498 | + } |
|
| 5075 | 5499 | } |
| 5076 | 5500 | $sql .= ") VALUES (".$this->id;
|
| 5077 | 5501 | |
@@ -5079,13 +5503,14 @@ discard block |
||
| 5079 | 5503 | {
|
| 5080 | 5504 | $attributeKey = substr($key,8); // Remove 'options_' prefix |
| 5081 | 5505 | // Add field of attribute |
| 5082 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5506 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { |
|
| 5507 | + // Only for other type than separator) |
|
| 5083 | 5508 | {
|
| 5084 | 5509 | if ($new_array_options[$key] != '') |
| 5085 | 5510 | {
|
| 5086 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5087 | - } |
|
| 5088 | - else |
|
| 5511 | + $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5512 | + } |
|
| 5513 | + } else |
|
| 5089 | 5514 | {
|
| 5090 | 5515 | $sql.=",null"; |
| 5091 | 5516 | } |
@@ -5106,7 +5531,9 @@ discard block |
||
| 5106 | 5531 | // Call trigger |
| 5107 | 5532 | $this->context=array('extrafieldaddupdate'=>1);
|
| 5108 | 5533 | $result=$this->call_trigger($trigger, $userused); |
| 5109 | - if ($result < 0) $error++; |
|
| 5534 | + if ($result < 0) { |
|
| 5535 | + $error++; |
|
| 5536 | + } |
|
| 5110 | 5537 | // End call trigger |
| 5111 | 5538 | } |
| 5112 | 5539 | |
@@ -5114,14 +5541,14 @@ discard block |
||
| 5114 | 5541 | {
|
| 5115 | 5542 | $this->db->rollback(); |
| 5116 | 5543 | return -1; |
| 5117 | - } |
|
| 5118 | - else |
|
| 5544 | + } else |
|
| 5119 | 5545 | {
|
| 5120 | 5546 | $this->db->commit(); |
| 5121 | 5547 | return 1; |
| 5122 | 5548 | } |
| 5123 | - } |
|
| 5124 | - else return 0; |
|
| 5549 | + } else { |
|
| 5550 | + return 0; |
|
| 5551 | + } |
|
| 5125 | 5552 | } |
| 5126 | 5553 | |
| 5127 | 5554 | /** |
@@ -5138,11 +5565,16 @@ discard block |
||
| 5138 | 5565 | {
|
| 5139 | 5566 | global $conf,$langs,$user; |
| 5140 | 5567 | |
| 5141 | - if (empty($userused)) $userused=$user; |
|
| 5568 | + if (empty($userused)) { |
|
| 5569 | + $userused=$user; |
|
| 5570 | + } |
|
| 5142 | 5571 | |
| 5143 | 5572 | $error=0; |
| 5144 | 5573 | |
| 5145 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used |
|
| 5574 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 5575 | + return 0; |
|
| 5576 | + } |
|
| 5577 | + // For avoid conflicts if trigger used |
|
| 5146 | 5578 | |
| 5147 | 5579 | if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
| 5148 | 5580 | {
|
@@ -5169,8 +5601,7 @@ discard block |
||
| 5169 | 5601 | {
|
| 5170 | 5602 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
| 5171 | 5603 | return -1; |
| 5172 | - } |
|
| 5173 | - elseif ($value=='') |
|
| 5604 | + } elseif ($value=='') |
|
| 5174 | 5605 | {
|
| 5175 | 5606 | $this->array_options["options_".$key] = null; |
| 5176 | 5607 | } |
@@ -5182,8 +5613,7 @@ discard block |
||
| 5182 | 5613 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
| 5183 | 5614 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
| 5184 | 5615 | return -1; |
| 5185 | - } |
|
| 5186 | - elseif ($value=='') |
|
| 5616 | + } elseif ($value=='') |
|
| 5187 | 5617 | {
|
| 5188 | 5618 | $this->array_options["options_".$key] = null; |
| 5189 | 5619 | } |
@@ -5235,7 +5665,9 @@ discard block |
||
| 5235 | 5665 | // Call trigger |
| 5236 | 5666 | $this->context=array('extrafieldupdate'=>1);
|
| 5237 | 5667 | $result=$this->call_trigger($trigger, $userused); |
| 5238 | - if ($result < 0) $error++; |
|
| 5668 | + if ($result < 0) { |
|
| 5669 | + $error++; |
|
| 5670 | + } |
|
| 5239 | 5671 | // End call trigger |
| 5240 | 5672 | } |
| 5241 | 5673 | |
@@ -5244,14 +5676,14 @@ discard block |
||
| 5244 | 5676 | dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
| 5245 | 5677 | $this->db->rollback(); |
| 5246 | 5678 | return -1; |
| 5247 | - } |
|
| 5248 | - else |
|
| 5679 | + } else |
|
| 5249 | 5680 | {
|
| 5250 | 5681 | $this->db->commit(); |
| 5251 | 5682 | return 1; |
| 5252 | 5683 | } |
| 5253 | - } |
|
| 5254 | - else return 0; |
|
| 5684 | + } else { |
|
| 5685 | + return 0; |
|
| 5686 | + } |
|
| 5255 | 5687 | } |
| 5256 | 5688 | |
| 5257 | 5689 | |
@@ -5326,8 +5758,11 @@ discard block |
||
| 5326 | 5758 | |
| 5327 | 5759 | if ($computed) |
| 5328 | 5760 | {
|
| 5329 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5330 | - else return ''; |
|
| 5761 | + if (! preg_match('/^search_/', $keyprefix)) { |
|
| 5762 | + return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 5763 | + } else { |
|
| 5764 | + return ''; |
|
| 5765 | + } |
|
| 5331 | 5766 | } |
| 5332 | 5767 | |
| 5333 | 5768 | |
@@ -5341,33 +5776,27 @@ discard block |
||
| 5341 | 5776 | if ($type == 'date') |
| 5342 | 5777 | {
|
| 5343 | 5778 | $morecss = 'minwidth100imp'; |
| 5344 | - } |
|
| 5345 | - elseif ($type == 'datetime') |
|
| 5779 | + } elseif ($type == 'datetime') |
|
| 5346 | 5780 | {
|
| 5347 | 5781 | $morecss = 'minwidth200imp'; |
| 5348 | - } |
|
| 5349 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5782 | + } elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5350 | 5783 | {
|
| 5351 | 5784 | $morecss = 'maxwidth75'; |
| 5352 | - }elseif ($type == 'url') |
|
| 5785 | + } elseif ($type == 'url') |
|
| 5353 | 5786 | {
|
| 5354 | 5787 | $morecss='minwidth400'; |
| 5355 | - } |
|
| 5356 | - elseif ($type == 'boolean') |
|
| 5788 | + } elseif ($type == 'boolean') |
|
| 5357 | 5789 | {
|
| 5358 | 5790 | $morecss=''; |
| 5359 | - } |
|
| 5360 | - else |
|
| 5791 | + } else |
|
| 5361 | 5792 | {
|
| 5362 | 5793 | if (round($size) < 12) |
| 5363 | 5794 | {
|
| 5364 | 5795 | $morecss = 'minwidth100'; |
| 5365 | - } |
|
| 5366 | - else if (round($size) <= 48) |
|
| 5796 | + } else if (round($size) <= 48) |
|
| 5367 | 5797 | {
|
| 5368 | 5798 | $morecss = 'minwidth200'; |
| 5369 | - } |
|
| 5370 | - else |
|
| 5799 | + } else |
|
| 5371 | 5800 | {
|
| 5372 | 5801 | $morecss = 'minwidth400'; |
| 5373 | 5802 | } |
@@ -5382,52 +5811,50 @@ discard block |
||
| 5382 | 5811 | $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
| 5383 | 5812 | |
| 5384 | 5813 | // Do not show current date when field not required (see selectDate() method) |
| 5385 | - if (!$required && $value == '') $value = '-1'; |
|
| 5814 | + if (!$required && $value == '') { |
|
| 5815 | + $value = '-1'; |
|
| 5816 | + } |
|
| 5386 | 5817 | |
| 5387 | 5818 | // TODO Must also support $moreparam |
| 5388 | 5819 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 5389 | - } |
|
| 5390 | - elseif (in_array($type,array('int','integer')))
|
|
| 5820 | + } elseif (in_array($type,array('int','integer')))
|
|
| 5391 | 5821 | {
|
| 5392 | 5822 | $tmp=explode(',',$size);
|
| 5393 | 5823 | $newsize=$tmp[0]; |
| 5394 | 5824 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
| 5395 | - } |
|
| 5396 | - elseif (preg_match('/varchar/', $type))
|
|
| 5825 | + } elseif (preg_match('/varchar/', $type))
|
|
| 5397 | 5826 | {
|
| 5398 | 5827 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
| 5399 | - } |
|
| 5400 | - elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5828 | + } elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5401 | 5829 | {
|
| 5402 | 5830 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5403 | - } |
|
| 5404 | - elseif ($type == 'text') |
|
| 5831 | + } elseif ($type == 'text') |
|
| 5405 | 5832 | {
|
| 5406 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5833 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 5834 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5407 | 5835 | {
|
| 5408 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5836 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5837 | + } |
|
| 5409 | 5838 | $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
| 5410 | 5839 | $out=$doleditor->Create(1); |
| 5411 | - } |
|
| 5412 | - else |
|
| 5840 | + } else |
|
| 5413 | 5841 | {
|
| 5414 | 5842 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5415 | 5843 | } |
| 5416 | - } |
|
| 5417 | - elseif ($type == 'html') |
|
| 5844 | + } elseif ($type == 'html') |
|
| 5418 | 5845 | {
|
| 5419 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5846 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 5847 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5420 | 5848 | {
|
| 5421 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5849 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5850 | + } |
|
| 5422 | 5851 | $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%'); |
| 5423 | 5852 | $out=$doleditor->Create(1); |
| 5424 | - } |
|
| 5425 | - else |
|
| 5853 | + } else |
|
| 5426 | 5854 | {
|
| 5427 | 5855 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5428 | 5856 | } |
| 5429 | - } |
|
| 5430 | - elseif ($type == 'boolean') |
|
| 5857 | + } elseif ($type == 'boolean') |
|
| 5431 | 5858 | {
|
| 5432 | 5859 | $checked=''; |
| 5433 | 5860 | if (!empty($value)) {
|
@@ -5436,22 +5863,19 @@ discard block |
||
| 5436 | 5863 | $checked=' value="1" '; |
| 5437 | 5864 | } |
| 5438 | 5865 | $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
| 5439 | - } |
|
| 5440 | - elseif ($type == 'price') |
|
| 5866 | + } elseif ($type == 'price') |
|
| 5441 | 5867 | {
|
| 5442 | 5868 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
| 5443 | 5869 | $value=price($value); |
| 5444 | 5870 | } |
| 5445 | 5871 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
| 5446 | - } |
|
| 5447 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5872 | + } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5448 | 5873 | {
|
| 5449 | 5874 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
| 5450 | 5875 | $value=price($value); |
| 5451 | 5876 | } |
| 5452 | 5877 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
| 5453 | - } |
|
| 5454 | - elseif ($type == 'select') |
|
| 5878 | + } elseif ($type == 'select') |
|
| 5455 | 5879 | {
|
| 5456 | 5880 | $out = ''; |
| 5457 | 5881 | if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
@@ -5461,10 +5885,14 @@ discard block |
||
| 5461 | 5885 | } |
| 5462 | 5886 | |
| 5463 | 5887 | $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
| 5464 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5888 | + if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1)) { |
|
| 5889 | + $out.='<option value="0"> </option>'; |
|
| 5890 | + } |
|
| 5465 | 5891 | foreach ($param['options'] as $key => $val) |
| 5466 | 5892 | {
|
| 5467 | - if ((string) $key == '') continue; |
|
| 5893 | + if ((string) $key == '') { |
|
| 5894 | + continue; |
|
| 5895 | + } |
|
| 5468 | 5896 | list($val, $parent) = explode('|', $val);
|
| 5469 | 5897 | $out.='<option value="'.$key.'"'; |
| 5470 | 5898 | $out.= (((string) $value == (string) $key)?' selected':''); |
@@ -5472,8 +5900,7 @@ discard block |
||
| 5472 | 5900 | $out.='>'.$val.'</option>'; |
| 5473 | 5901 | } |
| 5474 | 5902 | $out.='</select>'; |
| 5475 | - } |
|
| 5476 | - elseif ($type == 'sellist') |
|
| 5903 | + } elseif ($type == 'sellist') |
|
| 5477 | 5904 | {
|
| 5478 | 5905 | $out = ''; |
| 5479 | 5906 | if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
@@ -5540,13 +5967,11 @@ discard block |
||
| 5540 | 5967 | {
|
| 5541 | 5968 | $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
| 5542 | 5969 | $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
| 5543 | - } |
|
| 5544 | - else |
|
| 5970 | + } else |
|
| 5545 | 5971 | {
|
| 5546 | 5972 | $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
| 5547 | 5973 | } |
| 5548 | - } |
|
| 5549 | - else |
|
| 5974 | + } else |
|
| 5550 | 5975 | {
|
| 5551 | 5976 | $sqlwhere.= ' WHERE 1=1'; |
| 5552 | 5977 | } |
@@ -5582,8 +6007,7 @@ discard block |
||
| 5582 | 6007 | {
|
| 5583 | 6008 | $labeltoshow.= $obj->$field_toshow.' '; |
| 5584 | 6009 | } |
| 5585 | - } |
|
| 5586 | - else |
|
| 6010 | + } else |
|
| 5587 | 6011 | {
|
| 5588 | 6012 | $labeltoshow=$obj->{$InfoFieldList[1]};
|
| 5589 | 6013 | } |
@@ -5596,25 +6020,25 @@ discard block |
||
| 5596 | 6020 | $translabel=$langs->trans($obj->$field_toshow); |
| 5597 | 6021 | if ($translabel!=$obj->$field_toshow) {
|
| 5598 | 6022 | $labeltoshow=dol_trunc($translabel,18).' '; |
| 5599 | - }else {
|
|
| 6023 | + } else {
|
|
| 5600 | 6024 | $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
| 5601 | 6025 | } |
| 5602 | 6026 | } |
| 5603 | 6027 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
| 5604 | - } |
|
| 5605 | - else |
|
| 6028 | + } else |
|
| 5606 | 6029 | {
|
| 5607 | 6030 | if (! $notrans) |
| 5608 | 6031 | {
|
| 5609 | 6032 | $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
| 5610 | 6033 | if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
| 5611 | 6034 | $labeltoshow=dol_trunc($translabel,18); |
| 5612 | - } |
|
| 5613 | - else {
|
|
| 6035 | + } else {
|
|
| 5614 | 6036 | $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
| 5615 | 6037 | } |
| 5616 | 6038 | } |
| 5617 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 6039 | + if (empty($labeltoshow)) { |
|
| 6040 | + $labeltoshow='(not defined)'; |
|
| 6041 | + } |
|
| 5618 | 6042 | if ($value==$obj->rowid) |
| 5619 | 6043 | {
|
| 5620 | 6044 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
@@ -5634,19 +6058,16 @@ discard block |
||
| 5634 | 6058 | $i++; |
| 5635 | 6059 | } |
| 5636 | 6060 | $this->db->free($resql); |
| 5637 | - } |
|
| 5638 | - else {
|
|
| 6061 | + } else {
|
|
| 5639 | 6062 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 5640 | 6063 | } |
| 5641 | 6064 | } |
| 5642 | 6065 | $out.='</select>'; |
| 5643 | - } |
|
| 5644 | - elseif ($type == 'checkbox') |
|
| 6066 | + } elseif ($type == 'checkbox') |
|
| 5645 | 6067 | {
|
| 5646 | 6068 | $value_arr=explode(',',$value);
|
| 5647 | 6069 | $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
| 5648 | - } |
|
| 5649 | - elseif ($type == 'radio') |
|
| 6070 | + } elseif ($type == 'radio') |
|
| 5650 | 6071 | {
|
| 5651 | 6072 | $out=''; |
| 5652 | 6073 | foreach ($param['options'] as $keyopt => $val) |
@@ -5657,13 +6078,11 @@ discard block |
||
| 5657 | 6078 | $out.= ($value==$keyopt?'checked':''); |
| 5658 | 6079 | $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
| 5659 | 6080 | } |
| 5660 | - } |
|
| 5661 | - elseif ($type == 'chkbxlst') |
|
| 6081 | + } elseif ($type == 'chkbxlst') |
|
| 5662 | 6082 | {
|
| 5663 | 6083 | if (is_array($value)) {
|
| 5664 | 6084 | $value_arr = $value; |
| 5665 | - } |
|
| 5666 | - else {
|
|
| 6085 | + } else {
|
|
| 5667 | 6086 | $value_arr = explode(',', $value);
|
| 5668 | 6087 | } |
| 5669 | 6088 | |
@@ -5778,8 +6197,9 @@ discard block |
||
| 5778 | 6197 | $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
| 5779 | 6198 | } |
| 5780 | 6199 | } |
| 5781 | - if (empty($labeltoshow)) |
|
| 5782 | - $labeltoshow = '(not defined)'; |
|
| 6200 | + if (empty($labeltoshow)) { |
|
| 6201 | + $labeltoshow = '(not defined)'; |
|
| 6202 | + } |
|
| 5783 | 6203 | |
| 5784 | 6204 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
| 5785 | 6205 | $data[$obj->rowid]=$labeltoshow; |
@@ -5801,8 +6221,7 @@ discard block |
||
| 5801 | 6221 | print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
| 5802 | 6222 | } |
| 5803 | 6223 | } |
| 5804 | - } |
|
| 5805 | - elseif ($type == 'link') |
|
| 6224 | + } elseif ($type == 'link') |
|
| 5806 | 6225 | {
|
| 5807 | 6226 | $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
| 5808 | 6227 | $showempty=(($required && $default != '')?0:1); |
@@ -5810,18 +6229,19 @@ discard block |
||
| 5810 | 6229 | if ($conf->global->MAIN_FEATURES_LEVEL >= 2) |
| 5811 | 6230 | {
|
| 5812 | 6231 | list($class,$classfile)=explode(':',$param_list[0]);
|
| 5813 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5814 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 6232 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) { |
|
| 6233 | + $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 6234 | + } else { |
|
| 6235 | + $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 6236 | + } |
|
| 5815 | 6237 | $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
| 5816 | 6238 | // TODO Add Javascript code to add input fields contents to new elements urls |
| 5817 | 6239 | } |
| 5818 | - } |
|
| 5819 | - elseif ($type == 'password') |
|
| 6240 | + } elseif ($type == 'password') |
|
| 5820 | 6241 | {
|
| 5821 | 6242 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 5822 | 6243 | $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
| 5823 | - } |
|
| 5824 | - elseif ($type == 'array') |
|
| 6244 | + } elseif ($type == 'array') |
|
| 5825 | 6245 | {
|
| 5826 | 6246 | $newval = $val; |
| 5827 | 6247 | $newval['type'] = 'varchar(256)'; |
@@ -5899,17 +6319,25 @@ discard block |
||
| 5899 | 6319 | {
|
| 5900 | 6320 | $type = 'varchar'; // convert varchar(xx) int varchar |
| 5901 | 6321 | $size = $reg[1]; |
| 5902 | - } |
|
| 5903 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5904 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5905 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 6322 | + } elseif (preg_match('/varchar/', $type)) { |
|
| 6323 | + $type = 'varchar'; |
|
| 6324 | + } |
|
| 6325 | + // convert varchar(xx) int varchar |
|
| 6326 | + if (is_array($val['arrayofkeyval'])) { |
|
| 6327 | + $type='select'; |
|
| 6328 | + } |
|
| 6329 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
|
| 6330 | + $type='link'; |
|
| 6331 | + } |
|
| 5906 | 6332 | |
| 5907 | 6333 | $default=$val['default']; |
| 5908 | 6334 | $computed=$val['computed']; |
| 5909 | 6335 | $unique=$val['unique']; |
| 5910 | 6336 | $required=$val['required']; |
| 5911 | 6337 | $param=$val['param']; |
| 5912 | - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 6338 | + if (is_array($val['arrayofkeyval'])) { |
|
| 6339 | + $param['options'] = $val['arrayofkeyval']; |
|
| 6340 | + } |
|
| 5913 | 6341 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
| 5914 | 6342 | {
|
| 5915 | 6343 | $type='link'; |
@@ -5920,7 +6348,9 @@ discard block |
||
| 5920 | 6348 | $help=$val['help']; |
| 5921 | 6349 | $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) |
| 5922 | 6350 | |
| 5923 | - if ($hidden) return ''; |
|
| 6351 | + if ($hidden) { |
|
| 6352 | + return ''; |
|
| 6353 | + } |
|
| 5924 | 6354 | |
| 5925 | 6355 | // If field is a computed field, value must become result of compute |
| 5926 | 6356 | if ($computed) |
@@ -5936,36 +6366,29 @@ discard block |
||
| 5936 | 6366 | {
|
| 5937 | 6367 | //$showsize=10; |
| 5938 | 6368 | $showsize = 'minwidth100imp'; |
| 5939 | - } |
|
| 5940 | - elseif ($type == 'datetime') |
|
| 6369 | + } elseif ($type == 'datetime') |
|
| 5941 | 6370 | {
|
| 5942 | 6371 | //$showsize=19; |
| 5943 | 6372 | $showsize = 'minwidth200imp'; |
| 5944 | - } |
|
| 5945 | - elseif (in_array($type,array('int','double','price')))
|
|
| 6373 | + } elseif (in_array($type,array('int','double','price')))
|
|
| 5946 | 6374 | {
|
| 5947 | 6375 | //$showsize=10; |
| 5948 | 6376 | $showsize = 'maxwidth75'; |
| 5949 | - } |
|
| 5950 | - elseif ($type == 'url') |
|
| 6377 | + } elseif ($type == 'url') |
|
| 5951 | 6378 | {
|
| 5952 | 6379 | $showsize='minwidth400'; |
| 5953 | - } |
|
| 5954 | - elseif ($type == 'boolean') |
|
| 6380 | + } elseif ($type == 'boolean') |
|
| 5955 | 6381 | {
|
| 5956 | 6382 | $showsize=''; |
| 5957 | - } |
|
| 5958 | - else |
|
| 6383 | + } else |
|
| 5959 | 6384 | {
|
| 5960 | 6385 | if (round($size) < 12) |
| 5961 | 6386 | {
|
| 5962 | 6387 | $showsize = 'minwidth100'; |
| 5963 | - } |
|
| 5964 | - else if (round($size) <= 48) |
|
| 6388 | + } else if (round($size) <= 48) |
|
| 5965 | 6389 | {
|
| 5966 | 6390 | $showsize = 'minwidth200'; |
| 5967 | - } |
|
| 5968 | - else |
|
| 6391 | + } else |
|
| 5969 | 6392 | {
|
| 5970 | 6393 | //$showsize=48; |
| 5971 | 6394 | $showsize = 'minwidth400'; |
@@ -5974,59 +6397,52 @@ discard block |
||
| 5974 | 6397 | } |
| 5975 | 6398 | |
| 5976 | 6399 | // Format output value differently according to properties of field |
| 5977 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5978 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5979 | - elseif ($type == 'date') |
|
| 6400 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) { |
|
| 6401 | + $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 6402 | + } elseif ($key == 'status' && method_exists($this, 'getLibStatut')) { |
|
| 6403 | + $value=$this->getLibStatut(3); |
|
| 6404 | + } elseif ($type == 'date') |
|
| 5980 | 6405 | {
|
| 5981 | 6406 | if(! empty($value)) {
|
| 5982 | 6407 | $value=dol_print_date($value,'day'); |
| 5983 | 6408 | } else {
|
| 5984 | 6409 | $value=''; |
| 5985 | 6410 | } |
| 5986 | - } |
|
| 5987 | - elseif ($type == 'datetime') |
|
| 6411 | + } elseif ($type == 'datetime') |
|
| 5988 | 6412 | {
|
| 5989 | 6413 | if(! empty($value)) {
|
| 5990 | 6414 | $value=dol_print_date($value,'dayhour'); |
| 5991 | 6415 | } else {
|
| 5992 | 6416 | $value=''; |
| 5993 | 6417 | } |
| 5994 | - } |
|
| 5995 | - elseif ($type == 'double') |
|
| 6418 | + } elseif ($type == 'double') |
|
| 5996 | 6419 | {
|
| 5997 | 6420 | if (!empty($value)) {
|
| 5998 | 6421 | $value=price($value); |
| 5999 | 6422 | } |
| 6000 | - } |
|
| 6001 | - elseif ($type == 'boolean') |
|
| 6423 | + } elseif ($type == 'boolean') |
|
| 6002 | 6424 | {
|
| 6003 | 6425 | $checked=''; |
| 6004 | 6426 | if (!empty($value)) {
|
| 6005 | 6427 | $checked=' checked '; |
| 6006 | 6428 | } |
| 6007 | 6429 | $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
| 6008 | - } |
|
| 6009 | - elseif ($type == 'mail') |
|
| 6430 | + } elseif ($type == 'mail') |
|
| 6010 | 6431 | {
|
| 6011 | 6432 | $value=dol_print_email($value,0,0,0,64,1,1); |
| 6012 | - } |
|
| 6013 | - elseif ($type == 'url') |
|
| 6433 | + } elseif ($type == 'url') |
|
| 6014 | 6434 | {
|
| 6015 | 6435 | $value=dol_print_url($value,'_blank',32,1); |
| 6016 | - } |
|
| 6017 | - elseif ($type == 'phone') |
|
| 6436 | + } elseif ($type == 'phone') |
|
| 6018 | 6437 | {
|
| 6019 | 6438 | $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
| 6020 | - } |
|
| 6021 | - elseif ($type == 'price') |
|
| 6439 | + } elseif ($type == 'price') |
|
| 6022 | 6440 | {
|
| 6023 | 6441 | $value=price($value,0,$langs,0,0,-1,$conf->currency); |
| 6024 | - } |
|
| 6025 | - elseif ($type == 'select') |
|
| 6442 | + } elseif ($type == 'select') |
|
| 6026 | 6443 | {
|
| 6027 | 6444 | $value=$param['options'][$value]; |
| 6028 | - } |
|
| 6029 | - elseif ($type == 'sellist') |
|
| 6445 | + } elseif ($type == 'sellist') |
|
| 6030 | 6446 | {
|
| 6031 | 6447 | $param_list=array_keys($param['options']); |
| 6032 | 6448 | $InfoFieldList = explode(":", $param_list[0]);
|
@@ -6056,7 +6472,7 @@ discard block |
||
| 6056 | 6472 | $sql.= " WHERE ".$selectkey."=0"; |
| 6057 | 6473 | } elseif ($selectkey=='rowid') {
|
| 6058 | 6474 | $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
| 6059 | - }else {
|
|
| 6475 | + } else {
|
|
| 6060 | 6476 | $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 6061 | 6477 | } |
| 6062 | 6478 | |
@@ -6083,12 +6499,11 @@ discard block |
||
| 6083 | 6499 | } |
| 6084 | 6500 | if ($translabel!=$field_toshow) {
|
| 6085 | 6501 | $value.=dol_trunc($translabel,18).' '; |
| 6086 | - }else {
|
|
| 6502 | + } else {
|
|
| 6087 | 6503 | $value.=$obj->$field_toshow.' '; |
| 6088 | 6504 | } |
| 6089 | 6505 | } |
| 6090 | - } |
|
| 6091 | - else |
|
| 6506 | + } else |
|
| 6092 | 6507 | {
|
| 6093 | 6508 | $translabel=''; |
| 6094 | 6509 | if (!empty($obj->{$InfoFieldList[1]})) {
|
@@ -6096,18 +6511,17 @@ discard block |
||
| 6096 | 6511 | } |
| 6097 | 6512 | if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
| 6098 | 6513 | $value=dol_trunc($translabel,18); |
| 6099 | - }else {
|
|
| 6514 | + } else {
|
|
| 6100 | 6515 | $value=$obj->{$InfoFieldList[1]};
|
| 6101 | 6516 | } |
| 6102 | 6517 | } |
| 6103 | - } |
|
| 6104 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6105 | - } |
|
| 6106 | - elseif ($type == 'radio') |
|
| 6518 | + } else { |
|
| 6519 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6520 | + } |
|
| 6521 | + } elseif ($type == 'radio') |
|
| 6107 | 6522 | {
|
| 6108 | 6523 | $value=$param['options'][$value]; |
| 6109 | - } |
|
| 6110 | - elseif ($type == 'checkbox') |
|
| 6524 | + } elseif ($type == 'checkbox') |
|
| 6111 | 6525 | {
|
| 6112 | 6526 | $value_arr=explode(',',$value);
|
| 6113 | 6527 | $value=''; |
@@ -6118,8 +6532,7 @@ discard block |
||
| 6118 | 6532 | } |
| 6119 | 6533 | $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
| 6120 | 6534 | } |
| 6121 | - } |
|
| 6122 | - elseif ($type == 'chkbxlst') |
|
| 6535 | + } elseif ($type == 'chkbxlst') |
|
| 6123 | 6536 | {
|
| 6124 | 6537 | $value_arr = explode(',', $value);
|
| 6125 | 6538 | |
@@ -6187,8 +6600,7 @@ discard block |
||
| 6187 | 6600 | } else {
|
| 6188 | 6601 | dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
| 6189 | 6602 | } |
| 6190 | - } |
|
| 6191 | - elseif ($type == 'link') |
|
| 6603 | + } elseif ($type == 'link') |
|
| 6192 | 6604 | {
|
| 6193 | 6605 | $out=''; |
| 6194 | 6606 | |
@@ -6210,24 +6622,21 @@ discard block |
||
| 6210 | 6622 | $object->fetch($value); |
| 6211 | 6623 | $value=$object->getNomUrl($getnomurlparam); |
| 6212 | 6624 | } |
| 6213 | - } |
|
| 6214 | - else |
|
| 6625 | + } else |
|
| 6215 | 6626 | {
|
| 6216 | 6627 | dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
| 6217 | 6628 | return 'Error bad setup of extrafield'; |
| 6218 | 6629 | } |
| 6219 | - } |
|
| 6220 | - else $value=''; |
|
| 6221 | - } |
|
| 6222 | - elseif ($type == 'text' || $type == 'html') |
|
| 6630 | + } else { |
|
| 6631 | + $value=''; |
|
| 6632 | + } |
|
| 6633 | + } elseif ($type == 'text' || $type == 'html') |
|
| 6223 | 6634 | {
|
| 6224 | 6635 | $value=dol_htmlentitiesbr($value); |
| 6225 | - } |
|
| 6226 | - elseif ($type == 'password') |
|
| 6636 | + } elseif ($type == 'password') |
|
| 6227 | 6637 | {
|
| 6228 | 6638 | $value=preg_replace('/./i','*',$value);
|
| 6229 | - } |
|
| 6230 | - elseif ($type == 'array') |
|
| 6639 | + } elseif ($type == 'array') |
|
| 6231 | 6640 | {
|
| 6232 | 6641 | $value = implode('<br>', $value);
|
| 6233 | 6642 | } |
@@ -6254,7 +6663,9 @@ discard block |
||
| 6254 | 6663 | {
|
| 6255 | 6664 | global $db, $conf, $langs, $action, $form; |
| 6256 | 6665 | |
| 6257 | - if (! is_object($form)) $form=new Form($db); |
|
| 6666 | + if (! is_object($form)) { |
|
| 6667 | + $form=new Form($db); |
|
| 6668 | + } |
|
| 6258 | 6669 | |
| 6259 | 6670 | $out = ''; |
| 6260 | 6671 | |
@@ -6268,7 +6679,9 @@ discard block |
||
| 6268 | 6679 | foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
| 6269 | 6680 | {
|
| 6270 | 6681 | // Show only the key field in params |
| 6271 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 6682 | + if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) { |
|
| 6683 | + continue; |
|
| 6684 | + } |
|
| 6272 | 6685 | |
| 6273 | 6686 | $enabled = 1; |
| 6274 | 6687 | if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
@@ -6282,11 +6695,18 @@ discard block |
||
| 6282 | 6695 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
| 6283 | 6696 | } |
| 6284 | 6697 | |
| 6285 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6286 | - if (empty($perms)) continue; |
|
| 6698 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) { |
|
| 6699 | + continue; |
|
| 6700 | + } |
|
| 6701 | + // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6702 | + if (empty($perms)) { |
|
| 6703 | + continue; |
|
| 6704 | + } |
|
| 6287 | 6705 | |
| 6288 | 6706 | // Load language if required |
| 6289 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6707 | + if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) { |
|
| 6708 | + $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6709 | + } |
|
| 6290 | 6710 | |
| 6291 | 6711 | $colspan='3'; |
| 6292 | 6712 | if (is_array($params) && count($params)>0) {
|
@@ -6320,8 +6740,7 @@ discard block |
||
| 6320 | 6740 | if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
| 6321 | 6741 | {
|
| 6322 | 6742 | $out .= $extrafields->showSeparator($key, $this); |
| 6323 | - } |
|
| 6324 | - else |
|
| 6743 | + } else |
|
| 6325 | 6744 | {
|
| 6326 | 6745 | $csstyle=''; |
| 6327 | 6746 | $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
@@ -6351,9 +6770,11 @@ discard block |
||
| 6351 | 6770 | if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
| 6352 | 6771 | {
|
| 6353 | 6772 | $datenotinstring = $this->array_options['options_' . $key]; |
| 6354 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6773 | + if (! is_numeric($this->array_options['options_' . $key])) { |
|
| 6774 | + // For backward compatibility |
|
| 6355 | 6775 | {
|
| 6356 | - $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6776 | + $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6777 | + } |
|
| 6357 | 6778 | } |
| 6358 | 6779 | $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)):$datenotinstring; |
| 6359 | 6780 | } |
@@ -6366,11 +6787,18 @@ discard block |
||
| 6366 | 6787 | $labeltoshow = $langs->trans($label); |
| 6367 | 6788 | |
| 6368 | 6789 | $out .= '<td class="titlefield'; |
| 6369 | - if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6370 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6790 | + if (GETPOST('action','none') == 'create') { |
|
| 6791 | + $out.='create'; |
|
| 6792 | + } |
|
| 6793 | + if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) { |
|
| 6794 | + $out .= ' fieldrequired'; |
|
| 6795 | + } |
|
| 6371 | 6796 | $out .= '">'; |
| 6372 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6373 | - else $out .= $labeltoshow; |
|
| 6797 | + if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) { |
|
| 6798 | + $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6799 | + } else { |
|
| 6800 | + $out .= $labeltoshow; |
|
| 6801 | + } |
|
| 6374 | 6802 | $out .= '</td>'; |
| 6375 | 6803 | |
| 6376 | 6804 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
@@ -6387,8 +6815,11 @@ discard block |
||
| 6387 | 6815 | |
| 6388 | 6816 | $out .= '</td>'; |
| 6389 | 6817 | |
| 6390 | - if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) $out .= '</tr>'; |
|
| 6391 | - else $out .= '</tr>'; |
|
| 6818 | + if (! empty($conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) { |
|
| 6819 | + $out .= '</tr>'; |
|
| 6820 | + } else { |
|
| 6821 | + $out .= '</tr>'; |
|
| 6822 | + } |
|
| 6392 | 6823 | $e++; |
| 6393 | 6824 | } |
| 6394 | 6825 | } |
@@ -6440,7 +6871,9 @@ discard block |
||
| 6440 | 6871 | global $user; |
| 6441 | 6872 | |
| 6442 | 6873 | $element = $this->element; |
| 6443 | - if ($element == 'facturerec') $element='facture'; |
|
| 6874 | + if ($element == 'facturerec') { |
|
| 6875 | + $element='facture'; |
|
| 6876 | + } |
|
| 6444 | 6877 | |
| 6445 | 6878 | return $user->rights->{$element};
|
| 6446 | 6879 | } |
@@ -6465,7 +6898,10 @@ discard block |
||
| 6465 | 6898 | |
| 6466 | 6899 | if (! $db->query($sql)) |
| 6467 | 6900 | {
|
| 6468 | - 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. |
|
| 6901 | + if ($ignoreerrors) { |
|
| 6902 | + return true; |
|
| 6903 | + } |
|
| 6904 | + // 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. |
|
| 6469 | 6905 | //$this->errors = $db->lasterror(); |
| 6470 | 6906 | return false; |
| 6471 | 6907 | } |
@@ -6492,11 +6928,12 @@ discard block |
||
| 6492 | 6928 | |
| 6493 | 6929 | $buyPrice = 0; |
| 6494 | 6930 | |
| 6495 | - if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false |
|
| 6931 | + if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { |
|
| 6932 | + // In most cases, test here is false |
|
| 6496 | 6933 | {
|
| 6497 | - $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
| 6498 | - } |
|
| 6499 | - else |
|
| 6934 | + $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
| 6935 | + } |
|
| 6936 | + } else |
|
| 6500 | 6937 | {
|
| 6501 | 6938 | // Get cost price for margin calculation |
| 6502 | 6939 | if (! empty($fk_product)) |
@@ -6514,13 +6951,11 @@ discard block |
||
| 6514 | 6951 | if ($product->cost_price > 0) |
| 6515 | 6952 | {
|
| 6516 | 6953 | $buyPrice = $product->cost_price; |
| 6517 | - } |
|
| 6518 | - else if ($product->pmp > 0) |
|
| 6954 | + } else if ($product->pmp > 0) |
|
| 6519 | 6955 | {
|
| 6520 | 6956 | $buyPrice = $product->pmp; |
| 6521 | 6957 | } |
| 6522 | - } |
|
| 6523 | - else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
| 6958 | + } else if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') |
|
| 6524 | 6959 | {
|
| 6525 | 6960 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
| 6526 | 6961 | $product = new Product($this->db); |
@@ -6543,8 +6978,7 @@ discard block |
||
| 6543 | 6978 | if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
| 6544 | 6979 | {
|
| 6545 | 6980 | $buyPrice = $productFournisseur->fourn_unitprice; |
| 6546 | - } |
|
| 6547 | - else if ($result < 0) |
|
| 6981 | + } else if ($result < 0) |
|
| 6548 | 6982 | {
|
| 6549 | 6983 | $this->errors[] = $productFournisseur->error; |
| 6550 | 6984 | return -2; |
@@ -6590,8 +7024,7 @@ discard block |
||
| 6590 | 7024 | {
|
| 6591 | 7025 | $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
| 6592 | 7026 | $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
| 6593 | - } |
|
| 6594 | - else |
|
| 7027 | + } else |
|
| 6595 | 7028 | {
|
| 6596 | 7029 | $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
| 6597 | 7030 | $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
@@ -6654,19 +7087,26 @@ discard block |
||
| 6654 | 7087 | |
| 6655 | 7088 | // Find name of thumb file |
| 6656 | 7089 | $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
| 6657 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 7090 | + if (! dol_is_file($dirthumb.$photo_vignette)) { |
|
| 7091 | + $photo_vignette=''; |
|
| 7092 | + } |
|
| 6658 | 7093 | |
| 6659 | 7094 | // Get filesize of original file |
| 6660 | 7095 | $imgarray=dol_getImageSize($dir.$photo); |
| 6661 | 7096 | |
| 6662 | 7097 | if ($nbbyrow > 0) |
| 6663 | 7098 | {
|
| 6664 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7099 | + if ($nbphoto == 1) { |
|
| 7100 | + $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7101 | + } |
|
| 6665 | 7102 | |
| 6666 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 7103 | + if ($nbphoto % $nbbyrow == 1) { |
|
| 7104 | + $return.= '<tr align=center valign=middle border=1>'; |
|
| 7105 | + } |
|
| 6667 | 7106 | $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
| 6668 | - } |
|
| 6669 | - else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 7107 | + } else if ($nbbyrow < 0) { |
|
| 7108 | + $return .= '<div class="inline-block">'; |
|
| 7109 | + } |
|
| 6670 | 7110 | |
| 6671 | 7111 | $return.= "\n"; |
| 6672 | 7112 | |
@@ -6674,15 +7114,20 @@ discard block |
||
| 6674 | 7114 | if (empty($nolink)) |
| 6675 | 7115 | {
|
| 6676 | 7116 | $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
| 6677 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6678 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 7117 | + if ($urladvanced) { |
|
| 7118 | + $return.='<a href="'.$urladvanced.'">'; |
|
| 7119 | + } else { |
|
| 7120 | + $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 7121 | + } |
|
| 6679 | 7122 | } |
| 6680 | 7123 | |
| 6681 | 7124 | // Show image (width height=$maxHeight) |
| 6682 | 7125 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
| 6683 | 7126 | $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
| 6684 | 7127 | $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
| 6685 | - if ($notitle) $alt=''; |
|
| 7128 | + if ($notitle) { |
|
| 7129 | + $alt=''; |
|
| 7130 | + } |
|
| 6686 | 7131 | |
| 6687 | 7132 | if ($usesharelink) |
| 6688 | 7133 | {
|
@@ -6692,35 +7137,35 @@ discard block |
||
| 6692 | 7137 | {
|
| 6693 | 7138 | $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
| 6694 | 7139 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6695 | - } |
|
| 6696 | - else {
|
|
| 7140 | + } else {
|
|
| 6697 | 7141 | $return.= '<!-- Show original file -->'; |
| 6698 | 7142 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6699 | 7143 | } |
| 6700 | - } |
|
| 6701 | - else |
|
| 7144 | + } else |
|
| 6702 | 7145 | {
|
| 6703 | 7146 | $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
| 6704 | 7147 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
| 6705 | 7148 | } |
| 6706 | - } |
|
| 6707 | - else |
|
| 7149 | + } else |
|
| 6708 | 7150 | {
|
| 6709 | 7151 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6710 | 7152 | {
|
| 6711 | 7153 | $return.= '<!-- Show thumb -->'; |
| 6712 | 7154 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdirthumb.$photo_vignette).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6713 | - } |
|
| 6714 | - else {
|
|
| 7155 | + } else {
|
|
| 6715 | 7156 | $return.= '<!-- Show original file -->'; |
| 6716 | 7157 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6717 | 7158 | } |
| 6718 | 7159 | } |
| 6719 | 7160 | |
| 6720 | - if (empty($nolink)) $return.= '</a>'; |
|
| 7161 | + if (empty($nolink)) { |
|
| 7162 | + $return.= '</a>'; |
|
| 7163 | + } |
|
| 6721 | 7164 | $return.="\n"; |
| 6722 | 7165 | |
| 6723 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 7166 | + if ($showfilename) { |
|
| 7167 | + $return.= '<br>'.$viewfilename; |
|
| 7168 | + } |
|
| 6724 | 7169 | if ($showaction) |
| 6725 | 7170 | {
|
| 6726 | 7171 | $return.= '<br>'; |
@@ -6745,15 +7190,20 @@ discard block |
||
| 6745 | 7190 | if ($nbbyrow > 0) |
| 6746 | 7191 | {
|
| 6747 | 7192 | $return.= '</td>'; |
| 6748 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6749 | - } |
|
| 6750 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 7193 | + if (($nbphoto % $nbbyrow) == 0) { |
|
| 7194 | + $return.= '</tr>'; |
|
| 7195 | + } |
|
| 7196 | + } else if ($nbbyrow < 0) { |
|
| 7197 | + $return.='</div>'; |
|
| 7198 | + } |
|
| 6751 | 7199 | } |
| 6752 | 7200 | |
| 6753 | 7201 | if (empty($size)) { // Format origine
|
| 6754 | 7202 | $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
| 6755 | 7203 | |
| 6756 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 7204 | + if ($showfilename) { |
|
| 7205 | + $return.= '<br>'.$viewfilename; |
|
| 7206 | + } |
|
| 6757 | 7207 | if ($showaction) |
| 6758 | 7208 | {
|
| 6759 | 7209 | // Special case for product |
@@ -6770,7 +7220,9 @@ discard block |
||
| 6770 | 7220 | } |
| 6771 | 7221 | |
| 6772 | 7222 | // On continue ou on arrete de boucler ? |
| 6773 | - if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 7223 | + if ($nbmax && $nbphoto >= $nbmax) { |
|
| 7224 | + break; |
|
| 7225 | + } |
|
| 6774 | 7226 | } |
| 6775 | 7227 | } |
| 6776 | 7228 | |
@@ -6785,7 +7237,9 @@ discard block |
||
| 6785 | 7237 | $nbphoto++; |
| 6786 | 7238 | } |
| 6787 | 7239 | |
| 6788 | - if ($nbphoto) $return.= '</table>'; |
|
| 7240 | + if ($nbphoto) { |
|
| 7241 | + $return.= '</table>'; |
|
| 7242 | + } |
|
| 6789 | 7243 | } |
| 6790 | 7244 | } |
| 6791 | 7245 | } |
@@ -6806,10 +7260,14 @@ discard block |
||
| 6806 | 7260 | {
|
| 6807 | 7261 | if(is_array($info)) |
| 6808 | 7262 | {
|
| 6809 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6810 | - else return false; |
|
| 6811 | - } |
|
| 6812 | - else return false; |
|
| 7263 | + if(isset($info['type']) && $info['type']=='array') { |
|
| 7264 | + return true; |
|
| 7265 | + } else { |
|
| 7266 | + return false; |
|
| 7267 | + } |
|
| 7268 | + } else { |
|
| 7269 | + return false; |
|
| 7270 | + } |
|
| 6813 | 7271 | } |
| 6814 | 7272 | |
| 6815 | 7273 | /** |
@@ -6822,10 +7280,14 @@ discard block |
||
| 6822 | 7280 | {
|
| 6823 | 7281 | if(is_array($info)) |
| 6824 | 7282 | {
|
| 6825 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6826 | - else return false; |
|
| 6827 | - } |
|
| 6828 | - else return false; |
|
| 7283 | + if(isset($info['type']) && $info['type']=='null') { |
|
| 7284 | + return true; |
|
| 7285 | + } else { |
|
| 7286 | + return false; |
|
| 7287 | + } |
|
| 7288 | + } else { |
|
| 7289 | + return false; |
|
| 7290 | + } |
|
| 6829 | 7291 | } |
| 6830 | 7292 | |
| 6831 | 7293 | /** |
@@ -6836,8 +7298,11 @@ discard block |
||
| 6836 | 7298 | */ |
| 6837 | 7299 | public function isDate($info) |
| 6838 | 7300 | {
|
| 6839 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6840 | - else return false; |
|
| 7301 | + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) { |
|
| 7302 | + return true; |
|
| 7303 | + } else { |
|
| 7304 | + return false; |
|
| 7305 | + } |
|
| 6841 | 7306 | } |
| 6842 | 7307 | |
| 6843 | 7308 | /** |
@@ -6850,10 +7315,14 @@ discard block |
||
| 6850 | 7315 | {
|
| 6851 | 7316 | if(is_array($info)) |
| 6852 | 7317 | {
|
| 6853 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6854 | - else return false; |
|
| 6855 | - } |
|
| 6856 | - else return false; |
|
| 7318 | + if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) { |
|
| 7319 | + return true; |
|
| 7320 | + } else { |
|
| 7321 | + return false; |
|
| 7322 | + } |
|
| 7323 | + } else { |
|
| 7324 | + return false; |
|
| 7325 | + } |
|
| 6857 | 7326 | } |
| 6858 | 7327 | |
| 6859 | 7328 | /** |
@@ -6866,10 +7335,14 @@ discard block |
||
| 6866 | 7335 | {
|
| 6867 | 7336 | if(is_array($info)) |
| 6868 | 7337 | {
|
| 6869 | - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
|
| 6870 | - else return false; |
|
| 6871 | - } |
|
| 6872 | - else return false; |
|
| 7338 | + if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) { |
|
| 7339 | + return true; |
|
| 7340 | + } else { |
|
| 7341 | + return false; |
|
| 7342 | + } |
|
| 7343 | + } else { |
|
| 7344 | + return false; |
|
| 7345 | + } |
|
| 6873 | 7346 | } |
| 6874 | 7347 | |
| 6875 | 7348 | /** |
@@ -6882,10 +7355,14 @@ discard block |
||
| 6882 | 7355 | {
|
| 6883 | 7356 | if(is_array($info)) |
| 6884 | 7357 | {
|
| 6885 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6886 | - else return false; |
|
| 6887 | - } |
|
| 6888 | - else return false; |
|
| 7358 | + if(isset($info['type']) && $info['type']=='text') { |
|
| 7359 | + return true; |
|
| 7360 | + } else { |
|
| 7361 | + return false; |
|
| 7362 | + } |
|
| 7363 | + } else { |
|
| 7364 | + return false; |
|
| 7365 | + } |
|
| 6889 | 7366 | } |
| 6890 | 7367 | |
| 6891 | 7368 | /** |
@@ -6898,10 +7375,14 @@ discard block |
||
| 6898 | 7375 | {
|
| 6899 | 7376 | if(is_array($info)) |
| 6900 | 7377 | {
|
| 6901 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6902 | - else return false; |
|
| 6903 | - } |
|
| 6904 | - else return false; |
|
| 7378 | + if(isset($info['index']) && $info['index']==true) { |
|
| 7379 | + return true; |
|
| 7380 | + } else { |
|
| 7381 | + return false; |
|
| 7382 | + } |
|
| 7383 | + } else { |
|
| 7384 | + return false; |
|
| 7385 | + } |
|
| 6905 | 7386 | } |
| 6906 | 7387 | |
| 6907 | 7388 | /** |
@@ -6915,21 +7396,21 @@ discard block |
||
| 6915 | 7396 | global $conf; |
| 6916 | 7397 | |
| 6917 | 7398 | $queryarray=array(); |
| 6918 | - foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 7399 | + foreach ($this->fields as $field=>$info) { |
|
| 7400 | + // Loop on definition of fields |
|
| 6919 | 7401 | {
|
| 6920 | 7402 | // Depending on field type ('datetime', ...)
|
| 6921 | 7403 | if($this->isDate($info)) |
| 6922 | 7404 | {
|
| 6923 | 7405 | if(empty($this->{$field}))
|
| 6924 | 7406 | {
|
| 6925 | - $queryarray[$field] = null; |
|
| 6926 | - } |
|
| 6927 | - else |
|
| 7407 | + $queryarray[$field] = null; |
|
| 7408 | + } |
|
| 7409 | + } else |
|
| 6928 | 7410 | {
|
| 6929 | 7411 | $queryarray[$field] = $this->db->idate($this->{$field});
|
| 6930 | 7412 | } |
| 6931 | - } |
|
| 6932 | - else if($this->isArray($info)) |
|
| 7413 | + } else if($this->isArray($info)) |
|
| 6933 | 7414 | {
|
| 6934 | 7415 | if(! empty($this->{$field})) {
|
| 6935 | 7416 | if(! is_array($this->{$field})) {
|
@@ -6939,28 +7420,35 @@ discard block |
||
| 6939 | 7420 | } else {
|
| 6940 | 7421 | $queryarray[$field] = null; |
| 6941 | 7422 | } |
| 6942 | - } |
|
| 6943 | - else if($this->isInt($info)) |
|
| 7423 | + } else if($this->isInt($info)) |
|
| 6944 | 7424 | {
|
| 6945 | - if ($field == 'entity' && is_null($this->{$field})) $queryarray[$field]=$conf->entity;
|
|
| 6946 | - else |
|
| 7425 | + if ($field == 'entity' && is_null($this->{$field})) { |
|
| 7426 | + $queryarray[$field]=$conf->entity; |
|
| 7427 | + } else |
|
| 6947 | 7428 | {
|
| 6948 | 7429 | $queryarray[$field] = (int) price2num($this->{$field});
|
| 6949 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 7430 | + if (empty($queryarray[$field])) { |
|
| 7431 | + $queryarray[$field]=0; |
|
| 7432 | + } |
|
| 7433 | + // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6950 | 7434 | } |
| 6951 | - } |
|
| 6952 | - else if($this->isFloat($info)) |
|
| 7435 | + } else if($this->isFloat($info)) |
|
| 6953 | 7436 | {
|
| 6954 | 7437 | $queryarray[$field] = (double) price2num($this->{$field});
|
| 6955 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6956 | - } |
|
| 6957 | - else |
|
| 7438 | + if (empty($queryarray[$field])) { |
|
| 7439 | + $queryarray[$field]=0; |
|
| 7440 | + } |
|
| 7441 | + } else |
|
| 6958 | 7442 | {
|
| 6959 | 7443 | $queryarray[$field] = $this->{$field};
|
| 6960 | 7444 | } |
| 6961 | 7445 | |
| 6962 | - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6963 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 7446 | + if ($info['type'] == 'timestamp' && empty($queryarray[$field])) { |
|
| 7447 | + unset($queryarray[$field]); |
|
| 7448 | + } |
|
| 7449 | + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) { |
|
| 7450 | + $queryarray[$field] = null; |
|
| 7451 | + } |
|
| 6964 | 7452 | } |
| 6965 | 7453 | |
| 6966 | 7454 | return $queryarray; |
@@ -6978,42 +7466,47 @@ discard block |
||
| 6978 | 7466 | {
|
| 6979 | 7467 | if($this->isDate($info)) |
| 6980 | 7468 | {
|
| 6981 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6982 | - else $this->{$field} = strtotime($obj->{$field});
|
|
| 6983 | - } |
|
| 6984 | - elseif($this->isArray($info)) |
|
| 7469 | + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') { |
|
| 7470 | + $this->{$field} = 0; |
|
| 7471 | + } else { |
|
| 7472 | + $this->{$field} = strtotime($obj->{$field}); |
|
| 7473 | + } |
|
| 7474 | + } elseif($this->isArray($info)) |
|
| 6985 | 7475 | {
|
| 6986 | 7476 | if(! empty($obj->{$field})) {
|
| 6987 | 7477 | $this->{$field} = @unserialize($obj->{$field});
|
| 6988 | 7478 | // Hack for data not in UTF8 |
| 6989 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 7479 | + if($this->{$field } === false) { |
|
| 7480 | + @unserialize(utf8_decode($obj->{$field})); |
|
| 7481 | + } |
|
| 6990 | 7482 | } else {
|
| 6991 | 7483 | $this->{$field} = array();
|
| 6992 | 7484 | } |
| 6993 | - } |
|
| 6994 | - elseif($this->isInt($info)) |
|
| 7485 | + } elseif($this->isInt($info)) |
|
| 6995 | 7486 | {
|
| 6996 | - if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
|
| 6997 | - else $this->{$field} = (int) $obj->{$field};
|
|
| 6998 | - } |
|
| 6999 | - elseif($this->isFloat($info)) |
|
| 7487 | + if ($field == 'rowid') { |
|
| 7488 | + $this->id = (int) $obj->{$field}; |
|
| 7489 | + } else { |
|
| 7490 | + $this->{$field} = (int) $obj->{$field}; |
|
| 7491 | + } |
|
| 7492 | + } elseif($this->isFloat($info)) |
|
| 7000 | 7493 | {
|
| 7001 | 7494 | $this->{$field} = (double) $obj->{$field};
|
| 7002 | - } |
|
| 7003 | - elseif($this->isNull($info)) |
|
| 7495 | + } elseif($this->isNull($info)) |
|
| 7004 | 7496 | {
|
| 7005 | 7497 | $val = $obj->{$field};
|
| 7006 | 7498 | // zero is not null |
| 7007 | 7499 | $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
| 7008 | - } |
|
| 7009 | - else |
|
| 7500 | + } else |
|
| 7010 | 7501 | {
|
| 7011 | 7502 | $this->{$field} = $obj->{$field};
|
| 7012 | 7503 | } |
| 7013 | 7504 | } |
| 7014 | 7505 | |
| 7015 | 7506 | // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
| 7016 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7507 | + if (! isset($this->fields['ref']) && isset($this->id)) { |
|
| 7508 | + $this->ref = $this->id; |
|
| 7509 | + } |
|
| 7017 | 7510 | } |
| 7018 | 7511 | |
| 7019 | 7512 | /** |
@@ -7036,9 +7529,13 @@ discard block |
||
| 7036 | 7529 | */ |
| 7037 | 7530 | protected function quote($value, $fieldsentry) |
| 7038 | 7531 | {
|
| 7039 | - if (is_null($value)) return 'NULL'; |
|
| 7040 | - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
|
|
| 7041 | - else return "'".$this->db->escape($value)."'"; |
|
| 7532 | + if (is_null($value)) { |
|
| 7533 | + return 'NULL'; |
|
| 7534 | + } else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) { |
|
| 7535 | + return $this->db->escape("$value"); |
|
| 7536 | + } else { |
|
| 7537 | + return "'".$this->db->escape($value)."'"; |
|
| 7538 | + } |
|
| 7042 | 7539 | } |
| 7043 | 7540 | |
| 7044 | 7541 | |
@@ -7058,8 +7555,12 @@ discard block |
||
| 7058 | 7555 | $now=dol_now(); |
| 7059 | 7556 | |
| 7060 | 7557 | $fieldvalues = $this->setSaveQuery(); |
| 7061 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7062 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7558 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) { |
|
| 7559 | + $fieldvalues['date_creation']=$this->db->idate($now); |
|
| 7560 | + } |
|
| 7561 | + if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) { |
|
| 7562 | + $fieldvalues['fk_user_creat']=$user->id; |
|
| 7563 | + } |
|
| 7063 | 7564 | unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
| 7064 | 7565 | |
| 7065 | 7566 | $keys=array(); |
@@ -7074,8 +7575,12 @@ discard block |
||
| 7074 | 7575 | foreach($keys as $key) |
| 7075 | 7576 | {
|
| 7076 | 7577 | // If field is an implicit foreign key field |
| 7077 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7078 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7578 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { |
|
| 7579 | + $values[$key]=''; |
|
| 7580 | + } |
|
| 7581 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { |
|
| 7582 | + $values[$key]=''; |
|
| 7583 | + } |
|
| 7079 | 7584 | |
| 7080 | 7585 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7081 | 7586 | if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
@@ -7085,11 +7590,17 @@ discard block |
||
| 7085 | 7590 | } |
| 7086 | 7591 | |
| 7087 | 7592 | // If field is an implicit foreign key field |
| 7088 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7089 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7593 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) { |
|
| 7594 | + $values[$key]='null'; |
|
| 7595 | + } |
|
| 7596 | + if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) { |
|
| 7597 | + $values[$key]='null'; |
|
| 7598 | + } |
|
| 7090 | 7599 | } |
| 7091 | 7600 | |
| 7092 | - if ($error) return -1; |
|
| 7601 | + if ($error) { |
|
| 7602 | + return -1; |
|
| 7603 | + } |
|
| 7093 | 7604 | |
| 7094 | 7605 | $this->db->begin(); |
| 7095 | 7606 | |
@@ -7115,7 +7626,9 @@ discard block |
||
| 7115 | 7626 | if (! $error) |
| 7116 | 7627 | {
|
| 7117 | 7628 | $result=$this->insertExtraFields(); |
| 7118 | - if ($result < 0) $error++; |
|
| 7629 | + if ($result < 0) { |
|
| 7630 | + $error++; |
|
| 7631 | + } |
|
| 7119 | 7632 | } |
| 7120 | 7633 | |
| 7121 | 7634 | // Triggers |
@@ -7148,15 +7661,24 @@ discard block |
||
| 7148 | 7661 | */ |
| 7149 | 7662 | public function fetchCommon($id, $ref = null, $morewhere = '') |
| 7150 | 7663 | {
|
| 7151 | - if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 7664 | + if (empty($id) && empty($ref) && empty($morewhere)) { |
|
| 7665 | + return -1; |
|
| 7666 | + } |
|
| 7152 | 7667 | |
| 7153 | 7668 | $sql = 'SELECT '.$this->getFieldList(); |
| 7154 | 7669 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
| 7155 | 7670 | |
| 7156 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7157 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7158 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7159 | - if ($morewhere) $sql.= $morewhere; |
|
| 7671 | + if (!empty($id)) { |
|
| 7672 | + $sql.= ' WHERE rowid = '.$id; |
|
| 7673 | + } elseif (!empty($ref)) { |
|
| 7674 | + $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7675 | + } else { |
|
| 7676 | + $sql.=' WHERE 1 = 1'; |
|
| 7677 | + } |
|
| 7678 | + // usage with empty id and empty ref is very rare |
|
| 7679 | + if ($morewhere) { |
|
| 7680 | + $sql.= $morewhere; |
|
| 7681 | + } |
|
| 7160 | 7682 | $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
| 7161 | 7683 | |
| 7162 | 7684 | $res = $this->db->query($sql); |
@@ -7167,13 +7689,11 @@ discard block |
||
| 7167 | 7689 | {
|
| 7168 | 7690 | $this->setVarsFromFetchObj($obj); |
| 7169 | 7691 | return $this->id; |
| 7170 | - } |
|
| 7171 | - else |
|
| 7692 | + } else |
|
| 7172 | 7693 | {
|
| 7173 | 7694 | return 0; |
| 7174 | 7695 | } |
| 7175 | - } |
|
| 7176 | - else |
|
| 7696 | + } else |
|
| 7177 | 7697 | {
|
| 7178 | 7698 | $this->error = $this->db->lasterror(); |
| 7179 | 7699 | $this->errors[] = $this->error; |
@@ -7197,8 +7717,12 @@ discard block |
||
| 7197 | 7717 | $now=dol_now(); |
| 7198 | 7718 | |
| 7199 | 7719 | $fieldvalues = $this->setSaveQuery(); |
| 7200 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7201 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7720 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) { |
|
| 7721 | + $fieldvalues['date_modification']=$this->db->idate($now); |
|
| 7722 | + } |
|
| 7723 | + if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) { |
|
| 7724 | + $fieldvalues['fk_user_modif']=$user->id; |
|
| 7725 | + } |
|
| 7202 | 7726 | unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
| 7203 | 7727 | |
| 7204 | 7728 | $keys=array(); |
@@ -7213,8 +7737,14 @@ discard block |
||
| 7213 | 7737 | // Clean and check mandatory |
| 7214 | 7738 | foreach($keys as $key) |
| 7215 | 7739 | {
|
| 7216 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7217 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7740 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { |
|
| 7741 | + $values[$key]=''; |
|
| 7742 | + } |
|
| 7743 | + // This is an implicit foreign key field |
|
| 7744 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { |
|
| 7745 | + $values[$key]=''; |
|
| 7746 | + } |
|
| 7747 | + // This is an explicit foreign key field |
|
| 7218 | 7748 | |
| 7219 | 7749 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7220 | 7750 | /* |
@@ -7295,10 +7825,11 @@ discard block |
||
| 7295 | 7825 | return -1; |
| 7296 | 7826 | } |
| 7297 | 7827 | } |
| 7298 | - } |
|
| 7299 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7828 | + } elseif (! empty($this->fk_element) && ! empty($this->childtables)) { |
|
| 7829 | + // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7300 | 7830 | {
|
| 7301 | - $objectisused = $this->isObjectUsed($this->id); |
|
| 7831 | + $objectisused = $this->isObjectUsed($this->id); |
|
| 7832 | + } |
|
| 7302 | 7833 | if (! empty($objectisused)) |
| 7303 | 7834 | {
|
| 7304 | 7835 | dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
@@ -7405,7 +7936,9 @@ discard block |
||
| 7405 | 7936 | */ |
| 7406 | 7937 | public function trimParameters($parameters) |
| 7407 | 7938 | {
|
| 7408 | - if (!is_array($parameters)) return; |
|
| 7939 | + if (!is_array($parameters)) { |
|
| 7940 | + return; |
|
| 7941 | + } |
|
| 7409 | 7942 | foreach ($parameters as $parameter) {
|
| 7410 | 7943 | if (isset($this->$parameter)) {
|
| 7411 | 7944 | $this->$parameter = trim($this->$parameter); |
@@ -111,13 +111,13 @@ discard block |
||
| 111 | 111 | if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;/', $typeofdata)) {
|
| 112 | 112 | if (!empty($perm)) {
|
| 113 | 113 | $tmp = explode(':', $typeofdata);
|
| 114 | - $ret .= '<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ? ' ' . $tmp[1] : '') . '" id="' . $htmlname . '">'; |
|
| 114 | + $ret .= '<div class="editkey_'.$tmp[0].(!empty($tmp[1]) ? ' '.$tmp[1] : '').'" id="'.$htmlname.'">'; |
|
| 115 | 115 | if ($fieldrequired) |
| 116 | 116 | $ret .= '<span class="fieldrequired">'; |
| 117 | 117 | $ret .= $langs->trans($text); |
| 118 | 118 | if ($fieldrequired) |
| 119 | 119 | $ret .= '</span>'; |
| 120 | - $ret .= '</div>' . "\n"; |
|
| 120 | + $ret .= '</div>'."\n"; |
|
| 121 | 121 | } |
| 122 | 122 | else {
|
| 123 | 123 | if ($fieldrequired) |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | else {
|
| 131 | - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
|
| 131 | + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
|
|
| 132 | 132 | $ret .= '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">'; |
| 133 | 133 | } |
| 134 | 134 | if ($fieldrequired) {
|
@@ -141,14 +141,14 @@ discard block |
||
| 141 | 141 | if (!empty($notabletag)) {
|
| 142 | 142 | $ret .= ' '; |
| 143 | 143 | } |
| 144 | - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
|
| 144 | + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
|
|
| 145 | 145 | $ret .= '</td>'; |
| 146 | 146 | } |
| 147 | - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
|
| 147 | + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
|
|
| 148 | 148 | $ret .= '<td align="right">'; |
| 149 | 149 | } |
| 150 | - if ($htmlname && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
|
| 151 | - $ret .= '<a href="' . $_SERVER["PHP_SELF"] . '?action=edit' . $htmlname . '&' . $paramid . '=' . $object->id . $moreparam . '">' . img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)) . '</a>';
|
|
| 150 | + if ($htmlname && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
|
|
| 151 | + $ret .= '<a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&'.$paramid.'='.$object->id.$moreparam.'">'.img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)).'</a>';
|
|
| 152 | 152 | } |
| 153 | 153 | if (!empty($notabletag) && $notabletag == 1) {
|
| 154 | 154 | $ret .= ' : '; |
@@ -156,10 +156,10 @@ discard block |
||
| 156 | 156 | if (!empty($notabletag) && $notabletag == 3) {
|
| 157 | 157 | $ret .= ' '; |
| 158 | 158 | } |
| 159 | - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
|
| 159 | + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
|
|
| 160 | 160 | $ret .= '</td>'; |
| 161 | 161 | } |
| 162 | - if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
|
| 162 | + if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit'.$htmlname && $perm) {
|
|
| 163 | 163 | $ret .= '</tr></table>'; |
| 164 | 164 | } |
| 165 | 165 | } |
@@ -199,41 +199,41 @@ discard block |
||
| 199 | 199 | if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) { // TODO add jquery timepicker
|
| 200 | 200 | $ret .= $this->editInPlace($object, $value, $htmlname, $perm, $typeofdata, $editvalue, $extObject, $custommsg); |
| 201 | 201 | } else {
|
| 202 | - if (GETPOST('action', 'aZ09') == 'edit' . $htmlname) {
|
|
| 202 | + if (GETPOST('action', 'aZ09') == 'edit'.$htmlname) {
|
|
| 203 | 203 | $ret .= "\n"; |
| 204 | - $ret .= '<form method="post" action="' . $_SERVER["PHP_SELF"] . ($moreparam ? '?' . $moreparam : '') . '">'; |
|
| 205 | - $ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">'; |
|
| 206 | - $ret .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 207 | - $ret .= '<input type="hidden" name="' . $paramid . '" value="' . $object->id . '">'; |
|
| 204 | + $ret .= '<form method="post" action="'.$_SERVER["PHP_SELF"].($moreparam ? '?'.$moreparam : '').'">'; |
|
| 205 | + $ret .= '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
|
| 206 | + $ret .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 207 | + $ret .= '<input type="hidden" name="'.$paramid.'" value="'.$object->id.'">'; |
|
| 208 | 208 | if (empty($notabletag)) |
| 209 | 209 | $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">'; |
| 210 | 210 | if (empty($notabletag)) |
| 211 | 211 | $ret .= '<tr><td>'; |
| 212 | 212 | if (preg_match('/^(string|email)/', $typeofdata)) {
|
| 213 | 213 | $tmp = explode(':', $typeofdata);
|
| 214 | - $ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ($editvalue ? $editvalue : $value) . '"' . ($tmp[1] ? ' size="' . $tmp[1] . '"' : '') . '>'; |
|
| 214 | + $ret .= '<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue ? $editvalue : $value).'"'.($tmp[1] ? ' size="'.$tmp[1].'"' : '').'>'; |
|
| 215 | 215 | } else if (preg_match('/^(numeric|amount)/', $typeofdata)) {
|
| 216 | 216 | $tmp = explode(':', $typeofdata);
|
| 217 | 217 | $valuetoshow = price2num($editvalue ? $editvalue : $value); |
| 218 | - $ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ($valuetoshow != '' ? price($valuetoshow) : '') . '"' . ($tmp[1] ? ' size="' . $tmp[1] . '"' : '') . '>'; |
|
| 218 | + $ret .= '<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($valuetoshow != '' ? price($valuetoshow) : '').'"'.($tmp[1] ? ' size="'.$tmp[1].'"' : '').'>'; |
|
| 219 | 219 | } else if (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) {
|
| 220 | 220 | $tmp = explode(':', $typeofdata);
|
| 221 | 221 | $cols = $tmp[2]; |
| 222 | 222 | $morealt = ''; |
| 223 | 223 | if (preg_match('/%/', $cols)) {
|
| 224 | - $morealt = ' style="width: ' . $cols . '"'; |
|
| 224 | + $morealt = ' style="width: '.$cols.'"'; |
|
| 225 | 225 | $cols = ''; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | $valuetoshow = ($editvalue ? $editvalue : $value); |
| 229 | 229 | |
| 230 | - $ret .= '<textarea id="' . $htmlname . '" name="' . $htmlname . '" wrap="soft" rows="' . ($tmp[1] ? $tmp[1] : '20') . '"' . ($cols ? ' cols="' . $cols . '"' : 'class="quatrevingtpercent"') . $morealt . '">'; |
|
| 230 | + $ret .= '<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" rows="'.($tmp[1] ? $tmp[1] : '20').'"'.($cols ? ' cols="'.$cols.'"' : 'class="quatrevingtpercent"').$morealt.'">'; |
|
| 231 | 231 | $ret .= dol_string_neverthesehtmltags($valuetoshow, array('textarea'));
|
| 232 | 232 | $ret .= '</textarea>'; |
| 233 | 233 | } else if ($typeofdata == 'day' || $typeofdata == 'datepicker') {
|
| 234 | - $ret .= $this->selectDate($value, $htmlname, 0, 0, 1, 'form' . $htmlname, 1, 0); |
|
| 234 | + $ret .= $this->selectDate($value, $htmlname, 0, 0, 1, 'form'.$htmlname, 1, 0); |
|
| 235 | 235 | } else if ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') {
|
| 236 | - $ret .= $this->selectDate($value, $htmlname, 1, 1, 1, 'form' . $htmlname, 1, 0); |
|
| 236 | + $ret .= $this->selectDate($value, $htmlname, 1, 1, 1, 'form'.$htmlname, 1, 0); |
|
| 237 | 237 | } else if (preg_match('/^select;/', $typeofdata)) {
|
| 238 | 238 | $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata));
|
| 239 | 239 | foreach ($arraydata as $val) {
|
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | $ret .= $this->selectarray($htmlname, $arraylist, $value); |
| 244 | 244 | } else if (preg_match('/^ckeditor/', $typeofdata)) {
|
| 245 | - $tmp = explode(':', $typeofdata); // Example: ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols
|
|
| 246 | - require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; |
|
| 245 | + $tmp = explode(':', $typeofdata); // Example: ckeditor:dolibarr_zzz:width:height:savemethod:toolbarstartexpanded:rows:cols
|
|
| 246 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 247 | 247 | $doleditor = new DolEditor($htmlname, ($editvalue ? $editvalue : $value), ($tmp[2] ? $tmp[2] : ''), ($tmp[3] ? $tmp[3] : '100'), ($tmp[1] ? $tmp[1] : 'dolibarr_notes'), 'In', ($tmp[5] ? $tmp[5] : 0), true, true, ($tmp[6] ? $tmp[6] : '20'), ($tmp[7] ? $tmp[7] : '100')); |
| 248 | 248 | $ret .= $doleditor->Create(1); |
| 249 | 249 | } |
@@ -253,16 +253,16 @@ discard block |
||
| 253 | 253 | if (empty($notabletag)) |
| 254 | 254 | $ret .= '<td align="left">'; |
| 255 | 255 | //else $ret.='<div class="clearboth"></div>'; |
| 256 | - $ret .= '<input type="submit" class="button' . (empty($notabletag) ? '' : ' ') . '" name="modify" value="' . $langs->trans("Modify") . '">';
|
|
| 256 | + $ret .= '<input type="submit" class="button'.(empty($notabletag) ? '' : ' ').'" name="modify" value="'.$langs->trans("Modify").'">';
|
|
| 257 | 257 | if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag))
|
| 258 | - $ret .= '<br>' . "\n"; |
|
| 259 | - $ret .= '<input type="submit" class="button' . (empty($notabletag) ? '' : ' ') . '" name="cancel" value="' . $langs->trans("Cancel") . '">';
|
|
| 258 | + $ret .= '<br>'."\n"; |
|
| 259 | + $ret .= '<input type="submit" class="button'.(empty($notabletag) ? '' : ' ').'" name="cancel" value="'.$langs->trans("Cancel").'">';
|
|
| 260 | 260 | if (empty($notabletag)) |
| 261 | 261 | $ret .= '</td>'; |
| 262 | 262 | |
| 263 | 263 | if (empty($notabletag)) |
| 264 | - $ret .= '</tr></table>' . "\n"; |
|
| 265 | - $ret .= '</form>' . "\n"; |
|
| 264 | + $ret .= '</tr></table>'."\n"; |
|
| 265 | + $ret .= '</form>'."\n"; |
|
| 266 | 266 | } |
| 267 | 267 | else {
|
| 268 | 268 | if (preg_match('/^(email)/', $typeofdata))
|
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
|
| 288 | 288 | $firstline = preg_replace('/<br>.*/', '', $tmpcontent);
|
| 289 | 289 | $firstline = preg_replace('/[\n\r].*/', '', $firstline);
|
| 290 | - $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ? '...' : ''); |
|
| 290 | + $tmpcontent = $firstline.((strlen($firstline) != strlen($tmpcontent)) ? '...' : ''); |
|
| 291 | 291 | } |
| 292 | 292 | $ret .= $tmpcontent; |
| 293 | 293 | } else |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | $inputOption = $tmp[1]; |
| 356 | 356 | if (!empty($tmp[2])) |
| 357 | 357 | $savemethod = $tmp[2]; |
| 358 | - $out .= '<input id="width_' . $htmlname . '" value="' . $inputOption . '" type="hidden"/>' . "\n"; |
|
| 358 | + $out .= '<input id="width_'.$htmlname.'" value="'.$inputOption.'" type="hidden"/>'."\n"; |
|
| 359 | 359 | } |
| 360 | 360 | else if ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) {
|
| 361 | 361 | $tmp = explode(':', $inputType);
|
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | if (!empty($tmp[2])) |
| 366 | 366 | $savemethod = $tmp[2]; |
| 367 | 367 | |
| 368 | - $out .= '<input id="timestamp" type="hidden"/>' . "\n"; // Use for timestamp format |
|
| 368 | + $out .= '<input id="timestamp" type="hidden"/>'."\n"; // Use for timestamp format |
|
| 369 | 369 | } |
| 370 | 370 | else if (preg_match('/^(select|autocomplete)/', $inputType)) {
|
| 371 | 371 | $tmp = explode(':', $inputType);
|
@@ -393,35 +393,35 @@ discard block |
||
| 393 | 393 | $savemethod = $tmp[4]; |
| 394 | 394 | |
| 395 | 395 | if (!empty($conf->fckeditor->enabled)) {
|
| 396 | - $out .= '<input id="ckeditor_toolbar" value="' . $toolbar . '" type="hidden"/>' . "\n"; |
|
| 396 | + $out .= '<input id="ckeditor_toolbar" value="'.$toolbar.'" type="hidden"/>'."\n"; |
|
| 397 | 397 | } else {
|
| 398 | 398 | $inputType = 'textarea'; |
| 399 | 399 | } |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | - $out .= '<input id="element_' . $htmlname . '" value="' . $element . '" type="hidden"/>' . "\n"; |
|
| 403 | - $out .= '<input id="table_element_' . $htmlname . '" value="' . $table_element . '" type="hidden"/>' . "\n"; |
|
| 404 | - $out .= '<input id="fk_element_' . $htmlname . '" value="' . $fk_element . '" type="hidden"/>' . "\n"; |
|
| 405 | - $out .= '<input id="loadmethod_' . $htmlname . '" value="' . $loadmethod . '" type="hidden"/>' . "\n"; |
|
| 402 | + $out .= '<input id="element_'.$htmlname.'" value="'.$element.'" type="hidden"/>'."\n"; |
|
| 403 | + $out .= '<input id="table_element_'.$htmlname.'" value="'.$table_element.'" type="hidden"/>'."\n"; |
|
| 404 | + $out .= '<input id="fk_element_'.$htmlname.'" value="'.$fk_element.'" type="hidden"/>'."\n"; |
|
| 405 | + $out .= '<input id="loadmethod_'.$htmlname.'" value="'.$loadmethod.'" type="hidden"/>'."\n"; |
|
| 406 | 406 | if (!empty($savemethod)) |
| 407 | - $out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . "\n"; |
|
| 407 | + $out .= '<input id="savemethod_'.$htmlname.'" value="'.$savemethod.'" type="hidden"/>'."\n"; |
|
| 408 | 408 | if (!empty($ext_element)) |
| 409 | - $out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . "\n"; |
|
| 409 | + $out .= '<input id="ext_element_'.$htmlname.'" value="'.$ext_element.'" type="hidden"/>'."\n"; |
|
| 410 | 410 | if (!empty($custommsg)) {
|
| 411 | 411 | if (is_array($custommsg)) {
|
| 412 | 412 | if (!empty($custommsg['success'])) |
| 413 | - $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg['success'] . '" type="hidden"/>' . "\n"; |
|
| 413 | + $out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg['success'].'" type="hidden"/>'."\n"; |
|
| 414 | 414 | if (!empty($custommsg['error'])) |
| 415 | - $out .= '<input id="errormsg_' . $htmlname . '" value="' . $custommsg['error'] . '" type="hidden"/>' . "\n"; |
|
| 415 | + $out .= '<input id="errormsg_'.$htmlname.'" value="'.$custommsg['error'].'" type="hidden"/>'."\n"; |
|
| 416 | 416 | } else |
| 417 | - $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg . '" type="hidden"/>' . "\n"; |
|
| 417 | + $out .= '<input id="successmsg_'.$htmlname.'" value="'.$custommsg.'" type="hidden"/>'."\n"; |
|
| 418 | 418 | } |
| 419 | 419 | if ($inputType == 'textarea') {
|
| 420 | - $out .= '<input id="textarea_' . $htmlname . '_rows" value="' . $rows . '" type="hidden"/>' . "\n"; |
|
| 421 | - $out .= '<input id="textarea_' . $htmlname . '_cols" value="' . $cols . '" type="hidden"/>' . "\n"; |
|
| 420 | + $out .= '<input id="textarea_'.$htmlname.'_rows" value="'.$rows.'" type="hidden"/>'."\n"; |
|
| 421 | + $out .= '<input id="textarea_'.$htmlname.'_cols" value="'.$cols.'" type="hidden"/>'."\n"; |
|
| 422 | 422 | } |
| 423 | - $out .= '<span id="viewval_' . $htmlname . '" class="viewval_' . $inputType . ($button_only ? ' inactive' : ' active') . '">' . $value . '</span>' . "\n"; |
|
| 424 | - $out .= '<span id="editval_' . $htmlname . '" class="editval_' . $inputType . ($button_only ? ' inactive' : ' active') . ' hideobject">' . (!empty($editvalue) ? $editvalue : $value) . '</span>' . "\n"; |
|
| 423 | + $out .= '<span id="viewval_'.$htmlname.'" class="viewval_'.$inputType.($button_only ? ' inactive' : ' active').'">'.$value.'</span>'."\n"; |
|
| 424 | + $out .= '<span id="editval_'.$htmlname.'" class="editval_'.$inputType.($button_only ? ' inactive' : ' active').' hideobject">'.(!empty($editvalue) ? $editvalue : $value).'</span>'."\n"; |
|
| 425 | 425 | } else {
|
| 426 | 426 | $out = $value; |
| 427 | 427 | } |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | global $conf; |
| 454 | 454 | |
| 455 | 455 | if ($incbefore) {
|
| 456 | - $text = $incbefore . $text; |
|
| 456 | + $text = $incbefore.$text; |
|
| 457 | 457 | } |
| 458 | 458 | if (!$htmltext) {
|
| 459 | 459 | return $text; |
@@ -473,11 +473,11 @@ discard block |
||
| 473 | 473 | |
| 474 | 474 | $extrastyle = ''; |
| 475 | 475 | if ($direction < 0) {
|
| 476 | - $extracss = ($extracss ? $extracss . ' ' : '') . 'inline-block'; |
|
| 476 | + $extracss = ($extracss ? $extracss.' ' : '').'inline-block'; |
|
| 477 | 477 | $extrastyle = 'padding: 0px; padding-left: 3px !important;'; |
| 478 | 478 | } |
| 479 | 479 | if ($direction > 0) {
|
| 480 | - $extracss = ($extracss ? $extracss . ' ' : '') . 'inline-block'; |
|
| 480 | + $extracss = ($extracss ? $extracss.' ' : '').'inline-block'; |
|
| 481 | 481 | $extrastyle = 'padding: 0px; padding-right: 3px !important;'; |
| 482 | 482 | } |
| 483 | 483 | |
@@ -490,53 +490,53 @@ discard block |
||
| 490 | 490 | $htmltext = str_replace('"', """, $htmltext);
|
| 491 | 491 | } else {
|
| 492 | 492 | $classfortooltip = 'classfortooltiponclick'; |
| 493 | - $textfordialog .= '<div style="display: none;" id="idfortooltiponclick_' . $tooltiptrigger . '" class="classfortooltiponclicktext">' . $htmltext . '</div>'; |
|
| 493 | + $textfordialog .= '<div style="display: none;" id="idfortooltiponclick_'.$tooltiptrigger.'" class="classfortooltiponclicktext">'.$htmltext.'</div>'; |
|
| 494 | 494 | } |
| 495 | 495 | if ($tooltipon == 2 || $tooltipon == 3) {
|
| 496 | - $paramfortooltipimg = ' class="' . $classfortooltip . ' inline-block' . ($extracss ? ' ' . $extracss : '') . '" style="padding: 0px;' . ($extrastyle ? ' ' . $extrastyle : '') . '"'; |
|
| 496 | + $paramfortooltipimg = ' class="'.$classfortooltip.' inline-block'.($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'"'; |
|
| 497 | 497 | if ($tooltiptrigger == '') {
|
| 498 | - $paramfortooltipimg .= ' title="' . ($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)) . '"'; // Attribut to put on img tag to store tooltip |
|
| 498 | + $paramfortooltipimg .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on img tag to store tooltip |
|
| 499 | 499 | } else {
|
| 500 | - $paramfortooltipimg .= ' dolid="' . $tooltiptrigger . '"'; |
|
| 500 | + $paramfortooltipimg .= ' dolid="'.$tooltiptrigger.'"'; |
|
| 501 | 501 | } |
| 502 | 502 | } else {
|
| 503 | - $paramfortooltipimg = ($extracss ? ' class="' . $extracss . '"' : '') . ($extrastyle ? ' style="' . $extrastyle . '"' : ''); // Attribut to put on td text tag |
|
| 503 | + $paramfortooltipimg = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag |
|
| 504 | 504 | } |
| 505 | 505 | if ($tooltipon == 1 || $tooltipon == 3) {
|
| 506 | - $paramfortooltiptd = ' class="' . ($tooltipon == 3 ? 'cursorpointer ' : '') . $classfortooltip . ' inline-block' . ($extracss ? ' ' . $extracss : '') . '" style="padding: 0px;' . ($extrastyle ? ' ' . $extrastyle : '') . '" '; |
|
| 506 | + $paramfortooltiptd = ' class="'.($tooltipon == 3 ? 'cursorpointer ' : '').$classfortooltip.' inline-block'.($extracss ? ' '.$extracss : '').'" style="padding: 0px;'.($extrastyle ? ' '.$extrastyle : '').'" '; |
|
| 507 | 507 | if ($tooltiptrigger == '') {
|
| 508 | - $paramfortooltiptd .= ' title="' . ($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)) . '"'; // Attribut to put on td tag to store tooltip |
|
| 508 | + $paramfortooltiptd .= ' title="'.($noencodehtmltext ? $htmltext : dol_escape_htmltag($htmltext, 1)).'"'; // Attribut to put on td tag to store tooltip |
|
| 509 | 509 | } else {
|
| 510 | - $paramfortooltiptd .= ' dolid="' . $tooltiptrigger . '"'; |
|
| 510 | + $paramfortooltiptd .= ' dolid="'.$tooltiptrigger.'"'; |
|
| 511 | 511 | } |
| 512 | 512 | } else {
|
| 513 | - $paramfortooltiptd = ($extracss ? ' class="' . $extracss . '"' : '') . ($extrastyle ? ' style="' . $extrastyle . '"' : ''); // Attribut to put on td text tag |
|
| 513 | + $paramfortooltiptd = ($extracss ? ' class="'.$extracss.'"' : '').($extrastyle ? ' style="'.$extrastyle.'"' : ''); // Attribut to put on td text tag |
|
| 514 | 514 | } |
| 515 | 515 | if (empty($notabs)) {
|
| 516 | 516 | $s .= '<table class="nobordernopadding" summary=""><tr style="height: auto;">'; |
| 517 | 517 | } elseif ($notabs == 2) {
|
| 518 | - $s .= '<div class="inline-block' . ($forcenowrap ? ' nowrap' : '') . '">'; |
|
| 518 | + $s .= '<div class="inline-block'.($forcenowrap ? ' nowrap' : '').'">'; |
|
| 519 | 519 | } |
| 520 | 520 | // Define value if value is before |
| 521 | 521 | if ($direction < 0) {
|
| 522 | - $s .= '<' . $tag . $paramfortooltipimg; |
|
| 522 | + $s .= '<'.$tag.$paramfortooltipimg; |
|
| 523 | 523 | if ($tag == 'td') {
|
| 524 | 524 | $s .= ' valign="top" width="14"'; |
| 525 | 525 | } |
| 526 | - $s .= '>' . $textfordialog . $img . '</' . $tag . '>'; |
|
| 526 | + $s .= '>'.$textfordialog.$img.'</'.$tag.'>'; |
|
| 527 | 527 | } |
| 528 | 528 | // Use another method to help avoid having a space in value in order to use this value with jquery |
| 529 | 529 | // Define label |
| 530 | 530 | if ((string) $text != '') {
|
| 531 | - $s .= '<' . $tag . $paramfortooltiptd . '>' . $text . '</' . $tag . '>'; |
|
| 531 | + $s .= '<'.$tag.$paramfortooltiptd.'>'.$text.'</'.$tag.'>'; |
|
| 532 | 532 | } |
| 533 | 533 | // Define value if value is after |
| 534 | 534 | if ($direction > 0) {
|
| 535 | - $s .= '<' . $tag . $paramfortooltipimg; |
|
| 535 | + $s .= '<'.$tag.$paramfortooltipimg; |
|
| 536 | 536 | if ($tag == 'td') {
|
| 537 | 537 | $s .= ' valign="middle" width="14"'; |
| 538 | 538 | } |
| 539 | - $s .= '>' . $textfordialog . $img . '</' . $tag . '>'; |
|
| 539 | + $s .= '>'.$textfordialog.$img.'</'.$tag.'>'; |
|
| 540 | 540 | } |
| 541 | 541 | if (empty($notabs)) {
|
| 542 | 542 | $s .= '</tr></table>'; |
@@ -629,15 +629,15 @@ discard block |
||
| 629 | 629 | |
| 630 | 630 | $disabled = 0; |
| 631 | 631 | $ret = '<div class="centpercent center">'; |
| 632 | - $ret .= '<select class="flat' . (empty($conf->use_javascript_ajax) ? '' : ' hideobject') . ' massaction massactionselect" name="massaction"' . ($disabled ? ' disabled="disabled"' : '') . '>'; |
|
| 632 | + $ret .= '<select class="flat'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' massaction massactionselect" name="massaction"'.($disabled ? ' disabled="disabled"' : '').'>'; |
|
| 633 | 633 | |
| 634 | 634 | // Complete list with data from external modules. THe module can use $_SERVER['PHP_SELF'] to know on which page we are, or use the $parameters['currentcontext'] completed by executeHooks. |
| 635 | 635 | $parameters = array(); |
| 636 | - $reshook = $hookmanager->executeHooks('addMoreMassActions', $parameters); // Note that $action and $object may have been modified by hook
|
|
| 636 | + $reshook = $hookmanager->executeHooks('addMoreMassActions', $parameters); // Note that $action and $object may have been modified by hook
|
|
| 637 | 637 | if (empty($reshook)) {
|
| 638 | - $ret .= '<option value="0"' . ($disabled ? ' disabled="disabled"' : '') . '>-- ' . $langs->trans("SelectAction") . ' --</option>';
|
|
| 638 | + $ret .= '<option value="0"'.($disabled ? ' disabled="disabled"' : '').'>-- '.$langs->trans("SelectAction").' --</option>';
|
|
| 639 | 639 | foreach ($arrayofaction as $code => $label) {
|
| 640 | - $ret .= '<option value="' . $code . '"' . ($disabled ? ' disabled="disabled"' : '') . '>' . $label . '</option>'; |
|
| 640 | + $ret .= '<option value="'.$code.'"'.($disabled ? ' disabled="disabled"' : '').'>'.$label.'</option>'; |
|
| 641 | 641 | } |
| 642 | 642 | } |
| 643 | 643 | $ret .= $hookmanager->resPrint; |
@@ -645,7 +645,7 @@ discard block |
||
| 645 | 645 | $ret .= '</select>'; |
| 646 | 646 | // Warning: if you set submit button to disabled, post using 'Enter' will no more work if there is no another input submit. So we add a hidden button |
| 647 | 647 | $ret .= '<input type="submit" name="confirmmassactioninvisible" style="display: none" tabindex="-1">'; // Hidden button BEFORE so it is the one used when we submit with ENTER. |
| 648 | - $ret .= '<input type="submit" disabled name="confirmmassaction" class="button' . (empty($conf->use_javascript_ajax) ? '' : ' hideobject') . ' massaction massactionconfirmed" value="' . dol_escape_htmltag($langs->trans("Confirm")) . '">';
|
|
| 648 | + $ret .= '<input type="submit" disabled name="confirmmassaction" class="button'.(empty($conf->use_javascript_ajax) ? '' : ' hideobject').' massaction massactionconfirmed" value="'.dol_escape_htmltag($langs->trans("Confirm")).'">';
|
|
| 649 | 649 | $ret .= '</div>'; |
| 650 | 650 | |
| 651 | 651 | if (!empty($conf->use_javascript_ajax)) {
|
@@ -659,11 +659,11 @@ discard block |
||
| 659 | 659 | if ($(this).is(\':checked\')) atleastoneselected++; |
| 660 | 660 | }); |
| 661 | 661 | console.log("initCheckForSelect mode="+mode+" atleastoneselected="+atleastoneselected);
|
| 662 | - if (atleastoneselected || ' . $alwaysvisible . ') |
|
| 662 | + if (atleastoneselected || ' . $alwaysvisible.') |
|
| 663 | 663 | {
|
| 664 | 664 | jQuery(".massaction").show();
|
| 665 | - ' . ($selected ? 'if (atleastoneselected) { jQuery(".massactionselect").val("' . $selected . '"); jQuery(".massactionconfirmed").prop(\'disabled\', false); }' : '') . '
|
|
| 666 | - ' . ($selected ? 'if (! atleastoneselected) { jQuery(".massactionselect").val("0"); jQuery(".massactionconfirmed").prop(\'disabled\', true); } ' : '') . '
|
|
| 665 | + ' . ($selected ? 'if (atleastoneselected) { jQuery(".massactionselect").val("'.$selected.'"); jQuery(".massactionconfirmed").prop(\'disabled\', false); }' : '').'
|
|
| 666 | + ' . ($selected ? 'if (! atleastoneselected) { jQuery(".massactionselect").val("0"); jQuery(".massactionconfirmed").prop(\'disabled\', true); } ' : '').'
|
|
| 667 | 667 | } |
| 668 | 668 | else |
| 669 | 669 | {
|
@@ -732,14 +732,14 @@ discard block |
||
| 732 | 732 | $atleastonefavorite = 0; |
| 733 | 733 | |
| 734 | 734 | $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; |
| 735 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_country"; |
|
| 735 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_country"; |
|
| 736 | 736 | $sql .= " WHERE active > 0"; |
| 737 | 737 | //$sql.= " ORDER BY code ASC"; |
| 738 | 738 | |
| 739 | - dol_syslog(get_class($this) . "::select_country", LOG_DEBUG); |
|
| 739 | + dol_syslog(get_class($this)."::select_country", LOG_DEBUG); |
|
| 740 | 740 | $resql = $this->db->query($sql); |
| 741 | 741 | if ($resql) {
|
| 742 | - $out .= '<select id="select' . $htmlname . '" class="flat maxwidth200onsmartphone selectcountry' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" ' . $htmloption . '>'; |
|
| 742 | + $out .= '<select id="select'.$htmlname.'" class="flat maxwidth200onsmartphone selectcountry'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" '.$htmloption.'>'; |
|
| 743 | 743 | $num = $this->db->num_rows($resql); |
| 744 | 744 | $i = 0; |
| 745 | 745 | if ($num) {
|
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | $countryArray[$i]['rowid'] = $obj->rowid; |
| 751 | 751 | $countryArray[$i]['code_iso'] = $obj->code_iso; |
| 752 | 752 | $countryArray[$i]['code_iso3'] = $obj->code_iso3; |
| 753 | - $countryArray[$i]['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country" . $obj->code_iso) != "Country" . $obj->code_iso ? $langs->transnoentitiesnoconv("Country" . $obj->code_iso) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 753 | + $countryArray[$i]['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso) != "Country".$obj->code_iso ? $langs->transnoentitiesnoconv("Country".$obj->code_iso) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 754 | 754 | $countryArray[$i]['favorite'] = $obj->favorite; |
| 755 | 755 | $favorite[$i] = $obj->favorite; |
| 756 | 756 | $label[$i] = dol_string_unaccent($countryArray[$i]['label']); |
@@ -763,16 +763,16 @@ discard block |
||
| 763 | 763 | $countryArray = dol_sort_array($countryArray, 'label'); |
| 764 | 764 | |
| 765 | 765 | if ($showempty) {
|
| 766 | - $out .= '<option value=""> </option>' . "\n"; |
|
| 766 | + $out .= '<option value=""> </option>'."\n"; |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | if ($addspecialentries) { // Add dedicated entries for groups of countries
|
| 770 | 770 | //if ($showempty) $out.= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
| 771 | - $out .= '<option value="special_allnotme"' . ($selected == 'special_allnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>';
|
|
| 772 | - $out .= '<option value="special_eec"' . ($selected == 'special_eec' ? ' selected' : '') . '>' . $langs->trans("CountriesInEEC") . '</option>';
|
|
| 771 | + $out .= '<option value="special_allnotme"'.($selected == 'special_allnotme' ? ' selected' : '').'>'.$langs->trans("CountriesExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>';
|
|
| 772 | + $out .= '<option value="special_eec"'.($selected == 'special_eec' ? ' selected' : '').'>'.$langs->trans("CountriesInEEC").'</option>';
|
|
| 773 | 773 | if ($mysoc->isInEEC()) |
| 774 | - $out .= '<option value="special_eecnotme"' . ($selected == 'special_eecnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>';
|
|
| 775 | - $out .= '<option value="special_noteec"' . ($selected == 'special_noteec' ? ' selected' : '') . '>' . $langs->trans("CountriesNotInEEC") . '</option>';
|
|
| 774 | + $out .= '<option value="special_eecnotme"'.($selected == 'special_eecnotme' ? ' selected' : '').'>'.$langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country".$mysoc->country_code)).'</option>';
|
|
| 775 | + $out .= '<option value="special_noteec"'.($selected == 'special_noteec' ? ' selected' : '').'>'.$langs->trans("CountriesNotInEEC").'</option>';
|
|
| 776 | 776 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
| 777 | 777 | } |
| 778 | 778 | |
@@ -790,16 +790,16 @@ discard block |
||
| 790 | 790 | } |
| 791 | 791 | if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['code_iso3'] || $selected == $row['label'])) {
|
| 792 | 792 | $foundselected = true; |
| 793 | - $out .= '<option value="' . ($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']) . '" selected>'; |
|
| 793 | + $out .= '<option value="'.($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']).'" selected>'; |
|
| 794 | 794 | } else {
|
| 795 | - $out .= '<option value="' . ($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']) . '">'; |
|
| 795 | + $out .= '<option value="'.($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']).'">'; |
|
| 796 | 796 | } |
| 797 | 797 | if ($row['label']) |
| 798 | 798 | $out .= dol_trunc($row['label'], $maxlength, 'middle'); |
| 799 | 799 | else |
| 800 | 800 | $out .= ' '; |
| 801 | 801 | if ($row['code_iso']) |
| 802 | - $out .= ' (' . $row['code_iso'] . ')';
|
|
| 802 | + $out .= ' ('.$row['code_iso'].')';
|
|
| 803 | 803 | $out .= '</option>'; |
| 804 | 804 | } |
| 805 | 805 | } |
@@ -810,8 +810,8 @@ discard block |
||
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | // Make select dynamic |
| 813 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 814 | - $out .= ajax_combobox('select' . $htmlname);
|
|
| 813 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 814 | + $out .= ajax_combobox('select'.$htmlname);
|
|
| 815 | 815 | |
| 816 | 816 | return $out; |
| 817 | 817 | } |
@@ -840,25 +840,25 @@ discard block |
||
| 840 | 840 | $incotermArray = array(); |
| 841 | 841 | |
| 842 | 842 | $sql = "SELECT rowid, code"; |
| 843 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_incoterms"; |
|
| 843 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms"; |
|
| 844 | 844 | $sql .= " WHERE active > 0"; |
| 845 | 845 | $sql .= " ORDER BY code ASC"; |
| 846 | 846 | |
| 847 | - dol_syslog(get_class($this) . "::select_incoterm", LOG_DEBUG); |
|
| 847 | + dol_syslog(get_class($this)."::select_incoterm", LOG_DEBUG); |
|
| 848 | 848 | $resql = $this->db->query($sql); |
| 849 | 849 | if ($resql) {
|
| 850 | 850 | if ($conf->use_javascript_ajax && !$forcecombo) {
|
| 851 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 851 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 852 | 852 | $out .= ajax_combobox($htmlname, $events); |
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | if (!empty($page)) {
|
| 856 | - $out .= '<form method="post" action="' . $page . '">'; |
|
| 856 | + $out .= '<form method="post" action="'.$page.'">'; |
|
| 857 | 857 | $out .= '<input type="hidden" name="action" value="set_incoterms">'; |
| 858 | - $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 858 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | - $out .= '<select id="' . $htmlname . '" class="flat selectincoterm minwidth100imp noenlargeonsmartphone" name="' . $htmlname . '" ' . $htmloption . '>'; |
|
| 861 | + $out .= '<select id="'.$htmlname.'" class="flat selectincoterm minwidth100imp noenlargeonsmartphone" name="'.$htmlname.'" '.$htmloption.'>'; |
|
| 862 | 862 | $out .= '<option value="0"> </option>'; |
| 863 | 863 | $num = $this->db->num_rows($resql); |
| 864 | 864 | $i = 0; |
@@ -874,9 +874,9 @@ discard block |
||
| 874 | 874 | |
| 875 | 875 | foreach ($incotermArray as $row) {
|
| 876 | 876 | if ($selected && ($selected == $row['rowid'] || $selected == $row['code'])) {
|
| 877 | - $out .= '<option value="' . $row['rowid'] . '" selected>'; |
|
| 877 | + $out .= '<option value="'.$row['rowid'].'" selected>'; |
|
| 878 | 878 | } else {
|
| 879 | - $out .= '<option value="' . $row['rowid'] . '">'; |
|
| 879 | + $out .= '<option value="'.$row['rowid'].'">'; |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | if ($row['code']) |
@@ -887,10 +887,10 @@ discard block |
||
| 887 | 887 | } |
| 888 | 888 | $out .= '</select>'; |
| 889 | 889 | |
| 890 | - $out .= '<input id="location_incoterms" class="maxwidth100onsmartphone" name="location_incoterms" value="' . $location_incoterms . '">'; |
|
| 890 | + $out .= '<input id="location_incoterms" class="maxwidth100onsmartphone" name="location_incoterms" value="'.$location_incoterms.'">'; |
|
| 891 | 891 | |
| 892 | 892 | if (!empty($page)) {
|
| 893 | - $out .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '"></form>';
|
|
| 893 | + $out .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'"></form>';
|
|
| 894 | 894 | } |
| 895 | 895 | } else {
|
| 896 | 896 | dol_print_error($this->db); |
@@ -919,8 +919,8 @@ discard block |
||
| 919 | 919 | // If product & services are enabled or both disabled. |
| 920 | 920 | if ($forceall == 1 || (empty($forceall) && !empty($conf->product->enabled) && !empty($conf->service->enabled)) || (empty($forceall) && empty($conf->product->enabled) && empty($conf->service->enabled))) {
|
| 921 | 921 | if (empty($hidetext)) |
| 922 | - print $langs->trans("Type") . ': ';
|
|
| 923 | - print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 922 | + print $langs->trans("Type").': ';
|
|
| 923 | + print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 924 | 924 | if ($showempty) {
|
| 925 | 925 | print '<option value="-1"'; |
| 926 | 926 | if ($selected == -1) |
@@ -931,26 +931,26 @@ discard block |
||
| 931 | 931 | print '<option value="0"'; |
| 932 | 932 | if (0 == $selected) |
| 933 | 933 | print ' selected'; |
| 934 | - print '>' . $langs->trans("Product");
|
|
| 934 | + print '>'.$langs->trans("Product");
|
|
| 935 | 935 | |
| 936 | 936 | print '<option value="1"'; |
| 937 | 937 | if (1 == $selected) |
| 938 | 938 | print ' selected'; |
| 939 | - print '>' . $langs->trans("Service");
|
|
| 939 | + print '>'.$langs->trans("Service");
|
|
| 940 | 940 | |
| 941 | 941 | print '</select>'; |
| 942 | 942 | //if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
|
| 943 | 943 | } |
| 944 | 944 | if ((empty($forceall) && empty($conf->product->enabled) && !empty($conf->service->enabled)) || $forceall == 3) {
|
| 945 | 945 | print $langs->trans("Service");
|
| 946 | - print '<input type="hidden" name="' . $htmlname . '" value="1">'; |
|
| 946 | + print '<input type="hidden" name="'.$htmlname.'" value="1">'; |
|
| 947 | 947 | } |
| 948 | 948 | if ((empty($forceall) && !empty($conf->product->enabled) && empty($conf->service->enabled)) || $forceall == 2) {
|
| 949 | 949 | print $langs->trans("Product");
|
| 950 | - print '<input type="hidden" name="' . $htmlname . '" value="0">'; |
|
| 950 | + print '<input type="hidden" name="'.$htmlname.'" value="0">'; |
|
| 951 | 951 | } |
| 952 | 952 | if ($forceall < 0) { // This should happened only for contracts when both predefined product and service are disabled.
|
| 953 | - print '<input type="hidden" name="' . $htmlname . '" value="1">'; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1 |
|
| 953 | + print '<input type="hidden" name="'.$htmlname.'" value="1">'; // By default we set on service for contract. If CONTRACT_SUPPORT_PRODUCTS is set, forceall should be 1 not -1 |
|
| 954 | 954 | } |
| 955 | 955 | } |
| 956 | 956 | |
@@ -967,14 +967,14 @@ discard block |
||
| 967 | 967 | |
| 968 | 968 | $num = count($this->cache_types_fees); |
| 969 | 969 | if ($num > 0) |
| 970 | - return 0; // Cache already loaded |
|
| 970 | + return 0; // Cache already loaded |
|
| 971 | 971 | |
| 972 | 972 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 973 | 973 | |
| 974 | 974 | $langs->load("trips");
|
| 975 | 975 | |
| 976 | 976 | $sql = "SELECT c.code, c.label"; |
| 977 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_fees as c"; |
|
| 977 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; |
|
| 978 | 978 | $sql .= " WHERE active > 0"; |
| 979 | 979 | |
| 980 | 980 | $resql = $this->db->query($sql); |
@@ -1014,11 +1014,11 @@ discard block |
||
| 1014 | 1014 | // phpcs:enable |
| 1015 | 1015 | global $user, $langs; |
| 1016 | 1016 | |
| 1017 | - dol_syslog(__METHOD__ . " selected=" . $selected . ", htmlname=" . $htmlname, LOG_DEBUG); |
|
| 1017 | + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); |
|
| 1018 | 1018 | |
| 1019 | 1019 | $this->load_cache_types_fees(); |
| 1020 | 1020 | |
| 1021 | - print '<select id="select_' . $htmlname . '" class="flat" name="' . $htmlname . '">'; |
|
| 1021 | + print '<select id="select_'.$htmlname.'" class="flat" name="'.$htmlname.'">'; |
|
| 1022 | 1022 | if ($showempty) {
|
| 1023 | 1023 | print '<option value="-1"'; |
| 1024 | 1024 | if ($selected == -1) |
@@ -1027,7 +1027,7 @@ discard block |
||
| 1027 | 1027 | } |
| 1028 | 1028 | |
| 1029 | 1029 | foreach ($this->cache_types_fees as $key => $value) {
|
| 1030 | - print '<option value="' . $key . '"'; |
|
| 1030 | + print '<option value="'.$key.'"'; |
|
| 1031 | 1031 | if ($key == $selected) |
| 1032 | 1032 | print ' selected'; |
| 1033 | 1033 | print '>'; |
@@ -1090,25 +1090,25 @@ discard block |
||
| 1090 | 1090 | // No immediate load of all database |
| 1091 | 1091 | $placeholder = ''; |
| 1092 | 1092 | if ($selected && empty($selected_input_value)) {
|
| 1093 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 1093 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 1094 | 1094 | $societetmp = new Societe($this->db); |
| 1095 | 1095 | $societetmp->fetch($selected); |
| 1096 | 1096 | $selected_input_value = $societetmp->name; |
| 1097 | 1097 | unset($societetmp); |
| 1098 | 1098 | } |
| 1099 | 1099 | // mode 1 |
| 1100 | - $urloption = 'htmlname=' . $htmlname . '&outjson=1&filter=' . $filter . ($showtype ? '&showtype=' . $showtype : ''); |
|
| 1101 | - $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
|
| 1100 | + $urloption = 'htmlname='.$htmlname.'&outjson=1&filter='.$filter.($showtype ? '&showtype='.$showtype : ''); |
|
| 1101 | + $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
|
| 1102 | 1102 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
|
| 1103 | 1103 | if (empty($hidelabel)) |
| 1104 | - print $langs->trans("RefOrLabel") . ' : ';
|
|
| 1104 | + print $langs->trans("RefOrLabel").' : ';
|
|
| 1105 | 1105 | else if ($hidelabel > 1) {
|
| 1106 | - $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
|
|
| 1106 | + $placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"';
|
|
| 1107 | 1107 | if ($hidelabel == 2) {
|
| 1108 | 1108 | $out .= img_picto($langs->trans("Search"), 'search');
|
| 1109 | 1109 | } |
| 1110 | 1110 | } |
| 1111 | - $out .= '<input type="text" class="' . $morecss . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (!empty($conf->global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '') . ' />'; |
|
| 1111 | + $out .= '<input type="text" class="'.$morecss.'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' '.(!empty($conf->global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; |
|
| 1112 | 1112 | if ($hidelabel == 3) {
|
| 1113 | 1113 | $out .= img_picto($langs->trans("Search"), 'search');
|
| 1114 | 1114 | } |
@@ -1169,20 +1169,20 @@ discard block |
||
| 1169 | 1169 | $sql .= " , dictp.code as country_code"; |
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | - $sql .= " FROM (" . MAIN_DB_PREFIX . "societe as s";
|
|
| 1172 | + $sql .= " FROM (".MAIN_DB_PREFIX."societe as s";
|
|
| 1173 | 1173 | if (!$user->rights->societe->client->voir && !$user->socid) |
| 1174 | - $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 1174 | + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 1175 | 1175 | $sql .= " )"; |
| 1176 | 1176 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
|
| 1177 | - $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "c_country as dictp ON dictp.rowid=s.fk_pays"; |
|
| 1177 | + $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid=s.fk_pays"; |
|
| 1178 | 1178 | } |
| 1179 | - $sql .= " WHERE s.entity IN (" . getEntity('societe') . ")";
|
|
| 1179 | + $sql .= " WHERE s.entity IN (".getEntity('societe').")";
|
|
| 1180 | 1180 | if (!empty($user->socid)) |
| 1181 | - $sql .= " AND s.rowid = " . $user->socid; |
|
| 1181 | + $sql .= " AND s.rowid = ".$user->socid; |
|
| 1182 | 1182 | if ($filter) |
| 1183 | - $sql .= " AND (" . $filter . ")";
|
|
| 1183 | + $sql .= " AND (".$filter.")";
|
|
| 1184 | 1184 | if (!$user->rights->societe->client->voir && !$user->socid) |
| 1185 | - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 1185 | + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
| 1186 | 1186 | if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) |
| 1187 | 1187 | $sql .= " AND s.status <> 0"; |
| 1188 | 1188 | // Add criteria |
@@ -1197,31 +1197,31 @@ discard block |
||
| 1197 | 1197 | foreach ($scrit as $crit) {
|
| 1198 | 1198 | if ($i > 0) |
| 1199 | 1199 | $sql .= " AND "; |
| 1200 | - $sql .= "(s.nom LIKE '" . $this->db->escape($prefix . $crit) . "%')"; |
|
| 1200 | + $sql .= "(s.nom LIKE '".$this->db->escape($prefix.$crit)."%')"; |
|
| 1201 | 1201 | $i++; |
| 1202 | 1202 | } |
| 1203 | 1203 | if (count($scrit) > 1) |
| 1204 | 1204 | $sql .= ")"; |
| 1205 | 1205 | if (!empty($conf->barcode->enabled)) {
|
| 1206 | - $sql .= " OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 1206 | + $sql .= " OR s.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
|
| 1207 | 1207 | } |
| 1208 | - $sql .= " OR s.code_client LIKE '" . $this->db->escape($prefix . $filterkey) . "%' OR s.code_fournisseur LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 1208 | + $sql .= " OR s.code_client LIKE '".$this->db->escape($prefix.$filterkey)."%' OR s.code_fournisseur LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
|
| 1209 | 1209 | $sql .= ")"; |
| 1210 | 1210 | } |
| 1211 | 1211 | $sql .= $this->db->order("nom", "ASC");
|
| 1212 | 1212 | $sql .= $this->db->plimit($limit, 0); |
| 1213 | 1213 | |
| 1214 | 1214 | // Build output string |
| 1215 | - dol_syslog(get_class($this) . "::select_thirdparty_list", LOG_DEBUG); |
|
| 1215 | + dol_syslog(get_class($this)."::select_thirdparty_list", LOG_DEBUG); |
|
| 1216 | 1216 | $resql = $this->db->query($sql); |
| 1217 | 1217 | if ($resql) {
|
| 1218 | 1218 | if (!$forcecombo) {
|
| 1219 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 1219 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 1220 | 1220 | $out .= ajax_combobox($htmlname, $events, $conf->global->COMPANY_USE_SEARCH_TO_SELECT); |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | // Construct $out and $outarray |
| 1224 | - $out .= '<select id="' . $htmlname . '" class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($moreparam ? ' ' . $moreparam : '') . ' name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . '>' . "\n"; |
|
| 1224 | + $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'"'.($moreparam ? ' '.$moreparam : '').' name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').'>'."\n"; |
|
| 1225 | 1225 | |
| 1226 | 1226 | $textifempty = ''; |
| 1227 | 1227 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
@@ -1233,7 +1233,7 @@ discard block |
||
| 1233 | 1233 | $textifempty .= $langs->trans("All");
|
| 1234 | 1234 | } |
| 1235 | 1235 | if ($showempty) |
| 1236 | - $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 1236 | + $out .= '<option value="-1">'.$textifempty.'</option>'."\n"; |
|
| 1237 | 1237 | |
| 1238 | 1238 | $num = $this->db->num_rows($resql); |
| 1239 | 1239 | $i = 0; |
@@ -1243,18 +1243,18 @@ discard block |
||
| 1243 | 1243 | $label = ''; |
| 1244 | 1244 | if ($conf->global->SOCIETE_ADD_REF_IN_LIST) {
|
| 1245 | 1245 | if (($obj->client) && (!empty($obj->code_client))) {
|
| 1246 | - $label = $obj->code_client . ' - '; |
|
| 1246 | + $label = $obj->code_client.' - '; |
|
| 1247 | 1247 | } |
| 1248 | 1248 | if (($obj->fournisseur) && (!empty($obj->code_fournisseur))) {
|
| 1249 | - $label .= $obj->code_fournisseur . ' - '; |
|
| 1249 | + $label .= $obj->code_fournisseur.' - '; |
|
| 1250 | 1250 | } |
| 1251 | - $label .= ' ' . $obj->name; |
|
| 1251 | + $label .= ' '.$obj->name; |
|
| 1252 | 1252 | } else {
|
| 1253 | 1253 | $label = $obj->name; |
| 1254 | 1254 | } |
| 1255 | 1255 | |
| 1256 | 1256 | if (!empty($obj->name_alias)) {
|
| 1257 | - $label .= ' (' . $obj->name_alias . ')';
|
|
| 1257 | + $label .= ' ('.$obj->name_alias.')';
|
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | if ($showtype) {
|
@@ -1263,25 +1263,25 @@ discard block |
||
| 1263 | 1263 | if ($obj->client == 1 || $obj->client == 3) |
| 1264 | 1264 | $label .= $langs->trans("Customer");
|
| 1265 | 1265 | if ($obj->client == 2 || $obj->client == 3) |
| 1266 | - $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect");
|
|
| 1266 | + $label .= ($obj->client == 3 ? ', ' : '').$langs->trans("Prospect");
|
|
| 1267 | 1267 | if ($obj->fournisseur) |
| 1268 | - $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier");
|
|
| 1268 | + $label .= ($obj->client ? ', ' : '').$langs->trans("Supplier");
|
|
| 1269 | 1269 | if ($obj->client || $obj->fournisseur) |
| 1270 | 1270 | $label .= ')'; |
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
|
| 1274 | - $label .= '-' . $obj->address . '-' . $obj->zip . ' ' . $obj->town; |
|
| 1274 | + $label .= '-'.$obj->address.'-'.$obj->zip.' '.$obj->town; |
|
| 1275 | 1275 | if (!empty($obj->country_code)) {
|
| 1276 | - $label .= ' ' . $langs->trans('Country' . $obj->country_code);
|
|
| 1276 | + $label .= ' '.$langs->trans('Country'.$obj->country_code);
|
|
| 1277 | 1277 | } |
| 1278 | 1278 | } |
| 1279 | 1279 | |
| 1280 | 1280 | if (empty($outputmode)) {
|
| 1281 | 1281 | if (in_array($obj->rowid, $selected)) {
|
| 1282 | - $out .= '<option value="' . $obj->rowid . '" selected>' . $label . '</option>'; |
|
| 1282 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>'; |
|
| 1283 | 1283 | } else {
|
| 1284 | - $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>'; |
|
| 1284 | + $out .= '<option value="'.$obj->rowid.'">'.$label.'</option>'; |
|
| 1285 | 1285 | } |
| 1286 | 1286 | } else {
|
| 1287 | 1287 | array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
|
@@ -1292,7 +1292,7 @@ discard block |
||
| 1292 | 1292 | $out .= "\n"; |
| 1293 | 1293 | } |
| 1294 | 1294 | } |
| 1295 | - $out .= '</select>' . "\n"; |
|
| 1295 | + $out .= '</select>'."\n"; |
|
| 1296 | 1296 | } |
| 1297 | 1297 | else {
|
| 1298 | 1298 | dol_print_error($this->db); |
@@ -1324,17 +1324,17 @@ discard block |
||
| 1324 | 1324 | // On recherche les remises |
| 1325 | 1325 | $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; |
| 1326 | 1326 | $sql .= " re.description, re.fk_facture_source"; |
| 1327 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; |
|
| 1328 | - $sql .= " WHERE re.fk_soc = " . (int) $socid; |
|
| 1329 | - $sql .= " AND re.entity = " . $conf->entity; |
|
| 1327 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; |
|
| 1328 | + $sql .= " WHERE re.fk_soc = ".(int) $socid; |
|
| 1329 | + $sql .= " AND re.entity = ".$conf->entity; |
|
| 1330 | 1330 | if ($filter) |
| 1331 | - $sql .= " AND " . $filter; |
|
| 1331 | + $sql .= " AND ".$filter; |
|
| 1332 | 1332 | $sql .= " ORDER BY re.description ASC"; |
| 1333 | 1333 | |
| 1334 | - dol_syslog(get_class($this) . "::select_remises", LOG_DEBUG); |
|
| 1334 | + dol_syslog(get_class($this)."::select_remises", LOG_DEBUG); |
|
| 1335 | 1335 | $resql = $this->db->query($sql); |
| 1336 | 1336 | if ($resql) {
|
| 1337 | - print '<select id="select_' . $htmlname . '" class="flat maxwidthonsmartphone" name="' . $htmlname . '">'; |
|
| 1337 | + print '<select id="select_'.$htmlname.'" class="flat maxwidthonsmartphone" name="'.$htmlname.'">'; |
|
| 1338 | 1338 | $num = $this->db->num_rows($resql); |
| 1339 | 1339 | |
| 1340 | 1340 | $qualifiedlines = $num; |
@@ -1367,10 +1367,10 @@ discard block |
||
| 1367 | 1367 | if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) {
|
| 1368 | 1368 | $tmpfac = new Facture($this->db); |
| 1369 | 1369 | if ($tmpfac->fetch($obj->fk_facture_source) > 0) |
| 1370 | - $desc = $desc . ' - ' . $tmpfac->ref; |
|
| 1370 | + $desc = $desc.' - '.$tmpfac->ref; |
|
| 1371 | 1371 | } |
| 1372 | 1372 | |
| 1373 | - print '<option value="' . $obj->rowid . '"' . $selectstring . $disabled . '>' . $desc . ' (' . price($obj->amount_ht) . ' ' . $langs->trans("HT") . ' - ' . price($obj->amount_ttc) . ' ' . $langs->trans("TTC") . ')</option>';
|
|
| 1373 | + print '<option value="'.$obj->rowid.'"'.$selectstring.$disabled.'>'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
|
|
| 1374 | 1374 | $i++; |
| 1375 | 1375 | } |
| 1376 | 1376 | } |
@@ -1450,7 +1450,7 @@ discard block |
||
| 1450 | 1450 | $out = ''; |
| 1451 | 1451 | |
| 1452 | 1452 | if (!is_object($hookmanager)) {
|
| 1453 | - include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; |
|
| 1453 | + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
| 1454 | 1454 | $hookmanager = new HookManager($this->db); |
| 1455 | 1455 | } |
| 1456 | 1456 | |
@@ -1458,36 +1458,36 @@ discard block |
||
| 1458 | 1458 | $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; |
| 1459 | 1459 | if ($showsoc > 0) |
| 1460 | 1460 | $sql .= " , s.nom as company"; |
| 1461 | - $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as sp"; |
|
| 1461 | + $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; |
|
| 1462 | 1462 | if ($showsoc > 0) |
| 1463 | - $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc"; |
|
| 1464 | - $sql .= " WHERE sp.entity IN (" . getEntity('socpeople') . ")";
|
|
| 1463 | + $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc"; |
|
| 1464 | + $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")";
|
|
| 1465 | 1465 | if ($socid > 0 || $socid == -1) |
| 1466 | - $sql .= " AND sp.fk_soc=" . $socid; |
|
| 1466 | + $sql .= " AND sp.fk_soc=".$socid; |
|
| 1467 | 1467 | if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) |
| 1468 | 1468 | $sql .= " AND sp.statut <> 0"; |
| 1469 | 1469 | $sql .= " ORDER BY sp.lastname ASC"; |
| 1470 | 1470 | |
| 1471 | - dol_syslog(get_class($this) . "::select_contacts", LOG_DEBUG); |
|
| 1471 | + dol_syslog(get_class($this)."::select_contacts", LOG_DEBUG); |
|
| 1472 | 1472 | $resql = $this->db->query($sql); |
| 1473 | 1473 | if ($resql) {
|
| 1474 | 1474 | $num = $this->db->num_rows($resql); |
| 1475 | 1475 | |
| 1476 | 1476 | if ($conf->use_javascript_ajax && !$forcecombo && !$options_only) {
|
| 1477 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 1477 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 1478 | 1478 | $out .= ajax_combobox($htmlid, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); |
| 1479 | 1479 | } |
| 1480 | 1480 | |
| 1481 | 1481 | if ($htmlname != 'none' || $options_only) |
| 1482 | - $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlid . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . (!empty($moreparam) ? $moreparam : '') . '>'; |
|
| 1482 | + $out .= '<select class="flat'.($moreclass ? ' '.$moreclass : '').'" id="'.$htmlid.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.(!empty($moreparam) ? $moreparam : '').'>'; |
|
| 1483 | 1483 | if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) |
| 1484 | - $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '> </option>'; |
|
| 1484 | + $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'> </option>'; |
|
| 1485 | 1485 | if ($showempty == 2) |
| 1486 | - $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '>' . $langs->trans("Internal") . '</option>';
|
|
| 1486 | + $out .= '<option value="0"'.(in_array(0, $selected) ? ' selected' : '').'>'.$langs->trans("Internal").'</option>';
|
|
| 1487 | 1487 | $num = $this->db->num_rows($resql); |
| 1488 | 1488 | $i = 0; |
| 1489 | 1489 | if ($num) {
|
| 1490 | - include_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; |
|
| 1490 | + include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 1491 | 1491 | $contactstatic = new Contact($this->db); |
| 1492 | 1492 | |
| 1493 | 1493 | while ($i < $num) {
|
@@ -1504,27 +1504,27 @@ discard block |
||
| 1504 | 1504 | if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) |
| 1505 | 1505 | $disabled = 1; |
| 1506 | 1506 | if (!empty($selected) && in_array($obj->rowid, $selected)) {
|
| 1507 | - $out .= '<option value="' . $obj->rowid . '"'; |
|
| 1507 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 1508 | 1508 | if ($disabled) |
| 1509 | 1509 | $out .= ' disabled'; |
| 1510 | 1510 | $out .= ' selected>'; |
| 1511 | 1511 | $out .= $contactstatic->getFullName($langs); |
| 1512 | 1512 | if ($showfunction && $obj->poste) |
| 1513 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1513 | + $out .= ' ('.$obj->poste.')';
|
|
| 1514 | 1514 | if (($showsoc > 0) && $obj->company) |
| 1515 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1515 | + $out .= ' - ('.$obj->company.')';
|
|
| 1516 | 1516 | $out .= '</option>'; |
| 1517 | 1517 | } |
| 1518 | 1518 | else {
|
| 1519 | - $out .= '<option value="' . $obj->rowid . '"'; |
|
| 1519 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 1520 | 1520 | if ($disabled) |
| 1521 | 1521 | $out .= ' disabled'; |
| 1522 | 1522 | $out .= '>'; |
| 1523 | 1523 | $out .= $contactstatic->getFullName($langs); |
| 1524 | 1524 | if ($showfunction && $obj->poste) |
| 1525 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1525 | + $out .= ' ('.$obj->poste.')';
|
|
| 1526 | 1526 | if (($showsoc > 0) && $obj->company) |
| 1527 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1527 | + $out .= ' - ('.$obj->company.')';
|
|
| 1528 | 1528 | $out .= '</option>'; |
| 1529 | 1529 | } |
| 1530 | 1530 | } |
@@ -1532,9 +1532,9 @@ discard block |
||
| 1532 | 1532 | if (in_array($obj->rowid, $selected)) {
|
| 1533 | 1533 | $out .= $contactstatic->getFullName($langs); |
| 1534 | 1534 | if ($showfunction && $obj->poste) |
| 1535 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1535 | + $out .= ' ('.$obj->poste.')';
|
|
| 1536 | 1536 | if (($showsoc > 0) && $obj->company) |
| 1537 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1537 | + $out .= ' - ('.$obj->company.')';
|
|
| 1538 | 1538 | } |
| 1539 | 1539 | } |
| 1540 | 1540 | } |
@@ -1542,7 +1542,7 @@ discard block |
||
| 1542 | 1542 | } |
| 1543 | 1543 | } |
| 1544 | 1544 | else {
|
| 1545 | - $out .= '<option value="-1"' . (($showempty == 2 || $multiple) ? '' : ' selected') . ' disabled>'; |
|
| 1545 | + $out .= '<option value="-1"'.(($showempty == 2 || $multiple) ? '' : ' selected').' disabled>'; |
|
| 1546 | 1546 | $out .= ($socid != -1) ? ($langs->trans($socid ? "NoContactDefinedForThirdParty" : "NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst');
|
| 1547 | 1547 | $out .= '</option>'; |
| 1548 | 1548 | } |
@@ -1556,7 +1556,7 @@ discard block |
||
| 1556 | 1556 | 'showsoc' => $showsoc, |
| 1557 | 1557 | ); |
| 1558 | 1558 | |
| 1559 | - $reshook = $hookmanager->executeHooks('afterSelectContactOptions', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 1559 | + $reshook = $hookmanager->executeHooks('afterSelectContactOptions', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 1560 | 1560 | |
| 1561 | 1561 | if ($htmlname != 'none' || $options_only) {
|
| 1562 | 1562 | $out .= '</select>'; |
@@ -1655,33 +1655,33 @@ discard block |
||
| 1655 | 1655 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 1656 | 1656 | $sql .= ", e.label"; |
| 1657 | 1657 | } |
| 1658 | - $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
|
| 1658 | + $sql .= " FROM ".MAIN_DB_PREFIX."user as u"; |
|
| 1659 | 1659 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 1660 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=u.entity"; |
|
| 1660 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=u.entity"; |
|
| 1661 | 1661 | if ($force_entity) |
| 1662 | - $sql .= " WHERE u.entity IN (0," . $force_entity . ")"; |
|
| 1662 | + $sql .= " WHERE u.entity IN (0,".$force_entity.")"; |
|
| 1663 | 1663 | else |
| 1664 | 1664 | $sql .= " WHERE u.entity IS NOT NULL"; |
| 1665 | 1665 | } |
| 1666 | 1666 | else {
|
| 1667 | 1667 | if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1668 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ug"; |
|
| 1668 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1669 | 1669 | $sql .= " ON ug.fk_user = u.rowid"; |
| 1670 | - $sql .= " WHERE ug.entity = " . $conf->entity; |
|
| 1670 | + $sql .= " WHERE ug.entity = ".$conf->entity; |
|
| 1671 | 1671 | } else {
|
| 1672 | - $sql .= " WHERE u.entity IN (0," . $conf->entity . ")"; |
|
| 1672 | + $sql .= " WHERE u.entity IN (0,".$conf->entity.")"; |
|
| 1673 | 1673 | } |
| 1674 | 1674 | } |
| 1675 | 1675 | if (!empty($user->societe_id)) |
| 1676 | - $sql .= " AND u.fk_soc = " . $user->societe_id; |
|
| 1676 | + $sql .= " AND u.fk_soc = ".$user->societe_id; |
|
| 1677 | 1677 | if (is_array($exclude) && $excludeUsers) |
| 1678 | - $sql .= " AND u.rowid NOT IN (" . $excludeUsers . ")";
|
|
| 1678 | + $sql .= " AND u.rowid NOT IN (".$excludeUsers.")";
|
|
| 1679 | 1679 | if ($includeUsers) |
| 1680 | - $sql .= " AND u.rowid IN (" . $includeUsers . ")";
|
|
| 1680 | + $sql .= " AND u.rowid IN (".$includeUsers.")";
|
|
| 1681 | 1681 | if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) |
| 1682 | 1682 | $sql .= " AND u.statut <> 0"; |
| 1683 | 1683 | if (!empty($morefilter)) |
| 1684 | - $sql .= " " . $morefilter; |
|
| 1684 | + $sql .= " ".$morefilter; |
|
| 1685 | 1685 | |
| 1686 | 1686 | if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
|
| 1687 | 1687 | $sql .= " ORDER BY u.firstname ASC"; |
@@ -1689,22 +1689,22 @@ discard block |
||
| 1689 | 1689 | $sql .= " ORDER BY u.lastname ASC"; |
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | - dol_syslog(get_class($this) . "::select_dolusers", LOG_DEBUG); |
|
| 1692 | + dol_syslog(get_class($this)."::select_dolusers", LOG_DEBUG); |
|
| 1693 | 1693 | $resql = $this->db->query($sql); |
| 1694 | 1694 | if ($resql) {
|
| 1695 | 1695 | $num = $this->db->num_rows($resql); |
| 1696 | 1696 | $i = 0; |
| 1697 | 1697 | if ($num) {
|
| 1698 | 1698 | // Enhance with select2 |
| 1699 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 1699 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 1700 | 1700 | $out .= ajax_combobox($htmlname); |
| 1701 | 1701 | |
| 1702 | 1702 | // do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined |
| 1703 | - $out .= '<select class="flat' . ($morecss ? ' minwidth100 ' . $morecss : ' minwidth200') . '" id="' . $htmlname . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . ($disabled ? ' disabled' : '') . '>'; |
|
| 1703 | + $out .= '<select class="flat'.($morecss ? ' minwidth100 '.$morecss : ' minwidth200').'" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled ? ' disabled' : '').'>'; |
|
| 1704 | 1704 | if ($show_empty && !$multiple) |
| 1705 | - $out .= '<option value="-1"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 1705 | + $out .= '<option value="-1"'.((empty($selected) || in_array(-1, $selected)) ? ' selected' : '').'> </option>'."\n"; |
|
| 1706 | 1706 | if ($show_every) |
| 1707 | - $out .= '<option value="-2"' . ((in_array(-2, $selected)) ? ' selected' : '') . '>-- ' . $langs->trans("Everybody") . ' --</option>' . "\n";
|
|
| 1707 | + $out .= '<option value="-2"'.((in_array(-2, $selected)) ? ' selected' : '').'>-- '.$langs->trans("Everybody").' --</option>'."\n";
|
|
| 1708 | 1708 | |
| 1709 | 1709 | $userstatic = new User($this->db); |
| 1710 | 1710 | |
@@ -1719,14 +1719,14 @@ discard block |
||
| 1719 | 1719 | if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) |
| 1720 | 1720 | $disableline = ($enableonlytext ? $enableonlytext : '1'); |
| 1721 | 1721 | |
| 1722 | - if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected) )) {
|
|
| 1723 | - $out .= '<option value="' . $obj->rowid . '"'; |
|
| 1722 | + if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
|
|
| 1723 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 1724 | 1724 | if ($disableline) |
| 1725 | 1725 | $out .= ' disabled'; |
| 1726 | 1726 | $out .= ' selected>'; |
| 1727 | 1727 | } |
| 1728 | 1728 | else {
|
| 1729 | - $out .= '<option value="' . $obj->rowid . '"'; |
|
| 1729 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 1730 | 1730 | if ($disableline) |
| 1731 | 1731 | $out .= ' disabled'; |
| 1732 | 1732 | $out .= '>'; |
@@ -1742,31 +1742,31 @@ discard block |
||
| 1742 | 1742 | // Complete name with more info |
| 1743 | 1743 | $moreinfo = 0; |
| 1744 | 1744 | if (!empty($conf->global->MAIN_SHOW_LOGIN)) {
|
| 1745 | - $out .= ($moreinfo ? ' - ' : ' (') . $obj->login;
|
|
| 1745 | + $out .= ($moreinfo ? ' - ' : ' (').$obj->login;
|
|
| 1746 | 1746 | $moreinfo++; |
| 1747 | 1747 | } |
| 1748 | 1748 | if ($showstatus >= 0) {
|
| 1749 | 1749 | if ($obj->statut == 1 && $showstatus == 1) {
|
| 1750 | - $out .= ($moreinfo ? ' - ' : ' (') . $langs->trans('Enabled');
|
|
| 1750 | + $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Enabled');
|
|
| 1751 | 1751 | $moreinfo++; |
| 1752 | 1752 | } |
| 1753 | 1753 | if ($obj->statut == 0) {
|
| 1754 | - $out .= ($moreinfo ? ' - ' : ' (') . $langs->trans('Disabled');
|
|
| 1754 | + $out .= ($moreinfo ? ' - ' : ' (').$langs->trans('Disabled');
|
|
| 1755 | 1755 | $moreinfo++; |
| 1756 | 1756 | } |
| 1757 | 1757 | } |
| 1758 | 1758 | if (!empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 1759 | 1759 | if (!$obj->entity) {
|
| 1760 | - $out .= ($moreinfo ? ' - ' : ' (') . $langs->trans("AllEntities");
|
|
| 1760 | + $out .= ($moreinfo ? ' - ' : ' (').$langs->trans("AllEntities");
|
|
| 1761 | 1761 | $moreinfo++; |
| 1762 | 1762 | } else {
|
| 1763 | - $out .= ($moreinfo ? ' - ' : ' (') . ($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined"));
|
|
| 1763 | + $out .= ($moreinfo ? ' - ' : ' (').($obj->label ? $obj->label : $langs->trans("EntityNameNotDefined"));
|
|
| 1764 | 1764 | $moreinfo++; |
| 1765 | 1765 | } |
| 1766 | 1766 | } |
| 1767 | 1767 | $out .= ($moreinfo ? ')' : ''); |
| 1768 | 1768 | if ($disableline && $disableline != '1') {
|
| 1769 | - $out .= ' - ' . $disableline; // This is text from $enableonlytext parameter |
|
| 1769 | + $out .= ' - '.$disableline; // This is text from $enableonlytext parameter |
|
| 1770 | 1770 | } |
| 1771 | 1771 | $out .= '</option>'; |
| 1772 | 1772 | $outarray[$userstatic->id] = $userstatic->getFullName($langs, $fullNameMode, -1, $maxlength); |
@@ -1774,8 +1774,8 @@ discard block |
||
| 1774 | 1774 | $i++; |
| 1775 | 1775 | } |
| 1776 | 1776 | } else {
|
| 1777 | - $out .= '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '" disabled>'; |
|
| 1778 | - $out .= '<option value="">' . $langs->trans("None") . '</option>';
|
|
| 1777 | + $out .= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'" disabled>'; |
|
| 1778 | + $out .= '<option value="">'.$langs->trans("None").'</option>';
|
|
| 1779 | 1779 | } |
| 1780 | 1780 | $out .= '</select>'; |
| 1781 | 1781 | } else {
|
@@ -1826,7 +1826,7 @@ discard block |
||
| 1826 | 1826 | $out .= '<input type="hidden" class="removedassignedhidden" name="removedassigned" value="">'; |
| 1827 | 1827 | $out .= '<script type="text/javascript" language="javascript">jQuery(document).ready(function () { jQuery(".removedassigned").click(function() { jQuery(".removedassignedhidden").val(jQuery(this).val()); });})</script>';
|
| 1828 | 1828 | $out .= $this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter);
|
| 1829 | - $out .= ' <input type="submit" class="button valignmiddle" name="' . $action . 'assignedtouser" value="' . dol_escape_htmltag($langs->trans("Add")) . '">';
|
|
| 1829 | + $out .= ' <input type="submit" class="button valignmiddle" name="'.$action.'assignedtouser" value="'.dol_escape_htmltag($langs->trans("Add")).'">';
|
|
| 1830 | 1830 | $out .= '<br>'; |
| 1831 | 1831 | } |
| 1832 | 1832 | $assignedtouser = array(); |
@@ -1850,16 +1850,16 @@ discard block |
||
| 1850 | 1850 | $out .= $userstatic->getNomUrl(-1); |
| 1851 | 1851 | if ($i == 0) {
|
| 1852 | 1852 | $ownerid = $value['id']; |
| 1853 | - $out .= ' (' . $langs->trans("Owner") . ')';
|
|
| 1853 | + $out .= ' ('.$langs->trans("Owner").')';
|
|
| 1854 | 1854 | } |
| 1855 | 1855 | if ($nbassignetouser > 1 && $action != 'view') {
|
| 1856 | - $out .= ' <input type="image" style="border: 0px;" src="' . img_picto($langs->trans("Remove"), 'delete', '', 0, 1) . '" value="' . $userstatic->id . '" class="removedassigned" id="removedassigned_' . $userstatic->id . '" name="removedassigned_' . $userstatic->id . '">';
|
|
| 1856 | + $out .= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Remove"), 'delete', '', 0, 1).'" value="'.$userstatic->id.'" class="removedassigned" id="removedassigned_'.$userstatic->id.'" name="removedassigned_'.$userstatic->id.'">';
|
|
| 1857 | 1857 | } |
| 1858 | 1858 | // Show my availability |
| 1859 | 1859 | if ($showproperties) {
|
| 1860 | 1860 | if ($ownerid == $value['id'] && is_array($listofuserid) && count($listofuserid) && in_array($ownerid, array_keys($listofuserid))) {
|
| 1861 | 1861 | $out .= '<div class="myavailability inline-block">'; |
| 1862 | - $out .= ' - <span class="opacitymedium">' . $langs->trans("Availability") . ':</span> <input id="transparency" class="marginleftonly marginrightonly" ' . ($action == 'view' ? 'disabled' : '') . ' type="checkbox" name="transparency"' . ($listofuserid[$ownerid]['transparency'] ? ' checked' : '') . '>' . $langs->trans("Busy");
|
|
| 1862 | + $out .= ' - <span class="opacitymedium">'.$langs->trans("Availability").':</span> <input id="transparency" class="marginleftonly marginrightonly" '.($action == 'view' ? 'disabled' : '').' type="checkbox" name="transparency"'.($listofuserid[$ownerid]['transparency'] ? ' checked' : '').'>'.$langs->trans("Busy");
|
|
| 1863 | 1863 | $out .= '</div>'; |
| 1864 | 1864 | } |
| 1865 | 1865 | } |
@@ -1913,19 +1913,19 @@ discard block |
||
| 1913 | 1913 | $placeholder = ''; |
| 1914 | 1914 | |
| 1915 | 1915 | if ($selected && empty($selected_input_value)) {
|
| 1916 | - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
| 1916 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 1917 | 1917 | $producttmpselect = new Product($this->db); |
| 1918 | 1918 | $producttmpselect->fetch($selected); |
| 1919 | 1919 | $selected_input_value = $producttmpselect->ref; |
| 1920 | 1920 | unset($producttmpselect); |
| 1921 | 1921 | } |
| 1922 | 1922 | // mode=1 means customers products |
| 1923 | - $urloption = 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=1&status=' . $status . '&finished=' . $finished . '&hidepriceinlabel=' . $hidepriceinlabel . '&warehousestatus=' . $warehouseStatus; |
|
| 1923 | + $urloption = 'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=1&status='.$status.'&finished='.$finished.'&hidepriceinlabel='.$hidepriceinlabel.'&warehousestatus='.$warehouseStatus; |
|
| 1924 | 1924 | //Price by customer |
| 1925 | 1925 | if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
|
| 1926 | - $urloption .= '&socid=' . $socid; |
|
| 1926 | + $urloption .= '&socid='.$socid; |
|
| 1927 | 1927 | } |
| 1928 | - print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
|
| 1928 | + print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
|
| 1929 | 1929 | |
| 1930 | 1930 | if (!empty($conf->variants->enabled)) {
|
| 1931 | 1931 | |
@@ -2002,14 +2002,14 @@ discard block |
||
| 2002 | 2002 | <?php |
| 2003 | 2003 | } |
| 2004 | 2004 | if (empty($hidelabel)) |
| 2005 | - print $langs->trans("RefOrLabel") . ' : ';
|
|
| 2005 | + print $langs->trans("RefOrLabel").' : ';
|
|
| 2006 | 2006 | else if ($hidelabel > 1) {
|
| 2007 | - $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
|
|
| 2007 | + $placeholder = ' placeholder="'.$langs->trans("RefOrLabel").'"';
|
|
| 2008 | 2008 | if ($hidelabel == 2) {
|
| 2009 | 2009 | print img_picto($langs->trans("Search"), 'search');
|
| 2010 | 2010 | } |
| 2011 | 2011 | } |
| 2012 | - print '<input type="text" class="minwidth100" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '"' . $placeholder . ' ' . (!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '') . ' />'; |
|
| 2012 | + print '<input type="text" class="minwidth100" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'"'.$placeholder.' '.(!empty($conf->global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; |
|
| 2013 | 2013 | if ($hidelabel == 3) {
|
| 2014 | 2014 | print img_picto($langs->trans("Search"), 'search');
|
| 2015 | 2015 | } |
@@ -2052,7 +2052,7 @@ discard block |
||
| 2052 | 2052 | |
| 2053 | 2053 | $warehouseStatusArray = array(); |
| 2054 | 2054 | if (!empty($warehouseStatus)) {
|
| 2055 | - require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; |
|
| 2055 | + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; |
|
| 2056 | 2056 | if (preg_match('/warehouseclosed/', $warehouseStatus)) {
|
| 2057 | 2057 | $warehouseStatusArray[] = Entrepot::STATUS_CLOSED; |
| 2058 | 2058 | } |
@@ -2068,13 +2068,13 @@ discard block |
||
| 2068 | 2068 | (count($warehouseStatusArray)) ? $selectFieldsGrouped = ", sum(ps.reel) as stock" : $selectFieldsGrouped = ", p.stock"; |
| 2069 | 2069 | |
| 2070 | 2070 | $sql = "SELECT "; |
| 2071 | - $sql .= $selectFields . $selectFieldsGrouped; |
|
| 2071 | + $sql .= $selectFields.$selectFieldsGrouped; |
|
| 2072 | 2072 | |
| 2073 | 2073 | if (!empty($conf->global->PRODUCT_SORT_BY_CATEGORY)) {
|
| 2074 | 2074 | //Product category |
| 2075 | - $sql .= ", (SELECT " . MAIN_DB_PREFIX . "categorie_product.fk_categorie |
|
| 2076 | - FROM " . MAIN_DB_PREFIX . "categorie_product |
|
| 2077 | - WHERE " . MAIN_DB_PREFIX . "categorie_product.fk_product=p.rowid |
|
| 2075 | + $sql .= ", (SELECT ".MAIN_DB_PREFIX."categorie_product.fk_categorie |
|
| 2076 | + FROM " . MAIN_DB_PREFIX."categorie_product |
|
| 2077 | + WHERE " . MAIN_DB_PREFIX."categorie_product.fk_product=p.rowid |
|
| 2078 | 2078 | LIMIT 1 |
| 2079 | 2079 | ) AS categorie_product_id "; |
| 2080 | 2080 | } |
@@ -2093,45 +2093,45 @@ discard block |
||
| 2093 | 2093 | } |
| 2094 | 2094 | // Price by quantity |
| 2095 | 2095 | if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
|
| 2096 | - $sql .= ", (SELECT pp.rowid FROM " . MAIN_DB_PREFIX . "product_price as pp WHERE pp.fk_product = p.rowid"; |
|
| 2096 | + $sql .= ", (SELECT pp.rowid FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; |
|
| 2097 | 2097 | if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) |
| 2098 | - $sql .= " AND price_level=" . $price_level; |
|
| 2098 | + $sql .= " AND price_level=".$price_level; |
|
| 2099 | 2099 | $sql .= " ORDER BY date_price"; |
| 2100 | 2100 | $sql .= " DESC LIMIT 1) as price_rowid"; |
| 2101 | - $sql .= ", (SELECT pp.price_by_qty FROM " . MAIN_DB_PREFIX . "product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable |
|
| 2101 | + $sql .= ", (SELECT pp.price_by_qty FROM ".MAIN_DB_PREFIX."product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable |
|
| 2102 | 2102 | if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) |
| 2103 | - $sql .= " AND price_level=" . $price_level; |
|
| 2103 | + $sql .= " AND price_level=".$price_level; |
|
| 2104 | 2104 | $sql .= " ORDER BY date_price"; |
| 2105 | 2105 | $sql .= " DESC LIMIT 1) as price_by_qty"; |
| 2106 | 2106 | $selectFields .= ", price_rowid, price_by_qty"; |
| 2107 | 2107 | } |
| 2108 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; |
|
| 2108 | + $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; |
|
| 2109 | 2109 | if (count($warehouseStatusArray)) {
|
| 2110 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as ps on ps.fk_product = p.rowid"; |
|
| 2111 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entrepot as e on ps.fk_entrepot = e.rowid"; |
|
| 2110 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps on ps.fk_product = p.rowid"; |
|
| 2111 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e on ps.fk_entrepot = e.rowid"; |
|
| 2112 | 2112 | } |
| 2113 | 2113 | |
| 2114 | 2114 | // include search in supplier ref |
| 2115 | 2115 | if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) {
|
| 2116 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
|
| 2116 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
|
| 2117 | 2117 | } |
| 2118 | 2118 | |
| 2119 | 2119 | //Price by customer |
| 2120 | 2120 | if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES) && !empty($socid)) {
|
| 2121 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_customer_price as pcp ON pcp.fk_soc=" . $socid . " AND pcp.fk_product=p.rowid"; |
|
| 2121 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_customer_price as pcp ON pcp.fk_soc=".$socid." AND pcp.fk_product=p.rowid"; |
|
| 2122 | 2122 | } |
| 2123 | 2123 | // Multilang : we add translation |
| 2124 | 2124 | if (!empty($conf->global->MAIN_MULTILANGS)) {
|
| 2125 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='" . $langs->getDefaultLang() . "'"; |
|
| 2125 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_lang as pl ON pl.fk_product = p.rowid AND pl.lang='".$langs->getDefaultLang()."'"; |
|
| 2126 | 2126 | } |
| 2127 | 2127 | |
| 2128 | 2128 | if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
|
| 2129 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_attribute_combination pac ON pac.fk_product_child = p.rowid"; |
|
| 2129 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac.fk_product_child = p.rowid"; |
|
| 2130 | 2130 | } |
| 2131 | 2131 | |
| 2132 | - $sql .= ' WHERE p.entity IN (' . getEntity('product') . ')';
|
|
| 2132 | + $sql .= ' WHERE p.entity IN ('.getEntity('product').')';
|
|
| 2133 | 2133 | if (count($warehouseStatusArray)) {
|
| 2134 | - $sql .= ' AND (p.fk_product_type = 1 OR e.statut IN (' . $this->db->escape(implode(',', $warehouseStatusArray)) . '))';
|
|
| 2134 | + $sql .= ' AND (p.fk_product_type = 1 OR e.statut IN ('.$this->db->escape(implode(',', $warehouseStatusArray)).'))';
|
|
| 2135 | 2135 | } |
| 2136 | 2136 | |
| 2137 | 2137 | if (!empty($conf->global->PRODUIT_ATTRIBUTES_HIDECHILD)) {
|
@@ -2139,17 +2139,17 @@ discard block |
||
| 2139 | 2139 | } |
| 2140 | 2140 | |
| 2141 | 2141 | if ($finished == 0) {
|
| 2142 | - $sql .= " AND p.finished = " . $finished; |
|
| 2142 | + $sql .= " AND p.finished = ".$finished; |
|
| 2143 | 2143 | } elseif ($finished == 1) {
|
| 2144 | - $sql .= " AND p.finished = " . $finished; |
|
| 2144 | + $sql .= " AND p.finished = ".$finished; |
|
| 2145 | 2145 | if ($status >= 0) |
| 2146 | - $sql .= " AND p.tosell = " . $status; |
|
| 2146 | + $sql .= " AND p.tosell = ".$status; |
|
| 2147 | 2147 | } |
| 2148 | 2148 | elseif ($status >= 0) {
|
| 2149 | - $sql .= " AND p.tosell = " . $status; |
|
| 2149 | + $sql .= " AND p.tosell = ".$status; |
|
| 2150 | 2150 | } |
| 2151 | 2151 | if (strval($filtertype) != '') |
| 2152 | - $sql .= " AND p.fk_product_type=" . $filtertype; |
|
| 2152 | + $sql .= " AND p.fk_product_type=".$filtertype; |
|
| 2153 | 2153 | // Add criteria on ref/label |
| 2154 | 2154 | if ($filterkey != '') {
|
| 2155 | 2155 | $sql .= ' AND (';
|
@@ -2162,27 +2162,27 @@ discard block |
||
| 2162 | 2162 | foreach ($scrit as $crit) {
|
| 2163 | 2163 | if ($i > 0) |
| 2164 | 2164 | $sql .= " AND "; |
| 2165 | - $sql .= "(p.ref LIKE '" . $db->escape($prefix . $crit) . "%' OR p.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2165 | + $sql .= "(p.ref LIKE '".$db->escape($prefix.$crit)."%' OR p.label LIKE '".$db->escape($prefix.$crit)."%'"; |
|
| 2166 | 2166 | if (!empty($conf->global->MAIN_MULTILANGS)) |
| 2167 | - $sql .= " OR pl.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2167 | + $sql .= " OR pl.label LIKE '".$db->escape($prefix.$crit)."%'"; |
|
| 2168 | 2168 | if (!empty($conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION)) {
|
| 2169 | - $sql .= " OR p.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2169 | + $sql .= " OR p.description LIKE '".$db->escape($prefix.$crit)."%'"; |
|
| 2170 | 2170 | if (!empty($conf->global->MAIN_MULTILANGS)) |
| 2171 | - $sql .= " OR pl.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2171 | + $sql .= " OR pl.description LIKE '".$db->escape($prefix.$crit)."%'"; |
|
| 2172 | 2172 | } |
| 2173 | 2173 | if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) |
| 2174 | - $sql .= " OR pfp.ref_fourn LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2174 | + $sql .= " OR pfp.ref_fourn LIKE '".$db->escape($prefix.$crit)."%'"; |
|
| 2175 | 2175 | $sql .= ")"; |
| 2176 | 2176 | $i++; |
| 2177 | 2177 | } |
| 2178 | 2178 | if (count($scrit) > 1) |
| 2179 | 2179 | $sql .= ")"; |
| 2180 | 2180 | if (!empty($conf->barcode->enabled)) |
| 2181 | - $sql .= " OR p.barcode LIKE '" . $db->escape($prefix . $filterkey) . "%'"; |
|
| 2181 | + $sql .= " OR p.barcode LIKE '".$db->escape($prefix.$filterkey)."%'"; |
|
| 2182 | 2182 | $sql .= ')'; |
| 2183 | 2183 | } |
| 2184 | 2184 | if (count($warehouseStatusArray)) {
|
| 2185 | - $sql .= ' GROUP BY' . $selectFields; |
|
| 2185 | + $sql .= ' GROUP BY'.$selectFields; |
|
| 2186 | 2186 | } |
| 2187 | 2187 | |
| 2188 | 2188 | //Sort by category |
@@ -2197,21 +2197,21 @@ discard block |
||
| 2197 | 2197 | $sql .= $db->plimit($limit, 0); |
| 2198 | 2198 | |
| 2199 | 2199 | // Build output string |
| 2200 | - dol_syslog(get_class($this) . "::select_produits_list search product", LOG_DEBUG); |
|
| 2200 | + dol_syslog(get_class($this)."::select_produits_list search product", LOG_DEBUG); |
|
| 2201 | 2201 | $result = $this->db->query($sql); |
| 2202 | 2202 | if ($result) {
|
| 2203 | - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
| 2204 | - require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php'; |
|
| 2203 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 2204 | + require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; |
|
| 2205 | 2205 | $num = $this->db->num_rows($result); |
| 2206 | 2206 | |
| 2207 | 2207 | $events = null; |
| 2208 | 2208 | |
| 2209 | 2209 | if (!$forcecombo) {
|
| 2210 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 2210 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 2211 | 2211 | $out .= ajax_combobox($htmlname, $events, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT); |
| 2212 | 2212 | } |
| 2213 | 2213 | |
| 2214 | - $out .= '<select class="flat' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '" id="' . $htmlname . '">'; |
|
| 2214 | + $out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">'; |
|
| 2215 | 2215 | |
| 2216 | 2216 | $textifempty = ''; |
| 2217 | 2217 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
@@ -2223,7 +2223,7 @@ discard block |
||
| 2223 | 2223 | $textifempty .= $langs->trans("All");
|
| 2224 | 2224 | } |
| 2225 | 2225 | if ($showempty) |
| 2226 | - $out .= '<option value="0" selected>' . $textifempty . '</option>'; |
|
| 2226 | + $out .= '<option value="0" selected>'.$textifempty.'</option>'; |
|
| 2227 | 2227 | |
| 2228 | 2228 | $i = 0; |
| 2229 | 2229 | while ($num && $i < $num) {
|
@@ -2233,11 +2233,11 @@ discard block |
||
| 2233 | 2233 | |
| 2234 | 2234 | if ((!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) { // Price by quantity will return many prices for the same product
|
| 2235 | 2235 | $sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise, price_base_type"; |
| 2236 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product_price_by_qty"; |
|
| 2237 | - $sql .= " WHERE fk_product_price=" . $objp->price_rowid; |
|
| 2236 | + $sql .= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; |
|
| 2237 | + $sql .= " WHERE fk_product_price=".$objp->price_rowid; |
|
| 2238 | 2238 | $sql .= " ORDER BY quantity ASC"; |
| 2239 | 2239 | |
| 2240 | - dol_syslog(get_class($this) . "::select_produits_list search price by qty", LOG_DEBUG); |
|
| 2240 | + dol_syslog(get_class($this)."::select_produits_list search price by qty", LOG_DEBUG); |
|
| 2241 | 2241 | $result2 = $this->db->query($sql); |
| 2242 | 2242 | if ($result2) {
|
| 2243 | 2243 | $nb_prices = $this->db->num_rows($result2); |
@@ -2341,7 +2341,7 @@ discard block |
||
| 2341 | 2341 | if (!empty($objp->label_translated)) |
| 2342 | 2342 | $label = $objp->label_translated; |
| 2343 | 2343 | if (!empty($filterkey) && $filterkey != '') |
| 2344 | - $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2344 | + $label = preg_replace('/('.preg_quote($filterkey).')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2345 | 2345 | |
| 2346 | 2346 | $outkey = $objp->rowid; |
| 2347 | 2347 | $outref = $objp->ref; |
@@ -2353,10 +2353,10 @@ discard block |
||
| 2353 | 2353 | $outdurationvalue = $outtype == Product::TYPE_SERVICE ? substr($objp->duration, 0, dol_strlen($objp->duration) - 1) : ''; |
| 2354 | 2354 | $outdurationunit = $outtype == Product::TYPE_SERVICE ? substr($objp->duration, -1) : ''; |
| 2355 | 2355 | |
| 2356 | - $opt = '<option value="' . $objp->rowid . '"'; |
|
| 2356 | + $opt = '<option value="'.$objp->rowid.'"'; |
|
| 2357 | 2357 | $opt .= ($objp->rowid == $selected) ? ' selected' : ''; |
| 2358 | 2358 | if (!empty($objp->price_by_qty_rowid) && $objp->price_by_qty_rowid > 0) {
|
| 2359 | - $opt .= ' pbq="' . $objp->price_by_qty_rowid . '" data-pbq="' . $objp->price_by_qty_rowid . '" data-pbqqty="' . $objp->price_by_qty_quantity . '" data-pbqpercent="' . $objp->price_by_qty_remise_percent . '"'; |
|
| 2359 | + $opt .= ' pbq="'.$objp->price_by_qty_rowid.'" data-pbq="'.$objp->price_by_qty_rowid.'" data-pbqqty="'.$objp->price_by_qty_quantity.'" data-pbqpercent="'.$objp->price_by_qty_remise_percent.'"'; |
|
| 2360 | 2360 | } |
| 2361 | 2361 | if (!empty($conf->stock->enabled) && $objp->fk_product_type == 0 && isset($objp->stock)) {
|
| 2362 | 2362 | if ($objp->stock > 0) |
@@ -2367,16 +2367,16 @@ discard block |
||
| 2367 | 2367 | $opt .= '>'; |
| 2368 | 2368 | $opt .= $objp->ref; |
| 2369 | 2369 | if ($outbarcode) |
| 2370 | - $opt .= ' (' . $outbarcode . ')';
|
|
| 2371 | - $opt .= ' - ' . dol_trunc($label, $maxlengtharticle); |
|
| 2370 | + $opt .= ' ('.$outbarcode.')';
|
|
| 2371 | + $opt .= ' - '.dol_trunc($label, $maxlengtharticle); |
|
| 2372 | 2372 | |
| 2373 | 2373 | $objRef = $objp->ref; |
| 2374 | 2374 | if (!empty($filterkey) && $filterkey != '') |
| 2375 | - $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2375 | + $objRef = preg_replace('/('.preg_quote($filterkey).')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2376 | 2376 | $outval .= $objRef; |
| 2377 | 2377 | if ($outbarcode) |
| 2378 | - $outval .= ' (' . $outbarcode . ')';
|
|
| 2379 | - $outval .= ' - ' . dol_trunc($label, $maxlengtharticle); |
|
| 2378 | + $outval .= ' ('.$outbarcode.')';
|
|
| 2379 | + $outval .= ' - '.dol_trunc($label, $maxlengtharticle); |
|
| 2380 | 2380 | |
| 2381 | 2381 | $found = 0; |
| 2382 | 2382 | |
@@ -2384,25 +2384,25 @@ discard block |
||
| 2384 | 2384 | // If we need a particular price level (from 1 to 6) |
| 2385 | 2385 | if (empty($hidepriceinlabel) && $price_level >= 1 && (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES))) {
|
| 2386 | 2386 | $sql = "SELECT price, price_ttc, price_base_type, tva_tx"; |
| 2387 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product_price"; |
|
| 2388 | - $sql .= " WHERE fk_product='" . $objp->rowid . "'"; |
|
| 2389 | - $sql .= " AND entity IN (" . getEntity('productprice') . ")";
|
|
| 2390 | - $sql .= " AND price_level=" . $price_level; |
|
| 2387 | + $sql .= " FROM ".MAIN_DB_PREFIX."product_price"; |
|
| 2388 | + $sql .= " WHERE fk_product='".$objp->rowid."'"; |
|
| 2389 | + $sql .= " AND entity IN (".getEntity('productprice').")";
|
|
| 2390 | + $sql .= " AND price_level=".$price_level; |
|
| 2391 | 2391 | $sql .= " ORDER BY date_price DESC, rowid DESC"; // Warning DESC must be both on date_price and rowid. |
| 2392 | 2392 | $sql .= " LIMIT 1"; |
| 2393 | 2393 | |
| 2394 | - dol_syslog(get_class($this) . '::constructProductListOption search price for level ' . $price_level . '', LOG_DEBUG); |
|
| 2394 | + dol_syslog(get_class($this).'::constructProductListOption search price for level '.$price_level.'', LOG_DEBUG); |
|
| 2395 | 2395 | $result2 = $this->db->query($sql); |
| 2396 | 2396 | if ($result2) {
|
| 2397 | 2397 | $objp2 = $this->db->fetch_object($result2); |
| 2398 | 2398 | if ($objp2) {
|
| 2399 | 2399 | $found = 1; |
| 2400 | 2400 | if ($objp2->price_base_type == 'HT') {
|
| 2401 | - $opt .= ' - ' . price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
|
| 2402 | - $outval .= ' - ' . price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
|
| 2401 | + $opt .= ' - '.price($objp2->price, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("HT");
|
|
| 2402 | + $outval .= ' - '.price($objp2->price, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("HT");
|
|
| 2403 | 2403 | } else {
|
| 2404 | - $opt .= ' - ' . price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
|
| 2405 | - $outval .= ' - ' . price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
|
| 2404 | + $opt .= ' - '.price($objp2->price_ttc, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("TTC");
|
|
| 2405 | + $outval .= ' - '.price($objp2->price_ttc, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("TTC");
|
|
| 2406 | 2406 | } |
| 2407 | 2407 | $outprice_ht = price($objp2->price); |
| 2408 | 2408 | $outprice_ttc = price($objp2->price_ttc); |
@@ -2420,13 +2420,13 @@ discard block |
||
| 2420 | 2420 | $outqty = $objp->quantity; |
| 2421 | 2421 | $outdiscount = $objp->remise_percent; |
| 2422 | 2422 | if ($objp->quantity == 1) {
|
| 2423 | - $opt .= ' - ' . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/"; |
|
| 2424 | - $outval .= ' - ' . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/"; |
|
| 2423 | + $opt .= ' - '.price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/"; |
|
| 2424 | + $outval .= ' - '.price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/"; |
|
| 2425 | 2425 | $opt .= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding
|
| 2426 | 2426 | $outval .= $langs->transnoentities("Unit");
|
| 2427 | 2427 | } else {
|
| 2428 | - $opt .= ' - ' . price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity; |
|
| 2429 | - $outval .= ' - ' . price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity; |
|
| 2428 | + $opt .= ' - '.price($objp->price, 1, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
|
| 2429 | + $outval .= ' - '.price($objp->price, 0, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
|
| 2430 | 2430 | $opt .= $langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding
|
| 2431 | 2431 | $outval .= $langs->transnoentities("Units");
|
| 2432 | 2432 | } |
@@ -2437,12 +2437,12 @@ discard block |
||
| 2437 | 2437 | $outtva_tx = $objp->tva_tx; |
| 2438 | 2438 | } |
| 2439 | 2439 | if (empty($hidepriceinlabel) && !empty($objp->quantity) && $objp->quantity >= 1) {
|
| 2440 | - $opt .= " (" . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2441 | - $outval .= " (" . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->transnoentities("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2440 | + $opt .= " (".price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit").")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2441 | + $outval .= " (".price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->transnoentities("Unit").")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2442 | 2442 | } |
| 2443 | 2443 | if (empty($hidepriceinlabel) && !empty($objp->remise_percent) && $objp->remise_percent >= 1) {
|
| 2444 | - $opt .= " - " . $langs->trans("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
|
| 2445 | - $outval .= " - " . $langs->transnoentities("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
|
| 2444 | + $opt .= " - ".$langs->trans("Discount")." : ".vatrate($objp->remise_percent).' %';
|
|
| 2445 | + $outval .= " - ".$langs->transnoentities("Discount")." : ".vatrate($objp->remise_percent).' %';
|
|
| 2446 | 2446 | } |
| 2447 | 2447 | |
| 2448 | 2448 | // Price by customer |
@@ -2451,11 +2451,11 @@ discard block |
||
| 2451 | 2451 | $found = 1; |
| 2452 | 2452 | |
| 2453 | 2453 | if ($objp->custprice_base_type == 'HT') {
|
| 2454 | - $opt .= ' - ' . price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
|
| 2455 | - $outval .= ' - ' . price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
|
| 2454 | + $opt .= ' - '.price($objp->custprice, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("HT");
|
|
| 2455 | + $outval .= ' - '.price($objp->custprice, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("HT");
|
|
| 2456 | 2456 | } else {
|
| 2457 | - $opt .= ' - ' . price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
|
| 2458 | - $outval .= ' - ' . price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
|
| 2457 | + $opt .= ' - '.price($objp->custprice_ttc, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("TTC");
|
|
| 2458 | + $outval .= ' - '.price($objp->custprice_ttc, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("TTC");
|
|
| 2459 | 2459 | } |
| 2460 | 2460 | |
| 2461 | 2461 | $outprice_ht = price($objp->custprice); |
@@ -2468,11 +2468,11 @@ discard block |
||
| 2468 | 2468 | // If level no defined or multiprice not found, we used the default price |
| 2469 | 2469 | if (empty($hidepriceinlabel) && !$found) {
|
| 2470 | 2470 | if ($objp->price_base_type == 'HT') {
|
| 2471 | - $opt .= ' - ' . price($objp->price, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("HT");
|
|
| 2472 | - $outval .= ' - ' . price($objp->price, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("HT");
|
|
| 2471 | + $opt .= ' - '.price($objp->price, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("HT");
|
|
| 2472 | + $outval .= ' - '.price($objp->price, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("HT");
|
|
| 2473 | 2473 | } else {
|
| 2474 | - $opt .= ' - ' . price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->trans("TTC");
|
|
| 2475 | - $outval .= ' - ' . price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency) . ' ' . $langs->transnoentities("TTC");
|
|
| 2474 | + $opt .= ' - '.price($objp->price_ttc, 1, $langs, 0, 0, -1, $conf->currency).' '.$langs->trans("TTC");
|
|
| 2475 | + $outval .= ' - '.price($objp->price_ttc, 0, $langs, 0, 0, -1, $conf->currency).' '.$langs->transnoentities("TTC");
|
|
| 2476 | 2476 | } |
| 2477 | 2477 | $outprice_ht = price($objp->price); |
| 2478 | 2478 | $outprice_ttc = price($objp->price_ttc); |
@@ -2481,21 +2481,21 @@ discard block |
||
| 2481 | 2481 | } |
| 2482 | 2482 | |
| 2483 | 2483 | if (!empty($conf->stock->enabled) && isset($objp->stock) && $objp->fk_product_type == 0) {
|
| 2484 | - $opt .= ' - ' . $langs->trans("Stock") . ':' . $objp->stock;
|
|
| 2484 | + $opt .= ' - '.$langs->trans("Stock").':'.$objp->stock;
|
|
| 2485 | 2485 | |
| 2486 | 2486 | if ($objp->stock > 0) {
|
| 2487 | - $outval .= ' - <span class="product_line_stock_ok">' . $langs->transnoentities("Stock") . ':' . $objp->stock . '</span>';
|
|
| 2487 | + $outval .= ' - <span class="product_line_stock_ok">'.$langs->transnoentities("Stock").':'.$objp->stock.'</span>';
|
|
| 2488 | 2488 | } elseif ($objp->stock <= 0) {
|
| 2489 | - $outval .= ' - <span class="product_line_stock_too_low">' . $langs->transnoentities("Stock") . ':' . $objp->stock . '</span>';
|
|
| 2489 | + $outval .= ' - <span class="product_line_stock_too_low">'.$langs->transnoentities("Stock").':'.$objp->stock.'</span>';
|
|
| 2490 | 2490 | } |
| 2491 | 2491 | } |
| 2492 | 2492 | |
| 2493 | 2493 | if ($outdurationvalue && $outdurationunit) {
|
| 2494 | 2494 | $da = array("h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year"));
|
| 2495 | 2495 | if (isset($da[$outdurationunit])) {
|
| 2496 | - $key = $da[$outdurationunit] . ($outdurationvalue > 1 ? 's' : ''); |
|
| 2497 | - $opt .= ' - ' . $outdurationvalue . ' ' . $langs->trans($key); |
|
| 2498 | - $outval .= ' - ' . $outdurationvalue . ' ' . $langs->transnoentities($key); |
|
| 2496 | + $key = $da[$outdurationunit].($outdurationvalue > 1 ? 's' : ''); |
|
| 2497 | + $opt .= ' - '.$outdurationvalue.' '.$langs->trans($key); |
|
| 2498 | + $outval .= ' - '.$outdurationvalue.' '.$langs->transnoentities($key); |
|
| 2499 | 2499 | } |
| 2500 | 2500 | } |
| 2501 | 2501 | |
@@ -2526,7 +2526,7 @@ discard block |
||
| 2526 | 2526 | $selected_input_value = ''; |
| 2527 | 2527 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
|
| 2528 | 2528 | if ($selected > 0) {
|
| 2529 | - require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; |
|
| 2529 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 2530 | 2530 | $producttmpselect = new Product($this->db); |
| 2531 | 2531 | $producttmpselect->fetch($selected); |
| 2532 | 2532 | $selected_input_value = $producttmpselect->ref; |
@@ -2534,9 +2534,9 @@ discard block |
||
| 2534 | 2534 | } |
| 2535 | 2535 | |
| 2536 | 2536 | // mode=2 means suppliers products |
| 2537 | - $urloption = ($socid > 0 ? 'socid=' . $socid . '&' : '') . 'htmlname=' . $htmlname . '&outjson=1&price_level=' . $price_level . '&type=' . $filtertype . '&mode=2&status=' . $status . '&finished=' . $finished . '&alsoproductwithnosupplierprice=' . $alsoproductwithnosupplierprice; |
|
| 2538 | - print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
|
| 2539 | - print ($hidelabel ? '' : $langs->trans("RefOrLabel") . ' : ') . '<input type="text" size="20" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $selected_input_value . '">';
|
|
| 2537 | + $urloption = ($socid > 0 ? 'socid='.$socid.'&' : '').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished.'&alsoproductwithnosupplierprice='.$alsoproductwithnosupplierprice; |
|
| 2538 | + print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
|
| 2539 | + print ($hidelabel ? '' : $langs->trans("RefOrLabel").' : ').'<input type="text" size="20" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$selected_input_value.'">';
|
|
| 2540 | 2540 | } else {
|
| 2541 | 2541 | print $this->select_produits_fournisseurs_list($socid, $selected, $htmlname, $filtertype, $filtre, '', -1, 0, 0, $alsoproductwithnosupplierprice); |
| 2542 | 2542 | } |
@@ -2572,17 +2572,17 @@ discard block |
||
| 2572 | 2572 | $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,"; |
| 2573 | 2573 | $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; |
| 2574 | 2574 | $sql .= " pfp.supplier_reputation"; |
| 2575 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; |
|
| 2576 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
|
| 2575 | + $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; |
|
| 2576 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
|
| 2577 | 2577 | if ($socid) |
| 2578 | - $sql .= " AND pfp.fk_soc = " . $socid; |
|
| 2579 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON pfp.fk_soc = s.rowid"; |
|
| 2580 | - $sql .= " WHERE p.entity IN (" . getEntity('product') . ")";
|
|
| 2578 | + $sql .= " AND pfp.fk_soc = ".$socid; |
|
| 2579 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; |
|
| 2580 | + $sql .= " WHERE p.entity IN (".getEntity('product').")";
|
|
| 2581 | 2581 | $sql .= " AND p.tobuy = 1"; |
| 2582 | 2582 | if (strval($filtertype) != '') |
| 2583 | - $sql .= " AND p.fk_product_type=" . $this->db->escape($filtertype); |
|
| 2583 | + $sql .= " AND p.fk_product_type=".$this->db->escape($filtertype); |
|
| 2584 | 2584 | if (!empty($filtre)) |
| 2585 | - $sql .= " " . $filtre; |
|
| 2585 | + $sql .= " ".$filtre; |
|
| 2586 | 2586 | // Add criteria on ref/label |
| 2587 | 2587 | if ($filterkey != '') {
|
| 2588 | 2588 | $sql .= ' AND (';
|
@@ -2595,13 +2595,13 @@ discard block |
||
| 2595 | 2595 | foreach ($scrit as $crit) {
|
| 2596 | 2596 | if ($i > 0) |
| 2597 | 2597 | $sql .= " AND "; |
| 2598 | - $sql .= "(pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) . "%' OR p.ref LIKE '" . $this->db->escape($prefix . $crit) . "%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) . "%')"; |
|
| 2598 | + $sql .= "(pfp.ref_fourn LIKE '".$this->db->escape($prefix.$crit)."%' OR p.ref LIKE '".$this->db->escape($prefix.$crit)."%' OR p.label LIKE '".$this->db->escape($prefix.$crit)."%')"; |
|
| 2599 | 2599 | $i++; |
| 2600 | 2600 | } |
| 2601 | 2601 | if (count($scrit) > 1) |
| 2602 | 2602 | $sql .= ")"; |
| 2603 | 2603 | if (!empty($conf->barcode->enabled)) |
| 2604 | - $sql .= " OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 2604 | + $sql .= " OR p.barcode LIKE '".$this->db->escape($prefix.$filterkey)."%'"; |
|
| 2605 | 2605 | $sql .= ')'; |
| 2606 | 2606 | } |
| 2607 | 2607 | $sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; |
@@ -2609,15 +2609,15 @@ discard block |
||
| 2609 | 2609 | |
| 2610 | 2610 | // Build output string |
| 2611 | 2611 | |
| 2612 | - dol_syslog(get_class($this) . "::select_produits_fournisseurs_list", LOG_DEBUG); |
|
| 2612 | + dol_syslog(get_class($this)."::select_produits_fournisseurs_list", LOG_DEBUG); |
|
| 2613 | 2613 | $result = $this->db->query($sql); |
| 2614 | 2614 | if ($result) {
|
| 2615 | - require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php'; |
|
| 2615 | + require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; |
|
| 2616 | 2616 | |
| 2617 | 2617 | $num = $this->db->num_rows($result); |
| 2618 | 2618 | |
| 2619 | 2619 | //$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax |
| 2620 | - $out .= '<select class="flat maxwidthonsmartphone" id="' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 2620 | + $out .= '<select class="flat maxwidthonsmartphone" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 2621 | 2621 | if (!$selected) |
| 2622 | 2622 | $out .= '<option value="0" selected> </option>'; |
| 2623 | 2623 | else |
@@ -2627,9 +2627,9 @@ discard block |
||
| 2627 | 2627 | while ($i < $num) {
|
| 2628 | 2628 | $objp = $this->db->fetch_object($result); |
| 2629 | 2629 | |
| 2630 | - $outkey = $objp->idprodfournprice; // id in table of price |
|
| 2630 | + $outkey = $objp->idprodfournprice; // id in table of price |
|
| 2631 | 2631 | if (!$outkey && $alsoproductwithnosupplierprice) |
| 2632 | - $outkey = 'idprod_' . $objp->rowid; // id of product |
|
| 2632 | + $outkey = 'idprod_'.$objp->rowid; // id of product |
|
| 2633 | 2633 | |
| 2634 | 2634 | $outref = $objp->ref; |
| 2635 | 2635 | $outval = ''; |
@@ -2639,36 +2639,36 @@ discard block |
||
| 2639 | 2639 | $outdurationvalue = $outtype == Product::TYPE_SERVICE ? substr($objp->duration, 0, dol_strlen($objp->duration) - 1) : ''; |
| 2640 | 2640 | $outdurationunit = $outtype == Product::TYPE_SERVICE ? substr($objp->duration, -1) : ''; |
| 2641 | 2641 | |
| 2642 | - $opt = '<option value="' . $outkey . '"'; |
|
| 2642 | + $opt = '<option value="'.$outkey.'"'; |
|
| 2643 | 2643 | if ($selected && $selected == $objp->idprodfournprice) |
| 2644 | 2644 | $opt .= ' selected'; |
| 2645 | 2645 | if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) |
| 2646 | 2646 | $opt .= ' disabled'; |
| 2647 | 2647 | if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
|
| 2648 | - $opt .= ' pbq="' . $objp->idprodfournprice . '" data-pbq="' . $objp->idprodfournprice . '" data-pbqqty="' . $objp->quantity . '" data-pbqpercent="' . $objp->remise_percent . '"'; |
|
| 2648 | + $opt .= ' pbq="'.$objp->idprodfournprice.'" data-pbq="'.$objp->idprodfournprice.'" data-pbqqty="'.$objp->quantity.'" data-pbqpercent="'.$objp->remise_percent.'"'; |
|
| 2649 | 2649 | } |
| 2650 | 2650 | $opt .= '>'; |
| 2651 | 2651 | |
| 2652 | 2652 | $objRef = $objp->ref; |
| 2653 | 2653 | if ($filterkey && $filterkey != '') |
| 2654 | - $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2654 | + $objRef = preg_replace('/('.preg_quote($filterkey).')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2655 | 2655 | $objRefFourn = $objp->ref_fourn; |
| 2656 | 2656 | if ($filterkey && $filterkey != '') |
| 2657 | - $objRefFourn = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRefFourn, 1);
|
|
| 2657 | + $objRefFourn = preg_replace('/('.preg_quote($filterkey).')/i', '<strong>$1</strong>', $objRefFourn, 1);
|
|
| 2658 | 2658 | $label = $objp->label; |
| 2659 | 2659 | if ($filterkey && $filterkey != '') |
| 2660 | - $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2660 | + $label = preg_replace('/('.preg_quote($filterkey).')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2661 | 2661 | |
| 2662 | 2662 | $opt .= $objp->ref; |
| 2663 | 2663 | if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) |
| 2664 | - $opt .= ' (' . $objp->ref_fourn . ')';
|
|
| 2664 | + $opt .= ' ('.$objp->ref_fourn.')';
|
|
| 2665 | 2665 | $opt .= ' - '; |
| 2666 | 2666 | $outval .= $objRef; |
| 2667 | 2667 | if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) |
| 2668 | - $outval .= ' (' . $objRefFourn . ')';
|
|
| 2668 | + $outval .= ' ('.$objRefFourn.')';
|
|
| 2669 | 2669 | $outval .= ' - '; |
| 2670 | - $opt .= dol_trunc($label, 72) . ' - '; |
|
| 2671 | - $outval .= dol_trunc($label, 72) . ' - '; |
|
| 2670 | + $opt .= dol_trunc($label, 72).' - '; |
|
| 2671 | + $outval .= dol_trunc($label, 72).' - '; |
|
| 2672 | 2672 | |
| 2673 | 2673 | if (!empty($objp->idprodfournprice)) {
|
| 2674 | 2674 | $outqty = $objp->quantity; |
@@ -2690,39 +2690,39 @@ discard block |
||
| 2690 | 2690 | } |
| 2691 | 2691 | } |
| 2692 | 2692 | if ($objp->quantity == 1) {
|
| 2693 | - $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency) . "/"; |
|
| 2694 | - $outval .= price($objp->fprice, 0, $langs, 0, 0, -1, $conf->currency) . "/"; |
|
| 2693 | + $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency)."/"; |
|
| 2694 | + $outval .= price($objp->fprice, 0, $langs, 0, 0, -1, $conf->currency)."/"; |
|
| 2695 | 2695 | $opt .= $langs->trans("Unit"); // Do not use strtolower because it breaks utf8 encoding
|
| 2696 | 2696 | $outval .= $langs->transnoentities("Unit");
|
| 2697 | 2697 | } else {
|
| 2698 | - $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity; |
|
| 2699 | - $outval .= price($objp->fprice, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $objp->quantity; |
|
| 2700 | - $opt .= ' ' . $langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding
|
|
| 2701 | - $outval .= ' ' . $langs->transnoentities("Units");
|
|
| 2698 | + $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
|
| 2699 | + $outval .= price($objp->fprice, 0, $langs, 0, 0, -1, $conf->currency)."/".$objp->quantity; |
|
| 2700 | + $opt .= ' '.$langs->trans("Units"); // Do not use strtolower because it breaks utf8 encoding
|
|
| 2701 | + $outval .= ' '.$langs->transnoentities("Units");
|
|
| 2702 | 2702 | } |
| 2703 | 2703 | |
| 2704 | 2704 | if ($objp->quantity >= 1) {
|
| 2705 | - $opt .= " (" . price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2706 | - $outval .= " (" . price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->transnoentities("Unit") . ")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2705 | + $opt .= " (".price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit").")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2706 | + $outval .= " (".price($objp->unitprice, 0, $langs, 0, 0, -1, $conf->currency)."/".$langs->transnoentities("Unit").")"; // Do not use strtolower because it breaks utf8 encoding
|
|
| 2707 | 2707 | } |
| 2708 | 2708 | if ($objp->remise_percent >= 1) {
|
| 2709 | - $opt .= " - " . $langs->trans("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
|
| 2710 | - $outval .= " - " . $langs->transnoentities("Discount") . " : " . vatrate($objp->remise_percent) . ' %';
|
|
| 2709 | + $opt .= " - ".$langs->trans("Discount")." : ".vatrate($objp->remise_percent).' %';
|
|
| 2710 | + $outval .= " - ".$langs->transnoentities("Discount")." : ".vatrate($objp->remise_percent).' %';
|
|
| 2711 | 2711 | } |
| 2712 | 2712 | if ($objp->duration) {
|
| 2713 | - $opt .= " - " . $objp->duration; |
|
| 2714 | - $outval .= " - " . $objp->duration; |
|
| 2713 | + $opt .= " - ".$objp->duration; |
|
| 2714 | + $outval .= " - ".$objp->duration; |
|
| 2715 | 2715 | } |
| 2716 | 2716 | if (!$socid) {
|
| 2717 | - $opt .= " - " . dol_trunc($objp->name, 8); |
|
| 2718 | - $outval .= " - " . dol_trunc($objp->name, 8); |
|
| 2717 | + $opt .= " - ".dol_trunc($objp->name, 8); |
|
| 2718 | + $outval .= " - ".dol_trunc($objp->name, 8); |
|
| 2719 | 2719 | } |
| 2720 | 2720 | if ($objp->supplier_reputation) {
|
| 2721 | 2721 | //TODO dictionary |
| 2722 | 2722 | $reputations = array('' => $langs->trans('Standard'), 'FAVORITE' => $langs->trans('Favorite'), 'NOTTHGOOD' => $langs->trans('NotTheGoodQualitySupplier'), 'DONOTORDER' => $langs->trans('DoNotOrderThisProductToThisSupplier'));
|
| 2723 | 2723 | |
| 2724 | - $opt .= " - " . $reputations[$objp->supplier_reputation]; |
|
| 2725 | - $outval .= " - " . $reputations[$objp->supplier_reputation]; |
|
| 2724 | + $opt .= " - ".$reputations[$objp->supplier_reputation]; |
|
| 2725 | + $outval .= " - ".$reputations[$objp->supplier_reputation]; |
|
| 2726 | 2726 | } |
| 2727 | 2727 | } else {
|
| 2728 | 2728 | if (empty($alsoproductwithnosupplierprice)) { // No supplier price defined for couple product/supplier
|
@@ -2756,7 +2756,7 @@ discard block |
||
| 2756 | 2756 | |
| 2757 | 2757 | $this->db->free($result); |
| 2758 | 2758 | |
| 2759 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 2759 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 2760 | 2760 | $out .= ajax_combobox($htmlname); |
| 2761 | 2761 | |
| 2762 | 2762 | if (empty($outputmode)) |
@@ -2787,39 +2787,39 @@ discard block |
||
| 2787 | 2787 | $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, pfp.fk_soc,"; |
| 2788 | 2788 | $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,"; |
| 2789 | 2789 | $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name"; |
| 2790 | - $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; |
|
| 2791 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
|
| 2792 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON pfp.fk_soc = s.rowid"; |
|
| 2793 | - $sql .= " WHERE pfp.entity IN (" . getEntity('productsupplierprice') . ")";
|
|
| 2790 | + $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; |
|
| 2791 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
|
| 2792 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON pfp.fk_soc = s.rowid"; |
|
| 2793 | + $sql .= " WHERE pfp.entity IN (".getEntity('productsupplierprice').")";
|
|
| 2794 | 2794 | $sql .= " AND p.tobuy = 1"; |
| 2795 | 2795 | $sql .= " AND s.fournisseur = 1"; |
| 2796 | - $sql .= " AND p.rowid = " . $productid; |
|
| 2796 | + $sql .= " AND p.rowid = ".$productid; |
|
| 2797 | 2797 | $sql .= " ORDER BY s.nom, pfp.ref_fourn DESC"; |
| 2798 | 2798 | |
| 2799 | - dol_syslog(get_class($this) . "::select_product_fourn_price", LOG_DEBUG); |
|
| 2799 | + dol_syslog(get_class($this)."::select_product_fourn_price", LOG_DEBUG); |
|
| 2800 | 2800 | $result = $this->db->query($sql); |
| 2801 | 2801 | |
| 2802 | 2802 | if ($result) {
|
| 2803 | 2803 | $num = $this->db->num_rows($result); |
| 2804 | 2804 | |
| 2805 | - $form = '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 2805 | + $form = '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 2806 | 2806 | |
| 2807 | 2807 | if (!$num) {
|
| 2808 | - $form .= '<option value="0">-- ' . $langs->trans("NoSupplierPriceDefinedForThisProduct") . ' --</option>';
|
|
| 2808 | + $form .= '<option value="0">-- '.$langs->trans("NoSupplierPriceDefinedForThisProduct").' --</option>';
|
|
| 2809 | 2809 | } else {
|
| 2810 | - require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php'; |
|
| 2810 | + require_once DOL_DOCUMENT_ROOT.'/product/dynamic_price/class/price_parser.class.php'; |
|
| 2811 | 2811 | $form .= '<option value="0"> </option>'; |
| 2812 | 2812 | |
| 2813 | 2813 | $i = 0; |
| 2814 | 2814 | while ($i < $num) {
|
| 2815 | 2815 | $objp = $this->db->fetch_object($result); |
| 2816 | 2816 | |
| 2817 | - $opt = '<option value="' . $objp->idprodfournprice . '"'; |
|
| 2817 | + $opt = '<option value="'.$objp->idprodfournprice.'"'; |
|
| 2818 | 2818 | //if there is only one supplier, preselect it |
| 2819 | 2819 | if ($num == 1 || ($selected_supplier > 0 && $objp->fk_soc == $selected_supplier)) {
|
| 2820 | 2820 | $opt .= ' selected'; |
| 2821 | 2821 | } |
| 2822 | - $opt .= '>' . $objp->name . ' - ' . $objp->ref_fourn . ' - '; |
|
| 2822 | + $opt .= '>'.$objp->name.' - '.$objp->ref_fourn.' - '; |
|
| 2823 | 2823 | |
| 2824 | 2824 | if (!empty($conf->dynamicprices->enabled) && !empty($objp->fk_supplier_price_expression)) {
|
| 2825 | 2825 | $prod_supplier = new ProductFournisseur($this->db); |
@@ -2838,10 +2838,10 @@ discard block |
||
| 2838 | 2838 | } |
| 2839 | 2839 | } |
| 2840 | 2840 | if ($objp->quantity == 1) {
|
| 2841 | - $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency) . "/"; |
|
| 2841 | + $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency)."/"; |
|
| 2842 | 2842 | } |
| 2843 | 2843 | |
| 2844 | - $opt .= $objp->quantity . ' '; |
|
| 2844 | + $opt .= $objp->quantity.' '; |
|
| 2845 | 2845 | |
| 2846 | 2846 | if ($objp->quantity == 1) {
|
| 2847 | 2847 | $opt .= $langs->trans("Unit");
|
@@ -2850,10 +2850,10 @@ discard block |
||
| 2850 | 2850 | } |
| 2851 | 2851 | if ($objp->quantity > 1) {
|
| 2852 | 2852 | $opt .= " - "; |
| 2853 | - $opt .= price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit");
|
|
| 2853 | + $opt .= price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency)."/".$langs->trans("Unit");
|
|
| 2854 | 2854 | } |
| 2855 | 2855 | if ($objp->duration) |
| 2856 | - $opt .= " - " . $objp->duration; |
|
| 2856 | + $opt .= " - ".$objp->duration; |
|
| 2857 | 2857 | $opt .= "</option>\n"; |
| 2858 | 2858 | |
| 2859 | 2859 | $form .= $opt; |
@@ -2885,14 +2885,14 @@ discard block |
||
| 2885 | 2885 | // phpcs:enable |
| 2886 | 2886 | // looking for users |
| 2887 | 2887 | $sql = "SELECT a.rowid, a.label"; |
| 2888 | - $sql .= " FROM " . MAIN_DB_PREFIX . "societe_address as a"; |
|
| 2889 | - $sql .= " WHERE a.fk_soc = " . $socid; |
|
| 2888 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_address as a"; |
|
| 2889 | + $sql .= " WHERE a.fk_soc = ".$socid; |
|
| 2890 | 2890 | $sql .= " ORDER BY a.label ASC"; |
| 2891 | 2891 | |
| 2892 | - dol_syslog(get_class($this) . "::select_address", LOG_DEBUG); |
|
| 2892 | + dol_syslog(get_class($this)."::select_address", LOG_DEBUG); |
|
| 2893 | 2893 | $resql = $this->db->query($sql); |
| 2894 | 2894 | if ($resql) {
|
| 2895 | - print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 2895 | + print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 2896 | 2896 | if ($showempty) |
| 2897 | 2897 | print '<option value="0"> </option>'; |
| 2898 | 2898 | $num = $this->db->num_rows($resql); |
@@ -2902,9 +2902,9 @@ discard block |
||
| 2902 | 2902 | $obj = $this->db->fetch_object($resql); |
| 2903 | 2903 | |
| 2904 | 2904 | if ($selected && $selected == $obj->rowid) {
|
| 2905 | - print '<option value="' . $obj->rowid . '" selected>' . $obj->label . '</option>'; |
|
| 2905 | + print '<option value="'.$obj->rowid.'" selected>'.$obj->label.'</option>'; |
|
| 2906 | 2906 | } else {
|
| 2907 | - print '<option value="' . $obj->rowid . '">' . $obj->label . '</option>'; |
|
| 2907 | + print '<option value="'.$obj->rowid.'">'.$obj->label.'</option>'; |
|
| 2908 | 2908 | } |
| 2909 | 2909 | $i++; |
| 2910 | 2910 | } |
@@ -2929,13 +2929,13 @@ discard block |
||
| 2929 | 2929 | |
| 2930 | 2930 | $num = count($this->cache_conditions_paiements); |
| 2931 | 2931 | if ($num > 0) |
| 2932 | - return 0; // Cache already loaded |
|
| 2932 | + return 0; // Cache already loaded |
|
| 2933 | 2933 | |
| 2934 | 2934 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 2935 | 2935 | |
| 2936 | 2936 | $sql = "SELECT rowid, code, libelle as label"; |
| 2937 | - $sql .= " FROM " . MAIN_DB_PREFIX . 'c_payment_term'; |
|
| 2938 | - $sql .= " WHERE entity IN (" . getEntity('c_payment_term') . ")";
|
|
| 2937 | + $sql .= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; |
|
| 2938 | + $sql .= " WHERE entity IN (".getEntity('c_payment_term').")";
|
|
| 2939 | 2939 | $sql .= " AND active > 0"; |
| 2940 | 2940 | $sql .= " ORDER BY sortorder"; |
| 2941 | 2941 | |
@@ -2947,7 +2947,7 @@ discard block |
||
| 2947 | 2947 | $obj = $this->db->fetch_object($resql); |
| 2948 | 2948 | |
| 2949 | 2949 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 2950 | - $label = ($langs->trans("PaymentConditionShort" . $obj->code) != ("PaymentConditionShort" . $obj->code) ? $langs->trans("PaymentConditionShort" . $obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 2950 | + $label = ($langs->trans("PaymentConditionShort".$obj->code) != ("PaymentConditionShort".$obj->code) ? $langs->trans("PaymentConditionShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 2951 | 2951 | $this->cache_conditions_paiements[$obj->rowid]['code'] = $obj->code; |
| 2952 | 2952 | $this->cache_conditions_paiements[$obj->rowid]['label'] = $label; |
| 2953 | 2953 | $i++; |
@@ -2975,14 +2975,14 @@ discard block |
||
| 2975 | 2975 | |
| 2976 | 2976 | $num = count($this->cache_availability); |
| 2977 | 2977 | if ($num > 0) |
| 2978 | - return 0; // Cache already loaded |
|
| 2978 | + return 0; // Cache already loaded |
|
| 2979 | 2979 | |
| 2980 | 2980 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 2981 | 2981 | |
| 2982 | 2982 | $langs->load('propal');
|
| 2983 | 2983 | |
| 2984 | 2984 | $sql = "SELECT rowid, code, label"; |
| 2985 | - $sql .= " FROM " . MAIN_DB_PREFIX . 'c_availability'; |
|
| 2985 | + $sql .= " FROM ".MAIN_DB_PREFIX.'c_availability'; |
|
| 2986 | 2986 | $sql .= " WHERE active > 0"; |
| 2987 | 2987 | |
| 2988 | 2988 | $resql = $this->db->query($sql); |
@@ -2993,7 +2993,7 @@ discard block |
||
| 2993 | 2993 | $obj = $this->db->fetch_object($resql); |
| 2994 | 2994 | |
| 2995 | 2995 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 2996 | - $label = ($langs->trans("AvailabilityType" . $obj->code) != ("AvailabilityType" . $obj->code) ? $langs->trans("AvailabilityType" . $obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 2996 | + $label = ($langs->trans("AvailabilityType".$obj->code) != ("AvailabilityType".$obj->code) ? $langs->trans("AvailabilityType".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 2997 | 2997 | $this->cache_availability[$obj->rowid]['code'] = $obj->code; |
| 2998 | 2998 | $this->cache_availability[$obj->rowid]['label'] = $label; |
| 2999 | 2999 | $i++; |
@@ -3023,16 +3023,16 @@ discard block |
||
| 3023 | 3023 | |
| 3024 | 3024 | $this->load_cache_availability(); |
| 3025 | 3025 | |
| 3026 | - dol_syslog(__METHOD__ . " selected=" . $selected . ", htmlname=" . $htmlname, LOG_DEBUG); |
|
| 3026 | + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); |
|
| 3027 | 3027 | |
| 3028 | - print '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; |
|
| 3028 | + print '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">'; |
|
| 3029 | 3029 | if ($addempty) |
| 3030 | 3030 | print '<option value="0"> </option>'; |
| 3031 | 3031 | foreach ($this->cache_availability as $id => $arrayavailability) {
|
| 3032 | 3032 | if ($selected == $id) {
|
| 3033 | - print '<option value="' . $id . '" selected>'; |
|
| 3033 | + print '<option value="'.$id.'" selected>'; |
|
| 3034 | 3034 | } else {
|
| 3035 | - print '<option value="' . $id . '">'; |
|
| 3035 | + print '<option value="'.$id.'">'; |
|
| 3036 | 3036 | } |
| 3037 | 3037 | print $arrayavailability['label']; |
| 3038 | 3038 | print '</option>'; |
@@ -3053,10 +3053,10 @@ discard block |
||
| 3053 | 3053 | |
| 3054 | 3054 | $num = count($this->cache_demand_reason); |
| 3055 | 3055 | if ($num > 0) |
| 3056 | - return 0; // Cache already loaded |
|
| 3056 | + return 0; // Cache already loaded |
|
| 3057 | 3057 | |
| 3058 | 3058 | $sql = "SELECT rowid, code, label"; |
| 3059 | - $sql .= " FROM " . MAIN_DB_PREFIX . 'c_input_reason'; |
|
| 3059 | + $sql .= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; |
|
| 3060 | 3060 | $sql .= " WHERE active > 0"; |
| 3061 | 3061 | |
| 3062 | 3062 | $resql = $this->db->query($sql); |
@@ -3069,10 +3069,10 @@ discard block |
||
| 3069 | 3069 | |
| 3070 | 3070 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 3071 | 3071 | $label = ($obj->label != '-' ? $obj->label : ''); |
| 3072 | - if ($langs->trans("DemandReasonType" . $obj->code) != ("DemandReasonType" . $obj->code))
|
|
| 3073 | - $label = $langs->trans("DemandReasonType" . $obj->code); // So translation key DemandReasonTypeSRC_XXX will work
|
|
| 3072 | + if ($langs->trans("DemandReasonType".$obj->code) != ("DemandReasonType".$obj->code))
|
|
| 3073 | + $label = $langs->trans("DemandReasonType".$obj->code); // So translation key DemandReasonTypeSRC_XXX will work
|
|
| 3074 | 3074 | if ($langs->trans($obj->code) != $obj->code) |
| 3075 | - $label = $langs->trans($obj->code); // So translation key SRC_XXX will work |
|
| 3075 | + $label = $langs->trans($obj->code); // So translation key SRC_XXX will work |
|
| 3076 | 3076 | |
| 3077 | 3077 | $tmparray[$obj->rowid]['id'] = $obj->rowid; |
| 3078 | 3078 | $tmparray[$obj->rowid]['code'] = $obj->code; |
@@ -3107,17 +3107,17 @@ discard block |
||
| 3107 | 3107 | |
| 3108 | 3108 | $this->loadCacheInputReason(); |
| 3109 | 3109 | |
| 3110 | - print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 3110 | + print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 3111 | 3111 | if ($addempty) |
| 3112 | - print '<option value="0"' . (empty($selected) ? ' selected' : '') . '> </option>'; |
|
| 3112 | + print '<option value="0"'.(empty($selected) ? ' selected' : '').'> </option>'; |
|
| 3113 | 3113 | foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
|
| 3114 | 3114 | if ($arraydemandreason['code'] == $exclude) |
| 3115 | 3115 | continue; |
| 3116 | 3116 | |
| 3117 | 3117 | if ($selected && ($selected == $arraydemandreason['id'] || $selected == $arraydemandreason['code'])) {
|
| 3118 | - print '<option value="' . $arraydemandreason['id'] . '" selected>'; |
|
| 3118 | + print '<option value="'.$arraydemandreason['id'].'" selected>'; |
|
| 3119 | 3119 | } else {
|
| 3120 | - print '<option value="' . $arraydemandreason['id'] . '">'; |
|
| 3120 | + print '<option value="'.$arraydemandreason['id'].'">'; |
|
| 3121 | 3121 | } |
| 3122 | 3122 | $label = $arraydemandreason['label']; // Translation of label was already done into the ->loadCacheInputReason |
| 3123 | 3123 | print $langs->trans($label); |
@@ -3141,15 +3141,15 @@ discard block |
||
| 3141 | 3141 | |
| 3142 | 3142 | $num = count($this->cache_types_paiements); |
| 3143 | 3143 | if ($num > 0) |
| 3144 | - return $num; // Cache already loaded |
|
| 3144 | + return $num; // Cache already loaded |
|
| 3145 | 3145 | |
| 3146 | 3146 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 3147 | 3147 | |
| 3148 | 3148 | $this->cache_types_paiements = array(); |
| 3149 | 3149 | |
| 3150 | 3150 | $sql = "SELECT id, code, libelle as label, type, active"; |
| 3151 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_paiement"; |
|
| 3152 | - $sql .= " WHERE entity IN (" . getEntity('c_paiement') . ")";
|
|
| 3151 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_paiement"; |
|
| 3152 | + $sql .= " WHERE entity IN (".getEntity('c_paiement').")";
|
|
| 3153 | 3153 | //if ($active >= 0) $sql.= " AND active = ".$active; |
| 3154 | 3154 | |
| 3155 | 3155 | $resql = $this->db->query($sql); |
@@ -3160,7 +3160,7 @@ discard block |
||
| 3160 | 3160 | $obj = $this->db->fetch_object($resql); |
| 3161 | 3161 | |
| 3162 | 3162 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 3163 | - $label = ($langs->transnoentitiesnoconv("PaymentTypeShort" . $obj->code) != ("PaymentTypeShort" . $obj->code) ? $langs->transnoentitiesnoconv("PaymentTypeShort" . $obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 3163 | + $label = ($langs->transnoentitiesnoconv("PaymentTypeShort".$obj->code) != ("PaymentTypeShort".$obj->code) ? $langs->transnoentitiesnoconv("PaymentTypeShort".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
|
|
| 3164 | 3164 | $this->cache_types_paiements[$obj->id]['id'] = $obj->id; |
| 3165 | 3165 | $this->cache_types_paiements[$obj->id]['code'] = $obj->code; |
| 3166 | 3166 | $this->cache_types_paiements[$obj->id]['label'] = $label; |
@@ -3197,7 +3197,7 @@ discard block |
||
| 3197 | 3197 | // phpcs:enable |
| 3198 | 3198 | global $langs, $user, $conf; |
| 3199 | 3199 | |
| 3200 | - dol_syslog(__METHOD__ . " selected=" . $selected . ", htmlname=" . $htmlname, LOG_DEBUG); |
|
| 3200 | + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); |
|
| 3201 | 3201 | |
| 3202 | 3202 | $this->load_cache_conditions_paiements(); |
| 3203 | 3203 | |
@@ -3205,14 +3205,14 @@ discard block |
||
| 3205 | 3205 | if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) |
| 3206 | 3206 | $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID; |
| 3207 | 3207 | |
| 3208 | - print '<select id="' . $htmlname . '" class="flat selectpaymentterms' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '">'; |
|
| 3208 | + print '<select id="'.$htmlname.'" class="flat selectpaymentterms'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">'; |
|
| 3209 | 3209 | if ($addempty) |
| 3210 | 3210 | print '<option value="0"> </option>'; |
| 3211 | 3211 | foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
| 3212 | 3212 | if ($selected == $id) {
|
| 3213 | - print '<option value="' . $id . '" selected>'; |
|
| 3213 | + print '<option value="'.$id.'" selected>'; |
|
| 3214 | 3214 | } else {
|
| 3215 | - print '<option value="' . $id . '">'; |
|
| 3215 | + print '<option value="'.$id.'">'; |
|
| 3216 | 3216 | } |
| 3217 | 3217 | print $arrayconditions['label']; |
| 3218 | 3218 | print '</option>'; |
@@ -3242,7 +3242,7 @@ discard block |
||
| 3242 | 3242 | // phpcs:enable |
| 3243 | 3243 | global $langs, $user; |
| 3244 | 3244 | |
| 3245 | - dol_syslog(__METHOD__ . " " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG); |
|
| 3245 | + dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); |
|
| 3246 | 3246 | |
| 3247 | 3247 | $filterarray = array(); |
| 3248 | 3248 | if ($filtertype == 'CRDT') |
@@ -3254,7 +3254,7 @@ discard block |
||
| 3254 | 3254 | |
| 3255 | 3255 | $this->load_cache_types_paiements(); |
| 3256 | 3256 | |
| 3257 | - print '<select id="select' . $htmlname . '" class="flat selectpaymenttypes' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '">'; |
|
| 3257 | + print '<select id="select'.$htmlname.'" class="flat selectpaymenttypes'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'">'; |
|
| 3258 | 3258 | if ($empty) |
| 3259 | 3259 | print '<option value=""> </option>'; |
| 3260 | 3260 | foreach ($this->cache_types_paiements as $id => $arraytypes) {
|
@@ -3271,13 +3271,13 @@ discard block |
||
| 3271 | 3271 | continue; |
| 3272 | 3272 | |
| 3273 | 3273 | if ($format == 0) |
| 3274 | - print '<option value="' . $id . '"'; |
|
| 3274 | + print '<option value="'.$id.'"'; |
|
| 3275 | 3275 | elseif ($format == 1) |
| 3276 | - print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3276 | + print '<option value="'.$arraytypes['code'].'"'; |
|
| 3277 | 3277 | elseif ($format == 2) |
| 3278 | - print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3278 | + print '<option value="'.$arraytypes['code'].'"'; |
|
| 3279 | 3279 | elseif ($format == 3) |
| 3280 | - print '<option value="' . $id . '"'; |
|
| 3280 | + print '<option value="'.$id.'"'; |
|
| 3281 | 3281 | // Si selected est text, on compare avec code, sinon avec id |
| 3282 | 3282 | if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code'])
|
| 3283 | 3283 | print ' selected'; |
@@ -3313,16 +3313,16 @@ discard block |
||
| 3313 | 3313 | |
| 3314 | 3314 | $return = ''; |
| 3315 | 3315 | |
| 3316 | - $return .= '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 3316 | + $return .= '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 3317 | 3317 | $options = array( |
| 3318 | 3318 | 'HT' => $langs->trans("HT"),
|
| 3319 | 3319 | 'TTC' => $langs->trans("TTC")
|
| 3320 | 3320 | ); |
| 3321 | 3321 | foreach ($options as $id => $value) {
|
| 3322 | 3322 | if ($selected == $id) {
|
| 3323 | - $return .= '<option value="' . $id . '" selected>' . $value; |
|
| 3323 | + $return .= '<option value="'.$id.'" selected>'.$value; |
|
| 3324 | 3324 | } else {
|
| 3325 | - $return .= '<option value="' . $id . '">' . $value; |
|
| 3325 | + $return .= '<option value="'.$id.'">'.$value; |
|
| 3326 | 3326 | } |
| 3327 | 3327 | $return .= '</option>'; |
| 3328 | 3328 | } |
@@ -3349,30 +3349,30 @@ discard block |
||
| 3349 | 3349 | $langs->load("deliveries");
|
| 3350 | 3350 | |
| 3351 | 3351 | $sql = "SELECT rowid, code, libelle as label"; |
| 3352 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_shipment_mode"; |
|
| 3352 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; |
|
| 3353 | 3353 | $sql .= " WHERE active > 0"; |
| 3354 | 3354 | if ($filtre) |
| 3355 | - $sql .= " AND " . $filtre; |
|
| 3355 | + $sql .= " AND ".$filtre; |
|
| 3356 | 3356 | $sql .= " ORDER BY libelle ASC"; |
| 3357 | 3357 | |
| 3358 | - dol_syslog(get_class($this) . "::selectShippingMode", LOG_DEBUG); |
|
| 3358 | + dol_syslog(get_class($this)."::selectShippingMode", LOG_DEBUG); |
|
| 3359 | 3359 | $result = $this->db->query($sql); |
| 3360 | 3360 | if ($result) {
|
| 3361 | 3361 | $num = $this->db->num_rows($result); |
| 3362 | 3362 | $i = 0; |
| 3363 | 3363 | if ($num) {
|
| 3364 | - print '<select id="select' . $htmlname . '" class="flat selectshippingmethod" name="' . $htmlname . '"' . ($moreattrib ? ' ' . $moreattrib : '') . '>'; |
|
| 3364 | + print '<select id="select'.$htmlname.'" class="flat selectshippingmethod" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>'; |
|
| 3365 | 3365 | if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
|
| 3366 | 3366 | print '<option value="-1"> </option>'; |
| 3367 | 3367 | } |
| 3368 | 3368 | while ($i < $num) {
|
| 3369 | 3369 | $obj = $this->db->fetch_object($result); |
| 3370 | 3370 | if ($selected == $obj->rowid) {
|
| 3371 | - print '<option value="' . $obj->rowid . '" selected>'; |
|
| 3371 | + print '<option value="'.$obj->rowid.'" selected>'; |
|
| 3372 | 3372 | } else {
|
| 3373 | - print '<option value="' . $obj->rowid . '">'; |
|
| 3373 | + print '<option value="'.$obj->rowid.'">'; |
|
| 3374 | 3374 | } |
| 3375 | - print ($langs->trans("SendingMethod" . strtoupper($obj->code)) != "SendingMethod" . strtoupper($obj->code)) ? $langs->trans("SendingMethod" . strtoupper($obj->code)) : $obj->label;
|
|
| 3375 | + print ($langs->trans("SendingMethod".strtoupper($obj->code)) != "SendingMethod".strtoupper($obj->code)) ? $langs->trans("SendingMethod".strtoupper($obj->code)) : $obj->label;
|
|
| 3376 | 3376 | print '</option>'; |
| 3377 | 3377 | $i++; |
| 3378 | 3378 | } |
@@ -3403,16 +3403,16 @@ discard block |
||
| 3403 | 3403 | $langs->load("deliveries");
|
| 3404 | 3404 | |
| 3405 | 3405 | if ($htmlname != "none") {
|
| 3406 | - print '<form method="POST" action="' . $page . '">'; |
|
| 3406 | + print '<form method="POST" action="'.$page.'">'; |
|
| 3407 | 3407 | print '<input type="hidden" name="action" value="setshippingmethod">'; |
| 3408 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 3408 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 3409 | 3409 | $this->selectShippingMethod($selected, $htmlname, '', $addempty); |
| 3410 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 3410 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 3411 | 3411 | print '</form>'; |
| 3412 | 3412 | } else {
|
| 3413 | 3413 | if ($selected) {
|
| 3414 | 3414 | $code = $langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); |
| 3415 | - print $langs->trans("SendingMethod" . strtoupper($code));
|
|
| 3415 | + print $langs->trans("SendingMethod".strtoupper($code));
|
|
| 3416 | 3416 | } else {
|
| 3417 | 3417 | print " "; |
| 3418 | 3418 | } |
@@ -3434,7 +3434,7 @@ discard block |
||
| 3434 | 3434 | $langs->load('bills');
|
| 3435 | 3435 | |
| 3436 | 3436 | $opt = '<option value ="" selected></option>'; |
| 3437 | - $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_counter>=1'; |
|
| 3437 | + $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc FROM '.MAIN_DB_PREFIX.'facture WHERE situation_counter>=1'; |
|
| 3438 | 3438 | $sql .= ' ORDER by situation_cycle_ref, situation_counter desc'; |
| 3439 | 3439 | $resql = $this->db->query($sql); |
| 3440 | 3440 | if ($resql && $this->db->num_rows($resql) > 0) {
|
@@ -3452,9 +3452,9 @@ discard block |
||
| 3452 | 3452 | //Not prov? |
| 3453 | 3453 | if (substr($obj->ref, 1, 4) != 'PROV') {
|
| 3454 | 3454 | if ($selected == $obj->rowid) {
|
| 3455 | - $opt .= '<option value="' . $obj->rowid . '" selected>' . $obj->ref . '</option>'; |
|
| 3455 | + $opt .= '<option value="'.$obj->rowid.'" selected>'.$obj->ref.'</option>'; |
|
| 3456 | 3456 | } else {
|
| 3457 | - $opt .= '<option value="' . $obj->rowid . '">' . $obj->ref . '</option>'; |
|
| 3457 | + $opt .= '<option value="'.$obj->rowid.'">'.$obj->ref.'</option>'; |
|
| 3458 | 3458 | } |
| 3459 | 3459 | } |
| 3460 | 3460 | } |
@@ -3462,10 +3462,10 @@ discard block |
||
| 3462 | 3462 | } |
| 3463 | 3463 | } |
| 3464 | 3464 | } else {
|
| 3465 | - dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR);
|
|
| 3465 | + dol_syslog("Error sql=".$sql.", error=".$this->error, LOG_ERR);
|
|
| 3466 | 3466 | } |
| 3467 | 3467 | if ($opt == '<option value ="" selected></option>') {
|
| 3468 | - $opt = '<option value ="0" selected>' . $langs->trans('NoSituations') . '</option>';
|
|
| 3468 | + $opt = '<option value ="0" selected>'.$langs->trans('NoSituations').'</option>';
|
|
| 3469 | 3469 | } |
| 3470 | 3470 | return $opt; |
| 3471 | 3471 | } |
@@ -3484,9 +3484,9 @@ discard block |
||
| 3484 | 3484 | |
| 3485 | 3485 | $langs->load('products');
|
| 3486 | 3486 | |
| 3487 | - $return = '<select class="flat" id="' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 3487 | + $return = '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 3488 | 3488 | |
| 3489 | - $sql = 'SELECT rowid, label, code from ' . MAIN_DB_PREFIX . 'c_units'; |
|
| 3489 | + $sql = 'SELECT rowid, label, code from '.MAIN_DB_PREFIX.'c_units'; |
|
| 3490 | 3490 | $sql .= ' WHERE active > 0'; |
| 3491 | 3491 | |
| 3492 | 3492 | $resql = $this->db->query($sql); |
@@ -3496,14 +3496,14 @@ discard block |
||
| 3496 | 3496 | |
| 3497 | 3497 | while ($res = $this->db->fetch_object($resql)) {
|
| 3498 | 3498 | $unitLabel = $res->label; |
| 3499 | - if (!empty($langs->tab_translate['unit' . $res->code])) { // check if Translation is available before
|
|
| 3500 | - $unitLabel = $langs->trans('unit' . $res->code) != $res->label ? $langs->trans('unit' . $res->code) : $res->label;
|
|
| 3499 | + if (!empty($langs->tab_translate['unit'.$res->code])) { // check if Translation is available before
|
|
| 3500 | + $unitLabel = $langs->trans('unit'.$res->code) != $res->label ? $langs->trans('unit'.$res->code) : $res->label;
|
|
| 3501 | 3501 | } |
| 3502 | 3502 | |
| 3503 | 3503 | if ($selected == $res->rowid) {
|
| 3504 | - $return .= '<option value="' . $res->rowid . '" selected>' . $unitLabel . '</option>'; |
|
| 3504 | + $return .= '<option value="'.$res->rowid.'" selected>'.$unitLabel.'</option>'; |
|
| 3505 | 3505 | } else {
|
| 3506 | - $return .= '<option value="' . $res->rowid . '">' . $unitLabel . '</option>'; |
|
| 3506 | + $return .= '<option value="'.$res->rowid.'">'.$unitLabel.'</option>'; |
|
| 3507 | 3507 | } |
| 3508 | 3508 | } |
| 3509 | 3509 | $return .= '</select>'; |
@@ -3533,21 +3533,21 @@ discard block |
||
| 3533 | 3533 | $num = 0; |
| 3534 | 3534 | |
| 3535 | 3535 | $sql = "SELECT rowid, label, bank, clos as status, currency_code"; |
| 3536 | - $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; |
|
| 3537 | - $sql .= " WHERE entity IN (" . getEntity('bank_account') . ")";
|
|
| 3536 | + $sql .= " FROM ".MAIN_DB_PREFIX."bank_account"; |
|
| 3537 | + $sql .= " WHERE entity IN (".getEntity('bank_account').")";
|
|
| 3538 | 3538 | if ($statut != 2) |
| 3539 | - $sql .= " AND clos = '" . $statut . "'"; |
|
| 3539 | + $sql .= " AND clos = '".$statut."'"; |
|
| 3540 | 3540 | if ($filtre) |
| 3541 | - $sql .= " AND " . $filtre; |
|
| 3541 | + $sql .= " AND ".$filtre; |
|
| 3542 | 3542 | $sql .= " ORDER BY label"; |
| 3543 | 3543 | |
| 3544 | - dol_syslog(get_class($this) . "::select_comptes", LOG_DEBUG); |
|
| 3544 | + dol_syslog(get_class($this)."::select_comptes", LOG_DEBUG); |
|
| 3545 | 3545 | $result = $this->db->query($sql); |
| 3546 | 3546 | if ($result) {
|
| 3547 | 3547 | $num = $this->db->num_rows($result); |
| 3548 | 3548 | $i = 0; |
| 3549 | 3549 | if ($num) {
|
| 3550 | - print '<select id="select' . $htmlname . '" class="flat selectbankaccount" name="' . $htmlname . '"' . ($moreattrib ? ' ' . $moreattrib : '') . '>'; |
|
| 3550 | + print '<select id="select'.$htmlname.'" class="flat selectbankaccount" name="'.$htmlname.'"'.($moreattrib ? ' '.$moreattrib : '').'>'; |
|
| 3551 | 3551 | if ($useempty == 1 || ($useempty == 2 && $num > 1)) {
|
| 3552 | 3552 | print '<option value="-1"> </option>'; |
| 3553 | 3553 | } |
@@ -3555,15 +3555,15 @@ discard block |
||
| 3555 | 3555 | while ($i < $num) {
|
| 3556 | 3556 | $obj = $this->db->fetch_object($result); |
| 3557 | 3557 | if ($selected == $obj->rowid) {
|
| 3558 | - print '<option value="' . $obj->rowid . '" selected>'; |
|
| 3558 | + print '<option value="'.$obj->rowid.'" selected>'; |
|
| 3559 | 3559 | } else {
|
| 3560 | - print '<option value="' . $obj->rowid . '">'; |
|
| 3560 | + print '<option value="'.$obj->rowid.'">'; |
|
| 3561 | 3561 | } |
| 3562 | 3562 | print trim($obj->label); |
| 3563 | 3563 | if ($showcurrency) |
| 3564 | - print ' (' . $obj->currency_code . ')';
|
|
| 3564 | + print ' ('.$obj->currency_code.')';
|
|
| 3565 | 3565 | if ($statut == 2 && $obj->status == 1) |
| 3566 | - print ' (' . $langs->trans("Closed") . ')';
|
|
| 3566 | + print ' ('.$langs->trans("Closed").')';
|
|
| 3567 | 3567 | print '</option>'; |
| 3568 | 3568 | $i++; |
| 3569 | 3569 | } |
@@ -3571,9 +3571,9 @@ discard block |
||
| 3571 | 3571 | } |
| 3572 | 3572 | else {
|
| 3573 | 3573 | if ($statut == 0) |
| 3574 | - print '<span class="opacitymedium">' . $langs->trans("NoActiveBankAccountDefined") . '</span>';
|
|
| 3574 | + print '<span class="opacitymedium">'.$langs->trans("NoActiveBankAccountDefined").'</span>';
|
|
| 3575 | 3575 | else |
| 3576 | - print '<span class="opacitymedium">' . $langs->trans("NoBankAccountFound") . '</span>';
|
|
| 3576 | + print '<span class="opacitymedium">'.$langs->trans("NoBankAccountFound").'</span>';
|
|
| 3577 | 3577 | } |
| 3578 | 3578 | } |
| 3579 | 3579 | else {
|
@@ -3596,19 +3596,19 @@ discard block |
||
| 3596 | 3596 | {
|
| 3597 | 3597 | global $langs; |
| 3598 | 3598 | if ($htmlname != "none") {
|
| 3599 | - print '<form method="POST" action="' . $page . '">'; |
|
| 3599 | + print '<form method="POST" action="'.$page.'">'; |
|
| 3600 | 3600 | print '<input type="hidden" name="action" value="setbankaccount">'; |
| 3601 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 3601 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 3602 | 3602 | $nbaccountfound = $this->select_comptes($selected, $htmlname, 0, '', $addempty); |
| 3603 | 3603 | if ($nbaccountfound > 0) |
| 3604 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 3604 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 3605 | 3605 | print '</form>'; |
| 3606 | 3606 | } else {
|
| 3607 | 3607 | |
| 3608 | 3608 | $langs->load('banks');
|
| 3609 | 3609 | |
| 3610 | 3610 | if ($selected) {
|
| 3611 | - require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; |
|
| 3611 | + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; |
|
| 3612 | 3612 | $bankstatic = new Account($this->db); |
| 3613 | 3613 | $result = $bankstatic->fetch($selected); |
| 3614 | 3614 | if ($result) |
@@ -3638,19 +3638,19 @@ discard block |
||
| 3638 | 3638 | global $conf, $langs; |
| 3639 | 3639 | $langs->load("categories");
|
| 3640 | 3640 | |
| 3641 | - include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; |
|
| 3641 | + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
| 3642 | 3642 | |
| 3643 | 3643 | // For backward compatibility |
| 3644 | 3644 | if (is_numeric($type)) {
|
| 3645 | - dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); |
|
| 3645 | + dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); |
|
| 3646 | 3646 | } |
| 3647 | 3647 | |
| 3648 | 3648 | if ($type === Categorie::TYPE_BANK_LINE) {
|
| 3649 | 3649 | // TODO Move this into common category feature |
| 3650 | 3650 | $categids = array(); |
| 3651 | 3651 | $sql = "SELECT c.label, c.rowid"; |
| 3652 | - $sql .= " FROM " . MAIN_DB_PREFIX . "bank_categ as c"; |
|
| 3653 | - $sql .= " WHERE entity = " . $conf->entity; |
|
| 3652 | + $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as c"; |
|
| 3653 | + $sql .= " WHERE entity = ".$conf->entity; |
|
| 3654 | 3654 | $sql .= " ORDER BY c.label"; |
| 3655 | 3655 | $result = $this->db->query($sql); |
| 3656 | 3656 | if ($result) {
|
@@ -3671,11 +3671,11 @@ discard block |
||
| 3671 | 3671 | $cate_arbo = $cat->get_full_arbo($type, $excludeafterid); |
| 3672 | 3672 | } |
| 3673 | 3673 | |
| 3674 | - $output = '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">'; |
|
| 3674 | + $output = '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">'; |
|
| 3675 | 3675 | $outarray = array(); |
| 3676 | 3676 | if (is_array($cate_arbo)) {
|
| 3677 | 3677 | if (!count($cate_arbo)) |
| 3678 | - $output .= '<option value="-1" disabled>' . $langs->trans("NoCategoriesDefined") . '</option>';
|
|
| 3678 | + $output .= '<option value="-1" disabled>'.$langs->trans("NoCategoriesDefined").'</option>';
|
|
| 3679 | 3679 | else {
|
| 3680 | 3680 | $output .= '<option value="-1"> </option>'; |
| 3681 | 3681 | foreach ($cate_arbo as $key => $value) {
|
@@ -3684,7 +3684,7 @@ discard block |
||
| 3684 | 3684 | } else {
|
| 3685 | 3685 | $add = ''; |
| 3686 | 3686 | } |
| 3687 | - $output .= '<option ' . $add . 'value="' . $cate_arbo[$key]['id'] . '">' . dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle') . '</option>'; |
|
| 3687 | + $output .= '<option '.$add.'value="'.$cate_arbo[$key]['id'].'">'.dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle').'</option>'; |
|
| 3688 | 3688 | |
| 3689 | 3689 | $outarray[$cate_arbo[$key]['id']] = $cate_arbo[$key]['fulllabel']; |
| 3690 | 3690 | } |
@@ -3718,7 +3718,7 @@ discard block |
||
| 3718 | 3718 | function form_confirm($page, $title, $question, $action, $formquestion = '', $selectedchoice = "", $useajax = 0, $height = 170, $width = 500) |
| 3719 | 3719 | {
|
| 3720 | 3720 | // phpcs:enable |
| 3721 | - dol_syslog(__METHOD__ . ': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING); |
|
| 3721 | + dol_syslog(__METHOD__.': using form_confirm is deprecated. Use formconfim instead.', LOG_WARNING); |
|
| 3722 | 3722 | print $this->formconfirm($page, $title, $question, $action, $formquestion, $selectedchoice, $useajax, $height, $width); |
| 3723 | 3723 | } |
| 3724 | 3724 | |
@@ -3766,36 +3766,36 @@ discard block |
||
| 3766 | 3766 | foreach ($formquestion as $key => $input) {
|
| 3767 | 3767 | if (is_array($input) && !empty($input)) {
|
| 3768 | 3768 | if ($input['type'] == 'hidden') {
|
| 3769 | - $more .= '<input type="hidden" id="' . $input['name'] . '" name="' . $input['name'] . '" value="' . dol_escape_htmltag($input['value']) . '">' . "\n"; |
|
| 3769 | + $more .= '<input type="hidden" id="'.$input['name'].'" name="'.$input['name'].'" value="'.dol_escape_htmltag($input['value']).'">'."\n"; |
|
| 3770 | 3770 | } |
| 3771 | 3771 | } |
| 3772 | 3772 | } |
| 3773 | 3773 | |
| 3774 | 3774 | // Now add questions |
| 3775 | - $more .= '<table class="paddingtopbottomonly" width="100%">' . "\n"; |
|
| 3775 | + $more .= '<table class="paddingtopbottomonly" width="100%">'."\n"; |
|
| 3776 | 3776 | if (!empty($formquestion['text'])) |
| 3777 | - $more .= '<tr><td colspan="2">' . $formquestion['text'] . '</td></tr>' . "\n"; |
|
| 3777 | + $more .= '<tr><td colspan="2">'.$formquestion['text'].'</td></tr>'."\n"; |
|
| 3778 | 3778 | foreach ($formquestion as $key => $input) {
|
| 3779 | 3779 | if (is_array($input) && !empty($input)) {
|
| 3780 | - $size = (!empty($input['size']) ? ' size="' . $input['size'] . '"' : ''); |
|
| 3781 | - $moreattr = (!empty($input['moreattr']) ? ' ' . $input['moreattr'] : ''); |
|
| 3782 | - $morecss = (!empty($input['morecss']) ? ' ' . $input['morecss'] : ''); |
|
| 3780 | + $size = (!empty($input['size']) ? ' size="'.$input['size'].'"' : ''); |
|
| 3781 | + $moreattr = (!empty($input['moreattr']) ? ' '.$input['moreattr'] : ''); |
|
| 3782 | + $morecss = (!empty($input['morecss']) ? ' '.$input['morecss'] : ''); |
|
| 3783 | 3783 | |
| 3784 | 3784 | if ($input['type'] == 'text') {
|
| 3785 | - $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td><td align="left"><input type="text" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '"' . $size . ' value="' . $input['value'] . '"' . $moreattr . ' /></td></tr>' . "\n";
|
|
| 3785 | + $more .= '<tr><td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'>'.$input['label'].'</td><td align="left"><input type="text" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$size.' value="'.$input['value'].'"'.$moreattr.' /></td></tr>'."\n";
|
|
| 3786 | 3786 | } elseif ($input['type'] == 'password') {
|
| 3787 | - $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td><td align="left"><input type="password" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '"' . $size . ' value="' . $input['value'] . '"' . $moreattr . ' /></td></tr>' . "\n";
|
|
| 3787 | + $more .= '<tr><td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'>'.$input['label'].'</td><td align="left"><input type="password" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$size.' value="'.$input['value'].'"'.$moreattr.' /></td></tr>'."\n";
|
|
| 3788 | 3788 | } elseif ($input['type'] == 'select') {
|
| 3789 | - $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>';
|
|
| 3789 | + $more .= '<tr><td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'>';
|
|
| 3790 | 3790 | if (!empty($input['label'])) |
| 3791 | - $more .= $input['label'] . '</td><td class="tdtop" align="left">'; |
|
| 3791 | + $more .= $input['label'].'</td><td class="tdtop" align="left">'; |
|
| 3792 | 3792 | $more .= $this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss); |
| 3793 | - $more .= '</td></tr>' . "\n"; |
|
| 3793 | + $more .= '</td></tr>'."\n"; |
|
| 3794 | 3794 | } |
| 3795 | 3795 | elseif ($input['type'] == 'checkbox') {
|
| 3796 | 3796 | $more .= '<tr>'; |
| 3797 | - $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . ' </td><td align="left">';
|
|
| 3798 | - $more .= '<input type="checkbox" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '"' . $moreattr; |
|
| 3797 | + $more .= '<td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'>'.$input['label'].' </td><td align="left">';
|
|
| 3798 | + $more .= '<input type="checkbox" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'"'.$moreattr; |
|
| 3799 | 3799 | if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') |
| 3800 | 3800 | $more .= ' checked'; |
| 3801 | 3801 | if (is_bool($input['value']) && $input['value']) |
@@ -3803,51 +3803,51 @@ discard block |
||
| 3803 | 3803 | if (isset($input['disabled'])) |
| 3804 | 3804 | $more .= ' disabled'; |
| 3805 | 3805 | $more .= ' /></td>'; |
| 3806 | - $more .= '</tr>' . "\n"; |
|
| 3806 | + $more .= '</tr>'."\n"; |
|
| 3807 | 3807 | } |
| 3808 | 3808 | elseif ($input['type'] == 'radio') {
|
| 3809 | 3809 | $i = 0; |
| 3810 | 3810 | foreach ($input['values'] as $selkey => $selval) {
|
| 3811 | 3811 | $more .= '<tr>'; |
| 3812 | 3812 | if ($i == 0) |
| 3813 | - $more .= '<td' . (empty($input['tdclass']) ? ' class="tdtop"' : (' class="tdtop ' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>';
|
|
| 3813 | + $more .= '<td'.(empty($input['tdclass']) ? ' class="tdtop"' : (' class="tdtop '.$input['tdclass'].'"')).'>'.$input['label'].'</td>';
|
|
| 3814 | 3814 | else |
| 3815 | - $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '> </td>';
|
|
| 3816 | - $more .= '<td><input type="radio" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '" value="' . $selkey . '"' . $moreattr; |
|
| 3815 | + $more .= '<td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'> </td>';
|
|
| 3816 | + $more .= '<td><input type="radio" class="flat'.$morecss.'" id="'.$input['name'].'" name="'.$input['name'].'" value="'.$selkey.'"'.$moreattr; |
|
| 3817 | 3817 | if ($input['disabled']) |
| 3818 | 3818 | $more .= ' disabled'; |
| 3819 | 3819 | $more .= ' /> '; |
| 3820 | 3820 | $more .= $selval; |
| 3821 | - $more .= '</td></tr>' . "\n"; |
|
| 3821 | + $more .= '</td></tr>'."\n"; |
|
| 3822 | 3822 | $i++; |
| 3823 | 3823 | } |
| 3824 | 3824 | } |
| 3825 | 3825 | elseif ($input['type'] == 'date') {
|
| 3826 | - $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>';
|
|
| 3826 | + $more .= '<tr><td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'>'.$input['label'].'</td>';
|
|
| 3827 | 3827 | $more .= '<td align="left">'; |
| 3828 | 3828 | $more .= $this->selectDate($input['value'], $input['name'], 0, 0, 0, '', 1, 0); |
| 3829 | - $more .= '</td></tr>' . "\n"; |
|
| 3830 | - $formquestion[] = array('name' => $input['name'] . 'day');
|
|
| 3831 | - $formquestion[] = array('name' => $input['name'] . 'month');
|
|
| 3832 | - $formquestion[] = array('name' => $input['name'] . 'year');
|
|
| 3833 | - $formquestion[] = array('name' => $input['name'] . 'hour');
|
|
| 3834 | - $formquestion[] = array('name' => $input['name'] . 'min');
|
|
| 3829 | + $more .= '</td></tr>'."\n"; |
|
| 3830 | + $formquestion[] = array('name' => $input['name'].'day');
|
|
| 3831 | + $formquestion[] = array('name' => $input['name'].'month');
|
|
| 3832 | + $formquestion[] = array('name' => $input['name'].'year');
|
|
| 3833 | + $formquestion[] = array('name' => $input['name'].'hour');
|
|
| 3834 | + $formquestion[] = array('name' => $input['name'].'min');
|
|
| 3835 | 3835 | } elseif ($input['type'] == 'other') {
|
| 3836 | - $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>';
|
|
| 3836 | + $more .= '<tr><td'.(empty($input['tdclass']) ? '' : (' class="'.$input['tdclass'].'"')).'>';
|
|
| 3837 | 3837 | if (!empty($input['label'])) |
| 3838 | - $more .= $input['label'] . '</td><td align="left">'; |
|
| 3838 | + $more .= $input['label'].'</td><td align="left">'; |
|
| 3839 | 3839 | $more .= $input['value']; |
| 3840 | - $more .= '</td></tr>' . "\n"; |
|
| 3840 | + $more .= '</td></tr>'."\n"; |
|
| 3841 | 3841 | } |
| 3842 | 3842 | |
| 3843 | 3843 | elseif ($input['type'] == 'onecolumn') {
|
| 3844 | 3844 | $more .= '<tr><td colspan="2" align="left">'; |
| 3845 | 3845 | $more .= $input['value']; |
| 3846 | - $more .= '</td></tr>' . "\n"; |
|
| 3846 | + $more .= '</td></tr>'."\n"; |
|
| 3847 | 3847 | } |
| 3848 | 3848 | } |
| 3849 | 3849 | } |
| 3850 | - $more .= '</table>' . "\n"; |
|
| 3850 | + $more .= '</table>'."\n"; |
|
| 3851 | 3851 | } |
| 3852 | 3852 | |
| 3853 | 3853 | // JQUI method dialog is broken with jmobile, we use standard HTML. |
@@ -3866,10 +3866,10 @@ discard block |
||
| 3866 | 3866 | $button = $useajax; |
| 3867 | 3867 | $useajax = 1; |
| 3868 | 3868 | $autoOpen = false; |
| 3869 | - $dialogconfirm .= '-' . $button; |
|
| 3869 | + $dialogconfirm .= '-'.$button; |
|
| 3870 | 3870 | } |
| 3871 | - $pageyes = $page . (preg_match('/\?/', $page) ? '&' : '?') . 'action=' . $action . '&confirm=yes';
|
|
| 3872 | - $pageno = ($useajax == 2 ? $page . (preg_match('/\?/', $page) ? '&' : '?') . 'confirm=no' : '');
|
|
| 3871 | + $pageyes = $page.(preg_match('/\?/', $page) ? '&' : '?').'action='.$action.'&confirm=yes';
|
|
| 3872 | + $pageno = ($useajax == 2 ? $page.(preg_match('/\?/', $page) ? '&' : '?').'confirm=no' : '');
|
|
| 3873 | 3873 | // Add input fields into list of fields to read during submit (inputok and inputko) |
| 3874 | 3874 | if (is_array($formquestion)) {
|
| 3875 | 3875 | foreach ($formquestion as $key => $input) {
|
@@ -3881,20 +3881,20 @@ discard block |
||
| 3881 | 3881 | } |
| 3882 | 3882 | } |
| 3883 | 3883 | // Show JQuery confirm box. Note that global var $useglobalvars is used inside this template |
| 3884 | - $formconfirm .= '<div id="' . $dialogconfirm . '" title="' . dol_escape_htmltag($title) . '" style="display: none;">'; |
|
| 3884 | + $formconfirm .= '<div id="'.$dialogconfirm.'" title="'.dol_escape_htmltag($title).'" style="display: none;">'; |
|
| 3885 | 3885 | if (!empty($more)) {
|
| 3886 | - $formconfirm .= '<div class="confirmquestions">' . $more . '</div>'; |
|
| 3886 | + $formconfirm .= '<div class="confirmquestions">'.$more.'</div>'; |
|
| 3887 | 3887 | } |
| 3888 | - $formconfirm .= ($question ? '<div class="confirmmessage">' . img_help('', '') . ' ' . $question . '</div>' : '');
|
|
| 3889 | - $formconfirm .= '</div>' . "\n"; |
|
| 3888 | + $formconfirm .= ($question ? '<div class="confirmmessage">'.img_help('', '').' '.$question.'</div>' : '');
|
|
| 3889 | + $formconfirm .= '</div>'."\n"; |
|
| 3890 | 3890 | |
| 3891 | - $formconfirm .= "\n<!-- begin ajax formconfirm page=" . $page . " -->\n"; |
|
| 3892 | - $formconfirm .= '<script type="text/javascript">' . "\n"; |
|
| 3891 | + $formconfirm .= "\n<!-- begin ajax formconfirm page=".$page." -->\n"; |
|
| 3892 | + $formconfirm .= '<script type="text/javascript">'."\n"; |
|
| 3893 | 3893 | $formconfirm .= 'jQuery(document).ready(function() {
|
| 3894 | 3894 | $(function() {
|
| 3895 | - $( "#' . $dialogconfirm . '" ).dialog( |
|
| 3895 | + $( "#' . $dialogconfirm.'" ).dialog( |
|
| 3896 | 3896 | {
|
| 3897 | - autoOpen: ' . ($autoOpen ? "true" : "false") . ','; |
|
| 3897 | + autoOpen: ' . ($autoOpen ? "true" : "false").','; |
|
| 3898 | 3898 | if ($newselectedchoice == 'no') {
|
| 3899 | 3899 | $formconfirm .= ' |
| 3900 | 3900 | open: function() {
|
@@ -3903,15 +3903,15 @@ discard block |
||
| 3903 | 3903 | } |
| 3904 | 3904 | $formconfirm .= ' |
| 3905 | 3905 | resizable: false, |
| 3906 | - height: "' . $height . '", |
|
| 3907 | - width: "' . $width . '", |
|
| 3906 | + height: "' . $height.'", |
|
| 3907 | + width: "' . $width.'", |
|
| 3908 | 3908 | modal: true, |
| 3909 | 3909 | closeOnEscape: false, |
| 3910 | 3910 | buttons: {
|
| 3911 | - "' . dol_escape_js($langs->transnoentities("Yes")) . '": function() {
|
|
| 3911 | + "' . dol_escape_js($langs->transnoentities("Yes")).'": function() {
|
|
| 3912 | 3912 | var options=""; |
| 3913 | - var inputok = ' . json_encode($inputok) . '; |
|
| 3914 | - var pageyes = "' . dol_escape_js(!empty($pageyes) ? $pageyes : '') . '"; |
|
| 3913 | + var inputok = ' . json_encode($inputok).'; |
|
| 3914 | + var pageyes = "' . dol_escape_js(!empty($pageyes) ? $pageyes : '').'"; |
|
| 3915 | 3915 | if (inputok.length>0) {
|
| 3916 | 3916 | $.each(inputok, function(i, inputname) {
|
| 3917 | 3917 | var more = ""; |
@@ -3927,10 +3927,10 @@ discard block |
||
| 3927 | 3927 | if (pageyes.length > 0) { location.href = urljump; }
|
| 3928 | 3928 | $(this).dialog("close");
|
| 3929 | 3929 | }, |
| 3930 | - "' . dol_escape_js($langs->transnoentities("No")) . '": function() {
|
|
| 3930 | + "' . dol_escape_js($langs->transnoentities("No")).'": function() {
|
|
| 3931 | 3931 | var options = ""; |
| 3932 | - var inputko = ' . json_encode($inputko) . '; |
|
| 3933 | - var pageno="' . dol_escape_js(!empty($pageno) ? $pageno : '') . '"; |
|
| 3932 | + var inputko = ' . json_encode($inputko).'; |
|
| 3933 | + var pageno="' . dol_escape_js(!empty($pageno) ? $pageno : '').'"; |
|
| 3934 | 3934 | if (inputko.length>0) {
|
| 3935 | 3935 | $.each(inputko, function(i, inputname) {
|
| 3936 | 3936 | var more = ""; |
@@ -3949,10 +3949,10 @@ discard block |
||
| 3949 | 3949 | } |
| 3950 | 3950 | ); |
| 3951 | 3951 | |
| 3952 | - var button = "' . $button . '"; |
|
| 3952 | + var button = "' . $button.'"; |
|
| 3953 | 3953 | if (button.length > 0) {
|
| 3954 | 3954 | $( "#" + button ).click(function() {
|
| 3955 | - $("#' . $dialogconfirm . '").dialog("open");
|
|
| 3955 | + $("#' . $dialogconfirm.'").dialog("open");
|
|
| 3956 | 3956 | }); |
| 3957 | 3957 | } |
| 3958 | 3958 | }); |
@@ -3960,37 +3960,37 @@ discard block |
||
| 3960 | 3960 | </script>'; |
| 3961 | 3961 | $formconfirm .= "<!-- end ajax formconfirm -->\n"; |
| 3962 | 3962 | } else {
|
| 3963 | - $formconfirm .= "\n<!-- begin formconfirm page=" . $page . " -->\n"; |
|
| 3963 | + $formconfirm .= "\n<!-- begin formconfirm page=".$page." -->\n"; |
|
| 3964 | 3964 | |
| 3965 | 3965 | if (empty($disableformtag)) |
| 3966 | - $formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . "\n"; |
|
| 3966 | + $formconfirm .= '<form method="POST" action="'.$page.'" class="notoptoleftroright">'."\n"; |
|
| 3967 | 3967 | |
| 3968 | - $formconfirm .= '<input type="hidden" name="action" value="' . $action . '">' . "\n"; |
|
| 3968 | + $formconfirm .= '<input type="hidden" name="action" value="'.$action.'">'."\n"; |
|
| 3969 | 3969 | if (empty($disableformtag)) |
| 3970 | - $formconfirm .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">' . "\n"; |
|
| 3970 | + $formconfirm .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'."\n"; |
|
| 3971 | 3971 | |
| 3972 | - $formconfirm .= '<table width="100%" class="valid">' . "\n"; |
|
| 3972 | + $formconfirm .= '<table width="100%" class="valid">'."\n"; |
|
| 3973 | 3973 | |
| 3974 | 3974 | // Line title |
| 3975 | - $formconfirm .= '<tr class="validtitre"><td class="validtitre" colspan="3">' . img_picto('', 'recent') . ' ' . $title . '</td></tr>' . "\n";
|
|
| 3975 | + $formconfirm .= '<tr class="validtitre"><td class="validtitre" colspan="3">'.img_picto('', 'recent').' '.$title.'</td></tr>'."\n";
|
|
| 3976 | 3976 | |
| 3977 | 3977 | // Line form fields |
| 3978 | 3978 | if ($more) {
|
| 3979 | - $formconfirm .= '<tr class="valid"><td class="valid" colspan="3">' . "\n"; |
|
| 3979 | + $formconfirm .= '<tr class="valid"><td class="valid" colspan="3">'."\n"; |
|
| 3980 | 3980 | $formconfirm .= $more; |
| 3981 | - $formconfirm .= '</td></tr>' . "\n"; |
|
| 3981 | + $formconfirm .= '</td></tr>'."\n"; |
|
| 3982 | 3982 | } |
| 3983 | 3983 | |
| 3984 | 3984 | // Line with question |
| 3985 | 3985 | $formconfirm .= '<tr class="valid">'; |
| 3986 | - $formconfirm .= '<td class="valid">' . $question . '</td>'; |
|
| 3986 | + $formconfirm .= '<td class="valid">'.$question.'</td>'; |
|
| 3987 | 3987 | $formconfirm .= '<td class="valid">'; |
| 3988 | 3988 | $formconfirm .= $this->selectyesno("confirm", $newselectedchoice);
|
| 3989 | 3989 | $formconfirm .= '</td>'; |
| 3990 | - $formconfirm .= '<td class="valid" align="center"><input class="button valignmiddle" type="submit" value="' . $langs->trans("Validate") . '"></td>';
|
|
| 3991 | - $formconfirm .= '</tr>' . "\n"; |
|
| 3990 | + $formconfirm .= '<td class="valid" align="center"><input class="button valignmiddle" type="submit" value="'.$langs->trans("Validate").'"></td>';
|
|
| 3991 | + $formconfirm .= '</tr>'."\n"; |
|
| 3992 | 3992 | |
| 3993 | - $formconfirm .= '</table>' . "\n"; |
|
| 3993 | + $formconfirm .= '</table>'."\n"; |
|
| 3994 | 3994 | |
| 3995 | 3995 | if (empty($disableformtag)) |
| 3996 | 3996 | $formconfirm .= "</form>\n"; |
@@ -4021,8 +4021,8 @@ discard block |
||
| 4021 | 4021 | // phpcs:enable |
| 4022 | 4022 | global $langs; |
| 4023 | 4023 | |
| 4024 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/project.lib.php'; |
|
| 4025 | - require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; |
|
| 4024 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; |
|
| 4025 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; |
|
| 4026 | 4026 | |
| 4027 | 4027 | $out = ''; |
| 4028 | 4028 | |
@@ -4031,11 +4031,11 @@ discard block |
||
| 4031 | 4031 | $langs->load("project");
|
| 4032 | 4032 | if ($htmlname != "none") {
|
| 4033 | 4033 | $out .= "\n"; |
| 4034 | - $out .= '<form method="post" action="' . $page . '">'; |
|
| 4034 | + $out .= '<form method="post" action="'.$page.'">'; |
|
| 4035 | 4035 | $out .= '<input type="hidden" name="action" value="classin">'; |
| 4036 | - $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4036 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4037 | 4037 | $out .= $formproject->select_projects($socid, $selected, $htmlname, $maxlength, 0, 1, $discard_closed, $forcefocus, 0, 0, '', 1); |
| 4038 | - $out .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
|
|
| 4038 | + $out .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
|
| 4039 | 4039 | $out .= '</form>'; |
| 4040 | 4040 | } else {
|
| 4041 | 4041 | if ($selected) {
|
@@ -4070,11 +4070,11 @@ discard block |
||
| 4070 | 4070 | // phpcs:enable |
| 4071 | 4071 | global $langs; |
| 4072 | 4072 | if ($htmlname != "none") {
|
| 4073 | - print '<form method="post" action="' . $page . '">'; |
|
| 4073 | + print '<form method="post" action="'.$page.'">'; |
|
| 4074 | 4074 | print '<input type="hidden" name="action" value="setconditions">'; |
| 4075 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4075 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4076 | 4076 | $this->select_conditions_paiements($selected, $htmlname, -1, $addempty); |
| 4077 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 4077 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 4078 | 4078 | print '</form>'; |
| 4079 | 4079 | } else {
|
| 4080 | 4080 | if ($selected) {
|
@@ -4101,11 +4101,11 @@ discard block |
||
| 4101 | 4101 | // phpcs:enable |
| 4102 | 4102 | global $langs; |
| 4103 | 4103 | if ($htmlname != "none") {
|
| 4104 | - print '<form method="post" action="' . $page . '">'; |
|
| 4104 | + print '<form method="post" action="'.$page.'">'; |
|
| 4105 | 4105 | print '<input type="hidden" name="action" value="setavailability">'; |
| 4106 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4106 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4107 | 4107 | $this->selectAvailabilityDelay($selected, $htmlname, -1, $addempty); |
| 4108 | - print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
|
|
| 4108 | + print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
|
| 4109 | 4109 | print '</form>'; |
| 4110 | 4110 | } else {
|
| 4111 | 4111 | if ($selected) {
|
@@ -4131,11 +4131,11 @@ discard block |
||
| 4131 | 4131 | {
|
| 4132 | 4132 | global $langs; |
| 4133 | 4133 | if ($htmlname != "none") {
|
| 4134 | - print '<form method="post" action="' . $page . '">'; |
|
| 4134 | + print '<form method="post" action="'.$page.'">'; |
|
| 4135 | 4135 | print '<input type="hidden" name="action" value="setdemandreason">'; |
| 4136 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4136 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4137 | 4137 | $this->selectInputReason($selected, $htmlname, -1, $addempty); |
| 4138 | - print '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
|
|
| 4138 | + print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
|
|
| 4139 | 4139 | print '</form>'; |
| 4140 | 4140 | } else {
|
| 4141 | 4141 | if ($selected) {
|
@@ -4173,14 +4173,14 @@ discard block |
||
| 4173 | 4173 | $ret = ''; |
| 4174 | 4174 | |
| 4175 | 4175 | if ($htmlname != "none") {
|
| 4176 | - $ret .= '<form method="post" action="' . $page . '" name="form' . $htmlname . '">'; |
|
| 4177 | - $ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">'; |
|
| 4178 | - $ret .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4176 | + $ret .= '<form method="post" action="'.$page.'" name="form'.$htmlname.'">'; |
|
| 4177 | + $ret .= '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
|
| 4178 | + $ret .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4179 | 4179 | $ret .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
| 4180 | 4180 | $ret .= '<tr><td>'; |
| 4181 | - $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1, 'form' . $htmlname, 1, 0); |
|
| 4181 | + $ret .= $this->selectDate($selected, $htmlname, $displayhour, $displaymin, 1, 'form'.$htmlname, 1, 0); |
|
| 4182 | 4182 | $ret .= '</td>'; |
| 4183 | - $ret .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '"></td>';
|
|
| 4183 | + $ret .= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
|
| 4184 | 4184 | $ret .= '</tr></table></form>'; |
| 4185 | 4185 | } else {
|
| 4186 | 4186 | if ($displayhour) |
@@ -4211,15 +4211,15 @@ discard block |
||
| 4211 | 4211 | global $langs; |
| 4212 | 4212 | |
| 4213 | 4213 | if ($htmlname != "none") {
|
| 4214 | - print '<form method="POST" action="' . $page . '" name="form' . $htmlname . '">'; |
|
| 4215 | - print '<input type="hidden" name="action" value="set' . $htmlname . '">'; |
|
| 4216 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4214 | + print '<form method="POST" action="'.$page.'" name="form'.$htmlname.'">'; |
|
| 4215 | + print '<input type="hidden" name="action" value="set'.$htmlname.'">'; |
|
| 4216 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4217 | 4217 | print $this->select_dolusers($selected, $htmlname, 1, $exclude, 0, $include); |
| 4218 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 4218 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 4219 | 4219 | print '</form>'; |
| 4220 | 4220 | } else {
|
| 4221 | 4221 | if ($selected) {
|
| 4222 | - require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; |
|
| 4222 | + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; |
|
| 4223 | 4223 | $theuser = new User($this->db); |
| 4224 | 4224 | $theuser->fetch($selected); |
| 4225 | 4225 | print $theuser->getNomUrl(1); |
@@ -4245,11 +4245,11 @@ discard block |
||
| 4245 | 4245 | // phpcs:enable |
| 4246 | 4246 | global $langs; |
| 4247 | 4247 | if ($htmlname != "none") {
|
| 4248 | - print '<form method="POST" action="' . $page . '">'; |
|
| 4248 | + print '<form method="POST" action="'.$page.'">'; |
|
| 4249 | 4249 | print '<input type="hidden" name="action" value="setmode">'; |
| 4250 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4250 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4251 | 4251 | $this->select_types_paiements($selected, $htmlname, $filtertype, 0, 0, 0, 0, $active); |
| 4252 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 4252 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 4253 | 4253 | print '</form>'; |
| 4254 | 4254 | } else {
|
| 4255 | 4255 | if ($selected) {
|
@@ -4275,11 +4275,11 @@ discard block |
||
| 4275 | 4275 | // phpcs:enable |
| 4276 | 4276 | global $langs; |
| 4277 | 4277 | if ($htmlname != "none") {
|
| 4278 | - print '<form method="POST" action="' . $page . '">'; |
|
| 4278 | + print '<form method="POST" action="'.$page.'">'; |
|
| 4279 | 4279 | print '<input type="hidden" name="action" value="setmulticurrencycode">'; |
| 4280 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4280 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4281 | 4281 | print $this->selectMultiCurrency($selected, $htmlname, 0); |
| 4282 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 4282 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 4283 | 4283 | print '</form>'; |
| 4284 | 4284 | } else {
|
| 4285 | 4285 | dol_include_once('/core/lib/company.lib.php');
|
@@ -4303,21 +4303,21 @@ discard block |
||
| 4303 | 4303 | global $langs, $mysoc, $conf; |
| 4304 | 4304 | |
| 4305 | 4305 | if ($htmlname != "none") {
|
| 4306 | - print '<form method="POST" action="' . $page . '">'; |
|
| 4306 | + print '<form method="POST" action="'.$page.'">'; |
|
| 4307 | 4307 | print '<input type="hidden" name="action" value="setmulticurrencyrate">'; |
| 4308 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4309 | - print '<input type="text" name="' . $htmlname . '" value="' . (!empty($rate) ? price($rate) : 1) . '" size="10" /> '; |
|
| 4308 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4309 | + print '<input type="text" name="'.$htmlname.'" value="'.(!empty($rate) ? price($rate) : 1).'" size="10" /> '; |
|
| 4310 | 4310 | print '<select name="calculation_mode">'; |
| 4311 | - print '<option value="1">' . $currency . ' > ' . $conf->currency . '</option>'; |
|
| 4312 | - print '<option value="2">' . $conf->currency . ' > ' . $currency . '</option>'; |
|
| 4311 | + print '<option value="1">'.$currency.' > '.$conf->currency.'</option>'; |
|
| 4312 | + print '<option value="2">'.$conf->currency.' > '.$currency.'</option>'; |
|
| 4313 | 4313 | print '</select> '; |
| 4314 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 4314 | + print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 4315 | 4315 | print '</form>'; |
| 4316 | 4316 | } else {
|
| 4317 | 4317 | if (!empty($rate)) {
|
| 4318 | 4318 | print price($rate, 1, $langs, 1, 0); |
| 4319 | 4319 | if ($currency && $rate != 1) |
| 4320 | - print ' (' . price($rate, 1, $langs, 1, 0) . ' ' . $currency . ' = 1 ' . $conf->currency . ')';
|
|
| 4320 | + print ' ('.price($rate, 1, $langs, 1, 0).' '.$currency.' = 1 '.$conf->currency.')';
|
|
| 4321 | 4321 | } |
| 4322 | 4322 | else {
|
| 4323 | 4323 | print 1; |
@@ -4346,14 +4346,14 @@ discard block |
||
| 4346 | 4346 | // phpcs:enable |
| 4347 | 4347 | global $conf, $langs; |
| 4348 | 4348 | if ($htmlname != "none") {
|
| 4349 | - print '<form method="post" action="' . $page . '">'; |
|
| 4349 | + print '<form method="post" action="'.$page.'">'; |
|
| 4350 | 4350 | print '<input type="hidden" name="action" value="setabsolutediscount">'; |
| 4351 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4351 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4352 | 4352 | print '<div class="inline-block">'; |
| 4353 | 4353 | if (!empty($discount_type)) {
|
| 4354 | 4354 | if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
| 4355 | 4355 | if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") |
| 4356 | - $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4356 | + $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4357 | 4357 | else |
| 4358 | 4358 | $translationKey = 'HasCreditNoteFromSupplier'; |
| 4359 | 4359 | } |
@@ -4366,7 +4366,7 @@ discard block |
||
| 4366 | 4366 | } else {
|
| 4367 | 4367 | if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
| 4368 | 4368 | if (!$filter || $filter == "fk_facture_source IS NULL") |
| 4369 | - $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4369 | + $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4370 | 4370 | else |
| 4371 | 4371 | $translationKey = 'CompanyHasCreditNote'; |
| 4372 | 4372 | } |
@@ -4383,21 +4383,21 @@ discard block |
||
| 4383 | 4383 | print '</div>'; |
| 4384 | 4384 | if (empty($hidelist)) {
|
| 4385 | 4385 | print '<div class="inline-block" style="padding-right: 10px">'; |
| 4386 | - $newfilter = 'discount_type=' . intval($discount_type); |
|
| 4386 | + $newfilter = 'discount_type='.intval($discount_type); |
|
| 4387 | 4387 | if (!empty($discount_type)) {
|
| 4388 | 4388 | $newfilter .= ' AND fk_invoice_supplier IS NULL AND fk_invoice_supplier_line IS NULL'; // Supplier discounts available |
| 4389 | 4389 | } else {
|
| 4390 | 4390 | $newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available |
| 4391 | 4391 | } |
| 4392 | 4392 | if ($filter) |
| 4393 | - $newfilter .= ' AND (' . $filter . ')';
|
|
| 4393 | + $newfilter .= ' AND ('.$filter.')';
|
|
| 4394 | 4394 | $nbqualifiedlines = $this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue); |
| 4395 | 4395 | if ($nbqualifiedlines > 0) {
|
| 4396 | - print ' <input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans("UseLine")) . '"';
|
|
| 4396 | + print ' <input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("UseLine")).'"';
|
|
| 4397 | 4397 | if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") |
| 4398 | - print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"';
|
|
| 4398 | + print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
|
|
| 4399 | 4399 | if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") |
| 4400 | - print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"';
|
|
| 4400 | + print ' title="'.$langs->trans("UseCreditNoteInInvoicePayment").'"';
|
|
| 4401 | 4401 | |
| 4402 | 4402 | print '>'; |
| 4403 | 4403 | } |
@@ -4434,22 +4434,22 @@ discard block |
||
| 4434 | 4434 | global $langs, $conf; |
| 4435 | 4435 | |
| 4436 | 4436 | if ($htmlname != "none") {
|
| 4437 | - print '<form method="post" action="' . $page . '">'; |
|
| 4437 | + print '<form method="post" action="'.$page.'">'; |
|
| 4438 | 4438 | print '<input type="hidden" name="action" value="set_contact">'; |
| 4439 | - print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4439 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4440 | 4440 | print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; |
| 4441 | 4441 | print '<tr><td>'; |
| 4442 | 4442 | $num = $this->select_contacts($societe->id, $selected, $htmlname); |
| 4443 | 4443 | if ($num == 0) {
|
| 4444 | 4444 | $addcontact = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("AddContact") : $langs->trans("AddContactAddress"));
|
| 4445 | - print '<a href="' . DOL_URL_ROOT . '/contact/card.php?socid=' . $societe->id . '&action=create&backtoreferer=1">' . $addcontact . '</a>'; |
|
| 4445 | + print '<a href="'.DOL_URL_ROOT.'/contact/card.php?socid='.$societe->id.'&action=create&backtoreferer=1">'.$addcontact.'</a>'; |
|
| 4446 | 4446 | } |
| 4447 | 4447 | print '</td>'; |
| 4448 | - print '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '"></td>';
|
|
| 4448 | + print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
|
|
| 4449 | 4449 | print '</tr></table></form>'; |
| 4450 | 4450 | } else {
|
| 4451 | 4451 | if ($selected) {
|
| 4452 | - require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; |
|
| 4452 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 4453 | 4453 | $contact = new Contact($this->db); |
| 4454 | 4454 | $contact->fetch($selected); |
| 4455 | 4455 | print $contact->getFullName($langs); |
@@ -4481,15 +4481,15 @@ discard block |
||
| 4481 | 4481 | |
| 4482 | 4482 | $out = ''; |
| 4483 | 4483 | if ($htmlname != "none") {
|
| 4484 | - $out .= '<form method="post" action="' . $page . '">'; |
|
| 4484 | + $out .= '<form method="post" action="'.$page.'">'; |
|
| 4485 | 4485 | $out .= '<input type="hidden" name="action" value="set_thirdparty">'; |
| 4486 | - $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
|
| 4486 | + $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 4487 | 4487 | $out .= $this->select_company($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events); |
| 4488 | - $out .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 4488 | + $out .= '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
|
|
| 4489 | 4489 | $out .= '</form>'; |
| 4490 | 4490 | } else {
|
| 4491 | 4491 | if ($selected) {
|
| 4492 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 4492 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
| 4493 | 4493 | $soc = new Societe($this->db); |
| 4494 | 4494 | $soc->fetch($selected); |
| 4495 | 4495 | $out .= $soc->getNomUrl($langs); |
@@ -4535,17 +4535,17 @@ discard block |
||
| 4535 | 4535 | $out = ''; |
| 4536 | 4536 | |
| 4537 | 4537 | if ($selected == 'euro' || $selected == 'euros') |
| 4538 | - $selected = 'EUR'; // Pour compatibilite |
|
| 4538 | + $selected = 'EUR'; // Pour compatibilite |
|
| 4539 | 4539 | |
| 4540 | - $out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname . '" id="' . $htmlname . '">'; |
|
| 4540 | + $out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'" id="'.$htmlname.'">'; |
|
| 4541 | 4541 | foreach ($langs->cache_currencies as $code_iso => $currency) {
|
| 4542 | 4542 | if ($selected && $selected == $code_iso) {
|
| 4543 | - $out .= '<option value="' . $code_iso . '" selected>'; |
|
| 4543 | + $out .= '<option value="'.$code_iso.'" selected>'; |
|
| 4544 | 4544 | } else {
|
| 4545 | - $out .= '<option value="' . $code_iso . '">'; |
|
| 4545 | + $out .= '<option value="'.$code_iso.'">'; |
|
| 4546 | 4546 | } |
| 4547 | 4547 | $out .= $currency['label']; |
| 4548 | - $out .= ' (' . $langs->getCurrencySymbol($code_iso) . ')';
|
|
| 4548 | + $out .= ' ('.$langs->getCurrencySymbol($code_iso).')';
|
|
| 4549 | 4549 | $out .= '</option>'; |
| 4550 | 4550 | } |
| 4551 | 4551 | $out .= '</select>'; |
@@ -4553,7 +4553,7 @@ discard block |
||
| 4553 | 4553 | $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
| 4554 | 4554 | |
| 4555 | 4555 | // Make select dynamic |
| 4556 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 4556 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 4557 | 4557 | $out .= ajax_combobox($htmlname); |
| 4558 | 4558 | |
| 4559 | 4559 | return $out; |
@@ -4571,12 +4571,12 @@ discard block |
||
| 4571 | 4571 | {
|
| 4572 | 4572 | global $db, $conf, $langs, $user; |
| 4573 | 4573 | |
| 4574 | - $langs->loadCacheCurrencies(''); // Load ->cache_currencies
|
|
| 4574 | + $langs->loadCacheCurrencies(''); // Load ->cache_currencies
|
|
| 4575 | 4575 | |
| 4576 | 4576 | $TCurrency = array(); |
| 4577 | 4577 | |
| 4578 | - $sql = 'SELECT code FROM ' . MAIN_DB_PREFIX . 'multicurrency'; |
|
| 4579 | - $sql .= " WHERE entity IN ('" . getEntity('mutlicurrency') . "')";
|
|
| 4578 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'multicurrency'; |
|
| 4579 | + $sql .= " WHERE entity IN ('".getEntity('mutlicurrency')."')";
|
|
| 4580 | 4580 | $resql = $db->query($sql); |
| 4581 | 4581 | if ($resql) {
|
| 4582 | 4582 | while ($obj = $db->fetch_object($resql)) |
@@ -4584,7 +4584,7 @@ discard block |
||
| 4584 | 4584 | } |
| 4585 | 4585 | |
| 4586 | 4586 | $out = ''; |
| 4587 | - $out .= '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">'; |
|
| 4587 | + $out .= '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">'; |
|
| 4588 | 4588 | if ($useempty) |
| 4589 | 4589 | $out .= '<option value=""></option>'; |
| 4590 | 4590 | // If company current currency not in table, we add it into list. Should always be available. |
@@ -4595,12 +4595,12 @@ discard block |
||
| 4595 | 4595 | foreach ($langs->cache_currencies as $code_iso => $currency) {
|
| 4596 | 4596 | if (isset($TCurrency[$code_iso])) {
|
| 4597 | 4597 | if (!empty($selected) && $selected == $code_iso) |
| 4598 | - $out .= '<option value="' . $code_iso . '" selected="selected">'; |
|
| 4598 | + $out .= '<option value="'.$code_iso.'" selected="selected">'; |
|
| 4599 | 4599 | else |
| 4600 | - $out .= '<option value="' . $code_iso . '">'; |
|
| 4600 | + $out .= '<option value="'.$code_iso.'">'; |
|
| 4601 | 4601 | |
| 4602 | 4602 | $out .= $currency['label']; |
| 4603 | - $out .= ' (' . $langs->getCurrencySymbol($code_iso) . ')';
|
|
| 4603 | + $out .= ' ('.$langs->getCurrencySymbol($code_iso).')';
|
|
| 4604 | 4604 | $out .= '</option>'; |
| 4605 | 4605 | } |
| 4606 | 4606 | } |
@@ -4608,7 +4608,7 @@ discard block |
||
| 4608 | 4608 | |
| 4609 | 4609 | $out .= '</select>'; |
| 4610 | 4610 | // Make select dynamic |
| 4611 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 4611 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 4612 | 4612 | $out .= ajax_combobox($htmlname); |
| 4613 | 4613 | |
| 4614 | 4614 | return $out; |
@@ -4628,15 +4628,15 @@ discard block |
||
| 4628 | 4628 | |
| 4629 | 4629 | $num = count($this->cache_vatrates); |
| 4630 | 4630 | if ($num > 0) |
| 4631 | - return $num; // Cache already loaded |
|
| 4631 | + return $num; // Cache already loaded |
|
| 4632 | 4632 | |
| 4633 | 4633 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 4634 | 4634 | |
| 4635 | 4635 | $sql = "SELECT DISTINCT t.rowid, t.code, t.taux, t.localtax1, t.localtax1_type, t.localtax2, t.localtax2_type, t.recuperableonly"; |
| 4636 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t, " . MAIN_DB_PREFIX . "c_country as c"; |
|
| 4636 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; |
|
| 4637 | 4637 | $sql .= " WHERE t.fk_pays = c.rowid"; |
| 4638 | 4638 | $sql .= " AND t.active > 0"; |
| 4639 | - $sql .= " AND c.code IN (" . $country_code . ")";
|
|
| 4639 | + $sql .= " AND c.code IN (".$country_code.")";
|
|
| 4640 | 4640 | $sql .= " ORDER BY t.code ASC, t.taux ASC, t.recuperableonly ASC"; |
| 4641 | 4641 | |
| 4642 | 4642 | $resql = $this->db->query($sql); |
@@ -4654,28 +4654,28 @@ discard block |
||
| 4654 | 4654 | $this->cache_vatrates[$i]['localtax2'] = $obj->localtax2; |
| 4655 | 4655 | $this->cache_vatrates[$i]['localtax2_type'] = $obj->localtax1_type; |
| 4656 | 4656 | |
| 4657 | - $this->cache_vatrates[$i]['label'] = $obj->taux . '%' . ($obj->code ? ' (' . $obj->code . ')' : ''); // Label must contains only 0-9 , . % or *
|
|
| 4658 | - $this->cache_vatrates[$i]['labelallrates'] = $obj->taux . '/' . ($obj->localtax1 ? $obj->localtax1 : '0') . '/' . ($obj->localtax2 ? $obj->localtax2 : '0') . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
|
|
| 4657 | + $this->cache_vatrates[$i]['label'] = $obj->taux.'%'.($obj->code ? ' ('.$obj->code.')' : ''); // Label must contains only 0-9 , . % or *
|
|
| 4658 | + $this->cache_vatrates[$i]['labelallrates'] = $obj->taux.'/'.($obj->localtax1 ? $obj->localtax1 : '0').'/'.($obj->localtax2 ? $obj->localtax2 : '0').($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label
|
|
| 4659 | 4659 | $positiverates = ''; |
| 4660 | 4660 | if ($obj->taux) |
| 4661 | - $positiverates .= ($positiverates ? '/' : '') . $obj->taux; |
|
| 4661 | + $positiverates .= ($positiverates ? '/' : '').$obj->taux; |
|
| 4662 | 4662 | if ($obj->localtax1) |
| 4663 | - $positiverates .= ($positiverates ? '/' : '') . $obj->localtax1; |
|
| 4663 | + $positiverates .= ($positiverates ? '/' : '').$obj->localtax1; |
|
| 4664 | 4664 | if ($obj->localtax2) |
| 4665 | - $positiverates .= ($positiverates ? '/' : '') . $obj->localtax2; |
|
| 4665 | + $positiverates .= ($positiverates ? '/' : '').$obj->localtax2; |
|
| 4666 | 4666 | if (empty($positiverates)) |
| 4667 | 4667 | $positiverates = '0'; |
| 4668 | - $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
|
|
| 4668 | + $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates.($obj->code ? ' ('.$obj->code.')' : ''); // Must never be used as key, only label
|
|
| 4669 | 4669 | } |
| 4670 | 4670 | |
| 4671 | 4671 | return $num; |
| 4672 | 4672 | } |
| 4673 | 4673 | else {
|
| 4674 | - $this->error = '<font class="error">' . $langs->trans("ErrorNoVATRateDefinedForSellerCountry", $country_code) . '</font>';
|
|
| 4674 | + $this->error = '<font class="error">'.$langs->trans("ErrorNoVATRateDefinedForSellerCountry", $country_code).'</font>';
|
|
| 4675 | 4675 | return -1; |
| 4676 | 4676 | } |
| 4677 | 4677 | } else {
|
| 4678 | - $this->error = '<font class="error">' . $this->db->error() . '</font>'; |
|
| 4678 | + $this->error = '<font class="error">'.$this->db->error().'</font>'; |
|
| 4679 | 4679 | return -2; |
| 4680 | 4680 | } |
| 4681 | 4681 | } |
@@ -4724,9 +4724,9 @@ discard block |
||
| 4724 | 4724 | // Check parameters |
| 4725 | 4725 | if (is_object($societe_vendeuse) && !$societe_vendeuse->country_code) {
|
| 4726 | 4726 | if ($societe_vendeuse->id == $mysoc->id) {
|
| 4727 | - $return .= '<font class="error">' . $langs->trans("ErrorYourCountryIsNotDefined") . '</div>';
|
|
| 4727 | + $return .= '<font class="error">'.$langs->trans("ErrorYourCountryIsNotDefined").'</div>';
|
|
| 4728 | 4728 | } else {
|
| 4729 | - $return .= '<font class="error">' . $langs->trans("ErrorSupplierCountryIsNotDefined") . '</div>';
|
|
| 4729 | + $return .= '<font class="error">'.$langs->trans("ErrorSupplierCountryIsNotDefined").'</div>';
|
|
| 4730 | 4730 | } |
| 4731 | 4731 | return $return; |
| 4732 | 4732 | } |
@@ -4737,32 +4737,32 @@ discard block |
||
| 4737 | 4737 | // Define list of countries to use to search VAT rates to show |
| 4738 | 4738 | // First we defined code_country to use to find list |
| 4739 | 4739 | if (is_object($societe_vendeuse)) {
|
| 4740 | - $code_country = "'" . $societe_vendeuse->country_code . "'"; |
|
| 4740 | + $code_country = "'".$societe_vendeuse->country_code."'"; |
|
| 4741 | 4741 | } else {
|
| 4742 | - $code_country = "'" . $mysoc->country_code . "'"; // Pour compatibilite ascendente |
|
| 4742 | + $code_country = "'".$mysoc->country_code."'"; // Pour compatibilite ascendente |
|
| 4743 | 4743 | } |
| 4744 | 4744 | if (!empty($conf->global->SERVICE_ARE_ECOMMERCE_200238EC)) { // If option to have vat for end customer for services is on
|
| 4745 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; |
|
| 4745 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
| 4746 | 4746 | if (!isInEEC($societe_vendeuse) && (!is_object($societe_acheteuse) || (isInEEC($societe_acheteuse) && !$societe_acheteuse->isACompany()))) {
|
| 4747 | 4747 | // We also add the buyer |
| 4748 | 4748 | if (is_numeric($type)) {
|
| 4749 | 4749 | if ($type == 1) { // We know product is a service
|
| 4750 | - $code_country .= ",'" . $societe_acheteuse->country_code . "'"; |
|
| 4750 | + $code_country .= ",'".$societe_acheteuse->country_code."'"; |
|
| 4751 | 4751 | } |
| 4752 | 4752 | } else if (!$idprod) { // We don't know type of product
|
| 4753 | - $code_country .= ",'" . $societe_acheteuse->country_code . "'"; |
|
| 4753 | + $code_country .= ",'".$societe_acheteuse->country_code."'"; |
|
| 4754 | 4754 | } else {
|
| 4755 | 4755 | $prodstatic = new Product($this->db); |
| 4756 | 4756 | $prodstatic->fetch($idprod); |
| 4757 | 4757 | if ($prodstatic->type == Product::TYPE_SERVICE) { // We know product is a service
|
| 4758 | - $code_country .= ",'" . $societe_acheteuse->country_code . "'"; |
|
| 4758 | + $code_country .= ",'".$societe_acheteuse->country_code."'"; |
|
| 4759 | 4759 | } |
| 4760 | 4760 | } |
| 4761 | 4761 | } |
| 4762 | 4762 | } |
| 4763 | 4763 | |
| 4764 | 4764 | // Now we get list |
| 4765 | - $num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error |
|
| 4765 | + $num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error |
|
| 4766 | 4766 | |
| 4767 | 4767 | if ($num > 0) {
|
| 4768 | 4768 | // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '') |
@@ -4795,13 +4795,13 @@ discard block |
||
| 4795 | 4795 | if (is_object($societe_vendeuse) && $societe_vendeuse->id == $mysoc->id && $societe_vendeuse->tva_assuj == "0") {
|
| 4796 | 4796 | // Override/enable VAT for expense report regardless of global setting - needed if expense report used for business expenses |
| 4797 | 4797 | if (empty($conf->global->OVERRIDE_VAT_FOR_EXPENSE_REPORT)) {
|
| 4798 | - $title = ' title="' . $langs->trans('VATIsNotUsed') . '"';
|
|
| 4798 | + $title = ' title="'.$langs->trans('VATIsNotUsed').'"';
|
|
| 4799 | 4799 | $disabled = true; |
| 4800 | 4800 | } |
| 4801 | 4801 | } |
| 4802 | 4802 | |
| 4803 | 4803 | if (!$options_only) {
|
| 4804 | - $return .= '<select class="flat minwidth75imp" id="' . $htmlname . '" name="' . $htmlname . '"' . ($disabled ? ' disabled' : '') . $title . '>'; |
|
| 4804 | + $return .= '<select class="flat minwidth75imp" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled ? ' disabled' : '').$title.'>'; |
|
| 4805 | 4805 | } |
| 4806 | 4806 | |
| 4807 | 4807 | $selectedfound = false; |
@@ -4814,11 +4814,11 @@ discard block |
||
| 4814 | 4814 | $key = $rate['txtva']; |
| 4815 | 4815 | $key .= $rate['nprtva'] ? '*' : ''; |
| 4816 | 4816 | if ($mode > 0 && $rate['code']) |
| 4817 | - $key .= ' (' . $rate['code'] . ')';
|
|
| 4817 | + $key .= ' ('.$rate['code'].')';
|
|
| 4818 | 4818 | if ($mode < 0) |
| 4819 | 4819 | $key = $rate['rowid']; |
| 4820 | 4820 | |
| 4821 | - $return .= '<option value="' . $key . '"'; |
|
| 4821 | + $return .= '<option value="'.$key.'"'; |
|
| 4822 | 4822 | if (!$selectedfound) {
|
| 4823 | 4823 | if ($defaultcode) { // If defaultcode is defined, we used it in priority to select combo option instead of using rate+npr flag
|
| 4824 | 4824 | if ($defaultcode == $rate['code']) {
|
@@ -4838,7 +4838,7 @@ discard block |
||
| 4838 | 4838 | $return .= vatrate($rate['label']); |
| 4839 | 4839 | } |
| 4840 | 4840 | //$return.=($rate['code']?' '.$rate['code']:''); |
| 4841 | - $return .= (empty($rate['code']) && $rate['nprtva']) ? ' *' : ''; // We show the * (old behaviour only if new vat code is not used) |
|
| 4841 | + $return .= (empty($rate['code']) && $rate['nprtva']) ? ' *' : ''; // We show the * (old behaviour only if new vat code is not used) |
|
| 4842 | 4842 | |
| 4843 | 4843 | $return .= '</option>'; |
| 4844 | 4844 | } |
@@ -4937,7 +4937,7 @@ discard block |
||
| 4937 | 4937 | $orig_set_time = $set_time; |
| 4938 | 4938 | |
| 4939 | 4939 | if ($set_time === '' && $emptydate == 0) {
|
| 4940 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; |
|
| 4940 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
| 4941 | 4941 | $set_time = dol_now('tzuser') - (getServerTimeZoneInt('now') * 3600); // set_time must be relative to PHP server timezone
|
| 4942 | 4942 | } |
| 4943 | 4943 | |
@@ -4990,36 +4990,36 @@ discard block |
||
| 4990 | 4990 | //print "e".$set_time." t ".$conf->format_date_short; |
| 4991 | 4991 | if (strval($set_time) != '' && $set_time != -1) {
|
| 4992 | 4992 | //$formated_date=dol_print_date($set_time,$conf->format_date_short); |
| 4993 | - $formated_date = dol_print_date($set_time, $langs->trans("FormatDateShortInput")); // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
|
| 4993 | + $formated_date = dol_print_date($set_time, $langs->trans("FormatDateShortInput")); // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
|
| 4994 | 4994 | } |
| 4995 | 4995 | |
| 4996 | 4996 | // Calendrier popup version eldy |
| 4997 | 4997 | if ($usecalendar == "eldy") {
|
| 4998 | 4998 | // Zone de saisie manuelle de la date |
| 4999 | - $retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" class="maxwidth75" maxlength="11" value="' . $formated_date . '"'; |
|
| 4999 | + $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text" class="maxwidth75" maxlength="11" value="'.$formated_date.'"'; |
|
| 5000 | 5000 | $retstring .= ($disabled ? ' disabled' : ''); |
| 5001 | - $retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
|
| 5001 | + $retstring .= ' onChange="dpChangeDay(\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
|
| 5002 | 5002 | $retstring .= '>'; |
| 5003 | 5003 | |
| 5004 | 5004 | // Icone calendrier |
| 5005 | 5005 | if (!$disabled) {
|
| 5006 | - $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons"'; |
|
| 5007 | - $base = DOL_URL_ROOT . '/core/'; |
|
| 5008 | - $retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\',\'' . $langs->defaultlang . '\');"';
|
|
| 5009 | - $retstring .= '>' . img_object($langs->trans("SelectDate"), 'calendarday', 'class="datecallink"') . '</button>';
|
|
| 5006 | + $retstring .= '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons"'; |
|
| 5007 | + $base = DOL_URL_ROOT.'/core/'; |
|
| 5008 | + $retstring .= ' onClick="showDP(\''.$base.'\',\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput").'\',\''.$langs->defaultlang.'\');"';
|
|
| 5009 | + $retstring .= '>'.img_object($langs->trans("SelectDate"), 'calendarday', 'class="datecallink"').'</button>';
|
|
| 5010 | 5010 | } else |
| 5011 | - $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>';
|
|
| 5011 | + $retstring .= '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons">'.img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"').'</button>';
|
|
| 5012 | 5012 | |
| 5013 | - $retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . "\n"; |
|
| 5014 | - $retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . "\n"; |
|
| 5015 | - $retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . "\n"; |
|
| 5013 | + $retstring .= '<input type="hidden" id="'.$prefix.'day" name="'.$prefix.'day" value="'.$sday.'">'."\n"; |
|
| 5014 | + $retstring .= '<input type="hidden" id="'.$prefix.'month" name="'.$prefix.'month" value="'.$smonth.'">'."\n"; |
|
| 5015 | + $retstring .= '<input type="hidden" id="'.$prefix.'year" name="'.$prefix.'year" value="'.$syear.'">'."\n"; |
|
| 5016 | 5016 | } |
| 5017 | 5017 | elseif ($usecalendar == 'jquery') {
|
| 5018 | 5018 | if (!$disabled) {
|
| 5019 | 5019 | // Output javascript for datepicker |
| 5020 | 5020 | $retstring .= "<script type='text/javascript'>"; |
| 5021 | - $retstring .= "$(function(){ $('#" . $prefix . "').datepicker({
|
|
| 5022 | - dateFormat: '" . $langs->trans("FormatDateShortJQueryInput") . "',
|
|
| 5021 | + $retstring .= "$(function(){ $('#".$prefix."').datepicker({
|
|
| 5022 | + dateFormat: '" . $langs->trans("FormatDateShortJQueryInput")."',
|
|
| 5023 | 5023 | autoclose: true, |
| 5024 | 5024 | todayHighlight: true,"; |
| 5025 | 5025 | if (!empty($conf->dol_use_jmobile)) {
|
@@ -5042,7 +5042,7 @@ discard block |
||
| 5042 | 5042 | */ |
| 5043 | 5043 | $retstring .= " |
| 5044 | 5044 | showOn: 'button', |
| 5045 | - buttonImage: '" . DOL_BASE_URI . "/theme/" . $conf->theme . "/img/object_calendarday.png', |
|
| 5045 | + buttonImage: '" . DOL_BASE_URI."/theme/".$conf->theme."/img/object_calendarday.png', |
|
| 5046 | 5046 | buttonImageOnly: true"; |
| 5047 | 5047 | } |
| 5048 | 5048 | $retstring .= " |
@@ -5052,9 +5052,9 @@ discard block |
||
| 5052 | 5052 | |
| 5053 | 5053 | // Zone de saisie manuelle de la date |
| 5054 | 5054 | $retstring .= '<div class="nowrap inline-block">'; |
| 5055 | - $retstring .= '<input id="' . $prefix . '" name="' . $prefix . '" type="text" class="maxwidth75" maxlength="11" value="' . $formated_date . '"'; |
|
| 5055 | + $retstring .= '<input id="'.$prefix.'" name="'.$prefix.'" type="text" class="maxwidth75" maxlength="11" value="'.$formated_date.'"'; |
|
| 5056 | 5056 | $retstring .= ($disabled ? ' disabled' : ''); |
| 5057 | - $retstring .= ' onChange="dpChangeDay(\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
|
| 5057 | + $retstring .= ' onChange="dpChangeDay(\''.$prefix.'\',\''.$langs->trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript
|
|
| 5058 | 5058 | $retstring .= '>'; |
| 5059 | 5059 | |
| 5060 | 5060 | // Icone calendrier |
@@ -5069,13 +5069,13 @@ discard block |
||
| 5069 | 5069 | $retstring.='});'; |
| 5070 | 5070 | $retstring.="</script>"; */ |
| 5071 | 5071 | } else {
|
| 5072 | - $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>';
|
|
| 5072 | + $retstring .= '<button id="'.$prefix.'Button" type="button" class="dpInvisibleButtons">'.img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"').'</button>';
|
|
| 5073 | 5073 | } |
| 5074 | 5074 | |
| 5075 | 5075 | $retstring .= '</div>'; |
| 5076 | - $retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . "\n"; |
|
| 5077 | - $retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . "\n"; |
|
| 5078 | - $retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . "\n"; |
|
| 5076 | + $retstring .= '<input type="hidden" id="'.$prefix.'day" name="'.$prefix.'day" value="'.$sday.'">'."\n"; |
|
| 5077 | + $retstring .= '<input type="hidden" id="'.$prefix.'month" name="'.$prefix.'month" value="'.$smonth.'">'."\n"; |
|
| 5078 | + $retstring .= '<input type="hidden" id="'.$prefix.'year" name="'.$prefix.'year" value="'.$syear.'">'."\n"; |
|
| 5079 | 5079 | } else {
|
| 5080 | 5080 | $retstring .= "Bad value of MAIN_POPUP_CALENDAR"; |
| 5081 | 5081 | } |
@@ -5084,26 +5084,26 @@ discard block |
||
| 5084 | 5084 | else {
|
| 5085 | 5085 | //$retstring.='<div class="inline-block">'; |
| 5086 | 5086 | // Day |
| 5087 | - $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50imp" id="' . $prefix . 'day" name="' . $prefix . 'day">'; |
|
| 5087 | + $retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50imp" id="'.$prefix.'day" name="'.$prefix.'day">'; |
|
| 5088 | 5088 | |
| 5089 | 5089 | if ($emptydate || $set_time == -1) {
|
| 5090 | 5090 | $retstring .= '<option value="0" selected> </option>'; |
| 5091 | 5091 | } |
| 5092 | 5092 | |
| 5093 | 5093 | for ($day = 1; $day <= 31; $day++) {
|
| 5094 | - $retstring .= '<option value="' . $day . '"' . ($day == $sday ? ' selected' : '') . '>' . $day . '</option>'; |
|
| 5094 | + $retstring .= '<option value="'.$day.'"'.($day == $sday ? ' selected' : '').'>'.$day.'</option>'; |
|
| 5095 | 5095 | } |
| 5096 | 5096 | |
| 5097 | 5097 | $retstring .= "</select>"; |
| 5098 | 5098 | |
| 5099 | - $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp" id="' . $prefix . 'month" name="' . $prefix . 'month">'; |
|
| 5099 | + $retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'month" name="'.$prefix.'month">'; |
|
| 5100 | 5100 | if ($emptydate || $set_time == -1) {
|
| 5101 | 5101 | $retstring .= '<option value="0" selected> </option>'; |
| 5102 | 5102 | } |
| 5103 | 5103 | |
| 5104 | 5104 | // Month |
| 5105 | 5105 | for ($month = 1; $month <= 12; $month++) {
|
| 5106 | - $retstring .= '<option value="' . $month . '"' . ($month == $smonth ? ' selected' : '') . '>'; |
|
| 5106 | + $retstring .= '<option value="'.$month.'"'.($month == $smonth ? ' selected' : '').'>'; |
|
| 5107 | 5107 | $retstring .= dol_print_date(mktime(12, 0, 0, $month, 1, 2000), "%b"); |
| 5108 | 5108 | $retstring .= "</option>"; |
| 5109 | 5109 | } |
@@ -5111,12 +5111,12 @@ discard block |
||
| 5111 | 5111 | |
| 5112 | 5112 | // Year |
| 5113 | 5113 | if ($emptydate || $set_time == -1) {
|
| 5114 | - $retstring .= '<input' . ($disabled ? ' disabled' : '') . ' placeholder="' . dol_escape_htmltag($langs->trans("Year")) . '" class="flat maxwidth50imp valignmiddle" type="number" min="0" max="3000" maxlength="4" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">';
|
|
| 5114 | + $retstring .= '<input'.($disabled ? ' disabled' : '').' placeholder="'.dol_escape_htmltag($langs->trans("Year")).'" class="flat maxwidth50imp valignmiddle" type="number" min="0" max="3000" maxlength="4" id="'.$prefix.'year" name="'.$prefix.'year" value="'.$syear.'">';
|
|
| 5115 | 5115 | } else {
|
| 5116 | - $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth75imp" id="' . $prefix . 'year" name="' . $prefix . 'year">'; |
|
| 5116 | + $retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth75imp" id="'.$prefix.'year" name="'.$prefix.'year">'; |
|
| 5117 | 5117 | |
| 5118 | 5118 | for ($year = $syear - 10; $year < $syear + 10; $year++) {
|
| 5119 | - $retstring .= '<option value="' . $year . '"' . ($year == $syear ? ' selected' : '') . '>' . $year . '</option>'; |
|
| 5119 | + $retstring .= '<option value="'.$year.'"'.($year == $syear ? ' selected' : '').'>'.$year.'</option>'; |
|
| 5120 | 5120 | } |
| 5121 | 5121 | $retstring .= "</select>\n"; |
| 5122 | 5122 | } |
@@ -5129,13 +5129,13 @@ discard block |
||
| 5129 | 5129 | |
| 5130 | 5130 | if ($h) {
|
| 5131 | 5131 | // Show hour |
| 5132 | - $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 ' . ($fullday ? $fullday . 'hour' : '') . '" id="' . $prefix . 'hour" name="' . $prefix . 'hour">'; |
|
| 5132 | + $retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50 '.($fullday ? $fullday.'hour' : '').'" id="'.$prefix.'hour" name="'.$prefix.'hour">'; |
|
| 5133 | 5133 | if ($emptyhours) |
| 5134 | 5134 | $retstring .= '<option value="-1"> </option>'; |
| 5135 | 5135 | for ($hour = 0; $hour < 24; $hour++) {
|
| 5136 | 5136 | if (strlen($hour) < 2) |
| 5137 | - $hour = "0" . $hour; |
|
| 5138 | - $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour . (empty($conf->dol_optimize_smallscreen) ? '' : 'H') . '</option>'; |
|
| 5137 | + $hour = "0".$hour; |
|
| 5138 | + $retstring .= '<option value="'.$hour.'"'.(($hour == $shour) ? ' selected' : '').'>'.$hour.(empty($conf->dol_optimize_smallscreen) ? '' : 'H').'</option>'; |
|
| 5139 | 5139 | } |
| 5140 | 5140 | $retstring .= '</select>'; |
| 5141 | 5141 | if ($m && empty($conf->dol_optimize_smallscreen)) |
@@ -5144,17 +5144,17 @@ discard block |
||
| 5144 | 5144 | |
| 5145 | 5145 | if ($m) {
|
| 5146 | 5146 | // Show minutes |
| 5147 | - $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 ' . ($fullday ? $fullday . 'min' : '') . '" id="' . $prefix . 'min" name="' . $prefix . 'min">'; |
|
| 5147 | + $retstring .= '<select'.($disabled ? ' disabled' : '').' class="flat valignmiddle maxwidth50 '.($fullday ? $fullday.'min' : '').'" id="'.$prefix.'min" name="'.$prefix.'min">'; |
|
| 5148 | 5148 | if ($emptyhours) |
| 5149 | 5149 | $retstring .= '<option value="-1"> </option>'; |
| 5150 | 5150 | for ($min = 0; $min < 60; $min++) {
|
| 5151 | 5151 | if (strlen($min) < 2) |
| 5152 | - $min = "0" . $min; |
|
| 5153 | - $retstring .= '<option value="' . $min . '"' . (($min == $smin) ? ' selected' : '') . '>' . $min . (empty($conf->dol_optimize_smallscreen) ? '' : '') . '</option>'; |
|
| 5152 | + $min = "0".$min; |
|
| 5153 | + $retstring .= '<option value="'.$min.'"'.(($min == $smin) ? ' selected' : '').'>'.$min.(empty($conf->dol_optimize_smallscreen) ? '' : '').'</option>'; |
|
| 5154 | 5154 | } |
| 5155 | 5155 | $retstring .= '</select>'; |
| 5156 | 5156 | |
| 5157 | - $retstring .= '<input type="hidden" name="' . $prefix . 'sec" value="' . $ssec . '">'; |
|
| 5157 | + $retstring .= '<input type="hidden" name="'.$prefix.'sec" value="'.$ssec.'">'; |
|
| 5158 | 5158 | } |
| 5159 | 5159 | |
| 5160 | 5160 | // Add a "Now" link |
@@ -5163,10 +5163,10 @@ discard block |
||
| 5163 | 5163 | $reset_scripts = ""; |
| 5164 | 5164 | |
| 5165 | 5165 | // Generate the date part, depending on the use or not of the javascript calendar |
| 5166 | - $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date(dol_now(), 'day') . '\');'; |
|
| 5167 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date(dol_now(), '%d') . '\');'; |
|
| 5168 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date(dol_now(), '%m') . '\');'; |
|
| 5169 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date(dol_now(), '%Y') . '\');'; |
|
| 5166 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date(dol_now(), 'day').'\');'; |
|
| 5167 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.dol_print_date(dol_now(), '%d').'\');'; |
|
| 5168 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.dol_print_date(dol_now(), '%m').'\');'; |
|
| 5169 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.dol_print_date(dol_now(), '%Y').'\');'; |
|
| 5170 | 5170 | /* if ($usecalendar == "eldy") |
| 5171 | 5171 | {
|
| 5172 | 5172 | $base=DOL_URL_ROOT.'/core/'; |
@@ -5183,7 +5183,7 @@ discard block |
||
| 5183 | 5183 | if ($fullday) |
| 5184 | 5184 | $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
| 5185 | 5185 | //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); '; |
| 5186 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date(dol_now(), '%H') . '\');'; |
|
| 5186 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(\''.dol_print_date(dol_now(), '%H').'\');'; |
|
| 5187 | 5187 | if ($fullday) |
| 5188 | 5188 | $reset_scripts .= ' } '; |
| 5189 | 5189 | } |
@@ -5192,13 +5192,13 @@ discard block |
||
| 5192 | 5192 | if ($fullday) |
| 5193 | 5193 | $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
| 5194 | 5194 | //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); '; |
| 5195 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date(dol_now(), '%M') . '\');'; |
|
| 5195 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(\''.dol_print_date(dol_now(), '%M').'\');'; |
|
| 5196 | 5196 | if ($fullday) |
| 5197 | 5197 | $reset_scripts .= ' } '; |
| 5198 | 5198 | } |
| 5199 | 5199 | // If reset_scripts is not empty, print the link with the reset_scripts in the onClick |
| 5200 | 5200 | if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
|
| 5201 | - $retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonNow" type="button" name="_useless" value="now" onClick="' . $reset_scripts . '">'; |
|
| 5201 | + $retstring .= ' <button class="dpInvisibleButtons datenowlink" id="'.$prefix.'ButtonNow" type="button" name="_useless" value="now" onClick="'.$reset_scripts.'">'; |
|
| 5202 | 5202 | $retstring .= $langs->trans("Now");
|
| 5203 | 5203 | $retstring .= '</button> '; |
| 5204 | 5204 | } |
@@ -5210,15 +5210,15 @@ discard block |
||
| 5210 | 5210 | $reset_scripts = ""; |
| 5211 | 5211 | |
| 5212 | 5212 | // Generate the date part, depending on the use or not of the javascript calendar |
| 5213 | - $reset_scripts .= 'jQuery(\'#' . $prefix . '\').val(\'' . dol_print_date(dol_now(), 'day') . '\');'; |
|
| 5214 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'day\').val(\'' . dol_print_date(dol_now(), '%d') . '\');'; |
|
| 5215 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'month\').val(\'' . dol_print_date(dol_now(), '%m') . '\');'; |
|
| 5216 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date(dol_now(), '%Y') . '\');'; |
|
| 5213 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'\').val(\''.dol_print_date(dol_now(), 'day').'\');'; |
|
| 5214 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'day\').val(\''.dol_print_date(dol_now(), '%d').'\');'; |
|
| 5215 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'month\').val(\''.dol_print_date(dol_now(), '%m').'\');'; |
|
| 5216 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'year\').val(\''.dol_print_date(dol_now(), '%Y').'\');'; |
|
| 5217 | 5217 | // Update the hour part |
| 5218 | 5218 | if ($h) {
|
| 5219 | 5219 | if ($fullday) |
| 5220 | 5220 | $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
| 5221 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date(dol_now(), '%H') . '\');'; |
|
| 5221 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'hour\').val(\''.dol_print_date(dol_now(), '%H').'\');'; |
|
| 5222 | 5222 | if ($fullday) |
| 5223 | 5223 | $reset_scripts .= ' } '; |
| 5224 | 5224 | } |
@@ -5226,13 +5226,13 @@ discard block |
||
| 5226 | 5226 | if ($m) {
|
| 5227 | 5227 | if ($fullday) |
| 5228 | 5228 | $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
| 5229 | - $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date(dol_now(), '%M') . '\');'; |
|
| 5229 | + $reset_scripts .= 'jQuery(\'#'.$prefix.'min\').val(\''.dol_print_date(dol_now(), '%M').'\');'; |
|
| 5230 | 5230 | if ($fullday) |
| 5231 | 5231 | $reset_scripts .= ' } '; |
| 5232 | 5232 | } |
| 5233 | 5233 | // If reset_scripts is not empty, print the link with the reset_scripts in the onClick |
| 5234 | 5234 | if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
|
| 5235 | - $retstring .= ' <button class="dpInvisibleButtons datenowlink" id="' . $prefix . 'ButtonPlusOne" type="button" name="_useless2" value="plusone" onClick="' . $reset_scripts . '">'; |
|
| 5235 | + $retstring .= ' <button class="dpInvisibleButtons datenowlink" id="'.$prefix.'ButtonPlusOne" type="button" name="_useless2" value="plusone" onClick="'.$reset_scripts.'">'; |
|
| 5236 | 5236 | $retstring .= $langs->trans("DateStartPlusOne");
|
| 5237 | 5237 | $retstring .= '</button> '; |
| 5238 | 5238 | } |
@@ -5241,7 +5241,7 @@ discard block |
||
| 5241 | 5241 | // Add a "Plus one hour" link |
| 5242 | 5242 | if ($conf->use_javascript_ajax && $adddateof) {
|
| 5243 | 5243 | $tmparray = dol_getdate($adddateof); |
| 5244 | - $retstring .= ' - <button class="dpInvisibleButtons datenowlink" id="dateofinvoice" type="button" name="_dateofinvoice" value="now" onclick="jQuery(\'#re\').val(\'' . dol_print_date($adddateof, 'day') . '\');jQuery(\'#reday\').val(\'' . $tmparray['mday'] . '\');jQuery(\'#remonth\').val(\'' . $tmparray['mon'] . '\');jQuery(\'#reyear\').val(\'' . $tmparray['year'] . '\');">' . $langs->trans("DateInvoice") . '</a>';
|
|
| 5244 | + $retstring .= ' - <button class="dpInvisibleButtons datenowlink" id="dateofinvoice" type="button" name="_dateofinvoice" value="now" onclick="jQuery(\'#re\').val(\''.dol_print_date($adddateof, 'day').'\');jQuery(\'#reday\').val(\''.$tmparray['mday'].'\');jQuery(\'#remonth\').val(\''.$tmparray['mon'].'\');jQuery(\'#reyear\').val(\''.$tmparray['year'].'\');">'.$langs->trans("DateInvoice").'</a>';
|
|
| 5245 | 5245 | } |
| 5246 | 5246 | |
| 5247 | 5247 | return $retstring; |
@@ -5273,29 +5273,29 @@ discard block |
||
| 5273 | 5273 | |
| 5274 | 5274 | // Hours |
| 5275 | 5275 | if ($iSecond != '') {
|
| 5276 | - require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; |
|
| 5276 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; |
|
| 5277 | 5277 | |
| 5278 | 5278 | $hourSelected = convertSecondToTime($iSecond, 'allhour'); |
| 5279 | 5279 | $minSelected = convertSecondToTime($iSecond, 'min'); |
| 5280 | 5280 | } |
| 5281 | 5281 | |
| 5282 | 5282 | if ($typehour == 'select') {
|
| 5283 | - $retstring .= '<select class="flat" id="select_' . $prefix . 'hour" name="' . $prefix . 'hour"' . ($disabled ? ' disabled' : '') . '>'; |
|
| 5283 | + $retstring .= '<select class="flat" id="select_'.$prefix.'hour" name="'.$prefix.'hour"'.($disabled ? ' disabled' : '').'>'; |
|
| 5284 | 5284 | for ($hour = 0; $hour < 25; $hour++) { // For a duration, we allow 24 hours
|
| 5285 | - $retstring .= '<option value="' . $hour . '"'; |
|
| 5285 | + $retstring .= '<option value="'.$hour.'"'; |
|
| 5286 | 5286 | if ($hourSelected == $hour) {
|
| 5287 | 5287 | $retstring .= " selected"; |
| 5288 | 5288 | } |
| 5289 | - $retstring .= ">" . $hour . "</option>"; |
|
| 5289 | + $retstring .= ">".$hour."</option>"; |
|
| 5290 | 5290 | } |
| 5291 | 5291 | $retstring .= "</select>"; |
| 5292 | 5292 | } elseif ($typehour == 'text' || $typehour == 'textselect') {
|
| 5293 | - $retstring .= '<input placeholder="' . $langs->trans('HourShort') . '" type="number" min="0" size="1" name="' . $prefix . 'hour"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
|
|
| 5293 | + $retstring .= '<input placeholder="'.$langs->trans('HourShort').'" type="number" min="0" size="1" name="'.$prefix.'hour"'.($disabled ? ' disabled' : '').' class="flat maxwidth50 inputhour" value="'.(($hourSelected != '') ? ((int) $hourSelected) : '').'">';
|
|
| 5294 | 5294 | } else |
| 5295 | 5295 | return 'BadValueForParameterTypeHour'; |
| 5296 | 5296 | |
| 5297 | 5297 | if ($typehour != 'text') |
| 5298 | - $retstring .= ' ' . $langs->trans('HourShort');
|
|
| 5298 | + $retstring .= ' '.$langs->trans('HourShort');
|
|
| 5299 | 5299 | else |
| 5300 | 5300 | $retstring .= '<span class="hideonsmartphone">:</span>'; |
| 5301 | 5301 | |
@@ -5306,21 +5306,21 @@ discard block |
||
| 5306 | 5306 | $retstring .= '<span class="hideonsmartphone"> </span>'; |
| 5307 | 5307 | |
| 5308 | 5308 | if ($typehour == 'select' || $typehour == 'textselect') {
|
| 5309 | - $retstring .= '<select class="flat" id="select_' . $prefix . 'min" name="' . $prefix . 'min"' . ($disabled ? ' disabled' : '') . '>'; |
|
| 5309 | + $retstring .= '<select class="flat" id="select_'.$prefix.'min" name="'.$prefix.'min"'.($disabled ? ' disabled' : '').'>'; |
|
| 5310 | 5310 | for ($min = 0; $min <= 55; $min = $min + 5) {
|
| 5311 | - $retstring .= '<option value="' . $min . '"'; |
|
| 5311 | + $retstring .= '<option value="'.$min.'"'; |
|
| 5312 | 5312 | if ($minSelected == $min) |
| 5313 | 5313 | $retstring .= ' selected'; |
| 5314 | - $retstring .= '>' . $min . '</option>'; |
|
| 5314 | + $retstring .= '>'.$min.'</option>'; |
|
| 5315 | 5315 | } |
| 5316 | 5316 | $retstring .= "</select>"; |
| 5317 | 5317 | } |
| 5318 | 5318 | elseif ($typehour == 'text') {
|
| 5319 | - $retstring .= '<input placeholder="' . $langs->trans('MinuteShort') . '" type="number" min="0" size="1" name="' . $prefix . 'min"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
|
|
| 5319 | + $retstring .= '<input placeholder="'.$langs->trans('MinuteShort').'" type="number" min="0" size="1" name="'.$prefix.'min"'.($disabled ? ' disabled' : '').' class="flat maxwidth50 inputminute" value="'.(($minSelected != '') ? ((int) $minSelected) : '').'">';
|
|
| 5320 | 5320 | } |
| 5321 | 5321 | |
| 5322 | 5322 | if ($typehour != 'text') |
| 5323 | - $retstring .= ' ' . $langs->trans('MinuteShort');
|
|
| 5323 | + $retstring .= ' '.$langs->trans('MinuteShort');
|
|
| 5324 | 5324 | |
| 5325 | 5325 | //$retstring.=" "; |
| 5326 | 5326 | |
@@ -5363,30 +5363,30 @@ discard block |
||
| 5363 | 5363 | } |
| 5364 | 5364 | } |
| 5365 | 5365 | if (!is_object($objecttmp)) {
|
| 5366 | - dol_syslog('Error bad setup of type for field ' . $InfoFieldList, LOG_WARNING);
|
|
| 5367 | - return 'Error bad setup of type for field ' . join(',', $InfoFieldList);
|
|
| 5366 | + dol_syslog('Error bad setup of type for field '.$InfoFieldList, LOG_WARNING);
|
|
| 5367 | + return 'Error bad setup of type for field '.join(',', $InfoFieldList);
|
|
| 5368 | 5368 | } |
| 5369 | 5369 | |
| 5370 | 5370 | $prefixforautocompletemode = $objecttmp->element; |
| 5371 | 5371 | if ($prefixforautocompletemode == 'societe') |
| 5372 | 5372 | $prefixforautocompletemode = 'company'; |
| 5373 | - $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
|
| 5373 | + $confkeyforautocompletemode = strtoupper($prefixforautocompletemode).'_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
|
| 5374 | 5374 | |
| 5375 | - dol_syslog(get_class($this) . "::selectForForms", LOG_DEBUG); |
|
| 5375 | + dol_syslog(get_class($this)."::selectForForms", LOG_DEBUG); |
|
| 5376 | 5376 | |
| 5377 | 5377 | $out = ''; |
| 5378 | 5378 | if (!empty($conf->use_javascript_ajax) && !empty($conf->global->$confkeyforautocompletemode) && !$forcecombo) {
|
| 5379 | - $objectdesc = $classname . ':' . $classpath; |
|
| 5380 | - $urlforajaxcall = DOL_URL_ROOT . '/core/ajax/selectobject.php'; |
|
| 5379 | + $objectdesc = $classname.':'.$classpath; |
|
| 5380 | + $urlforajaxcall = DOL_URL_ROOT.'/core/ajax/selectobject.php'; |
|
| 5381 | 5381 | //if ($objecttmp->element == 'societe') $urlforajaxcall = DOL_URL_ROOT.'/societe/ajax/company.php'; |
| 5382 | 5382 | // No immediate load of all database |
| 5383 | - $urloption = 'htmlname=' . $htmlname . '&outjson=1&objectdesc=' . $objectdesc . ($moreparams ? $moreparams : ''); |
|
| 5383 | + $urloption = 'htmlname='.$htmlname.'&outjson=1&objectdesc='.$objectdesc.($moreparams ? $moreparams : ''); |
|
| 5384 | 5384 | // Activate the auto complete using ajax call. |
| 5385 | 5385 | $out .= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array()); |
| 5386 | 5386 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
|
| 5387 | 5387 | if ($placeholder) |
| 5388 | - $placeholder = ' placeholder="' . $placeholder . '"'; |
|
| 5389 | - $out .= '<input type="text" class="' . $morecss . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $preselectedvalue . '"' . $placeholder . ' />'; |
|
| 5388 | + $placeholder = ' placeholder="'.$placeholder.'"'; |
|
| 5389 | + $out .= '<input type="text" class="'.$morecss.'" name="search_'.$htmlname.'" id="search_'.$htmlname.'" value="'.$preselectedvalue.'"'.$placeholder.' />'; |
|
| 5390 | 5390 | } |
| 5391 | 5391 | else {
|
| 5392 | 5392 | // Immediate load of all database |
@@ -5420,14 +5420,14 @@ discard block |
||
| 5420 | 5420 | $prefixforautocompletemode = $objecttmp->element; |
| 5421 | 5421 | if ($prefixforautocompletemode == 'societe') |
| 5422 | 5422 | $prefixforautocompletemode = 'company'; |
| 5423 | - $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
|
| 5423 | + $confkeyforautocompletemode = strtoupper($prefixforautocompletemode).'_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
|
| 5424 | 5424 | |
| 5425 | 5425 | $fieldstoshow = 't.ref'; |
| 5426 | 5426 | if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields ( like societe, contact, ...)
|
| 5427 | 5427 | $tmpfieldstoshow = ''; |
| 5428 | 5428 | foreach ($objecttmp->fields as $key => $val) {
|
| 5429 | 5429 | if ($val['showoncombobox']) |
| 5430 | - $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key; |
|
| 5430 | + $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '').'t.'.$key; |
|
| 5431 | 5431 | } |
| 5432 | 5432 | if ($tmpfieldstoshow) |
| 5433 | 5433 | $fieldstoshow = $tmpfieldstoshow; |
@@ -5439,36 +5439,36 @@ discard block |
||
| 5439 | 5439 | $num = 0; |
| 5440 | 5440 | |
| 5441 | 5441 | // Search data |
| 5442 | - $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . MAIN_DB_PREFIX . $objecttmp->table_element . " as t"; |
|
| 5442 | + $sql = "SELECT t.rowid, ".$fieldstoshow." FROM ".MAIN_DB_PREFIX.$objecttmp->table_element." as t"; |
|
| 5443 | 5443 | if ($objecttmp->ismultientitymanaged == 2) |
| 5444 | 5444 | if (!$user->rights->societe->client->voir && !$user->societe_id) |
| 5445 | - $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 5445 | + $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
| 5446 | 5446 | $sql .= " WHERE 1=1"; |
| 5447 | 5447 | if (!empty($objecttmp->ismultientitymanaged)) |
| 5448 | - $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
|
|
| 5448 | + $sql .= " AND t.entity IN (".getEntity($objecttmp->table_element).")";
|
|
| 5449 | 5449 | if ($objecttmp->ismultientitymanaged == 1 && !empty($user->societe_id)) {
|
| 5450 | 5450 | if ($objecttmp->element == 'societe') |
| 5451 | - $sql .= " AND t.rowid = " . $user->societe_id; |
|
| 5451 | + $sql .= " AND t.rowid = ".$user->societe_id; |
|
| 5452 | 5452 | else |
| 5453 | - $sql .= " AND t.fk_soc = " . $user->societe_id; |
|
| 5453 | + $sql .= " AND t.fk_soc = ".$user->societe_id; |
|
| 5454 | 5454 | } |
| 5455 | 5455 | if ($searchkey != '') |
| 5456 | 5456 | $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
|
| 5457 | 5457 | if ($objecttmp->ismultientitymanaged == 2) |
| 5458 | 5458 | if (!$user->rights->societe->client->voir && !$user->societe_id) |
| 5459 | - $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 5459 | + $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = ".$user->id; |
|
| 5460 | 5460 | $sql .= $this->db->order($fieldstoshow, "ASC"); |
| 5461 | 5461 | //$sql.=$this->db->plimit($limit, 0); |
| 5462 | 5462 | // Build output string |
| 5463 | 5463 | $resql = $this->db->query($sql); |
| 5464 | 5464 | if ($resql) {
|
| 5465 | 5465 | if (!$forcecombo) {
|
| 5466 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5466 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5467 | 5467 | $out .= ajax_combobox($htmlname, null, $conf->global->$confkeyforautocompletemode); |
| 5468 | 5468 | } |
| 5469 | 5469 | |
| 5470 | 5470 | // Construct $out and $outarray |
| 5471 | - $out .= '<select id="' . $htmlname . '" class="flat' . ($morecss ? ' ' . $morecss : '') . '"' . ($moreparams ? ' ' . $moreparams : '') . ' name="' . $htmlname . '">' . "\n"; |
|
| 5471 | + $out .= '<select id="'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'"'.($moreparams ? ' '.$moreparams : '').' name="'.$htmlname.'">'."\n"; |
|
| 5472 | 5472 | |
| 5473 | 5473 | // Warning: Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. Seems it is no more true with selec2 v4 |
| 5474 | 5474 | $textifempty = ' '; |
@@ -5481,7 +5481,7 @@ discard block |
||
| 5481 | 5481 | $textifempty .= $langs->trans("All");
|
| 5482 | 5482 | } |
| 5483 | 5483 | if ($showempty) |
| 5484 | - $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 5484 | + $out .= '<option value="-1">'.$textifempty.'</option>'."\n"; |
|
| 5485 | 5485 | |
| 5486 | 5486 | $num = $this->db->num_rows($resql); |
| 5487 | 5487 | $i = 0; |
@@ -5492,13 +5492,13 @@ discard block |
||
| 5492 | 5492 | $tmparray = explode(',', $fieldstoshow);
|
| 5493 | 5493 | foreach ($tmparray as $key => $val) {
|
| 5494 | 5494 | $val = preg_replace('/t\./', '', $val);
|
| 5495 | - $label .= (($label && $obj->$val) ? ' - ' : '') . $obj->$val; |
|
| 5495 | + $label .= (($label && $obj->$val) ? ' - ' : '').$obj->$val; |
|
| 5496 | 5496 | } |
| 5497 | 5497 | if (empty($outputmode)) {
|
| 5498 | 5498 | if ($preselectedvalue > 0 && $preselectedvalue == $obj->rowid) {
|
| 5499 | - $out .= '<option value="' . $obj->rowid . '" selected>' . $label . '</option>'; |
|
| 5499 | + $out .= '<option value="'.$obj->rowid.'" selected>'.$label.'</option>'; |
|
| 5500 | 5500 | } else {
|
| 5501 | - $out .= '<option value="' . $obj->rowid . '">' . $label . '</option>'; |
|
| 5501 | + $out .= '<option value="'.$obj->rowid.'">'.$label.'</option>'; |
|
| 5502 | 5502 | } |
| 5503 | 5503 | } else {
|
| 5504 | 5504 | array_push($outarray, array('key' => $obj->rowid, 'value' => $label, 'label' => $label));
|
@@ -5510,7 +5510,7 @@ discard block |
||
| 5510 | 5510 | } |
| 5511 | 5511 | } |
| 5512 | 5512 | |
| 5513 | - $out .= '</select>' . "\n"; |
|
| 5513 | + $out .= '</select>'."\n"; |
|
| 5514 | 5514 | } |
| 5515 | 5515 | else {
|
| 5516 | 5516 | dol_print_error($this->db); |
@@ -5566,12 +5566,12 @@ discard block |
||
| 5566 | 5566 | $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ? (constant('REQUIRE_JQUERY_MULTISELECT') ? constant('REQUIRE_JQUERY_MULTISELECT') : 'select2') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
|
| 5567 | 5567 | |
| 5568 | 5568 | // Enhance with select2 |
| 5569 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5569 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 5570 | 5570 | $out .= ajax_combobox($htmlname); |
| 5571 | 5571 | } |
| 5572 | 5572 | |
| 5573 | - $out .= '<select id="' . preg_replace('/^\./', '', $htmlname) . '" ' . ($disabled ? 'disabled ' : '') . 'class="flat ' . (preg_replace('/^\./', '', $htmlname)) . ($morecss ? ' ' . $morecss : '') . '"';
|
|
| 5574 | - $out .= ' name="' . preg_replace('/^\./', '', $htmlname) . '" ' . ($moreparam ? $moreparam : '');
|
|
| 5573 | + $out .= '<select id="'.preg_replace('/^\./', '', $htmlname).'" '.($disabled ? 'disabled ' : '').'class="flat '.(preg_replace('/^\./', '', $htmlname)).($morecss ? ' '.$morecss : '').'"';
|
|
| 5574 | + $out .= ' name="'.preg_replace('/^\./', '', $htmlname).'" '.($moreparam ? $moreparam : '');
|
|
| 5575 | 5575 | $out .= '>'; |
| 5576 | 5576 | |
| 5577 | 5577 | if ($show_empty) {
|
@@ -5580,7 +5580,7 @@ discard block |
||
| 5580 | 5580 | $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small. |
| 5581 | 5581 | if (!is_numeric($show_empty)) |
| 5582 | 5582 | $textforempty = $show_empty; |
| 5583 | - $out .= '<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n"; |
|
| 5583 | + $out .= '<option class="optiongrey" '.($moreparamonempty ? $moreparamonempty.' ' : '').'value="'.($show_empty < 0 ? $show_empty : -1).'"'.($id == $show_empty ? ' selected' : '').'>'.$textforempty.'</option>'."\n"; |
|
| 5584 | 5584 | } |
| 5585 | 5585 | |
| 5586 | 5586 | if (is_array($array)) {
|
@@ -5610,9 +5610,9 @@ discard block |
||
| 5610 | 5610 | |
| 5611 | 5611 | if ($key_in_label) {
|
| 5612 | 5612 | if (empty($nohtmlescape)) |
| 5613 | - $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value)); |
|
| 5613 | + $selectOptionValue = dol_escape_htmltag($key.' - '.($maxlen ? dol_trunc($value, $maxlen) : $value)); |
|
| 5614 | 5614 | else |
| 5615 | - $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5615 | + $selectOptionValue = $key.' - '.($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5616 | 5616 | } |
| 5617 | 5617 | else {
|
| 5618 | 5618 | if (empty($nohtmlescape)) |
@@ -5623,12 +5623,12 @@ discard block |
||
| 5623 | 5623 | $selectOptionValue = ' '; |
| 5624 | 5624 | } |
| 5625 | 5625 | |
| 5626 | - $out .= '<option value="' . $key . '"'; |
|
| 5627 | - $out .= $style . $disabled; |
|
| 5626 | + $out .= '<option value="'.$key.'"'; |
|
| 5627 | + $out .= $style.$disabled; |
|
| 5628 | 5628 | if ($id != '' && $id == $key && !$disabled) |
| 5629 | - $out .= ' selected'; // To preselect a value |
|
| 5629 | + $out .= ' selected'; // To preselect a value |
|
| 5630 | 5630 | if ($nohtmlescape) |
| 5631 | - $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"'; |
|
| 5631 | + $out .= ' data-html="'.dol_escape_htmltag($selectOptionValue).'"'; |
|
| 5632 | 5632 | $out .= '>'; |
| 5633 | 5633 | //var_dump($selectOptionValue); |
| 5634 | 5634 | $out .= $selectOptionValue; |
@@ -5667,19 +5667,19 @@ discard block |
||
| 5667 | 5667 | if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT'))
|
| 5668 | 5668 | return ''; |
| 5669 | 5669 | |
| 5670 | - $out = '<select type="text" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>'; |
|
| 5670 | + $out = '<select type="text" class="'.$htmlname.($morecss ? ' '.$morecss : '').'" '.($moreparam ? $moreparam.' ' : '').'name="'.$htmlname.'"></select>'; |
|
| 5671 | 5671 | |
| 5672 | 5672 | $tmpplugin = 'select2'; |
| 5673 | - $outdelayed = "\n" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' --> |
|
| 5673 | + $outdelayed = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> |
|
| 5674 | 5674 | <script type="text/javascript"> |
| 5675 | 5675 | $(document).ready(function () {
|
| 5676 | 5676 | |
| 5677 | - ' . ($callurlonselect ? 'var saveRemoteData = [];' : '') . ' |
|
| 5677 | + ' . ($callurlonselect ? 'var saveRemoteData = [];' : '').' |
|
| 5678 | 5678 | |
| 5679 | - $(".' . $htmlname . '").select2({
|
|
| 5679 | + $(".' . $htmlname.'").select2({
|
|
| 5680 | 5680 | ajax: {
|
| 5681 | 5681 | dir: "ltr", |
| 5682 | - url: "' . $url . '", |
|
| 5682 | + url: "' . $url.'", |
|
| 5683 | 5683 | dataType: \'json\', |
| 5684 | 5684 | delay: 250, |
| 5685 | 5685 | data: function (params) {
|
@@ -5706,9 +5706,9 @@ discard block |
||
| 5706 | 5706 | }, |
| 5707 | 5707 | language: select2arrayoflanguage, |
| 5708 | 5708 | containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ |
| 5709 | - placeholder: "' . dol_escape_js($placeholder) . '", |
|
| 5709 | + placeholder: "' . dol_escape_js($placeholder).'", |
|
| 5710 | 5710 | escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
| 5711 | - minimumInputLength: ' . $minimumInputLength . ', |
|
| 5711 | + minimumInputLength: ' . $minimumInputLength.', |
|
| 5712 | 5712 | formatResult: function(result, container, query, escapeMarkup) {
|
| 5713 | 5713 | return escapeMarkup(result.text); |
| 5714 | 5714 | }, |
@@ -5716,10 +5716,10 @@ discard block |
||
| 5716 | 5716 | |
| 5717 | 5717 | ' . ($callurlonselect ? ' |
| 5718 | 5718 | /* Code to execute a GET when we select a value */ |
| 5719 | - $(".' . $htmlname . '").change(function() {
|
|
| 5720 | - var selected = $(".' . $htmlname . '").val();
|
|
| 5719 | + $(".' . $htmlname.'").change(function() {
|
|
| 5720 | + var selected = $(".' . $htmlname.'").val();
|
|
| 5721 | 5721 | console.log("We select in selectArrayAjax the entry "+selected)
|
| 5722 | - $(".' . $htmlname . '").val(""); /* reset visible combo value */
|
|
| 5722 | + $(".' . $htmlname.'").val(""); /* reset visible combo value */
|
|
| 5723 | 5723 | $.each( saveRemoteData, function( key, value ) {
|
| 5724 | 5724 | if (key == selected) |
| 5725 | 5725 | {
|
@@ -5727,7 +5727,7 @@ discard block |
||
| 5727 | 5727 | location.assign(value.url); |
| 5728 | 5728 | } |
| 5729 | 5729 | }); |
| 5730 | - });' : '' ) . ' |
|
| 5730 | + });' : '').' |
|
| 5731 | 5731 | |
| 5732 | 5732 | }); |
| 5733 | 5733 | </script>'; |
@@ -5767,7 +5767,7 @@ discard block |
||
| 5767 | 5767 | if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT'))
|
| 5768 | 5768 | return ''; |
| 5769 | 5769 | |
| 5770 | - $out = '<select type="text" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"><option></option></select>'; |
|
| 5770 | + $out = '<select type="text" class="'.$htmlname.($morecss ? ' '.$morecss : '').'" '.($moreparam ? $moreparam.' ' : '').'name="'.$htmlname.'"><option></option></select>'; |
|
| 5771 | 5771 | |
| 5772 | 5772 | $formattedarrayresult = array(); |
| 5773 | 5773 | |
@@ -5780,20 +5780,20 @@ discard block |
||
| 5780 | 5780 | } |
| 5781 | 5781 | |
| 5782 | 5782 | $tmpplugin = 'select2'; |
| 5783 | - $outdelayed = "\n" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' --> |
|
| 5783 | + $outdelayed = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> |
|
| 5784 | 5784 | <script type="text/javascript"> |
| 5785 | 5785 | $(document).ready(function () {
|
| 5786 | - var data = ' . json_encode($formattedarrayresult) . '; |
|
| 5786 | + var data = ' . json_encode($formattedarrayresult).'; |
|
| 5787 | 5787 | |
| 5788 | - ' . ($callurlonselect ? 'var saveRemoteData = ' . json_encode($array) . ';' : '') . ' |
|
| 5788 | + ' . ($callurlonselect ? 'var saveRemoteData = '.json_encode($array).';' : '').' |
|
| 5789 | 5789 | |
| 5790 | - $(".' . $htmlname . '").select2({
|
|
| 5790 | + $(".' . $htmlname.'").select2({
|
|
| 5791 | 5791 | data: data, |
| 5792 | 5792 | language: select2arrayoflanguage, |
| 5793 | 5793 | containerCssClass: \':all:\', /* Line to add class of origin SELECT propagated to the new <span class="select2-selection...> tag */ |
| 5794 | - placeholder: "' . dol_escape_js($placeholder) . '", |
|
| 5794 | + placeholder: "' . dol_escape_js($placeholder).'", |
|
| 5795 | 5795 | escapeMarkup: function (markup) { return markup; }, // let our custom formatter work
|
| 5796 | - minimumInputLength: ' . $minimumInputLength . ', |
|
| 5796 | + minimumInputLength: ' . $minimumInputLength.', |
|
| 5797 | 5797 | formatResult: function(result, container, query, escapeMarkup) {
|
| 5798 | 5798 | return escapeMarkup(result.text); |
| 5799 | 5799 | }, |
@@ -5831,11 +5831,11 @@ discard block |
||
| 5831 | 5831 | |
| 5832 | 5832 | ' . ($callurlonselect ? ' |
| 5833 | 5833 | /* Code to execute a GET when we select a value */ |
| 5834 | - $(".' . $htmlname . '").change(function() {
|
|
| 5835 | - var selected = $(".' . $htmlname . '").val();
|
|
| 5834 | + $(".' . $htmlname.'").change(function() {
|
|
| 5835 | + var selected = $(".' . $htmlname.'").val();
|
|
| 5836 | 5836 | console.log("We select "+selected)
|
| 5837 | 5837 | |
| 5838 | - $(".' . $htmlname . '").val(""); /* reset visible combo value */
|
|
| 5838 | + $(".' . $htmlname.'").val(""); /* reset visible combo value */
|
|
| 5839 | 5839 | $.each( saveRemoteData, function( key, value ) {
|
| 5840 | 5840 | if (key == selected) |
| 5841 | 5841 | {
|
@@ -5843,7 +5843,7 @@ discard block |
||
| 5843 | 5843 | location.assign(value.url); |
| 5844 | 5844 | } |
| 5845 | 5845 | }); |
| 5846 | - });' : '' ) . ' |
|
| 5846 | + });' : '').' |
|
| 5847 | 5847 | |
| 5848 | 5848 | }); |
| 5849 | 5849 | </script>'; |
@@ -5883,28 +5883,28 @@ discard block |
||
| 5883 | 5883 | |
| 5884 | 5884 | // Add code for jquery to use multiselect |
| 5885 | 5885 | if (!empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) || defined('REQUIRE_JQUERY_MULTISELECT')) {
|
| 5886 | - $out .= "\n" . '<!-- JS CODE TO ENABLE ' . $tmpplugin . ' for id ' . $htmlname . ' --> |
|
| 5886 | + $out .= "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' --> |
|
| 5887 | 5887 | <script type="text/javascript">' . "\n"; |
| 5888 | 5888 | if ($addjscombo == 1) {
|
| 5889 | 5889 | $tmpplugin = empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) ? constant('REQUIRE_JQUERY_MULTISELECT') : $conf->global->MAIN_USE_JQUERY_MULTISELECT;
|
| 5890 | - $out .= 'function formatResult(record) {' . "\n";
|
|
| 5890 | + $out .= 'function formatResult(record) {'."\n";
|
|
| 5891 | 5891 | if ($elemtype == 'category') {
|
| 5892 | - $out .= ' //return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png' . '"> <a href="' . DOL_URL_ROOT . '/categories/viewcat.php?type=0&id=\'+record.id+\'">\'+record.text+\'</a></span>\'; |
|
| 5893 | - return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png' . '"> \'+record.text+\'</span>\';'; |
|
| 5892 | + $out .= ' //return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> <a href="'.DOL_URL_ROOT.'/categories/viewcat.php?type=0&id=\'+record.id+\'">\'+record.text+\'</a></span>\'; |
|
| 5893 | + return \'<span><img src="' . DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> \'+record.text+\'</span>\';'; |
|
| 5894 | 5894 | } else {
|
| 5895 | 5895 | $out .= 'return record.text;'; |
| 5896 | 5896 | } |
| 5897 | - $out .= '};' . "\n"; |
|
| 5898 | - $out .= 'function formatSelection(record) {' . "\n";
|
|
| 5897 | + $out .= '};'."\n"; |
|
| 5898 | + $out .= 'function formatSelection(record) {'."\n";
|
|
| 5899 | 5899 | if ($elemtype == 'category') {
|
| 5900 | - $out .= ' //return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png' . '"> <a href="' . DOL_URL_ROOT . '/categories/viewcat.php?type=0&id=\'+record.id+\'">\'+record.text+\'</a></span>\'; |
|
| 5901 | - return \'<span><img src="' . DOL_URL_ROOT . '/theme/eldy/img/object_category.png' . '"> \'+record.text+\'</span>\';'; |
|
| 5900 | + $out .= ' //return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> <a href="'.DOL_URL_ROOT.'/categories/viewcat.php?type=0&id=\'+record.id+\'">\'+record.text+\'</a></span>\'; |
|
| 5901 | + return \'<span><img src="' . DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> \'+record.text+\'</span>\';'; |
|
| 5902 | 5902 | } else {
|
| 5903 | 5903 | $out .= 'return record.text;'; |
| 5904 | 5904 | } |
| 5905 | - $out .= '};' . "\n"; |
|
| 5905 | + $out .= '};'."\n"; |
|
| 5906 | 5906 | $out .= '$(document).ready(function () {
|
| 5907 | - $(\'#' . $htmlname . '\').' . $tmpplugin . '({
|
|
| 5907 | + $(\'#' . $htmlname.'\').'.$tmpplugin.'({
|
|
| 5908 | 5908 | dir: \'ltr\', |
| 5909 | 5909 | // Specify format function for dropdown item |
| 5910 | 5910 | formatResult: formatResult, |
@@ -5918,13 +5918,13 @@ discard block |
||
| 5918 | 5918 | // Add other js lib |
| 5919 | 5919 | // ... |
| 5920 | 5920 | $out .= '$(document).ready(function () {
|
| 5921 | - $(\'#' . $htmlname . '\').multiSelect({
|
|
| 5921 | + $(\'#' . $htmlname.'\').multiSelect({
|
|
| 5922 | 5922 | containerHTML: \'<div class="multi-select-container">\', |
| 5923 | 5923 | menuHTML: \'<div class="multi-select-menu">\', |
| 5924 | - buttonHTML: \'<span class="multi-select-button ' . $morecss . '">\', |
|
| 5924 | + buttonHTML: \'<span class="multi-select-button ' . $morecss.'">\', |
|
| 5925 | 5925 | menuItemHTML: \'<label class="multi-select-menuitem">\', |
| 5926 | 5926 | activeClass: \'multi-select-container--open\', |
| 5927 | - noneText: \'' . $placeholder . '\' |
|
| 5927 | + noneText: \'' . $placeholder.'\' |
|
| 5928 | 5928 | }); |
| 5929 | 5929 | })'; |
| 5930 | 5930 | } |
@@ -5933,27 +5933,27 @@ discard block |
||
| 5933 | 5933 | |
| 5934 | 5934 | // Try also magic suggest |
| 5935 | 5935 | |
| 5936 | - $out .= '<select id="' . $htmlname . '" class="multiselect' . ($morecss ? ' ' . $morecss : '') . '" multiple name="' . $htmlname . '[]"' . ($moreattrib ? ' ' . $moreattrib : '') . ($width ? ' style="width: ' . (preg_match('/%/', $width) ? $width : $width . 'px') . '"' : '') . '>' . "\n";
|
|
| 5936 | + $out .= '<select id="'.$htmlname.'" class="multiselect'.($morecss ? ' '.$morecss : '').'" multiple name="'.$htmlname.'[]"'.($moreattrib ? ' '.$moreattrib : '').($width ? ' style="width: '.(preg_match('/%/', $width) ? $width : $width.'px').'"' : '').'>'."\n";
|
|
| 5937 | 5937 | if (is_array($array) && !empty($array)) {
|
| 5938 | 5938 | if ($value_as_key) |
| 5939 | 5939 | $array = array_combine($array, $array); |
| 5940 | 5940 | |
| 5941 | 5941 | if (!empty($array)) {
|
| 5942 | 5942 | foreach ($array as $key => $value) {
|
| 5943 | - $out .= '<option value="' . $key . '"'; |
|
| 5943 | + $out .= '<option value="'.$key.'"'; |
|
| 5944 | 5944 | if (is_array($selected) && !empty($selected) && in_array($key, $selected) && !empty($key)) {
|
| 5945 | 5945 | $out .= ' selected'; |
| 5946 | 5946 | } |
| 5947 | 5947 | $out .= '>'; |
| 5948 | 5948 | |
| 5949 | 5949 | $newval = ($translate ? $langs->trans($value) : $value); |
| 5950 | - $newval = ($key_in_label ? $key . ' - ' . $newval : $newval); |
|
| 5950 | + $newval = ($key_in_label ? $key.' - '.$newval : $newval); |
|
| 5951 | 5951 | $out .= dol_htmlentitiesbr($newval); |
| 5952 | - $out .= '</option>' . "\n"; |
|
| 5952 | + $out .= '</option>'."\n"; |
|
| 5953 | 5953 | } |
| 5954 | 5954 | } |
| 5955 | 5955 | } |
| 5956 | - $out .= '</select>' . "\n"; |
|
| 5956 | + $out .= '</select>'."\n"; |
|
| 5957 | 5957 | |
| 5958 | 5958 | return $out; |
| 5959 | 5959 | } |
@@ -5974,7 +5974,7 @@ discard block |
||
| 5974 | 5974 | if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
| 5975 | 5975 | return ''; |
| 5976 | 5976 | |
| 5977 | - $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; |
|
| 5977 | + $tmpvar = "MAIN_SELECTEDFIELDS_".$varpage; |
|
| 5978 | 5978 | if (!empty($user->conf->$tmpvar)) {
|
| 5979 | 5979 | $tmparray = explode(',', $user->conf->$tmpvar);
|
| 5980 | 5980 | foreach ($array as $key => $val) {
|
@@ -5996,28 +5996,28 @@ discard block |
||
| 5996 | 5996 | var_dump(array_key_exists('enabled', $val));
|
| 5997 | 5997 | var_dump(!$val['enabled']); */ |
| 5998 | 5998 | if (array_key_exists('enabled', $val) && isset($val['enabled']) && !$val['enabled']) {
|
| 5999 | - unset($array[$key]); // We don't want this field |
|
| 5999 | + unset($array[$key]); // We don't want this field |
|
| 6000 | 6000 | continue; |
| 6001 | 6001 | } |
| 6002 | 6002 | if ($val['label']) {
|
| 6003 | - $lis .= '<li><input type="checkbox" id="checkbox' . $key . '" value="' . $key . '"' . (empty($val['checked']) ? '' : ' checked="checked"') . '/><label for="checkbox' . $key . '">' . dol_escape_htmltag($langs->trans($val['label'])) . '</label></li>'; |
|
| 6004 | - $listcheckedstring .= (empty($val['checked']) ? '' : $key . ','); |
|
| 6003 | + $lis .= '<li><input type="checkbox" id="checkbox'.$key.'" value="'.$key.'"'.(empty($val['checked']) ? '' : ' checked="checked"').'/><label for="checkbox'.$key.'">'.dol_escape_htmltag($langs->trans($val['label'])).'</label></li>'; |
|
| 6004 | + $listcheckedstring .= (empty($val['checked']) ? '' : $key.','); |
|
| 6005 | 6005 | } |
| 6006 | 6006 | } |
| 6007 | 6007 | |
| 6008 | - $out = '<!-- Component multiSelectArrayWithCheckbox ' . $htmlname . ' --> |
|
| 6008 | + $out = '<!-- Component multiSelectArrayWithCheckbox '.$htmlname.' --> |
|
| 6009 | 6009 | |
| 6010 | 6010 | <dl class="dropdown"> |
| 6011 | 6011 | <dt> |
| 6012 | 6012 | <a href="#"> |
| 6013 | - ' . img_picto('', 'list') . '
|
|
| 6013 | + ' . img_picto('', 'list').'
|
|
| 6014 | 6014 | </a> |
| 6015 | - <input type="hidden" class="' . $htmlname . '" name="' . $htmlname . '" value="' . $listcheckedstring . '"> |
|
| 6015 | + <input type="hidden" class="' . $htmlname.'" name="'.$htmlname.'" value="'.$listcheckedstring.'"> |
|
| 6016 | 6016 | </dt> |
| 6017 | 6017 | <dd class="dropdowndd"> |
| 6018 | - <div class="multiselectcheckbox' . $htmlname . '"> |
|
| 6019 | - <ul class="ul' . $htmlname . '"> |
|
| 6020 | - ' . $lis . ' |
|
| 6018 | + <div class="multiselectcheckbox' . $htmlname.'"> |
|
| 6019 | + <ul class="ul' . $htmlname.'"> |
|
| 6020 | + ' . $lis.' |
|
| 6021 | 6021 | </ul> |
| 6022 | 6022 | </div> |
| 6023 | 6023 | </dd> |
@@ -6025,15 +6025,15 @@ discard block |
||
| 6025 | 6025 | |
| 6026 | 6026 | <script type="text/javascript"> |
| 6027 | 6027 | jQuery(document).ready(function () {
|
| 6028 | - $(\'.multiselectcheckbox' . $htmlname . ' input[type="checkbox"]\').on(\'click\', function () {
|
|
| 6028 | + $(\'.multiselectcheckbox' . $htmlname.' input[type="checkbox"]\').on(\'click\', function () {
|
|
| 6029 | 6029 | console.log("A new field was added/removed")
|
| 6030 | 6030 | $("input:hidden[name=formfilteraction]").val(\'listafterchangingselectedfields\')
|
| 6031 | 6031 | var title = $(this).val() + ","; |
| 6032 | 6032 | if ($(this).is(\':checked\')) {
|
| 6033 | - $(\'.' . $htmlname . '\').val(title + $(\'.' . $htmlname . '\').val()); |
|
| 6033 | + $(\'.' . $htmlname.'\').val(title + $(\'.'.$htmlname.'\').val()); |
|
| 6034 | 6034 | } |
| 6035 | 6035 | else {
|
| 6036 | - $(\'.' . $htmlname . '\').val( $(\'.' . $htmlname . '\').val().replace(title, \'\') ) |
|
| 6036 | + $(\'.' . $htmlname.'\').val( $(\'.'.$htmlname.'\').val().replace(title, \'\') ) |
|
| 6037 | 6037 | } |
| 6038 | 6038 | // Now, we submit page |
| 6039 | 6039 | $(this).parents(\'form:first\').submit(); |
@@ -6057,7 +6057,7 @@ discard block |
||
| 6057 | 6057 | {
|
| 6058 | 6058 | global $db; |
| 6059 | 6059 | |
| 6060 | - include_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; |
|
| 6060 | + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
| 6061 | 6061 | |
| 6062 | 6062 | $cat = new Categorie($db); |
| 6063 | 6063 | $categories = $cat->containing($id, $type); |
@@ -6065,12 +6065,12 @@ discard block |
||
| 6065 | 6065 | if ($rendermode == 1) {
|
| 6066 | 6066 | $toprint = array(); |
| 6067 | 6067 | foreach ($categories as $c) {
|
| 6068 | - $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text |
|
| 6068 | + $ways = $c->print_all_ways(); // $ways[0] = "ccc2 >> ccc2a >> ccc2a1" with html formated text |
|
| 6069 | 6069 | foreach ($ways as $way) {
|
| 6070 | - $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"' . ($c->color ? ' style="background: #' . $c->color . ';"' : ' style="background: #aaa"') . '>' . img_object('', 'category') . ' ' . $way . '</li>';
|
|
| 6070 | + $toprint[] = '<li class="select2-search-choice-dolibarr noborderoncategories"'.($c->color ? ' style="background: #'.$c->color.';"' : ' style="background: #aaa"').'>'.img_object('', 'category').' '.$way.'</li>';
|
|
| 6071 | 6071 | } |
| 6072 | 6072 | } |
| 6073 | - return '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">' . implode(' ', $toprint) . '</ul></div>';
|
|
| 6073 | + return '<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6074 | 6074 | } |
| 6075 | 6075 | |
| 6076 | 6076 | if ($rendermode == 0) {
|
@@ -6106,7 +6106,7 @@ discard block |
||
| 6106 | 6106 | 'morehtmlright' => $morehtmlright, |
| 6107 | 6107 | 'compatibleImportElementsList' => & $compatibleImportElementsList, |
| 6108 | 6108 | ); |
| 6109 | - $reshook = $hookmanager->executeHooks('showLinkedObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
|
| 6109 | + $reshook = $hookmanager->executeHooks('showLinkedObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
|
| 6110 | 6110 | |
| 6111 | 6111 | if (empty($reshook)) {
|
| 6112 | 6112 | $nbofdifferenttypes = count($object->linkedObjects); |
@@ -6116,15 +6116,15 @@ discard block |
||
| 6116 | 6116 | |
| 6117 | 6117 | |
| 6118 | 6118 | print '<div class="div-table-responsive-no-min">'; |
| 6119 | - print '<table class="noborder allwidth" data-block="showLinkedObject" data-element="' . $object->element . '" data-elementid="' . $object->id . '" >'; |
|
| 6119 | + print '<table class="noborder allwidth" data-block="showLinkedObject" data-element="'.$object->element.'" data-elementid="'.$object->id.'" >'; |
|
| 6120 | 6120 | |
| 6121 | 6121 | print '<tr class="liste_titre">'; |
| 6122 | - print '<td>' . $langs->trans("Type") . '</td>';
|
|
| 6123 | - print '<td>' . $langs->trans("Ref") . '</td>';
|
|
| 6122 | + print '<td>'.$langs->trans("Type").'</td>';
|
|
| 6123 | + print '<td>'.$langs->trans("Ref").'</td>';
|
|
| 6124 | 6124 | print '<td align="center"></td>'; |
| 6125 | - print '<td align="center">' . $langs->trans("Date") . '</td>';
|
|
| 6126 | - print '<td align="right">' . $langs->trans("AmountHTShort") . '</td>';
|
|
| 6127 | - print '<td align="right">' . $langs->trans("Status") . '</td>';
|
|
| 6125 | + print '<td align="center">'.$langs->trans("Date").'</td>';
|
|
| 6126 | + print '<td align="right">'.$langs->trans("AmountHTShort").'</td>';
|
|
| 6127 | + print '<td align="right">'.$langs->trans("Status").'</td>';
|
|
| 6128 | 6128 | print '<td></td>'; |
| 6129 | 6129 | print '</tr>'; |
| 6130 | 6130 | |
@@ -6142,13 +6142,13 @@ discard block |
||
| 6142 | 6142 | if ($objecttype != 'supplier_proposal' && preg_match('/^([^_]+)_([^_]+)/i', $objecttype, $regs)) {
|
| 6143 | 6143 | $element = $regs[1]; |
| 6144 | 6144 | $subelement = $regs[2]; |
| 6145 | - $tplpath = $element . '/' . $subelement; |
|
| 6145 | + $tplpath = $element.'/'.$subelement; |
|
| 6146 | 6146 | } |
| 6147 | 6147 | $tplname = 'linkedobjectblock'; |
| 6148 | 6148 | |
| 6149 | 6149 | // To work with non standard path |
| 6150 | 6150 | if ($objecttype == 'facture') {
|
| 6151 | - $tplpath = 'compta/' . $element; |
|
| 6151 | + $tplpath = 'compta/'.$element; |
|
| 6152 | 6152 | if (empty($conf->facture->enabled)) |
| 6153 | 6153 | continue; // Do not show if module disabled |
| 6154 | 6154 | } |
@@ -6159,7 +6159,7 @@ discard block |
||
| 6159 | 6159 | continue; // Do not show if module disabled |
| 6160 | 6160 | } |
| 6161 | 6161 | else if ($objecttype == 'propal') {
|
| 6162 | - $tplpath = 'comm/' . $element; |
|
| 6162 | + $tplpath = 'comm/'.$element; |
|
| 6163 | 6163 | if (empty($conf->propal->enabled)) |
| 6164 | 6164 | continue; // Do not show if module disabled |
| 6165 | 6165 | } |
@@ -6197,14 +6197,14 @@ discard block |
||
| 6197 | 6197 | |
| 6198 | 6198 | |
| 6199 | 6199 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 6200 | - $dirtpls = array_merge($conf->modules_parts['tpl'], array('/' . $tplpath . '/tpl'));
|
|
| 6200 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/'.$tplpath.'/tpl'));
|
|
| 6201 | 6201 | foreach ($dirtpls as $reldir) {
|
| 6202 | 6202 | if ($nboftypesoutput == ($nbofdifferenttypes - 1)) { // No more type to show after
|
| 6203 | 6203 | global $noMoreLinkedObjectBlockAfter; |
| 6204 | 6204 | $noMoreLinkedObjectBlockAfter = 1; |
| 6205 | 6205 | } |
| 6206 | 6206 | |
| 6207 | - $res = @include dol_buildpath($reldir . '/' . $tplname . '.tpl.php'); |
|
| 6207 | + $res = @include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); |
|
| 6208 | 6208 | if ($res) {
|
| 6209 | 6209 | $nboftypesoutput++; |
| 6210 | 6210 | break; |
@@ -6213,7 +6213,7 @@ discard block |
||
| 6213 | 6213 | } |
| 6214 | 6214 | |
| 6215 | 6215 | if (!$nboftypesoutput) {
|
| 6216 | - print '<tr><td class="impair opacitymedium" colspan="7">' . $langs->trans("None") . '</td></tr>';
|
|
| 6216 | + print '<tr><td class="impair opacitymedium" colspan="7">'.$langs->trans("None").'</td></tr>';
|
|
| 6217 | 6217 | } |
| 6218 | 6218 | |
| 6219 | 6219 | print '</table>'; |
@@ -6253,26 +6253,26 @@ discard block |
||
| 6253 | 6253 | if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
|
| 6254 | 6254 | $listofidcompanytoscan = $object->thirdparty->id; |
| 6255 | 6255 | if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) |
| 6256 | - $listofidcompanytoscan .= ',' . $object->thirdparty->parent; |
|
| 6256 | + $listofidcompanytoscan .= ','.$object->thirdparty->parent; |
|
| 6257 | 6257 | if (($object->fk_project > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) {
|
| 6258 | - include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; |
|
| 6258 | + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 6259 | 6259 | $tmpproject = new Project($this->db); |
| 6260 | 6260 | $tmpproject->fetch($object->fk_project); |
| 6261 | 6261 | if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) |
| 6262 | - $listofidcompanytoscan .= ',' . $tmpproject->socid; |
|
| 6262 | + $listofidcompanytoscan .= ','.$tmpproject->socid; |
|
| 6263 | 6263 | unset($tmpproject); |
| 6264 | 6264 | } |
| 6265 | 6265 | |
| 6266 | 6266 | $possiblelinks = array( |
| 6267 | - 'propal' => array('enabled' => $conf->propal->enabled, 'perms' => 1, 'label' => 'LinkToProposal', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('propal') . ')'),
|
|
| 6268 | - 'order' => array('enabled' => $conf->commande->enabled, 'perms' => 1, 'label' => 'LinkToOrder', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('commande') . ')'),
|
|
| 6269 | - 'invoice' => array('enabled' => $conf->facture->enabled, 'perms' => 1, 'label' => 'LinkToInvoice', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total as total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('invoice') . ')'),
|
|
| 6270 | - 'invoice_template' => array('enabled' => $conf->facture->enabled, 'perms' => 1, 'label' => 'LinkToTemplateInvoice', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total as total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('invoice') . ')'),
|
|
| 6271 | - 'contrat' => array('enabled' => $conf->contrat->enabled, 'perms' => 1, 'label' => 'LinkToContract', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('contract') . ')'),
|
|
| 6272 | - 'fichinter' => array('enabled' => $conf->ficheinter->enabled, 'perms' => 1, 'label' => 'LinkToIntervention', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('intervention') . ')'),
|
|
| 6273 | - 'supplier_proposal' => array('enabled' => $conf->supplier_proposal->enabled, 'perms' => 1, 'label' => 'LinkToSupplierProposal', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('supplier_proposal') . ')'),
|
|
| 6274 | - 'order_supplier' => array('enabled' => $conf->supplier_order->enabled, 'perms' => 1, 'label' => 'LinkToSupplierOrder', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('commande_fournisseur') . ')'),
|
|
| 6275 | - 'invoice_supplier' => array('enabled' => $conf->supplier_invoice->enabled, 'perms' => 1, 'label' => 'LinkToSupplierInvoice', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (" . $listofidcompanytoscan . ') AND t.entity IN (' . getEntity('facture_fourn') . ')')
|
|
| 6267 | + 'propal' => array('enabled' => $conf->propal->enabled, 'perms' => 1, 'label' => 'LinkToProposal', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('propal').')'),
|
|
| 6268 | + 'order' => array('enabled' => $conf->commande->enabled, 'perms' => 1, 'label' => 'LinkToOrder', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande').')'),
|
|
| 6269 | + 'invoice' => array('enabled' => $conf->facture->enabled, 'perms' => 1, 'label' => 'LinkToInvoice', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'),
|
|
| 6270 | + 'invoice_template' => array('enabled' => $conf->facture->enabled, 'perms' => 1, 'label' => 'LinkToTemplateInvoice', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'),
|
|
| 6271 | + 'contrat' => array('enabled' => $conf->contrat->enabled, 'perms' => 1, 'label' => 'LinkToContract', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('contract').')'),
|
|
| 6272 | + 'fichinter' => array('enabled' => $conf->ficheinter->enabled, 'perms' => 1, 'label' => 'LinkToIntervention', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('intervention').')'),
|
|
| 6273 | + 'supplier_proposal' => array('enabled' => $conf->supplier_proposal->enabled, 'perms' => 1, 'label' => 'LinkToSupplierProposal', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('supplier_proposal').')'),
|
|
| 6274 | + 'order_supplier' => array('enabled' => $conf->supplier_order->enabled, 'perms' => 1, 'label' => 'LinkToSupplierOrder', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande_fournisseur').')'),
|
|
| 6275 | + 'invoice_supplier' => array('enabled' => $conf->supplier_invoice->enabled, 'perms' => 1, 'label' => 'LinkToSupplierInvoice', 'sql' => "SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn').')')
|
|
| 6276 | 6276 | ); |
| 6277 | 6277 | } |
| 6278 | 6278 | |
@@ -6281,7 +6281,7 @@ discard block |
||
| 6281 | 6281 | // Can complete the possiblelink array |
| 6282 | 6282 | $hookmanager->initHooks(array('commonobject'));
|
| 6283 | 6283 | $parameters = array('listofidcompanytoscan' => $listofidcompanytoscan);
|
| 6284 | - $reshook = $hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
|
| 6284 | + $reshook = $hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
|
|
| 6285 | 6285 | if (empty($reshook)) {
|
| 6286 | 6286 | if (is_array($hookmanager->resArray) && count($hookmanager->resArray)) {
|
| 6287 | 6287 | $possiblelinks = array_merge($possiblelinks, $hookmanager->resArray); |
@@ -6299,7 +6299,7 @@ discard block |
||
| 6299 | 6299 | continue; |
| 6300 | 6300 | |
| 6301 | 6301 | if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
|
| 6302 | - print '<div id="' . $key . 'list"' . (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>'; |
|
| 6302 | + print '<div id="'.$key.'list"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '').'>'; |
|
| 6303 | 6303 | $sql = $possiblelink['sql']; |
| 6304 | 6304 | |
| 6305 | 6305 | $resqllist = $this->db->query($sql); |
@@ -6307,34 +6307,34 @@ discard block |
||
| 6307 | 6307 | $num = $this->db->num_rows($resqllist); |
| 6308 | 6308 | $i = 0; |
| 6309 | 6309 | |
| 6310 | - print '<br><form action="' . $_SERVER["PHP_SELF"] . '" method="POST" name="formlinked' . $key . '">'; |
|
| 6311 | - print '<input type="hidden" name="id" value="' . $object->id . '">'; |
|
| 6310 | + print '<br><form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formlinked'.$key.'">'; |
|
| 6311 | + print '<input type="hidden" name="id" value="'.$object->id.'">'; |
|
| 6312 | 6312 | print '<input type="hidden" name="action" value="addlink">'; |
| 6313 | - print '<input type="hidden" name="addlink" value="' . $key . '">'; |
|
| 6313 | + print '<input type="hidden" name="addlink" value="'.$key.'">'; |
|
| 6314 | 6314 | print '<table class="noborder">'; |
| 6315 | 6315 | print '<tr class="liste_titre">'; |
| 6316 | 6316 | print '<td class="nowrap"></td>'; |
| 6317 | - print '<td align="center">' . $langs->trans("Ref") . '</td>';
|
|
| 6318 | - print '<td align="left">' . $langs->trans("RefCustomer") . '</td>';
|
|
| 6319 | - print '<td align="right">' . $langs->trans("AmountHTShort") . '</td>';
|
|
| 6320 | - print '<td align="left">' . $langs->trans("Company") . '</td>';
|
|
| 6317 | + print '<td align="center">'.$langs->trans("Ref").'</td>';
|
|
| 6318 | + print '<td align="left">'.$langs->trans("RefCustomer").'</td>';
|
|
| 6319 | + print '<td align="right">'.$langs->trans("AmountHTShort").'</td>';
|
|
| 6320 | + print '<td align="left">'.$langs->trans("Company").'</td>';
|
|
| 6321 | 6321 | print '</tr>'; |
| 6322 | 6322 | while ($i < $num) {
|
| 6323 | 6323 | $objp = $this->db->fetch_object($resqllist); |
| 6324 | 6324 | |
| 6325 | 6325 | print '<tr class="oddeven">'; |
| 6326 | 6326 | print '<td aling="left">'; |
| 6327 | - print '<input type="radio" name="idtolinkto" value=' . $objp->rowid . '>'; |
|
| 6327 | + print '<input type="radio" name="idtolinkto" value='.$objp->rowid.'>'; |
|
| 6328 | 6328 | print '</td>'; |
| 6329 | - print '<td align="center">' . $objp->ref . '</td>'; |
|
| 6330 | - print '<td>' . $objp->ref_client . '</td>'; |
|
| 6331 | - print '<td align="right">' . price($objp->total_ht) . '</td>'; |
|
| 6332 | - print '<td>' . $objp->name . '</td>'; |
|
| 6329 | + print '<td align="center">'.$objp->ref.'</td>'; |
|
| 6330 | + print '<td>'.$objp->ref_client.'</td>'; |
|
| 6331 | + print '<td align="right">'.price($objp->total_ht).'</td>'; |
|
| 6332 | + print '<td>'.$objp->name.'</td>'; |
|
| 6333 | 6333 | print '</tr>'; |
| 6334 | 6334 | $i++; |
| 6335 | 6335 | } |
| 6336 | 6336 | print '</table>'; |
| 6337 | - print '<div class="center"><input type="submit" class="button valignmiddle" value="' . $langs->trans('ToLink') . '"> <input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>';
|
|
| 6337 | + print '<div class="center"><input type="submit" class="button valignmiddle" value="'.$langs->trans('ToLink').'"> <input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></div>';
|
|
| 6338 | 6338 | |
| 6339 | 6339 | print '</form>'; |
| 6340 | 6340 | $this->db->free($resqllist); |
@@ -6348,20 +6348,20 @@ discard block |
||
| 6348 | 6348 | |
| 6349 | 6349 | //$linktoelem.=($linktoelem?' ':''); |
| 6350 | 6350 | if ($num > 0) |
| 6351 | - $linktoelemlist .= '<li><a href="#linkto' . $key . '" class="linkto dropdowncloseonclick" rel="' . $key . '">' . $langs->trans($possiblelink['label']) . ' (' . $num . ')</a></li>';
|
|
| 6351 | + $linktoelemlist .= '<li><a href="#linkto'.$key.'" class="linkto dropdowncloseonclick" rel="'.$key.'">'.$langs->trans($possiblelink['label']).' ('.$num.')</a></li>';
|
|
| 6352 | 6352 | //else $linktoelem.=$langs->trans($possiblelink['label']); |
| 6353 | 6353 | else |
| 6354 | - $linktoelemlist .= '<li><span class="linktodisabled">' . $langs->trans($possiblelink['label']) . ' (0)</span></li>'; |
|
| 6354 | + $linktoelemlist .= '<li><span class="linktodisabled">'.$langs->trans($possiblelink['label']).' (0)</span></li>'; |
|
| 6355 | 6355 | } |
| 6356 | 6356 | } |
| 6357 | 6357 | |
| 6358 | 6358 | if ($linktoelemlist) {
|
| 6359 | 6359 | $linktoelem = ' |
| 6360 | 6360 | <dl class="dropdown" id="linktoobjectname"> |
| 6361 | - <dt><a href="#linktoobjectname">' . $langs->trans("LinkTo") . '...</a></dt>
|
|
| 6361 | + <dt><a href="#linktoobjectname">' . $langs->trans("LinkTo").'...</a></dt>
|
|
| 6362 | 6362 | <dd> |
| 6363 | 6363 | <div class="multiselectlinkto"> |
| 6364 | - <ul class="ulselectedfields">' . $linktoelemlist . ' |
|
| 6364 | + <ul class="ulselectedfields">' . $linktoelemlist.' |
|
| 6365 | 6365 | </ul> |
| 6366 | 6366 | </div> |
| 6367 | 6367 | </dd> |
@@ -6408,18 +6408,18 @@ discard block |
||
| 6408 | 6408 | |
| 6409 | 6409 | $disabled = ($disabled ? ' disabled' : ''); |
| 6410 | 6410 | |
| 6411 | - $resultyesno = '<select class="flat width75" id="' . $htmlname . '" name="' . $htmlname . '"' . $disabled . '>' . "\n"; |
|
| 6411 | + $resultyesno = '<select class="flat width75" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n"; |
|
| 6412 | 6412 | if ($useempty) |
| 6413 | - $resultyesno .= '<option value="-1"' . (($value < 0) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 6413 | + $resultyesno .= '<option value="-1"'.(($value < 0) ? ' selected' : '').'> </option>'."\n"; |
|
| 6414 | 6414 | if (("$value" == 'yes') || ($value == 1)) {
|
| 6415 | - $resultyesno .= '<option value="' . $yes . '" selected>' . $langs->trans("Yes") . '</option>' . "\n";
|
|
| 6416 | - $resultyesno .= '<option value="' . $no . '">' . $langs->trans("No") . '</option>' . "\n";
|
|
| 6415 | + $resultyesno .= '<option value="'.$yes.'" selected>'.$langs->trans("Yes").'</option>'."\n";
|
|
| 6416 | + $resultyesno .= '<option value="'.$no.'">'.$langs->trans("No").'</option>'."\n";
|
|
| 6417 | 6417 | } else {
|
| 6418 | 6418 | $selected = (($useempty && $value != '0' && $value != 'no') ? '' : ' selected'); |
| 6419 | - $resultyesno .= '<option value="' . $yes . '">' . $langs->trans("Yes") . '</option>' . "\n";
|
|
| 6420 | - $resultyesno .= '<option value="' . $no . '"' . $selected . '>' . $langs->trans("No") . '</option>' . "\n";
|
|
| 6419 | + $resultyesno .= '<option value="'.$yes.'">'.$langs->trans("Yes").'</option>'."\n";
|
|
| 6420 | + $resultyesno .= '<option value="'.$no.'"'.$selected.'>'.$langs->trans("No").'</option>'."\n";
|
|
| 6421 | 6421 | } |
| 6422 | - $resultyesno .= '</select>' . "\n"; |
|
| 6422 | + $resultyesno .= '</select>'."\n"; |
|
| 6423 | 6423 | return $resultyesno; |
| 6424 | 6424 | } |
| 6425 | 6425 | |
@@ -6437,12 +6437,12 @@ discard block |
||
| 6437 | 6437 | {
|
| 6438 | 6438 | // phpcs:enable |
| 6439 | 6439 | $sql = "SELECT rowid, label"; |
| 6440 | - $sql .= " FROM " . MAIN_DB_PREFIX . "export_model"; |
|
| 6441 | - $sql .= " WHERE type = '" . $type . "'"; |
|
| 6440 | + $sql .= " FROM ".MAIN_DB_PREFIX."export_model"; |
|
| 6441 | + $sql .= " WHERE type = '".$type."'"; |
|
| 6442 | 6442 | $sql .= " ORDER BY rowid"; |
| 6443 | 6443 | $result = $this->db->query($sql); |
| 6444 | 6444 | if ($result) {
|
| 6445 | - print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
|
| 6445 | + print '<select class="flat" id="select_'.$htmlname.'" name="'.$htmlname.'">'; |
|
| 6446 | 6446 | if ($useempty) {
|
| 6447 | 6447 | print '<option value="-1"> </option>'; |
| 6448 | 6448 | } |
@@ -6452,9 +6452,9 @@ discard block |
||
| 6452 | 6452 | while ($i < $num) {
|
| 6453 | 6453 | $obj = $this->db->fetch_object($result); |
| 6454 | 6454 | if ($selected == $obj->rowid) {
|
| 6455 | - print '<option value="' . $obj->rowid . '" selected>'; |
|
| 6455 | + print '<option value="'.$obj->rowid.'" selected>'; |
|
| 6456 | 6456 | } else {
|
| 6457 | - print '<option value="' . $obj->rowid . '">'; |
|
| 6457 | + print '<option value="'.$obj->rowid.'">'; |
|
| 6458 | 6458 | } |
| 6459 | 6459 | print $obj->label; |
| 6460 | 6460 | print '</option>'; |
@@ -6497,7 +6497,7 @@ discard block |
||
| 6497 | 6497 | // Add where from hooks |
| 6498 | 6498 | if (is_object($hookmanager)) {
|
| 6499 | 6499 | $parameters = array(); |
| 6500 | - $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
|
|
| 6500 | + $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
|
|
| 6501 | 6501 | $object->next_prev_filter .= $hookmanager->resPrint; |
| 6502 | 6502 | } |
| 6503 | 6503 | $previous_ref = $next_ref = ''; |
@@ -6523,8 +6523,8 @@ discard block |
||
| 6523 | 6523 | $stringforfirstkey .= ' CTL +'; |
| 6524 | 6524 | } |
| 6525 | 6525 | |
| 6526 | - $previous_ref = $object->ref_previous ? '<a accesskey="p" title="' . $stringforfirstkey . ' p" class="classfortooltip" href="' . $navurl . '?' . $paramid . '=' . urlencode($object->ref_previous) . $moreparam . '"><i class="fa fa-chevron-left"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>'; |
|
| 6527 | - $next_ref = $object->ref_next ? '<a accesskey="n" title="' . $stringforfirstkey . ' n" class="classfortooltip" href="' . $navurl . '?' . $paramid . '=' . urlencode($object->ref_next) . $moreparam . '"><i class="fa fa-chevron-right"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>'; |
|
| 6526 | + $previous_ref = $object->ref_previous ? '<a accesskey="p" title="'.$stringforfirstkey.' p" class="classfortooltip" href="'.$navurl.'?'.$paramid.'='.urlencode($object->ref_previous).$moreparam.'"><i class="fa fa-chevron-left"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-left opacitymedium"></i></span>'; |
|
| 6527 | + $next_ref = $object->ref_next ? '<a accesskey="n" title="'.$stringforfirstkey.' n" class="classfortooltip" href="'.$navurl.'?'.$paramid.'='.urlencode($object->ref_next).$moreparam.'"><i class="fa fa-chevron-right"></i></a>' : '<span class="inactive"><i class="fa fa-chevron-right opacitymedium"></i></span>'; |
|
| 6528 | 6528 | } |
| 6529 | 6529 | |
| 6530 | 6530 | //print "xx".$previous_ref."x".$next_ref; |
@@ -6532,30 +6532,30 @@ discard block |
||
| 6532 | 6532 | |
| 6533 | 6533 | // Right part of banner |
| 6534 | 6534 | if ($morehtmlright) |
| 6535 | - $ret .= '<div class="inline-block floatleft">' . $morehtmlright . '</div>'; |
|
| 6535 | + $ret .= '<div class="inline-block floatleft">'.$morehtmlright.'</div>'; |
|
| 6536 | 6536 | |
| 6537 | 6537 | if ($previous_ref || $next_ref || $morehtml) {
|
| 6538 | 6538 | $ret .= '<div class="pagination paginationref"><ul class="right">'; |
| 6539 | 6539 | } |
| 6540 | 6540 | if ($morehtml) {
|
| 6541 | - $ret .= '<li class="noborder litext">' . $morehtml . '</li>'; |
|
| 6541 | + $ret .= '<li class="noborder litext">'.$morehtml.'</li>'; |
|
| 6542 | 6542 | } |
| 6543 | 6543 | if ($shownav && ($previous_ref || $next_ref)) {
|
| 6544 | - $ret .= '<li class="pagination">' . $previous_ref . '</li>'; |
|
| 6545 | - $ret .= '<li class="pagination">' . $next_ref . '</li>'; |
|
| 6544 | + $ret .= '<li class="pagination">'.$previous_ref.'</li>'; |
|
| 6545 | + $ret .= '<li class="pagination">'.$next_ref.'</li>'; |
|
| 6546 | 6546 | } |
| 6547 | 6547 | if ($previous_ref || $next_ref || $morehtml) {
|
| 6548 | 6548 | $ret .= '</ul></div>'; |
| 6549 | 6549 | } |
| 6550 | 6550 | |
| 6551 | 6551 | $parameters = array(); |
| 6552 | - $reshook = $hookmanager->executeHooks('moreHtmlStatus', $parameters, $object); // Note that $action and $object may have been modified by hook
|
|
| 6552 | + $reshook = $hookmanager->executeHooks('moreHtmlStatus', $parameters, $object); // Note that $action and $object may have been modified by hook
|
|
| 6553 | 6553 | if (empty($reshook)) |
| 6554 | 6554 | $morehtmlstatus .= $hookmanager->resPrint; |
| 6555 | 6555 | else |
| 6556 | 6556 | $morehtmlstatus = $hookmanager->resPrint; |
| 6557 | 6557 | if ($morehtmlstatus) |
| 6558 | - $ret .= '<div class="statusref">' . $morehtmlstatus . '</div>'; |
|
| 6558 | + $ret .= '<div class="statusref">'.$morehtmlstatus.'</div>'; |
|
| 6559 | 6559 | |
| 6560 | 6560 | $parameters = array(); |
| 6561 | 6561 | $reshook = $hookmanager->executeHooks('moreHtmlRef', $parameters, $object); // Note that $action and $object may have been modified by hook
|
@@ -6567,29 +6567,29 @@ discard block |
||
| 6567 | 6567 | // Left part of banner |
| 6568 | 6568 | if ($morehtmlleft) {
|
| 6569 | 6569 | if ($conf->browser->layout == 'phone') |
| 6570 | - $ret .= '<div class="floatleft">' . $morehtmlleft . '</div>'; // class="center" to have photo in middle |
|
| 6570 | + $ret .= '<div class="floatleft">'.$morehtmlleft.'</div>'; // class="center" to have photo in middle |
|
| 6571 | 6571 | else |
| 6572 | - $ret .= '<div class="inline-block floatleft">' . $morehtmlleft . '</div>'; |
|
| 6572 | + $ret .= '<div class="inline-block floatleft">'.$morehtmlleft.'</div>'; |
|
| 6573 | 6573 | } |
| 6574 | 6574 | |
| 6575 | 6575 | //if ($conf->browser->layout == 'phone') $ret.='<div class="clearboth"></div>'; |
| 6576 | - $ret .= '<div class="inline-block floatleft valignmiddle refid' . (($shownav && ($previous_ref || $next_ref)) ? ' refidpadding' : '') . '">'; |
|
| 6576 | + $ret .= '<div class="inline-block floatleft valignmiddle refid'.(($shownav && ($previous_ref || $next_ref)) ? ' refidpadding' : '').'">'; |
|
| 6577 | 6577 | |
| 6578 | 6578 | // For thirdparty, contact, user, member, the ref is the id, so we show something else |
| 6579 | 6579 | if ($object->element == 'societe') {
|
| 6580 | 6580 | $ret .= dol_htmlentities($object->name); |
| 6581 | 6581 | } else if ($object->element == 'member') {
|
| 6582 | - $ret .= $object->ref . '<br>'; |
|
| 6582 | + $ret .= $object->ref.'<br>'; |
|
| 6583 | 6583 | $fullname = $object->getFullName($langs); |
| 6584 | 6584 | if ($object->morphy == 'mor' && $object->societe) {
|
| 6585 | - $ret .= dol_htmlentities($object->societe) . ((!empty($fullname) && $object->societe != $fullname) ? ' (' . dol_htmlentities($fullname) . ')' : '');
|
|
| 6585 | + $ret .= dol_htmlentities($object->societe).((!empty($fullname) && $object->societe != $fullname) ? ' ('.dol_htmlentities($fullname).')' : '');
|
|
| 6586 | 6586 | } else {
|
| 6587 | - $ret .= dol_htmlentities($fullname) . ((!empty($object->societe) && $object->societe != $fullname) ? ' (' . dol_htmlentities($object->societe) . ')' : '');
|
|
| 6587 | + $ret .= dol_htmlentities($fullname).((!empty($object->societe) && $object->societe != $fullname) ? ' ('.dol_htmlentities($object->societe).')' : '');
|
|
| 6588 | 6588 | } |
| 6589 | 6589 | } else if (in_array($object->element, array('contact', 'user', 'usergroup'))) {
|
| 6590 | 6590 | $ret .= dol_htmlentities($object->getFullName($langs)); |
| 6591 | 6591 | } else if (in_array($object->element, array('action', 'agenda'))) {
|
| 6592 | - $ret .= $object->ref . '<br>' . $object->label; |
|
| 6592 | + $ret .= $object->ref.'<br>'.$object->label; |
|
| 6593 | 6593 | } else if (in_array($object->element, array('adherent_type'))) {
|
| 6594 | 6594 | $ret .= $object->label; |
| 6595 | 6595 | } else if ($object->element == 'ecm_directories') {
|
@@ -6599,7 +6599,7 @@ discard block |
||
| 6599 | 6599 | |
| 6600 | 6600 | |
| 6601 | 6601 | if ($morehtmlref) {
|
| 6602 | - $ret .= ' ' . $morehtmlref; |
|
| 6602 | + $ret .= ' '.$morehtmlref; |
|
| 6603 | 6603 | } |
| 6604 | 6604 | $ret .= '</div>'; |
| 6605 | 6605 | |
@@ -6632,9 +6632,9 @@ discard block |
||
| 6632 | 6632 | } |
| 6633 | 6633 | |
| 6634 | 6634 | // Barcode image |
| 6635 | - $url = DOL_URL_ROOT . '/viewimage.php?modulepart=barcode&generator=' . urlencode($object->barcode_type_coder) . '&code=' . urlencode($object->barcode) . '&encoding=' . urlencode($object->barcode_type_code); |
|
| 6636 | - $out = '<!-- url barcode = ' . $url . ' -->'; |
|
| 6637 | - $out .= '<img src="' . $url . '">'; |
|
| 6635 | + $url = DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($object->barcode_type_coder).'&code='.urlencode($object->barcode).'&encoding='.urlencode($object->barcode_type_code); |
|
| 6636 | + $out = '<!-- url barcode = '.$url.' -->'; |
|
| 6637 | + $out .= '<img src="'.$url.'">'; |
|
| 6638 | 6638 | return $out; |
| 6639 | 6639 | } |
| 6640 | 6640 | |
@@ -6671,25 +6671,25 @@ discard block |
||
| 6671 | 6671 | $dir = $conf->societe->multidir_output[$entity]; |
| 6672 | 6672 | if (!empty($object->logo)) {
|
| 6673 | 6673 | if ((string) $imagesize == 'mini') |
| 6674 | - $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . getImageFileNameForSize($object->logo, '_mini'); // getImageFileNameForSize include the thumbs |
|
| 6674 | + $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_mini'); // getImageFileNameForSize include the thumbs |
|
| 6675 | 6675 | else if ((string) $imagesize == 'small') |
| 6676 | - $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . getImageFileNameForSize($object->logo, '_small'); |
|
| 6676 | + $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.getImageFileNameForSize($object->logo, '_small'); |
|
| 6677 | 6677 | else |
| 6678 | - $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . $object->logo; |
|
| 6679 | - $originalfile = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . $object->logo; |
|
| 6678 | + $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo; |
|
| 6679 | + $originalfile = get_exdir(0, 0, 0, 0, $object, 'thirdparty').'/logos/'.$object->logo; |
|
| 6680 | 6680 | } |
| 6681 | 6681 | $email = $object->email; |
| 6682 | 6682 | } |
| 6683 | 6683 | else if ($modulepart == 'contact') {
|
| 6684 | - $dir = $conf->societe->multidir_output[$entity] . '/contact'; |
|
| 6684 | + $dir = $conf->societe->multidir_output[$entity].'/contact'; |
|
| 6685 | 6685 | if (!empty($object->photo)) {
|
| 6686 | 6686 | if ((string) $imagesize == 'mini') |
| 6687 | - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6687 | + $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_mini'); |
|
| 6688 | 6688 | else if ((string) $imagesize == 'small') |
| 6689 | - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6689 | + $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.getImageFileNameForSize($object->photo, '_small'); |
|
| 6690 | 6690 | else |
| 6691 | - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . $object->photo; |
|
| 6692 | - $originalfile = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . $object->photo; |
|
| 6691 | + $file = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo; |
|
| 6692 | + $originalfile = get_exdir(0, 0, 0, 0, $object, 'contact').'/photos/'.$object->photo; |
|
| 6693 | 6693 | } |
| 6694 | 6694 | $email = $object->email; |
| 6695 | 6695 | $capture = 'user'; |
@@ -6698,15 +6698,15 @@ discard block |
||
| 6698 | 6698 | $dir = $conf->user->dir_output; |
| 6699 | 6699 | if (!empty($object->photo)) {
|
| 6700 | 6700 | if ((string) $imagesize == 'mini') |
| 6701 | - $file = get_exdir(0, 0, 0, 0, $object, 'user') . $object->id . '/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6701 | + $file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_mini'); |
|
| 6702 | 6702 | else if ((string) $imagesize == 'small') |
| 6703 | - $file = get_exdir(0, 0, 0, 0, $object, 'user') . $object->id . '/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6703 | + $file = get_exdir(0, 0, 0, 0, $object, 'user').$object->id.'/'.getImageFileNameForSize($object->photo, '_small'); |
|
| 6704 | 6704 | else |
| 6705 | - $file = get_exdir(0, 0, 0, 0, $object, 'user') . '/' . $object->id . '/' . $object->photo; |
|
| 6706 | - $originalfile = get_exdir(0, 0, 0, 0, $object, 'user') . '/' . $object->id . '/' . $object->photo; |
|
| 6705 | + $file = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo; |
|
| 6706 | + $originalfile = get_exdir(0, 0, 0, 0, $object, 'user').'/'.$object->id.'/'.$object->photo; |
|
| 6707 | 6707 | } |
| 6708 | 6708 | if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) |
| 6709 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 6709 | + $altfile = $object->id.".jpg"; // For backward compatibility |
|
| 6710 | 6710 | $email = $object->email; |
| 6711 | 6711 | $capture = 'user'; |
| 6712 | 6712 | } |
@@ -6714,15 +6714,15 @@ discard block |
||
| 6714 | 6714 | $dir = $conf->adherent->dir_output; |
| 6715 | 6715 | if (!empty($object->photo)) {
|
| 6716 | 6716 | if ((string) $imagesize == 'mini') |
| 6717 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6717 | + $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_mini'); |
|
| 6718 | 6718 | else if ((string) $imagesize == 'small') |
| 6719 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6719 | + $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.getImageFileNameForSize($object->photo, '_small'); |
|
| 6720 | 6720 | else |
| 6721 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; |
|
| 6722 | - $originalfile = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; |
|
| 6721 | + $file = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo; |
|
| 6722 | + $originalfile = get_exdir(0, 0, 0, 0, $object, 'member').'photos/'.$object->photo; |
|
| 6723 | 6723 | } |
| 6724 | 6724 | if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) |
| 6725 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 6725 | + $altfile = $object->id.".jpg"; // For backward compatibility |
|
| 6726 | 6726 | $email = $object->email; |
| 6727 | 6727 | $capture = 'user'; |
| 6728 | 6728 | } |
@@ -6731,15 +6731,15 @@ discard block |
||
| 6731 | 6731 | $dir = $conf->$modulepart->dir_output; |
| 6732 | 6732 | if (!empty($object->photo)) {
|
| 6733 | 6733 | if ((string) $imagesize == 'mini') |
| 6734 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6734 | + $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_mini'); |
|
| 6735 | 6735 | else if ((string) $imagesize == 'small') |
| 6736 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6736 | + $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.getImageFileNameForSize($object->photo, '_small'); |
|
| 6737 | 6737 | else |
| 6738 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . $object->photo; |
|
| 6739 | - $originalfile = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . $object->photo; |
|
| 6738 | + $file = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo; |
|
| 6739 | + $originalfile = get_exdir($id, 2, 0, 0, $object, $modulepart).'photos/'.$object->photo; |
|
| 6740 | 6740 | } |
| 6741 | 6741 | if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) |
| 6742 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 6742 | + $altfile = $object->id.".jpg"; // For backward compatibility |
|
| 6743 | 6743 | $email = $object->email; |
| 6744 | 6744 | } |
| 6745 | 6745 | |
@@ -6747,27 +6747,27 @@ discard block |
||
| 6747 | 6747 | $capture = $forcecapture; |
| 6748 | 6748 | |
| 6749 | 6749 | if ($dir) {
|
| 6750 | - if ($file && file_exists($dir . "/" . $file)) {
|
|
| 6750 | + if ($file && file_exists($dir."/".$file)) {
|
|
| 6751 | 6751 | if ($addlinktofullsize) {
|
| 6752 | - $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity=' . $entity); |
|
| 6752 | + $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity='.$entity); |
|
| 6753 | 6753 | if ($urladvanced) |
| 6754 | - $ret .= '<a href="' . $urladvanced . '">'; |
|
| 6754 | + $ret .= '<a href="'.$urladvanced.'">'; |
|
| 6755 | 6755 | else |
| 6756 | - $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 6756 | + $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">'; |
|
| 6757 | 6757 | } |
| 6758 | - $ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="Photo" id="photologo' . (preg_replace('/[^a-z]/i', '_', $file)) . '" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($file) . '&cache=' . $cache . '">';
|
|
| 6758 | + $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="Photo" id="photologo'.(preg_replace('/[^a-z]/i', '_', $file)).'" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($file).'&cache='.$cache.'">';
|
|
| 6759 | 6759 | if ($addlinktofullsize) |
| 6760 | 6760 | $ret .= '</a>'; |
| 6761 | 6761 | } |
| 6762 | - else if ($altfile && file_exists($dir . "/" . $altfile)) {
|
|
| 6762 | + else if ($altfile && file_exists($dir."/".$altfile)) {
|
|
| 6763 | 6763 | if ($addlinktofullsize) {
|
| 6764 | - $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity=' . $entity); |
|
| 6764 | + $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity='.$entity); |
|
| 6765 | 6765 | if ($urladvanced) |
| 6766 | - $ret .= '<a href="' . $urladvanced . '">'; |
|
| 6766 | + $ret .= '<a href="'.$urladvanced.'">'; |
|
| 6767 | 6767 | else |
| 6768 | - $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 6768 | + $ret .= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($originalfile).'&cache='.$cache.'">'; |
|
| 6769 | 6769 | } |
| 6770 | - $ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="Photo alt" id="photologo' . (preg_replace('/[^a-z]/i', '_', $file)) . '" class="' . $cssclass . '" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($altfile) . '&cache=' . $cache . '">';
|
|
| 6770 | + $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="Photo alt" id="photologo'.(preg_replace('/[^a-z]/i', '_', $file)).'" class="'.$cssclass.'" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$entity.'&file='.urlencode($altfile).'&cache='.$cache.'">';
|
|
| 6771 | 6771 | if ($addlinktofullsize) |
| 6772 | 6772 | $ret .= '</a>'; |
| 6773 | 6773 | } |
@@ -6791,10 +6791,10 @@ discard block |
||
| 6791 | 6791 | $ret .= '<!-- Put link to gravatar -->'; |
| 6792 | 6792 | //$defaultimg=urlencode(dol_buildpath($nophoto,3)); |
| 6793 | 6793 | $defaultimg = 'mm'; |
| 6794 | - $ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="Gravatar avatar" title="' . $email . ' Gravatar avatar" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="https://www.gravatar.com/avatar/' . dol_hash(strtolower(trim($email)), 3) . '?s=' . $width . '&d=' . $defaultimg . '">'; // gravatar need md5 hash |
|
| 6794 | + $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="Gravatar avatar" title="'.$email.' Gravatar avatar" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="https://www.gravatar.com/avatar/'.dol_hash(strtolower(trim($email)), 3).'?s='.$width.'&d='.$defaultimg.'">'; // gravatar need md5 hash |
|
| 6795 | 6795 | } else {
|
| 6796 | 6796 | //$ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="No photo" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="' . DOL_URL_ROOT . $nophoto . '">'; |
| 6797 | - $ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="No photo" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="' . DOL_BASE_URI . $nophoto . '">'; |
|
| 6797 | + $ret .= '<img class="photo'.$modulepart.($cssclass ? ' '.$cssclass : '').'" alt="No photo" '.($width ? ' width="'.$width.'"' : '').($height ? ' height="'.$height.'"' : '').' src="'.DOL_BASE_URI.$nophoto.'">'; |
|
| 6798 | 6798 | } |
| 6799 | 6799 | } |
| 6800 | 6800 | |
@@ -6804,13 +6804,13 @@ discard block |
||
| 6804 | 6804 | } |
| 6805 | 6805 | $ret .= '<table class="nobordernopadding centpercent">'; |
| 6806 | 6806 | if ($object->photo) {
|
| 6807 | - $ret .= '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> ' . $langs->trans("Delete") . '<br><br></td></tr>';
|
|
| 6807 | + $ret .= '<tr><td><input type="checkbox" class="flat photodelete" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
|
|
| 6808 | 6808 | } |
| 6809 | - $ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput"' . ($capture ? ' capture="' . $capture . '"' : '') . '></td></tr>'; |
|
| 6809 | + $ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput"'.($capture ? ' capture="'.$capture.'"' : '').'></td></tr>'; |
|
| 6810 | 6810 | $ret .= '</table>'; |
| 6811 | 6811 | } |
| 6812 | 6812 | } else |
| 6813 | - dol_print_error('', 'Call of showphoto with wrong parameters modulepart=' . $modulepart);
|
|
| 6813 | + dol_print_error('', 'Call of showphoto with wrong parameters modulepart='.$modulepart);
|
|
| 6814 | 6814 | |
| 6815 | 6815 | return $ret; |
| 6816 | 6816 | } |
@@ -6853,37 +6853,37 @@ discard block |
||
| 6853 | 6853 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 6854 | 6854 | $sql .= ", e.label"; |
| 6855 | 6855 | } |
| 6856 | - $sql .= " FROM " . MAIN_DB_PREFIX . "usergroup as ug "; |
|
| 6856 | + $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as ug "; |
|
| 6857 | 6857 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 6858 | - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=ug.entity"; |
|
| 6858 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=ug.entity"; |
|
| 6859 | 6859 | if ($force_entity) |
| 6860 | - $sql .= " WHERE ug.entity IN (0," . $force_entity . ")"; |
|
| 6860 | + $sql .= " WHERE ug.entity IN (0,".$force_entity.")"; |
|
| 6861 | 6861 | else |
| 6862 | 6862 | $sql .= " WHERE ug.entity IS NOT NULL"; |
| 6863 | 6863 | } |
| 6864 | 6864 | else {
|
| 6865 | - $sql .= " WHERE ug.entity IN (0," . $conf->entity . ")"; |
|
| 6865 | + $sql .= " WHERE ug.entity IN (0,".$conf->entity.")"; |
|
| 6866 | 6866 | } |
| 6867 | 6867 | if (is_array($exclude) && $excludeGroups) |
| 6868 | - $sql .= " AND ug.rowid NOT IN ('" . $excludeGroups . "')";
|
|
| 6868 | + $sql .= " AND ug.rowid NOT IN ('".$excludeGroups."')";
|
|
| 6869 | 6869 | if (is_array($include) && $includeGroups) |
| 6870 | - $sql .= " AND ug.rowid IN ('" . $includeGroups . "')";
|
|
| 6870 | + $sql .= " AND ug.rowid IN ('".$includeGroups."')";
|
|
| 6871 | 6871 | $sql .= " ORDER BY ug.nom ASC"; |
| 6872 | 6872 | |
| 6873 | - dol_syslog(get_class($this) . "::select_dolgroups", LOG_DEBUG); |
|
| 6873 | + dol_syslog(get_class($this)."::select_dolgroups", LOG_DEBUG); |
|
| 6874 | 6874 | $resql = $this->db->query($sql); |
| 6875 | 6875 | if ($resql) {
|
| 6876 | 6876 | // Enhance with select2 |
| 6877 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 6877 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; |
|
| 6878 | 6878 | $out .= ajax_combobox($htmlname); |
| 6879 | 6879 | |
| 6880 | - $out .= '<select class="flat minwidth200" id="' . $htmlname . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . ($disabled ? ' disabled' : '') . '>'; |
|
| 6880 | + $out .= '<select class="flat minwidth200" id="'.$htmlname.'" name="'.$htmlname.($multiple ? '[]' : '').'" '.($multiple ? 'multiple' : '').' '.($disabled ? ' disabled' : '').'>'; |
|
| 6881 | 6881 | |
| 6882 | 6882 | $num = $this->db->num_rows($resql); |
| 6883 | 6883 | $i = 0; |
| 6884 | 6884 | if ($num) {
|
| 6885 | 6885 | if ($show_empty && !$multiple) |
| 6886 | - $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 6886 | + $out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'> </option>'."\n"; |
|
| 6887 | 6887 | |
| 6888 | 6888 | while ($i < $num) {
|
| 6889 | 6889 | $obj = $this->db->fetch_object($resql); |
@@ -6891,17 +6891,17 @@ discard block |
||
| 6891 | 6891 | if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) |
| 6892 | 6892 | $disableline = 1; |
| 6893 | 6893 | |
| 6894 | - $out .= '<option value="' . $obj->rowid . '"'; |
|
| 6894 | + $out .= '<option value="'.$obj->rowid.'"'; |
|
| 6895 | 6895 | if ($disableline) |
| 6896 | 6896 | $out .= ' disabled'; |
| 6897 | - if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (!is_object($selected[0]) && in_array($obj->rowid, $selected) )) {
|
|
| 6897 | + if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (!is_object($selected[0]) && in_array($obj->rowid, $selected))) {
|
|
| 6898 | 6898 | $out .= ' selected'; |
| 6899 | 6899 | } |
| 6900 | 6900 | $out .= '>'; |
| 6901 | 6901 | |
| 6902 | 6902 | $out .= $obj->name; |
| 6903 | 6903 | if (!empty($conf->multicompany->enabled) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
|
| 6904 | - $out .= " (" . $obj->label . ")";
|
|
| 6904 | + $out .= " (".$obj->label.")";
|
|
| 6905 | 6905 | } |
| 6906 | 6906 | |
| 6907 | 6907 | $out .= '</option>'; |
@@ -6909,8 +6909,8 @@ discard block |
||
| 6909 | 6909 | } |
| 6910 | 6910 | } else {
|
| 6911 | 6911 | if ($show_empty) |
| 6912 | - $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '></option>' . "\n"; |
|
| 6913 | - $out .= '<option value="" disabled>' . $langs->trans("NoUserGroupDefined") . '</option>';
|
|
| 6912 | + $out .= '<option value="-1"'.(in_array(-1, $selected) ? ' selected' : '').'></option>'."\n"; |
|
| 6913 | + $out .= '<option value="" disabled>'.$langs->trans("NoUserGroupDefined").'</option>';
|
|
| 6914 | 6914 | } |
| 6915 | 6915 | $out .= '</select>'; |
| 6916 | 6916 | } |
@@ -6931,8 +6931,8 @@ discard block |
||
| 6931 | 6931 | global $conf, $langs; |
| 6932 | 6932 | |
| 6933 | 6933 | $out = '<div class="nowrap">'; |
| 6934 | - $out .= '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
|
|
| 6935 | - $out .= '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
|
|
| 6934 | + $out .= '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
|
|
| 6935 | + $out .= '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
|
|
| 6936 | 6936 | $out .= '</div>'; |
| 6937 | 6937 | |
| 6938 | 6938 | return $out; |
@@ -6957,12 +6957,12 @@ discard block |
||
| 6957 | 6957 | $("#checkallactions").click(function() {
|
| 6958 | 6958 | if($(this).is(\':checked\')){
|
| 6959 | 6959 | console.log("We check all");
|
| 6960 | - $(".' . $cssclass . '").prop(\'checked\', true).trigger(\'change\');
|
|
| 6960 | + $(".' . $cssclass.'").prop(\'checked\', true).trigger(\'change\');
|
|
| 6961 | 6961 | } |
| 6962 | 6962 | else |
| 6963 | 6963 | {
|
| 6964 | 6964 | console.log("We uncheck all");
|
| 6965 | - $(".' . $cssclass . '").prop(\'checked\', false).trigger(\'change\');
|
|
| 6965 | + $(".' . $cssclass.'").prop(\'checked\', false).trigger(\'change\');
|
|
| 6966 | 6966 | }' . "\n"; |
| 6967 | 6967 | if ($calljsfunction) |
| 6968 | 6968 | $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
|
@@ -7011,64 +7011,64 @@ discard block |
||
| 7011 | 7011 | {
|
| 7012 | 7012 | global $db, $conf, $langs, $user; |
| 7013 | 7013 | |
| 7014 | - $sql = 'SELECT rowid, label FROM ' . MAIN_DB_PREFIX . 'c_exp_tax_cat WHERE active = 1'; |
|
| 7015 | - $sql .= ' AND entity IN (0,' . getEntity('exp_tax_cat') . ')';
|
|
| 7014 | + $sql = 'SELECT rowid, label FROM '.MAIN_DB_PREFIX.'c_exp_tax_cat WHERE active = 1'; |
|
| 7015 | + $sql .= ' AND entity IN (0,'.getEntity('exp_tax_cat').')';
|
|
| 7016 | 7016 | if (!empty($excludeid)) |
| 7017 | - $sql .= ' AND rowid NOT IN (' . implode(',', $excludeid) . ')';
|
|
| 7017 | + $sql .= ' AND rowid NOT IN ('.implode(',', $excludeid).')';
|
|
| 7018 | 7018 | $sql .= ' ORDER BY label'; |
| 7019 | 7019 | |
| 7020 | 7020 | $resql = $db->query($sql); |
| 7021 | 7021 | if ($resql) {
|
| 7022 | - $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
|
| 7022 | + $out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">'; |
|
| 7023 | 7023 | if ($useempty) |
| 7024 | 7024 | $out .= '<option value="0"> </option>'; |
| 7025 | 7025 | |
| 7026 | 7026 | while ($obj = $db->fetch_object($resql)) {
|
| 7027 | - $out .= '<option ' . ($selected == $obj->rowid ? 'selected="selected"' : '') . ' value="' . $obj->rowid . '">' . $langs->trans($obj->label) . '</option>'; |
|
| 7027 | + $out .= '<option '.($selected == $obj->rowid ? 'selected="selected"' : '').' value="'.$obj->rowid.'">'.$langs->trans($obj->label).'</option>'; |
|
| 7028 | 7028 | } |
| 7029 | 7029 | $out .= '</select>'; |
| 7030 | 7030 | if (!empty($htmlname) && $user->admin) |
| 7031 | - $out .= ' ' . info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 7031 | + $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 7032 | 7032 | |
| 7033 | 7033 | if (!empty($target)) {
|
| 7034 | - $sql = "SELECT c.id FROM " . MAIN_DB_PREFIX . "c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; |
|
| 7034 | + $sql = "SELECT c.id FROM ".MAIN_DB_PREFIX."c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; |
|
| 7035 | 7035 | $resql = $db->query($sql); |
| 7036 | 7036 | if ($resql) {
|
| 7037 | 7037 | if ($db->num_rows($resql) > 0) {
|
| 7038 | 7038 | $obj = $db->fetch_object($resql); |
| 7039 | 7039 | $out .= '<script type="text/javascript"> |
| 7040 | 7040 | $(function() {
|
| 7041 | - $("select[name=' . $target . ']").on("change", function() {
|
|
| 7041 | + $("select[name=' . $target.']").on("change", function() {
|
|
| 7042 | 7042 | var current_val = $(this).val(); |
| 7043 | - if (current_val == ' . $obj->id . ') {';
|
|
| 7043 | + if (current_val == ' . $obj->id.') {';
|
|
| 7044 | 7044 | if (!empty($default_selected) || !empty($selected)) |
| 7045 | - $out .= '$("select[name=' . $htmlname . ']").val("' . ($default_selected > 0 ? $default_selected : $selected) . '");';
|
|
| 7045 | + $out .= '$("select[name='.$htmlname.']").val("'.($default_selected > 0 ? $default_selected : $selected).'");';
|
|
| 7046 | 7046 | |
| 7047 | 7047 | $out .= ' |
| 7048 | - $("select[name=' . $htmlname . ']").change();
|
|
| 7048 | + $("select[name=' . $htmlname.']").change();
|
|
| 7049 | 7049 | } |
| 7050 | 7050 | }); |
| 7051 | 7051 | |
| 7052 | - $("select[name=' . $htmlname . ']").change(function() {
|
|
| 7052 | + $("select[name=' . $htmlname.']").change(function() {
|
|
| 7053 | 7053 | |
| 7054 | - if ($("select[name=' . $target . ']").val() == ' . $obj->id . ') {
|
|
| 7054 | + if ($("select[name=' . $target.']").val() == '.$obj->id.') {
|
|
| 7055 | 7055 | // get price of kilometer to fill the unit price |
| 7056 | - var data = ' . json_encode($params) . '; |
|
| 7056 | + var data = ' . json_encode($params).'; |
|
| 7057 | 7057 | data.fk_c_exp_tax_cat = $(this).val(); |
| 7058 | 7058 | |
| 7059 | 7059 | $.ajax({
|
| 7060 | 7060 | method: "POST", |
| 7061 | 7061 | dataType: "json", |
| 7062 | 7062 | data: data, |
| 7063 | - url: "' . (DOL_URL_ROOT . '/expensereport/ajax/ajaxik.php') . '", |
|
| 7063 | + url: "' . (DOL_URL_ROOT.'/expensereport/ajax/ajaxik.php').'", |
|
| 7064 | 7064 | }).done(function( data, textStatus, jqXHR ) {
|
| 7065 | 7065 | console.log(data); |
| 7066 | 7066 | if (typeof data.up != "undefined") {
|
| 7067 | 7067 | $("input[name=value_unit]").val(data.up);
|
| 7068 | - $("select[name=' . $htmlname . ']").attr("title", data.title);
|
|
| 7068 | + $("select[name=' . $htmlname.']").attr("title", data.title);
|
|
| 7069 | 7069 | } else {
|
| 7070 | 7070 | $("input[name=value_unit]").val("");
|
| 7071 | - $("select[name=' . $htmlname . ']").attr("title", "");
|
|
| 7071 | + $("select[name=' . $htmlname.']").attr("title", "");
|
|
| 7072 | 7072 | } |
| 7073 | 7073 | }); |
| 7074 | 7074 | } |
@@ -7098,17 +7098,17 @@ discard block |
||
| 7098 | 7098 | {
|
| 7099 | 7099 | global $db, $conf, $langs; |
| 7100 | 7100 | |
| 7101 | - $sql = 'SELECT rowid, range_ik FROM ' . MAIN_DB_PREFIX . 'c_exp_tax_range'; |
|
| 7102 | - $sql .= ' WHERE entity = ' . $conf->entity . ' AND active = 1'; |
|
| 7101 | + $sql = 'SELECT rowid, range_ik FROM '.MAIN_DB_PREFIX.'c_exp_tax_range'; |
|
| 7102 | + $sql .= ' WHERE entity = '.$conf->entity.' AND active = 1'; |
|
| 7103 | 7103 | |
| 7104 | 7104 | $resql = $db->query($sql); |
| 7105 | 7105 | if ($resql) {
|
| 7106 | - $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
|
| 7106 | + $out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">'; |
|
| 7107 | 7107 | if ($useempty) |
| 7108 | 7108 | $out .= '<option value="0"></option>'; |
| 7109 | 7109 | |
| 7110 | 7110 | while ($obj = $db->fetch_object($resql)) {
|
| 7111 | - $out .= '<option ' . ($selected == $obj->rowid ? 'selected="selected"' : '') . ' value="' . $obj->rowid . '">' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>'; |
|
| 7111 | + $out .= '<option '.($selected == $obj->rowid ? 'selected="selected"' : '').' value="'.$obj->rowid.'">'.price($obj->range_ik, 0, $langs, 1, 0).'</option>'; |
|
| 7112 | 7112 | } |
| 7113 | 7113 | $out .= '</select>'; |
| 7114 | 7114 | } else {
|
@@ -7132,16 +7132,16 @@ discard block |
||
| 7132 | 7132 | {
|
| 7133 | 7133 | global $db, $langs; |
| 7134 | 7134 | |
| 7135 | - $sql = 'SELECT id, code, label FROM ' . MAIN_DB_PREFIX . 'c_type_fees'; |
|
| 7135 | + $sql = 'SELECT id, code, label FROM '.MAIN_DB_PREFIX.'c_type_fees'; |
|
| 7136 | 7136 | $sql .= ' WHERE active = 1'; |
| 7137 | 7137 | |
| 7138 | 7138 | $resql = $db->query($sql); |
| 7139 | 7139 | if ($resql) {
|
| 7140 | - $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
|
| 7140 | + $out = '<select id="select_'.$htmlname.'" name="'.$htmlname.'" class="'.$htmlname.' flat minwidth75imp">'; |
|
| 7141 | 7141 | if ($useempty) |
| 7142 | 7142 | $out .= '<option value="0"></option>'; |
| 7143 | 7143 | if ($allchoice) |
| 7144 | - $out .= '<option value="-1">' . $langs->trans('AllExpenseReport') . '</option>';
|
|
| 7144 | + $out .= '<option value="-1">'.$langs->trans('AllExpenseReport').'</option>';
|
|
| 7145 | 7145 | |
| 7146 | 7146 | $field = 'code'; |
| 7147 | 7147 | if ($useid) |
@@ -7149,7 +7149,7 @@ discard block |
||
| 7149 | 7149 | |
| 7150 | 7150 | while ($obj = $db->fetch_object($resql)) {
|
| 7151 | 7151 | $key = $langs->trans($obj->code); |
| 7152 | - $out .= '<option ' . ($selected == $obj->{$field} ? 'selected="selected"' : '') . ' value="' . $obj->{$field} . '">' . ($key != $obj->code ? $key : $obj->label) . '</option>';
|
|
| 7152 | + $out .= '<option '.($selected == $obj->{$field} ? 'selected="selected"' : '').' value="'.$obj->{$field}.'">'.($key != $obj->code ? $key : $obj->label).'</option>';
|
|
| 7153 | 7153 | } |
| 7154 | 7154 | $out .= '</select>'; |
| 7155 | 7155 | } else {
|
@@ -112,22 +112,24 @@ discard block |
||
| 112 | 112 | if (!empty($perm)) {
|
| 113 | 113 | $tmp = explode(':', $typeofdata);
|
| 114 | 114 | $ret .= '<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ? ' ' . $tmp[1] : '') . '" id="' . $htmlname . '">'; |
| 115 | - if ($fieldrequired) |
|
| 116 | - $ret .= '<span class="fieldrequired">'; |
|
| 115 | + if ($fieldrequired) { |
|
| 116 | + $ret .= '<span class="fieldrequired">'; |
|
| 117 | + } |
|
| 117 | 118 | $ret .= $langs->trans($text); |
| 118 | - if ($fieldrequired) |
|
| 119 | - $ret .= '</span>'; |
|
| 119 | + if ($fieldrequired) { |
|
| 120 | + $ret .= '</span>'; |
|
| 121 | + } |
|
| 120 | 122 | $ret .= '</div>' . "\n"; |
| 121 | - } |
|
| 122 | - else {
|
|
| 123 | - if ($fieldrequired) |
|
| 124 | - $ret .= '<span class="fieldrequired">'; |
|
| 123 | + } else {
|
|
| 124 | + if ($fieldrequired) { |
|
| 125 | + $ret .= '<span class="fieldrequired">'; |
|
| 126 | + } |
|
| 125 | 127 | $ret .= $langs->trans($text); |
| 126 | - if ($fieldrequired) |
|
| 127 | - $ret .= '</span>'; |
|
| 128 | + if ($fieldrequired) { |
|
| 129 | + $ret .= '</span>'; |
|
| 130 | + } |
|
| 128 | 131 | } |
| 129 | - } |
|
| 130 | - else {
|
|
| 132 | + } else {
|
|
| 131 | 133 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
| 132 | 134 | $ret .= '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">'; |
| 133 | 135 | } |
@@ -192,8 +194,9 @@ discard block |
||
| 192 | 194 | $ret = ''; |
| 193 | 195 | |
| 194 | 196 | // Check parameters |
| 195 | - if (empty($typeofdata)) |
|
| 196 | - return 'ErrorBadParameter'; |
|
| 197 | + if (empty($typeofdata)) { |
|
| 198 | + return 'ErrorBadParameter'; |
|
| 199 | + } |
|
| 197 | 200 | |
| 198 | 201 | // When option to edit inline is activated |
| 199 | 202 | if (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) { // TODO add jquery timepicker
|
@@ -205,10 +208,12 @@ discard block |
||
| 205 | 208 | $ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">'; |
| 206 | 209 | $ret .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
| 207 | 210 | $ret .= '<input type="hidden" name="' . $paramid . '" value="' . $object->id . '">'; |
| 208 | - if (empty($notabletag)) |
|
| 209 | - $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">'; |
|
| 210 | - if (empty($notabletag)) |
|
| 211 | - $ret .= '<tr><td>'; |
|
| 211 | + if (empty($notabletag)) { |
|
| 212 | + $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">'; |
|
| 213 | + } |
|
| 214 | + if (empty($notabletag)) { |
|
| 215 | + $ret .= '<tr><td>'; |
|
| 216 | + } |
|
| 212 | 217 | if (preg_match('/^(string|email)/', $typeofdata)) {
|
| 213 | 218 | $tmp = explode(':', $typeofdata);
|
| 214 | 219 | $ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ($editvalue ? $editvalue : $value) . '"' . ($tmp[1] ? ' size="' . $tmp[1] . '"' : '') . '>'; |
@@ -247,35 +252,39 @@ discard block |
||
| 247 | 252 | $doleditor = new DolEditor($htmlname, ($editvalue ? $editvalue : $value), ($tmp[2] ? $tmp[2] : ''), ($tmp[3] ? $tmp[3] : '100'), ($tmp[1] ? $tmp[1] : 'dolibarr_notes'), 'In', ($tmp[5] ? $tmp[5] : 0), true, true, ($tmp[6] ? $tmp[6] : '20'), ($tmp[7] ? $tmp[7] : '100')); |
| 248 | 253 | $ret .= $doleditor->Create(1); |
| 249 | 254 | } |
| 250 | - if (empty($notabletag)) |
|
| 251 | - $ret .= '</td>'; |
|
| 255 | + if (empty($notabletag)) { |
|
| 256 | + $ret .= '</td>'; |
|
| 257 | + } |
|
| 252 | 258 | |
| 253 | - if (empty($notabletag)) |
|
| 254 | - $ret .= '<td align="left">'; |
|
| 259 | + if (empty($notabletag)) { |
|
| 260 | + $ret .= '<td align="left">'; |
|
| 261 | + } |
|
| 255 | 262 | //else $ret.='<div class="clearboth"></div>'; |
| 256 | 263 | $ret .= '<input type="submit" class="button' . (empty($notabletag) ? '' : ' ') . '" name="modify" value="' . $langs->trans("Modify") . '">';
|
| 257 | - if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag))
|
|
| 258 | - $ret .= '<br>' . "\n"; |
|
| 264 | + if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) { |
|
| 265 | + $ret .= '<br>' . "\n"; |
|
| 266 | + } |
|
| 259 | 267 | $ret .= '<input type="submit" class="button' . (empty($notabletag) ? '' : ' ') . '" name="cancel" value="' . $langs->trans("Cancel") . '">';
|
| 260 | - if (empty($notabletag)) |
|
| 261 | - $ret .= '</td>'; |
|
| 268 | + if (empty($notabletag)) { |
|
| 269 | + $ret .= '</td>'; |
|
| 270 | + } |
|
| 262 | 271 | |
| 263 | - if (empty($notabletag)) |
|
| 264 | - $ret .= '</tr></table>' . "\n"; |
|
| 272 | + if (empty($notabletag)) { |
|
| 273 | + $ret .= '</tr></table>' . "\n"; |
|
| 274 | + } |
|
| 265 | 275 | $ret .= '</form>' . "\n"; |
| 266 | - } |
|
| 267 | - else {
|
|
| 268 | - if (preg_match('/^(email)/', $typeofdata))
|
|
| 269 | - $ret .= dol_print_email($value, 0, 0, 0, 0, 1); |
|
| 270 | - elseif (preg_match('/^(amount|numeric)/', $typeofdata))
|
|
| 271 | - $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : ''); |
|
| 272 | - elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata))
|
|
| 273 | - $ret .= dol_htmlentitiesbr($value); |
|
| 274 | - elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') |
|
| 275 | - $ret .= dol_print_date($value, 'day'); |
|
| 276 | - elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') |
|
| 277 | - $ret .= dol_print_date($value, 'dayhour'); |
|
| 278 | - else if (preg_match('/^select;/', $typeofdata)) {
|
|
| 276 | + } else {
|
|
| 277 | + if (preg_match('/^(email)/', $typeofdata)) { |
|
| 278 | + $ret .= dol_print_email($value, 0, 0, 0, 0, 1); |
|
| 279 | + } elseif (preg_match('/^(amount|numeric)/', $typeofdata)) { |
|
| 280 | + $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, $conf->currency) : ''); |
|
| 281 | + } elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) { |
|
| 282 | + $ret .= dol_htmlentitiesbr($value); |
|
| 283 | + } elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') { |
|
| 284 | + $ret .= dol_print_date($value, 'day'); |
|
| 285 | + } elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') { |
|
| 286 | + $ret .= dol_print_date($value, 'dayhour'); |
|
| 287 | + } else if (preg_match('/^select;/', $typeofdata)) {
|
|
| 279 | 288 | $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata));
|
| 280 | 289 | foreach ($arraydata as $val) {
|
| 281 | 290 | $tmp = explode(':', $val);
|
@@ -290,8 +299,9 @@ discard block |
||
| 290 | 299 | $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ? '...' : ''); |
| 291 | 300 | } |
| 292 | 301 | $ret .= $tmpcontent; |
| 293 | - } else |
|
| 294 | - $ret .= $value; |
|
| 302 | + } else { |
|
| 303 | + $ret .= $value; |
|
| 304 | + } |
|
| 295 | 305 | |
| 296 | 306 | if ($formatfunc && method_exists($object, $formatfunc)) {
|
| 297 | 307 | $ret = $object->$formatfunc($ret); |
@@ -321,12 +331,13 @@ discard block |
||
| 321 | 331 | $out = ''; |
| 322 | 332 | |
| 323 | 333 | // Check parameters |
| 324 | - if (preg_match('/^text/', $inputType))
|
|
| 325 | - $value = dol_nl2br($value); |
|
| 326 | - else if (preg_match('/^numeric/', $inputType))
|
|
| 327 | - $value = price($value); |
|
| 328 | - else if ($inputType == 'day' || $inputType == 'datepicker') |
|
| 329 | - $value = dol_print_date($value, 'day'); |
|
| 334 | + if (preg_match('/^text/', $inputType)) { |
|
| 335 | + $value = dol_nl2br($value); |
|
| 336 | + } else if (preg_match('/^numeric/', $inputType)) { |
|
| 337 | + $value = price($value); |
|
| 338 | + } else if ($inputType == 'day' || $inputType == 'datepicker') { |
|
| 339 | + $value = dol_print_date($value, 'day'); |
|
| 340 | + } |
|
| 330 | 341 | |
| 331 | 342 | if ($condition) {
|
| 332 | 343 | $element = false; |
@@ -351,32 +362,35 @@ discard block |
||
| 351 | 362 | if (preg_match('/^(string|email|numeric)/', $inputType)) {
|
| 352 | 363 | $tmp = explode(':', $inputType);
|
| 353 | 364 | $inputType = $tmp[0]; |
| 354 | - if (!empty($tmp[1])) |
|
| 355 | - $inputOption = $tmp[1]; |
|
| 356 | - if (!empty($tmp[2])) |
|
| 357 | - $savemethod = $tmp[2]; |
|
| 365 | + if (!empty($tmp[1])) { |
|
| 366 | + $inputOption = $tmp[1]; |
|
| 367 | + } |
|
| 368 | + if (!empty($tmp[2])) { |
|
| 369 | + $savemethod = $tmp[2]; |
|
| 370 | + } |
|
| 358 | 371 | $out .= '<input id="width_' . $htmlname . '" value="' . $inputOption . '" type="hidden"/>' . "\n"; |
| 359 | - } |
|
| 360 | - else if ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) {
|
|
| 372 | + } else if ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) {
|
|
| 361 | 373 | $tmp = explode(':', $inputType);
|
| 362 | 374 | $inputType = $tmp[0]; |
| 363 | - if (!empty($tmp[1])) |
|
| 364 | - $inputOption = $tmp[1]; |
|
| 365 | - if (!empty($tmp[2])) |
|
| 366 | - $savemethod = $tmp[2]; |
|
| 375 | + if (!empty($tmp[1])) { |
|
| 376 | + $inputOption = $tmp[1]; |
|
| 377 | + } |
|
| 378 | + if (!empty($tmp[2])) { |
|
| 379 | + $savemethod = $tmp[2]; |
|
| 380 | + } |
|
| 367 | 381 | |
| 368 | 382 | $out .= '<input id="timestamp" type="hidden"/>' . "\n"; // Use for timestamp format |
| 369 | - } |
|
| 370 | - else if (preg_match('/^(select|autocomplete)/', $inputType)) {
|
|
| 383 | + } else if (preg_match('/^(select|autocomplete)/', $inputType)) {
|
|
| 371 | 384 | $tmp = explode(':', $inputType);
|
| 372 | 385 | $inputType = $tmp[0]; |
| 373 | 386 | $loadmethod = $tmp[1]; |
| 374 | - if (!empty($tmp[2])) |
|
| 375 | - $savemethod = $tmp[2]; |
|
| 376 | - if (!empty($tmp[3])) |
|
| 377 | - $button_only = true; |
|
| 378 | - } |
|
| 379 | - else if (preg_match('/^textarea/', $inputType)) {
|
|
| 387 | + if (!empty($tmp[2])) { |
|
| 388 | + $savemethod = $tmp[2]; |
|
| 389 | + } |
|
| 390 | + if (!empty($tmp[3])) { |
|
| 391 | + $button_only = true; |
|
| 392 | + } |
|
| 393 | + } else if (preg_match('/^textarea/', $inputType)) {
|
|
| 380 | 394 | $tmp = explode(':', $inputType);
|
| 381 | 395 | $inputType = $tmp[0]; |
| 382 | 396 | $rows = (empty($tmp[1]) ? '8' : $tmp[1]); |
@@ -385,12 +399,15 @@ discard block |
||
| 385 | 399 | $tmp = explode(':', $inputType);
|
| 386 | 400 | $inputType = $tmp[0]; |
| 387 | 401 | $toolbar = $tmp[1]; |
| 388 | - if (!empty($tmp[2])) |
|
| 389 | - $width = $tmp[2]; |
|
| 390 | - if (!empty($tmp[3])) |
|
| 391 | - $heigth = $tmp[3]; |
|
| 392 | - if (!empty($tmp[4])) |
|
| 393 | - $savemethod = $tmp[4]; |
|
| 402 | + if (!empty($tmp[2])) { |
|
| 403 | + $width = $tmp[2]; |
|
| 404 | + } |
|
| 405 | + if (!empty($tmp[3])) { |
|
| 406 | + $heigth = $tmp[3]; |
|
| 407 | + } |
|
| 408 | + if (!empty($tmp[4])) { |
|
| 409 | + $savemethod = $tmp[4]; |
|
| 410 | + } |
|
| 394 | 411 | |
| 395 | 412 | if (!empty($conf->fckeditor->enabled)) {
|
| 396 | 413 | $out .= '<input id="ckeditor_toolbar" value="' . $toolbar . '" type="hidden"/>' . "\n"; |
@@ -403,18 +420,23 @@ discard block |
||
| 403 | 420 | $out .= '<input id="table_element_' . $htmlname . '" value="' . $table_element . '" type="hidden"/>' . "\n"; |
| 404 | 421 | $out .= '<input id="fk_element_' . $htmlname . '" value="' . $fk_element . '" type="hidden"/>' . "\n"; |
| 405 | 422 | $out .= '<input id="loadmethod_' . $htmlname . '" value="' . $loadmethod . '" type="hidden"/>' . "\n"; |
| 406 | - if (!empty($savemethod)) |
|
| 407 | - $out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . "\n"; |
|
| 408 | - if (!empty($ext_element)) |
|
| 409 | - $out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . "\n"; |
|
| 423 | + if (!empty($savemethod)) { |
|
| 424 | + $out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . "\n"; |
|
| 425 | + } |
|
| 426 | + if (!empty($ext_element)) { |
|
| 427 | + $out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . "\n"; |
|
| 428 | + } |
|
| 410 | 429 | if (!empty($custommsg)) {
|
| 411 | 430 | if (is_array($custommsg)) {
|
| 412 | - if (!empty($custommsg['success'])) |
|
| 413 | - $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg['success'] . '" type="hidden"/>' . "\n"; |
|
| 414 | - if (!empty($custommsg['error'])) |
|
| 415 | - $out .= '<input id="errormsg_' . $htmlname . '" value="' . $custommsg['error'] . '" type="hidden"/>' . "\n"; |
|
| 416 | - } else |
|
| 417 | - $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg . '" type="hidden"/>' . "\n"; |
|
| 431 | + if (!empty($custommsg['success'])) { |
|
| 432 | + $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg['success'] . '" type="hidden"/>' . "\n"; |
|
| 433 | + } |
|
| 434 | + if (!empty($custommsg['error'])) { |
|
| 435 | + $out .= '<input id="errormsg_' . $htmlname . '" value="' . $custommsg['error'] . '" type="hidden"/>' . "\n"; |
|
| 436 | + } |
|
| 437 | + } else { |
|
| 438 | + $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg . '" type="hidden"/>' . "\n"; |
|
| 439 | + } |
|
| 418 | 440 | } |
| 419 | 441 | if ($inputType == 'textarea') {
|
| 420 | 442 | $out .= '<input id="textarea_' . $htmlname . '_rows" value="' . $rows . '" type="hidden"/>' . "\n"; |
@@ -566,20 +588,22 @@ discard block |
||
| 566 | 588 | global $conf, $langs; |
| 567 | 589 | |
| 568 | 590 | $alt = ''; |
| 569 | - if ($tooltiptrigger) |
|
| 570 | - $alt = $langs->transnoentitiesnoconv("ClickToShowHelp");
|
|
| 591 | + if ($tooltiptrigger) { |
|
| 592 | + $alt = $langs->transnoentitiesnoconv("ClickToShowHelp"); |
|
| 593 | + } |
|
| 571 | 594 | |
| 572 | 595 | //For backwards compatibility |
| 573 | - if ($type == '0') |
|
| 574 | - $type = 'info'; |
|
| 575 | - elseif ($type == '1') |
|
| 576 | - $type = 'help'; |
|
| 596 | + if ($type == '0') { |
|
| 597 | + $type = 'info'; |
|
| 598 | + } elseif ($type == '1') { |
|
| 599 | + $type = 'help'; |
|
| 600 | + } |
|
| 577 | 601 | |
| 578 | 602 | // If info or help with no javascript, show only text |
| 579 | 603 | if (empty($conf->use_javascript_ajax)) {
|
| 580 | - if ($type == 'info' || $type == 'help') |
|
| 581 | - return $text; |
|
| 582 | - else {
|
|
| 604 | + if ($type == 'info' || $type == 'help') { |
|
| 605 | + return $text; |
|
| 606 | + } else {
|
|
| 583 | 607 | $alt = $htmltext; |
| 584 | 608 | $htmltext = ''; |
| 585 | 609 | } |
@@ -587,27 +611,30 @@ discard block |
||
| 587 | 611 | |
| 588 | 612 | // If info or help with smartphone, show only text (tooltip hover can't works) |
| 589 | 613 | if (!empty($conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
|
| 590 | - if ($type == 'info' || $type == 'help') |
|
| 591 | - return $text; |
|
| 614 | + if ($type == 'info' || $type == 'help') { |
|
| 615 | + return $text; |
|
| 616 | + } |
|
| 592 | 617 | } |
| 593 | 618 | // If info or help with smartphone, show only text (tooltip on lick does not works with dialog on smaprtphone) |
| 594 | 619 | if (!empty($conf->dol_no_mouse_hover) && !empty($tooltiptrigger)) {
|
| 595 | - if ($type == 'info' || $type == 'help') |
|
| 596 | - return $text; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - if ($type == 'info') |
|
| 600 | - $img = img_help(0, $alt); |
|
| 601 | - elseif ($type == 'help') |
|
| 602 | - $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt); |
|
| 603 | - elseif ($type == 'superadmin') |
|
| 604 | - $img = img_picto($alt, 'redstar'); |
|
| 605 | - elseif ($type == 'admin') |
|
| 606 | - $img = img_picto($alt, 'star'); |
|
| 607 | - elseif ($type == 'warning') |
|
| 608 | - $img = img_warning($alt); |
|
| 609 | - else |
|
| 610 | - $img = img_picto($alt, $type); |
|
| 620 | + if ($type == 'info' || $type == 'help') { |
|
| 621 | + return $text; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if ($type == 'info') { |
|
| 626 | + $img = img_help(0, $alt); |
|
| 627 | + } elseif ($type == 'help') { |
|
| 628 | + $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt); |
|
| 629 | + } elseif ($type == 'superadmin') { |
|
| 630 | + $img = img_picto($alt, 'redstar'); |
|
| 631 | + } elseif ($type == 'admin') { |
|
| 632 | + $img = img_picto($alt, 'star'); |
|
| 633 | + } elseif ($type == 'warning') { |
|
| 634 | + $img = img_warning($alt); |
|
| 635 | + } else { |
|
| 636 | + $img = img_picto($alt, $type); |
|
| 637 | + } |
|
| 611 | 638 | |
| 612 | 639 | return $this->textwithtooltip($text, $htmltext, (($tooltiptrigger && !$img) ? 3 : 2), $direction, $img, $extracss, $notabs, '', $noencodehtmltext, $tooltiptrigger, $forcenowrap); |
| 613 | 640 | } |
@@ -624,8 +651,9 @@ discard block |
||
| 624 | 651 | {
|
| 625 | 652 | global $conf, $langs, $hookmanager; |
| 626 | 653 | |
| 627 | - if (count($arrayofaction) == 0) |
|
| 628 | - return; |
|
| 654 | + if (count($arrayofaction) == 0) { |
|
| 655 | + return; |
|
| 656 | + } |
|
| 629 | 657 | |
| 630 | 658 | $disabled = 0; |
| 631 | 659 | $ret = '<div class="centpercent center">'; |
@@ -757,10 +785,11 @@ discard block |
||
| 757 | 785 | $i++; |
| 758 | 786 | } |
| 759 | 787 | |
| 760 | - if (empty($disablefavorites)) |
|
| 761 | - array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray); |
|
| 762 | - else |
|
| 763 | - $countryArray = dol_sort_array($countryArray, 'label'); |
|
| 788 | + if (empty($disablefavorites)) { |
|
| 789 | + array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray); |
|
| 790 | + } else { |
|
| 791 | + $countryArray = dol_sort_array($countryArray, 'label'); |
|
| 792 | + } |
|
| 764 | 793 | |
| 765 | 794 | if ($showempty) {
|
| 766 | 795 | $out .= '<option value=""> </option>' . "\n"; |
@@ -770,8 +799,9 @@ discard block |
||
| 770 | 799 | //if ($showempty) $out.= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
| 771 | 800 | $out .= '<option value="special_allnotme"' . ($selected == 'special_allnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>';
|
| 772 | 801 | $out .= '<option value="special_eec"' . ($selected == 'special_eec' ? ' selected' : '') . '>' . $langs->trans("CountriesInEEC") . '</option>';
|
| 773 | - if ($mysoc->isInEEC()) |
|
| 774 | - $out .= '<option value="special_eecnotme"' . ($selected == 'special_eecnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>';
|
|
| 802 | + if ($mysoc->isInEEC()) { |
|
| 803 | + $out .= '<option value="special_eecnotme"' . ($selected == 'special_eecnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>'; |
|
| 804 | + } |
|
| 775 | 805 | $out .= '<option value="special_noteec"' . ($selected == 'special_noteec' ? ' selected' : '') . '>' . $langs->trans("CountriesNotInEEC") . '</option>';
|
| 776 | 806 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
| 777 | 807 | } |
@@ -782,8 +812,9 @@ discard block |
||
| 782 | 812 | continue; |
| 783 | 813 | } |
| 784 | 814 | |
| 785 | - if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) |
|
| 786 | - $atleastonefavorite++; |
|
| 815 | + if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) { |
|
| 816 | + $atleastonefavorite++; |
|
| 817 | + } |
|
| 787 | 818 | if (empty($row['favorite']) && $atleastonefavorite) {
|
| 788 | 819 | $atleastonefavorite = 0; |
| 789 | 820 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
@@ -794,18 +825,19 @@ discard block |
||
| 794 | 825 | } else {
|
| 795 | 826 | $out .= '<option value="' . ($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']) . '">'; |
| 796 | 827 | } |
| 797 | - if ($row['label']) |
|
| 798 | - $out .= dol_trunc($row['label'], $maxlength, 'middle'); |
|
| 799 | - else |
|
| 800 | - $out .= ' '; |
|
| 801 | - if ($row['code_iso']) |
|
| 802 | - $out .= ' (' . $row['code_iso'] . ')';
|
|
| 828 | + if ($row['label']) { |
|
| 829 | + $out .= dol_trunc($row['label'], $maxlength, 'middle'); |
|
| 830 | + } else { |
|
| 831 | + $out .= ' '; |
|
| 832 | + } |
|
| 833 | + if ($row['code_iso']) { |
|
| 834 | + $out .= ' (' . $row['code_iso'] . ')'; |
|
| 835 | + } |
|
| 803 | 836 | $out .= '</option>'; |
| 804 | 837 | } |
| 805 | 838 | } |
| 806 | 839 | $out .= '</select>'; |
| 807 | - } |
|
| 808 | - else {
|
|
| 840 | + } else {
|
|
| 809 | 841 | dol_print_error($this->db); |
| 810 | 842 | } |
| 811 | 843 | |
@@ -879,8 +911,9 @@ discard block |
||
| 879 | 911 | $out .= '<option value="' . $row['rowid'] . '">'; |
| 880 | 912 | } |
| 881 | 913 | |
| 882 | - if ($row['code']) |
|
| 883 | - $out .= $row['code']; |
|
| 914 | + if ($row['code']) { |
|
| 915 | + $out .= $row['code']; |
|
| 916 | + } |
|
| 884 | 917 | |
| 885 | 918 | $out .= '</option>'; |
| 886 | 919 | } |
@@ -918,24 +951,28 @@ discard block |
||
| 918 | 951 | |
| 919 | 952 | // If product & services are enabled or both disabled. |
| 920 | 953 | if ($forceall == 1 || (empty($forceall) && !empty($conf->product->enabled) && !empty($conf->service->enabled)) || (empty($forceall) && empty($conf->product->enabled) && empty($conf->service->enabled))) {
|
| 921 | - if (empty($hidetext)) |
|
| 922 | - print $langs->trans("Type") . ': ';
|
|
| 954 | + if (empty($hidetext)) { |
|
| 955 | + print $langs->trans("Type") . ': '; |
|
| 956 | + } |
|
| 923 | 957 | print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
| 924 | 958 | if ($showempty) {
|
| 925 | 959 | print '<option value="-1"'; |
| 926 | - if ($selected == -1) |
|
| 927 | - print ' selected'; |
|
| 960 | + if ($selected == -1) { |
|
| 961 | + print ' selected'; |
|
| 962 | + } |
|
| 928 | 963 | print '> </option>'; |
| 929 | 964 | } |
| 930 | 965 | |
| 931 | 966 | print '<option value="0"'; |
| 932 | - if (0 == $selected) |
|
| 933 | - print ' selected'; |
|
| 967 | + if (0 == $selected) { |
|
| 968 | + print ' selected'; |
|
| 969 | + } |
|
| 934 | 970 | print '>' . $langs->trans("Product");
|
| 935 | 971 | |
| 936 | 972 | print '<option value="1"'; |
| 937 | - if (1 == $selected) |
|
| 938 | - print ' selected'; |
|
| 973 | + if (1 == $selected) { |
|
| 974 | + print ' selected'; |
|
| 975 | + } |
|
| 939 | 976 | print '>' . $langs->trans("Service");
|
| 940 | 977 | |
| 941 | 978 | print '</select>'; |
@@ -966,8 +1003,10 @@ discard block |
||
| 966 | 1003 | global $langs; |
| 967 | 1004 | |
| 968 | 1005 | $num = count($this->cache_types_fees); |
| 969 | - if ($num > 0) |
|
| 970 | - return 0; // Cache already loaded |
|
| 1006 | + if ($num > 0) { |
|
| 1007 | + return 0; |
|
| 1008 | + } |
|
| 1009 | + // Cache already loaded |
|
| 971 | 1010 | |
| 972 | 1011 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 973 | 1012 | |
@@ -1021,23 +1060,26 @@ discard block |
||
| 1021 | 1060 | print '<select id="select_' . $htmlname . '" class="flat" name="' . $htmlname . '">'; |
| 1022 | 1061 | if ($showempty) {
|
| 1023 | 1062 | print '<option value="-1"'; |
| 1024 | - if ($selected == -1) |
|
| 1025 | - print ' selected'; |
|
| 1063 | + if ($selected == -1) { |
|
| 1064 | + print ' selected'; |
|
| 1065 | + } |
|
| 1026 | 1066 | print '> </option>'; |
| 1027 | 1067 | } |
| 1028 | 1068 | |
| 1029 | 1069 | foreach ($this->cache_types_fees as $key => $value) {
|
| 1030 | 1070 | print '<option value="' . $key . '"'; |
| 1031 | - if ($key == $selected) |
|
| 1032 | - print ' selected'; |
|
| 1071 | + if ($key == $selected) { |
|
| 1072 | + print ' selected'; |
|
| 1073 | + } |
|
| 1033 | 1074 | print '>'; |
| 1034 | 1075 | print $value; |
| 1035 | 1076 | print '</option>'; |
| 1036 | 1077 | } |
| 1037 | 1078 | |
| 1038 | 1079 | print '</select>'; |
| 1039 | - if ($user->admin) |
|
| 1040 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 1080 | + if ($user->admin) { |
|
| 1081 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 1082 | + } |
|
| 1041 | 1083 | } |
| 1042 | 1084 | |
| 1043 | 1085 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -1100,9 +1142,9 @@ discard block |
||
| 1100 | 1142 | $urloption = 'htmlname=' . $htmlname . '&outjson=1&filter=' . $filter . ($showtype ? '&showtype=' . $showtype : ''); |
| 1101 | 1143 | $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
| 1102 | 1144 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
|
| 1103 | - if (empty($hidelabel)) |
|
| 1104 | - print $langs->trans("RefOrLabel") . ' : ';
|
|
| 1105 | - else if ($hidelabel > 1) {
|
|
| 1145 | + if (empty($hidelabel)) { |
|
| 1146 | + print $langs->trans("RefOrLabel") . ' : '; |
|
| 1147 | + } else if ($hidelabel > 1) {
|
|
| 1106 | 1148 | $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
|
| 1107 | 1149 | if ($hidelabel == 2) {
|
| 1108 | 1150 | $out .= img_picto($langs->trans("Search"), 'search');
|
@@ -1149,10 +1191,11 @@ discard block |
||
| 1149 | 1191 | $num = 0; |
| 1150 | 1192 | $outarray = array(); |
| 1151 | 1193 | |
| 1152 | - if ($selected === '') |
|
| 1153 | - $selected = array(); |
|
| 1154 | - else if (!is_array($selected)) |
|
| 1155 | - $selected = array($selected); |
|
| 1194 | + if ($selected === '') { |
|
| 1195 | + $selected = array(); |
|
| 1196 | + } else if (!is_array($selected)) { |
|
| 1197 | + $selected = array($selected); |
|
| 1198 | + } |
|
| 1156 | 1199 | |
| 1157 | 1200 | // Clean $filter that may contains sql conditions so sql code |
| 1158 | 1201 | if (function_exists('testSqlAndScriptInject')) {
|
@@ -1170,21 +1213,26 @@ discard block |
||
| 1170 | 1213 | } |
| 1171 | 1214 | |
| 1172 | 1215 | $sql .= " FROM (" . MAIN_DB_PREFIX . "societe as s";
|
| 1173 | - if (!$user->rights->societe->client->voir && !$user->socid) |
|
| 1174 | - $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 1216 | + if (!$user->rights->societe->client->voir && !$user->socid) { |
|
| 1217 | + $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 1218 | + } |
|
| 1175 | 1219 | $sql .= " )"; |
| 1176 | 1220 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
|
| 1177 | 1221 | $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "c_country as dictp ON dictp.rowid=s.fk_pays"; |
| 1178 | 1222 | } |
| 1179 | 1223 | $sql .= " WHERE s.entity IN (" . getEntity('societe') . ")";
|
| 1180 | - if (!empty($user->socid)) |
|
| 1181 | - $sql .= " AND s.rowid = " . $user->socid; |
|
| 1182 | - if ($filter) |
|
| 1183 | - $sql .= " AND (" . $filter . ")";
|
|
| 1184 | - if (!$user->rights->societe->client->voir && !$user->socid) |
|
| 1185 | - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 1186 | - if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) |
|
| 1187 | - $sql .= " AND s.status <> 0"; |
|
| 1224 | + if (!empty($user->socid)) { |
|
| 1225 | + $sql .= " AND s.rowid = " . $user->socid; |
|
| 1226 | + } |
|
| 1227 | + if ($filter) { |
|
| 1228 | + $sql .= " AND (" . $filter . ")"; |
|
| 1229 | + } |
|
| 1230 | + if (!$user->rights->societe->client->voir && !$user->socid) { |
|
| 1231 | + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 1232 | + } |
|
| 1233 | + if (!empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) { |
|
| 1234 | + $sql .= " AND s.status <> 0"; |
|
| 1235 | + } |
|
| 1188 | 1236 | // Add criteria |
| 1189 | 1237 | if ($filterkey && $filterkey != '') {
|
| 1190 | 1238 | $sql .= " AND (";
|
@@ -1192,16 +1240,19 @@ discard block |
||
| 1192 | 1240 | // For natural search |
| 1193 | 1241 | $scrit = explode(' ', $filterkey);
|
| 1194 | 1242 | $i = 0; |
| 1195 | - if (count($scrit) > 1) |
|
| 1196 | - $sql .= "(";
|
|
| 1243 | + if (count($scrit) > 1) { |
|
| 1244 | + $sql .= "("; |
|
| 1245 | + } |
|
| 1197 | 1246 | foreach ($scrit as $crit) {
|
| 1198 | - if ($i > 0) |
|
| 1199 | - $sql .= " AND "; |
|
| 1247 | + if ($i > 0) { |
|
| 1248 | + $sql .= " AND "; |
|
| 1249 | + } |
|
| 1200 | 1250 | $sql .= "(s.nom LIKE '" . $this->db->escape($prefix . $crit) . "%')"; |
| 1201 | 1251 | $i++; |
| 1202 | 1252 | } |
| 1203 | - if (count($scrit) > 1) |
|
| 1204 | - $sql .= ")"; |
|
| 1253 | + if (count($scrit) > 1) { |
|
| 1254 | + $sql .= ")"; |
|
| 1255 | + } |
|
| 1205 | 1256 | if (!empty($conf->barcode->enabled)) {
|
| 1206 | 1257 | $sql .= " OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
| 1207 | 1258 | } |
@@ -1227,13 +1278,15 @@ discard block |
||
| 1227 | 1278 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
| 1228 | 1279 | //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
| 1229 | 1280 | if (!empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
|
| 1230 | - if ($showempty && !is_numeric($showempty)) |
|
| 1231 | - $textifempty = $langs->trans($showempty); |
|
| 1232 | - else |
|
| 1233 | - $textifempty .= $langs->trans("All");
|
|
| 1281 | + if ($showempty && !is_numeric($showempty)) { |
|
| 1282 | + $textifempty = $langs->trans($showempty); |
|
| 1283 | + } else { |
|
| 1284 | + $textifempty .= $langs->trans("All"); |
|
| 1285 | + } |
|
| 1234 | 1286 | } |
| 1235 | - if ($showempty) |
|
| 1236 | - $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 1287 | + if ($showempty) { |
|
| 1288 | + $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 1289 | + } |
|
| 1237 | 1290 | |
| 1238 | 1291 | $num = $this->db->num_rows($resql); |
| 1239 | 1292 | $i = 0; |
@@ -1258,16 +1311,21 @@ discard block |
||
| 1258 | 1311 | } |
| 1259 | 1312 | |
| 1260 | 1313 | if ($showtype) {
|
| 1261 | - if ($obj->client || $obj->fournisseur) |
|
| 1262 | - $label .= ' (';
|
|
| 1263 | - if ($obj->client == 1 || $obj->client == 3) |
|
| 1264 | - $label .= $langs->trans("Customer");
|
|
| 1265 | - if ($obj->client == 2 || $obj->client == 3) |
|
| 1266 | - $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect");
|
|
| 1267 | - if ($obj->fournisseur) |
|
| 1268 | - $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier");
|
|
| 1269 | - if ($obj->client || $obj->fournisseur) |
|
| 1270 | - $label .= ')'; |
|
| 1314 | + if ($obj->client || $obj->fournisseur) { |
|
| 1315 | + $label .= ' ('; |
|
| 1316 | + } |
|
| 1317 | + if ($obj->client == 1 || $obj->client == 3) { |
|
| 1318 | + $label .= $langs->trans("Customer"); |
|
| 1319 | + } |
|
| 1320 | + if ($obj->client == 2 || $obj->client == 3) { |
|
| 1321 | + $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect"); |
|
| 1322 | + } |
|
| 1323 | + if ($obj->fournisseur) { |
|
| 1324 | + $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier"); |
|
| 1325 | + } |
|
| 1326 | + if ($obj->client || $obj->fournisseur) { |
|
| 1327 | + $label .= ')'; |
|
| 1328 | + } |
|
| 1271 | 1329 | } |
| 1272 | 1330 | |
| 1273 | 1331 | if ($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
|
@@ -1288,20 +1346,21 @@ discard block |
||
| 1288 | 1346 | } |
| 1289 | 1347 | |
| 1290 | 1348 | $i++; |
| 1291 | - if (($i % 10) == 0) |
|
| 1292 | - $out .= "\n"; |
|
| 1349 | + if (($i % 10) == 0) { |
|
| 1350 | + $out .= "\n"; |
|
| 1351 | + } |
|
| 1293 | 1352 | } |
| 1294 | 1353 | } |
| 1295 | 1354 | $out .= '</select>' . "\n"; |
| 1296 | - } |
|
| 1297 | - else {
|
|
| 1355 | + } else {
|
|
| 1298 | 1356 | dol_print_error($this->db); |
| 1299 | 1357 | } |
| 1300 | 1358 | |
| 1301 | 1359 | $this->result = array('nbofthirdparties' => $num);
|
| 1302 | 1360 | |
| 1303 | - if ($outputmode) |
|
| 1304 | - return $outarray; |
|
| 1361 | + if ($outputmode) { |
|
| 1362 | + return $outarray; |
|
| 1363 | + } |
|
| 1305 | 1364 | return $out; |
| 1306 | 1365 | } |
| 1307 | 1366 | |
@@ -1327,8 +1386,9 @@ discard block |
||
| 1327 | 1386 | $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; |
| 1328 | 1387 | $sql .= " WHERE re.fk_soc = " . (int) $socid; |
| 1329 | 1388 | $sql .= " AND re.entity = " . $conf->entity; |
| 1330 | - if ($filter) |
|
| 1331 | - $sql .= " AND " . $filter; |
|
| 1389 | + if ($filter) { |
|
| 1390 | + $sql .= " AND " . $filter; |
|
| 1391 | + } |
|
| 1332 | 1392 | $sql .= " ORDER BY re.description ASC"; |
| 1333 | 1393 | |
| 1334 | 1394 | dol_syslog(get_class($this) . "::select_remises", LOG_DEBUG); |
@@ -1345,18 +1405,23 @@ discard block |
||
| 1345 | 1405 | while ($i < $num) {
|
| 1346 | 1406 | $obj = $this->db->fetch_object($resql); |
| 1347 | 1407 | $desc = dol_trunc($obj->description, 40); |
| 1348 | - if (preg_match('/\(CREDIT_NOTE\)/', $desc))
|
|
| 1349 | - $desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc);
|
|
| 1350 | - if (preg_match('/\(DEPOSIT\)/', $desc))
|
|
| 1351 | - $desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc);
|
|
| 1352 | - if (preg_match('/\(EXCESS RECEIVED\)/', $desc))
|
|
| 1353 | - $desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc);
|
|
| 1354 | - if (preg_match('/\(EXCESS PAID\)/', $desc))
|
|
| 1355 | - $desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc);
|
|
| 1408 | + if (preg_match('/\(CREDIT_NOTE\)/', $desc)) { |
|
| 1409 | + $desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc); |
|
| 1410 | + } |
|
| 1411 | + if (preg_match('/\(DEPOSIT\)/', $desc)) { |
|
| 1412 | + $desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc); |
|
| 1413 | + } |
|
| 1414 | + if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) { |
|
| 1415 | + $desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc); |
|
| 1416 | + } |
|
| 1417 | + if (preg_match('/\(EXCESS PAID\)/', $desc)) { |
|
| 1418 | + $desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc); |
|
| 1419 | + } |
|
| 1356 | 1420 | |
| 1357 | 1421 | $selectstring = ''; |
| 1358 | - if ($selected > 0 && $selected == $obj->rowid) |
|
| 1359 | - $selectstring = ' selected'; |
|
| 1422 | + if ($selected > 0 && $selected == $obj->rowid) { |
|
| 1423 | + $selectstring = ' selected'; |
|
| 1424 | + } |
|
| 1360 | 1425 | |
| 1361 | 1426 | $disabled = ''; |
| 1362 | 1427 | if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
|
@@ -1366,8 +1431,9 @@ discard block |
||
| 1366 | 1431 | |
| 1367 | 1432 | if (!empty($conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) {
|
| 1368 | 1433 | $tmpfac = new Facture($this->db); |
| 1369 | - if ($tmpfac->fetch($obj->fk_facture_source) > 0) |
|
| 1370 | - $desc = $desc . ' - ' . $tmpfac->ref; |
|
| 1434 | + if ($tmpfac->fetch($obj->fk_facture_source) > 0) { |
|
| 1435 | + $desc = $desc . ' - ' . $tmpfac->ref; |
|
| 1436 | + } |
|
| 1371 | 1437 | } |
| 1372 | 1438 | |
| 1373 | 1439 | print '<option value="' . $obj->rowid . '"' . $selectstring . $disabled . '>' . $desc . ' (' . price($obj->amount_ht) . ' ' . $langs->trans("HT") . ' - ' . price($obj->amount_ttc) . ' ' . $langs->trans("TTC") . ')</option>';
|
@@ -1376,8 +1442,7 @@ discard block |
||
| 1376 | 1442 | } |
| 1377 | 1443 | print '</select>'; |
| 1378 | 1444 | return $qualifiedlines; |
| 1379 | - } |
|
| 1380 | - else {
|
|
| 1445 | + } else {
|
|
| 1381 | 1446 | dol_print_error($this->db); |
| 1382 | 1447 | return -1; |
| 1383 | 1448 | } |
@@ -1440,13 +1505,15 @@ discard block |
||
| 1440 | 1505 | |
| 1441 | 1506 | $langs->load('companies');
|
| 1442 | 1507 | |
| 1443 | - if (empty($htmlid)) |
|
| 1444 | - $htmlid = $htmlname; |
|
| 1508 | + if (empty($htmlid)) { |
|
| 1509 | + $htmlid = $htmlname; |
|
| 1510 | + } |
|
| 1445 | 1511 | |
| 1446 | - if ($selected === '') |
|
| 1447 | - $selected = array(); |
|
| 1448 | - else if (!is_array($selected)) |
|
| 1449 | - $selected = array($selected); |
|
| 1512 | + if ($selected === '') { |
|
| 1513 | + $selected = array(); |
|
| 1514 | + } else if (!is_array($selected)) { |
|
| 1515 | + $selected = array($selected); |
|
| 1516 | + } |
|
| 1450 | 1517 | $out = ''; |
| 1451 | 1518 | |
| 1452 | 1519 | if (!is_object($hookmanager)) {
|
@@ -1456,16 +1523,20 @@ discard block |
||
| 1456 | 1523 | |
| 1457 | 1524 | // We search third parties |
| 1458 | 1525 | $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; |
| 1459 | - if ($showsoc > 0) |
|
| 1460 | - $sql .= " , s.nom as company"; |
|
| 1526 | + if ($showsoc > 0) { |
|
| 1527 | + $sql .= " , s.nom as company"; |
|
| 1528 | + } |
|
| 1461 | 1529 | $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as sp"; |
| 1462 | - if ($showsoc > 0) |
|
| 1463 | - $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc"; |
|
| 1530 | + if ($showsoc > 0) { |
|
| 1531 | + $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc"; |
|
| 1532 | + } |
|
| 1464 | 1533 | $sql .= " WHERE sp.entity IN (" . getEntity('socpeople') . ")";
|
| 1465 | - if ($socid > 0 || $socid == -1) |
|
| 1466 | - $sql .= " AND sp.fk_soc=" . $socid; |
|
| 1467 | - if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) |
|
| 1468 | - $sql .= " AND sp.statut <> 0"; |
|
| 1534 | + if ($socid > 0 || $socid == -1) { |
|
| 1535 | + $sql .= " AND sp.fk_soc=" . $socid; |
|
| 1536 | + } |
|
| 1537 | + if (!empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) { |
|
| 1538 | + $sql .= " AND sp.statut <> 0"; |
|
| 1539 | + } |
|
| 1469 | 1540 | $sql .= " ORDER BY sp.lastname ASC"; |
| 1470 | 1541 | |
| 1471 | 1542 | dol_syslog(get_class($this) . "::select_contacts", LOG_DEBUG); |
@@ -1478,12 +1549,15 @@ discard block |
||
| 1478 | 1549 | $out .= ajax_combobox($htmlid, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT); |
| 1479 | 1550 | } |
| 1480 | 1551 | |
| 1481 | - if ($htmlname != 'none' || $options_only) |
|
| 1482 | - $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlid . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . (!empty($moreparam) ? $moreparam : '') . '>'; |
|
| 1483 | - if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) |
|
| 1484 | - $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '> </option>'; |
|
| 1485 | - if ($showempty == 2) |
|
| 1486 | - $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '>' . $langs->trans("Internal") . '</option>';
|
|
| 1552 | + if ($htmlname != 'none' || $options_only) { |
|
| 1553 | + $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlid . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . (!empty($moreparam) ? $moreparam : '') . '>'; |
|
| 1554 | + } |
|
| 1555 | + if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) { |
|
| 1556 | + $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '> </option>'; |
|
| 1557 | + } |
|
| 1558 | + if ($showempty == 2) { |
|
| 1559 | + $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '>' . $langs->trans("Internal") . '</option>'; |
|
| 1560 | + } |
|
| 1487 | 1561 | $num = $this->db->num_rows($resql); |
| 1488 | 1562 | $i = 0; |
| 1489 | 1563 | if ($num) {
|
@@ -1499,49 +1573,56 @@ discard block |
||
| 1499 | 1573 | if ($obj->statut == 1) {
|
| 1500 | 1574 | if ($htmlname != 'none') {
|
| 1501 | 1575 | $disabled = 0; |
| 1502 | - if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) |
|
| 1503 | - $disabled = 1; |
|
| 1504 | - if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) |
|
| 1505 | - $disabled = 1; |
|
| 1576 | + if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) { |
|
| 1577 | + $disabled = 1; |
|
| 1578 | + } |
|
| 1579 | + if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) { |
|
| 1580 | + $disabled = 1; |
|
| 1581 | + } |
|
| 1506 | 1582 | if (!empty($selected) && in_array($obj->rowid, $selected)) {
|
| 1507 | 1583 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1508 | - if ($disabled) |
|
| 1509 | - $out .= ' disabled'; |
|
| 1584 | + if ($disabled) { |
|
| 1585 | + $out .= ' disabled'; |
|
| 1586 | + } |
|
| 1510 | 1587 | $out .= ' selected>'; |
| 1511 | 1588 | $out .= $contactstatic->getFullName($langs); |
| 1512 | - if ($showfunction && $obj->poste) |
|
| 1513 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1514 | - if (($showsoc > 0) && $obj->company) |
|
| 1515 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1589 | + if ($showfunction && $obj->poste) { |
|
| 1590 | + $out .= ' (' . $obj->poste . ')'; |
|
| 1591 | + } |
|
| 1592 | + if (($showsoc > 0) && $obj->company) { |
|
| 1593 | + $out .= ' - (' . $obj->company . ')'; |
|
| 1594 | + } |
|
| 1516 | 1595 | $out .= '</option>'; |
| 1517 | - } |
|
| 1518 | - else {
|
|
| 1596 | + } else {
|
|
| 1519 | 1597 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1520 | - if ($disabled) |
|
| 1521 | - $out .= ' disabled'; |
|
| 1598 | + if ($disabled) { |
|
| 1599 | + $out .= ' disabled'; |
|
| 1600 | + } |
|
| 1522 | 1601 | $out .= '>'; |
| 1523 | 1602 | $out .= $contactstatic->getFullName($langs); |
| 1524 | - if ($showfunction && $obj->poste) |
|
| 1525 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1526 | - if (($showsoc > 0) && $obj->company) |
|
| 1527 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1603 | + if ($showfunction && $obj->poste) { |
|
| 1604 | + $out .= ' (' . $obj->poste . ')'; |
|
| 1605 | + } |
|
| 1606 | + if (($showsoc > 0) && $obj->company) { |
|
| 1607 | + $out .= ' - (' . $obj->company . ')'; |
|
| 1608 | + } |
|
| 1528 | 1609 | $out .= '</option>'; |
| 1529 | 1610 | } |
| 1530 | - } |
|
| 1531 | - else {
|
|
| 1611 | + } else {
|
|
| 1532 | 1612 | if (in_array($obj->rowid, $selected)) {
|
| 1533 | 1613 | $out .= $contactstatic->getFullName($langs); |
| 1534 | - if ($showfunction && $obj->poste) |
|
| 1535 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1536 | - if (($showsoc > 0) && $obj->company) |
|
| 1537 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1614 | + if ($showfunction && $obj->poste) { |
|
| 1615 | + $out .= ' (' . $obj->poste . ')'; |
|
| 1616 | + } |
|
| 1617 | + if (($showsoc > 0) && $obj->company) { |
|
| 1618 | + $out .= ' - (' . $obj->company . ')'; |
|
| 1619 | + } |
|
| 1538 | 1620 | } |
| 1539 | 1621 | } |
| 1540 | 1622 | } |
| 1541 | 1623 | $i++; |
| 1542 | 1624 | } |
| 1543 | - } |
|
| 1544 | - else {
|
|
| 1625 | + } else {
|
|
| 1545 | 1626 | $out .= '<option value="-1"' . (($showempty == 2 || $multiple) ? '' : ' selected') . ' disabled>'; |
| 1546 | 1627 | $out .= ($socid != -1) ? ($langs->trans($socid ? "NoContactDefinedForThirdParty" : "NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst');
|
| 1547 | 1628 | $out .= '</option>'; |
@@ -1622,24 +1703,27 @@ discard block |
||
| 1622 | 1703 | global $conf, $user, $langs; |
| 1623 | 1704 | |
| 1624 | 1705 | // If no preselected user defined, we take current user |
| 1625 | - if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) |
|
| 1626 | - $selected = $user->id; |
|
| 1706 | + if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) { |
|
| 1707 | + $selected = $user->id; |
|
| 1708 | + } |
|
| 1627 | 1709 | |
| 1628 | - if ($selected === '') |
|
| 1629 | - $selected = array(); |
|
| 1630 | - else if (!is_array($selected)) |
|
| 1631 | - $selected = array($selected); |
|
| 1710 | + if ($selected === '') { |
|
| 1711 | + $selected = array(); |
|
| 1712 | + } else if (!is_array($selected)) { |
|
| 1713 | + $selected = array($selected); |
|
| 1714 | + } |
|
| 1632 | 1715 | |
| 1633 | 1716 | $excludeUsers = null; |
| 1634 | 1717 | $includeUsers = null; |
| 1635 | 1718 | |
| 1636 | 1719 | // Permettre l'exclusion d'utilisateurs |
| 1637 | - if (is_array($exclude)) |
|
| 1638 | - $excludeUsers = implode(",", $exclude);
|
|
| 1720 | + if (is_array($exclude)) { |
|
| 1721 | + $excludeUsers = implode(",", $exclude); |
|
| 1722 | + } |
|
| 1639 | 1723 | // Permettre l'inclusion d'utilisateurs |
| 1640 | - if (is_array($include)) |
|
| 1641 | - $includeUsers = implode(",", $include);
|
|
| 1642 | - else if ($include == 'hierarchy') {
|
|
| 1724 | + if (is_array($include)) { |
|
| 1725 | + $includeUsers = implode(",", $include); |
|
| 1726 | + } else if ($include == 'hierarchy') {
|
|
| 1643 | 1727 | // Build list includeUsers to have only hierarchy |
| 1644 | 1728 | $includeUsers = implode(",", $user->getAllChildIds(0));
|
| 1645 | 1729 | } else if ($include == 'hierarchyme') {
|
@@ -1658,12 +1742,12 @@ discard block |
||
| 1658 | 1742 | $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
| 1659 | 1743 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 1660 | 1744 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=u.entity"; |
| 1661 | - if ($force_entity) |
|
| 1662 | - $sql .= " WHERE u.entity IN (0," . $force_entity . ")"; |
|
| 1663 | - else |
|
| 1664 | - $sql .= " WHERE u.entity IS NOT NULL"; |
|
| 1665 | - } |
|
| 1666 | - else {
|
|
| 1745 | + if ($force_entity) { |
|
| 1746 | + $sql .= " WHERE u.entity IN (0," . $force_entity . ")"; |
|
| 1747 | + } else { |
|
| 1748 | + $sql .= " WHERE u.entity IS NOT NULL"; |
|
| 1749 | + } |
|
| 1750 | + } else {
|
|
| 1667 | 1751 | if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1668 | 1752 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ug"; |
| 1669 | 1753 | $sql .= " ON ug.fk_user = u.rowid"; |
@@ -1672,16 +1756,21 @@ discard block |
||
| 1672 | 1756 | $sql .= " WHERE u.entity IN (0," . $conf->entity . ")"; |
| 1673 | 1757 | } |
| 1674 | 1758 | } |
| 1675 | - if (!empty($user->societe_id)) |
|
| 1676 | - $sql .= " AND u.fk_soc = " . $user->societe_id; |
|
| 1677 | - if (is_array($exclude) && $excludeUsers) |
|
| 1678 | - $sql .= " AND u.rowid NOT IN (" . $excludeUsers . ")";
|
|
| 1679 | - if ($includeUsers) |
|
| 1680 | - $sql .= " AND u.rowid IN (" . $includeUsers . ")";
|
|
| 1681 | - if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) |
|
| 1682 | - $sql .= " AND u.statut <> 0"; |
|
| 1683 | - if (!empty($morefilter)) |
|
| 1684 | - $sql .= " " . $morefilter; |
|
| 1759 | + if (!empty($user->societe_id)) { |
|
| 1760 | + $sql .= " AND u.fk_soc = " . $user->societe_id; |
|
| 1761 | + } |
|
| 1762 | + if (is_array($exclude) && $excludeUsers) { |
|
| 1763 | + $sql .= " AND u.rowid NOT IN (" . $excludeUsers . ")"; |
|
| 1764 | + } |
|
| 1765 | + if ($includeUsers) { |
|
| 1766 | + $sql .= " AND u.rowid IN (" . $includeUsers . ")"; |
|
| 1767 | + } |
|
| 1768 | + if (!empty($conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) { |
|
| 1769 | + $sql .= " AND u.statut <> 0"; |
|
| 1770 | + } |
|
| 1771 | + if (!empty($morefilter)) { |
|
| 1772 | + $sql .= " " . $morefilter; |
|
| 1773 | + } |
|
| 1685 | 1774 | |
| 1686 | 1775 | if (empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
|
| 1687 | 1776 | $sql .= " ORDER BY u.firstname ASC"; |
@@ -1701,10 +1790,12 @@ discard block |
||
| 1701 | 1790 | |
| 1702 | 1791 | // do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined |
| 1703 | 1792 | $out .= '<select class="flat' . ($morecss ? ' minwidth100 ' . $morecss : ' minwidth200') . '" id="' . $htmlname . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . ($disabled ? ' disabled' : '') . '>'; |
| 1704 | - if ($show_empty && !$multiple) |
|
| 1705 | - $out .= '<option value="-1"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 1706 | - if ($show_every) |
|
| 1707 | - $out .= '<option value="-2"' . ((in_array(-2, $selected)) ? ' selected' : '') . '>-- ' . $langs->trans("Everybody") . ' --</option>' . "\n";
|
|
| 1793 | + if ($show_empty && !$multiple) { |
|
| 1794 | + $out .= '<option value="-1"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 1795 | + } |
|
| 1796 | + if ($show_every) { |
|
| 1797 | + $out .= '<option value="-2"' . ((in_array(-2, $selected)) ? ' selected' : '') . '>-- ' . $langs->trans("Everybody") . ' --</option>' . "\n"; |
|
| 1798 | + } |
|
| 1708 | 1799 | |
| 1709 | 1800 | $userstatic = new User($this->db); |
| 1710 | 1801 | |
@@ -1716,19 +1807,21 @@ discard block |
||
| 1716 | 1807 | $userstatic->firstname = $obj->firstname; |
| 1717 | 1808 | |
| 1718 | 1809 | $disableline = ''; |
| 1719 | - if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) |
|
| 1720 | - $disableline = ($enableonlytext ? $enableonlytext : '1'); |
|
| 1810 | + if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) { |
|
| 1811 | + $disableline = ($enableonlytext ? $enableonlytext : '1'); |
|
| 1812 | + } |
|
| 1721 | 1813 | |
| 1722 | 1814 | if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected) )) {
|
| 1723 | 1815 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1724 | - if ($disableline) |
|
| 1725 | - $out .= ' disabled'; |
|
| 1816 | + if ($disableline) { |
|
| 1817 | + $out .= ' disabled'; |
|
| 1818 | + } |
|
| 1726 | 1819 | $out .= ' selected>'; |
| 1727 | - } |
|
| 1728 | - else {
|
|
| 1820 | + } else {
|
|
| 1729 | 1821 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1730 | - if ($disableline) |
|
| 1731 | - $out .= ' disabled'; |
|
| 1822 | + if ($disableline) { |
|
| 1823 | + $out .= ' disabled'; |
|
| 1824 | + } |
|
| 1732 | 1825 | $out .= '>'; |
| 1733 | 1826 | } |
| 1734 | 1827 | |
@@ -1782,8 +1875,9 @@ discard block |
||
| 1782 | 1875 | dol_print_error($this->db); |
| 1783 | 1876 | } |
| 1784 | 1877 | |
| 1785 | - if ($outputmode) |
|
| 1786 | - return $outarray; |
|
| 1878 | + if ($outputmode) { |
|
| 1879 | + return $outarray; |
|
| 1880 | + } |
|
| 1787 | 1881 | return $out; |
| 1788 | 1882 | } |
| 1789 | 1883 | |
@@ -1835,15 +1929,18 @@ discard block |
||
| 1835 | 1929 | } |
| 1836 | 1930 | $nbassignetouser = count($assignedtouser); |
| 1837 | 1931 | |
| 1838 | - if ($nbassignetouser && $action != 'view') |
|
| 1839 | - $out .= '<br>'; |
|
| 1840 | - if ($nbassignetouser) |
|
| 1841 | - $out .= '<ul class="attendees">'; |
|
| 1932 | + if ($nbassignetouser && $action != 'view') { |
|
| 1933 | + $out .= '<br>'; |
|
| 1934 | + } |
|
| 1935 | + if ($nbassignetouser) { |
|
| 1936 | + $out .= '<ul class="attendees">'; |
|
| 1937 | + } |
|
| 1842 | 1938 | $i = 0; |
| 1843 | 1939 | $ownerid = 0; |
| 1844 | 1940 | foreach ($assignedtouser as $key => $value) {
|
| 1845 | - if ($value['id'] == $ownerid) |
|
| 1846 | - continue; |
|
| 1941 | + if ($value['id'] == $ownerid) { |
|
| 1942 | + continue; |
|
| 1943 | + } |
|
| 1847 | 1944 | |
| 1848 | 1945 | $out .= '<li>'; |
| 1849 | 1946 | $userstatic->fetch($value['id']); |
@@ -1869,8 +1966,9 @@ discard block |
||
| 1869 | 1966 | $out .= '</li>'; |
| 1870 | 1967 | $i++; |
| 1871 | 1968 | } |
| 1872 | - if ($nbassignetouser) |
|
| 1873 | - $out .= '</ul>'; |
|
| 1969 | + if ($nbassignetouser) { |
|
| 1970 | + $out .= '</ul>'; |
|
| 1971 | + } |
|
| 1874 | 1972 | |
| 1875 | 1973 | //$out.='</form>'; |
| 1876 | 1974 | return $out; |
@@ -2001,9 +2099,9 @@ discard block |
||
| 2001 | 2099 | </script> |
| 2002 | 2100 | <?php |
| 2003 | 2101 | } |
| 2004 | - if (empty($hidelabel)) |
|
| 2005 | - print $langs->trans("RefOrLabel") . ' : ';
|
|
| 2006 | - else if ($hidelabel > 1) {
|
|
| 2102 | + if (empty($hidelabel)) { |
|
| 2103 | + print $langs->trans("RefOrLabel") . ' : '; |
|
| 2104 | + } else if ($hidelabel > 1) {
|
|
| 2007 | 2105 | $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
|
| 2008 | 2106 | if ($hidelabel == 2) {
|
| 2009 | 2107 | print img_picto($langs->trans("Search"), 'search');
|
@@ -2094,13 +2192,15 @@ discard block |
||
| 2094 | 2192 | // Price by quantity |
| 2095 | 2193 | if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
|
| 2096 | 2194 | $sql .= ", (SELECT pp.rowid FROM " . MAIN_DB_PREFIX . "product_price as pp WHERE pp.fk_product = p.rowid"; |
| 2097 | - if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) |
|
| 2098 | - $sql .= " AND price_level=" . $price_level; |
|
| 2195 | + if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { |
|
| 2196 | + $sql .= " AND price_level=" . $price_level; |
|
| 2197 | + } |
|
| 2099 | 2198 | $sql .= " ORDER BY date_price"; |
| 2100 | 2199 | $sql .= " DESC LIMIT 1) as price_rowid"; |
| 2101 | 2200 | $sql .= ", (SELECT pp.price_by_qty FROM " . MAIN_DB_PREFIX . "product_price as pp WHERE pp.fk_product = p.rowid"; // price_by_qty is 1 if some prices by qty exists in subtable |
| 2102 | - if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) |
|
| 2103 | - $sql .= " AND price_level=" . $price_level; |
|
| 2201 | + if ($price_level >= 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { |
|
| 2202 | + $sql .= " AND price_level=" . $price_level; |
|
| 2203 | + } |
|
| 2104 | 2204 | $sql .= " ORDER BY date_price"; |
| 2105 | 2205 | $sql .= " DESC LIMIT 1) as price_by_qty"; |
| 2106 | 2206 | $selectFields .= ", price_rowid, price_by_qty"; |
@@ -2142,14 +2242,15 @@ discard block |
||
| 2142 | 2242 | $sql .= " AND p.finished = " . $finished; |
| 2143 | 2243 | } elseif ($finished == 1) {
|
| 2144 | 2244 | $sql .= " AND p.finished = " . $finished; |
| 2145 | - if ($status >= 0) |
|
| 2146 | - $sql .= " AND p.tosell = " . $status; |
|
| 2147 | - } |
|
| 2148 | - elseif ($status >= 0) {
|
|
| 2245 | + if ($status >= 0) { |
|
| 2246 | + $sql .= " AND p.tosell = " . $status; |
|
| 2247 | + } |
|
| 2248 | + } elseif ($status >= 0) {
|
|
| 2149 | 2249 | $sql .= " AND p.tosell = " . $status; |
| 2150 | 2250 | } |
| 2151 | - if (strval($filtertype) != '') |
|
| 2152 | - $sql .= " AND p.fk_product_type=" . $filtertype; |
|
| 2251 | + if (strval($filtertype) != '') { |
|
| 2252 | + $sql .= " AND p.fk_product_type=" . $filtertype; |
|
| 2253 | + } |
|
| 2153 | 2254 | // Add criteria on ref/label |
| 2154 | 2255 | if ($filterkey != '') {
|
| 2155 | 2256 | $sql .= ' AND (';
|
@@ -2157,28 +2258,35 @@ discard block |
||
| 2157 | 2258 | // For natural search |
| 2158 | 2259 | $scrit = explode(' ', $filterkey);
|
| 2159 | 2260 | $i = 0; |
| 2160 | - if (count($scrit) > 1) |
|
| 2161 | - $sql .= "(";
|
|
| 2261 | + if (count($scrit) > 1) { |
|
| 2262 | + $sql .= "("; |
|
| 2263 | + } |
|
| 2162 | 2264 | foreach ($scrit as $crit) {
|
| 2163 | - if ($i > 0) |
|
| 2164 | - $sql .= " AND "; |
|
| 2265 | + if ($i > 0) { |
|
| 2266 | + $sql .= " AND "; |
|
| 2267 | + } |
|
| 2165 | 2268 | $sql .= "(p.ref LIKE '" . $db->escape($prefix . $crit) . "%' OR p.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
| 2166 | - if (!empty($conf->global->MAIN_MULTILANGS)) |
|
| 2167 | - $sql .= " OR pl.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2269 | + if (!empty($conf->global->MAIN_MULTILANGS)) { |
|
| 2270 | + $sql .= " OR pl.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2271 | + } |
|
| 2168 | 2272 | if (!empty($conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION)) {
|
| 2169 | 2273 | $sql .= " OR p.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
| 2170 | - if (!empty($conf->global->MAIN_MULTILANGS)) |
|
| 2171 | - $sql .= " OR pl.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2274 | + if (!empty($conf->global->MAIN_MULTILANGS)) { |
|
| 2275 | + $sql .= " OR pl.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2276 | + } |
|
| 2172 | 2277 | } |
| 2173 | - if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) |
|
| 2174 | - $sql .= " OR pfp.ref_fourn LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2278 | + if (!empty($conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) { |
|
| 2279 | + $sql .= " OR pfp.ref_fourn LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2280 | + } |
|
| 2175 | 2281 | $sql .= ")"; |
| 2176 | 2282 | $i++; |
| 2177 | 2283 | } |
| 2178 | - if (count($scrit) > 1) |
|
| 2179 | - $sql .= ")"; |
|
| 2180 | - if (!empty($conf->barcode->enabled)) |
|
| 2181 | - $sql .= " OR p.barcode LIKE '" . $db->escape($prefix . $filterkey) . "%'"; |
|
| 2284 | + if (count($scrit) > 1) { |
|
| 2285 | + $sql .= ")"; |
|
| 2286 | + } |
|
| 2287 | + if (!empty($conf->barcode->enabled)) { |
|
| 2288 | + $sql .= " OR p.barcode LIKE '" . $db->escape($prefix . $filterkey) . "%'"; |
|
| 2289 | + } |
|
| 2182 | 2290 | $sql .= ')'; |
| 2183 | 2291 | } |
| 2184 | 2292 | if (count($warehouseStatusArray)) {
|
@@ -2217,13 +2325,15 @@ discard block |
||
| 2217 | 2325 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
| 2218 | 2326 | //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
| 2219 | 2327 | if (!empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
|
| 2220 | - if ($showempty && !is_numeric($showempty)) |
|
| 2221 | - $textifempty = $langs->trans($showempty); |
|
| 2222 | - else |
|
| 2223 | - $textifempty .= $langs->trans("All");
|
|
| 2328 | + if ($showempty && !is_numeric($showempty)) { |
|
| 2329 | + $textifempty = $langs->trans($showempty); |
|
| 2330 | + } else { |
|
| 2331 | + $textifempty .= $langs->trans("All"); |
|
| 2332 | + } |
|
| 2224 | 2333 | } |
| 2225 | - if ($showempty) |
|
| 2226 | - $out .= '<option value="0" selected>' . $textifempty . '</option>'; |
|
| 2334 | + if ($showempty) { |
|
| 2335 | + $out .= '<option value="0" selected>' . $textifempty . '</option>'; |
|
| 2336 | + } |
|
| 2227 | 2337 | |
| 2228 | 2338 | $i = 0; |
| 2229 | 2339 | while ($num && $i < $num) {
|
@@ -2297,11 +2407,11 @@ discard block |
||
| 2297 | 2407 | |
| 2298 | 2408 | $this->db->free($result); |
| 2299 | 2409 | |
| 2300 | - if (empty($outputmode)) |
|
| 2301 | - return $out; |
|
| 2410 | + if (empty($outputmode)) { |
|
| 2411 | + return $out; |
|
| 2412 | + } |
|
| 2302 | 2413 | return $outarray; |
| 2303 | - } |
|
| 2304 | - else {
|
|
| 2414 | + } else {
|
|
| 2305 | 2415 | dol_print_error($db); |
| 2306 | 2416 | } |
| 2307 | 2417 | } |
@@ -2338,10 +2448,12 @@ discard block |
||
| 2338 | 2448 | $maxlengtharticle = (empty($conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : $conf->global->PRODUCT_MAX_LENGTH_COMBO); |
| 2339 | 2449 | |
| 2340 | 2450 | $label = $objp->label; |
| 2341 | - if (!empty($objp->label_translated)) |
|
| 2342 | - $label = $objp->label_translated; |
|
| 2343 | - if (!empty($filterkey) && $filterkey != '') |
|
| 2344 | - $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2451 | + if (!empty($objp->label_translated)) { |
|
| 2452 | + $label = $objp->label_translated; |
|
| 2453 | + } |
|
| 2454 | + if (!empty($filterkey) && $filterkey != '') { |
|
| 2455 | + $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1); |
|
| 2456 | + } |
|
| 2345 | 2457 | |
| 2346 | 2458 | $outkey = $objp->rowid; |
| 2347 | 2459 | $outref = $objp->ref; |
@@ -2359,23 +2471,27 @@ discard block |
||
| 2359 | 2471 | $opt .= ' pbq="' . $objp->price_by_qty_rowid . '" data-pbq="' . $objp->price_by_qty_rowid . '" data-pbqqty="' . $objp->price_by_qty_quantity . '" data-pbqpercent="' . $objp->price_by_qty_remise_percent . '"'; |
| 2360 | 2472 | } |
| 2361 | 2473 | if (!empty($conf->stock->enabled) && $objp->fk_product_type == 0 && isset($objp->stock)) {
|
| 2362 | - if ($objp->stock > 0) |
|
| 2363 | - $opt .= ' class="product_line_stock_ok"'; |
|
| 2364 | - else if ($objp->stock <= 0) |
|
| 2365 | - $opt .= ' class="product_line_stock_too_low"'; |
|
| 2474 | + if ($objp->stock > 0) { |
|
| 2475 | + $opt .= ' class="product_line_stock_ok"'; |
|
| 2476 | + } else if ($objp->stock <= 0) { |
|
| 2477 | + $opt .= ' class="product_line_stock_too_low"'; |
|
| 2478 | + } |
|
| 2366 | 2479 | } |
| 2367 | 2480 | $opt .= '>'; |
| 2368 | 2481 | $opt .= $objp->ref; |
| 2369 | - if ($outbarcode) |
|
| 2370 | - $opt .= ' (' . $outbarcode . ')';
|
|
| 2482 | + if ($outbarcode) { |
|
| 2483 | + $opt .= ' (' . $outbarcode . ')'; |
|
| 2484 | + } |
|
| 2371 | 2485 | $opt .= ' - ' . dol_trunc($label, $maxlengtharticle); |
| 2372 | 2486 | |
| 2373 | 2487 | $objRef = $objp->ref; |
| 2374 | - if (!empty($filterkey) && $filterkey != '') |
|
| 2375 | - $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2488 | + if (!empty($filterkey) && $filterkey != '') { |
|
| 2489 | + $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1); |
|
| 2490 | + } |
|
| 2376 | 2491 | $outval .= $objRef; |
| 2377 | - if ($outbarcode) |
|
| 2378 | - $outval .= ' (' . $outbarcode . ')';
|
|
| 2492 | + if ($outbarcode) { |
|
| 2493 | + $outval .= ' (' . $outbarcode . ')'; |
|
| 2494 | + } |
|
| 2379 | 2495 | $outval .= ' - ' . dol_trunc($label, $maxlengtharticle); |
| 2380 | 2496 | |
| 2381 | 2497 | $found = 0; |
@@ -2574,15 +2690,18 @@ discard block |
||
| 2574 | 2690 | $sql .= " pfp.supplier_reputation"; |
| 2575 | 2691 | $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; |
| 2576 | 2692 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
| 2577 | - if ($socid) |
|
| 2578 | - $sql .= " AND pfp.fk_soc = " . $socid; |
|
| 2693 | + if ($socid) { |
|
| 2694 | + $sql .= " AND pfp.fk_soc = " . $socid; |
|
| 2695 | + } |
|
| 2579 | 2696 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON pfp.fk_soc = s.rowid"; |
| 2580 | 2697 | $sql .= " WHERE p.entity IN (" . getEntity('product') . ")";
|
| 2581 | 2698 | $sql .= " AND p.tobuy = 1"; |
| 2582 | - if (strval($filtertype) != '') |
|
| 2583 | - $sql .= " AND p.fk_product_type=" . $this->db->escape($filtertype); |
|
| 2584 | - if (!empty($filtre)) |
|
| 2585 | - $sql .= " " . $filtre; |
|
| 2699 | + if (strval($filtertype) != '') { |
|
| 2700 | + $sql .= " AND p.fk_product_type=" . $this->db->escape($filtertype); |
|
| 2701 | + } |
|
| 2702 | + if (!empty($filtre)) { |
|
| 2703 | + $sql .= " " . $filtre; |
|
| 2704 | + } |
|
| 2586 | 2705 | // Add criteria on ref/label |
| 2587 | 2706 | if ($filterkey != '') {
|
| 2588 | 2707 | $sql .= ' AND (';
|
@@ -2590,18 +2709,22 @@ discard block |
||
| 2590 | 2709 | // For natural search |
| 2591 | 2710 | $scrit = explode(' ', $filterkey);
|
| 2592 | 2711 | $i = 0; |
| 2593 | - if (count($scrit) > 1) |
|
| 2594 | - $sql .= "(";
|
|
| 2712 | + if (count($scrit) > 1) { |
|
| 2713 | + $sql .= "("; |
|
| 2714 | + } |
|
| 2595 | 2715 | foreach ($scrit as $crit) {
|
| 2596 | - if ($i > 0) |
|
| 2597 | - $sql .= " AND "; |
|
| 2716 | + if ($i > 0) { |
|
| 2717 | + $sql .= " AND "; |
|
| 2718 | + } |
|
| 2598 | 2719 | $sql .= "(pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) . "%' OR p.ref LIKE '" . $this->db->escape($prefix . $crit) . "%' OR p.label LIKE '" . $this->db->escape($prefix . $crit) . "%')"; |
| 2599 | 2720 | $i++; |
| 2600 | 2721 | } |
| 2601 | - if (count($scrit) > 1) |
|
| 2602 | - $sql .= ")"; |
|
| 2603 | - if (!empty($conf->barcode->enabled)) |
|
| 2604 | - $sql .= " OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 2722 | + if (count($scrit) > 1) { |
|
| 2723 | + $sql .= ")"; |
|
| 2724 | + } |
|
| 2725 | + if (!empty($conf->barcode->enabled)) { |
|
| 2726 | + $sql .= " OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 2727 | + } |
|
| 2605 | 2728 | $sql .= ')'; |
| 2606 | 2729 | } |
| 2607 | 2730 | $sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; |
@@ -2618,18 +2741,21 @@ discard block |
||
| 2618 | 2741 | |
| 2619 | 2742 | //$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax |
| 2620 | 2743 | $out .= '<select class="flat maxwidthonsmartphone" id="' . $htmlname . '" name="' . $htmlname . '">'; |
| 2621 | - if (!$selected) |
|
| 2622 | - $out .= '<option value="0" selected> </option>'; |
|
| 2623 | - else |
|
| 2624 | - $out .= '<option value="0"> </option>'; |
|
| 2744 | + if (!$selected) { |
|
| 2745 | + $out .= '<option value="0" selected> </option>'; |
|
| 2746 | + } else { |
|
| 2747 | + $out .= '<option value="0"> </option>'; |
|
| 2748 | + } |
|
| 2625 | 2749 | |
| 2626 | 2750 | $i = 0; |
| 2627 | 2751 | while ($i < $num) {
|
| 2628 | 2752 | $objp = $this->db->fetch_object($result); |
| 2629 | 2753 | |
| 2630 | 2754 | $outkey = $objp->idprodfournprice; // id in table of price |
| 2631 | - if (!$outkey && $alsoproductwithnosupplierprice) |
|
| 2632 | - $outkey = 'idprod_' . $objp->rowid; // id of product |
|
| 2755 | + if (!$outkey && $alsoproductwithnosupplierprice) { |
|
| 2756 | + $outkey = 'idprod_' . $objp->rowid; |
|
| 2757 | + } |
|
| 2758 | + // id of product |
|
| 2633 | 2759 | |
| 2634 | 2760 | $outref = $objp->ref; |
| 2635 | 2761 | $outval = ''; |
@@ -2640,32 +2766,39 @@ discard block |
||
| 2640 | 2766 | $outdurationunit = $outtype == Product::TYPE_SERVICE ? substr($objp->duration, -1) : ''; |
| 2641 | 2767 | |
| 2642 | 2768 | $opt = '<option value="' . $outkey . '"'; |
| 2643 | - if ($selected && $selected == $objp->idprodfournprice) |
|
| 2644 | - $opt .= ' selected'; |
|
| 2645 | - if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) |
|
| 2646 | - $opt .= ' disabled'; |
|
| 2769 | + if ($selected && $selected == $objp->idprodfournprice) { |
|
| 2770 | + $opt .= ' selected'; |
|
| 2771 | + } |
|
| 2772 | + if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) { |
|
| 2773 | + $opt .= ' disabled'; |
|
| 2774 | + } |
|
| 2647 | 2775 | if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
|
| 2648 | 2776 | $opt .= ' pbq="' . $objp->idprodfournprice . '" data-pbq="' . $objp->idprodfournprice . '" data-pbqqty="' . $objp->quantity . '" data-pbqpercent="' . $objp->remise_percent . '"'; |
| 2649 | 2777 | } |
| 2650 | 2778 | $opt .= '>'; |
| 2651 | 2779 | |
| 2652 | 2780 | $objRef = $objp->ref; |
| 2653 | - if ($filterkey && $filterkey != '') |
|
| 2654 | - $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2781 | + if ($filterkey && $filterkey != '') { |
|
| 2782 | + $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1); |
|
| 2783 | + } |
|
| 2655 | 2784 | $objRefFourn = $objp->ref_fourn; |
| 2656 | - if ($filterkey && $filterkey != '') |
|
| 2657 | - $objRefFourn = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRefFourn, 1);
|
|
| 2785 | + if ($filterkey && $filterkey != '') { |
|
| 2786 | + $objRefFourn = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRefFourn, 1); |
|
| 2787 | + } |
|
| 2658 | 2788 | $label = $objp->label; |
| 2659 | - if ($filterkey && $filterkey != '') |
|
| 2660 | - $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2789 | + if ($filterkey && $filterkey != '') { |
|
| 2790 | + $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1); |
|
| 2791 | + } |
|
| 2661 | 2792 | |
| 2662 | 2793 | $opt .= $objp->ref; |
| 2663 | - if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) |
|
| 2664 | - $opt .= ' (' . $objp->ref_fourn . ')';
|
|
| 2794 | + if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) { |
|
| 2795 | + $opt .= ' (' . $objp->ref_fourn . ')'; |
|
| 2796 | + } |
|
| 2665 | 2797 | $opt .= ' - '; |
| 2666 | 2798 | $outval .= $objRef; |
| 2667 | - if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) |
|
| 2668 | - $outval .= ' (' . $objRefFourn . ')';
|
|
| 2799 | + if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) { |
|
| 2800 | + $outval .= ' (' . $objRefFourn . ')'; |
|
| 2801 | + } |
|
| 2669 | 2802 | $outval .= ' - '; |
| 2670 | 2803 | $opt .= dol_trunc($label, 72) . ' - '; |
| 2671 | 2804 | $outval .= dol_trunc($label, 72) . ' - '; |
@@ -2759,11 +2892,11 @@ discard block |
||
| 2759 | 2892 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
| 2760 | 2893 | $out .= ajax_combobox($htmlname); |
| 2761 | 2894 | |
| 2762 | - if (empty($outputmode)) |
|
| 2763 | - return $out; |
|
| 2895 | + if (empty($outputmode)) { |
|
| 2896 | + return $out; |
|
| 2897 | + } |
|
| 2764 | 2898 | return $outarray; |
| 2765 | - } |
|
| 2766 | - else {
|
|
| 2899 | + } else {
|
|
| 2767 | 2900 | dol_print_error($this->db); |
| 2768 | 2901 | } |
| 2769 | 2902 | } |
@@ -2852,8 +2985,9 @@ discard block |
||
| 2852 | 2985 | $opt .= " - "; |
| 2853 | 2986 | $opt .= price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit");
|
| 2854 | 2987 | } |
| 2855 | - if ($objp->duration) |
|
| 2856 | - $opt .= " - " . $objp->duration; |
|
| 2988 | + if ($objp->duration) { |
|
| 2989 | + $opt .= " - " . $objp->duration; |
|
| 2990 | + } |
|
| 2857 | 2991 | $opt .= "</option>\n"; |
| 2858 | 2992 | |
| 2859 | 2993 | $form .= $opt; |
@@ -2864,8 +2998,7 @@ discard block |
||
| 2864 | 2998 | $form .= '</select>'; |
| 2865 | 2999 | $this->db->free($result); |
| 2866 | 3000 | return $form; |
| 2867 | - } |
|
| 2868 | - else {
|
|
| 3001 | + } else {
|
|
| 2869 | 3002 | dol_print_error($this->db); |
| 2870 | 3003 | } |
| 2871 | 3004 | } |
@@ -2893,8 +3026,9 @@ discard block |
||
| 2893 | 3026 | $resql = $this->db->query($sql); |
| 2894 | 3027 | if ($resql) {
|
| 2895 | 3028 | print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
| 2896 | - if ($showempty) |
|
| 2897 | - print '<option value="0"> </option>'; |
|
| 3029 | + if ($showempty) { |
|
| 3030 | + print '<option value="0"> </option>'; |
|
| 3031 | + } |
|
| 2898 | 3032 | $num = $this->db->num_rows($resql); |
| 2899 | 3033 | $i = 0; |
| 2900 | 3034 | if ($num) {
|
@@ -2928,8 +3062,10 @@ discard block |
||
| 2928 | 3062 | global $langs; |
| 2929 | 3063 | |
| 2930 | 3064 | $num = count($this->cache_conditions_paiements); |
| 2931 | - if ($num > 0) |
|
| 2932 | - return 0; // Cache already loaded |
|
| 3065 | + if ($num > 0) { |
|
| 3066 | + return 0; |
|
| 3067 | + } |
|
| 3068 | + // Cache already loaded |
|
| 2933 | 3069 | |
| 2934 | 3070 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 2935 | 3071 | |
@@ -2974,8 +3110,10 @@ discard block |
||
| 2974 | 3110 | global $langs; |
| 2975 | 3111 | |
| 2976 | 3112 | $num = count($this->cache_availability); |
| 2977 | - if ($num > 0) |
|
| 2978 | - return 0; // Cache already loaded |
|
| 3113 | + if ($num > 0) { |
|
| 3114 | + return 0; |
|
| 3115 | + } |
|
| 3116 | + // Cache already loaded |
|
| 2979 | 3117 | |
| 2980 | 3118 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 2981 | 3119 | |
@@ -3026,8 +3164,9 @@ discard block |
||
| 3026 | 3164 | dol_syslog(__METHOD__ . " selected=" . $selected . ", htmlname=" . $htmlname, LOG_DEBUG); |
| 3027 | 3165 | |
| 3028 | 3166 | print '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; |
| 3029 | - if ($addempty) |
|
| 3030 | - print '<option value="0"> </option>'; |
|
| 3167 | + if ($addempty) { |
|
| 3168 | + print '<option value="0"> </option>'; |
|
| 3169 | + } |
|
| 3031 | 3170 | foreach ($this->cache_availability as $id => $arrayavailability) {
|
| 3032 | 3171 | if ($selected == $id) {
|
| 3033 | 3172 | print '<option value="' . $id . '" selected>'; |
@@ -3038,8 +3177,9 @@ discard block |
||
| 3038 | 3177 | print '</option>'; |
| 3039 | 3178 | } |
| 3040 | 3179 | print '</select>'; |
| 3041 | - if ($user->admin) |
|
| 3042 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3180 | + if ($user->admin) { |
|
| 3181 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3182 | + } |
|
| 3043 | 3183 | } |
| 3044 | 3184 | |
| 3045 | 3185 | /** |
@@ -3052,8 +3192,10 @@ discard block |
||
| 3052 | 3192 | global $langs; |
| 3053 | 3193 | |
| 3054 | 3194 | $num = count($this->cache_demand_reason); |
| 3055 | - if ($num > 0) |
|
| 3056 | - return 0; // Cache already loaded |
|
| 3195 | + if ($num > 0) { |
|
| 3196 | + return 0; |
|
| 3197 | + } |
|
| 3198 | + // Cache already loaded |
|
| 3057 | 3199 | |
| 3058 | 3200 | $sql = "SELECT rowid, code, label"; |
| 3059 | 3201 | $sql .= " FROM " . MAIN_DB_PREFIX . 'c_input_reason'; |
@@ -3069,10 +3211,14 @@ discard block |
||
| 3069 | 3211 | |
| 3070 | 3212 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 3071 | 3213 | $label = ($obj->label != '-' ? $obj->label : ''); |
| 3072 | - if ($langs->trans("DemandReasonType" . $obj->code) != ("DemandReasonType" . $obj->code))
|
|
| 3073 | - $label = $langs->trans("DemandReasonType" . $obj->code); // So translation key DemandReasonTypeSRC_XXX will work
|
|
| 3074 | - if ($langs->trans($obj->code) != $obj->code) |
|
| 3075 | - $label = $langs->trans($obj->code); // So translation key SRC_XXX will work |
|
| 3214 | + if ($langs->trans("DemandReasonType" . $obj->code) != ("DemandReasonType" . $obj->code)) { |
|
| 3215 | + $label = $langs->trans("DemandReasonType" . $obj->code); |
|
| 3216 | + } |
|
| 3217 | + // So translation key DemandReasonTypeSRC_XXX will work |
|
| 3218 | + if ($langs->trans($obj->code) != $obj->code) { |
|
| 3219 | + $label = $langs->trans($obj->code); |
|
| 3220 | + } |
|
| 3221 | + // So translation key SRC_XXX will work |
|
| 3076 | 3222 | |
| 3077 | 3223 | $tmparray[$obj->rowid]['id'] = $obj->rowid; |
| 3078 | 3224 | $tmparray[$obj->rowid]['code'] = $obj->code; |
@@ -3084,8 +3230,7 @@ discard block |
||
| 3084 | 3230 | |
| 3085 | 3231 | unset($tmparray); |
| 3086 | 3232 | return $num; |
| 3087 | - } |
|
| 3088 | - else {
|
|
| 3233 | + } else {
|
|
| 3089 | 3234 | dol_print_error($this->db); |
| 3090 | 3235 | return -1; |
| 3091 | 3236 | } |
@@ -3108,11 +3253,13 @@ discard block |
||
| 3108 | 3253 | $this->loadCacheInputReason(); |
| 3109 | 3254 | |
| 3110 | 3255 | print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
| 3111 | - if ($addempty) |
|
| 3112 | - print '<option value="0"' . (empty($selected) ? ' selected' : '') . '> </option>'; |
|
| 3256 | + if ($addempty) { |
|
| 3257 | + print '<option value="0"' . (empty($selected) ? ' selected' : '') . '> </option>'; |
|
| 3258 | + } |
|
| 3113 | 3259 | foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
|
| 3114 | - if ($arraydemandreason['code'] == $exclude) |
|
| 3115 | - continue; |
|
| 3260 | + if ($arraydemandreason['code'] == $exclude) { |
|
| 3261 | + continue; |
|
| 3262 | + } |
|
| 3116 | 3263 | |
| 3117 | 3264 | if ($selected && ($selected == $arraydemandreason['id'] || $selected == $arraydemandreason['code'])) {
|
| 3118 | 3265 | print '<option value="' . $arraydemandreason['id'] . '" selected>'; |
@@ -3124,8 +3271,9 @@ discard block |
||
| 3124 | 3271 | print '</option>'; |
| 3125 | 3272 | } |
| 3126 | 3273 | print '</select>'; |
| 3127 | - if ($user->admin) |
|
| 3128 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3274 | + if ($user->admin) { |
|
| 3275 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3276 | + } |
|
| 3129 | 3277 | } |
| 3130 | 3278 | |
| 3131 | 3279 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -3140,8 +3288,10 @@ discard block |
||
| 3140 | 3288 | global $langs; |
| 3141 | 3289 | |
| 3142 | 3290 | $num = count($this->cache_types_paiements); |
| 3143 | - if ($num > 0) |
|
| 3144 | - return $num; // Cache already loaded |
|
| 3291 | + if ($num > 0) { |
|
| 3292 | + return $num; |
|
| 3293 | + } |
|
| 3294 | + // Cache already loaded |
|
| 3145 | 3295 | |
| 3146 | 3296 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 3147 | 3297 | |
@@ -3202,12 +3352,14 @@ discard block |
||
| 3202 | 3352 | $this->load_cache_conditions_paiements(); |
| 3203 | 3353 | |
| 3204 | 3354 | // Set default value if not already set by caller |
| 3205 | - if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) |
|
| 3206 | - $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID; |
|
| 3355 | + if (empty($selected) && !empty($conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) { |
|
| 3356 | + $selected = $conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID; |
|
| 3357 | + } |
|
| 3207 | 3358 | |
| 3208 | 3359 | print '<select id="' . $htmlname . '" class="flat selectpaymentterms' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '">'; |
| 3209 | - if ($addempty) |
|
| 3210 | - print '<option value="0"> </option>'; |
|
| 3360 | + if ($addempty) { |
|
| 3361 | + print '<option value="0"> </option>'; |
|
| 3362 | + } |
|
| 3211 | 3363 | foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
| 3212 | 3364 | if ($selected == $id) {
|
| 3213 | 3365 | print '<option value="' . $id . '" selected>'; |
@@ -3218,8 +3370,9 @@ discard block |
||
| 3218 | 3370 | print '</option>'; |
| 3219 | 3371 | } |
| 3220 | 3372 | print '</select>'; |
| 3221 | - if ($user->admin && empty($noinfoadmin)) |
|
| 3222 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3373 | + if ($user->admin && empty($noinfoadmin)) { |
|
| 3374 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3375 | + } |
|
| 3223 | 3376 | } |
| 3224 | 3377 | |
| 3225 | 3378 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -3245,59 +3398,68 @@ discard block |
||
| 3245 | 3398 | dol_syslog(__METHOD__ . " " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG); |
| 3246 | 3399 | |
| 3247 | 3400 | $filterarray = array(); |
| 3248 | - if ($filtertype == 'CRDT') |
|
| 3249 | - $filterarray = array(0, 2, 3); |
|
| 3250 | - elseif ($filtertype == 'DBIT') |
|
| 3251 | - $filterarray = array(1, 2, 3); |
|
| 3252 | - elseif ($filtertype != '' && $filtertype != '-1') |
|
| 3253 | - $filterarray = explode(',', $filtertype);
|
|
| 3401 | + if ($filtertype == 'CRDT') { |
|
| 3402 | + $filterarray = array(0, 2, 3); |
|
| 3403 | + } elseif ($filtertype == 'DBIT') { |
|
| 3404 | + $filterarray = array(1, 2, 3); |
|
| 3405 | + } elseif ($filtertype != '' && $filtertype != '-1') { |
|
| 3406 | + $filterarray = explode(',', $filtertype); |
|
| 3407 | + } |
|
| 3254 | 3408 | |
| 3255 | 3409 | $this->load_cache_types_paiements(); |
| 3256 | 3410 | |
| 3257 | 3411 | print '<select id="select' . $htmlname . '" class="flat selectpaymenttypes' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '">'; |
| 3258 | - if ($empty) |
|
| 3259 | - print '<option value=""> </option>'; |
|
| 3412 | + if ($empty) { |
|
| 3413 | + print '<option value=""> </option>'; |
|
| 3414 | + } |
|
| 3260 | 3415 | foreach ($this->cache_types_paiements as $id => $arraytypes) {
|
| 3261 | 3416 | // If not good status |
| 3262 | - if ($active >= 0 && $arraytypes['active'] != $active) |
|
| 3263 | - continue; |
|
| 3417 | + if ($active >= 0 && $arraytypes['active'] != $active) { |
|
| 3418 | + continue; |
|
| 3419 | + } |
|
| 3264 | 3420 | |
| 3265 | 3421 | // On passe si on a demande de filtrer sur des modes de paiments particuliers |
| 3266 | - if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) |
|
| 3267 | - continue; |
|
| 3422 | + if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) { |
|
| 3423 | + continue; |
|
| 3424 | + } |
|
| 3268 | 3425 | |
| 3269 | 3426 | // We discard empty line if showempty is on because an empty line has already been output. |
| 3270 | - if ($empty && empty($arraytypes['code'])) |
|
| 3271 | - continue; |
|
| 3272 | - |
|
| 3273 | - if ($format == 0) |
|
| 3274 | - print '<option value="' . $id . '"'; |
|
| 3275 | - elseif ($format == 1) |
|
| 3276 | - print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3277 | - elseif ($format == 2) |
|
| 3278 | - print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3279 | - elseif ($format == 3) |
|
| 3280 | - print '<option value="' . $id . '"'; |
|
| 3427 | + if ($empty && empty($arraytypes['code'])) { |
|
| 3428 | + continue; |
|
| 3429 | + } |
|
| 3430 | + |
|
| 3431 | + if ($format == 0) { |
|
| 3432 | + print '<option value="' . $id . '"'; |
|
| 3433 | + } elseif ($format == 1) { |
|
| 3434 | + print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3435 | + } elseif ($format == 2) { |
|
| 3436 | + print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3437 | + } elseif ($format == 3) { |
|
| 3438 | + print '<option value="' . $id . '"'; |
|
| 3439 | + } |
|
| 3281 | 3440 | // Si selected est text, on compare avec code, sinon avec id |
| 3282 | - if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code'])
|
|
| 3283 | - print ' selected'; |
|
| 3284 | - elseif ($selected == $id) |
|
| 3285 | - print ' selected'; |
|
| 3441 | + if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) { |
|
| 3442 | + print ' selected'; |
|
| 3443 | + } elseif ($selected == $id) { |
|
| 3444 | + print ' selected'; |
|
| 3445 | + } |
|
| 3286 | 3446 | print '>'; |
| 3287 | - if ($format == 0) |
|
| 3288 | - $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3289 | - elseif ($format == 1) |
|
| 3290 | - $value = $arraytypes['code']; |
|
| 3291 | - elseif ($format == 2) |
|
| 3292 | - $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3293 | - elseif ($format == 3) |
|
| 3294 | - $value = $arraytypes['code']; |
|
| 3447 | + if ($format == 0) { |
|
| 3448 | + $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3449 | + } elseif ($format == 1) { |
|
| 3450 | + $value = $arraytypes['code']; |
|
| 3451 | + } elseif ($format == 2) { |
|
| 3452 | + $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3453 | + } elseif ($format == 3) { |
|
| 3454 | + $value = $arraytypes['code']; |
|
| 3455 | + } |
|
| 3295 | 3456 | print $value ? $value : ' '; |
| 3296 | 3457 | print '</option>'; |
| 3297 | 3458 | } |
| 3298 | 3459 | print '</select>'; |
| 3299 | - if ($user->admin && !$noadmininfo) |
|
| 3300 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3460 | + if ($user->admin && !$noadmininfo) { |
|
| 3461 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3462 | + } |
|
| 3301 | 3463 | } |
| 3302 | 3464 | |
| 3303 | 3465 | /** |
@@ -3351,8 +3513,9 @@ discard block |
||
| 3351 | 3513 | $sql = "SELECT rowid, code, libelle as label"; |
| 3352 | 3514 | $sql .= " FROM " . MAIN_DB_PREFIX . "c_shipment_mode"; |
| 3353 | 3515 | $sql .= " WHERE active > 0"; |
| 3354 | - if ($filtre) |
|
| 3355 | - $sql .= " AND " . $filtre; |
|
| 3516 | + if ($filtre) { |
|
| 3517 | + $sql .= " AND " . $filtre; |
|
| 3518 | + } |
|
| 3356 | 3519 | $sql .= " ORDER BY libelle ASC"; |
| 3357 | 3520 | |
| 3358 | 3521 | dol_syslog(get_class($this) . "::selectShippingMode", LOG_DEBUG); |
@@ -3377,8 +3540,9 @@ discard block |
||
| 3377 | 3540 | $i++; |
| 3378 | 3541 | } |
| 3379 | 3542 | print "</select>"; |
| 3380 | - if ($user->admin) |
|
| 3381 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3543 | + if ($user->admin) { |
|
| 3544 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3545 | + } |
|
| 3382 | 3546 | } else {
|
| 3383 | 3547 | print $langs->trans("NoShippingMethodDefined");
|
| 3384 | 3548 | } |
@@ -3491,8 +3655,9 @@ discard block |
||
| 3491 | 3655 | |
| 3492 | 3656 | $resql = $this->db->query($sql); |
| 3493 | 3657 | if ($resql && $this->db->num_rows($resql) > 0) {
|
| 3494 | - if ($showempty) |
|
| 3495 | - $return .= '<option value="none"></option>'; |
|
| 3658 | + if ($showempty) { |
|
| 3659 | + $return .= '<option value="none"></option>'; |
|
| 3660 | + } |
|
| 3496 | 3661 | |
| 3497 | 3662 | while ($res = $this->db->fetch_object($resql)) {
|
| 3498 | 3663 | $unitLabel = $res->label; |
@@ -3535,10 +3700,12 @@ discard block |
||
| 3535 | 3700 | $sql = "SELECT rowid, label, bank, clos as status, currency_code"; |
| 3536 | 3701 | $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; |
| 3537 | 3702 | $sql .= " WHERE entity IN (" . getEntity('bank_account') . ")";
|
| 3538 | - if ($statut != 2) |
|
| 3539 | - $sql .= " AND clos = '" . $statut . "'"; |
|
| 3540 | - if ($filtre) |
|
| 3541 | - $sql .= " AND " . $filtre; |
|
| 3703 | + if ($statut != 2) { |
|
| 3704 | + $sql .= " AND clos = '" . $statut . "'"; |
|
| 3705 | + } |
|
| 3706 | + if ($filtre) { |
|
| 3707 | + $sql .= " AND " . $filtre; |
|
| 3708 | + } |
|
| 3542 | 3709 | $sql .= " ORDER BY label"; |
| 3543 | 3710 | |
| 3544 | 3711 | dol_syslog(get_class($this) . "::select_comptes", LOG_DEBUG); |
@@ -3560,23 +3727,24 @@ discard block |
||
| 3560 | 3727 | print '<option value="' . $obj->rowid . '">'; |
| 3561 | 3728 | } |
| 3562 | 3729 | print trim($obj->label); |
| 3563 | - if ($showcurrency) |
|
| 3564 | - print ' (' . $obj->currency_code . ')';
|
|
| 3565 | - if ($statut == 2 && $obj->status == 1) |
|
| 3566 | - print ' (' . $langs->trans("Closed") . ')';
|
|
| 3730 | + if ($showcurrency) { |
|
| 3731 | + print ' (' . $obj->currency_code . ')'; |
|
| 3732 | + } |
|
| 3733 | + if ($statut == 2 && $obj->status == 1) { |
|
| 3734 | + print ' (' . $langs->trans("Closed") . ')'; |
|
| 3735 | + } |
|
| 3567 | 3736 | print '</option>'; |
| 3568 | 3737 | $i++; |
| 3569 | 3738 | } |
| 3570 | 3739 | print "</select>"; |
| 3740 | + } else {
|
|
| 3741 | + if ($statut == 0) { |
|
| 3742 | + print '<span class="opacitymedium">' . $langs->trans("NoActiveBankAccountDefined") . '</span>'; |
|
| 3743 | + } else { |
|
| 3744 | + print '<span class="opacitymedium">' . $langs->trans("NoBankAccountFound") . '</span>'; |
|
| 3745 | + } |
|
| 3571 | 3746 | } |
| 3572 | - else {
|
|
| 3573 | - if ($statut == 0) |
|
| 3574 | - print '<span class="opacitymedium">' . $langs->trans("NoActiveBankAccountDefined") . '</span>';
|
|
| 3575 | - else |
|
| 3576 | - print '<span class="opacitymedium">' . $langs->trans("NoBankAccountFound") . '</span>';
|
|
| 3577 | - } |
|
| 3578 | - } |
|
| 3579 | - else {
|
|
| 3747 | + } else {
|
|
| 3580 | 3748 | dol_print_error($this->db); |
| 3581 | 3749 | } |
| 3582 | 3750 | |
@@ -3600,8 +3768,9 @@ discard block |
||
| 3600 | 3768 | print '<input type="hidden" name="action" value="setbankaccount">'; |
| 3601 | 3769 | print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
| 3602 | 3770 | $nbaccountfound = $this->select_comptes($selected, $htmlname, 0, '', $addempty); |
| 3603 | - if ($nbaccountfound > 0) |
|
| 3604 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 3771 | + if ($nbaccountfound > 0) { |
|
| 3772 | + print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">'; |
|
| 3773 | + } |
|
| 3605 | 3774 | print '</form>'; |
| 3606 | 3775 | } else {
|
| 3607 | 3776 | |
@@ -3611,8 +3780,9 @@ discard block |
||
| 3611 | 3780 | require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; |
| 3612 | 3781 | $bankstatic = new Account($this->db); |
| 3613 | 3782 | $result = $bankstatic->fetch($selected); |
| 3614 | - if ($result) |
|
| 3615 | - print $bankstatic->getNomUrl(1); |
|
| 3783 | + if ($result) { |
|
| 3784 | + print $bankstatic->getNomUrl(1); |
|
| 3785 | + } |
|
| 3616 | 3786 | } else {
|
| 3617 | 3787 | print " "; |
| 3618 | 3788 | } |
@@ -3658,15 +3828,16 @@ discard block |
||
| 3658 | 3828 | $i = 0; |
| 3659 | 3829 | while ($i < $num) {
|
| 3660 | 3830 | $objp = $this->db->fetch_object($result); |
| 3661 | - if ($objp) |
|
| 3662 | - $cate_arbo[$objp->rowid] = array('id' => $objp->rowid, 'fulllabel' => $objp->label);
|
|
| 3831 | + if ($objp) { |
|
| 3832 | + $cate_arbo[$objp->rowid] = array('id' => $objp->rowid, 'fulllabel' => $objp->label); |
|
| 3833 | + } |
|
| 3663 | 3834 | $i++; |
| 3664 | 3835 | } |
| 3665 | 3836 | $this->db->free($result); |
| 3666 | - } else |
|
| 3667 | - dol_print_error($this->db); |
|
| 3668 | - } |
|
| 3669 | - else {
|
|
| 3837 | + } else { |
|
| 3838 | + dol_print_error($this->db); |
|
| 3839 | + } |
|
| 3840 | + } else {
|
|
| 3670 | 3841 | $cat = new Categorie($this->db); |
| 3671 | 3842 | $cate_arbo = $cat->get_full_arbo($type, $excludeafterid); |
| 3672 | 3843 | } |
@@ -3674,9 +3845,9 @@ discard block |
||
| 3674 | 3845 | $output = '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">'; |
| 3675 | 3846 | $outarray = array(); |
| 3676 | 3847 | if (is_array($cate_arbo)) {
|
| 3677 | - if (!count($cate_arbo)) |
|
| 3678 | - $output .= '<option value="-1" disabled>' . $langs->trans("NoCategoriesDefined") . '</option>';
|
|
| 3679 | - else {
|
|
| 3848 | + if (!count($cate_arbo)) { |
|
| 3849 | + $output .= '<option value="-1" disabled>' . $langs->trans("NoCategoriesDefined") . '</option>'; |
|
| 3850 | + } else {
|
|
| 3680 | 3851 | $output .= '<option value="-1"> </option>'; |
| 3681 | 3852 | foreach ($cate_arbo as $key => $value) {
|
| 3682 | 3853 | if ($cate_arbo[$key]['id'] == $selected || ($selected == 'auto' && count($cate_arbo) == 1)) {
|
@@ -3693,8 +3864,9 @@ discard block |
||
| 3693 | 3864 | $output .= '</select>'; |
| 3694 | 3865 | $output .= "\n"; |
| 3695 | 3866 | |
| 3696 | - if ($outputmode) |
|
| 3697 | - return $outarray; |
|
| 3867 | + if ($outputmode) { |
|
| 3868 | + return $outarray; |
|
| 3869 | + } |
|
| 3698 | 3870 | return $output; |
| 3699 | 3871 | } |
| 3700 | 3872 | |
@@ -3758,8 +3930,9 @@ discard block |
||
| 3758 | 3930 | |
| 3759 | 3931 | // Clean parameters |
| 3760 | 3932 | $newselectedchoice = empty($selectedchoice) ? "no" : $selectedchoice; |
| 3761 | - if ($conf->browser->layout == 'phone') |
|
| 3762 | - $width = '95%'; |
|
| 3933 | + if ($conf->browser->layout == 'phone') { |
|
| 3934 | + $width = '95%'; |
|
| 3935 | + } |
|
| 3763 | 3936 | |
| 3764 | 3937 | if (is_array($formquestion) && !empty($formquestion)) {
|
| 3765 | 3938 | // First add hidden fields and value |
@@ -3773,8 +3946,9 @@ discard block |
||
| 3773 | 3946 | |
| 3774 | 3947 | // Now add questions |
| 3775 | 3948 | $more .= '<table class="paddingtopbottomonly" width="100%">' . "\n"; |
| 3776 | - if (!empty($formquestion['text'])) |
|
| 3777 | - $more .= '<tr><td colspan="2">' . $formquestion['text'] . '</td></tr>' . "\n"; |
|
| 3949 | + if (!empty($formquestion['text'])) { |
|
| 3950 | + $more .= '<tr><td colspan="2">' . $formquestion['text'] . '</td></tr>' . "\n"; |
|
| 3951 | + } |
|
| 3778 | 3952 | foreach ($formquestion as $key => $input) {
|
| 3779 | 3953 | if (is_array($input) && !empty($input)) {
|
| 3780 | 3954 | $size = (!empty($input['size']) ? ' size="' . $input['size'] . '"' : ''); |
@@ -3787,42 +3961,45 @@ discard block |
||
| 3787 | 3961 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td><td align="left"><input type="password" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '"' . $size . ' value="' . $input['value'] . '"' . $moreattr . ' /></td></tr>' . "\n";
|
| 3788 | 3962 | } elseif ($input['type'] == 'select') {
|
| 3789 | 3963 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>';
|
| 3790 | - if (!empty($input['label'])) |
|
| 3791 | - $more .= $input['label'] . '</td><td class="tdtop" align="left">'; |
|
| 3964 | + if (!empty($input['label'])) { |
|
| 3965 | + $more .= $input['label'] . '</td><td class="tdtop" align="left">'; |
|
| 3966 | + } |
|
| 3792 | 3967 | $more .= $this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss); |
| 3793 | 3968 | $more .= '</td></tr>' . "\n"; |
| 3794 | - } |
|
| 3795 | - elseif ($input['type'] == 'checkbox') {
|
|
| 3969 | + } elseif ($input['type'] == 'checkbox') {
|
|
| 3796 | 3970 | $more .= '<tr>'; |
| 3797 | 3971 | $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . ' </td><td align="left">';
|
| 3798 | 3972 | $more .= '<input type="checkbox" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '"' . $moreattr; |
| 3799 | - if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') |
|
| 3800 | - $more .= ' checked'; |
|
| 3801 | - if (is_bool($input['value']) && $input['value']) |
|
| 3802 | - $more .= ' checked'; |
|
| 3803 | - if (isset($input['disabled'])) |
|
| 3804 | - $more .= ' disabled'; |
|
| 3973 | + if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') { |
|
| 3974 | + $more .= ' checked'; |
|
| 3975 | + } |
|
| 3976 | + if (is_bool($input['value']) && $input['value']) { |
|
| 3977 | + $more .= ' checked'; |
|
| 3978 | + } |
|
| 3979 | + if (isset($input['disabled'])) { |
|
| 3980 | + $more .= ' disabled'; |
|
| 3981 | + } |
|
| 3805 | 3982 | $more .= ' /></td>'; |
| 3806 | 3983 | $more .= '</tr>' . "\n"; |
| 3807 | - } |
|
| 3808 | - elseif ($input['type'] == 'radio') {
|
|
| 3984 | + } elseif ($input['type'] == 'radio') {
|
|
| 3809 | 3985 | $i = 0; |
| 3810 | 3986 | foreach ($input['values'] as $selkey => $selval) {
|
| 3811 | 3987 | $more .= '<tr>'; |
| 3812 | - if ($i == 0) |
|
| 3813 | - $more .= '<td' . (empty($input['tdclass']) ? ' class="tdtop"' : (' class="tdtop ' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>';
|
|
| 3814 | - else |
|
| 3815 | - $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '> </td>';
|
|
| 3988 | + if ($i == 0) { |
|
| 3989 | + $more .= '<td' . (empty($input['tdclass']) ? ' class="tdtop"' : (' class="tdtop ' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>'; |
|
| 3990 | + } else { |
|
| 3991 | + $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '> </td>'; |
|
| 3992 | + } |
|
| 3816 | 3993 | $more .= '<td><input type="radio" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '" value="' . $selkey . '"' . $moreattr; |
| 3817 | - if ($input['disabled']) |
|
| 3818 | - $more .= ' disabled'; |
|
| 3994 | + if ($input['disabled']) { |
|
| 3995 | + $more .= ' disabled'; |
|
| 3996 | + } |
|
| 3819 | 3997 | $more .= ' /> '; |
| 3820 | 3998 | $more .= $selval; |
| 3821 | 3999 | $more .= '</td></tr>' . "\n"; |
| 3822 | 4000 | $i++; |
| 3823 | 4001 | } |
| 3824 | - } |
|
| 3825 | - elseif ($input['type'] == 'date') {
|
|
| 4002 | + } elseif ($input['type'] == 'date') {
|
|
| 3826 | 4003 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>';
|
| 3827 | 4004 | $more .= '<td align="left">'; |
| 3828 | 4005 | $more .= $this->selectDate($input['value'], $input['name'], 0, 0, 0, '', 1, 0); |
@@ -3834,13 +4011,12 @@ discard block |
||
| 3834 | 4011 | $formquestion[] = array('name' => $input['name'] . 'min');
|
| 3835 | 4012 | } elseif ($input['type'] == 'other') {
|
| 3836 | 4013 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>';
|
| 3837 | - if (!empty($input['label'])) |
|
| 3838 | - $more .= $input['label'] . '</td><td align="left">'; |
|
| 4014 | + if (!empty($input['label'])) { |
|
| 4015 | + $more .= $input['label'] . '</td><td align="left">'; |
|
| 4016 | + } |
|
| 3839 | 4017 | $more .= $input['value']; |
| 3840 | 4018 | $more .= '</td></tr>' . "\n"; |
| 3841 | - } |
|
| 3842 | - |
|
| 3843 | - elseif ($input['type'] == 'onecolumn') {
|
|
| 4019 | + } elseif ($input['type'] == 'onecolumn') {
|
|
| 3844 | 4020 | $more .= '<tr><td colspan="2" align="left">'; |
| 3845 | 4021 | $more .= $input['value']; |
| 3846 | 4022 | $more .= '</td></tr>' . "\n"; |
@@ -3853,10 +4029,12 @@ discard block |
||
| 3853 | 4029 | // JQUI method dialog is broken with jmobile, we use standard HTML. |
| 3854 | 4030 | // Note: When using dol_use_jmobile or no js, you must also check code for button use a GET url with action=xxx and check that you also output the confirm code when action=xxx |
| 3855 | 4031 | // See page product/card.php for example |
| 3856 | - if (!empty($conf->dol_use_jmobile)) |
|
| 3857 | - $useajax = 0; |
|
| 3858 | - if (empty($conf->use_javascript_ajax)) |
|
| 3859 | - $useajax = 0; |
|
| 4032 | + if (!empty($conf->dol_use_jmobile)) { |
|
| 4033 | + $useajax = 0; |
|
| 4034 | + } |
|
| 4035 | + if (empty($conf->use_javascript_ajax)) { |
|
| 4036 | + $useajax = 0; |
|
| 4037 | + } |
|
| 3860 | 4038 | |
| 3861 | 4039 | if ($useajax) {
|
| 3862 | 4040 | $autoOpen = true; |
@@ -3874,10 +4052,12 @@ discard block |
||
| 3874 | 4052 | if (is_array($formquestion)) {
|
| 3875 | 4053 | foreach ($formquestion as $key => $input) {
|
| 3876 | 4054 | //print "xx ".$key." rr ".is_array($input)."<br>\n"; |
| 3877 | - if (is_array($input) && isset($input['name'])) |
|
| 3878 | - array_push($inputok, $input['name']); |
|
| 3879 | - if (isset($input['inputko']) && $input['inputko'] == 1) |
|
| 3880 | - array_push($inputko, $input['name']); |
|
| 4055 | + if (is_array($input) && isset($input['name'])) { |
|
| 4056 | + array_push($inputok, $input['name']); |
|
| 4057 | + } |
|
| 4058 | + if (isset($input['inputko']) && $input['inputko'] == 1) { |
|
| 4059 | + array_push($inputko, $input['name']); |
|
| 4060 | + } |
|
| 3881 | 4061 | } |
| 3882 | 4062 | } |
| 3883 | 4063 | // Show JQuery confirm box. Note that global var $useglobalvars is used inside this template |
@@ -3962,12 +4142,14 @@ discard block |
||
| 3962 | 4142 | } else {
|
| 3963 | 4143 | $formconfirm .= "\n<!-- begin formconfirm page=" . $page . " -->\n"; |
| 3964 | 4144 | |
| 3965 | - if (empty($disableformtag)) |
|
| 3966 | - $formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . "\n"; |
|
| 4145 | + if (empty($disableformtag)) { |
|
| 4146 | + $formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . "\n"; |
|
| 4147 | + } |
|
| 3967 | 4148 | |
| 3968 | 4149 | $formconfirm .= '<input type="hidden" name="action" value="' . $action . '">' . "\n"; |
| 3969 | - if (empty($disableformtag)) |
|
| 3970 | - $formconfirm .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">' . "\n"; |
|
| 4150 | + if (empty($disableformtag)) { |
|
| 4151 | + $formconfirm .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">' . "\n"; |
|
| 4152 | + } |
|
| 3971 | 4153 | |
| 3972 | 4154 | $formconfirm .= '<table width="100%" class="valid">' . "\n"; |
| 3973 | 4155 | |
@@ -3992,8 +4174,9 @@ discard block |
||
| 3992 | 4174 | |
| 3993 | 4175 | $formconfirm .= '</table>' . "\n"; |
| 3994 | 4176 | |
| 3995 | - if (empty($disableformtag)) |
|
| 3996 | - $formconfirm .= "</form>\n"; |
|
| 4177 | + if (empty($disableformtag)) { |
|
| 4178 | + $formconfirm .= "</form>\n"; |
|
| 4179 | + } |
|
| 3997 | 4180 | $formconfirm .= '<br>'; |
| 3998 | 4181 | |
| 3999 | 4182 | $formconfirm .= "<!-- end formconfirm -->\n"; |
@@ -4183,14 +4366,16 @@ discard block |
||
| 4183 | 4366 | $ret .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '"></td>';
|
| 4184 | 4367 | $ret .= '</tr></table></form>'; |
| 4185 | 4368 | } else {
|
| 4186 | - if ($displayhour) |
|
| 4187 | - $ret .= dol_print_date($selected, 'dayhour'); |
|
| 4188 | - else |
|
| 4189 | - $ret .= dol_print_date($selected, 'day'); |
|
| 4369 | + if ($displayhour) { |
|
| 4370 | + $ret .= dol_print_date($selected, 'dayhour'); |
|
| 4371 | + } else { |
|
| 4372 | + $ret .= dol_print_date($selected, 'day'); |
|
| 4373 | + } |
|
| 4190 | 4374 | } |
| 4191 | 4375 | |
| 4192 | - if (empty($nooutput)) |
|
| 4193 | - print $ret; |
|
| 4376 | + if (empty($nooutput)) { |
|
| 4377 | + print $ret; |
|
| 4378 | + } |
|
| 4194 | 4379 | return $ret; |
| 4195 | 4380 | } |
| 4196 | 4381 | |
@@ -4316,10 +4501,10 @@ discard block |
||
| 4316 | 4501 | } else {
|
| 4317 | 4502 | if (!empty($rate)) {
|
| 4318 | 4503 | print price($rate, 1, $langs, 1, 0); |
| 4319 | - if ($currency && $rate != 1) |
|
| 4320 | - print ' (' . price($rate, 1, $langs, 1, 0) . ' ' . $currency . ' = 1 ' . $conf->currency . ')';
|
|
| 4321 | - } |
|
| 4322 | - else {
|
|
| 4504 | + if ($currency && $rate != 1) { |
|
| 4505 | + print ' (' . price($rate, 1, $langs, 1, 0) . ' ' . $currency . ' = 1 ' . $conf->currency . ')'; |
|
| 4506 | + } |
|
| 4507 | + } else {
|
|
| 4323 | 4508 | print 1; |
| 4324 | 4509 | } |
| 4325 | 4510 | } |
@@ -4352,34 +4537,41 @@ discard block |
||
| 4352 | 4537 | print '<div class="inline-block">'; |
| 4353 | 4538 | if (!empty($discount_type)) {
|
| 4354 | 4539 | if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
| 4355 | - if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") |
|
| 4356 | - $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4357 | - else |
|
| 4358 | - $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4359 | - } |
|
| 4360 | - else {
|
|
| 4361 | - if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") |
|
| 4362 | - $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
|
| 4363 | - else |
|
| 4364 | - $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4540 | + if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") { |
|
| 4541 | + $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
|
| 4542 | + } |
|
| 4543 | + // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4544 | + else { |
|
| 4545 | + $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4546 | + } |
|
| 4547 | + } else {
|
|
| 4548 | + if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") { |
|
| 4549 | + $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
|
| 4550 | + } else { |
|
| 4551 | + $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4552 | + } |
|
| 4365 | 4553 | } |
| 4366 | 4554 | } else {
|
| 4367 | 4555 | if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
| 4368 | - if (!$filter || $filter == "fk_facture_source IS NULL") |
|
| 4369 | - $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4370 | - else |
|
| 4371 | - $translationKey = 'CompanyHasCreditNote'; |
|
| 4372 | - } |
|
| 4373 | - else {
|
|
| 4374 | - if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") |
|
| 4375 | - $translationKey = 'CompanyHasAbsoluteDiscount'; |
|
| 4376 | - else |
|
| 4377 | - $translationKey = 'CompanyHasCreditNote'; |
|
| 4556 | + if (!$filter || $filter == "fk_facture_source IS NULL") { |
|
| 4557 | + $translationKey = 'CompanyHasAbsoluteDiscount'; |
|
| 4558 | + } |
|
| 4559 | + // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4560 | + else { |
|
| 4561 | + $translationKey = 'CompanyHasCreditNote'; |
|
| 4562 | + } |
|
| 4563 | + } else {
|
|
| 4564 | + if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") { |
|
| 4565 | + $translationKey = 'CompanyHasAbsoluteDiscount'; |
|
| 4566 | + } else { |
|
| 4567 | + $translationKey = 'CompanyHasCreditNote'; |
|
| 4568 | + } |
|
| 4378 | 4569 | } |
| 4379 | 4570 | } |
| 4380 | 4571 | print $langs->trans($translationKey, price($amount, 0, $langs, 0, 0, -1, $conf->currency)); |
| 4381 | - if (empty($hidelist)) |
|
| 4382 | - print ': '; |
|
| 4572 | + if (empty($hidelist)) { |
|
| 4573 | + print ': '; |
|
| 4574 | + } |
|
| 4383 | 4575 | print '</div>'; |
| 4384 | 4576 | if (empty($hidelist)) {
|
| 4385 | 4577 | print '<div class="inline-block" style="padding-right: 10px">'; |
@@ -4389,15 +4581,18 @@ discard block |
||
| 4389 | 4581 | } else {
|
| 4390 | 4582 | $newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available |
| 4391 | 4583 | } |
| 4392 | - if ($filter) |
|
| 4393 | - $newfilter .= ' AND (' . $filter . ')';
|
|
| 4584 | + if ($filter) { |
|
| 4585 | + $newfilter .= ' AND (' . $filter . ')'; |
|
| 4586 | + } |
|
| 4394 | 4587 | $nbqualifiedlines = $this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue); |
| 4395 | 4588 | if ($nbqualifiedlines > 0) {
|
| 4396 | 4589 | print ' <input type="submit" class="button" value="' . dol_escape_htmltag($langs->trans("UseLine")) . '"';
|
| 4397 | - if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") |
|
| 4398 | - print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"';
|
|
| 4399 | - if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") |
|
| 4400 | - print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"';
|
|
| 4590 | + if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") { |
|
| 4591 | + print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"'; |
|
| 4592 | + } |
|
| 4593 | + if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") { |
|
| 4594 | + print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"'; |
|
| 4595 | + } |
|
| 4401 | 4596 | |
| 4402 | 4597 | print '>'; |
| 4403 | 4598 | } |
@@ -4498,10 +4693,11 @@ discard block |
||
| 4498 | 4693 | } |
| 4499 | 4694 | } |
| 4500 | 4695 | |
| 4501 | - if ($nooutput) |
|
| 4502 | - return $out; |
|
| 4503 | - else |
|
| 4504 | - print $out; |
|
| 4696 | + if ($nooutput) { |
|
| 4697 | + return $out; |
|
| 4698 | + } else { |
|
| 4699 | + print $out; |
|
| 4700 | + } |
|
| 4505 | 4701 | } |
| 4506 | 4702 | |
| 4507 | 4703 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -4534,8 +4730,10 @@ discard block |
||
| 4534 | 4730 | |
| 4535 | 4731 | $out = ''; |
| 4536 | 4732 | |
| 4537 | - if ($selected == 'euro' || $selected == 'euros') |
|
| 4538 | - $selected = 'EUR'; // Pour compatibilite |
|
| 4733 | + if ($selected == 'euro' || $selected == 'euros') { |
|
| 4734 | + $selected = 'EUR'; |
|
| 4735 | + } |
|
| 4736 | + // Pour compatibilite |
|
| 4539 | 4737 | |
| 4540 | 4738 | $out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname . '" id="' . $htmlname . '">'; |
| 4541 | 4739 | foreach ($langs->cache_currencies as $code_iso => $currency) {
|
@@ -4549,8 +4747,9 @@ discard block |
||
| 4549 | 4747 | $out .= '</option>'; |
| 4550 | 4748 | } |
| 4551 | 4749 | $out .= '</select>'; |
| 4552 | - if ($user->admin) |
|
| 4553 | - $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 4750 | + if ($user->admin) { |
|
| 4751 | + $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 4752 | + } |
|
| 4554 | 4753 | |
| 4555 | 4754 | // Make select dynamic |
| 4556 | 4755 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
@@ -4579,14 +4778,16 @@ discard block |
||
| 4579 | 4778 | $sql .= " WHERE entity IN ('" . getEntity('mutlicurrency') . "')";
|
| 4580 | 4779 | $resql = $db->query($sql); |
| 4581 | 4780 | if ($resql) {
|
| 4582 | - while ($obj = $db->fetch_object($resql)) |
|
| 4583 | - $TCurrency[$obj->code] = $obj->code; |
|
| 4781 | + while ($obj = $db->fetch_object($resql)) { |
|
| 4782 | + $TCurrency[$obj->code] = $obj->code; |
|
| 4783 | + } |
|
| 4584 | 4784 | } |
| 4585 | 4785 | |
| 4586 | 4786 | $out = ''; |
| 4587 | 4787 | $out .= '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">'; |
| 4588 | - if ($useempty) |
|
| 4589 | - $out .= '<option value=""></option>'; |
|
| 4788 | + if ($useempty) { |
|
| 4789 | + $out .= '<option value=""></option>'; |
|
| 4790 | + } |
|
| 4590 | 4791 | // If company current currency not in table, we add it into list. Should always be available. |
| 4591 | 4792 | if (!in_array($conf->currency, $TCurrency)) {
|
| 4592 | 4793 | $TCurrency[$conf->currency] = $conf->currency; |
@@ -4594,10 +4795,11 @@ discard block |
||
| 4594 | 4795 | if (count($TCurrency) > 0) {
|
| 4595 | 4796 | foreach ($langs->cache_currencies as $code_iso => $currency) {
|
| 4596 | 4797 | if (isset($TCurrency[$code_iso])) {
|
| 4597 | - if (!empty($selected) && $selected == $code_iso) |
|
| 4598 | - $out .= '<option value="' . $code_iso . '" selected="selected">'; |
|
| 4599 | - else |
|
| 4600 | - $out .= '<option value="' . $code_iso . '">'; |
|
| 4798 | + if (!empty($selected) && $selected == $code_iso) { |
|
| 4799 | + $out .= '<option value="' . $code_iso . '" selected="selected">'; |
|
| 4800 | + } else { |
|
| 4801 | + $out .= '<option value="' . $code_iso . '">'; |
|
| 4802 | + } |
|
| 4601 | 4803 | |
| 4602 | 4804 | $out .= $currency['label']; |
| 4603 | 4805 | $out .= ' (' . $langs->getCurrencySymbol($code_iso) . ')';
|
@@ -4627,8 +4829,10 @@ discard block |
||
| 4627 | 4829 | global $langs; |
| 4628 | 4830 | |
| 4629 | 4831 | $num = count($this->cache_vatrates); |
| 4630 | - if ($num > 0) |
|
| 4631 | - return $num; // Cache already loaded |
|
| 4832 | + if ($num > 0) { |
|
| 4833 | + return $num; |
|
| 4834 | + } |
|
| 4835 | + // Cache already loaded |
|
| 4632 | 4836 | |
| 4633 | 4837 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 4634 | 4838 | |
@@ -4657,20 +4861,23 @@ discard block |
||
| 4657 | 4861 | $this->cache_vatrates[$i]['label'] = $obj->taux . '%' . ($obj->code ? ' (' . $obj->code . ')' : ''); // Label must contains only 0-9 , . % or *
|
| 4658 | 4862 | $this->cache_vatrates[$i]['labelallrates'] = $obj->taux . '/' . ($obj->localtax1 ? $obj->localtax1 : '0') . '/' . ($obj->localtax2 ? $obj->localtax2 : '0') . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
|
| 4659 | 4863 | $positiverates = ''; |
| 4660 | - if ($obj->taux) |
|
| 4661 | - $positiverates .= ($positiverates ? '/' : '') . $obj->taux; |
|
| 4662 | - if ($obj->localtax1) |
|
| 4663 | - $positiverates .= ($positiverates ? '/' : '') . $obj->localtax1; |
|
| 4664 | - if ($obj->localtax2) |
|
| 4665 | - $positiverates .= ($positiverates ? '/' : '') . $obj->localtax2; |
|
| 4666 | - if (empty($positiverates)) |
|
| 4667 | - $positiverates = '0'; |
|
| 4864 | + if ($obj->taux) { |
|
| 4865 | + $positiverates .= ($positiverates ? '/' : '') . $obj->taux; |
|
| 4866 | + } |
|
| 4867 | + if ($obj->localtax1) { |
|
| 4868 | + $positiverates .= ($positiverates ? '/' : '') . $obj->localtax1; |
|
| 4869 | + } |
|
| 4870 | + if ($obj->localtax2) { |
|
| 4871 | + $positiverates .= ($positiverates ? '/' : '') . $obj->localtax2; |
|
| 4872 | + } |
|
| 4873 | + if (empty($positiverates)) { |
|
| 4874 | + $positiverates = '0'; |
|
| 4875 | + } |
|
| 4668 | 4876 | $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
|
| 4669 | 4877 | } |
| 4670 | 4878 | |
| 4671 | 4879 | return $num; |
| 4672 | - } |
|
| 4673 | - else {
|
|
| 4880 | + } else {
|
|
| 4674 | 4881 | $this->error = '<font class="error">' . $langs->trans("ErrorNoVATRateDefinedForSellerCountry", $country_code) . '</font>';
|
| 4675 | 4882 | return -1; |
| 4676 | 4883 | } |
@@ -4807,16 +5014,19 @@ discard block |
||
| 4807 | 5014 | $selectedfound = false; |
| 4808 | 5015 | foreach ($this->cache_vatrates as $rate) {
|
| 4809 | 5016 | // Keep only 0 if seller is not subject to VAT |
| 4810 | - if ($disabled && $rate['txtva'] != 0) |
|
| 4811 | - continue; |
|
| 5017 | + if ($disabled && $rate['txtva'] != 0) { |
|
| 5018 | + continue; |
|
| 5019 | + } |
|
| 4812 | 5020 | |
| 4813 | 5021 | // Define key to use into select list |
| 4814 | 5022 | $key = $rate['txtva']; |
| 4815 | 5023 | $key .= $rate['nprtva'] ? '*' : ''; |
| 4816 | - if ($mode > 0 && $rate['code']) |
|
| 4817 | - $key .= ' (' . $rate['code'] . ')';
|
|
| 4818 | - if ($mode < 0) |
|
| 4819 | - $key = $rate['rowid']; |
|
| 5024 | + if ($mode > 0 && $rate['code']) { |
|
| 5025 | + $key .= ' (' . $rate['code'] . ')'; |
|
| 5026 | + } |
|
| 5027 | + if ($mode < 0) { |
|
| 5028 | + $key = $rate['rowid']; |
|
| 5029 | + } |
|
| 4820 | 5030 | |
| 4821 | 5031 | $return .= '<option value="' . $key . '"'; |
| 4822 | 5032 | if (!$selectedfound) {
|
@@ -4843,10 +5053,10 @@ discard block |
||
| 4843 | 5053 | $return .= '</option>'; |
| 4844 | 5054 | } |
| 4845 | 5055 | |
| 4846 | - if (!$options_only) |
|
| 4847 | - $return .= '</select>'; |
|
| 4848 | - } |
|
| 4849 | - else {
|
|
| 5056 | + if (!$options_only) { |
|
| 5057 | + $return .= '</select>'; |
|
| 5058 | + } |
|
| 5059 | + } else {
|
|
| 4850 | 5060 | $return .= $this->error; |
| 4851 | 5061 | } |
| 4852 | 5062 | |
@@ -4918,12 +5128,15 @@ discard block |
||
| 4918 | 5128 | |
| 4919 | 5129 | $retstring = ''; |
| 4920 | 5130 | |
| 4921 | - if ($prefix == '') |
|
| 4922 | - $prefix = 're'; |
|
| 4923 | - if ($h == '') |
|
| 4924 | - $h = 0; |
|
| 4925 | - if ($m == '') |
|
| 4926 | - $m = 0; |
|
| 5131 | + if ($prefix == '') { |
|
| 5132 | + $prefix = 're'; |
|
| 5133 | + } |
|
| 5134 | + if ($h == '') { |
|
| 5135 | + $h = 0; |
|
| 5136 | + } |
|
| 5137 | + if ($m == '') { |
|
| 5138 | + $m = 0; |
|
| 5139 | + } |
|
| 4927 | 5140 | $emptydate = 0; |
| 4928 | 5141 | $emptyhours = 0; |
| 4929 | 5142 | if ($empty == 1) {
|
@@ -4972,10 +5185,12 @@ discard block |
||
| 4972 | 5185 | $smin = !isset($conf->global->MAIN_DEFAULT_DATE_MIN) ? ($h == -1 ? '59' : '') : $conf->global->MAIN_DEFAULT_DATE_MIN; |
| 4973 | 5186 | $ssec = !isset($conf->global->MAIN_DEFAULT_DATE_SEC) ? ($h == -1 ? '59' : '') : $conf->global->MAIN_DEFAULT_DATE_SEC; |
| 4974 | 5187 | } |
| 4975 | - if ($h == 3) |
|
| 4976 | - $shour = ''; |
|
| 4977 | - if ($m == 3) |
|
| 4978 | - $smin = ''; |
|
| 5188 | + if ($h == 3) { |
|
| 5189 | + $shour = ''; |
|
| 5190 | + } |
|
| 5191 | + if ($m == 3) { |
|
| 5192 | + $smin = ''; |
|
| 5193 | + } |
|
| 4979 | 5194 | |
| 4980 | 5195 | // You can set MAIN_POPUP_CALENDAR to 'eldy' or 'jquery' |
| 4981 | 5196 | $usecalendar = 'combo'; |
@@ -5007,14 +5222,14 @@ discard block |
||
| 5007 | 5222 | $base = DOL_URL_ROOT . '/core/'; |
| 5008 | 5223 | $retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\',\'' . $langs->defaultlang . '\');"';
|
| 5009 | 5224 | $retstring .= '>' . img_object($langs->trans("SelectDate"), 'calendarday', 'class="datecallink"') . '</button>';
|
| 5010 | - } else |
|
| 5011 | - $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>';
|
|
| 5225 | + } else { |
|
| 5226 | + $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>'; |
|
| 5227 | + } |
|
| 5012 | 5228 | |
| 5013 | 5229 | $retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . "\n"; |
| 5014 | 5230 | $retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . "\n"; |
| 5015 | 5231 | $retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . "\n"; |
| 5016 | - } |
|
| 5017 | - elseif ($usecalendar == 'jquery') {
|
|
| 5232 | + } elseif ($usecalendar == 'jquery') {
|
|
| 5018 | 5233 | if (!$disabled) {
|
| 5019 | 5234 | // Output javascript for datepicker |
| 5020 | 5235 | $retstring .= "<script type='text/javascript'>"; |
@@ -5124,32 +5339,38 @@ discard block |
||
| 5124 | 5339 | } |
| 5125 | 5340 | } |
| 5126 | 5341 | |
| 5127 | - if ($d && $h) |
|
| 5128 | - $retstring .= ($h == 2 ? '<br>' : ' '); |
|
| 5342 | + if ($d && $h) { |
|
| 5343 | + $retstring .= ($h == 2 ? '<br>' : ' '); |
|
| 5344 | + } |
|
| 5129 | 5345 | |
| 5130 | 5346 | if ($h) {
|
| 5131 | 5347 | // Show hour |
| 5132 | 5348 | $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 ' . ($fullday ? $fullday . 'hour' : '') . '" id="' . $prefix . 'hour" name="' . $prefix . 'hour">'; |
| 5133 | - if ($emptyhours) |
|
| 5134 | - $retstring .= '<option value="-1"> </option>'; |
|
| 5349 | + if ($emptyhours) { |
|
| 5350 | + $retstring .= '<option value="-1"> </option>'; |
|
| 5351 | + } |
|
| 5135 | 5352 | for ($hour = 0; $hour < 24; $hour++) {
|
| 5136 | - if (strlen($hour) < 2) |
|
| 5137 | - $hour = "0" . $hour; |
|
| 5353 | + if (strlen($hour) < 2) { |
|
| 5354 | + $hour = "0" . $hour; |
|
| 5355 | + } |
|
| 5138 | 5356 | $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour . (empty($conf->dol_optimize_smallscreen) ? '' : 'H') . '</option>'; |
| 5139 | 5357 | } |
| 5140 | 5358 | $retstring .= '</select>'; |
| 5141 | - if ($m && empty($conf->dol_optimize_smallscreen)) |
|
| 5142 | - $retstring .= ":"; |
|
| 5359 | + if ($m && empty($conf->dol_optimize_smallscreen)) { |
|
| 5360 | + $retstring .= ":"; |
|
| 5361 | + } |
|
| 5143 | 5362 | } |
| 5144 | 5363 | |
| 5145 | 5364 | if ($m) {
|
| 5146 | 5365 | // Show minutes |
| 5147 | 5366 | $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 ' . ($fullday ? $fullday . 'min' : '') . '" id="' . $prefix . 'min" name="' . $prefix . 'min">'; |
| 5148 | - if ($emptyhours) |
|
| 5149 | - $retstring .= '<option value="-1"> </option>'; |
|
| 5367 | + if ($emptyhours) { |
|
| 5368 | + $retstring .= '<option value="-1"> </option>'; |
|
| 5369 | + } |
|
| 5150 | 5370 | for ($min = 0; $min < 60; $min++) {
|
| 5151 | - if (strlen($min) < 2) |
|
| 5152 | - $min = "0" . $min; |
|
| 5371 | + if (strlen($min) < 2) { |
|
| 5372 | + $min = "0" . $min; |
|
| 5373 | + } |
|
| 5153 | 5374 | $retstring .= '<option value="' . $min . '"' . (($min == $smin) ? ' selected' : '') . '>' . $min . (empty($conf->dol_optimize_smallscreen) ? '' : '') . '</option>'; |
| 5154 | 5375 | } |
| 5155 | 5376 | $retstring .= '</select>'; |
@@ -5180,21 +5401,25 @@ discard block |
||
| 5180 | 5401 | } */ |
| 5181 | 5402 | // Update the hour part |
| 5182 | 5403 | if ($h) {
|
| 5183 | - if ($fullday) |
|
| 5184 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5404 | + if ($fullday) { |
|
| 5405 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5406 | + } |
|
| 5185 | 5407 | //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); '; |
| 5186 | 5408 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date(dol_now(), '%H') . '\');'; |
| 5187 | - if ($fullday) |
|
| 5188 | - $reset_scripts .= ' } '; |
|
| 5409 | + if ($fullday) { |
|
| 5410 | + $reset_scripts .= ' } '; |
|
| 5411 | + } |
|
| 5189 | 5412 | } |
| 5190 | 5413 | // Update the minute part |
| 5191 | 5414 | if ($m) {
|
| 5192 | - if ($fullday) |
|
| 5193 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5415 | + if ($fullday) { |
|
| 5416 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5417 | + } |
|
| 5194 | 5418 | //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); '; |
| 5195 | 5419 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date(dol_now(), '%M') . '\');'; |
| 5196 | - if ($fullday) |
|
| 5197 | - $reset_scripts .= ' } '; |
|
| 5420 | + if ($fullday) { |
|
| 5421 | + $reset_scripts .= ' } '; |
|
| 5422 | + } |
|
| 5198 | 5423 | } |
| 5199 | 5424 | // If reset_scripts is not empty, print the link with the reset_scripts in the onClick |
| 5200 | 5425 | if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
|
@@ -5216,19 +5441,23 @@ discard block |
||
| 5216 | 5441 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . dol_print_date(dol_now(), '%Y') . '\');'; |
| 5217 | 5442 | // Update the hour part |
| 5218 | 5443 | if ($h) {
|
| 5219 | - if ($fullday) |
|
| 5220 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5444 | + if ($fullday) { |
|
| 5445 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5446 | + } |
|
| 5221 | 5447 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . dol_print_date(dol_now(), '%H') . '\');'; |
| 5222 | - if ($fullday) |
|
| 5223 | - $reset_scripts .= ' } '; |
|
| 5448 | + if ($fullday) { |
|
| 5449 | + $reset_scripts .= ' } '; |
|
| 5450 | + } |
|
| 5224 | 5451 | } |
| 5225 | 5452 | // Update the minute part |
| 5226 | 5453 | if ($m) {
|
| 5227 | - if ($fullday) |
|
| 5228 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5454 | + if ($fullday) { |
|
| 5455 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5456 | + } |
|
| 5229 | 5457 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . dol_print_date(dol_now(), '%M') . '\');'; |
| 5230 | - if ($fullday) |
|
| 5231 | - $reset_scripts .= ' } '; |
|
| 5458 | + if ($fullday) { |
|
| 5459 | + $reset_scripts .= ' } '; |
|
| 5460 | + } |
|
| 5232 | 5461 | } |
| 5233 | 5462 | // If reset_scripts is not empty, print the link with the reset_scripts in the onClick |
| 5234 | 5463 | if ($reset_scripts && empty($conf->dol_optimize_smallscreen)) {
|
@@ -5291,41 +5520,46 @@ discard block |
||
| 5291 | 5520 | $retstring .= "</select>"; |
| 5292 | 5521 | } elseif ($typehour == 'text' || $typehour == 'textselect') {
|
| 5293 | 5522 | $retstring .= '<input placeholder="' . $langs->trans('HourShort') . '" type="number" min="0" size="1" name="' . $prefix . 'hour"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputhour" value="' . (($hourSelected != '') ? ((int) $hourSelected) : '') . '">';
|
| 5294 | - } else |
|
| 5295 | - return 'BadValueForParameterTypeHour'; |
|
| 5523 | + } else { |
|
| 5524 | + return 'BadValueForParameterTypeHour'; |
|
| 5525 | + } |
|
| 5296 | 5526 | |
| 5297 | - if ($typehour != 'text') |
|
| 5298 | - $retstring .= ' ' . $langs->trans('HourShort');
|
|
| 5299 | - else |
|
| 5300 | - $retstring .= '<span class="hideonsmartphone">:</span>'; |
|
| 5527 | + if ($typehour != 'text') { |
|
| 5528 | + $retstring .= ' ' . $langs->trans('HourShort'); |
|
| 5529 | + } else { |
|
| 5530 | + $retstring .= '<span class="hideonsmartphone">:</span>'; |
|
| 5531 | + } |
|
| 5301 | 5532 | |
| 5302 | 5533 | // Minutes |
| 5303 | - if ($minunderhours) |
|
| 5304 | - $retstring .= '<br>'; |
|
| 5305 | - else |
|
| 5306 | - $retstring .= '<span class="hideonsmartphone"> </span>'; |
|
| 5534 | + if ($minunderhours) { |
|
| 5535 | + $retstring .= '<br>'; |
|
| 5536 | + } else { |
|
| 5537 | + $retstring .= '<span class="hideonsmartphone"> </span>'; |
|
| 5538 | + } |
|
| 5307 | 5539 | |
| 5308 | 5540 | if ($typehour == 'select' || $typehour == 'textselect') {
|
| 5309 | 5541 | $retstring .= '<select class="flat" id="select_' . $prefix . 'min" name="' . $prefix . 'min"' . ($disabled ? ' disabled' : '') . '>'; |
| 5310 | 5542 | for ($min = 0; $min <= 55; $min = $min + 5) {
|
| 5311 | 5543 | $retstring .= '<option value="' . $min . '"'; |
| 5312 | - if ($minSelected == $min) |
|
| 5313 | - $retstring .= ' selected'; |
|
| 5544 | + if ($minSelected == $min) { |
|
| 5545 | + $retstring .= ' selected'; |
|
| 5546 | + } |
|
| 5314 | 5547 | $retstring .= '>' . $min . '</option>'; |
| 5315 | 5548 | } |
| 5316 | 5549 | $retstring .= "</select>"; |
| 5317 | - } |
|
| 5318 | - elseif ($typehour == 'text') {
|
|
| 5550 | + } elseif ($typehour == 'text') {
|
|
| 5319 | 5551 | $retstring .= '<input placeholder="' . $langs->trans('MinuteShort') . '" type="number" min="0" size="1" name="' . $prefix . 'min"' . ($disabled ? ' disabled' : '') . ' class="flat maxwidth50 inputminute" value="' . (($minSelected != '') ? ((int) $minSelected) : '') . '">';
|
| 5320 | 5552 | } |
| 5321 | 5553 | |
| 5322 | - if ($typehour != 'text') |
|
| 5323 | - $retstring .= ' ' . $langs->trans('MinuteShort');
|
|
| 5554 | + if ($typehour != 'text') { |
|
| 5555 | + $retstring .= ' ' . $langs->trans('MinuteShort'); |
|
| 5556 | + } |
|
| 5324 | 5557 | |
| 5325 | 5558 | //$retstring.=" "; |
| 5326 | 5559 | |
| 5327 | - if (!empty($nooutput)) |
|
| 5328 | - return $retstring; |
|
| 5560 | + if (!empty($nooutput)) { |
|
| 5561 | + return $retstring; |
|
| 5562 | + } |
|
| 5329 | 5563 | |
| 5330 | 5564 | print $retstring; |
| 5331 | 5565 | return; |
@@ -5368,8 +5602,9 @@ discard block |
||
| 5368 | 5602 | } |
| 5369 | 5603 | |
| 5370 | 5604 | $prefixforautocompletemode = $objecttmp->element; |
| 5371 | - if ($prefixforautocompletemode == 'societe') |
|
| 5372 | - $prefixforautocompletemode = 'company'; |
|
| 5605 | + if ($prefixforautocompletemode == 'societe') { |
|
| 5606 | + $prefixforautocompletemode = 'company'; |
|
| 5607 | + } |
|
| 5373 | 5608 | $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
| 5374 | 5609 | |
| 5375 | 5610 | dol_syslog(get_class($this) . "::selectForForms", LOG_DEBUG); |
@@ -5384,11 +5619,11 @@ discard block |
||
| 5384 | 5619 | // Activate the auto complete using ajax call. |
| 5385 | 5620 | $out .= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, $conf->global->$confkeyforautocompletemode, 0, array()); |
| 5386 | 5621 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
|
| 5387 | - if ($placeholder) |
|
| 5388 | - $placeholder = ' placeholder="' . $placeholder . '"'; |
|
| 5622 | + if ($placeholder) { |
|
| 5623 | + $placeholder = ' placeholder="' . $placeholder . '"'; |
|
| 5624 | + } |
|
| 5389 | 5625 | $out .= '<input type="text" class="' . $morecss . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $preselectedvalue . '"' . $placeholder . ' />'; |
| 5390 | - } |
|
| 5391 | - else {
|
|
| 5626 | + } else {
|
|
| 5392 | 5627 | // Immediate load of all database |
| 5393 | 5628 | $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo); |
| 5394 | 5629 | } |
@@ -5418,19 +5653,22 @@ discard block |
||
| 5418 | 5653 | global $conf, $langs, $user; |
| 5419 | 5654 | |
| 5420 | 5655 | $prefixforautocompletemode = $objecttmp->element; |
| 5421 | - if ($prefixforautocompletemode == 'societe') |
|
| 5422 | - $prefixforautocompletemode = 'company'; |
|
| 5656 | + if ($prefixforautocompletemode == 'societe') { |
|
| 5657 | + $prefixforautocompletemode = 'company'; |
|
| 5658 | + } |
|
| 5423 | 5659 | $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
| 5424 | 5660 | |
| 5425 | 5661 | $fieldstoshow = 't.ref'; |
| 5426 | 5662 | if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields ( like societe, contact, ...)
|
| 5427 | 5663 | $tmpfieldstoshow = ''; |
| 5428 | 5664 | foreach ($objecttmp->fields as $key => $val) {
|
| 5429 | - if ($val['showoncombobox']) |
|
| 5430 | - $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key; |
|
| 5665 | + if ($val['showoncombobox']) { |
|
| 5666 | + $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key; |
|
| 5667 | + } |
|
| 5431 | 5668 | } |
| 5432 | - if ($tmpfieldstoshow) |
|
| 5433 | - $fieldstoshow = $tmpfieldstoshow; |
|
| 5669 | + if ($tmpfieldstoshow) { |
|
| 5670 | + $fieldstoshow = $tmpfieldstoshow; |
|
| 5671 | + } |
|
| 5434 | 5672 | } |
| 5435 | 5673 | |
| 5436 | 5674 | $out = ''; |
@@ -5440,23 +5678,28 @@ discard block |
||
| 5440 | 5678 | |
| 5441 | 5679 | // Search data |
| 5442 | 5680 | $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . MAIN_DB_PREFIX . $objecttmp->table_element . " as t"; |
| 5443 | - if ($objecttmp->ismultientitymanaged == 2) |
|
| 5444 | - if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5445 | - $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 5681 | + if ($objecttmp->ismultientitymanaged == 2) { |
|
| 5682 | + if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5683 | + $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 5684 | + } |
|
| 5446 | 5685 | $sql .= " WHERE 1=1"; |
| 5447 | - if (!empty($objecttmp->ismultientitymanaged)) |
|
| 5448 | - $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
|
|
| 5686 | + if (!empty($objecttmp->ismultientitymanaged)) { |
|
| 5687 | + $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")"; |
|
| 5688 | + } |
|
| 5449 | 5689 | if ($objecttmp->ismultientitymanaged == 1 && !empty($user->societe_id)) {
|
| 5450 | - if ($objecttmp->element == 'societe') |
|
| 5451 | - $sql .= " AND t.rowid = " . $user->societe_id; |
|
| 5452 | - else |
|
| 5453 | - $sql .= " AND t.fk_soc = " . $user->societe_id; |
|
| 5454 | - } |
|
| 5455 | - if ($searchkey != '') |
|
| 5456 | - $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
|
|
| 5457 | - if ($objecttmp->ismultientitymanaged == 2) |
|
| 5458 | - if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5459 | - $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 5690 | + if ($objecttmp->element == 'societe') { |
|
| 5691 | + $sql .= " AND t.rowid = " . $user->societe_id; |
|
| 5692 | + } else { |
|
| 5693 | + $sql .= " AND t.fk_soc = " . $user->societe_id; |
|
| 5694 | + } |
|
| 5695 | + } |
|
| 5696 | + if ($searchkey != '') { |
|
| 5697 | + $sql .= natural_search(explode(',', $fieldstoshow), $searchkey); |
|
| 5698 | + } |
|
| 5699 | + if ($objecttmp->ismultientitymanaged == 2) { |
|
| 5700 | + if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5701 | + $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 5702 | + } |
|
| 5460 | 5703 | $sql .= $this->db->order($fieldstoshow, "ASC"); |
| 5461 | 5704 | //$sql.=$this->db->plimit($limit, 0); |
| 5462 | 5705 | // Build output string |
@@ -5475,13 +5718,15 @@ discard block |
||
| 5475 | 5718 | |
| 5476 | 5719 | //if (! empty($conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
| 5477 | 5720 | if (!empty($conf->global->$confkeyforautocompletemode)) {
|
| 5478 | - if ($showempty && !is_numeric($showempty)) |
|
| 5479 | - $textifempty = $langs->trans($showempty); |
|
| 5480 | - else |
|
| 5481 | - $textifempty .= $langs->trans("All");
|
|
| 5721 | + if ($showempty && !is_numeric($showempty)) { |
|
| 5722 | + $textifempty = $langs->trans($showempty); |
|
| 5723 | + } else { |
|
| 5724 | + $textifempty .= $langs->trans("All"); |
|
| 5725 | + } |
|
| 5482 | 5726 | } |
| 5483 | - if ($showempty) |
|
| 5484 | - $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 5727 | + if ($showempty) { |
|
| 5728 | + $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 5729 | + } |
|
| 5485 | 5730 | |
| 5486 | 5731 | $num = $this->db->num_rows($resql); |
| 5487 | 5732 | $i = 0; |
@@ -5505,21 +5750,22 @@ discard block |
||
| 5505 | 5750 | } |
| 5506 | 5751 | |
| 5507 | 5752 | $i++; |
| 5508 | - if (($i % 10) == 0) |
|
| 5509 | - $out .= "\n"; |
|
| 5753 | + if (($i % 10) == 0) { |
|
| 5754 | + $out .= "\n"; |
|
| 5755 | + } |
|
| 5510 | 5756 | } |
| 5511 | 5757 | } |
| 5512 | 5758 | |
| 5513 | 5759 | $out .= '</select>' . "\n"; |
| 5514 | - } |
|
| 5515 | - else {
|
|
| 5760 | + } else {
|
|
| 5516 | 5761 | dol_print_error($this->db); |
| 5517 | 5762 | } |
| 5518 | 5763 | |
| 5519 | 5764 | $this->result = array('nbofelement' => $num);
|
| 5520 | 5765 | |
| 5521 | - if ($outputmode) |
|
| 5522 | - return $outarray; |
|
| 5766 | + if ($outputmode) { |
|
| 5767 | + return $outarray; |
|
| 5768 | + } |
|
| 5523 | 5769 | return $out; |
| 5524 | 5770 | } |
| 5525 | 5771 | |
@@ -5555,8 +5801,9 @@ discard block |
||
| 5555 | 5801 | //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
|
| 5556 | 5802 | $jsbeautify = 1; |
| 5557 | 5803 | |
| 5558 | - if ($value_as_key) |
|
| 5559 | - $array = array_combine($array, $array); |
|
| 5804 | + if ($value_as_key) { |
|
| 5805 | + $array = array_combine($array, $array); |
|
| 5806 | + } |
|
| 5560 | 5807 | |
| 5561 | 5808 | $out = ''; |
| 5562 | 5809 | |
@@ -5576,10 +5823,13 @@ discard block |
||
| 5576 | 5823 | |
| 5577 | 5824 | if ($show_empty) {
|
| 5578 | 5825 | $textforempty = ' '; |
| 5579 | - if (!empty($conf->use_javascript_ajax)) |
|
| 5580 | - $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small. |
|
| 5581 | - if (!is_numeric($show_empty)) |
|
| 5582 | - $textforempty = $show_empty; |
|
| 5826 | + if (!empty($conf->use_javascript_ajax)) { |
|
| 5827 | + $textforempty = ' '; |
|
| 5828 | + } |
|
| 5829 | + // If we use ajaxcombo, we need here to avoid to have an empty element that is too small. |
|
| 5830 | + if (!is_numeric($show_empty)) { |
|
| 5831 | + $textforempty = $show_empty; |
|
| 5832 | + } |
|
| 5583 | 5833 | $out .= '<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n"; |
| 5584 | 5834 | } |
| 5585 | 5835 | |
@@ -5592,10 +5842,11 @@ discard block |
||
| 5592 | 5842 | } |
| 5593 | 5843 | |
| 5594 | 5844 | // Sort |
| 5595 | - if ($sort == 'ASC') |
|
| 5596 | - asort($array); |
|
| 5597 | - elseif ($sort == 'DESC') |
|
| 5598 | - arsort($array); |
|
| 5845 | + if ($sort == 'ASC') { |
|
| 5846 | + asort($array); |
|
| 5847 | + } elseif ($sort == 'DESC') { |
|
| 5848 | + arsort($array); |
|
| 5849 | + } |
|
| 5599 | 5850 | |
| 5600 | 5851 | foreach ($array as $key => $value) {
|
| 5601 | 5852 | $disabled = ''; |
@@ -5609,26 +5860,31 @@ discard block |
||
| 5609 | 5860 | } |
| 5610 | 5861 | |
| 5611 | 5862 | if ($key_in_label) {
|
| 5612 | - if (empty($nohtmlescape)) |
|
| 5613 | - $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value)); |
|
| 5614 | - else |
|
| 5615 | - $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5616 | - } |
|
| 5617 | - else {
|
|
| 5618 | - if (empty($nohtmlescape)) |
|
| 5619 | - $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5620 | - else |
|
| 5621 | - $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value; |
|
| 5622 | - if ($value == '' || $value == '-') |
|
| 5623 | - $selectOptionValue = ' '; |
|
| 5863 | + if (empty($nohtmlescape)) { |
|
| 5864 | + $selectOptionValue = dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value)); |
|
| 5865 | + } else { |
|
| 5866 | + $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5867 | + } |
|
| 5868 | + } else {
|
|
| 5869 | + if (empty($nohtmlescape)) { |
|
| 5870 | + $selectOptionValue = dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5871 | + } else { |
|
| 5872 | + $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value; |
|
| 5873 | + } |
|
| 5874 | + if ($value == '' || $value == '-') { |
|
| 5875 | + $selectOptionValue = ' '; |
|
| 5876 | + } |
|
| 5624 | 5877 | } |
| 5625 | 5878 | |
| 5626 | 5879 | $out .= '<option value="' . $key . '"'; |
| 5627 | 5880 | $out .= $style . $disabled; |
| 5628 | - if ($id != '' && $id == $key && !$disabled) |
|
| 5629 | - $out .= ' selected'; // To preselect a value |
|
| 5630 | - if ($nohtmlescape) |
|
| 5631 | - $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"'; |
|
| 5881 | + if ($id != '' && $id == $key && !$disabled) { |
|
| 5882 | + $out .= ' selected'; |
|
| 5883 | + } |
|
| 5884 | + // To preselect a value |
|
| 5885 | + if ($nohtmlescape) { |
|
| 5886 | + $out .= ' data-html="' . dol_escape_htmltag($selectOptionValue) . '"'; |
|
| 5887 | + } |
|
| 5632 | 5888 | $out .= '>'; |
| 5633 | 5889 | //var_dump($selectOptionValue); |
| 5634 | 5890 | $out .= $selectOptionValue; |
@@ -5664,8 +5920,9 @@ discard block |
||
| 5664 | 5920 | global $delayedhtmlcontent; |
| 5665 | 5921 | |
| 5666 | 5922 | // TODO Use an internal dolibarr component instead of select2 |
| 5667 | - if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT'))
|
|
| 5668 | - return ''; |
|
| 5923 | + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) { |
|
| 5924 | + return ''; |
|
| 5925 | + } |
|
| 5669 | 5926 | |
| 5670 | 5927 | $out = '<select type="text" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>'; |
| 5671 | 5928 | |
@@ -5764,8 +6021,9 @@ discard block |
||
| 5764 | 6021 | global $delayedhtmlcontent; |
| 5765 | 6022 | |
| 5766 | 6023 | // TODO Use an internal dolibarr component instead of select2 |
| 5767 | - if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT'))
|
|
| 5768 | - return ''; |
|
| 6024 | + if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) { |
|
| 6025 | + return ''; |
|
| 6026 | + } |
|
| 5769 | 6027 | |
| 5770 | 6028 | $out = '<select type="text" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"><option></option></select>'; |
| 5771 | 6029 | |
@@ -5935,8 +6193,9 @@ discard block |
||
| 5935 | 6193 | |
| 5936 | 6194 | $out .= '<select id="' . $htmlname . '" class="multiselect' . ($morecss ? ' ' . $morecss : '') . '" multiple name="' . $htmlname . '[]"' . ($moreattrib ? ' ' . $moreattrib : '') . ($width ? ' style="width: ' . (preg_match('/%/', $width) ? $width : $width . 'px') . '"' : '') . '>' . "\n";
|
| 5937 | 6195 | if (is_array($array) && !empty($array)) {
|
| 5938 | - if ($value_as_key) |
|
| 5939 | - $array = array_combine($array, $array); |
|
| 6196 | + if ($value_as_key) { |
|
| 6197 | + $array = array_combine($array, $array); |
|
| 6198 | + } |
|
| 5940 | 6199 | |
| 5941 | 6200 | if (!empty($array)) {
|
| 5942 | 6201 | foreach ($array as $key => $value) {
|
@@ -5971,8 +6230,9 @@ discard block |
||
| 5971 | 6230 | {
|
| 5972 | 6231 | global $conf, $langs, $user; |
| 5973 | 6232 | |
| 5974 | - if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
| 5975 | - return ''; |
|
| 6233 | + if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
|
| 6234 | + return ''; |
|
| 6235 | + } |
|
| 5976 | 6236 | |
| 5977 | 6237 | $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; |
| 5978 | 6238 | if (!empty($user->conf->$tmpvar)) {
|
@@ -5980,10 +6240,11 @@ discard block |
||
| 5980 | 6240 | foreach ($array as $key => $val) {
|
| 5981 | 6241 | //var_dump($key); |
| 5982 | 6242 | //var_dump($tmparray); |
| 5983 | - if (in_array($key, $tmparray)) |
|
| 5984 | - $array[$key]['checked'] = 1; |
|
| 5985 | - else |
|
| 5986 | - $array[$key]['checked'] = 0; |
|
| 6243 | + if (in_array($key, $tmparray)) { |
|
| 6244 | + $array[$key]['checked'] = 1; |
|
| 6245 | + } else { |
|
| 6246 | + $array[$key]['checked'] = 0; |
|
| 6247 | + } |
|
| 5987 | 6248 | } |
| 5988 | 6249 | } |
| 5989 | 6250 | //var_dump($array); |
@@ -6149,40 +6410,47 @@ discard block |
||
| 6149 | 6410 | // To work with non standard path |
| 6150 | 6411 | if ($objecttype == 'facture') {
|
| 6151 | 6412 | $tplpath = 'compta/' . $element; |
| 6152 | - if (empty($conf->facture->enabled)) |
|
| 6153 | - continue; // Do not show if module disabled |
|
| 6154 | - } |
|
| 6155 | - else if ($objecttype == 'facturerec') {
|
|
| 6413 | + if (empty($conf->facture->enabled)) { |
|
| 6414 | + continue; |
|
| 6415 | + } |
|
| 6416 | + // Do not show if module disabled |
|
| 6417 | + } else if ($objecttype == 'facturerec') {
|
|
| 6156 | 6418 | $tplpath = 'compta/facture'; |
| 6157 | 6419 | $tplname = 'linkedobjectblockForRec'; |
| 6158 | - if (empty($conf->facture->enabled)) |
|
| 6159 | - continue; // Do not show if module disabled |
|
| 6160 | - } |
|
| 6161 | - else if ($objecttype == 'propal') {
|
|
| 6420 | + if (empty($conf->facture->enabled)) { |
|
| 6421 | + continue; |
|
| 6422 | + } |
|
| 6423 | + // Do not show if module disabled |
|
| 6424 | + } else if ($objecttype == 'propal') {
|
|
| 6162 | 6425 | $tplpath = 'comm/' . $element; |
| 6163 | - if (empty($conf->propal->enabled)) |
|
| 6164 | - continue; // Do not show if module disabled |
|
| 6165 | - } |
|
| 6166 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 6167 | - if (empty($conf->supplier_proposal->enabled)) |
|
| 6168 | - continue; // Do not show if module disabled |
|
| 6169 | - } |
|
| 6170 | - else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
|
|
| 6426 | + if (empty($conf->propal->enabled)) { |
|
| 6427 | + continue; |
|
| 6428 | + } |
|
| 6429 | + // Do not show if module disabled |
|
| 6430 | + } else if ($objecttype == 'supplier_proposal') {
|
|
| 6431 | + if (empty($conf->supplier_proposal->enabled)) { |
|
| 6432 | + continue; |
|
| 6433 | + } |
|
| 6434 | + // Do not show if module disabled |
|
| 6435 | + } else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
|
|
| 6171 | 6436 | $tplpath = 'expedition'; |
| 6172 | - if (empty($conf->expedition->enabled)) |
|
| 6173 | - continue; // Do not show if module disabled |
|
| 6174 | - } |
|
| 6175 | - else if ($objecttype == 'reception') {
|
|
| 6437 | + if (empty($conf->expedition->enabled)) { |
|
| 6438 | + continue; |
|
| 6439 | + } |
|
| 6440 | + // Do not show if module disabled |
|
| 6441 | + } else if ($objecttype == 'reception') {
|
|
| 6176 | 6442 | $tplpath = 'reception'; |
| 6177 | - if (empty($conf->reception->enabled)) |
|
| 6178 | - continue; // Do not show if module disabled |
|
| 6179 | - } |
|
| 6180 | - else if ($objecttype == 'delivery') {
|
|
| 6443 | + if (empty($conf->reception->enabled)) { |
|
| 6444 | + continue; |
|
| 6445 | + } |
|
| 6446 | + // Do not show if module disabled |
|
| 6447 | + } else if ($objecttype == 'delivery') {
|
|
| 6181 | 6448 | $tplpath = 'livraison'; |
| 6182 | - if (empty($conf->expedition->enabled)) |
|
| 6183 | - continue; // Do not show if module disabled |
|
| 6184 | - } |
|
| 6185 | - else if ($objecttype == 'invoice_supplier') {
|
|
| 6449 | + if (empty($conf->expedition->enabled)) { |
|
| 6450 | + continue; |
|
| 6451 | + } |
|
| 6452 | + // Do not show if module disabled |
|
| 6453 | + } else if ($objecttype == 'invoice_supplier') {
|
|
| 6186 | 6454 | $tplpath = 'fourn/facture'; |
| 6187 | 6455 | } else if ($objecttype == 'order_supplier') {
|
| 6188 | 6456 | $tplpath = 'fourn/commande'; |
@@ -6246,20 +6514,23 @@ discard block |
||
| 6246 | 6514 | $linktoelemlist = ''; |
| 6247 | 6515 | $listofidcompanytoscan = ''; |
| 6248 | 6516 | |
| 6249 | - if (!is_object($object->thirdparty)) |
|
| 6250 | - $object->fetch_thirdparty(); |
|
| 6517 | + if (!is_object($object->thirdparty)) { |
|
| 6518 | + $object->fetch_thirdparty(); |
|
| 6519 | + } |
|
| 6251 | 6520 | |
| 6252 | 6521 | $possiblelinks = array(); |
| 6253 | 6522 | if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
|
| 6254 | 6523 | $listofidcompanytoscan = $object->thirdparty->id; |
| 6255 | - if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) |
|
| 6256 | - $listofidcompanytoscan .= ',' . $object->thirdparty->parent; |
|
| 6524 | + if (($object->thirdparty->parent > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) { |
|
| 6525 | + $listofidcompanytoscan .= ',' . $object->thirdparty->parent; |
|
| 6526 | + } |
|
| 6257 | 6527 | if (($object->fk_project > 0) && !empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) {
|
| 6258 | 6528 | include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; |
| 6259 | 6529 | $tmpproject = new Project($this->db); |
| 6260 | 6530 | $tmpproject->fetch($object->fk_project); |
| 6261 | - if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) |
|
| 6262 | - $listofidcompanytoscan .= ',' . $tmpproject->socid; |
|
| 6531 | + if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) { |
|
| 6532 | + $listofidcompanytoscan .= ',' . $tmpproject->socid; |
|
| 6533 | + } |
|
| 6263 | 6534 | unset($tmpproject); |
| 6264 | 6535 | } |
| 6265 | 6536 | |
@@ -6295,8 +6566,9 @@ discard block |
||
| 6295 | 6566 | foreach ($possiblelinks as $key => $possiblelink) {
|
| 6296 | 6567 | $num = 0; |
| 6297 | 6568 | |
| 6298 | - if (empty($possiblelink['enabled'])) |
|
| 6299 | - continue; |
|
| 6569 | + if (empty($possiblelink['enabled'])) { |
|
| 6570 | + continue; |
|
| 6571 | + } |
|
| 6300 | 6572 | |
| 6301 | 6573 | if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
|
| 6302 | 6574 | print '<div id="' . $key . 'list"' . (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>'; |
@@ -6347,11 +6619,13 @@ discard block |
||
| 6347 | 6619 | } |
| 6348 | 6620 | |
| 6349 | 6621 | //$linktoelem.=($linktoelem?' ':''); |
| 6350 | - if ($num > 0) |
|
| 6351 | - $linktoelemlist .= '<li><a href="#linkto' . $key . '" class="linkto dropdowncloseonclick" rel="' . $key . '">' . $langs->trans($possiblelink['label']) . ' (' . $num . ')</a></li>';
|
|
| 6622 | + if ($num > 0) { |
|
| 6623 | + $linktoelemlist .= '<li><a href="#linkto' . $key . '" class="linkto dropdowncloseonclick" rel="' . $key . '">' . $langs->trans($possiblelink['label']) . ' (' . $num . ')</a></li>'; |
|
| 6624 | + } |
|
| 6352 | 6625 | //else $linktoelem.=$langs->trans($possiblelink['label']); |
| 6353 | - else |
|
| 6354 | - $linktoelemlist .= '<li><span class="linktodisabled">' . $langs->trans($possiblelink['label']) . ' (0)</span></li>'; |
|
| 6626 | + else { |
|
| 6627 | + $linktoelemlist .= '<li><span class="linktodisabled">' . $langs->trans($possiblelink['label']) . ' (0)</span></li>'; |
|
| 6628 | + } |
|
| 6355 | 6629 | } |
| 6356 | 6630 | } |
| 6357 | 6631 | |
@@ -6409,8 +6683,9 @@ discard block |
||
| 6409 | 6683 | $disabled = ($disabled ? ' disabled' : ''); |
| 6410 | 6684 | |
| 6411 | 6685 | $resultyesno = '<select class="flat width75" id="' . $htmlname . '" name="' . $htmlname . '"' . $disabled . '>' . "\n"; |
| 6412 | - if ($useempty) |
|
| 6413 | - $resultyesno .= '<option value="-1"' . (($value < 0) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 6686 | + if ($useempty) { |
|
| 6687 | + $resultyesno .= '<option value="-1"' . (($value < 0) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 6688 | + } |
|
| 6414 | 6689 | if (("$value" == 'yes') || ($value == 1)) {
|
| 6415 | 6690 | $resultyesno .= '<option value="' . $yes . '" selected>' . $langs->trans("Yes") . '</option>' . "\n";
|
| 6416 | 6691 | $resultyesno .= '<option value="' . $no . '">' . $langs->trans("No") . '</option>' . "\n";
|
@@ -6489,10 +6764,12 @@ discard block |
||
| 6489 | 6764 | global $langs, $conf, $hookmanager; |
| 6490 | 6765 | |
| 6491 | 6766 | $ret = ''; |
| 6492 | - if (empty($fieldid)) |
|
| 6493 | - $fieldid = 'rowid'; |
|
| 6494 | - if (empty($fieldref)) |
|
| 6495 | - $fieldref = 'ref'; |
|
| 6767 | + if (empty($fieldid)) { |
|
| 6768 | + $fieldid = 'rowid'; |
|
| 6769 | + } |
|
| 6770 | + if (empty($fieldref)) { |
|
| 6771 | + $fieldref = 'ref'; |
|
| 6772 | + } |
|
| 6496 | 6773 | |
| 6497 | 6774 | // Add where from hooks |
| 6498 | 6775 | if (is_object($hookmanager)) {
|
@@ -6531,8 +6808,9 @@ discard block |
||
| 6531 | 6808 | $ret .= '<!-- Start banner content --><div style="vertical-align: middle">'; |
| 6532 | 6809 | |
| 6533 | 6810 | // Right part of banner |
| 6534 | - if ($morehtmlright) |
|
| 6535 | - $ret .= '<div class="inline-block floatleft">' . $morehtmlright . '</div>'; |
|
| 6811 | + if ($morehtmlright) { |
|
| 6812 | + $ret .= '<div class="inline-block floatleft">' . $morehtmlright . '</div>'; |
|
| 6813 | + } |
|
| 6536 | 6814 | |
| 6537 | 6815 | if ($previous_ref || $next_ref || $morehtml) {
|
| 6538 | 6816 | $ret .= '<div class="pagination paginationref"><ul class="right">'; |
@@ -6550,26 +6828,32 @@ discard block |
||
| 6550 | 6828 | |
| 6551 | 6829 | $parameters = array(); |
| 6552 | 6830 | $reshook = $hookmanager->executeHooks('moreHtmlStatus', $parameters, $object); // Note that $action and $object may have been modified by hook
|
| 6553 | - if (empty($reshook)) |
|
| 6554 | - $morehtmlstatus .= $hookmanager->resPrint; |
|
| 6555 | - else |
|
| 6556 | - $morehtmlstatus = $hookmanager->resPrint; |
|
| 6557 | - if ($morehtmlstatus) |
|
| 6558 | - $ret .= '<div class="statusref">' . $morehtmlstatus . '</div>'; |
|
| 6831 | + if (empty($reshook)) { |
|
| 6832 | + $morehtmlstatus .= $hookmanager->resPrint; |
|
| 6833 | + } else { |
|
| 6834 | + $morehtmlstatus = $hookmanager->resPrint; |
|
| 6835 | + } |
|
| 6836 | + if ($morehtmlstatus) { |
|
| 6837 | + $ret .= '<div class="statusref">' . $morehtmlstatus . '</div>'; |
|
| 6838 | + } |
|
| 6559 | 6839 | |
| 6560 | 6840 | $parameters = array(); |
| 6561 | 6841 | $reshook = $hookmanager->executeHooks('moreHtmlRef', $parameters, $object); // Note that $action and $object may have been modified by hook
|
| 6562 | - if (empty($reshook)) |
|
| 6563 | - $morehtmlref .= $hookmanager->resPrint; |
|
| 6564 | - elseif ($reshook > 0) |
|
| 6565 | - $morehtmlref = $hookmanager->resPrint; |
|
| 6842 | + if (empty($reshook)) { |
|
| 6843 | + $morehtmlref .= $hookmanager->resPrint; |
|
| 6844 | + } elseif ($reshook > 0) { |
|
| 6845 | + $morehtmlref = $hookmanager->resPrint; |
|
| 6846 | + } |
|
| 6566 | 6847 | |
| 6567 | 6848 | // Left part of banner |
| 6568 | 6849 | if ($morehtmlleft) {
|
| 6569 | - if ($conf->browser->layout == 'phone') |
|
| 6570 | - $ret .= '<div class="floatleft">' . $morehtmlleft . '</div>'; // class="center" to have photo in middle |
|
| 6571 | - else |
|
| 6572 | - $ret .= '<div class="inline-block floatleft">' . $morehtmlleft . '</div>'; |
|
| 6850 | + if ($conf->browser->layout == 'phone') { |
|
| 6851 | + $ret .= '<div class="floatleft">' . $morehtmlleft . '</div>'; |
|
| 6852 | + } |
|
| 6853 | + // class="center" to have photo in middle |
|
| 6854 | + else { |
|
| 6855 | + $ret .= '<div class="inline-block floatleft">' . $morehtmlleft . '</div>'; |
|
| 6856 | + } |
|
| 6573 | 6857 | } |
| 6574 | 6858 | |
| 6575 | 6859 | //if ($conf->browser->layout == 'phone') $ret.='<div class="clearboth"></div>'; |
@@ -6594,8 +6878,9 @@ discard block |
||
| 6594 | 6878 | $ret .= $object->label; |
| 6595 | 6879 | } else if ($object->element == 'ecm_directories') {
|
| 6596 | 6880 | $ret .= ''; |
| 6597 | - } else if ($fieldref != 'none') |
|
| 6598 | - $ret .= dol_htmlentities($object->$fieldref); |
|
| 6881 | + } else if ($fieldref != 'none') { |
|
| 6882 | + $ret .= dol_htmlentities($object->$fieldref); |
|
| 6883 | + } |
|
| 6599 | 6884 | |
| 6600 | 6885 | |
| 6601 | 6886 | if ($morehtmlref) {
|
@@ -6620,15 +6905,17 @@ discard block |
||
| 6620 | 6905 | global $conf; |
| 6621 | 6906 | |
| 6622 | 6907 | //Check if barcode is filled in the card |
| 6623 | - if (empty($object->barcode)) |
|
| 6624 | - return ''; |
|
| 6908 | + if (empty($object->barcode)) { |
|
| 6909 | + return ''; |
|
| 6910 | + } |
|
| 6625 | 6911 | |
| 6626 | 6912 | // Complete object if not complete |
| 6627 | 6913 | if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) {
|
| 6628 | 6914 | $result = $object->fetch_barcode(); |
| 6629 | 6915 | //Check if fetch_barcode() failed |
| 6630 | - if ($result < 1) |
|
| 6631 | - return '<!-- ErrorFetchBarcode -->'; |
|
| 6916 | + if ($result < 1) { |
|
| 6917 | + return '<!-- ErrorFetchBarcode -->'; |
|
| 6918 | + } |
|
| 6632 | 6919 | } |
| 6633 | 6920 | |
| 6634 | 6921 | // Barcode image |
@@ -6670,108 +6957,120 @@ discard block |
||
| 6670 | 6957 | if ($modulepart == 'societe') {
|
| 6671 | 6958 | $dir = $conf->societe->multidir_output[$entity]; |
| 6672 | 6959 | if (!empty($object->logo)) {
|
| 6673 | - if ((string) $imagesize == 'mini') |
|
| 6674 | - $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . getImageFileNameForSize($object->logo, '_mini'); // getImageFileNameForSize include the thumbs |
|
| 6675 | - else if ((string) $imagesize == 'small') |
|
| 6676 | - $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . getImageFileNameForSize($object->logo, '_small'); |
|
| 6677 | - else |
|
| 6678 | - $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . $object->logo; |
|
| 6960 | + if ((string) $imagesize == 'mini') { |
|
| 6961 | + $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . getImageFileNameForSize($object->logo, '_mini'); |
|
| 6962 | + } |
|
| 6963 | + // getImageFileNameForSize include the thumbs |
|
| 6964 | + else if ((string) $imagesize == 'small') { |
|
| 6965 | + $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . getImageFileNameForSize($object->logo, '_small'); |
|
| 6966 | + } else { |
|
| 6967 | + $file = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . $object->logo; |
|
| 6968 | + } |
|
| 6679 | 6969 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'thirdparty') . '/logos/' . $object->logo; |
| 6680 | 6970 | } |
| 6681 | 6971 | $email = $object->email; |
| 6682 | - } |
|
| 6683 | - else if ($modulepart == 'contact') {
|
|
| 6972 | + } else if ($modulepart == 'contact') {
|
|
| 6684 | 6973 | $dir = $conf->societe->multidir_output[$entity] . '/contact'; |
| 6685 | 6974 | if (!empty($object->photo)) {
|
| 6686 | - if ((string) $imagesize == 'mini') |
|
| 6687 | - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6688 | - else if ((string) $imagesize == 'small') |
|
| 6689 | - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6690 | - else |
|
| 6691 | - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . $object->photo; |
|
| 6975 | + if ((string) $imagesize == 'mini') { |
|
| 6976 | + $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6977 | + } else if ((string) $imagesize == 'small') { |
|
| 6978 | + $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6979 | + } else { |
|
| 6980 | + $file = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . $object->photo; |
|
| 6981 | + } |
|
| 6692 | 6982 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'contact') . '/photos/' . $object->photo; |
| 6693 | 6983 | } |
| 6694 | 6984 | $email = $object->email; |
| 6695 | 6985 | $capture = 'user'; |
| 6696 | - } |
|
| 6697 | - else if ($modulepart == 'userphoto') {
|
|
| 6986 | + } else if ($modulepart == 'userphoto') {
|
|
| 6698 | 6987 | $dir = $conf->user->dir_output; |
| 6699 | 6988 | if (!empty($object->photo)) {
|
| 6700 | - if ((string) $imagesize == 'mini') |
|
| 6701 | - $file = get_exdir(0, 0, 0, 0, $object, 'user') . $object->id . '/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6702 | - else if ((string) $imagesize == 'small') |
|
| 6703 | - $file = get_exdir(0, 0, 0, 0, $object, 'user') . $object->id . '/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6704 | - else |
|
| 6705 | - $file = get_exdir(0, 0, 0, 0, $object, 'user') . '/' . $object->id . '/' . $object->photo; |
|
| 6989 | + if ((string) $imagesize == 'mini') { |
|
| 6990 | + $file = get_exdir(0, 0, 0, 0, $object, 'user') . $object->id . '/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6991 | + } else if ((string) $imagesize == 'small') { |
|
| 6992 | + $file = get_exdir(0, 0, 0, 0, $object, 'user') . $object->id . '/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6993 | + } else { |
|
| 6994 | + $file = get_exdir(0, 0, 0, 0, $object, 'user') . '/' . $object->id . '/' . $object->photo; |
|
| 6995 | + } |
|
| 6706 | 6996 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'user') . '/' . $object->id . '/' . $object->photo; |
| 6707 | 6997 | } |
| 6708 | - if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) |
|
| 6709 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 6998 | + if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) { |
|
| 6999 | + $altfile = $object->id . ".jpg"; |
|
| 7000 | + } |
|
| 7001 | + // For backward compatibility |
|
| 6710 | 7002 | $email = $object->email; |
| 6711 | 7003 | $capture = 'user'; |
| 6712 | - } |
|
| 6713 | - else if ($modulepart == 'memberphoto') {
|
|
| 7004 | + } else if ($modulepart == 'memberphoto') {
|
|
| 6714 | 7005 | $dir = $conf->adherent->dir_output; |
| 6715 | 7006 | if (!empty($object->photo)) {
|
| 6716 | - if ((string) $imagesize == 'mini') |
|
| 6717 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6718 | - else if ((string) $imagesize == 'small') |
|
| 6719 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6720 | - else |
|
| 6721 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; |
|
| 7007 | + if ((string) $imagesize == 'mini') { |
|
| 7008 | + $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 7009 | + } else if ((string) $imagesize == 'small') { |
|
| 7010 | + $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 7011 | + } else { |
|
| 7012 | + $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; |
|
| 7013 | + } |
|
| 6722 | 7014 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; |
| 6723 | 7015 | } |
| 6724 | - if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) |
|
| 6725 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 7016 | + if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) { |
|
| 7017 | + $altfile = $object->id . ".jpg"; |
|
| 7018 | + } |
|
| 7019 | + // For backward compatibility |
|
| 6726 | 7020 | $email = $object->email; |
| 6727 | 7021 | $capture = 'user'; |
| 6728 | - } |
|
| 6729 | - else {
|
|
| 7022 | + } else {
|
|
| 6730 | 7023 | // Generic case to show photos |
| 6731 | 7024 | $dir = $conf->$modulepart->dir_output; |
| 6732 | 7025 | if (!empty($object->photo)) {
|
| 6733 | - if ((string) $imagesize == 'mini') |
|
| 6734 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6735 | - else if ((string) $imagesize == 'small') |
|
| 6736 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6737 | - else |
|
| 6738 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . $object->photo; |
|
| 7026 | + if ((string) $imagesize == 'mini') { |
|
| 7027 | + $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 7028 | + } else if ((string) $imagesize == 'small') { |
|
| 7029 | + $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 7030 | + } else { |
|
| 7031 | + $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . $object->photo; |
|
| 7032 | + } |
|
| 6739 | 7033 | $originalfile = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . $object->photo; |
| 6740 | 7034 | } |
| 6741 | - if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) |
|
| 6742 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 7035 | + if (!empty($conf->global->MAIN_OLD_IMAGE_LINKS)) { |
|
| 7036 | + $altfile = $object->id . ".jpg"; |
|
| 7037 | + } |
|
| 7038 | + // For backward compatibility |
|
| 6743 | 7039 | $email = $object->email; |
| 6744 | 7040 | } |
| 6745 | 7041 | |
| 6746 | - if ($forcecapture) |
|
| 6747 | - $capture = $forcecapture; |
|
| 7042 | + if ($forcecapture) { |
|
| 7043 | + $capture = $forcecapture; |
|
| 7044 | + } |
|
| 6748 | 7045 | |
| 6749 | 7046 | if ($dir) {
|
| 6750 | 7047 | if ($file && file_exists($dir . "/" . $file)) {
|
| 6751 | 7048 | if ($addlinktofullsize) {
|
| 6752 | 7049 | $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity=' . $entity); |
| 6753 | - if ($urladvanced) |
|
| 6754 | - $ret .= '<a href="' . $urladvanced . '">'; |
|
| 6755 | - else |
|
| 6756 | - $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7050 | + if ($urladvanced) { |
|
| 7051 | + $ret .= '<a href="' . $urladvanced . '">'; |
|
| 7052 | + } else { |
|
| 7053 | + $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7054 | + } |
|
| 6757 | 7055 | } |
| 6758 | 7056 | $ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="Photo" id="photologo' . (preg_replace('/[^a-z]/i', '_', $file)) . '" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($file) . '&cache=' . $cache . '">';
|
| 6759 | - if ($addlinktofullsize) |
|
| 6760 | - $ret .= '</a>'; |
|
| 6761 | - } |
|
| 6762 | - else if ($altfile && file_exists($dir . "/" . $altfile)) {
|
|
| 7057 | + if ($addlinktofullsize) { |
|
| 7058 | + $ret .= '</a>'; |
|
| 7059 | + } |
|
| 7060 | + } else if ($altfile && file_exists($dir . "/" . $altfile)) {
|
|
| 6763 | 7061 | if ($addlinktofullsize) {
|
| 6764 | 7062 | $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity=' . $entity); |
| 6765 | - if ($urladvanced) |
|
| 6766 | - $ret .= '<a href="' . $urladvanced . '">'; |
|
| 6767 | - else |
|
| 6768 | - $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7063 | + if ($urladvanced) { |
|
| 7064 | + $ret .= '<a href="' . $urladvanced . '">'; |
|
| 7065 | + } else { |
|
| 7066 | + $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7067 | + } |
|
| 6769 | 7068 | } |
| 6770 | 7069 | $ret .= '<img class="photo' . $modulepart . ($cssclass ? ' ' . $cssclass : '') . '" alt="Photo alt" id="photologo' . (preg_replace('/[^a-z]/i', '_', $file)) . '" class="' . $cssclass . '" ' . ($width ? ' width="' . $width . '"' : '') . ($height ? ' height="' . $height . '"' : '') . ' src="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($altfile) . '&cache=' . $cache . '">';
|
| 6771 | - if ($addlinktofullsize) |
|
| 6772 | - $ret .= '</a>'; |
|
| 6773 | - } |
|
| 6774 | - else {
|
|
| 7070 | + if ($addlinktofullsize) { |
|
| 7071 | + $ret .= '</a>'; |
|
| 7072 | + } |
|
| 7073 | + } else {
|
|
| 6775 | 7074 | $nophoto = '/public/theme/common/nophoto.png'; |
| 6776 | 7075 | if (in_array($modulepart, array('userphoto', 'contact'))) { // For module that are "physical" users
|
| 6777 | 7076 | $nophoto = '/public/theme/common/user_anonymous.png'; |
@@ -6809,8 +7108,9 @@ discard block |
||
| 6809 | 7108 | $ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput"' . ($capture ? ' capture="' . $capture . '"' : '') . '></td></tr>'; |
| 6810 | 7109 | $ret .= '</table>'; |
| 6811 | 7110 | } |
| 6812 | - } else |
|
| 6813 | - dol_print_error('', 'Call of showphoto with wrong parameters modulepart=' . $modulepart);
|
|
| 7111 | + } else { |
|
| 7112 | + dol_print_error('', 'Call of showphoto with wrong parameters modulepart=' . $modulepart); |
|
| 7113 | + } |
|
| 6814 | 7114 | |
| 6815 | 7115 | return $ret; |
| 6816 | 7116 | } |
@@ -6837,14 +7137,17 @@ discard block |
||
| 6837 | 7137 | global $conf, $user, $langs; |
| 6838 | 7138 | |
| 6839 | 7139 | // Permettre l'exclusion de groupes |
| 6840 | - if (is_array($exclude)) |
|
| 6841 | - $excludeGroups = implode("','", $exclude);
|
|
| 7140 | + if (is_array($exclude)) { |
|
| 7141 | + $excludeGroups = implode("','", $exclude); |
|
| 7142 | + } |
|
| 6842 | 7143 | // Permettre l'inclusion de groupes |
| 6843 | - if (is_array($include)) |
|
| 6844 | - $includeGroups = implode("','", $include);
|
|
| 7144 | + if (is_array($include)) { |
|
| 7145 | + $includeGroups = implode("','", $include); |
|
| 7146 | + } |
|
| 6845 | 7147 | |
| 6846 | - if (!is_array($selected)) |
|
| 6847 | - $selected = array($selected); |
|
| 7148 | + if (!is_array($selected)) { |
|
| 7149 | + $selected = array($selected); |
|
| 7150 | + } |
|
| 6848 | 7151 | |
| 6849 | 7152 | $out = ''; |
| 6850 | 7153 | |
@@ -6856,18 +7159,20 @@ discard block |
||
| 6856 | 7159 | $sql .= " FROM " . MAIN_DB_PREFIX . "usergroup as ug "; |
| 6857 | 7160 | if (!empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
| 6858 | 7161 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=ug.entity"; |
| 6859 | - if ($force_entity) |
|
| 6860 | - $sql .= " WHERE ug.entity IN (0," . $force_entity . ")"; |
|
| 6861 | - else |
|
| 6862 | - $sql .= " WHERE ug.entity IS NOT NULL"; |
|
| 6863 | - } |
|
| 6864 | - else {
|
|
| 7162 | + if ($force_entity) { |
|
| 7163 | + $sql .= " WHERE ug.entity IN (0," . $force_entity . ")"; |
|
| 7164 | + } else { |
|
| 7165 | + $sql .= " WHERE ug.entity IS NOT NULL"; |
|
| 7166 | + } |
|
| 7167 | + } else {
|
|
| 6865 | 7168 | $sql .= " WHERE ug.entity IN (0," . $conf->entity . ")"; |
| 6866 | 7169 | } |
| 6867 | - if (is_array($exclude) && $excludeGroups) |
|
| 6868 | - $sql .= " AND ug.rowid NOT IN ('" . $excludeGroups . "')";
|
|
| 6869 | - if (is_array($include) && $includeGroups) |
|
| 6870 | - $sql .= " AND ug.rowid IN ('" . $includeGroups . "')";
|
|
| 7170 | + if (is_array($exclude) && $excludeGroups) { |
|
| 7171 | + $sql .= " AND ug.rowid NOT IN ('" . $excludeGroups . "')"; |
|
| 7172 | + } |
|
| 7173 | + if (is_array($include) && $includeGroups) { |
|
| 7174 | + $sql .= " AND ug.rowid IN ('" . $includeGroups . "')"; |
|
| 7175 | + } |
|
| 6871 | 7176 | $sql .= " ORDER BY ug.nom ASC"; |
| 6872 | 7177 | |
| 6873 | 7178 | dol_syslog(get_class($this) . "::select_dolgroups", LOG_DEBUG); |
@@ -6882,18 +7187,21 @@ discard block |
||
| 6882 | 7187 | $num = $this->db->num_rows($resql); |
| 6883 | 7188 | $i = 0; |
| 6884 | 7189 | if ($num) {
|
| 6885 | - if ($show_empty && !$multiple) |
|
| 6886 | - $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 7190 | + if ($show_empty && !$multiple) { |
|
| 7191 | + $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 7192 | + } |
|
| 6887 | 7193 | |
| 6888 | 7194 | while ($i < $num) {
|
| 6889 | 7195 | $obj = $this->db->fetch_object($resql); |
| 6890 | 7196 | $disableline = 0; |
| 6891 | - if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) |
|
| 6892 | - $disableline = 1; |
|
| 7197 | + if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) { |
|
| 7198 | + $disableline = 1; |
|
| 7199 | + } |
|
| 6893 | 7200 | |
| 6894 | 7201 | $out .= '<option value="' . $obj->rowid . '"'; |
| 6895 | - if ($disableline) |
|
| 6896 | - $out .= ' disabled'; |
|
| 7202 | + if ($disableline) { |
|
| 7203 | + $out .= ' disabled'; |
|
| 7204 | + } |
|
| 6897 | 7205 | if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (!is_object($selected[0]) && in_array($obj->rowid, $selected) )) {
|
| 6898 | 7206 | $out .= ' selected'; |
| 6899 | 7207 | } |
@@ -6908,13 +7216,13 @@ discard block |
||
| 6908 | 7216 | $i++; |
| 6909 | 7217 | } |
| 6910 | 7218 | } else {
|
| 6911 | - if ($show_empty) |
|
| 6912 | - $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '></option>' . "\n"; |
|
| 7219 | + if ($show_empty) { |
|
| 7220 | + $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '></option>' . "\n"; |
|
| 7221 | + } |
|
| 6913 | 7222 | $out .= '<option value="" disabled>' . $langs->trans("NoUserGroupDefined") . '</option>';
|
| 6914 | 7223 | } |
| 6915 | 7224 | $out .= '</select>'; |
| 6916 | - } |
|
| 6917 | - else {
|
|
| 7225 | + } else {
|
|
| 6918 | 7226 | dol_print_error($this->db); |
| 6919 | 7227 | } |
| 6920 | 7228 | |
@@ -6950,8 +7258,9 @@ discard block |
||
| 6950 | 7258 | global $conf, $langs; |
| 6951 | 7259 | |
| 6952 | 7260 | $out = ''; |
| 6953 | - if (!empty($conf->use_javascript_ajax)) |
|
| 6954 | - $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="checkallactions" name="checkallactions" class="checkallactions"></div>'; |
|
| 7261 | + if (!empty($conf->use_javascript_ajax)) { |
|
| 7262 | + $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="checkallactions" name="checkallactions" class="checkallactions"></div>'; |
|
| 7263 | + } |
|
| 6955 | 7264 | $out .= '<script type="text/javascript"> |
| 6956 | 7265 | $(document).ready(function() {
|
| 6957 | 7266 | $("#checkallactions").click(function() {
|
@@ -6964,8 +7273,9 @@ discard block |
||
| 6964 | 7273 | console.log("We uncheck all");
|
| 6965 | 7274 | $(".' . $cssclass . '").prop(\'checked\', false).trigger(\'change\');
|
| 6966 | 7275 | }' . "\n"; |
| 6967 | - if ($calljsfunction) |
|
| 6968 | - $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
|
|
| 7276 | + if ($calljsfunction) { |
|
| 7277 | + $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }'; |
|
| 7278 | + } |
|
| 6969 | 7279 | $out .= ' }); |
| 6970 | 7280 | |
| 6971 | 7281 | $(".checkforselect").change(function() {
|
@@ -7013,22 +7323,25 @@ discard block |
||
| 7013 | 7323 | |
| 7014 | 7324 | $sql = 'SELECT rowid, label FROM ' . MAIN_DB_PREFIX . 'c_exp_tax_cat WHERE active = 1'; |
| 7015 | 7325 | $sql .= ' AND entity IN (0,' . getEntity('exp_tax_cat') . ')';
|
| 7016 | - if (!empty($excludeid)) |
|
| 7017 | - $sql .= ' AND rowid NOT IN (' . implode(',', $excludeid) . ')';
|
|
| 7326 | + if (!empty($excludeid)) { |
|
| 7327 | + $sql .= ' AND rowid NOT IN (' . implode(',', $excludeid) . ')'; |
|
| 7328 | + } |
|
| 7018 | 7329 | $sql .= ' ORDER BY label'; |
| 7019 | 7330 | |
| 7020 | 7331 | $resql = $db->query($sql); |
| 7021 | 7332 | if ($resql) {
|
| 7022 | 7333 | $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
| 7023 | - if ($useempty) |
|
| 7024 | - $out .= '<option value="0"> </option>'; |
|
| 7334 | + if ($useempty) { |
|
| 7335 | + $out .= '<option value="0"> </option>'; |
|
| 7336 | + } |
|
| 7025 | 7337 | |
| 7026 | 7338 | while ($obj = $db->fetch_object($resql)) {
|
| 7027 | 7339 | $out .= '<option ' . ($selected == $obj->rowid ? 'selected="selected"' : '') . ' value="' . $obj->rowid . '">' . $langs->trans($obj->label) . '</option>'; |
| 7028 | 7340 | } |
| 7029 | 7341 | $out .= '</select>'; |
| 7030 | - if (!empty($htmlname) && $user->admin) |
|
| 7031 | - $out .= ' ' . info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 7342 | + if (!empty($htmlname) && $user->admin) { |
|
| 7343 | + $out .= ' ' . info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 7344 | + } |
|
| 7032 | 7345 | |
| 7033 | 7346 | if (!empty($target)) {
|
| 7034 | 7347 | $sql = "SELECT c.id FROM " . MAIN_DB_PREFIX . "c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; |
@@ -7041,8 +7354,9 @@ discard block |
||
| 7041 | 7354 | $("select[name=' . $target . ']").on("change", function() {
|
| 7042 | 7355 | var current_val = $(this).val(); |
| 7043 | 7356 | if (current_val == ' . $obj->id . ') {';
|
| 7044 | - if (!empty($default_selected) || !empty($selected)) |
|
| 7045 | - $out .= '$("select[name=' . $htmlname . ']").val("' . ($default_selected > 0 ? $default_selected : $selected) . '");';
|
|
| 7357 | + if (!empty($default_selected) || !empty($selected)) { |
|
| 7358 | + $out .= '$("select[name=' . $htmlname . ']").val("' . ($default_selected > 0 ? $default_selected : $selected) . '");'; |
|
| 7359 | + } |
|
| 7046 | 7360 | |
| 7047 | 7361 | $out .= ' |
| 7048 | 7362 | $("select[name=' . $htmlname . ']").change();
|
@@ -7078,8 +7392,7 @@ discard block |
||
| 7078 | 7392 | } |
| 7079 | 7393 | } |
| 7080 | 7394 | } |
| 7081 | - } |
|
| 7082 | - else {
|
|
| 7395 | + } else {
|
|
| 7083 | 7396 | dol_print_error($db); |
| 7084 | 7397 | } |
| 7085 | 7398 | |
@@ -7104,8 +7417,9 @@ discard block |
||
| 7104 | 7417 | $resql = $db->query($sql); |
| 7105 | 7418 | if ($resql) {
|
| 7106 | 7419 | $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
| 7107 | - if ($useempty) |
|
| 7108 | - $out .= '<option value="0"></option>'; |
|
| 7420 | + if ($useempty) { |
|
| 7421 | + $out .= '<option value="0"></option>'; |
|
| 7422 | + } |
|
| 7109 | 7423 | |
| 7110 | 7424 | while ($obj = $db->fetch_object($resql)) {
|
| 7111 | 7425 | $out .= '<option ' . ($selected == $obj->rowid ? 'selected="selected"' : '') . ' value="' . $obj->rowid . '">' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>'; |
@@ -7138,14 +7452,17 @@ discard block |
||
| 7138 | 7452 | $resql = $db->query($sql); |
| 7139 | 7453 | if ($resql) {
|
| 7140 | 7454 | $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
| 7141 | - if ($useempty) |
|
| 7142 | - $out .= '<option value="0"></option>'; |
|
| 7143 | - if ($allchoice) |
|
| 7144 | - $out .= '<option value="-1">' . $langs->trans('AllExpenseReport') . '</option>';
|
|
| 7455 | + if ($useempty) { |
|
| 7456 | + $out .= '<option value="0"></option>'; |
|
| 7457 | + } |
|
| 7458 | + if ($allchoice) { |
|
| 7459 | + $out .= '<option value="-1">' . $langs->trans('AllExpenseReport') . '</option>'; |
|
| 7460 | + } |
|
| 7145 | 7461 | |
| 7146 | 7462 | $field = 'code'; |
| 7147 | - if ($useid) |
|
| 7148 | - $field = 'id'; |
|
| 7463 | + if ($useid) { |
|
| 7464 | + $field = 'id'; |
|
| 7465 | + } |
|
| 7149 | 7466 | |
| 7150 | 7467 | while ($obj = $db->fetch_object($resql)) {
|
| 7151 | 7468 | $key = $langs->trans($obj->code); |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | class Interfaces |
| 25 | 25 | {
|
| 26 | 26 | |
| 27 | - var $dir; // Directory with all core and external triggers files |
|
| 27 | + var $dir; // Directory with all core and external triggers files |
|
| 28 | 28 | |
| 29 | 29 | /** |
| 30 | 30 | * @var string[] Error codes (or messages) |
@@ -58,16 +58,16 @@ discard block |
||
| 58 | 58 | // phpcs:enable |
| 59 | 59 | // Check parameters |
| 60 | 60 | if (!is_object($object) || !is_object($conf)) { // Error
|
| 61 | - $this->error = 'function run_triggers called with wrong parameters action=' . $action . ' object=' . is_object($object) . ' user=' . is_object($user) . ' langs=' . is_object($langs) . ' conf=' . is_object($conf); |
|
| 62 | - DolUtils::dol_syslog(get_class($this) . '::run_triggers ' . $this->error, LOG_ERR); |
|
| 61 | + $this->error = 'function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf); |
|
| 62 | + DolUtils::dol_syslog(get_class($this).'::run_triggers '.$this->error, LOG_ERR); |
|
| 63 | 63 | $this->errors[] = $this->error; |
| 64 | 64 | return -1; |
| 65 | 65 | } |
| 66 | 66 | if (!is_object($langs)) { // Warning
|
| 67 | - DolUtils::dol_syslog(get_class($this) . '::run_triggers was called with wrong parameters action=' . $action . ' object=' . is_object($object) . ' user=' . is_object($user) . ' langs=' . is_object($langs) . ' conf=' . is_object($conf), LOG_WARNING); |
|
| 67 | + DolUtils::dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING); |
|
| 68 | 68 | } |
| 69 | 69 | if (!is_object($user)) { // Warning
|
| 70 | - DolUtils::dol_syslog(get_class($this) . '::run_triggers was called with wrong parameters action=' . $action . ' object=' . is_object($object) . ' user=' . is_object($user) . ' langs=' . is_object($langs) . ' conf=' . is_object($conf), LOG_WARNING); |
|
| 70 | + DolUtils::dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING); |
|
| 71 | 71 | global $db; |
| 72 | 72 | $user = new User($db); |
| 73 | 73 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | $i = 0; |
| 81 | 81 | |
| 82 | 82 | // $dirtriggers = array_merge(array('/core/triggers'), $conf->modules_parts['triggers']);
|
| 83 | - $dirtriggers = array_merge(array(BASE_PATH . '/Helpers/triggers'), $conf->modules_parts['triggers']); |
|
| 83 | + $dirtriggers = array_merge(array(BASE_PATH.'/Helpers/triggers'), $conf->modules_parts['triggers']); |
|
| 84 | 84 | foreach ($dirtriggers as $reldir) {
|
| 85 | 85 | //$dir = DolUtils::dol_buildpath($reldir, 0); |
| 86 | 86 | //$newdir = DolUtils::dol_osencode($dir); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $handle = opendir($newdir); |
| 94 | 94 | if (is_resource($handle)) {
|
| 95 | 95 | while (($file = readdir($handle)) !== false) {
|
| 96 | - if (is_readable($newdir . "/" . $file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i', $file, $reg)) {
|
|
| 96 | + if (is_readable($newdir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i', $file, $reg)) {
|
|
| 97 | 97 | $part1 = $reg[1]; |
| 98 | 98 | $part2 = $reg[2]; |
| 99 | 99 | $part3 = $reg[3]; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | $qualified = true; |
| 108 | 108 | if (strtolower($reg[2]) != 'all') {
|
| 109 | 109 | $module = preg_replace('/^mod/i', '', $reg[2]);
|
| 110 | - $constparam = 'MAIN_MODULE_' . strtoupper($module); |
|
| 110 | + $constparam = 'MAIN_MODULE_'.strtoupper($module); |
|
| 111 | 111 | if (empty($conf->global->$constparam)) |
| 112 | 112 | $qualified = false; |
| 113 | 113 | } |
@@ -117,26 +117,26 @@ discard block |
||
| 117 | 117 | continue; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $modName = "Interface" . ucfirst($reg[3]); |
|
| 120 | + $modName = "Interface".ucfirst($reg[3]); |
|
| 121 | 121 | //print "file=$file - modName=$modName\n"; |
| 122 | 122 | if (in_array($modName, $modules)) { // $modules = list of modName already loaded
|
| 123 | 123 | $langs->load("errors");
|
| 124 | - DolUtils::dol_syslog(get_class($this) . "::run_triggers action=" . $action . " " . $langs->trans("ErrorDuplicateTrigger", $newdir . "/" . $file, $fullpathfiles[$modName]), LOG_WARNING);
|
|
| 124 | + DolUtils::dol_syslog(get_class($this)."::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger", $newdir."/".$file, $fullpathfiles[$modName]), LOG_WARNING);
|
|
| 125 | 125 | continue; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | try {
|
| 129 | 129 | //print 'Todo for '.$modName." : ".$newdir.'/'.$file."\n"; |
| 130 | - include_once $newdir . '/' . $file; |
|
| 130 | + include_once $newdir.'/'.$file; |
|
| 131 | 131 | //print 'Done for '.$modName."\n"; |
| 132 | 132 | } catch (Exception $e) {
|
| 133 | - DolUtils::dol_syslog('ko for ' . $modName . " " . $e->getMessage() . "\n", LOG_ERR);
|
|
| 133 | + DolUtils::dol_syslog('ko for '.$modName." ".$e->getMessage()."\n", LOG_ERR);
|
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | $modules[$i] = $modName; |
| 137 | 137 | $files[$i] = $file; |
| 138 | - $fullpathfiles[$modName] = $newdir . '/' . $file; |
|
| 139 | - $orders[$i] = $part1 . '_' . $part2 . '_' . $part3; // Set sort criteria value |
|
| 138 | + $fullpathfiles[$modName] = $newdir.'/'.$file; |
|
| 139 | + $orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value |
|
| 140 | 140 | |
| 141 | 141 | $i++; |
| 142 | 142 | } |
@@ -160,10 +160,10 @@ discard block |
||
| 160 | 160 | //DolUtils::dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG); |
| 161 | 161 | $result = $objMod->runTrigger($action, $object, $user, $langs, $conf); |
| 162 | 162 | } elseif (method_exists($objMod, 'run_trigger')) { // Deprecated method
|
| 163 | - DolUtils::dol_syslog(get_class($this) . "::run_triggers action=" . $action . " Launch old method run_trigger (rename your trigger into runTrigger) for file '" . $files[$key] . "'", LOG_WARNING); |
|
| 163 | + DolUtils::dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING); |
|
| 164 | 164 | $result = $objMod->run_trigger($action, $object, $user, $langs, $conf); |
| 165 | 165 | } else {
|
| 166 | - DolUtils::dol_syslog(get_class($this) . "::run_triggers action=" . $action . " A trigger was declared for class " . get_class($objMod) . " but method runTrigger was not found", LOG_ERR); |
|
| 166 | + DolUtils::dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR); |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | if ($result > 0) {
|
@@ -188,12 +188,12 @@ discard block |
||
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | else {
|
| 191 | - DolUtils::dol_syslog(get_class($this) . "::run_triggers action=" . $action . " Failed to instantiate trigger for file '" . $files[$key] . "'", LOG_ERR); |
|
| 191 | + DolUtils::dol_syslog(get_class($this)."::run_triggers action=".$action." Failed to instantiate trigger for file '".$files[$key]."'", LOG_ERR); |
|
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | if ($nbko) {
|
| 196 | - DolUtils::dol_syslog(get_class($this) . "::run_triggers action=" . $action . " Files found: " . $nbfile . ", Files launched: " . $nbtotal . ", Done: " . $nbok . ", Failed: " . $nbko . " - Nb of error string returned in this->errors = " . count($this->errors), LOG_ERR); |
|
| 196 | + DolUtils::dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko." - Nb of error string returned in this->errors = ".count($this->errors), LOG_ERR); |
|
| 197 | 197 | return -$nbko; |
| 198 | 198 | } else {
|
| 199 | 199 | //DolUtils::dol_syslog(get_class($this)."::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG); |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $handle = opendir($newdir); |
| 237 | 237 | if (is_resource($handle)) {
|
| 238 | 238 | while (($file = readdir($handle)) !== false) {
|
| 239 | - if (is_readable($newdir . '/' . $file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/', $file, $reg)) {
|
|
| 239 | + if (is_readable($newdir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/', $file, $reg)) {
|
|
| 240 | 240 | if (preg_match('/\.back$/', $file))
|
| 241 | 241 | continue; |
| 242 | 242 | |
@@ -244,21 +244,21 @@ discard block |
||
| 244 | 244 | $part2 = $reg[2]; |
| 245 | 245 | $part3 = $reg[3]; |
| 246 | 246 | |
| 247 | - $modName = 'Interface' . ucfirst($reg[3]); |
|
| 247 | + $modName = 'Interface'.ucfirst($reg[3]); |
|
| 248 | 248 | //print "file=$file"; print "modName=$modName"; exit; |
| 249 | 249 | if (in_array($modName, $modules)) {
|
| 250 | 250 | $langs->load("errors");
|
| 251 | - print '<div class="error">' . $langs->trans("Error") . ' : ' . $langs->trans("ErrorDuplicateTrigger", $modName, "/htdocs/core/triggers/") . '</div>';
|
|
| 251 | + print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger", $modName, "/htdocs/core/triggers/").'</div>';
|
|
| 252 | 252 | } else {
|
| 253 | - include_once $newdir . '/' . $file; |
|
| 253 | + include_once $newdir.'/'.$file; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | $files[$i] = $file; |
| 257 | - $fullpath[$i] = $dir . '/' . $file; |
|
| 258 | - $relpath[$i] = preg_replace('/^\//', '', $reldir) . '/' . $file;
|
|
| 257 | + $fullpath[$i] = $dir.'/'.$file; |
|
| 258 | + $relpath[$i] = preg_replace('/^\//', '', $reldir).'/'.$file;
|
|
| 259 | 259 | $iscoreorexternal[$i] = ($reldir == '/core/triggers/' ? 'internal' : 'external'); |
| 260 | 260 | $modules[$i] = $modName; |
| 261 | - $orders[$i] = $part1 . '_' . $part2 . '_' . $part3; // Set sort criteria value |
|
| 261 | + $orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value |
|
| 262 | 262 | |
| 263 | 263 | $i++; |
| 264 | 264 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | continue; |
| 280 | 280 | |
| 281 | 281 | if (!class_exists($modName)) {
|
| 282 | - print 'Error: A trigger file was found but its class "' . $modName . '" was not found.' . "<br>\n"; |
|
| 282 | + print 'Error: A trigger file was found but its class "'.$modName.'" was not found.'."<br>\n"; |
|
| 283 | 283 | continue; |
| 284 | 284 | } |
| 285 | 285 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | // Check if trigger file is for a particular module |
| 297 | 297 | if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i', $files[$key], $reg)) {
|
| 298 | 298 | $module = preg_replace('/^mod/i', '', $reg[2]);
|
| 299 | - $constparam = 'MAIN_MODULE_' . strtoupper($module); |
|
| 299 | + $constparam = 'MAIN_MODULE_'.strtoupper($module); |
|
| 300 | 300 | if (strtolower($module) == 'all') |
| 301 | 301 | $disabledbymodule = 0; |
| 302 | 302 | else if (empty($conf->global->$constparam)) |
@@ -315,21 +315,21 @@ discard block |
||
| 315 | 315 | if ($disabledbyname > 0 || $disabledbymodule > 1) |
| 316 | 316 | $triggers[$j]['status'] = ''; |
| 317 | 317 | |
| 318 | - $text = '<b>' . $langs->trans("Description") . ':</b><br>';
|
|
| 319 | - $text .= $objMod->getDesc() . '<br>'; |
|
| 320 | - $text .= '<br><b>' . $langs->trans("Status") . ':</b><br>';
|
|
| 318 | + $text = '<b>'.$langs->trans("Description").':</b><br>';
|
|
| 319 | + $text .= $objMod->getDesc().'<br>'; |
|
| 320 | + $text .= '<br><b>'.$langs->trans("Status").':</b><br>';
|
|
| 321 | 321 | if ($disabledbyname == 1) {
|
| 322 | - $text .= $langs->trans("TriggerDisabledByName") . '<br>';
|
|
| 322 | + $text .= $langs->trans("TriggerDisabledByName").'<br>';
|
|
| 323 | 323 | if ($disabledbymodule == 2) |
| 324 | - $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>';
|
|
| 324 | + $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module).'<br>';
|
|
| 325 | 325 | } |
| 326 | 326 | else {
|
| 327 | 327 | if ($disabledbymodule == 0) |
| 328 | - $text .= $langs->trans("TriggerAlwaysActive") . '<br>';
|
|
| 328 | + $text .= $langs->trans("TriggerAlwaysActive").'<br>';
|
|
| 329 | 329 | if ($disabledbymodule == 1) |
| 330 | - $text .= $langs->trans("TriggerActiveAsModuleActive", $module) . '<br>';
|
|
| 330 | + $text .= $langs->trans("TriggerActiveAsModuleActive", $module).'<br>';
|
|
| 331 | 331 | if ($disabledbymodule == 2) |
| 332 | - $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>';
|
|
| 332 | + $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module).'<br>';
|
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | $triggers[$j]['info'] = $text; |
@@ -87,8 +87,9 @@ discard block |
||
| 87 | 87 | $newdir = DolUtils::dol_buildpath($reldir, 0); |
| 88 | 88 | //print "xx".$dir;exit; |
| 89 | 89 | // Check if directory exists (we do not use dol_is_dir to avoir loading files.lib.php at each call) |
| 90 | - if (!is_dir($newdir)) |
|
| 91 | - continue; |
|
| 90 | + if (!is_dir($newdir)) { |
|
| 91 | + continue; |
|
| 92 | + } |
|
| 92 | 93 | |
| 93 | 94 | $handle = opendir($newdir); |
| 94 | 95 | if (is_resource($handle)) {
|
@@ -101,15 +102,17 @@ discard block |
||
| 101 | 102 | $nbfile++; |
| 102 | 103 | |
| 103 | 104 | // Check if trigger file is disabled by name |
| 104 | - if (preg_match('/NORUN$/i', $file))
|
|
| 105 | - continue; |
|
| 105 | + if (preg_match('/NORUN$/i', $file)) { |
|
| 106 | + continue; |
|
| 107 | + } |
|
| 106 | 108 | // Check if trigger file is for a particular module |
| 107 | 109 | $qualified = true; |
| 108 | 110 | if (strtolower($reg[2]) != 'all') {
|
| 109 | 111 | $module = preg_replace('/^mod/i', '', $reg[2]);
|
| 110 | 112 | $constparam = 'MAIN_MODULE_' . strtoupper($module); |
| 111 | - if (empty($conf->global->$constparam)) |
|
| 112 | - $qualified = false; |
|
| 113 | + if (empty($conf->global->$constparam)) { |
|
| 114 | + $qualified = false; |
|
| 115 | + } |
|
| 113 | 116 | } |
| 114 | 117 | |
| 115 | 118 | if (!$qualified) {
|
@@ -149,8 +152,9 @@ discard block |
||
| 149 | 152 | // Loop on each trigger |
| 150 | 153 | foreach ($orders as $key => $value) {
|
| 151 | 154 | $modName = $modules[$key]; |
| 152 | - if (empty($modName)) |
|
| 153 | - continue; |
|
| 155 | + if (empty($modName)) { |
|
| 156 | + continue; |
|
| 157 | + } |
|
| 154 | 158 | |
| 155 | 159 | $objMod = new $modName(); |
| 156 | 160 | if ($objMod) {
|
@@ -180,14 +184,14 @@ discard block |
||
| 180 | 184 | //DolUtils::dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($objMod->errors), LOG_ERR);
|
| 181 | 185 | $nbtotal++; |
| 182 | 186 | $nbko++; |
| 183 | - if (!empty($objMod->errors)) |
|
| 184 | - $this->errors = array_merge($this->errors, $objMod->errors); |
|
| 185 | - else if (!empty($objMod->error)) |
|
| 186 | - $this->errors[] = $objMod->error; |
|
| 187 | + if (!empty($objMod->errors)) { |
|
| 188 | + $this->errors = array_merge($this->errors, $objMod->errors); |
|
| 189 | + } else if (!empty($objMod->error)) { |
|
| 190 | + $this->errors[] = $objMod->error; |
|
| 191 | + } |
|
| 187 | 192 | //DolUtils::dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($this->errors), LOG_ERR);
|
| 188 | 193 | } |
| 189 | - } |
|
| 190 | - else {
|
|
| 194 | + } else {
|
|
| 191 | 195 | DolUtils::dol_syslog(get_class($this) . "::run_triggers action=" . $action . " Failed to instantiate trigger for file '" . $files[$key] . "'", LOG_ERR); |
| 192 | 196 | } |
| 193 | 197 | } |
@@ -230,15 +234,17 @@ discard block |
||
| 230 | 234 | $newdir = DolUtils::dol_osencode($dir); |
| 231 | 235 | |
| 232 | 236 | // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call) |
| 233 | - if (!is_dir($newdir)) |
|
| 234 | - continue; |
|
| 237 | + if (!is_dir($newdir)) { |
|
| 238 | + continue; |
|
| 239 | + } |
|
| 235 | 240 | |
| 236 | 241 | $handle = opendir($newdir); |
| 237 | 242 | if (is_resource($handle)) {
|
| 238 | 243 | while (($file = readdir($handle)) !== false) {
|
| 239 | 244 | if (is_readable($newdir . '/' . $file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/', $file, $reg)) {
|
| 240 | - if (preg_match('/\.back$/', $file))
|
|
| 241 | - continue; |
|
| 245 | + if (preg_match('/\.back$/', $file)) { |
|
| 246 | + continue; |
|
| 247 | + } |
|
| 242 | 248 | |
| 243 | 249 | $part1 = $reg[1]; |
| 244 | 250 | $part2 = $reg[2]; |
@@ -275,8 +281,9 @@ discard block |
||
| 275 | 281 | // Loop on each trigger |
| 276 | 282 | foreach ($orders as $key => $value) {
|
| 277 | 283 | $modName = $modules[$key]; |
| 278 | - if (empty($modName)) |
|
| 279 | - continue; |
|
| 284 | + if (empty($modName)) { |
|
| 285 | + continue; |
|
| 286 | + } |
|
| 280 | 287 | |
| 281 | 288 | if (!class_exists($modName)) {
|
| 282 | 289 | print 'Error: A trigger file was found but its class "' . $modName . '" was not found.' . "<br>\n"; |
@@ -291,16 +298,18 @@ discard block |
||
| 291 | 298 | $module = ''; |
| 292 | 299 | |
| 293 | 300 | // Check if trigger file is disabled by name |
| 294 | - if (preg_match('/NORUN$/i', $files[$key]))
|
|
| 295 | - $disabledbyname = 1; |
|
| 301 | + if (preg_match('/NORUN$/i', $files[$key])) { |
|
| 302 | + $disabledbyname = 1; |
|
| 303 | + } |
|
| 296 | 304 | // Check if trigger file is for a particular module |
| 297 | 305 | if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i', $files[$key], $reg)) {
|
| 298 | 306 | $module = preg_replace('/^mod/i', '', $reg[2]);
|
| 299 | 307 | $constparam = 'MAIN_MODULE_' . strtoupper($module); |
| 300 | - if (strtolower($module) == 'all') |
|
| 301 | - $disabledbymodule = 0; |
|
| 302 | - else if (empty($conf->global->$constparam)) |
|
| 303 | - $disabledbymodule = 2; |
|
| 308 | + if (strtolower($module) == 'all') { |
|
| 309 | + $disabledbymodule = 0; |
|
| 310 | + } else if (empty($conf->global->$constparam)) { |
|
| 311 | + $disabledbymodule = 2; |
|
| 312 | + } |
|
| 304 | 313 | $triggers[$j]['module'] = strtolower($module); |
| 305 | 314 | } |
| 306 | 315 | |
@@ -312,24 +321,28 @@ discard block |
||
| 312 | 321 | $triggers[$j]['iscoreorexternal'] = $iscoreorexternal[$key]; |
| 313 | 322 | $triggers[$j]['version'] = $objMod->getVersion(); |
| 314 | 323 | $triggers[$j]['status'] = img_picto($langs->trans("Active"), 'tick');
|
| 315 | - if ($disabledbyname > 0 || $disabledbymodule > 1) |
|
| 316 | - $triggers[$j]['status'] = ''; |
|
| 324 | + if ($disabledbyname > 0 || $disabledbymodule > 1) { |
|
| 325 | + $triggers[$j]['status'] = ''; |
|
| 326 | + } |
|
| 317 | 327 | |
| 318 | 328 | $text = '<b>' . $langs->trans("Description") . ':</b><br>';
|
| 319 | 329 | $text .= $objMod->getDesc() . '<br>'; |
| 320 | 330 | $text .= '<br><b>' . $langs->trans("Status") . ':</b><br>';
|
| 321 | 331 | if ($disabledbyname == 1) {
|
| 322 | 332 | $text .= $langs->trans("TriggerDisabledByName") . '<br>';
|
| 323 | - if ($disabledbymodule == 2) |
|
| 324 | - $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>';
|
|
| 325 | - } |
|
| 326 | - else {
|
|
| 327 | - if ($disabledbymodule == 0) |
|
| 328 | - $text .= $langs->trans("TriggerAlwaysActive") . '<br>';
|
|
| 329 | - if ($disabledbymodule == 1) |
|
| 330 | - $text .= $langs->trans("TriggerActiveAsModuleActive", $module) . '<br>';
|
|
| 331 | - if ($disabledbymodule == 2) |
|
| 332 | - $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>';
|
|
| 333 | + if ($disabledbymodule == 2) { |
|
| 334 | + $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>'; |
|
| 335 | + } |
|
| 336 | + } else {
|
|
| 337 | + if ($disabledbymodule == 0) { |
|
| 338 | + $text .= $langs->trans("TriggerAlwaysActive") . '<br>'; |
|
| 339 | + } |
|
| 340 | + if ($disabledbymodule == 1) { |
|
| 341 | + $text .= $langs->trans("TriggerActiveAsModuleActive", $module) . '<br>'; |
|
| 342 | + } |
|
| 343 | + if ($disabledbymodule == 2) { |
|
| 344 | + $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module) . '<br>'; |
|
| 345 | + } |
|
| 333 | 346 | } |
| 334 | 347 | |
| 335 | 348 | $triggers[$j]['info'] = $text; |
@@ -21,13 +21,13 @@ discard block |
||
| 21 | 21 | class Langs |
| 22 | 22 | {
|
| 23 | 23 | |
| 24 | - public $dir; // Directories that contains /langs subdirectory |
|
| 25 | - public $defaultlang; // Current language for current user |
|
| 26 | - public $charset_output = 'UTF-8'; // Codage used by "trans" method outputs |
|
| 27 | - public $tab_translate = array(); // Array of all translations key=>value |
|
| 28 | - private $_tab_loaded = array(); // Array to store result after loading each language file |
|
| 29 | - public $cache_labels = array(); // Cache for labels return by getLabelFromKey method |
|
| 30 | - public $cache_currencies = array(); // Cache to store currency symbols |
|
| 24 | + public $dir; // Directories that contains /langs subdirectory |
|
| 25 | + public $defaultlang; // Current language for current user |
|
| 26 | + public $charset_output = 'UTF-8'; // Codage used by "trans" method outputs |
|
| 27 | + public $tab_translate = array(); // Array of all translations key=>value |
|
| 28 | + private $_tab_loaded = array(); // Array to store result after loading each language file |
|
| 29 | + public $cache_labels = array(); // Cache for labels return by getLabelFromKey method |
|
| 30 | + public $cache_currencies = array(); // Cache to store currency symbols |
|
| 31 | 31 | private $cache_currencies_all_loaded = false; |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -60,13 +60,13 @@ discard block |
||
| 60 | 60 | $more = array(); |
| 61 | 61 | $i = 0; |
| 62 | 62 | foreach ($conf->file->dol_document_root as $dir) {
|
| 63 | - $newdir = $dir . $conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX' |
|
| 63 | + $newdir = $dir.$conf->global->MAIN_FORCELANGDIR; // For example $conf->global->MAIN_FORCELANGDIR is '/mymodule' meaning we search files into '/mymodule/langs/xx_XX' |
|
| 64 | 64 | if (!in_array($newdir, $this->dir)) {
|
| 65 | - $more['module_' . $i] = $newdir; |
|
| 66 | - $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir. |
|
| 65 | + $more['module_'.$i] = $newdir; |
|
| 66 | + $i++; // We add the forced dir into the array $more. Just after, we add entries into $more to list of lang dir $this->dir. |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | - $this->dir = array_merge($more, $this->dir); // Forced dir ($more) are before standard dirs ($this->dir) |
|
| 69 | + $this->dir = array_merge($more, $this->dir); // Forced dir ($more) are before standard dirs ($this->dir) |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | $this->origlang = $srclang; |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) |
| 91 | 91 | $srclang = $longforshort[strtolower($langpart[0])]; |
| 92 | 92 | else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser
|
| 93 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[1]); |
|
| 93 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[1]); |
|
| 94 | 94 | $longforlong = array('no_nb' => 'nb_NO');
|
| 95 | 95 | if (isset($longforlong[strtolower($srclang)])) |
| 96 | 96 | $srclang = $longforlong[strtolower($srclang)]; |
| 97 | 97 | } else |
| 98 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 98 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
| 99 | 99 | } |
| 100 | 100 | else { // If it's for a codetouse that is a short code xx
|
| 101 | 101 | // Array to convert short lang code into long code. |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | if (isset($longforshort[strtolower($langpart[0])])) |
| 104 | 104 | $srclang = $longforshort[strtolower($langpart[0])]; |
| 105 | 105 | else if (!empty($langpart[0])) |
| 106 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 106 | + $srclang = strtolower($langpart[0])."_".strtoupper($langpart[0]); |
|
| 107 | 107 | else |
| 108 | 108 | $srclang = 'en_US'; |
| 109 | 109 | } |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | //DolUtils::dol_syslog("Translate::Load Start domain=".$domain." alt=".$alt." forcelangdir=".$forcelangdir." this->defaultlang=".$this->defaultlang);
|
| 168 | 168 | // Check parameters |
| 169 | 169 | if (empty($domain)) {
|
| 170 | - dol_print_error('', get_class($this) . "::Load ErrorWrongParameters");
|
|
| 170 | + dol_print_error('', get_class($this)."::Load ErrorWrongParameters");
|
|
| 171 | 171 | return -1; |
| 172 | 172 | } |
| 173 | 173 | if ($this->defaultlang == 'none_NONE') |
| 174 | - return 0; // Special language code to not translate keys |
|
| 174 | + return 0; // Special language code to not translate keys |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | 177 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | // Load $this->tab_translate[] from database |
| 182 | 182 | if (empty($loadfromfileonly) && count($this->tab_translate) == 0) |
| 183 | - $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. |
|
| 183 | + $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. |
|
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | $newdomain = $domain; |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | $alt = 2; |
| 210 | 210 | |
| 211 | 211 | if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir
|
| 212 | - DolUtils::dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
|
|
| 212 | + DolUtils::dol_syslog("Error: ".get_class($this)."::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
|
|
| 213 | 213 | return -1; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | foreach ($this->dir as $keydir => $searchdir) {
|
| 217 | 217 | // Directory of translation files |
| 218 | - $file_lang = $searchdir . ($modulename ? '/' . $modulename : '') . "/langs/" . $langofdir . "/" . $newdomain . ".lang"; |
|
| 218 | + $file_lang = $searchdir.($modulename ? '/'.$modulename : '')."/langs/".$langofdir."/".$newdomain.".lang"; |
|
| 219 | 219 | $file_lang_osencoded = dol_osencode($file_lang); |
| 220 | 220 | |
| 221 | 221 | $filelangexists = is_file($file_lang_osencoded); |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | $usecachekey = ''; |
| 232 | 232 | // Using a memcached server |
| 233 | 233 | if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) {
|
| 234 | - $usecachekey = $newdomain . '_' . $langofdir . '_' . md5($file_lang); // Should not contains special chars |
|
| 234 | + $usecachekey = $newdomain.'_'.$langofdir.'_'.md5($file_lang); // Should not contains special chars |
|
| 235 | 235 | } |
| 236 | 236 | // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) |
| 237 | 237 | else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) {
|
@@ -242,7 +242,7 @@ discard block |
||
| 242 | 242 | //DolUtils::dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey);
|
| 243 | 243 | //global $aaa; $aaa+=1; |
| 244 | 244 | //print $aaa." ".$usecachekey."\n"; |
| 245 | - require_once DOL_BASE_PATH . '/core/lib/memory.lib.php'; |
|
| 245 | + require_once DOL_BASE_PATH.'/core/lib/memory.lib.php'; |
|
| 246 | 246 | $tmparray = dol_getcache($usecachekey); |
| 247 | 247 | if (is_array($tmparray) && count($tmparray)) {
|
| 248 | 248 | $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. |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | //var_dump($this->tab_translate); |
| 251 | 251 | if ($alt == 2) |
| 252 | 252 | $fileread = 1; |
| 253 | - $found = true; // Found in dolibarr PHP cache |
|
| 253 | + $found = true; // Found in dolibarr PHP cache |
|
| 254 | 254 | } |
| 255 | 255 | } |
| 256 | 256 | |
@@ -300,13 +300,13 @@ discard block |
||
| 300 | 300 | if ($usecachekey && count($tabtranslatedomain)) {
|
| 301 | 301 | $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain); |
| 302 | 302 | if ($ressetcache < 0) {
|
| 303 | - $error = 'Failed to set cache for usecachekey=' . $usecachekey . ' result=' . $ressetcache; |
|
| 303 | + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
| 304 | 304 | DolUtils::dol_syslog($error, LOG_ERR); |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | if (empty($conf->global->MAIN_FORCELANGDIR)) |
| 309 | - break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 309 | + break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 310 | 310 | } |
| 311 | 311 | } |
| 312 | 312 | } |
@@ -316,11 +316,11 @@ discard block |
||
| 316 | 316 | if ($alt == 0) {
|
| 317 | 317 | // This function MUST NOT contains call to syslog |
| 318 | 318 | //DolUtils::dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
|
| 319 | - $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]); |
|
| 319 | + $langofdir = strtolower($langarray[0]).'_'.strtoupper($langarray[0]); |
|
| 320 | 320 | if ($langofdir == 'el_EL') |
| 321 | - $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 321 | + $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 322 | 322 | if ($langofdir == 'ar_AR') |
| 323 | - $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 323 | + $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 324 | 324 | $this->load($domain, $alt + 1, $stopafterdirection, $langofdir); |
| 325 | 325 | } |
| 326 | 326 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | // We are in the pass of the reference file. No more files to scan to complete. |
| 336 | 336 | if ($alt == 2) {
|
| 337 | 337 | if ($fileread) |
| 338 | - $this->_tab_loaded[$newdomain] = 1; // Set domain file as found so loaded |
|
| 338 | + $this->_tab_loaded[$newdomain] = 1; // Set domain file as found so loaded |
|
| 339 | 339 | |
| 340 | 340 | if (empty($this->_tab_loaded[$newdomain])) |
| 341 | 341 | $this->_tab_loaded[$newdomain] = 2; // Set this file as not found |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | // This part is deprecated and replaced with table llx_overwrite_trans |
| 345 | 345 | // Kept for backward compatibility. |
| 346 | 346 | if (empty($loadfromfileonly)) {
|
| 347 | - $overwritekey = 'MAIN_OVERWRITE_TRANS_' . $this->defaultlang; |
|
| 347 | + $overwritekey = 'MAIN_OVERWRITE_TRANS_'.$this->defaultlang; |
|
| 348 | 348 | if (!empty($conf->global->$overwritekey)) { // Overwrite translation with key1:newstring1,key2:newstring2
|
| 349 | 349 | // Overwrite translation with param MAIN_OVERWRITE_TRANS_xx_XX |
| 350 | 350 | $tmparray = explode(',', $conf->global->$overwritekey);
|
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | |
| 384 | 384 | // Check parameters |
| 385 | 385 | if (empty($db)) |
| 386 | - return 0; // Database handler can't be used |
|
| 386 | + return 0; // Database handler can't be used |
|
| 387 | 387 | |
| 388 | 388 | |
| 389 | 389 | |
@@ -400,13 +400,13 @@ discard block |
||
| 400 | 400 | return 0; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | - $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only for domain 'database' |
|
| 403 | + $this->_tab_loaded[$newdomain] = 1; // We want to be sure this function is called once only for domain 'database' |
|
| 404 | 404 | |
| 405 | 405 | $fileread = 0; |
| 406 | 406 | $langofdir = $this->defaultlang; |
| 407 | 407 | |
| 408 | 408 | if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir
|
| 409 | - DolUtils::dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
|
|
| 409 | + DolUtils::dol_syslog("Error: ".get_class($this)."::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
|
|
| 410 | 410 | return -1; |
| 411 | 411 | } |
| 412 | 412 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | $usecachekey = ''; |
| 418 | 418 | // Using a memcached server |
| 419 | 419 | if (!empty($conf->memcached->enabled) && !empty($conf->global->MEMCACHED_SERVER)) {
|
| 420 | - $usecachekey = $newdomain . '_' . $langofdir; // Should not contains special chars |
|
| 420 | + $usecachekey = $newdomain.'_'.$langofdir; // Should not contains special chars |
|
| 421 | 421 | } |
| 422 | 422 | // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) |
| 423 | 423 | else if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) {
|
@@ -428,20 +428,20 @@ discard block |
||
| 428 | 428 | //DolUtils::dol_syslog('Translate::Load we will cache result into usecachekey '.$usecachekey);
|
| 429 | 429 | //global $aaa; $aaa+=1; |
| 430 | 430 | //print $aaa." ".$usecachekey."\n"; |
| 431 | - require_once DOL_BASE_PATH . '/core/lib/memory.lib.php'; |
|
| 431 | + require_once DOL_BASE_PATH.'/core/lib/memory.lib.php'; |
|
| 432 | 432 | $tmparray = dol_getcache($usecachekey); |
| 433 | 433 | if (is_array($tmparray) && count($tmparray)) {
|
| 434 | 434 | $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. |
| 435 | 435 | //print $newdomain."\n"; |
| 436 | 436 | //var_dump($this->tab_translate); |
| 437 | 437 | $fileread = 1; |
| 438 | - $found = true; // Found in dolibarr PHP cache |
|
| 438 | + $found = true; // Found in dolibarr PHP cache |
|
| 439 | 439 | } |
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | if (!$found && !empty($conf->global->MAIN_ENABLE_OVERWRITE_TRANSLATION)) {
|
| 443 | 443 | // Overwrite translation with database read |
| 444 | - $sql = "SELECT transkey, transvalue FROM " . MAIN_DB_PREFIX . "overwrite_trans where lang='" . $db->escape($this->defaultlang) . "'"; |
|
| 444 | + $sql = "SELECT transkey, transvalue FROM ".MAIN_DB_PREFIX."overwrite_trans where lang='".$db->escape($this->defaultlang)."'"; |
|
| 445 | 445 | $resql = $db->query($sql); |
| 446 | 446 | |
| 447 | 447 | if ($resql) {
|
@@ -476,7 +476,7 @@ discard block |
||
| 476 | 476 | if ($usecachekey && count($tabtranslatedomain)) {
|
| 477 | 477 | $ressetcache = dol_setcache($usecachekey, $tabtranslatedomain); |
| 478 | 478 | if ($ressetcache < 0) {
|
| 479 | - $error = 'Failed to set cache for usecachekey=' . $usecachekey . ' result=' . $ressetcache; |
|
| 479 | + $error = 'Failed to set cache for usecachekey='.$usecachekey.' result='.$ressetcache; |
|
| 480 | 480 | DolUtils::dol_syslog($error, LOG_ERR); |
| 481 | 481 | } |
| 482 | 482 | } |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded |
| 491 | 491 | |
| 492 | 492 | if (empty($this->_tab_loaded[$newdomain])) |
| 493 | - $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
| 493 | + $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
| 494 | 494 | |
| 495 | 495 | return 1; |
| 496 | 496 | } |
@@ -560,12 +560,12 @@ discard block |
||
| 560 | 560 | $str = $this->tab_translate[$key]; |
| 561 | 561 | |
| 562 | 562 | // Make some string replacement after translation |
| 563 | - $replacekey = 'MAIN_REPLACE_TRANS_' . $this->defaultlang; |
|
| 563 | + $replacekey = 'MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
| 564 | 564 | if (!empty($conf->global->$replacekey)) { // Replacement translation variable with string1:newstring1;string2:newstring2
|
| 565 | 565 | $tmparray = explode(';', $conf->global->$replacekey);
|
| 566 | 566 | foreach ($tmparray as $tmp) {
|
| 567 | 567 | $tmparray2 = explode(':', $tmp);
|
| 568 | - $str = preg_replace('/' . preg_quote($tmparray2[0]) . '/', $tmparray2[1], $str);
|
|
| 568 | + $str = preg_replace('/'.preg_quote($tmparray2[0]).'/', $tmparray2[1], $str);
|
|
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | |
@@ -635,12 +635,12 @@ discard block |
||
| 635 | 635 | $str = $this->tab_translate[$key]; |
| 636 | 636 | |
| 637 | 637 | // Make some string replacement after translation |
| 638 | - $replacekey = 'MAIN_REPLACE_TRANS_' . $this->defaultlang; |
|
| 638 | + $replacekey = 'MAIN_REPLACE_TRANS_'.$this->defaultlang; |
|
| 639 | 639 | if (!empty($conf->global->$replacekey)) { // Replacement translation variable with string1:newstring1;string2:newstring2
|
| 640 | 640 | $tmparray = explode(';', $conf->global->$replacekey);
|
| 641 | 641 | foreach ($tmparray as $tmp) {
|
| 642 | 642 | $tmparray2 = explode(':', $tmp);
|
| 643 | - $str = preg_replace('/' . preg_quote($tmparray2[0]) . '/', $tmparray2[1], $str);
|
|
| 643 | + $str = preg_replace('/'.preg_quote($tmparray2[0]).'/', $tmparray2[1], $str);
|
|
| 644 | 644 | } |
| 645 | 645 | } |
| 646 | 646 | |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | // We scan directory langs to detect available languages |
| 726 | - $handle = opendir($langdir . "/langs"); |
|
| 726 | + $handle = opendir($langdir."/langs"); |
|
| 727 | 727 | $langs_available = array(); |
| 728 | 728 | while ($dir = trim(readdir($handle))) {
|
| 729 | 729 | if (preg_match('/^[a-z]+_[A-Z]+/i', $dir)) {
|
@@ -733,9 +733,9 @@ discard block |
||
| 733 | 733 | $langs_available[$dir] = $dir; |
| 734 | 734 | } |
| 735 | 735 | if ($usecode == 1 || !empty($conf->global->MAIN_SHOW_LANGUAGE_CODE)) {
|
| 736 | - $langs_available[$dir] = $dir . ': ' . dol_trunc($this->trans('Language_' . $dir), $maxlength);
|
|
| 736 | + $langs_available[$dir] = $dir.': '.dol_trunc($this->trans('Language_'.$dir), $maxlength);
|
|
| 737 | 737 | } else {
|
| 738 | - $langs_available[$dir] = $this->trans('Language_' . $dir);
|
|
| 738 | + $langs_available[$dir] = $this->trans('Language_'.$dir);
|
|
| 739 | 739 | } |
| 740 | 740 | } |
| 741 | 741 | } |
@@ -755,13 +755,13 @@ discard block |
||
| 755 | 755 | // phpcs:enable |
| 756 | 756 | // Test si fichier dans repertoire de la langue |
| 757 | 757 | foreach ($this->dir as $searchdir) {
|
| 758 | - if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) |
|
| 758 | + if (is_readable(dol_osencode($searchdir."/langs/".$this->defaultlang."/".$filename))) |
|
| 759 | 759 | return true; |
| 760 | 760 | |
| 761 | 761 | if ($searchalt) {
|
| 762 | 762 | // Test si fichier dans repertoire de la langue alternative |
| 763 | 763 | if ($this->defaultlang != "en_US") |
| 764 | - $filenamealt = $searchdir . "/langs/en_US/" . $filename; |
|
| 764 | + $filenamealt = $searchdir."/langs/en_US/".$filename; |
|
| 765 | 765 | //else $filenamealt = $searchdir."/langs/fr_FR/".$filename; |
| 766 | 766 | if (is_readable(dol_osencode($filenamealt))) |
| 767 | 767 | return true; |
@@ -798,8 +798,8 @@ discard block |
||
| 798 | 798 | continue; // We must not use dol_is_dir here, function may not be loaded |
| 799 | 799 | |
| 800 | 800 | $fonc = 'numberwords'; |
| 801 | - if (file_exists($newdir . '/functions_' . $fonc . '.lib.php')) {
|
|
| 802 | - include_once $newdir . '/functions_' . $fonc . '.lib.php'; |
|
| 801 | + if (file_exists($newdir.'/functions_'.$fonc.'.lib.php')) {
|
|
| 802 | + include_once $newdir.'/functions_'.$fonc.'.lib.php'; |
|
| 803 | 803 | $newnumber = numberwords_getLabelFromNumber($this, $number, $isamount); |
| 804 | 804 | break; |
| 805 | 805 | } |
@@ -833,20 +833,20 @@ discard block |
||
| 833 | 833 | // Check if a translation is available (this can call getTradFromKey) |
| 834 | 834 | $tmp = $this->transnoentitiesnoconv($key); |
| 835 | 835 | if ($tmp != $key && $tmp != 'ErrorBadValueForParamNotAString') {
|
| 836 | - return $tmp; // Found in language array |
|
| 836 | + return $tmp; // Found in language array |
|
| 837 | 837 | } |
| 838 | 838 | |
| 839 | 839 | // Check in cache |
| 840 | 840 | if (isset($this->cache_labels[$tablename][$key])) { // Can be defined to 0 or ''
|
| 841 | - return $this->cache_labels[$tablename][$key]; // Found in cache |
|
| 841 | + return $this->cache_labels[$tablename][$key]; // Found in cache |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | - $sql = "SELECT " . $fieldlabel . " as label"; |
|
| 845 | - $sql .= " FROM " . MAIN_DB_PREFIX . $tablename; |
|
| 846 | - $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($keyforselect ? $keyforselect : $key) . "'"; |
|
| 844 | + $sql = "SELECT ".$fieldlabel." as label"; |
|
| 845 | + $sql .= " FROM ".MAIN_DB_PREFIX.$tablename; |
|
| 846 | + $sql .= " WHERE ".$fieldkey." = '".$db->escape($keyforselect ? $keyforselect : $key)."'"; |
|
| 847 | 847 | if ($filteronentity) |
| 848 | - $sql .= " AND entity IN (" . getEntity($tablename) . ')';
|
|
| 849 | - DolUtils::dol_syslog(get_class($this) . '::getLabelFromKey', LOG_DEBUG); |
|
| 848 | + $sql .= " AND entity IN (".getEntity($tablename).')';
|
|
| 849 | + DolUtils::dol_syslog(get_class($this).'::getLabelFromKey', LOG_DEBUG); |
|
| 850 | 850 | $resql = $db->query($sql); |
| 851 | 851 | if ($resql) {
|
| 852 | 852 | $obj = $db->fetch_object($resql); |
@@ -878,9 +878,9 @@ discard block |
||
| 878 | 878 | $symbol = $this->getCurrencySymbol($currency_code); |
| 879 | 879 | |
| 880 | 880 | if (in_array($currency_code, array('USD')))
|
| 881 | - return $symbol . $amount; |
|
| 881 | + return $symbol.$amount; |
|
| 882 | 882 | else |
| 883 | - return $amount . $symbol; |
|
| 883 | + return $amount.$symbol; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | /** |
@@ -919,18 +919,18 @@ discard block |
||
| 919 | 919 | global $db; |
| 920 | 920 | |
| 921 | 921 | if ($this->cache_currencies_all_loaded) |
| 922 | - return 0; // Cache already loaded for all |
|
| 922 | + return 0; // Cache already loaded for all |
|
| 923 | 923 | if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) |
| 924 | - return 0; // Cache already loaded for the currency |
|
| 924 | + return 0; // Cache already loaded for the currency |
|
| 925 | 925 | |
| 926 | 926 | $sql = "SELECT code_iso, label, unicode"; |
| 927 | - $sql .= " FROM " . MAIN_DB_PREFIX . "c_currencies"; |
|
| 927 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_currencies"; |
|
| 928 | 928 | $sql .= " WHERE active = 1"; |
| 929 | 929 | if (!empty($currency_code)) |
| 930 | - $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'"; |
|
| 930 | + $sql .= " AND code_iso = '".$db->escape($currency_code)."'"; |
|
| 931 | 931 | //$sql.= " ORDER BY code_iso ASC"; // Not required, a sort is done later |
| 932 | 932 | |
| 933 | - DolUtils::dol_syslog(get_class($this) . '::loadCacheCurrencies', LOG_DEBUG); |
|
| 933 | + DolUtils::dol_syslog(get_class($this).'::loadCacheCurrencies', LOG_DEBUG); |
|
| 934 | 934 | $resql = $db->query($sql); |
| 935 | 935 | if ($resql) {
|
| 936 | 936 | $this->load("dict");
|
@@ -945,7 +945,7 @@ discard block |
||
| 945 | 945 | $obj = $db->fetch_object($resql); |
| 946 | 946 | |
| 947 | 947 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 948 | - $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 : ''));
|
|
| 948 | + $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 : ''));
|
|
| 949 | 949 | $this->cache_currencies[$obj->code_iso]['unicode'] = (array) json_decode($obj->unicode, true); |
| 950 | 950 | $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label']; |
| 951 | 951 | $i++; |
@@ -977,8 +977,8 @@ discard block |
||
| 977 | 977 | $substitutionarray = array(); |
| 978 | 978 | |
| 979 | 979 | foreach ($this->tab_translate as $code => $label) {
|
| 980 | - $substitutionarray['lang_' . $code] = $label; |
|
| 981 | - $substitutionarray['__(' . $code . ')__'] = $label;
|
|
| 980 | + $substitutionarray['lang_'.$code] = $label; |
|
| 981 | + $substitutionarray['__('.$code.')__'] = $label;
|
|
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | return $substitutionarray; |
@@ -36,12 +36,15 @@ discard block |
||
| 36 | 36 | function __construct() |
| 37 | 37 | {
|
| 38 | 38 | $dir = DOL_BASE_PATH; |
| 39 | - if (!empty($conf->file->character_set_client)) |
|
| 40 | - $this->charset_output = $conf->file->character_set_client; // If charset output is forced |
|
| 41 | - if ($dir) |
|
| 42 | - $this->dir = array($dir); |
|
| 43 | - else |
|
| 44 | - $this->dir = $conf->file->dol_document_root; |
|
| 39 | + if (!empty($conf->file->character_set_client)) { |
|
| 40 | + $this->charset_output = $conf->file->character_set_client; |
|
| 41 | + } |
|
| 42 | + // If charset output is forced |
|
| 43 | + if ($dir) { |
|
| 44 | + $this->dir = array($dir); |
|
| 45 | + } else { |
|
| 46 | + $this->dir = $conf->file->dol_document_root; |
|
| 47 | + } |
|
| 45 | 48 | } |
| 46 | 49 | |
| 47 | 50 | /** |
@@ -77,8 +80,9 @@ discard block |
||
| 77 | 80 | $langpref = str_replace("-", "_", $langpref);
|
| 78 | 81 | $langlist = preg_split("/[;,]/", $langpref);
|
| 79 | 82 | $codetouse = $langlist[0]; |
| 80 | - } else |
|
| 81 | - $codetouse = $srclang; |
|
| 83 | + } else { |
|
| 84 | + $codetouse = $srclang; |
|
| 85 | + } |
|
| 82 | 86 | |
| 83 | 87 | // We redefine $srclang |
| 84 | 88 | $langpart = explode("_", $codetouse);
|
@@ -87,25 +91,27 @@ discard block |
||
| 87 | 91 | // Array force long code from first part, even if long code is defined |
| 88 | 92 | $longforshort = array('ar' => 'ar_SA');
|
| 89 | 93 | $longforshortexcep = array('ar_EG');
|
| 90 | - if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) |
|
| 91 | - $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 92 | - else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser
|
|
| 94 | + if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) { |
|
| 95 | + $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 96 | + } else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser
|
|
| 93 | 97 | $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[1]); |
| 94 | 98 | $longforlong = array('no_nb' => 'nb_NO');
|
| 95 | - if (isset($longforlong[strtolower($srclang)])) |
|
| 96 | - $srclang = $longforlong[strtolower($srclang)]; |
|
| 97 | - } else |
|
| 98 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 99 | - } |
|
| 100 | - else { // If it's for a codetouse that is a short code xx
|
|
| 99 | + if (isset($longforlong[strtolower($srclang)])) { |
|
| 100 | + $srclang = $longforlong[strtolower($srclang)]; |
|
| 101 | + } |
|
| 102 | + } else { |
|
| 103 | + $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 104 | + } |
|
| 105 | + } else { // If it's for a codetouse that is a short code xx
|
|
| 101 | 106 | // Array to convert short lang code into long code. |
| 102 | 107 | $longforshort = array('ar' => 'ar_SA', 'el' => 'el_GR', 'ca' => 'ca_ES', 'en' => 'en_US', 'nb' => 'nb_NO', 'no' => 'nb_NO');
|
| 103 | - if (isset($longforshort[strtolower($langpart[0])])) |
|
| 104 | - $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 105 | - else if (!empty($langpart[0])) |
|
| 106 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 107 | - else |
|
| 108 | - $srclang = 'en_US'; |
|
| 108 | + if (isset($longforshort[strtolower($langpart[0])])) { |
|
| 109 | + $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 110 | + } else if (!empty($langpart[0])) { |
|
| 111 | + $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 112 | + } else { |
|
| 113 | + $srclang = 'en_US'; |
|
| 114 | + } |
|
| 109 | 115 | } |
| 110 | 116 | |
| 111 | 117 | $this->defaultlang = $srclang; |
@@ -121,10 +127,11 @@ discard block |
||
| 121 | 127 | */ |
| 122 | 128 | function getDefaultLang($mode = 0) |
| 123 | 129 | {
|
| 124 | - if (empty($mode)) |
|
| 125 | - return $this->defaultlang; |
|
| 126 | - else |
|
| 127 | - return substr($this->defaultlang, 0, 2); |
|
| 130 | + if (empty($mode)) { |
|
| 131 | + return $this->defaultlang; |
|
| 132 | + } else { |
|
| 133 | + return substr($this->defaultlang, 0, 2); |
|
| 134 | + } |
|
| 128 | 135 | } |
| 129 | 136 | |
| 130 | 137 | /** |
@@ -170,8 +177,10 @@ discard block |
||
| 170 | 177 | dol_print_error('', get_class($this) . "::Load ErrorWrongParameters");
|
| 171 | 178 | return -1; |
| 172 | 179 | } |
| 173 | - if ($this->defaultlang == 'none_NONE') |
|
| 174 | - return 0; // Special language code to not translate keys |
|
| 180 | + if ($this->defaultlang == 'none_NONE') { |
|
| 181 | + return 0; |
|
| 182 | + } |
|
| 183 | + // Special language code to not translate keys |
|
| 175 | 184 | |
| 176 | 185 | |
| 177 | 186 | |
@@ -179,8 +188,10 @@ discard block |
||
| 179 | 188 | |
| 180 | 189 | |
| 181 | 190 | // Load $this->tab_translate[] from database |
| 182 | - if (empty($loadfromfileonly) && count($this->tab_translate) == 0) |
|
| 183 | - $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. |
|
| 191 | + if (empty($loadfromfileonly) && count($this->tab_translate) == 0) { |
|
| 192 | + $this->loadFromDatabase($db); |
|
| 193 | + } |
|
| 194 | + // No translation was never loaded yet, so we load database. |
|
| 184 | 195 | |
| 185 | 196 | |
| 186 | 197 | $newdomain = $domain; |
@@ -203,10 +214,12 @@ discard block |
||
| 203 | 214 | |
| 204 | 215 | // Redefine alt |
| 205 | 216 | $langarray = explode('_', $langofdir);
|
| 206 | - if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr'))))
|
|
| 207 | - $alt = 1; |
|
| 208 | - if ($alt < 2 && strtolower($langofdir) == 'en_us') |
|
| 209 | - $alt = 2; |
|
| 217 | + if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr')))) { |
|
| 218 | + $alt = 1; |
|
| 219 | + } |
|
| 220 | + if ($alt < 2 && strtolower($langofdir) == 'en_us') { |
|
| 221 | + $alt = 2; |
|
| 222 | + } |
|
| 210 | 223 | |
| 211 | 224 | if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir
|
| 212 | 225 | DolUtils::dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
|
@@ -248,16 +261,19 @@ discard block |
||
| 248 | 261 | $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. |
| 249 | 262 | //print $newdomain."\n"; |
| 250 | 263 | //var_dump($this->tab_translate); |
| 251 | - if ($alt == 2) |
|
| 252 | - $fileread = 1; |
|
| 264 | + if ($alt == 2) { |
|
| 265 | + $fileread = 1; |
|
| 266 | + } |
|
| 253 | 267 | $found = true; // Found in dolibarr PHP cache |
| 254 | 268 | } |
| 255 | 269 | } |
| 256 | 270 | |
| 257 | 271 | if (!$found) {
|
| 258 | 272 | if ($fp = @fopen($file_lang, "rt")) {
|
| 259 | - if ($usecachekey) |
|
| 260 | - $tabtranslatedomain = array(); // To save lang content in cache |
|
| 273 | + if ($usecachekey) { |
|
| 274 | + $tabtranslatedomain = array(); |
|
| 275 | + } |
|
| 276 | + // To save lang content in cache |
|
| 261 | 277 | |
| 262 | 278 | /** |
| 263 | 279 | * Read each lines until a '=' (with any combination of spaces around it) |
@@ -305,8 +321,10 @@ discard block |
||
| 305 | 321 | } |
| 306 | 322 | } |
| 307 | 323 | |
| 308 | - if (empty($conf->global->MAIN_FORCELANGDIR)) |
|
| 309 | - break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 324 | + if (empty($conf->global->MAIN_FORCELANGDIR)) { |
|
| 325 | + break; |
|
| 326 | + } |
|
| 327 | + // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 310 | 328 | } |
| 311 | 329 | } |
| 312 | 330 | } |
@@ -317,10 +335,14 @@ discard block |
||
| 317 | 335 | // This function MUST NOT contains call to syslog |
| 318 | 336 | //DolUtils::dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
|
| 319 | 337 | $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]); |
| 320 | - if ($langofdir == 'el_EL') |
|
| 321 | - $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 322 | - if ($langofdir == 'ar_AR') |
|
| 323 | - $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 338 | + if ($langofdir == 'el_EL') { |
|
| 339 | + $langofdir = 'el_GR'; |
|
| 340 | + } |
|
| 341 | + // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 342 | + if ($langofdir == 'ar_AR') { |
|
| 343 | + $langofdir = 'ar_SA'; |
|
| 344 | + } |
|
| 345 | + // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 324 | 346 | $this->load($domain, $alt + 1, $stopafterdirection, $langofdir); |
| 325 | 347 | } |
| 326 | 348 | |
@@ -334,11 +356,15 @@ discard block |
||
| 334 | 356 | |
| 335 | 357 | // We are in the pass of the reference file. No more files to scan to complete. |
| 336 | 358 | if ($alt == 2) {
|
| 337 | - if ($fileread) |
|
| 338 | - $this->_tab_loaded[$newdomain] = 1; // Set domain file as found so loaded |
|
| 339 | - |
|
| 340 | - if (empty($this->_tab_loaded[$newdomain])) |
|
| 341 | - $this->_tab_loaded[$newdomain] = 2; // Set this file as not found |
|
| 359 | + if ($fileread) { |
|
| 360 | + $this->_tab_loaded[$newdomain] = 1; |
|
| 361 | + } |
|
| 362 | + // Set domain file as found so loaded |
|
| 363 | + |
|
| 364 | + if (empty($this->_tab_loaded[$newdomain])) { |
|
| 365 | + $this->_tab_loaded[$newdomain] = 2; |
|
| 366 | + } |
|
| 367 | + // Set this file as not found |
|
| 342 | 368 | } |
| 343 | 369 | |
| 344 | 370 | // This part is deprecated and replaced with table llx_overwrite_trans |
@@ -350,15 +376,17 @@ discard block |
||
| 350 | 376 | $tmparray = explode(',', $conf->global->$overwritekey);
|
| 351 | 377 | foreach ($tmparray as $tmp) {
|
| 352 | 378 | $tmparray2 = explode(':', $tmp);
|
| 353 | - if (!empty($tmparray2[1])) |
|
| 354 | - $this->tab_translate[$tmparray2[0]] = $tmparray2[1]; |
|
| 379 | + if (!empty($tmparray2[1])) { |
|
| 380 | + $this->tab_translate[$tmparray2[0]] = $tmparray2[1]; |
|
| 381 | + } |
|
| 355 | 382 | } |
| 356 | 383 | } |
| 357 | 384 | } |
| 358 | 385 | |
| 359 | 386 | // Check to be sure that SeparatorDecimal differs from SeparatorThousand |
| 360 | - if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) |
|
| 361 | - $this->tab_translate["SeparatorThousand"] = ''; |
|
| 387 | + if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) { |
|
| 388 | + $this->tab_translate["SeparatorThousand"] = ''; |
|
| 389 | + } |
|
| 362 | 390 | |
| 363 | 391 | return 1; |
| 364 | 392 | } |
@@ -382,8 +410,10 @@ discard block |
||
| 382 | 410 | $domain = 'database'; |
| 383 | 411 | |
| 384 | 412 | // Check parameters |
| 385 | - if (empty($db)) |
|
| 386 | - return 0; // Database handler can't be used |
|
| 413 | + if (empty($db)) { |
|
| 414 | + return 0; |
|
| 415 | + } |
|
| 416 | + // Database handler can't be used |
|
| 387 | 417 | |
| 388 | 418 | |
| 389 | 419 | |
@@ -447,8 +477,10 @@ discard block |
||
| 447 | 477 | if ($resql) {
|
| 448 | 478 | $num = $db->num_rows($resql); |
| 449 | 479 | if ($num) {
|
| 450 | - if ($usecachekey) |
|
| 451 | - $tabtranslatedomain = array(); // To save lang content in cache |
|
| 480 | + if ($usecachekey) { |
|
| 481 | + $tabtranslatedomain = array(); |
|
| 482 | + } |
|
| 483 | + // To save lang content in cache |
|
| 452 | 484 | |
| 453 | 485 | $i = 0; |
| 454 | 486 | while ($i < $num) { // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents
|
@@ -462,8 +494,10 @@ discard block |
||
| 462 | 494 | $value = trim(preg_replace('/\\n/', "\n", $value));
|
| 463 | 495 | |
| 464 | 496 | $this->tab_translate[$key] = $value; |
| 465 | - if ($usecachekey) |
|
| 466 | - $tabtranslatedomain[$key] = $value; // To save lang content in cache |
|
| 497 | + if ($usecachekey) { |
|
| 498 | + $tabtranslatedomain[$key] = $value; |
|
| 499 | + } |
|
| 500 | + // To save lang content in cache |
|
| 467 | 501 | } |
| 468 | 502 | |
| 469 | 503 | $i++; |
@@ -486,11 +520,15 @@ discard block |
||
| 486 | 520 | } |
| 487 | 521 | } |
| 488 | 522 | |
| 489 | - if ($fileread) |
|
| 490 | - $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded |
|
| 523 | + if ($fileread) { |
|
| 524 | + $this->_tab_loaded[$newdomain] = 1; |
|
| 525 | + } |
|
| 526 | + // Set domain file as loaded |
|
| 491 | 527 | |
| 492 | - if (empty($this->_tab_loaded[$newdomain])) |
|
| 493 | - $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
| 528 | + if (empty($this->_tab_loaded[$newdomain])) { |
|
| 529 | + $this->_tab_loaded[$newdomain] = 2; |
|
| 530 | + } |
|
| 531 | + // Marque ce cas comme non trouve (no lines found for language) |
|
| 494 | 532 | |
| 495 | 533 | return 1; |
| 496 | 534 | } |
@@ -510,8 +548,10 @@ discard block |
||
| 510 | 548 | {
|
| 511 | 549 | global $conf, $db; |
| 512 | 550 | |
| 513 | - if (!is_string($key)) |
|
| 514 | - return 'ErrorBadValueForParamNotAString'; // Avoid multiple errors with code not using function correctly. |
|
| 551 | + if (!is_string($key)) { |
|
| 552 | + return 'ErrorBadValueForParamNotAString'; |
|
| 553 | + } |
|
| 554 | + // Avoid multiple errors with code not using function correctly. |
|
| 515 | 555 | |
| 516 | 556 | $newstr = $key; |
| 517 | 557 | if (preg_match('/^Civility([0-9A-Z]+)$/i', $key, $reg)) {
|
@@ -574,8 +614,9 @@ discard block |
||
| 574 | 614 | $str = sprintf($str, $param1, $param2, $param3, $param4); // Replace %s and %d except for FormatXXX strings. |
| 575 | 615 | } |
| 576 | 616 | |
| 577 | - if ($maxsize) |
|
| 578 | - $str = dol_trunc($str, $maxsize); |
|
| 617 | + if ($maxsize) { |
|
| 618 | + $str = dol_trunc($str, $maxsize); |
|
| 619 | + } |
|
| 579 | 620 | |
| 580 | 621 | // We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities |
| 581 | 622 | $str = str_replace(array('<', '>', '"',), array('__lt__', '__gt__', '__quot__'), $str);
|
@@ -586,8 +627,7 @@ discard block |
||
| 586 | 627 | $str = str_replace(array('__lt__', '__gt__', '__quot__'), array('<', '>', '"',), $str);
|
| 587 | 628 | |
| 588 | 629 | return $str; |
| 589 | - } |
|
| 590 | - else { // Translation is not available
|
|
| 630 | + } else { // Translation is not available
|
|
| 591 | 631 | //if ($key[0] == '$') { return dol_eval($key,1); }
|
| 592 | 632 | return $this->getTradFromKey($key); |
| 593 | 633 | } |
@@ -667,10 +707,11 @@ discard block |
||
| 667 | 707 | */ |
| 668 | 708 | function transcountry($str, $countrycode) |
| 669 | 709 | {
|
| 670 | - if ($this->tab_translate["$str$countrycode"]) |
|
| 671 | - return $this->trans("$str$countrycode");
|
|
| 672 | - else |
|
| 673 | - return $this->trans($str); |
|
| 710 | + if ($this->tab_translate["$str$countrycode"]) { |
|
| 711 | + return $this->trans("$str$countrycode"); |
|
| 712 | + } else { |
|
| 713 | + return $this->trans($str); |
|
| 714 | + } |
|
| 674 | 715 | } |
| 675 | 716 | |
| 676 | 717 | /** |
@@ -682,10 +723,11 @@ discard block |
||
| 682 | 723 | */ |
| 683 | 724 | function transcountrynoentities($str, $countrycode) |
| 684 | 725 | {
|
| 685 | - if ($this->tab_translate["$str$countrycode"]) |
|
| 686 | - return $this->transnoentities("$str$countrycode");
|
|
| 687 | - else |
|
| 688 | - return $this->transnoentities($str); |
|
| 726 | + if ($this->tab_translate["$str$countrycode"]) { |
|
| 727 | + return $this->transnoentities("$str$countrycode"); |
|
| 728 | + } else { |
|
| 729 | + return $this->transnoentities($str); |
|
| 730 | + } |
|
| 689 | 731 | } |
| 690 | 732 | |
| 691 | 733 | /** |
@@ -697,10 +739,12 @@ discard block |
||
| 697 | 739 | */ |
| 698 | 740 | function convToOutputCharset($str, $pagecodefrom = 'UTF-8') |
| 699 | 741 | {
|
| 700 | - if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') |
|
| 701 | - $str = utf8_encode($str); |
|
| 702 | - if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') |
|
| 703 | - $str = utf8_decode(str_replace('€', chr(128), $str));
|
|
| 742 | + if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') { |
|
| 743 | + $str = utf8_encode($str); |
|
| 744 | + } |
|
| 745 | + if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') { |
|
| 746 | + $str = utf8_decode(str_replace('€', chr(128), $str)); |
|
| 747 | + } |
|
| 704 | 748 | return $str; |
| 705 | 749 | } |
| 706 | 750 | |
@@ -755,16 +799,19 @@ discard block |
||
| 755 | 799 | // phpcs:enable |
| 756 | 800 | // Test si fichier dans repertoire de la langue |
| 757 | 801 | foreach ($this->dir as $searchdir) {
|
| 758 | - if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) |
|
| 759 | - return true; |
|
| 802 | + if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) { |
|
| 803 | + return true; |
|
| 804 | + } |
|
| 760 | 805 | |
| 761 | 806 | if ($searchalt) {
|
| 762 | 807 | // Test si fichier dans repertoire de la langue alternative |
| 763 | - if ($this->defaultlang != "en_US") |
|
| 764 | - $filenamealt = $searchdir . "/langs/en_US/" . $filename; |
|
| 808 | + if ($this->defaultlang != "en_US") { |
|
| 809 | + $filenamealt = $searchdir . "/langs/en_US/" . $filename; |
|
| 810 | + } |
|
| 765 | 811 | //else $filenamealt = $searchdir."/langs/fr_FR/".$filename; |
| 766 | - if (is_readable(dol_osencode($filenamealt))) |
|
| 767 | - return true; |
|
| 812 | + if (is_readable(dol_osencode($filenamealt))) { |
|
| 813 | + return true; |
|
| 814 | + } |
|
| 768 | 815 | } |
| 769 | 816 | } |
| 770 | 817 | |
@@ -794,8 +841,10 @@ discard block |
||
| 794 | 841 | $newdir = dol_osencode($dir); |
| 795 | 842 | |
| 796 | 843 | // Check if directory exists |
| 797 | - if (!is_dir($newdir)) |
|
| 798 | - continue; // We must not use dol_is_dir here, function may not be loaded |
|
| 844 | + if (!is_dir($newdir)) { |
|
| 845 | + continue; |
|
| 846 | + } |
|
| 847 | + // We must not use dol_is_dir here, function may not be loaded |
|
| 799 | 848 | |
| 800 | 849 | $fonc = 'numberwords'; |
| 801 | 850 | if (file_exists($newdir . '/functions_' . $fonc . '.lib.php')) {
|
@@ -826,8 +875,9 @@ discard block |
||
| 826 | 875 | function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '', $filteronentity = 0) |
| 827 | 876 | {
|
| 828 | 877 | // If key empty |
| 829 | - if ($key == '') |
|
| 830 | - return ''; |
|
| 878 | + if ($key == '') { |
|
| 879 | + return ''; |
|
| 880 | + } |
|
| 831 | 881 | |
| 832 | 882 | //print 'param: '.$key.'-'.$keydatabase.'-'.$this->trans($key); exit; |
| 833 | 883 | // Check if a translation is available (this can call getTradFromKey) |
@@ -844,21 +894,22 @@ discard block |
||
| 844 | 894 | $sql = "SELECT " . $fieldlabel . " as label"; |
| 845 | 895 | $sql .= " FROM " . MAIN_DB_PREFIX . $tablename; |
| 846 | 896 | $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($keyforselect ? $keyforselect : $key) . "'"; |
| 847 | - if ($filteronentity) |
|
| 848 | - $sql .= " AND entity IN (" . getEntity($tablename) . ')';
|
|
| 897 | + if ($filteronentity) { |
|
| 898 | + $sql .= " AND entity IN (" . getEntity($tablename) . ')'; |
|
| 899 | + } |
|
| 849 | 900 | DolUtils::dol_syslog(get_class($this) . '::getLabelFromKey', LOG_DEBUG); |
| 850 | 901 | $resql = $db->query($sql); |
| 851 | 902 | if ($resql) {
|
| 852 | 903 | $obj = $db->fetch_object($resql); |
| 853 | - if ($obj) |
|
| 854 | - $this->cache_labels[$tablename][$key] = $obj->label; |
|
| 855 | - else |
|
| 856 | - $this->cache_labels[$tablename][$key] = $key; |
|
| 904 | + if ($obj) { |
|
| 905 | + $this->cache_labels[$tablename][$key] = $obj->label; |
|
| 906 | + } else { |
|
| 907 | + $this->cache_labels[$tablename][$key] = $key; |
|
| 908 | + } |
|
| 857 | 909 | |
| 858 | 910 | $db->free($resql); |
| 859 | 911 | return $this->cache_labels[$tablename][$key]; |
| 860 | - } |
|
| 861 | - else {
|
|
| 912 | + } else {
|
|
| 862 | 913 | $this->error = $db->lasterror(); |
| 863 | 914 | return -1; |
| 864 | 915 | } |
@@ -877,10 +928,11 @@ discard block |
||
| 877 | 928 | {
|
| 878 | 929 | $symbol = $this->getCurrencySymbol($currency_code); |
| 879 | 930 | |
| 880 | - if (in_array($currency_code, array('USD')))
|
|
| 881 | - return $symbol . $amount; |
|
| 882 | - else |
|
| 883 | - return $amount . $symbol; |
|
| 931 | + if (in_array($currency_code, array('USD'))) { |
|
| 932 | + return $symbol . $amount; |
|
| 933 | + } else { |
|
| 934 | + return $amount . $symbol; |
|
| 935 | + } |
|
| 884 | 936 | } |
| 885 | 937 | |
| 886 | 938 | /** |
@@ -918,16 +970,21 @@ discard block |
||
| 918 | 970 | {
|
| 919 | 971 | global $db; |
| 920 | 972 | |
| 921 | - if ($this->cache_currencies_all_loaded) |
|
| 922 | - return 0; // Cache already loaded for all |
|
| 923 | - if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) |
|
| 924 | - return 0; // Cache already loaded for the currency |
|
| 973 | + if ($this->cache_currencies_all_loaded) { |
|
| 974 | + return 0; |
|
| 975 | + } |
|
| 976 | + // Cache already loaded for all |
|
| 977 | + if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) { |
|
| 978 | + return 0; |
|
| 979 | + } |
|
| 980 | + // Cache already loaded for the currency |
|
| 925 | 981 | |
| 926 | 982 | $sql = "SELECT code_iso, label, unicode"; |
| 927 | 983 | $sql .= " FROM " . MAIN_DB_PREFIX . "c_currencies"; |
| 928 | 984 | $sql .= " WHERE active = 1"; |
| 929 | - if (!empty($currency_code)) |
|
| 930 | - $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'"; |
|
| 985 | + if (!empty($currency_code)) { |
|
| 986 | + $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'"; |
|
| 987 | + } |
|
| 931 | 988 | //$sql.= " ORDER BY code_iso ASC"; // Not required, a sort is done later |
| 932 | 989 | |
| 933 | 990 | DolUtils::dol_syslog(get_class($this) . '::loadCacheCurrencies', LOG_DEBUG); |
@@ -935,9 +992,11 @@ discard block |
||
| 935 | 992 | if ($resql) {
|
| 936 | 993 | $this->load("dict");
|
| 937 | 994 | $label = array(); |
| 938 | - if (!empty($currency_code)) |
|
| 939 | - foreach ($this->cache_currencies as $key => $val) |
|
| 940 | - $label[$key] = $val['label']; // Label in already loaded cache |
|
| 995 | + if (!empty($currency_code)) { |
|
| 996 | + foreach ($this->cache_currencies as $key => $val) |
|
| 997 | + $label[$key] = $val['label']; |
|
| 998 | + } |
|
| 999 | + // Label in already loaded cache |
|
| 941 | 1000 | |
| 942 | 1001 | $num = $db->num_rows($resql); |
| 943 | 1002 | $i = 0; |
@@ -950,15 +1009,15 @@ discard block |
||
| 950 | 1009 | $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label']; |
| 951 | 1010 | $i++; |
| 952 | 1011 | } |
| 953 | - if (empty($currency_code)) |
|
| 954 | - $this->cache_currencies_all_loaded = true; |
|
| 1012 | + if (empty($currency_code)) { |
|
| 1013 | + $this->cache_currencies_all_loaded = true; |
|
| 1014 | + } |
|
| 955 | 1015 | //print count($label).' '.count($this->cache_currencies); |
| 956 | 1016 | // Resort cache |
| 957 | 1017 | array_multisort($label, SORT_ASC, $this->cache_currencies); |
| 958 | 1018 | //var_dump($this->cache_currencies); $this->cache_currencies is now sorted onto label |
| 959 | 1019 | return $num; |
| 960 | - } |
|
| 961 | - else {
|
|
| 1020 | + } else {
|
|
| 962 | 1021 | dol_print_error($db); |
| 963 | 1022 | return -1; |
| 964 | 1023 | } |