ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseArchives.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
25 
26 
37 {
39  var $ilias;
40  var $ilErr;
41  var $ilDB;
42  var $tree;
43  var $lng;
44 
50 
53 
54  private $fss_storage;
55 
56 
58  {
59  global $ilErr,$ilDB,$lng,$tree,$ilias;
60 
61  $this->ilias =& $ilias;
62  $this->ilErr =& $ilErr;
63  $this->ilDB =& $ilDB;
64  $this->lng =& $lng;
65  $this->tree =& $tree;
66 
67  $this->ARCHIVE_XML = 1;
68  $this->ARCHIVE_HTML = 2;
69  $this->ARCHIVE_PDF = 3;
70 
71  $this->course_obj =& $course_obj;
72 
73  $this->__read();
74  }
75 
76  // SET GET
77  function getArchives()
78  {
79  return $this->archives;
80  }
81 
82  function getArchive($a_id)
83  {
84  return $this->archives[$a_id];
85  }
86 
87  function getPublicArchives()
88  {
89  foreach($this->archives as $id => $archive)
90  {
91  if($archive['archive_type'] == $this->ARCHIVE_XML)
92  {
93  continue;
94  }
95  if($this->course_obj->getArchiveType() != $this->course_obj->ARCHIVE_DOWNLOAD and
96  $archive['archive_type'] == $this->ARCHIVE_PDF)
97  {
98  continue;
99  }
100  $public_archives[$id] = $archive;
101  }
102 
103  return $public_archives ? $public_archives : array();
104  }
105 
106  function setType($a_type)
107  {
108  $this->archive_type = $a_type;
109  }
110  function getType()
111  {
112  return $this->archive_type ? $this->archive_type : $this->ARCHIVE_XML;
113  }
114 
115  function setDate($a_date)
116  {
117  $this->archive_date = $a_date;
118  }
119  function getDate()
120  {
121  return $this->archive_date ? $this->archive_date : time();
122  }
123 
124  function setSize($a_size)
125  {
126  $this->archive_size = $a_size;
127  }
128  function getSize()
129  {
130  return $this->archive_size;
131  }
132  function setName($a_name)
133  {
134  $this->archive_name = $a_name;
135  }
136  function getName()
137  {
138  return $this->archive_name;
139  }
140  function setLanguage($a_lang_code)
141  {
142  $this->archive_lang = $a_lang_code;
143  }
144  function getLanguage()
145  {
146  return $this->archive_lang;
147  }
148 
149 
150  function getArchiveFile($a_id)
151  {
152  $archive = $this->getArchive($a_id);
153  $this->initCourseFilesObject();
154 
155  if(PATH_TO_ZIP)
156  {
157  return $this->course_files_obj->getArchiveDirectory().'/'.$archive['archive_name'].'.zip';
158  }
159  else
160  {
161  return $this->course_files_obj->getArchiveDirectory().'/'.$archive['archive_name'];
162  }
163 
164  }
165 
171  function addXML($a_selection = "")
172  {
173  $this->setType($this->ARCHIVE_XML);
174  $this->setName(time().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
175  $this->setDate(time());
176 
177  // Step one create folder
178  $this->initCourseFilesObject();
179  $this->course_files_obj->addArchiveSubDirectory($this->getName());
180 
181  // Step two create course xml
182  $this->initCourseXMLWriter();
183 
184  $this->course_xml_writer->start();
185  $this->course_files_obj->writeArchiveFile($this->course_xml_writer->getXML(),$this->getName().'/'.$this->getName().'.xml');
186 
187 
188  // Step three create child object xml
189  // add objects directory
190  $this->course_files_obj->addArchiveSubDirectory($this->getName().'/objects');
191 
192  $this->copied_files = array();
193  $this->__addZipFiles($this->course_obj->getRefId(), $a_selection);
194 
195  // Step four: Write index file
196  include_once("./Services/Export/classes/class.ilExport.php");
197  ilExport::_generateIndexFile($this->course_files_obj->getArchiveDirectory().'/'.
198  $this->getName().'/index.html', $this->course_obj->getId(),$this->copied_files);
199 
200  // Step five zip
201  $this->setSize($this->course_files_obj->zipArchive($this->getName(),$this->getName().'.zip'));
202 
203 
204  // Finally add entry in crs_archives table
205  $this->add();
206 
207  return true;
208  }
209 
210  function addHTML()
211  {
212  $this->setType($this->ARCHIVE_HTML);
213  $this->setDate(time());
214  $this->setName($this->getDate().'__'.$this->ilias->getSetting('inst_id').'__crs_'.$this->course_obj->getId());
215 
216  // Step one create folder
217  $this->initCourseFilesObject();
218  $this->course_files_obj->addArchiveSubDirectory($this->getName());
219 
220  // Step two, create child html
221  $this->course_files_obj->addArchiveSubDirectory($this->getName().'/objects');
222  $this->__addHTMLFiles($this->course_obj->getRefId());
223 
224  // Step three create course html
225  $this->__addCourseHTML();
226 
227  // Step three create copy in web dir
228  $this->course_files_obj->createArchiveOnlineVersion($this->getName());
229 
230  // Step four zip
231  $this->setSize($this->course_files_obj->zipArchive($this->getName(),$this->getName().'.zip'));
232 
233  // Finally add entry in crs_archives table
234  $this->add();
235 
236  return true;
237  }
238 
239 
240  function add()
241  {
242  global $ilDB;
243 
244  $next_id = $ilDB->nextId('crs_archives');
245  $query = "INSERT INTO crs_archives (archive_id,course_id,archive_name,archive_type,archive_date,archive_size,archive_lang) ".
246  "VALUES (" .
247  $ilDB->quote($next_id,'integer').", ".
248  $ilDB->quote($this->course_obj->getId(),'integer').",".
249  $ilDB->quote($this->getName(),'text').",".
250  $ilDB->quote($this->getType(),'integer').", ".
251  $ilDB->quote($this->getDate(),'integer').",".
252  $ilDB->quote($this->getSize(),'integer').",".
253  $ilDB->quote($this->getLanguage(),'text').
254  ")";
255  $res = $ilDB->manipulate($query);
256 
257  $this->__read();
258  return true;
259  }
260 
261  function delete($a_id)
262  {
263  global $ilDB;
264 
265  // Delete in file system
266  $this->initCourseFilesObject();
267 
268  $this->course_files_obj->deleteArchive($this->archives[$a_id]["archive_name"]);
269 
270  $query = "DELETE FROM crs_archives ".
271  "WHERE course_id = ".$ilDB->quote($this->course_obj->getId(),'integer')." ".
272  "AND archive_id = ".$ilDB->quote($a_id,'integer')." ";
273  $res = $ilDB->manipulate($query);
274 
275  $this->__read();
276  return true;
277  }
278 
279  function deleteAll()
280  {
281  foreach($this->getArchives() as $id => $archive)
282  {
283  $this->delete($id);
284  }
285  }
286 
288  {
289  if(!is_object($this->course_files_obj))
290  {
291  include_once('Modules/Course/classes/class.ilFSStorageCourse.php');
292  $this->course_files_obj = new ilFSStorageCourse($this->course_obj->getId());
293  }
294  return true;
295  }
296 
298  {
299  if(!is_object($this->course_xml_writer))
300  {
301  include_once "./Modules/Course/classes/class.ilCourseXMLWriter.php";
302  $this->course_xml_writer =& new ilCourseXMLWriter($this->course_obj);
303  }
304  return true;
305  }
306 
307  // PRIVATE
308 
314  function __addZipFiles($a_parent_id, $a_selection = "")
315  {
316  $this->course_obj->initCourseItemObject();
317  $this->course_obj->items_obj->setParentId($a_parent_id);
318 
319  foreach($this->course_obj->items_obj->getAllItems() as $item)
320  {
321  if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
322  {
323  continue;
324  }
325  $action = $a_selection[$item['child']];
326  if ($a_selection == "")
327  {
328  $action = "create";
329  }
330 
331  if ($action == "omit")
332  {
333  continue;
334  }
335 
336  if ($action == "create")
337  {
338  $abs_file_name = $tmp_obj->getXMLZip();
339  }
340  else
341  {
342  include_once("./Services/Export/classes/class.ilExport.php");
343  $info = ilExport::_getLastExportFileInformation($item['obj_id'], "xml", $item['type']);
344  $abs_file_name = ilExport::_getExportDirectory($item['obj_id'], "xml", $item['type'])."/".$info["file"];
345  if (!@is_file($abs_file_name))
346  {
347  $abs_file_name = "";
348  }
349  }
350 
351  // must return absolute path to zip file
352  if ($abs_file_name != "")
353  {
354  //$new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'].'.zip';
355  $new_name = basename($abs_file_name);
356  $this->course_files_obj->copyFile($abs_file_name,$this->course_files_obj->getArchiveDirectory().'/'.
357  $this->getName().'/'.$new_name);
358  if (is_file($this->course_files_obj->getArchiveDirectory().'/'.
359  $this->getName().'/'.$new_name))
360  {
361  $this->copied_files[] = array("title" => $item['title'],
362  "file" => $new_name, "type" => $item['type']);
363  }
364  }
365  $this->__addZipFiles($item['child']);
366 
367  unset($tmp_obj);
368  }
369  return true;
370  }
371 
372  function __addHTMLFiles($a_parent_id)
373  {
374  $this->course_obj->initCourseItemObject();
375  $this->course_obj->items_obj->setParentId($a_parent_id);
376 
377  foreach($this->course_obj->items_obj->getAllItems() as $item)
378  {
379  if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
380  {
381  continue;
382  }
383  if($abs_dir_name = $tmp_obj->getHTMLDirectory())
384  {
385  $new_name = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['obj_id'];
386 
387  $this->course_files_obj->addDirectory($this->getName().'/objects/'.$new_name);
388  $this->course_files_obj->rCopy($abs_dir_name,$this->getName().'/objects/'.$new_name);
389 
390  // Store filename in hashtable (used for create course html tree)
391  $this->html_files["$item[obj_id]"] = "objects/".$new_name."/index.html";
392  }
393  $this->__addHTMLFiles($item['child']);
394  unset($tmp_obj);
395  }
396  return true;
397  }
398 
399  function __addCourseHTML()
400  {
401  global $tpl,$ilias;
402 
403  // Get Language
404  if($this->getLanguage())
405  {
406  $lng =& new ilLanguage($this->getLanguage());
407  $lng->loadLanguageModule('crs');
408  }
409  else
410  {
411  $lng =& $this->lng;
412  }
413 
414  $tmp_tpl =& new ilTemplate("tpl.crs_export.html",true,true,'Modules/Course');
415 
416  $this->course_files_obj->copyFile($tpl->tplPath.'/'.$ilias->account->prefs["style"].'.css',
417  $this->course_files_obj->getArchiveDirectory().'/'.$this->getName().'/default.css');
418 
419  $tmp_tpl->setVariable('TITLE',$lng->txt('crs_export'));
420  $tmp_tpl->setVariable("CRS_STRUCTURE",$lng->txt('crs_structure'));
421 
422 
423  $tmp_tpl->setVariable("DETAILS_TITLE",$lng->txt("crs_details"));
424 
425  // SET TXT VARIABLES
426  $tmp_tpl->setVariable("TXT_SYLLABUS",$lng->txt("crs_syllabus"));
427  $tmp_tpl->setVariable("TXT_CONTACT",$lng->txt("crs_contact"));
428  $tmp_tpl->setVariable("TXT_CONTACT_NAME",$lng->txt("crs_contact_name"));
429  $tmp_tpl->setVariable("TXT_CONTACT_RESPONSIBILITY",$lng->txt("crs_contact_responsibility"));
430  $tmp_tpl->setVariable("TXT_CONTACT_EMAIL",$lng->txt("crs_contact_email"));
431  $tmp_tpl->setVariable("TXT_CONTACT_PHONE",$lng->txt("crs_contact_phone"));
432  $tmp_tpl->setVariable("TXT_CONTACT_CONSULTATION",$lng->txt("crs_contact_consultation"));
433  $tmp_tpl->setVariable("TXT_DATES",$lng->txt("crs_dates"));
434  $tmp_tpl->setVariable("TXT_ACTIVATION",$lng->txt("crs_activation"));
435  $tmp_tpl->setVariable("TXT_SUBSCRIPTION",$lng->txt("crs_subscription"));
436  $tmp_tpl->setVariable("TXT_ARCHIVE",$lng->txt("crs_archive"));
437 
438  // FILL
439  $tmp_tpl->setVariable("SYLLABUS",nl2br($this->course_obj->getSyllabus() ?
440  $this->course_obj->getSyllabus() :
441  $lng->txt("crs_not_available")));
442 
443  $tmp_tpl->setVariable("CONTACT_NAME",$this->course_obj->getContactName() ?
444  $this->course_obj->getContactName() :
445  $lng->txt("crs_not_available"));
446  $tmp_tpl->setVariable("CONTACT_RESPONSIBILITY",$this->course_obj->getContactResponsibility() ?
447  $this->course_obj->getContactResponsibility() :
448  $lng->txt("crs_not_available"));
449  $tmp_tpl->setVariable("CONTACT_PHONE",$this->course_obj->getContactPhone() ?
450  $this->course_obj->getContactPhone() :
451  $lng->txt("crs_not_available"));
452  $tmp_tpl->setVariable("CONTACT_CONSULTATION",nl2br($this->course_obj->getContactConsultation() ?
453  $this->course_obj->getContactConsultation() :
454  $lng->txt("crs_not_available")));
455  if($this->course_obj->getContactEmail())
456  {
457  $tmp_tpl->setCurrentBlock("email_link");
458  #$tmp_tpl->setVariable("EMAIL_LINK","ilias.php?baseClass=ilMailGUI&type=new&rcp_to=".$this->course_obj->getContactEmail());
459  $tmp_tpl->setVariable("CONTACT_EMAIL",$this->course_obj->getContactEmail());
460  $tmp_tpl->parseCurrentBlock();
461  }
462  else
463  {
464  $tmp_tpl->setCurrentBlock("no_mail");
465  $tmp_tpl->setVariable("NO_CONTACT_EMAIL",$this->course_obj->getContactEmail());
466  $tmp_tpl->parseCurrentBlock();
467  }
468  if($this->course_obj->getActivationUnlimitedStatus())
469  {
470  $tmp_tpl->setVariable("ACTIVATION",$lng->txt('crs_unlimited'));
471  }
472  else
473  {
474  $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationStart())." ".
475  $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getActivationEnd());
476  $tmp_tpl->setVariable("ACTIVATION",$str);
477  }
478  if($this->course_obj->getSubscriptionUnlimitedStatus())
479  {
480  $tmp_tpl->setVariable("SUBSCRIPTION",$lng->txt('crs_unlimited'));
481  }
482  else
483  {
484  $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionStart())." ".
485  $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getSubscriptionEnd());
486  $tmp_tpl->setVariable("SUBSCRIPTION",$str);
487  }
488  if($this->course_obj->getArchiveType() == $this->course_obj->ARCHIVE_DISABLED)
489  {
490  $tmp_tpl->setVariable("ARCHIVE",$lng->txt('crs_archive_disabled'));
491  }
492  else
493  {
494  $str = $lng->txt("crs_from")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveStart())." ".
495  $lng->txt("crs_to")." ".strftime("%Y-%m-%d %R",$this->course_obj->getArchiveEnd());
496  $tmp_tpl->setVariable("ARCHIVE",$str);
497  }
498 
499  $this->structure = '';
500  $this->__buildStructure($tmp_tpl,$this->course_obj->getRefId());
501  $tmp_tpl->setVariable("STRUCTURE",$this->structure);
502 
503  $this->course_files_obj->writeArchiveFile($tmp_tpl->get(),$this->getName().'/index.html');
504 
505  return true;
506  }
507 
508  function __buildStructure(&$tmp_tpl,$a_parent_id)
509  {
510  $this->course_obj->initCourseItemObject();
511  $this->course_obj->items_obj->setParentId($a_parent_id);
512 
513  $items = $this->course_obj->items_obj->getAllItems();
514 
515  foreach($items as $key => $item)
516  {
517  if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
518  {
519  continue;
520  }
521 
522 
523  if($key == 0)
524  {
525  $this->structure .= "<ul>";
526  }
527 
528  $this->structure .= "<li>";
529 
530  if(isset($this->html_files["$item[obj_id]"]))
531  {
532  $link = "<a href=\"./".$this->html_files["$item[obj_id]"]."\">".$item["title"]."</a>";
533  }
534  else
535  {
536  $link = $item['title'];
537  }
538  $this->structure .= $link;
539  $this->structure .= "</li>";
540 
541  $this->__buildStructure($tmp_tpl,$item['child']);
542 
543  if($key == (count($items) - 1))
544  {
545  $this->structure .= "</ul>";
546  }
547 
548 
549  unset($tmp_obj);
550  }
551  return true;
552  }
553 
561  public function cloneArchives()
562  {
563 
564  }
565 
566 
567  function __read()
568  {
569  global $ilDB;
570 
571  $this->archives = array();
572  $query = "SELECT * FROM crs_archives ".
573  "WHERE course_id = ".$ilDB->quote($this->course_obj->getId(),'integer')." ".
574  "ORDER BY archive_date DESC";
575 
576  $res = $this->ilDB->query($query);
577  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
578  {
579  $this->archives[$row->archive_id]["archive_id"] = $row->archive_id;
580  $this->archives[$row->archive_id]["archive_type"] = $row->archive_type;
581  $this->archives[$row->archive_id]["archive_date"] = $row->archive_date;
582  $this->archives[$row->archive_id]["archive_size"] = $row->archive_size;
583  $this->archives[$row->archive_id]["archive_name"] = $row->archive_name;
584  $this->archives[$row->archive_id]["archive_lang"] = $row->archive_lang;
585  }
586  return true;
587  }
588 }
589 ?>