/ January 4, 2006

Terrel Asked: I was installing a blog on my site

I think this may have effect my directory? I clicked on the link to my directory and this is the messages I recieved:

“Fatal error: Call to a member function on a non-object in /home/costa/public_html/directory/include/functions.php on line 47”

I don’t know much about php but here is info for lines 40-51 I checked with dreamweaver

Quote:
40 */
41 function read_config($db) {
42 global $tables, $tpl;
43 $sql = “SELECT * FROM {$tables[‘config’][‘name’]}”;
44 $db->SetFetchMode(ADODB_FETCH_ASSOC);
45 $rs = $db->Execute($sql);
46 while (!$rs->EOF) {
47 define($rs->Fields(‘ID’), $rs->Fields
48 (‘VALUE’));
49 $rs->MoveNext();
50 }
51 }

Here is the whole code

Quote:
<?php

function read_config($db) {
global $tables, $tpl;
$sql = “SELECT * FROM {$tables[‘config’][‘name’]}”;
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$rs = $db->Execute($sql);
while (!$rs->EOF) {
define($rs->Fields(‘ID’), $rs->Fields(‘VALUE’));
$rs->MoveNext();
}
}

function get_tpl() {
$tpl = new IntSmarty(‘en’);
$tpl->template_dir = INSTALL_PATH.’templates’;
$tpl->compile_dir = INSTALL_PATH.’temp/templates’;
$tpl->cache_dir = INSTALL_PATH.’temp/cache’;
return $tpl;
}

function _L($str) {
global $tpl;
if (method_exists($tpl, ‘translate’))
return $tpl->translate($str);
else
return $str;
}

function get_table_data($table) {
global $tables;
$data = array ();
foreach ($tables[$table][‘fields’] as $col => $v) {
if (isset ($_REQUEST[$col])) {
$data[$col] = $_REQUEST[$col];
}
}
return $data;
}

function get_categs_tree($db, $id) {
global $tables;
static $categs = array (“0” => “[Top]”);
static $level = 0;
$level ++;
$rs = $db->Execute(“SELECT ID, TITLE FROM {$tables[‘category’][‘name’]} WHERE PARENT_ID = $id and SYMBOLIC <> 1 ORDER BY TITLE”);

while (!$rs->EOF) {
if (empty($_SESSION[‘user_id’]) ||$_SESSION[‘is_admin’]) {
$categs[$rs->Fields(‘ID’)] = str_repeat(‘|’, $level -1).’|___’.$rs->Fields(‘TITLE’);
} else {
if (in_array($rs->Fields(‘ID’),$_SESSION[‘user_permission_array’])){
$categs[$rs->Fields(‘ID’)] = str_repeat(‘|’, $level -1).’|___’.$rs->Fields(‘TITLE’);
}
}
get_categs_tree($db, $rs->Fields(‘ID’));
$rs->MoveNext();
}
$level –;
return $categs;
}

function get_grant_categs_tree($db, $id) {
global $tables;
static $categs = array (“0” => “[Top]”);
static $level = 0;
$level ++;
$rs = $db->Execute(“SELECT ID, TITLE FROM {$tables[‘category’][‘name’]} WHERE PARENT_ID = $id and SYMBOLIC <> 1 ORDER BY TITLE”);

while (!$rs->EOF) {
if ($_SESSION[‘is_admin’]) {
$categs[$rs->Fields(‘ID’)] = str_repeat(‘|’, $level -1).’|___’.$rs->Fields(‘TITLE’);
} else {
if (in_array($rs->Fields(‘ID’),$_SESSION[‘user_grant_permission_array’])){
$categs[$rs->Fields(‘ID’)] = str_repeat(‘|’, $level -1).’|___’.$rs->Fields(‘TITLE’);
}
}
get_grant_categs_tree($db, $rs->Fields(‘ID’));
$rs->MoveNext();
}
$level –;
return $categs;
}

function get_client_ip() {
if (isset ($_SERVER[‘HTTP_X_FORWARDED_FOR’]))
$ipAddress = $_SERVER[‘HTTP_X_FORWARDED_FOR’];
else
$ipAddress = $_SERVER[‘REMOTE_ADDR’];
return $ipAddress;
}

