function handleEvent($eventName, $data)
 {
     if ($eventName == 'vtiger.entity.beforesave') {
         // Entity is about to be saved, take required action
     }
     if ($eventName == 'vtiger.entity.aftersave') {
         $db = PearDatabase::getInstance();
         $relatedToId = $data->get('related_to');
         if ($relatedToId) {
             $moduleName = getSalesEntityType($relatedToId);
             $focus = CRMEntity::getInstance($moduleName);
             $focus->retrieve_entity_info($relatedToId, $moduleName);
             $focus->id = $relatedToId;
             $fromPortal = $data->get('from_portal');
             if ($fromPortal) {
                 $focus->column_fields['from_portal'] = $fromPortal;
             }
             $entityData = VTEntityData::fromCRMEntity($focus);
             $wfs = new VTWorkflowManager($db);
             $relatedToEventHandler = new VTWorkflowEventHandler();
             $relatedToEventHandler->workflows = $wfs->getWorkflowsForModuleSupportingComments($entityData->getModuleName());
             $wsId = vtws_getWebserviceEntityId($entityData->getModuleName(), $entityData->getId());
             $fromPortal = $entityData->get('from_portal');
             $util = new VTWorkflowUtils();
             $entityCache = new VTEntityCache($util->adminUser());
             $entityCacheData = $entityCache->forId($wsId);
             $entityCacheData->set('from_portal', $fromPortal);
             $entityCache->cache[$wsId] = $entityCacheData;
             $relatedToEventHandler->handleEvent($eventName, $entityData, $entityCache);
             $util->revertUser();
         }
     }
 }
示例#2
0
 function fetchEntity($moduleName, $recordId)
 {
     $adb = PearDatabase::getInstance();
     $entityData = VTEntityData::fromEntityId($adb, $recordId);
     if ($moduleName == 'HelpDesk') {
         $entityData->set('comments', getTicketComments($recordId));
     }
     self::$newEntity[$moduleName][$recordId] = $entityData;
 }
 function handleEvent($eventName, $entityData)
 {
     $adb = PearDatabase::getInstance();
     $moduleName = $entityData->getModuleName();
     $recordId = $entityData->getId();
     if ($eventName == 'vtiger.entity.beforesave') {
         if (!empty($recordId)) {
             self::$oldEntity[$moduleName][$recordId] = VTEntityData::fromEntityId($adb, $recordId);
         }
     }
     if ($eventName == 'vtiger.entity.aftersave') {
         self::$newEntity[$moduleName][$recordId] = VTEntityData::fromEntityId($adb, $recordId);
         $this->computeDelta($moduleName, $recordId);
     }
 }
