commit
0433b28f7f
@ -0,0 +1,37 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class AdminPage extends Page |
||||
{ |
||||
|
||||
/** |
||||
* |
||||
* @return AdminPage |
||||
*/ |
||||
static function create($title = '') |
||||
{ |
||||
return new self($title); |
||||
} |
||||
|
||||
function __construct($title = '') |
||||
{ |
||||
global $this_section; |
||||
$this_section = SECTION_PLATFORM_ADMIN; |
||||
|
||||
api_protect_admin_script(); |
||||
|
||||
if (empty($title)) { |
||||
$title = get_lang(get_class($this)); |
||||
} |
||||
|
||||
$this->title = $title; |
||||
|
||||
$this->breadcrumbs = array(); |
||||
$this->breadcrumbs[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,124 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* |
||||
* |
||||
* @package chamilo.admin |
||||
* @author Laurent Opprecht <laurent@opprecht.info> |
||||
* @license see /license.txt |
||||
*/ |
||||
$language_file = array('admin'); |
||||
$cidReset = true; |
||||
require_once '../inc/global.inc.php'; |
||||
require_once __DIR__ . '/admin_page.class.php'; |
||||
|
||||
class SystemManagementPage extends AdminPage |
||||
{ |
||||
|
||||
const PARAM_ACTION = 'action'; |
||||
const PARAM_SECURITY_TOKEN = 'sec_token'; |
||||
const ACTION_DEFAULT = 'list'; |
||||
const ACTION_SECURITY_FAILED = 'security_failed'; |
||||
|
||||
function get_action() |
||||
{ |
||||
$result = Request::get(self::PARAM_ACTION, self::ACTION_DEFAULT); |
||||
if ($result != self::ACTION_DEFAULT) { |
||||
$passed = Security::check_token('get'); |
||||
Security::clear_token(); |
||||
$result = $passed ? $result : self::ACTION_SECURITY_FAILED; |
||||
} |
||||
return $result; |
||||
} |
||||
|
||||
function url($params) |
||||
{ |
||||
$token = Security::get_token(); |
||||
$params[self::PARAM_SECURITY_TOKEN] = $token; |
||||
return Uri::here($params); |
||||
} |
||||
|
||||
function display_default() |
||||
{ |
||||
$message = get_lang('RemoveOldDatabaseMessage'); |
||||
$url = $this->url(array(self::PARAM_ACTION => 'drop_old_databases')); |
||||
$go = get_lang('go'); |
||||
|
||||
echo <<<EOT |
||||
<ul> |
||||
<li> |
||||
<div>$message</div> |
||||
<a href=$url>$go</a> |
||||
</li> |
||||
</ul> |
||||
EOT; |
||||
} |
||||
|
||||
function display_security_failed() |
||||
{ |
||||
Display::display_error_message(get_lang('NotAuthorized')); |
||||
} |
||||
|
||||
function display_content() |
||||
{ |
||||
$action = $this->get_action(); |
||||
switch ($action) { |
||||
case self::ACTION_DEFAULT: |
||||
$this->display_default(); |
||||
return; |
||||
|
||||
case self::ACTION_SECURITY_FAILED: |
||||
$this->display_security_failed(); |
||||
return; |
||||
|
||||
default: |
||||
$f = array($this, $action); |
||||
if (is_callable($f)) { |
||||
call_user_func($f); |
||||
return; |
||||
} else { |
||||
Display::display_error_message(get_lang('UnknownAction')); |
||||
} |
||||
return; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @return ResultSet |
||||
*/ |
||||
function get_old_databases() |
||||
{ |
||||
$course_db = Database::get_main_table(TABLE_MAIN_COURSE); |
||||
$sql = "SELECT id, code, db_name, directory, course_language FROM $course_db WHERE target_course_code IS NULL AND db_name IS NOT NULL ORDER BY code"; |
||||
return new ResultSet($sql); |
||||
} |
||||
|
||||
function drop_old_databases() |
||||
{ |
||||
$result = array(); |
||||
$courses = $this->get_old_databases(); |
||||
$course_db = Database::get_main_table(TABLE_MAIN_COURSE); |
||||
foreach ($courses as $course) { |
||||
$drop_statement = 'DROP DATABASE ' . $course['db_name']; |
||||
$success = Database::query($drop_statement); |
||||
if ($sucess) { |
||||
/* |
||||
* Note that Database::update do not supports null statements so |
||||
* we do it by hand here. |
||||
*/ |
||||
$id = $course['id']; |
||||
$update_statement = "UPDATE $course_db SET db_name = NULL WHERE id = $id"; |
||||
Database::query($update_statement); |
||||
$result[] = $course['db_name']; |
||||
} |
||||
} |
||||
|
||||
Display::display_confirmation_message(get_lang('OldDatabasesDeleted') . ' ' . count($result)); |
||||
return $result; |
||||
} |
||||
|
||||
} |
||||
|
||||
$page = new SystemManagementPage(); |
||||
$page->display(); |
||||
@ -0,0 +1,27 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Abstract base class for QuickForm validation rules |
||||
*/ |
||||
require_once 'HTML/QuickForm/Rule.php'; |
||||
|
||||
/** |
||||
* Validate urls |
||||
* |
||||
*/ |
||||
class HTML_QuickForm_Rule_Url extends HTML_QuickForm_Rule |
||||
{ |
||||
|
||||
/** |
||||
* Validates url |
||||
* |
||||
* @param string $url |
||||
* @return boolean Returns true if valid, false otherwise. |
||||
*/ |
||||
function validate($url) |
||||
{ |
||||
return (bool) filter_var($url, FILTER_VALIDATE_URL); |
||||
} |
||||
|
||||
} |
||||
|
||||
@ -0,0 +1,168 @@ |
||||
<?php |
||||
|
||||
/** |
||||
* Web page wrapper. Usage: |
||||
* |
||||
* Page::create()->title('my_title')->display($content); |
||||
* |
||||
* $page = Page::create()->title('my_title')->help('help')->content($content); |
||||
* $page->display(); |
||||
* |
||||
* @license see /license.txt |
||||
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva |
||||
*/ |
||||
class Page |
||||
{ |
||||
|
||||
protected $title = null; |
||||
protected $help = null; |
||||
protected $header = null; |
||||
protected $content; |
||||
protected $breadcrumbs = ''; |
||||
protected $message = null; |
||||
protected $warning = null; |
||||
protected $error = null; |
||||
|
||||
/** |
||||
* |
||||
* @return Page |
||||
*/ |
||||
static function create($title = '') |
||||
{ |
||||
return new self($title); |
||||
} |
||||
|
||||
function __construct($title = '') |
||||
{ |
||||
$this->title = $title; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param $header |
||||
* @return Page |
||||
*/ |
||||
function header($header) |
||||
{ |
||||
$this->header = $header; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $title |
||||
* @return Page |
||||
*/ |
||||
function title($title) |
||||
{ |
||||
$this->title = $title; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param array $crumbs_ |
||||
* @return Page |
||||
*/ |
||||
function breadcrumbs($crumbs) |
||||
{ |
||||
$this->breadcrumbs = $crumbs; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $help help file name |
||||
* @return Page |
||||
*/ |
||||
function help($help) |
||||
{ |
||||
$this->help = $help; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $message |
||||
* @return Page |
||||
*/ |
||||
function message($message) |
||||
{ |
||||
$this->message = $message; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $warning |
||||
* @return Page |
||||
*/ |
||||
function warning($warning) |
||||
{ |
||||
$this->warning = $warning; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param string $error |
||||
* @return Page |
||||
*/ |
||||
function error($error) |
||||
{ |
||||
$this->error = $error; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param object|string $content |
||||
* @return Page |
||||
*/ |
||||
function content($content) |
||||
{ |
||||
$this->content = $content; |
||||
return $this; |
||||
} |
||||
|
||||
function __toString() |
||||
{ |
||||
$this->display($this->content); |
||||
} |
||||
|
||||
function display($content = null) |
||||
{ |
||||
$this->display_header(); |
||||
$this->display_content($content); |
||||
$this->display_footer(); |
||||
} |
||||
|
||||
function display_header() |
||||
{ |
||||
global $interbreadcrumb; |
||||
$interbreadcrumb = $this->breadcrumbs; |
||||
|
||||
Display::display_header($this->title, $this->help, $this->header); |
||||
if ($message = $this->message) { |
||||
Display::display_confirmation_message($message); |
||||
} |
||||
if ($warning = $this->warning) { |
||||
Display::display_warning_message($warning); |
||||
} |
||||
if ($error = $this->error) { |
||||
Display::display_error_message($error); |
||||
} |
||||
} |
||||
|
||||
protected function display_content($content) |
||||
{ |
||||
$content = $content ? $content : $this->content; |
||||
echo $content; |
||||
} |
||||
|
||||
function display_footer() |
||||
{ |
||||
Display::display_footer(); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue