Example #1
0
 function showTaxes(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $record = $request->get('record');
     $recordModule = $request->get('recordModule');
     $currency = $request->get('currency');
     $sourceRecord = $request->get('sourceRecord');
     $taxType = $request->get('taxType');
     $totalPrice = $request->get('totalPrice');
     $inventoryModel = Vtiger_Inventory_Model::getInstance($moduleName);
     $accountTaxs = $inventoryModel->getAccountTax($moduleName, $sourceRecord);
     $config = $inventoryModel->getTaxesConfig();
     $viewer = $this->getViewer($request);
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('RECORD', $record);
     $viewer->assign('RECORD_MODULE', $recordModule);
     $viewer->assign('GLOBAL_TAXS', $inventoryModel->getGlobalTaxs());
     $viewer->assign('CURRENCY_SYMBOL', Vtiger_Functions::getCurrencySymbolandRate($currency)['symbol']);
     $viewer->assign('TOTAL_PRICE', $totalPrice);
     $viewer->assign('CONFIG', $config);
     $viewer->assign('TAX_TYPE', $taxType);
     $viewer->assign('TAX_FIELD', Vtiger_InventoryField_Model::getTaxField($recordModule));
     $viewer->assign('AGGREGATION_TYPE', $config['aggregation']);
     $viewer->assign('AGGREGATION_INPUT_TYPE', $config['aggregation'] == 0 ? 'radio' : 'checkbox');
     $viewer->assign('GROUP_TAXS', $accountTaxs['taxs']);
     $viewer->assign('ACCOUNT_NAME', $accountTaxs['name']);
     echo $viewer->view('InventoryTaxes.tpl', $moduleName, true);
 }
Example #2
0
 function getListFiledOfRelatedModule($moduleName)
 {
     $db = PearDatabase::getInstance();
     $tabid = getTabid($moduleName);
     $sourceModule = $moduleName;
     $sql = "select vtiger_field.fieldid, fieldlabel, uitype, vtiger_fieldmodulerel.relmodule from vtiger_field \n\t\t\t\tleft JOIN vtiger_fieldmodulerel ON vtiger_fieldmodulerel.fieldid = vtiger_field.fieldid where tabid = ? AND (uitype = '10' OR uitype = '59' OR uitype = '53' OR uitype = '51')";
     $resultModuleList = $db->pquery($sql, array($tabid), true);
     $moduleList = array();
     for ($i = 0; $i < $db->num_rows($resultModuleList); $i++) {
         $uitype = $db->query_result($resultModuleList, $i, 'uitype');
         $fieldid = $db->query_result($resultModuleList, $i, 'fieldid');
         $fieldlabel = $db->query_result($resultModuleList, $i, 'fieldlabel');
         if ($uitype == 10) {
             $moduleList[] = array(Vtiger_Functions::getModuleId($db->query_result($resultModuleList, $i, 'relmodule')), $fieldlabel, $fieldid);
         } elseif ($uitype == 51) {
             $moduleList[] = array(Vtiger_Functions::getModuleId('Accounts'), $fieldlabel, $fieldid);
         } elseif ($uitype == 59) {
             $moduleList[] = array(Vtiger_Functions::getModuleId('Products'), $fieldlabel, $fieldid);
         } elseif ($uitype == 53) {
             $moduleList[] = array(Vtiger_Functions::getModuleId('Users'), $fieldlabel, $fieldid);
         }
     }
     $output = array();
     for ($i = 0; $i < count($moduleList); $i++) {
         $moduleInfoSql = "SELECT * FROM vtiger_tab WHERE tabid = ?";
         $moduleInfoResult = $db->pquery($moduleInfoSql, array($moduleList[$i][0]), true);
         $moduleName = $db->query_result($moduleInfoResult, 0, 'name');
         $moduleTrLabal = vtranslate($moduleList[$i][1], $sourceModule);
         $output[$moduleTrLabal] = array();
         $output[$moduleTrLabal] = $this->getListFiledOfModule($moduleName, $moduleList[$i][2]);
     }
     return $output;
 }
Example #3
0
 public function getSelectableDashboard()
 {
     global $log;
     $log->debug("Entering Settings_WidgetsManagement_Module_Model::getSelectableDashboard() method ...");
     $db = PearDatabase::getInstance();
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $sql = 'SELECT * FROM vtiger_links WHERE linktype = ?';
     $params = array('DASHBOARDWIDGET');
     $result = $db->pquery($sql, $params);
     $widgets = array();
     for ($i = 0; $i < $db->num_rows($result); $i++) {
         $row = $db->query_result_rowdata($result, $i);
         $moduleName = Vtiger_Functions::getModuleName($row['tabid']);
         if ($moduleName != 'Home' && ($row['linklabel'] == 'Mini List' || $row['linklabel'] == 'Notebook')) {
             continue;
         }
         if ($row['linklabel'] == 'Tag Cloud') {
             $isTagCloudExists = getTagCloudView($currentUser->getId());
             if ($isTagCloudExists == 'false') {
                 continue;
             }
         }
         $moduleName = Vtiger_Functions::getModuleName($row['tabid']);
         $widgets[$moduleName][] = Vtiger_Widget_Model::getInstanceFromValues($row);
     }
     $log->debug("Exiting Settings_WidgetsManagement_Module_Model::getSelectableDashboard() method ...");
     return $widgets;
 }
