| Conditions | 126 |
| Paths | 4902 |
| Total Lines | 697 |
| Code Lines | 570 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 615 | public function send($notifcode, $object, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array()) |
||
| 616 | { |
||
| 617 | global $user, $conf, $langs, $mysoc; |
||
| 618 | global $hookmanager; |
||
| 619 | global $dolibarr_main_url_root; |
||
| 620 | global $action; |
||
| 621 | |||
| 622 | // Complete the array Notify::$arrayofnotifsupported |
||
| 623 | if (!is_object($hookmanager)) { |
||
| 624 | $hookmanager = new HookManager($this->db); |
||
| 625 | } |
||
| 626 | $hookmanager->initHooks(array('notification')); |
||
| 627 | |||
| 628 | $parameters = array('notifcode' => $notifcode); |
||
| 629 | $reshook = $hookmanager->executeHooks('notifsupported', $parameters, $object, $action); |
||
| 630 | if (empty($reshook)) { |
||
| 631 | if (!empty($hookmanager->resArray['arrayofnotifsupported'])) { |
||
| 632 | Notify::$arrayofnotifsupported = array_merge(Notify::$arrayofnotifsupported, $hookmanager->resArray['arrayofnotifsupported']); |
||
| 633 | } |
||
| 634 | } |
||
| 635 | |||
| 636 | // If the trigger code is not managed by the Notification module |
||
| 637 | if (!in_array($notifcode, Notify::$arrayofnotifsupported)) { |
||
| 638 | return 0; |
||
| 639 | } |
||
| 640 | |||
| 641 | include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; |
||
| 642 | |||
| 643 | dol_syslog(get_class($this) . "::send notifcode=" . $notifcode . ", object id=" . $object->id); |
||
| 644 | |||
| 645 | $langs->load("other"); |
||
| 646 | |||
| 647 | // Define $urlwithroot |
||
| 648 | $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_URL_ROOT, '/') . '$/i', '', trim($dolibarr_main_url_root)); |
||
| 649 | $urlwithroot = $urlwithouturlroot . DOL_URL_ROOT; // This is to use external domain name found into config file |
||
| 650 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
||
| 651 | |||
| 652 | // Define some vars |
||
| 653 | $application = 'Dolibarr'; |
||
| 654 | if (getDolGlobalString('MAIN_APPLICATION_TITLE')) { |
||
| 655 | $application = getDolGlobalString('MAIN_APPLICATION_TITLE'); |
||
| 656 | } |
||
| 657 | $from = getDolGlobalString('NOTIFICATION_EMAIL_FROM'); |
||
| 658 | $object_type = ''; |
||
| 659 | $link = ''; |
||
| 660 | $num = 0; |
||
| 661 | $error = 0; |
||
| 662 | |||
| 663 | $oldref = (empty($object->oldref) ? $object->ref : $object->oldref); |
||
| 664 | $newref = (empty($object->newref) ? $object->ref : $object->newref); |
||
| 665 | |||
| 666 | $sql = ''; |
||
| 667 | |||
| 668 | // Check notification per third party |
||
| 669 | if (!empty($object->socid) && $object->socid > 0) { |
||
| 670 | $sql .= "SELECT 'tocontactid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; |
||
| 671 | $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type"; |
||
| 672 | $sql .= " FROM " . $this->db->prefix() . "socpeople as c,"; |
||
| 673 | $sql .= " " . $this->db->prefix() . "c_action_trigger as a,"; |
||
| 674 | $sql .= " " . $this->db->prefix() . "notify_def as n,"; |
||
| 675 | $sql .= " " . $this->db->prefix() . "societe as s"; |
||
| 676 | $sql .= " WHERE n.fk_contact = c.rowid AND a.rowid = n.fk_action"; |
||
| 677 | $sql .= " AND n.fk_soc = s.rowid"; |
||
| 678 | $sql .= " AND c.statut = 1"; |
||
| 679 | if (is_numeric($notifcode)) { |
||
| 680 | $sql .= " AND n.fk_action = " . ((int) $notifcode); // Old usage |
||
| 681 | } else { |
||
| 682 | $sql .= " AND a.code = '" . $this->db->escape($notifcode) . "'"; // New usage |
||
| 683 | } |
||
| 684 | $sql .= " AND s.rowid = " . ((int) $object->socid); |
||
| 685 | |||
| 686 | $sql .= "\nUNION\n"; |
||
| 687 | } |
||
| 688 | |||
| 689 | // Check notification per user |
||
| 690 | $sql .= "SELECT 'touserid' as type_target, c.email, c.rowid as cid, c.lastname, c.firstname, c.lang as default_lang,"; |
||
| 691 | $sql .= " a.rowid as adid, a.label, a.code, n.rowid, n.threshold, n.context, n.type"; |
||
| 692 | $sql .= " FROM " . $this->db->prefix() . "user as c,"; |
||
| 693 | $sql .= " " . $this->db->prefix() . "c_action_trigger as a,"; |
||
| 694 | $sql .= " " . $this->db->prefix() . "notify_def as n"; |
||
| 695 | $sql .= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; |
||
| 696 | $sql .= " AND c.statut = 1"; |
||
| 697 | if (is_numeric($notifcode)) { |
||
| 698 | $sql .= " AND n.fk_action = " . ((int) $notifcode); // Old usage |
||
| 699 | } else { |
||
| 700 | $sql .= " AND a.code = '" . $this->db->escape($notifcode) . "'"; // New usage |
||
| 701 | } |
||
| 702 | |||
| 703 | // Check notification fixed |
||
| 704 | // TODO Move part found after, into a sql here |
||
| 705 | |||
| 706 | |||
| 707 | // Loop on all notifications enabled |
||
| 708 | $result = $this->db->query($sql); |
||
| 709 | if ($result) { |
||
| 710 | $num = $this->db->num_rows($result); |
||
| 711 | $projtitle = ''; |
||
| 712 | if (is_object($object->project) || $object->fetch_project() > 0) { |
||
| 713 | $projtitle = '(' . $object->project->title . ')'; |
||
| 714 | } |
||
| 715 | |||
| 716 | if ($num > 0) { |
||
| 717 | $i = 0; |
||
| 718 | while ($i < $num && !$error) { // For each notification couple defined (third party/actioncode) |
||
| 719 | $obj = $this->db->fetch_object($result); |
||
| 720 | |||
| 721 | $sendto = dolGetFirstLastname($obj->firstname, $obj->lastname) . " <" . $obj->email . ">"; |
||
| 722 | $notifcodedefid = $obj->adid; |
||
| 723 | $trackid = ''; |
||
| 724 | if ($obj->type_target == 'tocontactid') { |
||
| 725 | $trackid = 'ctc' . $obj->cid; |
||
| 726 | } |
||
| 727 | if ($obj->type_target == 'touserid') { |
||
| 728 | $trackid = 'use' . $obj->cid; |
||
| 729 | } |
||
| 730 | |||
| 731 | if (dol_strlen($obj->email)) { |
||
| 732 | // Set output language |
||
| 733 | $outputlangs = $langs; |
||
| 734 | if ($obj->default_lang && $obj->default_lang != $langs->defaultlang) { |
||
| 735 | $outputlangs = new Translate('', $conf); |
||
| 736 | $outputlangs->setDefaultLang($obj->default_lang); |
||
| 737 | $outputlangs->loadLangs(array("main", "other")); |
||
| 738 | } |
||
| 739 | |||
| 740 | $appli = $mysoc->name; |
||
| 741 | |||
| 742 | $subject = '[' . $appli . '] ' . $outputlangs->transnoentitiesnoconv("DolibarrNotification") . ($projtitle ? ' ' . $projtitle : ''); |
||
| 743 | |||
| 744 | switch ($notifcode) { |
||
| 745 | case 'BILL_CANCEL': |
||
| 746 | $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 747 | $dir_output = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
||
| 748 | $object_type = 'facture'; |
||
| 749 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceCanceled", $link); |
||
| 750 | break; |
||
| 751 | case 'BILL_VALIDATE': |
||
| 752 | $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 753 | $dir_output = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
||
| 754 | $object_type = 'facture'; |
||
| 755 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link); |
||
| 756 | break; |
||
| 757 | case 'BILL_PAYED': |
||
| 758 | $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 759 | $dir_output = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
||
| 760 | $object_type = 'facture'; |
||
| 761 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInvoicePayed", $link); |
||
| 762 | break; |
||
| 763 | case 'ORDER_CANCEL': |
||
| 764 | $link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 765 | $dir_output = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
||
| 766 | $object_type = 'order'; |
||
| 767 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderCanceled", $link); |
||
| 768 | break; |
||
| 769 | case 'ORDER_VALIDATE': |
||
| 770 | $link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 771 | $dir_output = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
||
| 772 | $object_type = 'order'; |
||
| 773 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderValidated", $link); |
||
| 774 | break; |
||
| 775 | case 'ORDER_CLOSE': |
||
| 776 | $link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 777 | $dir_output = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
||
| 778 | $object_type = 'order'; |
||
| 779 | $labeltouse = getDolGlobalString('ORDER_CLOSE_TEMPLATE'); |
||
| 780 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextOrderClose", $link); |
||
| 781 | break; |
||
| 782 | case 'PROPAL_VALIDATE': |
||
| 783 | $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 784 | $dir_output = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
||
| 785 | $object_type = 'propal'; |
||
| 786 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalValidated", $link); |
||
| 787 | break; |
||
| 788 | case 'PROPAL_CLOSE_REFUSED': |
||
| 789 | $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 790 | $dir_output = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
||
| 791 | $object_type = 'propal'; |
||
| 792 | $labeltouse = getDolGlobalString('PROPAL_CLOSE_REFUSED_TEMPLATE'); |
||
| 793 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedRefused", $link); |
||
| 794 | if (!empty($object->context['closedfromonlinesignature'])) { |
||
| 795 | $mesg .= ' - From online page'; |
||
| 796 | } |
||
| 797 | break; |
||
| 798 | case 'PROPAL_CLOSE_SIGNED': |
||
| 799 | $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 800 | $dir_output = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
||
| 801 | $object_type = 'propal'; |
||
| 802 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link); |
||
| 803 | if (!empty($object->context['closedfromonlinesignature'])) { |
||
| 804 | $mesg .= ' - From online page'; |
||
| 805 | } |
||
| 806 | break; |
||
| 807 | case 'FICHINTER_ADD_CONTACT': |
||
| 808 | $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 809 | $dir_output = $conf->ficheinter->dir_output; |
||
| 810 | $object_type = 'ficheinter'; |
||
| 811 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link); |
||
| 812 | break; |
||
| 813 | case 'FICHINTER_VALIDATE': |
||
| 814 | $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 815 | $dir_output = $conf->ficheinter->dir_output; |
||
| 816 | $object_type = 'ficheinter'; |
||
| 817 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionValidated", $link); |
||
| 818 | break; |
||
| 819 | case 'FICHINTER_CLOSE': |
||
| 820 | $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 821 | $dir_output = $conf->ficheinter->dir_output; |
||
| 822 | $object_type = 'ficheinter'; |
||
| 823 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextInterventionClosed", $link); |
||
| 824 | break; |
||
| 825 | case 'ORDER_SUPPLIER_VALIDATE': |
||
| 826 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 827 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 828 | $object_type = 'order_supplier'; |
||
| 829 | $labeltouse = isset($conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_VALIDATE_TEMPLATE : ''; |
||
| 830 | $mesg = $outputlangs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 831 | $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($outputlangs)); |
||
| 832 | $mesg .= "\n\n" . $outputlangs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 833 | break; |
||
| 834 | case 'ORDER_SUPPLIER_CANCEL': |
||
| 835 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 836 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 837 | $object_type = 'order_supplier'; |
||
| 838 | $mesg = $outputlangs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 839 | $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($outputlangs)); |
||
| 840 | $mesg .= "\n\n" . $outputlangs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 841 | break; |
||
| 842 | case 'ORDER_SUPPLIER_APPROVE': |
||
| 843 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 844 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 845 | $object_type = 'order_supplier'; |
||
| 846 | $labeltouse = isset($conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_APPROVE_TEMPLATE : ''; |
||
| 847 | $mesg = $outputlangs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 848 | $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($outputlangs)); |
||
| 849 | $mesg .= "\n\n" . $outputlangs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 850 | break; |
||
| 851 | case 'ORDER_SUPPLIER_SUBMIT': |
||
| 852 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 853 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 854 | $object_type = 'order_supplier'; |
||
| 855 | $mesg = $outputlangs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 856 | $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($outputlangs)); |
||
| 857 | $mesg .= "\n\n" . $outputlangs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 858 | break; |
||
| 859 | case 'ORDER_SUPPLIER_REFUSE': |
||
| 860 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 861 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 862 | $object_type = 'order_supplier'; |
||
| 863 | $labeltouse = isset($conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE) ? $conf->global->ORDER_SUPPLIER_REFUSE_TEMPLATE : ''; |
||
| 864 | $mesg = $outputlangs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 865 | $mesg .= $outputlangs->transnoentitiesnoconv("EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($outputlangs)); |
||
| 866 | $mesg .= "\n\n" . $outputlangs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 867 | break; |
||
| 868 | case 'SHIPPING_VALIDATE': |
||
| 869 | $link = '<a href="' . $urlwithroot . '/expedition/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 870 | $dir_output = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment'); |
||
| 871 | $object_type = 'shipping'; |
||
| 872 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link); |
||
| 873 | break; |
||
| 874 | case 'EXPENSE_REPORT_VALIDATE': |
||
| 875 | $link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 876 | $dir_output = $conf->expensereport->dir_output; |
||
| 877 | $object_type = 'expensereport'; |
||
| 878 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link); |
||
| 879 | break; |
||
| 880 | case 'EXPENSE_REPORT_APPROVE': |
||
| 881 | $link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 882 | $dir_output = $conf->expensereport->dir_output; |
||
| 883 | $object_type = 'expensereport'; |
||
| 884 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link); |
||
| 885 | break; |
||
| 886 | case 'HOLIDAY_VALIDATE': |
||
| 887 | $link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 888 | $dir_output = $conf->holiday->dir_output; |
||
| 889 | $object_type = 'holiday'; |
||
| 890 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayValidated", $link); |
||
| 891 | break; |
||
| 892 | case 'HOLIDAY_APPROVE': |
||
| 893 | $link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 894 | $dir_output = $conf->holiday->dir_output; |
||
| 895 | $object_type = 'holiday'; |
||
| 896 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextHolidayApproved", $link); |
||
| 897 | break; |
||
| 898 | case 'ACTION_CREATE': |
||
| 899 | $link = '<a href="' . $urlwithroot . '/comm/action/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 900 | $dir_output = $conf->agenda->dir_output; |
||
| 901 | $object_type = 'action'; |
||
| 902 | $mesg = $outputlangs->transnoentitiesnoconv("EMailTextActionAdded", $link); |
||
| 903 | break; |
||
| 904 | default: |
||
| 905 | $object_type = $object->element; |
||
| 906 | $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity] . "/" . get_exdir(0, 0, 0, 1, $object, $object_type); |
||
| 907 | $template = $notifcode . '_TEMPLATE'; |
||
| 908 | $mesg = $outputlangs->transnoentitiesnoconv('Notify_' . $notifcode) . ' ' . $newref . ' ' . $dir_output; |
||
| 909 | break; |
||
| 910 | } |
||
| 911 | |||
| 912 | $formmail = new FormMail($this->db); |
||
| 913 | $arraydefaultmessage = null; |
||
| 914 | |||
| 915 | $template = $notifcode . '_TEMPLATE'; |
||
| 916 | $labeltouse = getDolGlobalString($template); |
||
| 917 | if (!empty($labeltouse)) { |
||
| 918 | $arraydefaultmessage = $formmail->getEMailTemplate($this->db, $object_type . '_send', $user, $outputlangs, 0, 1, $labeltouse); |
||
| 919 | } |
||
| 920 | if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) { |
||
| 921 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
||
| 922 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 923 | $subject = make_substitutions($arraydefaultmessage->topic, $substitutionarray, $outputlangs); |
||
| 924 | $message = make_substitutions($arraydefaultmessage->content, $substitutionarray, $outputlangs); |
||
| 925 | } else { |
||
| 926 | $message = $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification", $application, $mysoc->name) . "\n"; |
||
| 927 | $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; |
||
| 928 | $message .= "\n"; |
||
| 929 | $message .= $mesg; |
||
| 930 | } |
||
| 931 | |||
| 932 | $ref = dol_sanitizeFileName($newref); |
||
| 933 | $pdf_path = $dir_output . "/" . $ref . ".pdf"; |
||
| 934 | if (!dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) { |
||
| 935 | // We can't add PDF as it is not generated yet. |
||
| 936 | $filepdf = ''; |
||
| 937 | } else { |
||
| 938 | $filepdf = $pdf_path; |
||
| 939 | $filename_list[] = $filepdf; |
||
| 940 | $mimetype_list[] = mime_content_type($filepdf); |
||
| 941 | $mimefilename_list[] = $ref . ".pdf"; |
||
| 942 | } |
||
| 943 | |||
| 944 | $labeltouse = !empty($labeltouse) ? $labeltouse : ''; |
||
| 945 | |||
| 946 | // Replace keyword __SUPERVISOREMAIL__ |
||
| 947 | if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) { |
||
| 948 | $newval = ''; |
||
| 949 | if ($user->fk_user > 0) { |
||
| 950 | $supervisoruser = new User($this->db); |
||
| 951 | $supervisoruser->fetch($user->fk_user); |
||
| 952 | if ($supervisoruser->email) { |
||
| 953 | $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname) . ' <' . $supervisoruser->email . '>'); |
||
| 954 | } |
||
| 955 | } |
||
| 956 | dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval); |
||
| 957 | $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
||
| 958 | $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid |
||
| 959 | $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string |
||
| 960 | $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string |
||
| 961 | } |
||
| 962 | |||
| 963 | $parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'from' => $from, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'outputlangs' => $outputlangs, 'labeltouse' => $labeltouse); |
||
| 964 | if (!isset($action)) { |
||
| 965 | $action = ''; |
||
| 966 | } |
||
| 967 | |||
| 968 | $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 969 | if (empty($reshook)) { |
||
| 970 | if (!empty($hookmanager->resArray['files'])) { |
||
| 971 | $filename_list = $hookmanager->resArray['files']['file']; |
||
| 972 | $mimetype_list = $hookmanager->resArray['files']['mimefile']; |
||
| 973 | $mimefilename_list = $hookmanager->resArray['files']['filename']; |
||
| 974 | } |
||
| 975 | if (!empty($hookmanager->resArray['subject'])) { |
||
| 976 | $subject .= $hookmanager->resArray['subject']; |
||
| 977 | } |
||
| 978 | if (!empty($hookmanager->resArray['message'])) { |
||
| 979 | $message .= $hookmanager->resArray['message']; |
||
| 980 | } |
||
| 981 | } |
||
| 982 | |||
| 983 | $mailfile = new CMailFile( |
||
| 984 | $subject, |
||
| 985 | $sendto, |
||
| 986 | $from, |
||
| 987 | $message, |
||
| 988 | $filename_list, |
||
| 989 | $mimetype_list, |
||
| 990 | $mimefilename_list, |
||
| 991 | '', |
||
| 992 | '', |
||
| 993 | 0, |
||
| 994 | -1, |
||
| 995 | '', |
||
| 996 | '', |
||
| 997 | $trackid, |
||
| 998 | '', |
||
| 999 | 'notification' |
||
| 1000 | ); |
||
| 1001 | |||
| 1002 | if ($mailfile->sendfile()) { |
||
| 1003 | if ($obj->type_target == 'touserid') { |
||
| 1004 | $sql = "INSERT INTO " . $this->db->prefix() . "notify (daten, fk_action, fk_soc, fk_user, type, objet_type, type_target, objet_id, email)"; |
||
| 1005 | $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . ((int) $notifcodedefid) . ", " . ($object->socid > 0 ? ((int) $object->socid) : 'null') . ", " . ((int) $obj->cid) . ", '" . $this->db->escape($obj->type) . "', '" . $this->db->escape($object_type) . "', '" . $this->db->escape($obj->type_target) . "', " . ((int) $object->id) . ", '" . $this->db->escape($obj->email) . "')"; |
||
| 1006 | } else { |
||
| 1007 | $sql = "INSERT INTO " . $this->db->prefix() . "notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, type_target, objet_id, email)"; |
||
| 1008 | $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . ((int) $notifcodedefid) . ", " . ($object->socid > 0 ? ((int) $object->socid) : 'null') . ", " . ((int) $obj->cid) . ", '" . $this->db->escape($obj->type) . "', '" . $this->db->escape($object_type) . "', '" . $this->db->escape($obj->type_target) . "', " . ((int) $object->id) . ", '" . $this->db->escape($obj->email) . "')"; |
||
| 1009 | } |
||
| 1010 | if (!$this->db->query($sql)) { |
||
| 1011 | dol_print_error($this->db); |
||
| 1012 | } |
||
| 1013 | } else { |
||
| 1014 | $error++; |
||
| 1015 | $this->errors[] = $mailfile->error; |
||
| 1016 | } |
||
| 1017 | } else { |
||
| 1018 | dol_syslog("No notification sent for " . $sendto . " because email is empty"); |
||
| 1019 | } |
||
| 1020 | $i++; |
||
| 1021 | } |
||
| 1022 | } else { |
||
| 1023 | dol_syslog("No notification to thirdparty sent, nothing into notification setup for the thirdparty socid = " . (empty($object->socid) ? '' : $object->socid)); |
||
| 1024 | } |
||
| 1025 | } else { |
||
| 1026 | $error++; |
||
| 1027 | $this->errors[] = $this->db->lasterror(); |
||
| 1028 | dol_syslog("Failed to get list of notification to send " . $this->db->lasterror(), LOG_ERR); |
||
| 1029 | return -1; |
||
| 1030 | } |
||
| 1031 | |||
| 1032 | // Check notification using fixed email |
||
| 1033 | // TODO Move vars NOTIFICATION_FIXEDEMAIL into table llx_notify_def and inclulde the case into previous loop of sql result |
||
| 1034 | if (!$error) { |
||
| 1035 | foreach ($conf->global as $key => $val) { |
||
| 1036 | $reg = array(); |
||
| 1037 | if ($val == '' || !preg_match('/^NOTIFICATION_FIXEDEMAIL_' . $notifcode . '_THRESHOLD_HIGHER_(.*)$/', $key, $reg)) { |
||
| 1038 | continue; |
||
| 1039 | } |
||
| 1040 | |||
| 1041 | $sendto = $val; |
||
| 1042 | |||
| 1043 | $threshold = (float) $reg[1]; |
||
| 1044 | if (!empty($object->total_ht) && $object->total_ht <= $threshold) { |
||
| 1045 | dol_syslog("A notification is requested for notifcode = " . $notifcode . " but amount = " . $object->total_ht . " so lower than threshold = " . $threshold . ". We discard this notification"); |
||
| 1046 | continue; |
||
| 1047 | } |
||
| 1048 | |||
| 1049 | $notifcodedefid = dol_getIdFromCode($this->db, $notifcode, 'c_action_trigger', 'code', 'rowid'); |
||
| 1050 | if ($notifcodedefid <= 0) { |
||
| 1051 | dol_print_error($this->db, 'Failed to get id from code'); |
||
| 1052 | } |
||
| 1053 | $trackid = ''; |
||
| 1054 | |||
| 1055 | $object_type = ''; |
||
| 1056 | $link = ''; |
||
| 1057 | $num++; |
||
| 1058 | |||
| 1059 | $appli = $mysoc->name; |
||
| 1060 | |||
| 1061 | $subject = '[' . $appli . '] ' . $langs->transnoentitiesnoconv("DolibarrNotification") . ($projtitle ? ' ' . $projtitle : ''); |
||
| 1062 | |||
| 1063 | switch ($notifcode) { |
||
| 1064 | case 'BILL_VALIDATE': |
||
| 1065 | $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1066 | $dir_output = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
||
| 1067 | $object_type = 'facture'; |
||
| 1068 | $mesg = $langs->transnoentitiesnoconv("EMailTextInvoiceValidated", $link); |
||
| 1069 | break; |
||
| 1070 | case 'BILL_PAYED': |
||
| 1071 | $link = '<a href="' . $urlwithroot . '/compta/facture/card.php?facid=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1072 | $dir_output = $conf->facture->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'invoice'); |
||
| 1073 | $object_type = 'facture'; |
||
| 1074 | $mesg = $langs->transnoentitiesnoconv("EMailTextInvoicePayed", $link); |
||
| 1075 | break; |
||
| 1076 | case 'ORDER_VALIDATE': |
||
| 1077 | $link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1078 | $dir_output = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
||
| 1079 | $object_type = 'order'; |
||
| 1080 | $mesg = $langs->transnoentitiesnoconv("EMailTextOrderValidated", $link); |
||
| 1081 | break; |
||
| 1082 | case 'ORDER_CLOSE': |
||
| 1083 | $link = '<a href="' . $urlwithroot . '/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1084 | $dir_output = $conf->commande->dir_output . "/" . get_exdir(0, 0, 0, 1, $object, 'commande'); |
||
| 1085 | $object_type = 'order'; |
||
| 1086 | $mesg = $langs->transnoentitiesnoconv("EMailTextOrderClose", $link); |
||
| 1087 | break; |
||
| 1088 | case 'PROPAL_VALIDATE': |
||
| 1089 | $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1090 | $dir_output = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
||
| 1091 | $object_type = 'propal'; |
||
| 1092 | $mesg = $langs->transnoentitiesnoconv("EMailTextProposalValidated", $link); |
||
| 1093 | break; |
||
| 1094 | case 'PROPAL_CLOSE_SIGNED': |
||
| 1095 | $link = '<a href="' . $urlwithroot . '/comm/propal/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1096 | $dir_output = $conf->propal->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object, 'propal'); |
||
| 1097 | $object_type = 'propal'; |
||
| 1098 | $mesg = $langs->transnoentitiesnoconv("EMailTextProposalClosedSigned", $link); |
||
| 1099 | break; |
||
| 1100 | case 'FICHINTER_ADD_CONTACT': |
||
| 1101 | $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1102 | $dir_output = $conf->ficheinter->dir_output; |
||
| 1103 | $object_type = 'ficheinter'; |
||
| 1104 | $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionAddedContact", $link); |
||
| 1105 | break; |
||
| 1106 | case 'FICHINTER_VALIDATE': |
||
| 1107 | $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1108 | $dir_output = $conf->facture->dir_output; |
||
| 1109 | $object_type = 'ficheinter'; |
||
| 1110 | $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionValidated", $link); |
||
| 1111 | break; |
||
| 1112 | case 'FICHINTER_CLOSE': |
||
| 1113 | $link = '<a href="' . $urlwithroot . '/fichinter/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1114 | $dir_output = $conf->facture->dir_output; |
||
| 1115 | $object_type = 'ficheinter'; |
||
| 1116 | $mesg = $langs->transnoentitiesnoconv("EMailTextInterventionClosed", $link); |
||
| 1117 | break; |
||
| 1118 | case 'ORDER_SUPPLIER_CANCEL': |
||
| 1119 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1120 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 1121 | $object_type = 'order_supplier'; |
||
| 1122 | $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 1123 | $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderCanceledBy", $link, $user->getFullName($langs)); |
||
| 1124 | $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 1125 | break; |
||
| 1126 | case 'ORDER_SUPPLIER_VALIDATE': |
||
| 1127 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1128 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 1129 | $object_type = 'order_supplier'; |
||
| 1130 | $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 1131 | $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderValidatedBy", $link, $user->getFullName($langs)); |
||
| 1132 | $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 1133 | break; |
||
| 1134 | case 'ORDER_SUPPLIER_APPROVE': |
||
| 1135 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1136 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 1137 | $object_type = 'order_supplier'; |
||
| 1138 | $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 1139 | $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderApprovedBy", $link, $user->getFullName($langs)); |
||
| 1140 | $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 1141 | break; |
||
| 1142 | case 'ORDER_SUPPLIER_SUBMIT': |
||
| 1143 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1144 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 1145 | $object_type = 'order_supplier'; |
||
| 1146 | $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 1147 | $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderSubmittedBy", $link, $user->getFullName($langs)); |
||
| 1148 | $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 1149 | break; |
||
| 1150 | case 'ORDER_SUPPLIER_REFUSE': |
||
| 1151 | $link = '<a href="' . $urlwithroot . '/fourn/commande/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1152 | $dir_output = $conf->fournisseur->commande->multidir_output[$object->entity] . "/" . get_exdir(0, 0, 0, 1, $object); |
||
| 1153 | $object_type = 'order_supplier'; |
||
| 1154 | $mesg = $langs->transnoentitiesnoconv("Hello") . ",\n\n"; |
||
| 1155 | $mesg .= $langs->transnoentitiesnoconv("EMailTextSupplierOrderRefusedBy", $link, $user->getFullName($langs)); |
||
| 1156 | $mesg .= "\n\n" . $langs->transnoentitiesnoconv("Sincerely") . ".\n\n"; |
||
| 1157 | break; |
||
| 1158 | case 'SHIPPING_VALIDATE': |
||
| 1159 | $link = '<a href="' . $urlwithroot . '/expedition/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1160 | $dir_output = $conf->expedition->dir_output . "/sending/" . get_exdir(0, 0, 0, 1, $object, 'shipment'); |
||
| 1161 | $object_type = 'order_supplier'; |
||
| 1162 | $mesg = $langs->transnoentitiesnoconv("EMailTextExpeditionValidated", $link); |
||
| 1163 | break; |
||
| 1164 | case 'EXPENSE_REPORT_VALIDATE': |
||
| 1165 | $link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1166 | $dir_output = $conf->expensereport->dir_output; |
||
| 1167 | $object_type = 'expensereport'; |
||
| 1168 | $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportValidated", $link); |
||
| 1169 | break; |
||
| 1170 | case 'EXPENSE_REPORT_APPROVE': |
||
| 1171 | $link = '<a href="' . $urlwithroot . '/expensereport/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1172 | $dir_output = $conf->expensereport->dir_output; |
||
| 1173 | $object_type = 'expensereport'; |
||
| 1174 | $mesg = $langs->transnoentitiesnoconv("EMailTextExpenseReportApproved", $link); |
||
| 1175 | break; |
||
| 1176 | case 'HOLIDAY_VALIDATE': |
||
| 1177 | $link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1178 | $dir_output = $conf->holiday->dir_output; |
||
| 1179 | $object_type = 'holiday'; |
||
| 1180 | $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayValidated", $link); |
||
| 1181 | break; |
||
| 1182 | case 'HOLIDAY_APPROVE': |
||
| 1183 | $link = '<a href="' . $urlwithroot . '/holiday/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1184 | $dir_output = $conf->holiday->dir_output; |
||
| 1185 | $object_type = 'holiday'; |
||
| 1186 | $mesg = $langs->transnoentitiesnoconv("EMailTextHolidayApproved", $link); |
||
| 1187 | break; |
||
| 1188 | case 'ACTION_CREATE': |
||
| 1189 | $link = '<a href="' . $urlwithroot . '/comm/action/card.php?id=' . $object->id . '&entity=' . $object->entity . '">' . $newref . '</a>'; |
||
| 1190 | $dir_output = $conf->agenda->dir_output; |
||
| 1191 | $object_type = 'action'; |
||
| 1192 | $mesg = $langs->transnoentitiesnoconv("EMailTextActionAdded", $link); |
||
| 1193 | break; |
||
| 1194 | default: |
||
| 1195 | $object_type = $object->element; |
||
| 1196 | $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity] . "/" . get_exdir(0, 0, 0, 1, $object, $object_type); |
||
| 1197 | $mesg = $langs->transnoentitiesnoconv('Notify_' . $notifcode) . ' ' . $newref; |
||
| 1198 | break; |
||
| 1199 | } |
||
| 1200 | $ref = dol_sanitizeFileName($newref); |
||
| 1201 | $pdf_path = $dir_output . "/" . $ref . "/" . $ref . ".pdf"; |
||
| 1202 | if (!dol_is_file($pdf_path)) { |
||
| 1203 | // We can't add PDF as it is not generated yet. |
||
| 1204 | $filepdf = ''; |
||
| 1205 | } else { |
||
| 1206 | $filepdf = $pdf_path; |
||
| 1207 | $filename_list[] = $pdf_path; |
||
| 1208 | $mimetype_list[] = mime_content_type($filepdf); |
||
| 1209 | $mimefilename_list[] = $ref . ".pdf"; |
||
| 1210 | } |
||
| 1211 | |||
| 1212 | // Set output language |
||
| 1213 | $outputlangs = $langs; |
||
| 1214 | |||
| 1215 | // if an e-mail template is configured for this notification code (for instance 'SHIPPING_VALIDATE_TEMPLATE', ...), |
||
| 1216 | // we fetch this template by its label. Otherwise, a default message content will be sent. |
||
| 1217 | $mailTemplateLabel = getDolGlobalString($notifcode . '_TEMPLATE'); |
||
| 1218 | $emailTemplate = null; |
||
| 1219 | if (!empty($mailTemplateLabel)) { |
||
| 1220 | $formmail = new FormMail($this->db); |
||
| 1221 | $emailTemplate = $formmail->getEMailTemplate($this->db, $object_type . '_send', $user, $outputlangs, 0, 1, $mailTemplateLabel); |
||
| 1222 | } |
||
| 1223 | if (!empty($mailTemplateLabel) && is_object($emailTemplate) && $emailTemplate->id > 0) { |
||
| 1224 | if (property_exists($object, 'thirdparty') && $object->thirdparty instanceof Societe && $object->thirdparty->default_lang && $object->thirdparty->default_lang != $langs->defaultlang) { |
||
| 1225 | $outputlangs = new Translate('', $conf); |
||
| 1226 | $outputlangs->setDefaultLang($object->thirdparty->default_lang); |
||
| 1227 | $outputlangs->loadLangs(array('main', 'other')); |
||
| 1228 | } |
||
| 1229 | $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object); |
||
| 1230 | complete_substitutions_array($substitutionarray, $outputlangs, $object); |
||
| 1231 | $subject = make_substitutions($emailTemplate->topic, $substitutionarray, $outputlangs); |
||
| 1232 | $message = make_substitutions($emailTemplate->content, $substitutionarray, $outputlangs); |
||
| 1233 | } else { |
||
| 1234 | $message = ''; |
||
| 1235 | $message .= $outputlangs->transnoentities("YouReceiveMailBecauseOfNotification2", $application, $mysoc->name) . "\n"; |
||
| 1236 | $message .= "\n"; |
||
| 1237 | $message .= $mesg; |
||
| 1238 | |||
| 1239 | $message = nl2br($message); |
||
| 1240 | } |
||
| 1241 | |||
| 1242 | // Replace keyword __SUPERVISOREMAIL__ |
||
| 1243 | if (preg_match('/__SUPERVISOREMAIL__/', $sendto)) { |
||
| 1244 | $newval = ''; |
||
| 1245 | if ($user->fk_user > 0) { |
||
| 1246 | $supervisoruser = new User($this->db); |
||
| 1247 | $supervisoruser->fetch($user->fk_user); |
||
| 1248 | if ($supervisoruser->email) { |
||
| 1249 | $newval = trim(dolGetFirstLastname($supervisoruser->firstname, $supervisoruser->lastname) . ' <' . $supervisoruser->email . '>'); |
||
| 1250 | } |
||
| 1251 | } |
||
| 1252 | dol_syslog("Replace the __SUPERVISOREMAIL__ key into recipient email string with " . $newval); |
||
| 1253 | $sendto = preg_replace('/__SUPERVISOREMAIL__/', $newval, $sendto); |
||
| 1254 | $sendto = preg_replace('/,\s*,/', ',', $sendto); // in some case you can have $sendto like "email, __SUPERVISOREMAIL__ , otheremail" then you have "email, , othermail" and it's not valid |
||
| 1255 | $sendto = preg_replace('/^[\s,]+/', '', $sendto); // Clean start of string |
||
| 1256 | $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string |
||
| 1257 | } |
||
| 1258 | |||
| 1259 | if ($sendto) { |
||
| 1260 | $parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'from' => $from, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'subject' => &$subject, 'message' => &$message); |
||
| 1261 | $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
||
| 1262 | if (empty($reshook)) { |
||
| 1263 | if (!empty($hookmanager->resArray['files'])) { |
||
| 1264 | $filename_list = $hookmanager->resArray['files']['file']; |
||
| 1265 | $mimetype_list = $hookmanager->resArray['files']['mimefile']; |
||
| 1266 | $mimefilename_list = $hookmanager->resArray['files']['filename']; |
||
| 1267 | } |
||
| 1268 | if (!empty($hookmanager->resArray['subject'])) { |
||
| 1269 | $subject .= $hookmanager->resArray['subject']; |
||
| 1270 | } |
||
| 1271 | if (!empty($hookmanager->resArray['message'])) { |
||
| 1272 | $message .= $hookmanager->resArray['message']; |
||
| 1273 | } |
||
| 1274 | } |
||
| 1275 | $mailfile = new CMailFile( |
||
| 1276 | $subject, |
||
| 1277 | $sendto, |
||
| 1278 | $from, |
||
| 1279 | $message, |
||
| 1280 | $filename_list, |
||
| 1281 | $mimetype_list, |
||
| 1282 | $mimefilename_list, |
||
| 1283 | '', |
||
| 1284 | '', |
||
| 1285 | 0, |
||
| 1286 | 1, |
||
| 1287 | '', |
||
| 1288 | $trackid, |
||
| 1289 | '', |
||
| 1290 | '', |
||
| 1291 | 'notification' |
||
| 1292 | ); |
||
| 1293 | |||
| 1294 | if ($mailfile->sendfile()) { |
||
| 1295 | $sql = "INSERT INTO " . $this->db->prefix() . "notify (daten, fk_action, fk_soc, fk_contact, type, type_target, objet_type, objet_id, email)"; |
||
| 1296 | $sql .= " VALUES ('" . $this->db->idate(dol_now()) . "', " . ((int) $notifcodedefid) . ", " . ($object->socid > 0 ? ((int) $object->socid) : 'null') . ", null, 'email', 'tofixedemail', '" . $this->db->escape($object_type) . "', " . ((int) $object->id) . ", '" . $this->db->escape($sendto) . "')"; |
||
| 1297 | if (!$this->db->query($sql)) { |
||
| 1298 | dol_print_error($this->db); |
||
| 1299 | } |
||
| 1300 | } else { |
||
| 1301 | $error++; |
||
| 1302 | $this->errors[] = $mailfile->error; |
||
| 1303 | } |
||
| 1304 | } |
||
| 1305 | } |
||
| 1306 | } |
||
| 1307 | |||
| 1308 | if (!$error) { |
||
| 1309 | return $num; |
||
| 1310 | } else { |
||
| 1311 | return -1 * $error; |
||
| 1312 | } |
||
| 1315 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.