public function getDetailDashboards($moduleName, $recordId)
 {
     $dashboardsUrls = array();
     foreach (Reports_Module_Model::getTemplatesReportModels($moduleName) as $report) {
         $dashboardsUrls[] = $report->getWidgetReportURL();
     }
     $detailWidgets = array();
     if (!empty($dashboardsUrls)) {
         $inCriteria = '(' . substr(str_repeat('?,', count($dashboardsUrls)), 0, -1) . ')';
         $sql = "SELECT vtiger_links.*, vtiger_module_dashboard_widgets.userid, vtiger_module_dashboard_widgets.id as widgetid, vtiger_module_dashboard_widgets.position as position, vtiger_links.linkid FROM vtiger_links " . "INNER JOIN vtiger_module_dashboard_widgets ON vtiger_links.linkid=vtiger_module_dashboard_widgets.linkid " . "WHERE (linktype=? AND tabid=? AND vtiger_module_dashboard_widgets.userid=? AND linkurl IN" . $inCriteria . ")";
         $db = PearDatabase::getInstance();
         $currentUser = Users_Record_Model::getCurrentUserModel();
         $result = $db->pquery($sql, array_merge(array('DASHBOARDWIDGET', getTabid($moduleName), $currentUser->getId()), $dashboardsUrls));
         while ($row = $db->fetchByAssoc($result)) {
             /* Prepare URL for report template */
             if ($this->checkModulePermission($row)) {
                 $widgetModel = Vtiger_Widget_Model::getInstanceFromValues($row);
                 $widgetModel->applyTemplateRecordId($recordId);
                 $detailWidgets[] = $widgetModel;
             }
         }
     }
     return $detailWidgets;
 }
 /**
  * Function to get the detail view links (links and widgets)
  * @param <array> $linkParams - parameters which will be used to calicaulate the params
  * @return <array> - array of link models in the format as below
  *                   array('linktype'=>list of link models);
  */
 public function getDetailViewLinks($linkParams)
 {
     $linkTypes = array('DETAILVIEWBASIC', 'DETAILVIEW');
     $moduleModel = $this->getModule();
     $recordModel = $this->getRecord();
     $moduleName = $moduleModel->getName();
     $recordId = $recordModel->getId();
     $detailViewLink = array();
     if (Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId)) {
         $detailViewLinks[] = array('linktype' => 'DETAILVIEWBASIC', 'linklabel' => 'LBL_EDIT', 'linkurl' => $recordModel->getEditViewUrl(), 'linkicon' => '');
         foreach ($detailViewLinks as $detailViewLink) {
             $linkModelList['DETAILVIEWBASIC'][] = Vtiger_Link_Model::getInstanceFromValues($detailViewLink);
         }
     }
     $linkModelListDetails = Vtiger_Link_Model::getAllByType($moduleModel->getId(), $linkTypes, $linkParams);
     //Mark all detail view basic links as detail view links.
     //Since ui will be look ugly if you need many basic links
     $detailViewBasiclinks = $linkModelListDetails['DETAILVIEWBASIC'];
     unset($linkModelListDetails['DETAILVIEWBASIC']);
     if (Users_Privileges_Model::isPermitted($moduleName, 'Delete', $recordId)) {
         $deletelinkModel = array('linktype' => 'DETAILVIEW', 'linklabel' => sprintf("%s %s", getTranslatedString('LBL_DELETE', $moduleName), vtranslate('SINGLE_' . $moduleName, $moduleName)), 'linkurl' => 'javascript:Vtiger_Detail_Js.deleteRecord("' . $recordModel->getDeleteUrl() . '")', 'linkicon' => '');
         $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($deletelinkModel);
     }
     if (Users_Privileges_Model::isPermitted($moduleName, 'EditView', $recordId)) {
         $duplicateLinkModel = array('linktype' => 'DETAILVIEWBASIC', 'linklabel' => 'LBL_DUPLICATE', 'linkurl' => $recordModel->getDuplicateRecordUrl(), 'linkicon' => '');
         $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($duplicateLinkModel);
     }
     if (!empty($detailViewBasiclinks)) {
         foreach ($detailViewBasiclinks as $linkModel) {
             // Remove view history, needed in vtiger5 to see history but not in vtiger6
             if ($linkModel->linklabel == 'View History') {
                 continue;
             }
             $linkModelList['DETAILVIEW'][] = $linkModel;
         }
     }
     //SalesPlatform.ru begin -  add PDF templates links to DetailView  from SPPDFTemplates
     /* Two cycles - to order */
     $pdfTemplates = new SPPDFTemplates_Module_Model();
     $availableTemplates = $pdfTemplates->getModuleTemplates($this->getModuleName(), $this->record->get('spcompany'));
     foreach ($availableTemplates as $template) {
         /* Export PDF links */
         $pdfTemplateLink = array('linklabel' => sprintf("%s %s", vtranslate('LBL_EXPORT_TO_PDF', $moduleName), $template->getName()), 'linkurl' => $recordModel->getExportPDFURL($template));
         $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($pdfTemplateLink);
     }
     foreach ($availableTemplates as $template) {
         /* Email link */
         $sendEmailLink = array('linklabel' => sprintf("%s %s", vtranslate('LBL_SEND_MAIL_PDF', $moduleName), $template->getName()), 'linkurl' => 'javascript:Vtiger_Detail_Js.sendEmailPDFClickHandler(\'' . $recordModel->getSendEmailPDFUrl($template) . '\')');
         $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues($sendEmailLink);
     }
     //SalesPlatform.ru end
     $relatedLinks = $this->getDetailViewRelatedLinks();
     foreach ($relatedLinks as $relatedLinkEntry) {
         $relatedLink = Vtiger_Link_Model::getInstanceFromValues($relatedLinkEntry);
         $linkModelList[$relatedLink->getType()][] = $relatedLink;
     }
     $widgets = $this->getWidgets();
     foreach ($widgets as $widgetLinkModel) {
         $linkModelList['DETAILVIEWWIDGET'][] = $widgetLinkModel;
     }
     $currentUserModel = Users_Record_Model::getCurrentUserModel();
     if ($currentUserModel->isAdminUser()) {
         $settingsLinks = $moduleModel->getSettingLinks();
         foreach ($settingsLinks as $settingsLink) {
             $linkModelList['DETAILVIEWSETTING'][] = Vtiger_Link_Model::getInstanceFromValues($settingsLink);
         }
     }
     //SalesPlatform.ru begin add templates reports
     foreach (Reports_Module_Model::getTemplatesReportModels($moduleName) as $reportModel) {
         $linkModelList['DETAILVIEW'][] = Vtiger_Link_Model::getInstanceFromValues(array('linklabel' => vtranslate('SINGLE_Reports', 'Reports') . ' «' . $reportModel->getName() . '»', 'linkurl' => $reportModel->getDetailViewUrl() . '&report_record_id=' . $recordId));
     }
     //SalesPlatform.ru end
     return $linkModelList;
 }