function handleEvent($eventName, $data)
 {
     $moduleName = $data->getModuleName();
     if ($eventName == 'vtiger.entity.aftersave.final' && $moduleName == 'ProjectTask') {
         $recordId = $data->getId();
         if ($data->isNew()) {
             $recordModel = Vtiger_Module_Model::getInstance('ProjectMilestone');
             $recordModel->updateProgressMilestone($data->get('projectmilestoneid'));
         } else {
             vimport('include.events.VTEntityDelta');
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             foreach ($delta as $name => $value) {
                 if ($name == 'projectmilestoneid' || $name == 'estimated_work_time' || $name == 'projecttaskprogress') {
                     $recordModel = Vtiger_Module_Model::getInstance('ProjectMilestone');
                     if ($name == 'projectmilestoneid') {
                         $recordModel->updateProgressMilestone($value['currentValue']);
                         $recordModel->updateProgressMilestone($value['oldValue']);
                     } else {
                         $recordModel->updateProgressMilestone($data->get('projectmilestoneid'));
                     }
                 }
             }
         }
     } elseif ($eventName == 'vtiger.entity.afterdelete' && $moduleName == 'ProjectTask') {
         $recordModel = Vtiger_Module_Model::getInstance('ProjectMilestone');
         $recordModel->updateProgressMilestone($data->get('projectmilestoneid'));
     } elseif ($eventName == 'vtiger.entity.afterrestore' && $moduleName == 'ProjectTask') {
         $recordModel = Vtiger_Module_Model::getInstance('ProjectMilestone');
         $recordModel->updateProgressMilestone($data->get('projectmilestoneid'));
     }
 }
Esempio n. 2
0
 function handleEvent($eventName, $entityData)
 {
     global $adb, $shared_owners;
     if ($eventName == 'vtiger.entity.aftersave.final' && $shared_owners == true) {
         $moduleName = $entityData->getModuleName();
         $recordId = $entityData->getId();
         $vtEntityDelta = new VTEntityDelta();
         $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
         $shownerids = $entityData->get('shownerid');
         $inheritsharing = $entityData->get('inheritsharing');
         if (array_key_exists("shownerid", $delta)) {
             $usersUpadated = TRUE;
             $oldValue = Vtiger_Functions::getArrayFromValue($delta['shownerid']['oldValue']);
             $currentValue = Vtiger_Functions::getArrayFromValue($delta['shownerid']['currentValue']);
             $addUsers = $currentValue;
             $removeUser = array_diff($oldValue, $currentValue);
         } else {
             $usersUpadated = FALSE;
         }
         $updateRelatedRecords = TRUE;
         if (array_key_exists("inheritsharing", $delta)) {
             $inheritsharing = $delta['inheritsharing']['currentValue'];
             $inheritsharingUpdated = TRUE;
             if ('0' === $delta['inheritsharing']['currentValue']) {
                 $updateRelatedRecords = FALSE;
                 $removedShared = TRUE;
             }
         } else {
             $inheritsharingUpdated = FALSE;
             $inheritsharing = $entityData->get('inheritsharing');
             if (!$inheritsharing) {
                 $updateRelatedRecords = FALSE;
             }
         }
         if ($usersUpadated || $inheritsharingUpdated) {
             if ($updateRelatedRecords) {
                 Users_Privileges_Model::setSharedOwnerRecursively($recordId, $addUsers, $removeUser, $moduleName);
             }
             if ($removedShared) {
                 Users_Privileges_Model::setSharedOwnerRecursively($recordId, [], $addUsers, $moduleName);
             }
         }
     }
     if ($eventName == 'vtiger.entity.link.after' && $shared_owners == true && Vtiger_Processes_Model::getConfig('sales', 'popup', 'update_shared_permissions') == 'true') {
         $destinationModule = array('Products', 'Services');
         if ($entityData['sourceModule'] == 'Potentials' && in_array($entityData['destinationModule'], $destinationModule)) {
             $adb = PearDatabase::getInstance();
             $result1 = $adb->pquery('SELECT smownerid, shownerid FROM vtiger_crmentity WHERE crmid = ?;', array($entityData['destinationRecordId']));
             $result2 = $adb->pquery('SELECT shownerid FROM vtiger_crmentity WHERE crmid = ?;', array($entityData['sourceRecordId']));
             if ($adb->num_rows($result1) == 1 && $adb->num_rows($result2) == 1) {
                 $smownerid = $adb->query_result($result1, 0, 'smownerid') . ',' . $adb->query_result($result1, 0, 'shownerid');
                 $shownerid = $adb->query_result($result2, 0, 'shownerid') . ',' . trim($smownerid, ',');
                 $adb->pquery("UPDATE vtiger_crmentity SET shownerid = ? WHERE crmid = ?;", [trim($shownerid, ','), $entityData['sourceRecordId']]);
             }
         }
     }
 }
 function handleEvent($eventName, $data)
 {
     global $log, $current_module, $adb, $current_user;
     $moduleName = $data->getModuleName();
     $flag = ModTracker::isTrackingEnabledForModule($moduleName);
     if ($flag) {
         if ($eventName == 'vtiger.entity.aftersave.final') {
             $recordId = $data->getId();
             $columnFields = $data->getData();
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             $newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId);
             $newerColumnFields = $newerEntity->getData();
             if (is_array($delta)) {
                 $inserted = false;
                 foreach ($delta as $fieldName => $values) {
                     if ($fieldName != 'modifiedtime') {
                         if (!$inserted) {
                             $checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE 
                                 crmid = ?', array($recordId));
                             if ($adb->num_rows($checkRecordPresentResult)) {
                                 $status = ModTracker::$UPDATED;
                             } else {
                                 $status = ModTracker::$CREATED;
                             }
                             // get modified time from database in case it has been hidden in GUI
                             $crmrs = $adb->pquery('select modifiedtime from vtiger_crmentity where crmid=?', array($recordId));
                             $modtime = $adb->query_result($crmrs, 0, 0);
                             $this->id = $adb->getUniqueId('vtiger_modtracker_basic');
                             $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status)
                                         VALUES(?,?,?,?,?,?)', array($this->id, $recordId, $moduleName, $current_user->id, $modtime, $status));
                             $inserted = true;
                         }
                         $adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)', array($this->id, $fieldName, $values['oldValue'], $values['currentValue']));
                     }
                 }
             }
         }
         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));
         }
         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));
         }
     }
 }
 function isAssignToChanged($moduleName, $recordId, $user)
 {
     $wsModuleName = $this->getWsModuleName($moduleName);
     $handler = vtws_getModuleHandlerFromName($wsModuleName, $user);
     $meta = $handler->getMeta();
     $moduleOwnerFields = $meta->getOwnerFields();
     $assignToChanged = false;
     $vtEntityDelta = new VTEntityDelta();
     foreach ($moduleOwnerFields as $ownerField) {
         $assignToChanged = $vtEntityDelta->hasChanged($moduleName, $recordId, $ownerField);
         if ($assignToChanged) {
             break;
         }
     }
     return $assignToChanged;
 }
 function handleEvent($eventName, $entityData)
 {
     if ($eventName == 'vtiger.entity.aftersave.final' && vglobal('shared_owners') == true) {
         $moduleName = $entityData->getModuleName();
         $recordId = $entityData->getId();
         $vtEntityDelta = new VTEntityDelta();
         $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
         if (array_key_exists('assigned_user_id', $delta)) {
             $usersUpadated = TRUE;
             $oldValue = Vtiger_Functions::getArrayFromValue($delta['assigned_user_id']['oldValue']);
             $currentValue = Vtiger_Functions::getArrayFromValue($delta['assigned_user_id']['currentValue']);
             $addUsers = $currentValue;
             $removeUser = array_diff($oldValue, $currentValue);
             Users_Privileges_Model::setSharedOwnerRecursively($recordId, $addUsers, $removeUser, $moduleName);
         }
     }
 }
