/** * 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 */ 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 (!clr_dir($dir . '/' . $readdir)) { return false; } } } } } /* end while */ @closedir($opendir); if (!@rmdir($dir)) { return false; } return true; }
function backups_delete($course) { global $db; $path = AT_BACKUP_DIR . $course . '/'; clr_dir($path); $sql = "DELETE FROM " . TABLE_PREFIX . "backups WHERE course_id={$course}"; $result = mysql_query($sql, $db); }
function chat_delete($course) { global $db; $path = AT_CONTENT_DIR . 'chat/' . $course . '/'; if (is_dir($path)) { clr_dir($path); } }
function backups_delete($course) { global $db; $path = AT_BACKUP_DIR . $course . '/'; clr_dir($path); $sql = "DELETE FROM %sbackups WHERE course_id=%d"; $result = queryDB($sql, array(TABLE_PREFIX, $course)); }
function basiclti_delete($course) { global $db; // delete basiclti course table entries $sql = "DELETE FROM %sbasiclti_content WHERE course_id=%d"; queryDB($sql, array(TABLE_PREFIX, $course)); // delete basiclti course files $path = AT_CONTENT_DIR . 'basiclti/' . $course . '/'; clr_dir($path); }
function basiclti_delete($course) { global $db; // delete basiclti course table entries $sql = "DELETE FROM " . TABLE_PREFIX . "basiclti WHERE course_id={$course}"; mysql_query($sql, $db); // delete basiclti course files $path = AT_CONTENT_DIR . 'basiclti/' . $course . '/'; clr_dir($path); }
function clear_dir($dir) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') { continue; } if (is_dir($dir . $file)) { clr_dir($dir . $file); } else { unlink($dir . $file); } } closedir($dh); } }
function clear_dir($dir) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if (($file == '.') || ($file == '..')) continue; if (is_dir($dir.$file)) clr_dir($dir.$file); else unlink($dir.$file); } closedir($dh); } }
/* modify it under the terms of the GNU General Public License */ /* as published by the Free Software Foundation. */ /****************************************************************/ // $Id$ define('AT_INCLUDE_PATH', '../include/'); require AT_INCLUDE_PATH . 'vitals.inc.php'; admin_authenticate(AT_ADMIN_PRIV_ADMIN); if (isset($_POST['submit_no'])) { $msg->addFeedback('CANCELLED'); header('Location: ./error_logging.php'); exit; } else { if (isset($_POST['submit_yes'])) { //clean up the db require_once AT_INCLUDE_PATH . '../mods/_core/file_manager/filemanager.inc.php'; if ($result = clr_dir(AT_CONTENT_DIR . 'logs/')) { $msg->addFeedback('ERROR_LOG_RESET'); } else { $msg->addError('ERROR_LOG_NOT_RESET'); } header('Location: ./error_logging.php'); exit; } } require AT_INCLUDE_PATH . 'header.inc.php'; //print confirmation $hidden_vars['all'] = TRUE; $confirm = array('RESET_ERROR_LOG', $_SERVER['PHP_SELF']); $msg->addConfirm($confirm, $hidden_vars); $msg->printConfirm(); require AT_INCLUDE_PATH . 'footer.inc.php';
function restore_files() { $sql = "SELECT max_quota FROM " . TABLE_PREFIX . "courses WHERE course_id={$this->course_id}"; $result = mysql_query($sql, $this->db); $row = mysql_fetch_assoc($result); if ($row['max_quota'] != AT_COURSESIZE_UNLIMITED) { global $MaxCourseSize, $MaxCourseFloat; if ($row['max_quota'] == AT_COURSESIZE_DEFAULT) { $row['max_quota'] = $MaxCourseSize; } $totalBytes = dirsize($this->import_dir . 'content/'); $course_total = dirsize(AT_CONTENT_DIR . $this->course_id . '/'); $total_after = $row['max_quota'] - $course_total - $totalBytes + $MaxCourseFloat; if ($total_after < 0) { //debug('not enough space. delete everything'); // remove the content dir, since there's no space for it clr_dir($this->import_dir); return FALSE; } } copys($this->import_dir . 'content/', AT_CONTENT_DIR . $this->course_id); }
function delete_theme ($theme_dir) { global $msg, $db; //check status $sql = "SELECT status FROM ".TABLE_PREFIX."themes WHERE dir_name='$theme_dir'"; $result = mysql_query ($sql, $db); $row = mysql_fetch_assoc($result); $status = intval($row['status']); //can't delete original default or current default theme if (($theme_dir == 'default') || ($status == 2)) { $msg->addError('THEME_NOT_DELETED'); return FALSE; } else { //disable, clear directory and delete theme from db require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php'); /* for clr_dir() */ if ($status != 0) { disable_theme($theme_dir); $msg->deleteFeedback('THEME_DISABLED'); } $dir = '../../../themes/' . $theme_dir; //chmod($dir, 0777); @clr_dir($dir); $sql1 = "DELETE FROM ".TABLE_PREFIX."themes WHERE dir_name = '$theme_dir'"; $result1 = mysql_query ($sql1, $db); write_to_log(AT_ADMIN_LOG_DELETE, 'themes', mysql_affected_rows($db), $sql); $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); return TRUE; } }
/** * Delete an album and all associations */ function deleteAlbum() { //TODO Error checking on each step, if anyone fails, should report it to user global $db; $id = $this->id; //clean directory $sql = 'SELECT created_date FROM ' . TABLE_PREFIX . "pa_albums WHERE id={$id}"; $result = mysql_query($sql, $db); if ($result) { $row = mysql_fetch_assoc($result); } $filepath = AT_PA_CONTENT_DIR . getAlbumFilePath($id, $row['created_date']); //orig $filepath_tn = $filepath . '_tn'; //thumbnails //delete files if (is_dir($filepath) && is_dir($filepath_tn)) { clr_dir($filepath); clr_dir($filepath_tn); } //delete all photo comments $sql = 'DELETE c.* FROM ' . TABLE_PREFIX . 'pa_photo_comments c LEFT JOIN ' . TABLE_PREFIX . "pa_photos p ON c.photo_id=p.id WHERE p.album_id={$id}"; mysql_query($sql, $db); //delete all photos within this album $sql = "DELETE FROM " . TABLE_PREFIX . "pa_photos WHERE album_id={$id}"; mysql_query($sql, $db); //delete all album comments $sql = 'DELETE FROM ' . TABLE_PREFIX . "pa_album_comments WHERE album_id={$id}"; mysql_query($sql, $db); //delete album $sql = "DELETE FROM " . TABLE_PREFIX . "pa_albums WHERE id={$id}"; mysql_query($sql, $db); }
* a web browser. It will only execute if required from within an ATutor script, * in our case the Module::uninstall() method. */ if (!defined('AT_INCLUDE_PATH')) { exit; } /******** * the following code is used for removing a module-specific directory created in module_install.php. * it generates appropriate error messages to aid in its creation. */ $directory = AT_CONTENT_DIR .'bigbluebutton'; // check if the directory exists if (is_dir($directory)) { require(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php'); if (!clr_dir($directory)) $msg->addError(array('MODULE_UNINSTALL', '<li>'.$directory.' can not be removed. Please manually remove it.</li>')); } /****** * the following code checks if there are any errors (generated previously) * then uses the SqlUtility to run reverted database queries of module.sql, * ie. "create table" statement in module.sql is run as drop according table. */ if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) { // deal with the SQL file: require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php'); $sqlUtility = new SqlUtility(); /* * the SQL file could be stored anywhere, and named anything, "module.sql" is simply
/** * Imports a theme from a URL or Zip file to Atutor * @access private * @author Shozub Qureshi */ function import_theme() { global $db; global $msg; if (isset($_POST['url']) && $_POST['url'] != 'http://') { if ($content = @file_get_contents($_POST['url'])) { // save file to /themes/ $filename = pathinfo($_POST['url']); $filename = $filename['basename']; $full_filename = AT_CONTENT_DIR . '/' . $filename; if (!($fp = fopen($full_filename, 'w+b'))) { //Cannot open file ($filename)"; $errors = array('CANNOT_OPEN_FILE', $filename); $msg->addError($errors); header('Location: index.php'); exit; } if (fwrite($fp, $content, strlen($content)) === FALSE) { //"Cannot write to file ($filename)"; $errors = array('CANNOT_WRITE_FILE', $filename); $msg->addError($errors); header('Location: index.php'); exit; } fclose($fp); } $_FILES['file']['name'] = $filename; $_FILES['file']['tmp_name'] = $full_filename; $_FILES['file']['size'] = strlen($content); unset($content); $url_parts = pathinfo($_POST['url']); $package_base_name_url = $url_parts['basename']; } $ext = pathinfo($_FILES['file']['name']); $ext = $ext['extension']; //error in the file if ($_FILES['file']['error'] == 1) { $errors = array('FILE_MAX_SIZE', ini_get('upload_max_filesize')); $msg->addError($errors); header('Location: index.php'); exit; } //If file has no name or no address or if the extension is not .zip if (!$_FILES['file']['name'] || !is_uploaded_file($_FILES['file']['tmp_name']) && !$_POST['url']) { $msg->addError('FILE_NOT_SELECTED'); header('Location: index.php'); exit; } if ($ext != 'zip') { $msg->addError('IMPORT_NOT_PROPER_FORMAT'); header('Location: index.php'); exit; } //check if file size is ZERO if ($_FILES['file']['size'] == 0) { $msg->addError('IMPORTFILE_EMPTY'); header('Location: index.php'); exit; } // new directory name is the filename minus the extension $fldrname = substr($_FILES['file']['name'], 0, -4); $fldrname = str_replace(' ', '_', $fldrname); $import_path = AT_SUBSITE_THEME_DIR . $fldrname; //check if Folder by that name already exists if (is_dir($import_path)) { $i = 1; while (is_dir($import_path . '_' . $i)) { $i++; } $fldrname = $fldrname . '_' . $i; $import_path = $import_path . '_' . $i; } //if folder does not exist previously if (!@mkdir($import_path, 0700)) { $msg->addError('IMPORTDIR_FAILED'); header('Location: index.php'); exit; } // unzip file and save into directory in themes $archive = new PclZip($_FILES['file']['tmp_name']); //extract contents to importpath/foldrname if (!$archive->extract($import_path)) { $errors = array('IMPORT_ERROR_IN_ZIP', $archive->errorInfo(true)); clr_dir($import_path); $msg->addError($errors); header('Location: index.php'); exit; } $handle = opendir($import_path); while ($file = readdir($handle)) { if (is_dir($import_path . '/' . $file) && $file != '.' && $file != '..') { $folder = $file; } } //copy contents from importpath/foldrname to importpath copys($import_path . '/' . $folder, $import_path); //delete importpath/foldrname clr_dir($import_path . '/' . $folder); $theme_xml = @file_get_contents($import_path . '/theme_info.xml'); //Check if XML file exists (if it doesnt send error and clear directory) if ($theme_xml == false) { $version = '1.4.x'; $extra_info = 'unspecified'; } else { //parse information $xml_parser = new ThemeParser(); $xml_parser->parse($theme_xml); $version = $xml_parser->theme_rows['version']; $extra_info = $xml_parser->theme_rows['extra_info']; $type = $xml_parser->theme_rows['type']; } $title = str_replace('_', ' ', $fldrname); $last_updated = date('Y-m-d'); $status = '1'; //if version number is not compatible with current Atutor version, set theme as disabled if ($version != VERSION) { $status = '0'; } //save information in database $sql = "INSERT INTO %sthemes (title, version, dir_name, type, last_updated, extra_info, status, customized) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %d, 1)"; $result = queryDB($sql, array(TABLE_PREFIX, $title, $version, $fldrname, $type, $last_updated, $extra_info, $status)); global $sqlout; write_to_log(AT_ADMIN_LOG_INSERT, 'themes', $result, $sqlout); if (!$result) { $msg->addError('IMPORT_FAILED'); header('Location: index.php'); exit; } if (isset($_POST['url'])) { @unlink($full_filename); } }
// module content folder $module_content_folder = AT_CONTENT_DIR . "module/"; if (isset($_GET["mod"])) $mod = str_replace(array('.','..'), '', $_GET['mod']); else if (isset($_POST["mod"])) $mod = $_POST["mod"]; if (isset($_GET["new"])) $new = $_GET["new"]; else if (isset($_POST["new"])) $new = $_POST["new"]; if (isset($_GET["permission_granted"])) $permission_granted = $_GET["permission_granted"]; else if (isset($_POST["permission_granted"])) $permission_granted = $_POST["permission_granted"]; if (isset($_POST['submit_no'])) { clr_dir('../../../mods/'.$_POST['mod']); // if write permission on the mods folder has been granted, re-direct to the page of removing permission, // otherwise, back to start page. if ($_POST['permission_granted']==1) header('Location: '.AT_BASE_HREF.'mods/_core/modules/module_install_step_3.php?cancelled=1'); else { $msg->addFeedback('CANCELLED'); header('Location: '.AT_BASE_HREF.'mods/_core/modules/install_modules.php'); } exit; } else if (isset($_POST['submit_yes'])) {
/** * Uninstalls the module * @access public * @author Cindy Qi Li */ function uninstall($del_data = '') { global $msg; if (file_exists($this->_module_path . $this->_directoryName . '/module_uninstall.php') && $del_data == 1) { require $this->_module_path . $this->_directoryName . '/module_uninstall.php'; } if (!$msg->containsErrors()) { require_once AT_INCLUDE_PATH . '../mods/_core/file_manager/filemanager.inc.php'; if (!clr_dir($this->_module_path . $this->_directoryName)) { $msg->addError(array('MODULE_UNINSTALL', '<li>' . $this->_module_path . $this->_directoryName . ' can not be removed. Please manually remove it.</li>')); } } if (!$msg->containsErrors()) { global $db; $sql = "DELETE FROM " . TABLE_PREFIX . "modules WHERE dir_name = '" . $this->_directoryName . "'"; mysql_query($sql, $db); } if ($msg->containsErrors()) { global $db; $sql = "UPDATE " . TABLE_PREFIX . "modules SET status=" . AT_MODULE_STATUS_PARTIALLY_UNINSTALLED . " WHERE dir_name='" . $this->_directoryName . "'"; mysql_query($sql, $db); } }
if ($title == '') { $title = str_replace('_', ' ', $theme); } $last_updated = date('Y-m-d'); $status = '1'; //if version number is not compatible with current Atutor version, set theme as disabled if ($version != VERSION) { $status = '0'; } //save information in database $sql = "INSERT INTO %sthemes (title, version, dir_name, type, last_updated, extra_info, status, customized) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %d, 1)"; $result = queryDB($sql, array(TABLE_PREFIX, $title, $version, $theme, $type, $last_updated, $extra_info, $status)); global $sqlout; write_to_log(AT_ADMIN_LOG_INSERT, 'themes', $result, $sqlout); } if (!$result) { clr_dir("../../themes/" . $theme); if ($_GET['permission_granted'] == 1) { header('Location: ' . AT_BASE_HREF . 'mods/_core/themes/theme_install_step_3.php?error=1'); } else { $msg->addError('IMPORT_FAILED'); header('Location: ' . AT_BASE_HREF . 'mods/_core/themes/install_themes.php'); } } else { if ($_GET['permission_granted'] == 1) { header('Location: ' . AT_BASE_HREF . 'mods/_core/themes/theme_install_step_3.php?installed=1'); } else { $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); header('Location: ' . AT_BASE_HREF . 'mods/_core/themes/index.php'); } }
if (isset($_GET["new"])) { $new = $_GET["new"]; } else { if (isset($_POST["new"])) { $new = $_POST["new"]; } } if (isset($_GET["permission_granted"])) { $permission_granted = $_GET["permission_granted"]; } else { if (isset($_POST["permission_granted"])) { $permission_granted = $_POST["permission_granted"]; } } if (isset($_POST['submit_no'])) { clr_dir(AT_SUBSITE_MODULE_PATH . $_POST['mod']); // if write permission on the mods folder has been granted, re-direct to the page of removing permission, // otherwise, back to start page. if ($_POST['permission_granted'] == 1) { header('Location: ' . AT_BASE_HREF . 'mods/_core/modules/module_install_step_3.php?cancelled=1'); } else { $msg->addFeedback('CANCELLED'); header('Location: ' . AT_BASE_HREF . 'mods/_core/modules/install_modules.php'); } exit; } else { if (isset($_POST['submit_yes'])) { // install module $module = $moduleFactory->getModule($_POST['mod']); $module->load(); $module->install();
function delete_theme($theme_dir) { global $msg; $theme_dir = addslashes($theme_dir); //check status $sql = "SELECT status, customized FROM %sthemes WHERE dir_name='%s'"; $row = queryDB($sql, array(TABLE_PREFIX, $theme_dir), TRUE); $status = intval($row['status']); $customized = intval($row['customized']); //can't delete if // 1. a system default // 2. current default theme // 3. a system level theme if ($theme_dir == 'default' || $status == 2 || !$customized && defined('IS_SUBSITE') && IS_SUBSITE) { $msg->addError('THEME_NOT_DELETED'); return FALSE; } else { //disable, clear directory and delete theme from db require_once AT_INCLUDE_PATH . '../mods/_core/file_manager/filemanager.inc.php'; /* for clr_dir() */ if ($status != 0) { disable_theme($theme_dir); $msg->deleteFeedback('THEME_DISABLED'); } $dir = get_main_theme_dir($customized) . $theme_dir; //chmod($dir, 0777); @clr_dir($dir); $sql1 = "DELETE FROM %sthemes WHERE dir_name = '%s'"; $result1 = queryDB($sql1, array(TABLE_PREFIX, $theme_dir)); global $sqlout; write_to_log(AT_ADMIN_LOG_DELETE, 'themes', $result1, $sqlout); $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); return TRUE; } }
/** * 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() { clr_dir($this->zipfile_dir); }
/** * Delete an album and all associations */ function deleteAlbum() { //TODO Error checking on each step, if anyone fails, should report it to user $id = $this->id; //clean directory $sql = "SELECT created_date FROM %spa_albums WHERE id=%d"; $row = queryDB($sql, array(TABLE_PREFIX, $id), TRUE); $filepath = AT_PA_CONTENT_DIR . getAlbumFilePath($id, $row['created_date']); //orig $filepath_tn = $filepath . '_tn'; //thumbnails //delete files if (is_dir($filepath) && is_dir($filepath_tn)) { clr_dir($filepath); clr_dir($filepath_tn); } //delete all photo comments $sql = "DELETE c.* FROM %spa_photo_comments c LEFT JOIN %spa_photos p ON c.photo_id=p.id WHERE p.album_id=%d"; queryDB($sql, array(TABLE_PREFIX, TABLE_PREFIX, $id)); //delete all photos within this album $sql = "DELETE FROM %spa_photos WHERE album_id=%d"; queryDB($sql, array(TABLE_PREFIX, $id)); //delete all album comments $sql = "DELETE FROM %spa_album_comments WHERE album_id=%d"; queryDB($sql, array(TABLE_PREFIX, $id)); //delete album $sql = "DELETE FROM %spa_albums WHERE id=%d"; queryDB($sql, array(TABLE_PREFIX, $id)); }
require AT_INCLUDE_PATH . 'header.inc.php'; // $msg->addConfirm(array('MEDIA_FILE_EXISTED', $existing_files)); // $msg->printConfirm(); echo '<form action="" method="POST">'; echo '<div class="input-form">'; echo '<div class="row">'; $msg->printInfos(array('MEDIA_FILE_EXISTED', $existing_files)); echo '</div>'; echo '<div class="row buttons">'; echo '<input type="submit" class="" name="submit_yes" value="' . _AT('yes') . '"/>'; echo '<input type="submit" class="" name="submit_no" value="' . _AT('no') . '"/>'; echo '<input type="hidden" name="submit_import" value="submit_import" />'; echo '<input type="hidden" name="url" value="' . $_POST['url'] . '" />'; echo '</div></div>'; echo '</form>'; require AT_INCLUDE_PATH . 'footer.inc.php'; exit; } //Get the XML file out and start importing them into our database. //TODO: import_test.php shares approx. the same code as below, just that import_test.php has // an extra line of code that uses a stack to remember the question #. Might want to // create a function for this. $qti_import = new QTIImport($import_path); $qti_import->importQuestions($attributes); //debug('done'); clr_dir(AT_CONTENT_DIR . 'import/' . $_SESSION['course_id']); if (!$msg->containsErrors()) { $msg->addFeedback('IMPORT_SUCCEEDED'); } header('Location: question_db.php'); exit;
function file_manager_delete($course) { $path = AT_CONTENT_DIR . $course . '/'; clr_dir($path); }
if (!is_dir($course_dir)) { if (!@mkdir($course_dir, 0700)) { $msg->addError('IMPORTDIR_FAILED'); } } if (@rename($import_path . $package_base_path, $course_dir . $package_base_name) === false) { if (!$msg->containsErrors()) { $msg->addError('IMPORT_FAILED'); } } //check if there are still resources missing foreach ($items as $idetails) { $temp_path = pathinfo($idetails['href']); @rename($import_path . $temp_path['dirname'], $course_dir . $package_base_name . '/' . $temp_path['dirname']); } clr_dir($import_path); if (isset($_POST['url'])) { @unlink($full_filename); } //if ($_POST['s_cid'] || $course_id){ if (!$msg->containsErrors()) { $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); } header('Location: ../course.php?cid=' . $course_id); exit; //} else { // if (!$msg->containsErrors()) { // $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); // } // if ($_GET['tile']) { // header('Location: '.TR_BASE_HREF.'tools/tile/index.php');
$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']); 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']); exit; } else { if (!($result = 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']); 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']); exit; }
function delete_theme($theme_dir) { global $msg, $db; $theme_dir = addslashes($theme_dir); //check status $sql = "SELECT status, customized FROM " . TABLE_PREFIX . "themes WHERE dir_name='" . $theme_dir . "'"; $result = mysql_query($sql, $db); $row = mysql_fetch_assoc($result); $status = intval($row['status']); $customized = intval($row['customized']); //can't delete if // 1. a system default // 2. current default theme // 3. a system level theme if ($theme_dir == 'default' || $status == 2 || !$customized) { $msg->addError('THEME_NOT_DELETED'); return FALSE; } else { //disable, clear directory and delete theme from db require_once AT_INCLUDE_PATH . '../mods/_core/file_manager/filemanager.inc.php'; /* for clr_dir() */ if ($status != 0) { disable_theme($theme_dir); $msg->deleteFeedback('THEME_DISABLED'); } $dir = get_main_theme_dir($customized) . $theme_dir; //chmod($dir, 0777); @clr_dir($dir); $sql1 = "DELETE FROM " . TABLE_PREFIX . "themes WHERE dir_name = '{$theme_dir}'"; $result1 = mysql_query($sql1, $db); write_to_log(AT_ADMIN_LOG_DELETE, 'themes', mysql_affected_rows($db), $sql); $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY'); return TRUE; } }
/** * This function deletes $dir recrusively without deleting $dir itself. * @access public * @param string $charsets_array The name of the directory where all files and folders under needs to be deleted * @author Cindy Qi Li */ function clear_dir($dir) { require_once(AT_INCLUDE_PATH.'../mods/_core/file_manager/filemanager.inc.php'); 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 lib function to clear subdirectories recrusively */ if(!clr_dir($dir.'/'.$readdir)) { return false; } } } } /* end while */ @closedir($opendir); return true; }