function generate(Vtiger_Request $xxx0b)
 {
     global $xxx22, $xxx23, $xxx24, $xxx25, $xxx26, $xxx27, $xxx28, $xxx29;
     $xxx0c = new PDFMaker_PDFMaker_Model();
     $xxx0d = $xxx0b->getAll();
     $xxx0e = PearDatabase::getInstance();
     $xxx0f = "site_URL";
     $xxx10 = "vtiger_current_version";
     $xxx11 = vglobal($xxx10);
     $xxx12 = vglobal($xxx0f);
     $xxx13 = $xxx0b->get('relmodule');
     $xxx14 = CRMEntity::getInstance($xxx13);
     $xxx15 = $xxx0b->get('record');
     $xxx16 = $xxx0b->get('mode');
     $xxx17 = $xxx0b->get('language');
     $xxx18 = $xxx0b->get('type');
     $xxx19 = "";
     $xxx1a = $xxx0c->GetPreparedMPDF($xxx19, $xxx15, $xxx13, $xxx17);
     $xxx19->Output('cache/' . $xxx1a . '.pdf');
     @$xxx27();
     $xxx25('Content-Type: application/pdf');
     $xxx25("Content-length: " . $xxx22("./cache/{$xxx1a}.pdf"));
     $xxx25("Cache-Control: private");
     $xxx25("Content-Disposition: attachment; filename={$xxx1a}.pdf");
     $xxx25("Content-Description: PHP Generated Data");
     echo $xxx23($xxx24("./cache/{$xxx1a}.pdf", "r"), $xxx22("./cache/{$xxx1a}.pdf"));
     @$xxx29("cache/{$xxx1a}.pdf");
 }
Exemple #2
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $adb = PearDatabase::getInstance();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $viewer = $this->getViewer($request);
     $currentLanguage = Vtiger_Language_Handler::getLanguage();
     list($oLabels, $languages) = $PDFMaker->GetCustomLabels();
     $currLang = array();
     foreach ($languages as $langId => $langVal) {
         if ($langVal["prefix"] == $currentLanguage) {
             $currLang["id"] = $langId;
             $currLang["name"] = $langVal["name"];
             $currLang["label"] = $langVal["label"];
             $currLang["prefix"] = $langVal["prefix"];
             break;
         }
     }
     $viewLabels = array();
     foreach ($oLabels as $lblId => $oLabel) {
         $viewLabels[$lblId]["key"] = $oLabel->GetKey();
         $viewLabels[$lblId]["lang_values"] = $oLabel->GetLangValsArr();
     }
     $viewer->assign("LABELS", $viewLabels);
     $viewer->assign("LANGUAGES", $languages);
     $viewer->assign("CURR_LANG", $currLang);
     $viewer->view('CustomLabels.tpl', 'PDFMaker');
 }
Exemple #3
0
 protected function _getFile($id, $moduleName, $crmid)
 {
     $current_user = \Users_Record_Model::getCurrentUserModel();
     $useUser = \Users::getActiveAdminUser();
     $oldUser = vglobal('current_user');
     vglobal('current_user', $useUser);
     $tmpFilename = $this->_getTmpFilename();
     $mpdf = "";
     $language = $current_user->language;
     if (empty($language)) {
         $language = \Vtiger_Language_Handler::getLanguage();
     }
     $Records = array($crmid);
     // $request = $_REQUEST;
     // $_REQUEST['search'] = true;
     //$_REQUEST['submode'] = true;
     \Vtiger_Loader::autoLoad('PDFMaker_PDFMaker_Model');
     $PDFMaker = new \PDFMaker_PDFMaker_Model();
     $name = $PDFMaker->GetPreparedMPDF($mpdf, $Records, array($id), $moduleName, $language);
     $name = $PDFMaker->generate_cool_uri($name);
     if ($name != "") {
         $name = $name . ".pdf";
     }
     $mpdf->Output($tmpFilename);
     vglobal('current_user', $oldUser);
     $filetype = "application/pdf";
     //$_REQUEST = $request;
     return array('path' => $tmpFilename, 'name' => $name, 'type' => $filetype);
 }
Exemple #4
0
 /**
  * Function which will construct the compose email
  * This will handle the case of attaching the invoice pdf as attachment
  * @param Vtiger_Request $request 
  */
 public function composeMailData(Vtiger_Request $request)
 {
     parent::composeMailData($request);
     $viewer = $this->getViewer($request);
     $inventoryRecordId = $request->get('record');
     $mpdf = "";
     $Records = array($inventoryRecordId);
     $language = $request->get('language');
     $moduleName = $request->get('formodule');
     //$pdftemplateid = rtrim($request->get('pdftemplateid'),';');
     $pdftemplateid = rtrim($request->get('pdftemplateid'), ';');
     $Templateids = explode(";", $pdftemplateid);
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $name = $PDFMaker->GetPreparedMPDF($mpdf, $Records, $Templateids, $moduleName, $language);
     $name = $PDFMaker->generate_cool_uri($name);
     if ($name != "") {
         $fileName = $name . ".pdf";
     } else {
         $fileName = $moduleName . "_" . $inventoryRecordId . '.pdf';
     }
     $current_user = $cu_model = Users_Record_Model::getCurrentUserModel();
     if (!is_dir("storage/PDFMaker/")) {
         mkdir("storage/PDFMaker/");
     }
     if (!is_dir("storage/PDFMaker/" . $current_user->id)) {
         mkdir("storage/PDFMaker/" . $current_user->id);
     }
     $path = 'storage/PDFMaker/' . $current_user->id;
     $pdfFilePath = $path . '/' . $fileName;
     $mpdf->Output($pdfFilePath);
     $attachmentDetails = array(array('attachment' => $fileName, 'path' => $path, 'size' => filesize($pdfFilePath), 'type' => 'pdf', 'nondeletable' => true));
     $viewer->assign('ATTACHMENTS', $attachmentDetails);
     echo $viewer->view('ComposeEmailForm.tpl', 'Emails', true);
 }
Exemple #5
0
 public function process(Vtiger_Request $request)
 {
     if ($_FILES['import_file']['error'] == 0) {
         $tmp_file_name = $_FILES['import_file']['tmp_name'];
         $fh = fopen($tmp_file_name, "r");
         $xml_content = fread($fh, filesize($tmp_file_name));
         fclose($fh);
         $PDFMaker = new PDFMaker_PDFMaker_Model();
         $adb = PearDatabase::getInstance();
         $xml = new SimpleXMLElement($xml_content);
         foreach ($xml->template as $data) {
             $filename = $this->cdataDecode($data->templatename);
             $nameOfFile = $this->cdataDecode($data->filename);
             $description = $this->cdataDecode($data->description);
             $modulename = $this->cdataDecode($data->module);
             $pdf_format = $this->cdataDecode($data->settings->format);
             $pdf_orientation = $this->cdataDecode($data->settings->orientation);
             $tabid = getTabId($modulename);
             if ($PDFMaker->GetVersionType() == "professional" || in_array($tabid, $PDFMaker->GetBasicModules())) {
                 if ($data->settings->margins->top > 0) {
                     $margin_top = $data->settings->margins->top;
                 } else {
                     $margin_top = 0;
                 }
                 if ($data->settings->margins->bottom > 0) {
                     $margin_bottom = $data->settings->margins->bottom;
                 } else {
                     $margin_bottom = 0;
                 }
                 if ($data->settings->margins->left > 0) {
                     $margin_left = $data->settings->margins->left;
                 } else {
                     $margin_left = 0;
                 }
                 if ($data->settings->margins->right > 0) {
                     $margin_right = $data->settings->margins->right;
                 } else {
                     $margin_right = 0;
                 }
                 $dec_point = $this->cdataDecode($data->settings->decimals->point);
                 $dec_decimals = $this->cdataDecode($data->settings->decimals->decimals);
                 $dec_thousands = $this->cdataDecode($data->settings->decimals->thousands);
                 $header = $this->cdataDecode($data->header);
                 $body = $this->cdataDecode($data->body);
                 $footer = $this->cdataDecode($data->footer);
                 $templateid = $adb->getUniqueID('vtiger_pdfmaker');
                 $sql1 = "insert into vtiger_pdfmaker (filename,module,description,body,deleted,templateid) values (?,?,?,?,?,?)";
                 $params1 = array($filename, $modulename, $description, $body, 0, $templateid);
                 $adb->pquery($sql1, $params1);
                 $sql2 = "INSERT INTO vtiger_pdfmaker_settings (templateid, margin_top, margin_bottom, margin_left, margin_right, format, orientation, decimals, decimal_point, thousands_separator, header, footer, encoding, file_name) \n             VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                 $params2 = array($templateid, $margin_top, $margin_bottom, $margin_left, $margin_right, $pdf_format, $pdf_orientation, $dec_decimals, $dec_point, $dec_thousands, $header, $footer, "auto", $nameOfFile);
                 $adb->pquery($sql2, $params2);
                 $PDFMaker->AddLinks($modulename);
             }
         }
     }
     header('Location: index.php?module=PDFMaker&view=List');
 }
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("DELETE") == false) {
         $PDFMaker->DieDuePermission();
     }
     $adb = PearDatabase::getInstance();
     $id_array = array();
     if ($request->has('templateid') && !$request->isEmpty('templateid')) {
         $templateid = $request->get('templateid');
         $checkSql = "select module from vtiger_pdfmaker where templateid=?";
         $checkRes = $adb->pquery($checkSql, array($templateid));
         $checkRow = $adb->fetchByAssoc($checkRes);
         //if we are trying to delete template that is not allowed for current user then die because user should not be able to see the template
         //$PDFMaker->CheckTemplatePermissions($checkRow["module"], $templateid);
         $Template_Permissions_Data = $PDFMaker->returnTemplatePermissionsData($checkRow["module"], $templateid);
         if ($Template_Permissions_Data["delete"] === false) {
             $this->DieDuePermission();
         }
         $sql = "delete from vtiger_pdfmaker where templateid=?";
         $adb->pquery($sql, array($templateid));
         $sql = "delete from vtiger_pdfmaker_settings where templateid=?";
         $adb->pquery($sql, array($templateid));
     } else {
         $idlist = $request->get('idlist');
         $id_array = explode(';', $idlist);
         $checkSql = "select templateid, module from vtiger_pdfmaker where templateid IN (" . generateQuestionMarks($id_array) . ")";
         $checkRes = $adb->pquery($checkSql, $id_array);
         $checkArr = array();
         while ($checkRow = $adb->fetchByAssoc($checkRes)) {
             $checkArr[$checkRow["templateid"]] = $checkRow["module"];
         }
         for ($i = 0; $i < count($id_array) - 1; $i++) {
             //if we are trying to delete template that is not allowed for current user then die because user should not be able to see the template
             //$PDFMaker->CheckTemplatePermissions($checkArr[$id_array[$i]], $id_array[$i]);
             $Template_Permissions_Data = $PDFMaker->returnTemplatePermissionsData($checkArr[$id_array[$i]], $id_array[$i]);
             if ($Template_Permissions_Data["delete"] === false) {
                 $this->DieDuePermission();
             }
             $sql = "delete from vtiger_pdfmaker where templateid=?";
             $adb->pquery($sql, array($id_array[$i]));
             $sql = "delete from vtiger_pdfmaker_settings where templateid=?";
             $adb->pquery($sql, array($id_array[$i]));
         }
     }
     $ajaxDelete = $request->get('ajaxDelete');
     $listViewUrl = "index.php?module=PDFMaker&view=List";
     if ($ajaxDelete) {
         $response = new Vtiger_Response();
         $response->setResult($listViewUrl);
         return $response;
     } else {
         header("Location: {$listViewUrl}");
     }
 }
Exemple #7
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $adb = PearDatabase::getInstance();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $viewer = $this->getViewer($request);
     $mode = $request->get('mode');
     $viewer->assign("MODE", $mode);
     $viewer->assign("LICENSE", $PDFMaker->GetLicenseKey());
     $viewer->assign("VERSION_TYPE", $PDFMaker->GetVersionType());
     $viewer->view('License.tpl', 'PDFMaker');
 }
Exemple #8
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("DETAIL") == false) {
         $PDFMaker->DieDuePermission();
     }
     $viewer = $this->getViewer($request);
     if ($request->has('templateid') && !$request->isEmpty('templateid')) {
         $pdftemplateResult = $PDFMaker->GetDetailViewData($_REQUEST['templateid']);
         $viewer->assign("TEMPLATEID", $pdftemplateResult["templateid"]);
         $viewer->assign("MODULENAME", getTranslatedString($pdftemplateResult["module"]));
         $viewer->assign("BODY", decode_html($pdftemplateResult["body"]));
         $viewer->assign("HEADER", decode_html($pdftemplateResult["header"]));
         $viewer->assign("FOOTER", decode_html($pdftemplateResult["footer"]));
     }
     $version_type = $PDFMaker->GetVersionType();
     $viewer->assign("VERSION", $version_type . " " . PDFMaker_Version_Helper::$version);
     if ($PDFMaker->CheckPermissions("EDIT") && $PDFMaker->GetVersionType() != "deactivate") {
         $viewer->assign("EDIT", "permitted");
     }
     $category = getParentTab();
     $viewer->assign("CATEGORY", $category);
     $viewer->view('Detail.tpl', 'PDFMaker');
 }
Exemple #9
0
 public function preProcess(Vtiger_Request $request, $display = true)
 {
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $viewer = $this->getViewer($request);
     $moduleName = $request->getModule();
     $viewer->assign('QUALIFIED_MODULE', $moduleName);
     Vtiger_Basic_View::preProcess($request, false);
     $viewer = $this->getViewer($request);
     $moduleName = $request->getModule();
     $linkParams = array('MODULE' => $moduleName, 'ACTION' => $request->get('view'));
     $linkModels = $PDFMaker->getSideBarLinks($linkParams);
     $viewer->assign('QUICK_LINKS', $linkModels);
     $viewer->assign('CURRENT_USER_MODEL', Users_Record_Model::getCurrentUserModel());
     $viewer->assign('CURRENT_VIEW', $request->get('view'));
     if ($display) {
         $this->preProcessDisplay($request);
     }
 }
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $adb = PearDatabase::getInstance();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     //Debugger::GetInstance()->Init();
     $viewer = $this->getViewer($request);
     $permissions = $PDFMaker->GetProfilesPermissions();
     $profilesActions = $PDFMaker->GetProfilesActions();
     $actionEDIT = getActionid($profilesActions["EDIT"]);
     $actionDETAIL = getActionid($profilesActions["DETAIL"]);
     $actionDELETE = getActionid($profilesActions["DELETE"]);
     $actionEXPORT_RTF = getActionid($profilesActions["EXPORT_RTF"]);
     $mode = $request->get('mode');
     $viewer->assign("MODE", $mode);
     $permissionNames = array();
     foreach ($permissions as $profileid => $subArr) {
         $permissionNames[$profileid] = array();
         $profileName = $this->getProfileName($profileid);
         foreach ($subArr as $actionid => $perm) {
             $permStr = $perm == "0" ? 'checked="checked"' : "";
             switch ($actionid) {
                 case $actionEDIT:
                     $permissionNames[$profileid][$profileName]["EDIT"]["name"] = 'priv_chk_' . $profileid . '_' . $actionEDIT;
                     $permissionNames[$profileid][$profileName]["EDIT"]["checked"] = $permStr;
                     break;
                 case $actionDETAIL:
                     $permissionNames[$profileid][$profileName]["DETAIL"]["name"] = 'priv_chk_' . $profileid . '_' . $actionDETAIL;
                     $permissionNames[$profileid][$profileName]["DETAIL"]["checked"] = $permStr;
                     break;
                 case $actionDELETE:
                     $permissionNames[$profileid][$profileName]["DELETE"]["name"] = 'priv_chk_' . $profileid . '_' . $actionDELETE;
                     $permissionNames[$profileid][$profileName]["DELETE"]["checked"] = $permStr;
                     break;
                 case $actionEXPORT_RTF:
                     $permissionNames[$profileid][$profileName]["EXPORT_RTF"]["name"] = 'priv_chk_' . $profileid . '_' . $actionEXPORT_RTF;
                     $permissionNames[$profileid][$profileName]["EXPORT_RTF"]["checked"] = $permStr;
                     break;
             }
         }
     }
     $viewer->assign("PERMISSIONS", $permissionNames);
     $viewer->view('ProfilesPrivilegies.tpl', 'PDFMaker');
 }
 public function process(Vtiger_Request $request)
 {
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $adb = PearDatabase::getInstance();
     $permissions = $PDFMaker->GetProfilesPermissions();
     foreach ($permissions as $profileid => $subArr) {
         foreach ($subArr as $actionid => $perm) {
             $sql = "DELETE FROM vtiger_pdfmaker_profilespermissions WHERE profileid = ? AND operation = ?";
             $adb->pquery($sql, array($profileid, $actionid));
             $priv_chk = $request->get("priv_chk_" . $profileid . "_" . $actionid);
             if ($priv_chk == "on") {
                 $params = array($profileid, $actionid, "0");
             } else {
                 $params = array($profileid, $actionid, "1");
             }
             $sql = "INSERT INTO vtiger_pdfmaker_profilespermissions (profileid, operation, permissions) VALUES(?, ?, ?)";
             $adb->pquery($sql, $params);
         }
     }
     header("Location:index.php?module=PDFMaker&view=ProfilesPrivilegies");
 }
Exemple #12
0
 function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     //parent::process($request);
     $viewer = $this->getViewer($request);
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("EDIT")) {
         $viewer->assign("EXPORT", "yes");
         if ($PDFMaker->GetVersionType() != "deactivate") {
             $viewer->assign("IMPORT", "yes");
         }
     }
     if ($request->get('from_view') == 'Detail' && !$request->isEmpty('from_templateid')) {
         $viewer->assign('ALLOW_SET_AS', 'yes');
         $pdftemplateResult = $PDFMaker->GetDetailViewData($request->get('from_templateid'));
         $viewer->assign("IS_ACTIVE", $pdftemplateResult["is_active"]);
         $viewer->assign("IS_DEFAULT", $pdftemplateResult["is_default"]);
         $viewer->assign("ACTIVATE_BUTTON", $pdftemplateResult["activateButton"]);
         $viewer->assign("DEFAULT_BUTTON", $pdftemplateResult["defaultButton"]);
         $viewer->assign("TEMPLATEID", $request->get('from_templateid'));
     }
     //print_r($_REQUEST);
     $viewer->view('TemplateTools.tpl', 'PDFMaker');
 }