Example #4
0
 protected function getKeyMetricsWithCount()
 {
     global $log;
     $log->debug("Entering ./dashboards/KeyMetrics.php::getKeyMetricsWithCount");
     global $current_user, $adb;
     $current_user = Users_Record_Model::getCurrentUserModel();
     require_once 'modules/CustomView/ListViewTop.php';
     $metriclists = getMetricList();
     foreach ($metriclists as $key => $metriclist) {
         $metricresult = NULL;
         $queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
         $queryGenerator->initForCustomViewById($metriclist['id']);
         if ($metriclist['module'] == "Calendar") {
             // For calendar we need to eliminate emails or else it will break in status empty condition
             $queryGenerator->addCondition('activitytype', "Emails", 'n', QueryGenerator::$AND);
         }
         $metricsql = $queryGenerator->getQuery();
         $metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
         if ($metricresult) {
             $rowcount = $adb->fetch_array($metricresult);
             $metriclists[$key]['count'] = $rowcount['count'];
         }
     }
     return $metriclists;
 }
Example #5
0
 public function edit(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $qualifiedModuleName = $request->getModule(false);
     $wid = $request->get('id');
     $moduleModel = Settings_Widgets_Module_Model::getInstance($qualifiedModuleName);
     $WidgetInfo = $moduleModel->getWidgetInfo($wid);
     $RelatedModule = $moduleModel->getRelatedModule($WidgetInfo['tabid']);
     $type = $WidgetInfo['type'];
     $viewer = $this->getViewer($request);
     $viewer->assign('SOURCE', $WidgetInfo['tabid']);
     $viewer->assign('SOURCEMODULE', Vtiger_Functions::getModuleName($WidgetInfo['tabid']));
     $viewer->assign('WID', $wid);
     $viewer->assign('WIDGETINFO', $WidgetInfo);
     $viewer->assign('TYPE', $type);
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('MODULE_MODEL', $moduleModel);
     $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
     $viewer->assign('RELATEDMODULES', $RelatedModule);
     $widgetName = 'Vtiger_' . $type . '_Widget';
     if (class_exists($widgetName)) {
         $widgetInstance = new $widgetName();
         $tplName = $widgetInstance->getConfigTplName();
         $viewer->view("widgets/{$tplName}.tpl", 'Vtiger');
     }
 }
Example #6
0
 function process(Vtiger_Request $request)
 {
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     $baseUserId = $currentUserModel->getId();
     $userId = $request->get('id');
     $user = new Users();
     $currentUser = $user->retrieveCurrentUserInfoFromFile($userId);
     $name = $currentUserModel->getName();
     $userName = $currentUser->column_fields['user_name'];
     Vtiger_Session::set('AUTHUSERID', $userId);
     Vtiger_Session::set('authenticated_user_id', $userId);
     Vtiger_Session::set('user_name', $userName);
     Vtiger_Session::set('full_user_name', $name);
     $status = 'Switched';
     if (Vtiger_Session::get('baseUserId') == '') {
         Vtiger_Session::set('baseUserId', $baseUserId);
         $status = 'Signed in';
     } elseif ($userId == Vtiger_Session::get('baseUserId')) {
         $baseUserId = $userId;
         Vtiger_Session::set('baseUserId', '');
         $status = 'Signed out';
     } else {
         $baseUserId = Vtiger_Session::get('baseUserId');
     }
     $dbLog = PearDatabase::getInstance('log');
     $dbLog->insert('l_yf_switch_users', ['baseid' => $baseUserId, 'destid' => $userId, 'busername' => $currentUserModel->getName(), 'dusername' => $name, 'date' => date('Y-m-d H:i:s'), 'ip' => Vtiger_Functions::getRemoteIP(), 'agent' => $_SERVER['HTTP_USER_AGENT'], 'status' => $status]);
     header('Location: index.php');
 }
Example #7
0
 /**
  * Getting value to display
  * @param type $value
  * @return type
  */
 public function getDisplayValue($value)
 {
     if ($value != 0) {
         return Vtiger_Functions::getCRMRecordLabel($value);
     }
     return '';
 }
Example #8
0
 public function process(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $qualifiedModuleName = $request->getModule(false);
     $source = $request->get('source');
     $sourceModule = $request->get('sourceModule');
     if ($sourceModule != '') {
         $source = Vtiger_Functions::getModuleId($sourceModule);
     }
     if ($source == '') {
         $source = 6;
     }
     $moduleModel = Settings_Widgets_Module_Model::getInstance($qualifiedModuleName);
     $RelatedModule = $moduleModel->getRelatedModule($source);
     $viewer = $this->getViewer($request);
     $viewer->assign('MODULE_MODEL', $moduleModel);
     $viewer->assign('SOURCE', $source);
     $viewer->assign('SOURCEMODULE', Vtiger_Functions::getModuleName($source));
     $viewer->assign('WIDGETS', $moduleModel->getWidgets($source));
     $viewer->assign('RELATEDMODULES', $RelatedModule);
     $viewer->assign('FILTERS', json_encode($moduleModel->getFiletrs($RelatedModule)));
     $viewer->assign('CHECKBOXS', json_encode($moduleModel->getCheckboxs($RelatedModule)));
     //$viewer->assign('EXCLUDEDTYPES', $moduleModel->excludedTypes($source) );
     $viewer->assign('QUALIFIED_MODULE', $qualifiedModuleName);
     $viewer->assign('MODULE', $moduleName);
     $viewer->view('Index.tpl', $qualifiedModuleName);
 }
