[svn r17865] Minor - Fixing when editing a checkbox variable in Platform admin FS#3462

skala
Julio Montoya 17 years ago
parent 5c14358ad1
commit fff7d7de52
  1. 25
      main/admin/settings.php
  2. 26
      main/inc/lib/main_api.lib.php

@ -1,4 +1,4 @@
<?php // $Id: settings.php 17818 2009-01-19 12:44:20Z pcool $
<?php // $Id: settings.php 17865 2009-01-20 16:33:17Z juliomontoya $
/*
==============================================================================
Dokeos - elearning and course management software
@ -125,18 +125,16 @@ 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)
{
($countsetting['0']%10) < 5 ?$b=$countsetting['0']-10:$b=$countsetting['0'];
foreach($settings as $row) {
($countsetting['0']%10) < 5 ?$b=$countsetting['0']-10:$b=$countsetting['0'];
if ($i % 10 == 0 and $i<$b){
if ($_GET['category'] <> "Languages"){
$form->addElement('html','<div align="right">');
$form->addElement('submit', null,get_lang('SaveSettings'));
$form->addElement('html','</div>');
}
}$i++;
}
$i++;
$form->addElement('header', null, get_lang($row['title']));
$hideme=array();
@ -199,7 +197,18 @@ if (!empty($_GET['category']) and $_GET['category'] <> "Plugins" and $_GET['cate
$default_values[$row['variable']] = $row['selected_value'];
break;
case 'checkbox';
$sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."'";
//be default we chose the access_url 1 otherwise we will get parameters from all urls
if ($row['access_url_changeable']==1) {
//current access_url
$access_url = $_configuration['access_url'];
if (empty($access_url))
$access_url = 1;
$sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."' AND access_url = $access_url";
} else {
$sql = "SELECT * FROM settings_current WHERE variable='".$row['variable']."' AND access_url = 1";
}
$result = api_sql_query($sql, __FILE__, __LINE__);
$group = array ();
while ($rowkeys = Database::fetch_array($result)) {

@ -2285,23 +2285,27 @@ 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
if(Database::num_rows($res)>0) {
//found item for this access_url
$row = Database::fetch_array($res);
$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' ";
$res = api_sql_query($update,__FILE__,__LINE__);
} else {
//Item not found for this access_url, we have to check if it exist with access_url = 1
$select = "SELECT * FROM $t_settings WHERE variable = '$var' AND access_url = 1 ";
// just in case
if ($access_url==1) {
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
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);
$insert = "INSERT INTO $t_settings " .
"(variable,subkey," .
@ -2313,8 +2317,8 @@ function api_set_setting($var,$value,$subvar=null,$cat=null,$access_url=1) {
"('".$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)";
"".(!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);
@ -2333,7 +2337,7 @@ function api_set_setting($var,$value,$subvar=null,$cat=null,$access_url=1) {
$row = Database::fetch_array($res);
if ($row['access_url_changeable']==1) {
$insert = "INSERT INTO $t_settings " .
"(variable,subkey," .
"(variable,subkey," .
"type,category," .
"selected_value,title," .
"comment,scope," .
@ -2345,7 +2349,7 @@ function api_set_setting($var,$value,$subvar=null,$cat=null,$access_url=1) {
"'$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'].")";
"".(!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

Loading…
Cancel
Save