Ejemplo n.º 1
0
 function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $records = $request->get('records');
     $template = $request->get('template');
     $targetModuleName = $request->get('target');
     $method = $request->get('method');
     $success = [];
     if (!empty($template)) {
         $templateRecord = Vtiger_MappedFields_Model::getInstanceById($template);
         foreach ($records as $recordId) {
             if ($templateRecord->checkFiltersForRecord(intval($recordId))) {
                 if ($method == 0) {
                     $recordModel = Vtiger_Record_Model::getCleanInstance($targetModuleName);
                     $parentRecordModel = Vtiger_Record_Model::getInstanceById($recordId);
                     $recordModel->setRecordFieldValues($parentRecordModel);
                     if ($this->checkMandatoryFields($recordModel)) {
                         continue;
                     }
                     // TODO Add saving fields that exist in  advanced module
                     $recordModel->save();
                     if (isRecordExists($recordModel->getId())) {
                         $success[] = $recordId;
                     }
                 } else {
                     $success[] = $recordId;
                 }
             }
         }
     }
     $output = ['all' => count($records), 'ok' => $success, 'fail' => array_diff($records, $success)];
     $response = new Vtiger_Response();
     $response->setResult($output);
     $response->emit();
 }
Ejemplo n.º 2
0
 public function updateProgressMilestone($id)
 {
     $adb = PearDatabase::getInstance();
     //TODO need to handle security
     if (!isRecordExists($id)) {
         return;
     }
     $focus = CRMEntity::getInstance($this->getName());
     $relatedListMileston = $focus->get_dependents_list($id, $this->getId(), getTabid('ProjectTask'));
     $resultMileston = $adb->query($relatedListMileston['query']);
     $num = $adb->num_rows($resultMileston);
     $estimatedWorkTime = 0;
     $progressInHours = 0;
     for ($i = 0; $i < $num; $i++) {
         $row = $adb->query_result_rowdata($resultMileston, $i);
         $estimatedWorkTime += $row['estimated_work_time'];
         $recordProgress = $row['estimated_work_time'] * (int) $row['projecttaskprogress'] / 100;
         $progressInHours += $recordProgress;
     }
     if (!$estimatedWorkTime) {
         return;
     }
     $projectMilestoneProgress = round(100 * $progressInHours / $estimatedWorkTime);
     $focus->retrieve_entity_info($id, $this->getName());
     $focus->column_fields['projectmilestone_progress'] = $projectMilestoneProgress . '%';
     $focus->column_fields['mode'] = 'edit';
     $focus->saveentity($this->getName(), $id);
 }
Ejemplo n.º 3
0
 public function initializeListViewContents(Vtiger_Request $request, Vtiger_Viewer $viewer)
 {
     $moduleName = $this->getModule($request);
     $sourceModule = $request->get('src_module');
     $sourceRecord = $request->get('src_record');
     //list of records is narrowed to contacts related to help desks account, only in Help Desk Contacts relation view
     if ($moduleName == 'Contacts' && $sourceModule == 'HelpDesk' && isRecordExists($sourceRecord) && strpos($_SERVER['QUERY_STRING'], 'module=Contacts&src_module=HelpDesk') === 0) {
         $request->set('related_parent_module', 'Accounts');
         $helpDeskRecord = Vtiger_Record_Model::getInstanceById($sourceRecord, 'HelpDesk');
         $request->set('related_parent_id', $helpDeskRecord->get('parent_id'));
         $viewer->assign('SWITCH', true);
     }
     if ($moduleName == 'Contacts' && $sourceModule == 'SSalesProcesses' && isRecordExists($sourceRecord) && strpos($_SERVER['QUERY_STRING'], 'module=Contacts&src_module=SSalesProcesses') === 0) {
         $request->set('related_parent_module', 'Accounts');
         $moduleRecord = Vtiger_Record_Model::getInstanceById($sourceRecord, 'SSalesProcesses');
         $request->set('related_parent_id', $moduleRecord->get('related_to'));
         $viewer->assign('SWITCH', true);
     }
     if ($moduleName == 'Contacts' && $sourceModule == 'Project' && isRecordExists($sourceRecord) && strpos($_SERVER['QUERY_STRING'], 'module=Contacts&src_module=Project') === 0) {
         $request->set('related_parent_module', 'Accounts');
         $moduleRecord = Vtiger_Record_Model::getInstanceById($sourceRecord, 'Project');
         $request->set('related_parent_id', $moduleRecord->get('linktoaccountscontacts'));
         $viewer->assign('SWITCH', true);
     }
     parent::initializeListViewContents($request, $viewer);
 }
Ejemplo n.º 4
0
 function getComposeUrlParam($moduleName = false, $record = false, $view = false)
 {
     $url = '';
     if (!empty($record) && isRecordExists($record)) {
         $recordModel_OSSMailView = Vtiger_Record_Model::getCleanInstance('OSSMailView');
         $email = $recordModel_OSSMailView->findEmail($record, $moduleName);
         if ($email) {
             $url = '&to=' . $email;
         }
         $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName);
         if ($moduleName == 'HelpDesk') {
             $urldata = '&subject=' . $recordModel->get('ticket_no') . ' - ' . $recordModel->get('ticket_title');
         } elseif ($moduleName == 'SSalesProcesses') {
             $urldata = '&subject=' . $recordModel->get('ssalesprocesses_no') . ' - ' . $recordModel->get('subject');
         } elseif ($moduleName == 'Project') {
             $urldata = '&subject=' . $recordModel->get('project_no') . ' - ' . $recordModel->get('projectname');
         }
         $url .= $urldata;
     }
     if (!empty($moduleName)) {
         $url .= '&crmmodule=' . $moduleName;
     }
     if (!empty($record)) {
         $url .= '&crmrecord=' . $record;
     }
     if (!empty($view)) {
         $url .= '&crmview=' . $view;
     }
     return $url;
 }
Ejemplo n.º 5
0
 function getValue($fieldName, $relId, $templateId, $baseRecord = NULL, $parentTplId = NULL)
 {
     $val = parent::getValue($fieldName, $relId, $templateId, $baseRecord, $parentTplId);
     if ('base_on_parent_module' === $val) {
         if (isRecordExists($baseRecord)) {
             return $baseRecord;
         }
     }
 }
Ejemplo n.º 6
0
 function getValue($fieldName, $relId, $templateId, $baseRecord = NULL, $parentTplId = NULL)
 {
     $val = parent::getValue($fieldName, $relId, $templateId, $baseRecord, $parentTplId);
     if (isRecordExists($relId) && 'base_on_record' === $val) {
         $recodeModel = Vtiger_Record_Model::getInstanceById($relId);
         return $recodeModel->get('forecast_amount');
     } else {
         return '';
     }
 }