Exemple #13
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $adb = PearDatabase::getInstance();
     $viewer = $this->getViewer($request);
     $extensions = array();
     $link = "index.php?module=PDFMaker&action=IndexAjax&mode=downloadFile&parenttab=Tools&extid=";
     $extname = "CustomerPortal";
     $extensions[$extname]["label"] = "LBL_CUSTOMERPORTAL";
     $extensions[$extname]["desc"] = "LBL_CUSTOMERPORTAL_DESC";
     $extensions[$extname]["exinstall"] = "LBL_CP_EXPRESS_INSTAL_EXT";
     $extensions[$extname]["manual"] = $link . $extname . "&type=manual";
     $extensions[$extname]["download"] = $link . $extname . "&type=download";
     $extensions[$extname]["install"] = "";
     $extname = "Workflow";
     $extensions[$extname]["label"] = "LBL_WORKFLOW";
     $extensions[$extname]["desc"] = "LBL_WORKFLOW_DESC";
     $extensions[$extname]["exinstall"] = "";
     $extensions[$extname]["manual"] = "";
     $extensions[$extname]["download"] = "";
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $control = $PDFMaker->controlWorkflows();
     if ($control) {
         $extensions[$extname]["install_info"] = vtranslate("LBL_WORKFLOWS_ARE_ALREADY_INSTALLED", "PDFMaker");
         $extensions[$extname]["install"] = "";
     } else {
         $extensions[$extname]["install_info"] = "";
         $extensions[$extname]["install"] = $link . $extname . "&type=install";
     }
     $viewer->assign("EXTENSIONS_ARR", $extensions);
     $download_error = $request->get('download_error');
     if (isset($download_error) && $download_error != "") {
         $viewer->assign("ERROR", "true");
     }
     $viewer->view('Extensions.tpl', 'PDFMaker');
 }
Exemple #14
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("DETAIL") == false) {
         $PDFMaker->DieDuePermission();
     }
     $viewer = $this->getViewer($request);
     if ($request->has('templateid') && !$request->isEmpty('templateid')) {
         $pdftemplateResult = $PDFMaker->GetDetailViewData($_REQUEST['templateid']);
         $viewer->assign("FILENAME", $pdftemplateResult["filename"]);
         $viewer->assign("DESCRIPTION", $pdftemplateResult["description"]);
         $viewer->assign("TEMPLATEID", $pdftemplateResult["templateid"]);
         $viewer->assign("MODULENAME", getTranslatedString($pdftemplateResult["module"]));
         $viewer->assign("BODY", decode_html($pdftemplateResult["body"]));
         $viewer->assign("HEADER", decode_html($pdftemplateResult["header"]));
         $viewer->assign("FOOTER", decode_html($pdftemplateResult["footer"]));
         $viewer->assign("IS_ACTIVE", $pdftemplateResult["is_active"]);
         $viewer->assign("IS_DEFAULT", $pdftemplateResult["is_default"]);
         $viewer->assign("ACTIVATE_BUTTON", $pdftemplateResult["activateButton"]);
         $viewer->assign("DEFAULT_BUTTON", $pdftemplateResult["defaultButton"]);
     }
     $version_type = $PDFMaker->GetVersionType();
     $viewer->assign("VERSION", $version_type . " " . PDFMaker_Version_Helper::$version);
     if ($pdftemplateResult["permissions"]["edit"]) {
         //if ($PDFMaker->CheckPermissions("EDIT")) {
         $viewer->assign("EXPORT", "yes");
     }
     if ($PDFMaker->GetVersionType() != "deactivate") {
         if ($pdftemplateResult["permissions"]["edit"]) {
             //if ($PDFMaker->CheckPermissions("EDIT") && $PDFMaker->GetVersionType() != "deactivate") {
             $viewer->assign("EDIT", "permitted");
             $viewer->assign("IMPORT", "yes");
         }
         if ($pdftemplateResult["permissions"]["delete"]) {
             $viewer->assign("DELETE", "permitted");
         }
     }
     //$tool_buttons = Button_Check('PDFMaker');
     //$viewer->assign('CHECK', $tool_buttons);
     $category = getParentTab();
     $viewer->assign("CATEGORY", $category);
     $viewer->view('Detail.tpl', 'PDFMaker');
 }
Exemple #15
0
 public function process(Vtiger_Request $request)
 {
     //Debugger::GetInstance()->Init();
     $AvailableRelModules = array("Accounts", "Contacts", "Leads", "Vendors");
     $current_user = $cu_model = Users_Record_Model::getCurrentUserModel();
     $currentLanguage = Vtiger_Language_Handler::getLanguage();
     $adb = PearDatabase::getInstance();
     $viewer = $this->getViewer($request);
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("DETAIL") == false) {
         $output = '<table border=0 cellspacing=0 cellpadding=5 width=100% align=center bgcolor=white>
           <tr>
             <td class="dvtCellInfo" style="width:100%;border-top:1px solid #DEDEDE;text-align:center;">
               <strong>' . vtranslate("LBL_PERMISSION") . '</strong>
             </td>
           </tr>              		
           </table>';
         die($output);
     }
     $record = $request->get('record');
     $module = getSalesEntityType($record);
     $viewer->assign('MODULE', $module);
     $viewer->assign('ID', $record);
     $relfocus = CRMEntity::getInstance($module);
     $relfocus->id = $record;
     $relfocus->retrieve_entity_info($relfocus->id, $module);
     $relmodule = "";
     $relmodule_selid = "";
     if (in_array($module, $AvailableRelModules)) {
         $relmodule = $module;
         $relmodule_selid = $relfocus->id;
     } else {
         if (isset($relfocus->column_fields['account_id']) && $relfocus->column_fields['account_id'] != "" && $relfocus->column_fields['account_id'] != "0") {
             $relmodule = 'Accounts';
             $relmodule_selid = $relfocus->column_fields['account_id'];
         }
         if ($relmodule == "" && isset($relfocus->column_fields['related_to']) && $relfocus->column_fields['related_to'] != "" && $relfocus->column_fields['related_to'] != "0") {
             $relmodule_selid = $relfocus->column_fields['related_to'];
             $relmodule = getSalesEntityType($relmodule_selid);
             if (!in_array($relmodule, $AvailableRelModules)) {
                 $relmodule = $relmodule_selid = "";
             }
         }
         if ($relmodule == "" && isset($relfocus->column_fields['parent_id']) && $relfocus->column_fields['parent_id'] != "" && $relfocus->column_fields['parent_id'] != "0") {
             $relmodule_selid = $relfocus->column_fields['parent_id'];
             $relmodule = getSalesEntityType($relmodule_selid);
             if (!in_array($relmodule, $AvailableRelModules)) {
                 $relmodule = $relmodule_selid = "";
             }
         }
         if ($relmodule == "" && isset($relfocus->column_fields['contact_id']) && $relfocus->column_fields['contact_id'] != "" && $relfocus->column_fields['contact_id'] != "0") {
             $relmodule = 'Contacts';
             $relmodule_selid = $relfocus->column_fields['contact_id'];
         }
     }
     $viewer->assign('RELMODULE', $relmodule);
     $viewer->assign('RELMODULE_SELID', $relmodule_selid);
     require 'user_privileges/user_privileges_' . $current_user->id . '.php';
     if (is_dir("modules/PDFMaker/resources/mpdf") && $PDFMaker->CheckPermissions("DETAIL")) {
         $viewer->assign("ENABLE_PDFMAKER", 'true');
     } else {
         $viewer->assign("ENABLE_PDFMAKER", "false");
     }
     if (is_dir("modules/EMAILMaker") && vtlib_isModuleActive('EMAILMaker')) {
         $module_tabid = getTabId($module);
         $res = $adb->pquery("SELECT * FROM vtiger_links WHERE tabid = ? AND linktype = ? AND linkurl LIKE ?", array($module_tabid, 'DETAILVIEWSIDEBARWIDGET', 'module=EMAILMaker&view=GetEMAILActions&record=%'));
         if ($adb->num_rows($res) > 0) {
             $viewer->assign("ENABLE_EMAILMAKER", 'true');
         }
     }
     $viewer->assign('PDFMAKER_MOD', return_module_language($currentLanguage, "PDFMaker"));
     if (!isset($_SESSION["template_languages"]) || $_SESSION["template_languages"] == "") {
         $temp_res = $adb->pquery("SELECT label, prefix FROM vtiger_language WHERE active = ?", array('1'));
         while ($temp_row = $adb->fetchByAssoc($temp_res)) {
             $template_languages[$temp_row["prefix"]] = $temp_row["label"];
         }
         $_SESSION["template_languages"] = $template_languages;
     }
     $viewer->assign('TEMPLATE_LANGUAGES', $_SESSION["template_languages"]);
     $viewer->assign('CURRENT_LANGUAGE', $currentLanguage);
     $viewer->assign('IS_ADMIN', is_admin($current_user));
     $templates = $PDFMaker->GetAvailableTemplates($module);
     if (count($templates) > 0) {
         $no_templates_exist = 0;
     } else {
         $no_templates_exist = 1;
     }
     $viewer->assign('CRM_TEMPLATES', $templates);
     $viewer->assign('CRM_TEMPLATES_EXIST', $no_templates_exist);
     //Action permission handling
     //edit and export
     $editAndExportAction = "1";
     if (isPermitted($module, "EditView", $record) == "no") {
         $editAndExportAction = "0";
     }
     //save as doc
     $saveDocAction = "1";
     if (isPermitted("Documents", "EditView") == "no") {
         $saveDocAction = "0";
     }
     //send email with pdf
     $sendEmailPDF = "1";
     if (isPermitted("Emails", "") == "no" && isPermitted("MailManager", "") == "no") {
         $sendEmailPDF = "0";
     }
     if (is_dir("modules/EMAILMaker") && vtlib_isModuleActive('EMAILMaker')) {
         if (isPermitted("EMAILMaker", "") == "no" && ($sendEmailPDF = "0")) {
             $sendEmailPDF = "0";
         } else {
             $sendEmailPDF = "1";
         }
     }
     $viewer->assign("EDIT_AND_EXPORT_ACTION", $editAndExportAction);
     $viewer->assign("SAVE_AS_DOC_ACTION", $saveDocAction);
     $viewer->assign("SEND_EMAIL_PDF_ACTION", $sendEmailPDF);
     $viewer->view("GetPDFActions.tpl", 'PDFMaker');
 }
 /**
  * @param $context VTEntity
  */
 public function handleTask(&$context)
 {
     if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) {
         return 'yes';
     }
     global $adb, $current_user, $log, $root_directory;
     // PDFMaker greift auf Datenbank zurück. Daher zuerst speichern!
     $context->save();
     $userId = $context->get('assigned_user_id');
     if ($userId === null) {
         $userId = vtws_getWebserviceEntityId('Users', 1);
     }
     $moduleName = $context->getModuleName();
     $id = $context->getId();
     list($id2, $assigned_user_id) = explode("x", $userId);
     $parentid = $id;
     require_once 'modules/Documents/Documents.php';
     $focus = new \Documents();
     $focus->parentid = $parentid;
     $modFocus = $context->getInternalObject();
     $templateid = $this->template;
     $this->folder = 1;
     $foldername = $adb->getOne("SELECT foldername FROM vtiger_attachmentsfolder WHERE folderid='" . $this->folder . "'", 0, "foldername");
     $fieldname = $adb->getOne("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($moduleName), 0, "fieldname");
     /* new PDFMaker Routine */
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") {
         $file_name = $PDFMaker->generate_cool_uri($modFocus->column_fields[$fieldname]) . ".pdf";
     } else {
         $file_name = generate_cool_uri($foldername . "_" . $templateid . $focus->parentid . date("ymdHi")) . ".pdf";
     }
     $this->addStat("Attach Document '" . $file_name . "'");
     $docTitle = $this->get("documenttitle", $context);
     $docDescr = $this->get("documentdescr", $context);
     $focus->column_fields['notes_title'] = $docTitle;
     $focus->column_fields['assigned_user_id'] = $assigned_user_id;
     $focus->column_fields['filename'] = $file_name;
     $focus->column_fields['notecontent'] = $docDescr;
     $focus->column_fields['filetype'] = 'application/pdf';
     $focus->column_fields['filesize'] = '';
     $focus->column_fields['filelocationtype'] = 'I';
     $focus->column_fields['fileversion'] = '';
     $focus->column_fields['filestatus'] = 'on';
     $focus->column_fields['folderid'] = $this->get("folderid");
     $focus->save('Documents');
     $language = $current_user->language;
     $request = $_REQUEST;
     $_REQUEST['search'] = true;
     $_REQUEST['submode'] = true;
     if ($current_user->is_admin != "on") {
         $useUser = Users::getActiveAdminUser();
     } else {
         $useUser = $current_user;
     }
     $oldCurrentUser = $current_user;
     $current_user = $useUser;
     $dummyRequest = new Vtiger_Request(array());
     $PDFMaker->createPDFAndSaveFile($dummyRequest, $this->get("template"), $focus, $modFocus, $file_name, $this->getModuleName(), $language);
     $current_user = $oldCurrentUser;
     $_REQUEST = $request;
     /* new PDFMaker Routine */
     $overwriteFilename = $this->get("filename", $context);
     if ($overwriteFilename != -1 && !empty($overwriteFilename)) {
         global $root_directory;
         $sql = "SELECT attachmentsid FROM vtiger_seattachmentsrel WHERE crmid = " . $focus->id . " ORDER BY attachmentsid DESC LIMIT 1";
         $result = $adb->query($sql);
         if ($adb->num_rows($result) > 0) {
             $attachmentsid = $adb->query_result($result, 0, "attachmentsid");
             $attRst = $adb->query("SELECT * FROM vtiger_attachments WHERE attachmentsid = " . $attachmentsid);
             $attachment = $adb->fetchByAssoc($attRst);
             $oldFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $attachment["name"];
             $newFilename = $root_directory . "/" . $attachment["path"] . $attachmentsid . "_" . $overwriteFilename;
             @rename($oldFilename, $newFilename);
             $adb->pquery("UPDATE vtiger_attachments SET name = ? WHERE attachmentsid = " . $attachmentsid, array($overwriteFilename));
             $adb->pquery("UPDATE vtiger_notes SET filename = ? WHERE notesid = " . $focus->id, array($overwriteFilename));
         }
         $file_name = $foldername . "_" . $overwriteFilename;
     }
     $_REQUEST = $request;
     if ($this->get("createrel") === "1") {
         $sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $context->getId() . ", notesid = " . $focus->id;
         $adb->query($sql);
     } else {
         $sql = "DELETE FROM vtiger_senotesrel WHERE crmid = " . $context->getId() . " AND notesid = " . $focus->id;
         $adb->query($sql);
     }
     $newContext = \Workflow\VTEntity::getForId($focus->id, "Documents");
     if ($this->get("workflow") !== "") {
         $objWorkflow = new \Workflow\Main($this->get("workflow"), false, $context->getUser());
         $objWorkflow->setContext($newContext);
         $objWorkflow->isSubWorkflow(true);
         $objWorkflow->start();
     }
     $context->setEnvironment("new_record_id", $newContext->getWsId(), $this);
     return "yes";
 }
Exemple #17
0
    public function getList(Vtiger_Request $request) {

        PDFMaker_Debugger_Model::GetInstance()->Init();

        $PDFMaker = new PDFMaker_PDFMaker_Model();
        
        if ($PDFMaker->CheckPermissions("DETAIL") == false)
            $PDFMaker->DieDuePermission();

        $viewer = $this->getViewer($request);
        $orderby = "templateid";
        $dir = "asc";

        if (isset($_REQUEST["dir"]) && $_REQUEST["dir"] == "desc")
            $dir = "desc";

        if (isset($_REQUEST["orderby"])) {
            switch ($_REQUEST["orderby"]) {
                case "name":
                    $orderby = "filename";
                    break;

                case "module":
                    $orderby = "module";
                    break;

                case "description":
                    $orderby = "description";
                    break;

                case "order":
                    $orderby = "order";
                    break;
                default:
                    $orderby = $_REQUEST["orderby"];
                    break;
            }
        }

        $version_type = $PDFMaker->GetVersionType();
        $license_key = $PDFMaker->GetLicenseKey();

        $viewer->assign("VERSION_TYPE", $version_type);
        $viewer->assign("VERSION", ucfirst($version_type) . " " . PDFMaker_Version_Helper::$version);
    
        if ($PDFMaker->CheckPermissions("EDIT")) {
            $viewer->assign("EDIT", "permitted");
        }

        $notif = $PDFMaker->GetReleasesNotif();
        $viewer->assign("RELEASE_NOTIF", $notif);

        $php_version = phpversion();
        $notif = false;
        $max_in_vars = ini_get("max_input_vars");
        if ($max_in_vars <= 1000 && $php_version >= "5.3.9")
            $notif = true;

        $test = ini_set("memory_limit", "256M");
        $memory_limit = ini_get("memory_limit");
        if (substr($memory_limit, 0, -1) <= 128)
            $notif = true;

        $max_exec_time = ini_get("max_execution_time");
        if ($max_exec_time <= 60)
            $notif = true;

        if (extension_loaded('suhosin')) {
            $request_max_vars = ini_get("suhosin.request.max_vars");
            $post_max_vars = ini_get("suhosin.post.max_vars");
            if ($request_max_vars <= 1000)
                $notif = true;
            if ($post_max_vars <= 1000)
                $notif = true;
        }

        $viewer->assign("MOD", $mod_strings);
        $viewer->assign("APP", $app_strings);
        $viewer->assign("THEME", $theme);
        $viewer->assign("PARENTTAB", getParentTab());
        $viewer->assign("IMAGE_PATH", $image_path);

        $return_data = $PDFMaker->GetListviewData($orderby, $dir);
        $viewer->assign("PDFTEMPLATES", $return_data);
        $category = getParentTab();
        $viewer->assign("CATEGORY", $category);

        if (is_admin($current_user)) {
            $viewer->assign('IS_ADMIN', '1');
        }
        
        $linkModels = $PDFMaker->getListViewLinks($linkParams);
        $viewer->assign('LISTVIEW_LINKS', $linkModels);
        
        $tpl = "ListPDFTemplates";
        if ($request->get('ajax') == "true")
            $tpl .= "Contents";

        $viewer->view($tpl.".tpl", 'PDFMaker');
    }
 function process(Vtiger_Request $request)
 {
     $Vtiger_Utils_Log = true;
     include_once 'vtlib/Vtiger/Module.php';
     $adb = PearDatabase::getInstance();
     $module = Vtiger_Module::getInstance('PDFMaker');
     if ($module) {
         $PDFMakerModel = new PDFMaker_PDFMaker_Model();
         $request->set('key', $PDFMakerModel->GetLicenseKey());
         $PDFMaker_License_Action_Model = new PDFMaker_License_Action();
         $PDFMaker_License_Action_Model->deactivateLicense($request);
         $module->delete();
         @shell_exec('rm -r modules/PDFMaker');
         @shell_exec('rm -r layouts/vlayout/modules/PDFMaker');
         @shell_exec('rm -f languages/ae_ae/PDFMaker.php');
         @shell_exec('rm -f languages/cz_cz/PDFMaker.php');
         @shell_exec('rm -f languages/de_de/PDFMaker.php');
         @shell_exec('rm -f languages/en_gb/PDFMaker.php');
         @shell_exec('rm -f languages/en_us/PDFMaker.php');
         @shell_exec('rm -f languages/es_es/PDFMaker.php');
         @shell_exec('rm -f languages/es_mx/PDFMaker.php');
         @shell_exec('rm -f languages/fr_fr/PDFMaker.php');
         @shell_exec('rm -f languages/hi_hi/PDFMaker.php');
         @shell_exec('rm -f languages/hu_hu/PDFMaker.php');
         @shell_exec('rm -f languages/it_it/PDFMaker.php');
         @shell_exec('rm -f languages/nl_nl/PDFMaker.php');
         @shell_exec('rm -f languages/pl_pl/PDFMaker.php');
         @shell_exec('rm -f languages/pt_br/PDFMaker.php');
         @shell_exec('rm -f languages/ro_ro/PDFMaker.php');
         @shell_exec('rm -f languages/ru_ru/PDFMaker.php');
         @shell_exec('rm -f languages/sk_sk/PDFMaker.php');
         @shell_exec('rm -f languages/sv_se/PDFMaker.php');
         @shell_exec('rm -f languages/tr_tr/PDFMaker.php');
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_seq", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_settings", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_breakline", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_images", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_releases", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_userstatus", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblocks", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblocks_seq", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblockcol", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblockcriteria", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblockcriteria_g", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblockdatefilter", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_relblocksortcol", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_productbloc_tpl", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_ignorepicklistvalues", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_license", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_version", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_profilespermissions", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_sharing", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_labels", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_label_keys", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_label_vals", array());
         $adb->pquery("DROP TABLE IF EXISTS vtiger_pdfmaker_usersettings", array());
         $result = array('success' => true);
     } else {
         $result = array('success' => false);
     }
     ob_clean();
     $response = new Vtiger_Response();
     $response->setResult($result);
     $response->emit();
 }
 public function doTask($entityData)
 {
     global $current_user, $log, $root_directory;
     $request = new Vtiger_Request($_REQUEST, $_REQUEST);
     $adb = PearDatabase::getInstance();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $userId = $entityData->get('assigned_user_id');
     if ($userId === null) {
         $userId = vtws_getWebserviceEntityId('Users', 1);
     }
     $moduleName = $entityData->getModuleName();
     $adminUser = $this->getAdmin();
     $id = $entityData->getId();
     list($id2, $assigned_user_id) = explode("x", $userId);
     list($id3, $parentid) = explode("x", $id);
     $focus = CRMEntity::getInstance("Documents");
     $focus->parentid = $parentid;
     $modFocus = CRMEntity::getInstance($moduleName);
     if (isset($focus->parentid)) {
         $modFocus->retrieve_entity_info($focus->parentid, $moduleName);
         $modFocus->id = $focus->parentid;
     }
     $templateid = $this->template;
     if ($templateid != "" && $templateid != "0") {
         if ($PDFMaker->isTemplateDeleted($templateid)) {
             return;
         }
         $foldername = $adb->getOne("SELECT foldername FROM vtiger_attachmentsfolder WHERE folderid='" . $this->folder . "'", 0, "foldername");
         $fieldname = $adb->getOne("SELECT fieldname FROM vtiger_field WHERE uitype=4 AND tabid=" . getTabId($moduleName), 0, "fieldname");
         if (isset($modFocus->column_fields[$fieldname]) && $modFocus->column_fields[$fieldname] != "") {
             $file_name = $PDFMaker->generate_cool_uri($foldername . "_" . $modFocus->column_fields[$fieldname]) . ".pdf";
         } else {
             $file_name = $PDFMaker->generate_cool_uri($foldername . "_" . $templateid . $focus->parentid . date("ymdHi")) . ".pdf";
         }
         $focus->column_fields['notes_title'] = $this->title;
         $focus->column_fields['assigned_user_id'] = $assigned_user_id;
         $focus->column_fields['filename'] = $file_name;
         $focus->column_fields['notecontent'] = $this->description;
         $focus->column_fields['filetype'] = 'application/pdf';
         $focus->column_fields['filesize'] = '';
         $focus->column_fields['filelocationtype'] = 'I';
         $focus->column_fields['fileversion'] = '';
         $focus->column_fields['filestatus'] = 'on';
         $focus->column_fields['folderid'] = $this->folder;
         $focus->save('Documents');
         $language = $this->template_language;
         $PDFMaker->createPDFAndSaveFile($request, $templateid, $focus, $modFocus, $file_name, $moduleName, $language);
     }
 }
