function TicketOwnerComments($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $adb = PearDatabase::getInstance();
    //if commented from portal by the customer, then ignore this
    $customer = $entityData->get('customer');
    if (!empty($customer)) {
        return;
    }
    $wsParentId = $entityData->get('related_to');
    $parentIdParts = explode('x', $wsParentId);
    $parentId = $parentIdParts[1];
    $moduleName = getSalesEntityType($parentId);
    $isNew = $entityData->isNew();
    if ($moduleName == 'HelpDesk') {
        $ticketFocus = CRMEntity::getInstance($moduleName);
        $ticketFocus->retrieve_entity_info($parentId, $moduleName);
        $ticketFocus->id = $parentId;
        if (!$isNew) {
            $reply = 'Re : ';
        } else {
            $reply = '';
        }
        $subject = $ticketFocus->column_fields['ticket_no'] . ' [ ' . getTranslatedString('LBL_TICKET_ID', $moduleName) . ' : ' . $parentId . ' ] ' . $reply . $ticketFocus->column_fields['ticket_title'];
        $emailOptOut = 0;
        $contactId = $ticketFocus->column_fields['contact_id'];
        $accountId = $ticketFocus->column_fields['parent_id'];
        //To get the emailoptout vtiger_field value and then decide whether send mail about the tickets or not
        if (!empty($contactId)) {
            $result = $adb->pquery('SELECT email, emailoptout FROM vtiger_contactdetails WHERE contactid=?', array($contactId));
            $emailOptOut = $adb->query_result($result, 0, 'emailoptout');
            $parentEmail = $contactMailId = $adb->query_result($result, 0, 'email');
            $displayValueArray = getEntityName('Contacts', $contactId);
            if (!empty($displayValueArray)) {
                foreach ($displayValueArray as $key => $value) {
                    $contactName = $value;
                }
            }
            $parentName = $contactName;
            //Get the status of the vtiger_portal user. if the customer is active then send the vtiger_portal link in the mail
            if ($parentEmail != '') {
                $sql = "SELECT * FROM vtiger_portalinfo WHERE user_name=?";
                $isPortalUser = $adb->query_result($adb->pquery($sql, array($parentEmail)), 0, 'isactive');
            }
        } else {
            if (!empty($accountId)) {
                $result = $adb->pquery("SELECT accountname, emailoptout, email1 FROM vtiger_account WHERE accountid=?", array($accountId));
                $emailOptOut = $adb->query_result($result, 0, 'emailoptout');
                $parentEmail = $adb->query_result($result, 0, 'email1');
                $parentName = $adb->query_result($result, 0, 'accountname');
            }
        }
        //added condition to check the emailoptout
        if ($emailOptOut == 0) {
            $entityData = VTEntityData::fromCRMEntity($ticketFocus);
            if ($isPortalUser == 1) {
                $bodysubject = getTranslatedString('Ticket No', $moduleName) . ": " . $ticketFocus->column_fields['ticket_no'] . "<br>" . getTranslatedString('LBL_TICKET_ID', $moduleName) . ' : ' . $parentId . '<br> ' . getTranslatedString('LBL_SUBJECT', $moduleName) . $ticketFocus->column_fields['ticket_title'];
                $emailBody = $bodysubject . '<br><br>' . HelpDesk::getPortalTicketEmailContents($entityData);
            } else {
                $emailBody = HelpDesk::getTicketEmailContents($entityData);
            }
            send_mail('HelpDesk', $parentEmail, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $emailBody);
        }
    }
}
function HelpDesk_notifyParentOnTicketChange($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $adb = PearDatabase::getInstance();
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $isNew = $entityData->isNew();
    if (!$isNew) {
        $reply = 'Re : ';
    } else {
        $reply = '';
    }
    // SalesPlatform.ru begin
    $subject = ' [ ' . getTranslatedString('Ticket No', $moduleName) . ' ' . $entityData->get('ticket_no') . ' ] ' . $reply . $entityData->get('ticket_title');
    $bodysubject = getTranslatedString('Ticket No', $moduleName) . " " . $entityData->get('ticket_no') . "<br>" . getTranslatedString('LBL_SUBJECT', $moduleName) . " " . $entityData->get('ticket_title') . "<br>" . getTranslatedString('Status', $moduleName) . ": " . getTranslatedString($entityData->get('ticketstatus'), $moduleName);
    //	$subject = $entityData->get('ticket_no') . ' [ '.getTranslatedString('LBL_TICKET_ID', $moduleName)
    //						.' : '.$entityId.' ] '.$reply.$entityData->get('ticket_title');
    //	$bodysubject = getTranslatedString('Ticket No', $moduleName) .":<br>" . $entityData->get('ticket_no')
    //						. "<br>" . getTranslatedString('LBL_TICKET_ID', $moduleName).' : '.$entityId.'<br> '
    //						.getTranslatedString('LBL_SUBJECT', $moduleName).$entityData->get('ticket_title');
    // SalesPlatform.ru end
    $emailoptout = 0;
    $wsContactId = $entityData->get('contact_id');
    $contactId = explode('x', $wsContactId);
    $wsAccountId = $entityData->get('parent_id');
    $accountId = explode('x', $wsAccountId);
    //To get the emailoptout vtiger_field value and then decide whether send mail about the tickets or not
    if (!empty($contactId[0])) {
        $result = $adb->pquery('SELECT email, emailoptout, lastname, firstname FROM vtiger_contactdetails WHERE
						contactid=?', array($contactId[1]));
        $emailoptout = $adb->query_result($result, 0, 'emailoptout');
        $parent_email = $contact_mailid = $adb->query_result($result, 0, 'email');
        $parentname = $adb->query_result($result, 0, 'firstname') . ' ' . $adb->query_result($result, 0, 'firstname');
        //Get the status of the vtiger_portal user. if the customer is active then send the vtiger_portal link in the mail
        if ($parent_email != '') {
            $sql = "SELECT * FROM vtiger_portalinfo WHERE user_name=?";
            $isPortalUser = $adb->query_result($adb->pquery($sql, array($contact_mailid)), 0, 'isactive');
        }
    } elseif (!empty($accountId[0])) {
        $result = $adb->pquery("SELECT accountname, emailoptout, email1 FROM vtiger_account WHERE accountid=?", array($accountId[1]));
        $emailoptout = $adb->query_result($result, 0, 'emailoptout');
        $parent_email = $adb->query_result($result, 0, 'email1');
        $parentname = $adb->query_result($result, 0, 'accountname');
    }
    //added condition to check the emailoptout(this is for contacts and vtiger_accounts.)
    if ($emailoptout == 0) {
        if ($isPortalUser == 1) {
            $email_body = HelpDesk::getTicketEmailContents($entityData);
        } else {
            $email_body = HelpDesk::getTicketEmailContents($entityData);
        }
        //added condition to check the emailoptout(this is for contacts and vtiger_accounts.)
        if ($emailoptout == 0) {
            // SalesPlatform.ru begin
            //if($isPortalUser == 1){
            //	$url = "<a href='".$PORTAL_URL."/index.php?module=HelpDesk&action=index&ticketid=".$entityId."&fun=detail'>".$mod_strings['LBL_TICKET_DETAILS']."</a>";
            //	$email_body = $bodysubject.'<br><br>'.HelpDesk::getPortalTicketEmailContents($entityData);
            //}
            //else {
            //	$email_body = HelpDesk::getTicketEmailContents($entityData);
            //}
            // SalesPlatform.ru end
            if ($isNew) {
                // SalesPlatform.ru begin
                if ($isPortalUser == 1) {
                    $url = "<a href='" . $PORTAL_URL . "/index.php?module=HelpDesk&action=index&ticketid=" . $entityId . "&fun=detail'>" . $mod_strings['LBL_TICKET_DETAILS'] . "</a>";
                    $email_body = $bodysubject . '<br><br>' . HelpDesk::getPortalTicketEmailContents($entityData, true);
                } else {
                    $email_body = HelpDesk::getTicketEmailContents($entityData);
                    // SalesPlatform.ru end
                }
                $mail_status = send_mail('HelpDesk', $parent_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
            } else {
                $entityDelta = new VTEntityDelta();
                $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
                $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
                $ownerHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'assigned_user_id');
                $commentsHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'comments');
                // SalesPlatform.ru begin
                if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $commentsHasChanged || $solutionHasChanged) {
                    if ($isPortalUser == 1) {
                        $url = "<a href='" . $PORTAL_URL . "/index.php?module=HelpDesk&action=index&ticketid=" . $entityId . "&fun=detail'>" . $mod_strings['LBL_TICKET_DETAILS'] . "</a>";
                        $email_body = $bodysubject . '<br><br>' . HelpDesk::getPortalTicketEmailContents($entityData, false, $statusHasChanged, $solutionHasChanged, $ownerHasChanged, $commentsHasChanged);
                    } else {
                        $email_body = HelpDesk::getTicketEmailContents($entityData);
                    }
                    //if(($statusHasChanged && $entityData->get('ticketstatus') == "Closed") || $commentsHasChanged || $solutionHasChanged || $ownerHasChanged) {
                    // SalesPlatform.ru end
                    $mail_status = send_mail('HelpDesk', $parent_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
                }
            }
            $mail_status_str .= $parent_email . "=" . $mail_status . "&&&";
        } else {
            $entityDelta = new VTEntityDelta();
            $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
            $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
            $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
            if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $solutionHasChanged || $descriptionHasChanged) {
                send_mail('HelpDesk', $parent_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
            }
        }
    }
}
예제 #3
0
function HelpDesk_notifyParentOnTicketChange($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $adb = PearDatabase::getInstance();
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $wsParentId = $entityData->get('parent_id');
    $parentIdParts = explode('x', $wsParentId);
    $parentId = $parentIdParts[1];
    $isNew = $entityData->isNew();
    if (!$isNew) {
        $reply = 'Re : ';
    } else {
        $reply = '';
    }
    $subject = $entityData->get('ticket_no') . ' [ ' . getTranslatedString('LBL_TICKET_ID', $moduleName) . ' : ' . $entityId . ' ] ' . $reply . $entityData->get('ticket_title');
    $bodysubject = getTranslatedString('Ticket No', $moduleName) . ":<br>" . $entityData->get('ticket_no') . "<br>" . getTranslatedString('LBL_TICKET_ID', $moduleName) . ' : ' . $entityId . '<br> ' . getTranslatedString('LBL_SUBJECT', $moduleName) . $entityData->get('ticket_title');
    $emailoptout = 0;
    //To get the emailoptout vtiger_field value and then decide whether send mail about the tickets or not
    if ($parentId != '') {
        $parent_module = getSalesEntityType($parentId);
        if ($parent_module == 'Contacts') {
            $result = $adb->pquery('SELECT email, emailoptout FROM vtiger_contactdetails WHERE contactid=?', array($parentId));
            $emailoptout = $adb->query_result($result, 0, 'emailoptout');
            $parent_email = $contact_mailid = $adb->query_result($result, 0, 'email');
            $displayValueArray = getEntityName($parent_module, $parentId);
            if (!empty($displayValueArray)) {
                foreach ($displayValueArray as $key => $field_value) {
                    $contact_name = $field_value;
                }
            }
            $parentname = $contactname = $contact_name;
            //Get the status of the vtiger_portal user. if the customer is active then send the vtiger_portal link in the mail
            if ($contact_mailid != '') {
                $sql = "SELECT * FROM vtiger_portalinfo WHERE user_name=?";
                $isPortalUser = $adb->query_result($adb->pquery($sql, array($contact_mailid)), 0, 'isactive');
            }
        }
        if ($parent_module == 'Accounts') {
            $result = $adb->pquery("SELECT accountname, emailoptout, email1 FROM vtiger_account WHERE accountid=?", array($parentId));
            $emailoptout = $adb->query_result($result, 0, 'emailoptout');
            $parent_email = $adb->query_result($result, 0, 'email1');
            $parentname = $adb->query_result($result, 0, 'accountname');
        }
        //added condition to check the emailoptout(this is for contacts and vtiger_accounts.)
        if ($emailoptout == 0) {
            if ($isPortalUser == 1) {
                $url = "<a href='" . $PORTAL_URL . "/index.php?module=HelpDesk&action=index&ticketid=" . $entityId . "&fun=detail'>" . $mod_strings['LBL_TICKET_DETAILS'] . "</a>";
                $email_body = $bodysubject . '<br><br>' . HelpDesk::getPortalTicketEmailContents($entityData);
            } else {
                $email_body = HelpDesk::getTicketEmailContents($entityData);
            }
            if ($isNew) {
                $mail_status = send_mail('HelpDesk', $parent_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
            } else {
                $entityDelta = new VTEntityDelta();
                $statusHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'ticketstatus');
                $solutionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'solution');
                $ownerHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'assigned_user_id');
                $commentsHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'comments');
                if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $commentsHasChanged || $solutionHasChanged || $ownerHasChanged) {
                    $mail_status = send_mail('HelpDesk', $parent_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
                }
            }
            $mail_status_str .= $parent_email . "=" . $mail_status . "&&&";
        } else {
            $adb->println("'" . $parentname . "' is not want to get the email about the ticket details as emailoptout is selected");
        }
        if ($mail_status != '') {
            $mail_error_status = getMailErrorString($mail_status_str);
        }
    }
}