/**
  * (non-PHPdoc)
  * @see libraries/EfrontEntity#handleForm($form)
  */
 public function handleForm($form)
 {
     $values = $form->exportValues();
     if (!eF_checkParameter($values['name'], 'filename')) {
         throw new EfrontFileException(_ILLEGALFILENAME . ': ' . $values['name'], EfrontFileException::ILLEGAL_FILE_NAME);
     }
     $fields = array("name" => $values['name']);
     if (isset($_GET['add'])) {
         self::create($fields);
     } else {
         $directory = new EfrontDirectory(G_UPLOADPATH . $this->{$this->entity}['users_LOGIN'] . '/message_attachments/' . $this->{$this->entity}['name']);
         $directory->rename(G_UPLOADPATH . $this->{$this->entity}['users_LOGIN'] . '/message_attachments/' . $values['name']);
         $this->{$this->entity}['name'] = $values['name'];
         $this->persist();
     }
 }
Example #2
0
 /**
  * Restore system
  *
  * This function is used to restore a backup previously taken
  * <br/>Example:
  * <code>
  * </code>
  *
  * @param EfrontFile $restoreFile The file restore from
  * @param boolean $force Force restore even if versions are incompatible
  * @since 3.5.2
  * @access public
  */
 public static function restore($restoreFile, $force = false)
 {
     if (!$restoreFile instanceof EfrontFile) {
         $restoreFile = new EfrontFile($restoreFile);
     }
     $tempDir = G_BACKUPPATH . 'temp/';
     if (is_dir($tempDir)) {
         $dir = new EfrontDirectory($tempDir);
         $dir->delete();
     }
     mkdir($tempDir, 0755);
     $restoreFile = $restoreFile->copy($tempDir . '/');
     $restoreFile->uncompress(false);
     $filesystem = new FileSystemTree($tempDir);
     $iterator = new EfrontFileOnlyFilterIterator(new RecursiveIteratorIterator($filesystem->tree, RecursiveIteratorIterator::SELF_FIRST));
     foreach ($iterator as $key => $value) {
         if (strpos($key, 'version.txt') !== false) {
             $backupVersion = file_get_contents($key);
         }
     }
     if (version_compare($backupVersion, G_VERSION_NUM) != 0 && !$force) {
         throw new Exception(_INCOMPATIBLEVERSIONS . '<br/> ' . _BACKUPVERSION . ':' . $backupVersion . ' / ' . _CURRENTVERSION . ': ' . G_VERSION_NUM, EfrontSystemException::INCOMPATIBLE_VERSIONS);
     }
     $sql = file_get_contents($tempDir . 'db_backup/sql.txt');
     $sql = explode(";\n", $sql);
     $node = $filesystem->seekNode($tempDir . 'db_backup');
     for ($i = 0; $i < sizeof($sql); $i += 2) {
         preg_match("/drop table (.+)/", $sql[$i], $matches);
         if ($matches[1]) {
             $temp[$matches[1]] = array($sql[$i], $sql[$i + 1]);
         }
     }
     $sql = $temp;
     //For each one of the tables that have backup data, recreate its table and import data
     $iterator = new EfrontFileOnlyFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($node), RecursiveIteratorIterator::SELF_FIRST));
     $GLOBALS['db']->Execute("SET FOREIGN_KEY_CHECKS=0");
     foreach ($iterator as $file => $value) {
         $tableName = preg_replace("/\\.\\d+/", "", basename($file));
         if (isset($sql[$tableName])) {
             try {
                 eF_executeNew($sql[$tableName][0]);
             } catch (Exception $e) {
                 /*Don't halt for missing tables that can't be deleted*/
             }
             eF_executeNew($sql[$tableName][1]);
             unset($sql[$tableName]);
         }
         if (strpos($file, 'sql.txt') === false && strpos($file, 'version.txt') === false) {
             $data = unserialize(file_get_contents($file));
             $tableExists = false;
             try {
                 $tableExists = eF_describeTable($tableName);
             } catch (Exception $e) {
             }
             if ($tableExists !== false && !preg_match("/^\\w+_view\$/", $tableName)) {
                 eF_insertTableDataMultiple($tableName, $data);
             }
         }
     }
     $GLOBALS['db']->Execute("SET FOREIGN_KEY_CHECKS=1");
     //Turn off foreign key checks in order to be able to run "drop table" queries
     eF_executeNew("SET FOREIGN_KEY_CHECKS = 0;");
     //For each one of the tables that don't have backup data, simply recreate
     foreach ($sql as $tableName => $query) {
         try {
             eF_executeNew($query[0]);
         } catch (Exception $e) {
             /*Don't halt for missing tables that can't be deleted*/
         }
         eF_executeNew($query[1]);
     }
     eF_executeNew("SET FOREIGN_KEY_CHECKS = 1;");
     if (is_dir(G_BACKUPPATH . 'temp/upload')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/upload');
         $dir->copy(G_ROOTPATH . 'upload', true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/lessons')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/lessons');
         $dir->copy(G_CONTENTPATH . 'lessons', true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/efront_root')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/efront_root');
         $dir->copy(G_ROOTPATH, true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/certificate_templates')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/certificate_templates');
         $dir->copy(G_ROOTPATH . 'www/certificate_templates', true);
     }
     if (is_dir(G_BACKUPPATH . 'temp/editor_templates')) {
         $dir = new EfrontDirectory(G_BACKUPPATH . 'temp/editor_templates');
         $dir->copy(G_ROOTPATH . 'www/content/editor_templates', true);
     }
     $dir = new EfrontDirectory($tempDir);
     $dir->delete();
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache('user');
     }
     return true;
 }
Example #3
0
 } elseif ($_GET['mode'] == 'external') {
     $rootDir = new EfrontDirectory(G_EXTERNALPATH);
     $filesBaseUrl = G_EXTERNALURL;
 } elseif ($_GET['mode'] == 'upload') {
     $rootDir = new EfrontDirectory(G_UPLOADPATH . $_SESSION['s_login']);
     $filesBaseUrl = G_UPLOADPATH . $_SESSION['s_login'];
 } else {
     throw new Exception(_ILLEGALMODE);
 }
 //We are inside a directory. Verify that this directory is below the $rootDir, as defined previously
 if (isset($_GET['directory'])) {
     $directory = new EfrontDirectory($_GET['directory']);
     if (strpos($directory['path'], $rootDir['path']) === false) {
         $directory = $rootDir;
     } else {
         if (EfrontDirectory::normalize($directory['path']) == EfrontDirectory::normalize($rootDir['path'])) {
             $smarty->assign("T_PARENT_DIR", '');
         } else {
             $smarty->assign("T_PARENT_DIR", $directory['directory']);
         }
     }
 } else {
     $directory = $rootDir;
 }
 $offset = str_replace($rootDir['path'], '', $directory['path'] . '/');
 //$t_offset = rtrim($filesBaseUrl.$offset, '/').'/';  //possibly the problem with doulbe slash will be fixed by removing / from the above line, but in order to be sure ....
 $t_offset = str_replace('//', '/', $filesBaseUrl . $offset . '/');
 $t_offset = str_replace('//', '/', $t_offset);
 $smarty->assign("T_OFFSET", $t_offset);
 $files = $folders = array();
 //for_type defines which kind of files we need.