Esempio n. 6
0
 public static function recalculateTimeOldValues($record_id, $data)
 {
     require_once 'include/events/VTEntityDelta.php';
     $relatedField = array('accountid', 'contactid', 'ticketid', 'projectid', 'projecttaskid', 'servicecontractsid', 'assetsid');
     $vtEntityDelta = new VTEntityDelta();
     $delta = $vtEntityDelta->getEntityDelta('OSSTimeControl', $record_id, true);
     $recalculateOldValue = false;
     foreach ($relatedField as $key => $val) {
         if (array_key_exists($val, $delta) && $delta[$val]['oldValue'] != 0 && $delta[$val]['currentValue'] == 0) {
             $data->set($val, $delta[$val]['oldValue']);
             $recalculateOldValue = true;
         }
     }
     if ($recalculateOldValue) {
         OSSTimeControl_Record_Model::recalculateTimeControl($data);
     }
 }
Esempio n. 7
0
 function process($data)
 {
     $adb = PearDatabase::getInstance();
     $html = '';
     if ($data['record'] != '') {
         $vtEntityDelta = new VTEntityDelta();
         $delta = $vtEntityDelta->getEntityDelta($data['module'], $data['record']);
         if (count($delta) == 0) {
             return '';
         }
         $tabid = getTabid($data['module']);
         $html = '<ul>';
         foreach ($delta as $fieldName => $values) {
             if ($fieldName != 'modifiedtime' && in_array($fieldName, array('record_id', 'record_module')) == false && strstr($fieldName, 'label') === false) {
                 $result = $adb->pquery("SELECT uitype,fieldlabel FROM vtiger_field WHERE fieldname = ? AND tabid = ?", array($fieldName, $tabid), true);
                 $fieldlabel = $adb->query_result_raw($result, 0, 'fieldlabel');
                 $uitype = $adb->query_result_raw($result, 0, 'uitype');
                 $oldValue = $values['oldValue'];
                 if ($oldValue == '') {
                     $oldValue = 'LBL_NULL_VALUE';
                 }
                 $currentValue = $values['currentValue'];
                 if ($currentValue == '') {
                     $currentValue = 'LBL_NULL_VALUE';
                 }
                 if ($uitype == 10 && $oldValue != 'LBL_NULL_VALUE' && $currentValue != 'LBL_NULL_VALUE') {
                     $oldValue = Vtiger_Functions::getCRMRecordLabel($oldValue);
                     $currentValue = Vtiger_Functions::getCRMRecordLabel($currentValue);
                 } elseif (in_array($uitype, array('53', '52', '77')) && $oldValue != 'LBL_NULL_VALUE' && $currentValue != 'LBL_NULL_VALUE') {
                     $oldValue = Vtiger_Functions::getOwnerRecordLabel($oldValue);
                     $currentValue = Vtiger_Functions::getOwnerRecordLabel($currentValue);
                 } elseif ($uitype == 56 && $oldValue != 'LBL_NULL_VALUE' && $currentValue != 'LBL_NULL_VALUE') {
                     $oldValue = $oldValue == 1 ? vtranslate('LBL_YES', $data['module']) : vtranslate('LBL_NO', $data['module']);
                     $currentValue = $currentValue == 1 ? vtranslate('LBL_YES', $data['module']) : vtranslate('LBL_NO', $data['module']);
                 } else {
                     $oldValue = vtranslate($oldValue, $data['module']);
                     $currentValue = vtranslate($currentValue, $data['module']);
                 }
                 $html .= '<li>' . vtranslate('LBL_CHANGED', $data['module']) . ' <strong>' . vtranslate($fieldlabel, $data['module']) . '</strong> ' . vtranslate('LBL_FROM') . ' <i>' . $oldValue . '</i> ' . vtranslate('LBL_TO') . ' <i>' . $currentValue . '</i></li>';
             }
         }
         $html .= '</ul>';
         return $html;
     }
 }
