function handleEvent($eventName, $entityData)
 {
     global $current_user;
     $db = PearDatabase::getInstance();
     $moduleName = $entityData->getModuleName();
     //Specific to VAS
     if ($moduleName == 'Users') {
         return;
     }
     //END
     $recordId = $entityData->getId();
     $vtEntityDelta = new VTEntityDelta();
     $newEntityData = $vtEntityDelta->getNewEntity($moduleName, $recordId);
     $recordValues = $newEntityData->getData();
     $isAssignToModified = $this->isAssignToChanged($moduleName, $recordId, $current_user);
     if (!$isAssignToModified) {
         return;
     }
     $wsModuleName = $this->getWsModuleName($moduleName);
     if ($wsModuleName == "Calendar") {
         $wsModuleName = vtws_getCalendarEntityType($recordId);
     }
     $handler = vtws_getModuleHandlerFromName($wsModuleName, $current_user);
     $meta = $handler->getMeta();
     $recordWsValues = DataTransform::sanitizeData($recordValues, $meta);
     $syncServer = new SyncServer();
     $syncServer->markRecordAsDeleteForAllCleints($recordWsValues);
 }
Example #2
0
 /**
  * @static
  * @param int $id - CRMId des Records
  * @param string $module_name - ModuleName des records
  * @param Users $user - [Optional] Used for Object Access
  * @return VTEntity
  */
 public static function getForId($id, $module_name = false, $user = false)
 {
     if (empty($id)) {
         return self::getDummy();
     }
     if (strpos($id, "x") !== false) {
         $idParts = explode("x", $id);
         $id = $idParts[1];
         if (empty($module_name)) {
             global $adb;
             $sql = "SELECT name FROM vtiger_ws_entity WHERE id = " . intval($idParts[0]);
             $result = $adb->query($sql);
             $module_name = $adb->query_result($result, 0, "name");
         }
     }
     if (strpos($id, "@") !== false) {
         $id = explode("@", $id);
         $id = $id[0];
     }
     if ($module_name == false) {
         global $adb;
         $sql = "SELECT setype FROM vtiger_crmentity WHERE crmid = " . intval($id);
         $result = $adb->query($sql);
         $module_name = $adb->query_result($result, 0, "setype");
     }
     if (empty($module_name)) {
         return false;
     }
     if ($module_name == "Calendar" || $module_name == "Events") {
         $module_name = vtws_getCalendarEntityType($id);
     }
     if ($user === false) {
         $userID = VTEntity::$_user->id;
     } else {
         $userID = $user->id;
     }
     if (isset(VTEntity::$_cache[$userID][$id])) {
         return VTEntity::$_cache[$userID][$id];
     }
     global $current_user;
     if ($module_name == "Invoice" || $module_name == "Quotes" || $module_name == "SalesOrder" || $module_name == "PurchaseOrder") {
         VTEntity::$_cache[$userID][$id] = new VTInventoryEntity($module_name, $id);
     } else {
         VTEntity::$_cache[$userID][$id] = new VTEntity($module_name, $id);
     }
     return VTEntity::$_cache[$userID][$id];
 }
