/**
  * Export lesson
  *
  * This function is used to export the current lesson's data to
  * a file, which can then be imported to other systems. Apart from
  * the lesson content, the user may optinally specify additional
  * information to export, using the $exportEntities array. If
  * $exportEntities is 'all', everything that can be exported, is
  * exported
  *
  * <br/>Example:
  * <code>
  * $exportedFile = $lesson -> export('all');
  * </code>
  *
  * @param array $exportEntities The additional data to export
  * @param boolean $rename Whether to rename the exported file with the same name as the lesson
  * @param boolean $exportFiles Whether to export files as well
  * @return EfrontFile The object of the exported data file
  * @since 3.5.0
  * @access public
  */
 public function export($exportEntities, $rename = true, $exportFiles = true)
 {
     if (!$exportEntities) {
         $exportEntities = array('export_surveys' => 1, 'export_announcements' => 1, 'export_glossary' => 1, 'export_calendar' => 1, 'export_comments' => 1, 'export_rules' => 1);
     }
     $data['lessons'] = $this->lesson;
     unset($data['lessons']['share_folder']);
     unset($data['lessons']['instance_source']);
     unset($data['lessons']['originating_course']);
     $content = eF_getTableData("content", "*", "lessons_ID=" . $this->lesson['id']);
     if (sizeof($content) > 0) {
         $contentIds = array();
         for ($i = 0; $i < sizeof($content); $i++) {
             $content[$i]['data'] = str_replace(G_SERVERNAME, "##SERVERNAME##", $content[$i]['data']);
             $content[$i]['data'] = str_replace("content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']), "##LESSONSLINK##", $content[$i]['data']);
             $contentIds[] = $content[$i]['id'];
         }
         $content_list = implode(",", array_values($contentIds));
         $data['content'] = $content;
         $questions = eF_getTableData("questions", "*", "lessons_ID=" . $this->lesson['id']);
         if (sizeof($questions) > 0) {
             for ($i = 0; $i < sizeof($questions); $i++) {
                 $questions[$i]['text'] = str_replace(G_SERVERNAME, "##SERVERNAME##", $questions[$i]['text']);
                 $questions[$i]['text'] = str_replace("content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']), "##LESSONSLINK##", $questions[$i]['text']);
             }
             $data['questions'] = $questions;
         }
         $tests = eF_getTableData("tests", "*", "lessons_ID=" . $this->lesson['id']);
         if (sizeof($tests)) {
             $testsIds = array();
             foreach ($tests as $key => $value) {
                 $testsIds[] = $value['id'];
             }
             $tests_list = implode(",", array_values($testsIds));
             $tests_to_questions = eF_getTableData("tests_to_questions", "*", "tests_ID IN ({$tests_list})");
             for ($i = 0; $i < sizeof($tests); $i++) {
                 $tests[$i]['description'] = str_replace(G_SERVERNAME, "##SERVERNAME##", $tests[$i]['description']);
                 $tests[$i]['description'] = str_replace("content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']), "##LESSONSLINK##", $tests[$i]['description']);
             }
             $data['tests'] = $tests;
             $data['tests_to_questions'] = $tests_to_questions;
         }
         if (isset($exportEntities['export_rules'])) {
             $rules = eF_getTableData("rules", "*", "lessons_ID=" . $this->lesson['id']);
             if (sizeof($rules) > 0) {
                 $data['rules'] = $rules;
             }
         }
         if (isset($exportEntities['export_comments'])) {
             $comments = eF_getTableData("comments", "*", "content_ID IN ({$content_list})");
             if (sizeof($comments) > 0) {
                 $data['comments'] = $comments;
             }
         }
     }
     if (isset($exportEntities['export_calendar'])) {
         $calendar = calendar::getLessonCalendarEvents($this);
         $calendar = array_values($calendar);
         if (sizeof($calendar) > 0) {
             $data['calendar'] = $calendar;
         }
     }
     if (isset($exportEntities['export_glossary'])) {
         $glossary = eF_getTableData("glossary", "*", "lessons_ID = " . $this->lesson['id']);
         if (sizeof($glossary) > 0) {
             $data['glossary'] = $glossary;
         }
     }
     if (isset($exportEntities['export_announcements'])) {
         $news = eF_getTableData("news", "*", "lessons_ID=" . $this->lesson['id']);
         if (sizeof($news) > 0) {
             $data['news'] = $news;
         }
     }
     if (isset($exportEntities['export_surveys'])) {
         $surveys = eF_getTableData("surveys", "*", "lessons_ID=" . $this->lesson['id']);
         //prepei na ginei to   lesson_ID -> lessons_ID sti basi (ayto isos to parampsoyme eykola)
         if (sizeof($surveys) > 0) {
             $data['surveys'] = $surveys;
             $surveys_ = array();
             foreach ($surveys as $key => $value) {
                 $surveys_[$value['id']] = $value;
             }
             $surveys_list = implode(",", array_keys($surveys_));
             $questions_to_surveys = eF_getTableData("questions_to_surveys", "*", "surveys_ID IN ({$surveys_list})");
             // oposipote omos to survey_ID -> surveys_ID sti basi
             if (sizeof($questions_to_surveys) > 0) {
                 $data['questions_to_surveys'] = $questions_to_surveys;
             }
         }
     }
     $lesson_conditions = eF_getTableData("lesson_conditions", "*", "lessons_ID=" . $this->lesson['id']);
     if (sizeof($lesson_conditions) > 0) {
         $data['lesson_conditions'] = $lesson_conditions;
     }
     $projects = eF_getTableData("projects", "*", "lessons_ID=" . $this->lesson['id']);
     if (sizeof($projects) > 0) {
         $data['projects'] = $projects;
     }
     $lesson_files = eF_getTableData("files", "*", "path like '" . str_replace(G_ROOTPATH, '', EfrontDirectory::normalize($this->getDirectory())) . "%'");
     if (sizeof($lesson_files) > 0) {
         $data['files'] = $lesson_files;
     }
     if (G_VERSIONTYPE != 'community') {
         #cpp#ifndef COMMUNITY
         if (G_VERSIONTYPE != 'standard') {
             #cpp#ifndef STANDARD
             //Export scorm tables from here over
             $scormLessonTables = array('scorm_sequencing_adlseq_map_info', 'scorm_sequencing_content_to_organization', 'scorm_sequencing_maps_info', 'scorm_sequencing_organizations');
             foreach ($scormLessonTables as $table) {
                 $scorm_data = eF_getTableData($table, "*", "lessons_ID=" . $this->lesson['id']);
                 if (sizeof($scorm_data) > 0) {
                     $data[$table] = $scorm_data;
                 }
             }
             $scormContentTables = array('scorm_sequencing_completion_threshold', 'scorm_sequencing_constrained_choice', 'scorm_sequencing_control_mode', 'scorm_sequencing_delivery_controls', 'scorm_sequencing_hide_lms_ui', 'scorm_sequencing_limit_conditions', 'scorm_sequencing_maps', 'scorm_sequencing_map_info', 'scorm_sequencing_objectives', 'scorm_sequencing_rollup_considerations', 'scorm_sequencing_rollup_controls', 'scorm_sequencing_rollup_rules', 'scorm_sequencing_rules');
             if ($content_list) {
                 foreach ($scormContentTables as $table) {
                     $scorm_data = eF_getTableData($table, "*", "content_ID IN ({$content_list})");
                     if (sizeof($scorm_data) > 0) {
                         $data[$table] = $scorm_data;
                     }
                     if ($table == 'scorm_sequencing_rollup_rules' && sizeof($scorm_data) > 0) {
                         $ids = array();
                         foreach ($scorm_data as $value) {
                             $ids[] = $value['id'];
                         }
                         $result = eF_getTableData('scorm_sequencing_rollup_rule', "*", "scorm_sequencing_rollup_rules_ID IN (" . implode(",", $ids) . ")");
                         $data['scorm_sequencing_rollup_rule'] = $result;
                     }
                     if ($table == 'scorm_sequencing_rules' && sizeof($scorm_data) > 0) {
                         $ids = array();
                         foreach ($scorm_data as $value) {
                             $ids[] = $value['id'];
                         }
                         $result = eF_getTableData('scorm_sequencing_rule', "*", "scorm_sequencing_rules_ID IN (" . implode(",", $ids) . ")");
                         $data['scorm_sequencing_rule'] = $result;
                     }
                 }
             }
         }
         #cpp#endif
     }
     #cpp#endif
     //'scorm_sequencing_rollup_rule', 'scorm_sequencing_rule',
     // MODULES - Export module data
     // Get all modules (NOT only the ones that have to do with the user type)
     $modules = eF_loadAllModules();
     foreach ($modules as $module) {
         if ($moduleData = $module->onExportLesson($this->lesson['id'])) {
             $data[$module->className] = $moduleData;
         }
     }
     file_put_contents($this->directory . '/' . "data.dat", serialize($data));
     //Create database dump file
     if ($exportFiles) {
         $lessonDirectory = new EfrontDirectory($this->directory);
         $file = $lessonDirectory->compress($this->lesson['id'] . '_exported.zip', false);
         //Compress the lesson files
     } else {
         $dataFile = new EfrontFile($this->directory . '/' . "data.dat");
         $file = $dataFile->compress($this->lesson['id'] . '_exported.zip');
     }
     $newList = FileSystemTree::importFiles($file['path']);
     //Import the file to the database, so we can download it
     $file = new EfrontFile(current($newList));
     if (empty($GLOBALS['currentUser'])) {
         if ($_SESSION['s_login']) {
             $GLOBALS['currentUser'] = EfrontUserFactory::factory($_SESSION['s_login']);
             $userTempDir = $GLOBALS['currentUser']->user['directory'] . '/temp';
         } else {
             $userTempDir = sys_get_temp_dir();
         }
     } else {
         $userTempDir = $GLOBALS['currentUser']->user['directory'] . '/temp';
     }
     if (!is_dir($userTempDir)) {
         //If the user's temp directory does not exist, create it
         $userTempDir = EfrontDirectory::createDirectory($userTempDir, false);
         $userTempDir = $userTempDir['path'];
     }
     try {
         $existingFile = new EfrontFile($userTempDir . '/' . EfrontFile::encode($this->lesson['name']) . '.zip');
         //Delete any previous exported files
         $existingFile->delete();
     } catch (Exception $e) {
     }
     if ($rename) {
         $newName = str_replace(array('"', '>', '<', '*', '?', ':'), array('&quot;', '&gt;', '&lt;', '&#42;', '&#63;', '&#58;'), $this->lesson['name']);
         $file->rename($userTempDir . '/' . EfrontFile::encode($newName) . '.zip', true);
     }
     unlink($this->directory . '/' . "data.dat");
     //Delete database dump file
     return $file;
 }
示例#2
0
 private function getRssSource($source, $mode, $lesson)
 {
     $feeds = $this->getProvidedFeeds();
     foreach ($feeds as $value) {
         if ($value['active'] && $value['mode'] == 'system') {
             $systemFeeds[$value['type']] = $value;
         } else {
             if ($value['active'] && $value['mode'] == 'lesson') {
                 $lessonFeeds[$value['type']] = $value;
             }
         }
     }
     if ($mode == 'system' && !in_array($source, array_keys($systemFeeds))) {
         return array();
     } elseif ($mode == 'lesson' && !in_array($source, array_keys($lessonFeeds))) {
         return array();
     }
     $data = array();
     switch ($source) {
         case 'announcements':
             if ($mode == 'system') {
                 $news = news::getNews(0, true);
             } elseif ($mode == 'lesson') {
                 if ($lesson) {
                     $news = news::getNews($lesson, true);
                 } else {
                     $lessons = eF_getTableDataFlat("lessons", "id, name");
                     $lessonNames = array_combine($lessons['id'], $lessons['name']);
                     $news = news::getNews($lessons['id'], true);
                 }
             }
             $count = 1;
             foreach ($news as $value) {
                 if ($mode == 'lesson' && !$lesson) {
                     $value['title'] = $lessonNames[$value['lessons_ID']] . ': ' . $value['title'];
                     $link = G_SERVERNAME . 'userpage.php?lessons_ID=' . $value['lessons_ID'] . '&amp;ctg=news&amp;view=' . $value['id'];
                 } else {
                     $link = G_SERVERNAME . 'userpage.php?ctg=news&amp;view=' . $value['id'];
                 }
                 $data[] = array('title' => $value['title'], 'link' => $link, 'description' => $value['data']);
                 /*
                     				if ($count++ == $this -> feedLimit) {
                     					break;
                     				}
                 */
             }
             break;
         case 'catalog':
             $constraints = array("return_objects" => false, 'archive' => false, 'active' => true);
             $result = EfrontCourse::getAllCourses($constraints);
             $directionsTree = new EfrontDirectionsTree();
             $directionPaths = $directionsTree->toPathString();
             foreach ($result as $value) {
                 $pathString = $directionPaths[$value['directions_ID']] . '&nbsp;&rarr;&nbsp;' . $value['name'];
                 $data[] = array('title' => $pathString, 'link' => G_SERVERNAME . 'index.php?ctg=lesson_info&amp;courses_ID=' . $value['id'], 'description' => implode("<br>", unserialize($value['info'])));
             }
             $result = eF_getTableData("lessons", "id,name,directions_ID, info", "archive=0 and instance_source = 0 and active=1 and course_only=0", "name");
             foreach ($result as $value) {
                 $pathString = $directionPaths[$value['directions_ID']] . '&nbsp;&rarr;&nbsp;' . $value['name'];
                 $data[] = array('title' => $pathString, 'link' => G_SERVERNAME . 'index.php?ctg=lesson_info&amp;lessons_ID=' . $value['id'], 'description' => implode("<br>", unserialize($value['info'])));
             }
             $data = array_values(eF_multisort($data, 'title', 'asc'));
             //Sort results based on path string
             break;
         case 'calendar':
             if ($mode == 'system') {
                 $events = calendar::getGlobalCalendarEvents();
             } elseif ($mode == 'lesson') {
                 if ($lesson) {
                     $events = calendar::getLessonCalendarEvents($lesson);
                 } else {
                     $events = calendar::getCalendarEventsForAllLessons();
                 }
             }
             foreach ($events as $value) {
                 $value['name'] ? $title = formatTimestamp($value['timestamp']) . ' (' . $value['name'] . ')' : ($title = formatTimestamp($value['timestamp']));
                 $data[] = array('title' => $title, 'link' => G_SERVERNAME . 'userpage.php?ctg=calendar&amp;view_calendar=' . $value['timestamp'] . '&amp;type=0', 'description' => $value['data']);
             }
             break;
             /*
                 		case 'history':
                 			$currentUser = $this -> getCurrentUser();
             
             				$eventObjects = array();
                 			$result = eF_getTableData("events", "*", "", "timestamp DESC limit 100");
             				foreach ($result as $value) {
             					$eventObject = new EfrontEvent($value);
             					$eventObject -> createMessage();
             					pr($eventObject);
             				}
             
                 			break;
             */
         /*
             		case 'history':
             			$currentUser = $this -> getCurrentUser();
         
         				$eventObjects = array();
             			$result = eF_getTableData("events", "*", "", "timestamp DESC limit 100");
         				foreach ($result as $value) {
         					$eventObject = new EfrontEvent($value);
         					$eventObject -> createMessage();
         					pr($eventObject);
         				}
         
             			break;
         */
         case 'structure':
             if ($lesson) {
                 $contentTree = new EfrontContentTree($lesson);
                 $contentPath = $contentTree->toPathStrings();
                 foreach ($contentPath as $key => $value) {
                     $data[] = array('title' => $value, 'link' => G_SERVERNAME . 'userpage.php?lessons_ID=' . $lesson . '&amp;unit=' . $key, 'description' => $value);
                 }
             }
             break;
         case 'forum':
             if ($mode == 'system') {
                 $result = eF_getTableData("f_messages fm JOIN f_topics ft JOIN f_forums ff LEFT OUTER JOIN lessons l ON ff.lessons_ID = l.id", "ff.title as forum_name, fm.body, fm.title, fm.id, ft.id as topic_id, ft.title as topic_title, fm.users_LOGIN, fm.timestamp, l.name as lessons_name, lessons_id as show_lessons_id", "ft.f_forums_ID=ff.id AND fm.f_topics_ID=ft.id ", "fm.timestamp desc LIMIT 100");
             } elseif ($mode == 'lesson') {
                 if ($lesson) {
                     $result = eF_getTableData("f_messages fm JOIN f_topics ft JOIN f_forums ff LEFT OUTER JOIN lessons l ON ff.lessons_ID = l.id", "ff.title as forum_name, fm.body, fm.title, fm.id, ft.id as topic_id, ft.title as topic_title, fm.users_LOGIN, fm.timestamp, l.name as lessons_name, lessons_id as show_lessons_id", "ft.f_forums_ID=ff.id AND fm.f_topics_ID=ft.id AND ff.lessons_ID = '" . $lesson . "'", "fm.timestamp desc LIMIT 100");
                 } else {
                     $result = eF_getTableData("f_messages fm JOIN f_topics ft JOIN f_forums ff LEFT OUTER JOIN lessons l ON ff.lessons_ID = l.id", "ff.title as forum_name, fm.body, fm.title, fm.id, ft.id as topic_id, ft.title as topic_title, fm.users_LOGIN, fm.timestamp, l.name as lessons_name, lessons_id as show_lessons_id", "ft.f_forums_ID=ff.id AND fm.f_topics_ID=ft.id AND ff.lessons_ID != 0", "fm.timestamp desc LIMIT 100");
                 }
             }
             foreach ($result as $value) {
                 $value['title'] = $value['forum_name'] . ' >> ' . $value['topic_title'] . ' >> ' . $value['title'];
                 if ($mode == 'system' && $value['lessons_name'] || $mode == 'lesson' && !$lesson) {
                     $value['title'] = $value['lessons_name'] . ': ' . $value['title'];
                 }
                 $data[] = array('title' => $value['title'], 'link' => G_SERVERNAME . 'userpage.php?ctg=forum&amp;topic=' . $value['topic_id'], 'description' => $value['body']);
             }
             break;
         default:
             break;
     }
     return $data;
 }