diff --git a/main/admin/settings.php b/main/admin/settings.php index 00811fd78e..82d95226a2 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -1,4 +1,4 @@ - 'index.php', "name" => get_lang('PlatformAd $tool_name = get_lang('DokeosConfigSettings'); // Build the form -if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['category'] <> "stylesheets") -{ +if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['category'] <> "stylesheets") { $form = new FormValidator('settings', 'post', 'settings.php?category='.$_GET['category']); $renderer = & $form->defaultRenderer(); - $renderer->setHeaderTemplate('
{header}
'."\n"); - $renderer->setElementTemplate('
{label}
'."\n".'
{element}
'."\n"); - $my_category = mysql_real_escape_string($_GET['category']); + $renderer->setHeaderTemplate('
{header}
'."\n"); + $renderer->setElementTemplate('
{label}
'."\n".'
{element}
'."\n"); + $my_category = Database::escape_string($_GET['category']); - if ($_configuration['access_url']==1) - { + if ($_configuration['access_url']==1) { $settings = api_get_settings($my_category,'group',$_configuration['access_url']); - } - else - { + } else { $url_info = api_get_access_url($_configuration['access_url']); - if ($url_info['active']==1) - { + if ($url_info['active']==1) { //the default settings of Dokeos $settings = api_get_settings($my_category,'group',1,0); //the settings that are changeable from a particular site @@ -99,19 +93,22 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate //echo '
';
 			//print_r($settings_by_access);
 			$settings_by_access_list=array();
-			foreach($settings_by_access as $row)
-			{
-				if (empty($row['variable']))
+			foreach($settings_by_access as $row) {
+				if (empty($row['variable'])) {
 					$row['variable']=0;
-				if (empty($row['subkey']))
-					$row['subkey']=0;
-				if (empty($row['category']))
+				}
+				if (empty($row['subkey'])) {
+						$row['subkey']=0;
+				}
+				if (empty($row['category'])) {
 					$row['category']=0;
+				}
 				// one more validation if is changeable
-				if ($row['access_url_changeable']==1)
+				if ($row['access_url_changeable']==1) {
 					$settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ]	[ $row['category'] ]  = $row;
-				else
+				} else {
 					$settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ]	[ $row['category'] ]  = array();
+				}
 			}	
 		}
 	}
@@ -121,31 +118,28 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
 	//$resultsettings = api_sql_query($sqlsettings, __FILE__, __LINE__);
 	//while ($row = mysql_fetch_array($resultsettings))
 	$default_values = array();
