Beispiel #1
0
 public function beforeGetTaskform($transferData)
 {
     ${"GLOBALS"}["nwklyv"] = "transferData";
     $emzpvn = "availableFileActions";
     $dboktonzzwl = "adb";
     global $current_user;
     ${$dboktonzzwl} = \PearDatabase::getInstance();
     $washibvkmmrl = "data";
     list(${$washibvkmmrl}, ${${"GLOBALS"}["kosjnvnqt"]}) = ${${"GLOBALS"}["nwklyv"]};
     ${$emzpvn} = \Workflow\FileAction::getAvailableActions($this->parameter["module"]);
     if (empty($this->parameter["width"])) {
         ${"GLOBALS"}["pnloqnoxghmc"] = "width";
         ${${"GLOBALS"}["pnloqnoxghmc"]} = 600;
     } else {
         $qdistlen = "width";
         ${$qdistlen} = intval($this->parameter["width"]);
     }
     $gsuayydy = "transferData";
     $viewer->assign("field", $this->field);
     $viewer->assign("width", ${${"GLOBALS"}["ruujows"]});
     $viewer->assign("availableFileActions", ${${"GLOBALS"}["benaiftkv"]});
     $viewer->assign("fileactions_" . $this->field, $viewer->fetch("modules/Settings/Workflow2/helpers/FileActions.tpl"));
     $this->addInlineJS(${${"GLOBALS"}["nblfndkfu"]});
     return ${$gsuayydy};
 }
 public function handleTask(&$context)
 {
     /* Insert here source code to execute the task */
     $fileid = $this->get('fileid', $context);
     $filestore = $context->getTempFiles($fileid);
     \Workflow\FileAction::doActions($this->get('resultaction'), $filestore['path'], $filestore['name'], $context, array(), $this->getWorkflow());
     return "yes";
 }
 public function handleTask(&$context)
 {
     $adb = \PearDatabase::getInstance();
     /* Insert here source code to execute the task */
     $format = $this->get('fileformat');
     $fields = $this->get('fields');
     $tmpfile = tempnam(sys_get_temp_dir(), 'CSV');
     @unlink($tmpfile);
     $source = $this->get('source');
     if ($source == -1 || $source == 'envid') {
         $env = $context->getEnvironment($this->get('recordlistid'));
     } elseif ($source == 'customview') {
         $search_module = $this->get("search_module");
         $parts = explode("#~#", $search_module);
         $searchModuleName = $parts[0];
         $queryGenerator = new \QueryGenerator($searchModuleName, \Users::getActiveAdminUser());
         $queryGenerator->initForCustomViewById($this->get('customviewsource'));
         $query = $queryGenerator->getQuery();
         $parts = preg_split('/FROM/i', $query);
         $sqlQuery = 'SELECT vtiger_crmentity.crmid as id_col FROM ' . $parts[1];
         $result = $adb->query($sqlQuery, true);
         $this->addStat("num Rows: " . $adb->num_rows($result));
         while ($row = $adb->fetchByAssoc($result)) {
             $recordids[] = $row["id_col"];
         }
         $env = array('moduleName' => $searchModuleName, 'ids' => $recordids);
     }
     $moduleName = $env['moduleName'];
     $ids = $env['ids'];
     $filename = $this->get('filename', $context);
     switch ($format) {
         case 'csv':
             $file = fopen($tmpfile, 'w');
             $headline = $this->get('insertheadline');
             if ($headline == '1') {
                 $headline = array();
                 foreach ($fields as $field) {
                     $headline[] = $field['label'];
                 }
                 fputcsv($file, $headline, ';');
             }
             foreach ($ids as $id) {
                 $record = \Workflow\VTEntity::getForId($id, $moduleName);
                 $tmp = array();
                 foreach ($fields as $field) {
                     $tmp[] = \Workflow\VTTemplate::parse($field['field'], $record);
                 }
                 fputcsv($file, $tmp, ';');
             }
             fclose($file);
             break;
         case 'excel':
             require_once $this->getAdditionalPath('phpexcel') . 'PHPExcel.php';
             // Create new PHPExcel object
             $objPHPExcel = new PHPExcel();
             // Set document properties
             $objPHPExcel->getProperties()->setCreator("Workflow Designer")->setLastModifiedBy("Workflow Designer")->setTitle("Workflow Designer Export")->setSubject("Workflow Designer Export");
             $headline = $this->get('insertheadline');
             $alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
             $currentROW = 1;
             if ($headline == '1') {
                 $headline = array();
                 foreach ($fields as $field) {
                     $headline[] = $field['label'];
                 }
                 $objPHPExcel->setActiveSheetIndex(0)->fromArray(array($headline), NULL, 'A1');
                 $currentROW++;
             }
             foreach ($ids as $id) {
                 $record = \Workflow\VTEntity::getForId($id, $moduleName);
                 $tmp = array();
                 foreach ($fields as $field) {
                     $tmp[] = \Workflow\VTTemplate::parse($field['value'], $record);
                 }
                 $objPHPExcel->getActiveSheet()->fromArray($tmp, '', 'A' . $currentROW);
                 $currentROW++;
             }
             $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
             $objWriter->save($tmpfile);
             break;
     }
     \Workflow\FileAction::doActions($this->get('resultaction'), $tmpfile, $filename, $context, $context->getId(), $this->getWorkflow());
     @unlink($tmpfile);
     return "yes";
 }