示例#4
0
function vtws_sendRecoverPassword($username)
{
    global $adb, $log, $current_user, $PORTAL_URL, $url_code;
    $log->debug("Entering function vtws_sendRecoverPassword");
    $ctors = $adb->query("select contactid,email,user_password\n\t\t\tfrom vtiger_contactdetails\n\t\t\tinner join vtiger_portalinfo on id=contactid\n\t\t\twhere isactive=1 and user_name='{$username}'");
    if (!ctors or $adb->num_rows($ctors) == 0) {
        throw new WebServiceException(WebServiceErrorCode::$INVALIDUSERPWD, "Invalid username: username not found or not active");
    }
    require_once 'modules/Emails/mail.php';
    require_once 'modules/Contacts/Contacts.php';
    $cto = $adb->fetch_array($ctors);
    $password = $cto['user_password'];
    $entityData = VTEntityData::fromEntityId($adb, $cto['contactid']);
    $contents = Contacts::getPortalEmailContents($entityData, $password);
    $subject = getTranslatedString('Customer Portal Login Details', 'Contacts');
    $mail_status = send_mail('Contacts', $cto['email'], $current_user->user_name, "", $subject, $contents);
    $log->debug("Exiting function vtws_sendRecoverPassword");
    return $mail_status;
}
 public function save()
 {
     ${"GLOBALS"}["ducixeik"] = "additionalProductFields";
     ${${"GLOBALS"}["wtrcwdueuts"]} = PearDatabase::getInstance();
     ${${"GLOBALS"}["ducixeik"]} = $this->getAdditionalProductFields();
     ${"GLOBALS"}["molcrpc"] = "manualUpdateFields";
     ${"GLOBALS"}["gbmhcqh"] = "tmp";
     ${"GLOBALS"}["ewjsruuy"] = "fieldName";
     ${${"GLOBALS"}["molcrpc"]} = array();
     foreach (${${"GLOBALS"}["vptmrj"]} as ${${"GLOBALS"}["ewjsruuy"]} => ${${"GLOBALS"}["gbmhcqh"]}) {
         if (${${"GLOBALS"}["ykppheofobwk"]}["implemented"] == false) {
             $jpmxewcq = "relData";
             ${"GLOBALS"}["fkfnvsuaox"] = "manualUpdateFields";
             ${${"GLOBALS"}["fkfnvsuaox"]}[] = ${${"GLOBALS"}["thpgoyrlu"]};
             ${$jpmxewcq} = $this->_getProductRelData();
         }
     }
     require_once "modules/Emails/mail.php";
     if (!empty($this->_id) && $this->_changed == true) {
         $this->_changedProducts = $this->_changed;
         if ($this->_listitems === null) {
             $this->_loadProducts();
         }
     }
     parent::save();
     $this->prepareTransfer();
     if (!empty($this->_currencyID)) {
         ${${"GLOBALS"}["xkutivbm"]} = $this->_currencyID;
     } else {
         $ogqhrcro = "currency_id";
         ${$ogqhrcro} = false;
     }
     $this->clearData();
     if ($this->_changedProducts === true) {
         ${"GLOBALS"}["tgkrfb"] = "shipping_handling_charge";
         ${"GLOBALS"}["negltbro"] = "field";
         ${${"GLOBALS"}["amsupsflnmf"]} = $this->get("hdnTaxType");
         ${"GLOBALS"}["hxnewftfdqn"] = "i";
         ${"GLOBALS"}["etqhqirsnh"] = "taxtype";
         $agoclef = "adjustment";
         ${$agoclef} = 0;
         ${${"GLOBALS"}["tgkrfb"]} = 0;
         $qwpblm = "i";
         ${"GLOBALS"}["krxwtxw"] = "fields";
         ${${"GLOBALS"}["whqnrjvsw"]} = getAllTaxes();
         $nxxrnbh = "intObject";
         $mdwcbjhvim = "availTaxes";
         $vaqwwrr = "value";
         $_REQUEST["totalProductCount"] = count($this->_listitems);
         $_REQUEST["taxtype"] = ${${"GLOBALS"}["etqhqirsnh"]};
         $_REQUEST["subtotal"] = 0;
         ${${"GLOBALS"}["pponynktout"]} = $this->getProductFields();
         foreach (${${"GLOBALS"}["krxwtxw"]} as ${${"GLOBALS"}["negltbro"]} => ${$vaqwwrr}) {
             $_REQUEST[${${"GLOBALS"}["mlsoidilfq"]}] = ${${"GLOBALS"}["cqlhrtj"]};
         }
         for (${${"GLOBALS"}["hxnewftfdqn"]} = 1; ${${"GLOBALS"}["jsntgvnqkf"]} <= count($this->_listitems); ${${"GLOBALS"}["jsntgvnqkf"]}++) {
             ${"GLOBALS"}["zepdlqparq"] = "i";
             $_REQUEST["subtotal"] += ${${"GLOBALS"}["pponynktout"]}["productTotal" . ${${"GLOBALS"}["zepdlqparq"]}];
         }
         $klivirms = "intObject";
         $cnavotvg = "globalTaxValue";
         ${"GLOBALS"}["ouawiowlgku"] = "shipTaxValue";
         $_REQUEST["discount_percentage_final"] = $this->get("hdnDiscountPercent");
         $_REQUEST["discount_percentage_final"] = floatval($_REQUEST["discount_percentage_final"]);
         $_REQUEST["discount_amount_final"] = $this->get("hdnDiscountAmount");
         $_REQUEST["discount_amount_final"] = floatval($_REQUEST["discount_amount_final"]);
         $_REQUEST["discount_type_final"] = !empty($_REQUEST["discount_percentage_final"]) ? "percentage" : "amount";
         $_REQUEST["total"] = $_REQUEST["subtotal"];
         if ($_REQUEST["discount_type_final"] == "amount") {
             $_REQUEST["total"] -= $_REQUEST["discount_amount_final"];
         } elseif ($_REQUEST["discount_type_final"] == "percentage") {
             $_REQUEST["total"] -= $_REQUEST["total"] * ($_REQUEST["discount_percentage_final"] / 100);
         }
         ${$cnavotvg} = 0;
         if (${${"GLOBALS"}["amsupsflnmf"]} == "group") {
             ${"GLOBALS"}["yirabwmnwgyp"] = "globalTaxValue";
             $oplkjyxi = "availTaxes";
             foreach (${$oplkjyxi} as ${${"GLOBALS"}["wfuwxbmiwytq"]}) {
                 $psuluqnb = "request_tax_name";
                 $enefpgduf = "tax";
                 ${"GLOBALS"}["wxlvsgkcw"] = "request_tax_name";
                 ${${"GLOBALS"}["hvjpdk"]} = ${$enefpgduf}["taxname"];
                 ${${"GLOBALS"}["wxlvsgkcw"]} = ${${"GLOBALS"}["hvjpdk"]} . "_group_percentage";
                 $lifliipv = "request_tax_name";
                 $_REQUEST[${${"GLOBALS"}["hwivgkl"]}] = isset($this->_groupTax[${${"GLOBALS"}["hwivgkl"]}]) ? $this->_groupTax[${$psuluqnb}] : 0;
                 $bltbxkcxbjyp = "tmpTaxValue";
                 ${${"GLOBALS"}["fvbuscvwjf"]} = $_REQUEST["total"] * ($_REQUEST[${$lifliipv}] / 100);
                 ${${"GLOBALS"}["zjswudci"]} += ${$bltbxkcxbjyp};
             }
             $_REQUEST["total"] += ${${"GLOBALS"}["yirabwmnwgyp"]};
         }
         $_REQUEST["shipping_handling_charge"] = $this->_shippingCost;
         ${${"GLOBALS"}["cxnjuagap"]} = 0;
         $bbluqvmmcrl = "tax";
         foreach (${$mdwcbjhvim} as ${$bbluqvmmcrl}) {
             $rbwcrso = "request_tax_name";
             ${"GLOBALS"}["woxvppdlct"] = "tmpTaxValue";
             $xeqhidsvg = "shipTaxValue";
             ${"GLOBALS"}["rihoezbjibn"] = "tax_name";
             ${${"GLOBALS"}["rihoezbjibn"]} = ${${"GLOBALS"}["wfuwxbmiwytq"]}["taxname"];
             ${$rbwcrso} = ${${"GLOBALS"}["hvjpdk"]} . "_sh_percent";
             $uaabpfjmwc = "request_tax_name";
             $_REQUEST["sh" . ${${"GLOBALS"}["hwivgkl"]}] = isset($this->_shipTaxes[${${"GLOBALS"}["hwivgkl"]}]) ? $this->_shipTaxes[${${"GLOBALS"}["hwivgkl"]}] : 0;
             ${${"GLOBALS"}["fvbuscvwjf"]} = $_REQUEST["shipping_handling_charge"] * ($_REQUEST["sh" . ${$uaabpfjmwc}] / 100);
             ${$xeqhidsvg} += ${${"GLOBALS"}["woxvppdlct"]};
         }
         $_REQUEST["total"] += ${${"GLOBALS"}["ouawiowlgku"]} + $_REQUEST["shipping_handling_charge"];
         $_REQUEST["adjustment"] = floatval($this->get("txtAdjustment"));
         $_REQUEST["total"] += $_REQUEST["adjustment"];
         ${$nxxrnbh} = $this->getInternalObject();
         $intObject->mode = "edit";
         $intObject->isLineItemUpdate = true;
         @saveInventoryProductDetails(${$klivirms}, $this->getModuleName());
         for (${${"GLOBALS"}["jsntgvnqkf"]} = 1; ${${"GLOBALS"}["jsntgvnqkf"]} <= count($this->_listitems); ${$qwpblm}++) {
             ${"GLOBALS"}["xzgznik"] = "values";
             ${${"GLOBALS"}["xzgznik"]} = array();
             $dqnotemwlbq = "params";
             ${$dqnotemwlbq} = array();
             foreach (${${"GLOBALS"}["ogvkpmc"]} as ${${"GLOBALS"}["nctgtuliixp"]}) {
                 ${"GLOBALS"}["fjordnwx"] = "values";
                 ${${"GLOBALS"}["fjordnwx"]}[] = "`" . ${${"GLOBALS"}["nctgtuliixp"]} . "` = ?";
                 ${${"GLOBALS"}["tjyzhfdvth"]}[] = $this->_listitems[${${"GLOBALS"}["jsntgvnqkf"]} - 1][${${"GLOBALS"}["nctgtuliixp"]}];
             }
             if (count(${${"GLOBALS"}["ibmlnecaubpt"]}) > 0) {
                 $nvtwyqcc = "params";
                 $wbzhsv = "i";
                 $glpeqaibe = "params";
                 ${${"GLOBALS"}["tjyzhfdvth"]}[] = $this->getId();
                 $mjhhtobppu = "sql";
                 ${$nvtwyqcc}[] = ${$wbzhsv};
                 ${${"GLOBALS"}["hdblop"]} = "UPDATE vtiger_inventoryproductrel SET " . implode(",", ${${"GLOBALS"}["ibmlnecaubpt"]}) . " WHERE id = ? AND sequence_no = ?";
                 $adb->pquery(${$mjhhtobppu}, ${$glpeqaibe});
             }
         }
     }
     if (!empty(${${"GLOBALS"}["xkutivbm"]})) {
         $wrqjvjvs = "update_query";
         ${"GLOBALS"}["ryhoienvnsn"] = "cur_sym_rate";
         $xepbzcbhw = "update_params";
         ${"GLOBALS"}["ohiigcodbwo"] = "conversion_rate";
         $pcrolhc = "currency_id";
         ${"GLOBALS"}["udferc"] = "conversion_rate";
         $fkgwwhoop = "intObject";
         ${"GLOBALS"}["nglnmk"] = "update_query";
         ${"GLOBALS"}["nvezfxsotm"] = "currency_id";
         if (strpos(${${"GLOBALS"}["nvezfxsotm"]}, "x") !== false) {
             ${"GLOBALS"}["twtpeleg"] = "parts";
             ${${"GLOBALS"}["bbeqpsqwehf"]} = explode("x", ${${"GLOBALS"}["xkutivbm"]});
             ${${"GLOBALS"}["xkutivbm"]} = ${${"GLOBALS"}["twtpeleg"]}[1];
         } else {
             ${"GLOBALS"}["kuscdvfpt"] = "currency_id";
             ${${"GLOBALS"}["kuscdvfpt"]} = ${${"GLOBALS"}["xkutivbm"]};
         }
         $ksoimju = "cur_sym_rate";
         ${$ksoimju} = getCurrencySymbolandCRate(${${"GLOBALS"}["xkutivbm"]});
         ${${"GLOBALS"}["ohiigcodbwo"]} = ${${"GLOBALS"}["ryhoienvnsn"]}["rate"];
         ${"GLOBALS"}["epcnplti"] = "update_params";
         ${$fkgwwhoop} = $this->getInternalObject();
         ${$wrqjvjvs} = "update " . $intObject->table_name . " set currency_id = ?, conversion_rate = ? WHERE " . $intObject->table_index . " = ?";
         ${$xepbzcbhw} = array(${$pcrolhc}, ${${"GLOBALS"}["udferc"]}, $this->_id);
         $adb->pquery(${${"GLOBALS"}["nglnmk"]}, ${${"GLOBALS"}["epcnplti"]});
     }
     if (file_exists(vglobal("root_directory") . DIRECTORY_SEPARATOR . "modules" . DIRECTORY_SEPARATOR . "Invoice" . DIRECTORY_SEPARATOR . "InvoiceHandler.php")) {
         ${"GLOBALS"}["hebripdxg"] = "entityData";
         ${"GLOBALS"}["llplslhg"] = "adb";
         require_once "modules/Invoice/InvoiceHandler.php";
         require_once "include/events/VTEventHandler.inc";
         require_once "data/VTEntityDelta.php";
         ${${"GLOBALS"}["hebripdxg"]} = \VTEntityData::fromEntityId(${${"GLOBALS"}["llplslhg"]}, $this->getId(), $this->getModuleName());
         $omsgxnkjeni = "handler";
         ${$omsgxnkjeni} = new \InvoiceHandler();
         $handler->handleEvent("vtiger.entity.aftersave", ${${"GLOBALS"}["xxguhqgid"]});
     }
     $this->afterTransfer();
     $this->_data = false;
 }