Example #9
0
 function process(Vtiger_Request $request)
 {
     $viewer = $this->getViewer($request);
     $moduleName = $this->getModule($request);
     $template = $request->get('template');
     $srcField = $request->get('src_field');
     $srcRecord = $request->get('src_record');
     if (!empty($template)) {
         $recordModel = Settings_TreesManager_Record_Model::getInstanceById($template);
     } else {
         Vtiger_Functions::throwNewException(vtranslate('ERR_TREE_NOT_FOUND', $moduleName));
     }
     if (!$recordModel) {
         Vtiger_Functions::throwNewException(vtranslate('ERR_TREE_NOT_FOUND', $moduleName));
     }
     $tree = $recordModel->getTree();
     $viewer->assign('TREE', Zend_Json::encode($tree));
     $viewer->assign('SRC_RECORD', $srcRecord);
     $viewer->assign('SRC_FIELD', $srcField);
     $viewer->assign('TEMPLATE', $template);
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('TRIGGER_EVENT_NAME', $request->get('triggerEventName'));
     $viewer->assign('USER_MODEL', Users_Record_Model::getCurrentUserModel());
     $viewer->view('TreePopup.tpl', $moduleName);
 }
 public function showTree(Vtiger_Request $request)
 {
     $moduleName = $request->getModule();
     $sourceModule = $request->get('selectedModule');
     $viewer = $this->getViewer($request);
     $this->template = $this->getTemplate();
     if ($this->template) {
         $recordModel = Settings_TreesManager_Record_Model::getInstanceById($this->template);
     } else {
         Vtiger_Functions::throwNewException(vtranslate('ERR_TREE_NOT_FOUND', $moduleName));
     }
     if (!$recordModel) {
         Vtiger_Functions::throwNewException(vtranslate('ERR_TREE_NOT_FOUND', $moduleName));
     }
     if (!in_array($sourceModule, $this->modules)) {
         Vtiger_Functions::throwNewException(vtranslate('ERR_MODULE_NOT_FOUND', $moduleName));
     }
     $tree = $this->getCategory();
     $treeWithItems = $this->getRecords();
     $tree = array_merge($tree, $treeWithItems);
     $viewer->assign('TREE', Zend_Json::encode($tree));
     $viewer->assign('MODULES', $this->modules);
     $viewer->assign('MODULE', $moduleName);
     $viewer->assign('SELECTED_MODULE_NAME', $sourceModule);
     $viewer->assign('CUSTOM_VIEWS', CustomView_Record_Model::getAllByGroup($moduleName));
     $viewer->view('AccountsListTree.tpl', $moduleName);
 }
Example #11
0
 protected function getKeyMetricsWithCount()
 {
     global $current_user, $adb;
     $current_user = Users_Record_Model::getCurrentUserModel();
     require_once 'modules/CustomView/ListViewTop.php';
     $metriclists = getMetricList();
     foreach ($metriclists as $key => $metriclist) {
         $metricresult = NULL;
         if ($metriclist['module'] == "Calendar") {
             $listquery = getListQuery($metriclist['module']);
             $oCustomView = new CustomView($metriclist['module']);
             $metricsql = $oCustomView->getModifiedCvListQuery($metriclist['id'], $listquery, $metriclist['module']);
             $metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
         } else {
             $queryGenerator = new QueryGenerator($metriclist['module'], $current_user);
             $queryGenerator->initForCustomViewById($metriclist['id']);
             $metricsql = $queryGenerator->getQuery();
             $metricresult = $adb->query(Vtiger_Functions::mkCountQuery($metricsql));
         }
         if ($metricresult) {
             $rowcount = $adb->fetch_array($metricresult);
             $metriclists[$key]['count'] = $rowcount['count'];
         }
     }
     return $metriclists;
 }
Example #12
0
	/**
	 * Function to get the Display Value, for the current field type with given DB Insert Value
	 * @param <Object> $value
	 * @return <Object>
	 */
	public function getDisplayValue($values)
	{
		if ($values == '')
			return;

		foreach (Vtiger_Functions::getArrayFromValue($values) as $value) {
			if (Vtiger_Owner_UIType::getOwnerType($value) === 'User') {
				$userModel = Users_Record_Model::getCleanInstance('Users');
				$userModel->set('id', $value);
				$detailViewUrl = $userModel->getDetailViewUrl();
				$currentUser = Users_Record_Model::getCurrentUserModel();
				if ($currentUser->isAdminUser()) {
					$displayvalue[] = '<a href=' . $detailViewUrl . '>' . rtrim(getOwnerName($value)) . '</a>';
				} else {
					$displayvalue[] = rtrim(getOwnerName($value));
				}
			} else {
				$currentUser = Users_Record_Model::getCurrentUserModel();
				if ($currentUser->isAdminUser()) {
					$recordModel = new Settings_Groups_Record_Model();
					$recordModel->set('groupid', $value);
					$detailViewUrl = $recordModel->getDetailViewUrl();
					$displayvalue[] = '<a href=' . $detailViewUrl . '>' . rtrim(getOwnerName($value)) . '</a>';
				} else {
					$displayvalue[] = rtrim(getOwnerName($value));
				}
			}
		}
		$displayvalue = implode(', ', $displayvalue);
		return $displayvalue;
	}