Esempio n. 8
0
 function handleEvent($eventName, $entityData)
 {
     if ($eventName == 'vtiger.entity.aftersave.final') {
         $adb = PearDatabase::getInstance();
         $log = vglobal('log');
         $recordId = $entityData->getId();
         $moduleName = $entityData->getModuleName();
         $isNew = $entityData->isNew();
         if (!$isNew && $moduleName == 'Contacts') {
             $updateRecord = false;
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             $delta = array_change_key_case($delta, CASE_LOWER);
             $fields = array('firstname', 'lastname', 'email', 'secondary_email', 'phone', 'mobile');
             foreach ($fields as $val) {
                 if (isset($delta[$val])) {
                     $updateRecord = true;
                     break;
                 }
             }
             if ($updateRecord) {
                 $adb->pquery('UPDATE vtiger_contactdetails SET dav_status = ? WHERE contactid = ?', array(1, $recordId));
             }
         }
         if (!$isNew && $moduleName == 'OSSEmployees') {
             $updateRecord = false;
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             $delta = array_change_key_case($delta, CASE_LOWER);
             $fields = array('name', 'last_name', 'business_phone', 'business_mail', 'private_phone', 'private_mail');
             foreach ($fields as $val) {
                 if (isset($delta[$val])) {
                     $updateRecord = true;
                     break;
                 }
             }
             if ($updateRecord) {
                 $adb->pquery('UPDATE vtiger_ossemployees SET dav_status = ? WHERE ossemployeesid = ?', array(1, $recordId));
             }
         }
     }
 }
 function handleEvent($eventName, $entityData)
 {
     if ($eventName == 'vtiger.entity.aftersave.final' && vglobal('shared_owners') == true) {
         $moduleName = $entityData->getModuleName();
         $recordId = $entityData->getId();
         $vtEntityDelta = new VTEntityDelta();
         $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
         if (array_key_exists('assigned_user_id', $delta)) {
             $usersUpadated = TRUE;
             $oldValue = Vtiger_Functions::getArrayFromValue($delta['assigned_user_id']['oldValue']);
             $currentValue = Vtiger_Functions::getArrayFromValue($delta['assigned_user_id']['currentValue']);
             $addUsers = $currentValue;
             $removeUser = array_diff($oldValue, $currentValue);
             Users_Privileges_Model::setSharedOwnerRecursively($recordId, $addUsers, $removeUser, $moduleName);
         }
     }
     if ($eventName == 'vtiger.entity.link.after' && vglobal('shared_owners') == true && Vtiger_Processes_Model::getConfig('sales', 'popup', 'update_shared_permissions') == 'true') {
         $destinationModule = ['Products', 'Services'];
         if ($entityData['sourceModule'] == 'Potentials' && in_array($entityData['destinationModule'], $destinationModule)) {
             $db = PearDatabase::getInstance();
             $sourceRecordId =& $entityData['sourceRecordId'];
             $destinationRecordId =& $entityData['destinationRecordId'];
             $recordMetaData = Vtiger_Functions::getCRMRecordMetadata($sourceRecordId);
             $shownerIds = Vtiger_SharedOwner_UIType::getSharedOwners($sourceRecordId, $entityData['sourceModule']);
             $shownerIds[] = $recordMetaData['smownerid'];
             $shownerIds = array_unique($shownerIds);
             $usersExist = [];
             $shownersTable = Vtiger_SharedOwner_UIType::getShownerTable($entityData['destinationModule']);
             $result = $db->pquery('SELECT crmid, userid FROM ' . $shownersTable . ' WHERE userid IN(' . implode(',', $shownerIds) . ') AND crmid = ?', [$destinationRecordId]);
             while ($row = $db->getRow($result)) {
                 $usersExist[$row['crmid']][$row['userid']] = true;
             }
             foreach ($shownerIds as $userId) {
                 if (!isset($usersExist[$destinationRecordId][$userId])) {
                     $db->insert($shownersTable, ['crmid' => $destinationRecordId, 'userid' => $userId]);
                 }
             }
         }
     }
 }