示例#6
0
 public function triggerAfterSaveEventHandlers()
 {
     $adb = PearDatabase::getInstance();
     require_once "include/events/include.inc";
     //In Bulk mode stop triggering events
     if (!self::isBulkSaveMode()) {
         $em = new VTEventsManager($adb);
         // Initialize Event trigger cache
         $em->initTriggerCache();
         $entityData = VTEntityData::fromCRMEntity($this);
     }
     //Event triggering code ends
     if ($em) {
         //Event triggering code
         $em->triggerEvent("vtiger.entity.aftersave", $entityData);
         $em->triggerEvent("vtiger.entity.aftersave.final", $entityData);
     }
 }
 /** Function to restore a deleted record of specified module with given crmid
  * @param $module -- module name:: Type varchar
  * @param $entity_ids -- list of crmids :: Array
  */
 function restore($module, $id)
 {
     global $current_user, $adb;
     $this->db->println("TRANS restore starts {$module}");
     $this->db->startTransaction();
     $date_var = date("Y-m-d H:i:s");
     $query = 'UPDATE vtiger_crmentity SET deleted=0,modifiedtime=?,modifiedby=? WHERE crmid = ?';
     $this->db->pquery($query, array($this->db->formatDate($date_var, true), $current_user->id, $id), true, "Error restoring records :");
     //Restore related entities/records
     $this->restoreRelatedRecords($module, $id);
     //Event triggering code
     require_once "include/events/include.inc";
     global $adb;
     $em = new VTEventsManager($adb);
     // Initialize Event trigger cache
     $em->initTriggerCache();
     $this->id = $id;
     $entityData = VTEntityData::fromCRMEntity($this);
     //Event triggering code
     $em->triggerEvent("vtiger.entity.afterrestore", $entityData);
     //Event triggering code ends
     $this->db->completeTransaction();
     $this->db->println("TRANS restore ends");
 }
