02-26-2021, 05:44 PM
(This post was last modified: 02-26-2021, 05:44 PM by Victor Burgueño.)
searching i ad found that the function invoqued from the worqflow its SendPortalLoginDetails
the function that seems to be making this work it's Contacts_sendCustomerPortalLoginDetails
in Contactshandler.php
i had get the solution of activating the customer portal enabling this function on a workflow
but still it dont send the email maibe becouse it don't find the tempate... how it indicates which is the temlate
to be sended?
this function also seems to update the activation if the portal user is not disabled and disabling it on the database
but it doesnt work for me...
function Contacts_sendCustomerPortalLoginDetails($entityData) {
$adb = PearDatabase::getInstance();
//$moduleName = $entityData->getModuleName();
$wsId = $entityData->getId();
$parts = explode('x', $wsId);
$entityId = $parts[1];
$email = $entityData->get('email');
if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
$result = $adb->pquery('SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?', array($entityId));
$insert = false;
if ($adb->num_rows($result) == 0) {
$insert = true;
} else {
$dbusername = $adb->query_result($result, 0, 'user_name');
$isactive = $adb->query_result($result, 0, 'isactive');
if ($email == $dbusername && $isactive == 1 && !$entityData->isNew()) {
$update = false;
} elseif ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
$adb->pquery('UPDATE vtiger_portalinfo SET user_name=?, isactive=1 WHERE id=?', array($email, $entityId));
$password = $adb->query_result($result, 0, 'user_password');
$update = true;
} else {
$adb->pquery('UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?', array($email, 0, $entityId));
$update = false;
}
}
if ($insert == true) {
$password = makeRandomPassword();
$adb->pquery(
'INSERT INTO vtiger_portalinfo(id,user_name,user_password,type,isactive) VALUES(?,?,?,?,?)',
array($entityId, $email, $password, 'C', 1)
);
}
if ($insert == true || $update == true) {
require_once 'modules/Emails/mail.php';
global $current_user;
$emailData = Contacts::getPortalEmailContents($entityData, $password, 'LoginDetails');
$subject = $emailData['subject'];
$contents = $emailData['body'];
send_mail('Contacts', $entityData->get('email'), $current_user->user_name, "", $subject, $contents);
}
} else {
$adb->pquery('UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?', array($email, $entityId));
}
}
the function that seems to be making this work it's Contacts_sendCustomerPortalLoginDetails
in Contactshandler.php
i had get the solution of activating the customer portal enabling this function on a workflow
but still it dont send the email maibe becouse it don't find the tempate... how it indicates which is the temlate
to be sended?
this function also seems to update the activation if the portal user is not disabled and disabling it on the database
but it doesnt work for me...
function Contacts_sendCustomerPortalLoginDetails($entityData) {
$adb = PearDatabase::getInstance();
//$moduleName = $entityData->getModuleName();
$wsId = $entityData->getId();
$parts = explode('x', $wsId);
$entityId = $parts[1];
$email = $entityData->get('email');
if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
$result = $adb->pquery('SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?', array($entityId));
$insert = false;
if ($adb->num_rows($result) == 0) {
$insert = true;
} else {
$dbusername = $adb->query_result($result, 0, 'user_name');
$isactive = $adb->query_result($result, 0, 'isactive');
if ($email == $dbusername && $isactive == 1 && !$entityData->isNew()) {
$update = false;
} elseif ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
$adb->pquery('UPDATE vtiger_portalinfo SET user_name=?, isactive=1 WHERE id=?', array($email, $entityId));
$password = $adb->query_result($result, 0, 'user_password');
$update = true;
} else {
$adb->pquery('UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?', array($email, 0, $entityId));
$update = false;
}
}
if ($insert == true) {
$password = makeRandomPassword();
$adb->pquery(
'INSERT INTO vtiger_portalinfo(id,user_name,user_password,type,isactive) VALUES(?,?,?,?,?)',
array($entityId, $email, $password, 'C', 1)
);
}
if ($insert == true || $update == true) {
require_once 'modules/Emails/mail.php';
global $current_user;
$emailData = Contacts::getPortalEmailContents($entityData, $password, 'LoginDetails');
$subject = $emailData['subject'];
$contents = $emailData['body'];
send_mail('Contacts', $entityData->get('email'), $current_user->user_name, "", $subject, $contents);
}
} else {
$adb->pquery('UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?', array($email, $entityId));
}
}