function lfdata_connect($data_host,$data_user,$data_pass,$db)	{
   /* starts or stops database connection */
		if ($mysql_link=mysql_connect($data_host,$data_user,$data_pass)){
		lfquery("use `".$db."`");

			if (mysql_error($mysql_link)=="Unknown database '".$db."'") {
				lfquery("CREATE DATABASE ".$db);
				lfquery("use `".$db."`");
				};
			}
			else {$lferror="Can not connect to database";};

		if ((!(mysql_error($mysql_link)=="")) 
		AND (mysql_error($mysql_link)<>"Unknown database '".$db."'")) {
			echo "lfdata_connect.php,"._LINE.": ".mysql_error($mysql_link); };
		include "config.php";
		lfquery("SET NAMES '".$lfconf_db['encoding']."'", $mysql_link);
		return $mysql_link;};
Esempio n. 2
0
function lfdb($theme) {
include "config.php";
include "lfparts.php";
foreach ($lfpart as $part) {
	// List all the files 
	$dir = "parts/".$part."/lfdb";; 
	include $lfpath."system/lf_filelist.php";
	
	// Restarting Varibles
	$i1="1";
	
	while ($lf_file[$i1]<>"") {
		$i4=$i3=$i2="1";
		$db="";
		$tablename="";
		include $lfpath."parts/".$part."/lfdb/".$lf_file[$i1];
	
		// Changing table name if needed ($tablename taken from the lfdb file)
		if ($lfconf_db['change_tables']=="yes") {
			if (($tablename<>str_replace(".php","",$lf_file[$i1])) AND ($tablename<>"" )) {
				lfquery("RENAME TABLE `".str_replace(".php","",$lf_file[$i1])."` TO `".$tablename."`");
				rename( "parts/".$part."/lfdb/".$lf_file[$i1] , "parts/".$part."/lfdb/".$tablename.".php");
			}
				else {
				$tablename = str_replace(".php","",$lf_file[$i1]);
				};
		};
	
		$db['0']['name'] = $dbid;
	
			// Creating table
		if ($lfconf_db['create_tables']=="yes") {
			$q="CREATE TABLE IF NOT EXISTS `".$tablename."` (\n"."
			`".$dbid."` int (11) NOT NULL auto_increment ,\n
			PRIMARY KEY (`".$dbid."`) ) \n
			TYPE=MyISAM AUTO_INCREMENT=1 ;\n\n";
			$db["0"]['name']  = $dbid; // needed For Adding first table
			lfquery($q);
		};
	
		if ($lfconf_db['update_culmus']=="yes") {
	
			// Renaming id if needed
			
			$query=lfquery("SHOW COLUMNS IN `".$tablename."`");
			$row=mysql_fetch_array($query); 
		
			if ($row["Field"]<>$dbid) {
				$q="ALTER TABLE ".$tablename." CHANGE ".$row["Field"]." ".$dbid ." ".$row['Type'];
				lfquery($q);
				};
		
			// Deleting Columns that not in the config file
			$i4="1";
			$query=lfquery("SHOW COLUMNS IN `".$tablename."`");
			$row=mysql_fetch_array($query); // Skipping the id line
			while ($row=mysql_fetch_array($query)) {
				if (empty($db[$i4]['name'])) {
					$q="ALTER TABLE `".$tablename."`  DROP `". $row["Field"] . "`" ;
					lfquery($q);
					};
				$i4++;
				};
		
				// Updating Columns
			$i4="1";
			$query=lfquery("SHOW COLUMNS IN `".$tablename."`");
			$row=mysql_fetch_array($query); // Skipping the id line
		
			while ($row=mysql_fetch_array($query)) {
					// Updating db info
				if (($db[$i4]['name']<>$row["Field"]) OR ($db[$i4]['type'] <>$row["Type"] )) {
					$q="ALTER TABLE ".$tablename." CHANGE ".$row["Field"]." ".$db[$i4]['name']." ".$db[$i4]['type'];
					lfquery($q);
					};
				$i4++;
				};
		};
		
			// Creating Columns
		if ($lfconf_db['create_culomns']=="yes") {
			while ($db[$i2]["name"]<>"") {
				$query=lfquery("desc `".$tablename."` `".$db[$i2]["name"]."`");
				if (mysql_fetch_array($query)=="") {
					$q = "ALTER TABLE `".$tablename."` ADD `".$db[$i2]["name"]."` ".$db[$i2]["type"]/*." DEFAULT '".$db[$i2]["default"]*/." NOT NULL AFTER `".$db[$i2-1]["name"]."` ;
;\n";
					$q = str_replace("default 'auto_increment'","auto_increment",$q);
					$q = str_replace("DEFAULT ''","",$q);
					lfquery($q);
//echo "<div dir=ltr>".$q."</div>";
					}
				$i2++;
				};
		};
			// Checking for non-existent tables (for deleting non existing tables later)
		if ($lfconf_db['delete_tables']=="yes") {
			$q="SHOW TABLES";
			$query=lfquery($q);
			while ($row=mysql_fetch_array($query)) {
				if ($row['0'] == $tablename) {
					$table_exists[$tablename]="yes";};
			/*echo $row['0']."<br>";*/};
			}
			// Checking for actions
		$db_action['1']['action']="";
		$i1++; // Going to the next file
		};
	
	
	// Deleting non exists tables
	if ($lfconf_db['delete_tables']=="yes") {
		$q="SHOW TABLES";
		$query=lfquery($q);
		while ($row=mysql_fetch_array($query)) {
			if ($table_exists[$row['0']] <> "yes") {
				$q="DROP TABLE `".$row['0']."`";
				lfquery($q);
				};};
		};
	};
