Ejemplo n.º 1
0
 /**
  * Import lesson
  *
  * This function is used to import a lesson exported to a file
  * The first step is to optionally initialize the lesson, using initialize().
  * It then uncompresses the given file and proceeds to importing
  * <br/>Example:
  * <code>
  * try {
  *     $lesson = new EfrontLesson(32);                                             //32 is the lesson id
  *     $file = new EfrontFile($lesson -> getDirectory().'data.tar.gz');            //The file resides inside the lesson directory and is called 'data.tar.gz'
  *     $lesson -> import(array('content'), $file);
  * } catch (Exception $e) {
  *     echo $e -> getMessage();
  * }
  * </code><br/>
  *
  * @param EfrontFile $file The compressed lesson file object
  * @param array $deleteEntities The lesson aspects to initialize
  * @param boolean $lessonProperties Whether to import lesson properties as well
  * @param boolean $keepName Whether to keep the current (false) or the original name (true)
  * @return boolean True if the importing was successful
  * @since 3.5.0
  * @access public
  * @see EfrontLesson :: initialize()
  */
 public function import($file, $deleteEntities = false, $lessonProperties = false, $keepName = false, $exclude_search = false)
 {
     if ($deleteEntities) {
         $this->initialize($deleteEntities);
         //Initialize the lesson aspects that the user specified
     }
     if (!$file instanceof EfrontFile) {
         $file = new EfrontFile($file);
     }
     $fileList = $file->uncompress();
     $file->delete();
     $fileList = array_unique(array_reverse($fileList, true));
     $dataFile = new EfrontFile($file['directory'] . '/data.dat');
     $filedata = file_get_contents($dataFile['path']);
     $dataFile->delete();
     $data = unserialize($filedata);
     $data['content'] = self::eF_import_fixTree($data['content'], $last_current_node);
     for ($i = 0; $i < sizeof($data['files']); $i++) {
         if (isset($data['files'][$i]['file'])) {
             $newName = str_replace(G_ROOTPATH, '', dirname($data['files'][$i]['file']) . '/' . EfrontFile::encode(eFront_basename($data['files'][$i]['file'])));
             $newName = preg_replace("#(.*)www/content/lessons/#", "www/content/lessons/", $newName);
             $newName = preg_replace("#www/content/lessons/\\d+/(.*)#", "www/content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']) . "/\$1", $newName);
             if ($data['files'][$i]['original_name'] != eFront_basename($data['files'][$i]['file'])) {
                 if (is_file(G_ROOTPATH . $newName)) {
                     $replaceString['/\\/?(view_file.php\\?file=)' . $data['files'][$i]['id'] . '([^0-9])/'] = '${1}' . array_search(G_ROOTPATH . $newName, $fileList) . '${2}';
                     //Replace old ids with new ids
                     //$mp[$data['files'][$i]['id']] = array_search(G_ROOTPATH.$newName, $fileList);
                     $file = new EfrontFile(G_ROOTPATH . $newName);
                     $file->rename(G_ROOTPATH . dirname($newName) . '/' . EfrontFile::encode(rtrim($data['files'][$i]['original_name'], "/")));
                 }
             }
         } else {
             $newName = preg_replace("#www/content/lessons/\\d+/(.*)#", "www/content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']) . "/\$1", $data['files'][$i]['path']);
             if (is_file(G_ROOTPATH . $newName)) {
                 $replaceString['/\\/?(view_file.php\\?file=)' . $data['files'][$i]['id'] . '([^0-9])/'] = '${1}' . array_search(G_ROOTPATH . $newName, $fileList) . '${2}';
                 //Replace old ids with new ids
             }
         }
     }
     for ($i = 0; $i < sizeof($data['files']); $i++) {
         if (isset($data['files'][$i]['file'])) {
             $newName = str_replace(G_ROOTPATH, '', dirname($data['files'][$i]['file']) . '/' . EfrontFile::encode(eFront_basename($data['files'][$i]['file'])));
             $newName = preg_replace("#(.*)www/content/lessons/#", "www/content/lessons/", $newName);
             $newName = preg_replace("#www/content/lessons/\\d+/(.*)#", "www/content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']) . "/\$1", $newName);
             if ($data['files'][$i]['original_name'] != eFront_basename($data['files'][$i]['file'])) {
                 if (is_dir(G_ROOTPATH . $newName)) {
                     $file = new EfrontDirectory(G_ROOTPATH . $newName);
                     $file->rename(G_ROOTPATH . dirname($newName) . '/' . EfrontFile::encode(rtrim($data['files'][$i]['original_name'], "/")));
                 }
             }
         }
     }
     unset($data['files']);
     $last_current_node = 0;
     $existing_tree = eF_getContentTree($nouse, $this->lesson['id'], 0, false, false);
     if (sizeof($existing_tree) > 0) {
         $last_current_node = $existing_tree[sizeof($existing_tree) - 1]['id'];
         $first_node = self::eF_import_getTreeFirstChild($data['content']);
         $data['content'][$first_node]['previous_content_ID'] = $last_current_node;
     }
     // MODULES - Import 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 (isset($data[$module->className])) {
             $module->onImportLesson($this->lesson['id'], $data[$module->className]);
             unset($data[$module->className]);
         }
     }
     if (isset($data['glossary_words'])) {
         // to avoid excluding it with the lines below
         $data['glossary'] = $data['glossary_words'];
     }
     $dbtables = eF_showTables();
     //Skip tables that don't exist in current installation, such as modules' tables
     foreach (array_diff(array_keys($data), $dbtables) as $value) {
         unset($data[$value]);
     }
     //tests_to_questions table requires special handling
     //$testsToQuestions = $data['tests_to_questions'];
     //unset($data['tests_to_questions']);
     if (!$data['questions'] && $data['tests_to_questions']) {
         unset($data['tests_to_questions']);
     }
     foreach ($data as $table => $tabledata) {
         /*if ($table == "glossary_words") {
         			 $table = "glossary";
         
         			 } */
         // moved 20 lines above
         if ($table == "lessons") {
             //from v3 lessons parameters also imported
             if ($lessonProperties) {
                 unset($data['lessons']['id']);
                 unset($data['lessons']['directions_ID']);
                 unset($data['lessons']['created']);
                 $this->lesson = array_merge($this->lesson, $data['lessons']);
                 $this->persist();
             }
             eF_updateTableData("lessons", array('info' => $data['lessons']['info'], 'metadata' => $data['lessons']['metadata'], 'options' => $data['lessons']['options']), "id=" . $this->lesson['id']);
             if ($keepName) {
                 eF_updateTableData("lessons", array("name" => $data['lessons']['name']), "id=" . $this->lesson['id']);
                 $this->lesson['name'] = $data['lessons']['name'];
                 eF_updateTableData("f_forums", array("title" => $data['lessons']['name']), "lessons_ID=" . $this->lesson['id']);
             }
         } else {
             if ($table == "questions") {
                 foreach ($tabledata as $key => $value) {
                     unset($tabledata[$key]['timestamp']);
                     $tabledata[$key]['lessons_ID'] = $this->lesson['id'];
                     if ($tabledata[$key]['estimate'] == "") {
                         unset($tabledata[$key]['estimate']);
                     }
                     if (isset($tabledata[$key]['code'])) {
                         //code field removed in version 3.6
                         unset($tabledata[$key]['code']);
                     }
                 }
             }
             if ($table == "tests") {
                 for ($i = 0; $i < sizeof($tabledata); $i++) {
                     if (!isset($tabledata[$i]['options'])) {
                         $tabledata[$i]['options'] = serialize(array('duration' => $tabledata[$i]['duration'], 'redoable' => $tabledata[$i]['redoable'], 'onebyone' => $tabledata[$i]['onebyone'], 'answers' => $tabledata[$i]['answers'], 'given_answers' => $tabledata[$i]['given_answers'], 'shuffle_questions' => $tabledata[$i]['shuffle_questions'], 'shuffle_answers' => $tabledata[$i]['shuffle_answers']));
                         unset($tabledata[$i]['duration']);
                         unset($tabledata[$i]['redoable']);
                         unset($tabledata[$i]['onebyone']);
                         unset($tabledata[$i]['answers']);
                         unset($tabledata[$i]['given_answers']);
                         unset($tabledata[$i]['shuffle_questions']);
                         unset($tabledata[$i]['shuffle_answers']);
                     }
                 }
             }
             if ($table == 'calendar') {
                 $tabledata = array_values($tabledata);
                 // Because export returned assiciative array
                 for ($i = 0; $i < sizeof($tabledata); $i++) {
                     if (isset($tabledata[$i]['lessons_ID'])) {
                         if ($tabledata[$i]['lessons_ID']) {
                             $tabledata[$i]['foreign_ID'] = $tabledata[$i]['lessons_ID'];
                             $tabledata[$i]['type'] = 'lesson';
                         } else {
                             $tabledata[$i]['foreign_ID'] = 0;
                             $tabledata[$i]['type'] = '';
                         }
                         unset($tabledata[$i]['lessons_ID']);
                     }
                     unset($tabledata[$i]['name']);
                     unset($tabledata[$i]['lesson_name']);
                 }
             }
             for ($i = 0; $i < sizeof($tabledata); $i++) {
                 if ($table == "tests") {
                     if (!isset($tabledata[$i]['lessons_ID'])) {
                         $tabledata[$i]['lessons_ID'] = $this->lesson['id'];
                     }
                 }
                 if ($tabledata[$i]) {
                     $sql = "INSERT INTO " . G_DBPREFIX . $table . " SET ";
                     $connector = "";
                     $fields = array();
                     foreach ($tabledata[$i] as $key => $value) {
                         if ($key == "id") {
                             $old_id = $value;
                         } else {
                             if (($table == "content" and $key == "data") || ($table == "questions" and $key == "text") || ($table == "tests" and $key == "description")) {
                                 $value = str_replace("##SERVERNAME##", "", $value);
                                 //$value = str_replace("/##LESSONSLINK##", "content/lessons/".$this -> lesson['id'], $value);
                                 $value = str_replace("##LESSONSLINK##", "content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']), $value);
                                 $content_data = $value;
                             } elseif ($key == "lessons_ID") {
                                 $value = $this->lesson['id'];
                             } elseif ($table == "lesson_conditions" and $key == "options") {
                                 if (mb_strpos($data['lesson_conditions'][$i]['type'], "specific") === false) {
                                 } else {
                                     $options = unserialize($data['lesson_conditions'][$i]['options']);
                                     $options[0] = $map['content'][$options[0]];
                                     $value = serialize($options);
                                 }
                             } elseif ($table != "content" and mb_substr($key, -3) == "_ID") {
                                 $from_table = mb_substr($key, 0, -3);
                                 if (isset($map[$from_table][$value])) {
                                     $value = $map[$from_table][$value];
                                 }
                             }
                             if ($table == 'scorm_sequencing_content_to_organization' && $key == 'organization_content_ID') {
                                 $value = $map['content'][$value];
                             }
                             if ($table == 'scorm_sequencing_maps_info' && $key == 'organization_content_ID') {
                                 $value = $map['content'][$value];
                             }
                             if ($table == "content" and $key == 'previous_content_ID' and !$value) {
                                 $value = 0;
                             }
                             if (!($table == "content" and $key == "format")) {
                                 //$sql .= $connector.$key."='".str_replace("'","''",$value)."'";
                                 //$connector = ", ";
                                 $fields[$key] = $value;
                             }
                             if ($table == "content" and $key == "name") {
                                 $content_name = $value;
                             }
                         }
                     }
                     $new_id = eF_insertTableData($table, $fields);
                     if (!$exclude_search) {
                         if ($table == "content") {
                             EfrontSearch::insertText($content_name, $new_id, "content", "title");
                             EfrontSearch::insertText(strip_tags($content_data), $new_id, "content", "data");
                         }
                     }
                     $map[$table][$old_id] = $new_id;
                 }
             }
         }
     }
     if ($data['content']) {
         $map['content'] = array_reverse($map['content'], true);
         foreach ($map['content'] as $old_id => $new_id) {
             eF_updateTableData("content", array('parent_content_ID' => $new_id), "parent_content_ID={$old_id} AND lessons_ID=" . $this->lesson['id']);
             eF_updateTableData("content", array('previous_content_ID' => $new_id), "previous_content_ID={$old_id} AND lessons_ID=" . $this->lesson['id']);
             //eF_updateTableData("questions", array('content_ID' => $new_id), "content_ID=$old_id");
         }
     }
     if ($data['rules']) {
         foreach ($map['content'] as $old_id => $new_id) {
             eF_updateTableData("rules", array('rule_content_ID' => $new_id), "rule_content_ID={$old_id}");
         }
     }
     // Update lesson skill
     $lessonSkillId = $this->getLessonSkill();
     // The lesson offers skill record remains the same
     if ($lessonSkillId) {
         eF_updateTableData("module_hcd_skills", array("description" => _KNOWLEDGEOFLESSON . " " . $this->lesson['name'], "categories_ID" => -1), "skill_ID = " . $lessonSkillId['skill_ID']);
     }
     if ($data['questions']) {
         foreach ($map['questions'] as $old_id => $new_id) {
             eF_updateTableData("tests_to_questions", array('previous_question_ID' => $new_id), "previous_question_ID={$old_id} and tests_ID in (select id from tests where lessons_ID=" . $this->lesson['id'] . ")");
             // Update all questions of not course_only lessons to offer the lessons skill
             if ($lessonSkillId) {
                 eF_insertTableData("questions_to_skills", array("questions_id" => $new_id, "skills_ID" => $lessonSkillId['skill_ID'], "relevance" => 2));
             }
             //eF_insertTableData("questions_to_skills", array("q
             //$questions = eF_getTableDataFlat("questions", "id", "lessons_ID = ". $this ->lesson['id']);
             //eF_deleteTableData("questions_to_skills", "questions_id IN ('".implode("','",$questions['id'])."')");
         }
     }
     foreach ($map['content'] as $old_id => $new_id) {
         //needs debugging
         $content_new_IDs[] = $new_id;
     }
     $content_new_IDs_list = implode(",", $content_new_IDs);
     if ($content_new_IDs_list) {
         $content_data = eF_getTableData("content", "data,id", "id IN ({$content_new_IDs_list}) AND lessons_ID=" . $this->lesson['id']);
     }
     if (isset($replaceString)) {
         for ($i = 0; $i < sizeof($content_data); $i++) {
             $replaced = preg_replace(array_keys($replaceString), array_values($replaceString), $content_data[$i]['data']);
             eF_updateTableData("content", array('data' => $replaced), "id=" . $content_data[$i]['id']);
             if (!$exclude_search) {
                 EfrontSearch::removeText('content', $content_data[$i]['id'], 'data');
                 //Refresh the search keywords
                 EfrontSearch::insertText($replaced, $content_data[$i]['id'], "content", "data");
             }
         }
     }
     if ($content_new_IDs_list) {
         $content_data = eF_getTableData("content", "data,id", "id IN ({$content_new_IDs_list}) AND lessons_ID=" . $this->lesson['id'] . " AND data like '%##EFRONTINNERLINK##%'");
     }
     for ($i = 0; $i < sizeof($content_data); $i++) {
         preg_match_all("/##EFRONTINNERLINK##.php\\?ctg=content&amp;view_unit=(\\d+)/", $content_data[$i]['data'], $regs);
         foreach ($regs[1] as $value) {
             $replaced = str_replace("##EFRONTINNERLINK##.php?ctg=content&amp;view_unit=" . $value, "##EFRONTINNERLINK##.php?ctg=content&amp;view_unit=" . $map["content"][$value], $content_data[$i]['data']);
             eF_updateTableData("content", array('data' => $replaced), "id=" . $content_data[$i]['id']);
             if (!$exclude_search) {
                 EfrontSearch::removeText('content', $content_data[$i]['id'], 'data');
                 //Refresh the search keywords
                 EfrontSearch::insertText($replaced, $content_data[$i]['id'], "content", "data");
             }
         }
     }
     $tests = eF_getTableData("tests t, content c", "t.id, t.name, c.name as c_name", "t.content_ID=c.id");
     foreach ($tests as $test) {
         if (!$test['name']) {
             eF_updateTableData("tests", array("name" => $test['c_name']), "id=" . $test['id']);
         }
     }
     EfrontCache::getInstance()->clearCache();
     return true;
 }
Ejemplo n.º 2
0
                } elseif ($values['prompt_download']) {
                    $fields['data'] = '<iframe style="visibility:hidden;display:none" src="view_file.php?file=' . $file['id'] . '&action=download"></iframe>';
                    $unit = $currentContent->insertNode($fields);
                } elseif ($pathParts['extension'] == 'txt') {
                    $fields['data'] = '<a href = "view_file.php?file=' . $file['id'] . '&action=download"><img src="images/file_types/txt.png" style="vertical-align:middle" />' . eFront_basename($file['name']) . '</a>';
                    $unit = $currentContent->insertNode($fields);
                } elseif ($pathParts['extension'] == 'doc' || $pathParts['extension'] == 'rtf' || $pathParts['extension'] == 'docx' || $pathParts['extension'] == 'xls' || $pathParts['extension'] == 'xlsx' || $pathParts['extension'] == 'ppt' || $pathParts['extension'] == 'pptx' || $pathParts['extension'] == 'zip' || $pathParts['extension'] == 'rar') {
                    $fields['data'] = '<a href = "view_file.php?file=' . $file['id'] . '&action=download"><img src="images/file_types/' . $pathParts['extension'] . '.png" style="vertical-align:middle" />' . eFront_basename($file['name']) . '</a>';
                    $unit = $currentContent->insertNode($fields);
                } elseif ($pathParts['extension'] == 'js') {
                    //do not create unit for js files
                } else {
                    if (file_exists(G_THEMESPATH . 'default/images/file_types/' . $pathParts['extension'] . '.png')) {
                        $fields['data'] = '<a href = "view_file.php?file=' . $file['id'] . '&action=download"><img src="images/file_types/' . $pathParts['extension'] . '.png" style="vertical-align:middle" />' . eFront_basename($file['name']) . '</a>';
                    } else {
                        $fields['data'] = '<a href = "view_file.php?file=' . $file['id'] . '&action=download">' . eFront_basename($file['name']) . '</a>';
                    }
                    $unit = $currentContent->insertNode($fields);
                }
            }
        }
        $message = _FILESIMPORTEDSUCCESSFULLY;
        $message_type = 'success';
    } catch (Exception $e) {
        handleNormalFlowExceptions($e);
    }
}
$form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
$form->setRequiredNote(_REQUIREDNOTE);
$renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$renderer->setRequiredTemplate('{$html}{if $required}
Ejemplo n.º 3
0
 /**
  *
  * @param $file
  * @return unknown_type
  */
 public static function parseFile($file)
 {
     if ($file instanceof EfrontFile) {
         $file = $file['path'];
     }
     $xml = new SimpleXMLIterator(file_get_contents($file));
     //Remove comment nodes
     foreach (new RecursiveIteratorIterator($xml, RecursiveIteratorIterator::SELF_FIRST) as $key => $value) {
         unset($value->comment);
     }
     $fields = array('name' => (string) $xml->name ? (string) $xml->name : eFront_basename($file), 'title' => (string) $xml->title, 'version' => (string) $xml->version, 'author' => (string) $xml->author, 'path' => str_replace(G_THEMESPATH, "", str_replace("\\", "/", dirname($file)) . '/'), 'description' => (string) $xml->description, 'options' => (array) $xml->options, 'layout' => array('positions' => (array) $xml->layout->positions));
     return $fields;
 }
Ejemplo n.º 4
0
             if (!in_array($value, $imsFiles)) {
                 //This way we bypass duplicates
                 try {
                     $imsFiles[$value] = $filesystem->uploadFile("ims_file", $currentLesson->getDirectory(), $key);
                 } catch (EfrontFileException $e) {
                     if ($e->getCode() != UPLOAD_ERR_NO_FILE) {
                         throw $e;
                     }
                 }
             }
         }
     }
     //pr($imsFiles);exit;
     foreach ($imsFiles as $imsFile) {
         /* Imports ims package to database */
         $imsFolderName = EfrontFile::encode(eFront_basename($imsFile['name'], '.zip'));
         $imsPath = $currentLesson->getDirectory() . $imsFolderName . '/';
         is_dir($imsPath) or mkdir($imsPath, 0755);
         //pr($imsPath.$imsFile['name']);
         //try {
         $imsFile->rename($imsPath . $imsFile['name'], true);
         //} catch (Exception $e) {pr($e);throw $e;}
         $fileList = $imsFile->uncompress(false);
         $imsFile->delete();
         $total_fields = array();
         $resources = array();
         $manifestFile = new EfrontFile($imsPath . 'imsmanifest.xml');
         EfrontIMS::import($currentLesson, $manifestFile, $imsFolderName, array('embed_type' => $values['embed_type'], 'popup_parameters' => $values['popup_parameters']));
     }
     eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=ims&message=" . urlencode(_SUCCESSFULLYIMPORTEDIMSFILE) . "&message_type=success");
 } catch (Exception $e) {
 if ($currentCourse->options['certificate_tpl_id_rtf'] > 0) {
     try {
         $certificateFile = new EfrontFile($currentCourse->options['certificate_tpl_id_rtf']);
     } catch (Exception $e) {
         //$certificateFile = new EfrontFile(G_CERTIFICATETEMPLATEPATH."certificate1.rtf");
         $currentCourse->options['certificate_tpl_id_rtf'] = '';
         $currentCourse->persist();
         $message = _CERTIFICATEFILEWASCORRUPTORMISSINGANDWASRESET;
         $certificateFile = new EfrontFile(G_CERTIFICATETEMPLATEPATH . "certificate1.rtf");
     }
     $dname = $certificateFile->offsetGet('name');
 }
 try {
     $certificateFileSystemTree = new FileSystemTree(G_CERTIFICATETEMPLATEPATH);
     foreach (new EfrontFileTypeFilterIterator(new EfrontFileOnlyFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($certificateFileSystemTree->tree, RecursiveIteratorIterator::SELF_FIRST))), array('rtf')) as $key => $value) {
         $existingCertificates[eFront_basename($key)] = eFront_basename($key);
     }
 } catch (Exception $e) {
     handleNormalFlowExceptions($e);
 }
 $form = new HTML_QuickForm("edit_course_certificate_form", "post", basename($_SERVER['PHP_SELF']) . '?' . $baseUrl . '&op=format_certificate_docx', "", null, true);
 $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
 //Register this rule for checking user input with our function, eF_checkParameter
 $form->addElement('file', 'file_upload', _CERTIFICATETEMPLATE, 'class = "inputText"');
 $form->addElement('select', 'existing_certificate', _ORSELECTONEFROMLIST, $existingCertificates, "id = 'select_certificate'");
 if (G_VERSIONTYPE != 'standard') {
     #cpp#ifndef STANDARD
     $form->addElement('select', 'months', _MONTHS, range(0, 60), 'onChange="displayReset()"');
     $form->addElement('select', 'days', _DAYSCAPITAL, range(0, 30), 'onChange="displayReset()"');
     $form->addElement('advcheckbox', 'reset', _RESETCOURSEWHENEXPIRE, null, 'class = "inputCheckbox"', array(0, 1));
     $form->addElement('select', 'months_reset', _MONTHS, range(0, 60));
Ejemplo n.º 6
0
<?php

try {
    //$systemAvatars = array('' => '', 'none' => _USENONE);
    $systemAvatars = array('' => '');
    // Added because of #4444
    $avatarsFileSystemTree = new FileSystemTree(G_SYSTEMAVATARSPATH);
    foreach (new EfrontFileTypeFilterIterator(new EfrontFileOnlyFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($avatarsFileSystemTree->tree, RecursiveIteratorIterator::SELF_FIRST))), array('png')) as $key => $value) {
        $systemAvatars[eFront_basename($key)] = eFront_basename($key);
    }
    $smarty->assign("T_SYSTEM_AVATARS", $systemAvatars);
} catch (Exception $e) {
    handleNormalFlowExceptions($e);
}
if (!isset($_GET['add_user'])) {
    try {
        $avatar = new EfrontFile($editedUser->user['avatar']);
    } catch (Exception $e) {
        $avatar = new EfrontFile(G_SYSTEMAVATARSPATH . "unknown_small.png");
    }
} else {
    $avatar = new EfrontFile(G_SYSTEMAVATARSPATH . "unknown_small.png");
}
$roles = EfrontUser::getRoles(true);
if ($currentUser->user['user_type'] != 'administrator' || $currentUser->user['user_types_ID']) {
    $rolesPlain = EfrontUser::getRoles();
    foreach ($roles as $key => $value) {
        if ($rolesPlain[$key] == 'administrator' && $key != $editedUser->user['user_types_ID']) {
            unset($roles[$key]);
        }
    }
 /**
  * Import files to filesystem
  *
  * This function imports the specified files (in $list array) to the filesystem,
  * by creating a corresponding database representation. The $list
  * array should contain full paths to the files. The function returns an array
  * of the same size and contents as $list , but this time the file ids being the keys
  * <br/>Example:
  * <code>
  * $list = array('/var/www/text.txt', '/var/www/user.txt');
  * $newList = FileSystemTree :: importFiles($list);
  * </code>
  *
  * @param array $list The files list
  * @param array $options extra options to set for the files, such as whether they should be renamed, or the proper permissions
  * @return array An array with the new file ids
  * @access public
  * @since 3.0
  * @static
  */
 public static function importFiles($list, $options = array())
 {
     if (!is_array($list)) {
         $list = array($list);
     }
     $allFiles = eF_getTableDataFlat("files", "path");
     //Get all files, so that if a file already exists, a duplicate entry in the database won't be created
     for ($i = 0; $i < sizeof($list); $i++) {
         $list[$i] = EfrontFile::encode($list[$i]);
         if (!in_array($list[$i], $allFiles['path']) && strpos(dirname($list[$i]), rtrim(G_ROOTPATH, "/")) !== false) {
             $fileMetadata = array('title' => eFront_basename($list[$i]), 'creator' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'publisher' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'contributor' => $GLOBALS['currentUser']->user['name'] . ' ' . $GLOBALS['currentUser']->user['surname'], 'date' => date("Y/m/d", time()), 'type' => 'file');
             $fields = array('path' => str_replace(G_ROOTPATH, '', $list[$i]), 'users_LOGIN' => isset($_SESSION['s_login']) ? $_SESSION['s_login'] : '', 'timestamp' => time(), 'metadata' => serialize($fileMetadata));
             isset($options['access']) ? $fields['access'] = $options['access'] : null;
             $fileId = eF_insertTableData("files", $fields);
             if ($fileId) {
                 $newList[$fileId] = $list[$i];
                 /*
                 foreach ($fileMetadata as $key => $value) {
                     EfrontSearch :: insertText($value, $fileId, "files", "data");
                 }
                 */
                 $terms = '';
                 foreach ($fileMetadata as $key => $value) {
                     $terms .= $value . ' ';
                 }
                 EfrontSearch::insertText($terms, $fileId, "files", "data");
             }
         }
     }
     return $newList;
 }
Ejemplo n.º 8
0
 /**
  * Copy simple unit
  *
  * This function copies a unit (NOT its children) into the current content tree
  * <br/>Example:
  * <code>
  * $currentContent = new EfrontContentTree(5);           //Initialize content for lesson with id 5
  * $sourceUnit = new EfrontUnit(20);                     //Get the unit with id = 20
  * $currentContent -> copySimpleUnit($sourceUnit, false);   //Copy the source unit into the content tree (at its end)
  * </code>
  *
  * @param EfrontUnit $sourceUnit The unit object to be copied
  * @param mixed $targetUnit The id of the parent unit (or the parent EfrontUnit)in which the new unit will be copied, or false (the unit will be appended at the end)
  * @param mixed $previousUnit The id of the previous unit (or the unit itself) of the new unit, or false (the unit will be put to the end of the units)
  * @param boolean $copyFiles whether to copy files as well.
  * @param boolean $copyQuestions Whether to copy questions as well
  * @return EfrontUnit The newly created unit object
  * @since 3.5.0
  * @access public
  */
 public function copySimpleUnit($sourceUnit, $targetUnit = false, $previousUnit = false, $copyFiles = true, $copyQuestions = true)
 {
     if (!$sourceUnit instanceof EfrontUnit) {
         $sourceUnit = new EfrontUnit($sourceUnit);
     }
     $newUnit['name'] = $sourceUnit->offsetGet('name');
     $newUnit['ctg_type'] = $sourceUnit->offsetGet('ctg_type');
     $newUnit['data'] = $sourceUnit->offsetGet('data');
     $options = $sourceUnit->offsetGet('options');
     $newOptions['complete_unit_setting'] = $options['complete_unit_setting'];
     $newOptions['hide_navigation'] = $options['hide_navigation'];
     $newOptions['maximize_viewport'] = $options['maximize_viewport'];
     $newOptions['object_ids'] = $options['object_ids'];
     $newOptions['complete_question'] = $options['complete_question'];
     $newOptions['complete_time'] = $options['complete_time'];
     $newUnit['options'] = serialize($newOptions);
     $newUnit['lessons_ID'] = $this->lessonId;
     if ($targetUnit) {
         if ($targetUnit instanceof EfrontUnit) {
             $newUnit['parent_content_ID'] = $targetUnit->offsetGet('id');
         } else {
             if (eF_checkParameter($targetUnit, 'id')) {
                 $newUnit['parent_content_ID'] = $targetUnit;
             }
         }
         if ($previousUnit instanceof EfrontUnit) {
             $newUnit['previous_content_ID'] = $previousUnit->offsetGet('id');
         } else {
             if (eF_checkParameter($previousUnit, 'id')) {
                 $newUnit['previous_content_ID'] = $previousUnit;
             }
         }
         $unit = $this->insertNode($newUnit);
     } else {
         $unit = $this->appendUnit($newUnit);
     }
     if ($copyFiles) {
         $files = $unit->getFiles();
         $lesson = new EfrontLesson($this->lessonId);
         $data = $unit->offsetGet('data');
         foreach ($files as $file) {
             try {
                 $sourceFile = new EfrontFile($file);
                 $sourceFileOffset = preg_replace("#" . G_LESSONSPATH . "#", "", $sourceFile['directory']);
                 $position = strpos($sourceFileOffset, "/");
                 //check case that the file is in a subfolder of the lesson
                 if ($position !== false) {
                     $sourceLink = mb_substr($sourceFileOffset, $position + 1);
                     mkdir($lesson->getDirectory() . $sourceLink . '/', 0755, true);
                     $destinationPath = $lesson->getDirectory() . $sourceLink . '/' . eFront_basename($sourceFile['path']);
                     $copiedFile = $sourceFile->copy($destinationPath, false);
                 } else {
                     $destinationPath = $lesson->getDirectory() . eFront_basename($sourceFile['path']);
                     $copiedFile = $sourceFile->copy($destinationPath, false);
                 }
                 //@todo view_file.php?action=download&file=10410
                 //$data = str_replace("view_file.php?file=".$file, "view_file.php?file=".$copiedFile -> offsetGet('id'), $data);
                 //$data = str_replace("&file=".$file, "&file=".$copiedFile -> offsetGet('id'), $data);
                 //$data = str_replace("&amp;file=".$file, "&amp;file=".$copiedFile -> offsetGet('id'), $data);
                 $data = preg_replace('#view_file\\.php(.*)file=' . $file . '#', 'view_file.php${1}file=' . $copiedFile->offsetGet('id'), $data);
                 $folderId = $lesson->lesson['share_folder'] ? $lesson->lesson['share_folder'] : $lesson->lesson['id'];
                 $data = preg_replace("#(" . G_SERVERNAME . ")*content/lessons/" . $sourceUnit['lessons_ID'] . "/(.*)#", "content/lessons/" . $folderId . '/${2}', $data);
             } catch (EfrontFileException $e) {
                 if ($e->getCode() == EfrontFileException::FILE_ALREADY_EXISTS) {
                     $copiedFile = new EfrontFile($destinationPath);
                     //$data = str_replace("view_file.php?file=".$file, "view_file.php?file=".$copiedFile -> offsetGet('id'), $data);
                     //$data = str_replace("&file=".$file, "&file=".$copiedFile -> offsetGet('id'), $data);
                     //$data = str_replace("&amp;file=".$file, "&amp;file=".$copiedFile -> offsetGet('id'), $data);
                     $data = preg_replace('#view_file\\.php(.*)file=' . $file . '#', 'view_file.php${1}file=' . $copiedFile->offsetGet('id'), $data);
                     $folderId = $lesson->lesson['share_folder'] ? $lesson->lesson['share_folder'] : $lesson->lesson['id'];
                     $data = preg_replace("#(" . G_SERVERNAME . ")*content/lessons/" . $sourceUnit['lessons_ID'] . "/(.*)#", "content/lessons/" . $folderId . '/${2}', $data, -1, $count);
                 }
             }
             //this means that the file already exists
         }
         $unit->offsetSet('data', $data);
         if ($file && $unit['ctg_type'] == 'scorm' || $unit['ctg_type'] == 'scorm_test') {
             $d = new EfrontDirectory(dirname($file));
             $d->copy($lesson->getDirectory() . eFront_basename(dirname($file)), true);
         }
     }
     $unit->persist();
     // copying questions that belong to this unit
     if ($copyQuestions) {
         $questions = eF_getTableData("questions", "*", "content_ID=" . $sourceUnit->offsetGet('id'));
         if ($copyFiles) {
             $folderId = $lesson->lesson['share_folder'] ? $lesson->lesson['share_folder'] : $lesson->lesson['id'];
         }
         for ($k = 0; $k < sizeof($questions); $k++) {
             if ($copyFiles) {
                 $questions[$k]['text'] = replaceQuestionPaths($questions[$k]['text'], $questions[$k]['lessons_ID'], $folderId);
                 $questions[$k]['explanation'] = replaceQuestionPaths($questions[$k]['explanation'], $questions[$k]['lessons_ID'], $folderId);
             }
             $questions[$k]['content_ID'] = $unit->offsetGet('id');
             $questions[$k]['lessons_ID'] = $unit->offsetGet('lessons_ID');
             unset($questions[$k]['id']);
             eF_insertTableData("questions", $questions[$k]);
         }
     }
     return $unit;
 }
Ejemplo n.º 9
0
function replaceQuestionPaths($data, $sourceId, $newId)
{
    //$data = $question['text'];
    preg_match_all("/view_file\\.php\\?file=(\\d+)/", $data, $matchesId);
    $filesId = $matchesId[1];
    preg_match_all("#(" . G_SERVERNAME . ")*content/lessons/(.*)\"#U", $data, $matchesPath);
    $filesPath = $matchesPath[2];
    foreach ($filesId as $file) {
        $files[] = $file;
    }
    foreach ($filesPath as $file) {
        $files[] = G_LESSONSPATH . html_entity_decode($file);
    }
    $lesson = new EfrontLesson($newId);
    //$data   = $unit -> offsetGet('data');
    foreach ($files as $file) {
        try {
            $sourceFile = new EfrontFile($file);
            $sourceFileOffset = preg_replace("#" . G_LESSONSPATH . "#", "", $sourceFile['directory']);
            $position = strpos($sourceFileOffset, "/");
            //check case that the file is in a subfolder of the lesson
            if ($position !== false) {
                $sourceLink = mb_substr($sourceFileOffset, $position + 1);
                mkdir($lesson->getDirectory() . $sourceLink . '/', 0755, true);
                $destinationPath = $lesson->getDirectory() . $sourceLink . '/' . eFront_basename($sourceFile['path']);
                $copiedFile = $sourceFile->copy($lesson->getDirectory() . $sourceLink . '/' . eFront_basename($sourceFile['path']), false);
            } else {
                $destinationPath = $lesson->getDirectory() . eFront_basename($sourceFile['path']);
                $copiedFile = $sourceFile->copy($lesson->getDirectory() . eFront_basename($sourceFile['path']), false);
            }
            str_replace("view_file.php?file=" . $file, "view_file.php?file=" . $copiedFile->offsetGet('id'), $data);
            $data = preg_replace("#(" . G_SERVERNAME . ")*content/lessons/" . $sourceId . "/(.*)#", "content/lessons/" . $newId . '/${2}', $data);
        } catch (EfrontFileException $e) {
            if ($e->getCode() == EfrontFileException::FILE_ALREADY_EXISTS) {
                $copiedFile = new EfrontFile($destinationPath);
                str_replace("view_file.php?file=" . $file, "view_file.php?file=" . $copiedFile->offsetGet('id'), $data);
                $data = preg_replace("#(" . G_SERVERNAME . ")*content/lessons/" . $sourceId . "/(.*)#", "content/lessons/" . $newId . '/${2}', $data, -1, $count);
            }
        }
        //this means that the file already exists
    }
    //$question['text'] = $data;
    return $data;
}