/** * Function to related two records of different entity types */ function relateEntities($focus, $sourceModule, $sourceRecordId, $destinationModule, $destinationRecordIds) { if (!is_array($destinationRecordIds)) { $destinationRecordIds = array($destinationRecordIds); } $data = array(); $data['focus'] = $focus; $data['sourceModule'] = $sourceModule; $data['sourceRecordId'] = $sourceRecordId; $data['destinationModule'] = $destinationModule; foreach ($destinationRecordIds as $destinationRecordId) { $data['destinationRecordId'] = $destinationRecordId; cbEventHandler::do_action('corebos.entity.link.before', $data); $focus->save_related_module($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId); $focus->trackLinkedInfo($sourceModule, $sourceRecordId, $destinationModule, $destinationRecordId); cbEventHandler::do_action('corebos.entity.link.after', $data); } }
} $sid = $sessionManager->startSession($sessionId, $adoptSession); if (!$sessionId && !$operationManager->isPreLoginOperation()) { writeErrorOutput($operationManager, new WebServiceException(WebServiceErrorCode::$AUTHREQUIRED, "Authentication required")); return; } if (!$sid) { writeErrorOutput($operationManager, $sessionManager->getError()); return; } $userid = $sessionManager->get("authenticatedUserId"); if ($userid) { $seed_user = new Users(); $current_user = $seed_user->retrieveCurrentUserInfoFromFile($userid); } else { $current_user = null; } $operationInput = $operationManager->sanitizeOperation($input); $includes = $operationManager->getOperationIncludes(); foreach ($includes as $ind => $path) { checkFileAccessForInclusion($path); require_once $path; } cbEventHandler::do_action('corebos.audit.action', array(isset($current_user) ? $current_user->id : 0, 'Webservice', $operation, 0, date('Y-m-d H:i:s'))); $rawOutput = $operationManager->runOperation($operationInput, $current_user); writeOutput($operationManager, $rawOutput); } catch (WebServiceException $e) { writeErrorOutput($operationManager, $e); } catch (Exception $e) { writeErrorOutput($operationManager, new WebServiceException(WebServiceErrorCode::$INTERNALERROR, "Unknown Error while processing request")); }
public function createRecords() { $adb = PearDatabase::getInstance(); $moduleName = $this->module; $focus = CRMEntity::getInstance($moduleName); $moduleHandler = vtws_getModuleHandlerFromName($moduleName, $this->user); $moduleMeta = $moduleHandler->getMeta(); $moduleObjectId = $moduleMeta->getEntityId(); $moduleFields = $moduleMeta->getModuleFields(); $tableName = Import_Utils::getDbTableName($this->user); $sql = 'SELECT * FROM ' . $tableName . ' WHERE status = ' . Import_Data_Controller::$IMPORT_RECORD_NONE; if ($this->batchImport) { $configReader = new ConfigReader('modules/Import/config.inc', 'ImportConfig'); $importBatchLimit = $configReader->getConfig('importBatchLimit'); $sql .= ' LIMIT ' . $importBatchLimit; } $result = $adb->query($sql); $numberOfRecords = $adb->num_rows($result); if ($numberOfRecords <= 0) { return; } $fieldMapping = $this->fieldMapping; $fieldColumnMapping = $moduleMeta->getFieldColumnMapping(); for ($i = 0; $i < $numberOfRecords; ++$i) { $row = $adb->raw_query_result_rowdata($result, $i); $rowId = $row['id']; $entityInfo = null; $fieldData = array(); foreach ($fieldMapping as $fieldName => $index) { $fieldData[$fieldName] = $row[$fieldName]; } $mergeType = $this->mergeType; $createRecord = false; if (method_exists($focus, 'importRecord')) { $entityInfo = $focus->importRecord($this, $fieldData); } else { if (!empty($mergeType) && $mergeType != Import_Utils::$AUTO_MERGE_NONE) { $queryGenerator = new QueryGenerator($moduleName, $this->user); $queryGenerator->initForDefaultCustomView(); $fieldsList = array('id'); $queryGenerator->setFields($fieldsList); $mergeFields = $this->mergeFields; foreach ($mergeFields as $index => $mergeField) { if ($index != 0) { $queryGenerator->addConditionGlue(QueryGenerator::$AND); } $comparisonValue = $fieldData[$mergeField]; $fieldInstance = $moduleFields[$mergeField]; if ($fieldInstance->getFieldDataType() == 'owner') { $userId = getUserId_Ol($comparisonValue); $comparisonValue = getUserFullName($userId); } if ($fieldInstance->getFieldDataType() == 'reference') { if (strpos($comparisonValue, '::::') > 0) { $referenceFileValueComponents = explode('::::', $comparisonValue); } else { $referenceFileValueComponents = explode(':::', $comparisonValue); } if (count($referenceFileValueComponents) > 1) { $comparisonValue = trim($referenceFileValueComponents[1]); } } $queryGenerator->addCondition($mergeField, $comparisonValue, 'e'); } $query = $queryGenerator->getQuery(); $duplicatesResult = $adb->query($query); $noOfDuplicates = $adb->num_rows($duplicatesResult); if ($noOfDuplicates > 0) { if ($mergeType == Import_Utils::$AUTO_MERGE_IGNORE) { $entityInfo['status'] = self::$IMPORT_RECORD_SKIPPED; } elseif ($mergeType == Import_Utils::$AUTO_MERGE_OVERWRITE || $mergeType == Import_Utils::$AUTO_MERGE_MERGEFIELDS) { for ($index = 0; $index < $noOfDuplicates - 1; ++$index) { $duplicateRecordId = $adb->query_result($duplicatesResult, $index, $fieldColumnMapping['id']); $entityId = vtws_getId($moduleObjectId, $duplicateRecordId); vtws_delete($entityId, $this->user); } $baseRecordId = $adb->query_result($duplicatesResult, $noOfDuplicates - 1, $fieldColumnMapping['id']); $baseEntityId = vtws_getId($moduleObjectId, $baseRecordId); if ($mergeType == Import_Utils::$AUTO_MERGE_OVERWRITE) { $fieldData = $this->transformForImport($fieldData, $moduleMeta); $fieldData['id'] = $baseEntityId; $entityInfo = vtws_update($fieldData, $this->user); $entityInfo['status'] = self::$IMPORT_RECORD_UPDATED; //Prepare data for event handler $entityData = array(); $entityData['rowId'] = $rowId; $entityData['tableName'] = $tableName; $entityData['entityInfo'] = $entityInfo; $entityData['fieldData'] = $fieldData; $entityData['moduleName'] = $moduleName; $entityData['user'] = $this->user; cbEventHandler::do_action('corebos.entity.import.overwrite', $entityData); } if ($mergeType == Import_Utils::$AUTO_MERGE_MERGEFIELDS) { $filteredFieldData = array(); $defaultFieldValues = $this->getDefaultFieldValues($moduleMeta); foreach ($fieldData as $fieldName => $fieldValue) { if (!empty($fieldValue)) { $filteredFieldData[$fieldName] = $fieldValue; } } $existingFieldValues = vtws_retrieve($baseEntityId, $this->user); foreach ($existingFieldValues as $fieldName => $fieldValue) { if (empty($fieldValue) && empty($filteredFieldData[$fieldName]) && !empty($defaultFieldValues[$fieldName])) { $filteredFieldData[$fieldName] = $fieldValue; } } $filteredFieldData = $this->transformForImport($filteredFieldData, $moduleMeta, false, true); $filteredFieldData['id'] = $baseEntityId; $entityInfo = vtws_revise($filteredFieldData, $this->user); $entityInfo['status'] = self::$IMPORT_RECORD_MERGED; //Prepare data for event handler $entityData = array(); $entityData['rowId'] = $rowId; $entityData['tableName'] = $tableName; $entityData['entityInfo'] = $entityInfo; $entityData['fieldData'] = $fieldData; $entityData['moduleName'] = $moduleName; $entityData['user'] = $this->user; cbEventHandler::do_action('corebos.entity.import.merge', $entityData); } } else { $createRecord = true; } } else { $createRecord = true; } } else { $createRecord = true; } if ($createRecord) { $fieldData = $this->transformForImport($fieldData, $moduleMeta); if ($fieldData == null) { $entityInfo = null; } else { $entityInfo = vtws_create($moduleName, $fieldData, $this->user); $entityInfo['status'] = self::$IMPORT_RECORD_CREATED; //Prepare data for event handler $entityData = array(); $entityData['rowId'] = $rowId; $entityData['tableName'] = $tableName; $entityData['entityInfo'] = $entityInfo; $entityData['fieldData'] = $fieldData; $entityData['moduleName'] = $moduleName; $entityData['user'] = $this->user; cbEventHandler::do_action('corebos.entity.import.create', $entityData); } } } if ($entityInfo == null) { $entityInfo = array('id' => null, 'status' => self::$IMPORT_RECORD_FAILED); } $this->importedRecordInfo[$rowId] = $entityInfo; $this->updateImportStatus($rowId, $entityInfo); } unset($result); return true; }
/** * Function to track when a record is unlinked to a given record */ function trackUnLinkedInfo($module, $crmid, $with_module, $with_crmid) { global $current_user; $adb = PearDatabase::getInstance(); $currentTime = date('Y-m-d H:i:s'); $data = array(); $data['sourceModule'] = $module; $data['sourceRecordId'] = $crmid; $data['destinationModule'] = $with_module; $data['destinationRecordId'] = $with_crmid; cbEventHandler::do_action('corebos.entity.link.delete', $data); $adb->pquery('UPDATE vtiger_crmentity SET modifiedtime = ?, modifiedby = ? WHERE crmid = ?', array($currentTime, $current_user->id, $crmid)); }
// We check if we have the two new logo fields > if not we create them $cnorg = $adb->getColumnNames('vtiger_organizationdetails'); if (!in_array('faviconlogo', $cnorg)) { $adb->query('ALTER TABLE `vtiger_organizationdetails` ADD `frontlogo` VARCHAR(150) NOT NULL, ADD `faviconlogo` VARCHAR(150) NOT NULL'); } $sql = "select * from vtiger_organizationdetails"; $result = $adb->pquery($sql, array()); //Handle for allowed organization logo/logoname likes UTF-8 Character // $organization_logo = decode_html($adb->query_result($result,0,'logoname')); // if(!file_exists('test/logo/'.$organization_logo)) $organization_logo='noimageloaded.png'; // $smarty->assign("LOGO",$organization_logo); $favicon = decode_html($adb->query_result($result, 0, 'faviconlogo')); if ($favicon == '') { $favicon = 'themes/images/favicon.ico'; } else { $favicon = 'test/logo/' . $favicon; } $smarty->assign("FAVICON", $favicon); $frontlogo = decode_html($adb->query_result($result, 0, 'frontlogo')); if ($frontlogo == '') { $frontlogo = 'noimageloaded.png'; } $smarty->assign("FRONTLOGO", $frontlogo); $companyDetails = array(); $companyDetails['name'] = $adb->query_result($result, 0, 'organizationname'); $companyDetails['website'] = $adb->query_result($result, 0, 'website'); $companyDetails['logo'] = $organization_logo; $smarty->assign("COMPANY_DETAILS", $companyDetails); $smarty->display("Header.tpl"); cbEventHandler::do_action('corebos.header');
//added to get the theme . This is a bad fix as we need to know where the problem lies yet if (isset($_SESSION['vtiger_authenticated_user_theme']) && $_SESSION['vtiger_authenticated_user_theme'] != '') { $theme = $_SESSION['vtiger_authenticated_user_theme']; } else { $theme = $default_theme; } $Ajx_module = $module; if ($module == 'Events') { $Ajx_module = 'Calendar'; } if (!$viewAttachment && (!$viewAttachment && $action != 'home_rss') && $action != 'Tickerdetail' && $action != $Ajx_module . "Ajax" && $action != "chat" && $action != "HeadLines" && $action != 'massdelete' && $action != "DashboardAjax" && $action != "ActivityAjax") { // Under the SPL you do not have the right to remove this copyright statement. $copyrightstatement = "<style>\n\t\t.bggray\n\t\t{\n\t\t\tbackground-color: #dfdfdf;\n\t\t}\n\t.bgwhite\n\t{\n\t\tbackground-color: #FFFFFF;\n\t}\n\t.copy\n\t{\n\t\tfont-size:9px;\n\t\tfont-family: Verdana, Arial, Helvetica, Sans-serif;\n\t}\n\t</style>"; if (!$skipFooters && $action != "about_us" && $action != "vtchat" && $action != "ChangePassword" && $action != "body" && $action != $module . "Ajax" && $action != 'Popup' && $action != 'ImportStep3' && $action != 'ActivityAjax' && $action != 'getListOfRecords') { echo $copyrightstatement; cbEventHandler::do_action('corebos.footer.prefooter'); echo "<br><br><br><table border=0 cellspacing=0 cellpadding=5 width=100% class=settingsSelectedUI >"; echo "<tr><td class=small align=left><span style='color: rgb(153, 153, 153);'>Powered by " . getTranslatedString('APP_NAME') . " <span id='_vtiger_product_version_'>{$coreBOS_app_version}</span></span></td>"; echo "<td class=small align=right><span>© 2004-" . date('Y') . " <a href='{$coreBOS_app_url}' target='_blank'>{$coreBOS_app_name}</a> | <a href='copyright.html' target='_blank'>" . $app_strings['LNK_READ_LICENSE'] . "</a> | <a href='http://corebos.org/page/privacy-policy' target='_blank'>" . getTranslatedString('LNK_PRIVACY_POLICY') . "</a></span></td></tr></table>"; // echo "<table align='center'><tr><td align='center'>"; // Under the Sugar Public License referenced above, you are required to leave in all copyright statements // in both the code and end-user application. // if($calculate_response_time) // { // $endTime = microtime(); // $deltaTime = microtime_diff($startTime, $endTime); // echo(' Server response time: '.$deltaTime.' seconds.'); // } // echo "</td></tr></table>\n"; } if ($action != 'mytkt_rss' && $action != 'home_rss' && $action != $module . "Ajax" && $action != "body" && $action != 'ActivityAjax') {
$tmp_file_name = $import_dir . "IMPORT_" . $focus->id; if (file_exists($tmp_file_name)) { unlink($tmp_file_name); } $arr = $_SESSION['lastpage']; if (isset($_SESSION['lastpage'])) { header("Location: index.php?" . $arr); } else { header("Location: index.php"); } } else { $sql = 'select failed_login_attempts from vtiger_users where user_name=?'; $result = $adb->pquery($sql, array($focus->column_fields["user_name"])); $failed_login_attempts = 0; if ($result and $adb->num_rows($result) > 0) { $failed_login_attempts = $adb->query_result($result, 0, 0); } $maxFailedLoginAttempts = GlobalVariable::getVariable('Application_MaxFailedLoginAttempts', 5); // Increment number of failed login attempts $query = 'UPDATE vtiger_users SET failed_login_attempts=COALESCE(failed_login_attempts,0)+1 where user_name=?'; $adb->pquery($query, array($focus->column_fields['user_name'])); $_SESSION['login_user_name'] = $focus->column_fields["user_name"]; $_SESSION['login_password'] = $user_password; if (empty($_SESSION['login_error'])) { $_SESSION['login_error'] = $failed_login_attempts >= $maxFailedLoginAttempts ? $mod_strings['ERR_MAXLOGINATTEMPTS'] : $mod_strings['ERR_INVALID_PASSWORD']; } cbEventHandler::do_action('corebos.audit.login.attempt', array(0, $focus->column_fields["user_name"], 'Login Attempt', 0, date('Y-m-d H:i:s'))); // go back to the login screen. // create an error message for the user. header("Location: index.php"); }
function delete_related_module($module, $crmid, $with_module, $with_crmid) { global $log, $adb; if ($with_module == 'Contacts') { if (!is_array($with_crmid)) { $with_crmid = array($with_crmid); } $data = array(); $data['sourceModule'] = $module; $data['sourceRecordId'] = $crmid; $data['destinationModule'] = $with_module; foreach ($with_crmid as $relcrmid) { $data['destinationRecordId'] = $relcrmid; cbEventHandler::do_action('corebos.entity.link.delete', $data); $adb->pquery('DELETE FROM vtiger_vendorcontactrel WHERE vendorid=? AND contactid=?', array($crmid, $relcrmid)); } } else { parent::delete_related_module($module, $crmid, $with_module, $with_crmid); } }
/** Function that Records the Logout info of the User * @param ref variable $usname :: Type varchar * @param ref variable $usip :: Type varchar * @param ref variable $outime :: Type timestamp * Returns the query result which contains the details of User Logout Info */ function user_logout(&$usname, &$usip, &$outtime) { global $adb; cbEventHandler::do_action('corebos.audit.logout', array($usname, 'Users', 'Logout', $usname, date("Y-m-d H:i:s"))); $logid_qry = "SELECT max(login_id) AS login_id from vtiger_loginhistory where user_name=? and user_ip=?"; $result = $adb->pquery($logid_qry, array($usname, $usip)); $loginid = $adb->query_result($result, 0, "login_id"); if ($loginid == '') { return; } // update the user login info. $query = "Update vtiger_loginhistory set logout_time =?, status=? where login_id = ?"; $result = $adb->pquery($query, array($this->db->formatDate($outtime, true), 'Signed off', $loginid)) or die("MySQL error: " . mysql_error()); }