/** * 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; }
$certificateDirectory = G_CERTIFICATETEMPLATEPATH; if (!is_dir($certificateDirectory)) { mkdir($certificateDirectory, 0755); } $logoid = 0; try { if ($_FILES['file_upload']['size'] > 0) { $filesystem = new FileSystemTree($certificateDirectory); $uploadedFile = $filesystem->uploadFile('file_upload', $certificateDirectory); $certificateid = $uploadedFile['id']; } else { $selectedCertificate = $form->exportValue('existing_certificate'); $certificateFile = new EfrontFile(G_CERTIFICATETEMPLATEPATH . $selectedCertificate); if ($certificateFile['id'] < 0) { //if the file doesn't exist, then import it $selectedCertificate = $certificateFileSystemTree->seekNode(G_CERTIFICATETEMPLATEPATH . $selectedCertificate); $newList = FileSystemTree::importFiles($selectedCertificate['path']); $certificateid = key($newList); } else { $certificateid = $certificateFile['id']; } } if (G_VERSIONTYPE != 'standard') { #cpp#ifndef STANDARD $duration = $_POST['days'] * 24 * 60 * 60 + $_POST['months'] * 30 * 24 * 60 * 60; $currentCourse->course['certificate_expiration'] = $duration; $duration_reset = $form->exportValue('days_reset') * 24 * 60 * 60 + $form->exportValue('months_reset') * 30 * 24 * 60 * 60; $currentCourse->course['reset_interval'] = $duration_reset; if ($_POST['months'] != 0 || $_POST['days'] != 0) { $currentCourse->course['reset'] = $_POST['reset']; } else {
//pr($e); exit; if ($e->getCode() == EfrontFileException::NOT_APPROPRIATE_TYPE) { $uploadedFile->delete(); } if ($e->getCode() != UPLOAD_ERR_NO_FILE) { throw $e; } if ($form->exportValue('system_avatar') == "none") { $selectedAvatar = 'unknown_small.png'; } else { if ($form->exportValue('system_avatar') != "") { $selectedAvatar = $form->exportValue('system_avatar'); } } if (isset($selectedAvatar)) { $selectedAvatar = $avatarsFileSystemTree->seekNode(G_SYSTEMAVATARSPATH . $selectedAvatar); $newList = FileSystemTree::importFiles($selectedAvatar['path']); //Import the file to the database, so we can access it with view_file $editedUser->user['avatar'] = key($newList); } } EfrontEvent::triggerEvent(array("type" => EfrontEvent::AVATAR_CHANGE, "users_LOGIN" => $editedUser->user['login'], "users_name" => $editedUser->user['name'], "users_surname" => $editedUser->user['surname'], "lessons_ID" => 0, "lessons_name" => "", "entity_ID" => $editedUser->user['avatar'])); } $editedUser->persist(); if (G_VERSIONTYPE == 'enterprise') { #cpp#ifdef ENTERPRISE if (isset($_GET['add_user'])) { $editedEmployee = EfrontHcdUser::createUser(array('users_login' => $editedUser->user['login'])); if ($currentEmployee->isSupervisor() && !EfrontUser::isOptionVisible('show_unassigned_users_to_supervisors')) { //if supervisors can't see unassigned users, then attach this new user to the supervisor's firts branch and job $branch = new EfrontBranch(current($currentEmployee->getSupervisedBranchesRecursive()));