db = new DB(); include(__CM_ETC_DIR__ . '/hosts.conf.php'); $_site_url = str_replace('www.', '', $_SERVER['HTTP_HOST']); $this->db->db = $set[$_site_url]['db']; $this->db->host = $set[$_site_url]['host']; $this->db->user = $set[$_site_url]['user']; $this->db->passwd = $set[$_site_url]['passwd']; $this->loc = $set[$_site_url]['path']; define('__DBNAME',$this->db->db); //$this->db->dbase = $this->database; $this->db->connect(); if(isset($_REQUEST['page'])){ $index = $this->db->showIndex($_REQUEST['page']); $this->table_id = $index[0]->Column_name; $this->Key_name = $index[0]->Key_name; $this->Column_name = $index[0]->Column_name; $this->label = (isset($index[1]) > 0)? $index[1]->Column_name:''; } } // Select records from table and returns them into a array of objects // to improve: $value[field] = value function select($table, $sort, $values = array()) { $c = 0; $_sql = "SELECT * FROM " . __DBNAME . ".$table"; if(sizeof($values) > 0){ $_sql .= ' WHERE '; foreach($values as $k => $v){ $c++; $_sql .= "$k = '$v'"; $_sql .= ($c < sizeof($values))? ' AND ':''; } } $_sql .= " ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); $this->sql = $_sql; if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == "81.179.238.73" || $_SERVER['REMOTE_ADDR'] == "81.86.31.102" || $_SERVER['REMOTE_ADDR'] == "10.0.0.34") { //echo $_sql.'
'; } return $res; } function login(){ $_sql = "SELECT * FROM user WHERE user_email = '$this->user_email' AND user_pwd = '$this->user_pwd'"; $this->db->query($_sql); $r = $this->db->fetch(); $this->user_type = $r[0]->type; //return $r; return mysql_num_rows($this->db->res); } function add($table, $values){ $i = 0; $_sql = "INSERT INTO " . $table . " ("; foreach ($values as $k => $v){ $i++; $_sql .= $k; $_sql .= ($i < count($values))? ',':')'; } $_sql .= " VALUES ("; $i = 0; foreach ($values as $k => $v){ $i++; $_sql .= "'" . addslashes($v) . "'"; $_sql .= ($i < count($values))? ',':')'; } $this->sql = $_sql; $res = $this->db->query($_sql); return $_sql; } function count($table){ $_sql = "SELECT COUNT(*) AS count FROM $table"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function update($table, $values, $id){ $i = 0; $_sql = "UPDATE ".$this->db->db.".$table SET "; foreach ($values as $k => $v){ if (substr($k, 0, 2) != 'id'){ $i++; $_sql .= "$k = '" . addslashes($v) . "'"; $_sql .= ($i < count($values))? ",":" WHERE " . $this->table_id . " = $id"; } } $this->sql = $_sql; return $this->db->query($_sql); //return $_sql; } function delete($table, $id){ $_sql = "DELETE FROM $table WHERE $this->table_id = $id"; return $this->db->query($_sql); //return $_sql; } function removeFile($page,$id,$field){ $item = $this->displayKey($page,$this->table_id,$id,$this->table_id); $file = explode('.',$item[0]->$field); if($file[1] == 'pdf'){ $path = 'pdf\\'; }elseif($file[1] == 'jpg' || $file[1] == 'gif'){ $path = 'images\\'; } unlink($this->loc . $path . $item[0]->$field); $values[$field] = ''; $this->update($page,$values,$id); echo '

File removed. Record Updated.