Exemple #20
0
    public function process(Vtiger_Request $request)
    {
        $moduleName = $request->getModule();
        $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
        $for_module = $request->get('return_module');
        $recordIds = $this->getRecordsListFromRequest($request);
        $adb = PearDatabase::getInstance();
        PDFMaker_Debugger_Model::GetInstance()->Init();
        $PDFMaker = new PDFMaker_PDFMaker_Model();
        if ($PDFMaker->CheckPermissions("DETAIL") == false) {
            $close_img = vimage_path('close.gif');
            $output = '
                <table border=0 cellspacing=0 cellpadding=5 width=100% class=layerHeadingULine>
                <tr>
                      <td width="90%" align="left" class="genHeaderSmall" id="PDFListViewDivHandle" style="cursor:move;">' . vtranslate("LBL_PDF_ACTIONS", "PDFMaker") . '                 			
                      </td>
                      <td width="10%" align="right">
                              <a href="javascript:fninvsh(\'PDFListViewDiv\');"><img title="' . vtranslate("LBL_CLOSE") . '" alt="' . vtranslate("LBL_CLOSE") . '" src="' . $close_img . '" border="0"  align="absmiddle" /></a>
                      </td>
                </tr>
                </table>
                <table border=0 cellspacing=0 cellpadding=5 width=100% align=center>
                    <tr><td class="small">
                        <table border=0 cellspacing=0 cellpadding=5 width=100% align=center bgcolor=white>
                        <tr>
                          <td class="dvtCellInfo" style="width:100%;border-top:1px solid #DEDEDE;text-align:center;">
                            <strong>' . vtranslate("LBL_PERMISSION_DENIED") . '</strong>
                          </td>
                        </tr>
                        <tr>
                                      <td class="dvtCellInfo" style="width:100%;" align="center">
                            <input type="button" class="crmbutton small cancel" value="' . vtranslate("LBL_CANCEL") . '" onclick="fninvsh(\'PDFListViewDiv\');" />      
                          </td>
                              </tr>      		
                        </table>
                    </td></tr>
                </table>
                ';
            die($output);
        }
        $_REQUEST['idslist'] = implode(";", $recordIds);
        $request->set('idlist', $_REQUEST['idslist']);
        //$language = $_SESSION['authenticated_user_language'];
        $current_language = Vtiger_Language_Handler::getLanguage();
        $templates = $PDFMaker->GetAvailableTemplates($for_module, true);
        $options = "";
        foreach ($templates as $templateid => $valArr) {
            if ($valArr["is_default"] == "2" || $valArr["is_default"] == "3") {
                $selected = ' selected="selected" ';
            } else {
                $selected = "";
            }
            $options .= '<option value="' . $templateid . '"' . $selected . '>' . $valArr['templatename'] . '</option>';
        }
        $template_output = "";
        $language_output = "";
        $generate_pdf = "";
        if ($options != "") {
            $template_output = '
		    <tr>
		  		<td class="dvtCellInfo" style="width:100%;border-top:1px solid #DEDEDE;">
		  			<select name="use_common_template" id="use_common_template" class="detailedViewTextBox" multiple style="width:90%;" size="5">
		        ' . $options . '
		        </select>
		  		</td>
				</tr>
		  ';
            $templates_select = '<select name="use_common_template" id="use_common_template" style="display: none;" id="fieldList" class="select2 row-fluid" multiple="true" size="5" data-validation-engine="validate[required]">
		        ' . $options . '
		        </select>';
            $temp_res = $adb->pquery("SELECT label, prefix FROM vtiger_language WHERE active=?", array("1"));
            while ($temp_row = $adb->fetchByAssoc($temp_res)) {
                $template_languages[$temp_row["prefix"]] = $temp_row["label"];
            }
            //LANGUAGES BLOCK
            if (count($template_languages) > 1) {
                $options = "";
                foreach ($template_languages as $prefix => $label) {
                    if ($current_language != $prefix) {
                        $options .= '<option value="' . $prefix . '">' . $label . '</option>';
                    } else {
                        $options .= '<option value="' . $prefix . '" selected="selected">' . $label . '</option>';
                    }
                }
                $language_output = '
		      <tr>
		  		<td class="dvtCellInfo" style="width:100%;">    	
		          <select name="template_language" id="template_language" class="detailedViewTextBox" style="width:90%;" size="1">
		  		    ' . $options . '
		          </select>
		  		</td>
		      </tr>';
                $languages_select = '<select name="template_language" id="template_language" class="select2 row-fluid" style="display: none;">
		  		    ' . $options . '
		          </select>';
            } else {
                foreach ($template_languages as $prefix => $label) {
                    $languages_select .= '<input type="hidden" name="template_language" id="template_language" value="' . $prefix . '"/>';
                }
            }
        } else {
            $template_output = '<tr>
		                		<td class="dvtCellInfo" style="width:100%;border-top:1px solid #DEDEDE;">
		                		  ' . vtranslate("CRM_TEMPLATES_DONT_EXIST", "PDFMaker");
            //   if(isPermitted("PDFMaker","EditView") == 'yes')
            if ($PDFMaker->CheckPermissions("EDIT")) {
                $template_output .= '<br />' . vtranslate("CRM_TEMPLATES_ADMIN", "PDFMaker") . '
		                      <a href="index.php?module=PDFMaker&action=EditPDFTemplate&return_module=' . $request->get("return_module") . '&parenttab=Tools" class="webMnu">' . vtranslate("TEMPLATE_CREATE_HERE", "PDFMaker") . '</a>';
            }
            $template_output .= '</td></tr>';
        }
        $viewer = $this->getViewer($request);
        //$viewer->assign('MODULE', $relmodule);
        //$viewer->assign('ID', $record);
        $viewer->assign('templates_select', $templates_select);
        $viewer->assign('languages_select', $languages_select);
        $viewer->assign('idslist', $_REQUEST['idslist']);
        $viewer->assign('relmodule', $request->get('return_module'));
        $viewer->view("ListViewSelect.tpl", 'PDFMaker');
    }
Exemple #21
0
 function showCustomLabelValues(Vtiger_Request $request)
 {
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $viewer = $this->getViewer($request);
     list($oLabels, $languages) = $PDFMaker->GetCustomLabels();
     $labelid = $request->get('labelid');
     $currLangId = $request->get('langid');
     $oLbl = $oLabels[$labelid];
     $key = $oLbl->GetKey();
     $viewer->assign("LBLKEY", $key);
     $viewer->assign("LABELID", $langid);
     $viewer->assign("LANGID", $currLangId);
     $label_id = $labelid;
     $langValsArr = $oLbl->GetLangValsArr();
     $newLangValsArr = array();
     foreach ($langValsArr as $langId => $langVal) {
         if ($langId == $currLangId) {
             continue;
         }
         $label = $languages[$langId]["label"];
         $newLangValsArr[] = array("id" => $langId, "value" => $langVal, "label" => $label);
     }
     $viewer->assign("LANGVALSARR", $newLangValsArr);
     echo $viewer->view('ShowCustomLabelValues.tpl', 'PDFMaker', true);
 }
 public function getTemplates($selected_module)
 {
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $templates = $PDFMaker->GetAvailableTemplates($selected_module);
     $def_template = array();
     $fieldvalue = array();
     if ($PDFMaker->CheckPermissions("DETAIL") !== false) {
         foreach ($templates as $templateid => $valArr) {
             if ($valArr["is_default"] == "1" || $valArr["is_default"] == "3") {
                 $def_template[$templateid] = $valArr["templatename"];
             } else {
                 $fieldvalue[$templateid] = $valArr["templatename"];
             }
         }
         if (count($def_template) > 0) {
             $fieldvalue = (array) $def_template + (array) $fieldvalue;
         }
     }
     return $fieldvalue;
 }
