diff --git a/main/admin/settings.php b/main/admin/settings.php index f7c4c11a95..159bcd2087 100644 --- a/main/admin/settings.php +++ b/main/admin/settings.php @@ -1,5 +1,5 @@ "Plugins" and $_GET['cate $renderer->setHeaderTemplate('
';
+ //print_r($settings_by_access);
+ $settings_by_access_list=array();
+ foreach($settings_by_access as $row)
+ {
+ if (empty($row['variable']))
+ $row['variable']=0;
+ 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)
+ $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = $row;
+ else
+ $settings_by_access_list[ $row['variable'] ] [ $row['subkey'] ] [ $row['category'] ] = array();
+ }
+ }
+ }
+
+ //print_r($settings_by_access_list);echo '';
//$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
//$resultsettings = api_sql_query($sqlsettings, __FILE__, __LINE__);
//while ($row = mysql_fetch_array($resultsettings))
@@ -89,14 +125,44 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
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)
+ {
+ //we hide the element in other cases (checkbox, radiobutton) we 'freeze' the element
+ $hide_element=true;
+ $hideme=array('disabled');
+ }
+ elseif($url_info['active']==1)
+ {
+ // we show the elements
+ if (empty($row['variable']))
+ $row['variable']=0;
+ if (empty($row['subkey']))
+ $row['subkey']=0;
+ if (empty($row['category']))
+ $row['category']=0;
+
+ 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'];
+ }
+ // there is no else because we load the default $row['selected_value'] of the main Dokeos site
+ }
+ }
+
switch ($row['type'])
{
- case 'textfield' :
- $form->addElement('text', $row['variable'], get_lang($row['comment']));
+ case 'textfield' :
+ $form->addElement('text', $row['variable'], get_lang($row['comment']),$hideme);
$default_values[$row['variable']] = $row['selected_value'];
break;
case 'textarea' :
- $form->addElement('textarea', $row['variable'], get_lang($row['comment']));
+ $form->addElement('textarea', $row['variable'], get_lang($row['comment']),$hideme);
$default_values[$row['variable']] = $row['selected_value'];
break;
case 'radio' :
@@ -104,28 +170,34 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
$group = array ();
foreach ($values as $key => $value)
{
- $group[] = $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
+ $element = & $form->createElement('radio', $row['variable'], '', get_lang($value['display_text']), $value['value']);
+ if ($hide_element)
+ $element->freeze();
+ $group[] = $element;
}
+
$form->addGroup($group, $row['variable'], get_lang($row['comment']), '';print_r($result_other_site);
+$result = api_get_settings(null,'list',1);
+
//while ($row=mysql_fetch_array($result))
foreach($result as $row)
-{
- if ($row['subkey']==NULL)
+{
+ if ($_configuration['access_url']!=1)
{
- $_setting[$row['variable']]=$row['selected_value'];
+ if ($url_info['active']==1)
+ {
+ if (empty($row['variable']))
+ $var=0;
+ else
+ $var=$row['variable'];
+
+ if (empty($row['subkey']))
+ $subkey=0;
+ else
+ $subkey=$row['subkey'];
+
+ if (empty($row['category']))
+ $category=0;
+ else
+ $category=$row['category'];
+ }
+
+ if ($row['access_url_changeable']==1 && $url_info['active']==1)
+ {
+ if ($settings_by_access_list[ $var ] [ $subkey ] [$category ]['selected_value'] !='')
+ {
+ if ($row['subkey']==NULL)
+ {
+ $_setting[$row['variable']]= $settings_by_access_list[ $var ] [ $subkey ] [$category ]['selected_value'];
+ }
+ else
+ {
+ $_setting[$row['variable']][$row['subkey']]=$settings_by_access_list[ $var ] [ $subkey ] [$category ]['selected_value'];
+ }
+ }
+ else
+ {
+ if ($row['subkey']==NULL)
+ {
+ $_setting[$row['variable']]=$row['selected_value'];
+ }
+ else
+ {
+ $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
+ }
+ }
+ }
+ else
+ {
+ if ($row['subkey']==NULL)
+ {
+ $_setting[$row['variable']]=$row['selected_value'];
+ }
+ else
+ {
+ $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
+ }
+ }
+
}
else
- {
- $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
- }
+ {
+ if ($row['subkey']==NULL)
+ {
+ $_setting[$row['variable']]=$row['selected_value'];
+ }
+ else
+ {
+ $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
+ }
+ }
}
+//echo '';print_r($_setting);echo '
';
// we have to store the settings for the plugins differently because it expects an array
//$sql="SELECT * FROM settings_current WHERE category='plugins'";
//$result=mysql_query($sql) or die(mysql_error());
diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php
index af054f835c..ffe302ee1c 100644
--- a/main/inc/lib/main_api.lib.php
+++ b/main/inc/lib/main_api.lib.php
@@ -6,6 +6,7 @@
Copyright (c) 2004-2008 Dokeos S.A.
Copyright (c) 2003 Ghent University (UGent)
Copyright (c) 2001 Universite catholique de Louvain (UCL)
+ Copyright (c) Julio Montoya
Copyright (c) Hugues Peeters
Copyright (c) Christophe Gesche
Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
@@ -306,20 +307,41 @@ function api_is_self_registration_allowed()
*/
function api_get_path($path_type)
{
- global $_configuration;
-
+ global $_configuration;
+ if ($_configuration['access_url']==1 || $_configuration['access_url']=='')
+ {
+ //by default we call the $_configuration['root_web'] we don't query to the DB
+ //$url_info= api_get_access_url(1);
+ //$root_web = $url_info['url'];
+ $root_web = $_configuration['root_web'];
+ }
+ else
+ {
+ //we look into the DB the function api_get_access_url
+ //this funcion have a problem because we can't called to the Database:: functions
+ $url_info= api_get_access_url($_configuration['access_url']);
+ if ($url_info['active']==1)
+ {
+ $root_web = $url_info['url'];
+ }
+ else
+ {
+ $root_web = $_configuration['root_web'];
+ }
+ }
+
switch ($path_type)
{
case WEB_PATH :
// example: http://www.mydokeos.com/ or http://www.mydokeos.com/portal/ if you're using
// a subdirectory of your document root for Dokeos
- if(substr($_configuration['root_web'],-1) == '/')
+ if(substr($root_web,-1) == '/')
{
- return $_configuration['root_web'];
+ return $root_web;
}
else
{
- return $_configuration['root_web'].'/';
+ return $root_web.'/';
}
break;
@@ -349,7 +371,7 @@ function api_get_path($path_type)
case WEB_COURSE_PATH :
// example: http://www.mydokeos.com/courses/
- return $_configuration['root_web'].$_configuration['course_folder'];
+ return $root_web.$_configuration['course_folder'];
break;
case SYS_COURSE_PATH :
@@ -367,7 +389,8 @@ function api_get_path($path_type)
break;
case WEB_CODE_PATH :
// example: http://www.mydokeos.com/main/
- return $GLOBALS['clarolineRepositoryWeb'];
+ //return $GLOBALS['clarolineRepositoryWeb']; // this was changed
+ return $root_web.$_configuration['code_append'];
break;
case SYS_CODE_PATH :
// example: /var/www/dokeos/main/
@@ -1288,7 +1311,7 @@ function api_is_coach()
global $_user;
global $sessionIsCoach;
- $sql = "SELECT DISTINCT id, name, date_start, date_end
+ $sql = "SELECT DISTINCT id, name, date_start, date_end
FROM session
INNER JOIN session_rel_course
ON session_rel_course.id_coach = '".mysql_real_escape_string($_user['user_id'])."'
@@ -2433,48 +2456,91 @@ function api_set_setting($var,$value,$subvar=null,$cat=null,$access_url=1)
else
{
$select .= " AND access_url = 1 ";
- }
+ }
$res = api_sql_query($select,__FILE__,__LINE__);
if(Database::num_rows($res)>0)
- { //found item for this access_url
+ { //found item for this access_url
$row = Database::fetch_array($res);
- $update = "UPDATE $t_settings SET selected_value = '$value' WHERE id = ".$row['id'];
+ $update = "UPDATE $t_settings SET selected_value = '$value' WHERE id = ".$row['id'] ;
$res = api_sql_query($update,__FILE__,__LINE__);
}
else
{ //item not found for this access_url, we have to check if the whole thing is missing
//(in which case we ignore the insert) or if there *is* a record but just for access_url=1
- $select = "SELECT * FROM $t_settings WHERE variable = '$var' AND access_url = 1 ";
- if(!empty($subvar))
- {
- $select .= " AND subkey = '$subvar'";
- }
- if(!empty($cat))
+ $select = "SELECT * FROM $t_settings WHERE variable = '$var' AND access_url = '1' ";
+ if ($access_url==1)
{
- $select .= " AND category = '$cat'";
- }
- $res = api_sql_query($select,__FILE__,__LINE__);
- if(Database::num_rows($select)>0)
- { //we have a setting for access_url 1, but none for the current one, so create one
- $row = Database::fetch_array($res);
- $insert = "INSERT INTO $t_settings " .
- "(variable,subkey," .
- "type,category," .
- "selected_value,title," .
- "comment,scope," .
- "subkeytext,access_url)" .
- " VALUES " .
- "('".$row['variable']."',".(!empty($row['subkey'])?"'".$row['subkey']."'":"NULL")."," .
- "'".$row['type']."','".$row['category']."'," .
- "'$value','".$row['title']."'," .
- "".(!empty($row['comment'])?"'".$row['comment']."'":"NULL").",'".(!empty($row['scope'])?"'".$row['scope']."'":"NULL")."'," .
- "'".(!empty($row['subkeytext'])?"'".$row['subkeytext']."'":"NULL")."',$access_url)";
- $res = api_sql_query($insert,__FILE__,__LINE__);
+ if(!empty($subvar))
+ {
+ $select .= " AND subkey = '$subvar'";
+ }
+ if(!empty($cat))
+ {
+ $select .= " AND category = '$cat'";
+ }
+ $res = api_sql_query($select,__FILE__,__LINE__);
+ if(Database::num_rows($select)>0)
+ { //we have a setting for access_url 1, but none for the current one, so create one
+ $row = Database::fetch_array($res);
+ echo $insert = "INSERT INTO $t_settings " .
+ "(variable,subkey," .
+ "type,category," .
+ "selected_value,title," .
+ "comment,scope," .
+ "subkeytext,access_url)" .
+ " VALUES " .
+ "('".$row['variable']."',".(!empty($row['subkey'])?"'".$row['subkey']."'":"NULL")."," .
+ "'".$row['type']."','".$row['category']."'," .
+ "'$value','".$row['title']."'," .
+ "".(!empty($row['comment'])?"'".$row['comment']."'":"NULL").",'".(!empty($row['scope'])?"'".$row['scope']."'":"NULL")."'," .
+ "'".(!empty($row['subkeytext'])?"'".$row['subkeytext']."'":"NULL")."',$access_url)";
+ $res = api_sql_query($insert,__FILE__,__LINE__);
+ }
+ else
+ { // this setting does not exist
+ error_log(__FILE__.':'.__LINE__.': Attempting to update setting '.$var.' ('.$subvar.') which does not exist at all',0);
+ }
}
else
- { // this setting does not exist
- error_log(__FILE__.':'.__LINE__.': Attempting to update setting '.$var.' ('.$subvar.') which does not exist at all',0);
- }
+ {
+ // other access url
+ if(!empty($subvar))
+ {
+ $select .= " AND subkey = '$subvar'";
+ }
+ if(!empty($cat))
+ {
+ $select .= " AND category = '$cat'";
+ }
+ $res = api_sql_query($select,__FILE__,__LINE__);
+
+ if(Database::num_rows($res)>0)
+ { //we have a setting for access_url 1, but none for the current one, so create one
+ $row = Database::fetch_array($res);
+ if ($row['access_url_changeable']==1)
+ {
+ $insert = "INSERT INTO $t_settings " .
+ "(variable,subkey," .
+ "type,category," .
+ "selected_value,title," .
+ "comment,scope," .
+ "subkeytext,access_url, access_url_changeable)" .
+ " VALUES " .
+ "('".$row['variable']."',".
+ (!empty($row['subkey'])?"'".$row['subkey']."'":"NULL")."," .
+ "'".$row['type']."','".$row['category']."'," .
+ "'$value','".$row['title']."'," .
+ "".(!empty($row['comment'])?"'".$row['comment']."'":"NULL").",".
+ (!empty($row['scope'])?"'".$row['scope']."'":"NULL")."," .
+ "'".(!empty($row['subkeytext'])?"'".$row['subkeytext']."'":"NULL")."',$access_url,".$row['access_url_changeable'].")";
+ $res = api_sql_query($insert,__FILE__,__LINE__);
+ }
+ }
+ else
+ { // this setting does not exist
+ error_log(__FILE__.':'.__LINE__.': Attempting to update setting '.$var.' ('.$subvar.') which does not exist at all. The access_url is: '.$access_url.' ',0);
+ }
+ }
}
}
/**
@@ -2526,6 +2592,28 @@ function api_get_access_urls($from=0,$to=1000000,$order='url',$direction='ASC')
}
return $result;
}
+
+/**
+ * Get the access url info in an array
+ * @param id of the access url
+ * @return array Array with all the info (url, description, active, created_by, tms) from the access_url table
+ * @author Julio Montoya Armas
+ */
+function api_get_access_url($id)
+{
+ global $_configuration;
+ $result = array();
+ // calling the Database:: library dont work this is handmade
+ //$table_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
+ $table='access_url';
+ $database = $_configuration['main_database'];
+ $table_access_url = "`".$database."`.`".$table."`";
+ $sql = "SELECT url, description, active, created_by, tms FROM $table_access_url WHERE id = '$id' ";
+ $res = api_sql_query($sql,__FILE__,__LINE__);
+ $result = @mysql_fetch_array($res);
+ return $result;
+}
+
/**
* Adds an access URL into the database
* @param string URL
@@ -2571,14 +2659,20 @@ function api_add_access_url($u,$d='',$a=1)
* @param int Access URL's ID. Optional. Uses 1 by default, which is the unique URL
* @return array Array of database results for the current settings of the current access URL
*/
-function api_get_settings($cat=null,$ordering='list',$access_url=1)
+function api_get_settings($cat=null,$ordering='list',$access_url=1,$url_changeable=0)
{
$results = array();
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$access_url = (int) $access_url;
+
+ $url_changeable_where='';
+ if ($url_changeable==1)
+ {
+ $url_changeable_where= " AND access_url_changeable= '1' ";
+ }
if(empty($access_url)){$access_url=1;}
$sql = "SELECT id, variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url, access_url_changeable " .
- " FROM $t_cs WHERE access_url = $access_url ";
+ " FROM $t_cs WHERE access_url = $access_url $url_changeable_where ";
if(!empty($cat))
{
$cat = Database::escape_string($cat);
@@ -2591,7 +2685,7 @@ function api_get_settings($cat=null,$ordering='list',$access_url=1)
else
{
$sql .= " ORDER BY 1,2 ASC";
- }
+ }
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res === false){return $results;}
$results = api_store_result($res);