Esempio n. 10
0
 function handleEvent($eventName, $data)
 {
     global $adb, $shared_owners;
     if ($eventName == 'vtiger.entity.aftersave.final' && $shared_owners == true) {
         $moduleName = $data->getModuleName();
         $recordId = $data->getId();
         if ($data->get('inheritsharing') != NULL && $data->get('inheritsharing') !== 0) {
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             if (array_key_exists("shownerid", $delta)) {
                 $oldValue = Vtiger_Functions::getArrayFromValue($delta['shownerid']['oldValue']);
                 $currentValue = Vtiger_Functions::getArrayFromValue($delta['shownerid']['currentValue']);
                 if (count($oldValue) == 0) {
                     $addUser = $currentValue;
                     $removeUser = array();
                 } else {
                     $removeUser = array_diff($oldValue, $currentValue);
                     $addUser = array_diff($currentValue, $oldValue);
                 }
                 Users_Privileges_Model::setSharedOwnerRecursively($recordId, $addUser, $removeUser, $moduleName);
             }
         }
     }
     if ($eventName == 'vtiger.entity.link.after') {
         $destinationModule = array('Products', 'Services');
         if ($entityData['sourceModule'] == 'Potentials' && in_array($entityData['destinationModule'], $destinationModule)) {
             global $adb;
             $result1 = $adb->pquery('SELECT smownerid FROM vtiger_crmentity WHERE crmid = ?;', array($entityData['destinationRecordId']));
             $result2 = $adb->pquery('SELECT smownerid,shownerid FROM vtiger_crmentity WHERE crmid = ?;', array($entityData['sourceRecordId']));
             if ($adb->num_rows($result1) == 1 && $adb->num_rows($result2) == 1) {
                 $smownerid = $adb->query_result($result1, 0, 'smownerid');
                 $shownerid = $adb->query_result($result2, 0, 'shownerid') . ',' . $smownerid;
                 if ($smownerid != $adb->query_result($result2, 0, 'smownerid')) {
                     $adb->pquery("UPDATE vtiger_crmentity SET shownerid = ? WHERE crmid = ?;", array(rtrim($shownerid, ','), $entityData['sourceRecordId']));
                 }
             }
         }
     }
 }
 function handleEvent($eventName, $entityData)
 {
     $moduleName = $entityData->getModuleName();
     // Validate the event target
     if ($moduleName != 'PurchaseOrder') {
         return;
     }
     //Get Current User Information
     global $current_user, $currentModule;
     /**
      * Adjust the balance amount against total & paid amount
      * NOTE: beforesave the total amount will not be populated in event data.
      */
     if ($eventName == 'vtiger.entity.aftersave') {
         if ($currentModule != 'PurchaseOrder') {
             return;
         }
         $entityDelta = new VTEntityDelta();
         $oldCurrency = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $oldConversionRate = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'conversion_rate');
         $newCurrency = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $db = PearDatabase::getInstance();
         $wsid = vtws_getWebserviceEntityId('PurchaseOrder', $entityData->getId());
         $wsrecord = vtws_retrieve($wsid, $current_user);
         if ($oldCurrency != $newCurrency && $oldCurrency != '') {
             if ($oldConversionRate != '') {
                 $wsrecord['paid'] = floatval($wsrecord['paid'] / $oldConversionRate * $wsrecord['conversion_rate']);
             }
         }
         /*
                     $wsrecord['balance'] = floatval($wsrecord['hdnGrandTotal'] - $wsrecord['paid']);
                     if ($wsrecord['balance'] == 0)
                         $wsrecord['postatus'] = 'Received Shipment';
                     $query = "UPDATE vtiger_purchaseorder SET balance=?,paid=? WHERE purchaseorderid=?";
                     $db->pquery($query, array($wsrecord['balance'], $wsrecord['paid'], $entityData->getId()));
                     // TODO Make it available for other event handlers
         */
     }
 }
