diff --git a/main/admin/admin_page.class.php b/main/admin/admin_page.class.php new file mode 100644 index 0000000000..c09c7838a8 --- /dev/null +++ b/main/admin/admin_page.class.php @@ -0,0 +1,37 @@ + 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')); + } + +} \ No newline at end of file diff --git a/main/admin/index.php b/main/admin/index.php index c6a372d05a..0ec4d8c5da 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -242,6 +242,7 @@ if (api_is_platform_admin()) { $items[] = array('url'=>'archive_cleanup.php', 'label' => get_lang('ArchiveDirCleanup')); //} + $items[] = array('url'=>'system_management.php', 'label' => get_lang('SystemManagement')); //$items[] = array('url'=>'statistics/index.php?action=activities', 'label' => get_lang('ImportantActivities')); $blocks['settings']['items'] = $items; diff --git a/main/admin/system_management.php b/main/admin/system_management.php new file mode 100644 index 0000000000..a89ddba63b --- /dev/null +++ b/main/admin/system_management.php @@ -0,0 +1,124 @@ + + * @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 << +
  • +
    $message
    + $go +
  • + +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(); diff --git a/main/announcements/announcement_email.class.php b/main/announcements/announcement_email.class.php index 539058c65b..3baec64c0f 100644 --- a/main/announcements/announcement_email.class.php +++ b/main/announcements/announcement_email.class.php @@ -222,6 +222,7 @@ class AnnouncementEmail $content = $this->announcement('content'); $content = stripslashes($content); + $content = AnnouncementManager::parse_content($content, $this->course('code')); $user_firstname = $this->sender('firstName'); $user_lastname = $this->sender('lastName'); diff --git a/main/inc/lib/autoload.class.php b/main/inc/lib/autoload.class.php index 49f06b2044..78092c7e8a 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'; @@ -122,6 +123,9 @@ class Autoload $result['FillBlanks'] = '/main/exercice/fill_blanks.class.php'; $result['FlatViewDataGenerator'] = '/main/gradebook/lib/flatview_data_generator.class.php'; $result['FlatViewTable'] = '/main/gradebook/lib/fe/flatviewtable.class.php'; + $result['FormElement'] = '/main/media/lib/form_element.class.php'; + $result['FormElementTextarea'] = '/main/media/lib/form_element_textarea.class.php'; + $result['FormRule'] = '/main/media/lib/form_rule.class.php'; $result['FormValidator'] = '/main/inc/lib/formvalidator/FormValidator.class.php'; $result['Forum'] = '/main/coursecopy/classes/Forum.class.php'; $result['ForumCategory'] = '/main/coursecopy/classes/ForumCategory.class.php'; @@ -211,8 +215,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'; @@ -225,6 +231,8 @@ class Autoload $result['Login'] = '/main/inc/lib/login.lib.php'; $result['LoginRedirection'] = '/main/inc/lib/login_redirection.class.php'; $result['Matching'] = '/main/exercice/matching.class.php'; + $result['Media'] = '/main/media/model/media.class.php'; + $result['MediaForm'] = '/main/media/lib/media_form.class.php'; $result['MessageManager'] = '/main/inc/lib/message.lib.php'; $result['MultipleAnswer'] = '/main/exercice/multiple_answer.class.php'; $result['MultipleAnswerCombination'] = '/main/exercice/multiple_answer_combination.class.php'; @@ -249,6 +257,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 +400,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'; @@ -420,6 +430,7 @@ class Autoload $result['xhtdoc'] = '/main/inc/lib/xht.lib.php'; $result['xmddoc'] = '/main/inc/lib/xmd.lib.php'; + return $result; } @@ -483,7 +494,12 @@ class AutoloadClassFinder ksort($this->map); } - public function to_string() + public function __invoke() + { + $this->run(); + } + + public function __toString() { $result = array(); diff --git a/main/inc/lib/chamilo.class.php b/main/inc/lib/chamilo.class.php index fac36aec69..72b61644a4 100644 --- a/main/inc/lib/chamilo.class.php +++ b/main/inc/lib/chamilo.class.php @@ -39,7 +39,12 @@ class Chamilo { return Uri::url($path, $params, $html); } - + + public static function here($params = array(), $html = true) + { + return Uri::here($params, $html); + } + /** * Application web root */ @@ -57,6 +62,11 @@ class Chamilo { return api_get_path(SYS_PATH); } + + public static function root_courses() + { + return api_get_path(SYS_COURSE_PATH); + } public static function path($path = '') { diff --git a/main/inc/lib/course.lib.php b/main/inc/lib/course.lib.php index eeb19f5387..4c5a660c16 100644 --- a/main/inc/lib/course.lib.php +++ b/main/inc/lib/course.lib.php @@ -3710,5 +3710,35 @@ class CourseManager { return $result; } + /** + * + * + * @return ResultSet + */ + static function list_inactive_courses($ceiling, $visibility_level = COURSE_VISIBILITY_REGISTERED) + { + $ceiling = is_numeric($ceiling) ? (int) $ceiling : strtotime($ceiling); + $ceiling = date('Y-m-d H:i:s', $ceiling); + $visibility_level = $visibility_level ? $visibility_level : '0'; + + $table_course = Database::get_main_table(TABLE_MAIN_COURSE); + $table_category = Database::get_main_table(TABLE_MAIN_CATEGORY); + $sql = "SELECT + c.*, + cat.name AS category + FROM + $table_course AS c + LEFT JOIN + $table_category AS cat + ON + c.category_code = cat.code + WHERE + c.visibility >= $visibility_level AND + c.last_visit<='$ceiling' + "; + + return ResultSet::create($sql); + } + } //end class CourseManager \ No newline at end of file diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index 2bede44968..6573a4bfaf 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -86,6 +86,11 @@ class Display { public static function display_footer() { 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/formvalidator/FormValidator.class.php b/main/inc/lib/formvalidator/FormValidator.class.php index 645303c41c..b59afa5329 100644 --- a/main/inc/lib/formvalidator/FormValidator.class.php +++ b/main/inc/lib/formvalidator/FormValidator.class.php @@ -143,6 +143,7 @@ class FormValidator extends HTML_QuickForm $this->registerRule('username', null, 'HTML_QuickForm_Rule_Username', $dir . 'Rule/Username.php'); $this->registerRule('filetype', null, 'HTML_QuickForm_Rule_Filetype', $dir . 'Rule/Filetype.php'); $this->registerRule('multiple_required', 'required', 'HTML_QuickForm_Rule_MultipleRequired', $dir . 'Rule/MultipleRequired.php'); + $this->registerRule('url', null, 'HTML_QuickForm_Rule_Url', $dir . 'Rule/Url.php'); // Modify the default templates $renderer = & $this->defaultRenderer(); diff --git a/main/inc/lib/formvalidator/Rule/Url.php b/main/inc/lib/formvalidator/Rule/Url.php new file mode 100644 index 0000000000..5267aa7f07 --- /dev/null +++ b/main/inc/lib/formvalidator/Rule/Url.php @@ -0,0 +1,27 @@ +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; }