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