Ejemplo n.º 7
0
 function handleEvent($eventName, $entityData)
 {
     $adb = PearDatabase::getInstance();
     $log = vglobal('log');
     if ($eventName == 'vtiger.entity.aftersave.final') {
         $moduleName = $entityData->getModuleName();
         if ($moduleName == 'HelpDesk') {
             $ticketId = $entityData->getId();
             $sql = 'UPDATE `vtiger_troubletickets` SET `from_portal` = 0 WHERE `ticketid` = ?';
             $params = array($ticketId);
             $adb->pquery($sql, $params);
         }
     } else {
         if ($eventName == 'vtiger.entity.link.after') {
             if ($entityData['destinationModule'] == 'Contacts' && $entityData['sourceModule'] == 'HelpDesk' && isRecordExists($entityData['destinationRecordId'])) {
                 $ticketId = $entityData['sourceRecordId'];
                 $contactId = $entityData['destinationRecordId'];
                 $log->debug("Entering HelpDeskHandler:vtiger.entity.link.after");
                 $ticketRecord = Vtiger_Record_Model::getInstanceById($ticketId, 'HelpDesk');
                 if ($ticketRecord->get('ticketstatus') == 'Closed') {
                     return true;
                 }
                 $mails = [];
                 if (isRecordExists($contactId)) {
                     $contactRecord = Vtiger_Record_Model::getInstanceById($contactId, 'Contacts');
                     $primaryEmail = $contactRecord->get('email');
                     $secondaryEmail = $contactRecord->get('secondary_email');
                     if ($contactRecord->get('emailoptout') == 1) {
                         if (!empty($primaryEmail)) {
                             $mails[] = $primaryEmail;
                         } else {
                             if (!empty($secondaryEmail)) {
                                 $mails[] = $secondaryEmail;
                             }
                         }
                     }
                 }
                 if (count($mails) > 0) {
                     $mails = implode(',', $mails);
                     $data = array('id' => 39, 'to_email' => $mails, 'module' => 'HelpDesk', 'record' => $ticketId);
                     $recordModel = Vtiger_Record_Model::getCleanInstance('OSSMailTemplates');
                     $log->debug("HelpDeskHandler:vtiger.entity.link.after");
                     if ($recordModel->sendMailFromTemplate($data)) {
                         return true;
                     }
                 }
                 $log->debug("HelpDeskHandler:vtiger.entity.link.after");
                 return false;
             }
         }
     }
 }
Ejemplo n.º 8
0
 function process(Vtiger_Request $request)
 {
     $productId = $request->get('record');
     $values = [];
     if (isRecordExists($productId)) {
         $productModel = Vtiger_Record_Model::getInstanceById($productId);
         $subProducts = $productModel->getSubProducts();
         foreach ($subProducts as $subProduct) {
             $values[$subProduct->getId()] = $subProduct->getName();
         }
     }
     $response = new Vtiger_Response();
     $response->setResult($values);
     $response->emit();
 }
Ejemplo n.º 9
0
 function getValue($fieldName, $relId, $templateId, $baseRecord = NULL, $parentTplId = NULL)
 {
     $val = parent::getValue($fieldName, $relId, $templateId, $baseRecord, $parentTplId);
     if ('none' === $val) {
         return '';
     } else {
         if ('base_on_record' == $val) {
             if (isRecordExists($relId)) {
                 $recordModel = Vtiger_Record_Model::getInstanceById($relId);
                 return $recordModel->get('related_to');
             } else {
                 return '';
             }
         } else {
             return '';
         }
     }
 }
Ejemplo n.º 10
0
function HeldDeskClosedNotifyContacts($entityData)
{
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $log = vglobal('log');
    $db = PearDatabase::getInstance();
    $log->debug("Entering HeldDeskClosedNotifyContacts");
    $mails = [];
    $sql = 'SELECT `relcrmid` as contactid FROM `vtiger_crmentityrel` WHERE `module` = ? AND `relmodule` = ? AND `crmid` = ?;';
    $params = array('HelpDesk', 'Contacts', $entityId);
    $result = $db->pquery($sql, $params);
    $num = $db->num_rows($result);
    if ($num > 0) {
        for ($i = 0; $i < $num; $i++) {
            $contactId = $db->query_result($result, $i, 'contactid');
            if (isRecordExists($contactId)) {
                $contactRecord = Vtiger_Record_Model::getInstanceById($contactId, 'Contacts');
                $primaryEmail = $contactRecord->get('email');
                $secondaryEmail = $contactRecord->get('secondary_email');
                if ($contactRecord->get('emailoptout') == 1) {
                    if (!empty($primaryEmail)) {
                        $mails[] = $primaryEmail;
                    } else {
                        if (!empty($secondaryEmail)) {
                            $mails[] = $secondaryEmail;
                        }
                    }
                }
            }
        }
    }
    if (count($mails) > 0) {
        $mails = implode(',', $mails);
        $data = array('id' => 37, 'to_email' => $mails, 'module' => 'HelpDesk', 'record' => $entityId);
        $recordModel = Vtiger_Record_Model::getCleanInstance('OSSMailTemplates');
        $log->debug("HeldDeskClosedNotifyContacts");
        if ($recordModel->sendMailFromTemplate($data)) {
            return true;
        }
    }
    $log->debug("HeldDeskClosedNotifyContacts");
    return false;
}
Ejemplo n.º 11
0
 function handleEvent($eventName, $entityData)
 {
     $adb = PearDatabase::getInstance();
     $log = vglobal('log');
     if ($eventName == 'vtiger.entity.aftersave.final') {
         $moduleName = $entityData->getModuleName();
         if ($moduleName == 'HelpDesk') {
             $ticketId = $entityData->getId();
             $sql = 'UPDATE `vtiger_troubletickets` SET `from_portal` = 0 WHERE `ticketid` = ?';
             $adb->pquery($sql, [$ticketId]);
         }
     } else {
         if ($eventName == 'vtiger.entity.link.after') {
             if ($entityData['destinationModule'] == 'Contacts' && $entityData['sourceModule'] == 'HelpDesk' && isRecordExists($entityData['destinationRecordId'])) {
                 $ticketId = $entityData['sourceRecordId'];
                 $contactId = $entityData['destinationRecordId'];
                 $log->debug("Entering HelpDeskHandler:vtiger.entity.link.after");
                 $ticketRecord = Vtiger_Record_Model::getInstanceById($ticketId, 'HelpDesk');
                 if ($ticketRecord->get('ticketstatus') == 'Closed') {
                     return true;
                 }
                 $mail = false;
                 if (isRecordExists($contactId)) {
                     $contactRecord = Vtiger_Record_Model::getInstanceById($contactId, 'Contacts');
                     if ($contactRecord->get('emailoptout') == 1) {
                         $mail = $contactRecord->get('email');
                     }
                 }
                 if ($mail) {
                     $data = ['sysname' => 'NotifyContactOnTicketCreate', 'to_email' => $mail, 'module' => 'HelpDesk', 'record' => $ticketId];
                     $recordModel = Vtiger_Record_Model::getCleanInstance('OSSMailTemplates');
                     if ($recordModel->sendMailFromTemplate($data)) {
                         $log->debug('HelpDeskHandler:vtiger.entity.link.after');
                         return true;
                     }
                 }
                 $log->debug('HelpDeskHandler:vtiger.entity.link.after');
                 return false;
             }
         }
     }
 }
