replace with your data if config data is null or empty
//default_values => array(array())// ex: array('LOCAL_SERVER'=>array('TVALUE'=>'http:\\localhost'))
function look_config_default_values($field_name,$like='',$default_values=''){
if ($like == ''){
$sql="select NAME,IVALUE,TVALUE,COMMENTS from config where NAME in ";
$arg_sql=array();
$arg=mysql2_prepare($sql,$arg_sql,$field_name);
}else{
$arg['SQL']="select NAME,IVALUE,TVALUE,COMMENTS from config where NAME like '%s'";
$arg['ARG']=$field_name;
}
$resdefaultvalues=mysql2_query_secure($arg['SQL'],$_SESSION['OCS']["readServer"],$arg['ARG']);
while($item = mysql_fetch_object($resdefaultvalues)){
$result['name'][$item ->NAME]=$item ->NAME;
$result['ivalue'][$item ->NAME]=$item ->IVALUE;
$result['tvalue'][$item ->NAME]=$item ->TVALUE;
$result['comments'][$item ->NAME]=$item ->COMMENTS;
}
if (is_array($default_values)){
foreach ($default_values as $key=>$value){
$key=strtolower($key);
if (is_array($value)){
foreach ($value as $name=>$val){
if (!isset($result[$key][$name]) or $result[$key][$name] == '')
$result[$key][$name] = $val;
}
}
}
}
return $result;
}
/******************************************************SQL FUNCTION****************************************************/
function generate_secure_sql($sql,$arg=''){
if (is_array($arg)){
foreach ($arg as $key=>$value){
$arg_array_escape_string[]=mysql_real_escape_string($value);
}
$arg_escape_string=$arg_array_escape_string;
}elseif ($arg != ''){
$arg_escape_string=mysql_real_escape_string($arg);
}
if (isset($arg_escape_string)){
if (is_array($arg_escape_string)){
$sql = vsprintf($sql,$arg_escape_string);
}else
$sql = sprintf($sql,$arg_escape_string);
}
return $sql;
}
function mysql2_query_secure($sql,$link,$arg='',$log=false){
global $l,$lbl_log;
$query = generate_secure_sql($sql,$arg);
if ($log){
addLog( $log, $query,$lbl_log);
}
if ($_SESSION['OCS']['DEBUG'] == 'ON'){
$_SESSION['OCS']['SQL_DEBUG'][]=html_entity_decode($query,ENT_QUOTES);
}
if(DEMO){
$rest = mb_strtoupper(substr($query, 0, 6));
if ($rest == 'UPDATE' or $rest == 'INSERT' or $rest == 'DELETE'){
if(DEMO_MSG != 'show'){
msg_info($l->g(2103));
define('DEMO_MSG','show');
}
return false;
}
}
$result=mysql_query( $query, $link );
if ($_SESSION['OCS']['DEBUG'] == 'ON' and !$result)
msg_error(mysql_error($link));
return $result;
}
/*
* use this function before mysql2_query_secure
* $sql= requeste
* $arg_sql = arguments for mysql2_query_secure
* $arg_tab = arguments to implode
*
*/
function mysql2_prepare($sql,$arg_sql,$arg_tab='',$nocot=false){
if ($arg_sql == '')
$arg_sql = array();
if (!is_array($arg_tab)){
$arg_tab=explode(',',$arg_tab);
}
$sql.=" ( ";
foreach ($arg_tab as $key=>$value){
if (!$nocot)
$sql.=" '%s', ";
else
$sql.=" %s, ";
array_push($arg_sql,$value);
}
$sql = substr($sql,0,-2) . " ) ";
return array('SQL'=>$sql,'ARG'=>$arg_sql);
}
function prepare_sql_tab($list_fields,$explu=array(),$distinct=false){
$begin_arg = array();
$begin_sql = "SELECT ";
if ($distinct)
$begin_sql .= " distinct ";
foreach ($list_fields as $key=>$value){
if (!in_array($key,$explu)){
$begin_sql .= '%s, ';
array_push($begin_arg,$value);
}
}
return array('SQL'=>substr($begin_sql,0,-2)." ",'ARG'=>$begin_arg);
}
function dbconnect($server,$compte_base,$pswd_base,$db = DB_NAME) {
//$link is ok?
$link=@mysql_connect($server,$compte_base,$pswd_base);
if(!is_resource($link)) {
return "ERROR: MySql connection problem
".mysql_error();
}
//database is ok?
if( ! mysql_select_db($db,$link)) {
return "NO_DATABASE";
}
//force UTF-8
mysql_query("SET NAMES 'utf8'");
//sql_mode => not strict
mysql_query("SET sql_mode='NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'");
return $link;
}
/***********************************END SQL FUNCTION******************************************/
function addLog( $type, $value="",$lbl_sql='') {
//global $logHandler;
if ($_SESSION['OCS']['LOG_GUI'] == 1){
$logHandler = @fopen( LOG_FILE, "a");
$dte = getDate();
$date = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $dte["mday"], $dte["mon"], $dte["year"], $dte["hours"], $dte["minutes"], $dte["seconds"]);
if ($lbl_sql != ''){
$value=$lbl_sql.' => '.$value;
}
$towite=$_SESSION['OCS']["loggeduser"].";".$date.";".DB_NAME.";".$type.";".$value.";".$_SERVER['REMOTE_ADDR'].";\n";
@fwrite($logHandler,$towite);
@fclose($logHandler);
}
}
function dateTimeFromMysql($v) {
global $l;
if( $l->g(269) == "%m/%d/%Y" )
$ret = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $v[5].$v[6], $v[8].$v[9], $v, $v[11].$v[12],$v[14].$v[15],$v[17].$v[18]);
else
$ret = sprintf("%02d/%02d/%04d %02d:%02d:%02d", $v[8].$v[9], $v[5].$v[6], $v, $v[11].$v[12],$v[14].$v[15],$v[17].$v[18]);
return $ret;
}
function dateToMysql($date_cible) {
global $l;
if(!isset($date_cible)) return "";
$dateAr = explode("/", $date_cible);
if( $l->g(269) == "%m/%d/%Y" ) {
$jour = $dateAr[1];
$mois = $dateAr[0];
}
else {
$jour = $dateAr[0];
$mois = $dateAr[1];
}
$annee = $dateAr[2];
return sprintf("%04d-%02d-%02d", $annee, $mois, $jour);
}
function reloadform_closeme($form='',$close=false){
echo "";
}
function read_profil_file($name,$writable=''){
global $l;
//Select config file depending on user profile
$ms_cfg_file= $_SESSION['OCS']['CONF_PROFILS_DIR'].$name."_config.txt";
$search=array('INFO'=>'MULTI','PAGE_PROFIL'=>'MULTI','RESTRICTION'=>'MULTI','ADMIN_BLACKLIST'=>'MULTI','CONFIGURATION'=>'MULTI');
if (!is_writable($_SESSION['OCS']['OLD_CONF_DIR']) and $writable!='') {
msg_error($l->g(297).":
".$_SESSION['OCS']['OLD_CONF_DIR']."
".$l->g(1148));
}
return read_files($search,$ms_cfg_file,$writable);
}
function read_config_file($writable=''){
//Select config file depending on user profile
$ms_cfg_file= $_SESSION['OCS']['CONF_PROFILS_DIR']."4all_config.txt";
$search=array('ORDER_FIRST_TABLE'=>'MULTI2',
'ORDER_SECOND_TABLE'=>'MULTI2',
'LBL'=>'MULTI',
'MENU'=>'MULTI',
'MENU_TITLE'=>'MULTI',
'MENU_NAME'=>'MULTI',
'URL'=>'MULTI',
'DIRECTORY'=>'MULTI',
'JAVASCRIPT'=>'MULTI');
return read_files($search,$ms_cfg_file,$writable);
}
function read_files($search,$ms_cfg_file,$writable=''){
global $l;
if (!is_writable($ms_cfg_file) and $writable != '') {
msg_error($ms_cfg_file." ".$l->g(1006).". ".$l->g(1147));
return FALSE;
}
if (file_exists($ms_cfg_file)) {
$profil_data=read_configuration($ms_cfg_file,$search);
return $profil_data;
}else
return FALSE;
}
function replace_language($info){
global $l;
if (substr($info,0,2) == 'g(')
return $l->g(substr(substr($info,2),0,-1));
else
return $info;
}
function msg($txt,$css,$log=0){
echo "