Esempio n. 12
0
 function handleEvent($eventName, $entityData)
 {
     $moduleName = $entityData->getModuleName();
     // Validate the event target
     if ($moduleName != 'Invoice') {
         return;
     }
     //Get Current User Information
     global $current_user, $currentModule;
     /**
      * Adjust the balance amount against total & received amount
      * NOTE: beforesave the total amount will not be populated in event data.
      */
     if ($eventName == 'vtiger.entity.aftersave') {
         // Trigger from other module (due to indirect save) need to be ignored - to avoid inconsistency.
         if ($currentModule != 'Invoice') {
             return;
         }
         $entityDelta = new VTEntityDelta();
         $oldCurrency = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $newCurrency = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
         $oldConversionRate = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'conversion_rate');
         $db = PearDatabase::getInstance();
         $wsid = vtws_getWebserviceEntityId('Invoice', $entityData->getId());
         $wsrecord = vtws_retrieve($wsid, $current_user);
         if ($oldCurrency != $newCurrency && $oldCurrency != '') {
             if ($oldConversionRate != '') {
                 $wsrecord['received'] = floatval($wsrecord['received'] / $oldConversionRate * $wsrecord['conversion_rate']);
             }
         }
         $wsrecord['balance'] = floatval($wsrecord['hdnGrandTotal'] - $wsrecord['received']);
         if ($wsrecord['balance'] == 0) {
             $wsrecord['invoicestatus'] = 'Paid';
         }
         $query = "UPDATE vtiger_invoice SET balance=?,received=? WHERE invoiceid=?";
         $db->pquery($query, array($wsrecord['balance'], $wsrecord['received'], $entityData->getId()));
     }
 }
Esempio n. 13
0
    function handleEvent($eventName, $entityData)
    {
        $adb = PearDatabase::getInstance();
        $moduleName = $entityData->getModuleName();
        $recordId = $entityData->getId();
        if ($eventName == 'vtiger.entity.beforesave') {
            if (!empty($recordId)) {
                $entityData = VTEntityData::fromEntityId($adb, $recordId);
                if ($moduleName == 'HelpDesk') {
                    $entityData->set('comments', getTicketComments($recordId));
                }
                self::$oldEntity[$moduleName][$recordId] = $entityData;
                if ($moduleName == 'Products') {
                    self::$oldEntity_pimages = array();
                    $sql = 'SELECT vtiger_attachments.`attachmentsid`,name FROM `vtiger_seattachmentsrel`
						inner join vtiger_attachments on vtiger_attachments.`attachmentsid` = `vtiger_seattachmentsrel`.`attachmentsid`
						WHERE `crmid`=?';
                    $imagesrs = $adb->pquery($sql, array($recordId));
                    while ($image = $adb->fetch_array($imagesrs)) {
                        self::$oldEntity_pimages[$image['attachmentsid']] = $image['name'];
                    }
                }
            }
        }
        if ($eventName == 'vtiger.entity.aftersave') {
            $this->fetchEntity($moduleName, $recordId);
            if ($moduleName == 'Products') {
                self::$newEntity_pimages = array();
                $sql = 'SELECT vtiger_attachments.`attachmentsid`,name FROM `vtiger_seattachmentsrel`
					inner join vtiger_attachments on vtiger_attachments.`attachmentsid` = `vtiger_seattachmentsrel`.`attachmentsid`
					WHERE `crmid`=?';
                $imagesrs = $adb->pquery($sql, array($recordId));
                while ($image = $adb->fetch_array($imagesrs)) {
                    self::$newEntity_pimages[$image['attachmentsid']] = $image['name'];
                }
            }
            $this->computeDelta($moduleName, $recordId);
        }
    }
