function ODT() { global $title, $subtitle, $odtfile, $document, $ids, $files, $docs, $names, $output_text, $output_manifest, $output_meta, $tempdir, $msg, $lang, $template; $title = $this->title; $subtitle = $this->subtitle; $ids = $this->ids; $files = $this->files; $docs = $this->docs; $odtfile = "QSOS_" . $docs[0]->getkey("qsosappfamily") . ".odt"; $names = $this->names; $lang = $this->lang; $msg = $this->msg; $template = $this->template; function createTitle($level, $style, $text) { global $output_text; $title = $output_text->createElement("text:h", $text); $title->setAttribute("text:style-name", $style); $title->setAttribute("text:outline-level", $level); return $title; } function createFirstTitle1($text) { return createTitle("1", "P30", $text); } function createTitle1($text) { return createTitle("1", "Heading_20_1", $text); } function createTitle2($text) { return createTitle("2", "Heading_20_2", $text); } function createTitle3($text) { return createTitle("3", "Heading_20_3", $text); } function createSimpleP($text) { global $output_text; $p = $output_text->createElement("text:p", $text); $p->setAttribute("text:style-name", "Text_20_body"); return $p; } function createSimpleTODO($text) { global $output_text; $p = $output_text->createElement("text:p", $text); $p->setAttribute("text:style-name", "PHL"); return $p; } function createP($contents) { global $output_text; $p = $output_text->createElement("text:p"); $p->setAttribute("text:style-name", "Text_20_body"); foreach ($contents as $content) { switch ($content[0]) { case "t": $span = $output_text->createTextNode($content[1]); break; case "i": $span = $output_text->createElement("text:span", $content[1]); $span->setAttribute("text:style-name", "T1"); break; case "a": $span = $output_text->createElement("text:a", $content[1]); $span->setAttribute("xlink:type", "simple"); $span->setAttribute("xlink:href", $content[1]); break; } $p->appendChild($span); } return $p; } function createList($contents) { global $output_text; $list = $output_text->createElement("text:list"); $list->setAttribute("text:continue-numbering", "true"); $list->setAttribute("text:style-name", "List_20_1"); $item = $output_text->createElement("text:list-item"); if (is_array($contents)) { foreach ($contents as $subelement) { $item->appendChild(createList($subelement)); } } else { $p = $output_text->createElement("text:p", $contents); $p->setAttribute("text:style-name", "Liste_20_Hiérarchique"); $item->appendChild($p); } $list->appendChild($item); return $list; } function createBoldTitle($title) { global $output_text; $p = $output_text->createElement('text:p', $title); $p->setAttribute("text:style-name", "P16"); return $p; } function createImage($image) { global $tempdir, $output_text; if (substr($image, -3) == "png") { $ratio = 0.023291; //(ratio px <=> cm) //Get image dimensions $size = getimagesize($tempdir . "/" . $image); $width = $size[0] * $ratio; $height = $size[1] * $ratio; $style = "fr7"; } else { //Crop and scale image $ratio = 0.65; if ($image == "quadrant.svg") { $width = (26.457 - 1) * $ratio; $height = (15.874 - 5) * $ratio; $style = "frQuadrant"; } else { $width = (26.457 - 1) * $ratio; $height = (15.874 - 6) * $ratio; $style = "frSvg"; } } $p = $output_text->createElement('text:p'); $p->setAttribute("text:style-name", "P15"); $frame = $output_text->createElement('draw:frame'); $frame->setAttribute("draw:style-name", $style); $frame->setAttribute("text:anchor-type", "as-char"); $frame->setAttribute("svg:width", $width . "cm"); $frame->setAttribute("svg:height", $height . "cm"); $frame->setAttribute("draw:z-index", "191"); $svg = $output_text->createElement('draw:image'); $svg->setAttribute("xlink:href", "Pictures/{$image}"); $svg->setAttribute("xlink:type", "simple"); $svg->setAttribute("xlink:show", "embed"); $svg->setAttribute("xlink:actuate", "onLoad"); $frame->appendChild($svg); $p->appendChild($frame); return $p; } function createImageEmbedded($image, $width, $height) { global $output_text; $p = $output_text->createElement('text:p'); $p->setAttribute("text:style-name", "P15"); $frame = $output_text->createElement('draw:frame'); $frame->setAttribute("draw:style-name", "fr7"); $frame->setAttribute("text:anchor-type", "as-char"); $frame->setAttribute("svg:width", $width); $frame->setAttribute("svg:height", $height); $frame->setAttribute("draw:z-index", "191"); $svg = $output_text->createElement('draw:image'); $svg->setAttribute("xlink:href", "Pictures/{$image}"); $svg->setAttribute("xlink:type", "simple"); $svg->setAttribute("xlink:show", "embed"); $svg->setAttribute("xlink:actuate", "onLoad"); $frame->appendChild($svg); $p->appendChild($frame); return $p; } function createManifest() { global $output_manifest, $lang, $docs, $template; include "export/{$template}/settings-odt-{$lang}.php"; $manifest = $output_manifest->createElement('manifest:manifest'); $manifest->setAttribute("xmlns:manifest", "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"); $manifest->setAttribute("manifest:version", "1.2"); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "application/vnd.oasis.opendocument.text"); $file->setAttribute("manifest:version", "1.2"); $file->setAttribute("manifest:full-path", "/"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "image/png"); $file->setAttribute("manifest:full-path", "Thumbnails/thumbnail.png"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "application/binary"); $file->setAttribute("manifest:full-path", "layout-cache"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "text/xml"); $file->setAttribute("manifest:full-path", "settings.xml"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "text/xml"); $file->setAttribute("manifest:full-path", "content.xml"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "text/xml"); $file->setAttribute("manifest:full-path", "meta.xml"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "text/xml"); $file->setAttribute("manifest:full-path", "styles.xml"); $manifest->appendChild($file); foreach ($tpl_images as $image) { $tmp_array = array_reverse(explode(".", $image)); $ext = $tmp_array[0]; if ($ext == "jpg") { $mime = "image/jpeg"; } else { $mime = "image/{$ext}"; } if ($ext == "wmf") { $mime = ""; } $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "{$mime}"); $file->setAttribute("manifest:full-path", "Pictures/{$image}"); $manifest->appendChild($file); } foreach ($docs[0]->getTree() as $section) { $name = $section->name; $image = $name . ".svg"; $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "image/svg+xml"); $file->setAttribute("manifest:full-path", "Pictures/{$image}"); $manifest->appendChild($file); $image = "tpl-{$name}.png"; $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "image/png"); $file->setAttribute("manifest:full-path", "Pictures/{$image}"); $manifest->appendChild($file); for ($i = 0; $i < count($docs); $i++) { $image = "{$i}-{$name}.png"; $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "image/png"); $file->setAttribute("manifest:full-path", "Pictures/{$image}"); $manifest->appendChild($file); } } $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "image/svg+xml"); $file->setAttribute("manifest:full-path", "Pictures/quadrant.svg"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "application/rdf+xml"); $file->setAttribute("manifest:full-path", "manifest.rdf"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", ""); $file->setAttribute("manifest:full-path", "Configurations2/accelerator/current.xml"); $manifest->appendChild($file); $file = $output_manifest->createElement('manifest:file-entry'); $file->setAttribute("manifest:media-type", "application/vnd.sun.xml.ui.configuration"); $file->setAttribute("manifest:full-path", "Configurations2/"); $manifest->appendChild($file); return $manifest; } function createMeta() { global $output_meta, $lang, $docs, $title, $template; include "export/{$template}/settings-odt-{$lang}.php"; $meta = $output_meta->createElement('office:document-meta'); $meta->setAttribute("xmlns:office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0"); $meta->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink"); $meta->setAttribute("xmlns:dc", "http://purl.org/dc/elements/1.1/"); $meta->setAttribute("xmlns:meta", "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"); $meta->setAttribute("xmlns:ooo", "http://openoffice.org/2004/office"); $meta->setAttribute("xmlns:grddl", "http://www.w3.org/2003/g/data-view#"); $meta->setAttribute("office:version", "1.2"); $ometa = $output_meta->createElement('office:meta'); $ometa->appendChild($output_meta->createElement("meta:generator", "O3S")); $ometa->appendChild($output_meta->createElement("dc:title", $docs[0]->getkey("qsosappfamily"))); $ometa->appendChild($output_meta->createElement("dc:subject", $tpl_subject)); $ometa->appendChild($output_meta->createElement("meta:creation-date", Date('Y-m-d') . 'T' . Date('H:i:s'))); $ometa->appendChild($output_meta->createElement("meta:initial-creator", $tpl_creator)); $ometa->appendChild($output_meta->createElement("dc:date", Date('Y-m-d') . 'T' . Date('H:i:s'))); $ometa->appendChild($output_meta->createElement("dc:creator", $tpl_creator)); $ometa->appendChild($output_meta->createElement("meta:document-statistic")); $mud = $output_meta->createElement('meta:user-defined', $tpl_client1); $mud->setAttribute("meta:name", "Client 1"); $ometa->appendChild($mud); $mud = $output_meta->createElement('meta:user-defined', $tpl_client2); $mud->setAttribute("meta:name", "Client 2"); $ometa->appendChild($mud); $mud = $output_meta->createElement('meta:user-defined', Date('d-m-Y')); $mud->setAttribute("meta:name", "Date"); $ometa->appendChild($mud); $mud = $output_meta->createElement('meta:user-defined', $tpl_projet); $mud->setAttribute("meta:name", "Projet"); $ometa->appendChild($mud); $mud = $output_meta->createElement('meta:user-defined', "1"); $mud->setAttribute("meta:name", "Version Majeure"); $ometa->appendChild($mud); $mud = $output_meta->createElement('meta:user-defined', "0"); $mud->setAttribute("meta:name", "Version Mineure"); $ometa->appendChild($mud); $meta->appendChild($ometa); return $meta; } function createContent($contents) { global $output_text; if (!$contents) { return; } foreach ($contents as $content) { switch ($content[0]) { case "firsttitle1": $output_text->appendChild(createFirstTitle1($content[1])); break; case "title1": $output_text->appendChild(createTitle1($content[1])); break; case "title2": $output_text->appendChild(createTitle2($content[1])); break; case "title3": $output_text->appendChild(createTitle3($content[1])); break; case "todo": $output_text->appendChild(createSimpleTODO($content[1])); break; case "simplep": $output_text->appendChild(createSimpleP($content[1])); break; case "p": $output_text->appendChild(createP($content[1])); break; case "list": $output_text->appendChild(createList($content[1])); break; case "image": $output_text->appendChild(createImageEmbedded($content[1], $content[2], $content[3])); break; } } } //Finalize Document (on disk) $tempdir = $this->temp . uniqid(); mkdir($tempdir, 0755); //$output->save("$tempdir/content.xml"); copy("export/{$template}/template_odt.zip", "odf/{$odtfile}"); include 'libs/pclzip.lib.php'; $oofile = new PclZip("odf/{$odtfile}"); //Predefined XML elements $f = fopen("export/{$template}/odt.xml", "r"); $input = fread($f, filesize("export/{$template}/odt.xml")); fclose($f); //Contents include "export/{$template}/settings-odt-{$lang}.php"; $output_text = new DOMDocument('1.0', 'UTF-8'); //1. Introduction createContent($tpl_msg_content['Introduction']); //2. Template createContent($tpl_msg_content['Template']); $list = array(); //List of sections descriptions $section_title = array(); //List of sections titles $section_name = array(); //List of sections names $images = array(); //List of sections images (MindMap) foreach ($docs[0]->getTree() as $section) { $name = $section->name; $title = $section->title; $image = "tpl-" . $name; $this->exportTemplateSection($docs[0], $name, "{$tempdir}/{$image}"); $image = "{$image}.png"; $desc = $docs[0]->getTreeDesc($section->name); array_push($list, $desc); array_push($section_title, $title); array_push($section_name, $name); $v_list = $oofile->add("{$tempdir}/{$image}", PCLZIP_OPT_ADD_PATH, "Pictures", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 02: ODT generation " . $oofile->errorInfo(true)); } array_push($images, createImage($image)); } //List of sections $output_text->appendChild(createList($docs[0]->getTreeDesc())); //For each section display title, image and description $i = 0; foreach ($images as $image) { //$output_text->appendChild(createBoldTitle($section_title[$i])); $output_text->appendChild(createTitle2($section_title[$i])); $output_text->appendChild($image); $output_text->appendChild(createList($list[$i])); $i++; } //4. Solutions createContent($tpl_msg_content['Solutions_header']); $contents = array(); for ($i = 0; $i < count($ids); $i++) { array_push($contents, $names[$i] . " (" . $docs[$i]->getkey("url") . ") : " . $docs[$i]->getkey("desc")); } $output_text->appendChild(createList($contents)); createContent($tpl_msg_content['Solutions_header_todo']); for ($i = 0; $i < count($ids); $i++) { $output_text->appendChild(createTitle2($names[$i])); createContent($tpl_msg_content['Solutions_header_project']); $this->exportSection($docs[$i], $section_name[0], $tempdir . "/" . $i . "-" . $section_name[0]); $image = $i . "-" . $section_name[0] . ".png"; $v_list = $oofile->add("{$tempdir}/{$image}", PCLZIP_OPT_ADD_PATH, "Pictures", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 02: ODP generation " . $oofile->errorInfo(true)); } $output_text->appendChild(createImage($image)); createContent($tpl_msg_content['Solutions_footer_project']); createContent($tpl_msg_content['Solutions_header_coverage']); for ($k = 1; $k < count($section_title); $k++) { $output_text->appendChild(createBoldTitle($section_title[$k])); $this->exportSection($docs[$i], $section_name[$k], $tempdir . "/" . $i . "-" . $section_name[$k]); $image = $i . "-" . $section_name[$k] . ".png"; $v_list = $oofile->add("{$tempdir}/{$image}", PCLZIP_OPT_ADD_PATH, "Pictures", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 02: ODP generation " . $oofile->errorInfo(true)); } $output_text->appendChild(createImage($image)); createContent($tpl_msg_content['Solutions_footer_coverage']); } } //5. Synthesis createContent($tpl_msg_content['Analysis_header_comparison']); for ($i = 0; $i < count($section_name); $i++) { $image = $section_name[$i] . ".svg"; $this->setCriteria($section_name[$i]); $this->saveRadar("{$tempdir}/{$image}"); $v_list = $oofile->add("{$tempdir}/{$image}", PCLZIP_OPT_ADD_PATH, "Pictures", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 02: ODT generation " . $oofile->errorInfo(true)); } $output_text->appendChild(createBoldTitle($section_title[$i])); $output_text->appendChild(createImage($image)); createContent($tpl_msg_content['Analysis_footer_comparison']); } createContent($tpl_msg_content['Analysis_header_conclusion']); $image = "quadrant.svg"; $this->saveQuadrant("{$tempdir}/{$image}"); $v_list = $oofile->add("{$tempdir}/{$image}", PCLZIP_OPT_ADD_PATH, "Pictures", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 02: ODT generation " . $oofile->errorInfo(true)); } $output_text->appendChild(createImage($image)); createContent($tpl_msg_content['Analysis_footer_conclusion']); //6. Appendixes //QSOS createContent($tpl_msg_content['Appendixes_header']); //Sources or Credits createContent($tpl_msg_content['Sources']); createContent($tpl_msg_content['Credits']); $list = array(); $i = 0; foreach ($this->ids as $id) { $authors = ""; if ($tpl_msg_content['Credits']) { foreach ($docs[$i]->getauthors() as $author) { if ($author->name != "") { $authors .= $author->name . ","; } } if ($authors != "") { $authors = " (" . rtrim($authors, ",") . ")"; } } $tmp_array = array_reverse(explode("/", $files[$i])); array_push($list, $names[$i] . " : " . $tmp_array[0] . $authors); $i++; } $output_text->appendChild(createList($list)); //hack to remove XML declaration foreach ($output_text->childNodes as $node) { $fragment .= $output_text->saveXML($node) . "\n"; } $content = $input . "\n" . $fragment . "</office:text></office:body></office:document-content>"; $file_content = fopen("{$tempdir}/content.xml", 'w'); fwrite($file_content, $content); fclose($file_content); $v_list = $oofile->add("{$tempdir}/content.xml", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 03: ODT generation " . $oofile->errorInfo(true)); } //Manifest generation $output_manifest = new DOMDocument('1.0', 'UTF-8'); $output_manifest->appendChild(createManifest()); $output_manifest->save("{$tempdir}/manifest.xml"); $v_list = $oofile->add("{$tempdir}/manifest.xml", PCLZIP_OPT_ADD_PATH, "META-INF", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 04: ODT generation " . $oofile->errorInfo(true)); } //Meta generation $output_meta = new DOMDocument('1.0', 'UTF-8'); $output_meta->appendChild(createMeta()); $output_meta->save("{$tempdir}/meta.xml"); $v_list = $oofile->add("{$tempdir}/meta.xml", PCLZIP_OPT_REMOVE_PATH, $tempdir); if ($v_list == 0) { die("Error 05: ODT generation " . $oofile->errorInfo(true)); } //Return ODT file to the browser header("Location: odf/{$odtfile}"); exit; }
function createContent($secondClass, $what) { global $parentToMatch; global $table; if ($what == 'wholePage') { $sql = "SELECT * FROM `{$table}` WHERE parent='{$parentToMatch}' ORDER BY `index`"; } else { if ($what == 'singleItem') { $index = mysql_escape_string($_POST["index"]); $sql = "SELECT * FROM `{$table}` WHERE `index` ={$index}"; } } $result = mysql_query($sql); if ($result == false || mysql_num_rows($result) == 0) { /* This echo exists so that ../lib/adminScript.js has something to atatch new list-items after when a new entry is added to the page via AJAX */ echo '<li class="emptyItem"></li>'; return; } else { while ($post = mysql_fetch_assoc($result)) { global $loggedIn; $id = $post["JStitle"]; echo '<li class="contentListItem" id="' . $id . 'ContentListItem">'; if ($post["type"] != 1) { echo '<div id="' . $id . 'NicEditPanel"></div>'; } if ($post["type"] == 0) { if ($loggedIn) { makeAdminInterface($post, 0); } echo '<h3 class="X link" id="' . $id . '">' . $post["title"] . '</h3>'; echo '<div class="hidden ' . $secondClass . '" id="' . $id . 'Div">' . '<p id="' . $id . 'Text">' . $post["content"] . '</p></div>'; } else { if ($post["type"] == 1) { if ($loggedIn) { makeAdminInterface($post, 1); } echo '<div class="openCloseContainer"> <div class="button open" id="' . $id . 'OpenButton"><h4>Öppna alla</h4></div> <div class="button close" id="' . $id . 'CloseButton"><h4>Stäng alla</h4></div></div>'; } else { if ($post["type"] == 2) { if ($loggedIn) { makeAdminInterface($post, 2); } echo '<p id="' . $id . 'Text">' . $post["content"] . '</p>'; } else { if ($post["type"] == 4) { if ($loggedIn) { makeAdminInterface($post, 4); } echo '<h3 class="X kategoriHeader link" id="' . $id . '">' . $post["title"] . '</h3>'; echo '<div class="hidden kategori ' . $secondClass . '" id="' . $id . 'Div">'; $parentToMatch = $post["JStitle"]; echo '<ul id="' . $id . 'UnsortedList">'; createContent('child', 'wholePage'); //Calls itself to see if there are any children. echo '</ul>'; if ($loggedIn) { makeAddButton($id); } echo '</div>'; } } } } echo '</li>'; } } }
function formMetaResults() { $parser = new MetaParser(); return createContent($parser); }
$q = $_REQUEST["page_id"]; } $hint = ""; // lookup all hints from array if $q is different from "" if ($q == "") { $q = 1; } $connection = contentClass::singleton(); function createContent() { global $connection; global $q; global $language; $sql = "select content,option_a,option_b,option_c,option_d from project_one.questions;"; $result = $connection->conn->query($sql); if ($result->num_rows > 0) { while ($row = $result->fetch_assoc()) { echo $row["content"] . "<br/><br/>"; echo "A> " . $row["option_a"] . "         " . "     "; echo "B> " . $row["option_b"] . "<br/>"; echo "C> " . $row["option_c"] . "         " . "     "; echo "D> " . $row["option_d"] . "<br/><hr/><hr/><br/>"; } } } try { createContent(); } catch (Exception $e) { // echo 'Caught exception: ', $e->getMessage(), "\n"; echo "error occured"; }