Browse Source

Minor - Clean admin/index.php and move register_site() to api_register_site() in main_api

Yannick Warnier 10 years ago
parent
commit
201849a3a2
2 changed files with 135 additions and 133 deletions
  1. 114 133
      main/admin/index.php
  2. 21 0
      main/inc/lib/main_api.lib.php

+ 114 - 133
main/admin/index.php

@@ -36,26 +36,27 @@ if (api_is_platform_admin()) {
     }
     */
     if (is_dir(api_get_path(SYS_ARCHIVE_PATH)) && !is_writable(api_get_path(SYS_ARCHIVE_PATH))) {
-        $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'),'warning');
+        $message = Display::return_message(get_lang('ArchivesDirectoryNotWriteableContactAdmin'), 'warning');
     }
 
     /* ACTION HANDLING */
     if (!empty($_POST['Register'])) {
-        register_site();
-        $message = Display :: return_message(get_lang('VersionCheckEnabled'),'confirmation');
+        api_register_campus(!$_POST['donotlistcampus']);
+        $message = Display :: return_message(get_lang('VersionCheckEnabled'), 'confirmation');
     }
     $keyword_url = Security::remove_XSS((empty($_GET['keyword']) ? '' : $_GET['keyword']));
 }
 
 if (isset($_GET['msg']) && isset($_GET['type'])) {
-	if (in_array($_GET['msg'], array('ArchiveDirCleanupSucceeded', 'ArchiveDirCleanupFailed')))
-	switch($_GET['type']) {
-		case 'error':
-			$message = Display::return_message(get_lang($_GET['msg']), 'error');
-			break;
-		case 'confirmation':
-			$message = Display::return_message(get_lang($_GET['msg']), 'confirm');
-	}
+    if (in_array($_GET['msg'], array('ArchiveDirCleanupSucceeded', 'ArchiveDirCleanupFailed'))) {
+        switch ($_GET['type']) {
+            case 'error':
+                $message = Display::return_message(get_lang($_GET['msg']), 'error');
+                break;
+            case 'confirmation':
+                $message = Display::return_message(get_lang($_GET['msg']), 'confirm');
+        }
+    }
 }
 
 $blocks = array();