Ejemplo n.º 12
0
 public function getActiveTemplatesForRecord($recordId, $view, $moduleName = false)
 {
     $log = vglobal('log');
     $log->debug('Entering ' . __CLASS__ . '::' . __METHOD__ . '(' . $recordId . ',' . $view . ',' . $moduleName . ') method ...');
     if (!isRecordExists($recordId)) {
         $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...');
         return [];
     }
     if (!$moduleName) {
         $moduleName = Vtiger_Functions::getCRMRecordType($recordId);
     }
     $templates = $this->getTemplatesByModule($moduleName);
     foreach ($templates as $id => &$template) {
         if (!$template->checkFiltersForRecord($recordId) || !$template->checkUserPermissions() || !Users_Privileges_Model::isPermitted($template->getRelatedName(), 'EditView')) {
             unset($templates[$id]);
         }
     }
     $log->debug('Exiting ' . __CLASS__ . '::' . __METHOD__ . ' method ...');
     return $templates;
 }
Ejemplo n.º 13
0
function getContactsMailsFromTicket($id)
{
    if (empty($id)) {
        return [];
    }
    $db = PearDatabase::getInstance();
    $mails = [];
    $sql = 'SELECT `relcrmid` as contactid FROM `vtiger_crmentityrel` WHERE `module` = ? AND `relmodule` = ? AND `crmid` = ?;';
    $result = $db->pquery($sql, ['HelpDesk', 'Contacts', $id]);
    $num = $db->num_rows($result);
    while ($contactId = $db->getSingleValue($result)) {
        if (isRecordExists($contactId)) {
            $contactRecord = Vtiger_Record_Model::getInstanceById($contactId, 'Contacts');
            $primaryEmail = $contactRecord->get('email');
            if ($contactRecord->get('emailoptout') == 1 && !empty($primaryEmail)) {
                $mails[] = $primaryEmail;
            }
        }
    }
    return $mails;
}
Ejemplo n.º 14
0
function UpdatePotential($potentialId)
{
    if (!isRecordExists($potentialId) || Vtiger_Functions::getCRMRecordType($potentialId) != 'Potentials') {
        return false;
    }
    $db = PearDatabase::getInstance();
    $potentialTotal = 0;
    $paymentsIn = 0;
    $paymentsOut = 0;
    $sql = 'SELECT SUM(i.`total`) AS total FROM `vtiger_invoice` i INNER JOIN `vtiger_potential` p ON i.`potentialid` = p.`potentialid` WHERE p.`potentialid` = ?;';
    $params = array($potentialId);
    $result = $db->pquery($sql, $params);
    $potentialTotal = $db->query_result($result, 0, 'total');
    $sql = 'SELECT i.`invoiceid` FROM `vtiger_invoice` i INNER JOIN `vtiger_potential` p ON i.`potentialid` = p.`potentialid` WHERE p.`potentialid` = ?;';
    $params = array($potentialId);
    $result = $db->pquery($sql, $params);
    $invNum = $db->num_rows($result);
    if ($invNum > 0) {
        for ($i = 0; $i < $invNum; $i++) {
            $invoiceId = $db->query_result($result, $i, 'invoiceid');
            if (!isRecordExists($invoiceId)) {
                continue;
            }
            // get sum of payments in
            $sql = 'SELECT SUM(`paymentsvalue`) AS suma FROM `vtiger_paymentsin` WHERE `salesid` = ? AND `paymentsin_status` = ?;';
            $params = array($invoiceId, 'Paid');
            $inResult = $db->pquery($sql, $params);
            $paymentsIn += $db->query_result($inResult, 0, 'suma');
            // get sum of payments out
            $sql = 'SELECT SUM(`paymentsvalue`) AS suma FROM `vtiger_paymentsout` WHERE `salesid` = ? AND `paymentsout_status` = ?;';
            $inResult = $db->pquery($sql, $params);
            $paymentsOut += $db->query_result($inResult, 0, 'suma');
        }
    }
    $paymentsSum = $paymentsIn - $paymentsOut;
    $balance = $potentialTotal - $paymentsSum;
    $sql = 'UPDATE `vtiger_potential` SET `payment_balance` = ? WHERE `potentialid` = ? LIMIT 1;';
    $params = array($balance, $potentialId);
    $db->pquery($sql, $params);
}
Ejemplo n.º 15
0
 public function process(Vtiger_Request $request)
 {
     $adb = PearDatabase::getInstance();
     $moduleName = $request->getModule();
     $id = $request->get('id');
     $sourceModule = $request->get('sourceModule');
     $sourceData = array();
     if (isRecordExists($id)) {
         $record = Vtiger_Record_Model::getInstanceById($id, $sourceModule);
         $entity = $record->getEntity();
         $sourceData = $entity->column_fields;
         if ($sourceModule == 'HelpDesk') {
             $sourceData['contact_label'] = Vtiger_Functions::getCRMRecordLabel($sourceData['contact_id']);
             if (Vtiger_Functions::getCRMRecordType($sourceData['parent_id']) != 'Accounts') {
                 unset($sourceData['parent_id']);
             } else {
                 $sourceData['account_label'] = Vtiger_Functions::getCRMRecordLabel($sourceData['parent_id']);
             }
         } else {
             if ($sourceModule == 'Project') {
                 $ifExist = $adb->query("select * from vtiger_account where accountid = " . $sourceData['linktoaccountscontacts'] . "", true, "Błąd podczas pobierania danych z vtiger_crmentityrel");
                 if ($adb->num_rows($ifExist) > 0) {
                     $sourceData['account_label'] = Vtiger_Functions::getCRMRecordLabel($sourceData['linktoaccountscontacts']);
                 } else {
                     $sourceData['contact_label'] = Vtiger_Functions::getCRMRecordLabel($sourceData['linktoaccountscontacts']);
                 }
             }
         }
     }
     if ($sourceData === false) {
         $result = array('success' => false, 'message' => vtranslate('LBL_FAILED_TO_IMPORT_INFO', $moduleName));
     } else {
         $result = array('success' => true, 'sourceData' => $sourceData);
     }
     $response = new Vtiger_Response();
     $response->setResult($result);
     $response->emit();
 }
