Xataface 2.0
Xataface Application Framework
Dataface/ConfigTool/setConfigParam.function.php
Go to the documentation of this file.
00001 <?php
00022 function Dataface_ConfigTool_setConfigParam($file, $section, $key, $value, $username=null, $lang=null, $priority=5){
00023         $self =& Dataface_ConfigTool::getInstance();
00024         // See if this parameter has already been set:
00025         $where = array();
00026         $where[] = "`key`='".addslashes($key)."'";
00027         $where[] = "`file`='".addslashes($file)."'";
00028         $where[] = "`section`".(isset($section) ? "='".addslashes($section)."'" : ' IS NULL');
00029         $where[] = "`username`".(isset($username) ? "='".addslashes($username)."'" : ' IS NULL');
00030         $where[] = "`lang`".(isset($lang) ? "='".addslashes($lang)."'" : ' IS NULL');
00031         
00032         $where = implode(' and ',$where);
00033         $sql = "select `config_id` from `".$self->configTableName."` where $where limit 1";
00034 
00035         $res = mysql_query($sql,df_db());
00036         if ( !$res ){
00037                 $self->createConfigTable();
00038                 $res = mysql_query($sql, df_db());
00039         }
00040         if ( !$res ){
00041                 return PEAR::raiseError("Failed to get config parameter: ".mysql_error(df_db()));
00042         }
00043         
00044         $vals = array(
00045                         "section"=>(isset($section) ? "'".addslashes($section)."'" : 'NULL'),
00046                         "key"=>"'".addslashes($key)."'",
00047                         "value"=>"'".addslashes($value)."'",
00048                         "username"=>"'".addslashes($username)."'",
00049                         "lang"=>"'".addslashes($lang)."'",
00050                         "priority"=>$priority
00051                         );
00052         if ( mysql_num_rows($res) > 0 ){
00053                 $row = mysql_fetch_assoc($res);
00054 
00055                 // We need to perform an update
00056                 
00057                 $updates = array();
00058                 foreach ($vals as $vkey=>$vval){
00059                         $updates[] = '`'.$vkey.'`='.$vval;
00060                 }
00061                 $sets = implode(' and ', $updates);
00062                 $sql = "update `".$self->configTableName."` set ".$sets." where `config_id`='".$row['config_id']."' limit 1";
00063                 
00064         } else {
00065                 $values = array();
00066                 $cols = array();
00067                 foreach ($vals as $vkey=>$vval){
00068                         $cols[] = "`$vkey`";
00069                         $values[] = $vval;
00070                 }
00071                 $cols = implode(',',$cols);
00072                 $values = implode(',',$values);
00073                 $sql = "insert into `".$self->configTableName."` ($cols) VALUES ($values)";
00074                 
00075         }
00076         @mysql_free_result($res);
00077         $res = mysql_query($sql, df_db());
00078         if ( !$res ){
00079                 return PEAR::raiseError("Could not write config value: ".mysql_error(df_db()));
00080         }
00081         return true;
00082 }
 All Data Structures Namespaces Files Functions Variables Enumerations