function get_page($list_total) {
if (!isset ($_SESSION[‘p’])) {
$_SESSION[‘p’] = array ();
}
$page = isset ($_REQUEST[‘p’]) ? $_REQUEST[‘p’] : (isset ($_SESSION[SCRIPT_NAME][‘p’]) ? $_SESSION[SCRIPT_NAME][‘p’] : 1);
if (($page -1) > ($list_total / LINKS_PER_PAGE)) {
$page = floor($list_total / LINKS_PER_PAGE) + 1;
}
$_SESSION[SCRIPT_NAME][‘p’] = $page;
$_REQUEST[‘p’] = $page;
return $page;
}

function request_uri() {
if ($_SERVER[‘REQUEST_URI’])
return $_SERVER[‘REQUEST_URI’];

//IIS with ISAPI_REWRITE
if ($_SERVER[‘HTTP_X_REWRITE_URL’])
return $_SERVER[‘HTTP_X_REWRITE_URL’];
$p = $_SERVER[‘SCRIPT_NAME’];
if ($_SERVER[‘QUERY_STRING’])
$p .= ‘?’.$_SERVER[‘QUERY_STRING’];
return $p;
}

function get_category($uri = NULL) {
global $db, $tables;
if ($uri != NULL) {
$uri = parse_url($uri);
$query = $uri[‘query’];
$path = $uri[‘path’];
parse_str($query, $vars);
if (isset ($vars[‘c’]))
$cid = $vars[‘c’];
} else {
if (isset ($_REQUEST[‘c’]))
$cid = $_REQUEST[‘c’];
$path = request_uri();
}
$id = 0;
if (ENABLE_REWRITE && !isset ($cid)) {
$path = substr($path, strlen(DOC_ROOT) + 1);
$qp = strpos($path, ‘?’);
if ($qp !== false) {
$path = substr($path, 0, $qp);
}
$path = split(‘/’, $path);
$id = 0;
foreach ($path as $cat) {
if (!empty ($cat))
$id = $db->GetOne(“SELECT ID FROM {$tables[‘category’][‘name’]} WHERE STATUS=2 AND TITLE_URL = “.$db->qstr($cat).” AND PARENT_ID=”.$db->qstr($id));
}
}
elseif (preg_match(‘`\d+`’, $cid)) {
$id = $db->GetOne(“SELECT ID FROM {$tables[‘category’][‘name’]} WHERE STATUS=2 AND ID = $cid”);
}
return $id ? $id : ‘0’;
}
function get_path($id) {
global $db, $tables;
$path = array ();
$i = 0;
while ($id != 0 && $i < 100) {
$row = $db->GetRow(“SELECT * FROM {$tables[‘category’][‘name’]} WHERE ID = $id”);
$id = $row[‘PARENT_ID’];
$path[] = $row;
$i ++;
}
$path[] = array (‘ID’ => ‘0’, ‘TITLE’ => _L(SITE_NAME), ‘TITLE_URL’ => DOC_ROOT, ‘DESCRIPTION’ => SITE_DESC);
return array_reverse($path);
}

function validate_link($url) {
$ret = get_url($url, URL_HEADERS);
return array ($ret[‘status’] ? 2 : 0, ($ret[‘status’] || $ret[‘code’]) ? $ret[‘response’] : $ret[‘error’]);
}

function validate_url_online($value, $empty, & $params, & $form) {
$ret = get_url($value, URL_HEADERS);
return $ret[‘status’] ? 1 : 0;
}

