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(
642 $arrayoffieldstoexclude,
644 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
645 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
646 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
647 'extraparams',
'fk_incoterms',
'fk_user_creat',
'fk_user_valid',
'label_incoterms',
'location_incoterms',
'lines',
'nb',
'tms',
'comments',
'array_options',
'warnings',
648 'opening',
'status',
'date_valid'
654 $addthirdpartyatpaymentlevel = 0;
655 if (!empty(
$object->thirdparty) && in_array($this->element, array(
'payment',
'payment_supplier'))) {
656 $addthirdpartyatpaymentlevel = 1;
659 if (!empty(
$object->thirdparty) && !$addthirdpartyatpaymentlevel) {
660 $this->object_data->thirdparty =
new stdClass();
662 foreach (
$object->thirdparty as $key => $value) {
663 if (in_array($key, $arrayoffieldstoexclude)) {
667 if (!in_array($key, array(
668 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
669 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
674 $valuequalifiedforstorage =
false;
675 if (!is_object($value)) {
676 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
677 $valuequalifiedforstorage =
true;
680 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
681 $valuequalifiedforstorage =
true;
683 if (!is_null($value) && (
string) $value !==
'') {
684 $valuequalifiedforstorage =
true;
688 if ($valuequalifiedforstorage) {
689 $this->object_data->thirdparty->$key = $value;
695 if (!empty(
$mysoc) && in_array(
$object->element, array(
'facture',
'paiement'))) {
696 $this->object_data->mycompany =
new stdClass();
698 foreach (
$mysoc as $key => $value) {
699 if (in_array($key, $arrayoffieldstoexclude)) {
703 if (!in_array($key, array(
704 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
705 'tva_assuj',
'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
710 $valuequalifiedforstorage =
false;
711 if (!is_object($value)) {
712 if (empty($value) && in_array($key, array(
'country_code',
'idprof1',
'idprof2',
'tva_intra'))) {
713 $valuequalifiedforstorage =
true;
716 if (!is_null($value) && empty($value) && in_array($key, array(
'tva_assuj',
'localtax1_assuj',
'localtax2_assuj'))) {
717 $valuequalifiedforstorage =
true;
719 if (!is_null($value) && (
string) $value !==
'') {
720 $valuequalifiedforstorage =
true;
724 if ($valuequalifiedforstorage) {
725 $this->object_data->mycompany->$key = $value;
732 $this->fk_user = $user->id;
733 $this->user_fullname = $user->getFullName($langs);
737 if ($this->element ==
'facture') {
738 '@phan-var-force Facture $object';
742 foreach (
$object as $key => $value) {
743 if (in_array($key, $arrayoffieldstoexclude)) {
747 if (!in_array($key, array(
748 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
750 'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
751 'revenuestamp',
'datepointoftax',
'note_public',
753 'module_source',
'pos_source',
'pos_print_counter',
'email_sent_counter'
757 if ($key ==
'lines') {
759 foreach ($value as $tmpline) {
761 foreach ($tmpline as $keyline => $valueline) {
762 if (!in_array($keyline, array(
763 'ref',
'product_type',
'product_label',
765 'vat_src_code',
'tva_tx',
'localtax1_tx',
'localtax2_tx',
766 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
767 'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
768 'info_bits',
'special_code',
'remise_percent'
773 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
774 $this->object_data->invoiceline[$lineid] =
new stdClass();
777 $valuequalifiedforstorage =
false;
778 if (!is_object($valueline)) {
779 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'))) {
780 $valuequalifiedforstorage =
true;
782 if (!is_null($valueline) && (
string) $valueline !==
'') {
783 $valuequalifiedforstorage =
true;
786 if ($keyline ==
'product_label' && empty($valueline)) {
788 $valuequalifiedforstorage =
true;
791 if ($valuequalifiedforstorage) {
792 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
797 $valuequalifiedforstorage =
false;
798 if (!is_object($value)) {
799 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
800 $valuequalifiedforstorage =
true;
803 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
804 $valuequalifiedforstorage =
true;
806 if (!is_null($value) && (
string) $value !==
'') {
807 $valuequalifiedforstorage =
true;
811 if ($valuequalifiedforstorage) {
812 $this->object_data->$key = $value;
818 $this->object_data->ref =
$object->newref;
822 if ($action ==
'BILL_SENTBYMAIL') {
823 $this->object_data->action_email_sent = array(
824 "email_from" =>
$object->context[
'email_from'],
825 "email_to" =>
$object->context[
'email_to'],
826 "email_msgid" =>
$object->context[
'email_msgid']
829 } elseif ($this->element ==
'invoice_supplier') {
830 '@phan-var-force FactureFournisseur $object';
831 foreach (
$object as $key => $value) {
832 if (in_array($key, $arrayoffieldstoexclude)) {
836 if (!in_array($key, array(
837 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
842 $valuequalifiedforstorage =
false;
843 if (!is_object($value)) {
844 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
845 $valuequalifiedforstorage =
true;
848 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
849 $valuequalifiedforstorage =
true;
851 if (!is_null($value) && (
string) $value !==
'') {
852 $valuequalifiedforstorage =
true;
856 if ($valuequalifiedforstorage) {
857 $this->object_data->$key = $value;
862 $this->object_data->ref =
$object->newref;
864 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
865 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
869 $this->object_data->ref =
$object->ref;
870 $this->object_data->date = $datepayment;
871 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
873 if (!empty(
$object->num_payment)) {
874 $this->object_data->payment_num =
$object->num_payment;
876 if (!empty(
$object->note_private)) {
877 $this->object_data->note_private =
$object->note_private;
884 $this->type_code = $this->object_data->type_code;
885 $this->linktype = $this->element;
886 $this->linktoref =
'';
890 $amountsarray =
$object->getAmountsArray();
891 $object->amounts = $amountsarray;
893 if ($action ==
'PAYMENT_CUSTOMER_DELETE') {
894 foreach (
$object->amounts as $amountkey => $amountval) {
895 $object->amounts[$amountkey] = - $amountval;
903 $originofpayment =
null;
904 $terminalofpayment =
null;
905 $paymentpartnumber = 0;
906 foreach (
$object->amounts as $objid => $amount) {
907 if (empty($amount)) {
911 $totalamount += $amount;
914 if ($this->element ==
'payment_supplier') {
915 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
917 } elseif ($this->element ==
'payment') {
918 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
919 $tmpobject =
new Facture($this->db);
920 } elseif ($this->element ==
'payment_donation') {
921 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
922 $tmpobject =
new Don($this->db);
923 } elseif ($this->element ==
'payment_various') {
924 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
928 if (!is_object($tmpobject)) {
932 $result = $tmpobject->fetch($objid);
935 $this->error = $tmpobject->error;
936 $this->errors = $tmpobject->errors;
937 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
941 $this->linktoref .= ($this->linktoref ?
',' :
'').$tmpobject->ref;
944 if (property_exists($tmpobject,
'module_source')) {
945 if (is_null($originofpayment)) {
946 $originofpayment = (
string) $tmpobject->module_source;
947 } elseif ($originofpayment != $tmpobject->module_source) {
948 $originofpayment =
'mix';
950 $originofpayment = (
string) $tmpobject->module_source;
954 if (property_exists($tmpobject,
'pos_source')) {
955 if (is_null($terminalofpayment)) {
956 $terminalofpayment = (
string) $tmpobject->pos_source;
957 } elseif ($terminalofpayment != $tmpobject->pos_source) {
958 $terminalofpayment =
'mix';
960 $terminalofpayment = (
string) $tmpobject->pos_source;
964 $paymentpart->amount = $amount;
968 if ($addthirdpartyatpaymentlevel) {
969 $result = $tmpobject->fetch_thirdparty();
971 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
972 $this->errors[] = $this->error;
973 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
975 } elseif ($result < 0) {
976 $this->error = $tmpobject->error;
977 $this->errors = $tmpobject->errors;
981 $paymentpart->thirdparty =
new stdClass();
982 foreach ($tmpobject->thirdparty as $key => $value) {
983 if (in_array($key, $arrayoffieldstoexclude)) {
987 if (!in_array($key, array(
988 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
989 'tva_intra',
'tva_assuj',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
993 if (!is_object($value) && !is_null($value) && $value !==
'') {
994 $paymentpart->thirdparty->$key = $value;
1000 if ($this->element ==
'payment_donation') {
1001 $paymentpart->donation =
new stdClass();
1002 } elseif ($this->element ==
'payment_various') {
1003 $paymentpart->various =
new stdClass();
1005 $paymentpart->invoice =
new stdClass();
1008 if ($this->element !=
'payment_various') {
1009 foreach ($tmpobject as $key => $value) {
1010 if (in_array($key, $arrayoffieldstoexclude)) {
1014 if (!in_array($key, array(
1015 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
1016 'pos_source',
'module_source',
'pos_print_counter',
'email_sent_counter'
1021 $valuequalifiedforstorage =
false;
1022 if (!is_object($value)) {
1023 if (empty($value) && in_array($key, array(
'pos_source',
'module_source'))) {
1024 $valuequalifiedforstorage =
true;
1025 $value = (
string) $value;
1027 if (!is_null($value) && empty($value) && in_array($key, array(
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'pos_print_counter',
'email_sent_counter'))) {
1028 $valuequalifiedforstorage =
true;
1030 if (!is_null($value) && (
string) $value !==
'') {
1031 $valuequalifiedforstorage =
true;
1035 if ($valuequalifiedforstorage) {
1036 if ($this->element ==
'payment_donation') {
1037 $paymentpart->donation->$key = $value;
1038 } elseif ($this->element ==
'payment_various') {
1039 $paymentpart->various->$key = $value;
1041 $paymentpart->invoice->$key = $value;
1046 $paymentpartnumber++;
1047 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
1051 $this->module_source = (
string) $originofpayment;
1052 $this->pos_source = (
string) $terminalofpayment;
1053 } elseif (!empty(
$object->amount)) {
1054 $totalamount =
$object->amount;
1057 $this->object_data->amount = $totalamount;
1059 if (!empty(
$object->newref)) {
1060 $this->object_data->ref =
$object->newref;
1062 } elseif ($this->element ==
'payment_salary') {
1063 '@phan-var-force PaymentSalary $object';
1064 $this->object_data->amounts = array(
$object->amount);
1066 if (!empty(
$object->newref)) {
1067 $this->object_data->ref =
$object->newref;
1069 } elseif ($this->element ==
'subscription') {
1070 '@phan-var-force Subscription $object';
1071 foreach (
$object as $key => $value) {
1072 if (in_array($key, $arrayoffieldstoexclude)) {
1075 if (!in_array($key, array(
1076 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
1080 if (!is_object($value) && !is_null($value) && $value !==
'') {
1081 $this->object_data->$key = $value;
1085 if (!empty(
$object->newref)) {
1086 $this->object_data->ref =
$object->newref;
1088 } elseif ($this->element ==
'stockmouvement') {
1089 '@phan-var-force StockTransfer $object';
1090 foreach (
$object as $key => $value) {
1091 if (in_array($key, $arrayoffieldstoexclude)) {
1094 if (!is_object($value) && !is_null($value) && $value !==
'') {
1095 $this->object_data->$key = $value;
1099 if (
$object->element ==
'cashcontrol') {
1105 foreach (
$object as $key => $value) {
1106 if (in_array($key, $arrayoffieldstoexclude)) {
1109 if (!is_object($value) && !is_null($value) && $value !==
'') {
1110 $this->object_data->$key = $value;
1114 if (
$object->element ==
'cashcontrol') {
1115 $period =
$object->year_close;
1116 $period .= (
$object->month_close ?
"-".sprintf(
"%02d",
$object->month_close) :
"");
1117 $period .= (
$object->day_close ?
"-".sprintf(
"%02d",
$object->day_close) :
"");
1119 $this->object_data->period = $period;
1122 if (!empty(
$object->newref)) {
1123 $this->object_data->ref =
$object->newref;
1129 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
1276 public function create($user, $forcesignature =
'')
1280 $langs->load(
'blockedlog');
1283 $this->amounts = (float) $this->amounts;
1285 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
1288 if (!isset($this->amounts)) {
1289 $langs->load(
"errors");
1290 $this->error = $langs->trans(
"ErrorBlockLogNeedAmountsValue");
1295 if (empty($this->element)) {
1296 $langs->load(
"errors");
1297 $this->error = $langs->trans(
"ErrorBlockLogNeedElement");
1302 if (empty($this->object_data)) {
1303 $langs->load(
"errors");
1304 $this->error = $langs->trans(
"ErrorBlockLogNeedObject");
1309 if (empty($this->action)) {
1310 $langs->load(
"errors");
1311 $this->error = $langs->trans(
"ErrorBadParameterWhenCallingCreateOfBlockedLog");
1315 if (empty($this->fk_user)) {
1316 $this->user_fullname =
'(Anonymous)';
1319 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
1323 $this->date_creation =
dol_now();
1325 $this->object_version = DOL_VERSION;
1330 $this->object_format =
'V2';
1336 $previousdatecreation = 0;
1341 $previoushash = $tmparray[
'previoushash'];
1342 $previousid = $tmparray[
'previousid'];
1343 $previousdatecreation = $tmparray[
'previousdatecreation'];
1353 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1356 $this->error = $e->getMessage();
1360 $this->db->rollback();
1364 if ($forcesignature) {
1365 $this->signature = $forcesignature;
1369 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
1370 $sql .=
" date_creation,";
1372 $sql .=
" module_source,";
1373 $sql .=
" pos_source,";
1374 $sql .=
" amounts_taxexcl,";
1375 $sql .=
" amounts,";
1376 $sql .=
" signature,";
1377 $sql .=
" element,";
1378 $sql .=
" fk_object,";
1379 $sql .=
" date_object,";
1380 $sql .=
" ref_object,";
1381 $sql .=
" type_code,";
1382 $sql .=
" linktoref,";
1383 $sql .=
" linktype,";
1384 $sql .=
" object_data,";
1385 $sql .=
" object_version,";
1386 $sql .=
" object_format,";
1387 $sql .=
" certified,";
1388 $sql .=
" fk_user,";
1389 $sql .=
" user_fullname,";
1391 $sql .=
" debuginfo";
1392 $sql .=
") VALUES (";
1393 $sql .=
"'".$this->db->idate($this->date_creation, $tz).
"',";
1394 $sql .=
"'".$this->db->escape($this->action).
"',";
1395 $sql .=
"'".$this->db->escape((
string) $this->module_source).
"',";
1396 $sql .=
"'".$this->db->escape((
string) $this->pos_source).
"',";
1397 $sql .= (is_null($this->amounts_taxexcl) ?
"null" : (float) $this->amounts_taxexcl).
",";
1398 $sql .= (float) $this->amounts.
",";
1399 $sql .=
"'".$this->db->escape($this->signature).
"',";
1400 $sql .=
"'".$this->db->escape($this->element).
"',";
1401 $sql .= (int) $this->fk_object.
",";
1402 $sql .=
"'".$this->db->idate($this->date_object, $tz).
"',";
1403 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
1404 $sql .=
"'".$this->db->escape($this->type_code).
"',";
1405 $sql .= ($this->linktoref ?
"'".$this->db->escape($this->linktoref).
"'" :
"null").
",";
1406 $sql .= ($this->linktype ?
"'".$this->db->escape($this->linktype).
"'" :
"null").
",";
1408 $sql .=
"'".$this->db->escape($this->object_version).
"',";
1409 $sql .=
"'".$this->db->escape($this->object_format).
"',";
1411 $sql .= ((int) $this->fk_user).
",";
1412 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
1413 $sql .= ((int) ($this->entity ? $this->entity :
$conf->entity)).
",";
1414 $sql .=
"'".$this->db->escape($this->debuginfo).
"'";
1425 $res = $this->db->query($sql);
1427 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1435 $finalsignature = $this->signature;
1442 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1445 if (!file_exists($lockfile)) {
1448 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1455 $finalnote = $this->note;
1458 } elseif (is_writable($lockfile)) {
1459 $line = file_get_contents($lockfile);
1462 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.');
1465 $sql =
"SELECT value from ".MAIN_DB_PREFIX.
"const";
1466 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1467 $resql = $this->db->query($sql);
1469 $obj = $this->db->fetch_object($resql);
1471 $line = $obj->value;
1475 $this->note =
'EndOfChainDeletionDetected [after '.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
']';
1482 $finalnote = $this->note;
1488 throw new Exception(
"Cannot read into the blockedlog .end flag ".basename($lockfile).
' to update it. Transaction aborted.');
1494 $remoteobfuscationkey =
'';
1495 if (preg_match(
'/^dolcrypt/', $line)) {
1497 } elseif (preg_match(
'/^dolobfuscation/', $line)) {
1499 if (empty($remoteobfuscationkey)) {
1500 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.");
1502 $headstring =
dolDecrypt($line, $remoteobfuscationkey);
1506 if (preg_match(
'/^BLOCKEDLOGHEAD (\d+) ([^\s]+) ([a-zA-Z0-9\-]+)/', $headstring, $reg)) {
1508 $previousidheadflag = $reg[1];
1509 $previousdatecreationheadflag = $reg[2];
1510 $previoushashheadflag = $reg[3];
1513 if ($previousid < $previousidheadflag || $previoushash != $previoushashheadflag) {
1515 $this->note =
'EndOfChainDeletionDetected ['.dol_print_date($previousdatecreation,
'dayhourrfc',
'gmt').
' - '.
dol_print_date($previousdatecreationheadflag,
'dayhourrfc',
'gmt').
']';
1522 $finalnote = $this->note;
1524 } elseif ($headstring !=
'') {
1526 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.");
1530 if ($finalsignature != $this->signature) {
1533 $this->debuginfo =
'previoushash='.$previoushash.
' concatenateddatafirstpart='.$this->
buildFirstPartOfKeyForSignature().
' => signature='.$this->signature;
1537 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"blockedlog";
1538 $sql .=
" SET signature = '".$this->db->escape($finalsignature).
"',";
1539 $sql .=
" note = '".$this->db->escape($finalnote).
"',";
1540 $sql .=
" debuginfo = '".$this->db->escape($this->debuginfo).
"'";
1541 $sql .=
" WHERE rowid = ".((int) $this->
id);
1542 $resql = $this->db->query($sql);
1544 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.");
1550 $stringtowrite =
'BLOCKEDLOGHEAD '.$this->id.
" ".
dol_print_date($this->date_creation,
'dayhourrfc',
'gmt').
" ".(
string) $finalsignature;
1554 if (empty($remoteobfuscationkey)) {
1555 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.");
1557 $stringtowriteencoded =
dolEncrypt($stringtowrite, $remoteobfuscationkey,
'',
'',
'dolobfuscationv1-'.
$mysoc->idprof1.
'-'.$this->id);
1559 $stringtowriteencoded =
dolEncrypt($stringtowrite,
'',
'',
'',
'dolcrypt-'.
$mysoc->idprof1.
'-'.$this->id);
1564 if (defined(
'BLOCKEDLOG_END_FLAG_IN_A_FILE')) {
1565 $lockhandle = fopen($lockfile,
'w+');
1567 if (fwrite($lockhandle, $stringtowriteencoded.
"\n") ===
false) {
1568 throw new Exception(
"Cannot write to the blockedlog .end file ".$lockfile);
1571 fclose($lockhandle);
1574 throw new Exception(
"Cannot open for writing the blockedlog .end file ".$lockfile);
1577 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"const";
1578 $sql .=
" WHERE name = '".$this->db->escape(basename($lockfile)).
"' AND entity = ".((int)
$conf->entity);
1579 $resql = $this->db->query($sql);
1581 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"const(name, value, type, visible, note, entity)";
1582 $sql .=
" VALUES('".$this->db->escape(basename($lockfile)).
"', '".$this->db->escape($stringtowriteencoded).
"', 'chaine', 0, 'Blockedlog end of chain flag', ".((int)
$conf->entity).
")";
1583 $resql = $this->db->query($sql);
1585 throw new Exception(
"Cannot update the blockedlog .end flag ".basename($lockfile));
1589 $this->error = $e->getMessage();
1593 $this->db->rollback();
1597 $this->db->commit();
1619 $this->db->rollback();
1623 $this->error = $this->db->error();
1624 $this->db->rollback();
2221 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 =
'')
2229 if ($element ==
'all') {
2230 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2231 WHERE entity = ".
$conf->entity;
2232 } elseif ($element ==
'not_certified') {
2233 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2234 WHERE entity = ".
$conf->entity.
" AND certified = 0";
2235 } elseif ($element ==
'just_certified') {
2236 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2237 WHERE entity = ".
$conf->entity.
" AND certified = 1";
2239 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"blockedlog
2240 WHERE entity = ".
$conf->entity.
" AND element = '".$this->db->escape($element).
"'";
2246 if ($search_fk_user > 0) {
2249 if ($search_start > 0) {
2250 $sql .=
" AND date_creation >= '".$this->db->idate($search_start,
'gmt').
"'";
2252 if ($search_end > 0) {
2253 $sql .=
" AND date_creation <= '".$this->db->idate($search_end,
'gmt').
"'";
2255 if ($search_type_code) {
2258 if ($search_ref !=
'') {
2259 $sql .=
" AND (".natural_search(
"ref_object", $search_ref, 0, 1);
2260 $sql .=
" OR ".natural_search(
"linktoref", $search_ref, 0, 1).
")";
2262 if ($search_amount !=
'') {
2265 if ($search_signature !=
'') {
2268 if (is_array($search_code)) {
2269 if (!empty($search_code)) {
2270 if (in_array(
'PAYMENT_CUSTOMER', $search_code)) {
2271 $search_code[] =
'PAYMENT_CUSTOMER_CREATE';
2272 $search_code[] =
'PAYMENT_CUSTOMER_DELETE';
2278 if ($search_code !=
'' && $search_code !=
'-1') {
2282 if (is_array($search_module_source)) {
2283 if (!empty($search_module_source)) {
2285 if (in_array(
'0', $search_module_source)) {
2286 $sql .=
"module_source = ''";
2287 unset($search_module_source[0]);
2288 if (!empty($search_module_source)) {
2292 if (!empty($search_module_source)) {
2293 $tmp =
natural_search(
"module_source", implode(
',', $search_module_source), 0, 1);
2294 $tmp = str_replace(
'%backoffice%',
'', $tmp);
2297 $sql .=
" OR module_source = 'mix'";
2301 if ($search_module_source !=
'' && $search_module_source !=
'-1') {
2302 $sql .=
natural_search(
"module_source", $search_module_source, 3);
2305 if ($search_pos_source !=
'') {
2308 $sql .=
" OR pos_source = 'mix'";
2312 $sql .= $this->db->order($sortfield, $sortorder);
2313 $sql .= $this->db->plimit($limit + 1);
2315 $res = $this->db->query($sql);
2320 while ($obj = $this->db->fetch_object($res)) {
2330 $result = $b->fetch($obj->rowid);
2337 $this->error = $b->error;
2338 $this->errors = $b->errors;