Example #3
0
 public function getRecordData($moduleName, $recordId)
 {
     ${"GLOBALS"}["yhkvuqi"] = "moduleName";
     include_once "include/Webservices/Retrieve.php";
     include_once "include/Webservices/Utils.php";
     ${"GLOBALS"}["rwzcgorvwd"] = "modelData";
     if (${${"GLOBALS"}["yhkvuqi"]} == "Calendar") {
         ${${"GLOBALS"}["qdpmrziapjb"]} = vtws_getCalendarEntityType(${${"GLOBALS"}["kpdkgyrhwuc"]});
     }
     try {
         ${"GLOBALS"}["zwvujejhu"] = "recordId";
         ${${"GLOBALS"}["tykmttbjma"]} = vtws_getWebserviceEntityId(${${"GLOBALS"}["qdpmrziapjb"]}, ${${"GLOBALS"}["zwvujejhu"]});
         ${${"GLOBALS"}["cnbxfeulpcc"]} = vtws_retrieve(${${"GLOBALS"}["tykmttbjma"]}, vglobal("current_user"));
     } catch (WebServiceException $ex) {
         echo "getRecordData Error: " . $ex->getMessage();
     }
     return ${${"GLOBALS"}["rwzcgorvwd"]};
 }
 public function queueScheduledWorkflowTasks()
 {
     global $default_timezone;
     $adb = $this->db;
     $vtWorflowManager = new VTWorkflowManager($adb);
     $taskQueue = new VTTaskQueue($adb);
     $entityCache = new VTEntityCache($this->user);
     // set the time zone to the admin's time zone, this is needed so that the scheduled workflow will be triggered
     // at admin's time zone rather than the systems time zone. This is specially needed for Hourly and Daily scheduled workflows
     $admin = Users::getActiveAdminUser();
     $adminTimeZone = $admin->time_zone;
     @date_default_timezone_set($adminTimeZone);
     $currentTimestamp = date("Y-m-d H:i:s");
     @date_default_timezone_set($default_timezone);
     $scheduledWorkflows = $vtWorflowManager->getScheduledWorkflows($currentTimestamp);
     $noOfScheduledWorkflows = count($scheduledWorkflows);
     for ($i = 0; $i < $noOfScheduledWorkflows; ++$i) {
         $workflow = $scheduledWorkflows[$i];
         $tm = new VTTaskManager($adb);
         $tasks = $tm->getTasksForWorkflow($workflow->id);
         if ($tasks) {
             $records = $this->getEligibleWorkflowRecords($workflow);
             $noOfRecords = count($records);
             for ($j = 0; $j < $noOfRecords; ++$j) {
                 $recordId = $records[$j];
                 // We need to pass proper module name to get the webservice
                 if ($workflow->moduleName == 'Calendar') {
                     $moduleName = vtws_getCalendarEntityType($recordId);
                 } else {
                     $moduleName = $workflow->moduleName;
                 }
                 $wsEntityId = vtws_getWebserviceEntityId($moduleName, $recordId);
                 $entityData = $entityCache->forId($wsEntityId);
                 $data = $entityData->getData();
                 foreach ($tasks as $task) {
                     if ($task->active) {
                         $trigger = $task->trigger;
                         if ($trigger != null) {
                             $delay = strtotime($data[$trigger['field']]) + $trigger['days'] * 86400;
                         } else {
                             $delay = 0;
                         }
                         if ($task->executeImmediately == true) {
                             $task->doTask($entityData);
                         } else {
                             $taskQueue->queueTask($task->id, $entityData->getId(), $delay);
                         }
                     }
                 }
             }
         }
         $vtWorflowManager->updateNexTriggerTime($workflow);
     }
     $scheduledWorkflows = null;
 }
Example #5
0
function vtws_history_entityIdHelper($moduleName, $id)
{
    static $wsEntityIdCache = NULL;
    if ($wsEntityIdCache === NULL) {
        $wsEntityIdCache = array('users' => array(), 'records' => array());
    }
    if (!isset($wsEntityIdCache[$moduleName][$id])) {
        // Determine moduleName based on $id
        if (empty($moduleName)) {
            $moduleName = getSalesEntityType($id);
        }
        if ($moduleName == 'Calendar') {
            $moduleName = vtws_getCalendarEntityType($id);
        }
        $wsEntityIdCache[$moduleName][$id] = vtws_getWebserviceEntityId($moduleName, $id);
    }
    return $wsEntityIdCache[$moduleName][$id];
}
Example #6
0
 public function queueScheduledWorkflowTasks()
 {
     global $default_timezone;
     $adb = $this->db;
     $vtWorflowManager = new VTWorkflowManager($adb);
     $entityCache = new VTEntityCache($this->user);
     // set the time zone to the admin's time zone, this is needed so that the scheduled workflow will be triggered
     // at admin's time zone rather than the systems time zone. This is specially needed for Hourly and Daily scheduled workflows
     $admin = Users::getActiveAdminUser();
     $adminTimeZone = $admin->time_zone;
     @date_default_timezone_set($adminTimeZone);
     $currentTimestamp = date("Y-m-d H:i:s");
     @date_default_timezone_set($default_timezone);
     $scheduledWorkflows = $vtWorflowManager->getScheduledWorkflows($currentTimestamp);
     $noOfScheduledWorkflows = count($scheduledWorkflows);
     for ($i = 0; $i < $noOfScheduledWorkflows; ++$i) {
         $workflow = $scheduledWorkflows[$i];
         if ($workflow->active != 1) {
             continue;
         }
         $tm = new VTTaskManager($adb);
         $tasks = $tm->getTasksForWorkflow($workflow->id);
         if ($tasks) {
             $records = $this->getEligibleWorkflowRecords($workflow);
             $noOfRecords = count($records);
             for ($j = 0; $j < $noOfRecords; ++$j) {
                 $recordId = $records[$j];
                 // We need to pass proper module name to get the webservice
                 if ($workflow->moduleName == 'Calendar') {
                     $moduleName = vtws_getCalendarEntityType($recordId);
                 } else {
                     $moduleName = $workflow->moduleName;
                 }
                 $wsEntityId = vtws_getWebserviceEntityId($moduleName, $recordId);
                 $entityData = $entityCache->forId($wsEntityId);
                 $tm->performTasks($entityData, false);
             }
         }
         $vtWorflowManager->updateNexTriggerTime($workflow);
     }
     $scheduledWorkflows = null;
 }
 function getObjectEntityName($webserviceId)
 {
     global $adb;
     $idComponents = vtws_getIdComponents($webserviceId);
     $id = $idComponents[1];
     $seType = null;
     if ($this->objectName == 'Users') {
         $sql = "select user_name from vtiger_users where id=? and deleted=0";
         $result = $adb->pquery($sql, array($id));
         if ($result != null && isset($result)) {
             if ($adb->num_rows($result) > 0) {
                 $seType = 'Users';
             }
         }
     } else {
         $sql = "select * from vtiger_crmentity where crmid=? and deleted=0";
         $result = $adb->pquery($sql, array($id));
         if ($result != null && isset($result)) {
             if ($adb->num_rows($result) > 0) {
                 $seType = $adb->query_result($result, 0, "setype");
                 if ($seType == "Calendar") {
                     $seType = vtws_getCalendarEntityType($id);
                 }
             }
         }
     }
     return $seType;
 }