Example #13
0
 function addRelation($request)
 {
     $sourceModule = $request->getModule();
     $sourceRecordId = $request->get('src_record');
     $relatedModule = $request->get('related_module');
     if (is_numeric($relatedModule)) {
         $relatedModule = Vtiger_Functions::getModuleName($relatedModule);
     }
     $relatedRecordIdList = $request->get('related_record_list');
     $sourceModuleModel = Vtiger_Module_Model::getInstance($sourceModule);
     $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule);
     $relationModel = Vtiger_Relation_Model::getInstance($sourceModuleModel, $relatedModuleModel);
     foreach ($relatedRecordIdList as $relatedRecordId) {
         $relationModel->addRelation($sourceRecordId, $relatedRecordId, $listPrice);
         if ($relatedModule == 'PriceBooks') {
             $recordModel = Vtiger_Record_Model::getInstanceById($relatedRecordId);
             if ($sourceRecordId && ($sourceModule === 'Products' || $sourceModule === 'Services')) {
                 $parentRecordModel = Vtiger_Record_Model::getInstanceById($sourceRecordId, $sourceModule);
                 $recordModel->updateListPrice($sourceRecordId, $parentRecordModel->get('unit_price'));
             }
         }
     }
     $response = new Vtiger_Response();
     $response->setResult(true);
     $response->emit();
 }
	public function process(Vtiger_Request $request)
	{
		$qualifiedModuleName = $request->getModule(false);
		$moduleModel = Settings_Vtiger_CompanyDetails_Model::getInstance();
		$status = false;

		if ($request->get('organizationname')) {
			$saveLogo = $status = true;
			if (!empty($_FILES['logo']['name'])) {
				$logoDetails = $_FILES['logo'];
				$fileType = explode('/', $logoDetails['type']);
				$fileType = $fileType[1];

				if (!$logoDetails['size'] || !in_array($fileType, Settings_Vtiger_CompanyDetails_Model::$logoSupportedFormats)) {
					$saveLogo = false;
				}

				//mime type check 
				$mimeType = Vtiger_Functions::getMimeContentType($logoDetails['tmp_name']);
				$mimeTypeContents = explode('/', $mimeType);
				if (!$logoDetails['size'] || $mimeTypeContents[0] != 'image' || !in_array($mimeTypeContents[1], Settings_Vtiger_CompanyDetails_Model::$logoSupportedFormats)) {
					$saveLogo = false;
				}

				// Check for php code injection
				$imageContents = file_get_contents($_FILES["logo"]["tmp_name"]);
				if (preg_match('/(<\?php?(.*?))/i', $imageContents) == 1) {
					$saveLogo = false;
				}
				if ($saveLogo) {
					$moduleModel->saveLogo();
				}
			} else {
				$saveLogo = true;
			}
			$fields = $moduleModel->getFields();
			foreach ($fields as $fieldName => $fieldType) {
				$fieldValue = $request->get($fieldName);
				if ($fieldName === 'logoname') {
					if (!empty($logoDetails['name'])) {
						$fieldValue = ltrim(basename(" " . $logoDetails['name']));
					} else {
						$fieldValue = $moduleModel->get($fieldName);
					}
				}
				$moduleModel->set($fieldName, $fieldValue);
			}
			$moduleModel->save();
		}

		$reloadUrl = $moduleModel->getIndexViewUrl();
		if ($saveLogo && $status) {
			
		} else if (!$saveLogo) {
			$reloadUrl .= '&error=LBL_INVALID_IMAGE';
		} else {
			$reloadUrl = $moduleModel->getEditViewUrl() . '&error=LBL_FIELDS_INFO_IS_EMPTY';
		}
		header('Location: ' . $reloadUrl);
	}
Example #15
0
 public function getRelatedSummary($query)
 {
     $db = PearDatabase::getInstance();
     $relationQuery = preg_replace("/[ \t\n\r]+/", " ", $query);
     $position = stripos($relationQuery, ' from ');
     if ($position) {
         $split = explode(' FROM ', $relationQuery);
         $mainQuery = '';
         for ($i = 1; $i < count($split); $i++) {
             $mainQuery = $mainQuery . ' FROM ' . $split[$i];
         }
     }
     // Calculate total working time
     $result = $db->query('SELECT SUM(vtiger_osstimecontrol.sum_time) AS sumtime' . $mainQuery);
     $totalTime = $db->getSingleValue($result);
     // Calculate total working time divided into users
     $result = $db->query('SELECT SUM(vtiger_osstimecontrol.sum_time) AS sumtime, vtiger_crmentity.smownerid' . $mainQuery . ' GROUP BY vtiger_crmentity.smownerid');
     $userTime = [];
     $count = 1;
     while ($row = $db->fetch_array($result)) {
         $smownerid = Vtiger_Functions::getOwnerRecordLabel($row['smownerid']);
         $userTime[] = ['name' => [$count, $smownerid], 'initial' => [$count, Vtiger_Functions::getInitials($smownerid)], 'data' => [$count, $row['sumtime']]];
         $count++;
     }
     return ['totalTime' => $totalTime, 'userTime' => $userTime];
 }