Exemple #23
0
 public function installExtension(Vtiger_Request $request)
 {
     $extname = $request->get("extname");
     if ($extname == "Workflow") {
         $Errors = array();
         include_once 'modules/PDFMaker/PDFMaker.php';
         $PDFMaker = new PDFMaker();
         $PDFMakerModel = new PDFMaker_PDFMaker_Model();
         $Workflows = $PDFMakerModel->GetWorkflowsList();
         foreach ($Workflows as $name) {
             $folder_dest1 = "modules/com_vtiger_workflow/tasks/";
             $dest1 = $folder_dest1 . $name . ".inc";
             $source1 = "modules/PDFMaker/workflow/" . $name . ".inc";
             if (!file_exists($dest1)) {
                 if (!copy($source1, $dest1)) {
                     $Errors[] = vtranslate("LBL_PERMISSION_ERROR_PART_1", "PDFMaker") . ' "' . $source1 . '" ' . vtranslate("LBL_PERMISSION_ERROR_PART_2", "PDFMaker") . ' "' . $folder_dest1 . '" ' . vtranslate("LBL_PERMISSION_ERROR_PART_3", "PDFMaker") . '.';
                 }
             }
             $folder_dest2 = "layouts/vlayout/modules/Settings/Workflows/Tasks/";
             $dest2 = $folder_dest2 . $name . ".tpl";
             $source2 = "layouts/vlayout/modules/PDFMaker/taskforms/" . $name . ".tpl";
             if (!file_exists($dest2)) {
                 if (!copy($source2, $dest2)) {
                     $Errors[] = vtranslate("LBL_PERMISSION_ERROR_PART_1", "PDFMaker") . ' "' . $source2 . '" ' . vtranslate("LBL_PERMISSION_ERROR_PART_2", "PDFMaker") . ' "' . $folder_dest2 . '" ' . vtranslate("LBL_PERMISSION_ERROR_PART_3", "PDFMaker") . '.';
                 }
             }
         }
         if (count($Errors) > 0) {
             $error = '<div class="modelContainer">';
             $error .= '<div class="modal-header">';
             $error .= '<button class="close vtButton" data-dismiss="modal">×</button>';
             $error .= '<h3 class="redColor">';
             $error .= vtranslate("LBL_INSTALLATION_FAILED", "PDFMaker");
             $error .= '</h3>';
             $error .= '</div>';
             $error .= '<div class="modal-body">';
             $error .= implode("<br>", $Errors);
             $error .= "<br><br>" . vtranslate("LBL_CHANGE_PERMISSION", "PDFMaker");
             $error .= '</div>';
             $error .= '</div>';
         } else {
             $PDFMaker->installWorkflows();
             $control = $PDFMakerModel->controlWorkflows();
             if (!$control) {
                 $error = vtranslate("LBL_INSTALLATION_FAILED", "PDFMaker");
             }
         }
         if ($error == "") {
             $result = array('success' => true, 'message' => vtranslate("LBL_WORKFLOWS_ARE_ALREADY_INSTALLED", "PDFMaker"));
         } else {
             $result = array('success' => false, 'message' => vtranslate($error, 'PDFMaker'));
         }
     } else {
         $result = array('success' => false);
     }
     $response = new Vtiger_Response();
     $response->setResult($result);
     $response->emit();
 }
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $adb = PearDatabase::getInstance();
     $cu_model = Users_Record_Model::getCurrentUserModel();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $S_Data = $request->getAll();
     $filename = $request->get('filename');
     $modulename = $request->get('modulename');
     $templateid = $request->get('templateid');
     $description = $request->get('description');
     $body = $S_Data['body'];
     $pdf_format = $request->get('pdf_format');
     $pdf_orientation = $request->get('pdf_orientation');
     $owner = $request->get('template_owner');
     $sharingtype = $request->get('sharing');
     //vtiger_pdfmaker_user_status
     $is_active = $request->get('is_active');
     $is_default_dv = $request->get('is_default_dv');
     $is_default_lv = $request->get('is_default_lv');
     $is_portal = $request->get('is_portal');
     $is_listview = $request->get('is_listview');
     if ($is_default_dv != "") {
         $is_default_dv = "1";
     } else {
         $is_default_dv = "0";
     }
     if ($is_default_lv != "") {
         $is_default_lv = "1";
     } else {
         $is_default_lv = "0";
     }
     if ($is_portal != "") {
         $is_portal = "1";
     } else {
         $is_portal = "0";
     }
     if ($is_listview != "") {
         $is_listview = "1";
     } else {
         $is_listview = "0";
     }
     $order = $request->get('tmpl_order');
     $dh_first = $request->get('dh_first');
     $dh_other = $request->get('dh_other');
     $df_first = $request->get('df_first');
     $df_last = $request->get('df_last');
     $df_other = $request->get('df_other');
     if ($dh_first != "") {
         $dh_first = "1";
     } else {
         $dh_first = "0";
     }
     if ($dh_other != "") {
         $dh_other = "1";
     } else {
         $dh_other = "0";
     }
     if ($df_first != "") {
         $df_first = "1";
     } else {
         $df_first = "0";
     }
     if ($df_last != "") {
         $df_last = "1";
     } else {
         $df_last = "0";
     }
     if ($df_other != "") {
         $df_other = "1";
     } else {
         $df_other = "0";
     }
     if (isset($templateid) && $templateid != '') {
         $sql = "update vtiger_pdfmaker set filename =?, module =?, description =?, body =? where templateid =?";
         $params = array($filename, $modulename, $description, $body, $templateid);
         $adb->pquery($sql, $params);
         $sql2 = "DELETE FROM vtiger_pdfmaker_settings WHERE templateid =?";
         $params2 = array($templateid);
         $adb->pquery($sql2, $params2);
         $sql21 = "DELETE FROM vtiger_pdfmaker_userstatus WHERE templateid=? AND userid=?";
         $adb->pquery($sql21, array($templateid, $cu_model->id));
     } else {
         $templateid = $adb->getUniqueID('vtiger_pdfmaker');
         $sql3 = "insert into vtiger_pdfmaker (filename,module,description,body,deleted,templateid) values (?,?,?,?,?,?)";
         $params3 = array($filename, $modulename, $description, $body, 0, $templateid);
         $adb->pquery($sql3, $params3);
     }
     $margin_top = $request->get('margin_top');
     if ($margin_top < 0) {
         $margin_top = 0;
     }
     $margin_bottom = $request->get('margin_bottom');
     if ($margin_bottom < 0) {
         $margin_bottom = 0;
     }
     $margin_left = $request->get('margin_left');
     if ($margin_left < 0) {
         $margin_left = 0;
     }
     $margin_right = $request->get('margin_right');
     if ($margin_right < 0) {
         $margin_right = 0;
     }
     $dec_point = $request->get('dec_point');
     $dec_decimals = $request->get('dec_decimals');
     $dec_thousands = $request->get('dec_thousands');
     if ($dec_thousands == " ") {
         $dec_thousands = "sp";
     }
     $header = $S_Data['header_body'];
     $footer = $S_Data['footer_body'];
     $encoding = $request->get('encoding');
     if ($encoding == "") {
         $encoding = "auto";
     }
     $nameOfFile = $request->get('nameOfFile');
     // ITS4YOU-CR VlZa
     //in case of allowed module make sure that only one template from that module is set for portal
     if (($modulename == "Invoice" || $modulename == "Quotes") && $is_portal == "1") {
         $sql4a = "UPDATE vtiger_pdfmaker_settings \n            INNER JOIN vtiger_pdfmaker \n              USING(templateid)\n            SET is_portal = '0' \n            WHERE is_portal = '1'\n              AND module=?";
         $params4a = array($modulename);
         $adb->pquery($sql4a, $params4a);
     }
     if ($pdf_format == "Custom") {
         $pdf_cf_width = $request->get('pdf_format_width');
         $pdf_cf_height = $request->get('pdf_format_height');
         $pdf_format = $pdf_cf_width . ";" . $pdf_cf_height;
     }
     $disp_header = base_convert($dh_first . $dh_other, 2, 10);
     $disp_footer = base_convert($df_first . $df_last . $df_other, 2, 10);
     $sql4 = "INSERT INTO vtiger_pdfmaker_settings (templateid, margin_top, margin_bottom, margin_left, margin_right, format, orientation, \n                                               decimals, decimal_point, thousands_separator, header, footer, encoding, file_name, is_portal,\n                                               is_listview, owner, sharingtype, disp_header, disp_footer)\n         VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
     $params4 = array($templateid, $margin_top, $margin_bottom, $margin_left, $margin_right, $pdf_format, $pdf_orientation, $dec_decimals, $dec_point, $dec_thousands, $header, $footer, $encoding, $nameOfFile, $is_portal, $is_listview, $owner, $sharingtype, $disp_header, $disp_footer);
     $adb->pquery($sql4, $params4);
     // ITS4YOU-END
     //ignored picklist values
     $adb->pquery("DELETE FROM vtiger_pdfmaker_ignorepicklistvalues", array());
     $ignore_picklist_values = $request->get('ignore_picklist_values');
     $pvvalues = explode(",", $ignore_picklist_values);
     foreach ($pvvalues as $value) {
         $adb->pquery("INSERT INTO vtiger_pdfmaker_ignorepicklistvalues(value) VALUES(?)", array(trim($value)));
     }
     // end ignored picklist values
     //unset the former default template because only one template can be default per user x module
     $is_default_bin = $is_default_lv . $is_default_dv;
     $is_default_dec = intval(base_convert($is_default_bin, 2, 10));
     // convert binary format xy to decimal; where x stands for is_default_lv and y stands for is_default_dv
     if ($is_default_dec > 0) {
         $sql5 = "UPDATE vtiger_pdfmaker_userstatus\n            INNER JOIN vtiger_pdfmaker USING(templateid)\n            SET is_default=?\n            WHERE is_default=? AND userid=? AND module=?";
         switch ($is_default_dec) {
             //      in case of only is_default_dv is checked
             case 1:
                 $adb->pquery($sql5, array("0", "1", $cu_model->id, $modulename));
                 $adb->pquery($sql5, array("2", "3", $cu_model->id, $modulename));
                 break;
                 //      in case of only is_default_lv is checked
             //      in case of only is_default_lv is checked
             case 2:
                 $adb->pquery($sql5, array("0", "2", $cu_model->id, $modulename));
                 $adb->pquery($sql5, array("1", "3", $cu_model->id, $modulename));
                 break;
                 //      in case of both is_default_* are checked
             //      in case of both is_default_* are checked
             case 3:
                 $sql5 = "UPDATE vtiger_pdfmaker_userstatus\n                    INNER JOIN vtiger_pdfmaker USING(templateid)\n                    SET is_default=?\n                    WHERE is_default > ? AND userid=? AND module=?";
                 $adb->pquery($sql5, array("0", "0", $cu_model->id, $modulename));
         }
     }
     $sql6 = "INSERT INTO vtiger_pdfmaker_userstatus(templateid, userid, is_active, is_default, sequence) VALUES(?,?,?,?,?)";
     $adb->pquery($sql6, array($templateid, $cu_model->id, $is_active, $is_default_dec, $order));
     //SHARING
     $sql7 = "DELETE FROM vtiger_pdfmaker_sharing WHERE templateid=?";
     $adb->pquery($sql7, array($templateid));
     $selected_col_string = $request->get('sharingSelectedColumnsString');
     if ($sharingtype == "share" && $selected_col_string != "") {
         $member_array = explode(';', $selected_col_string);
         $groupMemberArray = self::constructSharingMemberArray($member_array);
         $sql8a = "INSERT INTO vtiger_pdfmaker_sharing(templateid, shareid, setype) VALUES ";
         $sql8b = "";
         $params8 = array();
         foreach ($groupMemberArray as $setype => $shareIdArr) {
             foreach ($shareIdArr as $shareId) {
                 $sql8b .= "(?, ?, ?),";
                 $params8[] = $templateid;
                 $params8[] = $shareId;
                 $params8[] = $setype;
             }
         }
         if ($sql8b != "") {
             $sql8b = rtrim($sql8b, ",");
             $sql8 = $sql8a . $sql8b;
             $adb->pquery($sql8, $params8);
         }
     }
     $PDFMaker->AddLinks($modulename);
     $redirect = $request->get('redirect');
     if ($redirect == "false") {
         $redirect_url = "index.php?module=PDFMaker&view=Edit&parenttab=Tools&applied=true&templateid=" . $templateid;
         $return_module = $request->get('return_module');
         $return_view = $request->get('return_view');
         if ($return_module != "") {
             $redirect_url .= "&return_module=" . $return_module;
         }
         if ($return_view != "") {
             $redirect_url .= "&return_view=" . $return_view;
         }
         header("Location:" . $redirect_url);
     } else {
         header("Location:index.php?module=PDFMaker&view=Detail&parenttab=Tools&templateid=" . $templateid);
     }
 }
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("EDIT") == false) {
         $PDFMaker->DieDuePermission();
     }
     $viewer = $this->getViewer($request);
     $emode = "";
     $template = array();
     $tplid = $request->get('tplid');
     $mode = $request->get('mode');
     if (isset($tplid) && $tplid != "") {
         $adb = PearDatabase::getInstance();
         $sql = "SELECT * FROM vtiger_pdfmaker_productbloc_tpl WHERE id=?";
         $result = $adb->pquery($sql, array($tplid));
         $row = $adb->fetchByAssoc($result);
         if ($mode != "duplicate") {
             $template["id"] = $row["id"];
         }
         $template["name"] = $row["name"];
         $template["body"] = $row["body"];
         $emode = "edit";
     }
     //if no ID is specified then it is create view
     $viewer->assign("EDIT_TEMPLATE", $template);
     //PROPERTIES tab
     $ProductBlockFields = $PDFMaker->GetProductBlockFields();
     foreach ($ProductBlockFields as $smarty_key => $pbFields) {
         $viewer->assign($smarty_key, $pbFields);
     }
     //LABELS
     //global lang
     $cu_model = Users_Record_Model::getCurrentUserModel();
     $this->cu_language = $cu_model->get('language');
     $app_strings_big = Vtiger_Language_Handler::getModuleStringsFromFile($this->cu_language);
     $app_strings = $app_strings_big['languageStrings'];
     $global_lang_labels = array_flip($app_strings);
     $global_lang_labels = array_flip($global_lang_labels);
     asort($global_lang_labels);
     $viewer->assign("GLOBAL_LANG_LABELS", $global_lang_labels);
     //custom lang
     list($custom_labels, $languages) = $PDFMaker->GetCustomLabels();
     $currLangId = "";
     foreach ($languages as $langId => $langVal) {
         if ($langVal["prefix"] == $current_language) {
             $currLangId = $langId;
             break;
         }
     }
     $vcustom_labels = array();
     if (count($custom_labels) > 0) {
         foreach ($custom_labels as $oLbl) {
             $currLangVal = $oLbl->GetLangValue($currLangId);
             if ($currLangVal == "") {
                 $currLangVal = $oLbl->GetFirstNonEmptyValue();
             }
             $vcustom_labels[$oLbl->GetKey()] = $currLangVal;
         }
         asort($vcustom_labels);
     } else {
         $vcustom_labels = $mod_strings["LBL_SELECT_MODULE_FIELD"];
     }
     $viewer->assign("CUSTOM_LANG_LABELS", $vcustom_labels);
     //VIEW HELPERS
     if ($PDFMaker->GetVersionType() == "professional") {
         $type = "professional";
     } else {
         $type = "basic";
     }
     $viewer->assign("TYPE", $type);
     $viewer->assign("EMODE", $emode);
     $viewer->assign("MODE", $mode);
     $viewer->view('EditProductBlock.tpl', 'PDFMaker');
 }