Example #8
0
 public static function getForId($id, $module_name = false, $user = false)
 {
     $nunqvjnjktj = "id";
     $prxedru = "recordModel";
     ${"GLOBALS"}["ggrdjoffmb"] = "_cache";
     $uwvatjqrp = "userID";
     if (empty(${$nunqvjnjktj})) {
         return self::getDummy();
     }
     if (${${"GLOBALS"}["mzocslvphn"]} === "ModuleName") {
         ${"GLOBALS"}["fcvcdlj"] = "module_name";
         ${${"GLOBALS"}["fcvcdlj"]} = null;
     }
     ${"GLOBALS"}["kspajmgpepoe"] = "module_name";
     ${"GLOBALS"}["mgzikjhft"] = "module_name";
     if (strpos(${${"GLOBALS"}["htjiqkfioz"]}, "x") !== false) {
         ${${"GLOBALS"}["fvqttrwn"]} = explode("x", ${${"GLOBALS"}["htjiqkfioz"]});
         ${${"GLOBALS"}["htjiqkfioz"]} = ${${"GLOBALS"}["fvqttrwn"]}[1];
         if (empty(${${"GLOBALS"}["mzocslvphn"]})) {
             $bxvwlywklero = "sql";
             global $adb;
             ${"GLOBALS"}["temhpm"] = "idParts";
             ${"GLOBALS"}["utvlfkq"] = "module_name";
             $lxxtylbpp = "result";
             ${"GLOBALS"}["qtkofnintxr"] = "result";
             ${"GLOBALS"}["ffwcqruwcy"] = "sql";
             ${${"GLOBALS"}["ffwcqruwcy"]} = "SELECT name FROM vtiger_ws_entity WHERE id = " . intval(${${"GLOBALS"}["temhpm"]}[0]);
             ${${"GLOBALS"}["qtkofnintxr"]} = $adb->query(${$bxvwlywklero});
             ${${"GLOBALS"}["utvlfkq"]} = $adb->query_result(${$lxxtylbpp}, 0, "name");
         }
     }
     if (strpos(${${"GLOBALS"}["htjiqkfioz"]}, "@") !== false) {
         $yvzmzqqd = "id";
         $jxdtttisxz = "id";
         ${${"GLOBALS"}["htjiqkfioz"]} = explode("@", ${$jxdtttisxz});
         ${$yvzmzqqd} = ${${"GLOBALS"}["htjiqkfioz"]}[0];
     }
     ${"GLOBALS"}["zbjajoidpx"] = "id";
     if (${${"GLOBALS"}["mgzikjhft"]} == false) {
         $zuoqslbydi = "result";
         ${"GLOBALS"}["qsiqiwmyplj"] = "module_name";
         global $adb;
         $bywlclhlw = "sql";
         ${${"GLOBALS"}["clnussj"]} = "SELECT setype FROM vtiger_crmentity WHERE crmid = " . intval(${${"GLOBALS"}["htjiqkfioz"]});
         ${${"GLOBALS"}["orgnykvnkpk"]} = $adb->query(${$bywlclhlw});
         ${${"GLOBALS"}["qsiqiwmyplj"]} = $adb->query_result(${$zuoqslbydi}, 0, "setype");
     }
     if (empty(${${"GLOBALS"}["kspajmgpepoe"]})) {
         return false;
     }
     if (${${"GLOBALS"}["mzocslvphn"]} == "Calendar" || ${${"GLOBALS"}["mzocslvphn"]} == "Events") {
         ${"GLOBALS"}["cyjvhaubar"] = "module_name";
         ${${"GLOBALS"}["cyjvhaubar"]} = vtws_getCalendarEntityType(${${"GLOBALS"}["htjiqkfioz"]});
     }
     if (${${"GLOBALS"}["drdrrfuzney"]} === false) {
         ${${"GLOBALS"}["oklwinvdfh"]} = VTEntity::$_user->id;
     } else {
         $ovvzvxz = "userID";
         ${$ovvzvxz} = $user->id;
     }
     if (isset(VTEntity::${${"GLOBALS"}["abwmltbg"]}[${${"GLOBALS"}["oklwinvdfh"]}][${${"GLOBALS"}["zbjajoidpx"]}])) {
         ${"GLOBALS"}["kodrwe"] = "_cache";
         ${"GLOBALS"}["lidsqndylvq"] = "id";
         return VTEntity::${${"GLOBALS"}["kodrwe"]}[${${"GLOBALS"}["oklwinvdfh"]}][${${"GLOBALS"}["lidsqndylvq"]}];
     }
     global $current_user;
     ${$prxedru} = \Vtiger_Module_Model::getInstance(${${"GLOBALS"}["mzocslvphn"]});
     if (${${"GLOBALS"}["fzwbepjlgw"]} instanceof \Inventory_Module_Model) {
         $rdfydtrw = "userID";
         $bgggyhjuaazh = "module_name";
         VTEntity::${${"GLOBALS"}["abwmltbg"]}[${$rdfydtrw}][${${"GLOBALS"}["htjiqkfioz"]}] = new VTInventoryEntity(${$bgggyhjuaazh}, ${${"GLOBALS"}["htjiqkfioz"]});
     } else {
         ${"GLOBALS"}["tuyxlsowgs"] = "userID";
         ${"GLOBALS"}["ygchzxehnsjf"] = "_cache";
         VTEntity::${${"GLOBALS"}["ygchzxehnsjf"]}[${${"GLOBALS"}["tuyxlsowgs"]}][${${"GLOBALS"}["htjiqkfioz"]}] = new VTEntity(${${"GLOBALS"}["mzocslvphn"]}, ${${"GLOBALS"}["htjiqkfioz"]});
     }
     return VTEntity::${${"GLOBALS"}["ggrdjoffmb"]}[${$uwvatjqrp}][${${"GLOBALS"}["htjiqkfioz"]}];
 }
