366 if ($this->element ===
'facture') {
367 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
370 if (
$object->fetch($this->fk_object) > 0) {
373 $this->error = (string) (((
int) $this->error) + 1);
376 if ($this->element ===
'invoice_supplier') {
377 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
380 if (
$object->fetch($this->fk_object) > 0) {
383 $this->error = (string) (((
int) $this->error) + 1);
385 } elseif ($this->element ===
'payment') {
386 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
389 if (
$object->fetch($this->fk_object) > 0) {
392 $this->error = (string) (((
int) $this->error) + 1);
394 } elseif ($this->element ===
'payment_supplier') {
395 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
398 if (
$object->fetch($this->fk_object) > 0) {
401 $this->error = (string) (((
int) $this->error) + 1);
403 } elseif ($this->element ===
'payment_donation') {
404 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
407 if (
$object->fetch($this->fk_object) > 0) {
410 $this->error = (string) (((
int) $this->error) + 1);
412 } elseif ($this->element ===
'payment_various') {
413 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
416 if (
$object->fetch($this->fk_object) > 0) {
419 $this->error = (string) (((
int) $this->error) + 1);
421 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
422 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
425 if (
$object->fetch($this->fk_object) > 0) {
428 $this->error = (string) (((
int) $this->error) + 1);
430 } elseif ($this->element ===
'subscription') {
431 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
434 if (
$object->fetch($this->fk_object) > 0) {
437 $this->error = (string) (((
int) $this->error) + 1);
439 } elseif ($this->element ===
'cashcontrol') {
440 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
443 if (
$object->fetch($this->fk_object) > 0) {
446 $this->error = (string) (((
int) $this->error) + 1);
448 } elseif ($this->element ===
'stockmouvement') {
449 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
452 if (
$object->fetch($this->fk_object) > 0) {
455 $this->error = (string) (((
int) $this->error) + 1);
457 } elseif ($this->element ===
'project') {
458 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
461 if (
$object->fetch($this->fk_object) > 0) {
464 $this->error = (string) (((
int) $this->error) + 1);
466 } elseif ($this->action ==
'BLOCKEDLOG_EXPORT') {
467 return '<i class="opacitymedium">'.$langs->trans(
"logBLOCKEDLOG_EXPORT").
'</i>';
468 } elseif ($this->action ==
'MODULE_SET') {
469 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
470 } elseif ($this->action ==
'MODULE_RESET') {
471 if ($this->signature ==
'0000000000') {
472 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
474 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
478 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
522 global $langs, $user,
$mysoc;
524 if (is_object($fuser)) {
529 $this->object_data =
new stdClass();
537 $this->action = $action;
540 $this->amounts_taxexcl = $amounts_taxexcl;
541 $this->amounts = $amounts;
542 if ($action ===
'MEMBER_SUBSCRIPTION_DELETE' || $action ===
'PAYMENT_CUSTOMER_DELETE' || $action ===
'PAYMENT_SUPPLIER_DELETE' || $action ===
'DONATION_PAYMENT_DELETE') {
543 $this->amounts_taxexcl = - $this->amounts_taxexcl;
544 $this->amounts = - $this->amounts;
548 if (
$object->element ==
'payment' ||
$object->element ==
'payment_supplier') {
549 '@phan-var-force Paiement|PaiementFourn $object';
551 } elseif (
$object->element ==
'payment_salary') {
552 '@phan-var-force PaymentSalary $object';
553 $this->date_object =
$object->datev;
554 } elseif (
$object->element ==
'payment_donation' ||
$object->element ==
'payment_various') {
555 '@phan-var-force PaymentDonation $object';
557 } elseif (
$object->element ==
'subscription') {
558 '@phan-var-force Subscription $object';
559 $this->date_object =
$object->dateh;
560 } elseif (
$object->element ==
'cashcontrol') {
562 '@phan-var-force CashControl $object';
563 $this->date_object =
$object->date_creation;
564 $this->module_source =
$object->posmodule;
565 $this->pos_source =
$object->posnumber;
566 } elseif (property_exists(
$object,
'date')) {
568 $this->date_object =
$object->date;
569 } elseif (property_exists(
$object,
'datem')) {
571 $this->date_object =
$object->datem;
575 if (
$object->element ==
'invoice_supplier') {
576 '@phan-var-force FactureFournisseur $object';
579 $invoice->fetch(
$object->fk_facture_source);
580 if ($invoice->id > 0) {
581 $this->linktype =
'credit_note_of';
582 $this->linktoref = $invoice->ref;
588 if (
$object->element ==
'facture') {
589 '@phan-var-force Facture $object';
591 $invoice =
new Facture($this->db);
592 $invoice->fetch(
$object->fk_facture_source);
593 if ($invoice->id > 0) {
594 $this->linktype =
'credit_note_of';
595 $this->linktoref = $invoice->ref;
597 $this->object_data->link = $this->linktype.
' '.$this->linktoref;
599 $this->module_source = (string) $invoice->module_source;
600 $this->pos_source = (string) $invoice->pos_source;
607 $this->element =
$object->element;
609 $this->fk_object =
$object->id;
612 if (empty(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
618 $arrayoffieldstoexclude = array(
619 'table_element',
'fields',
621 'ref_previous',
'ref_next',
622 'origin',
'origin_id',
623 'oldcopy',
'picto',
'error',
'errors',
624 'model_pdf',
'modelpdf',
'last_main_doc',
'civility_id',
'contact',
'contact_id',
625 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
635 'fk_delivery_address',
637 'restrictiononfksoc',
642 if ($this->element ==
'cashcontrol') {
643 $arrayoffieldstoexclude = array_merge(
644 $arrayoffieldstoexclude,
646 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
647 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
648 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
649 'extraparams',
'fk_incoterms',
'fk_user_creat',
'fk_user_valid',
'label_incoterms',
'location_incoterms',
'lines',
'nb',
'tms',
'comments',
'array_options',
'warnings',
650 'opening',
'status',
'date_valid'
656 $addthirdpartyatpaymentlevel = 0;
657 if (!empty(
$object->thirdparty) && in_array($this->element, array(
'payment',
'payment_supplier'))) {
658 $addthirdpartyatpaymentlevel = 1;
661 if (!empty(
$object->thirdparty) && !$addthirdpartyatpaymentlevel) {
662 $this->object_data->thirdparty =
new stdClass();
664 foreach (
$object->thirdparty as $key => $value) {
665 if (in_array($key, $arrayoffieldstoexclude)) {
669 if (!in_array($key, array(
670 'name',
'name_alias',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
671 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
676 $valuequalifiedforstorage =
false;
677 if (!is_object($value)) {
678 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
679 $valuequalifiedforstorage =
true;
680 $value = (string) $value;
682 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
683 $valuequalifiedforstorage =
true;
685 if (!is_null($value) && (string) $value !==
'') {
686 $valuequalifiedforstorage =
true;
690 if ($valuequalifiedforstorage) {
691 $this->object_data->thirdparty->$key = $value;
697 if (!empty(
$mysoc) && in_array(
$object->element, array(
'facture',
'paiement'))) {
698 $this->object_data->mycompany =
new stdClass();
700 foreach (
$mysoc as $key => $value) {
701 if (in_array($key, $arrayoffieldstoexclude)) {
705 if (!in_array($key, array(
706 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
707 'tva_assuj',
'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
712 $valuequalifiedforstorage =
false;
713 if (!is_object($value)) {
714 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
715 $valuequalifiedforstorage =
true;
716 $value = (string) $value;
718 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
719 $valuequalifiedforstorage =
true;
721 if (!is_null($value) && (string) $value !==
'') {
722 $valuequalifiedforstorage =
true;
726 if ($valuequalifiedforstorage) {
727 $this->object_data->mycompany->$key = $value;
734 $this->fk_user = $user->id;
735 $this->user_fullname = $user->getFullName($langs);
739 if ($this->element ==
'facture') {
740 '@phan-var-force Facture $object';
741 $this->module_source = (string)
$object->module_source;
742 $this->pos_source = (string)
$object->pos_source;
744 foreach (
$object as $key => $value) {
745 if (in_array($key, $arrayoffieldstoexclude)) {
749 if (!in_array($key, array(
750 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
752 'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
753 'revenuestamp',
'datepointoftax',
'note_public',
755 'module_source',
'pos_source',
'pos_print_counter',
'email_sent_counter'
759 if ($key ==
'lines') {
761 foreach ($value as $tmpline) {
763 foreach ($tmpline as $keyline => $valueline) {
764 if (!in_array($keyline, array(
765 'ref',
'product_type',
'product_label',
767 'vat_src_code',
'tva_tx',
'localtax1_tx',
'localtax2_tx',
768 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
769 'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
770 'info_bits',
'special_code',
'remise_percent'
775 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
776 $this->object_data->invoiceline[$lineid] =
new stdClass();
779 $valuequalifiedforstorage =
false;
780 if (!is_object($valueline)) {
781 if (!is_null($valueline) && empty($valueline) && in_array($key, array(
'tva_tx',
'localtax1_tx',
'localtax2_tx',
'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2'))) {
782 $valuequalifiedforstorage =
true;
784 if (!is_null($valueline) && (
string) $valueline !==
'') {
785 $valuequalifiedforstorage =
true;
788 if ($keyline ==
'product_label' && empty($valueline)) {
790 $valuequalifiedforstorage =
true;
793 if ($valuequalifiedforstorage) {
794 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
799 $valuequalifiedforstorage =
false;
800 if (!is_object($value)) {
801 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
802 $valuequalifiedforstorage =
true;
803 $value = (string) $value;
805 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
806 $valuequalifiedforstorage =
true;
808 if (!is_null($value) && (string) $value !==
'') {
809 $valuequalifiedforstorage =
true;
813 if ($valuequalifiedforstorage) {
814 $this->object_data->$key = $value;
820 $this->object_data->ref =
$object->newref;
824 if ($action ==
'BILL_SENTBYMAIL') {
825 $this->object_data->action_email_sent = array(
826 "email_from" =>
$object->context[
'email_from'],
827 "email_to" =>
$object->context[
'email_to'],
828 "email_msgid" =>
$object->context[
'email_msgid']
831 } elseif ($this->element ==
'invoice_supplier') {
832 '@phan-var-force FactureFournisseur $object';
833 foreach (
$object as $key => $value) {
834 if (in_array($key, $arrayoffieldstoexclude)) {
838 if (!in_array($key, array(
839 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
844 $valuequalifiedforstorage =
false;
845 if (!is_object($value)) {
846 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
847 $valuequalifiedforstorage =
true;
848 $value = (string) $value;
850 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
851 $valuequalifiedforstorage =
true;
853 if (!is_null($value) && (string) $value !==
'') {
854 $valuequalifiedforstorage =
true;
858 if ($valuequalifiedforstorage) {
859 $this->object_data->$key = $value;
864 $this->object_data->ref =
$object->newref;
866 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
867 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
871 $this->object_data->ref =
$object->ref;
872 $this->object_data->date = $datepayment;
873 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
875 if (!empty(
$object->num_payment)) {
876 $this->object_data->payment_num =
$object->num_payment;
878 if (!empty(
$object->note_private)) {
879 $this->object_data->note_private =
$object->note_private;
886 $this->type_code = $this->object_data->type_code;
887 $this->linktype = $this->element;
888 $this->linktoref =
'';
892 $amountsarray =
$object->getAmountsArray();
893 $object->amounts = $amountsarray;
895 if ($action ==
'PAYMENT_CUSTOMER_DELETE') {
896 foreach (
$object->amounts as $amountkey => $amountval) {
897 $object->amounts[$amountkey] = - $amountval;
905 $originofpayment =
null;
906 $terminalofpayment =
null;
907 $paymentpartnumber = 0;
908 foreach (
$object->amounts as $objid => $amount) {
909 if (empty($amount)) {
913 $totalamount += $amount;
916 if ($this->element ==
'payment_supplier') {
917 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
919 } elseif ($this->element ==
'payment') {
920 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
921 $tmpobject =
new Facture($this->db);
922 } elseif ($this->element ==
'payment_donation') {
923 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
924 $tmpobject =
new Don($this->db);
925 } elseif ($this->element ==
'payment_various') {
926 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
930 if (!is_object($tmpobject)) {
934 $result = $tmpobject->fetch($objid);
937 $this->error = $tmpobject->error;
938 $this->errors = $tmpobject->errors;
939 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
943 $this->linktoref .= ($this->linktoref ?
',' :
'').$tmpobject->ref;
946 if (property_exists($tmpobject,
'module_source')) {
947 if (is_null($originofpayment)) {
948 $originofpayment = (string) $tmpobject->module_source;
949 } elseif ($originofpayment != $tmpobject->module_source) {
950 $originofpayment =
'mix';
952 $originofpayment = (string) $tmpobject->module_source;
956 if (property_exists($tmpobject,
'pos_source')) {
957 if (is_null($terminalofpayment)) {
958 $terminalofpayment = (string) $tmpobject->pos_source;
959 } elseif ($terminalofpayment != $tmpobject->pos_source) {
960 $terminalofpayment =
'mix';
962 $terminalofpayment = (string) $tmpobject->pos_source;
966 $paymentpart->amount = $amount;
970 if ($addthirdpartyatpaymentlevel) {
971 $result = $tmpobject->fetch_thirdparty();
973 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
974 $this->errors[] = $this->error;
975 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
977 } elseif ($result < 0) {
978 $this->error = $tmpobject->error;
979 $this->errors = $tmpobject->errors;
983 $paymentpart->thirdparty =
new stdClass();
984 foreach ($tmpobject->thirdparty as $key => $value) {
985 if (in_array($key, $arrayoffieldstoexclude)) {
989 if (!in_array($key, array(
990 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
991 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
995 if (!is_object($value) && !is_null($value) && $value !==
'') {
996 $paymentpart->thirdparty->$key = $value;
1002 if ($this->element ==
'payment_donation') {
1003 $paymentpart->donation =
new stdClass();
1004 } elseif ($this->element ==
'payment_various') {
1005 $paymentpart->various =
new stdClass();
1007 $paymentpart->invoice =
new stdClass();
1010 if ($this->element !=
'payment_various') {
1011 foreach ($tmpobject as $key => $value) {
1012 if (in_array($key, $arrayoffieldstoexclude)) {
1016 if (!in_array($key, array(
1017 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
1018 'pos_source',
'module_source',
'pos_print_counter',
'email_sent_counter'
1023 $valuequalifiedforstorage =
false;
1024 if (!is_object($value)) {
1025 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
1026 $valuequalifiedforstorage =
true;
1027 $value = (string) $value;
1029 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
1030 $valuequalifiedforstorage =
true;
1032 if (!is_null($value) && (string) $value !==
'') {
1033 $valuequalifiedforstorage =
true;
1037 if ($valuequalifiedforstorage) {
1038 if ($this->element ==
'payment_donation') {
1039 $paymentpart->donation->$key = $value;
1040 } elseif ($this->element ==
'payment_various') {
1041 $paymentpart->various->$key = $value;
1043 $paymentpart->invoice->$key = $value;
1048 $paymentpartnumber++;
1049 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
1053 $this->module_source = (string) $originofpayment;
1054 $this->pos_source = (string) $terminalofpayment;
1055 } elseif (!empty(
$object->amount)) {
1056 $totalamount =
$object->amount;
1059 $this->object_data->amount = $totalamount;
1061 if (!empty(
$object->newref)) {
1062 $this->object_data->ref =
$object->newref;
1064 } elseif ($this->element ==
'payment_salary') {
1065 '@phan-var-force PaymentSalary $object';
1066 $this->object_data->amounts = array(
$object->amount);
1068 if (!empty(
$object->newref)) {
1069 $this->object_data->ref =
$object->newref;
1071 } elseif ($this->element ==
'subscription') {
1072 '@phan-var-force Subscription $object';
1073 foreach (
$object as $key => $value) {
1074 if (in_array($key, $arrayoffieldstoexclude)) {
1077 if (!in_array($key, array(
1078 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
1082 if (!is_object($value) && !is_null($value) && $value !==
'') {
1083 $this->object_data->$key = $value;
1087 if (!empty(
$object->newref)) {
1088 $this->object_data->ref =
$object->newref;
1090 } elseif ($this->element ==
'stockmouvement') {
1091 '@phan-var-force StockTransfer $object';
1092 foreach (
$object as $key => $value) {
1093 if (in_array($key, $arrayoffieldstoexclude)) {
1096 if (!is_object($value) && !is_null($value) && $value !==
'') {
1097 $this->object_data->$key = $value;
1101 if (
$object->element ==
'cashcontrol') {
1102 $this->module_source = (string)
$object->posmodule;
1103 $this->pos_source = (string)
$object->posnumber;
1107 foreach (
$object as $key => $value) {
1108 if (in_array($key, $arrayoffieldstoexclude)) {
1111 if (!is_object($value) && !is_null($value) && $value !==
'') {
1112 $this->object_data->$key = $value;
1116 if (
$object->element ==
'cashcontrol') {
1117 $period =
$object->year_close;
1118 $period .= (
$object->month_close ?
"-".sprintf(
"%02d",
$object->month_close) :
"");
1119 $period .= (
$object->day_close ?
"-".sprintf(
"%02d",
$object->day_close) :
"");
1121 $this->object_data->period = $period;
1124 if (!empty(
$object->newref)) {
1125 $this->object_data->ref =
$object->newref;
1131 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
1278 public function create($user, $forcesignature =
'')
1282 $langs->load(
'blockedlog');
1285 $this->amounts = (float) $this->amounts;
1287 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
1290 if (!isset($this->amounts)) {
1291 $langs->load(
"errors");
1292 $this->error = $langs->trans(
"ErrorBlockLogNeedAmountsValue");
1297 if (empty($this->element)) {
1298 $langs->load(
"errors");
1299 $this->error = $langs->trans(
"ErrorBlockLogNeedElement");
1304 if (empty($this->object_data)) {
1305 $langs->load(
"errors");
1306 $this->error = $langs->trans(
"ErrorBlockLogNeedObject");
1311 if (empty($this->date_object)) {
1312 $langs->load(
"errors");
1313 $this->error = $langs->trans(
"ErrorBlockLogNeedDateObject");
1318 if (empty($this->action)) {
1319 $langs->load(
"errors");
1320 $this->error = $langs->trans(
"ErrorBadParameterWhenCallingCreateOfBlockedLog");
1324 if (empty($this->fk_user)) {
1325 $this->user_fullname =
'(Anonymous)';
1328 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
1332 $this->date_creation =
dol_now();
1334 $this->object_version = DOL_VERSION;
1339 $this->object_format =
'V2';
1345 $previousdatecreation = 0;
1350 $previoushash = $tmparray[
'previoushash'];
1351 $previousid = $tmparray[
'previousid'];
1352 $previousdatecreation = $tmparray[
'previousdatecreation'];
1362 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1365 $this->error = $e->getMessage();
1369 $this->db->rollback();
1373 if ($forcesignature) {
1374 $this->signature = $forcesignature;
1378 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
1379 $sql .=
" date_creation,";
1381 $sql .=
" module_source,";
1382 $sql .=
" pos_source,";
1383 $sql .=
" amounts_taxexcl,";
1384 $sql .=
" amounts,";
1385 $sql .=
" signature,";
1386 $sql .=
" element,";
1387 $sql .=
" fk_object,";
1388 $sql .=
" date_object,";
1389 $sql .=
" ref_object,";
1390 $sql .=
" type_code,";
1391 $sql .=
" linktoref,";
1392 $sql .=
" linktype,";
1393 $sql .=
" object_data,";
1394 $sql .=
" object_version,";
1395 $sql .=
" object_format,";
1396 $sql .=
" certified,";
1397 $sql .=
" fk_user,";
1398 $sql .=
" user_fullname,";
1400 $sql .=
" debuginfo";
1401 $sql .=
") VALUES (";
1402 $sql .=
"'".$this->db->idate($this->date_creation, $tz).
"',";
1403 $sql .=
"'".$this->db->escape($this->action).
"',";
1404 $sql .=
"'".$this->db->escape((
string) $this->module_source).
"',";
1405 $sql .=
"'".$this->db->escape((
string) $this->pos_source).
"',";
1406 $sql .= (is_null($this->amounts_taxexcl) ?
"null" : (float) $this->amounts_taxexcl).
",";
1407 $sql .= (float) $this->amounts.
",";
1408 $sql .=
"'".$this->db->escape($this->signature).
"',";
1409 $sql .=
"'".$this->db->escape($this->element).
"',";
1410 $sql .= (int) $this->fk_object.
",";
1411 $sql .=
"'".$this->db->idate($this->date_object, $tz).
"',";
1412 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
1413 $sql .=
"'".$this->db->escape($this->type_code).
"',";
1414 $sql .= ($this->linktoref ?
"'".$this->db->escape($this->linktoref).
"'" :
"null").
",";
1415 $sql .= ($this->linktype ?
"'".$this->db->escape($this->linktype).
"'" :
"null").
",";
1417 $sql .=
"'".$this->db->escape($this->object_version).
"',";
1418 $sql .=
"'".$this->db->escape($this->object_format).
"',";
1420 $sql .= ((int) $this->fk_user).
",";
1421 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
1422 $sql .= ((int) ($this->entity ? ((
int) $this->entity) : ((int)
$conf->entity))).
",";
1423 $sql .=
"'".$this->db->escape($this->debuginfo).
"'";
1434 $res = $this->db->query($sql);
1436 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1444 $finalsignature = $this->signature;
1451 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1454 if (!file_exists($lockfile)) {
1457 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1464 $finalnote = $this->note;
1467 } elseif (is_writable($lockfile)) {
1468 $line = file_get_contents($lockfile);
1471 throw new Exception(
"Cannot write into the blockedlog .end flag ".$lockfile.
' to update it. Is the file writable by the running user and not open by another process? Transaction aborted.');
1474 $sql =
"SELECT value from ".MAIN_DB_PREFIX.
"const";
1475 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1476 $resql = $this->db->query($sql);
1478 $obj = $this->db->fetch_object($resql);
1480 $line = $obj->value;
1484 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1491 $finalnote = $this->note;
1497 throw new Exception(
"Cannot read into the blockedlog .end flag ".basename($lockfile).
' to update it. Transaction aborted.');
1503 $remoteobfuscationkey =
'';
1504 if (preg_match(
'/^dolcrypt/', $line)) {
1506 } elseif (preg_match(
'/^dolobfuscation/', $line)) {
1508 if (empty($remoteobfuscationkey)) {
1509 throw new Exception(
"Failed to get the remote obfuscation key. We can't read the end of chain flag file so we abort the transaction.");
1511 $headstring =
dolDecrypt($line, $remoteobfuscationkey);
1515 if (preg_match(
'/^BLOCKEDLOGHEAD (\d+) ([^\s]+) ([a-zA-Z0-9\-]+)/', $headstring, $reg)) {
1517 $previousidheadflag = $reg[1];
1518 $previousdatecreationheadflag = $reg[2];
1519 $previoushashheadflag = $reg[3];
1522 if ($previousid < $previousidheadflag || $previoushash != $previoushashheadflag) {
1524 $this->note =
'EndOfChainDeletionDetected ['.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
' - '.
dol_print_date($previousdatecreationheadflag,
'dayhourrfc',
'gmt').
']';
1531 $finalnote = $this->note;
1533 } elseif ($headstring !=
'') {
1535 throw new Exception(
"Failed to decode the content of the .end flag ".basename($lockfile).
", content = ".$line.
" (remote obfuscation key = ".$remoteobfuscationkey.
"), so we can't record the head file so we abort the transaction.");
1539 if ($finalsignature != $this->signature) {
1542 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1546 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog";
1547 $sql .=
" SET signature = '".$this->db->escape($finalsignature).
"',";
1548 $sql .=
" note = '".$this->db->escape($finalnote).
"',";
1549 $sql .=
" debuginfo = '".$this->db->escape($this->debuginfo).
"'";
1550 $sql .=
" WHERE rowid = ".((int) $this->
id);
1551 $resql = $this->db->query($sql);
1553 throw new Exception(
"End of chain deletion detected but we failed to update the signature of the record ".$this->
id.
" to set the note and new signature ".$finalsignature.
" to track this.");
1559 $stringtowrite =
'BLOCKEDLOGHEAD '.$this->id.
" ".
dol_print_date($this->date_creation,
'dayhourrfc',
'gmt').
" ".(string) $finalsignature;
1563 if (empty($remoteobfuscationkey)) {
1564 throw new Exception(
"Failed to get the remote obfuscation key. We can't record the end of chain flag file so we abort the transaction.");
1566 $stringtowriteencoded =
dolEncrypt($stringtowrite, $remoteobfuscationkey,
'',
'',
'dolobfuscationv1-'.
$mysoc->idprof1.
'-'.$this->id);
1568 $stringtowriteencoded =
dolEncrypt($stringtowrite,
'',
'',
'',
'dolcrypt-'.
$mysoc->idprof1.
'-'.$this->id);
1573 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1574 $lockhandle = fopen($lockfile,
'w+');
1576 if (fwrite($lockhandle, $stringtowriteencoded.
"\n") ===
false) {
1577 throw new Exception(
"Cannot write to the blockedlog .end file ".$lockfile);
1580 fclose($lockhandle);
1583 throw new Exception(
"Cannot open for writing the blockedlog .end file ".$lockfile);
1586 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1587 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1588 $resql = $this->db->query($sql);
1590 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name, value, type, visible, note, entity)";
1591 $sql .=
" VALUES('".$this->db->escape(basename($lockfile)).
"', '".$this->db->escape($stringtowriteencoded).
"', 'chaine', 0, 'Blockedlog end of chain flag', ".((int)
$conf->entity).
")";
1592 $resql = $this->db->query($sql);
1594 throw new Exception(
"Cannot update the blockedlog .end flag ".basename($lockfile));
1598 $this->error = $e->getMessage();
1602 $this->db->rollback();
1606 $this->db->commit();
1628 $this->db->rollback();
1632 $this->error = $this->db->error();
1633 $this->db->rollback();