public function save2($form, $formName, $formTitle, $formDescription, $templateCode, array $areas, $pages = 1) { $dataObject = Zend_Json::decode(bf_b64dec($templateCode)); $mdata = $dataObject['properties']; $this->db->setQuery("Select id From #__facileforms_forms Where id = " . $this->db->Quote($form) . ""); if (count($this->db->loadObjectList()) == 0) { $scriptCond1 = ""; $scriptCond2 = ""; if ($mdata['submittedScriptCondidtion'] != -1) { $scriptCond1 = ",\n\t\t\t\t\t\t\tscript2cond,\n\t\t\t\t\t\t\tscript2code"; $scriptCond2 = ",\n\t\t\t\t\t\t\t" . $this->db->Quote($mdata['submittedScriptCondidtion']) . ",\n\t\t\t\t\t\t\t" . $this->db->Quote($mdata['submittedScriptCode']); } $this->db->setQuery("Insert Into #__facileforms_forms\n\t\t\t\t\t\t(\n package,\n\t\t\t\t\t\t\ttemplate_code,\n\t\t\t\t\t\t\ttemplate_areas,\n\t\t\t\t\t\t\tpublished,\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\tclass1,\n\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\theight,\n\t\t\t\t\t\t\tpages,\n\t\t\t\t\t\t\temailntf,\n\t\t\t\t\t\t\temailadr\n " . $scriptCond1 . "\n\t\t\t\t\t\t)\n\t\t\t\t\t\tValues\n\t\t\t\t\t\t(\n 'QuickModeForms',\n\t\t\t\t\t\t\t" . trim($this->db->Quote($templateCode), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t" . $this->db->Quote(Zend_Json::encode($areas)) . ",\n\t\t\t\t\t\t\t'1',\n\t\t\t\t\t\t\t" . trim($this->db->Quote($formName), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t" . trim($this->db->Quote($formTitle), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t" . trim($this->db->Quote($formDescription), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t'400',\n\t\t\t\t\t\t\t'500',\n\t\t\t\t\t\t\t" . $this->db->Quote($pages) . ",\n\t\t\t\t\t\t\t" . $this->db->Quote($mdata['mailNotification'] ? 2 : 0) . ",\n\t\t\t\t\t\t\t" . $this->db->Quote($mdata['mailRecipient']) . "\n " . $scriptCond2 . "\n\n\t\t\t\t\t\t)"); $this->db->query(); $form = $this->db->insertid(); } else { // preventing mysql has gone away errors by splitting the template code string into chunks // and sending each chunk in a seperate query $length = strlen(trim($templateCode)); $chunks = array(); $chunk = ''; $cnt = 0; for ($i = 0; $i < $length; $i++) { $chunk .= $templateCode[$i]; $cnt++; if ($cnt == 60000 || $i + 1 == $length && $cnt + 1 < 60000) { $chunks[] = $chunk; $chunk = ''; $cnt = 0; } } $scriptCond = ""; if ($mdata['submittedScriptCondidtion'] != -1) { $scriptCond = ",\n\t\t\t\t\t\t\tscript2cond = " . $this->db->Quote($mdata['submittedScriptCondidtion']) . ",\n\t\t\t\t\t\t\tscript2code = " . $this->db->Quote($mdata['submittedScriptCode']); } $this->db->setQuery("Update\n\t\t\t\t\t\t\t#__facileforms_forms\n\t\t\t\t\t\t Set\n\t\t\t\t\t\t\ttemplate_code = '' ,\n\t\t\t\t\t\t\ttemplate_areas = " . $this->db->Quote(Zend_Json::encode($areas)) . ",\n\t\t\t\t\t\t\tname = " . trim($this->db->Quote($formName), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\ttitle = " . trim($this->db->Quote($formTitle), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\tdescription = " . trim($this->db->Quote($formDescription), "\t, ,\n,\r") . ",\n\t\t\t\t\t\t\tpages = " . $this->db->Quote($pages) . ",\n\t\t\t\t\t\t\temailntf = " . $this->db->Quote($mdata['mailNotification'] ? 2 : 0) . ",\n\t\t\t\t\t\t\temailadr = " . $this->db->Quote($mdata['mailRecipient']) . "\n " . $scriptCond . "\n\t\t\t\t\t\t Where\n\t\t\t\t\t\t\tid = " . $this->db->Quote($form) . "\n\t\t\t\t\t\t"); $this->db->query(); $chunkLength = count($chunks); for ($i = 0; $i < $chunkLength; $i++) { $this->db->setQuery("Update\n\t\t\t\t\t\t\t#__facileforms_forms\n\t\t\t\t\t\t Set\n\t\t\t\t\t\t\ttemplate_code = Concat(template_code," . $this->db->Quote($chunks[$i], "\t, ,\n,\r") . ")\n\t\t\t\t\t\t Where\n\t\t\t\t\t\t\tid = " . $this->db->Quote($form) . "\n\t\t\t\t\t\t"); $this->db->query(); } } $notRemoveIds = ''; $i = 0; $elementCount = 0; foreach ($areas[0]['elements'] as $element) { $elementId = -1; if ($element['dbId'] == 0) { $this->db->setQuery("Insert Into #__facileforms_elements\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\tmailback,\n\t\t\t\t\t\t\t\tmailbackfile,\n\t\t\t\t\t\t\t\tform,\n\t\t\t\t\t\t\t\tpage,\n\t\t\t\t\t\t\t\tpublished,\n\t\t\t\t\t\t\t\tordering,\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\tclass1,\n\t\t\t\t\t\t\t\tclass2,\n\t\t\t\t\t\t\t\tlogging,\n\t\t\t\t\t\t\t\tposx,\n\t\t\t\t\t\t\t\tposxmode,\n\t\t\t\t\t\t\t\tposy,\n\t\t\t\t\t\t\t\tposymode,\n\t\t\t\t\t\t\t\twidth,\n\t\t\t\t\t\t\t\twidthmode,\n\t\t\t\t\t\t\t\theight,\n\t\t\t\t\t\t\t\theightmode,\n\t\t\t\t\t\t\t\tflag1,\n\t\t\t\t\t\t\t\tflag2,\n\t\t\t\t\t\t\t\tdata1,\n\t\t\t\t\t\t\t\tdata2,\n\t\t\t\t\t\t\t\tdata3,\n\t\t\t\t\t\t\t\tscript1cond,\n\t\t\t\t\t\t\t\tscript1id,\n\t\t\t\t\t\t\t\tscript1code,\n\t\t\t\t\t\t\t\tscript1flag1,\n\t\t\t\t\t\t\t\tscript1flag2,\n\t\t\t\t\t\t\t\tscript2cond,\n\t\t\t\t\t\t\t\tscript2id,\n\t\t\t\t\t\t\t\tscript2code,\n\t\t\t\t\t\t\t\tscript2flag1,\n\t\t\t\t\t\t\t\tscript2flag2,\n\t\t\t\t\t\t\t\tscript2flag3,\n\t\t\t\t\t\t\t\tscript2flag4,\n\t\t\t\t\t\t\t\tscript2flag5,\n\t\t\t\t\t\t\t\tscript3cond,\n\t\t\t\t\t\t\t\tscript3id,\n\t\t\t\t\t\t\t\tscript3code,\n\t\t\t\t\t\t\t\tscript3msg\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tValues\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['mailback']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['mailbackfile']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($form) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote(isset($element['page']) ? $element['page'] : 1) . ",\n\t\t\t\t\t\t\t\t'1',\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['orderNumber']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['name']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['title']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['bfType']) . ",\n\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['logging']) . ",\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'" . 40 * $elementCount . "',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'20',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t'20',\n\t\t\t\t\t\t\t\t'0',\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['flag1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['flag2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['data1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['data2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['data3']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1cond']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1id']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1code']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1flag1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script1flag2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2cond']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2id']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2code']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag1']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag2']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag3']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag4']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script2flag5']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3cond']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3id']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3code']) . ",\n\t\t\t\t\t\t\t\t" . $this->db->Quote($element['script3msg']) . "\n\t\t\t\t\t\t\t)"); $this->db->query(); if ($this->db->getErrormsg() == '') { $elementId = $this->db->insertid(); $areas[0]['elements'][$elementCount]['dbId'] = $elementId; $this->updateDbId($dataObject, $areas[0]['elements'][$elementCount]['qId'], $elementId); } } else { // fix ids of copied elements $this->db->setQuery("Select id From #__facileforms_elements Where name = " . $this->db->Quote($element['name']) . " And form = " . $this->db->Quote($form) . " "); $elementCheck = $this->db->loadObjectList(); if ($this->db->getErrormsg() == '') { foreach ($elementCheck as $check) { if ($check->id != intval($element['dbId'])) { $element['dbId'] = $check->id; $areas[0]['elements'][$elementCount]['dbId'] = $check->id; $this->updateDbId($dataObject, $areas[0]['elements'][$elementCount]['qId'], $check->id); } } } $this->db->setQuery("Update #__facileforms_elements Set\n\t\t\t\t\t\t\t\tmailback=" . $this->db->Quote($element['mailback']) . ",\n\t\t\t\t\t\t\t\tmailbackfile=" . $this->db->Quote($element['mailbackfile']) . ",\n\t\t\t\t\t\t\t\tform=" . $this->db->Quote($form) . ",\n\t\t\t\t\t\t\t\tpage=" . $this->db->Quote(isset($element['page']) ? $element['page'] : 1) . ",\n\t\t\t\t\t\t\t\tpublished='1',\n\t\t\t\t\t\t\t\tordering=" . $this->db->Quote($element['orderNumber']) . ",\n\t\t\t\t\t\t\t\tname=" . $this->db->Quote($element['name']) . ",\n\t\t\t\t\t\t\t\ttitle=" . $this->db->Quote($element['title']) . ",\n\t\t\t\t\t\t\t\ttype=" . $this->db->Quote($element['bfType']) . ",\n\t\t\t\t\t\t\t\tclass1='',\n\t\t\t\t\t\t\t\tclass2='',\n\t\t\t\t\t\t\t\tlogging=" . $this->db->Quote($element['logging']) . ",\n\t\t\t\t\t\t\t\tposx='0',\n\t\t\t\t\t\t\t\tposxmode='0',\n\t\t\t\t\t\t\t\tposy='" . 40 * $elementCount . "',\n\t\t\t\t\t\t\t\tposymode='0',\n\t\t\t\t\t\t\t\twidth='20',\n\t\t\t\t\t\t\t\twidthmode='0',\n\t\t\t\t\t\t\t\theight='20',\n\t\t\t\t\t\t\t\theightmode='0',\n\t\t\t\t\t\t\t\tflag1=" . $this->db->Quote($element['flag1']) . ",\n\t\t\t\t\t\t\t\tflag2=" . $this->db->Quote($element['flag2']) . ",\n\t\t\t\t\t\t\t\tdata1=" . $this->db->Quote($element['data1']) . ",\n\t\t\t\t\t\t\t\tdata2=" . $this->db->Quote($element['data2']) . ",\n\t\t\t\t\t\t\t\tdata3=" . $this->db->Quote($element['data3']) . ",\n\t\t\t\t\t\t\t\tscript1cond=" . $this->db->Quote($element['script1cond']) . ",\n\t\t\t\t\t\t\t\tscript1id=" . $this->db->Quote($element['script1id']) . ",\n\t\t\t\t\t\t\t\tscript1code=" . $this->db->Quote($element['script1code']) . ",\n\t\t\t\t\t\t\t\tscript1flag1=" . $this->db->Quote($element['script1flag1']) . ",\n\t\t\t\t\t\t\t\tscript1flag2=" . $this->db->Quote($element['script1flag2']) . ",\n\t\t\t\t\t\t\t\tscript2cond=" . $this->db->Quote($element['script2cond']) . ",\n\t\t\t\t\t\t\t\tscript2id=" . $this->db->Quote($element['script2id']) . ",\n\t\t\t\t\t\t\t\tscript2code=" . $this->db->Quote($element['script2code']) . ",\n\t\t\t\t\t\t\t\tscript2flag1=" . $this->db->Quote($element['script2flag1']) . ",\n\t\t\t\t\t\t\t\tscript2flag2=" . $this->db->Quote($element['script2flag2']) . ",\n\t\t\t\t\t\t\t\tscript2flag3=" . $this->db->Quote($element['script2flag3']) . ",\n\t\t\t\t\t\t\t\tscript2flag4=" . $this->db->Quote($element['script2flag4']) . ",\n\t\t\t\t\t\t\t\tscript2flag5=" . $this->db->Quote($element['script2flag5']) . ",\n\t\t\t\t\t\t\t\tscript3cond=" . $this->db->Quote($element['script3cond']) . ",\n\t\t\t\t\t\t\t\tscript3id=" . $this->db->Quote($element['script3id']) . ",\n\t\t\t\t\t\t\t\tscript3code=" . $this->db->Quote($element['script3code']) . ",\n\t\t\t\t\t\t\t\tscript3msg=" . $this->db->Quote($element['script3msg']) . "\n\t\t\t\t\t\t\tWhere\n\t\t\t\t\t\t\t\tid = " . $this->db->Quote($element['dbId']) . "\n\t\t\t\t\t\t\t"); $this->db->query(); $elementId = $element['dbId']; } $notRemoveIds .= ' id<>' . $this->db->Quote($elementId) . ' And '; $elementCount++; } $i++; if (strlen($notRemoveIds) != 0) { $this->db->setQuery("Delete From #__facileforms_elements Where " . $notRemoveIds . " form = " . $this->db->Quote($form) . " "); $this->db->query(); } else { $this->db->setQuery("Delete From #__facileforms_elements Where form = " . $this->db->Quote($form) . " "); $this->db->query(); } // preventing mysql has gone away errors by splitting the template code string into chunks // and sending each chunk in a seperate query $templateCode = bf_b64enc(Zend_Json::encode($dataObject)); $length = strlen($templateCode); $chunks = array(); $chunk = ''; $cnt = 0; for ($i = 0; $i < $length; $i++) { $chunk .= $templateCode[$i]; $cnt++; if ($cnt == 60000 || $i + 1 == $length && $cnt + 1 < 60000) { $chunks[] = $chunk; $chunk = ''; $cnt = 0; } } $this->db->setQuery("Update\n\t\t\t\t\t\t\t#__facileforms_forms\n\t\t\t\t\t\t Set\n\t\t\t\t\t\t \ttemplate_code = '',\n\t\t\t\t\t\t \ttemplate_code_processed = 'QuickMode',\n\t\t\t\t\t\t\ttemplate_areas = " . $this->db->Quote(Zend_Json::encode($areas)) . "\n\t\t\t\t\t\t Where\n\t\t\t\t\t\t\tid = " . $this->db->Quote($form) . "\n\t\t\t\t\t\t"); $this->db->query(); $chunkLength = count($chunks); for ($i = 0; $i < $chunkLength; $i++) { $this->db->setQuery("Update\n #__facileforms_forms\n Set\n template_code = Concat(template_code, " . $this->db->Quote($chunks[$i]) . ")\n Where\n id = " . $this->db->Quote($form) . "\n "); $this->db->query(); } return $form; }
function mkPackage($option, $caller, $pkg) { global $ff_admpath, $ff_version, $mosConfig_fileperms; $id = $pkg; $name = JRequest::getVar('pkg_name', ''); $title = JRequest::getVar('pkg_title', ''); $version = JRequest::getVar('pkg_version', ''); $created = date('Y-m-d H:i:s'); $author = JRequest::getVar('pkg_author', ''); $email = JRequest::getVar('pkg_email', ''); $url = JRequest::getVar('pkg_url', ''); $description = JRequest::getVar('pkg_description', ''); $copyright = JRequest::getVar('pkg_copyright', ''); savePackage($id, $name, $title, $version, $created, $author, $email, $url, $description, $copyright); $xmlname = $ff_admpath . '/packages/' . $name . '.xml'; $existed = file_exists($xmlname); if ($existed) { if (!is_writable($xmlname)) { die('XML file is not writable!'); } } $file = fopen($xmlname, "w"); $xml = '<?xml version="1.0" encoding="utf-8" ?>' . nl() . '<FacileFormsPackage'; if ($id != '') { $xml .= ' id="' . $id . '"'; } if ($id == '') { $xml .= ' id="' . $name . '"'; } $xml .= ' type="autoincrement" version="' . $ff_version . '">' . nl() . indent(1) . '<name>' . expstring($name) . '</name>' . nl() . indent(1) . '<title>' . expstring($title) . '</title>' . nl() . indent(1) . '<version>' . expstring($version) . '</version>' . nl() . indent(1) . '<creationDate>' . $created . '</creationDate>' . nl() . indent(1) . '<author>' . expstring($author) . '</author>' . nl() . indent(1) . '<authorEmail>' . expstring($email) . '</authorEmail>' . nl() . indent(1) . '<authorUrl>' . expstring($url) . '</authorUrl>' . nl() . indent(1) . '<description>' . expstring($description) . '</description>' . nl() . indent(1) . '<copyright>' . expstring($copyright) . '</copyright>' . nl(); if ($id == '') { $ids = JRequest::getVar('scriptsel', array()); } else { $ids = array(); $rows = _ff_select("select id from #__facileforms_scripts " . "where package = " . JFactory::getDBO()->Quote($id) . " " . "order by id"); if (count($rows)) { foreach ($rows as $row) { $ids[] = $row->id; } } } // if if (count($ids) > 0) { $quoted_ids = array(); foreach ($ids as $the_id) { $quoted_ids[] = JFactory::getDBO()->Quote($the_id); } $ids = implode(',', $quoted_ids); $scripts = _ff_select("select * from #__facileforms_scripts where id in ({$ids}) order by package, name, id"); for ($s = 0; $s < count($scripts); $s++) { $script = $scripts[$s]; $xml .= indent(1) . '<script id="' . $script->id . '">' . nl(); if ($script->published != 1) { $xml .= indent(2) . '<published>' . $script->published . '</published>' . nl(); } if ($script->package != '') { $xml .= indent(2) . '<package>' . expstring($script->package) . '</package>' . nl(); } $xml .= indent(2) . '<name>' . expstring($script->name) . '</name>' . nl() . indent(2) . '<title>' . expstring($script->title) . '</title>' . nl(); if ($script->type != 'Untyped') { $xml .= indent(2) . '<type>' . expstring($script->type) . '</type>' . nl(); } $script->description = trim($script->description); if ($script->description != '') { $xml .= indent(2) . '<description>' . expstring($script->description) . '</description>' . nl(); } $script->code = trim($script->code); if ($script->code != '') { $xml .= indent(2) . '<code>' . expstring($script->code) . '</code>' . nl(); } $xml .= indent(1) . '</script>' . nl(); } // for } // if if ($id == '') { $ids = JRequest::getVar('piecesel', array()); } else { $ids = array(); $rows = _ff_select("select id from #__facileforms_pieces " . "where package = " . JFactory::getDBO()->Quote($id) . " " . "order by id"); if (count($rows)) { foreach ($rows as $row) { $ids[] = $row->id; } } } // if if (count($ids) > 0) { $quoted_ids = array(); foreach ($ids as $the_id) { $quoted_ids[] = JFactory::getDBO()->Quote($the_id); } $ids = implode(',', $quoted_ids); $pieces = _ff_select("select * from #__facileforms_pieces where id in ({$ids}) order by package, name, id"); for ($p = 0; $p < count($pieces); $p++) { $piece = $pieces[$p]; $xml .= indent(1) . '<piece id="' . $piece->id . '">' . nl(); if ($piece->published != 1) { $xml .= indent(2) . '<published>' . $piece->published . '</published>' . nl(); } if ($piece->package != '') { $xml .= indent(2) . '<package>' . expstring($piece->package) . '</package>' . nl(); } $xml .= indent(2) . '<name>' . expstring($piece->name) . '</name>' . nl() . indent(2) . '<title>' . expstring($piece->title) . '</title>' . nl(); if ($piece->type != 'Untyped') { $xml .= indent(2) . '<type>' . expstring($piece->type) . '</type>' . nl(); } $piece->description = trim($piece->description); if ($piece->description != '') { $xml .= indent(2) . '<description>' . expstring($piece->description) . '</description>' . nl(); } $piece->code = trim($piece->code); if ($piece->code != '') { $xml .= indent(2) . '<code>' . expstring($piece->code) . '</code>' . nl(); } $xml .= indent(1) . '</piece>' . nl(); } // for } // if if ($id == '') { $ids = JRequest::getVar('formsel', array()); } else { $ids = array(); $rows = _ff_select("select id from #__facileforms_forms " . "where package = " . JFactory::getDBO()->Quote($id) . " " . "order by id"); if (count($rows)) { foreach ($rows as $row) { $ids[] = $row->id; } } } // if if (count($ids) > 0) { $quoted_ids = array(); foreach ($ids as $the_id) { $quoted_ids[] = JFactory::getDBO()->Quote($the_id); } $ids = implode(',', $quoted_ids); $forms = _ff_select("select * from #__facileforms_forms where id in ({$ids}) order by package, ordering, id"); for ($f = 0; $f < count($forms); $f++) { $form = $forms[$f]; $xml .= indent(1) . '<form id="' . $form->id . '">' . nl(); if ($form->published != 1) { $xml .= indent(2) . '<published>' . $form->published . '</published>' . nl(); } if ($form->runmode != 0) { $xml .= indent(2) . '<runmode>' . $form->runmode . '</runmode>' . nl(); } if ($form->package != '') { $xml .= indent(2) . '<package>' . expstring($form->package) . '</package>' . nl(); } $xml .= indent(2) . '<name>' . expstring($form->name) . '</name>' . nl() . indent(2) . '<title>' . expstring($form->title) . '</title>' . nl(); if ($form->description != '') { $xml .= indent(2) . '<description>' . expstring($form->description) . '</description>' . nl(); } if ($form->class1 != '') { $xml .= indent(2) . '<class1>' . expstring($form->class1) . '</class1>' . nl(); } if ($form->class2 != '') { $xml .= indent(2) . '<class2>' . expstring($form->class2) . '</class2>' . nl(); } $xml .= indent(2) . '<width>' . $form->width . '</width>' . nl(); if ($form->widthmode != 0) { $xml .= indent(2) . '<widthmode>' . $form->widthmode . '</widthmode>' . nl(); } $xml .= indent(2) . '<height>' . $form->height . '</height>' . nl(); if ($form->heightmode != 0) { $xml .= indent(2) . '<heightmode>' . $form->heightmode . '</heightmode>' . nl(); } if ($form->pages != 1) { $xml .= indent(2) . '<pages>' . $form->pages . '</pages>' . nl(); } if ($form->emailntf != 1) { $xml .= indent(2) . '<emailntf>' . $form->emailntf . '</emailntf>' . nl(); } if ($form->emaillog != 1) { $xml .= indent(2) . '<emaillog>' . $form->emaillog . '</emaillog>' . nl(); } if ($form->emailxml != 0) { $xml .= indent(2) . '<emailxml>' . $form->emailxml . '</emailxml>' . nl(); } if ($form->emailntf == 2) { $form->emailadr = expstring($form->emailadr); if ($form->emailadr != '') { $xml .= indent(2) . '<emailadr>' . $form->emailadr . '</emailadr>' . nl(); } } // if if ($form->template_code != '') { $xml .= indent(2) . '<template_code>' . bf_b64enc($form->template_code) . '</template_code>'; } if ($form->template_code_processed != '') { $xml .= indent(2) . '<template_code_processed>' . bf_b64enc($form->template_code_processed) . '</template_code_processed>'; } if ($form->template_areas != '') { $xml .= indent(2) . '<template_areas>' . bf_b64enc($form->template_areas) . '</template_areas>'; } if ($form->dblog != 1) { $xml .= indent(2) . '<dblog>' . $form->dblog . '</dblog>' . nl(); } $form->description = trim($form->description); if ($form->prevmode != 2) { $xml .= indent(2) . '<prevmode>' . $form->prevmode . '</prevmode>' . nl(); } if ($form->prevmode != 0 && $form->widthmode != 0 && $form->prevwidth != '') { $xml .= indent(2) . '<prevwidth>' . $form->prevwidth . '</prevwidth>' . nl(); } $this->exportScript('script1', '#__facileforms_scripts', $form->script1cond, $form->script1id, $form->script1code, 2, $xml); $this->exportScript('script2', '#__facileforms_scripts', $form->script2cond, $form->script2id, $form->script2code, 2, $xml); $this->exportScript('piece1', '#__facileforms_pieces', $form->piece1cond, $form->piece1id, $form->piece1code, 2, $xml); $this->exportScript('piece2', '#__facileforms_pieces', $form->piece2cond, $form->piece2id, $form->piece2code, 2, $xml); $this->exportScript('piece3', '#__facileforms_pieces', $form->piece3cond, $form->piece3id, $form->piece3code, 2, $xml); $this->exportScript('piece4', '#__facileforms_pieces', $form->piece4cond, $form->piece4id, $form->piece4code, 2, $xml); $elems = _ff_select("select * from #__facileforms_elements where form={$form->id} order by page, ordering, id"); for ($e = 0; $e < count($elems); $e++) { $elem = $elems[$e]; $xml .= indent(2) . '<element id="' . $elem->id . '">' . nl(); if ($elem->page != 1) { $xml .= indent(3) . '<page>' . $elem->page . '</page>' . nl(); } if ($elem->published != 1) { $xml .= indent(3) . '<published>' . $elem->published . '</published>' . nl(); } $xml .= indent(3) . '<name>' . expstring($elem->name) . '</name>' . nl() . indent(3) . '<title>' . expstring($elem->title) . '</title>' . nl(); if ($elem->type != 'Static Text/HTML') { $xml .= indent(3) . '<type>' . $elem->type . '</type>' . nl(); } if ($elem->class1 != '') { $xml .= indent(3) . '<class1>' . expstring($elem->class1) . '</class1>' . nl(); } if ($elem->class2 != '') { $xml .= indent(3) . '<class2>' . expstring($elem->class2) . '</class2>' . nl(); } if (isInputElement($elem->type)) { if ($elem->logging != 1) { $xml .= indent(3) . '<logging>' . $elem->logging . '</logging>' . nl(); } } // if if (isVisibleElement($elem->type)) { if ($elem->posx != NULL) { $xml .= indent(3) . '<posx>' . $elem->posx . '</posx>' . nl(); } if ($elem->posx != NULL && $elem->posxmode != 0) { $xml .= indent(3) . '<posxmode>' . $elem->posxmode . '</posxmode>' . nl(); } if ($elem->posy != NULL) { $xml .= indent(3) . '<posy>' . $elem->posy . '</posy>' . nl(); } if ($elem->posy != NULL && $elem->posymode != 0) { $xml .= indent(3) . '<posymode>' . $elem->posymode . '</posymode>' . nl(); } if ($elem->width != NULL) { $xml .= indent(3) . '<width>' . $elem->width . '</width>' . nl(); } if ($elem->width != NULL && $elem->widthmode != 0) { $xml .= indent(3) . '<widthmode>' . $elem->widthmode . '</widthmode>' . nl(); } if ($elem->height != NULL) { $xml .= indent(3) . '<height>' . $elem->height . '</height>' . nl(); } if ($elem->height != NULL && $elem->heightmode != 0) { $xml .= indent(3) . '<heightmode>' . $elem->heightmode . '</heightmode>' . nl(); } } // if $xml .= indent(3) . '<mailback>' . $elem->mailback . '</mailback>' . nl(); $xml .= indent(3) . '<mailbackfile>' . $elem->mailbackfile . '</mailbackfile>' . nl(); if ($elem->flag1) { $xml .= indent(3) . '<flag1>' . $elem->flag1 . '</flag1>' . nl(); } if ($elem->flag2) { $xml .= indent(3) . '<flag2>' . $elem->flag2 . '</flag2>' . nl(); } $elem->data1 = expstring($elem->data1); if ($elem->data1 != '') { $xml .= indent(3) . '<data1>' . $elem->data1 . '</data1>' . nl(); } $elem->data2 = expstring($elem->data2); if ($elem->data2 != '') { $xml .= indent(3) . '<data2>' . $elem->data2 . '</data2>' . nl(); } $elem->data3 = expstring($elem->data3); if ($elem->data3 != '') { $xml .= indent(3) . '<data3>' . $elem->data3 . '</data3>' . nl(); } $this->exportScript('script1', '#__facileforms_scripts', $elem->script1cond, $elem->script1id, $elem->script1code, 3, $xml); if ($elem->script1cond > 0) { if ($elem->script1flag1) { $xml .= indent(3) . '<script1flag1>' . $elem->script1flag1 . '</script1flag1>' . nl(); } if ($elem->script1flag2) { $xml .= indent(3) . '<script1flag2>' . $elem->script1flag2 . '</script1flag2>' . nl(); } } // if $this->exportScript('script2', '#__facileforms_scripts', $elem->script2cond, $elem->script2id, $elem->script2code, 3, $xml); if ($elem->script2cond > 0) { if ($elem->script2flag1) { $xml .= indent(3) . '<script2flag1>' . $elem->script2flag1 . '</script2flag1>' . nl(); } if ($elem->script2flag2) { $xml .= indent(3) . '<script2flag2>' . $elem->script2flag2 . '</script2flag2>' . nl(); } if ($elem->script2flag3) { $xml .= indent(3) . '<script2flag3>' . $elem->script2flag3 . '</script2flag3>' . nl(); } if ($elem->script2flag4) { $xml .= indent(3) . '<script2flag4>' . $elem->script2flag4 . '</script2flag4>' . nl(); } if ($elem->script2flag5) { $xml .= indent(3) . '<script2flag5>' . $elem->script2flag5 . '</script2flag5>' . nl(); } } // if $this->exportScript('script3', '#__facileforms_scripts', $elem->script3cond, $elem->script3id, $elem->script3code, 3, $xml); if ($elem->script3cond > 0) { if ($elem->script3msg != '') { $xml .= indent(3) . '<script3msg>' . expstring($elem->script3msg) . '</script3msg>' . nl(); } } // if $xml .= indent(2) . '</element>' . nl(); } // for $xml .= indent(1) . '</form>' . nl(); } // for } // if if ($id == '') { $ids = JRequest::getVar('menusel', array()); } else { $ids = array(); $rows = _ff_select("select id from #__facileforms_compmenus " . "where package = " . JFactory::getDBO()->Quote($id) . " and parent = 0 " . "order by id"); if (count($rows)) { foreach ($rows as $row) { $ids[] = $row->id; } } } // if if (count($ids) > 0) { $quoted_ids = array(); foreach ($ids as $the_id) { $quoted_ids[] = JFactory::getDBO()->Quote($the_id); } $ids = implode(',', $quoted_ids); $menus = _ff_select("select * from #__facileforms_compmenus where id in ({$ids}) order by package, ordering, id"); for ($m = 0; $m < count($menus); $m++) { $menu = $menus[$m]; $xml .= indent(1) . '<compmenu id="' . $menu->id . '">' . nl(); if ($menu->published != 1) { $xml .= indent(2) . '<published>' . $menu->published . '</published>' . nl(); } $menu->img = trim($menu->img); if ($menu->img != '') { $xml .= indent(2) . '<img>' . expstring($menu->img) . '</img>' . nl(); } if ($menu->package != '') { $xml .= indent(2) . '<package>' . expstring($menu->package) . '</package>' . nl(); } $xml .= indent(2) . '<title>' . expstring($menu->title) . '</title>' . nl(); $menu->name = trim($menu->name); if ($menu->name != '') { $xml .= indent(2) . '<name>' . expstring($menu->name) . '</name>' . nl(); } if ($menu->page != 1 && $menu->page != '') { $xml .= indent(2) . '<page>' . $menu->page . '</page>' . nl(); } if ($menu->frame != 0) { $xml .= indent(2) . '<frame>' . $menu->frame . '</frame>' . nl(); } if ($menu->border != 0) { $xml .= indent(2) . '<border>' . $menu->border . '</border>' . nl(); } $menu->params = trim($menu->params); if ($menu->params != '') { $xml .= indent(2) . '<params>' . expstring($menu->params) . '</params>' . nl(); } $submenus = _ff_select("select * from #__facileforms_compmenus where parent={$menu->id} order by ordering, id"); for ($s = 0; $s < count($submenus); $s++) { $submenu = $submenus[$s]; $xml .= indent(2) . '<compmenu id="' . $submenu->id . '">' . nl(); if ($submenu->published != 1) { $xml .= indent(3) . '<published>' . $submenu->published . '</published>' . nl(); } $submenu->img = trim($submenu->img); if ($submenu->img != '') { $xml .= indent(3) . '<img>' . expstring($submenu->img) . '</img>' . nl(); } if ($menu->package != '') { $xml .= indent(3) . '<package>' . expstring($submenu->package) . '</package>' . nl(); } $xml .= indent(3) . '<title>' . expstring($submenu->title) . '</title>' . nl(); $submenu->name = trim($submenu->name); if ($submenu->name != '') { $xml .= indent(3) . '<name>' . expstring($submenu->name) . '</name>' . nl(); } if ($submenu->page != 1 && $submenu->page != '') { $xml .= indent(3) . '<page>' . $submenu->page . '</page>' . nl(); } if ($submenu->frame != 0) { $xml .= indent(3) . '<frame>' . $submenu->frame . '</frame>' . nl(); } if ($submenu->border != 0) { $xml .= indent(3) . '<border>' . $submenu->border . '</border>' . nl(); } $submenu->params = trim($submenu->params); if ($submenu->params != '') { $xml .= indent(3) . '<params>' . expstring($submenu->params) . '</params>' . nl(); } $xml .= indent(2) . '</compmenu>' . nl(); } // for $xml .= indent(1) . '</compmenu>' . nl(); } // for } // if $xml .= '</FacileFormsPackage>' . nl(); fwrite($file, $xml); fclose($file); if (!$existed) { $filemode = NULL; if (isset($mosConfig_fileperms)) { if ($mosConfig_fileperms != '') { $filemode = octdec($mosConfig_fileperms); } } else { $filemode = 0644; } if (isset($filemode)) { @chmod($xmlname, $filemode); } } // if HTML_facileFormsConf::edit($option, $caller, $pkg, $xmlname); }
function import($filename) { global $errors, $errmode; // import crossreferences $this->xscripts = $this->xpieces = $this->oldscripts = $this->oldpieces = $this->scripts = $this->pieces = $this->forms = $this->elements = $this->menus = $this->warnings = array(); $this->pubmenus = 0; if ($errmode == 'log') { $this->saveErrors = $errors; $errors = array(); } // if $ok = parent::import($filename); if (!$ok) { // fail case $this->rollback(); if ($errmode == 'log') { if (count($this->saveErrors)) { $errors = array_merge($this->saveErrors, $errors); } $errors[] = BFText::_('COM_BREEZINGFORMS_INSTALLER') . ': ' . $this->error; } // if } else { // success case if ($this->pubmenus > 0) { updateComponentMenus(); } $id = $this->getText(0, 'pkgid'); if ($id != '') { relinkScripts($this->oldscripts); relinkPieces($this->oldpieces); savePackage($id, $this->getText(0, 'name'), $this->getText(0, 'title'), $this->getText(0, 'version'), $this->getText(0, 'creationDate'), $this->getText(0, 'author'), $this->getText(0, 'authorEmail'), $this->getText(0, 'authorUrl'), $this->getText(0, 'description'), $this->getText(0, 'copyright')); } // if require_once JPATH_SITE . '/administrator/components/com_breezingforms/admin/quickmode.class.php'; require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/Zend/Json/Decoder.php'; require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/Zend/Json/Encoder.php'; foreach ($this->forms as $form_id) { JFactory::getDBO()->setQuery("Select template_areas, template_code_processed, template_code From #__facileforms_forms Where id = " . intval($form_id)); $row = JFactory::getDBO()->loadObject(); if (trim($row->template_code) != '') { $areas = Zend_Json::decode(bf_b64dec($row->template_areas)); $i = 0; foreach ($areas as $area) { $j = 0; foreach ($area['elements'] as $element) { $areas[$i]['elements'][$j]['dbId'] = 0; $j++; } $i++; } $template_areas = Zend_Json::encode($areas); $template_code = $row->template_code; if ($row->template_code_processed == 'QuickMode') { $dataObject = Zend_Json::decode(bf_b64dec($row->template_code)); $this->resetQuickModeDbId($dataObject); $template_code = bf_b64enc(Zend_Json::encode($dataObject)); } JFactory::getDBO()->setQuery("Update #__facileforms_forms Set template_code = " . JFactory::getDBO()->Quote($template_code) . ", template_areas = " . JFactory::getDBO()->Quote($template_areas) . " Where id = " . intval($form_id)); JFactory::getDBO()->query(); if ($row && $row->template_code_processed == 'QuickMode') { $quickMode = new QuickMode(); $quickMode->save($form_id, Zend_Json::decode(bf_b64dec($template_code))); } } } } // if return $ok; }
static function copy($option, $pkg, $ids) { global $database; JArrayHelper::toInteger($ids); require_once JPATH_SITE . '/administrator/components/com_breezingforms/admin/quickmode.class.php'; require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/Zend/Json/Decoder.php'; require_once JPATH_SITE . '/administrator/components/com_breezingforms/libraries/Zend/Json/Encoder.php'; $database = JFactory::getDBO(); $total = count($ids); $row = new facileFormsForms($database); $elem = new facileFormsElements($database); if (count($ids)) { foreach ($ids as $id) { $row->load(intval($id)); $row->id = NULL; $row->ordering = 999999; $row->title = 'Copy of ' . $row->title; $row->name = 'copy_' . $row->name; $row->store(); $row->reorder(''); $database->setQuery("select id from #__facileforms_elements where form={$id}"); $eids = $database->loadObjectList(); for ($i = 0; $i < count($eids); $i++) { $eid = $eids[$i]; $elem->load(intval($eid->id)); $elem->id = NULL; $elem->form = $row->id; $elem->store(); } // for // resetting easy and quickmode database ids JFactory::getDBO()->setQuery("Select template_areas, template_code_processed, template_code From #__facileforms_forms Where id = " . intval($row->{$id})); $row_ = JFactory::getDBO()->loadObject(); if (trim($row_->template_code) != '') { $areas = Zend_Json::decode($row_->template_areas); $i = 0; foreach ($areas as $area) { $j = 0; foreach ($area['elements'] as $element) { $areas[$i]['elements'][$j]['dbId'] = 0; $j++; } $i++; } $template_areas = Zend_Json::encode($areas); $template_code = $row_->template_code; if ($row_->template_code_processed == 'QuickMode') { $dataObject = Zend_Json::decode(bf_b64dec($row_->template_code)); resetQuickModeDbId($dataObject); $template_code = bf_b64enc(Zend_Json::encode($dataObject)); } JFactory::getDBO()->setQuery("Update #__facileforms_forms Set template_code = " . JFactory::getDBO()->Quote($template_code) . ", template_areas = " . JFactory::getDBO()->Quote($template_areas) . " Where id = " . intval($id)); JFactory::getDBO()->query(); if ($row_ && $row_->template_code_processed == 'QuickMode') { $quickMode = new QuickMode(); $quickMode->save($id, Zend_Json::decode(bf_b64dec($template_code))); } } // reset end } } // foreach $msg = $total . ' ' . BFText::_('COM_BREEZINGFORMS_FORMS_SUCOPIED'); JFactory::getApplication()->redirect("index.php?option={$option}&act=manageforms&pkg={$pkg}&mosmsg={$msg}"); }
function _recaptcha_mailhide_urlb64($x) { return strtr(bf_b64enc($x), '+/', '-_'); }
/** * Send the document to a given destination: string, local file or browser. * In the last case, the plug-in may be used (if present) or a download ("Save as" dialog box) may be forced.<br /> * The method first calls Close() if necessary to terminate the document. * @param $name (string) The name of the file when saved. Note that special characters are removed and blanks characters are replaced with the underscore character. * @param $dest (string) Destination where to send the document. It can take one of the following values:<ul><li>I: send the file inline to the browser (default). The plug-in is used if available. The name given by name is used when one selects the "Save as" option on the link generating the PDF.</li><li>D: send to the browser and force a file download with the name given by name.</li><li>F: save to a local server file with the name given by name.</li><li>S: return the document as a string (name is ignored).</li><li>FI: equivalent to F + I option</li><li>FD: equivalent to F + D option</li><li>E: return the document as b64 mime multi-part email attachment (RFC 2045)</li></ul> * @public * @since 1.0 * @see Close() */ public function Output($name = 'doc.pdf', $dest = 'I') { //Output PDF to some destination //Finish document if necessary if ($this->state < 3) { $this->Close(); } //Normalize parameters if (is_bool($dest)) { $dest = $dest ? 'D' : 'F'; } $dest = strtoupper($dest); if ($dest[0] != 'F') { $name = preg_replace('/[\\s]+/', '_', $name); $name = preg_replace('/[^a-zA-Z0-9_\\.-]/', '', $name); } if ($this->sign) { // *** apply digital signature to the document *** // get the document content $pdfdoc = $this->getBuffer(); // remove last newline $pdfdoc = substr($pdfdoc, 0, -1); // Remove the original buffer if (isset($this->diskcache) and $this->diskcache) { // remove buffer file from cache unlink($this->buffer); } unset($this->buffer); // remove filler space $byterange_string_len = strlen(TCPDF_STATIC::$byterange_string); // define the ByteRange $byte_range = array(); $byte_range[0] = 0; $byte_range[1] = strpos($pdfdoc, TCPDF_STATIC::$byterange_string) + $byterange_string_len + 10; $byte_range[2] = $byte_range[1] + $this->signature_max_length + 2; $byte_range[3] = strlen($pdfdoc) - $byte_range[2]; $pdfdoc = substr($pdfdoc, 0, $byte_range[1]) . substr($pdfdoc, $byte_range[2]); // replace the ByteRange $byterange = sprintf('/ByteRange[0 %u %u %u]', $byte_range[1], $byte_range[2], $byte_range[3]); $byterange .= str_repeat(' ', $byterange_string_len - strlen($byterange)); $pdfdoc = str_replace(TCPDF_STATIC::$byterange_string, $byterange, $pdfdoc); // write the document to a temporary folder $tempdoc = TCPDF_STATIC::getObjFilename('doc'); $f = fopen($tempdoc, 'wb'); if (!$f) { $this->Error('Unable to create temporary file: ' . $tempdoc); } $pdfdoc_length = strlen($pdfdoc); fwrite($f, $pdfdoc, $pdfdoc_length); fclose($f); // get digital signature via openssl library $tempsign = TCPDF_STATIC::getObjFilename('sig'); if (empty($this->signature_data['extracerts'])) { openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED); } else { openssl_pkcs7_sign($tempdoc, $tempsign, $this->signature_data['signcert'], array($this->signature_data['privkey'], $this->signature_data['password']), array(), PKCS7_BINARY | PKCS7_DETACHED, $this->signature_data['extracerts']); } unlink($tempdoc); // read signature $signature = file_get_contents($tempsign); unlink($tempsign); // extract signature $signature = substr($signature, $pdfdoc_length); $signature = substr($signature, strpos($signature, "%%EOF\n\n------") + 13); $tmparr = explode("\n\n", $signature); $signature = $tmparr[1]; unset($tmparr); // decode signature $signature = bf_b64dec(trim($signature)); // convert signature to hex $signature = current(unpack('H*', $signature)); $signature = str_pad($signature, $this->signature_max_length, '0'); // disable disk caching $this->diskcache = false; // Add signature to the document $this->buffer = substr($pdfdoc, 0, $byte_range[1]) . '<' . $signature . '>' . substr($pdfdoc, $byte_range[1]); $this->bufferlen = strlen($this->buffer); } switch ($dest) { case 'I': // Send PDF to the standard output if (ob_get_contents()) { $this->Error('Some data has already been output, can\'t send PDF file'); } if (php_sapi_name() != 'cli') { // send output to a browser header('Content-Type: application/pdf'); if (headers_sent()) { $this->Error('Some data has already been output to browser, can\'t send PDF file'); } header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1'); //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: inline; filename="' . basename($name) . '"'); TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen); } else { echo $this->getBuffer(); } break; case 'D': // download PDF as file if (ob_get_contents()) { $this->Error('Some data has already been output, can\'t send PDF file'); } header('Content-Description: File Transfer'); if (headers_sent()) { $this->Error('Some data has already been output to browser, can\'t send PDF file'); } header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1'); //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // force download dialog if (strpos(php_sapi_name(), 'cgi') === false) { header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream', false); header('Content-Type: application/download', false); header('Content-Type: application/pdf', false); } else { header('Content-Type: application/pdf'); } // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="' . basename($name) . '"'); header('Content-Transfer-Encoding: binary'); TCPDF_STATIC::sendOutputData($this->getBuffer(), $this->bufferlen); break; case 'F': case 'FI': case 'FD': // save PDF to a local file if ($this->diskcache) { copy($this->buffer, $name); } else { $f = fopen($name, 'wb'); if (!$f) { $this->Error('Unable to create output file: ' . $name); } fwrite($f, $this->getBuffer(), $this->bufferlen); fclose($f); } if ($dest == 'FI') { // send headers to browser header('Content-Type: application/pdf'); header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1'); //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1 header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Content-Disposition: inline; filename="' . basename($name) . '"'); TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name)); } elseif ($dest == 'FD') { // send headers to browser if (ob_get_contents()) { $this->Error('Some data has already been output, can\'t send PDF file'); } header('Content-Description: File Transfer'); if (headers_sent()) { $this->Error('Some data has already been output to browser, can\'t send PDF file'); } header('Cache-Control: private, must-revalidate, post-check=0, pre-check=0, max-age=1'); header('Pragma: public'); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // force download dialog if (strpos(php_sapi_name(), 'cgi') === false) { header('Content-Type: application/force-download'); header('Content-Type: application/octet-stream', false); header('Content-Type: application/download', false); header('Content-Type: application/pdf', false); } else { header('Content-Type: application/pdf'); } // use the Content-Disposition header to supply a recommended filename header('Content-Disposition: attachment; filename="' . basename($name) . '"'); header('Content-Transfer-Encoding: binary'); TCPDF_STATIC::sendOutputData(file_get_contents($name), filesize($name)); } break; case 'E': $base = 'base'; $sixty_four = '64'; // return PDF as b64 mime multi-part email attachment (RFC 2045) $retval = 'Content-Type: application/pdf;' . "\r\n"; $retval .= ' name="' . $name . '"' . "\r\n"; $retval .= 'Content-Transfer-Encoding: ' . $base . $sixty_four . "\r\n"; $retval .= 'Content-Disposition: attachment;' . "\r\n"; $retval .= ' filename="' . $name . '"' . "\r\n\r\n"; $retval .= chunk_split(bf_b64enc($this->getBuffer()), 76, "\r\n"); return $retval; case 'S': // returns PDF as a string return $this->getBuffer(); default: $this->Error('Incorrect output destination: ' . $dest); } return ''; }