Example #16
0
 public function process(Vtiger_Request $request)
 {
     $adb = PearDatabase::getInstance();
     $metod = $request->get('metod');
     $params = $request->get('params');
     $params['folder'] = urldecode($params['folder']);
     $return = false;
     if (Vtiger_Functions::getModuleId('OSSMailView') && Vtiger_Functions::getModuleId('OSSMailScanner')) {
         $return = 0;
         $account = OSSMail_Record_Model::get_account_detail_by_name($params['username']);
         $result = $adb->pquery("SELECT ossmailviewid FROM vtiger_ossmailview WHERE id = ? AND mbox = ? AND rc_user = ?", array($params['uid'], $params['folder'], $account[0]['user_id']), true);
         if ($adb->num_rows($result) > 0) {
             $return = $adb->query_result($result, 0, 'ossmailviewid');
         } else {
             $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
             $params['actions'] = '0_created_Email';
             $mail_Scan_mail = $scannerModel->manualScanMail($params);
             if ($mail_Scan_mail['0_created_Email']) {
                 $return = $mail_Scan_mail['0_created_Email']['created_Email'];
             }
         }
     }
     $response = new Vtiger_Response();
     $response->setResult($return);
     $response->emit();
 }
 public function process($instance)
 {
     $log = vglobal('log');
     $log->debug("Entering SumTimeProjectTask::process() method ...");
     $sum_time = Vtiger_Functions::decimalTimeFormat($instance->get('sum_time_pt'));
     $log->debug("Exiting SumTimeProjectTask::process() method ...");
     return $sum_time['short'];
 }
Example #18
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $moduleName = $module->getName();
     $parentModuleName = $module->getParentName();
     $qualifiedModuleName = $moduleName;
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $qualifiedModuleName;
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listQuery = $this->getBasicListQuery();
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy) && $orderBy === 'smownerid') {
         $fieldModel = Vtiger_Field_Model::getInstance('assigned_user_id', $moduleModel);
         if ($fieldModel->getFieldDataType() == 'owner') {
             $orderBy = 'COALESCE(CONCAT(vtiger_users.first_name,vtiger_users.last_name),vtiger_groups.groupname)';
         }
     }
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $tabId = Vtiger_Functions::getModuleId($sourceModule);
         $listQuery .= " WHERE `module` = '{$tabId}' ";
     }
     if ($module->isPagingSupported()) {
         $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
         $listQuery .= " LIMIT {$startIndex}, {$pageLimit}";
     }
     $listResult = $db->pquery($listQuery, array());
     $noOfRecords = $db->num_rows($listResult);
     $listViewRecordModels = array();
     for ($i = 0; $i < $noOfRecords; ++$i) {
         $row = $db->query_result_rowdata($listResult, $i);
         $record = new $recordModelClass();
         $record->setData($row);
         $recordModule = Vtiger_Functions::getModuleName($row['module']);
         $record->set('module', vtranslate($recordModule, $recordModule));
         if (method_exists($record, 'getModule') && method_exists($record, 'setModule')) {
             $moduleModel = Settings_Vtiger_Module_Model::getInstance($qualifiedModuleName);
             $record->setModule($moduleModel);
         }
         $listViewRecordModels[$record->getId()] = $record;
     }
     if ($module->isPagingSupported()) {
         $pagingModel->calculatePageRange($listViewRecordModels);
         $nextPageResult = $db->pquery($nextListQuery, array());
         $nextPageNumRows = $db->num_rows($nextPageResult);
         if ($nextPageNumRows <= 0) {
             $pagingModel->set('nextPageExists', false);
         }
     }
     return $listViewRecordModels;
 }
Example #19
0
 public function getRelatedModuleRecordIds(Vtiger_Request $request, $recordIds = [])
 {
     $db = PearDatabase::getInstance();
     $basicModule = $request->getModule();
     $relatedModules = $request->get('related_modules');
     $parentModuleModel = Vtiger_Module_Model::getInstance($basicModule);
     $relatedIds = [];
     if (!empty($relatedModules)) {
         foreach ($relatedModules as $relModData) {
             $relModData = explode('::', $relModData);
             $relatedModule = $relModData[0];
             $type = $relModData[1];
             switch ($type) {
                 case 0:
                     $field = $relModData[2];
                     foreach ($recordIds as $recordId) {
                         $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $basicModule);
                         if ($recordModel->get($field) != 0 && Vtiger_Functions::getCRMRecordType($recordModel->get($field)) == $relatedModule) {
                             $relatedIds[] = $recordModel->get($field);
                         }
                     }
                     break;
                 case 1:
                     $relatedModuleModel = Vtiger_Module_Model::getInstance($relatedModule);
                     $instance = CRMEntity::getInstance($relatedModule);
                     $relationModel = Vtiger_Relation_Model::getInstance($parentModuleModel, $relatedModuleModel);
                     $fieldModel = $relationModel->getRelationField();
                     $tablename = $fieldModel->get('table');
                     $tabIndex = $instance->table_index;
                     $relIndex = $this->getRelatedFieldName($relatedModule, $basicModule);
                     if (!$relIndex) {
                         break;
                     }
                     $sql = "SELECT vtiger_crmentity.crmid FROM vtiger_crmentity INNER JOIN {$tablename} ON {$tablename}.{$tabIndex} = vtiger_crmentity.crmid\n\t\t\t\t\t\tWHERE {$tablename}.{$relIndex} IN (" . $db->generateQuestionMarks($recordIds) . ")";
                     $result = $db->pquery($sql, $recordIds);
                     while ($crmid = $db->getSingleValue($result)) {
                         $relatedIds[] = $crmid;
                     }
                     break;
                 case 2:
                     foreach ($recordIds as $recordId) {
                         $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $basicModule);
                         $relationListView = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModule);
                         $query = $relationListView->getRelationQuery();
                         $queryEx = explode('FROM', $query, 2);
                         $query = 'SELECT DISTINCT vtiger_crmentity.crmid FROM' . $queryEx[1];
                         $result = $db->query($query);
                         while ($crmid = $db->getSingleValue($result)) {
                             $relatedIds[] = $crmid;
                         }
                     }
                     break;
             }
             $relatedIds = array_unique($relatedIds);
         }
     }
     return $relatedIds;
 }
