public function process(Vtiger_Request $request)
 {
     $current_user = Users_Record_Model::getCurrentUserModel();
     $RelatedBlock = new PDFMaker_RelatedBlock_Model();
     $sec_module = $request->get('secmodule');
     $pri_module = $request->get('primodule');
     $mode = $request->get('mode');
     $module_list = $RelatedBlock->getModuleList($sec_module);
     $content = "";
     if ($mode == "stdcriteria") {
         $options = $RelatedBlock->getStdCriteriaByModule($sec_module, $module_list, $current_user);
         if (count($options) > 0) {
             foreach ($options as $value => $label) {
                 $content .= "<option value='" . $value . "'>" . $label . "</option>";
             }
         }
     } else {
         foreach ($module_list as $blockid => $optgroup) {
             $options = $RelatedBlock->getColumnsListbyBlock($sec_module, $blockid, $pri_module, $current_user);
             if (count($options) > 0) {
                 $content .= "<optgroup label='" . $optgroup . "'>";
                 foreach ($options as $value => $label) {
                     $content .= "<option value='" . $value . "'>" . $label . "</option>";
                 }
                 $content .= "</optgroup>";
             }
         }
     }
     $response = new Vtiger_Response();
     $response->setResult($content);
     $response->emit();
 }
Example #2
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $adb = PearDatabase::getInstance();
     $current_user = Users_Record_Model::getCurrentUserModel();
     $viewer = $this->getViewer($request);
     global $current_language;
     $step = $request->get('step');
     if ($step == "") {
         $step = "1";
     }
     $mode = $request->get('mode');
     $record = $request->get('record');
     if (isset($mode) && $mode == "Delete") {
         $sql1 = "SELECT module FROM vtiger_pdfmaker_relblocks WHERE relblockid = ?";
         $rel_module = $adb->query_result($adb->pquery($sql1, array($record)), 0, "module");
         $sql2 = "DELETE FROM vtiger_pdfmaker_relblocks WHERE relblockid = ?";
         $result = $adb->pquery($sql2, array($record));
         header("Location:index.php?module=PDFMaker&action=PDFMakerAjax&file=ListRelatedBlocks&parenttab=Tools&pdfmodule=" . $rel_module);
         exit;
     }
     if (isset($mode) && $mode == "add") {
         $sql = "SELECT * FROM vtiger_pdfmaker_relblocks WHERE relblockid = ?";
         $result = $adb->pquery($sql, array($record));
         $Blockdata = $adb->fetchByAssoc($result, 0);
         $body = $Blockdata["block"];
         $body = str_replace("RELBLOCK_START", "RELBLOCK" . $record . "_START", $body);
         $body = str_replace("RELBLOCK_END", "RELBLOCK" . $record . "_END", $body);
         //echo $body; exit;
         echo "<div id='block' style='display:none;'>" . $body . "</div>";
         echo "<script> \n\t\tvar oEditor = window.opener.CKEDITOR.instances.body; \n\t\t\n\t\tcontent = document.getElementById('block').innerHTML;\n\t\t\n\t\toEditor.insertHtml(content); \n\t\tself.close();\n\t\t</script>";
         exit;
     }
     $viewer->assign("PARENTTAB", getParentTab());
     $viewer->assign("DATEFORMAT", $current_user->get('date_format'));
     $viewer->assign("JS_DATEFORMAT", parse_calendardate(vtranslate('NTC_DATE_FORMAT')));
     $RelatedBlock = new PDFMaker_RelatedBlock_Model();
     $columns1 = "";
     if ($record) {
         $sql = "SELECT * FROM vtiger_pdfmaker_relblocks WHERE relblockid = ?";
         $result = $adb->pquery($sql, array($record));
         $Blockdata = $adb->fetchByAssoc($result, 0);
         $rel_module = $Blockdata["module"];
         $sec_module = $Blockdata["secmodule"];
         $blockname = $Blockdata["name"];
         $block = $Blockdata["block"];
         $sql2 = "SELECT * FROM vtiger_pdfmaker_relblockdatefilter WHERE datefilterid = ?";
         $result2 = $adb->pquery($sql2, array($record));
         $num_rows2 = $adb->num_rows($result2);
         if ($num_rows2 > 0) {
             $datecolumnname = $adb->query_result($result2, 0, "datecolumnname");
             $stdselectedfilter = $adb->query_result($result2, 0, "datefilter");
             $startdate = $adb->query_result($result2, 0, "startdate");
             $enddate = $adb->query_result($result2, 0, "enddate");
             if ($startdate != "" && $startdate != "0000-00-00") {
                 $viewer->assign("STARTDATE_STD", getValidDisplayDate($startdate));
             }
             if ($enddate != "" && $startdate != "0000-00-00") {
                 $viewer->assign("ENDDATE_STD", getValidDisplayDate($enddate));
             }
         }
         $module_list = $RelatedBlock->getModuleList($sec_module);
         $options1 = $RelatedBlock->getStdCriteriaByModule($sec_module, $module_list, $current_user);
         if (count($options1) > 0) {
             foreach ($options1 as $value => $label) {
                 if ($value == $datecolumnname) {
                     $sel = "selected";
                 } else {
                     $sel = "";
                 }
                 $columns1 .= "<option value='" . $value . "' " . $sel . ">" . $label . "</option>";
             }
         }
         $columns2 = "";
         foreach ($module_list as $blockid => $optgroup) {
             $options2 = $RelatedBlock->getColumnsListbyBlock($sec_module, $blockid, $rel_module, $current_user);
             if (count($options2) > 0) {
                 $columns2 .= "<optgroup label='" . $optgroup . "'>";
                 foreach ($options2 as $value => $label) {
                     $columns2 .= "<option value='" . $value . "'>" . $label . "</option>";
                 }
                 $columns2 .= "</optgroup>";
             }
         }
         $selected_columns = $this->getSelectedColumnsList($rel_module, $sec_module, $record, $current_user);
         list($sortCols, $sortOrder) = $this->getSortColumns($record, $selected_columns);
         $step = 3;
         $mode = 'edit';
         $RelatedBlock->setId($record);
         $reportModel = Reports_Record_Model::getCleanInstance('');
         $reportModel->setPrimaryModule($rel_module);
         $RelatedBlock->setPrimaryModule($rel_module);
         if (!empty($sec_module)) {
             $RelatedBlock->setSecondaryModule($sec_module);
             $reportModel->setSecondaryModule($sec_module);
         }
         $viewer->assign('SELECTED_ADVANCED_FILTER_FIELDS', $RelatedBlock->transformToNewAdvancedFilter());
         $viewer->assign('PRIMARY_MODULE', $primaryModule);
         $recordStructureInstance = Vtiger_RecordStructure_Model::getInstanceFromRecordModel($reportModel);
         $primaryModuleRecordStructure = $recordStructureInstance->getPrimaryModuleRecordStructure();
         $secondaryModuleRecordStructures = $recordStructureInstance->getSecondaryModuleRecordStructure();
         $viewer->assign('PRIMARY_MODULE_RECORD_STRUCTURE', $primaryModuleRecordStructure);
         $viewer->assign('SECONDARY_MODULE_RECORD_STRUCTURES', $secondaryModuleRecordStructures);
         $viewer->assign('ADVANCED_FILTER_OPTIONS', Vtiger_Field_Model::getAdvancedFilterOptions());
         $viewer->assign('ADVANCED_FILTER_OPTIONS_BY_TYPE', Vtiger_Field_Model::getAdvancedFilterOpsByFieldType());
         $dateFilters = Vtiger_Field_Model::getDateFilterTypes();
         foreach ($dateFilters as $comparatorKey => $comparatorInfo) {
             $comparatorInfo['startdate'] = DateTimeField::convertToUserFormat($comparatorInfo['startdate']);
             $comparatorInfo['enddate'] = DateTimeField::convertToUserFormat($comparatorInfo['enddate']);
             $comparatorInfo['label'] = vtranslate($comparatorInfo['label'], $module);
             $dateFilters[$comparatorKey] = $comparatorInfo;
         }
         $viewer->assign('DATE_FILTERS', $dateFilters);
         $viewer->assign('PRIMARY_MODULE_FIELDS', $reportModel->getPrimaryModuleFields());
         $viewer->assign('SECONDARY_MODULE_FIELDS', $reportModel->getSecondaryModuleFields());
         $viewer->assign('SELECTED_SORT_FIELDS', $RelatedBlock->getSelectedSortFields());
     } else {
         $primaryModule = $request->get('primarymodule');
         $secondaryModules = $request->get('secondarymodule');
         $rel_module = $_REQUEST["pdfmodule"];
         $block = "";
         $record = "";
         $blockname = "";
         $columns = "";
         $columns2 = "";
         $selected_columns = "";
         $sortCols = "";
         $sortOrder = "";
         $stdselectedfilter = "";
         $mode = 'create';
     }
     $viewer->assign("MODE", $mode);
     $viewer->assign("RECORD", $record);
     $viewer->assign("BLOCKNAME", $blockname);
     $Related_Modules = PDFMaker_RelatedBlock_Model::getRelatedModulesList($rel_module);
     if ($record == "") {
         $sec_module = $Related_Modules[0];
     }
     $viewer->assign("SEC_MODULE", $sec_module);
     $viewer->assign("RELATED_MODULES", $Related_Modules);
     $version = PDFMaker_Version_Helper::$version;
     $viewer->assign("VERSION", $version);
     $viewer->assign("REL_MODULE", $rel_module);
     $viewer->assign("RELATEDBLOCK", $block);
     $viewer->assign("STEP", $step);
     $viewer->view('EditRelatedBlock.tpl', 'PDFMaker');
 }