Example #9
0
function vtws_sync($mtime, $elementType, $user)
{
    global $adb, $recordString, $modifiedTimeString;
    $ignoreModules = array("");
    $typed = true;
    $dformat = "Y-m-d H:i:s";
    $datetime = date($dformat, $mtime);
    $setypeArray = array();
    $setypeData = array();
    $setypeHandler = array();
    $setypeNoAccessArray = array();
    if (!isset($elementType) || $elementType == '' || $elementType == null) {
        $typed = false;
    }
    $adb->startTransaction();
    $q = "select crmid,setype from vtiger_crmentity where modifiedtime >? and smownerid=? and deleted=0";
    $params = array($datetime, $user->id);
    if ($typed) {
        $q = $q . " and setype=?";
        array_push($params, $elementType);
    }
    $result = $adb->pquery($q, $params);
    do {
        if ($arre) {
            if (strpos($arre["setype"], " ") === FALSE) {
                if ($arre["setype"] == 'Calendar') {
                    $seType = vtws_getCalendarEntityType($arre['crmid']);
                } else {
                    $seType = $arre["setype"];
                }
                if (array_search($seType, $ignoreModules) === FALSE) {
                    $setypeArray[$arre["crmid"]] = $seType;
                    if (!$setypeData[$seType]) {
                        $webserviceObject = VtigerWebserviceObject::fromName($adb, $seType);
                        $handlerPath = $webserviceObject->getHandlerPath();
                        $handlerClass = $webserviceObject->getHandlerClass();
                        require_once $handlerPath;
                        $setypeHandler[$seType] = new $handlerClass($webserviceObject, $user, $adb, $log);
                        $meta = $setypeHandler[$seType]->getMeta();
                        $setypeData[$seType] = new VtigerCRMObject(getTabId($meta->getEntityName()), true);
                    }
                }
            }
        }
        $arre = $adb->fetchByAssoc($result);
    } while ($arre);
    $output = array();
    $output["updated"] = array();
    foreach ($setypeArray as $key => $val) {
        $handler = $setypeHandler[$val];
        $meta = $handler->getMeta();
        if (!$meta->hasAccess() || !$meta->hasWriteAccess() || !$meta->hasPermission(EntityMeta::$RETRIEVE, $key)) {
            if (!$setypeNoAccessArray[$val]) {
                $setypeNoAccessArray[] = $val;
            }
            continue;
        }
        try {
            $error = $setypeData[$val]->read($key);
            if (!$error) {
                //Ignore records whose fetch results in an error.
                continue;
            }
            $output["updated"][] = DataTransform::filterAndSanitize($setypeData[$val]->getFields(), $meta);
        } catch (WebServiceException $e) {
            //ignore records the user doesn't have access to.
            continue;
        } catch (Exception $e) {
            throw new WebServiceException(WebServiceErrorCode::$INTERNALERROR, "Unknown Error while processing request");
        }
    }
    $setypeArray = array();
    $setypeData = array();
    $q = "select crmid,setype,modifiedtime from vtiger_crmentity where modifiedtime >? and smownerid=? and deleted=1";
    $params = array($datetime, $user->id);
    if ($typed) {
        $q = $q . " and setype=?";
        array_push($params, $elementType);
    }
    $result = $adb->pquery($q, $params);
    do {
        if ($arre) {
            if (strpos($arre["setype"], " ") === FALSE) {
                if ($arre["setype"] == 'Calendar') {
                    $seType = vtws_getCalendarEntityType($arre['crmid']);
                } else {
                    $seType = $arre["setype"];
                }
                if (array_search($seType, $ignoreModules) === FALSE) {
                    $setypeArray[$arre["crmid"]] = $seType;
                    if (!$setypeData[$seType]) {
                        $webserviceObject = VtigerWebserviceObject::fromName($adb, $seType);
                        $handlerPath = $webserviceObject->getHandlerPath();
                        $handlerClass = $webserviceObject->getHandlerClass();
                        require_once $handlerPath;
                        $setypeHandler[$seType] = new $handlerClass($webserviceObject, $user, $adb, $log);
                        $meta = $setypeHandler[$seType]->getMeta();
                        $setypeData[$seType] = new VtigerCRMObject(getTabId($meta->getEntityName()), true);
                    }
                }
            }
        }
        $arre = $adb->fetchByAssoc($result);
    } while ($arre);
    $output["deleted"] = array();
    foreach ($setypeArray as $key => $val) {
        $handler = $setypeHandler[$val];
        $meta = $handler->getMeta();
        if (!$meta->hasAccess() || !$meta->hasWriteAccess()) {
            if (!$setypeNoAccessArray[$val]) {
                $setypeNoAccessArray[] = $val;
            }
            continue;
        }
        $output["deleted"][] = vtws_getId($meta->getEntityId(), $key);
    }
    $q = "select max(modifiedtime) as modifiedtime from vtiger_crmentity where modifiedtime >? and smownerid=?";
    $params = array($datetime, $user->id);
    if ($typed) {
        $q = $q . " and setype=?";
        array_push($params, $elementType);
    } else {
        if (sizeof($setypeNoAccessArray) > 0) {
            $q = $q . " and setype not in ('" . generateQuestionMarks($setypeNoAccessArray) . "')";
            array_push($params, $setypeNoAccessArray);
        }
    }
    $result = $adb->pquery($q, $params);
    $arre = $adb->fetchByAssoc($result);
    $modifiedtime = $arre['modifiedtime'];
    if (!$modifiedtime) {
        $modifiedtime = $mtime;
    } else {
        $modifiedtime = vtws_getSeconds($modifiedtime);
    }
    if (is_string($modifiedtime)) {
        $modifiedtime = intval($modifiedtime);
    }
    $output['lastModifiedTime'] = $modifiedtime;
    $error = $adb->hasFailedTransaction();
    $adb->completeTransaction();
    if ($error) {
        throw new WebServiceException(WebServiceErrorCode::$DATABASEQUERYERROR, "Database error while performing required operation");
    }
    VTWS_PreserveGlobal::flush();
    return $output;
}