Example #20
0
 public function __construct($message = null, $code = 0)
 {
     parent::__construct($message, $code);
     Vtiger_Session::init();
     $request = new Vtiger_Request($_REQUEST);
     $dbLog = PearDatabase::getInstance('log');
     $userName = Vtiger_Session::get('full_user_name');
     $dbLog->insert('o_yf_access_for_api', ['username' => empty($userName) ? '-' : $userName, 'date' => date('Y-m-d H:i:s'), 'ip' => Vtiger_Functions::getRemoteIP(), 'url' => Vtiger_Functions::getBrowserInfo()->url, 'agent' => $_SERVER['HTTP_USER_AGENT'], 'request' => json_encode($_REQUEST)]);
 }
Example #21
0
 /**
  * Function to get the Display Value, for the current field type with given DB Insert Value
  * @param <Object> $value
  * @return <Object>
  */
 public function getDisplayValue($value)
 {
     if ($this->get('field')->getFieldName() == 'sum_time') {
         $return = Vtiger_Functions::decimalTimeFormat($value);
         return $return['short'];
     } else {
         return decimalFormat($value);
     }
 }
Example #22
0
 function process(Vtiger_Request $request)
 {
     $username = $request->get('username');
     $password = $request->get('password');
     if ($request->get('mode') == 'install') {
         error_reporting(0);
         $dirPath = 'install';
         foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirPath, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $path) {
             $path->isDir() ? rmdir($path->getPathname()) : unlink($path->getPathname());
         }
         rmdir($dirPath);
     }
     $checkBlocked = Settings_BruteForce_Module_Model::checkBlocked();
     $bruteForceSettings = Settings_BruteForce_Module_Model::getBruteForceSettings();
     if ($checkBlocked && $bruteForceSettings['active']) {
         Settings_BruteForce_Module_Model::sendNotificationEmail();
         header('Location: index.php?module=Users&parent=Settings&view=Login&error=2');
         exit;
     }
     $user = CRMEntity::getInstance('Users');
     $user->column_fields['user_name'] = $username;
     $moduleModel = Users_Module_Model::getInstance('Users');
     if ($user->doLogin($password)) {
         if (vglobal('session_regenerate_id')) {
             session_regenerate_id(true);
         }
         // to overcome session id reuse.
         $userid = $user->retrieve_user_id($username);
         Vtiger_Session::set('AUTHUSERID', $userid);
         // For Backward compatability
         // TODO Remove when switch-to-old look is not needed
         $_SESSION['authenticated_user_id'] = $userid;
         $_SESSION['app_unique_key'] = vglobal('application_unique_key');
         $_SESSION['authenticated_user_language'] = vglobal('default_language');
         $_SESSION['user_name'] = $username;
         $_SESSION['full_user_name'] = Vtiger_Functions::getUserRecordLabel($userid);
         //Enabled session variable for KCFINDER
         $_SESSION['KCFINDER'] = array();
         $_SESSION['KCFINDER']['disabled'] = false;
         $_SESSION['KCFINDER']['uploadURL'] = "cache/upload";
         $_SESSION['KCFINDER']['uploadDir'] = "../../cache/upload";
         $deniedExts = implode(" ", vglobal('upload_badext'));
         $_SESSION['KCFINDER']['deniedExts'] = $deniedExts;
         // End
         //Track the login History
         $moduleModel->saveLoginHistory($user->column_fields['user_name']);
         //End
         header('Location: index.php');
         exit;
     } else {
         //Track the login History
         $browser = Settings_BruteForce_Module_Model::browserDetect();
         $moduleModel->saveLoginHistory($username, 'Failed login', $browser);
         header('Location: index.php?module=Users&parent=Settings&view=Login&error=1');
         exit;
     }
 }
 function handleEvent($eventName, $entityData)
 {
     global $adb, $shared_owners;
     if ($eventName == 'vtiger.entity.aftersave.final' && $shared_owners == true) {
         $moduleName = $entityData->getModuleName();
         $recordId = $entityData->getId();
         $vtEntityDelta = new VTEntityDelta();
         $delta = $vtEntityDelta->getEntityDelta($moduleName, $recordId, true);
         $shownerids = $entityData->get('shownerid');
         $inheritsharing = $entityData->get('inheritsharing');
         if (array_key_exists("shownerid", $delta)) {
             $usersUpadated = TRUE;
             $oldValue = Vtiger_Functions::getArrayFromValue($delta['shownerid']['oldValue']);
             $currentValue = Vtiger_Functions::getArrayFromValue($delta['shownerid']['currentValue']);
             $addUsers = $currentValue;
             $removeUser = array_diff($oldValue, $currentValue);
         } else {
             $usersUpadated = FALSE;
         }
         $updateRelatedRecords = TRUE;
         if (array_key_exists("inheritsharing", $delta)) {
             $inheritsharing = $delta['inheritsharing']['currentValue'];
             $inheritsharingUpdated = TRUE;
             if ('0' === $delta['inheritsharing']['currentValue']) {
                 $updateRelatedRecords = FALSE;
                 $removedShared = TRUE;
             }
         } else {
             $inheritsharingUpdated = FALSE;
             $inheritsharing = $entityData->get('inheritsharing');
             if (!$inheritsharing) {
                 $updateRelatedRecords = FALSE;
             }
         }
         if ($usersUpadated || $inheritsharingUpdated) {
             if ($updateRelatedRecords) {
                 Users_Privileges_Model::setSharedOwnerRecursively($recordId, $addUsers, $removeUser, $moduleName);
             }
             if ($removedShared) {
                 Users_Privileges_Model::setSharedOwnerRecursively($recordId, [], $addUsers, $moduleName);
             }
         }
     }
     if ($eventName == 'vtiger.entity.link.after' && $shared_owners == true && Vtiger_Processes_Model::getConfig('sales', 'popup', 'update_shared_permissions') == 'true') {
         $destinationModule = array('Products', 'Services');
         if ($entityData['sourceModule'] == 'Potentials' && in_array($entityData['destinationModule'], $destinationModule)) {
             $adb = PearDatabase::getInstance();
             $result1 = $adb->pquery('SELECT smownerid, shownerid FROM vtiger_crmentity WHERE crmid = ?;', array($entityData['destinationRecordId']));
             $result2 = $adb->pquery('SELECT shownerid FROM vtiger_crmentity WHERE crmid = ?;', array($entityData['sourceRecordId']));
             if ($adb->num_rows($result1) == 1 && $adb->num_rows($result2) == 1) {
                 $smownerid = $adb->query_result($result1, 0, 'smownerid') . ',' . $adb->query_result($result1, 0, 'shownerid');
                 $shownerid = $adb->query_result($result2, 0, 'shownerid') . ',' . trim($smownerid, ',');
                 $adb->pquery("UPDATE vtiger_crmentity SET shownerid = ? WHERE crmid = ?;", [trim($shownerid, ','), $entityData['sourceRecordId']]);
             }
         }
     }
 }
