public function downloadMPDF(Vtiger_Request $request) { $error == ""; $srcZip = "http://www.crm4you.sk/PDFMaker/src/mpdf.zip"; $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")) { $error = vtranslate("UNZIP_ERROR", 'PDFMaker'); $viewer->assign("STEP", "error"); $viewer->assign("ERROR_TBL", $errTbl); } } else { $error = vtranslate("DOWNLOAD_ERROR", 'PDFMaker'); } if ($error == "") { $result = array('success' => true, 'message' => ''); } else { $result = array('success' => false, 'message' => $error); } $response = new Vtiger_Response(); $response->setResult($result); $response->emit(); }
$theme_path = "themes/" . $theme_path . "/"; $image_path = $theme_path . "images/"; $smarty->assign("THEME", $theme_path); $smarty->assign("IMAGE_PATH", $image_path); $smarty->assign("MOD", $mod_strings); $smarty->assign("APP", $app_strings); if ($_REQUEST["installtype"] == "download_src") { $errTbl = array(); $srcZip = "http://www.crm4you.sk/PDFMaker/src/mpdf5.zip"; $trgZip = "modules/PDFMaker/mpdf.zip"; if (copy($srcZip, $trgZip)) { require_once 'vtlib/thirdparty/dUnzip2.inc.php'; $unzip = new dUnzip2($trgZip); $unzip->unzipAll(getcwd() . "/modules/PDFMaker/"); if ($unzip) { $unzip->close(); } if (!is_dir("modules/PDFMaker/mpdf")) { $errTbl[] = $mod_strings["UNZIP_ERROR"]; $smarty->assign("STEP", "error"); $smarty->assign("ERROR_TBL", $errTbl); } else { unlink($trgZip); $smarty->assign("STEP", "2"); $smarty->assign("CURRENT_STEP", "3"); $smarty->assign("TOTAL_STEPS", "4"); $smarty->assign("STEPNAME", $mod_strings["LBL_INSTALL_SELECTION"]); $smarty->assign("P_ERRORS", $p_errors); } } else { $errTbl[] = $mod_strings["DOWNLOAD_ERROR"];
/** * Check the Attemted Uploads for errors etc if everything goes good move the file, to the upload_dir. * * @param array $object * @return unknown */ public function upload($object) { $errors =& $this->errors; if (empty($errors['general'])) { if (empty($this->upload_dir)) { $this->upload_dir = dirname(__FILE__) . '/'; } //if no default upload_dir has been specified used the current dir. if ($this->check_dir($this->upload_dir)) { $files = $_FILES[$object]; //$count = count($files['name']) - 1; /*echo '<pre>'; var_dump($files); echo '</pre>';*/ $error = ''; try { //check for $_FILES Errors switch ($files['error']) { case 0: break; case 1: $error = $files['name'] . ' exceeds the upload_max_filesize directive in php.ini'; break; case 2: $error = $files['name'] . ' exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; break; case 3: $error = $files['name'] . ' was only partially uploaded'; break; case 4: $error = 'No file was uploaded'; break; case 6: $error = 'Missing a temporary folder'; break; case 7: $error = 'Failed to write ' . $files['name'] . ' to disk'; break; case 8: $error = $files['name'] . ' stopped by extension'; break; default: $error = 'Unidentified Error, caused by ' . $files['name']; break; } if ($error) { throw new TrigerErrorException($error, $files['name']); } //check that the file is not empty if ($files['size'] <= 0) { throw new TrigerErrorException($files['name'] . ' is empty', $files['name']); } //check that the file does not exceed the defined max_file_size if ($this->max_file_size) { if ($files['size'] >= $this->max_file_size) { throw new TrigerErrorException($files['name'] . ' exceeds defined max_file_size', $files['name']); } } if ($this->check_file_type == 'allowed' && !in_array($files['type'], $this->allowed_mime_types)) { throw new TrigerErrorException($files['name'] . ' is not an allowed type', $files['name']); } elseif ($this->check_file_type == 'denied' && in_array($files['type'], $this->denied_mime_types)) { throw new TrigerErrorException($files['name'] . ' is a denied type', $files['name']); } //if make_safe is true call make safe function if ($this->make_safe) { $files['name'] = $this->make_safe($files['name']); } //if overwrite is false and the file exists error if (!$this->overwrite && file_exists($this->upload_dir . $files['name'])) { throw new TrigerErrorException($files['name'] . ' already exsists', $files['name']); } //move the uploaded file, error if anything goes wrong. if (!move_uploaded_file($files['tmp_name'], $this->upload_dir . $files['name'])) { throw new TrigerErrorException($files['name'] . ' could not be moved', $files['name']); } // Check if zip... then unzip it if (in_array($files['type'], $this->zip_mime_types)) { include_once '../classes/dUnzip/dUnzip2.inc.php'; include_once '../classes/dUnzip/dZip.inc.php'; $zip = new dUnzip2($this->upload_dir . $files['name']); $zip->debug = false; $zip->getList(); $zip->unzipAll($this->upload_dir); $zip->close(); @unlink($this->upload_dir . $files['name']); } } catch (TrigerErrorException $e) { $errors[$files['name']][] = $e->Message(); } if (empty($errors)) { //return true if there where no errors return true; } else { //return the errors array if there where any errros return $errors; } } else { //return false as dir is not valid $errors['general'][] = "The Specified Dir is Not Valid or is Not Writeable"; return false; } } }
private function unzip($zipfile) { $ret = false; $zip = new dUnzip2($zipfile); $zip->debug = false; $list = $zip->getList(); if ($list) { foreach ($list as $fileName => $zippedFile) { if (substr($fileName, -1) != "/") { // unzip to a temporary file $tempFile = $this->tempFileName(); $zip->unzip($fileName, $tempFile); $ret = array("fileName" => $fileName, "filePath" => $tempFile); break; } } } $zip->close(); return $ret; }
} else { if ($file_to_create[2] == "rlt") { $fp = fopen($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], "w"); fwrite($fp, $file_to_create[1]); fclose($fp); $template_check_rlt = $file_to_create[1]; chmod($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], 0777); } else { $fp = fopen($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], "w"); fwrite($fp, $file_to_create[1]); fclose($fp); chmod($xerte_toolkits_site->import_path . $this_dir . $file_to_create[0], 0777); } } } $zip->close(); unlink($new_file_name); /* * use the template attributes to make the folders required and name them accordingly * * For now, ignore version * * 1. Then in template.xml (which is called data.xml at this point in time) * 2. First look in $template_data_equivalent * 3. Then in $template_check_rlt * 4. Then make it Nottingham iff template.xml contains an LO * */ $folder = ""; $data_xml_is_a_LO = false; // 1. Look in template.xml (here it is stored for the current objects
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; } }