/** * This function exports all the data for a given module * Param $type - module name * Return type text */ function export($type) { global $log, $list_max_entries_per_page; $log->debug("Entering export(" . $type . ") method ..."); global $adb; $focus = 0; $content = ''; if ($type != "") { // vtlib customization: Hook to dynamically include required module file. // Refer to the logic in setting $currentModule in index.php $focus = CRMEntity::getInstance($type); } $log = LoggerManager::getLogger('export_' . $type); $db = PearDatabase::getInstance(); $oCustomView = new CustomView("{$type}"); $viewid = $oCustomView->getViewId("{$type}"); $sorder = $focus->getSortOrder(); $order_by = $focus->getOrderBy(); $search_type = $_REQUEST['search_type']; $export_data = $_REQUEST['export_data']; if (isset($_SESSION['export_where']) && $_SESSION['export_where'] != '' && $search_type == 'includesearch') { $where = $_SESSION['export_where']; } $query = $focus->create_export_query($where); if ($search_type != 'includesearch' && $type != 'Calendar') { $stdfiltersql = $oCustomView->getCVStdFilterSQL($viewid); $advfiltersql = $oCustomView->getCVAdvFilterSQL($viewid); if (isset($stdfiltersql) && $stdfiltersql != '') { $query .= ' and ' . $stdfiltersql; } if (isset($advfiltersql) && $advfiltersql != '') { $query .= ' and ' . $advfiltersql; } } $params = array(); if (($search_type == 'withoutsearch' || $search_type == 'includesearch') && $export_data == 'selecteddata') { $idstring = explode(";", $_REQUEST['idstring']); if ($type == 'Accounts' && count($idstring) > 0) { $query .= ' and vtiger_account.accountid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'Contacts' && count($idstring) > 0) { $query .= ' and vtiger_contactdetails.contactid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'Potentials' && count($idstring) > 0) { $query .= ' and vtiger_potential.potentialid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'Leads' && count($idstring) > 0) { $query .= ' and vtiger_leaddetails.leadid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'Products' && count($idstring) > 0) { $query .= ' and vtiger_products.productid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'Documents' && count($idstring) > 0) { $query .= ' and vtiger_notes.notesid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'HelpDesk' && count($idstring) > 0) { $query .= ' and vtiger_troubletickets.ticketid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } elseif ($type == 'Vendors' && count($idstring) > 0) { $query .= ' and vtiger_vendor.vendorid in (' . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); } else { if (count($idstring) > 0) { // vtlib customization: Hook to make the export feature available for custom modules. $query .= " and {$focus->table_name}.{$focus->table_index} in (" . generateQuestionMarks($idstring) . ')'; array_push($params, $idstring); // END } } } if (isset($order_by) && $order_by != '') { if ($order_by == 'smownerid') { $query .= ' ORDER BY user_name ' . $sorder; } elseif ($order_by == 'lastname' && $type == 'Documents') { $query .= ' ORDER BY vtiger_contactdetails.lastname ' . $sorder; } elseif ($order_by == 'crmid' && $type == 'HelpDesk') { $query .= ' ORDER BY vtiger_troubletickets.ticketid ' . $sorder; } else { $tablename = getTableNameForField($type, $order_by); $tablename = $tablename != '' ? $tablename . "." : ''; if ($adb->dbType == "pgsql") { $query .= ' GROUP BY ' . $tablename . $order_by; } $query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder; } } if ($export_data == 'currentpage') { $current_page = ListViewSession::getCurrentPage($type, $viewid); $limit_start_rec = ($current_page - 1) * $list_max_entries_per_page; if ($limit_start_rec < 0) { $limit_start_rec = 0; } $query .= ' LIMIT ' . $limit_start_rec . ',' . $list_max_entries_per_page; } $result = $adb->pquery($query, $params, true, "Error exporting {$type}: " . "<BR>{$query}"); $fields_array = $adb->getFieldsArray($result); $fields_array = array_diff($fields_array, array("user_name")); $__processor = new ExportUtils($type, $fields_array); // Translated the field names based on the language used. $translated_fields_array = array(); for ($i = 0; $i < count($fields_array); $i++) { $translated_fields_array[$i] = getTranslatedString($fields_array[$i], $type); } $header = implode("\",\"", array_values($translated_fields_array)); $header = "\"" . $header; $header .= "\"\r\n"; /** Output header information */ echo $header; $column_list = implode(",", array_values($fields_array)); while ($val = $adb->fetchByAssoc($result, -1, false)) { $new_arr = array(); $val = $__processor->sanitizeValues($val); foreach ($val as $key => $value) { if ($type == 'Documents' && $key == 'description') { $value = strip_tags($value); $value = str_replace(' ', '', $value); array_push($new_arr, $value); } elseif ($key != "user_name") { // Let us provide the module to transform the value before we save it to CSV file $value = $focus->transform_export_value($key, $value); array_push($new_arr, preg_replace("/\"/", "\"\"", $value)); } } $line = implode("\",\"", $new_arr); $line = "\"" . $line; $line .= "\"\r\n"; /** Output each row information */ echo $line; } $log->debug("Exiting export method ..."); return true; }
public static function getListViewNavigation($currentRecordId) { global $currentModule, $current_user, $adb, $log, $list_max_entries_per_page; Zend_Json::$useBuiltinEncoderDecoder = true; $reUseData = false; $displayBufferRecordCount = 10; $bufferRecordCount = 15; if ($currentModule == 'Documents') { $sql = "select folderid from vtiger_notes where notesid=?"; $params = array($currentRecordId); $result = $adb->pquery($sql, $params); $folderId = $adb->query_result($result, 0, 'folderid'); } $cv = new CustomView(); $viewId = $cv->getViewId($currentModule); if (!empty($_SESSION[$currentModule . '_DetailView_Navigation' . $viewId])) { $recordNavigationInfo = Zend_Json::decode($_SESSION[$currentModule . '_DetailView_Navigation' . $viewId]); $pageNumber = 0; if (count($recordNavigationInfo) == 1) { foreach ($recordNavigationInfo as $recordIdList) { if (in_array($currentRecordId, $recordIdList)) { $reUseData = true; } } } else { $recordList = array(); $recordPageMapping = array(); foreach ($recordNavigationInfo as $start => $recordIdList) { foreach ($recordIdList as $index => $recordId) { $recordList[] = $recordId; $recordPageMapping[$recordId] = $start; if ($recordId == $currentRecordId) { $searchKey = count($recordList) - 1; } } } if ($searchKey > $displayBufferRecordCount - 1 && $searchKey < count($recordList) - $displayBufferRecordCount) { $reUseData = true; } } } if ($reUseData === false) { $recordNavigationInfo = array(); if (!empty($_REQUEST['start'])) { $start = ListViewSession::getRequestStartPage(); } else { $start = ListViewSession::getCurrentPage($currentModule, $viewId); } $startRecord = ($start - 1) * $list_max_entries_per_page - $bufferRecordCount; if ($startRecord < 0) { $startRecord = 0; } $list_query = $_SESSION[$currentModule . '_listquery']; $instance = CRMEntity::getInstance($currentModule); $instance->getNonAdminAccessControlQuery($currentModule, $current_user); vtlib_setup_modulevars($currentModule, $instance); if ($currentModule == 'Documents' && !empty($folderId)) { $list_query = preg_replace("/[\n\r\\s]+/", " ", $list_query); $hasOrderBy = stripos($list_query, 'order by'); if ($hasOrderBy > 0) { $list_query = substr($list_query, 0, $hasOrderBy - 1) . " AND vtiger_notes.folderid={$folderId} " . substr($list_query, $hasOrderBy); } else { $list_query .= " AND vtiger_notes.folderid={$folderId}"; $order_by = $instance->getOrderByForFolder($folderId); $sorder = $instance->getSortOrderForFolder($folderId); $tablename = getTableNameForField($currentModule, $order_by); $tablename = $tablename != '' ? $tablename . "." : ''; if (!empty($order_by)) { $list_query .= ' ORDER BY ' . $tablename . $order_by . ' ' . $sorder; } } } if ($start != 1) { $recordCount = $list_max_entries_per_page + 2 * $bufferRecordCount; } else { $recordCount = $list_max_entries_per_page + $bufferRecordCount; } $list_query .= " LIMIT {$startRecord}, {$recordCount}"; $resultAllCRMIDlist_query = $adb->pquery($list_query, array()); $navigationRecordList = array(); while ($forAllCRMID = $adb->fetch_array($resultAllCRMIDlist_query)) { $navigationRecordList[] = $forAllCRMID[$instance->table_index]; } $pageCount = 0; $current = $start; if ($start == 1) { $firstPageRecordCount = $list_max_entries_per_page; } else { $firstPageRecordCount = $bufferRecordCount; $current -= 1; } $searchKey = array_search($currentRecordId, $navigationRecordList); $recordNavigationInfo = array(); if ($searchKey !== false) { foreach ($navigationRecordList as $index => $recordId) { if (!is_array($recordNavigationInfo[$current])) { $recordNavigationInfo[$current] = array(); } if ($index == $firstPageRecordCount || $index == $firstPageRecordCount + $pageCount * $list_max_entries_per_page) { $current++; $pageCount++; } $recordNavigationInfo[$current][] = $recordId; } } $_SESSION[$currentModule . '_DetailView_Navigation' . $viewId] = Zend_Json::encode($recordNavigationInfo); } return $recordNavigationInfo; }
function getExportRecordIds($moduleName, $viewid, $input) { global $adb, $current_user, $list_max_entries_per_page; $idstring = vtlib_purify($input['idstring']); $export_data = vtlib_purify($input['export_data']); if (in_array($moduleName, getInventoryModules()) && $export_data == 'currentpage') { $queryGenerator = new QueryGenerator($moduleName, $current_user); $queryGenerator->initForCustomViewById($viewid); if ($input['query'] == 'true') { $queryGenerator->addUserSearchConditions($input); } $queryGenerator->setFields(array('id')); $query = $queryGenerator->getQuery(); $current_page = ListViewSession::getCurrentPage($moduleName, $viewid); $limit_start_rec = ($current_page - 1) * $list_max_entries_per_page; if ($limit_start_rec < 0) { $limit_start_rec = 0; } $query .= ' LIMIT ' . $limit_start_rec . ',' . $list_max_entries_per_page; $result = $adb->pquery($query, array()); $idstring = array(); $focus = CRMEntity::getInstance($moduleName); for ($i = 0; $i < $adb->num_rows($result); $i++) { $idstring[] = $adb->query_result($result, $i, $focus->table_index); } $idstring = implode(';', $idstring); $export_data = 'selecteddata'; } return $idstring . '#@@#' . $export_data; }
function getListViewNavigation($currentRecordId) { global $currentModule, $current_user, $adb, $log, $list_max_entries_per_page; Zend_Json::$useBuiltinEncoderDecoder = true; $reUseData = false; $displayBufferRecordCount = 10; $bufferRecordCount = 15; if ($currentModule == 'Documents') { $sql = "select folderid from vtiger_notes where notesid=?"; $params = array($currentRecordId); $result = $adb->pquery($sql, $params); $folderId = $adb->query_result($result, 0, 'folderid'); } $cv = new CustomView(); $viewId = $cv->getViewId($currentModule); if (!empty($_SESSION[$currentModule . '_DetailView_Navigation' . $viewId])) { $recordNavigationInfo = Zend_Json::decode($_SESSION[$currentModule . '_DetailView_Navigation' . $viewId]); $pageNumber = 0; if (count($recordNavigationInfo) == 1) { foreach ($recordNavigationInfo as $recordIdList) { if (in_array($currentRecordId, $recordIdList)) { $reUseData = true; } } } else { $recordList = array(); $recordPageMapping = array(); foreach ($recordNavigationInfo as $start => $recordIdList) { foreach ($recordIdList as $index => $recordId) { $recordList[] = $recordId; $recordPageMapping[$recordId] = $start; if ($recordId == $currentRecordId) { $searchKey = count($recordList) - 1; } } } if ($searchKey > $displayBufferRecordCount - 1 && $searchKey < count($recordList) - $displayBufferRecordCount) { $reUseData = true; } } } if ($reUseData === false) { $recordNavigationInfo = array(); if (!empty($_REQUEST['start'])) { $start = ListViewSession::getRequestStartPage(); } else { $start = ListViewSession::getCurrentPage($currentModule, $viewId); } $startRecord = ($start - 1) * $list_max_entries_per_page - $bufferRecordCount; if ($startRecord < 0) { $startRecord = 0; } $list_query = $_SESSION[$currentModule . '_listquery']; if ($currentModule == 'Documents' && !empty($folderId)) { $list_query = preg_replace("/[\n\r\\s]+/", " ", $list_query); $findOrderByPosition = stripos($list_query, ' ORDER BY '); if ($findOrderByPosition > 0) { $orderByClause = substr($list_query, $findOrderByPosition, strlen($list_query)); $list_query = substr($list_query, 0, $findOrderByPosition) . " AND vtiger_notes.folderid={$folderId} " . $orderByClause; } else { $list_query .= " AND vtiger_notes.folderid={$folderId}"; } } if ($start != 1) { $recordCount = $list_max_entries_per_page + 2 * $bufferRecordCount; } else { $recordCount = $list_max_entries_per_page + $bufferRecordCount; } if ($adb->dbType == "pgsql") { $list_query .= " OFFSET {$startRecord} LIMIT {$recordCount}"; } else { $list_query .= " LIMIT {$startRecord}, {$recordCount}"; } $resultAllCRMIDlist_query = $adb->pquery($list_query, array()); $navigationRecordList = array(); while ($forAllCRMID = $adb->fetch_array($resultAllCRMIDlist_query)) { $navigationRecordList[] = $forAllCRMID['crmid']; } $pageCount = 0; $current = $start; if ($start == 1) { $firstPageRecordCount = $list_max_entries_per_page; } else { $firstPageRecordCount = $bufferRecordCount; $current -= 1; } $searchKey = array_search($currentRecordId, $navigationRecordList); $recordNavigationInfo = array(); if ($searchKey !== false) { foreach ($navigationRecordList as $index => $recordId) { if (!is_array($recordNavigationInfo[$current])) { $recordNavigationInfo[$current] = array(); } if ($index == $firstPageRecordCount || $index == $firstPageRecordCount + $pageCount * $list_max_entries_per_page) { $current++; $pageCount++; } $recordNavigationInfo[$current][] = $recordId; } } $_SESSION[$currentModule . '_DetailView_Navigation' . $viewId] = Zend_Json::encode($recordNavigationInfo); } return $recordNavigationInfo; }