示例#8
0
文件: Users.php 项目: kduqi/corebos
 function transformOwnerShipAndDelete($userId, $transformToUserId)
 {
     $adb = PearDatabase::getInstance();
     $em = new VTEventsManager($adb);
     // Initialize Event trigger cache
     $em->initTriggerCache();
     $entityData = VTEntityData::fromUserId($adb, $userId);
     //set transform user id
     $entityData->set('transformtouserid', $transformToUserId);
     $em->triggerEvent("vtiger.entity.beforedelete", $entityData);
     vtws_transferOwnership($userId, $transformToUserId);
     //delete from user vtiger_table;
     $sql = "delete from vtiger_users where id=?";
     $adb->pquery($sql, array($userId));
     //Delete user extension in asterisk.
     $sql = "delete from vtiger_asteriskextensions where userid=?";
     $adb->pquery($sql, array($userId));
 }
示例#9
0
 /**
  * Trigger event based on CRM Record
  * @param String Name of the Event to trigger
  * @param Integer CRM record id on which event needs to be triggered.
  */
 static function trigger($eventname, $crmid)
 {
     if (!self::hasSupport()) {
         return;
     }
     $adb = PearDatabase::getInstance();
     $checkres = $adb->pquery("SELECT setype, crmid, deleted FROM vtiger_crmentity WHERE crmid=?", array($crmid));
     if ($adb->num_rows($checkres)) {
         $result = $adb->fetch_array($checkres, 0);
         if ($result['deleted'] == '0') {
             $module = $result['setype'];
             $moduleInstance = CRMEntity::getInstance($module);
             $moduleInstance->retrieve_entity_info($result['crmid'], $module);
             $moduleInstance->id = $result['crmid'];
             $current_user = vglobal('current_user');
             if (!$current_user) {
                 $current_user = new Users();
                 $current_user->id = $moduleInstance->column_fields['assigned_user_id'];
             }
             // Trigger the event
             $em = new VTEventsManager($adb);
             $em->triggerEvent($eventname, VTEntityData::fromCRMEntity($moduleInstance));
         }
     }
 }
