[svn r15078] Code changes preparing for the multiple-url access. CAUTION: FROM NOW ON, ONLY USE FUNCTIONS PROVIDED IN main_api.lib.php TO EDIT SETTINGS_CURRENT TABLE (see FS#2470 for more info)

skala
Yannick Warnier 18 years ago
parent dd9fdf1dbe
commit 07aa711d50
  1. 11
      main/admin/index.php
  2. 60
      main/admin/settings.php
  3. 45
      main/inc/global.inc.php
  4. 3
      main/inc/lib/database.lib.php
  5. 396
      main/inc/lib/main_api.lib.php

@ -1,4 +1,4 @@
<?php // $Id: index.php 15050 2008-04-23 22:50:59Z yannoo $ <?php // $Id: index.php 15078 2008-04-24 23:15:37Z yannoo $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -134,6 +134,12 @@ $keyword_url = Security::remove_XSS($_GET['keyword']);
<?php if(!empty($phpMyAdminPath)): ?> <?php if(!empty($phpMyAdminPath)): ?>
<li><a href="<?php echo $phpMyAdminPath; ?>" target="_blank"><?php echo get_lang("AdminDatabases"); ?></a><br />(<?php echo get_lang("DBManagementOnlyForServerAdmin"); ?>)</li> <li><a href="<?php echo $phpMyAdminPath; ?>" target="_blank"><?php echo get_lang("AdminDatabases"); ?></a><br />(<?php echo get_lang("DBManagementOnlyForServerAdmin"); ?>)</li>
<?php endif; ?> <?php endif; ?>
<?php
if(!empty($_configuration['multiple_access_urls']))
{
echo ' <li><a href="access_urls.php">'.get_lang('ConfigureMultipleAccessURLs').'</a></li>';
}
?>
</ul> </ul>
</div> </div>
@ -160,6 +166,7 @@ if(api_get_setting('use_session_mode')=='true')
<li><a href="session_import.php"><?php echo get_lang('ImportSessionListXMLCSV') ?></a></li> <li><a href="session_import.php"><?php echo get_lang('ImportSessionListXMLCSV') ?></a></li>
<li><a href="session_export.php"><?php echo get_lang('ExportSessionListXMLCSV') ?></a></li> <li><a href="session_export.php"><?php echo get_lang('ExportSessionListXMLCSV') ?></a></li>
</ul> </ul>
<br /><br />
</div> </div>
<?php <?php
@ -182,6 +189,8 @@ else if(api_is_platform_admin())
<li><a href="class_import.php"><?php echo get_lang('ImportClassListCSV'); ?></a></li> <li><a href="class_import.php"><?php echo get_lang('ImportClassListCSV'); ?></a></li>
<li><a href="class_user_import.php"><?php echo get_lang('AddUsersToAClass'); ?> CSV</a></li> <li><a href="class_user_import.php"><?php echo get_lang('AddUsersToAClass'); ?> CSV</a></li>
</ul> </ul>
<br />
<br />
</div> </div>
<?php <?php
} }

