Ejemplo n.º 1
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']]);
             }
         }
     }
 }
Ejemplo n.º 2
0
 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);
         }
     }
 }
Ejemplo n.º 3
0
 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]);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
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']));
                 }
             }
         }
     }
 }