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