示例#10
0
/**
 * Function to related two records of different entity types
 */
function relateEntities($focus, $sourceModule, $sourceRecordId, $destinationModule, $destinationRecordIds)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $log->debug("Entering relateEntities method ({$sourceModule}, {$sourceRecordId}, {$destinationModule}, {$destinationRecordIds})");
    require_once 'include/events/include.inc';
    //require_once('modules/com_vtiger_workflow/VTWorkflowManager.inc');
    //require_once('modules/com_vtiger_workflow/VTEntityCache.inc');
    $em = new VTEventsManager($adb);
    $em->initTriggerCache();
    if (!is_array($destinationRecordIds)) {
        $destinationRecordIds = [$destinationRecordIds];
    }
    $data = [];
    $data['CRMEntity'] = $focus;
    $data['entityData'] = VTEntityData::fromEntityId($adb, $sourceRecordId);
    $data['sourceModule'] = $sourceModule;
    $data['sourceRecordId'] = $sourceRecordId;
    $data['destinationModule'] = $destinationModule;
    foreach ($destinationRecordIds as $destinationRecordId) {
        $data['destinationRecordId'] = $destinationRecordId;
        $em->triggerEvent('vtiger.entity.link.before', $data);
        $focus->save_related_module($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId);
        $focus->trackLinkedInfo($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId);
        /*
         $wfs = new VTWorkflowManager($adb);
         $workflows = $wfs->getWorkflowsForModule($sourceModule, VTWorkflowManager::$ON_RELATED);
         $entityCache = new VTEntityCache(Users_Record_Model::getCurrentUserModel());
         $entityData = VTEntityData::fromCRMEntity($focus);
         $entityData->eventType = VTWorkflowManager::$ON_RELATED;
         $entityData->relatedInfo = [
         'destId' => $destinationRecordId,
         'destModule' => $destinationModule,
         ];
         foreach ($workflows as $id => $workflow) {
         if ($workflow->evaluate($entityCache, $entityData->getId())) {
         $workflow->performTasks($entityData);
         }
         }
        */
        $em->triggerEvent('vtiger.entity.link.after', $data);
    }
    $log->debug("Exiting relateEntities method ...");
}
示例#11
0
 /** Function to restore a deleted record of specified module with given crmid
  * @param $module -- module name:: Type varchar
  * @param $entity_ids -- list of crmids :: Array
  */
 function restore($module, $id)
 {
     $db = PearDatabase::getInstance();
     $currentUser = vglobal('current_user');
     $db->startTransaction();
     $db->update('vtiger_crmentity', ['deleted' => 0, 'modifiedtime' => date('Y-m-d H:i:s'), 'modifiedby' => $currentUser->id], 'crmid = ?', [$id]);
     //Restore related entities/records
     $this->restoreRelatedRecords($module, $id);
     //Event triggering code
     require_once 'include/events/include.inc';
     $em = new VTEventsManager($db);
     // Initialize Event trigger cache
     $em->initTriggerCache();
     $this->id = $id;
     $entityData = VTEntityData::fromCRMEntity($this);
     //Event triggering code
     $em->triggerEvent('vtiger.entity.afterrestore', $entityData);
     //Event triggering code ends
     $db->completeTransaction();
 }
