Viewing file: admin.booklibrary.class.impexp.php (25.24 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/**
*
* @package Booklibrary
* @copyright 2009 Andrey Kvasnevskiy-OrdaSoft([email protected]);Rob de Cleen([email protected])
* Homepage: http://www.joomlawebserver.com
* @version: 1.5.2 Free $
*
**/
function print_vars($obj) {
$arr = get_object_vars($obj);
while (list($prop, $val) = each($arr))
if(class_exists($val)) print_vars($val);
else echo "\t $prop = $val\n<br />";
}
function print_methods($obj) {
$arr = get_class_methods(get_class($obj));
foreach ($arr as $method) echo "\tfunction $method()\n <br />";
}
if (PHP_VERSION >= 5) {
// Emulate the old xslt library functions
function xslt_create() {
return new XsltProcessor();
}
function xslt_process($xsltproc,
$xml_arg,
$xsl_arg,
$xslcontainer = null,
$args = null,
$params = null) {
// Create instances of the DomDocument class
$xml = new DomDocument;
$xsl = new DomDocument;
// Load the xml document and the xsl template
$xml->load($xml_arg);
$xsl->load($xsl_arg);
// Load the xsl template
$xsltproc->importStyleSheet($xsl);
// Set parameters when defined
if ($params) {
foreach ($params as $param => $value) {
$xsltproc->setParameter("", $param, $value);
}
}
// Start the transformation
$processed = $xsltproc->transformToXML($xml);
// Put the result in a file when specified
if ($xslcontainer) {
return @file_put_contents($xslcontainer, $processed);
} else {
return $processed;
}
}
function xslt_free($xsltproc) {
unset($xsltproc);
}
}
class mosBooklibraryImportExport{
/**
* Imports the lines given to this method into the database and writes a
* table containing the information of the imported books.
* The imported books will be set to [not published]
* Format: #;id;isbn;title;author;language
* @param array lines - an array of lines read from the file
* @param int catid - the id of the category the books should be added to
*/
function importBooksCSV($lines, $catid){
global $database;
$retVal= array();
$i = 0;
foreach ($lines as $line) {
$tmp = array();
$book = new mosBookLibrary($database);
if(trim($line) == "" ) continue;
$line = explode('|', $line);
/*print_r($line);
echo "<br /><br />";*/
$book->bookid = intval($line[0]);
$book->isbn = $line[1];
$book->title = $line[2];
$book->authors = $line[3];
$book->manufacturer = $line[4];
$book->catid = $catid;
//$book->date = date("Y-m-d H:i:s");
$book->date = $line[15];
$book->language = $line[6];//Language
$book->comment = $line[16];//Book Description
// optimize!!!
$tmp[0] = $i;
$tmp[1] = $book->bookid;
$tmp[2] = $line[1];
$tmp[3] = $line[2];
$tmp[4] = $line[3];
$tmp[5] = $line[4];
if (!$book->check() ) {
$tmp[6] = $book->getError();
$retVal[$i] = $tmp;
$i++;
continue;
}
if ( !$book->store()) {
$tmp[6] = $book->getError();
$retVal[$i] = $tmp;
$i++;
continue;
$tmp[6] = $book->getError();
} else {
$tmp[6] = "OK";
}
$book->checkin();
$book->updateOrder( "catid='$book->catid'" );
$retVal[$i] = $tmp;
$i++;
}
//exit;
return $retVal;
}
function getXMLItemValue($item,$item_name) {
$book_items = $item->getElementsByTagname( $item_name );
$book_item = $book_items->item(0);
if(NULL != $book_item) return $book_item->nodeValue ;
else return "";
}
//***************************************************************************************************
//*********************** begin add for import XML format ***************************************
//***************************************************************************************************
function importBooksXML($files_name_pars, $catid)
{
global $database;
$retVal= array();
$k = 0;
$dom = new domDocument('1.0','windows-1251');
$dom->load($files_name_pars);
$book_list = $dom->getElementsByTagname('book');
$st = $bookid = "";
$begin = $end = $kol = 0;
for ($i = 0; $i < $book_list->length; $i++) {
$book_class = new mosBookLibrary($database);
$book = $book_list->item($i);
// echo $book_item->hasChildNodes() . "<br />";
//get BookID
$book_id = $book_class->bookid = mosBooklibraryImportExport::getXMLItemValue($book,'bookid');
//get ISBN
$book_isbn = $book_class->isbn = mosBooklibraryImportExport::getXMLItemValue($book,'isbn');
//get Title(book)
$book_title = $book_class->title = mosBooklibraryImportExport::getXMLItemValue($book,'title');
//get Authors
$book_authors = $book_class->authors = mosBooklibraryImportExport::getXMLItemValue($book,'authors');
//get Manufacturer
$book_manufacturer = $book_class->manufacturer = mosBooklibraryImportExport::getXMLItemValue($book,'manufacturer');
//get releasedate
$book_class->release_Date = mosBooklibraryImportExport::getXMLItemValue($book,'releasedate');
//get language
$book_class->language = mosBooklibraryImportExport::getXMLItemValue($book,'language');
//get hits
$book_class->hits = mosBooklibraryImportExport::getXMLItemValue($book,'hits');
//get rating
$book_class->rating = mosBooklibraryImportExport::getXMLItemValue($book,'rating');
//get price
$book_class->price = mosBooklibraryImportExport::getXMLItemValue($book,'price');
//get URL
$book_class->URL = mosBooklibraryImportExport::getXMLItemValue($book,'url');
//get imageURL
$book_class->imageURL = mosBooklibraryImportExport::getXMLItemValue($book,'imageURL');
//get edition
$book_class->edition = mosBooklibraryImportExport::getXMLItemValue($book,'edition');
//get ebookURL
$book_class->ebookURL = mosBooklibraryImportExport::getXMLItemValue($book,'ebookURL');
//get informationFrom
$book_class->informationFrom = mosBooklibraryImportExport::getXMLItemValue($book,'informationFrom');
//get date
$book_class->date = mosBooklibraryImportExport::getXMLItemValue($book,'date');
//get comment
$book_class->comment = mosBooklibraryImportExport::getXMLItemValue($book,'comment');
//get Categorie
$book_class->catid = $catid;
//get Language
$book_class->language = mosBooklibraryImportExport::getXMLItemValue($book,'language');
//get Comment for book (item Book Description)
$book_class->comment = mosBooklibraryImportExport::getXMLItemValue($book,'comment');
//for output rezult in table
$tmp[0] = $i;
$tmp[1] = $book_id;
$tmp[2] = $book_isbn;
$tmp[3] = $book_title;
$tmp[4] = $book_authors;
$tmp[5] = $book_manufacturer;
if ( !$book_class->check() ){
$tmp[6] = $book_class->getError();
continue;
}
if ( !$book_class->store() ){
$tmp[6] = $book_class->getError();
continue;
} else { $tmp[6] = "OK"; }
$book_class->checkin();
$book_class->updateOrder( "catid='$book_class->catid'" );
$retVal[$i] = $tmp;
//get Reviews
if( $tmp[6] = "OK" && mosBooklibraryImportExport::getXMLItemValue($book,'reviews') != "" ){
$review_list = $book->getElementsByTagname('review');
for ($j = 0; $j < $review_list->length; $j++) {
$review = $review_list->item($j);
//get for review - fk_bookid == #__booklibrary.id
$database->setQuery("SELECT id FROM #__booklibrary ".
"\n WHERE isbn = '".$book_isbn."';");
$fk_bookid = $database->loadResult();
//get for review - fk_userid
$review_fk_userid = mosBooklibraryImportExport::getXMLItemValue($review,'fk_userid');
//check - exist this user or not - if don't exist set he as anonymous
$database->setQuery("SELECT id FROM #__users ".
"\n WHERE id = ".$review_fk_userid . ";");
$review_fk_userid = $database->loadResult();
if( count($review_fk_userid) == 0 ) $review_fk_userid = 0;
//get for review - date
$review_date = mosBooklibraryImportExport::getXMLItemValue($review,'date');
//get for review - rating
$review_rating = mosBooklibraryImportExport::getXMLItemValue($review,'rating');
//get for review - title
$review_title = mosBooklibraryImportExport::getXMLItemValue($review,'title');
//get for review - comment
$review_comment = mosBooklibraryImportExport::getXMLItemValue($review,'comment');
//insert data in table jos_booklibrary_review
$database->setQuery("INSERT INTO #__booklibrary_review".
"\n (fk_bookid, fk_userid, date, rating, title, comment)".
"\n VALUES ".
"\n (".$fk_bookid.", ".$review_fk_userid.", '".$review_date."',".$review_rating.",'".$review_title."', '".$review_comment."');");
$database->query();
} //end for(...) - REVIEW
}
}//end for(...) - BOOK
return $retVal;
}
//***************************************************************************************************
//*********************** end add for import XML format *****************************************
//***************************************************************************************************
function exportBooksXML($books, $all){
global $mosConfig_live_site, $mosConfig_absolute_path, $booklibrary_configuration;
$xmlDoc =& new DOMIT_Document();
$xmlDoc->appendChild($xmlDoc->createProcessingInstruction('xml', "version=\"1.0\" encoding=\"iso-8859-2\""));
//$xmlDoc->appendChild($xmlDoc->createProcessingInstruction("xml-stylesheet", "type=\"text/xslt\" href=\"standard.css\"");
//append doctype info; just pass in doctype name and text
/*$doctypeText = "<!DOCTYPE sr:staterotation [\n\t" .
"<!ELEMENT sr:staterotation (sr:rotation+)>\n\t" .
"<!ELEMENT sr:rotation (sr:state, sr:banner)>\n\t" .
"<!ELEMENT sr:state (#PCDATA)>\n\t" .
"<!ELEMENT sr:banner (#PCDATA)>\n" .
"]>)";
$doctype =& new DOMIT_DocumentType('sr:staterotation', $doctypeText);
$xmldoc->appendChild($doctype);*/
//create and append list element
$xmlDoc->appendChild($xmlDoc->createElement("books"));
foreach ($books as $book) {
$xmlDoc->documentElement->appendChild($book->toXML( $xmlDoc, $all));
}
// $fileAddr = "/administrator/components/com_booklibrary/exports/" . "booklibrary_" . date("Ymd_His") . ".xml";
return $xmlDoc->toNormalizedString ();
}
function storeExportFile($data, $type){
global $mosConfig_live_site, $mosConfig_absolute_path, $booklibrary_configuration;
$fileName = "booklibrary_" . date("Ymd_His");
$fileBase = "/administrator/components/com_booklibrary/exports/";
//echo 'PRINT : '.$mosConfig_absolute_path;exit;
//write the xml file
$fp = fopen($mosConfig_absolute_path . $fileBase . $fileName . ".xml" , "w", 0); #open for writing
fwrite($fp, $data); #write all of $data to our opened file
fclose($fp); #close the file
$InformationArray = array();
$InformationArray['xml_file'] = $fileName . '.xml';
$InformationArray['log_file'] = $fileName . '.log';
$InformationArray['fileBase'] = "file://" . getcwd (). "/components/com_booklibrary/exports/";
$InformationArray['urlBase'] = $mosConfig_live_site . $fileBase;
$InformationArray['out_file'] = $InformationArray['xml_file'];
$InformationArray['error'] = null;
switch($type){
case 'csv':
$InformationArray['xslt_file'] = 'csv.xsl';
$InformationArray['out_file'] = $fileName . '.csv';
mosBooklibraryImportExport :: transformPHP4($InformationArray);
break;
default:
break;
}
return $InformationArray;
}
function transformPHP4(&$InformationArray){
// create the XSLT processor^M
$xh = xslt_create() or die("Could not create XSLT processor");
// Process the document
$result = xslt_process($xh, $InformationArray['fileBase'].$InformationArray['xml_file'], $InformationArray['fileBase'].$InformationArray['xslt_file'], $InformationArray['fileBase'].$InformationArray['out_file']);
if (!$result)
{
// Something croaked. Show the error
$InformationArray['error'] = "Cannot process XSLT document: " . xslt_errno($xh) . " " . xslt_error($xh);
}
// Destroy the XSLT processor
xslt_free($xh);
}
////////// MY ///////////////////////////////////////////////
function datadump ($table) {
$cnt = 0;
$result = '';
$resrt = '';
$reslt = "# Dump of $table \n";
$reslt .= "# Dump DATE : " . date("d-M-Y") ."\n\n\n";
$query = mysql_query('select * $table');
while($Row = mysql_fetch_assoc($query))
{
// print_r($Row);
$reslt .= "INSERT INTO ".$table." (";
$resrt .= ") VALUES ('";
while (list($key, $value) = each($Row)) {
// echo "Key: $key; Value: $value<br />\n";
$reslt .= $key.",";
$resrt .= mysql_real_escape_string($value)."','";
}
$reslt = substr($reslt,0,-1);
$resrt = substr($resrt,0,-2);
$resrt .= ");\n";
$result .= ($reslt.$resrt);
$reslt ='';
$resrt ='';
}
return $result . "\n\n\n";
}
function wise_select_cat()
{
global $database;
$fcnt = 0;
$cnt = 0;
$parenttmp = 0;
$result ='';
$reslt = '';
$resrt = '';
$reslt = "# Dump of category \n";
$reslt .= "# Dump DATE : " . date("d-M-Y") ."\n\n\n";
$query = "select * from #__categories where section = 'com_booklibrary' order by parent_id";
$database->setQuery($query);
$Rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
for($i = 0; $i < count($Rows); $i++)
{
$reslt .= "INSERT INTO #__categories (";
$resrt .= ") VALUES ('";
while (list($key, $value) = each($Rows[$i])) {
$reslt .= $key.",";
switch($fcnt) //specialize params
{
case 0:
$resrt .= "','";
break;
case 1:
$resrt .= "%|%','";
break;
default:
$resrt .= mysql_real_escape_string($value)."','";
}
$fcnt++;
}
$reslt = substr($reslt,0,-1);
$resrt = substr($resrt,0,-2);
$resrt .= ")|%|\n";
$result .= ($reslt.$resrt);
$reslt ='';
$resrt ='';
$fcnt = 0;
}
return $result;
}
function wise_select_book()
{
global $database;
$fcnt = 0;
$cnt = 0;
$parenttmp = 0;
$result ='';
$reslt = '';
$resrt = '';
$reslt = "# Dump of \n";
$reslt .= "# Dump DATE : " . date("d-M-Y") ."\n\n\n";
$query = 'select * from #__booklibrary order by id';
$database->setQuery($query);
$Rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
for($i = 0; $i < count($Rows); $i++)
{
$reslt .= "INSERT INTO #__booklibrary (";
$resrt .= ") VALUES ('";
while (list($key, $value) = each($Rows[$i])) {
$reslt .= $key.",";
switch($fcnt)
{
case 0:
$resrt .= "','";
break;
case 2:
$resrt .= "%|%','";
break;
default:
$resrt .= $database->getEscaped($value)."','";
}
$fcnt++;
}
$reslt = substr($reslt,0,-1);
$resrt = substr($resrt,0,-2);
$resrt .= ")|%|\n";
$result .= ($reslt.$resrt);
$reslt ='';
$resrt ='';
$fcnt = 0;
}
return $result;
}
function select_catid()
{
global $database;
$str ='';
$c = 0;
$i = 0;
$query = 'select catid from #__booklibrary order by id';
$database->setQuery($query);
$Rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
$arr = array();
$arr = array_values($Rows);
for($i = 0; $i < count($Rows); $i++)
{
list($key, $value) = each($Rows[$i]);
$arr[$c] = $value;
$c++;
}
for($i = 0;$i < count($arr); $i++)
{
$tmp = $arr[$i];
$str .= $tmp. "::";
}
return substr($str,0,-2);
}
function select_linked()
{
global $database;
$str ='';
$c = 0;
$i = 0;
$query = 'select id, parent_id from #__categories where section = "com_booklibrary" order by parent_id';
$database->setQuery($query);
$Rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
$arr = array();
for($i = 0; $i < count($Rows); $i++)
{
list($key, $value) = each($Rows[$i]);
$arr[$c][0] = $value;
list($key, $value) = each($Rows[$i]);
$arr[$c][1] = $value;
$c++;
}
for($i = 0;$i < count($arr); $i++)
{
$tmp0 = $arr[$i][0];
$tmp1 = $arr[$i][1];
$str .= $tmp0. "::".$tmp1."::";
}
return substr($str,0,-2);
}
//************ begin add for 'MySQL tables import/export' #__booklibrary_review **********
function wise_select_review()
{
global $database;
$fcnt = 0;
$cnt = 0;
$parenttmp = 0;
$result ='';
$reslt = '';
$resrt = '';
$reslt = "# Dump of \n";
$reslt .= "# Dump DATE : " . date("d-M-Y") ."\n\n\n";
$query = 'select * from #__booklibrary_review order by id';
$database->setQuery($query);
$Rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
for($i = 0; $i < count($Rows); $i++)
{
$reslt .= "INSERT INTO #__booklibrary_review (";
$resrt .= ") VALUES ('";
while (list($key, $value) = each($Rows[$i])) {
$reslt .= $key.",";
switch($fcnt)
{
case 1:
$resrt .= "','";
break;
default:
$resrt .= $database->getEscaped($value)."','";
}
$fcnt++;
}
$reslt = substr($reslt,0,-1);
$resrt = substr($resrt,0,-2);
$resrt .= ")|%|\n";
$result .= ($reslt.$resrt);
$reslt ='';
$resrt ='';
$fcnt = 0;
}
return $result;
}
function load_isbn() {
global $database;
$result ='';
$result = "# Dump of \n";
$result .= "# Dump DATE : " . date("d-M-Y") ."\n\n\n";
$query = 'SELECT review.id,book.isbn FROM #__booklibrary_review AS review, #__booklibrary AS book WHERE review.fk_bookid=book.id;';
$database->setQuery($query);
$rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
for ($i = 0; $i < count($rows); $i++) {
if ($i == 0) {$result .= "::".$rows[$i]->id."::".$rows[$i]->isbn."::";}
else {$result .= $rows[$i]->id."::".$rows[$i]->isbn."::";}
}
return $result;
}
//*********** end add for 'MySQL tables import/export' #__booklibrary_review *************
function entire_export()
{
global $mosConfig_absolute_path,$mosConfig_live_site;
$cats = mosBooklibraryImportExport::wise_select_cat();
$books = mosBooklibraryImportExport::wise_select_book();
$reviews = mosBooklibraryImportExport::wise_select_review();
$id_isbn = mosBooklibraryImportExport::load_isbn();
$sarr = mosBooklibraryImportExport::select_catid();
$carr = mosBooklibraryImportExport::select_linked();
$fileName = "booklibrary_full_backup_" . date("Ymd_His").".dat";
$fileBase = "/administrator/components/com_booklibrary/exports/";
$file_path = $mosConfig_absolute_path.$fileBase.$fileName;
$fp = fopen($file_path,"w");
fwrite($fp,$books."\n\n###CAT\n\n".$cats."\n\n###".$sarr."\n\n###".$carr."\n\n###REVIEW\n\n".$reviews."\n\n###ISBN\n\n".$id_isbn);
fclose($fp);
$InformationArray = array();
$InformationArray['out_file'] = $fileName;
$InformationArray['urlBase'] = $mosConfig_live_site . $fileBase;
$InformationArray['error'] = null;
return $InformationArray;
}
////////////// IMPORT ////////////////
function import_cat($whole, $supp_file)
{
global $database;
$tmparr = array();
$cont = explode('|%|',$whole);
$arr = mosBooklibraryImportExport::load_arr($supp_file);
for($i = 0; $i<count($cont); $i++)
{
$strquer = substr( $cont[$i],strpos($cont[$i],"INSERT"));
if(substr($strquer,0,6)=="INSERT")
{
if($arr[$i][1] == 0)
{
$strquer = str_replace('%|%','0',$strquer);
}
else
{
$tmp_ind = mosBooklibraryImportExport::search_in_arr($arr[$i][1],$arr);
$strquer = str_replace('%|%',$tmparr[$tmp_ind],$strquer);
}
$database->setQuery($strquer);
$database->query();
if ($database->getErrorNum()) {
echo $database->stderr();
return $database->stderr();
}
$tmparr[$i] = $database->insertid();
$arr[$i][1] = $tmparr[$i];
}
}
return $arr;
}
function search_in_arr($search, $arr)
{
for($i = 0; $i<count($arr);$i++)
{
if($arr[$i][0] == $search) return $i;
}
return 0;
}
function load_arr($whole)
{
$arr = array();
$cont = explode('::', $whole);
for($i = 0; $i < count($cont)/2; $i ++)
{
$arr[$i][0] = $cont[$i*2];
$arr[$i][1] = $cont[$i*2+1];
}
return $arr;
}
function load_catid($whole)
{
$arr = array();
$cont = explode('::', $whole);
for($i = 0; $i < count($cont); $i ++)
$arr[$i] = $cont[$i];
return $arr;
}
function import_book($whole, $supp_file, $arr)
{
global $database;
$ctidarr = mosBooklibraryImportExport::load_catid($supp_file);
$cont = explode ('|%|',$whole);
for($i = 0; $i<count($cont); $i++)
{
$strquer = substr( $cont[$i],strpos($cont[$i],"INSERT"));
if(substr($strquer,0,6)=="INSERT")
{
$tmp_ind = mosBooklibraryImportExport::search_in_arr($ctidarr[$i] ,$arr);
$strquer = str_replace('%|%',$arr[$tmp_ind][1] ,$strquer);
$database->setQuery($strquer);
$database->query();
if ($database->getErrorNum()) {
echo $database->stderr();
return $database->stderr();
}
}
}
return "";
}
function import_review($review, $isbn)
{
global $database;//$pc[4]=review,$pc[5]=isbn
//select new bookid for review
$query = 'SELECT id,isbn FROM #__booklibrary;';
$database->setQuery($query);
$rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
$query = 'SELECT id FROM #__users;';
$database->setQuery($query);
$users = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
$st = $isbn;
$tmp = explode('::',$isbn);
$mas = "";
for ($i = 1; $i < count($tmp)-1; $i++) {
for ($j = 0; $j < count($rows); $j++) {
if ($tmp[$i] == $rows[$j]->isbn) $mas .= $rows[$j]->id."::";
}
}
//new fk_bookid = $mas[$i]
$mas = explode('::',$mas);//potom -- 'count($mas)-1'//in $mas = new id for jos_booklibrary
$st = $review;
$kol = strlen($st);
$st = substr($st, strpos($st, "INSERT"), $kol);
$insert = "";//rus --> 'это тот массив лементы которого надо будет вставить в базу'
for ($i = 0; $i < count($mas)-1; $i++) {
$k = strpos($st, "|%|");
$insert = substr($st, strpos($st, "INSERT"), $k);
$insert_1 = substr($insert,strpos($insert, "INSERT"), strpos($insert, ",'',"));
$insert_2 = substr($insert, strpos($insert, ",'',")+4, strlen($insert));
//insert user
$usr = substr($insert, strpos($insert, ",'',")+4, strlen($insert));
//$usr_1 == number user id old from file .dat
$usr_1 = substr($usr, strpos($usr, "'")+1, strpos($usr, "','")-1);
$usr_1 = (int)$usr_1;
$status = false;
for ($j = 0; $j < count($users); $j++) {
if ($users[$j]->id == $usr_1) $status = true;
}
if ($status) {
$zapros = $insert_1.",'".$mas[$i]."',".$insert_2;
} else {
$usr_2 = substr($usr, strpos($usr, ",'"), strlen($usr));
$zapros = $insert_1.",'".$mas[$i]."','0'".$usr_2;
}
$query = $zapros.";";
$database->setQuery($query);
@$kuku = $database->loadResult();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
$kol = strlen($st);
$st = substr($st, $k+4, $kol);
}
return "";
}
function remove_info()
{
global $database;
$database->setQuery('truncate #__booklibrary');
$database->query();
if ($database->getErrorNum()) {
echo $database->stderr();
return $database->stderr();
}
$database->setQuery("delete from #__categories where section='com_booklibrary'");
$database->query();
if ($database->getErrorNum()) {
echo $database->stderr();
return $database->stderr();
}
$database->setQuery('truncate #__booklibrary_review');
$database->query();
if ($database->getErrorNum()) {
echo $database->stderr();
return $database->stderr();
}
return "";
}
function entire_import($file)
{
global $mosConfig_absolute_path;
$ret = mosBooklibraryImportExport::remove_info();
if( $ret != "" ) return;
$fp = fopen($file,"r");
$whole = fread($fp,filesize($file));
$pc = array();
$pc = explode('###',$whole);
$urr = mosBooklibraryImportExport::import_cat(trim($pc[1]),trim($pc[3]));
if( !is_array($urr) ) return;
$ret = mosBooklibraryImportExport::import_book(trim($pc[0]),trim($pc[2]),$urr);
//$pc[4]=review,$pc[5]=isbn
$ret = mosBooklibraryImportExport::import_review(trim($pc[4]),trim($pc[5]));
if( $ret == "" ) echo "<h2 style='color:#0f0;'>OK</h2>";
}
}
?>
|