/** * Enables deletion of directory if not empty * @access public * @param string $dir the directory to delete * @return boolean whether the deletion was successful * @author Joel Kronenberg */ public static function clr_dir($dir) { if (!($opendir = @opendir($dir))) { return false; } while (($readdir = readdir($opendir)) !== false) { if ($readdir !== '..' && $readdir !== '.') { $readdir = trim($readdir); clearstatcache(); /* especially needed for Windows machines: */ if (is_file($dir . '/' . $readdir)) { if (!@unlink($dir . '/' . $readdir)) { return false; } } else { if (is_dir($dir . '/' . $readdir)) { /* calls itself to clear subdirectories */ if (!FileUtility::clr_dir($dir . '/' . $readdir)) { return false; } } } } } /* end while */ @closedir($opendir); if (!@rmdir($dir)) { return false; } return true; }
exit; } //Get the XML file out and start importing them into our database. //TODO: See question_import.php 287-289. $qti_import = new QTIImport($import_path); $qids = $qti_import->importQuestions($attributes); //import test $tid = $qti_import->importTest(); //associate question and tests foreach ($qids as $order => $qid) { if (isset($qti_import->weights[$order])) { $weight = round($qti_import->weights[$order]); } else { $weight = 0; } $new_order = $order + 1; // $sql = "INSERT INTO " . TABLE_PREFIX . "tests_questions_assoc" . // "(test_id, question_id, weight, ordering, required) " . // "VALUES ($tid, $qid, $weight, $new_order, 0)"; // $result = mysql_query($sql, $db); $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO(); $testsQuestionsAssocDAO->Create($tid, $qid, $weight, $new_order); } //debug('imported test'); if (!$msg->containsErrors()) { $msg->addFeedback('IMPORT_SUCCEEDED'); } //clear directory FileUtility::clr_dir(TR_CONTENT_DIR . 'import/' . $_course_id); header('Location: index.php?_course_id=' . $_course_id); exit;
$result = true; for ($i = 0; $i < $count; $i++) { $filename = $checkbox[$i]; if (strpos($filename, '..') !== false) { $msg->addError('UNKNOWN'); $result = false; header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'framed=' . $_POST['framed'] . SEP . 'popup=' . $_POST['popup'] . SEP . 'cp=' . $_POST['cp'] . SEP . 'cid=' . $_POST['cid'] . SEP . 'pid=' . $_POST['pid'] . SEP . 'a_type=' . $_POST['a_type'] . SEP . '_course_id=' . $_course_id); exit; } else { if (!is_dir($current_path . $pathext . $filename)) { $msg->addError(array('DIR_NOT_DELETED', $filename)); $result = false; header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'framed=' . $_POST['framed'] . SEP . 'popup=' . $_POST['popup'] . SEP . 'cp=' . $_POST['cp'] . SEP . 'cid=' . $_POST['cid'] . SEP . 'pid=' . $_POST['pid'] . SEP . 'a_type=' . $_POST['a_type'] . SEP . '_course_id=' . $_course_id); exit; } else { if (!($result = FileUtility::clr_dir($current_path . $pathext . $filename))) { $msg->addError('DIR_NO_PERMISSION'); $result = false; header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'framed=' . $_POST['framed'] . SEP . 'popup=' . $_POST['popup'] . SEP . 'cp=' . $_POST['cp'] . SEP . 'cid=' . $_POST['cid'] . SEP . 'pid=' . $_POST['pid'] . SEP . 'a_type=' . $_POST['a_type'] . SEP . '_course_id=' . $_course_id); exit; } } } } if ($result) { $msg->addFeedback('DIR_DELETED'); } } header('Location: index.php?pathext=' . $_POST['pathext'] . SEP . 'framed=' . $_POST['framed'] . SEP . 'popup=' . $_POST['popup'] . SEP . 'cp=' . $_POST['cp'] . SEP . 'cid=' . $_POST['cid'] . SEP . 'pid=' . $_POST['pid'] . SEP . 'a_type=' . $_POST['a_type'] . SEP . '_course_id=' . $_course_id); exit; }
/** * Destructor - removes temporary folder and its content. * Should self-destruct automatically for PHP 5.0+; otherwise developers should call this function * to clean up. * @access public * @author Harris Wong */ function __destruct() { FileUtility::clr_dir($this->zipfile_dir); }
$patch_list_array = $patchListParser->getMyParsedArrayForVersion(VERSION); } } // end of get patch list $module_content_folder = TR_CONTENT_DIR . "updater/temp"; if (!is_dir($module_content_folder)) { mkdir($module_content_folder); } if ($_POST['install_upload'] && $_POST['uploading']) { include_once TR_INCLUDE_PATH . 'lib/pclzip.lib.php'; // clean up module content folder FileUtility::clr_dir($module_content_folder); // 1. unzip uploaded file to module's content directory $archive = new PclZip($_FILES['patchfile']['tmp_name']); if ($archive->extract(PCLZIP_OPT_PATH, $module_content_folder) == 0) { FileUtility::clr_dir($module_content_folder); $msg->addError('CANNOT_UNZIP'); } } // Installation process if ($_POST['install'] || $_POST['install_upload'] && !isset($_POST["not_ignore_version"])) { if (isset($_POST['id'])) { $id = $_POST['id']; } else { $id = $_REQUEST['id']; } if ($_POST['install'] && $id == "") { $msg->addError('CHOOSE_UNINSTALLED_PATCH'); } else { if ($_POST['install']) { $patchURL = $patch_folder . $patch_list_array[$id][patch_folder] . "/";
/** * Delete course * @access public * @param course ID * @return true, if successful * false and add error into global var $msg, if unsuccessful * @author Cindy Qi Li */ public function Delete($courseID) { require_once TR_INCLUDE_PATH . 'classes/FileUtility.class.php'; require_once TR_INCLUDE_PATH . 'classes/DAO/ContentDAO.class.php'; require_once TR_INCLUDE_PATH . 'classes/DAO/ForumsCoursesDAO.class.php'; $contentDAO = new ContentDAO(); $forumsCoursesDAO = new ForumsCoursesDAO(); unset($_SESSION['s_cid']); // delete course content dir $content_dir = TR_CONTENT_DIR . $courseID . '/'; FileUtility::clr_dir($content_dir); // delete tests and tests related data $sql = "DELETE FROM " . TABLE_PREFIX . "content_tests_assoc\n\t\t WHERE content_id in (SELECT content_id FROM " . TABLE_PREFIX . "content WHERE course_id = " . $courseID . ")"; $this->execute($sql); $sql = "DELETE FROM " . TABLE_PREFIX . "tests_questions_categories WHERE course_id = " . $courseID; $this->execute($sql); $sql = "DELETE FROM " . TABLE_PREFIX . "tests_questions_assoc \n\t\t WHERE test_id in (SELECT test_id FROM " . TABLE_PREFIX . "tests WHERE course_id = " . $courseID . ")"; $this->execute($sql); $sql = "DELETE FROM " . TABLE_PREFIX . "tests_questions WHERE course_id = " . $courseID; $this->execute($sql); $sql = "DELETE FROM " . TABLE_PREFIX . "tests WHERE course_id = " . $courseID; $this->execute($sql); // delete forums that are associated with this course $forumsCoursesDAO->DeleteByCourseID($courseID); // loop thru content to delete using ContentDAO->Delete(), which deletes a4a objects as well $content_rows = $contentDAO->getContentByCourseID($courseID); if (is_array($content_rows)) { foreach ($content_rows as $content) { $contentDAO->Delete($content['content_id']); } } $sql = "DELETE FROM " . TABLE_PREFIX . "content WHERE course_id = " . $courseID; $this->execute($sql); // delete user <-> course association $sql = "DELETE FROM " . TABLE_PREFIX . "user_courses WHERE course_id = " . $courseID; $this->execute($sql); // delete the course $sql = "DELETE FROM " . TABLE_PREFIX . "courses WHERE course_id = " . $courseID; return $this->execute($sql); }
function check_available_size($course_id) { global $coursesDAO, $MaxCourseSize, $import_path, $msg, $oauth_import; $q_row = $coursesDAO->get($course_id); //$sql = "SELECT max_quota FROM ".TABLE_PREFIX."courses WHERE course_id=$_SESSION[course_id]"; //$result = mysql_query($sql, $db); //$q_row = mysql_fetch_assoc($result); if ($q_row['max_quota'] == TR_COURSESIZE_UNLIMITED) { return; } else { $zip_size_limit = $MaxCourseSize; } $totalBytes = FileUtility::dirsize($import_path); $total_after = $zip_size_limit - $totalBytes; if (is_dir(TR_CONTENT_DIR . $course_id . '/')) { $course_total = FileUtility::dirsize(TR_CONTENT_DIR . $course_id . '/'); $total_after -= $course_total; } if ($total_after < 0) { /* remove the content dir, since there's no space for it */ $errors = array('NO_CONTENT_SPACE', number_format(-1 * ($total_after / TR_KBYTE_SIZE), 2)); $msg->addError($errors); // Clean up import path and inserted course row FileUtility::clr_dir($import_path); $coursesDAO->Delete($course_id); if (isset($_GET['tile'])) { header('Location: ' . $_base_path . 'tools/tile/index.php'); } else { if ($oauth_import) { echo "error=" . urlencode('No space for the content.'); } else { header('Location: ' . $_SERVER['HTTP_REFERER']); } } exit; } }