Beispiel #4
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";
 }
Beispiel #5
0
        $next_id = $adb->getUniqueID("vtiger_crmentity");
        copy($filepath, $upload_file_path . $next_id . "_" . $filename);
        $sql1 = "insert into vtiger_crmentity (crmid,smcreatorid,smownerid,setype,description,createdtime,modifiedtime) values(?, ?, ?, ?, ?, ?, ?)";
        $params1 = array($next_id, $context->get('assigned_user_id'), $context->get('assigned_user_id'), "Documents Attachment", 'Documents Attachment', date("Y-m-d H:i:s"), date("Y-m-d H:i:s"));
        $adb->pquery($sql1, $params1);
        $filetype = "application/octet-stream";
        $sql2 = "insert into vtiger_attachments(attachmentsid, name, description, type, path) values(?, ?, ?, ?, ?)";
        $params2 = array($next_id, $filename, $docDescr, $filetype, $upload_file_path);
        $adb->pquery($sql2, $params2, true);
        $sql3 = 'insert into vtiger_seattachmentsrel values(?,?)';
        $adb->pquery($sql3, array($focus->id, $next_id));
        if ($configuration["relation"] === "1") {
            foreach ($targetRecordIds as $id) {
                $sql = "INSERT INTO vtiger_senotesrel SET crmid = " . $id . ", 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 ($configuration['workflowid'] !== "") {
            $objWorkflow = new \Workflow\Main($configuration['workflowid'], false, $context->getUser());
            $objWorkflow->setContext($newContext);
            $objWorkflow->isSubWorkflow(true);
            $objWorkflow->start();
        }
    }
}
\Workflow\FileAction::register('documents', '\\Workflow\\Plugins\\FileActions\\Documents');
Beispiel #6
0
     * @param $value
     * @param $context \Workflow\VTEntity
     * @return array|void
     */
    public function doAction($configuration, $filepath, $filename, $context, $targetRecordIds = array())
    {
        if (\Workflow2::$isAjax === true) {
            $workflow = $this->getWorkflow();
            if (!empty($workflow)) {
                $id = md5(microtime(false) . rand(10000, 99999));
                copy($filepath, vglobal('root_directory') . '/modules/Workflow2/tmp/download/' . $id);
                $workflow->setSuccessRedirection('index.php?module=Workflow2&action=DownloadFile&filename=' . urlencode($filename) . '&id=' . $id);
                $workflow->setSuccessRedirectionTarget('new');
                return;
            }
        }
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-type: application/octet-stream");
        header("Content-Disposition: attachment; filename=\"" . $filename . "\"");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: " . filesize($filepath));
        @readfile($filepath);
        exit;
    }
}
\Workflow\FileAction::register('download', '\\Workflow\\Plugins\\FileActions\\Download');
Beispiel #7
0
                         )
    */
    public function getActions($moduleName)
    {
        $return = array('id' => 'filestore', 'title' => 'Store in Filestore', 'options' => array('filestoreid' => array('type' => 'templatefield', 'label' => 'Filestore ID', 'placeholder' => 'ID, which will be used to store the file'), 'filename' => array('type' => 'templatefield', 'label' => 'Filename', 'placeholder' => 'Name of file (empty use the original one)')));
        return $return;
    }
    /**
     * @param array $configuration - Array with all configuration options, the user configure
     * @param string $filepath  - The temporarily filepath of the file, which should be transformed
     * @param string $filename  - The filename of this file
     * @param \Workflow\VTEntity $context - The Context of the Workflow
     * @param array $targetRecordIds
     * @return void
     */
    public function doAction($configuration, $filepath, $filename, $context, $targetRecordIds = array())
    {
        $adb = \PearDatabase::getInstance();
        $overwrite_filename = $configuration['filename'];
        if (!empty($overwrite_filename)) {
            $filenamedata = pathinfo($filename);
            $overwrite_filename = str_replace('$extension', $filenamedata['extension'], $overwrite_filename);
            $filename = \Workflow\VTTemplate::parse($overwrite_filename, $context);
        }
        $filestoreid = $configuration['filestoreid'];
        $filestoreid = \Workflow\VTTemplate::parse($filestoreid, $context);
        $context->addTempFile($filepath, $filestoreid, $filename);
    }
}
\Workflow\FileAction::register('filestore', '\\Workflow\\Plugins\\FileActions\\Filestore');