@@ -67,33 +68,34 @@ $blocks['users']['label'] = api_ucfirst(get_lang('Users'));
 $blocks['users']['class'] = 'block-admin-users';
 
 if (api_is_platform_admin()) {
-	$search_form = ' <form method="get" class="form-search" action="user_list.php">
-						<input class="span3" type="text" name="keyword" value="">
-						<button class="btn" type="submit">'.get_lang('Search').'</button>
-            		</form>';
-	$blocks['users']['search_form'] = $search_form;
-	$items = array(
-		array('url'=>'user_list.php', 	'label' => get_lang('UserList')),
-		array('url'=>'user_add.php', 	'label' => get_lang('AddUsers')),
-		array('url'=>'user_export.php', 'label' => get_lang('ExportUserListXMLCSV')),
-		array('url'=>'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
-               array('url'=>'user_update_import.php', 'label' => get_lang('EditUserListCSV')),
-	);
-
-	if (api_get_setting('allow_social_tool') == 'true') {
-		$items[] = array('url'=>'group_add.php', 	'label' => get_lang('AddGroups'));
-		$items[] = array('url'=>'group_list.php', 	'label' => get_lang('GroupList'));
-	}
-	if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
-		$items[] = array('url'=>'ldap_users_list.php', 	'label' => get_lang('ImportLDAPUsersIntoPlatform'));
-	}
-	$items[] = array('url'=>'user_fields.php', 	'label' => get_lang('ManageUserFields'));
+    $search_form = '
+            <form method="get" class="form-search" action="user_list.php">
+                <input class="span3" type="text" name="keyword" value="">
+                <button class="btn" type="submit">'.get_lang('Search').'</button>
+            </form>';
+    $blocks['users']['search_form'] = $search_form;
+    $items = array(
+        array('url'=>'user_list.php', 	'label' => get_lang('UserList')),
+        array('url'=>'user_add.php', 	'label' => get_lang('AddUsers')),
+        array('url'=>'user_export.php', 'label' => get_lang('ExportUserListXMLCSV')),
+        array('url'=>'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
+        array('url'=>'user_update_import.php', 'label' => get_lang('EditUserListCSV')),
+    );
+
+    if (api_get_setting('allow_social_tool') == 'true') {
+        $items[] = array('url'=>'group_add.php', 	'label' => get_lang('AddGroups'));
+        $items[] = array('url'=>'group_list.php', 	'label' => get_lang('GroupList'));
+    }
+    if (isset($extAuthSource) && isset($extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
+        $items[] = array('url'=>'ldap_users_list.php', 	'label' => get_lang('ImportLDAPUsersIntoPlatform'));
+    }
+    $items[] = array('url'=>'user_fields.php', 	'label' => get_lang('ManageUserFields'));
 } else {
- 	$items = array(
- 		array('url'=>'user_list.php', 	'label' => get_lang('UserList')),
- 		array('url'=>'user_add.php', 	'label' => get_lang('AddUsers')),
- 		array('url'=>'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
- 	);
+    $items = array(
+        array('url'=>'user_list.php', 	'label' => get_lang('UserList')),
+        array('url'=>'user_add.php', 	'label' => get_lang('AddUsers')),
+        array('url'=>'user_import.php', 'label' => get_lang('ImportUserListXMLCSV')),
+    );
 }
 
 $items[] = array('url'=>'usergroups.php', 	'label' => get_lang('Classes'));
@@ -102,33 +104,33 @@ $blocks['users']['items'] = $items;
 $blocks['users']['extra'] = null;
 
 if (api_is_platform_admin()) {
-	/* Courses */
-	$blocks['courses']['icon']  = Display::return_icon('course.gif', get_lang('Courses'), array(), ICON_SIZE_MEDIUM, false);
-	$blocks['courses']['label'] = api_ucfirst(get_lang('Courses'));
+    /* Courses */
+    $blocks['courses']['icon']  = Display::return_icon('course.gif', get_lang('Courses'), array(), ICON_SIZE_MEDIUM, false);
+    $blocks['courses']['label'] = api_ucfirst(get_lang('Courses'));
     $blocks['courses']['class'] = 'block-admin-courses';
 
-	$search_form = ' <form method="get" class="form-search" action="course_list.php">
+    $search_form = ' <form method="get" class="form-search" action="course_list.php">
 							<input class="span3" type="text" name="keyword" value="">
 							<button class="btn" type="submit">'.get_lang('Search').'</button>
 	            		</form>';
-	$blocks['courses']['search_form'] = $search_form;
+    $blocks['courses']['search_form'] = $search_form;
 
-	$items = array();
-	$items[] = array('url'=>'course_list.php', 	'label' => get_lang('CourseList'));
-  $items[] = array('url'=>'course_add.php', 	'label' => get_lang('AddCourse'));
+    $items = array();
+    $items[] = array('url'=>'course_list.php', 	'label' => get_lang('CourseList'));
+    $items[] = array('url'=>'course_add.php', 	'label' => get_lang('AddCourse'));
 
-  if (api_get_setting('course_validation') == 'true') {
+    if (api_get_setting('course_validation') == 'true') {
 
-		$items[] = array('url'=>'course_request_review.php', 	'label' => get_lang('ReviewCourseRequests'));
-		$items[] = array('url'=>'course_request_accepted.php', 	'label' => get_lang('AcceptedCourseRequests'));
-		$items[] = array('url'=>'course_request_rejected.php', 	'label' => get_lang('RejectedCourseRequests'));
-	}
+        $items[] = array('url'=>'course_request_review.php', 	'label' => get_lang('ReviewCourseRequests'));
+        $items[] = array('url'=>'course_request_accepted.php', 	'label' => get_lang('AcceptedCourseRequests'));
+        $items[] = array('url'=>'course_request_rejected.php', 	'label' => get_lang('RejectedCourseRequests'));
+    }
 
-	$items[] = array('url'=>'course_export.php', 			'label' => get_lang('ExportCourses'));
-	$items[] = array('url'=>'course_import.php', 			'label' => get_lang('ImportCourses'));
-	$items[] = array('url'=>'course_category.php', 			'label' => get_lang('AdminCategories'));
-	$items[] = array('url'=>'subscribe_user2course.php', 	'label' => get_lang('AddUsersToACourse'));
-	$items[] = array('url'=>'course_user_import.php', 		'label' => get_lang('ImportUsersToACourse'));
+    $items[] = array('url'=>'course_export.php', 			'label' => get_lang('ExportCourses'));
+    $items[] = array('url'=>'course_import.php', 			'label' => get_lang('ImportCourses'));
+    $items[] = array('url'=>'course_category.php', 			'label' => get_lang('AdminCategories'));
+    $items[] = array('url'=>'subscribe_user2course.php', 	'label' => get_lang('AddUsersToACourse'));
+    $items[] = array('url'=>'course_user_import.php', 		'label' => get_lang('ImportUsersToACourse'));
     //$items[] = array('url'=>'course_intro_pdf_import.php', 	'label' => get_lang('ImportPDFIntroToCourses'));
 
     if (api_get_setting('gradebook_enable_grade_model') == 'true') {
@@ -173,18 +175,18 @@ if (api_is_platform_admin()) {
     }
 
     if (!empty($_configuration['multiple_access_urls'])) {
-		if (api_is_global_platform_admin()) {
-            	$items[] = array('url'=>'access_urls.php', 	'label' => get_lang('ConfigureMultipleAccessURLs'));
-            }
+        if (api_is_global_platform_admin()) {
+            $items[] = array('url'=>'access_urls.php', 	'label' => get_lang('ConfigureMultipleAccessURLs'));
+        }
     }
 
     if (api_get_setting('allow_reservation') == 'true') {
-    	$items[] = array('url'=>'../reservation/m_category.php', 	'label' => get_lang('BookingSystem'));
-	}
-	if (api_get_setting('allow_terms_conditions') == 'true') {
-    	$items[] = array('url'=>'legal_add.php', 	'label' => get_lang('TermsAndConditions'));
-	}
-	$blocks['platform']['items'] = $items;
+        $items[] = array('url'=>'../reservation/m_category.php', 	'label' => get_lang('BookingSystem'));
+    }
+    if (api_get_setting('allow_terms_conditions') == 'true') {
+        $items[] = array('url'=>'legal_add.php', 	'label' => get_lang('TermsAndConditions'));
+    }
+    $blocks['platform']['items'] = $items;
     $blocks['platform']['extra'] = null;
 }
 
@@ -225,21 +227,21 @@ $blocks['sessions']['extra'] = null;
 /* Settings */
 if (api_is_platform_admin()) {
 
-	$blocks['settings']['icon']  = Display::return_icon('settings.png', get_lang('System'), array(), ICON_SIZE_SMALL, false);
-	$blocks['settings']['label'] = api_ucfirst(get_lang('System'));
+    $blocks['settings']['icon']  = Display::return_icon('settings.png', get_lang('System'), array(), ICON_SIZE_SMALL, false);
+    $blocks['settings']['label'] = api_ucfirst(get_lang('System'));
     $blocks['settings']['class'] = 'block-admin-settings';
 
 
     $items = array();
-	$items[] = array('url'=>'special_exports.php', 	'label' => get_lang('SpecialExports'));
-	if (!empty($_configuration['db_admin_path'])) {
-		$items[] = array('url'=>$_configuration['db_admin_path'], 	'label' => get_lang('AdminDatabases').' ('.get_lang('DBManagementOnlyForServerAdmin').') ');
-	}
-	$items[] = array('url'=>'system_status.php', 	'label' => get_lang('SystemStatus'));
-	if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) {
-		$items[] = array('url'=>'filler.php', 	'label' => get_lang('DataFiller'));
-	}
-	$items[] = array('url'=>'archive_cleanup.php', 	'label' => get_lang('ArchiveDirCleanup'));
+    $items[] = array('url'=>'special_exports.php', 	'label' => get_lang('SpecialExports'));
+    if (!empty($_configuration['db_admin_path'])) {
+        $items[] = array('url'=>$_configuration['db_admin_path'], 	'label' => get_lang('AdminDatabases').' ('.get_lang('DBManagementOnlyForServerAdmin').') ');
+    }
+    $items[] = array('url'=>'system_status.php', 	'label' => get_lang('SystemStatus'));
+    if (is_dir(api_get_path(SYS_TEST_PATH).'datafiller/')) {
+        $items[] = array('url'=>'filler.php', 	'label' => get_lang('DataFiller'));
+    }
+    $items[] = array('url'=>'archive_cleanup.php', 	'label' => get_lang('ArchiveDirCleanup'));
     if (api_get_setting('server_type') === 'test') {
         $items[] = array('url'=>'system_management.php', 'label' => get_lang('SystemManagement'));
     }
@@ -255,26 +257,26 @@ if (api_is_platform_admin()) {
         $items[] = array('url'=>"db.php?username=$username&db=$databaseName&server=$host", 'label' => get_lang('Database Manager'));
     }
 
-	$blocks['settings']['items'] = $items;
+    $blocks['settings']['items'] = $items;
     $blocks['settings']['extra'] = null;
 
     $blocks['settings']['search_form'] = null;
 
-	/* Extensions */
-	/*
-	$blocks['extensions']['icon']  = Display::return_icon('visio_meeting.gif', get_lang('ConfigureExtensions'), array(), ICON_SIZE_SMALL, false);
-	$blocks['extensions']['label'] = api_ucfirst(get_lang('ConfigureExtensions'));
-	$blocks['extensions']['class'] = 'block-admin-extensions';
-
-
-	$items = array();
-	$items[] = array('url'=>'configure_extensions.php?display=visio', 	'label' => get_lang('Visioconf'));
-	$items[] = array('url'=>'configure_extensions.php?display=ppt2lp', 	'label' => get_lang('Ppt2lp'));
-	//$items[] = array('url'=>'configure_extensions.php?display=ephorus', 	'label' => get_lang('EphorusPlagiarismPrevention'));
-	$items[] = array('url'=>'configure_extensions.php?display=search', 	'label' => get_lang('SearchEngine'));
-	$items[] = array('url'=>'configure_extensions.php?display=serverstats', 	'label' => get_lang('ServerStatistics'));
-	$items[] = array('url'=>'configure_extensions.php?display=bandwidthstats', 	'label' => get_lang('BandWidthStatistics'));
-	$blocks['extensions']['items'] = $items;
+    /* Extensions */
+    /*
+    $blocks['extensions']['icon']  = Display::return_icon('visio_meeting.gif', get_lang('ConfigureExtensions'), array(), ICON_SIZE_SMALL, false);
+    $blocks['extensions']['label'] = api_ucfirst(get_lang('ConfigureExtensions'));
+    $blocks['extensions']['class'] = 'block-admin-extensions';
+
+
+    $items = array();
+    $items[] = array('url'=>'configure_extensions.php?display=visio', 	'label' => get_lang('Visioconf'));
+    $items[] = array('url'=>'configure_extensions.php?display=ppt2lp', 	'label' => get_lang('Ppt2lp'));
+    //$items[] = array('url'=>'configure_extensions.php?display=ephorus', 	'label' => get_lang('EphorusPlagiarismPrevention'));
+    $items[] = array('url'=>'configure_extensions.php?display=search', 	'label' => get_lang('SearchEngine'));
+    $items[] = array('url'=>'configure_extensions.php?display=serverstats', 	'label' => get_lang('ServerStatistics'));
+    $items[] = array('url'=>'configure_extensions.php?display=bandwidthstats', 	'label' => get_lang('BandWidthStatistics'));
+    $blocks['extensions']['items'] = $items;
     */
 
     //Skills
@@ -296,38 +298,38 @@ if (api_is_platform_admin()) {
         $blocks['skills']['search_form'] = null;
     }
 
-	/* Chamilo.org */
+    /* Chamilo.org */
 
-	$blocks['chamilo']['icon']  = Display::return_icon('logo.png', 'Chamilo.org', array(), ICON_SIZE_SMALL, false);
-	$blocks['chamilo']['label'] = 'Chamilo.org';
+    $blocks['chamilo']['icon']  = Display::return_icon('logo.png', 'Chamilo.org', array(), ICON_SIZE_SMALL, false);
+    $blocks['chamilo']['label'] = 'Chamilo.org';
     $blocks['chamilo']['class'] = 'block-admin-chamilo';
 
 
     $items = array();
-	$items[] = array('url'=>'http://www.chamilo.org/', 	'label' => get_lang('ChamiloHomepage'));
-	$items[] = array('url'=>'http://www.chamilo.org/forum', 	'label' => get_lang('ChamiloForum'));
-
-	$items[] = array('url'=>'../../documentation/installation_guide.html', 	'label' => get_lang('InstallationGuide'));
-	$items[] = array('url'=>'../../documentation/changelog.html', 	'label' => get_lang('ChangesInLastVersion'));
-	$items[] = array('url'=>'../../documentation/credits.html', 	'label' => get_lang('ContributorsList'));
-	$items[] = array('url'=>'../../documentation/security.html', 	'label' => get_lang('SecurityGuide'));
-	$items[] = array('url'=>'../../documentation/optimization.html', 	'label' => get_lang('OptimizationGuide'));
-	$items[] = array('url'=>'http://www.chamilo.org/extensions', 	'label' => get_lang('ChamiloExtensions'));
-	$items[] = array('url'=>'http://www.chamilo.org/en/providers', 	'label' => get_lang('ChamiloOfficialServicesProviders'));
-
-	$blocks['chamilo']['items'] = $items;
+    $items[] = array('url'=>'http://www.chamilo.org/', 	'label' => get_lang('ChamiloHomepage'));
+    $items[] = array('url'=>'http://www.chamilo.org/forum', 	'label' => get_lang('ChamiloForum'));
+
+    $items[] = array('url'=>'../../documentation/installation_guide.html', 	'label' => get_lang('InstallationGuide'));
+    $items[] = array('url'=>'../../documentation/changelog.html', 	'label' => get_lang('ChangesInLastVersion'));
+    $items[] = array('url'=>'../../documentation/credits.html', 	'label' => get_lang('ContributorsList'));
+    $items[] = array('url'=>'../../documentation/security.html', 	'label' => get_lang('SecurityGuide'));
+    $items[] = array('url'=>'../../documentation/optimization.html', 	'label' => get_lang('OptimizationGuide'));
+    $items[] = array('url'=>'http://www.chamilo.org/extensions', 	'label' => get_lang('ChamiloExtensions'));
+    $items[] = array('url'=>'http://www.chamilo.org/en/providers', 	'label' => get_lang('ChamiloOfficialServicesProviders'));
+
+    $blocks['chamilo']['items'] = $items;
     $blocks['chamilo']['extra'] = null;
     $blocks['chamilo']['search_form'] = null;
 
-	// Try to display a maximum before we check the chamilo version and all that.
-	//session_write_close(); //close session to avoid blocking concurrent access
-	//flush(); //send data to client as much as allowed by the web server
-	//ob_flush();
+    // Try to display a maximum before we check the chamilo version and all that.
+    //session_write_close(); //close session to avoid blocking concurrent access
+    //flush(); //send data to client as much as allowed by the web server
+    //ob_flush();
 
     //Version check
     $blocks['version_check']['icon']  = Display::return_icon('logo.png', 'Chamilo.org', array(), ICON_SIZE_SMALL, false);
-	$blocks['version_check']['label'] = get_lang('VersionCheck');
-	$blocks['version_check']['extra'] = '<div class="admin-block-version"></div>';
+    $blocks['version_check']['label'] = get_lang('VersionCheck');
+    $blocks['version_check']['extra'] = '<div class="admin-block-version"></div>';
     $blocks['version_check']['search_form'] = null;
     $blocks['version_check']['items'] = null;
     $blocks['version_check']['class'] = 'block-admin-version_check';
@@ -345,25 +347,4 @@ $tpl->assign('content', $content);
 $tpl->assign('message', $message);
 $tpl->display_one_col_template();
 
-/**
- * This setting changes the registration status for the campus
- *
- * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
- * @version August 2006
- *
- * @todo the $_settings should be reloaded here. => write api function for this and use this in global.inc.php also.
- */
-function register_site() {
-    $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
-
-    $sql = "UPDATE $tbl_settings SET selected_value='true' WHERE variable='registered'";
-    Database::query($sql);
-
-    if ($_POST['donotlistcampus']) {
-        $sql = "UPDATE $tbl_settings SET selected_value='true' WHERE variable='donotlistcampus'";
-        Database::query($sql);
-    }
-    // Reload the settings.
-}
-
 // Note: version checking mechanism has now been moved to main/inc/ajax/admin.ajax.php

+ 21 - 0
main/inc/lib/main_api.lib.php

@@ -7563,3 +7563,24 @@ function api_get_supported_image_extensions()
     }
     return $supportedImageExtensions;
 }
+
+/**
+ * This setting changes the registration status for the campus
+ *
+ * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
+ * @version August 2006
+ * @param   bool    $listCampus Whether we authorize
+ * @todo the $_settings should be reloaded here. => write api function for this and use this in global.inc.php also.
+ */
+function api_register_campus($listCampus = true) {
+    $tbl_settings = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
+
+    $sql = "UPDATE $tbl_settings SET selected_value='true' WHERE variable='registered'";
+    Database::query($sql);
+
+    if (!$listCampus) {
+        $sql = "UPDATE $tbl_settings SET selected_value='true' WHERE variable='donotlistcampus'";
+        Database::query($sql);
+    }
+    // Reload the settings.
+}