示例#12
0
 require_once "data/Tracker.php";
 require_once "modules/com_vtiger_workflow/VTWorkflowManager.inc";
 require_once "modules/com_vtiger_workflow/VTTaskManager.inc";
 require_once "modules/com_vtiger_workflow/VTWorkflowApplication.inc";
 require_once "modules/com_vtiger_workflow/VTEntityMethodManager.inc";
 require_once "include/utils/CommonUtils.php";
 require_once "include/events/SqlResultIterator.inc";
 require_once "modules/com_vtiger_workflow/VTWorkflowUtils.php";
 require_once "modules/Project/Project.php";
 $focus1 = new Project();
 $focus1->retrieve_entity_info($pcdetailsproject, "Project");
 $focus1->id = $pcdetailsproject;
 $em = new VTEventsManager($adb);
 // Initialize Event trigger cache
 $em->initTriggerCache();
 $entityData = VTEntityData::fromCRMEntity($focus1);
 $em->triggerEvent("vtiger.entity.beforesave.modifiable", $entityData);
 $em->triggerEvent("vtiger.entity.beforesave", $entityData);
 $em->triggerEvent("vtiger.entity.beforesave.final", $entityData);
 $em->triggerEvent("vtiger.entity.aftersave", $entityData);
 //}
 $projectQuery1 = $adb->query("select * from vtiger_project where projectid={$pcdetailsproject}");
 if ($adb->query_result($projectQuery1, 0, "substatusproj") == "CAT_parts sent by Teknema" && $adb->query_result($projectQuery1, 0, "statopartech") == 'SHIPPED') {
     $logpart .= "Movimento frecce avvenuto con successo </span><br><br>";
     $logs[$i - 1] .= "Movimento frecce avvenuto con successo";
 } elseif ($subs != "CAT_parts request" && strstr($subs, "attesa parti") != '' && $adb->query_result($projectQuery1, 0, "statopartech") == 'SHIPPED') {
     $logpart .= "<span style='color:blue'> Substatus errato {$d['2']} </span></span><br><br>";
     $logs[$i - 1] .= "Substatus errato {$d['2']}";
 } else {
     $logpart .= "Substatus non modificato </span><br><br>";
     $logs[$i - 1] .= "Substatus non modificato";
示例#13
0
 public function createEntityRecord($moduleName, $entityLabel)
 {
     $moduleHandler = vtws_getModuleHandlerFromName($moduleName, $this->user);
     $moduleMeta = $moduleHandler->getMeta();
     $moduleFields = $moduleMeta->getModuleFields();
     $mandatoryFields = $moduleMeta->getMandatoryFields();
     $entityNameFieldsString = $moduleMeta->getNameFields();
     $entityNameFields = explode(',', $entityNameFieldsString);
     $fieldData = array();
     foreach ($entityNameFields as $entityNameField) {
         $entityNameField = trim($entityNameField);
         if (in_array($entityNameField, $mandatoryFields)) {
             $fieldData[$entityNameField] = $entityLabel;
         }
     }
     foreach ($mandatoryFields as $mandatoryField) {
         if (empty($fieldData[$mandatoryField])) {
             $fieldInstance = $moduleFields[$mandatoryField];
             if ($fieldInstance->getFieldDataType() == 'owner') {
                 $fieldData[$mandatoryField] = $this->user->id;
             } else {
                 if (!in_array($mandatoryField, $entityNameFields) && $fieldInstance->getFieldDataType() != 'reference') {
                     $fieldData[$mandatoryField] = '????';
                 }
             }
         }
     }
     $fieldData = DataTransform::sanitizeData($fieldData, $moduleMeta);
     $entityIdInfo = vtws_create($moduleName, $fieldData, $this->user);
     $adb = PearDatabase::getInstance();
     $entityIdComponents = vtws_getIdComponents($entityIdInfo['id']);
     $recordId = $entityIdComponents[1];
     $entityfields = getEntityFieldNames($moduleName);
     switch ($moduleName) {
         case 'HelpDesk':
             $entityfields['fieldname'] = array('ticket_title');
             break;
         case 'Documents':
             $entityfields['fieldname'] = array('notes_title');
             break;
         case 'Documents':
             $entityfields['fieldname'] = array('notes_title');
             break;
     }
     $label = '';
     if (is_array($entityfields['fieldname'])) {
         foreach ($entityfields['fieldname'] as $field) {
             $label .= $fieldData[$field] . " ";
         }
     } else {
         $label = $fieldData[$entityfields['fieldname']];
     }
     $label = trim($label);
     $adb->pquery('UPDATE vtiger_crmentity SET label=? WHERE crmid=?', array($label, $recordId));
     $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
     $focus = $recordModel->getEntity();
     $focus->id = $recordId;
     $focus->column_fields = $fieldData;
     $this->entityData[] = VTEntityData::fromCRMEntity($focus);
     $focus->updateMissingSeqNumber($moduleName);
     return $entityIdInfo;
 }
示例#14
0
function vtws_convertlead($entityvalues, $user)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $log->debug('Start ' . __CLASS__ . ':' . __FUNCTION__);
    if (empty($entityvalues['assignedTo'])) {
        $entityvalues['assignedTo'] = vtws_getWebserviceEntityId('Users', $user->id);
    }
    if (empty($entityvalues['transferRelatedRecordsTo'])) {
        $entityvalues['transferRelatedRecordsTo'] = 'Accounts';
    }
    $leadObject = VtigerWebserviceObject::fromName($adb, 'Leads');
    $handlerPath = $leadObject->getHandlerPath();
    $handlerClass = $leadObject->getHandlerClass();
    require_once $handlerPath;
    $leadHandler = new $handlerClass($leadObject, $user, $adb, $log);
    $leadInfo = vtws_retrieve($entityvalues['leadId'], $user);
    $sql = "select converted from vtiger_leaddetails where converted = 1 and leadid=?";
    $leadIdComponents = vtws_getIdComponents($entityvalues['leadId']);
    $result = $adb->pquery($sql, array($leadIdComponents[1]));
    if ($result === false) {
        $log->error('Error converting a lead: ' . vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
        throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, vtws_getWebserviceTranslatedString('LBL_' . WebServiceErrorCode::$DATABASEQUERYERROR));
    }
    $rowCount = $adb->num_rows($result);
    if ($rowCount > 0) {
        $log->error('Error converting a lead: Lead is already converted');
        throw new WebServiceException(WebServiceErrorCode::$LEAD_ALREADY_CONVERTED, "Lead is already converted");
    }
    require_once "include/events/include.inc";
    $em = new VTEventsManager($adb);
    // Initialize Event trigger cache
    $em->initTriggerCache();
    $entityData = VTEntityData::fromEntityId($adb, $leadIdComponents[1]);
    $em->triggerEvent('entity.convertlead.before', [$entityvalues, $user, $leadInfo]);
    $entityIds = [];
    $availableModules = ['Accounts', 'Contacts', 'Potentials'];
    if (!($entityvalues['entities']['Accounts']['create'] || $entityvalues['entities']['Contacts']['create'])) {
        return null;
    }
    foreach ($availableModules as $entityName) {
        if ($entityvalues['entities'][$entityName]['create']) {
            $entityvalue = $entityvalues['entities'][$entityName];
            $entityObject = VtigerWebserviceObject::fromName($adb, $entityvalue['name']);
            $handlerPath = $entityObject->getHandlerPath();
            $handlerClass = $entityObject->getHandlerClass();
            require_once $handlerPath;
            $entityHandler = new $handlerClass($entityObject, $user, $adb, $log);
            $entityObjectValues = array();
            $entityObjectValues['assigned_user_id'] = $entityvalues['assignedTo'];
            $entityObjectValues = vtws_populateConvertLeadEntities($entityvalue, $entityObjectValues, $entityHandler, $leadHandler, $leadInfo);
            //update potential related to property
            if ($entityvalue['name'] == 'Potentials') {
                if (!empty($entityIds['Accounts'])) {
                    $entityObjectValues['related_to'] = $entityIds['Accounts'];
                }
                if (!empty($entityIds['Contacts'])) {
                    $entityObjectValues['contact_id'] = $entityIds['Contacts'];
                }
            }
            //update the contacts relation
            if ($entityvalue['name'] == 'Contacts') {
                if (!empty($entityIds['Accounts'])) {
                    $entityObjectValues['parent_id'] = $entityIds['Accounts'];
                }
            }
            try {
                $create = true;
                if ($entityvalue['name'] == 'Accounts' && $entityvalue['convert_to_id'] && is_int($entityvalue['convert_to_id'])) {
                    $entityIds[$entityName] = vtws_getWebserviceEntityId('Accounts', $entityvalue['convert_to_id']);
                    $create = false;
                }
                if ($create) {
                    $entityRecord = vtws_create($entityvalue['name'], $entityObjectValues, $user);
                    $entityIds[$entityName] = $entityRecord['id'];
                }
            } catch (Exception $e) {
                $log->error('Error converting a lead: ' . $e->getMessage());
                throw new WebServiceException(WebServiceErrorCode::$UNKNOWNOPERATION, $e->getMessage() . ' : ' . $entityvalue['name']);
            }
        }
    }
    try {
        $accountIdComponents = vtws_getIdComponents($entityIds['Accounts']);
        $accountId = $accountIdComponents[1];
        $contactIdComponents = vtws_getIdComponents($entityIds['Contacts']);
        $contactId = $contactIdComponents[1];
        if (!empty($accountId) && !empty($contactId) && !empty($entityIds['Potentials'])) {
            $potentialIdComponents = vtws_getIdComponents($entityIds['Potentials']);
            $potentialId = $potentialIdComponents[1];
            $sql = "insert into vtiger_contpotentialrel values(?,?)";
            $result = $adb->pquery($sql, array($contactId, $potentialIdComponents[1]));
            if ($result === false) {
                throw new WebServiceException(WebServiceErrorCode::$FAILED_TO_CREATE_RELATION, "Failed to related Contact with the Potential");
            }
        }
        $transfered = vtws_convertLeadTransferHandler($leadIdComponents, $entityIds, $entityvalues);
        $relatedIdComponents = vtws_getIdComponents($entityIds[$entityvalues['transferRelatedRecordsTo']]);
        vtws_getRelatedActivities($leadIdComponents[1], $accountId, $contactId, $relatedIdComponents[1]);
        vtws_updateConvertLeadStatus($entityIds, $entityvalues['leadId'], $user);
        if ($em) {
            $em->triggerEvent('entity.convertlead.after', [$entityvalues, $user, $leadInfo, $entityIds]);
        }
    } catch (Exception $e) {
        $log->error('Error converting a lead: ' . $e->getMessage());
        foreach ($entityIds as $entity => $id) {
            vtws_delete($id, $user);
        }
        return null;
    }
    $log->debug('End ' . __CLASS__ . ':' . __FUNCTION__);
    return $entityIds;
}
示例#15
0
/**
 * This function returns no value but handles the delete functionality of each entity.
 * Input Parameter are $module - module name, $return_module - return module name, $focus - module object, $record - entity id, $return_id - return entity id.
 */
