Esempio n. 1
0
 /**
  * @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";
 }
Esempio n. 2
0
 public function getFilename()
 {
     global $x0b, $x0c, $x0d, $x0e, $x0f, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x1a, $x1b, $x1c, $x1d, $x1e, $x1f, $x20, $x21, $x22, $x23, $x24, $x25, $x26;
     $this->content = $this->filename;
     $this->replacements["\$#TEMPLATE_NAME#\$"] = $this->templatename;
     $this->replacements["\$#DD-MM-YYYY#\$"] = $x10("d-m-Y");
     $this->replacements["\$#MM-DD-YYYY#\$"] = $x10("m-d-Y");
     $this->replacements["\$#YYYY-MM-DD#\$"] = $x10("Y-m-d");
     $this->replacements["\$" . $x22($this->module) . "_CRMID\$"] = $this->focus->id;
     $this->x0e($this->module, $this->focus);
     $this->replacements = array();
     $this->replacements["\r\\156"] = "";
     $this->replacements["\\n\\r"] = "";
     $this->replacements["\\n"] = "";
     $this->replacements["\\162"] = "";
     $this->x12();
     return $x24(generate_cool_uri($x20($x14($this->content, ENT_QUOTES, "utf-8"))), 0, 255);
 }