@@ -172,15 +172,19 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique = 0, $required = 0, $default_value = '', $param = '', $alwayseditable = 0, $perms = '', $list = '-1', $help = '', $computed = '', $entity = '', $langfile = '', $enabled = '1') |
| 174 | 174 | {
|
| 175 | - if (empty($attrname)) |
|
| 176 | - return -1; |
|
| 177 | - if (empty($label)) |
|
| 178 | - return -1; |
|
| 179 | - |
|
| 180 | - if ($elementtype == 'thirdparty') |
|
| 181 | - $elementtype = 'societe'; |
|
| 182 | - if ($elementtype == 'contact') |
|
| 183 | - $elementtype = 'socpeople'; |
|
| 175 | + if (empty($attrname)) { |
|
| 176 | + return -1; |
|
| 177 | + } |
|
| 178 | + if (empty($label)) { |
|
| 179 | + return -1; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if ($elementtype == 'thirdparty') { |
|
| 183 | + $elementtype = 'societe'; |
|
| 184 | + } |
|
| 185 | + if ($elementtype == 'contact') { |
|
| 186 | + $elementtype = 'socpeople'; |
|
| 187 | + } |
|
| 184 | 188 | |
| 185 | 189 | // Create field into database except for separator type which is not stored in database |
| 186 | 190 | if ($type != 'separate') {
|
@@ -195,10 +199,10 @@ discard block |
||
| 195 | 199 | $this->error = ''; |
| 196 | 200 | $this->errno = 0; |
| 197 | 201 | return 1; |
| 198 | - } else |
|
| 199 | - return -2; |
|
| 200 | - } |
|
| 201 | - else {
|
|
| 202 | + } else { |
|
| 203 | + return -2; |
|
| 204 | + } |
|
| 205 | + } else {
|
|
| 202 | 206 | return -1; |
| 203 | 207 | } |
| 204 | 208 | } |
@@ -222,14 +226,17 @@ discard block |
||
| 222 | 226 | */ |
| 223 | 227 | private function create($attrname, $type = 'varchar', $length = 255, $elementtype = 'member', $unique = 0, $required = 0, $default_value = '', $param = '', $perms = '', $list = '0', $computed = '') |
| 224 | 228 | {
|
| 225 | - if ($elementtype == 'thirdparty') |
|
| 226 | - $elementtype = 'societe'; |
|
| 227 | - if ($elementtype == 'contact') |
|
| 228 | - $elementtype = 'socpeople'; |
|
| 229 | + if ($elementtype == 'thirdparty') { |
|
| 230 | + $elementtype = 'societe'; |
|
| 231 | + } |
|
| 232 | + if ($elementtype == 'contact') { |
|
| 233 | + $elementtype = 'socpeople'; |
|
| 234 | + } |
|
| 229 | 235 | |
| 230 | 236 | $table = $elementtype . '_extrafields'; |
| 231 | - if ($elementtype == 'categorie') |
|
| 232 | - $table = 'categories_extrafields'; |
|
| 237 | + if ($elementtype == 'categorie') { |
|
| 238 | + $table = 'categories_extrafields'; |
|
| 239 | + } |
|
| 233 | 240 | |
| 234 | 241 | if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/", $attrname) && !is_numeric($attrname)) {
|
| 235 | 242 | if ($type == 'boolean') {
|
@@ -262,8 +269,9 @@ discard block |
||
| 262 | 269 | } else {
|
| 263 | 270 | $typedb = $type; |
| 264 | 271 | $lengthdb = $length; |
| 265 | - if ($type == 'varchar' && empty($lengthdb)) |
|
| 266 | - $lengthdb = '255'; |
|
| 272 | + if ($type == 'varchar' && empty($lengthdb)) { |
|
| 273 | + $lengthdb = '255'; |
|
| 274 | + } |
|
| 267 | 275 | } |
| 268 | 276 | $field_desc = array( |
| 269 | 277 | 'type' => $typedb, |
@@ -318,22 +326,29 @@ discard block |
||
| 318 | 326 | // phpcs:enable |
| 319 | 327 | // global $conf, $user; |
| 320 | 328 | |
| 321 | - if ($elementtype == 'thirdparty') |
|
| 322 | - $elementtype = 'societe'; |
|
| 323 | - if ($elementtype == 'contact') |
|
| 324 | - $elementtype = 'socpeople'; |
|
| 329 | + if ($elementtype == 'thirdparty') { |
|
| 330 | + $elementtype = 'societe'; |
|
| 331 | + } |
|
| 332 | + if ($elementtype == 'contact') { |
|
| 333 | + $elementtype = 'socpeople'; |
|
| 334 | + } |
|
| 325 | 335 | |
| 326 | 336 | // Clean parameters |
| 327 | - if (empty($pos)) |
|
| 328 | - $pos = 0; |
|
| 329 | - if (empty($list)) |
|
| 330 | - $list = '0'; |
|
| 331 | - if (empty($required)) |
|
| 332 | - $required = 0; |
|
| 333 | - if (empty($unique)) |
|
| 334 | - $unique = 0; |
|
| 335 | - if (empty($alwayseditable)) |
|
| 336 | - $alwayseditable = 0; |
|
| 337 | + if (empty($pos)) { |
|
| 338 | + $pos = 0; |
|
| 339 | + } |
|
| 340 | + if (empty($list)) { |
|
| 341 | + $list = '0'; |
|
| 342 | + } |
|
| 343 | + if (empty($required)) { |
|
| 344 | + $required = 0; |
|
| 345 | + } |
|
| 346 | + if (empty($unique)) { |
|
| 347 | + $unique = 0; |
|
| 348 | + } |
|
| 349 | + if (empty($alwayseditable)) { |
|
| 350 | + $alwayseditable = 0; |
|
| 351 | + } |
|
| 337 | 352 | |
| 338 | 353 | if (!empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname) && !is_numeric($attrname)) {
|
| 339 | 354 | if (is_array($param) && count($param) > 0) {
|
@@ -410,14 +425,17 @@ discard block |
||
| 410 | 425 | */ |
| 411 | 426 | function delete($attrname, $elementtype = 'member') |
| 412 | 427 | {
|
| 413 | - if ($elementtype == 'thirdparty') |
|
| 414 | - $elementtype = 'societe'; |
|
| 415 | - if ($elementtype == 'contact') |
|
| 416 | - $elementtype = 'socpeople'; |
|
| 428 | + if ($elementtype == 'thirdparty') { |
|
| 429 | + $elementtype = 'societe'; |
|
| 430 | + } |
|
| 431 | + if ($elementtype == 'contact') { |
|
| 432 | + $elementtype = 'socpeople'; |
|
| 433 | + } |
|
| 417 | 434 | |
| 418 | 435 | $table = $elementtype . '_extrafields'; |
| 419 | - if ($elementtype == 'categorie') |
|
| 420 | - $table = 'categories_extrafields'; |
|
| 436 | + if ($elementtype == 'categorie') { |
|
| 437 | + $table = 'categories_extrafields'; |
|
| 438 | + } |
|
| 421 | 439 | |
| 422 | 440 | $error = 0; |
| 423 | 441 | |
@@ -466,10 +484,12 @@ discard block |
||
| 466 | 484 | // phpcs:enable |
| 467 | 485 | // global $conf; |
| 468 | 486 | |
| 469 | - if ($elementtype == 'thirdparty') |
|
| 470 | - $elementtype = 'societe'; |
|
| 471 | - if ($elementtype == 'contact') |
|
| 472 | - $elementtype = 'socpeople'; |
|
| 487 | + if ($elementtype == 'thirdparty') { |
|
| 488 | + $elementtype = 'societe'; |
|
| 489 | + } |
|
| 490 | + if ($elementtype == 'contact') { |
|
| 491 | + $elementtype = 'socpeople'; |
|
| 492 | + } |
|
| 473 | 493 | |
| 474 | 494 | if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
|
| 475 | 495 | $sql = "DELETE FROM " . MAIN_DB_PREFIX . "extrafields"; |
@@ -516,14 +536,17 @@ discard block |
||
| 516 | 536 | */ |
| 517 | 537 | function update($attrname, $label, $type, $length, $elementtype, $unique = 0, $required = 0, $pos = 0, $param = '', $alwayseditable = 0, $perms = '', $list = '', $help = '', $default = '', $computed = '', $entity = '', $langfile = '', $enabled = '1', $totalizable = 0) |
| 518 | 538 | {
|
| 519 | - if ($elementtype == 'thirdparty') |
|
| 520 | - $elementtype = 'societe'; |
|
| 521 | - if ($elementtype == 'contact') |
|
| 522 | - $elementtype = 'socpeople'; |
|
| 539 | + if ($elementtype == 'thirdparty') { |
|
| 540 | + $elementtype = 'societe'; |
|
| 541 | + } |
|
| 542 | + if ($elementtype == 'contact') { |
|
| 543 | + $elementtype = 'socpeople'; |
|
| 544 | + } |
|
| 523 | 545 | |
| 524 | 546 | $table = $elementtype . '_extrafields'; |
| 525 | - if ($elementtype == 'categorie') |
|
| 526 | - $table = 'categories_extrafields'; |
|
| 547 | + if ($elementtype == 'categorie') { |
|
| 548 | + $table = 'categories_extrafields'; |
|
| 549 | + } |
|
| 527 | 550 | |
| 528 | 551 | if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
|
| 529 | 552 | if ($type == 'boolean') {
|
@@ -620,24 +643,31 @@ discard block |
||
| 620 | 643 | AlDolUtils::dol_syslog(get_class($this) . "::update_label " . $attrname . ", " . $label . ", " . $type . ", " . $size . ", " . $elementtype . ", " . $unique . ", " . $required . ", " . $pos . ", " . $alwayseditable . ", " . $perms . ", " . $list . ", " . $default . ", " . $computed . ", " . $entity . ", " . $langfile . ", " . $enabled . ", " . $totalizable); |
| 621 | 644 | |
| 622 | 645 | // Clean parameters |
| 623 | - if ($elementtype == 'thirdparty') |
|
| 624 | - $elementtype = 'societe'; |
|
| 625 | - if ($elementtype == 'contact') |
|
| 626 | - $elementtype = 'socpeople'; |
|
| 627 | - |
|
| 628 | - if (empty($pos)) |
|
| 629 | - $pos = 0; |
|
| 630 | - if (empty($list)) |
|
| 631 | - $list = '0'; |
|
| 646 | + if ($elementtype == 'thirdparty') { |
|
| 647 | + $elementtype = 'societe'; |
|
| 648 | + } |
|
| 649 | + if ($elementtype == 'contact') { |
|
| 650 | + $elementtype = 'socpeople'; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + if (empty($pos)) { |
|
| 654 | + $pos = 0; |
|
| 655 | + } |
|
| 656 | + if (empty($list)) { |
|
| 657 | + $list = '0'; |
|
| 658 | + } |
|
| 632 | 659 | if (empty($totalizable)) {
|
| 633 | 660 | $totalizable = 0; |
| 634 | 661 | } |
| 635 | - if (empty($required)) |
|
| 636 | - $required = 0; |
|
| 637 | - if (empty($unique)) |
|
| 638 | - $unique = 0; |
|
| 639 | - if (empty($alwayseditable)) |
|
| 640 | - $alwayseditable = 0; |
|
| 662 | + if (empty($required)) { |
|
| 663 | + $required = 0; |
|
| 664 | + } |
|
| 665 | + if (empty($unique)) { |
|
| 666 | + $unique = 0; |
|
| 667 | + } |
|
| 668 | + if (empty($alwayseditable)) { |
|
| 669 | + $alwayseditable = 0; |
|
| 670 | + } |
|
| 641 | 671 | |
| 642 | 672 | if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) {
|
| 643 | 673 | Config::$dbEngine->begin(); |
@@ -741,21 +771,26 @@ discard block |
||
| 741 | 771 | // phpcs:enable |
| 742 | 772 | // global $conf; |
| 743 | 773 | |
| 744 | - if (empty($elementtype)) |
|
| 745 | - return array(); |
|
| 774 | + if (empty($elementtype)) { |
|
| 775 | + return array(); |
|
| 776 | + } |
|
| 746 | 777 | |
| 747 | - if ($elementtype == 'thirdparty') |
|
| 748 | - $elementtype = 'societe'; |
|
| 749 | - if ($elementtype == 'contact') |
|
| 750 | - $elementtype = 'socpeople'; |
|
| 751 | - if ($elementtype == 'order_supplier') |
|
| 752 | - $elementtype = 'commande_fournisseur'; |
|
| 778 | + if ($elementtype == 'thirdparty') { |
|
| 779 | + $elementtype = 'societe'; |
|
| 780 | + } |
|
| 781 | + if ($elementtype == 'contact') { |
|
| 782 | + $elementtype = 'socpeople'; |
|
| 783 | + } |
|
| 784 | + if ($elementtype == 'order_supplier') { |
|
| 785 | + $elementtype = 'commande_fournisseur'; |
|
| 786 | + } |
|
| 753 | 787 | |
| 754 | 788 | $array_name_label = array(); |
| 755 | 789 | |
| 756 | 790 | // To avoid conflicts with external modules. TODO Remove this. |
| 757 | - if (!$forceload &&!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 758 | - return $array_name_label; |
|
| 791 | + if (!$forceload &&!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 792 | + return $array_name_label; |
|
| 793 | + } |
|
| 759 | 794 | |
| 760 | 795 | // Set array of label of entity |
| 761 | 796 | // TODO Remove completely loading of label. This should be done by presentation. |
@@ -776,8 +811,10 @@ discard block |
||
| 776 | 811 | $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; |
| 777 | 812 | $sql .= " FROM " . MAIN_DB_PREFIX . "extrafields"; |
| 778 | 813 | $sql .= " WHERE entity IN (0," . Globals::$conf->entity . ")"; |
| 779 | - if ($elementtype) |
|
| 780 | - $sql .= " AND elementtype = '" . $elementtype . "'"; // Filed with object->table_element |
|
| 814 | + if ($elementtype) { |
|
| 815 | + $sql .= " AND elementtype = '" . $elementtype . "'"; |
|
| 816 | + } |
|
| 817 | + // Filed with object->table_element |
|
| 781 | 818 | $sql .= " ORDER BY pos"; |
| 782 | 819 | |
| 783 | 820 | $resql = Config::$dbEngine->select($sql); |
@@ -901,10 +938,11 @@ discard block |
||
| 901 | 938 | } |
| 902 | 939 | |
| 903 | 940 | if ($computed) {
|
| 904 | - if (!preg_match('/^search_/', $keyprefix))
|
|
| 905 | - return '<span class="opacitymedium">' . Globals::$langs->trans("AutomaticallyCalculated") . '</span>';
|
|
| 906 | - else |
|
| 907 | - return ''; |
|
| 941 | + if (!preg_match('/^search_/', $keyprefix)) { |
|
| 942 | + return '<span class="opacitymedium">' . Globals::$langs->trans("AutomaticallyCalculated") . '</span>'; |
|
| 943 | + } else { |
|
| 944 | + return ''; |
|
| 945 | + } |
|
| 908 | 946 | } |
| 909 | 947 | |
| 910 | 948 | if (empty($morecss)) {
|
@@ -938,13 +976,13 @@ discard block |
||
| 938 | 976 | $showtime = in_array($type, array('datetime')) ? 1 : 0;
|
| 939 | 977 | |
| 940 | 978 | // Do not show current date when field not required (see selectDate() method) |
| 941 | - if (!$required && $value == '') |
|
| 942 | - $value = '-1'; |
|
| 979 | + if (!$required && $value == '') { |
|
| 980 | + $value = '-1'; |
|
| 981 | + } |
|
| 943 | 982 | |
| 944 | 983 | // TODO Must also support $moreparam |
| 945 | 984 | $out = $form->selectDate($value, $keyprefix . $key . $keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 946 | - } |
|
| 947 | - elseif (in_array($type, array('int', 'integer'))) {
|
|
| 985 | + } elseif (in_array($type, array('int', 'integer'))) {
|
|
| 948 | 986 | $tmp = explode(',', $size);
|
| 949 | 987 | $newsize = $tmp[0]; |
| 950 | 988 | $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 : '') . '>'; |
@@ -996,22 +1034,23 @@ discard block |
||
| 996 | 1034 | $out .= '<select class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" ' . ($moreparam ? $moreparam : '') . '>'; |
| 997 | 1035 | $out .= '<option value="0"> </option>'; |
| 998 | 1036 | foreach ($param['options'] as $key => $val) {
|
| 999 | - if ((string) $key == '') |
|
| 1000 | - continue; |
|
| 1037 | + if ((string) $key == '') { |
|
| 1038 | + continue; |
|
| 1039 | + } |
|
| 1001 | 1040 | list($val, $parent) = explode('|', $val);
|
| 1002 | 1041 | $out .= '<option value="' . $key . '"'; |
| 1003 | 1042 | $out .= (((string) $value == (string) $key) ? ' selected' : ''); |
| 1004 | 1043 | $out .= (!empty($parent) ? ' parent="' . $parent . '"' : ''); |
| 1005 | 1044 | $out .= '>'; |
| 1006 | - if ($langfile && $val) |
|
| 1007 | - $out .= Globals::$langs->trans($val); |
|
| 1008 | - else |
|
| 1009 | - $out .= $val; |
|
| 1045 | + if ($langfile && $val) { |
|
| 1046 | + $out .= Globals::$langs->trans($val); |
|
| 1047 | + } else { |
|
| 1048 | + $out .= $val; |
|
| 1049 | + } |
|
| 1010 | 1050 | $out .= '</option>'; |
| 1011 | 1051 | } |
| 1012 | 1052 | $out .= '</select>'; |
| 1013 | - } |
|
| 1014 | - elseif ($type == 'sellist') {
|
|
| 1053 | + } elseif ($type == 'sellist') {
|
|
| 1015 | 1054 | $out = ''; |
| 1016 | 1055 | if (!empty(Globals::$conf->use_javascript_ajax) &&!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
| 1017 | 1056 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
@@ -1130,8 +1169,9 @@ discard block |
||
| 1130 | 1169 | $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
| 1131 | 1170 | } |
| 1132 | 1171 | } |
| 1133 | - if (empty($labeltoshow)) |
|
| 1134 | - $labeltoshow = '(not defined)'; |
|
| 1172 | + if (empty($labeltoshow)) { |
|
| 1173 | + $labeltoshow = '(not defined)'; |
|
| 1174 | + } |
|
| 1135 | 1175 | if ($value == $obj->rowid) {
|
| 1136 | 1176 | $out .= '<option value="' . $obj->rowid . '" selected>' . $labeltoshow . '</option>'; |
| 1137 | 1177 | } |
@@ -1330,8 +1370,9 @@ discard block |
||
| 1330 | 1370 | $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
| 1331 | 1371 | } |
| 1332 | 1372 | } |
| 1333 | - if (empty($labeltoshow)) |
|
| 1334 | - $labeltoshow = '(not defined)'; |
|
| 1373 | + if (empty($labeltoshow)) { |
|
| 1374 | + $labeltoshow = '(not defined)'; |
|
| 1375 | + } |
|
| 1335 | 1376 | |
| 1336 | 1377 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
| 1337 | 1378 | $data[$obj->rowid] = $labeltoshow; |
@@ -1415,8 +1456,10 @@ discard block |
||
| 1415 | 1456 | $hidden = (empty($list) ? 1 : 0); // If $list empty, 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) |
| 1416 | 1457 | } |
| 1417 | 1458 | |
| 1418 | - if ($hidden) |
|
| 1419 | - return ''; // This is a protection. If field is hidden, we should just not call this method. |
|
| 1459 | + if ($hidden) { |
|
| 1460 | + return ''; |
|
| 1461 | + } |
|
| 1462 | + // This is a protection. If field is hidden, we should just not call this method. |
|
| 1420 | 1463 | |
| 1421 | 1464 | |
| 1422 | 1465 | |
@@ -1457,12 +1500,12 @@ discard block |
||
| 1457 | 1500 | } elseif ($type == 'price') {
|
| 1458 | 1501 | $value = price($value, 0, Globals::$langs, 0, 0, -1, Globals::$conf->currency); |
| 1459 | 1502 | } elseif ($type == 'select') {
|
| 1460 | - if ($langfile && $param['options'][$value]) |
|
| 1461 | - $value = Globals::$langs->trans($param['options'][$value]); |
|
| 1462 | - else |
|
| 1463 | - $value = $param['options'][$value]; |
|
| 1464 | - } |
|
| 1465 | - elseif ($type == 'sellist') {
|
|
| 1503 | + if ($langfile && $param['options'][$value]) { |
|
| 1504 | + $value = Globals::$langs->trans($param['options'][$value]); |
|
| 1505 | + } else { |
|
| 1506 | + $value = $param['options'][$value]; |
|
| 1507 | + } |
|
| 1508 | + } elseif ($type == 'sellist') {
|
|
| 1466 | 1509 | $param_list = array_keys($param['options']); |
| 1467 | 1510 | $InfoFieldList = explode(":", $param_list[0]);
|
| 1468 | 1511 | |
@@ -1528,10 +1571,10 @@ discard block |
||
| 1528 | 1571 | $value = $obj->{$InfoFieldList[1]};
|
| 1529 | 1572 | } |
| 1530 | 1573 | } |
| 1531 | - } else |
|
| 1532 | - AlDolUtils::dol_syslog(get_class($this) . '::showOutputField error ' . Config::$dbEngine->lasterror(), LOG_WARNING); |
|
| 1533 | - } |
|
| 1534 | - elseif ($type == 'radio') {
|
|
| 1574 | + } else { |
|
| 1575 | + AlDolUtils::dol_syslog(get_class($this) . '::showOutputField error ' . Config::$dbEngine->lasterror(), LOG_WARNING); |
|
| 1576 | + } |
|
| 1577 | + } elseif ($type == 'radio') {
|
|
| 1535 | 1578 | $value = $param['options'][$value]; |
| 1536 | 1579 | } elseif ($type == 'checkbox') {
|
| 1537 | 1580 | $value_arr = explode(',', $value);
|
@@ -1640,8 +1683,9 @@ discard block |
||
| 1640 | 1683 | $value = dol_trunc(preg_replace('/./i', '*', $value), 8, 'right', 'UTF-8', 1);
|
| 1641 | 1684 | } else {
|
| 1642 | 1685 | $showsize = round($size); |
| 1643 | - if ($showsize > 48) |
|
| 1644 | - $showsize = 48; |
|
| 1686 | + if ($showsize > 48) { |
|
| 1687 | + $showsize = 48; |
|
| 1688 | + } |
|
| 1645 | 1689 | } |
| 1646 | 1690 | |
| 1647 | 1691 | //print $type.'-'.$size; |
@@ -1661,10 +1705,11 @@ discard block |
||
| 1661 | 1705 | {
|
| 1662 | 1706 | // global $conf, $langs; |
| 1663 | 1707 | |
| 1664 | - if (!empty($extrafieldsobjectkey)) |
|
| 1665 | - $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1666 | - else |
|
| 1667 | - $type = $this->attribute_type[$key]; |
|
| 1708 | + if (!empty($extrafieldsobjectkey)) { |
|
| 1709 | + $type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1710 | + } else { |
|
| 1711 | + $type = $this->attribute_type[$key]; |
|
| 1712 | + } |
|
| 1668 | 1713 | |
| 1669 | 1714 | $align = ''; |
| 1670 | 1715 | |
@@ -1720,18 +1765,21 @@ discard block |
||
| 1720 | 1765 | $nofillrequired = ''; // For error when required field left blank |
| 1721 | 1766 | $error_field_required = array(); |
| 1722 | 1767 | |
| 1723 | - if (is_array($this->attributes[$object->table_element]['label'])) |
|
| 1724 | - $extralabels = $this->attributes[$object->table_element]['label']; |
|
| 1768 | + if (is_array($this->attributes[$object->table_element]['label'])) { |
|
| 1769 | + $extralabels = $this->attributes[$object->table_element]['label']; |
|
| 1770 | + } |
|
| 1725 | 1771 | |
| 1726 | 1772 | if (is_array($extralabels)) {
|
| 1727 | 1773 | // Get extra fields |
| 1728 | 1774 | foreach ($extralabels as $key => $value) {
|
| 1729 | - if (!empty($onlykey) && $key != $onlykey) |
|
| 1730 | - continue; |
|
| 1775 | + if (!empty($onlykey) && $key != $onlykey) { |
|
| 1776 | + continue; |
|
| 1777 | + } |
|
| 1731 | 1778 | |
| 1732 | 1779 | $key_type = $this->attributes[$object->table_element]['type'][$key]; |
| 1733 | - if ($key_type == 'separate') |
|
| 1734 | - continue; |
|
| 1780 | + if ($key_type == 'separate') { |
|
| 1781 | + continue; |
|
| 1782 | + } |
|
| 1735 | 1783 | |
| 1736 | 1784 | $enabled = 1; |
| 1737 | 1785 | if (isset($this->attributes[$object->table_element]['list'][$key])) {
|
@@ -1741,10 +1789,12 @@ discard block |
||
| 1741 | 1789 | if (isset($this->attributes[$object->table_element]['perms'][$key])) {
|
| 1742 | 1790 | $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); |
| 1743 | 1791 | } |
| 1744 | - if (empty($enabled)) |
|
| 1745 | - continue; |
|
| 1746 | - if (empty($perms)) |
|
| 1747 | - continue; |
|
| 1792 | + if (empty($enabled)) { |
|
| 1793 | + continue; |
|
| 1794 | + } |
|
| 1795 | + if (empty($perms)) { |
|
| 1796 | + continue; |
|
| 1797 | + } |
|
| 1748 | 1798 | |
| 1749 | 1799 | if ($this->attributes[$object->table_element]['required'][$key]) { // Value is required
|
| 1750 | 1800 | // Check if empty without using GETPOST, value can be alpha, int, array, etc... |
@@ -21,7389 +21,7389 @@ |
||
| 21 | 21 | |
| 22 | 22 | abstract class AlCommonObject |
| 23 | 23 | {
|
| 24 | - /** |
|
| 24 | + /** |
|
| 25 | 25 | * @var int The object identifier |
| 26 | 26 | */ |
| 27 | - public $id; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var string Error string |
|
| 31 | - * @see errors |
|
| 32 | - */ |
|
| 33 | - public $error; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var string[] Array of error strings |
|
| 37 | - */ |
|
| 38 | - public $errors=array(); |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @var string ID to identify managed object |
|
| 42 | - */ |
|
| 43 | - public $element; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @var string Name of table without prefix where object is stored |
|
| 47 | - */ |
|
| 48 | - public $table_element; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @var int Name of subtable line |
|
| 52 | - */ |
|
| 53 | - public $table_element_line=''; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @var string Key value used to track if data is coming from import wizard |
|
| 57 | - */ |
|
| 58 | - public $import_key; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @var mixed Contains data to manage extrafields |
|
| 62 | - */ |
|
| 63 | - public $array_options=array(); |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
|
| 67 | - */ |
|
| 68 | - public $linkedObjectsIds; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var mixed Array of linked objects. Loaded by ->fetchObjectLinked |
|
| 72 | - */ |
|
| 73 | - public $linkedObjects; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @var Object To store a cloned copy of object before to edit it and keep track of old properties |
|
| 77 | - */ |
|
| 78 | - public $oldcopy; |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * @var string Column name of the ref field. |
|
| 82 | - */ |
|
| 83 | - protected $table_ref_field = ''; |
|
| 84 | - |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * @var array<string,mixed> Can be used to pass information when only object is provided to method |
|
| 91 | - */ |
|
| 92 | - public $context=array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @var string Contains canvas name if record is an alternative canvas record |
|
| 96 | - */ |
|
| 97 | - public $canvas; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @var Project The related project |
|
| 101 | - * @see fetch_projet() |
|
| 102 | - */ |
|
| 103 | - public $project; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @var int The related project ID |
|
| 107 | - * @see setProject(), project |
|
| 108 | - */ |
|
| 109 | - public $fk_project; |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @deprecated |
|
| 113 | - * @see project |
|
| 114 | - */ |
|
| 115 | - public $projet; |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @var Contact a related contact |
|
| 119 | - * @see fetch_contact() |
|
| 120 | - */ |
|
| 121 | - public $contact; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @var int The related contact ID |
|
| 125 | - * @see fetch_contact() |
|
| 126 | - */ |
|
| 127 | - public $contact_id; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @var Societe A related thirdparty |
|
| 131 | - * @see fetch_thirdparty() |
|
| 132 | - */ |
|
| 133 | - public $thirdparty; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @var User A related user |
|
| 137 | - * @see fetch_user() |
|
| 138 | - */ |
|
| 139 | - public $user; |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @var string The type of originating object ('commande', 'facture', ...)
|
|
| 143 | - * @see fetch_origin() |
|
| 144 | - */ |
|
| 145 | - public $origin; |
|
| 146 | - |
|
| 147 | - /** |
|
| 148 | - * @var int The id of originating object |
|
| 149 | - * @see fetch_origin() |
|
| 150 | - */ |
|
| 151 | - public $origin_id; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * @var string The object's reference |
|
| 155 | - */ |
|
| 156 | - public $ref; |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * @var string The object's previous reference |
|
| 160 | - */ |
|
| 161 | - public $ref_previous; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * @var string The object's next reference |
|
| 165 | - */ |
|
| 166 | - public $ref_next; |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @var string An external reference for the object |
|
| 170 | - */ |
|
| 171 | - public $ref_ext; |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * @var int The object's status |
|
| 175 | - * @see setStatut() |
|
| 176 | - */ |
|
| 177 | - public $statut; |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @var string |
|
| 181 | - * @see getFullAddress() |
|
| 182 | - */ |
|
| 183 | - public $country; |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @var int |
|
| 187 | - * @see getFullAddress(), country |
|
| 188 | - */ |
|
| 189 | - public $country_id; |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @var string |
|
| 193 | - * @see getFullAddress(), isInEEC(), country |
|
| 194 | - */ |
|
| 195 | - public $country_code; |
|
| 27 | + public $id; |
|
| 196 | 28 | |
| 197 | 29 | /** |
| 198 | - * @var string |
|
| 199 | - * @see getFullAddress() |
|
| 200 | - */ |
|
| 201 | - public $state; |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @var int |
|
| 205 | - * @see getFullAddress(), state |
|
| 206 | - */ |
|
| 207 | - public $state_id; |
|
| 30 | + * @var string Error string |
|
| 31 | + * @see errors |
|
| 32 | + */ |
|
| 33 | + public $error; |
|
| 208 | 34 | |
| 209 | - /** |
|
| 210 | - * @var string |
|
| 211 | - * @see getFullAddress(), state |
|
| 212 | - */ |
|
| 213 | - public $state_code; |
|
| 35 | + /** |
|
| 36 | + * @var string[] Array of error strings |
|
| 37 | + */ |
|
| 38 | + public $errors=array(); |
|
| 214 | 39 | |
| 215 | 40 | /** |
| 216 | - * @var string |
|
| 217 | - * @see getFullAddress(), region |
|
| 218 | - */ |
|
| 219 | - public $region; |
|
| 41 | + * @var string ID to identify managed object |
|
| 42 | + */ |
|
| 43 | + public $element; |
|
| 220 | 44 | |
| 221 | - /** |
|
| 222 | - * @var string |
|
| 223 | - * @see getFullAddress(), region |
|
| 224 | - */ |
|
| 225 | - public $region_code; |
|
| 45 | + /** |
|
| 46 | + * @var string Name of table without prefix where object is stored |
|
| 47 | + */ |
|
| 48 | + public $table_element; |
|
| 226 | 49 | |
| 227 | - /** |
|
| 228 | - * @var int |
|
| 229 | - * @see fetch_barcode() |
|
| 230 | - */ |
|
| 231 | - public $barcode_type; |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @var string |
|
| 235 | - * @see fetch_barcode(), barcode_type |
|
| 236 | - */ |
|
| 237 | - public $barcode_type_code; |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * @var string |
|
| 241 | - * @see fetch_barcode(), barcode_type |
|
| 242 | - */ |
|
| 243 | - public $barcode_type_label; |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * @var string |
|
| 247 | - * @see fetch_barcode(), barcode_type |
|
| 248 | - */ |
|
| 249 | - public $barcode_type_coder; |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * @var int Payment method ID (cheque, cash, ...) |
|
| 253 | - * @see setPaymentMethods() |
|
| 254 | - */ |
|
| 255 | - public $mode_reglement_id; |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @var int Payment terms ID |
|
| 259 | - * @see setPaymentTerms() |
|
| 260 | - */ |
|
| 261 | - public $cond_reglement_id; |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * @var int Payment terms ID |
|
| 265 | - * @deprecated Kept for compatibility |
|
| 266 | - * @see cond_reglement_id; |
|
| 267 | - */ |
|
| 268 | - public $cond_reglement; |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * @var int Delivery address ID |
|
| 272 | - * @deprecated |
|
| 273 | - * @see setDeliveryAddress() |
|
| 274 | - */ |
|
| 275 | - public $fk_delivery_address; |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * @var int Shipping method ID |
|
| 279 | - * @see setShippingMethod() |
|
| 280 | - */ |
|
| 281 | - public $shipping_method_id; |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * @var string |
|
| 285 | - * @see SetDocModel() |
|
| 286 | - */ |
|
| 287 | - public $modelpdf; |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * @var int Bank account ID |
|
| 291 | - * @see SetBankAccount() |
|
| 292 | - */ |
|
| 293 | - public $fk_account; |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * @var string Public note |
|
| 297 | - * @see update_note() |
|
| 298 | - */ |
|
| 299 | - public $note_public; |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * @var string Private note |
|
| 303 | - * @see update_note() |
|
| 304 | - */ |
|
| 305 | - public $note_private; |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * @deprecated |
|
| 309 | - * @see note_public |
|
| 310 | - */ |
|
| 311 | - public $note; |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * @var float Total amount before taxes |
|
| 315 | - * @see update_price() |
|
| 316 | - */ |
|
| 317 | - public $total_ht; |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * @var float Total VAT amount |
|
| 321 | - * @see update_price() |
|
| 322 | - */ |
|
| 323 | - public $total_tva; |
|
| 324 | - |
|
| 325 | - /** |
|
| 326 | - * @var float Total local tax 1 amount |
|
| 327 | - * @see update_price() |
|
| 328 | - */ |
|
| 329 | - public $total_localtax1; |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * @var float Total local tax 2 amount |
|
| 333 | - * @see update_price() |
|
| 334 | - */ |
|
| 335 | - public $total_localtax2; |
|
| 336 | - |
|
| 337 | - /** |
|
| 338 | - * @var float Total amount with taxes |
|
| 339 | - * @see update_price() |
|
| 340 | - */ |
|
| 341 | - public $total_ttc; |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * @var CommonObjectLine[] |
|
| 345 | - */ |
|
| 346 | - public $lines; |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * @var mixed Contains comments |
|
| 350 | - * @see fetchComments() |
|
| 351 | - */ |
|
| 352 | - public $comments=array(); |
|
| 353 | - |
|
| 354 | - /** |
|
| 355 | - * @var int |
|
| 356 | - * @see setIncoterms() |
|
| 357 | - */ |
|
| 358 | - public $fk_incoterms; |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * @var string |
|
| 362 | - * @see SetIncoterms() |
|
| 363 | - */ |
|
| 364 | - public $libelle_incoterms; |
|
| 365 | - |
|
| 366 | - /** |
|
| 367 | - * @var string |
|
| 368 | - * @see display_incoterms() |
|
| 369 | - */ |
|
| 370 | - public $location_incoterms; |
|
| 371 | - |
|
| 372 | - public $name; |
|
| 373 | - public $lastname; |
|
| 374 | - public $firstname; |
|
| 375 | - public $civility_id; |
|
| 376 | - |
|
| 377 | - // Dates |
|
| 378 | - public $date_creation; // Date creation |
|
| 379 | - public $date_validation; // Date validation |
|
| 380 | - public $date_modification; // Date last change (tms field) |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - |
|
| 384 | - // No constructor as it is an abstract class |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Check an object id/ref exists |
|
| 388 | - * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch |
|
| 389 | - * |
|
| 390 | - * @param string $element String of element ('product', 'facture', ...)
|
|
| 391 | - * @param int $id Id of object |
|
| 392 | - * @param string $ref Ref of object to check |
|
| 393 | - * @param string $ref_ext Ref ext of object to check |
|
| 394 | - * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
|
| 395 | - */ |
|
| 396 | - static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 397 | - {
|
|
| 398 | - global $db,$conf; |
|
| 399 | - |
|
| 400 | - $sql = "SELECT rowid, ref, ref_ext"; |
|
| 401 | - $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 402 | - $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
|
| 403 | - |
|
| 404 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 405 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 406 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 407 | - else {
|
|
| 408 | - $error='ErrorWrongParameters'; |
|
| 409 | - dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
| 410 | - return -1; |
|
| 411 | - } |
|
| 412 | - if ($ref || $ref_ext) |
|
| 413 | - $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 50 | + /** |
|
| 51 | + * @var int Name of subtable line |
|
| 52 | + */ |
|
| 53 | + public $table_element_line=''; |
|
| 414 | 54 | |
| 415 | - dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
| 416 | - $resql = $db->query($sql); |
|
| 417 | - if ($resql) |
|
| 418 | - {
|
|
| 419 | - $num=$db->num_rows($resql); |
|
| 420 | - if ($num > 0) return 1; |
|
| 421 | - else return 0; |
|
| 422 | - } |
|
| 423 | - return -1; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Method to output saved errors |
|
| 428 | - * |
|
| 429 | - * @return string String with errors |
|
| 430 | - */ |
|
| 431 | - function errorsToString() |
|
| 432 | - {
|
|
| 433 | - return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):'');
|
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * Return full name (civility+' '+name+' '+lastname) |
|
| 438 | - * |
|
| 439 | - * @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
| 440 | - * @param int $option 0=No option, 1=Add civility |
|
| 441 | - * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname |
|
| 442 | - * @param int $maxlen Maximum length |
|
| 443 | - * @return string String with full name |
|
| 444 | - */ |
|
| 445 | - function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 446 | - {
|
|
| 447 | - //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
| 448 | - $lastname=$this->lastname; |
|
| 449 | - $firstname=$this->firstname; |
|
| 450 | - 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:''))))); |
|
| 451 | - |
|
| 452 | - $ret=''; |
|
| 453 | - if ($option && $this->civility_id) |
|
| 454 | - {
|
|
| 455 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 456 | - else $ret.=$this->civility_id.' '; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - $ret .= AlDolUtils::dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 55 | + /** |
|
| 56 | + * @var string Key value used to track if data is coming from import wizard |
|
| 57 | + */ |
|
| 58 | + public $import_key; |
|
| 460 | 59 | |
| 461 | - return AlDolUtils::dol_trunc($ret, $maxlen); |
|
| 462 | - } |
|
| 60 | + /** |
|
| 61 | + * @var mixed Contains data to manage extrafields |
|
| 62 | + */ |
|
| 63 | + public $array_options=array(); |
|
| 463 | 64 | |
| 464 | - /** |
|
| 465 | - * Return full address of contact |
|
| 466 | - * |
|
| 467 | - * @param int $withcountry 1=Add country into address string |
|
| 468 | - * @param string $sep Separator to use to build string |
|
| 469 | - * @param int $withregion 1=Add region into address string |
|
| 470 | - * @return string Full address string |
|
| 471 | - */ |
|
| 472 | - function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
| 473 | - {
|
|
| 474 | - if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
|
| 475 | - {
|
|
| 476 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 477 | - $tmparray=getCountry($this->country_id,'all'); |
|
| 478 | - $this->country_code=$tmparray['code']; |
|
| 479 | - $this->country =$tmparray['label']; |
|
| 480 | - } |
|
| 65 | + /** |
|
| 66 | + * @var int[][] Array of linked objects ids. Loaded by ->fetchObjectLinked |
|
| 67 | + */ |
|
| 68 | + public $linkedObjectsIds; |
|
| 481 | 69 | |
| 482 | - if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
|
| 483 | - {
|
|
| 484 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 485 | - $tmparray=getState($this->state_id,'all',0,1); |
|
| 486 | - $this->state_code =$tmparray['code']; |
|
| 487 | - $this->state =$tmparray['label']; |
|
| 488 | - $this->region_code =$tmparray['region_code']; |
|
| 489 | - $this->region =$tmparray['region']; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - return dol_format_address($this, $withcountry, $sep); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Return full address for banner |
|
| 498 | - * |
|
| 499 | - * @param string $htmlkey HTML id to make banner content unique |
|
| 500 | - * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
| 501 | - * @return string Full address string |
|
| 502 | - */ |
|
| 503 | - function getBannerAddress($htmlkey, $object) |
|
| 504 | - {
|
|
| 505 | - global $conf, $langs; |
|
| 506 | - |
|
| 507 | - $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
|
|
| 508 | - |
|
| 509 | - $contactid=0; |
|
| 510 | - $thirdpartyid=0; |
|
| 511 | - if ($this->element == 'societe') |
|
| 512 | - {
|
|
| 513 | - $thirdpartyid=$this->id; |
|
| 514 | - } |
|
| 515 | - if ($this->element == 'contact') |
|
| 516 | - {
|
|
| 517 | - $contactid=$this->id; |
|
| 518 | - $thirdpartyid=$object->fk_soc; |
|
| 519 | - } |
|
| 520 | - if ($this->element == 'user') |
|
| 521 | - {
|
|
| 522 | - $contactid=$this->contact_id; |
|
| 523 | - $thirdpartyid=$object->fk_soc; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - $out='<!-- BEGIN part to show address block -->'; |
|
| 527 | - |
|
| 528 | - $outdone=0; |
|
| 529 | - $coords = $this->getFullAddress(1, ', ', Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 530 | - if ($coords) |
|
| 531 | - {
|
|
| 532 | - if (!empty(Globals::$conf->use_javascript_ajax)) {
|
|
| 533 | - $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 534 | - // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
| 535 | - $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
|
|
| 536 | - $out.=img_picto($langs->trans("Address"), 'object_address.png');
|
|
| 537 | - $out.='</a> '; |
|
| 538 | - } |
|
| 539 | - $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 540 | - $outdone++; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if (!in_array($this->country_code, $countriesusingstate) && empty(Globals::$conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
| 544 | - && empty(Globals::$conf->global->SOCIETE_DISABLE_STATE) && $this->state) {
|
|
| 545 | - if (!empty(Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && Globals::$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(Globals::$conf->socialnetworks->enabled)) {
|
|
| 594 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 595 | - $outdone++; |
|
| 596 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 597 | - $outdone++; |
|
| 598 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 599 | - $outdone++; |
|
| 600 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 601 | - $outdone++; |
|
| 602 | - } |
|
| 603 | - $out.='</div>'; |
|
| 604 | - |
|
| 605 | - $out.='<!-- END Part to show address block -->'; |
|
| 606 | - |
|
| 607 | - return $out; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Return the link of last main doc file for direct public download. |
|
| 612 | - * |
|
| 613 | - * @param string $modulepart Module related to document |
|
| 614 | - * @param int $initsharekey Init the share key if it was not yet defined |
|
| 615 | - * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
|
| 616 | - * @return string Link or empty string if there is no download link |
|
| 617 | - */ |
|
| 618 | - function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 619 | - {
|
|
| 620 | - global $user, $dolibarr_main_url_root; |
|
| 621 | - |
|
| 622 | - if (empty($this->last_main_doc)) |
|
| 623 | - {
|
|
| 624 | - return ''; // No way to known which document name to use |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 628 | - $ecmfile=new EcmFiles($this->db); |
|
| 629 | - $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
|
| 630 | - if ($result < 0) |
|
| 631 | - {
|
|
| 632 | - $this->error = $ecmfile->error; |
|
| 633 | - $this->errors = $ecmfile->errors; |
|
| 634 | - return -1; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - if (empty($ecmfile->id)) |
|
| 638 | - {
|
|
| 639 | - // Add entry into index |
|
| 640 | - if ($initsharekey) |
|
| 641 | - {
|
|
| 642 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 643 | - // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
|
| 644 | - /* |
|
| 645 | - $ecmfile->filepath = $rel_dir; |
|
| 646 | - $ecmfile->filename = $filename; |
|
| 647 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 648 | - $ecmfile->fullpath_orig = ''; |
|
| 649 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
| 650 | - $ecmfile->description = ''; // indexed content |
|
| 651 | - $ecmfile->keyword = ''; // keyword content |
|
| 652 | - $ecmfile->share = getRandomPassword(true); |
|
| 653 | - $result = $ecmfile->create($user); |
|
| 654 | - if ($result < 0) |
|
| 655 | - {
|
|
| 656 | - $this->error = $ecmfile->error; |
|
| 657 | - $this->errors = $ecmfile->errors; |
|
| 658 | - } |
|
| 659 | - */ |
|
| 660 | - } |
|
| 661 | - else return ''; |
|
| 662 | - } |
|
| 663 | - elseif (empty($ecmfile->share)) |
|
| 664 | - {
|
|
| 665 | - // Add entry into index |
|
| 666 | - if ($initsharekey) |
|
| 667 | - {
|
|
| 668 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 669 | - $ecmfile->share = getRandomPassword(true); |
|
| 670 | - $ecmfile->update($user); |
|
| 671 | - } |
|
| 672 | - else return ''; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - // Define $urlwithroot |
|
| 676 | - $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
|
|
| 677 | - $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 678 | - //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 679 | - |
|
| 680 | - $forcedownload=0; |
|
| 681 | - |
|
| 682 | - $paramlink=''; |
|
| 683 | - //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
|
| 684 | - //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
|
| 685 | - //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
|
| 686 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 687 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 688 | - |
|
| 689 | - if ($relativelink) |
|
| 690 | - {
|
|
| 691 | - $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 692 | - } |
|
| 693 | - else |
|
| 694 | - {
|
|
| 695 | - $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - // Here $ecmfile->share is defined |
|
| 699 | - return $linktoreturn; |
|
| 700 | - } |
|
| 70 | + /** |
|
| 71 | + * @var mixed Array of linked objects. Loaded by ->fetchObjectLinked |
|
| 72 | + */ |
|
| 73 | + public $linkedObjects; |
|
| 701 | 74 | |
| 75 | + /** |
|
| 76 | + * @var Object To store a cloned copy of object before to edit it and keep track of old properties |
|
| 77 | + */ |
|
| 78 | + public $oldcopy; |
|
| 702 | 79 | |
| 703 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 704 | - /** |
|
| 705 | - * Add a link between element $this->element and a contact |
|
| 706 | - * |
|
| 707 | - * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link |
|
| 708 | - * @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 |
|
| 709 | - * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) |
|
| 710 | - * @param int $notrigger Disable all triggers |
|
| 711 | - * @return int <0 if KO, >0 if OK |
|
| 712 | - */ |
|
| 713 | - function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 714 | - {
|
|
| 715 | - // phpcs:enable |
|
| 716 | - global $user,$langs; |
|
| 717 | - |
|
| 718 | - |
|
| 719 | - dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
| 720 | - |
|
| 721 | - // Check parameters |
|
| 722 | - if ($fk_socpeople <= 0) |
|
| 723 | - {
|
|
| 724 | - $langs->load("errors");
|
|
| 725 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","1");
|
|
| 726 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 727 | - return -1; |
|
| 728 | - } |
|
| 729 | - if (! $type_contact) |
|
| 730 | - {
|
|
| 731 | - $langs->load("errors");
|
|
| 732 | - $this->error=$langs->trans("ErrorWrongValueForParameterX","2");
|
|
| 733 | - dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 734 | - return -2; |
|
| 735 | - } |
|
| 736 | - |
|
| 737 | - $id_type_contact=0; |
|
| 738 | - if (is_numeric($type_contact)) |
|
| 739 | - {
|
|
| 740 | - $id_type_contact=$type_contact; |
|
| 741 | - } |
|
| 742 | - else |
|
| 743 | - {
|
|
| 744 | - // We look for id type_contact |
|
| 745 | - $sql = "SELECT tc.rowid"; |
|
| 746 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 747 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 748 | - $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 749 | - $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 750 | - //print $sql; |
|
| 751 | - $resql=$this->db->query($sql); |
|
| 752 | - if ($resql) |
|
| 753 | - {
|
|
| 754 | - $obj = $this->db->fetch_object($resql); |
|
| 755 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 756 | - } |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - if ($id_type_contact == 0) |
|
| 760 | - {
|
|
| 761 | - $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 762 | - 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");
|
|
| 763 | - return -3; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - $datecreate = dol_now(); |
|
| 767 | - |
|
| 768 | - // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
|
| 769 | - $TListeContacts=$this->liste_contact(-1, $source); |
|
| 770 | - $already_added=false; |
|
| 771 | - if(!empty($TListeContacts)) {
|
|
| 772 | - foreach($TListeContacts as $array_contact) {
|
|
| 773 | - if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
|
| 774 | - $already_added=true; |
|
| 775 | - break; |
|
| 776 | - } |
|
| 777 | - } |
|
| 778 | - } |
|
| 80 | + /** |
|
| 81 | + * @var string Column name of the ref field. |
|
| 82 | + */ |
|
| 83 | + protected $table_ref_field = ''; |
|
| 779 | 84 | |
| 780 | - if(!$already_added) {
|
|
| 781 | 85 | |
| 782 | - $this->db->begin(); |
|
| 783 | 86 | |
| 784 | - // Insert into database |
|
| 785 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
| 786 | - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 787 | - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
|
| 788 | - $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 789 | - $sql.= ", 4, ". $id_type_contact; |
|
| 790 | - $sql.= ")"; |
|
| 87 | + // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. |
|
| 791 | 88 | |
| 792 | - $resql=$this->db->query($sql); |
|
| 793 | - if ($resql) |
|
| 794 | - {
|
|
| 795 | - if (! $notrigger) |
|
| 796 | - {
|
|
| 797 | - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 798 | - if ($result < 0) |
|
| 799 | - {
|
|
| 800 | - $this->db->rollback(); |
|
| 801 | - return -1; |
|
| 802 | - } |
|
| 803 | - } |
|
| 89 | + /** |
|
| 90 | + * @var array<string,mixed> Can be used to pass information when only object is provided to method |
|
| 91 | + */ |
|
| 92 | + public $context=array(); |
|
| 804 | 93 | |
| 805 | - $this->db->commit(); |
|
| 806 | - return 1; |
|
| 807 | - } |
|
| 808 | - else |
|
| 809 | - {
|
|
| 810 | - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
| 811 | - {
|
|
| 812 | - $this->error=$this->db->errno(); |
|
| 813 | - $this->db->rollback(); |
|
| 814 | - echo 'err rollback'; |
|
| 815 | - return -2; |
|
| 816 | - } |
|
| 817 | - else |
|
| 818 | - {
|
|
| 819 | - $this->error=$this->db->error(); |
|
| 820 | - $this->db->rollback(); |
|
| 821 | - return -1; |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - } else return 0; |
|
| 825 | - } |
|
| 94 | + /** |
|
| 95 | + * @var string Contains canvas name if record is an alternative canvas record |
|
| 96 | + */ |
|
| 97 | + public $canvas; |
|
| 826 | 98 | |
| 827 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 828 | - /** |
|
| 829 | - * Copy contact from one element to current |
|
| 830 | - * |
|
| 831 | - * @param CommonObject $objFrom Source element |
|
| 832 | - * @param string $source Nature of contact ('internal' or 'external')
|
|
| 833 | - * @return int >0 if OK, <0 if KO |
|
| 834 | - */ |
|
| 835 | - function copy_linked_contact($objFrom, $source='internal') |
|
| 836 | - {
|
|
| 837 | - // phpcs:enable |
|
| 838 | - $contacts = $objFrom->liste_contact(-1, $source); |
|
| 839 | - foreach($contacts as $contact) |
|
| 840 | - {
|
|
| 841 | - if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
|
| 842 | - {
|
|
| 843 | - $this->error=$this->db->lasterror(); |
|
| 844 | - return -1; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - return 1; |
|
| 848 | - } |
|
| 99 | + /** |
|
| 100 | + * @var Project The related project |
|
| 101 | + * @see fetch_projet() |
|
| 102 | + */ |
|
| 103 | + public $project; |
|
| 849 | 104 | |
| 850 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 851 | - /** |
|
| 852 | - * Update a link to contact line |
|
| 853 | - * |
|
| 854 | - * @param int $rowid Id of line contact-element |
|
| 855 | - * @param int $statut New status of link |
|
| 856 | - * @param int $type_contact_id Id of contact type (not modified if 0) |
|
| 857 | - * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
|
| 858 | - * @return int <0 if KO, >= 0 if OK |
|
| 859 | - */ |
|
| 860 | - function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 861 | - {
|
|
| 862 | - // phpcs:enable |
|
| 863 | - // Insert into database |
|
| 864 | - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
| 865 | - $sql.= " statut = ".$statut; |
|
| 866 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 867 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 868 | - $sql.= " where rowid = ".$rowid; |
|
| 869 | - $resql=$this->db->query($sql); |
|
| 870 | - if ($resql) |
|
| 871 | - {
|
|
| 872 | - return 0; |
|
| 873 | - } |
|
| 874 | - else |
|
| 875 | - {
|
|
| 876 | - $this->error=$this->db->lasterror(); |
|
| 877 | - return -1; |
|
| 878 | - } |
|
| 879 | - } |
|
| 105 | + /** |
|
| 106 | + * @var int The related project ID |
|
| 107 | + * @see setProject(), project |
|
| 108 | + */ |
|
| 109 | + public $fk_project; |
|
| 880 | 110 | |
| 881 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 882 | - /** |
|
| 883 | - * Delete a link to contact line |
|
| 884 | - * |
|
| 885 | - * @param int $rowid Id of contact link line to delete |
|
| 886 | - * @param int $notrigger Disable all triggers |
|
| 887 | - * @return int >0 if OK, <0 if KO |
|
| 888 | - */ |
|
| 889 | - function delete_contact($rowid, $notrigger=0) |
|
| 890 | - {
|
|
| 891 | - // phpcs:enable |
|
| 892 | - global $user; |
|
| 111 | + /** |
|
| 112 | + * @deprecated |
|
| 113 | + * @see project |
|
| 114 | + */ |
|
| 115 | + public $projet; |
|
| 893 | 116 | |
| 117 | + /** |
|
| 118 | + * @var Contact a related contact |
|
| 119 | + * @see fetch_contact() |
|
| 120 | + */ |
|
| 121 | + public $contact; |
|
| 894 | 122 | |
| 895 | - $this->db->begin(); |
|
| 123 | + /** |
|
| 124 | + * @var int The related contact ID |
|
| 125 | + * @see fetch_contact() |
|
| 126 | + */ |
|
| 127 | + public $contact_id; |
|
| 896 | 128 | |
| 897 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 898 | - $sql.= " WHERE rowid =".$rowid; |
|
| 129 | + /** |
|
| 130 | + * @var Societe A related thirdparty |
|
| 131 | + * @see fetch_thirdparty() |
|
| 132 | + */ |
|
| 133 | + public $thirdparty; |
|
| 899 | 134 | |
| 900 | - dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
| 901 | - if ($this->db->query($sql)) |
|
| 902 | - {
|
|
| 903 | - if (! $notrigger) |
|
| 904 | - {
|
|
| 905 | - $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 906 | - if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - $this->db->commit(); |
|
| 910 | - return 1; |
|
| 911 | - } |
|
| 912 | - else |
|
| 913 | - {
|
|
| 914 | - $this->error=$this->db->lasterror(); |
|
| 915 | - $this->db->rollback(); |
|
| 916 | - return -1; |
|
| 917 | - } |
|
| 918 | - } |
|
| 135 | + /** |
|
| 136 | + * @var User A related user |
|
| 137 | + * @see fetch_user() |
|
| 138 | + */ |
|
| 139 | + public $user; |
|
| 919 | 140 | |
| 920 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 921 | - /** |
|
| 922 | - * Delete all links between an object $this and all its contacts |
|
| 923 | - * |
|
| 924 | - * @param string $source '' or 'internal' or 'external' |
|
| 925 | - * @param string $code Type of contact (code or id) |
|
| 926 | - * @return int >0 if OK, <0 if KO |
|
| 927 | - */ |
|
| 928 | - function delete_linked_contact($source='',$code='') |
|
| 929 | - {
|
|
| 930 | - // phpcs:enable |
|
| 931 | - $temp = array(); |
|
| 932 | - $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 933 | - |
|
| 934 | - foreach($typeContact as $key => $value) |
|
| 935 | - {
|
|
| 936 | - array_push($temp,$key); |
|
| 937 | - } |
|
| 938 | - $listId = implode(",", $temp);
|
|
| 939 | - |
|
| 940 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 941 | - $sql.= " WHERE element_id = ".$this->id; |
|
| 942 | - if ($listId) |
|
| 943 | - $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 944 | - |
|
| 945 | - dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
| 946 | - if ($this->db->query($sql)) |
|
| 947 | - {
|
|
| 948 | - return 1; |
|
| 949 | - } |
|
| 950 | - else |
|
| 951 | - {
|
|
| 952 | - $this->error=$this->db->lasterror(); |
|
| 953 | - return -1; |
|
| 954 | - } |
|
| 955 | - } |
|
| 141 | + /** |
|
| 142 | + * @var string The type of originating object ('commande', 'facture', ...)
|
|
| 143 | + * @see fetch_origin() |
|
| 144 | + */ |
|
| 145 | + public $origin; |
|
| 956 | 146 | |
| 957 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 958 | - /** |
|
| 959 | - * Get array of all contacts for an object |
|
| 960 | - * |
|
| 961 | - * @param int $statut Status of links to get (-1=all) |
|
| 962 | - * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) |
|
| 963 | - * @param int $list 0:Return array contains all properties, 1:Return array contains just id |
|
| 964 | - * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
|
|
| 965 | - * @return array|int Array of contacts, -1 if error |
|
| 966 | - */ |
|
| 967 | - function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 968 | - {
|
|
| 969 | - // phpcs:enable |
|
| 970 | - global $langs; |
|
| 971 | - |
|
| 972 | - $tab=array(); |
|
| 973 | - |
|
| 974 | - $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 |
|
| 975 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 976 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 977 | - $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 978 | - $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 979 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 980 | - $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 981 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 982 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 983 | - $sql.= " WHERE ec.element_id =".$this->id; |
|
| 984 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 985 | - $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 986 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 987 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 988 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 989 | - $sql.= " AND tc.active=1"; |
|
| 990 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 991 | - $sql.=" ORDER BY t.lastname ASC"; |
|
| 992 | - |
|
| 993 | - dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
| 994 | - $resql=$this->db->query($sql); |
|
| 995 | - if ($resql) |
|
| 996 | - {
|
|
| 997 | - $num=$this->db->num_rows($resql); |
|
| 998 | - $i=0; |
|
| 999 | - while ($i < $num) |
|
| 1000 | - {
|
|
| 1001 | - $obj = $this->db->fetch_object($resql); |
|
| 147 | + /** |
|
| 148 | + * @var int The id of originating object |
|
| 149 | + * @see fetch_origin() |
|
| 150 | + */ |
|
| 151 | + public $origin_id; |
|
| 1002 | 152 | |
| 1003 | - if (! $list) |
|
| 1004 | - {
|
|
| 1005 | - $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1006 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1007 | - $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,
|
|
| 1008 | - 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1009 | - 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
|
| 1010 | - 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
|
| 1011 | - } |
|
| 1012 | - else |
|
| 1013 | - {
|
|
| 1014 | - $tab[$i]=$obj->id; |
|
| 1015 | - } |
|
| 153 | + /** |
|
| 154 | + * @var string The object's reference |
|
| 155 | + */ |
|
| 156 | + public $ref; |
|
| 1016 | 157 | |
| 1017 | - $i++; |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - return $tab; |
|
| 1021 | - } |
|
| 1022 | - else |
|
| 1023 | - {
|
|
| 1024 | - $this->error=$this->db->lasterror(); |
|
| 1025 | - dol_print_error($this->db); |
|
| 1026 | - return -1; |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - |
|
| 1031 | - /** |
|
| 1032 | - * Update status of a contact linked to object |
|
| 1033 | - * |
|
| 1034 | - * @param int $rowid Id of link between object and contact |
|
| 1035 | - * @return int <0 if KO, >=0 if OK |
|
| 1036 | - */ |
|
| 1037 | - function swapContactStatus($rowid) |
|
| 1038 | - {
|
|
| 1039 | - $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
|
| 1040 | - $sql.= " tc.code, tc.libelle"; |
|
| 1041 | - //$sql.= ", s.fk_soc"; |
|
| 1042 | - $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
|
|
| 1043 | - //$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 |
|
| 1044 | - $sql.= " WHERE ec.rowid =".$rowid; |
|
| 1045 | - $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1046 | - $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1047 | - |
|
| 1048 | - dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
| 1049 | - $resql=$this->db->query($sql); |
|
| 1050 | - if ($resql) |
|
| 1051 | - {
|
|
| 1052 | - $obj = $this->db->fetch_object($resql); |
|
| 1053 | - $newstatut = ($obj->statut == 4) ? 5 : 4; |
|
| 1054 | - $result = $this->update_contact($rowid, $newstatut); |
|
| 1055 | - $this->db->free($resql); |
|
| 1056 | - return $result; |
|
| 1057 | - } |
|
| 1058 | - else |
|
| 1059 | - {
|
|
| 1060 | - $this->error=$this->db->error(); |
|
| 1061 | - dol_print_error($this->db); |
|
| 1062 | - return -1; |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 158 | + /** |
|
| 159 | + * @var string The object's previous reference |
|
| 160 | + */ |
|
| 161 | + public $ref_previous; |
|
| 1065 | 162 | |
| 1066 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1067 | - /** |
|
| 1068 | - * Return array with list of possible values for type of contacts |
|
| 1069 | - * |
|
| 1070 | - * @param string $source 'internal', 'external' or 'all' |
|
| 1071 | - * @param string $order Sort order by : 'position', 'code', 'rowid'... |
|
| 1072 | - * @param int $option 0=Return array id->label, 1=Return array code->label |
|
| 1073 | - * @param int $activeonly 0=all status of contact, 1=only the active |
|
| 1074 | - * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
|
| 1075 | - * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
|
| 1076 | - */ |
|
| 1077 | - function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1078 | - {
|
|
| 1079 | - // phpcs:enable |
|
| 1080 | - global $langs; |
|
| 1081 | - |
|
| 1082 | - if (empty($order)) $order='position'; |
|
| 1083 | - if ($order == 'position') $order.=',code'; |
|
| 1084 | - |
|
| 1085 | - $tab = array(); |
|
| 1086 | - $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
|
| 1087 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1088 | - $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1089 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1090 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1091 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1092 | - $sql.= $this->db->order($order,'ASC'); |
|
| 1093 | - |
|
| 1094 | - //print "sql=".$sql; |
|
| 1095 | - $resql=$this->db->query($sql); |
|
| 1096 | - if ($resql) |
|
| 1097 | - {
|
|
| 1098 | - $num=$this->db->num_rows($resql); |
|
| 1099 | - $i=0; |
|
| 1100 | - while ($i < $num) |
|
| 1101 | - {
|
|
| 1102 | - $obj = $this->db->fetch_object($resql); |
|
| 1103 | - |
|
| 1104 | - $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1105 | - $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1106 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1107 | - else $tab[$obj->code]=$libelle_type; |
|
| 1108 | - $i++; |
|
| 1109 | - } |
|
| 1110 | - return $tab; |
|
| 1111 | - } |
|
| 1112 | - else |
|
| 1113 | - {
|
|
| 1114 | - $this->error=$this->db->lasterror(); |
|
| 1115 | - //dol_print_error($this->db); |
|
| 1116 | - return null; |
|
| 1117 | - } |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - /** |
|
| 1121 | - * Return id of contacts for a source and a contact code. |
|
| 1122 | - * Example: contact client de facturation ('external', 'BILLING')
|
|
| 1123 | - * Example: contact client de livraison ('external', 'SHIPPING')
|
|
| 1124 | - * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL')
|
|
| 1125 | - * |
|
| 1126 | - * @param string $source 'external' or 'internal' |
|
| 1127 | - * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... |
|
| 1128 | - * @param int $status limited to a certain status |
|
| 1129 | - * @return array List of id for such contacts |
|
| 1130 | - */ |
|
| 1131 | - function getIdContact($source,$code,$status=0) |
|
| 1132 | - {
|
|
| 1133 | - global $conf; |
|
| 1134 | - |
|
| 1135 | - $result=array(); |
|
| 1136 | - $i=0; |
|
| 1137 | - //cas particulier pour les expeditions |
|
| 1138 | - if($this->element=='shipping' && $this->origin_id != 0) {
|
|
| 1139 | - $id=$this->origin_id; |
|
| 1140 | - $element='commande'; |
|
| 1141 | - } else if($this->element=='reception' && $this->origin_id != 0) {
|
|
| 1142 | - $id=$this->origin_id; |
|
| 1143 | - $element='order_supplier'; |
|
| 1144 | - } else {
|
|
| 1145 | - $id=$this->id; |
|
| 1146 | - $element=$this->element; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - $sql = "SELECT ec.fk_socpeople"; |
|
| 1150 | - $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1151 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1152 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1153 | - $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1154 | - $sql.= " WHERE ec.element_id = ".$id; |
|
| 1155 | - $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
| 1156 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1157 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1158 | - $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1159 | - $sql.= " AND tc.element = '".$element."'"; |
|
| 1160 | - $sql.= " AND tc.source = '".$source."'"; |
|
| 1161 | - $sql.= " AND tc.code = '".$code."'"; |
|
| 1162 | - $sql.= " AND tc.active = 1"; |
|
| 1163 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1164 | - |
|
| 1165 | - dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
| 1166 | - $resql=$this->db->query($sql); |
|
| 1167 | - if ($resql) |
|
| 1168 | - {
|
|
| 1169 | - while ($obj = $this->db->fetch_object($resql)) |
|
| 1170 | - {
|
|
| 1171 | - $result[$i]=$obj->fk_socpeople; |
|
| 1172 | - $i++; |
|
| 1173 | - } |
|
| 1174 | - } |
|
| 1175 | - else |
|
| 1176 | - {
|
|
| 1177 | - $this->error=$this->db->error(); |
|
| 1178 | - return null; |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return $result; |
|
| 1182 | - } |
|
| 163 | + /** |
|
| 164 | + * @var string The object's next reference |
|
| 165 | + */ |
|
| 166 | + public $ref_next; |
|
| 1183 | 167 | |
| 1184 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1185 | - /** |
|
| 1186 | - * Load object contact with id=$this->contactid into $this->contact |
|
| 1187 | - * |
|
| 1188 | - * @param int $contactid Id du contact. Use this->contactid if empty. |
|
| 1189 | - * @return int <0 if KO, >0 if OK |
|
| 1190 | - */ |
|
| 1191 | - function fetch_contact($contactid=null) |
|
| 1192 | - {
|
|
| 1193 | - // phpcs:enable |
|
| 1194 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 168 | + /** |
|
| 169 | + * @var string An external reference for the object |
|
| 170 | + */ |
|
| 171 | + public $ref_ext; |
|
| 1195 | 172 | |
| 1196 | - if (empty($contactid)) return 0; |
|
| 173 | + /** |
|
| 174 | + * @var int The object's status |
|
| 175 | + * @see setStatut() |
|
| 176 | + */ |
|
| 177 | + public $statut; |
|
| 1197 | 178 | |
| 1198 | - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 1199 | - $contact = new Contact($this->db); |
|
| 1200 | - $result=$contact->fetch($contactid); |
|
| 1201 | - $this->contact = $contact; |
|
| 1202 | - return $result; |
|
| 1203 | - } |
|
| 179 | + /** |
|
| 180 | + * @var string |
|
| 181 | + * @see getFullAddress() |
|
| 182 | + */ |
|
| 183 | + public $country; |
|
| 1204 | 184 | |
| 1205 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1206 | - /** |
|
| 1207 | - * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty |
|
| 1208 | - * |
|
| 1209 | - * @param int $force_thirdparty_id Force thirdparty id |
|
| 1210 | - * @return int <0 if KO, >0 if OK |
|
| 1211 | - */ |
|
| 1212 | - function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1213 | - {
|
|
| 1214 | - // phpcs:enable |
|
| 1215 | - global $conf; |
|
| 185 | + /** |
|
| 186 | + * @var int |
|
| 187 | + * @see getFullAddress(), country |
|
| 188 | + */ |
|
| 189 | + public $country_id; |
|
| 1216 | 190 | |
| 1217 | - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1218 | - return 0; |
|
| 191 | + /** |
|
| 192 | + * @var string |
|
| 193 | + * @see getFullAddress(), isInEEC(), country |
|
| 194 | + */ |
|
| 195 | + public $country_code; |
|
| 1219 | 196 | |
| 1220 | - require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 197 | + /** |
|
| 198 | + * @var string |
|
| 199 | + * @see getFullAddress() |
|
| 200 | + */ |
|
| 201 | + public $state; |
|
| 1221 | 202 | |
| 1222 | - $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
|
| 1223 | - if ($force_thirdparty_id) |
|
| 1224 | - $idtofetch = $force_thirdparty_id; |
|
| 203 | + /** |
|
| 204 | + * @var int |
|
| 205 | + * @see getFullAddress(), state |
|
| 206 | + */ |
|
| 207 | + public $state_id; |
|
| 1225 | 208 | |
| 1226 | - if ($idtofetch) {
|
|
| 1227 | - $thirdparty = new Societe($this->db); |
|
| 1228 | - $result = $thirdparty->fetch($idtofetch); |
|
| 1229 | - $this->thirdparty = $thirdparty; |
|
| 209 | + /** |
|
| 210 | + * @var string |
|
| 211 | + * @see getFullAddress(), state |
|
| 212 | + */ |
|
| 213 | + public $state_code; |
|
| 1230 | 214 | |
| 1231 | - // Use first price level if level not defined for third party |
|
| 1232 | - if (!empty(Globals::$conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) {
|
|
| 1233 | - $this->thirdparty->price_level = 1; |
|
| 1234 | - } |
|
| 215 | + /** |
|
| 216 | + * @var string |
|
| 217 | + * @see getFullAddress(), region |
|
| 218 | + */ |
|
| 219 | + public $region; |
|
| 1235 | 220 | |
| 1236 | - return $result; |
|
| 1237 | - } else |
|
| 1238 | - return -1; |
|
| 1239 | - } |
|
| 221 | + /** |
|
| 222 | + * @var string |
|
| 223 | + * @see getFullAddress(), region |
|
| 224 | + */ |
|
| 225 | + public $region_code; |
|
| 1240 | 226 | |
| 227 | + /** |
|
| 228 | + * @var int |
|
| 229 | + * @see fetch_barcode() |
|
| 230 | + */ |
|
| 231 | + public $barcode_type; |
|
| 1241 | 232 | |
| 1242 | - /** |
|
| 1243 | - * Looks for an object with ref matching the wildcard provided |
|
| 1244 | - * It does only work when $this->table_ref_field is set |
|
| 1245 | - * |
|
| 1246 | - * @param string $ref Wildcard |
|
| 1247 | - * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO |
|
| 1248 | - */ |
|
| 1249 | - public function fetchOneLike($ref) |
|
| 1250 | - {
|
|
| 1251 | - if (!$this->table_ref_field) {
|
|
| 1252 | - return 0; |
|
| 1253 | - } |
|
| 233 | + /** |
|
| 234 | + * @var string |
|
| 235 | + * @see fetch_barcode(), barcode_type |
|
| 236 | + */ |
|
| 237 | + public $barcode_type_code; |
|
| 1254 | 238 | |
| 1255 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
| 239 | + /** |
|
| 240 | + * @var string |
|
| 241 | + * @see fetch_barcode(), barcode_type |
|
| 242 | + */ |
|
| 243 | + public $barcode_type_label; |
|
| 1256 | 244 | |
| 1257 | - $query = $this->db->query($sql); |
|
| 245 | + /** |
|
| 246 | + * @var string |
|
| 247 | + * @see fetch_barcode(), barcode_type |
|
| 248 | + */ |
|
| 249 | + public $barcode_type_coder; |
|
| 1258 | 250 | |
| 1259 | - if (!$this->db->num_rows($query)) {
|
|
| 1260 | - return 0; |
|
| 1261 | - } |
|
| 251 | + /** |
|
| 252 | + * @var int Payment method ID (cheque, cash, ...) |
|
| 253 | + * @see setPaymentMethods() |
|
| 254 | + */ |
|
| 255 | + public $mode_reglement_id; |
|
| 1262 | 256 | |
| 1263 | - $result = $this->db->fetch_object($query); |
|
| 257 | + /** |
|
| 258 | + * @var int Payment terms ID |
|
| 259 | + * @see setPaymentTerms() |
|
| 260 | + */ |
|
| 261 | + public $cond_reglement_id; |
|
| 1264 | 262 | |
| 1265 | - return $this->fetch($result->rowid); |
|
| 1266 | - } |
|
| 263 | + /** |
|
| 264 | + * @var int Payment terms ID |
|
| 265 | + * @deprecated Kept for compatibility |
|
| 266 | + * @see cond_reglement_id; |
|
| 267 | + */ |
|
| 268 | + public $cond_reglement; |
|
| 1267 | 269 | |
| 1268 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1269 | - /** |
|
| 1270 | - * Load data for barcode into properties ->barcode_type* |
|
| 1271 | - * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but |
|
| 1272 | - * if it is not defined, ->element must be defined to know default barcode type. |
|
| 1273 | - * |
|
| 1274 | - * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) |
|
| 1275 | - */ |
|
| 1276 | - function fetch_barcode() |
|
| 1277 | - {
|
|
| 1278 | - // phpcs:enable |
|
| 1279 | - global $conf; |
|
| 270 | + /** |
|
| 271 | + * @var int Delivery address ID |
|
| 272 | + * @deprecated |
|
| 273 | + * @see setDeliveryAddress() |
|
| 274 | + */ |
|
| 275 | + public $fk_delivery_address; |
|
| 1280 | 276 | |
| 1281 | - dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
| 277 | + /** |
|
| 278 | + * @var int Shipping method ID |
|
| 279 | + * @see setShippingMethod() |
|
| 280 | + */ |
|
| 281 | + public $shipping_method_id; |
|
| 1282 | 282 | |
| 1283 | - $idtype=$this->barcode_type; |
|
| 1284 | - 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 |
|
| 1285 | - {
|
|
| 1286 | - if ($this->element == 'product') |
|
| 1287 | - $idtype = Globals::$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1288 | - else if ($this->element == 'societe') |
|
| 1289 | - $idtype = Globals::$conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1290 | - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
|
|
| 1291 | - } |
|
| 283 | + /** |
|
| 284 | + * @var string |
|
| 285 | + * @see SetDocModel() |
|
| 286 | + */ |
|
| 287 | + public $modelpdf; |
|
| 1292 | 288 | |
| 1293 | - if ($idtype > 0) |
|
| 1294 | - {
|
|
| 1295 | - 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 |
|
| 1296 | - {
|
|
| 1297 | - $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1298 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1299 | - $sql.= " WHERE rowid = ".$idtype; |
|
| 1300 | - dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
| 1301 | - $resql = $this->db->query($sql); |
|
| 1302 | - if ($resql) |
|
| 1303 | - {
|
|
| 1304 | - $obj = $this->db->fetch_object($resql); |
|
| 1305 | - $this->barcode_type = $obj->rowid; |
|
| 1306 | - $this->barcode_type_code = $obj->code; |
|
| 1307 | - $this->barcode_type_label = $obj->label; |
|
| 1308 | - $this->barcode_type_coder = $obj->coder; |
|
| 1309 | - return 1; |
|
| 1310 | - } |
|
| 1311 | - else |
|
| 1312 | - {
|
|
| 1313 | - dol_print_error($this->db); |
|
| 1314 | - return -1; |
|
| 1315 | - } |
|
| 1316 | - } |
|
| 1317 | - } |
|
| 1318 | - return 0; |
|
| 1319 | - } |
|
| 289 | + /** |
|
| 290 | + * @var int Bank account ID |
|
| 291 | + * @see SetBankAccount() |
|
| 292 | + */ |
|
| 293 | + public $fk_account; |
|
| 1320 | 294 | |
| 1321 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1322 | - /** |
|
| 1323 | - * Load the project with id $this->fk_project into this->project |
|
| 1324 | - * |
|
| 1325 | - * @return int <0 if KO, >=0 if OK |
|
| 1326 | - */ |
|
| 1327 | - function fetch_projet() |
|
| 1328 | - {
|
|
| 1329 | - // phpcs:enable |
|
| 1330 | - include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 295 | + /** |
|
| 296 | + * @var string Public note |
|
| 297 | + * @see update_note() |
|
| 298 | + */ |
|
| 299 | + public $note_public; |
|
| 1331 | 300 | |
| 1332 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1333 | - if (empty($this->fk_project)) return 0; |
|
| 301 | + /** |
|
| 302 | + * @var string Private note |
|
| 303 | + * @see update_note() |
|
| 304 | + */ |
|
| 305 | + public $note_private; |
|
| 1334 | 306 | |
| 1335 | - $project = new Project($this->db); |
|
| 1336 | - $result = $project->fetch($this->fk_project); |
|
| 307 | + /** |
|
| 308 | + * @deprecated |
|
| 309 | + * @see note_public |
|
| 310 | + */ |
|
| 311 | + public $note; |
|
| 1337 | 312 | |
| 1338 | - $this->projet = $project; // deprecated |
|
| 1339 | - $this->project = $project; |
|
| 1340 | - return $result; |
|
| 1341 | - } |
|
| 313 | + /** |
|
| 314 | + * @var float Total amount before taxes |
|
| 315 | + * @see update_price() |
|
| 316 | + */ |
|
| 317 | + public $total_ht; |
|
| 1342 | 318 | |
| 1343 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1344 | - /** |
|
| 1345 | - * Load the product with id $this->fk_product into this->product |
|
| 1346 | - * |
|
| 1347 | - * @return int <0 if KO, >=0 if OK |
|
| 1348 | - */ |
|
| 1349 | - function fetch_product() |
|
| 1350 | - {
|
|
| 1351 | - // phpcs:enable |
|
| 1352 | - include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 319 | + /** |
|
| 320 | + * @var float Total VAT amount |
|
| 321 | + * @see update_price() |
|
| 322 | + */ |
|
| 323 | + public $total_tva; |
|
| 1353 | 324 | |
| 1354 | - if (empty($this->fk_product)) return 0; |
|
| 325 | + /** |
|
| 326 | + * @var float Total local tax 1 amount |
|
| 327 | + * @see update_price() |
|
| 328 | + */ |
|
| 329 | + public $total_localtax1; |
|
| 1355 | 330 | |
| 1356 | - $product = new Product($this->db); |
|
| 1357 | - $result = $product->fetch($this->fk_product); |
|
| 331 | + /** |
|
| 332 | + * @var float Total local tax 2 amount |
|
| 333 | + * @see update_price() |
|
| 334 | + */ |
|
| 335 | + public $total_localtax2; |
|
| 1358 | 336 | |
| 1359 | - $this->product = $product; |
|
| 1360 | - return $result; |
|
| 1361 | - } |
|
| 337 | + /** |
|
| 338 | + * @var float Total amount with taxes |
|
| 339 | + * @see update_price() |
|
| 340 | + */ |
|
| 341 | + public $total_ttc; |
|
| 1362 | 342 | |
| 1363 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1364 | - /** |
|
| 1365 | - * Load the user with id $userid into this->user |
|
| 1366 | - * |
|
| 1367 | - * @param int $userid Id du contact |
|
| 1368 | - * @return int <0 if KO, >0 if OK |
|
| 1369 | - */ |
|
| 1370 | - function fetch_user($userid) |
|
| 1371 | - {
|
|
| 1372 | - // phpcs:enable |
|
| 1373 | - $user = new User($this->db); |
|
| 1374 | - $result=$user->fetch($userid); |
|
| 1375 | - $this->user = $user; |
|
| 1376 | - return $result; |
|
| 1377 | - } |
|
| 343 | + /** |
|
| 344 | + * @var CommonObjectLine[] |
|
| 345 | + */ |
|
| 346 | + public $lines; |
|
| 1378 | 347 | |
| 1379 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1380 | - /** |
|
| 1381 | - * Read linked origin object |
|
| 1382 | - * |
|
| 1383 | - * @return void |
|
| 1384 | - */ |
|
| 1385 | - function fetch_origin() |
|
| 1386 | - {
|
|
| 1387 | - // phpcs:enable |
|
| 1388 | - if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1389 | - if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1390 | - if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 348 | + /** |
|
| 349 | + * @var mixed Contains comments |
|
| 350 | + * @see fetchComments() |
|
| 351 | + */ |
|
| 352 | + public $comments=array(); |
|
| 1391 | 353 | |
| 1392 | - $origin = $this->origin; |
|
| 354 | + /** |
|
| 355 | + * @var int |
|
| 356 | + * @see setIncoterms() |
|
| 357 | + */ |
|
| 358 | + public $fk_incoterms; |
|
| 1393 | 359 | |
| 1394 | - $classname = ucfirst($origin); |
|
| 1395 | - $this->$origin = new $classname($this->db); |
|
| 1396 | - $this->$origin->fetch($this->origin_id); |
|
| 1397 | - } |
|
| 360 | + /** |
|
| 361 | + * @var string |
|
| 362 | + * @see SetIncoterms() |
|
| 363 | + */ |
|
| 364 | + public $libelle_incoterms; |
|
| 1398 | 365 | |
| 1399 | - /** |
|
| 1400 | - * Load object from specific field |
|
| 1401 | - * |
|
| 1402 | - * @param string $table Table element or element line |
|
| 1403 | - * @param string $field Field selected |
|
| 1404 | - * @param string $key Import key |
|
| 1405 | - * @param string $element Element name |
|
| 1406 | - * @return int <0 if KO, >0 if OK |
|
| 366 | + /** |
|
| 367 | + * @var string |
|
| 368 | + * @see display_incoterms() |
|
| 1407 | 369 | */ |
| 1408 | - function fetchObjectFrom($table, $field, $key, $element = null) |
|
| 1409 | - {
|
|
| 1410 | - global $conf; |
|
| 1411 | - |
|
| 1412 | - $result=false; |
|
| 1413 | - |
|
| 1414 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
| 1415 | - $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1416 | - if (! empty($element)) {
|
|
| 1417 | - $sql.= " AND entity IN (".getEntity($element).")";
|
|
| 1418 | - } else {
|
|
| 1419 | - $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
| 1423 | - $resql = $this->db->query($sql); |
|
| 1424 | - if ($resql) |
|
| 1425 | - {
|
|
| 1426 | - $row = $this->db->fetch_row($resql); |
|
| 1427 | - // Test for avoid error -1 |
|
| 1428 | - if ($row[0] > 0) {
|
|
| 1429 | - $result = $this->fetch($row[0]); |
|
| 1430 | - } |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - return $result; |
|
| 1434 | - } |
|
| 1435 | - |
|
| 1436 | - /** |
|
| 1437 | - * Getter generic. Load value from a specific field |
|
| 1438 | - * |
|
| 1439 | - * @param string $table Table of element or element line |
|
| 1440 | - * @param int $id Element id |
|
| 1441 | - * @param string $field Field selected |
|
| 1442 | - * @return int <0 if KO, >0 if OK |
|
| 1443 | - */ |
|
| 1444 | - function getValueFrom($table, $id, $field) |
|
| 1445 | - {
|
|
| 1446 | - $result=false; |
|
| 1447 | - if (!empty($id) && !empty($field) && !empty($table)) {
|
|
| 1448 | - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
| 1449 | - $sql.= " WHERE rowid = ".$id; |
|
| 1450 | - |
|
| 1451 | - dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
| 1452 | - $resql = $this->db->query($sql); |
|
| 1453 | - if ($resql) |
|
| 1454 | - {
|
|
| 1455 | - $row = $this->db->fetch_row($resql); |
|
| 1456 | - $result = $row[0]; |
|
| 1457 | - } |
|
| 1458 | - } |
|
| 1459 | - return $result; |
|
| 1460 | - } |
|
| 1461 | - |
|
| 1462 | - /** |
|
| 1463 | - * Setter generic. Update a specific field into database. |
|
| 1464 | - * Warning: Trigger is run only if param trigkey is provided. |
|
| 1465 | - * |
|
| 1466 | - * @param string $field Field to update |
|
| 1467 | - * @param mixed $value New value |
|
| 1468 | - * @param string $table To force other table element or element line (should not be used) |
|
| 1469 | - * @param int $id To force other object id (should not be used) |
|
| 1470 | - * @param string $format Data format ('text', 'date'). 'text' is used if not defined
|
|
| 1471 | - * @param string $id_field To force rowid field name. 'rowid' is used if not defined |
|
| 1472 | - * @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' |
|
| 1473 | - * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') |
|
| 1474 | - * @param string $fk_user_field Name of field to save user id making change |
|
| 1475 | - * @return int <0 if KO, >0 if OK |
|
| 1476 | - * @see updateExtraField |
|
| 1477 | - */ |
|
| 1478 | - function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
| 1479 | - {
|
|
| 1480 | - global $user,$langs,$conf; |
|
| 1481 | - |
|
| 1482 | - if (empty($table)) $table=$this->table_element; |
|
| 1483 | - if (empty($id)) $id=$this->id; |
|
| 1484 | - if (empty($format)) $format='text'; |
|
| 1485 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1486 | - |
|
| 1487 | - $error=0; |
|
| 1488 | - |
|
| 1489 | - $this->db->begin(); |
|
| 1490 | - |
|
| 1491 | - // Special case |
|
| 1492 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1493 | - if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
|
| 1494 | - |
|
| 1495 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
| 1496 | - |
|
| 1497 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1498 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1499 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1500 | - |
|
| 1501 | - if ($fk_user_field) |
|
| 1502 | - {
|
|
| 1503 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1504 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1505 | - } |
|
| 1506 | - |
|
| 1507 | - $sql.= " WHERE ".$id_field." = ".$id; |
|
| 1508 | - |
|
| 1509 | - dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
| 1510 | - $resql = $this->db->query($sql); |
|
| 1511 | - if ($resql) |
|
| 1512 | - {
|
|
| 1513 | - if ($trigkey) |
|
| 1514 | - {
|
|
| 1515 | - // call trigger with updated object values |
|
| 1516 | - if (empty($this->fields) && method_exists($this, 'fetch')) |
|
| 1517 | - {
|
|
| 1518 | - $result = $this->fetch($id); |
|
| 1519 | - } |
|
| 1520 | - else |
|
| 1521 | - {
|
|
| 1522 | - $result = $this->fetchCommon($id); |
|
| 1523 | - } |
|
| 1524 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1525 | - if ($result < 0) $error++; |
|
| 1526 | - } |
|
| 370 | + public $location_incoterms; |
|
| 1527 | 371 | |
| 1528 | - if (! $error) |
|
| 1529 | - {
|
|
| 1530 | - if (property_exists($this, $field)) $this->$field = $value; |
|
| 1531 | - $this->db->commit(); |
|
| 1532 | - return 1; |
|
| 1533 | - } |
|
| 1534 | - else |
|
| 1535 | - {
|
|
| 1536 | - $this->db->rollback(); |
|
| 1537 | - return -2; |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1540 | - else |
|
| 1541 | - {
|
|
| 1542 | - $this->error=$this->db->lasterror(); |
|
| 1543 | - $this->db->rollback(); |
|
| 1544 | - return -1; |
|
| 1545 | - } |
|
| 1546 | - } |
|
| 372 | + public $name; |
|
| 373 | + public $lastname; |
|
| 374 | + public $firstname; |
|
| 375 | + public $civility_id; |
|
| 1547 | 376 | |
| 1548 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1549 | - /** |
|
| 1550 | - * Load properties id_previous and id_next by comparing $fieldid with $this->ref |
|
| 1551 | - * |
|
| 1552 | - * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" |
|
| 1553 | - * @param string $fieldid Name of field to use for the select MAX and MIN |
|
| 1554 | - * @param int $nodbprefix Do not include DB prefix to forge table name |
|
| 1555 | - * @return int <0 if KO, >0 if OK |
|
| 1556 | - */ |
|
| 1557 | - function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1558 | - {
|
|
| 1559 | - // phpcs:enable |
|
| 1560 | - global $conf, $user; |
|
| 1561 | - |
|
| 1562 | - if (! $this->table_element) |
|
| 1563 | - {
|
|
| 1564 | - dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
|
| 1565 | - return -1; |
|
| 1566 | - } |
|
| 1567 | - if ($fieldid == 'none') return 1; |
|
| 1568 | - |
|
| 1569 | - // Security on socid |
|
| 1570 | - $socid = 0; |
|
| 1571 | - if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 1572 | - |
|
| 1573 | - // this->ismultientitymanaged contains |
|
| 1574 | - // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
| 1575 | - $alias = 's'; |
|
| 1576 | - if ($this->element == 'societe') $alias = 'te'; |
|
| 1577 | - |
|
| 1578 | - $sql = "SELECT MAX(te.".$fieldid.")"; |
|
| 1579 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1580 | - if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1581 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1582 | - } |
|
| 1583 | - 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 |
|
| 1584 | - 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 |
|
| 1585 | - 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 |
|
| 1586 | - 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"; |
|
| 1587 | - $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1588 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1589 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1590 | - if (! empty($filter)) |
|
| 1591 | - {
|
|
| 1592 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1593 | - $sql.=$filter; |
|
| 1594 | - } |
|
| 1595 | - 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 |
|
| 1596 | - 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 |
|
| 1597 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1598 | - if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1599 | - if (!empty($user->admin) && empty($user->entity) && Globals::$conf->entity == 1) {
|
|
| 1600 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1601 | - } else {
|
|
| 1602 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1603 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1604 | - } |
|
| 1605 | - } else {
|
|
| 1606 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1607 | - } |
|
| 1608 | - } |
|
| 1609 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1610 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1611 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1612 | - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 1613 | - |
|
| 1614 | - $result = $this->db->query($sql); |
|
| 1615 | - if (! $result) |
|
| 1616 | - {
|
|
| 1617 | - $this->error=$this->db->lasterror(); |
|
| 1618 | - return -1; |
|
| 1619 | - } |
|
| 1620 | - $row = $this->db->fetch_row($result); |
|
| 1621 | - $this->ref_previous = $row[0]; |
|
| 1622 | - |
|
| 1623 | - |
|
| 1624 | - $sql = "SELECT MIN(te.".$fieldid.")"; |
|
| 1625 | - $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1626 | - if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1627 | - $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1628 | - } |
|
| 1629 | - 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 |
|
| 1630 | - 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 |
|
| 1631 | - 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 |
|
| 1632 | - 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"; |
|
| 1633 | - $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1634 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1635 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1636 | - if (! empty($filter)) |
|
| 1637 | - {
|
|
| 1638 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1639 | - $sql.=$filter; |
|
| 1640 | - } |
|
| 1641 | - 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 |
|
| 1642 | - 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 |
|
| 1643 | - if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1644 | - if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1645 | - if (!empty($user->admin) && empty($user->entity) && Globals::$conf->entity == 1) {
|
|
| 1646 | - $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1647 | - } else {
|
|
| 1648 | - $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1649 | - $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1650 | - } |
|
| 1651 | - } else {
|
|
| 1652 | - $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1653 | - } |
|
| 1654 | - } |
|
| 1655 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1656 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1657 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1658 | - //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 1659 | - // 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 |
|
| 1660 | - |
|
| 1661 | - $result = $this->db->query($sql); |
|
| 1662 | - if (! $result) |
|
| 1663 | - {
|
|
| 1664 | - $this->error=$this->db->lasterror(); |
|
| 1665 | - return -2; |
|
| 1666 | - } |
|
| 1667 | - $row = $this->db->fetch_row($result); |
|
| 1668 | - $this->ref_next = $row[0]; |
|
| 1669 | - |
|
| 1670 | - return 1; |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - |
|
| 1674 | - /** |
|
| 1675 | - * Return list of id of contacts of object |
|
| 1676 | - * |
|
| 1677 | - * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) |
|
| 1678 | - * @return array Array of id of contacts (if source=external or internal) |
|
| 1679 | - * Array of id of third parties with at least one contact on object (if source=thirdparty) |
|
| 1680 | - */ |
|
| 1681 | - function getListContactId($source='external') |
|
| 1682 | - {
|
|
| 1683 | - $contactAlreadySelected = array(); |
|
| 1684 | - $tab = $this->liste_contact(-1,$source); |
|
| 1685 | - $num=count($tab); |
|
| 1686 | - $i = 0; |
|
| 1687 | - while ($i < $num) |
|
| 1688 | - {
|
|
| 1689 | - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1690 | - else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1691 | - $i++; |
|
| 1692 | - } |
|
| 1693 | - return $contactAlreadySelected; |
|
| 1694 | - } |
|
| 1695 | - |
|
| 1696 | - |
|
| 1697 | - /** |
|
| 1698 | - * Link element with a project |
|
| 1699 | - * |
|
| 1700 | - * @param int $projectid Project id to link element to |
|
| 1701 | - * @return int <0 if KO, >0 if OK |
|
| 1702 | - */ |
|
| 1703 | - function setProject($projectid) |
|
| 1704 | - {
|
|
| 1705 | - if (! $this->table_element) |
|
| 1706 | - {
|
|
| 1707 | - dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1708 | - return -1; |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1712 | - if ($this->table_element == 'actioncomm') |
|
| 1713 | - {
|
|
| 1714 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1715 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1716 | - $sql.= ' WHERE id = '.$this->id; |
|
| 1717 | - } |
|
| 1718 | - else |
|
| 1719 | - {
|
|
| 1720 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1721 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1722 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 1723 | - } |
|
| 1724 | - |
|
| 1725 | - dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
| 1726 | - if ($this->db->query($sql)) |
|
| 1727 | - {
|
|
| 1728 | - $this->fk_project = $projectid; |
|
| 1729 | - return 1; |
|
| 1730 | - } |
|
| 1731 | - else |
|
| 1732 | - {
|
|
| 1733 | - dol_print_error($this->db); |
|
| 1734 | - return -1; |
|
| 1735 | - } |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - /** |
|
| 1739 | - * Change the payments methods |
|
| 1740 | - * |
|
| 1741 | - * @param int $id Id of new payment method |
|
| 1742 | - * @return int >0 if OK, <0 if KO |
|
| 1743 | - */ |
|
| 1744 | - function setPaymentMethods($id) |
|
| 1745 | - {
|
|
| 1746 | - dol_syslog(get_class($this).'::setPaymentMethods('.$id.')');
|
|
| 1747 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1748 | - {
|
|
| 1749 | - // TODO uniformize field name |
|
| 1750 | - $fieldname = 'fk_mode_reglement'; |
|
| 1751 | - if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1752 | - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 1753 | - |
|
| 1754 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1755 | - $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1756 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1757 | - |
|
| 1758 | - if ($this->db->query($sql)) |
|
| 1759 | - {
|
|
| 1760 | - $this->mode_reglement_id = $id; |
|
| 1761 | - // for supplier |
|
| 1762 | - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1763 | - return 1; |
|
| 1764 | - } |
|
| 1765 | - else |
|
| 1766 | - {
|
|
| 1767 | - dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
| 1768 | - $this->error=$this->db->error(); |
|
| 1769 | - return -1; |
|
| 1770 | - } |
|
| 1771 | - } |
|
| 1772 | - else |
|
| 1773 | - {
|
|
| 1774 | - dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
| 1775 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1776 | - return -2; |
|
| 1777 | - } |
|
| 1778 | - } |
|
| 1779 | - |
|
| 1780 | - /** |
|
| 1781 | - * Change the multicurrency code |
|
| 1782 | - * |
|
| 1783 | - * @param string $code multicurrency code |
|
| 1784 | - * @return int >0 if OK, <0 if KO |
|
| 1785 | - */ |
|
| 1786 | - function setMulticurrencyCode($code) |
|
| 1787 | - {
|
|
| 1788 | - dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')');
|
|
| 1789 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1790 | - {
|
|
| 1791 | - $fieldname = 'multicurrency_code'; |
|
| 1792 | - |
|
| 1793 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1794 | - $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
| 1795 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1796 | - |
|
| 1797 | - if ($this->db->query($sql)) |
|
| 1798 | - {
|
|
| 1799 | - $this->multicurrency_code = $code; |
|
| 377 | + // Dates |
|
| 378 | + public $date_creation; // Date creation |
|
| 379 | + public $date_validation; // Date validation |
|
| 380 | + public $date_modification; // Date last change (tms field) |
|
| 1800 | 381 | |
| 1801 | - list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
|
| 1802 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 1803 | 382 | |
| 1804 | - return 1; |
|
| 1805 | - } |
|
| 1806 | - else |
|
| 1807 | - {
|
|
| 1808 | - dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
| 1809 | - $this->error=$this->db->error(); |
|
| 1810 | - return -1; |
|
| 1811 | - } |
|
| 1812 | - } |
|
| 1813 | - else |
|
| 1814 | - {
|
|
| 1815 | - dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
| 1816 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1817 | - return -2; |
|
| 1818 | - } |
|
| 1819 | - } |
|
| 1820 | - |
|
| 1821 | - /** |
|
| 1822 | - * Change the multicurrency rate |
|
| 1823 | - * |
|
| 1824 | - * @param double $rate multicurrency rate |
|
| 1825 | - * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
|
| 1826 | - * @return int >0 if OK, <0 if KO |
|
| 1827 | - */ |
|
| 1828 | - function setMulticurrencyRate($rate, $mode=1) |
|
| 1829 | - {
|
|
| 1830 | - dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')');
|
|
| 1831 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1832 | - {
|
|
| 1833 | - $fieldname = 'multicurrency_tx'; |
|
| 1834 | - |
|
| 1835 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1836 | - $sql .= ' SET '.$fieldname.' = '.$rate; |
|
| 1837 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1838 | - |
|
| 1839 | - if ($this->db->query($sql)) |
|
| 1840 | - {
|
|
| 1841 | - $this->multicurrency_tx = $rate; |
|
| 1842 | 383 | |
| 1843 | - // Update line price |
|
| 1844 | - if (!empty($this->lines)) |
|
| 1845 | - {
|
|
| 1846 | - foreach ($this->lines as &$line) |
|
| 1847 | - {
|
|
| 1848 | - if($mode == 1) {
|
|
| 1849 | - $line->subprice = 0; |
|
| 1850 | - } |
|
| 384 | + // No constructor as it is an abstract class |
|
| 1851 | 385 | |
| 1852 | - switch ($this->element) {
|
|
| 1853 | - case 'propal': |
|
| 1854 | - $this->updateline( |
|
| 1855 | - $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1856 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1857 | - $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
|
| 1858 | - $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1859 | - ); |
|
| 1860 | - break; |
|
| 1861 | - case 'commande': |
|
| 1862 | - $this->updateline( |
|
| 1863 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1864 | - $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
|
| 1865 | - $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1866 | - $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1867 | - ); |
|
| 1868 | - break; |
|
| 1869 | - case 'facture': |
|
| 1870 | - $this->updateline( |
|
| 1871 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1872 | - $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
|
| 1873 | - $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1874 | - $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
|
| 1875 | - ); |
|
| 1876 | - break; |
|
| 1877 | - case 'supplier_proposal': |
|
| 1878 | - $this->updateline( |
|
| 1879 | - $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1880 | - ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1881 | - $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
|
| 1882 | - $line->ref_fourn, $line->multicurrency_subprice |
|
| 1883 | - ); |
|
| 1884 | - break; |
|
| 1885 | - case 'order_supplier': |
|
| 1886 | - $this->updateline( |
|
| 1887 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1888 | - $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
|
| 1889 | - $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1890 | - ); |
|
| 1891 | - break; |
|
| 1892 | - case 'invoice_supplier': |
|
| 1893 | - $this->updateline( |
|
| 1894 | - $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1895 | - $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
|
| 1896 | - $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1897 | - ); |
|
| 1898 | - break; |
|
| 1899 | - default: |
|
| 1900 | - dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
| 1901 | - break; |
|
| 1902 | - } |
|
| 1903 | - } |
|
| 1904 | - } |
|
| 386 | + /** |
|
| 387 | + * Check an object id/ref exists |
|
| 388 | + * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch |
|
| 389 | + * |
|
| 390 | + * @param string $element String of element ('product', 'facture', ...)
|
|
| 391 | + * @param int $id Id of object |
|
| 392 | + * @param string $ref Ref of object to check |
|
| 393 | + * @param string $ref_ext Ref ext of object to check |
|
| 394 | + * @return int <0 if KO, 0 if OK but not found, >0 if OK and exists |
|
| 395 | + */ |
|
| 396 | + static function isExistingObject($element, $id, $ref='', $ref_ext='') |
|
| 397 | + {
|
|
| 398 | + global $db,$conf; |
|
| 399 | + |
|
| 400 | + $sql = "SELECT rowid, ref, ref_ext"; |
|
| 401 | + $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
|
| 402 | + $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
|
| 403 | + |
|
| 404 | + if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 405 | + else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 406 | + else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 407 | + else {
|
|
| 408 | + $error='ErrorWrongParameters'; |
|
| 409 | + dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
|
| 410 | + return -1; |
|
| 411 | + } |
|
| 412 | + if ($ref || $ref_ext) |
|
| 413 | + $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 1905 | 414 | |
| 1906 | - return 1; |
|
| 1907 | - } |
|
| 1908 | - else |
|
| 1909 | - {
|
|
| 1910 | - dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
| 1911 | - $this->error=$this->db->error(); |
|
| 1912 | - return -1; |
|
| 1913 | - } |
|
| 1914 | - } |
|
| 1915 | - else |
|
| 1916 | - {
|
|
| 1917 | - dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
| 1918 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1919 | - return -2; |
|
| 1920 | - } |
|
| 1921 | - } |
|
| 1922 | - |
|
| 1923 | - /** |
|
| 1924 | - * Change the payments terms |
|
| 1925 | - * |
|
| 1926 | - * @param int $id Id of new payment terms |
|
| 1927 | - * @return int >0 if OK, <0 if KO |
|
| 1928 | - */ |
|
| 1929 | - function setPaymentTerms($id) |
|
| 1930 | - {
|
|
| 1931 | - dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
|
|
| 1932 | - if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1933 | - {
|
|
| 1934 | - // TODO uniformize field name |
|
| 1935 | - $fieldname = 'fk_cond_reglement'; |
|
| 1936 | - if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1937 | - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 1938 | - |
|
| 1939 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1940 | - $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1941 | - $sql .= ' WHERE rowid='.$this->id; |
|
| 1942 | - |
|
| 1943 | - if ($this->db->query($sql)) |
|
| 1944 | - {
|
|
| 1945 | - $this->cond_reglement_id = $id; |
|
| 1946 | - // for supplier |
|
| 1947 | - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 1948 | - $this->cond_reglement = $id; // for compatibility |
|
| 1949 | - return 1; |
|
| 1950 | - } |
|
| 1951 | - else |
|
| 1952 | - {
|
|
| 1953 | - dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
| 1954 | - $this->error=$this->db->error(); |
|
| 1955 | - return -1; |
|
| 1956 | - } |
|
| 1957 | - } |
|
| 1958 | - else |
|
| 1959 | - {
|
|
| 1960 | - dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
| 1961 | - $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1962 | - return -2; |
|
| 1963 | - } |
|
| 1964 | - } |
|
| 1965 | - |
|
| 1966 | - /** |
|
| 1967 | - * Define delivery address |
|
| 1968 | - * @deprecated |
|
| 1969 | - * |
|
| 1970 | - * @param int $id Address id |
|
| 1971 | - * @return int <0 si ko, >0 si ok |
|
| 1972 | - */ |
|
| 1973 | - function setDeliveryAddress($id) |
|
| 1974 | - {
|
|
| 1975 | - $fieldname = 'fk_delivery_address'; |
|
| 1976 | - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 1977 | - |
|
| 1978 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
| 1979 | - $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 1980 | - |
|
| 1981 | - if ($this->db->query($sql)) |
|
| 1982 | - {
|
|
| 1983 | - $this->fk_delivery_address = $id; |
|
| 1984 | - return 1; |
|
| 1985 | - } |
|
| 1986 | - else |
|
| 1987 | - {
|
|
| 1988 | - $this->error=$this->db->error(); |
|
| 1989 | - dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
| 1990 | - return -1; |
|
| 1991 | - } |
|
| 1992 | - } |
|
| 1993 | - |
|
| 1994 | - |
|
| 1995 | - /** |
|
| 1996 | - * Change the shipping method |
|
| 1997 | - * |
|
| 1998 | - * @param int $shipping_method_id Id of shipping method |
|
| 1999 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 2000 | - * @param User $userused Object user |
|
| 2001 | - * |
|
| 2002 | - * @return int 1 if OK, 0 if KO |
|
| 2003 | - */ |
|
| 2004 | - function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 2005 | - {
|
|
| 2006 | - global $user; |
|
| 415 | + dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
|
| 416 | + $resql = $db->query($sql); |
|
| 417 | + if ($resql) |
|
| 418 | + {
|
|
| 419 | + $num=$db->num_rows($resql); |
|
| 420 | + if ($num > 0) return 1; |
|
| 421 | + else return 0; |
|
| 422 | + } |
|
| 423 | + return -1; |
|
| 424 | + } |
|
| 2007 | 425 | |
| 2008 | - if (empty($userused)) $userused=$user; |
|
| 426 | + /** |
|
| 427 | + * Method to output saved errors |
|
| 428 | + * |
|
| 429 | + * @return string String with errors |
|
| 430 | + */ |
|
| 431 | + function errorsToString() |
|
| 432 | + {
|
|
| 433 | + return $this->error.(is_array($this->errors)?(($this->error!=''?', ':'').join(', ',$this->errors)):'');
|
|
| 434 | + } |
|
| 2009 | 435 | |
| 2010 | - $error = 0; |
|
| 436 | + /** |
|
| 437 | + * Return full name (civility+' '+name+' '+lastname) |
|
| 438 | + * |
|
| 439 | + * @param Translate $langs Language object for translation of civility (used only if option is 1) |
|
| 440 | + * @param int $option 0=No option, 1=Add civility |
|
| 441 | + * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname |
|
| 442 | + * @param int $maxlen Maximum length |
|
| 443 | + * @return string String with full name |
|
| 444 | + */ |
|
| 445 | + function getFullName($langs,$option=0,$nameorder=-1,$maxlen=0) |
|
| 446 | + {
|
|
| 447 | + //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
|
| 448 | + $lastname=$this->lastname; |
|
| 449 | + $firstname=$this->firstname; |
|
| 450 | + 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:''))))); |
|
| 2011 | 451 | |
| 2012 | - if (! $this->table_element) {
|
|
| 2013 | - dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 2014 | - return -1; |
|
| 2015 | - } |
|
| 452 | + $ret=''; |
|
| 453 | + if ($option && $this->civility_id) |
|
| 454 | + {
|
|
| 455 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 456 | + else $ret.=$this->civility_id.' '; |
|
| 457 | + } |
|
| 2016 | 458 | |
| 2017 | - $this->db->begin(); |
|
| 459 | + $ret .= AlDolUtils::dolGetFirstLastname($firstname, $lastname, $nameorder); |
|
| 2018 | 460 | |
| 2019 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2020 | - dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
|
| 461 | + return AlDolUtils::dol_trunc($ret, $maxlen); |
|
| 462 | + } |
|
| 2021 | 463 | |
| 2022 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2023 | - $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2024 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2025 | - $resql = $this->db->query($sql); |
|
| 2026 | - if (! $resql) {
|
|
| 2027 | - dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
| 2028 | - $this->error = $this->db->lasterror(); |
|
| 2029 | - $error++; |
|
| 2030 | - } else {
|
|
| 2031 | - if (!$notrigger) |
|
| 2032 | - {
|
|
| 2033 | - // Call trigger |
|
| 2034 | - $this->context=array('shippingmethodupdate'=>1);
|
|
| 2035 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2036 | - if ($result < 0) $error++; |
|
| 2037 | - // End call trigger |
|
| 2038 | - } |
|
| 2039 | - } |
|
| 2040 | - if ($error) |
|
| 464 | + /** |
|
| 465 | + * Return full address of contact |
|
| 466 | + * |
|
| 467 | + * @param int $withcountry 1=Add country into address string |
|
| 468 | + * @param string $sep Separator to use to build string |
|
| 469 | + * @param int $withregion 1=Add region into address string |
|
| 470 | + * @return string Full address string |
|
| 471 | + */ |
|
| 472 | + function getFullAddress($withcountry=0, $sep="\n", $withregion=0) |
|
| 473 | + {
|
|
| 474 | + if ($withcountry && $this->country_id && (empty($this->country_code) || empty($this->country))) |
|
| 2041 | 475 | {
|
| 2042 | - $this->db->rollback(); |
|
| 2043 | - return -1; |
|
| 2044 | - } else {
|
|
| 2045 | - $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 2046 | - $this->db->commit(); |
|
| 2047 | - return 1; |
|
| 476 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 477 | + $tmparray=getCountry($this->country_id,'all'); |
|
| 478 | + $this->country_code=$tmparray['code']; |
|
| 479 | + $this->country =$tmparray['label']; |
|
| 2048 | 480 | } |
| 2049 | - } |
|
| 2050 | - |
|
| 2051 | - |
|
| 2052 | - /** |
|
| 2053 | - * Change the warehouse |
|
| 2054 | - * |
|
| 2055 | - * @param int $warehouse_id Id of warehouse |
|
| 2056 | - * @return int 1 if OK, 0 if KO |
|
| 2057 | - */ |
|
| 2058 | - function setWarehouse($warehouse_id) |
|
| 2059 | - {
|
|
| 2060 | - if (! $this->table_element) {
|
|
| 2061 | - dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 2062 | - return -1; |
|
| 2063 | - } |
|
| 2064 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2065 | - dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
|
| 2066 | - |
|
| 2067 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2068 | - $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 2069 | - $sql.= " WHERE rowid=".$this->id; |
|
| 2070 | - |
|
| 2071 | - if ($this->db->query($sql)) {
|
|
| 2072 | - $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 2073 | - return 1; |
|
| 2074 | - } else {
|
|
| 2075 | - dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
| 2076 | - $this->error=$this->db->error(); |
|
| 2077 | - return 0; |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - |
|
| 2081 | - |
|
| 2082 | - /** |
|
| 2083 | - * Set last model used by doc generator |
|
| 2084 | - * |
|
| 2085 | - * @param User $user User object that make change |
|
| 2086 | - * @param string $modelpdf Modele name |
|
| 2087 | - * @return int <0 if KO, >0 if OK |
|
| 2088 | - */ |
|
| 2089 | - function setDocModel($user, $modelpdf) |
|
| 2090 | - {
|
|
| 2091 | - if (! $this->table_element) |
|
| 2092 | - {
|
|
| 2093 | - dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 2094 | - return -1; |
|
| 2095 | - } |
|
| 2096 | - |
|
| 2097 | - $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 2098 | - |
|
| 2099 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2100 | - $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2101 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 2102 | - // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
|
| 2103 | - // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
|
| 2104 | - |
|
| 2105 | - dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
| 2106 | - $resql=$this->db->query($sql); |
|
| 2107 | - if ($resql) |
|
| 2108 | - {
|
|
| 2109 | - $this->modelpdf=$modelpdf; |
|
| 2110 | - return 1; |
|
| 2111 | - } |
|
| 2112 | - else |
|
| 2113 | - {
|
|
| 2114 | - dol_print_error($this->db); |
|
| 2115 | - return 0; |
|
| 2116 | - } |
|
| 2117 | - } |
|
| 2118 | - |
|
| 2119 | - |
|
| 2120 | - /** |
|
| 2121 | - * Change the bank account |
|
| 2122 | - * |
|
| 2123 | - * @param int $fk_account Id of bank account |
|
| 2124 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 2125 | - * @param User $userused Object user |
|
| 2126 | - * @return int 1 if OK, 0 if KO |
|
| 2127 | - */ |
|
| 2128 | - function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 2129 | - {
|
|
| 2130 | - global $user; |
|
| 2131 | 481 | |
| 2132 | - if (empty($userused)) $userused=$user; |
|
| 482 | + if ($withregion && $this->state_id && (empty($this->state_code) || empty($this->state) || empty($this->region) || empty($this->region_cpde))) |
|
| 483 | + {
|
|
| 484 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/company.lib.php'; |
|
| 485 | + $tmparray=getState($this->state_id,'all',0,1); |
|
| 486 | + $this->state_code =$tmparray['code']; |
|
| 487 | + $this->state =$tmparray['label']; |
|
| 488 | + $this->region_code =$tmparray['region_code']; |
|
| 489 | + $this->region =$tmparray['region']; |
|
| 490 | + } |
|
| 2133 | 491 | |
| 2134 | - $error = 0; |
|
| 492 | + return dol_format_address($this, $withcountry, $sep); |
|
| 493 | + } |
|
| 2135 | 494 | |
| 2136 | - if (! $this->table_element) {
|
|
| 2137 | - dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 2138 | - return -1; |
|
| 2139 | - } |
|
| 2140 | - $this->db->begin(); |
|
| 2141 | 495 | |
| 2142 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2143 | - dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
|
| 496 | + /** |
|
| 497 | + * Return full address for banner |
|
| 498 | + * |
|
| 499 | + * @param string $htmlkey HTML id to make banner content unique |
|
| 500 | + * @param Object $object Object (thirdparty, thirdparty of contact for contact, null for a member) |
|
| 501 | + * @return string Full address string |
|
| 502 | + */ |
|
| 503 | + function getBannerAddress($htmlkey, $object) |
|
| 504 | + {
|
|
| 505 | + global $conf, $langs; |
|
| 2144 | 506 | |
| 2145 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2146 | - $sql.= " SET fk_account = ".$fk_account; |
|
| 2147 | - $sql.= " WHERE rowid=".$this->id; |
|
| 507 | + $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS
|
|
| 2148 | 508 | |
| 2149 | - $resql = $this->db->query($sql); |
|
| 2150 | - if (! $resql) |
|
| 509 | + $contactid=0; |
|
| 510 | + $thirdpartyid=0; |
|
| 511 | + if ($this->element == 'societe') |
|
| 2151 | 512 | {
|
| 2152 | - dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
| 2153 | - $this->error = $this->db->lasterror(); |
|
| 2154 | - $error++; |
|
| 513 | + $thirdpartyid=$this->id; |
|
| 2155 | 514 | } |
| 2156 | - else |
|
| 515 | + if ($this->element == 'contact') |
|
| 2157 | 516 | {
|
| 2158 | - if (!$notrigger) |
|
| 2159 | - {
|
|
| 2160 | - // Call trigger |
|
| 2161 | - $this->context=array('bankaccountupdate'=>1);
|
|
| 2162 | - $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2163 | - if ($result < 0) $error++; |
|
| 2164 | - // End call trigger |
|
| 2165 | - } |
|
| 517 | + $contactid=$this->id; |
|
| 518 | + $thirdpartyid=$object->fk_soc; |
|
| 2166 | 519 | } |
| 2167 | - if ($error) |
|
| 520 | + if ($this->element == 'user') |
|
| 2168 | 521 | {
|
| 2169 | - $this->db->rollback(); |
|
| 2170 | - return -1; |
|
| 522 | + $contactid=$this->contact_id; |
|
| 523 | + $thirdpartyid=$object->fk_soc; |
|
| 2171 | 524 | } |
| 2172 | - else |
|
| 525 | + |
|
| 526 | + $out='<!-- BEGIN part to show address block -->'; |
|
| 527 | + |
|
| 528 | + $outdone=0; |
|
| 529 | + $coords = $this->getFullAddress(1, ', ', Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT); |
|
| 530 | + if ($coords) |
|
| 2173 | 531 | {
|
| 2174 | - $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 2175 | - $this->db->commit(); |
|
| 2176 | - return 1; |
|
| 532 | + if (!empty(Globals::$conf->use_javascript_ajax)) {
|
|
| 533 | + $namecoords = $this->getFullName($langs,1).'<br>'.$coords; |
|
| 534 | + // hideonsmatphone because copyToClipboard call jquery dialog that does not work with jmobile |
|
| 535 | + $out.='<a href="#" class="hideonsmartphone" onclick="return copyToClipboard(\''.dol_escape_js($namecoords).'\',\''.dol_escape_js($langs->trans("HelpCopyToClipboard")).'\');">';
|
|
| 536 | + $out.=img_picto($langs->trans("Address"), 'object_address.png');
|
|
| 537 | + $out.='</a> '; |
|
| 538 | + } |
|
| 539 | + $out.=dol_print_address($coords, 'address_'.$htmlkey.'_'.$this->id, $this->element, $this->id, 1, ', '); $outdone++; |
|
| 540 | + $outdone++; |
|
| 2177 | 541 | } |
| 2178 | - } |
|
| 2179 | 542 | |
| 543 | + if (!in_array($this->country_code, $countriesusingstate) && empty(Globals::$conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress |
|
| 544 | + && empty(Globals::$conf->global->SOCIETE_DISABLE_STATE) && $this->state) {
|
|
| 545 | + if (!empty(Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && Globals::$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 | + } |
|
| 2180 | 553 | |
| 2181 | - // TODO: Move line related operations to CommonObjectLine? |
|
| 2182 | - |
|
| 2183 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2184 | - /** |
|
| 2185 | - * Save a new position (field rang) for details lines. |
|
| 2186 | - * You can choose to set position for lines with already a position or lines without any position defined. |
|
| 2187 | - * |
|
| 2188 | - * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. |
|
| 2189 | - * @param string $rowidorder ASC or DESC |
|
| 2190 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2191 | - * @return int <0 if KO, >0 if OK |
|
| 2192 | - */ |
|
| 2193 | - function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2194 | - {
|
|
| 2195 | - // phpcs:enable |
|
| 2196 | - if (! $this->table_element_line) |
|
| 2197 | - {
|
|
| 2198 | - dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2199 | - return -1; |
|
| 2200 | - } |
|
| 2201 | - if (! $this->fk_element) |
|
| 2202 | - {
|
|
| 2203 | - dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2204 | - return -1; |
|
| 2205 | - } |
|
| 2206 | - |
|
| 2207 | - // Count number of lines to reorder (according to choice $renum) |
|
| 2208 | - $nl=0; |
|
| 2209 | - $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2210 | - $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2211 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2212 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2213 | - |
|
| 2214 | - dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
| 2215 | - $resql = $this->db->query($sql); |
|
| 2216 | - if ($resql) |
|
| 2217 | - {
|
|
| 2218 | - $row = $this->db->fetch_row($resql); |
|
| 2219 | - $nl = $row[0]; |
|
| 2220 | - } |
|
| 2221 | - else dol_print_error($this->db); |
|
| 2222 | - if ($nl > 0) |
|
| 2223 | - {
|
|
| 2224 | - // The goal of this part is to reorder all lines, with all children lines sharing the same |
|
| 2225 | - // counter that parents. |
|
| 2226 | - $rows=array(); |
|
| 2227 | - |
|
| 2228 | - // We first search all lines that are parent lines (for multilevel details lines) |
|
| 2229 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2230 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2231 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2232 | - $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2233 | - |
|
| 2234 | - dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
| 2235 | - $resql = $this->db->query($sql); |
|
| 2236 | - if ($resql) |
|
| 2237 | - {
|
|
| 2238 | - $i=0; |
|
| 2239 | - $num = $this->db->num_rows($resql); |
|
| 2240 | - while ($i < $num) |
|
| 2241 | - {
|
|
| 2242 | - $row = $this->db->fetch_row($resql); |
|
| 2243 | - $rows[] = $row[0]; // Add parent line into array rows |
|
| 2244 | - $childrens = $this->getChildrenOfLine($row[0]); |
|
| 2245 | - if (! empty($childrens)) |
|
| 2246 | - {
|
|
| 2247 | - foreach($childrens as $child) |
|
| 2248 | - {
|
|
| 2249 | - array_push($rows, $child); |
|
| 2250 | - } |
|
| 2251 | - } |
|
| 2252 | - $i++; |
|
| 2253 | - } |
|
| 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 | + } |
|
| 2254 | 579 | |
| 2255 | - // Now we set a new number for each lines (parent and children with children included into parent tree) |
|
| 2256 | - if (! empty($rows)) |
|
| 2257 | - {
|
|
| 2258 | - foreach($rows as $key => $row) |
|
| 2259 | - {
|
|
| 2260 | - $this->updateRangOfLine($row, ($key+1)); |
|
| 2261 | - } |
|
| 2262 | - } |
|
| 2263 | - } |
|
| 2264 | - else |
|
| 2265 | - {
|
|
| 2266 | - dol_print_error($this->db); |
|
| 2267 | - } |
|
| 2268 | - } |
|
| 2269 | - return 1; |
|
| 2270 | - } |
|
| 2271 | - |
|
| 2272 | - /** |
|
| 2273 | - * Get children of line |
|
| 2274 | - * |
|
| 2275 | - * @param int $id Id of parent line |
|
| 2276 | - * @return array Array with list of children lines id |
|
| 2277 | - */ |
|
| 2278 | - function getChildrenOfLine($id) |
|
| 2279 | - {
|
|
| 2280 | - $rows=array(); |
|
| 2281 | - |
|
| 2282 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2283 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2284 | - $sql.= ' AND fk_parent_line = '.$id; |
|
| 2285 | - $sql.= ' ORDER BY rang ASC'; |
|
| 2286 | - |
|
| 2287 | - dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
| 2288 | - $resql = $this->db->query($sql); |
|
| 2289 | - if ($resql) |
|
| 2290 | - {
|
|
| 2291 | - $i=0; |
|
| 2292 | - $num = $this->db->num_rows($resql); |
|
| 2293 | - while ($i < $num) |
|
| 2294 | - {
|
|
| 2295 | - $row = $this->db->fetch_row($resql); |
|
| 2296 | - $rows[$i] = $row[0]; |
|
| 2297 | - $i++; |
|
| 2298 | - } |
|
| 2299 | - } |
|
| 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(Globals::$conf->socialnetworks->enabled)) {
|
|
| 594 | + if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 595 | + $outdone++; |
|
| 596 | + if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 597 | + $outdone++; |
|
| 598 | + if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 599 | + $outdone++; |
|
| 600 | + if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 601 | + $outdone++; |
|
| 602 | + } |
|
| 603 | + $out.='</div>'; |
|
| 2300 | 604 | |
| 2301 | - return $rows; |
|
| 2302 | - } |
|
| 605 | + $out.='<!-- END Part to show address block -->'; |
|
| 2303 | 606 | |
| 2304 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2305 | - /** |
|
| 2306 | - * Update a line to have a lower rank |
|
| 2307 | - * |
|
| 2308 | - * @param int $rowid Id of line |
|
| 2309 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2310 | - * @return void |
|
| 2311 | - */ |
|
| 2312 | - function line_up($rowid, $fk_parent_line=true) |
|
| 2313 | - {
|
|
| 2314 | - // phpcs:enable |
|
| 2315 | - $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 607 | + return $out; |
|
| 608 | + } |
|
| 2316 | 609 | |
| 2317 | - // Get rang of line |
|
| 2318 | - $rang = $this->getRangOfLine($rowid); |
|
| 610 | + /** |
|
| 611 | + * Return the link of last main doc file for direct public download. |
|
| 612 | + * |
|
| 613 | + * @param string $modulepart Module related to document |
|
| 614 | + * @param int $initsharekey Init the share key if it was not yet defined |
|
| 615 | + * @param int $relativelink 0=Return full external link, 1=Return link relative to root of file |
|
| 616 | + * @return string Link or empty string if there is no download link |
|
| 617 | + */ |
|
| 618 | + function getLastMainDocLink($modulepart, $initsharekey=0, $relativelink=0) |
|
| 619 | + {
|
|
| 620 | + global $user, $dolibarr_main_url_root; |
|
| 2319 | 621 | |
| 2320 | - // Update position of line |
|
| 2321 | - $this->updateLineUp($rowid, $rang); |
|
| 2322 | - } |
|
| 622 | + if (empty($this->last_main_doc)) |
|
| 623 | + {
|
|
| 624 | + return ''; // No way to known which document name to use |
|
| 625 | + } |
|
| 2323 | 626 | |
| 2324 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2325 | - /** |
|
| 2326 | - * Update a line to have a higher rank |
|
| 2327 | - * |
|
| 2328 | - * @param int $rowid Id of line |
|
| 2329 | - * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2330 | - * @return void |
|
| 2331 | - */ |
|
| 2332 | - function line_down($rowid, $fk_parent_line=true) |
|
| 2333 | - {
|
|
| 2334 | - // phpcs:enable |
|
| 2335 | - $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 2336 | - |
|
| 2337 | - // Get rang of line |
|
| 2338 | - $rang = $this->getRangOfLine($rowid); |
|
| 2339 | - |
|
| 2340 | - // Get max value for rang |
|
| 2341 | - $max = $this->line_max(); |
|
| 2342 | - |
|
| 2343 | - // Update position of line |
|
| 2344 | - $this->updateLineDown($rowid, $rang, $max); |
|
| 2345 | - } |
|
| 2346 | - |
|
| 2347 | - /** |
|
| 2348 | - * Update position of line (rang) |
|
| 2349 | - * |
|
| 2350 | - * @param int $rowid Id of line |
|
| 2351 | - * @param int $rang Position |
|
| 2352 | - * @return void |
|
| 2353 | - */ |
|
| 2354 | - function updateRangOfLine($rowid,$rang) |
|
| 2355 | - {
|
|
| 2356 | - $fieldposition = 'rang'; |
|
| 2357 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2358 | - |
|
| 2359 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2360 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2361 | - |
|
| 2362 | - dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
| 2363 | - if (! $this->db->query($sql)) |
|
| 2364 | - {
|
|
| 2365 | - dol_print_error($this->db); |
|
| 2366 | - } |
|
| 2367 | - } |
|
| 627 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 628 | + $ecmfile=new EcmFiles($this->db); |
|
| 629 | + $result = $ecmfile->fetch(0, '', $this->last_main_doc); |
|
| 630 | + if ($result < 0) |
|
| 631 | + {
|
|
| 632 | + $this->error = $ecmfile->error; |
|
| 633 | + $this->errors = $ecmfile->errors; |
|
| 634 | + return -1; |
|
| 635 | + } |
|
| 2368 | 636 | |
| 2369 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2370 | - /** |
|
| 2371 | - * Update position of line with ajax (rang) |
|
| 2372 | - * |
|
| 2373 | - * @param array $rows Array of rows |
|
| 2374 | - * @return void |
|
| 2375 | - */ |
|
| 2376 | - function line_ajaxorder($rows) |
|
| 2377 | - {
|
|
| 2378 | - // phpcs:enable |
|
| 2379 | - $num = count($rows); |
|
| 2380 | - for ($i = 0 ; $i < $num ; $i++) |
|
| 2381 | - {
|
|
| 2382 | - $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2383 | - } |
|
| 2384 | - } |
|
| 2385 | - |
|
| 2386 | - /** |
|
| 2387 | - * Update position of line up (rang) |
|
| 2388 | - * |
|
| 2389 | - * @param int $rowid Id of line |
|
| 2390 | - * @param int $rang Position |
|
| 2391 | - * @return void |
|
| 2392 | - */ |
|
| 2393 | - function updateLineUp($rowid,$rang) |
|
| 2394 | - {
|
|
| 2395 | - if ($rang > 1) |
|
| 2396 | - {
|
|
| 2397 | - $fieldposition = 'rang'; |
|
| 2398 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2399 | - |
|
| 2400 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
| 2401 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2402 | - $sql.= ' AND rang = '.($rang - 1); |
|
| 2403 | - if ($this->db->query($sql) ) |
|
| 2404 | - {
|
|
| 2405 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
| 2406 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2407 | - if (! $this->db->query($sql) ) |
|
| 2408 | - {
|
|
| 2409 | - dol_print_error($this->db); |
|
| 2410 | - } |
|
| 2411 | - } |
|
| 2412 | - else |
|
| 2413 | - {
|
|
| 2414 | - dol_print_error($this->db); |
|
| 2415 | - } |
|
| 2416 | - } |
|
| 2417 | - } |
|
| 2418 | - |
|
| 2419 | - /** |
|
| 2420 | - * Update position of line down (rang) |
|
| 2421 | - * |
|
| 2422 | - * @param int $rowid Id of line |
|
| 2423 | - * @param int $rang Position |
|
| 2424 | - * @param int $max Max |
|
| 2425 | - * @return void |
|
| 2426 | - */ |
|
| 2427 | - function updateLineDown($rowid,$rang,$max) |
|
| 2428 | - {
|
|
| 2429 | - if ($rang < $max) |
|
| 2430 | - {
|
|
| 2431 | - $fieldposition = 'rang'; |
|
| 2432 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2433 | - |
|
| 2434 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2435 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2436 | - $sql.= ' AND rang = '.($rang+1); |
|
| 2437 | - if ($this->db->query($sql) ) |
|
| 2438 | - {
|
|
| 2439 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
| 2440 | - $sql.= ' WHERE rowid = '.$rowid; |
|
| 2441 | - if (! $this->db->query($sql) ) |
|
| 637 | + if (empty($ecmfile->id)) |
|
| 638 | + {
|
|
| 639 | + // Add entry into index |
|
| 640 | + if ($initsharekey) |
|
| 641 | + {
|
|
| 642 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 643 | + // TODO We can't, we dont' have full path of file, only last_main_doc adn ->element, so we must rebuild full path first |
|
| 644 | + /* |
|
| 645 | + $ecmfile->filepath = $rel_dir; |
|
| 646 | + $ecmfile->filename = $filename; |
|
| 647 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 648 | + $ecmfile->fullpath_orig = ''; |
|
| 649 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
| 650 | + $ecmfile->description = ''; // indexed content |
|
| 651 | + $ecmfile->keyword = ''; // keyword content |
|
| 652 | + $ecmfile->share = getRandomPassword(true); |
|
| 653 | + $result = $ecmfile->create($user); |
|
| 654 | + if ($result < 0) |
|
| 2442 | 655 | {
|
| 2443 | - dol_print_error($this->db); |
|
| 656 | + $this->error = $ecmfile->error; |
|
| 657 | + $this->errors = $ecmfile->errors; |
|
| 2444 | 658 | } |
| 2445 | - } |
|
| 2446 | - else |
|
| 2447 | - {
|
|
| 2448 | - dol_print_error($this->db); |
|
| 2449 | - } |
|
| 2450 | - } |
|
| 2451 | - } |
|
| 2452 | - |
|
| 2453 | - /** |
|
| 2454 | - * Get position of line (rang) |
|
| 2455 | - * |
|
| 2456 | - * @param int $rowid Id of line |
|
| 2457 | - * @return int Value of rang in table of lines |
|
| 2458 | - */ |
|
| 2459 | - function getRangOfLine($rowid) |
|
| 2460 | - {
|
|
| 2461 | - $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2462 | - $sql.= ' WHERE rowid ='.$rowid; |
|
| 2463 | - |
|
| 2464 | - dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
| 2465 | - $resql = $this->db->query($sql); |
|
| 2466 | - if ($resql) |
|
| 2467 | - {
|
|
| 2468 | - $row = $this->db->fetch_row($resql); |
|
| 2469 | - return $row[0]; |
|
| 2470 | - } |
|
| 2471 | - } |
|
| 2472 | - |
|
| 2473 | - /** |
|
| 2474 | - * Get rowid of the line relative to its position |
|
| 2475 | - * |
|
| 2476 | - * @param int $rang Rang value |
|
| 2477 | - * @return int Rowid of the line |
|
| 2478 | - */ |
|
| 2479 | - function getIdOfLine($rang) |
|
| 2480 | - {
|
|
| 2481 | - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2482 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2483 | - $sql.= ' AND rang = '.$rang; |
|
| 2484 | - $resql = $this->db->query($sql); |
|
| 2485 | - if ($resql) |
|
| 2486 | - {
|
|
| 2487 | - $row = $this->db->fetch_row($resql); |
|
| 2488 | - return $row[0]; |
|
| 2489 | - } |
|
| 2490 | - } |
|
| 659 | + */ |
|
| 660 | + } |
|
| 661 | + else return ''; |
|
| 662 | + } |
|
| 663 | + elseif (empty($ecmfile->share)) |
|
| 664 | + {
|
|
| 665 | + // Add entry into index |
|
| 666 | + if ($initsharekey) |
|
| 667 | + {
|
|
| 668 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 669 | + $ecmfile->share = getRandomPassword(true); |
|
| 670 | + $ecmfile->update($user); |
|
| 671 | + } |
|
| 672 | + else return ''; |
|
| 673 | + } |
|
| 2491 | 674 | |
| 2492 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2493 | - /** |
|
| 2494 | - * Get max value used for position of line (rang) |
|
| 2495 | - * |
|
| 2496 | - * @param int $fk_parent_line Parent line id |
|
| 2497 | - * @return int Max value of rang in table of lines |
|
| 2498 | - */ |
|
| 2499 | - function line_max($fk_parent_line=0) |
|
| 2500 | - {
|
|
| 2501 | - // phpcs:enable |
|
| 2502 | - // Search the last rang with fk_parent_line |
|
| 2503 | - if ($fk_parent_line) |
|
| 2504 | - {
|
|
| 2505 | - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2506 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2507 | - $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2508 | - |
|
| 2509 | - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2510 | - $resql = $this->db->query($sql); |
|
| 2511 | - if ($resql) |
|
| 2512 | - {
|
|
| 2513 | - $row = $this->db->fetch_row($resql); |
|
| 2514 | - if (! empty($row[0])) |
|
| 2515 | - {
|
|
| 2516 | - return $row[0]; |
|
| 2517 | - } |
|
| 2518 | - else |
|
| 2519 | - {
|
|
| 2520 | - return $this->getRangOfLine($fk_parent_line); |
|
| 2521 | - } |
|
| 2522 | - } |
|
| 2523 | - } |
|
| 2524 | - // If not, search the last rang of element |
|
| 2525 | - else |
|
| 2526 | - {
|
|
| 2527 | - $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2528 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2529 | - |
|
| 2530 | - dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2531 | - $resql = $this->db->query($sql); |
|
| 2532 | - if ($resql) |
|
| 2533 | - {
|
|
| 2534 | - $row = $this->db->fetch_row($resql); |
|
| 2535 | - return $row[0]; |
|
| 2536 | - } |
|
| 2537 | - } |
|
| 2538 | - } |
|
| 675 | + // Define $urlwithroot |
|
| 676 | + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
|
|
| 677 | + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
| 678 | + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
|
| 2539 | 679 | |
| 2540 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2541 | - /** |
|
| 2542 | - * Update external ref of element |
|
| 2543 | - * |
|
| 2544 | - * @param string $ref_ext Update field ref_ext |
|
| 2545 | - * @return int <0 if KO, >0 if OK |
|
| 2546 | - */ |
|
| 2547 | - function update_ref_ext($ref_ext) |
|
| 2548 | - {
|
|
| 2549 | - // phpcs:enable |
|
| 2550 | - if (! $this->table_element) |
|
| 2551 | - {
|
|
| 2552 | - dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
| 2553 | - return -1; |
|
| 2554 | - } |
|
| 2555 | - |
|
| 2556 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2557 | - $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2558 | - $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2559 | - |
|
| 2560 | - dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
| 2561 | - if ($this->db->query($sql)) |
|
| 2562 | - {
|
|
| 2563 | - $this->ref_ext = $ref_ext; |
|
| 2564 | - return 1; |
|
| 2565 | - } |
|
| 2566 | - else |
|
| 2567 | - {
|
|
| 2568 | - $this->error=$this->db->error(); |
|
| 2569 | - return -1; |
|
| 2570 | - } |
|
| 2571 | - } |
|
| 680 | + $forcedownload=0; |
|
| 2572 | 681 | |
| 2573 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2574 | - /** |
|
| 2575 | - * Update note of element |
|
| 2576 | - * |
|
| 2577 | - * @param string $note New value for note |
|
| 2578 | - * @param string $suffix '', '_public' or '_private' |
|
| 2579 | - * @return int <0 if KO, >0 if OK |
|
| 2580 | - */ |
|
| 2581 | - function update_note($note, $suffix='') |
|
| 2582 | - {
|
|
| 2583 | - // phpcs:enable |
|
| 2584 | - global $user; |
|
| 2585 | - |
|
| 2586 | - if (! $this->table_element) |
|
| 2587 | - {
|
|
| 2588 | - $this->error='update_note was called on objet with property table_element not defined'; |
|
| 2589 | - dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
| 2590 | - return -1; |
|
| 2591 | - } |
|
| 2592 | - if (! in_array($suffix,array('','_public','_private')))
|
|
| 2593 | - {
|
|
| 2594 | - $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2595 | - dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
| 2596 | - return -2; |
|
| 2597 | - } |
|
| 2598 | - // Special cas |
|
| 2599 | - //var_dump($this->table_element);exit; |
|
| 2600 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2601 | - |
|
| 2602 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2603 | - $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
|
| 2604 | - $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id;
|
|
| 2605 | - $sql.= " WHERE rowid =". $this->id; |
|
| 2606 | - |
|
| 2607 | - dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
| 2608 | - if ($this->db->query($sql)) |
|
| 2609 | - {
|
|
| 2610 | - if ($suffix == '_public') $this->note_public = $note; |
|
| 2611 | - else if ($suffix == '_private') $this->note_private = $note; |
|
| 2612 | - else |
|
| 2613 | - {
|
|
| 2614 | - $this->note = $note; // deprecated |
|
| 2615 | - $this->note_private = $note; |
|
| 2616 | - } |
|
| 2617 | - return 1; |
|
| 2618 | - } |
|
| 2619 | - else |
|
| 2620 | - {
|
|
| 2621 | - $this->error=$this->db->lasterror(); |
|
| 2622 | - return -1; |
|
| 2623 | - } |
|
| 2624 | - } |
|
| 682 | + $paramlink=''; |
|
| 683 | + //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
|
| 684 | + //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
|
| 685 | + //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
|
| 686 | + if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 687 | + if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 688 | + |
|
| 689 | + if ($relativelink) |
|
| 690 | + {
|
|
| 691 | + $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
|
| 692 | + } |
|
| 693 | + else |
|
| 694 | + {
|
|
| 695 | + $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + // Here $ecmfile->share is defined |
|
| 699 | + return $linktoreturn; |
|
| 700 | + } |
|
| 2625 | 701 | |
| 2626 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2627 | - /** |
|
| 2628 | - * Update public note (kept for backward compatibility) |
|
| 2629 | - * |
|
| 2630 | - * @param string $note New value for note |
|
| 2631 | - * @return int <0 if KO, >0 if OK |
|
| 2632 | - * @deprecated |
|
| 2633 | - * @see update_note() |
|
| 2634 | - */ |
|
| 2635 | - function update_note_public($note) |
|
| 2636 | - {
|
|
| 2637 | - // phpcs:enable |
|
| 2638 | - return $this->update_note($note,'_public'); |
|
| 2639 | - } |
|
| 2640 | 702 | |
| 2641 | 703 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 2642 | - /** |
|
| 2643 | - * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). |
|
| 2644 | - * Must be called at end of methods addline or updateline. |
|
| 2645 | - * |
|
| 2646 | - * @param int $exclspec >0 = Exclude special product (product_type=9) |
|
| 2647 | - * @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 |
|
| 2648 | - * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. |
|
| 2649 | - * @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. |
|
| 2650 | - * @return int <0 if KO, >0 if OK |
|
| 2651 | - */ |
|
| 2652 | - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2653 | - {
|
|
| 704 | + /** |
|
| 705 | + * Add a link between element $this->element and a contact |
|
| 706 | + * |
|
| 707 | + * @param int $fk_socpeople Id of thirdparty contact (if source = 'external') or id of user (if souce = 'internal') to link |
|
| 708 | + * @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 |
|
| 709 | + * @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user) |
|
| 710 | + * @param int $notrigger Disable all triggers |
|
| 711 | + * @return int <0 if KO, >0 if OK |
|
| 712 | + */ |
|
| 713 | + function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger=0) |
|
| 714 | + {
|
|
| 2654 | 715 | // phpcs:enable |
| 2655 | - global $conf, $hookmanager, $action; |
|
| 2656 | - |
|
| 2657 | - // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
|
| 2658 | - $MODULE = ""; |
|
| 2659 | - if ($this->element == 'propal') |
|
| 2660 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2661 | - elseif ($this->element == 'order') |
|
| 2662 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2663 | - elseif ($this->element == 'facture') |
|
| 2664 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2665 | - elseif ($this->element == 'facture_fourn') |
|
| 2666 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2667 | - elseif ($this->element == 'order_supplier') |
|
| 2668 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2669 | - elseif ($this->element == 'supplier_proposal') |
|
| 2670 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2671 | - |
|
| 2672 | - if (! empty($MODULE)) {
|
|
| 2673 | - if (!empty(Globals::$conf->global->$MODULE)) {
|
|
| 2674 | - $modsactivated = explode(',', Globals::$conf->global->$MODULE);
|
|
| 2675 | - foreach ($modsactivated as $mod) {
|
|
| 2676 | - if (Globals::$conf->$mod->enabled) |
|
| 2677 | - return 1; // update was disabled by specific setup |
|
| 2678 | - } |
|
| 2679 | - } |
|
| 2680 | - } |
|
| 716 | + global $user,$langs; |
|
| 2681 | 717 | |
| 2682 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
| 2683 | 718 | |
| 2684 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 719 | + dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source, $notrigger"); |
|
| 2685 | 720 | |
| 2686 | - $forcedroundingmode=$roundingadjust; |
|
| 2687 | - if ($forcedroundingmode == 'auto' && isset(Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) |
|
| 2688 | - $forcedroundingmode = Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2689 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 721 | + // Check parameters |
|
| 722 | + if ($fk_socpeople <= 0) |
|
| 723 | + {
|
|
| 724 | + $langs->load("errors");
|
|
| 725 | + $this->error=$langs->trans("ErrorWrongValueForParameterX","1");
|
|
| 726 | + dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 727 | + return -1; |
|
| 728 | + } |
|
| 729 | + if (! $type_contact) |
|
| 730 | + {
|
|
| 731 | + $langs->load("errors");
|
|
| 732 | + $this->error=$langs->trans("ErrorWrongValueForParameterX","2");
|
|
| 733 | + dol_syslog(get_class($this)."::add_contact ".$this->error,LOG_ERR); |
|
| 734 | + return -2; |
|
| 735 | + } |
|
| 2690 | 736 | |
| 2691 | - $error=0; |
|
| 2692 | - |
|
| 2693 | - $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
|
| 2694 | - |
|
| 2695 | - // Define constants to find lines to sum |
|
| 2696 | - $fieldtva='total_tva'; |
|
| 2697 | - $fieldlocaltax1='total_localtax1'; |
|
| 2698 | - $fieldlocaltax2='total_localtax2'; |
|
| 2699 | - $fieldup='subprice'; |
|
| 2700 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 2701 | - {
|
|
| 2702 | - $fieldtva='tva'; |
|
| 2703 | - $fieldup='pu_ht'; |
|
| 2704 | - } |
|
| 2705 | - if ($this->element == 'expensereport') |
|
| 2706 | - {
|
|
| 2707 | - $fieldup='value_unit'; |
|
| 2708 | - } |
|
| 2709 | - |
|
| 2710 | - $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,'; |
|
| 2711 | - $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2712 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2713 | - $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2714 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2715 | - $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2716 | - if ($exclspec) |
|
| 2717 | - {
|
|
| 2718 | - $product_field='product_type'; |
|
| 2719 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2720 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2721 | - } |
|
| 2722 | - $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 |
|
| 2723 | - |
|
| 2724 | - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2725 | - $resql = $this->db->query($sql); |
|
| 2726 | - if ($resql) |
|
| 2727 | - {
|
|
| 2728 | - $this->total_ht = 0; |
|
| 2729 | - $this->total_tva = 0; |
|
| 2730 | - $this->total_localtax1 = 0; |
|
| 2731 | - $this->total_localtax2 = 0; |
|
| 2732 | - $this->total_ttc = 0; |
|
| 2733 | - $total_ht_by_vats = array(); |
|
| 2734 | - $total_tva_by_vats = array(); |
|
| 2735 | - $total_ttc_by_vats = array(); |
|
| 2736 | - $this->multicurrency_total_ht = 0; |
|
| 2737 | - $this->multicurrency_total_tva = 0; |
|
| 2738 | - $this->multicurrency_total_ttc = 0; |
|
| 2739 | - |
|
| 2740 | - $num = $this->db->num_rows($resql); |
|
| 2741 | - $i = 0; |
|
| 2742 | - while ($i < $num) |
|
| 2743 | - {
|
|
| 2744 | - $obj = $this->db->fetch_object($resql); |
|
| 737 | + $id_type_contact=0; |
|
| 738 | + if (is_numeric($type_contact)) |
|
| 739 | + {
|
|
| 740 | + $id_type_contact=$type_contact; |
|
| 741 | + } |
|
| 742 | + else |
|
| 743 | + {
|
|
| 744 | + // We look for id type_contact |
|
| 745 | + $sql = "SELECT tc.rowid"; |
|
| 746 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 747 | + $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 748 | + $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 749 | + $sql.= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; |
|
| 750 | + //print $sql; |
|
| 751 | + $resql=$this->db->query($sql); |
|
| 752 | + if ($resql) |
|
| 753 | + {
|
|
| 754 | + $obj = $this->db->fetch_object($resql); |
|
| 755 | + if ($obj) $id_type_contact=$obj->rowid; |
|
| 756 | + } |
|
| 757 | + } |
|
| 2745 | 758 | |
| 2746 | - // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
|
| 2747 | - $parameters=array('fk_element' => $obj->rowid);
|
|
| 2748 | - $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 759 | + if ($id_type_contact == 0) |
|
| 760 | + {
|
|
| 761 | + $this->error='CODE_NOT_VALID_FOR_THIS_ELEMENT'; |
|
| 762 | + 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");
|
|
| 763 | + return -3; |
|
| 764 | + } |
|
| 2749 | 765 | |
| 2750 | - 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' |
|
| 2751 | - {
|
|
| 2752 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2753 | - $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); |
|
| 2754 | - $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2755 | - if ($diff) |
|
| 2756 | - {
|
|
| 2757 | - $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2758 | - 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);
|
|
| 2759 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2760 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2761 | - $obj->total_tva = $tmpcal[1]; |
|
| 2762 | - $obj->total_ttc = $tmpcal[2]; |
|
| 2763 | - // |
|
| 2764 | - } |
|
| 2765 | - } |
|
| 766 | + $datecreate = dol_now(); |
|
| 2766 | 767 | |
| 2767 | - $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2768 | - $this->total_tva += $obj->total_tva; |
|
| 2769 | - $this->total_localtax1 += $obj->total_localtax1; |
|
| 2770 | - $this->total_localtax2 += $obj->total_localtax2; |
|
| 2771 | - $this->total_ttc += $obj->total_ttc; |
|
| 2772 | - $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2773 | - $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
|
| 2774 | - $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
|
| 2775 | - |
|
| 2776 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2777 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2778 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 2779 | - $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
|
| 2780 | - $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
|
| 2781 | - $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
|
| 2782 | - |
|
| 2783 | - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2784 | - {
|
|
| 2785 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2786 | - $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2787 | - //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"; |
|
| 2788 | - if ($diff) |
|
| 2789 | - {
|
|
| 2790 | - if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; }
|
|
| 2791 | - $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; |
|
| 2792 | - 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);
|
|
| 2793 | - $resqlfix=$this->db->query($sqlfix); |
|
| 2794 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2795 | - $this->total_tva -= $diff; |
|
| 2796 | - $this->total_ttc -= $diff; |
|
| 2797 | - $total_tva_by_vats[$obj->vatrate] -= $diff; |
|
| 2798 | - $total_ttc_by_vats[$obj->vatrate] -= $diff; |
|
| 2799 | - } |
|
| 2800 | - } |
|
| 768 | + // Socpeople must have already been added by some trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error |
|
| 769 | + $TListeContacts=$this->liste_contact(-1, $source); |
|
| 770 | + $already_added=false; |
|
| 771 | + if(!empty($TListeContacts)) {
|
|
| 772 | + foreach($TListeContacts as $array_contact) {
|
|
| 773 | + if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) {
|
|
| 774 | + $already_added=true; |
|
| 775 | + break; |
|
| 776 | + } |
|
| 777 | + } |
|
| 778 | + } |
|
| 2801 | 779 | |
| 2802 | - $i++; |
|
| 2803 | - } |
|
| 780 | + if(!$already_added) {
|
|
| 2804 | 781 | |
| 2805 | - // Add revenue stamp to total |
|
| 2806 | - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2807 | - $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 782 | + $this->db->begin(); |
|
| 2808 | 783 | |
| 2809 | - // Situations totals |
|
| 2810 | - if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
| 2811 | - {
|
|
| 2812 | - $prev_sits = $this->get_prev_sits(); |
|
| 2813 | - |
|
| 2814 | - foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch.
|
|
| 2815 | - $this->total_ht -= $sit->total_ht; |
|
| 2816 | - $this->total_tva -= $sit->total_tva; |
|
| 2817 | - $this->total_localtax1 -= $sit->total_localtax1; |
|
| 2818 | - $this->total_localtax2 -= $sit->total_localtax2; |
|
| 2819 | - $this->total_ttc -= $sit->total_ttc; |
|
| 2820 | - $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; |
|
| 2821 | - $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; |
|
| 2822 | - $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; |
|
| 2823 | - } |
|
| 2824 | - } |
|
| 2825 | - |
|
| 2826 | - $this->db->free($resql); |
|
| 2827 | - |
|
| 2828 | - // Now update global field total_ht, total_ttc and tva |
|
| 2829 | - $fieldht='total_ht'; |
|
| 2830 | - $fieldtva='tva'; |
|
| 2831 | - $fieldlocaltax1='localtax1'; |
|
| 2832 | - $fieldlocaltax2='localtax2'; |
|
| 2833 | - $fieldttc='total_ttc'; |
|
| 2834 | - // Specific code for backward compatibility with old field names |
|
| 2835 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2836 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2837 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2838 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2839 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 2840 | - |
|
| 2841 | - if (empty($nodatabaseupdate)) |
|
| 2842 | - {
|
|
| 2843 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
| 2844 | - $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
| 2845 | - $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
| 2846 | - $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
| 2847 | - $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
| 2848 | - $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
| 2849 | - $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
| 2850 | - $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
| 2851 | - $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
| 2852 | - $sql .= ' WHERE rowid = '.$this->id; |
|
| 2853 | - |
|
| 2854 | - |
|
| 2855 | - dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2856 | - $resql=$this->db->query($sql); |
|
| 2857 | - if (! $resql) |
|
| 2858 | - {
|
|
| 2859 | - $error++; |
|
| 2860 | - $this->error=$this->db->lasterror(); |
|
| 2861 | - $this->errors[]=$this->db->lasterror(); |
|
| 2862 | - } |
|
| 2863 | - } |
|
| 784 | + // Insert into database |
|
| 785 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; |
|
| 786 | + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; |
|
| 787 | + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ;
|
|
| 788 | + $sql.= "'".$this->db->idate($datecreate)."'"; |
|
| 789 | + $sql.= ", 4, ". $id_type_contact; |
|
| 790 | + $sql.= ")"; |
|
| 2864 | 791 | |
| 2865 | - if (! $error) |
|
| 2866 | - {
|
|
| 2867 | - return 1; |
|
| 2868 | - } |
|
| 2869 | - else |
|
| 2870 | - {
|
|
| 2871 | - return -1; |
|
| 2872 | - } |
|
| 2873 | - } |
|
| 2874 | - else |
|
| 2875 | - {
|
|
| 2876 | - dol_print_error($this->db,'Bad request in update_price'); |
|
| 2877 | - return -1; |
|
| 2878 | - } |
|
| 2879 | - } |
|
| 792 | + $resql=$this->db->query($sql); |
|
| 793 | + if ($resql) |
|
| 794 | + {
|
|
| 795 | + if (! $notrigger) |
|
| 796 | + {
|
|
| 797 | + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); |
|
| 798 | + if ($result < 0) |
|
| 799 | + {
|
|
| 800 | + $this->db->rollback(); |
|
| 801 | + return -1; |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + $this->db->commit(); |
|
| 806 | + return 1; |
|
| 807 | + } |
|
| 808 | + else |
|
| 809 | + {
|
|
| 810 | + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
| 811 | + {
|
|
| 812 | + $this->error=$this->db->errno(); |
|
| 813 | + $this->db->rollback(); |
|
| 814 | + echo 'err rollback'; |
|
| 815 | + return -2; |
|
| 816 | + } |
|
| 817 | + else |
|
| 818 | + {
|
|
| 819 | + $this->error=$this->db->error(); |
|
| 820 | + $this->db->rollback(); |
|
| 821 | + return -1; |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + } else return 0; |
|
| 825 | + } |
|
| 2880 | 826 | |
| 2881 | 827 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 2882 | - /** |
|
| 2883 | - * Add objects linked in llx_element_element. |
|
| 2884 | - * |
|
| 2885 | - * @param string $origin Linked element type |
|
| 2886 | - * @param int $origin_id Linked element id |
|
| 2887 | - * @return int <=0 if KO, >0 if OK |
|
| 2888 | - * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
|
| 2889 | - */ |
|
| 2890 | - function add_object_linked($origin=null, $origin_id=null) |
|
| 2891 | - {
|
|
| 828 | + /** |
|
| 829 | + * Copy contact from one element to current |
|
| 830 | + * |
|
| 831 | + * @param CommonObject $objFrom Source element |
|
| 832 | + * @param string $source Nature of contact ('internal' or 'external')
|
|
| 833 | + * @return int >0 if OK, <0 if KO |
|
| 834 | + */ |
|
| 835 | + function copy_linked_contact($objFrom, $source='internal') |
|
| 836 | + {
|
|
| 2892 | 837 | // phpcs:enable |
| 2893 | - $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2894 | - $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2895 | - |
|
| 2896 | - // Special case |
|
| 2897 | - if ($origin == 'order') $origin='commande'; |
|
| 2898 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2899 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2900 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 2901 | - $this->db->begin(); |
|
| 2902 | - |
|
| 2903 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
|
| 2904 | - $sql.= "fk_source"; |
|
| 2905 | - $sql.= ", sourcetype"; |
|
| 2906 | - $sql.= ", fk_target"; |
|
| 2907 | - $sql.= ", targettype"; |
|
| 2908 | - $sql.= ") VALUES (";
|
|
| 2909 | - $sql.= $origin_id; |
|
| 2910 | - $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2911 | - $sql.= ", ".$this->id; |
|
| 2912 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2913 | - $sql.= ")"; |
|
| 2914 | - |
|
| 2915 | - dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
| 2916 | - if ($this->db->query($sql)) |
|
| 2917 | - {
|
|
| 2918 | - $this->db->commit(); |
|
| 2919 | - return 1; |
|
| 2920 | - } |
|
| 2921 | - else |
|
| 2922 | - {
|
|
| 2923 | - $this->error=$this->db->lasterror(); |
|
| 2924 | - $this->db->rollback(); |
|
| 2925 | - return 0; |
|
| 2926 | - } |
|
| 2927 | - } |
|
| 2928 | - |
|
| 2929 | - /** |
|
| 2930 | - * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into |
|
| 2931 | - * this->linkedObjectsIds array and |
|
| 2932 | - * this->linkedObjects array if $loadalsoobjects = 1 |
|
| 2933 | - * Possible usage for parameters: |
|
| 2934 | - * - all parameters empty -> we look all link to current object (current object can be source or target) |
|
| 2935 | - * - source id+type -> will get target list linked to source |
|
| 2936 | - * - target id+type -> will get source list linked to target |
|
| 2937 | - * - source id+type + target type -> will get target list of the type |
|
| 2938 | - * - target id+type + target source -> will get source list of the type |
|
| 2939 | - * |
|
| 2940 | - * @param int $sourceid Object source id (if not defined, id of object) |
|
| 2941 | - * @param string $sourcetype Object source type (if not defined, element name of object) |
|
| 2942 | - * @param int $targetid Object target id (if not defined, id of object) |
|
| 2943 | - * @param string $targettype Object target type (if not defined, elemennt name of object) |
|
| 2944 | - * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided |
|
| 2945 | - * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. |
|
| 2946 | - * @param string $orderby SQL 'ORDER BY' clause |
|
| 2947 | - * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) |
|
| 2948 | - * @return int <0 if KO, >0 if OK |
|
| 2949 | - * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
|
| 2950 | - */ |
|
| 2951 | - function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
| 2952 | - {
|
|
| 2953 | - global $conf; |
|
| 2954 | - |
|
| 2955 | - $this->linkedObjectsIds=array(); |
|
| 2956 | - $this->linkedObjects=array(); |
|
| 2957 | - |
|
| 2958 | - $justsource=false; |
|
| 2959 | - $justtarget=false; |
|
| 2960 | - $withtargettype=false; |
|
| 2961 | - $withsourcetype=false; |
|
| 2962 | - |
|
| 2963 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2964 | - {
|
|
| 2965 | - $justsource=true; // the source (id and type) is a search criteria |
|
| 2966 | - if (! empty($targettype)) $withtargettype=true; |
|
| 2967 | - } |
|
| 2968 | - if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2969 | - {
|
|
| 2970 | - $justtarget=true; // the target (id and type) is a search criteria |
|
| 2971 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2972 | - } |
|
| 2973 | - |
|
| 2974 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2975 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2976 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2977 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2978 | - |
|
| 2979 | - /*if (empty($sourceid) && empty($targetid)) |
|
| 2980 | - {
|
|
| 2981 | - dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR);
|
|
| 2982 | - return -1; |
|
| 2983 | - }*/ |
|
| 2984 | - |
|
| 2985 | - // Links between objects are stored in table element_element |
|
| 2986 | - $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
|
| 2987 | - $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2988 | - $sql.= " WHERE "; |
|
| 2989 | - if ($justsource || $justtarget) |
|
| 2990 | - {
|
|
| 2991 | - if ($justsource) |
|
| 2992 | - {
|
|
| 2993 | - $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2994 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2995 | - } |
|
| 2996 | - else if ($justtarget) |
|
| 2997 | - {
|
|
| 2998 | - $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2999 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3000 | - } |
|
| 3001 | - } |
|
| 3002 | - else |
|
| 3003 | - {
|
|
| 3004 | - $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3005 | - $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3006 | - } |
|
| 3007 | - $sql .= ' ORDER BY '.$orderby; |
|
| 3008 | - |
|
| 3009 | - dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
| 3010 | - $resql = $this->db->query($sql); |
|
| 3011 | - if ($resql) |
|
| 3012 | - {
|
|
| 3013 | - $num = $this->db->num_rows($resql); |
|
| 3014 | - $i = 0; |
|
| 3015 | - while ($i < $num) |
|
| 3016 | - {
|
|
| 3017 | - $obj = $this->db->fetch_object($resql); |
|
| 3018 | - if ($justsource || $justtarget) |
|
| 3019 | - {
|
|
| 3020 | - if ($justsource) |
|
| 3021 | - {
|
|
| 3022 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3023 | - } |
|
| 3024 | - else if ($justtarget) |
|
| 3025 | - {
|
|
| 3026 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3027 | - } |
|
| 3028 | - } |
|
| 3029 | - else |
|
| 3030 | - {
|
|
| 3031 | - if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
|
| 3032 | - {
|
|
| 3033 | - $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3034 | - } |
|
| 3035 | - if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
|
| 3036 | - {
|
|
| 3037 | - $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3038 | - } |
|
| 3039 | - } |
|
| 3040 | - $i++; |
|
| 3041 | - } |
|
| 838 | + $contacts = $objFrom->liste_contact(-1, $source); |
|
| 839 | + foreach($contacts as $contact) |
|
| 840 | + {
|
|
| 841 | + if ($this->add_contact($contact['id'], $contact['fk_c_type_contact'], $contact['source']) < 0) |
|
| 842 | + {
|
|
| 843 | + $this->error=$this->db->lasterror(); |
|
| 844 | + return -1; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + return 1; |
|
| 848 | + } |
|
| 3042 | 849 | |
| 3043 | - if (! empty($this->linkedObjectsIds)) |
|
| 3044 | - {
|
|
| 3045 | - $tmparray = $this->linkedObjectsIds; |
|
| 3046 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3047 | - {
|
|
| 3048 | - // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
|
| 3049 | - $module = $element = $subelement = $objecttype; |
|
| 3050 | - if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
|
| 3051 | - && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
|
| 3052 | - {
|
|
| 3053 | - $module = $element = $regs[1]; |
|
| 3054 | - $subelement = $regs[2]; |
|
| 3055 | - } |
|
| 3056 | - |
|
| 3057 | - $classpath = $element.'/class'; |
|
| 3058 | - // To work with non standard classpath or module name |
|
| 3059 | - if ($objecttype == 'facture') {
|
|
| 3060 | - $classpath = 'compta/facture/class'; |
|
| 3061 | - } |
|
| 3062 | - else if ($objecttype == 'facturerec') {
|
|
| 3063 | - $classpath = 'compta/facture/class'; $module = 'facture'; |
|
| 3064 | - } |
|
| 3065 | - else if ($objecttype == 'propal') {
|
|
| 3066 | - $classpath = 'comm/propal/class'; |
|
| 3067 | - } |
|
| 3068 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3069 | - $classpath = 'supplier_proposal/class'; |
|
| 3070 | - } |
|
| 3071 | - else if ($objecttype == 'shipping') {
|
|
| 3072 | - $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
|
| 3073 | - } |
|
| 3074 | - else if ($objecttype == 'delivery') {
|
|
| 3075 | - $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
|
| 3076 | - } |
|
| 3077 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3078 | - $classpath = 'fourn/class'; $module = 'fournisseur'; |
|
| 3079 | - } |
|
| 3080 | - else if ($objecttype == 'fichinter') {
|
|
| 3081 | - $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
|
| 3082 | - } |
|
| 3083 | - else if ($objecttype == 'subscription') {
|
|
| 3084 | - $classpath = 'adherents/class'; $module = 'adherent'; |
|
| 3085 | - } |
|
| 3086 | - |
|
| 3087 | - // Set classfile |
|
| 3088 | - $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
|
| 3089 | - |
|
| 3090 | - if ($objecttype == 'order') {
|
|
| 3091 | - $classfile = 'commande'; $classname = 'Commande'; |
|
| 3092 | - } |
|
| 3093 | - else if ($objecttype == 'invoice_supplier') {
|
|
| 3094 | - $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
|
| 3095 | - } |
|
| 3096 | - else if ($objecttype == 'order_supplier') {
|
|
| 3097 | - $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
|
| 3098 | - } |
|
| 3099 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3100 | - $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
|
| 3101 | - } |
|
| 3102 | - else if ($objecttype == 'facturerec') {
|
|
| 3103 | - $classfile = 'facture-rec'; $classname = 'FactureRec'; |
|
| 3104 | - } |
|
| 3105 | - else if ($objecttype == 'subscription') {
|
|
| 3106 | - $classfile = 'subscription'; $classname = 'Subscription'; |
|
| 3107 | - } |
|
| 3108 | - |
|
| 3109 | - // Here $module, $classfile and $classname are set |
|
| 3110 | - if (Globals::$conf->$module->enabled && (($element != $this->element) || $alsosametype)) {
|
|
| 3111 | - if ($loadalsoobjects) |
|
| 3112 | - {
|
|
| 3113 | - dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
|
|
| 3114 | - //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
|
| 3115 | - if (class_exists($classname)) |
|
| 3116 | - {
|
|
| 3117 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3118 | - {
|
|
| 3119 | - $object = new $classname($this->db); |
|
| 3120 | - $ret = $object->fetch($objectid); |
|
| 3121 | - if ($ret >= 0) |
|
| 3122 | - {
|
|
| 3123 | - $this->linkedObjects[$objecttype][$i] = $object; |
|
| 3124 | - } |
|
| 3125 | - } |
|
| 3126 | - } |
|
| 3127 | - } |
|
| 3128 | - } |
|
| 3129 | - else |
|
| 3130 | - {
|
|
| 3131 | - unset($this->linkedObjectsIds[$objecttype]); |
|
| 3132 | - } |
|
| 3133 | - } |
|
| 3134 | - } |
|
| 3135 | - return 1; |
|
| 3136 | - } |
|
| 3137 | - else |
|
| 3138 | - {
|
|
| 3139 | - dol_print_error($this->db); |
|
| 3140 | - return -1; |
|
| 3141 | - } |
|
| 3142 | - } |
|
| 3143 | - |
|
| 3144 | - /** |
|
| 3145 | - * Update object linked of a current object |
|
| 3146 | - * |
|
| 3147 | - * @param int $sourceid Object source id |
|
| 3148 | - * @param string $sourcetype Object source type |
|
| 3149 | - * @param int $targetid Object target id |
|
| 3150 | - * @param string $targettype Object target type |
|
| 3151 | - * @return int >0 if OK, <0 if KO |
|
| 3152 | - * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
|
| 3153 | - */ |
|
| 3154 | - function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 3155 | - {
|
|
| 3156 | - $updatesource=false; |
|
| 3157 | - $updatetarget=false; |
|
| 3158 | - |
|
| 3159 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3160 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3161 | - |
|
| 3162 | - $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
| 3163 | - if ($updatesource) |
|
| 3164 | - {
|
|
| 3165 | - $sql.= "fk_source = ".$sourceid; |
|
| 3166 | - $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3167 | - $sql.= " WHERE fk_target = ".$this->id; |
|
| 3168 | - $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3169 | - } |
|
| 3170 | - else if ($updatetarget) |
|
| 3171 | - {
|
|
| 3172 | - $sql.= "fk_target = ".$targetid; |
|
| 3173 | - $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3174 | - $sql.= " WHERE fk_source = ".$this->id; |
|
| 3175 | - $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3176 | - } |
|
| 3177 | - |
|
| 3178 | - dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
| 3179 | - if ($this->db->query($sql)) |
|
| 3180 | - {
|
|
| 3181 | - return 1; |
|
| 3182 | - } |
|
| 3183 | - else |
|
| 3184 | - {
|
|
| 3185 | - $this->error=$this->db->lasterror(); |
|
| 3186 | - return -1; |
|
| 3187 | - } |
|
| 3188 | - } |
|
| 3189 | - |
|
| 3190 | - /** |
|
| 3191 | - * Delete all links between an object $this |
|
| 3192 | - * |
|
| 3193 | - * @param int $sourceid Object source id |
|
| 3194 | - * @param string $sourcetype Object source type |
|
| 3195 | - * @param int $targetid Object target id |
|
| 3196 | - * @param string $targettype Object target type |
|
| 3197 | - * @param int $rowid Row id of line to delete. If defined, other parameters are not used. |
|
| 3198 | - * @return int >0 if OK, <0 if KO |
|
| 3199 | - * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
|
| 3200 | - */ |
|
| 3201 | - function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 3202 | - {
|
|
| 3203 | - $deletesource=false; |
|
| 3204 | - $deletetarget=false; |
|
| 3205 | - |
|
| 3206 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3207 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3208 | - |
|
| 3209 | - $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 3210 | - $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3211 | - $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3212 | - $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 3213 | - |
|
| 3214 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
| 3215 | - $sql.= " WHERE"; |
|
| 3216 | - if ($rowid > 0) |
|
| 3217 | - {
|
|
| 3218 | - $sql.=" rowid = ".$rowid; |
|
| 3219 | - } |
|
| 3220 | - else |
|
| 3221 | - {
|
|
| 3222 | - if ($deletesource) |
|
| 3223 | - {
|
|
| 3224 | - $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3225 | - $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3226 | - } |
|
| 3227 | - else if ($deletetarget) |
|
| 3228 | - {
|
|
| 3229 | - $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3230 | - $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3231 | - } |
|
| 3232 | - else |
|
| 3233 | - {
|
|
| 3234 | - $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3235 | - $sql.= " OR"; |
|
| 3236 | - $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3237 | - } |
|
| 3238 | - } |
|
| 3239 | - |
|
| 3240 | - dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
| 3241 | - if ($this->db->query($sql)) |
|
| 3242 | - {
|
|
| 3243 | - return 1; |
|
| 3244 | - } |
|
| 3245 | - else |
|
| 3246 | - {
|
|
| 3247 | - $this->error=$this->db->lasterror(); |
|
| 3248 | - $this->errors[]=$this->error; |
|
| 3249 | - return -1; |
|
| 3250 | - } |
|
| 3251 | - } |
|
| 3252 | - |
|
| 3253 | - /** |
|
| 3254 | - * Set status of an object |
|
| 3255 | - * |
|
| 3256 | - * @param int $status Status to set |
|
| 3257 | - * @param int $elementId Id of element to force (use this->id by default) |
|
| 3258 | - * @param string $elementType Type of element to force (use this->table_element by default) |
|
| 3259 | - * @param string $trigkey Trigger key to use for trigger |
|
| 3260 | - * @return int <0 if KO, >0 if OK |
|
| 3261 | - */ |
|
| 3262 | - function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
| 3263 | - {
|
|
| 3264 | - global $user,$langs,$conf; |
|
| 3265 | - |
|
| 3266 | - $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3267 | - |
|
| 3268 | - $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3269 | - $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3270 | - |
|
| 3271 | - $this->db->begin(); |
|
| 3272 | - |
|
| 3273 | - $fieldstatus="fk_statut"; |
|
| 3274 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3275 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3276 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3277 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3278 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3279 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3280 | - |
|
| 3281 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
| 3282 | - $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3283 | - // If status = 1 = validated, update also fk_user_valid |
|
| 3284 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3285 | - $sql.= " WHERE rowid=".$elementId; |
|
| 3286 | - |
|
| 3287 | - dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
| 3288 | - if ($this->db->query($sql)) |
|
| 3289 | - {
|
|
| 3290 | - $error = 0; |
|
| 3291 | - |
|
| 3292 | - // Try autoset of trigkey |
|
| 3293 | - if (empty($trigkey)) |
|
| 3294 | - {
|
|
| 3295 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3296 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3297 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3298 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3299 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3300 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3301 | - } |
|
| 3302 | - |
|
| 3303 | - if ($trigkey) |
|
| 3304 | - {
|
|
| 3305 | - // Appel des triggers |
|
| 3306 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3307 | - $interface=new Interfaces($this->db); |
|
| 3308 | - $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3309 | - if ($result < 0) {
|
|
| 3310 | - $error++; $this->errors=$interface->errors; |
|
| 3311 | - } |
|
| 3312 | - // Fin appel triggers |
|
| 3313 | - } |
|
| 850 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 851 | + /** |
|
| 852 | + * Update a link to contact line |
|
| 853 | + * |
|
| 854 | + * @param int $rowid Id of line contact-element |
|
| 855 | + * @param int $statut New status of link |
|
| 856 | + * @param int $type_contact_id Id of contact type (not modified if 0) |
|
| 857 | + * @param int $fk_socpeople Id of soc_people to update (not modified if 0) |
|
| 858 | + * @return int <0 if KO, >= 0 if OK |
|
| 859 | + */ |
|
| 860 | + function update_contact($rowid, $statut, $type_contact_id=0, $fk_socpeople=0) |
|
| 861 | + {
|
|
| 862 | + // phpcs:enable |
|
| 863 | + // Insert into database |
|
| 864 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
|
| 865 | + $sql.= " statut = ".$statut; |
|
| 866 | + if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 867 | + if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 868 | + $sql.= " where rowid = ".$rowid; |
|
| 869 | + $resql=$this->db->query($sql); |
|
| 870 | + if ($resql) |
|
| 871 | + {
|
|
| 872 | + return 0; |
|
| 873 | + } |
|
| 874 | + else |
|
| 875 | + {
|
|
| 876 | + $this->error=$this->db->lasterror(); |
|
| 877 | + return -1; |
|
| 878 | + } |
|
| 879 | + } |
|
| 3314 | 880 | |
| 3315 | - if (! $error) |
|
| 3316 | - {
|
|
| 3317 | - $this->db->commit(); |
|
| 881 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 882 | + /** |
|
| 883 | + * Delete a link to contact line |
|
| 884 | + * |
|
| 885 | + * @param int $rowid Id of contact link line to delete |
|
| 886 | + * @param int $notrigger Disable all triggers |
|
| 887 | + * @return int >0 if OK, <0 if KO |
|
| 888 | + */ |
|
| 889 | + function delete_contact($rowid, $notrigger=0) |
|
| 890 | + {
|
|
| 891 | + // phpcs:enable |
|
| 892 | + global $user; |
|
| 3318 | 893 | |
| 3319 | - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3320 | - {
|
|
| 3321 | - $this->statut = $status; |
|
| 3322 | - $this->status = $status; |
|
| 3323 | - } |
|
| 3324 | 894 | |
| 3325 | - return 1; |
|
| 3326 | - } |
|
| 3327 | - else |
|
| 3328 | - {
|
|
| 3329 | - $this->db->rollback(); |
|
| 3330 | - dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3331 | - return -1; |
|
| 3332 | - } |
|
| 3333 | - } |
|
| 3334 | - else |
|
| 3335 | - {
|
|
| 3336 | - $this->error=$this->db->lasterror(); |
|
| 3337 | - $this->db->rollback(); |
|
| 3338 | - return -1; |
|
| 3339 | - } |
|
| 3340 | - } |
|
| 3341 | - |
|
| 3342 | - |
|
| 3343 | - /** |
|
| 3344 | - * Load type of canvas of an object if it exists |
|
| 3345 | - * |
|
| 3346 | - * @param int $id Record id |
|
| 3347 | - * @param string $ref Record ref |
|
| 3348 | - * @return int <0 if KO, 0 if nothing done, >0 if OK |
|
| 3349 | - */ |
|
| 3350 | - function getCanvas($id=0,$ref='') |
|
| 3351 | - {
|
|
| 3352 | - global $conf; |
|
| 3353 | - |
|
| 3354 | - if (empty($id) && empty($ref)) return 0; |
|
| 3355 | - if (!empty(Globals::$conf->global->MAIN_DISABLE_CANVAS)) |
|
| 3356 | - return 0; // To increase speed. Not enabled by default. |
|
| 895 | + $this->db->begin(); |
|
| 3357 | 896 | |
| 3358 | - // Clean parameters |
|
| 3359 | - $ref = trim($ref); |
|
| 3360 | - |
|
| 3361 | - $sql = "SELECT rowid, canvas"; |
|
| 3362 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3363 | - $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
|
| 3364 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3365 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3366 | - |
|
| 3367 | - $resql = $this->db->query($sql); |
|
| 3368 | - if ($resql) |
|
| 3369 | - {
|
|
| 3370 | - $obj = $this->db->fetch_object($resql); |
|
| 3371 | - if ($obj) |
|
| 3372 | - {
|
|
| 3373 | - $this->canvas = $obj->canvas; |
|
| 3374 | - return 1; |
|
| 3375 | - } |
|
| 3376 | - else return 0; |
|
| 3377 | - } |
|
| 3378 | - else |
|
| 3379 | - {
|
|
| 3380 | - dol_print_error($this->db); |
|
| 3381 | - return -1; |
|
| 3382 | - } |
|
| 3383 | - } |
|
| 3384 | - |
|
| 3385 | - |
|
| 3386 | - /** |
|
| 3387 | - * Get special code of a line |
|
| 3388 | - * |
|
| 3389 | - * @param int $lineid Id of line |
|
| 3390 | - * @return int Special code |
|
| 3391 | - */ |
|
| 3392 | - function getSpecialCode($lineid) |
|
| 3393 | - {
|
|
| 3394 | - $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 3395 | - $sql.= ' WHERE rowid = '.$lineid; |
|
| 3396 | - $resql = $this->db->query($sql); |
|
| 3397 | - if ($resql) |
|
| 3398 | - {
|
|
| 3399 | - $row = $this->db->fetch_row($resql); |
|
| 3400 | - return $row[0]; |
|
| 3401 | - } |
|
| 3402 | - } |
|
| 3403 | - |
|
| 3404 | - /** |
|
| 3405 | - * Function to check if an object is used by others. |
|
| 3406 | - * Check is done into this->childtables. There is no check into llx_element_element. |
|
| 3407 | - * |
|
| 3408 | - * @param int $id Force id of object |
|
| 3409 | - * @return int <0 if KO, 0 if not used, >0 if already used |
|
| 3410 | - */ |
|
| 3411 | - function isObjectUsed($id=0) |
|
| 3412 | - {
|
|
| 3413 | - global $langs; |
|
| 3414 | - |
|
| 3415 | - if (empty($id)) $id=$this->id; |
|
| 3416 | - |
|
| 3417 | - // Check parameters |
|
| 3418 | - if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3419 | - {
|
|
| 3420 | - dol_print_error('Called isObjectUsed on a class with property this->childtables not defined');
|
|
| 3421 | - return -1; |
|
| 3422 | - } |
|
| 3423 | - |
|
| 3424 | - $arraytoscan = $this->childtables; |
|
| 3425 | - // For backward compatibility, we check if array is old format array('table1', 'table2', ...)
|
|
| 3426 | - $tmparray=array_keys($this->childtables); |
|
| 3427 | - if (is_numeric($tmparray[0])) |
|
| 3428 | - {
|
|
| 3429 | - $arraytoscan = array_flip($this->childtables); |
|
| 3430 | - } |
|
| 3431 | - |
|
| 3432 | - // Test if child exists |
|
| 3433 | - $haschild=0; |
|
| 3434 | - foreach($arraytoscan as $table => $elementname) |
|
| 3435 | - {
|
|
| 3436 | - //print $id.'-'.$table.'-'.$elementname.'<br>'; |
|
| 3437 | - // Check if third party can be deleted |
|
| 3438 | - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
| 3439 | - $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3440 | - $resql=$this->db->query($sql); |
|
| 3441 | - if ($resql) |
|
| 3442 | - {
|
|
| 3443 | - $obj=$this->db->fetch_object($resql); |
|
| 3444 | - if ($obj->nb > 0) |
|
| 3445 | - {
|
|
| 3446 | - $langs->load("errors");
|
|
| 3447 | - //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
|
| 3448 | - $haschild += $obj->nb; |
|
| 3449 | - if (is_numeric($elementname)) // old usage |
|
| 3450 | - {
|
|
| 3451 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3452 | - } |
|
| 3453 | - else // new usage: $elementname=Translation key |
|
| 3454 | - {
|
|
| 3455 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
|
| 3456 | - } |
|
| 3457 | - break; // We found at least one, we stop here |
|
| 3458 | - } |
|
| 3459 | - } |
|
| 3460 | - else |
|
| 3461 | - {
|
|
| 3462 | - $this->errors[]=$this->db->lasterror(); |
|
| 3463 | - return -1; |
|
| 3464 | - } |
|
| 3465 | - } |
|
| 3466 | - if ($haschild > 0) |
|
| 3467 | - {
|
|
| 3468 | - $this->errors[]="ErrorRecordHasChildren"; |
|
| 3469 | - return $haschild; |
|
| 3470 | - } |
|
| 3471 | - else return 0; |
|
| 3472 | - } |
|
| 3473 | - |
|
| 3474 | - /** |
|
| 3475 | - * Function to say how many lines object contains |
|
| 3476 | - * |
|
| 3477 | - * @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 |
|
| 3478 | - * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
|
| 3479 | - */ |
|
| 3480 | - function hasProductsOrServices($predefined=-1) |
|
| 3481 | - {
|
|
| 3482 | - $nb=0; |
|
| 3483 | - |
|
| 3484 | - foreach($this->lines as $key => $val) |
|
| 3485 | - {
|
|
| 3486 | - $qualified=0; |
|
| 3487 | - if ($predefined == -1) $qualified=1; |
|
| 3488 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3489 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3490 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3491 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3492 | - if ($qualified) $nb++; |
|
| 3493 | - } |
|
| 3494 | - dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
| 3495 | - return $nb; |
|
| 3496 | - } |
|
| 3497 | - |
|
| 3498 | - /** |
|
| 3499 | - * Function that returns the total amount HT of discounts applied for all lines. |
|
| 3500 | - * |
|
| 3501 | - * @return float |
|
| 3502 | - */ |
|
| 3503 | - function getTotalDiscount() |
|
| 3504 | - {
|
|
| 3505 | - $total_discount=0.00; |
|
| 3506 | - |
|
| 3507 | - $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
|
| 3508 | - $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3509 | - $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3510 | - |
|
| 3511 | - dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
| 3512 | - $resql = $this->db->query($sql); |
|
| 3513 | - if ($resql) |
|
| 3514 | - {
|
|
| 3515 | - $num=$this->db->num_rows($resql); |
|
| 3516 | - $i=0; |
|
| 3517 | - while ($i < $num) |
|
| 3518 | - {
|
|
| 3519 | - $obj = $this->db->fetch_object($resql); |
|
| 3520 | - |
|
| 3521 | - $pu_ht = $obj->pu_ht; |
|
| 3522 | - $qty= $obj->qty; |
|
| 3523 | - $total_ht = $obj->total_ht; |
|
| 3524 | - |
|
| 3525 | - $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
|
| 3526 | - $total_discount += $total_discount_line; |
|
| 3527 | - |
|
| 3528 | - $i++; |
|
| 3529 | - } |
|
| 3530 | - } |
|
| 3531 | - |
|
| 3532 | - //print $total_discount; exit; |
|
| 3533 | - return price2num($total_discount); |
|
| 3534 | - } |
|
| 3535 | - |
|
| 3536 | - |
|
| 3537 | - /** |
|
| 3538 | - * Return into unit=0, the calculated total of weight and volume of all lines * qty |
|
| 3539 | - * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. |
|
| 3540 | - * |
|
| 3541 | - * @return array array('weight'=>...,'volume'=>...)
|
|
| 3542 | - */ |
|
| 3543 | - function getTotalWeightVolume() |
|
| 3544 | - {
|
|
| 3545 | - $totalWeight = 0; |
|
| 3546 | - $totalVolume = 0; |
|
| 3547 | - // defined for shipment only |
|
| 3548 | - $totalOrdered = ''; |
|
| 3549 | - // defined for shipment only |
|
| 3550 | - $totalToShip = ''; |
|
| 3551 | - |
|
| 3552 | - foreach ($this->lines as $line) |
|
| 3553 | - {
|
|
| 3554 | - if (isset($line->qty_asked)) |
|
| 3555 | - {
|
|
| 3556 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3557 | - $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3558 | - } |
|
| 3559 | - if (isset($line->qty_shipped)) |
|
| 3560 | - {
|
|
| 3561 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3562 | - $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3563 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 897 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 898 | + $sql.= " WHERE rowid =".$rowid; |
|
| 899 | + |
|
| 900 | + dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); |
|
| 901 | + if ($this->db->query($sql)) |
|
| 902 | + {
|
|
| 903 | + if (! $notrigger) |
|
| 3564 | 904 | {
|
| 3565 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3566 | - $totalToShip+=$line->qty; // defined for reception only |
|
| 3567 | - } |
|
| 3568 | - |
|
| 3569 | - // Define qty, weight, volume, weight_units, volume_units |
|
| 3570 | - if ($this->element == 'shipping') {
|
|
| 3571 | - // for shipments |
|
| 3572 | - $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
|
| 3573 | - } |
|
| 3574 | - else {
|
|
| 3575 | - $qty = $line->qty ? $line->qty : 0; |
|
| 3576 | - } |
|
| 3577 | - |
|
| 3578 | - $weight = $line->weight ? $line->weight : 0; |
|
| 3579 | - ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
| 3580 | - $volume = $line->volume ? $line->volume : 0; |
|
| 3581 | - ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
| 905 | + $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); |
|
| 906 | + if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 907 | + } |
|
| 3582 | 908 | |
| 3583 | - $weight_units=$line->weight_units; |
|
| 3584 | - ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
| 3585 | - $volume_units=$line->volume_units; |
|
| 3586 | - ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
| 909 | + $this->db->commit(); |
|
| 910 | + return 1; |
|
| 911 | + } |
|
| 912 | + else |
|
| 913 | + {
|
|
| 914 | + $this->error=$this->db->lasterror(); |
|
| 915 | + $this->db->rollback(); |
|
| 916 | + return -1; |
|
| 917 | + } |
|
| 918 | + } |
|
| 3587 | 919 | |
| 3588 | - $weightUnit=0; |
|
| 3589 | - $volumeUnit=0; |
|
| 3590 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3591 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 920 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 921 | + /** |
|
| 922 | + * Delete all links between an object $this and all its contacts |
|
| 923 | + * |
|
| 924 | + * @param string $source '' or 'internal' or 'external' |
|
| 925 | + * @param string $code Type of contact (code or id) |
|
| 926 | + * @return int >0 if OK, <0 if KO |
|
| 927 | + */ |
|
| 928 | + function delete_linked_contact($source='',$code='') |
|
| 929 | + {
|
|
| 930 | + // phpcs:enable |
|
| 931 | + $temp = array(); |
|
| 932 | + $typeContact = $this->liste_type_contact($source,'',0,0,$code); |
|
| 3592 | 933 | |
| 3593 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3594 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 934 | + foreach($typeContact as $key => $value) |
|
| 935 | + {
|
|
| 936 | + array_push($temp,$key); |
|
| 937 | + } |
|
| 938 | + $listId = implode(",", $temp);
|
|
| 3595 | 939 | |
| 3596 | - //var_dump($line->volume_units); |
|
| 3597 | - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3598 | - {
|
|
| 3599 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3600 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3601 | - } |
|
| 3602 | - else {
|
|
| 3603 | - if ($weight_units == 99) {
|
|
| 3604 | - // conversion 1 Pound = 0.45359237 KG |
|
| 3605 | - $trueWeightUnit = 0.45359237; |
|
| 3606 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3607 | - } elseif ($weight_units == 98) {
|
|
| 3608 | - // conversion 1 Ounce = 0.0283495 KG |
|
| 3609 | - $trueWeightUnit = 0.0283495; |
|
| 3610 | - $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3611 | - } |
|
| 3612 | - else |
|
| 3613 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3614 | - } |
|
| 3615 | - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3616 | - {
|
|
| 3617 | - //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
|
| 3618 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3619 | - //print $line->volume; |
|
| 3620 | - $totalVolume += $volume * $qty * $trueVolumeUnit; |
|
| 3621 | - } |
|
| 3622 | - else |
|
| 3623 | - {
|
|
| 3624 | - $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3625 | - } |
|
| 3626 | - } |
|
| 3627 | - |
|
| 3628 | - return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip);
|
|
| 3629 | - } |
|
| 3630 | - |
|
| 3631 | - |
|
| 3632 | - /** |
|
| 3633 | - * Set extra parameters |
|
| 3634 | - * |
|
| 3635 | - * @return int <0 if KO, >0 if OK |
|
| 3636 | - */ |
|
| 3637 | - function setExtraParameters() |
|
| 3638 | - {
|
|
| 3639 | - $this->db->begin(); |
|
| 3640 | - |
|
| 3641 | - $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3642 | - |
|
| 3643 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3644 | - $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3645 | - $sql.= " WHERE rowid = ".$this->id; |
|
| 3646 | - |
|
| 3647 | - dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
| 3648 | - $resql = $this->db->query($sql); |
|
| 3649 | - if (! $resql) |
|
| 3650 | - {
|
|
| 3651 | - $this->error=$this->db->lasterror(); |
|
| 3652 | - $this->db->rollback(); |
|
| 3653 | - return -1; |
|
| 3654 | - } |
|
| 3655 | - else |
|
| 3656 | - {
|
|
| 3657 | - $this->db->commit(); |
|
| 3658 | - return 1; |
|
| 3659 | - } |
|
| 3660 | - } |
|
| 940 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
|
| 941 | + $sql.= " WHERE element_id = ".$this->id; |
|
| 942 | + if ($listId) |
|
| 943 | + $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 3661 | 944 | |
| 945 | + dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
|
| 946 | + if ($this->db->query($sql)) |
|
| 947 | + {
|
|
| 948 | + return 1; |
|
| 949 | + } |
|
| 950 | + else |
|
| 951 | + {
|
|
| 952 | + $this->error=$this->db->lasterror(); |
|
| 953 | + return -1; |
|
| 954 | + } |
|
| 955 | + } |
|
| 3662 | 956 | |
| 3663 | 957 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 3664 | - /** |
|
| 3665 | - * Return incoterms informations |
|
| 3666 | - * TODO Use a cache for label get |
|
| 3667 | - * |
|
| 3668 | - * @return string incoterms info |
|
| 3669 | - */ |
|
| 3670 | - function display_incoterms() |
|
| 3671 | - {
|
|
| 958 | + /** |
|
| 959 | + * Get array of all contacts for an object |
|
| 960 | + * |
|
| 961 | + * @param int $statut Status of links to get (-1=all) |
|
| 962 | + * @param string $source Source of contact: external or thirdparty (llx_socpeople) or internal (llx_user) |
|
| 963 | + * @param int $list 0:Return array contains all properties, 1:Return array contains just id |
|
| 964 | + * @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
|
|
| 965 | + * @return array|int Array of contacts, -1 if error |
|
| 966 | + */ |
|
| 967 | + function liste_contact($statut=-1,$source='external',$list=0,$code='') |
|
| 968 | + {
|
|
| 3672 | 969 | // phpcs:enable |
| 3673 | - $out = ''; |
|
| 3674 | - $this->libelle_incoterms = ''; |
|
| 3675 | - if (!empty($this->fk_incoterms)) |
|
| 3676 | - {
|
|
| 3677 | - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3678 | - $result = $this->db->query($sql); |
|
| 3679 | - if ($result) |
|
| 3680 | - {
|
|
| 3681 | - $res = $this->db->fetch_object($result); |
|
| 3682 | - $out .= $res->code; |
|
| 3683 | - } |
|
| 3684 | - } |
|
| 3685 | - |
|
| 3686 | - $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3687 | - |
|
| 3688 | - return $out; |
|
| 3689 | - } |
|
| 3690 | - |
|
| 3691 | - /** |
|
| 3692 | - * Return incoterms informations for pdf display |
|
| 3693 | - * |
|
| 3694 | - * @return string incoterms info |
|
| 3695 | - */ |
|
| 3696 | - function getIncotermsForPDF() |
|
| 3697 | - {
|
|
| 3698 | - $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3699 | - $resql = $this->db->query($sql); |
|
| 3700 | - if ($resql) |
|
| 3701 | - {
|
|
| 3702 | - $num = $this->db->num_rows($resql); |
|
| 3703 | - if ($num > 0) |
|
| 3704 | - {
|
|
| 3705 | - $res = $this->db->fetch_object($resql); |
|
| 3706 | - return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
| 3707 | - } |
|
| 3708 | - else |
|
| 3709 | - {
|
|
| 3710 | - return ''; |
|
| 3711 | - } |
|
| 3712 | - } |
|
| 3713 | - else |
|
| 3714 | - {
|
|
| 3715 | - $this->errors[] = $this->db->lasterror(); |
|
| 3716 | - return false; |
|
| 3717 | - } |
|
| 3718 | - } |
|
| 3719 | - |
|
| 3720 | - /** |
|
| 3721 | - * Define incoterms values of current object |
|
| 3722 | - * |
|
| 3723 | - * @param int $id_incoterm Id of incoterm to set or '' to remove |
|
| 3724 | - * @param string $location location of incoterm |
|
| 3725 | - * @return int <0 if KO, >0 if OK |
|
| 3726 | - */ |
|
| 3727 | - function setIncoterms($id_incoterm, $location) |
|
| 3728 | - {
|
|
| 3729 | - if ($this->id && $this->table_element) |
|
| 3730 | - {
|
|
| 3731 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3732 | - $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3733 | - $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3734 | - $sql.= " WHERE rowid = " . $this->id; |
|
| 3735 | - dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
| 3736 | - $resql=$this->db->query($sql); |
|
| 3737 | - if ($resql) |
|
| 3738 | - {
|
|
| 3739 | - $this->fk_incoterms = $id_incoterm; |
|
| 3740 | - $this->location_incoterms = $location; |
|
| 970 | + global $langs; |
|
| 971 | + |
|
| 972 | + $tab=array(); |
|
| 973 | + |
|
| 974 | + $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 |
|
| 975 | + if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 976 | + if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 977 | + $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
|
| 978 | + $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
|
| 979 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
|
| 980 | + $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
|
| 981 | + if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 982 | + if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 983 | + $sql.= " WHERE ec.element_id =".$this->id; |
|
| 984 | + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 985 | + $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
|
| 986 | + if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 987 | + if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 988 | + if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 989 | + $sql.= " AND tc.active=1"; |
|
| 990 | + if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 991 | + $sql.=" ORDER BY t.lastname ASC"; |
|
| 992 | + |
|
| 993 | + dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
|
| 994 | + $resql=$this->db->query($sql); |
|
| 995 | + if ($resql) |
|
| 996 | + {
|
|
| 997 | + $num=$this->db->num_rows($resql); |
|
| 998 | + $i=0; |
|
| 999 | + while ($i < $num) |
|
| 1000 | + {
|
|
| 1001 | + $obj = $this->db->fetch_object($resql); |
|
| 1002 | + |
|
| 1003 | + if (! $list) |
|
| 1004 | + {
|
|
| 1005 | + $transkey="TypeContact_".$obj->element."_".$obj->source."_".$obj->code; |
|
| 1006 | + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1007 | + $tab[$i]=array('source'=>$obj->source,'socid'=>$obj->socid,'id'=>$obj->id,
|
|
| 1008 | + 'nom'=>$obj->lastname, // For backward compatibility |
|
| 1009 | + 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
|
| 1010 | + 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
|
| 1011 | + } |
|
| 1012 | + else |
|
| 1013 | + {
|
|
| 1014 | + $tab[$i]=$obj->id; |
|
| 1015 | + } |
|
| 3741 | 1016 | |
| 3742 | - $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3743 | - $res = $this->db->query($sql); |
|
| 3744 | - if ($res) |
|
| 3745 | - {
|
|
| 3746 | - $obj = $this->db->fetch_object($res); |
|
| 3747 | - $this->libelle_incoterms = $obj->libelle; |
|
| 3748 | - } |
|
| 3749 | - return 1; |
|
| 3750 | - } |
|
| 3751 | - else |
|
| 3752 | - {
|
|
| 3753 | - $this->errors[] = $this->db->lasterror(); |
|
| 3754 | - return -1; |
|
| 3755 | - } |
|
| 3756 | - } |
|
| 3757 | - else return -1; |
|
| 3758 | - } |
|
| 3759 | - |
|
| 3760 | - |
|
| 3761 | - // -------------------- |
|
| 3762 | - // TODO: All functions here must be redesigned and moved as they are not business functions but output functions |
|
| 3763 | - // -------------------- |
|
| 3764 | - |
|
| 3765 | - /* This is to show add lines */ |
|
| 3766 | - |
|
| 3767 | - /** |
|
| 3768 | - * Show add free and predefined products/services form |
|
| 3769 | - * |
|
| 3770 | - * @param int $dateSelector 1=Show also date range input fields |
|
| 3771 | - * @param Societe $seller Object thirdparty who sell |
|
| 3772 | - * @param Societe $buyer Object thirdparty who buy |
|
| 3773 | - * @return void |
|
| 3774 | - */ |
|
| 3775 | - function formAddObjectLine($dateSelector, $seller, $buyer) |
|
| 3776 | - {
|
|
| 3777 | - global $conf,$user,$langs,$object,$hookmanager; |
|
| 3778 | - global $form,$bcnd,$var; |
|
| 3779 | - |
|
| 3780 | - // Line extrafield |
|
| 3781 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3782 | - $extrafieldsline = new AlExtraFields($this->db); |
|
| 3783 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 1017 | + $i++; |
|
| 1018 | + } |
|
| 3784 | 1019 | |
| 3785 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 3786 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 3787 | - $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 3788 | - foreach($dirtpls as $reldir) |
|
| 3789 | - {
|
|
| 3790 | - $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
| 3791 | - if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 3792 | - $res=@include $tpl; |
|
| 3793 | - } else {
|
|
| 3794 | - $res=include $tpl; // for debug |
|
| 3795 | - } |
|
| 3796 | - if ($res) break; |
|
| 3797 | - } |
|
| 3798 | - } |
|
| 3799 | - |
|
| 3800 | - |
|
| 3801 | - |
|
| 3802 | - /* This is to show array of line of details */ |
|
| 3803 | - |
|
| 3804 | - |
|
| 3805 | - /** |
|
| 3806 | - * Return HTML table for object lines |
|
| 3807 | - * TODO Move this into an output class file (htmlline.class.php) |
|
| 3808 | - * If lines are into a template, title must also be into a template |
|
| 3809 | - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 3810 | - * |
|
| 3811 | - * @param string $action Action code |
|
| 3812 | - * @param string $seller Object of seller third party |
|
| 3813 | - * @param string $buyer Object of buyer third party |
|
| 3814 | - * @param int $selected Object line selected |
|
| 3815 | - * @param int $dateSelector 1=Show also date range input fields |
|
| 3816 | - * @return void |
|
| 3817 | - */ |
|
| 3818 | - function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3819 | - {
|
|
| 3820 | - global $conf, $hookmanager, $langs, $user; |
|
| 3821 | - // TODO We should not use global var for this ! |
|
| 3822 | - global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
|
| 3823 | - |
|
| 3824 | - // Define usemargins |
|
| 3825 | - $usemargins=0; |
|
| 3826 | - if (!empty(Globals::$conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande')))
|
|
| 3827 | - $usemargins = 1; |
|
| 1020 | + return $tab; |
|
| 1021 | + } |
|
| 1022 | + else |
|
| 1023 | + {
|
|
| 1024 | + $this->error=$this->db->lasterror(); |
|
| 1025 | + dol_print_error($this->db); |
|
| 1026 | + return -1; |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 3828 | 1029 | |
| 3829 | - $num = count($this->lines); |
|
| 3830 | 1030 | |
| 3831 | - // Line extrafield |
|
| 3832 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3833 | - $extrafieldsline = new AlExtraFields($this->db); |
|
| 3834 | - $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 1031 | + /** |
|
| 1032 | + * Update status of a contact linked to object |
|
| 1033 | + * |
|
| 1034 | + * @param int $rowid Id of link between object and contact |
|
| 1035 | + * @return int <0 if KO, >=0 if OK |
|
| 1036 | + */ |
|
| 1037 | + function swapContactStatus($rowid) |
|
| 1038 | + {
|
|
| 1039 | + $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; |
|
| 1040 | + $sql.= " tc.code, tc.libelle"; |
|
| 1041 | + //$sql.= ", s.fk_soc"; |
|
| 1042 | + $sql.= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)";
|
|
| 1043 | + //$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 |
|
| 1044 | + $sql.= " WHERE ec.rowid =".$rowid; |
|
| 1045 | + $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
|
| 1046 | + $sql.= " AND tc.element = '".$this->db->escape($this->element)."'"; |
|
| 1047 | + |
|
| 1048 | + dol_syslog(get_class($this)."::swapContactStatus", LOG_DEBUG); |
|
| 1049 | + $resql=$this->db->query($sql); |
|
| 1050 | + if ($resql) |
|
| 1051 | + {
|
|
| 1052 | + $obj = $this->db->fetch_object($resql); |
|
| 1053 | + $newstatut = ($obj->statut == 4) ? 5 : 4; |
|
| 1054 | + $result = $this->update_contact($rowid, $newstatut); |
|
| 1055 | + $this->db->free($resql); |
|
| 1056 | + return $result; |
|
| 1057 | + } |
|
| 1058 | + else |
|
| 1059 | + {
|
|
| 1060 | + $this->error=$this->db->error(); |
|
| 1061 | + dol_print_error($this->db); |
|
| 1062 | + return -1; |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 3835 | 1065 | |
| 3836 | - $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3837 | - $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3838 | - if (empty($reshook)) |
|
| 3839 | - {
|
|
| 3840 | - // Title line |
|
| 3841 | - print "<thead>\n"; |
|
| 1066 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1067 | + /** |
|
| 1068 | + * Return array with list of possible values for type of contacts |
|
| 1069 | + * |
|
| 1070 | + * @param string $source 'internal', 'external' or 'all' |
|
| 1071 | + * @param string $order Sort order by : 'position', 'code', 'rowid'... |
|
| 1072 | + * @param int $option 0=Return array id->label, 1=Return array code->label |
|
| 1073 | + * @param int $activeonly 0=all status of contact, 1=only the active |
|
| 1074 | + * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') |
|
| 1075 | + * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) |
|
| 1076 | + */ |
|
| 1077 | + function liste_type_contact($source='internal', $order='position', $option=0, $activeonly=0, $code='') |
|
| 1078 | + {
|
|
| 1079 | + // phpcs:enable |
|
| 1080 | + global $langs; |
|
| 1081 | + |
|
| 1082 | + if (empty($order)) $order='position'; |
|
| 1083 | + if ($order == 'position') $order.=',code'; |
|
| 1084 | + |
|
| 1085 | + $tab = array(); |
|
| 1086 | + $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
|
| 1087 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1088 | + $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
|
| 1089 | + if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1090 | + if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1091 | + if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1092 | + $sql.= $this->db->order($order,'ASC'); |
|
| 1093 | + |
|
| 1094 | + //print "sql=".$sql; |
|
| 1095 | + $resql=$this->db->query($sql); |
|
| 1096 | + if ($resql) |
|
| 1097 | + {
|
|
| 1098 | + $num=$this->db->num_rows($resql); |
|
| 1099 | + $i=0; |
|
| 1100 | + while ($i < $num) |
|
| 1101 | + {
|
|
| 1102 | + $obj = $this->db->fetch_object($resql); |
|
| 3842 | 1103 | |
| 3843 | - print '<tr class="liste_titre nodrag nodrop">'; |
|
| 1104 | + $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
|
| 1105 | + $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
|
| 1106 | + if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1107 | + else $tab[$obj->code]=$libelle_type; |
|
| 1108 | + $i++; |
|
| 1109 | + } |
|
| 1110 | + return $tab; |
|
| 1111 | + } |
|
| 1112 | + else |
|
| 1113 | + {
|
|
| 1114 | + $this->error=$this->db->lasterror(); |
|
| 1115 | + //dol_print_error($this->db); |
|
| 1116 | + return null; |
|
| 1117 | + } |
|
| 1118 | + } |
|
| 3844 | 1119 | |
| 3845 | - // Adds a line numbering column |
|
| 3846 | - if (!empty(Globals::$conf->global->MAIN_VIEW_LINE_NUMBER)) |
|
| 3847 | - print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 1120 | + /** |
|
| 1121 | + * Return id of contacts for a source and a contact code. |
|
| 1122 | + * Example: contact client de facturation ('external', 'BILLING')
|
|
| 1123 | + * Example: contact client de livraison ('external', 'SHIPPING')
|
|
| 1124 | + * Example: contact interne suivi paiement ('internal', 'SALESREPFOLL')
|
|
| 1125 | + * |
|
| 1126 | + * @param string $source 'external' or 'internal' |
|
| 1127 | + * @param string $code 'BILLING', 'SHIPPING', 'SALESREPFOLL', ... |
|
| 1128 | + * @param int $status limited to a certain status |
|
| 1129 | + * @return array List of id for such contacts |
|
| 1130 | + */ |
|
| 1131 | + function getIdContact($source,$code,$status=0) |
|
| 1132 | + {
|
|
| 1133 | + global $conf; |
|
| 3848 | 1134 | |
| 3849 | - // Description |
|
| 3850 | - print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
|
| 1135 | + $result=array(); |
|
| 1136 | + $i=0; |
|
| 1137 | + //cas particulier pour les expeditions |
|
| 1138 | + if($this->element=='shipping' && $this->origin_id != 0) {
|
|
| 1139 | + $id=$this->origin_id; |
|
| 1140 | + $element='commande'; |
|
| 1141 | + } else if($this->element=='reception' && $this->origin_id != 0) {
|
|
| 1142 | + $id=$this->origin_id; |
|
| 1143 | + $element='order_supplier'; |
|
| 1144 | + } else {
|
|
| 1145 | + $id=$this->id; |
|
| 1146 | + $element=$this->element; |
|
| 1147 | + } |
|
| 3851 | 1148 | |
| 3852 | - if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') |
|
| 3853 | - {
|
|
| 3854 | - print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>';
|
|
| 3855 | - } |
|
| 1149 | + $sql = "SELECT ec.fk_socpeople"; |
|
| 1150 | + $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
|
| 1151 | + if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1152 | + if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1153 | + $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
|
| 1154 | + $sql.= " WHERE ec.element_id = ".$id; |
|
| 1155 | + $sql.= " AND ec.fk_socpeople = c.rowid"; |
|
| 1156 | + if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1157 | + if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1158 | + $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
|
| 1159 | + $sql.= " AND tc.element = '".$element."'"; |
|
| 1160 | + $sql.= " AND tc.source = '".$source."'"; |
|
| 1161 | + $sql.= " AND tc.code = '".$code."'"; |
|
| 1162 | + $sql.= " AND tc.active = 1"; |
|
| 1163 | + if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1164 | + |
|
| 1165 | + dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
|
| 1166 | + $resql=$this->db->query($sql); |
|
| 1167 | + if ($resql) |
|
| 1168 | + {
|
|
| 1169 | + while ($obj = $this->db->fetch_object($resql)) |
|
| 1170 | + {
|
|
| 1171 | + $result[$i]=$obj->fk_socpeople; |
|
| 1172 | + $i++; |
|
| 1173 | + } |
|
| 1174 | + } |
|
| 1175 | + else |
|
| 1176 | + {
|
|
| 1177 | + $this->error=$this->db->error(); |
|
| 1178 | + return null; |
|
| 1179 | + } |
|
| 3856 | 1180 | |
| 3857 | - // VAT |
|
| 3858 | - print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>';
|
|
| 1181 | + return $result; |
|
| 1182 | + } |
|
| 3859 | 1183 | |
| 3860 | - // Price HT |
|
| 3861 | - print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
|
|
| 1184 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1185 | + /** |
|
| 1186 | + * Load object contact with id=$this->contactid into $this->contact |
|
| 1187 | + * |
|
| 1188 | + * @param int $contactid Id du contact. Use this->contactid if empty. |
|
| 1189 | + * @return int <0 if KO, >0 if OK |
|
| 1190 | + */ |
|
| 1191 | + function fetch_contact($contactid=null) |
|
| 1192 | + {
|
|
| 1193 | + // phpcs:enable |
|
| 1194 | + if (empty($contactid)) $contactid=$this->contactid; |
|
| 3862 | 1195 | |
| 3863 | - // Multicurrency |
|
| 3864 | - if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) |
|
| 3865 | - print '<td class="linecoluht_currency" align="right" width="80">' . $langs->trans('PriceUHTCurrency', $this->multicurrency_code) . '</td>';
|
|
| 1196 | + if (empty($contactid)) return 0; |
|
| 3866 | 1197 | |
| 3867 | - if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
|
|
| 1198 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
| 1199 | + $contact = new Contact($this->db); |
|
| 1200 | + $result=$contact->fetch($contactid); |
|
| 1201 | + $this->contact = $contact; |
|
| 1202 | + return $result; |
|
| 1203 | + } |
|
| 3868 | 1204 | |
| 3869 | - // Qty |
|
| 3870 | - print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
|
| 1205 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1206 | + /** |
|
| 1207 | + * Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty |
|
| 1208 | + * |
|
| 1209 | + * @param int $force_thirdparty_id Force thirdparty id |
|
| 1210 | + * @return int <0 if KO, >0 if OK |
|
| 1211 | + */ |
|
| 1212 | + function fetch_thirdparty($force_thirdparty_id=0) |
|
| 1213 | + {
|
|
| 1214 | + // phpcs:enable |
|
| 1215 | + global $conf; |
|
| 3871 | 1216 | |
| 3872 | - if (Globals::$conf->global->PRODUCT_USE_UNITS) {
|
|
| 3873 | - print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
|
|
| 3874 | - } |
|
| 1217 | + if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1218 | + return 0; |
|
| 3875 | 1219 | |
| 3876 | - // Reduction short |
|
| 3877 | - print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
|
|
| 1220 | + require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
|
| 3878 | 1221 | |
| 3879 | - if ($this->situation_cycle_ref) {
|
|
| 3880 | - print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
|
|
| 3881 | - } |
|
| 1222 | + $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
|
| 1223 | + if ($force_thirdparty_id) |
|
| 1224 | + $idtofetch = $force_thirdparty_id; |
|
| 3882 | 1225 | |
| 3883 | - if ($usemargins && !empty(Globals::$conf->margin->enabled) && empty($user->societe_id)) {
|
|
| 3884 | - if (!empty($user->rights->margins->creer)) |
|
| 3885 | - {
|
|
| 3886 | - if (Globals::$conf->global->MARGIN_TYPE == "1") |
|
| 3887 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
|
|
| 3888 | - else |
|
| 3889 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
|
| 3890 | - } |
|
| 1226 | + if ($idtofetch) {
|
|
| 1227 | + $thirdparty = new Societe($this->db); |
|
| 1228 | + $result = $thirdparty->fetch($idtofetch); |
|
| 1229 | + $this->thirdparty = $thirdparty; |
|
| 3891 | 1230 | |
| 3892 | - if (!empty(Globals::$conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3893 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
|
| 3894 | - if (!empty(Globals::$conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3895 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
|
| 3896 | - } |
|
| 1231 | + // Use first price level if level not defined for third party |
|
| 1232 | + if (!empty(Globals::$conf->global->PRODUIT_MULTIPRICES) && empty($this->thirdparty->price_level)) {
|
|
| 1233 | + $this->thirdparty->price_level = 1; |
|
| 1234 | + } |
|
| 3897 | 1235 | |
| 3898 | - // Total HT |
|
| 3899 | - print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
|
|
| 1236 | + return $result; |
|
| 1237 | + } else |
|
| 1238 | + return -1; |
|
| 1239 | + } |
|
| 3900 | 1240 | |
| 3901 | - // Multicurrency |
|
| 3902 | - if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) |
|
| 3903 | - print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>';
|
|
| 3904 | 1241 | |
| 3905 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
|
| 1242 | + /** |
|
| 1243 | + * Looks for an object with ref matching the wildcard provided |
|
| 1244 | + * It does only work when $this->table_ref_field is set |
|
| 1245 | + * |
|
| 1246 | + * @param string $ref Wildcard |
|
| 1247 | + * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO |
|
| 1248 | + */ |
|
| 1249 | + public function fetchOneLike($ref) |
|
| 1250 | + {
|
|
| 1251 | + if (!$this->table_ref_field) {
|
|
| 1252 | + return 0; |
|
| 1253 | + } |
|
| 3906 | 1254 | |
| 3907 | - print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 1255 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE '.$this->table_ref_field.' LIKE "'.$this->db->escape($ref).'" LIMIT 1'; |
|
| 3908 | 1256 | |
| 3909 | - print '<td class="linecoldelete" width="10"></td>'; |
|
| 1257 | + $query = $this->db->query($sql); |
|
| 3910 | 1258 | |
| 3911 | - print '<td class="linecolmove" width="10"></td>'; |
|
| 1259 | + if (!$this->db->num_rows($query)) {
|
|
| 1260 | + return 0; |
|
| 1261 | + } |
|
| 3912 | 1262 | |
| 3913 | - if($action == 'selectlines') |
|
| 3914 | - {
|
|
| 3915 | - print '<td class="linecolcheckall" align="center">'; |
|
| 3916 | - print '<input type="checkbox" class="linecheckboxtoggle" />'; |
|
| 3917 | - print '<script type="text/javascript">$(document).ready(function() {$(".linecheckboxtoggle").click(function() {var checkBoxes = $(".linecheckbox");checkBoxes.prop("checked", this.checked);})});</script>';
|
|
| 3918 | - print '</td>'; |
|
| 3919 | - } |
|
| 3920 | - |
|
| 3921 | - print "</tr>\n"; |
|
| 3922 | - print "</thead>\n"; |
|
| 3923 | - } |
|
| 3924 | - |
|
| 3925 | - $var = true; |
|
| 3926 | - $i = 0; |
|
| 3927 | - |
|
| 3928 | - print "<tbody>\n"; |
|
| 3929 | - foreach ($this->lines as $line) |
|
| 3930 | - {
|
|
| 3931 | - //Line extrafield |
|
| 3932 | - $line->fetch_optionals(); |
|
| 3933 | - |
|
| 3934 | - //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 3935 | - if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 3936 | - {
|
|
| 3937 | - if (empty($line->fk_parent_line)) |
|
| 3938 | - {
|
|
| 3939 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3940 | - $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3941 | - } |
|
| 3942 | - else |
|
| 3943 | - {
|
|
| 3944 | - $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);
|
|
| 3945 | - $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3946 | - } |
|
| 3947 | - } |
|
| 3948 | - if (empty($reshook)) |
|
| 3949 | - {
|
|
| 3950 | - $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3951 | - } |
|
| 3952 | - |
|
| 3953 | - $i++; |
|
| 3954 | - } |
|
| 3955 | - print "</tbody>\n"; |
|
| 3956 | - } |
|
| 3957 | - |
|
| 3958 | - /** |
|
| 3959 | - * Return HTML content of a detail line |
|
| 3960 | - * TODO Move this into an output class file (htmlline.class.php) |
|
| 3961 | - * |
|
| 3962 | - * @param string $action GET/POST action |
|
| 3963 | - * @param CommonObjectLine $line Selected object line to output |
|
| 3964 | - * @param string $var Is it a an odd line (true) |
|
| 3965 | - * @param int $num Number of line (0) |
|
| 3966 | - * @param int $i I |
|
| 3967 | - * @param int $dateSelector 1=Show also date range input fields |
|
| 3968 | - * @param string $seller Object of seller third party |
|
| 3969 | - * @param string $buyer Object of buyer third party |
|
| 3970 | - * @param int $selected Object line selected |
|
| 3971 | - * @param int $extrafieldsline Object of extrafield line attribute |
|
| 3972 | - * @return void |
|
| 3973 | - */ |
|
| 3974 | - function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3975 | - {
|
|
| 3976 | - global $conf,$langs,$user,$object,$hookmanager; |
|
| 3977 | - global $form,$bc,$bcdd; |
|
| 3978 | - global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3979 | - |
|
| 3980 | - $object_rights = $this->getRights(); |
|
| 3981 | - |
|
| 3982 | - $element=$this->element; |
|
| 3983 | - |
|
| 3984 | - $text=''; $description=''; $type=0; |
|
| 3985 | - |
|
| 3986 | - // Show product and description |
|
| 3987 | - $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 3988 | - // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
|
| 3989 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3990 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 3991 | - |
|
| 3992 | - // Ligne en mode visu |
|
| 3993 | - if ($action != 'editline' || $selected != $line->id) |
|
| 3994 | - {
|
|
| 3995 | - // Product |
|
| 3996 | - if ($line->fk_product > 0) |
|
| 3997 | - {
|
|
| 3998 | - $product_static = new Product($this->db); |
|
| 3999 | - $product_static->fetch($line->fk_product); |
|
| 4000 | - |
|
| 4001 | - $product_static->ref = $line->ref; //can change ref in hook |
|
| 4002 | - $product_static->label = $line->label; //can change label in hook |
|
| 4003 | - $text=$product_static->getNomUrl(1); |
|
| 4004 | - |
|
| 4005 | - // Define output language and label |
|
| 4006 | - if (!empty(Globals::$conf->global->MAIN_MULTILANGS)) {
|
|
| 4007 | - if (! is_object($this->thirdparty)) |
|
| 4008 | - {
|
|
| 4009 | - dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
|
|
| 4010 | - return; |
|
| 4011 | - } |
|
| 4012 | - |
|
| 4013 | - $prod = new Product($this->db); |
|
| 4014 | - $prod->fetch($line->fk_product); |
|
| 4015 | - |
|
| 4016 | - $outputlangs = $langs; |
|
| 4017 | - $newlang=''; |
|
| 4018 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4019 | - if (!empty(Globals::$conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) |
|
| 4020 | - $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
| 4021 | - if (! empty($newlang)) |
|
| 4022 | - {
|
|
| 4023 | - $outputlangs = new Translate("",$conf);
|
|
| 4024 | - $outputlangs->setDefaultLang($newlang); |
|
| 4025 | - } |
|
| 1263 | + $result = $this->db->fetch_object($query); |
|
| 4026 | 1264 | |
| 4027 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4028 | - } |
|
| 4029 | - else |
|
| 4030 | - {
|
|
| 4031 | - $label = $line->product_label; |
|
| 4032 | - } |
|
| 1265 | + return $this->fetch($result->rowid); |
|
| 1266 | + } |
|
| 4033 | 1267 | |
| 4034 | - $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 4035 | - $description .= (!empty(Globals::$conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. |
|
| 4036 | - } |
|
| 1268 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1269 | + /** |
|
| 1270 | + * Load data for barcode into properties ->barcode_type* |
|
| 1271 | + * Properties ->barcode_type that is id of barcode. Type is used to find other properties, but |
|
| 1272 | + * if it is not defined, ->element must be defined to know default barcode type. |
|
| 1273 | + * |
|
| 1274 | + * @return int <0 if KO, 0 if can't guess type of barcode (ISBN, EAN13...), >0 if OK (all barcode properties loaded) |
|
| 1275 | + */ |
|
| 1276 | + function fetch_barcode() |
|
| 1277 | + {
|
|
| 1278 | + // phpcs:enable |
|
| 1279 | + global $conf; |
|
| 4037 | 1280 | |
| 4038 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 1281 | + dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
|
| 4039 | 1282 | |
| 4040 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4041 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 4042 | - $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4043 | - foreach($dirtpls as $reldir) |
|
| 4044 | - {
|
|
| 4045 | - $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
| 4046 | - if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 4047 | - $res=@include $tpl; |
|
| 4048 | - } else {
|
|
| 4049 | - $res=include $tpl; // for debug |
|
| 4050 | - } |
|
| 4051 | - if ($res) break; |
|
| 4052 | - } |
|
| 4053 | - } |
|
| 1283 | + $idtype=$this->barcode_type; |
|
| 1284 | + 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 |
|
| 1285 | + {
|
|
| 1286 | + if ($this->element == 'product') |
|
| 1287 | + $idtype = Globals::$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1288 | + else if ($this->element == 'societe') |
|
| 1289 | + $idtype = Globals::$conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1290 | + else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
|
|
| 1291 | + } |
|
| 4054 | 1292 | |
| 4055 | - // Ligne en mode update |
|
| 4056 | - if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
|
| 4057 | - {
|
|
| 4058 | - $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4059 | - $placeholder=' placeholder="'.$langs->trans("Label").'"';
|
|
| 1293 | + if ($idtype > 0) |
|
| 1294 | + {
|
|
| 1295 | + 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 |
|
| 1296 | + {
|
|
| 1297 | + $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1298 | + $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
|
| 1299 | + $sql.= " WHERE rowid = ".$idtype; |
|
| 1300 | + dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
|
| 1301 | + $resql = $this->db->query($sql); |
|
| 1302 | + if ($resql) |
|
| 1303 | + {
|
|
| 1304 | + $obj = $this->db->fetch_object($resql); |
|
| 1305 | + $this->barcode_type = $obj->rowid; |
|
| 1306 | + $this->barcode_type_code = $obj->code; |
|
| 1307 | + $this->barcode_type_label = $obj->label; |
|
| 1308 | + $this->barcode_type_coder = $obj->coder; |
|
| 1309 | + return 1; |
|
| 1310 | + } |
|
| 1311 | + else |
|
| 1312 | + {
|
|
| 1313 | + dol_print_error($this->db); |
|
| 1314 | + return -1; |
|
| 1315 | + } |
|
| 1316 | + } |
|
| 1317 | + } |
|
| 1318 | + return 0; |
|
| 1319 | + } |
|
| 4060 | 1320 | |
| 4061 | - $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 1321 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1322 | + /** |
|
| 1323 | + * Load the project with id $this->fk_project into this->project |
|
| 1324 | + * |
|
| 1325 | + * @return int <0 if KO, >=0 if OK |
|
| 1326 | + */ |
|
| 1327 | + function fetch_projet() |
|
| 1328 | + {
|
|
| 1329 | + // phpcs:enable |
|
| 1330 | + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
|
| 4062 | 1331 | |
| 4063 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4064 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 4065 | - $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4066 | - foreach($dirtpls as $reldir) |
|
| 4067 | - {
|
|
| 4068 | - $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
| 4069 | - if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 4070 | - $res=@include $tpl; |
|
| 4071 | - } else {
|
|
| 4072 | - $res=include $tpl; // for debug |
|
| 4073 | - } |
|
| 4074 | - if ($res) break; |
|
| 4075 | - } |
|
| 4076 | - } |
|
| 4077 | - } |
|
| 4078 | - |
|
| 4079 | - |
|
| 4080 | - /* This is to show array of line of details of source object */ |
|
| 4081 | - |
|
| 4082 | - |
|
| 4083 | - /** |
|
| 4084 | - * Return HTML table table of source object lines |
|
| 4085 | - * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4086 | - * If lines are into a template, title must also be into a template |
|
| 4087 | - * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. |
|
| 4088 | - * |
|
| 4089 | - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
|
| 4090 | - * @return void |
|
| 4091 | - */ |
|
| 4092 | - function printOriginLinesList($restrictlist='') |
|
| 4093 | - {
|
|
| 4094 | - global $langs, $hookmanager, $conf; |
|
| 4095 | - |
|
| 4096 | - print '<tr class="liste_titre">'; |
|
| 4097 | - print '<td>'.$langs->trans('Ref').'</td>';
|
|
| 4098 | - print '<td>'.$langs->trans('Description').'</td>';
|
|
| 4099 | - print '<td align="right">'.$langs->trans('VATRate').'</td>';
|
|
| 4100 | - print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
|
| 4101 | - if (!empty(Globals::$conf->multicurrency->enabled)) |
|
| 4102 | - print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>';
|
|
| 4103 | - print '<td align="right">'.$langs->trans('Qty').'</td>';
|
|
| 4104 | - if (Globals::$conf->global->PRODUCT_USE_UNITS) {
|
|
| 4105 | - print '<td align="left">'.$langs->trans('Unit').'</td>';
|
|
| 4106 | - } |
|
| 4107 | - print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
|
|
| 1332 | + if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1333 | + if (empty($this->fk_project)) return 0; |
|
| 4108 | 1334 | |
| 4109 | - $var = true; |
|
| 4110 | - $i = 0; |
|
| 1335 | + $project = new Project($this->db); |
|
| 1336 | + $result = $project->fetch($this->fk_project); |
|
| 4111 | 1337 | |
| 4112 | - if (! empty($this->lines)) |
|
| 4113 | - {
|
|
| 4114 | - foreach ($this->lines as $line) |
|
| 4115 | - {
|
|
| 4116 | - if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 4117 | - {
|
|
| 4118 | - if (empty($line->fk_parent_line)) |
|
| 4119 | - {
|
|
| 4120 | - $parameters=array('line'=>$line,'var'=>$var,'i'=>$i);
|
|
| 4121 | - $action=''; |
|
| 4122 | - $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
| 4123 | - } |
|
| 4124 | - } |
|
| 4125 | - else |
|
| 4126 | - {
|
|
| 4127 | - $this->printOriginLine($line, $var, $restrictlist); |
|
| 4128 | - } |
|
| 1338 | + $this->projet = $project; // deprecated |
|
| 1339 | + $this->project = $project; |
|
| 1340 | + return $result; |
|
| 1341 | + } |
|
| 4129 | 1342 | |
| 4130 | - $i++; |
|
| 4131 | - } |
|
| 4132 | - } |
|
| 4133 | - } |
|
| 4134 | - |
|
| 4135 | - /** |
|
| 4136 | - * Return HTML with a line of table array of source object lines |
|
| 4137 | - * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4138 | - * If lines are into a template, title must also be into a template |
|
| 4139 | - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 4140 | - * |
|
| 4141 | - * @param CommonObjectLine $line Line |
|
| 4142 | - * @param string $var Var |
|
| 4143 | - * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
|
| 4144 | - * @return void |
|
| 4145 | - */ |
|
| 4146 | - function printOriginLine($line, $var, $restrictlist='') |
|
| 4147 | - {
|
|
| 4148 | - global $langs, $conf; |
|
| 4149 | - |
|
| 4150 | - //var_dump($line); |
|
| 4151 | - if (!empty($line->date_start)) |
|
| 4152 | - {
|
|
| 4153 | - $date_start=$line->date_start; |
|
| 4154 | - } |
|
| 4155 | - else |
|
| 4156 | - {
|
|
| 4157 | - $date_start=$line->date_debut_prevue; |
|
| 4158 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4159 | - } |
|
| 4160 | - if (!empty($line->date_end)) |
|
| 4161 | - {
|
|
| 4162 | - $date_end=$line->date_end; |
|
| 4163 | - } |
|
| 4164 | - else |
|
| 4165 | - {
|
|
| 4166 | - $date_end=$line->date_fin_prevue; |
|
| 4167 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4168 | - } |
|
| 4169 | - |
|
| 4170 | - $this->tpl['label'] = ''; |
|
| 4171 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4172 | - |
|
| 4173 | - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4174 | - {
|
|
| 4175 | - $discount=new DiscountAbsolute($this->db); |
|
| 4176 | - $discount->fk_soc = $this->socid; |
|
| 4177 | - $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 4178 | - } |
|
| 4179 | - else if (! empty($line->fk_product)) |
|
| 4180 | - {
|
|
| 4181 | - $productstatic = new Product($this->db); |
|
| 4182 | - $productstatic->id = $line->fk_product; |
|
| 4183 | - $productstatic->ref = $line->ref; |
|
| 4184 | - $productstatic->type = $line->fk_product_type; |
|
| 4185 | - if(empty($productstatic->ref)){
|
|
| 4186 | - $line->fetch_product(); |
|
| 4187 | - $productstatic = $line->product; |
|
| 4188 | - } |
|
| 4189 | - |
|
| 4190 | - $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 4191 | - $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 4192 | - // Dates |
|
| 4193 | - if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4194 | - {
|
|
| 4195 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4196 | - } |
|
| 4197 | - } |
|
| 4198 | - else |
|
| 4199 | - {
|
|
| 4200 | - $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
|
| 4201 | - if (!empty($line->desc)) {
|
|
| 4202 | - $this->tpl['label'].=$line->desc; |
|
| 4203 | - }else {
|
|
| 4204 | - $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 4205 | - } |
|
| 4206 | - |
|
| 4207 | - // Dates |
|
| 4208 | - if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4209 | - {
|
|
| 4210 | - $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4211 | - } |
|
| 4212 | - } |
|
| 1343 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1344 | + /** |
|
| 1345 | + * Load the product with id $this->fk_product into this->product |
|
| 1346 | + * |
|
| 1347 | + * @return int <0 if KO, >=0 if OK |
|
| 1348 | + */ |
|
| 1349 | + function fetch_product() |
|
| 1350 | + {
|
|
| 1351 | + // phpcs:enable |
|
| 1352 | + include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 4213 | 1353 | |
| 4214 | - if (! empty($line->desc)) |
|
| 4215 | - {
|
|
| 4216 | - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4217 | - {
|
|
| 4218 | - $discount=new DiscountAbsolute($this->db); |
|
| 4219 | - $discount->fetch($line->fk_remise_except); |
|
| 4220 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
|
| 4221 | - } |
|
| 4222 | - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4223 | - {
|
|
| 4224 | - $discount=new DiscountAbsolute($this->db); |
|
| 4225 | - $discount->fetch($line->fk_remise_except); |
|
| 4226 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
|
| 4227 | - } |
|
| 4228 | - elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4229 | - {
|
|
| 4230 | - $discount=new DiscountAbsolute($this->db); |
|
| 4231 | - $discount->fetch($line->fk_remise_except); |
|
| 4232 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
|
| 4233 | - } |
|
| 4234 | - elseif ($line->desc == '(EXCESS PAID)') |
|
| 4235 | - {
|
|
| 4236 | - $discount=new DiscountAbsolute($this->db); |
|
| 4237 | - $discount->fetch($line->fk_remise_except); |
|
| 4238 | - $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
|
| 4239 | - } |
|
| 4240 | - else |
|
| 4241 | - {
|
|
| 4242 | - $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 4243 | - } |
|
| 4244 | - } |
|
| 4245 | - else |
|
| 4246 | - {
|
|
| 4247 | - $this->tpl['description'] = ' '; |
|
| 4248 | - } |
|
| 4249 | - |
|
| 4250 | - // VAT Rate |
|
| 4251 | - $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
|
| 4252 | - $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
|
| 4253 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 4254 | - |
|
| 4255 | - $this->tpl['price'] = price($line->subprice); |
|
| 4256 | - $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
|
| 4257 | - $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
|
| 4258 | - if (Globals::$conf->global->PRODUCT_USE_UNITS) |
|
| 4259 | - $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
|
|
| 4260 | - $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
|
| 1354 | + if (empty($this->fk_product)) return 0; |
|
| 4261 | 1355 | |
| 4262 | - // Is the line strike or not |
|
| 4263 | - $this->tpl['strike']=0; |
|
| 4264 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4265 | - |
|
| 4266 | - // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4267 | - // Use global variables + $dateSelector + $seller and $buyer |
|
| 4268 | - $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4269 | - foreach($dirtpls as $reldir) |
|
| 4270 | - {
|
|
| 4271 | - $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
| 4272 | - if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 4273 | - $res=@include $tpl; |
|
| 4274 | - } else {
|
|
| 4275 | - $res=include $tpl; // for debug |
|
| 4276 | - } |
|
| 4277 | - if ($res) break; |
|
| 4278 | - } |
|
| 4279 | - } |
|
| 1356 | + $product = new Product($this->db); |
|
| 1357 | + $result = $product->fetch($this->fk_product); |
|
| 4280 | 1358 | |
| 1359 | + $this->product = $product; |
|
| 1360 | + return $result; |
|
| 1361 | + } |
|
| 4281 | 1362 | |
| 4282 | 1363 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 4283 | - /** |
|
| 4284 | - * Add resources to the current object : add entry into llx_element_resources |
|
| 4285 | - * Need $this->element & $this->id |
|
| 4286 | - * |
|
| 4287 | - * @param int $resource_id Resource id |
|
| 4288 | - * @param string $resource_type 'resource' |
|
| 4289 | - * @param int $busy Busy or not |
|
| 4290 | - * @param int $mandatory Mandatory or not |
|
| 4291 | - * @return int <=0 if KO, >0 if OK |
|
| 4292 | - */ |
|
| 4293 | - function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4294 | - {
|
|
| 1364 | + /** |
|
| 1365 | + * Load the user with id $userid into this->user |
|
| 1366 | + * |
|
| 1367 | + * @param int $userid Id du contact |
|
| 1368 | + * @return int <0 if KO, >0 if OK |
|
| 1369 | + */ |
|
| 1370 | + function fetch_user($userid) |
|
| 1371 | + {
|
|
| 4295 | 1372 | // phpcs:enable |
| 4296 | - $this->db->begin(); |
|
| 4297 | - |
|
| 4298 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
|
| 4299 | - $sql.= "resource_id"; |
|
| 4300 | - $sql.= ", resource_type"; |
|
| 4301 | - $sql.= ", element_id"; |
|
| 4302 | - $sql.= ", element_type"; |
|
| 4303 | - $sql.= ", busy"; |
|
| 4304 | - $sql.= ", mandatory"; |
|
| 4305 | - $sql.= ") VALUES (";
|
|
| 4306 | - $sql.= $resource_id; |
|
| 4307 | - $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4308 | - $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4309 | - $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4310 | - $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4311 | - $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4312 | - $sql.= ")"; |
|
| 4313 | - |
|
| 4314 | - dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
| 4315 | - if ($this->db->query($sql)) |
|
| 4316 | - {
|
|
| 4317 | - $this->db->commit(); |
|
| 4318 | - return 1; |
|
| 4319 | - } |
|
| 4320 | - else |
|
| 4321 | - {
|
|
| 4322 | - $this->error=$this->db->lasterror(); |
|
| 4323 | - $this->db->rollback(); |
|
| 4324 | - return 0; |
|
| 4325 | - } |
|
| 4326 | - } |
|
| 1373 | + $user = new User($this->db); |
|
| 1374 | + $result=$user->fetch($userid); |
|
| 1375 | + $this->user = $user; |
|
| 1376 | + return $result; |
|
| 1377 | + } |
|
| 4327 | 1378 | |
| 4328 | 1379 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
| 4329 | - /** |
|
| 4330 | - * Delete a link to resource line |
|
| 4331 | - * |
|
| 4332 | - * @param int $rowid Id of resource line to delete |
|
| 4333 | - * @param int $element element name (for trigger) TODO: use $this->element into commonobject class |
|
| 4334 | - * @param int $notrigger Disable all triggers |
|
| 4335 | - * @return int >0 if OK, <0 if KO |
|
| 4336 | - */ |
|
| 4337 | - function delete_resource($rowid, $element, $notrigger=0) |
|
| 4338 | - {
|
|
| 1380 | + /** |
|
| 1381 | + * Read linked origin object |
|
| 1382 | + * |
|
| 1383 | + * @return void |
|
| 1384 | + */ |
|
| 1385 | + function fetch_origin() |
|
| 1386 | + {
|
|
| 4339 | 1387 | // phpcs:enable |
| 4340 | - global $user; |
|
| 1388 | + if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1389 | + if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1390 | + if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 4341 | 1391 | |
| 4342 | - $this->db->begin(); |
|
| 1392 | + $origin = $this->origin; |
|
| 4343 | 1393 | |
| 4344 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
| 4345 | - $sql.= " WHERE rowid=".$rowid; |
|
| 1394 | + $classname = ucfirst($origin); |
|
| 1395 | + $this->$origin = new $classname($this->db); |
|
| 1396 | + $this->$origin->fetch($this->origin_id); |
|
| 1397 | + } |
|
| 4346 | 1398 | |
| 4347 | - dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
| 1399 | + /** |
|
| 1400 | + * Load object from specific field |
|
| 1401 | + * |
|
| 1402 | + * @param string $table Table element or element line |
|
| 1403 | + * @param string $field Field selected |
|
| 1404 | + * @param string $key Import key |
|
| 1405 | + * @param string $element Element name |
|
| 1406 | + * @return int <0 if KO, >0 if OK |
|
| 1407 | + */ |
|
| 1408 | + function fetchObjectFrom($table, $field, $key, $element = null) |
|
| 1409 | + {
|
|
| 1410 | + global $conf; |
|
| 4348 | 1411 | |
| 4349 | - $resql=$this->db->query($sql); |
|
| 4350 | - if (! $resql) |
|
| 4351 | - {
|
|
| 4352 | - $this->error=$this->db->lasterror(); |
|
| 4353 | - $this->db->rollback(); |
|
| 4354 | - return -1; |
|
| 4355 | - } |
|
| 4356 | - else |
|
| 4357 | - {
|
|
| 4358 | - if (! $notrigger) |
|
| 4359 | - {
|
|
| 4360 | - $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4361 | - if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 4362 | - } |
|
| 4363 | - $this->db->commit(); |
|
| 4364 | - return 1; |
|
| 4365 | - } |
|
| 4366 | - } |
|
| 4367 | - |
|
| 4368 | - |
|
| 4369 | - /** |
|
| 4370 | - * Overwrite magic function to solve problem of cloning object that are kept as references |
|
| 4371 | - * |
|
| 4372 | - * @return void |
|
| 4373 | - */ |
|
| 4374 | - function __clone() |
|
| 4375 | - {
|
|
| 4376 | - // Force a copy of this->lines, otherwise it will point to same object. |
|
| 4377 | - if (isset($this->lines) && is_array($this->lines)) |
|
| 4378 | - {
|
|
| 4379 | - $nboflines=count($this->lines); |
|
| 4380 | - for($i=0; $i < $nboflines; $i++) |
|
| 4381 | - {
|
|
| 4382 | - $this->lines[$i] = clone $this->lines[$i]; |
|
| 4383 | - } |
|
| 4384 | - } |
|
| 4385 | - } |
|
| 4386 | - |
|
| 4387 | - /** |
|
| 4388 | - * Common function for all objects extending CommonObject for generating documents |
|
| 4389 | - * |
|
| 4390 | - * @param string $modelspath Relative folder where generators are placed |
|
| 4391 | - * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
|
|
| 4392 | - * @param Translate $outputlangs Output language to use |
|
| 4393 | - * @param int $hidedetails 1 to hide details. 0 by default |
|
| 4394 | - * @param int $hidedesc 1 to hide product description. 0 by default |
|
| 4395 | - * @param int $hideref 1 to hide product reference. 0 by default |
|
| 4396 | - * @param null|array $moreparams Array to provide more information |
|
| 4397 | - * @return int >0 if OK, <0 if KO |
|
| 4398 | - * @see addFileIntoDatabaseIndex |
|
| 4399 | - */ |
|
| 4400 | - protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4401 | - {
|
|
| 4402 | - global $conf, $langs, $user; |
|
| 4403 | - |
|
| 4404 | - $srctemplatepath=''; |
|
| 4405 | - |
|
| 4406 | - // Increase limit for PDF build |
|
| 4407 | - $err=error_reporting(); |
|
| 4408 | - error_reporting(0); |
|
| 4409 | - @set_time_limit(120); |
|
| 4410 | - error_reporting($err); |
|
| 4411 | - |
|
| 4412 | - // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
|
| 4413 | - $tmp=explode(':',$modele,2);
|
|
| 4414 | - if (! empty($tmp[1])) |
|
| 4415 | - {
|
|
| 4416 | - $modele=$tmp[0]; |
|
| 4417 | - $srctemplatepath=$tmp[1]; |
|
| 4418 | - } |
|
| 4419 | - |
|
| 4420 | - // Search template files |
|
| 4421 | - $file=''; $classname=''; $filefound=0; |
|
| 4422 | - $dirmodels=array('/');
|
|
| 4423 | - if (is_array(Globals::$conf->modules_parts['models'])) |
|
| 4424 | - $dirmodels = array_merge($dirmodels, Globals::$conf->modules_parts['models']); |
|
| 4425 | - foreach($dirmodels as $reldir) |
|
| 4426 | - {
|
|
| 4427 | - foreach(array('doc','pdf') as $prefix)
|
|
| 4428 | - {
|
|
| 4429 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4430 | - else $file = $prefix."_".$modele.".modules.php"; |
|
| 1412 | + $result=false; |
|
| 4431 | 1413 | |
| 4432 | - // On verifie l'emplacement du modele |
|
| 4433 | - $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4434 | - if (file_exists($file)) |
|
| 4435 | - {
|
|
| 4436 | - $filefound=1; |
|
| 4437 | - $classname=$prefix.'_'.$modele; |
|
| 4438 | - break; |
|
| 4439 | - } |
|
| 4440 | - } |
|
| 4441 | - if ($filefound) break; |
|
| 4442 | - } |
|
| 1414 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; |
|
| 1415 | + $sql.= " WHERE ".$field." = '".$key."'"; |
|
| 1416 | + if (! empty($element)) {
|
|
| 1417 | + $sql.= " AND entity IN (".getEntity($element).")";
|
|
| 1418 | + } else {
|
|
| 1419 | + $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 1420 | + } |
|
| 4443 | 1421 | |
| 4444 | - // If generator was found |
|
| 4445 | - if ($filefound) |
|
| 4446 | - {
|
|
| 4447 | - global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 1422 | + dol_syslog(get_class($this).'::fetchObjectFrom', LOG_DEBUG); |
|
| 1423 | + $resql = $this->db->query($sql); |
|
| 1424 | + if ($resql) |
|
| 1425 | + {
|
|
| 1426 | + $row = $this->db->fetch_row($resql); |
|
| 1427 | + // Test for avoid error -1 |
|
| 1428 | + if ($row[0] > 0) {
|
|
| 1429 | + $result = $this->fetch($row[0]); |
|
| 1430 | + } |
|
| 1431 | + } |
|
| 4448 | 1432 | |
| 4449 | - require_once $file; |
|
| 1433 | + return $result; |
|
| 1434 | + } |
|
| 4450 | 1435 | |
| 4451 | - $obj = new $classname($this->db); |
|
| 1436 | + /** |
|
| 1437 | + * Getter generic. Load value from a specific field |
|
| 1438 | + * |
|
| 1439 | + * @param string $table Table of element or element line |
|
| 1440 | + * @param int $id Element id |
|
| 1441 | + * @param string $field Field selected |
|
| 1442 | + * @return int <0 if KO, >0 if OK |
|
| 1443 | + */ |
|
| 1444 | + function getValueFrom($table, $id, $field) |
|
| 1445 | + {
|
|
| 1446 | + $result=false; |
|
| 1447 | + if (!empty($id) && !empty($field) && !empty($table)) {
|
|
| 1448 | + $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; |
|
| 1449 | + $sql.= " WHERE rowid = ".$id; |
|
| 1450 | + |
|
| 1451 | + dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); |
|
| 1452 | + $resql = $this->db->query($sql); |
|
| 1453 | + if ($resql) |
|
| 1454 | + {
|
|
| 1455 | + $row = $this->db->fetch_row($resql); |
|
| 1456 | + $result = $row[0]; |
|
| 1457 | + } |
|
| 1458 | + } |
|
| 1459 | + return $result; |
|
| 1460 | + } |
|
| 4452 | 1461 | |
| 4453 | - // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
|
| 4454 | - if ($obj->type == 'odt' && empty($srctemplatepath)) |
|
| 4455 | - {
|
|
| 4456 | - $varfortemplatedir=$obj->scandir; |
|
| 4457 | - if ($varfortemplatedir && !empty(Globals::$conf->global->$varfortemplatedir)) {
|
|
| 4458 | - $dirtoscan = Globals::$conf->global->$varfortemplatedir; |
|
| 1462 | + /** |
|
| 1463 | + * Setter generic. Update a specific field into database. |
|
| 1464 | + * Warning: Trigger is run only if param trigkey is provided. |
|
| 1465 | + * |
|
| 1466 | + * @param string $field Field to update |
|
| 1467 | + * @param mixed $value New value |
|
| 1468 | + * @param string $table To force other table element or element line (should not be used) |
|
| 1469 | + * @param int $id To force other object id (should not be used) |
|
| 1470 | + * @param string $format Data format ('text', 'date'). 'text' is used if not defined
|
|
| 1471 | + * @param string $id_field To force rowid field name. 'rowid' is used if not defined |
|
| 1472 | + * @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' |
|
| 1473 | + * @param string $trigkey Trigger key to run (in most cases something like 'XXX_MODIFY') |
|
| 1474 | + * @param string $fk_user_field Name of field to save user id making change |
|
| 1475 | + * @return int <0 if KO, >0 if OK |
|
| 1476 | + * @see updateExtraField |
|
| 1477 | + */ |
|
| 1478 | + function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='', $fk_user_field='fk_user_modif') |
|
| 1479 | + {
|
|
| 1480 | + global $user,$langs,$conf; |
|
| 4459 | 1481 | |
| 4460 | - $listoffiles=array(); |
|
| 1482 | + if (empty($table)) $table=$this->table_element; |
|
| 1483 | + if (empty($id)) $id=$this->id; |
|
| 1484 | + if (empty($format)) $format='text'; |
|
| 1485 | + if (empty($id_field)) $id_field='rowid'; |
|
| 4461 | 1486 | |
| 4462 | - // Now we add first model found in directories scanned |
|
| 4463 | - $listofdir=explode(',',$dirtoscan);
|
|
| 4464 | - foreach($listofdir as $key => $tmpdir) |
|
| 4465 | - {
|
|
| 4466 | - $tmpdir=trim($tmpdir); |
|
| 4467 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
|
| 4468 | - if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
|
| 4469 | - if (is_dir($tmpdir)) |
|
| 4470 | - {
|
|
| 4471 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4472 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4473 | - } |
|
| 4474 | - } |
|
| 4475 | - |
|
| 4476 | - if (count($listoffiles)) |
|
| 4477 | - {
|
|
| 4478 | - foreach($listoffiles as $record) |
|
| 4479 | - {
|
|
| 4480 | - $srctemplatepath=$record['fullname']; |
|
| 4481 | - break; |
|
| 4482 | - } |
|
| 4483 | - } |
|
| 4484 | - } |
|
| 1487 | + $error=0; |
|
| 4485 | 1488 | |
| 4486 | - if (empty($srctemplatepath)) |
|
| 4487 | - {
|
|
| 4488 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4489 | - return -1; |
|
| 4490 | - } |
|
| 4491 | - } |
|
| 1489 | + $this->db->begin(); |
|
| 4492 | 1490 | |
| 4493 | - if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4494 | - {
|
|
| 4495 | - if (! dol_is_file($srctemplatepath)) |
|
| 4496 | - {
|
|
| 4497 | - $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4498 | - return -1; |
|
| 4499 | - } |
|
| 4500 | - } |
|
| 1491 | + // Special case |
|
| 1492 | + if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1493 | + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
|
| 4501 | 1494 | |
| 4502 | - // We save charset_output to restore it because write_file can change it if needed for |
|
| 4503 | - // output format that does not support UTF8. |
|
| 4504 | - $sav_charset_output=$outputlangs->charset_output; |
|
| 1495 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
|
| 4505 | 1496 | |
| 4506 | - if (in_array(get_class($this), array('Adherent')))
|
|
| 4507 | - {
|
|
| 4508 | - $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4509 | - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
|
| 4510 | - } |
|
| 4511 | - else |
|
| 4512 | - {
|
|
| 4513 | - $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
| 4514 | - } |
|
| 4515 | - // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. |
|
| 1497 | + if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1498 | + else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1499 | + else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 4516 | 1500 | |
| 4517 | - if ($resultwritefile > 0) |
|
| 4518 | - {
|
|
| 4519 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 1501 | + if ($fk_user_field) |
|
| 1502 | + {
|
|
| 1503 | + if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1504 | + elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1505 | + } |
|
| 4520 | 1506 | |
| 4521 | - // We delete old preview |
|
| 4522 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 4523 | - dol_delete_preview($this); |
|
| 1507 | + $sql.= " WHERE ".$id_field." = ".$id; |
|
| 4524 | 1508 | |
| 4525 | - // Index file in database |
|
| 4526 | - if (! empty($obj->result['fullpath'])) |
|
| 4527 | - {
|
|
| 4528 | - $destfull = $obj->result['fullpath']; |
|
| 4529 | - $upload_dir = dirname($destfull); |
|
| 4530 | - $destfile = basename($destfull); |
|
| 4531 | - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
|
| 4532 | - |
|
| 4533 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4534 | - {
|
|
| 4535 | - $filename = basename($destfile); |
|
| 4536 | - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
|
| 4537 | - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
|
| 4538 | - |
|
| 4539 | - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 4540 | - $ecmfile=new EcmFiles($this->db); |
|
| 4541 | - $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4542 | - |
|
| 4543 | - // Set the public "share" key |
|
| 4544 | - $setsharekey = false; |
|
| 4545 | - if ($this->element == 'propal') |
|
| 4546 | - {
|
|
| 4547 | - $useonlinesignature = Globals::$conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4548 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4549 | - if (!empty(Globals::$conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4550 | - $setsharekey = true; |
|
| 4551 | - } |
|
| 4552 | - if ($this->element == 'commande' && !empty(Globals::$conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4553 | - $setsharekey = true; |
|
| 4554 | - if ($this->element == 'facture' && !empty(Globals::$conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4555 | - $setsharekey = true; |
|
| 4556 | - if ($this->element == 'bank_account' && !empty(Globals::$conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4557 | - $setsharekey = true; |
|
| 1509 | + dol_syslog(get_class($this)."::".__FUNCTION__."", LOG_DEBUG); |
|
| 1510 | + $resql = $this->db->query($sql); |
|
| 1511 | + if ($resql) |
|
| 1512 | + {
|
|
| 1513 | + if ($trigkey) |
|
| 1514 | + {
|
|
| 1515 | + // call trigger with updated object values |
|
| 1516 | + if (empty($this->fields) && method_exists($this, 'fetch')) |
|
| 1517 | + {
|
|
| 1518 | + $result = $this->fetch($id); |
|
| 1519 | + } |
|
| 1520 | + else |
|
| 1521 | + {
|
|
| 1522 | + $result = $this->fetchCommon($id); |
|
| 1523 | + } |
|
| 1524 | + if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1525 | + if ($result < 0) $error++; |
|
| 1526 | + } |
|
| 4558 | 1527 | |
| 4559 | - if ($setsharekey) |
|
| 4560 | - {
|
|
| 4561 | - if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4562 | - {
|
|
| 4563 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4564 | - $ecmfile->share = getRandomPassword(true); |
|
| 4565 | - } |
|
| 4566 | - } |
|
| 1528 | + if (! $error) |
|
| 1529 | + {
|
|
| 1530 | + if (property_exists($this, $field)) $this->$field = $value; |
|
| 1531 | + $this->db->commit(); |
|
| 1532 | + return 1; |
|
| 1533 | + } |
|
| 1534 | + else |
|
| 1535 | + {
|
|
| 1536 | + $this->db->rollback(); |
|
| 1537 | + return -2; |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | + else |
|
| 1541 | + {
|
|
| 1542 | + $this->error=$this->db->lasterror(); |
|
| 1543 | + $this->db->rollback(); |
|
| 1544 | + return -1; |
|
| 1545 | + } |
|
| 1546 | + } |
|
| 4567 | 1547 | |
| 4568 | - if ($result > 0) |
|
| 4569 | - {
|
|
| 4570 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4571 | - $ecmfile->fullpath_orig = ''; |
|
| 4572 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4573 | - $ecmfile->description = ''; // indexed content |
|
| 4574 | - $ecmfile->keyword = ''; // keyword content |
|
| 4575 | - $result = $ecmfile->update($user); |
|
| 4576 | - if ($result < 0) |
|
| 4577 | - {
|
|
| 4578 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4579 | - } |
|
| 4580 | - } |
|
| 4581 | - else |
|
| 4582 | - {
|
|
| 4583 | - $ecmfile->entity = Globals::$conf->entity; |
|
| 4584 | - $ecmfile->filepath = $rel_dir; |
|
| 4585 | - $ecmfile->filename = $filename; |
|
| 4586 | - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4587 | - $ecmfile->fullpath_orig = ''; |
|
| 4588 | - $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4589 | - $ecmfile->description = ''; // indexed content |
|
| 4590 | - $ecmfile->keyword = ''; // keyword content |
|
| 4591 | - $ecmfile->src_object_type = $this->table_element; |
|
| 4592 | - $ecmfile->src_object_id = $this->id; |
|
| 4593 | - |
|
| 4594 | - $result = $ecmfile->create($user); |
|
| 4595 | - if ($result < 0) |
|
| 4596 | - {
|
|
| 4597 | - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4598 | - } |
|
| 4599 | - } |
|
| 1548 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 1549 | + /** |
|
| 1550 | + * Load properties id_previous and id_next by comparing $fieldid with $this->ref |
|
| 1551 | + * |
|
| 1552 | + * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" |
|
| 1553 | + * @param string $fieldid Name of field to use for the select MAX and MIN |
|
| 1554 | + * @param int $nodbprefix Do not include DB prefix to forge table name |
|
| 1555 | + * @return int <0 if KO, >0 if OK |
|
| 1556 | + */ |
|
| 1557 | + function load_previous_next_ref($filter, $fieldid, $nodbprefix=0) |
|
| 1558 | + {
|
|
| 1559 | + // phpcs:enable |
|
| 1560 | + global $conf, $user; |
|
| 4600 | 1561 | |
| 4601 | - /*$this->result['fullname']=$destfull; |
|
| 4602 | - $this->result['filepath']=$ecmfile->filepath; |
|
| 4603 | - $this->result['filename']=$ecmfile->filename;*/ |
|
| 4604 | - //var_dump($obj->update_main_doc_field);exit; |
|
| 4605 | - |
|
| 4606 | - // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
|
| 4607 | - $update_main_doc_field=0; |
|
| 4608 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4609 | - if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4610 | - {
|
|
| 4611 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
| 4612 | - $sql.= ' WHERE rowid = '.$this->id; |
|
| 4613 | - $resql = $this->db->query($sql); |
|
| 4614 | - if (! $resql) dol_print_error($this->db); |
|
| 4615 | - } |
|
| 4616 | - } |
|
| 4617 | - } |
|
| 4618 | - else |
|
| 4619 | - {
|
|
| 4620 | - 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);
|
|
| 4621 | - } |
|
| 1562 | + if (! $this->table_element) |
|
| 1563 | + {
|
|
| 1564 | + dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
|
| 1565 | + return -1; |
|
| 1566 | + } |
|
| 1567 | + if ($fieldid == 'none') return 1; |
|
| 4622 | 1568 | |
| 4623 | - // Success in building document. We build meta file. |
|
| 4624 | - dol_meta_create($this); |
|
| 1569 | + // Security on socid |
|
| 1570 | + $socid = 0; |
|
| 1571 | + if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 4625 | 1572 | |
| 4626 | - return 1; |
|
| 4627 | - } |
|
| 4628 | - else |
|
| 4629 | - {
|
|
| 4630 | - $outputlangs->charset_output=$sav_charset_output; |
|
| 4631 | - dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
| 4632 | - return -1; |
|
| 4633 | - } |
|
| 4634 | - } |
|
| 4635 | - else |
|
| 4636 | - {
|
|
| 4637 | - $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
|
| 4638 | - dol_print_error('',$this->error);
|
|
| 4639 | - return -1; |
|
| 4640 | - } |
|
| 4641 | - } |
|
| 4642 | - |
|
| 4643 | - /** |
|
| 4644 | - * Build thumb |
|
| 4645 | - * @TODO Move this into files.lib.php |
|
| 4646 | - * |
|
| 4647 | - * @param string $file Path file in UTF8 to original file to create thumbs from. |
|
| 4648 | - * @return void |
|
| 4649 | - */ |
|
| 4650 | - function addThumbs($file) |
|
| 4651 | - {
|
|
| 4652 | - global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
|
| 4653 | - |
|
| 4654 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4655 | - |
|
| 4656 | - $file_osencoded=dol_osencode($file); |
|
| 4657 | - if (file_exists($file_osencoded)) |
|
| 4658 | - {
|
|
| 4659 | - // Create small thumbs for company (Ratio is near 16/9) |
|
| 4660 | - // Used on logon for example |
|
| 4661 | - vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); |
|
| 4662 | - |
|
| 4663 | - // Create mini thumbs for company (Ratio is near 16/9) |
|
| 4664 | - // Used on menu or for setup page for example |
|
| 4665 | - vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); |
|
| 4666 | - } |
|
| 4667 | - } |
|
| 4668 | - |
|
| 4669 | - |
|
| 4670 | - /* Functions common to commonobject and commonobjectline */ |
|
| 4671 | - |
|
| 4672 | - /* For default values */ |
|
| 4673 | - |
|
| 4674 | - /** |
|
| 4675 | - * Return the default value to use for a field when showing the create form of object. |
|
| 4676 | - * Return values in this order: |
|
| 4677 | - * 1) If parameter is available into POST, we return it first. |
|
| 4678 | - * 2) If not but an alternate value was provided as parameter of function, we return it. |
|
| 4679 | - * 3) If not but a constant Globals::$conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). |
|
| 4680 | - * 4) Return value found into database (TODO No yet implemented) |
|
| 4681 | - * |
|
| 4682 | - * @param string $fieldname Name of field |
|
| 4683 | - * @param string $alternatevalue Alternate value to use |
|
| 4684 | - * @return string|string[] Default value (can be an array if the GETPOST return an array) |
|
| 4685 | - **/ |
|
| 4686 | - function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4687 | - {
|
|
| 4688 | - global $conf, $_POST; |
|
| 4689 | - |
|
| 4690 | - // If param here has been posted, we use this value first. |
|
| 4691 | - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 4692 | - |
|
| 4693 | - if (isset($alternatevalue)) return $alternatevalue; |
|
| 4694 | - |
|
| 4695 | - $newelement=$this->element; |
|
| 4696 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4697 | - if ($newelement == 'commande') $newelement='order'; |
|
| 4698 | - if (empty($newelement)) |
|
| 4699 | - {
|
|
| 4700 | - dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
|
| 4701 | - return ''; |
|
| 4702 | - } |
|
| 4703 | - |
|
| 4704 | - $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4705 | - //var_dump($keyforfieldname); |
|
| 4706 | - if (isset(Globals::$conf->global->$keyforfieldname)) |
|
| 4707 | - return Globals::$conf->global->$keyforfieldname; |
|
| 1573 | + // this->ismultientitymanaged contains |
|
| 1574 | + // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
| 1575 | + $alias = 's'; |
|
| 1576 | + if ($this->element == 'societe') $alias = 'te'; |
|
| 4708 | 1577 | |
| 4709 | - // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
|
| 4710 | - } |
|
| 1578 | + $sql = "SELECT MAX(te.".$fieldid.")"; |
|
| 1579 | + $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1580 | + if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1581 | + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1582 | + } |
|
| 1583 | + 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 |
|
| 1584 | + 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 |
|
| 1585 | + 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 |
|
| 1586 | + 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"; |
|
| 1587 | + $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1588 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1589 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1590 | + if (! empty($filter)) |
|
| 1591 | + {
|
|
| 1592 | + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1593 | + $sql.=$filter; |
|
| 1594 | + } |
|
| 1595 | + 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 |
|
| 1596 | + 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 |
|
| 1597 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1598 | + if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1599 | + if (!empty($user->admin) && empty($user->entity) && Globals::$conf->entity == 1) {
|
|
| 1600 | + $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1601 | + } else {
|
|
| 1602 | + $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1603 | + $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1604 | + } |
|
| 1605 | + } else {
|
|
| 1606 | + $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1607 | + } |
|
| 1608 | + } |
|
| 1609 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1610 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1611 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1612 | + //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 4711 | 1613 | |
| 1614 | + $result = $this->db->query($sql); |
|
| 1615 | + if (! $result) |
|
| 1616 | + {
|
|
| 1617 | + $this->error=$this->db->lasterror(); |
|
| 1618 | + return -1; |
|
| 1619 | + } |
|
| 1620 | + $row = $this->db->fetch_row($result); |
|
| 1621 | + $this->ref_previous = $row[0]; |
|
| 4712 | 1622 | |
| 4713 | - /* For triggers */ |
|
| 4714 | 1623 | |
| 1624 | + $sql = "SELECT MIN(te.".$fieldid.")"; |
|
| 1625 | + $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
|
| 1626 | + if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1627 | + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
|
| 1628 | + } |
|
| 1629 | + 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 |
|
| 1630 | + 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 |
|
| 1631 | + 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 |
|
| 1632 | + 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"; |
|
| 1633 | + $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
|
| 1634 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1635 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1636 | + if (! empty($filter)) |
|
| 1637 | + {
|
|
| 1638 | + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1639 | + $sql.=$filter; |
|
| 1640 | + } |
|
| 1641 | + 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 |
|
| 1642 | + 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 |
|
| 1643 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
|
| 1644 | + if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
|
| 1645 | + if (!empty($user->admin) && empty($user->entity) && Globals::$conf->entity == 1) {
|
|
| 1646 | + $sql.= " AND te.entity IS NOT NULL"; // Show all users |
|
| 1647 | + } else {
|
|
| 1648 | + $sql.= " AND ug.fk_user = te.rowid"; |
|
| 1649 | + $sql.= " AND ug.entity IN (".getEntity($this->element).")";
|
|
| 1650 | + } |
|
| 1651 | + } else {
|
|
| 1652 | + $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
|
| 1653 | + } |
|
| 1654 | + } |
|
| 1655 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1656 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1657 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1658 | + //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
|
| 1659 | + // 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 |
|
| 1660 | + |
|
| 1661 | + $result = $this->db->query($sql); |
|
| 1662 | + if (! $result) |
|
| 1663 | + {
|
|
| 1664 | + $this->error=$this->db->lasterror(); |
|
| 1665 | + return -2; |
|
| 1666 | + } |
|
| 1667 | + $row = $this->db->fetch_row($result); |
|
| 1668 | + $this->ref_next = $row[0]; |
|
| 4715 | 1669 | |
| 4716 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4717 | - /** |
|
| 4718 | - * Call trigger based on this instance. |
|
| 4719 | - * Some context information may also be provided into array property this->context. |
|
| 4720 | - * NB: Error from trigger are stacked in interface->errors |
|
| 4721 | - * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. |
|
| 4722 | - * |
|
| 4723 | - * @param string $trigger_name trigger's name to execute |
|
| 4724 | - * @param User $user Object user |
|
| 4725 | - * @return int Result of run_triggers |
|
| 4726 | - */ |
|
| 4727 | - function call_trigger($trigger_name, $user) |
|
| 4728 | - {
|
|
| 4729 | - // phpcs:enable |
|
| 4730 | - global $langs,$conf; |
|
| 1670 | + return 1; |
|
| 1671 | + } |
|
| 4731 | 1672 | |
| 4732 | - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4733 | - $interface=new Interfaces($this->db); |
|
| 4734 | - $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 4735 | 1673 | |
| 4736 | - if ($result < 0) |
|
| 4737 | - {
|
|
| 4738 | - if (!empty($this->errors)) |
|
| 4739 | - {
|
|
| 4740 | - $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. |
|
| 4741 | - } |
|
| 4742 | - else |
|
| 4743 | - {
|
|
| 4744 | - $this->errors=$interface->errors; |
|
| 4745 | - } |
|
| 4746 | - } |
|
| 4747 | - return $result; |
|
| 4748 | - } |
|
| 1674 | + /** |
|
| 1675 | + * Return list of id of contacts of object |
|
| 1676 | + * |
|
| 1677 | + * @param string $source Source of contact: external (llx_socpeople) or internal (llx_user) or thirdparty (llx_societe) |
|
| 1678 | + * @return array Array of id of contacts (if source=external or internal) |
|
| 1679 | + * Array of id of third parties with at least one contact on object (if source=thirdparty) |
|
| 1680 | + */ |
|
| 1681 | + function getListContactId($source='external') |
|
| 1682 | + {
|
|
| 1683 | + $contactAlreadySelected = array(); |
|
| 1684 | + $tab = $this->liste_contact(-1,$source); |
|
| 1685 | + $num=count($tab); |
|
| 1686 | + $i = 0; |
|
| 1687 | + while ($i < $num) |
|
| 1688 | + {
|
|
| 1689 | + if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1690 | + else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1691 | + $i++; |
|
| 1692 | + } |
|
| 1693 | + return $contactAlreadySelected; |
|
| 1694 | + } |
|
| 4749 | 1695 | |
| 4750 | 1696 | |
| 4751 | - /* Functions for extrafields */ |
|
| 1697 | + /** |
|
| 1698 | + * Link element with a project |
|
| 1699 | + * |
|
| 1700 | + * @param int $projectid Project id to link element to |
|
| 1701 | + * @return int <0 if KO, >0 if OK |
|
| 1702 | + */ |
|
| 1703 | + function setProject($projectid) |
|
| 1704 | + {
|
|
| 1705 | + if (! $this->table_element) |
|
| 1706 | + {
|
|
| 1707 | + dol_syslog(get_class($this)."::setProject was called on objet with property table_element not defined",LOG_ERR); |
|
| 1708 | + return -1; |
|
| 1709 | + } |
|
| 4752 | 1710 | |
| 1711 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1712 | + if ($this->table_element == 'actioncomm') |
|
| 1713 | + {
|
|
| 1714 | + if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1715 | + else $sql.= ' SET fk_project = NULL'; |
|
| 1716 | + $sql.= ' WHERE id = '.$this->id; |
|
| 1717 | + } |
|
| 1718 | + else |
|
| 1719 | + {
|
|
| 1720 | + if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1721 | + else $sql.= ' SET fk_projet = NULL'; |
|
| 1722 | + $sql.= ' WHERE rowid = '.$this->id; |
|
| 1723 | + } |
|
| 4753 | 1724 | |
| 4754 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4755 | - /** |
|
| 4756 | - * Function to get extra fields of an object into $this->array_options |
|
| 4757 | - * This method is in most cases called by method fetch of objects but you can call it separately. |
|
| 4758 | - * |
|
| 4759 | - * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. |
|
| 4760 | - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
|
| 4761 | - * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
|
| 4762 | - */ |
|
| 4763 | - function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4764 | - {
|
|
| 4765 | - // phpcs:enable |
|
| 4766 | - if (empty($rowid)) {
|
|
| 4767 | - $rowid = $this->id; |
|
| 1725 | + dol_syslog(get_class($this)."::setProject", LOG_DEBUG); |
|
| 1726 | + if ($this->db->query($sql)) |
|
| 1727 | + {
|
|
| 1728 | + $this->fk_project = $projectid; |
|
| 1729 | + return 1; |
|
| 1730 | + } |
|
| 1731 | + else |
|
| 1732 | + {
|
|
| 1733 | + dol_print_error($this->db); |
|
| 1734 | + return -1; |
|
| 4768 | 1735 | } |
| 1736 | + } |
|
| 4769 | 1737 | |
| 4770 | - // To avoid SQL errors. Probably not the better solution though |
|
| 4771 | - if (!$this->table_element) {
|
|
| 4772 | - return 0; |
|
| 4773 | - } |
|
| 4774 | - |
|
| 4775 | - $this->array_options=array(); |
|
| 4776 | - |
|
| 4777 | - if (! is_array($optionsArray)) |
|
| 4778 | - {
|
|
| 4779 | - // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
|
| 4780 | - // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
|
| 4781 | - // global $extrafields; |
|
| 4782 | - //if (! is_object($extrafields)) |
|
| 4783 | - //{
|
|
| 4784 | - // require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4785 | - $extrafields = new AlExtraFields(); |
|
| 4786 | - //} |
|
| 1738 | + /** |
|
| 1739 | + * Change the payments methods |
|
| 1740 | + * |
|
| 1741 | + * @param int $id Id of new payment method |
|
| 1742 | + * @return int >0 if OK, <0 if KO |
|
| 1743 | + */ |
|
| 1744 | + function setPaymentMethods($id) |
|
| 1745 | + {
|
|
| 1746 | + dol_syslog(get_class($this).'::setPaymentMethods('.$id.')');
|
|
| 1747 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1748 | + {
|
|
| 1749 | + // TODO uniformize field name |
|
| 1750 | + $fieldname = 'fk_mode_reglement'; |
|
| 1751 | + if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1752 | + if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 4787 | 1753 | |
| 4788 | - // Load array of extrafields for elementype = $this->table_element |
|
| 4789 | - if (empty($extrafields->attributes[$this->table_element]['loaded'])) |
|
| 4790 | - {
|
|
| 4791 | - $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4792 | - } |
|
| 4793 | - $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
| 4794 | - } |
|
| 4795 | - else |
|
| 4796 | - {
|
|
| 4797 | - // global $extrafields; |
|
| 4798 | - dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
|
|
| 4799 | - } |
|
| 1754 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1755 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1756 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 4800 | 1757 | |
| 4801 | - $table_element = $this->table_element; |
|
| 4802 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 1758 | + if ($this->db->query($sql)) |
|
| 1759 | + {
|
|
| 1760 | + $this->mode_reglement_id = $id; |
|
| 1761 | + // for supplier |
|
| 1762 | + if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1763 | + return 1; |
|
| 1764 | + } |
|
| 1765 | + else |
|
| 1766 | + {
|
|
| 1767 | + dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
|
| 1768 | + $this->error=$this->db->error(); |
|
| 1769 | + return -1; |
|
| 1770 | + } |
|
| 1771 | + } |
|
| 1772 | + else |
|
| 1773 | + {
|
|
| 1774 | + dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
|
| 1775 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1776 | + return -2; |
|
| 1777 | + } |
|
| 1778 | + } |
|
| 4803 | 1779 | |
| 4804 | - // Request to get complementary values |
|
| 4805 | - if (is_array($optionsArray) && count($optionsArray) > 0) |
|
| 4806 | - {
|
|
| 4807 | - $sql = "SELECT rowid"; |
|
| 4808 | - foreach ($optionsArray as $name => $label) |
|
| 4809 | - {
|
|
| 4810 | - if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
|
| 4811 | - {
|
|
| 4812 | - $sql.= ", ".$name; |
|
| 4813 | - } |
|
| 4814 | - } |
|
| 4815 | - $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4816 | - $sql.= " WHERE fk_object = ".$rowid; |
|
| 1780 | + /** |
|
| 1781 | + * Change the multicurrency code |
|
| 1782 | + * |
|
| 1783 | + * @param string $code multicurrency code |
|
| 1784 | + * @return int >0 if OK, <0 if KO |
|
| 1785 | + */ |
|
| 1786 | + function setMulticurrencyCode($code) |
|
| 1787 | + {
|
|
| 1788 | + dol_syslog(get_class($this).'::setMulticurrencyCode('.$id.')');
|
|
| 1789 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1790 | + {
|
|
| 1791 | + $fieldname = 'multicurrency_code'; |
|
| 4817 | 1792 | |
| 4818 | - //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
|
| 4819 | - $resql=$this->db->query($sql); |
|
| 4820 | - if ($resql) |
|
| 4821 | - {
|
|
| 4822 | - $this->array_options = array(); |
|
| 4823 | - $numrows=$this->db->num_rows($resql); |
|
| 4824 | - if ($numrows) |
|
| 4825 | - {
|
|
| 4826 | - $tab = $this->db->fetch_array($resql); |
|
| 4827 | - |
|
| 4828 | - foreach ($tab as $key => $value) |
|
| 4829 | - {
|
|
| 4830 | - // 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) |
|
| 4831 | - if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4832 | - {
|
|
| 4833 | - // we can add this attribute to object |
|
| 4834 | - if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime')))
|
|
| 4835 | - {
|
|
| 4836 | - //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
|
| 4837 | - $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4838 | - } |
|
| 4839 | - else |
|
| 4840 | - {
|
|
| 4841 | - $this->array_options["options_".$key]=$value; |
|
| 4842 | - } |
|
| 1793 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1794 | + $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; |
|
| 1795 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 4843 | 1796 | |
| 4844 | - //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]);
|
|
| 4845 | - } |
|
| 4846 | - } |
|
| 4847 | - } |
|
| 1797 | + if ($this->db->query($sql)) |
|
| 1798 | + {
|
|
| 1799 | + $this->multicurrency_code = $code; |
|
| 4848 | 1800 | |
| 4849 | - $this->db->free($resql); |
|
| 1801 | + list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
|
| 1802 | + if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 4850 | 1803 | |
| 4851 | - if ($numrows) return $numrows; |
|
| 4852 | - else return 0; |
|
| 4853 | - } |
|
| 4854 | - else |
|
| 4855 | - {
|
|
| 4856 | - dol_print_error($this->db); |
|
| 4857 | - return -1; |
|
| 4858 | - } |
|
| 4859 | - } |
|
| 4860 | - return 0; |
|
| 4861 | - } |
|
| 4862 | - |
|
| 4863 | - /** |
|
| 4864 | - * Delete all extra fields values for the current object. |
|
| 4865 | - * |
|
| 4866 | - * @return int <0 if KO, >0 if OK |
|
| 4867 | - */ |
|
| 4868 | - function deleteExtraFields() |
|
| 4869 | - {
|
|
| 4870 | - $this->db->begin(); |
|
| 4871 | - |
|
| 4872 | - $table_element = $this->table_element; |
|
| 4873 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4874 | - |
|
| 4875 | - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 4876 | - dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
| 4877 | - $resql=$this->db->query($sql_del); |
|
| 4878 | - if (! $resql) |
|
| 4879 | - {
|
|
| 4880 | - $this->error=$this->db->lasterror(); |
|
| 4881 | - $this->db->rollback(); |
|
| 4882 | - return -1; |
|
| 4883 | - } |
|
| 4884 | - else |
|
| 4885 | - {
|
|
| 4886 | - $this->db->commit(); |
|
| 4887 | - return 1; |
|
| 4888 | - } |
|
| 4889 | - } |
|
| 4890 | - |
|
| 4891 | - /** |
|
| 4892 | - * Add/Update all extra fields values for the current object. |
|
| 4893 | - * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 4894 | - * This function delete record with all extrafields and insert them again from the array $this->array_options. |
|
| 4895 | - * |
|
| 4896 | - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 4897 | - * @param User $userused Object user |
|
| 4898 | - * @return int -1=error, O=did nothing, 1=OK |
|
| 4899 | - * @see updateExtraField, setValueFrom |
|
| 4900 | - */ |
|
| 4901 | - function insertExtraFields($trigger='', $userused=null) |
|
| 4902 | - {
|
|
| 4903 | - global $conf,$langs,$user; |
|
| 4904 | - |
|
| 4905 | - if (empty($userused)) $userused=$user; |
|
| 4906 | - |
|
| 4907 | - $error=0; |
|
| 4908 | - |
|
| 4909 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 4910 | - return 0; // For avoid conflicts if trigger used |
|
| 1804 | + return 1; |
|
| 1805 | + } |
|
| 1806 | + else |
|
| 1807 | + {
|
|
| 1808 | + dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
|
| 1809 | + $this->error=$this->db->error(); |
|
| 1810 | + return -1; |
|
| 1811 | + } |
|
| 1812 | + } |
|
| 1813 | + else |
|
| 1814 | + {
|
|
| 1815 | + dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
|
| 1816 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1817 | + return -2; |
|
| 1818 | + } |
|
| 1819 | + } |
|
| 4911 | 1820 | |
| 4912 | - if (! empty($this->array_options)) |
|
| 4913 | - {
|
|
| 4914 | - // Check parameters |
|
| 4915 | - $langs->load('admin');
|
|
| 4916 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4917 | - $extrafields = new AlExtraFields($this->db); |
|
| 4918 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 1821 | + /** |
|
| 1822 | + * Change the multicurrency rate |
|
| 1823 | + * |
|
| 1824 | + * @param double $rate multicurrency rate |
|
| 1825 | + * @param int $mode mode 1 : amounts in company currency will be recalculated, mode 2 : amounts in foreign currency |
|
| 1826 | + * @return int >0 if OK, <0 if KO |
|
| 1827 | + */ |
|
| 1828 | + function setMulticurrencyRate($rate, $mode=1) |
|
| 1829 | + {
|
|
| 1830 | + dol_syslog(get_class($this).'::setMulticurrencyRate('.$id.')');
|
|
| 1831 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1832 | + {
|
|
| 1833 | + $fieldname = 'multicurrency_tx'; |
|
| 4919 | 1834 | |
| 4920 | - //Eliminate copied source object extra_fields that do not exist in target object |
|
| 4921 | - $new_array_options=array(); |
|
| 4922 | - foreach ($this->array_options as $key => $value) {
|
|
| 4923 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4924 | - $new_array_options[$key] = $value; |
|
| 4925 | - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 4926 | - $new_array_options['options_'.$key] = $value; |
|
| 4927 | - } |
|
| 1835 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1836 | + $sql .= ' SET '.$fieldname.' = '.$rate; |
|
| 1837 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 4928 | 1838 | |
| 4929 | - foreach($new_array_options as $key => $value) |
|
| 4930 | - {
|
|
| 4931 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4932 | - $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
|
| 4933 | - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
|
| 4934 | - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
|
| 4935 | - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; |
|
| 4936 | - |
|
| 4937 | - if ($attributeRequired) |
|
| 4938 | - {
|
|
| 4939 | - $mandatorypb=false; |
|
| 4940 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4941 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4942 | - if ($mandatorypb) |
|
| 4943 | - {
|
|
| 4944 | - dol_syslog($this->error); |
|
| 4945 | - $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel);
|
|
| 4946 | - return -1; |
|
| 4947 | - } |
|
| 4948 | - } |
|
| 4949 | - |
|
| 4950 | - //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 4951 | - //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 4952 | - |
|
| 4953 | - switch ($attributeType) |
|
| 4954 | - {
|
|
| 4955 | - case 'int': |
|
| 4956 | - if (!is_numeric($value) && $value!='') |
|
| 4957 | - {
|
|
| 4958 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4959 | - return -1; |
|
| 4960 | - } |
|
| 4961 | - elseif ($value=='') |
|
| 4962 | - {
|
|
| 4963 | - $new_array_options[$key] = null; |
|
| 4964 | - } |
|
| 4965 | - break; |
|
| 4966 | - case 'double': |
|
| 4967 | - $value = price2num($value); |
|
| 4968 | - if (!is_numeric($value) && $value!='') |
|
| 4969 | - {
|
|
| 4970 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 4971 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4972 | - return -1; |
|
| 4973 | - } |
|
| 4974 | - elseif ($value=='') |
|
| 4975 | - {
|
|
| 4976 | - $new_array_options[$key] = null; |
|
| 4977 | - } |
|
| 4978 | - //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 4979 | - $new_array_options[$key] = $value; |
|
| 4980 | - break; |
|
| 4981 | - /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 4982 | - if ($value=='-1') |
|
| 4983 | - {
|
|
| 4984 | - $this->array_options[$key] = null; |
|
| 4985 | - } |
|
| 4986 | - break;*/ |
|
| 4987 | - case 'password': |
|
| 4988 | - $algo=''; |
|
| 4989 | - if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
|
| 4990 | - {
|
|
| 4991 | - // If there is an encryption choice, we use it to crypt data before insert |
|
| 4992 | - $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
|
| 4993 | - $algo=reset($tmparrays); |
|
| 4994 | - if ($algo != '') |
|
| 4995 | - {
|
|
| 4996 | - //global $action; // $action may be 'create', 'update', 'update_extras'... |
|
| 4997 | - //var_dump($action); |
|
| 4998 | - //var_dump($this->oldcopy);exit; |
|
| 4999 | - 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 |
|
| 5000 | - {
|
|
| 5001 | - //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
|
| 5002 | - 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. |
|
| 5003 | - {
|
|
| 5004 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5005 | - } |
|
| 5006 | - else |
|
| 5007 | - {
|
|
| 5008 | - // var_dump($algo); |
|
| 5009 | - $newvalue = dol_hash($this->array_options[$key], $algo); |
|
| 5010 | - $new_array_options[$key] = $newvalue; |
|
| 5011 | - } |
|
| 5012 | - } |
|
| 5013 | - else |
|
| 5014 | - {
|
|
| 5015 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5016 | - } |
|
| 5017 | - } |
|
| 5018 | - } |
|
| 5019 | - else // Common usage |
|
| 5020 | - {
|
|
| 5021 | - $new_array_options[$key] = $this->array_options[$key]; |
|
| 5022 | - } |
|
| 5023 | - break; |
|
| 5024 | - case 'price': |
|
| 5025 | - $new_array_options[$key] = price2num($this->array_options[$key]); |
|
| 5026 | - break; |
|
| 5027 | - case 'date': |
|
| 5028 | - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5029 | - break; |
|
| 5030 | - case 'datetime': |
|
| 5031 | - // If data is a string instead of a timestamp, we convert it |
|
| 5032 | - if (! is_int($this->array_options[$key])) {
|
|
| 5033 | - $this->array_options[$key] = strtotime($this->array_options[$key]); |
|
| 5034 | - } |
|
| 5035 | - $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5036 | - break; |
|
| 5037 | - case 'link': |
|
| 5038 | - $param_list=array_keys($attributeParam['options']); |
|
| 5039 | - // 0 : ObjectName |
|
| 5040 | - // 1 : classPath |
|
| 5041 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5042 | - dol_include_once($InfoFieldList[1]); |
|
| 5043 | - if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
|
| 5044 | - {
|
|
| 5045 | - if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5046 | - {
|
|
| 5047 | - $new_array_options[$key]=''; |
|
| 5048 | - } |
|
| 5049 | - elseif ($value) |
|
| 5050 | - {
|
|
| 5051 | - $object = new $InfoFieldList[0]($this->db); |
|
| 5052 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5053 | - else $res=$object->fetch('',$value);
|
|
| 5054 | - |
|
| 5055 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5056 | - else |
|
| 5057 | - {
|
|
| 5058 | - $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5059 | - $this->db->rollback(); |
|
| 5060 | - return -1; |
|
| 5061 | - } |
|
| 5062 | - } |
|
| 5063 | - } |
|
| 5064 | - else |
|
| 5065 | - {
|
|
| 5066 | - dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 5067 | - } |
|
| 5068 | - break; |
|
| 5069 | - } |
|
| 5070 | - } |
|
| 5071 | - |
|
| 5072 | - $this->db->begin(); |
|
| 1839 | + if ($this->db->query($sql)) |
|
| 1840 | + {
|
|
| 1841 | + $this->multicurrency_tx = $rate; |
|
| 1842 | + |
|
| 1843 | + // Update line price |
|
| 1844 | + if (!empty($this->lines)) |
|
| 1845 | + {
|
|
| 1846 | + foreach ($this->lines as &$line) |
|
| 1847 | + {
|
|
| 1848 | + if($mode == 1) {
|
|
| 1849 | + $line->subprice = 0; |
|
| 1850 | + } |
|
| 5073 | 1851 | |
| 5074 | - $table_element = $this->table_element; |
|
| 5075 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 1852 | + switch ($this->element) {
|
|
| 1853 | + case 'propal': |
|
| 1854 | + $this->updateline( |
|
| 1855 | + $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1856 | + ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1857 | + $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, |
|
| 1858 | + $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1859 | + ); |
|
| 1860 | + break; |
|
| 1861 | + case 'commande': |
|
| 1862 | + $this->updateline( |
|
| 1863 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1864 | + $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->date_start, $line->date_end, |
|
| 1865 | + $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1866 | + $line->special_code, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1867 | + ); |
|
| 1868 | + break; |
|
| 1869 | + case 'facture': |
|
| 1870 | + $this->updateline( |
|
| 1871 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1872 | + $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, |
|
| 1873 | + $line->product_type, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, |
|
| 1874 | + $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit, $line->multicurrency_subprice |
|
| 1875 | + ); |
|
| 1876 | + break; |
|
| 1877 | + case 'supplier_proposal': |
|
| 1878 | + $this->updateline( |
|
| 1879 | + $line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, |
|
| 1880 | + ($line->description?$line->description:$line->desc), 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, |
|
| 1881 | + $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->array_options, |
|
| 1882 | + $line->ref_fourn, $line->multicurrency_subprice |
|
| 1883 | + ); |
|
| 1884 | + break; |
|
| 1885 | + case 'order_supplier': |
|
| 1886 | + $this->updateline( |
|
| 1887 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->qty, $line->remise_percent, |
|
| 1888 | + $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, false, |
|
| 1889 | + $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1890 | + ); |
|
| 1891 | + break; |
|
| 1892 | + case 'invoice_supplier': |
|
| 1893 | + $this->updateline( |
|
| 1894 | + $line->id, ($line->description?$line->description:$line->desc), $line->subprice, $line->tva_tx, $line->localtax1_tx, |
|
| 1895 | + $line->localtax2_tx, $line->qty, 0, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, false, |
|
| 1896 | + $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice |
|
| 1897 | + ); |
|
| 1898 | + break; |
|
| 1899 | + default: |
|
| 1900 | + dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); |
|
| 1901 | + break; |
|
| 1902 | + } |
|
| 1903 | + } |
|
| 1904 | + } |
|
| 5076 | 1905 | |
| 5077 | - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 5078 | - dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
| 5079 | - $this->db->query($sql_del); |
|
| 1906 | + return 1; |
|
| 1907 | + } |
|
| 1908 | + else |
|
| 1909 | + {
|
|
| 1910 | + dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
|
| 1911 | + $this->error=$this->db->error(); |
|
| 1912 | + return -1; |
|
| 1913 | + } |
|
| 1914 | + } |
|
| 1915 | + else |
|
| 1916 | + {
|
|
| 1917 | + dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
|
| 1918 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1919 | + return -2; |
|
| 1920 | + } |
|
| 1921 | + } |
|
| 5080 | 1922 | |
| 5081 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
| 5082 | - foreach($new_array_options as $key => $value) |
|
| 5083 | - {
|
|
| 5084 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5085 | - // Add field of attribut |
|
| 5086 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5087 | - $sql.=",".$attributeKey; |
|
| 5088 | - } |
|
| 5089 | - $sql .= ") VALUES (".$this->id;
|
|
| 5090 | - |
|
| 5091 | - foreach($new_array_options as $key => $value) |
|
| 5092 | - {
|
|
| 5093 | - $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5094 | - // Add field of attribute |
|
| 5095 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5096 | - {
|
|
| 5097 | - if ($new_array_options[$key] != '') |
|
| 5098 | - {
|
|
| 5099 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5100 | - } |
|
| 5101 | - else |
|
| 5102 | - {
|
|
| 5103 | - $sql.=",null"; |
|
| 5104 | - } |
|
| 5105 | - } |
|
| 5106 | - } |
|
| 5107 | - $sql.=")"; |
|
| 1923 | + /** |
|
| 1924 | + * Change the payments terms |
|
| 1925 | + * |
|
| 1926 | + * @param int $id Id of new payment terms |
|
| 1927 | + * @return int >0 if OK, <0 if KO |
|
| 1928 | + */ |
|
| 1929 | + function setPaymentTerms($id) |
|
| 1930 | + {
|
|
| 1931 | + dol_syslog(get_class($this).'::setPaymentTerms('.$id.')');
|
|
| 1932 | + if ($this->statut >= 0 || $this->element == 'societe') |
|
| 1933 | + {
|
|
| 1934 | + // TODO uniformize field name |
|
| 1935 | + $fieldname = 'fk_cond_reglement'; |
|
| 1936 | + if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1937 | + if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 5108 | 1938 | |
| 5109 | - dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
| 5110 | - $resql = $this->db->query($sql); |
|
| 5111 | - if (! $resql) |
|
| 5112 | - {
|
|
| 5113 | - $this->error=$this->db->lasterror(); |
|
| 5114 | - $error++; |
|
| 5115 | - } |
|
| 1939 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 1940 | + $sql .= ' SET '.$fieldname.' = '.$id; |
|
| 1941 | + $sql .= ' WHERE rowid='.$this->id; |
|
| 5116 | 1942 | |
| 5117 | - if (! $error && $trigger) |
|
| 5118 | - {
|
|
| 5119 | - // Call trigger |
|
| 5120 | - $this->context=array('extrafieldaddupdate'=>1);
|
|
| 5121 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5122 | - if ($result < 0) $error++; |
|
| 5123 | - // End call trigger |
|
| 5124 | - } |
|
| 5125 | - |
|
| 5126 | - if ($error) |
|
| 5127 | - {
|
|
| 5128 | - $this->db->rollback(); |
|
| 5129 | - return -1; |
|
| 5130 | - } |
|
| 5131 | - else |
|
| 5132 | - {
|
|
| 5133 | - $this->db->commit(); |
|
| 5134 | - return 1; |
|
| 5135 | - } |
|
| 5136 | - } |
|
| 5137 | - else return 0; |
|
| 5138 | - } |
|
| 5139 | - |
|
| 5140 | - /** |
|
| 5141 | - * Update an extra field value for the current object. |
|
| 5142 | - * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 5143 | - * |
|
| 5144 | - * @param string $key Key of the extrafield (without starting 'options_') |
|
| 5145 | - * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 5146 | - * @param User $userused Object user |
|
| 5147 | - * @return int -1=error, O=did nothing, 1=OK |
|
| 5148 | - * @see setValueFrom, insertExtraFields |
|
| 5149 | - */ |
|
| 5150 | - function updateExtraField($key, $trigger=null, $userused=null) |
|
| 5151 | - {
|
|
| 5152 | - global $conf,$langs,$user; |
|
| 5153 | - |
|
| 5154 | - if (empty($userused)) $userused=$user; |
|
| 5155 | - |
|
| 5156 | - $error=0; |
|
| 5157 | - |
|
| 5158 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 5159 | - return 0; // For avoid conflicts if trigger used |
|
| 1943 | + if ($this->db->query($sql)) |
|
| 1944 | + {
|
|
| 1945 | + $this->cond_reglement_id = $id; |
|
| 1946 | + // for supplier |
|
| 1947 | + if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 1948 | + $this->cond_reglement = $id; // for compatibility |
|
| 1949 | + return 1; |
|
| 1950 | + } |
|
| 1951 | + else |
|
| 1952 | + {
|
|
| 1953 | + dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
|
| 1954 | + $this->error=$this->db->error(); |
|
| 1955 | + return -1; |
|
| 1956 | + } |
|
| 1957 | + } |
|
| 1958 | + else |
|
| 1959 | + {
|
|
| 1960 | + dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
|
| 1961 | + $this->error='Status of the object is incompatible '.$this->statut; |
|
| 1962 | + return -2; |
|
| 1963 | + } |
|
| 1964 | + } |
|
| 5160 | 1965 | |
| 5161 | - if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5162 | - {
|
|
| 5163 | - // Check parameters |
|
| 5164 | - $langs->load('admin');
|
|
| 5165 | - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 5166 | - $extrafields = new AlExtraFields($this->db); |
|
| 5167 | - $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 1966 | + /** |
|
| 1967 | + * Define delivery address |
|
| 1968 | + * @deprecated |
|
| 1969 | + * |
|
| 1970 | + * @param int $id Address id |
|
| 1971 | + * @return int <0 si ko, >0 si ok |
|
| 1972 | + */ |
|
| 1973 | + function setDeliveryAddress($id) |
|
| 1974 | + {
|
|
| 1975 | + $fieldname = 'fk_delivery_address'; |
|
| 1976 | + if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 5168 | 1977 | |
| 5169 | - $value=$this->array_options["options_".$key]; |
|
| 1978 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
|
| 1979 | + $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
|
| 5170 | 1980 | |
| 5171 | - $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
|
| 5172 | - $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
|
| 5173 | - $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; |
|
| 5174 | - $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; |
|
| 1981 | + if ($this->db->query($sql)) |
|
| 1982 | + {
|
|
| 1983 | + $this->fk_delivery_address = $id; |
|
| 1984 | + return 1; |
|
| 1985 | + } |
|
| 1986 | + else |
|
| 1987 | + {
|
|
| 1988 | + $this->error=$this->db->error(); |
|
| 1989 | + dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
|
| 1990 | + return -1; |
|
| 1991 | + } |
|
| 1992 | + } |
|
| 5175 | 1993 | |
| 5176 | - //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 5177 | - //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 5178 | 1994 | |
| 5179 | - switch ($attributeType) |
|
| 5180 | - {
|
|
| 5181 | - case 'int': |
|
| 5182 | - if (!is_numeric($value) && $value!='') |
|
| 5183 | - {
|
|
| 5184 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
|
| 5185 | - return -1; |
|
| 5186 | - } |
|
| 5187 | - elseif ($value=='') |
|
| 5188 | - {
|
|
| 5189 | - $this->array_options["options_".$key] = null; |
|
| 5190 | - } |
|
| 5191 | - break; |
|
| 5192 | - case 'double': |
|
| 5193 | - $value = price2num($value); |
|
| 5194 | - if (!is_numeric($value) && $value!='') |
|
| 5195 | - {
|
|
| 5196 | - dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 5197 | - $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5198 | - return -1; |
|
| 5199 | - } |
|
| 5200 | - elseif ($value=='') |
|
| 5201 | - {
|
|
| 5202 | - $this->array_options["options_".$key] = null; |
|
| 5203 | - } |
|
| 5204 | - //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 5205 | - $this->array_options["options_".$key] = $value; |
|
| 5206 | - break; |
|
| 5207 | - /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 5208 | - if ($value=='-1') |
|
| 5209 | - {
|
|
| 5210 | - $this->array_options[$key] = null; |
|
| 5211 | - } |
|
| 5212 | - break;*/ |
|
| 5213 | - case 'price': |
|
| 5214 | - $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
| 5215 | - break; |
|
| 5216 | - case 'date': |
|
| 5217 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5218 | - break; |
|
| 5219 | - case 'datetime': |
|
| 5220 | - $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5221 | - break; |
|
| 5222 | - case 'link': |
|
| 5223 | - $param_list=array_keys($attributeParam['options']); |
|
| 5224 | - // 0 : ObjectName |
|
| 5225 | - // 1 : classPath |
|
| 5226 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5227 | - dol_include_once($InfoFieldList[1]); |
|
| 5228 | - if ($value) |
|
| 5229 | - {
|
|
| 5230 | - $object = new $InfoFieldList[0]($this->db); |
|
| 5231 | - $object->fetch(0,$value); |
|
| 5232 | - $this->array_options["options_".$key]=$object->id; |
|
| 5233 | - } |
|
| 5234 | - break; |
|
| 5235 | - } |
|
| 5236 | - |
|
| 5237 | - $this->db->begin(); |
|
| 5238 | - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
| 5239 | - $sql .= " WHERE fk_object = ".$this->id; |
|
| 5240 | - $resql = $this->db->query($sql); |
|
| 5241 | - if (! $resql) |
|
| 5242 | - {
|
|
| 5243 | - $error++; |
|
| 5244 | - $this->error=$this->db->lasterror(); |
|
| 5245 | - } |
|
| 1995 | + /** |
|
| 1996 | + * Change the shipping method |
|
| 1997 | + * |
|
| 1998 | + * @param int $shipping_method_id Id of shipping method |
|
| 1999 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 2000 | + * @param User $userused Object user |
|
| 2001 | + * |
|
| 2002 | + * @return int 1 if OK, 0 if KO |
|
| 2003 | + */ |
|
| 2004 | + function setShippingMethod($shipping_method_id, $notrigger=false, $userused=null) |
|
| 2005 | + {
|
|
| 2006 | + global $user; |
|
| 5246 | 2007 | |
| 5247 | - if (! $error && $trigger) |
|
| 5248 | - {
|
|
| 5249 | - // Call trigger |
|
| 5250 | - $this->context=array('extrafieldupdate'=>1);
|
|
| 5251 | - $result=$this->call_trigger($trigger, $userused); |
|
| 5252 | - if ($result < 0) $error++; |
|
| 5253 | - // End call trigger |
|
| 5254 | - } |
|
| 5255 | - |
|
| 5256 | - if ($error) |
|
| 5257 | - {
|
|
| 5258 | - dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
| 5259 | - $this->db->rollback(); |
|
| 5260 | - return -1; |
|
| 5261 | - } |
|
| 5262 | - else |
|
| 5263 | - {
|
|
| 5264 | - $this->db->commit(); |
|
| 5265 | - return 1; |
|
| 5266 | - } |
|
| 5267 | - } |
|
| 5268 | - else return 0; |
|
| 5269 | - } |
|
| 5270 | - |
|
| 5271 | - |
|
| 5272 | - /** |
|
| 5273 | - * Return HTML string to put an input field into a page |
|
| 5274 | - * Code very similar with showInputField of extra fields |
|
| 5275 | - * |
|
| 5276 | - * @param array $val Array of properties for field to show |
|
| 5277 | - * @param string $key Key of attribute |
|
| 5278 | - * @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) |
|
| 5279 | - * @param string $moreparam To add more parameters on html input tag |
|
| 5280 | - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5281 | - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5282 | - * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
|
| 5283 | - * @return string |
|
| 5284 | - */ |
|
| 5285 | - function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
| 5286 | - {
|
|
| 5287 | - global $conf,$langs,$form; |
|
| 5288 | - |
|
| 5289 | - if (! is_object($form)) |
|
| 5290 | - {
|
|
| 5291 | - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5292 | - $form=new Form($this->db); |
|
| 5293 | - } |
|
| 5294 | - |
|
| 5295 | - $val=$this->fields[$key]; |
|
| 5296 | - |
|
| 5297 | - $out=''; |
|
| 5298 | - $type=''; |
|
| 5299 | - $param = array(); |
|
| 5300 | - $param['options']=array(); |
|
| 5301 | - $size =$this->fields[$key]['size']; |
|
| 5302 | - // Because we work on extrafields |
|
| 5303 | - if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){
|
|
| 5304 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5305 | - $type ='link'; |
|
| 5306 | - } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5307 | - $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5308 | - $type ='link'; |
|
| 5309 | - } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5310 | - $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5311 | - $type ='sellist'; |
|
| 5312 | - } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) {
|
|
| 5313 | - $param['options']=array(); |
|
| 5314 | - $type ='varchar'; |
|
| 5315 | - $size=$reg[1]; |
|
| 5316 | - } elseif(preg_match('/varchar/', $val['type'])) {
|
|
| 5317 | - $param['options']=array(); |
|
| 5318 | - $type ='varchar'; |
|
| 5319 | - } elseif(is_array($this->fields[$key]['arrayofkeyval'])) {
|
|
| 5320 | - $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
| 5321 | - $type ='select'; |
|
| 5322 | - } else {
|
|
| 5323 | - $param['options']=array(); |
|
| 5324 | - $type =$this->fields[$key]['type']; |
|
| 5325 | - } |
|
| 2008 | + if (empty($userused)) $userused=$user; |
|
| 5326 | 2009 | |
| 5327 | - $label=$this->fields[$key]['label']; |
|
| 5328 | - //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
|
| 5329 | - $default=$this->fields[$key]['default']; |
|
| 5330 | - $computed=$this->fields[$key]['computed']; |
|
| 5331 | - $unique=$this->fields[$key]['unique']; |
|
| 5332 | - $required=$this->fields[$key]['required']; |
|
| 2010 | + $error = 0; |
|
| 5333 | 2011 | |
| 5334 | - $langfile=$this->fields[$key]['langfile']; |
|
| 5335 | - $list=$this->fields[$key]['list']; |
|
| 5336 | - $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
| 2012 | + if (! $this->table_element) {
|
|
| 2013 | + dol_syslog(get_class($this)."::setShippingMethod was called on objet with property table_element not defined",LOG_ERR); |
|
| 2014 | + return -1; |
|
| 2015 | + } |
|
| 5337 | 2016 | |
| 5338 | - $objectid = $this->id; |
|
| 2017 | + $this->db->begin(); |
|
| 5339 | 2018 | |
| 2019 | + if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2020 | + dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
|
| 5340 | 2021 | |
| 5341 | - if ($computed) |
|
| 5342 | - {
|
|
| 5343 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5344 | - else return ''; |
|
| 5345 | - } |
|
| 2022 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2023 | + $sql.= " SET fk_shipping_method = ".$shipping_method_id; |
|
| 2024 | + $sql.= " WHERE rowid=".$this->id; |
|
| 2025 | + $resql = $this->db->query($sql); |
|
| 2026 | + if (! $resql) {
|
|
| 2027 | + dol_syslog(get_class($this).'::setShippingMethod Error ', LOG_DEBUG); |
|
| 2028 | + $this->error = $this->db->lasterror(); |
|
| 2029 | + $error++; |
|
| 2030 | + } else {
|
|
| 2031 | + if (!$notrigger) |
|
| 2032 | + {
|
|
| 2033 | + // Call trigger |
|
| 2034 | + $this->context=array('shippingmethodupdate'=>1);
|
|
| 2035 | + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2036 | + if ($result < 0) $error++; |
|
| 2037 | + // End call trigger |
|
| 2038 | + } |
|
| 2039 | + } |
|
| 2040 | + if ($error) |
|
| 2041 | + {
|
|
| 2042 | + $this->db->rollback(); |
|
| 2043 | + return -1; |
|
| 2044 | + } else {
|
|
| 2045 | + $this->shipping_method_id = ($shipping_method_id=='NULL')?null:$shipping_method_id; |
|
| 2046 | + $this->db->commit(); |
|
| 2047 | + return 1; |
|
| 2048 | + } |
|
| 2049 | + } |
|
| 5346 | 2050 | |
| 5347 | 2051 | |
| 5348 | - // Use in priority showsize from parameters, then $val['css'] then autodefine |
|
| 5349 | - if (empty($morecss) && ! empty($val['css'])) |
|
| 5350 | - {
|
|
| 5351 | - $showsize = $val['css']; |
|
| 5352 | - } |
|
| 5353 | - if (empty($morecss)) |
|
| 5354 | - {
|
|
| 5355 | - if ($type == 'date') |
|
| 5356 | - {
|
|
| 5357 | - $morecss = 'minwidth100imp'; |
|
| 5358 | - } |
|
| 5359 | - elseif ($type == 'datetime') |
|
| 5360 | - {
|
|
| 5361 | - $morecss = 'minwidth200imp'; |
|
| 5362 | - } |
|
| 5363 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5364 | - {
|
|
| 5365 | - $morecss = 'maxwidth75'; |
|
| 5366 | - }elseif ($type == 'url') |
|
| 5367 | - {
|
|
| 5368 | - $morecss='minwidth400'; |
|
| 5369 | - } |
|
| 5370 | - elseif ($type == 'boolean') |
|
| 5371 | - {
|
|
| 5372 | - $morecss=''; |
|
| 5373 | - } |
|
| 5374 | - else |
|
| 5375 | - {
|
|
| 5376 | - if (round($size) < 12) |
|
| 5377 | - {
|
|
| 5378 | - $morecss = 'minwidth100'; |
|
| 5379 | - } |
|
| 5380 | - else if (round($size) <= 48) |
|
| 5381 | - {
|
|
| 5382 | - $morecss = 'minwidth200'; |
|
| 5383 | - } |
|
| 5384 | - else |
|
| 5385 | - {
|
|
| 5386 | - $morecss = 'minwidth400'; |
|
| 5387 | - } |
|
| 5388 | - } |
|
| 5389 | - } |
|
| 5390 | - |
|
| 5391 | - if (in_array($type,array('date','datetime')))
|
|
| 5392 | - {
|
|
| 5393 | - $tmp=explode(',',$size);
|
|
| 5394 | - $newsize=$tmp[0]; |
|
| 5395 | - |
|
| 5396 | - $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
|
| 5397 | - |
|
| 5398 | - // Do not show current date when field not required (see selectDate() method) |
|
| 5399 | - if (!$required && $value == '') $value = '-1'; |
|
| 5400 | - |
|
| 5401 | - // TODO Must also support $moreparam |
|
| 5402 | - $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
| 5403 | - } |
|
| 5404 | - elseif (in_array($type,array('int','integer')))
|
|
| 5405 | - {
|
|
| 5406 | - $tmp=explode(',',$size);
|
|
| 5407 | - $newsize=$tmp[0]; |
|
| 5408 | - $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:'').'>'; |
|
| 5409 | - } |
|
| 5410 | - elseif (preg_match('/varchar/', $type))
|
|
| 5411 | - {
|
|
| 5412 | - $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:'').'>'; |
|
| 5413 | - } |
|
| 5414 | - elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5415 | - {
|
|
| 5416 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5417 | - } |
|
| 5418 | - elseif ($type == 'text') |
|
| 5419 | - {
|
|
| 5420 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5421 | - {
|
|
| 5422 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5423 | - $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 5424 | - $out=$doleditor->Create(1); |
|
| 5425 | - } |
|
| 5426 | - else |
|
| 5427 | - {
|
|
| 5428 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5429 | - } |
|
| 5430 | - } |
|
| 5431 | - elseif ($type == 'html') |
|
| 5432 | - {
|
|
| 5433 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5434 | - {
|
|
| 5435 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5436 | - $doleditor = new DolEditor($keyprefix . $key . $keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty(Globals::$conf->fckeditor->enabled) && Globals::$conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); |
|
| 5437 | - $out=$doleditor->Create(1); |
|
| 5438 | - } |
|
| 5439 | - else |
|
| 5440 | - {
|
|
| 5441 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5442 | - } |
|
| 5443 | - } |
|
| 5444 | - elseif ($type == 'boolean') |
|
| 5445 | - {
|
|
| 5446 | - $checked=''; |
|
| 5447 | - if (!empty($value)) {
|
|
| 5448 | - $checked=' checked value="1" '; |
|
| 5449 | - } else {
|
|
| 5450 | - $checked=' value="1" '; |
|
| 5451 | - } |
|
| 5452 | - $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5453 | - } |
|
| 5454 | - elseif ($type == 'price') |
|
| 5455 | - {
|
|
| 5456 | - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5457 | - $value=price($value); |
|
| 5458 | - } |
|
| 5459 | - $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '> ' . $langs->getCurrencySymbol(Globals::$conf->currency); |
|
| 5460 | - } |
|
| 5461 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5462 | - {
|
|
| 5463 | - if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5464 | - $value=price($value); |
|
| 5465 | - } |
|
| 5466 | - $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5467 | - } |
|
| 5468 | - elseif ($type == 'select') |
|
| 5469 | - {
|
|
| 5470 | - $out = ''; |
|
| 5471 | - if (!empty(Globals::$conf->use_javascript_ajax) && !empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
|
| 5472 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5473 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5474 | - } |
|
| 5475 | - |
|
| 5476 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5477 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5478 | - foreach ($param['options'] as $key => $val) |
|
| 5479 | - {
|
|
| 5480 | - if ((string) $key == '') continue; |
|
| 5481 | - list($val, $parent) = explode('|', $val);
|
|
| 5482 | - $out.='<option value="'.$key.'"'; |
|
| 5483 | - $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5484 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5485 | - $out.='>'.$val.'</option>'; |
|
| 5486 | - } |
|
| 5487 | - $out.='</select>'; |
|
| 5488 | - } |
|
| 5489 | - elseif ($type == 'sellist') |
|
| 5490 | - {
|
|
| 5491 | - $out = ''; |
|
| 5492 | - if (!empty(Globals::$conf->use_javascript_ajax) && !empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
|
| 5493 | - include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5494 | - $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5495 | - } |
|
| 5496 | - |
|
| 5497 | - $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5498 | - if (is_array($param['options'])) |
|
| 5499 | - {
|
|
| 5500 | - $param_list=array_keys($param['options']); |
|
| 5501 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5502 | - $parentName=''; |
|
| 5503 | - $parentField=''; |
|
| 5504 | - // 0 : tableName |
|
| 5505 | - // 1 : label field name |
|
| 5506 | - // 2 : key fields name (if differ of rowid) |
|
| 5507 | - // 3 : key field parent (for dependent lists) |
|
| 5508 | - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5509 | - $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5510 | - |
|
| 5511 | - |
|
| 5512 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5513 | - {
|
|
| 5514 | - if (strpos($InfoFieldList[4], 'extra.') !== false) |
|
| 5515 | - {
|
|
| 5516 | - $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5517 | - } else {
|
|
| 5518 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5519 | - } |
|
| 5520 | - } |
|
| 5521 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5522 | - {
|
|
| 5523 | - list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
|
|
| 5524 | - $keyList.= ', '.$parentField; |
|
| 5525 | - } |
|
| 2052 | + /** |
|
| 2053 | + * Change the warehouse |
|
| 2054 | + * |
|
| 2055 | + * @param int $warehouse_id Id of warehouse |
|
| 2056 | + * @return int 1 if OK, 0 if KO |
|
| 2057 | + */ |
|
| 2058 | + function setWarehouse($warehouse_id) |
|
| 2059 | + {
|
|
| 2060 | + if (! $this->table_element) {
|
|
| 2061 | + dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
|
| 2062 | + return -1; |
|
| 2063 | + } |
|
| 2064 | + if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2065 | + dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
|
| 5526 | 2066 | |
| 5527 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5528 | - if (is_array($fields_label)) |
|
| 5529 | - {
|
|
| 5530 | - $keyList .=', '; |
|
| 5531 | - $keyList .= implode(', ', $fields_label);
|
|
| 5532 | - } |
|
| 2067 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2068 | + $sql.= " SET fk_warehouse = ".$warehouse_id; |
|
| 2069 | + $sql.= " WHERE rowid=".$this->id; |
|
| 5533 | 2070 | |
| 5534 | - $sqlwhere=''; |
|
| 5535 | - $sql = 'SELECT '.$keyList; |
|
| 5536 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5537 | - if (!empty($InfoFieldList[4])) |
|
| 5538 | - {
|
|
| 5539 | - // can use SELECT request |
|
| 5540 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5541 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5542 | - } |
|
| 5543 | - |
|
| 5544 | - // current object id can be use into filter |
|
| 5545 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5546 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5547 | - } else {
|
|
| 5548 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5549 | - } |
|
| 5550 | - //We have to join on extrafield table |
|
| 5551 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5552 | - {
|
|
| 5553 | - $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5554 | - $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5555 | - } |
|
| 5556 | - else |
|
| 5557 | - {
|
|
| 5558 | - $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5559 | - } |
|
| 5560 | - } |
|
| 5561 | - else |
|
| 5562 | - {
|
|
| 5563 | - $sqlwhere.= ' WHERE 1=1'; |
|
| 5564 | - } |
|
| 5565 | - // Some tables may have field, some other not. For the moment we disable it. |
|
| 5566 | - if (in_array($InfoFieldList[0],array('tablewithentity')))
|
|
| 5567 | - {
|
|
| 5568 | - $sqlwhere .= ' AND entity = ' . Globals::$conf->entity; |
|
| 5569 | - } |
|
| 5570 | - $sql.=$sqlwhere; |
|
| 5571 | - //print $sql; |
|
| 2071 | + if ($this->db->query($sql)) {
|
|
| 2072 | + $this->warehouse_id = ($warehouse_id=='NULL')?null:$warehouse_id; |
|
| 2073 | + return 1; |
|
| 2074 | + } else {
|
|
| 2075 | + dol_syslog(get_class($this).'::setWarehouse Error ', LOG_DEBUG); |
|
| 2076 | + $this->error=$this->db->error(); |
|
| 2077 | + return 0; |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 5572 | 2080 | |
| 5573 | - $sql .= ' ORDER BY ' . implode(', ', $fields_label);
|
|
| 5574 | 2081 | |
| 5575 | - dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
| 5576 | - $resql = $this->db->query($sql); |
|
| 5577 | - if ($resql) |
|
| 5578 | - {
|
|
| 5579 | - $out.='<option value="0"> </option>'; |
|
| 5580 | - $num = $this->db->num_rows($resql); |
|
| 5581 | - $i = 0; |
|
| 5582 | - while ($i < $num) |
|
| 5583 | - {
|
|
| 5584 | - $labeltoshow=''; |
|
| 5585 | - $obj = $this->db->fetch_object($resql); |
|
| 5586 | - |
|
| 5587 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 5588 | - $notrans = false; |
|
| 5589 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5590 | - if (is_array($fields_label)) |
|
| 5591 | - {
|
|
| 5592 | - $notrans = true; |
|
| 5593 | - foreach ($fields_label as $field_toshow) |
|
| 5594 | - {
|
|
| 5595 | - $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5596 | - } |
|
| 5597 | - } |
|
| 5598 | - else |
|
| 5599 | - {
|
|
| 5600 | - $labeltoshow=$obj->{$InfoFieldList[1]};
|
|
| 5601 | - } |
|
| 5602 | - $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5603 | - |
|
| 5604 | - if ($value == $obj->rowid) |
|
| 5605 | - {
|
|
| 5606 | - foreach ($fields_label as $field_toshow) |
|
| 5607 | - {
|
|
| 5608 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 5609 | - if ($translabel!=$obj->$field_toshow) {
|
|
| 5610 | - $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5611 | - }else {
|
|
| 5612 | - $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5613 | - } |
|
| 5614 | - } |
|
| 5615 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5616 | - } |
|
| 5617 | - else |
|
| 5618 | - {
|
|
| 5619 | - if (! $notrans) |
|
| 5620 | - {
|
|
| 5621 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5622 | - if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 5623 | - $labeltoshow=dol_trunc($translabel,18); |
|
| 5624 | - } |
|
| 5625 | - else {
|
|
| 5626 | - $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
|
| 5627 | - } |
|
| 5628 | - } |
|
| 5629 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5630 | - if ($value==$obj->rowid) |
|
| 5631 | - {
|
|
| 5632 | - $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5633 | - } |
|
| 2082 | + /** |
|
| 2083 | + * Set last model used by doc generator |
|
| 2084 | + * |
|
| 2085 | + * @param User $user User object that make change |
|
| 2086 | + * @param string $modelpdf Modele name |
|
| 2087 | + * @return int <0 if KO, >0 if OK |
|
| 2088 | + */ |
|
| 2089 | + function setDocModel($user, $modelpdf) |
|
| 2090 | + {
|
|
| 2091 | + if (! $this->table_element) |
|
| 2092 | + {
|
|
| 2093 | + dol_syslog(get_class($this)."::setDocModel was called on objet with property table_element not defined",LOG_ERR); |
|
| 2094 | + return -1; |
|
| 2095 | + } |
|
| 5634 | 2096 | |
| 5635 | - if (!empty($InfoFieldList[3]) && $parentField) |
|
| 5636 | - {
|
|
| 5637 | - $parent = $parentName.':'.$obj->{$parentField};
|
|
| 5638 | - } |
|
| 2097 | + $newmodelpdf=dol_trunc($modelpdf,255); |
|
| 5639 | 2098 | |
| 5640 | - $out.='<option value="'.$obj->rowid.'"'; |
|
| 5641 | - $out.= ($value==$obj->rowid?' selected':''); |
|
| 5642 | - $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5643 | - $out.='>'.$labeltoshow.'</option>'; |
|
| 5644 | - } |
|
| 2099 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2100 | + $sql.= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; |
|
| 2101 | + $sql.= " WHERE rowid = ".$this->id; |
|
| 2102 | + // if ($this->element == 'facture') $sql.= " AND fk_statut < 2"; |
|
| 2103 | + // if ($this->element == 'propal') $sql.= " AND fk_statut = 0"; |
|
| 5645 | 2104 | |
| 5646 | - $i++; |
|
| 5647 | - } |
|
| 5648 | - $this->db->free($resql); |
|
| 5649 | - } |
|
| 5650 | - else {
|
|
| 5651 | - print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5652 | - } |
|
| 5653 | - } |
|
| 5654 | - $out.='</select>'; |
|
| 5655 | - } |
|
| 5656 | - elseif ($type == 'checkbox') |
|
| 5657 | - {
|
|
| 5658 | - $value_arr=explode(',',$value);
|
|
| 5659 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5660 | - } |
|
| 5661 | - elseif ($type == 'radio') |
|
| 5662 | - {
|
|
| 5663 | - $out=''; |
|
| 5664 | - foreach ($param['options'] as $keyopt => $val) |
|
| 5665 | - {
|
|
| 5666 | - $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5667 | - $out.=' value="'.$keyopt.'"'; |
|
| 5668 | - $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5669 | - $out.= ($value==$keyopt?'checked':''); |
|
| 5670 | - $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5671 | - } |
|
| 5672 | - } |
|
| 5673 | - elseif ($type == 'chkbxlst') |
|
| 5674 | - {
|
|
| 5675 | - if (is_array($value)) {
|
|
| 5676 | - $value_arr = $value; |
|
| 5677 | - } |
|
| 5678 | - else {
|
|
| 5679 | - $value_arr = explode(',', $value);
|
|
| 5680 | - } |
|
| 5681 | - |
|
| 5682 | - if (is_array($param['options'])) {
|
|
| 5683 | - $param_list = array_keys($param['options']); |
|
| 5684 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5685 | - $parentName=''; |
|
| 5686 | - $parentField=''; |
|
| 5687 | - // 0 : tableName |
|
| 5688 | - // 1 : label field name |
|
| 5689 | - // 2 : key fields name (if differ of rowid) |
|
| 5690 | - // 3 : key field parent (for dependent lists) |
|
| 5691 | - // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5692 | - $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5693 | - |
|
| 5694 | - if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
|
|
| 5695 | - list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
|
|
| 5696 | - $keyList .= ', ' . $parentField; |
|
| 5697 | - } |
|
| 5698 | - if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
|
|
| 5699 | - if (strpos($InfoFieldList[4], 'extra.') !== false) {
|
|
| 5700 | - $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5701 | - } else {
|
|
| 5702 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5703 | - } |
|
| 5704 | - } |
|
| 2105 | + dol_syslog(get_class($this)."::setDocModel", LOG_DEBUG); |
|
| 2106 | + $resql=$this->db->query($sql); |
|
| 2107 | + if ($resql) |
|
| 2108 | + {
|
|
| 2109 | + $this->modelpdf=$modelpdf; |
|
| 2110 | + return 1; |
|
| 2111 | + } |
|
| 2112 | + else |
|
| 2113 | + {
|
|
| 2114 | + dol_print_error($this->db); |
|
| 2115 | + return 0; |
|
| 2116 | + } |
|
| 2117 | + } |
|
| 5705 | 2118 | |
| 5706 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5707 | - if (is_array($fields_label)) {
|
|
| 5708 | - $keyList .= ', '; |
|
| 5709 | - $keyList .= implode(', ', $fields_label);
|
|
| 5710 | - } |
|
| 5711 | 2119 | |
| 5712 | - $sqlwhere = ''; |
|
| 5713 | - $sql = 'SELECT ' . $keyList; |
|
| 5714 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5715 | - if (! empty($InfoFieldList[4])) {
|
|
| 5716 | - |
|
| 5717 | - // can use SELECT request |
|
| 5718 | - if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5719 | - $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5720 | - } |
|
| 5721 | - |
|
| 5722 | - // current object id can be use into filter |
|
| 5723 | - if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5724 | - $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5725 | - } else {
|
|
| 5726 | - $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5727 | - } |
|
| 5728 | - |
|
| 5729 | - // We have to join on extrafield table |
|
| 5730 | - if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 5731 | - $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5732 | - $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5733 | - } else {
|
|
| 5734 | - $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5735 | - } |
|
| 5736 | - } else {
|
|
| 5737 | - $sqlwhere .= ' WHERE 1=1'; |
|
| 5738 | - } |
|
| 5739 | - // Some tables may have field, some other not. For the moment we disable it. |
|
| 5740 | - if (in_array($InfoFieldList[0], array ('tablewithentity')))
|
|
| 5741 | - {
|
|
| 5742 | - $sqlwhere .= ' AND entity = ' . Globals::$conf->entity; |
|
| 5743 | - } |
|
| 5744 | - // $sql.=preg_replace('/^ AND /','',$sqlwhere);
|
|
| 5745 | - // print $sql; |
|
| 5746 | - |
|
| 5747 | - $sql .= $sqlwhere; |
|
| 5748 | - dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5749 | - $resql = $this->db->query($sql); |
|
| 5750 | - if ($resql) {
|
|
| 5751 | - $num = $this->db->num_rows($resql); |
|
| 5752 | - $i = 0; |
|
| 5753 | - |
|
| 5754 | - $data=array(); |
|
| 5755 | - |
|
| 5756 | - while ( $i < $num ) {
|
|
| 5757 | - $labeltoshow = ''; |
|
| 5758 | - $obj = $this->db->fetch_object($resql); |
|
| 5759 | - |
|
| 5760 | - $notrans = false; |
|
| 5761 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 5762 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5763 | - if (is_array($fields_label)) {
|
|
| 5764 | - $notrans = true; |
|
| 5765 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 5766 | - $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 5767 | - } |
|
| 5768 | - } else {
|
|
| 5769 | - $labeltoshow = $obj->{$InfoFieldList[1]};
|
|
| 5770 | - } |
|
| 5771 | - $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5772 | - |
|
| 5773 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5774 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 5775 | - $translabel = $langs->trans($obj->$field_toshow); |
|
| 5776 | - if ($translabel != $obj->$field_toshow) {
|
|
| 5777 | - $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5778 | - } else {
|
|
| 5779 | - $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5780 | - } |
|
| 5781 | - } |
|
| 2120 | + /** |
|
| 2121 | + * Change the bank account |
|
| 2122 | + * |
|
| 2123 | + * @param int $fk_account Id of bank account |
|
| 2124 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 2125 | + * @param User $userused Object user |
|
| 2126 | + * @return int 1 if OK, 0 if KO |
|
| 2127 | + */ |
|
| 2128 | + function setBankAccount($fk_account, $notrigger=false, $userused=null) |
|
| 2129 | + {
|
|
| 2130 | + global $user; |
|
| 5782 | 2131 | |
| 5783 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5784 | - } else {
|
|
| 5785 | - if (! $notrans) {
|
|
| 5786 | - $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5787 | - if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 5788 | - $labeltoshow = dol_trunc($translabel, 18); |
|
| 5789 | - } else {
|
|
| 5790 | - $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
|
| 5791 | - } |
|
| 5792 | - } |
|
| 5793 | - if (empty($labeltoshow)) |
|
| 5794 | - $labeltoshow = '(not defined)'; |
|
| 2132 | + if (empty($userused)) $userused=$user; |
|
| 5795 | 2133 | |
| 5796 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5797 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5798 | - } |
|
| 2134 | + $error = 0; |
|
| 5799 | 2135 | |
| 5800 | - if (! empty($InfoFieldList[3]) && $parentField) {
|
|
| 5801 | - $parent = $parentName . ':' . $obj->{$parentField};
|
|
| 5802 | - } |
|
| 2136 | + if (! $this->table_element) {
|
|
| 2137 | + dol_syslog(get_class($this)."::setBankAccount was called on objet with property table_element not defined",LOG_ERR); |
|
| 2138 | + return -1; |
|
| 2139 | + } |
|
| 2140 | + $this->db->begin(); |
|
| 5803 | 2141 | |
| 5804 | - $data[$obj->rowid]=$labeltoshow; |
|
| 5805 | - } |
|
| 2142 | + if ($fk_account<0) $fk_account='NULL'; |
|
| 2143 | + dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
|
| 5806 | 2144 | |
| 5807 | - $i ++; |
|
| 5808 | - } |
|
| 5809 | - $this->db->free($resql); |
|
| 2145 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 2146 | + $sql.= " SET fk_account = ".$fk_account; |
|
| 2147 | + $sql.= " WHERE rowid=".$this->id; |
|
| 5810 | 2148 | |
| 5811 | - $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5812 | - } else {
|
|
| 5813 | - print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5814 | - } |
|
| 5815 | - } |
|
| 5816 | - } |
|
| 5817 | - elseif ($type == 'link') |
|
| 5818 | - {
|
|
| 5819 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5820 | - $showempty=(($required && $default != '')?0:1); |
|
| 5821 | - $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5822 | - if (Globals::$conf->global->MAIN_FEATURES_LEVEL >= 2) {
|
|
| 5823 | - list($class,$classfile)=explode(':',$param_list[0]);
|
|
| 5824 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5825 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 5826 | - $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5827 | - // TODO Add Javascript code to add input fields contents to new elements urls |
|
| 5828 | - } |
|
| 5829 | - } |
|
| 5830 | - elseif ($type == 'password') |
|
| 5831 | - {
|
|
| 5832 | - // If prefix is 'search_', field is used as a filter, we use a common text field. |
|
| 5833 | - $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5834 | - } |
|
| 5835 | - elseif ($type == 'array') |
|
| 5836 | - {
|
|
| 5837 | - $newval = $val; |
|
| 5838 | - $newval['type'] = 'varchar(256)'; |
|
| 5839 | - |
|
| 5840 | - $out=''; |
|
| 5841 | - |
|
| 5842 | - $inputs = array(); |
|
| 5843 | - if(! empty($value)) {
|
|
| 5844 | - foreach($value as $option) {
|
|
| 5845 | - $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5846 | - $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5847 | - } |
|
| 5848 | - } |
|
| 2149 | + $resql = $this->db->query($sql); |
|
| 2150 | + if (! $resql) |
|
| 2151 | + {
|
|
| 2152 | + dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
|
| 2153 | + $this->error = $this->db->lasterror(); |
|
| 2154 | + $error++; |
|
| 2155 | + } |
|
| 2156 | + else |
|
| 2157 | + {
|
|
| 2158 | + if (!$notrigger) |
|
| 2159 | + {
|
|
| 2160 | + // Call trigger |
|
| 2161 | + $this->context=array('bankaccountupdate'=>1);
|
|
| 2162 | + $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
|
| 2163 | + if ($result < 0) $error++; |
|
| 2164 | + // End call trigger |
|
| 2165 | + } |
|
| 2166 | + } |
|
| 2167 | + if ($error) |
|
| 2168 | + {
|
|
| 2169 | + $this->db->rollback(); |
|
| 2170 | + return -1; |
|
| 2171 | + } |
|
| 2172 | + else |
|
| 2173 | + {
|
|
| 2174 | + $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
|
| 2175 | + $this->db->commit(); |
|
| 2176 | + return 1; |
|
| 2177 | + } |
|
| 2178 | + } |
|
| 5849 | 2179 | |
| 5850 | - $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5851 | 2180 | |
| 5852 | - $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5853 | - $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 2181 | + // TODO: Move line related operations to CommonObjectLine? |
|
| 5854 | 2182 | |
| 5855 | - if (!empty(Globals::$conf->use_javascript_ajax)) {
|
|
| 5856 | - $out.= ' |
|
| 5857 | - <script type="text/javascript"> |
|
| 5858 | - $(document).ready(function() {
|
|
| 5859 | - $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() {
|
|
| 5860 | - $("'.dol_escape_js($newInput).'").insertBefore(this);
|
|
| 5861 | - }); |
|
| 2183 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2184 | + /** |
|
| 2185 | + * Save a new position (field rang) for details lines. |
|
| 2186 | + * You can choose to set position for lines with already a position or lines without any position defined. |
|
| 2187 | + * |
|
| 2188 | + * @param boolean $renum True to renum all already ordered lines, false to renum only not already ordered lines. |
|
| 2189 | + * @param string $rowidorder ASC or DESC |
|
| 2190 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2191 | + * @return int <0 if KO, >0 if OK |
|
| 2192 | + */ |
|
| 2193 | + function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true) |
|
| 2194 | + {
|
|
| 2195 | + // phpcs:enable |
|
| 2196 | + if (! $this->table_element_line) |
|
| 2197 | + {
|
|
| 2198 | + dol_syslog(get_class($this)."::line_order was called on objet with property table_element_line not defined",LOG_ERR); |
|
| 2199 | + return -1; |
|
| 2200 | + } |
|
| 2201 | + if (! $this->fk_element) |
|
| 2202 | + {
|
|
| 2203 | + dol_syslog(get_class($this)."::line_order was called on objet with property fk_element not defined",LOG_ERR); |
|
| 2204 | + return -1; |
|
| 2205 | + } |
|
| 2206 | + |
|
| 2207 | + // Count number of lines to reorder (according to choice $renum) |
|
| 2208 | + $nl=0; |
|
| 2209 | + $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2210 | + $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
|
| 2211 | + if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2212 | + if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2213 | + |
|
| 2214 | + dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
|
| 2215 | + $resql = $this->db->query($sql); |
|
| 2216 | + if ($resql) |
|
| 2217 | + {
|
|
| 2218 | + $row = $this->db->fetch_row($resql); |
|
| 2219 | + $nl = $row[0]; |
|
| 2220 | + } |
|
| 2221 | + else dol_print_error($this->db); |
|
| 2222 | + if ($nl > 0) |
|
| 2223 | + {
|
|
| 2224 | + // The goal of this part is to reorder all lines, with all children lines sharing the same |
|
| 2225 | + // counter that parents. |
|
| 2226 | + $rows=array(); |
|
| 2227 | + |
|
| 2228 | + // We first search all lines that are parent lines (for multilevel details lines) |
|
| 2229 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2230 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2231 | + if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2232 | + $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
|
| 2233 | + |
|
| 2234 | + dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
|
| 2235 | + $resql = $this->db->query($sql); |
|
| 2236 | + if ($resql) |
|
| 2237 | + {
|
|
| 2238 | + $i=0; |
|
| 2239 | + $num = $this->db->num_rows($resql); |
|
| 2240 | + while ($i < $num) |
|
| 2241 | + {
|
|
| 2242 | + $row = $this->db->fetch_row($resql); |
|
| 2243 | + $rows[] = $row[0]; // Add parent line into array rows |
|
| 2244 | + $childrens = $this->getChildrenOfLine($row[0]); |
|
| 2245 | + if (! empty($childrens)) |
|
| 2246 | + {
|
|
| 2247 | + foreach($childrens as $child) |
|
| 2248 | + {
|
|
| 2249 | + array_push($rows, $child); |
|
| 2250 | + } |
|
| 2251 | + } |
|
| 2252 | + $i++; |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + // Now we set a new number for each lines (parent and children with children included into parent tree) |
|
| 2256 | + if (! empty($rows)) |
|
| 2257 | + {
|
|
| 2258 | + foreach($rows as $key => $row) |
|
| 2259 | + {
|
|
| 2260 | + $this->updateRangOfLine($row, ($key+1)); |
|
| 2261 | + } |
|
| 2262 | + } |
|
| 2263 | + } |
|
| 2264 | + else |
|
| 2265 | + {
|
|
| 2266 | + dol_print_error($this->db); |
|
| 2267 | + } |
|
| 2268 | + } |
|
| 2269 | + return 1; |
|
| 2270 | + } |
|
| 2271 | + |
|
| 2272 | + /** |
|
| 2273 | + * Get children of line |
|
| 2274 | + * |
|
| 2275 | + * @param int $id Id of parent line |
|
| 2276 | + * @return array Array with list of children lines id |
|
| 2277 | + */ |
|
| 2278 | + function getChildrenOfLine($id) |
|
| 2279 | + {
|
|
| 2280 | + $rows=array(); |
|
| 2281 | + |
|
| 2282 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2283 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2284 | + $sql.= ' AND fk_parent_line = '.$id; |
|
| 2285 | + $sql.= ' ORDER BY rang ASC'; |
|
| 2286 | + |
|
| 2287 | + dol_syslog(get_class($this)."::getChildrenOfLine search children lines for line ".$id."", LOG_DEBUG); |
|
| 2288 | + $resql = $this->db->query($sql); |
|
| 2289 | + if ($resql) |
|
| 2290 | + {
|
|
| 2291 | + $i=0; |
|
| 2292 | + $num = $this->db->num_rows($resql); |
|
| 2293 | + while ($i < $num) |
|
| 2294 | + {
|
|
| 2295 | + $row = $this->db->fetch_row($resql); |
|
| 2296 | + $rows[$i] = $row[0]; |
|
| 2297 | + $i++; |
|
| 2298 | + } |
|
| 2299 | + } |
|
| 2300 | + |
|
| 2301 | + return $rows; |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2305 | + /** |
|
| 2306 | + * Update a line to have a lower rank |
|
| 2307 | + * |
|
| 2308 | + * @param int $rowid Id of line |
|
| 2309 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2310 | + * @return void |
|
| 2311 | + */ |
|
| 2312 | + function line_up($rowid, $fk_parent_line=true) |
|
| 2313 | + {
|
|
| 2314 | + // phpcs:enable |
|
| 2315 | + $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 2316 | + |
|
| 2317 | + // Get rang of line |
|
| 2318 | + $rang = $this->getRangOfLine($rowid); |
|
| 2319 | + |
|
| 2320 | + // Update position of line |
|
| 2321 | + $this->updateLineUp($rowid, $rang); |
|
| 2322 | + } |
|
| 2323 | + |
|
| 2324 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2325 | + /** |
|
| 2326 | + * Update a line to have a higher rank |
|
| 2327 | + * |
|
| 2328 | + * @param int $rowid Id of line |
|
| 2329 | + * @param boolean $fk_parent_line Table with fk_parent_line field or not |
|
| 2330 | + * @return void |
|
| 2331 | + */ |
|
| 2332 | + function line_down($rowid, $fk_parent_line=true) |
|
| 2333 | + {
|
|
| 2334 | + // phpcs:enable |
|
| 2335 | + $this->line_order(false, 'ASC', $fk_parent_line); |
|
| 2336 | + |
|
| 2337 | + // Get rang of line |
|
| 2338 | + $rang = $this->getRangOfLine($rowid); |
|
| 2339 | + |
|
| 2340 | + // Get max value for rang |
|
| 2341 | + $max = $this->line_max(); |
|
| 2342 | + |
|
| 2343 | + // Update position of line |
|
| 2344 | + $this->updateLineDown($rowid, $rang, $max); |
|
| 2345 | + } |
|
| 2346 | + |
|
| 2347 | + /** |
|
| 2348 | + * Update position of line (rang) |
|
| 2349 | + * |
|
| 2350 | + * @param int $rowid Id of line |
|
| 2351 | + * @param int $rang Position |
|
| 2352 | + * @return void |
|
| 2353 | + */ |
|
| 2354 | + function updateRangOfLine($rowid,$rang) |
|
| 2355 | + {
|
|
| 2356 | + $fieldposition = 'rang'; |
|
| 2357 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2358 | + |
|
| 2359 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2360 | + $sql.= ' WHERE rowid = '.$rowid; |
|
| 2361 | + |
|
| 2362 | + dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); |
|
| 2363 | + if (! $this->db->query($sql)) |
|
| 2364 | + {
|
|
| 2365 | + dol_print_error($this->db); |
|
| 2366 | + } |
|
| 2367 | + } |
|
| 2368 | + |
|
| 2369 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2370 | + /** |
|
| 2371 | + * Update position of line with ajax (rang) |
|
| 2372 | + * |
|
| 2373 | + * @param array $rows Array of rows |
|
| 2374 | + * @return void |
|
| 2375 | + */ |
|
| 2376 | + function line_ajaxorder($rows) |
|
| 2377 | + {
|
|
| 2378 | + // phpcs:enable |
|
| 2379 | + $num = count($rows); |
|
| 2380 | + for ($i = 0 ; $i < $num ; $i++) |
|
| 2381 | + {
|
|
| 2382 | + $this->updateRangOfLine($rows[$i], ($i+1)); |
|
| 2383 | + } |
|
| 2384 | + } |
|
| 2385 | + |
|
| 2386 | + /** |
|
| 2387 | + * Update position of line up (rang) |
|
| 2388 | + * |
|
| 2389 | + * @param int $rowid Id of line |
|
| 2390 | + * @param int $rang Position |
|
| 2391 | + * @return void |
|
| 2392 | + */ |
|
| 2393 | + function updateLineUp($rowid,$rang) |
|
| 2394 | + {
|
|
| 2395 | + if ($rang > 1) |
|
| 2396 | + {
|
|
| 2397 | + $fieldposition = 'rang'; |
|
| 2398 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2399 | + |
|
| 2400 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
|
| 2401 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2402 | + $sql.= ' AND rang = '.($rang - 1); |
|
| 2403 | + if ($this->db->query($sql) ) |
|
| 2404 | + {
|
|
| 2405 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang - 1); |
|
| 2406 | + $sql.= ' WHERE rowid = '.$rowid; |
|
| 2407 | + if (! $this->db->query($sql) ) |
|
| 2408 | + {
|
|
| 2409 | + dol_print_error($this->db); |
|
| 2410 | + } |
|
| 2411 | + } |
|
| 2412 | + else |
|
| 2413 | + {
|
|
| 2414 | + dol_print_error($this->db); |
|
| 2415 | + } |
|
| 2416 | + } |
|
| 2417 | + } |
|
| 2418 | + |
|
| 2419 | + /** |
|
| 2420 | + * Update position of line down (rang) |
|
| 2421 | + * |
|
| 2422 | + * @param int $rowid Id of line |
|
| 2423 | + * @param int $rang Position |
|
| 2424 | + * @param int $max Max |
|
| 2425 | + * @return void |
|
| 2426 | + */ |
|
| 2427 | + function updateLineDown($rowid,$rang,$max) |
|
| 2428 | + {
|
|
| 2429 | + if ($rang < $max) |
|
| 2430 | + {
|
|
| 2431 | + $fieldposition = 'rang'; |
|
| 2432 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2433 | + |
|
| 2434 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
|
| 2435 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2436 | + $sql.= ' AND rang = '.($rang+1); |
|
| 2437 | + if ($this->db->query($sql) ) |
|
| 2438 | + {
|
|
| 2439 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.($rang+1); |
|
| 2440 | + $sql.= ' WHERE rowid = '.$rowid; |
|
| 2441 | + if (! $this->db->query($sql) ) |
|
| 2442 | + {
|
|
| 2443 | + dol_print_error($this->db); |
|
| 2444 | + } |
|
| 2445 | + } |
|
| 2446 | + else |
|
| 2447 | + {
|
|
| 2448 | + dol_print_error($this->db); |
|
| 2449 | + } |
|
| 2450 | + } |
|
| 2451 | + } |
|
| 2452 | + |
|
| 2453 | + /** |
|
| 2454 | + * Get position of line (rang) |
|
| 2455 | + * |
|
| 2456 | + * @param int $rowid Id of line |
|
| 2457 | + * @return int Value of rang in table of lines |
|
| 2458 | + */ |
|
| 2459 | + function getRangOfLine($rowid) |
|
| 2460 | + {
|
|
| 2461 | + $sql = 'SELECT rang FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2462 | + $sql.= ' WHERE rowid ='.$rowid; |
|
| 2463 | + |
|
| 2464 | + dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); |
|
| 2465 | + $resql = $this->db->query($sql); |
|
| 2466 | + if ($resql) |
|
| 2467 | + {
|
|
| 2468 | + $row = $this->db->fetch_row($resql); |
|
| 2469 | + return $row[0]; |
|
| 2470 | + } |
|
| 2471 | + } |
|
| 2472 | + |
|
| 2473 | + /** |
|
| 2474 | + * Get rowid of the line relative to its position |
|
| 2475 | + * |
|
| 2476 | + * @param int $rang Rang value |
|
| 2477 | + * @return int Rowid of the line |
|
| 2478 | + */ |
|
| 2479 | + function getIdOfLine($rang) |
|
| 2480 | + {
|
|
| 2481 | + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2482 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2483 | + $sql.= ' AND rang = '.$rang; |
|
| 2484 | + $resql = $this->db->query($sql); |
|
| 2485 | + if ($resql) |
|
| 2486 | + {
|
|
| 2487 | + $row = $this->db->fetch_row($resql); |
|
| 2488 | + return $row[0]; |
|
| 2489 | + } |
|
| 2490 | + } |
|
| 2491 | + |
|
| 2492 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2493 | + /** |
|
| 2494 | + * Get max value used for position of line (rang) |
|
| 2495 | + * |
|
| 2496 | + * @param int $fk_parent_line Parent line id |
|
| 2497 | + * @return int Max value of rang in table of lines |
|
| 2498 | + */ |
|
| 2499 | + function line_max($fk_parent_line=0) |
|
| 2500 | + {
|
|
| 2501 | + // phpcs:enable |
|
| 2502 | + // Search the last rang with fk_parent_line |
|
| 2503 | + if ($fk_parent_line) |
|
| 2504 | + {
|
|
| 2505 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2506 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2507 | + $sql.= ' AND fk_parent_line = '.$fk_parent_line; |
|
| 2508 | + |
|
| 2509 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2510 | + $resql = $this->db->query($sql); |
|
| 2511 | + if ($resql) |
|
| 2512 | + {
|
|
| 2513 | + $row = $this->db->fetch_row($resql); |
|
| 2514 | + if (! empty($row[0])) |
|
| 2515 | + {
|
|
| 2516 | + return $row[0]; |
|
| 2517 | + } |
|
| 2518 | + else |
|
| 2519 | + {
|
|
| 2520 | + return $this->getRangOfLine($fk_parent_line); |
|
| 2521 | + } |
|
| 2522 | + } |
|
| 2523 | + } |
|
| 2524 | + // If not, search the last rang of element |
|
| 2525 | + else |
|
| 2526 | + {
|
|
| 2527 | + $sql = 'SELECT max(rang) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2528 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2529 | + |
|
| 2530 | + dol_syslog(get_class($this)."::line_max", LOG_DEBUG); |
|
| 2531 | + $resql = $this->db->query($sql); |
|
| 2532 | + if ($resql) |
|
| 2533 | + {
|
|
| 2534 | + $row = $this->db->fetch_row($resql); |
|
| 2535 | + return $row[0]; |
|
| 2536 | + } |
|
| 2537 | + } |
|
| 2538 | + } |
|
| 2539 | + |
|
| 2540 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2541 | + /** |
|
| 2542 | + * Update external ref of element |
|
| 2543 | + * |
|
| 2544 | + * @param string $ref_ext Update field ref_ext |
|
| 2545 | + * @return int <0 if KO, >0 if OK |
|
| 2546 | + */ |
|
| 2547 | + function update_ref_ext($ref_ext) |
|
| 2548 | + {
|
|
| 2549 | + // phpcs:enable |
|
| 2550 | + if (! $this->table_element) |
|
| 2551 | + {
|
|
| 2552 | + dol_syslog(get_class($this)."::update_ref_ext was called on objet with property table_element not defined", LOG_ERR); |
|
| 2553 | + return -1; |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2557 | + $sql.= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; |
|
| 2558 | + $sql.= " WHERE ".(isset($this->table_rowid)?$this->table_rowid:'rowid')." = ". $this->id; |
|
| 2559 | + |
|
| 2560 | + dol_syslog(get_class($this)."::update_ref_ext", LOG_DEBUG); |
|
| 2561 | + if ($this->db->query($sql)) |
|
| 2562 | + {
|
|
| 2563 | + $this->ref_ext = $ref_ext; |
|
| 2564 | + return 1; |
|
| 2565 | + } |
|
| 2566 | + else |
|
| 2567 | + {
|
|
| 2568 | + $this->error=$this->db->error(); |
|
| 2569 | + return -1; |
|
| 2570 | + } |
|
| 2571 | + } |
|
| 2572 | + |
|
| 2573 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2574 | + /** |
|
| 2575 | + * Update note of element |
|
| 2576 | + * |
|
| 2577 | + * @param string $note New value for note |
|
| 2578 | + * @param string $suffix '', '_public' or '_private' |
|
| 2579 | + * @return int <0 if KO, >0 if OK |
|
| 2580 | + */ |
|
| 2581 | + function update_note($note, $suffix='') |
|
| 2582 | + {
|
|
| 2583 | + // phpcs:enable |
|
| 2584 | + global $user; |
|
| 2585 | + |
|
| 2586 | + if (! $this->table_element) |
|
| 2587 | + {
|
|
| 2588 | + $this->error='update_note was called on objet with property table_element not defined'; |
|
| 2589 | + dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); |
|
| 2590 | + return -1; |
|
| 2591 | + } |
|
| 2592 | + if (! in_array($suffix,array('','_public','_private')))
|
|
| 2593 | + {
|
|
| 2594 | + $this->error='update_note Parameter suffix must be empty, \'_private\' or \'_public\''; |
|
| 2595 | + dol_syslog(get_class($this)."::update_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR); |
|
| 2596 | + return -2; |
|
| 2597 | + } |
|
| 2598 | + // Special cas |
|
| 2599 | + //var_dump($this->table_element);exit; |
|
| 2600 | + if ($this->table_element == 'product') $suffix=''; |
|
| 2601 | + |
|
| 2602 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
|
| 2603 | + $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
|
| 2604 | + $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id;
|
|
| 2605 | + $sql.= " WHERE rowid =". $this->id; |
|
| 2606 | + |
|
| 2607 | + dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
|
| 2608 | + if ($this->db->query($sql)) |
|
| 2609 | + {
|
|
| 2610 | + if ($suffix == '_public') $this->note_public = $note; |
|
| 2611 | + else if ($suffix == '_private') $this->note_private = $note; |
|
| 2612 | + else |
|
| 2613 | + {
|
|
| 2614 | + $this->note = $note; // deprecated |
|
| 2615 | + $this->note_private = $note; |
|
| 2616 | + } |
|
| 2617 | + return 1; |
|
| 2618 | + } |
|
| 2619 | + else |
|
| 2620 | + {
|
|
| 2621 | + $this->error=$this->db->lasterror(); |
|
| 2622 | + return -1; |
|
| 2623 | + } |
|
| 2624 | + } |
|
| 2625 | + |
|
| 2626 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2627 | + /** |
|
| 2628 | + * Update public note (kept for backward compatibility) |
|
| 2629 | + * |
|
| 2630 | + * @param string $note New value for note |
|
| 2631 | + * @return int <0 if KO, >0 if OK |
|
| 2632 | + * @deprecated |
|
| 2633 | + * @see update_note() |
|
| 2634 | + */ |
|
| 2635 | + function update_note_public($note) |
|
| 2636 | + {
|
|
| 2637 | + // phpcs:enable |
|
| 2638 | + return $this->update_note($note,'_public'); |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2642 | + /** |
|
| 2643 | + * Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines). |
|
| 2644 | + * Must be called at end of methods addline or updateline. |
|
| 2645 | + * |
|
| 2646 | + * @param int $exclspec >0 = Exclude special product (product_type=9) |
|
| 2647 | + * @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 |
|
| 2648 | + * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. |
|
| 2649 | + * @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. |
|
| 2650 | + * @return int <0 if KO, >0 if OK |
|
| 2651 | + */ |
|
| 2652 | + function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) |
|
| 2653 | + {
|
|
| 2654 | + // phpcs:enable |
|
| 2655 | + global $conf, $hookmanager, $action; |
|
| 2656 | + |
|
| 2657 | + // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
|
| 2658 | + $MODULE = ""; |
|
| 2659 | + if ($this->element == 'propal') |
|
| 2660 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2661 | + elseif ($this->element == 'order') |
|
| 2662 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2663 | + elseif ($this->element == 'facture') |
|
| 2664 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2665 | + elseif ($this->element == 'facture_fourn') |
|
| 2666 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2667 | + elseif ($this->element == 'order_supplier') |
|
| 2668 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2669 | + elseif ($this->element == 'supplier_proposal') |
|
| 2670 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2671 | + |
|
| 2672 | + if (! empty($MODULE)) {
|
|
| 2673 | + if (!empty(Globals::$conf->global->$MODULE)) {
|
|
| 2674 | + $modsactivated = explode(',', Globals::$conf->global->$MODULE);
|
|
| 2675 | + foreach ($modsactivated as $mod) {
|
|
| 2676 | + if (Globals::$conf->$mod->enabled) |
|
| 2677 | + return 1; // update was disabled by specific setup |
|
| 2678 | + } |
|
| 2679 | + } |
|
| 2680 | + } |
|
| 2681 | + |
|
| 2682 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
|
| 2683 | + |
|
| 2684 | + if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2685 | + |
|
| 2686 | + $forcedroundingmode=$roundingadjust; |
|
| 2687 | + if ($forcedroundingmode == 'auto' && isset(Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) |
|
| 2688 | + $forcedroundingmode = Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2689 | + elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2690 | + |
|
| 2691 | + $error=0; |
|
| 2692 | + |
|
| 2693 | + $multicurrency_tx = !empty($this->multicurrency_tx) ? $this->multicurrency_tx : 1; |
|
| 2694 | + |
|
| 2695 | + // Define constants to find lines to sum |
|
| 2696 | + $fieldtva='total_tva'; |
|
| 2697 | + $fieldlocaltax1='total_localtax1'; |
|
| 2698 | + $fieldlocaltax2='total_localtax2'; |
|
| 2699 | + $fieldup='subprice'; |
|
| 2700 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') |
|
| 2701 | + {
|
|
| 2702 | + $fieldtva='tva'; |
|
| 2703 | + $fieldup='pu_ht'; |
|
| 2704 | + } |
|
| 2705 | + if ($this->element == 'expensereport') |
|
| 2706 | + {
|
|
| 2707 | + $fieldup='value_unit'; |
|
| 2708 | + } |
|
| 2709 | + |
|
| 2710 | + $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,'; |
|
| 2711 | + $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
|
| 2712 | + if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2713 | + $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
|
| 2714 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 2715 | + $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 2716 | + if ($exclspec) |
|
| 2717 | + {
|
|
| 2718 | + $product_field='product_type'; |
|
| 2719 | + if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2720 | + if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2721 | + } |
|
| 2722 | + $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 |
|
| 2723 | + |
|
| 2724 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2725 | + $resql = $this->db->query($sql); |
|
| 2726 | + if ($resql) |
|
| 2727 | + {
|
|
| 2728 | + $this->total_ht = 0; |
|
| 2729 | + $this->total_tva = 0; |
|
| 2730 | + $this->total_localtax1 = 0; |
|
| 2731 | + $this->total_localtax2 = 0; |
|
| 2732 | + $this->total_ttc = 0; |
|
| 2733 | + $total_ht_by_vats = array(); |
|
| 2734 | + $total_tva_by_vats = array(); |
|
| 2735 | + $total_ttc_by_vats = array(); |
|
| 2736 | + $this->multicurrency_total_ht = 0; |
|
| 2737 | + $this->multicurrency_total_tva = 0; |
|
| 2738 | + $this->multicurrency_total_ttc = 0; |
|
| 2739 | + |
|
| 2740 | + $num = $this->db->num_rows($resql); |
|
| 2741 | + $i = 0; |
|
| 2742 | + while ($i < $num) |
|
| 2743 | + {
|
|
| 2744 | + $obj = $this->db->fetch_object($resql); |
|
| 2745 | + |
|
| 2746 | + // Note: There is no check on detail line and no check on total, if $forcedroundingmode = 'none' |
|
| 2747 | + $parameters=array('fk_element' => $obj->rowid);
|
|
| 2748 | + $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 2749 | + |
|
| 2750 | + 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' |
|
| 2751 | + {
|
|
| 2752 | + $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2753 | + $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); |
|
| 2754 | + $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
|
| 2755 | + if ($diff) |
|
| 2756 | + {
|
|
| 2757 | + $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
|
| 2758 | + 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);
|
|
| 2759 | + $resqlfix=$this->db->query($sqlfix); |
|
| 2760 | + if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2761 | + $obj->total_tva = $tmpcal[1]; |
|
| 2762 | + $obj->total_ttc = $tmpcal[2]; |
|
| 2763 | + // |
|
| 2764 | + } |
|
| 2765 | + } |
|
| 2766 | + |
|
| 2767 | + $this->total_ht += $obj->total_ht; // The field visible at end of line detail |
|
| 2768 | + $this->total_tva += $obj->total_tva; |
|
| 2769 | + $this->total_localtax1 += $obj->total_localtax1; |
|
| 2770 | + $this->total_localtax2 += $obj->total_localtax2; |
|
| 2771 | + $this->total_ttc += $obj->total_ttc; |
|
| 2772 | + $this->multicurrency_total_ht += $obj->multicurrency_total_ht; // The field visible at end of line detail |
|
| 2773 | + $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
|
| 2774 | + $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
|
| 2775 | + |
|
| 2776 | + if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2777 | + if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2778 | + if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 2779 | + $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
|
| 2780 | + $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
|
| 2781 | + $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
|
| 2782 | + |
|
| 2783 | + if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2784 | + {
|
|
| 2785 | + $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 2786 | + $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
|
| 2787 | + //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"; |
|
| 2788 | + if ($diff) |
|
| 2789 | + {
|
|
| 2790 | + if (abs($diff) > 0.1) { dol_syslog('A rounding difference was detected into TOTAL but is too high to be corrected', LOG_WARNING); exit; }
|
|
| 2791 | + $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; |
|
| 2792 | + 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);
|
|
| 2793 | + $resqlfix=$this->db->query($sqlfix); |
|
| 2794 | + if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2795 | + $this->total_tva -= $diff; |
|
| 2796 | + $this->total_ttc -= $diff; |
|
| 2797 | + $total_tva_by_vats[$obj->vatrate] -= $diff; |
|
| 2798 | + $total_ttc_by_vats[$obj->vatrate] -= $diff; |
|
| 2799 | + } |
|
| 2800 | + } |
|
| 2801 | + |
|
| 2802 | + $i++; |
|
| 2803 | + } |
|
| 2804 | + |
|
| 2805 | + // Add revenue stamp to total |
|
| 2806 | + $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; |
|
| 2807 | + $this->multicurrency_total_ttc += isset($this->revenuestamp)?($this->revenuestamp * $multicurrency_tx):0; |
|
| 2808 | + |
|
| 2809 | + // Situations totals |
|
| 2810 | + if ($this->situation_cycle_ref && $this->situation_counter > 1 && method_exists($this, 'get_prev_sits') && $this->type != $this::TYPE_CREDIT_NOTE ) |
|
| 2811 | + {
|
|
| 2812 | + $prev_sits = $this->get_prev_sits(); |
|
| 2813 | + |
|
| 2814 | + foreach ($prev_sits as $sit) { // $sit is an object Facture loaded with a fetch.
|
|
| 2815 | + $this->total_ht -= $sit->total_ht; |
|
| 2816 | + $this->total_tva -= $sit->total_tva; |
|
| 2817 | + $this->total_localtax1 -= $sit->total_localtax1; |
|
| 2818 | + $this->total_localtax2 -= $sit->total_localtax2; |
|
| 2819 | + $this->total_ttc -= $sit->total_ttc; |
|
| 2820 | + $this->multicurrency_total_ht -= $sit->multicurrency_total_ht; |
|
| 2821 | + $this->multicurrency_total_tva -= $sit->multicurrency_total_tva; |
|
| 2822 | + $this->multicurrency_total_ttc -= $sit->multicurrency_total_ttc; |
|
| 2823 | + } |
|
| 2824 | + } |
|
| 2825 | + |
|
| 2826 | + $this->db->free($resql); |
|
| 2827 | + |
|
| 2828 | + // Now update global field total_ht, total_ttc and tva |
|
| 2829 | + $fieldht='total_ht'; |
|
| 2830 | + $fieldtva='tva'; |
|
| 2831 | + $fieldlocaltax1='localtax1'; |
|
| 2832 | + $fieldlocaltax2='localtax2'; |
|
| 2833 | + $fieldttc='total_ttc'; |
|
| 2834 | + // Specific code for backward compatibility with old field names |
|
| 2835 | + if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2836 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2837 | + if ($this->element == 'propal') $fieldttc='total'; |
|
| 2838 | + if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2839 | + if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 2840 | + |
|
| 2841 | + if (empty($nodatabaseupdate)) |
|
| 2842 | + {
|
|
| 2843 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; |
|
| 2844 | + $sql .= " ".$fieldht."='".price2num($this->total_ht)."',"; |
|
| 2845 | + $sql .= " ".$fieldtva."='".price2num($this->total_tva)."',"; |
|
| 2846 | + $sql .= " ".$fieldlocaltax1."='".price2num($this->total_localtax1)."',"; |
|
| 2847 | + $sql .= " ".$fieldlocaltax2."='".price2num($this->total_localtax2)."',"; |
|
| 2848 | + $sql .= " ".$fieldttc."='".price2num($this->total_ttc)."'"; |
|
| 2849 | + $sql .= ", multicurrency_total_ht='".price2num($this->multicurrency_total_ht, 'MT', 1)."'"; |
|
| 2850 | + $sql .= ", multicurrency_total_tva='".price2num($this->multicurrency_total_tva, 'MT', 1)."'"; |
|
| 2851 | + $sql .= ", multicurrency_total_ttc='".price2num($this->multicurrency_total_ttc, 'MT', 1)."'"; |
|
| 2852 | + $sql .= ' WHERE rowid = '.$this->id; |
|
| 2853 | + |
|
| 2854 | + |
|
| 2855 | + dol_syslog(get_class($this)."::update_price", LOG_DEBUG); |
|
| 2856 | + $resql=$this->db->query($sql); |
|
| 2857 | + if (! $resql) |
|
| 2858 | + {
|
|
| 2859 | + $error++; |
|
| 2860 | + $this->error=$this->db->lasterror(); |
|
| 2861 | + $this->errors[]=$this->db->lasterror(); |
|
| 2862 | + } |
|
| 2863 | + } |
|
| 2864 | + |
|
| 2865 | + if (! $error) |
|
| 2866 | + {
|
|
| 2867 | + return 1; |
|
| 2868 | + } |
|
| 2869 | + else |
|
| 2870 | + {
|
|
| 2871 | + return -1; |
|
| 2872 | + } |
|
| 2873 | + } |
|
| 2874 | + else |
|
| 2875 | + {
|
|
| 2876 | + dol_print_error($this->db,'Bad request in update_price'); |
|
| 2877 | + return -1; |
|
| 2878 | + } |
|
| 2879 | + } |
|
| 2880 | + |
|
| 2881 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 2882 | + /** |
|
| 2883 | + * Add objects linked in llx_element_element. |
|
| 2884 | + * |
|
| 2885 | + * @param string $origin Linked element type |
|
| 2886 | + * @param int $origin_id Linked element id |
|
| 2887 | + * @return int <=0 if KO, >0 if OK |
|
| 2888 | + * @see fetchObjectLinked, updateObjectLinked, deleteObjectLinked |
|
| 2889 | + */ |
|
| 2890 | + function add_object_linked($origin=null, $origin_id=null) |
|
| 2891 | + {
|
|
| 2892 | + // phpcs:enable |
|
| 2893 | + $origin = (! empty($origin) ? $origin : $this->origin); |
|
| 2894 | + $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
|
| 2895 | + |
|
| 2896 | + // Special case |
|
| 2897 | + if ($origin == 'order') $origin='commande'; |
|
| 2898 | + if ($origin == 'invoice') $origin='facture'; |
|
| 2899 | + if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2900 | + if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 2901 | + $this->db->begin(); |
|
| 2902 | + |
|
| 2903 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
|
| 2904 | + $sql.= "fk_source"; |
|
| 2905 | + $sql.= ", sourcetype"; |
|
| 2906 | + $sql.= ", fk_target"; |
|
| 2907 | + $sql.= ", targettype"; |
|
| 2908 | + $sql.= ") VALUES (";
|
|
| 2909 | + $sql.= $origin_id; |
|
| 2910 | + $sql.= ", '".$this->db->escape($origin)."'"; |
|
| 2911 | + $sql.= ", ".$this->id; |
|
| 2912 | + $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 2913 | + $sql.= ")"; |
|
| 2914 | + |
|
| 2915 | + dol_syslog(get_class($this)."::add_object_linked", LOG_DEBUG); |
|
| 2916 | + if ($this->db->query($sql)) |
|
| 2917 | + {
|
|
| 2918 | + $this->db->commit(); |
|
| 2919 | + return 1; |
|
| 2920 | + } |
|
| 2921 | + else |
|
| 2922 | + {
|
|
| 2923 | + $this->error=$this->db->lasterror(); |
|
| 2924 | + $this->db->rollback(); |
|
| 2925 | + return 0; |
|
| 2926 | + } |
|
| 2927 | + } |
|
| 2928 | + |
|
| 2929 | + /** |
|
| 2930 | + * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into |
|
| 2931 | + * this->linkedObjectsIds array and |
|
| 2932 | + * this->linkedObjects array if $loadalsoobjects = 1 |
|
| 2933 | + * Possible usage for parameters: |
|
| 2934 | + * - all parameters empty -> we look all link to current object (current object can be source or target) |
|
| 2935 | + * - source id+type -> will get target list linked to source |
|
| 2936 | + * - target id+type -> will get source list linked to target |
|
| 2937 | + * - source id+type + target type -> will get target list of the type |
|
| 2938 | + * - target id+type + target source -> will get source list of the type |
|
| 2939 | + * |
|
| 2940 | + * @param int $sourceid Object source id (if not defined, id of object) |
|
| 2941 | + * @param string $sourcetype Object source type (if not defined, element name of object) |
|
| 2942 | + * @param int $targetid Object target id (if not defined, id of object) |
|
| 2943 | + * @param string $targettype Object target type (if not defined, elemennt name of object) |
|
| 2944 | + * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided |
|
| 2945 | + * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. |
|
| 2946 | + * @param string $orderby SQL 'ORDER BY' clause |
|
| 2947 | + * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) |
|
| 2948 | + * @return int <0 if KO, >0 if OK |
|
| 2949 | + * @see add_object_linked, updateObjectLinked, deleteObjectLinked |
|
| 2950 | + */ |
|
| 2951 | + function fetchObjectLinked($sourceid=null,$sourcetype='',$targetid=null,$targettype='',$clause='OR',$alsosametype=1,$orderby='sourcetype',$loadalsoobjects=1) |
|
| 2952 | + {
|
|
| 2953 | + global $conf; |
|
| 2954 | + |
|
| 2955 | + $this->linkedObjectsIds=array(); |
|
| 2956 | + $this->linkedObjects=array(); |
|
| 2957 | + |
|
| 2958 | + $justsource=false; |
|
| 2959 | + $justtarget=false; |
|
| 2960 | + $withtargettype=false; |
|
| 2961 | + $withsourcetype=false; |
|
| 2962 | + |
|
| 2963 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
|
| 2964 | + {
|
|
| 2965 | + $justsource=true; // the source (id and type) is a search criteria |
|
| 2966 | + if (! empty($targettype)) $withtargettype=true; |
|
| 2967 | + } |
|
| 2968 | + if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
|
| 2969 | + {
|
|
| 2970 | + $justtarget=true; // the target (id and type) is a search criteria |
|
| 2971 | + if (! empty($sourcetype)) $withsourcetype=true; |
|
| 2972 | + } |
|
| 2973 | + |
|
| 2974 | + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 2975 | + $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 2976 | + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 2977 | + $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 2978 | + |
|
| 2979 | + /*if (empty($sourceid) && empty($targetid)) |
|
| 2980 | + {
|
|
| 2981 | + dol_syslog('Bad usage of function. No source nor target id defined (nor as parameter nor as object id)', LOG_ERR);
|
|
| 2982 | + return -1; |
|
| 2983 | + }*/ |
|
| 2984 | + |
|
| 2985 | + // Links between objects are stored in table element_element |
|
| 2986 | + $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; |
|
| 2987 | + $sql.= ' FROM '.MAIN_DB_PREFIX.'element_element'; |
|
| 2988 | + $sql.= " WHERE "; |
|
| 2989 | + if ($justsource || $justtarget) |
|
| 2990 | + {
|
|
| 2991 | + if ($justsource) |
|
| 2992 | + {
|
|
| 2993 | + $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
|
| 2994 | + if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2995 | + } |
|
| 2996 | + else if ($justtarget) |
|
| 2997 | + {
|
|
| 2998 | + $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
|
| 2999 | + if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3000 | + } |
|
| 3001 | + } |
|
| 3002 | + else |
|
| 3003 | + {
|
|
| 3004 | + $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
|
| 3005 | + $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
|
| 3006 | + } |
|
| 3007 | + $sql .= ' ORDER BY '.$orderby; |
|
| 3008 | + |
|
| 3009 | + dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); |
|
| 3010 | + $resql = $this->db->query($sql); |
|
| 3011 | + if ($resql) |
|
| 3012 | + {
|
|
| 3013 | + $num = $this->db->num_rows($resql); |
|
| 3014 | + $i = 0; |
|
| 3015 | + while ($i < $num) |
|
| 3016 | + {
|
|
| 3017 | + $obj = $this->db->fetch_object($resql); |
|
| 3018 | + if ($justsource || $justtarget) |
|
| 3019 | + {
|
|
| 3020 | + if ($justsource) |
|
| 3021 | + {
|
|
| 3022 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3023 | + } |
|
| 3024 | + else if ($justtarget) |
|
| 3025 | + {
|
|
| 3026 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3027 | + } |
|
| 3028 | + } |
|
| 3029 | + else |
|
| 3030 | + {
|
|
| 3031 | + if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
|
| 3032 | + {
|
|
| 3033 | + $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
|
| 3034 | + } |
|
| 3035 | + if ($obj->fk_target == $targetid && $obj->targettype == $targettype) |
|
| 3036 | + {
|
|
| 3037 | + $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
|
| 3038 | + } |
|
| 3039 | + } |
|
| 3040 | + $i++; |
|
| 3041 | + } |
|
| 3042 | + |
|
| 3043 | + if (! empty($this->linkedObjectsIds)) |
|
| 3044 | + {
|
|
| 3045 | + $tmparray = $this->linkedObjectsIds; |
|
| 3046 | + foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3047 | + {
|
|
| 3048 | + // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
|
| 3049 | + $module = $element = $subelement = $objecttype; |
|
| 3050 | + if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
|
| 3051 | + && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
|
| 3052 | + {
|
|
| 3053 | + $module = $element = $regs[1]; |
|
| 3054 | + $subelement = $regs[2]; |
|
| 3055 | + } |
|
| 3056 | + |
|
| 3057 | + $classpath = $element.'/class'; |
|
| 3058 | + // To work with non standard classpath or module name |
|
| 3059 | + if ($objecttype == 'facture') {
|
|
| 3060 | + $classpath = 'compta/facture/class'; |
|
| 3061 | + } |
|
| 3062 | + else if ($objecttype == 'facturerec') {
|
|
| 3063 | + $classpath = 'compta/facture/class'; $module = 'facture'; |
|
| 3064 | + } |
|
| 3065 | + else if ($objecttype == 'propal') {
|
|
| 3066 | + $classpath = 'comm/propal/class'; |
|
| 3067 | + } |
|
| 3068 | + else if ($objecttype == 'supplier_proposal') {
|
|
| 3069 | + $classpath = 'supplier_proposal/class'; |
|
| 3070 | + } |
|
| 3071 | + else if ($objecttype == 'shipping') {
|
|
| 3072 | + $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
|
| 3073 | + } |
|
| 3074 | + else if ($objecttype == 'delivery') {
|
|
| 3075 | + $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
|
| 3076 | + } |
|
| 3077 | + else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3078 | + $classpath = 'fourn/class'; $module = 'fournisseur'; |
|
| 3079 | + } |
|
| 3080 | + else if ($objecttype == 'fichinter') {
|
|
| 3081 | + $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
|
| 3082 | + } |
|
| 3083 | + else if ($objecttype == 'subscription') {
|
|
| 3084 | + $classpath = 'adherents/class'; $module = 'adherent'; |
|
| 3085 | + } |
|
| 3086 | + |
|
| 3087 | + // Set classfile |
|
| 3088 | + $classfile = strtolower($subelement); $classname = ucfirst($subelement); |
|
| 3089 | + |
|
| 3090 | + if ($objecttype == 'order') {
|
|
| 3091 | + $classfile = 'commande'; $classname = 'Commande'; |
|
| 3092 | + } |
|
| 3093 | + else if ($objecttype == 'invoice_supplier') {
|
|
| 3094 | + $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
|
| 3095 | + } |
|
| 3096 | + else if ($objecttype == 'order_supplier') {
|
|
| 3097 | + $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
|
| 3098 | + } |
|
| 3099 | + else if ($objecttype == 'supplier_proposal') {
|
|
| 3100 | + $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
|
| 3101 | + } |
|
| 3102 | + else if ($objecttype == 'facturerec') {
|
|
| 3103 | + $classfile = 'facture-rec'; $classname = 'FactureRec'; |
|
| 3104 | + } |
|
| 3105 | + else if ($objecttype == 'subscription') {
|
|
| 3106 | + $classfile = 'subscription'; $classname = 'Subscription'; |
|
| 3107 | + } |
|
| 3108 | + |
|
| 3109 | + // Here $module, $classfile and $classname are set |
|
| 3110 | + if (Globals::$conf->$module->enabled && (($element != $this->element) || $alsosametype)) {
|
|
| 3111 | + if ($loadalsoobjects) |
|
| 3112 | + {
|
|
| 3113 | + dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
|
|
| 3114 | + //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
|
| 3115 | + if (class_exists($classname)) |
|
| 3116 | + {
|
|
| 3117 | + foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3118 | + {
|
|
| 3119 | + $object = new $classname($this->db); |
|
| 3120 | + $ret = $object->fetch($objectid); |
|
| 3121 | + if ($ret >= 0) |
|
| 3122 | + {
|
|
| 3123 | + $this->linkedObjects[$objecttype][$i] = $object; |
|
| 3124 | + } |
|
| 3125 | + } |
|
| 3126 | + } |
|
| 3127 | + } |
|
| 3128 | + } |
|
| 3129 | + else |
|
| 3130 | + {
|
|
| 3131 | + unset($this->linkedObjectsIds[$objecttype]); |
|
| 3132 | + } |
|
| 3133 | + } |
|
| 3134 | + } |
|
| 3135 | + return 1; |
|
| 3136 | + } |
|
| 3137 | + else |
|
| 3138 | + {
|
|
| 3139 | + dol_print_error($this->db); |
|
| 3140 | + return -1; |
|
| 3141 | + } |
|
| 3142 | + } |
|
| 3143 | + |
|
| 3144 | + /** |
|
| 3145 | + * Update object linked of a current object |
|
| 3146 | + * |
|
| 3147 | + * @param int $sourceid Object source id |
|
| 3148 | + * @param string $sourcetype Object source type |
|
| 3149 | + * @param int $targetid Object target id |
|
| 3150 | + * @param string $targettype Object target type |
|
| 3151 | + * @return int >0 if OK, <0 if KO |
|
| 3152 | + * @see add_object_linked, fetObjectLinked, deleteObjectLinked |
|
| 3153 | + */ |
|
| 3154 | + function updateObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='') |
|
| 3155 | + {
|
|
| 3156 | + $updatesource=false; |
|
| 3157 | + $updatetarget=false; |
|
| 3158 | + |
|
| 3159 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3160 | + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3161 | + |
|
| 3162 | + $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
|
| 3163 | + if ($updatesource) |
|
| 3164 | + {
|
|
| 3165 | + $sql.= "fk_source = ".$sourceid; |
|
| 3166 | + $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3167 | + $sql.= " WHERE fk_target = ".$this->id; |
|
| 3168 | + $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3169 | + } |
|
| 3170 | + else if ($updatetarget) |
|
| 3171 | + {
|
|
| 3172 | + $sql.= "fk_target = ".$targetid; |
|
| 3173 | + $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
|
| 3174 | + $sql.= " WHERE fk_source = ".$this->id; |
|
| 3175 | + $sql.= " AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3176 | + } |
|
| 3177 | + |
|
| 3178 | + dol_syslog(get_class($this)."::updateObjectLinked", LOG_DEBUG); |
|
| 3179 | + if ($this->db->query($sql)) |
|
| 3180 | + {
|
|
| 3181 | + return 1; |
|
| 3182 | + } |
|
| 3183 | + else |
|
| 3184 | + {
|
|
| 3185 | + $this->error=$this->db->lasterror(); |
|
| 3186 | + return -1; |
|
| 3187 | + } |
|
| 3188 | + } |
|
| 3189 | + |
|
| 3190 | + /** |
|
| 3191 | + * Delete all links between an object $this |
|
| 3192 | + * |
|
| 3193 | + * @param int $sourceid Object source id |
|
| 3194 | + * @param string $sourcetype Object source type |
|
| 3195 | + * @param int $targetid Object target id |
|
| 3196 | + * @param string $targettype Object target type |
|
| 3197 | + * @param int $rowid Row id of line to delete. If defined, other parameters are not used. |
|
| 3198 | + * @return int >0 if OK, <0 if KO |
|
| 3199 | + * @see add_object_linked, updateObjectLinked, fetchObjectLinked |
|
| 3200 | + */ |
|
| 3201 | + function deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='') |
|
| 3202 | + {
|
|
| 3203 | + $deletesource=false; |
|
| 3204 | + $deletetarget=false; |
|
| 3205 | + |
|
| 3206 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3207 | + else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3208 | + |
|
| 3209 | + $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
|
| 3210 | + $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
|
| 3211 | + $targetid = (! empty($targetid) ? $targetid : $this->id); |
|
| 3212 | + $targettype = (! empty($targettype) ? $targettype : $this->element); |
|
| 3213 | + |
|
| 3214 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_element"; |
|
| 3215 | + $sql.= " WHERE"; |
|
| 3216 | + if ($rowid > 0) |
|
| 3217 | + {
|
|
| 3218 | + $sql.=" rowid = ".$rowid; |
|
| 3219 | + } |
|
| 3220 | + else |
|
| 3221 | + {
|
|
| 3222 | + if ($deletesource) |
|
| 3223 | + {
|
|
| 3224 | + $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
|
| 3225 | + $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
|
| 3226 | + } |
|
| 3227 | + else if ($deletetarget) |
|
| 3228 | + {
|
|
| 3229 | + $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
|
| 3230 | + $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
|
| 3231 | + } |
|
| 3232 | + else |
|
| 3233 | + {
|
|
| 3234 | + $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
|
| 3235 | + $sql.= " OR"; |
|
| 3236 | + $sql.= " (fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."')"; |
|
| 3237 | + } |
|
| 3238 | + } |
|
| 3239 | + |
|
| 3240 | + dol_syslog(get_class($this)."::deleteObjectLinked", LOG_DEBUG); |
|
| 3241 | + if ($this->db->query($sql)) |
|
| 3242 | + {
|
|
| 3243 | + return 1; |
|
| 3244 | + } |
|
| 3245 | + else |
|
| 3246 | + {
|
|
| 3247 | + $this->error=$this->db->lasterror(); |
|
| 3248 | + $this->errors[]=$this->error; |
|
| 3249 | + return -1; |
|
| 3250 | + } |
|
| 3251 | + } |
|
| 3252 | + |
|
| 3253 | + /** |
|
| 3254 | + * Set status of an object |
|
| 3255 | + * |
|
| 3256 | + * @param int $status Status to set |
|
| 3257 | + * @param int $elementId Id of element to force (use this->id by default) |
|
| 3258 | + * @param string $elementType Type of element to force (use this->table_element by default) |
|
| 3259 | + * @param string $trigkey Trigger key to use for trigger |
|
| 3260 | + * @return int <0 if KO, >0 if OK |
|
| 3261 | + */ |
|
| 3262 | + function setStatut($status, $elementId=null, $elementType='', $trigkey='') |
|
| 3263 | + {
|
|
| 3264 | + global $user,$langs,$conf; |
|
| 3265 | + |
|
| 3266 | + $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. |
|
| 3267 | + |
|
| 3268 | + $elementId = (!empty($elementId)?$elementId:$this->id); |
|
| 3269 | + $elementTable = (!empty($elementType)?$elementType:$this->table_element); |
|
| 3270 | + |
|
| 3271 | + $this->db->begin(); |
|
| 3272 | + |
|
| 3273 | + $fieldstatus="fk_statut"; |
|
| 3274 | + if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3275 | + if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3276 | + if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3277 | + if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3278 | + if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3279 | + if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3280 | + |
|
| 3281 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
|
| 3282 | + $sql.= " SET ".$fieldstatus." = ".$status; |
|
| 3283 | + // If status = 1 = validated, update also fk_user_valid |
|
| 3284 | + if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3285 | + $sql.= " WHERE rowid=".$elementId; |
|
| 3286 | + |
|
| 3287 | + dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
|
| 3288 | + if ($this->db->query($sql)) |
|
| 3289 | + {
|
|
| 3290 | + $error = 0; |
|
| 3291 | + |
|
| 3292 | + // Try autoset of trigkey |
|
| 3293 | + if (empty($trigkey)) |
|
| 3294 | + {
|
|
| 3295 | + if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3296 | + if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3297 | + if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3298 | + if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3299 | + if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3300 | + if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3301 | + } |
|
| 3302 | + |
|
| 3303 | + if ($trigkey) |
|
| 3304 | + {
|
|
| 3305 | + // Appel des triggers |
|
| 3306 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 3307 | + $interface=new Interfaces($this->db); |
|
| 3308 | + $result=$interface->run_triggers($trigkey,$this,$user,$langs,$conf); |
|
| 3309 | + if ($result < 0) {
|
|
| 3310 | + $error++; $this->errors=$interface->errors; |
|
| 3311 | + } |
|
| 3312 | + // Fin appel triggers |
|
| 3313 | + } |
|
| 3314 | + |
|
| 3315 | + if (! $error) |
|
| 3316 | + {
|
|
| 3317 | + $this->db->commit(); |
|
| 3318 | + |
|
| 3319 | + if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3320 | + {
|
|
| 3321 | + $this->statut = $status; |
|
| 3322 | + $this->status = $status; |
|
| 3323 | + } |
|
| 3324 | + |
|
| 3325 | + return 1; |
|
| 3326 | + } |
|
| 3327 | + else |
|
| 3328 | + {
|
|
| 3329 | + $this->db->rollback(); |
|
| 3330 | + dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
|
| 3331 | + return -1; |
|
| 3332 | + } |
|
| 3333 | + } |
|
| 3334 | + else |
|
| 3335 | + {
|
|
| 3336 | + $this->error=$this->db->lasterror(); |
|
| 3337 | + $this->db->rollback(); |
|
| 3338 | + return -1; |
|
| 3339 | + } |
|
| 3340 | + } |
|
| 3341 | + |
|
| 3342 | + |
|
| 3343 | + /** |
|
| 3344 | + * Load type of canvas of an object if it exists |
|
| 3345 | + * |
|
| 3346 | + * @param int $id Record id |
|
| 3347 | + * @param string $ref Record ref |
|
| 3348 | + * @return int <0 if KO, 0 if nothing done, >0 if OK |
|
| 3349 | + */ |
|
| 3350 | + function getCanvas($id=0,$ref='') |
|
| 3351 | + {
|
|
| 3352 | + global $conf; |
|
| 3353 | + |
|
| 3354 | + if (empty($id) && empty($ref)) return 0; |
|
| 3355 | + if (!empty(Globals::$conf->global->MAIN_DISABLE_CANVAS)) |
|
| 3356 | + return 0; // To increase speed. Not enabled by default. |
|
| 3357 | + |
|
| 3358 | + // Clean parameters |
|
| 3359 | + $ref = trim($ref); |
|
| 3360 | + |
|
| 3361 | + $sql = "SELECT rowid, canvas"; |
|
| 3362 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3363 | + $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
|
| 3364 | + if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3365 | + if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3366 | + |
|
| 3367 | + $resql = $this->db->query($sql); |
|
| 3368 | + if ($resql) |
|
| 3369 | + {
|
|
| 3370 | + $obj = $this->db->fetch_object($resql); |
|
| 3371 | + if ($obj) |
|
| 3372 | + {
|
|
| 3373 | + $this->canvas = $obj->canvas; |
|
| 3374 | + return 1; |
|
| 3375 | + } |
|
| 3376 | + else return 0; |
|
| 3377 | + } |
|
| 3378 | + else |
|
| 3379 | + {
|
|
| 3380 | + dol_print_error($this->db); |
|
| 3381 | + return -1; |
|
| 3382 | + } |
|
| 3383 | + } |
|
| 3384 | + |
|
| 3385 | + |
|
| 3386 | + /** |
|
| 3387 | + * Get special code of a line |
|
| 3388 | + * |
|
| 3389 | + * @param int $lineid Id of line |
|
| 3390 | + * @return int Special code |
|
| 3391 | + */ |
|
| 3392 | + function getSpecialCode($lineid) |
|
| 3393 | + {
|
|
| 3394 | + $sql = 'SELECT special_code FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
|
| 3395 | + $sql.= ' WHERE rowid = '.$lineid; |
|
| 3396 | + $resql = $this->db->query($sql); |
|
| 3397 | + if ($resql) |
|
| 3398 | + {
|
|
| 3399 | + $row = $this->db->fetch_row($resql); |
|
| 3400 | + return $row[0]; |
|
| 3401 | + } |
|
| 3402 | + } |
|
| 3403 | + |
|
| 3404 | + /** |
|
| 3405 | + * Function to check if an object is used by others. |
|
| 3406 | + * Check is done into this->childtables. There is no check into llx_element_element. |
|
| 3407 | + * |
|
| 3408 | + * @param int $id Force id of object |
|
| 3409 | + * @return int <0 if KO, 0 if not used, >0 if already used |
|
| 3410 | + */ |
|
| 3411 | + function isObjectUsed($id=0) |
|
| 3412 | + {
|
|
| 3413 | + global $langs; |
|
| 3414 | + |
|
| 3415 | + if (empty($id)) $id=$this->id; |
|
| 3416 | + |
|
| 3417 | + // Check parameters |
|
| 3418 | + if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
|
| 3419 | + {
|
|
| 3420 | + dol_print_error('Called isObjectUsed on a class with property this->childtables not defined');
|
|
| 3421 | + return -1; |
|
| 3422 | + } |
|
| 3423 | + |
|
| 3424 | + $arraytoscan = $this->childtables; |
|
| 3425 | + // For backward compatibility, we check if array is old format array('table1', 'table2', ...)
|
|
| 3426 | + $tmparray=array_keys($this->childtables); |
|
| 3427 | + if (is_numeric($tmparray[0])) |
|
| 3428 | + {
|
|
| 3429 | + $arraytoscan = array_flip($this->childtables); |
|
| 3430 | + } |
|
| 3431 | + |
|
| 3432 | + // Test if child exists |
|
| 3433 | + $haschild=0; |
|
| 3434 | + foreach($arraytoscan as $table => $elementname) |
|
| 3435 | + {
|
|
| 3436 | + //print $id.'-'.$table.'-'.$elementname.'<br>'; |
|
| 3437 | + // Check if third party can be deleted |
|
| 3438 | + $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; |
|
| 3439 | + $sql.= " WHERE ".$this->fk_element." = ".$id; |
|
| 3440 | + $resql=$this->db->query($sql); |
|
| 3441 | + if ($resql) |
|
| 3442 | + {
|
|
| 3443 | + $obj=$this->db->fetch_object($resql); |
|
| 3444 | + if ($obj->nb > 0) |
|
| 3445 | + {
|
|
| 3446 | + $langs->load("errors");
|
|
| 3447 | + //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
|
| 3448 | + $haschild += $obj->nb; |
|
| 3449 | + if (is_numeric($elementname)) // old usage |
|
| 3450 | + {
|
|
| 3451 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3452 | + } |
|
| 3453 | + else // new usage: $elementname=Translation key |
|
| 3454 | + {
|
|
| 3455 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
|
| 3456 | + } |
|
| 3457 | + break; // We found at least one, we stop here |
|
| 3458 | + } |
|
| 3459 | + } |
|
| 3460 | + else |
|
| 3461 | + {
|
|
| 3462 | + $this->errors[]=$this->db->lasterror(); |
|
| 3463 | + return -1; |
|
| 3464 | + } |
|
| 3465 | + } |
|
| 3466 | + if ($haschild > 0) |
|
| 3467 | + {
|
|
| 3468 | + $this->errors[]="ErrorRecordHasChildren"; |
|
| 3469 | + return $haschild; |
|
| 3470 | + } |
|
| 3471 | + else return 0; |
|
| 3472 | + } |
|
| 3473 | + |
|
| 3474 | + /** |
|
| 3475 | + * Function to say how many lines object contains |
|
| 3476 | + * |
|
| 3477 | + * @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 |
|
| 3478 | + * @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found |
|
| 3479 | + */ |
|
| 3480 | + function hasProductsOrServices($predefined=-1) |
|
| 3481 | + {
|
|
| 3482 | + $nb=0; |
|
| 3483 | + |
|
| 3484 | + foreach($this->lines as $key => $val) |
|
| 3485 | + {
|
|
| 3486 | + $qualified=0; |
|
| 3487 | + if ($predefined == -1) $qualified=1; |
|
| 3488 | + if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3489 | + if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3490 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3491 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3492 | + if ($qualified) $nb++; |
|
| 3493 | + } |
|
| 3494 | + dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
|
| 3495 | + return $nb; |
|
| 3496 | + } |
|
| 3497 | + |
|
| 3498 | + /** |
|
| 3499 | + * Function that returns the total amount HT of discounts applied for all lines. |
|
| 3500 | + * |
|
| 3501 | + * @return float |
|
| 3502 | + */ |
|
| 3503 | + function getTotalDiscount() |
|
| 3504 | + {
|
|
| 3505 | + $total_discount=0.00; |
|
| 3506 | + |
|
| 3507 | + $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; |
|
| 3508 | + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."det"; |
|
| 3509 | + $sql.= " WHERE ".$this->fk_element." = ".$this->id; |
|
| 3510 | + |
|
| 3511 | + dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); |
|
| 3512 | + $resql = $this->db->query($sql); |
|
| 3513 | + if ($resql) |
|
| 3514 | + {
|
|
| 3515 | + $num=$this->db->num_rows($resql); |
|
| 3516 | + $i=0; |
|
| 3517 | + while ($i < $num) |
|
| 3518 | + {
|
|
| 3519 | + $obj = $this->db->fetch_object($resql); |
|
| 3520 | + |
|
| 3521 | + $pu_ht = $obj->pu_ht; |
|
| 3522 | + $qty= $obj->qty; |
|
| 3523 | + $total_ht = $obj->total_ht; |
|
| 3524 | + |
|
| 3525 | + $total_discount_line = floatval(price2num(($pu_ht * $qty) - $total_ht, 'MT')); |
|
| 3526 | + $total_discount += $total_discount_line; |
|
| 3527 | + |
|
| 3528 | + $i++; |
|
| 3529 | + } |
|
| 3530 | + } |
|
| 3531 | + |
|
| 3532 | + //print $total_discount; exit; |
|
| 3533 | + return price2num($total_discount); |
|
| 3534 | + } |
|
| 3535 | + |
|
| 3536 | + |
|
| 3537 | + /** |
|
| 3538 | + * Return into unit=0, the calculated total of weight and volume of all lines * qty |
|
| 3539 | + * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. |
|
| 3540 | + * |
|
| 3541 | + * @return array array('weight'=>...,'volume'=>...)
|
|
| 3542 | + */ |
|
| 3543 | + function getTotalWeightVolume() |
|
| 3544 | + {
|
|
| 3545 | + $totalWeight = 0; |
|
| 3546 | + $totalVolume = 0; |
|
| 3547 | + // defined for shipment only |
|
| 3548 | + $totalOrdered = ''; |
|
| 3549 | + // defined for shipment only |
|
| 3550 | + $totalToShip = ''; |
|
| 3551 | + |
|
| 3552 | + foreach ($this->lines as $line) |
|
| 3553 | + {
|
|
| 3554 | + if (isset($line->qty_asked)) |
|
| 3555 | + {
|
|
| 3556 | + if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3557 | + $totalOrdered+=$line->qty_asked; // defined for shipment only |
|
| 3558 | + } |
|
| 3559 | + if (isset($line->qty_shipped)) |
|
| 3560 | + {
|
|
| 3561 | + if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3562 | + $totalToShip+=$line->qty_shipped; // defined for shipment only |
|
| 3563 | + }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3564 | + {
|
|
| 3565 | + if (empty($totalToShip)) $totalToShip=0; |
|
| 3566 | + $totalToShip+=$line->qty; // defined for reception only |
|
| 3567 | + } |
|
| 3568 | + |
|
| 3569 | + // Define qty, weight, volume, weight_units, volume_units |
|
| 3570 | + if ($this->element == 'shipping') {
|
|
| 3571 | + // for shipments |
|
| 3572 | + $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
|
| 3573 | + } |
|
| 3574 | + else {
|
|
| 3575 | + $qty = $line->qty ? $line->qty : 0; |
|
| 3576 | + } |
|
| 3577 | + |
|
| 3578 | + $weight = $line->weight ? $line->weight : 0; |
|
| 3579 | + ($weight==0 && !empty($line->product->weight))? $weight=$line->product->weight: 0; |
|
| 3580 | + $volume = $line->volume ? $line->volume : 0; |
|
| 3581 | + ($volume==0 && !empty($line->product->volume))? $volume=$line->product->volume: 0; |
|
| 3582 | + |
|
| 3583 | + $weight_units=$line->weight_units; |
|
| 3584 | + ($weight_units==0 && !empty($line->product->weight_units))? $weight_units=$line->product->weight_units: 0; |
|
| 3585 | + $volume_units=$line->volume_units; |
|
| 3586 | + ($volume_units==0 && !empty($line->product->volume_units))? $volume_units=$line->product->volume_units: 0; |
|
| 3587 | + |
|
| 3588 | + $weightUnit=0; |
|
| 3589 | + $volumeUnit=0; |
|
| 3590 | + if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3591 | + if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3592 | + |
|
| 3593 | + if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3594 | + if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3595 | + |
|
| 3596 | + //var_dump($line->volume_units); |
|
| 3597 | + if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3598 | + {
|
|
| 3599 | + $trueWeightUnit=pow(10, $weightUnit); |
|
| 3600 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3601 | + } |
|
| 3602 | + else {
|
|
| 3603 | + if ($weight_units == 99) {
|
|
| 3604 | + // conversion 1 Pound = 0.45359237 KG |
|
| 3605 | + $trueWeightUnit = 0.45359237; |
|
| 3606 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3607 | + } elseif ($weight_units == 98) {
|
|
| 3608 | + // conversion 1 Ounce = 0.0283495 KG |
|
| 3609 | + $trueWeightUnit = 0.0283495; |
|
| 3610 | + $totalWeight += $weight * $qty * $trueWeightUnit; |
|
| 3611 | + } |
|
| 3612 | + else |
|
| 3613 | + $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3614 | + } |
|
| 3615 | + if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3616 | + {
|
|
| 3617 | + //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
|
| 3618 | + $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3619 | + //print $line->volume; |
|
| 3620 | + $totalVolume += $volume * $qty * $trueVolumeUnit; |
|
| 3621 | + } |
|
| 3622 | + else |
|
| 3623 | + {
|
|
| 3624 | + $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
|
| 3625 | + } |
|
| 3626 | + } |
|
| 3627 | + |
|
| 3628 | + return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip);
|
|
| 3629 | + } |
|
| 3630 | + |
|
| 3631 | + |
|
| 3632 | + /** |
|
| 3633 | + * Set extra parameters |
|
| 3634 | + * |
|
| 3635 | + * @return int <0 if KO, >0 if OK |
|
| 3636 | + */ |
|
| 3637 | + function setExtraParameters() |
|
| 3638 | + {
|
|
| 3639 | + $this->db->begin(); |
|
| 3640 | + |
|
| 3641 | + $extraparams = (! empty($this->extraparams) ? json_encode($this->extraparams) : null); |
|
| 3642 | + |
|
| 3643 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3644 | + $sql.= " SET extraparams = ".(! empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); |
|
| 3645 | + $sql.= " WHERE rowid = ".$this->id; |
|
| 3646 | + |
|
| 3647 | + dol_syslog(get_class($this)."::setExtraParameters", LOG_DEBUG); |
|
| 3648 | + $resql = $this->db->query($sql); |
|
| 3649 | + if (! $resql) |
|
| 3650 | + {
|
|
| 3651 | + $this->error=$this->db->lasterror(); |
|
| 3652 | + $this->db->rollback(); |
|
| 3653 | + return -1; |
|
| 3654 | + } |
|
| 3655 | + else |
|
| 3656 | + {
|
|
| 3657 | + $this->db->commit(); |
|
| 3658 | + return 1; |
|
| 3659 | + } |
|
| 3660 | + } |
|
| 3661 | + |
|
| 3662 | + |
|
| 3663 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 3664 | + /** |
|
| 3665 | + * Return incoterms informations |
|
| 3666 | + * TODO Use a cache for label get |
|
| 3667 | + * |
|
| 3668 | + * @return string incoterms info |
|
| 3669 | + */ |
|
| 3670 | + function display_incoterms() |
|
| 3671 | + {
|
|
| 3672 | + // phpcs:enable |
|
| 3673 | + $out = ''; |
|
| 3674 | + $this->libelle_incoterms = ''; |
|
| 3675 | + if (!empty($this->fk_incoterms)) |
|
| 3676 | + {
|
|
| 3677 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3678 | + $result = $this->db->query($sql); |
|
| 3679 | + if ($result) |
|
| 3680 | + {
|
|
| 3681 | + $res = $this->db->fetch_object($result); |
|
| 3682 | + $out .= $res->code; |
|
| 3683 | + } |
|
| 3684 | + } |
|
| 3685 | + |
|
| 3686 | + $out .= (($res->code && $this->location_incoterms)?' - ':'').$this->location_incoterms; |
|
| 3687 | + |
|
| 3688 | + return $out; |
|
| 3689 | + } |
|
| 3690 | + |
|
| 3691 | + /** |
|
| 3692 | + * Return incoterms informations for pdf display |
|
| 3693 | + * |
|
| 3694 | + * @return string incoterms info |
|
| 3695 | + */ |
|
| 3696 | + function getIncotermsForPDF() |
|
| 3697 | + {
|
|
| 3698 | + $sql = 'SELECT code FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3699 | + $resql = $this->db->query($sql); |
|
| 3700 | + if ($resql) |
|
| 3701 | + {
|
|
| 3702 | + $num = $this->db->num_rows($resql); |
|
| 3703 | + if ($num > 0) |
|
| 3704 | + {
|
|
| 3705 | + $res = $this->db->fetch_object($resql); |
|
| 3706 | + return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
|
| 3707 | + } |
|
| 3708 | + else |
|
| 3709 | + {
|
|
| 3710 | + return ''; |
|
| 3711 | + } |
|
| 3712 | + } |
|
| 3713 | + else |
|
| 3714 | + {
|
|
| 3715 | + $this->errors[] = $this->db->lasterror(); |
|
| 3716 | + return false; |
|
| 3717 | + } |
|
| 3718 | + } |
|
| 3719 | + |
|
| 3720 | + /** |
|
| 3721 | + * Define incoterms values of current object |
|
| 3722 | + * |
|
| 3723 | + * @param int $id_incoterm Id of incoterm to set or '' to remove |
|
| 3724 | + * @param string $location location of incoterm |
|
| 3725 | + * @return int <0 if KO, >0 if OK |
|
| 3726 | + */ |
|
| 3727 | + function setIncoterms($id_incoterm, $location) |
|
| 3728 | + {
|
|
| 3729 | + if ($this->id && $this->table_element) |
|
| 3730 | + {
|
|
| 3731 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
|
| 3732 | + $sql.= " SET fk_incoterms = ".($id_incoterm > 0 ? $id_incoterm : "null"); |
|
| 3733 | + $sql.= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); |
|
| 3734 | + $sql.= " WHERE rowid = " . $this->id; |
|
| 3735 | + dol_syslog(get_class($this).'::setIncoterms', LOG_DEBUG); |
|
| 3736 | + $resql=$this->db->query($sql); |
|
| 3737 | + if ($resql) |
|
| 3738 | + {
|
|
| 3739 | + $this->fk_incoterms = $id_incoterm; |
|
| 3740 | + $this->location_incoterms = $location; |
|
| 3741 | + |
|
| 3742 | + $sql = 'SELECT libelle FROM '.MAIN_DB_PREFIX.'c_incoterms WHERE rowid = '.(int) $this->fk_incoterms; |
|
| 3743 | + $res = $this->db->query($sql); |
|
| 3744 | + if ($res) |
|
| 3745 | + {
|
|
| 3746 | + $obj = $this->db->fetch_object($res); |
|
| 3747 | + $this->libelle_incoterms = $obj->libelle; |
|
| 3748 | + } |
|
| 3749 | + return 1; |
|
| 3750 | + } |
|
| 3751 | + else |
|
| 3752 | + {
|
|
| 3753 | + $this->errors[] = $this->db->lasterror(); |
|
| 3754 | + return -1; |
|
| 3755 | + } |
|
| 3756 | + } |
|
| 3757 | + else return -1; |
|
| 3758 | + } |
|
| 3759 | + |
|
| 3760 | + |
|
| 3761 | + // -------------------- |
|
| 3762 | + // TODO: All functions here must be redesigned and moved as they are not business functions but output functions |
|
| 3763 | + // -------------------- |
|
| 3764 | + |
|
| 3765 | + /* This is to show add lines */ |
|
| 3766 | + |
|
| 3767 | + /** |
|
| 3768 | + * Show add free and predefined products/services form |
|
| 3769 | + * |
|
| 3770 | + * @param int $dateSelector 1=Show also date range input fields |
|
| 3771 | + * @param Societe $seller Object thirdparty who sell |
|
| 3772 | + * @param Societe $buyer Object thirdparty who buy |
|
| 3773 | + * @return void |
|
| 3774 | + */ |
|
| 3775 | + function formAddObjectLine($dateSelector, $seller, $buyer) |
|
| 3776 | + {
|
|
| 3777 | + global $conf,$user,$langs,$object,$hookmanager; |
|
| 3778 | + global $form,$bcnd,$var; |
|
| 3779 | + |
|
| 3780 | + // Line extrafield |
|
| 3781 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3782 | + $extrafieldsline = new AlExtraFields($this->db); |
|
| 3783 | + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3784 | + |
|
| 3785 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 3786 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 3787 | + $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 3788 | + foreach($dirtpls as $reldir) |
|
| 3789 | + {
|
|
| 3790 | + $tpl = dol_buildpath($reldir.'/objectline_create.tpl.php'); |
|
| 3791 | + if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 3792 | + $res=@include $tpl; |
|
| 3793 | + } else {
|
|
| 3794 | + $res=include $tpl; // for debug |
|
| 3795 | + } |
|
| 3796 | + if ($res) break; |
|
| 3797 | + } |
|
| 3798 | + } |
|
| 3799 | + |
|
| 3800 | + |
|
| 3801 | + |
|
| 3802 | + /* This is to show array of line of details */ |
|
| 3803 | + |
|
| 3804 | + |
|
| 3805 | + /** |
|
| 3806 | + * Return HTML table for object lines |
|
| 3807 | + * TODO Move this into an output class file (htmlline.class.php) |
|
| 3808 | + * If lines are into a template, title must also be into a template |
|
| 3809 | + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 3810 | + * |
|
| 3811 | + * @param string $action Action code |
|
| 3812 | + * @param string $seller Object of seller third party |
|
| 3813 | + * @param string $buyer Object of buyer third party |
|
| 3814 | + * @param int $selected Object line selected |
|
| 3815 | + * @param int $dateSelector 1=Show also date range input fields |
|
| 3816 | + * @return void |
|
| 3817 | + */ |
|
| 3818 | + function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) |
|
| 3819 | + {
|
|
| 3820 | + global $conf, $hookmanager, $langs, $user; |
|
| 3821 | + // TODO We should not use global var for this ! |
|
| 3822 | + global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove, $outputalsopricetotalwithtax; |
|
| 3823 | + |
|
| 3824 | + // Define usemargins |
|
| 3825 | + $usemargins=0; |
|
| 3826 | + if (!empty(Globals::$conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande')))
|
|
| 3827 | + $usemargins = 1; |
|
| 3828 | + |
|
| 3829 | + $num = count($this->lines); |
|
| 3830 | + |
|
| 3831 | + // Line extrafield |
|
| 3832 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 3833 | + $extrafieldsline = new AlExtraFields($this->db); |
|
| 3834 | + $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); |
|
| 3835 | + |
|
| 3836 | + $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3837 | + $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3838 | + if (empty($reshook)) |
|
| 3839 | + {
|
|
| 3840 | + // Title line |
|
| 3841 | + print "<thead>\n"; |
|
| 3842 | + |
|
| 3843 | + print '<tr class="liste_titre nodrag nodrop">'; |
|
| 3844 | + |
|
| 3845 | + // Adds a line numbering column |
|
| 3846 | + if (!empty(Globals::$conf->global->MAIN_VIEW_LINE_NUMBER)) |
|
| 3847 | + print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 3848 | + |
|
| 3849 | + // Description |
|
| 3850 | + print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
|
| 3851 | + |
|
| 3852 | + if ($this->element == 'supplier_proposal' || $this->element == 'order_supplier' || $this->element == 'invoice_supplier') |
|
| 3853 | + {
|
|
| 3854 | + print '<td class="linerefsupplier"><span id="title_fourn_ref">'.$langs->trans("SupplierRef").'</span></td>';
|
|
| 3855 | + } |
|
| 3856 | + |
|
| 3857 | + // VAT |
|
| 3858 | + print '<td class="linecolvat" align="right" width="80">'.$langs->trans('VAT').'</td>';
|
|
| 3859 | + |
|
| 3860 | + // Price HT |
|
| 3861 | + print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
|
|
| 3862 | + |
|
| 3863 | + // Multicurrency |
|
| 3864 | + if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) |
|
| 3865 | + print '<td class="linecoluht_currency" align="right" width="80">' . $langs->trans('PriceUHTCurrency', $this->multicurrency_code) . '</td>';
|
|
| 3866 | + |
|
| 3867 | + if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
|
|
| 3868 | + |
|
| 3869 | + // Qty |
|
| 3870 | + print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
|
| 3871 | + |
|
| 3872 | + if (Globals::$conf->global->PRODUCT_USE_UNITS) {
|
|
| 3873 | + print '<td class="linecoluseunit" align="left">'.$langs->trans('Unit').'</td>';
|
|
| 3874 | + } |
|
| 3875 | + |
|
| 3876 | + // Reduction short |
|
| 3877 | + print '<td class="linecoldiscount" align="right">'.$langs->trans('ReductionShort').'</td>';
|
|
| 3878 | + |
|
| 3879 | + if ($this->situation_cycle_ref) {
|
|
| 3880 | + print '<td class="linecolcycleref" align="right">' . $langs->trans('Progress') . '</td>';
|
|
| 3881 | + } |
|
| 3882 | + |
|
| 3883 | + if ($usemargins && !empty(Globals::$conf->margin->enabled) && empty($user->societe_id)) {
|
|
| 3884 | + if (!empty($user->rights->margins->creer)) |
|
| 3885 | + {
|
|
| 3886 | + if (Globals::$conf->global->MARGIN_TYPE == "1") |
|
| 3887 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
|
|
| 3888 | + else |
|
| 3889 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
|
| 3890 | + } |
|
| 3891 | + |
|
| 3892 | + if (!empty(Globals::$conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3893 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
|
| 3894 | + if (!empty(Globals::$conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3895 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
|
| 3896 | + } |
|
| 3897 | + |
|
| 3898 | + // Total HT |
|
| 3899 | + print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
|
|
| 3900 | + |
|
| 3901 | + // Multicurrency |
|
| 3902 | + if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) |
|
| 3903 | + print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>';
|
|
| 3904 | + |
|
| 3905 | + if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
|
| 3906 | + |
|
| 3907 | + print '<td class="linecoledit"></td>'; // No width to allow autodim |
|
| 3908 | + |
|
| 3909 | + print '<td class="linecoldelete" width="10"></td>'; |
|
| 3910 | + |
|
| 3911 | + print '<td class="linecolmove" width="10"></td>'; |
|
| 3912 | + |
|
| 3913 | + if($action == 'selectlines') |
|
| 3914 | + {
|
|
| 3915 | + print '<td class="linecolcheckall" align="center">'; |
|
| 3916 | + print '<input type="checkbox" class="linecheckboxtoggle" />'; |
|
| 3917 | + print '<script type="text/javascript">$(document).ready(function() {$(".linecheckboxtoggle").click(function() {var checkBoxes = $(".linecheckbox");checkBoxes.prop("checked", this.checked);})});</script>';
|
|
| 3918 | + print '</td>'; |
|
| 3919 | + } |
|
| 3920 | + |
|
| 3921 | + print "</tr>\n"; |
|
| 3922 | + print "</thead>\n"; |
|
| 3923 | + } |
|
| 3924 | + |
|
| 3925 | + $var = true; |
|
| 3926 | + $i = 0; |
|
| 3927 | + |
|
| 3928 | + print "<tbody>\n"; |
|
| 3929 | + foreach ($this->lines as $line) |
|
| 3930 | + {
|
|
| 3931 | + //Line extrafield |
|
| 3932 | + $line->fetch_optionals(); |
|
| 3933 | + |
|
| 3934 | + //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 3935 | + if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 3936 | + {
|
|
| 3937 | + if (empty($line->fk_parent_line)) |
|
| 3938 | + {
|
|
| 3939 | + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 3940 | + $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3941 | + } |
|
| 3942 | + else |
|
| 3943 | + {
|
|
| 3944 | + $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);
|
|
| 3945 | + $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
|
| 3946 | + } |
|
| 3947 | + } |
|
| 3948 | + if (empty($reshook)) |
|
| 3949 | + {
|
|
| 3950 | + $this->printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected,$extrafieldsline); |
|
| 3951 | + } |
|
| 3952 | + |
|
| 3953 | + $i++; |
|
| 3954 | + } |
|
| 3955 | + print "</tbody>\n"; |
|
| 3956 | + } |
|
| 3957 | + |
|
| 3958 | + /** |
|
| 3959 | + * Return HTML content of a detail line |
|
| 3960 | + * TODO Move this into an output class file (htmlline.class.php) |
|
| 3961 | + * |
|
| 3962 | + * @param string $action GET/POST action |
|
| 3963 | + * @param CommonObjectLine $line Selected object line to output |
|
| 3964 | + * @param string $var Is it a an odd line (true) |
|
| 3965 | + * @param int $num Number of line (0) |
|
| 3966 | + * @param int $i I |
|
| 3967 | + * @param int $dateSelector 1=Show also date range input fields |
|
| 3968 | + * @param string $seller Object of seller third party |
|
| 3969 | + * @param string $buyer Object of buyer third party |
|
| 3970 | + * @param int $selected Object line selected |
|
| 3971 | + * @param int $extrafieldsline Object of extrafield line attribute |
|
| 3972 | + * @return void |
|
| 3973 | + */ |
|
| 3974 | + function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) |
|
| 3975 | + {
|
|
| 3976 | + global $conf,$langs,$user,$object,$hookmanager; |
|
| 3977 | + global $form,$bc,$bcdd; |
|
| 3978 | + global $object_rights, $disableedit, $disablemove, $disableremove; // TODO We should not use global var for this ! |
|
| 3979 | + |
|
| 3980 | + $object_rights = $this->getRights(); |
|
| 3981 | + |
|
| 3982 | + $element=$this->element; |
|
| 3983 | + |
|
| 3984 | + $text=''; $description=''; $type=0; |
|
| 3985 | + |
|
| 3986 | + // Show product and description |
|
| 3987 | + $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
|
| 3988 | + // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
|
| 3989 | + if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3990 | + if (! empty($line->date_end)) $type=1; // deprecated |
|
| 3991 | + |
|
| 3992 | + // Ligne en mode visu |
|
| 3993 | + if ($action != 'editline' || $selected != $line->id) |
|
| 3994 | + {
|
|
| 3995 | + // Product |
|
| 3996 | + if ($line->fk_product > 0) |
|
| 3997 | + {
|
|
| 3998 | + $product_static = new Product($this->db); |
|
| 3999 | + $product_static->fetch($line->fk_product); |
|
| 4000 | + |
|
| 4001 | + $product_static->ref = $line->ref; //can change ref in hook |
|
| 4002 | + $product_static->label = $line->label; //can change label in hook |
|
| 4003 | + $text=$product_static->getNomUrl(1); |
|
| 4004 | + |
|
| 4005 | + // Define output language and label |
|
| 4006 | + if (!empty(Globals::$conf->global->MAIN_MULTILANGS)) {
|
|
| 4007 | + if (! is_object($this->thirdparty)) |
|
| 4008 | + {
|
|
| 4009 | + dol_print_error('','Error: Method printObjectLine was called on an object and object->fetch_thirdparty was not done before');
|
|
| 4010 | + return; |
|
| 4011 | + } |
|
| 4012 | + |
|
| 4013 | + $prod = new Product($this->db); |
|
| 4014 | + $prod->fetch($line->fk_product); |
|
| 4015 | + |
|
| 4016 | + $outputlangs = $langs; |
|
| 4017 | + $newlang=''; |
|
| 4018 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4019 | + if (!empty(Globals::$conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) |
|
| 4020 | + $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
| 4021 | + if (! empty($newlang)) |
|
| 4022 | + {
|
|
| 4023 | + $outputlangs = new Translate("",$conf);
|
|
| 4024 | + $outputlangs->setDefaultLang($newlang); |
|
| 4025 | + } |
|
| 4026 | + |
|
| 4027 | + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
|
| 4028 | + } |
|
| 4029 | + else |
|
| 4030 | + {
|
|
| 4031 | + $label = $line->product_label; |
|
| 4032 | + } |
|
| 4033 | + |
|
| 4034 | + $text.= ' - '.(! empty($line->label)?$line->label:$label); |
|
| 4035 | + $description .= (!empty(Globals::$conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. |
|
| 4036 | + } |
|
| 4037 | + |
|
| 4038 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4039 | + |
|
| 4040 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4041 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 4042 | + $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4043 | + foreach($dirtpls as $reldir) |
|
| 4044 | + {
|
|
| 4045 | + $tpl = dol_buildpath($reldir.'/objectline_view.tpl.php'); |
|
| 4046 | + if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 4047 | + $res=@include $tpl; |
|
| 4048 | + } else {
|
|
| 4049 | + $res=include $tpl; // for debug |
|
| 4050 | + } |
|
| 4051 | + if ($res) break; |
|
| 4052 | + } |
|
| 4053 | + } |
|
| 4054 | + |
|
| 4055 | + // Ligne en mode update |
|
| 4056 | + if ($this->statut == 0 && $action == 'editline' && $selected == $line->id) |
|
| 4057 | + {
|
|
| 4058 | + $label = (! empty($line->label) ? $line->label : (($line->fk_product > 0) ? $line->product_label : '')); |
|
| 4059 | + $placeholder=' placeholder="'.$langs->trans("Label").'"';
|
|
| 4060 | + |
|
| 4061 | + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); |
|
| 4062 | + |
|
| 4063 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4064 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 4065 | + $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4066 | + foreach($dirtpls as $reldir) |
|
| 4067 | + {
|
|
| 4068 | + $tpl = dol_buildpath($reldir.'/objectline_edit.tpl.php'); |
|
| 4069 | + if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 4070 | + $res=@include $tpl; |
|
| 4071 | + } else {
|
|
| 4072 | + $res=include $tpl; // for debug |
|
| 4073 | + } |
|
| 4074 | + if ($res) break; |
|
| 4075 | + } |
|
| 4076 | + } |
|
| 4077 | + } |
|
| 4078 | + |
|
| 4079 | + |
|
| 4080 | + /* This is to show array of line of details of source object */ |
|
| 4081 | + |
|
| 4082 | + |
|
| 4083 | + /** |
|
| 4084 | + * Return HTML table table of source object lines |
|
| 4085 | + * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4086 | + * If lines are into a template, title must also be into a template |
|
| 4087 | + * But for the moment we don't know if it's possible, so we keep the method available on overloaded objects. |
|
| 4088 | + * |
|
| 4089 | + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only |
|
| 4090 | + * @return void |
|
| 4091 | + */ |
|
| 4092 | + function printOriginLinesList($restrictlist='') |
|
| 4093 | + {
|
|
| 4094 | + global $langs, $hookmanager, $conf; |
|
| 4095 | + |
|
| 4096 | + print '<tr class="liste_titre">'; |
|
| 4097 | + print '<td>'.$langs->trans('Ref').'</td>';
|
|
| 4098 | + print '<td>'.$langs->trans('Description').'</td>';
|
|
| 4099 | + print '<td align="right">'.$langs->trans('VATRate').'</td>';
|
|
| 4100 | + print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
|
| 4101 | + if (!empty(Globals::$conf->multicurrency->enabled)) |
|
| 4102 | + print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>';
|
|
| 4103 | + print '<td align="right">'.$langs->trans('Qty').'</td>';
|
|
| 4104 | + if (Globals::$conf->global->PRODUCT_USE_UNITS) {
|
|
| 4105 | + print '<td align="left">'.$langs->trans('Unit').'</td>';
|
|
| 4106 | + } |
|
| 4107 | + print '<td align="right">'.$langs->trans('ReductionShort').'</td></tr>';
|
|
| 4108 | + |
|
| 4109 | + $var = true; |
|
| 4110 | + $i = 0; |
|
| 4111 | + |
|
| 4112 | + if (! empty($this->lines)) |
|
| 4113 | + {
|
|
| 4114 | + foreach ($this->lines as $line) |
|
| 4115 | + {
|
|
| 4116 | + if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
|
| 4117 | + {
|
|
| 4118 | + if (empty($line->fk_parent_line)) |
|
| 4119 | + {
|
|
| 4120 | + $parameters=array('line'=>$line,'var'=>$var,'i'=>$i);
|
|
| 4121 | + $action=''; |
|
| 4122 | + $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
|
| 4123 | + } |
|
| 4124 | + } |
|
| 4125 | + else |
|
| 4126 | + {
|
|
| 4127 | + $this->printOriginLine($line, $var, $restrictlist); |
|
| 4128 | + } |
|
| 4129 | + |
|
| 4130 | + $i++; |
|
| 4131 | + } |
|
| 4132 | + } |
|
| 4133 | + } |
|
| 4134 | + |
|
| 4135 | + /** |
|
| 4136 | + * Return HTML with a line of table array of source object lines |
|
| 4137 | + * TODO Move this and previous function into output html class file (htmlline.class.php). |
|
| 4138 | + * If lines are into a template, title must also be into a template |
|
| 4139 | + * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. |
|
| 4140 | + * |
|
| 4141 | + * @param CommonObjectLine $line Line |
|
| 4142 | + * @param string $var Var |
|
| 4143 | + * @param string $restrictlist ''=All lines, 'services'=Restrict to services only (strike line if not) |
|
| 4144 | + * @return void |
|
| 4145 | + */ |
|
| 4146 | + function printOriginLine($line, $var, $restrictlist='') |
|
| 4147 | + {
|
|
| 4148 | + global $langs, $conf; |
|
| 4149 | + |
|
| 4150 | + //var_dump($line); |
|
| 4151 | + if (!empty($line->date_start)) |
|
| 4152 | + {
|
|
| 4153 | + $date_start=$line->date_start; |
|
| 4154 | + } |
|
| 4155 | + else |
|
| 4156 | + {
|
|
| 4157 | + $date_start=$line->date_debut_prevue; |
|
| 4158 | + if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4159 | + } |
|
| 4160 | + if (!empty($line->date_end)) |
|
| 4161 | + {
|
|
| 4162 | + $date_end=$line->date_end; |
|
| 4163 | + } |
|
| 4164 | + else |
|
| 4165 | + {
|
|
| 4166 | + $date_end=$line->date_fin_prevue; |
|
| 4167 | + if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4168 | + } |
|
| 4169 | + |
|
| 4170 | + $this->tpl['label'] = ''; |
|
| 4171 | + if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4172 | + |
|
| 4173 | + if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4174 | + {
|
|
| 4175 | + $discount=new DiscountAbsolute($this->db); |
|
| 4176 | + $discount->fk_soc = $this->socid; |
|
| 4177 | + $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
|
| 4178 | + } |
|
| 4179 | + else if (! empty($line->fk_product)) |
|
| 4180 | + {
|
|
| 4181 | + $productstatic = new Product($this->db); |
|
| 4182 | + $productstatic->id = $line->fk_product; |
|
| 4183 | + $productstatic->ref = $line->ref; |
|
| 4184 | + $productstatic->type = $line->fk_product_type; |
|
| 4185 | + if(empty($productstatic->ref)){
|
|
| 4186 | + $line->fetch_product(); |
|
| 4187 | + $productstatic = $line->product; |
|
| 4188 | + } |
|
| 4189 | + |
|
| 4190 | + $this->tpl['label'].= $productstatic->getNomUrl(1); |
|
| 4191 | + $this->tpl['label'].= ' - '.(! empty($line->label)?$line->label:$line->product_label); |
|
| 4192 | + // Dates |
|
| 4193 | + if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4194 | + {
|
|
| 4195 | + $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4196 | + } |
|
| 4197 | + } |
|
| 4198 | + else |
|
| 4199 | + {
|
|
| 4200 | + $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
|
| 4201 | + if (!empty($line->desc)) {
|
|
| 4202 | + $this->tpl['label'].=$line->desc; |
|
| 4203 | + }else {
|
|
| 4204 | + $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
|
| 4205 | + } |
|
| 4206 | + |
|
| 4207 | + // Dates |
|
| 4208 | + if ($line->product_type == 1 && ($date_start || $date_end)) |
|
| 4209 | + {
|
|
| 4210 | + $this->tpl['label'].= get_date_range($date_start,$date_end); |
|
| 4211 | + } |
|
| 4212 | + } |
|
| 4213 | + |
|
| 4214 | + if (! empty($line->desc)) |
|
| 4215 | + {
|
|
| 4216 | + if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4217 | + {
|
|
| 4218 | + $discount=new DiscountAbsolute($this->db); |
|
| 4219 | + $discount->fetch($line->fk_remise_except); |
|
| 4220 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
|
| 4221 | + } |
|
| 4222 | + elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4223 | + {
|
|
| 4224 | + $discount=new DiscountAbsolute($this->db); |
|
| 4225 | + $discount->fetch($line->fk_remise_except); |
|
| 4226 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
|
| 4227 | + } |
|
| 4228 | + elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4229 | + {
|
|
| 4230 | + $discount=new DiscountAbsolute($this->db); |
|
| 4231 | + $discount->fetch($line->fk_remise_except); |
|
| 4232 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
|
| 4233 | + } |
|
| 4234 | + elseif ($line->desc == '(EXCESS PAID)') |
|
| 4235 | + {
|
|
| 4236 | + $discount=new DiscountAbsolute($this->db); |
|
| 4237 | + $discount->fetch($line->fk_remise_except); |
|
| 4238 | + $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
|
| 4239 | + } |
|
| 4240 | + else |
|
| 4241 | + {
|
|
| 4242 | + $this->tpl['description'] = dol_trunc($line->desc,60); |
|
| 4243 | + } |
|
| 4244 | + } |
|
| 4245 | + else |
|
| 4246 | + {
|
|
| 4247 | + $this->tpl['description'] = ' '; |
|
| 4248 | + } |
|
| 4249 | + |
|
| 4250 | + // VAT Rate |
|
| 4251 | + $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
|
| 4252 | + $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
|
| 4253 | + if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 4254 | + |
|
| 4255 | + $this->tpl['price'] = price($line->subprice); |
|
| 4256 | + $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
|
| 4257 | + $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
|
| 4258 | + if (Globals::$conf->global->PRODUCT_USE_UNITS) |
|
| 4259 | + $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
|
|
| 4260 | + $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
|
| 4261 | + |
|
| 4262 | + // Is the line strike or not |
|
| 4263 | + $this->tpl['strike']=0; |
|
| 4264 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4265 | + |
|
| 4266 | + // Output template part (modules that overwrite templates must declare this into descriptor) |
|
| 4267 | + // Use global variables + $dateSelector + $seller and $buyer |
|
| 4268 | + $dirtpls = array_merge(Globals::$conf->modules_parts['tpl'], array('/core/tpl'));
|
|
| 4269 | + foreach($dirtpls as $reldir) |
|
| 4270 | + {
|
|
| 4271 | + $tpl = dol_buildpath($reldir.'/originproductline.tpl.php'); |
|
| 4272 | + if (empty(Globals::$conf->file->strict_mode)) {
|
|
| 4273 | + $res=@include $tpl; |
|
| 4274 | + } else {
|
|
| 4275 | + $res=include $tpl; // for debug |
|
| 4276 | + } |
|
| 4277 | + if ($res) break; |
|
| 4278 | + } |
|
| 4279 | + } |
|
| 4280 | + |
|
| 4281 | + |
|
| 4282 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4283 | + /** |
|
| 4284 | + * Add resources to the current object : add entry into llx_element_resources |
|
| 4285 | + * Need $this->element & $this->id |
|
| 4286 | + * |
|
| 4287 | + * @param int $resource_id Resource id |
|
| 4288 | + * @param string $resource_type 'resource' |
|
| 4289 | + * @param int $busy Busy or not |
|
| 4290 | + * @param int $mandatory Mandatory or not |
|
| 4291 | + * @return int <=0 if KO, >0 if OK |
|
| 4292 | + */ |
|
| 4293 | + function add_element_resource($resource_id, $resource_type, $busy=0, $mandatory=0) |
|
| 4294 | + {
|
|
| 4295 | + // phpcs:enable |
|
| 4296 | + $this->db->begin(); |
|
| 4297 | + |
|
| 4298 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources (";
|
|
| 4299 | + $sql.= "resource_id"; |
|
| 4300 | + $sql.= ", resource_type"; |
|
| 4301 | + $sql.= ", element_id"; |
|
| 4302 | + $sql.= ", element_type"; |
|
| 4303 | + $sql.= ", busy"; |
|
| 4304 | + $sql.= ", mandatory"; |
|
| 4305 | + $sql.= ") VALUES (";
|
|
| 4306 | + $sql.= $resource_id; |
|
| 4307 | + $sql.= ", '".$this->db->escape($resource_type)."'"; |
|
| 4308 | + $sql.= ", '".$this->db->escape($this->id)."'"; |
|
| 4309 | + $sql.= ", '".$this->db->escape($this->element)."'"; |
|
| 4310 | + $sql.= ", '".$this->db->escape($busy)."'"; |
|
| 4311 | + $sql.= ", '".$this->db->escape($mandatory)."'"; |
|
| 4312 | + $sql.= ")"; |
|
| 4313 | + |
|
| 4314 | + dol_syslog(get_class($this)."::add_element_resource", LOG_DEBUG); |
|
| 4315 | + if ($this->db->query($sql)) |
|
| 4316 | + {
|
|
| 4317 | + $this->db->commit(); |
|
| 4318 | + return 1; |
|
| 4319 | + } |
|
| 4320 | + else |
|
| 4321 | + {
|
|
| 4322 | + $this->error=$this->db->lasterror(); |
|
| 4323 | + $this->db->rollback(); |
|
| 4324 | + return 0; |
|
| 4325 | + } |
|
| 4326 | + } |
|
| 4327 | + |
|
| 4328 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4329 | + /** |
|
| 4330 | + * Delete a link to resource line |
|
| 4331 | + * |
|
| 4332 | + * @param int $rowid Id of resource line to delete |
|
| 4333 | + * @param int $element element name (for trigger) TODO: use $this->element into commonobject class |
|
| 4334 | + * @param int $notrigger Disable all triggers |
|
| 4335 | + * @return int >0 if OK, <0 if KO |
|
| 4336 | + */ |
|
| 4337 | + function delete_resource($rowid, $element, $notrigger=0) |
|
| 4338 | + {
|
|
| 4339 | + // phpcs:enable |
|
| 4340 | + global $user; |
|
| 4341 | + |
|
| 4342 | + $this->db->begin(); |
|
| 4343 | + |
|
| 4344 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; |
|
| 4345 | + $sql.= " WHERE rowid=".$rowid; |
|
| 4346 | + |
|
| 4347 | + dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); |
|
| 4348 | + |
|
| 4349 | + $resql=$this->db->query($sql); |
|
| 4350 | + if (! $resql) |
|
| 4351 | + {
|
|
| 4352 | + $this->error=$this->db->lasterror(); |
|
| 4353 | + $this->db->rollback(); |
|
| 4354 | + return -1; |
|
| 4355 | + } |
|
| 4356 | + else |
|
| 4357 | + {
|
|
| 4358 | + if (! $notrigger) |
|
| 4359 | + {
|
|
| 4360 | + $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); |
|
| 4361 | + if ($result < 0) { $this->db->rollback(); return -1; }
|
|
| 4362 | + } |
|
| 4363 | + $this->db->commit(); |
|
| 4364 | + return 1; |
|
| 4365 | + } |
|
| 4366 | + } |
|
| 4367 | + |
|
| 4368 | + |
|
| 4369 | + /** |
|
| 4370 | + * Overwrite magic function to solve problem of cloning object that are kept as references |
|
| 4371 | + * |
|
| 4372 | + * @return void |
|
| 4373 | + */ |
|
| 4374 | + function __clone() |
|
| 4375 | + {
|
|
| 4376 | + // Force a copy of this->lines, otherwise it will point to same object. |
|
| 4377 | + if (isset($this->lines) && is_array($this->lines)) |
|
| 4378 | + {
|
|
| 4379 | + $nboflines=count($this->lines); |
|
| 4380 | + for($i=0; $i < $nboflines; $i++) |
|
| 4381 | + {
|
|
| 4382 | + $this->lines[$i] = clone $this->lines[$i]; |
|
| 4383 | + } |
|
| 4384 | + } |
|
| 4385 | + } |
|
| 4386 | + |
|
| 4387 | + /** |
|
| 4388 | + * Common function for all objects extending CommonObject for generating documents |
|
| 4389 | + * |
|
| 4390 | + * @param string $modelspath Relative folder where generators are placed |
|
| 4391 | + * @param string $modele Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
|
|
| 4392 | + * @param Translate $outputlangs Output language to use |
|
| 4393 | + * @param int $hidedetails 1 to hide details. 0 by default |
|
| 4394 | + * @param int $hidedesc 1 to hide product description. 0 by default |
|
| 4395 | + * @param int $hideref 1 to hide product reference. 0 by default |
|
| 4396 | + * @param null|array $moreparams Array to provide more information |
|
| 4397 | + * @return int >0 if OK, <0 if KO |
|
| 4398 | + * @see addFileIntoDatabaseIndex |
|
| 4399 | + */ |
|
| 4400 | + protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null) |
|
| 4401 | + {
|
|
| 4402 | + global $conf, $langs, $user; |
|
| 4403 | + |
|
| 4404 | + $srctemplatepath=''; |
|
| 4405 | + |
|
| 4406 | + // Increase limit for PDF build |
|
| 4407 | + $err=error_reporting(); |
|
| 4408 | + error_reporting(0); |
|
| 4409 | + @set_time_limit(120); |
|
| 4410 | + error_reporting($err); |
|
| 4411 | + |
|
| 4412 | + // If selected model is a filename template (then $modele="modelname" or "modelname:filename") |
|
| 4413 | + $tmp=explode(':',$modele,2);
|
|
| 4414 | + if (! empty($tmp[1])) |
|
| 4415 | + {
|
|
| 4416 | + $modele=$tmp[0]; |
|
| 4417 | + $srctemplatepath=$tmp[1]; |
|
| 4418 | + } |
|
| 4419 | + |
|
| 4420 | + // Search template files |
|
| 4421 | + $file=''; $classname=''; $filefound=0; |
|
| 4422 | + $dirmodels=array('/');
|
|
| 4423 | + if (is_array(Globals::$conf->modules_parts['models'])) |
|
| 4424 | + $dirmodels = array_merge($dirmodels, Globals::$conf->modules_parts['models']); |
|
| 4425 | + foreach($dirmodels as $reldir) |
|
| 4426 | + {
|
|
| 4427 | + foreach(array('doc','pdf') as $prefix)
|
|
| 4428 | + {
|
|
| 4429 | + if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4430 | + else $file = $prefix."_".$modele.".modules.php"; |
|
| 4431 | + |
|
| 4432 | + // On verifie l'emplacement du modele |
|
| 4433 | + $file=dol_buildpath($reldir.$modelspath.$file,0); |
|
| 4434 | + if (file_exists($file)) |
|
| 4435 | + {
|
|
| 4436 | + $filefound=1; |
|
| 4437 | + $classname=$prefix.'_'.$modele; |
|
| 4438 | + break; |
|
| 4439 | + } |
|
| 4440 | + } |
|
| 4441 | + if ($filefound) break; |
|
| 4442 | + } |
|
| 4443 | + |
|
| 4444 | + // If generator was found |
|
| 4445 | + if ($filefound) |
|
| 4446 | + {
|
|
| 4447 | + global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db |
|
| 4448 | + |
|
| 4449 | + require_once $file; |
|
| 4450 | + |
|
| 4451 | + $obj = new $classname($this->db); |
|
| 4452 | + |
|
| 4453 | + // If generator is ODT, we must have srctemplatepath defined, if not we set it. |
|
| 4454 | + if ($obj->type == 'odt' && empty($srctemplatepath)) |
|
| 4455 | + {
|
|
| 4456 | + $varfortemplatedir=$obj->scandir; |
|
| 4457 | + if ($varfortemplatedir && !empty(Globals::$conf->global->$varfortemplatedir)) {
|
|
| 4458 | + $dirtoscan = Globals::$conf->global->$varfortemplatedir; |
|
| 4459 | + |
|
| 4460 | + $listoffiles=array(); |
|
| 4461 | + |
|
| 4462 | + // Now we add first model found in directories scanned |
|
| 4463 | + $listofdir=explode(',',$dirtoscan);
|
|
| 4464 | + foreach($listofdir as $key => $tmpdir) |
|
| 4465 | + {
|
|
| 4466 | + $tmpdir=trim($tmpdir); |
|
| 4467 | + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir);
|
|
| 4468 | + if (! $tmpdir) { unset($listofdir[$key]); continue; }
|
|
| 4469 | + if (is_dir($tmpdir)) |
|
| 4470 | + {
|
|
| 4471 | + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
|
| 4472 | + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4473 | + } |
|
| 4474 | + } |
|
| 4475 | + |
|
| 4476 | + if (count($listoffiles)) |
|
| 4477 | + {
|
|
| 4478 | + foreach($listoffiles as $record) |
|
| 4479 | + {
|
|
| 4480 | + $srctemplatepath=$record['fullname']; |
|
| 4481 | + break; |
|
| 4482 | + } |
|
| 4483 | + } |
|
| 4484 | + } |
|
| 4485 | + |
|
| 4486 | + if (empty($srctemplatepath)) |
|
| 4487 | + {
|
|
| 4488 | + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotDefined'; |
|
| 4489 | + return -1; |
|
| 4490 | + } |
|
| 4491 | + } |
|
| 4492 | + |
|
| 4493 | + if ($obj->type == 'odt' && ! empty($srctemplatepath)) |
|
| 4494 | + {
|
|
| 4495 | + if (! dol_is_file($srctemplatepath)) |
|
| 4496 | + {
|
|
| 4497 | + $this->error='ErrorGenerationAskedForOdtTemplateWithSrcFileNotFound'; |
|
| 4498 | + return -1; |
|
| 4499 | + } |
|
| 4500 | + } |
|
| 4501 | + |
|
| 4502 | + // We save charset_output to restore it because write_file can change it if needed for |
|
| 4503 | + // output format that does not support UTF8. |
|
| 4504 | + $sav_charset_output=$outputlangs->charset_output; |
|
| 4505 | + |
|
| 4506 | + if (in_array(get_class($this), array('Adherent')))
|
|
| 4507 | + {
|
|
| 4508 | + $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
|
| 4509 | + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
|
| 4510 | + } |
|
| 4511 | + else |
|
| 4512 | + {
|
|
| 4513 | + $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
| 4514 | + } |
|
| 4515 | + // After call of write_file $obj->result['fullpath'] is set with generated file. It will be used to update the ECM database index. |
|
| 4516 | + |
|
| 4517 | + if ($resultwritefile > 0) |
|
| 4518 | + {
|
|
| 4519 | + $outputlangs->charset_output=$sav_charset_output; |
|
| 4520 | + |
|
| 4521 | + // We delete old preview |
|
| 4522 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
| 4523 | + dol_delete_preview($this); |
|
| 4524 | + |
|
| 4525 | + // Index file in database |
|
| 4526 | + if (! empty($obj->result['fullpath'])) |
|
| 4527 | + {
|
|
| 4528 | + $destfull = $obj->result['fullpath']; |
|
| 4529 | + $upload_dir = dirname($destfull); |
|
| 4530 | + $destfile = basename($destfull); |
|
| 4531 | + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
|
| 4532 | + |
|
| 4533 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4534 | + {
|
|
| 4535 | + $filename = basename($destfile); |
|
| 4536 | + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
|
| 4537 | + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
|
| 4538 | + |
|
| 4539 | + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; |
|
| 4540 | + $ecmfile=new EcmFiles($this->db); |
|
| 4541 | + $result = $ecmfile->fetch(0, '', ($rel_dir?$rel_dir.'/':'').$filename); |
|
| 4542 | + |
|
| 4543 | + // Set the public "share" key |
|
| 4544 | + $setsharekey = false; |
|
| 4545 | + if ($this->element == 'propal') |
|
| 4546 | + {
|
|
| 4547 | + $useonlinesignature = Globals::$conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
|
| 4548 | + if ($useonlinesignature) $setsharekey=true; |
|
| 4549 | + if (!empty(Globals::$conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4550 | + $setsharekey = true; |
|
| 4551 | + } |
|
| 4552 | + if ($this->element == 'commande' && !empty(Globals::$conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4553 | + $setsharekey = true; |
|
| 4554 | + if ($this->element == 'facture' && !empty(Globals::$conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4555 | + $setsharekey = true; |
|
| 4556 | + if ($this->element == 'bank_account' && !empty(Globals::$conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4557 | + $setsharekey = true; |
|
| 4558 | + |
|
| 4559 | + if ($setsharekey) |
|
| 4560 | + {
|
|
| 4561 | + if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4562 | + {
|
|
| 4563 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4564 | + $ecmfile->share = getRandomPassword(true); |
|
| 4565 | + } |
|
| 4566 | + } |
|
| 4567 | + |
|
| 4568 | + if ($result > 0) |
|
| 4569 | + {
|
|
| 4570 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4571 | + $ecmfile->fullpath_orig = ''; |
|
| 4572 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4573 | + $ecmfile->description = ''; // indexed content |
|
| 4574 | + $ecmfile->keyword = ''; // keyword content |
|
| 4575 | + $result = $ecmfile->update($user); |
|
| 4576 | + if ($result < 0) |
|
| 4577 | + {
|
|
| 4578 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4579 | + } |
|
| 4580 | + } |
|
| 4581 | + else |
|
| 4582 | + {
|
|
| 4583 | + $ecmfile->entity = Globals::$conf->entity; |
|
| 4584 | + $ecmfile->filepath = $rel_dir; |
|
| 4585 | + $ecmfile->filename = $filename; |
|
| 4586 | + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content |
|
| 4587 | + $ecmfile->fullpath_orig = ''; |
|
| 4588 | + $ecmfile->gen_or_uploaded = 'generated'; |
|
| 4589 | + $ecmfile->description = ''; // indexed content |
|
| 4590 | + $ecmfile->keyword = ''; // keyword content |
|
| 4591 | + $ecmfile->src_object_type = $this->table_element; |
|
| 4592 | + $ecmfile->src_object_id = $this->id; |
|
| 4593 | + |
|
| 4594 | + $result = $ecmfile->create($user); |
|
| 4595 | + if ($result < 0) |
|
| 4596 | + {
|
|
| 4597 | + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
|
| 4598 | + } |
|
| 4599 | + } |
|
| 4600 | + |
|
| 4601 | + /*$this->result['fullname']=$destfull; |
|
| 4602 | + $this->result['filepath']=$ecmfile->filepath; |
|
| 4603 | + $this->result['filename']=$ecmfile->filename;*/ |
|
| 4604 | + //var_dump($obj->update_main_doc_field);exit; |
|
| 4605 | + |
|
| 4606 | + // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
|
| 4607 | + $update_main_doc_field=0; |
|
| 4608 | + if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4609 | + if ($update_main_doc_field && ! empty($this->table_element)) |
|
| 4610 | + {
|
|
| 4611 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
|
| 4612 | + $sql.= ' WHERE rowid = '.$this->id; |
|
| 4613 | + $resql = $this->db->query($sql); |
|
| 4614 | + if (! $resql) dol_print_error($this->db); |
|
| 4615 | + } |
|
| 4616 | + } |
|
| 4617 | + } |
|
| 4618 | + else |
|
| 4619 | + {
|
|
| 4620 | + 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);
|
|
| 4621 | + } |
|
| 4622 | + |
|
| 4623 | + // Success in building document. We build meta file. |
|
| 4624 | + dol_meta_create($this); |
|
| 4625 | + |
|
| 4626 | + return 1; |
|
| 4627 | + } |
|
| 4628 | + else |
|
| 4629 | + {
|
|
| 4630 | + $outputlangs->charset_output=$sav_charset_output; |
|
| 4631 | + dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
|
| 4632 | + return -1; |
|
| 4633 | + } |
|
| 4634 | + } |
|
| 4635 | + else |
|
| 4636 | + {
|
|
| 4637 | + $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
|
| 4638 | + dol_print_error('',$this->error);
|
|
| 4639 | + return -1; |
|
| 4640 | + } |
|
| 4641 | + } |
|
| 4642 | + |
|
| 4643 | + /** |
|
| 4644 | + * Build thumb |
|
| 4645 | + * @TODO Move this into files.lib.php |
|
| 4646 | + * |
|
| 4647 | + * @param string $file Path file in UTF8 to original file to create thumbs from. |
|
| 4648 | + * @return void |
|
| 4649 | + */ |
|
| 4650 | + function addThumbs($file) |
|
| 4651 | + {
|
|
| 4652 | + global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini, $quality; |
|
| 4653 | + |
|
| 4654 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; // This define also $maxwidthsmall, $quality, ... |
|
| 4655 | + |
|
| 4656 | + $file_osencoded=dol_osencode($file); |
|
| 4657 | + if (file_exists($file_osencoded)) |
|
| 4658 | + {
|
|
| 4659 | + // Create small thumbs for company (Ratio is near 16/9) |
|
| 4660 | + // Used on logon for example |
|
| 4661 | + vignette($file_osencoded, $maxwidthsmall, $maxheightsmall, '_small', $quality); |
|
| 4662 | + |
|
| 4663 | + // Create mini thumbs for company (Ratio is near 16/9) |
|
| 4664 | + // Used on menu or for setup page for example |
|
| 4665 | + vignette($file_osencoded, $maxwidthmini, $maxheightmini, '_mini', $quality); |
|
| 4666 | + } |
|
| 4667 | + } |
|
| 4668 | + |
|
| 4669 | + |
|
| 4670 | + /* Functions common to commonobject and commonobjectline */ |
|
| 4671 | + |
|
| 4672 | + /* For default values */ |
|
| 4673 | + |
|
| 4674 | + /** |
|
| 4675 | + * Return the default value to use for a field when showing the create form of object. |
|
| 4676 | + * Return values in this order: |
|
| 4677 | + * 1) If parameter is available into POST, we return it first. |
|
| 4678 | + * 2) If not but an alternate value was provided as parameter of function, we return it. |
|
| 4679 | + * 3) If not but a constant Globals::$conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). |
|
| 4680 | + * 4) Return value found into database (TODO No yet implemented) |
|
| 4681 | + * |
|
| 4682 | + * @param string $fieldname Name of field |
|
| 4683 | + * @param string $alternatevalue Alternate value to use |
|
| 4684 | + * @return string|string[] Default value (can be an array if the GETPOST return an array) |
|
| 4685 | + **/ |
|
| 4686 | + function getDefaultCreateValueFor($fieldname, $alternatevalue=null) |
|
| 4687 | + {
|
|
| 4688 | + global $conf, $_POST; |
|
| 4689 | + |
|
| 4690 | + // If param here has been posted, we use this value first. |
|
| 4691 | + if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 4692 | + |
|
| 4693 | + if (isset($alternatevalue)) return $alternatevalue; |
|
| 4694 | + |
|
| 4695 | + $newelement=$this->element; |
|
| 4696 | + if ($newelement == 'facture') $newelement='invoice'; |
|
| 4697 | + if ($newelement == 'commande') $newelement='order'; |
|
| 4698 | + if (empty($newelement)) |
|
| 4699 | + {
|
|
| 4700 | + dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
|
| 4701 | + return ''; |
|
| 4702 | + } |
|
| 4703 | + |
|
| 4704 | + $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
|
| 4705 | + //var_dump($keyforfieldname); |
|
| 4706 | + if (isset(Globals::$conf->global->$keyforfieldname)) |
|
| 4707 | + return Globals::$conf->global->$keyforfieldname; |
|
| 4708 | + |
|
| 4709 | + // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
|
| 4710 | + } |
|
| 4711 | + |
|
| 4712 | + |
|
| 4713 | + /* For triggers */ |
|
| 4714 | + |
|
| 4715 | + |
|
| 4716 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4717 | + /** |
|
| 4718 | + * Call trigger based on this instance. |
|
| 4719 | + * Some context information may also be provided into array property this->context. |
|
| 4720 | + * NB: Error from trigger are stacked in interface->errors |
|
| 4721 | + * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. |
|
| 4722 | + * |
|
| 4723 | + * @param string $trigger_name trigger's name to execute |
|
| 4724 | + * @param User $user Object user |
|
| 4725 | + * @return int Result of run_triggers |
|
| 4726 | + */ |
|
| 4727 | + function call_trigger($trigger_name, $user) |
|
| 4728 | + {
|
|
| 4729 | + // phpcs:enable |
|
| 4730 | + global $langs,$conf; |
|
| 4731 | + |
|
| 4732 | + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; |
|
| 4733 | + $interface=new Interfaces($this->db); |
|
| 4734 | + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); |
|
| 4735 | + |
|
| 4736 | + if ($result < 0) |
|
| 4737 | + {
|
|
| 4738 | + if (!empty($this->errors)) |
|
| 4739 | + {
|
|
| 4740 | + $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. |
|
| 4741 | + } |
|
| 4742 | + else |
|
| 4743 | + {
|
|
| 4744 | + $this->errors=$interface->errors; |
|
| 4745 | + } |
|
| 4746 | + } |
|
| 4747 | + return $result; |
|
| 4748 | + } |
|
| 4749 | + |
|
| 4750 | + |
|
| 4751 | + /* Functions for extrafields */ |
|
| 4752 | + |
|
| 4753 | + |
|
| 4754 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 4755 | + /** |
|
| 4756 | + * Function to get extra fields of an object into $this->array_options |
|
| 4757 | + * This method is in most cases called by method fetch of objects but you can call it separately. |
|
| 4758 | + * |
|
| 4759 | + * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. |
|
| 4760 | + * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. |
|
| 4761 | + * @return int <0 if error, 0 if no values of extrafield to find nor found, 1 if an attribute is found and value loaded |
|
| 4762 | + */ |
|
| 4763 | + function fetch_optionals($rowid=null, $optionsArray=null) |
|
| 4764 | + {
|
|
| 4765 | + // phpcs:enable |
|
| 4766 | + if (empty($rowid)) {
|
|
| 4767 | + $rowid = $this->id; |
|
| 4768 | + } |
|
| 4769 | + |
|
| 4770 | + // To avoid SQL errors. Probably not the better solution though |
|
| 4771 | + if (!$this->table_element) {
|
|
| 4772 | + return 0; |
|
| 4773 | + } |
|
| 4774 | + |
|
| 4775 | + $this->array_options=array(); |
|
| 4776 | + |
|
| 4777 | + if (! is_array($optionsArray)) |
|
| 4778 | + {
|
|
| 4779 | + // If $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. |
|
| 4780 | + // TODO Use of existing $extrafield is not yet ready (must mutualize code that use extrafields in form first) |
|
| 4781 | + // global $extrafields; |
|
| 4782 | + //if (! is_object($extrafields)) |
|
| 4783 | + //{
|
|
| 4784 | + // require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4785 | + $extrafields = new AlExtraFields(); |
|
| 4786 | + //} |
|
| 4787 | + |
|
| 4788 | + // Load array of extrafields for elementype = $this->table_element |
|
| 4789 | + if (empty($extrafields->attributes[$this->table_element]['loaded'])) |
|
| 4790 | + {
|
|
| 4791 | + $extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4792 | + } |
|
| 4793 | + $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
|
| 4794 | + } |
|
| 4795 | + else |
|
| 4796 | + {
|
|
| 4797 | + // global $extrafields; |
|
| 4798 | + dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
|
|
| 4799 | + } |
|
| 4800 | + |
|
| 4801 | + $table_element = $this->table_element; |
|
| 4802 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4803 | + |
|
| 4804 | + // Request to get complementary values |
|
| 4805 | + if (is_array($optionsArray) && count($optionsArray) > 0) |
|
| 4806 | + {
|
|
| 4807 | + $sql = "SELECT rowid"; |
|
| 4808 | + foreach ($optionsArray as $name => $label) |
|
| 4809 | + {
|
|
| 4810 | + if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') |
|
| 4811 | + {
|
|
| 4812 | + $sql.= ", ".$name; |
|
| 4813 | + } |
|
| 4814 | + } |
|
| 4815 | + $sql.= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; |
|
| 4816 | + $sql.= " WHERE fk_object = ".$rowid; |
|
| 4817 | + |
|
| 4818 | + //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose |
|
| 4819 | + $resql=$this->db->query($sql); |
|
| 4820 | + if ($resql) |
|
| 4821 | + {
|
|
| 4822 | + $this->array_options = array(); |
|
| 4823 | + $numrows=$this->db->num_rows($resql); |
|
| 4824 | + if ($numrows) |
|
| 4825 | + {
|
|
| 4826 | + $tab = $this->db->fetch_array($resql); |
|
| 4827 | + |
|
| 4828 | + foreach ($tab as $key => $value) |
|
| 4829 | + {
|
|
| 4830 | + // 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) |
|
| 4831 | + if ($key != 'rowid' && $key != 'tms' && $key != 'fk_member' && ! is_int($key)) |
|
| 4832 | + {
|
|
| 4833 | + // we can add this attribute to object |
|
| 4834 | + if (! empty($extrafields) && in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date','datetime')))
|
|
| 4835 | + {
|
|
| 4836 | + //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
|
| 4837 | + $this->array_options["options_".$key]=$this->db->jdate($value); |
|
| 4838 | + } |
|
| 4839 | + else |
|
| 4840 | + {
|
|
| 4841 | + $this->array_options["options_".$key]=$value; |
|
| 4842 | + } |
|
| 4843 | + |
|
| 4844 | + //var_dump('key '.$key.' '.$value.' type='.$extrafields->attributes[$this->table_element]['type'][$key].' '.$this->array_options["options_".$key]);
|
|
| 4845 | + } |
|
| 4846 | + } |
|
| 4847 | + } |
|
| 4848 | + |
|
| 4849 | + $this->db->free($resql); |
|
| 4850 | + |
|
| 4851 | + if ($numrows) return $numrows; |
|
| 4852 | + else return 0; |
|
| 4853 | + } |
|
| 4854 | + else |
|
| 4855 | + {
|
|
| 4856 | + dol_print_error($this->db); |
|
| 4857 | + return -1; |
|
| 4858 | + } |
|
| 4859 | + } |
|
| 4860 | + return 0; |
|
| 4861 | + } |
|
| 4862 | + |
|
| 4863 | + /** |
|
| 4864 | + * Delete all extra fields values for the current object. |
|
| 4865 | + * |
|
| 4866 | + * @return int <0 if KO, >0 if OK |
|
| 4867 | + */ |
|
| 4868 | + function deleteExtraFields() |
|
| 4869 | + {
|
|
| 4870 | + $this->db->begin(); |
|
| 4871 | + |
|
| 4872 | + $table_element = $this->table_element; |
|
| 4873 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 4874 | + |
|
| 4875 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 4876 | + dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
|
| 4877 | + $resql=$this->db->query($sql_del); |
|
| 4878 | + if (! $resql) |
|
| 4879 | + {
|
|
| 4880 | + $this->error=$this->db->lasterror(); |
|
| 4881 | + $this->db->rollback(); |
|
| 4882 | + return -1; |
|
| 4883 | + } |
|
| 4884 | + else |
|
| 4885 | + {
|
|
| 4886 | + $this->db->commit(); |
|
| 4887 | + return 1; |
|
| 4888 | + } |
|
| 4889 | + } |
|
| 4890 | + |
|
| 4891 | + /** |
|
| 4892 | + * Add/Update all extra fields values for the current object. |
|
| 4893 | + * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 4894 | + * This function delete record with all extrafields and insert them again from the array $this->array_options. |
|
| 4895 | + * |
|
| 4896 | + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 4897 | + * @param User $userused Object user |
|
| 4898 | + * @return int -1=error, O=did nothing, 1=OK |
|
| 4899 | + * @see updateExtraField, setValueFrom |
|
| 4900 | + */ |
|
| 4901 | + function insertExtraFields($trigger='', $userused=null) |
|
| 4902 | + {
|
|
| 4903 | + global $conf,$langs,$user; |
|
| 4904 | + |
|
| 4905 | + if (empty($userused)) $userused=$user; |
|
| 4906 | + |
|
| 4907 | + $error=0; |
|
| 4908 | + |
|
| 4909 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 4910 | + return 0; // For avoid conflicts if trigger used |
|
| 4911 | + |
|
| 4912 | + if (! empty($this->array_options)) |
|
| 4913 | + {
|
|
| 4914 | + // Check parameters |
|
| 4915 | + $langs->load('admin');
|
|
| 4916 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 4917 | + $extrafields = new AlExtraFields($this->db); |
|
| 4918 | + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 4919 | + |
|
| 4920 | + //Eliminate copied source object extra_fields that do not exist in target object |
|
| 4921 | + $new_array_options=array(); |
|
| 4922 | + foreach ($this->array_options as $key => $value) {
|
|
| 4923 | + if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4924 | + $new_array_options[$key] = $value; |
|
| 4925 | + elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 4926 | + $new_array_options['options_'.$key] = $value; |
|
| 4927 | + } |
|
| 4928 | + |
|
| 4929 | + foreach($new_array_options as $key => $value) |
|
| 4930 | + {
|
|
| 4931 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 4932 | + $attributeType = $extrafields->attributes[$this->table_element]['type'][$attributeKey]; |
|
| 4933 | + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$attributeKey]; |
|
| 4934 | + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$attributeKey]; |
|
| 4935 | + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$attributeKey]; |
|
| 4936 | + |
|
| 4937 | + if ($attributeRequired) |
|
| 4938 | + {
|
|
| 4939 | + $mandatorypb=false; |
|
| 4940 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4941 | + if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 4942 | + if ($mandatorypb) |
|
| 4943 | + {
|
|
| 4944 | + dol_syslog($this->error); |
|
| 4945 | + $this->errors[]=$langs->trans('ErrorFieldRequired', $attributeLabel);
|
|
| 4946 | + return -1; |
|
| 4947 | + } |
|
| 4948 | + } |
|
| 4949 | + |
|
| 4950 | + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 4951 | + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 4952 | + |
|
| 4953 | + switch ($attributeType) |
|
| 4954 | + {
|
|
| 4955 | + case 'int': |
|
| 4956 | + if (!is_numeric($value) && $value!='') |
|
| 4957 | + {
|
|
| 4958 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4959 | + return -1; |
|
| 4960 | + } |
|
| 4961 | + elseif ($value=='') |
|
| 4962 | + {
|
|
| 4963 | + $new_array_options[$key] = null; |
|
| 4964 | + } |
|
| 4965 | + break; |
|
| 4966 | + case 'double': |
|
| 4967 | + $value = price2num($value); |
|
| 4968 | + if (!is_numeric($value) && $value!='') |
|
| 4969 | + {
|
|
| 4970 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 4971 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 4972 | + return -1; |
|
| 4973 | + } |
|
| 4974 | + elseif ($value=='') |
|
| 4975 | + {
|
|
| 4976 | + $new_array_options[$key] = null; |
|
| 4977 | + } |
|
| 4978 | + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 4979 | + $new_array_options[$key] = $value; |
|
| 4980 | + break; |
|
| 4981 | + /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 4982 | + if ($value=='-1') |
|
| 4983 | + {
|
|
| 4984 | + $this->array_options[$key] = null; |
|
| 4985 | + } |
|
| 4986 | + break;*/ |
|
| 4987 | + case 'password': |
|
| 4988 | + $algo=''; |
|
| 4989 | + if ($this->array_options[$key] != '' && is_array($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options'])) |
|
| 4990 | + {
|
|
| 4991 | + // If there is an encryption choice, we use it to crypt data before insert |
|
| 4992 | + $tmparrays = array_keys($extrafields->attributes[$this->table_element]['param'][$attributeKey]['options']); |
|
| 4993 | + $algo=reset($tmparrays); |
|
| 4994 | + if ($algo != '') |
|
| 4995 | + {
|
|
| 4996 | + //global $action; // $action may be 'create', 'update', 'update_extras'... |
|
| 4997 | + //var_dump($action); |
|
| 4998 | + //var_dump($this->oldcopy);exit; |
|
| 4999 | + 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 |
|
| 5000 | + {
|
|
| 5001 | + //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
|
| 5002 | + 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. |
|
| 5003 | + {
|
|
| 5004 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5005 | + } |
|
| 5006 | + else |
|
| 5007 | + {
|
|
| 5008 | + // var_dump($algo); |
|
| 5009 | + $newvalue = dol_hash($this->array_options[$key], $algo); |
|
| 5010 | + $new_array_options[$key] = $newvalue; |
|
| 5011 | + } |
|
| 5012 | + } |
|
| 5013 | + else |
|
| 5014 | + {
|
|
| 5015 | + $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5016 | + } |
|
| 5017 | + } |
|
| 5018 | + } |
|
| 5019 | + else // Common usage |
|
| 5020 | + {
|
|
| 5021 | + $new_array_options[$key] = $this->array_options[$key]; |
|
| 5022 | + } |
|
| 5023 | + break; |
|
| 5024 | + case 'price': |
|
| 5025 | + $new_array_options[$key] = price2num($this->array_options[$key]); |
|
| 5026 | + break; |
|
| 5027 | + case 'date': |
|
| 5028 | + $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5029 | + break; |
|
| 5030 | + case 'datetime': |
|
| 5031 | + // If data is a string instead of a timestamp, we convert it |
|
| 5032 | + if (! is_int($this->array_options[$key])) {
|
|
| 5033 | + $this->array_options[$key] = strtotime($this->array_options[$key]); |
|
| 5034 | + } |
|
| 5035 | + $new_array_options[$key] = $this->db->idate($this->array_options[$key]); |
|
| 5036 | + break; |
|
| 5037 | + case 'link': |
|
| 5038 | + $param_list=array_keys($attributeParam['options']); |
|
| 5039 | + // 0 : ObjectName |
|
| 5040 | + // 1 : classPath |
|
| 5041 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5042 | + dol_include_once($InfoFieldList[1]); |
|
| 5043 | + if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
|
| 5044 | + {
|
|
| 5045 | + if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5046 | + {
|
|
| 5047 | + $new_array_options[$key]=''; |
|
| 5048 | + } |
|
| 5049 | + elseif ($value) |
|
| 5050 | + {
|
|
| 5051 | + $object = new $InfoFieldList[0]($this->db); |
|
| 5052 | + if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5053 | + else $res=$object->fetch('',$value);
|
|
| 5054 | + |
|
| 5055 | + if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5056 | + else |
|
| 5057 | + {
|
|
| 5058 | + $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
|
| 5059 | + $this->db->rollback(); |
|
| 5060 | + return -1; |
|
| 5061 | + } |
|
| 5062 | + } |
|
| 5063 | + } |
|
| 5064 | + else |
|
| 5065 | + {
|
|
| 5066 | + dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 5067 | + } |
|
| 5068 | + break; |
|
| 5069 | + } |
|
| 5070 | + } |
|
| 5071 | + |
|
| 5072 | + $this->db->begin(); |
|
| 5073 | + |
|
| 5074 | + $table_element = $this->table_element; |
|
| 5075 | + if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5076 | + |
|
| 5077 | + $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
|
| 5078 | + dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
|
| 5079 | + $this->db->query($sql_del); |
|
| 5080 | + |
|
| 5081 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; |
|
| 5082 | + foreach($new_array_options as $key => $value) |
|
| 5083 | + {
|
|
| 5084 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5085 | + // Add field of attribut |
|
| 5086 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5087 | + $sql.=",".$attributeKey; |
|
| 5088 | + } |
|
| 5089 | + $sql .= ") VALUES (".$this->id;
|
|
| 5090 | + |
|
| 5091 | + foreach($new_array_options as $key => $value) |
|
| 5092 | + {
|
|
| 5093 | + $attributeKey = substr($key,8); // Remove 'options_' prefix |
|
| 5094 | + // Add field of attribute |
|
| 5095 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5096 | + {
|
|
| 5097 | + if ($new_array_options[$key] != '') |
|
| 5098 | + {
|
|
| 5099 | + $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5100 | + } |
|
| 5101 | + else |
|
| 5102 | + {
|
|
| 5103 | + $sql.=",null"; |
|
| 5104 | + } |
|
| 5105 | + } |
|
| 5106 | + } |
|
| 5107 | + $sql.=")"; |
|
| 5108 | + |
|
| 5109 | + dol_syslog(get_class($this)."::insertExtraFields insert", LOG_DEBUG); |
|
| 5110 | + $resql = $this->db->query($sql); |
|
| 5111 | + if (! $resql) |
|
| 5112 | + {
|
|
| 5113 | + $this->error=$this->db->lasterror(); |
|
| 5114 | + $error++; |
|
| 5115 | + } |
|
| 5116 | + |
|
| 5117 | + if (! $error && $trigger) |
|
| 5118 | + {
|
|
| 5119 | + // Call trigger |
|
| 5120 | + $this->context=array('extrafieldaddupdate'=>1);
|
|
| 5121 | + $result=$this->call_trigger($trigger, $userused); |
|
| 5122 | + if ($result < 0) $error++; |
|
| 5123 | + // End call trigger |
|
| 5124 | + } |
|
| 5125 | + |
|
| 5126 | + if ($error) |
|
| 5127 | + {
|
|
| 5128 | + $this->db->rollback(); |
|
| 5129 | + return -1; |
|
| 5130 | + } |
|
| 5131 | + else |
|
| 5132 | + {
|
|
| 5133 | + $this->db->commit(); |
|
| 5134 | + return 1; |
|
| 5135 | + } |
|
| 5136 | + } |
|
| 5137 | + else return 0; |
|
| 5138 | + } |
|
| 5139 | + |
|
| 5140 | + /** |
|
| 5141 | + * Update an extra field value for the current object. |
|
| 5142 | + * Data to describe values to update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...)
|
|
| 5143 | + * |
|
| 5144 | + * @param string $key Key of the extrafield (without starting 'options_') |
|
| 5145 | + * @param string $trigger If defined, call also the trigger (for example COMPANY_MODIFY) |
|
| 5146 | + * @param User $userused Object user |
|
| 5147 | + * @return int -1=error, O=did nothing, 1=OK |
|
| 5148 | + * @see setValueFrom, insertExtraFields |
|
| 5149 | + */ |
|
| 5150 | + function updateExtraField($key, $trigger=null, $userused=null) |
|
| 5151 | + {
|
|
| 5152 | + global $conf,$langs,$user; |
|
| 5153 | + |
|
| 5154 | + if (empty($userused)) $userused=$user; |
|
| 5155 | + |
|
| 5156 | + $error=0; |
|
| 5157 | + |
|
| 5158 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 5159 | + return 0; // For avoid conflicts if trigger used |
|
| 5160 | + |
|
| 5161 | + if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
|
| 5162 | + {
|
|
| 5163 | + // Check parameters |
|
| 5164 | + $langs->load('admin');
|
|
| 5165 | + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
| 5166 | + $extrafields = new AlExtraFields($this->db); |
|
| 5167 | + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); |
|
| 5168 | + |
|
| 5169 | + $value=$this->array_options["options_".$key]; |
|
| 5170 | + |
|
| 5171 | + $attributeType = $extrafields->attributes[$this->table_element]['type'][$key]; |
|
| 5172 | + $attributeLabel = $extrafields->attributes[$this->table_element]['label'][$key]; |
|
| 5173 | + $attributeParam = $extrafields->attributes[$this->table_element]['param'][$key]; |
|
| 5174 | + $attributeRequired = $extrafields->attributes[$this->table_element]['required'][$key]; |
|
| 5175 | + |
|
| 5176 | + //dol_syslog("attributeLabel=".$attributeLabel, LOG_DEBUG);
|
|
| 5177 | + //dol_syslog("attributeType=".$attributeType, LOG_DEBUG);
|
|
| 5178 | + |
|
| 5179 | + switch ($attributeType) |
|
| 5180 | + {
|
|
| 5181 | + case 'int': |
|
| 5182 | + if (!is_numeric($value) && $value!='') |
|
| 5183 | + {
|
|
| 5184 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
|
| 5185 | + return -1; |
|
| 5186 | + } |
|
| 5187 | + elseif ($value=='') |
|
| 5188 | + {
|
|
| 5189 | + $this->array_options["options_".$key] = null; |
|
| 5190 | + } |
|
| 5191 | + break; |
|
| 5192 | + case 'double': |
|
| 5193 | + $value = price2num($value); |
|
| 5194 | + if (!is_numeric($value) && $value!='') |
|
| 5195 | + {
|
|
| 5196 | + dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
|
| 5197 | + $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
|
| 5198 | + return -1; |
|
| 5199 | + } |
|
| 5200 | + elseif ($value=='') |
|
| 5201 | + {
|
|
| 5202 | + $this->array_options["options_".$key] = null; |
|
| 5203 | + } |
|
| 5204 | + //dol_syslog("double value"." sur ".$attributeLabel."(".$value." is '".$attributeType."')", LOG_DEBUG);
|
|
| 5205 | + $this->array_options["options_".$key] = $value; |
|
| 5206 | + break; |
|
| 5207 | + /*case 'select': // Not required, we chosed value='0' for undefined values |
|
| 5208 | + if ($value=='-1') |
|
| 5209 | + {
|
|
| 5210 | + $this->array_options[$key] = null; |
|
| 5211 | + } |
|
| 5212 | + break;*/ |
|
| 5213 | + case 'price': |
|
| 5214 | + $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); |
|
| 5215 | + break; |
|
| 5216 | + case 'date': |
|
| 5217 | + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5218 | + break; |
|
| 5219 | + case 'datetime': |
|
| 5220 | + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); |
|
| 5221 | + break; |
|
| 5222 | + case 'link': |
|
| 5223 | + $param_list=array_keys($attributeParam['options']); |
|
| 5224 | + // 0 : ObjectName |
|
| 5225 | + // 1 : classPath |
|
| 5226 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5227 | + dol_include_once($InfoFieldList[1]); |
|
| 5228 | + if ($value) |
|
| 5229 | + {
|
|
| 5230 | + $object = new $InfoFieldList[0]($this->db); |
|
| 5231 | + $object->fetch(0,$value); |
|
| 5232 | + $this->array_options["options_".$key]=$object->id; |
|
| 5233 | + } |
|
| 5234 | + break; |
|
| 5235 | + } |
|
| 5236 | + |
|
| 5237 | + $this->db->begin(); |
|
| 5238 | + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; |
|
| 5239 | + $sql .= " WHERE fk_object = ".$this->id; |
|
| 5240 | + $resql = $this->db->query($sql); |
|
| 5241 | + if (! $resql) |
|
| 5242 | + {
|
|
| 5243 | + $error++; |
|
| 5244 | + $this->error=$this->db->lasterror(); |
|
| 5245 | + } |
|
| 5246 | + |
|
| 5247 | + if (! $error && $trigger) |
|
| 5248 | + {
|
|
| 5249 | + // Call trigger |
|
| 5250 | + $this->context=array('extrafieldupdate'=>1);
|
|
| 5251 | + $result=$this->call_trigger($trigger, $userused); |
|
| 5252 | + if ($result < 0) $error++; |
|
| 5253 | + // End call trigger |
|
| 5254 | + } |
|
| 5255 | + |
|
| 5256 | + if ($error) |
|
| 5257 | + {
|
|
| 5258 | + dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
|
| 5259 | + $this->db->rollback(); |
|
| 5260 | + return -1; |
|
| 5261 | + } |
|
| 5262 | + else |
|
| 5263 | + {
|
|
| 5264 | + $this->db->commit(); |
|
| 5265 | + return 1; |
|
| 5266 | + } |
|
| 5267 | + } |
|
| 5268 | + else return 0; |
|
| 5269 | + } |
|
| 5270 | + |
|
| 5271 | + |
|
| 5272 | + /** |
|
| 5273 | + * Return HTML string to put an input field into a page |
|
| 5274 | + * Code very similar with showInputField of extra fields |
|
| 5275 | + * |
|
| 5276 | + * @param array $val Array of properties for field to show |
|
| 5277 | + * @param string $key Key of attribute |
|
| 5278 | + * @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) |
|
| 5279 | + * @param string $moreparam To add more parameters on html input tag |
|
| 5280 | + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5281 | + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5282 | + * @param string|int $morecss Value for css to define style/length of field. May also be a numeric. |
|
| 5283 | + * @return string |
|
| 5284 | + */ |
|
| 5285 | + function showInputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $morecss=0) |
|
| 5286 | + {
|
|
| 5287 | + global $conf,$langs,$form; |
|
| 5288 | + |
|
| 5289 | + if (! is_object($form)) |
|
| 5290 | + {
|
|
| 5291 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5292 | + $form=new Form($this->db); |
|
| 5293 | + } |
|
| 5294 | + |
|
| 5295 | + $val=$this->fields[$key]; |
|
| 5296 | + |
|
| 5297 | + $out=''; |
|
| 5298 | + $type=''; |
|
| 5299 | + $param = array(); |
|
| 5300 | + $param['options']=array(); |
|
| 5301 | + $size =$this->fields[$key]['size']; |
|
| 5302 | + // Because we work on extrafields |
|
| 5303 | + if(preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)){
|
|
| 5304 | + $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5305 | + $type ='link'; |
|
| 5306 | + } elseif(preg_match('/^link:(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5307 | + $param['options']=array($reg[1].':'.$reg[2]=>'N'); |
|
| 5308 | + $type ='link'; |
|
| 5309 | + } elseif(preg_match('/^sellist:(.*):(.*):(.*):(.*)/i', $val['type'], $reg)) {
|
|
| 5310 | + $param['options']=array($reg[1].':'.$reg[2].':'.$reg[3].':'.$reg[4]=>'N'); |
|
| 5311 | + $type ='sellist'; |
|
| 5312 | + } elseif(preg_match('/varchar\((\d+)\)/', $val['type'],$reg)) {
|
|
| 5313 | + $param['options']=array(); |
|
| 5314 | + $type ='varchar'; |
|
| 5315 | + $size=$reg[1]; |
|
| 5316 | + } elseif(preg_match('/varchar/', $val['type'])) {
|
|
| 5317 | + $param['options']=array(); |
|
| 5318 | + $type ='varchar'; |
|
| 5319 | + } elseif(is_array($this->fields[$key]['arrayofkeyval'])) {
|
|
| 5320 | + $param['options']=$this->fields[$key]['arrayofkeyval']; |
|
| 5321 | + $type ='select'; |
|
| 5322 | + } else {
|
|
| 5323 | + $param['options']=array(); |
|
| 5324 | + $type =$this->fields[$key]['type']; |
|
| 5325 | + } |
|
| 5326 | + |
|
| 5327 | + $label=$this->fields[$key]['label']; |
|
| 5328 | + //$elementtype=$this->fields[$key]['elementtype']; // Seems not used |
|
| 5329 | + $default=$this->fields[$key]['default']; |
|
| 5330 | + $computed=$this->fields[$key]['computed']; |
|
| 5331 | + $unique=$this->fields[$key]['unique']; |
|
| 5332 | + $required=$this->fields[$key]['required']; |
|
| 5333 | + |
|
| 5334 | + $langfile=$this->fields[$key]['langfile']; |
|
| 5335 | + $list=$this->fields[$key]['list']; |
|
| 5336 | + $hidden=abs($this->fields[$key]['visible'])!=1?1:0; |
|
| 5337 | + |
|
| 5338 | + $objectid = $this->id; |
|
| 5339 | + |
|
| 5340 | + |
|
| 5341 | + if ($computed) |
|
| 5342 | + {
|
|
| 5343 | + if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5344 | + else return ''; |
|
| 5345 | + } |
|
| 5346 | + |
|
| 5347 | + |
|
| 5348 | + // Use in priority showsize from parameters, then $val['css'] then autodefine |
|
| 5349 | + if (empty($morecss) && ! empty($val['css'])) |
|
| 5350 | + {
|
|
| 5351 | + $showsize = $val['css']; |
|
| 5352 | + } |
|
| 5353 | + if (empty($morecss)) |
|
| 5354 | + {
|
|
| 5355 | + if ($type == 'date') |
|
| 5356 | + {
|
|
| 5357 | + $morecss = 'minwidth100imp'; |
|
| 5358 | + } |
|
| 5359 | + elseif ($type == 'datetime') |
|
| 5360 | + {
|
|
| 5361 | + $morecss = 'minwidth200imp'; |
|
| 5362 | + } |
|
| 5363 | + elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5364 | + {
|
|
| 5365 | + $morecss = 'maxwidth75'; |
|
| 5366 | + }elseif ($type == 'url') |
|
| 5367 | + {
|
|
| 5368 | + $morecss='minwidth400'; |
|
| 5369 | + } |
|
| 5370 | + elseif ($type == 'boolean') |
|
| 5371 | + {
|
|
| 5372 | + $morecss=''; |
|
| 5373 | + } |
|
| 5374 | + else |
|
| 5375 | + {
|
|
| 5376 | + if (round($size) < 12) |
|
| 5377 | + {
|
|
| 5378 | + $morecss = 'minwidth100'; |
|
| 5379 | + } |
|
| 5380 | + else if (round($size) <= 48) |
|
| 5381 | + {
|
|
| 5382 | + $morecss = 'minwidth200'; |
|
| 5383 | + } |
|
| 5384 | + else |
|
| 5385 | + {
|
|
| 5386 | + $morecss = 'minwidth400'; |
|
| 5387 | + } |
|
| 5388 | + } |
|
| 5389 | + } |
|
| 5390 | + |
|
| 5391 | + if (in_array($type,array('date','datetime')))
|
|
| 5392 | + {
|
|
| 5393 | + $tmp=explode(',',$size);
|
|
| 5394 | + $newsize=$tmp[0]; |
|
| 5395 | + |
|
| 5396 | + $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
|
| 5397 | + |
|
| 5398 | + // Do not show current date when field not required (see selectDate() method) |
|
| 5399 | + if (!$required && $value == '') $value = '-1'; |
|
| 5400 | + |
|
| 5401 | + // TODO Must also support $moreparam |
|
| 5402 | + $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
|
| 5403 | + } |
|
| 5404 | + elseif (in_array($type,array('int','integer')))
|
|
| 5405 | + {
|
|
| 5406 | + $tmp=explode(',',$size);
|
|
| 5407 | + $newsize=$tmp[0]; |
|
| 5408 | + $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:'').'>'; |
|
| 5409 | + } |
|
| 5410 | + elseif (preg_match('/varchar/', $type))
|
|
| 5411 | + {
|
|
| 5412 | + $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:'').'>'; |
|
| 5413 | + } |
|
| 5414 | + elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5415 | + {
|
|
| 5416 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5417 | + } |
|
| 5418 | + elseif ($type == 'text') |
|
| 5419 | + {
|
|
| 5420 | + if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5421 | + {
|
|
| 5422 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5423 | + $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
|
| 5424 | + $out=$doleditor->Create(1); |
|
| 5425 | + } |
|
| 5426 | + else |
|
| 5427 | + {
|
|
| 5428 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5429 | + } |
|
| 5430 | + } |
|
| 5431 | + elseif ($type == 'html') |
|
| 5432 | + {
|
|
| 5433 | + if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5434 | + {
|
|
| 5435 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5436 | + $doleditor = new DolEditor($keyprefix . $key . $keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty(Globals::$conf->fckeditor->enabled) && Globals::$conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); |
|
| 5437 | + $out=$doleditor->Create(1); |
|
| 5438 | + } |
|
| 5439 | + else |
|
| 5440 | + {
|
|
| 5441 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
|
| 5442 | + } |
|
| 5443 | + } |
|
| 5444 | + elseif ($type == 'boolean') |
|
| 5445 | + {
|
|
| 5446 | + $checked=''; |
|
| 5447 | + if (!empty($value)) {
|
|
| 5448 | + $checked=' checked value="1" '; |
|
| 5449 | + } else {
|
|
| 5450 | + $checked=' value="1" '; |
|
| 5451 | + } |
|
| 5452 | + $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
|
| 5453 | + } |
|
| 5454 | + elseif ($type == 'price') |
|
| 5455 | + {
|
|
| 5456 | + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5457 | + $value=price($value); |
|
| 5458 | + } |
|
| 5459 | + $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '> ' . $langs->getCurrencySymbol(Globals::$conf->currency); |
|
| 5460 | + } |
|
| 5461 | + elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5462 | + {
|
|
| 5463 | + if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
|
| 5464 | + $value=price($value); |
|
| 5465 | + } |
|
| 5466 | + $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
|
| 5467 | + } |
|
| 5468 | + elseif ($type == 'select') |
|
| 5469 | + {
|
|
| 5470 | + $out = ''; |
|
| 5471 | + if (!empty(Globals::$conf->use_javascript_ajax) && !empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
|
| 5472 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5473 | + $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5474 | + } |
|
| 5475 | + |
|
| 5476 | + $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5477 | + if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5478 | + foreach ($param['options'] as $key => $val) |
|
| 5479 | + {
|
|
| 5480 | + if ((string) $key == '') continue; |
|
| 5481 | + list($val, $parent) = explode('|', $val);
|
|
| 5482 | + $out.='<option value="'.$key.'"'; |
|
| 5483 | + $out.= (((string) $value == (string) $key)?' selected':''); |
|
| 5484 | + $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5485 | + $out.='>'.$val.'</option>'; |
|
| 5486 | + } |
|
| 5487 | + $out.='</select>'; |
|
| 5488 | + } |
|
| 5489 | + elseif ($type == 'sellist') |
|
| 5490 | + {
|
|
| 5491 | + $out = ''; |
|
| 5492 | + if (!empty(Globals::$conf->use_javascript_ajax) && !empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
|
| 5493 | + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
|
| 5494 | + $out.= ajax_combobox($keyprefix.$key.$keysuffix, array(), 0); |
|
| 5495 | + } |
|
| 5496 | + |
|
| 5497 | + $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5498 | + if (is_array($param['options'])) |
|
| 5499 | + {
|
|
| 5500 | + $param_list=array_keys($param['options']); |
|
| 5501 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5502 | + $parentName=''; |
|
| 5503 | + $parentField=''; |
|
| 5504 | + // 0 : tableName |
|
| 5505 | + // 1 : label field name |
|
| 5506 | + // 2 : key fields name (if differ of rowid) |
|
| 5507 | + // 3 : key field parent (for dependent lists) |
|
| 5508 | + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5509 | + $keyList=(empty($InfoFieldList[2])?'rowid':$InfoFieldList[2].' as rowid'); |
|
| 5510 | + |
|
| 5511 | + |
|
| 5512 | + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) |
|
| 5513 | + {
|
|
| 5514 | + if (strpos($InfoFieldList[4], 'extra.') !== false) |
|
| 5515 | + {
|
|
| 5516 | + $keyList='main.'.$InfoFieldList[2].' as rowid'; |
|
| 5517 | + } else {
|
|
| 5518 | + $keyList=$InfoFieldList[2].' as rowid'; |
|
| 5519 | + } |
|
| 5520 | + } |
|
| 5521 | + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) |
|
| 5522 | + {
|
|
| 5523 | + list($parentName, $parentField) = explode('|', $InfoFieldList[3]);
|
|
| 5524 | + $keyList.= ', '.$parentField; |
|
| 5525 | + } |
|
| 5526 | + |
|
| 5527 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5528 | + if (is_array($fields_label)) |
|
| 5529 | + {
|
|
| 5530 | + $keyList .=', '; |
|
| 5531 | + $keyList .= implode(', ', $fields_label);
|
|
| 5532 | + } |
|
| 5533 | + |
|
| 5534 | + $sqlwhere=''; |
|
| 5535 | + $sql = 'SELECT '.$keyList; |
|
| 5536 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 5537 | + if (!empty($InfoFieldList[4])) |
|
| 5538 | + {
|
|
| 5539 | + // can use SELECT request |
|
| 5540 | + if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5541 | + $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5542 | + } |
|
| 5543 | + |
|
| 5544 | + // current object id can be use into filter |
|
| 5545 | + if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5546 | + $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5547 | + } else {
|
|
| 5548 | + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5549 | + } |
|
| 5550 | + //We have to join on extrafield table |
|
| 5551 | + if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 5552 | + {
|
|
| 5553 | + $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
|
| 5554 | + $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
|
| 5555 | + } |
|
| 5556 | + else |
|
| 5557 | + {
|
|
| 5558 | + $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
|
| 5559 | + } |
|
| 5560 | + } |
|
| 5561 | + else |
|
| 5562 | + {
|
|
| 5563 | + $sqlwhere.= ' WHERE 1=1'; |
|
| 5564 | + } |
|
| 5565 | + // Some tables may have field, some other not. For the moment we disable it. |
|
| 5566 | + if (in_array($InfoFieldList[0],array('tablewithentity')))
|
|
| 5567 | + {
|
|
| 5568 | + $sqlwhere .= ' AND entity = ' . Globals::$conf->entity; |
|
| 5569 | + } |
|
| 5570 | + $sql.=$sqlwhere; |
|
| 5571 | + //print $sql; |
|
| 5572 | + |
|
| 5573 | + $sql .= ' ORDER BY ' . implode(', ', $fields_label);
|
|
| 5574 | + |
|
| 5575 | + dol_syslog(get_class($this).'::showInputField type=sellist', LOG_DEBUG); |
|
| 5576 | + $resql = $this->db->query($sql); |
|
| 5577 | + if ($resql) |
|
| 5578 | + {
|
|
| 5579 | + $out.='<option value="0"> </option>'; |
|
| 5580 | + $num = $this->db->num_rows($resql); |
|
| 5581 | + $i = 0; |
|
| 5582 | + while ($i < $num) |
|
| 5583 | + {
|
|
| 5584 | + $labeltoshow=''; |
|
| 5585 | + $obj = $this->db->fetch_object($resql); |
|
| 5586 | + |
|
| 5587 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 5588 | + $notrans = false; |
|
| 5589 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 5590 | + if (is_array($fields_label)) |
|
| 5591 | + {
|
|
| 5592 | + $notrans = true; |
|
| 5593 | + foreach ($fields_label as $field_toshow) |
|
| 5594 | + {
|
|
| 5595 | + $labeltoshow.= $obj->$field_toshow.' '; |
|
| 5596 | + } |
|
| 5597 | + } |
|
| 5598 | + else |
|
| 5599 | + {
|
|
| 5600 | + $labeltoshow=$obj->{$InfoFieldList[1]};
|
|
| 5601 | + } |
|
| 5602 | + $labeltoshow=dol_trunc($labeltoshow,45); |
|
| 5603 | + |
|
| 5604 | + if ($value == $obj->rowid) |
|
| 5605 | + {
|
|
| 5606 | + foreach ($fields_label as $field_toshow) |
|
| 5607 | + {
|
|
| 5608 | + $translabel=$langs->trans($obj->$field_toshow); |
|
| 5609 | + if ($translabel!=$obj->$field_toshow) {
|
|
| 5610 | + $labeltoshow=dol_trunc($translabel,18).' '; |
|
| 5611 | + }else {
|
|
| 5612 | + $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
|
| 5613 | + } |
|
| 5614 | + } |
|
| 5615 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5616 | + } |
|
| 5617 | + else |
|
| 5618 | + {
|
|
| 5619 | + if (! $notrans) |
|
| 5620 | + {
|
|
| 5621 | + $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5622 | + if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 5623 | + $labeltoshow=dol_trunc($translabel,18); |
|
| 5624 | + } |
|
| 5625 | + else {
|
|
| 5626 | + $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
|
| 5627 | + } |
|
| 5628 | + } |
|
| 5629 | + if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 5630 | + if ($value==$obj->rowid) |
|
| 5631 | + {
|
|
| 5632 | + $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
|
| 5633 | + } |
|
| 5634 | + |
|
| 5635 | + if (!empty($InfoFieldList[3]) && $parentField) |
|
| 5636 | + {
|
|
| 5637 | + $parent = $parentName.':'.$obj->{$parentField};
|
|
| 5638 | + } |
|
| 5639 | + |
|
| 5640 | + $out.='<option value="'.$obj->rowid.'"'; |
|
| 5641 | + $out.= ($value==$obj->rowid?' selected':''); |
|
| 5642 | + $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
|
| 5643 | + $out.='>'.$labeltoshow.'</option>'; |
|
| 5644 | + } |
|
| 5645 | + |
|
| 5646 | + $i++; |
|
| 5647 | + } |
|
| 5648 | + $this->db->free($resql); |
|
| 5649 | + } |
|
| 5650 | + else {
|
|
| 5651 | + print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
|
| 5652 | + } |
|
| 5653 | + } |
|
| 5654 | + $out.='</select>'; |
|
| 5655 | + } |
|
| 5656 | + elseif ($type == 'checkbox') |
|
| 5657 | + {
|
|
| 5658 | + $value_arr=explode(',',$value);
|
|
| 5659 | + $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
|
| 5660 | + } |
|
| 5661 | + elseif ($type == 'radio') |
|
| 5662 | + {
|
|
| 5663 | + $out=''; |
|
| 5664 | + foreach ($param['options'] as $keyopt => $val) |
|
| 5665 | + {
|
|
| 5666 | + $out.='<input class="flat '.$morecss.'" type="radio" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:''); |
|
| 5667 | + $out.=' value="'.$keyopt.'"'; |
|
| 5668 | + $out.=' id="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'"'; |
|
| 5669 | + $out.= ($value==$keyopt?'checked':''); |
|
| 5670 | + $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
|
| 5671 | + } |
|
| 5672 | + } |
|
| 5673 | + elseif ($type == 'chkbxlst') |
|
| 5674 | + {
|
|
| 5675 | + if (is_array($value)) {
|
|
| 5676 | + $value_arr = $value; |
|
| 5677 | + } |
|
| 5678 | + else {
|
|
| 5679 | + $value_arr = explode(',', $value);
|
|
| 5680 | + } |
|
| 5681 | + |
|
| 5682 | + if (is_array($param['options'])) {
|
|
| 5683 | + $param_list = array_keys($param['options']); |
|
| 5684 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 5685 | + $parentName=''; |
|
| 5686 | + $parentField=''; |
|
| 5687 | + // 0 : tableName |
|
| 5688 | + // 1 : label field name |
|
| 5689 | + // 2 : key fields name (if differ of rowid) |
|
| 5690 | + // 3 : key field parent (for dependent lists) |
|
| 5691 | + // 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value |
|
| 5692 | + $keyList = (empty($InfoFieldList[2]) ? 'rowid' : $InfoFieldList[2] . ' as rowid'); |
|
| 5693 | + |
|
| 5694 | + if (count($InfoFieldList) > 3 && ! empty($InfoFieldList[3])) {
|
|
| 5695 | + list ( $parentName, $parentField ) = explode('|', $InfoFieldList[3]);
|
|
| 5696 | + $keyList .= ', ' . $parentField; |
|
| 5697 | + } |
|
| 5698 | + if (count($InfoFieldList) > 4 && ! empty($InfoFieldList[4])) {
|
|
| 5699 | + if (strpos($InfoFieldList[4], 'extra.') !== false) {
|
|
| 5700 | + $keyList = 'main.' . $InfoFieldList[2] . ' as rowid'; |
|
| 5701 | + } else {
|
|
| 5702 | + $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 5703 | + } |
|
| 5704 | + } |
|
| 5705 | + |
|
| 5706 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5707 | + if (is_array($fields_label)) {
|
|
| 5708 | + $keyList .= ', '; |
|
| 5709 | + $keyList .= implode(', ', $fields_label);
|
|
| 5710 | + } |
|
| 5711 | + |
|
| 5712 | + $sqlwhere = ''; |
|
| 5713 | + $sql = 'SELECT ' . $keyList; |
|
| 5714 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 5715 | + if (! empty($InfoFieldList[4])) {
|
|
| 5716 | + |
|
| 5717 | + // can use SELECT request |
|
| 5718 | + if (strpos($InfoFieldList[4], '$SEL$')!==false) {
|
|
| 5719 | + $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]);
|
|
| 5720 | + } |
|
| 5721 | + |
|
| 5722 | + // current object id can be use into filter |
|
| 5723 | + if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) {
|
|
| 5724 | + $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]);
|
|
| 5725 | + } else {
|
|
| 5726 | + $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]);
|
|
| 5727 | + } |
|
| 5728 | + |
|
| 5729 | + // We have to join on extrafield table |
|
| 5730 | + if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 5731 | + $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; |
|
| 5732 | + $sqlwhere .= ' WHERE extra.fk_object=main.' . $InfoFieldList[2] . ' AND ' . $InfoFieldList[4]; |
|
| 5733 | + } else {
|
|
| 5734 | + $sqlwhere .= ' WHERE ' . $InfoFieldList[4]; |
|
| 5735 | + } |
|
| 5736 | + } else {
|
|
| 5737 | + $sqlwhere .= ' WHERE 1=1'; |
|
| 5738 | + } |
|
| 5739 | + // Some tables may have field, some other not. For the moment we disable it. |
|
| 5740 | + if (in_array($InfoFieldList[0], array ('tablewithentity')))
|
|
| 5741 | + {
|
|
| 5742 | + $sqlwhere .= ' AND entity = ' . Globals::$conf->entity; |
|
| 5743 | + } |
|
| 5744 | + // $sql.=preg_replace('/^ AND /','',$sqlwhere);
|
|
| 5745 | + // print $sql; |
|
| 5746 | + |
|
| 5747 | + $sql .= $sqlwhere; |
|
| 5748 | + dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); |
|
| 5749 | + $resql = $this->db->query($sql); |
|
| 5750 | + if ($resql) {
|
|
| 5751 | + $num = $this->db->num_rows($resql); |
|
| 5752 | + $i = 0; |
|
| 5753 | + |
|
| 5754 | + $data=array(); |
|
| 5755 | + |
|
| 5756 | + while ( $i < $num ) {
|
|
| 5757 | + $labeltoshow = ''; |
|
| 5758 | + $obj = $this->db->fetch_object($resql); |
|
| 5759 | + |
|
| 5760 | + $notrans = false; |
|
| 5761 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 5762 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 5763 | + if (is_array($fields_label)) {
|
|
| 5764 | + $notrans = true; |
|
| 5765 | + foreach ( $fields_label as $field_toshow ) {
|
|
| 5766 | + $labeltoshow .= $obj->$field_toshow . ' '; |
|
| 5767 | + } |
|
| 5768 | + } else {
|
|
| 5769 | + $labeltoshow = $obj->{$InfoFieldList[1]};
|
|
| 5770 | + } |
|
| 5771 | + $labeltoshow = dol_trunc($labeltoshow, 45); |
|
| 5772 | + |
|
| 5773 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5774 | + foreach ( $fields_label as $field_toshow ) {
|
|
| 5775 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 5776 | + if ($translabel != $obj->$field_toshow) {
|
|
| 5777 | + $labeltoshow = dol_trunc($translabel, 18) . ' '; |
|
| 5778 | + } else {
|
|
| 5779 | + $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; |
|
| 5780 | + } |
|
| 5781 | + } |
|
| 5782 | + |
|
| 5783 | + $data[$obj->rowid]=$labeltoshow; |
|
| 5784 | + } else {
|
|
| 5785 | + if (! $notrans) {
|
|
| 5786 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 5787 | + if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 5788 | + $labeltoshow = dol_trunc($translabel, 18); |
|
| 5789 | + } else {
|
|
| 5790 | + $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
|
| 5791 | + } |
|
| 5792 | + } |
|
| 5793 | + if (empty($labeltoshow)) |
|
| 5794 | + $labeltoshow = '(not defined)'; |
|
| 5795 | + |
|
| 5796 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 5797 | + $data[$obj->rowid]=$labeltoshow; |
|
| 5798 | + } |
|
| 5799 | + |
|
| 5800 | + if (! empty($InfoFieldList[3]) && $parentField) {
|
|
| 5801 | + $parent = $parentName . ':' . $obj->{$parentField};
|
|
| 5802 | + } |
|
| 5803 | + |
|
| 5804 | + $data[$obj->rowid]=$labeltoshow; |
|
| 5805 | + } |
|
| 5806 | + |
|
| 5807 | + $i ++; |
|
| 5808 | + } |
|
| 5809 | + $this->db->free($resql); |
|
| 5810 | + |
|
| 5811 | + $out=$form->multiselectarray($keyprefix.$key.$keysuffix, $data, $value_arr, '', 0, '', 0, '100%'); |
|
| 5812 | + } else {
|
|
| 5813 | + print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
|
| 5814 | + } |
|
| 5815 | + } |
|
| 5816 | + } |
|
| 5817 | + elseif ($type == 'link') |
|
| 5818 | + {
|
|
| 5819 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 5820 | + $showempty=(($required && $default != '')?0:1); |
|
| 5821 | + $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
|
| 5822 | + if (Globals::$conf->global->MAIN_FEATURES_LEVEL >= 2) {
|
|
| 5823 | + list($class,$classfile)=explode(':',$param_list[0]);
|
|
| 5824 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5825 | + else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 5826 | + $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5827 | + // TODO Add Javascript code to add input fields contents to new elements urls |
|
| 5828 | + } |
|
| 5829 | + } |
|
| 5830 | + elseif ($type == 'password') |
|
| 5831 | + {
|
|
| 5832 | + // If prefix is 'search_', field is used as a filter, we use a common text field. |
|
| 5833 | + $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
|
| 5834 | + } |
|
| 5835 | + elseif ($type == 'array') |
|
| 5836 | + {
|
|
| 5837 | + $newval = $val; |
|
| 5838 | + $newval['type'] = 'varchar(256)'; |
|
| 5839 | + |
|
| 5840 | + $out=''; |
|
| 5841 | + |
|
| 5842 | + $inputs = array(); |
|
| 5843 | + if(! empty($value)) {
|
|
| 5844 | + foreach($value as $option) {
|
|
| 5845 | + $out.= '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5846 | + $out.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', $option, $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5847 | + } |
|
| 5848 | + } |
|
| 5849 | + |
|
| 5850 | + $out.= '<a id="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_add" href="javascript:;"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
|
| 5851 | + |
|
| 5852 | + $newInput = '<span><a class="'.dol_escape_htmltag($keyprefix.$key.$keysuffix).'_del" href="javascript:;"><span class="fa fa-minus-circle valignmiddle"></span></a> '; |
|
| 5853 | + $newInput.= $this->showInputField($newval, $keyprefix.$key.$keysuffix.'[]', '', $moreparam, '', '', $showsize).'<br></span>'; |
|
| 5854 | + |
|
| 5855 | + if (!empty(Globals::$conf->use_javascript_ajax)) {
|
|
| 5856 | + $out.= ' |
|
| 5857 | + <script type="text/javascript"> |
|
| 5858 | + $(document).ready(function() {
|
|
| 5859 | + $("a#'.dol_escape_js($keyprefix.$key.$keysuffix).'_add").click(function() {
|
|
| 5860 | + $("'.dol_escape_js($newInput).'").insertBefore(this);
|
|
| 5861 | + }); |
|
| 5862 | + |
|
| 5863 | + $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() {
|
|
| 5864 | + $(this).parent().remove(); |
|
| 5865 | + }); |
|
| 5866 | + }); |
|
| 5867 | + </script>'; |
|
| 5868 | + } |
|
| 5869 | + } |
|
| 5870 | + if (!empty($hidden)) {
|
|
| 5871 | + $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5872 | + } |
|
| 5873 | + /* Add comments |
|
| 5874 | + if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
|
| 5875 | + elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; |
|
| 5876 | + */ |
|
| 5877 | + return $out; |
|
| 5878 | + } |
|
| 5879 | + |
|
| 5880 | + /** |
|
| 5881 | + * Return HTML string to show a field into a page |
|
| 5882 | + * Code very similar with showOutputField of extra fields |
|
| 5883 | + * |
|
| 5884 | + * @param array $val Array of properties of field to show |
|
| 5885 | + * @param string $key Key of attribute |
|
| 5886 | + * @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) |
|
| 5887 | + * @param string $moreparam To add more parametes on html input tag |
|
| 5888 | + * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5889 | + * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5890 | + * @param mixed $showsize Value for css to define size. May also be a numeric. |
|
| 5891 | + * @return string |
|
| 5892 | + */ |
|
| 5893 | + function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5894 | + {
|
|
| 5895 | + global $conf,$langs,$form; |
|
| 5896 | + |
|
| 5897 | + if (! is_object($form)) |
|
| 5898 | + {
|
|
| 5899 | + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5900 | + $form=new Form($this->db); |
|
| 5901 | + } |
|
| 5902 | + |
|
| 5903 | + $objectid = $this->id; |
|
| 5904 | + $label = $val['label']; |
|
| 5905 | + $type = $val['type']; |
|
| 5906 | + $size = $val['css']; |
|
| 5907 | + |
|
| 5908 | + // Convert var to be able to share same code than showOutputField of extrafields |
|
| 5909 | + if (preg_match('/varchar\((\d+)\)/', $type, $reg))
|
|
| 5910 | + {
|
|
| 5911 | + $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5912 | + $size = $reg[1]; |
|
| 5913 | + } |
|
| 5914 | + elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5915 | + if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5916 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 5917 | + |
|
| 5918 | + $default=$val['default']; |
|
| 5919 | + $computed=$val['computed']; |
|
| 5920 | + $unique=$val['unique']; |
|
| 5921 | + $required=$val['required']; |
|
| 5922 | + $param=$val['param']; |
|
| 5923 | + if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 5924 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
|
| 5925 | + {
|
|
| 5926 | + $type='link'; |
|
| 5927 | + $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5928 | + } |
|
| 5929 | + $langfile=$val['langfile']; |
|
| 5930 | + $list=$val['list']; |
|
| 5931 | + $help=$val['help']; |
|
| 5932 | + $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) |
|
| 5933 | + |
|
| 5934 | + if ($hidden) return ''; |
|
| 5935 | + |
|
| 5936 | + // If field is a computed field, value must become result of compute |
|
| 5937 | + if ($computed) |
|
| 5938 | + {
|
|
| 5939 | + // Make the eval of compute string |
|
| 5940 | + //var_dump($computed); |
|
| 5941 | + $value = dol_eval($computed, 1, 0); |
|
| 5942 | + } |
|
| 5943 | + |
|
| 5944 | + if (empty($showsize)) |
|
| 5945 | + {
|
|
| 5946 | + if ($type == 'date') |
|
| 5947 | + {
|
|
| 5948 | + //$showsize=10; |
|
| 5949 | + $showsize = 'minwidth100imp'; |
|
| 5950 | + } |
|
| 5951 | + elseif ($type == 'datetime') |
|
| 5952 | + {
|
|
| 5953 | + //$showsize=19; |
|
| 5954 | + $showsize = 'minwidth200imp'; |
|
| 5955 | + } |
|
| 5956 | + elseif (in_array($type,array('int','double','price')))
|
|
| 5957 | + {
|
|
| 5958 | + //$showsize=10; |
|
| 5959 | + $showsize = 'maxwidth75'; |
|
| 5960 | + } |
|
| 5961 | + elseif ($type == 'url') |
|
| 5962 | + {
|
|
| 5963 | + $showsize='minwidth400'; |
|
| 5964 | + } |
|
| 5965 | + elseif ($type == 'boolean') |
|
| 5966 | + {
|
|
| 5967 | + $showsize=''; |
|
| 5968 | + } |
|
| 5969 | + else |
|
| 5970 | + {
|
|
| 5971 | + if (round($size) < 12) |
|
| 5972 | + {
|
|
| 5973 | + $showsize = 'minwidth100'; |
|
| 5974 | + } |
|
| 5975 | + else if (round($size) <= 48) |
|
| 5976 | + {
|
|
| 5977 | + $showsize = 'minwidth200'; |
|
| 5978 | + } |
|
| 5979 | + else |
|
| 5980 | + {
|
|
| 5981 | + //$showsize=48; |
|
| 5982 | + $showsize = 'minwidth400'; |
|
| 5983 | + } |
|
| 5984 | + } |
|
| 5985 | + } |
|
| 5986 | + |
|
| 5987 | + // Format output value differently according to properties of field |
|
| 5988 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5989 | + elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5990 | + elseif ($type == 'date') |
|
| 5991 | + {
|
|
| 5992 | + if(! empty($value)) {
|
|
| 5993 | + $value=dol_print_date($value,'day'); |
|
| 5994 | + } else {
|
|
| 5995 | + $value=''; |
|
| 5996 | + } |
|
| 5997 | + } |
|
| 5998 | + elseif ($type == 'datetime') |
|
| 5999 | + {
|
|
| 6000 | + if(! empty($value)) {
|
|
| 6001 | + $value=dol_print_date($value,'dayhour'); |
|
| 6002 | + } else {
|
|
| 6003 | + $value=''; |
|
| 6004 | + } |
|
| 6005 | + } |
|
| 6006 | + elseif ($type == 'double') |
|
| 6007 | + {
|
|
| 6008 | + if (!empty($value)) {
|
|
| 6009 | + $value=price($value); |
|
| 6010 | + } |
|
| 6011 | + } |
|
| 6012 | + elseif ($type == 'boolean') |
|
| 6013 | + {
|
|
| 6014 | + $checked=''; |
|
| 6015 | + if (!empty($value)) {
|
|
| 6016 | + $checked=' checked '; |
|
| 6017 | + } |
|
| 6018 | + $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 6019 | + } |
|
| 6020 | + elseif ($type == 'mail') |
|
| 6021 | + {
|
|
| 6022 | + $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 6023 | + } |
|
| 6024 | + elseif ($type == 'url') |
|
| 6025 | + {
|
|
| 6026 | + $value=dol_print_url($value,'_blank',32,1); |
|
| 6027 | + } |
|
| 6028 | + elseif ($type == 'phone') |
|
| 6029 | + {
|
|
| 6030 | + $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6031 | + } |
|
| 6032 | + elseif ($type == 'price') |
|
| 6033 | + {
|
|
| 6034 | + $value = price($value, 0, $langs, 0, 0, -1, Globals::$conf->currency); |
|
| 6035 | + } |
|
| 6036 | + elseif ($type == 'select') |
|
| 6037 | + {
|
|
| 6038 | + $value=$param['options'][$value]; |
|
| 6039 | + } |
|
| 6040 | + elseif ($type == 'sellist') |
|
| 6041 | + {
|
|
| 6042 | + $param_list=array_keys($param['options']); |
|
| 6043 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6044 | + |
|
| 6045 | + $selectkey="rowid"; |
|
| 6046 | + $keyList='rowid'; |
|
| 6047 | + |
|
| 6048 | + if (count($InfoFieldList)>=3) |
|
| 6049 | + {
|
|
| 6050 | + $selectkey = $InfoFieldList[2]; |
|
| 6051 | + $keyList=$InfoFieldList[2].' as rowid'; |
|
| 6052 | + } |
|
| 6053 | + |
|
| 6054 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6055 | + if(is_array($fields_label)) {
|
|
| 6056 | + $keyList .=', '; |
|
| 6057 | + $keyList .= implode(', ', $fields_label);
|
|
| 6058 | + } |
|
| 6059 | + |
|
| 6060 | + $sql = 'SELECT '.$keyList; |
|
| 6061 | + $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 6062 | + if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 6063 | + {
|
|
| 6064 | + $sql.= ' as main'; |
|
| 6065 | + } |
|
| 6066 | + if ($selectkey=='rowid' && empty($value)) {
|
|
| 6067 | + $sql.= " WHERE ".$selectkey."=0"; |
|
| 6068 | + } elseif ($selectkey=='rowid') {
|
|
| 6069 | + $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6070 | + }else {
|
|
| 6071 | + $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6072 | + } |
|
| 6073 | + |
|
| 6074 | + //$sql.= ' AND entity = '.Globals::$conf->entity; |
|
| 6075 | + |
|
| 6076 | + dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
| 6077 | + $resql = $this->db->query($sql); |
|
| 6078 | + if ($resql) |
|
| 6079 | + {
|
|
| 6080 | + $value=''; // value was used, so now we reste it to use it to build final output |
|
| 6081 | + |
|
| 6082 | + $obj = $this->db->fetch_object($resql); |
|
| 6083 | + |
|
| 6084 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 6085 | + $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6086 | + |
|
| 6087 | + if(is_array($fields_label) && count($fields_label)>1) |
|
| 6088 | + {
|
|
| 6089 | + foreach ($fields_label as $field_toshow) |
|
| 6090 | + {
|
|
| 6091 | + $translabel=''; |
|
| 6092 | + if (!empty($obj->$field_toshow)) {
|
|
| 6093 | + $translabel=$langs->trans($obj->$field_toshow); |
|
| 6094 | + } |
|
| 6095 | + if ($translabel!=$field_toshow) {
|
|
| 6096 | + $value.=dol_trunc($translabel,18).' '; |
|
| 6097 | + }else {
|
|
| 6098 | + $value.=$obj->$field_toshow.' '; |
|
| 6099 | + } |
|
| 6100 | + } |
|
| 6101 | + } |
|
| 6102 | + else |
|
| 6103 | + {
|
|
| 6104 | + $translabel=''; |
|
| 6105 | + if (!empty($obj->{$InfoFieldList[1]})) {
|
|
| 6106 | + $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6107 | + } |
|
| 6108 | + if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 6109 | + $value=dol_trunc($translabel,18); |
|
| 6110 | + }else {
|
|
| 6111 | + $value=$obj->{$InfoFieldList[1]};
|
|
| 6112 | + } |
|
| 6113 | + } |
|
| 6114 | + } |
|
| 6115 | + else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6116 | + } |
|
| 6117 | + elseif ($type == 'radio') |
|
| 6118 | + {
|
|
| 6119 | + $value=$param['options'][$value]; |
|
| 6120 | + } |
|
| 6121 | + elseif ($type == 'checkbox') |
|
| 6122 | + {
|
|
| 6123 | + $value_arr=explode(',',$value);
|
|
| 6124 | + $value=''; |
|
| 6125 | + if (is_array($value_arr) && count($value_arr)>0) |
|
| 6126 | + {
|
|
| 6127 | + foreach ($value_arr as $keyval=>$valueval) {
|
|
| 6128 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6129 | + } |
|
| 6130 | + $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6131 | + } |
|
| 6132 | + } |
|
| 6133 | + elseif ($type == 'chkbxlst') |
|
| 6134 | + {
|
|
| 6135 | + $value_arr = explode(',', $value);
|
|
| 6136 | + |
|
| 6137 | + $param_list = array_keys($param['options']); |
|
| 6138 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6139 | + |
|
| 6140 | + $selectkey = "rowid"; |
|
| 6141 | + $keyList = 'rowid'; |
|
| 6142 | + |
|
| 6143 | + if (count($InfoFieldList) >= 3) {
|
|
| 6144 | + $selectkey = $InfoFieldList[2]; |
|
| 6145 | + $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 6146 | + } |
|
| 6147 | + |
|
| 6148 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6149 | + if (is_array($fields_label)) {
|
|
| 6150 | + $keyList .= ', '; |
|
| 6151 | + $keyList .= implode(', ', $fields_label);
|
|
| 6152 | + } |
|
| 6153 | + |
|
| 6154 | + $sql = 'SELECT ' . $keyList; |
|
| 6155 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 6156 | + if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 6157 | + $sql .= ' as main'; |
|
| 6158 | + } |
|
| 6159 | + // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6160 | + // $sql.= ' AND entity = '.Globals::$conf->entity; |
|
| 6161 | + |
|
| 6162 | + dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 6163 | + $resql = $this->db->query($sql); |
|
| 6164 | + if ($resql) {
|
|
| 6165 | + $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 6166 | + $toprint=array(); |
|
| 6167 | + while ( $obj = $this->db->fetch_object($resql) ) {
|
|
| 6168 | + |
|
| 6169 | + // Several field into label (eq table:code|libelle:rowid) |
|
| 6170 | + $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6171 | + if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 6172 | + if (is_array($fields_label) && count($fields_label) > 1) {
|
|
| 6173 | + foreach ( $fields_label as $field_toshow ) {
|
|
| 6174 | + $translabel = ''; |
|
| 6175 | + if (! empty($obj->$field_toshow)) {
|
|
| 6176 | + $translabel = $langs->trans($obj->$field_toshow); |
|
| 6177 | + } |
|
| 6178 | + if ($translabel != $field_toshow) {
|
|
| 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->$field_toshow.'</li>'; |
|
| 6182 | + } |
|
| 6183 | + } |
|
| 6184 | + } else {
|
|
| 6185 | + $translabel = ''; |
|
| 6186 | + if (! empty($obj->{$InfoFieldList[1]})) {
|
|
| 6187 | + $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6188 | + } |
|
| 6189 | + if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 6190 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6191 | + } else {
|
|
| 6192 | + $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
|
|
| 6193 | + } |
|
| 6194 | + } |
|
| 6195 | + } |
|
| 6196 | + } |
|
| 6197 | + $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6198 | + } else {
|
|
| 6199 | + dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 6200 | + } |
|
| 6201 | + } |
|
| 6202 | + elseif ($type == 'link') |
|
| 6203 | + {
|
|
| 6204 | + $out=''; |
|
| 6205 | + |
|
| 6206 | + // only if something to display (perf) |
|
| 6207 | + if ($value) |
|
| 6208 | + {
|
|
| 6209 | + $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 6210 | + |
|
| 6211 | + $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6212 | + $classname=$InfoFieldList[0]; |
|
| 6213 | + $classpath=$InfoFieldList[1]; |
|
| 6214 | + $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6215 | + if (! empty($classpath)) |
|
| 6216 | + {
|
|
| 6217 | + dol_include_once($InfoFieldList[1]); |
|
| 6218 | + if ($classname && class_exists($classname)) |
|
| 6219 | + {
|
|
| 6220 | + $object = new $classname($this->db); |
|
| 6221 | + $object->fetch($value); |
|
| 6222 | + $value=$object->getNomUrl($getnomurlparam); |
|
| 6223 | + } |
|
| 6224 | + } |
|
| 6225 | + else |
|
| 6226 | + {
|
|
| 6227 | + dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 6228 | + return 'Error bad setup of extrafield'; |
|
| 6229 | + } |
|
| 6230 | + } |
|
| 6231 | + else $value=''; |
|
| 6232 | + } |
|
| 6233 | + elseif ($type == 'text' || $type == 'html') |
|
| 6234 | + {
|
|
| 6235 | + $value=dol_htmlentitiesbr($value); |
|
| 6236 | + } |
|
| 6237 | + elseif ($type == 'password') |
|
| 6238 | + {
|
|
| 6239 | + $value=preg_replace('/./i','*',$value);
|
|
| 6240 | + } |
|
| 6241 | + elseif ($type == 'array') |
|
| 6242 | + {
|
|
| 6243 | + $value = implode('<br>', $value);
|
|
| 6244 | + } |
|
| 6245 | + |
|
| 6246 | + //print $type.'-'.$size; |
|
| 6247 | + $out=$value; |
|
| 6248 | + |
|
| 6249 | + return $out; |
|
| 6250 | + } |
|
| 6251 | + |
|
| 6252 | + |
|
| 6253 | + /** |
|
| 6254 | + * Function to show lines of extrafields with output datas |
|
| 6255 | + * |
|
| 6256 | + * @param Extrafields $extrafields Extrafield Object |
|
| 6257 | + * @param string $mode Show output (view) or input (edit) for extrafield |
|
| 6258 | + * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
|
|
| 6259 | + * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) |
|
| 6260 | + * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) |
|
| 6261 | + * @param string $onetrtd All fields in same tr td |
|
| 6262 | + * @return string |
|
| 6263 | + */ |
|
| 6264 | + function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
| 6265 | + {
|
|
| 6266 | + global $db, $conf, $langs, $action, $form; |
|
| 6267 | + |
|
| 6268 | + if (! is_object($form)) $form=new Form($db); |
|
| 6269 | + |
|
| 6270 | + $out = ''; |
|
| 6271 | + |
|
| 6272 | + if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) |
|
| 6273 | + {
|
|
| 6274 | + $out .= "\n"; |
|
| 6275 | + $out .= '<!-- showOptionalsInput --> '; |
|
| 6276 | + $out .= "\n"; |
|
| 6277 | + |
|
| 6278 | + $e = 0; |
|
| 6279 | + foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6280 | + {
|
|
| 6281 | + // Show only the key field in params |
|
| 6282 | + if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 6283 | + |
|
| 6284 | + $enabled = 1; |
|
| 6285 | + if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
|
| 6286 | + {
|
|
| 6287 | + $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1); |
|
| 6288 | + } |
|
| 6289 | + |
|
| 6290 | + $perms = 1; |
|
| 6291 | + if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) |
|
| 6292 | + {
|
|
| 6293 | + $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
|
| 6294 | + } |
|
| 6295 | + |
|
| 6296 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6297 | + if (empty($perms)) continue; |
|
| 6298 | + |
|
| 6299 | + // Load language if required |
|
| 6300 | + if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6301 | + |
|
| 6302 | + $colspan='3'; |
|
| 6303 | + if (is_array($params) && count($params)>0) {
|
|
| 6304 | + if (array_key_exists('colspan',$params)) {
|
|
| 6305 | + $colspan=$params['colspan']; |
|
| 6306 | + } |
|
| 6307 | + } |
|
| 6308 | + |
|
| 6309 | + switch($mode) {
|
|
| 6310 | + case "view": |
|
| 6311 | + $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 6312 | + break; |
|
| 6313 | + case "edit": |
|
| 6314 | + $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6315 | + // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
|
|
| 6316 | + if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
|
| 6317 | + {
|
|
| 6318 | + if (is_array($getposttemp)) {
|
|
| 6319 | + // $getposttemp is an array but following code expects a comma separated string |
|
| 6320 | + $value = implode(",", $getposttemp);
|
|
| 6321 | + } else {
|
|
| 6322 | + $value = $getposttemp; |
|
| 6323 | + } |
|
| 6324 | + } else {
|
|
| 6325 | + $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6326 | + } |
|
| 6327 | + //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
|
| 6328 | + break; |
|
| 6329 | + } |
|
| 6330 | + |
|
| 6331 | + if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
|
| 6332 | + {
|
|
| 6333 | + $out .= $extrafields->showSeparator($key, $this); |
|
| 6334 | + } |
|
| 6335 | + else |
|
| 6336 | + {
|
|
| 6337 | + $csstyle=''; |
|
| 6338 | + $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6339 | + if (is_array($params) && count($params)>0) {
|
|
| 6340 | + if (array_key_exists('style',$params)) {
|
|
| 6341 | + $csstyle=$params['style']; |
|
| 6342 | + } |
|
| 6343 | + } |
|
| 6344 | + |
|
| 6345 | + // add html5 elements |
|
| 6346 | + $domData = ' data-element="extrafield"'; |
|
| 6347 | + $domData .= ' data-targetelement="'.$this->element.'"'; |
|
| 6348 | + $domData .= ' data-targetid="'.$this->id.'"'; |
|
| 6349 | + |
|
| 6350 | + $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
| 6351 | + |
|
| 6352 | + $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
| 6353 | + |
|
| 6354 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
|
|
| 6355 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
|
|
| 6356 | + $colspan = '0'; |
|
| 6357 | + } |
|
| 6358 | + } |
|
| 6359 | + |
|
| 6360 | + if ($action == 'selectlines') { $colspan++; }
|
|
| 6361 | + |
|
| 6362 | + // Convert date into timestamp format (value in memory must be a timestamp) |
|
| 6363 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
|
| 6364 | + {
|
|
| 6365 | + $datenotinstring = $this->array_options['options_' . $key]; |
|
| 6366 | + if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6367 | + {
|
|
| 6368 | + $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6369 | + } |
|
| 6370 | + $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; |
|
| 6371 | + } |
|
| 6372 | + // Convert float submited string into real php numeric (value in memory must be a php numeric) |
|
| 6373 | + if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double')))
|
|
| 6374 | + {
|
|
| 6375 | + $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
| 6376 | + } |
|
| 6377 | + |
|
| 6378 | + $labeltoshow = $langs->trans($label); |
|
| 6379 | + |
|
| 6380 | + $out .= '<td class="titlefield'; |
|
| 6381 | + if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6382 | + if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6383 | + $out .= '">'; |
|
| 6384 | + if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6385 | + else $out .= $labeltoshow; |
|
| 6386 | + $out .= '</td>'; |
|
| 6387 | + |
|
| 6388 | + $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
| 6389 | + $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 6390 | + |
|
| 6391 | + switch($mode) {
|
|
| 6392 | + case "view": |
|
| 6393 | + $out .= $extrafields->showOutputField($key, $value); |
|
| 6394 | + break; |
|
| 6395 | + case "edit": |
|
| 6396 | + $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); |
|
| 6397 | + break; |
|
| 6398 | + } |
|
| 6399 | + |
|
| 6400 | + $out .= '</td>'; |
|
| 6401 | + |
|
| 6402 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) |
|
| 6403 | + $out .= '</tr>'; |
|
| 6404 | + else $out .= '</tr>'; |
|
| 6405 | + $e++; |
|
| 6406 | + } |
|
| 6407 | + } |
|
| 6408 | + $out .= "\n"; |
|
| 6409 | + // Add code to manage list depending on others |
|
| 6410 | + if (!empty(Globals::$conf->use_javascript_ajax)) {
|
|
| 6411 | + $out .= ' |
|
| 6412 | + <script type="text/javascript"> |
|
| 6413 | + jQuery(document).ready(function() {
|
|
| 6414 | + function showOptions(child_list, parent_list) |
|
| 6415 | + {
|
|
| 6416 | + var val = $("select[name=\"options_"+parent_list+"\"]").val();
|
|
| 6417 | + var parentVal = parent_list + ":" + val; |
|
| 6418 | + if(val > 0) {
|
|
| 6419 | + $("select[name=\""+child_list+"\"] option[parent]").hide();
|
|
| 6420 | + $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
|
|
| 6421 | + } else {
|
|
| 6422 | + $("select[name=\""+child_list+"\"] option").show();
|
|
| 6423 | + } |
|
| 6424 | + } |
|
| 6425 | + function setListDependencies() {
|
|
| 6426 | + jQuery("select option[parent]").parent().each(function() {
|
|
| 6427 | + var child_list = $(this).attr("name");
|
|
| 6428 | + var parent = $(this).find("option[parent]:first").attr("parent");
|
|
| 6429 | + var infos = parent.split(":");
|
|
| 6430 | + var parent_list = infos[0]; |
|
| 6431 | + $("select[name=\""+parent_list+"\"]").change(function() {
|
|
| 6432 | + showOptions(child_list, parent_list); |
|
| 6433 | + }); |
|
| 6434 | + }); |
|
| 6435 | + } |
|
| 6436 | + |
|
| 6437 | + setListDependencies(); |
|
| 6438 | + }); |
|
| 6439 | + </script>'."\n"; |
|
| 6440 | + $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
| 6441 | + } |
|
| 6442 | + } |
|
| 6443 | + return $out; |
|
| 6444 | + } |
|
| 6445 | + |
|
| 6446 | + |
|
| 6447 | + /** |
|
| 6448 | + * Returns the rights used for this class |
|
| 6449 | + * @return stdClass |
|
| 6450 | + */ |
|
| 6451 | + public function getRights() |
|
| 6452 | + {
|
|
| 6453 | + global $user; |
|
| 6454 | + |
|
| 6455 | + $element = $this->element; |
|
| 6456 | + if ($element == 'facturerec') $element='facture'; |
|
| 6457 | + |
|
| 6458 | + return $user->rights->{$element};
|
|
| 6459 | + } |
|
| 6460 | + |
|
| 6461 | + /** |
|
| 6462 | + * Function used to replace a thirdparty id with another one. |
|
| 6463 | + * This function is meant to be called from replaceThirdparty with the appropiate tables |
|
| 6464 | + * Column name fk_soc MUST be used to identify thirdparties |
|
| 6465 | + * |
|
| 6466 | + * @param DoliDB $db Database handler |
|
| 6467 | + * @param int $origin_id Old thirdparty id (the thirdparty to delete) |
|
| 6468 | + * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) |
|
| 6469 | + * @param string[] $tables Tables that need to be changed |
|
| 6470 | + * @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) |
|
| 6471 | + * @return bool True if success, False if error |
|
| 6472 | + */ |
|
| 6473 | + public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6474 | + {
|
|
| 6475 | + foreach ($tables as $table) |
|
| 6476 | + {
|
|
| 6477 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
| 5862 | 6478 | |
| 5863 | - $(document).on("click", "a.'.dol_escape_js($keyprefix.$key.$keysuffix).'_del", function() {
|
|
| 5864 | - $(this).parent().remove(); |
|
| 5865 | - }); |
|
| 5866 | - }); |
|
| 5867 | - </script>'; |
|
| 5868 | - } |
|
| 5869 | - } |
|
| 5870 | - if (!empty($hidden)) {
|
|
| 5871 | - $out='<input type="hidden" value="'.$value.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'"/>'; |
|
| 5872 | - } |
|
| 5873 | - /* Add comments |
|
| 5874 | - if ($type == 'date') $out.=' (YYYY-MM-DD)'; |
|
| 5875 | - elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; |
|
| 5876 | - */ |
|
| 5877 | - return $out; |
|
| 5878 | - } |
|
| 5879 | - |
|
| 5880 | - /** |
|
| 5881 | - * Return HTML string to show a field into a page |
|
| 5882 | - * Code very similar with showOutputField of extra fields |
|
| 5883 | - * |
|
| 5884 | - * @param array $val Array of properties of field to show |
|
| 5885 | - * @param string $key Key of attribute |
|
| 5886 | - * @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) |
|
| 5887 | - * @param string $moreparam To add more parametes on html input tag |
|
| 5888 | - * @param string $keysuffix Prefix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5889 | - * @param string $keyprefix Suffix string to add into name and id of field (can be used to avoid duplicate names) |
|
| 5890 | - * @param mixed $showsize Value for css to define size. May also be a numeric. |
|
| 5891 | - * @return string |
|
| 5892 | - */ |
|
| 5893 | - function showOutputField($val, $key, $value, $moreparam='', $keysuffix='', $keyprefix='', $showsize=0) |
|
| 5894 | - {
|
|
| 5895 | - global $conf,$langs,$form; |
|
| 5896 | - |
|
| 5897 | - if (! is_object($form)) |
|
| 5898 | - {
|
|
| 5899 | - require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; |
|
| 5900 | - $form=new Form($this->db); |
|
| 5901 | - } |
|
| 5902 | - |
|
| 5903 | - $objectid = $this->id; |
|
| 5904 | - $label = $val['label']; |
|
| 5905 | - $type = $val['type']; |
|
| 5906 | - $size = $val['css']; |
|
| 5907 | - |
|
| 5908 | - // Convert var to be able to share same code than showOutputField of extrafields |
|
| 5909 | - if (preg_match('/varchar\((\d+)\)/', $type, $reg))
|
|
| 5910 | - {
|
|
| 5911 | - $type = 'varchar'; // convert varchar(xx) int varchar |
|
| 5912 | - $size = $reg[1]; |
|
| 5913 | - } |
|
| 5914 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5915 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5916 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 5917 | - |
|
| 5918 | - $default=$val['default']; |
|
| 5919 | - $computed=$val['computed']; |
|
| 5920 | - $unique=$val['unique']; |
|
| 5921 | - $required=$val['required']; |
|
| 5922 | - $param=$val['param']; |
|
| 5923 | - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 5924 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
|
| 5925 | - {
|
|
| 5926 | - $type='link'; |
|
| 5927 | - $param['options']=array($reg[1].':'.$reg[2]=>$reg[1].':'.$reg[2]); |
|
| 5928 | - } |
|
| 5929 | - $langfile=$val['langfile']; |
|
| 5930 | - $list=$val['list']; |
|
| 5931 | - $help=$val['help']; |
|
| 5932 | - $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) |
|
| 5933 | - |
|
| 5934 | - if ($hidden) return ''; |
|
| 5935 | - |
|
| 5936 | - // If field is a computed field, value must become result of compute |
|
| 5937 | - if ($computed) |
|
| 5938 | - {
|
|
| 5939 | - // Make the eval of compute string |
|
| 5940 | - //var_dump($computed); |
|
| 5941 | - $value = dol_eval($computed, 1, 0); |
|
| 5942 | - } |
|
| 5943 | - |
|
| 5944 | - if (empty($showsize)) |
|
| 5945 | - {
|
|
| 5946 | - if ($type == 'date') |
|
| 5947 | - {
|
|
| 5948 | - //$showsize=10; |
|
| 5949 | - $showsize = 'minwidth100imp'; |
|
| 5950 | - } |
|
| 5951 | - elseif ($type == 'datetime') |
|
| 5952 | - {
|
|
| 5953 | - //$showsize=19; |
|
| 5954 | - $showsize = 'minwidth200imp'; |
|
| 5955 | - } |
|
| 5956 | - elseif (in_array($type,array('int','double','price')))
|
|
| 5957 | - {
|
|
| 5958 | - //$showsize=10; |
|
| 5959 | - $showsize = 'maxwidth75'; |
|
| 5960 | - } |
|
| 5961 | - elseif ($type == 'url') |
|
| 5962 | - {
|
|
| 5963 | - $showsize='minwidth400'; |
|
| 5964 | - } |
|
| 5965 | - elseif ($type == 'boolean') |
|
| 5966 | - {
|
|
| 5967 | - $showsize=''; |
|
| 5968 | - } |
|
| 5969 | - else |
|
| 5970 | - {
|
|
| 5971 | - if (round($size) < 12) |
|
| 5972 | - {
|
|
| 5973 | - $showsize = 'minwidth100'; |
|
| 5974 | - } |
|
| 5975 | - else if (round($size) <= 48) |
|
| 5976 | - {
|
|
| 5977 | - $showsize = 'minwidth200'; |
|
| 5978 | - } |
|
| 5979 | - else |
|
| 5980 | - {
|
|
| 5981 | - //$showsize=48; |
|
| 5982 | - $showsize = 'minwidth400'; |
|
| 5983 | - } |
|
| 5984 | - } |
|
| 5985 | - } |
|
| 5986 | - |
|
| 5987 | - // Format output value differently according to properties of field |
|
| 5988 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5989 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5990 | - elseif ($type == 'date') |
|
| 5991 | - {
|
|
| 5992 | - if(! empty($value)) {
|
|
| 5993 | - $value=dol_print_date($value,'day'); |
|
| 5994 | - } else {
|
|
| 5995 | - $value=''; |
|
| 5996 | - } |
|
| 5997 | - } |
|
| 5998 | - elseif ($type == 'datetime') |
|
| 5999 | - {
|
|
| 6000 | - if(! empty($value)) {
|
|
| 6001 | - $value=dol_print_date($value,'dayhour'); |
|
| 6002 | - } else {
|
|
| 6003 | - $value=''; |
|
| 6004 | - } |
|
| 6005 | - } |
|
| 6006 | - elseif ($type == 'double') |
|
| 6007 | - {
|
|
| 6008 | - if (!empty($value)) {
|
|
| 6009 | - $value=price($value); |
|
| 6010 | - } |
|
| 6011 | - } |
|
| 6012 | - elseif ($type == 'boolean') |
|
| 6013 | - {
|
|
| 6014 | - $checked=''; |
|
| 6015 | - if (!empty($value)) {
|
|
| 6016 | - $checked=' checked '; |
|
| 6017 | - } |
|
| 6018 | - $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
|
| 6019 | - } |
|
| 6020 | - elseif ($type == 'mail') |
|
| 6021 | - {
|
|
| 6022 | - $value=dol_print_email($value,0,0,0,64,1,1); |
|
| 6023 | - } |
|
| 6024 | - elseif ($type == 'url') |
|
| 6025 | - {
|
|
| 6026 | - $value=dol_print_url($value,'_blank',32,1); |
|
| 6027 | - } |
|
| 6028 | - elseif ($type == 'phone') |
|
| 6029 | - {
|
|
| 6030 | - $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
|
| 6031 | - } |
|
| 6032 | - elseif ($type == 'price') |
|
| 6033 | - {
|
|
| 6034 | - $value = price($value, 0, $langs, 0, 0, -1, Globals::$conf->currency); |
|
| 6035 | - } |
|
| 6036 | - elseif ($type == 'select') |
|
| 6037 | - {
|
|
| 6038 | - $value=$param['options'][$value]; |
|
| 6039 | - } |
|
| 6040 | - elseif ($type == 'sellist') |
|
| 6041 | - {
|
|
| 6042 | - $param_list=array_keys($param['options']); |
|
| 6043 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6044 | - |
|
| 6045 | - $selectkey="rowid"; |
|
| 6046 | - $keyList='rowid'; |
|
| 6047 | - |
|
| 6048 | - if (count($InfoFieldList)>=3) |
|
| 6049 | - {
|
|
| 6050 | - $selectkey = $InfoFieldList[2]; |
|
| 6051 | - $keyList=$InfoFieldList[2].' as rowid'; |
|
| 6052 | - } |
|
| 6053 | - |
|
| 6054 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6055 | - if(is_array($fields_label)) {
|
|
| 6056 | - $keyList .=', '; |
|
| 6057 | - $keyList .= implode(', ', $fields_label);
|
|
| 6058 | - } |
|
| 6059 | - |
|
| 6060 | - $sql = 'SELECT '.$keyList; |
|
| 6061 | - $sql.= ' FROM '.MAIN_DB_PREFIX .$InfoFieldList[0]; |
|
| 6062 | - if (strpos($InfoFieldList[4], 'extra')!==false) |
|
| 6063 | - {
|
|
| 6064 | - $sql.= ' as main'; |
|
| 6065 | - } |
|
| 6066 | - if ($selectkey=='rowid' && empty($value)) {
|
|
| 6067 | - $sql.= " WHERE ".$selectkey."=0"; |
|
| 6068 | - } elseif ($selectkey=='rowid') {
|
|
| 6069 | - $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
|
| 6070 | - }else {
|
|
| 6071 | - $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6072 | - } |
|
| 6073 | - |
|
| 6074 | - //$sql.= ' AND entity = '.Globals::$conf->entity; |
|
| 6479 | + if (! $db->query($sql)) |
|
| 6480 | + {
|
|
| 6481 | + 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. |
|
| 6482 | + //$this->errors = $db->lasterror(); |
|
| 6483 | + return false; |
|
| 6484 | + } |
|
| 6485 | + } |
|
| 6075 | 6486 | |
| 6076 | - dol_syslog(get_class($this).':showOutputField:$type=sellist', LOG_DEBUG); |
|
| 6077 | - $resql = $this->db->query($sql); |
|
| 6078 | - if ($resql) |
|
| 6079 | - {
|
|
| 6080 | - $value=''; // value was used, so now we reste it to use it to build final output |
|
| 6487 | + return true; |
|
| 6488 | + } |
|
| 6081 | 6489 | |
| 6082 | - $obj = $this->db->fetch_object($resql); |
|
| 6490 | + /** |
|
| 6491 | + * Get buy price to use for margin calculation. This function is called when buy price is unknown. |
|
| 6492 | + * Set buy price = sell price if ForceBuyingPriceIfNull configured, |
|
| 6493 | + * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice |
|
| 6494 | + * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice |
|
| 6495 | + * else set min buy price as buy price |
|
| 6496 | + * |
|
| 6497 | + * @param float $unitPrice Product unit price |
|
| 6498 | + * @param float $discountPercent Line discount percent |
|
| 6499 | + * @param int $fk_product Product id |
|
| 6500 | + * @return float <0 if KO, buyprice if OK |
|
| 6501 | + */ |
|
| 6502 | + public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) |
|
| 6503 | + {
|
|
| 6504 | + global $conf; |
|
| 6083 | 6505 | |
| 6084 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 6085 | - $fields_label = explode('|',$InfoFieldList[1]);
|
|
| 6506 | + $buyPrice = 0; |
|
| 6086 | 6507 | |
| 6087 | - if(is_array($fields_label) && count($fields_label)>1) |
|
| 6088 | - {
|
|
| 6089 | - foreach ($fields_label as $field_toshow) |
|
| 6090 | - {
|
|
| 6091 | - $translabel=''; |
|
| 6092 | - if (!empty($obj->$field_toshow)) {
|
|
| 6093 | - $translabel=$langs->trans($obj->$field_toshow); |
|
| 6094 | - } |
|
| 6095 | - if ($translabel!=$field_toshow) {
|
|
| 6096 | - $value.=dol_trunc($translabel,18).' '; |
|
| 6097 | - }else {
|
|
| 6098 | - $value.=$obj->$field_toshow.' '; |
|
| 6099 | - } |
|
| 6100 | - } |
|
| 6101 | - } |
|
| 6102 | - else |
|
| 6103 | - {
|
|
| 6104 | - $translabel=''; |
|
| 6105 | - if (!empty($obj->{$InfoFieldList[1]})) {
|
|
| 6106 | - $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6107 | - } |
|
| 6108 | - if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
|
| 6109 | - $value=dol_trunc($translabel,18); |
|
| 6110 | - }else {
|
|
| 6111 | - $value=$obj->{$InfoFieldList[1]};
|
|
| 6112 | - } |
|
| 6113 | - } |
|
| 6114 | - } |
|
| 6115 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6116 | - } |
|
| 6117 | - elseif ($type == 'radio') |
|
| 6118 | - {
|
|
| 6119 | - $value=$param['options'][$value]; |
|
| 6120 | - } |
|
| 6121 | - elseif ($type == 'checkbox') |
|
| 6122 | - {
|
|
| 6123 | - $value_arr=explode(',',$value);
|
|
| 6124 | - $value=''; |
|
| 6125 | - if (is_array($value_arr) && count($value_arr)>0) |
|
| 6126 | - {
|
|
| 6127 | - foreach ($value_arr as $keyval=>$valueval) {
|
|
| 6128 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$param['options'][$valueval].'</li>'; |
|
| 6129 | - } |
|
| 6130 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6131 | - } |
|
| 6132 | - } |
|
| 6133 | - elseif ($type == 'chkbxlst') |
|
| 6134 | - {
|
|
| 6135 | - $value_arr = explode(',', $value);
|
|
| 6136 | - |
|
| 6137 | - $param_list = array_keys($param['options']); |
|
| 6138 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6139 | - |
|
| 6140 | - $selectkey = "rowid"; |
|
| 6141 | - $keyList = 'rowid'; |
|
| 6142 | - |
|
| 6143 | - if (count($InfoFieldList) >= 3) {
|
|
| 6144 | - $selectkey = $InfoFieldList[2]; |
|
| 6145 | - $keyList = $InfoFieldList[2] . ' as rowid'; |
|
| 6146 | - } |
|
| 6147 | - |
|
| 6148 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6149 | - if (is_array($fields_label)) {
|
|
| 6150 | - $keyList .= ', '; |
|
| 6151 | - $keyList .= implode(', ', $fields_label);
|
|
| 6152 | - } |
|
| 6153 | - |
|
| 6154 | - $sql = 'SELECT ' . $keyList; |
|
| 6155 | - $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; |
|
| 6156 | - if (strpos($InfoFieldList[4], 'extra') !== false) {
|
|
| 6157 | - $sql .= ' as main'; |
|
| 6158 | - } |
|
| 6159 | - // $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
|
| 6160 | - // $sql.= ' AND entity = '.Globals::$conf->entity; |
|
| 6508 | + if (($unitPrice > 0) && (isset(Globals::$conf->global->ForceBuyingPriceIfNull) && Globals::$conf->global->ForceBuyingPriceIfNull == 1)) { // In most cases, test here is false{
|
|
| 6509 | + $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
| 6510 | + } |
|
| 6511 | + else |
|
| 6512 | + {
|
|
| 6513 | + // Get cost price for margin calculation |
|
| 6514 | + if (! empty($fk_product)) |
|
| 6515 | + {
|
|
| 6516 | + if (isset(Globals::$conf->global->MARGIN_TYPE) && Globals::$conf->global->MARGIN_TYPE == 'costprice') {
|
|
| 6517 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6518 | + $product = new Product($this->db); |
|
| 6519 | + $result = $product->fetch($fk_product); |
|
| 6520 | + if ($result <= 0) |
|
| 6521 | + {
|
|
| 6522 | + $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6523 | + return -1; |
|
| 6524 | + } |
|
| 6525 | + if ($product->cost_price > 0) |
|
| 6526 | + {
|
|
| 6527 | + $buyPrice = $product->cost_price; |
|
| 6528 | + } |
|
| 6529 | + else if ($product->pmp > 0) |
|
| 6530 | + {
|
|
| 6531 | + $buyPrice = $product->pmp; |
|
| 6532 | + } |
|
| 6533 | + } |
|
| 6534 | + else if (isset(Globals::$conf->global->MARGIN_TYPE) && Globals::$conf->global->MARGIN_TYPE == 'pmp') {
|
|
| 6535 | + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6536 | + $product = new Product($this->db); |
|
| 6537 | + $result = $product->fetch($fk_product); |
|
| 6538 | + if ($result <= 0) |
|
| 6539 | + {
|
|
| 6540 | + $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6541 | + return -1; |
|
| 6542 | + } |
|
| 6543 | + if ($product->pmp > 0) |
|
| 6544 | + {
|
|
| 6545 | + $buyPrice = $product->pmp; |
|
| 6546 | + } |
|
| 6547 | + } |
|
| 6548 | + |
|
| 6549 | + if (empty($buyPrice) && isset(Globals::$conf->global->MARGIN_TYPE) && in_array(Globals::$conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice'))) {
|
|
| 6550 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
| 6551 | + $productFournisseur = new ProductFournisseur($this->db); |
|
| 6552 | + if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
|
| 6553 | + {
|
|
| 6554 | + $buyPrice = $productFournisseur->fourn_unitprice; |
|
| 6555 | + } |
|
| 6556 | + else if ($result < 0) |
|
| 6557 | + {
|
|
| 6558 | + $this->errors[] = $productFournisseur->error; |
|
| 6559 | + return -2; |
|
| 6560 | + } |
|
| 6561 | + } |
|
| 6562 | + } |
|
| 6563 | + } |
|
| 6564 | + return $buyPrice; |
|
| 6565 | + } |
|
| 6566 | + |
|
| 6567 | + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 6568 | + /** |
|
| 6569 | + * Show photos of an object (nbmax maximum), into several columns |
|
| 6570 | + * |
|
| 6571 | + * @param string $modulepart 'product', 'ticket', ... |
|
| 6572 | + * @param string $sdir Directory to scan (full absolute path) |
|
| 6573 | + * @param int $size 0=original size, 1='small' use thumbnail if possible |
|
| 6574 | + * @param int $nbmax Nombre maximum de photos (0=pas de max) |
|
| 6575 | + * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. |
|
| 6576 | + * @param int $showfilename 1=Show filename |
|
| 6577 | + * @param int $showaction 1=Show icon with action links (resize, delete) |
|
| 6578 | + * @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. |
|
| 6579 | + * @param int $maxWidth Max width of original image when size='small' |
|
| 6580 | + * @param int $nolink Do not add a href link to view enlarged imaged into a new tab |
|
| 6581 | + * @param int $notitle Do not add title tag on image |
|
| 6582 | + * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
|
| 6583 | + * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
|
| 6584 | + */ |
|
| 6585 | + 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) |
|
| 6586 | + {
|
|
| 6587 | + // phpcs:enable |
|
| 6588 | + global $conf,$user,$langs; |
|
| 6589 | + |
|
| 6590 | + include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
| 6591 | + include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
| 6592 | + |
|
| 6593 | + $sortfield='position_name'; |
|
| 6594 | + $sortorder='asc'; |
|
| 6595 | + |
|
| 6596 | + $dir = $sdir . '/'; |
|
| 6597 | + $pdir = '/'; |
|
| 6598 | + if ($modulepart == 'ticket') |
|
| 6599 | + {
|
|
| 6600 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6601 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6602 | + } |
|
| 6603 | + else |
|
| 6604 | + {
|
|
| 6605 | + $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6606 | + $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6607 | + } |
|
| 6608 | + |
|
| 6609 | + // For backward compatibility |
|
| 6610 | + if ($modulepart == 'product' && !empty(Globals::$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
|
|
| 6611 | + $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6612 | + $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6613 | + } |
|
| 6614 | + |
|
| 6615 | + // Defined relative dir to DOL_DATA_ROOT |
|
| 6616 | + $relativedir = ''; |
|
| 6617 | + if ($dir) |
|
| 6618 | + {
|
|
| 6619 | + $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
|
| 6620 | + $relativedir = preg_replace('/^[\\/]/','',$relativedir);
|
|
| 6621 | + $relativedir = preg_replace('/[\\/]$/','',$relativedir);
|
|
| 6622 | + } |
|
| 6623 | + |
|
| 6624 | + $dirthumb = $dir.'thumbs/'; |
|
| 6625 | + $pdirthumb = $pdir.'thumbs/'; |
|
| 6626 | + |
|
| 6627 | + $return ='<!-- Photo -->'."\n"; |
|
| 6628 | + $nbphoto=0; |
|
| 6629 | + |
|
| 6630 | + $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6631 | + |
|
| 6632 | + /* if (! empty(Globals::$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
|
| 6633 | + {
|
|
| 6634 | + $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6635 | + $filearray=array_merge($filearray, $filearrayold); |
|
| 6636 | + } */ |
|
| 6637 | + |
|
| 6638 | + completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
| 6639 | + |
|
| 6640 | + if (count($filearray)) |
|
| 6641 | + {
|
|
| 6642 | + if ($sortfield && $sortorder) |
|
| 6643 | + {
|
|
| 6644 | + $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6645 | + } |
|
| 6646 | + |
|
| 6647 | + foreach($filearray as $key => $val) |
|
| 6648 | + {
|
|
| 6649 | + $photo=''; |
|
| 6650 | + $file = $val['name']; |
|
| 6651 | + |
|
| 6652 | + //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
|
| 6653 | + |
|
| 6654 | + //if (dol_is_file($dir.$file) && image_format_supported($file) >= 0) |
|
| 6655 | + if (image_format_supported($file) >= 0) |
|
| 6656 | + {
|
|
| 6657 | + $nbphoto++; |
|
| 6658 | + $photo = $file; |
|
| 6659 | + $viewfilename = $file; |
|
| 6660 | + |
|
| 6661 | + if ($size == 1 || $size == 'small') { // Format vignette
|
|
| 6662 | + |
|
| 6663 | + // Find name of thumb file |
|
| 6664 | + $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6665 | + if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 6666 | + |
|
| 6667 | + // Get filesize of original file |
|
| 6668 | + $imgarray=dol_getImageSize($dir.$photo); |
|
| 6669 | + |
|
| 6670 | + if ($nbbyrow > 0) |
|
| 6671 | + {
|
|
| 6672 | + if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 6673 | + |
|
| 6674 | + if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 6675 | + $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
| 6676 | + } |
|
| 6677 | + else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 6678 | + |
|
| 6679 | + $return.= "\n"; |
|
| 6680 | + |
|
| 6681 | + $relativefile=preg_replace('/^\//', '', $pdir.$photo);
|
|
| 6682 | + if (empty($nolink)) |
|
| 6683 | + {
|
|
| 6684 | + $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
| 6685 | + if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6686 | + else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 6687 | + } |
|
| 6688 | + |
|
| 6689 | + // Show image (width height=$maxHeight) |
|
| 6690 | + // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
|
| 6691 | + $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
| 6692 | + $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
| 6693 | + if ($notitle) $alt=''; |
|
| 6694 | + |
|
| 6695 | + if ($usesharelink) |
|
| 6696 | + {
|
|
| 6697 | + if ($val['share']) |
|
| 6698 | + {
|
|
| 6699 | + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6700 | + {
|
|
| 6701 | + $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6702 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6703 | + } |
|
| 6704 | + else {
|
|
| 6705 | + $return.= '<!-- Show original file -->'; |
|
| 6706 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6707 | + } |
|
| 6708 | + } |
|
| 6709 | + else |
|
| 6710 | + {
|
|
| 6711 | + $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6712 | + $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6713 | + } |
|
| 6714 | + } |
|
| 6715 | + else |
|
| 6716 | + {
|
|
| 6717 | + if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6718 | + {
|
|
| 6719 | + $return.= '<!-- Show thumb -->'; |
|
| 6720 | + $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).'">'; |
|
| 6721 | + } |
|
| 6722 | + else {
|
|
| 6723 | + $return.= '<!-- Show original file -->'; |
|
| 6724 | + $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).'">'; |
|
| 6725 | + } |
|
| 6726 | + } |
|
| 6727 | + |
|
| 6728 | + if (empty($nolink)) $return.= '</a>'; |
|
| 6729 | + $return.="\n"; |
|
| 6730 | + |
|
| 6731 | + if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6732 | + if ($showaction) |
|
| 6733 | + {
|
|
| 6734 | + $return.= '<br>'; |
|
| 6735 | + // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
|
| 6736 | + if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
|
| 6737 | + {
|
|
| 6738 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>';
|
|
| 6739 | + } |
|
| 6740 | + // Special cas for product |
|
| 6741 | + if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6742 | + {
|
|
| 6743 | + // Link to resize |
|
| 6744 | + $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> ';
|
|
| 6745 | + |
|
| 6746 | + // Link to delete |
|
| 6747 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6748 | + $return.= img_delete().'</a>'; |
|
| 6749 | + } |
|
| 6750 | + } |
|
| 6751 | + $return.= "\n"; |
|
| 6752 | + |
|
| 6753 | + if ($nbbyrow > 0) |
|
| 6754 | + {
|
|
| 6755 | + $return.= '</td>'; |
|
| 6756 | + if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6757 | + } |
|
| 6758 | + else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6759 | + } |
|
| 6760 | + |
|
| 6761 | + if (empty($size)) { // Format origine
|
|
| 6762 | + $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6763 | + |
|
| 6764 | + if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6765 | + if ($showaction) |
|
| 6766 | + {
|
|
| 6767 | + // Special case for product |
|
| 6768 | + if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6769 | + {
|
|
| 6770 | + // Link to resize |
|
| 6771 | + $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> ';
|
|
| 6772 | + |
|
| 6773 | + // Link to delete |
|
| 6774 | + $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6775 | + $return.= img_delete().'</a>'; |
|
| 6776 | + } |
|
| 6777 | + } |
|
| 6778 | + } |
|
| 6779 | + |
|
| 6780 | + // On continue ou on arrete de boucler ? |
|
| 6781 | + if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 6782 | + } |
|
| 6783 | + } |
|
| 6784 | + |
|
| 6785 | + if ($size==1 || $size=='small') |
|
| 6786 | + {
|
|
| 6787 | + if ($nbbyrow > 0) |
|
| 6788 | + {
|
|
| 6789 | + // Ferme tableau |
|
| 6790 | + while ($nbphoto % $nbbyrow) |
|
| 6791 | + {
|
|
| 6792 | + $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
| 6793 | + $nbphoto++; |
|
| 6794 | + } |
|
| 6795 | + |
|
| 6796 | + if ($nbphoto) $return.= '</table>'; |
|
| 6797 | + } |
|
| 6798 | + } |
|
| 6799 | + } |
|
| 6800 | + |
|
| 6801 | + $this->nbphoto = $nbphoto; |
|
| 6802 | + |
|
| 6803 | + return $return; |
|
| 6804 | + } |
|
| 6805 | + |
|
| 6806 | + |
|
| 6807 | + /** |
|
| 6808 | + * Function test if type is array |
|
| 6809 | + * |
|
| 6810 | + * @param array $info content informations of field |
|
| 6811 | + * @return bool |
|
| 6812 | + */ |
|
| 6813 | + protected function isArray($info) |
|
| 6814 | + {
|
|
| 6815 | + if(is_array($info)) |
|
| 6816 | + {
|
|
| 6817 | + if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6818 | + else return false; |
|
| 6819 | + } |
|
| 6820 | + else return false; |
|
| 6821 | + } |
|
| 6822 | + |
|
| 6823 | + /** |
|
| 6824 | + * Function test if type is null |
|
| 6825 | + * |
|
| 6826 | + * @param array $info content informations of field |
|
| 6827 | + * @return bool |
|
| 6828 | + */ |
|
| 6829 | + protected function isNull($info) |
|
| 6830 | + {
|
|
| 6831 | + if(is_array($info)) |
|
| 6832 | + {
|
|
| 6833 | + if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6834 | + else return false; |
|
| 6835 | + } |
|
| 6836 | + else return false; |
|
| 6837 | + } |
|
| 6838 | + |
|
| 6839 | + /** |
|
| 6840 | + * Function test if type is date |
|
| 6841 | + * |
|
| 6842 | + * @param array $info content informations of field |
|
| 6843 | + * @return bool |
|
| 6844 | + */ |
|
| 6845 | + public function isDate($info) |
|
| 6846 | + {
|
|
| 6847 | + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6848 | + else return false; |
|
| 6849 | + } |
|
| 6850 | + |
|
| 6851 | + /** |
|
| 6852 | + * Function test if type is integer |
|
| 6853 | + * |
|
| 6854 | + * @param array $info content informations of field |
|
| 6855 | + * @return bool |
|
| 6856 | + */ |
|
| 6857 | + public function isInt($info) |
|
| 6858 | + {
|
|
| 6859 | + if(is_array($info)) |
|
| 6860 | + {
|
|
| 6861 | + if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6862 | + else return false; |
|
| 6863 | + } |
|
| 6864 | + else return false; |
|
| 6865 | + } |
|
| 6866 | + |
|
| 6867 | + /** |
|
| 6868 | + * Function test if type is float |
|
| 6869 | + * |
|
| 6870 | + * @param array $info content informations of field |
|
| 6871 | + * @return bool |
|
| 6872 | + */ |
|
| 6873 | + public function isFloat($info) |
|
| 6874 | + {
|
|
| 6875 | + if(is_array($info)) |
|
| 6876 | + {
|
|
| 6877 | + if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
|
| 6878 | + else return false; |
|
| 6879 | + } |
|
| 6880 | + else return false; |
|
| 6881 | + } |
|
| 6882 | + |
|
| 6883 | + /** |
|
| 6884 | + * Function test if type is text |
|
| 6885 | + * |
|
| 6886 | + * @param array $info content informations of field |
|
| 6887 | + * @return bool |
|
| 6888 | + */ |
|
| 6889 | + public function isText($info) |
|
| 6890 | + {
|
|
| 6891 | + if(is_array($info)) |
|
| 6892 | + {
|
|
| 6893 | + if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6894 | + else return false; |
|
| 6895 | + } |
|
| 6896 | + else return false; |
|
| 6897 | + } |
|
| 6898 | + |
|
| 6899 | + /** |
|
| 6900 | + * Function test if is indexed |
|
| 6901 | + * |
|
| 6902 | + * @param array $info content informations of field |
|
| 6903 | + * @return bool |
|
| 6904 | + */ |
|
| 6905 | + protected function isIndex($info) |
|
| 6906 | + {
|
|
| 6907 | + if(is_array($info)) |
|
| 6908 | + {
|
|
| 6909 | + if(isset($info['index']) && $info['index']==true) return true; |
|
| 6910 | + else return false; |
|
| 6911 | + } |
|
| 6912 | + else return false; |
|
| 6913 | + } |
|
| 6914 | + |
|
| 6915 | + /** |
|
| 6916 | + * Function to prepare the values to insert. |
|
| 6917 | + * Note $this->${field} are set by the page that make the createCommon or the updateCommon.
|
|
| 6918 | + * |
|
| 6919 | + * @return array |
|
| 6920 | + */ |
|
| 6921 | + protected function setSaveQuery() |
|
| 6922 | + {
|
|
| 6923 | + global $conf; |
|
| 6924 | + |
|
| 6925 | + $queryarray=array(); |
|
| 6926 | + foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 6927 | + {
|
|
| 6928 | + // Depending on field type ('datetime', ...)
|
|
| 6929 | + if($this->isDate($info)) |
|
| 6930 | + {
|
|
| 6931 | + if(empty($this->{$field}))
|
|
| 6932 | + {
|
|
| 6933 | + $queryarray[$field] = null; |
|
| 6934 | + } |
|
| 6935 | + else |
|
| 6936 | + {
|
|
| 6937 | + $queryarray[$field] = $this->db->idate($this->{$field});
|
|
| 6938 | + } |
|
| 6939 | + } |
|
| 6940 | + else if($this->isArray($info)) |
|
| 6941 | + {
|
|
| 6942 | + if(! empty($this->{$field})) {
|
|
| 6943 | + if(! is_array($this->{$field})) {
|
|
| 6944 | + $this->{$field} = array($this->{$field});
|
|
| 6945 | + } |
|
| 6946 | + $queryarray[$field] = serialize($this->{$field});
|
|
| 6947 | + } else {
|
|
| 6948 | + $queryarray[$field] = null; |
|
| 6949 | + } |
|
| 6950 | + } |
|
| 6951 | + else if($this->isInt($info)) |
|
| 6952 | + {
|
|
| 6953 | + if ($field == 'entity' && is_null($this->{$field}))
|
|
| 6954 | + $queryarray[$field] = Globals::$conf->entity; |
|
| 6955 | + else |
|
| 6956 | + {
|
|
| 6957 | + $queryarray[$field] = (int) price2num($this->{$field});
|
|
| 6958 | + if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6959 | + } |
|
| 6960 | + } |
|
| 6961 | + else if($this->isFloat($info)) |
|
| 6962 | + {
|
|
| 6963 | + $queryarray[$field] = (double) price2num($this->{$field});
|
|
| 6964 | + if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6965 | + } |
|
| 6966 | + else |
|
| 6967 | + {
|
|
| 6968 | + $queryarray[$field] = $this->{$field};
|
|
| 6969 | + } |
|
| 6970 | + |
|
| 6971 | + if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6972 | + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6973 | + } |
|
| 6974 | + |
|
| 6975 | + return $queryarray; |
|
| 6976 | + } |
|
| 6977 | + |
|
| 6978 | + /** |
|
| 6979 | + * Function to load data from a SQL pointer into properties of current object $this |
|
| 6980 | + * |
|
| 6981 | + * @param stdClass $obj Contain data of object from database |
|
| 6982 | + * @return void |
|
| 6983 | + */ |
|
| 6984 | + protected function setVarsFromFetchObj(&$obj) |
|
| 6985 | + {
|
|
| 6986 | + foreach ($this->fields as $field => $info) |
|
| 6987 | + {
|
|
| 6988 | + if($this->isDate($info)) |
|
| 6989 | + {
|
|
| 6990 | + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6991 | + else $this->{$field} = strtotime($obj->{$field});
|
|
| 6992 | + } |
|
| 6993 | + elseif($this->isArray($info)) |
|
| 6994 | + {
|
|
| 6995 | + if(! empty($obj->{$field})) {
|
|
| 6996 | + $this->{$field} = @unserialize($obj->{$field});
|
|
| 6997 | + // Hack for data not in UTF8 |
|
| 6998 | + if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 6999 | + } else {
|
|
| 7000 | + $this->{$field} = array();
|
|
| 7001 | + } |
|
| 7002 | + } |
|
| 7003 | + elseif($this->isInt($info)) |
|
| 7004 | + {
|
|
| 7005 | + if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
|
| 7006 | + else $this->{$field} = (int) $obj->{$field};
|
|
| 7007 | + } |
|
| 7008 | + elseif($this->isFloat($info)) |
|
| 7009 | + {
|
|
| 7010 | + $this->{$field} = (double) $obj->{$field};
|
|
| 7011 | + } |
|
| 7012 | + elseif($this->isNull($info)) |
|
| 7013 | + {
|
|
| 7014 | + $val = $obj->{$field};
|
|
| 7015 | + // zero is not null |
|
| 7016 | + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
|
| 7017 | + } |
|
| 7018 | + else |
|
| 7019 | + {
|
|
| 7020 | + $this->{$field} = $obj->{$field};
|
|
| 7021 | + } |
|
| 7022 | + } |
|
| 7023 | + |
|
| 7024 | + // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
|
| 7025 | + if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7026 | + } |
|
| 7027 | + |
|
| 7028 | + /** |
|
| 7029 | + * Function to concat keys of fields |
|
| 7030 | + * |
|
| 7031 | + * @return string |
|
| 7032 | + */ |
|
| 7033 | + protected function getFieldList() |
|
| 7034 | + {
|
|
| 7035 | + $keys = array_keys($this->fields); |
|
| 7036 | + return implode(',', $keys);
|
|
| 7037 | + } |
|
| 7038 | + |
|
| 7039 | + /** |
|
| 7040 | + * Add quote to field value if necessary |
|
| 7041 | + * |
|
| 7042 | + * @param string|int $value Value to protect |
|
| 7043 | + * @param array $fieldsentry Properties of field |
|
| 7044 | + * @return string |
|
| 7045 | + */ |
|
| 7046 | + protected function quote($value, $fieldsentry) |
|
| 7047 | + {
|
|
| 7048 | + if (is_null($value)) return 'NULL'; |
|
| 7049 | + else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
|
|
| 7050 | + else return "'".$this->db->escape($value)."'"; |
|
| 7051 | + } |
|
| 7052 | + |
|
| 7053 | + |
|
| 7054 | + /** |
|
| 7055 | + * Create object into database |
|
| 7056 | + * |
|
| 7057 | + * @param User $user User that creates |
|
| 7058 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7059 | + * @return int <0 if KO, Id of created object if OK |
|
| 7060 | + */ |
|
| 7061 | + public function createCommon(User $user, $notrigger = false) |
|
| 7062 | + {
|
|
| 7063 | + global $langs; |
|
| 6161 | 7064 | |
| 6162 | - dol_syslog(get_class($this) . ':showOutputField:$type=chkbxlst',LOG_DEBUG); |
|
| 6163 | - $resql = $this->db->query($sql); |
|
| 6164 | - if ($resql) {
|
|
| 6165 | - $value = ''; // value was used, so now we reste it to use it to build final output |
|
| 6166 | - $toprint=array(); |
|
| 6167 | - while ( $obj = $this->db->fetch_object($resql) ) {
|
|
| 6168 | - |
|
| 6169 | - // Several field into label (eq table:code|libelle:rowid) |
|
| 6170 | - $fields_label = explode('|', $InfoFieldList[1]);
|
|
| 6171 | - if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
|
| 6172 | - if (is_array($fields_label) && count($fields_label) > 1) {
|
|
| 6173 | - foreach ( $fields_label as $field_toshow ) {
|
|
| 6174 | - $translabel = ''; |
|
| 6175 | - if (! empty($obj->$field_toshow)) {
|
|
| 6176 | - $translabel = $langs->trans($obj->$field_toshow); |
|
| 6177 | - } |
|
| 6178 | - if ($translabel != $field_toshow) {
|
|
| 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->$field_toshow.'</li>'; |
|
| 6182 | - } |
|
| 6183 | - } |
|
| 6184 | - } else {
|
|
| 6185 | - $translabel = ''; |
|
| 6186 | - if (! empty($obj->{$InfoFieldList[1]})) {
|
|
| 6187 | - $translabel = $langs->trans($obj->{$InfoFieldList[1]});
|
|
| 6188 | - } |
|
| 6189 | - if ($translabel != $obj->{$InfoFieldList[1]}) {
|
|
| 6190 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.dol_trunc($translabel, 18).'</li>'; |
|
| 6191 | - } else {
|
|
| 6192 | - $toprint[]='<li class="select2-search-choice-dolibarr noborderoncategories" style="background: #aaa">'.$obj->{$InfoFieldList[1]}.'</li>';
|
|
| 6193 | - } |
|
| 6194 | - } |
|
| 6195 | - } |
|
| 6196 | - } |
|
| 6197 | - $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
|
| 6198 | - } else {
|
|
| 6199 | - dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
|
| 6200 | - } |
|
| 6201 | - } |
|
| 6202 | - elseif ($type == 'link') |
|
| 6203 | - {
|
|
| 6204 | - $out=''; |
|
| 6205 | - |
|
| 6206 | - // only if something to display (perf) |
|
| 6207 | - if ($value) |
|
| 6208 | - {
|
|
| 6209 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 7065 | + $error = 0; |
|
| 6210 | 7066 | |
| 6211 | - $InfoFieldList = explode(":", $param_list[0]);
|
|
| 6212 | - $classname=$InfoFieldList[0]; |
|
| 6213 | - $classpath=$InfoFieldList[1]; |
|
| 6214 | - $getnomurlparam=(empty($InfoFieldList[2]) ? 3 : $InfoFieldList[2]); |
|
| 6215 | - if (! empty($classpath)) |
|
| 6216 | - {
|
|
| 6217 | - dol_include_once($InfoFieldList[1]); |
|
| 6218 | - if ($classname && class_exists($classname)) |
|
| 6219 | - {
|
|
| 6220 | - $object = new $classname($this->db); |
|
| 6221 | - $object->fetch($value); |
|
| 6222 | - $value=$object->getNomUrl($getnomurlparam); |
|
| 6223 | - } |
|
| 6224 | - } |
|
| 6225 | - else |
|
| 6226 | - {
|
|
| 6227 | - dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
|
| 6228 | - return 'Error bad setup of extrafield'; |
|
| 6229 | - } |
|
| 6230 | - } |
|
| 6231 | - else $value=''; |
|
| 6232 | - } |
|
| 6233 | - elseif ($type == 'text' || $type == 'html') |
|
| 6234 | - {
|
|
| 6235 | - $value=dol_htmlentitiesbr($value); |
|
| 6236 | - } |
|
| 6237 | - elseif ($type == 'password') |
|
| 6238 | - {
|
|
| 6239 | - $value=preg_replace('/./i','*',$value);
|
|
| 6240 | - } |
|
| 6241 | - elseif ($type == 'array') |
|
| 6242 | - {
|
|
| 6243 | - $value = implode('<br>', $value);
|
|
| 6244 | - } |
|
| 6245 | - |
|
| 6246 | - //print $type.'-'.$size; |
|
| 6247 | - $out=$value; |
|
| 6248 | - |
|
| 6249 | - return $out; |
|
| 6250 | - } |
|
| 6251 | - |
|
| 6252 | - |
|
| 6253 | - /** |
|
| 6254 | - * Function to show lines of extrafields with output datas |
|
| 6255 | - * |
|
| 6256 | - * @param Extrafields $extrafields Extrafield Object |
|
| 6257 | - * @param string $mode Show output (view) or input (edit) for extrafield |
|
| 6258 | - * @param array $params Optional parameters. Example: array('style'=>'class="oddeven"', 'colspan'=>$colspan)
|
|
| 6259 | - * @param string $keysuffix Suffix string to add after name and id of field (can be used to avoid duplicate names) |
|
| 6260 | - * @param string $keyprefix Prefix string to add before name and id of field (can be used to avoid duplicate names) |
|
| 6261 | - * @param string $onetrtd All fields in same tr td |
|
| 6262 | - * @return string |
|
| 6263 | - */ |
|
| 6264 | - function showOptionals($extrafields, $mode='view', $params=null, $keysuffix='', $keyprefix='', $onetrtd=0) |
|
| 6265 | - {
|
|
| 6266 | - global $db, $conf, $langs, $action, $form; |
|
| 6267 | - |
|
| 6268 | - if (! is_object($form)) $form=new Form($db); |
|
| 6269 | - |
|
| 6270 | - $out = ''; |
|
| 6271 | - |
|
| 6272 | - if (is_array($extrafields->attributes[$this->table_element]['label']) && count($extrafields->attributes[$this->table_element]['label']) > 0) |
|
| 6273 | - {
|
|
| 6274 | - $out .= "\n"; |
|
| 6275 | - $out .= '<!-- showOptionalsInput --> '; |
|
| 6276 | - $out .= "\n"; |
|
| 6277 | - |
|
| 6278 | - $e = 0; |
|
| 6279 | - foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
|
| 6280 | - {
|
|
| 6281 | - // Show only the key field in params |
|
| 6282 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 7067 | + $now=dol_now(); |
|
| 6283 | 7068 | |
| 6284 | - $enabled = 1; |
|
| 6285 | - if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
|
| 6286 | - {
|
|
| 6287 | - $enabled = dol_eval($extrafields->attributes[$this->table_element]['list'][$key], 1); |
|
| 6288 | - } |
|
| 7069 | + $fieldvalues = $this->setSaveQuery(); |
|
| 7070 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7071 | + if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7072 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 6289 | 7073 | |
| 6290 | - $perms = 1; |
|
| 6291 | - if ($perms && isset($extrafields->attributes[$this->table_element]['perms'][$key])) |
|
| 6292 | - {
|
|
| 6293 | - $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
|
| 6294 | - } |
|
| 7074 | + $keys=array(); |
|
| 7075 | + $values = array(); |
|
| 7076 | + foreach ($fieldvalues as $k => $v) {
|
|
| 7077 | + $keys[$k] = $k; |
|
| 7078 | + $value = $this->fields[$k]; |
|
| 7079 | + $values[$k] = $this->quote($v, $value); |
|
| 7080 | + } |
|
| 6295 | 7081 | |
| 6296 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6297 | - if (empty($perms)) continue; |
|
| 7082 | + // Clean and check mandatory |
|
| 7083 | + foreach($keys as $key) |
|
| 7084 | + {
|
|
| 7085 | + // If field is an implicit foreign key field |
|
| 7086 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7087 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 6298 | 7088 | |
| 6299 | - // Load language if required |
|
| 6300 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 7089 | + //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7090 | + if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
| 7091 | + {
|
|
| 7092 | + $error++; |
|
| 7093 | + $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7094 | + } |
|
| 6301 | 7095 | |
| 6302 | - $colspan='3'; |
|
| 6303 | - if (is_array($params) && count($params)>0) {
|
|
| 6304 | - if (array_key_exists('colspan',$params)) {
|
|
| 6305 | - $colspan=$params['colspan']; |
|
| 6306 | - } |
|
| 6307 | - } |
|
| 7096 | + // If field is an implicit foreign key field |
|
| 7097 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7098 | + if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7099 | + } |
|
| 6308 | 7100 | |
| 6309 | - switch($mode) {
|
|
| 6310 | - case "view": |
|
| 6311 | - $value=$this->array_options["options_".$key.$keysuffix]; |
|
| 6312 | - break; |
|
| 6313 | - case "edit": |
|
| 6314 | - $getposttemp = GETPOST($keyprefix.'options_'.$key.$keysuffix, 'none'); // GETPOST can get value from GET, POST or setup of default values. |
|
| 6315 | - // GETPOST("options_" . $key) can be 'abc' or array(0=>'abc')
|
|
| 6316 | - if (is_array($getposttemp) || $getposttemp != '' || GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) |
|
| 6317 | - {
|
|
| 6318 | - if (is_array($getposttemp)) {
|
|
| 6319 | - // $getposttemp is an array but following code expects a comma separated string |
|
| 6320 | - $value = implode(",", $getposttemp);
|
|
| 6321 | - } else {
|
|
| 6322 | - $value = $getposttemp; |
|
| 6323 | - } |
|
| 6324 | - } else {
|
|
| 6325 | - $value = $this->array_options["options_" . $key]; // No GET, no POST, no default value, so we take value of object. |
|
| 6326 | - } |
|
| 6327 | - //var_dump($keyprefix.' - '.$key.' - '.$keysuffix.' - '.$keyprefix.'options_'.$key.$keysuffix.' - '.$this->array_options["options_".$key.$keysuffix].' - '.$getposttemp.' - '.$value); |
|
| 6328 | - break; |
|
| 6329 | - } |
|
| 7101 | + if ($error) return -1; |
|
| 6330 | 7102 | |
| 6331 | - if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
|
| 6332 | - {
|
|
| 6333 | - $out .= $extrafields->showSeparator($key, $this); |
|
| 6334 | - } |
|
| 6335 | - else |
|
| 6336 | - {
|
|
| 6337 | - $csstyle=''; |
|
| 6338 | - $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
|
| 6339 | - if (is_array($params) && count($params)>0) {
|
|
| 6340 | - if (array_key_exists('style',$params)) {
|
|
| 6341 | - $csstyle=$params['style']; |
|
| 6342 | - } |
|
| 6343 | - } |
|
| 7103 | + $this->db->begin(); |
|
| 6344 | 7104 | |
| 6345 | - // add html5 elements |
|
| 6346 | - $domData = ' data-element="extrafield"'; |
|
| 6347 | - $domData .= ' data-targetelement="'.$this->element.'"'; |
|
| 6348 | - $domData .= ' data-targetid="'.$this->id.'"'; |
|
| 7105 | + if (! $error) |
|
| 7106 | + {
|
|
| 7107 | + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7108 | + $sql.= ' ('.implode( ", ", $keys ).')';
|
|
| 7109 | + $sql.= ' VALUES ('.implode( ", ", $values ).')';
|
|
| 7110 | + |
|
| 7111 | + $res = $this->db->query($sql); |
|
| 7112 | + if ($res===false) {
|
|
| 7113 | + $error++; |
|
| 7114 | + $this->errors[] = $this->db->lasterror(); |
|
| 7115 | + } |
|
| 7116 | + } |
|
| 6349 | 7117 | |
| 6350 | - $html_id = !empty($this->id) ? 'extrarow-'.$this->element.'_'.$key.'_'.$this->id : ''; |
|
| 7118 | + if (! $error) |
|
| 7119 | + {
|
|
| 7120 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 7121 | + } |
|
| 6351 | 7122 | |
| 6352 | - $out .= '<tr id="'.$html_id.'" '.$csstyle.' class="'.$class.$this->element.'_extras_'.$key.'" '.$domData.' >'; |
|
| 7123 | + // Create extrafields |
|
| 7124 | + if (! $error) |
|
| 7125 | + {
|
|
| 7126 | + $result=$this->insertExtraFields(); |
|
| 7127 | + if ($result < 0) $error++; |
|
| 7128 | + } |
|
| 6353 | 7129 | |
| 6354 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
|
|
| 6355 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && ($e % 2) == 0) {
|
|
| 6356 | - $colspan = '0'; |
|
| 6357 | - } |
|
| 6358 | - } |
|
| 7130 | + // Triggers |
|
| 7131 | + if (! $error && ! $notrigger) |
|
| 7132 | + {
|
|
| 7133 | + // Call triggers |
|
| 7134 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 7135 | + if ($result < 0) { $error++; }
|
|
| 7136 | + // End call triggers |
|
| 7137 | + } |
|
| 6359 | 7138 | |
| 6360 | - if ($action == 'selectlines') { $colspan++; }
|
|
| 7139 | + // Commit or rollback |
|
| 7140 | + if ($error) {
|
|
| 7141 | + $this->db->rollback(); |
|
| 7142 | + return -1; |
|
| 7143 | + } else {
|
|
| 7144 | + $this->db->commit(); |
|
| 7145 | + return $this->id; |
|
| 7146 | + } |
|
| 7147 | + } |
|
| 6361 | 7148 | |
| 6362 | - // Convert date into timestamp format (value in memory must be a timestamp) |
|
| 6363 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
|
| 6364 | - {
|
|
| 6365 | - $datenotinstring = $this->array_options['options_' . $key]; |
|
| 6366 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6367 | - {
|
|
| 6368 | - $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6369 | - } |
|
| 6370 | - $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; |
|
| 6371 | - } |
|
| 6372 | - // Convert float submited string into real php numeric (value in memory must be a php numeric) |
|
| 6373 | - if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('price','double')))
|
|
| 6374 | - {
|
|
| 6375 | - $value = GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)?price2num(GETPOST($keyprefix.'options_'.$key.$keysuffix, 'alpha', 3)):$this->array_options['options_'.$key]; |
|
| 6376 | - } |
|
| 6377 | - |
|
| 6378 | - $labeltoshow = $langs->trans($label); |
|
| 6379 | - |
|
| 6380 | - $out .= '<td class="titlefield'; |
|
| 6381 | - if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6382 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6383 | - $out .= '">'; |
|
| 6384 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6385 | - else $out .= $labeltoshow; |
|
| 6386 | - $out .= '</td>'; |
|
| 6387 | - |
|
| 6388 | - $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
|
| 6389 | - $out .='<td id="'.$html_id.'" class="'.$this->element.'_extras_'.$key.'" '.($colspan?' colspan="'.$colspan.'"':'').'>'; |
|
| 6390 | - |
|
| 6391 | - switch($mode) {
|
|
| 6392 | - case "view": |
|
| 6393 | - $out .= $extrafields->showOutputField($key, $value); |
|
| 6394 | - break; |
|
| 6395 | - case "edit": |
|
| 6396 | - $out .= $extrafields->showInputField($key, $value, '', $keysuffix, '', 0, $this->id); |
|
| 6397 | - break; |
|
| 6398 | - } |
|
| 6399 | - |
|
| 6400 | - $out .= '</td>'; |
|
| 6401 | - |
|
| 6402 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) |
|
| 6403 | - $out .= '</tr>'; |
|
| 6404 | - else $out .= '</tr>'; |
|
| 6405 | - $e++; |
|
| 6406 | - } |
|
| 6407 | - } |
|
| 6408 | - $out .= "\n"; |
|
| 6409 | - // Add code to manage list depending on others |
|
| 6410 | - if (!empty(Globals::$conf->use_javascript_ajax)) {
|
|
| 6411 | - $out .= ' |
|
| 6412 | - <script type="text/javascript"> |
|
| 6413 | - jQuery(document).ready(function() {
|
|
| 6414 | - function showOptions(child_list, parent_list) |
|
| 6415 | - {
|
|
| 6416 | - var val = $("select[name=\"options_"+parent_list+"\"]").val();
|
|
| 6417 | - var parentVal = parent_list + ":" + val; |
|
| 6418 | - if(val > 0) {
|
|
| 6419 | - $("select[name=\""+child_list+"\"] option[parent]").hide();
|
|
| 6420 | - $("select[name=\""+child_list+"\"] option[parent=\""+parentVal+"\"]").show();
|
|
| 6421 | - } else {
|
|
| 6422 | - $("select[name=\""+child_list+"\"] option").show();
|
|
| 6423 | - } |
|
| 6424 | - } |
|
| 6425 | - function setListDependencies() {
|
|
| 6426 | - jQuery("select option[parent]").parent().each(function() {
|
|
| 6427 | - var child_list = $(this).attr("name");
|
|
| 6428 | - var parent = $(this).find("option[parent]:first").attr("parent");
|
|
| 6429 | - var infos = parent.split(":");
|
|
| 6430 | - var parent_list = infos[0]; |
|
| 6431 | - $("select[name=\""+parent_list+"\"]").change(function() {
|
|
| 6432 | - showOptions(child_list, parent_list); |
|
| 6433 | - }); |
|
| 6434 | - }); |
|
| 6435 | - } |
|
| 6436 | 7149 | |
| 6437 | - setListDependencies(); |
|
| 6438 | - }); |
|
| 6439 | - </script>'."\n"; |
|
| 6440 | - $out .= '<!-- /showOptionalsInput --> '."\n"; |
|
| 6441 | - } |
|
| 6442 | - } |
|
| 6443 | - return $out; |
|
| 6444 | - } |
|
| 6445 | - |
|
| 6446 | - |
|
| 6447 | - /** |
|
| 6448 | - * Returns the rights used for this class |
|
| 6449 | - * @return stdClass |
|
| 6450 | - */ |
|
| 6451 | - public function getRights() |
|
| 6452 | - {
|
|
| 6453 | - global $user; |
|
| 6454 | - |
|
| 6455 | - $element = $this->element; |
|
| 6456 | - if ($element == 'facturerec') $element='facture'; |
|
| 6457 | - |
|
| 6458 | - return $user->rights->{$element};
|
|
| 6459 | - } |
|
| 6460 | - |
|
| 6461 | - /** |
|
| 6462 | - * Function used to replace a thirdparty id with another one. |
|
| 6463 | - * This function is meant to be called from replaceThirdparty with the appropiate tables |
|
| 6464 | - * Column name fk_soc MUST be used to identify thirdparties |
|
| 6465 | - * |
|
| 6466 | - * @param DoliDB $db Database handler |
|
| 6467 | - * @param int $origin_id Old thirdparty id (the thirdparty to delete) |
|
| 6468 | - * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) |
|
| 6469 | - * @param string[] $tables Tables that need to be changed |
|
| 6470 | - * @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) |
|
| 6471 | - * @return bool True if success, False if error |
|
| 6472 | - */ |
|
| 6473 | - public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) |
|
| 6474 | - {
|
|
| 6475 | - foreach ($tables as $table) |
|
| 6476 | - {
|
|
| 6477 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; |
|
| 6478 | - |
|
| 6479 | - if (! $db->query($sql)) |
|
| 6480 | - {
|
|
| 6481 | - 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. |
|
| 6482 | - //$this->errors = $db->lasterror(); |
|
| 6483 | - return false; |
|
| 6484 | - } |
|
| 6485 | - } |
|
| 6486 | - |
|
| 6487 | - return true; |
|
| 6488 | - } |
|
| 6489 | - |
|
| 6490 | - /** |
|
| 6491 | - * Get buy price to use for margin calculation. This function is called when buy price is unknown. |
|
| 6492 | - * Set buy price = sell price if ForceBuyingPriceIfNull configured, |
|
| 6493 | - * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice |
|
| 6494 | - * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice |
|
| 6495 | - * else set min buy price as buy price |
|
| 6496 | - * |
|
| 6497 | - * @param float $unitPrice Product unit price |
|
| 6498 | - * @param float $discountPercent Line discount percent |
|
| 6499 | - * @param int $fk_product Product id |
|
| 6500 | - * @return float <0 if KO, buyprice if OK |
|
| 6501 | - */ |
|
| 6502 | - public function defineBuyPrice($unitPrice = 0.0, $discountPercent = 0.0, $fk_product = 0) |
|
| 6503 | - {
|
|
| 6504 | - global $conf; |
|
| 6505 | - |
|
| 6506 | - $buyPrice = 0; |
|
| 6507 | - |
|
| 6508 | - if (($unitPrice > 0) && (isset(Globals::$conf->global->ForceBuyingPriceIfNull) && Globals::$conf->global->ForceBuyingPriceIfNull == 1)) { // In most cases, test here is false{
|
|
| 6509 | - $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
|
| 6510 | - } |
|
| 6511 | - else |
|
| 6512 | - {
|
|
| 6513 | - // Get cost price for margin calculation |
|
| 6514 | - if (! empty($fk_product)) |
|
| 6515 | - {
|
|
| 6516 | - if (isset(Globals::$conf->global->MARGIN_TYPE) && Globals::$conf->global->MARGIN_TYPE == 'costprice') {
|
|
| 6517 | - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6518 | - $product = new Product($this->db); |
|
| 6519 | - $result = $product->fetch($fk_product); |
|
| 6520 | - if ($result <= 0) |
|
| 6521 | - {
|
|
| 6522 | - $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6523 | - return -1; |
|
| 6524 | - } |
|
| 6525 | - if ($product->cost_price > 0) |
|
| 6526 | - {
|
|
| 6527 | - $buyPrice = $product->cost_price; |
|
| 6528 | - } |
|
| 6529 | - else if ($product->pmp > 0) |
|
| 6530 | - {
|
|
| 6531 | - $buyPrice = $product->pmp; |
|
| 6532 | - } |
|
| 6533 | - } |
|
| 6534 | - else if (isset(Globals::$conf->global->MARGIN_TYPE) && Globals::$conf->global->MARGIN_TYPE == 'pmp') {
|
|
| 6535 | - require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
|
| 6536 | - $product = new Product($this->db); |
|
| 6537 | - $result = $product->fetch($fk_product); |
|
| 6538 | - if ($result <= 0) |
|
| 6539 | - {
|
|
| 6540 | - $this->errors[] = 'ErrorProductIdDoesNotExists'; |
|
| 6541 | - return -1; |
|
| 6542 | - } |
|
| 6543 | - if ($product->pmp > 0) |
|
| 6544 | - {
|
|
| 6545 | - $buyPrice = $product->pmp; |
|
| 6546 | - } |
|
| 6547 | - } |
|
| 7150 | + /** |
|
| 7151 | + * Load object in memory from the database |
|
| 7152 | + * |
|
| 7153 | + * @param int $id Id object |
|
| 7154 | + * @param string $ref Ref |
|
| 7155 | + * @param string $morewhere More SQL filters (' AND ...')
|
|
| 7156 | + * @return int <0 if KO, 0 if not found, >0 if OK |
|
| 7157 | + */ |
|
| 7158 | + public function fetchCommon($id, $ref = null, $morewhere = '') |
|
| 7159 | + {
|
|
| 7160 | + if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 6548 | 7161 | |
| 6549 | - if (empty($buyPrice) && isset(Globals::$conf->global->MARGIN_TYPE) && in_array(Globals::$conf->global->MARGIN_TYPE, array('1', 'pmp', 'costprice'))) {
|
|
| 6550 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; |
|
| 6551 | - $productFournisseur = new ProductFournisseur($this->db); |
|
| 6552 | - if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
|
| 6553 | - {
|
|
| 6554 | - $buyPrice = $productFournisseur->fourn_unitprice; |
|
| 6555 | - } |
|
| 6556 | - else if ($result < 0) |
|
| 6557 | - {
|
|
| 6558 | - $this->errors[] = $productFournisseur->error; |
|
| 6559 | - return -2; |
|
| 6560 | - } |
|
| 6561 | - } |
|
| 6562 | - } |
|
| 6563 | - } |
|
| 6564 | - return $buyPrice; |
|
| 6565 | - } |
|
| 7162 | + $sql = 'SELECT '.$this->getFieldList(); |
|
| 7163 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 6566 | 7164 | |
| 6567 | - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
|
| 6568 | - /** |
|
| 6569 | - * Show photos of an object (nbmax maximum), into several columns |
|
| 6570 | - * |
|
| 6571 | - * @param string $modulepart 'product', 'ticket', ... |
|
| 6572 | - * @param string $sdir Directory to scan (full absolute path) |
|
| 6573 | - * @param int $size 0=original size, 1='small' use thumbnail if possible |
|
| 6574 | - * @param int $nbmax Nombre maximum de photos (0=pas de max) |
|
| 6575 | - * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. |
|
| 6576 | - * @param int $showfilename 1=Show filename |
|
| 6577 | - * @param int $showaction 1=Show icon with action links (resize, delete) |
|
| 6578 | - * @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. |
|
| 6579 | - * @param int $maxWidth Max width of original image when size='small' |
|
| 6580 | - * @param int $nolink Do not add a href link to view enlarged imaged into a new tab |
|
| 6581 | - * @param int $notitle Do not add title tag on image |
|
| 6582 | - * @param int $usesharelink Use the public shared link of image (if not available, the 'nophoto' image will be shown instead) |
|
| 6583 | - * @return string Html code to show photo. Number of photos shown is saved in this->nbphoto |
|
| 6584 | - */ |
|
| 6585 | - 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) |
|
| 6586 | - {
|
|
| 6587 | - // phpcs:enable |
|
| 6588 | - global $conf,$user,$langs; |
|
| 6589 | - |
|
| 6590 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; |
|
| 6591 | - include_once DOL_DOCUMENT_ROOT .'/core/lib/images.lib.php'; |
|
| 6592 | - |
|
| 6593 | - $sortfield='position_name'; |
|
| 6594 | - $sortorder='asc'; |
|
| 6595 | - |
|
| 6596 | - $dir = $sdir . '/'; |
|
| 6597 | - $pdir = '/'; |
|
| 6598 | - if ($modulepart == 'ticket') |
|
| 6599 | - {
|
|
| 6600 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6601 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
|
| 6602 | - } |
|
| 6603 | - else |
|
| 6604 | - {
|
|
| 6605 | - $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6606 | - $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
|
| 6607 | - } |
|
| 6608 | - |
|
| 6609 | - // For backward compatibility |
|
| 6610 | - if ($modulepart == 'product' && !empty(Globals::$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) {
|
|
| 6611 | - $dir = $sdir . '/'. get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6612 | - $pdir = '/' . get_exdir($this->id,2,0,0,$this,$modulepart) . $this->id ."/photos/"; |
|
| 6613 | - } |
|
| 6614 | - |
|
| 6615 | - // Defined relative dir to DOL_DATA_ROOT |
|
| 6616 | - $relativedir = ''; |
|
| 6617 | - if ($dir) |
|
| 6618 | - {
|
|
| 6619 | - $relativedir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
|
| 6620 | - $relativedir = preg_replace('/^[\\/]/','',$relativedir);
|
|
| 6621 | - $relativedir = preg_replace('/[\\/]$/','',$relativedir);
|
|
| 6622 | - } |
|
| 6623 | - |
|
| 6624 | - $dirthumb = $dir.'thumbs/'; |
|
| 6625 | - $pdirthumb = $pdir.'thumbs/'; |
|
| 6626 | - |
|
| 6627 | - $return ='<!-- Photo -->'."\n"; |
|
| 6628 | - $nbphoto=0; |
|
| 6629 | - |
|
| 6630 | - $filearray=dol_dir_list($dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6631 | - |
|
| 6632 | - /* if (! empty(Globals::$conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) // For backward compatiblity, we scan also old dirs |
|
| 6633 | - {
|
|
| 6634 | - $filearrayold=dol_dir_list($dirold,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
| 6635 | - $filearray=array_merge($filearray, $filearrayold); |
|
| 6636 | - } */ |
|
| 7165 | + if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7166 | + elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7167 | + else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7168 | + if ($morewhere) $sql.= $morewhere; |
|
| 7169 | + $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 6637 | 7170 | |
| 6638 | - completeFileArrayWithDatabaseInfo($filearray, $relativedir); |
|
| 7171 | + $res = $this->db->query($sql); |
|
| 7172 | + if ($res) |
|
| 7173 | + {
|
|
| 7174 | + $obj = $this->db->fetch_object($res); |
|
| 7175 | + if ($obj) |
|
| 7176 | + {
|
|
| 7177 | + $this->setVarsFromFetchObj($obj); |
|
| 7178 | + return $this->id; |
|
| 7179 | + } |
|
| 7180 | + else |
|
| 7181 | + {
|
|
| 7182 | + return 0; |
|
| 7183 | + } |
|
| 7184 | + } |
|
| 7185 | + else |
|
| 7186 | + {
|
|
| 7187 | + $this->error = $this->db->lasterror(); |
|
| 7188 | + $this->errors[] = $this->error; |
|
| 7189 | + return -1; |
|
| 7190 | + } |
|
| 7191 | + } |
|
| 6639 | 7192 | |
| 6640 | - if (count($filearray)) |
|
| 6641 | - {
|
|
| 6642 | - if ($sortfield && $sortorder) |
|
| 6643 | - {
|
|
| 6644 | - $filearray=dol_sort_array($filearray, $sortfield, $sortorder); |
|
| 6645 | - } |
|
| 7193 | + /** |
|
| 7194 | + * Update object into database |
|
| 7195 | + * |
|
| 7196 | + * @param User $user User that modifies |
|
| 7197 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7198 | + * @return int <0 if KO, >0 if OK |
|
| 7199 | + */ |
|
| 7200 | + public function updateCommon(User $user, $notrigger = false) |
|
| 7201 | + {
|
|
| 7202 | + global $conf, $langs; |
|
| 6646 | 7203 | |
| 6647 | - foreach($filearray as $key => $val) |
|
| 6648 | - {
|
|
| 6649 | - $photo=''; |
|
| 6650 | - $file = $val['name']; |
|
| 7204 | + $error = 0; |
|
| 6651 | 7205 | |
| 6652 | - //if (! utf8_check($file)) $file=utf8_encode($file); // To be sure file is stored in UTF8 in memory |
|
| 7206 | + $now=dol_now(); |
|
| 6653 | 7207 | |
| 6654 | - //if (dol_is_file($dir.$file) && image_format_supported($file) >= 0) |
|
| 6655 | - if (image_format_supported($file) >= 0) |
|
| 6656 | - {
|
|
| 6657 | - $nbphoto++; |
|
| 6658 | - $photo = $file; |
|
| 6659 | - $viewfilename = $file; |
|
| 7208 | + $fieldvalues = $this->setSaveQuery(); |
|
| 7209 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7210 | + if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7211 | + unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 6660 | 7212 | |
| 6661 | - if ($size == 1 || $size == 'small') { // Format vignette
|
|
| 7213 | + $keys=array(); |
|
| 7214 | + $values = array(); |
|
| 7215 | + foreach ($fieldvalues as $k => $v) {
|
|
| 7216 | + $keys[$k] = $k; |
|
| 7217 | + $value = $this->fields[$k]; |
|
| 7218 | + $values[$k] = $this->quote($v, $value); |
|
| 7219 | + $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
| 7220 | + } |
|
| 6662 | 7221 | |
| 6663 | - // Find name of thumb file |
|
| 6664 | - $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
|
| 6665 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 7222 | + // Clean and check mandatory |
|
| 7223 | + foreach($keys as $key) |
|
| 7224 | + {
|
|
| 7225 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7226 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 6666 | 7227 | |
| 6667 | - // Get filesize of original file |
|
| 6668 | - $imgarray=dol_getImageSize($dir.$photo); |
|
| 7228 | + //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7229 | + /* |
|
| 7230 | + if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) |
|
| 7231 | + {
|
|
| 7232 | + $error++; |
|
| 7233 | + $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7234 | + }*/ |
|
| 7235 | + } |
|
| 6669 | 7236 | |
| 6670 | - if ($nbbyrow > 0) |
|
| 6671 | - {
|
|
| 6672 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7237 | + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 6673 | 7238 | |
| 6674 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 6675 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
|
| 6676 | - } |
|
| 6677 | - else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 7239 | + $this->db->begin(); |
|
| 7240 | + if (! $error) |
|
| 7241 | + {
|
|
| 7242 | + $res = $this->db->query($sql); |
|
| 7243 | + if ($res===false) |
|
| 7244 | + {
|
|
| 7245 | + $error++; |
|
| 7246 | + $this->errors[] = $this->db->lasterror(); |
|
| 7247 | + } |
|
| 7248 | + } |
|
| 6678 | 7249 | |
| 6679 | - $return.= "\n"; |
|
| 7250 | + // Update extrafield |
|
| 7251 | + if (!$error && empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) {
|
|
| 7252 | + $result=$this->insertExtraFields(); |
|
| 7253 | + if ($result < 0) |
|
| 7254 | + {
|
|
| 7255 | + $error++; |
|
| 7256 | + } |
|
| 7257 | + } |
|
| 6680 | 7258 | |
| 6681 | - $relativefile=preg_replace('/^\//', '', $pdir.$photo);
|
|
| 6682 | - if (empty($nolink)) |
|
| 6683 | - {
|
|
| 6684 | - $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
|
| 6685 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6686 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 6687 | - } |
|
| 7259 | + // Triggers |
|
| 7260 | + if (! $error && ! $notrigger) |
|
| 7261 | + {
|
|
| 7262 | + // Call triggers |
|
| 7263 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 7264 | + if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
|
|
| 7265 | + // End call triggers |
|
| 7266 | + } |
|
| 6688 | 7267 | |
| 6689 | - // Show image (width height=$maxHeight) |
|
| 6690 | - // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
|
| 6691 | - $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
|
| 6692 | - $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
|
| 6693 | - if ($notitle) $alt=''; |
|
| 6694 | - |
|
| 6695 | - if ($usesharelink) |
|
| 6696 | - {
|
|
| 6697 | - if ($val['share']) |
|
| 6698 | - {
|
|
| 6699 | - if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6700 | - {
|
|
| 6701 | - $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
|
| 6702 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6703 | - } |
|
| 6704 | - else {
|
|
| 6705 | - $return.= '<!-- Show original file -->'; |
|
| 6706 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6707 | - } |
|
| 6708 | - } |
|
| 6709 | - else |
|
| 6710 | - {
|
|
| 6711 | - $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
|
| 6712 | - $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
|
| 6713 | - } |
|
| 6714 | - } |
|
| 6715 | - else |
|
| 6716 | - {
|
|
| 6717 | - if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
|
| 6718 | - {
|
|
| 6719 | - $return.= '<!-- Show thumb -->'; |
|
| 6720 | - $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).'">'; |
|
| 6721 | - } |
|
| 6722 | - else {
|
|
| 6723 | - $return.= '<!-- Show original file -->'; |
|
| 6724 | - $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).'">'; |
|
| 6725 | - } |
|
| 6726 | - } |
|
| 7268 | + // Commit or rollback |
|
| 7269 | + if ($error) {
|
|
| 7270 | + $this->db->rollback(); |
|
| 7271 | + return -1; |
|
| 7272 | + } else {
|
|
| 7273 | + $this->db->commit(); |
|
| 7274 | + return $this->id; |
|
| 7275 | + } |
|
| 7276 | + } |
|
| 6727 | 7277 | |
| 6728 | - if (empty($nolink)) $return.= '</a>'; |
|
| 6729 | - $return.="\n"; |
|
| 6730 | - |
|
| 6731 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6732 | - if ($showaction) |
|
| 6733 | - {
|
|
| 6734 | - $return.= '<br>'; |
|
| 6735 | - // On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites |
|
| 6736 | - if ($photo_vignette && (image_format_supported($photo) > 0) && ($this->imgWidth > $maxWidth || $this->imgHeight > $maxHeight)) |
|
| 6737 | - {
|
|
| 6738 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=addthumb&file='.urlencode($pdir.$viewfilename).'">'.img_picto($langs->trans('GenerateThumb'),'refresh').' </a>';
|
|
| 6739 | - } |
|
| 6740 | - // Special cas for product |
|
| 6741 | - if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6742 | - {
|
|
| 6743 | - // Link to resize |
|
| 6744 | - $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> ';
|
|
| 6745 | - |
|
| 6746 | - // Link to delete |
|
| 6747 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6748 | - $return.= img_delete().'</a>'; |
|
| 6749 | - } |
|
| 6750 | - } |
|
| 6751 | - $return.= "\n"; |
|
| 7278 | + /** |
|
| 7279 | + * Delete object in database |
|
| 7280 | + * |
|
| 7281 | + * @param User $user User that deletes |
|
| 7282 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7283 | + * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
|
| 7284 | + * @return int <=0 if KO, >0 if OK |
|
| 7285 | + */ |
|
| 7286 | + public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
| 7287 | + {
|
|
| 7288 | + $error=0; |
|
| 6752 | 7289 | |
| 6753 | - if ($nbbyrow > 0) |
|
| 6754 | - {
|
|
| 6755 | - $return.= '</td>'; |
|
| 6756 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6757 | - } |
|
| 6758 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 6759 | - } |
|
| 6760 | - |
|
| 6761 | - if (empty($size)) { // Format origine
|
|
| 6762 | - $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
|
| 6763 | - |
|
| 6764 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 6765 | - if ($showaction) |
|
| 6766 | - {
|
|
| 6767 | - // Special case for product |
|
| 6768 | - if ($modulepart == 'product' && ($user->rights->produit->creer || $user->rights->service->creer)) |
|
| 6769 | - {
|
|
| 6770 | - // Link to resize |
|
| 6771 | - $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> ';
|
|
| 6772 | - |
|
| 6773 | - // Link to delete |
|
| 6774 | - $return.= '<a href="'.$_SERVER["PHP_SELF"].'?id='.$this->id.'&action=delete&file='.urlencode($pdir.$viewfilename).'">'; |
|
| 6775 | - $return.= img_delete().'</a>'; |
|
| 6776 | - } |
|
| 6777 | - } |
|
| 6778 | - } |
|
| 7290 | + $this->db->begin(); |
|
| 6779 | 7291 | |
| 6780 | - // On continue ou on arrete de boucler ? |
|
| 6781 | - if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 6782 | - } |
|
| 6783 | - } |
|
| 7292 | + if ($forcechilddeletion) |
|
| 7293 | + {
|
|
| 7294 | + foreach($this->childtables as $table) |
|
| 7295 | + {
|
|
| 7296 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 7297 | + $resql = $this->db->query($sql); |
|
| 7298 | + if (! $resql) |
|
| 7299 | + {
|
|
| 7300 | + $this->error=$this->db->lasterror(); |
|
| 7301 | + $this->errors[]=$this->error; |
|
| 7302 | + $this->db->rollback(); |
|
| 7303 | + return -1; |
|
| 7304 | + } |
|
| 7305 | + } |
|
| 7306 | + } |
|
| 7307 | + elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7308 | + {
|
|
| 7309 | + $objectisused = $this->isObjectUsed($this->id); |
|
| 7310 | + if (! empty($objectisused)) |
|
| 7311 | + {
|
|
| 7312 | + dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
| 7313 | + $this->error='ErrorRecordHasChildren'; |
|
| 7314 | + $this->errors[]=$this->error; |
|
| 7315 | + $this->db->rollback(); |
|
| 7316 | + return 0; |
|
| 7317 | + } |
|
| 7318 | + } |
|
| 6784 | 7319 | |
| 6785 | - if ($size==1 || $size=='small') |
|
| 6786 | - {
|
|
| 6787 | - if ($nbbyrow > 0) |
|
| 6788 | - {
|
|
| 6789 | - // Ferme tableau |
|
| 6790 | - while ($nbphoto % $nbbyrow) |
|
| 6791 | - {
|
|
| 6792 | - $return.= '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; |
|
| 6793 | - $nbphoto++; |
|
| 6794 | - } |
|
| 6795 | - |
|
| 6796 | - if ($nbphoto) $return.= '</table>'; |
|
| 6797 | - } |
|
| 6798 | - } |
|
| 6799 | - } |
|
| 6800 | - |
|
| 6801 | - $this->nbphoto = $nbphoto; |
|
| 6802 | - |
|
| 6803 | - return $return; |
|
| 6804 | - } |
|
| 6805 | - |
|
| 6806 | - |
|
| 6807 | - /** |
|
| 6808 | - * Function test if type is array |
|
| 6809 | - * |
|
| 6810 | - * @param array $info content informations of field |
|
| 6811 | - * @return bool |
|
| 6812 | - */ |
|
| 6813 | - protected function isArray($info) |
|
| 6814 | - {
|
|
| 6815 | - if(is_array($info)) |
|
| 6816 | - {
|
|
| 6817 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6818 | - else return false; |
|
| 6819 | - } |
|
| 6820 | - else return false; |
|
| 6821 | - } |
|
| 6822 | - |
|
| 6823 | - /** |
|
| 6824 | - * Function test if type is null |
|
| 6825 | - * |
|
| 6826 | - * @param array $info content informations of field |
|
| 6827 | - * @return bool |
|
| 6828 | - */ |
|
| 6829 | - protected function isNull($info) |
|
| 6830 | - {
|
|
| 6831 | - if(is_array($info)) |
|
| 6832 | - {
|
|
| 6833 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6834 | - else return false; |
|
| 6835 | - } |
|
| 6836 | - else return false; |
|
| 6837 | - } |
|
| 6838 | - |
|
| 6839 | - /** |
|
| 6840 | - * Function test if type is date |
|
| 6841 | - * |
|
| 6842 | - * @param array $info content informations of field |
|
| 6843 | - * @return bool |
|
| 6844 | - */ |
|
| 6845 | - public function isDate($info) |
|
| 6846 | - {
|
|
| 6847 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6848 | - else return false; |
|
| 6849 | - } |
|
| 6850 | - |
|
| 6851 | - /** |
|
| 6852 | - * Function test if type is integer |
|
| 6853 | - * |
|
| 6854 | - * @param array $info content informations of field |
|
| 6855 | - * @return bool |
|
| 6856 | - */ |
|
| 6857 | - public function isInt($info) |
|
| 6858 | - {
|
|
| 6859 | - if(is_array($info)) |
|
| 6860 | - {
|
|
| 6861 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6862 | - else return false; |
|
| 6863 | - } |
|
| 6864 | - else return false; |
|
| 6865 | - } |
|
| 6866 | - |
|
| 6867 | - /** |
|
| 6868 | - * Function test if type is float |
|
| 6869 | - * |
|
| 6870 | - * @param array $info content informations of field |
|
| 6871 | - * @return bool |
|
| 6872 | - */ |
|
| 6873 | - public function isFloat($info) |
|
| 6874 | - {
|
|
| 6875 | - if(is_array($info)) |
|
| 6876 | - {
|
|
| 6877 | - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
|
| 6878 | - else return false; |
|
| 6879 | - } |
|
| 6880 | - else return false; |
|
| 6881 | - } |
|
| 6882 | - |
|
| 6883 | - /** |
|
| 6884 | - * Function test if type is text |
|
| 6885 | - * |
|
| 6886 | - * @param array $info content informations of field |
|
| 6887 | - * @return bool |
|
| 6888 | - */ |
|
| 6889 | - public function isText($info) |
|
| 6890 | - {
|
|
| 6891 | - if(is_array($info)) |
|
| 6892 | - {
|
|
| 6893 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6894 | - else return false; |
|
| 6895 | - } |
|
| 6896 | - else return false; |
|
| 6897 | - } |
|
| 6898 | - |
|
| 6899 | - /** |
|
| 6900 | - * Function test if is indexed |
|
| 6901 | - * |
|
| 6902 | - * @param array $info content informations of field |
|
| 6903 | - * @return bool |
|
| 6904 | - */ |
|
| 6905 | - protected function isIndex($info) |
|
| 6906 | - {
|
|
| 6907 | - if(is_array($info)) |
|
| 6908 | - {
|
|
| 6909 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6910 | - else return false; |
|
| 6911 | - } |
|
| 6912 | - else return false; |
|
| 6913 | - } |
|
| 6914 | - |
|
| 6915 | - /** |
|
| 6916 | - * Function to prepare the values to insert. |
|
| 6917 | - * Note $this->${field} are set by the page that make the createCommon or the updateCommon.
|
|
| 6918 | - * |
|
| 6919 | - * @return array |
|
| 6920 | - */ |
|
| 6921 | - protected function setSaveQuery() |
|
| 6922 | - {
|
|
| 6923 | - global $conf; |
|
| 6924 | - |
|
| 6925 | - $queryarray=array(); |
|
| 6926 | - foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 6927 | - {
|
|
| 6928 | - // Depending on field type ('datetime', ...)
|
|
| 6929 | - if($this->isDate($info)) |
|
| 6930 | - {
|
|
| 6931 | - if(empty($this->{$field}))
|
|
| 6932 | - {
|
|
| 6933 | - $queryarray[$field] = null; |
|
| 6934 | - } |
|
| 6935 | - else |
|
| 6936 | - {
|
|
| 6937 | - $queryarray[$field] = $this->db->idate($this->{$field});
|
|
| 6938 | - } |
|
| 6939 | - } |
|
| 6940 | - else if($this->isArray($info)) |
|
| 6941 | - {
|
|
| 6942 | - if(! empty($this->{$field})) {
|
|
| 6943 | - if(! is_array($this->{$field})) {
|
|
| 6944 | - $this->{$field} = array($this->{$field});
|
|
| 6945 | - } |
|
| 6946 | - $queryarray[$field] = serialize($this->{$field});
|
|
| 6947 | - } else {
|
|
| 6948 | - $queryarray[$field] = null; |
|
| 6949 | - } |
|
| 6950 | - } |
|
| 6951 | - else if($this->isInt($info)) |
|
| 6952 | - {
|
|
| 6953 | - if ($field == 'entity' && is_null($this->{$field}))
|
|
| 6954 | - $queryarray[$field] = Globals::$conf->entity; |
|
| 6955 | - else |
|
| 6956 | - {
|
|
| 6957 | - $queryarray[$field] = (int) price2num($this->{$field});
|
|
| 6958 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6959 | - } |
|
| 6960 | - } |
|
| 6961 | - else if($this->isFloat($info)) |
|
| 6962 | - {
|
|
| 6963 | - $queryarray[$field] = (double) price2num($this->{$field});
|
|
| 6964 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6965 | - } |
|
| 6966 | - else |
|
| 6967 | - {
|
|
| 6968 | - $queryarray[$field] = $this->{$field};
|
|
| 6969 | - } |
|
| 7320 | + if (! $error) {
|
|
| 7321 | + if (! $notrigger) {
|
|
| 7322 | + // Call triggers |
|
| 7323 | + $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7324 | + if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
|
|
| 7325 | + // End call triggers |
|
| 7326 | + } |
|
| 7327 | + } |
|
| 6970 | 7328 | |
| 6971 | - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6972 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 6973 | - } |
|
| 7329 | + if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 7330 | + {
|
|
| 7331 | + $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 7332 | + $sql.= " WHERE fk_object=" . $this->id; |
|
| 6974 | 7333 | |
| 6975 | - return $queryarray; |
|
| 6976 | - } |
|
| 7334 | + $resql = $this->db->query($sql); |
|
| 7335 | + if (! $resql) |
|
| 7336 | + {
|
|
| 7337 | + $this->errors[] = $this->db->lasterror(); |
|
| 7338 | + $error++; |
|
| 7339 | + } |
|
| 7340 | + } |
|
| 6977 | 7341 | |
| 6978 | - /** |
|
| 6979 | - * Function to load data from a SQL pointer into properties of current object $this |
|
| 6980 | - * |
|
| 6981 | - * @param stdClass $obj Contain data of object from database |
|
| 6982 | - * @return void |
|
| 6983 | - */ |
|
| 6984 | - protected function setVarsFromFetchObj(&$obj) |
|
| 6985 | - {
|
|
| 6986 | - foreach ($this->fields as $field => $info) |
|
| 6987 | - {
|
|
| 6988 | - if($this->isDate($info)) |
|
| 6989 | - {
|
|
| 6990 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6991 | - else $this->{$field} = strtotime($obj->{$field});
|
|
| 6992 | - } |
|
| 6993 | - elseif($this->isArray($info)) |
|
| 6994 | - {
|
|
| 6995 | - if(! empty($obj->{$field})) {
|
|
| 6996 | - $this->{$field} = @unserialize($obj->{$field});
|
|
| 6997 | - // Hack for data not in UTF8 |
|
| 6998 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 6999 | - } else {
|
|
| 7000 | - $this->{$field} = array();
|
|
| 7001 | - } |
|
| 7002 | - } |
|
| 7003 | - elseif($this->isInt($info)) |
|
| 7004 | - {
|
|
| 7005 | - if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
|
| 7006 | - else $this->{$field} = (int) $obj->{$field};
|
|
| 7007 | - } |
|
| 7008 | - elseif($this->isFloat($info)) |
|
| 7009 | - {
|
|
| 7010 | - $this->{$field} = (double) $obj->{$field};
|
|
| 7011 | - } |
|
| 7012 | - elseif($this->isNull($info)) |
|
| 7013 | - {
|
|
| 7014 | - $val = $obj->{$field};
|
|
| 7015 | - // zero is not null |
|
| 7016 | - $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
|
| 7017 | - } |
|
| 7018 | - else |
|
| 7019 | - {
|
|
| 7020 | - $this->{$field} = $obj->{$field};
|
|
| 7021 | - } |
|
| 7022 | - } |
|
| 7023 | - |
|
| 7024 | - // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
|
| 7025 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7026 | - } |
|
| 7027 | - |
|
| 7028 | - /** |
|
| 7029 | - * Function to concat keys of fields |
|
| 7030 | - * |
|
| 7031 | - * @return string |
|
| 7032 | - */ |
|
| 7033 | - protected function getFieldList() |
|
| 7034 | - {
|
|
| 7035 | - $keys = array_keys($this->fields); |
|
| 7036 | - return implode(',', $keys);
|
|
| 7037 | - } |
|
| 7038 | - |
|
| 7039 | - /** |
|
| 7040 | - * Add quote to field value if necessary |
|
| 7041 | - * |
|
| 7042 | - * @param string|int $value Value to protect |
|
| 7043 | - * @param array $fieldsentry Properties of field |
|
| 7044 | - * @return string |
|
| 7045 | - */ |
|
| 7046 | - protected function quote($value, $fieldsentry) |
|
| 7047 | - {
|
|
| 7048 | - if (is_null($value)) return 'NULL'; |
|
| 7049 | - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
|
|
| 7050 | - else return "'".$this->db->escape($value)."'"; |
|
| 7051 | - } |
|
| 7052 | - |
|
| 7053 | - |
|
| 7054 | - /** |
|
| 7055 | - * Create object into database |
|
| 7056 | - * |
|
| 7057 | - * @param User $user User that creates |
|
| 7058 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7059 | - * @return int <0 if KO, Id of created object if OK |
|
| 7060 | - */ |
|
| 7061 | - public function createCommon(User $user, $notrigger = false) |
|
| 7062 | - {
|
|
| 7063 | - global $langs; |
|
| 7064 | - |
|
| 7065 | - $error = 0; |
|
| 7066 | - |
|
| 7067 | - $now=dol_now(); |
|
| 7068 | - |
|
| 7069 | - $fieldvalues = $this->setSaveQuery(); |
|
| 7070 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7071 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7072 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
|
| 7073 | - |
|
| 7074 | - $keys=array(); |
|
| 7075 | - $values = array(); |
|
| 7076 | - foreach ($fieldvalues as $k => $v) {
|
|
| 7077 | - $keys[$k] = $k; |
|
| 7078 | - $value = $this->fields[$k]; |
|
| 7079 | - $values[$k] = $this->quote($v, $value); |
|
| 7080 | - } |
|
| 7081 | - |
|
| 7082 | - // Clean and check mandatory |
|
| 7083 | - foreach($keys as $key) |
|
| 7084 | - {
|
|
| 7085 | - // If field is an implicit foreign key field |
|
| 7086 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7087 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7088 | - |
|
| 7089 | - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7090 | - if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
|
| 7091 | - {
|
|
| 7092 | - $error++; |
|
| 7093 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7094 | - } |
|
| 7342 | + if (! $error) |
|
| 7343 | + {
|
|
| 7344 | + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
| 7095 | 7345 | |
| 7096 | - // If field is an implicit foreign key field |
|
| 7097 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7098 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7099 | - } |
|
| 7346 | + $res = $this->db->query($sql); |
|
| 7347 | + if($res===false) {
|
|
| 7348 | + $error++; |
|
| 7349 | + $this->errors[] = $this->db->lasterror(); |
|
| 7350 | + } |
|
| 7351 | + } |
|
| 7100 | 7352 | |
| 7101 | - if ($error) return -1; |
|
| 7353 | + // Commit or rollback |
|
| 7354 | + if ($error) {
|
|
| 7355 | + $this->db->rollback(); |
|
| 7356 | + return -1; |
|
| 7357 | + } else {
|
|
| 7358 | + $this->db->commit(); |
|
| 7359 | + return 1; |
|
| 7360 | + } |
|
| 7361 | + } |
|
| 7102 | 7362 | |
| 7103 | - $this->db->begin(); |
|
| 7363 | + /** |
|
| 7364 | + * Initialise object with example values |
|
| 7365 | + * Id must be 0 if object instance is a specimen |
|
| 7366 | + * |
|
| 7367 | + * @return void |
|
| 7368 | + */ |
|
| 7369 | + public function initAsSpecimenCommon() |
|
| 7370 | + {
|
|
| 7371 | + $this->id = 0; |
|
| 7104 | 7372 | |
| 7105 | - if (! $error) |
|
| 7106 | - {
|
|
| 7107 | - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7108 | - $sql.= ' ('.implode( ", ", $keys ).')';
|
|
| 7109 | - $sql.= ' VALUES ('.implode( ", ", $values ).')';
|
|
| 7373 | + // TODO... |
|
| 7374 | + } |
|
| 7110 | 7375 | |
| 7111 | - $res = $this->db->query($sql); |
|
| 7112 | - if ($res===false) {
|
|
| 7113 | - $error++; |
|
| 7114 | - $this->errors[] = $this->db->lasterror(); |
|
| 7115 | - } |
|
| 7116 | - } |
|
| 7117 | - |
|
| 7118 | - if (! $error) |
|
| 7119 | - {
|
|
| 7120 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); |
|
| 7121 | - } |
|
| 7122 | - |
|
| 7123 | - // Create extrafields |
|
| 7124 | - if (! $error) |
|
| 7125 | - {
|
|
| 7126 | - $result=$this->insertExtraFields(); |
|
| 7127 | - if ($result < 0) $error++; |
|
| 7128 | - } |
|
| 7129 | - |
|
| 7130 | - // Triggers |
|
| 7131 | - if (! $error && ! $notrigger) |
|
| 7132 | - {
|
|
| 7133 | - // Call triggers |
|
| 7134 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_CREATE',$user); |
|
| 7135 | - if ($result < 0) { $error++; }
|
|
| 7136 | - // End call triggers |
|
| 7137 | - } |
|
| 7138 | - |
|
| 7139 | - // Commit or rollback |
|
| 7140 | - if ($error) {
|
|
| 7141 | - $this->db->rollback(); |
|
| 7142 | - return -1; |
|
| 7143 | - } else {
|
|
| 7144 | - $this->db->commit(); |
|
| 7145 | - return $this->id; |
|
| 7146 | - } |
|
| 7147 | - } |
|
| 7148 | - |
|
| 7149 | - |
|
| 7150 | - /** |
|
| 7151 | - * Load object in memory from the database |
|
| 7152 | - * |
|
| 7153 | - * @param int $id Id object |
|
| 7154 | - * @param string $ref Ref |
|
| 7155 | - * @param string $morewhere More SQL filters (' AND ...')
|
|
| 7156 | - * @return int <0 if KO, 0 if not found, >0 if OK |
|
| 7157 | - */ |
|
| 7158 | - public function fetchCommon($id, $ref = null, $morewhere = '') |
|
| 7159 | - {
|
|
| 7160 | - if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 7161 | - |
|
| 7162 | - $sql = 'SELECT '.$this->getFieldList(); |
|
| 7163 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
|
| 7164 | - |
|
| 7165 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7166 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7167 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7168 | - if ($morewhere) $sql.= $morewhere; |
|
| 7169 | - $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
|
| 7170 | - |
|
| 7171 | - $res = $this->db->query($sql); |
|
| 7172 | - if ($res) |
|
| 7173 | - {
|
|
| 7174 | - $obj = $this->db->fetch_object($res); |
|
| 7175 | - if ($obj) |
|
| 7176 | - {
|
|
| 7177 | - $this->setVarsFromFetchObj($obj); |
|
| 7178 | - return $this->id; |
|
| 7179 | - } |
|
| 7180 | - else |
|
| 7181 | - {
|
|
| 7182 | - return 0; |
|
| 7183 | - } |
|
| 7184 | - } |
|
| 7185 | - else |
|
| 7186 | - {
|
|
| 7187 | - $this->error = $this->db->lasterror(); |
|
| 7188 | - $this->errors[] = $this->error; |
|
| 7189 | - return -1; |
|
| 7190 | - } |
|
| 7191 | - } |
|
| 7192 | - |
|
| 7193 | - /** |
|
| 7194 | - * Update object into database |
|
| 7195 | - * |
|
| 7196 | - * @param User $user User that modifies |
|
| 7197 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7198 | - * @return int <0 if KO, >0 if OK |
|
| 7199 | - */ |
|
| 7200 | - public function updateCommon(User $user, $notrigger = false) |
|
| 7201 | - {
|
|
| 7202 | - global $conf, $langs; |
|
| 7203 | - |
|
| 7204 | - $error = 0; |
|
| 7205 | - |
|
| 7206 | - $now=dol_now(); |
|
| 7207 | - |
|
| 7208 | - $fieldvalues = $this->setSaveQuery(); |
|
| 7209 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7210 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7211 | - unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
|
| 7212 | - |
|
| 7213 | - $keys=array(); |
|
| 7214 | - $values = array(); |
|
| 7215 | - foreach ($fieldvalues as $k => $v) {
|
|
| 7216 | - $keys[$k] = $k; |
|
| 7217 | - $value = $this->fields[$k]; |
|
| 7218 | - $values[$k] = $this->quote($v, $value); |
|
| 7219 | - $tmp[] = $k.'='.$this->quote($v, $this->fields[$k]); |
|
| 7220 | - } |
|
| 7221 | - |
|
| 7222 | - // Clean and check mandatory |
|
| 7223 | - foreach($keys as $key) |
|
| 7224 | - {
|
|
| 7225 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7226 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7227 | - |
|
| 7228 | - //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
|
| 7229 | - /* |
|
| 7230 | - if ($this->fields[$key]['notnull'] == 1 && empty($values[$key])) |
|
| 7231 | - {
|
|
| 7232 | - $error++; |
|
| 7233 | - $this->errors[]=$langs->trans("ErrorFieldRequired", $this->fields[$key]['label']);
|
|
| 7234 | - }*/ |
|
| 7235 | - } |
|
| 7236 | 7376 | |
| 7237 | - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; |
|
| 7377 | + /* Part for comments */ |
|
| 7238 | 7378 | |
| 7239 | - $this->db->begin(); |
|
| 7240 | - if (! $error) |
|
| 7241 | - {
|
|
| 7242 | - $res = $this->db->query($sql); |
|
| 7243 | - if ($res===false) |
|
| 7244 | - {
|
|
| 7245 | - $error++; |
|
| 7246 | - $this->errors[] = $this->db->lasterror(); |
|
| 7247 | - } |
|
| 7248 | - } |
|
| 7249 | - |
|
| 7250 | - // Update extrafield |
|
| 7251 | - if (!$error && empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options) > 0) {
|
|
| 7252 | - $result=$this->insertExtraFields(); |
|
| 7253 | - if ($result < 0) |
|
| 7254 | - {
|
|
| 7255 | - $error++; |
|
| 7256 | - } |
|
| 7257 | - } |
|
| 7258 | - |
|
| 7259 | - // Triggers |
|
| 7260 | - if (! $error && ! $notrigger) |
|
| 7261 | - {
|
|
| 7262 | - // Call triggers |
|
| 7263 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_MODIFY',$user); |
|
| 7264 | - if ($result < 0) { $error++; } //Do also here what you must do to rollback action if trigger fail
|
|
| 7265 | - // End call triggers |
|
| 7266 | - } |
|
| 7267 | - |
|
| 7268 | - // Commit or rollback |
|
| 7269 | - if ($error) {
|
|
| 7270 | - $this->db->rollback(); |
|
| 7271 | - return -1; |
|
| 7272 | - } else {
|
|
| 7273 | - $this->db->commit(); |
|
| 7274 | - return $this->id; |
|
| 7275 | - } |
|
| 7276 | - } |
|
| 7277 | - |
|
| 7278 | - /** |
|
| 7279 | - * Delete object in database |
|
| 7280 | - * |
|
| 7281 | - * @param User $user User that deletes |
|
| 7282 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
| 7283 | - * @param int $forcechilddeletion 0=no, 1=Force deletion of children |
|
| 7284 | - * @return int <=0 if KO, >0 if OK |
|
| 7285 | - */ |
|
| 7286 | - public function deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0) |
|
| 7287 | - {
|
|
| 7288 | - $error=0; |
|
| 7289 | - |
|
| 7290 | - $this->db->begin(); |
|
| 7291 | - |
|
| 7292 | - if ($forcechilddeletion) |
|
| 7293 | - {
|
|
| 7294 | - foreach($this->childtables as $table) |
|
| 7295 | - {
|
|
| 7296 | - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table.' WHERE '.$this->fk_element.' = '.$this->id; |
|
| 7297 | - $resql = $this->db->query($sql); |
|
| 7298 | - if (! $resql) |
|
| 7299 | - {
|
|
| 7300 | - $this->error=$this->db->lasterror(); |
|
| 7301 | - $this->errors[]=$this->error; |
|
| 7302 | - $this->db->rollback(); |
|
| 7303 | - return -1; |
|
| 7304 | - } |
|
| 7305 | - } |
|
| 7306 | - } |
|
| 7307 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7308 | - {
|
|
| 7309 | - $objectisused = $this->isObjectUsed($this->id); |
|
| 7310 | - if (! empty($objectisused)) |
|
| 7311 | - {
|
|
| 7312 | - dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
|
| 7313 | - $this->error='ErrorRecordHasChildren'; |
|
| 7314 | - $this->errors[]=$this->error; |
|
| 7315 | - $this->db->rollback(); |
|
| 7316 | - return 0; |
|
| 7317 | - } |
|
| 7318 | - } |
|
| 7319 | - |
|
| 7320 | - if (! $error) {
|
|
| 7321 | - if (! $notrigger) {
|
|
| 7322 | - // Call triggers |
|
| 7323 | - $result=$this->call_trigger(strtoupper(get_class($this)).'_DELETE', $user); |
|
| 7324 | - if ($result < 0) { $error++; } // Do also here what you must do to rollback action if trigger fail
|
|
| 7325 | - // End call triggers |
|
| 7326 | - } |
|
| 7327 | - } |
|
| 7328 | - |
|
| 7329 | - if (! $error && ! empty($this->isextrafieldmanaged)) |
|
| 7330 | - {
|
|
| 7331 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . $this->table_element."_extrafields"; |
|
| 7332 | - $sql.= " WHERE fk_object=" . $this->id; |
|
| 7333 | - |
|
| 7334 | - $resql = $this->db->query($sql); |
|
| 7335 | - if (! $resql) |
|
| 7336 | - {
|
|
| 7337 | - $this->errors[] = $this->db->lasterror(); |
|
| 7338 | - $error++; |
|
| 7339 | - } |
|
| 7340 | - } |
|
| 7379 | + /** |
|
| 7380 | + * Load comments linked with current task |
|
| 7381 | + * @return boolean 1 if ok |
|
| 7382 | + */ |
|
| 7383 | + public function fetchComments() |
|
| 7384 | + {
|
|
| 7385 | + require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
| 7341 | 7386 | |
| 7342 | - if (! $error) |
|
| 7343 | - {
|
|
| 7344 | - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; |
|
| 7387 | + $comment = new Comment($this->db); |
|
| 7388 | + $result=$comment->fetchAllFor($this->element, $this->id); |
|
| 7389 | + if ($result<0) {
|
|
| 7390 | + $this->errors=array_merge($this->errors, $comment->errors); |
|
| 7391 | + return -1; |
|
| 7392 | + } else {
|
|
| 7393 | + $this->comments = $comment->comments; |
|
| 7394 | + } |
|
| 7395 | + return count($this->comments); |
|
| 7396 | + } |
|
| 7345 | 7397 | |
| 7346 | - $res = $this->db->query($sql); |
|
| 7347 | - if($res===false) {
|
|
| 7348 | - $error++; |
|
| 7349 | - $this->errors[] = $this->db->lasterror(); |
|
| 7350 | - } |
|
| 7351 | - } |
|
| 7352 | - |
|
| 7353 | - // Commit or rollback |
|
| 7354 | - if ($error) {
|
|
| 7355 | - $this->db->rollback(); |
|
| 7356 | - return -1; |
|
| 7357 | - } else {
|
|
| 7358 | - $this->db->commit(); |
|
| 7359 | - return 1; |
|
| 7360 | - } |
|
| 7361 | - } |
|
| 7362 | - |
|
| 7363 | - /** |
|
| 7364 | - * Initialise object with example values |
|
| 7365 | - * Id must be 0 if object instance is a specimen |
|
| 7366 | - * |
|
| 7367 | - * @return void |
|
| 7368 | - */ |
|
| 7369 | - public function initAsSpecimenCommon() |
|
| 7370 | - {
|
|
| 7371 | - $this->id = 0; |
|
| 7372 | - |
|
| 7373 | - // TODO... |
|
| 7374 | - } |
|
| 7375 | - |
|
| 7376 | - |
|
| 7377 | - /* Part for comments */ |
|
| 7378 | - |
|
| 7379 | - /** |
|
| 7380 | - * Load comments linked with current task |
|
| 7381 | - * @return boolean 1 if ok |
|
| 7382 | - */ |
|
| 7383 | - public function fetchComments() |
|
| 7384 | - {
|
|
| 7385 | - require_once DOL_DOCUMENT_ROOT.'/core/class/comment.class.php'; |
|
| 7386 | - |
|
| 7387 | - $comment = new Comment($this->db); |
|
| 7388 | - $result=$comment->fetchAllFor($this->element, $this->id); |
|
| 7389 | - if ($result<0) {
|
|
| 7390 | - $this->errors=array_merge($this->errors, $comment->errors); |
|
| 7391 | - return -1; |
|
| 7392 | - } else {
|
|
| 7393 | - $this->comments = $comment->comments; |
|
| 7394 | - } |
|
| 7395 | - return count($this->comments); |
|
| 7396 | - } |
|
| 7397 | - |
|
| 7398 | - /** |
|
| 7399 | - * Return nb comments already posted |
|
| 7400 | - * |
|
| 7401 | - * @return int |
|
| 7402 | - */ |
|
| 7403 | - public function getNbComments() |
|
| 7404 | - {
|
|
| 7405 | - return count($this->comments); |
|
| 7406 | - } |
|
| 7398 | + /** |
|
| 7399 | + * Return nb comments already posted |
|
| 7400 | + * |
|
| 7401 | + * @return int |
|
| 7402 | + */ |
|
| 7403 | + public function getNbComments() |
|
| 7404 | + {
|
|
| 7405 | + return count($this->comments); |
|
| 7406 | + } |
|
| 7407 | 7407 | |
| 7408 | 7408 | /** |
| 7409 | 7409 | * Trim object parameters |
@@ -401,24 +401,31 @@ discard block |
||
| 401 | 401 | $sql.= " FROM ".MAIN_DB_PREFIX.$element; |
| 402 | 402 | $sql.= " WHERE entity IN (".getEntity($element).")" ;
|
| 403 | 403 | |
| 404 | - if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); |
|
| 405 | - else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 406 | - else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 407 | - else {
|
|
| 404 | + if ($id > 0) { |
|
| 405 | + $sql.= " AND rowid = ".$db->escape($id); |
|
| 406 | + } else if ($ref) { |
|
| 407 | + $sql.= " AND ref = '".$db->escape($ref)."'"; |
|
| 408 | + } else if ($ref_ext) { |
|
| 409 | + $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; |
|
| 410 | + } else {
|
|
| 408 | 411 | $error='ErrorWrongParameters'; |
| 409 | 412 | dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); |
| 410 | 413 | return -1; |
| 411 | 414 | } |
| 412 | - if ($ref || $ref_ext) |
|
| 413 | - $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 415 | + if ($ref || $ref_ext) { |
|
| 416 | + $sql .= " AND entity = " . Globals::$conf->entity; |
|
| 417 | + } |
|
| 414 | 418 | |
| 415 | 419 | dol_syslog(get_class()."::isExistingObject", LOG_DEBUG); |
| 416 | 420 | $resql = $db->query($sql); |
| 417 | 421 | if ($resql) |
| 418 | 422 | {
|
| 419 | 423 | $num=$db->num_rows($resql); |
| 420 | - if ($num > 0) return 1; |
|
| 421 | - else return 0; |
|
| 424 | + if ($num > 0) { |
|
| 425 | + return 1; |
|
| 426 | + } else { |
|
| 427 | + return 0; |
|
| 428 | + } |
|
| 422 | 429 | } |
| 423 | 430 | return -1; |
| 424 | 431 | } |
@@ -447,13 +454,18 @@ discard block |
||
| 447 | 454 | //print "lastname=".$this->lastname." name=".$this->name." nom=".$this->nom."<br>\n"; |
| 448 | 455 | $lastname=$this->lastname; |
| 449 | 456 | $firstname=$this->firstname; |
| 450 | - 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:''))))); |
|
| 457 | + if (empty($lastname)) { |
|
| 458 | + $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:''))))); |
|
| 459 | + } |
|
| 451 | 460 | |
| 452 | 461 | $ret=''; |
| 453 | 462 | if ($option && $this->civility_id) |
| 454 | 463 | {
|
| 455 | - if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' ';
|
|
| 456 | - else $ret.=$this->civility_id.' '; |
|
| 464 | + if ($langs->transnoentitiesnoconv("Civility".$this->civility_id)!="Civility".$this->civility_id) { |
|
| 465 | + $ret.=$langs->transnoentitiesnoconv("Civility".$this->civility_id).' '; |
|
| 466 | + } else { |
|
| 467 | + $ret.=$this->civility_id.' '; |
|
| 468 | + } |
|
| 457 | 469 | } |
| 458 | 470 | |
| 459 | 471 | $ret .= AlDolUtils::dolGetFirstLastname($firstname, $lastname, $nameorder); |
@@ -544,14 +556,15 @@ discard block |
||
| 544 | 556 | && empty(Globals::$conf->global->SOCIETE_DISABLE_STATE) && $this->state) {
|
| 545 | 557 | if (!empty(Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && Globals::$conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1 && $this->region) {
|
| 546 | 558 | $out.=($outdone?' - ':'').$this->region.' - '.$this->state; |
| 547 | - } |
|
| 548 | - else {
|
|
| 559 | + } else {
|
|
| 549 | 560 | $out.=($outdone?' - ':'').$this->state; |
| 550 | 561 | } |
| 551 | 562 | $outdone++; |
| 552 | 563 | } |
| 553 | 564 | |
| 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>':''); |
|
| 565 | + 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)) { |
|
| 566 | + $out.=($outdone?'<br>':''); |
|
| 567 | + } |
|
| 555 | 568 | if (! empty($this->phone) && empty($this->phone_pro)) { // For objects that store pro phone into ->phone
|
| 556 | 569 | $out.=dol_print_phone($this->phone,$this->country_code,$contactid,$thirdpartyid,'AC_TEL',' ','phone',$langs->trans("PhonePro")); $outdone++;
|
| 557 | 570 | } |
@@ -591,13 +604,21 @@ discard block |
||
| 591 | 604 | } |
| 592 | 605 | $out.='<div style="clear: both;">'; |
| 593 | 606 | if (!empty(Globals::$conf->socialnetworks->enabled)) {
|
| 594 | - if ($this->skype) $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 607 | + if ($this->skype) { |
|
| 608 | + $out.=dol_print_socialnetworks($this->skype,$this->id,$object->id,'skype'); |
|
| 609 | + } |
|
| 595 | 610 | $outdone++; |
| 596 | - if ($this->jabberid) $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 611 | + if ($this->jabberid) { |
|
| 612 | + $out.=dol_print_socialnetworks($this->jabberid,$this->id,$object->id,'jabber'); |
|
| 613 | + } |
|
| 597 | 614 | $outdone++; |
| 598 | - if ($this->twitter) $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 615 | + if ($this->twitter) { |
|
| 616 | + $out.=dol_print_socialnetworks($this->twitter,$this->id,$object->id,'twitter'); |
|
| 617 | + } |
|
| 599 | 618 | $outdone++; |
| 600 | - if ($this->facebook) $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 619 | + if ($this->facebook) { |
|
| 620 | + $out.=dol_print_socialnetworks($this->facebook,$this->id,$object->id,'facebook'); |
|
| 621 | + } |
|
| 601 | 622 | $outdone++; |
| 602 | 623 | } |
| 603 | 624 | $out.='</div>'; |
@@ -657,10 +678,10 @@ discard block |
||
| 657 | 678 | $this->errors = $ecmfile->errors; |
| 658 | 679 | } |
| 659 | 680 | */ |
| 660 | - } |
|
| 661 | - else return ''; |
|
| 662 | - } |
|
| 663 | - elseif (empty($ecmfile->share)) |
|
| 681 | + } else { |
|
| 682 | + return ''; |
|
| 683 | + } |
|
| 684 | + } elseif (empty($ecmfile->share)) |
|
| 664 | 685 | {
|
| 665 | 686 | // Add entry into index |
| 666 | 687 | if ($initsharekey) |
@@ -668,8 +689,9 @@ discard block |
||
| 668 | 689 | require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
| 669 | 690 | $ecmfile->share = getRandomPassword(true); |
| 670 | 691 | $ecmfile->update($user); |
| 671 | - } |
|
| 672 | - else return ''; |
|
| 692 | + } else { |
|
| 693 | + return ''; |
|
| 694 | + } |
|
| 673 | 695 | } |
| 674 | 696 | |
| 675 | 697 | // Define $urlwithroot |
@@ -683,14 +705,18 @@ discard block |
||
| 683 | 705 | //if (! empty($modulepart)) $paramlink.=($paramlink?'&':'').'modulepart='.$modulepart; // For sharing with hash (so public files), modulepart is not required. |
| 684 | 706 | //if (! empty($ecmfile->entity)) $paramlink.='&entity='.$ecmfile->entity; // For sharing with hash (so public files), entity is not required. |
| 685 | 707 | //$paramlink.=($paramlink?'&':'').'file='.urlencode($filepath); // No need of name of file for public link, we will use the hash |
| 686 | - if (! empty($ecmfile->share)) $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; // Hash for public share |
|
| 687 | - if ($forcedownload) $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 708 | + if (! empty($ecmfile->share)) { |
|
| 709 | + $paramlink.=($paramlink?'&':'').'hashp='.$ecmfile->share; |
|
| 710 | + } |
|
| 711 | + // Hash for public share |
|
| 712 | + if ($forcedownload) { |
|
| 713 | + $paramlink.=($paramlink?'&':'').'attachment=1'; |
|
| 714 | + } |
|
| 688 | 715 | |
| 689 | 716 | if ($relativelink) |
| 690 | 717 | {
|
| 691 | 718 | $linktoreturn='document.php'.($paramlink?'?'.$paramlink:''); |
| 692 | - } |
|
| 693 | - else |
|
| 719 | + } else |
|
| 694 | 720 | {
|
| 695 | 721 | $linktoreturn=$urlwithroot.'/document.php'.($paramlink?'?'.$paramlink:''); |
| 696 | 722 | } |
@@ -738,8 +764,7 @@ discard block |
||
| 738 | 764 | if (is_numeric($type_contact)) |
| 739 | 765 | {
|
| 740 | 766 | $id_type_contact=$type_contact; |
| 741 | - } |
|
| 742 | - else |
|
| 767 | + } else |
|
| 743 | 768 | {
|
| 744 | 769 | // We look for id type_contact |
| 745 | 770 | $sql = "SELECT tc.rowid"; |
@@ -752,7 +777,9 @@ discard block |
||
| 752 | 777 | if ($resql) |
| 753 | 778 | {
|
| 754 | 779 | $obj = $this->db->fetch_object($resql); |
| 755 | - if ($obj) $id_type_contact=$obj->rowid; |
|
| 780 | + if ($obj) { |
|
| 781 | + $id_type_contact=$obj->rowid; |
|
| 782 | + } |
|
| 756 | 783 | } |
| 757 | 784 | } |
| 758 | 785 | |
@@ -804,8 +831,7 @@ discard block |
||
| 804 | 831 | |
| 805 | 832 | $this->db->commit(); |
| 806 | 833 | return 1; |
| 807 | - } |
|
| 808 | - else |
|
| 834 | + } else |
|
| 809 | 835 | {
|
| 810 | 836 | if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
| 811 | 837 | {
|
@@ -813,15 +839,16 @@ discard block |
||
| 813 | 839 | $this->db->rollback(); |
| 814 | 840 | echo 'err rollback'; |
| 815 | 841 | return -2; |
| 816 | - } |
|
| 817 | - else |
|
| 842 | + } else |
|
| 818 | 843 | {
|
| 819 | 844 | $this->error=$this->db->error(); |
| 820 | 845 | $this->db->rollback(); |
| 821 | 846 | return -1; |
| 822 | 847 | } |
| 823 | 848 | } |
| 824 | - } else return 0; |
|
| 849 | + } else { |
|
| 850 | + return 0; |
|
| 851 | + } |
|
| 825 | 852 | } |
| 826 | 853 | |
| 827 | 854 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -863,15 +890,18 @@ discard block |
||
| 863 | 890 | // Insert into database |
| 864 | 891 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; |
| 865 | 892 | $sql.= " statut = ".$statut; |
| 866 | - if ($type_contact_id) $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 867 | - if ($fk_socpeople) $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 893 | + if ($type_contact_id) { |
|
| 894 | + $sql.= ", fk_c_type_contact = '".$type_contact_id ."'"; |
|
| 895 | + } |
|
| 896 | + if ($fk_socpeople) { |
|
| 897 | + $sql.= ", fk_socpeople = '".$fk_socpeople ."'"; |
|
| 898 | + } |
|
| 868 | 899 | $sql.= " where rowid = ".$rowid; |
| 869 | 900 | $resql=$this->db->query($sql); |
| 870 | 901 | if ($resql) |
| 871 | 902 | {
|
| 872 | 903 | return 0; |
| 873 | - } |
|
| 874 | - else |
|
| 904 | + } else |
|
| 875 | 905 | {
|
| 876 | 906 | $this->error=$this->db->lasterror(); |
| 877 | 907 | return -1; |
@@ -908,8 +938,7 @@ discard block |
||
| 908 | 938 | |
| 909 | 939 | $this->db->commit(); |
| 910 | 940 | return 1; |
| 911 | - } |
|
| 912 | - else |
|
| 941 | + } else |
|
| 913 | 942 | {
|
| 914 | 943 | $this->error=$this->db->lasterror(); |
| 915 | 944 | $this->db->rollback(); |
@@ -939,15 +968,15 @@ discard block |
||
| 939 | 968 | |
| 940 | 969 | $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; |
| 941 | 970 | $sql.= " WHERE element_id = ".$this->id; |
| 942 | - if ($listId) |
|
| 943 | - $sql.= " AND fk_c_type_contact IN (".$listId.")";
|
|
| 971 | + if ($listId) { |
|
| 972 | + $sql.= " AND fk_c_type_contact IN (".$listId.")"; |
|
| 973 | + } |
|
| 944 | 974 | |
| 945 | 975 | dol_syslog(get_class($this)."::delete_linked_contact", LOG_DEBUG); |
| 946 | 976 | if ($this->db->query($sql)) |
| 947 | 977 | {
|
| 948 | 978 | return 1; |
| 949 | - } |
|
| 950 | - else |
|
| 979 | + } else |
|
| 951 | 980 | {
|
| 952 | 981 | $this->error=$this->db->lasterror(); |
| 953 | 982 | return -1; |
@@ -972,22 +1001,38 @@ discard block |
||
| 972 | 1001 | $tab=array(); |
| 973 | 1002 | |
| 974 | 1003 | $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 |
| 975 | - if ($source == 'internal') $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 976 | - if ($source == 'external' || $source == 'thirdparty') $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 1004 | + if ($source == 'internal') { |
|
| 1005 | + $sql.=", '-1' as socid, t.statut as statuscontact, t.login, t.photo"; |
|
| 1006 | + } |
|
| 1007 | + if ($source == 'external' || $source == 'thirdparty') { |
|
| 1008 | + $sql.=", t.fk_soc as socid, t.statut as statuscontact"; |
|
| 1009 | + } |
|
| 977 | 1010 | $sql.= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; |
| 978 | 1011 | $sql.= ", tc.source, tc.element, tc.code, tc.libelle"; |
| 979 | 1012 | $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; |
| 980 | 1013 | $sql.= ", ".MAIN_DB_PREFIX."element_contact ec"; |
| 981 | - if ($source == 'internal') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 982 | - if ($source == 'external'|| $source == 'thirdparty') $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 1014 | + if ($source == 'internal') { |
|
| 1015 | + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; |
|
| 1016 | + } |
|
| 1017 | + if ($source == 'external'|| $source == 'thirdparty') { |
|
| 1018 | + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; |
|
| 1019 | + } |
|
| 983 | 1020 | $sql.= " WHERE ec.element_id =".$this->id; |
| 984 | 1021 | $sql.= " AND ec.fk_c_type_contact=tc.rowid"; |
| 985 | 1022 | $sql.= " AND tc.element='".$this->db->escape($this->element)."'"; |
| 986 | - if ($code) $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 987 | - if ($source == 'internal') $sql.= " AND tc.source = 'internal'"; |
|
| 988 | - if ($source == 'external' || $source == 'thirdparty') $sql.= " AND tc.source = 'external'"; |
|
| 1023 | + if ($code) { |
|
| 1024 | + $sql.= " AND tc.code = '".$this->db->escape($code)."'"; |
|
| 1025 | + } |
|
| 1026 | + if ($source == 'internal') { |
|
| 1027 | + $sql.= " AND tc.source = 'internal'"; |
|
| 1028 | + } |
|
| 1029 | + if ($source == 'external' || $source == 'thirdparty') { |
|
| 1030 | + $sql.= " AND tc.source = 'external'"; |
|
| 1031 | + } |
|
| 989 | 1032 | $sql.= " AND tc.active=1"; |
| 990 | - if ($statut >= 0) $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1033 | + if ($statut >= 0) { |
|
| 1034 | + $sql.= " AND ec.statut = '".$statut."'"; |
|
| 1035 | + } |
|
| 991 | 1036 | $sql.=" ORDER BY t.lastname ASC"; |
| 992 | 1037 | |
| 993 | 1038 | dol_syslog(get_class($this)."::liste_contact", LOG_DEBUG); |
@@ -1008,8 +1053,7 @@ discard block |
||
| 1008 | 1053 | 'nom'=>$obj->lastname, // For backward compatibility |
| 1009 | 1054 | 'civility'=>$obj->civility, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, 'email'=>$obj->email, 'login'=>$obj->login, 'photo'=>$obj->photo, 'statuscontact'=>$obj->statuscontact, |
| 1010 | 1055 | 'rowid'=>$obj->rowid, 'code'=>$obj->code, 'libelle'=>$libelle_type, 'status'=>$obj->statuslink, 'fk_c_type_contact'=>$obj->fk_c_type_contact); |
| 1011 | - } |
|
| 1012 | - else |
|
| 1056 | + } else |
|
| 1013 | 1057 | {
|
| 1014 | 1058 | $tab[$i]=$obj->id; |
| 1015 | 1059 | } |
@@ -1018,8 +1062,7 @@ discard block |
||
| 1018 | 1062 | } |
| 1019 | 1063 | |
| 1020 | 1064 | return $tab; |
| 1021 | - } |
|
| 1022 | - else |
|
| 1065 | + } else |
|
| 1023 | 1066 | {
|
| 1024 | 1067 | $this->error=$this->db->lasterror(); |
| 1025 | 1068 | dol_print_error($this->db); |
@@ -1054,8 +1097,7 @@ discard block |
||
| 1054 | 1097 | $result = $this->update_contact($rowid, $newstatut); |
| 1055 | 1098 | $this->db->free($resql); |
| 1056 | 1099 | return $result; |
| 1057 | - } |
|
| 1058 | - else |
|
| 1100 | + } else |
|
| 1059 | 1101 | {
|
| 1060 | 1102 | $this->error=$this->db->error(); |
| 1061 | 1103 | dol_print_error($this->db); |
@@ -1079,16 +1121,27 @@ discard block |
||
| 1079 | 1121 | // phpcs:enable |
| 1080 | 1122 | global $langs; |
| 1081 | 1123 | |
| 1082 | - if (empty($order)) $order='position'; |
|
| 1083 | - if ($order == 'position') $order.=',code'; |
|
| 1124 | + if (empty($order)) { |
|
| 1125 | + $order='position'; |
|
| 1126 | + } |
|
| 1127 | + if ($order == 'position') { |
|
| 1128 | + $order.=',code'; |
|
| 1129 | + } |
|
| 1084 | 1130 | |
| 1085 | 1131 | $tab = array(); |
| 1086 | 1132 | $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; |
| 1087 | 1133 | $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; |
| 1088 | 1134 | $sql.= " WHERE tc.element='".$this->db->escape($this->element)."'"; |
| 1089 | - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types |
|
| 1090 | - if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1091 | - if (! empty($code)) $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1135 | + if ($activeonly == 1) { |
|
| 1136 | + $sql.= " AND tc.active=1"; |
|
| 1137 | + } |
|
| 1138 | + // only the active types |
|
| 1139 | + if (! empty($source) && $source != 'all') { |
|
| 1140 | + $sql.= " AND tc.source='".$this->db->escape($source)."'"; |
|
| 1141 | + } |
|
| 1142 | + if (! empty($code)) { |
|
| 1143 | + $sql.= " AND tc.code='".$this->db->escape($code)."'"; |
|
| 1144 | + } |
|
| 1092 | 1145 | $sql.= $this->db->order($order,'ASC'); |
| 1093 | 1146 | |
| 1094 | 1147 | //print "sql=".$sql; |
@@ -1103,13 +1156,15 @@ discard block |
||
| 1103 | 1156 | |
| 1104 | 1157 | $transkey="TypeContact_".$this->element."_".$source."_".$obj->code; |
| 1105 | 1158 | $libelle_type=($langs->trans($transkey)!=$transkey ? $langs->trans($transkey) : $obj->libelle); |
| 1106 | - if (empty($option)) $tab[$obj->rowid]=$libelle_type; |
|
| 1107 | - else $tab[$obj->code]=$libelle_type; |
|
| 1159 | + if (empty($option)) { |
|
| 1160 | + $tab[$obj->rowid]=$libelle_type; |
|
| 1161 | + } else { |
|
| 1162 | + $tab[$obj->code]=$libelle_type; |
|
| 1163 | + } |
|
| 1108 | 1164 | $i++; |
| 1109 | 1165 | } |
| 1110 | 1166 | return $tab; |
| 1111 | - } |
|
| 1112 | - else |
|
| 1167 | + } else |
|
| 1113 | 1168 | {
|
| 1114 | 1169 | $this->error=$this->db->lasterror(); |
| 1115 | 1170 | //dol_print_error($this->db); |
@@ -1148,19 +1203,29 @@ discard block |
||
| 1148 | 1203 | |
| 1149 | 1204 | $sql = "SELECT ec.fk_socpeople"; |
| 1150 | 1205 | $sql.= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; |
| 1151 | - if ($source == 'internal') $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1152 | - if ($source == 'external') $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1206 | + if ($source == 'internal') { |
|
| 1207 | + $sql.= " ".MAIN_DB_PREFIX."user as c,"; |
|
| 1208 | + } |
|
| 1209 | + if ($source == 'external') { |
|
| 1210 | + $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; |
|
| 1211 | + } |
|
| 1153 | 1212 | $sql.= " ".MAIN_DB_PREFIX."c_type_contact as tc"; |
| 1154 | 1213 | $sql.= " WHERE ec.element_id = ".$id; |
| 1155 | 1214 | $sql.= " AND ec.fk_socpeople = c.rowid"; |
| 1156 | - if ($source == 'internal') $sql.= " AND c.entity IN (".getEntity('user').")";
|
|
| 1157 | - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")";
|
|
| 1215 | + if ($source == 'internal') { |
|
| 1216 | + $sql.= " AND c.entity IN (".getEntity('user').")"; |
|
| 1217 | + } |
|
| 1218 | + if ($source == 'external') { |
|
| 1219 | + $sql.= " AND c.entity IN (".getEntity('societe').")"; |
|
| 1220 | + } |
|
| 1158 | 1221 | $sql.= " AND ec.fk_c_type_contact = tc.rowid"; |
| 1159 | 1222 | $sql.= " AND tc.element = '".$element."'"; |
| 1160 | 1223 | $sql.= " AND tc.source = '".$source."'"; |
| 1161 | 1224 | $sql.= " AND tc.code = '".$code."'"; |
| 1162 | 1225 | $sql.= " AND tc.active = 1"; |
| 1163 | - if ($status) $sql.= " AND ec.statut = ".$status; |
|
| 1226 | + if ($status) { |
|
| 1227 | + $sql.= " AND ec.statut = ".$status; |
|
| 1228 | + } |
|
| 1164 | 1229 | |
| 1165 | 1230 | dol_syslog(get_class($this)."::getIdContact", LOG_DEBUG); |
| 1166 | 1231 | $resql=$this->db->query($sql); |
@@ -1171,8 +1236,7 @@ discard block |
||
| 1171 | 1236 | $result[$i]=$obj->fk_socpeople; |
| 1172 | 1237 | $i++; |
| 1173 | 1238 | } |
| 1174 | - } |
|
| 1175 | - else |
|
| 1239 | + } else |
|
| 1176 | 1240 | {
|
| 1177 | 1241 | $this->error=$this->db->error(); |
| 1178 | 1242 | return null; |
@@ -1191,9 +1255,13 @@ discard block |
||
| 1191 | 1255 | function fetch_contact($contactid=null) |
| 1192 | 1256 | {
|
| 1193 | 1257 | // phpcs:enable |
| 1194 | - if (empty($contactid)) $contactid=$this->contactid; |
|
| 1258 | + if (empty($contactid)) { |
|
| 1259 | + $contactid=$this->contactid; |
|
| 1260 | + } |
|
| 1195 | 1261 | |
| 1196 | - if (empty($contactid)) return 0; |
|
| 1262 | + if (empty($contactid)) { |
|
| 1263 | + return 0; |
|
| 1264 | + } |
|
| 1197 | 1265 | |
| 1198 | 1266 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
| 1199 | 1267 | $contact = new Contact($this->db); |
@@ -1214,14 +1282,16 @@ discard block |
||
| 1214 | 1282 | // phpcs:enable |
| 1215 | 1283 | global $conf; |
| 1216 | 1284 | |
| 1217 | - if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) |
|
| 1218 | - return 0; |
|
| 1285 | + if (empty($this->socid) && empty($this->fk_soc) && empty($this->fk_thirdparty) && empty($force_thirdparty_id)) { |
|
| 1286 | + return 0; |
|
| 1287 | + } |
|
| 1219 | 1288 | |
| 1220 | 1289 | require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; |
| 1221 | 1290 | |
| 1222 | 1291 | $idtofetch = isset($this->socid) ? $this->socid : (isset($this->fk_soc) ? $this->fk_soc : $this->fk_thirdparty); |
| 1223 | - if ($force_thirdparty_id) |
|
| 1224 | - $idtofetch = $force_thirdparty_id; |
|
| 1292 | + if ($force_thirdparty_id) { |
|
| 1293 | + $idtofetch = $force_thirdparty_id; |
|
| 1294 | + } |
|
| 1225 | 1295 | |
| 1226 | 1296 | if ($idtofetch) {
|
| 1227 | 1297 | $thirdparty = new Societe($this->db); |
@@ -1234,8 +1304,9 @@ discard block |
||
| 1234 | 1304 | } |
| 1235 | 1305 | |
| 1236 | 1306 | return $result; |
| 1237 | - } else |
|
| 1238 | - return -1; |
|
| 1307 | + } else { |
|
| 1308 | + return -1; |
|
| 1309 | + } |
|
| 1239 | 1310 | } |
| 1240 | 1311 | |
| 1241 | 1312 | |
@@ -1281,20 +1352,25 @@ discard block |
||
| 1281 | 1352 | dol_syslog(get_class($this).'::fetch_barcode this->element='.$this->element.' this->barcode_type='.$this->barcode_type); |
| 1282 | 1353 | |
| 1283 | 1354 | $idtype=$this->barcode_type; |
| 1284 | - 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 |
|
| 1355 | + if (empty($idtype) && $idtype != '0') { |
|
| 1356 | + // If type of barcode no set, we try to guess. If set to '0' it means we forced to have type remain not defined |
|
| 1285 | 1357 | {
|
| 1286 | 1358 | if ($this->element == 'product') |
| 1287 | - $idtype = Globals::$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1288 | - else if ($this->element == 'societe') |
|
| 1289 | - $idtype = Globals::$conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1290 | - else dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING);
|
|
| 1359 | + $idtype = Globals::$conf->global->PRODUIT_DEFAULT_BARCODE_TYPE; |
|
| 1360 | + } else if ($this->element == 'societe') { |
|
| 1361 | + $idtype = Globals::$conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY; |
|
| 1362 | + } else { |
|
| 1363 | + dol_syslog('Call fetch_barcode with barcode_type not defined and cant be guessed', LOG_WARNING); |
|
| 1364 | + } |
|
| 1291 | 1365 | } |
| 1292 | 1366 | |
| 1293 | 1367 | if ($idtype > 0) |
| 1294 | 1368 | {
|
| 1295 | - 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 |
|
| 1369 | + if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) { |
|
| 1370 | + // If data not already loaded |
|
| 1296 | 1371 | {
|
| 1297 | - $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1372 | + $sql = "SELECT rowid, code, libelle as label, coder"; |
|
| 1373 | + } |
|
| 1298 | 1374 | $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; |
| 1299 | 1375 | $sql.= " WHERE rowid = ".$idtype; |
| 1300 | 1376 | dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); |
@@ -1307,8 +1383,7 @@ discard block |
||
| 1307 | 1383 | $this->barcode_type_label = $obj->label; |
| 1308 | 1384 | $this->barcode_type_coder = $obj->coder; |
| 1309 | 1385 | return 1; |
| 1310 | - } |
|
| 1311 | - else |
|
| 1386 | + } else |
|
| 1312 | 1387 | {
|
| 1313 | 1388 | dol_print_error($this->db); |
| 1314 | 1389 | return -1; |
@@ -1329,8 +1404,13 @@ discard block |
||
| 1329 | 1404 | // phpcs:enable |
| 1330 | 1405 | include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
| 1331 | 1406 | |
| 1332 | - if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility |
|
| 1333 | - if (empty($this->fk_project)) return 0; |
|
| 1407 | + if (empty($this->fk_project) && ! empty($this->fk_projet)) { |
|
| 1408 | + $this->fk_project = $this->fk_projet; |
|
| 1409 | + } |
|
| 1410 | + // For backward compatibility |
|
| 1411 | + if (empty($this->fk_project)) { |
|
| 1412 | + return 0; |
|
| 1413 | + } |
|
| 1334 | 1414 | |
| 1335 | 1415 | $project = new Project($this->db); |
| 1336 | 1416 | $result = $project->fetch($this->fk_project); |
@@ -1351,7 +1431,9 @@ discard block |
||
| 1351 | 1431 | // phpcs:enable |
| 1352 | 1432 | include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
| 1353 | 1433 | |
| 1354 | - if (empty($this->fk_product)) return 0; |
|
| 1434 | + if (empty($this->fk_product)) { |
|
| 1435 | + return 0; |
|
| 1436 | + } |
|
| 1355 | 1437 | |
| 1356 | 1438 | $product = new Product($this->db); |
| 1357 | 1439 | $result = $product->fetch($this->fk_product); |
@@ -1385,9 +1467,15 @@ discard block |
||
| 1385 | 1467 | function fetch_origin() |
| 1386 | 1468 | {
|
| 1387 | 1469 | // phpcs:enable |
| 1388 | - if ($this->origin == 'shipping') $this->origin = 'expedition'; |
|
| 1389 | - if ($this->origin == 'delivery') $this->origin = 'livraison'; |
|
| 1390 | - if ($this->origin == 'order_supplier') $this->origin = 'commandeFournisseur'; |
|
| 1470 | + if ($this->origin == 'shipping') { |
|
| 1471 | + $this->origin = 'expedition'; |
|
| 1472 | + } |
|
| 1473 | + if ($this->origin == 'delivery') { |
|
| 1474 | + $this->origin = 'livraison'; |
|
| 1475 | + } |
|
| 1476 | + if ($this->origin == 'order_supplier') { |
|
| 1477 | + $this->origin = 'commandeFournisseur'; |
|
| 1478 | + } |
|
| 1391 | 1479 | |
| 1392 | 1480 | $origin = $this->origin; |
| 1393 | 1481 | |
@@ -1479,29 +1567,48 @@ discard block |
||
| 1479 | 1567 | {
|
| 1480 | 1568 | global $user,$langs,$conf; |
| 1481 | 1569 | |
| 1482 | - if (empty($table)) $table=$this->table_element; |
|
| 1483 | - if (empty($id)) $id=$this->id; |
|
| 1484 | - if (empty($format)) $format='text'; |
|
| 1485 | - if (empty($id_field)) $id_field='rowid'; |
|
| 1570 | + if (empty($table)) { |
|
| 1571 | + $table=$this->table_element; |
|
| 1572 | + } |
|
| 1573 | + if (empty($id)) { |
|
| 1574 | + $id=$this->id; |
|
| 1575 | + } |
|
| 1576 | + if (empty($format)) { |
|
| 1577 | + $format='text'; |
|
| 1578 | + } |
|
| 1579 | + if (empty($id_field)) { |
|
| 1580 | + $id_field='rowid'; |
|
| 1581 | + } |
|
| 1486 | 1582 | |
| 1487 | 1583 | $error=0; |
| 1488 | 1584 | |
| 1489 | 1585 | $this->db->begin(); |
| 1490 | 1586 | |
| 1491 | 1587 | // Special case |
| 1492 | - if ($table == 'product' && $field == 'note_private') $field='note'; |
|
| 1493 | - if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) $fk_user_field = 'fk_user_mod';
|
|
| 1588 | + if ($table == 'product' && $field == 'note_private') { |
|
| 1589 | + $field='note'; |
|
| 1590 | + } |
|
| 1591 | + if (in_array($table, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))) { |
|
| 1592 | + $fk_user_field = 'fk_user_mod'; |
|
| 1593 | + } |
|
| 1494 | 1594 | |
| 1495 | 1595 | $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; |
| 1496 | 1596 | |
| 1497 | - if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1498 | - else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); |
|
| 1499 | - else if ($format == 'date') $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1597 | + if ($format == 'text') { |
|
| 1598 | + $sql.= $field." = '".$this->db->escape($value)."'"; |
|
| 1599 | + } else if ($format == 'int') { |
|
| 1600 | + $sql.= $field." = ".$this->db->escape($value); |
|
| 1601 | + } else if ($format == 'date') { |
|
| 1602 | + $sql.= $field." = ".($value ? "'".$this->db->idate($value)."'" : "null"); |
|
| 1603 | + } |
|
| 1500 | 1604 | |
| 1501 | 1605 | if ($fk_user_field) |
| 1502 | 1606 | {
|
| 1503 | - if (! empty($fuser) && is_object($fuser)) $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1504 | - elseif (empty($fuser) || $fuser != 'none') $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1607 | + if (! empty($fuser) && is_object($fuser)) { |
|
| 1608 | + $sql.=", ".$fk_user_field." = ".$fuser->id; |
|
| 1609 | + } elseif (empty($fuser) || $fuser != 'none') { |
|
| 1610 | + $sql.=", ".$fk_user_field." = ".$user->id; |
|
| 1611 | + } |
|
| 1505 | 1612 | } |
| 1506 | 1613 | |
| 1507 | 1614 | $sql.= " WHERE ".$id_field." = ".$id; |
@@ -1516,28 +1623,32 @@ discard block |
||
| 1516 | 1623 | if (empty($this->fields) && method_exists($this, 'fetch')) |
| 1517 | 1624 | {
|
| 1518 | 1625 | $result = $this->fetch($id); |
| 1519 | - } |
|
| 1520 | - else |
|
| 1626 | + } else |
|
| 1521 | 1627 | {
|
| 1522 | 1628 | $result = $this->fetchCommon($id); |
| 1523 | 1629 | } |
| 1524 | - if ($result >= 0) $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); // This may set this->errors |
|
| 1525 | - if ($result < 0) $error++; |
|
| 1630 | + if ($result >= 0) { |
|
| 1631 | + $result=$this->call_trigger($trigkey, (! empty($fuser) && is_object($fuser)) ? $fuser : $user); |
|
| 1632 | + } |
|
| 1633 | + // This may set this->errors |
|
| 1634 | + if ($result < 0) { |
|
| 1635 | + $error++; |
|
| 1636 | + } |
|
| 1526 | 1637 | } |
| 1527 | 1638 | |
| 1528 | 1639 | if (! $error) |
| 1529 | 1640 | {
|
| 1530 | - if (property_exists($this, $field)) $this->$field = $value; |
|
| 1641 | + if (property_exists($this, $field)) { |
|
| 1642 | + $this->$field = $value; |
|
| 1643 | + } |
|
| 1531 | 1644 | $this->db->commit(); |
| 1532 | 1645 | return 1; |
| 1533 | - } |
|
| 1534 | - else |
|
| 1646 | + } else |
|
| 1535 | 1647 | {
|
| 1536 | 1648 | $this->db->rollback(); |
| 1537 | 1649 | return -2; |
| 1538 | 1650 | } |
| 1539 | - } |
|
| 1540 | - else |
|
| 1651 | + } else |
|
| 1541 | 1652 | {
|
| 1542 | 1653 | $this->error=$this->db->lasterror(); |
| 1543 | 1654 | $this->db->rollback(); |
@@ -1564,36 +1675,66 @@ discard block |
||
| 1564 | 1675 | dol_print_error('',get_class($this)."::load_previous_next_ref was called on objet with property table_element not defined");
|
| 1565 | 1676 | return -1; |
| 1566 | 1677 | } |
| 1567 | - if ($fieldid == 'none') return 1; |
|
| 1678 | + if ($fieldid == 'none') { |
|
| 1679 | + return 1; |
|
| 1680 | + } |
|
| 1568 | 1681 | |
| 1569 | 1682 | // Security on socid |
| 1570 | 1683 | $socid = 0; |
| 1571 | - if ($user->societe_id > 0) $socid = $user->societe_id; |
|
| 1684 | + if ($user->societe_id > 0) { |
|
| 1685 | + $socid = $user->societe_id; |
|
| 1686 | + } |
|
| 1572 | 1687 | |
| 1573 | 1688 | // this->ismultientitymanaged contains |
| 1574 | 1689 | // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
| 1575 | 1690 | $alias = 's'; |
| 1576 | - if ($this->element == 'societe') $alias = 'te'; |
|
| 1691 | + if ($this->element == 'societe') { |
|
| 1692 | + $alias = 'te'; |
|
| 1693 | + } |
|
| 1577 | 1694 | |
| 1578 | 1695 | $sql = "SELECT MAX(te.".$fieldid.")"; |
| 1579 | 1696 | $sql.= " FROM ".(empty($nodbprefix)?MAIN_DB_PREFIX:'').$this->table_element." as te"; |
| 1580 | 1697 | if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1581 | 1698 | $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
| 1582 | 1699 | } |
| 1583 | - 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 |
|
| 1584 | - 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 |
|
| 1585 | - 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 |
|
| 1586 | - 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"; |
|
| 1700 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1701 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1702 | + } |
|
| 1703 | + // If we need to link to societe to limit select to entity |
|
| 1704 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1705 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1706 | + } |
|
| 1707 | + // If we need to link to societe to limit select to socid |
|
| 1708 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1709 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; |
|
| 1710 | + } |
|
| 1711 | + // If we need to link to societe to limit select to socid |
|
| 1712 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) { |
|
| 1713 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1714 | + } |
|
| 1587 | 1715 | $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
| 1588 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1589 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1716 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1717 | + $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1718 | + } |
|
| 1719 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1720 | + $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1721 | + } |
|
| 1590 | 1722 | if (! empty($filter)) |
| 1591 | 1723 | {
|
| 1592 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1724 | + if (! preg_match('/^\s*AND/i', $filter)) { |
|
| 1725 | + $sql.=" AND "; |
|
| 1726 | + } |
|
| 1727 | + // For backward compatibility |
|
| 1593 | 1728 | $sql.=$filter; |
| 1594 | 1729 | } |
| 1595 | - 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 |
|
| 1596 | - 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 |
|
| 1730 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1731 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1732 | + } |
|
| 1733 | + // If we need to link to societe to limit select to entity |
|
| 1734 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1735 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1736 | + } |
|
| 1737 | + // If we need to link to societe to limit select to socid |
|
| 1597 | 1738 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
| 1598 | 1739 | if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1599 | 1740 | if (!empty($user->admin) && empty($user->entity) && Globals::$conf->entity == 1) {
|
@@ -1606,9 +1747,15 @@ discard block |
||
| 1606 | 1747 | $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
| 1607 | 1748 | } |
| 1608 | 1749 | } |
| 1609 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1610 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1611 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1750 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') { |
|
| 1751 | + $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1752 | + } |
|
| 1753 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') { |
|
| 1754 | + $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1755 | + } |
|
| 1756 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') { |
|
| 1757 | + $sql.= ' AND te.rowid = ' . $socid; |
|
| 1758 | + } |
|
| 1612 | 1759 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1613 | 1760 | |
| 1614 | 1761 | $result = $this->db->query($sql); |
@@ -1626,20 +1773,44 @@ discard block |
||
| 1626 | 1773 | if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1627 | 1774 | $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; |
| 1628 | 1775 | } |
| 1629 | - 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 |
|
| 1630 | - 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 |
|
| 1631 | - 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 |
|
| 1632 | - 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"; |
|
| 1776 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1777 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1778 | + } |
|
| 1779 | + // If we need to link to societe to limit select to entity |
|
| 1780 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1781 | + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; |
|
| 1782 | + } |
|
| 1783 | + // If we need to link to societe to limit select to socid |
|
| 1784 | + else if ($this->restrictiononfksoc == 2 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1785 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; |
|
| 1786 | + } |
|
| 1787 | + // If we need to link to societe to limit select to socid |
|
| 1788 | + if ($this->restrictiononfksoc && !$user->rights->societe->client->voir && !$socid) { |
|
| 1789 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; |
|
| 1790 | + } |
|
| 1633 | 1791 | $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) |
| 1634 | - if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1635 | - if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1792 | + if ($this->restrictiononfksoc == 1 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1793 | + $sql.= " AND sc.fk_user = " .$user->id; |
|
| 1794 | + } |
|
| 1795 | + if ($this->restrictiononfksoc == 2 && !$user->rights->societe->client->voir && !$socid) { |
|
| 1796 | + $sql.= " AND (sc.fk_user = " .$user->id.' OR te.fk_soc IS NULL)'; |
|
| 1797 | + } |
|
| 1636 | 1798 | if (! empty($filter)) |
| 1637 | 1799 | {
|
| 1638 | - if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility
|
|
| 1800 | + if (! preg_match('/^\s*AND/i', $filter)) { |
|
| 1801 | + $sql.=" AND "; |
|
| 1802 | + } |
|
| 1803 | + // For backward compatibility |
|
| 1639 | 1804 | $sql.=$filter; |
| 1640 | 1805 | } |
| 1641 | - 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 |
|
| 1642 | - 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 |
|
| 1806 | + if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2) { |
|
| 1807 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1808 | + } |
|
| 1809 | + // If we need to link to societe to limit select to entity |
|
| 1810 | + else if ($this->restrictiononfksoc == 1 && $this->element != 'societe' && !$user->rights->societe->client->voir && !$socid) { |
|
| 1811 | + $sql.= ' AND te.fk_soc = s.rowid'; |
|
| 1812 | + } |
|
| 1813 | + // If we need to link to societe to limit select to socid |
|
| 1643 | 1814 | if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
| 1644 | 1815 | if ($this->element == 'user' && !empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1645 | 1816 | if (!empty($user->admin) && empty($user->entity) && Globals::$conf->entity == 1) {
|
@@ -1652,9 +1823,15 @@ discard block |
||
| 1652 | 1823 | $sql.= ' AND te.entity IN ('.getEntity($this->element).')';
|
| 1653 | 1824 | } |
| 1654 | 1825 | } |
| 1655 | - if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1656 | - if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1657 | - if ($this->restrictiononfksoc && $socid && $this->element == 'societe') $sql.= ' AND te.rowid = ' . $socid; |
|
| 1826 | + if ($this->restrictiononfksoc == 1 && $socid && $this->element != 'societe') { |
|
| 1827 | + $sql.= ' AND te.fk_soc = ' . $socid; |
|
| 1828 | + } |
|
| 1829 | + if ($this->restrictiononfksoc == 2 && $socid && $this->element != 'societe') { |
|
| 1830 | + $sql.= ' AND (te.fk_soc = ' . $socid.' OR te.fk_soc IS NULL)'; |
|
| 1831 | + } |
|
| 1832 | + if ($this->restrictiononfksoc && $socid && $this->element == 'societe') { |
|
| 1833 | + $sql.= ' AND te.rowid = ' . $socid; |
|
| 1834 | + } |
|
| 1658 | 1835 | //print 'socid='.$socid.' restrictiononfksoc='.$this->restrictiononfksoc.' ismultientitymanaged = '.$this->ismultientitymanaged.' filter = '.$filter.' -> '.$sql."<br>"; |
| 1659 | 1836 | // 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 |
| 1660 | 1837 | |
@@ -1686,8 +1863,11 @@ discard block |
||
| 1686 | 1863 | $i = 0; |
| 1687 | 1864 | while ($i < $num) |
| 1688 | 1865 | {
|
| 1689 | - if ($source == 'thirdparty') $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1690 | - else $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1866 | + if ($source == 'thirdparty') { |
|
| 1867 | + $contactAlreadySelected[$i] = $tab[$i]['socid']; |
|
| 1868 | + } else { |
|
| 1869 | + $contactAlreadySelected[$i] = $tab[$i]['id']; |
|
| 1870 | + } |
|
| 1691 | 1871 | $i++; |
| 1692 | 1872 | } |
| 1693 | 1873 | return $contactAlreadySelected; |
@@ -1711,14 +1891,19 @@ discard block |
||
| 1711 | 1891 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1712 | 1892 | if ($this->table_element == 'actioncomm') |
| 1713 | 1893 | {
|
| 1714 | - if ($projectid) $sql.= ' SET fk_project = '.$projectid; |
|
| 1715 | - else $sql.= ' SET fk_project = NULL'; |
|
| 1894 | + if ($projectid) { |
|
| 1895 | + $sql.= ' SET fk_project = '.$projectid; |
|
| 1896 | + } else { |
|
| 1897 | + $sql.= ' SET fk_project = NULL'; |
|
| 1898 | + } |
|
| 1716 | 1899 | $sql.= ' WHERE id = '.$this->id; |
| 1717 | - } |
|
| 1718 | - else |
|
| 1900 | + } else |
|
| 1719 | 1901 | {
|
| 1720 | - if ($projectid) $sql.= ' SET fk_projet = '.$projectid; |
|
| 1721 | - else $sql.= ' SET fk_projet = NULL'; |
|
| 1902 | + if ($projectid) { |
|
| 1903 | + $sql.= ' SET fk_projet = '.$projectid; |
|
| 1904 | + } else { |
|
| 1905 | + $sql.= ' SET fk_projet = NULL'; |
|
| 1906 | + } |
|
| 1722 | 1907 | $sql.= ' WHERE rowid = '.$this->id; |
| 1723 | 1908 | } |
| 1724 | 1909 | |
@@ -1727,8 +1912,7 @@ discard block |
||
| 1727 | 1912 | {
|
| 1728 | 1913 | $this->fk_project = $projectid; |
| 1729 | 1914 | return 1; |
| 1730 | - } |
|
| 1731 | - else |
|
| 1915 | + } else |
|
| 1732 | 1916 | {
|
| 1733 | 1917 | dol_print_error($this->db); |
| 1734 | 1918 | return -1; |
@@ -1748,8 +1932,12 @@ discard block |
||
| 1748 | 1932 | {
|
| 1749 | 1933 | // TODO uniformize field name |
| 1750 | 1934 | $fieldname = 'fk_mode_reglement'; |
| 1751 | - if ($this->element == 'societe') $fieldname = 'mode_reglement'; |
|
| 1752 | - if (get_class($this) == 'Fournisseur') $fieldname = 'mode_reglement_supplier'; |
|
| 1935 | + if ($this->element == 'societe') { |
|
| 1936 | + $fieldname = 'mode_reglement'; |
|
| 1937 | + } |
|
| 1938 | + if (get_class($this) == 'Fournisseur') { |
|
| 1939 | + $fieldname = 'mode_reglement_supplier'; |
|
| 1940 | + } |
|
| 1753 | 1941 | |
| 1754 | 1942 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1755 | 1943 | $sql .= ' SET '.$fieldname.' = '.$id; |
@@ -1759,17 +1947,17 @@ discard block |
||
| 1759 | 1947 | {
|
| 1760 | 1948 | $this->mode_reglement_id = $id; |
| 1761 | 1949 | // for supplier |
| 1762 | - if (get_class($this) == 'Fournisseur') $this->mode_reglement_supplier_id = $id; |
|
| 1950 | + if (get_class($this) == 'Fournisseur') { |
|
| 1951 | + $this->mode_reglement_supplier_id = $id; |
|
| 1952 | + } |
|
| 1763 | 1953 | return 1; |
| 1764 | - } |
|
| 1765 | - else |
|
| 1954 | + } else |
|
| 1766 | 1955 | {
|
| 1767 | 1956 | dol_syslog(get_class($this).'::setPaymentMethods Erreur '.$sql.' - '.$this->db->error()); |
| 1768 | 1957 | $this->error=$this->db->error(); |
| 1769 | 1958 | return -1; |
| 1770 | 1959 | } |
| 1771 | - } |
|
| 1772 | - else |
|
| 1960 | + } else |
|
| 1773 | 1961 | {
|
| 1774 | 1962 | dol_syslog(get_class($this).'::setPaymentMethods, status of the object is incompatible'); |
| 1775 | 1963 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1799,18 +1987,18 @@ discard block |
||
| 1799 | 1987 | $this->multicurrency_code = $code; |
| 1800 | 1988 | |
| 1801 | 1989 | list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); |
| 1802 | - if ($rate) $this->setMulticurrencyRate($rate,2); |
|
| 1990 | + if ($rate) { |
|
| 1991 | + $this->setMulticurrencyRate($rate,2); |
|
| 1992 | + } |
|
| 1803 | 1993 | |
| 1804 | 1994 | return 1; |
| 1805 | - } |
|
| 1806 | - else |
|
| 1995 | + } else |
|
| 1807 | 1996 | {
|
| 1808 | 1997 | dol_syslog(get_class($this).'::setMulticurrencyCode Erreur '.$sql.' - '.$this->db->error()); |
| 1809 | 1998 | $this->error=$this->db->error(); |
| 1810 | 1999 | return -1; |
| 1811 | 2000 | } |
| 1812 | - } |
|
| 1813 | - else |
|
| 2001 | + } else |
|
| 1814 | 2002 | {
|
| 1815 | 2003 | dol_syslog(get_class($this).'::setMulticurrencyCode, status of the object is incompatible'); |
| 1816 | 2004 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1904,15 +2092,13 @@ discard block |
||
| 1904 | 2092 | } |
| 1905 | 2093 | |
| 1906 | 2094 | return 1; |
| 1907 | - } |
|
| 1908 | - else |
|
| 2095 | + } else |
|
| 1909 | 2096 | {
|
| 1910 | 2097 | dol_syslog(get_class($this).'::setMulticurrencyRate Erreur '.$sql.' - '.$this->db->error()); |
| 1911 | 2098 | $this->error=$this->db->error(); |
| 1912 | 2099 | return -1; |
| 1913 | 2100 | } |
| 1914 | - } |
|
| 1915 | - else |
|
| 2101 | + } else |
|
| 1916 | 2102 | {
|
| 1917 | 2103 | dol_syslog(get_class($this).'::setMulticurrencyRate, status of the object is incompatible'); |
| 1918 | 2104 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1933,8 +2119,12 @@ discard block |
||
| 1933 | 2119 | {
|
| 1934 | 2120 | // TODO uniformize field name |
| 1935 | 2121 | $fieldname = 'fk_cond_reglement'; |
| 1936 | - if ($this->element == 'societe') $fieldname = 'cond_reglement'; |
|
| 1937 | - if (get_class($this) == 'Fournisseur') $fieldname = 'cond_reglement_supplier'; |
|
| 2122 | + if ($this->element == 'societe') { |
|
| 2123 | + $fieldname = 'cond_reglement'; |
|
| 2124 | + } |
|
| 2125 | + if (get_class($this) == 'Fournisseur') { |
|
| 2126 | + $fieldname = 'cond_reglement_supplier'; |
|
| 2127 | + } |
|
| 1938 | 2128 | |
| 1939 | 2129 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 1940 | 2130 | $sql .= ' SET '.$fieldname.' = '.$id; |
@@ -1944,18 +2134,18 @@ discard block |
||
| 1944 | 2134 | {
|
| 1945 | 2135 | $this->cond_reglement_id = $id; |
| 1946 | 2136 | // for supplier |
| 1947 | - if (get_class($this) == 'Fournisseur') $this->cond_reglement_supplier_id = $id; |
|
| 2137 | + if (get_class($this) == 'Fournisseur') { |
|
| 2138 | + $this->cond_reglement_supplier_id = $id; |
|
| 2139 | + } |
|
| 1948 | 2140 | $this->cond_reglement = $id; // for compatibility |
| 1949 | 2141 | return 1; |
| 1950 | - } |
|
| 1951 | - else |
|
| 2142 | + } else |
|
| 1952 | 2143 | {
|
| 1953 | 2144 | dol_syslog(get_class($this).'::setPaymentTerms Erreur '.$sql.' - '.$this->db->error()); |
| 1954 | 2145 | $this->error=$this->db->error(); |
| 1955 | 2146 | return -1; |
| 1956 | 2147 | } |
| 1957 | - } |
|
| 1958 | - else |
|
| 2148 | + } else |
|
| 1959 | 2149 | {
|
| 1960 | 2150 | dol_syslog(get_class($this).'::setPaymentTerms, status of the object is incompatible'); |
| 1961 | 2151 | $this->error='Status of the object is incompatible '.$this->statut; |
@@ -1973,7 +2163,9 @@ discard block |
||
| 1973 | 2163 | function setDeliveryAddress($id) |
| 1974 | 2164 | {
|
| 1975 | 2165 | $fieldname = 'fk_delivery_address'; |
| 1976 | - if ($this->element == 'delivery' || $this->element == 'shipping') $fieldname = 'fk_address'; |
|
| 2166 | + if ($this->element == 'delivery' || $this->element == 'shipping') { |
|
| 2167 | + $fieldname = 'fk_address'; |
|
| 2168 | + } |
|
| 1977 | 2169 | |
| 1978 | 2170 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".$id; |
| 1979 | 2171 | $sql.= " WHERE rowid = ".$this->id." AND fk_statut = 0"; |
@@ -1982,8 +2174,7 @@ discard block |
||
| 1982 | 2174 | {
|
| 1983 | 2175 | $this->fk_delivery_address = $id; |
| 1984 | 2176 | return 1; |
| 1985 | - } |
|
| 1986 | - else |
|
| 2177 | + } else |
|
| 1987 | 2178 | {
|
| 1988 | 2179 | $this->error=$this->db->error(); |
| 1989 | 2180 | dol_syslog(get_class($this).'::setDeliveryAddress Erreur '.$sql.' - '.$this->error); |
@@ -2005,7 +2196,9 @@ discard block |
||
| 2005 | 2196 | {
|
| 2006 | 2197 | global $user; |
| 2007 | 2198 | |
| 2008 | - if (empty($userused)) $userused=$user; |
|
| 2199 | + if (empty($userused)) { |
|
| 2200 | + $userused=$user; |
|
| 2201 | + } |
|
| 2009 | 2202 | |
| 2010 | 2203 | $error = 0; |
| 2011 | 2204 | |
@@ -2016,7 +2209,9 @@ discard block |
||
| 2016 | 2209 | |
| 2017 | 2210 | $this->db->begin(); |
| 2018 | 2211 | |
| 2019 | - if ($shipping_method_id<0) $shipping_method_id='NULL'; |
|
| 2212 | + if ($shipping_method_id<0) { |
|
| 2213 | + $shipping_method_id='NULL'; |
|
| 2214 | + } |
|
| 2020 | 2215 | dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')');
|
| 2021 | 2216 | |
| 2022 | 2217 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2033,7 +2228,9 @@ discard block |
||
| 2033 | 2228 | // Call trigger |
| 2034 | 2229 | $this->context=array('shippingmethodupdate'=>1);
|
| 2035 | 2230 | $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
| 2036 | - if ($result < 0) $error++; |
|
| 2231 | + if ($result < 0) { |
|
| 2232 | + $error++; |
|
| 2233 | + } |
|
| 2037 | 2234 | // End call trigger |
| 2038 | 2235 | } |
| 2039 | 2236 | } |
@@ -2061,7 +2258,9 @@ discard block |
||
| 2061 | 2258 | dol_syslog(get_class($this)."::setWarehouse was called on objet with property table_element not defined",LOG_ERR); |
| 2062 | 2259 | return -1; |
| 2063 | 2260 | } |
| 2064 | - if ($warehouse_id<0) $warehouse_id='NULL'; |
|
| 2261 | + if ($warehouse_id<0) { |
|
| 2262 | + $warehouse_id='NULL'; |
|
| 2263 | + } |
|
| 2065 | 2264 | dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')');
|
| 2066 | 2265 | |
| 2067 | 2266 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2108,8 +2307,7 @@ discard block |
||
| 2108 | 2307 | {
|
| 2109 | 2308 | $this->modelpdf=$modelpdf; |
| 2110 | 2309 | return 1; |
| 2111 | - } |
|
| 2112 | - else |
|
| 2310 | + } else |
|
| 2113 | 2311 | {
|
| 2114 | 2312 | dol_print_error($this->db); |
| 2115 | 2313 | return 0; |
@@ -2129,7 +2327,9 @@ discard block |
||
| 2129 | 2327 | {
|
| 2130 | 2328 | global $user; |
| 2131 | 2329 | |
| 2132 | - if (empty($userused)) $userused=$user; |
|
| 2330 | + if (empty($userused)) { |
|
| 2331 | + $userused=$user; |
|
| 2332 | + } |
|
| 2133 | 2333 | |
| 2134 | 2334 | $error = 0; |
| 2135 | 2335 | |
@@ -2139,7 +2339,9 @@ discard block |
||
| 2139 | 2339 | } |
| 2140 | 2340 | $this->db->begin(); |
| 2141 | 2341 | |
| 2142 | - if ($fk_account<0) $fk_account='NULL'; |
|
| 2342 | + if ($fk_account<0) { |
|
| 2343 | + $fk_account='NULL'; |
|
| 2344 | + } |
|
| 2143 | 2345 | dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')');
|
| 2144 | 2346 | |
| 2145 | 2347 | $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; |
@@ -2152,15 +2354,16 @@ discard block |
||
| 2152 | 2354 | dol_syslog(get_class($this).'::setBankAccount Error '.$sql.' - '.$this->db->error()); |
| 2153 | 2355 | $this->error = $this->db->lasterror(); |
| 2154 | 2356 | $error++; |
| 2155 | - } |
|
| 2156 | - else |
|
| 2357 | + } else |
|
| 2157 | 2358 | {
|
| 2158 | 2359 | if (!$notrigger) |
| 2159 | 2360 | {
|
| 2160 | 2361 | // Call trigger |
| 2161 | 2362 | $this->context=array('bankaccountupdate'=>1);
|
| 2162 | 2363 | $result = $this->call_trigger(strtoupper(get_class($this)) . '_MODIFY', $userused); |
| 2163 | - if ($result < 0) $error++; |
|
| 2364 | + if ($result < 0) { |
|
| 2365 | + $error++; |
|
| 2366 | + } |
|
| 2164 | 2367 | // End call trigger |
| 2165 | 2368 | } |
| 2166 | 2369 | } |
@@ -2168,8 +2371,7 @@ discard block |
||
| 2168 | 2371 | {
|
| 2169 | 2372 | $this->db->rollback(); |
| 2170 | 2373 | return -1; |
| 2171 | - } |
|
| 2172 | - else |
|
| 2374 | + } else |
|
| 2173 | 2375 | {
|
| 2174 | 2376 | $this->fk_account = ($fk_account=='NULL')?null:$fk_account; |
| 2175 | 2377 | $this->db->commit(); |
@@ -2208,8 +2410,12 @@ discard block |
||
| 2208 | 2410 | $nl=0; |
| 2209 | 2411 | $sql = 'SELECT count(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2210 | 2412 | $sql.= ' WHERE '.$this->fk_element.'='.$this->id; |
| 2211 | - if (! $renum) $sql.= ' AND rang = 0'; |
|
| 2212 | - if ($renum) $sql.= ' AND rang <> 0'; |
|
| 2413 | + if (! $renum) { |
|
| 2414 | + $sql.= ' AND rang = 0'; |
|
| 2415 | + } |
|
| 2416 | + if ($renum) { |
|
| 2417 | + $sql.= ' AND rang <> 0'; |
|
| 2418 | + } |
|
| 2213 | 2419 | |
| 2214 | 2420 | dol_syslog(get_class($this)."::line_order", LOG_DEBUG); |
| 2215 | 2421 | $resql = $this->db->query($sql); |
@@ -2217,8 +2423,9 @@ discard block |
||
| 2217 | 2423 | {
|
| 2218 | 2424 | $row = $this->db->fetch_row($resql); |
| 2219 | 2425 | $nl = $row[0]; |
| 2220 | - } |
|
| 2221 | - else dol_print_error($this->db); |
|
| 2426 | + } else { |
|
| 2427 | + dol_print_error($this->db); |
|
| 2428 | + } |
|
| 2222 | 2429 | if ($nl > 0) |
| 2223 | 2430 | {
|
| 2224 | 2431 | // The goal of this part is to reorder all lines, with all children lines sharing the same |
@@ -2228,7 +2435,9 @@ discard block |
||
| 2228 | 2435 | // We first search all lines that are parent lines (for multilevel details lines) |
| 2229 | 2436 | $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2230 | 2437 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
| 2231 | - if ($fk_parent_line) $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2438 | + if ($fk_parent_line) { |
|
| 2439 | + $sql.= ' AND fk_parent_line IS NULL'; |
|
| 2440 | + } |
|
| 2232 | 2441 | $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; |
| 2233 | 2442 | |
| 2234 | 2443 | dol_syslog(get_class($this)."::line_order search all parent lines", LOG_DEBUG); |
@@ -2260,8 +2469,7 @@ discard block |
||
| 2260 | 2469 | $this->updateRangOfLine($row, ($key+1)); |
| 2261 | 2470 | } |
| 2262 | 2471 | } |
| 2263 | - } |
|
| 2264 | - else |
|
| 2472 | + } else |
|
| 2265 | 2473 | {
|
| 2266 | 2474 | dol_print_error($this->db); |
| 2267 | 2475 | } |
@@ -2354,7 +2562,9 @@ discard block |
||
| 2354 | 2562 | function updateRangOfLine($rowid,$rang) |
| 2355 | 2563 | {
|
| 2356 | 2564 | $fieldposition = 'rang'; |
| 2357 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2565 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2566 | + $fieldposition = 'position'; |
|
| 2567 | + } |
|
| 2358 | 2568 | |
| 2359 | 2569 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2360 | 2570 | $sql.= ' WHERE rowid = '.$rowid; |
@@ -2395,7 +2605,9 @@ discard block |
||
| 2395 | 2605 | if ($rang > 1) |
| 2396 | 2606 | {
|
| 2397 | 2607 | $fieldposition = 'rang'; |
| 2398 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2608 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2609 | + $fieldposition = 'position'; |
|
| 2610 | + } |
|
| 2399 | 2611 | |
| 2400 | 2612 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang ; |
| 2401 | 2613 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
@@ -2408,8 +2620,7 @@ discard block |
||
| 2408 | 2620 | {
|
| 2409 | 2621 | dol_print_error($this->db); |
| 2410 | 2622 | } |
| 2411 | - } |
|
| 2412 | - else |
|
| 2623 | + } else |
|
| 2413 | 2624 | {
|
| 2414 | 2625 | dol_print_error($this->db); |
| 2415 | 2626 | } |
@@ -2429,7 +2640,9 @@ discard block |
||
| 2429 | 2640 | if ($rang < $max) |
| 2430 | 2641 | {
|
| 2431 | 2642 | $fieldposition = 'rang'; |
| 2432 | - if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) $fieldposition = 'position';
|
|
| 2643 | + if (in_array($this->table_element_line, array('ecm_files', 'emailcollector_emailcollectoraction'))) { |
|
| 2644 | + $fieldposition = 'position'; |
|
| 2645 | + } |
|
| 2433 | 2646 | |
| 2434 | 2647 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; |
| 2435 | 2648 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
@@ -2442,8 +2655,7 @@ discard block |
||
| 2442 | 2655 | {
|
| 2443 | 2656 | dol_print_error($this->db); |
| 2444 | 2657 | } |
| 2445 | - } |
|
| 2446 | - else |
|
| 2658 | + } else |
|
| 2447 | 2659 | {
|
| 2448 | 2660 | dol_print_error($this->db); |
| 2449 | 2661 | } |
@@ -2514,8 +2726,7 @@ discard block |
||
| 2514 | 2726 | if (! empty($row[0])) |
| 2515 | 2727 | {
|
| 2516 | 2728 | return $row[0]; |
| 2517 | - } |
|
| 2518 | - else |
|
| 2729 | + } else |
|
| 2519 | 2730 | {
|
| 2520 | 2731 | return $this->getRangOfLine($fk_parent_line); |
| 2521 | 2732 | } |
@@ -2562,8 +2773,7 @@ discard block |
||
| 2562 | 2773 | {
|
| 2563 | 2774 | $this->ref_ext = $ref_ext; |
| 2564 | 2775 | return 1; |
| 2565 | - } |
|
| 2566 | - else |
|
| 2776 | + } else |
|
| 2567 | 2777 | {
|
| 2568 | 2778 | $this->error=$this->db->error(); |
| 2569 | 2779 | return -1; |
@@ -2597,7 +2807,9 @@ discard block |
||
| 2597 | 2807 | } |
| 2598 | 2808 | // Special cas |
| 2599 | 2809 | //var_dump($this->table_element);exit; |
| 2600 | - if ($this->table_element == 'product') $suffix=''; |
|
| 2810 | + if ($this->table_element == 'product') { |
|
| 2811 | + $suffix=''; |
|
| 2812 | + } |
|
| 2601 | 2813 | |
| 2602 | 2814 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; |
| 2603 | 2815 | $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
|
@@ -2607,16 +2819,17 @@ discard block |
||
| 2607 | 2819 | dol_syslog(get_class($this)."::update_note", LOG_DEBUG); |
| 2608 | 2820 | if ($this->db->query($sql)) |
| 2609 | 2821 | {
|
| 2610 | - if ($suffix == '_public') $this->note_public = $note; |
|
| 2611 | - else if ($suffix == '_private') $this->note_private = $note; |
|
| 2612 | - else |
|
| 2822 | + if ($suffix == '_public') { |
|
| 2823 | + $this->note_public = $note; |
|
| 2824 | + } else if ($suffix == '_private') { |
|
| 2825 | + $this->note_private = $note; |
|
| 2826 | + } else |
|
| 2613 | 2827 | {
|
| 2614 | 2828 | $this->note = $note; // deprecated |
| 2615 | 2829 | $this->note_private = $note; |
| 2616 | 2830 | } |
| 2617 | 2831 | return 1; |
| 2618 | - } |
|
| 2619 | - else |
|
| 2832 | + } else |
|
| 2620 | 2833 | {
|
| 2621 | 2834 | $this->error=$this->db->lasterror(); |
| 2622 | 2835 | return -1; |
@@ -2656,37 +2869,45 @@ discard block |
||
| 2656 | 2869 | |
| 2657 | 2870 | // Some external module want no update price after a trigger because they have another method to calculate the total (ex: with an extrafield) |
| 2658 | 2871 | $MODULE = ""; |
| 2659 | - if ($this->element == 'propal') |
|
| 2660 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2661 | - elseif ($this->element == 'order') |
|
| 2662 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2663 | - elseif ($this->element == 'facture') |
|
| 2664 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2665 | - elseif ($this->element == 'facture_fourn') |
|
| 2666 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2667 | - elseif ($this->element == 'order_supplier') |
|
| 2668 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2669 | - elseif ($this->element == 'supplier_proposal') |
|
| 2670 | - $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2872 | + if ($this->element == 'propal') { |
|
| 2873 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_PROPOSAL"; |
|
| 2874 | + } elseif ($this->element == 'order') { |
|
| 2875 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; |
|
| 2876 | + } elseif ($this->element == 'facture') { |
|
| 2877 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; |
|
| 2878 | + } elseif ($this->element == 'facture_fourn') { |
|
| 2879 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; |
|
| 2880 | + } elseif ($this->element == 'order_supplier') { |
|
| 2881 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; |
|
| 2882 | + } elseif ($this->element == 'supplier_proposal') { |
|
| 2883 | + $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_PROPOSAL"; |
|
| 2884 | + } |
|
| 2671 | 2885 | |
| 2672 | 2886 | if (! empty($MODULE)) {
|
| 2673 | 2887 | if (!empty(Globals::$conf->global->$MODULE)) {
|
| 2674 | 2888 | $modsactivated = explode(',', Globals::$conf->global->$MODULE);
|
| 2675 | 2889 | foreach ($modsactivated as $mod) {
|
| 2676 | - if (Globals::$conf->$mod->enabled) |
|
| 2677 | - return 1; // update was disabled by specific setup |
|
| 2890 | + if (Globals::$conf->$mod->enabled) { |
|
| 2891 | + return 1; |
|
| 2892 | + } |
|
| 2893 | + // update was disabled by specific setup |
|
| 2678 | 2894 | } |
| 2679 | 2895 | } |
| 2680 | 2896 | } |
| 2681 | 2897 | |
| 2682 | 2898 | include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; |
| 2683 | 2899 | |
| 2684 | - if ($roundingadjust == '-1') $roundingadjust='auto'; // For backward compatibility |
|
| 2900 | + if ($roundingadjust == '-1') { |
|
| 2901 | + $roundingadjust='auto'; |
|
| 2902 | + } |
|
| 2903 | + // For backward compatibility |
|
| 2685 | 2904 | |
| 2686 | 2905 | $forcedroundingmode=$roundingadjust; |
| 2687 | - if ($forcedroundingmode == 'auto' && isset(Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) |
|
| 2688 | - $forcedroundingmode = Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2689 | - elseif ($forcedroundingmode == 'auto') $forcedroundingmode='0'; |
|
| 2906 | + if ($forcedroundingmode == 'auto' && isset(Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND)) { |
|
| 2907 | + $forcedroundingmode = Globals::$conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND; |
|
| 2908 | + } elseif ($forcedroundingmode == 'auto') { |
|
| 2909 | + $forcedroundingmode='0'; |
|
| 2910 | + } |
|
| 2690 | 2911 | |
| 2691 | 2912 | $error=0; |
| 2692 | 2913 | |
@@ -2709,15 +2930,22 @@ discard block |
||
| 2709 | 2930 | |
| 2710 | 2931 | $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,'; |
| 2711 | 2932 | $sql.= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, info_bits, product_type'; |
| 2712 | - if ($this->table_element_line == 'facturedet') $sql.= ', situation_percent'; |
|
| 2933 | + if ($this->table_element_line == 'facturedet') { |
|
| 2934 | + $sql.= ', situation_percent'; |
|
| 2935 | + } |
|
| 2713 | 2936 | $sql.= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; |
| 2714 | 2937 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line; |
| 2715 | 2938 | $sql.= ' WHERE '.$this->fk_element.' = '.$this->id; |
| 2716 | 2939 | if ($exclspec) |
| 2717 | 2940 | {
|
| 2718 | 2941 | $product_field='product_type'; |
| 2719 | - if ($this->table_element_line == 'contratdet') $product_field=''; // contratdet table has no product_type field |
|
| 2720 | - if ($product_field) $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2942 | + if ($this->table_element_line == 'contratdet') { |
|
| 2943 | + $product_field=''; |
|
| 2944 | + } |
|
| 2945 | + // contratdet table has no product_type field |
|
| 2946 | + if ($product_field) { |
|
| 2947 | + $sql.= ' AND '.$product_field.' <> 9'; |
|
| 2948 | + } |
|
| 2721 | 2949 | } |
| 2722 | 2950 | $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 |
| 2723 | 2951 | |
@@ -2747,9 +2975,11 @@ discard block |
||
| 2747 | 2975 | $parameters=array('fk_element' => $obj->rowid);
|
| 2748 | 2976 | $reshook = $hookmanager->executeHooks('changeRoundingMode', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
| 2749 | 2977 | |
| 2750 | - 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' |
|
| 2978 | + if (empty($reshook) && $forcedroundingmode == '0') { |
|
| 2979 | + // Check if data on line are consistent. This may solve lines that were not consistent because set with $forcedroundingmode='auto' |
|
| 2751 | 2980 | {
|
| 2752 | - $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2981 | + $localtax_array=array($obj->localtax1_type,$obj->localtax1_tx,$obj->localtax2_type,$obj->localtax2_tx); |
|
| 2982 | + } |
|
| 2753 | 2983 | $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); |
| 2754 | 2984 | $diff=price2num($tmpcal[1] - $obj->total_tva, 'MT', 1); |
| 2755 | 2985 | if ($diff) |
@@ -2757,7 +2987,9 @@ discard block |
||
| 2757 | 2987 | $sqlfix="UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".$tmpcal[1].", total_ttc = ".$tmpcal[2]." WHERE rowid = ".$obj->rowid; |
| 2758 | 2988 | 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);
|
| 2759 | 2989 | $resqlfix=$this->db->query($sqlfix); |
| 2760 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 2990 | + if (! $resqlfix) { |
|
| 2991 | + dol_print_error($this->db,'Failed to update line'); |
|
| 2992 | + } |
|
| 2761 | 2993 | $obj->total_tva = $tmpcal[1]; |
| 2762 | 2994 | $obj->total_ttc = $tmpcal[2]; |
| 2763 | 2995 | // |
@@ -2773,16 +3005,24 @@ discard block |
||
| 2773 | 3005 | $this->multicurrency_total_tva += $obj->multicurrency_total_tva; |
| 2774 | 3006 | $this->multicurrency_total_ttc += $obj->multicurrency_total_ttc; |
| 2775 | 3007 | |
| 2776 | - if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; |
|
| 2777 | - if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; |
|
| 2778 | - if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 3008 | + if (! isset($total_ht_by_vats[$obj->vatrate])) { |
|
| 3009 | + $total_ht_by_vats[$obj->vatrate]=0; |
|
| 3010 | + } |
|
| 3011 | + if (! isset($total_tva_by_vats[$obj->vatrate])) { |
|
| 3012 | + $total_tva_by_vats[$obj->vatrate]=0; |
|
| 3013 | + } |
|
| 3014 | + if (! isset($total_ttc_by_vats[$obj->vatrate])) { |
|
| 3015 | + $total_ttc_by_vats[$obj->vatrate]=0; |
|
| 3016 | + } |
|
| 2779 | 3017 | $total_ht_by_vats[$obj->vatrate] += $obj->total_ht; |
| 2780 | 3018 | $total_tva_by_vats[$obj->vatrate] += $obj->total_tva; |
| 2781 | 3019 | $total_ttc_by_vats[$obj->vatrate] += $obj->total_ttc; |
| 2782 | 3020 | |
| 2783 | - if ($forcedroundingmode == '1') // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 3021 | + if ($forcedroundingmode == '1') { |
|
| 3022 | + // Check if we need adjustement onto line for vat. TODO This works on the company currency but not on multicurrency |
|
| 2784 | 3023 | {
|
| 2785 | - $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 3024 | + $tmpvat=price2num($total_ht_by_vats[$obj->vatrate] * $obj->vatrate / 100, 'MT', 1); |
|
| 3025 | + } |
|
| 2786 | 3026 | $diff=price2num($total_tva_by_vats[$obj->vatrate]-$tmpvat, 'MT', 1); |
| 2787 | 3027 | //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"; |
| 2788 | 3028 | if ($diff) |
@@ -2791,7 +3031,9 @@ discard block |
||
| 2791 | 3031 | $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; |
| 2792 | 3032 | 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);
|
| 2793 | 3033 | $resqlfix=$this->db->query($sqlfix); |
| 2794 | - if (! $resqlfix) dol_print_error($this->db,'Failed to update line'); |
|
| 3034 | + if (! $resqlfix) { |
|
| 3035 | + dol_print_error($this->db,'Failed to update line'); |
|
| 3036 | + } |
|
| 2795 | 3037 | $this->total_tva -= $diff; |
| 2796 | 3038 | $this->total_ttc -= $diff; |
| 2797 | 3039 | $total_tva_by_vats[$obj->vatrate] -= $diff; |
@@ -2832,11 +3074,21 @@ discard block |
||
| 2832 | 3074 | $fieldlocaltax2='localtax2'; |
| 2833 | 3075 | $fieldttc='total_ttc'; |
| 2834 | 3076 | // Specific code for backward compatibility with old field names |
| 2835 | - if ($this->element == 'facture' || $this->element == 'facturerec') $fieldht='total'; |
|
| 2836 | - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') $fieldtva='total_tva'; |
|
| 2837 | - if ($this->element == 'propal') $fieldttc='total'; |
|
| 2838 | - if ($this->element == 'expensereport') $fieldtva='total_tva'; |
|
| 2839 | - if ($this->element == 'supplier_proposal') $fieldttc='total'; |
|
| 3077 | + if ($this->element == 'facture' || $this->element == 'facturerec') { |
|
| 3078 | + $fieldht='total'; |
|
| 3079 | + } |
|
| 3080 | + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { |
|
| 3081 | + $fieldtva='total_tva'; |
|
| 3082 | + } |
|
| 3083 | + if ($this->element == 'propal') { |
|
| 3084 | + $fieldttc='total'; |
|
| 3085 | + } |
|
| 3086 | + if ($this->element == 'expensereport') { |
|
| 3087 | + $fieldtva='total_tva'; |
|
| 3088 | + } |
|
| 3089 | + if ($this->element == 'supplier_proposal') { |
|
| 3090 | + $fieldttc='total'; |
|
| 3091 | + } |
|
| 2840 | 3092 | |
| 2841 | 3093 | if (empty($nodatabaseupdate)) |
| 2842 | 3094 | {
|
@@ -2865,13 +3117,11 @@ discard block |
||
| 2865 | 3117 | if (! $error) |
| 2866 | 3118 | {
|
| 2867 | 3119 | return 1; |
| 2868 | - } |
|
| 2869 | - else |
|
| 3120 | + } else |
|
| 2870 | 3121 | {
|
| 2871 | 3122 | return -1; |
| 2872 | 3123 | } |
| 2873 | - } |
|
| 2874 | - else |
|
| 3124 | + } else |
|
| 2875 | 3125 | {
|
| 2876 | 3126 | dol_print_error($this->db,'Bad request in update_price'); |
| 2877 | 3127 | return -1; |
@@ -2894,10 +3144,18 @@ discard block |
||
| 2894 | 3144 | $origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id); |
| 2895 | 3145 | |
| 2896 | 3146 | // Special case |
| 2897 | - if ($origin == 'order') $origin='commande'; |
|
| 2898 | - if ($origin == 'invoice') $origin='facture'; |
|
| 2899 | - if ($origin == 'invoice_template') $origin='facturerec'; |
|
| 2900 | - if ($origin == 'supplierorder') $origin='order_supplier'; |
|
| 3147 | + if ($origin == 'order') { |
|
| 3148 | + $origin='commande'; |
|
| 3149 | + } |
|
| 3150 | + if ($origin == 'invoice') { |
|
| 3151 | + $origin='facture'; |
|
| 3152 | + } |
|
| 3153 | + if ($origin == 'invoice_template') { |
|
| 3154 | + $origin='facturerec'; |
|
| 3155 | + } |
|
| 3156 | + if ($origin == 'supplierorder') { |
|
| 3157 | + $origin='order_supplier'; |
|
| 3158 | + } |
|
| 2901 | 3159 | $this->db->begin(); |
| 2902 | 3160 | |
| 2903 | 3161 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
@@ -2917,8 +3175,7 @@ discard block |
||
| 2917 | 3175 | {
|
| 2918 | 3176 | $this->db->commit(); |
| 2919 | 3177 | return 1; |
| 2920 | - } |
|
| 2921 | - else |
|
| 3178 | + } else |
|
| 2922 | 3179 | {
|
| 2923 | 3180 | $this->error=$this->db->lasterror(); |
| 2924 | 3181 | $this->db->rollback(); |
@@ -2963,12 +3220,16 @@ discard block |
||
| 2963 | 3220 | if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid)) |
| 2964 | 3221 | {
|
| 2965 | 3222 | $justsource=true; // the source (id and type) is a search criteria |
| 2966 | - if (! empty($targettype)) $withtargettype=true; |
|
| 3223 | + if (! empty($targettype)) { |
|
| 3224 | + $withtargettype=true; |
|
| 3225 | + } |
|
| 2967 | 3226 | } |
| 2968 | 3227 | if (! empty($targetid) && ! empty($targettype) && empty($sourceid)) |
| 2969 | 3228 | {
|
| 2970 | 3229 | $justtarget=true; // the target (id and type) is a search criteria |
| 2971 | - if (! empty($sourcetype)) $withsourcetype=true; |
|
| 3230 | + if (! empty($sourcetype)) { |
|
| 3231 | + $withsourcetype=true; |
|
| 3232 | + } |
|
| 2972 | 3233 | } |
| 2973 | 3234 | |
| 2974 | 3235 | $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
@@ -2991,15 +3252,17 @@ discard block |
||
| 2991 | 3252 | if ($justsource) |
| 2992 | 3253 | {
|
| 2993 | 3254 | $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; |
| 2994 | - if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; |
|
| 2995 | - } |
|
| 2996 | - else if ($justtarget) |
|
| 3255 | + if ($withtargettype) { |
|
| 3256 | + $sql.= " AND targettype = '".$targettype."'"; |
|
| 3257 | + } |
|
| 3258 | + } else if ($justtarget) |
|
| 2997 | 3259 | {
|
| 2998 | 3260 | $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; |
| 2999 | - if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3261 | + if ($withsourcetype) { |
|
| 3262 | + $sql.= " AND sourcetype = '".$sourcetype."'"; |
|
| 3263 | + } |
|
| 3000 | 3264 | } |
| 3001 | - } |
|
| 3002 | - else |
|
| 3265 | + } else |
|
| 3003 | 3266 | {
|
| 3004 | 3267 | $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; |
| 3005 | 3268 | $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; |
@@ -3020,13 +3283,11 @@ discard block |
||
| 3020 | 3283 | if ($justsource) |
| 3021 | 3284 | {
|
| 3022 | 3285 | $this->linkedObjectsIds[$obj->targettype][$obj->rowid]=$obj->fk_target; |
| 3023 | - } |
|
| 3024 | - else if ($justtarget) |
|
| 3286 | + } else if ($justtarget) |
|
| 3025 | 3287 | {
|
| 3026 | 3288 | $this->linkedObjectsIds[$obj->sourcetype][$obj->rowid]=$obj->fk_source; |
| 3027 | 3289 | } |
| 3028 | - } |
|
| 3029 | - else |
|
| 3290 | + } else |
|
| 3030 | 3291 | {
|
| 3031 | 3292 | if ($obj->fk_source == $sourceid && $obj->sourcetype == $sourcetype) |
| 3032 | 3293 | {
|
@@ -3043,10 +3304,12 @@ discard block |
||
| 3043 | 3304 | if (! empty($this->linkedObjectsIds)) |
| 3044 | 3305 | {
|
| 3045 | 3306 | $tmparray = $this->linkedObjectsIds; |
| 3046 | - foreach($tmparray as $objecttype => $objectids) // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3307 | + foreach($tmparray as $objecttype => $objectids) { |
|
| 3308 | + // $objecttype is a module name ('facture', 'mymodule', ...) or a module name with a suffix ('project_task', 'mymodule_myobj', ...)
|
|
| 3047 | 3309 | {
|
| 3048 | 3310 | // Parse element/subelement (ex: project_task, cabinetmed_consultation, ...) |
| 3049 | - $module = $element = $subelement = $objecttype; |
|
| 3311 | + $module = $element = $subelement = $objecttype; |
|
| 3312 | + } |
|
| 3050 | 3313 | if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' |
| 3051 | 3314 | && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
|
| 3052 | 3315 | {
|
@@ -3058,29 +3321,21 @@ discard block |
||
| 3058 | 3321 | // To work with non standard classpath or module name |
| 3059 | 3322 | if ($objecttype == 'facture') {
|
| 3060 | 3323 | $classpath = 'compta/facture/class'; |
| 3061 | - } |
|
| 3062 | - else if ($objecttype == 'facturerec') {
|
|
| 3324 | + } else if ($objecttype == 'facturerec') {
|
|
| 3063 | 3325 | $classpath = 'compta/facture/class'; $module = 'facture'; |
| 3064 | - } |
|
| 3065 | - else if ($objecttype == 'propal') {
|
|
| 3326 | + } else if ($objecttype == 'propal') {
|
|
| 3066 | 3327 | $classpath = 'comm/propal/class'; |
| 3067 | - } |
|
| 3068 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3328 | + } else if ($objecttype == 'supplier_proposal') {
|
|
| 3069 | 3329 | $classpath = 'supplier_proposal/class'; |
| 3070 | - } |
|
| 3071 | - else if ($objecttype == 'shipping') {
|
|
| 3330 | + } else if ($objecttype == 'shipping') {
|
|
| 3072 | 3331 | $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; |
| 3073 | - } |
|
| 3074 | - else if ($objecttype == 'delivery') {
|
|
| 3332 | + } else if ($objecttype == 'delivery') {
|
|
| 3075 | 3333 | $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; |
| 3076 | - } |
|
| 3077 | - else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3334 | + } else if ($objecttype == 'invoice_supplier' || $objecttype == 'order_supplier') {
|
|
| 3078 | 3335 | $classpath = 'fourn/class'; $module = 'fournisseur'; |
| 3079 | - } |
|
| 3080 | - else if ($objecttype == 'fichinter') {
|
|
| 3336 | + } else if ($objecttype == 'fichinter') {
|
|
| 3081 | 3337 | $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; |
| 3082 | - } |
|
| 3083 | - else if ($objecttype == 'subscription') {
|
|
| 3338 | + } else if ($objecttype == 'subscription') {
|
|
| 3084 | 3339 | $classpath = 'adherents/class'; $module = 'adherent'; |
| 3085 | 3340 | } |
| 3086 | 3341 | |
@@ -3089,20 +3344,15 @@ discard block |
||
| 3089 | 3344 | |
| 3090 | 3345 | if ($objecttype == 'order') {
|
| 3091 | 3346 | $classfile = 'commande'; $classname = 'Commande'; |
| 3092 | - } |
|
| 3093 | - else if ($objecttype == 'invoice_supplier') {
|
|
| 3347 | + } else if ($objecttype == 'invoice_supplier') {
|
|
| 3094 | 3348 | $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; |
| 3095 | - } |
|
| 3096 | - else if ($objecttype == 'order_supplier') {
|
|
| 3349 | + } else if ($objecttype == 'order_supplier') {
|
|
| 3097 | 3350 | $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; |
| 3098 | - } |
|
| 3099 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 3351 | + } else if ($objecttype == 'supplier_proposal') {
|
|
| 3100 | 3352 | $classfile = 'supplier_proposal'; $classname = 'SupplierProposal'; |
| 3101 | - } |
|
| 3102 | - else if ($objecttype == 'facturerec') {
|
|
| 3353 | + } else if ($objecttype == 'facturerec') {
|
|
| 3103 | 3354 | $classfile = 'facture-rec'; $classname = 'FactureRec'; |
| 3104 | - } |
|
| 3105 | - else if ($objecttype == 'subscription') {
|
|
| 3355 | + } else if ($objecttype == 'subscription') {
|
|
| 3106 | 3356 | $classfile = 'subscription'; $classname = 'Subscription'; |
| 3107 | 3357 | } |
| 3108 | 3358 | |
@@ -3114,9 +3364,11 @@ discard block |
||
| 3114 | 3364 | //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); |
| 3115 | 3365 | if (class_exists($classname)) |
| 3116 | 3366 | {
|
| 3117 | - foreach($objectids as $i => $objectid) // $i is rowid into llx_element_element |
|
| 3367 | + foreach($objectids as $i => $objectid) { |
|
| 3368 | + // $i is rowid into llx_element_element |
|
| 3118 | 3369 | {
|
| 3119 | - $object = new $classname($this->db); |
|
| 3370 | + $object = new $classname($this->db); |
|
| 3371 | + } |
|
| 3120 | 3372 | $ret = $object->fetch($objectid); |
| 3121 | 3373 | if ($ret >= 0) |
| 3122 | 3374 | {
|
@@ -3125,16 +3377,14 @@ discard block |
||
| 3125 | 3377 | } |
| 3126 | 3378 | } |
| 3127 | 3379 | } |
| 3128 | - } |
|
| 3129 | - else |
|
| 3380 | + } else |
|
| 3130 | 3381 | {
|
| 3131 | 3382 | unset($this->linkedObjectsIds[$objecttype]); |
| 3132 | 3383 | } |
| 3133 | 3384 | } |
| 3134 | 3385 | } |
| 3135 | 3386 | return 1; |
| 3136 | - } |
|
| 3137 | - else |
|
| 3387 | + } else |
|
| 3138 | 3388 | {
|
| 3139 | 3389 | dol_print_error($this->db); |
| 3140 | 3390 | return -1; |
@@ -3156,8 +3406,11 @@ discard block |
||
| 3156 | 3406 | $updatesource=false; |
| 3157 | 3407 | $updatetarget=false; |
| 3158 | 3408 | |
| 3159 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $updatesource=true; |
|
| 3160 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $updatetarget=true; |
|
| 3409 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) { |
|
| 3410 | + $updatesource=true; |
|
| 3411 | + } else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) { |
|
| 3412 | + $updatetarget=true; |
|
| 3413 | + } |
|
| 3161 | 3414 | |
| 3162 | 3415 | $sql = "UPDATE ".MAIN_DB_PREFIX."element_element SET "; |
| 3163 | 3416 | if ($updatesource) |
@@ -3166,8 +3419,7 @@ discard block |
||
| 3166 | 3419 | $sql.= ", sourcetype = '".$this->db->escape($sourcetype)."'"; |
| 3167 | 3420 | $sql.= " WHERE fk_target = ".$this->id; |
| 3168 | 3421 | $sql.= " AND targettype = '".$this->db->escape($this->element)."'"; |
| 3169 | - } |
|
| 3170 | - else if ($updatetarget) |
|
| 3422 | + } else if ($updatetarget) |
|
| 3171 | 3423 | {
|
| 3172 | 3424 | $sql.= "fk_target = ".$targetid; |
| 3173 | 3425 | $sql.= ", targettype = '".$this->db->escape($targettype)."'"; |
@@ -3179,8 +3431,7 @@ discard block |
||
| 3179 | 3431 | if ($this->db->query($sql)) |
| 3180 | 3432 | {
|
| 3181 | 3433 | return 1; |
| 3182 | - } |
|
| 3183 | - else |
|
| 3434 | + } else |
|
| 3184 | 3435 | {
|
| 3185 | 3436 | $this->error=$this->db->lasterror(); |
| 3186 | 3437 | return -1; |
@@ -3203,8 +3454,11 @@ discard block |
||
| 3203 | 3454 | $deletesource=false; |
| 3204 | 3455 | $deletetarget=false; |
| 3205 | 3456 | |
| 3206 | - if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) $deletesource=true; |
|
| 3207 | - else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) $deletetarget=true; |
|
| 3457 | + if (! empty($sourceid) && ! empty($sourcetype) && empty($targetid) && empty($targettype)) { |
|
| 3458 | + $deletesource=true; |
|
| 3459 | + } else if (empty($sourceid) && empty($sourcetype) && ! empty($targetid) && ! empty($targettype)) { |
|
| 3460 | + $deletetarget=true; |
|
| 3461 | + } |
|
| 3208 | 3462 | |
| 3209 | 3463 | $sourceid = (! empty($sourceid) ? $sourceid : $this->id); |
| 3210 | 3464 | $sourcetype = (! empty($sourcetype) ? $sourcetype : $this->element); |
@@ -3216,20 +3470,17 @@ discard block |
||
| 3216 | 3470 | if ($rowid > 0) |
| 3217 | 3471 | {
|
| 3218 | 3472 | $sql.=" rowid = ".$rowid; |
| 3219 | - } |
|
| 3220 | - else |
|
| 3473 | + } else |
|
| 3221 | 3474 | {
|
| 3222 | 3475 | if ($deletesource) |
| 3223 | 3476 | {
|
| 3224 | 3477 | $sql.= " fk_source = ".$sourceid." AND sourcetype = '".$this->db->escape($sourcetype)."'"; |
| 3225 | 3478 | $sql.= " AND fk_target = ".$this->id." AND targettype = '".$this->db->escape($this->element)."'"; |
| 3226 | - } |
|
| 3227 | - else if ($deletetarget) |
|
| 3479 | + } else if ($deletetarget) |
|
| 3228 | 3480 | {
|
| 3229 | 3481 | $sql.= " fk_target = ".$targetid." AND targettype = '".$this->db->escape($targettype)."'"; |
| 3230 | 3482 | $sql.= " AND fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."'"; |
| 3231 | - } |
|
| 3232 | - else |
|
| 3483 | + } else |
|
| 3233 | 3484 | {
|
| 3234 | 3485 | $sql.= " (fk_source = ".$this->id." AND sourcetype = '".$this->db->escape($this->element)."')"; |
| 3235 | 3486 | $sql.= " OR"; |
@@ -3241,8 +3492,7 @@ discard block |
||
| 3241 | 3492 | if ($this->db->query($sql)) |
| 3242 | 3493 | {
|
| 3243 | 3494 | return 1; |
| 3244 | - } |
|
| 3245 | - else |
|
| 3495 | + } else |
|
| 3246 | 3496 | {
|
| 3247 | 3497 | $this->error=$this->db->lasterror(); |
| 3248 | 3498 | $this->errors[]=$this->error; |
@@ -3271,17 +3521,31 @@ discard block |
||
| 3271 | 3521 | $this->db->begin(); |
| 3272 | 3522 | |
| 3273 | 3523 | $fieldstatus="fk_statut"; |
| 3274 | - if ($elementTable == 'facture_rec') $fieldstatus="suspended"; |
|
| 3275 | - if ($elementTable == 'mailing') $fieldstatus="statut"; |
|
| 3276 | - if ($elementTable == 'cronjob') $fieldstatus="status"; |
|
| 3277 | - if ($elementTable == 'user') $fieldstatus="statut"; |
|
| 3278 | - if ($elementTable == 'expensereport') $fieldstatus="fk_statut"; |
|
| 3279 | - if ($elementTable == 'commande_fournisseur_dispatch') $fieldstatus="status"; |
|
| 3524 | + if ($elementTable == 'facture_rec') { |
|
| 3525 | + $fieldstatus="suspended"; |
|
| 3526 | + } |
|
| 3527 | + if ($elementTable == 'mailing') { |
|
| 3528 | + $fieldstatus="statut"; |
|
| 3529 | + } |
|
| 3530 | + if ($elementTable == 'cronjob') { |
|
| 3531 | + $fieldstatus="status"; |
|
| 3532 | + } |
|
| 3533 | + if ($elementTable == 'user') { |
|
| 3534 | + $fieldstatus="statut"; |
|
| 3535 | + } |
|
| 3536 | + if ($elementTable == 'expensereport') { |
|
| 3537 | + $fieldstatus="fk_statut"; |
|
| 3538 | + } |
|
| 3539 | + if ($elementTable == 'commande_fournisseur_dispatch') { |
|
| 3540 | + $fieldstatus="status"; |
|
| 3541 | + } |
|
| 3280 | 3542 | |
| 3281 | 3543 | $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; |
| 3282 | 3544 | $sql.= " SET ".$fieldstatus." = ".$status; |
| 3283 | 3545 | // If status = 1 = validated, update also fk_user_valid |
| 3284 | - if ($status == 1 && $elementTable == 'expensereport') $sql.=", fk_user_valid = ".$user->id; |
|
| 3546 | + if ($status == 1 && $elementTable == 'expensereport') { |
|
| 3547 | + $sql.=", fk_user_valid = ".$user->id; |
|
| 3548 | + } |
|
| 3285 | 3549 | $sql.= " WHERE rowid=".$elementId; |
| 3286 | 3550 | |
| 3287 | 3551 | dol_syslog(get_class($this)."::setStatut", LOG_DEBUG); |
@@ -3292,12 +3556,27 @@ discard block |
||
| 3292 | 3556 | // Try autoset of trigkey |
| 3293 | 3557 | if (empty($trigkey)) |
| 3294 | 3558 | {
|
| 3295 | - if ($this->element == 'supplier_proposal' && $status == 2) $trigkey='SUPPLIER_PROPOSAL_SIGN'; // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3296 | - if ($this->element == 'supplier_proposal' && $status == 3) $trigkey='SUPPLIER_PROPOSAL_REFUSE'; // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3297 | - if ($this->element == 'supplier_proposal' && $status == 4) $trigkey='SUPPLIER_PROPOSAL_CLOSE'; // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3298 | - if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3299 | - if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3300 | - if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3559 | + if ($this->element == 'supplier_proposal' && $status == 2) { |
|
| 3560 | + $trigkey='SUPPLIER_PROPOSAL_SIGN'; |
|
| 3561 | + } |
|
| 3562 | + // 2 = SupplierProposal::STATUS_SIGNED. Can't use constant into this generic class |
|
| 3563 | + if ($this->element == 'supplier_proposal' && $status == 3) { |
|
| 3564 | + $trigkey='SUPPLIER_PROPOSAL_REFUSE'; |
|
| 3565 | + } |
|
| 3566 | + // 3 = SupplierProposal::STATUS_REFUSED. Can't use constant into this generic class |
|
| 3567 | + if ($this->element == 'supplier_proposal' && $status == 4) { |
|
| 3568 | + $trigkey='SUPPLIER_PROPOSAL_CLOSE'; |
|
| 3569 | + } |
|
| 3570 | + // 4 = SupplierProposal::STATUS_CLOSED. Can't use constant into this generic class |
|
| 3571 | + if ($this->element == 'fichinter' && $status == 3) { |
|
| 3572 | + $trigkey='FICHINTER_CLASSIFY_DONE'; |
|
| 3573 | + } |
|
| 3574 | + if ($this->element == 'fichinter' && $status == 2) { |
|
| 3575 | + $trigkey='FICHINTER_CLASSIFY_BILLED'; |
|
| 3576 | + } |
|
| 3577 | + if ($this->element == 'fichinter' && $status == 1) { |
|
| 3578 | + $trigkey='FICHINTER_CLASSIFY_UNBILLED'; |
|
| 3579 | + } |
|
| 3301 | 3580 | } |
| 3302 | 3581 | |
| 3303 | 3582 | if ($trigkey) |
@@ -3316,22 +3595,22 @@ discard block |
||
| 3316 | 3595 | {
|
| 3317 | 3596 | $this->db->commit(); |
| 3318 | 3597 | |
| 3319 | - if (empty($savElementId)) // If the element we update was $this (so $elementId is null) |
|
| 3598 | + if (empty($savElementId)) { |
|
| 3599 | + // If the element we update was $this (so $elementId is null) |
|
| 3320 | 3600 | {
|
| 3321 | - $this->statut = $status; |
|
| 3601 | + $this->statut = $status; |
|
| 3602 | + } |
|
| 3322 | 3603 | $this->status = $status; |
| 3323 | 3604 | } |
| 3324 | 3605 | |
| 3325 | 3606 | return 1; |
| 3326 | - } |
|
| 3327 | - else |
|
| 3607 | + } else |
|
| 3328 | 3608 | {
|
| 3329 | 3609 | $this->db->rollback(); |
| 3330 | 3610 | dol_syslog(get_class($this)."::setStatus ".$this->error,LOG_ERR); |
| 3331 | 3611 | return -1; |
| 3332 | 3612 | } |
| 3333 | - } |
|
| 3334 | - else |
|
| 3613 | + } else |
|
| 3335 | 3614 | {
|
| 3336 | 3615 | $this->error=$this->db->lasterror(); |
| 3337 | 3616 | $this->db->rollback(); |
@@ -3351,9 +3630,13 @@ discard block |
||
| 3351 | 3630 | {
|
| 3352 | 3631 | global $conf; |
| 3353 | 3632 | |
| 3354 | - if (empty($id) && empty($ref)) return 0; |
|
| 3355 | - if (!empty(Globals::$conf->global->MAIN_DISABLE_CANVAS)) |
|
| 3356 | - return 0; // To increase speed. Not enabled by default. |
|
| 3633 | + if (empty($id) && empty($ref)) { |
|
| 3634 | + return 0; |
|
| 3635 | + } |
|
| 3636 | + if (!empty(Globals::$conf->global->MAIN_DISABLE_CANVAS)) { |
|
| 3637 | + return 0; |
|
| 3638 | + } |
|
| 3639 | + // To increase speed. Not enabled by default. |
|
| 3357 | 3640 | |
| 3358 | 3641 | // Clean parameters |
| 3359 | 3642 | $ref = trim($ref); |
@@ -3361,8 +3644,12 @@ discard block |
||
| 3361 | 3644 | $sql = "SELECT rowid, canvas"; |
| 3362 | 3645 | $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; |
| 3363 | 3646 | $sql.= " WHERE entity IN (".getEntity($this->element).")";
|
| 3364 | - if (! empty($id)) $sql.= " AND rowid = ".$id; |
|
| 3365 | - if (! empty($ref)) $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3647 | + if (! empty($id)) { |
|
| 3648 | + $sql.= " AND rowid = ".$id; |
|
| 3649 | + } |
|
| 3650 | + if (! empty($ref)) { |
|
| 3651 | + $sql.= " AND ref = '".$this->db->escape($ref)."'"; |
|
| 3652 | + } |
|
| 3366 | 3653 | |
| 3367 | 3654 | $resql = $this->db->query($sql); |
| 3368 | 3655 | if ($resql) |
@@ -3372,10 +3659,10 @@ discard block |
||
| 3372 | 3659 | {
|
| 3373 | 3660 | $this->canvas = $obj->canvas; |
| 3374 | 3661 | return 1; |
| 3375 | - } |
|
| 3376 | - else return 0; |
|
| 3377 | - } |
|
| 3378 | - else |
|
| 3662 | + } else { |
|
| 3663 | + return 0; |
|
| 3664 | + } |
|
| 3665 | + } else |
|
| 3379 | 3666 | {
|
| 3380 | 3667 | dol_print_error($this->db); |
| 3381 | 3668 | return -1; |
@@ -3412,7 +3699,9 @@ discard block |
||
| 3412 | 3699 | {
|
| 3413 | 3700 | global $langs; |
| 3414 | 3701 | |
| 3415 | - if (empty($id)) $id=$this->id; |
|
| 3702 | + if (empty($id)) { |
|
| 3703 | + $id=$this->id; |
|
| 3704 | + } |
|
| 3416 | 3705 | |
| 3417 | 3706 | // Check parameters |
| 3418 | 3707 | if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) |
@@ -3446,18 +3735,18 @@ discard block |
||
| 3446 | 3735 | $langs->load("errors");
|
| 3447 | 3736 | //print 'Found into table '.$table.', type '.$langs->transnoentitiesnoconv($elementname).', haschild='.$haschild; |
| 3448 | 3737 | $haschild += $obj->nb; |
| 3449 | - if (is_numeric($elementname)) // old usage |
|
| 3738 | + if (is_numeric($elementname)) { |
|
| 3739 | + // old usage |
|
| 3450 | 3740 | {
|
| 3451 | - $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table);
|
|
| 3452 | - } |
|
| 3453 | - else // new usage: $elementname=Translation key |
|
| 3741 | + $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $table); |
|
| 3742 | + } |
|
| 3743 | + } else // new usage: $elementname=Translation key |
|
| 3454 | 3744 | {
|
| 3455 | 3745 | $this->errors[]=$langs->trans("ErrorRecordHasAtLeastOneChildOfType", $langs->transnoentitiesnoconv($elementname));
|
| 3456 | 3746 | } |
| 3457 | 3747 | break; // We found at least one, we stop here |
| 3458 | 3748 | } |
| 3459 | - } |
|
| 3460 | - else |
|
| 3749 | + } else |
|
| 3461 | 3750 | {
|
| 3462 | 3751 | $this->errors[]=$this->db->lasterror(); |
| 3463 | 3752 | return -1; |
@@ -3467,8 +3756,9 @@ discard block |
||
| 3467 | 3756 | {
|
| 3468 | 3757 | $this->errors[]="ErrorRecordHasChildren"; |
| 3469 | 3758 | return $haschild; |
| 3470 | - } |
|
| 3471 | - else return 0; |
|
| 3759 | + } else { |
|
| 3760 | + return 0; |
|
| 3761 | + } |
|
| 3472 | 3762 | } |
| 3473 | 3763 | |
| 3474 | 3764 | /** |
@@ -3484,12 +3774,24 @@ discard block |
||
| 3484 | 3774 | foreach($this->lines as $key => $val) |
| 3485 | 3775 | {
|
| 3486 | 3776 | $qualified=0; |
| 3487 | - if ($predefined == -1) $qualified=1; |
|
| 3488 | - if ($predefined == 1 && $val->fk_product > 0) $qualified=1; |
|
| 3489 | - if ($predefined == 0 && $val->fk_product <= 0) $qualified=1; |
|
| 3490 | - if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) $qualified=1; |
|
| 3491 | - if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) $qualified=1; |
|
| 3492 | - if ($qualified) $nb++; |
|
| 3777 | + if ($predefined == -1) { |
|
| 3778 | + $qualified=1; |
|
| 3779 | + } |
|
| 3780 | + if ($predefined == 1 && $val->fk_product > 0) { |
|
| 3781 | + $qualified=1; |
|
| 3782 | + } |
|
| 3783 | + if ($predefined == 0 && $val->fk_product <= 0) { |
|
| 3784 | + $qualified=1; |
|
| 3785 | + } |
|
| 3786 | + if ($predefined == 2 && $val->fk_product > 0 && $val->product_type==0) { |
|
| 3787 | + $qualified=1; |
|
| 3788 | + } |
|
| 3789 | + if ($predefined == 3 && $val->fk_product > 0 && $val->product_type==1) { |
|
| 3790 | + $qualified=1; |
|
| 3791 | + } |
|
| 3792 | + if ($qualified) { |
|
| 3793 | + $nb++; |
|
| 3794 | + } |
|
| 3493 | 3795 | } |
| 3494 | 3796 | dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies'); |
| 3495 | 3797 | return $nb; |
@@ -3553,16 +3855,24 @@ discard block |
||
| 3553 | 3855 | {
|
| 3554 | 3856 | if (isset($line->qty_asked)) |
| 3555 | 3857 | {
|
| 3556 | - if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' |
|
| 3858 | + if (empty($totalOrdered)) { |
|
| 3859 | + $totalOrdered=0; |
|
| 3860 | + } |
|
| 3861 | + // Avoid warning because $totalOrdered is '' |
|
| 3557 | 3862 | $totalOrdered+=$line->qty_asked; // defined for shipment only |
| 3558 | 3863 | } |
| 3559 | 3864 | if (isset($line->qty_shipped)) |
| 3560 | 3865 | {
|
| 3561 | - if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' |
|
| 3866 | + if (empty($totalToShip)) { |
|
| 3867 | + $totalToShip=0; |
|
| 3868 | + } |
|
| 3869 | + // Avoid warning because $totalToShip is '' |
|
| 3562 | 3870 | $totalToShip+=$line->qty_shipped; // defined for shipment only |
| 3563 | - }else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3871 | + } else if ($line->element == 'commandefournisseurdispatch' && isset($line->qty)) |
|
| 3564 | 3872 | {
|
| 3565 | - if (empty($totalToShip)) $totalToShip=0; |
|
| 3873 | + if (empty($totalToShip)) { |
|
| 3874 | + $totalToShip=0; |
|
| 3875 | + } |
|
| 3566 | 3876 | $totalToShip+=$line->qty; // defined for reception only |
| 3567 | 3877 | } |
| 3568 | 3878 | |
@@ -3570,8 +3880,7 @@ discard block |
||
| 3570 | 3880 | if ($this->element == 'shipping') {
|
| 3571 | 3881 | // for shipments |
| 3572 | 3882 | $qty = $line->qty_shipped ? $line->qty_shipped : 0; |
| 3573 | - } |
|
| 3574 | - else {
|
|
| 3883 | + } else {
|
|
| 3575 | 3884 | $qty = $line->qty ? $line->qty : 0; |
| 3576 | 3885 | } |
| 3577 | 3886 | |
@@ -3587,19 +3896,30 @@ discard block |
||
| 3587 | 3896 | |
| 3588 | 3897 | $weightUnit=0; |
| 3589 | 3898 | $volumeUnit=0; |
| 3590 | - if (! empty($weight_units)) $weightUnit = $weight_units; |
|
| 3591 | - if (! empty($volume_units)) $volumeUnit = $volume_units; |
|
| 3592 | - |
|
| 3593 | - if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' |
|
| 3594 | - if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' |
|
| 3899 | + if (! empty($weight_units)) { |
|
| 3900 | + $weightUnit = $weight_units; |
|
| 3901 | + } |
|
| 3902 | + if (! empty($volume_units)) { |
|
| 3903 | + $volumeUnit = $volume_units; |
|
| 3904 | + } |
|
| 3905 | + |
|
| 3906 | + if (empty($totalWeight)) { |
|
| 3907 | + $totalWeight=0; |
|
| 3908 | + } |
|
| 3909 | + // Avoid warning because $totalWeight is '' |
|
| 3910 | + if (empty($totalVolume)) { |
|
| 3911 | + $totalVolume=0; |
|
| 3912 | + } |
|
| 3913 | + // Avoid warning because $totalVolume is '' |
|
| 3595 | 3914 | |
| 3596 | 3915 | //var_dump($line->volume_units); |
| 3597 | - if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3916 | + if ($weight_units < 50) { |
|
| 3917 | + // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3598 | 3918 | {
|
| 3599 | - $trueWeightUnit=pow(10, $weightUnit); |
|
| 3919 | + $trueWeightUnit=pow(10, $weightUnit); |
|
| 3920 | + } |
|
| 3600 | 3921 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3601 | - } |
|
| 3602 | - else {
|
|
| 3922 | + } else {
|
|
| 3603 | 3923 | if ($weight_units == 99) {
|
| 3604 | 3924 | // conversion 1 Pound = 0.45359237 KG |
| 3605 | 3925 | $trueWeightUnit = 0.45359237; |
@@ -3608,18 +3928,20 @@ discard block |
||
| 3608 | 3928 | // conversion 1 Ounce = 0.0283495 KG |
| 3609 | 3929 | $trueWeightUnit = 0.0283495; |
| 3610 | 3930 | $totalWeight += $weight * $qty * $trueWeightUnit; |
| 3611 | - } |
|
| 3612 | - else |
|
| 3613 | - $totalWeight += $weight * $qty; // This may be wrong if we mix different units |
|
| 3931 | + } else { |
|
| 3932 | + $totalWeight += $weight * $qty; |
|
| 3933 | + } |
|
| 3934 | + // This may be wrong if we mix different units |
|
| 3614 | 3935 | } |
| 3615 | - if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3936 | + if ($volume_units < 50) { |
|
| 3937 | + // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) |
|
| 3616 | 3938 | {
|
| 3617 | 3939 | //print $line->volume."x".$line->volume_units."x".($line->volume_units < 50)."x".$volumeUnit; |
| 3618 | - $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3940 | + $trueVolumeUnit=pow(10, $volumeUnit); |
|
| 3941 | + } |
|
| 3619 | 3942 | //print $line->volume; |
| 3620 | 3943 | $totalVolume += $volume * $qty * $trueVolumeUnit; |
| 3621 | - } |
|
| 3622 | - else |
|
| 3944 | + } else |
|
| 3623 | 3945 | {
|
| 3624 | 3946 | $totalVolume += $volume * $qty; // This may be wrong if we mix different units |
| 3625 | 3947 | } |
@@ -3651,8 +3973,7 @@ discard block |
||
| 3651 | 3973 | $this->error=$this->db->lasterror(); |
| 3652 | 3974 | $this->db->rollback(); |
| 3653 | 3975 | return -1; |
| 3654 | - } |
|
| 3655 | - else |
|
| 3976 | + } else |
|
| 3656 | 3977 | {
|
| 3657 | 3978 | $this->db->commit(); |
| 3658 | 3979 | return 1; |
@@ -3704,13 +4025,11 @@ discard block |
||
| 3704 | 4025 | {
|
| 3705 | 4026 | $res = $this->db->fetch_object($resql); |
| 3706 | 4027 | return 'Incoterm : '.$res->code.' - '.$this->location_incoterms; |
| 3707 | - } |
|
| 3708 | - else |
|
| 4028 | + } else |
|
| 3709 | 4029 | {
|
| 3710 | 4030 | return ''; |
| 3711 | 4031 | } |
| 3712 | - } |
|
| 3713 | - else |
|
| 4032 | + } else |
|
| 3714 | 4033 | {
|
| 3715 | 4034 | $this->errors[] = $this->db->lasterror(); |
| 3716 | 4035 | return false; |
@@ -3747,14 +4066,14 @@ discard block |
||
| 3747 | 4066 | $this->libelle_incoterms = $obj->libelle; |
| 3748 | 4067 | } |
| 3749 | 4068 | return 1; |
| 3750 | - } |
|
| 3751 | - else |
|
| 4069 | + } else |
|
| 3752 | 4070 | {
|
| 3753 | 4071 | $this->errors[] = $this->db->lasterror(); |
| 3754 | 4072 | return -1; |
| 3755 | 4073 | } |
| 3756 | - } |
|
| 3757 | - else return -1; |
|
| 4074 | + } else { |
|
| 4075 | + return -1; |
|
| 4076 | + } |
|
| 3758 | 4077 | } |
| 3759 | 4078 | |
| 3760 | 4079 | |
@@ -3793,7 +4112,9 @@ discard block |
||
| 3793 | 4112 | } else {
|
| 3794 | 4113 | $res=include $tpl; // for debug |
| 3795 | 4114 | } |
| 3796 | - if ($res) break; |
|
| 4115 | + if ($res) { |
|
| 4116 | + break; |
|
| 4117 | + } |
|
| 3797 | 4118 | } |
| 3798 | 4119 | } |
| 3799 | 4120 | |
@@ -3823,8 +4144,9 @@ discard block |
||
| 3823 | 4144 | |
| 3824 | 4145 | // Define usemargins |
| 3825 | 4146 | $usemargins=0; |
| 3826 | - if (!empty(Globals::$conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande')))
|
|
| 3827 | - $usemargins = 1; |
|
| 4147 | + if (!empty(Globals::$conf->margin->enabled) && !empty($this->element) && in_array($this->element, array('facture', 'propal', 'commande'))) { |
|
| 4148 | + $usemargins = 1; |
|
| 4149 | + } |
|
| 3828 | 4150 | |
| 3829 | 4151 | $num = count($this->lines); |
| 3830 | 4152 | |
@@ -3843,8 +4165,9 @@ discard block |
||
| 3843 | 4165 | print '<tr class="liste_titre nodrag nodrop">'; |
| 3844 | 4166 | |
| 3845 | 4167 | // Adds a line numbering column |
| 3846 | - if (!empty(Globals::$conf->global->MAIN_VIEW_LINE_NUMBER)) |
|
| 3847 | - print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 4168 | + if (!empty(Globals::$conf->global->MAIN_VIEW_LINE_NUMBER)) { |
|
| 4169 | + print '<td class="linecolnum" align="center" width="5"> </td>'; |
|
| 4170 | + } |
|
| 3848 | 4171 | |
| 3849 | 4172 | // Description |
| 3850 | 4173 | print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
|
@@ -3861,10 +4184,13 @@ discard block |
||
| 3861 | 4184 | print '<td class="linecoluht" align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
|
| 3862 | 4185 | |
| 3863 | 4186 | // Multicurrency |
| 3864 | - if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) |
|
| 3865 | - print '<td class="linecoluht_currency" align="right" width="80">' . $langs->trans('PriceUHTCurrency', $this->multicurrency_code) . '</td>';
|
|
| 4187 | + if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) { |
|
| 4188 | + print '<td class="linecoluht_currency" align="right" width="80">' . $langs->trans('PriceUHTCurrency', $this->multicurrency_code) . '</td>'; |
|
| 4189 | + } |
|
| 3866 | 4190 | |
| 3867 | - if ($inputalsopricewithtax) print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>';
|
|
| 4191 | + if ($inputalsopricewithtax) { |
|
| 4192 | + print '<td align="right" width="80">'.$langs->trans('PriceUTTC').'</td>'; |
|
| 4193 | + } |
|
| 3868 | 4194 | |
| 3869 | 4195 | // Qty |
| 3870 | 4196 | print '<td class="linecolqty" align="right">'.$langs->trans('Qty').'</td>';
|
@@ -3883,26 +4209,32 @@ discard block |
||
| 3883 | 4209 | if ($usemargins && !empty(Globals::$conf->margin->enabled) && empty($user->societe_id)) {
|
| 3884 | 4210 | if (!empty($user->rights->margins->creer)) |
| 3885 | 4211 | {
|
| 3886 | - if (Globals::$conf->global->MARGIN_TYPE == "1") |
|
| 3887 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>';
|
|
| 3888 | - else |
|
| 3889 | - print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>';
|
|
| 4212 | + if (Globals::$conf->global->MARGIN_TYPE == "1") { |
|
| 4213 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('BuyingPrice').'</td>'; |
|
| 4214 | + } else { |
|
| 4215 | + print '<td class="linecolmargin1 margininfos" align="right" width="80">'.$langs->trans('CostPrice').'</td>'; |
|
| 4216 | + } |
|
| 3890 | 4217 | } |
| 3891 | 4218 | |
| 3892 | - if (!empty(Globals::$conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) |
|
| 3893 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>';
|
|
| 3894 | - if (!empty(Globals::$conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) |
|
| 3895 | - print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>';
|
|
| 4219 | + if (!empty(Globals::$conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) { |
|
| 4220 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarginRate').'</td>'; |
|
| 4221 | + } |
|
| 4222 | + if (!empty(Globals::$conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) { |
|
| 4223 | + print '<td class="linecolmargin2 margininfos" align="right" width="50">'.$langs->trans('MarkRate').'</td>'; |
|
| 4224 | + } |
|
| 3896 | 4225 | } |
| 3897 | 4226 | |
| 3898 | 4227 | // Total HT |
| 3899 | 4228 | print '<td class="linecolht" align="right">'.$langs->trans('TotalHTShort').'</td>';
|
| 3900 | 4229 | |
| 3901 | 4230 | // Multicurrency |
| 3902 | - if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) |
|
| 3903 | - print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>';
|
|
| 4231 | + if (!empty(Globals::$conf->multicurrency->enabled) && $this->multicurrency_code != Globals::$conf->currency) { |
|
| 4232 | + print '<td class="linecoltotalht_currency" align="right">' . $langs->trans('TotalHTShortCurrency', $this->multicurrency_code) . '</td>'; |
|
| 4233 | + } |
|
| 3904 | 4234 | |
| 3905 | - if ($outputalsopricetotalwithtax) print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>';
|
|
| 4235 | + if ($outputalsopricetotalwithtax) { |
|
| 4236 | + print '<td align="right" width="80">'.$langs->trans('TotalTTCShort').'</td>'; |
|
| 4237 | + } |
|
| 3906 | 4238 | |
| 3907 | 4239 | print '<td class="linecoledit"></td>'; // No width to allow autodim |
| 3908 | 4240 | |
@@ -3932,14 +4264,15 @@ discard block |
||
| 3932 | 4264 | $line->fetch_optionals(); |
| 3933 | 4265 | |
| 3934 | 4266 | //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) |
| 3935 | - if (is_object($hookmanager)) // Old code is commented on preceding line. |
|
| 4267 | + if (is_object($hookmanager)) { |
|
| 4268 | + // Old code is commented on preceding line. |
|
| 3936 | 4269 | {
|
| 3937 | 4270 | if (empty($line->fk_parent_line)) |
| 3938 | 4271 | {
|
| 3939 | - $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline);
|
|
| 4272 | + $parameters = array('line'=>$line,'var'=>$var,'num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); |
|
| 4273 | + } |
|
| 3940 | 4274 | $reshook = $hookmanager->executeHooks('printObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
| 3941 | - } |
|
| 3942 | - else |
|
| 4275 | + } else |
|
| 3943 | 4276 | {
|
| 3944 | 4277 | $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);
|
| 3945 | 4278 | $reshook = $hookmanager->executeHooks('printObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
|
@@ -3986,8 +4319,14 @@ discard block |
||
| 3986 | 4319 | // Show product and description |
| 3987 | 4320 | $type=(! empty($line->product_type)?$line->product_type:$line->fk_product_type); |
| 3988 | 4321 | // Try to enhance type detection using date_start and date_end for free lines where type was not saved. |
| 3989 | - if (! empty($line->date_start)) $type=1; // deprecated |
|
| 3990 | - if (! empty($line->date_end)) $type=1; // deprecated |
|
| 4322 | + if (! empty($line->date_start)) { |
|
| 4323 | + $type=1; |
|
| 4324 | + } |
|
| 4325 | + // deprecated |
|
| 4326 | + if (! empty($line->date_end)) { |
|
| 4327 | + $type=1; |
|
| 4328 | + } |
|
| 4329 | + // deprecated |
|
| 3991 | 4330 | |
| 3992 | 4331 | // Ligne en mode visu |
| 3993 | 4332 | if ($action != 'editline' || $selected != $line->id) |
@@ -4015,9 +4354,13 @@ discard block |
||
| 4015 | 4354 | |
| 4016 | 4355 | $outputlangs = $langs; |
| 4017 | 4356 | $newlang=''; |
| 4018 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09');
|
|
| 4019 | - if (!empty(Globals::$conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) |
|
| 4020 | - $newlang = $this->thirdparty->default_lang; // For language to language of customer |
|
| 4357 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
| 4358 | + $newlang=GETPOST('lang_id','aZ09'); |
|
| 4359 | + } |
|
| 4360 | + if (!empty(Globals::$conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) { |
|
| 4361 | + $newlang = $this->thirdparty->default_lang; |
|
| 4362 | + } |
|
| 4363 | + // For language to language of customer |
|
| 4021 | 4364 | if (! empty($newlang)) |
| 4022 | 4365 | {
|
| 4023 | 4366 | $outputlangs = new Translate("",$conf);
|
@@ -4025,8 +4368,7 @@ discard block |
||
| 4025 | 4368 | } |
| 4026 | 4369 | |
| 4027 | 4370 | $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $line->product_label; |
| 4028 | - } |
|
| 4029 | - else |
|
| 4371 | + } else |
|
| 4030 | 4372 | {
|
| 4031 | 4373 | $label = $line->product_label; |
| 4032 | 4374 | } |
@@ -4048,7 +4390,9 @@ discard block |
||
| 4048 | 4390 | } else {
|
| 4049 | 4391 | $res=include $tpl; // for debug |
| 4050 | 4392 | } |
| 4051 | - if ($res) break; |
|
| 4393 | + if ($res) { |
|
| 4394 | + break; |
|
| 4395 | + } |
|
| 4052 | 4396 | } |
| 4053 | 4397 | } |
| 4054 | 4398 | |
@@ -4071,7 +4415,9 @@ discard block |
||
| 4071 | 4415 | } else {
|
| 4072 | 4416 | $res=include $tpl; // for debug |
| 4073 | 4417 | } |
| 4074 | - if ($res) break; |
|
| 4418 | + if ($res) { |
|
| 4419 | + break; |
|
| 4420 | + } |
|
| 4075 | 4421 | } |
| 4076 | 4422 | } |
| 4077 | 4423 | } |
@@ -4098,8 +4444,9 @@ discard block |
||
| 4098 | 4444 | print '<td>'.$langs->trans('Description').'</td>';
|
| 4099 | 4445 | print '<td align="right">'.$langs->trans('VATRate').'</td>';
|
| 4100 | 4446 | print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
|
| 4101 | - if (!empty(Globals::$conf->multicurrency->enabled)) |
|
| 4102 | - print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>';
|
|
| 4447 | + if (!empty(Globals::$conf->multicurrency->enabled)) { |
|
| 4448 | + print '<td align="right">' . $langs->trans('PriceUHTCurrency') . '</td>'; |
|
| 4449 | + } |
|
| 4103 | 4450 | print '<td align="right">'.$langs->trans('Qty').'</td>';
|
| 4104 | 4451 | if (Globals::$conf->global->PRODUCT_USE_UNITS) {
|
| 4105 | 4452 | print '<td align="left">'.$langs->trans('Unit').'</td>';
|
@@ -4121,8 +4468,7 @@ discard block |
||
| 4121 | 4468 | $action=''; |
| 4122 | 4469 | $hookmanager->executeHooks('printOriginObjectLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
|
| 4123 | 4470 | } |
| 4124 | - } |
|
| 4125 | - else |
|
| 4471 | + } else |
|
| 4126 | 4472 | {
|
| 4127 | 4473 | $this->printOriginLine($line, $var, $restrictlist); |
| 4128 | 4474 | } |
@@ -4151,32 +4497,37 @@ discard block |
||
| 4151 | 4497 | if (!empty($line->date_start)) |
| 4152 | 4498 | {
|
| 4153 | 4499 | $date_start=$line->date_start; |
| 4154 | - } |
|
| 4155 | - else |
|
| 4500 | + } else |
|
| 4156 | 4501 | {
|
| 4157 | 4502 | $date_start=$line->date_debut_prevue; |
| 4158 | - if ($line->date_debut_reel) $date_start=$line->date_debut_reel; |
|
| 4503 | + if ($line->date_debut_reel) { |
|
| 4504 | + $date_start=$line->date_debut_reel; |
|
| 4505 | + } |
|
| 4159 | 4506 | } |
| 4160 | 4507 | if (!empty($line->date_end)) |
| 4161 | 4508 | {
|
| 4162 | 4509 | $date_end=$line->date_end; |
| 4163 | - } |
|
| 4164 | - else |
|
| 4510 | + } else |
|
| 4165 | 4511 | {
|
| 4166 | 4512 | $date_end=$line->date_fin_prevue; |
| 4167 | - if ($line->date_fin_reel) $date_end=$line->date_fin_reel; |
|
| 4513 | + if ($line->date_fin_reel) { |
|
| 4514 | + $date_end=$line->date_fin_reel; |
|
| 4515 | + } |
|
| 4168 | 4516 | } |
| 4169 | 4517 | |
| 4170 | 4518 | $this->tpl['label'] = ''; |
| 4171 | - if (! empty($line->fk_parent_line)) $this->tpl['label'].= img_picto('', 'rightarrow');
|
|
| 4519 | + if (! empty($line->fk_parent_line)) { |
|
| 4520 | + $this->tpl['label'].= img_picto('', 'rightarrow'); |
|
| 4521 | + } |
|
| 4172 | 4522 | |
| 4173 | - if (($line->info_bits & 2) == 2) // TODO Not sure this is used for source object |
|
| 4523 | + if (($line->info_bits & 2) == 2) { |
|
| 4524 | + // TODO Not sure this is used for source object |
|
| 4174 | 4525 | {
|
| 4175 | - $discount=new DiscountAbsolute($this->db); |
|
| 4526 | + $discount=new DiscountAbsolute($this->db); |
|
| 4527 | + } |
|
| 4176 | 4528 | $discount->fk_soc = $this->socid; |
| 4177 | 4529 | $this->tpl['label'].= $discount->getNomUrl(0,'discount'); |
| 4178 | - } |
|
| 4179 | - else if (! empty($line->fk_product)) |
|
| 4530 | + } else if (! empty($line->fk_product)) |
|
| 4180 | 4531 | {
|
| 4181 | 4532 | $productstatic = new Product($this->db); |
| 4182 | 4533 | $productstatic->id = $line->fk_product; |
@@ -4194,13 +4545,12 @@ discard block |
||
| 4194 | 4545 | {
|
| 4195 | 4546 | $this->tpl['label'].= get_date_range($date_start,$date_end); |
| 4196 | 4547 | } |
| 4197 | - } |
|
| 4198 | - else |
|
| 4548 | + } else |
|
| 4199 | 4549 | {
|
| 4200 | 4550 | $this->tpl['label'].= ($line->product_type == -1 ? ' ' : ($line->product_type == 1 ? img_object($langs->trans(''),'service') : img_object($langs->trans(''),'product')));
|
| 4201 | 4551 | if (!empty($line->desc)) {
|
| 4202 | 4552 | $this->tpl['label'].=$line->desc; |
| 4203 | - }else {
|
|
| 4553 | + } else {
|
|
| 4204 | 4554 | $this->tpl['label'].= ($line->label ? ' '.$line->label : ''); |
| 4205 | 4555 | } |
| 4206 | 4556 | |
@@ -4213,36 +4563,35 @@ discard block |
||
| 4213 | 4563 | |
| 4214 | 4564 | if (! empty($line->desc)) |
| 4215 | 4565 | {
|
| 4216 | - if ($line->desc == '(CREDIT_NOTE)') // TODO Not sure this is used for source object |
|
| 4566 | + if ($line->desc == '(CREDIT_NOTE)') { |
|
| 4567 | + // TODO Not sure this is used for source object |
|
| 4217 | 4568 | {
|
| 4218 | - $discount=new DiscountAbsolute($this->db); |
|
| 4569 | + $discount=new DiscountAbsolute($this->db); |
|
| 4570 | + } |
|
| 4219 | 4571 | $discount->fetch($line->fk_remise_except); |
| 4220 | 4572 | $this->tpl['description'] = $langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
|
| 4221 | - } |
|
| 4222 | - elseif ($line->desc == '(DEPOSIT)') // TODO Not sure this is used for source object |
|
| 4573 | + } elseif ($line->desc == '(DEPOSIT)') { |
|
| 4574 | + // TODO Not sure this is used for source object |
|
| 4223 | 4575 | {
|
| 4224 | - $discount=new DiscountAbsolute($this->db); |
|
| 4576 | + $discount=new DiscountAbsolute($this->db); |
|
| 4577 | + } |
|
| 4225 | 4578 | $discount->fetch($line->fk_remise_except); |
| 4226 | 4579 | $this->tpl['description'] = $langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
|
| 4227 | - } |
|
| 4228 | - elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4580 | + } elseif ($line->desc == '(EXCESS RECEIVED)') |
|
| 4229 | 4581 | {
|
| 4230 | 4582 | $discount=new DiscountAbsolute($this->db); |
| 4231 | 4583 | $discount->fetch($line->fk_remise_except); |
| 4232 | 4584 | $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0));
|
| 4233 | - } |
|
| 4234 | - elseif ($line->desc == '(EXCESS PAID)') |
|
| 4585 | + } elseif ($line->desc == '(EXCESS PAID)') |
|
| 4235 | 4586 | {
|
| 4236 | 4587 | $discount=new DiscountAbsolute($this->db); |
| 4237 | 4588 | $discount->fetch($line->fk_remise_except); |
| 4238 | 4589 | $this->tpl['description'] = $langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0));
|
| 4239 | - } |
|
| 4240 | - else |
|
| 4590 | + } else |
|
| 4241 | 4591 | {
|
| 4242 | 4592 | $this->tpl['description'] = dol_trunc($line->desc,60); |
| 4243 | 4593 | } |
| 4244 | - } |
|
| 4245 | - else |
|
| 4594 | + } else |
|
| 4246 | 4595 | {
|
| 4247 | 4596 | $this->tpl['description'] = ' '; |
| 4248 | 4597 | } |
@@ -4250,18 +4599,23 @@ discard block |
||
| 4250 | 4599 | // VAT Rate |
| 4251 | 4600 | $this->tpl['vat_rate'] = vatrate($line->tva_tx, true); |
| 4252 | 4601 | $this->tpl['vat_rate'] .= (($line->info_bits & 1) == 1) ? '*' : ''; |
| 4253 | - if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')';
|
|
| 4602 | + if (! empty($line->vat_src_code) && ! preg_match('/\(/', $this->tpl['vat_rate'])) { |
|
| 4603 | + $this->tpl['vat_rate'].=' ('.$line->vat_src_code.')'; |
|
| 4604 | + } |
|
| 4254 | 4605 | |
| 4255 | 4606 | $this->tpl['price'] = price($line->subprice); |
| 4256 | 4607 | $this->tpl['multicurrency_price'] = price($line->multicurrency_subprice); |
| 4257 | 4608 | $this->tpl['qty'] = (($line->info_bits & 2) != 2) ? $line->qty : ' '; |
| 4258 | - if (Globals::$conf->global->PRODUCT_USE_UNITS) |
|
| 4259 | - $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long'));
|
|
| 4609 | + if (Globals::$conf->global->PRODUCT_USE_UNITS) { |
|
| 4610 | + $this->tpl['unit'] = $langs->transnoentities($line->getLabelOfUnit('long')); |
|
| 4611 | + } |
|
| 4260 | 4612 | $this->tpl['remise_percent'] = (($line->info_bits & 2) != 2) ? vatrate($line->remise_percent, true) : ' '; |
| 4261 | 4613 | |
| 4262 | 4614 | // Is the line strike or not |
| 4263 | 4615 | $this->tpl['strike']=0; |
| 4264 | - if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) $this->tpl['strike']=1; |
|
| 4616 | + if ($restrictlist == 'services' && $line->product_type != Product::TYPE_SERVICE) { |
|
| 4617 | + $this->tpl['strike']=1; |
|
| 4618 | + } |
|
| 4265 | 4619 | |
| 4266 | 4620 | // Output template part (modules that overwrite templates must declare this into descriptor) |
| 4267 | 4621 | // Use global variables + $dateSelector + $seller and $buyer |
@@ -4274,7 +4628,9 @@ discard block |
||
| 4274 | 4628 | } else {
|
| 4275 | 4629 | $res=include $tpl; // for debug |
| 4276 | 4630 | } |
| 4277 | - if ($res) break; |
|
| 4631 | + if ($res) { |
|
| 4632 | + break; |
|
| 4633 | + } |
|
| 4278 | 4634 | } |
| 4279 | 4635 | } |
| 4280 | 4636 | |
@@ -4316,8 +4672,7 @@ discard block |
||
| 4316 | 4672 | {
|
| 4317 | 4673 | $this->db->commit(); |
| 4318 | 4674 | return 1; |
| 4319 | - } |
|
| 4320 | - else |
|
| 4675 | + } else |
|
| 4321 | 4676 | {
|
| 4322 | 4677 | $this->error=$this->db->lasterror(); |
| 4323 | 4678 | $this->db->rollback(); |
@@ -4352,8 +4707,7 @@ discard block |
||
| 4352 | 4707 | $this->error=$this->db->lasterror(); |
| 4353 | 4708 | $this->db->rollback(); |
| 4354 | 4709 | return -1; |
| 4355 | - } |
|
| 4356 | - else |
|
| 4710 | + } else |
|
| 4357 | 4711 | {
|
| 4358 | 4712 | if (! $notrigger) |
| 4359 | 4713 | {
|
@@ -4420,14 +4774,20 @@ discard block |
||
| 4420 | 4774 | // Search template files |
| 4421 | 4775 | $file=''; $classname=''; $filefound=0; |
| 4422 | 4776 | $dirmodels=array('/');
|
| 4423 | - if (is_array(Globals::$conf->modules_parts['models'])) |
|
| 4424 | - $dirmodels = array_merge($dirmodels, Globals::$conf->modules_parts['models']); |
|
| 4777 | + if (is_array(Globals::$conf->modules_parts['models'])) { |
|
| 4778 | + $dirmodels = array_merge($dirmodels, Globals::$conf->modules_parts['models']); |
|
| 4779 | + } |
|
| 4425 | 4780 | foreach($dirmodels as $reldir) |
| 4426 | 4781 | {
|
| 4427 | 4782 | foreach(array('doc','pdf') as $prefix)
|
| 4428 | 4783 | {
|
| 4429 | - if (in_array(get_class($this), array('Adherent'))) $file = $prefix."_".$modele.".class.php"; // Member module use prefix_module.class.php
|
|
| 4430 | - else $file = $prefix."_".$modele.".modules.php"; |
|
| 4784 | + if (in_array(get_class($this), array('Adherent'))) { |
|
| 4785 | + $file = $prefix."_".$modele.".class.php"; |
|
| 4786 | + } |
|
| 4787 | + // Member module use prefix_module.class.php |
|
| 4788 | + else { |
|
| 4789 | + $file = $prefix."_".$modele.".modules.php"; |
|
| 4790 | + } |
|
| 4431 | 4791 | |
| 4432 | 4792 | // On verifie l'emplacement du modele |
| 4433 | 4793 | $file=dol_buildpath($reldir.$modelspath.$file,0); |
@@ -4438,7 +4798,9 @@ discard block |
||
| 4438 | 4798 | break; |
| 4439 | 4799 | } |
| 4440 | 4800 | } |
| 4441 | - if ($filefound) break; |
|
| 4801 | + if ($filefound) { |
|
| 4802 | + break; |
|
| 4803 | + } |
|
| 4442 | 4804 | } |
| 4443 | 4805 | |
| 4444 | 4806 | // If generator was found |
@@ -4469,7 +4831,9 @@ discard block |
||
| 4469 | 4831 | if (is_dir($tmpdir)) |
| 4470 | 4832 | {
|
| 4471 | 4833 | $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0); |
| 4472 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4834 | + if (count($tmpfiles)) { |
|
| 4835 | + $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
| 4836 | + } |
|
| 4473 | 4837 | } |
| 4474 | 4838 | } |
| 4475 | 4839 | |
@@ -4507,8 +4871,7 @@ discard block |
||
| 4507 | 4871 | {
|
| 4508 | 4872 | $arrayofrecords = array(); // The write_file of templates of adherent class need this var |
| 4509 | 4873 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); |
| 4510 | - } |
|
| 4511 | - else |
|
| 4874 | + } else |
|
| 4512 | 4875 | {
|
| 4513 | 4876 | $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, $hidedetails, $hidedesc, $hideref, $moreparams); |
| 4514 | 4877 | } |
@@ -4530,9 +4893,11 @@ discard block |
||
| 4530 | 4893 | $destfile = basename($destfull); |
| 4531 | 4894 | $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
| 4532 | 4895 | |
| 4533 | - if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
| 4896 | + if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { |
|
| 4897 | + // If not a tmp dir |
|
| 4534 | 4898 | {
|
| 4535 | - $filename = basename($destfile); |
|
| 4899 | + $filename = basename($destfile); |
|
| 4900 | + } |
|
| 4536 | 4901 | $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
| 4537 | 4902 | $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
| 4538 | 4903 | |
@@ -4545,22 +4910,30 @@ discard block |
||
| 4545 | 4910 | if ($this->element == 'propal') |
| 4546 | 4911 | {
|
| 4547 | 4912 | $useonlinesignature = Globals::$conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok |
| 4548 | - if ($useonlinesignature) $setsharekey=true; |
|
| 4549 | - if (!empty(Globals::$conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4550 | - $setsharekey = true; |
|
| 4913 | + if ($useonlinesignature) { |
|
| 4914 | + $setsharekey=true; |
|
| 4915 | + } |
|
| 4916 | + if (!empty(Globals::$conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4917 | + $setsharekey = true; |
|
| 4918 | + } |
|
| 4551 | 4919 | } |
| 4552 | - if ($this->element == 'commande' && !empty(Globals::$conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4553 | - $setsharekey = true; |
|
| 4554 | - if ($this->element == 'facture' && !empty(Globals::$conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4555 | - $setsharekey = true; |
|
| 4556 | - if ($this->element == 'bank_account' && !empty(Globals::$conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) |
|
| 4557 | - $setsharekey = true; |
|
| 4920 | + if ($this->element == 'commande' && !empty(Globals::$conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4921 | + $setsharekey = true; |
|
| 4922 | + } |
|
| 4923 | + if ($this->element == 'facture' && !empty(Globals::$conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4924 | + $setsharekey = true; |
|
| 4925 | + } |
|
| 4926 | + if ($this->element == 'bank_account' && !empty(Globals::$conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { |
|
| 4927 | + $setsharekey = true; |
|
| 4928 | + } |
|
| 4558 | 4929 | |
| 4559 | 4930 | if ($setsharekey) |
| 4560 | 4931 | {
|
| 4561 | - if (empty($ecmfile->share)) // Because object not found or share not set yet |
|
| 4932 | + if (empty($ecmfile->share)) { |
|
| 4933 | + // Because object not found or share not set yet |
|
| 4562 | 4934 | {
|
| 4563 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4935 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; |
|
| 4936 | + } |
|
| 4564 | 4937 | $ecmfile->share = getRandomPassword(true); |
| 4565 | 4938 | } |
| 4566 | 4939 | } |
@@ -4577,8 +4950,7 @@ discard block |
||
| 4577 | 4950 | {
|
| 4578 | 4951 | setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); |
| 4579 | 4952 | } |
| 4580 | - } |
|
| 4581 | - else |
|
| 4953 | + } else |
|
| 4582 | 4954 | {
|
| 4583 | 4955 | $ecmfile->entity = Globals::$conf->entity; |
| 4584 | 4956 | $ecmfile->filepath = $rel_dir; |
@@ -4605,17 +4977,20 @@ discard block |
||
| 4605 | 4977 | |
| 4606 | 4978 | // Update the last_main_doc field into main object (if documenent generator has property ->update_main_doc_field set) |
| 4607 | 4979 | $update_main_doc_field=0; |
| 4608 | - if (! empty($obj->update_main_doc_field)) $update_main_doc_field=1; |
|
| 4980 | + if (! empty($obj->update_main_doc_field)) { |
|
| 4981 | + $update_main_doc_field=1; |
|
| 4982 | + } |
|
| 4609 | 4983 | if ($update_main_doc_field && ! empty($this->table_element)) |
| 4610 | 4984 | {
|
| 4611 | 4985 | $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".($ecmfile->filepath.'/'.$ecmfile->filename)."'"; |
| 4612 | 4986 | $sql.= ' WHERE rowid = '.$this->id; |
| 4613 | 4987 | $resql = $this->db->query($sql); |
| 4614 | - if (! $resql) dol_print_error($this->db); |
|
| 4988 | + if (! $resql) { |
|
| 4989 | + dol_print_error($this->db); |
|
| 4990 | + } |
|
| 4615 | 4991 | } |
| 4616 | 4992 | } |
| 4617 | - } |
|
| 4618 | - else |
|
| 4993 | + } else |
|
| 4619 | 4994 | {
|
| 4620 | 4995 | 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);
|
| 4621 | 4996 | } |
@@ -4624,15 +4999,13 @@ discard block |
||
| 4624 | 4999 | dol_meta_create($this); |
| 4625 | 5000 | |
| 4626 | 5001 | return 1; |
| 4627 | - } |
|
| 4628 | - else |
|
| 5002 | + } else |
|
| 4629 | 5003 | {
|
| 4630 | 5004 | $outputlangs->charset_output=$sav_charset_output; |
| 4631 | 5005 | dol_print_error($this->db, "Error generating document for ".__CLASS__.". Error: ".$obj->error, $obj->errors); |
| 4632 | 5006 | return -1; |
| 4633 | 5007 | } |
| 4634 | - } |
|
| 4635 | - else |
|
| 5008 | + } else |
|
| 4636 | 5009 | {
|
| 4637 | 5010 | $this->error=$langs->trans("Error")." ".$langs->trans("ErrorFileDoesNotExists",$file);
|
| 4638 | 5011 | dol_print_error('',$this->error);
|
@@ -4688,13 +5061,21 @@ discard block |
||
| 4688 | 5061 | global $conf, $_POST; |
| 4689 | 5062 | |
| 4690 | 5063 | // If param here has been posted, we use this value first. |
| 4691 | - if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); |
|
| 5064 | + if (isset($_POST[$fieldname])) { |
|
| 5065 | + return GETPOST($fieldname, 2); |
|
| 5066 | + } |
|
| 4692 | 5067 | |
| 4693 | - if (isset($alternatevalue)) return $alternatevalue; |
|
| 5068 | + if (isset($alternatevalue)) { |
|
| 5069 | + return $alternatevalue; |
|
| 5070 | + } |
|
| 4694 | 5071 | |
| 4695 | 5072 | $newelement=$this->element; |
| 4696 | - if ($newelement == 'facture') $newelement='invoice'; |
|
| 4697 | - if ($newelement == 'commande') $newelement='order'; |
|
| 5073 | + if ($newelement == 'facture') { |
|
| 5074 | + $newelement='invoice'; |
|
| 5075 | + } |
|
| 5076 | + if ($newelement == 'commande') { |
|
| 5077 | + $newelement='order'; |
|
| 5078 | + } |
|
| 4698 | 5079 | if (empty($newelement)) |
| 4699 | 5080 | {
|
| 4700 | 5081 | dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING);
|
@@ -4703,8 +5084,9 @@ discard block |
||
| 4703 | 5084 | |
| 4704 | 5085 | $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); |
| 4705 | 5086 | //var_dump($keyforfieldname); |
| 4706 | - if (isset(Globals::$conf->global->$keyforfieldname)) |
|
| 4707 | - return Globals::$conf->global->$keyforfieldname; |
|
| 5087 | + if (isset(Globals::$conf->global->$keyforfieldname)) { |
|
| 5088 | + return Globals::$conf->global->$keyforfieldname; |
|
| 5089 | + } |
|
| 4708 | 5090 | |
| 4709 | 5091 | // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname |
| 4710 | 5092 | } |
@@ -4738,8 +5120,7 @@ discard block |
||
| 4738 | 5120 | if (!empty($this->errors)) |
| 4739 | 5121 | {
|
| 4740 | 5122 | $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. |
| 4741 | - } |
|
| 4742 | - else |
|
| 5123 | + } else |
|
| 4743 | 5124 | {
|
| 4744 | 5125 | $this->errors=$interface->errors; |
| 4745 | 5126 | } |
@@ -4791,15 +5172,17 @@ discard block |
||
| 4791 | 5172 | $extrafields->fetch_name_optionals_label($this->table_element); |
| 4792 | 5173 | } |
| 4793 | 5174 | $optionsArray = (! empty($extrafields->attributes[$this->table_element]['label'])?$extrafields->attributes[$this->table_element]['label']:null); |
| 4794 | - } |
|
| 4795 | - else |
|
| 5175 | + } else |
|
| 4796 | 5176 | {
|
| 4797 | 5177 | // global $extrafields; |
| 4798 | 5178 | dol_syslog("Warning: fetch_optionals was called with param optionsArray defined when you should pass null now", LOG_WARNING);
|
| 4799 | 5179 | } |
| 4800 | 5180 | |
| 4801 | 5181 | $table_element = $this->table_element; |
| 4802 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5182 | + if ($table_element == 'categorie') { |
|
| 5183 | + $table_element = 'categories'; |
|
| 5184 | + } |
|
| 5185 | + // For compatibility |
|
| 4803 | 5186 | |
| 4804 | 5187 | // Request to get complementary values |
| 4805 | 5188 | if (is_array($optionsArray) && count($optionsArray) > 0) |
@@ -4835,8 +5218,7 @@ discard block |
||
| 4835 | 5218 | {
|
| 4836 | 5219 | //var_dump($extrafields->attributes[$this->table_element]['type'][$key]); |
| 4837 | 5220 | $this->array_options["options_".$key]=$this->db->jdate($value); |
| 4838 | - } |
|
| 4839 | - else |
|
| 5221 | + } else |
|
| 4840 | 5222 | {
|
| 4841 | 5223 | $this->array_options["options_".$key]=$value; |
| 4842 | 5224 | } |
@@ -4848,10 +5230,12 @@ discard block |
||
| 4848 | 5230 | |
| 4849 | 5231 | $this->db->free($resql); |
| 4850 | 5232 | |
| 4851 | - if ($numrows) return $numrows; |
|
| 4852 | - else return 0; |
|
| 4853 | - } |
|
| 4854 | - else |
|
| 5233 | + if ($numrows) { |
|
| 5234 | + return $numrows; |
|
| 5235 | + } else { |
|
| 5236 | + return 0; |
|
| 5237 | + } |
|
| 5238 | + } else |
|
| 4855 | 5239 | {
|
| 4856 | 5240 | dol_print_error($this->db); |
| 4857 | 5241 | return -1; |
@@ -4870,7 +5254,10 @@ discard block |
||
| 4870 | 5254 | $this->db->begin(); |
| 4871 | 5255 | |
| 4872 | 5256 | $table_element = $this->table_element; |
| 4873 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5257 | + if ($table_element == 'categorie') { |
|
| 5258 | + $table_element = 'categories'; |
|
| 5259 | + } |
|
| 5260 | + // For compatibility |
|
| 4874 | 5261 | |
| 4875 | 5262 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 4876 | 5263 | dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); |
@@ -4880,8 +5267,7 @@ discard block |
||
| 4880 | 5267 | $this->error=$this->db->lasterror(); |
| 4881 | 5268 | $this->db->rollback(); |
| 4882 | 5269 | return -1; |
| 4883 | - } |
|
| 4884 | - else |
|
| 5270 | + } else |
|
| 4885 | 5271 | {
|
| 4886 | 5272 | $this->db->commit(); |
| 4887 | 5273 | return 1; |
@@ -4902,12 +5288,16 @@ discard block |
||
| 4902 | 5288 | {
|
| 4903 | 5289 | global $conf,$langs,$user; |
| 4904 | 5290 | |
| 4905 | - if (empty($userused)) $userused=$user; |
|
| 5291 | + if (empty($userused)) { |
|
| 5292 | + $userused=$user; |
|
| 5293 | + } |
|
| 4906 | 5294 | |
| 4907 | 5295 | $error=0; |
| 4908 | 5296 | |
| 4909 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 4910 | - return 0; // For avoid conflicts if trigger used |
|
| 5297 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 5298 | + return 0; |
|
| 5299 | + } |
|
| 5300 | + // For avoid conflicts if trigger used |
|
| 4911 | 5301 | |
| 4912 | 5302 | if (! empty($this->array_options)) |
| 4913 | 5303 | {
|
@@ -4920,10 +5310,13 @@ discard block |
||
| 4920 | 5310 | //Eliminate copied source object extra_fields that do not exist in target object |
| 4921 | 5311 | $new_array_options=array(); |
| 4922 | 5312 | foreach ($this->array_options as $key => $value) {
|
| 4923 | - if (in_array(substr($key,8), array_keys($target_extrafields))) // We remove the 'options_' from $key for test |
|
| 4924 | - $new_array_options[$key] = $value; |
|
| 4925 | - elseif (in_array($key, array_keys($target_extrafields))) // We test on $key that does not contains the 'options_' prefix |
|
| 4926 | - $new_array_options['options_'.$key] = $value; |
|
| 5313 | + if (in_array(substr($key,8), array_keys($target_extrafields))) { |
|
| 5314 | + // We remove the 'options_' from $key for test |
|
| 5315 | + $new_array_options[$key] = $value; |
|
| 5316 | + } elseif (in_array($key, array_keys($target_extrafields))) { |
|
| 5317 | + // We test on $key that does not contains the 'options_' prefix |
|
| 5318 | + $new_array_options['options_'.$key] = $value; |
|
| 5319 | + } |
|
| 4927 | 5320 | } |
| 4928 | 5321 | |
| 4929 | 5322 | foreach($new_array_options as $key => $value) |
@@ -4937,8 +5330,12 @@ discard block |
||
| 4937 | 5330 | if ($attributeRequired) |
| 4938 | 5331 | {
|
| 4939 | 5332 | $mandatorypb=false; |
| 4940 | - if ($attributeType == 'link' && $this->array_options[$key] == '-1') $mandatorypb=true; |
|
| 4941 | - if ($this->array_options[$key] === '') $mandatorypb=true; |
|
| 5333 | + if ($attributeType == 'link' && $this->array_options[$key] == '-1') { |
|
| 5334 | + $mandatorypb=true; |
|
| 5335 | + } |
|
| 5336 | + if ($this->array_options[$key] === '') { |
|
| 5337 | + $mandatorypb=true; |
|
| 5338 | + } |
|
| 4942 | 5339 | if ($mandatorypb) |
| 4943 | 5340 | {
|
| 4944 | 5341 | dol_syslog($this->error); |
@@ -4957,8 +5354,7 @@ discard block |
||
| 4957 | 5354 | {
|
| 4958 | 5355 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
| 4959 | 5356 | return -1; |
| 4960 | - } |
|
| 4961 | - elseif ($value=='') |
|
| 5357 | + } elseif ($value=='') |
|
| 4962 | 5358 | {
|
| 4963 | 5359 | $new_array_options[$key] = null; |
| 4964 | 5360 | } |
@@ -4970,8 +5366,7 @@ discard block |
||
| 4970 | 5366 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
| 4971 | 5367 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
| 4972 | 5368 | return -1; |
| 4973 | - } |
|
| 4974 | - elseif ($value=='') |
|
| 5369 | + } elseif ($value=='') |
|
| 4975 | 5370 | {
|
| 4976 | 5371 | $new_array_options[$key] = null; |
| 4977 | 5372 | } |
@@ -4996,27 +5391,27 @@ discard block |
||
| 4996 | 5391 | //global $action; // $action may be 'create', 'update', 'update_extras'... |
| 4997 | 5392 | //var_dump($action); |
| 4998 | 5393 | //var_dump($this->oldcopy);exit; |
| 4999 | - 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 |
|
| 5394 | + if (is_object($this->oldcopy)) { |
|
| 5395 | + // If this->oldcopy is not defined, we can't know if we change attribute or not, so we must keep value |
|
| 5000 | 5396 | {
|
| 5001 | 5397 | //var_dump($this->oldcopy->array_options[$key]); var_dump($this->array_options[$key]); |
| 5002 | 5398 | 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. |
| 5003 | 5399 | {
|
| 5004 | - $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
|
| 5005 | - } |
|
| 5006 | - else |
|
| 5400 | + $new_array_options[$key] = $this->array_options[$key]; |
|
| 5401 | + } |
|
| 5402 | + // Value is kept |
|
| 5403 | + } else |
|
| 5007 | 5404 | {
|
| 5008 | 5405 | // var_dump($algo); |
| 5009 | 5406 | $newvalue = dol_hash($this->array_options[$key], $algo); |
| 5010 | 5407 | $new_array_options[$key] = $newvalue; |
| 5011 | 5408 | } |
| 5012 | - } |
|
| 5013 | - else |
|
| 5409 | + } else |
|
| 5014 | 5410 | {
|
| 5015 | 5411 | $new_array_options[$key] = $this->array_options[$key]; // Value is kept |
| 5016 | 5412 | } |
| 5017 | 5413 | } |
| 5018 | - } |
|
| 5019 | - else // Common usage |
|
| 5414 | + } else // Common usage |
|
| 5020 | 5415 | {
|
| 5021 | 5416 | $new_array_options[$key] = $this->array_options[$key]; |
| 5022 | 5417 | } |
@@ -5042,26 +5437,30 @@ discard block |
||
| 5042 | 5437 | dol_include_once($InfoFieldList[1]); |
| 5043 | 5438 | if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) |
| 5044 | 5439 | {
|
| 5045 | - if ($value == '-1') // -1 is key for no defined in combo list of objects |
|
| 5440 | + if ($value == '-1') { |
|
| 5441 | + // -1 is key for no defined in combo list of objects |
|
| 5046 | 5442 | {
|
| 5047 | - $new_array_options[$key]=''; |
|
| 5048 | - } |
|
| 5049 | - elseif ($value) |
|
| 5443 | + $new_array_options[$key]=''; |
|
| 5444 | + } |
|
| 5445 | + } elseif ($value) |
|
| 5050 | 5446 | {
|
| 5051 | 5447 | $object = new $InfoFieldList[0]($this->db); |
| 5052 | - if (is_numeric($value)) $res=$object->fetch($value); |
|
| 5053 | - else $res=$object->fetch('',$value);
|
|
| 5054 | - |
|
| 5055 | - if ($res > 0) $new_array_options[$key]=$object->id; |
|
| 5056 | - else |
|
| 5448 | + if (is_numeric($value)) { |
|
| 5449 | + $res=$object->fetch($value); |
|
| 5450 | + } else { |
|
| 5451 | + $res=$object->fetch('',$value); |
|
| 5452 | + } |
|
| 5453 | + |
|
| 5454 | + if ($res > 0) { |
|
| 5455 | + $new_array_options[$key]=$object->id; |
|
| 5456 | + } else |
|
| 5057 | 5457 | {
|
| 5058 | 5458 | $this->error="Id/Ref '".$value."' for object '".$object->element."' not found"; |
| 5059 | 5459 | $this->db->rollback(); |
| 5060 | 5460 | return -1; |
| 5061 | 5461 | } |
| 5062 | 5462 | } |
| 5063 | - } |
|
| 5064 | - else |
|
| 5463 | + } else |
|
| 5065 | 5464 | {
|
| 5066 | 5465 | dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
| 5067 | 5466 | } |
@@ -5072,7 +5471,10 @@ discard block |
||
| 5072 | 5471 | $this->db->begin(); |
| 5073 | 5472 | |
| 5074 | 5473 | $table_element = $this->table_element; |
| 5075 | - if ($table_element == 'categorie') $table_element = 'categories'; // For compatibility |
|
| 5474 | + if ($table_element == 'categorie') { |
|
| 5475 | + $table_element = 'categories'; |
|
| 5476 | + } |
|
| 5477 | + // For compatibility |
|
| 5076 | 5478 | |
| 5077 | 5479 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".$this->id; |
| 5078 | 5480 | dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); |
@@ -5083,8 +5485,10 @@ discard block |
||
| 5083 | 5485 | {
|
| 5084 | 5486 | $attributeKey = substr($key,8); // Remove 'options_' prefix |
| 5085 | 5487 | // Add field of attribut |
| 5086 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator |
|
| 5087 | - $sql.=",".$attributeKey; |
|
| 5488 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { |
|
| 5489 | + // Only for other type than separator |
|
| 5490 | + $sql.=",".$attributeKey; |
|
| 5491 | + } |
|
| 5088 | 5492 | } |
| 5089 | 5493 | $sql .= ") VALUES (".$this->id;
|
| 5090 | 5494 | |
@@ -5092,13 +5496,14 @@ discard block |
||
| 5092 | 5496 | {
|
| 5093 | 5497 | $attributeKey = substr($key,8); // Remove 'options_' prefix |
| 5094 | 5498 | // Add field of attribute |
| 5095 | - if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') // Only for other type than separator) |
|
| 5499 | + if ($extrafields->attributes[$this->table_element]['type'][$attributeKey] != 'separate') { |
|
| 5500 | + // Only for other type than separator) |
|
| 5096 | 5501 | {
|
| 5097 | 5502 | if ($new_array_options[$key] != '') |
| 5098 | 5503 | {
|
| 5099 | - $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5100 | - } |
|
| 5101 | - else |
|
| 5504 | + $sql.=",'".$this->db->escape($new_array_options[$key])."'"; |
|
| 5505 | + } |
|
| 5506 | + } else |
|
| 5102 | 5507 | {
|
| 5103 | 5508 | $sql.=",null"; |
| 5104 | 5509 | } |
@@ -5119,7 +5524,9 @@ discard block |
||
| 5119 | 5524 | // Call trigger |
| 5120 | 5525 | $this->context=array('extrafieldaddupdate'=>1);
|
| 5121 | 5526 | $result=$this->call_trigger($trigger, $userused); |
| 5122 | - if ($result < 0) $error++; |
|
| 5527 | + if ($result < 0) { |
|
| 5528 | + $error++; |
|
| 5529 | + } |
|
| 5123 | 5530 | // End call trigger |
| 5124 | 5531 | } |
| 5125 | 5532 | |
@@ -5127,14 +5534,14 @@ discard block |
||
| 5127 | 5534 | {
|
| 5128 | 5535 | $this->db->rollback(); |
| 5129 | 5536 | return -1; |
| 5130 | - } |
|
| 5131 | - else |
|
| 5537 | + } else |
|
| 5132 | 5538 | {
|
| 5133 | 5539 | $this->db->commit(); |
| 5134 | 5540 | return 1; |
| 5135 | 5541 | } |
| 5136 | - } |
|
| 5137 | - else return 0; |
|
| 5542 | + } else { |
|
| 5543 | + return 0; |
|
| 5544 | + } |
|
| 5138 | 5545 | } |
| 5139 | 5546 | |
| 5140 | 5547 | /** |
@@ -5151,12 +5558,16 @@ discard block |
||
| 5151 | 5558 | {
|
| 5152 | 5559 | global $conf,$langs,$user; |
| 5153 | 5560 | |
| 5154 | - if (empty($userused)) $userused=$user; |
|
| 5561 | + if (empty($userused)) { |
|
| 5562 | + $userused=$user; |
|
| 5563 | + } |
|
| 5155 | 5564 | |
| 5156 | 5565 | $error=0; |
| 5157 | 5566 | |
| 5158 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) |
|
| 5159 | - return 0; // For avoid conflicts if trigger used |
|
| 5567 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 5568 | + return 0; |
|
| 5569 | + } |
|
| 5570 | + // For avoid conflicts if trigger used |
|
| 5160 | 5571 | |
| 5161 | 5572 | if (! empty($this->array_options) && isset($this->array_options["options_".$key])) |
| 5162 | 5573 | {
|
@@ -5183,8 +5594,7 @@ discard block |
||
| 5183 | 5594 | {
|
| 5184 | 5595 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue",$attributeLabel);
|
| 5185 | 5596 | return -1; |
| 5186 | - } |
|
| 5187 | - elseif ($value=='') |
|
| 5597 | + } elseif ($value=='') |
|
| 5188 | 5598 | {
|
| 5189 | 5599 | $this->array_options["options_".$key] = null; |
| 5190 | 5600 | } |
@@ -5196,8 +5606,7 @@ discard block |
||
| 5196 | 5606 | dol_syslog($langs->trans("ExtraFieldHasWrongValue")." sur ".$attributeLabel."(".$value."is not '".$attributeType."')", LOG_DEBUG);
|
| 5197 | 5607 | $this->errors[]=$langs->trans("ExtraFieldHasWrongValue", $attributeLabel);
|
| 5198 | 5608 | return -1; |
| 5199 | - } |
|
| 5200 | - elseif ($value=='') |
|
| 5609 | + } elseif ($value=='') |
|
| 5201 | 5610 | {
|
| 5202 | 5611 | $this->array_options["options_".$key] = null; |
| 5203 | 5612 | } |
@@ -5249,7 +5658,9 @@ discard block |
||
| 5249 | 5658 | // Call trigger |
| 5250 | 5659 | $this->context=array('extrafieldupdate'=>1);
|
| 5251 | 5660 | $result=$this->call_trigger($trigger, $userused); |
| 5252 | - if ($result < 0) $error++; |
|
| 5661 | + if ($result < 0) { |
|
| 5662 | + $error++; |
|
| 5663 | + } |
|
| 5253 | 5664 | // End call trigger |
| 5254 | 5665 | } |
| 5255 | 5666 | |
@@ -5258,14 +5669,14 @@ discard block |
||
| 5258 | 5669 | dol_syslog(get_class($this) . "::".__METHOD__ . $this->error, LOG_ERR); |
| 5259 | 5670 | $this->db->rollback(); |
| 5260 | 5671 | return -1; |
| 5261 | - } |
|
| 5262 | - else |
|
| 5672 | + } else |
|
| 5263 | 5673 | {
|
| 5264 | 5674 | $this->db->commit(); |
| 5265 | 5675 | return 1; |
| 5266 | 5676 | } |
| 5267 | - } |
|
| 5268 | - else return 0; |
|
| 5677 | + } else { |
|
| 5678 | + return 0; |
|
| 5679 | + } |
|
| 5269 | 5680 | } |
| 5270 | 5681 | |
| 5271 | 5682 | |
@@ -5340,8 +5751,11 @@ discard block |
||
| 5340 | 5751 | |
| 5341 | 5752 | if ($computed) |
| 5342 | 5753 | {
|
| 5343 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>';
|
|
| 5344 | - else return ''; |
|
| 5754 | + if (! preg_match('/^search_/', $keyprefix)) { |
|
| 5755 | + return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 5756 | + } else { |
|
| 5757 | + return ''; |
|
| 5758 | + } |
|
| 5345 | 5759 | } |
| 5346 | 5760 | |
| 5347 | 5761 | |
@@ -5355,33 +5769,27 @@ discard block |
||
| 5355 | 5769 | if ($type == 'date') |
| 5356 | 5770 | {
|
| 5357 | 5771 | $morecss = 'minwidth100imp'; |
| 5358 | - } |
|
| 5359 | - elseif ($type == 'datetime') |
|
| 5772 | + } elseif ($type == 'datetime') |
|
| 5360 | 5773 | {
|
| 5361 | 5774 | $morecss = 'minwidth200imp'; |
| 5362 | - } |
|
| 5363 | - elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5775 | + } elseif (in_array($type,array('int','integer','price')) || preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5364 | 5776 | {
|
| 5365 | 5777 | $morecss = 'maxwidth75'; |
| 5366 | - }elseif ($type == 'url') |
|
| 5778 | + } elseif ($type == 'url') |
|
| 5367 | 5779 | {
|
| 5368 | 5780 | $morecss='minwidth400'; |
| 5369 | - } |
|
| 5370 | - elseif ($type == 'boolean') |
|
| 5781 | + } elseif ($type == 'boolean') |
|
| 5371 | 5782 | {
|
| 5372 | 5783 | $morecss=''; |
| 5373 | - } |
|
| 5374 | - else |
|
| 5784 | + } else |
|
| 5375 | 5785 | {
|
| 5376 | 5786 | if (round($size) < 12) |
| 5377 | 5787 | {
|
| 5378 | 5788 | $morecss = 'minwidth100'; |
| 5379 | - } |
|
| 5380 | - else if (round($size) <= 48) |
|
| 5789 | + } else if (round($size) <= 48) |
|
| 5381 | 5790 | {
|
| 5382 | 5791 | $morecss = 'minwidth200'; |
| 5383 | - } |
|
| 5384 | - else |
|
| 5792 | + } else |
|
| 5385 | 5793 | {
|
| 5386 | 5794 | $morecss = 'minwidth400'; |
| 5387 | 5795 | } |
@@ -5396,52 +5804,50 @@ discard block |
||
| 5396 | 5804 | $showtime = in_array($type,array('datetime')) ? 1 : 0;
|
| 5397 | 5805 | |
| 5398 | 5806 | // Do not show current date when field not required (see selectDate() method) |
| 5399 | - if (!$required && $value == '') $value = '-1'; |
|
| 5807 | + if (!$required && $value == '') { |
|
| 5808 | + $value = '-1'; |
|
| 5809 | + } |
|
| 5400 | 5810 | |
| 5401 | 5811 | // TODO Must also support $moreparam |
| 5402 | 5812 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 5403 | - } |
|
| 5404 | - elseif (in_array($type,array('int','integer')))
|
|
| 5813 | + } elseif (in_array($type,array('int','integer')))
|
|
| 5405 | 5814 | {
|
| 5406 | 5815 | $tmp=explode(',',$size);
|
| 5407 | 5816 | $newsize=$tmp[0]; |
| 5408 | 5817 | $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:'').'>'; |
| 5409 | - } |
|
| 5410 | - elseif (preg_match('/varchar/', $type))
|
|
| 5818 | + } elseif (preg_match('/varchar/', $type))
|
|
| 5411 | 5819 | {
|
| 5412 | 5820 | $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:'').'>'; |
| 5413 | - } |
|
| 5414 | - elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5821 | + } elseif (in_array($type, array('mail', 'phone', 'url')))
|
|
| 5415 | 5822 | {
|
| 5416 | 5823 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5417 | - } |
|
| 5418 | - elseif ($type == 'text') |
|
| 5824 | + } elseif ($type == 'text') |
|
| 5419 | 5825 | {
|
| 5420 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5826 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 5827 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5421 | 5828 | {
|
| 5422 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5829 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5830 | + } |
|
| 5423 | 5831 | $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
| 5424 | 5832 | $out=$doleditor->Create(1); |
| 5425 | - } |
|
| 5426 | - else |
|
| 5833 | + } else |
|
| 5427 | 5834 | {
|
| 5428 | 5835 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5429 | 5836 | } |
| 5430 | - } |
|
| 5431 | - elseif ($type == 'html') |
|
| 5837 | + } elseif ($type == 'html') |
|
| 5432 | 5838 | {
|
| 5433 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field
|
|
| 5839 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 5840 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 5434 | 5841 | {
|
| 5435 | - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5842 | + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
|
| 5843 | + } |
|
| 5436 | 5844 | $doleditor = new DolEditor($keyprefix . $key . $keysuffix, $value, '', 200, 'dolibarr_notes', 'In', false, false, !empty(Globals::$conf->fckeditor->enabled) && Globals::$conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_5, '90%'); |
| 5437 | 5845 | $out=$doleditor->Create(1); |
| 5438 | - } |
|
| 5439 | - else |
|
| 5846 | + } else |
|
| 5440 | 5847 | {
|
| 5441 | 5848 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 5442 | 5849 | } |
| 5443 | - } |
|
| 5444 | - elseif ($type == 'boolean') |
|
| 5850 | + } elseif ($type == 'boolean') |
|
| 5445 | 5851 | {
|
| 5446 | 5852 | $checked=''; |
| 5447 | 5853 | if (!empty($value)) {
|
@@ -5450,22 +5856,19 @@ discard block |
||
| 5450 | 5856 | $checked=' value="1" '; |
| 5451 | 5857 | } |
| 5452 | 5858 | $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
| 5453 | - } |
|
| 5454 | - elseif ($type == 'price') |
|
| 5859 | + } elseif ($type == 'price') |
|
| 5455 | 5860 | {
|
| 5456 | 5861 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
| 5457 | 5862 | $value=price($value); |
| 5458 | 5863 | } |
| 5459 | 5864 | $out = '<input type="text" class="flat ' . $morecss . ' maxwidthonsmartphone" name="' . $keyprefix . $key . $keysuffix . '" id="' . $keyprefix . $key . $keysuffix . '" value="' . $value . '" ' . ($moreparam ? $moreparam : '') . '> ' . $langs->getCurrencySymbol(Globals::$conf->currency); |
| 5460 | - } |
|
| 5461 | - elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5865 | + } elseif (preg_match('/^double(\([0-9],[0-9]\)){0,1}/',$type))
|
|
| 5462 | 5866 | {
|
| 5463 | 5867 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format.
|
| 5464 | 5868 | $value=price($value); |
| 5465 | 5869 | } |
| 5466 | 5870 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
| 5467 | - } |
|
| 5468 | - elseif ($type == 'select') |
|
| 5871 | + } elseif ($type == 'select') |
|
| 5469 | 5872 | {
|
| 5470 | 5873 | $out = ''; |
| 5471 | 5874 | if (!empty(Globals::$conf->use_javascript_ajax) && !empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
@@ -5474,10 +5877,14 @@ discard block |
||
| 5474 | 5877 | } |
| 5475 | 5878 | |
| 5476 | 5879 | $out.='<select class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.($moreparam?$moreparam:'').'>'; |
| 5477 | - if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1))$out.='<option value="0"> </option>'; |
|
| 5880 | + if((! isset($this->fields[$key]['default'])) ||($this->fields[$key]['notnull']!=1)) { |
|
| 5881 | + $out.='<option value="0"> </option>'; |
|
| 5882 | + } |
|
| 5478 | 5883 | foreach ($param['options'] as $key => $val) |
| 5479 | 5884 | {
|
| 5480 | - if ((string) $key == '') continue; |
|
| 5885 | + if ((string) $key == '') { |
|
| 5886 | + continue; |
|
| 5887 | + } |
|
| 5481 | 5888 | list($val, $parent) = explode('|', $val);
|
| 5482 | 5889 | $out.='<option value="'.$key.'"'; |
| 5483 | 5890 | $out.= (((string) $value == (string) $key)?' selected':''); |
@@ -5485,8 +5892,7 @@ discard block |
||
| 5485 | 5892 | $out.='>'.$val.'</option>'; |
| 5486 | 5893 | } |
| 5487 | 5894 | $out.='</select>'; |
| 5488 | - } |
|
| 5489 | - elseif ($type == 'sellist') |
|
| 5895 | + } elseif ($type == 'sellist') |
|
| 5490 | 5896 | {
|
| 5491 | 5897 | $out = ''; |
| 5492 | 5898 | if (!empty(Globals::$conf->use_javascript_ajax) && !empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) {
|
@@ -5552,13 +5958,11 @@ discard block |
||
| 5552 | 5958 | {
|
| 5553 | 5959 | $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
| 5554 | 5960 | $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
| 5555 | - } |
|
| 5556 | - else |
|
| 5961 | + } else |
|
| 5557 | 5962 | {
|
| 5558 | 5963 | $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
| 5559 | 5964 | } |
| 5560 | - } |
|
| 5561 | - else |
|
| 5965 | + } else |
|
| 5562 | 5966 | {
|
| 5563 | 5967 | $sqlwhere.= ' WHERE 1=1'; |
| 5564 | 5968 | } |
@@ -5594,8 +5998,7 @@ discard block |
||
| 5594 | 5998 | {
|
| 5595 | 5999 | $labeltoshow.= $obj->$field_toshow.' '; |
| 5596 | 6000 | } |
| 5597 | - } |
|
| 5598 | - else |
|
| 6001 | + } else |
|
| 5599 | 6002 | {
|
| 5600 | 6003 | $labeltoshow=$obj->{$InfoFieldList[1]};
|
| 5601 | 6004 | } |
@@ -5608,25 +6011,25 @@ discard block |
||
| 5608 | 6011 | $translabel=$langs->trans($obj->$field_toshow); |
| 5609 | 6012 | if ($translabel!=$obj->$field_toshow) {
|
| 5610 | 6013 | $labeltoshow=dol_trunc($translabel,18).' '; |
| 5611 | - }else {
|
|
| 6014 | + } else {
|
|
| 5612 | 6015 | $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
| 5613 | 6016 | } |
| 5614 | 6017 | } |
| 5615 | 6018 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
| 5616 | - } |
|
| 5617 | - else |
|
| 6019 | + } else |
|
| 5618 | 6020 | {
|
| 5619 | 6021 | if (! $notrans) |
| 5620 | 6022 | {
|
| 5621 | 6023 | $translabel=$langs->trans($obj->{$InfoFieldList[1]});
|
| 5622 | 6024 | if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
| 5623 | 6025 | $labeltoshow=dol_trunc($translabel,18); |
| 5624 | - } |
|
| 5625 | - else {
|
|
| 6026 | + } else {
|
|
| 5626 | 6027 | $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18);
|
| 5627 | 6028 | } |
| 5628 | 6029 | } |
| 5629 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 6030 | + if (empty($labeltoshow)) { |
|
| 6031 | + $labeltoshow='(not defined)'; |
|
| 6032 | + } |
|
| 5630 | 6033 | if ($value==$obj->rowid) |
| 5631 | 6034 | {
|
| 5632 | 6035 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
@@ -5646,19 +6049,16 @@ discard block |
||
| 5646 | 6049 | $i++; |
| 5647 | 6050 | } |
| 5648 | 6051 | $this->db->free($resql); |
| 5649 | - } |
|
| 5650 | - else {
|
|
| 6052 | + } else {
|
|
| 5651 | 6053 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 5652 | 6054 | } |
| 5653 | 6055 | } |
| 5654 | 6056 | $out.='</select>'; |
| 5655 | - } |
|
| 5656 | - elseif ($type == 'checkbox') |
|
| 6057 | + } elseif ($type == 'checkbox') |
|
| 5657 | 6058 | {
|
| 5658 | 6059 | $value_arr=explode(',',$value);
|
| 5659 | 6060 | $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
| 5660 | - } |
|
| 5661 | - elseif ($type == 'radio') |
|
| 6061 | + } elseif ($type == 'radio') |
|
| 5662 | 6062 | {
|
| 5663 | 6063 | $out=''; |
| 5664 | 6064 | foreach ($param['options'] as $keyopt => $val) |
@@ -5669,13 +6069,11 @@ discard block |
||
| 5669 | 6069 | $out.= ($value==$keyopt?'checked':''); |
| 5670 | 6070 | $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
| 5671 | 6071 | } |
| 5672 | - } |
|
| 5673 | - elseif ($type == 'chkbxlst') |
|
| 6072 | + } elseif ($type == 'chkbxlst') |
|
| 5674 | 6073 | {
|
| 5675 | 6074 | if (is_array($value)) {
|
| 5676 | 6075 | $value_arr = $value; |
| 5677 | - } |
|
| 5678 | - else {
|
|
| 6076 | + } else {
|
|
| 5679 | 6077 | $value_arr = explode(',', $value);
|
| 5680 | 6078 | } |
| 5681 | 6079 | |
@@ -5790,8 +6188,9 @@ discard block |
||
| 5790 | 6188 | $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18);
|
| 5791 | 6189 | } |
| 5792 | 6190 | } |
| 5793 | - if (empty($labeltoshow)) |
|
| 5794 | - $labeltoshow = '(not defined)'; |
|
| 6191 | + if (empty($labeltoshow)) { |
|
| 6192 | + $labeltoshow = '(not defined)'; |
|
| 6193 | + } |
|
| 5795 | 6194 | |
| 5796 | 6195 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) {
|
| 5797 | 6196 | $data[$obj->rowid]=$labeltoshow; |
@@ -5813,26 +6212,26 @@ discard block |
||
| 5813 | 6212 | print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
| 5814 | 6213 | } |
| 5815 | 6214 | } |
| 5816 | - } |
|
| 5817 | - elseif ($type == 'link') |
|
| 6215 | + } elseif ($type == 'link') |
|
| 5818 | 6216 | {
|
| 5819 | 6217 | $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
| 5820 | 6218 | $showempty=(($required && $default != '')?0:1); |
| 5821 | 6219 | $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
| 5822 | 6220 | if (Globals::$conf->global->MAIN_FEATURES_LEVEL >= 2) {
|
| 5823 | 6221 | list($class,$classfile)=explode(':',$param_list[0]);
|
| 5824 | - if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 5825 | - else $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 6222 | + if (file_exists(dol_buildpath(dirname(dirname($classfile)).'/card.php'))) { |
|
| 6223 | + $url_path=dol_buildpath(dirname(dirname($classfile)).'/card.php',1); |
|
| 6224 | + } else { |
|
| 6225 | + $url_path=dol_buildpath(dirname(dirname($classfile)).'/'.$class.'_card.php',1); |
|
| 6226 | + } |
|
| 5826 | 6227 | $out.='<a class="butActionNew" href="'.$url_path.'?action=create&backtopage='.$_SERVER['PHP_SELF'].'"><span class="fa fa-plus-circle valignmiddle"></span></a>'; |
| 5827 | 6228 | // TODO Add Javascript code to add input fields contents to new elements urls |
| 5828 | 6229 | } |
| 5829 | - } |
|
| 5830 | - elseif ($type == 'password') |
|
| 6230 | + } elseif ($type == 'password') |
|
| 5831 | 6231 | {
|
| 5832 | 6232 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 5833 | 6233 | $out='<input type="'.($keyprefix=='search_'?'text':'password').'" class="flat '.$morecss.'" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'>'; |
| 5834 | - } |
|
| 5835 | - elseif ($type == 'array') |
|
| 6234 | + } elseif ($type == 'array') |
|
| 5836 | 6235 | {
|
| 5837 | 6236 | $newval = $val; |
| 5838 | 6237 | $newval['type'] = 'varchar(256)'; |
@@ -5910,17 +6309,25 @@ discard block |
||
| 5910 | 6309 | {
|
| 5911 | 6310 | $type = 'varchar'; // convert varchar(xx) int varchar |
| 5912 | 6311 | $size = $reg[1]; |
| 5913 | - } |
|
| 5914 | - elseif (preg_match('/varchar/', $type)) $type = 'varchar'; // convert varchar(xx) int varchar
|
|
| 5915 | - if (is_array($val['arrayofkeyval'])) $type='select'; |
|
| 5916 | - if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) $type='link';
|
|
| 6312 | + } elseif (preg_match('/varchar/', $type)) { |
|
| 6313 | + $type = 'varchar'; |
|
| 6314 | + } |
|
| 6315 | + // convert varchar(xx) int varchar |
|
| 6316 | + if (is_array($val['arrayofkeyval'])) { |
|
| 6317 | + $type='select'; |
|
| 6318 | + } |
|
| 6319 | + if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg)) { |
|
| 6320 | + $type='link'; |
|
| 6321 | + } |
|
| 5917 | 6322 | |
| 5918 | 6323 | $default=$val['default']; |
| 5919 | 6324 | $computed=$val['computed']; |
| 5920 | 6325 | $unique=$val['unique']; |
| 5921 | 6326 | $required=$val['required']; |
| 5922 | 6327 | $param=$val['param']; |
| 5923 | - if (is_array($val['arrayofkeyval'])) $param['options'] = $val['arrayofkeyval']; |
|
| 6328 | + if (is_array($val['arrayofkeyval'])) { |
|
| 6329 | + $param['options'] = $val['arrayofkeyval']; |
|
| 6330 | + } |
|
| 5924 | 6331 | if (preg_match('/^integer:(.*):(.*)/i', $val['type'], $reg))
|
| 5925 | 6332 | {
|
| 5926 | 6333 | $type='link'; |
@@ -5931,7 +6338,9 @@ discard block |
||
| 5931 | 6338 | $help=$val['help']; |
| 5932 | 6339 | $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) |
| 5933 | 6340 | |
| 5934 | - if ($hidden) return ''; |
|
| 6341 | + if ($hidden) { |
|
| 6342 | + return ''; |
|
| 6343 | + } |
|
| 5935 | 6344 | |
| 5936 | 6345 | // If field is a computed field, value must become result of compute |
| 5937 | 6346 | if ($computed) |
@@ -5947,36 +6356,29 @@ discard block |
||
| 5947 | 6356 | {
|
| 5948 | 6357 | //$showsize=10; |
| 5949 | 6358 | $showsize = 'minwidth100imp'; |
| 5950 | - } |
|
| 5951 | - elseif ($type == 'datetime') |
|
| 6359 | + } elseif ($type == 'datetime') |
|
| 5952 | 6360 | {
|
| 5953 | 6361 | //$showsize=19; |
| 5954 | 6362 | $showsize = 'minwidth200imp'; |
| 5955 | - } |
|
| 5956 | - elseif (in_array($type,array('int','double','price')))
|
|
| 6363 | + } elseif (in_array($type,array('int','double','price')))
|
|
| 5957 | 6364 | {
|
| 5958 | 6365 | //$showsize=10; |
| 5959 | 6366 | $showsize = 'maxwidth75'; |
| 5960 | - } |
|
| 5961 | - elseif ($type == 'url') |
|
| 6367 | + } elseif ($type == 'url') |
|
| 5962 | 6368 | {
|
| 5963 | 6369 | $showsize='minwidth400'; |
| 5964 | - } |
|
| 5965 | - elseif ($type == 'boolean') |
|
| 6370 | + } elseif ($type == 'boolean') |
|
| 5966 | 6371 | {
|
| 5967 | 6372 | $showsize=''; |
| 5968 | - } |
|
| 5969 | - else |
|
| 6373 | + } else |
|
| 5970 | 6374 | {
|
| 5971 | 6375 | if (round($size) < 12) |
| 5972 | 6376 | {
|
| 5973 | 6377 | $showsize = 'minwidth100'; |
| 5974 | - } |
|
| 5975 | - else if (round($size) <= 48) |
|
| 6378 | + } else if (round($size) <= 48) |
|
| 5976 | 6379 | {
|
| 5977 | 6380 | $showsize = 'minwidth200'; |
| 5978 | - } |
|
| 5979 | - else |
|
| 6381 | + } else |
|
| 5980 | 6382 | {
|
| 5981 | 6383 | //$showsize=48; |
| 5982 | 6384 | $showsize = 'minwidth400'; |
@@ -5985,59 +6387,52 @@ discard block |
||
| 5985 | 6387 | } |
| 5986 | 6388 | |
| 5987 | 6389 | // Format output value differently according to properties of field |
| 5988 | - if ($key == 'ref' && method_exists($this, 'getNomUrl')) $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 5989 | - elseif ($key == 'status' && method_exists($this, 'getLibStatut')) $value=$this->getLibStatut(3); |
|
| 5990 | - elseif ($type == 'date') |
|
| 6390 | + if ($key == 'ref' && method_exists($this, 'getNomUrl')) { |
|
| 6391 | + $value=$this->getNomUrl(1, '', 0, '', 1); |
|
| 6392 | + } elseif ($key == 'status' && method_exists($this, 'getLibStatut')) { |
|
| 6393 | + $value=$this->getLibStatut(3); |
|
| 6394 | + } elseif ($type == 'date') |
|
| 5991 | 6395 | {
|
| 5992 | 6396 | if(! empty($value)) {
|
| 5993 | 6397 | $value=dol_print_date($value,'day'); |
| 5994 | 6398 | } else {
|
| 5995 | 6399 | $value=''; |
| 5996 | 6400 | } |
| 5997 | - } |
|
| 5998 | - elseif ($type == 'datetime') |
|
| 6401 | + } elseif ($type == 'datetime') |
|
| 5999 | 6402 | {
|
| 6000 | 6403 | if(! empty($value)) {
|
| 6001 | 6404 | $value=dol_print_date($value,'dayhour'); |
| 6002 | 6405 | } else {
|
| 6003 | 6406 | $value=''; |
| 6004 | 6407 | } |
| 6005 | - } |
|
| 6006 | - elseif ($type == 'double') |
|
| 6408 | + } elseif ($type == 'double') |
|
| 6007 | 6409 | {
|
| 6008 | 6410 | if (!empty($value)) {
|
| 6009 | 6411 | $value=price($value); |
| 6010 | 6412 | } |
| 6011 | - } |
|
| 6012 | - elseif ($type == 'boolean') |
|
| 6413 | + } elseif ($type == 'boolean') |
|
| 6013 | 6414 | {
|
| 6014 | 6415 | $checked=''; |
| 6015 | 6416 | if (!empty($value)) {
|
| 6016 | 6417 | $checked=' checked '; |
| 6017 | 6418 | } |
| 6018 | 6419 | $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
| 6019 | - } |
|
| 6020 | - elseif ($type == 'mail') |
|
| 6420 | + } elseif ($type == 'mail') |
|
| 6021 | 6421 | {
|
| 6022 | 6422 | $value=dol_print_email($value,0,0,0,64,1,1); |
| 6023 | - } |
|
| 6024 | - elseif ($type == 'url') |
|
| 6423 | + } elseif ($type == 'url') |
|
| 6025 | 6424 | {
|
| 6026 | 6425 | $value=dol_print_url($value,'_blank',32,1); |
| 6027 | - } |
|
| 6028 | - elseif ($type == 'phone') |
|
| 6426 | + } elseif ($type == 'phone') |
|
| 6029 | 6427 | {
|
| 6030 | 6428 | $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
| 6031 | - } |
|
| 6032 | - elseif ($type == 'price') |
|
| 6429 | + } elseif ($type == 'price') |
|
| 6033 | 6430 | {
|
| 6034 | 6431 | $value = price($value, 0, $langs, 0, 0, -1, Globals::$conf->currency); |
| 6035 | - } |
|
| 6036 | - elseif ($type == 'select') |
|
| 6432 | + } elseif ($type == 'select') |
|
| 6037 | 6433 | {
|
| 6038 | 6434 | $value=$param['options'][$value]; |
| 6039 | - } |
|
| 6040 | - elseif ($type == 'sellist') |
|
| 6435 | + } elseif ($type == 'sellist') |
|
| 6041 | 6436 | {
|
| 6042 | 6437 | $param_list=array_keys($param['options']); |
| 6043 | 6438 | $InfoFieldList = explode(":", $param_list[0]);
|
@@ -6067,7 +6462,7 @@ discard block |
||
| 6067 | 6462 | $sql.= " WHERE ".$selectkey."=0"; |
| 6068 | 6463 | } elseif ($selectkey=='rowid') {
|
| 6069 | 6464 | $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
| 6070 | - }else {
|
|
| 6465 | + } else {
|
|
| 6071 | 6466 | $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 6072 | 6467 | } |
| 6073 | 6468 | |
@@ -6094,12 +6489,11 @@ discard block |
||
| 6094 | 6489 | } |
| 6095 | 6490 | if ($translabel!=$field_toshow) {
|
| 6096 | 6491 | $value.=dol_trunc($translabel,18).' '; |
| 6097 | - }else {
|
|
| 6492 | + } else {
|
|
| 6098 | 6493 | $value.=$obj->$field_toshow.' '; |
| 6099 | 6494 | } |
| 6100 | 6495 | } |
| 6101 | - } |
|
| 6102 | - else |
|
| 6496 | + } else |
|
| 6103 | 6497 | {
|
| 6104 | 6498 | $translabel=''; |
| 6105 | 6499 | if (!empty($obj->{$InfoFieldList[1]})) {
|
@@ -6107,18 +6501,17 @@ discard block |
||
| 6107 | 6501 | } |
| 6108 | 6502 | if ($translabel!=$obj->{$InfoFieldList[1]}) {
|
| 6109 | 6503 | $value=dol_trunc($translabel,18); |
| 6110 | - }else {
|
|
| 6504 | + } else {
|
|
| 6111 | 6505 | $value=$obj->{$InfoFieldList[1]};
|
| 6112 | 6506 | } |
| 6113 | 6507 | } |
| 6114 | - } |
|
| 6115 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6116 | - } |
|
| 6117 | - elseif ($type == 'radio') |
|
| 6508 | + } else { |
|
| 6509 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 6510 | + } |
|
| 6511 | + } elseif ($type == 'radio') |
|
| 6118 | 6512 | {
|
| 6119 | 6513 | $value=$param['options'][$value]; |
| 6120 | - } |
|
| 6121 | - elseif ($type == 'checkbox') |
|
| 6514 | + } elseif ($type == 'checkbox') |
|
| 6122 | 6515 | {
|
| 6123 | 6516 | $value_arr=explode(',',$value);
|
| 6124 | 6517 | $value=''; |
@@ -6129,8 +6522,7 @@ discard block |
||
| 6129 | 6522 | } |
| 6130 | 6523 | $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>';
|
| 6131 | 6524 | } |
| 6132 | - } |
|
| 6133 | - elseif ($type == 'chkbxlst') |
|
| 6525 | + } elseif ($type == 'chkbxlst') |
|
| 6134 | 6526 | {
|
| 6135 | 6527 | $value_arr = explode(',', $value);
|
| 6136 | 6528 | |
@@ -6198,8 +6590,7 @@ discard block |
||
| 6198 | 6590 | } else {
|
| 6199 | 6591 | dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
| 6200 | 6592 | } |
| 6201 | - } |
|
| 6202 | - elseif ($type == 'link') |
|
| 6593 | + } elseif ($type == 'link') |
|
| 6203 | 6594 | {
|
| 6204 | 6595 | $out=''; |
| 6205 | 6596 | |
@@ -6221,24 +6612,21 @@ discard block |
||
| 6221 | 6612 | $object->fetch($value); |
| 6222 | 6613 | $value=$object->getNomUrl($getnomurlparam); |
| 6223 | 6614 | } |
| 6224 | - } |
|
| 6225 | - else |
|
| 6615 | + } else |
|
| 6226 | 6616 | {
|
| 6227 | 6617 | dol_syslog('Error bad setup of extrafield', LOG_WARNING);
|
| 6228 | 6618 | return 'Error bad setup of extrafield'; |
| 6229 | 6619 | } |
| 6230 | - } |
|
| 6231 | - else $value=''; |
|
| 6232 | - } |
|
| 6233 | - elseif ($type == 'text' || $type == 'html') |
|
| 6620 | + } else { |
|
| 6621 | + $value=''; |
|
| 6622 | + } |
|
| 6623 | + } elseif ($type == 'text' || $type == 'html') |
|
| 6234 | 6624 | {
|
| 6235 | 6625 | $value=dol_htmlentitiesbr($value); |
| 6236 | - } |
|
| 6237 | - elseif ($type == 'password') |
|
| 6626 | + } elseif ($type == 'password') |
|
| 6238 | 6627 | {
|
| 6239 | 6628 | $value=preg_replace('/./i','*',$value);
|
| 6240 | - } |
|
| 6241 | - elseif ($type == 'array') |
|
| 6629 | + } elseif ($type == 'array') |
|
| 6242 | 6630 | {
|
| 6243 | 6631 | $value = implode('<br>', $value);
|
| 6244 | 6632 | } |
@@ -6265,7 +6653,9 @@ discard block |
||
| 6265 | 6653 | {
|
| 6266 | 6654 | global $db, $conf, $langs, $action, $form; |
| 6267 | 6655 | |
| 6268 | - if (! is_object($form)) $form=new Form($db); |
|
| 6656 | + if (! is_object($form)) { |
|
| 6657 | + $form=new Form($db); |
|
| 6658 | + } |
|
| 6269 | 6659 | |
| 6270 | 6660 | $out = ''; |
| 6271 | 6661 | |
@@ -6279,7 +6669,9 @@ discard block |
||
| 6279 | 6669 | foreach($extrafields->attributes[$this->table_element]['label'] as $key=>$label) |
| 6280 | 6670 | {
|
| 6281 | 6671 | // Show only the key field in params |
| 6282 | - if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) continue;
|
|
| 6672 | + if (is_array($params) && array_key_exists('onlykey',$params) && $key != $params['onlykey']) { |
|
| 6673 | + continue; |
|
| 6674 | + } |
|
| 6283 | 6675 | |
| 6284 | 6676 | $enabled = 1; |
| 6285 | 6677 | if ($enabled && isset($extrafields->attributes[$this->table_element]['list'][$key])) |
@@ -6293,11 +6685,18 @@ discard block |
||
| 6293 | 6685 | $perms = dol_eval($extrafields->attributes[$this->table_element]['perms'][$key], 1); |
| 6294 | 6686 | } |
| 6295 | 6687 | |
| 6296 | - if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) continue; // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6297 | - if (empty($perms)) continue; |
|
| 6688 | + if (($mode == 'create' || $mode == 'edit') && abs($enabled) != 1 && abs($enabled) != 3) { |
|
| 6689 | + continue; |
|
| 6690 | + } |
|
| 6691 | + // <> -1 and <> 1 and <> 3 = not visible on forms, only on list |
|
| 6692 | + if (empty($perms)) { |
|
| 6693 | + continue; |
|
| 6694 | + } |
|
| 6298 | 6695 | |
| 6299 | 6696 | // Load language if required |
| 6300 | - if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6697 | + if (! empty($extrafields->attributes[$this->table_element]['langfile'][$key])) { |
|
| 6698 | + $langs->load($extrafields->attributes[$this->table_element]['langfile'][$key]); |
|
| 6699 | + } |
|
| 6301 | 6700 | |
| 6302 | 6701 | $colspan='3'; |
| 6303 | 6702 | if (is_array($params) && count($params)>0) {
|
@@ -6331,8 +6730,7 @@ discard block |
||
| 6331 | 6730 | if ($extrafields->attributes[$this->table_element]['type'][$key] == 'separate') |
| 6332 | 6731 | {
|
| 6333 | 6732 | $out .= $extrafields->showSeparator($key, $this); |
| 6334 | - } |
|
| 6335 | - else |
|
| 6733 | + } else |
|
| 6336 | 6734 | {
|
| 6337 | 6735 | $csstyle=''; |
| 6338 | 6736 | $class=(!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); |
@@ -6363,9 +6761,11 @@ discard block |
||
| 6363 | 6761 | if (in_array($extrafields->attributes[$this->table_element]['type'][$key],array('date','datetime')))
|
| 6364 | 6762 | {
|
| 6365 | 6763 | $datenotinstring = $this->array_options['options_' . $key]; |
| 6366 | - if (! is_numeric($this->array_options['options_' . $key])) // For backward compatibility |
|
| 6764 | + if (! is_numeric($this->array_options['options_' . $key])) { |
|
| 6765 | + // For backward compatibility |
|
| 6367 | 6766 | {
|
| 6368 | - $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6767 | + $datenotinstring = $this->db->jdate($datenotinstring); |
|
| 6768 | + } |
|
| 6369 | 6769 | } |
| 6370 | 6770 | $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; |
| 6371 | 6771 | } |
@@ -6378,11 +6778,18 @@ discard block |
||
| 6378 | 6778 | $labeltoshow = $langs->trans($label); |
| 6379 | 6779 | |
| 6380 | 6780 | $out .= '<td class="titlefield'; |
| 6381 | - if (GETPOST('action','none') == 'create') $out.='create';
|
|
| 6382 | - if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) $out .= ' fieldrequired'; |
|
| 6781 | + if (GETPOST('action','none') == 'create') { |
|
| 6782 | + $out.='create'; |
|
| 6783 | + } |
|
| 6784 | + if ($mode != 'view' && ! empty($extrafields->attributes[$this->table_element]['required'][$key])) { |
|
| 6785 | + $out .= ' fieldrequired'; |
|
| 6786 | + } |
|
| 6383 | 6787 | $out .= '">'; |
| 6384 | - if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6385 | - else $out .= $labeltoshow; |
|
| 6788 | + if (! empty($extrafields->attributes[$object->table_element]['help'][$key])) { |
|
| 6789 | + $out .= $form->textwithpicto($labeltoshow, $extrafields->attributes[$object->table_element]['help'][$key]); |
|
| 6790 | + } else { |
|
| 6791 | + $out .= $labeltoshow; |
|
| 6792 | + } |
|
| 6386 | 6793 | $out .= '</td>'; |
| 6387 | 6794 | |
| 6388 | 6795 | $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; |
@@ -6399,9 +6806,11 @@ discard block |
||
| 6399 | 6806 | |
| 6400 | 6807 | $out .= '</td>'; |
| 6401 | 6808 | |
| 6402 | - if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) |
|
| 6403 | - $out .= '</tr>'; |
|
| 6404 | - else $out .= '</tr>'; |
|
| 6809 | + if (!empty(Globals::$conf->global->MAIN_EXTRAFIELDS_USE_TWO_COLUMS) && (($e % 2) == 1)) { |
|
| 6810 | + $out .= '</tr>'; |
|
| 6811 | + } else { |
|
| 6812 | + $out .= '</tr>'; |
|
| 6813 | + } |
|
| 6405 | 6814 | $e++; |
| 6406 | 6815 | } |
| 6407 | 6816 | } |
@@ -6453,7 +6862,9 @@ discard block |
||
| 6453 | 6862 | global $user; |
| 6454 | 6863 | |
| 6455 | 6864 | $element = $this->element; |
| 6456 | - if ($element == 'facturerec') $element='facture'; |
|
| 6865 | + if ($element == 'facturerec') { |
|
| 6866 | + $element='facture'; |
|
| 6867 | + } |
|
| 6457 | 6868 | |
| 6458 | 6869 | return $user->rights->{$element};
|
| 6459 | 6870 | } |
@@ -6478,7 +6889,10 @@ discard block |
||
| 6478 | 6889 | |
| 6479 | 6890 | if (! $db->query($sql)) |
| 6480 | 6891 | {
|
| 6481 | - 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. |
|
| 6892 | + if ($ignoreerrors) { |
|
| 6893 | + return true; |
|
| 6894 | + } |
|
| 6895 | + // 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. |
|
| 6482 | 6896 | //$this->errors = $db->lasterror(); |
| 6483 | 6897 | return false; |
| 6484 | 6898 | } |
@@ -6507,8 +6921,7 @@ discard block |
||
| 6507 | 6921 | |
| 6508 | 6922 | if (($unitPrice > 0) && (isset(Globals::$conf->global->ForceBuyingPriceIfNull) && Globals::$conf->global->ForceBuyingPriceIfNull == 1)) { // In most cases, test here is false{
|
| 6509 | 6923 | $buyPrice = $unitPrice * (1 - $discountPercent / 100); |
| 6510 | - } |
|
| 6511 | - else |
|
| 6924 | + } else |
|
| 6512 | 6925 | {
|
| 6513 | 6926 | // Get cost price for margin calculation |
| 6514 | 6927 | if (! empty($fk_product)) |
@@ -6525,13 +6938,11 @@ discard block |
||
| 6525 | 6938 | if ($product->cost_price > 0) |
| 6526 | 6939 | {
|
| 6527 | 6940 | $buyPrice = $product->cost_price; |
| 6528 | - } |
|
| 6529 | - else if ($product->pmp > 0) |
|
| 6941 | + } else if ($product->pmp > 0) |
|
| 6530 | 6942 | {
|
| 6531 | 6943 | $buyPrice = $product->pmp; |
| 6532 | 6944 | } |
| 6533 | - } |
|
| 6534 | - else if (isset(Globals::$conf->global->MARGIN_TYPE) && Globals::$conf->global->MARGIN_TYPE == 'pmp') {
|
|
| 6945 | + } else if (isset(Globals::$conf->global->MARGIN_TYPE) && Globals::$conf->global->MARGIN_TYPE == 'pmp') {
|
|
| 6535 | 6946 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
| 6536 | 6947 | $product = new Product($this->db); |
| 6537 | 6948 | $result = $product->fetch($fk_product); |
@@ -6552,8 +6963,7 @@ discard block |
||
| 6552 | 6963 | if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) |
| 6553 | 6964 | {
|
| 6554 | 6965 | $buyPrice = $productFournisseur->fourn_unitprice; |
| 6555 | - } |
|
| 6556 | - else if ($result < 0) |
|
| 6966 | + } else if ($result < 0) |
|
| 6557 | 6967 | {
|
| 6558 | 6968 | $this->errors[] = $productFournisseur->error; |
| 6559 | 6969 | return -2; |
@@ -6599,8 +7009,7 @@ discard block |
||
| 6599 | 7009 | {
|
| 6600 | 7010 | $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
| 6601 | 7011 | $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->track_id.'/'; |
| 6602 | - } |
|
| 6603 | - else |
|
| 7012 | + } else |
|
| 6604 | 7013 | {
|
| 6605 | 7014 | $dir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
| 6606 | 7015 | $pdir .= get_exdir(0, 0, 0, 0, $this, $modulepart).$this->ref.'/'; |
@@ -6662,19 +7071,26 @@ discard block |
||
| 6662 | 7071 | |
| 6663 | 7072 | // Find name of thumb file |
| 6664 | 7073 | $photo_vignette=basename(getImageFileNameForSize($dir.$file, '_small')); |
| 6665 | - if (! dol_is_file($dirthumb.$photo_vignette)) $photo_vignette=''; |
|
| 7074 | + if (! dol_is_file($dirthumb.$photo_vignette)) { |
|
| 7075 | + $photo_vignette=''; |
|
| 7076 | + } |
|
| 6666 | 7077 | |
| 6667 | 7078 | // Get filesize of original file |
| 6668 | 7079 | $imgarray=dol_getImageSize($dir.$photo); |
| 6669 | 7080 | |
| 6670 | 7081 | if ($nbbyrow > 0) |
| 6671 | 7082 | {
|
| 6672 | - if ($nbphoto == 1) $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7083 | + if ($nbphoto == 1) { |
|
| 7084 | + $return.= '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; |
|
| 7085 | + } |
|
| 6673 | 7086 | |
| 6674 | - if ($nbphoto % $nbbyrow == 1) $return.= '<tr align=center valign=middle border=1>'; |
|
| 7087 | + if ($nbphoto % $nbbyrow == 1) { |
|
| 7088 | + $return.= '<tr align=center valign=middle border=1>'; |
|
| 7089 | + } |
|
| 6675 | 7090 | $return.= '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; |
| 6676 | - } |
|
| 6677 | - else if ($nbbyrow < 0) $return .= '<div class="inline-block">'; |
|
| 7091 | + } else if ($nbbyrow < 0) { |
|
| 7092 | + $return .= '<div class="inline-block">'; |
|
| 7093 | + } |
|
| 6678 | 7094 | |
| 6679 | 7095 | $return.= "\n"; |
| 6680 | 7096 | |
@@ -6682,15 +7098,20 @@ discard block |
||
| 6682 | 7098 | if (empty($nolink)) |
| 6683 | 7099 | {
|
| 6684 | 7100 | $urladvanced=getAdvancedPreviewUrl($modulepart, $relativefile, 0, 'entity='.$this->entity); |
| 6685 | - if ($urladvanced) $return.='<a href="'.$urladvanced.'">'; |
|
| 6686 | - else $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 7101 | + if ($urladvanced) { |
|
| 7102 | + $return.='<a href="'.$urladvanced.'">'; |
|
| 7103 | + } else { |
|
| 7104 | + $return.= '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'" class="aphoto" target="_blank">'; |
|
| 7105 | + } |
|
| 6687 | 7106 | } |
| 6688 | 7107 | |
| 6689 | 7108 | // Show image (width height=$maxHeight) |
| 6690 | 7109 | // Si fichier vignette disponible et image source trop grande, on utilise la vignette, sinon on utilise photo origine |
| 6691 | 7110 | $alt=$langs->transnoentitiesnoconv('File').': '.$relativefile;
|
| 6692 | 7111 | $alt.=' - '.$langs->transnoentitiesnoconv('Size').': '.$imgarray['width'].'x'.$imgarray['height'];
|
| 6693 | - if ($notitle) $alt=''; |
|
| 7112 | + if ($notitle) { |
|
| 7113 | + $alt=''; |
|
| 7114 | + } |
|
| 6694 | 7115 | |
| 6695 | 7116 | if ($usesharelink) |
| 6696 | 7117 | {
|
@@ -6700,35 +7121,35 @@ discard block |
||
| 6700 | 7121 | {
|
| 6701 | 7122 | $return.= '<!-- Show original file (thumb not yet available with shared links) -->'; |
| 6702 | 7123 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6703 | - } |
|
| 6704 | - else {
|
|
| 7124 | + } else {
|
|
| 6705 | 7125 | $return.= '<!-- Show original file -->'; |
| 6706 | 7126 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?hashp='.urlencode($val['share']).'" title="'.dol_escape_htmltag($alt).'">'; |
| 6707 | 7127 | } |
| 6708 | - } |
|
| 6709 | - else |
|
| 7128 | + } else |
|
| 6710 | 7129 | {
|
| 6711 | 7130 | $return.= '<!-- Show nophoto file (because file is not shared) -->'; |
| 6712 | 7131 | $return.= '<img class="photo photowithmargin" border="0" height="'.$maxHeight.'" src="'.DOL_URL_ROOT.'/public/theme/common/nophoto.png" title="'.dol_escape_htmltag($alt).'">'; |
| 6713 | 7132 | } |
| 6714 | - } |
|
| 6715 | - else |
|
| 7133 | + } else |
|
| 6716 | 7134 | {
|
| 6717 | 7135 | if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) |
| 6718 | 7136 | {
|
| 6719 | 7137 | $return.= '<!-- Show thumb -->'; |
| 6720 | 7138 | $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).'">'; |
| 6721 | - } |
|
| 6722 | - else {
|
|
| 7139 | + } else {
|
|
| 6723 | 7140 | $return.= '<!-- Show original file -->'; |
| 6724 | 7141 | $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).'">'; |
| 6725 | 7142 | } |
| 6726 | 7143 | } |
| 6727 | 7144 | |
| 6728 | - if (empty($nolink)) $return.= '</a>'; |
|
| 7145 | + if (empty($nolink)) { |
|
| 7146 | + $return.= '</a>'; |
|
| 7147 | + } |
|
| 6729 | 7148 | $return.="\n"; |
| 6730 | 7149 | |
| 6731 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 7150 | + if ($showfilename) { |
|
| 7151 | + $return.= '<br>'.$viewfilename; |
|
| 7152 | + } |
|
| 6732 | 7153 | if ($showaction) |
| 6733 | 7154 | {
|
| 6734 | 7155 | $return.= '<br>'; |
@@ -6753,15 +7174,20 @@ discard block |
||
| 6753 | 7174 | if ($nbbyrow > 0) |
| 6754 | 7175 | {
|
| 6755 | 7176 | $return.= '</td>'; |
| 6756 | - if (($nbphoto % $nbbyrow) == 0) $return.= '</tr>'; |
|
| 6757 | - } |
|
| 6758 | - else if ($nbbyrow < 0) $return.='</div>'; |
|
| 7177 | + if (($nbphoto % $nbbyrow) == 0) { |
|
| 7178 | + $return.= '</tr>'; |
|
| 7179 | + } |
|
| 7180 | + } else if ($nbbyrow < 0) { |
|
| 7181 | + $return.='</div>'; |
|
| 7182 | + } |
|
| 6759 | 7183 | } |
| 6760 | 7184 | |
| 6761 | 7185 | if (empty($size)) { // Format origine
|
| 6762 | 7186 | $return.= '<img class="photo photowithmargin" border="0" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.$this->entity.'&file='.urlencode($pdir.$photo).'">'; |
| 6763 | 7187 | |
| 6764 | - if ($showfilename) $return.= '<br>'.$viewfilename; |
|
| 7188 | + if ($showfilename) { |
|
| 7189 | + $return.= '<br>'.$viewfilename; |
|
| 7190 | + } |
|
| 6765 | 7191 | if ($showaction) |
| 6766 | 7192 | {
|
| 6767 | 7193 | // Special case for product |
@@ -6778,7 +7204,9 @@ discard block |
||
| 6778 | 7204 | } |
| 6779 | 7205 | |
| 6780 | 7206 | // On continue ou on arrete de boucler ? |
| 6781 | - if ($nbmax && $nbphoto >= $nbmax) break; |
|
| 7207 | + if ($nbmax && $nbphoto >= $nbmax) { |
|
| 7208 | + break; |
|
| 7209 | + } |
|
| 6782 | 7210 | } |
| 6783 | 7211 | } |
| 6784 | 7212 | |
@@ -6793,7 +7221,9 @@ discard block |
||
| 6793 | 7221 | $nbphoto++; |
| 6794 | 7222 | } |
| 6795 | 7223 | |
| 6796 | - if ($nbphoto) $return.= '</table>'; |
|
| 7224 | + if ($nbphoto) { |
|
| 7225 | + $return.= '</table>'; |
|
| 7226 | + } |
|
| 6797 | 7227 | } |
| 6798 | 7228 | } |
| 6799 | 7229 | } |
@@ -6814,10 +7244,14 @@ discard block |
||
| 6814 | 7244 | {
|
| 6815 | 7245 | if(is_array($info)) |
| 6816 | 7246 | {
|
| 6817 | - if(isset($info['type']) && $info['type']=='array') return true; |
|
| 6818 | - else return false; |
|
| 6819 | - } |
|
| 6820 | - else return false; |
|
| 7247 | + if(isset($info['type']) && $info['type']=='array') { |
|
| 7248 | + return true; |
|
| 7249 | + } else { |
|
| 7250 | + return false; |
|
| 7251 | + } |
|
| 7252 | + } else { |
|
| 7253 | + return false; |
|
| 7254 | + } |
|
| 6821 | 7255 | } |
| 6822 | 7256 | |
| 6823 | 7257 | /** |
@@ -6830,10 +7264,14 @@ discard block |
||
| 6830 | 7264 | {
|
| 6831 | 7265 | if(is_array($info)) |
| 6832 | 7266 | {
|
| 6833 | - if(isset($info['type']) && $info['type']=='null') return true; |
|
| 6834 | - else return false; |
|
| 6835 | - } |
|
| 6836 | - else return false; |
|
| 7267 | + if(isset($info['type']) && $info['type']=='null') { |
|
| 7268 | + return true; |
|
| 7269 | + } else { |
|
| 7270 | + return false; |
|
| 7271 | + } |
|
| 7272 | + } else { |
|
| 7273 | + return false; |
|
| 7274 | + } |
|
| 6837 | 7275 | } |
| 6838 | 7276 | |
| 6839 | 7277 | /** |
@@ -6844,8 +7282,11 @@ discard block |
||
| 6844 | 7282 | */ |
| 6845 | 7283 | public function isDate($info) |
| 6846 | 7284 | {
|
| 6847 | - if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) return true; |
|
| 6848 | - else return false; |
|
| 7285 | + if(isset($info['type']) && ($info['type']=='date' || $info['type']=='datetime' || $info['type']=='timestamp')) { |
|
| 7286 | + return true; |
|
| 7287 | + } else { |
|
| 7288 | + return false; |
|
| 7289 | + } |
|
| 6849 | 7290 | } |
| 6850 | 7291 | |
| 6851 | 7292 | /** |
@@ -6858,10 +7299,14 @@ discard block |
||
| 6858 | 7299 | {
|
| 6859 | 7300 | if(is_array($info)) |
| 6860 | 7301 | {
|
| 6861 | - if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) return true;
|
|
| 6862 | - else return false; |
|
| 6863 | - } |
|
| 6864 | - else return false; |
|
| 7302 | + if(isset($info['type']) && ($info['type']=='int' || preg_match('/^integer/i',$info['type']) ) ) { |
|
| 7303 | + return true; |
|
| 7304 | + } else { |
|
| 7305 | + return false; |
|
| 7306 | + } |
|
| 7307 | + } else { |
|
| 7308 | + return false; |
|
| 7309 | + } |
|
| 6865 | 7310 | } |
| 6866 | 7311 | |
| 6867 | 7312 | /** |
@@ -6874,10 +7319,14 @@ discard block |
||
| 6874 | 7319 | {
|
| 6875 | 7320 | if(is_array($info)) |
| 6876 | 7321 | {
|
| 6877 | - if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) return true;
|
|
| 6878 | - else return false; |
|
| 6879 | - } |
|
| 6880 | - else return false; |
|
| 7322 | + if (isset($info['type']) && (preg_match('/^(double|real)/i', $info['type']))) { |
|
| 7323 | + return true; |
|
| 7324 | + } else { |
|
| 7325 | + return false; |
|
| 7326 | + } |
|
| 7327 | + } else { |
|
| 7328 | + return false; |
|
| 7329 | + } |
|
| 6881 | 7330 | } |
| 6882 | 7331 | |
| 6883 | 7332 | /** |
@@ -6890,10 +7339,14 @@ discard block |
||
| 6890 | 7339 | {
|
| 6891 | 7340 | if(is_array($info)) |
| 6892 | 7341 | {
|
| 6893 | - if(isset($info['type']) && $info['type']=='text') return true; |
|
| 6894 | - else return false; |
|
| 6895 | - } |
|
| 6896 | - else return false; |
|
| 7342 | + if(isset($info['type']) && $info['type']=='text') { |
|
| 7343 | + return true; |
|
| 7344 | + } else { |
|
| 7345 | + return false; |
|
| 7346 | + } |
|
| 7347 | + } else { |
|
| 7348 | + return false; |
|
| 7349 | + } |
|
| 6897 | 7350 | } |
| 6898 | 7351 | |
| 6899 | 7352 | /** |
@@ -6906,10 +7359,14 @@ discard block |
||
| 6906 | 7359 | {
|
| 6907 | 7360 | if(is_array($info)) |
| 6908 | 7361 | {
|
| 6909 | - if(isset($info['index']) && $info['index']==true) return true; |
|
| 6910 | - else return false; |
|
| 6911 | - } |
|
| 6912 | - else return false; |
|
| 7362 | + if(isset($info['index']) && $info['index']==true) { |
|
| 7363 | + return true; |
|
| 7364 | + } else { |
|
| 7365 | + return false; |
|
| 7366 | + } |
|
| 7367 | + } else { |
|
| 7368 | + return false; |
|
| 7369 | + } |
|
| 6913 | 7370 | } |
| 6914 | 7371 | |
| 6915 | 7372 | /** |
@@ -6923,21 +7380,21 @@ discard block |
||
| 6923 | 7380 | global $conf; |
| 6924 | 7381 | |
| 6925 | 7382 | $queryarray=array(); |
| 6926 | - foreach ($this->fields as $field=>$info) // Loop on definition of fields |
|
| 7383 | + foreach ($this->fields as $field=>$info) { |
|
| 7384 | + // Loop on definition of fields |
|
| 6927 | 7385 | {
|
| 6928 | 7386 | // Depending on field type ('datetime', ...)
|
| 6929 | 7387 | if($this->isDate($info)) |
| 6930 | 7388 | {
|
| 6931 | 7389 | if(empty($this->{$field}))
|
| 6932 | 7390 | {
|
| 6933 | - $queryarray[$field] = null; |
|
| 6934 | - } |
|
| 6935 | - else |
|
| 7391 | + $queryarray[$field] = null; |
|
| 7392 | + } |
|
| 7393 | + } else |
|
| 6936 | 7394 | {
|
| 6937 | 7395 | $queryarray[$field] = $this->db->idate($this->{$field});
|
| 6938 | 7396 | } |
| 6939 | - } |
|
| 6940 | - else if($this->isArray($info)) |
|
| 7397 | + } else if($this->isArray($info)) |
|
| 6941 | 7398 | {
|
| 6942 | 7399 | if(! empty($this->{$field})) {
|
| 6943 | 7400 | if(! is_array($this->{$field})) {
|
@@ -6947,29 +7404,35 @@ discard block |
||
| 6947 | 7404 | } else {
|
| 6948 | 7405 | $queryarray[$field] = null; |
| 6949 | 7406 | } |
| 6950 | - } |
|
| 6951 | - else if($this->isInt($info)) |
|
| 7407 | + } else if($this->isInt($info)) |
|
| 6952 | 7408 | {
|
| 6953 | - if ($field == 'entity' && is_null($this->{$field}))
|
|
| 6954 | - $queryarray[$field] = Globals::$conf->entity; |
|
| 6955 | - else |
|
| 7409 | + if ($field == 'entity' && is_null($this->{$field})) { |
|
| 7410 | + $queryarray[$field] = Globals::$conf->entity; |
|
| 7411 | + } else |
|
| 6956 | 7412 | {
|
| 6957 | 7413 | $queryarray[$field] = (int) price2num($this->{$field});
|
| 6958 | - if (empty($queryarray[$field])) $queryarray[$field]=0; // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 7414 | + if (empty($queryarray[$field])) { |
|
| 7415 | + $queryarray[$field]=0; |
|
| 7416 | + } |
|
| 7417 | + // May be reset to null later if property 'notnull' is -1 for this field. |
|
| 6959 | 7418 | } |
| 6960 | - } |
|
| 6961 | - else if($this->isFloat($info)) |
|
| 7419 | + } else if($this->isFloat($info)) |
|
| 6962 | 7420 | {
|
| 6963 | 7421 | $queryarray[$field] = (double) price2num($this->{$field});
|
| 6964 | - if (empty($queryarray[$field])) $queryarray[$field]=0; |
|
| 6965 | - } |
|
| 6966 | - else |
|
| 7422 | + if (empty($queryarray[$field])) { |
|
| 7423 | + $queryarray[$field]=0; |
|
| 7424 | + } |
|
| 7425 | + } else |
|
| 6967 | 7426 | {
|
| 6968 | 7427 | $queryarray[$field] = $this->{$field};
|
| 6969 | 7428 | } |
| 6970 | 7429 | |
| 6971 | - if ($info['type'] == 'timestamp' && empty($queryarray[$field])) unset($queryarray[$field]); |
|
| 6972 | - if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) $queryarray[$field] = null; |
|
| 7430 | + if ($info['type'] == 'timestamp' && empty($queryarray[$field])) { |
|
| 7431 | + unset($queryarray[$field]); |
|
| 7432 | + } |
|
| 7433 | + if (! empty($info['notnull']) && $info['notnull'] == -1 && empty($queryarray[$field])) { |
|
| 7434 | + $queryarray[$field] = null; |
|
| 7435 | + } |
|
| 6973 | 7436 | } |
| 6974 | 7437 | |
| 6975 | 7438 | return $queryarray; |
@@ -6987,42 +7450,47 @@ discard block |
||
| 6987 | 7450 | {
|
| 6988 | 7451 | if($this->isDate($info)) |
| 6989 | 7452 | {
|
| 6990 | - if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0;
|
|
| 6991 | - else $this->{$field} = strtotime($obj->{$field});
|
|
| 6992 | - } |
|
| 6993 | - elseif($this->isArray($info)) |
|
| 7453 | + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') { |
|
| 7454 | + $this->{$field} = 0; |
|
| 7455 | + } else { |
|
| 7456 | + $this->{$field} = strtotime($obj->{$field}); |
|
| 7457 | + } |
|
| 7458 | + } elseif($this->isArray($info)) |
|
| 6994 | 7459 | {
|
| 6995 | 7460 | if(! empty($obj->{$field})) {
|
| 6996 | 7461 | $this->{$field} = @unserialize($obj->{$field});
|
| 6997 | 7462 | // Hack for data not in UTF8 |
| 6998 | - if($this->{$field } === false) @unserialize(utf8_decode($obj->{$field}));
|
|
| 7463 | + if($this->{$field } === false) { |
|
| 7464 | + @unserialize(utf8_decode($obj->{$field})); |
|
| 7465 | + } |
|
| 6999 | 7466 | } else {
|
| 7000 | 7467 | $this->{$field} = array();
|
| 7001 | 7468 | } |
| 7002 | - } |
|
| 7003 | - elseif($this->isInt($info)) |
|
| 7469 | + } elseif($this->isInt($info)) |
|
| 7004 | 7470 | {
|
| 7005 | - if ($field == 'rowid') $this->id = (int) $obj->{$field};
|
|
| 7006 | - else $this->{$field} = (int) $obj->{$field};
|
|
| 7007 | - } |
|
| 7008 | - elseif($this->isFloat($info)) |
|
| 7471 | + if ($field == 'rowid') { |
|
| 7472 | + $this->id = (int) $obj->{$field}; |
|
| 7473 | + } else { |
|
| 7474 | + $this->{$field} = (int) $obj->{$field}; |
|
| 7475 | + } |
|
| 7476 | + } elseif($this->isFloat($info)) |
|
| 7009 | 7477 | {
|
| 7010 | 7478 | $this->{$field} = (double) $obj->{$field};
|
| 7011 | - } |
|
| 7012 | - elseif($this->isNull($info)) |
|
| 7479 | + } elseif($this->isNull($info)) |
|
| 7013 | 7480 | {
|
| 7014 | 7481 | $val = $obj->{$field};
|
| 7015 | 7482 | // zero is not null |
| 7016 | 7483 | $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val);
|
| 7017 | - } |
|
| 7018 | - else |
|
| 7484 | + } else |
|
| 7019 | 7485 | {
|
| 7020 | 7486 | $this->{$field} = $obj->{$field};
|
| 7021 | 7487 | } |
| 7022 | 7488 | } |
| 7023 | 7489 | |
| 7024 | 7490 | // If there is no 'ref' field, we force property ->ref to ->id for a better compatibility with common functions. |
| 7025 | - if (! isset($this->fields['ref']) && isset($this->id)) $this->ref = $this->id; |
|
| 7491 | + if (! isset($this->fields['ref']) && isset($this->id)) { |
|
| 7492 | + $this->ref = $this->id; |
|
| 7493 | + } |
|
| 7026 | 7494 | } |
| 7027 | 7495 | |
| 7028 | 7496 | /** |
@@ -7045,9 +7513,13 @@ discard block |
||
| 7045 | 7513 | */ |
| 7046 | 7514 | protected function quote($value, $fieldsentry) |
| 7047 | 7515 | {
|
| 7048 | - if (is_null($value)) return 'NULL'; |
|
| 7049 | - else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) return $this->db->escape("$value");
|
|
| 7050 | - else return "'".$this->db->escape($value)."'"; |
|
| 7516 | + if (is_null($value)) { |
|
| 7517 | + return 'NULL'; |
|
| 7518 | + } else if (preg_match('/^(int|double|real)/i', $fieldsentry['type'])) { |
|
| 7519 | + return $this->db->escape("$value"); |
|
| 7520 | + } else { |
|
| 7521 | + return "'".$this->db->escape($value)."'"; |
|
| 7522 | + } |
|
| 7051 | 7523 | } |
| 7052 | 7524 | |
| 7053 | 7525 | |
@@ -7067,8 +7539,12 @@ discard block |
||
| 7067 | 7539 | $now=dol_now(); |
| 7068 | 7540 | |
| 7069 | 7541 | $fieldvalues = $this->setSaveQuery(); |
| 7070 | - if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) $fieldvalues['date_creation']=$this->db->idate($now);
|
|
| 7071 | - if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) $fieldvalues['fk_user_creat']=$user->id;
|
|
| 7542 | + if (array_key_exists('date_creation', $fieldvalues) && empty($fieldvalues['date_creation'])) { |
|
| 7543 | + $fieldvalues['date_creation']=$this->db->idate($now); |
|
| 7544 | + } |
|
| 7545 | + if (array_key_exists('fk_user_creat', $fieldvalues) && ! ($fieldvalues['fk_user_creat'] > 0)) { |
|
| 7546 | + $fieldvalues['fk_user_creat']=$user->id; |
|
| 7547 | + } |
|
| 7072 | 7548 | unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into insert. |
| 7073 | 7549 | |
| 7074 | 7550 | $keys=array(); |
@@ -7083,8 +7559,12 @@ discard block |
||
| 7083 | 7559 | foreach($keys as $key) |
| 7084 | 7560 | {
|
| 7085 | 7561 | // If field is an implicit foreign key field |
| 7086 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]='';
|
|
| 7087 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; |
|
| 7562 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { |
|
| 7563 | + $values[$key]=''; |
|
| 7564 | + } |
|
| 7565 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { |
|
| 7566 | + $values[$key]=''; |
|
| 7567 | + } |
|
| 7088 | 7568 | |
| 7089 | 7569 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7090 | 7570 | if (isset($this->fields[$key]['notnull']) && $this->fields[$key]['notnull'] == 1 && ! isset($values[$key]) && is_null($val['default'])) |
@@ -7094,11 +7574,17 @@ discard block |
||
| 7094 | 7574 | } |
| 7095 | 7575 | |
| 7096 | 7576 | // If field is an implicit foreign key field |
| 7097 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) $values[$key]='null';
|
|
| 7098 | - if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) $values[$key]='null'; |
|
| 7577 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && empty($values[$key])) { |
|
| 7578 | + $values[$key]='null'; |
|
| 7579 | + } |
|
| 7580 | + if (! empty($this->fields[$key]['foreignkey']) && empty($values[$key])) { |
|
| 7581 | + $values[$key]='null'; |
|
| 7582 | + } |
|
| 7099 | 7583 | } |
| 7100 | 7584 | |
| 7101 | - if ($error) return -1; |
|
| 7585 | + if ($error) { |
|
| 7586 | + return -1; |
|
| 7587 | + } |
|
| 7102 | 7588 | |
| 7103 | 7589 | $this->db->begin(); |
| 7104 | 7590 | |
@@ -7124,7 +7610,9 @@ discard block |
||
| 7124 | 7610 | if (! $error) |
| 7125 | 7611 | {
|
| 7126 | 7612 | $result=$this->insertExtraFields(); |
| 7127 | - if ($result < 0) $error++; |
|
| 7613 | + if ($result < 0) { |
|
| 7614 | + $error++; |
|
| 7615 | + } |
|
| 7128 | 7616 | } |
| 7129 | 7617 | |
| 7130 | 7618 | // Triggers |
@@ -7157,15 +7645,24 @@ discard block |
||
| 7157 | 7645 | */ |
| 7158 | 7646 | public function fetchCommon($id, $ref = null, $morewhere = '') |
| 7159 | 7647 | {
|
| 7160 | - if (empty($id) && empty($ref) && empty($morewhere)) return -1; |
|
| 7648 | + if (empty($id) && empty($ref) && empty($morewhere)) { |
|
| 7649 | + return -1; |
|
| 7650 | + } |
|
| 7161 | 7651 | |
| 7162 | 7652 | $sql = 'SELECT '.$this->getFieldList(); |
| 7163 | 7653 | $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; |
| 7164 | 7654 | |
| 7165 | - if (!empty($id)) $sql.= ' WHERE rowid = '.$id; |
|
| 7166 | - elseif (!empty($ref)) $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7167 | - else $sql.=' WHERE 1 = 1'; // usage with empty id and empty ref is very rare |
|
| 7168 | - if ($morewhere) $sql.= $morewhere; |
|
| 7655 | + if (!empty($id)) { |
|
| 7656 | + $sql.= ' WHERE rowid = '.$id; |
|
| 7657 | + } elseif (!empty($ref)) { |
|
| 7658 | + $sql.= " WHERE ref = ".$this->quote($ref, $this->fields['ref']); |
|
| 7659 | + } else { |
|
| 7660 | + $sql.=' WHERE 1 = 1'; |
|
| 7661 | + } |
|
| 7662 | + // usage with empty id and empty ref is very rare |
|
| 7663 | + if ($morewhere) { |
|
| 7664 | + $sql.= $morewhere; |
|
| 7665 | + } |
|
| 7169 | 7666 | $sql.=' LIMIT 1'; // This is a fetch, to be sure to get only one record |
| 7170 | 7667 | |
| 7171 | 7668 | $res = $this->db->query($sql); |
@@ -7176,13 +7673,11 @@ discard block |
||
| 7176 | 7673 | {
|
| 7177 | 7674 | $this->setVarsFromFetchObj($obj); |
| 7178 | 7675 | return $this->id; |
| 7179 | - } |
|
| 7180 | - else |
|
| 7676 | + } else |
|
| 7181 | 7677 | {
|
| 7182 | 7678 | return 0; |
| 7183 | 7679 | } |
| 7184 | - } |
|
| 7185 | - else |
|
| 7680 | + } else |
|
| 7186 | 7681 | {
|
| 7187 | 7682 | $this->error = $this->db->lasterror(); |
| 7188 | 7683 | $this->errors[] = $this->error; |
@@ -7206,8 +7701,12 @@ discard block |
||
| 7206 | 7701 | $now=dol_now(); |
| 7207 | 7702 | |
| 7208 | 7703 | $fieldvalues = $this->setSaveQuery(); |
| 7209 | - if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) $fieldvalues['date_modification']=$this->db->idate($now);
|
|
| 7210 | - if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) $fieldvalues['fk_user_modif']=$user->id;
|
|
| 7704 | + if (array_key_exists('date_modification', $fieldvalues) && empty($fieldvalues['date_modification'])) { |
|
| 7705 | + $fieldvalues['date_modification']=$this->db->idate($now); |
|
| 7706 | + } |
|
| 7707 | + if (array_key_exists('fk_user_modif', $fieldvalues) && ! ($fieldvalues['fk_user_modif'] > 0)) { |
|
| 7708 | + $fieldvalues['fk_user_modif']=$user->id; |
|
| 7709 | + } |
|
| 7211 | 7710 | unset($fieldvalues['rowid']); // The field 'rowid' is reserved field name for autoincrement field so we don't need it into update. |
| 7212 | 7711 | |
| 7213 | 7712 | $keys=array(); |
@@ -7222,8 +7721,14 @@ discard block |
||
| 7222 | 7721 | // Clean and check mandatory |
| 7223 | 7722 | foreach($keys as $key) |
| 7224 | 7723 | {
|
| 7225 | - if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') $values[$key]=''; // This is an implicit foreign key field
|
|
| 7226 | - if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') $values[$key]=''; // This is an explicit foreign key field |
|
| 7724 | + if (preg_match('/^integer:/i', $this->fields[$key]['type']) && $values[$key] == '-1') { |
|
| 7725 | + $values[$key]=''; |
|
| 7726 | + } |
|
| 7727 | + // This is an implicit foreign key field |
|
| 7728 | + if (! empty($this->fields[$key]['foreignkey']) && $values[$key] == '-1') { |
|
| 7729 | + $values[$key]=''; |
|
| 7730 | + } |
|
| 7731 | + // This is an explicit foreign key field |
|
| 7227 | 7732 | |
| 7228 | 7733 | //var_dump($key.'-'.$values[$key].'-'.($this->fields[$key]['notnull'] == 1)); |
| 7229 | 7734 | /* |
@@ -7303,10 +7808,11 @@ discard block |
||
| 7303 | 7808 | return -1; |
| 7304 | 7809 | } |
| 7305 | 7810 | } |
| 7306 | - } |
|
| 7307 | - elseif (! empty($this->fk_element) && ! empty($this->childtables)) // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7811 | + } elseif (! empty($this->fk_element) && ! empty($this->childtables)) { |
|
| 7812 | + // If object has childs linked with a foreign key field, we check all child tables. |
|
| 7308 | 7813 | {
|
| 7309 | - $objectisused = $this->isObjectUsed($this->id); |
|
| 7814 | + $objectisused = $this->isObjectUsed($this->id); |
|
| 7815 | + } |
|
| 7310 | 7816 | if (! empty($objectisused)) |
| 7311 | 7817 | {
|
| 7312 | 7818 | dol_syslog(get_class($this)."::deleteCommon Can't delete record as it has some child", LOG_WARNING); |
@@ -7413,7 +7919,9 @@ discard block |
||
| 7413 | 7919 | */ |
| 7414 | 7920 | public function trimParameters($parameters) |
| 7415 | 7921 | {
|
| 7416 | - if (!is_array($parameters)) return; |
|
| 7922 | + if (!is_array($parameters)) { |
|
| 7923 | + return; |
|
| 7924 | + } |
|
| 7417 | 7925 | foreach ($parameters as $parameter) {
|
| 7418 | 7926 | if (isset($this->$parameter)) {
|
| 7419 | 7927 | $this->$parameter = trim($this->$parameter); |
@@ -37,12 +37,15 @@ discard block |
||
| 37 | 37 | function __construct() |
| 38 | 38 | {
|
| 39 | 39 | $dir = DOL_BASE_PATH; |
| 40 | - if (!empty(Globals::$conf->file->character_set_client)) |
|
| 41 | - $this->charset_output = Globals::$conf->file->character_set_client; // If charset output is forced |
|
| 42 | - if ($dir) |
|
| 43 | - $this->dir = array($dir); |
|
| 44 | - else |
|
| 45 | - $this->dir = Globals::$conf->file->dol_document_root; |
|
| 40 | + if (!empty(Globals::$conf->file->character_set_client)) { |
|
| 41 | + $this->charset_output = Globals::$conf->file->character_set_client; |
|
| 42 | + } |
|
| 43 | + // If charset output is forced |
|
| 44 | + if ($dir) { |
|
| 45 | + $this->dir = array($dir); |
|
| 46 | + } else { |
|
| 47 | + $this->dir = Globals::$conf->file->dol_document_root; |
|
| 48 | + } |
|
| 46 | 49 | } |
| 47 | 50 | |
| 48 | 51 | /** |
@@ -78,8 +81,9 @@ discard block |
||
| 78 | 81 | $langpref = str_replace("-", "_", $langpref);
|
| 79 | 82 | $langlist = preg_split("/[;,]/", $langpref);
|
| 80 | 83 | $codetouse = $langlist[0]; |
| 81 | - } else |
|
| 82 | - $codetouse = $srclang; |
|
| 84 | + } else { |
|
| 85 | + $codetouse = $srclang; |
|
| 86 | + } |
|
| 83 | 87 | |
| 84 | 88 | // We redefine $srclang |
| 85 | 89 | $langpart = explode("_", $codetouse);
|
@@ -88,25 +92,27 @@ discard block |
||
| 88 | 92 | // Array force long code from first part, even if long code is defined |
| 89 | 93 | $longforshort = array('ar' => 'ar_SA');
|
| 90 | 94 | $longforshortexcep = array('ar_EG');
|
| 91 | - if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) |
|
| 92 | - $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 93 | - else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser
|
|
| 95 | + if (isset($longforshort[strtolower($langpart[0])]) && !in_array($codetouse, $longforshortexcep)) { |
|
| 96 | + $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 97 | + } else if (!is_numeric($langpart[1])) { // Second part YY may be a numeric with some Chrome browser
|
|
| 94 | 98 | $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[1]); |
| 95 | 99 | $longforlong = array('no_nb' => 'nb_NO');
|
| 96 | - if (isset($longforlong[strtolower($srclang)])) |
|
| 97 | - $srclang = $longforlong[strtolower($srclang)]; |
|
| 98 | - } else |
|
| 99 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 100 | - } |
|
| 101 | - else { // If it's for a codetouse that is a short code xx
|
|
| 100 | + if (isset($longforlong[strtolower($srclang)])) { |
|
| 101 | + $srclang = $longforlong[strtolower($srclang)]; |
|
| 102 | + } |
|
| 103 | + } else { |
|
| 104 | + $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 105 | + } |
|
| 106 | + } else { // If it's for a codetouse that is a short code xx
|
|
| 102 | 107 | // Array to convert short lang code into long code. |
| 103 | 108 | $longforshort = array('ar' => 'ar_SA', 'el' => 'el_GR', 'ca' => 'ca_ES', 'en' => 'en_US', 'nb' => 'nb_NO', 'no' => 'nb_NO');
|
| 104 | - if (isset($longforshort[strtolower($langpart[0])])) |
|
| 105 | - $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 106 | - else if (!empty($langpart[0])) |
|
| 107 | - $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 108 | - else |
|
| 109 | - $srclang = 'en_US'; |
|
| 109 | + if (isset($longforshort[strtolower($langpart[0])])) { |
|
| 110 | + $srclang = $longforshort[strtolower($langpart[0])]; |
|
| 111 | + } else if (!empty($langpart[0])) { |
|
| 112 | + $srclang = strtolower($langpart[0]) . "_" . strtoupper($langpart[0]); |
|
| 113 | + } else { |
|
| 114 | + $srclang = 'en_US'; |
|
| 115 | + } |
|
| 110 | 116 | } |
| 111 | 117 | |
| 112 | 118 | $this->defaultlang = $srclang; |
@@ -122,10 +128,11 @@ discard block |
||
| 122 | 128 | */ |
| 123 | 129 | function getDefaultLang($mode = 0) |
| 124 | 130 | {
|
| 125 | - if (empty($mode)) |
|
| 126 | - return $this->defaultlang; |
|
| 127 | - else |
|
| 128 | - return substr($this->defaultlang, 0, 2); |
|
| 131 | + if (empty($mode)) { |
|
| 132 | + return $this->defaultlang; |
|
| 133 | + } else { |
|
| 134 | + return substr($this->defaultlang, 0, 2); |
|
| 135 | + } |
|
| 129 | 136 | } |
| 130 | 137 | |
| 131 | 138 | /** |
@@ -171,8 +178,10 @@ discard block |
||
| 171 | 178 | dol_print_error('', get_class($this) . "::Load ErrorWrongParameters");
|
| 172 | 179 | return -1; |
| 173 | 180 | } |
| 174 | - if ($this->defaultlang == 'none_NONE') |
|
| 175 | - return 0; // Special language code to not translate keys |
|
| 181 | + if ($this->defaultlang == 'none_NONE') { |
|
| 182 | + return 0; |
|
| 183 | + } |
|
| 184 | + // Special language code to not translate keys |
|
| 176 | 185 | |
| 177 | 186 | |
| 178 | 187 | |
@@ -180,8 +189,10 @@ discard block |
||
| 180 | 189 | |
| 181 | 190 | |
| 182 | 191 | // Load $this->tab_translate[] from database |
| 183 | - if (empty($loadfromfileonly) && count($this->tab_translate) == 0) |
|
| 184 | - $this->loadFromDatabase($db); // No translation was never loaded yet, so we load database. |
|
| 192 | + if (empty($loadfromfileonly) && count($this->tab_translate) == 0) { |
|
| 193 | + $this->loadFromDatabase($db); |
|
| 194 | + } |
|
| 195 | + // No translation was never loaded yet, so we load database. |
|
| 185 | 196 | |
| 186 | 197 | |
| 187 | 198 | $newdomain = $domain; |
@@ -204,10 +215,12 @@ discard block |
||
| 204 | 215 | |
| 205 | 216 | // Redefine alt |
| 206 | 217 | $langarray = explode('_', $langofdir);
|
| 207 | - if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr'))))
|
|
| 208 | - $alt = 1; |
|
| 209 | - if ($alt < 2 && strtolower($langofdir) == 'en_us') |
|
| 210 | - $alt = 2; |
|
| 218 | + if ($alt < 1 && isset($langarray[1]) && (strtolower($langarray[0]) == strtolower($langarray[1]) || in_array(strtolower($langofdir), array('el_gr')))) { |
|
| 219 | + $alt = 1; |
|
| 220 | + } |
|
| 221 | + if ($alt < 2 && strtolower($langofdir) == 'en_us') { |
|
| 222 | + $alt = 2; |
|
| 223 | + } |
|
| 211 | 224 | |
| 212 | 225 | if (empty($langofdir)) { // This may occurs when load is called without setting the language and without providing a value for forcelangdir
|
| 213 | 226 | AlDolUtils::dol_syslog("Error: " . get_class($this) . "::Load was called but language was not set yet with langs->setDefaultLang(). Nothing will be loaded.", LOG_WARNING);
|
@@ -249,16 +262,19 @@ discard block |
||
| 249 | 262 | $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 | 263 | //print $newdomain."\n"; |
| 251 | 264 | //var_dump($this->tab_translate); |
| 252 | - if ($alt == 2) |
|
| 253 | - $fileread = 1; |
|
| 265 | + if ($alt == 2) { |
|
| 266 | + $fileread = 1; |
|
| 267 | + } |
|
| 254 | 268 | $found = true; // Found in dolibarr PHP cache |
| 255 | 269 | } |
| 256 | 270 | } |
| 257 | 271 | |
| 258 | 272 | if (!$found) {
|
| 259 | 273 | if ($fp = @fopen($file_lang, "rt")) {
|
| 260 | - if ($usecachekey) |
|
| 261 | - $tabtranslatedomain = array(); // To save lang content in cache |
|
| 274 | + if ($usecachekey) { |
|
| 275 | + $tabtranslatedomain = array(); |
|
| 276 | + } |
|
| 277 | + // To save lang content in cache |
|
| 262 | 278 | |
| 263 | 279 | /** |
| 264 | 280 | * Read each lines until a '=' (with any combination of spaces around it) |
@@ -306,8 +322,10 @@ discard block |
||
| 306 | 322 | } |
| 307 | 323 | } |
| 308 | 324 | |
| 309 | - if (empty(Globals::$conf->global->MAIN_FORCELANGDIR)) |
|
| 310 | - break; // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 325 | + if (empty(Globals::$conf->global->MAIN_FORCELANGDIR)) { |
|
| 326 | + break; |
|
| 327 | + } |
|
| 328 | + // Break loop on each root dir. If a module has forced dir, we do not stop loop. |
|
| 311 | 329 | } |
| 312 | 330 | } |
| 313 | 331 | } |
@@ -318,10 +336,14 @@ discard block |
||
| 318 | 336 | // This function MUST NOT contains call to syslog |
| 319 | 337 | //DolUtils::dol_syslog("Translate::Load loading alternate translation file (to complete ".$this->defaultlang."/".$newdomain.".lang file)", LOG_DEBUG);
|
| 320 | 338 | $langofdir = strtolower($langarray[0]) . '_' . strtoupper($langarray[0]); |
| 321 | - if ($langofdir == 'el_EL') |
|
| 322 | - $langofdir = 'el_GR'; // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 323 | - if ($langofdir == 'ar_AR') |
|
| 324 | - $langofdir = 'ar_SA'; // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 339 | + if ($langofdir == 'el_EL') { |
|
| 340 | + $langofdir = 'el_GR'; |
|
| 341 | + } |
|
| 342 | + // main parent for el_CY is not 'el_EL' but 'el_GR' |
|
| 343 | + if ($langofdir == 'ar_AR') { |
|
| 344 | + $langofdir = 'ar_SA'; |
|
| 345 | + } |
|
| 346 | + // main parent for ar_EG is not 'ar_AR' but 'ar_SA' |
|
| 325 | 347 | $this->load($domain, $alt + 1, $stopafterdirection, $langofdir); |
| 326 | 348 | } |
| 327 | 349 | |
@@ -335,11 +357,15 @@ discard block |
||
| 335 | 357 | |
| 336 | 358 | // We are in the pass of the reference file. No more files to scan to complete. |
| 337 | 359 | if ($alt == 2) {
|
| 338 | - if ($fileread) |
|
| 339 | - $this->_tab_loaded[$newdomain] = 1; // Set domain file as found so loaded |
|
| 340 | - |
|
| 341 | - if (empty($this->_tab_loaded[$newdomain])) |
|
| 342 | - $this->_tab_loaded[$newdomain] = 2; // Set this file as not found |
|
| 360 | + if ($fileread) { |
|
| 361 | + $this->_tab_loaded[$newdomain] = 1; |
|
| 362 | + } |
|
| 363 | + // Set domain file as found so loaded |
|
| 364 | + |
|
| 365 | + if (empty($this->_tab_loaded[$newdomain])) { |
|
| 366 | + $this->_tab_loaded[$newdomain] = 2; |
|
| 367 | + } |
|
| 368 | + // Set this file as not found |
|
| 343 | 369 | } |
| 344 | 370 | |
| 345 | 371 | // This part is deprecated and replaced with table llx_overwrite_trans |
@@ -351,15 +377,17 @@ discard block |
||
| 351 | 377 | $tmparray = explode(',', Globals::$conf->global->$overwritekey);
|
| 352 | 378 | foreach ($tmparray as $tmp) {
|
| 353 | 379 | $tmparray2 = explode(':', $tmp);
|
| 354 | - if (!empty($tmparray2[1])) |
|
| 355 | - $this->tab_translate[$tmparray2[0]] = $tmparray2[1]; |
|
| 380 | + if (!empty($tmparray2[1])) { |
|
| 381 | + $this->tab_translate[$tmparray2[0]] = $tmparray2[1]; |
|
| 382 | + } |
|
| 356 | 383 | } |
| 357 | 384 | } |
| 358 | 385 | } |
| 359 | 386 | |
| 360 | 387 | // Check to be sure that SeparatorDecimal differs from SeparatorThousand |
| 361 | - if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) |
|
| 362 | - $this->tab_translate["SeparatorThousand"] = ''; |
|
| 388 | + if (!empty($this->tab_translate["SeparatorDecimal"]) && !empty($this->tab_translate["SeparatorThousand"]) && $this->tab_translate["SeparatorDecimal"] == $this->tab_translate["SeparatorThousand"]) { |
|
| 389 | + $this->tab_translate["SeparatorThousand"] = ''; |
|
| 390 | + } |
|
| 363 | 391 | |
| 364 | 392 | return 1; |
| 365 | 393 | } |
@@ -383,8 +411,10 @@ discard block |
||
| 383 | 411 | $domain = 'database'; |
| 384 | 412 | |
| 385 | 413 | // Check parameters |
| 386 | - if (empty($db)) |
|
| 387 | - return 0; // Database handler can't be used |
|
| 414 | + if (empty($db)) { |
|
| 415 | + return 0; |
|
| 416 | + } |
|
| 417 | + // Database handler can't be used |
|
| 388 | 418 | |
| 389 | 419 | |
| 390 | 420 | |
@@ -448,8 +478,10 @@ discard block |
||
| 448 | 478 | if ($resql) {
|
| 449 | 479 | $num = $db->num_rows($resql); |
| 450 | 480 | if ($num) {
|
| 451 | - if ($usecachekey) |
|
| 452 | - $tabtranslatedomain = array(); // To save lang content in cache |
|
| 481 | + if ($usecachekey) { |
|
| 482 | + $tabtranslatedomain = array(); |
|
| 483 | + } |
|
| 484 | + // To save lang content in cache |
|
| 453 | 485 | |
| 454 | 486 | $i = 0; |
| 455 | 487 | while ($i < $num) { // Ex: Need 225ms for all fgets on all lang file for Third party page. Same speed than file_get_contents
|
@@ -463,8 +495,10 @@ discard block |
||
| 463 | 495 | $value = trim(preg_replace('/\\n/', "\n", $value));
|
| 464 | 496 | |
| 465 | 497 | $this->tab_translate[$key] = $value; |
| 466 | - if ($usecachekey) |
|
| 467 | - $tabtranslatedomain[$key] = $value; // To save lang content in cache |
|
| 498 | + if ($usecachekey) { |
|
| 499 | + $tabtranslatedomain[$key] = $value; |
|
| 500 | + } |
|
| 501 | + // To save lang content in cache |
|
| 468 | 502 | } |
| 469 | 503 | |
| 470 | 504 | $i++; |
@@ -487,11 +521,15 @@ discard block |
||
| 487 | 521 | } |
| 488 | 522 | } |
| 489 | 523 | |
| 490 | - if ($fileread) |
|
| 491 | - $this->_tab_loaded[$newdomain] = 1; // Set domain file as loaded |
|
| 524 | + if ($fileread) { |
|
| 525 | + $this->_tab_loaded[$newdomain] = 1; |
|
| 526 | + } |
|
| 527 | + // Set domain file as loaded |
|
| 492 | 528 | |
| 493 | - if (empty($this->_tab_loaded[$newdomain])) |
|
| 494 | - $this->_tab_loaded[$newdomain] = 2; // Marque ce cas comme non trouve (no lines found for language) |
|
| 529 | + if (empty($this->_tab_loaded[$newdomain])) { |
|
| 530 | + $this->_tab_loaded[$newdomain] = 2; |
|
| 531 | + } |
|
| 532 | + // Marque ce cas comme non trouve (no lines found for language) |
|
| 495 | 533 | |
| 496 | 534 | return 1; |
| 497 | 535 | } |
@@ -511,8 +549,10 @@ discard block |
||
| 511 | 549 | {
|
| 512 | 550 | global $conf, $db; |
| 513 | 551 | |
| 514 | - if (!is_string($key)) |
|
| 515 | - return 'ErrorBadValueForParamNotAString'; // Avoid multiple errors with code not using function correctly. |
|
| 552 | + if (!is_string($key)) { |
|
| 553 | + return 'ErrorBadValueForParamNotAString'; |
|
| 554 | + } |
|
| 555 | + // Avoid multiple errors with code not using function correctly. |
|
| 516 | 556 | |
| 517 | 557 | $newstr = $key; |
| 518 | 558 | if (preg_match('/^Civility([0-9A-Z]+)$/i', $key, $reg)) {
|
@@ -575,8 +615,9 @@ discard block |
||
| 575 | 615 | $str = sprintf($str, $param1, $param2, $param3, $param4); // Replace %s and %d except for FormatXXX strings. |
| 576 | 616 | } |
| 577 | 617 | |
| 578 | - if ($maxsize) |
|
| 579 | - $str = dol_trunc($str, $maxsize); |
|
| 618 | + if ($maxsize) { |
|
| 619 | + $str = dol_trunc($str, $maxsize); |
|
| 620 | + } |
|
| 580 | 621 | |
| 581 | 622 | // We replace some HTML tags by __xx__ to avoid having them encoded by htmlentities |
| 582 | 623 | $str = str_replace(array('<', '>', '"',), array('__lt__', '__gt__', '__quot__'), $str);
|
@@ -587,8 +628,7 @@ discard block |
||
| 587 | 628 | $str = str_replace(array('__lt__', '__gt__', '__quot__'), array('<', '>', '"',), $str);
|
| 588 | 629 | |
| 589 | 630 | return $str; |
| 590 | - } |
|
| 591 | - else { // Translation is not available
|
|
| 631 | + } else { // Translation is not available
|
|
| 592 | 632 | //if ($key[0] == '$') { return dol_eval($key,1); }
|
| 593 | 633 | return $this->getTradFromKey($key); |
| 594 | 634 | } |
@@ -668,10 +708,11 @@ discard block |
||
| 668 | 708 | */ |
| 669 | 709 | function transcountry($str, $countrycode) |
| 670 | 710 | {
|
| 671 | - if ($this->tab_translate["$str$countrycode"]) |
|
| 672 | - return $this->trans("$str$countrycode");
|
|
| 673 | - else |
|
| 674 | - return $this->trans($str); |
|
| 711 | + if ($this->tab_translate["$str$countrycode"]) { |
|
| 712 | + return $this->trans("$str$countrycode"); |
|
| 713 | + } else { |
|
| 714 | + return $this->trans($str); |
|
| 715 | + } |
|
| 675 | 716 | } |
| 676 | 717 | |
| 677 | 718 | /** |
@@ -683,10 +724,11 @@ discard block |
||
| 683 | 724 | */ |
| 684 | 725 | function transcountrynoentities($str, $countrycode) |
| 685 | 726 | {
|
| 686 | - if ($this->tab_translate["$str$countrycode"]) |
|
| 687 | - return $this->transnoentities("$str$countrycode");
|
|
| 688 | - else |
|
| 689 | - return $this->transnoentities($str); |
|
| 727 | + if ($this->tab_translate["$str$countrycode"]) { |
|
| 728 | + return $this->transnoentities("$str$countrycode"); |
|
| 729 | + } else { |
|
| 730 | + return $this->transnoentities($str); |
|
| 731 | + } |
|
| 690 | 732 | } |
| 691 | 733 | |
| 692 | 734 | /** |
@@ -698,10 +740,12 @@ discard block |
||
| 698 | 740 | */ |
| 699 | 741 | function convToOutputCharset($str, $pagecodefrom = 'UTF-8') |
| 700 | 742 | {
|
| 701 | - if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') |
|
| 702 | - $str = utf8_encode($str); |
|
| 703 | - if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') |
|
| 704 | - $str = utf8_decode(str_replace('€', chr(128), $str));
|
|
| 743 | + if ($pagecodefrom == 'ISO-8859-1' && $this->charset_output == 'UTF-8') { |
|
| 744 | + $str = utf8_encode($str); |
|
| 745 | + } |
|
| 746 | + if ($pagecodefrom == 'UTF-8' && $this->charset_output == 'ISO-8859-1') { |
|
| 747 | + $str = utf8_decode(str_replace('€', chr(128), $str)); |
|
| 748 | + } |
|
| 705 | 749 | return $str; |
| 706 | 750 | } |
| 707 | 751 | |
@@ -756,16 +800,19 @@ discard block |
||
| 756 | 800 | // phpcs:enable |
| 757 | 801 | // Test si fichier dans repertoire de la langue |
| 758 | 802 | foreach ($this->dir as $searchdir) {
|
| 759 | - if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) |
|
| 760 | - return true; |
|
| 803 | + if (is_readable(dol_osencode($searchdir . "/langs/" . $this->defaultlang . "/" . $filename))) { |
|
| 804 | + return true; |
|
| 805 | + } |
|
| 761 | 806 | |
| 762 | 807 | if ($searchalt) {
|
| 763 | 808 | // Test si fichier dans repertoire de la langue alternative |
| 764 | - if ($this->defaultlang != "en_US") |
|
| 765 | - $filenamealt = $searchdir . "/langs/en_US/" . $filename; |
|
| 809 | + if ($this->defaultlang != "en_US") { |
|
| 810 | + $filenamealt = $searchdir . "/langs/en_US/" . $filename; |
|
| 811 | + } |
|
| 766 | 812 | //else $filenamealt = $searchdir."/langs/fr_FR/".$filename; |
| 767 | - if (is_readable(dol_osencode($filenamealt))) |
|
| 768 | - return true; |
|
| 813 | + if (is_readable(dol_osencode($filenamealt))) { |
|
| 814 | + return true; |
|
| 815 | + } |
|
| 769 | 816 | } |
| 770 | 817 | } |
| 771 | 818 | |
@@ -795,8 +842,10 @@ discard block |
||
| 795 | 842 | $newdir = dol_osencode($dir); |
| 796 | 843 | |
| 797 | 844 | // Check if directory exists |
| 798 | - if (!is_dir($newdir)) |
|
| 799 | - continue; // We must not use dol_is_dir here, function may not be loaded |
|
| 845 | + if (!is_dir($newdir)) { |
|
| 846 | + continue; |
|
| 847 | + } |
|
| 848 | + // We must not use dol_is_dir here, function may not be loaded |
|
| 800 | 849 | |
| 801 | 850 | $fonc = 'numberwords'; |
| 802 | 851 | if (file_exists($newdir . '/functions_' . $fonc . '.lib.php')) {
|
@@ -827,8 +876,9 @@ discard block |
||
| 827 | 876 | function getLabelFromKey($db, $key, $tablename, $fieldkey, $fieldlabel, $keyforselect = '', $filteronentity = 0) |
| 828 | 877 | {
|
| 829 | 878 | // If key empty |
| 830 | - if ($key == '') |
|
| 831 | - return ''; |
|
| 879 | + if ($key == '') { |
|
| 880 | + return ''; |
|
| 881 | + } |
|
| 832 | 882 | |
| 833 | 883 | //print 'param: '.$key.'-'.$keydatabase.'-'.$this->trans($key); exit; |
| 834 | 884 | // Check if a translation is available (this can call getTradFromKey) |
@@ -845,21 +895,22 @@ discard block |
||
| 845 | 895 | $sql = "SELECT " . $fieldlabel . " as label"; |
| 846 | 896 | $sql .= " FROM " . MAIN_DB_PREFIX . $tablename; |
| 847 | 897 | $sql .= " WHERE " . $fieldkey . " = '" . $db->escape($keyforselect ? $keyforselect : $key) . "'"; |
| 848 | - if ($filteronentity) |
|
| 849 | - $sql .= " AND entity IN (" . getEntity($tablename) . ')';
|
|
| 898 | + if ($filteronentity) { |
|
| 899 | + $sql .= " AND entity IN (" . getEntity($tablename) . ')'; |
|
| 900 | + } |
|
| 850 | 901 | AlDolUtils::dol_syslog(get_class($this) . '::getLabelFromKey', LOG_DEBUG); |
| 851 | 902 | $resql = $db->query($sql); |
| 852 | 903 | if ($resql) {
|
| 853 | 904 | $obj = $db->fetch_object($resql); |
| 854 | - if ($obj) |
|
| 855 | - $this->cache_labels[$tablename][$key] = $obj->label; |
|
| 856 | - else |
|
| 857 | - $this->cache_labels[$tablename][$key] = $key; |
|
| 905 | + if ($obj) { |
|
| 906 | + $this->cache_labels[$tablename][$key] = $obj->label; |
|
| 907 | + } else { |
|
| 908 | + $this->cache_labels[$tablename][$key] = $key; |
|
| 909 | + } |
|
| 858 | 910 | |
| 859 | 911 | $db->free($resql); |
| 860 | 912 | return $this->cache_labels[$tablename][$key]; |
| 861 | - } |
|
| 862 | - else {
|
|
| 913 | + } else {
|
|
| 863 | 914 | $this->error = $db->lasterror(); |
| 864 | 915 | return -1; |
| 865 | 916 | } |
@@ -878,10 +929,11 @@ discard block |
||
| 878 | 929 | {
|
| 879 | 930 | $symbol = $this->getCurrencySymbol($currency_code); |
| 880 | 931 | |
| 881 | - if (in_array($currency_code, array('USD')))
|
|
| 882 | - return $symbol . $amount; |
|
| 883 | - else |
|
| 884 | - return $amount . $symbol; |
|
| 932 | + if (in_array($currency_code, array('USD'))) { |
|
| 933 | + return $symbol . $amount; |
|
| 934 | + } else { |
|
| 935 | + return $amount . $symbol; |
|
| 936 | + } |
|
| 885 | 937 | } |
| 886 | 938 | |
| 887 | 939 | /** |
@@ -919,16 +971,21 @@ discard block |
||
| 919 | 971 | {
|
| 920 | 972 | global $db; |
| 921 | 973 | |
| 922 | - if ($this->cache_currencies_all_loaded) |
|
| 923 | - return 0; // Cache already loaded for all |
|
| 924 | - if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) |
|
| 925 | - return 0; // Cache already loaded for the currency |
|
| 974 | + if ($this->cache_currencies_all_loaded) { |
|
| 975 | + return 0; |
|
| 976 | + } |
|
| 977 | + // Cache already loaded for all |
|
| 978 | + if (!empty($currency_code) && isset($this->cache_currencies[$currency_code])) { |
|
| 979 | + return 0; |
|
| 980 | + } |
|
| 981 | + // Cache already loaded for the currency |
|
| 926 | 982 | |
| 927 | 983 | $sql = "SELECT code_iso, label, unicode"; |
| 928 | 984 | $sql .= " FROM " . MAIN_DB_PREFIX . "c_currencies"; |
| 929 | 985 | $sql .= " WHERE active = 1"; |
| 930 | - if (!empty($currency_code)) |
|
| 931 | - $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'"; |
|
| 986 | + if (!empty($currency_code)) { |
|
| 987 | + $sql .= " AND code_iso = '" . $db->escape($currency_code) . "'"; |
|
| 988 | + } |
|
| 932 | 989 | //$sql.= " ORDER BY code_iso ASC"; // Not required, a sort is done later |
| 933 | 990 | |
| 934 | 991 | AlDolUtils::dol_syslog(get_class($this) . '::loadCacheCurrencies', LOG_DEBUG); |
@@ -936,9 +993,11 @@ discard block |
||
| 936 | 993 | if ($resql) {
|
| 937 | 994 | $this->load("dict");
|
| 938 | 995 | $label = array(); |
| 939 | - if (!empty($currency_code)) |
|
| 940 | - foreach ($this->cache_currencies as $key => $val) |
|
| 941 | - $label[$key] = $val['label']; // Label in already loaded cache |
|
| 996 | + if (!empty($currency_code)) { |
|
| 997 | + foreach ($this->cache_currencies as $key => $val) |
|
| 998 | + $label[$key] = $val['label']; |
|
| 999 | + } |
|
| 1000 | + // Label in already loaded cache |
|
| 942 | 1001 | |
| 943 | 1002 | $num = $db->num_rows($resql); |
| 944 | 1003 | $i = 0; |
@@ -951,15 +1010,15 @@ discard block |
||
| 951 | 1010 | $label[$obj->code_iso] = $this->cache_currencies[$obj->code_iso]['label']; |
| 952 | 1011 | $i++; |
| 953 | 1012 | } |
| 954 | - if (empty($currency_code)) |
|
| 955 | - $this->cache_currencies_all_loaded = true; |
|
| 1013 | + if (empty($currency_code)) { |
|
| 1014 | + $this->cache_currencies_all_loaded = true; |
|
| 1015 | + } |
|
| 956 | 1016 | //print count($label).' '.count($this->cache_currencies); |
| 957 | 1017 | // Resort cache |
| 958 | 1018 | array_multisort($label, SORT_ASC, $this->cache_currencies); |
| 959 | 1019 | //var_dump($this->cache_currencies); $this->cache_currencies is now sorted onto label |
| 960 | 1020 | return $num; |
| 961 | - } |
|
| 962 | - else {
|
|
| 1021 | + } else {
|
|
| 963 | 1022 | dol_print_error($db); |
| 964 | 1023 | return -1; |
| 965 | 1024 | } |
@@ -199,15 +199,20 @@ discard block |
||
| 199 | 199 | if (!empty(Globals::$conf->global->MAIN_APPLICATION_TITLE)) { |
| 200 | 200 | $appli = Globals::$conf->global->MAIN_APPLICATION_TITLE; |
| 201 | 201 | if (preg_match('/\d\.\d/', $appli)) { |
| 202 | - if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli)) |
|
| 203 | - $appli .= " (" . DOL_VERSION . ")"; // If new title contains a version that is different than core |
|
| 204 | - } else |
|
| 205 | - $appli .= " " . DOL_VERSION; |
|
| 206 | - } else |
|
| 207 | - $appli .= " " . DOL_VERSION; |
|
| 202 | + if (!preg_match('/' . preg_quote(DOL_VERSION) . '/', $appli)) { |
|
| 203 | + $appli .= " (" . DOL_VERSION . ")"; |
|
| 204 | + } |
|
| 205 | + // If new title contains a version that is different than core |
|
| 206 | + } else { |
|
| 207 | + $appli .= " " . DOL_VERSION; |
|
| 208 | + } |
|
| 209 | + } else { |
|
| 210 | + $appli .= " " . DOL_VERSION; |
|
| 211 | + } |
|
| 208 | 212 | |
| 209 | - if (!empty(Globals::$conf->global->MAIN_FEATURES_LEVEL)) |
|
| 210 | - $appli .= "<br>" . Globals::$langs->trans("LevelOfFeature") . ': ' . Globals::$conf->global->MAIN_FEATURES_LEVEL; |
|
| 213 | + if (!empty(Globals::$conf->global->MAIN_FEATURES_LEVEL)) { |
|
| 214 | + $appli .= "<br>" . Globals::$langs->trans("LevelOfFeature") . ': ' . Globals::$conf->global->MAIN_FEATURES_LEVEL; |
|
| 215 | + } |
|
| 211 | 216 | |
| 212 | 217 | $logouttext = ''; |
| 213 | 218 | if (empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
@@ -247,12 +252,15 @@ discard block |
||
| 247 | 252 | $parameters = array(); |
| 248 | 253 | $result = Globals::$hookManager->executeHooks('printTopRightMenu', $parameters); // Note that $action and $object may have been modified by some hooks |
| 249 | 254 | if (is_numeric($result)) { |
| 250 | - if ($result == 0) |
|
| 251 | - $toprightmenu .= Globals::$hookManager->resPrint; // add |
|
| 252 | - else |
|
| 253 | - $toprightmenu = Globals::$hookManager->resPrint; // replace |
|
| 254 | - } |
|
| 255 | - else { |
|
| 255 | + if ($result == 0) { |
|
| 256 | + $toprightmenu .= Globals::$hookManager->resPrint; |
|
| 257 | + } |
|
| 258 | + // add |
|
| 259 | + else { |
|
| 260 | + $toprightmenu = Globals::$hookManager->resPrint; |
|
| 261 | + } |
|
| 262 | + // replace |
|
| 263 | + } else { |
|
| 256 | 264 | $toprightmenu .= $result; // For backward compatibility |
| 257 | 265 | } |
| 258 | 266 | |
@@ -412,8 +420,9 @@ discard block |
||
| 412 | 420 | $reshook = Globals::$hookManager->executeHooks('printSearchForm', $parameters); // Note that $action and $object may have been modified by some hooks |
| 413 | 421 | if (empty($reshook)) { |
| 414 | 422 | $searchform .= Globals::$hookManager->resPrint; |
| 415 | - } else |
|
| 416 | - $searchform = Globals::$hookManager->resPrint; |
|
| 423 | + } else { |
|
| 424 | + $searchform = Globals::$hookManager->resPrint; |
|
| 425 | + } |
|
| 417 | 426 | |
| 418 | 427 | // Force special value for $searchform |
| 419 | 428 | if (!empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) || empty(Globals::$conf->use_javascript_ajax)) { |
@@ -595,18 +604,21 @@ discard block |
||
| 595 | 604 | // If WIKI URL |
| 596 | 605 | if (preg_match('/^es/i', Globals::$langs->defaultlang)) { |
| 597 | 606 | $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s'; |
| 598 | - if (preg_match('/ES:([^|]+)/i', $helppagename, $reg)) |
|
| 599 | - $helppage = $reg[1]; |
|
| 607 | + if (preg_match('/ES:([^|]+)/i', $helppagename, $reg)) { |
|
| 608 | + $helppage = $reg[1]; |
|
| 609 | + } |
|
| 600 | 610 | } |
| 601 | 611 | if (preg_match('/^fr/i', Globals::$langs->defaultlang)) { |
| 602 | 612 | $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s'; |
| 603 | - if (preg_match('/FR:([^|]+)/i', $helppagename, $reg)) |
|
| 604 | - $helppage = $reg[1]; |
|
| 613 | + if (preg_match('/FR:([^|]+)/i', $helppagename, $reg)) { |
|
| 614 | + $helppage = $reg[1]; |
|
| 615 | + } |
|
| 605 | 616 | } |
| 606 | 617 | if (empty($helppage)) { // If help page not already found |
| 607 | 618 | $helpbaseurl = 'http://wiki.dolibarr.org/index.php/%s'; |
| 608 | - if (preg_match('/EN:([^|]+)/i', $helppagename, $reg)) |
|
| 609 | - $helppage = $reg[1]; |
|
| 619 | + if (preg_match('/EN:([^|]+)/i', $helppagename, $reg)) { |
|
| 620 | + $helppage = $reg[1]; |
|
| 621 | + } |
|
| 610 | 622 | } |
| 611 | 623 | $mode = 'wiki'; |
| 612 | 624 | } |
@@ -697,8 +709,9 @@ discard block |
||
| 697 | 709 | |
| 698 | 710 | $relativepathstring = $_SERVER["PHP_SELF"]; |
| 699 | 711 | // Clean $relativepathstring |
| 700 | - if (constant('DOL_BASE_URI')) |
|
| 701 | - $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring); |
|
| 712 | + if (constant('DOL_BASE_URI')) { |
|
| 713 | + $relativepathstring = preg_replace('/^' . preg_quote(constant('DOL_BASE_URI'), '/') . '/', '', $relativepathstring); |
|
| 714 | + } |
|
| 702 | 715 | $relativepathstring = preg_replace('/^\//', '', $relativepathstring); |
| 703 | 716 | $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring); |
| 704 | 717 | if (preg_match('/list\.php$/', $relativepathstring)) { |
@@ -706,12 +719,15 @@ discard block |
||
| 706 | 719 | unset($_SESSION['lastsearch_page_tmp_' . $relativepathstring]); |
| 707 | 720 | unset($_SESSION['lastsearch_limit_tmp_' . $relativepathstring]); |
| 708 | 721 | |
| 709 | - if (!empty($contextpage)) |
|
| 710 | - $_SESSION['lastsearch_contextpage_tmp_' . $relativepathstring] = $contextpage; |
|
| 711 | - if (!empty($page) && $page > 1) |
|
| 712 | - $_SESSION['lastsearch_page_tmp_' . $relativepathstring] = $page; |
|
| 713 | - if (!empty($limit) && $limit != Globals::$conf->limit) |
|
| 714 | - $_SESSION['lastsearch_limit_tmp_' . $relativepathstring] = $limit; |
|
| 722 | + if (!empty($contextpage)) { |
|
| 723 | + $_SESSION['lastsearch_contextpage_tmp_' . $relativepathstring] = $contextpage; |
|
| 724 | + } |
|
| 725 | + if (!empty($page) && $page > 1) { |
|
| 726 | + $_SESSION['lastsearch_page_tmp_' . $relativepathstring] = $page; |
|
| 727 | + } |
|
| 728 | + if (!empty($limit) && $limit != Globals::$conf->limit) { |
|
| 729 | + $_SESSION['lastsearch_limit_tmp_' . $relativepathstring] = $limit; |
|
| 730 | + } |
|
| 715 | 731 | |
| 716 | 732 | unset($_SESSION['lastsearch_contextpage_' . $relativepathstring]); |
| 717 | 733 | unset($_SESSION['lastsearch_page_' . $relativepathstring]); |
@@ -738,20 +754,26 @@ discard block |
||
| 738 | 754 | |
| 739 | 755 | print '</div> <!-- End div class="fiche" -->' . "\n"; // End div fiche |
| 740 | 756 | |
| 741 | - if (empty(Globals::$conf->dol_hide_leftmenu)) |
|
| 742 | - print '</div> <!-- End div id-right -->' . "\n"; // End div id-right |
|
| 757 | + if (empty(Globals::$conf->dol_hide_leftmenu)) { |
|
| 758 | + print '</div> <!-- End div id-right -->' . "\n"; |
|
| 759 | + } |
|
| 760 | + // End div id-right |
|
| 743 | 761 | |
| 744 | - if (empty(Globals::$conf->dol_hide_leftmenu) && empty(Globals::$conf->dol_use_jmobile)) |
|
| 745 | - print '</div> <!-- End div id-container -->' . "\n"; // End div container |
|
| 762 | + if (empty(Globals::$conf->dol_hide_leftmenu) && empty(Globals::$conf->dol_use_jmobile)) { |
|
| 763 | + print '</div> <!-- End div id-container -->' . "\n"; |
|
| 764 | + } |
|
| 765 | + // End div container |
|
| 746 | 766 | |
| 747 | 767 | print "\n"; |
| 748 | - if ($comment) |
|
| 749 | - print '<!-- ' . $comment . ' -->' . "\n"; |
|
| 768 | + if ($comment) { |
|
| 769 | + print '<!-- ' . $comment . ' -->' . "\n"; |
|
| 770 | + } |
|
| 750 | 771 | |
| 751 | 772 | AlDolUtils::printCommonFooter($zone); |
| 752 | 773 | |
| 753 | - if (!empty($delayedhtmlcontent)) |
|
| 754 | - print $delayedhtmlcontent; |
|
| 774 | + if (!empty($delayedhtmlcontent)) { |
|
| 775 | + print $delayedhtmlcontent; |
|
| 776 | + } |
|
| 755 | 777 | |
| 756 | 778 | if (!empty(Globals::$conf->use_javascript_ajax)) { |
| 757 | 779 | print "\n" . '<!-- Includes JS Footer of Dolibarr -->' . "\n"; |
@@ -113,22 +113,24 @@ discard block |
||
| 113 | 113 | if (!empty($perm)) {
|
| 114 | 114 | $tmp = explode(':', $typeofdata);
|
| 115 | 115 | $ret .= '<div class="editkey_' . $tmp[0] . (!empty($tmp[1]) ? ' ' . $tmp[1] : '') . '" id="' . $htmlname . '">'; |
| 116 | - if ($fieldrequired) |
|
| 117 | - $ret .= '<span class="fieldrequired">'; |
|
| 116 | + if ($fieldrequired) { |
|
| 117 | + $ret .= '<span class="fieldrequired">'; |
|
| 118 | + } |
|
| 118 | 119 | $ret .= $langs->trans($text); |
| 119 | - if ($fieldrequired) |
|
| 120 | - $ret .= '</span>'; |
|
| 120 | + if ($fieldrequired) { |
|
| 121 | + $ret .= '</span>'; |
|
| 122 | + } |
|
| 121 | 123 | $ret .= '</div>' . "\n"; |
| 122 | - } |
|
| 123 | - else {
|
|
| 124 | - if ($fieldrequired) |
|
| 125 | - $ret .= '<span class="fieldrequired">'; |
|
| 124 | + } else {
|
|
| 125 | + if ($fieldrequired) { |
|
| 126 | + $ret .= '<span class="fieldrequired">'; |
|
| 127 | + } |
|
| 126 | 128 | $ret .= $langs->trans($text); |
| 127 | - if ($fieldrequired) |
|
| 128 | - $ret .= '</span>'; |
|
| 129 | + if ($fieldrequired) { |
|
| 130 | + $ret .= '</span>'; |
|
| 131 | + } |
|
| 129 | 132 | } |
| 130 | - } |
|
| 131 | - else {
|
|
| 133 | + } else {
|
|
| 132 | 134 | if (empty($notabletag) && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) {
|
| 133 | 135 | $ret .= '<table class="nobordernopadding" width="100%"><tr><td class="nowrap">'; |
| 134 | 136 | } |
@@ -193,8 +195,9 @@ discard block |
||
| 193 | 195 | $ret = ''; |
| 194 | 196 | |
| 195 | 197 | // Check parameters |
| 196 | - if (empty($typeofdata)) |
|
| 197 | - return 'ErrorBadParameter'; |
|
| 198 | + if (empty($typeofdata)) { |
|
| 199 | + return 'ErrorBadParameter'; |
|
| 200 | + } |
|
| 198 | 201 | |
| 199 | 202 | // When option to edit inline is activated |
| 200 | 203 | if (!empty(Globals::$conf->global->MAIN_USE_JQUERY_JEDITABLE) && !preg_match('/^select;|datehourpicker/', $typeofdata)) { // TODO add jquery timepicker
|
@@ -206,10 +209,12 @@ discard block |
||
| 206 | 209 | $ret .= '<input type="hidden" name="action" value="set' . $htmlname . '">'; |
| 207 | 210 | $ret .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
| 208 | 211 | $ret .= '<input type="hidden" name="' . $paramid . '" value="' . $object->id . '">'; |
| 209 | - if (empty($notabletag)) |
|
| 210 | - $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">'; |
|
| 211 | - if (empty($notabletag)) |
|
| 212 | - $ret .= '<tr><td>'; |
|
| 212 | + if (empty($notabletag)) { |
|
| 213 | + $ret .= '<table class="nobordernopadding centpercent" cellpadding="0" cellspacing="0">'; |
|
| 214 | + } |
|
| 215 | + if (empty($notabletag)) { |
|
| 216 | + $ret .= '<tr><td>'; |
|
| 217 | + } |
|
| 213 | 218 | if (preg_match('/^(string|email)/', $typeofdata)) {
|
| 214 | 219 | $tmp = explode(':', $typeofdata);
|
| 215 | 220 | $ret .= '<input type="text" id="' . $htmlname . '" name="' . $htmlname . '" value="' . ($editvalue ? $editvalue : $value) . '"' . ($tmp[1] ? ' size="' . $tmp[1] . '"' : '') . '>'; |
@@ -248,35 +253,39 @@ discard block |
||
| 248 | 253 | $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')); |
| 249 | 254 | $ret .= $doleditor->Create(1); |
| 250 | 255 | } |
| 251 | - if (empty($notabletag)) |
|
| 252 | - $ret .= '</td>'; |
|
| 256 | + if (empty($notabletag)) { |
|
| 257 | + $ret .= '</td>'; |
|
| 258 | + } |
|
| 253 | 259 | |
| 254 | - if (empty($notabletag)) |
|
| 255 | - $ret .= '<td align="left">'; |
|
| 260 | + if (empty($notabletag)) { |
|
| 261 | + $ret .= '<td align="left">'; |
|
| 262 | + } |
|
| 256 | 263 | //else $ret.='<div class="clearboth"></div>'; |
| 257 | 264 | $ret .= '<input type="submit" class="button' . (empty($notabletag) ? '' : ' ') . '" name="modify" value="' . $langs->trans("Modify") . '">';
|
| 258 | - if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag))
|
|
| 259 | - $ret .= '<br>' . "\n"; |
|
| 265 | + if (preg_match('/ckeditor|textarea/', $typeofdata) && empty($notabletag)) { |
|
| 266 | + $ret .= '<br>' . "\n"; |
|
| 267 | + } |
|
| 260 | 268 | $ret .= '<input type="submit" class="button' . (empty($notabletag) ? '' : ' ') . '" name="cancel" value="' . $langs->trans("Cancel") . '">';
|
| 261 | - if (empty($notabletag)) |
|
| 262 | - $ret .= '</td>'; |
|
| 269 | + if (empty($notabletag)) { |
|
| 270 | + $ret .= '</td>'; |
|
| 271 | + } |
|
| 263 | 272 | |
| 264 | - if (empty($notabletag)) |
|
| 265 | - $ret .= '</tr></table>' . "\n"; |
|
| 273 | + if (empty($notabletag)) { |
|
| 274 | + $ret .= '</tr></table>' . "\n"; |
|
| 275 | + } |
|
| 266 | 276 | $ret .= '</form>' . "\n"; |
| 267 | - } |
|
| 268 | - else {
|
|
| 269 | - if (preg_match('/^(email)/', $typeofdata))
|
|
| 270 | - $ret .= dol_print_email($value, 0, 0, 0, 0, 1); |
|
| 271 | - elseif (preg_match('/^(amount|numeric)/', $typeofdata))
|
|
| 272 | - $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, Globals::$conf->currency) : ''); |
|
| 273 | - elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata))
|
|
| 274 | - $ret .= dol_htmlentitiesbr($value); |
|
| 275 | - elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') |
|
| 276 | - $ret .= AlDolUtils::dol_print_date($value, 'day'); |
|
| 277 | - elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') |
|
| 278 | - $ret .= AlDolUtils::dol_print_date($value, 'dayhour'); |
|
| 279 | - else if (preg_match('/^select;/', $typeofdata)) {
|
|
| 277 | + } else {
|
|
| 278 | + if (preg_match('/^(email)/', $typeofdata)) { |
|
| 279 | + $ret .= dol_print_email($value, 0, 0, 0, 0, 1); |
|
| 280 | + } elseif (preg_match('/^(amount|numeric)/', $typeofdata)) { |
|
| 281 | + $ret .= ($value != '' ? price($value, '', $langs, 0, -1, -1, Globals::$conf->currency) : ''); |
|
| 282 | + } elseif (preg_match('/^text/', $typeofdata) || preg_match('/^note/', $typeofdata)) { |
|
| 283 | + $ret .= dol_htmlentitiesbr($value); |
|
| 284 | + } elseif ($typeofdata == 'day' || $typeofdata == 'datepicker') { |
|
| 285 | + $ret .= AlDolUtils::dol_print_date($value, 'day'); |
|
| 286 | + } elseif ($typeofdata == 'dayhour' || $typeofdata == 'datehourpicker') { |
|
| 287 | + $ret .= AlDolUtils::dol_print_date($value, 'dayhour'); |
|
| 288 | + } else if (preg_match('/^select;/', $typeofdata)) {
|
|
| 280 | 289 | $arraydata = explode(',', preg_replace('/^select;/', '', $typeofdata));
|
| 281 | 290 | foreach ($arraydata as $val) {
|
| 282 | 291 | $tmp = explode(':', $val);
|
@@ -291,8 +300,9 @@ discard block |
||
| 291 | 300 | $tmpcontent = $firstline . ((strlen($firstline) != strlen($tmpcontent)) ? '...' : ''); |
| 292 | 301 | } |
| 293 | 302 | $ret .= $tmpcontent; |
| 294 | - } else |
|
| 295 | - $ret .= $value; |
|
| 303 | + } else { |
|
| 304 | + $ret .= $value; |
|
| 305 | + } |
|
| 296 | 306 | |
| 297 | 307 | if ($formatfunc && method_exists($object, $formatfunc)) {
|
| 298 | 308 | $ret = $object->$formatfunc($ret); |
@@ -322,12 +332,13 @@ discard block |
||
| 322 | 332 | $out = ''; |
| 323 | 333 | |
| 324 | 334 | // Check parameters |
| 325 | - if (preg_match('/^text/', $inputType))
|
|
| 326 | - $value = dol_nl2br($value); |
|
| 327 | - else if (preg_match('/^numeric/', $inputType))
|
|
| 328 | - $value = price($value); |
|
| 329 | - else if ($inputType == 'day' || $inputType == 'datepicker') |
|
| 330 | - $value = AlDolUtils::dol_print_date($value, 'day'); |
|
| 335 | + if (preg_match('/^text/', $inputType)) { |
|
| 336 | + $value = dol_nl2br($value); |
|
| 337 | + } else if (preg_match('/^numeric/', $inputType)) { |
|
| 338 | + $value = price($value); |
|
| 339 | + } else if ($inputType == 'day' || $inputType == 'datepicker') { |
|
| 340 | + $value = AlDolUtils::dol_print_date($value, 'day'); |
|
| 341 | + } |
|
| 331 | 342 | |
| 332 | 343 | if ($condition) {
|
| 333 | 344 | $element = false; |
@@ -352,32 +363,35 @@ discard block |
||
| 352 | 363 | if (preg_match('/^(string|email|numeric)/', $inputType)) {
|
| 353 | 364 | $tmp = explode(':', $inputType);
|
| 354 | 365 | $inputType = $tmp[0]; |
| 355 | - if (!empty($tmp[1])) |
|
| 356 | - $inputOption = $tmp[1]; |
|
| 357 | - if (!empty($tmp[2])) |
|
| 358 | - $savemethod = $tmp[2]; |
|
| 366 | + if (!empty($tmp[1])) { |
|
| 367 | + $inputOption = $tmp[1]; |
|
| 368 | + } |
|
| 369 | + if (!empty($tmp[2])) { |
|
| 370 | + $savemethod = $tmp[2]; |
|
| 371 | + } |
|
| 359 | 372 | $out .= '<input id="width_' . $htmlname . '" value="' . $inputOption . '" type="hidden"/>' . "\n"; |
| 360 | - } |
|
| 361 | - else if ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) {
|
|
| 373 | + } else if ((preg_match('/^day$/', $inputType)) || (preg_match('/^datepicker/', $inputType)) || (preg_match('/^datehourpicker/', $inputType))) {
|
|
| 362 | 374 | $tmp = explode(':', $inputType);
|
| 363 | 375 | $inputType = $tmp[0]; |
| 364 | - if (!empty($tmp[1])) |
|
| 365 | - $inputOption = $tmp[1]; |
|
| 366 | - if (!empty($tmp[2])) |
|
| 367 | - $savemethod = $tmp[2]; |
|
| 376 | + if (!empty($tmp[1])) { |
|
| 377 | + $inputOption = $tmp[1]; |
|
| 378 | + } |
|
| 379 | + if (!empty($tmp[2])) { |
|
| 380 | + $savemethod = $tmp[2]; |
|
| 381 | + } |
|
| 368 | 382 | |
| 369 | 383 | $out .= '<input id="timestamp" type="hidden"/>' . "\n"; // Use for timestamp format |
| 370 | - } |
|
| 371 | - else if (preg_match('/^(select|autocomplete)/', $inputType)) {
|
|
| 384 | + } else if (preg_match('/^(select|autocomplete)/', $inputType)) {
|
|
| 372 | 385 | $tmp = explode(':', $inputType);
|
| 373 | 386 | $inputType = $tmp[0]; |
| 374 | 387 | $loadmethod = $tmp[1]; |
| 375 | - if (!empty($tmp[2])) |
|
| 376 | - $savemethod = $tmp[2]; |
|
| 377 | - if (!empty($tmp[3])) |
|
| 378 | - $button_only = true; |
|
| 379 | - } |
|
| 380 | - else if (preg_match('/^textarea/', $inputType)) {
|
|
| 388 | + if (!empty($tmp[2])) { |
|
| 389 | + $savemethod = $tmp[2]; |
|
| 390 | + } |
|
| 391 | + if (!empty($tmp[3])) { |
|
| 392 | + $button_only = true; |
|
| 393 | + } |
|
| 394 | + } else if (preg_match('/^textarea/', $inputType)) {
|
|
| 381 | 395 | $tmp = explode(':', $inputType);
|
| 382 | 396 | $inputType = $tmp[0]; |
| 383 | 397 | $rows = (empty($tmp[1]) ? '8' : $tmp[1]); |
@@ -386,12 +400,15 @@ discard block |
||
| 386 | 400 | $tmp = explode(':', $inputType);
|
| 387 | 401 | $inputType = $tmp[0]; |
| 388 | 402 | $toolbar = $tmp[1]; |
| 389 | - if (!empty($tmp[2])) |
|
| 390 | - $width = $tmp[2]; |
|
| 391 | - if (!empty($tmp[3])) |
|
| 392 | - $heigth = $tmp[3]; |
|
| 393 | - if (!empty($tmp[4])) |
|
| 394 | - $savemethod = $tmp[4]; |
|
| 403 | + if (!empty($tmp[2])) { |
|
| 404 | + $width = $tmp[2]; |
|
| 405 | + } |
|
| 406 | + if (!empty($tmp[3])) { |
|
| 407 | + $heigth = $tmp[3]; |
|
| 408 | + } |
|
| 409 | + if (!empty($tmp[4])) { |
|
| 410 | + $savemethod = $tmp[4]; |
|
| 411 | + } |
|
| 395 | 412 | |
| 396 | 413 | if (!empty(Globals::$conf->fckeditor->enabled)) {
|
| 397 | 414 | $out .= '<input id="ckeditor_toolbar" value="' . $toolbar . '" type="hidden"/>' . "\n"; |
@@ -404,18 +421,23 @@ discard block |
||
| 404 | 421 | $out .= '<input id="table_element_' . $htmlname . '" value="' . $table_element . '" type="hidden"/>' . "\n"; |
| 405 | 422 | $out .= '<input id="fk_element_' . $htmlname . '" value="' . $fk_element . '" type="hidden"/>' . "\n"; |
| 406 | 423 | $out .= '<input id="loadmethod_' . $htmlname . '" value="' . $loadmethod . '" type="hidden"/>' . "\n"; |
| 407 | - if (!empty($savemethod)) |
|
| 408 | - $out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . "\n"; |
|
| 409 | - if (!empty($ext_element)) |
|
| 410 | - $out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . "\n"; |
|
| 424 | + if (!empty($savemethod)) { |
|
| 425 | + $out .= '<input id="savemethod_' . $htmlname . '" value="' . $savemethod . '" type="hidden"/>' . "\n"; |
|
| 426 | + } |
|
| 427 | + if (!empty($ext_element)) { |
|
| 428 | + $out .= '<input id="ext_element_' . $htmlname . '" value="' . $ext_element . '" type="hidden"/>' . "\n"; |
|
| 429 | + } |
|
| 411 | 430 | if (!empty($custommsg)) {
|
| 412 | 431 | if (is_array($custommsg)) {
|
| 413 | - if (!empty($custommsg['success'])) |
|
| 414 | - $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg['success'] . '" type="hidden"/>' . "\n"; |
|
| 415 | - if (!empty($custommsg['error'])) |
|
| 416 | - $out .= '<input id="errormsg_' . $htmlname . '" value="' . $custommsg['error'] . '" type="hidden"/>' . "\n"; |
|
| 417 | - } else |
|
| 418 | - $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg . '" type="hidden"/>' . "\n"; |
|
| 432 | + if (!empty($custommsg['success'])) { |
|
| 433 | + $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg['success'] . '" type="hidden"/>' . "\n"; |
|
| 434 | + } |
|
| 435 | + if (!empty($custommsg['error'])) { |
|
| 436 | + $out .= '<input id="errormsg_' . $htmlname . '" value="' . $custommsg['error'] . '" type="hidden"/>' . "\n"; |
|
| 437 | + } |
|
| 438 | + } else { |
|
| 439 | + $out .= '<input id="successmsg_' . $htmlname . '" value="' . $custommsg . '" type="hidden"/>' . "\n"; |
|
| 440 | + } |
|
| 419 | 441 | } |
| 420 | 442 | if ($inputType == 'textarea') {
|
| 421 | 443 | $out .= '<input id="textarea_' . $htmlname . '_rows" value="' . $rows . '" type="hidden"/>' . "\n"; |
@@ -567,20 +589,22 @@ discard block |
||
| 567 | 589 | global $conf, $langs; |
| 568 | 590 | |
| 569 | 591 | $alt = ''; |
| 570 | - if ($tooltiptrigger) |
|
| 571 | - $alt = $langs->transnoentitiesnoconv("ClickToShowHelp");
|
|
| 592 | + if ($tooltiptrigger) { |
|
| 593 | + $alt = $langs->transnoentitiesnoconv("ClickToShowHelp"); |
|
| 594 | + } |
|
| 572 | 595 | |
| 573 | 596 | //For backwards compatibility |
| 574 | - if ($type == '0') |
|
| 575 | - $type = 'info'; |
|
| 576 | - elseif ($type == '1') |
|
| 577 | - $type = 'help'; |
|
| 597 | + if ($type == '0') { |
|
| 598 | + $type = 'info'; |
|
| 599 | + } elseif ($type == '1') { |
|
| 600 | + $type = 'help'; |
|
| 601 | + } |
|
| 578 | 602 | |
| 579 | 603 | // If info or help with no javascript, show only text |
| 580 | 604 | if (empty(Globals::$conf->use_javascript_ajax)) {
|
| 581 | - if ($type == 'info' || $type == 'help') |
|
| 582 | - return $text; |
|
| 583 | - else {
|
|
| 605 | + if ($type == 'info' || $type == 'help') { |
|
| 606 | + return $text; |
|
| 607 | + } else {
|
|
| 584 | 608 | $alt = $htmltext; |
| 585 | 609 | $htmltext = ''; |
| 586 | 610 | } |
@@ -588,27 +612,30 @@ discard block |
||
| 588 | 612 | |
| 589 | 613 | // If info or help with smartphone, show only text (tooltip hover can't works) |
| 590 | 614 | if (!empty(Globals::$conf->dol_no_mouse_hover) && empty($tooltiptrigger)) {
|
| 591 | - if ($type == 'info' || $type == 'help') |
|
| 592 | - return $text; |
|
| 615 | + if ($type == 'info' || $type == 'help') { |
|
| 616 | + return $text; |
|
| 617 | + } |
|
| 593 | 618 | } |
| 594 | 619 | // If info or help with smartphone, show only text (tooltip on lick does not works with dialog on smaprtphone) |
| 595 | 620 | if (!empty(Globals::$conf->dol_no_mouse_hover) && !empty($tooltiptrigger)) {
|
| 596 | - if ($type == 'info' || $type == 'help') |
|
| 597 | - return $text; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - if ($type == 'info') |
|
| 601 | - $img = img_help(0, $alt); |
|
| 602 | - elseif ($type == 'help') |
|
| 603 | - $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt); |
|
| 604 | - elseif ($type == 'superadmin') |
|
| 605 | - $img = img_picto($alt, 'redstar'); |
|
| 606 | - elseif ($type == 'admin') |
|
| 607 | - $img = img_picto($alt, 'star'); |
|
| 608 | - elseif ($type == 'warning') |
|
| 609 | - $img = img_warning($alt); |
|
| 610 | - else |
|
| 611 | - $img = img_picto($alt, $type); |
|
| 621 | + if ($type == 'info' || $type == 'help') { |
|
| 622 | + return $text; |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + if ($type == 'info') { |
|
| 627 | + $img = img_help(0, $alt); |
|
| 628 | + } elseif ($type == 'help') { |
|
| 629 | + $img = img_help(($tooltiptrigger != '' ? 2 : 1), $alt); |
|
| 630 | + } elseif ($type == 'superadmin') { |
|
| 631 | + $img = img_picto($alt, 'redstar'); |
|
| 632 | + } elseif ($type == 'admin') { |
|
| 633 | + $img = img_picto($alt, 'star'); |
|
| 634 | + } elseif ($type == 'warning') { |
|
| 635 | + $img = img_warning($alt); |
|
| 636 | + } else { |
|
| 637 | + $img = img_picto($alt, $type); |
|
| 638 | + } |
|
| 612 | 639 | |
| 613 | 640 | return $this->textwithtooltip($text, $htmltext, (($tooltiptrigger && !$img) ? 3 : 2), $direction, $img, $extracss, $notabs, '', $noencodehtmltext, $tooltiptrigger, $forcenowrap); |
| 614 | 641 | } |
@@ -625,8 +652,9 @@ discard block |
||
| 625 | 652 | {
|
| 626 | 653 | global $conf, $langs, $hookmanager; |
| 627 | 654 | |
| 628 | - if (count($arrayofaction) == 0) |
|
| 629 | - return; |
|
| 655 | + if (count($arrayofaction) == 0) { |
|
| 656 | + return; |
|
| 657 | + } |
|
| 630 | 658 | |
| 631 | 659 | $disabled = 0; |
| 632 | 660 | $ret = '<div class="centpercent center">'; |
@@ -758,10 +786,11 @@ discard block |
||
| 758 | 786 | $i++; |
| 759 | 787 | } |
| 760 | 788 | |
| 761 | - if (empty($disablefavorites)) |
|
| 762 | - array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray); |
|
| 763 | - else |
|
| 764 | - $countryArray = dol_sort_array($countryArray, 'label'); |
|
| 789 | + if (empty($disablefavorites)) { |
|
| 790 | + array_multisort($favorite, SORT_DESC, $label, SORT_ASC, $countryArray); |
|
| 791 | + } else { |
|
| 792 | + $countryArray = dol_sort_array($countryArray, 'label'); |
|
| 793 | + } |
|
| 765 | 794 | |
| 766 | 795 | if ($showempty) {
|
| 767 | 796 | $out .= '<option value=""> </option>' . "\n"; |
@@ -771,8 +800,9 @@ discard block |
||
| 771 | 800 | //if ($showempty) $out.= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
| 772 | 801 | $out .= '<option value="special_allnotme"' . ($selected == 'special_allnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>';
|
| 773 | 802 | $out .= '<option value="special_eec"' . ($selected == 'special_eec' ? ' selected' : '') . '>' . $langs->trans("CountriesInEEC") . '</option>';
|
| 774 | - if ($mysoc->isInEEC()) |
|
| 775 | - $out .= '<option value="special_eecnotme"' . ($selected == 'special_eecnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>';
|
|
| 803 | + if ($mysoc->isInEEC()) { |
|
| 804 | + $out .= '<option value="special_eecnotme"' . ($selected == 'special_eecnotme' ? ' selected' : '') . '>' . $langs->trans("CountriesInEECExceptMe", $langs->transnoentitiesnoconv("Country" . $mysoc->country_code)) . '</option>'; |
|
| 805 | + } |
|
| 776 | 806 | $out .= '<option value="special_noteec"' . ($selected == 'special_noteec' ? ' selected' : '') . '>' . $langs->trans("CountriesNotInEEC") . '</option>';
|
| 777 | 807 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
| 778 | 808 | } |
@@ -783,8 +813,9 @@ discard block |
||
| 783 | 813 | continue; |
| 784 | 814 | } |
| 785 | 815 | |
| 786 | - if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) |
|
| 787 | - $atleastonefavorite++; |
|
| 816 | + if (empty($disablefavorites) && $row['favorite'] && $row['code_iso']) { |
|
| 817 | + $atleastonefavorite++; |
|
| 818 | + } |
|
| 788 | 819 | if (empty($row['favorite']) && $atleastonefavorite) {
|
| 789 | 820 | $atleastonefavorite = 0; |
| 790 | 821 | $out .= '<option value="" disabled class="selectoptiondisabledwhite">--------------</option>'; |
@@ -795,18 +826,19 @@ discard block |
||
| 795 | 826 | } else {
|
| 796 | 827 | $out .= '<option value="' . ($usecodeaskey ? ($usecodeaskey == 'code2' ? $row['code_iso'] : $row['code_iso3']) : $row['rowid']) . '">'; |
| 797 | 828 | } |
| 798 | - if ($row['label']) |
|
| 799 | - $out .= dol_trunc($row['label'], $maxlength, 'middle'); |
|
| 800 | - else |
|
| 801 | - $out .= ' '; |
|
| 802 | - if ($row['code_iso']) |
|
| 803 | - $out .= ' (' . $row['code_iso'] . ')';
|
|
| 829 | + if ($row['label']) { |
|
| 830 | + $out .= dol_trunc($row['label'], $maxlength, 'middle'); |
|
| 831 | + } else { |
|
| 832 | + $out .= ' '; |
|
| 833 | + } |
|
| 834 | + if ($row['code_iso']) { |
|
| 835 | + $out .= ' (' . $row['code_iso'] . ')'; |
|
| 836 | + } |
|
| 804 | 837 | $out .= '</option>'; |
| 805 | 838 | } |
| 806 | 839 | } |
| 807 | 840 | $out .= '</select>'; |
| 808 | - } |
|
| 809 | - else {
|
|
| 841 | + } else {
|
|
| 810 | 842 | AlDolUtils::dol_print_error($this->db); |
| 811 | 843 | } |
| 812 | 844 | |
@@ -880,8 +912,9 @@ discard block |
||
| 880 | 912 | $out .= '<option value="' . $row['rowid'] . '">'; |
| 881 | 913 | } |
| 882 | 914 | |
| 883 | - if ($row['code']) |
|
| 884 | - $out .= $row['code']; |
|
| 915 | + if ($row['code']) { |
|
| 916 | + $out .= $row['code']; |
|
| 917 | + } |
|
| 885 | 918 | |
| 886 | 919 | $out .= '</option>'; |
| 887 | 920 | } |
@@ -919,24 +952,28 @@ discard block |
||
| 919 | 952 | |
| 920 | 953 | // If product & services are enabled or both disabled. |
| 921 | 954 | if ($forceall == 1 || (empty($forceall) && !empty(Globals::$conf->product->enabled) && !empty(Globals::$conf->service->enabled)) || (empty($forceall) && empty(Globals::$conf->product->enabled) && empty(Globals::$conf->service->enabled))) {
|
| 922 | - if (empty($hidetext)) |
|
| 923 | - print $langs->trans("Type") . ': ';
|
|
| 955 | + if (empty($hidetext)) { |
|
| 956 | + print $langs->trans("Type") . ': '; |
|
| 957 | + } |
|
| 924 | 958 | print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
| 925 | 959 | if ($showempty) {
|
| 926 | 960 | print '<option value="-1"'; |
| 927 | - if ($selected == -1) |
|
| 928 | - print ' selected'; |
|
| 961 | + if ($selected == -1) { |
|
| 962 | + print ' selected'; |
|
| 963 | + } |
|
| 929 | 964 | print '> </option>'; |
| 930 | 965 | } |
| 931 | 966 | |
| 932 | 967 | print '<option value="0"'; |
| 933 | - if (0 == $selected) |
|
| 934 | - print ' selected'; |
|
| 968 | + if (0 == $selected) { |
|
| 969 | + print ' selected'; |
|
| 970 | + } |
|
| 935 | 971 | print '>' . $langs->trans("Product");
|
| 936 | 972 | |
| 937 | 973 | print '<option value="1"'; |
| 938 | - if (1 == $selected) |
|
| 939 | - print ' selected'; |
|
| 974 | + if (1 == $selected) { |
|
| 975 | + print ' selected'; |
|
| 976 | + } |
|
| 940 | 977 | print '>' . $langs->trans("Service");
|
| 941 | 978 | |
| 942 | 979 | print '</select>'; |
@@ -967,8 +1004,10 @@ discard block |
||
| 967 | 1004 | global $langs; |
| 968 | 1005 | |
| 969 | 1006 | $num = count($this->cache_types_fees); |
| 970 | - if ($num > 0) |
|
| 971 | - return 0; // Cache already loaded |
|
| 1007 | + if ($num > 0) { |
|
| 1008 | + return 0; |
|
| 1009 | + } |
|
| 1010 | + // Cache already loaded |
|
| 972 | 1011 | |
| 973 | 1012 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 974 | 1013 | |
@@ -1022,23 +1061,26 @@ discard block |
||
| 1022 | 1061 | print '<select id="select_' . $htmlname . '" class="flat" name="' . $htmlname . '">'; |
| 1023 | 1062 | if ($showempty) {
|
| 1024 | 1063 | print '<option value="-1"'; |
| 1025 | - if ($selected == -1) |
|
| 1026 | - print ' selected'; |
|
| 1064 | + if ($selected == -1) { |
|
| 1065 | + print ' selected'; |
|
| 1066 | + } |
|
| 1027 | 1067 | print '> </option>'; |
| 1028 | 1068 | } |
| 1029 | 1069 | |
| 1030 | 1070 | foreach ($this->cache_types_fees as $key => $value) {
|
| 1031 | 1071 | print '<option value="' . $key . '"'; |
| 1032 | - if ($key == $selected) |
|
| 1033 | - print ' selected'; |
|
| 1072 | + if ($key == $selected) { |
|
| 1073 | + print ' selected'; |
|
| 1074 | + } |
|
| 1034 | 1075 | print '>'; |
| 1035 | 1076 | print $value; |
| 1036 | 1077 | print '</option>'; |
| 1037 | 1078 | } |
| 1038 | 1079 | |
| 1039 | 1080 | print '</select>'; |
| 1040 | - if ($user->admin) |
|
| 1041 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 1081 | + if ($user->admin) { |
|
| 1082 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 1083 | + } |
|
| 1042 | 1084 | } |
| 1043 | 1085 | |
| 1044 | 1086 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -1101,9 +1143,9 @@ discard block |
||
| 1101 | 1143 | $urloption = 'htmlname=' . $htmlname . '&outjson=1&filter=' . $filter . ($showtype ? '&showtype=' . $showtype : ''); |
| 1102 | 1144 | $out .= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT . '/societe/ajax/company.php', $urloption, Globals::$conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); |
| 1103 | 1145 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
|
| 1104 | - if (empty($hidelabel)) |
|
| 1105 | - print $langs->trans("RefOrLabel") . ' : ';
|
|
| 1106 | - else if ($hidelabel > 1) {
|
|
| 1146 | + if (empty($hidelabel)) { |
|
| 1147 | + print $langs->trans("RefOrLabel") . ' : '; |
|
| 1148 | + } else if ($hidelabel > 1) {
|
|
| 1107 | 1149 | $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
|
| 1108 | 1150 | if ($hidelabel == 2) {
|
| 1109 | 1151 | $out .= img_picto($langs->trans("Search"), 'search');
|
@@ -1150,10 +1192,11 @@ discard block |
||
| 1150 | 1192 | $num = 0; |
| 1151 | 1193 | $outarray = array(); |
| 1152 | 1194 | |
| 1153 | - if ($selected === '') |
|
| 1154 | - $selected = array(); |
|
| 1155 | - else if (!is_array($selected)) |
|
| 1156 | - $selected = array($selected); |
|
| 1195 | + if ($selected === '') { |
|
| 1196 | + $selected = array(); |
|
| 1197 | + } else if (!is_array($selected)) { |
|
| 1198 | + $selected = array($selected); |
|
| 1199 | + } |
|
| 1157 | 1200 | |
| 1158 | 1201 | // Clean $filter that may contains sql conditions so sql code |
| 1159 | 1202 | if (function_exists('testSqlAndScriptInject')) {
|
@@ -1171,21 +1214,26 @@ discard block |
||
| 1171 | 1214 | } |
| 1172 | 1215 | |
| 1173 | 1216 | $sql .= " FROM (" . MAIN_DB_PREFIX . "societe as s";
|
| 1174 | - if (!$user->rights->societe->client->voir && !$user->socid) |
|
| 1175 | - $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 1217 | + if (!$user->rights->societe->client->voir && !$user->socid) { |
|
| 1218 | + $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 1219 | + } |
|
| 1176 | 1220 | $sql .= " )"; |
| 1177 | 1221 | if (Globals::$conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
|
| 1178 | 1222 | $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "c_country as dictp ON dictp.rowid=s.fk_pays"; |
| 1179 | 1223 | } |
| 1180 | 1224 | $sql .= " WHERE s.entity IN (" . getEntity('societe') . ")";
|
| 1181 | - if (!empty($user->socid)) |
|
| 1182 | - $sql .= " AND s.rowid = " . $user->socid; |
|
| 1183 | - if ($filter) |
|
| 1184 | - $sql .= " AND (" . $filter . ")";
|
|
| 1185 | - if (!$user->rights->societe->client->voir && !$user->socid) |
|
| 1186 | - $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 1187 | - if (!empty(Globals::$conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) |
|
| 1188 | - $sql .= " AND s.status <> 0"; |
|
| 1225 | + if (!empty($user->socid)) { |
|
| 1226 | + $sql .= " AND s.rowid = " . $user->socid; |
|
| 1227 | + } |
|
| 1228 | + if ($filter) { |
|
| 1229 | + $sql .= " AND (" . $filter . ")"; |
|
| 1230 | + } |
|
| 1231 | + if (!$user->rights->societe->client->voir && !$user->socid) { |
|
| 1232 | + $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 1233 | + } |
|
| 1234 | + if (!empty(Globals::$conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) { |
|
| 1235 | + $sql .= " AND s.status <> 0"; |
|
| 1236 | + } |
|
| 1189 | 1237 | // Add criteria |
| 1190 | 1238 | if ($filterkey && $filterkey != '') {
|
| 1191 | 1239 | $sql .= " AND (";
|
@@ -1193,16 +1241,19 @@ discard block |
||
| 1193 | 1241 | // For natural search |
| 1194 | 1242 | $scrit = explode(' ', $filterkey);
|
| 1195 | 1243 | $i = 0; |
| 1196 | - if (count($scrit) > 1) |
|
| 1197 | - $sql .= "(";
|
|
| 1244 | + if (count($scrit) > 1) { |
|
| 1245 | + $sql .= "("; |
|
| 1246 | + } |
|
| 1198 | 1247 | foreach ($scrit as $crit) {
|
| 1199 | - if ($i > 0) |
|
| 1200 | - $sql .= " AND "; |
|
| 1248 | + if ($i > 0) { |
|
| 1249 | + $sql .= " AND "; |
|
| 1250 | + } |
|
| 1201 | 1251 | $sql .= "(s.nom LIKE '" . $this->db->escape($prefix . $crit) . "%')"; |
| 1202 | 1252 | $i++; |
| 1203 | 1253 | } |
| 1204 | - if (count($scrit) > 1) |
|
| 1205 | - $sql .= ")"; |
|
| 1254 | + if (count($scrit) > 1) { |
|
| 1255 | + $sql .= ")"; |
|
| 1256 | + } |
|
| 1206 | 1257 | if (!empty(Globals::$conf->barcode->enabled)) {
|
| 1207 | 1258 | $sql .= " OR s.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
| 1208 | 1259 | } |
@@ -1228,13 +1279,15 @@ discard block |
||
| 1228 | 1279 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
| 1229 | 1280 | //if (! empty(Globals::$conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
| 1230 | 1281 | if (!empty(Globals::$conf->global->COMPANY_USE_SEARCH_TO_SELECT)) {
|
| 1231 | - if ($showempty && !is_numeric($showempty)) |
|
| 1232 | - $textifempty = $langs->trans($showempty); |
|
| 1233 | - else |
|
| 1234 | - $textifempty .= $langs->trans("All");
|
|
| 1282 | + if ($showempty && !is_numeric($showempty)) { |
|
| 1283 | + $textifempty = $langs->trans($showempty); |
|
| 1284 | + } else { |
|
| 1285 | + $textifempty .= $langs->trans("All"); |
|
| 1286 | + } |
|
| 1235 | 1287 | } |
| 1236 | - if ($showempty) |
|
| 1237 | - $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 1288 | + if ($showempty) { |
|
| 1289 | + $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 1290 | + } |
|
| 1238 | 1291 | |
| 1239 | 1292 | $num = $this->db->num_rows($resql); |
| 1240 | 1293 | $i = 0; |
@@ -1259,16 +1312,21 @@ discard block |
||
| 1259 | 1312 | } |
| 1260 | 1313 | |
| 1261 | 1314 | if ($showtype) {
|
| 1262 | - if ($obj->client || $obj->fournisseur) |
|
| 1263 | - $label .= ' (';
|
|
| 1264 | - if ($obj->client == 1 || $obj->client == 3) |
|
| 1265 | - $label .= $langs->trans("Customer");
|
|
| 1266 | - if ($obj->client == 2 || $obj->client == 3) |
|
| 1267 | - $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect");
|
|
| 1268 | - if ($obj->fournisseur) |
|
| 1269 | - $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier");
|
|
| 1270 | - if ($obj->client || $obj->fournisseur) |
|
| 1271 | - $label .= ')'; |
|
| 1315 | + if ($obj->client || $obj->fournisseur) { |
|
| 1316 | + $label .= ' ('; |
|
| 1317 | + } |
|
| 1318 | + if ($obj->client == 1 || $obj->client == 3) { |
|
| 1319 | + $label .= $langs->trans("Customer"); |
|
| 1320 | + } |
|
| 1321 | + if ($obj->client == 2 || $obj->client == 3) { |
|
| 1322 | + $label .= ($obj->client == 3 ? ', ' : '') . $langs->trans("Prospect"); |
|
| 1323 | + } |
|
| 1324 | + if ($obj->fournisseur) { |
|
| 1325 | + $label .= ($obj->client ? ', ' : '') . $langs->trans("Supplier"); |
|
| 1326 | + } |
|
| 1327 | + if ($obj->client || $obj->fournisseur) { |
|
| 1328 | + $label .= ')'; |
|
| 1329 | + } |
|
| 1272 | 1330 | } |
| 1273 | 1331 | |
| 1274 | 1332 | if (Globals::$conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST) {
|
@@ -1289,20 +1347,21 @@ discard block |
||
| 1289 | 1347 | } |
| 1290 | 1348 | |
| 1291 | 1349 | $i++; |
| 1292 | - if (($i % 10) == 0) |
|
| 1293 | - $out .= "\n"; |
|
| 1350 | + if (($i % 10) == 0) { |
|
| 1351 | + $out .= "\n"; |
|
| 1352 | + } |
|
| 1294 | 1353 | } |
| 1295 | 1354 | } |
| 1296 | 1355 | $out .= '</select>' . "\n"; |
| 1297 | - } |
|
| 1298 | - else {
|
|
| 1356 | + } else {
|
|
| 1299 | 1357 | AlDolUtils::dol_print_error($this->db); |
| 1300 | 1358 | } |
| 1301 | 1359 | |
| 1302 | 1360 | $this->result = array('nbofthirdparties' => $num);
|
| 1303 | 1361 | |
| 1304 | - if ($outputmode) |
|
| 1305 | - return $outarray; |
|
| 1362 | + if ($outputmode) { |
|
| 1363 | + return $outarray; |
|
| 1364 | + } |
|
| 1306 | 1365 | return $out; |
| 1307 | 1366 | } |
| 1308 | 1367 | |
@@ -1328,8 +1387,9 @@ discard block |
||
| 1328 | 1387 | $sql .= " FROM " . MAIN_DB_PREFIX . "societe_remise_except as re"; |
| 1329 | 1388 | $sql .= " WHERE re.fk_soc = " . (int) $socid; |
| 1330 | 1389 | $sql .= " AND re.entity = " . Globals::$conf->entity; |
| 1331 | - if ($filter) |
|
| 1332 | - $sql .= " AND " . $filter; |
|
| 1390 | + if ($filter) { |
|
| 1391 | + $sql .= " AND " . $filter; |
|
| 1392 | + } |
|
| 1333 | 1393 | $sql .= " ORDER BY re.description ASC"; |
| 1334 | 1394 | |
| 1335 | 1395 | dol_syslog(get_class($this) . "::select_remises", LOG_DEBUG); |
@@ -1346,18 +1406,23 @@ discard block |
||
| 1346 | 1406 | while ($i < $num) {
|
| 1347 | 1407 | $obj = $this->db->fetch_object($resql); |
| 1348 | 1408 | $desc = dol_trunc($obj->description, 40); |
| 1349 | - if (preg_match('/\(CREDIT_NOTE\)/', $desc))
|
|
| 1350 | - $desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc);
|
|
| 1351 | - if (preg_match('/\(DEPOSIT\)/', $desc))
|
|
| 1352 | - $desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc);
|
|
| 1353 | - if (preg_match('/\(EXCESS RECEIVED\)/', $desc))
|
|
| 1354 | - $desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc);
|
|
| 1355 | - if (preg_match('/\(EXCESS PAID\)/', $desc))
|
|
| 1356 | - $desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc);
|
|
| 1409 | + if (preg_match('/\(CREDIT_NOTE\)/', $desc)) { |
|
| 1410 | + $desc = preg_replace('/\(CREDIT_NOTE\)/', $langs->trans("CreditNote"), $desc); |
|
| 1411 | + } |
|
| 1412 | + if (preg_match('/\(DEPOSIT\)/', $desc)) { |
|
| 1413 | + $desc = preg_replace('/\(DEPOSIT\)/', $langs->trans("Deposit"), $desc); |
|
| 1414 | + } |
|
| 1415 | + if (preg_match('/\(EXCESS RECEIVED\)/', $desc)) { |
|
| 1416 | + $desc = preg_replace('/\(EXCESS RECEIVED\)/', $langs->trans("ExcessReceived"), $desc); |
|
| 1417 | + } |
|
| 1418 | + if (preg_match('/\(EXCESS PAID\)/', $desc)) { |
|
| 1419 | + $desc = preg_replace('/\(EXCESS PAID\)/', $langs->trans("ExcessPaid"), $desc); |
|
| 1420 | + } |
|
| 1357 | 1421 | |
| 1358 | 1422 | $selectstring = ''; |
| 1359 | - if ($selected > 0 && $selected == $obj->rowid) |
|
| 1360 | - $selectstring = ' selected'; |
|
| 1423 | + if ($selected > 0 && $selected == $obj->rowid) { |
|
| 1424 | + $selectstring = ' selected'; |
|
| 1425 | + } |
|
| 1361 | 1426 | |
| 1362 | 1427 | $disabled = ''; |
| 1363 | 1428 | if ($maxvalue > 0 && $obj->amount_ttc > $maxvalue) {
|
@@ -1367,8 +1432,9 @@ discard block |
||
| 1367 | 1432 | |
| 1368 | 1433 | if (!empty(Globals::$conf->global->MAIN_SHOW_FACNUMBER_IN_DISCOUNT_LIST) && !empty($obj->fk_facture_source)) {
|
| 1369 | 1434 | $tmpfac = new Facture($this->db); |
| 1370 | - if ($tmpfac->fetch($obj->fk_facture_source) > 0) |
|
| 1371 | - $desc = $desc . ' - ' . $tmpfac->ref; |
|
| 1435 | + if ($tmpfac->fetch($obj->fk_facture_source) > 0) { |
|
| 1436 | + $desc = $desc . ' - ' . $tmpfac->ref; |
|
| 1437 | + } |
|
| 1372 | 1438 | } |
| 1373 | 1439 | |
| 1374 | 1440 | print '<option value="' . $obj->rowid . '"' . $selectstring . $disabled . '>' . $desc . ' (' . price($obj->amount_ht) . ' ' . $langs->trans("HT") . ' - ' . price($obj->amount_ttc) . ' ' . $langs->trans("TTC") . ')</option>';
|
@@ -1377,8 +1443,7 @@ discard block |
||
| 1377 | 1443 | } |
| 1378 | 1444 | print '</select>'; |
| 1379 | 1445 | return $qualifiedlines; |
| 1380 | - } |
|
| 1381 | - else {
|
|
| 1446 | + } else {
|
|
| 1382 | 1447 | AlDolUtils::dol_print_error($this->db); |
| 1383 | 1448 | return -1; |
| 1384 | 1449 | } |
@@ -1441,13 +1506,15 @@ discard block |
||
| 1441 | 1506 | |
| 1442 | 1507 | $langs->load('companies');
|
| 1443 | 1508 | |
| 1444 | - if (empty($htmlid)) |
|
| 1445 | - $htmlid = $htmlname; |
|
| 1509 | + if (empty($htmlid)) { |
|
| 1510 | + $htmlid = $htmlname; |
|
| 1511 | + } |
|
| 1446 | 1512 | |
| 1447 | - if ($selected === '') |
|
| 1448 | - $selected = array(); |
|
| 1449 | - else if (!is_array($selected)) |
|
| 1450 | - $selected = array($selected); |
|
| 1513 | + if ($selected === '') { |
|
| 1514 | + $selected = array(); |
|
| 1515 | + } else if (!is_array($selected)) { |
|
| 1516 | + $selected = array($selected); |
|
| 1517 | + } |
|
| 1451 | 1518 | $out = ''; |
| 1452 | 1519 | |
| 1453 | 1520 | if (!is_object($hookmanager)) {
|
@@ -1457,16 +1524,20 @@ discard block |
||
| 1457 | 1524 | |
| 1458 | 1525 | // We search third parties |
| 1459 | 1526 | $sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste"; |
| 1460 | - if ($showsoc > 0) |
|
| 1461 | - $sql .= " , s.nom as company"; |
|
| 1527 | + if ($showsoc > 0) { |
|
| 1528 | + $sql .= " , s.nom as company"; |
|
| 1529 | + } |
|
| 1462 | 1530 | $sql .= " FROM " . MAIN_DB_PREFIX . "socpeople as sp"; |
| 1463 | - if ($showsoc > 0) |
|
| 1464 | - $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc"; |
|
| 1531 | + if ($showsoc > 0) { |
|
| 1532 | + $sql .= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid=sp.fk_soc"; |
|
| 1533 | + } |
|
| 1465 | 1534 | $sql .= " WHERE sp.entity IN (" . getEntity('socpeople') . ")";
|
| 1466 | - if ($socid > 0 || $socid == -1) |
|
| 1467 | - $sql .= " AND sp.fk_soc=" . $socid; |
|
| 1468 | - if (!empty(Globals::$conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) |
|
| 1469 | - $sql .= " AND sp.statut <> 0"; |
|
| 1535 | + if ($socid > 0 || $socid == -1) { |
|
| 1536 | + $sql .= " AND sp.fk_soc=" . $socid; |
|
| 1537 | + } |
|
| 1538 | + if (!empty(Globals::$conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) { |
|
| 1539 | + $sql .= " AND sp.statut <> 0"; |
|
| 1540 | + } |
|
| 1470 | 1541 | $sql .= " ORDER BY sp.lastname ASC"; |
| 1471 | 1542 | |
| 1472 | 1543 | dol_syslog(get_class($this) . "::select_contacts", LOG_DEBUG); |
@@ -1479,12 +1550,15 @@ discard block |
||
| 1479 | 1550 | $out .= ajax_combobox($htmlid, $events, Globals::$conf->global->CONTACT_USE_SEARCH_TO_SELECT); |
| 1480 | 1551 | } |
| 1481 | 1552 | |
| 1482 | - if ($htmlname != 'none' || $options_only) |
|
| 1483 | - $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlid . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . (!empty($moreparam) ? $moreparam : '') . '>'; |
|
| 1484 | - if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) |
|
| 1485 | - $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '> </option>'; |
|
| 1486 | - if ($showempty == 2) |
|
| 1487 | - $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '>' . $langs->trans("Internal") . '</option>';
|
|
| 1553 | + if ($htmlname != 'none' || $options_only) { |
|
| 1554 | + $out .= '<select class="flat' . ($moreclass ? ' ' . $moreclass : '') . '" id="' . $htmlid . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . (!empty($moreparam) ? $moreparam : '') . '>'; |
|
| 1555 | + } |
|
| 1556 | + if (($showempty == 1 || ($showempty == 3 && $num > 1)) && !$multiple) { |
|
| 1557 | + $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '> </option>'; |
|
| 1558 | + } |
|
| 1559 | + if ($showempty == 2) { |
|
| 1560 | + $out .= '<option value="0"' . (in_array(0, $selected) ? ' selected' : '') . '>' . $langs->trans("Internal") . '</option>'; |
|
| 1561 | + } |
|
| 1488 | 1562 | $num = $this->db->num_rows($resql); |
| 1489 | 1563 | $i = 0; |
| 1490 | 1564 | if ($num) {
|
@@ -1500,49 +1574,56 @@ discard block |
||
| 1500 | 1574 | if ($obj->statut == 1) {
|
| 1501 | 1575 | if ($htmlname != 'none') {
|
| 1502 | 1576 | $disabled = 0; |
| 1503 | - if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) |
|
| 1504 | - $disabled = 1; |
|
| 1505 | - if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) |
|
| 1506 | - $disabled = 1; |
|
| 1577 | + if (is_array($exclude) && count($exclude) && in_array($obj->rowid, $exclude)) { |
|
| 1578 | + $disabled = 1; |
|
| 1579 | + } |
|
| 1580 | + if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) { |
|
| 1581 | + $disabled = 1; |
|
| 1582 | + } |
|
| 1507 | 1583 | if (!empty($selected) && in_array($obj->rowid, $selected)) {
|
| 1508 | 1584 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1509 | - if ($disabled) |
|
| 1510 | - $out .= ' disabled'; |
|
| 1585 | + if ($disabled) { |
|
| 1586 | + $out .= ' disabled'; |
|
| 1587 | + } |
|
| 1511 | 1588 | $out .= ' selected>'; |
| 1512 | 1589 | $out .= $contactstatic->getFullName($langs); |
| 1513 | - if ($showfunction && $obj->poste) |
|
| 1514 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1515 | - if (($showsoc > 0) && $obj->company) |
|
| 1516 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1590 | + if ($showfunction && $obj->poste) { |
|
| 1591 | + $out .= ' (' . $obj->poste . ')'; |
|
| 1592 | + } |
|
| 1593 | + if (($showsoc > 0) && $obj->company) { |
|
| 1594 | + $out .= ' - (' . $obj->company . ')'; |
|
| 1595 | + } |
|
| 1517 | 1596 | $out .= '</option>'; |
| 1518 | - } |
|
| 1519 | - else {
|
|
| 1597 | + } else {
|
|
| 1520 | 1598 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1521 | - if ($disabled) |
|
| 1522 | - $out .= ' disabled'; |
|
| 1599 | + if ($disabled) { |
|
| 1600 | + $out .= ' disabled'; |
|
| 1601 | + } |
|
| 1523 | 1602 | $out .= '>'; |
| 1524 | 1603 | $out .= $contactstatic->getFullName($langs); |
| 1525 | - if ($showfunction && $obj->poste) |
|
| 1526 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1527 | - if (($showsoc > 0) && $obj->company) |
|
| 1528 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1604 | + if ($showfunction && $obj->poste) { |
|
| 1605 | + $out .= ' (' . $obj->poste . ')'; |
|
| 1606 | + } |
|
| 1607 | + if (($showsoc > 0) && $obj->company) { |
|
| 1608 | + $out .= ' - (' . $obj->company . ')'; |
|
| 1609 | + } |
|
| 1529 | 1610 | $out .= '</option>'; |
| 1530 | 1611 | } |
| 1531 | - } |
|
| 1532 | - else {
|
|
| 1612 | + } else {
|
|
| 1533 | 1613 | if (in_array($obj->rowid, $selected)) {
|
| 1534 | 1614 | $out .= $contactstatic->getFullName($langs); |
| 1535 | - if ($showfunction && $obj->poste) |
|
| 1536 | - $out .= ' (' . $obj->poste . ')';
|
|
| 1537 | - if (($showsoc > 0) && $obj->company) |
|
| 1538 | - $out .= ' - (' . $obj->company . ')';
|
|
| 1615 | + if ($showfunction && $obj->poste) { |
|
| 1616 | + $out .= ' (' . $obj->poste . ')'; |
|
| 1617 | + } |
|
| 1618 | + if (($showsoc > 0) && $obj->company) { |
|
| 1619 | + $out .= ' - (' . $obj->company . ')'; |
|
| 1620 | + } |
|
| 1539 | 1621 | } |
| 1540 | 1622 | } |
| 1541 | 1623 | } |
| 1542 | 1624 | $i++; |
| 1543 | 1625 | } |
| 1544 | - } |
|
| 1545 | - else {
|
|
| 1626 | + } else {
|
|
| 1546 | 1627 | $out .= '<option value="-1"' . (($showempty == 2 || $multiple) ? '' : ' selected') . ' disabled>'; |
| 1547 | 1628 | $out .= ($socid != -1) ? ($langs->trans($socid ? "NoContactDefinedForThirdParty" : "NoContactDefined")) : $langs->trans('SelectAThirdPartyFirst');
|
| 1548 | 1629 | $out .= '</option>'; |
@@ -1623,24 +1704,27 @@ discard block |
||
| 1623 | 1704 | global $conf, $user, $langs; |
| 1624 | 1705 | |
| 1625 | 1706 | // If no preselected user defined, we take current user |
| 1626 | - if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty(Globals::$conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) |
|
| 1627 | - $selected = $user->id; |
|
| 1707 | + if ((is_numeric($selected) && ($selected < -2 || empty($selected))) && empty(Globals::$conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) { |
|
| 1708 | + $selected = $user->id; |
|
| 1709 | + } |
|
| 1628 | 1710 | |
| 1629 | - if ($selected === '') |
|
| 1630 | - $selected = array(); |
|
| 1631 | - else if (!is_array($selected)) |
|
| 1632 | - $selected = array($selected); |
|
| 1711 | + if ($selected === '') { |
|
| 1712 | + $selected = array(); |
|
| 1713 | + } else if (!is_array($selected)) { |
|
| 1714 | + $selected = array($selected); |
|
| 1715 | + } |
|
| 1633 | 1716 | |
| 1634 | 1717 | $excludeUsers = null; |
| 1635 | 1718 | $includeUsers = null; |
| 1636 | 1719 | |
| 1637 | 1720 | // Permettre l'exclusion d'utilisateurs |
| 1638 | - if (is_array($exclude)) |
|
| 1639 | - $excludeUsers = implode(",", $exclude);
|
|
| 1721 | + if (is_array($exclude)) { |
|
| 1722 | + $excludeUsers = implode(",", $exclude); |
|
| 1723 | + } |
|
| 1640 | 1724 | // Permettre l'inclusion d'utilisateurs |
| 1641 | - if (is_array($include)) |
|
| 1642 | - $includeUsers = implode(",", $include);
|
|
| 1643 | - else if ($include == 'hierarchy') {
|
|
| 1725 | + if (is_array($include)) { |
|
| 1726 | + $includeUsers = implode(",", $include); |
|
| 1727 | + } else if ($include == 'hierarchy') {
|
|
| 1644 | 1728 | // Build list includeUsers to have only hierarchy |
| 1645 | 1729 | $includeUsers = implode(",", $user->getAllChildIds(0));
|
| 1646 | 1730 | } else if ($include == 'hierarchyme') {
|
@@ -1659,12 +1743,12 @@ discard block |
||
| 1659 | 1743 | $sql .= " FROM " . MAIN_DB_PREFIX . "user as u"; |
| 1660 | 1744 | if (!empty(Globals::$conf->multicompany->enabled) && Globals::$conf->entity == 1 && $user->admin && !$user->entity) {
|
| 1661 | 1745 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=u.entity"; |
| 1662 | - if ($force_entity) |
|
| 1663 | - $sql .= " WHERE u.entity IN (0," . $force_entity . ")"; |
|
| 1664 | - else |
|
| 1665 | - $sql .= " WHERE u.entity IS NOT NULL"; |
|
| 1666 | - } |
|
| 1667 | - else {
|
|
| 1746 | + if ($force_entity) { |
|
| 1747 | + $sql .= " WHERE u.entity IN (0," . $force_entity . ")"; |
|
| 1748 | + } else { |
|
| 1749 | + $sql .= " WHERE u.entity IS NOT NULL"; |
|
| 1750 | + } |
|
| 1751 | + } else {
|
|
| 1668 | 1752 | if (!empty(Globals::$conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
| 1669 | 1753 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "usergroup_user as ug"; |
| 1670 | 1754 | $sql .= " ON ug.fk_user = u.rowid"; |
@@ -1673,16 +1757,21 @@ discard block |
||
| 1673 | 1757 | $sql .= " WHERE u.entity IN (0," . Globals::$conf->entity . ")"; |
| 1674 | 1758 | } |
| 1675 | 1759 | } |
| 1676 | - if (!empty($user->societe_id)) |
|
| 1677 | - $sql .= " AND u.fk_soc = " . $user->societe_id; |
|
| 1678 | - if (is_array($exclude) && $excludeUsers) |
|
| 1679 | - $sql .= " AND u.rowid NOT IN (" . $excludeUsers . ")";
|
|
| 1680 | - if ($includeUsers) |
|
| 1681 | - $sql .= " AND u.rowid IN (" . $includeUsers . ")";
|
|
| 1682 | - if (!empty(Globals::$conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) |
|
| 1683 | - $sql .= " AND u.statut <> 0"; |
|
| 1684 | - if (!empty($morefilter)) |
|
| 1685 | - $sql .= " " . $morefilter; |
|
| 1760 | + if (!empty($user->societe_id)) { |
|
| 1761 | + $sql .= " AND u.fk_soc = " . $user->societe_id; |
|
| 1762 | + } |
|
| 1763 | + if (is_array($exclude) && $excludeUsers) { |
|
| 1764 | + $sql .= " AND u.rowid NOT IN (" . $excludeUsers . ")"; |
|
| 1765 | + } |
|
| 1766 | + if ($includeUsers) { |
|
| 1767 | + $sql .= " AND u.rowid IN (" . $includeUsers . ")"; |
|
| 1768 | + } |
|
| 1769 | + if (!empty(Globals::$conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX) || $noactive) { |
|
| 1770 | + $sql .= " AND u.statut <> 0"; |
|
| 1771 | + } |
|
| 1772 | + if (!empty($morefilter)) { |
|
| 1773 | + $sql .= " " . $morefilter; |
|
| 1774 | + } |
|
| 1686 | 1775 | |
| 1687 | 1776 | if (empty(Globals::$conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { // MAIN_FIRSTNAME_NAME_POSITION is 0 means firstname+lastname
|
| 1688 | 1777 | $sql .= " ORDER BY u.firstname ASC"; |
@@ -1702,10 +1791,12 @@ discard block |
||
| 1702 | 1791 | |
| 1703 | 1792 | // do not use maxwidthonsmartphone by default. Set it by caller so auto size to 100% will work when not defined |
| 1704 | 1793 | $out .= '<select class="flat' . ($morecss ? ' minwidth100 ' . $morecss : ' minwidth200') . '" id="' . $htmlname . '" name="' . $htmlname . ($multiple ? '[]' : '') . '" ' . ($multiple ? 'multiple' : '') . ' ' . ($disabled ? ' disabled' : '') . '>'; |
| 1705 | - if ($show_empty && !$multiple) |
|
| 1706 | - $out .= '<option value="-1"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 1707 | - if ($show_every) |
|
| 1708 | - $out .= '<option value="-2"' . ((in_array(-2, $selected)) ? ' selected' : '') . '>-- ' . $langs->trans("Everybody") . ' --</option>' . "\n";
|
|
| 1794 | + if ($show_empty && !$multiple) { |
|
| 1795 | + $out .= '<option value="-1"' . ((empty($selected) || in_array(-1, $selected)) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 1796 | + } |
|
| 1797 | + if ($show_every) { |
|
| 1798 | + $out .= '<option value="-2"' . ((in_array(-2, $selected)) ? ' selected' : '') . '>-- ' . $langs->trans("Everybody") . ' --</option>' . "\n"; |
|
| 1799 | + } |
|
| 1709 | 1800 | |
| 1710 | 1801 | $userstatic = new User($this->db); |
| 1711 | 1802 | |
@@ -1717,19 +1808,21 @@ discard block |
||
| 1717 | 1808 | $userstatic->firstname = $obj->firstname; |
| 1718 | 1809 | |
| 1719 | 1810 | $disableline = ''; |
| 1720 | - if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) |
|
| 1721 | - $disableline = ($enableonlytext ? $enableonlytext : '1'); |
|
| 1811 | + if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) { |
|
| 1812 | + $disableline = ($enableonlytext ? $enableonlytext : '1'); |
|
| 1813 | + } |
|
| 1722 | 1814 | |
| 1723 | 1815 | if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected) )) {
|
| 1724 | 1816 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1725 | - if ($disableline) |
|
| 1726 | - $out .= ' disabled'; |
|
| 1817 | + if ($disableline) { |
|
| 1818 | + $out .= ' disabled'; |
|
| 1819 | + } |
|
| 1727 | 1820 | $out .= ' selected>'; |
| 1728 | - } |
|
| 1729 | - else {
|
|
| 1821 | + } else {
|
|
| 1730 | 1822 | $out .= '<option value="' . $obj->rowid . '"'; |
| 1731 | - if ($disableline) |
|
| 1732 | - $out .= ' disabled'; |
|
| 1823 | + if ($disableline) { |
|
| 1824 | + $out .= ' disabled'; |
|
| 1825 | + } |
|
| 1733 | 1826 | $out .= '>'; |
| 1734 | 1827 | } |
| 1735 | 1828 | |
@@ -1783,8 +1876,9 @@ discard block |
||
| 1783 | 1876 | AlDolUtils::dol_print_error($this->db); |
| 1784 | 1877 | } |
| 1785 | 1878 | |
| 1786 | - if ($outputmode) |
|
| 1787 | - return $outarray; |
|
| 1879 | + if ($outputmode) { |
|
| 1880 | + return $outarray; |
|
| 1881 | + } |
|
| 1788 | 1882 | return $out; |
| 1789 | 1883 | } |
| 1790 | 1884 | |
@@ -1836,15 +1930,18 @@ discard block |
||
| 1836 | 1930 | } |
| 1837 | 1931 | $nbassignetouser = count($assignedtouser); |
| 1838 | 1932 | |
| 1839 | - if ($nbassignetouser && $action != 'view') |
|
| 1840 | - $out .= '<br>'; |
|
| 1841 | - if ($nbassignetouser) |
|
| 1842 | - $out .= '<ul class="attendees">'; |
|
| 1933 | + if ($nbassignetouser && $action != 'view') { |
|
| 1934 | + $out .= '<br>'; |
|
| 1935 | + } |
|
| 1936 | + if ($nbassignetouser) { |
|
| 1937 | + $out .= '<ul class="attendees">'; |
|
| 1938 | + } |
|
| 1843 | 1939 | $i = 0; |
| 1844 | 1940 | $ownerid = 0; |
| 1845 | 1941 | foreach ($assignedtouser as $key => $value) {
|
| 1846 | - if ($value['id'] == $ownerid) |
|
| 1847 | - continue; |
|
| 1942 | + if ($value['id'] == $ownerid) { |
|
| 1943 | + continue; |
|
| 1944 | + } |
|
| 1848 | 1945 | |
| 1849 | 1946 | $out .= '<li>'; |
| 1850 | 1947 | $userstatic->fetch($value['id']); |
@@ -1870,8 +1967,9 @@ discard block |
||
| 1870 | 1967 | $out .= '</li>'; |
| 1871 | 1968 | $i++; |
| 1872 | 1969 | } |
| 1873 | - if ($nbassignetouser) |
|
| 1874 | - $out .= '</ul>'; |
|
| 1970 | + if ($nbassignetouser) { |
|
| 1971 | + $out .= '</ul>'; |
|
| 1972 | + } |
|
| 1875 | 1973 | |
| 1876 | 1974 | //$out.='</form>'; |
| 1877 | 1975 | return $out; |
@@ -2002,9 +2100,9 @@ discard block |
||
| 2002 | 2100 | </script> |
| 2003 | 2101 | <?php |
| 2004 | 2102 | } |
| 2005 | - if (empty($hidelabel)) |
|
| 2006 | - print $langs->trans("RefOrLabel") . ' : ';
|
|
| 2007 | - else if ($hidelabel > 1) {
|
|
| 2103 | + if (empty($hidelabel)) { |
|
| 2104 | + print $langs->trans("RefOrLabel") . ' : '; |
|
| 2105 | + } else if ($hidelabel > 1) {
|
|
| 2008 | 2106 | $placeholder = ' placeholder="' . $langs->trans("RefOrLabel") . '"';
|
| 2009 | 2107 | if ($hidelabel == 2) {
|
| 2010 | 2108 | print img_picto($langs->trans("Search"), 'search');
|
@@ -2095,13 +2193,15 @@ discard block |
||
| 2095 | 2193 | // Price by quantity |
| 2096 | 2194 | if (!empty(Globals::$conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) || !empty(Globals::$conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
|
| 2097 | 2195 | $sql .= ", (SELECT pp.rowid FROM " . MAIN_DB_PREFIX . "product_price as pp WHERE pp.fk_product = p.rowid"; |
| 2098 | - if ($price_level >= 1 && !empty(Globals::$conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) |
|
| 2099 | - $sql .= " AND price_level=" . $price_level; |
|
| 2196 | + if ($price_level >= 1 && !empty(Globals::$conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { |
|
| 2197 | + $sql .= " AND price_level=" . $price_level; |
|
| 2198 | + } |
|
| 2100 | 2199 | $sql .= " ORDER BY date_price"; |
| 2101 | 2200 | $sql .= " DESC LIMIT 1) as price_rowid"; |
| 2102 | 2201 | $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 |
| 2103 | - if ($price_level >= 1 && !empty(Globals::$conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) |
|
| 2104 | - $sql .= " AND price_level=" . $price_level; |
|
| 2202 | + if ($price_level >= 1 && !empty(Globals::$conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { |
|
| 2203 | + $sql .= " AND price_level=" . $price_level; |
|
| 2204 | + } |
|
| 2105 | 2205 | $sql .= " ORDER BY date_price"; |
| 2106 | 2206 | $sql .= " DESC LIMIT 1) as price_by_qty"; |
| 2107 | 2207 | $selectFields .= ", price_rowid, price_by_qty"; |
@@ -2143,14 +2243,15 @@ discard block |
||
| 2143 | 2243 | $sql .= " AND p.finished = " . $finished; |
| 2144 | 2244 | } elseif ($finished == 1) {
|
| 2145 | 2245 | $sql .= " AND p.finished = " . $finished; |
| 2146 | - if ($status >= 0) |
|
| 2147 | - $sql .= " AND p.tosell = " . $status; |
|
| 2148 | - } |
|
| 2149 | - elseif ($status >= 0) {
|
|
| 2246 | + if ($status >= 0) { |
|
| 2247 | + $sql .= " AND p.tosell = " . $status; |
|
| 2248 | + } |
|
| 2249 | + } elseif ($status >= 0) {
|
|
| 2150 | 2250 | $sql .= " AND p.tosell = " . $status; |
| 2151 | 2251 | } |
| 2152 | - if (strval($filtertype) != '') |
|
| 2153 | - $sql .= " AND p.fk_product_type=" . $filtertype; |
|
| 2252 | + if (strval($filtertype) != '') { |
|
| 2253 | + $sql .= " AND p.fk_product_type=" . $filtertype; |
|
| 2254 | + } |
|
| 2154 | 2255 | // Add criteria on ref/label |
| 2155 | 2256 | if ($filterkey != '') {
|
| 2156 | 2257 | $sql .= ' AND (';
|
@@ -2158,28 +2259,35 @@ discard block |
||
| 2158 | 2259 | // For natural search |
| 2159 | 2260 | $scrit = explode(' ', $filterkey);
|
| 2160 | 2261 | $i = 0; |
| 2161 | - if (count($scrit) > 1) |
|
| 2162 | - $sql .= "(";
|
|
| 2262 | + if (count($scrit) > 1) { |
|
| 2263 | + $sql .= "("; |
|
| 2264 | + } |
|
| 2163 | 2265 | foreach ($scrit as $crit) {
|
| 2164 | - if ($i > 0) |
|
| 2165 | - $sql .= " AND "; |
|
| 2266 | + if ($i > 0) { |
|
| 2267 | + $sql .= " AND "; |
|
| 2268 | + } |
|
| 2166 | 2269 | $sql .= "(p.ref LIKE '" . $db->escape($prefix . $crit) . "%' OR p.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
| 2167 | - if (!empty(Globals::$conf->global->MAIN_MULTILANGS)) |
|
| 2168 | - $sql .= " OR pl.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2270 | + if (!empty(Globals::$conf->global->MAIN_MULTILANGS)) { |
|
| 2271 | + $sql .= " OR pl.label LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2272 | + } |
|
| 2169 | 2273 | if (!empty(Globals::$conf->global->PRODUCT_AJAX_SEARCH_ON_DESCRIPTION)) {
|
| 2170 | 2274 | $sql .= " OR p.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
| 2171 | - if (!empty(Globals::$conf->global->MAIN_MULTILANGS)) |
|
| 2172 | - $sql .= " OR pl.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2275 | + if (!empty(Globals::$conf->global->MAIN_MULTILANGS)) { |
|
| 2276 | + $sql .= " OR pl.description LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2277 | + } |
|
| 2173 | 2278 | } |
| 2174 | - if (!empty(Globals::$conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) |
|
| 2175 | - $sql .= " OR pfp.ref_fourn LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2279 | + if (!empty(Globals::$conf->global->MAIN_SEARCH_PRODUCT_BY_FOURN_REF)) { |
|
| 2280 | + $sql .= " OR pfp.ref_fourn LIKE '" . $db->escape($prefix . $crit) . "%'"; |
|
| 2281 | + } |
|
| 2176 | 2282 | $sql .= ")"; |
| 2177 | 2283 | $i++; |
| 2178 | 2284 | } |
| 2179 | - if (count($scrit) > 1) |
|
| 2180 | - $sql .= ")"; |
|
| 2181 | - if (!empty(Globals::$conf->barcode->enabled)) |
|
| 2182 | - $sql .= " OR p.barcode LIKE '" . $db->escape($prefix . $filterkey) . "%'"; |
|
| 2285 | + if (count($scrit) > 1) { |
|
| 2286 | + $sql .= ")"; |
|
| 2287 | + } |
|
| 2288 | + if (!empty(Globals::$conf->barcode->enabled)) { |
|
| 2289 | + $sql .= " OR p.barcode LIKE '" . $db->escape($prefix . $filterkey) . "%'"; |
|
| 2290 | + } |
|
| 2183 | 2291 | $sql .= ')'; |
| 2184 | 2292 | } |
| 2185 | 2293 | if (count($warehouseStatusArray)) {
|
@@ -2218,13 +2326,15 @@ discard block |
||
| 2218 | 2326 | // Do not use textifempty = ' ' or ' ' here, or search on key will search on ' key'. |
| 2219 | 2327 | //if (! empty(Globals::$conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
| 2220 | 2328 | if (!empty(Globals::$conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) {
|
| 2221 | - if ($showempty && !is_numeric($showempty)) |
|
| 2222 | - $textifempty = $langs->trans($showempty); |
|
| 2223 | - else |
|
| 2224 | - $textifempty .= $langs->trans("All");
|
|
| 2329 | + if ($showempty && !is_numeric($showempty)) { |
|
| 2330 | + $textifempty = $langs->trans($showempty); |
|
| 2331 | + } else { |
|
| 2332 | + $textifempty .= $langs->trans("All"); |
|
| 2333 | + } |
|
| 2225 | 2334 | } |
| 2226 | - if ($showempty) |
|
| 2227 | - $out .= '<option value="0" selected>' . $textifempty . '</option>'; |
|
| 2335 | + if ($showempty) { |
|
| 2336 | + $out .= '<option value="0" selected>' . $textifempty . '</option>'; |
|
| 2337 | + } |
|
| 2228 | 2338 | |
| 2229 | 2339 | $i = 0; |
| 2230 | 2340 | while ($num && $i < $num) {
|
@@ -2298,11 +2408,11 @@ discard block |
||
| 2298 | 2408 | |
| 2299 | 2409 | $this->db->free($result); |
| 2300 | 2410 | |
| 2301 | - if (empty($outputmode)) |
|
| 2302 | - return $out; |
|
| 2411 | + if (empty($outputmode)) { |
|
| 2412 | + return $out; |
|
| 2413 | + } |
|
| 2303 | 2414 | return $outarray; |
| 2304 | - } |
|
| 2305 | - else {
|
|
| 2415 | + } else {
|
|
| 2306 | 2416 | AlDolUtils::dol_print_error($db); |
| 2307 | 2417 | } |
| 2308 | 2418 | } |
@@ -2339,10 +2449,12 @@ discard block |
||
| 2339 | 2449 | $maxlengtharticle = (empty(Globals::$conf->global->PRODUCT_MAX_LENGTH_COMBO) ? 48 : Globals::$conf->global->PRODUCT_MAX_LENGTH_COMBO); |
| 2340 | 2450 | |
| 2341 | 2451 | $label = $objp->label; |
| 2342 | - if (!empty($objp->label_translated)) |
|
| 2343 | - $label = $objp->label_translated; |
|
| 2344 | - if (!empty($filterkey) && $filterkey != '') |
|
| 2345 | - $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2452 | + if (!empty($objp->label_translated)) { |
|
| 2453 | + $label = $objp->label_translated; |
|
| 2454 | + } |
|
| 2455 | + if (!empty($filterkey) && $filterkey != '') { |
|
| 2456 | + $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1); |
|
| 2457 | + } |
|
| 2346 | 2458 | |
| 2347 | 2459 | $outkey = $objp->rowid; |
| 2348 | 2460 | $outref = $objp->ref; |
@@ -2360,23 +2472,27 @@ discard block |
||
| 2360 | 2472 | $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 . '"'; |
| 2361 | 2473 | } |
| 2362 | 2474 | if (!empty(Globals::$conf->stock->enabled) && $objp->fk_product_type == 0 && isset($objp->stock)) {
|
| 2363 | - if ($objp->stock > 0) |
|
| 2364 | - $opt .= ' class="product_line_stock_ok"'; |
|
| 2365 | - else if ($objp->stock <= 0) |
|
| 2366 | - $opt .= ' class="product_line_stock_too_low"'; |
|
| 2475 | + if ($objp->stock > 0) { |
|
| 2476 | + $opt .= ' class="product_line_stock_ok"'; |
|
| 2477 | + } else if ($objp->stock <= 0) { |
|
| 2478 | + $opt .= ' class="product_line_stock_too_low"'; |
|
| 2479 | + } |
|
| 2367 | 2480 | } |
| 2368 | 2481 | $opt .= '>'; |
| 2369 | 2482 | $opt .= $objp->ref; |
| 2370 | - if ($outbarcode) |
|
| 2371 | - $opt .= ' (' . $outbarcode . ')';
|
|
| 2483 | + if ($outbarcode) { |
|
| 2484 | + $opt .= ' (' . $outbarcode . ')'; |
|
| 2485 | + } |
|
| 2372 | 2486 | $opt .= ' - ' . dol_trunc($label, $maxlengtharticle); |
| 2373 | 2487 | |
| 2374 | 2488 | $objRef = $objp->ref; |
| 2375 | - if (!empty($filterkey) && $filterkey != '') |
|
| 2376 | - $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2489 | + if (!empty($filterkey) && $filterkey != '') { |
|
| 2490 | + $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1); |
|
| 2491 | + } |
|
| 2377 | 2492 | $outval .= $objRef; |
| 2378 | - if ($outbarcode) |
|
| 2379 | - $outval .= ' (' . $outbarcode . ')';
|
|
| 2493 | + if ($outbarcode) { |
|
| 2494 | + $outval .= ' (' . $outbarcode . ')'; |
|
| 2495 | + } |
|
| 2380 | 2496 | $outval .= ' - ' . dol_trunc($label, $maxlengtharticle); |
| 2381 | 2497 | |
| 2382 | 2498 | $found = 0; |
@@ -2575,15 +2691,18 @@ discard block |
||
| 2575 | 2691 | $sql .= " pfp.supplier_reputation"; |
| 2576 | 2692 | $sql .= " FROM " . MAIN_DB_PREFIX . "product as p"; |
| 2577 | 2693 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; |
| 2578 | - if ($socid) |
|
| 2579 | - $sql .= " AND pfp.fk_soc = " . $socid; |
|
| 2694 | + if ($socid) { |
|
| 2695 | + $sql .= " AND pfp.fk_soc = " . $socid; |
|
| 2696 | + } |
|
| 2580 | 2697 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON pfp.fk_soc = s.rowid"; |
| 2581 | 2698 | $sql .= " WHERE p.entity IN (" . getEntity('product') . ")";
|
| 2582 | 2699 | $sql .= " AND p.tobuy = 1"; |
| 2583 | - if (strval($filtertype) != '') |
|
| 2584 | - $sql .= " AND p.fk_product_type=" . $this->db->escape($filtertype); |
|
| 2585 | - if (!empty($filtre)) |
|
| 2586 | - $sql .= " " . $filtre; |
|
| 2700 | + if (strval($filtertype) != '') { |
|
| 2701 | + $sql .= " AND p.fk_product_type=" . $this->db->escape($filtertype); |
|
| 2702 | + } |
|
| 2703 | + if (!empty($filtre)) { |
|
| 2704 | + $sql .= " " . $filtre; |
|
| 2705 | + } |
|
| 2587 | 2706 | // Add criteria on ref/label |
| 2588 | 2707 | if ($filterkey != '') {
|
| 2589 | 2708 | $sql .= ' AND (';
|
@@ -2591,18 +2710,22 @@ discard block |
||
| 2591 | 2710 | // For natural search |
| 2592 | 2711 | $scrit = explode(' ', $filterkey);
|
| 2593 | 2712 | $i = 0; |
| 2594 | - if (count($scrit) > 1) |
|
| 2595 | - $sql .= "(";
|
|
| 2713 | + if (count($scrit) > 1) { |
|
| 2714 | + $sql .= "("; |
|
| 2715 | + } |
|
| 2596 | 2716 | foreach ($scrit as $crit) {
|
| 2597 | - if ($i > 0) |
|
| 2598 | - $sql .= " AND "; |
|
| 2717 | + if ($i > 0) { |
|
| 2718 | + $sql .= " AND "; |
|
| 2719 | + } |
|
| 2599 | 2720 | $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) . "%')"; |
| 2600 | 2721 | $i++; |
| 2601 | 2722 | } |
| 2602 | - if (count($scrit) > 1) |
|
| 2603 | - $sql .= ")"; |
|
| 2604 | - if (!empty(Globals::$conf->barcode->enabled)) |
|
| 2605 | - $sql .= " OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 2723 | + if (count($scrit) > 1) { |
|
| 2724 | + $sql .= ")"; |
|
| 2725 | + } |
|
| 2726 | + if (!empty(Globals::$conf->barcode->enabled)) { |
|
| 2727 | + $sql .= " OR p.barcode LIKE '" . $this->db->escape($prefix . $filterkey) . "%'"; |
|
| 2728 | + } |
|
| 2606 | 2729 | $sql .= ')'; |
| 2607 | 2730 | } |
| 2608 | 2731 | $sql .= " ORDER BY pfp.ref_fourn DESC, pfp.quantity ASC"; |
@@ -2619,18 +2742,21 @@ discard block |
||
| 2619 | 2742 | |
| 2620 | 2743 | //$out.='<select class="flat" id="select'.$htmlname.'" name="'.$htmlname.'">'; // remove select to have id same with combo and ajax |
| 2621 | 2744 | $out .= '<select class="flat maxwidthonsmartphone" id="' . $htmlname . '" name="' . $htmlname . '">'; |
| 2622 | - if (!$selected) |
|
| 2623 | - $out .= '<option value="0" selected> </option>'; |
|
| 2624 | - else |
|
| 2625 | - $out .= '<option value="0"> </option>'; |
|
| 2745 | + if (!$selected) { |
|
| 2746 | + $out .= '<option value="0" selected> </option>'; |
|
| 2747 | + } else { |
|
| 2748 | + $out .= '<option value="0"> </option>'; |
|
| 2749 | + } |
|
| 2626 | 2750 | |
| 2627 | 2751 | $i = 0; |
| 2628 | 2752 | while ($i < $num) {
|
| 2629 | 2753 | $objp = $this->db->fetch_object($result); |
| 2630 | 2754 | |
| 2631 | 2755 | $outkey = $objp->idprodfournprice; // id in table of price |
| 2632 | - if (!$outkey && $alsoproductwithnosupplierprice) |
|
| 2633 | - $outkey = 'idprod_' . $objp->rowid; // id of product |
|
| 2756 | + if (!$outkey && $alsoproductwithnosupplierprice) { |
|
| 2757 | + $outkey = 'idprod_' . $objp->rowid; |
|
| 2758 | + } |
|
| 2759 | + // id of product |
|
| 2634 | 2760 | |
| 2635 | 2761 | $outref = $objp->ref; |
| 2636 | 2762 | $outval = ''; |
@@ -2641,32 +2767,39 @@ discard block |
||
| 2641 | 2767 | $outdurationunit = $outtype == Product::TYPE_SERVICE ? substr($objp->duration, -1) : ''; |
| 2642 | 2768 | |
| 2643 | 2769 | $opt = '<option value="' . $outkey . '"'; |
| 2644 | - if ($selected && $selected == $objp->idprodfournprice) |
|
| 2645 | - $opt .= ' selected'; |
|
| 2646 | - if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) |
|
| 2647 | - $opt .= ' disabled'; |
|
| 2770 | + if ($selected && $selected == $objp->idprodfournprice) { |
|
| 2771 | + $opt .= ' selected'; |
|
| 2772 | + } |
|
| 2773 | + if (empty($objp->idprodfournprice) && empty($alsoproductwithnosupplierprice)) { |
|
| 2774 | + $opt .= ' disabled'; |
|
| 2775 | + } |
|
| 2648 | 2776 | if (!empty($objp->idprodfournprice) && $objp->idprodfournprice > 0) {
|
| 2649 | 2777 | $opt .= ' pbq="' . $objp->idprodfournprice . '" data-pbq="' . $objp->idprodfournprice . '" data-pbqqty="' . $objp->quantity . '" data-pbqpercent="' . $objp->remise_percent . '"'; |
| 2650 | 2778 | } |
| 2651 | 2779 | $opt .= '>'; |
| 2652 | 2780 | |
| 2653 | 2781 | $objRef = $objp->ref; |
| 2654 | - if ($filterkey && $filterkey != '') |
|
| 2655 | - $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1);
|
|
| 2782 | + if ($filterkey && $filterkey != '') { |
|
| 2783 | + $objRef = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRef, 1); |
|
| 2784 | + } |
|
| 2656 | 2785 | $objRefFourn = $objp->ref_fourn; |
| 2657 | - if ($filterkey && $filterkey != '') |
|
| 2658 | - $objRefFourn = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRefFourn, 1);
|
|
| 2786 | + if ($filterkey && $filterkey != '') { |
|
| 2787 | + $objRefFourn = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $objRefFourn, 1); |
|
| 2788 | + } |
|
| 2659 | 2789 | $label = $objp->label; |
| 2660 | - if ($filterkey && $filterkey != '') |
|
| 2661 | - $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1);
|
|
| 2790 | + if ($filterkey && $filterkey != '') { |
|
| 2791 | + $label = preg_replace('/(' . preg_quote($filterkey) . ')/i', '<strong>$1</strong>', $label, 1); |
|
| 2792 | + } |
|
| 2662 | 2793 | |
| 2663 | 2794 | $opt .= $objp->ref; |
| 2664 | - if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) |
|
| 2665 | - $opt .= ' (' . $objp->ref_fourn . ')';
|
|
| 2795 | + if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) { |
|
| 2796 | + $opt .= ' (' . $objp->ref_fourn . ')'; |
|
| 2797 | + } |
|
| 2666 | 2798 | $opt .= ' - '; |
| 2667 | 2799 | $outval .= $objRef; |
| 2668 | - if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) |
|
| 2669 | - $outval .= ' (' . $objRefFourn . ')';
|
|
| 2800 | + if (!empty($objp->idprodfournprice) && ($objp->ref != $objp->ref_fourn)) { |
|
| 2801 | + $outval .= ' (' . $objRefFourn . ')'; |
|
| 2802 | + } |
|
| 2670 | 2803 | $outval .= ' - '; |
| 2671 | 2804 | $opt .= dol_trunc($label, 72) . ' - '; |
| 2672 | 2805 | $outval .= dol_trunc($label, 72) . ' - '; |
@@ -2760,11 +2893,11 @@ discard block |
||
| 2760 | 2893 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
| 2761 | 2894 | $out .= ajax_combobox($htmlname); |
| 2762 | 2895 | |
| 2763 | - if (empty($outputmode)) |
|
| 2764 | - return $out; |
|
| 2896 | + if (empty($outputmode)) { |
|
| 2897 | + return $out; |
|
| 2898 | + } |
|
| 2765 | 2899 | return $outarray; |
| 2766 | - } |
|
| 2767 | - else {
|
|
| 2900 | + } else {
|
|
| 2768 | 2901 | AlDolUtils::dol_print_error($this->db); |
| 2769 | 2902 | } |
| 2770 | 2903 | } |
@@ -2853,8 +2986,9 @@ discard block |
||
| 2853 | 2986 | $opt .= " - "; |
| 2854 | 2987 | $opt .= price($objp->unitprice, 1, $langs, 0, 0, -1, Globals::$conf->currency) . "/" . $langs->trans("Unit");
|
| 2855 | 2988 | } |
| 2856 | - if ($objp->duration) |
|
| 2857 | - $opt .= " - " . $objp->duration; |
|
| 2989 | + if ($objp->duration) { |
|
| 2990 | + $opt .= " - " . $objp->duration; |
|
| 2991 | + } |
|
| 2858 | 2992 | $opt .= "</option>\n"; |
| 2859 | 2993 | |
| 2860 | 2994 | $form .= $opt; |
@@ -2865,8 +2999,7 @@ discard block |
||
| 2865 | 2999 | $form .= '</select>'; |
| 2866 | 3000 | $this->db->free($result); |
| 2867 | 3001 | return $form; |
| 2868 | - } |
|
| 2869 | - else {
|
|
| 3002 | + } else {
|
|
| 2870 | 3003 | AlDolUtils::dol_print_error($this->db); |
| 2871 | 3004 | } |
| 2872 | 3005 | } |
@@ -2894,8 +3027,9 @@ discard block |
||
| 2894 | 3027 | $resql = $this->db->query($sql); |
| 2895 | 3028 | if ($resql) {
|
| 2896 | 3029 | print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
| 2897 | - if ($showempty) |
|
| 2898 | - print '<option value="0"> </option>'; |
|
| 3030 | + if ($showempty) { |
|
| 3031 | + print '<option value="0"> </option>'; |
|
| 3032 | + } |
|
| 2899 | 3033 | $num = $this->db->num_rows($resql); |
| 2900 | 3034 | $i = 0; |
| 2901 | 3035 | if ($num) {
|
@@ -2929,8 +3063,10 @@ discard block |
||
| 2929 | 3063 | global $langs; |
| 2930 | 3064 | |
| 2931 | 3065 | $num = count($this->cache_conditions_paiements); |
| 2932 | - if ($num > 0) |
|
| 2933 | - return 0; // Cache already loaded |
|
| 3066 | + if ($num > 0) { |
|
| 3067 | + return 0; |
|
| 3068 | + } |
|
| 3069 | + // Cache already loaded |
|
| 2934 | 3070 | |
| 2935 | 3071 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 2936 | 3072 | |
@@ -2975,8 +3111,10 @@ discard block |
||
| 2975 | 3111 | global $langs; |
| 2976 | 3112 | |
| 2977 | 3113 | $num = count($this->cache_availability); |
| 2978 | - if ($num > 0) |
|
| 2979 | - return 0; // Cache already loaded |
|
| 3114 | + if ($num > 0) { |
|
| 3115 | + return 0; |
|
| 3116 | + } |
|
| 3117 | + // Cache already loaded |
|
| 2980 | 3118 | |
| 2981 | 3119 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 2982 | 3120 | |
@@ -3027,8 +3165,9 @@ discard block |
||
| 3027 | 3165 | dol_syslog(__METHOD__ . " selected=" . $selected . ", htmlname=" . $htmlname, LOG_DEBUG); |
| 3028 | 3166 | |
| 3029 | 3167 | print '<select id="' . $htmlname . '" class="flat" name="' . $htmlname . '">'; |
| 3030 | - if ($addempty) |
|
| 3031 | - print '<option value="0"> </option>'; |
|
| 3168 | + if ($addempty) { |
|
| 3169 | + print '<option value="0"> </option>'; |
|
| 3170 | + } |
|
| 3032 | 3171 | foreach ($this->cache_availability as $id => $arrayavailability) {
|
| 3033 | 3172 | if ($selected == $id) {
|
| 3034 | 3173 | print '<option value="' . $id . '" selected>'; |
@@ -3039,8 +3178,9 @@ discard block |
||
| 3039 | 3178 | print '</option>'; |
| 3040 | 3179 | } |
| 3041 | 3180 | print '</select>'; |
| 3042 | - if ($user->admin) |
|
| 3043 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3181 | + if ($user->admin) { |
|
| 3182 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3183 | + } |
|
| 3044 | 3184 | } |
| 3045 | 3185 | |
| 3046 | 3186 | /** |
@@ -3053,8 +3193,10 @@ discard block |
||
| 3053 | 3193 | global $langs; |
| 3054 | 3194 | |
| 3055 | 3195 | $num = count($this->cache_demand_reason); |
| 3056 | - if ($num > 0) |
|
| 3057 | - return 0; // Cache already loaded |
|
| 3196 | + if ($num > 0) { |
|
| 3197 | + return 0; |
|
| 3198 | + } |
|
| 3199 | + // Cache already loaded |
|
| 3058 | 3200 | |
| 3059 | 3201 | $sql = "SELECT rowid, code, label"; |
| 3060 | 3202 | $sql .= " FROM " . MAIN_DB_PREFIX . 'c_input_reason'; |
@@ -3070,10 +3212,14 @@ discard block |
||
| 3070 | 3212 | |
| 3071 | 3213 | // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut |
| 3072 | 3214 | $label = ($obj->label != '-' ? $obj->label : ''); |
| 3073 | - if ($langs->trans("DemandReasonType" . $obj->code) != ("DemandReasonType" . $obj->code))
|
|
| 3074 | - $label = $langs->trans("DemandReasonType" . $obj->code); // So translation key DemandReasonTypeSRC_XXX will work
|
|
| 3075 | - if ($langs->trans($obj->code) != $obj->code) |
|
| 3076 | - $label = $langs->trans($obj->code); // So translation key SRC_XXX will work |
|
| 3215 | + if ($langs->trans("DemandReasonType" . $obj->code) != ("DemandReasonType" . $obj->code)) { |
|
| 3216 | + $label = $langs->trans("DemandReasonType" . $obj->code); |
|
| 3217 | + } |
|
| 3218 | + // So translation key DemandReasonTypeSRC_XXX will work |
|
| 3219 | + if ($langs->trans($obj->code) != $obj->code) { |
|
| 3220 | + $label = $langs->trans($obj->code); |
|
| 3221 | + } |
|
| 3222 | + // So translation key SRC_XXX will work |
|
| 3077 | 3223 | |
| 3078 | 3224 | $tmparray[$obj->rowid]['id'] = $obj->rowid; |
| 3079 | 3225 | $tmparray[$obj->rowid]['code'] = $obj->code; |
@@ -3085,8 +3231,7 @@ discard block |
||
| 3085 | 3231 | |
| 3086 | 3232 | unset($tmparray); |
| 3087 | 3233 | return $num; |
| 3088 | - } |
|
| 3089 | - else {
|
|
| 3234 | + } else {
|
|
| 3090 | 3235 | AlDolUtils::dol_print_error($this->db); |
| 3091 | 3236 | return -1; |
| 3092 | 3237 | } |
@@ -3109,11 +3254,13 @@ discard block |
||
| 3109 | 3254 | $this->loadCacheInputReason(); |
| 3110 | 3255 | |
| 3111 | 3256 | print '<select class="flat" id="select_' . $htmlname . '" name="' . $htmlname . '">'; |
| 3112 | - if ($addempty) |
|
| 3113 | - print '<option value="0"' . (empty($selected) ? ' selected' : '') . '> </option>'; |
|
| 3257 | + if ($addempty) { |
|
| 3258 | + print '<option value="0"' . (empty($selected) ? ' selected' : '') . '> </option>'; |
|
| 3259 | + } |
|
| 3114 | 3260 | foreach ($this->cache_demand_reason as $id => $arraydemandreason) {
|
| 3115 | - if ($arraydemandreason['code'] == $exclude) |
|
| 3116 | - continue; |
|
| 3261 | + if ($arraydemandreason['code'] == $exclude) { |
|
| 3262 | + continue; |
|
| 3263 | + } |
|
| 3117 | 3264 | |
| 3118 | 3265 | if ($selected && ($selected == $arraydemandreason['id'] || $selected == $arraydemandreason['code'])) {
|
| 3119 | 3266 | print '<option value="' . $arraydemandreason['id'] . '" selected>'; |
@@ -3125,8 +3272,9 @@ discard block |
||
| 3125 | 3272 | print '</option>'; |
| 3126 | 3273 | } |
| 3127 | 3274 | print '</select>'; |
| 3128 | - if ($user->admin) |
|
| 3129 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3275 | + if ($user->admin) { |
|
| 3276 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3277 | + } |
|
| 3130 | 3278 | } |
| 3131 | 3279 | |
| 3132 | 3280 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -3141,8 +3289,10 @@ discard block |
||
| 3141 | 3289 | global $langs; |
| 3142 | 3290 | |
| 3143 | 3291 | $num = count($this->cache_types_paiements); |
| 3144 | - if ($num > 0) |
|
| 3145 | - return $num; // Cache already loaded |
|
| 3292 | + if ($num > 0) { |
|
| 3293 | + return $num; |
|
| 3294 | + } |
|
| 3295 | + // Cache already loaded |
|
| 3146 | 3296 | |
| 3147 | 3297 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 3148 | 3298 | |
@@ -3203,12 +3353,14 @@ discard block |
||
| 3203 | 3353 | $this->load_cache_conditions_paiements(); |
| 3204 | 3354 | |
| 3205 | 3355 | // Set default value if not already set by caller |
| 3206 | - if (empty($selected) && !empty(Globals::$conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) |
|
| 3207 | - $selected = Globals::$conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID; |
|
| 3356 | + if (empty($selected) && !empty(Globals::$conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID)) { |
|
| 3357 | + $selected = Globals::$conf->global->MAIN_DEFAULT_PAYMENT_TERM_ID; |
|
| 3358 | + } |
|
| 3208 | 3359 | |
| 3209 | 3360 | print '<select id="' . $htmlname . '" class="flat selectpaymentterms' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '">'; |
| 3210 | - if ($addempty) |
|
| 3211 | - print '<option value="0"> </option>'; |
|
| 3361 | + if ($addempty) { |
|
| 3362 | + print '<option value="0"> </option>'; |
|
| 3363 | + } |
|
| 3212 | 3364 | foreach ($this->cache_conditions_paiements as $id => $arrayconditions) {
|
| 3213 | 3365 | if ($selected == $id) {
|
| 3214 | 3366 | print '<option value="' . $id . '" selected>'; |
@@ -3219,8 +3371,9 @@ discard block |
||
| 3219 | 3371 | print '</option>'; |
| 3220 | 3372 | } |
| 3221 | 3373 | print '</select>'; |
| 3222 | - if ($user->admin && empty($noinfoadmin)) |
|
| 3223 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3374 | + if ($user->admin && empty($noinfoadmin)) { |
|
| 3375 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3376 | + } |
|
| 3224 | 3377 | } |
| 3225 | 3378 | |
| 3226 | 3379 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -3246,59 +3399,68 @@ discard block |
||
| 3246 | 3399 | dol_syslog(__METHOD__ . " " . $selected . ", " . $htmlname . ", " . $filtertype . ", " . $format, LOG_DEBUG); |
| 3247 | 3400 | |
| 3248 | 3401 | $filterarray = array(); |
| 3249 | - if ($filtertype == 'CRDT') |
|
| 3250 | - $filterarray = array(0, 2, 3); |
|
| 3251 | - elseif ($filtertype == 'DBIT') |
|
| 3252 | - $filterarray = array(1, 2, 3); |
|
| 3253 | - elseif ($filtertype != '' && $filtertype != '-1') |
|
| 3254 | - $filterarray = explode(',', $filtertype);
|
|
| 3402 | + if ($filtertype == 'CRDT') { |
|
| 3403 | + $filterarray = array(0, 2, 3); |
|
| 3404 | + } elseif ($filtertype == 'DBIT') { |
|
| 3405 | + $filterarray = array(1, 2, 3); |
|
| 3406 | + } elseif ($filtertype != '' && $filtertype != '-1') { |
|
| 3407 | + $filterarray = explode(',', $filtertype); |
|
| 3408 | + } |
|
| 3255 | 3409 | |
| 3256 | 3410 | $this->load_cache_types_paiements(); |
| 3257 | 3411 | |
| 3258 | 3412 | print '<select id="select' . $htmlname . '" class="flat selectpaymenttypes' . ($morecss ? ' ' . $morecss : '') . '" name="' . $htmlname . '">'; |
| 3259 | - if ($empty) |
|
| 3260 | - print '<option value=""> </option>'; |
|
| 3413 | + if ($empty) { |
|
| 3414 | + print '<option value=""> </option>'; |
|
| 3415 | + } |
|
| 3261 | 3416 | foreach ($this->cache_types_paiements as $id => $arraytypes) {
|
| 3262 | 3417 | // If not good status |
| 3263 | - if ($active >= 0 && $arraytypes['active'] != $active) |
|
| 3264 | - continue; |
|
| 3418 | + if ($active >= 0 && $arraytypes['active'] != $active) { |
|
| 3419 | + continue; |
|
| 3420 | + } |
|
| 3265 | 3421 | |
| 3266 | 3422 | // On passe si on a demande de filtrer sur des modes de paiments particuliers |
| 3267 | - if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) |
|
| 3268 | - continue; |
|
| 3423 | + if (count($filterarray) && !in_array($arraytypes['type'], $filterarray)) { |
|
| 3424 | + continue; |
|
| 3425 | + } |
|
| 3269 | 3426 | |
| 3270 | 3427 | // We discard empty line if showempty is on because an empty line has already been output. |
| 3271 | - if ($empty && empty($arraytypes['code'])) |
|
| 3272 | - continue; |
|
| 3273 | - |
|
| 3274 | - if ($format == 0) |
|
| 3275 | - print '<option value="' . $id . '"'; |
|
| 3276 | - elseif ($format == 1) |
|
| 3277 | - print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3278 | - elseif ($format == 2) |
|
| 3279 | - print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3280 | - elseif ($format == 3) |
|
| 3281 | - print '<option value="' . $id . '"'; |
|
| 3428 | + if ($empty && empty($arraytypes['code'])) { |
|
| 3429 | + continue; |
|
| 3430 | + } |
|
| 3431 | + |
|
| 3432 | + if ($format == 0) { |
|
| 3433 | + print '<option value="' . $id . '"'; |
|
| 3434 | + } elseif ($format == 1) { |
|
| 3435 | + print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3436 | + } elseif ($format == 2) { |
|
| 3437 | + print '<option value="' . $arraytypes['code'] . '"'; |
|
| 3438 | + } elseif ($format == 3) { |
|
| 3439 | + print '<option value="' . $id . '"'; |
|
| 3440 | + } |
|
| 3282 | 3441 | // Si selected est text, on compare avec code, sinon avec id |
| 3283 | - if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code'])
|
|
| 3284 | - print ' selected'; |
|
| 3285 | - elseif ($selected == $id) |
|
| 3286 | - print ' selected'; |
|
| 3442 | + if (preg_match('/[a-z]/i', $selected) && $selected == $arraytypes['code']) { |
|
| 3443 | + print ' selected'; |
|
| 3444 | + } elseif ($selected == $id) { |
|
| 3445 | + print ' selected'; |
|
| 3446 | + } |
|
| 3287 | 3447 | print '>'; |
| 3288 | - if ($format == 0) |
|
| 3289 | - $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3290 | - elseif ($format == 1) |
|
| 3291 | - $value = $arraytypes['code']; |
|
| 3292 | - elseif ($format == 2) |
|
| 3293 | - $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3294 | - elseif ($format == 3) |
|
| 3295 | - $value = $arraytypes['code']; |
|
| 3448 | + if ($format == 0) { |
|
| 3449 | + $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3450 | + } elseif ($format == 1) { |
|
| 3451 | + $value = $arraytypes['code']; |
|
| 3452 | + } elseif ($format == 2) { |
|
| 3453 | + $value = ($maxlength ? dol_trunc($arraytypes['label'], $maxlength) : $arraytypes['label']); |
|
| 3454 | + } elseif ($format == 3) { |
|
| 3455 | + $value = $arraytypes['code']; |
|
| 3456 | + } |
|
| 3296 | 3457 | print $value ? $value : ' '; |
| 3297 | 3458 | print '</option>'; |
| 3298 | 3459 | } |
| 3299 | 3460 | print '</select>'; |
| 3300 | - if ($user->admin && !$noadmininfo) |
|
| 3301 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3461 | + if ($user->admin && !$noadmininfo) { |
|
| 3462 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3463 | + } |
|
| 3302 | 3464 | } |
| 3303 | 3465 | |
| 3304 | 3466 | /** |
@@ -3352,8 +3514,9 @@ discard block |
||
| 3352 | 3514 | $sql = "SELECT rowid, code, libelle as label"; |
| 3353 | 3515 | $sql .= " FROM " . MAIN_DB_PREFIX . "c_shipment_mode"; |
| 3354 | 3516 | $sql .= " WHERE active > 0"; |
| 3355 | - if ($filtre) |
|
| 3356 | - $sql .= " AND " . $filtre; |
|
| 3517 | + if ($filtre) { |
|
| 3518 | + $sql .= " AND " . $filtre; |
|
| 3519 | + } |
|
| 3357 | 3520 | $sql .= " ORDER BY libelle ASC"; |
| 3358 | 3521 | |
| 3359 | 3522 | dol_syslog(get_class($this) . "::selectShippingMode", LOG_DEBUG); |
@@ -3378,8 +3541,9 @@ discard block |
||
| 3378 | 3541 | $i++; |
| 3379 | 3542 | } |
| 3380 | 3543 | print "</select>"; |
| 3381 | - if ($user->admin) |
|
| 3382 | - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 3544 | + if ($user->admin) { |
|
| 3545 | + print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 3546 | + } |
|
| 3383 | 3547 | } else {
|
| 3384 | 3548 | print $langs->trans("NoShippingMethodDefined");
|
| 3385 | 3549 | } |
@@ -3492,8 +3656,9 @@ discard block |
||
| 3492 | 3656 | |
| 3493 | 3657 | $resql = $this->db->query($sql); |
| 3494 | 3658 | if ($resql && $this->db->num_rows($resql) > 0) {
|
| 3495 | - if ($showempty) |
|
| 3496 | - $return .= '<option value="none"></option>'; |
|
| 3659 | + if ($showempty) { |
|
| 3660 | + $return .= '<option value="none"></option>'; |
|
| 3661 | + } |
|
| 3497 | 3662 | |
| 3498 | 3663 | while ($res = $this->db->fetch_object($resql)) {
|
| 3499 | 3664 | $unitLabel = $res->label; |
@@ -3536,10 +3701,12 @@ discard block |
||
| 3536 | 3701 | $sql = "SELECT rowid, label, bank, clos as status, currency_code"; |
| 3537 | 3702 | $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; |
| 3538 | 3703 | $sql .= " WHERE entity IN (" . getEntity('bank_account') . ")";
|
| 3539 | - if ($statut != 2) |
|
| 3540 | - $sql .= " AND clos = '" . $statut . "'"; |
|
| 3541 | - if ($filtre) |
|
| 3542 | - $sql .= " AND " . $filtre; |
|
| 3704 | + if ($statut != 2) { |
|
| 3705 | + $sql .= " AND clos = '" . $statut . "'"; |
|
| 3706 | + } |
|
| 3707 | + if ($filtre) { |
|
| 3708 | + $sql .= " AND " . $filtre; |
|
| 3709 | + } |
|
| 3543 | 3710 | $sql .= " ORDER BY label"; |
| 3544 | 3711 | |
| 3545 | 3712 | dol_syslog(get_class($this) . "::select_comptes", LOG_DEBUG); |
@@ -3561,23 +3728,24 @@ discard block |
||
| 3561 | 3728 | print '<option value="' . $obj->rowid . '">'; |
| 3562 | 3729 | } |
| 3563 | 3730 | print trim($obj->label); |
| 3564 | - if ($showcurrency) |
|
| 3565 | - print ' (' . $obj->currency_code . ')';
|
|
| 3566 | - if ($statut == 2 && $obj->status == 1) |
|
| 3567 | - print ' (' . $langs->trans("Closed") . ')';
|
|
| 3731 | + if ($showcurrency) { |
|
| 3732 | + print ' (' . $obj->currency_code . ')'; |
|
| 3733 | + } |
|
| 3734 | + if ($statut == 2 && $obj->status == 1) { |
|
| 3735 | + print ' (' . $langs->trans("Closed") . ')'; |
|
| 3736 | + } |
|
| 3568 | 3737 | print '</option>'; |
| 3569 | 3738 | $i++; |
| 3570 | 3739 | } |
| 3571 | 3740 | print "</select>"; |
| 3741 | + } else {
|
|
| 3742 | + if ($statut == 0) { |
|
| 3743 | + print '<span class="opacitymedium">' . $langs->trans("NoActiveBankAccountDefined") . '</span>'; |
|
| 3744 | + } else { |
|
| 3745 | + print '<span class="opacitymedium">' . $langs->trans("NoBankAccountFound") . '</span>'; |
|
| 3746 | + } |
|
| 3572 | 3747 | } |
| 3573 | - else {
|
|
| 3574 | - if ($statut == 0) |
|
| 3575 | - print '<span class="opacitymedium">' . $langs->trans("NoActiveBankAccountDefined") . '</span>';
|
|
| 3576 | - else |
|
| 3577 | - print '<span class="opacitymedium">' . $langs->trans("NoBankAccountFound") . '</span>';
|
|
| 3578 | - } |
|
| 3579 | - } |
|
| 3580 | - else {
|
|
| 3748 | + } else {
|
|
| 3581 | 3749 | AlDolUtils::dol_print_error($this->db); |
| 3582 | 3750 | } |
| 3583 | 3751 | |
@@ -3601,8 +3769,9 @@ discard block |
||
| 3601 | 3769 | print '<input type="hidden" name="action" value="setbankaccount">'; |
| 3602 | 3770 | print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">'; |
| 3603 | 3771 | $nbaccountfound = $this->select_comptes($selected, $htmlname, 0, '', $addempty); |
| 3604 | - if ($nbaccountfound > 0) |
|
| 3605 | - print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
|
|
| 3772 | + if ($nbaccountfound > 0) { |
|
| 3773 | + print '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">'; |
|
| 3774 | + } |
|
| 3606 | 3775 | print '</form>'; |
| 3607 | 3776 | } else {
|
| 3608 | 3777 | |
@@ -3612,8 +3781,9 @@ discard block |
||
| 3612 | 3781 | require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; |
| 3613 | 3782 | $bankstatic = new Account($this->db); |
| 3614 | 3783 | $result = $bankstatic->fetch($selected); |
| 3615 | - if ($result) |
|
| 3616 | - print $bankstatic->getNomUrl(1); |
|
| 3784 | + if ($result) { |
|
| 3785 | + print $bankstatic->getNomUrl(1); |
|
| 3786 | + } |
|
| 3617 | 3787 | } else {
|
| 3618 | 3788 | print " "; |
| 3619 | 3789 | } |
@@ -3659,15 +3829,16 @@ discard block |
||
| 3659 | 3829 | $i = 0; |
| 3660 | 3830 | while ($i < $num) {
|
| 3661 | 3831 | $objp = $this->db->fetch_object($result); |
| 3662 | - if ($objp) |
|
| 3663 | - $cate_arbo[$objp->rowid] = array('id' => $objp->rowid, 'fulllabel' => $objp->label);
|
|
| 3832 | + if ($objp) { |
|
| 3833 | + $cate_arbo[$objp->rowid] = array('id' => $objp->rowid, 'fulllabel' => $objp->label); |
|
| 3834 | + } |
|
| 3664 | 3835 | $i++; |
| 3665 | 3836 | } |
| 3666 | 3837 | $this->db->free($result); |
| 3667 | - } else |
|
| 3668 | - AlDolUtils::dol_print_error($this->db); |
|
| 3669 | - } |
|
| 3670 | - else {
|
|
| 3838 | + } else { |
|
| 3839 | + AlDolUtils::dol_print_error($this->db); |
|
| 3840 | + } |
|
| 3841 | + } else {
|
|
| 3671 | 3842 | $cat = new Categorie($this->db); |
| 3672 | 3843 | $cate_arbo = $cat->get_full_arbo($type, $excludeafterid); |
| 3673 | 3844 | } |
@@ -3675,9 +3846,9 @@ discard block |
||
| 3675 | 3846 | $output = '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">'; |
| 3676 | 3847 | $outarray = array(); |
| 3677 | 3848 | if (is_array($cate_arbo)) {
|
| 3678 | - if (!count($cate_arbo)) |
|
| 3679 | - $output .= '<option value="-1" disabled>' . $langs->trans("NoCategoriesDefined") . '</option>';
|
|
| 3680 | - else {
|
|
| 3849 | + if (!count($cate_arbo)) { |
|
| 3850 | + $output .= '<option value="-1" disabled>' . $langs->trans("NoCategoriesDefined") . '</option>'; |
|
| 3851 | + } else {
|
|
| 3681 | 3852 | $output .= '<option value="-1"> </option>'; |
| 3682 | 3853 | foreach ($cate_arbo as $key => $value) {
|
| 3683 | 3854 | if ($cate_arbo[$key]['id'] == $selected || ($selected == 'auto' && count($cate_arbo) == 1)) {
|
@@ -3694,8 +3865,9 @@ discard block |
||
| 3694 | 3865 | $output .= '</select>'; |
| 3695 | 3866 | $output .= "\n"; |
| 3696 | 3867 | |
| 3697 | - if ($outputmode) |
|
| 3698 | - return $outarray; |
|
| 3868 | + if ($outputmode) { |
|
| 3869 | + return $outarray; |
|
| 3870 | + } |
|
| 3699 | 3871 | return $output; |
| 3700 | 3872 | } |
| 3701 | 3873 | |
@@ -3759,8 +3931,9 @@ discard block |
||
| 3759 | 3931 | |
| 3760 | 3932 | // Clean parameters |
| 3761 | 3933 | $newselectedchoice = empty($selectedchoice) ? "no" : $selectedchoice; |
| 3762 | - if (Globals::$conf->browser->layout == 'phone') |
|
| 3763 | - $width = '95%'; |
|
| 3934 | + if (Globals::$conf->browser->layout == 'phone') { |
|
| 3935 | + $width = '95%'; |
|
| 3936 | + } |
|
| 3764 | 3937 | |
| 3765 | 3938 | if (is_array($formquestion) && !empty($formquestion)) {
|
| 3766 | 3939 | // First add hidden fields and value |
@@ -3774,8 +3947,9 @@ discard block |
||
| 3774 | 3947 | |
| 3775 | 3948 | // Now add questions |
| 3776 | 3949 | $more .= '<table class="paddingtopbottomonly" width="100%">' . "\n"; |
| 3777 | - if (!empty($formquestion['text'])) |
|
| 3778 | - $more .= '<tr><td colspan="2">' . $formquestion['text'] . '</td></tr>' . "\n"; |
|
| 3950 | + if (!empty($formquestion['text'])) { |
|
| 3951 | + $more .= '<tr><td colspan="2">' . $formquestion['text'] . '</td></tr>' . "\n"; |
|
| 3952 | + } |
|
| 3779 | 3953 | foreach ($formquestion as $key => $input) {
|
| 3780 | 3954 | if (is_array($input) && !empty($input)) {
|
| 3781 | 3955 | $size = (!empty($input['size']) ? ' size="' . $input['size'] . '"' : ''); |
@@ -3788,42 +3962,45 @@ discard block |
||
| 3788 | 3962 | $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";
|
| 3789 | 3963 | } elseif ($input['type'] == 'select') {
|
| 3790 | 3964 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>';
|
| 3791 | - if (!empty($input['label'])) |
|
| 3792 | - $more .= $input['label'] . '</td><td class="tdtop" align="left">'; |
|
| 3965 | + if (!empty($input['label'])) { |
|
| 3966 | + $more .= $input['label'] . '</td><td class="tdtop" align="left">'; |
|
| 3967 | + } |
|
| 3793 | 3968 | $more .= $this->selectarray($input['name'], $input['values'], $input['default'], 1, 0, 0, $moreattr, 0, 0, 0, '', $morecss); |
| 3794 | 3969 | $more .= '</td></tr>' . "\n"; |
| 3795 | - } |
|
| 3796 | - elseif ($input['type'] == 'checkbox') {
|
|
| 3970 | + } elseif ($input['type'] == 'checkbox') {
|
|
| 3797 | 3971 | $more .= '<tr>'; |
| 3798 | 3972 | $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . ' </td><td align="left">';
|
| 3799 | 3973 | $more .= '<input type="checkbox" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '"' . $moreattr; |
| 3800 | - if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') |
|
| 3801 | - $more .= ' checked'; |
|
| 3802 | - if (is_bool($input['value']) && $input['value']) |
|
| 3803 | - $more .= ' checked'; |
|
| 3804 | - if (isset($input['disabled'])) |
|
| 3805 | - $more .= ' disabled'; |
|
| 3974 | + if (!is_bool($input['value']) && $input['value'] != 'false' && $input['value'] != '0') { |
|
| 3975 | + $more .= ' checked'; |
|
| 3976 | + } |
|
| 3977 | + if (is_bool($input['value']) && $input['value']) { |
|
| 3978 | + $more .= ' checked'; |
|
| 3979 | + } |
|
| 3980 | + if (isset($input['disabled'])) { |
|
| 3981 | + $more .= ' disabled'; |
|
| 3982 | + } |
|
| 3806 | 3983 | $more .= ' /></td>'; |
| 3807 | 3984 | $more .= '</tr>' . "\n"; |
| 3808 | - } |
|
| 3809 | - elseif ($input['type'] == 'radio') {
|
|
| 3985 | + } elseif ($input['type'] == 'radio') {
|
|
| 3810 | 3986 | $i = 0; |
| 3811 | 3987 | foreach ($input['values'] as $selkey => $selval) {
|
| 3812 | 3988 | $more .= '<tr>'; |
| 3813 | - if ($i == 0) |
|
| 3814 | - $more .= '<td' . (empty($input['tdclass']) ? ' class="tdtop"' : (' class="tdtop ' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>';
|
|
| 3815 | - else |
|
| 3816 | - $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '> </td>';
|
|
| 3989 | + if ($i == 0) { |
|
| 3990 | + $more .= '<td' . (empty($input['tdclass']) ? ' class="tdtop"' : (' class="tdtop ' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>'; |
|
| 3991 | + } else { |
|
| 3992 | + $more .= '<td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '> </td>'; |
|
| 3993 | + } |
|
| 3817 | 3994 | $more .= '<td><input type="radio" class="flat' . $morecss . '" id="' . $input['name'] . '" name="' . $input['name'] . '" value="' . $selkey . '"' . $moreattr; |
| 3818 | - if ($input['disabled']) |
|
| 3819 | - $more .= ' disabled'; |
|
| 3995 | + if ($input['disabled']) { |
|
| 3996 | + $more .= ' disabled'; |
|
| 3997 | + } |
|
| 3820 | 3998 | $more .= ' /> '; |
| 3821 | 3999 | $more .= $selval; |
| 3822 | 4000 | $more .= '</td></tr>' . "\n"; |
| 3823 | 4001 | $i++; |
| 3824 | 4002 | } |
| 3825 | - } |
|
| 3826 | - elseif ($input['type'] == 'date') {
|
|
| 4003 | + } elseif ($input['type'] == 'date') {
|
|
| 3827 | 4004 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>' . $input['label'] . '</td>';
|
| 3828 | 4005 | $more .= '<td align="left">'; |
| 3829 | 4006 | $more .= $this->selectDate($input['value'], $input['name'], 0, 0, 0, '', 1, 0); |
@@ -3835,13 +4012,12 @@ discard block |
||
| 3835 | 4012 | $formquestion[] = array('name' => $input['name'] . 'min');
|
| 3836 | 4013 | } elseif ($input['type'] == 'other') {
|
| 3837 | 4014 | $more .= '<tr><td' . (empty($input['tdclass']) ? '' : (' class="' . $input['tdclass'] . '"')) . '>';
|
| 3838 | - if (!empty($input['label'])) |
|
| 3839 | - $more .= $input['label'] . '</td><td align="left">'; |
|
| 4015 | + if (!empty($input['label'])) { |
|
| 4016 | + $more .= $input['label'] . '</td><td align="left">'; |
|
| 4017 | + } |
|
| 3840 | 4018 | $more .= $input['value']; |
| 3841 | 4019 | $more .= '</td></tr>' . "\n"; |
| 3842 | - } |
|
| 3843 | - |
|
| 3844 | - elseif ($input['type'] == 'onecolumn') {
|
|
| 4020 | + } elseif ($input['type'] == 'onecolumn') {
|
|
| 3845 | 4021 | $more .= '<tr><td colspan="2" align="left">'; |
| 3846 | 4022 | $more .= $input['value']; |
| 3847 | 4023 | $more .= '</td></tr>' . "\n"; |
@@ -3854,10 +4030,12 @@ discard block |
||
| 3854 | 4030 | // JQUI method dialog is broken with jmobile, we use standard HTML. |
| 3855 | 4031 | // 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 |
| 3856 | 4032 | // See page product/card.php for example |
| 3857 | - if (!empty(Globals::$conf->dol_use_jmobile)) |
|
| 3858 | - $useajax = 0; |
|
| 3859 | - if (empty(Globals::$conf->use_javascript_ajax)) |
|
| 3860 | - $useajax = 0; |
|
| 4033 | + if (!empty(Globals::$conf->dol_use_jmobile)) { |
|
| 4034 | + $useajax = 0; |
|
| 4035 | + } |
|
| 4036 | + if (empty(Globals::$conf->use_javascript_ajax)) { |
|
| 4037 | + $useajax = 0; |
|
| 4038 | + } |
|
| 3861 | 4039 | |
| 3862 | 4040 | if ($useajax) {
|
| 3863 | 4041 | $autoOpen = true; |
@@ -3875,10 +4053,12 @@ discard block |
||
| 3875 | 4053 | if (is_array($formquestion)) {
|
| 3876 | 4054 | foreach ($formquestion as $key => $input) {
|
| 3877 | 4055 | //print "xx ".$key." rr ".is_array($input)."<br>\n"; |
| 3878 | - if (is_array($input) && isset($input['name'])) |
|
| 3879 | - array_push($inputok, $input['name']); |
|
| 3880 | - if (isset($input['inputko']) && $input['inputko'] == 1) |
|
| 3881 | - array_push($inputko, $input['name']); |
|
| 4056 | + if (is_array($input) && isset($input['name'])) { |
|
| 4057 | + array_push($inputok, $input['name']); |
|
| 4058 | + } |
|
| 4059 | + if (isset($input['inputko']) && $input['inputko'] == 1) { |
|
| 4060 | + array_push($inputko, $input['name']); |
|
| 4061 | + } |
|
| 3882 | 4062 | } |
| 3883 | 4063 | } |
| 3884 | 4064 | // Show JQuery confirm box. Note that global var $useglobalvars is used inside this template |
@@ -3963,12 +4143,14 @@ discard block |
||
| 3963 | 4143 | } else {
|
| 3964 | 4144 | $formconfirm .= "\n<!-- begin formconfirm page=" . $page . " -->\n"; |
| 3965 | 4145 | |
| 3966 | - if (empty($disableformtag)) |
|
| 3967 | - $formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . "\n"; |
|
| 4146 | + if (empty($disableformtag)) { |
|
| 4147 | + $formconfirm .= '<form method="POST" action="' . $page . '" class="notoptoleftroright">' . "\n"; |
|
| 4148 | + } |
|
| 3968 | 4149 | |
| 3969 | 4150 | $formconfirm .= '<input type="hidden" name="action" value="' . $action . '">' . "\n"; |
| 3970 | - if (empty($disableformtag)) |
|
| 3971 | - $formconfirm .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">' . "\n"; |
|
| 4151 | + if (empty($disableformtag)) { |
|
| 4152 | + $formconfirm .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">' . "\n"; |
|
| 4153 | + } |
|
| 3972 | 4154 | |
| 3973 | 4155 | $formconfirm .= '<table width="100%" class="valid">' . "\n"; |
| 3974 | 4156 | |
@@ -3993,8 +4175,9 @@ discard block |
||
| 3993 | 4175 | |
| 3994 | 4176 | $formconfirm .= '</table>' . "\n"; |
| 3995 | 4177 | |
| 3996 | - if (empty($disableformtag)) |
|
| 3997 | - $formconfirm .= "</form>\n"; |
|
| 4178 | + if (empty($disableformtag)) { |
|
| 4179 | + $formconfirm .= "</form>\n"; |
|
| 4180 | + } |
|
| 3998 | 4181 | $formconfirm .= '<br>'; |
| 3999 | 4182 | |
| 4000 | 4183 | $formconfirm .= "<!-- end formconfirm -->\n"; |
@@ -4184,14 +4367,16 @@ discard block |
||
| 4184 | 4367 | $ret .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '"></td>';
|
| 4185 | 4368 | $ret .= '</tr></table></form>'; |
| 4186 | 4369 | } else {
|
| 4187 | - if ($displayhour) |
|
| 4188 | - $ret .= AlDolUtils::dol_print_date($selected, 'dayhour'); |
|
| 4189 | - else |
|
| 4190 | - $ret .= AlDolUtils::dol_print_date($selected, 'day'); |
|
| 4370 | + if ($displayhour) { |
|
| 4371 | + $ret .= AlDolUtils::dol_print_date($selected, 'dayhour'); |
|
| 4372 | + } else { |
|
| 4373 | + $ret .= AlDolUtils::dol_print_date($selected, 'day'); |
|
| 4374 | + } |
|
| 4191 | 4375 | } |
| 4192 | 4376 | |
| 4193 | - if (empty($nooutput)) |
|
| 4194 | - print $ret; |
|
| 4377 | + if (empty($nooutput)) { |
|
| 4378 | + print $ret; |
|
| 4379 | + } |
|
| 4195 | 4380 | return $ret; |
| 4196 | 4381 | } |
| 4197 | 4382 | |
@@ -4317,10 +4502,10 @@ discard block |
||
| 4317 | 4502 | } else {
|
| 4318 | 4503 | if (!empty($rate)) {
|
| 4319 | 4504 | print price($rate, 1, $langs, 1, 0); |
| 4320 | - if ($currency && $rate != 1) |
|
| 4321 | - print ' (' . price($rate, 1, $langs, 1, 0) . ' ' . $currency . ' = 1 ' . Globals::$conf->currency . ')';
|
|
| 4322 | - } |
|
| 4323 | - else {
|
|
| 4505 | + if ($currency && $rate != 1) { |
|
| 4506 | + print ' (' . price($rate, 1, $langs, 1, 0) . ' ' . $currency . ' = 1 ' . Globals::$conf->currency . ')'; |
|
| 4507 | + } |
|
| 4508 | + } else {
|
|
| 4324 | 4509 | print 1; |
| 4325 | 4510 | } |
| 4326 | 4511 | } |
@@ -4353,34 +4538,41 @@ discard block |
||
| 4353 | 4538 | print '<div class="inline-block">'; |
| 4354 | 4539 | if (!empty($discount_type)) {
|
| 4355 | 4540 | if (!empty(Globals::$conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
| 4356 | - if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") |
|
| 4357 | - $translationKey = 'HasAbsoluteDiscountFromSupplier'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4358 | - else |
|
| 4359 | - $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4360 | - } |
|
| 4361 | - else {
|
|
| 4362 | - if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") |
|
| 4363 | - $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
|
| 4364 | - else |
|
| 4365 | - $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4541 | + if (!$filter || $filter == "fk_invoice_supplier_source IS NULL") { |
|
| 4542 | + $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
|
| 4543 | + } |
|
| 4544 | + // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4545 | + else { |
|
| 4546 | + $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4547 | + } |
|
| 4548 | + } else {
|
|
| 4549 | + if (!$filter || $filter == "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") { |
|
| 4550 | + $translationKey = 'HasAbsoluteDiscountFromSupplier'; |
|
| 4551 | + } else { |
|
| 4552 | + $translationKey = 'HasCreditNoteFromSupplier'; |
|
| 4553 | + } |
|
| 4366 | 4554 | } |
| 4367 | 4555 | } else {
|
| 4368 | 4556 | if (!empty(Globals::$conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
|
| 4369 | - if (!$filter || $filter == "fk_facture_source IS NULL") |
|
| 4370 | - $translationKey = 'CompanyHasAbsoluteDiscount'; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4371 | - else |
|
| 4372 | - $translationKey = 'CompanyHasCreditNote'; |
|
| 4373 | - } |
|
| 4374 | - else {
|
|
| 4375 | - if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") |
|
| 4376 | - $translationKey = 'CompanyHasAbsoluteDiscount'; |
|
| 4377 | - else |
|
| 4378 | - $translationKey = 'CompanyHasCreditNote'; |
|
| 4557 | + if (!$filter || $filter == "fk_facture_source IS NULL") { |
|
| 4558 | + $translationKey = 'CompanyHasAbsoluteDiscount'; |
|
| 4559 | + } |
|
| 4560 | + // If we want deposit to be substracted to payments only and not to total of final invoice |
|
| 4561 | + else { |
|
| 4562 | + $translationKey = 'CompanyHasCreditNote'; |
|
| 4563 | + } |
|
| 4564 | + } else {
|
|
| 4565 | + if (!$filter || $filter == "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") { |
|
| 4566 | + $translationKey = 'CompanyHasAbsoluteDiscount'; |
|
| 4567 | + } else { |
|
| 4568 | + $translationKey = 'CompanyHasCreditNote'; |
|
| 4569 | + } |
|
| 4379 | 4570 | } |
| 4380 | 4571 | } |
| 4381 | 4572 | print $langs->trans($translationKey, price($amount, 0, $langs, 0, 0, -1, Globals::$conf->currency)); |
| 4382 | - if (empty($hidelist)) |
|
| 4383 | - print ': '; |
|
| 4573 | + if (empty($hidelist)) { |
|
| 4574 | + print ': '; |
|
| 4575 | + } |
|
| 4384 | 4576 | print '</div>'; |
| 4385 | 4577 | if (empty($hidelist)) {
|
| 4386 | 4578 | print '<div class="inline-block" style="padding-right: 10px">'; |
@@ -4390,15 +4582,18 @@ discard block |
||
| 4390 | 4582 | } else {
|
| 4391 | 4583 | $newfilter .= ' AND fk_facture IS NULL AND fk_facture_line IS NULL'; // Customer discounts available |
| 4392 | 4584 | } |
| 4393 | - if ($filter) |
|
| 4394 | - $newfilter .= ' AND (' . $filter . ')';
|
|
| 4585 | + if ($filter) { |
|
| 4586 | + $newfilter .= ' AND (' . $filter . ')'; |
|
| 4587 | + } |
|
| 4395 | 4588 | $nbqualifiedlines = $this->select_remises($selected, $htmlname, $newfilter, $socid, $maxvalue); |
| 4396 | 4589 | if ($nbqualifiedlines > 0) {
|
| 4397 | 4590 | print ' <input type="submit" class="button" value="' . AlDolUtils::dol_escape_htmltag($langs->trans("UseLine")) . '"';
|
| 4398 | - if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") |
|
| 4399 | - print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"';
|
|
| 4400 | - if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") |
|
| 4401 | - print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"';
|
|
| 4591 | + if (!empty($discount_type) && $filter && $filter != "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')") { |
|
| 4592 | + print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"'; |
|
| 4593 | + } |
|
| 4594 | + if (empty($discount_type) && $filter && $filter != "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')") { |
|
| 4595 | + print ' title="' . $langs->trans("UseCreditNoteInInvoicePayment") . '"'; |
|
| 4596 | + } |
|
| 4402 | 4597 | |
| 4403 | 4598 | print '>'; |
| 4404 | 4599 | } |
@@ -4499,10 +4694,11 @@ discard block |
||
| 4499 | 4694 | } |
| 4500 | 4695 | } |
| 4501 | 4696 | |
| 4502 | - if ($nooutput) |
|
| 4503 | - return $out; |
|
| 4504 | - else |
|
| 4505 | - print $out; |
|
| 4697 | + if ($nooutput) { |
|
| 4698 | + return $out; |
|
| 4699 | + } else { |
|
| 4700 | + print $out; |
|
| 4701 | + } |
|
| 4506 | 4702 | } |
| 4507 | 4703 | |
| 4508 | 4704 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -4535,8 +4731,10 @@ discard block |
||
| 4535 | 4731 | |
| 4536 | 4732 | $out = ''; |
| 4537 | 4733 | |
| 4538 | - if ($selected == 'euro' || $selected == 'euros') |
|
| 4539 | - $selected = 'EUR'; // Pour compatibilite |
|
| 4734 | + if ($selected == 'euro' || $selected == 'euros') { |
|
| 4735 | + $selected = 'EUR'; |
|
| 4736 | + } |
|
| 4737 | + // Pour compatibilite |
|
| 4540 | 4738 | |
| 4541 | 4739 | $out .= '<select class="flat maxwidth200onsmartphone minwidth300" name="' . $htmlname . '" id="' . $htmlname . '">'; |
| 4542 | 4740 | foreach ($langs->cache_currencies as $code_iso => $currency) {
|
@@ -4550,8 +4748,9 @@ discard block |
||
| 4550 | 4748 | $out .= '</option>'; |
| 4551 | 4749 | } |
| 4552 | 4750 | $out .= '</select>'; |
| 4553 | - if ($user->admin) |
|
| 4554 | - $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 4751 | + if ($user->admin) { |
|
| 4752 | + $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 4753 | + } |
|
| 4555 | 4754 | |
| 4556 | 4755 | // Make select dynamic |
| 4557 | 4756 | include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; |
@@ -4580,14 +4779,16 @@ discard block |
||
| 4580 | 4779 | $sql .= " WHERE entity IN ('" . getEntity('mutlicurrency') . "')";
|
| 4581 | 4780 | $resql = $db->query($sql); |
| 4582 | 4781 | if ($resql) {
|
| 4583 | - while ($obj = $db->fetch_object($resql)) |
|
| 4584 | - $TCurrency[$obj->code] = $obj->code; |
|
| 4782 | + while ($obj = $db->fetch_object($resql)) { |
|
| 4783 | + $TCurrency[$obj->code] = $obj->code; |
|
| 4784 | + } |
|
| 4585 | 4785 | } |
| 4586 | 4786 | |
| 4587 | 4787 | $out = ''; |
| 4588 | 4788 | $out .= '<select class="flat" name="' . $htmlname . '" id="' . $htmlname . '">'; |
| 4589 | - if ($useempty) |
|
| 4590 | - $out .= '<option value=""></option>'; |
|
| 4789 | + if ($useempty) { |
|
| 4790 | + $out .= '<option value=""></option>'; |
|
| 4791 | + } |
|
| 4591 | 4792 | // If company current currency not in table, we add it into list. Should always be available. |
| 4592 | 4793 | if (!in_array(Globals::$conf->currency, $TCurrency)) {
|
| 4593 | 4794 | $TCurrency[Globals::$conf->currency] = Globals::$conf->currency; |
@@ -4595,10 +4796,11 @@ discard block |
||
| 4595 | 4796 | if (count($TCurrency) > 0) {
|
| 4596 | 4797 | foreach ($langs->cache_currencies as $code_iso => $currency) {
|
| 4597 | 4798 | if (isset($TCurrency[$code_iso])) {
|
| 4598 | - if (!empty($selected) && $selected == $code_iso) |
|
| 4599 | - $out .= '<option value="' . $code_iso . '" selected="selected">'; |
|
| 4600 | - else |
|
| 4601 | - $out .= '<option value="' . $code_iso . '">'; |
|
| 4799 | + if (!empty($selected) && $selected == $code_iso) { |
|
| 4800 | + $out .= '<option value="' . $code_iso . '" selected="selected">'; |
|
| 4801 | + } else { |
|
| 4802 | + $out .= '<option value="' . $code_iso . '">'; |
|
| 4803 | + } |
|
| 4602 | 4804 | |
| 4603 | 4805 | $out .= $currency['label']; |
| 4604 | 4806 | $out .= ' (' . $langs->getCurrencySymbol($code_iso) . ')';
|
@@ -4628,8 +4830,10 @@ discard block |
||
| 4628 | 4830 | global $langs; |
| 4629 | 4831 | |
| 4630 | 4832 | $num = count($this->cache_vatrates); |
| 4631 | - if ($num > 0) |
|
| 4632 | - return $num; // Cache already loaded |
|
| 4833 | + if ($num > 0) { |
|
| 4834 | + return $num; |
|
| 4835 | + } |
|
| 4836 | + // Cache already loaded |
|
| 4633 | 4837 | |
| 4634 | 4838 | dol_syslog(__METHOD__, LOG_DEBUG); |
| 4635 | 4839 | |
@@ -4658,20 +4862,23 @@ discard block |
||
| 4658 | 4862 | $this->cache_vatrates[$i]['label'] = $obj->taux . '%' . ($obj->code ? ' (' . $obj->code . ')' : ''); // Label must contains only 0-9 , . % or *
|
| 4659 | 4863 | $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
|
| 4660 | 4864 | $positiverates = ''; |
| 4661 | - if ($obj->taux) |
|
| 4662 | - $positiverates .= ($positiverates ? '/' : '') . $obj->taux; |
|
| 4663 | - if ($obj->localtax1) |
|
| 4664 | - $positiverates .= ($positiverates ? '/' : '') . $obj->localtax1; |
|
| 4665 | - if ($obj->localtax2) |
|
| 4666 | - $positiverates .= ($positiverates ? '/' : '') . $obj->localtax2; |
|
| 4667 | - if (empty($positiverates)) |
|
| 4668 | - $positiverates = '0'; |
|
| 4865 | + if ($obj->taux) { |
|
| 4866 | + $positiverates .= ($positiverates ? '/' : '') . $obj->taux; |
|
| 4867 | + } |
|
| 4868 | + if ($obj->localtax1) { |
|
| 4869 | + $positiverates .= ($positiverates ? '/' : '') . $obj->localtax1; |
|
| 4870 | + } |
|
| 4871 | + if ($obj->localtax2) { |
|
| 4872 | + $positiverates .= ($positiverates ? '/' : '') . $obj->localtax2; |
|
| 4873 | + } |
|
| 4874 | + if (empty($positiverates)) { |
|
| 4875 | + $positiverates = '0'; |
|
| 4876 | + } |
|
| 4669 | 4877 | $this->cache_vatrates[$i]['labelpositiverates'] = $positiverates . ($obj->code ? ' (' . $obj->code . ')' : ''); // Must never be used as key, only label
|
| 4670 | 4878 | } |
| 4671 | 4879 | |
| 4672 | 4880 | return $num; |
| 4673 | - } |
|
| 4674 | - else {
|
|
| 4881 | + } else {
|
|
| 4675 | 4882 | $this->error = '<font class="error">' . $langs->trans("ErrorNoVATRateDefinedForSellerCountry", $country_code) . '</font>';
|
| 4676 | 4883 | return -1; |
| 4677 | 4884 | } |
@@ -4808,16 +5015,19 @@ discard block |
||
| 4808 | 5015 | $selectedfound = false; |
| 4809 | 5016 | foreach ($this->cache_vatrates as $rate) {
|
| 4810 | 5017 | // Keep only 0 if seller is not subject to VAT |
| 4811 | - if ($disabled && $rate['txtva'] != 0) |
|
| 4812 | - continue; |
|
| 5018 | + if ($disabled && $rate['txtva'] != 0) { |
|
| 5019 | + continue; |
|
| 5020 | + } |
|
| 4813 | 5021 | |
| 4814 | 5022 | // Define key to use into select list |
| 4815 | 5023 | $key = $rate['txtva']; |
| 4816 | 5024 | $key .= $rate['nprtva'] ? '*' : ''; |
| 4817 | - if ($mode > 0 && $rate['code']) |
|
| 4818 | - $key .= ' (' . $rate['code'] . ')';
|
|
| 4819 | - if ($mode < 0) |
|
| 4820 | - $key = $rate['rowid']; |
|
| 5025 | + if ($mode > 0 && $rate['code']) { |
|
| 5026 | + $key .= ' (' . $rate['code'] . ')'; |
|
| 5027 | + } |
|
| 5028 | + if ($mode < 0) { |
|
| 5029 | + $key = $rate['rowid']; |
|
| 5030 | + } |
|
| 4821 | 5031 | |
| 4822 | 5032 | $return .= '<option value="' . $key . '"'; |
| 4823 | 5033 | if (!$selectedfound) {
|
@@ -4844,10 +5054,10 @@ discard block |
||
| 4844 | 5054 | $return .= '</option>'; |
| 4845 | 5055 | } |
| 4846 | 5056 | |
| 4847 | - if (!$options_only) |
|
| 4848 | - $return .= '</select>'; |
|
| 4849 | - } |
|
| 4850 | - else {
|
|
| 5057 | + if (!$options_only) { |
|
| 5058 | + $return .= '</select>'; |
|
| 5059 | + } |
|
| 5060 | + } else {
|
|
| 4851 | 5061 | $return .= $this->error; |
| 4852 | 5062 | } |
| 4853 | 5063 | |
@@ -4919,12 +5129,15 @@ discard block |
||
| 4919 | 5129 | |
| 4920 | 5130 | $retstring = ''; |
| 4921 | 5131 | |
| 4922 | - if ($prefix == '') |
|
| 4923 | - $prefix = 're'; |
|
| 4924 | - if ($h == '') |
|
| 4925 | - $h = 0; |
|
| 4926 | - if ($m == '') |
|
| 4927 | - $m = 0; |
|
| 5132 | + if ($prefix == '') { |
|
| 5133 | + $prefix = 're'; |
|
| 5134 | + } |
|
| 5135 | + if ($h == '') { |
|
| 5136 | + $h = 0; |
|
| 5137 | + } |
|
| 5138 | + if ($m == '') { |
|
| 5139 | + $m = 0; |
|
| 5140 | + } |
|
| 4928 | 5141 | $emptydate = 0; |
| 4929 | 5142 | $emptyhours = 0; |
| 4930 | 5143 | if ($empty == 1) {
|
@@ -4973,10 +5186,12 @@ discard block |
||
| 4973 | 5186 | $smin = !isset(Globals::$conf->global->MAIN_DEFAULT_DATE_MIN) ? ($h == -1 ? '59' : '') : Globals::$conf->global->MAIN_DEFAULT_DATE_MIN; |
| 4974 | 5187 | $ssec = !isset(Globals::$conf->global->MAIN_DEFAULT_DATE_SEC) ? ($h == -1 ? '59' : '') : Globals::$conf->global->MAIN_DEFAULT_DATE_SEC; |
| 4975 | 5188 | } |
| 4976 | - if ($h == 3) |
|
| 4977 | - $shour = ''; |
|
| 4978 | - if ($m == 3) |
|
| 4979 | - $smin = ''; |
|
| 5189 | + if ($h == 3) { |
|
| 5190 | + $shour = ''; |
|
| 5191 | + } |
|
| 5192 | + if ($m == 3) { |
|
| 5193 | + $smin = ''; |
|
| 5194 | + } |
|
| 4980 | 5195 | |
| 4981 | 5196 | // You can set MAIN_POPUP_CALENDAR to 'eldy' or 'jquery' |
| 4982 | 5197 | $usecalendar = 'combo'; |
@@ -5008,14 +5223,14 @@ discard block |
||
| 5008 | 5223 | $base = DOL_URL_ROOT . '/core/'; |
| 5009 | 5224 | $retstring .= ' onClick="showDP(\'' . $base . '\',\'' . $prefix . '\',\'' . $langs->trans("FormatDateShortJavaInput") . '\',\'' . $langs->defaultlang . '\');"';
|
| 5010 | 5225 | $retstring .= '>' . img_object($langs->trans("SelectDate"), 'calendarday', 'class="datecallink"') . '</button>';
|
| 5011 | - } else |
|
| 5012 | - $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>';
|
|
| 5226 | + } else { |
|
| 5227 | + $retstring .= '<button id="' . $prefix . 'Button" type="button" class="dpInvisibleButtons">' . img_object($langs->trans("Disabled"), 'calendarday', 'class="datecallink"') . '</button>'; |
|
| 5228 | + } |
|
| 5013 | 5229 | |
| 5014 | 5230 | $retstring .= '<input type="hidden" id="' . $prefix . 'day" name="' . $prefix . 'day" value="' . $sday . '">' . "\n"; |
| 5015 | 5231 | $retstring .= '<input type="hidden" id="' . $prefix . 'month" name="' . $prefix . 'month" value="' . $smonth . '">' . "\n"; |
| 5016 | 5232 | $retstring .= '<input type="hidden" id="' . $prefix . 'year" name="' . $prefix . 'year" value="' . $syear . '">' . "\n"; |
| 5017 | - } |
|
| 5018 | - elseif ($usecalendar == 'jquery') {
|
|
| 5233 | + } elseif ($usecalendar == 'jquery') {
|
|
| 5019 | 5234 | if (!$disabled) {
|
| 5020 | 5235 | // Output javascript for datepicker |
| 5021 | 5236 | $retstring .= "<script type='text/javascript'>"; |
@@ -5125,32 +5340,38 @@ discard block |
||
| 5125 | 5340 | } |
| 5126 | 5341 | } |
| 5127 | 5342 | |
| 5128 | - if ($d && $h) |
|
| 5129 | - $retstring .= ($h == 2 ? '<br>' : ' '); |
|
| 5343 | + if ($d && $h) { |
|
| 5344 | + $retstring .= ($h == 2 ? '<br>' : ' '); |
|
| 5345 | + } |
|
| 5130 | 5346 | |
| 5131 | 5347 | if ($h) {
|
| 5132 | 5348 | // Show hour |
| 5133 | 5349 | $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 ' . ($fullday ? $fullday . 'hour' : '') . '" id="' . $prefix . 'hour" name="' . $prefix . 'hour">'; |
| 5134 | - if ($emptyhours) |
|
| 5135 | - $retstring .= '<option value="-1"> </option>'; |
|
| 5350 | + if ($emptyhours) { |
|
| 5351 | + $retstring .= '<option value="-1"> </option>'; |
|
| 5352 | + } |
|
| 5136 | 5353 | for ($hour = 0; $hour < 24; $hour++) {
|
| 5137 | - if (strlen($hour) < 2) |
|
| 5138 | - $hour = "0" . $hour; |
|
| 5354 | + if (strlen($hour) < 2) { |
|
| 5355 | + $hour = "0" . $hour; |
|
| 5356 | + } |
|
| 5139 | 5357 | $retstring .= '<option value="' . $hour . '"' . (($hour == $shour) ? ' selected' : '') . '>' . $hour . (empty(Globals::$conf->dol_optimize_smallscreen) ? '' : 'H') . '</option>'; |
| 5140 | 5358 | } |
| 5141 | 5359 | $retstring .= '</select>'; |
| 5142 | - if ($m && empty(Globals::$conf->dol_optimize_smallscreen)) |
|
| 5143 | - $retstring .= ":"; |
|
| 5360 | + if ($m && empty(Globals::$conf->dol_optimize_smallscreen)) { |
|
| 5361 | + $retstring .= ":"; |
|
| 5362 | + } |
|
| 5144 | 5363 | } |
| 5145 | 5364 | |
| 5146 | 5365 | if ($m) {
|
| 5147 | 5366 | // Show minutes |
| 5148 | 5367 | $retstring .= '<select' . ($disabled ? ' disabled' : '') . ' class="flat valignmiddle maxwidth50 ' . ($fullday ? $fullday . 'min' : '') . '" id="' . $prefix . 'min" name="' . $prefix . 'min">'; |
| 5149 | - if ($emptyhours) |
|
| 5150 | - $retstring .= '<option value="-1"> </option>'; |
|
| 5368 | + if ($emptyhours) { |
|
| 5369 | + $retstring .= '<option value="-1"> </option>'; |
|
| 5370 | + } |
|
| 5151 | 5371 | for ($min = 0; $min < 60; $min++) {
|
| 5152 | - if (strlen($min) < 2) |
|
| 5153 | - $min = "0" . $min; |
|
| 5372 | + if (strlen($min) < 2) { |
|
| 5373 | + $min = "0" . $min; |
|
| 5374 | + } |
|
| 5154 | 5375 | $retstring .= '<option value="' . $min . '"' . (($min == $smin) ? ' selected' : '') . '>' . $min . (empty(Globals::$conf->dol_optimize_smallscreen) ? '' : '') . '</option>'; |
| 5155 | 5376 | } |
| 5156 | 5377 | $retstring .= '</select>'; |
@@ -5181,21 +5402,25 @@ discard block |
||
| 5181 | 5402 | } */ |
| 5182 | 5403 | // Update the hour part |
| 5183 | 5404 | if ($h) {
|
| 5184 | - if ($fullday) |
|
| 5185 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5405 | + if ($fullday) { |
|
| 5406 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5407 | + } |
|
| 5186 | 5408 | //$reset_scripts .= 'this.form.elements[\''.$prefix.'hour\'].value=formatDate(new Date(), \'HH\'); '; |
| 5187 | 5409 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . AlDolUtils::dol_print_date(dol_now(), '%H') . '\');'; |
| 5188 | - if ($fullday) |
|
| 5189 | - $reset_scripts .= ' } '; |
|
| 5410 | + if ($fullday) { |
|
| 5411 | + $reset_scripts .= ' } '; |
|
| 5412 | + } |
|
| 5190 | 5413 | } |
| 5191 | 5414 | // Update the minute part |
| 5192 | 5415 | if ($m) {
|
| 5193 | - if ($fullday) |
|
| 5194 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5416 | + if ($fullday) { |
|
| 5417 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5418 | + } |
|
| 5195 | 5419 | //$reset_scripts .= 'this.form.elements[\''.$prefix.'min\'].value=formatDate(new Date(), \'mm\'); '; |
| 5196 | 5420 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . AlDolUtils::dol_print_date(dol_now(), '%M') . '\');'; |
| 5197 | - if ($fullday) |
|
| 5198 | - $reset_scripts .= ' } '; |
|
| 5421 | + if ($fullday) { |
|
| 5422 | + $reset_scripts .= ' } '; |
|
| 5423 | + } |
|
| 5199 | 5424 | } |
| 5200 | 5425 | // If reset_scripts is not empty, print the link with the reset_scripts in the onClick |
| 5201 | 5426 | if ($reset_scripts && empty(Globals::$conf->dol_optimize_smallscreen)) {
|
@@ -5217,19 +5442,23 @@ discard block |
||
| 5217 | 5442 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'year\').val(\'' . AlDolUtils::dol_print_date(dol_now(), '%Y') . '\');'; |
| 5218 | 5443 | // Update the hour part |
| 5219 | 5444 | if ($h) {
|
| 5220 | - if ($fullday) |
|
| 5221 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5445 | + if ($fullday) { |
|
| 5446 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5447 | + } |
|
| 5222 | 5448 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'hour\').val(\'' . AlDolUtils::dol_print_date(dol_now(), '%H') . '\');'; |
| 5223 | - if ($fullday) |
|
| 5224 | - $reset_scripts .= ' } '; |
|
| 5449 | + if ($fullday) { |
|
| 5450 | + $reset_scripts .= ' } '; |
|
| 5451 | + } |
|
| 5225 | 5452 | } |
| 5226 | 5453 | // Update the minute part |
| 5227 | 5454 | if ($m) {
|
| 5228 | - if ($fullday) |
|
| 5229 | - $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {";
|
|
| 5455 | + if ($fullday) { |
|
| 5456 | + $reset_scripts .= " if (jQuery('#fullday:checked').val() == null) {"; |
|
| 5457 | + } |
|
| 5230 | 5458 | $reset_scripts .= 'jQuery(\'#' . $prefix . 'min\').val(\'' . AlDolUtils::dol_print_date(dol_now(), '%M') . '\');'; |
| 5231 | - if ($fullday) |
|
| 5232 | - $reset_scripts .= ' } '; |
|
| 5459 | + if ($fullday) { |
|
| 5460 | + $reset_scripts .= ' } '; |
|
| 5461 | + } |
|
| 5233 | 5462 | } |
| 5234 | 5463 | // If reset_scripts is not empty, print the link with the reset_scripts in the onClick |
| 5235 | 5464 | if ($reset_scripts && empty(Globals::$conf->dol_optimize_smallscreen)) {
|
@@ -5292,41 +5521,46 @@ discard block |
||
| 5292 | 5521 | $retstring .= "</select>"; |
| 5293 | 5522 | } elseif ($typehour == 'text' || $typehour == 'textselect') {
|
| 5294 | 5523 | $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) : '') . '">';
|
| 5295 | - } else |
|
| 5296 | - return 'BadValueForParameterTypeHour'; |
|
| 5524 | + } else { |
|
| 5525 | + return 'BadValueForParameterTypeHour'; |
|
| 5526 | + } |
|
| 5297 | 5527 | |
| 5298 | - if ($typehour != 'text') |
|
| 5299 | - $retstring .= ' ' . $langs->trans('HourShort');
|
|
| 5300 | - else |
|
| 5301 | - $retstring .= '<span class="hideonsmartphone">:</span>'; |
|
| 5528 | + if ($typehour != 'text') { |
|
| 5529 | + $retstring .= ' ' . $langs->trans('HourShort'); |
|
| 5530 | + } else { |
|
| 5531 | + $retstring .= '<span class="hideonsmartphone">:</span>'; |
|
| 5532 | + } |
|
| 5302 | 5533 | |
| 5303 | 5534 | // Minutes |
| 5304 | - if ($minunderhours) |
|
| 5305 | - $retstring .= '<br>'; |
|
| 5306 | - else |
|
| 5307 | - $retstring .= '<span class="hideonsmartphone"> </span>'; |
|
| 5535 | + if ($minunderhours) { |
|
| 5536 | + $retstring .= '<br>'; |
|
| 5537 | + } else { |
|
| 5538 | + $retstring .= '<span class="hideonsmartphone"> </span>'; |
|
| 5539 | + } |
|
| 5308 | 5540 | |
| 5309 | 5541 | if ($typehour == 'select' || $typehour == 'textselect') {
|
| 5310 | 5542 | $retstring .= '<select class="flat" id="select_' . $prefix . 'min" name="' . $prefix . 'min"' . ($disabled ? ' disabled' : '') . '>'; |
| 5311 | 5543 | for ($min = 0; $min <= 55; $min = $min + 5) {
|
| 5312 | 5544 | $retstring .= '<option value="' . $min . '"'; |
| 5313 | - if ($minSelected == $min) |
|
| 5314 | - $retstring .= ' selected'; |
|
| 5545 | + if ($minSelected == $min) { |
|
| 5546 | + $retstring .= ' selected'; |
|
| 5547 | + } |
|
| 5315 | 5548 | $retstring .= '>' . $min . '</option>'; |
| 5316 | 5549 | } |
| 5317 | 5550 | $retstring .= "</select>"; |
| 5318 | - } |
|
| 5319 | - elseif ($typehour == 'text') {
|
|
| 5551 | + } elseif ($typehour == 'text') {
|
|
| 5320 | 5552 | $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) : '') . '">';
|
| 5321 | 5553 | } |
| 5322 | 5554 | |
| 5323 | - if ($typehour != 'text') |
|
| 5324 | - $retstring .= ' ' . $langs->trans('MinuteShort');
|
|
| 5555 | + if ($typehour != 'text') { |
|
| 5556 | + $retstring .= ' ' . $langs->trans('MinuteShort'); |
|
| 5557 | + } |
|
| 5325 | 5558 | |
| 5326 | 5559 | //$retstring.=" "; |
| 5327 | 5560 | |
| 5328 | - if (!empty($nooutput)) |
|
| 5329 | - return $retstring; |
|
| 5561 | + if (!empty($nooutput)) { |
|
| 5562 | + return $retstring; |
|
| 5563 | + } |
|
| 5330 | 5564 | |
| 5331 | 5565 | print $retstring; |
| 5332 | 5566 | return; |
@@ -5369,8 +5603,9 @@ discard block |
||
| 5369 | 5603 | } |
| 5370 | 5604 | |
| 5371 | 5605 | $prefixforautocompletemode = $objecttmp->element; |
| 5372 | - if ($prefixforautocompletemode == 'societe') |
|
| 5373 | - $prefixforautocompletemode = 'company'; |
|
| 5606 | + if ($prefixforautocompletemode == 'societe') { |
|
| 5607 | + $prefixforautocompletemode = 'company'; |
|
| 5608 | + } |
|
| 5374 | 5609 | $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
| 5375 | 5610 | |
| 5376 | 5611 | dol_syslog(get_class($this) . "::selectForForms", LOG_DEBUG); |
@@ -5385,11 +5620,11 @@ discard block |
||
| 5385 | 5620 | // Activate the auto complete using ajax call. |
| 5386 | 5621 | $out .= ajax_autocompleter($preselectedvalue, $htmlname, $urlforajaxcall, $urloption, Globals::$conf->global->$confkeyforautocompletemode, 0, array()); |
| 5387 | 5622 | $out .= '<style type="text/css">.ui-autocomplete { z-index: 250; }</style>';
|
| 5388 | - if ($placeholder) |
|
| 5389 | - $placeholder = ' placeholder="' . $placeholder . '"'; |
|
| 5623 | + if ($placeholder) { |
|
| 5624 | + $placeholder = ' placeholder="' . $placeholder . '"'; |
|
| 5625 | + } |
|
| 5390 | 5626 | $out .= '<input type="text" class="' . $morecss . '" name="search_' . $htmlname . '" id="search_' . $htmlname . '" value="' . $preselectedvalue . '"' . $placeholder . ' />'; |
| 5391 | - } |
|
| 5392 | - else {
|
|
| 5627 | + } else {
|
|
| 5393 | 5628 | // Immediate load of all database |
| 5394 | 5629 | $out .= $this->selectForFormsList($objecttmp, $htmlname, $preselectedvalue, $showempty, $searchkey, $placeholder, $morecss, $moreparams, $forcecombo); |
| 5395 | 5630 | } |
@@ -5419,19 +5654,22 @@ discard block |
||
| 5419 | 5654 | global $conf, $langs, $user; |
| 5420 | 5655 | |
| 5421 | 5656 | $prefixforautocompletemode = $objecttmp->element; |
| 5422 | - if ($prefixforautocompletemode == 'societe') |
|
| 5423 | - $prefixforautocompletemode = 'company'; |
|
| 5657 | + if ($prefixforautocompletemode == 'societe') { |
|
| 5658 | + $prefixforautocompletemode = 'company'; |
|
| 5659 | + } |
|
| 5424 | 5660 | $confkeyforautocompletemode = strtoupper($prefixforautocompletemode) . '_USE_SEARCH_TO_SELECT'; // For example COMPANY_USE_SEARCH_TO_SELECT |
| 5425 | 5661 | |
| 5426 | 5662 | $fieldstoshow = 't.ref'; |
| 5427 | 5663 | if (!empty($objecttmp->fields)) { // For object that declare it, it is better to use declared fields ( like societe, contact, ...)
|
| 5428 | 5664 | $tmpfieldstoshow = ''; |
| 5429 | 5665 | foreach ($objecttmp->fields as $key => $val) {
|
| 5430 | - if ($val['showoncombobox']) |
|
| 5431 | - $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key; |
|
| 5666 | + if ($val['showoncombobox']) { |
|
| 5667 | + $tmpfieldstoshow .= ($tmpfieldstoshow ? ',' : '') . 't.' . $key; |
|
| 5668 | + } |
|
| 5432 | 5669 | } |
| 5433 | - if ($tmpfieldstoshow) |
|
| 5434 | - $fieldstoshow = $tmpfieldstoshow; |
|
| 5670 | + if ($tmpfieldstoshow) { |
|
| 5671 | + $fieldstoshow = $tmpfieldstoshow; |
|
| 5672 | + } |
|
| 5435 | 5673 | } |
| 5436 | 5674 | |
| 5437 | 5675 | $out = ''; |
@@ -5441,23 +5679,28 @@ discard block |
||
| 5441 | 5679 | |
| 5442 | 5680 | // Search data |
| 5443 | 5681 | $sql = "SELECT t.rowid, " . $fieldstoshow . " FROM " . MAIN_DB_PREFIX . $objecttmp->table_element . " as t"; |
| 5444 | - if ($objecttmp->ismultientitymanaged == 2) |
|
| 5445 | - if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5446 | - $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 5682 | + if ($objecttmp->ismultientitymanaged == 2) { |
|
| 5683 | + if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5684 | + $sql .= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
| 5685 | + } |
|
| 5447 | 5686 | $sql .= " WHERE 1=1"; |
| 5448 | - if (!empty($objecttmp->ismultientitymanaged)) |
|
| 5449 | - $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")";
|
|
| 5687 | + if (!empty($objecttmp->ismultientitymanaged)) { |
|
| 5688 | + $sql .= " AND t.entity IN (" . getEntity($objecttmp->table_element) . ")"; |
|
| 5689 | + } |
|
| 5450 | 5690 | if ($objecttmp->ismultientitymanaged == 1 && !empty($user->societe_id)) {
|
| 5451 | - if ($objecttmp->element == 'societe') |
|
| 5452 | - $sql .= " AND t.rowid = " . $user->societe_id; |
|
| 5453 | - else |
|
| 5454 | - $sql .= " AND t.fk_soc = " . $user->societe_id; |
|
| 5455 | - } |
|
| 5456 | - if ($searchkey != '') |
|
| 5457 | - $sql .= natural_search(explode(',', $fieldstoshow), $searchkey);
|
|
| 5458 | - if ($objecttmp->ismultientitymanaged == 2) |
|
| 5459 | - if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5460 | - $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 5691 | + if ($objecttmp->element == 'societe') { |
|
| 5692 | + $sql .= " AND t.rowid = " . $user->societe_id; |
|
| 5693 | + } else { |
|
| 5694 | + $sql .= " AND t.fk_soc = " . $user->societe_id; |
|
| 5695 | + } |
|
| 5696 | + } |
|
| 5697 | + if ($searchkey != '') { |
|
| 5698 | + $sql .= natural_search(explode(',', $fieldstoshow), $searchkey); |
|
| 5699 | + } |
|
| 5700 | + if ($objecttmp->ismultientitymanaged == 2) { |
|
| 5701 | + if (!$user->rights->societe->client->voir && !$user->societe_id) |
|
| 5702 | + $sql .= " AND t.rowid = sc.fk_soc AND sc.fk_user = " . $user->id; |
|
| 5703 | + } |
|
| 5461 | 5704 | $sql .= $this->db->order($fieldstoshow, "ASC"); |
| 5462 | 5705 | //$sql.=$this->db->plimit($limit, 0); |
| 5463 | 5706 | // Build output string |
@@ -5476,13 +5719,15 @@ discard block |
||
| 5476 | 5719 | |
| 5477 | 5720 | //if (! empty(Globals::$conf->use_javascript_ajax) || $forcecombo) $textifempty=''; |
| 5478 | 5721 | if (!empty(Globals::$conf->global->$confkeyforautocompletemode)) {
|
| 5479 | - if ($showempty && !is_numeric($showempty)) |
|
| 5480 | - $textifempty = $langs->trans($showempty); |
|
| 5481 | - else |
|
| 5482 | - $textifempty .= $langs->trans("All");
|
|
| 5722 | + if ($showempty && !is_numeric($showempty)) { |
|
| 5723 | + $textifempty = $langs->trans($showempty); |
|
| 5724 | + } else { |
|
| 5725 | + $textifempty .= $langs->trans("All"); |
|
| 5726 | + } |
|
| 5483 | 5727 | } |
| 5484 | - if ($showempty) |
|
| 5485 | - $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 5728 | + if ($showempty) { |
|
| 5729 | + $out .= '<option value="-1">' . $textifempty . '</option>' . "\n"; |
|
| 5730 | + } |
|
| 5486 | 5731 | |
| 5487 | 5732 | $num = $this->db->num_rows($resql); |
| 5488 | 5733 | $i = 0; |
@@ -5506,21 +5751,22 @@ discard block |
||
| 5506 | 5751 | } |
| 5507 | 5752 | |
| 5508 | 5753 | $i++; |
| 5509 | - if (($i % 10) == 0) |
|
| 5510 | - $out .= "\n"; |
|
| 5754 | + if (($i % 10) == 0) { |
|
| 5755 | + $out .= "\n"; |
|
| 5756 | + } |
|
| 5511 | 5757 | } |
| 5512 | 5758 | } |
| 5513 | 5759 | |
| 5514 | 5760 | $out .= '</select>' . "\n"; |
| 5515 | - } |
|
| 5516 | - else {
|
|
| 5761 | + } else {
|
|
| 5517 | 5762 | AlDolUtils::dol_print_error($this->db); |
| 5518 | 5763 | } |
| 5519 | 5764 | |
| 5520 | 5765 | $this->result = array('nbofelement' => $num);
|
| 5521 | 5766 | |
| 5522 | - if ($outputmode) |
|
| 5523 | - return $outarray; |
|
| 5767 | + if ($outputmode) { |
|
| 5768 | + return $outarray; |
|
| 5769 | + } |
|
| 5524 | 5770 | return $out; |
| 5525 | 5771 | } |
| 5526 | 5772 | |
@@ -5556,8 +5802,9 @@ discard block |
||
| 5556 | 5802 | //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1;
|
| 5557 | 5803 | $jsbeautify = 1; |
| 5558 | 5804 | |
| 5559 | - if ($value_as_key) |
|
| 5560 | - $array = array_combine($array, $array); |
|
| 5805 | + if ($value_as_key) { |
|
| 5806 | + $array = array_combine($array, $array); |
|
| 5807 | + } |
|
| 5561 | 5808 | |
| 5562 | 5809 | $out = ''; |
| 5563 | 5810 | |
@@ -5577,10 +5824,13 @@ discard block |
||
| 5577 | 5824 | |
| 5578 | 5825 | if ($show_empty) {
|
| 5579 | 5826 | $textforempty = ' '; |
| 5580 | - if (!empty(Globals::$conf->use_javascript_ajax)) |
|
| 5581 | - $textforempty = ' '; // If we use ajaxcombo, we need here to avoid to have an empty element that is too small. |
|
| 5582 | - if (!is_numeric($show_empty)) |
|
| 5583 | - $textforempty = $show_empty; |
|
| 5827 | + if (!empty(Globals::$conf->use_javascript_ajax)) { |
|
| 5828 | + $textforempty = ' '; |
|
| 5829 | + } |
|
| 5830 | + // If we use ajaxcombo, we need here to avoid to have an empty element that is too small. |
|
| 5831 | + if (!is_numeric($show_empty)) { |
|
| 5832 | + $textforempty = $show_empty; |
|
| 5833 | + } |
|
| 5584 | 5834 | $out .= '<option class="optiongrey" ' . ($moreparamonempty ? $moreparamonempty . ' ' : '') . 'value="' . ($show_empty < 0 ? $show_empty : -1) . '"' . ($id == $show_empty ? ' selected' : '') . '>' . $textforempty . '</option>' . "\n"; |
| 5585 | 5835 | } |
| 5586 | 5836 | |
@@ -5593,10 +5843,11 @@ discard block |
||
| 5593 | 5843 | } |
| 5594 | 5844 | |
| 5595 | 5845 | // Sort |
| 5596 | - if ($sort == 'ASC') |
|
| 5597 | - asort($array); |
|
| 5598 | - elseif ($sort == 'DESC') |
|
| 5599 | - arsort($array); |
|
| 5846 | + if ($sort == 'ASC') { |
|
| 5847 | + asort($array); |
|
| 5848 | + } elseif ($sort == 'DESC') { |
|
| 5849 | + arsort($array); |
|
| 5850 | + } |
|
| 5600 | 5851 | |
| 5601 | 5852 | foreach ($array as $key => $value) {
|
| 5602 | 5853 | $disabled = ''; |
@@ -5610,26 +5861,31 @@ discard block |
||
| 5610 | 5861 | } |
| 5611 | 5862 | |
| 5612 | 5863 | if ($key_in_label) {
|
| 5613 | - if (empty($nohtmlescape)) |
|
| 5614 | - $selectOptionValue = AlDolUtils::dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value)); |
|
| 5615 | - else |
|
| 5616 | - $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5617 | - } |
|
| 5618 | - else {
|
|
| 5619 | - if (empty($nohtmlescape)) |
|
| 5620 | - $selectOptionValue = AlDolUtils::dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5621 | - else |
|
| 5622 | - $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value; |
|
| 5623 | - if ($value == '' || $value == '-') |
|
| 5624 | - $selectOptionValue = ' '; |
|
| 5864 | + if (empty($nohtmlescape)) { |
|
| 5865 | + $selectOptionValue = AlDolUtils::dol_escape_htmltag($key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value)); |
|
| 5866 | + } else { |
|
| 5867 | + $selectOptionValue = $key . ' - ' . ($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5868 | + } |
|
| 5869 | + } else {
|
|
| 5870 | + if (empty($nohtmlescape)) { |
|
| 5871 | + $selectOptionValue = AlDolUtils::dol_escape_htmltag($maxlen ? dol_trunc($value, $maxlen) : $value); |
|
| 5872 | + } else { |
|
| 5873 | + $selectOptionValue = $maxlen ? dol_trunc($value, $maxlen) : $value; |
|
| 5874 | + } |
|
| 5875 | + if ($value == '' || $value == '-') { |
|
| 5876 | + $selectOptionValue = ' '; |
|
| 5877 | + } |
|
| 5625 | 5878 | } |
| 5626 | 5879 | |
| 5627 | 5880 | $out .= '<option value="' . $key . '"'; |
| 5628 | 5881 | $out .= $style . $disabled; |
| 5629 | - if ($id != '' && $id == $key && !$disabled) |
|
| 5630 | - $out .= ' selected'; // To preselect a value |
|
| 5631 | - if ($nohtmlescape) |
|
| 5632 | - $out .= ' data-html="' . AlDolUtils::dol_escape_htmltag($selectOptionValue) . '"'; |
|
| 5882 | + if ($id != '' && $id == $key && !$disabled) { |
|
| 5883 | + $out .= ' selected'; |
|
| 5884 | + } |
|
| 5885 | + // To preselect a value |
|
| 5886 | + if ($nohtmlescape) { |
|
| 5887 | + $out .= ' data-html="' . AlDolUtils::dol_escape_htmltag($selectOptionValue) . '"'; |
|
| 5888 | + } |
|
| 5633 | 5889 | $out .= '>'; |
| 5634 | 5890 | //var_dump($selectOptionValue); |
| 5635 | 5891 | $out .= $selectOptionValue; |
@@ -5665,8 +5921,9 @@ discard block |
||
| 5665 | 5921 | global $delayedhtmlcontent; |
| 5666 | 5922 | |
| 5667 | 5923 | // TODO Use an internal dolibarr component instead of select2 |
| 5668 | - if (empty(Globals::$conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT'))
|
|
| 5669 | - return ''; |
|
| 5924 | + if (empty(Globals::$conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) { |
|
| 5925 | + return ''; |
|
| 5926 | + } |
|
| 5670 | 5927 | |
| 5671 | 5928 | $out = '<select type="text" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"></select>'; |
| 5672 | 5929 | |
@@ -5765,8 +6022,9 @@ discard block |
||
| 5765 | 6022 | global $delayedhtmlcontent; |
| 5766 | 6023 | |
| 5767 | 6024 | // TODO Use an internal dolibarr component instead of select2 |
| 5768 | - if (empty(Globals::$conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT'))
|
|
| 5769 | - return ''; |
|
| 6025 | + if (empty(Globals::$conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) { |
|
| 6026 | + return ''; |
|
| 6027 | + } |
|
| 5770 | 6028 | |
| 5771 | 6029 | $out = '<select type="text" class="' . $htmlname . ($morecss ? ' ' . $morecss : '') . '" ' . ($moreparam ? $moreparam . ' ' : '') . 'name="' . $htmlname . '"><option></option></select>'; |
| 5772 | 6030 | |
@@ -5936,8 +6194,9 @@ discard block |
||
| 5936 | 6194 | |
| 5937 | 6195 | $out .= '<select id="' . $htmlname . '" class="multiselect' . ($morecss ? ' ' . $morecss : '') . '" multiple name="' . $htmlname . '[]"' . ($moreattrib ? ' ' . $moreattrib : '') . ($width ? ' style="width: ' . (preg_match('/%/', $width) ? $width : $width . 'px') . '"' : '') . '>' . "\n";
|
| 5938 | 6196 | if (is_array($array) && !empty($array)) {
|
| 5939 | - if ($value_as_key) |
|
| 5940 | - $array = array_combine($array, $array); |
|
| 6197 | + if ($value_as_key) { |
|
| 6198 | + $array = array_combine($array, $array); |
|
| 6199 | + } |
|
| 5941 | 6200 | |
| 5942 | 6201 | if (!empty($array)) {
|
| 5943 | 6202 | foreach ($array as $key => $value) {
|
@@ -5972,8 +6231,9 @@ discard block |
||
| 5972 | 6231 | {
|
| 5973 | 6232 | global $conf, $langs, $user; |
| 5974 | 6233 | |
| 5975 | - if (!empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) |
|
| 5976 | - return ''; |
|
| 6234 | + if (!empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { |
|
| 6235 | + return ''; |
|
| 6236 | + } |
|
| 5977 | 6237 | |
| 5978 | 6238 | $tmpvar = "MAIN_SELECTEDFIELDS_" . $varpage; |
| 5979 | 6239 | if (!empty($user->conf->$tmpvar)) {
|
@@ -5981,10 +6241,11 @@ discard block |
||
| 5981 | 6241 | foreach ($array as $key => $val) {
|
| 5982 | 6242 | //var_dump($key); |
| 5983 | 6243 | //var_dump($tmparray); |
| 5984 | - if (in_array($key, $tmparray)) |
|
| 5985 | - $array[$key]['checked'] = 1; |
|
| 5986 | - else |
|
| 5987 | - $array[$key]['checked'] = 0; |
|
| 6244 | + if (in_array($key, $tmparray)) { |
|
| 6245 | + $array[$key]['checked'] = 1; |
|
| 6246 | + } else { |
|
| 6247 | + $array[$key]['checked'] = 0; |
|
| 6248 | + } |
|
| 5988 | 6249 | } |
| 5989 | 6250 | } |
| 5990 | 6251 | //var_dump($array); |
@@ -6150,40 +6411,47 @@ discard block |
||
| 6150 | 6411 | // To work with non standard path |
| 6151 | 6412 | if ($objecttype == 'facture') {
|
| 6152 | 6413 | $tplpath = 'compta/' . $element; |
| 6153 | - if (empty(Globals::$conf->facture->enabled)) |
|
| 6154 | - continue; // Do not show if module disabled |
|
| 6155 | - } |
|
| 6156 | - else if ($objecttype == 'facturerec') {
|
|
| 6414 | + if (empty(Globals::$conf->facture->enabled)) { |
|
| 6415 | + continue; |
|
| 6416 | + } |
|
| 6417 | + // Do not show if module disabled |
|
| 6418 | + } else if ($objecttype == 'facturerec') {
|
|
| 6157 | 6419 | $tplpath = 'compta/facture'; |
| 6158 | 6420 | $tplname = 'linkedobjectblockForRec'; |
| 6159 | - if (empty(Globals::$conf->facture->enabled)) |
|
| 6160 | - continue; // Do not show if module disabled |
|
| 6161 | - } |
|
| 6162 | - else if ($objecttype == 'propal') {
|
|
| 6421 | + if (empty(Globals::$conf->facture->enabled)) { |
|
| 6422 | + continue; |
|
| 6423 | + } |
|
| 6424 | + // Do not show if module disabled |
|
| 6425 | + } else if ($objecttype == 'propal') {
|
|
| 6163 | 6426 | $tplpath = 'comm/' . $element; |
| 6164 | - if (empty(Globals::$conf->propal->enabled)) |
|
| 6165 | - continue; // Do not show if module disabled |
|
| 6166 | - } |
|
| 6167 | - else if ($objecttype == 'supplier_proposal') {
|
|
| 6168 | - if (empty(Globals::$conf->supplier_proposal->enabled)) |
|
| 6169 | - continue; // Do not show if module disabled |
|
| 6170 | - } |
|
| 6171 | - else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
|
|
| 6427 | + if (empty(Globals::$conf->propal->enabled)) { |
|
| 6428 | + continue; |
|
| 6429 | + } |
|
| 6430 | + // Do not show if module disabled |
|
| 6431 | + } else if ($objecttype == 'supplier_proposal') {
|
|
| 6432 | + if (empty(Globals::$conf->supplier_proposal->enabled)) { |
|
| 6433 | + continue; |
|
| 6434 | + } |
|
| 6435 | + // Do not show if module disabled |
|
| 6436 | + } else if ($objecttype == 'shipping' || $objecttype == 'shipment') {
|
|
| 6172 | 6437 | $tplpath = 'expedition'; |
| 6173 | - if (empty(Globals::$conf->expedition->enabled)) |
|
| 6174 | - continue; // Do not show if module disabled |
|
| 6175 | - } |
|
| 6176 | - else if ($objecttype == 'reception') {
|
|
| 6438 | + if (empty(Globals::$conf->expedition->enabled)) { |
|
| 6439 | + continue; |
|
| 6440 | + } |
|
| 6441 | + // Do not show if module disabled |
|
| 6442 | + } else if ($objecttype == 'reception') {
|
|
| 6177 | 6443 | $tplpath = 'reception'; |
| 6178 | - if (empty(Globals::$conf->reception->enabled)) |
|
| 6179 | - continue; // Do not show if module disabled |
|
| 6180 | - } |
|
| 6181 | - else if ($objecttype == 'delivery') {
|
|
| 6444 | + if (empty(Globals::$conf->reception->enabled)) { |
|
| 6445 | + continue; |
|
| 6446 | + } |
|
| 6447 | + // Do not show if module disabled |
|
| 6448 | + } else if ($objecttype == 'delivery') {
|
|
| 6182 | 6449 | $tplpath = 'livraison'; |
| 6183 | - if (empty(Globals::$conf->expedition->enabled)) |
|
| 6184 | - continue; // Do not show if module disabled |
|
| 6185 | - } |
|
| 6186 | - else if ($objecttype == 'invoice_supplier') {
|
|
| 6450 | + if (empty(Globals::$conf->expedition->enabled)) { |
|
| 6451 | + continue; |
|
| 6452 | + } |
|
| 6453 | + // Do not show if module disabled |
|
| 6454 | + } else if ($objecttype == 'invoice_supplier') {
|
|
| 6187 | 6455 | $tplpath = 'fourn/facture'; |
| 6188 | 6456 | } else if ($objecttype == 'order_supplier') {
|
| 6189 | 6457 | $tplpath = 'fourn/commande'; |
@@ -6247,20 +6515,23 @@ discard block |
||
| 6247 | 6515 | $linktoelemlist = ''; |
| 6248 | 6516 | $listofidcompanytoscan = ''; |
| 6249 | 6517 | |
| 6250 | - if (!is_object($object->thirdparty)) |
|
| 6251 | - $object->fetch_thirdparty(); |
|
| 6518 | + if (!is_object($object->thirdparty)) { |
|
| 6519 | + $object->fetch_thirdparty(); |
|
| 6520 | + } |
|
| 6252 | 6521 | |
| 6253 | 6522 | $possiblelinks = array(); |
| 6254 | 6523 | if (is_object($object->thirdparty) && !empty($object->thirdparty->id) && $object->thirdparty->id > 0) {
|
| 6255 | 6524 | $listofidcompanytoscan = $object->thirdparty->id; |
| 6256 | - if (($object->thirdparty->parent > 0) && !empty(Globals::$conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) |
|
| 6257 | - $listofidcompanytoscan .= ',' . $object->thirdparty->parent; |
|
| 6525 | + if (($object->thirdparty->parent > 0) && !empty(Globals::$conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) { |
|
| 6526 | + $listofidcompanytoscan .= ',' . $object->thirdparty->parent; |
|
| 6527 | + } |
|
| 6258 | 6528 | if (($object->fk_project > 0) && !empty(Globals::$conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO)) {
|
| 6259 | 6529 | include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; |
| 6260 | 6530 | $tmpproject = new Project($this->db); |
| 6261 | 6531 | $tmpproject->fetch($object->fk_project); |
| 6262 | - if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) |
|
| 6263 | - $listofidcompanytoscan .= ',' . $tmpproject->socid; |
|
| 6532 | + if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) { |
|
| 6533 | + $listofidcompanytoscan .= ',' . $tmpproject->socid; |
|
| 6534 | + } |
|
| 6264 | 6535 | unset($tmpproject); |
| 6265 | 6536 | } |
| 6266 | 6537 | |
@@ -6296,8 +6567,9 @@ discard block |
||
| 6296 | 6567 | foreach ($possiblelinks as $key => $possiblelink) {
|
| 6297 | 6568 | $num = 0; |
| 6298 | 6569 | |
| 6299 | - if (empty($possiblelink['enabled'])) |
|
| 6300 | - continue; |
|
| 6570 | + if (empty($possiblelink['enabled'])) { |
|
| 6571 | + continue; |
|
| 6572 | + } |
|
| 6301 | 6573 | |
| 6302 | 6574 | if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) {
|
| 6303 | 6575 | print '<div id="' . $key . 'list"' . (empty(Globals::$conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? ' style="display:none"' : '') . '>'; |
@@ -6348,11 +6620,13 @@ discard block |
||
| 6348 | 6620 | } |
| 6349 | 6621 | |
| 6350 | 6622 | //$linktoelem.=($linktoelem?' ':''); |
| 6351 | - if ($num > 0) |
|
| 6352 | - $linktoelemlist .= '<li><a href="#linkto' . $key . '" class="linkto dropdowncloseonclick" rel="' . $key . '">' . $langs->trans($possiblelink['label']) . ' (' . $num . ')</a></li>';
|
|
| 6623 | + if ($num > 0) { |
|
| 6624 | + $linktoelemlist .= '<li><a href="#linkto' . $key . '" class="linkto dropdowncloseonclick" rel="' . $key . '">' . $langs->trans($possiblelink['label']) . ' (' . $num . ')</a></li>'; |
|
| 6625 | + } |
|
| 6353 | 6626 | //else $linktoelem.=$langs->trans($possiblelink['label']); |
| 6354 | - else |
|
| 6355 | - $linktoelemlist .= '<li><span class="linktodisabled">' . $langs->trans($possiblelink['label']) . ' (0)</span></li>'; |
|
| 6627 | + else { |
|
| 6628 | + $linktoelemlist .= '<li><span class="linktodisabled">' . $langs->trans($possiblelink['label']) . ' (0)</span></li>'; |
|
| 6629 | + } |
|
| 6356 | 6630 | } |
| 6357 | 6631 | } |
| 6358 | 6632 | |
@@ -6410,8 +6684,9 @@ discard block |
||
| 6410 | 6684 | $disabled = ($disabled ? ' disabled' : ''); |
| 6411 | 6685 | |
| 6412 | 6686 | $resultyesno = '<select class="flat width75" id="' . $htmlname . '" name="' . $htmlname . '"' . $disabled . '>' . "\n"; |
| 6413 | - if ($useempty) |
|
| 6414 | - $resultyesno .= '<option value="-1"' . (($value < 0) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 6687 | + if ($useempty) { |
|
| 6688 | + $resultyesno .= '<option value="-1"' . (($value < 0) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 6689 | + } |
|
| 6415 | 6690 | if (("$value" == 'yes') || ($value == 1)) {
|
| 6416 | 6691 | $resultyesno .= '<option value="' . $yes . '" selected>' . $langs->trans("Yes") . '</option>' . "\n";
|
| 6417 | 6692 | $resultyesno .= '<option value="' . $no . '">' . $langs->trans("No") . '</option>' . "\n";
|
@@ -6490,10 +6765,12 @@ discard block |
||
| 6490 | 6765 | global $langs, $conf, $hookmanager; |
| 6491 | 6766 | |
| 6492 | 6767 | $ret = ''; |
| 6493 | - if (empty($fieldid)) |
|
| 6494 | - $fieldid = 'rowid'; |
|
| 6495 | - if (empty($fieldref)) |
|
| 6496 | - $fieldref = 'ref'; |
|
| 6768 | + if (empty($fieldid)) { |
|
| 6769 | + $fieldid = 'rowid'; |
|
| 6770 | + } |
|
| 6771 | + if (empty($fieldref)) { |
|
| 6772 | + $fieldref = 'ref'; |
|
| 6773 | + } |
|
| 6497 | 6774 | |
| 6498 | 6775 | // Add where from hooks |
| 6499 | 6776 | if (is_object($hookmanager)) {
|
@@ -6532,8 +6809,9 @@ discard block |
||
| 6532 | 6809 | $ret .= '<!-- Start banner content --><div style="vertical-align: middle">'; |
| 6533 | 6810 | |
| 6534 | 6811 | // Right part of banner |
| 6535 | - if ($morehtmlright) |
|
| 6536 | - $ret .= '<div class="inline-block floatleft">' . $morehtmlright . '</div>'; |
|
| 6812 | + if ($morehtmlright) { |
|
| 6813 | + $ret .= '<div class="inline-block floatleft">' . $morehtmlright . '</div>'; |
|
| 6814 | + } |
|
| 6537 | 6815 | |
| 6538 | 6816 | if ($previous_ref || $next_ref || $morehtml) {
|
| 6539 | 6817 | $ret .= '<div class="pagination paginationref"><ul class="right">'; |
@@ -6551,26 +6829,32 @@ discard block |
||
| 6551 | 6829 | |
| 6552 | 6830 | $parameters = array(); |
| 6553 | 6831 | $reshook = $hookmanager->executeHooks('moreHtmlStatus', $parameters, $object); // Note that $action and $object may have been modified by hook
|
| 6554 | - if (empty($reshook)) |
|
| 6555 | - $morehtmlstatus .= $hookmanager->resPrint; |
|
| 6556 | - else |
|
| 6557 | - $morehtmlstatus = $hookmanager->resPrint; |
|
| 6558 | - if ($morehtmlstatus) |
|
| 6559 | - $ret .= '<div class="statusref">' . $morehtmlstatus . '</div>'; |
|
| 6832 | + if (empty($reshook)) { |
|
| 6833 | + $morehtmlstatus .= $hookmanager->resPrint; |
|
| 6834 | + } else { |
|
| 6835 | + $morehtmlstatus = $hookmanager->resPrint; |
|
| 6836 | + } |
|
| 6837 | + if ($morehtmlstatus) { |
|
| 6838 | + $ret .= '<div class="statusref">' . $morehtmlstatus . '</div>'; |
|
| 6839 | + } |
|
| 6560 | 6840 | |
| 6561 | 6841 | $parameters = array(); |
| 6562 | 6842 | $reshook = $hookmanager->executeHooks('moreHtmlRef', $parameters, $object); // Note that $action and $object may have been modified by hook
|
| 6563 | - if (empty($reshook)) |
|
| 6564 | - $morehtmlref .= $hookmanager->resPrint; |
|
| 6565 | - elseif ($reshook > 0) |
|
| 6566 | - $morehtmlref = $hookmanager->resPrint; |
|
| 6843 | + if (empty($reshook)) { |
|
| 6844 | + $morehtmlref .= $hookmanager->resPrint; |
|
| 6845 | + } elseif ($reshook > 0) { |
|
| 6846 | + $morehtmlref = $hookmanager->resPrint; |
|
| 6847 | + } |
|
| 6567 | 6848 | |
| 6568 | 6849 | // Left part of banner |
| 6569 | 6850 | if ($morehtmlleft) {
|
| 6570 | - if (Globals::$conf->browser->layout == 'phone') |
|
| 6571 | - $ret .= '<div class="floatleft">' . $morehtmlleft . '</div>'; // class="center" to have photo in middle |
|
| 6572 | - else |
|
| 6573 | - $ret .= '<div class="inline-block floatleft">' . $morehtmlleft . '</div>'; |
|
| 6851 | + if (Globals::$conf->browser->layout == 'phone') { |
|
| 6852 | + $ret .= '<div class="floatleft">' . $morehtmlleft . '</div>'; |
|
| 6853 | + } |
|
| 6854 | + // class="center" to have photo in middle |
|
| 6855 | + else { |
|
| 6856 | + $ret .= '<div class="inline-block floatleft">' . $morehtmlleft . '</div>'; |
|
| 6857 | + } |
|
| 6574 | 6858 | } |
| 6575 | 6859 | |
| 6576 | 6860 | //if (Globals::$conf->browser->layout == 'phone') $ret.='<div class="clearboth"></div>'; |
@@ -6595,8 +6879,9 @@ discard block |
||
| 6595 | 6879 | $ret .= $object->label; |
| 6596 | 6880 | } else if ($object->element == 'ecm_directories') {
|
| 6597 | 6881 | $ret .= ''; |
| 6598 | - } else if ($fieldref != 'none') |
|
| 6599 | - $ret .= dol_htmlentities($object->$fieldref); |
|
| 6882 | + } else if ($fieldref != 'none') { |
|
| 6883 | + $ret .= dol_htmlentities($object->$fieldref); |
|
| 6884 | + } |
|
| 6600 | 6885 | |
| 6601 | 6886 | |
| 6602 | 6887 | if ($morehtmlref) {
|
@@ -6621,15 +6906,17 @@ discard block |
||
| 6621 | 6906 | global $conf; |
| 6622 | 6907 | |
| 6623 | 6908 | //Check if barcode is filled in the card |
| 6624 | - if (empty($object->barcode)) |
|
| 6625 | - return ''; |
|
| 6909 | + if (empty($object->barcode)) { |
|
| 6910 | + return ''; |
|
| 6911 | + } |
|
| 6626 | 6912 | |
| 6627 | 6913 | // Complete object if not complete |
| 6628 | 6914 | if (empty($object->barcode_type_code) || empty($object->barcode_type_coder)) {
|
| 6629 | 6915 | $result = $object->fetch_barcode(); |
| 6630 | 6916 | //Check if fetch_barcode() failed |
| 6631 | - if ($result < 1) |
|
| 6632 | - return '<!-- ErrorFetchBarcode -->'; |
|
| 6917 | + if ($result < 1) { |
|
| 6918 | + return '<!-- ErrorFetchBarcode -->'; |
|
| 6919 | + } |
|
| 6633 | 6920 | } |
| 6634 | 6921 | |
| 6635 | 6922 | // Barcode image |
@@ -6717,66 +7004,74 @@ discard block |
||
| 6717 | 7004 | if ($modulepart == 'memberphoto') {
|
| 6718 | 7005 | $dir = Globals::$conf->adherent->dir_output; |
| 6719 | 7006 | if (!empty($object->photo)) {
|
| 6720 | - if ((string) $imagesize == 'mini') |
|
| 6721 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6722 | - else if ((string) $imagesize == 'small') |
|
| 6723 | - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6724 | - else |
|
| 6725 | - $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 | + } |
|
| 6726 | 7014 | $originalfile = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; |
| 6727 | 7015 | } |
| 6728 | - if (!empty(Globals::$conf->global->MAIN_OLD_IMAGE_LINKS)) |
|
| 6729 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 7016 | + if (!empty(Globals::$conf->global->MAIN_OLD_IMAGE_LINKS)) { |
|
| 7017 | + $altfile = $object->id . ".jpg"; |
|
| 7018 | + } |
|
| 7019 | + // For backward compatibility |
|
| 6730 | 7020 | $email = $object->email; |
| 6731 | 7021 | $capture = 'user'; |
| 6732 | - } |
|
| 6733 | - else {
|
|
| 7022 | + } else {
|
|
| 6734 | 7023 | // Generic case to show photos |
| 6735 | 7024 | $dir = Globals::$conf->$modulepart->dir_output; |
| 6736 | 7025 | if (!empty($object->photo)) {
|
| 6737 | - if ((string) $imagesize == 'mini') |
|
| 6738 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); |
|
| 6739 | - else if ((string) $imagesize == 'small') |
|
| 6740 | - $file = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . getImageFileNameForSize($object->photo, '_small'); |
|
| 6741 | - else |
|
| 6742 | - $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 | + } |
|
| 6743 | 7033 | $originalfile = get_exdir($id, 2, 0, 0, $object, $modulepart) . 'photos/' . $object->photo; |
| 6744 | 7034 | } |
| 6745 | - if (!empty(Globals::$conf->global->MAIN_OLD_IMAGE_LINKS)) |
|
| 6746 | - $altfile = $object->id . ".jpg"; // For backward compatibility |
|
| 7035 | + if (!empty(Globals::$conf->global->MAIN_OLD_IMAGE_LINKS)) { |
|
| 7036 | + $altfile = $object->id . ".jpg"; |
|
| 7037 | + } |
|
| 7038 | + // For backward compatibility |
|
| 6747 | 7039 | $email = $object->email; |
| 6748 | 7040 | } |
| 6749 | 7041 | } |
| 6750 | 7042 | } |
| 6751 | - if ($forcecapture) |
|
| 6752 | - $capture = $forcecapture; |
|
| 7043 | + if ($forcecapture) { |
|
| 7044 | + $capture = $forcecapture; |
|
| 7045 | + } |
|
| 6753 | 7046 | |
| 6754 | 7047 | if ($dir) {
|
| 6755 | 7048 | if ($file && file_exists($dir . "/" . $file)) {
|
| 6756 | 7049 | if ($addlinktofullsize) {
|
| 6757 | 7050 | $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity=' . $entity); |
| 6758 | - if ($urladvanced) |
|
| 6759 | - $ret .= '<a href="' . $urladvanced . '">'; |
|
| 6760 | - else |
|
| 6761 | - $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7051 | + if ($urladvanced) { |
|
| 7052 | + $ret .= '<a href="' . $urladvanced . '">'; |
|
| 7053 | + } else { |
|
| 7054 | + $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7055 | + } |
|
| 6762 | 7056 | } |
| 6763 | 7057 | $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 . '">';
|
| 6764 | - if ($addlinktofullsize) |
|
| 6765 | - $ret .= '</a>'; |
|
| 6766 | - } |
|
| 6767 | - else if ($altfile && file_exists($dir . "/" . $altfile)) {
|
|
| 7058 | + if ($addlinktofullsize) { |
|
| 7059 | + $ret .= '</a>'; |
|
| 7060 | + } |
|
| 7061 | + } else if ($altfile && file_exists($dir . "/" . $altfile)) {
|
|
| 6768 | 7062 | if ($addlinktofullsize) {
|
| 6769 | 7063 | $urladvanced = getAdvancedPreviewUrl($modulepart, $originalfile, 0, '&entity=' . $entity); |
| 6770 | - if ($urladvanced) |
|
| 6771 | - $ret .= '<a href="' . $urladvanced . '">'; |
|
| 6772 | - else |
|
| 6773 | - $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7064 | + if ($urladvanced) { |
|
| 7065 | + $ret .= '<a href="' . $urladvanced . '">'; |
|
| 7066 | + } else { |
|
| 7067 | + $ret .= '<a href="' . DOL_URL_ROOT . '/viewimage.php?modulepart=' . $modulepart . '&entity=' . $entity . '&file=' . urlencode($originalfile) . '&cache=' . $cache . '">'; |
|
| 7068 | + } |
|
| 6774 | 7069 | } |
| 6775 | 7070 | $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 . '">';
|
| 6776 | - if ($addlinktofullsize) |
|
| 6777 | - $ret .= '</a>'; |
|
| 6778 | - } |
|
| 6779 | - else {
|
|
| 7071 | + if ($addlinktofullsize) { |
|
| 7072 | + $ret .= '</a>'; |
|
| 7073 | + } |
|
| 7074 | + } else {
|
|
| 6780 | 7075 | $nophoto = '/public/theme/common/nophoto.png'; |
| 6781 | 7076 | if (in_array($modulepart, array('userphoto', 'contact'))) { // For module that are "physical" users
|
| 6782 | 7077 | $nophoto = '/public/theme/common/user_anonymous.png'; |
@@ -6814,8 +7109,9 @@ discard block |
||
| 6814 | 7109 | $ret .= '<tr><td class="tdoverflow"><input type="file" class="flat maxwidth200onsmartphone" name="photo" id="photoinput"' . ($capture ? ' capture="' . $capture . '"' : '') . '></td></tr>'; |
| 6815 | 7110 | $ret .= '</table>'; |
| 6816 | 7111 | } |
| 6817 | - } else |
|
| 6818 | - AlDolUtils::dol_print_error('', 'Call of showphoto with wrong parameters modulepart=' . $modulepart);
|
|
| 7112 | + } else { |
|
| 7113 | + AlDolUtils::dol_print_error('', 'Call of showphoto with wrong parameters modulepart=' . $modulepart); |
|
| 7114 | + } |
|
| 6819 | 7115 | |
| 6820 | 7116 | return $ret; |
| 6821 | 7117 | } |
@@ -6842,14 +7138,17 @@ discard block |
||
| 6842 | 7138 | global $conf, $user, $langs; |
| 6843 | 7139 | |
| 6844 | 7140 | // Permettre l'exclusion de groupes |
| 6845 | - if (is_array($exclude)) |
|
| 6846 | - $excludeGroups = implode("','", $exclude);
|
|
| 7141 | + if (is_array($exclude)) { |
|
| 7142 | + $excludeGroups = implode("','", $exclude); |
|
| 7143 | + } |
|
| 6847 | 7144 | // Permettre l'inclusion de groupes |
| 6848 | - if (is_array($include)) |
|
| 6849 | - $includeGroups = implode("','", $include);
|
|
| 7145 | + if (is_array($include)) { |
|
| 7146 | + $includeGroups = implode("','", $include); |
|
| 7147 | + } |
|
| 6850 | 7148 | |
| 6851 | - if (!is_array($selected)) |
|
| 6852 | - $selected = array($selected); |
|
| 7149 | + if (!is_array($selected)) { |
|
| 7150 | + $selected = array($selected); |
|
| 7151 | + } |
|
| 6853 | 7152 | |
| 6854 | 7153 | $out = ''; |
| 6855 | 7154 | |
@@ -6861,18 +7160,20 @@ discard block |
||
| 6861 | 7160 | $sql .= " FROM " . MAIN_DB_PREFIX . "usergroup as ug "; |
| 6862 | 7161 | if (!empty(Globals::$conf->multicompany->enabled) && Globals::$conf->entity == 1 && $user->admin && !$user->entity) {
|
| 6863 | 7162 | $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entity as e ON e.rowid=ug.entity"; |
| 6864 | - if ($force_entity) |
|
| 6865 | - $sql .= " WHERE ug.entity IN (0," . $force_entity . ")"; |
|
| 6866 | - else |
|
| 6867 | - $sql .= " WHERE ug.entity IS NOT NULL"; |
|
| 6868 | - } |
|
| 6869 | - else {
|
|
| 7163 | + if ($force_entity) { |
|
| 7164 | + $sql .= " WHERE ug.entity IN (0," . $force_entity . ")"; |
|
| 7165 | + } else { |
|
| 7166 | + $sql .= " WHERE ug.entity IS NOT NULL"; |
|
| 7167 | + } |
|
| 7168 | + } else {
|
|
| 6870 | 7169 | $sql .= " WHERE ug.entity IN (0," . Globals::$conf->entity . ")"; |
| 6871 | 7170 | } |
| 6872 | - if (is_array($exclude) && $excludeGroups) |
|
| 6873 | - $sql .= " AND ug.rowid NOT IN ('" . $excludeGroups . "')";
|
|
| 6874 | - if (is_array($include) && $includeGroups) |
|
| 6875 | - $sql .= " AND ug.rowid IN ('" . $includeGroups . "')";
|
|
| 7171 | + if (is_array($exclude) && $excludeGroups) { |
|
| 7172 | + $sql .= " AND ug.rowid NOT IN ('" . $excludeGroups . "')"; |
|
| 7173 | + } |
|
| 7174 | + if (is_array($include) && $includeGroups) { |
|
| 7175 | + $sql .= " AND ug.rowid IN ('" . $includeGroups . "')"; |
|
| 7176 | + } |
|
| 6876 | 7177 | $sql .= " ORDER BY ug.nom ASC"; |
| 6877 | 7178 | |
| 6878 | 7179 | dol_syslog(get_class($this) . "::select_dolgroups", LOG_DEBUG); |
@@ -6887,18 +7188,21 @@ discard block |
||
| 6887 | 7188 | $num = $this->db->num_rows($resql); |
| 6888 | 7189 | $i = 0; |
| 6889 | 7190 | if ($num) {
|
| 6890 | - if ($show_empty && !$multiple) |
|
| 6891 | - $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 7191 | + if ($show_empty && !$multiple) { |
|
| 7192 | + $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '> </option>' . "\n"; |
|
| 7193 | + } |
|
| 6892 | 7194 | |
| 6893 | 7195 | while ($i < $num) {
|
| 6894 | 7196 | $obj = $this->db->fetch_object($resql); |
| 6895 | 7197 | $disableline = 0; |
| 6896 | - if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) |
|
| 6897 | - $disableline = 1; |
|
| 7198 | + if (is_array($enableonly) && count($enableonly) && !in_array($obj->rowid, $enableonly)) { |
|
| 7199 | + $disableline = 1; |
|
| 7200 | + } |
|
| 6898 | 7201 | |
| 6899 | 7202 | $out .= '<option value="' . $obj->rowid . '"'; |
| 6900 | - if ($disableline) |
|
| 6901 | - $out .= ' disabled'; |
|
| 7203 | + if ($disableline) { |
|
| 7204 | + $out .= ' disabled'; |
|
| 7205 | + } |
|
| 6902 | 7206 | if ((is_object($selected[0]) && $selected[0]->id == $obj->rowid) || (!is_object($selected[0]) && in_array($obj->rowid, $selected) )) {
|
| 6903 | 7207 | $out .= ' selected'; |
| 6904 | 7208 | } |
@@ -6913,13 +7217,13 @@ discard block |
||
| 6913 | 7217 | $i++; |
| 6914 | 7218 | } |
| 6915 | 7219 | } else {
|
| 6916 | - if ($show_empty) |
|
| 6917 | - $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '></option>' . "\n"; |
|
| 7220 | + if ($show_empty) { |
|
| 7221 | + $out .= '<option value="-1"' . (in_array(-1, $selected) ? ' selected' : '') . '></option>' . "\n"; |
|
| 7222 | + } |
|
| 6918 | 7223 | $out .= '<option value="" disabled>' . $langs->trans("NoUserGroupDefined") . '</option>';
|
| 6919 | 7224 | } |
| 6920 | 7225 | $out .= '</select>'; |
| 6921 | - } |
|
| 6922 | - else {
|
|
| 7226 | + } else {
|
|
| 6923 | 7227 | AlDolUtils::dol_print_error($this->db); |
| 6924 | 7228 | } |
| 6925 | 7229 | |
@@ -6955,8 +7259,9 @@ discard block |
||
| 6955 | 7259 | global $conf, $langs; |
| 6956 | 7260 | |
| 6957 | 7261 | $out = ''; |
| 6958 | - if (!empty(Globals::$conf->use_javascript_ajax)) |
|
| 6959 | - $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="checkallactions" name="checkallactions" class="checkallactions"></div>'; |
|
| 7262 | + if (!empty(Globals::$conf->use_javascript_ajax)) { |
|
| 7263 | + $out .= '<div class="inline-block checkallactions"><input type="checkbox" id="checkallactions" name="checkallactions" class="checkallactions"></div>'; |
|
| 7264 | + } |
|
| 6960 | 7265 | $out .= '<script type="text/javascript"> |
| 6961 | 7266 | $(document).ready(function() {
|
| 6962 | 7267 | $("#checkallactions").click(function() {
|
@@ -6969,8 +7274,9 @@ discard block |
||
| 6969 | 7274 | console.log("We uncheck all");
|
| 6970 | 7275 | $(".' . $cssclass . '").prop(\'checked\', false).trigger(\'change\');
|
| 6971 | 7276 | }' . "\n"; |
| 6972 | - if ($calljsfunction) |
|
| 6973 | - $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }';
|
|
| 7277 | + if ($calljsfunction) { |
|
| 7278 | + $out .= 'if (typeof initCheckForSelect == \'function\') { initCheckForSelect(0); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }'; |
|
| 7279 | + } |
|
| 6974 | 7280 | $out .= ' }); |
| 6975 | 7281 | |
| 6976 | 7282 | $(".checkforselect").change(function() {
|
@@ -7018,22 +7324,25 @@ discard block |
||
| 7018 | 7324 | |
| 7019 | 7325 | $sql = 'SELECT rowid, label FROM ' . MAIN_DB_PREFIX . 'c_exp_tax_cat WHERE active = 1'; |
| 7020 | 7326 | $sql .= ' AND entity IN (0,' . getEntity('exp_tax_cat') . ')';
|
| 7021 | - if (!empty($excludeid)) |
|
| 7022 | - $sql .= ' AND rowid NOT IN (' . implode(',', $excludeid) . ')';
|
|
| 7327 | + if (!empty($excludeid)) { |
|
| 7328 | + $sql .= ' AND rowid NOT IN (' . implode(',', $excludeid) . ')'; |
|
| 7329 | + } |
|
| 7023 | 7330 | $sql .= ' ORDER BY label'; |
| 7024 | 7331 | |
| 7025 | 7332 | $resql = $db->query($sql); |
| 7026 | 7333 | if ($resql) {
|
| 7027 | 7334 | $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
| 7028 | - if ($useempty) |
|
| 7029 | - $out .= '<option value="0"> </option>'; |
|
| 7335 | + if ($useempty) { |
|
| 7336 | + $out .= '<option value="0"> </option>'; |
|
| 7337 | + } |
|
| 7030 | 7338 | |
| 7031 | 7339 | while ($obj = $db->fetch_object($resql)) {
|
| 7032 | 7340 | $out .= '<option ' . ($selected == $obj->rowid ? 'selected="selected"' : '') . ' value="' . $obj->rowid . '">' . $langs->trans($obj->label) . '</option>'; |
| 7033 | 7341 | } |
| 7034 | 7342 | $out .= '</select>'; |
| 7035 | - if (!empty($htmlname) && $user->admin) |
|
| 7036 | - $out .= ' ' . info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
|
| 7343 | + if (!empty($htmlname) && $user->admin) { |
|
| 7344 | + $out .= ' ' . info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); |
|
| 7345 | + } |
|
| 7037 | 7346 | |
| 7038 | 7347 | if (!empty($target)) {
|
| 7039 | 7348 | $sql = "SELECT c.id FROM " . MAIN_DB_PREFIX . "c_type_fees as c WHERE c.code = 'EX_KME' AND c.active = 1"; |
@@ -7046,8 +7355,9 @@ discard block |
||
| 7046 | 7355 | $("select[name=' . $target . ']").on("change", function() {
|
| 7047 | 7356 | var current_val = $(this).val(); |
| 7048 | 7357 | if (current_val == ' . $obj->id . ') {';
|
| 7049 | - if (!empty($default_selected) || !empty($selected)) |
|
| 7050 | - $out .= '$("select[name=' . $htmlname . ']").val("' . ($default_selected > 0 ? $default_selected : $selected) . '");';
|
|
| 7358 | + if (!empty($default_selected) || !empty($selected)) { |
|
| 7359 | + $out .= '$("select[name=' . $htmlname . ']").val("' . ($default_selected > 0 ? $default_selected : $selected) . '");'; |
|
| 7360 | + } |
|
| 7051 | 7361 | |
| 7052 | 7362 | $out .= ' |
| 7053 | 7363 | $("select[name=' . $htmlname . ']").change();
|
@@ -7083,8 +7393,7 @@ discard block |
||
| 7083 | 7393 | } |
| 7084 | 7394 | } |
| 7085 | 7395 | } |
| 7086 | - } |
|
| 7087 | - else {
|
|
| 7396 | + } else {
|
|
| 7088 | 7397 | AlDolUtils::dol_print_error($db); |
| 7089 | 7398 | } |
| 7090 | 7399 | |
@@ -7109,8 +7418,9 @@ discard block |
||
| 7109 | 7418 | $resql = $db->query($sql); |
| 7110 | 7419 | if ($resql) {
|
| 7111 | 7420 | $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
| 7112 | - if ($useempty) |
|
| 7113 | - $out .= '<option value="0"></option>'; |
|
| 7421 | + if ($useempty) { |
|
| 7422 | + $out .= '<option value="0"></option>'; |
|
| 7423 | + } |
|
| 7114 | 7424 | |
| 7115 | 7425 | while ($obj = $db->fetch_object($resql)) {
|
| 7116 | 7426 | $out .= '<option ' . ($selected == $obj->rowid ? 'selected="selected"' : '') . ' value="' . $obj->rowid . '">' . price($obj->range_ik, 0, $langs, 1, 0) . '</option>'; |
@@ -7143,14 +7453,17 @@ discard block |
||
| 7143 | 7453 | $resql = $db->query($sql); |
| 7144 | 7454 | if ($resql) {
|
| 7145 | 7455 | $out = '<select id="select_' . $htmlname . '" name="' . $htmlname . '" class="' . $htmlname . ' flat minwidth75imp">'; |
| 7146 | - if ($useempty) |
|
| 7147 | - $out .= '<option value="0"></option>'; |
|
| 7148 | - if ($allchoice) |
|
| 7149 | - $out .= '<option value="-1">' . $langs->trans('AllExpenseReport') . '</option>';
|
|
| 7456 | + if ($useempty) { |
|
| 7457 | + $out .= '<option value="0"></option>'; |
|
| 7458 | + } |
|
| 7459 | + if ($allchoice) { |
|
| 7460 | + $out .= '<option value="-1">' . $langs->trans('AllExpenseReport') . '</option>'; |
|
| 7461 | + } |
|
| 7150 | 7462 | |
| 7151 | 7463 | $field = 'code'; |
| 7152 | - if ($useid) |
|
| 7153 | - $field = 'id'; |
|
| 7464 | + if ($useid) { |
|
| 7465 | + $field = 'id'; |
|
| 7466 | + } |
|
| 7154 | 7467 | |
| 7155 | 7468 | while ($obj = $db->fetch_object($resql)) {
|
| 7156 | 7469 | $key = $langs->trans($obj->code); |
@@ -51,70 +51,70 @@ discard block |
||
| 51 | 51 | */ |
| 52 | 52 | function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode) |
| 53 | 53 | { |
| 54 | - global $conf,$langs; |
|
| 54 | + global $conf,$langs; |
|
| 55 | 55 | //global $dolauthmode; // To return authentication finally used |
| 56 | 56 | |
| 57 | - // Check parameters |
|
| 58 | - if ($entitytotest == '') $entitytotest=1; |
|
| 57 | + // Check parameters |
|
| 58 | + if ($entitytotest == '') $entitytotest=1; |
|
| 59 | 59 | |
| 60 | 60 | dol_syslog("checkLoginPassEntity usertotest=".$usertotest." entitytotest=".$entitytotest." authmode=".join(',',$authmode)); |
| 61 | - $login = ''; |
|
| 62 | - |
|
| 63 | - // Validation of login/pass/entity with standard modules |
|
| 64 | - if (empty($login)) |
|
| 65 | - { |
|
| 66 | - $test=true; |
|
| 67 | - foreach($authmode as $mode) |
|
| 68 | - { |
|
| 69 | - if ($test && $mode && ! $login) |
|
| 70 | - { |
|
| 71 | - // Validation of login/pass/entity for mode $mode |
|
| 72 | - $mode=trim($mode); |
|
| 73 | - $authfile='functions_'.$mode.'.php'; |
|
| 74 | - $fullauthfile=''; |
|
| 75 | - |
|
| 76 | - $dirlogin=array_merge(array("/core/login"),(array) $conf->modules_parts['login']); |
|
| 77 | - foreach($dirlogin as $reldir) |
|
| 78 | - { |
|
| 79 | - $dir=dol_buildpath($reldir,0); |
|
| 80 | - $newdir=dol_osencode($dir); |
|
| 81 | - |
|
| 82 | - // Check if file found (do not use dol_is_file to avoid loading files.lib.php) |
|
| 83 | - $tmpnewauthfile = $newdir.(preg_match('/\/$/',$newdir)?'':'/').$authfile; |
|
| 84 | - if (is_file($tmpnewauthfile)) $fullauthfile=$tmpnewauthfile; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $result=false; |
|
| 88 | - if ($fullauthfile) $result=include_once $fullauthfile; |
|
| 89 | - if ($fullauthfile && $result) |
|
| 90 | - { |
|
| 91 | - // Call function to check user/password |
|
| 92 | - $function='check_user_password_'.$mode; |
|
| 93 | - $login=call_user_func($function, $usertotest, $passwordtotest, $entitytotest); |
|
| 94 | - if ($login) // Login is successfull |
|
| 95 | - { |
|
| 96 | - $test=false; // To stop once at first login success |
|
| 97 | - $conf->authmode=$mode; // This properties is defined only when logged to say what mode was successfully used |
|
| 98 | - $dol_tz=GETPOST('tz'); |
|
| 99 | - $dol_dst=GETPOST('dst'); |
|
| 100 | - $dol_screenwidth=GETPOST('screenwidth'); |
|
| 101 | - $dol_screenheight=GETPOST('screenheight'); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - else |
|
| 105 | - { |
|
| 106 | - dol_syslog("Authentification ko - failed to load file '".$authfile."'", LOG_ERR); |
|
| 107 | - sleep(1); |
|
| 108 | - // Load translation files required by the page |
|
| 61 | + $login = ''; |
|
| 62 | + |
|
| 63 | + // Validation of login/pass/entity with standard modules |
|
| 64 | + if (empty($login)) |
|
| 65 | + { |
|
| 66 | + $test=true; |
|
| 67 | + foreach($authmode as $mode) |
|
| 68 | + { |
|
| 69 | + if ($test && $mode && ! $login) |
|
| 70 | + { |
|
| 71 | + // Validation of login/pass/entity for mode $mode |
|
| 72 | + $mode=trim($mode); |
|
| 73 | + $authfile='functions_'.$mode.'.php'; |
|
| 74 | + $fullauthfile=''; |
|
| 75 | + |
|
| 76 | + $dirlogin=array_merge(array("/core/login"),(array) $conf->modules_parts['login']); |
|
| 77 | + foreach($dirlogin as $reldir) |
|
| 78 | + { |
|
| 79 | + $dir=dol_buildpath($reldir,0); |
|
| 80 | + $newdir=dol_osencode($dir); |
|
| 81 | + |
|
| 82 | + // Check if file found (do not use dol_is_file to avoid loading files.lib.php) |
|
| 83 | + $tmpnewauthfile = $newdir.(preg_match('/\/$/',$newdir)?'':'/').$authfile; |
|
| 84 | + if (is_file($tmpnewauthfile)) $fullauthfile=$tmpnewauthfile; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $result=false; |
|
| 88 | + if ($fullauthfile) $result=include_once $fullauthfile; |
|
| 89 | + if ($fullauthfile && $result) |
|
| 90 | + { |
|
| 91 | + // Call function to check user/password |
|
| 92 | + $function='check_user_password_'.$mode; |
|
| 93 | + $login=call_user_func($function, $usertotest, $passwordtotest, $entitytotest); |
|
| 94 | + if ($login) // Login is successfull |
|
| 95 | + { |
|
| 96 | + $test=false; // To stop once at first login success |
|
| 97 | + $conf->authmode=$mode; // This properties is defined only when logged to say what mode was successfully used |
|
| 98 | + $dol_tz=GETPOST('tz'); |
|
| 99 | + $dol_dst=GETPOST('dst'); |
|
| 100 | + $dol_screenwidth=GETPOST('screenwidth'); |
|
| 101 | + $dol_screenheight=GETPOST('screenheight'); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + else |
|
| 105 | + { |
|
| 106 | + dol_syslog("Authentification ko - failed to load file '".$authfile."'", LOG_ERR); |
|
| 107 | + sleep(1); |
|
| 108 | + // Load translation files required by the page |
|
| 109 | 109 | $langs->loadLangs(array('other', 'main', 'errors')); |
| 110 | 110 | |
| 111 | - $_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode", $mode); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 111 | + $_SESSION["dol_loginmesg"]=$langs->trans("ErrorFailedToLoadLoginFileForMode", $mode); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return $login; |
|
| 117 | + return $login; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -130,9 +130,9 @@ discard block |
||
| 130 | 130 | * @return void |
| 131 | 131 | */ |
| 132 | 132 | function dol_loginfunction($langs,$conf,$mysoc) |
| 133 | - { |
|
| 134 | - global $dolibarr_main_demo,$db; |
|
| 135 | - global $smartphone,$hookmanager; |
|
| 133 | + { |
|
| 134 | + global $dolibarr_main_demo,$db; |
|
| 135 | + global $smartphone,$hookmanager; |
|
| 136 | 136 | |
| 137 | 137 | $langs->loadLangs(array("main", "other", "help", "admin")); |
| 138 | 138 | |
@@ -143,16 +143,16 @@ discard block |
||
| 143 | 143 | |
| 144 | 144 | $session_name=session_name(); // Get current session name |
| 145 | 145 | |
| 146 | - $dol_url_root = DOL_URL_ROOT; |
|
| 146 | + $dol_url_root = DOL_URL_ROOT; |
|
| 147 | 147 | |
| 148 | - // Title |
|
| 149 | - $appli=constant('DOL_APPLICATION_TITLE'); |
|
| 150 | - $title=$appli.' '.constant('DOL_VERSION'); |
|
| 151 | - if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; |
|
| 152 | - $titletruedolibarrversion=constant('DOL_VERSION'); // $title used by login template after the @ to inform of true Dolibarr version |
|
| 148 | + // Title |
|
| 149 | + $appli=constant('DOL_APPLICATION_TITLE'); |
|
| 150 | + $title=$appli.' '.constant('DOL_VERSION'); |
|
| 151 | + if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; |
|
| 152 | + $titletruedolibarrversion=constant('DOL_VERSION'); // $title used by login template after the @ to inform of true Dolibarr version |
|
| 153 | 153 | |
| 154 | - // Note: $conf->css looks like '/theme/eldy/style.css.php' |
|
| 155 | - /* |
|
| 154 | + // Note: $conf->css looks like '/theme/eldy/style.css.php' |
|
| 155 | + /* |
|
| 156 | 156 | $conf->css = "/theme/".(GETPOST('theme','alpha')?GETPOST('theme','alpha'):$conf->theme)."/style.css.php"; |
| 157 | 157 | $themepath=dol_buildpath($conf->css,1); |
| 158 | 158 | if (! empty($conf->modules_parts['theme'])) // Using this feature slow down application |
@@ -169,138 +169,138 @@ discard block |
||
| 169 | 169 | $conf_css = $themepath."?lang=".$langs->defaultlang; |
| 170 | 170 | */ |
| 171 | 171 | |
| 172 | - // Select templates dir |
|
| 173 | - if (! empty($conf->modules_parts['tpl'])) // Using this feature slow down application |
|
| 174 | - { |
|
| 175 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl/')); |
|
| 176 | - foreach($dirtpls as $reldir) |
|
| 177 | - { |
|
| 178 | - $tmp=dol_buildpath($reldir.'login.tpl.php'); |
|
| 179 | - if (file_exists($tmp)) { $template_dir=preg_replace('/login\.tpl\.php$/','',$tmp); break; } |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - else |
|
| 183 | - { |
|
| 184 | - $template_dir = DOL_DOCUMENT_ROOT."/core/tpl/"; |
|
| 185 | - } |
|
| 172 | + // Select templates dir |
|
| 173 | + if (! empty($conf->modules_parts['tpl'])) // Using this feature slow down application |
|
| 174 | + { |
|
| 175 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl/')); |
|
| 176 | + foreach($dirtpls as $reldir) |
|
| 177 | + { |
|
| 178 | + $tmp=dol_buildpath($reldir.'login.tpl.php'); |
|
| 179 | + if (file_exists($tmp)) { $template_dir=preg_replace('/login\.tpl\.php$/','',$tmp); break; } |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + else |
|
| 183 | + { |
|
| 184 | + $template_dir = DOL_DOCUMENT_ROOT."/core/tpl/"; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - // Set cookie for timeout management |
|
| 188 | - $prefix=dol_getprefix(''); |
|
| 189 | - $sessiontimeout='DOLSESSTIMEOUT_'.$prefix; |
|
| 190 | - if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", null, false, true); |
|
| 187 | + // Set cookie for timeout management |
|
| 188 | + $prefix=dol_getprefix(''); |
|
| 189 | + $sessiontimeout='DOLSESSTIMEOUT_'.$prefix; |
|
| 190 | + if (! empty($conf->global->MAIN_SESSION_TIMEOUT)) setcookie($sessiontimeout, $conf->global->MAIN_SESSION_TIMEOUT, 0, "/", null, false, true); |
|
| 191 | 191 | |
| 192 | - if (GETPOST('urlfrom','alpha')) $_SESSION["urlfrom"]=GETPOST('urlfrom','alpha'); |
|
| 193 | - else unset($_SESSION["urlfrom"]); |
|
| 192 | + if (GETPOST('urlfrom','alpha')) $_SESSION["urlfrom"]=GETPOST('urlfrom','alpha'); |
|
| 193 | + else unset($_SESSION["urlfrom"]); |
|
| 194 | 194 | |
| 195 | - if (! GETPOST("username",'alpha')) $focus_element='username'; |
|
| 196 | - else $focus_element='password'; |
|
| 195 | + if (! GETPOST("username",'alpha')) $focus_element='username'; |
|
| 196 | + else $focus_element='password'; |
|
| 197 | 197 | |
| 198 | - $demologin=''; |
|
| 199 | - $demopassword=''; |
|
| 200 | - if (! empty($dolibarr_main_demo)) |
|
| 201 | - { |
|
| 202 | - $tab=explode(',',$dolibarr_main_demo); |
|
| 203 | - $demologin=$tab[0]; |
|
| 204 | - $demopassword=$tab[1]; |
|
| 205 | - } |
|
| 198 | + $demologin=''; |
|
| 199 | + $demopassword=''; |
|
| 200 | + if (! empty($dolibarr_main_demo)) |
|
| 201 | + { |
|
| 202 | + $tab=explode(',',$dolibarr_main_demo); |
|
| 203 | + $demologin=$tab[0]; |
|
| 204 | + $demopassword=$tab[1]; |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - // Execute hook getLoginPageOptions (for table) |
|
| 208 | - $parameters=array('entity' => GETPOST('entity','int')); |
|
| 209 | - $reshook = $hookmanager->executeHooks('getLoginPageOptions',$parameters); // Note that $action and $object may have been modified by some hooks. |
|
| 210 | - if (is_array($hookmanager->resArray) && ! empty($hookmanager->resArray)) { |
|
| 211 | - $morelogincontent = $hookmanager->resArray; // (deprecated) For compatibility |
|
| 212 | - } else { |
|
| 213 | - $morelogincontent = $hookmanager->resPrint; |
|
| 214 | - } |
|
| 207 | + // Execute hook getLoginPageOptions (for table) |
|
| 208 | + $parameters=array('entity' => GETPOST('entity','int')); |
|
| 209 | + $reshook = $hookmanager->executeHooks('getLoginPageOptions',$parameters); // Note that $action and $object may have been modified by some hooks. |
|
| 210 | + if (is_array($hookmanager->resArray) && ! empty($hookmanager->resArray)) { |
|
| 211 | + $morelogincontent = $hookmanager->resArray; // (deprecated) For compatibility |
|
| 212 | + } else { |
|
| 213 | + $morelogincontent = $hookmanager->resPrint; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - // Execute hook getLoginPageExtraOptions (eg for js) |
|
| 217 | - $parameters=array('entity' => GETPOST('entity','int')); |
|
| 218 | - $reshook = $hookmanager->executeHooks('getLoginPageExtraOptions',$parameters); // Note that $action and $object may have been modified by some hooks. |
|
| 219 | - $moreloginextracontent = $hookmanager->resPrint; |
|
| 216 | + // Execute hook getLoginPageExtraOptions (eg for js) |
|
| 217 | + $parameters=array('entity' => GETPOST('entity','int')); |
|
| 218 | + $reshook = $hookmanager->executeHooks('getLoginPageExtraOptions',$parameters); // Note that $action and $object may have been modified by some hooks. |
|
| 219 | + $moreloginextracontent = $hookmanager->resPrint; |
|
| 220 | 220 | |
| 221 | - // Login |
|
| 222 | - $login = (! empty($hookmanager->resArray['username']) ? $hookmanager->resArray['username'] : (GETPOST("username","alpha") ? GETPOST("username","alpha") : $demologin)); |
|
| 223 | - $password = $demopassword; |
|
| 221 | + // Login |
|
| 222 | + $login = (! empty($hookmanager->resArray['username']) ? $hookmanager->resArray['username'] : (GETPOST("username","alpha") ? GETPOST("username","alpha") : $demologin)); |
|
| 223 | + $password = $demopassword; |
|
| 224 | 224 | |
| 225 | - // Show logo (search in order: small company logo, large company logo, theme logo, common logo) |
|
| 226 | - $width=0; |
|
| 227 | - $urllogo = DOL_BASE_URI . '/theme/login_logo.png'; |
|
| 225 | + // Show logo (search in order: small company logo, large company logo, theme logo, common logo) |
|
| 226 | + $width=0; |
|
| 227 | + $urllogo = DOL_BASE_URI . '/theme/login_logo.png'; |
|
| 228 | 228 | |
| 229 | 229 | if (! empty($mysoc->logo_small) && is_readable($conf->mycompany->dir_output.'/logos/thumbs/'.$mysoc->logo_small)) |
| 230 | - { |
|
| 231 | - $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_small); |
|
| 232 | - } |
|
| 233 | - elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) |
|
| 234 | - { |
|
| 235 | - $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/'.$mysoc->logo); |
|
| 236 | - $width=128; |
|
| 237 | - } |
|
| 238 | - elseif (is_readable(DOL_BASE_URI . '/theme/' . $conf->theme . '/img/dolibarr_logo.png')) { |
|
| 239 | - $urllogo = DOL_BASE_URI . '/theme/' . $conf->theme . '/img/dolibarr_logo.png'; |
|
| 230 | + { |
|
| 231 | + $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/thumbs/'.$mysoc->logo_small); |
|
| 240 | 232 | } |
| 241 | - elseif (is_readable(DOL_BASE_URI . '/theme/dolibarr_logo.png')) { |
|
| 242 | - $urllogo = DOL_BASE_URI . '/theme/dolibarr_logo.png'; |
|
| 233 | + elseif (! empty($mysoc->logo) && is_readable($conf->mycompany->dir_output.'/logos/'.$mysoc->logo)) |
|
| 234 | + { |
|
| 235 | + $urllogo=DOL_URL_ROOT.'/viewimage.php?cache=1&modulepart=mycompany&file='.urlencode('logos/'.$mysoc->logo); |
|
| 236 | + $width=128; |
|
| 237 | + } |
|
| 238 | + elseif (is_readable(DOL_BASE_URI . '/theme/' . $conf->theme . '/img/dolibarr_logo.png')) { |
|
| 239 | + $urllogo = DOL_BASE_URI . '/theme/' . $conf->theme . '/img/dolibarr_logo.png'; |
|
| 240 | + } |
|
| 241 | + elseif (is_readable(DOL_BASE_URI . '/theme/dolibarr_logo.png')) { |
|
| 242 | + $urllogo = DOL_BASE_URI . '/theme/dolibarr_logo.png'; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | - // Security graphical code |
|
| 246 | - $captcha=0; |
|
| 247 | - $captcha_refresh=''; |
|
| 248 | - if (function_exists("imagecreatefrompng") && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) |
|
| 249 | - { |
|
| 250 | - $captcha=1; |
|
| 251 | - $captcha_refresh=img_picto($langs->trans("Refresh"),'refresh','id="captcha_refresh_img"'); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // Extra link |
|
| 255 | - $forgetpasslink=0; |
|
| 256 | - $helpcenterlink=0; |
|
| 257 | - if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) |
|
| 258 | - { |
|
| 259 | - if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) |
|
| 260 | - { |
|
| 261 | - $forgetpasslink=1; |
|
| 262 | - } |
|
| 245 | + // Security graphical code |
|
| 246 | + $captcha=0; |
|
| 247 | + $captcha_refresh=''; |
|
| 248 | + if (function_exists("imagecreatefrompng") && ! empty($conf->global->MAIN_SECURITY_ENABLECAPTCHA)) |
|
| 249 | + { |
|
| 250 | + $captcha=1; |
|
| 251 | + $captcha_refresh=img_picto($langs->trans("Refresh"),'refresh','id="captcha_refresh_img"'); |
|
| 252 | + } |
|
| 263 | 253 | |
| 264 | - if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) |
|
| 265 | - { |
|
| 266 | - $helpcenterlink=1; |
|
| 267 | - } |
|
| 268 | - } |
|
| 254 | + // Extra link |
|
| 255 | + $forgetpasslink=0; |
|
| 256 | + $helpcenterlink=0; |
|
| 257 | + if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK) || empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) |
|
| 258 | + { |
|
| 259 | + if (empty($conf->global->MAIN_SECURITY_DISABLEFORGETPASSLINK)) |
|
| 260 | + { |
|
| 261 | + $forgetpasslink=1; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + if (empty($conf->global->MAIN_HELPCENTER_DISABLELINK)) |
|
| 265 | + { |
|
| 266 | + $helpcenterlink=1; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - // Home message |
|
| 271 | - $main_home=''; |
|
| 272 | - if (! empty($conf->global->MAIN_HOME)) |
|
| 273 | - { |
|
| 274 | - $substitutionarray=getCommonSubstitutionArray($langs); |
|
| 275 | - complete_substitutions_array($substitutionarray, $langs); |
|
| 276 | - $texttoshow = make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs); |
|
| 270 | + // Home message |
|
| 271 | + $main_home=''; |
|
| 272 | + if (! empty($conf->global->MAIN_HOME)) |
|
| 273 | + { |
|
| 274 | + $substitutionarray=getCommonSubstitutionArray($langs); |
|
| 275 | + complete_substitutions_array($substitutionarray, $langs); |
|
| 276 | + $texttoshow = make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs); |
|
| 277 | 277 | |
| 278 | - $main_home=dol_htmlcleanlastbr($texttoshow); |
|
| 279 | - } |
|
| 278 | + $main_home=dol_htmlcleanlastbr($texttoshow); |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - // Google AD |
|
| 282 | - $main_google_ad_client = ((! empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && ! empty($conf->global->MAIN_GOOGLE_AD_SLOT))?1:0); |
|
| 281 | + // Google AD |
|
| 282 | + $main_google_ad_client = ((! empty($conf->global->MAIN_GOOGLE_AD_CLIENT) && ! empty($conf->global->MAIN_GOOGLE_AD_SLOT))?1:0); |
|
| 283 | 283 | |
| 284 | - // Set jquery theme |
|
| 285 | - $dol_loginmesg = (! empty($_SESSION["dol_loginmesg"])?$_SESSION["dol_loginmesg"]:''); |
|
| 286 | - $favicon=dol_buildpath('/theme/'.$conf->theme.'/img/favicon.ico',1); |
|
| 287 | - if (! empty($conf->global->MAIN_FAVICON_URL)) $favicon=$conf->global->MAIN_FAVICON_URL; |
|
| 288 | - $jquerytheme = 'base'; |
|
| 289 | - if (! empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME; |
|
| 284 | + // Set jquery theme |
|
| 285 | + $dol_loginmesg = (! empty($_SESSION["dol_loginmesg"])?$_SESSION["dol_loginmesg"]:''); |
|
| 286 | + $favicon=dol_buildpath('/theme/'.$conf->theme.'/img/favicon.ico',1); |
|
| 287 | + if (! empty($conf->global->MAIN_FAVICON_URL)) $favicon=$conf->global->MAIN_FAVICON_URL; |
|
| 288 | + $jquerytheme = 'base'; |
|
| 289 | + if (! empty($conf->global->MAIN_USE_JQUERY_THEME)) $jquerytheme = $conf->global->MAIN_USE_JQUERY_THEME; |
|
| 290 | 290 | |
| 291 | - // Set dol_hide_topmenu, dol_hide_leftmenu, dol_optimize_smallscreen, dol_no_mouse_hover |
|
| 292 | - $dol_hide_topmenu=GETPOST('dol_hide_topmenu','int'); |
|
| 293 | - $dol_hide_leftmenu=GETPOST('dol_hide_leftmenu','int'); |
|
| 294 | - $dol_optimize_smallscreen=GETPOST('dol_optimize_smallscreen','int'); |
|
| 295 | - $dol_no_mouse_hover=GETPOST('dol_no_mouse_hover','int'); |
|
| 296 | - $dol_use_jmobile=GETPOST('dol_use_jmobile','int'); |
|
| 291 | + // Set dol_hide_topmenu, dol_hide_leftmenu, dol_optimize_smallscreen, dol_no_mouse_hover |
|
| 292 | + $dol_hide_topmenu=GETPOST('dol_hide_topmenu','int'); |
|
| 293 | + $dol_hide_leftmenu=GETPOST('dol_hide_leftmenu','int'); |
|
| 294 | + $dol_optimize_smallscreen=GETPOST('dol_optimize_smallscreen','int'); |
|
| 295 | + $dol_no_mouse_hover=GETPOST('dol_no_mouse_hover','int'); |
|
| 296 | + $dol_use_jmobile=GETPOST('dol_use_jmobile','int'); |
|
| 297 | 297 | |
| 298 | - // Include login page template |
|
| 299 | - include $template_dir.'login.tpl.php'; |
|
| 298 | + // Include login page template |
|
| 299 | + include $template_dir.'login.tpl.php'; |
|
| 300 | 300 | |
| 301 | 301 | |
| 302 | - $_SESSION["dol_loginmesg"] = ''; |
|
| 303 | - } |
|
| 302 | + $_SESSION["dol_loginmesg"] = ''; |
|
| 303 | + } |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -313,23 +313,23 @@ discard block |
||
| 313 | 313 | */ |
| 314 | 314 | function makesalt($type=CRYPT_SALT_LENGTH) |
| 315 | 315 | { |
| 316 | - dol_syslog("makesalt type=".$type); |
|
| 317 | - switch($type) |
|
| 318 | - { |
|
| 319 | - case 12: // 8 + 4 |
|
| 320 | - $saltlen=8; $saltprefix='$1$'; $saltsuffix='$'; break; |
|
| 321 | - case 8: // 8 (Pour compatibilite, ne devrait pas etre utilise) |
|
| 322 | - $saltlen=8; $saltprefix='$1$'; $saltsuffix='$'; break; |
|
| 323 | - case 2: // 2 |
|
| 324 | - default: // by default, fall back on Standard DES (should work everywhere) |
|
| 325 | - $saltlen=2; $saltprefix=''; $saltsuffix=''; break; |
|
| 326 | - } |
|
| 327 | - $salt=''; |
|
| 328 | - while(dol_strlen($salt) < $saltlen) $salt.=chr(mt_rand(64,126)); |
|
| 329 | - |
|
| 330 | - $result=$saltprefix.$salt.$saltsuffix; |
|
| 331 | - dol_syslog("makesalt return=".$result); |
|
| 332 | - return $result; |
|
| 316 | + dol_syslog("makesalt type=".$type); |
|
| 317 | + switch($type) |
|
| 318 | + { |
|
| 319 | + case 12: // 8 + 4 |
|
| 320 | + $saltlen=8; $saltprefix='$1$'; $saltsuffix='$'; break; |
|
| 321 | + case 8: // 8 (Pour compatibilite, ne devrait pas etre utilise) |
|
| 322 | + $saltlen=8; $saltprefix='$1$'; $saltsuffix='$'; break; |
|
| 323 | + case 2: // 2 |
|
| 324 | + default: // by default, fall back on Standard DES (should work everywhere) |
|
| 325 | + $saltlen=2; $saltprefix=''; $saltsuffix=''; break; |
|
| 326 | + } |
|
| 327 | + $salt=''; |
|
| 328 | + while(dol_strlen($salt) < $saltlen) $salt.=chr(mt_rand(64,126)); |
|
| 329 | + |
|
| 330 | + $result=$saltprefix.$salt.$saltsuffix; |
|
| 331 | + dol_syslog("makesalt return=".$result); |
|
| 332 | + return $result; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -340,102 +340,102 @@ discard block |
||
| 340 | 340 | */ |
| 341 | 341 | function encodedecode_dbpassconf($level=0) |
| 342 | 342 | { |
| 343 | - dol_syslog("encodedecode_dbpassconf level=".$level, LOG_DEBUG); |
|
| 344 | - $config = ''; |
|
| 345 | - $passwd=''; |
|
| 346 | - $passwd_crypted=''; |
|
| 347 | - |
|
| 348 | - if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) |
|
| 349 | - { |
|
| 350 | - while(!feof($fp)) |
|
| 351 | - { |
|
| 352 | - $buffer = fgets($fp,4096); |
|
| 353 | - |
|
| 354 | - $lineofpass=0; |
|
| 355 | - |
|
| 356 | - if (preg_match('/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i',$buffer,$reg)) // Old way to save crypted value |
|
| 357 | - { |
|
| 358 | - $val = trim($reg[1]); // This also remove CR/LF |
|
| 359 | - $val=preg_replace('/^["\']/','',$val); |
|
| 360 | - $val=preg_replace('/["\'][\s;]*$/','',$val); |
|
| 361 | - if (! empty($val)) |
|
| 362 | - { |
|
| 363 | - $passwd_crypted = $val; |
|
| 364 | - $val = dol_decode($val); |
|
| 365 | - $passwd = $val; |
|
| 366 | - $lineofpass=1; |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - elseif (preg_match('/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i',$buffer,$reg)) |
|
| 370 | - { |
|
| 371 | - $val = trim($reg[1]); // This also remove CR/LF |
|
| 372 | - $val=preg_replace('/^["\']/','',$val); |
|
| 373 | - $val=preg_replace('/["\'][\s;]*$/','',$val); |
|
| 374 | - if (preg_match('/crypted:/i',$buffer)) |
|
| 375 | - { |
|
| 376 | - $val = preg_replace('/crypted:/i','',$val); |
|
| 377 | - $passwd_crypted = $val; |
|
| 378 | - $val = dol_decode($val); |
|
| 379 | - $passwd = $val; |
|
| 380 | - } |
|
| 381 | - else |
|
| 382 | - { |
|
| 383 | - $passwd = $val; |
|
| 384 | - $val = dol_encode($val); |
|
| 385 | - $passwd_crypted = $val; |
|
| 386 | - } |
|
| 387 | - $lineofpass=1; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - // Output line |
|
| 391 | - if ($lineofpass) |
|
| 392 | - { |
|
| 393 | - // Add value at end of file |
|
| 394 | - if ($level == 0) |
|
| 395 | - { |
|
| 396 | - $config .= '$dolibarr_main_db_pass=\''.$passwd.'\';'."\n"; |
|
| 397 | - } |
|
| 398 | - if ($level == 1) |
|
| 399 | - { |
|
| 400 | - $config .= '$dolibarr_main_db_pass=\'crypted:'.$passwd_crypted.'\';'."\n"; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - //print 'passwd = '.$passwd.' - passwd_crypted = '.$passwd_crypted; |
|
| 404 | - //exit; |
|
| 405 | - } |
|
| 406 | - else |
|
| 407 | - { |
|
| 408 | - $config .= $buffer; |
|
| 409 | - } |
|
| 410 | - } |
|
| 411 | - fclose($fp); |
|
| 412 | - |
|
| 413 | - // Write new conf file |
|
| 414 | - $file=DOL_DOCUMENT_ROOT.'/conf/conf.php'; |
|
| 415 | - if ($fp = @fopen($file,'w')) |
|
| 416 | - { |
|
| 417 | - fputs($fp, $config); |
|
| 418 | - fflush($fp); |
|
| 419 | - fclose($fp); |
|
| 420 | - clearstatcache(); |
|
| 421 | - |
|
| 422 | - // It's config file, so we set read permission for creator only. |
|
| 423 | - // Should set permission to web user and groups for users used by batch |
|
| 424 | - //@chmod($file, octdec('0600')); |
|
| 425 | - |
|
| 426 | - return 1; |
|
| 427 | - } |
|
| 428 | - else |
|
| 429 | - { |
|
| 430 | - dol_syslog("encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING); |
|
| 431 | - return -1; |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - else |
|
| 435 | - { |
|
| 436 | - dol_syslog("encodedecode_dbpassconf Failed to read conf.php", LOG_ERR); |
|
| 437 | - return -2; |
|
| 438 | - } |
|
| 343 | + dol_syslog("encodedecode_dbpassconf level=".$level, LOG_DEBUG); |
|
| 344 | + $config = ''; |
|
| 345 | + $passwd=''; |
|
| 346 | + $passwd_crypted=''; |
|
| 347 | + |
|
| 348 | + if ($fp = fopen(DOL_DOCUMENT_ROOT.'/conf/conf.php','r')) |
|
| 349 | + { |
|
| 350 | + while(!feof($fp)) |
|
| 351 | + { |
|
| 352 | + $buffer = fgets($fp,4096); |
|
| 353 | + |
|
| 354 | + $lineofpass=0; |
|
| 355 | + |
|
| 356 | + if (preg_match('/^[^#]*dolibarr_main_db_encrypted_pass[\s]*=[\s]*(.*)/i',$buffer,$reg)) // Old way to save crypted value |
|
| 357 | + { |
|
| 358 | + $val = trim($reg[1]); // This also remove CR/LF |
|
| 359 | + $val=preg_replace('/^["\']/','',$val); |
|
| 360 | + $val=preg_replace('/["\'][\s;]*$/','',$val); |
|
| 361 | + if (! empty($val)) |
|
| 362 | + { |
|
| 363 | + $passwd_crypted = $val; |
|
| 364 | + $val = dol_decode($val); |
|
| 365 | + $passwd = $val; |
|
| 366 | + $lineofpass=1; |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + elseif (preg_match('/^[^#]*dolibarr_main_db_pass[\s]*=[\s]*(.*)/i',$buffer,$reg)) |
|
| 370 | + { |
|
| 371 | + $val = trim($reg[1]); // This also remove CR/LF |
|
| 372 | + $val=preg_replace('/^["\']/','',$val); |
|
| 373 | + $val=preg_replace('/["\'][\s;]*$/','',$val); |
|
| 374 | + if (preg_match('/crypted:/i',$buffer)) |
|
| 375 | + { |
|
| 376 | + $val = preg_replace('/crypted:/i','',$val); |
|
| 377 | + $passwd_crypted = $val; |
|
| 378 | + $val = dol_decode($val); |
|
| 379 | + $passwd = $val; |
|
| 380 | + } |
|
| 381 | + else |
|
| 382 | + { |
|
| 383 | + $passwd = $val; |
|
| 384 | + $val = dol_encode($val); |
|
| 385 | + $passwd_crypted = $val; |
|
| 386 | + } |
|
| 387 | + $lineofpass=1; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + // Output line |
|
| 391 | + if ($lineofpass) |
|
| 392 | + { |
|
| 393 | + // Add value at end of file |
|
| 394 | + if ($level == 0) |
|
| 395 | + { |
|
| 396 | + $config .= '$dolibarr_main_db_pass=\''.$passwd.'\';'."\n"; |
|
| 397 | + } |
|
| 398 | + if ($level == 1) |
|
| 399 | + { |
|
| 400 | + $config .= '$dolibarr_main_db_pass=\'crypted:'.$passwd_crypted.'\';'."\n"; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + //print 'passwd = '.$passwd.' - passwd_crypted = '.$passwd_crypted; |
|
| 404 | + //exit; |
|
| 405 | + } |
|
| 406 | + else |
|
| 407 | + { |
|
| 408 | + $config .= $buffer; |
|
| 409 | + } |
|
| 410 | + } |
|
| 411 | + fclose($fp); |
|
| 412 | + |
|
| 413 | + // Write new conf file |
|
| 414 | + $file=DOL_DOCUMENT_ROOT.'/conf/conf.php'; |
|
| 415 | + if ($fp = @fopen($file,'w')) |
|
| 416 | + { |
|
| 417 | + fputs($fp, $config); |
|
| 418 | + fflush($fp); |
|
| 419 | + fclose($fp); |
|
| 420 | + clearstatcache(); |
|
| 421 | + |
|
| 422 | + // It's config file, so we set read permission for creator only. |
|
| 423 | + // Should set permission to web user and groups for users used by batch |
|
| 424 | + //@chmod($file, octdec('0600')); |
|
| 425 | + |
|
| 426 | + return 1; |
|
| 427 | + } |
|
| 428 | + else |
|
| 429 | + { |
|
| 430 | + dol_syslog("encodedecode_dbpassconf Failed to open conf.php file for writing", LOG_WARNING); |
|
| 431 | + return -1; |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + else |
|
| 435 | + { |
|
| 436 | + dol_syslog("encodedecode_dbpassconf Failed to read conf.php", LOG_ERR); |
|
| 437 | + return -2; |
|
| 438 | + } |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | /** |
@@ -448,72 +448,72 @@ discard block |
||
| 448 | 448 | */ |
| 449 | 449 | function getRandomPassword($generic=false, $replaceambiguouschars=null) |
| 450 | 450 | { |
| 451 | - global $db,$conf,$langs,$user; |
|
| 452 | - |
|
| 453 | - $generated_password=''; |
|
| 454 | - if ($generic) |
|
| 455 | - { |
|
| 456 | - $length = 32; |
|
| 457 | - $lowercase = "qwertyuiopasdfghjklzxcvbnm"; |
|
| 458 | - $uppercase = "ASDFGHJKLZXCVBNMQWERTYUIOP"; |
|
| 459 | - $numbers = "1234567890"; |
|
| 460 | - $randomCode = ""; |
|
| 461 | - $nbofchar = round($length/3); |
|
| 462 | - $nbofcharlast = ($length - 2*$nbofchar); |
|
| 463 | - //var_dump($nbofchar.'-'.$nbofcharlast); |
|
| 464 | - if (function_exists('random_int')) // Cryptographic random |
|
| 465 | - { |
|
| 466 | - $max = strlen($lowercase) - 1; |
|
| 467 | - for ($x = 0; $x < $nbofchar; $x++) { |
|
| 468 | - $randomCode .= $lowercase{random_int(0, $max)}; |
|
| 469 | - } |
|
| 470 | - $max = strlen($uppercase) - 1; |
|
| 471 | - for ($x = 0; $x < $nbofchar; $x++) { |
|
| 472 | - $randomCode .= $uppercase{random_int(0, $max)}; |
|
| 473 | - } |
|
| 474 | - $max = strlen($numbers) - 1; |
|
| 475 | - for ($x = 0; $x < $nbofcharlast; $x++) { |
|
| 476 | - $randomCode .= $numbers{random_int(0, $max)}; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - $generated_password=str_shuffle($randomCode); |
|
| 480 | - } |
|
| 481 | - else // Old platform, non cryptographic random |
|
| 482 | - { |
|
| 483 | - $max = strlen($lowercase) - 1; |
|
| 484 | - for ($x = 0; $x < $nbofchar; $x++) { |
|
| 485 | - $randomCode .= $lowercase{mt_rand(0, $max)}; |
|
| 486 | - } |
|
| 487 | - $max = strlen($uppercase) - 1; |
|
| 488 | - for ($x = 0; $x < $nbofchar; $x++) { |
|
| 489 | - $randomCode .= $uppercase{mt_rand(0, $max)}; |
|
| 490 | - } |
|
| 491 | - $max = strlen($numbers) - 1; |
|
| 492 | - for ($x = 0; $x < $nbofcharlast; $x++) { |
|
| 493 | - $randomCode .= $numbers{mt_rand(0, $max)}; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - $generated_password=str_shuffle($randomCode); |
|
| 497 | - } |
|
| 498 | - } |
|
| 499 | - else if (! empty($conf->global->USER_PASSWORD_GENERATED)) |
|
| 500 | - { |
|
| 501 | - $nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED); |
|
| 502 | - $nomfichier=$nomclass.".class.php"; |
|
| 503 | - //print DOL_DOCUMENT_ROOT."/core/modules/security/generate/".$nomclass; |
|
| 504 | - require_once DOL_DOCUMENT_ROOT."/core/modules/security/generate/".$nomfichier; |
|
| 505 | - $genhandler=new $nomclass($db,$conf,$langs,$user); |
|
| 506 | - $generated_password=$genhandler->getNewGeneratedPassword(); |
|
| 507 | - unset($genhandler); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // Do we have to discard some alphabetic characters ? |
|
| 511 | - if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) |
|
| 512 | - { |
|
| 513 | - $numbers = "ABCDEF"; |
|
| 514 | - $max = strlen($numbers) - 1; |
|
| 515 | - $generated_password=str_replace($replaceambiguouschars, $numbers{random_int(0, $max)}, $generated_password); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - return $generated_password; |
|
| 451 | + global $db,$conf,$langs,$user; |
|
| 452 | + |
|
| 453 | + $generated_password=''; |
|
| 454 | + if ($generic) |
|
| 455 | + { |
|
| 456 | + $length = 32; |
|
| 457 | + $lowercase = "qwertyuiopasdfghjklzxcvbnm"; |
|
| 458 | + $uppercase = "ASDFGHJKLZXCVBNMQWERTYUIOP"; |
|
| 459 | + $numbers = "1234567890"; |
|
| 460 | + $randomCode = ""; |
|
| 461 | + $nbofchar = round($length/3); |
|
| 462 | + $nbofcharlast = ($length - 2*$nbofchar); |
|
| 463 | + //var_dump($nbofchar.'-'.$nbofcharlast); |
|
| 464 | + if (function_exists('random_int')) // Cryptographic random |
|
| 465 | + { |
|
| 466 | + $max = strlen($lowercase) - 1; |
|
| 467 | + for ($x = 0; $x < $nbofchar; $x++) { |
|
| 468 | + $randomCode .= $lowercase{random_int(0, $max)}; |
|
| 469 | + } |
|
| 470 | + $max = strlen($uppercase) - 1; |
|
| 471 | + for ($x = 0; $x < $nbofchar; $x++) { |
|
| 472 | + $randomCode .= $uppercase{random_int(0, $max)}; |
|
| 473 | + } |
|
| 474 | + $max = strlen($numbers) - 1; |
|
| 475 | + for ($x = 0; $x < $nbofcharlast; $x++) { |
|
| 476 | + $randomCode .= $numbers{random_int(0, $max)}; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + $generated_password=str_shuffle($randomCode); |
|
| 480 | + } |
|
| 481 | + else // Old platform, non cryptographic random |
|
| 482 | + { |
|
| 483 | + $max = strlen($lowercase) - 1; |
|
| 484 | + for ($x = 0; $x < $nbofchar; $x++) { |
|
| 485 | + $randomCode .= $lowercase{mt_rand(0, $max)}; |
|
| 486 | + } |
|
| 487 | + $max = strlen($uppercase) - 1; |
|
| 488 | + for ($x = 0; $x < $nbofchar; $x++) { |
|
| 489 | + $randomCode .= $uppercase{mt_rand(0, $max)}; |
|
| 490 | + } |
|
| 491 | + $max = strlen($numbers) - 1; |
|
| 492 | + for ($x = 0; $x < $nbofcharlast; $x++) { |
|
| 493 | + $randomCode .= $numbers{mt_rand(0, $max)}; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + $generated_password=str_shuffle($randomCode); |
|
| 497 | + } |
|
| 498 | + } |
|
| 499 | + else if (! empty($conf->global->USER_PASSWORD_GENERATED)) |
|
| 500 | + { |
|
| 501 | + $nomclass="modGeneratePass".ucfirst($conf->global->USER_PASSWORD_GENERATED); |
|
| 502 | + $nomfichier=$nomclass.".class.php"; |
|
| 503 | + //print DOL_DOCUMENT_ROOT."/core/modules/security/generate/".$nomclass; |
|
| 504 | + require_once DOL_DOCUMENT_ROOT."/core/modules/security/generate/".$nomfichier; |
|
| 505 | + $genhandler=new $nomclass($db,$conf,$langs,$user); |
|
| 506 | + $generated_password=$genhandler->getNewGeneratedPassword(); |
|
| 507 | + unset($genhandler); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // Do we have to discard some alphabetic characters ? |
|
| 511 | + if (is_array($replaceambiguouschars) && count($replaceambiguouschars) > 0) |
|
| 512 | + { |
|
| 513 | + $numbers = "ABCDEF"; |
|
| 514 | + $max = strlen($numbers) - 1; |
|
| 515 | + $generated_password=str_replace($replaceambiguouschars, $numbers{random_int(0, $max)}, $generated_password); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + return $generated_password; |
|
| 519 | 519 | } |
@@ -70,25 +70,25 @@ discard block |
||
| 70 | 70 | $result = $db->query($sql); |
| 71 | 71 | if ($result) |
| 72 | 72 | {
|
| 73 | - $num = $db->num_rows($result); |
|
| 74 | - $i = 0; |
|
| 75 | - while ($i < $num) |
|
| 76 | - {
|
|
| 77 | - $objp = $db->fetch_object($result); |
|
| 78 | - |
|
| 79 | - $adhtype=new AdherentType($db); |
|
| 80 | - $adhtype->id=$objp->rowid; |
|
| 81 | - $adhtype->subscription=$objp->subscription; |
|
| 82 | - $adhtype->label=$objp->label; |
|
| 83 | - $AdherentType[$objp->rowid]=$adhtype; |
|
| 84 | - |
|
| 85 | - if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
|
|
| 86 | - if ($objp->statut == 1) { $MembersValidated[$objp->rowid]=$objp->somme; }
|
|
| 87 | - if ($objp->statut == 0) { $MembersResiliated[$objp->rowid]=$objp->somme; }
|
|
| 88 | - |
|
| 89 | - $i++; |
|
| 90 | - } |
|
| 91 | - $db->free($result); |
|
| 73 | + $num = $db->num_rows($result); |
|
| 74 | + $i = 0; |
|
| 75 | + while ($i < $num) |
|
| 76 | + {
|
|
| 77 | + $objp = $db->fetch_object($result); |
|
| 78 | + |
|
| 79 | + $adhtype=new AdherentType($db); |
|
| 80 | + $adhtype->id=$objp->rowid; |
|
| 81 | + $adhtype->subscription=$objp->subscription; |
|
| 82 | + $adhtype->label=$objp->label; |
|
| 83 | + $AdherentType[$objp->rowid]=$adhtype; |
|
| 84 | + |
|
| 85 | + if ($objp->statut == -1) { $MemberToValidate[$objp->rowid]=$objp->somme; }
|
|
| 86 | + if ($objp->statut == 1) { $MembersValidated[$objp->rowid]=$objp->somme; }
|
|
| 87 | + if ($objp->statut == 0) { $MembersResiliated[$objp->rowid]=$objp->somme; }
|
|
| 88 | + |
|
| 89 | + $i++; |
|
| 90 | + } |
|
| 91 | + $db->free($result); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $now=dol_now(); |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | $result = $db->query($sql); |
| 109 | 109 | if ($result) |
| 110 | 110 | {
|
| 111 | - $num = $db->num_rows($result); |
|
| 112 | - $i = 0; |
|
| 113 | - while ($i < $num) |
|
| 114 | - {
|
|
| 115 | - $objp = $db->fetch_object($result); |
|
| 116 | - $MemberUpToDate[$objp->fk_adherent_type]=$objp->somme; |
|
| 117 | - $i++; |
|
| 118 | - } |
|
| 119 | - $db->free(); |
|
| 111 | + $num = $db->num_rows($result); |
|
| 112 | + $i = 0; |
|
| 113 | + while ($i < $num) |
|
| 114 | + {
|
|
| 115 | + $objp = $db->fetch_object($result); |
|
| 116 | + $MemberUpToDate[$objp->fk_adherent_type]=$objp->somme; |
|
| 117 | + $i++; |
|
| 118 | + } |
|
| 119 | + $db->free(); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | |
@@ -129,27 +129,27 @@ discard block |
||
| 129 | 129 | // Search contact/address |
| 130 | 130 | if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire) |
| 131 | 131 | {
|
| 132 | - $listofsearchfields['search_member']=array('text'=>'Member');
|
|
| 132 | + $listofsearchfields['search_member']=array('text'=>'Member');
|
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if (count($listofsearchfields)) |
| 136 | 136 | {
|
| 137 | - print '<form method="post" action="'.BASE_URI.'?controller=core&method=search">'; |
|
| 138 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 139 | - print '<table class="noborder nohover centpercent">'; |
|
| 140 | - $i=0; |
|
| 141 | - foreach($listofsearchfields as $key => $value) |
|
| 142 | - {
|
|
| 143 | - if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
|
|
| 144 | - print '<tr class="oddeven">'; |
|
| 145 | - print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label>:</td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>'; |
|
| 146 | - if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
|
|
| 147 | - print '</tr>'; |
|
| 148 | - $i++; |
|
| 149 | - } |
|
| 150 | - print '</table>'; |
|
| 151 | - print '</form>'; |
|
| 152 | - print '<br>'; |
|
| 137 | + print '<form method="post" action="'.BASE_URI.'?controller=core&method=search">'; |
|
| 138 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
| 139 | + print '<table class="noborder nohover centpercent">'; |
|
| 140 | + $i=0; |
|
| 141 | + foreach($listofsearchfields as $key => $value) |
|
| 142 | + {
|
|
| 143 | + if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
|
|
| 144 | + print '<tr class="oddeven">'; |
|
| 145 | + print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label>:</td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>'; |
|
| 146 | + if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
|
|
| 147 | + print '</tr>'; |
|
| 148 | + $i++; |
|
| 149 | + } |
|
| 150 | + print '</table>'; |
|
| 151 | + print '</form>'; |
|
| 152 | + print '<br>'; |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | if ($conf->use_javascript_ajax) |
| 162 | 162 | {
|
| 163 | - print '<div class="div-table-responsive-no-min">'; |
|
| 164 | - print '<table class="noborder nohover" width="100%">'; |
|
| 163 | + print '<div class="div-table-responsive-no-min">'; |
|
| 164 | + print '<table class="noborder nohover" width="100%">'; |
|
| 165 | 165 | print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
|
| 166 | 166 | print '<tr><td align="center" colspan="2">'; |
| 167 | 167 | |
@@ -294,49 +294,49 @@ discard block |
||
| 294 | 294 | $resql=$db->query($sql); |
| 295 | 295 | if ($resql) |
| 296 | 296 | {
|
| 297 | - print '<div class="div-table-responsive-no-min">'; |
|
| 298 | - print '<table class="noborder" width="100%">'; |
|
| 299 | - print '<tr class="liste_titre">'; |
|
| 300 | - print '<th colspan="4">'.$langs->trans("LastMembersModified",$max).'</th></tr>';
|
|
| 301 | - |
|
| 302 | - $num = $db->num_rows($resql); |
|
| 303 | - if ($num) |
|
| 304 | - {
|
|
| 305 | - $i = 0; |
|
| 306 | - while ($i < $num) |
|
| 307 | - {
|
|
| 308 | - $obj = $db->fetch_object($resql); |
|
| 309 | - print '<tr class="oddeven">'; |
|
| 310 | - $staticmember->id=$obj->rowid; |
|
| 311 | - $staticmember->lastname=$obj->lastname; |
|
| 312 | - $staticmember->firstname=$obj->firstname; |
|
| 313 | - if (! empty($obj->fk_soc)) |
|
| 314 | - {
|
|
| 315 | - $staticmember->fk_soc = $obj->fk_soc; |
|
| 316 | - $staticmember->fetch_thirdparty(); |
|
| 317 | - $staticmember->name=$staticmember->thirdparty->name; |
|
| 318 | - } |
|
| 319 | - else |
|
| 320 | - {
|
|
| 321 | - $staticmember->name=$obj->company; |
|
| 322 | - } |
|
| 323 | - $staticmember->ref=$staticmember->getFullName($langs); |
|
| 324 | - $statictype->id=$obj->typeid; |
|
| 325 | - $statictype->label=$obj->label; |
|
| 326 | - print '<td>'.$staticmember->getNomUrl(1,32).'</td>'; |
|
| 327 | - print '<td>'.$statictype->getNomUrl(1,32).'</td>'; |
|
| 328 | - print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>'; |
|
| 329 | - print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>'; |
|
| 330 | - print '</tr>'; |
|
| 331 | - $i++; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - print "</table></div>"; |
|
| 335 | - print "<br>"; |
|
| 297 | + print '<div class="div-table-responsive-no-min">'; |
|
| 298 | + print '<table class="noborder" width="100%">'; |
|
| 299 | + print '<tr class="liste_titre">'; |
|
| 300 | + print '<th colspan="4">'.$langs->trans("LastMembersModified",$max).'</th></tr>';
|
|
| 301 | + |
|
| 302 | + $num = $db->num_rows($resql); |
|
| 303 | + if ($num) |
|
| 304 | + {
|
|
| 305 | + $i = 0; |
|
| 306 | + while ($i < $num) |
|
| 307 | + {
|
|
| 308 | + $obj = $db->fetch_object($resql); |
|
| 309 | + print '<tr class="oddeven">'; |
|
| 310 | + $staticmember->id=$obj->rowid; |
|
| 311 | + $staticmember->lastname=$obj->lastname; |
|
| 312 | + $staticmember->firstname=$obj->firstname; |
|
| 313 | + if (! empty($obj->fk_soc)) |
|
| 314 | + {
|
|
| 315 | + $staticmember->fk_soc = $obj->fk_soc; |
|
| 316 | + $staticmember->fetch_thirdparty(); |
|
| 317 | + $staticmember->name=$staticmember->thirdparty->name; |
|
| 318 | + } |
|
| 319 | + else |
|
| 320 | + {
|
|
| 321 | + $staticmember->name=$obj->company; |
|
| 322 | + } |
|
| 323 | + $staticmember->ref=$staticmember->getFullName($langs); |
|
| 324 | + $statictype->id=$obj->typeid; |
|
| 325 | + $statictype->label=$obj->label; |
|
| 326 | + print '<td>'.$staticmember->getNomUrl(1,32).'</td>'; |
|
| 327 | + print '<td>'.$statictype->getNomUrl(1,32).'</td>'; |
|
| 328 | + print '<td>'.dol_print_date($db->jdate($obj->datem),'dayhour').'</td>'; |
|
| 329 | + print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>'; |
|
| 330 | + print '</tr>'; |
|
| 331 | + $i++; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + print "</table></div>"; |
|
| 335 | + print "<br>"; |
|
| 336 | 336 | } |
| 337 | 337 | else |
| 338 | 338 | {
|
| 339 | - dol_print_error($db); |
|
| 339 | + dol_print_error($db); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | |
@@ -357,48 +357,48 @@ discard block |
||
| 357 | 357 | $resql=$db->query($sql); |
| 358 | 358 | if ($resql) |
| 359 | 359 | {
|
| 360 | - print '<div class="div-table-responsive-no-min">'; |
|
| 361 | - print '<table class="noborder" width="100%">'; |
|
| 362 | - print '<tr class="liste_titre">'; |
|
| 363 | - print '<th colspan="5">'.$langs->trans("LastSubscriptionsModified",$max).'</th></tr>';
|
|
| 364 | - |
|
| 365 | - $num = $db->num_rows($resql); |
|
| 366 | - if ($num) |
|
| 367 | - {
|
|
| 368 | - $i = 0; |
|
| 369 | - while ($i < $num) |
|
| 370 | - {
|
|
| 371 | - $obj = $db->fetch_object($resql); |
|
| 372 | - print '<tr class="oddeven">'; |
|
| 373 | - $subscriptionstatic->id=$obj->cid; |
|
| 374 | - $subscriptionstatic->ref=$obj->cid; |
|
| 375 | - $staticmember->id=$obj->rowid; |
|
| 376 | - $staticmember->lastname=$obj->lastname; |
|
| 377 | - $staticmember->firstname=$obj->firstname; |
|
| 378 | - if (! empty($obj->fk_soc)) {
|
|
| 379 | - $staticmember->fk_soc = $obj->fk_soc; |
|
| 380 | - $staticmember->fetch_thirdparty(); |
|
| 381 | - $staticmember->name=$staticmember->thirdparty->name; |
|
| 382 | - } else {
|
|
| 383 | - $staticmember->name=$obj->company; |
|
| 384 | - } |
|
| 385 | - $staticmember->ref=$staticmember->getFullName($langs); |
|
| 386 | - print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>'; |
|
| 387 | - print '<td>'.$staticmember->getNomUrl(1,32,'subscription').'</td>'; |
|
| 388 | - print '<td>'.get_date_range($db->jdate($obj->date_start),$db->jdate($obj->date_end)).'</td>'; |
|
| 389 | - print '<td align="right">'.price($obj->subscription).'</td>'; |
|
| 390 | - //print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>'; |
|
| 391 | - print '<td align="right">'.dol_print_date($db->jdate($obj->datem?$obj->datem:$obj->datec),'dayhour').'</td>'; |
|
| 392 | - print '</tr>'; |
|
| 393 | - $i++; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - print "</table></div>"; |
|
| 397 | - print "<br>"; |
|
| 360 | + print '<div class="div-table-responsive-no-min">'; |
|
| 361 | + print '<table class="noborder" width="100%">'; |
|
| 362 | + print '<tr class="liste_titre">'; |
|
| 363 | + print '<th colspan="5">'.$langs->trans("LastSubscriptionsModified",$max).'</th></tr>';
|
|
| 364 | + |
|
| 365 | + $num = $db->num_rows($resql); |
|
| 366 | + if ($num) |
|
| 367 | + {
|
|
| 368 | + $i = 0; |
|
| 369 | + while ($i < $num) |
|
| 370 | + {
|
|
| 371 | + $obj = $db->fetch_object($resql); |
|
| 372 | + print '<tr class="oddeven">'; |
|
| 373 | + $subscriptionstatic->id=$obj->cid; |
|
| 374 | + $subscriptionstatic->ref=$obj->cid; |
|
| 375 | + $staticmember->id=$obj->rowid; |
|
| 376 | + $staticmember->lastname=$obj->lastname; |
|
| 377 | + $staticmember->firstname=$obj->firstname; |
|
| 378 | + if (! empty($obj->fk_soc)) {
|
|
| 379 | + $staticmember->fk_soc = $obj->fk_soc; |
|
| 380 | + $staticmember->fetch_thirdparty(); |
|
| 381 | + $staticmember->name=$staticmember->thirdparty->name; |
|
| 382 | + } else {
|
|
| 383 | + $staticmember->name=$obj->company; |
|
| 384 | + } |
|
| 385 | + $staticmember->ref=$staticmember->getFullName($langs); |
|
| 386 | + print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>'; |
|
| 387 | + print '<td>'.$staticmember->getNomUrl(1,32,'subscription').'</td>'; |
|
| 388 | + print '<td>'.get_date_range($db->jdate($obj->date_start),$db->jdate($obj->date_end)).'</td>'; |
|
| 389 | + print '<td align="right">'.price($obj->subscription).'</td>'; |
|
| 390 | + //print '<td align="right">'.$staticmember->LibStatut($obj->statut,($obj->subscription=='yes'?1:0),$db->jdate($obj->date_end_subscription),5).'</td>'; |
|
| 391 | + print '<td align="right">'.dol_print_date($db->jdate($obj->datem?$obj->datem:$obj->datec),'dayhour').'</td>'; |
|
| 392 | + print '</tr>'; |
|
| 393 | + $i++; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + print "</table></div>"; |
|
| 397 | + print "<br>"; |
|
| 398 | 398 | } |
| 399 | 399 | else |
| 400 | 400 | {
|
| 401 | - dol_print_error($db); |
|
| 401 | + dol_print_error($db); |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
@@ -415,13 +415,13 @@ discard block |
||
| 415 | 415 | |
| 416 | 416 | foreach ($AdherentType as $key => $adhtype) |
| 417 | 417 | {
|
| 418 | - print '<tr class="oddeven">'; |
|
| 419 | - print '<td>'.$adhtype->getNomUrl(1, dol_size(32)).'</td>'; |
|
| 420 | - print '<td align="right">'.(isset($MemberToValidate[$key]) && $MemberToValidate[$key] > 0?$MemberToValidate[$key]:'').' '.$staticmember->LibStatut(-1,$adhtype->subscription,0,3).'</td>'; |
|
| 421 | - print '<td align="right">'.(isset($MembersValidated[$key]) && ($MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0) > 0) ? $MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):'').' '.$staticmember->LibStatut(1,$adhtype->subscription,0,3).'</td>'; |
|
| 422 | - print '<td align="right">'.(isset($MemberUpToDate[$key]) && $MemberUpToDate[$key] > 0 ? $MemberUpToDate[$key]:'').' '.$staticmember->LibStatut(1,$adhtype->subscription,$now,3).'</td>'; |
|
| 423 | - print '<td align="right">'.(isset($MembersResiliated[$key]) && $MembersResiliated[$key]> 0 ?$MembersResiliated[$key]:'').' '.$staticmember->LibStatut(0,$adhtype->subscription,0,3).'</td>'; |
|
| 424 | - print "</tr>\n"; |
|
| 418 | + print '<tr class="oddeven">'; |
|
| 419 | + print '<td>'.$adhtype->getNomUrl(1, dol_size(32)).'</td>'; |
|
| 420 | + print '<td align="right">'.(isset($MemberToValidate[$key]) && $MemberToValidate[$key] > 0?$MemberToValidate[$key]:'').' '.$staticmember->LibStatut(-1,$adhtype->subscription,0,3).'</td>'; |
|
| 421 | + print '<td align="right">'.(isset($MembersValidated[$key]) && ($MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0) > 0) ? $MembersValidated[$key]-(isset($MemberUpToDate[$key])?$MemberUpToDate[$key]:0):'').' '.$staticmember->LibStatut(1,$adhtype->subscription,0,3).'</td>'; |
|
| 422 | + print '<td align="right">'.(isset($MemberUpToDate[$key]) && $MemberUpToDate[$key] > 0 ? $MemberUpToDate[$key]:'').' '.$staticmember->LibStatut(1,$adhtype->subscription,$now,3).'</td>'; |
|
| 423 | + print '<td align="right">'.(isset($MembersResiliated[$key]) && $MembersResiliated[$key]> 0 ?$MembersResiliated[$key]:'').' '.$staticmember->LibStatut(0,$adhtype->subscription,0,3).'</td>'; |
|
| 424 | + print "</tr>\n"; |
|
| 425 | 425 | } |
| 426 | 426 | print '<tr class="liste_total">'; |
| 427 | 427 | print '<td class="liste_total">'.$langs->trans("Total").'</td>';
|
@@ -124,12 +124,14 @@ discard block |
||
| 124 | 124 | print '<div class="fichecenter"><div class="fichethirdleft">'; |
| 125 | 125 | |
| 126 | 126 | |
| 127 | -if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo |
|
| 127 | +if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { |
|
| 128 | + // This is useless due to the global search combo |
|
| 128 | 129 | {
|
| 129 | 130 | // Search contact/address |
| 130 | 131 | if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire) |
| 131 | 132 | {
|
| 132 | - $listofsearchfields['search_member']=array('text'=>'Member');
|
|
| 133 | + $listofsearchfields['search_member']=array('text'=>'Member'); |
|
| 134 | +} |
|
| 133 | 135 | } |
| 134 | 136 | |
| 135 | 137 | if (count($listofsearchfields)) |
@@ -140,10 +142,14 @@ discard block |
||
| 140 | 142 | $i=0; |
| 141 | 143 | foreach($listofsearchfields as $key => $value) |
| 142 | 144 | {
|
| 143 | - if ($i == 0) print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
|
|
| 145 | + if ($i == 0) { |
|
| 146 | + print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>'; |
|
| 147 | + } |
|
| 144 | 148 | print '<tr class="oddeven">'; |
| 145 | 149 | print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label>:</td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>'; |
| 146 | - if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
|
|
| 150 | + if ($i == 0) { |
|
| 151 | + print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>'; |
|
| 152 | + } |
|
| 147 | 153 | print '</tr>'; |
| 148 | 154 | $i++; |
| 149 | 155 | } |
@@ -315,8 +321,7 @@ discard block |
||
| 315 | 321 | $staticmember->fk_soc = $obj->fk_soc; |
| 316 | 322 | $staticmember->fetch_thirdparty(); |
| 317 | 323 | $staticmember->name=$staticmember->thirdparty->name; |
| 318 | - } |
|
| 319 | - else |
|
| 324 | + } else |
|
| 320 | 325 | {
|
| 321 | 326 | $staticmember->name=$obj->company; |
| 322 | 327 | } |
@@ -333,8 +338,7 @@ discard block |
||
| 333 | 338 | } |
| 334 | 339 | print "</table></div>"; |
| 335 | 340 | print "<br>"; |
| 336 | -} |
|
| 337 | -else |
|
| 341 | +} else |
|
| 338 | 342 | {
|
| 339 | 343 | dol_print_error($db); |
| 340 | 344 | } |
@@ -395,8 +399,7 @@ discard block |
||
| 395 | 399 | } |
| 396 | 400 | print "</table></div>"; |
| 397 | 401 | print "<br>"; |
| 398 | -} |
|
| 399 | -else |
|
| 402 | +} else |
|
| 400 | 403 | {
|
| 401 | 404 | dol_print_error($db); |
| 402 | 405 | } |
@@ -114,30 +114,30 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | if ($catname || $id > 0) |
| 116 | 116 | {
|
| 117 | - $cats = $categstatic->rechercher($id, $catname, $typetext); |
|
| 118 | - |
|
| 119 | - print '<table class="noborder" width="100%">'; |
|
| 120 | - print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
|
|
| 121 | - |
|
| 122 | - foreach ($cats as $cat) |
|
| 123 | - {
|
|
| 124 | - print "\t".'<tr class="oddeven">'."\n"; |
|
| 125 | - print "\t\t<td>"; |
|
| 126 | - $categstatic->id=$cat->id; |
|
| 127 | - $categstatic->ref=$cat->label; |
|
| 128 | - $categstatic->label=$cat->label; |
|
| 129 | - $categstatic->type=$cat->type; |
|
| 130 | - $categstatic->color=$cat->color; |
|
| 131 | - print '<span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>'; |
|
| 132 | - print $categstatic->getNomUrl(1,''); |
|
| 133 | - print '</span>'; |
|
| 134 | - print "</td>\n"; |
|
| 135 | - print "\t\t<td>"; |
|
| 136 | - print dolGetFirstLineOfText($cat->description); |
|
| 137 | - print "</td>\n"; |
|
| 138 | - print "\t</tr>\n"; |
|
| 139 | - } |
|
| 140 | - print "</table>"; |
|
| 117 | + $cats = $categstatic->rechercher($id, $catname, $typetext); |
|
| 118 | + |
|
| 119 | + print '<table class="noborder" width="100%">'; |
|
| 120 | + print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("FoundCats").'</td></tr>';
|
|
| 121 | + |
|
| 122 | + foreach ($cats as $cat) |
|
| 123 | + {
|
|
| 124 | + print "\t".'<tr class="oddeven">'."\n"; |
|
| 125 | + print "\t\t<td>"; |
|
| 126 | + $categstatic->id=$cat->id; |
|
| 127 | + $categstatic->ref=$cat->label; |
|
| 128 | + $categstatic->label=$cat->label; |
|
| 129 | + $categstatic->type=$cat->type; |
|
| 130 | + $categstatic->color=$cat->color; |
|
| 131 | + print '<span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>'; |
|
| 132 | + print $categstatic->getNomUrl(1,''); |
|
| 133 | + print '</span>'; |
|
| 134 | + print "</td>\n"; |
|
| 135 | + print "\t\t<td>"; |
|
| 136 | + print dolGetFirstLineOfText($cat->description); |
|
| 137 | + print "</td>\n"; |
|
| 138 | + print "\t</tr>\n"; |
|
| 139 | + } |
|
| 140 | + print "</table>"; |
|
| 141 | 141 | } |
| 142 | 142 | else print ' '; |
| 143 | 143 | |
@@ -159,21 +159,21 @@ discard block |
||
| 159 | 159 | $data[] = array('rowid'=>0,'fk_menu'=>-1,'title'=>"racine",'mainmenu'=>'','leftmenu'=>'','fk_mainmenu'=>'','fk_leftmenu'=>'');
|
| 160 | 160 | foreach($fulltree as $key => $val) |
| 161 | 161 | {
|
| 162 | - $categstatic->id=$val['id']; |
|
| 163 | - $categstatic->ref=$val['label']; |
|
| 164 | - $categstatic->color=$val['color']; |
|
| 165 | - $categstatic->type=$type; |
|
| 166 | - $li=$categstatic->getNomUrl(1,'',60); |
|
| 167 | - $desc=dol_htmlcleanlastbr($val['description']); |
|
| 168 | - |
|
| 169 | - $data[] = array( |
|
| 170 | - 'rowid'=>$val['rowid'], |
|
| 171 | - 'fk_menu'=>$val['fk_parent'], |
|
| 172 | - 'entry'=>'<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>'.$li.'</span></td>'. |
|
| 173 | - //'<td width="50%">'.dolGetFirstLineOfText($desc).'</td>'. |
|
| 174 | - '<td align="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.'">'.img_view().'</a></td>'. |
|
| 175 | - '</tr></table>' |
|
| 176 | - ); |
|
| 162 | + $categstatic->id=$val['id']; |
|
| 163 | + $categstatic->ref=$val['label']; |
|
| 164 | + $categstatic->color=$val['color']; |
|
| 165 | + $categstatic->type=$type; |
|
| 166 | + $li=$categstatic->getNomUrl(1,'',60); |
|
| 167 | + $desc=dol_htmlcleanlastbr($val['description']); |
|
| 168 | + |
|
| 169 | + $data[] = array( |
|
| 170 | + 'rowid'=>$val['rowid'], |
|
| 171 | + 'fk_menu'=>$val['fk_parent'], |
|
| 172 | + 'entry'=>'<table class="nobordernopadding centpercent"><tr><td><span class="noborderoncategories" '.($categstatic->color?' style="background: #'.$categstatic->color.';"':' style="background: #aaa"').'>'.$li.'</span></td>'. |
|
| 173 | + //'<td width="50%">'.dolGetFirstLineOfText($desc).'</td>'. |
|
| 174 | + '<td align="right" width="20px;"><a href="'.DOL_URL_ROOT.'/categories/viewcat.php?id='.$val['id'].'&type='.$type.'">'.img_view().'</a></td>'. |
|
| 175 | + '</tr></table>' |
|
| 176 | + ); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | print '<tr class="liste_titre"><td>'.$langs->trans("Categories").'</td><td></td><td align="right">';
|
| 184 | 184 | if (! empty($conf->use_javascript_ajax)) |
| 185 | 185 | {
|
| 186 | - print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('','object_category').' '.$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('','object_category-expanded').' '.$langs->trans("ExpandAll").'</a></div>';
|
|
| 186 | + print '<div id="iddivjstreecontrol"><a class="notasortlink" href="#">'.img_picto('','object_category').' '.$langs->trans("UndoExpandAll").'</a> | <a class="notasortlink" href="#">'.img_picto('','object_category-expanded').' '.$langs->trans("ExpandAll").'</a></div>';
|
|
| 187 | 187 | } |
| 188 | 188 | print '</td></tr>'; |
| 189 | 189 | |
@@ -191,20 +191,20 @@ discard block |
||
| 191 | 191 | |
| 192 | 192 | if ($nbofentries > 0) |
| 193 | 193 | {
|
| 194 | - print '<tr class="pair"><td colspan="3">'; |
|
| 195 | - tree_recur($data,$data[0],0); |
|
| 196 | - print '</td></tr>'; |
|
| 194 | + print '<tr class="pair"><td colspan="3">'; |
|
| 195 | + tree_recur($data,$data[0],0); |
|
| 196 | + print '</td></tr>'; |
|
| 197 | 197 | } |
| 198 | 198 | else |
| 199 | 199 | {
|
| 200 | - print '<tr class="pair">'; |
|
| 201 | - print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
|
|
| 202 | - print '<td valign="middle">'; |
|
| 203 | - print $langs->trans("NoCategoryYet");
|
|
| 204 | - print '</td>'; |
|
| 205 | - print '<td> </td>'; |
|
| 206 | - print '</table></td>'; |
|
| 207 | - print '</tr>'; |
|
| 200 | + print '<tr class="pair">'; |
|
| 201 | + print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
|
|
| 202 | + print '<td valign="middle">'; |
|
| 203 | + print $langs->trans("NoCategoryYet");
|
|
| 204 | + print '</td>'; |
|
| 205 | + print '<td> </td>'; |
|
| 206 | + print '</table></td>'; |
|
| 207 | + print '</tr>'; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | print "</table>"; |
@@ -35,13 +35,18 @@ discard block |
||
| 35 | 35 | // Load translation files required by the page |
| 36 | 36 | $langs->load("categories");
|
| 37 | 37 | |
| 38 | -if (! $user->rights->categorie->lire) accessforbidden(); |
|
| 38 | +if (! $user->rights->categorie->lire) { |
|
| 39 | + accessforbidden(); |
|
| 40 | +} |
|
| 39 | 41 | |
| 40 | 42 | $id=GETPOST('id','int');
|
| 41 | 43 | $type=(GETPOST('type','aZ09') ? GETPOST('type','aZ09') : Categorie::TYPE_PRODUCT);
|
| 42 | 44 | $catname=GETPOST('catname','alpha');
|
| 43 | 45 | |
| 44 | -if (is_numeric($type)) $type=Categorie::$MAP_ID_TO_CODE[$type]; // For backward compatibility |
|
| 46 | +if (is_numeric($type)) { |
|
| 47 | + $type=Categorie::$MAP_ID_TO_CODE[$type]; |
|
| 48 | +} |
|
| 49 | +// For backward compatibility |
|
| 45 | 50 | |
| 46 | 51 | |
| 47 | 52 | /* |
@@ -51,15 +56,7 @@ discard block |
||
| 51 | 56 | $categstatic = new Categorie($db); |
| 52 | 57 | $form = new Form($db); |
| 53 | 58 | |
| 54 | -if ($type == Categorie::TYPE_PRODUCT) { $title=$langs->trans("ProductsCategoriesArea"); $typetext='product'; }
|
|
| 55 | -elseif ($type == Categorie::TYPE_SUPPLIER) { $title=$langs->trans("SuppliersCategoriesArea"); $typetext='supplier'; }
|
|
| 56 | -elseif ($type == Categorie::TYPE_CUSTOMER) { $title=$langs->trans("CustomersCategoriesArea"); $typetext='customer'; }
|
|
| 57 | -elseif ($type == Categorie::TYPE_MEMBER) { $title=$langs->trans("MembersCategoriesArea"); $typetext='member'; }
|
|
| 58 | -elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCategoriesArea"); $typetext='contact'; }
|
|
| 59 | -elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='bank_account'; }
|
|
| 60 | -elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; }
|
|
| 61 | -elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; }
|
|
| 62 | -else { $title=$langs->trans("CategoriesArea"); $typetext='unknown'; }
|
|
| 59 | +if ($type == Categorie::TYPE_PRODUCT) { $title=$langs->trans("ProductsCategoriesArea"); $typetext='product'; } elseif ($type == Categorie::TYPE_SUPPLIER) { $title=$langs->trans("SuppliersCategoriesArea"); $typetext='supplier'; } elseif ($type == Categorie::TYPE_CUSTOMER) { $title=$langs->trans("CustomersCategoriesArea"); $typetext='customer'; } elseif ($type == Categorie::TYPE_MEMBER) { $title=$langs->trans("MembersCategoriesArea"); $typetext='member'; } elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCategoriesArea"); $typetext='contact'; } elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='bank_account'; } elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; } elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; } else { $title=$langs->trans("CategoriesArea"); $typetext='unknown'; }
|
|
| 63 | 60 | |
| 64 | 61 | $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js');
|
| 65 | 62 | $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css');
|
@@ -138,8 +135,9 @@ discard block |
||
| 138 | 135 | print "\t</tr>\n"; |
| 139 | 136 | } |
| 140 | 137 | print "</table>"; |
| 141 | -} |
|
| 142 | -else print ' '; |
|
| 138 | +} else { |
|
| 139 | + print ' '; |
|
| 140 | +} |
|
| 143 | 141 | |
| 144 | 142 | |
| 145 | 143 | //print '</td></tr></table>'; |
@@ -194,8 +192,7 @@ discard block |
||
| 194 | 192 | print '<tr class="pair"><td colspan="3">'; |
| 195 | 193 | tree_recur($data,$data[0],0); |
| 196 | 194 | print '</td></tr>'; |
| 197 | -} |
|
| 198 | -else |
|
| 195 | +} else |
|
| 199 | 196 | {
|
| 200 | 197 | print '<tr class="pair">'; |
| 201 | 198 | print '<td colspan="3"><table class="nobordernopadding"><tr class="nobordernopadding"><td>'.img_picto_common('','treemenu/branchbottom.gif').'</td>';
|
@@ -70,5 +70,7 @@ |
||
| 70 | 70 | print '<br><br>'.$langs->trans("SomeTranslationAreUncomplete");
|
| 71 | 71 | |
| 72 | 72 | // If there's no error, we display the next step button |
| 73 | -if ($err == 0) pFooter(0); |
|
| 73 | +if ($err == 0) { |
|
| 74 | + pFooter(0); |
|
| 75 | +} |
|
| 74 | 76 | |