Example #24
0
 /**
  * Getting value to display
  * @param type $value
  * @return type
  */
 public function getDisplayValue($value)
 {
     if ($value == 0) {
         return '';
     }
     $metaData = Vtiger_Functions::getCRMRecordMetadata($value);
     $linkValue = '<a class="moduleColor_' . $metaData['setype'] . '" href="index.php?module=' . $metaData['setype'] . '&view=Detail&record=' . $value . '" title="' . vtranslate($metaData['setype'], $metaData['setype']) . '">' . $metaData['label'] . '</a>';
     return $linkValue;
 }
Example #25
0
 public static function getTablesAll()
 {
     $modulesFields = self::getAllField();
     foreach ($modulesFields as $key => $fields) {
         foreach ($fields as $field) {
             $instance[$key][] = Vtiger_Functions::getModuleFieldInfo(getTabid($field['module']), $field['nameField']);
         }
     }
     return $instance;
 }
Example #26
0
    public function process($instance)
    {
        $adb = PearDatabase::getInstance();
        $timecontrol = 'SELECT SUM(sum_time) as sum FROM vtiger_osstimecontrol
				INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid=vtiger_osstimecontrol.osstimecontrolid
				WHERE vtiger_crmentity.deleted=0 AND  vtiger_osstimecontrol.accountid = ? AND osstimecontrol_status = ?';
        $result_timecontrol = $adb->pquery($timecontrol, array($instance->getId(), 'Accepted'));
        $decimalTimeFormat = Vtiger_Functions::decimalTimeFormat($adb->query_result($result_timecontrol, 0, 'sum'));
        return $decimalTimeFormat['short'];
    }
Example #27
0
 public function deleteKey($params)
 {
     $adb = PearDatabase::getInstance();
     $adb->pquery('DELETE dav_calendars FROM dav_calendars LEFT JOIN dav_principals ON dav_calendars.principaluri = dav_principals.uri WHERE dav_principals.userid = ?;', array($params['user']));
     $adb->pquery('DELETE FROM dav_users WHERE userid = ?;', array($params['user']));
     $adb->pquery('DELETE FROM dav_principals WHERE userid = ?;', array($params['user']));
     $user = Users_Record_Model::getInstanceById($params['user'], 'Users');
     $user_name = $user->get('user_name');
     $davStorageDir = vglobal('davStorageDir');
     Vtiger_Functions::recurseDelete($davStorageDir . '/' . $user_name);
 }
