PLEASE HELP - PLEASE HELP HOW TO MAKE THIS RUN FOR PHP+
<?php
// This is our base class for publishing plugins!
if ( ! class_exists ( "Publish" )) {
require "../includes/config.php";
class Publish {
var $sql;
function Publish ( $sql ) {
// get the database handle
$this->sql = $sql;
}
function getInfo () {
$details = array ();
$details [ 'name' ] = $this->getName ();
$details [ 'javascript' ] = $this->getJavaScript ();
return $details;
}
/* return an array containing all property data */
function getPropertyData ()
{
global $propertystatus_table;
global $propertylocations_table;
global $propertytypes_table;
global $propertyfeatures_table;
global $features_table;
global $property_table;
// firstly let's get the various info to make this job easier on MySQL<5
$status = array ();
$status_data = $this->sql->execute (
"SELECT id, propertystatus FROM " . $propertystatus_table,
SQL_RETURN_ASSOC );
for ( $i = 0; $i < sizeof ( $status_data ); ++$i )
{
$status [ $status_data [ $i ] [ "id" ] ] =
$status_data [ $i ] [ "propertystatus" ];
}
$location = array ();
$loc_data = $this->sql->execute (
"SELECT id, propertylocation FROM " . $propertylocations_table,
SQL_RETURN_ASSOC );
for ( $i = 0; $i < sizeof ( $loc_data ); ++$i )
{
$location [ $loc_data [ $i ] [ "id" ] ] =
$loc_data [ $i ] [ "propertylocation" ];
}
$type = array ();
$type_data = $this->sql->execute (
"SELECT id, propertytype FROM " . $propertytypes_table,
SQL_RETURN_ASSOC );
for ( $i = 0; $i < sizeof ( $type_data ); ++$i )
{
$type [ $type_data [ $i ] [ "id" ] ] =
$type_data [ $i ] [ "propertytype" ];
}
// get all property data
$data = $this->sql->execute (
"SELECT * FROM " . $property_table, SQL_RETURN_ASSOC );
// now go through and fill in the status, type and location data
for ( $i = 0; $i < sizeof ( $data ); ++$i )
{
// populate features information
$data [ $i ] [ 'propertyfeatures' ] = array ();
$features = $this->sql->execute (
"SELECT description FROM " . $features_table .
" INNER JOIN " . $propertyfeatures_table .
" ON (id=feature_id) WHERE property_id=" . $data [ $i ] [ "id" ],
SQL_RETURN_ASSOC );
for ( $f = 0; $f < sizeof ( $features ); ++$f )
{
error_log ( "Adding " . $features [ $f ] [ "description" ] .
" to the feature list for property." );
$data [ $i ] [ 'propertyfeatures' ] [] = $features [ $f ] [ "description" ];
}
$data [ $i ] [ 'propertytype_text' ] =
$type [ $data [ $i ] [ 'propertytype' ] ];
$data [ $i ] [ 'propertylocation_text' ] =
$location [ $data [ $i ] [ 'propertylocation' ] ];
$data [ $i ] [ 'propertystatus_text' ] =
$status [ $data [ $i ] [ 'propertystatus' ] ];
}
$fulldata [ 'data' ] = $data;
$fields = array (
'id',
'agentref',
'propertyoption',
'propertyref',
'propertytype',
'propertytype_text',
'propertyprice',
'propertybedrooms',
'propertybathrooms',
'propertyyearbuilt',
'propertylivingarea',
'propertyplotsize',
'propertyaddress',
'propertylocation',
'propertylocation_text',
'propertypostcode',
'propertycountry',
'shortdescription',
'longdescription',
'propertystatus',
'propertystatus_text',
'propertyphoto1',
'propertyphoto2',
'propertyphoto3',
'propertyphoto4',
'propertyphoto5',
'propertyphoto6',
'propertyphoto7',
'propertyphoto8',
'propertyphoto9',
'propertyphoto10',
'pdf',
'propertyviews',
'propertyshow',
'featuredproperty',
'propertyowner',
'dateadded' );
$fulldata [ 'fields' ] = $fields;
return $fulldata;
}
// these must be overridden
function getName () {}
function getJavaScript () {}
function constructForm () {}
function processForm ( $formdata, &$message )
{
$fulldata = $this->getPropertyData ();
$data = $fulldata [ 'data' ];
$fields = $fulldata [ 'fields' ];
header ( "Content-Type: text/tab-separated-values" );
header ( "Content-Disposition: attachment;filename=export.tsv" );
$rows = array ();
for ( $i = 0; $i < sizeof ( $data ); ++$i )
{
$vals = array ();
foreach ( $fields as $field )
{
array_push ( $vals,
preg_replace ( "/[\t\n\r]/", " ", $data [ $i ] [ $field ] ) );
}
array_push ( $rows, implode ( "\t", $vals ) );
}
print implode ( "\n", $rows );
exit ();
}
}
}
?>