365 if ($this->element ===
'facture') {
366 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
369 if (
$object->fetch($this->fk_object) > 0) {
372 $this->error = (
string) (((
int) $this->error) + 1);
375 if ($this->element ===
'invoice_supplier') {
376 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
379 if (
$object->fetch($this->fk_object) > 0) {
382 $this->error = (
string) (((
int) $this->error) + 1);
384 } elseif ($this->element ===
'payment') {
385 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
388 if (
$object->fetch($this->fk_object) > 0) {
391 $this->error = (
string) (((
int) $this->error) + 1);
393 } elseif ($this->element ===
'payment_supplier') {
394 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
397 if (
$object->fetch($this->fk_object) > 0) {
400 $this->error = (
string) (((
int) $this->error) + 1);
402 } elseif ($this->element ===
'payment_donation') {
403 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
406 if (
$object->fetch($this->fk_object) > 0) {
409 $this->error = (
string) (((
int) $this->error) + 1);
411 } elseif ($this->element ===
'payment_various') {
412 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
415 if (
$object->fetch($this->fk_object) > 0) {
418 $this->error = (
string) (((
int) $this->error) + 1);
420 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
421 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
424 if (
$object->fetch($this->fk_object) > 0) {
427 $this->error = (
string) (((
int) $this->error) + 1);
429 } elseif ($this->element ===
'subscription') {
430 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
433 if (
$object->fetch($this->fk_object) > 0) {
436 $this->error = (
string) (((
int) $this->error) + 1);
438 } elseif ($this->element ===
'cashcontrol') {
439 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
442 if (
$object->fetch($this->fk_object) > 0) {
445 $this->error = (
string) (((
int) $this->error) + 1);
447 } elseif ($this->element ===
'stockmouvement') {
448 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
451 if (
$object->fetch($this->fk_object) > 0) {
454 $this->error = (
string) (((
int) $this->error) + 1);
456 } elseif ($this->element ===
'project') {
457 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
460 if (
$object->fetch($this->fk_object) > 0) {
463 $this->error = (
string) (((
int) $this->error) + 1);
465 } elseif ($this->action ==
'BLOCKEDLOG_EXPORT') {
466 return '<i class="opacitymedium">'.$langs->trans(
"logBLOCKEDLOG_EXPORT").
'</i>';
467 } elseif ($this->action ==
'MODULE_SET') {
468 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
469 } elseif ($this->action ==
'MODULE_RESET') {
470 if ($this->signature ==
'0000000000') {
471 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
473 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
477 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
521 global $langs, $user,
$mysoc;
523 if (is_object($fuser)) {
528 $this->object_data =
new stdClass();
536 $this->action = $action;
539 $this->amounts_taxexcl = $amounts_taxexcl;
540 $this->amounts = $amounts;
541 if ($action ===
'MEMBER_SUBSCRIPTION_DELETE' || $action ===
'PAYMENT_CUSTOMER_DELETE' || $action ===
'PAYMENT_SUPPLIER_DELETE' || $action ===
'DONATION_PAYMENT_DELETE') {
542 $this->amounts_taxexcl = - $this->amounts_taxexcl;
543 $this->amounts = - $this->amounts;
547 if (
$object->element ==
'payment' ||
$object->element ==
'payment_supplier') {
548 '@phan-var-force Paiement|PaiementFourn $object';
550 } elseif (
$object->element ==
'payment_salary') {
551 '@phan-var-force PaymentSalary $object';
552 $this->date_object =
$object->datev;
553 } elseif (
$object->element ==
'payment_donation' ||
$object->element ==
'payment_various') {
554 '@phan-var-force PaymentDonation $object';
556 } elseif (
$object->element ==
'subscription') {
557 '@phan-var-force Subscription $object';
558 $this->date_object =
$object->dateh;
559 } elseif (
$object->element ==
'cashcontrol') {
561 '@phan-var-force CashControl $object';
562 $this->date_object =
$object->date_creation;
563 $this->module_source =
$object->posmodule;
564 $this->pos_source =
$object->posnumber;
565 } elseif (property_exists(
$object,
'date')) {
567 $this->date_object =
$object->date;
568 } elseif (property_exists(
$object,
'datem')) {
570 $this->date_object =
$object->datem;
574 if (
$object->element ==
'invoice_supplier') {
575 '@phan-var-force FactureFournisseur $object';
578 $invoice->fetch(
$object->fk_facture_source);
579 if ($invoice->id > 0) {
580 $this->linktype =
'credit_note_of';
581 $this->linktoref = $invoice->ref;
587 if (
$object->element ==
'facture') {
588 '@phan-var-force Facture $object';
590 $invoice =
new Facture($this->db);
591 $invoice->fetch(
$object->fk_facture_source);
592 if ($invoice->id > 0) {
593 $this->linktype =
'credit_note_of';
594 $this->linktoref = $invoice->ref;
596 $this->object_data->link = $this->linktype.
' '.$this->linktoref;
598 $this->module_source = (
string) $invoice->module_source;
599 $this->pos_source = (
string) $invoice->pos_source;
606 $this->element =
$object->element;
608 $this->fk_object =
$object->id;
611 if (empty(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
617 $arrayoffieldstoexclude = array(
618 'table_element',
'fields',
619 'ref_previous',
'ref_next',
620 'origin',
'origin_id',
621 'oldcopy',
'picto',
'error',
'errors',
622 'model_pdf',
'modelpdf',
'last_main_doc',
'civility_id',
'contact',
'contact_id',
623 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
633 'fk_delivery_address',
635 'restrictiononfksoc',
640 if ($this->element ==
'cashcontrol') {
641 $arrayoffieldstoexclude = array_merge($arrayoffieldstoexclude, array(
642 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
643 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
644 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
645 'extraparams',
'fk_incoterms',
'fk_user_creat',
'fk_user_valid',
'label_incoterms',
'location_incoterms',
'lines',
'nb',
'tms',
'comments',
'array_options',
'warnings',
646 'opening',
'status',
'date_valid'
652 $addthirdpartyatpaymentlevel = 0;
653 if (!empty(
$object->thirdparty) && in_array($this->element, array(
'payment',
'payment_supplier'))) {
654 $addthirdpartyatpaymentlevel = 1;
657 if (!empty(
$object->thirdparty) && !$addthirdpartyatpaymentlevel) {
658 $this->object_data->thirdparty =
new stdClass();
660 foreach (
$object->thirdparty as $key => $value) {
661 if (in_array($key, $arrayoffieldstoexclude)) {
665 if (!in_array($key, array(
666 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
667 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
672 $valuequalifiedforstorage =
false;
673 if (!is_object($value)) {
674 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
675 $valuequalifiedforstorage =
true;
678 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
679 $valuequalifiedforstorage =
true;
681 if (!is_null($value) && (
string) $value !==
'') {
682 $valuequalifiedforstorage =
true;
686 if ($valuequalifiedforstorage) {
687 $this->object_data->thirdparty->$key = $value;
693 if (!empty(
$mysoc) && in_array(
$object->element, array(
'facture',
'paiement'))) {
694 $this->object_data->mycompany =
new stdClass();
696 foreach (
$mysoc as $key => $value) {
697 if (in_array($key, $arrayoffieldstoexclude)) {
701 if (!in_array($key, array(
702 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
703 'tva_assuj',
'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
708 $valuequalifiedforstorage =
false;
709 if (!is_object($value)) {
710 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
711 $valuequalifiedforstorage =
true;
714 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
715 $valuequalifiedforstorage =
true;
717 if (!is_null($value) && (
string) $value !==
'') {
718 $valuequalifiedforstorage =
true;
722 if ($valuequalifiedforstorage) {
723 $this->object_data->mycompany->$key = $value;
730 $this->fk_user = $user->id;
731 $this->user_fullname = $user->getFullName($langs);
735 if ($this->element ==
'facture') {
736 '@phan-var-force Facture $object';
740 foreach (
$object as $key => $value) {
741 if (in_array($key, $arrayoffieldstoexclude)) {
745 if (!in_array($key, array(
746 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
748 'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
749 'revenuestamp',
'datepointoftax',
'note_public',
751 'module_source',
'pos_source',
'pos_print_counter',
'email_sent_counter'
755 if ($key ==
'lines') {
757 foreach ($value as $tmpline) {
759 foreach ($tmpline as $keyline => $valueline) {
760 if (!in_array($keyline, array(
761 'ref',
'product_type',
'product_label',
763 'vat_src_code',
'tva_tx',
'localtax1_tx',
'localtax2_tx',
764 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
765 'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
766 'info_bits',
'special_code',
'remise_percent'
771 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
772 $this->object_data->invoiceline[$lineid] =
new stdClass();
775 $valuequalifiedforstorage =
false;
776 if (!is_object($valueline)) {
777 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'))) {
778 $valuequalifiedforstorage =
true;
780 if (!is_null($valueline) && (
string) $valueline !==
'') {
781 $valuequalifiedforstorage =
true;
784 if ($keyline ==
'product_label' && empty($valueline)) {
786 $valuequalifiedforstorage =
true;
789 if ($valuequalifiedforstorage) {
790 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
795 $valuequalifiedforstorage =
false;
796 if (!is_object($value)) {
797 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
798 $valuequalifiedforstorage =
true;
801 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
802 $valuequalifiedforstorage =
true;
804 if (!is_null($value) && (
string) $value !==
'') {
805 $valuequalifiedforstorage =
true;
809 if ($valuequalifiedforstorage) {
810 $this->object_data->$key = $value;
816 $this->object_data->ref =
$object->newref;
820 if ($action ==
'BILL_SENTBYMAIL') {
821 $this->object_data->action_email_sent = array(
822 "email_from" =>
$object->context[
'email_from'],
823 "email_to" =>
$object->context[
'email_to'],
824 "email_msgid" =>
$object->context[
'email_msgid']
827 } elseif ($this->element ==
'invoice_supplier') {
828 '@phan-var-force FactureFournisseur $object';
829 foreach (
$object as $key => $value) {
830 if (in_array($key, $arrayoffieldstoexclude)) {
834 if (!in_array($key, array(
835 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
840 $valuequalifiedforstorage =
false;
841 if (!is_object($value)) {
842 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
843 $valuequalifiedforstorage =
true;
846 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
847 $valuequalifiedforstorage =
true;
849 if (!is_null($value) && (
string) $value !==
'') {
850 $valuequalifiedforstorage =
true;
854 if ($valuequalifiedforstorage) {
855 $this->object_data->$key = $value;
860 $this->object_data->ref =
$object->newref;
862 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
863 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
867 $this->object_data->ref =
$object->ref;
868 $this->object_data->date = $datepayment;
869 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
871 if (!empty(
$object->num_payment)) {
872 $this->object_data->payment_num =
$object->num_payment;
874 if (!empty(
$object->note_private)) {
875 $this->object_data->note_private =
$object->note_private;
882 $this->type_code = $this->object_data->type_code;
883 $this->linktype = $this->element;
884 $this->linktoref =
'';
888 $amountsarray =
$object->getAmountsArray();
889 $object->amounts = $amountsarray;
891 if ($action ==
'PAYMENT_CUSTOMER_DELETE') {
892 foreach (
$object->amounts as $amountkey => $amountval) {
893 $object->amounts[$amountkey] = - $amountval;
901 $originofpayment =
null;
902 $terminalofpayment =
null;
903 $paymentpartnumber = 0;
904 foreach (
$object->amounts as $objid => $amount) {
905 if (empty($amount)) {
909 $totalamount += $amount;
912 if ($this->element ==
'payment_supplier') {
913 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
915 } elseif ($this->element ==
'payment') {
916 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
917 $tmpobject =
new Facture($this->db);
918 } elseif ($this->element ==
'payment_donation') {
919 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
920 $tmpobject =
new Don($this->db);
921 } elseif ($this->element ==
'payment_various') {
922 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
926 if (!is_object($tmpobject)) {
930 $result = $tmpobject->fetch($objid);
933 $this->error = $tmpobject->error;
934 $this->errors = $tmpobject->errors;
935 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
939 $this->linktoref .= ($this->linktoref ?
',' :
'').$tmpobject->ref;
942 if (property_exists($tmpobject,
'module_source')) {
943 if (is_null($originofpayment)) {
944 $originofpayment = (
string) $tmpobject->module_source;
945 } elseif ($originofpayment != $tmpobject->module_source) {
946 $originofpayment =
'mix';
948 $originofpayment = (
string) $tmpobject->module_source;
952 if (property_exists($tmpobject,
'pos_source')) {
953 if (is_null($terminalofpayment)) {
954 $terminalofpayment = (
string) $tmpobject->pos_source;
955 } elseif ($terminalofpayment != $tmpobject->pos_source) {
956 $terminalofpayment =
'mix';
958 $terminalofpayment = (
string) $tmpobject->pos_source;
962 $paymentpart->amount = $amount;
966 if ($addthirdpartyatpaymentlevel) {
967 $result = $tmpobject->fetch_thirdparty();
969 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
970 $this->errors[] = $this->error;
971 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
973 } elseif ($result < 0) {
974 $this->error = $tmpobject->error;
975 $this->errors = $tmpobject->errors;
979 $paymentpart->thirdparty =
new stdClass();
980 foreach ($tmpobject->thirdparty as $key => $value) {
981 if (in_array($key, $arrayoffieldstoexclude)) {
985 if (!in_array($key, array(
986 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
987 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
991 if (!is_object($value) && !is_null($value) && $value !==
'') {
992 $paymentpart->thirdparty->$key = $value;
998 if ($this->element ==
'payment_donation') {
999 $paymentpart->donation =
new stdClass();
1000 } elseif ($this->element ==
'payment_various') {
1001 $paymentpart->various =
new stdClass();
1003 $paymentpart->invoice =
new stdClass();
1006 if ($this->element !=
'payment_various') {
1007 foreach ($tmpobject as $key => $value) {
1008 if (in_array($key, $arrayoffieldstoexclude)) {
1012 if (!in_array($key, array(
1013 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
1014 'pos_source',
'module_source',
'pos_print_counter',
'email_sent_counter'
1019 $valuequalifiedforstorage =
false;
1020 if (!is_object($value)) {
1021 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
1022 $valuequalifiedforstorage =
true;
1023 $value = (
string) $value;
1025 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
1026 $valuequalifiedforstorage =
true;
1028 if (!is_null($value) && (
string) $value !==
'') {
1029 $valuequalifiedforstorage =
true;
1033 if ($valuequalifiedforstorage) {
1034 if ($this->element ==
'payment_donation') {
1035 $paymentpart->donation->$key = $value;
1036 } elseif ($this->element ==
'payment_various') {
1037 $paymentpart->various->$key = $value;
1039 $paymentpart->invoice->$key = $value;
1044 $paymentpartnumber++;
1045 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
1049 $this->module_source = (
string) $originofpayment;
1050 $this->pos_source = (
string) $terminalofpayment;
1051 } elseif (!empty(
$object->amount)) {
1052 $totalamount =
$object->amount;
1055 $this->object_data->amount = $totalamount;
1057 if (!empty(
$object->newref)) {
1058 $this->object_data->ref =
$object->newref;
1060 } elseif ($this->element ==
'payment_salary') {
1061 '@phan-var-force PaymentSalary $object';
1062 $this->object_data->amounts = array(
$object->amount);
1064 if (!empty(
$object->newref)) {
1065 $this->object_data->ref =
$object->newref;
1067 } elseif ($this->element ==
'subscription') {
1068 '@phan-var-force Subscription $object';
1069 foreach (
$object as $key => $value) {
1070 if (in_array($key, $arrayoffieldstoexclude)) {
1073 if (!in_array($key, array(
1074 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
1078 if (!is_object($value) && !is_null($value) && $value !==
'') {
1079 $this->object_data->$key = $value;
1083 if (!empty(
$object->newref)) {
1084 $this->object_data->ref =
$object->newref;
1086 } elseif ($this->element ==
'stockmouvement') {
1087 '@phan-var-force StockTransfer $object';
1088 foreach (
$object as $key => $value) {
1089 if (in_array($key, $arrayoffieldstoexclude)) {
1092 if (!is_object($value) && !is_null($value) && $value !==
'') {
1093 $this->object_data->$key = $value;
1097 if (
$object->element ==
'cashcontrol') {
1103 foreach (
$object as $key => $value) {
1104 if (in_array($key, $arrayoffieldstoexclude)) {
1107 if (!is_object($value) && !is_null($value) && $value !==
'') {
1108 $this->object_data->$key = $value;
1112 if (
$object->element ==
'cashcontrol') {
1113 $period =
$object->year_close;
1114 $period .= (
$object->month_close ?
"-".sprintf(
"%02d",
$object->month_close) :
"");
1115 $period .= (
$object->day_close ?
"-".sprintf(
"%02d",
$object->day_close) :
"");
1117 $this->object_data->period = $period;
1120 if (!empty(
$object->newref)) {
1121 $this->object_data->ref =
$object->newref;
1127 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
1275 public function create($user, $forcesignature =
'')
1279 $langs->load(
'blockedlog');
1282 $this->amounts = (float) $this->amounts;
1284 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
1287 if (!isset($this->amounts)) {
1288 $langs->load(
"errors");
1289 $this->error = $langs->trans(
"ErrorBlockLogNeedAmountsValue");
1294 if (empty($this->element)) {
1295 $langs->load(
"errors");
1296 $this->error = $langs->trans(
"ErrorBlockLogNeedElement");
1301 if (empty($this->object_data)) {
1302 $langs->load(
"errors");
1303 $this->error = $langs->trans(
"ErrorBlockLogNeedObject");
1308 if (empty($this->action)) {
1309 $langs->load(
"errors");
1310 $this->error = $langs->trans(
"ErrorBadParameterWhenCallingCreateOfBlockedLog");
1314 if (empty($this->fk_user)) {
1315 $this->user_fullname =
'(Anonymous)';
1318 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
1322 $this->date_creation =
dol_now();
1324 $this->object_version = DOL_VERSION;
1329 $this->object_format =
'V2';
1335 $previousdatecreation = 0;
1340 $previoushash = $tmparray[
'previoushash'];
1341 $previousid = $tmparray[
'previousid'];
1342 $previousdatecreation = $tmparray[
'previousdatecreation'];
1352 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1355 $this->error = $e->getMessage();
1359 $this->db->rollback();
1363 if ($forcesignature) {
1364 $this->signature = $forcesignature;
1368 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
1369 $sql .=
" date_creation,";
1371 $sql .=
" module_source,";
1372 $sql .=
" pos_source,";
1373 $sql .=
" amounts_taxexcl,";
1374 $sql .=
" amounts,";
1375 $sql .=
" signature,";
1376 $sql .=
" element,";
1377 $sql .=
" fk_object,";
1378 $sql .=
" date_object,";
1379 $sql .=
" ref_object,";
1380 $sql .=
" type_code,";
1381 $sql .=
" linktoref,";
1382 $sql .=
" linktype,";
1383 $sql .=
" object_data,";
1384 $sql .=
" object_version,";
1385 $sql .=
" object_format,";
1386 $sql .=
" certified,";
1387 $sql .=
" fk_user,";
1388 $sql .=
" user_fullname,";
1390 $sql .=
" debuginfo";
1391 $sql .=
") VALUES (";
1392 $sql .=
"'".$this->db->idate($this->date_creation, $tz).
"',";
1393 $sql .=
"'".$this->db->escape($this->action).
"',";
1394 $sql .=
"'".$this->db->escape((
string) $this->module_source).
"',";
1395 $sql .=
"'".$this->db->escape((
string) $this->pos_source).
"',";
1396 $sql .= (is_null($this->amounts_taxexcl) ?
"null" : (float) $this->amounts_taxexcl).
",";
1397 $sql .= (float) $this->amounts.
",";
1398 $sql .=
"'".$this->db->escape($this->signature).
"',";
1399 $sql .=
"'".$this->db->escape($this->element).
"',";
1400 $sql .= (int) $this->fk_object.
",";
1401 $sql .=
"'".$this->db->idate($this->date_object, $tz).
"',";
1402 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
1403 $sql .=
"'".$this->db->escape($this->type_code).
"',";
1404 $sql .= ($this->linktoref ?
"'".$this->db->escape($this->linktoref).
"'" :
"null").
",";
1405 $sql .= ($this->linktype ?
"'".$this->db->escape($this->linktype).
"'" :
"null").
",";
1407 $sql .=
"'".$this->db->escape($this->object_version).
"',";
1408 $sql .=
"'".$this->db->escape($this->object_format).
"',";
1410 $sql .= ((int) $this->fk_user).
",";
1411 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
1412 $sql .= ((int) ($this->entity ? $this->entity :
$conf->entity)).
",";
1413 $sql .=
"'".$this->db->escape($this->debuginfo).
"'";
1424 $res = $this->db->query($sql);
1426 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1434 $finalsignature = $this->signature;
1441 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1444 if (!file_exists($lockfile)) {
1447 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1454 $finalnote = $this->note;
1457 } elseif (is_writable($lockfile)) {
1458 $line = file_get_contents($lockfile);
1461 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.');
1464 $sql =
"SELECT value from ".MAIN_DB_PREFIX.
"const";
1465 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1466 $resql = $this->db->query($sql);
1468 $obj = $this->db->fetch_object($resql);
1470 $line = $obj->value;
1474 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1481 $finalnote = $this->note;
1487 throw new Exception(
"Cannot read into the blockedlog .end flag ".basename($lockfile).
' to update it. Transaction aborted.');
1493 $remoteobfuscationkey =
'';
1494 if (preg_match(
'/^dolcrypt/', $line)) {
1496 } elseif (preg_match(
'/^dolobfuscation/', $line)) {
1498 if (empty($remoteobfuscationkey)) {
1499 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.");
1501 $headstring =
dolDecrypt($line, $remoteobfuscationkey);
1505 if (preg_match(
'/^BLOCKEDLOGHEAD (\d+) ([^\s]+) ([a-zA-Z0-9\-]+)/', $headstring, $reg)) {
1507 $previousidheadflag = $reg[1];
1508 $previousdatecreationheadflag = $reg[2];
1509 $previoushashheadflag = $reg[3];
1512 if ($previousid < $previousidheadflag || $previoushash != $previoushashheadflag) {
1514 $this->note =
'EndOfChainDeletionDetected ['.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
' - '.
dol_print_date($previousdatecreationheadflag,
'dayhourrfc',
'gmt').
']';
1521 $finalnote = $this->note;
1523 } elseif ($headstring !=
'') {
1525 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.");
1529 if ($finalsignature != $this->signature) {
1532 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1536 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog";
1537 $sql .=
" SET signature = '".$this->db->escape($finalsignature).
"',";
1538 $sql .=
" note = '".$this->db->escape($finalnote).
"',";
1539 $sql .=
" debuginfo = '".$this->db->escape($this->debuginfo).
"'";
1540 $sql .=
" WHERE rowid = ".((int) $this->
id);
1541 $resql = $this->db->query($sql);
1543 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.");
1549 $stringtowrite =
'BLOCKEDLOGHEAD '.$this->id.
" ".
dol_print_date($this->date_creation,
'dayhourrfc',
'gmt').
" ".(
string) $finalsignature;
1553 if (empty($remoteobfuscationkey)) {
1554 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.");
1556 $stringtowriteencoded =
dolEncrypt($stringtowrite, $remoteobfuscationkey,
'',
'',
'dolobfuscationv1-'.
$mysoc->idprof1.
'-'.$this->id);
1558 $stringtowriteencoded =
dolEncrypt($stringtowrite,
'',
'',
'',
'dolcrypt-'.
$mysoc->idprof1.
'-'.$this->id);
1563 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1564 $lockhandle = fopen($lockfile,
'w+');
1566 if (fwrite($lockhandle, $stringtowriteencoded.
"\n") ===
false) {
1567 throw new Exception(
"Cannot write to the blockedlog .end file ".$lockfile);
1570 fclose($lockhandle);
1573 throw new Exception(
"Cannot open for writing the blockedlog .end file ".$lockfile);
1576 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1577 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1578 $resql = $this->db->query($sql);
1580 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name, value, type, visible, note, entity)";
1581 $sql .=
" VALUES('".$this->db->escape(basename($lockfile)).
"', '".$this->db->escape($stringtowriteencoded).
"', 'chaine', 0, 'Blockedlog end of chain flag', ".((int)
$conf->entity).
")";
1582 $resql = $this->db->query($sql);
1584 throw new Exception(
"Cannot update the blockedlog .end flag ".basename($lockfile));
1588 $this->error = $e->getMessage();
1592 $this->db->rollback();
1596 $this->db->commit();
1618 $this->db->rollback();
1622 $this->error = $this->db->error();
1623 $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 = ".
$conf->entity;
2233 } elseif ($element ==
'not_certified') {
2234 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2235 WHERE entity = ".
$conf->entity.
" AND certified = 0";
2236 } elseif ($element ==
'just_certified') {
2237 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2238 WHERE entity = ".
$conf->entity.
" AND certified = 1";
2240 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2241 WHERE entity = ".
$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 $tmp =
natural_search(
"module_source", implode(
',', $search_module_source), 0, 1);
2295 $tmp = str_replace(
'%backoffice%',
'', $tmp);
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;