Example #28
0
 public function getCurrencyParam($currencies, $param = false)
 {
     if ($param !== false) {
         return Zend_Json::decode($param);
     } else {
         foreach ($currencies as $currency) {
             $return[$currency['id']] = Vtiger_Functions::getConversionRateInfo($currency['id']);
         }
     }
     return $return;
 }
 /**
  * Invoked when special actions are performed on the module.
  * @param String Module name
  * @param String Event Type
  */
 function vtlib_handler($moduleName, $eventType)
 {
     global $adb;
     if ($eventType == 'module.postinstall') {
         include_once 'vtlib/Vtiger/Module.php';
         $moduleInstance = CRMEntity::getInstance('RequirementCards');
         $moduleInstance->setModuleSeqNumber("configure", 'RequirementCards', 'RC', '1');
         $adb->pquery('UPDATE vtiger_tab SET customized=0 WHERE name=?', array('RequirementCards'));
         $moduleInstance = Vtiger_Module::getInstance('RequirementCards');
         $targetModule = Vtiger_Module::getInstance('Accounts');
         $targetModule->setRelatedList($moduleInstance, 'RequirementCards', array('ADD'), 'get_dependents_list');
         $modcommentsModuleInstance = Vtiger_Module::getInstance('ModComments');
         if ($modcommentsModuleInstance && file_exists('modules/ModComments/ModComments.php')) {
             include_once 'modules/ModComments/ModComments.php';
             if (class_exists('ModComments')) {
                 ModComments::addWidgetTo(array('RequirementCards'));
             }
         }
         $modcommentsModuleInstance = Vtiger_Module::getInstance('ModTracker');
         if ($modcommentsModuleInstance && file_exists('modules/ModTracker/ModTracker.php')) {
             include_once 'vtlib/Vtiger/Module.php';
             include_once 'modules/ModTracker/ModTracker.php';
             $tabid = Vtiger_Functions::getModuleId('RequirementCards');
             $moduleModTrackerInstance = new ModTracker();
             if (!$moduleModTrackerInstance->isModulePresent($tabid)) {
                 $res = $adb->pquery("INSERT INTO vtiger_modtracker_tabs VALUES(?,?)", array($tabid, 1));
                 $moduleModTrackerInstance->updateCache($tabid, 1);
             } else {
                 $updatevisibility = $adb->pquery("UPDATE vtiger_modtracker_tabs SET visible = 1 WHERE tabid = ?", array($tabid));
                 $moduleModTrackerInstance->updateCache($tabid, 1);
             }
             if (!$moduleModTrackerInstance->isModTrackerLinkPresent($tabid)) {
                 $moduleInstance = Vtiger_Module::getInstance($tabid);
                 $moduleInstance->addLink('DETAILVIEWBASIC', 'View History', "javascript:ModTrackerCommon.showhistory('\$RECORD\$')", '', '', array('path' => 'modules/ModTracker/ModTracker.php', 'class' => 'ModTracker', 'method' => 'isViewPermitted'));
             }
         }
     } else {
         if ($eventType == 'module.disabled') {
             // TODO Handle actions before this module is being uninstalled.
         } else {
             if ($eventType == 'module.preuninstall') {
                 // TODO Handle actions when this module is about to be deleted.
             } else {
                 if ($eventType == 'module.preupdate') {
                     // TODO Handle actions before this module is updated.
                 } else {
                     if ($eventType == 'module.postupdate') {
                         // TODO Handle actions after this module is updated.
                     }
                 }
             }
         }
     }
 }
Example #30
0
 /**
  * Function to get the list view entries
  * @param Vtiger_Paging_Model $pagingModel
  * @return <Array> - Associative array of record id mapped to Vtiger_Record_Model instance.
  */
 public function getListViewEntries($pagingModel)
 {
     $db = PearDatabase::getInstance();
     $module = $this->getModule();
     $parentModuleName = $module->getParentName();
     if (!empty($parentModuleName)) {
         $qualifiedModuleName = $parentModuleName . ':' . $module->getName();
     }
     $recordModelClass = Vtiger_Loader::getComponentClassName('Model', 'Record', $qualifiedModuleName);
     $listFields = $module->listFields;
     $listQuery = 'SELECT ';
     foreach ($listFields as $fieldName => $fieldLabel) {
         $listQuery .= '`' . $fieldName . '`, ';
     }
     $listQuery .= '`' . $module->baseIndex . '` FROM `' . $module->baseTable . '`';
     $params = [];
     $sourceModule = $this->get('sourceModule');
     if (!empty($sourceModule)) {
         $sourceModule = Vtiger_Functions::getModuleName($sourceModule);
         $listQuery .= ' WHERE `tabid` = ?';
         $params[] = $sourceModule;
     }
     $startIndex = $pagingModel->getStartIndex();
     $pageLimit = $pagingModel->getPageLimit();
     $orderBy = $this->getForSql('orderby');
     if (!empty($orderBy)) {
         $listQuery .= ' ORDER BY ' . $orderBy . ' ' . $this->getForSql('sortorder');
     }
     $nextListQuery = $listQuery . ' LIMIT ' . ($startIndex + $pageLimit) . ',1';
     $listQuery .= " LIMIT {$startIndex}," . ($pageLimit + 1);
     $listResult = $db->pquery($listQuery, $params);
     $listViewRecordModels = [];
     while ($row = $db->getRow($listResult)) {
         $recordModel = new $recordModelClass();
         $moduleName = Vtiger_Functions::getModuleName($row['tabid']);
         $relModuleName = Vtiger_Functions::getModuleName($row['reltabid']);
         $row['tabid'] = vtranslate($moduleName, $moduleName);
         $row['reltabid'] = vtranslate($relModuleName, $relModuleName);
         $recordModel->setData($row);
         $listViewRecordModels[$recordModel->getId()] = $recordModel;
     }
     $pagingModel->calculatePageRange($listViewRecordModels);
     if ($listResult->rowCount() > $pageLimit) {
         array_pop($listViewRecordModels);
         $pagingModel->set('nextPageExists', true);
     } else {
         $pagingModel->set('nextPageExists', false);
     }
     $nextPageResult = $db->pquery($nextListQuery, $params);
     if ($nextPageResult->rowCount() <= 0) {
         $pagingModel->set('nextPageExists', false);
     }
     return $listViewRecordModels;
 }