Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
setConfigParam.function.php
Go to the documentation of this file.
1 <?php
22 function Dataface_ConfigTool_setConfigParam($file, $section, $key, $value, $username=null, $lang=null, $priority=5){
24  // See if this parameter has already been set:
25  $where = array();
26  $where[] = "`key`='".addslashes($key)."'";
27  $where[] = "`file`='".addslashes($file)."'";
28  $where[] = "`section`".(isset($section) ? "='".addslashes($section)."'" : ' IS NULL');
29  $where[] = "`username`".(isset($username) ? "='".addslashes($username)."'" : ' IS NULL');
30  $where[] = "`lang`".(isset($lang) ? "='".addslashes($lang)."'" : ' IS NULL');
31 
32  $where = implode(' and ',$where);
33  $sql = "select `config_id` from `".$self->configTableName."` where $where limit 1";
34 
35  $res = mysql_query($sql,df_db());
36  if ( !$res ){
37  $self->createConfigTable();
38  $res = mysql_query($sql, df_db());
39  }
40  if ( !$res ){
41  return PEAR::raiseError("Failed to get config parameter: ".mysql_error(df_db()));
42  }
43 
44  $vals = array(
45  "section"=>(isset($section) ? "'".addslashes($section)."'" : 'NULL'),
46  "key"=>"'".addslashes($key)."'",
47  "value"=>"'".addslashes($value)."'",
48  "username"=>"'".addslashes($username)."'",
49  "lang"=>"'".addslashes($lang)."'",
50  "priority"=>$priority
51  );
52  if ( mysql_num_rows($res) > 0 ){
53  $row = mysql_fetch_assoc($res);
54 
55  // We need to perform an update
56 
57  $updates = array();
58  foreach ($vals as $vkey=>$vval){
59  $updates[] = '`'.$vkey.'`='.$vval;
60  }
61  $sets = implode(' and ', $updates);
62  $sql = "update `".$self->configTableName."` set ".$sets." where `config_id`='".$row['config_id']."' limit 1";
63 
64  } else {
65  $values = array();
66  $cols = array();
67  foreach ($vals as $vkey=>$vval){
68  $cols[] = "`$vkey`";
69  $values[] = $vval;
70  }
71  $cols = implode(',',$cols);
72  $values = implode(',',$values);
73  $sql = "insert into `".$self->configTableName."` ($cols) VALUES ($values)";
74 
75  }
76  @mysql_free_result($res);
77  $res = mysql_query($sql, df_db());
78  if ( !$res ){
79  return PEAR::raiseError("Could not write config value: ".mysql_error(df_db()));
80  }
81  return true;
82 }