function DeleteEntity($module, $return_module, $focus, $record, $return_id)
{
    global $log, $adb;
    $log->debug("Entering DeleteEntity method ({$module}, {$return_module}, {$record}, {$return_id})");
    require_once "include/events/include.inc";
    $em = new VTEventsManager($adb);
    $em->initTriggerCache();
    $entityData = VTEntityData::fromEntityId($adb, $record);
    $em->triggerEvent("vtiger.entity.beforeunlink", $entityData);
    if ($module != $return_module && !empty($return_module) && !empty($return_id)) {
        $focus->unlinkRelationship($record, $return_module, $return_id);
        $focus->trackUnLinkedInfo($return_module, $return_id, $module, $record);
    } else {
        $focus->trash($module, $record);
    }
    if ($em) {
        $entityData = VTEntityData::fromEntityId($adb, $record);
        $em->triggerEvent("vtiger.entity.afterunlink", $entityData);
    }
    $log->debug("Exiting DeleteEntity method ...");
}
示例#16
0
 /** Function to saves the values in all the tables mentioned in the class variable $tab_name for the specified module
  * @param $module -- module:: Type varchar
  */
 function save($module_name, $fileid = '')
 {
     global $log;
     $log->debug("module name is " . $module_name);
     //Event triggering code
     require_once "include/events/include.inc";
     global $adb;
     $em = new VTEventsManager($adb);
     // Initialize Event trigger cache
     $em->initTriggerCache();
     $entityData = VTEntityData::fromCRMEntity($this);
     $em->triggerEvent("vtiger.entity.beforesave.modifiable", $entityData);
     $em->triggerEvent("vtiger.entity.beforesave", $entityData);
     $em->triggerEvent("vtiger.entity.beforesave.final", $entityData);
     //Event triggering code ends
     //GS Save entity being called with the modulename as parameter
     $this->saveentity($module_name, $fileid);
     //Event triggering code
     $em->triggerEvent("vtiger.entity.aftersave", $entityData);
     //Event triggering code ends
 }
