feat: Enhance email functionality and PDF generation for Sales Orders
- Enabled SMTP debugging in PHPMailer for better error tracking. - Added a "Test send email" link in the Inventory Detail View for quick email testing. - Implemented automatic PDF generation and email sending upon Sales Order creation. - Created a new action for sending Sales Order emails with attached PDFs. - Added a new AJAX action for testing outgoing email server configurations. - Updated outgoing server settings to use new SMTP credentials. - Improved email templates for better user experience. - Added test scripts for validating PDF generation and email sending.
This commit is contained in:
@@ -1,304 +1,610 @@
|
||||
<?php
|
||||
|
||||
/*+***********************************************************************************
|
||||
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
|
||||
* All Rights Reserved.
|
||||
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
|
||||
require_once 'SUtiles.php';
|
||||
|
||||
|
||||
|
||||
class Accounts_ListView_Model extends Vtiger_ListView_Model {
|
||||
|
||||
|
||||
|
||||
protected $isVMPharma = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Function to get the list of Mass actions for the module
|
||||
|
||||
* @param <Array> $linkParams
|
||||
|
||||
* @return <Array> - Associative array of Link type to List of Vtiger_Link_Model instances for Mass Actions
|
||||
|
||||
*/
|
||||
|
||||
public function getListViewMassActions($linkParams) {
|
||||
|
||||
$massActionLinks = parent::getListViewMassActions($linkParams);
|
||||
|
||||
|
||||
|
||||
$currentUserModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
|
||||
|
||||
$emailModuleModel = Vtiger_Module_Model::getInstance('Emails');
|
||||
|
||||
|
||||
|
||||
if($currentUserModel->hasModulePermission($emailModuleModel->getId())) {
|
||||
|
||||
$massActionLink = array(
|
||||
|
||||
'linktype' => 'LISTVIEWMASSACTION',
|
||||
|
||||
'linklabel' => 'LBL_SEND_EMAIL',
|
||||
|
||||
'linkurl' => 'javascript:Vtiger_List_Js.triggerSendEmail("index.php?module='.$this->getModule()->getName().'&view=MassActionAjax&mode=showComposeEmailForm&step=step1","Emails");',
|
||||
|
||||
'linkicon' => ''
|
||||
|
||||
);
|
||||
|
||||
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$SMSNotifierModuleModel = Vtiger_Module_Model::getInstance('SMSNotifier');
|
||||
|
||||
if(!empty($SMSNotifierModuleModel) && $currentUserModel->hasModulePermission($SMSNotifierModuleModel->getId())) {
|
||||
|
||||
$massActionLink = array(
|
||||
|
||||
'linktype' => 'LISTVIEWMASSACTION',
|
||||
|
||||
'linklabel' => 'LBL_SEND_SMS',
|
||||
|
||||
'linkurl' => 'javascript:Vtiger_List_Js.triggerSendSms("index.php?module='.$this->getModule()->getName().'&view=MassActionAjax&mode=showSendSMSForm","SMSNotifier");',
|
||||
|
||||
'linkicon' => ''
|
||||
|
||||
);
|
||||
|
||||
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$currentUser = Users_Record_Model::getCurrentUserModel();
|
||||
|
||||
$userId = $currentUser->get('id');
|
||||
|
||||
|
||||
|
||||
if($userId == 1 || $userId == 17) {
|
||||
|
||||
$moduleModel = $this->getModule();
|
||||
|
||||
if($currentUserModel->hasModuleActionPermission($moduleModel->getId(), 'EditView')) {
|
||||
|
||||
$massActionLink = array(
|
||||
|
||||
'linktype' => 'LISTVIEWMASSACTION',
|
||||
|
||||
'linklabel' => 'LBL_TRANSFER_OWNERSHIP',
|
||||
|
||||
'linkurl' => 'javascript:Vtiger_List_Js.triggerTransferOwnership("index.php?module='.$moduleModel->getName().'&view=MassActionAjax&mode=transferOwnership")',
|
||||
|
||||
'linkicon' => ''
|
||||
|
||||
);
|
||||
|
||||
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $massActionLinks;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Function to get the list of listview links for the module
|
||||
|
||||
* @param <Array> $linkParams
|
||||
|
||||
* @return <Array> - Associate array of Link Type to List of Vtiger_Link_Model instances
|
||||
|
||||
*/
|
||||
|
||||
function getListViewLinks($linkParams) {
|
||||
|
||||
$links = parent::getListViewLinks($linkParams);
|
||||
|
||||
|
||||
|
||||
$index=0;
|
||||
|
||||
foreach($links['LISTVIEWBASIC'] as $link) {
|
||||
|
||||
if($link->linklabel == 'Send SMS') {
|
||||
|
||||
unset($links['LISTVIEWBASIC'][$index]);
|
||||
|
||||
}
|
||||
|
||||
$index++;
|
||||
|
||||
}
|
||||
|
||||
return $links;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//filter account by default
|
||||
|
||||
private function customSearch($roleid) {
|
||||
|
||||
|
||||
|
||||
$field_value = "all";
|
||||
|
||||
$fullname = "";
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_account:account_type:accounttype:Accounts_Type:V", "comparator" => "n", "value" => $field_value];
|
||||
|
||||
$aCondition2 = [];
|
||||
|
||||
$aCondition3 = [];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$currentUser = Users_Record_Model::getCurrentUserModel();
|
||||
|
||||
if(isByWilaya($currentUser->get('id'))) {
|
||||
|
||||
|
||||
|
||||
$lieu = $currentUser->get('secteur1_id').','.$currentUser->get('secteur2_id').','.$currentUser->get('secteur3_id').','.$currentUser->get('secteur4_id');
|
||||
|
||||
|
||||
|
||||
$industry = "Pharmacie";
|
||||
|
||||
if(isMedecin($roleid))
|
||||
|
||||
$industry = "Medecin";
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => $industry, "column_condition" => "and"];
|
||||
|
||||
$aCondition2 = ["columnname" => "vtiger_accountscf:cf_992:cf_992:Accounts_Wilaya:V", "comparator" => "c", "value" => $lieu];
|
||||
|
||||
$asearchParams = $this->get('search_params');
|
||||
|
||||
if(empty($asearchParams)) {
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition, $aCondition2] ]];
|
||||
|
||||
$this->set('search_params', $searchParams);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else
|
||||
|
||||
|
||||
|
||||
if(isMedecin($roleid) || isPharma($roleid)) {
|
||||
|
||||
$field_value = "Medecin";
|
||||
|
||||
$fullname = $currentUser->get('first_name').' '.$currentUser->get('last_name');
|
||||
|
||||
$sub = getSubordinateRoleAndUsers($roleid);
|
||||
|
||||
foreach($sub as $roleid=>$userids) {
|
||||
|
||||
foreach($userids as $roleid2=>$userids2) {
|
||||
|
||||
$fullname = $fullname.",".$userids2;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $fullname, "column_condition" => "or"];
|
||||
|
||||
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $fullname, "column_condition" => "or"];
|
||||
|
||||
if($this->isVMPharma)
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie"];
|
||||
|
||||
else
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $fullname];
|
||||
|
||||
|
||||
|
||||
} else if(isGro($roleid)) {
|
||||
|
||||
$field_value = "Grossiste";
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => $field_value];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// update search_params
|
||||
|
||||
$searchParams = $this->get('search_params');
|
||||
|
||||
if(empty($searchParams)) {
|
||||
|
||||
if($aCondition2 != [] && $aCondition3 != []) {
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition, $aCondition2, $aCondition3] ]];
|
||||
|
||||
} else {
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition] ]];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$exist = 0;
|
||||
|
||||
$index = 0;
|
||||
|
||||
$columns = $searchParams[0]["columns"];
|
||||
|
||||
|
||||
|
||||
foreach ($columns as $column) {
|
||||
|
||||
|
||||
|
||||
if(isByWilaya($currentUser->get('id'))) {
|
||||
|
||||
<?php
|
||||
|
||||
/*+***********************************************************************************
|
||||
|
||||
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
|
||||
|
||||
* ("License"); You may not use this file except in compliance with the License
|
||||
|
||||
* The Original Code is: vtiger CRM Open Source
|
||||
|
||||
* The Initial Developer of the Original Code is vtiger.
|
||||
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
|
||||
* All Rights Reserved.
|
||||
|
||||
*************************************************************************************/
|
||||
|
||||
|
||||
|
||||
require_once 'SUtiles.php';
|
||||
|
||||
|
||||
|
||||
class Accounts_ListView_Model extends Vtiger_ListView_Model {
|
||||
|
||||
|
||||
|
||||
protected $isVMPharma = true;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Function to get the list of Mass actions for the module
|
||||
|
||||
* @param <Array> $linkParams
|
||||
|
||||
* @return <Array> - Associative array of Link type to List of Vtiger_Link_Model instances for Mass Actions
|
||||
|
||||
*/
|
||||
|
||||
public function getListViewMassActions($linkParams) {
|
||||
|
||||
$massActionLinks = parent::getListViewMassActions($linkParams);
|
||||
|
||||
|
||||
|
||||
$currentUserModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
|
||||
|
||||
$emailModuleModel = Vtiger_Module_Model::getInstance('Emails');
|
||||
|
||||
|
||||
|
||||
if($currentUserModel->hasModulePermission($emailModuleModel->getId())) {
|
||||
|
||||
$massActionLink = array(
|
||||
|
||||
'linktype' => 'LISTVIEWMASSACTION',
|
||||
|
||||
'linklabel' => 'LBL_SEND_EMAIL',
|
||||
|
||||
'linkurl' => 'javascript:Vtiger_List_Js.triggerSendEmail("index.php?module='.$this->getModule()->getName().'&view=MassActionAjax&mode=showComposeEmailForm&step=step1","Emails");',
|
||||
|
||||
'linkicon' => ''
|
||||
|
||||
);
|
||||
|
||||
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$SMSNotifierModuleModel = Vtiger_Module_Model::getInstance('SMSNotifier');
|
||||
|
||||
if(!empty($SMSNotifierModuleModel) && $currentUserModel->hasModulePermission($SMSNotifierModuleModel->getId())) {
|
||||
|
||||
$massActionLink = array(
|
||||
|
||||
'linktype' => 'LISTVIEWMASSACTION',
|
||||
|
||||
'linklabel' => 'LBL_SEND_SMS',
|
||||
|
||||
'linkurl' => 'javascript:Vtiger_List_Js.triggerSendSms("index.php?module='.$this->getModule()->getName().'&view=MassActionAjax&mode=showSendSMSForm","SMSNotifier");',
|
||||
|
||||
'linkicon' => ''
|
||||
|
||||
);
|
||||
|
||||
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$currentUser = Users_Record_Model::getCurrentUserModel();
|
||||
|
||||
$userId = $currentUser->get('id');
|
||||
|
||||
|
||||
|
||||
if($userId == 1 || $userId == 17) {
|
||||
|
||||
$moduleModel = $this->getModule();
|
||||
|
||||
if($currentUserModel->hasModuleActionPermission($moduleModel->getId(), 'EditView')) {
|
||||
|
||||
$massActionLink = array(
|
||||
|
||||
'linktype' => 'LISTVIEWMASSACTION',
|
||||
|
||||
'linklabel' => 'LBL_TRANSFER_OWNERSHIP',
|
||||
|
||||
'linkurl' => 'javascript:Vtiger_List_Js.triggerTransferOwnership("index.php?module='.$moduleModel->getName().'&view=MassActionAjax&mode=transferOwnership")',
|
||||
|
||||
'linkicon' => ''
|
||||
|
||||
);
|
||||
|
||||
$massActionLinks['LISTVIEWMASSACTION'][] = Vtiger_Link_Model::getInstanceFromValues($massActionLink);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $massActionLinks;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
||||
* Function to get the list of listview links for the module
|
||||
|
||||
* @param <Array> $linkParams
|
||||
|
||||
* @return <Array> - Associate array of Link Type to List of Vtiger_Link_Model instances
|
||||
|
||||
*/
|
||||
|
||||
function getListViewLinks($linkParams) {
|
||||
|
||||
$links = parent::getListViewLinks($linkParams);
|
||||
|
||||
|
||||
|
||||
$index=0;
|
||||
|
||||
foreach($links['LISTVIEWBASIC'] as $link) {
|
||||
|
||||
if($link->linklabel == 'Send SMS') {
|
||||
|
||||
unset($links['LISTVIEWBASIC'][$index]);
|
||||
|
||||
}
|
||||
|
||||
$index++;
|
||||
|
||||
}
|
||||
|
||||
return $links;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//filter account by default
|
||||
|
||||
private function customSearch($roleid) {
|
||||
|
||||
|
||||
|
||||
$field_value = "all";
|
||||
|
||||
$fullname = "";
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_account:account_type:accounttype:Accounts_Type:V", "comparator" => "n", "value" => $field_value];
|
||||
|
||||
$aCondition2 = [];
|
||||
|
||||
$aCondition3 = [];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$currentUser = Users_Record_Model::getCurrentUserModel();
|
||||
|
||||
if(isByWilaya($currentUser->get('id'))) {
|
||||
|
||||
|
||||
|
||||
$lieu = $currentUser->get('secteur1_id').','.$currentUser->get('secteur2_id').','.$currentUser->get('secteur3_id').','.$currentUser->get('secteur4_id');
|
||||
|
||||
|
||||
|
||||
$industry = "Pharmacie";
|
||||
|
||||
if(isMedecin($roleid))
|
||||
|
||||
$industry = "Medecin";
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => $industry, "column_condition" => "and"];
|
||||
|
||||
$aCondition2 = ["columnname" => "vtiger_accountscf:cf_992:cf_992:Accounts_Wilaya:V", "comparator" => "c", "value" => $lieu];
|
||||
|
||||
$asearchParams = $this->get('search_params');
|
||||
|
||||
if(empty($asearchParams)) {
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition, $aCondition2] ]];
|
||||
|
||||
$this->set('search_params', $searchParams);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else
|
||||
|
||||
|
||||
|
||||
if(isMedecin($roleid) || isPharma($roleid)) {
|
||||
|
||||
$field_value = "Medecin";
|
||||
|
||||
$fullname = $currentUser->get('first_name').' '.$currentUser->get('last_name');
|
||||
|
||||
$sub = getSubordinateRoleAndUsers($roleid);
|
||||
|
||||
foreach($sub as $roleid=>$userids) {
|
||||
|
||||
foreach($userids as $roleid2=>$userids2) {
|
||||
|
||||
$fullname = $fullname.",".$userids2;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $fullname, "column_condition" => "or"];
|
||||
|
||||
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $fullname, "column_condition" => "or"];
|
||||
|
||||
if($this->isVMPharma)
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie"];
|
||||
|
||||
else
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $fullname];
|
||||
|
||||
|
||||
|
||||
} else if(isGro($roleid)) {
|
||||
|
||||
$field_value = "Grossiste";
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => $field_value];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// update search_params
|
||||
|
||||
$searchParams = $this->get('search_params');
|
||||
|
||||
if(empty($searchParams)) {
|
||||
|
||||
if($aCondition2 != [] && $aCondition3 != []) {
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition, $aCondition2, $aCondition3] ]];
|
||||
|
||||
} else {
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition] ]];
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$exist = 0;
|
||||
|
||||
$index = 0;
|
||||
|
||||
$columns = $searchParams[0]["columns"];
|
||||
|
||||
|
||||
|
||||
foreach ($columns as $column) {
|
||||
|
||||
|
||||
|
||||
if(isByWilaya($currentUser->get('id'))) {
|
||||
|
||||
if($column["columnname"] == "vtiger_account:account_type:accounttype:Accounts_Type:V") {
|
||||
|
||||
$column["value"] = $field_value;
|
||||
|
||||
|
||||
|
||||
$exist = 1;
|
||||
|
||||
}
|
||||
|
||||
} else
|
||||
|
||||
|
||||
|
||||
if(isGro($roleid)) {
|
||||
|
||||
if($column["columnname"] == "vtiger_account:industry:industry:Accounts_industry:V") {
|
||||
|
||||
|
||||
|
||||
if($roleid == 'H4' && ($column["value"] == 'Pharmacie' || $column["value"] == 'Grossiste')) {
|
||||
|
||||
} else {
|
||||
|
||||
$column["value"] = $field_value;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$exist = 1;
|
||||
|
||||
}
|
||||
|
||||
} else if(isMedecin($roleid) || isPharma($roleid)) {
|
||||
|
||||
|
||||
|
||||
if($column["columnname"] == "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V" || $column["columnname"] == "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V" || $column["columnname"] == "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V") {
|
||||
|
||||
//$column["value"] = $fullname;
|
||||
|
||||
$fullnames = split(',', $fullname);
|
||||
|
||||
$acolumns = split(',', $column["value"]);
|
||||
|
||||
if (count(array_diff($fullnames, $acolumns)) == 0) {
|
||||
|
||||
$exist = 1;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if($column["columnname"] == "vtiger_account:account_type:accounttype:Accounts_Type:V") {
|
||||
|
||||
$column["value"] = $field_value;
|
||||
|
||||
|
||||
|
||||
$exist = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$exist && $index < count($columns)) {
|
||||
|
||||
//if($column["column_condition"] != 'or')
|
||||
|
||||
$column["column_condition"] = "and";
|
||||
|
||||
}
|
||||
|
||||
$columns[$index] = $column;
|
||||
|
||||
|
||||
|
||||
$index++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!$exist) {
|
||||
|
||||
|
||||
|
||||
if(isByWilaya($currentUser->get('id'))) {
|
||||
|
||||
array_push($columns, $aCondition, $aCondition2);
|
||||
|
||||
} else
|
||||
|
||||
|
||||
|
||||
if(isMedecin($roleid) || isPharma($roleid)) {
|
||||
|
||||
$tempColumns = $columns;
|
||||
|
||||
array_push($columns, $aCondition);
|
||||
|
||||
foreach ($tempColumns as $column) {
|
||||
|
||||
array_push($columns, $column);
|
||||
|
||||
}
|
||||
|
||||
array_push($columns, $aCondition2);
|
||||
|
||||
foreach ($tempColumns as $column) {
|
||||
|
||||
array_push($columns, $column);
|
||||
|
||||
}
|
||||
|
||||
array_push($columns, $aCondition3);
|
||||
|
||||
} else {
|
||||
|
||||
array_push($columns, $aCondition);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
$searchParams[0]["columns"] = $columns;
|
||||
|
||||
}
|
||||
|
||||
//print_r($searchParams);
|
||||
|
||||
$this->set('search_params', $searchParams);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function getListViewEntries($pagingModel) {
|
||||
|
||||
|
||||
|
||||
$currentUser = Users_Record_Model::getCurrentUserModel();
|
||||
|
||||
$roleid = $currentUser->get('roleid');
|
||||
|
||||
if($roleid != 'H2' && $_GET['viewname'] != 70) {
|
||||
|
||||
// if($roleid != 'H2' && $roleid != 'H20' && $roleid != 'H26' && $roleid != 'H39' && $_GET['viewname'] != 70) {
|
||||
|
||||
$this->customSearch($roleid);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
if($_GET['parent'] != '') {
|
||||
|
||||
|
||||
|
||||
$parent = $_GET['parent'];
|
||||
|
||||
$infousers = explode('user;', $parent);
|
||||
|
||||
|
||||
|
||||
if(count($infousers) > 1) {
|
||||
|
||||
$auser = $infousers[1];
|
||||
|
||||
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
||||
|
||||
$aCondition5 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
||||
|
||||
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
||||
|
||||
$aCondition6 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
||||
|
||||
if($this->isVMPharma)
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie", "column_condition" => "and"];
|
||||
|
||||
else
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
||||
|
||||
$aCondition4 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0'];
|
||||
|
||||
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition, $aCondition5, $aCondition2, $aCondition6, $aCondition3, $aCondition4] ]];
|
||||
|
||||
|
||||
|
||||
//print_r($searchParams);
|
||||
|
||||
$this->set('search_params', $searchParams);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return parent::getListViewEntries($pagingModel);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public function getListViewCount() {
|
||||
|
||||
|
||||
|
||||
$currentUser = Users_Record_Model::getCurrentUserModel();
|
||||
|
||||
$roleid = $currentUser->get('roleid');
|
||||
|
||||
if($roleid != 'H2' && $_GET['viewname'] != 70) {
|
||||
|
||||
// if($roleid != 'H2' && $roleid != 'H20' && $roleid != 'H26' && $roleid != 'H39' && $_GET['viewname'] != 70) {
|
||||
|
||||
$this->customSearch($roleid);
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
if($_GET['parent'] != '') {
|
||||
|
||||
|
||||
|
||||
$parent = $_GET['parent'];
|
||||
|
||||
$infousers = explode('user;', $parent);
|
||||
|
||||
|
||||
|
||||
if(count($infousers) > 1) {
|
||||
|
||||
$auser = $infousers[1];
|
||||
|
||||
|
||||
|
||||
$aCondition = ["columnname" => "vtiger_crmentity:smownerid:assigned_user_id:Accounts_Assigned_To:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
||||
|
||||
$aCondition5 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
||||
|
||||
$aCondition2 = ["columnname" => "vtiger_account:vm2_id:vm2_id:Accounts_VM2:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
||||
|
||||
$aCondition6 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0', "column_condition" => "or"];
|
||||
|
||||
if($this->isVMPharma)
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:industry:industry:Accounts_industry:V", "comparator" => "c", "value" => "Pharmacie", "column_condition" => "and"];
|
||||
|
||||
else
|
||||
|
||||
$aCondition3 = ["columnname" => "vtiger_account:vm3_id:vm3_id:Accounts_VM3:V", "comparator" => "c", "value" => $auser, "column_condition" => "and"];
|
||||
|
||||
$aCondition4 = ["columnname" => "vtiger_accountscf:cf_986:cf_986:Accounts_Latitude:V", "comparator" => "l", "value" => '0'];
|
||||
|
||||
|
||||
|
||||
$searchParams = [[ "columns" => [$aCondition, $aCondition5, $aCondition2, $aCondition6, $aCondition3, $aCondition4] ]];
|
||||
|
||||
|
||||
|
||||
//print_r($searchParams);
|
||||
|
||||
$this->set('search_params', $searchParams);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return parent::getListViewCount();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -301,7 +301,7 @@ class PHPMailer {
|
||||
* Sets SMTP class debugging on or off.
|
||||
* @var bool
|
||||
*/
|
||||
public $SMTPDebug = false;
|
||||
public $SMTPDebug = true;
|
||||
|
||||
/**
|
||||
* Sets the function/method to use for debugging output.
|
||||
|
||||
@@ -36,6 +36,15 @@ class Inventory_DetailView_Model extends Vtiger_DetailView_Model {
|
||||
);
|
||||
|
||||
$linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($sendEmailLink);
|
||||
|
||||
|
||||
$testsendEmailLink = array(
|
||||
'linklabel' => "Test send email",
|
||||
'linkurl' => 'javascript:Inventory_Detail_Js.testSendEmailPDFClickHandler(\''.$recordModel->getSendEmailPDFUrl().'\')',
|
||||
'linkicon' => ''
|
||||
);
|
||||
|
||||
$linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($testsendEmailLink);
|
||||
}
|
||||
|
||||
return $linkModelList;
|
||||
|
||||
@@ -7,19 +7,21 @@
|
||||
* Portions created by vtiger are Copyright (C) vtiger.
|
||||
* All Rights Reserved.
|
||||
************************************************************************************/
|
||||
require_once dirname(__FILE__) .'/ModTracker.php';
|
||||
require_once dirname(__FILE__) . '/ModTracker.php';
|
||||
require_once 'data/VTEntityDelta.php';
|
||||
|
||||
class ModTrackerHandler extends VTEventHandler {
|
||||
class ModTrackerHandler extends VTEventHandler
|
||||
{
|
||||
|
||||
function handleEvent($eventName, $data) {
|
||||
function handleEvent($eventName, $data)
|
||||
{
|
||||
global $adb, $current_user;
|
||||
$moduleName = $data->getModuleName();
|
||||
$isTrackingEnabled = ModTracker::isTrackingEnabledForModule($moduleName);
|
||||
if(!$isTrackingEnabled) {
|
||||
if (!$isTrackingEnabled) {
|
||||
return;
|
||||
}
|
||||
if($eventName == 'vtiger.entity.aftersave.final') {
|
||||
if ($eventName == 'vtiger.entity.aftersave.final') {
|
||||
$recordId = $data->getId();
|
||||
$columnFields = $data->getData();
|
||||
$vtEntityDelta = new VTEntityDelta();
|
||||
@@ -28,50 +30,222 @@ class ModTrackerHandler extends VTEventHandler {
|
||||
$newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId);
|
||||
$newerColumnFields = $newerEntity->getData();
|
||||
|
||||
if(is_array($delta)) {
|
||||
|
||||
if ($moduleName === 'SalesOrder') {
|
||||
|
||||
$recordId = $data->getId();
|
||||
$focus = CRMEntity::getInstance($moduleName);
|
||||
$focus->retrieve_entity_info($recordId, $moduleName);
|
||||
|
||||
$accountId = $focus->column_fields['account_id'];
|
||||
if (empty($accountId)) return;
|
||||
|
||||
$toEmail = "souldibachir3150@gmail.com";
|
||||
// $toEmail = getSingleFieldValue('vtiger_account', 'email1', 'accountid', $accountId);
|
||||
if (empty($toEmail)) return;
|
||||
|
||||
|
||||
/** -----------------------------------------------------------
|
||||
* 🔥 Secure ExportPDF with login cookie (your working version)
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
ob_clean();
|
||||
|
||||
$loginUrl = "https://sophal.net/sophalcrm/index.php?module=Users&action=Login";
|
||||
$exportUrl = "https://sophal.net/sophalcrm/index.php?module=SalesOrder&action=ExportPDF&record=$recordId";
|
||||
|
||||
// 1) Login
|
||||
$post = http_build_query([
|
||||
'username' => 'admin', // ⚠️ Replace later with "pdfbot"
|
||||
'password' => 'Sophal@Crm@Sophal', // ⚠️ Replace later with another password
|
||||
]);
|
||||
|
||||
$contextLogin = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'POST',
|
||||
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
|
||||
'content' => $post,
|
||||
]
|
||||
]);
|
||||
|
||||
file_get_contents($loginUrl, false, $contextLogin);
|
||||
|
||||
// Extract session cookie
|
||||
$cookies = [];
|
||||
foreach ($http_response_header as $hdr) {
|
||||
if (stripos($hdr, 'Set-Cookie:') === 0) {
|
||||
$cookies[] = trim(substr($hdr, 11), ';');
|
||||
}
|
||||
}
|
||||
$cookieHeader = 'Cookie: ' . implode('; ', $cookies);
|
||||
|
||||
// 2) Download PDF
|
||||
$contextPDF = stream_context_create([
|
||||
'http' => [
|
||||
'method' => 'GET',
|
||||
'header' => $cookieHeader
|
||||
]
|
||||
]);
|
||||
|
||||
$pdfContent = file_get_contents($exportUrl, false, $contextPDF);
|
||||
|
||||
// 3) Validate
|
||||
if (strpos($pdfContent, '%PDF') !== 0) {
|
||||
error_log("❌ ExportPDF returned invalid PDF for SalesOrder #$recordId");
|
||||
return;
|
||||
}
|
||||
|
||||
// 4) Save to storage
|
||||
$pdfPath = "storage/SalesOrder_{$recordId}.pdf";
|
||||
$filePath = $_SERVER['DOCUMENT_ROOT']."/sophalcrm/storage/SalesOrder_$recordId.pdf";
|
||||
file_put_contents($filePath, $pdfContent);
|
||||
|
||||
ob_end_clean();
|
||||
|
||||
|
||||
/** -----------------------------------------------------------
|
||||
* 📧 Email body + send
|
||||
* ----------------------------------------------------------- */
|
||||
|
||||
$subject = "Sales Order #" . $focus->column_fields['salesorder_no'];
|
||||
$body = '<html>
|
||||
<body style="font-family: Arial, sans-serif; background-color:#f5f5f5; margin:0; padding:0;">
|
||||
|
||||
<!-- HEADER -->
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background-color:#0d6efd; padding:20px 0;">
|
||||
<tr>
|
||||
<td align="center">
|
||||
<img src="https://sophal.net/sophalcrm/layouts/v7/skins/images/favicon.ico" alt="SOPHAL SPA" style="max-height:60px;">
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" style="color:#ffffff; font-size:20px; padding-top:10px;">
|
||||
<strong>SOPHAL SPA</strong>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- BODY -->
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="padding:30px;">
|
||||
<tr>
|
||||
<td style="background:#ffffff; padding:25px; border-radius:8px;">
|
||||
|
||||
<p>Bonjour <strong>'.$accountId.'</strong>,</p>
|
||||
|
||||
<p>Votre <strong>bon de commande n° '.$focus->column_fields['salesorder_no'].'</strong> est maintenant disponible.</p>
|
||||
<p>Vous pouvez le télécharger en cliquant sur le bouton ci-dessous :</p>
|
||||
|
||||
<!-- DOWNLOAD BUTTON -->
|
||||
<p style="text-align:center; margin:30px 0;">
|
||||
<a href="https://sophal.net/sophalcrm/'.$pdfPath.'"
|
||||
style="
|
||||
background-color:#0d6efd;
|
||||
color:#ffffff;
|
||||
padding:14px 28px;
|
||||
text-decoration:none;
|
||||
font-size:16px;
|
||||
border-radius:6px;
|
||||
display:inline-block;
|
||||
font-weight:bold;
|
||||
">
|
||||
📄 Télécharger le Bon de Commande
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p style="color:#b00; font-size:13px; margin-top:20px;">
|
||||
⚠️ Ceci est un email automatique. Merci de ne pas répondre à ce message.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Pour toute assistance, veuillez contacter notre service client :<br>
|
||||
📞 +213541229487<br>
|
||||
✉️ COMMERCIAL@SOPHAL.DZ
|
||||
</p>
|
||||
|
||||
<p>Cordialement,<br>
|
||||
<strong>SOPHAL SPA</strong></p>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<!-- FOOTER -->
|
||||
<table width="100%" cellpadding="0" cellspacing="0" style="background:#f0f0f0; padding:15px 0; border-top:1px solid #ddd;">
|
||||
<tr>
|
||||
<td align="center" style="font-size:12px; color:#666;">
|
||||
© 2025 SOPHAL SPA — Tous droits réservés.<br>
|
||||
HASSI BEN OKBA ORAN
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
</body>
|
||||
</html>';
|
||||
|
||||
// Send email
|
||||
$outgoingModel = Settings_Vtiger_Systems_Model::getInstanceFromServerType('email', 'OutgoingServer');
|
||||
$outgoingModel->pdf_path = $pdfPath;
|
||||
$outgoingModel->to_email = $toEmail;
|
||||
|
||||
$ajaxAction = new Settings_Vtiger_OutgoingServerAjax_Action();
|
||||
$ajaxAction->sendTestMail($outgoingModel, $subject, $body, $pdfPath);
|
||||
}
|
||||
|
||||
|
||||
if (is_array($delta)) {
|
||||
$inserted = false;
|
||||
foreach($delta as $fieldName => $values) {
|
||||
if($fieldName != 'modifiedtime') {
|
||||
if(!$inserted) {
|
||||
foreach ($delta as $fieldName => $values) {
|
||||
if ($fieldName != 'modifiedtime') {
|
||||
if (!$inserted) {
|
||||
$checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE crmid = ? AND status = ?', array($recordId, ModTracker::$CREATED));
|
||||
if(!$adb->num_rows($checkRecordPresentResult) && $data->isNew()) {
|
||||
if (!$adb->num_rows($checkRecordPresentResult) && $data->isNew()) {
|
||||
$status = ModTracker::$CREATED;
|
||||
} else {
|
||||
$status = ModTracker::$UPDATED;
|
||||
}
|
||||
$this->id = $adb->getUniqueId('vtiger_modtracker_basic');
|
||||
$changedOn = $newerColumnFields['modifiedtime'];
|
||||
if($moduleName == 'Users') {
|
||||
if ($moduleName == 'Users') {
|
||||
$date_var = date("Y-m-d H:i:s");
|
||||
$changedOn = $adb->formatDate($date_var,true);
|
||||
$changedOn = $adb->formatDate($date_var, true);
|
||||
}
|
||||
$adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status)
|
||||
VALUES(?,?,?,?,?,?)', Array($this->id, $recordId, $moduleName,
|
||||
$current_user->id, $changedOn, $status));
|
||||
VALUES(?,?,?,?,?,?)', array(
|
||||
$this->id,
|
||||
$recordId,
|
||||
$moduleName,
|
||||
$current_user->id,
|
||||
$changedOn,
|
||||
$status
|
||||
));
|
||||
$inserted = true;
|
||||
}
|
||||
$adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)',
|
||||
Array($this->id, $fieldName, $values['oldValue'], $values['currentValue']));
|
||||
$adb->pquery(
|
||||
'INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)',
|
||||
array($this->id, $fieldName, $values['oldValue'], $values['currentValue'])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
if($eventName == 'vtiger.entity.beforedelete') {
|
||||
if ($eventName == 'vtiger.entity.beforedelete') {
|
||||
$recordId = $data->getId();
|
||||
$columnFields = $data->getData();
|
||||
$id = $adb->getUniqueId('vtiger_modtracker_basic');
|
||||
$adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status)
|
||||
VALUES(?,?,?,?,?,?)', Array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s',time()), ModTracker::$DELETED));
|
||||
VALUES(?,?,?,?,?,?)', array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s', time()), ModTracker::$DELETED));
|
||||
}
|
||||
|
||||
if($eventName == 'vtiger.entity.afterrestore') {
|
||||
if ($eventName == 'vtiger.entity.afterrestore') {
|
||||
$recordId = $data->getId();
|
||||
$columnFields = $data->getData();
|
||||
$id = $adb->getUniqueId('vtiger_modtracker_basic');
|
||||
$adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status)
|
||||
VALUES(?,?,?,?,?,?)', Array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s',time()), ModTracker::$RESTORED));
|
||||
VALUES(?,?,?,?,?,?)', array($id, $recordId, $moduleName, $current_user->id, date('Y-m-d H:i:s', time()), ModTracker::$RESTORED));
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
63
modules/SalesOrder/actions/SendSaleOrderMailAjax.php
Normal file
63
modules/SalesOrder/actions/SendSaleOrderMailAjax.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
class SalesOrder_SendSaleOrderMailAjax_Action extends Vtiger_BasicAjax_Action
|
||||
{
|
||||
public function process(Vtiger_Request $request)
|
||||
{
|
||||
$recordId = $request->get('record');
|
||||
$response = new Vtiger_Response();
|
||||
|
||||
try {
|
||||
// Get record model
|
||||
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, 'SalesOrder');
|
||||
|
||||
// Load Outgoing Server config
|
||||
$outgoingServerSettingsModel = Settings_Vtiger_Systems_Model::getInstanceFromServerType('email', 'OutgoingServer');
|
||||
|
||||
// Include mailer
|
||||
require_once 'vtlib/Vtiger/Mailer.php';
|
||||
$mailer = new Vtiger_Mailer();
|
||||
|
||||
$mailer->IsSMTP();
|
||||
$mailer->Host = $outgoingServerSettingsModel->get('server');
|
||||
$mailer->Port = 587;
|
||||
$mailer->SMTPAuth = $outgoingServerSettingsModel->isSmtpAuthEnabled();
|
||||
$mailer->Username = $outgoingServerSettingsModel->get('server_username');
|
||||
$mailer->Password = $outgoingServerSettingsModel->get('server_password');
|
||||
$mailer->SMTPSecure = 'tls';
|
||||
$mailer->From = $outgoingServerSettingsModel->get('from_email_field');
|
||||
$mailer->FromName = 'Vtiger CRM';
|
||||
$mailer->AddAddress('souldibachir3150@gmail.com');
|
||||
$mailer->Subject = 'Sales Order #' . $recordModel->get('salesorder_no');
|
||||
|
||||
$mailer->Body = 'Attached is your Sales Order from Vtiger CRM.';
|
||||
|
||||
// Attach PDF
|
||||
$pdfPath = 'storage/SalesOrder_' . $recordId . '.pdf';
|
||||
$this->generatePDF($recordId, $pdfPath);
|
||||
$mailer->AddAttachment($pdfPath);
|
||||
|
||||
// Force send immediately
|
||||
$sent = $mailer->Send(true);
|
||||
|
||||
if ($sent) {
|
||||
$response->setResult(['success' => true, 'message' => '✅ Sales Order email sent successfully!']);
|
||||
} else {
|
||||
$response->setResult(['success' => false, 'message' => '⚠️ Failed to send Sales Order email.']);
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
$response->setError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
|
||||
$response->emit();
|
||||
}
|
||||
|
||||
private function generatePDF($recordId, $pdfPath)
|
||||
{
|
||||
require_once 'modules/SalesOrder/SalesOrderPDFController.php';
|
||||
$pdfController = new Vtiger_SalesOrderPDFController('SalesOrder');
|
||||
$pdfController->loadRecord($recordId);
|
||||
$pdfContent = $pdfController->Output('', 'S'); // Output as string
|
||||
file_put_contents($pdfPath, $pdfContent);
|
||||
}
|
||||
}
|
||||
74
modules/Settings/Vtiger/actions/OutgoingServerAjax.php
Normal file
74
modules/Settings/Vtiger/actions/OutgoingServerAjax.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*+***********************************************************************************
|
||||
* Custom Action for Outgoing Server Test Mail
|
||||
*************************************************************************************/
|
||||
|
||||
class Settings_Vtiger_OutgoingServerAjax_Action extends Settings_Vtiger_Basic_Action
|
||||
{
|
||||
public function process(Vtiger_Request $request)
|
||||
{
|
||||
$outgoingServerSettingsModel = Settings_Vtiger_Systems_Model::getInstanceFromServerType('email', 'OutgoingServer');
|
||||
$response = new Vtiger_Response();
|
||||
|
||||
try {
|
||||
// Always send test mail
|
||||
$sent = $this->sendTestMail($outgoingServerSettingsModel);
|
||||
|
||||
if ($sent) {
|
||||
|
||||
$data = $outgoingServerSettingsModel->getData();
|
||||
$data['message'] = '✅ Configuration saved and test mail sent successfully.';
|
||||
$data['success'] = true;
|
||||
$response->setResult($data);
|
||||
} else {
|
||||
$response->setResult([
|
||||
'success' => false,
|
||||
'message' => '⚠️ Test mail failed to send. Check SMTP settings or logs.'
|
||||
]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$response->setError($e->getCode(), $e->getMessage());
|
||||
}
|
||||
|
||||
// Important: emit and stop ALL further output
|
||||
$response->emit();
|
||||
exit; // 🔹 This prevents extra output after JSON
|
||||
}
|
||||
|
||||
public function sendTestMail($model , $subject = null, $body = null,$pdf_path = null)
|
||||
{
|
||||
require_once 'vtlib/Vtiger/Mailer.php';
|
||||
$mailer = new Vtiger_Mailer();
|
||||
|
||||
try {
|
||||
$mailer->IsSMTP();
|
||||
$mailer->Host = $model->get('server');
|
||||
$mailer->Port = 587;
|
||||
$mailer->SMTPAuth = $model->isSmtpAuthEnabled();
|
||||
$mailer->Username = $model->get('server_username');
|
||||
$mailer->Password = $model->get('server_password');
|
||||
$mailer->SMTPSecure = 'tls';
|
||||
$mailer->From = $model->get('from_email_field');
|
||||
$mailer->FromName = 'Vtiger Test Mail';
|
||||
$mailer->AddAddress($model->to_email ?? 'souldibachir3150@gmail.com');
|
||||
$mailer->AddCC('andryamo2231@gmail.com');
|
||||
$mailer->Subject = $subject ?? 'Test Mail from Vtiger CRM 2';
|
||||
$mailer->IsHTML(true);
|
||||
$mailer->Body = $body ?? 'This is a test mail sent when saving outgoing server configuration. 2'.$pdf_path;
|
||||
// // Attach Sales Order PDF if available
|
||||
// if (!empty($model->pdf_path) && file_exists($model->pdf_path)) {
|
||||
// $mailer->AddAttachment($model->pdf_path, basename($model->pdf_path));
|
||||
// }
|
||||
if (!$mailer->Send(true)) {
|
||||
error_log('SMTP send() failed: ' . $mailer->ErrorInfo);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
error_log('SMTP Test Mail Error: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,7 @@ class Settings_Vtiger_OutgoingServerEdit_View extends Settings_Vtiger_Index_View
|
||||
$viewer->assign('MODEL',$systemDetailsModel);
|
||||
$viewer->assign('QUALIFIED_MODULE', $qualifiedName);
|
||||
$viewer->assign('CURRENT_USER_MODEL', Users_Record_Model::getCurrentUserModel());
|
||||
$viewer->assign('TEST_MAIL', true);
|
||||
$viewer->view('OutgoingServerEdit.tpl',$qualifiedName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user