<?php /** * Show avatars * * This file is the page which shows the avatars list * @package eFront * @version 1.0 */ session_cache_limiter('none'); session_start(); $path = "../libraries/"; /** Configuration file.*/ include_once $path . "configuration.php"; try { $currentUser = EfrontUser::checkUserAccess(); } catch (Exception $e) { echo "<script>parent.location = 'index.php?logout=true&message=" . urlencode($e->getMessage() . ' (' . $e->getCode() . ')') . "&message_type=failure'</script>"; //This way the frameset will revert back to single frame, and the annoying effect of 2 index.php, one in each frame, will not happen exit; } $current_dir = getcwd(); chdir(G_SYSTEMAVATARSPATH); $avatar_files = eF_getDirContents(false, 'png'); chdir($current_dir); $smarty->assign("T_SYSTEM_AVATARS", $avatar_files); if ($GLOBALS['configuration']['social_modules_activated'] > 0) { $smarty->assign("T_SOCIAL_INTERFACE", 1); } $smarty->display("show_avatars.tpl");
/** * Returns the contents of a directory * * This function accepts a directory name and returns an array where the elements are * the full paths to every file in it, recursively. If the second parameter is specified, * then only files of the specified type are returned. If no argument is specified, it searches * the current directory and returns every file in it. * <br/>Example: * <code> * $file_list = eF_getDirContents(); //return current directory contents * $file_list = eF_getDirContents('/tmp'); //return /tmp directory contents * $file_list = eF_getDirContents(false, 'php'); //return files with extension php in the current directory and subdirectories * $file_list = eF_getDirContents(false, array('php', 'html')); //return files with extension php or html in the current directory and subdirectories * </code> * * @param string $dir The directory to recurse into * @param mixed $ext Return only files with extension $ext, or in array $ext * @param bool $get_dir If false, do not append directory information to files * @param bool $recurse Whether to recurse into subdirectories * @return array An array with every file and directory inside the directory specified * @version 1.8 * Changes from version 1.7 to 1.8 (2007/08/10 - peris): * - Exclude .svn folder from return list * Changes from version 1.6 to 1.7 (2007/07/30 - peris): * - Now, it returns directory names along with file names * Changes from version 1.5 to 1.6 (2007/07/26 - peris): * - Added $recurse parameter * Changes from version 1.3 to 1.4 (2007/03/26 - peris): * - Added $get_dir parameter * Changes from version 1.2 to 1.3 (2007/03/25 - peris): * - Changed data type of $ext from string to mixed. Now, $ext can be an array of possible extensions. Also, minor bug fix, in $ext and directories handling * Changes from version 1.1 to 1.2 (2007/03/05 - peris): * - Fixed recursion bug (Added $ext parameter to recurse call) * Changes from version 1.0 to 1.1 (22/12/2005): * - Added $ext parameter */ function eF_getDirContents($dir = false, $ext = false, $get_dir = true, $recurse = true) { if ($dir) { $handle = opendir($dir); } else { $handle = opendir(getcwd()); } $filelist = array(); while (false !== ($file = readdir($handle))) { if ($file != "." and $file != ".." and $file != '.svn') { if (is_dir($dir . $file) && $recurse) { //echo "!$dir . $file@<br>"; $temp = eF_getDirContents($dir . $file . '/', $ext, $get_dir); $get_dir ? $filelist[] = $dir . $file . '/' : ($filelist[] = $file . '/'); if (!$ext) { //It is put here for empty directories (when $ext is not specified), or, if $ext is specified, to not return directories $filelist = array_merge($filelist, $temp); } } else { if ($ext) { if (is_array($ext)) { if (in_array(pathinfo($file, PATHINFO_EXTENSION), $ext)) { $get_dir ? $filelist[] = $dir . $file : ($filelist[] = $file); } } else { if (pathinfo($file, PATHINFO_EXTENSION) == $ext) { $get_dir ? $filelist[] = $dir . $file : ($filelist[] = $file); } } } else { $get_dir ? $filelist[] = $dir . $file : ($filelist[] = $file); } } } } return $filelist; }
public function fromIMS($ims_file, $deleteEntities = false) { if ($deleteEntities) { $this->initialize($deleteEntities); //Initialize the lesson aspects that the user specified } $timestamp = time(); $zip = new Archive_zip($ims_file); $extracted_files = $zip->extract(array('add_path' => G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp)); $total_fields = array(); $resources = array(); $tagArray = @eF_local_parseManifest(G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp); $questions = array(); $tests = array(); $content = array(); $inContent = false; $inTest = false; $inQuestion = false; $references = array(); $questionsKeys = array(); $testsKeys = array(); foreach ($tagArray as $key => $value) { $fields = array(); switch ($value['tag']) { case 'TITLE': $cur = $value['parent_index']; if ($inContent) { $content[$cur]['name'] = $value['value']; } if ($inTest) { $tests[$cur]['name'] = $value['value']; } break; case 'ITEM': $cur = $key; if ($value['attributes']['TYPE'] != 'question' && $value['attributes']['TYPE'] != 'test') { $inContent = true; $inTest = false; $inQuestion = false; $content[$key]['lessons_ID'] = $this->lesson['id']; $content[$key]['timestamp'] = time(); $content[$key]['ctg_type'] = 'theory'; $content[$key]['active'] = 1; $references[$key] = $value['attributes']['IDENTIFIERREF']; } else { if ($value['attributes']['TYPE'] == 'test') { $inTest = true; $inContent = false; $inQuestion = false; $tests[$key]['active'] = '1'; $testsKeys[$value['attributes']['IDENTIFIERREF']] = $key; $references[$key] = $value['attributes']['IDENTIFIERREF']; } else { if ($value['attributes']['TYPE'] == 'question') { $inQuestion = true; $inContent = false; $inTest = false; $questions[$key]['difficulty'] = 'medium'; //initial value $questions[$key]['type'] = 'true_false'; //initial value $questions[$key]['timestamp'] = time(); $questionsKeys[$value['attributes']['IDENTIFIERREF']] = $key; $references[$key] = $value['attributes']['IDENTIFIERREF']; } } } break; case 'RESOURCE': $resources[$key] = $value['attributes']['IDENTIFIER']; break; case 'FILE': $files[$key] = $value['attributes']['HREF']; break; case 'ADLCP:MAXTIMEALLOWED': $maxtimeallowed[$key] = $value['value']; break; case 'ADLCP:TIMELIMITACTION': $timelimitaction[$key] = $value['value']; break; case 'ADLCP:MASTERYSCORE': $masteryscore[$key] = $value['value']; break; case 'ADLCP:DATAFROMLMS': $datafromlms[$key] = $value['value']; break; case 'ADLCP:PREREQUISITES': $prerequisites[$key] = $value['value']; break; default: break; } } foreach ($references as $key => $value) { $ref = array_search($value, $resources); if ($ref !== false && !is_null($ref)) { $data = file_get_contents(G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp . "/" . $tagArray[$ref]['attributes']['HREF']); $primitive_hrefs[$ref] = $tagArray[$ref]['attributes']['HREF']; $path_part[$ref] = dirname($primitive_hrefs[$ref]); foreach ($tagArray[$ref]['children'] as $value2) { if ($tagArray[$value2]['tag'] == 'DEPENDENCY') { $idx = array_search($tagArray[$value2]['attributes']['IDENTIFIERREF'], $resources); foreach ($tagArray[$idx]['children'] as $value3) { if ($tagArray[$value3]['tag'] == 'FILE') { $data = preg_replace("#(\\.\\.\\/(\\w+\\/)*)?" . $tagArray[$value3]['attributes']['HREF'] . "#", G_LESSONSPATH . $this->lesson['id'] . "/" . $path_part[$ref] . "/\$1" . $tagArray[$value3]['attributes']['HREF'], $data); } } } } if ($content[$key]['active'] == 1) { $i1 = stripos($data, "<body"); $i2 = stripos($data, ">", $i1); $i3 = strripos($data, "<script"); $data = substr($data, $i2 + 1, $i3 - $i2 - 1); $content[$key]['data'] = $data; } else { if ($tests[$key]) { $data = $data; $tests[$key]['description'] = $data; } else { if ($questions[$key]) { $data = $data; $questions[$key]['text'] = $data; } } } } } $inStart = true; foreach ($content as $key => $value) { $cid = ef_insertTableData("content", $value); /* TODO INDEX */ if ($inStart) { $inStart = false; foreach ($questions as $keyq => $valueq) { $questions[$keyq]['content_ID'] = $cid; } } } foreach ($questions as $key => $value) { $qid = ef_insertTableData("questions", $value); $questions[$key]['id'] = $qid; } foreach ($tests as $key => $value) { $test_content['lessons_ID'] = $this->lesson['id']; $test_content['timestamp'] = time(); $test_content['ctg_type'] = 'tests'; $test_content['active'] = 1; $test_content['name'] = $value['name']; unset($value['name']); $cid = ef_insertTableData("content", $test_content); $value['content_id'] = $cid; $tid = ef_insertTableData("tests", $value); $tests[$key]['id'] = $tid; } eF_local_buildDirectories(G_LESSONSPATH . $this->lesson['id'] . "/", G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp); foreach ($files as $key => $value) { // if (!in_array($value, $primitive_hrefs)) // { $newhref = $tagArray[$tagArray[$key]['parent_index']]['attributes']['XML:BASE']; //copy(G_LESSONSPATH.$this->lesson['id']."/IMS_".$timestamp."/".trim($newhref,"/")."/".trim($value,"/"), G_LESSONSPATH.$this->lesson['id']."/".trim($newhref,"/")."/".trim($value,"/")); // } } $cur_dir = getcwd(); chdir(G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp); $filelist = eF_getDirContents(); foreach ($filelist as $value) { copy($value, G_LESSONSPATH . $this->lesson['id'] . "/" . $value); } chdir($cur_dir); foreach ($prerequisites as $key => $value) { foreach ($tagArray as $key2 => $value2) { if (isset($value2['attributes']['IDENTIFIER']) && $value2['attributes']['IDENTIFIER'] == $value) { unset($fields_insert); $fields_insert['users_LOGIN'] = "******"; $fields_insert['content_ID'] = $tagArray[$tagArray[$key]['parent_index']]['this_id']; $fields_insert['rule_type'] = "hasnot_seen"; $fields_insert['rule_content_ID'] = $value2['this_id']; $fields_insert['rule_option'] = 0; //eF_insertTableData("rules", $fields_insert); } } } //read the special EfrontLesson.xml $xmlfile = G_LESSONSPATH . $this->lesson['id'] . "/IMS_" . $timestamp . "/EfrontLesson.xml"; $xml = simplexml_load_file($xmlfile); for ($i = 0; $i < sizeof($xml->conditions->condition); $i++) { $condition = array(); $condition['type'] = (string) $xml->conditions->condition[$i]->type; $condition['options'] = (string) $xml->conditions->condition[$i]->options; $condition['relation'] = (string) $xml->conditions->condition[$i]->relation; $condition['lessons_ID'] = $this->lesson['id']; $cid = ef_insertTableData("lesson_conditions", $condition); } for ($i = 0; $i < sizeof($xml->glossary->word); $i++) { $glossary = array(); $glossary['name'] = (string) $xml->glossary->word[$i]->name; $glossary['type'] = (string) $xml->glossary->word[$i]->type; $glossary['info'] = (string) $xml->glossary->word[$i]->info; $glossary['active'] = (string) $xml->glossary->word[$i]->active; $glossary['lessons_ID'] = $this->lesson['id']; $cid = ef_insertTableData("glossary", $glossary); } for ($i = 0; $i < sizeof($xml->questions->question); $i++) { $update = array(); $refid = (string) $xml->questions->question[$i]->refid; $qk = $questionsKeys[$refid]; $qid = $questions[$qk]['id']; $update['type'] = (string) $xml->questions->question[$i]->type; $update['difficulty'] = (string) $xml->questions->question[$i]->difficulty; $update['options'] = (string) $xml->questions->question[$i]->options; $update['answer'] = (string) $xml->questions->question[$i]->answer; $update['explanation'] = (string) $xml->questions->question[$i]->explanation; ef_updateTableData("questions", $update, "id = {$qid}"); } for ($i = 0; $i < sizeof($xml->tests->test); $i++) { $update = array(); $refid = (string) $xml->tests->test[$i]->refid; $tk = $testsKeys[$refid]; $tid = $tests[$tk]['id']; $update['duration'] = (string) $xml->tests->test[$i]->duration; $update['redoable'] = (string) $xml->tests->test[$i]->redoable; $update['onebyone'] = (string) $xml->tests->test[$i]->onebyone; $update['answers'] = (string) $xml->tests->test[$i]->answers; $update['shuffle_questions'] = (string) $xml->tests->test[$i]->shuffle_questions; $update['shuffle_answers'] = (string) $xml->tests->test[$i]->shuffle_answers; $update['given_answers'] = (string) $xml->tests->test[$i]->given_answers; ef_updateTableData("tests", $update, "id=" . $tid); for ($j = 0; $j < sizeof($xml->tests->test[$i]->questions->question); $j++) { $testQuestions = array(); $refid = (string) $xml->tests->test[$i]->questions->question[$j]->refid; $qk = $questionsKeys[$refid]; $qid = $questions[$qk]['id']; $previd = (string) $xml->tests->test[$i]->questions->question[$j]->previous; if ($previd != "q0") { $pk = $questionsKeys[$previd]; $pid = $questions[$pk]['id']; } else { $pid = 0; } $testQuestions['tests_ID'] = $tid; $testQuestions['questions_ID'] = $qid; $testQuestions['previous_question_ID'] = $pid; $testQuestions['weight'] = (string) $xml->tests->test[$i]->questions->question[$j]->weight; ef_insertTableData("tests_to_questions", $testQuestions); } } }
/** * Recursively delete directory contents * * This function deletes all the contents of the designated folder, including subfolders, and the folder itself * <br/>Example: * <code> * eF_deleteFolder('/tmp/useless_dir/'); * </code> * * @param string $folder The full pathname of the directory to be deleted * @return bool true if everythin is ok. * @see eF_getDirContents * @todo return other than true */ function eF_deleteFolder($folder) { $folder = $folder . '/'; $filelist = eF_getDirContents($folder); for ($i = 0; $i < sizeof($filelist); $i++) { unlink($filelist[$i]); } $folders[] = $folder; for ($k = 0; $k < sizeof($folders); $k++) { $handle = opendir($folders[$k]); while (false !== ($file = readdir($handle))) { if ($file != "." and $file != "..") { $folders[] = $folders[$k] . '/' . $file; } } closedir($handle); } for ($k = sizeof($folders) - 1; $k >= 0; $k--) { rmdir($folders[$k]); } if (is_dir($folder)) { return false; } else { return true; } }