Viewing file: admin.booklibrary.php (66.89 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @package Booklibrary
* @copyright 2009 Andrey Kvasnevskiy-OrdaSoft([email protected]);Rob de Cleen([email protected])
* Homepage: http://www.joomlawebserver.com
* @version: 1.5.2 Free $
*
**/
defined( '_VM_IS_BACKEND' ) or define( '_VM_IS_BACKEND', '1' );
include_once( dirname(__FILE__).'/compat.joomla1.5.php' );
$my=$GLOBALS['my'];
$css = $mosConfig_live_site.'/administrator/components/com_booklibrary/includes/booklibrary.css';
include_once ($mainframe->getPath('admin_html'));
include_once ($mainframe->getPath('class'));
require_once ($mosConfig_absolute_path."/components/com_booklibrary/booklibrary.class.lend.php");
require_once ($mosConfig_absolute_path."/components/com_booklibrary/booklibrary.class.lend_request.php");
require_once ($mosConfig_absolute_path."/administrator/components/com_booklibrary/admin.booklibrary.class.ws.php");
require_once ($mosConfig_absolute_path."/administrator/components/com_booklibrary/admin.booklibrary.class.impexp.php");
require_once ($mosConfig_absolute_path."/administrator/components/com_booklibrary/admin.booklibrary.class.conf.php");
$GLOBALS['booklibrary_configuration'] = $booklibrary_configuration;
$GLOBALS['database'] = $database;
$GLOBALS['my'] = $my;
$GLOBALS['mosConfig_absolute_path'] = $mosConfig_absolute_path;
require_once ($mosConfig_absolute_path."/includes/domit/xml_domit_include.php");
// *** Get language files
if (file_exists($mosConfig_absolute_path."/components/com_booklibrary/language/{$mosConfig_lang}.php" ))
{
include_once($mosConfig_absolute_path."/components/com_booklibrary/language/{$mosConfig_lang}.php" );
}
else
{
include_once($mosConfig_absolute_path."/components/com_booklibrary/language/english.php" );
}
$bid = mosGetParam($_POST, 'bid', array (0));
$section = mosGetParam( $_REQUEST, 'section', 'courses' );
if($booklibrary_configuration['debug'] == '1'){
echo "Task: ".$task . "<br />";
print_r($_POST);
echo "<hr /><br />";
}
if (isset($section) && $section=='categories')
{
switch ($task){
case "edit" :
editCategory($option, $bid[0]);
break;
case "new":
editCategory($option, 0);
break;
case "cancel":
cancelCategory();
break;
case "save":
saveCategory();
break;
case "remove":
removeCategories($option, $bid);
break;
case "publish":
publishCategories("com_booklibrary", $id, $bid, 1);
break;
case "unpublish":
publishCategories("com_booklibrary", $id, $bid, 0);
break;
case "orderup":
orderCategory($bid[0], -1);
break;
case "orderdown":
orderCategory($bid[0], 1);
break;
case "accesspublic":
accessCategory($bid[0], 0);
break;
case "accessregistered":
accessCategory($bid[0], 1);
break;
case "accessspecial":
accessCategory($bid[0], 2);
break;
case "show":
default :
showCategories();
}
}
else
{
switch ($task) {
case "categories":
echo "now work $section=='categories , this part not work"; exit;
mosRedirect( "index2.php?option=categories§ion=com_booklibrary" );
break;
case "new" :
editBook($option, 0);
break;
case "edit" :
editBook($option, array_pop($bid));
break;
case "refetchInfos" :
refetchInfo($option, $bid);
break;
case "save" :
saveBook($option);
break;
case "remove" :
removeBooks($bid, $option);
break;
case "publish" :
publishBooks($bid, 1, $option);
break;
case "unpublish" :
publishBooks($bid, 0, $option);
break;
case "cancel" :
cancelBook($option);
break;
case "bookorderdown" :
orderBooks($bid[0], 1, $option);
break;
case "bookorderup" :
orderBooks($bid[0], -1, $option);
break;
case "show_import_export" :
importExportBooks($option);
break;
case "import" :
import($option);
break;
case "export" :
export($option);
break;
case "config_frontend" :
configure_frontend($option);
break;
case "config_backend" :
configure_backend($option);
break;
case "config_save_frontend" :
configure_save_frontend($option);
break;
case "config_save_backend" :
configure_save_backend($option);
break;
case "lend" :
if (mosGetParam($_POST, 'save') == 1) {
saveLend($option, $bid);
} else{
lend($option, $bid);
}
break;
case "lend_requests" :
lend_requests($option, $bid);
break;
case "accept_lend_requests" :
accept_lend_requests($option, $bid);
break;
case "decline_lend_requests" :
decline_lend_requests($option, $bid);
break;
case "about" :
HTML_booklibrary :: about();
break;
case "show_info" :
showInfo($option, $bid);
break;
case "lend_return" :
if (mosGetParam($_POST, 'save') == 1) {
saveLend_return($option, $bid);
} else {
lend_return($option, $bid);
}
break;
$booklibrary_configuration;
case "delete_review" :
$ids = explode(',',$bid[0]);
delete_review($option, $ids[1]);
editBook($option, $ids[0]);
break;
case "edit_review" :
$ids = explode(',',$bid[0]);
edit_review($option, $ids[1], $ids[0]);
break;
case "update_review" :
$title = mosGetParam($_POST, 'title') ;
$comment = mosGetParam($_POST, 'comment') ;
$rating = mosGetParam($_POST, 'rating') ;
$book_id = mosGetParam($_POST, 'book_id') ;
$review_id = mosGetParam($_POST, 'review_id') ;
update_review($title,$comment,$rating,$review_id );
editBook($option, $book_id );
break;
case "cancel_review_edit" :
$book_id = mosGetParam($_POST, 'book_id') ;
editBook($option, $book_id );
break;
default :
showBooks($option);
break;
}
} //else
class CAT_Utils
{
function categoryArray()
{
global $database;
// get a list of the menu items
$query = "SELECT c.*, c.parent_id AS parent"
. "\n FROM #__categories c"
. "\n WHERE section='com_booklibrary'"
. "\n AND published <> -2"
. "\n ORDER BY ordering" ;
$database->setQuery($query);
$items = $database->loadObjectList();
// establish the hierarchy of the menu
$children = array();
// first pass - collect children
foreach ($items as $v) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push($list, $v);
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$array = mosTreeRecurse(0, '', array(), $children);
return $array;
}
}
/**
* HTML Class
* Utility class for all HTML drawing classes
* @desc class General HTML creation class. We use it for back/front ends.
*/
class HTML
{
// TODO :: merge categoryList and categoryParentList
// add filter option ?
function categoryList($id, $action, $options = array())
{
$list = CAT_Utils::categoryArray();
// assemble menu items to the array
foreach ($list as $item) {
$options[] = mosHTML::makeOption($item->id, $item->treename);
}
$parent = mosHTML::selectList($options, 'catid', 'id="catid" class="inputbox" size="1" onchange="' . $action . '"', 'value', 'text', $id);
return $parent;
}
function categoryParentList($id, $action,$is_new, $options = array())
{
global $database;
$list = CAT_Utils::categoryArray();
$cat = new mosCategory($database);
$cat->load($id);
$this_treename = '';
foreach ($list as $item) {
if ($this_treename) {
if ($item->id != $cat->id && strpos($item->treename, $this_treename) === false) {
$options[] = mosHTML::makeOption($item->id, $item->treename);
}
} else {
if ($item->id != $cat->id) {
$options[] = mosHTML::makeOption($item->id, $item->treename);
} else {
$this_treename = "$item->treename/";
}
}
}
$parent= null;
if($is_new){
$parent = mosHTML::selectList($options, 'parent_id',
'class="inputbox" size="1"', 'value', 'text', $cat->parent_id);
} else{
$parent = mosHTML::selectList($options, 'parent_id',
'class="inputbox" size="1" disabled="true" ', 'value', 'text', $cat->parent_id);
}
return $parent;
}
function imageList($name, &$active, $javascript = null, $directory = null)
{
global $mosConfig_absolute_path;
if (!$javascript)
{
$javascript = "onchange=\"javascript:if (document.adminForm." . $name .
".options[selectedIndex].value!='') ".
"{document.imagelib.src='../images/stories/' + document.adminForm."
. $name . ".options[selectedIndex].value} else {document.imagelib.src='../images/blank.png'}\"";
}
if (!$directory) {
$directory = '/images/stories';
}
$imageFiles = mosReadDirectory($mosConfig_absolute_path.$directory);
$images = array(mosHTML::makeOption('', _A_SELECT_IMAGE));
foreach ($imageFiles as $file) {
if (eregi("bmp|gif|jpg|png", $file)) {
$images[] = mosHTML::makeOption($file);
}
}
$images = mosHTML::selectList($images, $name, 'id="'.$name.'" class="inputbox" size="1" '
. $javascript, 'value', 'text', $active);
return $images;
}
}
function bookLibraryTreeRecurse( $id, $indent, $list, &$children, $maxlevel=9999, $level=0, $type=1 ) {
if (@$children[$id] && $level <= $maxlevel) {
$parent_id = $id;
foreach ($children[$id] as $v) {
$id = $v->id;
if ( $type ) {
$pre = '<sup>L</sup> ';
$spacer = '. ';
} else {
$pre = '- ';
$spacer = ' ';
}
if ( $v->parent == 0 ) {
$txt = $v->name;
} else {
$txt = $pre . $v->name;
}
$pt = $v->parent;
$list[$id] = $v;
$list[$id]->treename = "$indent$txt";
$list[$id]->children = count( @$children[$id] );
$list[$id]->all_fields_in_list = count(@$children[$parent_id]);
$list = bookLibraryTreeRecurse( $id, $indent . $spacer, $list, $children, $maxlevel, $level+1, $type );
}
}
return $list;
}
function showCategories()
{
global $database, $my, $option, $menutype, $mainframe, $mosConfig_list_limit;
$section = "com_booklibrary";
$sectionid = $mainframe->getUserStateFromRequest("sectionid{$section}{$section}", 'sectionid', 0);
$limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mosConfig_list_limit);
$limitstart = $mainframe->getUserStateFromRequest("view{$section}limitstart", 'limitstart', 0);
$levellimit = $mainframe->getUserStateFromRequest("view{$option}limit$menutype", 'levellimit', 10);
$query = "SELECT c.*, c.checked_out as checked_out_contact_category, c.parent_id as parent, g.name AS groupname, u.name AS editor"
. "\n FROM #__categories AS c"
. "\n LEFT JOIN #__users AS u ON u.id = c.checked_out"
. "\n LEFT JOIN #__groups AS g ON g.id = c.access"
. "\n WHERE c.section='$section'"
. "\n AND c.published != -2"
. "\n ORDER BY parent_id, ordering" ;
$database->setQuery($query);
$rows = $database->loadObjectList();
foreach ($rows as $k => $v) {
$rows[$k]->ncourses=0;
$sql="SELECT COUNT(catid) AS cc FROM #__booklibrary WHERE catid=".$v->id;
$database->setQuery($sql);
$aa = $database->loadObjectList();
$rows[$k]->nbook=($aa[0]->cc==0)?"-":"<a href=\"?option=com_booklibrary§ion=book&catid=".$v->id."\">".($aa[0]->cc)."</a>";
}
if ($database->getErrorNum()) {
echo $database->stderr();
return false;
}
// establish the hierarchy of the categories
$children = array();
// first pass - collect children
foreach ($rows as $v) {
$pt = $v->parent;
$list = @$children[$pt] ? $children[$pt] : array();
array_push($list, $v);
$children[$pt] = $list;
}
// second pass - get an indent list of the items
$list = bookLibraryTreeRecurse(0, '', array(), $children, max(0, $levellimit-1));
$total = count($list);
require_once($GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php');
$pageNav = new mosPageNav($total, $limitstart, $limit);
$levellist = mosHTML::integerSelectList(1, 20, 1, 'levellimit', 'size="1" onchange="document.adminForm.submit();"', $levellimit);
// slice out elements based on limits
$list = array_slice($list, $pageNav->limitstart, $pageNav->limit);
//echo "<pre>"; print_r($list); echo "</pre>";exit;
$count = count($list);
// number of Active Items
/* for ($i = 0; $i < $count; $i++) {
$query = "SELECT COUNT( d.id )"
. "\n FROM #__categories AS d"
. "\n WHERE d.catid = " . $list[$i]->id;
// . "\n AND d.state <> '-2'";
$database->setQuery($query);
$active = $database->loadResult();
$list[$i]->documents = $active;
}*/
// get list of sections for dropdown filter
$javascript = 'onchange="document.adminForm.submit();"';
$lists['sectionid'] = mosAdminMenus::SelectSection('sectionid', $sectionid, $javascript);
HTML_Categories::show($list, $my->id, $pageNav, $lists, 'other');
}
function editCategory($section = '', $uid = 0)
{
global $database, $my;
global $mosConfig_absolute_path, $mosConfig_live_site;
$type = mosGetParam($_REQUEST, 'type', '');
$redirect = mosGetParam($_POST, 'section', '');;
$row = new mosCategory($database);
// load the row from the db table
$row->load($uid);
// fail if checked out not by 'me'
if ($row->checked_out && $row->checked_out <> $my->id) {
mosRedirect('index2.php?option=com_booklibrary&task=categories', 'The category ' . $row->title . ' is currently being edited by another administrator');
}
$is_new = false;
if ($uid) {
// existing record
$row->checkout($my->id);
// code for Link Menu
} else {
$is_new = true;
// new record
$row->section = $section;
$row->published = 1;
}
// make order list
$order = array();
$database->setQuery("SELECT COUNT(*) FROM #__categories WHERE section='$row->section'");
$max = intval($database->loadResult()) + 1;
for ($i = 1; $i < $max; $i++) {
$order[] = mosHTML::makeOption($i);
}
// build the html select list for ordering
$query = "SELECT ordering AS value, title AS text"
. "\n FROM #__categories"
. "\n WHERE section = '$row->section'"
. "\n ORDER BY ordering" ;
$lists['ordering'] = mosAdminMenus::SpecificOrdering($row, $uid, $query);
// build the select list for the image positions
$active = ($row->image_position ? $row->image_position : 'left');
$lists['image_position'] = mosAdminMenus::Positions('image_position', $active, null, 0, 0);
// Imagelist
$lists['image'] = HTML::imageList('image', $row->image);
// build the html select list for the group access
$lists['access'] = mosAdminMenus::Access($row);
// build the html radio buttons for published
$lists['published'] = mosHTML::yesnoRadioList('published', 'class="inputbox"', $row->published);
// build the html select list for paraent item
$options = array();
$options[] = mosHTML::makeOption('0', _A_SELECT_TOP);
$lists['parent'] = HTML::categoryParentList($row->id, "",$is_new, $options);
HTML_Categories::edit($row, $section, $lists, $redirect);
}
function saveCategory()
{
global $database;
$row = new mosCategory($database);
if (!$row->bind($_POST)) {
echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
exit();
}
$row->section='com_booklibrary';
$row->parent_id=$_REQUEST['parent_id'];
if (!$row->check()) {
echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
exit();
}
if (!$row->store()) {
echo "<script> alert('" . $row->getError() . "'); window.history.go(-1); </script>\n";
exit();
}
$row->checkin();
$row->updateOrder("section='com_booklibrary' AND parent_id='$row->parent_id'");
if ($oldtitle = mosGetParam($_POST, 'oldtitle', null)) {
if ($oldtitle != $row->title) {
$database->setQuery("UPDATE #__categories " . "\n SET name='$row->title' " . "\n WHERE name='$oldtitle' " . "\n AND section='com_booklibrary'");
$database->query();
}
}
mosRedirect('index2.php?option=com_booklibrary§ion=categories');
}
//this function check - is exist books in this folder and folders under this category
function is_exist_curr_and_subcategory_books($catid) {
global $database, $my;
$query = "SELECT *, COUNT(a.id) AS numlinks FROM #__categories AS cc"
. "\n LEFT JOIN #__booklibrary AS a ON a.catid = cc.id"
. "\n WHERE a.published='1' AND a.approved='1' AND section='com_booklibrary' AND cc.id='$catid' AND cc.published='1' AND cc.access <= '$my->gid'"
. "\n GROUP BY cc.id"
. "\n ORDER BY cc.ordering";
$database->setQuery( $query );
$categories = $database->loadObjectList();
if( count($categories) != 0 ) return true;
$query = "SELECT id "
. "FROM #__categories AS cc "
. " WHERE section='com_booklibrary' AND parent_id='$catid' AND published='1' AND access<='$my->gid'";
$database->setQuery( $query );
$categories = $database->loadObjectList();
if( count($categories) == 0 ) return false;
foreach($categories as $k) {
if( is_exist_curr_and_subcategory_books($k->id) ) return true;
}
return false;
}//end function
function removeCategoriesFromDB($cid){
global $database, $my;
$query = "SELECT id, "
. "FROM #__categories AS cc "
. " WHERE section='com_booklibrary' AND parent_id='$cid' AND published='1' AND access<='$my->gid'";
$database->setQuery( $query );
$categories = $database->loadObjectList();
// echo $database->getErrorMsg() ;
if( count($categories) != 0 ) {
//delete child
foreach($categories as $k) {
removeCategoriesFromDB($k->id) ;
}
}
$sql="DELETE FROM #__categories WHERE id = $cid ";
$database->setQuery($sql);
$database->query();
}
/**
* Deletes one or more categories from the categories table
*
* @param string $ The name of the category section
* @param array $ An array of unique category id numbers
*/
function removeCategories($section, $cid)
{
global $database;
if (count($cid) < 1) {
echo "<script> alert('Select a category to delete'); window.history.go(-1);</script>\n";
exit;
}
foreach ($cid as $catid) {
if(is_exist_curr_and_subcategory_books( $catid ) ){
echo "<script> alert('Some category from yours select contain books. \\n Please remove books first!'); window.history.go(-1); </script>\n";
exit ;
}
}
foreach ($cid as $catid) {
removeCategoriesFromDB($catid) ;
}
/* $cids = implode(',', $cid);
$query = "SELECT c.id AS numcat, c.name, COUNT(s.catid ) AS numkids"
. "\n FROM #__categories AS c"
. "\n LEFT JOIN #__booklibrary AS s ON s.catid=c.id"
. "\n WHERE c.id IN ($cids)"
. "\n GROUP BY c.id" ;
// add set query
$database->setQuery($query);
if (!($rows = $database->loadObjectList())) {
echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
return ;
}
$err = array();
$new_cid = array();
foreach ($rows as $row) {
if ($row->numkids == 0) {
$new_cid[] = $row->numcat;
} else {
$err[] = $row->name;
}
}
if (count($new_cid)) {
$new_cids = implode(',', $new_cid);
if (count($cid)) {
$new_cids = implode(',', $cid);
$sql="DELETE FROM #__categories WHERE id IN ($new_cids)";
$database->setQuery($sql);
if (!$database->query()) {
echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
return ;
}
}
if (count($err)) {
if (count($err) > 1) {
$new_cids = implode(', ', $err);
$msg = "Categories : $new_cids -";
} else {
$msg = "Category " . $err[0] ;
}
$msg .= ' cannot be removed. There are associated records and/or subcategories';
mosRedirect('index2.php?option=com_booklibrary§ion=categories&mosmsg=' . $msg);
}
*/
$msg = (count($err) > 1 ? "Categories " : _CATEGORIES_NAME . " ") . _DELETED;
mosRedirect('index2.php?option=com_booklibrary§ion=categories&mosmsg=' . $msg) ;
}
/**
* Publishes or Unpublishes one or more categories
*
* @param string $ The name of the category section
* @param integer $ A unique category id (passed from an edit form)
* @param array $ An array of unique category id numbers
* @param integer $ 0 if unpublishing, 1 if publishing
* @param string $ The name of the current user
*/
function publishCategories($section, $categoryid = null, $cid = null, $publish = 1)
{
global $database, $my;
if (!is_array($cid)) {
$cid = array();
}
if ($categoryid) {
$cid[] = $categoryid;
}
if (count($cid) < 1) {
$action = $publish ? _PUBLISH : _DML_UNPUBLISH;
echo "<script> alert('" . _DML_SELECTCATTO . " $action'); window.history.go(-1);</script>\n";
exit;
}
$cids = implode(',', $cid);
$query = "UPDATE #__categories SET published='$publish'"
. "\nWHERE id IN ($cids) AND (checked_out=0 OR (checked_out='$my->id'))" ;
$database->setQuery($query);
if (!$database->query()) {
echo "<script> alert('" . $database->getErrorMsg() . "'); window.history.go(-1); </script>\n";
exit();
}
if (count($cid) == 1) {
$row = new mosCategory($database);
$row->checkin($cid[0]);
}
mosRedirect('index2.php?option=com_booklibrary§ion=categories');
}
/**
* Cancels an edit operation
*
* @param string $ The name of the category section
* @param integer $ A unique category id
*/
function cancelCategory()
{
global $database;
$row = new mosCategory($database);
$row->bind($_POST);
$row->checkin();
mosRedirect('index2.php?option=com_booklibrary§ion=categories');
}
/**
* Moves the order of a record
*
* @param integer $ The increment to reorder by
*/
function orderCategory($uid, $inc)
{
global $database;
$row = new mosCategory($database);
$row->load($uid);
if($row->ordering == 1 && $inc == -1) mosRedirect('index2.php?option=com_booklibrary§ion=categories');
$new_order = $row->ordering + $inc ;
//change ordering - for other element
$query = "UPDATE #__categories SET ordering='".($row->ordering)."'"
. "\nWHERE parent_id = $row->parent_id and ordering=$new_order" ;
$database->setQuery($query);
$database->query();
//change ordering - for this element
$query = "UPDATE #__categories SET ordering='".$new_order."'"
. "\nWHERE id = $uid" ;
$database->setQuery($query);
$database->query();
mosRedirect('index2.php?option=com_booklibrary§ion=categories');
/* $row = new mosCategory($database);
$row->load($uid);
$row->move($inc, "section='$row->section'");
mosRedirect('index2.php?option=com_booklibrary§ion=categories');
*/
}
/**
* changes the access level of a record
*
* @param integer $ The increment to reorder by
*/
function accessCategory($uid, $access)
{
global $database;
$row = new mosCategory($database);
$row->load($uid);
$row->access = $access;
if (!$row->check()) {
return $row->getError();
}
if (!$row->store()) {
return $row->getError();
}
mosRedirect('index2.php?option=com_booklibrary§ion=categories');
}
function update_review($title,$comment,$rating,$review_id ) {
global $database;
//update review where id =.. ;
$database->setQuery('update #__booklibrary_review set rating='.$rating.
', title="'.$title.'", comment="'.$comment.'" where id = '.$review_id.' ;' );
$database->query();
echo $database->getErrorMsg();
}
function edit_review($option, $review_id,$book_id) {
global $database;
$database->setQuery("SELECT * FROM #__booklibrary_review WHERE id=".$review_id." ");
$review = $database->loadObjectList();
echo $database->getErrorMsg();
HTML_booklibrary :: edit_review($option, $book_id, $review);
}
/*
* Add Nikolay.
* Function for delete coment
* (comment for every book)
* in database.
*/
function delete_review($option, $id) {
global $database;
//delete review where id =.. ;
$database->setQuery("DELETE FROM #__booklibrary_review WHERE #__booklibrary_review.id=".$id.";");
$database->query();
echo $database->getErrorMsg();
}
//*************************************************************************************************************
//********************************* begin for manage reviews **********************************************
//*************************************************************************************************************
function delete_manage_review($option, $id) {
global $database;
for ($i = 0; $i < count($id); $i++) {
//delete review where id =.. ;
$database->setQuery("DELETE FROM #__booklibrary_review WHERE #__booklibrary_review.id=".$id[$i].";");
$database->query();
echo $database->getErrorMsg();
}
}
function edit_manage_review($option, $review_id) {
//old ($option, $review_id,$book_id) {
global $database;
if (count($review_id)>1) {
echo "<script> alert('Please select one review for edit!!!'); window.history.go(-1); </script>\n";
} else {
$database->setQuery("SELECT * FROM #__booklibrary_review WHERE id=".$review_id[0]." ");
$review = $database->loadObjectList();
echo $database->getErrorMsg();
HTML_booklibrary :: edit_manage_review($option, $review);
}
}
//*************************************************************************************************************
//********************************* end for manage reviews ************************************************
//*************************************************************************************************************
function showInfo($option, $bid){
if(is_array($bid) && count($bid) > 0){
$bid = $bid[0];
}
echo "Test: " . $bid;
}
function decline_lend_requests($option, $bids){
global $database;
foreach($bids as $bid){
$lend_request = new mosBookLibrary_lend_request($database);
$lend_request->load($bid);
$tmp = $lend_request->decline();
if($tmp != null){
echo "<script> alert('" .$tmp . "'); window.history.go(-1); </script>\n";
exit ();
}
}
mosRedirect("index2.php?option=$option&task=lend_requests");
}
function accept_lend_requests($option, $bids){
global $database;
foreach($bids as $bid){
$lend_request = new mosBookLibrary_lend_request($database);
$lend_request->load($bid);
$tmp = $lend_request->accept();
if($tmp != null){
echo "<script> alert('" .$tmp . "'); window.history.go(-1); </script>\n";
exit ();
}
}
mosRedirect("index2.php?option=$option&task=lend_requests");
}
function lend_requests($option, $bid){
global $database, $mainframe, $mosConfig_list_limit;
$limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mosConfig_list_limit);
$limitstart = $mainframe->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0);
$database->setQuery("SELECT count(*) FROM #__booklibrary AS a".
"\nLEFT JOIN #__booklibrary_lend_request AS l".
"\nON l.fk_bookid = a.id".
"\nWHERE l.status = 0");
$total = $database->loadResult();
echo $database->getErrorMsg();
require_once ($GLOBALS['mosConfig_absolute_path'].'/administrator/includes/pageNavigation.php');
$pageNav = new mosPageNav($total, $limitstart, $limit);
$database->setQuery("SELECT * FROM #__booklibrary AS a".
"\nLEFT JOIN #__booklibrary_lend_request AS l".
"\nON l.fk_bookid = a.id".
"\nWHERE l.status = 0".
"\nORDER BY l.lend_from, l.lend_until, l.user_name".
"\nLIMIT $pageNav->limitstart,$pageNav->limit;");
$lend_requests = $database->loadObjectList();
echo $database->getErrorMsg();
// print_r($total);
HTML_booklibrary :: showRequestLendBooks($option, $lend_requests, $pageNav);
}
/**
* Compiles a list of records
* @param database - A database connector object
* select categories
*/
function showBooks($option)
{
global $database, $mainframe, $mosConfig_list_limit;
$limit = $mainframe->getUserStateFromRequest("viewlistlimit", 'limit', $mosConfig_list_limit);
$limitstart = $mainframe->getUserStateFromRequest("view{$option}limitstart", 'limitstart', 0);
$catid = $mainframe->getUserStateFromRequest("catid{$option}", 'catid', '-1');//old 0
$lend = $mainframe->getUserStateFromRequest("lend{$option}", 'lend', '-1');//add nik
$pub = $mainframe->getUserStateFromRequest("pub{$option}", 'pub', '-1');//add nik
$search = $mainframe->getUserStateFromRequest("search{$option}", 'search', '');
$search = $database->getEscaped(trim(strtolower($search)));
$where = array ();
if ($lend == "lend") {
array_push($where, "a.fk_lendid <> 0");
} else if ($lend == "not_lend") {
array_push($where, "a.fk_lendid = 0");
}
if ($pub== "pub") {
array_push($where, "a.published = 1");
} else if ($pub == "not_pub") {
array_push($where, "a.published = 0");
}
if ($catid > 0) {
array_push($where, "a.catid='$catid'");
}
if ($search) {
array_push($where, "(LOWER(a.title) LIKE '%$search%' OR LOWER(a.authors) LIKE '%$search%' OR LOWER(a.isbn) LIKE '%$search%' OR LOWER(a.comment) LIKE '%$search%')");
}
$database->setQuery("SELECT count(*) FROM #__booklibrary AS a".
"\nLEFT JOIN #__booklibrary_lend AS l".
"\nON a.fk_lendid = l.id".
(count($where) ? "\nWHERE ".implode(' AND ', $where) : ""));
$total = $database->loadResult();
echo $database->getErrorMsg();
require_once ($GLOBALS['mosConfig_absolute_path'].'/administrator/includes/pageNavigation.php');
$pageNav = new mosPageNav($total, $limitstart, $limit);
$selectstring = "SELECT a.*, cc.title AS category, l.id as lendid, l.lend_from as lend_from, l.lend_return as lend_return, l.lend_until as lend_until, u.name AS editor".
"\nFROM #__booklibrary AS a".
"\nLEFT JOIN #__categories AS cc ON cc.id = a.catid".
"\nLEFT JOIN #__booklibrary_lend AS l ON a.fk_lendid = l.id".
"\nLEFT JOIN #__users AS u ON u.id = a.checked_out".
(count($where) ? "\nWHERE ".implode(' AND ', $where) : "").
"\nORDER BY a.catid, a.ordering".
"\nLIMIT $pageNav->limitstart,$pageNav->limit;";
$database->setQuery($selectstring);
$rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return false;
}
// get list of categories
/*
* select list treeSelectList
*/
$categories[] = mosHTML :: makeOption('0', _BOOKLIBRARY_LABEL_SELECT_CATEGORIES);
$categories[] = mosHTML :: makeOption('-1', _BOOKLIBRARY_LABEL_SELECT_ALL_CATEGORIES);
//$database->setQuery("SELECT id AS value, title AS text FROM #__categories"."\nWHERE section='com_booklibrary' ORDER BY ordering");
// $categories = array_merge($categories, $database->loadObjectList());//old valid
// $clist = mosHTML :: selectList($categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $catid);//old valid
//************* begin add for sub category in select in manager books *************
$options = $categories;
$id = 0;//$categories_array;
$list = CAT_Utils::categoryArray();
$cat = new mosCategory($database);
$cat->load($id);
$this_treename = '';
foreach ($list as $item) {
if ($this_treename) {
if ($item->id != $cat->id && strpos($item->treename, $this_treename) === false) {
$options[] = mosHTML::makeOption($item->id, $item->treename);
}
} else {
if ($item->id != $cat->id) {
$options[] = mosHTML::makeOption($item->id, $item->treename);
} else {
$this_treename = "$item->treename/";
}
}
}
$clist = mosHTML::selectList($options, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $catid);//new nik edit
// $clist = mosHTML :: selectList($categories, 'catid', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $catid);//old valid
//***** end add for sub category in select in manager books **********
$lendmenu[] = mosHTML :: makeOption('0', _BOOKLIBRARY_LABEL_SELECT_TO_LEND);
$lendmenu[] = mosHTML :: makeOption('-1', _BOOKLIBRARY_LABEL_SELECT_ALL_LEND);
$lendmenu[] = mosHTML :: makeOption('not_lend', _BOOKLIBRARY_LABEL_SELECT_NOT_LEND);
$lendmenu[] = mosHTML :: makeOption('lend', _BOOKLIBRARY_LABEL_SELECT_LEND);
$lendlist = mosHTML :: selectList($lendmenu, 'lend', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $lend);
$pubmenu[] = mosHTML :: makeOption('0', _BOOKLIBRARY_LABEL_SELECT_TO_PUBLIC);
$pubmenu[] = mosHTML :: makeOption('-1', _BOOKLIBRARY_LABEL_SELECT_ALL_PUBLIC);
$pubmenu[] = mosHTML :: makeOption('not_pub', _BOOKLIBRARY_LABEL_SELECT_NOT_PUBLIC);
$pubmenu[] = mosHTML :: makeOption('pub', _BOOKLIBRARY_LABEL_SELECT_PUBLIC);
$publist = mosHTML :: selectList($pubmenu, 'pub', 'class="inputbox" size="1" onchange="document.adminForm.submit();"', 'value', 'text', $pub);
HTML_booklibrary :: showBooks($option, $rows, $clist, $lendlist, $publist, $search, $pageNav);
}
/**
* Compiles information to add or edit books
* @param integer bid The unique id of the record to edit (0 if new)
* @param array option the current options
*/
function editBook($option,$bid)
{
global $database, $my, $mosConfig_live_site, $booklibrary_configuration;
$book = new mosBookLibrary($database);
// load the row from the db table
$book->load(intval($bid));
$numeric_bookids ;
// get list of categories
$categories[] = mosHTML :: makeOption('0', _BOOKLIBRARY_LABEL_SELECT_CATEGORIES);
$database->setQuery("SELECT id AS value, name AS text FROM #__categories"."\nWHERE section='$option' ORDER BY ordering");
$categories = array_merge($categories, $database->loadObjectList());
if (count($categories) <= 1) {
mosRedirect("index2.php?option=com_booklibrary§ion=categories", _BOOKLIBRARY_ADMIN_IMPEXP_ADD);
}
$clist = mosHTML :: selectList($categories, 'catid', 'class="inputbox" size="1"', 'value', 'text', intval($book->catid));
// get list of WS
$retVal = mosBooklibraryWS :: getArray();
$ws = null;
for ($i = 0, $n = count($retVal); $i < $n; $i ++) {
$help = & $retVal[$i];
$ws[] = mosHTML :: makeOption($help[0], $help[1]);
}
if($bid == 0) $wslist = mosHTML :: selectList($ws, 'informationFrom', 'class="inputbox" size="1"',
'value', 'text', 0 );
else $wslist = mosHTML :: selectList($ws, 'informationFrom', 'class="inputbox" size="1"', 'value',
'text', intval($book->informationFrom));
//get language List
$retVal1 = mosBooklibraryOthers :: getLanguageArray();
$lang = null;
for ($i = 0, $n = count($retVal1); $i < $n; $i ++) {
$help = & $retVal1[$i];
$lang[] = mosHTML :: makeOption($help[0], $help[1]);
}
if($bid == 0) $langlist = mosHTML :: selectList($lang, 'language', 'class="inputbox" size="1"',
'value', 'text', $booklibrary_configuration['editbook']['default']['lang'] );
else $langlist = mosHTML :: selectList($lang, 'language', 'class="inputbox" size="1"', 'value',
'text', $book->language);
//get Rating
$retVal2 = mosBooklibraryOthers :: getRatingArray();
$rating = null;
for ($i = 0, $n = count($retVal2); $i < $n; $i ++) {
$help = & $retVal2[$i];
$rating[] = mosHTML :: makeOption($help[0], $help[1]);
}
$ratinglist = mosHTML :: selectList($rating, 'rating', 'class="inputbox" size="1"', 'value', 'text', $book->rating);
//delete ebook?
$help = str_replace($mosConfig_live_site, "", $book->ebookURL);
$delete_ebook_yesno[] = mosHTML :: makeOption($help, _BOOKLIBRARY_YES);
$delete_ebook_yesno[] = mosHTML :: makeOption('0', _BOOKLIBRARY_NO);
$delete_ebook = mosHTML :: RadioList($delete_ebook_yesno, 'delete_ebook', 'class="inputbox"', '0', 'value', 'text');
// fail if checked out not by 'me'
if ($book->checked_out && $book->checked_out <> $my->id) {
mosRedirect("index2.php?option=$option", _BOOKLIBRARY_IS_EDITED);
}
if ($bid) {
$book->checkout($my->id);
} else {
// initialise new record
$book->published = 0;
$book->approved = 0;
}
//***************************** begin for reviews **************************//
//select a.*, b.name from jos_booklibrary_review a, jos_users b WHERE a.fk_userid = b.id and a.fk_bookid=2 ORDER BY date
$database->setQuery("select a.*, b.name from #__booklibrary_review a, #__users b".
" WHERE a.fk_userid = b.id and a.fk_bookid=".$bid." ORDER BY date ;");
$reviews1 = $database->loadObjectList();
//take review for anonymous users
$database->setQuery("select a.*, 'anonymous' as name from #__booklibrary_review a ".
" WHERE a.fk_userid = 0 and a.fk_bookid = ".$bid." ORDER BY date ;");
$reviews2 = $database->loadObjectList();
$reviews = array_merge($reviews1, $reviews2);
//********************** end for reviews *****************************//
HTML_booklibrary :: editBook($option, $book, $clist, $wslist, $langlist, $ratinglist, $delete_ebook, $reviews);
}
/**
* Saves the record on an edit form submit
* @param database A database connector object
*/
function saveBook($option)
{
/*print_r($_POST);
echo "11111111111111 <br />";
print_r($book);
echo "<br />"; exit;*/
global $database, $my,$mosConfig_absolute_path, $mosConfig_live_site, $booklibrary_configuration;
//print_r($database);exit;
//check how the other info should be provided
$book = new mosBookLibrary($database);
//print_r($book);exit;
if (!$book->bind($_POST)) {
echo "<script> alert('".$book->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
//fetch all information from the webservices if necessary
$book = mosBooklibraryWS :: fetchInfos($book);
if (is_string($book)) {
//there was an error while fetching!
echo "<script> alert('" . $book . "'); window.history.go(-1); </script>\n";
exit ();
}
if($_POST['ebook_Url'] != '') $book->ebookURL = $_POST['ebook_Url'];
//delete ebook file if neccesary
$delete_ebook = mosGetParam($_POST, 'delete_ebook', 0);
if($delete_ebook != '0'){
$retVal = @unlink($mosConfig_absolute_path . $delete_ebook);
$book->ebookURL = "";
}
//storing e-book
$file = $_FILES['ebook_file'];
//check if fileupload is correct
if($booklibrary_configuration['ebooks']['allow'] && intval($file['error']) > 0
&& intval($file['error']) < 4){
echo "<script> alert('" . _BOOKLIBRARY_LABEL_EBOOK_UPLOAD_ERROR .
"'); window.history.go(-1); </script>\n";
exit ();
}else if ($booklibrary_configuration['ebooks']['allow'] && intval($file['error']) != 4){
$file_new = $mosConfig_absolute_path . $booklibrary_configuration['ebooks']['location'] .
$file['name'];
echo $file_new;
if(!move_uploaded_file($file['tmp_name'], $file_new)){
echo "<script> alert('" . _BOOKLIBRARY_LABEL_EBOOK_UPLOAD_ERROR .
"'); window.history.go(-1); </script>\n";
exit ();
}else {
$book->ebookURL = $mosConfig_live_site . $booklibrary_configuration['ebooks']['location'] .
$file['name'];
}
}
$file = $_FILES['picture_file'];
//check if fileupload is correct
if($file['size'] != 0 && ( $file['error'] != 0
|| strpos($file['type'],'image') === false
||strpos($file['type'],'image')===""))
{
echo "<script> alert('" . _BOOKLIBRARY_LABEL_PICTURE_URL_UPLOAD_ERROR .
"'); window.history.go(-1); </script>\n";
exit ();
}
//store pictures locally if neccesary, first check remote URL
$retVal = null;
if(intval($booklibrary_configuration['fetchImages']['boolean']) == 1
&& trim($book->imageURL) != ""
&& $file['size'] == 0 ){
$retVal = mosBooklibraryOthers :: storeImageFile($book,null);
}
if(intval($booklibrary_configuration['fetchImages']['boolean']) == 1 && $file['size'] != 0)
{
$retVal = mosBooklibraryOthers :: storeImageFile($book, $file);
if ($retVal != null)
{
echo "<script> alert('".$retVal."'); window.history.go(-1); </script>\n";
exit ();
}
}
if($file['size'] == 0){
$file = null;
}
$book->date = date("Y-m-d H:i:s");
if (!$book->check()) {
echo "<script> alert('".$book->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
//remove escaped slashes
if(get_magic_quotes_gpc()) {
$book->comment = stripslashes($book->comment);
}
if (!$book->store()) {
echo "<script> alert('".$book->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
$book->checkin();
$book->updateOrder( "catid='$book->catid'" );
//$book->updateOrder("catid='$row->catid'");
//$id = $row->id;*/
mosRedirect("index2.php?option=$option");
}
/**
* Deletes one or more records
* @param array - An array of unique category id numbers
* @param string - The current author option
*/
function removeBooks($bid, $option) {
global $database;
if (!is_array($bid) || count($bid) < 1) {
echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>\n";
exit;
}
if (count($bid)) {
$bids = implode(',', $bid);
$database->setQuery("DELETE FROM #__booklibrary_review WHERE fk_bookid IN ($bids)");
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
}
$database->setQuery("DELETE FROM #__booklibrary WHERE id IN ($bids)");
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
}
}
mosRedirect("index2.php?option=$option");
}
/**
* Publishes or Unpublishes one or more records
* @param array - An array of unique category id numbers
* @param integer - 0 if unpublishing, 1 if publishing
* @param string - The current author option
*/
function publishBooks($bid, $publish, $option) {
global $database, $my;
$catid = mosGetParam($_POST, 'catid', array (0));
if (!is_array($bid) || count($bid) < 1) {
$action = $publish ? 'publish' : 'unpublish';
echo "<script> alert('Select an item to $action'); window.history.go(-1);</script>\n";
exit;
}
$bids = implode(',', $bid);
$database->setQuery("UPDATE #__booklibrary SET published='$publish'".
"\nWHERE id IN ($bids) AND (checked_out=0 OR (checked_out='$my->id'))");
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit ();
}
if (count($bid) == 1) {
$row = new mosBookLibrary($database);
$row->checkin($bid[0]);
}
mosRedirect("index2.php?option=$option");
}
/**
* Moves the order of a record
* @param integer - The increment to reorder by
*/
function orderBooks($bid, $inc, $option) {
global $database;
$book = new mosBookLibrary($database);
$book->load($bid);
$book->move($inc);
mosRedirect("index2.php?option=$option");
}
/**
* Cancels an edit operation
* @param string - The current author option
*/
function cancelBook($option) {
global $database;
$row = new mosBookLibrary($database);
$row->bind($_POST);
$row->checkin();
mosRedirect("index2.php?option=$option");
}
/**
* Refetches the book information
* @param string - The current author option
*/
function refetchInfo($option, $bid) {
global $database, $my, $booklibrary_configuration;
$informationFrom = mosGetParam($_POST, 'informationFrom');
if (!is_array($bid) || count($bid) < 1) {
echo "<script> alert('Select an item to refetch'); window.history.go(-1);</script>\n";
exit;
}
$bids = implode(',', $bid);
$database->setQuery("SELECT id, bookid, isbn, title, informationFrom from #__booklibrary WHERE id IN ($bids)");
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit ();
}
$books = $database->loadObjectList();
// get list of WS
$retVal = mosBooklibraryWS :: getWSArray();
$ws = null;
for ($i = 0, $n = count($retVal); $i < $n; $i ++) {
$help = $retVal[$i];
$ws[] = mosHTML :: makeOption($help[0], $help[1]);
}
$wslist = mosHTML :: selectList($ws, 'informationFrom', 'class="inputbox" size="1"', 'value', 'text');
if ($informationFrom == null) {
//show fetching information
HTML_booklibrary :: refetchBoosks($option, $books, $wslist);
} else {
//fetching information
$infos = array ();
$bookid = array_pop($bid);
while ($bookid != null) {
$book = new mosBookLibrary($database);
$book->load($bookid);
$book->informationFrom = $informationFrom;
$book_tmp = $book;
$book = mosBooklibraryWS :: fetchInfos($book);
if (is_string($book)) {
//there was an error while fetching!
array_push($infos, array ($book_tmp->id, $book_tmp->bookid, $book_tmp->isbn, $book));
} else {
//storing pictures if neccesary
$retVal = null;
if(intval($booklibrary_configuration['fetchImages']['boolean']) == 1){
$retVal = mosBooklibraryOthers :: storeImageFile($book, null);
}
//fetching was OK!
$book->date = date("Y-m-d H:i:s");
if ($retVal != null){
// error storing picture
array_push($infos, array ($book->id, $book->bookid, $book->isbn, $retVal));
} else if(!$book->check() || !$book->store()) {
//error while storing information!
array_push($infos, array ($book->id, $book->bookid, $book->isbn, $book->getError()));
} else {
array_push($infos, array ($book->id, $book->bookid, $book->isbn, "OK"));
}
$book->checkin();
}
$bookid = array_pop($bid);
}
$infos = array_reverse($infos);
HTML_booklibrary :: showInfoRefetchBooks($option, $infos, $wslist);
}
}
function configure_save_frontend($option){
global $my, $booklibrary_configuration;
$str = '';
$supArr = array();
$supArr = mosGetParam($_POST, 'ebooks_registrationlevel', 0);
for($i = 0;$i<count($supArr);$i++)
$str.=$supArr[$i].',';
$str = substr($str,0,-1);
$booklibrary_configuration['ebooks']['registrationlevel']=$str;
$str = '';
$supArr = mosGetParam($_POST, 'reviews_registrationlevel', 0);
for($i = 0;$i<count($supArr);$i++)
$str.=$supArr[$i].',';
$str = substr($str,0,-1);
$booklibrary_configuration['reviews']['registrationlevel']=$str;
$str = '';
$supArr = mosGetParam($_POST, 'lendrequest_registrationlevel', 0);
for($i = 0;$i<count($supArr);$i++)
$str.=$supArr[$i].',';
$str = substr($str,0,-1);
$booklibrary_configuration['lendrequest']['registrationlevel']=$str;
$booklibrary_configuration['reviews']['show']= mosGetParam($_POST, 'reviews_show', 0);//front--1
$booklibrary_configuration['lendstatus']['show']=mosGetParam($_POST, 'lendstatus_show', 0);//front--3
$booklibrary_configuration['ebooks']['show']= mosGetParam($_POST, 'ebooks_show', 0);//front--5
$booklibrary_configuration['price']['show']= mosGetParam($_POST, 'price_show', 0);//front--6
$booklibrary_configuration['foto']['high']=mosGetParam($_POST, 'foto_high');//front--7_high
$booklibrary_configuration['foto']['width']=mosGetParam($_POST, 'foto_width');//front--7_width
$booklibrary_configuration['page']['items']=mosGetParam($_POST, 'page_items');//front--8_page
//add for show in category picture
$booklibrary_configuration['cat_pic']['show'] = mosGetParam($_POST, 'cat_pic_show');
//add for show subcategory
$booklibrary_configuration['subcategory']['show'] = mosGetParam($_POST, 'subcategory_show');
mosBooklibraryOthers :: setParams();
configure_frontend($option);
}
function configure_save_backend($option){
global $my, $booklibrary_configuration,$mosConfig_absolute_path;
$booklibrary_configuration['fetchImages']['boolean']= mosGetParam($_POST, 'fetchImages_boolean', 0);
$booklibrary_configuration['fetchImages']['location']= mosGetParam($_POST, 'fetchImages_location', "/components/com_booklibrary/covers/");
$booklibrary_configuration['ebooks']['allow']= mosGetParam($_POST, 'ebooks_allow', 0);
$booklibrary_configuration['ebooks']['location']= mosGetParam($_POST, 'ebooks_location', "/components/com_booklibrary/ebooks/");
$booklibrary_configuration['ws']['amazon']['tag']=mosGetParam($_POST, 'ws_amazon_tag', "gerdsaurer-20");
$booklibrary_configuration['ws']['amazon']['devtag']=mosGetParam($_POST, 'ws_amazon_devtag');
$booklibrary_configuration['editbook']['check']['isbn'] = mosGetParam($_POST, 'editbook_check_isbn', 0);//back--7
$booklibrary_configuration['editbook']['default']['lang'] = mosGetParam($_POST, 'editbook_default_lang', 0);
mosBooklibraryOthers :: setParams();
configure_backend($option);
}
function configure_frontend($option)
{
global $my, $booklibrary_configuration, $acl,$database;
$yesno[] = mosHTML :: makeOption('1', _BOOKLIBRARY_YES);
$yesno[] = mosHTML :: makeOption('0', _BOOKLIBRARY_NO);
$gtree[] = mosHTML :: makeOption('-2', 'Everyone');
$gtree = array_merge($gtree, $acl->get_group_children_tree( null, 'USERS', false ));
$lists = array ();
$f="";
$s = explode(',',$booklibrary_configuration['reviews']['registrationlevel']);
for($i = 0;$i<count($s);$i++)
$f[] = mosHTML::makeOption( $s[$i] );
$lists['reviews']['show'] = mosHTML :: RadioList($yesno, 'reviews_show', 'class="inputbox"', $booklibrary_configuration['reviews']['show'], 'value', 'text');
$lists['reviews']['registrationlevel'] = mosHTML::selectList( $gtree, 'reviews_registrationlevel[]', 'size="4" multiple="multiple"', 'value', 'text', $f);
$f="";
$s = explode(',',$booklibrary_configuration['lendrequest']['registrationlevel']);
for($i = 0;$i<count($s);$i++)
$f[] = mosHTML::makeOption( $s[$i] );
$lists['lendstatus']['show'] = mosHTML :: RadioList($yesno, 'lendstatus_show', 'class="inputbox"', $booklibrary_configuration['lendstatus']['show'], 'value', 'text');
$lists['lendrequest']['registrationlevel'] = mosHTML::selectList( $gtree, 'lendrequest_registrationlevel[]', 'size="4" multiple="multiple"', 'value', 'text', $f );
$f="";
$s = explode(',',$booklibrary_configuration['ebooks']['registrationlevel']);
for($i = 0;$i<count($s);$i++)
$f[] = mosHTML::makeOption( $s[$i] );
$lists['ebooks']['registrationlevel'] = mosHTML::selectList( $gtree, 'ebooks_registrationlevel[]', 'size="4" multiple="multiple"', 'value', 'text', $f );
$lists['ebooks']['show'] = mosHTML :: RadioList($yesno, 'ebooks_show', 'class="inputbox"', $booklibrary_configuration['ebooks']['show'], 'value', 'text');
$lists['price']['show'] = mosHTML :: RadioList($yesno, 'price_show', 'class="inputbox"', $booklibrary_configuration['price']['show'], 'value', 'text');
$lists['foto']['high'] = '<input type="text" name="foto_high" value="'.$booklibrary_configuration['foto']['high'].'" class="inputbox" size="4" maxlength="4" title="" />';
$lists['foto']['width'] = '<input type="text" name="foto_width" value="'.$booklibrary_configuration['foto']['width'].'" class="inputbox" size="4" maxlength="4" title="" />';
$lists['page']['items'] = '<input type="text" name="page_items" value="'.$booklibrary_configuration['page']['items'].'" class="inputbox" size="2" maxlength="2" title="" />';
//add for show in category picture
$lists['cat_pic']['show'] = mosHTML :: RadioList($yesno, 'cat_pic_show', 'class="inputbox"', $booklibrary_configuration['cat_pic']['show'], 'value', 'text');
//add for show subcategory
$lists['subcategory']['show'] = mosHTML :: RadioList($yesno, 'subcategory_show', 'class="inputbox"', $booklibrary_configuration['subcategory']['show'], 'value', 'text');
HTML_booklibrary :: showConfiguration_frontend($lists, $option);
}
function configure_backend($option) {
global $my, $booklibrary_configuration, $acl;
$yesno[] = mosHTML :: makeOption('1', _BOOKLIBRARY_YES);
$yesno[] = mosHTML :: makeOption('0', _BOOKLIBRARY_NO);
$gtree[] = mosHTML :: makeOption('-2', 'Everyone');
$gtree = array_merge($gtree, $acl->get_group_children_tree( null, 'USERS', false ));
$lists = array ();
$lists['fetchImages']['boolean'] = mosHTML :: RadioList($yesno, 'fetchImages_boolean', 'class="inputbox"', $booklibrary_configuration['fetchImages']['boolean'], 'value', 'text');
$lists['fetchImages']['location'] = '<input type="text" name="fetchImages_location" value="'.$booklibrary_configuration['fetchImages']['location'].'" class="inputbox" size="50" maxlength="50" title="" />';
$lists['ebooks']['allow'] = mosHTML :: RadioList($yesno, 'ebooks_allow', 'class="inputbox"', $booklibrary_configuration['ebooks']['allow'], 'value', 'text');
$lists['ebooks']['location'] = '<input type="text" name="ebooks_location" value="'.$booklibrary_configuration['ebooks']['location'].'" class="inputbox" size="50" maxlength="50" title="" />';
$lists['ws']['amazon']['tag'] = '<input type="text" name="ws_amazon_tag" value="'.$booklibrary_configuration['ws']['amazon']['tag'].'" class="inputbox" size="50" maxlength="50" title="" />';
$lists['ws']['amazon']['devtag'] = '<input type="text" name="ws_amazon_devtag" value="'.$booklibrary_configuration['ws']['amazon']['devtag'].'" class="inputbox" size="50" maxlength="50" title="" />';
@$lists['editbook']['check']['isbn'] = mosHTML :: RadioList($yesno, 'editbook_check_isbn', 'class="inputbox"', $booklibrary_configuration['editbook']['check']['isbn'], 'value', 'text');//back--7
//get language List
$retVal1 = mosBooklibraryOthers :: getLanguageArray();
$lang = null;
for ($i = 0, $n = count($retVal1); $i < $n; $i ++) {
$help = & $retVal1[$i];
$lang[] = mosHTML :: makeOption($help[0], $help[1]);
}
$lists['editbook']['default']['lang'] = mosHTML :: selectList($lang, 'editbook_default_lang', 'class="inputbox" size="1"', 'value', 'text', $booklibrary_configuration['editbook']['default']['lang']);
$lists['ebooks']['registrationlevel'] = mosHTML::selectList( $gtree, 'ebooks_registrationlevel', 'size="4"', 'value', 'text', $my->gid );//(rus)--i tam i tam nado navernoe!
HTML_booklibrary :: showConfiguration_backend($lists, $option );
}
//***************************** end moe *********************
function lend($option, $bid)
{
global $database, $my;
if (!is_array($bid) || count($bid) < 1) {
echo "<script> alert('Select an item to lend'); window.history.go(-1);</script>\n";
exit;
}
$bids = implode(',', $bid);
$select ="SELECT a.*, cc.name AS category, l.id as lendid, l.lend_from as lend_from, ".
"l.lend_return as lend_return, l.lend_until as lend_until, l.fk_userid as fk_userid, ".
"l.user_name as user_name, l.user_email as user_email, u.name AS name, u.email as email".
"\nFROM #__booklibrary AS a".
"\nLEFT JOIN #__categories AS cc ON cc.id = a.catid".
"\nLEFT JOIN #__booklibrary_lend AS l ON l.id = a.fk_lendid".
"\nLEFT JOIN #__users AS u ON u.id = l.fk_userid".
"\nWHERE a.id in (".$bids.")";
$database->setQuery($select);
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit ();
}
$books = $database->loadObjectList();
// get list of categories
$userlist[] = mosHTML :: makeOption('-1', '----------');
$database->setQuery("SELECT id AS value, name AS text from #__users ORDER BY name");
$userlist = array_merge($userlist, $database->loadObjectList());
$usermenu = mosHTML :: selectList($userlist, 'userid', 'class="inputbox" size="1"', 'value', 'text', '-1');
HTML_booklibrary :: showLendBooks($option, $books, $usermenu, "lend");
}
function lend_return($option, $bid)
{
global $database, $my;
if (!is_array($bid) || count($bid) < 1) {
echo "<script> alert('Select an item to lend'); window.history.go(-1);</script>\n";
exit;
}
$bids = implode(',', $bid);
//for databases without subselect
$select ="SELECT a.*, cc.name AS category, l.id as lendid, l.lend_from as lend_from, ".
"l.lend_return as lend_return, l.lend_until as lend_until, l.fk_userid as fk_userid, ".
"l.user_name as user_name, l.user_email as user_email, u.name AS name, u.email as email".
"\nFROM #__booklibrary AS a".
"\nLEFT JOIN #__categories AS cc ON cc.id = a.catid".
"\nLEFT JOIN #__booklibrary_lend AS l ON l.id = a.fk_lendid".
"\nLEFT JOIN #__users AS u ON u.id = l.fk_userid".
"\nWHERE a.id in (".$bids.")";
$database->setQuery($select);
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit ();
}
$books = $database->loadObjectList();
$count=count($books);
for($i=0;$i<1;$i++)
{
if((($books[$i]->lend_from)=='')&&(($books[$i]->lend_return)==''))
{
/*
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>\n";
exit ();
*/
?>
<script type = "text/JavaScript" language = "JavaScript">
alert('You cannot return books that were not lent out');
window.history.go(-1);
</script>
<?php
exit;
}
}
// get list of users
$userlist[] = mosHTML :: makeOption('-1', '----------');
$database->setQuery("SELECT id AS value, name AS text from #__users ORDER BY name");
$userlist = array_merge($userlist, $database->loadObjectList());
$usermenu = mosHTML :: selectList($userlist, 'userid', 'class="inputbox" size="1"', 'value', 'text', '-1');
HTML_booklibrary :: showLendBooks($option, $books, $usermenu, "lend_return");
}
function saveLend($option, $bids) {
global $database, $my;
if (!is_array($bids) || count($bids) < 1) {
echo "<script> alert('Select an item to lend'); window.history.go(-1);</script>\n";
exit;
}
for ($i = 0, $n = count($bids); $i < $n; $i ++) {
$id = $bids[$i];
$lend = new mosBookLibrary_lend($database);
$lend->lend_from = date("Y-m-d H:i:s");
if (mosGetParam($_POST, 'lend_until') != "") {
$lend->lend_until = mosGetParam($_POST, 'lend_until');
} else {
$lend->lend_until = null;
}
$lend->fk_bookid = $id;
$userid = mosGetParam($_POST, 'userid');
if ($userid == "-1") {
$lend->user_name = mosGetParam($_POST, 'user_name', '');
$lend->user_email = mosGetParam($_POST, 'user_email', '');
} else {
$lend->fk_userid = intval($userid);
}
if (!$lend->check($lend)) {
echo "<script> alert('".$lend->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
if (!$lend->store()) {
echo "<script> alert('".$lend->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
$lend->checkin();
$book = new mosBookLibrary($database);
$book->load($id);
$book->fk_lendid = $lend->id;
$book->store();
$book->checkin();
}
mosRedirect("index2.php?option=$option");
}
function saveLend_return($option, $lids) {
global $database, $my;
if (!is_array($lids) || count($lids) < 1) {
echo "<script> alert('Select an item to return'); window.history.go(-1);</script>\n";
exit;
}
for ($i = 0, $n = count($lids); $i < $n; $i ++) {
$id = $lids[$i];
$lend = new mosBookLibrary_lend($database);
$lend->load(intval($id));
$lend->lend_return = date("Y-m-d H:i:s");
if (!$lend->check($lend)) {
echo "<script> alert('".$lend->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
if (!$lend->store()) {
echo "<script> alert('".$lend->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
$lend->checkin();
$book = new mosBookLibrary($database);
$book->load($lend->fk_bookid);
$book->fk_lendid = null;
$book->store(true);
$book->checkin(true);
}
mosRedirect("index2.php?option=$option");
}
function import($option)
{
global $database, $my;
$file = file($_FILES['import_file']['tmp_name']);
$catid = mosGetParam($_POST, 'import_catid');
//*********************** begin add for XML format ***************************************
$type = mosGetParam($_POST, 'import_type');
switch($type)
{
//CSV=='1' XML=='2'
case '1':
$retVal = mosBooklibraryImportExport :: importBooksCSV($file, $catid);
HTML_booklibrary:: showImportResult($retVal, $option);
break;
case '2':
$retVal = mosBooklibraryImportExport :: importBooksXML($_FILES['import_file']['tmp_name'], $catid);
HTML_booklibrary:: showImportResult($retVal, $option);
break;
case '3':
$retVal = mosBooklibraryImportExport :: entire_import($_FILES['import_file']['tmp_name']);
break;
//*********************** end add for XML format *****************************************
// $retVal = mosBooklibraryImportExport :: importBooksCSV($file, $catid);//old CSV
}
}
function export($option) {
global $database, $my, $mainframe;
if($_POST['export_type'] == 3)
{
$InformationArray = mosBooklibraryImportExport :: entire_export();
HTML_booklibrary :: showExportResult($InformationArray, $option);
}
else
{
$catid = mosGetParam($_POST, 'export_catid', 0);
$lend = mosGetParam($_POST, 'export_lend', null);
$pub = mosGetParam($_POST, 'export_pub', null);
$type = mosGetParam($_POST, 'export_type', 0);
$search = $mainframe->getUserStateFromRequest("search{$option}", 'search', '');
$search = $database->getEscaped(trim(strtolower($search)));
$where = array ();
if ($lend == "lend") {
array_push($where, "a.fk_lendid <> 0");
} else if ($lend == "not_lend") {
array_push($where, "a.fk_lendid = 0");
}
if ($pub== "pub") {
array_push($where, "a.published = 1");
} else if ($pub == "not_pub") {
array_push($where, "a.published = 0");
}
if ($catid > 0) {
array_push($where, "a.catid='$catid'");
}
if ($search) {
array_push($where, "(LOWER(a.title) LIKE '%$search%' OR LOWER(a.authors) LIKE '%$search%' OR LOWER(a.isbn) LIKE '%$search%' OR LOWER(a.comment) LIKE '%$search%')");
}
$selectstring = "SELECT id FROM #__booklibrary AS a ".
(count($where) ? "\nWHERE ".implode(' AND ', $where) : "").
"\nORDER BY a.catid, a.ordering";
$database->setQuery($selectstring);
$bids = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return;
}
$books = array();
$count = 0;
foreach($bids as $bid){
$book = new mosBookLibrary($database);
// load the row from the db table
$book->load(intval($bid->id));
$books[$count] = $book;
$count ++;
}
//parsing in title and commenr symbol '|'
for ($i = 0; $i < count($books); $i++) {
$books[$i]->title = str_replace('|','-',$books[$i]->title);
$books[$i]->title = str_replace('\n',' ',$books[$i]->title);
$books[$i]->title = str_replace('\r',' ',$books[$i]->title);
$books[$i]->comment = str_replace('|','-',$books[$i]->comment);
$books[$i]->comment = str_replace('\n',' ',$books[$i]->comment);
$books[$i]->comment = str_replace('\r',' ',$books[$i]->comment);
}
// begin add for Export XML all record
// if ($type == '1') {$retVal = mosBooklibraryImportExport :: exportBooksXML($books, false);}
// if ($type == '2') {$retVal = mosBooklibraryImportExport :: exportBooksXML($books, true);}
//move to xml - all data
$retVal = mosBooklibraryImportExport :: exportBooksXML($books, true);
$type2 = 'xml';
switch ($type) {
case '1':
$type2 = 'csv';
break;
case '2':
$type2 = 'xml';
break;
}
$InformationArray = mosBooklibraryImportExport :: storeExportFile($retVal, $type2);
HTML_booklibrary :: showExportResult($InformationArray, $option);
}
}
function importExportBooks($option) {
global $database;
// get list of categories
$categories[] = mosHTML :: makeOption('0', _BOOKLIBRARY_LABEL_SELECT_CATEGORIES);
$database->setQuery("SELECT id AS value, name AS text FROM #__categories"."\nWHERE section='$option' ORDER BY ordering");
$categories = array_merge($categories, $database->loadObjectList());
if (count($categories) < 1) {
mosRedirect("index2.php?option=com_booklibrary§ion=categories", _BOOKLIBRARY_ADMIN_IMPEXP_ADD);
}
$impclist = mosHTML :: selectList($categories, 'import_catid', 'class="inputbox" size="1" id="import_catid"', 'value', 'text', 0);
$expclist = mosHTML :: selectList($categories, 'export_catid', 'class="inputbox" size="1" id="export_catid"', 'value', 'text', 0);
$params = array();
$params['import']['category'] = $impclist;
$params['export']['category'] = $expclist;
$importtypes[0] = mosHTML :: makeOption('0', _BOOKLIBRARY_ADMIN_PLEASE_SEL);
$importtypes[1] = mosHTML :: makeOption('1', _BOOKLIBRARY_ADMIN_FORMAT_CSV);
$importtypes[2] = mosHTML :: makeOption('2', _BOOKLIBRARY_ADMIN_FORMAT_XML);
$importtypes[3] = mosHTML :: makeOption('3', _BOOKLIBRARY_ADMIN_ENTIRE_RECOVER);
$params['import']['type'] = mosHTML :: selectList($importtypes, 'import_type', 'id="import_type" class="inputbox" size="1" onchange = "impch();"', 'value', 'text', 0);
$exporttypes[0] = mosHTML :: makeOption('0', _BOOKLIBRARY_ADMIN_PLEASE_SEL);
$exporttypes[1] = mosHTML :: makeOption('1', _BOOKLIBRARY_ADMIN_FORMAT_CSV);
$exporttypes[2] = mosHTML :: makeOption('2', _BOOKLIBRARY_ADMIN_FORMAT_XML);
$exporttypes[3] = mosHTML :: makeOption('3', _BOOKLIBRARY_ADMIN_ENTIRE_BU);
$params['export']['type'] = mosHTML :: selectList($exporttypes, 'export_type', 'id="export_type" class="inputbox" size="1" onchange="expch();"', 'value', 'text', 0);
HTML_booklibrary :: showImportExportBooks($params, $option);
}
?>
|