示例#17
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');
 }
示例#18
0
/**
 * Function to related two records of different entity types
 */
function relateEntities($focus, $sourceModule, $sourceRecordId, $destinationModule, $destinationRecordIds)
{
    $adb = PearDatabase::getInstance();
    $log = vglobal('log');
    $log->debug("Entering relateEntities method ({$sourceModule}, {$sourceRecordId}, {$destinationModule}, {$destinationRecordIds})");
    require_once "include/events/include.inc";
    $em = new VTEventsManager($adb);
    $em->initTriggerCache();
    if (!is_array($destinationRecordIds)) {
        $destinationRecordIds = [$destinationRecordIds];
    }
    $data = [];
    $data['CRMEntity'] = $focus;
    $data['entityData'] = VTEntityData::fromEntityId($adb, $sourceRecordId);
    $data['sourceModule'] = $sourceModule;
    $data['sourceRecordId'] = $sourceRecordId;
    $data['destinationModule'] = $destinationModule;
    foreach ($destinationRecordIds as $destinationRecordId) {
        $data['destinationRecordId'] = $destinationRecordId;
        $em->triggerEvent('vtiger.entity.link.before', $data);
        $focus->save_related_module($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId);
        $focus->trackLinkedInfo($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId);
        $em->triggerEvent('vtiger.entity.link.after', $data);
    }
    $log->debug("Exiting relateEntities method ...");
}