@ -1,5 +1,5 @@
<?php <?php
// $Id: settings.php 15067 2008-04-24 17:39:03Z juliomontoya $ // $Id: settings.php 15078 2008-04-24 23:15:37Z yannoo $
/* /*
============================================================================== ==============================================================================
Dokeos - elearning and course management software Dokeos - elearning and course management software
@ -79,9 +79,11 @@ if ($_GET['category'] and $_GET['category'] <> "Plugins" and $_GET['category'] <
$renderer->setHeaderTemplate('<div class="settingtitle">{header}</div>'."\n"); $renderer->setHeaderTemplate('<div class="settingtitle">{header}</div>'."\n");
$renderer->setElementTemplate('<div class="settingcomment">{label}</div>'."\n".'<div class="settingvalue">{element}</div>'."\n"); $renderer->setElementTemplate('<div class="settingcomment">{label}</div>'."\n".'<div class="settingvalue">{element}</div>'."\n");
$my_category = mysql_real_escape_string($_GET['category']); $my_category = mysql_real_escape_string($_GET['category']);
$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC"; $settings = api_get_settings($my_category,'group',$_configuration['access_url']);
$resultsettings = api_sql_query($sqlsettings, __FILE__, __LINE__); //$sqlsettings = "SELECT DISTINCT * FROM $table_settings_current WHERE category='$my_category' GROUP BY variable ORDER BY id ASC";
while ($row = mysql_fetch_array($resultsettings)) //$resultsettings = api_sql_query($sqlsettings, __FILE__, __LINE__);
//while ($row = mysql_fetch_array($resultsettings))
foreach($settings as $row)
{ {
$form->addElement('header', null, get_lang($row['title'])); $form->addElement('header', null, get_lang($row['title']));
switch ($row['type']) switch ($row['type'])
@ -130,23 +132,28 @@ if ($_GET['category'] and $_GET['category'] <> "Plugins" and $_GET['category'] <
$values = $form->exportValues(); $values = $form->exportValues();
// the first step is to set all the variables that have type=checkbox of the category // 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 // to false as the checkbox that is unchecked is not in the $_POST data and can
// therefore not be set to false // therefore not be set to false.
$sql = "UPDATE $table_settings_current SET selected_value='false' WHERE category='$my_category' AND type='checkbox'"; // This, however, also means that if the process breaks on the third of five checkboxes, the others
$result = api_sql_query($sql, __FILE__, __LINE__); // will be set to false.
$r = api_set_settings_category($my_category,'false',$_configuration['access_url']);
//$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 // Save the settings
foreach ($values as $key => $value) foreach ($values as $key => $value)
{ {
if (!is_array($value)) if (!is_array($value))
{ {
$sql = "UPDATE $table_settings_current SET selected_value='".mysql_real_escape_string($value)."' WHERE variable='$key'"; //$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_sql_query($sql, __FILE__, __LINE__);
$result = api_set_setting($key,$value,null,null,$_configuration['access_url']);
} }
else else
{ {
foreach ($value as $subkey => $subvalue) foreach ($value as $subkey => $subvalue)
{ {
$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'"; //$sql = "UPDATE $table_settings_current SET selected_value='true' WHERE variable='$key' AND subkey = '$subkey'";
$result = api_sql_query($sql, __FILE__, __LINE__); //$result = api_sql_query($sql, __FILE__, __LINE__);
$result = api_set_setting($key,'true',$subkey,null,$_configuration['access_url']);
} }
} }
} }
@ -166,10 +173,12 @@ if ($_GET['action'] == "stored")
} }
// grabbing the categories // grabbing the categories
$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')"; //$selectcategories = "SELECT DISTINCT category FROM ".$table_settings_current." WHERE category NOT IN ('stylesheets','Plugins')";
$resultcategories = api_sql_query($selectcategories, __FILE__, __LINE__); //$resultcategories = api_sql_query($selectcategories, __FILE__, __LINE__);
$resultcategories = api_get_settings_categories(array('stylesheets','Plugins'));
echo "\n<div><ul>"; echo "\n<div><ul>";
while ($row = mysql_fetch_array($resultcategories)) //while ($row = mysql_fetch_array($resultcategories))
foreach($resultcategories as $row)
{ {
echo "\n\t<li><a href=\"".api_get_self()."?category=".$row['category']."\">".ucfirst(get_lang($row['category']))."</a></li>"; echo "\n\t<li><a href=\"".api_get_self()."?category=".$row['category']."\">".ucfirst(get_lang($row['category']))."</a></li>";
} }
@ -299,9 +308,11 @@ function handle_plugins()
echo "\t</tr>\n"; echo "\t</tr>\n";
/* We retrieve all the active plugins. */ /* We retrieve all the active plugins. */
$sql = "SELECT * FROM $table_settings_current WHERE category='Plugins'"; //$sql = "SELECT * FROM $table_settings_current WHERE category='Plugins'";
$result = api_sql_query($sql); //$result = api_sql_query($sql);
while ($row = mysql_fetch_array($result)) $result = api_get_settings('Plugins');
//while ($row = mysql_fetch_array($result))
foreach($result as $row)
{ {
$usedplugins[$row['variable']][] = $row['selected_value']; $usedplugins[$row['variable']][] = $row['selected_value'];
} }
@ -430,10 +441,12 @@ function handle_stylesheets()
function store_plugins() function store_plugins()
{ {
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
global $_configuration;
// Step 1 : we remove all the plugins // Step 1 : we remove all the plugins
$sql = "DELETE FROM $table_settings_current WHERE category='Plugins'"; //$sql = "DELETE FROM $table_settings_current WHERE category='Plugins'";
api_sql_query($sql, __LINE__, __FILE__); //api_sql_query($sql, __LINE__, __FILE__);
$r = api_delete_category_settings('Plugins',$_configuration['access_url']);
// step 2: looping through all the post values we only store these which are really a valid plugin location. // step 2: looping through all the post values we only store these which are really a valid plugin location.
foreach ($_POST as $form_name => $formvalue) foreach ($_POST as $form_name => $formvalue)
@ -441,8 +454,9 @@ function store_plugins()
$form_name_elements = explode("-", $form_name); $form_name_elements = explode("-", $form_name);
if (is_valid_plugin_location($form_name_elements[1])) if (is_valid_plugin_location($form_name_elements[1]))
{ {
$sql = "INSERT into $table_settings_current (variable,category,selected_value) VALUES ('".$form_name_elements['1']."','Plugins','".$form_name_elements['0']."')"; //$sql = "INSERT into $table_settings_current (variable,category,selected_value) VALUES ('".$form_name_elements['1']."','Plugins','".$form_name_elements['0']."')";
api_sql_query($sql, __LINE__, __FILE__); //api_sql_query($sql, __LINE__, __FILE__);
api_add_setting($form_name_elements['0'],$form_name_elements['1'],null,null,'Plugins',null,null,null,null,$_configuration['access_url'],1);
} }
} }
} }
@ -471,6 +485,7 @@ function is_valid_plugin_location($location)
*/ */
function store_stylesheets() function store_stylesheets()
{ {
global $_configuration;
// Database Table Definitions // Database Table Definitions
$table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT); $table_settings_current = Database :: get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
@ -478,12 +493,15 @@ function store_stylesheets()
$style = Database::escape_string($_POST['style']); $style = Database::escape_string($_POST['style']);
if (is_style($style)) if (is_style($style))
{ {
/*
$sql = 'UPDATE '.$table_settings_current.' SET $sql = 'UPDATE '.$table_settings_current.' SET
selected_value = "'.$style.'" selected_value = "'.$style.'"
WHERE variable = "stylesheets" WHERE variable = "stylesheets"
AND category = "stylesheets"'; AND category = "stylesheets"';
api_sql_query($sql, __LINE__, __FILE__); api_sql_query($sql, __LINE__, __FILE__);
*/
api_set_setting('stylesheets',$style,null,'stylesheets');
} }
return true; return true;

@ -156,26 +156,57 @@ $selectResult = mysql_select_db($_configuration['main_database'],$dokeos_databas
-------------------------------------------- --------------------------------------------
RETRIEVING ALL THE DOKEOS CONFIG SETTINGS RETRIEVING ALL THE DOKEOS CONFIG SETTINGS
-------------------------------------------- --------------------------------------------
*/ */
$sql="SELECT * FROM settings_current"; if(!empty($_configuration['multiple_access_urls']))
$result=mysql_query($sql) or die(mysql_error()); {
while ($row=mysql_fetch_array($result)) error_log(__FILE__.' '.__LINE__);
$_configuration['access_url'] = 1;
$access_urls = api_get_access_urls();
$protocol = ((!empty($_SERVER['HTTPS']) && strtoupper($_SERVER['HTTPS'])!='OFF')?'https':'http').'://';
$request_url1 = $protocol.$_SERVER['SERVER_NAME'].'/';
$request_url2 = $protocol.$_SERVER['HTTP_HOST'].'/';
foreach($access_urls as $details)
{
if($request_url1 == $details['url'] or $request_url2 == $details['url'])
{
$_configuration['access_url'] = $details['id'];
}
}
}
else
{
error_log(__FILE__.' '.__LINE__);
$_configuration['access_url'] = 1;
}
error_log(__FILE__.' '.__LINE__.' access url is :'.$_configuration['access_url']);
//$sql="SELECT * FROM settings_current";
//$result=mysql_query($sql) or die(mysql_error());
$result = api_get_settings(null,'list',$_configuration['access_url']);
//while ($row=mysql_fetch_array($result))
foreach($result as $row)
{ {
if ($row['subkey']==NULL) if ($row['subkey']==NULL)
{ {
$_setting[$row['variable']]=$row['selected_value']; $_setting[$row['variable']]=$row['selected_value'];
error_log(__FILE__.' '.__LINE__.' v.'.$row['variable'].'='.$row['selected_value']);
} }
else else
{ {
$_setting[$row['variable']][$row['subkey']]=$row['selected_value']; $_setting[$row['variable']][$row['subkey']]=$row['selected_value'];
error_log(__FILE__.' '.__LINE__.' v.'.$row['variable'].'.'.$row['subkey'].'='.$row['selected_value']);
} }
} }
// we have to store the settings for the plugins differently because it expects an array // we have to store the settings for the plugins differently because it expects an array
$sql="SELECT * FROM settings_current WHERE category='plugins'"; //$sql="SELECT * FROM settings_current WHERE category='plugins'";
$result=mysql_query($sql) or die(mysql_error()); //$result=mysql_query($sql) or die(mysql_error());
$result = api_get_settings('Plugins','list',$_configuration['access_url']);
$_plugins=array(); $_plugins=array();
while ($row=mysql_fetch_array($result)) //while ($row=mysql_fetch_array($result))
foreach($result as $row)
{ {
error_log(__FILE__.' '.__LINE__);
$key= $row['variable']; $key= $row['variable'];
if (is_string($_setting[$key])) if (is_string($_setting[$key]))
{ {

@ -1,4 +1,4 @@
<?php // $Id: database.lib.php 14991 2008-04-21 17:59:41Z yannoo $ <?php // $Id: database.lib.php 15078 2008-04-24 23:15:37Z yannoo $
/* See license terms in /dokeos_license.txt */ /* See license terms in /dokeos_license.txt */
/** /**
============================================================================== ==============================================================================
@ -51,6 +51,7 @@ define('TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY','gradebook_score_display');
define('TABLE_MAIN_USER_FIELD', 'user_field'); define('TABLE_MAIN_USER_FIELD', 'user_field');
define('TABLE_MAIN_USER_FIELD_OPTIONS', 'user_field_options'); define('TABLE_MAIN_USER_FIELD_OPTIONS', 'user_field_options');
define('TABLE_MAIN_USER_FIELD_VALUES', 'user_field_values'); define('TABLE_MAIN_USER_FIELD_VALUES', 'user_field_values');
define('TABLE_MAIN_ACCESS_URL', 'access_url');
//statistic database tables //statistic database tables
define('TABLE_STATISTIC_TRACK_E_LASTACCESS', 'track_e_lastaccess'); define('TABLE_STATISTIC_TRACK_E_LASTACCESS', 'track_e_lastaccess');

@ -1094,9 +1094,10 @@ class api_failure
function get_setting($variable, $key = NULL) function get_setting($variable, $key = NULL)
{ {
global $_setting; global $_setting;
return is_null($key) ? $_setting[$variable] : $_setting[$variable][$key]; return api_get_setting($variable, $key);
} }
/** /**
* Returns the value of a setting from the web-adjustable admin config settings. * Returns the value of a setting from the web-adjustable admin config settings.
* *
@ -1104,7 +1105,8 @@ function get_setting($variable, $key = NULL)
* if(api_get_setting("show_navigation_menu") == "true") //CORRECT * if(api_get_setting("show_navigation_menu") == "true") //CORRECT
* instead of * instead of
* if(api_get_setting("show_navigation_menu") == true) //INCORRECT * if(api_get_setting("show_navigation_menu") == true) //INCORRECT
* * @param string The variable name
* @param string The subkey (sub-variable) if any. Defaults to NULL
* @author Rene Haentjens * @author Rene Haentjens
* @author Bart Mollet * @author Bart Mollet
*/ */
@ -2274,4 +2276,394 @@ function api_get_status_langvars()
ANONYMOUS=>get_lang('Anonymous') ANONYMOUS=>get_lang('Anonymous')
); );
} }
/**
* Sets a platform configuration setting to a given value
* @param string The variable we want to update
* @param string The value we want to record
* @param string The sub-variable if any (in most cases, this will remain null)
* @param string The category if any (in most cases, this will remain null)
* @param int The access_url for which this parameter is valid
*/
function api_set_setting($var,$value,$subvar=null,$cat=null,$access_url=1)
{
if(empty($var)) { return false; }
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$var = Database::escape_string($var);
$value = Database::escape_string($value);
$access_url = (int) $access_url;
if(empty($access_url)){$access_url=1;}
$select = "SELECT * FROM $t_settings WHERE variable = '$var' ";
if(!empty($subvar))
{
$subvar = Database::escape_string($subvar);
$select .= " AND subkey = '$subvar'";
}
if(!empty($cat))
{
$cat = Database::escape_string($cat);
$select .= " AND category = '$cat'";
}
if($access_url > 1)
{
$select .= " AND access_url = $access_url";
}
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
$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 ";
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);
$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);
}
}
}
/**
* Sets a whole category of settings to one specific value
* @param string Category
* @param string Value
* @param int Access URL. Optional. Defaults to 1
*/
function api_set_settings_category($category,$value=null,$access_url=1)
{
if(empty($category)){return false;}
$category = Database::escape_string($category);
$t_s = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$access_url = (int) $access_url;
if(empty($access_url)){$access_url=1;}
if(isset($value))
{
$value = Database::escape_string($value);
$sql = "UPDATE $t_s SET selected_value = '$value' WHERE category = '$category' AND access_url = $access_url";
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res === false){ return false; }
return true;
}
else
{
$sql = "UPDATE $t_s SET selected_value = NULL WHERE category = '$category' AND access_url = $access_url";
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res === false){ return false; }
return true;
}
}
/**
* Get all available access urls in an array (as in the database)
* @return array Array of database records
*/
function api_get_access_urls($from=0,$to=1000000,$order='url',$direction='ASC')
{
$result = array();
$t_au = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$from = (int) $from;
$to = (int) $to;
$order = Database::escape_string($order);
$direction = Database::escape_string($direction);
$sql = "SELECT id, url, description, active, created_by, tms FROM $t_au ORDER BY $order $direction LIMIT $to OFFSET $from";
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res !==false)
{
$result = api_store_result($res);
}
return $result;
}
/**
* Adds an access URL into the database
* @param string URL
* @param string Description
* @param int Active (1= active, 0=disabled)
* @return int The new database id, or the existing database id if this url already exists
*/
function api_add_access_url($u,$d='',$a=1)
{
$t_au = Database::get_main_table(TABLE_MAIN_ACCESS_URL);
$u = Database::escape_string($u);
$d = Database::escape_string($d);
$a = (int) $a;
$sql = "SELECT * FROM $t_au WHERE url LIKE '$u'";
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res === false)
{
//problem querying the database - return false
return false;
}
else
{
if(Database::num_rows($res)>0)
{
return Database::result($res,0,'id');
}
else
{
$ui = api_get_user_id();
$time =
$sql = "INSERT INTO $t_au (url,description,active,created_by,tms)"
." VALUES ('$u','$d',$a,$ui,'')";
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res === false){return false;}
return Database::insert_id();
}
}
}
/**
* Gets all the current settings for a specific access url
* @param string The category, if any, that we want to get
* @param string Whether we want a simple list (display a catgeory) or a grouped list (group by variable as in settings.php default). Values: 'list' or 'group'
* @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)
{
$results = array();
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$access_url = (int) $access_url;
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 ";
if(!empty($cat))
{
$cat = Database::escape_string($cat);
$sql .= " AND category='$cat' ";
}
if($ordering=='group')
{
$sql .= " GROUP BY variable ORDER BY id ASC";
}
else
{
$sql .= " ORDER BY 1,2 ASC";
}
$res = api_sql_query($sql,__FILE__,__LINE__);
if($res === false){return $results;}
$results = api_store_result($res);
return $results;
}
/**
* Gets the distinct settings categories
* @param array Array of strings giving the categories we want to exclude
* @param int Access URL. Optional. Defaults to 1
* @return array A list of categories
*/
function api_get_settings_categories($exceptions=array(),$access_url=1)
{
$result = array();
$access_url = (int) $access_url;
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$list = "'".implode("','",$exceptions)."'";
$sql = "SELECT DISTINCT category FROM $t_cs";
if($list != "'',''" and $list != "''" and !empty($list))
{
$sql .= " WHERE category NOT IN ($list)";
}
$r = api_sql_query($sql,__FILE__,__LINE__);
if($r === false)
{
return $result;
}
$result = api_store_result($r);
return $result;
}
/**
* Delete setting
* @param string Variable
* @param string Subkey
* @param int Access URL
* @return boolean False on failure, true on success
*/
function api_delete_setting($v,$s=NULL,$a=1)
{
if(empty($v)){return false;}
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$v = Database::escape_string($v);
$a = (int) $a;
if(empty($a)){$a=1;}
if(!empty($s))
{
$s = Database::escape_string($s);
$sql = "DELETE FROM $t_cs WHERE variable = '$v' AND subkey = '$s' AND access_url = $a";
$r = api_sql_query($sql);
return $r;
}
else
{
$sql = "DELETE FROM $t_cs WHERE variable = '$v' AND access_url = $a";
$r = api_sql_query($sql);
return $r;
}
}
/**
* Delete all the settings from one category
* @param string Category
* @param int Access URL
* @return boolean False on failure, true on success
*/
function api_delete_category_settings($c,$a=1)
{
if(empty($c)){return false;}
$t_cs = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$c = Database::escape_string($c);
$a = (int) $a;
if(empty($a)){$a=1;}
$sql = "DELETE FROM $t_cs WHERE category = '$c' AND access_url = $a";
$r = api_sql_query($sql);
return $r;
}
/**
* Sets a platform configuration setting to a given value
* @param string The value we want to record
* @param string The variable name we want to insert
* @param string The subkey for the variable we want to insert
* @param string The type for the variable we want to insert
* @param string The category for the variable we want to insert
* @param string The title
* @param string The comment
* @param string The scope
* @param string The subkey text
* @param int The access_url for which this parameter is valid
* @param int The changeability of this setting for non-master urls
* @return boolean true on success, false on failure
*/
function api_add_setting($val,$var,$sk=null,$type='textfield',$c=null,$title='',$com='',$sc=null,$skt=null,$a=1,$v=0)
{
if(empty($var) or !isset($val)) { return false; }
$t_settings = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
$var = Database::escape_string($var);
$val = Database::escape_string($val);
$a = (int) $a;
if(empty($a)){$a=1;}
//check if this variable doesn't exist already
$select = "SELECT * FROM $t_settings WHERE variable = '$var' ";
if(!empty($sk))
{
$sk = Database::escape_string($sk);
$select .= " AND subkey = '$sk'";
}
if($a > 1)
{
$select .= " AND access_url = $a";
}
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
$row = Database::fetch_array($res);
return $row['id'];
}
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
$insert = "INSERT INTO $t_settings " .
"(variable,selected_value," .
"type,category," .
"subkey,title," .
"comment,scope," .
"subkeytext,access_url,access_url_changeable)" .
" VALUES ('$var','$val',";
if(isset($type))
{
$type = Database::escape_string($type);
$insert .= "'$type',";
}
else
{
$insert .= "NULL,";
}
if(isset($c)) //category
{
$c = Database::escape_string($c);
$insert .= "'$c',";
}
else
{
$insert .= "NULL,";
}
if(isset($sk)) //subkey
{
$sk = Database::escape_string($sk);
$insert .= "'$sk',";
}
else
{
$insert .= "NULL,";
}
if(isset($title)) //title
{
$title = Database::escape_string($title);
$insert .= "'$title',";
}
else
{
$insert .= "NULL,";
}
if(isset($com)) //comment
{
$com = Database::escape_string($com);
$insert .= "'$com',";
}
else
{
$insert .= "NULL,";
}
if(isset($sc)) //scope
{
$sc = Database::escape_string($sc);
$insert .= "'$sc',";
}
else
{
$insert .= "NULL,";
}
if(isset($skt)) //subkey text
{
$skt = Database::escape_string($skt);
$insert .= "'$skt',";
}
else
{
$insert .= "NULL,";
}
$insert .= "$a,$v)";
$res = api_sql_query($insert,__FILE__,__LINE__);
return $res;
}
}
?> ?>
Loading…
Cancel
Save