Location: PHPKode > projects > SimpleHRM > simplehrm-1.0-beta1/simplehrm-1.0-beta1/flexycms/classes/data/setting.php
<?php
//include_once("/var/www/html/flexycms/flexycms_core/classes/common/validation.php");
/*
Modified on 02/09/2005 for humor cms .. 
1. Removed fk functions as they are not being used 
2. Modified get function to work only for one id 
3. Added error cheincg in get , insert , update and delete 
4. Changed the table heading to return #LBL_fieldname#
*/

class setting{
	// null args constructor g
	function setting(){
	}
	// Insert into database Return inserted id  if success , error message if failed 
	function insert($arr){
		global $link;
		$sql = "INSERT INTO ".TABLE_PREFIX."config";
		$fld_str_key = "";
		$fld_str_value = "";
		foreach($arr as $key => $value){
			$fld_str_key .= $key.","; 
		}
		$fld_str_key = substr($fld_str_key,',',strlen($fld_str_key)-1);
		foreach ($arr as $key => $value) {
			if(!isset($value) || $value == ""){
				$fld_str_value .= "NULL,";
			} else {
				$fld_str_value .= "'".$value."',";
			}
		}
		$fld_str_value = substr($fld_str_value,',',strlen($fld_str_value)-1);
		$sql = $sql." (".$fld_str_key.") VALUES(".$fld_str_value.")";
		//print $sql;exit;
		$err = execute($sql,$err);
		$id_user = mysqli_insert_id($link);
		return $id_user;
	}
	function edit_config($data,$id_config){
		$sql = "UPDATE ".TABLE_PREFIX."config SET ";
		foreach($data as $k => $v) {
			$sql.= $k."='".$v."',";
		}
		$sql = trim($sql,',');
		$sql.=" WHERE id_config = {$id_config}";
		execute($sql,$err);
	}
	function insert_msg($data) {
		$field_key = '';
		$field_value = '';
		foreach($data as $k => $v) {
			if($v) {
				if($k == 'key_name') {
					$v = strtoupper($v);
				}
				$field_key .= $k.",";
				$field_value .= $v."','";
			}
		}
		$sql = "INSERT INTO ".TABLE_PREFIX."message (".trim($field_key,',').") 
			VALUES ('".trim($field_value,",'")."')";
		return $sql;
	}
	function edit_msg($data,$id_msg){
		$sql = "UPDATE ".TABLE_PREFIX."message SET ";
		foreach($data as $k => $v) {
			if($k == 'key_name') {
				$v = strtoupper($v);
			}
			$sql.= $k."='".$v."',";
		}
		$sql = trim($sql,',');
		$sql.=" WHERE id_message = {$id_msg}";
		return $sql;
	}
	function delete_msg($key_name){
		$sql="DELETE FROM ".TABLE_PREFIX."message WHERE key_name = '".$key_name."'";
		return $sql;
	}
	function insert1($table,$arr){
		global $link;
		$sql = "INSERT INTO ".TABLE_PREFIX.$table;
		$fld_str_key = "";
		$fld_str_value = "";
		foreach($arr as $key => $value){
			$fld_str_key .= $key.","; 
		}
		$fld_str_key = substr($fld_str_key,',',strlen($fld_str_key)-1);
		foreach ($arr as $key => $value) {
			if(!isset($value) || $value == ""){
				$fld_str_value .= "NULL,";
			} else {
				$fld_str_value .= "'".$value."',";
			}
		}
		$fld_str_value = substr($fld_str_value,',',strlen($fld_str_value)-1);
		$sql = $sql." (".$fld_str_key.") VALUES(".$fld_str_value.")";
		//print $sql;exit;
		$err = execute($sql,$err);
		$id_user = mysqli_insert_id($link);
		return $id_user;
	}
	function update1($table,$data,$condition="") {
		$sql="UPDATE ".TABLE_PREFIX.$table." SET ";
		foreach ($data as $key => $value) {
			$sql.=$key."='".$value."',";
		}
		$sql=trim($sql,',');
		//$sql.=" WHERE id_company= ".$_SESSION['id_company'];
		if($condition){
		$sql.=" WHERE ".$condition;
		}
		//print $sql;exit;
		execute($sql,$err);
		if($err) return $err;
		return TRUE;
	}
	function delete1($tblname,$cond){
		$sql="DELETE FROM ".TABLE_PREFIX.$tblname." WHERE ".$cond;
		execute($sql,$err);
		if($err) return $err;
		return TRUE;
	}
}
?>
Return current item: SimpleHRM