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',
620 'ref_previous',
'ref_next',
621 'origin',
'origin_id',
622 'oldcopy',
'picto',
'error',
'errors',
623 'model_pdf',
'modelpdf',
'last_main_doc',
'civility_id',
'contact',
'contact_id',
624 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
634 'fk_delivery_address',
636 'restrictiononfksoc',
641 if ($this->element ==
'cashcontrol') {
642 $arrayoffieldstoexclude = array_merge(
643 $arrayoffieldstoexclude,
645 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
646 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
647 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
648 'extraparams',
'fk_incoterms',
'fk_user_creat',
'fk_user_valid',
'label_incoterms',
'location_incoterms',
'lines',
'nb',
'tms',
'comments',
'array_options',
'warnings',
649 'opening',
'status',
'date_valid'
655 $addthirdpartyatpaymentlevel = 0;
656 if (!empty(
$object->thirdparty) && in_array($this->element, array(
'payment',
'payment_supplier'))) {
657 $addthirdpartyatpaymentlevel = 1;
660 if (!empty(
$object->thirdparty) && !$addthirdpartyatpaymentlevel) {
661 $this->object_data->thirdparty =
new stdClass();
663 foreach (
$object->thirdparty as $key => $value) {
664 if (in_array($key, $arrayoffieldstoexclude)) {
668 if (!in_array($key, array(
669 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
670 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
675 $valuequalifiedforstorage =
false;
676 if (!is_object($value)) {
677 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
678 $valuequalifiedforstorage =
true;
681 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
682 $valuequalifiedforstorage =
true;
684 if (!is_null($value) && (
string) $value !==
'') {
685 $valuequalifiedforstorage =
true;
689 if ($valuequalifiedforstorage) {
690 $this->object_data->thirdparty->$key = $value;
696 if (!empty(
$mysoc) && in_array(
$object->element, array(
'facture',
'paiement'))) {
697 $this->object_data->mycompany =
new stdClass();
699 foreach (
$mysoc as $key => $value) {
700 if (in_array($key, $arrayoffieldstoexclude)) {
704 if (!in_array($key, array(
705 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
706 'tva_assuj',
'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
711 $valuequalifiedforstorage =
false;
712 if (!is_object($value)) {
713 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
714 $valuequalifiedforstorage =
true;
717 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
718 $valuequalifiedforstorage =
true;
720 if (!is_null($value) && (
string) $value !==
'') {
721 $valuequalifiedforstorage =
true;
725 if ($valuequalifiedforstorage) {
726 $this->object_data->mycompany->$key = $value;
733 $this->fk_user = $user->id;
734 $this->user_fullname = $user->getFullName($langs);
738 if ($this->element ==
'facture') {
739 '@phan-var-force Facture $object';
743 foreach (
$object as $key => $value) {
744 if (in_array($key, $arrayoffieldstoexclude)) {
748 if (!in_array($key, array(
749 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
751 'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
752 'revenuestamp',
'datepointoftax',
'note_public',
754 'module_source',
'pos_source',
'pos_print_counter',
'email_sent_counter'
758 if ($key ==
'lines') {
760 foreach ($value as $tmpline) {
762 foreach ($tmpline as $keyline => $valueline) {
763 if (!in_array($keyline, array(
764 'ref',
'product_type',
'product_label',
766 'vat_src_code',
'tva_tx',
'localtax1_tx',
'localtax2_tx',
767 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
768 'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
769 'info_bits',
'special_code',
'remise_percent'
774 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
775 $this->object_data->invoiceline[$lineid] =
new stdClass();
778 $valuequalifiedforstorage =
false;
779 if (!is_object($valueline)) {
780 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'))) {
781 $valuequalifiedforstorage =
true;
783 if (!is_null($valueline) && (
string) $valueline !==
'') {
784 $valuequalifiedforstorage =
true;
787 if ($keyline ==
'product_label' && empty($valueline)) {
789 $valuequalifiedforstorage =
true;
792 if ($valuequalifiedforstorage) {
793 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
798 $valuequalifiedforstorage =
false;
799 if (!is_object($value)) {
800 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
801 $valuequalifiedforstorage =
true;
804 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
805 $valuequalifiedforstorage =
true;
807 if (!is_null($value) && (
string) $value !==
'') {
808 $valuequalifiedforstorage =
true;
812 if ($valuequalifiedforstorage) {
813 $this->object_data->$key = $value;
819 $this->object_data->ref =
$object->newref;
823 if ($action ==
'BILL_SENTBYMAIL') {
824 $this->object_data->action_email_sent = array(
825 "email_from" =>
$object->context[
'email_from'],
826 "email_to" =>
$object->context[
'email_to'],
827 "email_msgid" =>
$object->context[
'email_msgid']
830 } elseif ($this->element ==
'invoice_supplier') {
831 '@phan-var-force FactureFournisseur $object';
832 foreach (
$object as $key => $value) {
833 if (in_array($key, $arrayoffieldstoexclude)) {
837 if (!in_array($key, array(
838 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
843 $valuequalifiedforstorage =
false;
844 if (!is_object($value)) {
845 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
846 $valuequalifiedforstorage =
true;
849 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
850 $valuequalifiedforstorage =
true;
852 if (!is_null($value) && (
string) $value !==
'') {
853 $valuequalifiedforstorage =
true;
857 if ($valuequalifiedforstorage) {
858 $this->object_data->$key = $value;
863 $this->object_data->ref =
$object->newref;
865 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
866 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
870 $this->object_data->ref =
$object->ref;
871 $this->object_data->date = $datepayment;
872 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
874 if (!empty(
$object->num_payment)) {
875 $this->object_data->payment_num =
$object->num_payment;
877 if (!empty(
$object->note_private)) {
878 $this->object_data->note_private =
$object->note_private;
885 $this->type_code = $this->object_data->type_code;
886 $this->linktype = $this->element;
887 $this->linktoref =
'';
891 $amountsarray =
$object->getAmountsArray();
892 $object->amounts = $amountsarray;
894 if ($action ==
'PAYMENT_CUSTOMER_DELETE') {
895 foreach (
$object->amounts as $amountkey => $amountval) {
896 $object->amounts[$amountkey] = - $amountval;
904 $originofpayment =
null;
905 $terminalofpayment =
null;
906 $paymentpartnumber = 0;
907 foreach (
$object->amounts as $objid => $amount) {
908 if (empty($amount)) {
912 $totalamount += $amount;
915 if ($this->element ==
'payment_supplier') {
916 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
918 } elseif ($this->element ==
'payment') {
919 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
920 $tmpobject =
new Facture($this->db);
921 } elseif ($this->element ==
'payment_donation') {
922 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
923 $tmpobject =
new Don($this->db);
924 } elseif ($this->element ==
'payment_various') {
925 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
929 if (!is_object($tmpobject)) {
933 $result = $tmpobject->fetch($objid);
936 $this->error = $tmpobject->error;
937 $this->errors = $tmpobject->errors;
938 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
942 $this->linktoref .= ($this->linktoref ?
',' :
'').$tmpobject->ref;
945 if (property_exists($tmpobject,
'module_source')) {
946 if (is_null($originofpayment)) {
947 $originofpayment = (
string) $tmpobject->module_source;
948 } elseif ($originofpayment != $tmpobject->module_source) {
949 $originofpayment =
'mix';
951 $originofpayment = (
string) $tmpobject->module_source;
955 if (property_exists($tmpobject,
'pos_source')) {
956 if (is_null($terminalofpayment)) {
957 $terminalofpayment = (
string) $tmpobject->pos_source;
958 } elseif ($terminalofpayment != $tmpobject->pos_source) {
959 $terminalofpayment =
'mix';
961 $terminalofpayment = (
string) $tmpobject->pos_source;
965 $paymentpart->amount = $amount;
969 if ($addthirdpartyatpaymentlevel) {
970 $result = $tmpobject->fetch_thirdparty();
972 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
973 $this->errors[] = $this->error;
974 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
976 } elseif ($result < 0) {
977 $this->error = $tmpobject->error;
978 $this->errors = $tmpobject->errors;
982 $paymentpart->thirdparty =
new stdClass();
983 foreach ($tmpobject->thirdparty as $key => $value) {
984 if (in_array($key, $arrayoffieldstoexclude)) {
988 if (!in_array($key, array(
989 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
990 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
994 if (!is_object($value) && !is_null($value) && $value !==
'') {
995 $paymentpart->thirdparty->$key = $value;
1001 if ($this->element ==
'payment_donation') {
1002 $paymentpart->donation =
new stdClass();
1003 } elseif ($this->element ==
'payment_various') {
1004 $paymentpart->various =
new stdClass();
1006 $paymentpart->invoice =
new stdClass();
1009 if ($this->element !=
'payment_various') {
1010 foreach ($tmpobject as $key => $value) {
1011 if (in_array($key, $arrayoffieldstoexclude)) {
1015 if (!in_array($key, array(
1016 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
1017 'pos_source',
'module_source',
'pos_print_counter',
'email_sent_counter'
1022 $valuequalifiedforstorage =
false;
1023 if (!is_object($value)) {
1024 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
1025 $valuequalifiedforstorage =
true;
1026 $value = (
string) $value;
1028 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
1029 $valuequalifiedforstorage =
true;
1031 if (!is_null($value) && (
string) $value !==
'') {
1032 $valuequalifiedforstorage =
true;
1036 if ($valuequalifiedforstorage) {
1037 if ($this->element ==
'payment_donation') {
1038 $paymentpart->donation->$key = $value;
1039 } elseif ($this->element ==
'payment_various') {
1040 $paymentpart->various->$key = $value;
1042 $paymentpart->invoice->$key = $value;
1047 $paymentpartnumber++;
1048 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
1052 $this->module_source = (
string) $originofpayment;
1053 $this->pos_source = (
string) $terminalofpayment;
1054 } elseif (!empty(
$object->amount)) {
1055 $totalamount =
$object->amount;
1058 $this->object_data->amount = $totalamount;
1060 if (!empty(
$object->newref)) {
1061 $this->object_data->ref =
$object->newref;
1063 } elseif ($this->element ==
'payment_salary') {
1064 '@phan-var-force PaymentSalary $object';
1065 $this->object_data->amounts = array(
$object->amount);
1067 if (!empty(
$object->newref)) {
1068 $this->object_data->ref =
$object->newref;
1070 } elseif ($this->element ==
'subscription') {
1071 '@phan-var-force Subscription $object';
1072 foreach (
$object as $key => $value) {
1073 if (in_array($key, $arrayoffieldstoexclude)) {
1076 if (!in_array($key, array(
1077 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
1081 if (!is_object($value) && !is_null($value) && $value !==
'') {
1082 $this->object_data->$key = $value;
1086 if (!empty(
$object->newref)) {
1087 $this->object_data->ref =
$object->newref;
1089 } elseif ($this->element ==
'stockmouvement') {
1090 '@phan-var-force StockTransfer $object';
1091 foreach (
$object as $key => $value) {
1092 if (in_array($key, $arrayoffieldstoexclude)) {
1095 if (!is_object($value) && !is_null($value) && $value !==
'') {
1096 $this->object_data->$key = $value;
1100 if (
$object->element ==
'cashcontrol') {
1106 foreach (
$object as $key => $value) {
1107 if (in_array($key, $arrayoffieldstoexclude)) {
1110 if (!is_object($value) && !is_null($value) && $value !==
'') {
1111 $this->object_data->$key = $value;
1115 if (
$object->element ==
'cashcontrol') {
1116 $period =
$object->year_close;
1117 $period .= (
$object->month_close ?
"-".sprintf(
"%02d",
$object->month_close) :
"");
1118 $period .= (
$object->day_close ?
"-".sprintf(
"%02d",
$object->day_close) :
"");
1120 $this->object_data->period = $period;
1123 if (!empty(
$object->newref)) {
1124 $this->object_data->ref =
$object->newref;
1130 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
1277 public function create($user, $forcesignature =
'')
1281 $langs->load(
'blockedlog');
1284 $this->amounts = (float) $this->amounts;
1286 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
1289 if (!isset($this->amounts)) {
1290 $langs->load(
"errors");
1291 $this->error = $langs->trans(
"ErrorBlockLogNeedAmountsValue");
1296 if (empty($this->element)) {
1297 $langs->load(
"errors");
1298 $this->error = $langs->trans(
"ErrorBlockLogNeedElement");
1303 if (empty($this->object_data)) {
1304 $langs->load(
"errors");
1305 $this->error = $langs->trans(
"ErrorBlockLogNeedObject");
1310 if (empty($this->action)) {
1311 $langs->load(
"errors");
1312 $this->error = $langs->trans(
"ErrorBadParameterWhenCallingCreateOfBlockedLog");
1316 if (empty($this->fk_user)) {
1317 $this->user_fullname =
'(Anonymous)';
1320 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
1324 $this->date_creation =
dol_now();
1326 $this->object_version = DOL_VERSION;
1331 $this->object_format =
'V2';
1337 $previousdatecreation = 0;
1342 $previoushash = $tmparray[
'previoushash'];
1343 $previousid = $tmparray[
'previousid'];
1344 $previousdatecreation = $tmparray[
'previousdatecreation'];
1354 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1357 $this->error = $e->getMessage();
1361 $this->db->rollback();
1365 if ($forcesignature) {
1366 $this->signature = $forcesignature;
1370 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
1371 $sql .=
" date_creation,";
1373 $sql .=
" module_source,";
1374 $sql .=
" pos_source,";
1375 $sql .=
" amounts_taxexcl,";
1376 $sql .=
" amounts,";
1377 $sql .=
" signature,";
1378 $sql .=
" element,";
1379 $sql .=
" fk_object,";
1380 $sql .=
" date_object,";
1381 $sql .=
" ref_object,";
1382 $sql .=
" type_code,";
1383 $sql .=
" linktoref,";
1384 $sql .=
" linktype,";
1385 $sql .=
" object_data,";
1386 $sql .=
" object_version,";
1387 $sql .=
" object_format,";
1388 $sql .=
" certified,";
1389 $sql .=
" fk_user,";
1390 $sql .=
" user_fullname,";
1392 $sql .=
" debuginfo";
1393 $sql .=
") VALUES (";
1394 $sql .=
"'".$this->db->idate($this->date_creation, $tz).
"',";
1395 $sql .=
"'".$this->db->escape($this->action).
"',";
1396 $sql .=
"'".$this->db->escape((
string) $this->module_source).
"',";
1397 $sql .=
"'".$this->db->escape((
string) $this->pos_source).
"',";
1398 $sql .= (is_null($this->amounts_taxexcl) ?
"null" : (float) $this->amounts_taxexcl).
",";
1399 $sql .= (float) $this->amounts.
",";
1400 $sql .=
"'".$this->db->escape($this->signature).
"',";
1401 $sql .=
"'".$this->db->escape($this->element).
"',";
1402 $sql .= (int) $this->fk_object.
",";
1403 $sql .=
"'".$this->db->idate($this->date_object, $tz).
"',";
1404 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
1405 $sql .=
"'".$this->db->escape($this->type_code).
"',";
1406 $sql .= ($this->linktoref ?
"'".$this->db->escape($this->linktoref).
"'" :
"null").
",";
1407 $sql .= ($this->linktype ?
"'".$this->db->escape($this->linktype).
"'" :
"null").
",";
1409 $sql .=
"'".$this->db->escape($this->object_version).
"',";
1410 $sql .=
"'".$this->db->escape($this->object_format).
"',";
1412 $sql .= ((int) $this->fk_user).
",";
1413 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
1414 $sql .= ((int) ($this->entity ? ((
int) $this->entity) : ((int)
$conf->entity))).
",";
1415 $sql .=
"'".$this->db->escape($this->debuginfo).
"'";
1426 $res = $this->db->query($sql);
1428 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1436 $finalsignature = $this->signature;
1443 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1446 if (!file_exists($lockfile)) {
1449 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1456 $finalnote = $this->note;
1459 } elseif (is_writable($lockfile)) {
1460 $line = file_get_contents($lockfile);
1463 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.');
1466 $sql =
"SELECT value from ".MAIN_DB_PREFIX.
"const";
1467 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1468 $resql = $this->db->query($sql);
1470 $obj = $this->db->fetch_object($resql);
1472 $line = $obj->value;
1476 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1483 $finalnote = $this->note;
1489 throw new Exception(
"Cannot read into the blockedlog .end flag ".basename($lockfile).
' to update it. Transaction aborted.');
1495 $remoteobfuscationkey =
'';
1496 if (preg_match(
'/^dolcrypt/', $line)) {
1498 } elseif (preg_match(
'/^dolobfuscation/', $line)) {
1500 if (empty($remoteobfuscationkey)) {
1501 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.");
1503 $headstring =
dolDecrypt($line, $remoteobfuscationkey);
1507 if (preg_match(
'/^BLOCKEDLOGHEAD (\d+) ([^\s]+) ([a-zA-Z0-9\-]+)/', $headstring, $reg)) {
1509 $previousidheadflag = $reg[1];
1510 $previousdatecreationheadflag = $reg[2];
1511 $previoushashheadflag = $reg[3];
1514 if ($previousid < $previousidheadflag || $previoushash != $previoushashheadflag) {
1516 $this->note =
'EndOfChainDeletionDetected ['.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
' - '.
dol_print_date($previousdatecreationheadflag,
'dayhourrfc',
'gmt').
']';
1523 $finalnote = $this->note;
1525 } elseif ($headstring !=
'') {
1527 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.");
1531 if ($finalsignature != $this->signature) {
1534 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1538 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog";
1539 $sql .=
" SET signature = '".$this->db->escape($finalsignature).
"',";
1540 $sql .=
" note = '".$this->db->escape($finalnote).
"',";
1541 $sql .=
" debuginfo = '".$this->db->escape($this->debuginfo).
"'";
1542 $sql .=
" WHERE rowid = ".((int) $this->
id);
1543 $resql = $this->db->query($sql);
1545 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.");
1551 $stringtowrite =
'BLOCKEDLOGHEAD '.$this->id.
" ".
dol_print_date($this->date_creation,
'dayhourrfc',
'gmt').
" ".(
string) $finalsignature;
1555 if (empty($remoteobfuscationkey)) {
1556 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.");
1558 $stringtowriteencoded =
dolEncrypt($stringtowrite, $remoteobfuscationkey,
'',
'',
'dolobfuscationv1-'.
$mysoc->idprof1.
'-'.$this->id);
1560 $stringtowriteencoded =
dolEncrypt($stringtowrite,
'',
'',
'',
'dolcrypt-'.
$mysoc->idprof1.
'-'.$this->id);
1565 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1566 $lockhandle = fopen($lockfile,
'w+');
1568 if (fwrite($lockhandle, $stringtowriteencoded.
"\n") ===
false) {
1569 throw new Exception(
"Cannot write to the blockedlog .end file ".$lockfile);
1572 fclose($lockhandle);
1575 throw new Exception(
"Cannot open for writing the blockedlog .end file ".$lockfile);
1578 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1579 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1580 $resql = $this->db->query($sql);
1582 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name, value, type, visible, note, entity)";
1583 $sql .=
" VALUES('".$this->db->escape(basename($lockfile)).
"', '".$this->db->escape($stringtowriteencoded).
"', 'chaine', 0, 'Blockedlog end of chain flag', ".((int)
$conf->entity).
")";
1584 $resql = $this->db->query($sql);
1586 throw new Exception(
"Cannot update the blockedlog .end flag ".basename($lockfile));
1590 $this->error = $e->getMessage();
1594 $this->db->rollback();
1598 $this->db->commit();
1620 $this->db->rollback();
1624 $this->error = $this->db->error();
1625 $this->db->rollback();
2222 public function getLog($element, $fk_object, $limit = 0, $sortfield =
'', $sortorder =
'', $search_fk_user = -1, $search_start = -1, $search_end = -1, $search_ref =
'', $search_amount =
'', $search_code =
'', $search_signature =
'', $search_module_source =
'', $search_pos_source =
'', $search_type_code =
'')
2230 if ($element ==
'all') {
2231 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2232 WHERE entity = ".((int)
$conf->entity);
2233 } elseif ($element ==
'not_certified') {
2234 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2235 WHERE entity = ".((int)
$conf->entity).
" AND certified = 0";
2236 } elseif ($element ==
'just_certified') {
2237 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2238 WHERE entity = ".((int)
$conf->entity).
" AND certified = 1";
2240 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2241 WHERE entity = ".((int)
$conf->entity).
" AND element = '".$this->db->escape($element).
"'";
2247 if ($search_fk_user > 0) {
2250 if ($search_start > 0) {
2251 $sql .=
" AND date_creation >= '".$this->db->idate($search_start,
'gmt').
"'";
2253 if ($search_end > 0) {
2254 $sql .=
" AND date_creation <= '".$this->db->idate($search_end,
'gmt').
"'";
2256 if ($search_type_code) {
2259 if ($search_ref !=
'') {
2260 $sql .=
" AND (".natural_search(
"ref_object", $search_ref, 0, 1);
2261 $sql .=
" OR ".natural_search(
"linktoref", $search_ref, 0, 1).
")";
2263 if ($search_amount !=
'') {
2266 if ($search_signature !=
'') {
2269 if (is_array($search_code)) {
2270 if (!empty($search_code)) {
2271 if (in_array(
'PAYMENT_CUSTOMER', $search_code)) {
2272 $search_code[] =
'PAYMENT_CUSTOMER_CREATE';
2273 $search_code[] =
'PAYMENT_CUSTOMER_DELETE';
2279 if ($search_code !=
'' && $search_code !=
'-1') {
2283 if (is_array($search_module_source)) {
2284 if (!empty($search_module_source)) {
2286 if (in_array(
'0', $search_module_source)) {
2287 $sql .=
"module_source = ''";
2288 unset($search_module_source[0]);
2289 if (!empty($search_module_source)) {
2293 if (!empty($search_module_source)) {
2294 $sqlTmp =
natural_search(
"module_source", implode(
',', $search_module_source), 0, 1);
2295 $sqlTmp = str_replace(
'%backoffice%',
'', $sqlTmp);
2298 $sql .=
" OR module_source = 'mix'";
2302 if ($search_module_source !=
'' && $search_module_source !=
'-1') {
2303 $sql .=
natural_search(
"module_source", $search_module_source, 3);
2306 if ($search_pos_source !=
'') {
2309 $sql .=
" OR pos_source = 'mix'";
2313 $sql .= $this->db->order($sortfield, $sortorder);
2314 $sql .= $this->db->plimit($limit + 1);
2316 $res = $this->db->query($sql);
2321 while ($obj = $this->db->fetch_object($res)) {
2331 $result = $b->fetch($obj->rowid);
2338 $this->error = $b->error;
2339 $this->errors = $b->errors;