function removeDir($path) { // Add trailing slash to $path if one is not there if (substr($path, -1, 1) != "/") { $path .= "/"; } $files = glob($path . "*"); if (count($files) > 0) { foreach ($files as $file) { if (is_file($file) === true) { // Remove each file in this Directory if (unlink($file) === false) { return false; } } else { if (is_dir($file) === true) { // If this Directory contains a Subdirectory, run this Function on it if (removeDir($file) == false) { return false; } } } } } // Remove Directory once Files have been removed (If Exists) if (is_dir($path) === true) { if (rmdir($path) == false) { return false; } } return true; }
function test_clean() { logTestMessage(NEW_LINE_LOG . " >> Cleanup all test users..."); removeDir(USER_DIR); // including files logTestMessage("End cleanup"); }
/** * Recursively delete a directory * * @param string $path Intial path to delete */ function removeDir($path) { $normal_files = glob($path . "*"); $hidden_files = glob($path . "\\.?*"); $all_files = array_merge($normal_files, $hidden_files); foreach ($all_files as $file) { /* Skip pseudo links to current and parent dirs (./ and ../). */ if (preg_match("/(\\.|\\.\\.)\$/", $file)) { continue; } if (is_file($file) === TRUE) { /* Remove each file in this Directory */ unlink($file); echo _gettext('Removed File') . ': ' . $file . "<br />"; } else { if (is_dir($file) === TRUE) { /* If this Directory contains a Subdirectory, run this Function on it */ removeDir($file); } } } /* Remove Directory once Files have been removed (If Exists) */ if (is_dir($path) === TRUE) { rmdir($path); echo '<br />' . _gettext('Removed Directory') . ': ' . $path . "<br /><br />"; } }
function removeDir($dir) { if (file_exists($dir)) { // create directory pointer $dp = opendir($dir) or die('ERROR: Cannot open directory'); // read directory contents // delete files found // call itself recursively if directories found while ($file = readdir($dp)) { if ($file != '.' && $file != '..') { if (is_file("{$dir}/{$file}")) { unlink("{$dir}/{$file}"); } else { if (is_dir("{$dir}/{$file}")) { removeDir("{$dir}/{$file}"); } } } } // close directory pointer closedir($dp); // remove now-empty directory if (rmdir($dir)) { return true; } else { return false; } } }
public function checkIsEmpty($ftp, $ftp_folder, $file) { $directory = explode('/', $file); if (count($directory) > 1) { unset($directory[count($directory) - 1]); $path = implode('/', $directory); removeDir($ftp_folder, $path, $ftp); } }
public function deleteAction() { if ($this->getConfig()->get('default_layout') == $this->getRequest()->getParam('key')) { $this->addMessage('cantDeleteDefaultLayout'); } else { removeDir(APPLICATION_PATH . '/layouts/' . $this->getRequest()->getParam('key')); $this->addMessage('deleteSuccess'); } $this->redirect(array('action' => 'index')); }
function removeDir($dir) { if (!file_exists($dir)) { return false; } $files = array_diff(scandir($dir), array('.', '..')); foreach ($files as $file) { is_dir("{$dir}/{$file}") && !is_link($dir) ? removeDir("{$dir}/{$file}") : unlink("{$dir}/{$file}"); } return rmdir($dir); }
function removeDir($path) { foreach (glob($path . "/*") as $file) { if (is_dir($file)) { removeDir($file); } else { unlink($file); } } rmdir($path); }
function removeDir($path) { // Normalise $path. $path = rtrim($path, '/') . '/'; // Remove all child files and directories. $items = glob($path . '*'); foreach ($items as $item) { is_dir($item) ? removeDir($item) : unlink($item); } // Remove directory. rmdir($path); }
function removeDir($path) { $dir = new DirectoryIterator($path); foreach ($dir as $fileinfo) { if ($fileinfo->isFile() || $fileinfo->isLink()) { unlink($fileinfo->getPathName()); } elseif (!$fileinfo->isDot() && $fileinfo->isDir()) { removeDir($fileinfo->getPathName()); } } rmdir($path); }
public function deleteAction() { $modules = new \Modules\Admin\Mappers\Module(); $key = $this->getRequest()->getParam('key'); if ($this->getRequest()->isSecure()) { $configClass = '\\Modules\\' . ucfirst($key) . '\\Config\\config'; $config = new $configClass($this->getTranslator()); $config->uninstall(); $modules->delete($key); removeDir(APPLICATION_PATH . '/modules/' . $this->getRequest()->getParam('key')); $this->addMessage('deleteSuccess'); } $this->redirect(array('action' => 'index')); }
/** * Delete a file or a directory * * @author - Hugues Peeters * @param - $file (String) - the path of file or directory to delete * @return - bolean - true if the delete succeed * bolean - false otherwise. * @see - delete() uses check_name_exist() and removeDir() functions */ function my_delete($file) { if (check_name_exist($file)) { if (is_file($file)) { unlink($file); return true; } elseif (is_dir($file)) { removeDir($file); return true; } } else { return false; // no file or directory to delete } }
function cherry_restore_callback() { $theme_folder = isset($_GET['theme_folder']) ? $_GET['theme_folder'] : ''; if (!$theme_folder) { wp_die('File not provided', 'Error'); } $file = str_replace('\\', '/', WP_CONTENT_DIR) . '/themes_backup/' . $theme_folder . ".zip"; $themes_folder = str_replace('\\', '/', get_theme_root()) . '/' . $theme_folder; if (file_exists($file)) { removeDir($themes_folder); cherry_unzip_backup($file, $themes_folder); } else { echo theme_locals("unfortunately") . $theme_folder . theme_locals("please_try"); } }
function removeDir($dirName) { if (!is_dir($dirName)) { return @unlink($dirName); } $handle = @opendir($dirName); while (($file = @readdir($handle)) !== false) { if ($file != '.' && $file != '..') { $dir = $dirName . '/' . $file; is_dir($dir) ? removeDir($dir) : @unlink($dir); } } closedir($handle); return true; }
function removeDir($dir) { if (is_dir($dir)) { $files = scandir($dir); foreach ($files as $file) { if ($file != "." && $file != "..") { removeDir("{$dir}/{$file}"); } } rmdir($dir); } else { if (file_exists($dir)) { unlink($dir); } } }
function removeDir($dirName) { if ($handle = @opendir("{$dirName}")) { while (false !== ($item = @readdir($handle))) { if ($item != "." && $item != "..") { if (is_dir("{$dirName}/{$item}")) { removeDir("{$dirName}/{$item}"); } else { @unlink("{$dirName}/{$item}"); } } } return 1; closedir($handle); } }
function logout() { $userid = isset($_SESSION['userid']) ? $_SESSION['userid'] : 0; $ip = client_ip(); update_user_status($_SESSION['userid'], 0, $ip, $_SERVER['HTTP_USER_AGENT']); update_confid($userid, md5(mt_rand())); $dir = $_SERVER['DOCUMENT_ROOT'] . "/Contacts/views/user/temp/" . md5($userid); if (file_exists($dir)) { removeDir($dir); } unset($_SESSION['userid']); unset($_SESSION['timeout']); unset($_SESSION['username']); unset($_SESSION['isLoggedIn']); unset($_SESSION['becomeLogin']); }
function removeDir($dirName) { $result = false; if (!is_dir($dirName)) { trigger_error("Ŀ¼Ãû³Æ´íÎó", E_USER_ERROR); } $handle = opendir($dirName); while (($file = readdir($handle)) !== false) { if ($file != '.' && $file != '..') { $dir = $dirName . DIRECTORY_SEPARATOR . $file; is_dir($dir) ? removeDir($dir) : unlink($dir); } } closedir($handle); $result = rmdir($dirName) ? true : false; return $result; }
public function update($event, $val = null) { switch ($event) { case Render::FINALIZE: $this->writeJsonIndex(); break; case Render::CHUNK: $this->flags = $val; break; case Render::STANDALONE: if ($val) { $this->registerElementMap(static::getDefaultElementMap()); $this->registerTextMap(static::getDefaultTextMap()); } break; case Render::INIT: $this->loadVersionAcronymInfo(); $this->setOutputDir(Config::output_dir() . strtolower($this->getFormatName()) . '/'); $this->postConstruct(); if (file_exists($this->getOutputDir())) { if (!is_dir($this->getOutputDir())) { v("Output directory is a file?", E_USER_ERROR); } } else { if (!mkdir($this->getOutputDir(), 0777, true)) { v("Can't create output directory", E_USER_ERROR); } } if ($this->getFormatName() == "PHP-Web") { if (!Config::no_toc() && is_dir($this->getOutputDir() . 'toc')) { removeDir($this->getOutputDir() . 'toc'); } if (!file_exists($this->getOutputDir() . "toc") || is_file($this->getOutputDir() . "toc")) { mkdir($this->getOutputDir() . "toc", 0777, true) or die("Can't create the toc directory"); } } if (Config::css()) { $this->fetchStylesheet(); } break; case Render::VERBOSE: v("Starting %s rendering", $this->getFormatName(), VERBOSE_FORMAT_RENDERING); break; } }
/** * Delete directory recursive. * * @param string $dir */ function removeDir($dir) { if (is_dir($dir)) { $dircontent = scandir($dir); foreach ($dircontent as $c) { if ($c != '.' && $c != '..' && is_dir($dir . '/' . $c)) { removeDir($dir . '/' . $c); } else { if ($c != '.' && $c != '..') { unlink($dir . '/' . $c); } } } rmdir($dir); } else { unlink($dir); } }
function removeDir($dirPath) { if (!is_dir($dirPath)) { throw new Exception("{$dirPath} must be a directory"); } if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') { $dirPath .= '/'; } $files = glob($dirPath . '*', GLOB_MARK); foreach ($files as $file) { if (is_dir($file)) { removeDir($file); } else { unlink($file); } } rmdir($dirPath); }
/** * @param $base */ function cleanPackages($base) { if ($dirs = @scandir($base)) { foreach ($dirs as $dir) { if (in_array($dir, array('.', '..'))) { continue; } $path = $base . $dir; if (is_dir($path)) { if (in_array($dir, array('tests', 'docs', 'gui'))) { removeDir($path); } else { cleanPackages($path . '/'); } } elseif (pathinfo($path, PATHINFO_EXTENSION) != 'php') { unlink($path); } } } }
echo <<<HTML <div class="big_board"><div class="board_title">爱特文管-系统警告</div></div> Hello,待处理文件为空! HTML; } else { echo <<<HTML <div class="big_board"><div class="board_title">删除文件-删除结果</div></div> <span class="true">■</span>删除成功 <span class="false">■</span>删除异常 HTML; $i = 0; while ($i < count($_SESSION['path'])) { echo <<<HTML <div class="big_board"><div class="board_title"></div></div> HTML; if (is_dir(_decode($_SESSION['path'][$i])) == true) { removeDir(_decode($_SESSION['path'][$i])); if (file_exists(_decode($_SESSION['path'][$i])) == false) { echo '[dir]<span class="true">' . _decode($_SESSION['path'][$i]) . '</span>'; } else { echo '[dir]<span class="false">' . _decode($_SESSION['path'][$i]) . '</span>'; } } if (is_file(_decode($_SESSION['path'][$i])) == true) { if (removeFile(_decode($_SESSION['path'][$i])) == true) { echo '[file]<span class="true">' . _decode($_SESSION['path'][$i]) . '</span>'; } else { echo '[file]<span class="false">' . _decode($_SESSION['path'][$i]) . '</span>'; } } $i++; }
function removeElements() { // Initialize the match $elements_removed = false; $elements_remove = array(); // Try to get the elements to remove foreach ($_POST as $post_key => $post_value) { // Is a safe file? if (preg_match('/^element_(.+)$/i', $post_key) && isSafe($post_value)) { // Update the marker $elements_removed = true; // Get the real path $post_element = JAPPIX_BASE . '/store/' . $post_value; // Remove the current element if (is_dir($post_element)) { removeDir($post_element); } else { if (file_exists($post_element)) { unlink($post_element); } } } } // Show a notification message if ($elements_removed) { echo '<p class="info smallspace success">' . T_("The selected elements have been removed.") . '</p>'; } else { echo '<p class="info smallspace fail">' . T_("You must select elements to remove!") . '</p>'; } }
public function RightColumnContent() { switch ($this->Action) { case 'view': $this->CheckIdExist(); $LakeModel = Db_Lake::getObjectDetails($this->Id); $this->TPL->assign('LakeModel', $LakeModel); $LakeTransModel = Db_LakeTrans::getObjectTransById($this->Id); $this->TPL->assign('LakeTransModel', $LakeTransModel); $LakeImageModel = Db_LakeImage::getObjectById($this->Id); $this->TPL->assign('LakeImageModel', $LakeImageModel); $LocationModel = Db_Location::getLocationByLakeIdAndLangId($this->Id, 2); $this->TPL->assign('LocationModel', $LocationModel); $LanguageModel = Db_Language::getLanguageWithKey(); $this->TPL->assign('LanguageModel', $LanguageModel); $LakeNearModelSelected = Db_LakeNear::getAllSelectedNearLakesById($this->Id); $this->TPL->assign('LakeNearModelSelected', $LakeNearModelSelected); break; case 'edit': $this->CheckIdExist(); $LakeModel = Db_Lake::getObjectDetails($this->Id); $this->TPL->assign('LakeModel', $LakeModel); $LakeTransModel = Db_LakeTrans::getObjectTransById($this->Id); $this->TPL->assign('LakeTransModel', $LakeTransModel); $LocationModel = Db_Location::getAllObjects(); $this->TPL->assign('LocationModel', $LocationModel); $LakeImageModel = Db_LakeImage::getObjectById($this->Id); $this->TPL->assign('LakeImageModel', $LakeImageModel); $LakeNearModelSelected = Db_LakeNear::getAllSelectedNearLakesById($this->Id); $this->TPL->assign('LakeNearModelSelected', $LakeNearModelSelected); $LakeNearModel = Db_LakeNear::getAllNearLakesById($this->Id); $this->TPL->assign('LakeNearModel', $LakeNearModel); $LanguageModel = Db_Language::getLanguageWithKey(); $this->TPL->assign('LanguageModel', $LanguageModel); break; case 'delete': if ($this->Id != 0) { Db_Lake::deleteByField('id', $this->Id, 1); Db_LakeImage::deleteByField('li_lake_id', $this->Id); Db_LakeNear::deleteByField('ln_lake_id', $this->Id); Db_LakeTrans::deleteByField('lt_lake_id', $this->Id, 3); if (is_dir(BASE_PATH . $this->imageFolderPath . $this->Id)) { removeDir(BASE_PATH . $this->imageFolderPath . $this->Id); } $this->Msg->SetMsg($this->_T('success_item_deleted')); $this->Redirect($this->PageUrl); } break; case 'deletefromlake': $LakeImageItem = Db_LakeImage::getObjectDetails($this->Id); if (!empty($LakeImageItem) && !empty($LakeImageItem->li_img_name)) { Upload::deleteImage(BASE_PATH . $this->imageFolderPath . '/' . $LakeImageItem->li_lake_id . '/images/', $LakeImageItem->li_img_name, $this->imageSizes); $result = Db_LakeImage::deleteByField('id', $this->Id, 1); } if ($result) { die($this->Id); } else { die('error'); } break; case 'add': $this->LakeModel = Db_Lake::getObjectDetails($this->Id); $this->TPL->assign('LakeModel', $this->LakeModel); $this->LakeTransModel = Db_LakeTrans::getObjectTransById($this->Id); $this->TPL->assign('LakeTransModel', $this->LakeTransModel); $LocationModel = Db_Location::getAllObjects(); $this->TPL->assign('LocationModel', $LocationModel); $LakeNearModel = Db_Lake::getAllAvailableLakesById($this->Id); $this->TPL->assign('LakeNearModel', $LakeNearModel); $LakeNearSelectedModel = Db_LakeNear::getAllNearLakesById($this->Id); $this->TPL->assign('LakeNearSelectedModel', $LakeNearSelectedModel); $LanguageModel = Db_Language::getLanguageWithKey(); $this->TPL->assign('LanguageModel', $LanguageModel); break; case 'save': if ($this->Id != 0) { $this->CheckIdExist(); } /* Variables for Lake =======================================*/ $l_location = $this->getPost('l_location'); $l_location_lat = $this->getPost('l_location_lat'); $l_location_lng = $this->getPost('l_location_lng'); $l_price_rod = $this->getPost('l_price_rod', 'float'); $l_price_fider = $this->getPost('l_price_fider', 'float'); $l_price = $this->getPost('l_price'); $l_site = $this->getPost('l_site'); $l_video = stripslashes($this->getPost('l_video', 'any', true)); $l_date = date(DATE_FORMAT_USER); $l_link = $this->getPost('l_link'); $l_published = $this->getPost('l_published') ? 1 : 0; $l_approved = $this->getPost('l_approved') ? 1 : 0; $l_recommended = $this->getPost('l_recommended') ? 1 : 0; $l_f_restrict = $this->getPost('l_fishing_restrict') ? 1 : 0; /* Variables for LakeTrans ===================================*/ $lt_title = $this->getPost('lt_title'); $lt_desc = $this->getPost('lt_desc'); /* Validate form =============================================*/ if (!$lt_title[2]) { $this->Msg->SetMsg($this->_T('error_mandatory_fields')); $this->Msg->SetError(true); if ($this->Id != 0) { $this->Redirect($this->PageUrl . '?action=edit&id=' . $this->Id); } else { $this->Redirect($this->PageUrl . '?action=add'); } } /* Perform link */ if ($l_link) { $l_link = Utils::FilterURL($l_link); $LinkModel = Db_Lake::checkLinkUniqueness($l_link, $this->Id); if (!empty($LinkModel)) { $this->Msg->SetMsg($this->_T('error_link_uniqueness')); $this->Msg->SetError(true); if ($this->Id != 0) { $this->Redirect($this->PageUrl . '?action=edit&id=' . $this->Id); } else { $this->Redirect($this->PageUrl . '?action=add'); } } } else { $l_link = Utils::FilterURL($lt_title[2]); } /* Save data into Lake table */ $this->LakeModel = new Db_Lake($this->DB, $this->Id, 'id'); $this->LakeModel->l_location = $l_location; $this->LakeModel->l_location_lat = $l_location_lat; $this->LakeModel->l_location_lng = $l_location_lng; $this->LakeModel->l_price_rod = $l_price_rod; $this->LakeModel->l_price_fider = $l_price_fider; $this->LakeModel->l_price = $l_price; $this->LakeModel->l_site = $l_site; $this->LakeModel->l_date = $l_date; $this->LakeModel->l_link = $l_link; $this->LakeModel->l_published = $l_published; $this->LakeModel->l_approved = $l_approved; $this->LakeModel->l_recommended = $l_recommended; $this->LakeModel->l_fishing_restrict = $l_f_restrict; if (!empty($l_video)) { $this->LakeModel->l_video = $l_video; } $this->LakeModel->save(); $lake_id = $this->LakeModel->id; $img_link_slider = BASE_PATH . $this->imageFolderPath . $lake_id . '/slider/'; $img_link_main = BASE_PATH . $this->imageFolderPath . $lake_id . '/main/'; $l_img_slider = ''; if (isset($_FILES['l_img_slider']) && $_FILES['l_img_slider']['error'] == 0) { if (is_dir($img_link_slider)) { removeDir($img_link_slider); } $l_img_slider = Upload::uploadImage($img_link_slider, $_FILES['l_img_slider'], 'slider', $this->imageSizes); $this->LakeModel->updateSliderImage($lake_id, $l_img_slider); } if (isset($_FILES['l_img_main']) && $_FILES['l_img_main']['error'] == 0) { if (is_dir($img_link_main)) { removeDir($img_link_main); } $l_img_main = Upload::uploadImage($img_link_main, $_FILES['l_img_main'], 'main', $this->imageSizes); $this->LakeModel->updateMainImage($lake_id, $l_img_main); } /* Save data into LakeTrans table */ $lake_id = $this->LakeModel->id; foreach ($lt_title as $langid => $value) { $this->LakeTransModel = new Db_LakeTrans(); $this->LakeTransModel->findByFields(array('lt_lake_id' => $lake_id, 'lt_lang_id' => $langid)); $this->LakeTransModel->lt_lake_id = $lake_id; $this->LakeTransModel->lt_title = $lt_title[$langid]; $this->LakeTransModel->lt_desc = $lt_desc[$langid]; $this->LakeTransModel->lt_lang_id = $langid; $this->LakeTransModel->save(); } /* Variables for LakeNear ====================================*/ $ln_lake_near_id = $this->getPost('ln_lake_near_id'); Db_LakeNear::deleteAllById($this->Id); foreach ($ln_lake_near_id as $lake_near_id) { $LakeNear = new Db_LakeNear($this->DB, $this->Id, 'id'); $LakeNear->ln_lake_id = $this->LakeModel->id; $LakeNear->ln_lake_near_id = $lake_near_id; $LakeNear->save(); } /* Save images */ $img_priority = $this->getPost('img_priority'); $imgs_link = BASE_PATH . $this->imageFolderPath . $lake_id . '/images/'; if (isset($_FILES['li_image'])) { $gallery = fixFilesArray($_FILES['li_image']); array_pop($gallery); $imageNames = array(); foreach ($gallery as $index => $value) { $imageNames[$index] = Upload::uploadImage($imgs_link, $gallery[$index], 'comment_image', $this->imageSizes); } foreach ($imageNames as $index => $value) { if (!empty($value)) { $newLakeImage = new Db_LakeImage($this->DB); $newLakeImage->li_lake_id = $this->LakeModel->id; $newLakeImage->li_img_name = $value; $newLakeImage->li_priority = $img_priority[$index] ? '0' : $img_priority[$index]; $newLakeImage->save(); } } } $this->Msg->SetMsg($this->_T('success_item_saved')); $this->Redirect($this->PageUrl . '?action=view&id=' . $this->LakeModel->id); break; default: $Objects = Db_Lake::getAllObjects(); $ObjectsTrans = Db_LakeTrans::getObjectsTrans($this->LangId); $ListGrid = false; if ($Objects) { $ListGrid = new TGrid(); $ListGrid->Spacing = 0; $ListGrid->Width = '100%'; $ListGrid->SetClass('table table-bordered table-highlight-head'); $ListGrid->AddHeaderRow($this->_T('id'), $this->_T('title'), $this->_T('price_rod'), $this->_T('price_fiber'), $this->_T('site'), $this->_T('published'), $this->_T('field_approved'), $this->_T('actions')); $ListGrid->BeginBody(); foreach ($Objects as $Object) { $Grid_TR = new TGrid_TTR(); $Grid_TD = new TGrid_TTD($Object['id'] . ' ( <a href="' . $this->PageUrl . '?action=view&id=' . $Object['id'] . '">' . $this->_T('see') . '</a> )'); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD(isset($ObjectsTrans[$Object['id']]['lt_title']) ? $ObjectsTrans[$Object['id']]['lt_title'] : ''); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD($Object['l_price_rod']); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD($Object['l_price_fider']); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD($Object['l_site']); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD($Object['l_published'] == 1 ? $this->_T('yes') : $this->_T('no')); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD($Object['l_approved'] == 1 ? $this->_T('yes') : $this->_T('no')); $Grid_TR->Add($Grid_TD); $Grid_TD = new TGrid_TTD(' <a class="bs-tooltip" title="" href="' . $this->PageUrl . '?action=edit&id=' . $Object['id'] . '" data-original-title="' . $this->_T('edit') . '"><i class="icon-pencil"></i></a> <a class="bs-tooltip confirm-dialog" data-text="' . _T('sure_you_want_to_delete') . '" title="" href="' . $this->PageUrl . '?action=delete&id=' . $Object['id'] . '" data-original-title="' . $this->_T('delete') . '"><i class="icon-trash"></i></a> '); $Grid_TD->AddAttr(new TAttr('class', 'align-center')); $Grid_TR->Add($Grid_TD); $ListGrid->AddTR($Grid_TR); } $ListGrid->EndBody(); $ListGrid = $ListGrid->Html(); } $this->TPL->assign('ListGrid', $ListGrid); break; } $msg = $this->Msg->Html(); $this->TPL->assign('msg', $msg); $this->TPL->assign('Action', $this->Action); $result = $this->TPL->display(null, true); $this->Msg->Clear(); return $result; }
if (is_writeable(BASEDIR . '/load/files')) { $folder = $downs['folder'] ? $downs['folder'] . '/' : ''; $querydel = DB::run()->query("SELECT `downs_link`, `downs_screen` FROM `downs` WHERE `downs_cats_id`=?;", array($cid)); $arr_script = $querydel->fetchAll(); DB::run()->query("DELETE FROM `commload` WHERE `commload_cats`=?;", array($cid)); DB::run()->query("DELETE FROM `downs` WHERE `downs_cats_id`=?;", array($cid)); DB::run()->query("DELETE FROM `cats` WHERE `cats_id`=?;", array($cid)); foreach ($arr_script as $delfile) { if (!empty($delfile['downs_link']) && file_exists(BASEDIR . '/load/files/' . $folder . $delfile['downs_link'])) { unlink(BASEDIR . '/load/files/' . $folder . $delfile['downs_link']); } unlink_image('load/screen/' . $folder, $delfile['downs_screen']); } if (!empty($folder)) { removeDir(BASEDIR . '/load/files/' . $folder); removeDir(BASEDIR . '/load/screen/' . $folder); } notice('Раздел успешно удален!'); redirect("load.php"); } else { show_error('Ошибка! Не установлены атрибуты доступа на дирекоторию с файлами!'); } } else { show_error('Ошибка! Данный раздел имеет подкатегории!'); } } else { show_error('Ошибка! Данного раздела не существует!'); } } else { show_error('Ошибка! Неверный идентификатор сессии, повторите действие!'); }
function create_restored_course(&$tool_content, $restoreThis, $course_code, $course_lang, $course_title, $course_desc, $course_vis, $course_prof) { global $webDir, $urlServer, $urlAppend, $langEnter, $langBack, $currentCourseCode; require_once 'modules/create_course/functions.php'; require_once 'modules/course_info/restorehelper.class.php'; require_once 'include/lib/fileManageLib.inc.php'; $new_course_code = null; $new_course_id = null; Database::get()->transaction(function() use (&$new_course_code, &$new_course_id, $restoreThis, $course_code, $course_lang, $course_title, $course_desc, $course_vis, $course_prof, $webDir, &$tool_content, $urlServer, $urlAppend) { $departments = array(); if (isset($_POST['department'])) { foreach ($_POST['department'] as $did) { $departments[] = intval($did); } } else { $minDep = Database::get()->querySingle("SELECT MIN(id) AS min FROM hierarchy"); if ($minDep) { $departments[0] = $minDep->min; } } $r = $restoreThis . '/html'; list($new_course_code, $new_course_id) = create_course($course_code, $course_lang, $course_title, $course_desc, $departments, $course_vis, $course_prof); if (!$new_course_code) { $tool_content = "<div class='alert alert-warning'>" . $GLOBALS['langError'] . "</div>"; draw($tool_content, 3); exit; } if (!file_exists($restoreThis)) { redirect_to_home_page('modules/course_info/restore_course.php'); } $config_data = unserialize(file_get_contents($restoreThis . '/config_vars')); // If old $urlAppend didn't end in /, add it if (substr($config_data['urlAppend'], -1) !== '/') { $config_data['urlAppend'] .= '/'; } $eclass_version = (isset($config_data['version'])) ? $config_data['version'] : null; $backupData = null; if (file_exists($restoreThis . '/backup.php')) { $backupData = parse_backup_php($restoreThis . '/backup.php'); $eclass_version = $backupData['eclass_version']; } $restoreHelper = new RestoreHelper($eclass_version); $course_file = $restoreThis . '/' . $restoreHelper->getFile('course'); if (file_exists($course_file)) { $course_dataArr = unserialize(file_get_contents($course_file)); $course_data = $course_dataArr[0]; // update course query $upd_course_sql = "UPDATE course SET keywords = ?s, doc_quota = ?f, video_quota = ?f, " . " group_quota = ?f, dropbox_quota = ?f, glossary_expand = ?d "; $upd_course_args = array( $course_data[$restoreHelper->getField('course', 'keywords')], floatval($course_data['doc_quota']), floatval($course_data['video_quota']), floatval($course_data['group_quota']), floatval($course_data['dropbox_quota']), intval($course_data[$restoreHelper->getField('course', 'glossary_expand')]) ); if (isset($course_data['home_layout']) and isset($course_data['course_image'])) { $upd_course_sql .= ', home_layout = ?d, course_image = ?s '; $upd_course_args[] = $course_data['home_layout']; $upd_course_args[] = $course_data['course_image']; } // Set keywords to '' if NULL if (!isset($upd_course_args[0])) { $upd_course_args[0] = ''; } // handle course weekly if exists if (isset($course_data['view_type']) && isset($course_data['start_date']) && isset($course_data['finish_date'])) { $upd_course_sql .= " , view_type = ?s, start_date = ?t, finish_date = ?t "; array_push($upd_course_args, $course_data['view_type'], $course_data['start_date'], $course_data['finish_date'] ); } $upd_course_sql .= " WHERE id = ?d "; array_push($upd_course_args, intval($new_course_id)); Database::get()->query($upd_course_sql, $upd_course_args); } $userid_map = array(); $user_file = $restoreThis . '/user'; if (file_exists($user_file)) { $cours_user = unserialize(file_get_contents($restoreThis . '/' . $restoreHelper->getFile('course_user'))); $userid_map = restore_users(unserialize(file_get_contents($user_file)), $cours_user, $departments, $restoreHelper); register_users($new_course_id, $userid_map, $cours_user, $restoreHelper); } $userid_map[0] = 0; $userid_map[-1] = -1; $coursedir = "${webDir}/courses/$new_course_code"; $videodir = "${webDir}/video/$new_course_code"; move_dir($r, $coursedir); if (is_dir($restoreThis . '/video_files')) { move_dir($restoreThis . '/video_files', $videodir); } course_index($new_course_code); $tool_content .= "<div class='alert alert-info'>" . $GLOBALS['langCopyFiles'] . " $coursedir</div>"; require_once 'upgrade/functions.php'; load_global_messages(); $url_prefix_map = array( $config_data['urlServer'] . 'modules/ebook/show.php/' . $course_data['code'] => $urlServer . 'modules/ebook/show.php/' . $new_course_code, $config_data['urlAppend'] . 'modules/ebook/show.php/' . $course_data['code'] => $urlAppend . 'modules/ebook/show.php/' . $new_course_code, $config_data['urlServer'] . 'modules/document/file.php/' . $course_data['code'] => $urlServer . 'modules/document/file.php/' . $new_course_code, $config_data['urlAppend'] . 'modules/document/file.php/' . $course_data['code'] => $urlAppend . 'modules/document/file.php/' . $new_course_code, $config_data['urlServer'] . 'courses/' . $course_data['code'] => $urlServer . 'courses/' . $new_course_code, $config_data['urlAppend'] . 'courses/' . $course_data['code'] => $urlAppend . 'courses/' . $new_course_code, $course_data['code'] => $new_course_code); if ($restoreHelper->getBackupVersion() === RestoreHelper::STYLE_3X) { restore_table($restoreThis, 'course_module', array('set' => array('course_id' => $new_course_id), 'delete' => array('id')), $url_prefix_map, $backupData, $restoreHelper); } else if ($restoreHelper->getBackupVersion() === RestoreHelper::STYLE_2X) { create_modules($new_course_id); foreach (get_tabledata_from_parsed('accueil', $backupData, $restoreHelper) as $accueil) { Database::get()->query('UPDATE course_module SET visible = ?d WHERE course_id = ?d AND module_id = ?d', $accueil['visible'], $new_course_id, $accueil['id']); } } restore_table($restoreThis, 'announcement', array('set' => array('course_id' => $new_course_id), 'delete' => array('id', 'preview')), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'group_properties', array('set' => array('course_id' => $new_course_id)), $url_prefix_map, $backupData, $restoreHelper); $group_map = restore_table($restoreThis, 'group', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'group_members', array('map' => array('group_id' => $group_map, 'user_id' => $userid_map)), $url_prefix_map, $backupData, $restoreHelper); // Forums Restore $forum_category_map = restore_table($restoreThis, 'forum_category', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $forum_category_map[0] = 0; $forum_map = restore_table($restoreThis, 'forum', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id', 'map' => array('cat_id' => $forum_category_map)), $url_prefix_map, $backupData, $restoreHelper); $forum_map[0] = 0; $forum_topic_map = restore_table($restoreThis, 'forum_topic', array('return_mapping' => 'id', 'map' => array('forum_id' => $forum_map, 'poster_id' => $userid_map)), $url_prefix_map, $backupData, $restoreHelper); $forum_topic_map[0] = 0; $forum_post_options = array('return_mapping' => 'id', 'map' => array('topic_id' => $forum_topic_map, 'poster_id' => $userid_map)); if ($restoreHelper->getBackupVersion() === RestoreHelper::STYLE_2X) { $forum_post_options['set'] = array('post_text' => ''); } $forum_post_map = restore_table($restoreThis, 'forum_post', $forum_post_options, $url_prefix_map, $backupData, $restoreHelper); $forum_post_map[0] = 0; restore_table($restoreThis, 'forum_notify', array('set' => array('course_id' => $new_course_id), 'map' => array('user_id' => $userid_map, 'cat_id' => $forum_category_map, 'forum_id' => $forum_map, 'topic_id' => $forum_topic_map), 'delete' => array('id')), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'forum_user_stats', array('set' => array('course_id' => $new_course_id), 'map' => array('user_id' => $userid_map)), $url_prefix_map, $backupData, $restoreHelper); if ($restoreHelper->getBackupVersion() === RestoreHelper::STYLE_2X && isset($backupData) && is_array($backupData) && isset($backupData['query']) && is_array($backupData['query'])) { $postsText = get_tabledata_from_parsed('posts_text', $backupData, $restoreHelper); foreach ($postsText as $ptData) { if (array_key_exists($ptData['post_id'], $forum_post_map)) { Database::get()->query("UPDATE forum_post SET post_text = ?s WHERE id = ?d", $ptData['post_text'], intval($forum_post_map[$ptData['post_id']])); } } } $forumLastPosts = Database::get()->queryArray("SELECT DISTINCT last_post_id FROM forum WHERE course_id = ?d ", intval($new_course_id)); if (is_array($forumLastPosts) && count($forumLastPosts) > 0) { foreach ($forumLastPosts as $lastPost) { if (isset($forum_post_map[$lastPost->last_post_id])) { Database::get()->query("UPDATE forum SET last_post_id = ?d WHERE course_id = ?d AND last_post_id = ?d", intval($forum_post_map[$lastPost->last_post_id]), intval($new_course_id), intval($lastPost->last_post_id)); } } } $topicLastPosts = Database::get()->queryArray("SELECT DISTINCT last_post_id FROM forum_topic WHERE forum_id IN (SELECT id FROM forum WHERE course_id = ?d)", intval($new_course_id)); if (is_array($topicLastPosts) && count($topicLastPosts) > 0) { foreach ($topicLastPosts as $lastPost) { if (isset($forum_post_map[$lastPost->last_post_id])) { Database::get()->query("UPDATE forum_topic SET last_post_id = ?d WHERE last_post_id = ?d", intval($forum_post_map[$lastPost->last_post_id]), intval($lastPost->last_post_id)); } } } $parentPosts = Database::get()->queryArray("SELECT DISTINCT parent_post_id FROM forum_post WHERE topic_id IN (SELECT id FROM forum_topic WHERE forum_id IN (SELECT id FROM forum WHERE course_id = ?d))", intval($new_course_id)); if (is_array($parentPosts) && count($parentPosts) > 0) { foreach ($parentPosts as $parentPost) { if (isset($forum_post_map[$parentPost->parent_post_id])) { Database::get()->query("UPDATE forum_post SET parent_post_id = ?d WHERE parent_post_id = ?d", intval($forum_post_map[$parentPost->parent_post_id]), intval($parentPost->parent_post_id)); } } } // Forums Restore End // Glossary Restore $glossary_category_map = restore_table($restoreThis, 'glossary_category', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $glossary_category_map[0] = 0; restore_table($restoreThis, 'glossary', array('set' => array('course_id' => $new_course_id), 'delete' => array('id'), 'map' => array('category_id' => $glossary_category_map)), $url_prefix_map, $backupData, $restoreHelper); // Glossary Restore End $link_category_map = restore_table($restoreThis, 'link_category', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $link_category_map[0] = 0; $link_category_map[-1] = -1; $link_category_map[-2] = -2; $link_map = restore_table($restoreThis, 'link', array('set' => array('course_id' => $new_course_id), 'map' => array('category' => $link_category_map, 'user_id' => $userid_map), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $ebook_map = restore_table($restoreThis, 'ebook', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); foreach ($ebook_map as $old_id => $new_id) { // new and old id might overlap as the map contains multiple values! rename("$coursedir/ebook/$old_id", "$coursedir/ebook/__during_restore__$new_id"); } foreach ($ebook_map as $old_id => $new_id) { // better to use an intermediary rename step rename("$coursedir/ebook/__during_restore__$new_id", "$coursedir/ebook/$new_id"); } $document_map = restore_table($restoreThis, 'document', array('set' => array('course_id' => $new_course_id), 'map_function' => 'document_map_function', 'map_function_data' => array(1 => $group_map, 2 => $ebook_map), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $ebook_section_map = restore_table($restoreThis, 'ebook_section', array('map' => array('ebook_id' => $ebook_map), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $ebook_subsection_map = restore_table($restoreThis, 'ebook_subsection', array('map' => array('section_id' => $ebook_section_map, 'file_id' => $document_map), 'delete' => array('file'), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); // Video $videocat_map = restore_table($restoreThis, 'video_category', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $videocat_map[''] = ''; $videocat_map[0] = 0; $video_map = restore_table($restoreThis, 'video', array( 'map' => array('category' => $videocat_map), 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); $videolink_map = restore_table($restoreThis, 'videolink', array( 'map' => array('category' => $videocat_map), 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); // Dropbox $dropbox_map = restore_table($restoreThis, 'dropbox_msg', array('set' => array('course_id' => $new_course_id), 'map' => array('author_id' => $userid_map), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'dropbox_attachment', array('map' => array('msg_id' => $dropbox_map), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'dropbox_index', array('map' => array('msg_id' => $dropbox_map, 'recipient_id' => $userid_map)), $url_prefix_map, $backupData, $restoreHelper); // Learning Path $lp_learnPath_map = restore_table($restoreThis, 'lp_learnPath', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'learnPath_id'), $url_prefix_map, $backupData, $restoreHelper); $lp_module_map = restore_table($restoreThis, 'lp_module', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'module_id'), $url_prefix_map, $backupData, $restoreHelper); $lp_asset_map = restore_table($restoreThis, 'lp_asset', array('map' => array('module_id' => $lp_module_map), 'return_mapping' => 'asset_id'), $url_prefix_map, $backupData, $restoreHelper); // update lp_module startAsset_id with new asset_id from map foreach ($lp_asset_map as $key => $value) { Database::get()->query("UPDATE lp_module SET `startAsset_id` = ?d " . "WHERE `course_id` = ?d " . "AND `startAsset_id` = ?d", intval($value), intval($new_course_id), intval($key)); } $lp_rel_learnPath_module_map = restore_table($restoreThis, 'lp_rel_learnPath_module', array('map' => array('learnPath_id' => $lp_learnPath_map, 'module_id' => $lp_module_map), 'return_mapping' => 'learnPath_module_id'), $url_prefix_map, $backupData, $restoreHelper); // update parent foreach ($lp_rel_learnPath_module_map as $key => $value) { Database::get()->query("UPDATE lp_rel_learnPath_module SET `parent` = ?d " . "WHERE `learnPath_id` IN (SELECT learnPath_id FROM lp_learnPath WHERE course_id = ?d) " . "AND `parent` = ?d", intval($value), intval($new_course_id), intval($key)); } restore_table($restoreThis, 'lp_user_module_progress', array('delete' => array('user_module_progress_id'), 'map' => array('user_id' => $userid_map, 'learnPath_module_id' => $lp_rel_learnPath_module_map, 'learnPath_id' => $lp_learnPath_map)), $url_prefix_map, $backupData, $restoreHelper); foreach ($lp_learnPath_map as $old_id => $new_id) { // new and old id might overlap as the map contains multiple values! $old_dir = "$coursedir/scormPackages/path_$old_id"; if (file_exists($old_dir) && is_dir($old_dir)) { rename($old_dir, "$coursedir/scormPackages/__during_restore__$new_id"); } } foreach ($lp_learnPath_map as $old_id => $new_id) { // better to use an intermediary rename step $tempLPDir = "$coursedir/scormPackages/__during_restore__$new_id"; if (file_exists($tempLPDir) && is_dir($tempLPDir)) { rename($tempLPDir, "$coursedir/scormPackages/path_$new_id"); } } // Wiki $wiki_map = restore_table($restoreThis, 'wiki_properties', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'wiki_acls', array('map' => array('wiki_id' => $wiki_map)), $url_prefix_map, $backupData, $restoreHelper); $wiki_pages_map = restore_table($restoreThis, 'wiki_pages', array('map' => array('wiki_id' => $wiki_map, 'owner_id' => $userid_map), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'wiki_pages_content', array('delete' => array('id'), 'map' => array('pid' => $wiki_pages_map, 'editor_id' => $userid_map)), $url_prefix_map, $backupData, $restoreHelper); // Blog if (file_exists("$restoreThis/blog_post")) { $blog_map = restore_table($restoreThis, 'blog_post', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); } // Comments if (file_exists("$restoreThis/comments")) { $comment_map = restore_table($restoreThis, 'comments', array('delete' => array('id'), 'map' => array('user_id' => $userid_map), 'map_function' => 'comments_map_function', 'map_function_data' => array($blog_map, $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); } //Abuse Report if (file_exists("$restoreThis/abuse_report")) { restore_table($restoreThis, 'abuse_report', array('delete' => array('id'), 'set' => array('course_id' => $new_course_id), 'map' => array('user_id' => $userid_map), 'map_function' => 'abuse_report_map_function', 'map_function_data' => array($forum_post_map, $comment_map, $link_map)), $url_prefix_map, $backupData, $restoreHelper); } // Rating if (file_exists("$restoreThis/rating")) { restore_table($restoreThis, 'rating', array('delete' => array('rate_id'), 'map' => array('user_id' => $userid_map), 'map_function' => 'ratings_map_function', 'map_function_data' => array($blog_map, $forum_post_map, $link_map, $new_course_id)), $url_prefix_map, $backupData, $restoreHelper); } if (file_exists("$restoreThis/rating_cache")) { restore_table($restoreThis, 'rating_cache', array('delete' => array('rate_cache_id'), 'map_function' => 'ratings_map_function', 'map_function_data' => array($blog_map, $forum_post_map, $link_map, $new_course_id)), $url_prefix_map, $backupData, $restoreHelper); } // Course_settings if (file_exists("$restoreThis/course_settings")) { restore_table($restoreThis, 'course_settings', array('set' => array('course_id' => $new_course_id)), $url_prefix_map, $backupData, $restoreHelper); } // Polls $poll_map = restore_table($restoreThis, 'poll', array('set' => array('course_id' => $new_course_id), 'map' => array('creator_id' => $userid_map), 'return_mapping' => 'pid', 'delete' => array('type')), $url_prefix_map, $backupData, $restoreHelper); $poll_question_map = restore_table($restoreThis, 'poll_question', array('map' => array('pid' => $poll_map), 'return_mapping' => 'pqid'), $url_prefix_map, $backupData, $restoreHelper); $poll_answer_map = restore_table($restoreThis, 'poll_question_answer', array('map' => array('pqid' => $poll_question_map), 'return_mapping' => 'pqaid'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'poll_answer_record', array('delete' => array('arid'), 'map' => array('pid' => $poll_map, 'qid' => $poll_question_map, 'aid' => $poll_answer_map, 'user_id' => $userid_map)), $url_prefix_map, $backupData, $restoreHelper); // Assignments if (!isset($group_map[0])) { $group_map[0] = 0; } $assignments_map = restore_table($restoreThis, 'assignment', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); $assignments_map[0] = 0; restore_table($restoreThis, 'assignment_submit', array('delete' => array('id'), 'map' => array('uid' => $userid_map, 'assignment_id' => $assignments_map, 'group_id' => $group_map)), $url_prefix_map, $backupData, $restoreHelper); // Agenda $agenda_map = restore_table($restoreThis, 'agenda', array( 'return_mapping' => 'id', 'set' => array('course_id' => $new_course_id) ), $url_prefix_map, $backupData, $restoreHelper); $agenda_map[0] = 0; // Exercises $exercise_map = restore_table($restoreThis, 'exercise', array( 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); $exercise_map[0] = 0; restore_table($restoreThis, 'exercise_user_record', array( 'delete' => array('eurid'), 'map' => array('eid' => $exercise_map, 'uid' => $userid_map) ), $url_prefix_map, $backupData, $restoreHelper); $question_category_map = restore_table($restoreThis, 'exercise_question_cats', array( 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'question_cat_id' ), $url_prefix_map, $backupData, $restoreHelper); $question_category_map[0] = 0; $question_map = restore_table($restoreThis, 'exercise_question', array( 'set' => array('course_id' => $new_course_id), 'init' => array('category' => 0), 'map' => array('category' => $question_category_map), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'exercise_answer', array( 'delete' => array('id'), 'map' => array('question_id' => $question_map) ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'exercise_answer_record', array( 'delete' => array('answer_record_id'), 'map' => array('question_id' => $question_map, 'eurid' => $userid_map) ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'exercise_with_questions', array( 'map' => array('question_id' => $question_map, 'exercise_id' => $exercise_map) ), $url_prefix_map, $backupData, $restoreHelper); $sql = "SELECT asset.asset_id, asset.path FROM `lp_module` AS module, `lp_asset` AS asset WHERE module.startAsset_id = asset.asset_id AND course_id = ?d AND contentType = 'EXERCISE' AND path <> '' AND path IS NOT NULL"; $rows = Database::get()->queryArray($sql, intval($new_course_id)); if (is_array($rows) && count($rows) > 0) { foreach ($rows as $row) { Database::get()->query("UPDATE `lp_asset` SET path = ?s WHERE asset_id = ?d", $exercise_map[$row->path], intval($row->asset_id)); } } // Attendance $attendance_map = restore_table($restoreThis, 'attendance', array( 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); $attendance_activities_map = restore_table($restoreThis, 'attendance_activities', array( 'map' => array('attendance_id' => $attendance_map), 'map_function' => 'attendance_gradebook_activities_map_function', 'map_function_data' => array($assignments_map, $exercise_map), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'attendance_book', array( 'map' => array( 'attendance_activity_id' => $attendance_activities_map, 'uid' => $userid_map ), 'delete' => array('id') ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'attendance_users', array( 'map' => array( 'attendance_id' => $attendance_map, 'uid' => $userid_map ), 'delete' => array('id') ), $url_prefix_map, $backupData, $restoreHelper); // Gradebook $gradebook_map = restore_table($restoreThis, 'gradebook', array( 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); $gradebook_activities_map = restore_table($restoreThis, 'gradebook_activities', array( 'map' => array('gradebook_id' => $gradebook_map), 'map_function' => 'attendance_gradebook_activities_map_function', 'map_function_data' => array($assignments_map, $exercise_map), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'gradebook_book', array( 'map' => array( 'gradebook_activity_id' => $gradebook_activities_map, 'uid' => $userid_map ), 'delete' => array('id') ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'gradebook_users', array( 'map' => array( 'gradebook_id' => $gradebook_map, 'uid' => $userid_map ), 'delete' => array('id') ), $url_prefix_map, $backupData, $restoreHelper); // Notes restore_table($restoreThis, 'note', array( 'set' => array('reference_obj_course' => $new_course_id), 'map' => array('user_id' => $userid_map), 'map_function' => 'notes_map_function', 'map_function_data' => array($new_course_id, $agenda_map, $document_map, $link_map, $video_map, $videolink_map, $assignments_map, $exercise_map, $ebook_map, $lp_learnPath_map), 'delete' => array('id') ), $url_prefix_map, $backupData, $restoreHelper); // Units $unit_map = restore_table($restoreThis, 'course_units', array('set' => array('course_id' => $new_course_id), 'return_mapping' => 'id'), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'unit_resources', array('delete' => array('id'), 'map' => array('unit_id' => $unit_map), 'map_function' => 'unit_map_function', 'map_function_data' => array($document_map, $link_category_map, $link_map, $ebook_map, $ebook_section_map, $ebook_subsection_map, $video_map, $videolink_map, $lp_learnPath_map, $wiki_map, $assignments_map, $exercise_map, $forum_map, $forum_topic_map) ), $url_prefix_map, $backupData, $restoreHelper); // Weekly $weekly_map = restore_table($restoreThis, 'course_weekly_view', array( 'set' => array('course_id' => $new_course_id), 'return_mapping' => 'id' ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'course_weekly_view_activities', array( 'delete' => array('id'), 'map' => array('course_weekly_view_id' => $weekly_map), 'map_function' => 'unit_map_function', 'map_function_data' => array($document_map, $link_category_map, $link_map, $ebook_map, $ebook_section_map, $ebook_subsection_map, $video_map, $videolink_map, $lp_learnPath_map, $wiki_map, $assignments_map, $exercise_map, $forum_map, $forum_topic_map) ), $url_prefix_map, $backupData, $restoreHelper); restore_table($restoreThis, 'course_description', array( 'set' => array('course_id' => $new_course_id), 'delete' => array('id') ), $url_prefix_map, $backupData, $restoreHelper); removeDir($restoreThis); // index course after restoring require_once 'modules/search/indexer.class.php'; Indexer::queueAsync(Indexer::REQUEST_REMOVEALLBYCOURSE, Indexer::RESOURCE_IDX, $new_course_id); Indexer::queueAsync(Indexer::REQUEST_STOREALLBYCOURSE, Indexer::RESOURCE_IDX, $new_course_id); }); // check/cleanup video files after restore transaction if ($new_course_code != null && $new_course_id != null) { $videodir = $webDir . "/video/" . $new_course_code; $videos = scandir($videodir); foreach ($videos as $videofile) { if (is_dir($videofile)) { continue; } $vlike = '/' . $videofile; if (!isWhitelistAllowed($videofile)) { unlink($videodir . "/" . $videofile); Database::get()->query("DELETE FROM `video` WHERE course_id = ?d AND path LIKE ?s", $new_course_id, $vlike); continue; } $vcnt = Database::get()->querySingle("SELECT count(id) AS count FROM `video` WHERE course_id = ?d AND path LIKE ?s", $new_course_id, $vlike)->count; if ($vcnt <= 0) { unlink($videodir . "/" . $videofile); } } $backUrl = $urlAppend . (isset($currentCourseCode)? "courses/$currentCourseCode/": 'modules/admin/'); $tool_content .= action_bar(array( array('title' => $langEnter, 'url' => $urlAppend . "courses/$new_course_code/", 'icon' => 'fa-arrow-right', 'level' => 'primary-label', 'button-class' => 'btn-success'), array('title' => $langBack, 'url' => $backUrl, 'icon' => 'fa-reply', 'level' => 'primary-label')), false); } }
function completeDelete($data) { $CI =& get_instance(); if (file_exists(__DATABASE_CONFIG_PATH__ . '/' . $CI->db->database . '/' . sha1('com_' . $_GET['key']['crud_components.id']))) { removeDir(__DATABASE_CONFIG_PATH__ . '/' . $CI->db->database . '/' . sha1('com_' . $_GET['key']['crud_components.id'])); } return $data; }
} if ($_GET["des"] == "add") { echo add_edit(); } if ($_GET["des"] == "del") { $sql = "SELECT * FROM newstbl LEFT JOIN catbl ON newstbl.id_cat = catbl.id_cat WHERE id=" . $_GET["id"] . ""; $qur = mysql_query($sql); $kol = mysql_num_rows($qur); if ($qur && $kol) { $rez = mysql_fetch_assoc($qur); function removeDir($path) { return is_file($path) ? unlink($path) : array_map('removeDir', glob($path . "/*")) == rmdir($path); } $path = "../../../hardware/" . $rez["title_cat"] . "/" . $_GET["id"] . "/"; removeDir($path); } $sql = "DELETE FROM newstbl WHERE id=" . $_GET["id"] . " LIMIT 1"; $qur = mysql_query($sql); echo show(); } } else { echo show(); } ?> </section> </div> </div> </div> </div> </body></html>
function removeDir($src) { if (is_dir($src) === true) { $handle = opendir($src); while ($entry = readdir($handle)) { if ($entry === '.' || $entry === '..') { continue; } removeDir("{$src}/{$entry}"); } rmdir($src); closedir($handle); } else { unlink($src); } }