function process(Mobile_API_Request $request) { $response = new Mobile_API_Response(); $username = $request->get('username'); $password = $request->get('password'); $current_user = CRMEntity::getInstance('Users'); $current_user->column_fields['user_name'] = $username; if (vtlib_isModuleActive('Mobile') === false) { $response->setError(1501, 'Service not available'); return $response; } if (!$current_user->doLogin($password)) { $response->setError(1210, 'Authentication Failed'); } else { // Start session now $sessionid = Mobile_API_Session::init(); if ($sessionid === false) { echo "Session init failed {$sessionid}\n"; } $current_user->id = $current_user->retrieve_user_id($username); $current_user->retrieveCurrentUserInfoFromFile($current_user->id); $this->setActiveUser($current_user); $result = array(); $result['login'] = array('userid' => $current_user->id, 'crm_tz' => DateTimeField::getDBTimeZone(), 'user_tz' => $current_user->time_zone, 'user_currency' => $current_user->currency_code, 'session' => $sessionid, 'vtiger_version' => Mobile_WS_Utils::getVtigerVersion(), 'date_format' => $current_user->date_format, 'mobile_module_version' => Mobile_WS_Utils::getVersion()); $response->setResult($result); $this->postProcess($response); } return $response; }
function process(Mobile_API_Request $request) { $response = new Mobile_API_Response(); $username = $request->get('username'); $password = $request->get('password'); $current_user = CRMEntity::getInstance('Users'); $current_user->column_fields['user_name'] = $username; if (vtlib_isModuleActive('Mobile') === false) { $response->setError(1501, 'Service not available'); return $response; } if (!$current_user->load_user($password) || !$current_user->authenticated) { global $mod_strings; $response->setError(1210, $mod_strings['ERR_INVALID_PASSWORD']); } else { // Start session now $sessionid = Mobile_API_Session::init(); if ($sessionid === false) { echo "Session init failed {$sessionid}\n"; } include_once 'config.php'; global $application_unique_key; $current_user->id = $current_user->retrieve_user_id($username); $this->setActiveUser($current_user); $_SESSION["authenticated_user_id"] = $current_user->id; $_SESSION["app_unique_key"] = $application_unique_key; $result = array(); $result['login'] = array('userid' => $current_user->id, 'crm_tz' => DateTimeField::getDBTimeZone(), 'user_tz' => $current_user->time_zone, 'session' => $sessionid, 'language' => $current_user->language, 'vtiger_version' => Mobile_WS_Utils::getVtigerVersion(), 'mobile_module_version' => Mobile_WS_Utils::getVersion()); $response->setResult($result); $this->postProcess($response); } return $response; }
function process(Mobile_API_Request $request) { $response = new Mobile_API_Response(); $current_user = $this->getActiveUser(); $module = $request->get('module'); $moduleWSID = Mobile_WS_Utils::getEntityModuleWSId($module); if (empty($module)) { $response->setError(1501, "Module not specified."); return $response; } $records = array(); // Fetch the request parameters $idlist = $request->get('ids'); $alertid = $request->get('alertid'); // List of ids specified? if (!empty($idlist)) { $idlist = Zend_Json::decode($idlist); $records = $this->fetchRecordsWithId($module, $idlist, $current_user); } else { if (!empty($alertid)) { $alert = Mobile_WS_AlertModel::modelWithId($alertid); if ($alert === false) { $response->setError(1404, "Alert not found."); $records = false; } $alert->setUser($current_user); $records = $this->fetchAlertRecords($module, $alert); } } if ($records !== false) { $response->setResult(array('records' => $records)); } return $response; }
function process(Mobile_API_Request $request) { $response = new Mobile_API_Response(); global $adb; global $current_language; $current_language = Mobile_API_Session::get('language'); //never trust an entry $sSearch = vtlib_purify($request->get('term')); $sResult = ""; $arrayName = array(); $ModuleArray = explode(',', vtlib_purify($request->get('relmodule'))); $ModuleLabels = array(); foreach ($ModuleArray as $Module) { $translatedModule = getTranslatedString($Module, 'Mobile'); $arrayName[$translatedModule] = array(); $moduleWSID = Mobile_WS_Utils::getEntityModuleWSId($Module); // get related module fields $query = "SELECT tablename,fieldname,entityidfield FROM vtiger_entityname WHERE modulename = ?"; $result = $adb->pquery($query, array($Module)); if (!$result or $adb->num_rows($result) == 0) { $response->setError(1407, 'Error: Could not fetch entity info'); return $response; } $tablename = $adb->query_result($result, 0, 'tablename'); $fieldname = $adb->query_result($result, 0, 'fieldname'); $entityidfield = $adb->query_result($result, 0, 'entityidfield'); $fieldname = explode(',', $fieldname); $fieldname = $fieldname[0]; //START DATABASE ACCOUNT SEARCH $minhaquery = "SELECT " . $fieldname . "," . $entityidfield . " FROM " . $tablename . " \n\t\t\t\t\t\t\tINNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = " . $tablename . "." . $entityidfield . "\n\t\t\t\t\t\t\tWHERE deleted = 0 AND " . $fieldname . " LIKE ? ORDER BY " . $fieldname . ""; $params = $sSearch . "%"; $result = $adb->pquery($minhaquery, array($params)); if (!$result) { $response->setError(1408, 'Error: Could not fetch entity data'); return $response; } for ($i = 0; $i < $adb->num_rows($result); $i++) { $arrayName[$translatedModule][] = array($moduleWSID . 'x' . $adb->query_result($result, $i, $entityidfield), decode_html($adb->query_result($result, $i, $fieldname))); } } $sResult = $arrayName; $sResult = json_encode($sResult); $response->setResult($sResult); return $response; }
function process(Mobile_API_Request $request) { global $current_user; // Required for vtws_update API $current_user = $this->getActiveUser(); $module = $request->get('module'); //update if recordid exist $recordid = $request->get('record'); $valueArray = Mobile_API_Request::getvaluemap($request); $values = ''; if (!empty($valueArray) && is_string($valueArray)) { $values = Zend_Json::decode($valueArray); } else { $values = $valueArray; // Either empty or already decoded. } //catch error $response = new Mobile_API_Response(); if (empty($values)) { $response->setError(1501, "Values cannot be empty!"); return $response; } try { // Retrieve or Initialize if (!empty($recordid)) { $this->recordValues = parent::processRetrieve($request); } else { $this->recordValues = array(); } // Set the modified values foreach ($values as $name => $value) { $this->recordValues[$name] = $value; } // Update or Create if (isset($this->recordValues['id'])) { $this->recordValues = vtws_update($this->recordValues, $current_user); } else { // Set right target module name for Calendar/Event record if ($module == 'Calendar') { if (!empty($this->recordValues['eventstatus']) && $this->recordValues['activitytype'] != 'Task') { $module = 'Events'; } } $this->recordValues = vtws_create($module, $this->recordValues, $current_user); } // Update the record id $request->set('record', $this->recordValues['id']); $request->set('id', $this->recordValues['id']); // Gather response with full details $response = parent::process($request); } catch (Exception $e) { $response->setError($e->getCode(), $e->getMessage()); } return $response; }
function process(Mobile_API_Request $request) { global $current_user, $adb, $currentModule; $current_user = $this->getActiveUser(); $response = new Mobile_API_Response(); $record = $request->get('record'); $relatedmodule = $request->get('relatedmodule'); $currentPage = $request->get('page', 0); // Input validation if (empty($record)) { $response->setError(1001, 'Record id is empty'); return $response; } $recordid = vtws_getIdComponents($record); $recordid = $recordid[1]; $module = Mobile_WS_Utils::detectModulenameFromRecordId($record); // Initialize global variable $currentModule = $module; $functionHandler = Mobile_WS_Utils::getRelatedFunctionHandler($module, $relatedmodule); if ($functionHandler) { $sourceFocus = CRMEntity::getInstance($module); $relationResult = call_user_func_array(array($sourceFocus, $functionHandler), array($recordid, getTabid($module), getTabid($relatedmodule))); $query = $relationResult['query']; $querySEtype = "vtiger_crmentity.setype as setype"; if ($relatedmodule == 'Calendar') { $querySEtype = "vtiger_activity.activitytype as setype"; } $query = sprintf("SELECT vtiger_crmentity.crmid, {$querySEtype} %s", substr($query, stripos($query, 'FROM'))); $queryResult = $adb->query($query); // Gather resolved record id's $relatedRecords = array(); while ($row = $adb->fetch_array($queryResult)) { $targetSEtype = $row['setype']; if ($relatedmodule == 'Calendar') { if ($row['setype'] != 'Task' && $row['setype'] != 'Emails') { $targetSEtype = 'Events'; } else { $targetSEtype = $relatedmodule; } } $relatedRecords[] = sprintf("%sx%s", Mobile_WS_Utils::getEntityModuleWSId($targetSEtype), $row['crmid']); } // Perform query to get record information with grouping $wsquery = sprintf("SELECT * FROM %s WHERE id IN ('%s');", $relatedmodule, implode("','", $relatedRecords)); $newRequest = new Mobile_API_Request(); $newRequest->set('module', $relatedmodule); $newRequest->set('query', $wsquery); $newRequest->set('page', $currentPage); $response = parent::process($newRequest); } return $response; }
function process(Mobile_API_Request $request) { global $current_user, $adb, $currentModule; $current_user = $this->getActiveUser(); $response = new Mobile_API_Response(); $record = $request->get('record'); $currentPage = $request->get('page', 0); // Input validation if (empty($record)) { $response->setError(1001, 'Record id is empty'); return $response; } $recordid = vtws_getIdComponents($record); $recordid = $recordid[1]; $module = Mobile_WS_Utils::detectModulenameFromRecordId($record); // Initialize global variable $currentModule = $module; //related module currently supported $relatedmodule = array('Contacts', 'Potentials', 'HelpDesk'); $activemodule = $this->sessionGet('_MODULES'); foreach ($activemodule as $amodule) { if (in_array($amodule->name(), $relatedmodule)) { $active_related_module[] = $amodule->name(); } } foreach ($active_related_module as $relmod) { $functionHandler = Mobile_WS_Utils::getRelatedFunctionHandler($module, $relmod); $fieldmodel = new Mobile_UI_FieldModel(); if ($functionHandler) { $sourceFocus = CRMEntity::getInstance($module); $relationResult = call_user_func_array(array($sourceFocus, $functionHandler), array($recordid, getTabid($module), getTabid($relmod))); $relatedRecords[$relmod] = array_keys($relationResult['entries']); $response->setResult($relatedRecords); } else { $response->setError(1018, 'Function Handler for module ' . $module . ' for related Module ' . $relmod . ' not found.'); } } return $response; }
static function process(Mobile_API_Request $request) { $operation = $request->getOperation(); $sessionid = HTTP_Session::detectId(); //$request->getSession(); if (empty($operation)) { $operation = 'login'; } $response = false; if (isset(self::$opControllers[$operation])) { $operationFile = self::$opControllers[$operation]['file']; $operationClass = self::$opControllers[$operation]['class']; include_once dirname(__FILE__) . $operationFile; $operationController = new $operationClass(); $operationSession = false; if ($operationController->requireLogin()) { $operationSession = Mobile_API_Session::init($sessionid); if ($operationController->hasActiveUser() === false) { $operationSession = false; } //Mobile_WS_Utils::initAppGlobals(); } else { // By-pass login $operationSession = true; } if ($operationSession === false) { $response = new Mobile_API_Response(); $response->setError(1501, 'Login required'); } else { try { $response = $operationController->process($request); } catch (Exception $e) { $response = new Mobile_API_Response(); $response->setError($e->getCode(), $e->getMessage()); } } } else { $response = new Mobile_API_Response(); $response->setError(1404, 'Operation not found: ' . $operation); } if ($response !== false) { if ($response->hasError()) { include_once dirname(__FILE__) . '/ui/Error.php'; $errorController = new Mobile_UI_Error(); $errorController->setError($response->getError()); echo $errorController->process($request)->emitHTML(); } else { echo $response->emitHTML(); } } }
function process(Mobile_API_Request $request) { global $current_user; $response = new Mobile_API_Response(); $alertid = $request->get('alertid'); $current_user = $this->getActiveUser(); $alert = $this->getAlertDetails($alertid); if (empty($alert)) { $response->setError(1401, 'Alert not found'); } else { $result = array(); $result['alert'] = $this->getAlertDetails($alertid); $response->setResult($result); } return $response; }
function processSearchRecordLabel(Mobile_API_Request $request) { global $current_user; // Few core API assumes this variable availability $current_user = $this->getActiveUser(); $module = $request->get('module'); $alertid = $request->get('alertid'); $filterid = $request->get('filterid'); $search = $request->get('search'); $filterOrAlertInstance = false; if (!empty($alertid)) { $filterOrAlertInstance = Mobile_WS_AlertModel::modelWithId($alertid); } else { if (!empty($filterid)) { $filterOrAlertInstance = Mobile_WS_FilterModel::modelWithId($module, $filterid); } else { if (!empty($search)) { $filterOrAlertInstance = $this->getSearchFilterModel($module, $search); } } } if ($filterOrAlertInstance && strcmp($module, $filterOrAlertInstance->moduleName)) { $response = new Mobile_API_Response(); $response->setError(1001, 'Mistached module information.'); return $response; } // Initialize with more information if ($filterOrAlertInstance) { $filterOrAlertInstance->setUser($current_user); } // Paging model $pagingModel = $this->getPagingModel($request); if ($this->isCalendarModule($module)) { return $this->processSearchRecordLabelForCalendar($request, $pagingModel); } $records = $this->fetchRecordLabelsForModule($module, $current_user, array(), $filterOrAlertInstance, $pagingModel); $modifiedRecords = array(); foreach ($records as $record) { if ($record instanceof SqlResultIteratorRow) { $record = $record->data; // Remove all integer indexed mappings for ($index = count($record); $index > -1; --$index) { if (isset($record[$index])) { unset($record[$index]); } } } $recordid = $record['id']; unset($record['id']); $eventstart = ''; if ($this->isCalendarModule($module)) { $eventstart = $record['date_start']; unset($record['date_start']); } $values = array_values($record); $label = implode(' ', $values); $modifiedRecord = array('id' => $recordid, 'label' => $label); if (!empty($eventstart)) { $modifiedRecord['eventstart'] = $eventstart; } $modifiedRecords[] = $modifiedRecord; } $response = new Mobile_API_Response(); $response->setResult(array('records' => $modifiedRecords, 'module' => $module)); return $response; }
function process(Mobile_API_Request $request) { if ($request->get('username') == '') { $response = new Mobile_API_Response(); $response->setError(1501, 'Login required'); } else { global $displayed_modules, $current_language, $current_user, $mod_strings, $app_strings; $username = $request->get('username'); $current_user = CRMEntity::getInstance('Users'); $userid = $current_user->retrieve_user_id($username); $current_user = $current_user->retrieveCurrentUserInfoFromFile($userid); $language = $current_user->language; $CRM_Version = Mobile::config('crm_version'); if ($CRM_Version != '5.2.1') { //for v5.3.0 use User's Settings if ($language != '') { $current_language = $language; } else { $current_language = 'en_us'; } } else { //for v5.2.1 use default language global $adb; $queryResult = $adb->pquery("SELECT prefix FROM vtiger_language WHERE isdefault =1", array()); $current_language = $adb->query_result($queryResult, 0, 'prefix'); } //set $app_strings Mobile_WS_Utils::initAppGlobals(); $wsResponse = parent::process($request); $response = false; if ($wsResponse->hasError()) { $response = $wsResponse; } else { $wsResponseResult = $wsResponse->getResult(); //fill cache $modules = Mobile_UI_ModuleModel::buildModelsFromResponse($wsResponseResult['modules']); $this->cacheModules($modules); Mobile_API_Session::set('language', $current_language); include dirname(__FILE__) . '/../language/' . $current_language . '.lang.php'; //remove Events from module list display function filter_by_value($array, $index, $value) { if (is_array($array) && count($array) > 0) { foreach (array_keys($array) as $key) { $temp[$key] = $array[$key][$index]; if ($temp[$key] == $value) { $newarray[$key] = $array[$key]; } } } return $newarray; } $eventarray = filter_by_value($wsResponseResult['modules'], 'name', 'Events'); $eventkey = array_keys($eventarray); unset($modules[$eventkey[0]]); $viewer = new Mobile_UI_Viewer(); $viewer->assign('_MODULES', $modules); $viewer->assign('MOD', $mod_strings); //reserved for future use: list modules for global search $viewer->assign('SEARCHIN', implode(",", $displayed_modules)); $response = $viewer->process('generic/Home.tpl'); } } return $response; }