function HelpDesk_notifyOwnerOnTicketChange($entityData)
{
    global $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID;
    $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');
    //$subject = $entityData->get('ticket_no') . ' [ '.getTranslatedString('LBL_TICKET_ID', $moduleName)
    //					.' : '.$entityId.' ] '.$reply.$entityData->get('ticket_title');
    // SalesPlatform.ru end
    $email_body = HelpDesk::getTicketEmailContents($entityData, true);
    if (PerformancePrefs::getBoolean('NOTIFY_OWNER_EMAILS', true) === true) {
        //send mail to the assigned to user and the parent to whom this ticket is assigned
        require_once 'modules/Emails/mail.php';
        $wsAssignedUserId = $entityData->get('assigned_user_id');
        $userIdParts = explode('x', $wsAssignedUserId);
        $ownerId = $userIdParts[1];
        $ownerType = vtws_getOwnerType($ownerId);
        if ($ownerType == 'Users') {
            $to_email = getUserEmailId('id', $ownerId);
        }
        if ($ownerType == 'Groups') {
            $to_email = implode(',', getDefaultAssigneeEmailIds($ownerId));
        }
        if ($to_email != '') {
            if ($isNew) {
                $mail_status = send_mail('HelpDesk', $to_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');
                $descriptionHasChanged = $entityDelta->hasChanged($entityData->getModuleName(), $entityId, 'description');
                if ($statusHasChanged && $entityData->get('ticketstatus') == "Closed" || $solutionHasChanged || $ownerHasChanged || $descriptionHasChanged) {
                    $mail_status = send_mail('HelpDesk', $to_email, $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $email_body);
                }
            }
            $mail_status_str = $to_email . "=" . $mail_status . "&&&";
        } else {
            $mail_status_str = "'" . $to_email . "'=0&&&";
        }
        if ($mail_status != '') {
            $mail_error_status = getMailErrorString($mail_status_str);
        }
    }
}
Esempio n. 15
0
 function handleEvent($eventName, $data)
 {
     $adb = PearDatabase::getInstance();
     $current_user = vglobal('current_user');
     $log = vglobal('log');
     $current_module = vglobal('current_module');
     if (!is_object($data)) {
         $extendedData = $data;
         $data = $extendedData['entityData'];
     }
     $moduleName = $data->getModuleName();
     $flag = ModTracker::isTrackingEnabledForModule($moduleName);
     if ($flag) {
         if ($eventName == 'vtiger.entity.aftersave.final') {
             $recordId = $data->getId();
             $columnFields = $data->getData();
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             $newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId);
             $newerColumnFields = $newerEntity->getData();
             $newerColumnFields = array_change_key_case($newerColumnFields, CASE_LOWER);
             $delta = array_change_key_case($delta, CASE_LOWER);
             if (is_array($delta)) {
                 $inserted = false;
                 foreach ($delta as $fieldName => $values) {
                     if ($fieldName != 'modifiedtime') {
                         if (!$inserted) {
                             $checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE crmid = ?', array($recordId));
                             if (!$adb->num_rows($checkRecordPresentResult) && $data->isNew()) {
                                 $status = ModTracker::$CREATED;
                             } else {
                                 $status = ModTracker::$UPDATED;
                             }
                             $this->id = $adb->getUniqueId('vtiger_modtracker_basic');
                             $adb->insert('vtiger_modtracker_basic', ['id' => $this->id, 'crmid' => $recordId, 'module' => $moduleName, 'whodid' => $current_user->id, 'changedon' => $newerColumnFields['modifiedtime'], 'status' => $status, 'whodidsu' => Vtiger_Session::get('baseUserId')]);
                             $inserted = true;
                         }
                         $adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)', array($this->id, $fieldName, $values['oldValue'], $values['currentValue']));
                     }
                 }
             }
             $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId));
             if ($adb->num_rows($isMyRecord) > 0) {
                 $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId));
             }
         }
         if ($eventName == 'vtiger.entity.beforedelete') {
             $recordId = $data->getId();
             $columnFields = $data->getData();
             $id = $adb->getUniqueId('vtiger_modtracker_basic');
             $adb->insert('vtiger_modtracker_basic', ['id' => $id, 'crmid' => $recordId, 'module' => $moduleName, 'whodid' => $current_user->id, 'changedon' => date('Y-m-d H:i:s', time()), 'status' => ModTracker::$DELETED, 'whodidsu' => Vtiger_Session::get('baseUserId')]);
             $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId));
             if ($adb->num_rows($isMyRecord) > 0) {
                 $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId));
             }
         }
         if ($eventName == 'vtiger.entity.afterrestore') {
             $recordId = $data->getId();
             $columnFields = $data->getData();
             $id = $adb->getUniqueId('vtiger_modtracker_basic');
             $adb->insert('vtiger_modtracker_basic', ['id' => $id, 'crmid' => $recordId, 'module' => $moduleName, 'whodid' => $current_user->id, 'changedon' => date('Y-m-d H:i:s', time()), 'status' => ModTracker::$RESTORED, 'whodidsu' => Vtiger_Session::get('baseUserId')]);
             $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId));
             if ($adb->num_rows($isMyRecord) > 0) {
                 $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId));
             }
         }
         if ($eventName == 'vtiger.entity.link.after') {
             ModTracker::linkRelation($extendedData['sourceModule'], $extendedData['sourceRecordId'], $extendedData['destinationModule'], $extendedData['destinationRecordId']);
         }
         if ($eventName == 'vtiger.entity.unlink.after') {
             ModTracker::unLinkRelation($extendedData['sourceModule'], $extendedData['sourceRecordId'], $extendedData['destinationModule'], $extendedData['destinationRecordId']);
         }
     }
 }