function validate_recpr_link($value, $empty, & $params, & $form) {
global $tpl;
if ($empty && empty ($value))
return 1;
$ret = check_recpr_link($form);
if ($ret == -1) {
$tpl->assign(‘RECPR_ERROR’, _L(“The URL could not be validated. Either the page does not exist or the server could not be contacted.”));
return 0;
}
if ($ret == 0) {
$tmp = _L(“A link to #SITE_URL# could not be found at the specified URL.”);
$tmp = str_replace(‘#SITE_URL#’, SITE_URL, $tmp);
$tpl->assign(‘RECPR_ERROR’, $tmp);
return 0;
}
return 1;
}

function check_recpr_link($data) {
if (!trim($data[‘RECPR_URL’]))
return -1;
$ret = get_url($data[‘RECPR_URL’], URL_CONTENT);
if (!$ret[‘status’]) {
return -1;
}
if (empty ($data[‘RECPR_ID’])) { //Old validation method (until RC3)
return (preg_match(“`<a.*href=(\”|’)?”.SITE_URL.”/?(\”|’)?.*>`Ui”, $ret[‘content’]) && !preg_match(“`<a.*href=(\”|’)?”.SITE_URL.”/?(\”|’)?.*rel\s*=\s*(\”|’)nofollow(\”|’).*>`Ui”, $ret[‘content’])) == 0 ? 0 : 1;
} else { //New validation method
$valid = 0;
$rid = sprintf(‘R%X’, $data[‘RECPR_ID’]);
if (preg_match(“`<a(.*href=(\”|’)”.SITE_URL.”/?(\”|’).*)>(.*)</a>`Ui”, $ret[‘content’], $m)) {
error_log(sprint_r($m));
if (preg_match(“`id=(\”|’)”.$rid.”(\”|’)`i”, $m[1]) && !preg_match(“`rel\s*=\s*(\”|’)?\s*nofollow\s*(\”|’ )?`i”, $m[1])) {
$valid = 1;
}
}
return $valid;
}
}

define(‘URL_RESPONSE’, 0);
define(‘URL_HEADERS’, 1);
define(‘URL_CONTENT’, 2);
function get_url($url, $what = 0, $referer = “”, $cookies = array (), $useragent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)”) {
static $redirect_count = 0;
$ret = array ();
$ret[‘status’] = false;
$timeout = 10;
$urlArray = parse_url($url);
if (!$urlArray[‘port’]) {
if ($urlArray[‘scheme’] == ‘http’) {
$urlArray[‘port’] = 80;
}
elseif ($urlArray[‘scheme’] == ‘https’) {
$urlArray[‘port’] = 443;
}
elseif ($urlArray[‘scheme’] == ‘ftp’) {
$urlArray[‘port’] = 21;
}
}
if (!$urlArray[‘path’]) {
$urlArray[‘path’] = ‘/’;
}
$errno = “”;
$errstr = “”;
$fp = @ fsockopen($urlArray[‘host’].’.’, $urlArray[‘port’], $errno, $errstr, $timeout);
if ($fp) {
$request = “GET {$urlArray[‘path’]}”;
if (!empty ($urlArray[‘query’])) {
$request .= “?”.$urlArray[‘query’];
}
$request .= ” HTTP/1.1\r\n”.”Host: {$urlArray[‘host’]}\r\n”.”User-Agent: $useragent\r\n”;
if (!empty ($referer)) {
$request .= “Referer: $referer\r\n”;
}
$request .= “Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1\r\n”.”Accept-Language: en-us, en;q=0.50\r\n”.
#”Accept-Encoding: gzip, deflate, compress;q=0.9\r\n”.
//”Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66\r\n”.
#”Keep-Alive: 300\r\n”.
“Connection: close\r\n”.”Cache-Control: max-age=0\r\n”;
foreach ($cookies as $k => $v) {
$request .= “Cookie: $k=$v\r\n”;
}
$request .= “\r\n”;
fputs($fp, $request);
$ret[‘response’] = fgets($fp);
if (preg_match(“`HTTP/1\.. (.*) (.*)`U”, $ret[‘response’], $parts)) {
$ret[‘status’] = $parts[1][0] == ‘2’ || $parts[1][0] == ‘3’;
$ret[‘code’] = $parts[1];
if ($what == URL_RESPONSE || !$ret[‘status’]) {
fclose($fp);
return $ret;
}
$ret[‘headers’] = array ();
$ret[‘cookies’] = array ();
while (!feof($fp)) {
$header = fgets($fp, 2048);
if ($header == “\r\n” || $header == “\n” || $header == “\n\l”)
break;
list ($key, $value) = split(‘:’, $header, 2);
if (trim($key) == ‘Set-Cookie’) {
$value = trim($value);
$p1 = strpos($value, ‘=’);
$p2 = strpos($value, ‘;’);
$key = substr($value, 0, $p1);
$val = substr($value, $p1 +1, $p2 – $p1 -1);
$ret[‘cookies’][$key] = $val;
} else {
$ret[‘headers’][trim($key)] = trim($value);
}
}
if (($ret[‘code’] == ‘301’ || $ret[‘code’] == ‘302’) && !empty ($ret[‘headers’][‘Location’]) && $redirect_count < 20) {
$redirect_count ++;
fclose($fp);
if (strpos($ret[‘headers’][‘Location’], ‘http://’) === 0 || strpos($ret[‘headers’][‘Location’], ‘http://’)) {
$redir_url = $ret[‘headers’][‘Location’];
}
elseif (strpos($ret[‘headers’][‘Location’], ‘/’) === 0) {
$redir_url = $urlArray[‘scheme’].”://”.$urlArray[host].$ret[‘headers’][‘Location’];
} else {
$redir_url = $urlArray[‘scheme’].”://”.$urlArray[host].$urlArray[path].$ret[‘headers’][‘Location’];
}
return get_url($redir_url, $what, $url, $ret[‘cookies’]);
}
$redirect_count = 0;
if ($what == URL_HEADERS) {
fclose($fp);
return $ret;
}
$chunked = isset ($ret[‘headers’][‘Transfer-Encoding’]) && (‘chunked’ == $ret[‘headers’][‘Transfer-Encoding’]);
while (!feof($fp)) {
$data = ”;
if ($chunked) {
$line = fgets($fp, 128);
if (preg_match(‘/^([0-9a-f]+)/i’, $line, $matches)) {
$len = hexdec($matches[1]);
if (0 == $len) {
while (!feof($fp))
fread($fp, 4096);
} else {
$data = fread($fp, $len);
}
}
} else {
$data = fread($fp, 4096);
}
$ret[‘content’] .= $data;
}
} else {
$errstr = “Bad Communication”;
}
fclose($fp);
} else { // Occurs when if ($fp) returns false
}
$ret[‘error’] = $errstr;
return $ret;

}

function parse_news($str) {
$str = str_replace(“\r\n”, “\n”, $str);
$str = split(“\n”, $str);
$news = array ();
$len = count($str);
$i = 0;
while ($i < $len) {
if ($str[$i] == ”) {
$i ++;
continue;
}
$n = array ();
$n[‘title’] = $str[$i ++];
$n[‘date’] = $str[$i ++];
while ($i < $len && $str[$i] != ”)
$n[‘body’] .= $str[$i ++].”\n”;
$news[] = $n;
$i ++;
}
return $news;
}

function validate_unique($value, $empty, & $params, & $form) {
return check_unique($params[‘field2’], $params[‘field’], $value, $params[‘field3’], $params[‘field4’], $form[$params[‘field4’]]);
}

function check_unique($table, $field, $value, $exclude_id = NULL, $parent_field = NULL, $parent_value = NULL) {
global $tables, $db;
$sql = “SELECT COUNT(*) FROM “.$tables[$table][‘name’].” WHERE “.$field.” = “.$db->qstr($value);
if (strlen($exclude_id) > 0) {
$sql .= ” AND ID != “.$db->qstr($exclude_id);
}
if (isset ($parent_field)) {
$sql .= ” AND “.$parent_field.” = “.$db->qstr($parent_value);
}
$c = $db->GetOne($sql);
return $c == 0 ? 1 : 0;
}

function validate_symbolic_unique($value, $empty, & $params, & $form) {
global $tpl, $tables, $db, $id;
$sql = “SELECT COUNT(*) FROM “.$tables[‘category’][‘name’].” WHERE SYMBOLIC_ID = “.$value .” AND PARENT_ID = ” .$form[‘PARENT_ID’];
if ($id > 0) {
$sql .= ” AND ID <> “.$id;
}
$c = $db->GetOne($sql);
return $c == 0 ? 1 : 0;
}

function validate_symbolic_parent($value, $empty, & $params, & $form) {
global $tpl, $tables, $db;
$sql = “SELECT COUNT(*) FROM “.$tables[‘category’][‘name’].” WHERE ID = “.$value .” AND PARENT_ID = ‘” .$form[‘PARENT_ID’] . “‘”;
$c = $db->GetOne($sql);
return $c == 0 ? 1 : 0;
}

function validate_not_equal($value, $empty, & $params, & $form) {
return $value != $params[‘field2’];
}

function validate_not_equal_var($value, $empty, & $params, & $form) {
return $value != $form[$params[‘field2’]];
}

function parse_version($val) {
preg_match(‘`(\d+)\.(\d+)\.(\d+)\s*((RC)(\d+))?`’, $val, $match);
$ver = sprintf(“%02d%02d%02d%02d”, $match[1], $match[2], $match[3], $match[6]);
return $ver;
}

if (!function_exists(‘file_get_contents’)) {
function file_get_contents($fn) {
$len = filesize($fn);
if (!$len)
return false;
$fp = fopen($fn, ‘r’);
if ($fp) {
return fread($fp, $len);
} else
return false;
}
}
function set_log($file) {
ini_set(‘display_errors’, 0);
ini_set(‘log_errors’, 1);
ini_set(‘error_log’, INSTALL_PATH.’temp/’.$file);
error_reporting(E_ALL ^ E_NOTICE);
}

function replace_email_vars($text, $data, $type = 1) {
if ($type == 1) {
$prefix = ‘EMAIL_’;
}
elseif ($type == 2) {
$prefix = ‘LINK_’;
}
elseif ($type == 3) {
$prefix = ‘PAYMENT_’;
}
$text = str_replace(‘{MY_SITE_NAME}’, SITE_NAME, $text);
$text = str_replace(‘{MY_SITE_URL}’, SITE_URL, $text);
$text = str_replace(‘{MY_SITE_DESC}’, SITE_DESC, $text);
foreach ($data as $k => $v) {
$text = str_replace(“{“.$prefix.$k.”}”, $v, $text);
}
return $text;
}

function get_emailer() {
global $tables, $db;
require_once ‘libs/phpmailer/class.phpmailer.php’;
if (isset ($_SESSION[‘user_id’])) {
$where = “ID=”.$_SESSION[‘user_id’];
} else {
$where = “ADMIN = 1”;
}
$rs = $db->SelectLimit(“SELECT * FROM {$tables[‘user’][‘name’]} WHERE “.$where, 1);
$user = $rs->GetAssoc(true);
$mail = new PHPMailer();
$mail->PluginDir = ‘libs/phpmailer/’;
$mail->From = $user[‘EMAIL’];
$mail->FromName = $user[‘NAME’];
$mail->Mailer = EMAIL_METHOD;
switch (EMAIL_METHOD) {
case ‘smtp’ :
$mail->Host = EMAIL_SERVER;
if (strlen(EMAIL_USER) > 0) {
$mail->SMTPAuth = true;
$mail->Username = EMAIL_USER;
$mail->Password = EMAIL_PASS;
}
break;
case ‘sendmail’ :
$mail->Sendmail = EMAIL_SENDMAIL;
break;
}
return $mail;
}

function get_emailer_admin(){
global $tables, $db;
require_once ‘libs/phpmailer/class.phpmailer.php’;
$user = $db->GetRow(“SELECT * FROM {$tables[‘user’][‘name’]} WHERE ADMIN=1”);
$mail = new PHPMailer();
$mail->PluginDir = ‘libs/phpmailer/’;
$mail->From = $user[‘EMAIL’];
$mail->FromName = $user[‘NAME’];
$mail->Mailer = EMAIL_METHOD;
switch(EMAIL_METHOD){
case ‘smtp’:
$mail->Host = EMAIL_SERVER;
if(strlen(EMAIL_USER)>0){
$mail->SMTPAuth = true;
$mail->Username = EMAIL_USER;
$mail->Password = EMAIL_PASS;
}
break;
case ‘sendmail’:
$mail->Sendmail = EMAIL_SENDMAIL;
break;
}
return $mail;
}

function db_replace($table, $data, $keyCol) {
global $tables, $db;
foreach ($data as $key => $val) {
if (substr($tables[$table][‘fields’][$key], 0, 1) == ‘T’) {
$data[$key] = $db->DBDate($val);
} else {
$data[$key] = $db->qstr($val);
}
}
return $db->Replace($tables[$table][‘name’], $data, $keyCol, false);
}

function send_submit_notifications($data) {
global $db, $tables, $notif_msg;
if (DEMO)
return;
$sql = “SELECT SUBJECT, BODY FROM {$tables[’email_tpl’][‘name’]} WHERE ID=”.$db->qstr(NTF_SUBMIT_TPL);
$tmpl = $db->GetRow($sql);
if ($tmpl) {
$mail = get_emailer_admin();
$mail->Body = replace_email_vars($tmpl[‘BODY’], $data, 2);
$mail->Subject = replace_email_vars($tmpl[‘SUBJECT’], $data, 2);
$mail->AddAddress($data[‘OWNER_EMAIL’], $data[‘OWNER_NAME’]);
$sent = $mail->Send();
}

$tmpl = $notif_msg[‘submit’];
$rs = $db->Execute(“SELECT * FROM {$tables[‘user’][‘name’]} WHERE SUBMIT_NOTIF=1”);
$users = $rs->GetAssoc(true);
$mail = get_emailer_admin();
$mail->Body = replace_email_vars($tmpl[‘BODY’], $data, 2);
$mail->Subject = replace_email_vars($tmpl[‘SUBJECT’], $data, 2);
foreach ($users as $user) {
$mail->AddBCC($user[‘EMAIL’], $user[‘NAME’]);
}
$sent = $mail->Send();
}
function send_payment_notifications($pdata, $ldata) {
global $db, $tables, $notif_msg;
if (DEMO)
return;
$pdata[‘SUCCESS’] = $pdata[‘CONFIRMED’] ? ‘successful’ : ‘failed’;
$sql = “SELECT SUBJECT, BODY FROM {$tables[’email_tpl’][‘name’]} WHERE ID=”.$db->qstr(NTF_PAYMENT_TPL);
$tmpl = $db->GetRow($sql);
if ($tmpl) {
$mail = get_emailer();
$body = replace_email_vars($tmpl[‘BODY’], $ldata, 2);
$subject = replace_email_vars($tmpl[‘SUBJECT’], $ldata, 2);
$mail->Body = replace_email_vars($body, $pdata, 3);
$mail->Subject = replace_email_vars($subject, $pdata, 3);
$mail->AddAddress($data[‘OWNER_EMAIL’], $data[‘OWNER_NAME’]);
$sent = $mail->Send();
}
$tmpl = $notif_msg[‘payment’];
$rs = $db->Execute(“SELECT * FROM {$tables[‘user’][‘name’]} WHERE PAYMENT_NOTIF=1”);
$users = $rs->GetAssoc(true, true);
$mail = get_emailer();
$body = replace_email_vars($tmpl[‘BODY’], $ldata, 2);
$subject = replace_email_vars($tmpl[‘SUBJECT’], $ldata, 2);
$mail->Body = replace_email_vars($body, $pdata, 3);
$mail->Subject = replace_email_vars($subject, $pdata, 3);
foreach ($users as $user) {
$mail->AddBCC($user[‘EMAIL’], $data[‘NAME’]);
}
$sent = $mail->Send();
}

function date_add($timestamp, $months) {
$d = getdate($timestamp);
$mon = $months % 12;
$years = $months / 12;
$mytime = mktime($d[‘hours’], $d[‘minutes’], $d[‘seconds’], $d[‘mon’] + $mon, 1, $d[‘year’] + $years);
$days = min($d[‘mday’], date(‘t’, $mytime));
$mytime += ($days -1) * 86400;
return $mytime;
}

function calculate_expiry_date($start, $units, $um) {
switch ($um) {
case 1 :
$mul = 1;
break;
case 2 :
$mul = 3;
break;
case 3 :
$mul = 6;
break;
case 4 :
$mul = 12;
break;
default :
$mul = 0;
break;
}
if ($mul != 0) {
return date_add($start, $units * $mul);
}
return 0;
}

function update_link_payment($pid, $data, $success, $raw) {
global $db, $tables;

$pdata = $db->GetRow(“SELECT * FROM {$tables[‘payment’][‘name’]} WHERE ID = “.$db->qstr($pid));
if (!$pdata[‘ID’])
return;
$pdata[‘NAME’] = $data[‘name’];
$pdata[‘EMAIL’] = $data[’email’];
$pdata[‘PAYED_TOTAL’] = (int) $data[‘total’];
$pdata[‘PAYED_QUANTITY’] = (float) $data[‘quantity’];
$pdata[‘CONFIRMED’] = $success ? 1 : 0;
$pdata[‘CONFIRM_DATE’] = gmdate(‘Y-m-d H:i:s’);
$pdate[‘RAW_LOG’] = $raw;
db_replace(‘payment’, $pdata, ‘ID’);
$ldata = $db->GetRow(“SELECT * FROM {$tables[‘link’][‘name’]} WHERE ID = “.$db->qstr($pdata[‘LINK_ID’]));
send_payment_notifications($pdata, $ldata);
//Take no action if link not found
if (!$ldata[‘ID’])
return;
$ldata[‘EXPIRY_DATE’] = ”;
if ($pdata[‘CONFIRMED’] != 1 || (float) $pdata[‘PAYED_TOTAL’] < (float) $pdata[‘TOTAL’]) {
$ldata[‘PAYED’] = 0;
} else {
$ldata[‘PAYED’] = $pdata[‘ID’];
if (PAY_AUTO_ACCEPT) {
$ldata[‘STATUS’] = 2;
$exp_date = calculate_expiry_date(time(), $pdata[‘QUANTITY’], $pdata[‘UM’]);
if ($exp_date != 0) {
$ldata[‘EXPIRY_DATE’] = gmdate(‘Y-m-d H:i:s’, $exp_date);
}
}
}
db_replace(‘link’, $ldata, ‘ID’);

}

function sprint_r($val) {
ob_start();
print_r($val);
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}

function numeric_entify_utf8($utf8_string) {
$out = “”;
$ns = strlen($utf8_string);
for ($nn = 0; $nn < $ns; $nn ++) {
$ch = $utf8_string[$nn];
$ii = ord($ch);
//1 7 0bbbbbbb (127)
if ($ii < 128)
$out .= $ch;
//2 11 110bbbbb 10bbbbbb (2047)
else
if ($ii >> 5 == 6) {
$b1 = ($ii & 31);
$nn ++;
$ch = $utf8_string[$nn];
$ii = ord($ch);
$b2 = ($ii & 63);
$ii = ($b1 * 64) + $b2;
$ent = sprintf(“&#%d;”, $ii);
$out .= $ent;
}
//3 16 1110bbbb 10bbbbbb 10bbbbbb
else
if ($ii >> 4 == 14) {
$b1 = ($ii & 31);
$nn ++;
$ch = $utf8_string[$nn];
$ii = ord($ch);
$b2 = ($ii & 63);
$nn ++;
$ch = $utf8_string[$nn];
$ii = ord($ch);
$b3 = ($ii & 63);
$ii = ((($b1 * 64) + $b2) * 64) + $b3;
$ent = sprintf(“&#%d;”, $ii);
$out .= $ent;
}
//4 21 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
else
if ($ii >> 3 == 30) {
$b1 = ($ii & 31);
$nn ++;
$ch = $utf8_string[$nn];
$ii = ord($ch);
$b2 = ($ii & 63);
$nn ++;
$ch = $utf8_string[$nn];
$ii = ord($ch);
$b3 = ($ii & 63);
$nn ++;
$ch = $utf8_string[$nn];
$ii = ord($ch);
$b4 = ($ii & 63);
$ii = ((((($b1 * 64) + $b2) * 64) + $b3) * 64) + $b4;
$ent = sprintf(“&#%d;”, $ii);
$out .= $ent;
}
}
return $out;
}

function xml_utf8_encode($str){
return numeric_entify_utf8(htmlspecialchars($str));
}

function validate_email_and_add_link($value, $empty, & $params, & $form) {
global $tpl, $tables, $db, $id;
if ($form[‘TPL_TYPE’] !=3) {
return true;
}
if (!empty ($id)) {
return true;
} else {
$sql = “SELECT ID FROM “.$tables[’email_tpl’][‘name’].” WHERE TPL_TYPE = 3″;
$c = $db->GetOne($sql);
if ($c) {
return false;
} else {
return true;
}
}
}

function validate_not_sub_category($value, $empty, & $params, & $form) {
global $tpl, $tables, $db, $u;

$category = $value;

$sql = “SELECT PARENT_ID FROM “.$tables[‘category’][‘name’].” WHERE ID = “. $form[‘CATEGORY_ID’];
$category = $db->GetOne($sql);

if ($category != 0) {

$count_sql = “SELECT COUNT(*) FROM “.$tables[‘user_permission’][‘name’].” WHERE USER_ID = “.$db->qstr($u). ” AND (CATEGORY_ID = ” . $category;

while ($category != 0) {
$sql = “SELECT PARENT_ID FROM “.$tables[‘category’][‘name’].” WHERE ID = “. $category;
$category = $db->GetOne($sql);
if ($category != 0) {
$count_sql .= ” OR CATEGORY_ID = “. $category;
}
}
$count_sql .= “)”;
$c = $db->GetOne($count_sql);
} else {
$c = 0;
}
return $c == 0 ? 1 : 0;
}

function find_child_categories() {
global $tables, $db, $data, $u;

$child_count = 0;

$rs = $db->Execute(“SELECT CATEGORY_ID FROM {$tables[‘user_permission’][‘name’]} WHERE USER_ID = “.$db->qstr($u));

while (!$rs->EOF) {
$row = $rs->FetchRow();

$category = $row[‘CATEGORY_ID’];

while ($category != 0) {
$sql = “SELECT PARENT_ID FROM “.$tables[‘category’][‘name’].” WHERE ID = “. $category;
$category = $db->GetOne($sql);
if ($category == $data[‘CATEGORY_ID’]) {
$child_count++;
break;
}
}
}
$rs->Close();

return $child_count;
}

function delete_child_categories() {
global $tables, $db, $id, $u;

$child_count = 0;

$rs = $db->Execute(“SELECT ID, CATEGORY_ID FROM {$tables[‘user_permission’][‘name’]} WHERE USER_ID = “.$db->qstr($u));

while (!$rs->EOF) {
$row = $rs->FetchRow();

$category = $row[‘CATEGORY_ID’];

while ($category != 0) {
$sql = “SELECT PARENT_ID FROM “.$tables[‘category’][‘name’].” WHERE ID = “. $category;
$category = $db->GetOne($sql);
if ($category == $id) {
$db->Execute(“DELETE FROM {$tables[‘user_permission’][‘name’]} WHERE ID = “.$db->qstr($row[‘ID’]));
break;
}
}
}
$rs->Close();
}

function get_editor_permission($user_id) {
global $tables, $db, $user_grant_permission, $user_permission, $user_grant_permission_array, $user_permission_array;

$all_first_iteration = true;
$first_iteration = true;

$rs = $db->Execute(“SELECT CATEGORY_ID FROM {$tables[‘user_permission’][‘name’]} WHERE USER_ID = “.$db->qstr($user_id));

while (!$rs->EOF) {
$row = $rs->FetchRow();
if ($all_first_iteration) {
$user_permission = “ID = “.$row[‘CATEGORY_ID’];
$all_first_iteration = false;
} else {
$user_permission .= ” OR ID = “.$row[‘CATEGORY_ID’];
}

$user_permission_array[] = $row[‘CATEGORY_ID’];

$new_sub_categories = get_sub_categories($db, $row[‘CATEGORY_ID’]);

foreach ($new_sub_categories as $category_id) {
if ($first_iteration) {
$user_grant_permission = “ID = “.$category_id;
$user_permission .= ” OR ID = “.$category_id;
$first_iteration = false;
} else {
$user_grant_permission .= ” || ID = “.$category_id;
$user_permission .= ” OR ID = “.$category_id;
}
$user_permission_array[] = $category_id;
$user_grant_permission_array[] = $category_id;
}

}
$rs->Close();
}

function get_sub_categories($db, $id) {
global $tables;
$categs = array();
$rs = $db->Execute(“SELECT ID, TITLE FROM {$tables[‘category’][‘name’]} WHERE PARENT_ID = $id ORDER BY TITLE”);
while (!$rs->EOF) {
$categs[] = $rs->Fields(‘ID’);
$categs = array_merge($categs, get_sub_categories($db, $rs->Fields(‘ID’)));
$rs->MoveNext();
}
return $categs;
}

?>

How can this be fixed?

Hues asked: Just checked your directory, its working fine. , how did you fix this? I am having the same problem

Tarheit replied: I was able to fix it in my case by adding the following line to the beginning of index.php, submit.php, etc.

Code:
global $tables, $tpl, $db;

I think for some reason when the files .php files are included inside the blog (or cms in my case) they simply don’t get reconized as global and can’t be found by various functions that expect them.

This might vary depending on what you are trying to plug in to your cms/blog. Another real-estate system I had to plug in required the global statements to be added to the index.php of the cms rather than just the index.php of application I was trying to add on. So if the first doesn’t work, then try the other.

I should add that if your cms/blog already uses those variables elsewhere you could end up with a conflict requireing you to rename all references to the variable in the phpLD code.

(I suspect the orginal poster didn’t get it quite working yet as it appears it hasn’t been pluged into the blog, at least in the link he posted.)

My directory isn’t quite finished yet. It works, but I haven’t setup categories, etc. Just a few for testing. And I’m still working on the appearance. I also reworked the templates to have SEO links that fit within my current CMS.