'; } function set($table, $flag, $value, $id){ $_sql = "UPDATE $table SET $flag = '$value' WHERE $table"."_id"."= $id"; return $this->db->query($_sql); //return $_sql; } function setOrphan($table, $field, $id){ $_sql = "UPDATE $table SET $field = 666 WHERE $field = $id"; return $this->db->query($_sql); //return $_sql; } function displayAll($table){ $_sql = "SELECT * FROM $table ORDER BY $this->table_id ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayOne($table, $value){ $_sql = "SELECT * FROM $table WHERE $this->table_id = $value"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayLast($table){ $_sql = "SELECT * FROM $table ORDER BY $table"."_id DESC LIMIT 1"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayKey($table, $key, $id, $sort){ $_sql = "SELECT * FROM $table WHERE $key = '$id' ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayKeyLimit($table, $key, $id, $sort, $limit){ $_sql = "SELECT * FROM $table WHERE $key = '$id' ORDER BY $sort ASC LIMIT $limit , 20"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayLike($table, $key, $id, $sort){ $_sql = "SELECT * FROM $table WHERE $key LIKE '%$id%' ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; //return $_sql; } function displayLikeM($table, $key, $id, $key1, $id1, $sort){ $_sql = "SELECT * FROM $table WHERE $key LIKE '%$id%' AND $key1 = '$id1' ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayLikeLimit($table, $key, $id, $sort,$limit){ $_sql = "SELECT * FROM $table WHERE $key LIKE '%$id%' ORDER BY $sort ASC LIMIT $limit , 20"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayKeyM($table, $key, $id, $key1, $id1, $sort){ $_sql = "SELECT * FROM $table WHERE $key = '$id' AND $key1 = '$id1' ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayKeyMulti($table, $key, $id, $sort){ $_sql = "SELECT * FROM $table WHERE "; foreach ($key as $k => $v){ $_sql .= "$v = '$id[$k]' "; echo (count($key) > $k)? "AND ":""; } $_sql .= "ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $_sql; } function display($table, $sort){ $_sql = "SELECT * FROM $table ORDER BY $sort ASC"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function displayLimit($table, $sort,$limit){ $_sql = "SELECT * FROM $table ORDER BY $sort ASC LIMIT $limit, 20"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function joint($key1, $key2, $key3, $id){ $_sql = "SELECT * FROM $key1 a, $key2 b, $key3 c WHERE a.$key2 = b.".$key2."_id and b.$key3 = c.".$key3."_id and c.".$key3."_id = $id"; $this->db->query($_sql); $res = $this->db->fetch(); return $res; } function checkRef($src, $string){ if(!($c=curl_init($src))){ die("Cannot open $src "); } $s = "href=\"http:\/\/" . $string ."\""; $s = "/$s/i"; //$s = "/$string/i"; curl_setopt($c, CURLOPT_RETURNTRANSFER,1); // return into a variable $this->fp = curl_exec($c); //var_dump($fp); curl_close($c); //CHECK FOR MATCHES INTO LOADED FILE if (preg_match($s, $this->fp)){ echo $string . " is reciprocate on $src"; return TRUE; }else{ echo $string . " is NOT reciprocate on $src"; return FALSE; } } function searchString($string, $array, $flags,$search_type){ foreach($array as $value){ $_surname = ($value == 'member')? ', member_surname, organisation ':''; $_topic = ($value == 'subtopic')? ', topic ':''; $_subject = ($value == 'exhibition' || $value == 'venue')? ', subject':''; $_expires = ($value == 'exhibition')? " AND (end_date > NOW() OR end_date = '0000-00-00')":''; $_web_area = ($value == 'web_content')? ', web_area ':''; $_fields = $this->db->showIndex($value); $_sql = "SELECT " . "Firstname,Surname,contact_id"; if($string != ''){ //$_sql .= ($value == 'member')? ",MATCH(member_surname":", MATCH(caption"; $_sql .= ", MATCH(Firstname"; foreach($_fields as $field){ if ($field->Index_type == 'FULLTEXT' && $field->Column_name != "Firstname"){ $_sql .= " ," . $field->Column_name; } } $_sql .= ($search_type == 'phrase')? ") AGAINST ('\"" . addslashes($string) . "\"' IN BOOLEAN MODE) AS relevance":") AGAINST ('*" . addslashes($string) . "*' IN BOOLEAN MODE) AS relevance"; } $_sql .= " FROM " . $value . " WHERE "; if($string != ''){ $_sql .= ($value == 'member')? "MATCH(member_surname":"MATCH(Firstname"; foreach($_fields as $field){ if ($field->Index_type == 'FULLTEXT' && $field->Column_name != "Firstname"){ $_sql .= " ," . $field->Column_name; } } $_sql .= ($search_type == 'phrase')? ") AGAINST ('\"" . addslashes($string) . "\"' IN BOOLEAN MODE)":") AGAINST ('*" . addslashes($string) . "*' IN BOOLEAN MODE)"; }else{ $_sql .= "ins_date <= '" . date('Y-m-d') . "'"; } if (sizeof($flags) > 0){ foreach($flags as $k => $v){ $_operator = ($k == 'organisation' || $k == 'fee' || $k == 'size' || $k == 'region')? '=' . $v :" LIKE '%" . $v . "%'"; $_newly = ($k == 'ins_date')? ' AND ' . $k . ' >= "' . $v . '"':''; $_sql .= ($k != 'ins_date')? " AND " . $k . $_operator:""; $_sql .= $_newly; } } $_sql .= ($value == 'member' || $value == 'vanue' || $value == 'exhibition')? " AND status = 'active'":""; $_sql .= $_expires; if($string != ''){ $_sql .= " ORDER BY relevance DESC"; }else{ $_sql .= " ORDER BY caption ASC"; } $this->db->query($_sql); $res[] = $this->db->fetch(); $_sql = ''; } return $res; } function searchLike($table, $values, $flags = array()){ $_sql = "SELECT * FROM $table WHERE "; $c = 0; foreach($values as $k => $v) { $c++; $_sql .= $k . " LIKE '%" . $v . "%'"; $_sql .= ($c < sizeof($values))? " OR ":""; } $c = 0; if(sizeof($flags) > 0) { foreach($flags as $k => $v) { $c++; $_sql .= " AND " . $k . " = '" . $v . "'"; //$_sql .= ($c < sizeof($flags))? " AND ":""; } } $this->sql = $_sql; $this->db->query($_sql); return $this->db->fetch(); } } ?>