Esempio n. 16
0
function Contacts_sendCustomerPortalLoginDetails($entityData)
{
    $adb = PearDatabase::getInstance();
    $moduleName = $entityData->getModuleName();
    $wsId = $entityData->getId();
    $parts = explode('x', $wsId);
    $entityId = $parts[1];
    $entityDelta = new VTEntityDelta();
    $portalChanged = $entityDelta->hasChanged($moduleName, $entityId, 'portal');
    $email = $entityData->get('email');
    if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
        $sql = "SELECT id, user_name, user_password, isactive FROM vtiger_portalinfo WHERE id=?";
        $result = $adb->pquery($sql, 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;
            } else {
                if ($entityData->get('portal') == 'on' || $entityData->get('portal') == '1') {
                    $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
                    $adb->pquery($sql, array($email, 1, $entityId));
                    $update = true;
                } else {
                    $sql = "UPDATE vtiger_portalinfo SET user_name=?, isactive=? WHERE id=?";
                    $adb->pquery($sql, array($email, 0, $entityId));
                    $update = false;
                }
            }
        }
        $password = makeRandomPassword();
        $md5_password = md5($password);
        if ($insert == true) {
            $sql = "INSERT INTO vtiger_portalinfo(id,user_name,user_password,type,isactive) VALUES(?,?,?,?,?)";
            $params = array($entityId, $email, $md5_password, 'C', 1);
            $adb->pquery($sql, $params);
        }
        if ($update == true && $portalChanged == true) {
            $sql = "UPDATE vtiger_portalinfo SET user_password=? WHERE id=?";
            $params = array($md5_password, $entityId);
            $adb->pquery($sql, $params);
        }
        if (($insert == true || ($update = true && $portalChanged == true)) && $entityData->get('emailoptout') == 0) {
            global $current_user, $HELPDESK_SUPPORT_EMAIL_ID, $HELPDESK_SUPPORT_NAME;
            require_once "modules/Emails/mail.php";
            $emailData = Contacts::getPortalEmailContents($entityData, $password, 'LoginDetails');
            $subject = $emailData['subject'];
            if (empty($subject)) {
                $subject = 'Customer Portal Login Details';
            }
            $contents = $emailData['body'];
            $contents = decode_html(getMergedDescription($contents, $entityId, 'Contacts'));
            if (empty($contents)) {
                require_once 'config.inc.php';
                global $PORTAL_URL;
                $contents = 'LoginDetails';
                $contents .= "<br><br> User ID : " . $entityData->get('email');
                $contents .= "<br> Password: "******"' . $PORTAL_URL . '" style="font-family:Arial, Helvetica, sans-serif;font-size:13px;">' . vtranslate('click here', $moduleName) . '</a>';
                $contents .= "<br>" . $portalURL;
            }
            $subject = decode_html(getMergedDescription($subject, $entityId, 'Contacts'));
            send_mail('Contacts', $entityData->get('email'), $HELPDESK_SUPPORT_NAME, $HELPDESK_SUPPORT_EMAIL_ID, $subject, $contents, '', '', '', '', '', true);
        }
    } else {
        $sql = "UPDATE vtiger_portalinfo SET user_name=?,isactive=0 WHERE id=?";
        $adb->pquery($sql, array($email, $entityId));
    }
}
Esempio n. 17
0
function updateInventoryProductRel($entity)
{
    global $log, $adb, $updateInventoryProductRel_update_product_array, $updateInventoryProductRel_deduct_stock;
    $entity_id = vtws_getIdComponents($entity->getId());
    $entity_id = $entity_id[1];
    $update_product_array = $updateInventoryProductRel_update_product_array;
    $log->debug("Entering into function updateInventoryProductRel(" . $entity_id . ").");
    if (!empty($update_product_array)) {
        foreach ($update_product_array as $id => $seq) {
            foreach ($seq as $seq => $product_info) {
                foreach ($product_info as $key => $index) {
                    $updqtyinstk = getPrdQtyInStck($key);
                    $upd_qty = $updqtyinstk + $index;
                    updateProductQty($key, $upd_qty);
                }
            }
        }
    }
    $moduleName = $entity->getModuleName();
    if ($moduleName === 'Invoice') {
        $statusFieldName = 'invoicestatus';
        $statusFieldValue = 'Cancel';
    } elseif ($moduleName === 'PurchaseOrder') {
        $statusFieldName = 'postatus';
        $statusFieldValue = 'Received Shipment';
    }
    $statusChanged = false;
    $vtEntityDelta = new VTEntityDelta();
    $oldEntity = $vtEntityDelta->getOldValue($moduleName, $entity_id, $statusFieldName);
    $recordDetails = $entity->getData();
    $statusChanged = $vtEntityDelta->hasChanged($moduleName, $entity_id, $statusFieldName);
    if ($statusChanged) {
        if ($recordDetails[$statusFieldName] == $statusFieldValue) {
            $adb->pquery("UPDATE vtiger_inventoryproductrel SET incrementondel=0 WHERE id=?", array($entity_id));
            $updateInventoryProductRel_deduct_stock = false;
            if (empty($update_product_array)) {
                addProductsToStock($entity_id);
            }
        } elseif ($oldEntity == $statusFieldValue) {
            $updateInventoryProductRel_deduct_stock = false;
            deductProductsFromStock($entity_id);
        }
    } elseif ($recordDetails[$statusFieldName] == $statusFieldValue) {
        $updateInventoryProductRel_deduct_stock = false;
    }
    if ($updateInventoryProductRel_deduct_stock) {
        $adb->pquery("UPDATE vtiger_inventoryproductrel SET incrementondel=1 WHERE id=?", array($entity_id));
        $product_info = $adb->pquery("SELECT productid,sequence_no, quantity from vtiger_inventoryproductrel WHERE id=?", array($entity_id));
        $numrows = $adb->num_rows($product_info);
        for ($index = 0; $index < $numrows; $index++) {
            $productid = $adb->query_result($product_info, $index, 'productid');
            $qty = $adb->query_result($product_info, $index, 'quantity');
            $sequence_no = $adb->query_result($product_info, $index, 'sequence_no');
            $qtyinstk = getPrdQtyInStck($productid);
            $upd_qty = $qtyinstk - $qty;
            updateProductQty($productid, $upd_qty);
            $sub_prod_query = $adb->pquery("SELECT productid from vtiger_inventorysubproductrel WHERE id=? AND sequence_no=?", array($entity_id, $sequence_no));
            if ($adb->num_rows($sub_prod_query) > 0) {
                for ($j = 0; $j < $adb->num_rows($sub_prod_query); $j++) {
                    $sub_prod_id = $adb->query_result($sub_prod_query, $j, "productid");
                    $sqtyinstk = getPrdQtyInStck($sub_prod_id);
                    $supd_qty = $sqtyinstk - $qty;
                    updateProductQty($sub_prod_id, $supd_qty);
                }
            }
        }
    }
    $log->debug("Exit from function updateInventoryProductRel(" . $entity_id . ")");
}
Esempio n. 18
0
 function handleEvent($eventName, $data)
 {
     global $log, $current_module, $adb, $current_user;
     $moduleName = $data->getModuleName();
     $flag = ModTracker::isTrackingEnabledForModule($moduleName);
     if ($flag) {
         if ($eventName == 'vtiger.entity.aftersave.final') {
             $recordId = $data->getId();
             $columnFields = $data->getData();
             $vtEntityDelta = new VTEntityDelta();
             $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
             $newerEntity = $vtEntityDelta->getNewEntity($moduleName, $recordId);
             $newerColumnFields = $newerEntity->getData();
             $newerColumnFields = array_change_key_case($newerColumnFields, CASE_LOWER);
             $delta = array_change_key_case($delta, CASE_LOWER);
             if (is_array($delta)) {
                 $inserted = false;
                 foreach ($delta as $fieldName => $values) {
                     if ($fieldName != 'modifiedtime') {
                         if (!$inserted) {
                             $checkRecordPresentResult = $adb->pquery('SELECT * FROM vtiger_modtracker_basic WHERE 
                                 crmid = ?', array($recordId));
                             if (!$adb->num_rows($checkRecordPresentResult) && $data->isNew()) {
                                 $status = ModTracker::$CREATED;
                             } else {
                                 $status = ModTracker::$UPDATED;
                             }
                             $this->id = $adb->getUniqueId('vtiger_modtracker_basic');
                             $adb->pquery('INSERT INTO vtiger_modtracker_basic(id, crmid, module, whodid, changedon, status)
                                         VALUES(?,?,?,?,?,?)', array($this->id, $recordId, $moduleName, $current_user->id, $newerColumnFields['modifiedtime'], $status));
                             $inserted = true;
                         }
                         $adb->pquery('INSERT INTO vtiger_modtracker_detail(id,fieldname,prevalue,postvalue) VALUES(?,?,?,?)', array($this->id, $fieldName, $values['oldValue'], $values['currentValue']));
                     }
                 }
             }
             $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId));
             if ($adb->num_rows($isMyRecord) > 0) {
                 $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId));
             }
         }
         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));
             $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId));
             if ($adb->num_rows($isMyRecord) > 0) {
                 $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId));
             }
         }
         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));
             $isMyRecord = $adb->pquery('SELECT crmid FROM vtiger_crmentity WHERE smownerid <> ? AND crmid = ?', array($current_user->id, $recordId));
             if ($adb->num_rows($isMyRecord) > 0) {
                 $adb->pquery("UPDATE vtiger_crmentity SET was_read = 0 WHERE crmid = ?;", array($recordId));
             }
         }
     }
 }