Example #4
0
function clearBackupTempFolder()
{
    try {
        $directory = new EfrontDirectory(G_BACKUPPATH . 'temp/');
        $directory->delete();
    } catch (Exception $e) {
    }
}
 public function scormExport()
 {
     $scormExportFolder = G_SCORMPATH . $this->lesson['id'] . "/";
     try {
         $dir = new EfrontDirectory($scormExportFolder);
         $dir->delete();
     } catch (Exception $e) {
     }
     $htmlExportFolder = $scormExportFolder . 'html/';
     $filesExportFolder = $scormExportFolder . 'html/files/';
     is_dir($filesExportFolder) or mkdir($filesExportFolder, 0755, true);
     //is_dir($htmlExportFolder)  OR mkdir($htmlExportFolder, 0755, true);
     $filelist = array();
     $content = new EfrontContentTree($this, true);
     foreach (new EfrontContentFilterIterator(new EfrontNoSCORMFilterIterator(new EfrontVisitableAndEmptyFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($content->tree, RecursiveIteratorIterator::SELF_FIRST))))) as $key => $unit) {
         $unitFiles = $unit->getFiles(true);
         $units[] = $unit;
         $data = $unit['data'];
         foreach ($unitFiles as $file) {
             $filePath = str_replace($this->getDirectory(), "/", EfrontFile::encode($file['path']));
             //Added this line in case of a space in path(urlencode makes it + and rawurlencode convers also slashes ) (#2143)
             $data = str_replace("content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']) . str_replace(' ', '%20', $filePath), "files" . str_replace(' ', '%20', $filePath), $data);
             $data = str_replace("content/lessons/" . ($this->lesson['share_folder'] ? $this->lesson['share_folder'] : $this->lesson['id']) . $filePath, "files" . $filePath, $data);
             $data = str_replace("view_file.php?file=" . $file['id'], "files" . $filePath, $data);
         }
         $unitContent = $this->createSCORMHtmlFiles($data);
         $unitFilename = $htmlExportFolder . str_replace('?', ' ', $unit['name']) . ".html";
         file_put_contents(EfrontFile::encode($unitFilename), $unitContent);
         $metadata = $this->getSCORMAssetMetadata($unit);
         $metadataFilename = $htmlExportFolder . str_replace('?', ' ', $unit['name']) . ".xml";
         //file_put_contents($metadataFilename, $metadata);
         file_put_contents(EfrontFile::encode($metadataFilename), $metadata);
         $filelist = array_merge($filelist, $unitFiles);
     }
     foreach ($filelist as $file) {
         $filePath = str_replace($this->getDirectory(), "", $file['path']);
         if (!is_dir($filesExportFolder . dirname($filePath))) {
             mkdir($filesExportFolder . dirname($filePath), 0755, true);
         }
         $file->copy($filesExportFolder . $filePath, true, false);
         $metadata = $this->getSCORMAssetMetadata($file);
         $metadataFilename = EfrontFile::encode($filesExportFolder . $filePath . ".xml");
         file_put_contents($metadataFilename, $metadata);
     }
     /*Create manifest*/
     $prerequisites = $this->getSCORMPrerequisites();
     $organizations_str = $this->buildSCORMManifestOrganizations($prerequisites);
     $resources_str = $this->buildSCORMManifestResources($units);
     $metadata_str = $this->buildSCORMManifestMetadata(0);
     $manifest = $this->buildSCORMManifestMain($metadata_str . $organizations_str . $resources_str);
     file_put_contents($scormExportFolder . "imsmanifest.xml", $manifest);
     /*Create functions files*/
     list($func1, $func2) = $this->getAPIFunctions();
     file_put_contents($scormExportFolder . "APIWrapper.js", $func1);
     file_put_contents($scormExportFolder . "SCOFunctions.js", $func2);
     $scormDirectory = new EfrontDirectory($scormExportFolder);
     if (eF_checkParameter($this->lesson['name'], 'path')) {
         $filename = $this->lesson['name'] . '.zip';
     } else {
         $filename = 'SCO.zip';
     }
     $compressedFile = $scormDirectory->compress($filename, false);
     $scormDirectory->delete();
     return $compressedFile;
 }
 /**
  *
  * @return unknown_type
  */
 public function export()
 {
     if (!$this->remote) {
         global $currentUser;
         $directory = new EfrontDirectory(G_THEMESPATH . $this->{$this->entity}['path']);
         $file = $directory->compress();
         $file = $file->copy($currentUser->getDirectory() . $file['name']);
         return $file;
     }
 }
 /**
  * Delete user
  *
  * This function is used to delete a user from the system.
  * The user cannot be deleted if he is the last system administrator.
  * <br/>Example:
  * <code>
  * $user = EfrontUserFactory :: factory('jdoe');
  * $user -> delete();
  * </code>
  *
  * @return boolean True if the user was deleted successfully
  * @since 3.5.0
  * @access public
  */
 public function delete()
 {
     // Added by Masoud Sadjadi on July 6, 2014 to support vLab in eFront
     $vLab_username = $this->user['login'];
     $this->logout();
     ///MODULES2 - Module user delete events - Before anything else
     // Get all modules (NOT only the ones that have to do with the user type)
     $modules = eF_loadAllModules();
     // Trigger all necessary events. If the function has not been re-defined in the derived module class, nothing will happen
     foreach ($modules as $module) {
         $module->onDeleteUser($this->user['login']);
     }
     try {
         $directory = new EfrontDirectory($this->user['directory']);
         $directory->delete();
     } catch (EfrontFileException $e) {
         $message = _USERDIRECTORYCOULDNOTBEDELETED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ')';
         //This does nothing at the moment
     }
     foreach ($this->aspects as $aspect) {
         $aspect->delete();
     }
     calendar::deleteUserCalendarEvents($this->user['login']);
     eF_updateTableData("f_forums", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("f_messages", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("f_topics", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("f_poll", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("news", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("files", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("f_folders", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("f_personal_messages", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("bookmarks", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("comments", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("f_users_to_polls", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("logs", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("rules", "users_LOGIN='******'login'] . "'");
     //eF_deleteTableData("users_online", "users_LOGIN='******'login']."'");
     eF_deleteTableData("user_times", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_surveys", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_done_surveys", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("survey_questions_done", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("lessons_timeline_topics_data", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("events", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("profile_comments", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_content", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_lessons", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_courses", "users_LOGIN='******'login'] . "'");
     if (G_VERSIONTYPE != 'community') {
         #cpp#ifndef COMMUNITY
         eF_deleteTableData("payments", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("facebook_connect", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("users_to_skillgap_tests", "users_LOGIN='******'login'] . "'");
     }
     #cpp#endif
     //This line was in EfrontProfessor and EfrontStudent without an obvious reason. Admins may also be members of groups
     eF_deleteTableData("users_to_groups", "users_LOGIN='******'login'] . "'");
     //Changing order of these lines because of #4318, where system removal notification was set (user triggering the event)
     eF_deleteTableData("notifications", "recipient='" . $this->user['login'] . "'");
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_REMOVAL, "users_LOGIN" => $this->user['login'], "users_name" => $this->user['name'], "users_surname" => $this->user['surname']));
     eF_deleteTableData("users", "login='******'login'] . "'");
     // Added by Masoud Sadjadi on July 6, 2014 to support vLab in eFront
     // Beging addition
     // $vLab_username 				= $this -> user['login'];
     $vLab_username_urlEncoded = rawurlencode($vLab_username);
     $vLab_courseid = 123;
     // Kaseya 7.0 Fundamentals Workshop
     $vLab_courseid_urlEncoded = rawurlencode($vLab_courseid);
     // $vLab_moodleURL = "http://localhost/moodle19";
     $vLab_moodleURL = "http://ita-portal.cis.fiu.edu";
     // auto delete
     $str = $vLab_moodleURL . "/mod/deva/embedded/auto-delete.php?username={$vLab_username_urlEncoded}&courseid={$vLab_courseid_urlEncoded}";
     // echo $str . '<br>';
     $payload = file_get_contents($str);
     // echo $payload;
     return true;
 }
Example #8
0
             mkdir(IMS_FOLDER, 0755);
         }
         $ims_filename = "ims_lesson" . $lessons_id . ".zip";
         if (is_file(IMS_FOLDER . "/" . $ims_filename)) {
             unlink(IMS_FOLDER . "/" . $ims_filename);
         }
         $lessons_id = $currentLesson->lesson['id'];
         try {
             $filesystem = new FileSystemTree($currentLesson->getDirectory());
             foreach (new EfrontNodeFilterIterator(new RecursiveIteratorIterator($filesystem->tree, RecursiveIteratorIterator::SELF_FIRST)) as $key => $value) {
                 $value instanceof EfrontDirectory ? $filelist[] = preg_replace("#" . $currentLesson->getDirectory() . "#", "", $key) . '/' : ($filelist[] = preg_replace("#" . $currentLesson->getDirectory() . "#", "", $key));
             }
             $lesson_entries = eF_getTableData("content", "id,name,data", "lessons_ID=" . $lessons_id . " and ctg_type!='tests' and active=1");
             require_once "ims_tools.php";
             create_manifest($lessons_id, $lesson_entries, $filelist, IMS_FOLDER);
             $imsDirectory = new EfrontDirectory(IMS_FOLDER . "/lesson" . $lessons_id . "/");
             $compressedFile = $imsDirectory->compress(false, false, true);
             $imsDirectory->delete();
             $smarty->assign("T_IMS_EXPORT_FILE", $compressedFile);
             $smarty->assign("T_MESSAGE", _SUCCESSFULLYEXPORTEDIMSFILE);
             $smarty->assign("T_MESSAGE_TYPE", "success");
         } catch (Exception $e) {
             $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
             $message = _SOMEPROBLEMEMERGED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
             $message_type = "failure";
         }
     }
     $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
     $form->accept($renderer);
     $smarty->assign('T_EXPORT_IMS_FORM', $renderer->toArray());
 }
 /**
  * Create The MS Word Document from given HTML
  *
  * @param String $html :: HTML Content or HTML File Name like path/to/html/file.html
  * @param String $file :: Document File Name
  * @param Boolean $download :: Wheather to download the file or save the file
  * @return boolean 
  */
 function createDoc($html, $file, $download = false)
 {
     if (is_file($html)) {
         $html = @file_get_contents($html);
     }
     $this->_parseHtml($html);
     $this->setDocFileName($file);
     $doc = $this->getHeader();
     $doc .= $this->htmlBody;
     $doc .= $this->getFotter();
     if ($download) {
         if (!empty($this->localimgs)) {
             if (file_exists($this->lessonDirectory . $file)) {
                 $tmpDir = new EfrontDirectory($this->lessonDirectory . $file);
             } else {
                 $tmpDir = EfrontDirectory::createDirectory($this->lessonDirectory . $file);
             }
             $array_cp = $tmpDir->getArrayCopy();
             foreach ($this->localimgs as $img) {
                 $file = new EfrontFile($img['path'] . $img['src']);
                 $file->copy($array_cp['path'] . "/" . $img['src']);
             }
             $this->write_file($array_cp['path'] . "/" . $this->docFile, $doc);
             $zipfile = $tmpDir->compress();
             $tmpDir->delete();
             $zipfile->sendFile();
             exit;
         } else {
             @header("Cache-Control: ");
             // leave blank to avoid IE errors
             @header("Pragma: ");
             // leave blank to avoid IE errors
             @header("Content-type: application/octet-stream");
             @header("Content-Disposition: attachment; filename=\"{$this->docFile}\"");
             echo $doc;
         }
         return true;
     } else {
         return $this->write_file($this->docFile, $doc);
     }
 }
Example #10
0
     $file = $form->addElement('file', 'filename', _FILE);
     $maxFileSize = FileSystemTree::getUploadMaxSize();
     $form->addRule('filename', _THEFIELD . ' "' . _FILE . '" ' . _ISMANDATORY, 'required', null, 'client');
     $form->setMaxFileSize($maxFileSize * 1024);
     $form->addElement('submit', 'submit_upload_project', _SENDPROJECT, 'class = "flatButton"');
 }
 $smarty->assign("T_MAX_FILE_SIZE", $maxFileSize);
 if ($form->isSubmitted() && $form->validate() && !$currentProject->expired) {
     try {
         $projectDirectory = G_UPLOADPATH . $currentUser->user['login'] . '/projects';
         if (!is_dir($projectDirectory)) {
             EfrontDirectory::createDirectory($projectDirectory);
         }
         $projectDirectory = G_UPLOADPATH . $currentUser->user['login'] . '/projects/' . $currentProject->project['id'];
         if (!is_dir($projectDirectory)) {
             EfrontDirectory::createDirectory($projectDirectory);
         }
         $filesystem = new FileSystemTree($projectDirectory);
         $uploadedFile = $filesystem->uploadFile('filename', $projectDirectory);
         //$uploadedFile -> rename($uploadedFile['directory'].'/project_'.$currentProject -> project['id'].'.'.$uploadedFile['extension']);
         $fields_update = array("filename" => $uploadedFile['id'], "upload_timestamp" => time());
         eF_updateTableData("users_to_projects", $fields_update, "users_LOGIN='******'login'] . "' AND projects_ID=" . $_GET['view_project']);
         EfrontEvent::triggerEvent(array("type" => EfrontEvent::PROJECT_SUBMISSION, "users_LOGIN" => $currentUser->user['login'], "lessons_ID" => $currentLesson->lesson['id'], "lessons_name" => $currentLesson->lesson['name'], "entity_ID" => $currentProject->project['id'], "entity_name" => $currentProject->project['title']));
         eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=projects&view_project=" . $_GET['view_project'] . "&message=" . urlencode(_FILEUPLOADED) . "&message_type=success");
     } catch (EfrontFileException $e) {
         $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
         $message = _SOMEPROBLEMOCCURED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
         $message_type = 'failure';
     }
 } elseif ($currentProject->expired) {
     $message = _PROJECTEXPIRED;
    /**
     * The main functionality
     *
     * (non-PHPdoc)
     * @see libraries/EfrontModule#getModule()
     */
    public function getModule()
    {
        $smarty = $this->getSmartyVar();
        $smarty->assign("T_MODULE_BASEDIR", $this->moduleBaseDir);
        $smarty->assign("T_MODULE_BASELINK", $this->moduleBaseLink);
        $smarty->assign("T_MODULE_BASEURL", $this->moduleBaseUrl);
        $form = new HTML_QuickForm("bootstrap_form", "post", $this->moduleBaseUrl, "", null, true);
        $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
        $form->addElement('text', 'name', _NAME, 'class = "inputText"');
        $form->addElement('static', '', _MODULE_BOOTSTRAP_WITHOUTTHECLASS, 'class = "inputText"');
        $form->addRule('name', _THEFIELD . ' ' . _NAME . ' ' . _ISMANDATORY, 'required', null, 'client');
        $form->addRule('name', _INVALIDFIELDDATA, 'checkParameter', 'alnum');
        $form->addElement('text', 'title', _TITLE, 'class = "inputText"');
        $form->addElement('text', 'creator', _MODULE_BOOTSTRAP_CREATOR, 'class = "inputText"');
        $form->addElement('checkbox', 'administrator', _ADMINISTRATOR);
        $form->addElement('checkbox', 'professor', _PROFESSOR);
        $form->addElement('checkbox', 'student', _STUDENT);
        $form->addElement('checkbox', 'supervisor', _MODULE_BOOTSTRAP_SUPERVISORONLY);
        $form->addElement('checkbox', 'tabber', _MODULE_BOOTSTRAP_TABBER);
        $form->addElement('textarea', 'form', _MODULE_BOOTSTRAP_FORMFIELDS, 'class = "inputTextarea" style = "height:40px"');
        $form->addElement('static', '', _MODULE_BOOTSTRAP_FORMINSTRUCTIONS);
        $form->addElement('textarea', 'grid', _MODULE_BOOTSTRAP_GRIDFIELDS, 'class = "inputTextarea" style = "height:40px"');
        $form->addElement('static', '', _MODULE_BOOTSTRAP_GRIDINSTRUCTIONS);
        $form->addElement('checkbox', 'filemanager', _MODULE_BOOTSTRAP_FILEMANAGER);
        $form->addElement('textarea', 'description', _DESCRIPTION, 'class = "inputTextarea" style = "height:80px"');
        //$form -> addElement('placing', 'student', _MODULE_BOOTSTRAP_NAME);
        $form->addElement('checkbox', 'overwrite', _MODULE_BOOTSTRAP_OVERWRITEIFEXISTS);
        $form->addElement('submit', 'submit', _INSTALL, 'class = "flatButton"');
        $form->setDefaults(array('creator' => $this->getCurrentUser()->user['name'] . ' ' . $this->getCurrentUser()->user['surname']));
        if ($form->isSubmitted() && $form->validate()) {
            try {
                $values = $form->exportValues();
                if (!$values['administrator'] && !$values['student'] && !$values['professor']) {
                    throw new Exception(_MODULE_BOOTSTRAP_YOUMUSTSELECTATLEASTATYPE);
                }
                $module_name = $values['name'];
                $module_dir = $this->moduleBaseDir . 'module_' . $module_name;
                if (!is_dir($module_dir)) {
                    mkdir($module_dir, 0755);
                }
                if (!is_dir("{$module_dir}/img")) {
                    mkdir("{$module_dir}/img", 0755);
                }
                if (!is_dir("{$module_dir}/assets")) {
                    mkdir("{$module_dir}/assets", 0755);
                }
                if ($values['administrator']) {
                    $roles[] = 'administrator';
                }
                if ($values['professor']) {
                    $roles[] = 'professor';
                }
                if ($values['student']) {
                    $roles[] = 'student';
                }
                $roles = '"' . implode('","', $roles) . '"';
                $contents = $tabber = $block = $grid_content = $fields_content = '';
                $fields = array();
                if ($values['form']) {
                    foreach (explode(",", $values['form']) as $property) {
                        $property = explode(":", $property);
                        array_walk($property, create_function('&$v', '$v = trim($v);'));
                        $fields[] = array('type' => $property[0], 'name' => $property[1], 'title' => $property[2], 'extra' => $property[3]);
                    }
                    foreach ($fields as $value) {
                        $fields_content .= '$form -> addElement("' . $value["type"] . '", "' . $value["name"] . '", "' . $value["title"] . '", "' . $value["extra"] . '");';
                    }
                } else {
                    $fields = "return false;";
                }
                if ($values['filemanager']) {
                    $file_manager = "true";
                } else {
                    $file_manager = "false";
                }
                if ($values['grid']) {
                    $headers = $rows = $grid_contents = array();
                    $grid_content = "\$data = array(array(";
                    foreach (explode(",", $values['grid']) as $property) {
                        $property = trim($property);
                        if ($property) {
                            $property = explode(":", $property);
                            array_walk($property, create_function('&$v', '$v = trim($v);'));
                            $headers[] = "\r\n\t\t\t\t\t\t\t\t<td class = 'topTitle' name = '{$property[0]}'>{$property[1]}</td>";
                            $rows[] = "\r\n\t\t\t\t\t\t\t\t<td>{\$item.{$property[0]}}</td>";
                            $grid_content .= "'{$property[0]}' => 'sample value',";
                        }
                    }
                    $grid_content .= "));";
                    $headers = implode("\n", $headers);
                    $rows = implode("\n", $rows);
                    $contents .= <<<GRID
{capture name = "t_grid_code"}
<!--ajax:{$module_name}Table-->
\t\t\t\t\t<table style = "width:100%" class = "sortedTable" size = "{\$T_TABLE_SIZE}" sortBy = "0" id = "{$module_name}Table" useAjax = "1" rowsPerPage = "{\$smarty.const.G_DEFAULT_TABLE_SIZE}" url = "{\$T_MODULE_BASEURL}&">
\t\t\t\t\t\t<tr class = "topTitle">
\t\t\t\t\t\t\t{$headers}
\t\t\t\t\t\t</tr>
\t{foreach name = 'demo_data_list' key = 'key' item = 'item' from = \$T_DATA_SOURCE}
\t\t\t\t\t\t<tr class = "defaultRowHeight {cycle values = "oddRowColor, evenRowColor"}">
\t\t\t\t\t\t\t{$rows}
\t\t\t\t\t\t</tr>
\t{foreachelse}
\t\t\t\t\t<tr class = "defaultRowHeight oddRowColor"><td class = "emptyCategory" colspan = "100%">{\$smarty.const._NODATAFOUND}</td></tr>
\t{/foreach}
\t\t\t\t</table>

<!--/ajax:{$module_name}Table-->

{/capture}

GRID;
                    if ($values['tabber']) {
                        $tabber = "tabber = \"{$module_name}_grid\"";
                    }
                    $block .= '{eF_template_printBlock ' . $tabber . ' title = "' . _MODULE_BOOTSTRAP_DATA . '" data = $smarty.capture.t_grid_code}' . "\n";
                }
                if ($values['form']) {
                    $contents .= <<<FORM
{capture name = "t_form_block_code"}
\t{eF_template_printForm form = \$T_FORM}
{/capture}
FORM;
                    if ($values['tabber']) {
                        $tabber = "tabber = \"{$module_name}_form\"";
                    }
                    $block .= '{eF_template_printBlock ' . $tabber . ' title = "' . _MODULE_BOOTSTRAP_FORM . '" data = $smarty.capture.t_form_block_code}' . "\n";
                }
                if ($values['filemanager']) {
                    $contents .= <<<FILEMANAGER
{capture name = "t_block_code"}
\t{\$T_FILE_MANAGER}
{/capture}
FILEMANAGER;
                    if ($values['tabber']) {
                        $tabber = "tabber = \"{$module_name}_filemanager\"";
                    }
                    $block .= '{eF_template_printBlock ' . $tabber . ' title = "' . _MODULE_BOOTSTRAP_FILES . '" data = $smarty.capture.t_block_code}';
                }
                if ($values['empty_page']) {
                    $contents .= <<<EMPTY
{capture name = "t_block_code"}
\tCode here
{/capture}
EMPTY;
                    if ($values['tabber']) {
                        $tabber = "tabber = \"{$module_name}_page\"";
                    }
                    $block .= '{eF_template_printBlock ' . $tabber . ' title = "' . _MODULE_BOOTSTRAP_PAGE . '" data = $smarty.capture.t_block_code}';
                }
                if ($values['tabber']) {
                    $contents = <<<CONTENTS
{$contents}
{capture name = "t_code"}
<div class = "tabber">
{$block}
</div>
{/capture}
{eF_template_printBlock title = "{$values["title"]}" data = \$smarty.capture.t_code}
CONTENTS;
                } else {
                    $contents = $contents . $block;
                }
                file_put_contents("{$module_dir}/module.tpl", $contents);
                $search = array("###NAME###", "###TITLE###", "###ROLES###", "###FIELDS###", "###FILE_MANAGER###", "###GRID_DATA###");
                $replace = array($module_name, $values['title'], $roles, $fields_content, $file_manager, $grid_content);
                $contents = file_get_contents($this->moduleBaseDir . "template/module_.class.php");
                $contents = str_replace($search, $replace, $contents);
                file_put_contents("{$module_dir}/module_{$module_name}.class.php", $contents);
                $date = date("Y m d");
                $xml = <<<XML
<?xml version="1.0" ?>
<module>
\t<title>{$values['title']}</title>
\t<author>{$values['creator']}</author>
\t<date>{$date}</date>
\t<version>1.0</version>
\t<description>{$values['description']}</description>
\t<className>module_{$module_name}</className>
\t<requires>3.6.11</requires>
</module>
XML;
                file_put_contents("{$module_dir}/module.xml", $xml);
                copy($this->moduleBaseDir . "img/logo.png", "{$module_dir}/img/logo.png");
                copy($this->moduleBaseDir . "img/generic.png", "{$module_dir}/img/generic.png");
                $directory = new EfrontDirectory($module_dir);
                if (is_dir(G_MODULESPATH . basename($module_dir))) {
                    if ($values['overwrite']) {
                        $file = $directory->copy(G_MODULESPATH . basename($module_dir), true);
                    } else {
                        throw new Exception(_MODULE_BOOTSTRAP_MODULEEXISTS);
                    }
                } else {
                    $file = $directory->copy(G_MODULESPATH . basename($module_dir));
                }
                $this->setMessageVar(_MODULE_BOOTSTRAP_MODULEINSTALLED, 'success');
            } catch (Exception $e) {
                $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
                $message = $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
                $this->setMessageVar($message, 'failure');
            }
        }
        $smarty->assign("T_FORM", $form->toArray());
        return true;
    }
 /**
  * Delete user
  *
  * This function is used to delete a user from the system.
  * The user cannot be deleted if he is the last system administrator.
  * <br/>Example:
  * <code>
  * $user = EfrontUserFactory :: factory('jdoe');
  * $user -> delete();
  * </code>
  *
  * @return boolean True if the user was deleted successfully
  * @since 3.5.0
  * @access public
  */
 public function delete()
 {
     $this->logout();
     ///MODULES2 - Module user delete events - Before anything else
     // Get all modules (NOT only the ones that have to do with the user type)
     $modules = eF_loadAllModules();
     // Trigger all necessary events. If the function has not been re-defined in the derived module class, nothing will happen
     foreach ($modules as $module) {
         $module->onDeleteUser($this->user['login']);
     }
     try {
         $directory = new EfrontDirectory($this->user['directory']);
         $directory->delete();
     } catch (EfrontFileException $e) {
         $message = _USERDIRECTORYCOULDNOTBEDELETED . ': ' . $e->getMessage() . ' (' . $e->getCode() . ')';
         //This does nothing at the moment
     }
     foreach ($this->aspects as $aspect) {
         $aspect->delete();
     }
     calendar::deleteUserCalendarEvents($this->user['login']);
     eF_updateTableData("f_forums", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("f_messages", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("f_topics", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("f_poll", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("news", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_updateTableData("files", array("users_LOGIN" => ''), "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("f_folders", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("f_personal_messages", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("bookmarks", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("comments", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("f_users_to_polls", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("logs", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("rules", "users_LOGIN='******'login'] . "'");
     //eF_deleteTableData("users_online", "users_LOGIN='******'login']."'");
     eF_deleteTableData("user_times", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_surveys", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_done_surveys", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("survey_questions_done", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("lessons_timeline_topics_data", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("events", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("profile_comments", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_content", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_lessons", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("users_to_courses", "users_LOGIN='******'login'] . "'");
     eF_deleteTableData("scorm_data", "users_LOGIN='******'login'] . "'");
     if (G_VERSIONTYPE != 'community') {
         #cpp#ifndef COMMUNITY
         eF_deleteTableData("payments", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("facebook_connect", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("users_to_skillgap_tests", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_data_2004", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_activity_progress_information", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_activity_state_information", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_comments_from_learner", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_global_state_information", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_interactions", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_learner_preferences", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_maps_info", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_objective_progress_information", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_shared_data", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_shared_data_not_g", "users_LOGIN='******'login'] . "'");
         eF_deleteTableData("scorm_sequencing_objective_progress_information_all", "users_LOGIN='******'login'] . "'");
     }
     #cpp#endif
     //This line was in EfrontProfessor and EfrontStudent without an obvious reason. Admins may also be members of groups
     eF_deleteTableData("users_to_groups", "users_LOGIN='******'login'] . "'");
     //Changing order of these lines because of #4318, where system removal notification was set (user triggering the event)
     eF_deleteTableData("notifications", "recipient='" . $this->user['login'] . "'");
     EfrontEvent::triggerEvent(array("type" => EfrontEvent::SYSTEM_REMOVAL, "users_LOGIN" => $this->user['login'], "users_name" => $this->user['name'], "users_surname" => $this->user['surname']));
     eF_deleteTableData("users", "login='******'login'] . "'");
     return true;
 }
 /**
  * Handle AJAX actions
  *
  * This function is used to perform the necessary ajax actions,
  * that may be fired by the file manager
  * <br/>Example:
  * <code>
  * $basedir    = $currentLesson -> getDirectory();
  * $filesystem = new FileSystemTree($basedir);
  * $filesystem -> handleAjaxActions();
  * </code>
  *
  * @param EfrontUser $currentUser The current user
  * @since 3.5.0
  * @access public
  */
 public function handleAjaxActions($currentUser)
 {
     if (isset($_GET['delete_file']) && (eF_checkParameter($_GET['delete_file'], 'id') || strpos(urldecode($_GET['delete_file']), $this->dir['path']) !== false)) {
         try {
             $file = new EfrontFile(urldecode($_GET['delete_file']));
             if (strpos($file['path'], $this->dir['path']) === false) {
                 throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
             }
             $file->delete();
         } catch (Exception $e) {
             handleAjaxExceptions($e);
         }
         exit;
     } else {
         if (isset($_GET['share']) && (eF_checkParameter($_GET['share'], 'id') || strpos(urldecode($_GET['share']), $this->dir['path']) !== false)) {
             try {
                 $file = new EfrontFile(urldecode($_GET['share']));
                 if (strpos($file['path'], $this->dir['path']) === false) {
                     throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                 }
                 $file->share();
             } catch (Exception $e) {
                 handleAjaxExceptions($e);
             }
             exit;
         } else {
             if (isset($_GET['unshare']) && (eF_checkParameter($_GET['unshare'], 'id') || strpos(urldecode($_GET['unshare']), $this->dir['path']) !== false)) {
                 try {
                     $file = new EfrontFile(urldecode($_GET['unshare']));
                     if (strpos($file['path'], $this->dir['path']) === false) {
                         throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                     }
                     $file->unshare();
                 } catch (Exception $e) {
                     handleAjaxExceptions($e);
                 }
                 exit;
             } else {
                 if (isset($_GET['uncompress']) && (eF_checkParameter($_GET['uncompress'], 'id') || strpos(urldecode($_GET['uncompress']), $this->dir['path']) !== false)) {
                     try {
                         $file = new EfrontFile(urldecode($_GET['uncompress']));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $file->uncompress();
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['delete_folder']) && (eF_checkParameter($_GET['delete_folder'], 'id') || strpos(urldecode($_GET['delete_folder']), $this->dir['path']) !== false)) {
                     try {
                         $directory = new EfrontDirectory(urldecode($_GET['delete_folder']));
                         if (strpos($directory['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $directory->delete();
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['download']) && (eF_checkParameter($_GET['download'], 'id') || strpos(urldecode($_GET['download']), $this->dir['path']) !== false)) {
                     try {
                         $file = new EfrontFile(urldecode($_GET['download']));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $file->sendFile(true);
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['view']) && (eF_checkParameter($_GET['view'], 'id') || strpos(urldecode($_GET['view']), $this->dir['path']) !== false)) {
                     try {
                         $file = new EfrontFile(urldecode($_GET['view']));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $file->sendFile(false);
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 } elseif (isset($_GET['update']) && (eF_checkParameter($_GET['update'], 'id') || strpos(urldecode($_GET['update']), $this->dir['path']) !== false)) {
                     try {
                         $_GET['type'] == 'file' ? $file = new EfrontFile(urldecode($_GET['update'])) : ($file = new EfrontDirectory(urldecode($_GET['update'])));
                         if (strpos($file['path'], $this->dir['path']) === false) {
                             throw new EfrontFileException(_YOUCANNOTACCESSTHEREQUESTEDRESOURCE, EfrontFileException::UNAUTHORIZED_ACTION);
                         }
                         $previousName = $file['name'];
                         if ($file['name'] != $_GET['name']) {
                             $file->rename(dirname($file['path']) . '/' . EfrontFile::encode(urldecode($_GET['name'])));
                         }
                         echo json_encode(array('previousName' => $previousName, 'name' => $file['name']));
                     } catch (Exception $e) {
                         handleAjaxExceptions($e);
                     }
                     exit;
                 }
             }
         }
     }
 }
Example #14
0
 /**
  * Delete done test information
  *
  * This function is used to delete the done information for the specified
  * user.
  * <br/>Example:
  * <code>
  * $test -> undo('jdoe');                           //Delete test information for user jdoe
  * $test -> undo('jdoe', 43);                       //Delete test information for user jdoe and completed test 43
  * </code>
  *
  * @param mixed $user The user to delete test for, either a user login or an EfrontUser instance
  * @param int $instance A specific completedTest instance to delete. If it's ommited, all completed tests from this user will be deleted
  * @since 3.5.2
  * @access public
  */
 public function undo($user, $instance = false)
 {
     if ($user instanceof EfrontUser) {
         $login = $user->user['login'];
     } elseif (eF_checkParameter($user, 'login')) {
         $login = $user;
     } else {
         throw new EfrontTestException(_INVALIDLOGIN . ': ' . $user, EfrontTestException::INVALID_LOGIN);
     }
     if (!$instance) {
         $result = eF_getTableData("completed_tests", "id", "users_LOGIN='******' and tests_ID=" . $this->test['id']);
         foreach ($result as $value) {
             if (is_dir(G_UPLOADPATH . $login . '/tests/' . $value['id'])) {
                 try {
                     $directory = new EfrontDirectory(G_UPLOADPATH . $login . '/tests/' . $value['id'] . '/');
                     $directory->delete();
                 } catch (EfrontFileException $e) {
                 }
             }
         }
         if ($this->test['content_ID']) {
             //Set the unit as "not seen"
             if (!$user instanceof EfrontUser) {
                 $user = EfrontUserFactory::factory($login, false, 'student');
             }
             $user->setSeenUnit($this->test['content_ID'], key($this->getLesson()), 0);
         } else {
             eF_updateTableData("users_to_skillgap_tests", array("solved" => 0), "tests_id = " . $this->test['id'] . " AND users_login = '******'");
         }
         eF_deleteTableData("completed_tests", "users_LOGIN='******' and tests_ID=" . $this->test['id']);
     } else {
         if (!eF_checkParameter($instance, 'id')) {
             throw new EfrontTestException(_INVALIDID . ': ' . $instance, EfrontTestException::INVALID_ID);
         }
         $result = EfrontCompletedTest::retrieveCompletedTest("completed_tests ct", "ct.*", "users_LOGIN='******' and ct.id = " . $instance);
         if (sizeof($result) == 0) {
             throw new EfrontTestException(_USERHASNOTDONETEST . ': ' . $login, EfrontTestException::NOT_DONE_TEST);
         }
         if (is_dir(G_UPLOADPATH . $login . '/tests/' . $instance)) {
             try {
                 $directory = new EfrontDirectory(G_UPLOADPATH . $login . '/tests/' . $instance . '/');
                 $directory->delete();
             } catch (EfrontFileException $e) {
             }
         }
         //If the test is the last one (the 'active'), set it as not seen.
         //If it doesn't have a content id, it is a skill-gap test
         if ($result[0]['archive'] == 0 && $this->test['content_ID']) {
             if (!$user instanceof EfrontUser) {
                 $user = EfrontUserFactory::factory($login, false, 'student');
             }
             $user->setSeenUnit($this->test['content_ID'], key($this->getLesson()), 0);
         } else {
             if (!$this->test['content_ID']) {
                 eF_updateTableData("users_to_skillgap_tests", array("solved" => 0), "tests_id = " . $this->test['id'] . " AND users_login = '******'");
             }
         }
         eF_deleteTableData("completed_tests", "id=" . $instance);
     }
 }
Example #15
0
 private function createUserTempDirectory()
 {
     $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);
     } else {
         $userTempDir = new EfrontDirectory($userTempDir);
     }
     return $userTempDir;
 }
 public function unitExport(EfrontUnit $unit)
 {
     $currentLesson = $this->getCurrentLesson();
     $unitExportFolder = $this->moduleBaseDir . "assets/";
     try {
         $dir = new EfrontDirectory($unitExportFolder);
         $dir->delete();
     } catch (Exception $e) {
     }
     $htmlExportFolder = $unitExportFolder . 'html/';
     $filesExportFolder = $unitExportFolder . 'html/files/';
     is_dir($filesExportFolder) or mkdir($filesExportFolder, 0755, true);
     //is_dir($htmlExportFolder)  OR mkdir($htmlExportFolder, 0755, true);
     $filelist = array();
     $unitFiles = $unit->getFiles(true);
     $units[] = $unit;
     $data = $unit['data'];
     foreach ($unitFiles as $file) {
         $filePath = str_replace($currentLesson->getDirectory(), "/", EfrontFile::encode($file['path']));
         //Added this line in case of a space in path(urlencode makes it + and rawurlencode convers also slashes ) (#2143)
         $data = str_replace("content/lessons/" . ($currentLesson->lesson['share_folder'] ? $currentLesson->lesson['share_folder'] : $currentLesson->lesson['id']) . str_replace(' ', '%20', $filePath), "files" . str_replace(' ', '%20', $filePath), $data);
         $data = str_replace("content/lessons/" . ($currentLesson->lesson['share_folder'] ? $currentLesson->lesson['share_folder'] : $currentLesson->lesson['id']) . $filePath, "files" . $filePath, $data);
         $data = str_replace("view_file.php?file=" . $file['id'], "files" . $filePath, $data);
     }
     $unitContent = $data;
     $unitFilename = $htmlExportFolder . $unit['name'] . ".html";
     file_put_contents(EfrontFile::encode($unitFilename), $unitContent);
     $filelist = array_merge($filelist, $unitFiles);
     foreach ($filelist as $file) {
         $filePath = str_replace($currentLesson->getDirectory(), "", $file['path']);
         if (!is_dir($filesExportFolder . dirname($filePath))) {
             mkdir($filesExportFolder . dirname($filePath), 0755, true);
         }
         $file->copy($filesExportFolder . $filePath);
     }
     $unitDirectory = new EfrontDirectory($unitExportFolder);
     if (eF_checkParameter($unit['name'], 'file')) {
         $filename = $unit['name'] . '.zip';
     } else {
         $filename = 'unit.zip';
     }
     $compressedFile = $unitDirectory->compress($filename, false);
     //$unitDirectory -> delete();
     return $compressedFile;
 }
Example #17
0
//@todo:temporary here, should leave
$cacheId = null;
$message = $message_type = '';
$benchmark = new EfrontBenchmark($debug_TimeStart);
$benchmark->set('init');
//Set headers in order to eliminate browser cache (especially IE's)
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
header("cache-control: no-transform");
//To prevent 3G carriers from compressing the site, which will break all grids
//Delete installation directory after install/upgrade
if (is_dir("install") && isset($_GET['delete_install'])) {
    try {
        $dir = new EfrontDirectory('install');
        $dir->delete();
    } catch (Exception $e) {
        echo "The installation directory could not be deleted. Please delete it manually or your system security is at risk.";
    }
}
if (G_VERSIONTYPE != 'community') {
    #cpp#ifndef COMMUNITY
    try {
        if (isset($_GET['logout']) && $GLOBALS['configuration']['facebook_api_key'] && $GLOBALS['configuration']['facebook_secret'] && EfrontFacebook::userConnected()) {
            //probably never goes here with new way
            $path = "../libraries/";
            //require_once $path . "external/facebook-platform/php/facebook.php";
            require_once $path . "external/facebook/facebook.php";
            $facebook = new Facebook(array('appId' => $GLOBALS['configuration']['facebook_api_key'], 'secret' => $GLOBALS['configuration']['facebook_secret'], 'cookie' => true));
            $smarty->assign("T_OPEN_FACEBOOK_SESSION", 1);
 /**
  * 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'];
     $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 . '/' . basename($sourceFile['path']);
                     $copiedFile = $sourceFile->copy($destinationPath, false);
                 } else {
                     $destinationPath = $lesson->getDirectory() . 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() . 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;
 }
     eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
 }
 /* Import part */
 $form = new HTML_QuickForm("import_course_form", "post", basename($_SERVER['PHP_SELF']) . '?' . $baseUrl . '&op=import_course', "", null, true);
 $form->addElement('file', 'file_upload', null, 'class = "inputText"');
 //Lesson file
 $form->setMaxFileSize(FileSystemTree::getUploadMaxSize() * 1024);
 //getUploadMaxSize returns size in KB
 $form->addElement('submit', 'submit_import_course', _SUBMIT, 'class = "flatButton"');
 $smarty->assign("T_MAX_FILESIZE", FileSystemTree::getUploadMaxSize());
 if ($form->isSubmitted() && $form->validate()) {
     try {
         $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);
         } else {
             $userTempDir = new EfrontDirectory($userTempDir);
         }
         $filesystem = new FileSystemTree($userTempDir);
         $uploadedFile = $filesystem->uploadFile('file_upload', $userTempDir);
         $currentCourse->import($uploadedFile);
         $message = _COURSEIMPORTEDSUCCESFULLY;
         $message_type = 'success';
     } catch (Exception $e) {
         $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
         $message = _PROBLEMIMPORTINGFILE . ': ' . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
         $message_type = 'failure';
     }
 }
 $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
Example #20
0
                 if (isset($_GET['toggle_block'])) {
                     if (isset($layoutTheme->layout['positions']['enabled'][$_GET['toggle_block']])) {
                         unset($layoutTheme->layout['positions']['enabled'][$_GET['toggle_block']]);
                         echo json_encode(array('enabled' => false));
                     } else {
                         $layoutTheme->layout['positions']['enabled'][$_GET['toggle_block']] = true;
                         echo json_encode(array('enabled' => true));
                     }
                     //pr($layoutTheme -> layout['positions']);
                     $layoutTheme->persist();
                     //pr($_GET['toggle_block']);
                     exit;
                 } else {
                     if (isset($_GET['export_layout'])) {
                         file_put_contents(G_THEMESPATH . $layoutTheme->themes['path'] . 'external/layout_settings.php.inc', serialize($layoutTheme->layout));
                         $directory = new EfrontDirectory(G_THEMESPATH . $layoutTheme->themes['path'] . 'external/');
                         $tempDir = $currentUser->getDirectory() . 'temp/';
                         if (!is_dir($tempDir) && !mkdir($tempDir, 0755)) {
                             throw new EfrontFileException(_COULDNOTCREATEDIRECTORY . ': ' . $tempDir, EfrontFileException::CANNOT_CREATE_DIR);
                         }
                         //pr($tempDir.'layout.zip');debug();
                         $file = $directory->compress(false, false);
                         $file->rename($tempDir . $layoutTheme->{$layoutTheme->entity}['name'] . '_layout.zip', true);
                         echo json_encode(array('file' => $file['path']));
                         exit;
                     }
                 }
             }
         }
     }
 } catch (Exception $e) {
Example #21
0
 foreach ($values['import_url'] as $key => $urlUpload) {
     if ($urlUpload && !in_array(basename($urlUpload), $uploadedFiles)) {
         FileSystemTree::checkFile($urlUpload);
         $urlArray = explode("/", $urlUpload);
         $urlFile = urldecode($urlArray[sizeof($urlArray) - 1]);
         if (!copy(dirname($urlUpload) . '/' . rawurlencode(basename($urlUpload)), $uploadDir . "/" . $urlFile)) {
             $errors[] = _PROBLEMUPLOADINGFILE . ': ' . $urlUpload;
         } else {
             $uploadedFiles[basename($urlUpload)] = new EfrontFile($uploadDir . "/" . $urlFile);
         }
     }
 }
 //Perform any path uploads
 foreach ($values['import_path'] as $key => $pathUpload) {
     if ($pathUpload && !in_array($pathUpload, $uploadedFiles)) {
         $pathUpload = EfrontDirectory::normalize($pathUpload);
         if (strpos(dirname($pathUpload), rtrim(G_ROOTPATH, "/")) !== false) {
             FileSystemTree::checkFile($pathUpload);
             $pathArray = explode("/", $pathUpload);
             $pathFile = urldecode($pathArray[sizeof($pathArray) - 1]);
             if (!copy($pathUpload, $uploadDir . "/" . $pathFile)) {
                 $errors[] = _PROBLEMUPLOADINGFILE . ': ' . $pathUpload;
             } else {
                 $uploadedFiles[basename($pathUpload)] = new EfrontFile($uploadDir . "/" . $pathFile);
             }
         } else {
             $errors[] = _PROBLEMUPLOADINGFILE . ': ' . $pathUpload;
         }
     }
 }
 if (!empty($errors)) {
Example #22
0
 foreach ($removedDir as $key => $value) {
     if (is_dir($value)) {
         try {
             $directory = new EfrontDirectory($value);
             $directory->delete();
         } catch (EfrontFileException $e) {
         }
         //Don't stop on filesystem errors
     }
 }
 $fileSystemTree = new FileSystemTree(G_ROOTPATH . 'www/editor/tiny_mce/plugins', true);
 foreach (new EfrontDirectoryOnlyFilterIterator($fileSystemTree->tree) as $key => $value) {
     if (is_dir($key . '/jscripts')) {
         try {
             if ($value['name'] != 'preview' && $value['name'] != 'Jsvk') {
                 $directory = new EfrontDirectory($key . '/jscripts');
                 $directory->delete();
             }
         } catch (EfrontFileException $e) {
         }
         //Don't stop on filesystem errors
     }
 }
 try {
     $cacheTree = new FileSystemTree(G_THEMECACHE, true);
     foreach (new EfrontDirectoryOnlyFilterIterator($cacheTree->tree) as $value) {
         $value->delete();
     }
 } catch (Exception $e) {
 }
 EfrontConfiguration::setValue('database_version', G_VERSION_NUM);