00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
00025
00035 class ilCourseArchives
00036 {
00037 var $course_obj;
00038 var $ilias;
00039 var $ilErr;
00040 var $ilDB;
00041 var $tree;
00042 var $lng;
00043
00044 var $archive_type;
00045 var $archive_date;
00046 var $archive_size;
00047 var $archive_name;
00048 var $archive_lang;
00049
00050 var $course_files_obj;
00051 var $course_xml_writer;
00052
00053 private $fss_storage;
00054
00055
00056 function ilCourseArchives(&$course_obj)
00057 {
00058 global $ilErr,$ilDB,$lng,$tree,$ilias;
00059
00060 $this->ilias =& $ilias;
00061 $this->ilErr =& $ilErr;
00062 $this->ilDB =& $ilDB;
00063 $this->lng =& $lng;
00064 $this->tree =& $tree;
00065
00066 $this->ARCHIVE_XML = 1;
00067 $this->ARCHIVE_HTML = 2;
00068 $this->ARCHIVE_PDF = 3;
00069
00070 $this->course_obj =& $course_obj;
00071
00072 $this->__read();
00073 }
00074
00075
00076 function getArchives()
00077 {
00078 return $this->archives;
00079 }
00080
00081 function getArchive($a_id)
00082 {
00083 return $this->archives[$a_id];
00084 }
00085
00086 function getPublicArchives()
00087 {
00088 foreach($this->archives as $id => $archive)
00089 {
00090 if($archive['archive_type'] == $this->ARCHIVE_XML)
00091 {
00092 continue;
00093 }
00094 if($this->course_obj->getArchiveType() != $this->course_obj->ARCHIVE_DOWNLOAD and
00095 $archive['archive_type'] == $this->ARCHIVE_PDF)
00096 {
00097 continue;
00098 }
00099 $public_archives[$id] = $archive;
00100 }
00101
00102 return $public_archives ? $public_archives : array();
00103 }
00104
00105 function setType($a_type)
00106 {
00107 $this->archive_type = $a_type;
00108 }
00109 function getType()
00110 {
00111 return $this->archive_type ? $this->archive_type : $this->ARCHIVE_XML;
00112 }
00113
00114 function setDate($a_date)
00115 {
00116 $this->archive_date = $a_date;
00117 }
00118 function getDate()
00119 {
00120 return $this->archive_date ? $this->archive_date : time();
00121 }
00122
00123 function setSize($a_size)
00124 {
00125 $this->archive_size = $a_size;
00126 }
00127 function getSize()
00128 {
00129 return $this->archive_size;
00130 }
00131 function setName($a_name)
00132 {
00133 $this->archive_name = $a_name;
00134 }
00135 function getName()
00136 {
00137 return $this->archive_name;
00138 }
00139 function setLanguage($a_lang_code)
00140 {
00141 $this->archive_lang = $a_lang_code;
00142 }
00143 function getLanguage()
00144 {
00145 return $this->archive_lang;
00146 }
00147
00148
00149 function getArchiveFile($a_id)
00150 {
00151 $archive = $this->getArchive($a_id);
00152 $this->initCourseFilesObject();
00153
00154 if(PATH_TO_ZIP)
00155 {
00156 return $this->course_files_obj->getArchiveDirectory().'/'.$archive['archive_name'].'.zip';
00157 }
00158 else
00159 {
00160 return $this->course_files_obj->getArchiveDirectory().'/'.$archive['archive_name'];
00161 }
00162
00163 }
00164
00165 function addXML()
00166 {
00167 $this->setType($this->ARCHIVE_XML);
00168 $this->setName(time().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
00169 $this->setDate(time());
00170
00171
00172 $this->initCourseFilesObject();
00173 $this->course_files_obj->addArchiveSubDirectory($this->getName());
00174
00175
00176 $this->initCourseXMLWriter();
00177
00178 $this->course_xml_writer->start();
00179 $this->course_files_obj->writeArchiveFile($this->course_xml_writer->getXML(),$this->getName().'/'.$this->getName().'.xml');
00180
00181
00182
00183
00184 $this->course_files_obj->addArchiveSubDirectory($this->getName().'/objects');
00185
00186 $this->__addZipFiles($this->course_obj->getRefId());
00187
00188
00189
00190 $this->setSize($this->course_files_obj->zipArchive($this->getName(),$this->getName().'.zip'));
00191
00192
00193
00194 $this->add();
00195
00196 return true;
00197 }
00198
00199 function addHTML()
00200 {
00201 $this->setType($this->ARCHIVE_HTML);
00202 $this->setDate(time());
00203 $this->setName($this->getDate().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
00204
00205
00206 $this->initCourseFilesObject();
00207 $this->course_files_obj->addArchiveSubDirectory($this->getName());
00208
00209
00210 $this->course_files_obj->addArchiveSubDirectory($this->getName().'/objects');
00211 $this->__addHTMLFiles($this->course_obj->getRefId());
00212
00213
00214 $this->__addCourseHTML();
00215
00216
00217 $this->course_files_obj->createArchiveOnlineVersion($this->getName());
00218
00219
00220 $this->setSize($this->course_files_obj->zipArchive($this->getName(),$this->getName().'.zip'));
00221
00222
00223 $this->add();
00224
00225 return true;
00226 }
00227
00228
00229 function add()
00230 {
00231 global $ilDB;
00232
00233 $query = "INSERT INTO crs_archives ".
00234 "VALUES ('',".$ilDB->quote($this->course_obj->getId()).",".$ilDB->quote($this->getName()).",".$ilDB->quote($this->getType()).", ".
00235 $ilDB->quote($this->getDate()).",".$ilDB->quote($this->getSize()).",".$ilDB->quote($this->getLanguage()).")";
00236
00237 $this->ilDB->query($query);
00238 $this->__read();
00239
00240 return true;
00241 }
00242
00243 function delete($a_id)
00244 {
00245 global $ilDB;
00246
00247
00248 $this->initCourseFilesObject();
00249
00250 $this->course_files_obj->deleteArchive($this->archives[$a_id]["archive_name"]);
00251
00252 $query = "DELETE FROM crs_archives ".
00253 "WHERE course_id = ".$ilDB->quote($this->course_obj->getId())." ".
00254 "AND archive_id = ".$ilDB->quote($a_id)." ";
00255
00256 $this->ilDB->query($query);
00257 $this->__read();
00258
00259 return true;
00260 }
00261
00262 function deleteAll()
00263 {
00264 foreach($this->getArchives() as $id => $archive)
00265 {
00266 $this->delete($id);
00267 }
00268 }
00269
00270 function initCourseFilesObject()
00271 {
00272 if(!is_object($this->course_files_obj))
00273 {
00274 include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
00275 $this->course_files_obj = new ilFSStorageCourse($this->course_obj->getId());
00276 }
00277 return true;
00278 }
00279
00280 function initCourseXMLWriter()
00281 {
00282 if(!is_object($this->course_xml_writer))
00283 {
00284 include_once "./Modules/Course/classes/class.ilCourseXMLWriter.php";
00285 $this->course_xml_writer =& new ilCourseXMLWriter($this->course_obj);
00286 }
00287 return true;
00288 }
00289
00290
00291 function __addZipFiles($a_parent_id)
00292 {
00293 $this->course_obj->initCourseItemObject();
00294 $this->course_obj->items_obj->setParentId($a_parent_id);
00295
00296 foreach($this->course_obj->items_obj->getAllItems() as $item)
00297 {
00298 if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00299 {
00300 continue;
00301 }
00302
00303
00304 if($abs_file_name = $tmp_obj->getXMLZip())
00305 {
00306 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'].'.zip';
00307 $this->course_files_obj->copyFile($abs_file_name,$this->course_files_obj->getArchiveDirectory().'/'.
00308 $this->getName().'/objects'.
00309 $new_name);
00310 }
00311 $this->__addZipFiles($item['child']);
00312 unset($tmp_obj);
00313 }
00314 return true;
00315 }
00316
00317 function __addHTMLFiles($a_parent_id)
00318 {
00319 $this->course_obj->initCourseItemObject();
00320 $this->course_obj->items_obj->setParentId($a_parent_id);
00321
00322 foreach($this->course_obj->items_obj->getAllItems() as $item)
00323 {
00324 if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00325 {
00326 continue;
00327 }
00328 if($abs_dir_name = $tmp_obj->getHTMLDirectory())
00329 {
00330 $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'];
00331
00332 $this->course_files_obj->addDirectory($this->getName().'/objects/'.$new_name);
00333 $this->course_files_obj->rCopy($abs_dir_name,$this->getName().'/objects/'.$new_name);
00334
00335
00336 $this->html_files["$item[obj_id]"] = "objects/".$new_name."/index.html";
00337 }
00338 $this->__addHTMLFiles($item['child']);
00339 unset($tmp_obj);
00340 }
00341 return true;
00342 }
00343
00344 function __addCourseHTML()
00345 {
00346 global $tpl,$ilias;
00347
00348
00349 if($this->getLanguage())
00350 {
00351 $lng =& new ilLanguage($this->getLanguage());
00352 $lng->loadLanguageModule('crs');
00353 }
00354 else
00355 {
00356 $lng =& $this->lng;
00357 }
00358
00359 $tmp_tpl =& new ilTemplate("tpl.crs_export.html",true,true,'Modules/Course');
00360
00361 $this->course_files_obj->copyFile($tpl->tplPath.'/'.$ilias->account->prefs["style"].'.css',
00362 $this->course_files_obj->getArchiveDirectory().'/'.$this->getName().'/default.css');
00363
00364 $tmp_tpl->setVariable('TITLE',$lng->txt('crs_export'));
00365 $tmp_tpl->setVariable("CRS_STRUCTURE",$lng->txt('crs_structure'));
00366
00367
00368 $tmp_tpl->setVariable("DETAILS_TITLE",$lng->txt("crs_details"));
00369
00370
00371 $tmp_tpl->setVariable("TXT_SYLLABUS",$lng->txt("crs_syllabus"));
00372 $tmp_tpl->setVariable("TXT_CONTACT",$lng->txt("crs_contact"));
00373 $tmp_tpl->setVariable("TXT_CONTACT_NAME",$lng->txt("crs_contact_name"));
00374 $tmp_tpl->setVariable("TXT_CONTACT_RESPONSIBILITY",$lng->txt("crs_contact_responsibility"));
00375 $tmp_tpl->setVariable("TXT_CONTACT_EMAIL",$lng->txt("crs_contact_email"));
00376 $tmp_tpl->setVariable("TXT_CONTACT_PHONE",$lng->txt("crs_contact_phone"));
00377 $tmp_tpl->setVariable("TXT_CONTACT_CONSULTATION",$lng->txt("crs_contact_consultation"));
00378 $tmp_tpl->setVariable("TXT_DATES",$lng->txt("crs_dates"));
00379 $tmp_tpl->setVariable("TXT_ACTIVATION",$lng->txt("crs_activation"));
00380 $tmp_tpl->setVariable("TXT_SUBSCRIPTION",$lng->txt("crs_subscription"));
00381 $tmp_tpl->setVariable("TXT_ARCHIVE",$lng->txt("crs_archive"));
00382
00383
00384 $tmp_tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus() ?
00385 $this->course_obj->getSyllabus() :
00386 $lng->txt("crs_not_available")));
00387
00388 $tmp_tpl->setVariable("CONTACT_NAME",$this->course_obj->getContactName() ?
00389 $this->course_obj->getContactName() :
00390 $lng->txt("crs_not_available"));
00391 $tmp_tpl->setVariable("CONTACT_RESPONSIBILITY",$this->course_obj->getContactResponsibility() ?
00392 $this->course_obj->getContactResponsibility() :
00393 $lng->txt("crs_not_available"));
00394 $tmp_tpl->setVariable("CONTACT_PHONE",$this->course_obj->getContactPhone() ?
00395 $this->course_obj->getContactPhone() :
00396 $lng->txt("crs_not_available"));
00397 $tmp_tpl->setVariable("CONTACT_CONSULTATION",nl2br($this->course_obj->getContactConsultation() ?
00398 $this->course_obj->getContactConsultation() :
00399 $lng->txt("crs_not_available")));
00400 if($this->course_obj->getContactEmail())
00401 {
00402 $tmp_tpl->setCurrentBlock("email_link");
00403 #$tmp_tpl->setVariable("EMAIL_LINK","ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$this->course_obj->getContactEmail());
00404 $tmp_tpl->setVariable("CONTACT_EMAIL",$this->course_obj->getContactEmail());
00405 $tmp_tpl->parseCurrentBlock();
00406 }
00407 else
00408 {
00409 $tmp_tpl->setCurrentBlock("no_mail");
00410 $tmp_tpl->setVariable("NO_CONTACT_EMAIL",$this->course_obj->getContactEmail());
00411 $tmp_tpl->parseCurrentBlock();
00412 }
00413 if($this->course_obj->getActivationUnlimitedStatus())
00414 {
00415 $tmp_tpl->setVariable("ACTIVATION",$lng->txt('crs_unlimited'));
00416 }
00417 else
00418 {
00419 $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationStart())." ".
00420 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationEnd());
00421 $tmp_tpl->setVariable("ACTIVATION",$str);
00422 }
00423 if($this->course_obj->getSubscriptionUnlimitedStatus())
00424 {
00425 $tmp_tpl->setVariable("SUBSCRIPTION",$lng->txt('crs_unlimited'));
00426 }
00427 else
00428 {
00429 $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionStart())." ".
00430 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionEnd());
00431 $tmp_tpl->setVariable("SUBSCRIPTION",$str);
00432 }
00433 if($this->course_obj->getArchiveType() == $this->course_obj->ARCHIVE_DISABLED)
00434 {
00435 $tmp_tpl->setVariable("ARCHIVE",$lng->txt('crs_archive_disabled'));
00436 }
00437 else
00438 {
00439 $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveStart())." ".
00440 $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveEnd());
00441 $tmp_tpl->setVariable("ARCHIVE",$str);
00442 }
00443
00444 $this->structure = '';
00445 $this->__buildStructure($tmp_tpl,$this->course_obj->getRefId());
00446 $tmp_tpl->setVariable("STRUCTURE",$this->structure);
00447
00448 $this->course_files_obj->writeArchiveFile($tmp_tpl->get(),$this->getName().'/index.html');
00449
00450 return true;
00451 }
00452
00453 function __buildStructure(&$tmp_tpl,$a_parent_id)
00454 {
00455 $this->course_obj->initCourseItemObject();
00456 $this->course_obj->items_obj->setParentId($a_parent_id);
00457
00458 $items = $this->course_obj->items_obj->getAllItems();
00459
00460 foreach($items as $key => $item)
00461 {
00462 if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
00463 {
00464 continue;
00465 }
00466
00467
00468 if($key == 0)
00469 {
00470 $this->structure .= "<ul>";
00471 }
00472
00473 $this->structure .= "<li>";
00474
00475 if(isset($this->html_files["$item[obj_id]"]))
00476 {
00477 $link = "<a href=\"./".$this->html_files["$item[obj_id]"]."\">".$item["title"]."</a>";
00478 }
00479 else
00480 {
00481 $link = $item['title'];
00482 }
00483 $this->structure .= $link;
00484 $this->structure .= "</li>";
00485
00486 $this->__buildStructure($tmp_tpl,$item['child']);
00487
00488 if($key == (count($items) - 1))
00489 {
00490 $this->structure .= "</ul>";
00491 }
00492
00493
00494 unset($tmp_obj);
00495 }
00496 return true;
00497 }
00498
00506 public function cloneArchives()
00507 {
00508
00509 }
00510
00511
00512 function __read()
00513 {
00514 global $ilDB;
00515
00516 $this->archives = array();
00517 $query = "SELECT * FROM crs_archives ".
00518 "WHERE course_id = ".$ilDB->quote($this->course_obj->getId())." ".
00519 "ORDER BY archive_date DESC";
00520
00521 $res = $this->ilDB->query($query);
00522 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
00523 {
00524 $this->archives[$row->archive_id]["archive_id"] = $row->archive_id;
00525 $this->archives[$row->archive_id]["archive_type"] = $row->archive_type;
00526 $this->archives[$row->archive_id]["archive_date"] = $row->archive_date;
00527 $this->archives[$row->archive_id]["archive_size"] = $row->archive_size;
00528 $this->archives[$row->archive_id]["archive_name"] = $row->archive_name;
00529 $this->archives[$row->archive_id]["archive_lang"] = $row->archive_lang;
00530 }
00531 return true;
00532 }
00533 }
00534 ?>