-	foreach($settings as $row)
-	{
+	foreach ($settings as $row) {
 		$form->addElement('header', null, get_lang($row['title']));
 		$hideme=array();
 		$hide_element=false;
-		if ($_configuration['access_url']!=1)
-		{
-			if ($row['access_url_changeable']==0)
-			{
+		if ($_configuration['access_url']!=1) {
+			if ($row['access_url_changeable']==0) {
 				//we hide the element in other cases (checkbox, radiobutton) we 'freeze' the element
 				$hide_element=true;
 				$hideme=array('disabled');
-			}
-			elseif($url_info['active']==1)
-			{
+			} elseif($url_info['active']==1) {
 				// we show the elements 
-				if (empty($row['variable']))
+				if (empty($row['variable'])) {
 					$row['variable']=0;
-				if (empty($row['subkey']))
+				}	
+				if (empty($row['subkey'])) {
 					$row['subkey']=0;
-				if (empty($row['category']))
+				}
+				if (empty($row['category'])) {
 					$row['category']=0;
-					
-				if (is_array ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ]	[ $row['category'] ]))
-				{
+				}
+
+				if (is_array ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ]	[ $row['category'] ])) {
 					// we are sure that the other site have a selected value 
 					if ($settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ]	[ $row['category'] ]['selected_value']!='')											
 						$row['selected_value']	=$settings_by_access_list[$row['variable']] [$row['subkey']]	[ $row['category'] ]['selected_value'];
@@ -154,8 +148,7 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
 			}	
 		}	
 				
-		switch ($row['type'])
-		{
+		switch ($row['type']) {
 			case 'textfield' :						
 				$form->addElement('text', $row['variable'], get_lang($row['comment']),$hideme);
 				$default_values[$row['variable']] = $row['selected_value'];
@@ -167,10 +160,9 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
 			case 'radio' :
 				$values = get_settings_options($row['variable']);
 				$group = array ();
-				foreach ($values as $key => $value)
-				{
+				foreach ($values as $key => $value) {
 					$element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
-					if ($hide_element)
+					if ($hide_element) 
 						$element->freeze();
 					$group[] = $element; 
 				}
@@ -182,15 +174,14 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
 				$sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."'";
 				$result = api_sql_query($sql, __FILE__, __LINE__);
 				$group = array ();	
-				while ($rowkeys = mysql_fetch_array($result))
-				{
+				while ($rowkeys = Database::fetch_array($result)) {
 					$element = & $form->createElement('checkbox', $rowkeys['subkey'], '', get_lang($rowkeys['subkeytext']));
-					if ($rowkeys['selected_value'] == 'true' && ! $form->isSubmitted())
-					{
+					if ($rowkeys['selected_value'] == 'true' && ! $form->isSubmitted()) {
 						$element->setChecked(true); 
 					}
-					if ($hide_element)
+					if ($hide_element) {
 						$element->freeze();
+					}	
 					$group[] = $element;
 				}
 				$form->addGroup($group, $row['variable'], get_lang($row['comment']), '
'."\n"); @@ -201,8 +192,7 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate } $form->addElement('submit', null, get_lang('Ok')); $form->setDefaults($default_values); - if ($form->validate()) - { + if ($form->validate()) { $values = $form->exportValues(); // the first step is to set all the variables that have type=checkbox of the category // to false as the checkbox that is unchecked is not in the $_POST data and can @@ -213,18 +203,13 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate //$sql = "UPDATE $table_settings_current SET selected_value='false' WHERE category='$my_category' AND type='checkbox'"; //$result = api_sql_query($sql, __FILE__, __LINE__); // Save the settings - foreach ($values as $key => $value) - { - if (!is_array($value)) - { + foreach ($values as $key => $value) { + if (!is_array($value)) { //$sql = "UPDATE $table_settings_current SET selected_value='".mysql_real_escape_string($value)."' WHERE variable='$key'"; //$result = api_sql_query($sql, __FILE__, __LINE__); $result = api_set_setting($key,$value,null,null,$_configuration['access_url']); - } - else - { - foreach ($value as $subkey => $subvalue) - { + } else { + foreach ($value as $subkey => $subvalue) { //$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'"; //$result = api_sql_query($sql, __FILE__, __LINE__); $result = api_set_setting($key,'true',$subkey,null,$_configuration['access_url']); @@ -241,8 +226,7 @@ Display :: display_header($tool_name); //api_display_tool_title($tool_name); // displaying the message that the settings have been stored -if (!empty($_GET['action']) && $_GET['action'] == "stored") -{ +if (!empty($_GET['action']) && $_GET['action'] == "stored") { Display :: display_normal_message($SettingsStored); } @@ -264,20 +248,18 @@ $action_images['stylesheets'] = 'theme.gif'; //$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')"; //$resultcategories = api_sql_query($selectcategories, __FILE__, __LINE__); $resultcategories = api_get_settings_categories(array('stylesheets','Plugins')); -echo "\n
"; +echo "\n
"; +echo "\n\t
  • ".ucfirst(get_lang('Plugins'))."
  • "; +echo "\n\t
  • ".ucfirst(get_lang('Stylesheets'))."
  • "; +echo "\n
    "; -if (isset ($_GET['category'])) -{ - switch ($_GET['category']) - { +if (isset ($_GET['category'])) { + switch ($_GET['category']) { // displaying the extensions: plugins // this will be available to all the sites (access_urls) case 'Plugins' : @@ -291,16 +273,12 @@ if (isset ($_GET['category'])) $form->display(); } } - /* ============================================================================== FOOTER ============================================================================== */ Display :: display_footer(); - - - /* ============================================================================== FUNCTIONS @@ -310,32 +288,27 @@ Display :: display_footer(); * The function that retrieves all the possible settings for a certain config setting * @author Patrick Cool , Ghent University */ -function get_settings_options($var) -{ +function get_settings_options($var) { $table_settings_options = Database :: get_main_table(TABLE_MAIN_SETTINGS_OPTIONS); $sql = "SELECT * FROM $table_settings_options WHERE variable='$var'"; $result = api_sql_query($sql, __FILE__, __LINE__); - while ($row = mysql_fetch_array($result)) - { + while ($row = Database::fetch_array($result)) { $temp_array = array ('value' => $row['value'], 'display_text' => $row['display_text']); $settings_options_array[] = $temp_array; } return $settings_options_array; } - /** * This function allows easy activating and inactivating of plugins * @todo: a similar function needs to be written to activate or inactivate additional tools. * @author Patrick Cool , Ghent University */ -function handle_plugins() -{ +function handle_plugins() { global $SettingsStored; $userplugins = array(); $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); - if (!empty($_POST['submit_plugins'])) - { + if (!empty($_POST['submit_plugins'])) { store_plugins(); Display :: display_normal_message($SettingsStored); } @@ -346,10 +319,8 @@ function handle_plugins() $pluginpath = api_get_path(SYS_PLUGIN_PATH); $handle = @opendir($pluginpath); - while (false !== ($file = readdir($handle))) - { - if ($file <> '.' AND $file <> '..' AND is_dir(api_get_path(SYS_PLUGIN_PATH).$file)) - { + while (false !== ($file = readdir($handle))) { + if ($file <> '.' AND $file <> '..' AND is_dir(api_get_path(SYS_PLUGIN_PATH).$file)) { $possibleplugins[] = $file; } } @@ -401,42 +372,34 @@ function handle_plugins() //$result = api_sql_query($sql); $result = api_get_settings('Plugins'); //while ($row = mysql_fetch_array($result)) - foreach($result as $row) - { + foreach($result as $row) { $usedplugins[$row['variable']][] = $row['selected_value']; } /* We display all the possible plugins and the checkboxes */ - foreach ($possibleplugins as $testplugin) - { + foreach ($possibleplugins as $testplugin) { $plugin_info_file = api_get_path(SYS_PLUGIN_PATH).$testplugin."/plugin.php"; - if (file_exists($plugin_info_file)) - { + if (file_exists($plugin_info_file)) { $plugin_info = array(); include ($plugin_info_file); echo "\t\n"; echo "\t\t\n"; - foreach ($plugin_info as $key => $value) - { - if ($key <> 'location') - { - if ($key == 'title') - { + foreach ($plugin_info as $key => $value) { + if ($key <> 'location') { + if ($key == 'title') { $value = ''.$value.''; } echo get_lang(ucwords($key)).': '.$value.'
    '; } } - if (file_exists(api_get_path(SYS_PLUGIN_PATH).$testplugin.'/readme.txt')) - { + if (file_exists(api_get_path(SYS_PLUGIN_PATH).$testplugin.'/readme.txt')) { echo "readme.txt"; } echo "\t\t\n"; // column: LoginPageMainArea - if(empty($usedplugins)) - { + if (empty($usedplugins)) { $usedplugins = array(); } display_plugin_cell('loginpage_main', $plugin_info, $testplugin, $usedplugins); @@ -451,23 +414,16 @@ function handle_plugins() } } echo ''; - echo ''; - } - +} -function display_plugin_cell($location, $plugin_info, $current_plugin, $active_plugins) -{ +function display_plugin_cell($location, $plugin_info, $current_plugin, $active_plugins) { echo "\t\t\n"; - if (in_array($location, $plugin_info['location'])) - { + if (in_array($location, $plugin_info['location'])) { if (isset($active_plugins[$location]) && is_array($active_plugins[$location]) - && in_array($current_plugin, $active_plugins[$location])) - { + && in_array($current_plugin, $active_plugins[$location])) { $checked = "checked"; - } - else - { + } else { $checked = ''; } echo ''; @@ -479,25 +435,20 @@ function display_plugin_cell($location, $plugin_info, $current_plugin, $active_p * This function allows the platform admin to choose the default stylesheet * @author Patrick Cool , Ghent University */ -function handle_stylesheets() -{ +function handle_stylesheets() { global $_configuration; // Current style $currentstyle = api_get_setting('stylesheets'); $is_style_changeable=false; - if ($_configuration['access_url']!=1) - { + if ($_configuration['access_url']!=1) { $style_info = api_get_settings('stylesheets','',1,0); $url_info = api_get_access_url($_configuration['access_url']); - if ($style_info[0]['access_url_changeable']==1 && $url_info['active']==1) - { + if ($style_info[0]['access_url_changeable']==1 && $url_info['active']==1) { $is_style_changeable=true; echo ''.get_lang('UploadNewStylesheet').''; } - } - else - { + } else { $is_style_changeable=true; echo ''.get_lang('UploadNewStylesheet').''; } @@ -510,39 +461,26 @@ function handle_stylesheets() $form->addRule('new_stylesheet', get_lang('InvalidExtension').' ('.implode(',', $allowed_file_types).')', 'filetype', $allowed_file_types); $form->addRule('new_stylesheet', get_lang('ThisFieldIsRequired'), 'required'); $form->addElement('submit', 'stylesheet_upload', get_lang('Ok')); - if( $form->validate() AND is_writable(api_get_path(SYS_CODE_PATH).'css/')) - { + if( $form->validate() AND is_writable(api_get_path(SYS_CODE_PATH).'css/')) { $values = $form->exportValues(); $picture_element = & $form->getElement('new_stylesheet'); $picture = $picture_element->getValue(); upload_stylesheet($values, $picture); Display::display_confirmation_message(get_lang('StylesheetAdded')); - } - else - { - if (!is_writable(api_get_path(SYS_CODE_PATH).'css/')) - { + } else { + if (!is_writable(api_get_path(SYS_CODE_PATH).'css/')) { Display::display_error_message(api_get_path(SYS_CODE_PATH).'css/'.get_lang('IsNotWritable')); - } - else - { - if ($_GET['showuploadform'] == 'true') - { + } else { + if ($_GET['showuploadform'] == 'true') { echo '
    '; - } - else - { + } else { echo '