- Added comprehensive AI Assistant system (aiassist/ directory): * Vector search and embedding capabilities * Typebot proxy integration * Elastic search functionality * Message classification and chat history * MCP proxy for external integrations - Implemented Court Status API (GetCourtStatus.php): * Real-time court document status checking * Integration with external court systems * Comprehensive error handling and logging - Enhanced S3 integration: * Improved file backup system with metadata * Batch processing capabilities * Enhanced error logging and recovery * Copy operations with URL fixing - Added Telegram contact creation API - Improved error logging across all modules - Enhanced callback system for AI responses - Extensive backup file storage with timestamps - Updated documentation and README files - File storage improvements: * Thousands of backup files with proper metadata * Fix operations for broken file references * Project-specific backup and recovery systems * Comprehensive file integrity checking Total: 26,461+ files added/modified including AWS SDK, vendor dependencies, and extensive backup system.
972 lines
30 KiB
PHP
972 lines
30 KiB
PHP
<?php
|
|
/* * *******************************************************************************
|
|
* Description: ITS4You Mobile App
|
|
* All Rights Reserved.
|
|
* Contributor: IT-Solutions4You s.r.o - www.its4you.sk
|
|
* ****************************************************************************** */
|
|
|
|
include_once('modules/CustomView/CustomView.php');
|
|
|
|
class ApiListEntriesModel
|
|
{
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $moduleName = '';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $defaultFilter = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $entries = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $headers = [];
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $licenseUrl = '';
|
|
|
|
/**
|
|
* @var integer
|
|
*/
|
|
protected $pageNumber = 1;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $tableFields = [];
|
|
|
|
/**
|
|
* @var integer
|
|
*/
|
|
protected $pageCount = 0;
|
|
|
|
/**
|
|
* @var integer
|
|
*/
|
|
protected $totalCount = 0;
|
|
|
|
/**
|
|
* @var integer
|
|
*/
|
|
protected $pageLimit = 0;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $range = [];
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
protected $searchText = '';
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $searchParamsAdvance = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $filterParams = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $filters = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $overdueActivities = [];
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $upcomingActivities = [];
|
|
|
|
/**
|
|
* @var int
|
|
*/
|
|
protected $userId = 0;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $users = [];
|
|
|
|
/**
|
|
* @var int
|
|
*/
|
|
protected $viewId = 0;
|
|
|
|
/**
|
|
* @param string $moduleName
|
|
*/
|
|
public function setModuleName($moduleName)
|
|
{
|
|
$this->moduleName = $moduleName;
|
|
}
|
|
|
|
/**
|
|
* @param array $defaultFilter
|
|
*/
|
|
public function setDefaultFilter($defaultFilter)
|
|
{
|
|
$this->defaultFilter = $defaultFilter;
|
|
}
|
|
|
|
/**
|
|
* @param integer $recordId
|
|
* @param array $entry
|
|
*/
|
|
public function setEntry($recordId, $entry, $info, $headerFields, $entityName = '')
|
|
{
|
|
$this->entries[] = array(
|
|
'id' => $recordId,
|
|
'fields' => $entry,
|
|
'info' => $info,
|
|
'headerFields' => $headerFields,
|
|
'entityName' => $entityName
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @param array $header
|
|
*/
|
|
public function setHeader($header)
|
|
{
|
|
$this->headers[] = $header;
|
|
}
|
|
|
|
/**
|
|
* @param int $pageNumber
|
|
*/
|
|
public function setPageNumber($pageNumber)
|
|
{
|
|
$this->pageNumber = $pageNumber;
|
|
}
|
|
|
|
/**
|
|
* @param array $tableFields
|
|
*/
|
|
public function setTableFields($tableFields)
|
|
{
|
|
$this->tableFields = $tableFields;
|
|
}
|
|
|
|
/**
|
|
* @param string $searchText
|
|
*/
|
|
public function setSearchText($searchText)
|
|
{
|
|
$this->searchText = $searchText;
|
|
}
|
|
|
|
/**
|
|
* @param array $searchParamsAdvance
|
|
*/
|
|
public function setSearchParamsAdvance($searchParamsAdvance)
|
|
{
|
|
$this->searchParamsAdvance = $searchParamsAdvance;
|
|
}
|
|
|
|
/**
|
|
* @param array $filterParams
|
|
*/
|
|
public function setFilterParams($filterParams)
|
|
{
|
|
$this->filterParams = $filterParams;
|
|
}
|
|
|
|
/**
|
|
* @param array $filters
|
|
*/
|
|
public function setFilters($filters)
|
|
{
|
|
$this->filters = $filters;
|
|
}
|
|
|
|
/**
|
|
* @param array $overdueActivities
|
|
*/
|
|
public function setOverdueActivities($overdueActivities)
|
|
{
|
|
$this->overdueActivities = $overdueActivities;
|
|
}
|
|
|
|
/**
|
|
* @param array $upcomingActivities
|
|
*/
|
|
public function setUpcomingActivities($upcomingActivities)
|
|
{
|
|
$this->upcomingActivities = $upcomingActivities;
|
|
}
|
|
|
|
/**
|
|
* @param int $userId
|
|
*/
|
|
public function setUserId($userId)
|
|
{
|
|
$this->userId = $userId;
|
|
}
|
|
|
|
/**
|
|
* @param array $users
|
|
*/
|
|
public function setUsers($users)
|
|
{
|
|
$this->users = $users;
|
|
}
|
|
|
|
/**
|
|
* @param int $viewId
|
|
*/
|
|
public function setViewId($viewId)
|
|
{
|
|
$this->viewId = $viewId;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getDefaultFilter()
|
|
{
|
|
return $this->defaultFilter;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getEntries()
|
|
{
|
|
return $this->entries;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getHeaders()
|
|
{
|
|
return $this->headers;
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getLicenseUrl()
|
|
{
|
|
return $this->licenseUrl;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getPageNumber()
|
|
{
|
|
return $this->pageNumber;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getPageCount()
|
|
{
|
|
return $this->pageCount;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getTotalCount()
|
|
{
|
|
return $this->totalCount;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getPageLimit()
|
|
{
|
|
return $this->pageLimit;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getRange()
|
|
{
|
|
return $this->range;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getFilters()
|
|
{
|
|
return $this->filters;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getOverdueActivities()
|
|
{
|
|
return $this->overdueActivities;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getUpcomingActivities()
|
|
{
|
|
return $this->upcomingActivities;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function getUsers()
|
|
{
|
|
return $this->users;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getViewId()
|
|
{
|
|
return $this->viewId;
|
|
}
|
|
|
|
/**
|
|
* @param $tableField
|
|
* @return bool
|
|
*/
|
|
public function isTableField($tableField)
|
|
{
|
|
return in_array($tableField, $this->tableFields);
|
|
}
|
|
|
|
public function load()
|
|
{
|
|
//$customView = new CustomView($this->moduleName);
|
|
//$defaultViewId = $customView->getViewId($this->moduleName);
|
|
$defaultViewId = $this->getDefaultViewId();
|
|
$searchParams = [];
|
|
|
|
if (empty($this->viewId)) {
|
|
$this->viewId = $defaultViewId;
|
|
}
|
|
|
|
$listViewModel = ITS4YouMobileApp_ListView_Model::getInstance($this->moduleName, $this->viewId);
|
|
|
|
$pagingModel = new Vtiger_Paging_Model();
|
|
$pagingModel->set('page', $this->pageNumber);
|
|
|
|
if ('Calendar' === $this->moduleName) {
|
|
$pagingModel->set('limit', 500);
|
|
}
|
|
|
|
if (!empty($this->searchText)) {
|
|
$entityFields = $this->getEntityNames();
|
|
|
|
foreach ($entityFields as $fieldName) {
|
|
$searchParams[] = [[$fieldName, 'c', $this->searchText]];
|
|
}
|
|
}
|
|
|
|
if (!empty($searchParams)) {
|
|
$transformedSearchParams = ITS4YouMobileApp_SearchParams_Helper::transferListSearchParamsToFilterCondition($searchParams, $listViewModel->getModule());
|
|
$listViewModel->set('search_params', $transformedSearchParams);
|
|
}
|
|
|
|
if (!empty($this->filterParams)) {
|
|
foreach ($this->filterParams as $name => $value) {
|
|
$field = array(
|
|
'relFieldDep_fldid' => getFieldid(getTabid($this->moduleName), $name),
|
|
'relFieldDep_val' => $value,
|
|
);
|
|
|
|
if (!empty($this->searchParamsAdvance)) {
|
|
$field['relFieldDep_startGroup'] = 'AND';
|
|
}
|
|
|
|
$relFieldDependencies = array($field);
|
|
$listViewModel->set('relfielddependencies', $relFieldDependencies);
|
|
}
|
|
}
|
|
|
|
$headers = $listViewModel->getListViewHeaders();
|
|
|
|
foreach ($headers as $header) {
|
|
$headerColumn = $header->get('column');
|
|
|
|
if ($header->isNameField() || $this->isTableField($headerColumn)) {
|
|
$this->setHeader(array(
|
|
'column' => $headerColumn,
|
|
'label' => vtranslate($header->get('label'), $this->moduleName)
|
|
));
|
|
}
|
|
}
|
|
|
|
$customView = ITS4YouMobileApp_Record_Model::getInstanceById($this->viewId);
|
|
$recordIds = $customView->getRecordIds();
|
|
$listViewCount = count($recordIds);
|
|
$moduleModel = Vtiger_Module_Model::getInstance($this->moduleName);
|
|
$fieldModels = $moduleModel->getFields();
|
|
|
|
$entries = $listViewModel->getListViewEntries($pagingModel);
|
|
|
|
/*if (!empty($this->searchText) && !empty($entries)) {
|
|
foreach ($fieldModels as $fieldModel) {
|
|
if ($fieldModel->get('headerfield')) {
|
|
$listViewModel = Vtiger_ListView_Model::getInstanceForPopup($this->moduleName);
|
|
$listViewModel->set('search_key', $fieldModel->get('name'));
|
|
$listViewModel->set('search_value', $this->searchText);
|
|
|
|
foreach ($listViewModel->getListViewEntries($pagingModel) as $entry) {
|
|
if (!in_array($entry->getId(), array_keys($entries))) {
|
|
array_push($entries, $entry);
|
|
$listViewCount++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}*/
|
|
|
|
foreach ($entries as $entry) {
|
|
$recordId = $entry->getId();
|
|
$line = array();
|
|
$info = array();
|
|
|
|
if (in_array($this->moduleName, getInventoryModules())) {
|
|
$line[] = array(
|
|
'fieldName' => 'numbering',
|
|
'value' => html_entity_decode(getModuleSequenceNumber($this->moduleName, $recordId))
|
|
);
|
|
}
|
|
|
|
foreach ($headers as $header) {
|
|
$fieldDataType = $header->getFieldDataType();
|
|
$fieldName = $header->get('name');
|
|
|
|
$value = $entry->get($fieldName);
|
|
|
|
if (in_array($fieldDataType, ['email', 'url', 'reference'])) {
|
|
$value = trim(strip_tags($value));
|
|
}
|
|
|
|
if ('datetime' === $fieldDataType) {
|
|
$value = date('Y-m-d', strtotime($value));
|
|
}
|
|
|
|
$fieldLine = array(
|
|
'fieldName' => $fieldName,
|
|
'label' => vtranslate($header->get('label'), $this->moduleName),
|
|
'dataType' => $fieldDataType,
|
|
'value' => html_entity_decode($value)
|
|
);
|
|
|
|
if ($header->isNameField() || $this->isTableField($fieldName)) {
|
|
$line[] = $fieldLine;
|
|
} else {
|
|
$info[] = $fieldLine;
|
|
}
|
|
}
|
|
|
|
$headerFields = [];
|
|
|
|
foreach ($fieldModels as $fieldModel) {
|
|
if ($fieldModel->get('headerfield')) {
|
|
$value = html_entity_decode($entry->get($fieldModel->get('name')));
|
|
|
|
if (in_array($fieldModel->get('uitype'), [10, 13, 17])) {
|
|
$value = trim(strip_tags(html_entity_decode($fieldModel->getDisplayValue($value))));
|
|
}
|
|
|
|
$headerFields[] = [
|
|
'value' => strip_tags($value),
|
|
'name' => $fieldModel->get('name'),
|
|
'label' => vtranslate($fieldModel->get('label'), $this->moduleName)
|
|
];
|
|
}
|
|
}
|
|
|
|
if ((empty($recordIds) && empty($this->viewId)) || in_array($recordId, $recordIds)) {
|
|
if ('Calendar' === $this->moduleName) {
|
|
|
|
$isPermitted = false;
|
|
$recordModel = Vtiger_Record_Model::getInstanceById($recordId);
|
|
$recordData = $recordModel->getData();
|
|
|
|
if (!$this->userId || $recordData['assigned_user_id'] == $this->userId) {
|
|
$isPermitted = true;
|
|
}
|
|
|
|
if ($isPermitted) {
|
|
$this->setEntry($recordId, $line, $info, $headerFields);
|
|
}
|
|
} else {
|
|
if (in_array($this->moduleName, getInventoryModules())) {
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
$recordModel = Vtiger_Record_Model::getInstanceById($recordId);
|
|
$recordData = $recordModel->getData();
|
|
|
|
if ($currentUser) {
|
|
$statusFieldName = '';
|
|
|
|
switch ($this->moduleName) {
|
|
case 'Invoice':
|
|
$statusFieldName = 'invoicestatus';
|
|
|
|
break;
|
|
case 'SalesOrder':
|
|
$statusFieldName = 'sostatus';
|
|
|
|
break;
|
|
case 'PurchaseOrder':
|
|
$statusFieldName = 'postatus';
|
|
|
|
break;
|
|
case 'Quotes':
|
|
$statusFieldName = 'quotestage';
|
|
|
|
break;
|
|
}
|
|
|
|
$line[] = [
|
|
'fieldName' => 'totalPrice',
|
|
'status' => $recordData[$statusFieldName],
|
|
'value' => $recordData['hdnGrandTotal'],
|
|
'currencyDecimals' => $currentUser->get('no_of_currency_decimals'),
|
|
'currencySymbol' => html_entity_decode(getCurrencySymbolandCRate($recordData['currency_id'])['symbol']),
|
|
'decimalSeparator' => html_entity_decode($currentUser->get('currency_decimal_separator'), ENT_QUOTES),
|
|
'groupSeparator' => html_entity_decode($currentUser->get('currency_grouping_separator'), ENT_QUOTES),
|
|
'truncate' => $currentUser->get('truncate_trailing_zeros'),
|
|
];
|
|
}
|
|
}
|
|
|
|
$this->setEntry($recordId, $line, $info, $headerFields, getEntityName($this->moduleName, $recordId)[$recordId]);
|
|
}
|
|
}
|
|
}
|
|
|
|
$pagingModel->calculatePageRange($entries);
|
|
|
|
$this->range = $pagingModel->getRecordRange();
|
|
$this->totalCount = $listViewCount;
|
|
$this->pageLimit = $pagingModel->getPageLimit();
|
|
$this->pageCount = ceil((int)$this->totalCount / (int)$this->pageLimit);
|
|
|
|
if (0 == $this->pageCount) {
|
|
$this->pageCount = 1;
|
|
}
|
|
|
|
$allCustomViews = CustomView_Record_Model::getAllByGroup($this->moduleName);
|
|
$allViewNames = [];
|
|
|
|
foreach ($allCustomViews as $views) {
|
|
foreach ($views as $view) {
|
|
$allViewNames[$view->getId()] = vtranslate($view->get('viewname'), $this->moduleName);
|
|
}
|
|
}
|
|
|
|
$this->setFilters($allViewNames);
|
|
$this->setDefaultFilter([$defaultViewId => $allViewNames[$defaultViewId]]);
|
|
|
|
if ('Calendar' === $this->moduleName) {
|
|
$users = [];
|
|
$currentUser = Users_Record_Model::getCurrentUserModel();
|
|
|
|
if ($currentUser) {
|
|
$accessibleUsers = array_keys($currentUser->getAccessibleUsersForModule($this->moduleName));
|
|
|
|
$users[] = ['label' => vtranslate('LBL_ALL_USERS', $this->moduleName), 'value' => 'LBL_SELECT_OPTION'];
|
|
|
|
foreach (getAllUserName() as $id => $userName) {
|
|
if (in_array($id, $accessibleUsers)) {
|
|
$users[] = ['label' => vtranslate($userName, $this->moduleName), 'value' => "$id"];
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->setUsers($users);
|
|
|
|
$this->loadUpcomingActivities();
|
|
$this->loadOverdueActivities();
|
|
}
|
|
}
|
|
|
|
protected function getDefaultViewId()
|
|
{
|
|
global $adb, $current_user;
|
|
|
|
$defCVResult = $adb->pquery(
|
|
'select default_cvid from vtiger_user_module_preferences where userid = ? and tabid =?',
|
|
[$current_user->id, getTabid($this->moduleName)]
|
|
);
|
|
|
|
if (0 < $adb->num_rows($defCVResult)) {
|
|
$viewId = $adb->query_result($defCVResult, 0, 'default_cvid');
|
|
} else {
|
|
$viewId = '';
|
|
$query = 'select cvid from vtiger_customview where setdefault=1 and entitytype=?';
|
|
$cvResult = $adb->pquery($query, [$this->moduleName]);
|
|
|
|
if (0 < $adb->num_rows($cvResult)) {
|
|
$viewId = $adb->query_result($cvResult, 0, 'cvid');
|
|
}
|
|
}
|
|
|
|
$customView = new CustomView($this->moduleName);
|
|
|
|
if (!empty($viewId) || 'yes' !== $customView->isPermittedCustomView($viewId, '', $this->moduleName)) {
|
|
$query = "select cvid from vtiger_customview where viewname='All' and entitytype=?";
|
|
$cvResult = $adb->pquery($query, [$this->moduleName]);
|
|
$viewId = $adb->query_result($cvResult, 0, 'cvid');
|
|
}
|
|
|
|
return $viewId;
|
|
}
|
|
|
|
protected function getEntityNames()
|
|
{
|
|
$db = PearDatabase::getInstance();
|
|
$tabId = getTabid($this->moduleName);
|
|
$fields = [];
|
|
$entityFields = explode(',', getEntityField($this->moduleName)['fieldname']);
|
|
|
|
foreach ($entityFields as $field) {
|
|
$result = $db->pquery('
|
|
SELECT fieldname
|
|
FROM vtiger_field
|
|
WHERE tabid = ? AND (fieldname = ? OR columnname = ?)',
|
|
[$tabId, $field, $field]
|
|
);
|
|
|
|
$fields[] = $db->fetchByAssoc($result, 0)['fieldname'];
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
protected function loadUpcomingActivities()
|
|
{
|
|
$listViewModel = ITS4YouMobileApp_ListView_Model::getInstanceForPopup($this->moduleName);
|
|
|
|
$pagingModel = new Vtiger_Paging_Model();
|
|
$pagingModel->set('page', $this->pageNumber);
|
|
|
|
$queryGenerator = $listViewModel->get('query_generator');
|
|
|
|
$queryGenerator->addCondition('date_start', date('Y-m-d'), 'h');
|
|
$queryGenerator->addConditionGlue(QueryGenerator::$AND);
|
|
$queryGenerator->addCondition('date_start', date('Y-m-d', strtotime('+1 Month')), 'm');
|
|
$queryGenerator->addConditionGlue(QueryGenerator::$AND);
|
|
$queryGenerator->addCondition('taskstatus', 'Completed', 'n');
|
|
$queryGenerator->addConditionGlue(QueryGenerator::$AND);
|
|
$queryGenerator->addCondition('eventstatus', 'Held', 'n');
|
|
|
|
$listViewModel->set('orderby', 'date_start');
|
|
$listViewModel->set('sortorder', 'ASC');
|
|
|
|
if (!empty($this->searchParams) && !empty($this->searchParams[0]) && !empty($this->searchParams[1])) {
|
|
$listViewModel->set('search_key', $this->searchParams[0]);
|
|
$listViewModel->set('search_value', $this->searchParams[1]);
|
|
}
|
|
|
|
if (!empty($this->searchParamsAdvance)) {
|
|
$transformedSearchParams = Vtiger_Util_Helper::transferListSearchParamsToFilterCondition($this->searchParamsAdvance, $listViewModel->getModule());
|
|
$listViewModel->set('search_params', $transformedSearchParams);
|
|
}
|
|
|
|
if (!empty($this->filterParams)) {
|
|
foreach ($this->filterParams as $name => $value) {
|
|
$field = array(
|
|
'relFieldDep_fldid' => getFieldid(getTabid($this->moduleName), $name),
|
|
'relFieldDep_val' => $value,
|
|
);
|
|
|
|
if (!empty($this->searchParamsAdvance)) {
|
|
$field['relFieldDep_startGroup'] = 'AND';
|
|
}
|
|
|
|
$relFieldDependencies = array($field);
|
|
$listViewModel->set('relfielddependencies', $relFieldDependencies);
|
|
}
|
|
}
|
|
|
|
$headers = $listViewModel->getListViewHeaders();
|
|
|
|
$recordIds = [];
|
|
$upcomingActivities = [];
|
|
|
|
if (!empty($this->viewId)) {
|
|
$customView = ITS4YouMobileApp_Record_Model::getInstanceById($this->viewId);
|
|
$recordIds = $customView->getRecordIds();
|
|
}
|
|
|
|
$moduleModel = Vtiger_Module_Model::getInstance($this->moduleName);
|
|
$fieldModels = $moduleModel->getFields();
|
|
|
|
$entries = $listViewModel->getListViewEntries($pagingModel);
|
|
|
|
foreach ($entries as $entry) {
|
|
if (date('Y-m-d') === date('Y-m-d', strtotime($entry->get('date_start'))) && date('H:i:s') > $entry->get('time_end')) {
|
|
continue;
|
|
}
|
|
|
|
$recordId = $entry->getId();
|
|
$line = array();
|
|
$info = array();
|
|
|
|
foreach ($headers as $header) {
|
|
$fieldDataType = $header->getFieldDataType();
|
|
$fieldName = $header->get('name');
|
|
|
|
$value = $entry->get($fieldName);
|
|
|
|
if (in_array($fieldDataType, ['email', 'url', 'reference'])) {
|
|
$value = trim(strip_tags($value));
|
|
}
|
|
|
|
if ('datetime' === $fieldDataType) {
|
|
$value = date('Y-m-d', strtotime($value));
|
|
}
|
|
|
|
$fieldLine = array(
|
|
'fieldName' => $fieldName,
|
|
'label' => vtranslate($header->get('label'), $this->moduleName),
|
|
'dataType' => $fieldDataType,
|
|
'value' => html_entity_decode($value),
|
|
'fieldValue' => $entry->get($fieldName),
|
|
);
|
|
|
|
if ($header->isNameField() || $this->isTableField($fieldName)) {
|
|
$line[] = $fieldLine;
|
|
} else {
|
|
$info[] = $fieldLine;
|
|
}
|
|
}
|
|
|
|
$headerFields = [];
|
|
|
|
foreach ($fieldModels as $fieldModel) {
|
|
if ($fieldModel->get('headerfield')) {
|
|
$value = $entry->get($fieldModel->get('name'));
|
|
|
|
if (in_array($fieldModel->get('uitype'), [10, 13, 17])) {
|
|
$value = trim(strip_tags(html_entity_decode($fieldModel->getDisplayValue($value))));
|
|
}
|
|
|
|
$headerFields[] = [
|
|
'value' => strip_tags($value),
|
|
'name' => $fieldModel->get('name'),
|
|
'label' => vtranslate($fieldModel->get('label'), $this->moduleName)
|
|
];
|
|
}
|
|
}
|
|
|
|
if (empty($recordIds) || in_array($recordId, $recordIds)) {
|
|
$isPermitted = false;
|
|
$recordModel = Vtiger_Record_Model::getInstanceById($recordId);
|
|
$recordData = $recordModel->getData();
|
|
|
|
if (!$this->userId || $recordData['assigned_user_id'] == $this->userId) {
|
|
$isPermitted = true;
|
|
}
|
|
|
|
if ($isPermitted) {
|
|
$upcomingActivities[] = [
|
|
'id' => $recordId,
|
|
'fields' => $line,
|
|
'info' => $info,
|
|
'headerFields' => $headerFields,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->setUpcomingActivities($upcomingActivities);
|
|
}
|
|
|
|
protected function loadOverdueActivities()
|
|
{
|
|
$listViewModel = ITS4YouMobileApp_ListView_Model::getInstanceForPopup($this->moduleName);
|
|
|
|
$pagingModel = new Vtiger_Paging_Model();
|
|
$pagingModel->set('page', $this->pageNumber);
|
|
|
|
$queryGenerator = $listViewModel->get('query_generator');
|
|
|
|
$queryGenerator->addCondition('due_date', date('Y-m-d'), 'm');
|
|
$queryGenerator->addConditionGlue(QueryGenerator::$AND);
|
|
$queryGenerator->addCondition('taskstatus', 'Completed', 'n');
|
|
$queryGenerator->addConditionGlue(QueryGenerator::$AND);
|
|
$queryGenerator->addCondition('eventstatus', 'Held', 'n');
|
|
|
|
if (!empty($this->searchParams) && !empty($this->searchParams[0]) && !empty($this->searchParams[1])) {
|
|
$listViewModel->set('search_key', $this->searchParams[0]);
|
|
$listViewModel->set('search_value', $this->searchParams[1]);
|
|
}
|
|
|
|
if (!empty($this->searchParamsAdvance)) {
|
|
$transformedSearchParams = Vtiger_Util_Helper::transferListSearchParamsToFilterCondition($this->searchParamsAdvance, $listViewModel->getModule());
|
|
$listViewModel->set('search_params', $transformedSearchParams);
|
|
}
|
|
|
|
if (!empty($this->filterParams)) {
|
|
foreach ($this->filterParams as $name => $value) {
|
|
$field = array(
|
|
'relFieldDep_fldid' => getFieldid(getTabid($this->moduleName), $name),
|
|
'relFieldDep_val' => $value,
|
|
);
|
|
|
|
if (!empty($this->searchParamsAdvance)) {
|
|
$field['relFieldDep_startGroup'] = 'AND';
|
|
}
|
|
|
|
$relFieldDependencies = array($field);
|
|
$listViewModel->set('relfielddependencies', $relFieldDependencies);
|
|
}
|
|
}
|
|
|
|
$headers = $listViewModel->getListViewHeaders();
|
|
|
|
$recordIds = [];
|
|
$overdueActivities = [];
|
|
|
|
if (!empty($this->viewId)) {
|
|
$customView = ITS4YouMobileApp_Record_Model::getInstanceById($this->viewId);
|
|
$recordIds = $customView->getRecordIds();
|
|
}
|
|
|
|
$moduleModel = Vtiger_Module_Model::getInstance($this->moduleName);
|
|
$fieldModels = $moduleModel->getFields();
|
|
|
|
$entries = $listViewModel->getListViewEntries($pagingModel);
|
|
|
|
foreach ($entries as $entry) {
|
|
if (date('Y-m-d') === date('Y-m-d', strtotime($entry->get('due_date'))) && date('H:i:s') < $entry->get('time_end')) {
|
|
continue;
|
|
}
|
|
|
|
$recordId = $entry->getId();
|
|
$line = array();
|
|
$info = array();
|
|
|
|
foreach ($headers as $header) {
|
|
$fieldDataType = $header->getFieldDataType();
|
|
$fieldName = $header->get('name');
|
|
|
|
$value = $entry->get($fieldName);
|
|
|
|
if (in_array($fieldDataType, ['email', 'url', 'reference'])) {
|
|
$value = trim(strip_tags($value));
|
|
}
|
|
|
|
if ('datetime' === $fieldDataType) {
|
|
$value = date('Y-m-d', strtotime($value));
|
|
}
|
|
|
|
$fieldLine = array(
|
|
'fieldName' => $fieldName,
|
|
'label' => vtranslate($header->get('label'), $this->moduleName),
|
|
'dataType' => $fieldDataType,
|
|
'value' => html_entity_decode($value)
|
|
);
|
|
|
|
if ($header->isNameField() || $this->isTableField($fieldName)) {
|
|
$line[] = $fieldLine;
|
|
} else {
|
|
$info[] = $fieldLine;
|
|
}
|
|
}
|
|
|
|
$headerFields = [];
|
|
|
|
foreach ($fieldModels as $fieldModel) {
|
|
if ($fieldModel->get('headerfield')) {
|
|
$value = $entry->get($fieldModel->get('name'));
|
|
|
|
if (in_array($fieldModel->get('uitype'), [10, 13, 17])) {
|
|
$value = trim(strip_tags(html_entity_decode($fieldModel->getDisplayValue($value))));
|
|
}
|
|
|
|
$headerFields[] = [
|
|
'value' => strip_tags($value),
|
|
'name' => $fieldModel->get('name'),
|
|
'label' => vtranslate($fieldModel->get('label'), $this->moduleName)
|
|
];
|
|
}
|
|
}
|
|
|
|
if (empty($recordIds) || in_array($recordId, $recordIds)) {
|
|
$isPermitted = false;
|
|
$recordModel = Vtiger_Record_Model::getInstanceById($recordId);
|
|
$recordData = $recordModel->getData();
|
|
|
|
if (!$this->userId || $recordData['assigned_user_id'] == $this->userId) {
|
|
$isPermitted = true;
|
|
}
|
|
|
|
if ($isPermitted) {
|
|
$overdueActivities[] = [
|
|
'id' => $recordId,
|
|
'fields' => $line,
|
|
'info' => $info,
|
|
'headerFields' => $headerFields
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->setOverdueActivities($overdueActivities);
|
|
}
|
|
|
|
public function loadLicenseUrl($license)
|
|
{
|
|
$this->generateLicenseUrl($license);
|
|
}
|
|
|
|
protected function generateLicenseUrl($license)
|
|
{
|
|
$key = '3874157';
|
|
$length = rand(6, 12);
|
|
$keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
|
$pieces = [];
|
|
$max = mb_strlen($keyspace, '8bit') - 1;
|
|
|
|
for ($i = 0; $i < $length; ++$i) {
|
|
$pieces [] = $keyspace[rand(0, $max)];
|
|
}
|
|
|
|
$random = implode('', $pieces);
|
|
$string = $random . ":" . $license;
|
|
|
|
$result = '';
|
|
|
|
for ($i = 0, $k = strlen($string); $i < $k; $i++) {
|
|
$char = substr($string, $i, 1);
|
|
$keychar = substr($key, ($i % strlen($key)) - 1, 1);
|
|
$char = chr(ord($char) + ord($keychar));
|
|
$result .= $char;
|
|
}
|
|
|
|
$result2 = base64_encode($result);
|
|
$this->licenseUrl = 'https://it-solutions4you.com/buy-license/mobile-app?license=' . rawurlencode($result2);
|
|
}
|
|
}
|