Ejemplo n.º 16
0
    }
    // END
    if (getFieldVisibilityPermission($sModule, $current_user->id, $checkForFieldAccess) == '0') {
        $permittedFieldNameList[] = $fieldName;
    }
}
$cv = new CustomView();
$viewId = $cv->getViewId($sModule);
if (!empty($_SESSION[$sModule . '_DetailView_Navigation' . $viewId])) {
    $recordNavigationInfo = Zend_Json::decode($_SESSION[$sModule . '_DetailView_Navigation' . $viewId]);
    $recordList = array();
    $recordIndex = null;
    $recordPageMapping = array();
    foreach ($recordNavigationInfo as $start => $recordIdList) {
        foreach ($recordIdList as $index => $recordId) {
            if (!isRecordExists($recordId)) {
                continue;
            }
            $recordList[] = $recordId;
            $recordPageMapping[$recordId] = $start;
            if ($recordId == $iCurRecord) {
                $recordIndex = count($recordList) - 1;
            }
        }
    }
} else {
    $recordList = array();
}
$output = '<table width="100%" border="0" cellpadding="5" cellspacing="0" class="layerHeadingULine">
			<tr><td width="60%" align="left" style="font-size:12px;font-weight:bold;">Jump to ' . $app_strings[$sModule] . ':</td>
			<td width="5%" align="right"><a href="javascript:fninvsh(\'lstRecordLayout\');"><img src="' . vtiger_imageurl('close.gif', $theme) . '" border="0"  align="absmiddle" /></a></td>
Ejemplo n.º 17
0
function undoLastImport($obj, $user)
{
    $adb = PearDatabase::getInstance();
    $moduleName = $obj->get('module');
    $ownerId = $obj->get('foruser');
    $owner = new Users();
    $owner->id = $ownerId;
    $owner->retrieve_entity_info($ownerId, 'Users');
    $dbTableName = Import_Utils_Helper::getDbTableName($owner);
    if (!is_admin($user) && $user->id != $owner->id) {
        $viewer = new Vtiger_Viewer();
        $viewer->view('OperationNotPermitted.tpl', 'Vtiger');
        exit;
    }
    $result = $adb->query("SELECT recordid FROM {$dbTableName} WHERE temp_status = " . Import_Data_Controller::$IMPORT_RECORD_CREATED . " AND recordid IS NOT NULL;");
    $noOfRecords = $adb->num_rows($result);
    $noOfRecordsDeleted = 0;
    for ($i = 0; $i < $noOfRecords; ++$i) {
        $recordId = $adb->query_result($result, $i, 'recordid');
        if (isRecordExists($recordId) && isPermitted($moduleName, 'Delete', $recordId) == 'yes') {
            $focus = CRMEntity::getInstance($moduleName);
            $focus->id = $recordId;
            $focus->trash($moduleName, $recordId);
            $noOfRecordsDeleted++;
        }
    }
    $viewer = new Vtiger_Viewer();
    $viewer->assign('FOR_MODULE', $moduleName);
    $viewer->assign('TOTAL_RECORDS', $noOfRecords);
    $viewer->assign('DELETED_RECORDS_COUNT', $noOfRecordsDeleted);
    $viewer->view('ImportUndoResult.tpl');
}
Ejemplo n.º 18
0
 public function getActiveTemplatesForRecord($recordId, $view, $moduleName = false)
 {
     if (!isRecordExists($recordId)) {
         return [];
     }
     if (!$moduleName) {
         $moduleName = Vtiger_Functions::getCRMRecordType($recordId);
     }
     $templates = $this->getTemplatesByModule($moduleName);
     foreach ($templates as $id => &$template) {
         $active = true;
         if (!$template->isVisible($view) || !$template->checkFiltersForRecord($recordId) || !$template->checkUserPermissions()) {
             unset($templates[$id]);
         }
     }
     return $templates;
 }