// Finishing lfdb
return $theme;
};
Esempio n. 3
0
				};
				
			for  ($i="2"; $i <= count($if_cookie_fields); $i++) {
				$q .= " AND ".$if_cookie_fields[$i-1]." = '".$_COOKIE[$if_cookie_fields[$i-1]]."'";
//				echo $q."<br>";
				};
//			echo $if_name.":<div dir=ltr align=center>".$q."<div>";
			}
		elseif ($if_check[$if_name]['type'] == "sql") {
			$q = $if_check[$if_name]['sql'];
//echo $if_name."<br />";
			};
//	echo $q."<br><br>";
		if (($if_check[$if_name]['type'] == "cookie") OR ($if_check[$if_name]['type'] == "sql")) {
			if ($q<>"") {
				if ($query  = lfquery($q)) {
					$result = mysql_fetch_array($query);
//					echo "<b>";print_r($result);echo "</b><br><br>";
					}
				else {
					$result="";
					};
				}
			else {
				$result = "";
				};
			}
		elseif ($if_check[$if_name]['type'] == "true") {
			if ($if_check[$if_name]['check']=="1") {
				$result="yes";
				}
Esempio n. 4
0
			$dv=$value;
			$_GET[$varName] = mysql_escape_string($dv);
			};
	
	// Starting Connection to Database
	$lf_connection=
	lfdata_connect($lfconf_db['host'],$lfconf_db['user'],$lfconf_db['pass'],$lfconf_db['db']);
	
	// Getting the tables list
	$q="SHOW TABLES";
	$table_query=lfquery($q);
	while ($table_result=mysql_fetch_row($table_query)) {
	//	echo $table_result['0'];
		//  Getting the columns list
		$q="SHOW COLUMNS IN ".$table_result['0'];
		$query=lfquery($q);
		
		// Making the lfdb file
		$file  =	"<?\n".
				'$tablename="'.$table_result['0'].'";'."\n".
				'$column=0; // Don\'t touch'."\n\n";
		
		while ($result=mysql_fetch_row($query)) {
			$file .= "\t//".$result['0']."\n\n";
			$file .= '$column++;'."\n";
			$file .= '$db[$column][\'name\']  = "'.$result['0'].'"'.";\n";
			$file .= '$db[$column][\'type\']  = "'.$result['1'].'"'.";\n\n";
			if ($result['5']=="auto_increment") {
				$file .= '$dbid = "'.$result['0'].'";'."\n";
				};
			}
Esempio n. 5
0
	
	// getting the id
	include $table_file[$_GET['table']];
	$q = "SELECT * FROM " . $_GET['table'] . " WHERE " . $dbid . " = '".$_GET['id']."'";
	$query = lfquery($q);
	$result = mysql_fetch_array($query);
	
	// Checking for action
	if ($_POST['do']=="edit") {
		$q2 = "UPDATE " . $_POST['table'] . " SET `" . $_POST['field'] . "` = '" . $_POST['value'] . "' WHERE " . $_POST['id_name'] . " = '".$_POST['id_value']."'";
		lfquery($q2);
		header('Location: index.php');
		}
	elseif ($_POST['do']=="del") {
		$q2 = "DELETE FROM `" . $_POST['table'] . "` WHERE " . $_POST['id_name'] . " = '".$_POST['id_value']."'";
		lfquery($q2);
		header('Location: index.php');
		};

	// Showing edit options
	 ?>
	<form enctype="multipart/form-data" action="lfadmin.php" method="post" id="artwork_form"
 target="_self">

	<input type=hidden name="table" value="<? echo $_GET['table']; ?>">
	<input type=hidden name="field" value="<? echo $_GET['field']; ?>">
	<input type=hidden name="do"    value="del">
	<input type=hidden name="id_name" value="<? echo $dbid; ?>">
	<input type=hidden name="id_value" value="<? echo $_GET['id']; ?>">	
	<div align=center><input type=submit value="delete row '<? echo $_GET['id']?>' from <? echo $_GET['table']?> (no way to undo!)"></div>
	</form>
Esempio n. 6
0
<?
// tips
//count how many tips there are
$q_tip = "SELECT COUNT(*) FROM tips";
$query_tip = lfquery($q_tip);
if ($query_tip<>"") {
	$tip_result = mysql_fetch_row($query_tip);
	};
$counted_tips=$tip_result['0'];

// Random Tip
$_GET['tipid']=rand(1, $counted_tips);


// product of the week
$_GET['prodid']="1";
?>
Esempio n. 7
0
function add ($lfaction_set,$_POST,$lfaction_static,$table_file,$lfaction_type,$lfaction_get,$lfaction_file) {
		// adding the "push" option
	if (($lfaction_set['action']=="add") AND ($lfaction_set['push']['field']<>"")) {
		mysql_query("UPDATE `book` SET `" . $lfaction_set['push']['field']."`=`" . $lfaction_set['push']['field'] . "`+" . $lfaction_set['push']['value']." WHERE `place`>=". $_POST[$lfaction_set['push']['field']] . ";");
			};

	$sql_query="INSERT INTO " . $lfaction_set['table'] . "(";
	
		// The begining of the query
	$q="SHOW COLUMNS IN ".$lfaction_set['table'];
	$query=lfquery($q);
	while ($result=mysql_fetch_row($query)) {
		$sql_query .= "`".$result['0']."`, ";
		}

		// The values of the quiery
	$sql_query .= ") VALUES (";
			
	$q="SHOW COLUMNS IN ".$lfaction_set['table'];
	$query=lfquery($q);

	include $table_file[$lfaction_set['table']]; // From "system/list_lfdb_files.php"

	while ($result=mysql_fetch_row($query)) {

		if ($dbid<>$lfaction_set['table']) { // not including ID
			// Check if it is a normal text
//		echo $lfaction_type[$result['0']]."<br>";
			if (($lfaction_type[$result['0']]=="text") OR ($lfaction_type[$result['0']]=="mail")) {
				
				if ($lfaction_static[$result['0']]=="") {
					$sql_query .= "'".$_POST[$result['0']]."', ";
					};
				}
			// Check if it is a uploaded file
			elseif ($lfaction_type[$result['0']]=="file") {
				if ($lfaction_static[$result['0']]=="") {
					if ($_FILES[$result['0']]['name']<>"") {
						$sql_query .= "'".$lfaction_file[$result['0']]['upload_loc']."/".$_FILES[$result['0']]['name']."', ";
						}
					else {
						$sql_query .= "'', ";
						};
					};
				}
			elseif ($lfaction_type[$result['0']]=="md5") {
				if ($lfaction_static[$result['0']]=="") {
					$sql_query .= "'".md5($_POST[$result['0']])."', ";
					};
				}
			elseif ($lfaction_type[$result['0']]=="get") {
				
				$q55 = "SELECT " . $lfaction_get[$result['0']]['get'] . " FROM " . $lfaction_get[$result['0']]['table'] . " WHERE " . $lfaction_get[$result['0']]['where'] . " = '" . $lfaction_get[$result['0']]['with'] . "'";
				
				$query55 = lfquery ($q55);

				$get_result = mysql_fetch_row($query55);
				if ($lfaction_static[$result['0']]=="") {
					$sql_query .= "'".$get_result['0']."', ";
					};
				}

			// else inserting a blank value
			else {
				if ($lfaction_static[$result['0']]=="") {
					$sql_query .= "'', ";
					};
				};

			// check if it is a static value
			if ($lfaction_static[$result['0']]<>"") {
				$sql_query .= "'".$lfaction_static[$result['0']]."', ";
				};
			}
		}
	
		// The end of the query
	$sql_query .= ")      ";
	$sql_query = str_replace(", )", ")", $sql_query);
	if ($_POST['lfupdate']=="yes") {
		if ($lfaction_set['allow_update']   == "yes") {
			$sql_query_willbe = "UPDATE ".$lfaction_set['table']." SET ";
			$cutted_qery	      = split("\(",$sql_query); // splitting into 2 rows
			$cutted_qery_2_1= split("`",$cutted_qery['1']); // spliting row 1 - for fields
			$cutted_qery_2_2= split("'",$cutted_qery['2']); // spliting row 1 - for values
			$update_fileds=split(",",$lfaction_set['update_fields']);
//			print_r($cutted_qery_2_1);echo "<br><br>";
//			print_r($cutted_qery_2_1);echo "<br><br>";exit;
			// Making a list of allowed fields
			foreach ($update_fileds as $fieldvalue) {
				$allow_update[$fieldvalue]="yes";
				$allow_update[" ".$fieldvalue]="yes";
				};
			$cutName=1;
			while ($cutted_qery_2_1[$cutName]<>"") {
				//caching allowed fields
				$cutValue= str_replace(") VALUES ","",$cutValue); // cleaning broken end
				$cutted_qery_2_2[$cutName]= str_replace("')","'",$cutted_qery_2_2[$cutName]); // cleaning broken end
//				echo $cutValue.":".$cutted_qery_2_2[$cutName]."<br>";
//				print_r($allow_update);
				if ($allow_update[$cutted_qery_2_1[$cutName]]=="yes") { // If update is allowed

					if ($cutted_qery_2_1[$cutName]<>$dbid) {
							// Checking if not empty
						if (($cutted_qery_2_2[$cutName]<>"") AND ($cutted_qery_2_2[$cutName]<>" ''")){
							$sql_query_willbe.=" `". $cutted_qery_2_1[$cutName]. "` = '" . $cutted_qery_2_2[$cutName]."' , ";
							};
						};
					};
				$cutName=$cutName+2;
				};
			};

		//cleaning end and adding key and fit in query
		
		$sql_query_willbe.="___";
		$sql_query_willbe = str_replace(") VALUES","",$sql_query_willbe);
		$sql_query=str_replace(", ___"," WHERE `".$dbid."` = '".$_POST['lfupdate_id']."'",$sql_query_willbe);
		};/*
	$sql_query = str_replace("||_-","(",$sql_query);
	$sql_query = str_replace("-_||",")",$sql_query);*/
	// Make a fix for multiple
//	$sql_query=str_replace(";\\')",";')",$sql_query);
//	$sql_query=str_replace(":\\')",":')",$sql_query);
	$sql_query=str_replace("\')     ","')",$sql_query);
	return ($sql_query);
	};