示例#1
0
 /**
  *	exports the digi-lib-object into a xml structure
  */
 function export($a_deliver = true)
 {
     global $ilDB;
     include_once "./Services/Xml/classes/class.ilNestedSetXML.php";
     // ------------------------------------------------------
     // anhand der ref_id die obj_id ermitteln.
     // ------------------------------------------------------
     $objRow["obj_id"] = ilOject::_lookupObjId();
     $objRow["title"] = ilOject::_lookupTitle($objRow["obj_id"]);
     $obj_id = $objRow["obj_id"];
     $this->mob_ids = array();
     // ------------------------------------------------------
     // start xml-String
     // ------------------------------------------------------
     $xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE ContentObject SYSTEM \"ilias_co.dtd\">\n<ContentObject Type=\"LibObject\">\n";
     // ------------------------------------------------------
     // get global meta-data
     // ------------------------------------------------------
     $nested = new ilNestedSetXML();
     $xml .= $nested->export($obj_id, "dbk") . "\n";
     // ------------------------------------------------------
     // get all book-xml-data recursiv
     // ------------------------------------------------------
     $query = "SELECT  *\n                  FROM lm_tree, lm_data\n                  WHERE lm_tree.lm_id = " . $ilDB->quote($obj_id, "integer") . "\n                  AND   lm_tree.child = lm_data.obj_id\n                  AND   ( lm_data.type =  'du' )\n                  AND lm_tree.depth = 1\n                  ORDER BY lm_tree.lft";
     $result = $ilDB->query($query);
     $treeData = $ilDB->fetchAssoc($result);
     $xml .= $this->exportRekursiv($obj_id, 2, $treeData["lft"], $treeData["rgt"]);
     // ------------------------------------------------------
     // get or create export-directory
     // ------------------------------------------------------
     $this->createExportDirectory();
     $export_dir = $this->getExportDirectory();
     // ------------------------------------------------------
     // get mediaobject-xml-data
     // ------------------------------------------------------
     $mob_ids = $this->mob_ids;
     if (is_array($mob_ids) && count($mob_ids) > 0) {
         reset($mob_ids);
         while (list($key, $val) = each($mob_ids)) {
             $xml .= "<MediaObject>";
             $query = "SELECT * FROM media_item WHERE mob_id= " . $ilDB->quote($key, "integer") . " ";
             //vd($query);
             $first = true;
             $result = $ilDB->query($query);
             while (is_array($row = $ilDB->fetchRow($result))) {
                 if ($first) {
                     //vd($row[purpose]);
                     $nested = new ilNestedSetXML();
                     $metaxml = $nested->export($key, "mob");
                     $metaxml = preg_replace("/Entry=\"(.*?)\"/", "Entry=\"il__mob_" . $key . "\"", $metaxml);
                     $metaxml2 = "<Technical>";
                     $metaxml2 .= "<Format>" . $row["format"] . "</Format>";
                     $metaxml2 .= "<Size>14559</Size>";
                     $metaxml2 .= "<Location Type=\"" . $row["location_type"] . "\">" . $row["location"] . "</Location>";
                     $metaxml2 .= "</Technical>";
                     $metaxml = str_replace("</MetaData>", $metaxml2 . "</MetaData>", $metaxml);
                     $xml .= $metaxml;
                     $first = false;
                 }
                 $xml .= "<MediaItem Purpose=\"" . $row["purpose"] . "\">";
                 $xml .= "<Location Type=\"" . $row["location_type"] . "\">" . $row["location"] . "</Location>";
                 $xml .= "<Format>" . $row["format"] . "</Format>";
                 $xml .= "<Layout Width=\"" . $row["width"] . "\" Height=\"" . $row["height"] . "\"/>";
                 $xml .= "</MediaItem>";
             }
             $xml .= "</MediaObject>";
         }
     }
     // ------------------------------------------------------
     // get bib-xml-data
     // ------------------------------------------------------
     $nested = new ilNestedSetXML();
     $bib = $nested->export($obj_id, "bib");
     $xml .= $bib . "\n";
     // ------------------------------------------------------
     // xml-ending
     // ------------------------------------------------------
     $xml .= "</ContentObject>";
     // ------------------------------------------------------
     // filename and directory-creation
     // ------------------------------------------------------
     $fileName = $objRow["title"];
     $fileName = str_replace(" ", "_", $fileName);
     if (!file_exists($export_dir . "/" . $fileName)) {
         @mkdir($export_dir . "/" . $fileName);
         @chmod($export_dir . "/" . $fileName, 0755);
     }
     if (!file_exists($export_dir . "/" . $fileName . "/objects")) {
         @mkdir($export_dir . "/" . $fileName . "/objects");
         @chmod($export_dir . "/" . $fileName . "/objects", 0755);
     }
     // ------------------------------------------------------
     // copy mob-files
     // ------------------------------------------------------
     $mob_ids = $this->mob_ids;
     if (is_array($mob_ids) && count($mob_ids) > 0) {
         reset($mob_ids);
         while (list($key, $val) = each($mob_ids)) {
             if (!file_exists($export_dir . "/" . $fileName . "/objects/mm" . $key)) {
                 @mkdir($export_dir . "/" . $fileName . "/objects/mm" . $key);
                 @chmod($export_dir . "/" . $fileName . "/objects/mm" . $key, 0755);
             }
             $mobdir = "./data/mobs/mm_" . $key;
             ilUtil::rCopy($mobdir, $export_dir . "/" . $fileName . "/objects/mm" . $key);
         }
     }
     // ------------------------------------------------------
     // save xml-file
     // ------------------------------------------------------
     $fp = fopen($export_dir . "/" . $fileName . "/" . $fileName . ".xml", "wb");
     fwrite($fp, $xml);
     fclose($fp);
     // ------------------------------------------------------
     // zip all files
     // ------------------------------------------------------
     ilUtil::zip($export_dir . "/" . $fileName, $export_dir . "/" . $fileName . ".zip");
     // ------------------------------------------------------
     // deliver files
     // ------------------------------------------------------
     if ($a_deliver) {
         ilUtil::deliverFile($export_dir . "/" . $fileName . ".zip", $fileName);
     } else {
         return $export_dir . "/" . $fileName . ".zip";
     }
     /*
     header("Expires: Mon, 1 Jan 1990 00:00:00 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-store, no-cache, must-revalidate");
     header("Cache-Control: post-check=0, pre-check=0", false);
     header("Pragma: no-cache");
     header("Content-type: application/octet-stream");
     if (stristr(" ".$GLOBALS["HTTP_SERVER_VARS"]["HTTP_USER_AGENT"],"MSIE") )
     {
     	header ("Content-Disposition: attachment; filename=" . $fileName.".zip");
     }
     else
     {
     	header ("Content-Disposition: inline; filename=".$fileName.".zip" );
     }
     header ("Content-length:".(string)( filesize($export_dir."/".$fileName.".zip")) );
     
     readfile( $export_dir."/".$fileName.".zip" );
     */
 }
 /**
  * get a xml string that contains all Bibliography elements, that
  * are referenced by any bibitem alias in the page
  */
 function getBibliographyXML()
 {
     global $ilias, $ilDB;
     // todo: access to $_GET and $_POST variables is not
     // allowed in non GUI classes!
     //
     // access to db table object_reference is not allowed here!
     $r = $ilias->db->query("SELECT * FROM object_reference WHERE ref_id=" . $ilDB->quote($_GET["ref_id"], 'integer'));
     $row = $r->fetchRow(DB_FETCHMODE_ASSOC);
     include_once "./Services/Xml/classes/class.ilNestedSetXML.php";
     $nested = new ilNestedSetXML();
     $bibs_xml = $nested->export($row["obj_id"], "bib");
     return $bibs_xml;
 }