Ejemplo n.º 19
0
<?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 'modules/Vtiger/EditView.php';
if (!empty($_REQUEST['service_id'])) {
    $serviceObj = CRMEntity::getInstance('Services');
    if (isRecordExists($_REQUEST['service_id'])) {
        $serviceObj->retrieve_entity_info($_REQUEST['service_id'], 'Services');
        $focus->column_fields['tracking_unit'] = $serviceObj->column_fields['service_usageunit'];
    }
}
if (!empty($_REQUEST['return_id']) && !empty($_REQUEST['return_module'])) {
    $invModule = $_REQUEST['return_module'];
    $inventoryObj = CRMEntity::getInstance($invModule);
    $inventoryObj->retrieve_entity_info($_REQUEST['return_id'], $invModule);
    if (empty($_REQUEST['sc_related_to'])) {
        if (!empty($inventoryObj->column_fields['account_id'])) {
            $focus->column_fields['sc_related_to_type'] = 'Accounts';
            $focus->column_fields['sc_related_to'] = $inventoryObj->column_fields['account_id'];
        } else {
            if (!empty($inventoryObj->column_fields['contact_id'])) {
                $focus->column_fields['sc_related_to_type'] = 'Contacts';
                $focus->column_fields['sc_related_to'] = $inventoryObj->column_fields['contact_id'];
            }
Ejemplo n.º 20
0
 public function syncAddressBooks()
 {
     $this->log->debug(__CLASS__ . '::' . __METHOD__ . ' | Start');
     $db = PearDatabase::getInstance();
     $result = $this->getDavCardsToSync();
     $create = $deletes = $updates = 0;
     for ($i = 0; $i < $db->num_rows($result); $i++) {
         $card = $db->raw_query_result_rowdata($result, $i);
         if (!$card['crmid']) {
             //Creating
             $this->createRecord('Contacts', $card);
             $create++;
         } elseif (!isRecordExists($card['crmid']) || !Users_Privileges_Model::isPermitted($card['setype'], 'DetailView', $card['crmid'])) {
             // Deleting
             $this->deletedCard($card);
             $deletes++;
         } else {
             $crmLMT = strtotime($card['modifiedtime']);
             $cardLMT = $card['lastmodified'];
             if ($crmLMT < $cardLMT) {
                 // Updating
                 $recordModel = Vtiger_Record_Model::getInstanceById($card['crmid']);
                 $this->updateRecord($recordModel, $card);
                 $updates++;
             }
         }
     }
     $this->log->info("cardDavDav2Crm | create: {$create} | deletes: {$deletes} | updates: {$updates}");
     $this->log->debug(__CLASS__ . '::' . __METHOD__ . ' | End');
 }
Ejemplo n.º 21
0
 public function findEmail($id, $module)
 {
     if (!isRecordExists($id)) {
         return false;
     }
     $returnEmail = '';
     if (strcmp($module, 'HelpDesk') != 0 && strcmp($module, 'Potentials') != 0 && strcmp($module, 'Project') != 0) {
         $polaEmail = OSSMailScanner_Record_Model::getEmailSearch($module);
         if (count($polaEmail) > 0) {
             $recordModel = Vtiger_Record_Model::getInstanceById($id, $module);
             foreach ($polaEmail as $em) {
                 $email = $recordModel->get($em[2]);
                 if (!empty($email)) {
                     $returnEmail = $email;
                 }
             }
         }
     } else {
         $kontrahentId = '';
         $kontaktId = '';
         if (strcmp($module, 'HelpDesk') == 0) {
             $helpdeskRecord = Vtiger_Record_Model::getInstanceById($id, $module);
             $kontrahentId = $helpdeskRecord->get('parent_id');
             $kontaktId = $helpdeskRecord->get('contact_id');
         } else {
             if (strcmp($module, 'Potentials') == 0) {
                 $helpdeskRecord = Vtiger_Record_Model::getInstanceById($id, $module);
                 $kontrahentId = $helpdeskRecord->get('related_to');
             } else {
                 if (strcmp($module, 'Project') == 0) {
                     $helpdeskRecord = Vtiger_Record_Model::getInstanceById($id, $module);
                     $kontrahentId = $helpdeskRecord->get('linktoaccountscontacts');
                 }
             }
         }
         // czy kontrahent istnieje
         if (isRecordExists($kontrahentId)) {
             $nazwaModulu = Vtiger_Functions::getCRMRecordType($kontrahentId);
             $returnEmail = $this->findEmail($kontrahentId, $nazwaModulu);
         }
         if (isRecordExists($kontaktId)) {
             $nazwaModulu = Vtiger_Functions::getCRMRecordType($kontaktId);
             $returnEmail = $this->findEmail($kontaktId, $nazwaModulu);
         }
     }
     return $returnEmail;
 }
 public function docStatus($record, $folder, $docName)
 {
     $db = PearDatabase::getInstance();
     $getListDocumentRelSql = "SELECT * FROM vtiger_senotesrel WHERE crmid = ?";
     $getListDocumentRelResult = $db->pquery($getListDocumentRelSql, array($record), TRUE);
     for ($i = 0; $i < $db->num_rows($getListDocumentRelResult); $i++) {
         $ID = $db->query_result($getListDocumentRelResult, $i, 'notesid');
         if (isRecordExists($ID)) {
             $documentModel = Vtiger_Record_Model::getInstanceById($ID);
             if ($docName == $documentModel->get('notes_title') && $folder == $documentModel->get('folderid')) {
                 return $documentModel->get('ossdc_status');
             }
         }
     }
     return false;
 }
Ejemplo n.º 23
0
 /**
  * Function to get list of Selected Fields from target module for this record instance
  * @return <Array> list of field models <Settings_Webforms_Field_Model>
  */
 public function getSelectedFieldsList($mode = '')
 {
     if (!$this->selectedFields) {
         $targetModule = $this->get('targetmodule');
         if ($targetModule) {
             $db = PearDatabase::getInstance();
             $targetModuleModel = Vtiger_Module_Model::getInstance($targetModule);
             $allFields = $targetModuleModel->getFields();
             $result = $db->pquery("SELECT * FROM vtiger_webforms_field WHERE webformid = ? ORDER BY sequence", array($this->getId()));
             $numOfRows = $db->num_rows($result);
             for ($i = 0; $i < $numOfRows; $i++) {
                 $fieldData = $db->query_result_rowdata($result, $i);
                 $fieldName = $fieldData['fieldname'];
                 if (array_key_exists($fieldName, $allFields)) {
                     $fieldModel = $allFields[$fieldName];
                     //Check for hidden fields made as mandatory from layout editor,to unset hidden option
                     $mandatoryStatus = $fieldModel->isMandatory(true);
                     $hiddenStatus = $fieldData['hidden'];
                     $fieldValue = trim($fieldData['defaultvalue']);
                     $fieldType = $fieldModel->getFieldDataType();
                     if ($mandatoryStatus == 1 and $hiddenStatus == 1 and $fieldValue == "" and $fieldType != "boolean") {
                         $fieldData['hidden'] = 0;
                     }
                     if ($fieldType == 'reference' && $mode != 'showForm') {
                         $explodeResult = explode("x", $fieldValue);
                         $fieldValue = $explodeResult[1];
                         if (!isRecordExists($fieldValue)) {
                             $fieldValue = 0;
                         }
                     }
                     if ($fieldModel->isViewable()) {
                         foreach ($fieldData as $key => $value) {
                             $fieldModel->set($key, $value);
                         }
                         $fieldModel->set('fieldvalue', $fieldValue);
                         $selectedFields[$fieldName] = $fieldModel;
                     }
                 }
             }
         }
         $this->selectedFields = $selectedFields;
     }
     return $this->selectedFields;
 }
Ejemplo n.º 24
0
 /**
  * Function returns the Calendar Events for the module
  * @param <String> $mode - upcoming/overdue mode
  * @param <Vtiger_Paging_Model> $pagingModel - $pagingModel
  * @param <String> $user - all/userid
  * @param <String> $recordId - record id
  * @return <Array>
  */
 function getAssignedProjectsTasks($mode, $pagingModel, $user, $recordId = false)
 {
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $db = PearDatabase::getInstance();
     if (!$user) {
         $user = $currentUser->getId();
     }
     $nowInUserFormat = Vtiger_Datetime_UIType::getDisplayDateTimeValue(date('Y-m-d H:i:s'));
     $nowInDBFormat = Vtiger_Datetime_UIType::getDBDateTimeValue($nowInUserFormat);
     list($currentDate, $currentTime) = explode(' ', $nowInDBFormat);
     $instance = CRMEntity::getInstance('ProjectTask');
     $UserAccessConditions = $instance->getUserAccessConditionsQuerySR('ProjectTask');
     $params = array();
     $query = "SELECT vtiger_crmentity.crmid, vtiger_crmentity.smownerid, vtiger_crmentity.setype, vtiger_projecttask.*\n\t\t\tFROM vtiger_projecttask\n\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_projecttask.projecttaskid\n\t\t\tWHERE vtiger_crmentity.deleted=0 AND vtiger_crmentity.smcreatorid = ?";
     $params[] = $currentUser->getId();
     $query .= $UserAccessConditions;
     if ($mode === 'upcoming') {
         $query .= " AND targetenddate >= ?";
     } elseif ($mode === 'overdue') {
         $query .= " AND targetenddate < ?";
     }
     $params[] = $currentDate;
     $accessibleUsers = $currentUser->getAccessibleUsers();
     $accessibleGroups = $currentUser->getAccessibleGroups();
     if ($user != 'all' && $user != '' && (array_key_exists($user, $accessibleUsers) || array_key_exists($user, $accessibleGroups))) {
         $query .= " AND vtiger_crmentity.smownerid = ?";
         $params[] = $user;
     }
     $query .= " ORDER BY targetenddate LIMIT ?, ?";
     $params[] = $pagingModel->getStartIndex();
     $params[] = $pagingModel->getPageLimit() + 1;
     $result = $db->pquery($query, $params);
     $numOfRows = $db->num_rows($result);
     $projecttasks = array();
     for ($i = 0; $i < $numOfRows; $i++) {
         $row = $db->query_result_rowdata($result, $i);
         $model = Vtiger_Record_Model::getCleanInstance('ProjectTask');
         $model->setData($row);
         $model->setId($row['crmid']);
         if ($row['projectid']) {
             if (isRecordExists($row['projectid'])) {
                 $record = Vtiger_Record_Model::getInstanceById($row['projectid'], 'Project');
                 if (isRecordExists($record->get('linktoaccountscontacts'))) {
                     $model->set('account', '<a href="index.php?module=' . Vtiger_Functions::getCRMRecordType($record->get('linktoaccountscontacts')) . '&view=Detail&record=' . $record->get('linktoaccountscontacts') . '">' . Vtiger_Functions::getCRMRecordLabel($record->get('linktoaccountscontacts')) . '</a>');
                 }
             }
         }
         $projecttasks[] = $model;
     }
     $pagingModel->calculatePageRange($projecttasks);
     if ($numOfRows > $pagingModel->getPageLimit()) {
         array_pop($projecttasks);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     return $projecttasks;
 }
Ejemplo n.º 25
0
 function getUrlToCompose($module, $record)
 {
     if (!isRecordExists($record)) {
         return false;
     }
     $recordModel_OSSMailView = Vtiger_Record_Model::getCleanInstance('OSSMailView');
     $email = $recordModel_OSSMailView->findEmail($record, $module);
     $url = '&to=' . $email;
     $InstanceModel = Vtiger_Record_Model::getInstanceById($record, $module);
     if ($module == 'HelpDesk') {
         $urldata = '&subject=' . $InstanceModel->get('ticket_no') . ' - ' . $InstanceModel->get('ticket_title');
     } elseif ($module == 'Potentials') {
         $urldata = '&subject=' . $InstanceModel->get('potential_no') . ' - ' . $InstanceModel->get('potentialname');
     } elseif ($module == 'Project') {
         $urldata = '&subject=' . $InstanceModel->get('project_no') . ' - ' . $InstanceModel->get('projectname');
     }
     $url .= $urldata;
     return $url;
 }
Ejemplo n.º 26
0
 function undoImport(Vtiger_Request $request)
 {
     $viewer = new Vtiger_Viewer();
     $db = PearDatabase::getInstance();
     $moduleName = $request->getModule();
     $ownerId = $request->get('foruser');
     $user = Users_Record_Model::getCurrentUserModel();
     $dbTableName = Import_Utils_Helper::getDbTableName($user);
     if (!$user->isAdminUser() && $user->id != $ownerId) {
         $viewer->assign('MESSAGE', 'LBL_PERMISSION_DENIED');
         $viewer->view('OperationNotPermitted.tpl', 'Vtiger');
         exit;
     }
     $previousBulkSaveMode = $VTIGER_BULK_SAVE_MODE;
     $VTIGER_BULK_SAVE_MODE = true;
     $query = "SELECT recordid FROM {$dbTableName} WHERE temp_status = ? AND recordid IS NOT NULL";
     //For inventory modules
     $inventoryModules = getInventoryModules();
     if (in_array($moduleName, $inventoryModules)) {
         $query .= ' GROUP BY subject';
     }
     //End
     $result = $db->pquery($query, array(Import_Data_Action::$IMPORT_RECORD_CREATED));
     $noOfRecords = $db->num_rows($result);
     $noOfRecordsDeleted = 0;
     $entityData = array();
     for ($i = 0; $i < $noOfRecords; $i++) {
         $recordId = $db->query_result($result, $i, 'recordid');
         if (isRecordExists($recordId) && isPermitted($moduleName, 'Delete', $recordId) == 'yes') {
             $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
             $recordModel->setId($recordId);
             $recordModel->delete();
             $focus = $recordModel->getEntity();
             $focus->id = $recordId;
             $entityData[] = VTEntityData::fromCRMEntity($focus);
             $noOfRecordsDeleted++;
         }
     }
     $entity = new VTEventsManager($db);
     $entity->triggerEvent('vtiger.batchevent.delete', $entityData);
     $VTIGER_BULK_SAVE_MODE = $previousBulkSaveMode;
     $viewer->assign('FOR_MODULE', $moduleName);
     $viewer->assign('MODULE', 'Import');
     $viewer->assign('TOTAL_RECORDS', $noOfRecords);
     $viewer->assign('DELETED_RECORDS_COUNT', $noOfRecordsDeleted);
     $viewer->view('ImportUndoResult.tpl', 'Import');
 }
Ejemplo n.º 27
0
 public function executeColorListHandlers($moduleName, $record, $recordModelObiect)
 {
     if (!isRecordExists($record)) {
         return false;
     }
     vimport('~~modules/Settings/DataAccess/helpers/DataAccess_Conditions.php');
     $db = PearDatabase::getInstance();
     $recordModel = Vtiger_Record_Model::getInstanceById($record, $moduleName);
     $conditions = new DataAccess_Conditions();
     $success = true;
     $sql = "SELECT * FROM vtiger_dataaccess WHERE module_name = ? AND data LIKE '%colorList%'";
     $result = $db->pquery($sql, array($moduleName), true);
     for ($i = 0; $i < $db->num_rows($result); $i++) {
         $row = $db->raw_query_result_rowdata($result, $i);
         $condition_result = $conditions->checkConditions($row['dataaccessid'], $recordModel->entity->column_fields);
         if ($condition_result['test'] == true) {
             $data = unserialize($row['data']);
             return array('text' => $data[0]['text'], 'background' => $data[0]['bg']);
         }
     }
     return false;
 }
Ejemplo n.º 28
0
 function replaceRelatedModuleFields($content, $module, $recordid, $fields, &$site_URL)
 {
     $db = PearDatabase::getInstance();
     require_once 'include/utils/utils.php';
     $userLang = Users_Record_Model::getCurrentUserModel()->get('language');
     include "languages/" . $userLang . "/OSSPdf.php";
     require_once 'include/utils/CommonUtils.php';
     require_once 'include/fields/CurrencyField.php';
     #################################################################################
     $uitypelist2 = array('10', '58', '51', '57', '68', '59', '75', '80', '76', '73', '81', '78');
     $uitype2module2 = array('58' => 'Campaigns', '51' => 'Accounts', '57' => 'Contacts', '68' => 'Accounts;Contacts', '59' => 'Products', '75' => 'Vendors', '80' => 'SalesOrder', '76' => 'Potentials', '73' => 'Accounts', '81' => 'Vendors', '78' => 'Quotes');
     #################################################################################
     $uitypelist = array('10', '58', '51', '57', '68', '59', '75', '80', '76', '73', '81', '52', '53', '78');
     $uitype2module = array('58' => 'Campaigns', '51' => 'Accounts', '57' => 'Contacts', '68' => 'Accounts;Contacts', '59' => 'Products', '75' => 'Vendors', '80' => 'SalesOrder', '76' => 'Potentials', '73' => 'Accounts', '81' => 'Vendors', '52' => 'Users', '53' => 'Users', '78' => 'Quotes');
     #################################################################################
     $ui_datefields = array('70', '5', '23');
     #################################################################################
     $ui_currfields = array('71', '72', '7');
     #################################################################################
     if ($module == 'Activity') {
         $wynik = $db->query("select tabid,name from vtiger_tab where name='Calendar'", true);
     } else {
         $wynik = $db->query("select tabid,name from vtiger_tab where name='{$module}'", true);
     }
     $moduleid = $db->query_result($wynik, 0, "tabid");
     $list = array();
     $pobierz = $db->query("select fieldid,uitype, fieldname from vtiger_field where tabid = '{$moduleid}'", true);
     for ($i = 0; $i < $db->num_rows($pobierz); $i++) {
         $uitype = $db->query_result($pobierz, $i, "uitype");
         $fieldid = $db->query_result($pobierz, $i, "fieldid");
         if (in_array($uitype, $uitypelist)) {
             if ($uitype == '10') {
                 $wynik = $db->query("select relmodule from vtiger_fieldmodulerel where fieldid = '{$fieldid}'", true);
                 for ($k = 0; $k < $db->num_rows($wynik); $k++) {
                     $list[$db->query_result($wynik, $k, "relmodule")] = $fields[$db->query_result($pobierz, $i, "fieldname")];
                 }
             } else {
                 $zmienna = $uitype2module[$uitype];
                 $zmienna = explode(';', $zmienna);
                 foreach ($zmienna as $value) {
                     $list[$value] = $fields[$db->query_result($pobierz, $i, "fieldname")];
                 }
             }
         }
     }
     if (count($list) > 0) {
         foreach ($list as $name => $record) {
             $modulename = $name;
             require_once "modules/{$modulename}/{$modulename}.php";
             if ($modulename == 'Users') {
                 $obiekt = new $modulename();
                 $pobierz_usera = $db->query("select * from vtiger_users where id = '{$record}'", true);
                 if ($db->num_rows($pobierz_usera) > 0) {
                     $obiekt->retrieve_entity_info($record, $modulename);
                 }
             } else {
                 $obiekt = new $modulename();
                 $assigned_module = getSalesEntityType($record);
                 if (isRecordExists($record) && $assigned_module == $modulename) {
                     $obiekt->retrieve_entity_info($record, $modulename);
                 }
             }
             $pobierz = $db->query("select tabid from vtiger_tab where name = '{$modulename}'", true);
             $moduleid = $db->query_result($pobierz, 0, "tabid");
             $pobierz_bloki = $db->query("select blockid, blocklabel from vtiger_blocks where tabid = '{$moduleid}'", true);
             $relatedfield_list = array();
             for ($k = 0; $k < $db->num_rows($pobierz_bloki); $k++) {
                 $blockid = $db->query_result($pobierz_bloki, $k, "blockid");
                 $label = $db->query_result($pobierz_bloki, $k, "blocklabel");
                 $pobierz_pola = $db->query("select fieldname,fieldlabel,uitype from vtiger_field where block='{$blockid}' and tabid = '{$moduleid}'", true);
                 for ($i = 0; $i < $db->num_rows($pobierz_pola); $i++) {
                     $field_uitype = $db->query_result($pobierz_pola, $i, "uitype");
                     $label = $db->query_result($pobierz_pola, $i, "fieldlabel");
                     $key = $db->query_result($pobierz_pola, $i, "fieldname");
                     $value = $obiekt->column_fields[$key];
                     ################################################
                     /// for date type fields
                     if (in_array($field_uitype, $ui_datefields) && !empty($field)) {
                         $value = getValidDisplayDate($value);
                     }
                     ################################################
                     /// for currency type fields
                     if (in_array($field_uitype, $ui_currfields)) {
                         $currfield = new CurrencyField($value);
                         $value = $currfield->getDisplayValue();
                     }
                     //// for users language field
                     if ($field_uitype == 27) {
                         if ($value == 'I') {
                             $value = getTranslatedString('Internal', $modulename);
                         } elseif ($value == 'E') {
                             $value = getTranslatedString('External', $modulename);
                         }
                     }
                     if ($field_uitype == 32) {
                         $name = '%' . $value . '%';
                         $new_value = $db->query("select name from vtiger_language where prefix like '{$name}'", true);
                         $value = getTranslatedString($db->query_result($new_value, 0, "name"));
                     }
                     /// dla pól z przypisanym użytkownikie,
                     if ($field_uitype == 53 || $field_uitype == 52) {
                         $value = getUserName($value);
                     }
                     /// dla pól z folderem
                     /* if( $field_uitype == 26 ) {
                     	  $new_value = $db->query( "select foldername from vtiger_attachmentsfolder where folderid = '$value'", true );
                     	  $value = $db->query_result( $new_value, 0, "foldername" );
                     	  } */
                     /// Dla pól z roląużytkownika w organizacji
                     if ($field_uitype == 98) {
                         $new_value = $db->query("select rolename from vtiger_role where roleid = '{$value}'", true);
                         $value = $db->query_result($new_value, 0, "rolename");
                     }
                     /// Dla pól typu checkbox
                     if ($field_uitype == 56) {
                         if ($value == 1) {
                             $value = getTranslatedString('yes', "OSSPdf");
                         } elseif ($value == 0) {
                             $value = getTranslatedString('no', "OSSPdf");
                         }
                     }
                     /// Dla pola ze zdjęciem użytkownika
                     if ($field_uitype == 105) {
                         $recordModel = Users_Record_Model::getInstanceFromUserObject($obiekt);
                         $details = $recordModel->getImageDetails();
                         if (is_array($details[0])) {
                             $value = $details[0]['path'] . '_' . $details[0]['orgname'];
                         } else {
                             $value = '';
                         }
                     }
                     /// Dla pól typu lista wyboru
                     if ($field_uitype == 15 || $field_uitype == 16 || $field_uitype == 55 && $key == 'salutationtype') {
                         $value = getTranslatedString($value, $modulename);
                     }
                     if ($field_uitype == 83) {
                         $pobierz_tax = $db->query("select * from vtiger_producttaxrel where productid = '{$record}'", true);
                         for ($a = 0; $a < $db->num_rows($pobierz_tax); $a++) {
                             $taxid = $db->query_result($pobierz_tax, $a, "taxid");
                             $taxvalue = $db->query_result($pobierz_tax, $a, "taxpercentage");
                             if ($taxid == 1) {
                                 $value .= getTranslatedString('LBL_VAT') . getTranslatedString('COVERED_PERCENTAGE') . ': ' . $taxvalue . '%';
                             } elseif ($taxid == 2) {
                                 $value .= getTranslatedString('LBL_SALES') . getTranslatedString('COVERED_PERCENTAGE') . ': ' . $taxvalue . '%';
                             } elseif ($taxid == 3) {
                                 $value .= getTranslatedString('LBL_SERVICE') . getTranslatedString('COVERED_PERCENTAGE') . ': ' . $taxvalue . '%';
                             }
                             $value .= '<br/>';
                         }
                     }
                     ########################
                     if (in_array($field_uitype2, $uitypelist2)) {
                         if ($field_uitype == 10) {
                             $pobierz_wartosc = $db->query("select relmodule from vtiger_fieldmodulerel where fieldid = '{$fieldid}'", true);
                             for ($i = 0; $i < $db->num_rows($pobierz_wartosc); $i++) {
                                 $module .= $db->query_result($pobierz_wartosc, $i, "relmodule") . ';';
                             }
                         } else {
                             $module = $uitype2module[$field_uitype];
                         }
                         $module = trim($module, ';');
                         $ids = explode(';', $module);
                         foreach ($ids as $singleid) {
                             $newvalue = $db->query("select tablename, entityidfield,fieldname from vtiger_entityname where modulename = '{$singleid}'", true);
                             $tablename = $db->query_result($newvalue, 0, "tablename");
                             $fieldname = $db->query_result($newvalue, 0, "fieldname");
                             $tableid = $db->query_result($newvalue, 0, "entityidfield");
                             $newvalue2 = $db->query("select {$fieldname} from {$tablename} where {$tableid} = '{$value}'", true);
                             $value = $db->query_result($newvalue2, 0, $fieldname);
                         }
                     }
                     ########################
                     if ($field_uitype == 10 && is_numeric($value)) {
                         if ($value != 0) {
                             $value = Vtiger_Functions::getCRMRecordLabel($value);
                         } elseif ($value == 0) {
                             $value = '';
                         }
                     }
                     $string = "#" . $modulename . "_" . $key . "#";
                     $string2 = "#" . $modulename . "_label_" . $key . "#";
                     //."# TLUMACZENIE: ". getTranslatedString( $label, $modulename );
                     $pozycja = (int) strpos($content, $string2);
                     $content = str_replace($string2, getTranslatedString($label, $modulename), $content);
                     if ($record != 0 && ($assigned_module == $modulename || $modulename == 'Users')) {
                         $content = str_replace($string, $value, $content);
                     } else {
                         $content = str_replace($string, '', $content);
                     }
                 }
             }
         }
     }
     return $content;
 }
Ejemplo n.º 29
0
 function updateServiceContractState($focusId)
 {
     $this->id = $focusId;
     $this->retrieve_entity_info($focusId, 'ServiceContracts');
     $contractTicketsResult = $this->db->pquery("SELECT relcrmid FROM vtiger_crmentityrel\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE module = 'ServiceContracts'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND relmodule = 'HelpDesk' AND crmid = ?\n\t\t\t\t\t\t\t\t\t\t\t\t\tUNION\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tSELECT crmid FROM vtiger_crmentityrel\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE relmodule = 'ServiceContracts'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tAND module = 'HelpDesk' AND relcrmid = ?", array($focusId, $focusId));
     $noOfTickets = $this->db->num_rows($contractTicketsResult);
     $ticketFocus = CRMEntity::getInstance('HelpDesk');
     $totalUsedUnits = 0;
     for ($i = 0; $i < $noOfTickets; ++$i) {
         $ticketId = $this->db->query_result($contractTicketsResult, $i, 'relcrmid');
         $ticketFocus->id = $ticketId;
         if (isRecordExists($ticketId)) {
             $ticketFocus->retrieve_entity_info($ticketId, 'HelpDesk');
             if (strtolower($ticketFocus->column_fields['ticketstatus']) == 'closed') {
                 $totalUsedUnits += $this->computeUsedUnits($ticketFocus->column_fields);
             }
         }
     }
     $this->updateUsedUnits($totalUsedUnits);
     $this->calculateProgress();
 }
Ejemplo n.º 30
0
	/**
	 * Replaces related module variables with values
	 * @param string $content - text
	 * @param integer $recordId - if od main module record
	 * @return string text with replaced values
	 */
	public function replaceRelatedModuleFields(&$content, $recordId)
	{
		$recordModel = $this->getRecordModelById($recordId);
		$fieldsModel = $this->getFieldsById($recordId);
		$fieldsTypes = ['reference', 'owner', 'multireference'];

		foreach ($fieldsModel as $fieldName => &$fieldModel) {
			$fieldType = $fieldModel->getFieldDataType();
			if (in_array($fieldType, $fieldsTypes)) {
				$value = $recordModel->get($fieldName);
				$referenceModules = $fieldModel->getReferenceList();
				if ($type == 'owner')
					$referenceModules = ['Users'];
				foreach ($referenceModules as $module) {
					if ($module == 'Users') {
						$referenceRecordModel = Users_Record_Model::getInstanceById($value, $module);
					} else {
						if (!isRecordExists($value)) {
							continue;
						}
						$referenceRecordModel = $this->getRecordModelById($value);
					}
					$moduleModel = $referenceRecordModel->getModule();
					foreach ($moduleModel->getFields() as $referenceFieldName => &$referenceFieldModel) {
						$replaceBy = $referenceRecordModel->getDisplayValue($referenceFieldName, $value, true);
						$content = str_replace('$' . $fieldName . '|' . $module . '|' . $referenceFieldName . '$', $replaceBy, $content);
						$newLabel = Vtiger_Language_Handler::getLanguageTranslatedString($this->get('language'), $referenceFieldModel->get('label'), $module);
						$content = str_replace('%' . $fieldName . '|' . $module . '|' . $referenceFieldName . '%', $newLabel, $content);
					}
				}
			}
		}
		return $content;
	}