Exemple #26
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $viewer = $this->getViewer($request);
     if ($request->has('templateid') && !$request->isEmpty('templateid')) {
         $templateid = $request->get('templateid');
         $pdftemplateResult = $PDFMaker->GetEditViewData($templateid);
         $select_module = $pdftemplateResult["module"];
         $select_format = $pdftemplateResult["format"];
         $select_orientation = $pdftemplateResult["orientation"];
         $nameOfFile = $pdftemplateResult["file_name"];
         $is_portal = $pdftemplateResult["is_portal"];
         $is_listview = $pdftemplateResult["is_listview"];
         $is_active = $pdftemplateResult["is_active"];
         $is_default = $pdftemplateResult["is_default"];
         $order = $pdftemplateResult["order"];
         $owner = $pdftemplateResult["owner"];
         $sharingtype = $pdftemplateResult["sharingtype"];
         $sharingMemberArray = $PDFMaker->GetSharingMemberArray($templateid);
         $disp_header = $pdftemplateResult["disp_header"];
         $disp_footer = $pdftemplateResult["disp_footer"];
         if (!$pdftemplateResult["permissions"]["edit"]) {
             $PDFMaker->DieDuePermission();
         }
     } else {
         $templateid = "";
         if ($request->has("return_module") && !$request->isEmpty("return_module")) {
             $select_module = $request->get("return_module");
         } else {
             $select_module = "";
         }
         $select_format = "A4";
         $select_orientation = "portrait";
         //$select_encoding = "utf-8";
         $nameOfFile = "";
         $is_portal = "0";
         $is_listview = "0";
         $is_active = "1";
         $is_default = "0";
         $order = "1";
         $owner = $cu_model->id;
         $sharingtype = "public";
         $sharingMemberArray = array();
         $disp_header = "3";
         $disp_footer = "7";
         $PDFMaker->CheckTemplatePermissions($select_module, $templateid);
     }
     if ($PDFMaker->GetVersionType() == "professional") {
         $type = "professional";
     } else {
         $type = "basic";
     }
     $viewer->assign("TYPE", $type);
     if ($request->has("isDuplicate") && $request->get("isDuplicate") == "true") {
         $viewer->assign("FILENAME", "");
         $viewer->assign("DUPLICATE_FILENAME", $pdftemplateResult["filename"]);
     } else {
         $viewer->assign("FILENAME", $pdftemplateResult["filename"]);
     }
     $viewer->assign("DESCRIPTION", $pdftemplateResult["description"]);
     if (!$request->has("isDuplicate") or $request->has("isDuplicate") && $request->get("isDuplicate") != "true") {
         $viewer->assign("SAVETEMPLATEID", $templateid);
     }
     if ($templateid != "") {
         $viewer->assign("EMODE", "edit");
     }
     $viewer->assign("TEMPLATEID", $templateid);
     $viewer->assign("MODULENAME", vtranslate($select_module, $select_module));
     $viewer->assign("SELECTMODULE", $select_module);
     $viewer->assign("BODY", $pdftemplateResult["body"]);
     $cu_model = Users_Record_Model::getCurrentUserModel();
     $this->cu_language = $cu_model->get('language');
     $viewer->assign("THEME", $theme);
     $viewer->assign("IMAGE_PATH", $image_path);
     $app_strings_big = Vtiger_Language_Handler::getModuleStringsFromFile($this->cu_language);
     $app_strings = $app_strings_big['languageStrings'];
     $viewer->assign("APP", $app_strings);
     $viewer->assign("PARENTTAB", getParentTab());
     $modArr = $PDFMaker->GetAllModules();
     $Modulenames = $modArr[0];
     $ModuleIDS = $modArr[1];
     $viewer->assign("MODULENAMES", $Modulenames);
     // ******************************************   Company and User information: **********************************
     $CUI_BLOCKS["Account"] = vtranslate("LBL_COMPANY_INFO", 'PDFMaker');
     $CUI_BLOCKS["Assigned"] = vtranslate("LBL_USER_INFO", 'PDFMaker');
     $CUI_BLOCKS["Logged"] = vtranslate("LBL_LOGGED_USER_INFO", 'PDFMaker');
     $viewer->assign("CUI_BLOCKS", $CUI_BLOCKS);
     $adb = PearDatabase::getInstance();
     $sql = "SELECT * FROM vtiger_organizationdetails";
     $result = $adb->pquery($sql, array());
     $organization_logoname = decode_html($adb->query_result($result, 0, 'logoname'));
     $organization_header = decode_html($adb->query_result($result, 0, 'headername'));
     $organization_stamp_signature = $adb->query_result($result, 0, 'stamp_signature');
     global $site_URL;
     $path = $site_URL . "/test/logo/";
     if (isset($organization_logoname)) {
         $organization_logo_img = "<img src=\"" . $path . $organization_logoname . "\">";
         $viewer->assign("COMPANYLOGO", $organization_logo_img);
     }
     if (isset($organization_stamp_signature)) {
         $organization_stamp_signature_img = "<img src=\"" . $path . $organization_stamp_signature . "\">";
         $viewer->assign("COMPANY_STAMP_SIGNATURE", $organization_stamp_signature_img);
     }
     if (isset($organization_header)) {
         $organization_header_img = "<img src=\"" . $path . $organization_header . "\">";
         $viewer->assign("COMPANY_HEADER_SIGNATURE", $organization_header_img);
     }
     $Acc_Info = array('' => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "COMPANY_NAME" => vtranslate("LBL_COMPANY_NAME", 'PDFMaker'), "COMPANY_LOGO" => vtranslate("LBL_COMPANY_LOGO", 'PDFMaker'), "COMPANY_ADDRESS" => vtranslate("LBL_COMPANY_ADDRESS", 'PDFMaker'), "COMPANY_CITY" => vtranslate("LBL_COMPANY_CITY", 'PDFMaker'), "COMPANY_STATE" => vtranslate("LBL_COMPANY_STATE", 'PDFMaker'), "COMPANY_ZIP" => vtranslate("LBL_COMPANY_ZIP", 'PDFMaker'), "COMPANY_COUNTRY" => vtranslate("LBL_COMPANY_COUNTRY", 'PDFMaker'), "COMPANY_PHONE" => vtranslate("LBL_COMPANY_PHONE", "PDFMaker"), "COMPANY_FAX" => vtranslate("LBL_COMPANY_FAX", 'PDFMaker'), "COMPANY_WEBSITE" => vtranslate("LBL_COMPANY_WEBSITE", 'PDFMaker'));
     $viewer->assign("ACCOUNTINFORMATIONS", $Acc_Info);
     if (getTabId('MultiCompany4you') && vtlib_isModuleActive('MultiCompany4you')) {
         $MultiAcc_info = array('' => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "MULTICOMPANY_COMPANYNAME" => vtranslate("LBL_COMPANY_NAME", 'MultiCompany4you'), "MULTICOMPANY_STREET" => vtranslate("Street", 'MultiCompany4you'), "MULTICOMPANY_CITY" => vtranslate("City", 'MultiCompany4you'), "MULTICOMPANY_CODE" => vtranslate("Code", 'MultiCompany4you'), "MULTICOMPANY_STATE" => vtranslate("State", 'MultiCompany4you'), "MULTICOMPANY_COUNTRY" => vtranslate("Country", 'MultiCompany4you'), "MULTICOMPANY_PHONE" => vtranslate("phone", 'MultiCompany4you'), "MULTICOMPANY_FAX" => vtranslate("Fax", 'MultiCompany4you'), "MULTICOMPANY_EMAIL" => vtranslate("email", 'MultiCompany4you'), "MULTICOMPANY_WEBSITE" => vtranslate("Website", 'MultiCompany4you'), "MULTICOMPANY_LOGO" => vtranslate("Logo", 'MultiCompany4you'), "MULTICOMPANY_STAMP" => vtranslate("Stamp", 'MultiCompany4you'), "MULTICOMPANY_BANKNAME" => vtranslate("BankName", 'MultiCompany4you'), "MULTICOMPANY_BANKACCOUNTNO" => vtranslate("BankAccountNo", 'MultiCompany4you'), "MULTICOMPANY_IBAN" => vtranslate("IBAN", 'MultiCompany4you'), "MULTICOMPANY_SWIFT" => vtranslate("SWIFT", 'MultiCompany4you'), "MULTICOMPANY_REGISTRATIONNO" => vtranslate("RegistrationNo", 'MultiCompany4you'), "MULTICOMPANY_VATNO" => vtranslate("VATNo", 'MultiCompany4you'), "MULTICOMPANY_TAXID" => vtranslate("TaxId", 'MultiCompany4you'), "MULTICOMPANY_ADDITIONALINFORMATIONS" => vtranslate("AdditionalInformations", 'MultiCompany4you'));
         $viewer->assign("MULTICOMPANYINFORMATIONS", $MultiAcc_info);
         $viewer->assign("LBL_MULTICOMPANY", vtranslate('MultiCompany', 'MultiCompany4you'));
     }
     $sql_user_block = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid = ? ORDER BY sequence ASC";
     $res_user_block = $adb->pquery($sql_user_block, array('29'));
     $user_block_info_arr = array();
     while ($row_user_block = $adb->fetch_array($res_user_block)) {
         $sql_user_field = "SELECT fieldid, uitype FROM vtiger_field WHERE block = ? and (displaytype != ? OR uitype = ?) ORDER BY sequence ASC";
         $res_user_field = $adb->pquery($sql_user_field, array($row_user_block['blockid'], '3', '55'));
         $num_user_field = $adb->num_rows($res_user_field);
         if ($num_user_field > 0) {
             $user_field_id_array = array();
             while ($row_user_field = $adb->fetch_array($res_user_field)) {
                 $user_field_id_array[] = $row_user_field['fieldid'];
             }
             $user_block_info_arr[$row_user_block['blocklabel']] = $user_field_id_array;
         }
     }
     $user_mod_strings = $this->getModuleLanguageArray("Users");
     $b = 0;
     foreach ($user_block_info_arr as $block_label => $block_fields) {
         $b++;
         if (isset($user_mod_strings[$block_label]) and $user_mod_strings[$block_label] != "") {
             $optgroup_value = $user_mod_strings[$block_label];
         } else {
             $optgroup_value = vtranslate($block_label, 'PDFMaker');
         }
         if (count($block_fields) > 0) {
             $sql1 = "SELECT * FROM vtiger_field WHERE fieldid IN (" . generateQuestionMarks($block_fields) . ")";
             $result1 = $adb->pquery($sql1, $block_fields);
             while ($row1 = $adb->fetchByAssoc($result1)) {
                 $fieldname = $row1['fieldname'];
                 $fieldlabel = $row1['fieldlabel'];
                 $option_key = strtoupper("Users" . "_" . $fieldname);
                 if (isset($current_mod_strings[$fieldlabel]) and $current_mod_strings[$fieldlabel] != "") {
                     $option_value = $current_mod_strings[$fieldlabel];
                 } elseif (isset($app_strings[$fieldlabel]) and $app_strings[$fieldlabel] != "") {
                     $option_value = $app_strings[$fieldlabel];
                 } else {
                     $option_value = $fieldlabel;
                 }
                 $User_Info[$optgroup_value][$option_key] = $option_value;
                 $Logged_User_Info[$optgroup_value]["R_" . $option_key] = $option_value;
             }
         }
         //variable RECORD ID added
         if ($b == 1) {
             $option_value = "Record ID";
             $option_key = strtoupper("USERS_CRMID");
             $User_Info[$optgroup_value][$option_key] = $option_value;
             $Logged_User_Info[$optgroup_value]["R_" . $option_key] = $option_value;
         }
         //end
     }
     // ****************************************** END: Company and User information **********************************
     $viewer->assign("USERINFORMATIONS", $User_Info);
     $viewer->assign("LOGGEDUSERINFORMATION", $Logged_User_Info);
     $Invterandcon = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "TERMS_AND_CONDITIONS" => vtranslate("LBL_TERMS_AND_CONDITIONS", 'PDFMaker'));
     $viewer->assign("INVENTORYTERMSANDCONDITIONS", $Invterandcon);
     //custom functions
     $customFunctions = $this->getCustomFunctionsList();
     $viewer->assign("CUSTOM_FUNCTIONS", $customFunctions);
     //labels
     $global_lang_labels = @array_flip($app_strings);
     $global_lang_labels = @array_flip($global_lang_labels);
     asort($global_lang_labels);
     $viewer->assign("GLOBAL_LANG_LABELS", $global_lang_labels);
     $module_lang_labels = array();
     if ($select_module != "") {
         $mod_lang = $this->getModuleLanguageArray($select_module);
         $module_lang_labels = @array_flip($mod_lang);
         $module_lang_labels = @array_flip($module_lang_labels);
         asort($module_lang_labels);
     } else {
         $module_lang_labels[""] = vtranslate("LBL_SELECT_MODULE_FIELD", 'PDFMaker');
     }
     $viewer->assign("MODULE_LANG_LABELS", $module_lang_labels);
     list($custom_labels, $languages) = $PDFMaker->GetCustomLabels();
     $currLangId = "";
     foreach ($languages as $langId => $langVal) {
         if ($langVal["prefix"] == $current_language) {
             $currLangId = $langId;
             break;
         }
     }
     $vcustom_labels = array();
     if (count($custom_labels) > 0) {
         foreach ($custom_labels as $oLbl) {
             $currLangVal = $oLbl->GetLangValue($currLangId);
             if ($currLangVal == "") {
                 $currLangVal = $oLbl->GetFirstNonEmptyValue();
             }
             $vcustom_labels[$oLbl->GetKey()] = $currLangVal;
         }
         asort($vcustom_labels);
     } else {
         $vcustom_labels = vtranslate("LBL_SELECT_MODULE_FIELD", 'PDFMaker');
     }
     $viewer->assign("CUSTOM_LANG_LABELS", $vcustom_labels);
     $Header_Footer_Strings = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "PAGE" => $app_strings["Page"], "PAGES" => $app_strings["Pages"]);
     $viewer->assign("HEADER_FOOTER_STRINGS", $Header_Footer_Strings);
     //PDF FORMAT SETTINGS
     $Formats = array("A3" => "A3", "A4" => "A4", "A5" => "A5", "A6" => "A6", "Letter" => "Letter", "Legal" => "Legal", "Custom" => "Custom");
     // ITS4YOU VlZa
     $viewer->assign("FORMATS", $Formats);
     if (strpos($select_format, ";") > 0) {
         $tmpArr = explode(";", $select_format);
         $select_format = "Custom";
         $custom_format["width"] = $tmpArr[0];
         $custom_format["height"] = $tmpArr[1];
         $viewer->assign("CUSTOM_FORMAT", $custom_format);
     }
     $viewer->assign("SELECT_FORMAT", $select_format);
     //PDF ORIENTATION SETTINGS
     $Orientations = array("portrait" => vtranslate("portrait", 'PDFMaker'), "landscape" => vtranslate("landscape", 'PDFMaker'));
     $viewer->assign("ORIENTATIONS", $Orientations);
     $viewer->assign("SELECT_ORIENTATION", $select_orientation);
     //PDF STATUS SETTINGS
     $Status = array("1" => $app_strings["Active"], "0" => vtranslate("Inactive", 'PDFMaker'));
     $viewer->assign("STATUS", $Status);
     $viewer->assign("IS_ACTIVE", $is_active);
     if ($is_active == "0") {
         $viewer->assign("IS_DEFAULT_DV_CHECKED", 'disabled="disabled"');
         $viewer->assign("IS_DEFAULT_LV_CHECKED", 'disabled="disabled"');
     } elseif ($is_default > 0) {
         $is_default_bin = str_pad(base_convert($is_default, 10, 2), 2, "0", STR_PAD_LEFT);
         $is_default_lv = substr($is_default_bin, 0, 1);
         $is_default_dv = substr($is_default_bin, 1, 1);
         if ($is_default_lv == "1") {
             $viewer->assign("IS_DEFAULT_LV_CHECKED", 'checked="checked"');
         }
         if ($is_default_dv == "1") {
             $viewer->assign("IS_DEFAULT_DV_CHECKED", 'checked="checked"');
         }
     }
     $viewer->assign("ORDER", $order);
     if ($is_portal == "1") {
         $viewer->assign("IS_PORTAL_CHECKED", 'checked="checked"');
     }
     if ($is_listview == "1") {
         $viewer->assign("IS_LISTVIEW_CHECKED", 'checked="checked"');
     }
     //PDF MARGIN SETTINGS
     if ($request->has("templateid") && !$request->isEmpty("templateid")) {
         $Margins = array("top" => $pdftemplateResult["margin_top"], "bottom" => $pdftemplateResult["margin_bottom"], "left" => $pdftemplateResult["margin_left"], "right" => $pdftemplateResult["margin_right"]);
         $Decimals = array("point" => $pdftemplateResult["decimal_point"], "decimals" => $pdftemplateResult["decimals"], "thousands" => $pdftemplateResult["thousands_separator"] != "sp" ? $pdftemplateResult["thousands_separator"] : " ");
     } else {
         $Margins = array("top" => "2", "bottom" => "2", "left" => "2", "right" => "2");
         $Decimals = array("point" => ",", "decimals" => "2", "thousands" => " ");
     }
     $viewer->assign("MARGINS", $Margins);
     $viewer->assign("DECIMALS", $Decimals);
     //PDF HEADER / FOOTER
     $header = "";
     $footer = "";
     if ($request->has("templateid") && !$request->isEmpty("templateid")) {
         $header = $pdftemplateResult["header"];
         $footer = $pdftemplateResult["footer"];
     }
     $viewer->assign("HEADER", $header);
     $viewer->assign("FOOTER", $footer);
     $hfVariables = array("##PAGE##" => vtranslate("LBL_CURRENT_PAGE", 'PDFMaker'), "##PAGES##" => vtranslate("LBL_ALL_PAGES", 'PDFMaker'), "##PAGE##/##PAGES##" => vtranslate("LBL_PAGE_PAGES", 'PDFMaker'));
     $viewer->assign("HEAD_FOOT_VARS", $hfVariables);
     $dateVariables = array("##DD.MM.YYYY##" => vtranslate("LBL_DATE_DD.MM.YYYY", 'PDFMaker'), "##DD-MM-YYYY##" => vtranslate("LBL_DATE_DD-MM-YYYY", 'PDFMaker'), "##MM-DD-YYYY##" => vtranslate("LBL_DATE_MM-DD-YYYY", 'PDFMaker'), "##YYYY-MM-DD##" => vtranslate("LBL_DATE_YYYY-MM-DD", 'PDFMaker'));
     $viewer->assign("DATE_VARS", $dateVariables);
     //PDF FILENAME FIELDS
     $filenameFields = array("#TEMPLATE_NAME#" => vtranslate("LBL_PDF_NAME", 'PDFMaker'), "#DD-MM-YYYY#" => vtranslate("LBL_CURDATE_DD-MM-YYYY", 'PDFMaker'), "#MM-DD-YYYY#" => vtranslate("LBL_CURDATE_MM-DD-YYYY", 'PDFMaker'), "#YYYY-MM-DD#" => vtranslate("LBL_CURDATE_YYYY-MM-DD", 'PDFMaker'));
     $viewer->assign("FILENAME_FIELDS", $filenameFields);
     $viewer->assign("NAME_OF_FILE", $nameOfFile);
     //Sharing
     $template_owners = get_user_array(false);
     $viewer->assign("TEMPLATE_OWNERS", $template_owners);
     $viewer->assign("TEMPLATE_OWNER", $owner);
     $sharing_types = array("public" => vtranslate("PUBLIC_FILTER", 'PDFMaker'), "private" => vtranslate("PRIVATE_FILTER", 'PDFMaker'), "share" => vtranslate("SHARE_FILTER", 'PDFMaker'));
     $viewer->assign("SHARINGTYPES", $sharing_types);
     $viewer->assign("SHARINGTYPE", $sharingtype);
     $cmod = $this->getModuleLanguageArray("Settings");
     //$cmod = return_specified_module_language($current_language, "Settings");
     $viewer->assign("CMOD", $cmod);
     //Constructing the Role Array
     $roleDetails = getAllRoleDetails();
     $i = 0;
     $roleIdStr = "";
     $roleNameStr = "";
     $userIdStr = "";
     $userNameStr = "";
     $grpIdStr = "";
     $grpNameStr = "";
     foreach ($roleDetails as $roleId => $roleInfo) {
         if ($i != 0) {
             if ($i != 1) {
                 $roleIdStr .= ", ";
                 $roleNameStr .= ", ";
             }
             $roleName = $roleInfo[0];
             $roleIdStr .= "'" . $roleId . "'";
             $roleNameStr .= "'" . addslashes(decode_html($roleName)) . "'";
         }
         $i++;
     }
     //Constructing the User Array
     $l = 0;
     $userDetails = getAllUserName();
     foreach ($userDetails as $userId => $userInfo) {
         if ($l != 0) {
             $userIdStr .= ", ";
             $userNameStr .= ", ";
         }
         $userIdStr .= "'" . $userId . "'";
         $userNameStr .= "'" . $userInfo . "'";
         $l++;
     }
     //Constructing the Group Array
     $parentGroupArray = array();
     $m = 0;
     $grpDetails = getAllGroupName();
     foreach ($grpDetails as $grpId => $grpName) {
         if (!in_array($grpId, $parentGroupArray)) {
             if ($m != 0) {
                 $grpIdStr .= ", ";
                 $grpNameStr .= ", ";
             }
             $grpIdStr .= "'" . $grpId . "'";
             $grpNameStr .= "'" . addslashes(decode_html($grpName)) . "'";
             $m++;
         }
     }
     $viewer->assign("ROLEIDSTR", $roleIdStr);
     $viewer->assign("ROLENAMESTR", $roleNameStr);
     $viewer->assign("USERIDSTR", $userIdStr);
     $viewer->assign("USERNAMESTR", $userNameStr);
     $viewer->assign("GROUPIDSTR", $grpIdStr);
     $viewer->assign("GROUPNAMESTR", $grpNameStr);
     if (count($sharingMemberArray) > 0) {
         $outputMemberArr = array();
         foreach ($sharingMemberArray as $setype => $shareIdArr) {
             foreach ($shareIdArr as $shareId) {
                 switch ($setype) {
                     case "groups":
                         $groupInfo = getGroupName($shareId);
                         $memberName = $groupInfo[0];
                         $memberDisplay = "Group::";
                         break;
                     case "roles":
                         $memberName = getRoleName($shareId);
                         $memberDisplay = "Roles::";
                         break;
                     case "rs":
                         $memberName = getRoleName($shareId);
                         $memberDisplay = "RoleAndSubordinates::";
                         break;
                     case "users":
                         $memberName = getUserName($shareId);
                         $memberDisplay = "User::";
                         break;
                 }
                 $outputMemberArr[] = $setype . "::" . $shareId;
                 $outputMemberArr[] = $memberDisplay . $memberName;
             }
         }
         $viewer->assign("MEMBER", array_chunk($outputMemberArr, 2));
     }
     //Ignored picklist values
     $pvsql = "SELECT value FROM vtiger_pdfmaker_ignorepicklistvalues";
     $pvresult = $adb->pquery($pvsql, array());
     $pvvalues = "";
     while ($pvrow = $adb->fetchByAssoc($pvresult)) {
         $pvvalues .= $pvrow["value"] . ", ";
     }
     $viewer->assign("IGNORE_PICKLIST_VALUES", rtrim($pvvalues, ", "));
     $More_Fields = array("CURRENCYNAME" => vtranslate("LBL_CURRENCY_NAME", 'PDFMaker'), "CURRENCYSYMBOL" => vtranslate("LBL_CURRENCY_SYMBOL", 'PDFMaker'), "CURRENCYCODE" => vtranslate("LBL_CURRENCY_CODE", 'PDFMaker'), "TOTALWITHOUTVAT" => vtranslate("LBL_VARIABLE_SUMWITHOUTVAT", 'PDFMaker'), "TOTALDISCOUNT" => vtranslate("LBL_VARIABLE_TOTALDISCOUNT", 'PDFMaker'), "TOTALDISCOUNTPERCENT" => vtranslate("LBL_VARIABLE_TOTALDISCOUNT_PERCENT", 'PDFMaker'), "TOTALAFTERDISCOUNT" => vtranslate("LBL_VARIABLE_TOTALAFTERDISCOUNT", 'PDFMaker'), "VAT" => vtranslate("LBL_VARIABLE_VAT", 'PDFMaker'), "VATPERCENT" => vtranslate("LBL_VARIABLE_VAT_PERCENT", 'PDFMaker'), "VATBLOCK" => vtranslate("LBL_VARIABLE_VAT_BLOCK", 'PDFMaker'), "TOTALWITHVAT" => vtranslate("LBL_VARIABLE_SUMWITHVAT", 'PDFMaker'), "SHTAXTOTAL" => vtranslate("LBL_SHTAXTOTAL", 'PDFMaker'), "SHTAXAMOUNT" => vtranslate("LBL_SHTAXAMOUNT", 'PDFMaker'), "ADJUSTMENT" => vtranslate("LBL_ADJUSTMENT", 'PDFMaker'), "TOTAL" => vtranslate("LBL_VARIABLE_TOTALSUM", 'PDFMaker'));
     //formatable VATBLOCK content
     $vatblock_table = '<table border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse;">
             		<tr>
                         <td>' . $app_strings["Name"] . '</td>
                         <td>' . vtranslate("LBL_VATBLOCK_VAT_PERCENT", 'PDFMaker') . '</td>
                         <td>' . vtranslate("LBL_VATBLOCK_SUM", 'PDFMaker') . '</td>
                         <td>' . vtranslate("LBL_VATBLOCK_VAT_VALUE", 'PDFMaker') . '</td>
                     </tr>
             		<tr>
                         <td colspan="4">#VATBLOCK_START#</td>
                     </tr>
             		<tr>
             			<td>$VATBLOCK_LABEL$</td>
             			<td>$VATBLOCK_VALUE$</td>
             			<td>$VATBLOCK_NETTO$</td>
             			<td>$VATBLOCK_VAT$</td>
             		</tr>
             		<tr>
                         <td colspan="4">#VATBLOCK_END#</td>
                     </tr>
                 </table>';
     $vatblock_table = str_replace(array("\r\n", "\r", "\n", "\t"), "", $vatblock_table);
     $vatblock_table = ereg_replace(" {2,}", ' ', $vatblock_table);
     $viewer->assign("VATBLOCK_TABLE", $vatblock_table);
     $ModCommentsModules = array();
     /*
             $ModComments = is_numeric(getTabId("ModComments"));
             if ($ModComments == true) {
                 $sql = "SELECT relmodule FROM vtiger_fieldmodulerel WHERE module='ModComments' AND relmodule != 'ModComments'";
                 $result = $adb->pquery($sql,array());
                 while ($row = $adb->fetchByAssoc($result))
                     $ModCommentsModules[$row["relmodule"]] = $row["relmodule"];
             }
     */
     foreach ($ModuleIDS as $module => $module_id) {
         $this->getModuleFields($module, $module_id);
     }
     //Permissions are taken into consideration when dealing with realted modules
     $AllowedRelMods = array();
     if (count($this->All_Related_Modules) > 0) {
         foreach ($this->All_Related_Modules as $Mod => $RelMods) {
             foreach ($RelMods as $RelModKey => $RelMod) {
                 $RelModName = $RelMod[2];
                 if (isPermitted($RelModName, '') == "yes") {
                     $AllowedRelMods[$Mod][$RelModKey] = $RelMod;
                 }
             }
         }
     }
     $this->All_Related_Modules = $AllowedRelMods;
     // Fix of emtpy selectbox in case of selected module does not have any related modules
     foreach ($Modulenames as $key => $value) {
         if (!isset($this->All_Related_Modules[$key])) {
             $this->All_Related_Modules[$key] = array();
         }
     }
     $viewer->assign("ALL_RELATED_MODULES", $this->All_Related_Modules);
     if ($select_module != "" && count($this->All_Related_Modules[$select_module]) > 0) {
         foreach ($this->All_Related_Modules[$select_module] as $RelModArr) {
             $Related_Modules[$RelModArr[2] . "|" . $RelModArr[0]] = vtranslate($RelModArr[2]) . " (" . $RelModArr[1] . ")";
         }
     }
     $viewer->assign("RELATED_MODULES", $Related_Modules);
     $tacModules = array();
     $tac4you = is_numeric(getTabId("Tac4you"));
     if ($tac4you == true) {
         $sql = "SELECT tac4you_module FROM vtiger_tac4you_module WHERE presence = ?";
         $result = $adb->pquery($sql, array('1'));
         while ($row = $adb->fetchByAssoc($result)) {
             $tacModules[$row["tac4you_module"]] = $row["tac4you_module"];
         }
     }
     $desc4youModules = array();
     $desc4you = is_numeric(getTabId("Descriptions4you"));
     if ($desc4you == true) {
         $sql = "SELECT b.name FROM vtiger_links AS a INNER JOIN vtiger_tab AS b USING (tabid) WHERE linktype = ? AND linkurl = ?";
         $result = $adb->pquery($sql, array('DETAILVIEWWIDGET', 'block://ModDescriptions4you:modules/Descriptions4you/ModDescriptions4you.php'));
         while ($row = $adb->fetchByAssoc($result)) {
             $desc4youModules[$row["name"]] = $row["name"];
         }
     }
     $Settings_Profiles_Record_Model = new Settings_Profiles_Record_Model();
     foreach ($this->ModuleFields as $module => $Blocks) {
         $Optgroupts = array();
         $current_mod_strings = $this->getModuleLanguageArray($module);
         $moduleModel = Vtiger_Module_Model::getInstance($module);
         $b = 0;
         if ($module == 'Calendar') {
             $b++;
             $Optgroupts[] = '"' . vtranslate('Calendar') . '","' . $b . '"';
             $Convert_ModuleFields['Calendar|1'] .= ',"Record ID","CALENDAR_CRMID"';
             $SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"] = "Record ID";
             $EventModel = Vtiger_Module_Model::getInstance('Events');
         }
         foreach ($Blocks as $block_label => $block_fields) {
             $b++;
             $Options = array();
             if ($block_label != "TEMP_MODCOMMENTS_BLOCK") {
                 $optgroup_value = vtranslate($block_label, $module);
                 if ($optgroup_value == $block_label) {
                     $optgroup_value = vtranslate($block_label, 'PDFMaker');
                 }
             } else {
                 $optgroup_value = vtranslate("LBL_MODCOMMENTS_INFORMATION", 'PDFMaker');
             }
             $Optgroupts[] = '"' . $optgroup_value . '","' . $b . '"';
             if (count($block_fields) > 0) {
                 $sql1 = "SELECT * FROM vtiger_field WHERE fieldid IN (" . generateQuestionMarks($block_fields) . ")";
                 $result1 = $adb->pquery($sql1, $block_fields);
                 while ($row1 = $adb->fetchByAssoc($result1)) {
                     $fieldname = $row1['fieldname'];
                     $fieldlabel = $row1['fieldlabel'];
                     $fieldModel = Vtiger_Field_Model::getInstance($fieldname, $moduleModel);
                     if (!$fieldModel || !$fieldModel->getPermissions('readonly')) {
                         if ($module == 'Calendar') {
                             $eventFieldModel = Vtiger_Field_Model::getInstance($fieldname, $EventModel);
                             if (!$eventFieldModel || !$eventFieldModel->getPermissions('readonly')) {
                                 continue;
                             }
                         } else {
                             continue;
                         }
                     }
                     $option_key = strtoupper($module . "_" . $fieldname);
                     if (isset($current_mod_strings[$fieldlabel]) and $current_mod_strings[$fieldlabel] != "") {
                         $option_value = $current_mod_strings[$fieldlabel];
                     } elseif (isset($app_strings[$fieldlabel]) and $app_strings[$fieldlabel] != "") {
                         $option_value = $app_strings[$fieldlabel];
                     } else {
                         $option_value = $fieldlabel;
                     }
                     $option_value = nl2br($option_value);
                     if ($module == 'Calendar') {
                         if ($option_key == 'CALENDAR_ACTIVITYTYPE' || $option_key == 'CALENDAR_DUE_DATE') {
                             $Convert_ModuleFields['Calendar|1'] .= ',"' . $option_value . '","' . $option_key . '"';
                             $SelectModuleFields['Calendar'][vtranslate('Calendar')][$option_key] = $option_value;
                             continue;
                         } elseif (!isset($Existing_ModuleFields[$option_key])) {
                             $Existing_ModuleFields[$option_key] = $optgroup_value;
                         } else {
                             $Convert_ModuleFields['Calendar|1'] .= ',"' . $option_value . '","' . $option_key . '"';
                             $SelectModuleFields['Calendar'][vtranslate('Calendar')][$option_key] = $option_value;
                             $Unset_Module_Fields[] = '"' . $option_value . '","' . $option_key . '"';
                             unset($SelectModuleFields['Calendar'][$Existing_ModuleFields[$option_key]][$option_key]);
                             continue;
                         }
                     }
                     $Options[] = '"' . $option_value . '","' . $option_key . '"';
                     $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
                 }
             }
             //variable RECORD ID added
             if ($b == 1) {
                 $option_value = "Record ID";
                 $option_key = strtoupper($module . "_CRMID");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
                 $option_value = vtranslate('Created Time') . ' (' . vtranslate('Due Date & Time') . ')';
                 $option_key = strtoupper($module . "_CREATEDTIME_DATETIME");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
                 $option_value = vtranslate('Modified Time') . ' (' . vtranslate('Due Date & Time') . ')';
                 $option_key = strtoupper($module . "_MODIFIEDTIME_DATETIME");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             //end
             if ($block_label == "LBL_TERMS_INFORMATION" && isset($tacModules[$module])) {
                 $option_value = vtranslate("LBL_TAC4YOU", 'PDFMaker');
                 $option_key = strtoupper($module . "_TAC4YOU");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             if ($block_label == "LBL_DESCRIPTION_INFORMATION" && isset($desc4youModules[$module])) {
                 $option_value = vtranslate("LBL_DESC4YOU", 'PDFMaker');
                 $option_key = strtoupper($module . "_DESC4YOU");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             //ModComments support
             if ($block_label == "TEMP_MODCOMMENTS_BLOCK" && in_array($module, $ModCommentsModules) == true) {
                 $option_value = vtranslate("LBL_MODCOMMENTS", 'PDFMaker');
                 $option_key = strtoupper($module . "_MODCOMMENTS");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             $Convert_RelatedModuleFields[$module . "|" . $b] = implode(",", $Options);
             $OptionsRelMod = array();
             if (($block_label == "LBL_DETAILS_BLOCK" || $block_label == "LBL_ITEM_DETAILS") && ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder" || $module == "Issuecards" || $module == "Receiptcards" || $module == "Creditnote" || $module == "StornoInvoice")) {
                 $Set_More_Fields = $More_Fields;
                 if ($module == "Invoice") {
                     $Set_More_Fields[strtoupper($module) . "_RECEIVED"] = vtranslate("Received", $module);
                 }
                 if ($module == "Invoice" || $module == "PurchaseOrder") {
                     $Set_More_Fields[strtoupper($module) . "_BALANCE"] = vtranslate("Balance", $module);
                 }
                 foreach ($Set_More_Fields as $variable => $variable_name) {
                     $variable_key = strtoupper($variable);
                     $Options[] = '"' . $variable_name . '","' . $variable_key . '"';
                     $SelectModuleFields[$module][$optgroup_value][$variable_key] = $variable_name;
                     if ($variable_key != "VATBLOCK") {
                         $OptionsRelMod[] = '"' . $variable_name . '","' . strtoupper($module) . '_' . $variable_key . '"';
                     }
                 }
             }
             //this concatenation is because of need to have extra Details block in Inventory modules which are as related modules
             $Convert_RelatedModuleFields[$module . "|" . $b] .= implode(',', $OptionsRelMod);
             $Convert_ModuleFields[$module . "|" . $b] = implode(",", $Options);
         }
         if ($module == 'Calendar') {
             $Convert_ModuleFields['Calendar|1'] = str_replace(',"Record ID","CALENDAR_CRMID",', "", $Convert_ModuleFields['Calendar|1']);
             $Convert_ModuleFields['Calendar|1'] .= ',"Record ID","CALENDAR_CRMID"';
             unset($SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"]);
             $SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"] = "Record ID";
         }
         $Convert_ModuleBlocks[$module] = implode(",", $Optgroupts);
     }
     foreach ($Convert_ModuleFields as $cmf_key => $cmf_value) {
         if (substr($cmf_key, 0, 9) == 'Calendar|' && $cmf_key != 'Calendar|1') {
             foreach ($Unset_Module_Fields as $to_unset) {
                 $cmf_value = str_replace($to_unset, '', $cmf_value);
                 $cmf_value = str_replace(",,", ',', $cmf_value);
                 $Convert_ModuleFields[$cmf_key] = trim($cmf_value, ',');
             }
         }
     }
     $viewer->assign("MODULE_BLOCKS", $Convert_ModuleBlocks);
     $viewer->assign("RELATED_MODULE_FIELDS", $Convert_RelatedModuleFields);
     $viewer->assign("MODULE_FIELDS", $Convert_ModuleFields);
     //Product block fields start
     // Product bloc templates
     $sql = "SELECT * FROM vtiger_pdfmaker_productbloc_tpl";
     $result = $adb->pquery($sql, array());
     $Productbloc_tpl[""] = vtranslate("LBL_PLS_SELECT", 'PDFMaker');
     while ($row = $adb->fetchByAssoc($result)) {
         $Productbloc_tpl[$row["body"]] = $row["name"];
     }
     $viewer->assign("PRODUCT_BLOC_TPL", $Productbloc_tpl);
     $ProductBlockFields = $PDFMaker->GetProductBlockFields($select_module);
     foreach ($ProductBlockFields as $viewer_key => $pbFields) {
         $viewer->assign($viewer_key, $pbFields);
     }
     //Product block fields end
     //Related block postprocessing
     $Related_Blocks = $PDFMaker->GetRelatedBlocks($select_module);
     $viewer->assign("RELATED_BLOCKS", $Related_Blocks);
     //Related blocks end
     if ($templateid != "" || $select_module != "") {
         $viewer->assign("SELECT_MODULE_FIELD", $SelectModuleFields[$select_module]);
         $smf_filename = $SelectModuleFields[$select_module];
         if ($select_module == "Invoice" || $select_module == "Quotes" || $select_module == "SalesOrder" || $select_module == "PurchaseOrder" || $select_module == "Issuecards" || $select_module == "Receiptcards" || $select_module == "Creditnote" || $select_module == "StornoInvoice") {
             unset($smf_filename["Details"]);
         }
         $viewer->assign("SELECT_MODULE_FIELD_FILENAME", $smf_filename);
     }
     // header / footer display settings
     $disp_optionsArr = array("DH_FIRST", "DH_OTHER");
     $disp_header_bin = str_pad(base_convert($disp_header, 10, 2), 2, "0", STR_PAD_LEFT);
     for ($i = 0; $i < count($disp_optionsArr); $i++) {
         if (substr($disp_header_bin, $i, 1) == "1") {
             $viewer->assign($disp_optionsArr[$i], 'checked="checked"');
         }
     }
     if ($disp_header == "3") {
         $viewer->assign("DH_ALL", 'checked="checked"');
     }
     $disp_optionsArr = array("DF_FIRST", "DF_LAST", "DF_OTHER");
     $disp_footer_bin = str_pad(base_convert($disp_footer, 10, 2), 3, "0", STR_PAD_LEFT);
     for ($i = 0; $i < count($disp_optionsArr); $i++) {
         if (substr($disp_footer_bin, $i, 1) == "1") {
             $viewer->assign($disp_optionsArr[$i], 'checked="checked"');
         }
     }
     if ($disp_footer == "7") {
         $viewer->assign("DF_ALL", 'checked="checked"');
     }
     $ListView_Block = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "LISTVIEWBLOCK_START" => vtranslate("LBL_ARTICLE_START", 'PDFMaker'), "LISTVIEWBLOCK_END" => vtranslate("LBL_ARTICLE_END", 'PDFMaker'), "CRIDX" => vtranslate("LBL_COUNTER", 'PDFMaker'));
     $viewer->assign("LISTVIEW_BLOCK_TPL", $ListView_Block);
     $version_type = ucfirst($PDFMaker->GetVersionType());
     $viewer->assign("VERSION", $version_type . " " . PDFMaker_Version_Helper::$version);
     $category = getParentTab();
     $viewer->assign("CATEGORY", $category);
     $viewer->view('Edit.tpl', 'PDFMaker');
 }
Exemple #27
0
 public function process(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("EDIT") == false) {
         $PDFMaker->DieDuePermission();
     }
     $viewer = $this->getViewer($request);
     if ($request->has('templateid') && !$request->isEmpty('templateid')) {
         $templateid = $request->get('templateid');
         $pdftemplateResult = $PDFMaker->GetEditViewData($templateid);
         $select_module = $pdftemplateResult["module"];
         $select_format = $pdftemplateResult["format"];
         $select_orientation = $pdftemplateResult["orientation"];
     } else {
         $templateid = "";
         if ($request->has("return_module") && !$request->isEmpty("return_module")) {
             $select_module = $request->get("return_module");
         } else {
             $select_module = "";
         }
         $select_format = "A4";
         $select_orientation = "portrait";
     }
     $PDFMaker->CheckTemplatePermissions($select_module, $templateid);
     $viewer->assign("EMODE", "edit");
     $viewer->assign("TEMPLATEID", $templateid);
     $viewer->assign("MODULENAME", vtranslate($select_module, $select_module));
     $viewer->assign("SELECTMODULE", $select_module);
     $viewer->assign("BODY", $pdftemplateResult["body"]);
     $cu_model = Users_Record_Model::getCurrentUserModel();
     $this->cu_language = $cu_model->get('language');
     $viewer->assign("THEME", $theme);
     $viewer->assign("IMAGE_PATH", $image_path);
     $app_strings_big = Vtiger_Language_Handler::getModuleStringsFromFile($this->cu_language);
     $app_strings = $app_strings_big['languageStrings'];
     $viewer->assign("APP", $app_strings);
     $viewer->assign("PARENTTAB", getParentTab());
     $modArr = $PDFMaker->GetAllModules();
     $Modulenames = $modArr[0];
     $ModuleIDS = $modArr[1];
     // ******************************************   Company and User information: **********************************
     $CUI_BLOCKS["Account"] = vtranslate("LBL_COMPANY_INFO", 'PDFMaker');
     $CUI_BLOCKS["Assigned"] = vtranslate("LBL_USER_INFO", 'PDFMaker');
     $CUI_BLOCKS["Logged"] = vtranslate("LBL_LOGGED_USER_INFO", 'PDFMaker');
     $viewer->assign("CUI_BLOCKS", $CUI_BLOCKS);
     $adb = PearDatabase::getInstance();
     $sql = "SELECT * FROM vtiger_organizationdetails";
     $result = $adb->pquery($sql, array());
     $organization_logoname = decode_html($adb->query_result($result, 0, 'logoname'));
     $organization_header = decode_html($adb->query_result($result, 0, 'headername'));
     $organization_stamp_signature = $adb->query_result($result, 0, 'stamp_signature');
     global $site_URL;
     $path = $site_URL . "/test/logo/";
     if (isset($organization_logoname)) {
         $organization_logo_img = "<img src=\"" . $path . $organization_logoname . "\">";
         $viewer->assign("COMPANYLOGO", $organization_logo_img);
     }
     if (isset($organization_stamp_signature)) {
         $organization_stamp_signature_img = "<img src=\"" . $path . $organization_stamp_signature . "\">";
         $viewer->assign("COMPANY_STAMP_SIGNATURE", $organization_stamp_signature_img);
     }
     if (isset($organization_header)) {
         $organization_header_img = "<img src=\"" . $path . $organization_header . "\">";
         $viewer->assign("COMPANY_HEADER_SIGNATURE", $organization_header_img);
     }
     $Acc_Info = array('' => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "COMPANY_NAME" => vtranslate("LBL_COMPANY_NAME", 'PDFMaker'), "COMPANY_LOGO" => vtranslate("LBL_COMPANY_LOGO", 'PDFMaker'), "COMPANY_ADDRESS" => vtranslate("LBL_COMPANY_ADDRESS", 'PDFMaker'), "COMPANY_CITY" => vtranslate("LBL_COMPANY_CITY", 'PDFMaker'), "COMPANY_STATE" => vtranslate("LBL_COMPANY_STATE", 'PDFMaker'), "COMPANY_ZIP" => vtranslate("LBL_COMPANY_ZIP", 'PDFMaker'), "COMPANY_COUNTRY" => vtranslate("LBL_COMPANY_COUNTRY", 'PDFMaker'), "COMPANY_PHONE" => vtranslate("LBL_COMPANY_PHONE", "PDFMaker"), "COMPANY_FAX" => vtranslate("LBL_COMPANY_FAX", 'PDFMaker'), "COMPANY_WEBSITE" => vtranslate("LBL_COMPANY_WEBSITE", 'PDFMaker'));
     $viewer->assign("ACCOUNTINFORMATIONS", $Acc_Info);
     $sql_user_block = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid=29 ORDER BY sequence ASC";
     $res_user_block = $adb->query($sql_user_block);
     $user_block_info_arr = array();
     while ($row_user_block = $adb->fetch_array($res_user_block)) {
         $sql_user_field = "SELECT fieldid, uitype FROM vtiger_field WHERE block=" . $row_user_block['blockid'] . " and (displaytype != 3 OR uitype = 55) ORDER BY sequence ASC";
         $res_user_field = $adb->query($sql_user_field);
         $num_user_field = $adb->num_rows($res_user_field);
         if ($num_user_field > 0) {
             $user_field_id_array = array();
             while ($row_user_field = $adb->fetch_array($res_user_field)) {
                 $user_field_id_array[] = $row_user_field['fieldid'];
                 // print_r($user_field_id_array);
             }
             $user_block_info_arr[$row_user_block['blocklabel']] = $user_field_id_array;
         }
     }
     $user_mod_strings = $this->getModuleLanguageArray("Users");
     $b = 0;
     foreach ($user_block_info_arr as $block_label => $block_fields) {
         $b++;
         if (isset($user_mod_strings[$block_label]) and $user_mod_strings[$block_label] != "") {
             $optgroup_value = $user_mod_strings[$block_label];
         } else {
             $optgroup_value = vtranslate($block_label, 'PDFMaker');
         }
         if (count($block_fields) > 0) {
             $field_ids = implode(",", $block_fields);
             $sql1 = "SELECT * FROM vtiger_field WHERE fieldid IN (" . $field_ids . ")";
             $result1 = $adb->query($sql1);
             while ($row1 = $adb->fetchByAssoc($result1)) {
                 $fieldname = $row1['fieldname'];
                 $fieldlabel = $row1['fieldlabel'];
                 $option_key = strtoupper("Users" . "_" . $fieldname);
                 if (isset($current_mod_strings[$fieldlabel]) and $current_mod_strings[$fieldlabel] != "") {
                     $option_value = $current_mod_strings[$fieldlabel];
                 } elseif (isset($app_strings[$fieldlabel]) and $app_strings[$fieldlabel] != "") {
                     $option_value = $app_strings[$fieldlabel];
                 } else {
                     $option_value = $fieldlabel;
                 }
                 $User_Info[$optgroup_value][$option_key] = $option_value;
                 $Logged_User_Info[$optgroup_value]["R_" . $option_key] = $option_value;
             }
         }
         //variable RECORD ID added
         if ($b == 1) {
             $option_value = "Record ID";
             $option_key = strtoupper("USERS_CRMID");
             $User_Info[$optgroup_value][$option_key] = $option_value;
             $Logged_User_Info[$optgroup_value]["R_" . $option_key] = $option_value;
         }
         //end
     }
     // ****************************************** END: Company and User information **********************************
     $viewer->assign("USERINFORMATIONS", $User_Info);
     $viewer->assign("LOGGEDUSERINFORMATION", $Logged_User_Info);
     $Invterandcon = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "TERMS_AND_CONDITIONS" => vtranslate("LBL_TERMS_AND_CONDITIONS", 'PDFMaker'));
     $viewer->assign("INVENTORYTERMSANDCONDITIONS", $Invterandcon);
     //labels
     $global_lang_labels = @array_flip($app_strings);
     $global_lang_labels = @array_flip($global_lang_labels);
     asort($global_lang_labels);
     $viewer->assign("GLOBAL_LANG_LABELS", $global_lang_labels);
     $module_lang_labels = array();
     if ($select_module != "") {
         $mod_lang = $this->getModuleLanguageArray($select_module);
         $module_lang_labels = @array_flip($mod_lang);
         $module_lang_labels = @array_flip($module_lang_labels);
         asort($module_lang_labels);
     } else {
         $module_lang_labels[""] = vtranslate("LBL_SELECT_MODULE_FIELD", 'PDFMaker');
     }
     $viewer->assign("MODULE_LANG_LABELS", $module_lang_labels);
     $Header_Footer_Strings = array("" => vtranslate("LBL_PLS_SELECT", 'PDFMaker'), "PAGE" => $app_strings["Page"], "PAGES" => $app_strings["Pages"]);
     $viewer->assign("HEADER_FOOTER_STRINGS", $Header_Footer_Strings);
     //PDF FORMAT SETTINGS
     $Formats = array("A3" => "A3", "A4" => "A4", "A5" => "A5", "A6" => "A6", "Letter" => "Letter", "Legal" => "Legal", "Custom" => "Custom");
     // ITS4YOU VlZa
     $viewer->assign("FORMATS", $Formats);
     if (strpos($select_format, ";") > 0) {
         $tmpArr = explode(";", $select_format);
         $select_format = "Custom";
         $custom_format["width"] = $tmpArr[0];
         $custom_format["height"] = $tmpArr[1];
         $viewer->assign("CUSTOM_FORMAT", $custom_format);
     }
     $viewer->assign("SELECT_FORMAT", $select_format);
     //PDF ORIENTATION SETTINGS
     $Orientations = array("portrait" => vtranslate("portrait", 'PDFMaker'), "landscape" => vtranslate("landscape", 'PDFMaker'));
     $viewer->assign("ORIENTATIONS", $Orientations);
     $viewer->assign("SELECT_ORIENTATION", $select_orientation);
     //PDF MARGIN SETTINGS
     if ($request->has("templateid") && !$request->isEmpty("templateid")) {
         $Margins = array("top" => $pdftemplateResult["margin_top"], "bottom" => $pdftemplateResult["margin_bottom"], "left" => $pdftemplateResult["margin_left"], "right" => $pdftemplateResult["margin_right"]);
         $Decimals = array("point" => $pdftemplateResult["decimal_point"], "decimals" => $pdftemplateResult["decimals"], "thousands" => $pdftemplateResult["thousands_separator"] != "sp" ? $pdftemplateResult["thousands_separator"] : " ");
     } else {
         $Margins = array("top" => "2", "bottom" => "2", "left" => "2", "right" => "2");
         $Decimals = array("point" => ",", "decimals" => "2", "thousands" => " ");
     }
     $viewer->assign("MARGINS", $Margins);
     $viewer->assign("DECIMALS", $Decimals);
     //PDF HEADER / FOOTER
     $header = "";
     $footer = "";
     if ($request->has("templateid") && !$request->isEmpty("templateid")) {
         $header = $pdftemplateResult["header"];
         $footer = $pdftemplateResult["footer"];
     }
     $viewer->assign("HEADER", $header);
     $viewer->assign("FOOTER", $footer);
     $hfVariables = array("##PAGE##" => vtranslate("LBL_CURRENT_PAGE", 'PDFMaker'), "##PAGES##" => vtranslate("LBL_ALL_PAGES", 'PDFMaker'), "##PAGE##/##PAGES##" => vtranslate("LBL_PAGE_PAGES", 'PDFMaker'));
     $viewer->assign("HEAD_FOOT_VARS", $hfVariables);
     $dateVariables = array("##DD.MM.YYYY##" => vtranslate("LBL_DATE_DD.MM.YYYY", 'PDFMaker'), "##DD-MM-YYYY##" => vtranslate("LBL_DATE_DD-MM-YYYY", 'PDFMaker'), "##MM-DD-YYYY##" => vtranslate("LBL_DATE_MM-DD-YYYY", 'PDFMaker'), "##YYYY-MM-DD##" => vtranslate("LBL_DATE_YYYY-MM-DD", 'PDFMaker'));
     $viewer->assign("DATE_VARS", $dateVariables);
     $cmod = $this->getModuleLanguageArray("Settings");
     //$cmod = return_specified_module_language($current_language, "Settings");
     $viewer->assign("CMOD", $cmod);
     //Ignored picklist values
     $pvsql = "SELECT value FROM vtiger_pdfmaker_ignorepicklistvalues";
     $pvresult = $adb->query($pvsql);
     $pvvalues = "";
     while ($pvrow = $adb->fetchByAssoc($pvresult)) {
         $pvvalues .= $pvrow["value"] . ", ";
     }
     $viewer->assign("IGNORE_PICKLIST_VALUES", rtrim($pvvalues, ", "));
     $More_Fields = array("CURRENCYNAME" => vtranslate("LBL_CURRENCY_NAME", 'PDFMaker'), "CURRENCYSYMBOL" => vtranslate("LBL_CURRENCY_SYMBOL", 'PDFMaker'), "CURRENCYCODE" => vtranslate("LBL_CURRENCY_CODE", 'PDFMaker'), "TOTALWITHOUTVAT" => vtranslate("LBL_VARIABLE_SUMWITHOUTVAT", 'PDFMaker'), "TOTALDISCOUNT" => vtranslate("LBL_VARIABLE_TOTALDISCOUNT", 'PDFMaker'), "TOTALDISCOUNTPERCENT" => vtranslate("LBL_VARIABLE_TOTALDISCOUNT_PERCENT", 'PDFMaker'), "TOTALAFTERDISCOUNT" => vtranslate("LBL_VARIABLE_TOTALAFTERDISCOUNT", 'PDFMaker'), "VAT" => vtranslate("LBL_VARIABLE_VAT", 'PDFMaker'), "VATPERCENT" => vtranslate("LBL_VARIABLE_VAT_PERCENT", 'PDFMaker'), "VATBLOCK" => vtranslate("LBL_VARIABLE_VAT_BLOCK", 'PDFMaker'), "TOTALWITHVAT" => vtranslate("LBL_VARIABLE_SUMWITHVAT", 'PDFMaker'), "SHTAXTOTAL" => vtranslate("LBL_SHTAXTOTAL", 'PDFMaker'), "SHTAXAMOUNT" => vtranslate("LBL_SHTAXAMOUNT", 'PDFMaker'), "ADJUSTMENT" => vtranslate("LBL_ADJUSTMENT", 'PDFMaker'), "TOTAL" => vtranslate("LBL_VARIABLE_TOTALSUM", 'PDFMaker'));
     //formatable VATBLOCK content
     $vatblock_table = '<table border="1" cellpadding="3" cellspacing="0" style="border-collapse:collapse;">
             		<tr>
                         <td>' . $app_strings["Name"] . '</td>
                         <td>' . vtranslate("LBL_VATBLOCK_VAT_PERCENT", 'PDFMaker') . '</td>
                         <td>' . vtranslate("LBL_VATBLOCK_SUM", 'PDFMaker') . '</td>
                         <td>' . vtranslate("LBL_VATBLOCK_VAT_VALUE", 'PDFMaker') . '</td>
                     </tr>
             		<tr>
                         <td colspan="4">#VATBLOCK_START#</td>
                     </tr>
             		<tr>
             			<td>$VATBLOCK_LABEL$</td>
             			<td>$VATBLOCK_VALUE$</td>
             			<td>$VATBLOCK_NETTO$</td>
             			<td>$VATBLOCK_VAT$</td>
             		</tr>
             		<tr>
                         <td colspan="4">#VATBLOCK_END#</td>
                     </tr>
                 </table>';
     $vatblock_table = str_replace(array("\r\n", "\r", "\n", "\t"), "", $vatblock_table);
     $vatblock_table = ereg_replace(" {2,}", ' ', $vatblock_table);
     $viewer->assign("VATBLOCK_TABLE", $vatblock_table);
     $ModCommentsModules = array();
     foreach ($ModuleIDS as $module => $IDS) {
         if ($module == 'Calendar') {
             $sql1 = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid IN (9,16) ORDER BY sequence ASC";
         } elseif ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder" || $module == "Issuecards" || $module == "Receiptcards" || $module == "Creditnote" || $module == "StornoInvoice") {
             $sql1 = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid=" . $IDS . " AND blocklabel != 'LBL_DETAILS_BLOCK' AND blocklabel != 'LBL_ITEM_DETAILS' ORDER BY sequence ASC";
         } else {
             $sql1 = "SELECT blockid, blocklabel FROM vtiger_blocks WHERE tabid=" . $IDS . " ORDER BY sequence ASC";
         }
         $res1 = $adb->query($sql1);
         $block_info_arr = array();
         while ($row = $adb->fetch_array($res1)) {
             if ($row['blockid'] == '41' && $row['blocklabel'] == '') {
                 $row['blocklabel'] = 'LBL_EVENT_INFORMATION';
             }
             $sql2 = "SELECT fieldid, uitype, columnname, fieldlabel\n                 FROM vtiger_field\n                 WHERE block=" . $row['blockid'] . "\n                    AND (displaytype != 3 OR uitype = 55)\n                 ORDER BY sequence ASC";
             $res2 = $adb->query($sql2);
             $num_rows2 = $adb->num_rows($res2);
             if ($num_rows2 > 0) {
                 $field_id_array = array();
                 while ($row2 = $adb->fetch_array($res2)) {
                     $field_id_array[] = $row2['fieldid'];
                     $tmpArr = array($row2["columnname"], $row2["fieldlabel"]);
                     switch ($row2['uitype']) {
                         case "51":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Accounts");
                             break;
                         case "57":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Contacts");
                             break;
                         case "58":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Campaigns");
                             break;
                         case "59":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Products");
                             break;
                         case "73":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Accounts");
                             break;
                         case "75":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Vendors");
                             break;
                         case "81":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Vendors");
                             break;
                         case "76":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Potentials");
                             break;
                         case "78":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Quotes");
                             break;
                         case "80":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "SalesOrder");
                             break;
                         case "68":
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Accounts");
                             $All_Related_Modules[$module][] = array_merge($tmpArr, (array) "Contacts");
                             break;
                         case "10":
                             $fmrs = $adb->query('SELECT relmodule FROM vtiger_fieldmodulerel WHERE fieldid=' . $row2['fieldid']);
                             while ($rm = $adb->fetch_array($fmrs)) {
                                 $All_Related_Modules[$module][] = array_merge($tmpArr, (array) $rm['relmodule']);
                             }
                             break;
                     }
                 }
                 // ITS4YOU MaJu
                 //$block_info_arr[$row['blocklabel']] = $field_id_array;
                 if (!empty($block_info_arr[$row['blocklabel']])) {
                     foreach ($field_id_array as $field_id_array_value) {
                         $block_info_arr[$row['blocklabel']][] = $field_id_array_value;
                     }
                 } else {
                     $block_info_arr[$row['blocklabel']] = $field_id_array;
                 }
                 // ITS4YOU-END
             }
         }
         if ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder") {
             $block_info_arr["LBL_DETAILS_BLOCK"] = array();
         }
         //ModComments support
         //if (in_array($module, $ModCommentsModules)) {
         //    $block_info_arr["TEMP_MODCOMMENTS_BLOCK"] = array();
         //}
         $ModuleFields[$module] = $block_info_arr;
     }
     //Permissions are taken into consideration when dealing with realted modules
     $AllowedRelMods = array();
     if (count($All_Related_Modules) > 0) {
         foreach ($All_Related_Modules as $Mod => $RelMods) {
             foreach ($RelMods as $RelModKey => $RelMod) {
                 $RelModName = $RelMod[2];
                 if (isPermitted($RelModName, '') == "yes") {
                     $AllowedRelMods[$Mod][$RelModKey] = $RelMod;
                 }
             }
         }
     }
     $All_Related_Modules = $AllowedRelMods;
     // Fix of emtpy selectbox in case of selected module does not have any related modules
     foreach ($Modulenames as $key => $value) {
         if (!isset($All_Related_Modules[$key])) {
             $All_Related_Modules[$key] = array();
         }
     }
     $viewer->assign("ALL_RELATED_MODULES", $All_Related_Modules);
     if ($select_module != "" && count($All_Related_Modules[$select_module]) > 0) {
         foreach ($All_Related_Modules[$select_module] as $RelModArr) {
             $Related_Modules[$RelModArr[2] . "|" . $RelModArr[0]] = vtranslate($RelModArr[2]) . " (" . $RelModArr[1] . ")";
         }
     }
     $viewer->assign("RELATED_MODULES", $Related_Modules);
     $tacModules = array();
     $tac4you = is_numeric(getTabId("Tac4you"));
     if ($tac4you == true) {
         $sql = "SELECT tac4you_module FROM vtiger_tac4you_module WHERE presence = 1";
         $result = $adb->query($sql);
         while ($row = $adb->fetchByAssoc($result)) {
             $tacModules[$row["tac4you_module"]] = $row["tac4you_module"];
         }
     }
     $desc4youModules = array();
     $desc4you = is_numeric(getTabId("Descriptions4you"));
     if ($desc4you == true) {
         $sql = "SELECT b.name FROM vtiger_links AS a\n             INNER JOIN vtiger_tab AS b USING (tabid)\n             WHERE linktype = 'DETAILVIEWWIDGET'\n                AND linkurl = 'block://ModDescriptions4you:modules/Descriptions4you/ModDescriptions4you.php'";
         $result = $adb->query($sql);
         while ($row = $adb->fetchByAssoc($result)) {
             $desc4youModules[$row["name"]] = $row["name"];
         }
     }
     $Settings_Profiles_Record_Model = new Settings_Profiles_Record_Model();
     foreach ($ModuleFields as $module => $Blocks) {
         $Optgroupts = array();
         $current_mod_strings = $this->getModuleLanguageArray($module);
         $moduleModel = Vtiger_Module_Model::getInstance($module);
         $b = 0;
         if ($module == 'Calendar') {
             $b++;
             $Optgroupts[] = '"' . vtranslate('Calendar') . '","' . $b . '"';
             $Convert_ModuleFields['Calendar|1'] .= ',"Record ID","CALENDAR_CRMID"';
             $SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"] = "Record ID";
             $EventModel = Vtiger_Module_Model::getInstance('Events');
         }
         foreach ($Blocks as $block_label => $block_fields) {
             $b++;
             $Options = array();
             if ($block_label != "TEMP_MODCOMMENTS_BLOCK") {
                 $optgroup_value = vtranslate($block_label, $module);
                 if ($optgroup_value == $block_label) {
                     $optgroup_value = vtranslate($block_label, 'PDFMaker');
                 }
             } else {
                 $optgroup_value = vtranslate("LBL_MODCOMMENTS_INFORMATION", 'PDFMaker');
             }
             $Optgroupts[] = '"' . $optgroup_value . '","' . $b . '"';
             if (count($block_fields) > 0) {
                 $field_ids = implode(",", $block_fields);
                 $sql1 = "SELECT * FROM vtiger_field WHERE fieldid IN (" . $field_ids . ")";
                 $result1 = $adb->query($sql1);
                 while ($row1 = $adb->fetchByAssoc($result1)) {
                     $fieldname = $row1['fieldname'];
                     $fieldlabel = $row1['fieldlabel'];
                     $fieldModel = Vtiger_Field_Model::getInstance($fieldname, $moduleModel);
                     if (!$fieldModel || !$fieldModel->getPermissions('readonly')) {
                         if ($module == 'Calendar') {
                             $eventFieldModel = Vtiger_Field_Model::getInstance($fieldname, $EventModel);
                             if (!$eventFieldModel || !$eventFieldModel->getPermissions('readonly')) {
                                 continue;
                             }
                         } else {
                             continue;
                         }
                     }
                     $option_key = strtoupper($module . "_" . $fieldname);
                     if (isset($current_mod_strings[$fieldlabel]) and $current_mod_strings[$fieldlabel] != "") {
                         $option_value = $current_mod_strings[$fieldlabel];
                     } elseif (isset($app_strings[$fieldlabel]) and $app_strings[$fieldlabel] != "") {
                         $option_value = $app_strings[$fieldlabel];
                     } else {
                         $option_value = $fieldlabel;
                     }
                     if ($module == 'Calendar') {
                         if ($option_key == 'CALENDAR_ACTIVITYTYPE' || $option_key == 'CALENDAR_DUE_DATE') {
                             $Convert_ModuleFields['Calendar|1'] .= ',"' . $option_value . '","' . $option_key . '"';
                             $SelectModuleFields['Calendar'][vtranslate('Calendar')][$option_key] = $option_value;
                             continue;
                         } elseif (!isset($Existing_ModuleFields[$option_key])) {
                             $Existing_ModuleFields[$option_key] = $optgroup_value;
                         } else {
                             $Convert_ModuleFields['Calendar|1'] .= ',"' . $option_value . '","' . $option_key . '"';
                             $SelectModuleFields['Calendar'][vtranslate('Calendar')][$option_key] = $option_value;
                             $Unset_Module_Fields[] = '"' . $option_value . '","' . $option_key . '"';
                             unset($SelectModuleFields['Calendar'][$Existing_ModuleFields[$option_key]][$option_key]);
                             continue;
                         }
                     }
                     $Options[] = '"' . $option_value . '","' . $option_key . '"';
                     $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
                 }
             }
             //variable RECORD ID added
             if ($b == 1) {
                 $option_value = "Record ID";
                 $option_key = strtoupper($module . "_CRMID");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
                 $option_value = vtranslate('Created Time') . ' (' . vtranslate('Due Date & Time') . ')';
                 $option_key = strtoupper($module . "_CREATEDTIME_DATETIME");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
                 $option_value = vtranslate('Modified Time') . ' (' . vtranslate('Due Date & Time') . ')';
                 $option_key = strtoupper($module . "_MODIFIEDTIME_DATETIME");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             //end
             if ($block_label == "LBL_TERMS_INFORMATION" && isset($tacModules[$module])) {
                 $option_value = vtranslate("LBL_TAC4YOU", 'PDFMaker');
                 $option_key = strtoupper($module . "_TAC4YOU");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             if ($block_label == "LBL_DESCRIPTION_INFORMATION" && isset($desc4youModules[$module])) {
                 $option_value = vtranslate("LBL_DESC4YOU", 'PDFMaker');
                 $option_key = strtoupper($module . "_DESC4YOU");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             //ModComments support
             if ($block_label == "TEMP_MODCOMMENTS_BLOCK" && in_array($module, $ModCommentsModules) == true) {
                 $option_value = vtranslate("LBL_MODCOMMENTS", 'PDFMaker');
                 $option_key = strtoupper($module . "_MODCOMMENTS");
                 $Options[] = '"' . $option_value . '","' . $option_key . '"';
                 $SelectModuleFields[$module][$optgroup_value][$option_key] = $option_value;
             }
             $Convert_RelatedModuleFields[$module . "|" . $b] = implode(",", $Options);
             $OptionsRelMod = array();
             if (($block_label == "LBL_DETAILS_BLOCK" || $block_label == "LBL_ITEM_DETAILS") && ($module == "Quotes" || $module == "Invoice" || $module == "SalesOrder" || $module == "PurchaseOrder" || $module == "Issuecards" || $module == "Receiptcards" || $module == "Creditnote" || $module == "StornoInvoice")) {
                 foreach ($More_Fields as $variable => $variable_name) {
                     $variable_key = strtoupper($variable);
                     $Options[] = '"' . $variable_name . '","' . $variable_key . '"';
                     $SelectModuleFields[$module][$optgroup_value][$variable_key] = $variable_name;
                     if ($variable_key != "VATBLOCK") {
                         $OptionsRelMod[] = '"' . $variable_name . '","' . strtoupper($module) . '_' . $variable_key . '"';
                     }
                 }
             }
             //this concatenation is because of need to have extra Details block in Inventory modules which are as related modules
             $Convert_RelatedModuleFields[$module . "|" . $b] .= implode(',', $OptionsRelMod);
             $Convert_ModuleFields[$module . "|" . $b] = implode(",", $Options);
         }
         if ($module == 'Calendar') {
             $Convert_ModuleFields['Calendar|1'] = str_replace(',"Record ID","CALENDAR_CRMID",', "", $Convert_ModuleFields['Calendar|1']);
             $Convert_ModuleFields['Calendar|1'] .= ',"Record ID","CALENDAR_CRMID"';
             unset($SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"]);
             $SelectModuleFields['Calendar'][vtranslate('Calendar')]["CALENDAR_CRMID"] = "Record ID";
         }
         $Convert_ModuleBlocks[$module] = implode(",", $Optgroupts);
     }
     foreach ($Convert_ModuleFields as $cmf_key => $cmf_value) {
         if (substr($cmf_key, 0, 9) == 'Calendar|' && $cmf_key != 'Calendar|1') {
             foreach ($Unset_Module_Fields as $to_unset) {
                 $cmf_value = str_replace($to_unset, '', $cmf_value);
                 $cmf_value = str_replace(",,", ',', $cmf_value);
                 $Convert_ModuleFields[$cmf_key] = trim($cmf_value, ',');
             }
         }
     }
     $viewer->assign("MODULE_BLOCKS", $Convert_ModuleBlocks);
     $viewer->assign("RELATED_MODULE_FIELDS", $Convert_RelatedModuleFields);
     $viewer->assign("MODULE_FIELDS", $Convert_ModuleFields);
     //Product block fields start
     // Product bloc templates
     $sql = "SELECT * FROM vtiger_pdfmaker_productbloc_tpl";
     $result = $adb->query($sql);
     $Productbloc_tpl[""] = vtranslate("LBL_PLS_SELECT", 'PDFMaker');
     while ($row = $adb->fetchByAssoc($result)) {
         $Productbloc_tpl[$row["body"]] = $row["name"];
     }
     $viewer->assign("PRODUCT_BLOC_TPL", $Productbloc_tpl);
     $ProductBlockFields = $PDFMaker->GetProductBlockFields();
     foreach ($ProductBlockFields as $viewer_key => $pbFields) {
         $viewer->assign($viewer_key, $pbFields);
     }
     //Product block fields end
     $viewer->assign("SELECT_MODULE_FIELD", $SelectModuleFields[$select_module]);
     $smf_filename = $SelectModuleFields[$select_module];
     unset($smf_filename["Details"]);
     $viewer->assign("SELECT_MODULE_FIELD_FILENAME", $smf_filename);
     $version_type = ucfirst($PDFMaker->GetVersionType());
     $viewer->assign("VERSION", $version_type . " " . PDFMaker_Version_Helper::$version);
     $category = getParentTab();
     $viewer->assign("CATEGORY", $category);
     $viewer->view('Edit.tpl', 'PDFMaker');
 }
 public function process(Vtiger_Request $request)
 {
     $adb = PearDatabase::getInstance();
     $cu_model = Users_Record_Model::getCurrentUserModel();
     switch ($request->get("handler")) {
         case "fill_lang":
             $module = addslashes($request->get("langmod"));
             $mod_lang_big = Vtiger_Language_Handler::getModuleStringsFromFile($cu_model->get('language'), $module);
             $mod_lang = $mod_lang_big['languageStrings'];
             unset($mod_lang_big);
             $module_lang_labels = array_flip($mod_lang);
             $module_lang_labels = array_flip($module_lang_labels);
             asort($module_lang_labels);
             $keys = implode('||', array_keys($module_lang_labels));
             $values = implode('||', $module_lang_labels);
             echo $keys . '|@|' . $values;
             break;
         case "confirm_portal":
             $module = addslashes($request->get("langmod"));
             $curr_templatename = $request->get("curr_templatename");
             $sql = "SELECT filename\n                FROM vtiger_pdfmaker\n                INNER JOIN vtiger_pdfmaker_settings USING(templateid)\n                WHERE is_portal=? AND module=?";
             $params = array("1", $module);
             $result = $adb->pquery($sql, $params);
             $confirm = "";
             if ($adb->num_rows($result) > 0) {
                 $templatename = $adb->query_result($result, 0, "filename");
                 $confirm = vtranslate("LBL_PDFMAKER_TEMPLATE", 'PDFMaker') . " '" . $templatename . "' " . vtranslate("LBL_REPLACED_PORTAL_TEMPLATE", 'PDFMaker') . " '" . $curr_templatename . "' " . vtranslate("LBL_AS_PORTAL_TEMPLATE", 'PDFMaker');
             } else {
                 $confirm = vtranslate("LBL_VTIGER_TEMPLATE", 'PDFMaker') . " " . vtranslate("LBL_REPLACED_PORTAL_TEMPLATE", 'PDFMaker') . " '" . $curr_templatename . "' " . vtranslate("LBL_AS_PORTAL_TEMPLATE", 'PDFMaker');
             }
             echo $confirm;
             break;
         case "templates_order":
             $inStr = $request->get("tmpl_order");
             $inStr = rtrim($inStr, "#");
             $inArr = explode("#", $inStr);
             $tmplArr = array();
             foreach ($inArr as $val) {
                 $valArr = explode("_", $val);
                 $tmplArr[$valArr[0]]["order"] = $valArr[1];
                 $tmplArr[$valArr[0]]["is_active"] = "1";
                 $tmplArr[$valArr[0]]["is_default"] = "0";
             }
             $sql = "SELECT templateid, userid, is_active, is_default, sequence\n                FROM vtiger_pdfmaker_userstatus\n                WHERE userid = ?";
             $result = $adb->pquery($sql, array($cu_model->getId()));
             while ($row = $adb->fetchByAssoc($result)) {
                 if (!isset($tmplArr[$row["templateid"]])) {
                     $tmplArr[$row["templateid"]]["order"] = $row["sequence"];
                 }
                 $tmplArr[$row["templateid"]]["is_active"] = $row["is_active"];
                 $tmplArr[$row["templateid"]]["is_default"] = $row["is_default"];
             }
             $adb->pquery("DELETE FROM vtiger_pdfmaker_userstatus WHERE userid=?", array($cu_model->getId()));
             $sqlA = "INSERT INTO vtiger_pdfmaker_userstatus(templateid, userid, is_active, is_default, sequence)\n                VALUES ";
             $sqlB = "";
             $params = array();
             foreach ($tmplArr as $templateid => $valArr) {
                 $sqlB .= "(?,?,?,?,?),";
                 $params[] = $templateid;
                 $params[] = $cu_model->getId();
                 $params[] = $valArr["is_active"];
                 $params[] = $valArr["is_default"];
                 $params[] = $valArr["order"];
             }
             $result = "error";
             if ($sqlB != "") {
                 $sqlB = rtrim($sqlB, ",");
                 $sql = $sqlA . $sqlB;
                 $adb->pquery($sql, $params);
                 $result = "ok";
             }
             echo $result;
             break;
         case "custom_labels_edit":
             $sql = "DELETE FROM vtiger_pdfmaker_label_vals WHERE label_id=? AND lang_id=?";
             $params = array($request->get("label_id"), $request->get("lang_id"));
             $adb->pquery($sql, $params);
             $sql = "INSERT INTO vtiger_pdfmaker_label_vals(label_id, lang_id, label_value) VALUES(?,?,?)";
             $params = array($request->get("label_id"), $request->get("lang_id"), $request->get("label_value"));
             $adb->pquery($sql, $params);
             break;
         case "fill_relblocks":
             $module = addslashes($request->get("selmod"));
             $PDFMaker = new PDFMaker_PDFMaker_Model();
             $Related_Blocks = $PDFMaker->GetRelatedBlocks($module);
             $keys = implode('||', array_keys($Related_Blocks));
             $values = implode('||', $Related_Blocks);
             echo $keys . '|@|' . $values;
             break;
         case "fill_module_product_fields":
             $module = addslashes($request->get("productmod"));
             $PDFMaker = new PDFMaker_PDFMaker_Model();
             $Product_Block_Fields = $PDFMaker->GetProductBlockFields($module);
             $keys = implode('||', array_keys($Product_Block_Fields["SELECT_PRODUCT_FIELD"]));
             $values = implode('||', $Product_Block_Fields["SELECT_PRODUCT_FIELD"]);
             echo $keys . '|@|' . $values;
             break;
         case "get_relblock":
             $record = addslashes($request->get("relblockid"));
             $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 html_entity_decode($body);
             break;
         case "delete_relblock":
             $record = addslashes($request->get("relblockid"));
             //$sql = "DELETE FROM vtiger_pdfmaker_relblocks WHERE relblockid = ?";
             $sql = "UPDATE vtiger_pdfmaker_relblocks SET deleted = 1 WHERE relblockid = ?";
             $adb->pquery($sql, array($record));
             break;
         case "download_release":
             $err = $mod_strings["LBL_ERROR_TBL"] . ": ";
             if ($request->get("type") == "mpdf") {
                 $srcZip = $request->get("url");
                 $trgZip = "modules/PDFMaker/resources/mpdf.zip";
                 if (copy($srcZip, $trgZip)) {
                     require_once 'vtlib/thirdparty/dUnzip2.inc.php';
                     $unzip = new dUnzip2($trgZip);
                     $unzip->unzipAll(getcwd() . "/modules/PDFMaker/resources/");
                     if ($unzip) {
                         $unzip->close();
                     }
                     if (!is_dir("modules/PDFMaker/resources/mpdf")) {
                         $err .= $mod_strings["UNZIP_ERROR"];
                     } else {
                         $err = $mod_strings["LBL_UPDATE_SUCCESS"];
                     }
                 } else {
                     $err .= $mod_strings["DOWNLOAD_ERROR"];
                 }
             }
             echo $err;
             break;
     }
 }
Exemple #29
0
 public function handleTask(&$context)
 {
     $adb = \PearDatabase::getInstance();
     if (!getTabid('PDFMaker') || !vtlib_isModuleActive('PDFMaker')) {
         throw new \Exception('PDFMaker Extension not found!');
     }
     /* Insert here source code to execute the task */
     $recordChooser = $this->get('recordChooser');
     if (empty($recordChooser) || $recordChooser == -1) {
         throw new \Exception('You need to configure the PDFMaker Integraion.');
     }
     $recordIds = array();
     if ($recordChooser === 'current') {
         $recordIds = array($context->getId());
         $moduleName = $this->getModuleName();
     } else {
         $currentTime = microtime(true);
         $benchmark = array();
         $parts = explode("#~#", $this->get("search_module"));
         $related_module = VtUtils::getModuleName($parts[1]);
         $moduleName = $related_module;
         $logger = new \Workflow\ConditionLogger();
         $objMySQL = new \Workflow\ConditionMysql($related_module, $context);
         $objMySQL->setLogger($logger);
         $main_module = \CRMEntity::getInstance($related_module);
         $sqlCondition = $objMySQL->parse($this->get("condition"));
         $newTime = microtime(true);
         $benchmark[] = round($newTime - $currentTime, 3);
         $currentTime = $newTime;
         $sqlTables = $objMySQL->generateTables();
         if (strlen($sqlCondition) > 3) {
             $sqlCondition .= " AND vtiger_crmentity.deleted = 0";
         } else {
             $sqlCondition .= " vtiger_crmentity.deleted = 0";
         }
         $logs = $logger->getLogs();
         $this->setStat($logs);
         $sqlCondition .= " GROUP BY vtiger_crmentity.crmid ";
         $idColumn = $main_module->table_name . "." . $main_module->table_index;
         $sqlQuery = "SELECT {$idColumn} as `idCol` " . $sqlTables . " WHERE " . (strlen($sqlCondition) > 3 ? $sqlCondition : "");
         $sortField = $this->get("sort_field");
         if (!empty($sortField) && $sortField != -1) {
             $sortField = VtUtils::getColumnName($sortField);
             $sortDirection = $this->get("sortDirection");
             $sqlQuery .= " ORDER BY " . $sortField . " " . $sortDirection;
         }
         $this->addStat("MySQL Query: " . $sqlQuery);
         $result = $adb->query($sqlQuery, true);
         $newTime = microtime(true);
         $benchmark[] = round($newTime - $currentTime, 3);
         $this->addStat("num Rows: " . $adb->num_rows($result));
         # If no records are found, fo other way
         if ($adb->num_rows($result) == 0) {
             return "yes";
         }
         $this->addStat("Benchmark: " . implode("/", $benchmark));
         while ($row = $adb->fetchByAssoc($result)) {
             $recordIds[] = $row['idcol'];
         }
     }
     $context->save();
     $useUser = Users::getActiveAdminUser();
     $oldUser = vglobal('current_user');
     vglobal('current_user', $useUser);
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     $dl = Vtiger_Language_Handler::getLanguage();
     $mpdf = "";
     $copies = $this->get('copies');
     if ($copies == -1 || empty($copies)) {
         $copies = 1;
     }
     $templateids = array();
     for ($i = 0; $i < $copies; $i++) {
         $templateids = array_merge($templateids, $this->get("template"));
     }
     $filename = $PDFMaker->GetPreparedMPDF($mpdf, $recordIds, $templateids, $moduleName, $dl, '');
     if (strpos($filename, '.pdf') === false) {
         $filename .= '.pdf';
     }
     //        $filename = $PDFMaker->generate_cool_uri($filename);
     $tmpfile = tempnam(sys_get_temp_dir(), 'WfTmp');
     @unlink($tmpfile);
     $mpdf->Output($tmpfile);
     $overwriteFilename = $this->get("filename", $context);
     if ($overwriteFilename != -1 && !empty($overwriteFilename)) {
         $filename = $overwriteFilename;
     }
     \Workflow\FileAction::doActions($this->get('resultaction'), $tmpfile, $filename, $context, $recordIds, $this->getWorkflow());
     vglobal('current_user', $oldUser);
     return "yes";
 }
Exemple #30
0
 public function getList(Vtiger_Request $request)
 {
     PDFMaker_Debugger_Model::GetInstance()->Init();
     $PDFMaker = new PDFMaker_PDFMaker_Model();
     if ($PDFMaker->CheckPermissions("DETAIL") == false) {
         $PDFMaker->DieDuePermission();
     }
     $viewer = $this->getViewer($request);
     $orderby = "templateid";
     $dir = "asc";
     if (isset($_REQUEST["dir"]) && $_REQUEST["dir"] == "desc") {
         $dir = "desc";
     }
     if (isset($_REQUEST["orderby"])) {
         switch ($_REQUEST["orderby"]) {
             case "name":
                 $orderby = "filename";
                 break;
             case "module":
                 $orderby = "module";
                 break;
             case "description":
                 $orderby = "description";
                 break;
             case "order":
                 $orderby = "order";
                 break;
             default:
                 $orderby = $_REQUEST["orderby"];
                 break;
         }
     }
     $version_type = $PDFMaker->GetVersionType();
     $license_key = $PDFMaker->GetLicenseKey();
     $viewer->assign("VERSION_TYPE", $version_type);
     $viewer->assign("VERSION", ucfirst($version_type) . " " . PDFMaker_Version_Helper::$version);
     $viewer->assign("LICENSE_KEY", $license_key);
     // $to_update = "false";
     // $smarty->assign("TO_UPDATE",$to_update);
     if ($PDFMaker->CheckPermissions("EDIT")) {
         $viewer->assign("EXPORT", "yes");
     }
     if ($PDFMaker->CheckPermissions("EDIT") && $PDFMaker->GetVersionType() != "deactivate") {
         $viewer->assign("EDIT", "permitted");
         $viewer->assign("IMPORT", "yes");
     }
     if ($PDFMaker->CheckPermissions("DELETE") && $PDFMaker->GetVersionType() != "deactivate") {
         $viewer->assign("DELETE", "permitted");
     }
     $notif = $PDFMaker->GetReleasesNotif();
     $viewer->assign("RELEASE_NOTIF", $notif);
     $php_version = phpversion();
     $notif = false;
     $max_in_vars = ini_get("max_input_vars");
     if ($max_in_vars <= 1000 && $php_version >= "5.3.9") {
         $notif = true;
     }
     $test = ini_set("memory_limit", "256M");
     $memory_limit = ini_get("memory_limit");
     if (substr($memory_limit, 0, -1) <= 128) {
         $notif = true;
     }
     $max_exec_time = ini_get("max_execution_time");
     if ($max_exec_time <= 60) {
         $notif = true;
     }
     if (extension_loaded('suhosin')) {
         $request_max_vars = ini_get("suhosin.request.max_vars");
         $post_max_vars = ini_get("suhosin.post.max_vars");
         if ($request_max_vars <= 1000) {
             $notif = true;
         }
         if ($post_max_vars <= 1000) {
             $notif = true;
         }
     }
     if ($notif === true) {
         //$notif = '<a href="index.php?module=PDFMaker&action=Debugging&parenttab=Settings" title="' . vtranslate("LBL_GOTO_DEBUG","PDFMaker") . '" style="color:red;">' . vtranslate("LBL_DBG_NOTIF","PDFMaker") . '</a>';
         //$viewer->assign("DEBUG_NOTIF", $notif);
     }
     $viewer->assign("MOD", $mod_strings);
     $viewer->assign("APP", $app_strings);
     $viewer->assign("THEME", $theme);
     $viewer->assign("PARENTTAB", getParentTab());
     $viewer->assign("IMAGE_PATH", $image_path);
     $viewer->assign("ORDERBY", $orderby);
     $viewer->assign("DIR", $dir);
     $return_data = $PDFMaker->GetListviewData($orderby, $dir);
     $viewer->assign("PDFTEMPLATES", $return_data);
     $category = getParentTab();
     $viewer->assign("CATEGORY", $category);
     if (is_admin($current_user)) {
         $viewer->assign('IS_ADMIN', '1');
     }
     //$tool_buttons = Button_Check($currentModule);
     //$viewer->assign('CHECK', $tool_buttons);
     $linkParams = array('MODULE' => $moduleName, 'ACTION' => $request->get('view'));
     $linkModels = $PDFMaker->getListViewLinks($linkParams);
     $viewer->assign('LISTVIEW_MASSACTIONS', $linkModels['LISTVIEWMASSACTION']);
     $viewer->assign('LISTVIEW_LINKS', $linkModels);
     $tpl = "ListPDFTemplates";
     if ($request->get('ajax') == "true") {
         $tpl .= "Contents";
     }
     $viewer->view($tpl . ".tpl", 'PDFMaker');
 }