array("id IN ('$vidlist')" => array()))); } } else { $todelete = Database::select( '*', 'vchamilo', array('where' => array("root_web = '{$n->root_web}' " => array())) ); } if ($todelete) { foreach ($todelete as $fooid => $instance) { $slug = $instance['slug']; if (!empty($slug)) { // Remove all files and eventual symlinks $absalternatecourse = Virtual::getConfig('vchamilo', 'course_real_root'); $coursedir = $absalternatecourse.$slug; Display::addFlash(Display::return_message("Deleting $coursedir")); removeDir($coursedir); if ($absalternatehome = Virtual::getConfig('vchamilo', 'home_real_root')) { $homedir = $absalternatehome.'/'.$slug; Display::addFlash(Display::return_message("Deleting $homedir")); removeDir($homedir); } // delete archive if ($absalternatearchive = Virtual::getConfig('vchamilo', 'archive_real_root')) { $archivedir = $absalternatearchive.'/'.$slug; Display::addFlash(Display::return_message("Deleting $archivedir")); removeDir($archivedir); } // Delete upload if ($dir = Virtual::getConfig('vchamilo', 'upload_real_root')) { $dir = $dir.'/'.$slug; Display::addFlash(Display::return_message("Deleting $dir")); removeDir($dir); } } $sql = "DELETE FROM {$table} WHERE id = ".$instance['id']; Database::query($sql); Display::addFlash(Display::return_message("Removing instance: ".$instance['root_web'])); Virtual::dropDatabase((object) $instance); } } break; case 'snapshotinstance': $interbreadcrumb[] = array('url' => 'manage.php', 'name' => get_lang('VChamilo')); $vid = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : ''; if ($vid) { $vhosts = Database::select('*', 'vchamilo', array('where' => array('id = ?' => $vid))); $vhost = (object) array_pop($vhosts); } else { $vhost = (object) $_configuration; $vhost->slug = Virtual::getSlugFromUrl($vhost->root_web); $vhost->id = 0; } // Parsing url for building the template name. $wwwroot = $vhost->root_web; $vchamilostep = isset($_REQUEST['step']) ? $_REQUEST['step'] : ''; // Make template directory (files and SQL). $separator = DIRECTORY_SEPARATOR; $backupDir = api_get_path(SYS_PATH).'plugin'.$separator.'vchamilo'.$separator.'templates'.$separator.$vhost->slug.$separator; $absolute_datadir = $backupDir.'data'; $absolute_sqldir = $backupDir.'dump.sql'; if (!is_dir($backupDir)) { $result = mkdir($backupDir, 0777, true); if ($result) { Display::addFlash( Display::return_message('Directory created: '.$backupDir) ); } else { Display::addFlash( Display::return_message("Cannot create directory: $backupDir check the folder permissions", 'error') ); } } if ($vchamilostep == 0) { // Create directories, if necessary. if (!is_dir($absolute_datadir)) { mkdir($absolute_datadir, 0777, true); mkdir($absolute_datadir.'/home', 0777, true); } if (empty($fullautomation)) { $actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; $content = '
'; $content .= ''; $content .= ''; $content .= ''; $content .= ''; $content .= '
'; $content .= ''; $tpl = new Template(get_lang('Snapshot'), true, true, false, true, false); $tpl->assign('message', '

'.$plugin->get_lang('vchamilosnapshot1').'

'); $tpl->assign('content', $content); $tpl->display_one_col_template(); exit; } else { // continue next step $vchamilostep = 1; } } if ($vchamilostep >= 1) { if ($wwwroot == $_configuration['root_web']) { // Make fake Vchamilo record. $vchamilo = Virtual::makeThis(); $coursePath = api_get_path(SYS_COURSE_PATH); $homePath = api_get_path(SYS_HOME_PATH); $archivePath = api_get_path(SYS_ARCHIVE_PATH); $uploadPath = api_get_path(SYS_UPLOAD_PATH); } else { // Get Vchamilo known record. $vchamilo = Database::select('*', 'vchamilo', array('where' => array('root_web = ?' => array($wwwroot))), 'first'); $vchamilo = (object) $vchamilo; $coursePath = Virtual::getConfig('vchamilo', 'course_real_root'); $homePath = Virtual::getConfig('vchamilo', 'home_real_root'); $archivePath = Virtual::getConfig('vchamilo', 'archive_real_root'); $uploadPath = Virtual::getConfig('vchamilo', 'upload_real_root'); $coursePath = $coursePath.'/'.$vchamilo->slug; $homePath = $homePath.'/'.$vchamilo->slug; $archivePath = $archivePath.'/'.$vchamilo->slug; $uploadPath = $uploadPath.'/'.$vchamilo->slug; } $content = ''; if ($vchamilostep == 1) { // Auto dump the databases in a master template folder. // this will create three files : dump.sql $result = Virtual::backupDatabase($vchamilo, $absolute_sqldir); if (empty($fullautomation)) { if (!$result) { $actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; $content .= '

'; $content .= ''; $content .= '

'; } else { $actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; $message = $plugin->get_lang('vchamilosnapshot2'); Display::addFlash( Display::return_message('Database file created: '.$absolute_sqldir) ); $content .= '
'; $content .= ''; $content .= ''; $content .= ''; $content .= ''; $content .= '
'; } $tpl = new Template(get_lang('Snapshot'), true, true, false, true, false); $tpl->assign('message', '

'.$message.'

'); $tpl->assign('content', $content); $tpl->display_one_col_template(); die; } } Display::addFlash(Display::return_message("Copying from '$homePath' to '{$absolute_datadir}/home' ")); copyDirTo($homePath, $absolute_datadir.'/home/', false); Display::addFlash(Display::return_message("Copying from '$coursePath' to '$absolute_datadir/courses' ")); copyDirTo($coursePath, $absolute_datadir.'/courses/', false); Display::addFlash(Display::return_message("Copying from '$uploadPath' to '$absolute_datadir/upload' ")); copyDirTo($uploadPath, $absolute_datadir.'/upload/', false); // Store original hostname and some config info for further database or filestore replacements. $FILE = fopen($backupDir.$separator.'manifest.php', 'w'); fwrite($FILE, '<'.'?php '); fwrite($FILE, "\$templatewwwroot = '".$wwwroot."';\n"); fwrite($FILE, '?'.'>'); fclose($FILE); // Every step was SUCCESS. if (empty($fullautomation)) { Display::addFlash( Display::return_message( $plugin->get_lang('successfinishedcapture'), 'success' ) ); if (empty($vid)) { $template = Virtual::getConfig('vchamilo', 'default_template'); if (empty($template)) { Display::addFlash( Display::return_message('Set default template as '.$vhost->slug.'', 'success', false) ); $params = [ 'subkey' => 'vchamilo', 'title' => 'default_template', 'type' => 'setting', 'category' => 'Plugins', 'variable' => 'vchamilo_default_template', 'selected_value' => $vhost->slug, 'access_url_changeable' => 0 ]; api_set_setting_simple($params); } else { Display::addFlash( Display::return_message('Default template is: '.$vhost->slug.'', 'success', false) ); } } $actionurl = $_configuration['root_web'].'/plugin/vchamilo/views/manage.php'; $content .= '
'; $content .= ''; $content .= '
'; $tpl = new Template(get_lang('Snapshot'), true, true, false, true, false); $tpl->assign('message', $plugin->get_lang('vchamilosnapshot3')); $tpl->assign('content', $content); $tpl->display_one_col_template(); exit; } } break; case 'clearcache': // Removes cache directory. if (empty($automation)) { if (array_key_exists('vids', $_REQUEST)) { $toclear = Database::select('*', 'vchamilo', array('where' => array("id IN ('$vidlist')" => array()))); } else { $vid = isset($_REQUEST['vid']) ? $_REQUEST['vid'] : 0; if ($vid) { $vhosts = Database::select('*', 'vchamilo', array('where' => array('id = ?' => $vid))); $vhost = (object) array_pop($vhosts); $toclear[$vhost->id] = $vhost; } else { $toclear[0] = (object) $_configuration; } } } else { $toclear = Database::select( '*', 'vchamilo', array('where' => array("root_web = '{$n->root_web}' " => array())) ); } foreach ($toclear as $fooid => $instance) { if ($fooid == 0) { $templatepath = api_get_path(SYS_ARCHIVE_PATH).'twig'; Display::addFlash(Display::return_message("Deleting master cache $templatepath \n")); removeDir($templatepath); } else { $coursePath = Virtual::getConfig('vchamilo', 'course_real_root'); $homePath = Virtual::getConfig('vchamilo', 'home_real_root'); $archivePath = Virtual::getConfig('vchamilo', 'archive_real_root'); //$uploadPath = Virtual::getConfig('vchamilo', 'upload_real_root'); // Get instance archive $archivepath = api_get_path(SYS_ARCHIVE_PATH, (array) $instance); $templatepath = $archivePath.'/'.$instance['slug'].'/twig'; Display::addFlash(Display::return_message("Deleting cache $templatepath \n")); removeDir($templatepath); } } break; case 'setconfigvalue': $select = ''; if (empty($vidlist)) { api_not_allowed(true, 'No virtual chamilo selected'); } Display::display_header(); echo '

'.$plugin->get_lang('sendconfigvalue').'

'; echo '
'; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
'.get_lang('variable').''.get_lang('subkey').'
'.$select.'
'; echo '
'; echo '
'; Display::display_footer(); exit; break; }