From f2ca1404448f5375c66170180beb4a5e7dbe0688 Mon Sep 17 00:00:00 2001 From: Laurent Opprecht Date: Tue, 15 May 2012 09:52:46 +0200 Subject: [PATCH] #4652 Zombie users --- main/admin/admin_page.class.php | 69 ++------ main/inc/lib/autoload.class.php | 12 +- main/inc/lib/display.lib.php | 5 + main/inc/lib/header.class.php | 5 +- main/inc/lib/page.class.php | 168 ++++++++++++++++++++ main/inc/lib/zombie/zombie_report.class.php | 4 +- 6 files changed, 206 insertions(+), 57 deletions(-) create mode 100644 main/inc/lib/page.class.php diff --git a/main/admin/admin_page.class.php b/main/admin/admin_page.class.php index 1ffaebcd75..c09c7838a8 100644 --- a/main/admin/admin_page.class.php +++ b/main/admin/admin_page.class.php @@ -2,71 +2,36 @@ /** * - * @copyright (c) 2012 University of Geneva - * @license GNU General Public License - http://www.gnu.org/copyleft/gpl.html - * @author Laurent Opprecht + * @license see /license.txt + * @author Laurent Opprecht for the Univesity of Geneva */ -class AdminPage +class AdminPage extends Page { - protected $title = ''; - protected $breadcrumbs = ''; - - function __construct($title = '', $breadcrumbs = array()) + /** + * + * @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; - if (empty($breadcrumbs)) { - $breadcrumbs[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); - } - - $this->breadcrumbs = $breadcrumbs; - } - - public function get_title() - { - return $this->title; - } - - public function get_breadcrumbs() - { - return $this->breadcrumbs; - } - - function display() - { - $this->display_header(); - $this->display_content(); - $this->display_footer(); - } - - public function display_header() - { - $breadcrumbs = $this->get_breadcrumbs(); - $title = $this->get_title(); - - global $interbreadcrumb; - $interbreadcrumb = $breadcrumbs; - Display :: display_header($title); - } - - public function display_content() - { - ; - } - - public function display_footer() - { - Display :: display_footer(); + $this->breadcrumbs = array(); + $this->breadcrumbs[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); } } \ No newline at end of file diff --git a/main/inc/lib/autoload.class.php b/main/inc/lib/autoload.class.php index 49f06b2044..ca33f8902b 100644 --- a/main/inc/lib/autoload.class.php +++ b/main/inc/lib/autoload.class.php @@ -62,6 +62,7 @@ class Autoload $result['AddCourseToSession'] = '/main/inc/lib/add_courses_to_session_functions.lib.php'; $result['AddManySessionToCategoryFunctions'] = '/main/inc/lib/add_many_session_to_category_functions.lib.php'; $result['Admin'] = '/main/auth/shibboleth/app/model/admin.class.php'; + $result['AdminPage'] = '/main/admin/admin_page.class.php'; $result['AdminStore'] = '/main/auth/shibboleth/app/model/admin.class.php'; $result['Agenda'] = '/main/calendar/agenda.lib.php'; $result['Announcement'] = '/main/coursecopy/classes/Announcement.class.php'; @@ -211,8 +212,10 @@ class Autoload $result['ImageWrapper'] = '/main/inc/lib/image.lib.php'; $result['ImagickWrapper'] = '/main/inc/lib/image.lib.php'; $result['Import'] = '/main/inc/lib/import.lib.php'; + $result['InactiveCourseReport'] = '/main/admin/inactive_course_report.class.php'; $result['IndexManager'] = '/main/inc/lib/userportal.lib.php'; $result['IndexableChunk'] = '/main/inc/lib/search/IndexableChunk.class.php'; + $result['Install'] = '/main/install/install.class.php'; $result['Javascript'] = '/main/inc/lib/javascript.class.php'; $result['KeyAuth'] = '/main/auth/key/key_auth.class.php'; $result['LearnpathLink'] = '/main/gradebook/lib/be/learnpathlink.class.php'; @@ -249,6 +252,7 @@ class Autoload $result['PEAR'] = '/main/inc/lib/pear/PEAR.php'; $result['PEAR5'] = '/main/inc/lib/pear/PEAR5.php'; $result['PEAR_Error'] = '/main/inc/lib/pear/PEAR.php'; + $result['Page'] = '/main/inc/lib/page.class.php'; $result['Pager'] = '/main/inc/lib/pear/Pager/Pager.php'; $result['Pager_Common'] = '/main/inc/lib/pear/Pager/Common.php'; $result['Pager_HtmlWidgets'] = '/main/inc/lib/pear/Pager/HtmlWidgets.php'; @@ -391,6 +395,7 @@ class Autoload $result['ch_yesno'] = '/main/survey/survey.lib.php'; $result['db'] = '/main/inc/lib/db.lib.php'; $result['document_processor'] = '/main/inc/lib/search/tool_processors/document_processor.class.php'; + $result['iDatabase'] = '/main/install/i_database.class.php'; $result['learnpath'] = '/main/newscorm/learnpath.class.php'; $result['learnpathItem'] = '/main/newscorm/learnpathItem.class.php'; $result['learnpathList'] = '/main/newscorm/learnpathList.class.php'; @@ -482,8 +487,13 @@ class AutoloadClassFinder $this->synch(Chamilo::path('/main')); ksort($this->map); } + + public function __invoke() + { + $this->run(); + } - public function to_string() + public function __toString() { $result = array(); diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 6bf7350ca2..bb45ed3ffc 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -101,6 +101,11 @@ class Display { global $_plugins, $global_tpl; echo self::$global_template ->show_footer_template(); } + + public static function page() + { + return new Page(); + } /** * Displays the tool introduction of a tool. diff --git a/main/inc/lib/header.class.php b/main/inc/lib/header.class.php index 240a922436..b92ce2900a 100644 --- a/main/inc/lib/header.class.php +++ b/main/inc/lib/header.class.php @@ -9,13 +9,14 @@ class Header { - public static function content_type($mime_type) + public static function content_type($mime_type, $charset = '') { if (empty($mime_type)) { return; } - header('Content-type: ' . $mime_type); + $type = $charset ? "$mime_type;charset=$charset" : $mime_type; + header('Content-type: ' . $type); } public static function content_type_xml() diff --git a/main/inc/lib/page.class.php b/main/inc/lib/page.class.php new file mode 100644 index 0000000000..1b06ef4453 --- /dev/null +++ b/main/inc/lib/page.class.php @@ -0,0 +1,168 @@ +title('my_title')->display($content); + * + * $page = Page::create()->title('my_title')->help('help')->content($content); + * $page->display(); + * + * @license see /license.txt + * @author Laurent Opprecht 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(); + } + +} \ No newline at end of file diff --git a/main/inc/lib/zombie/zombie_report.class.php b/main/inc/lib/zombie/zombie_report.class.php index 301a077e41..9a7bc83d00 100644 --- a/main/inc/lib/zombie/zombie_report.class.php +++ b/main/inc/lib/zombie/zombie_report.class.php @@ -309,12 +309,12 @@ class ZombieReport implements Countable $result = $this->display_parameters($return); if ($this->perform_action()) { if ($return) { - $result = Display::return_confirmation_message(get_lang('Done')); + $result .= Display::return_confirmation_message(get_lang('Done')); } else { Display::display_confirmation_message(get_lang('Done')); } } - $result = $this->display_data($return); + $result .= $this->display_data($return); if ($return) { return $result; }